Automad
class Automad (View source)
The Automad class includes all methods and properties regarding the site, structure and pages.
A Automad object is the "main" object. It consists of many single Page objects, the Shared object and holds also additional data like the Filelist and Pagelist objects.
Properties
$Context | Automad's Context object. | ||
$Shared | Automad's Shared object. | ||
private | $collection | Array holding all the site's pages and the related data. | |
private | $Filelist | Automad's Filelist object | |
private | $Pagelist | Automad's Pagelist object. | |
private | $reservedUrls | An array of existing directories within the base directory (/automad, /config, /pages etc.) | |
private | $user | The username of the currently logged in user or false. |
Methods
Parse sitewide settings, create $collection and set the context to the currently requested page.
Define properties to be cached.
Set new Context after being restored from cache.
Tests wheter the currently requested page actually exists and is not an error page.
Return $collection array.
Return Automad's instance of the Filelist class and create instance when accessed for the first time.
Return Automad's instance of the Pagelist class and create instance when accessed for the first time.
Load and buffer a template file and return its content as string. The Automad object gets passed as parameter to be available for all plain PHP within the included file.
Searches $path recursively for files with the AM_FILE_EXT_DATA and adds the parsed data to $collection.
Return the page object for the requested page.
Get an array of reseverd URLs - all real directories within the base directory and the UI URL.
Builds an URL out of the parent URL and the actual file system folder name.
Create a temporary page for a missing page and send a 404 header.
Details
at line 100
__construct()
Parse sitewide settings, create $collection and set the context to the currently requested page.
at line 116
array
__sleep()
Define properties to be cached.
at line 126
__wakeup()
Set new Context after being restored from cache.
at line 136
bool
currentPageExists()
Tests wheter the currently requested page actually exists and is not an error page.
at line 147
array
getCollection()
Return $collection array.
at line 156
Filelist
getFilelist()
Return Automad's instance of the Filelist class and create instance when accessed for the first time.
at line 170
Page|null
getPage(string $url)
If existing, return the page object for the passed relative URL.
at line 181
Pagelist
getPagelist()
Return Automad's instance of the Pagelist class and create instance when accessed for the first time.
at line 201
string
loadTemplate(string $file)
Load and buffer a template file and return its content as string. The Automad object gets passed as parameter to be available for all plain PHP within the included file.
This is basically the base method to load a template without parsing the Automad markup. It just gets the parsed PHP content.
Before returning the markup, all comments <# ... #> get stripped.
Note that even when the it is possible to use plain PHP in a template file, all that code will be parsed first when buffering, before any of the Automad markup is getting parsed. That also means, that is not possible to make plain PHP code really interact with any of the Automad placeholder markup.
at line 231
private
collectPages(string $path = '/', int $level = 0, string $parentUrl = '')
Searches $path recursively for files with the AM_FILE_EXT_DATA and adds the parsed data to $collection.
After successful indexing, the $collection holds basically all information (except media files) from all pages of the whole site. This makes searching and filtering very easy since all data is stored in one place. To access the data of a specific page within the $collection array, the page's url serves as the key: $this->collection['/path/to/page']
at line 334
private
getReservedUrls()
Get an array of reseverd URLs - all real directories within the base directory and the UI URL.
at line 368
private string
makeUrl(string $parentUrl, string $slug)
Builds an URL out of the parent URL and the actual file system folder name.
It is important to only transform the actual folder name (slug) and not the whole path, because of handling possible duplicate parent folder names right. If there are for example two folders on the level above, called xxx.folder/ and yyy.folder/, they will be transformed into folder/ and folder-1/. If the URL from yyy.folder/child/ is made from the whole path, it will return folder/child/ instead of folder-1/child/, even if the parent URL would be folder-1/.
The prefix for sorting (xxx.folder) will be stripped. In case the resulting url is already in use, a suffix (-1, -2 ...) gets appende to the new url.