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

__construct()

Parse sitewide settings, create $collection and set the context to the currently requested page.

array
__sleep()

Define properties to be cached.

__wakeup()

Set new Context after being restored from cache.

bool
currentPageExists()

Tests wheter the currently requested page actually exists and is not an error page.

array
getCollection()

Return $collection array.

getFilelist()

Return Automad's instance of the Filelist class and create instance when accessed for the first time.

Page|null
getPage(string $url)

If existing, return the page object for the passed relative URL.

getPagelist()

Return Automad's instance of the Pagelist class and create instance when accessed for the first time.

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.

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.

getRequestedPage()

Return the page object for the requested page.

getReservedUrls()

Get an array of reseverd URLs - all real directories within the base directory and the UI URL.

string
makeUrl(string $parentUrl, string $slug)

Builds an URL out of the parent URL and the actual file system folder name.

pageNotFound()

Create a temporary page for a missing page and send a 404 header.

Details

__construct()

Parse sitewide settings, create $collection and set the context to the currently requested page.

array __sleep()

Define properties to be cached.

Return Value

array $itemsToCache

__wakeup()

Set new Context after being restored from cache.

bool currentPageExists()

Tests wheter the currently requested page actually exists and is not an error page.

Return Value

bool True if existing

array getCollection()

Return $collection array.

Return Value

array $this->collection

Filelist getFilelist()

Return Automad's instance of the Filelist class and create instance when accessed for the first time.

Return Value

Filelist Filelist object

Page|null getPage(string $url)

If existing, return the page object for the passed relative URL.

Parameters

string $url

Return Value

Page|null Page or null

Pagelist getPagelist()

Return Automad's instance of the Pagelist class and create instance when accessed for the first time.

Return Value

Pagelist Pagelist object

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.

Parameters

string $file

Return Value

string The buffered output

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']

Parameters

string $path
int $level
string $parentUrl

private Page getRequestedPage()

Return the page object for the requested page.

Return Value

Page A page object

private getReservedUrls()

Get an array of reseverd URLs - all real directories within the base directory and the UI URL.

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.

Parameters

string $parentUrl
string $slug

Return Value

string $url

private Page pageNotFound()

Create a temporary page for a missing page and send a 404 header.

Return Value

Page The error page