collection['url']. * * @var array */ private array $collection = array(); /** * Automad's Filelist object * * The object is part of the Automad class to allow to access always the same instance of the Filelist class for all objects using the Automad object as parameter. */ private ?Filelist $Filelist = null; /** * Automad's Pagelist object. * * The object is part of the Automad class to allow to access always the same instance of the Pagelist class for all objects using the Automad object as parameter. */ private ?Pagelist $Pagelist = null; /** * Set collection and Shared properties and create the context object with the currently requested page. * * @param array $collection * @param Shared $Shared */ public function __construct(array $collection, Shared $Shared) { $this->collection = $collection; $this->Shared = $Shared; Debug::log(array('Shared' => $this->Shared, 'Collection' => $this->collection), 'New instance created'); $this->Context = new Context($this->getRequestedPage()); } /** * Define properties to be cached. * * @return array $itemsToCache */ public function __sleep(): array { $itemsToCache = array('collection', 'Shared'); Debug::log($itemsToCache, 'Preparing Automad object for serialization! Caching the following items'); return $itemsToCache; } /** * Set new Context after being restored from cache. */ public function __wakeup(): void { Debug::log(get_object_vars($this), 'Automad object got unserialized'); $this->Context = new Context($this->getRequestedPage()); } /** * Create a new Automad instance including its required dependencies. * * @return Automad */ public static function create(): Automad { $Shared = new Shared(); $PageCollection = new PageCollection('/', $Shared); return new Automad($PageCollection->get(), $Shared); } /** * Tests wheter the currently requested page actually exists and is not an error page. * * @return bool True if existing */ public function currentPageExists(): bool { $Page = $this->Context->get(); return ($Page->template != Page::TEMPLATE_NAME_404); } /** * Load Automad instance from cache if possible. * * @return Automad */ public static function fromCache(): Automad { $Cache = new Cache(); return $Cache->getAutomad(); } /** * Return $collection array. * * @return array $this->collection */ public function getCollection(): array { return $this->collection; } /** * Return Automad's instance of the Filelist class and create instance when accessed for the first time. * * @return Filelist Filelist object */ public function getFilelist(): Filelist { if (!$this->Filelist) { $this->Filelist = new Filelist($this->Context); } return $this->Filelist; } /** * Build the pages array that is used to build a nav tree. * * @return array the rendered data array */ public function getNavigationMetaData(): array { $pages = array(); foreach ($this->collection as $Page) { $pages[$Page->origUrl] = array( 'title' => $Page->get(Fields::TITLE), 'index' => $Page->index, 'url' => $Page->origUrl, 'path' => $Page->path, 'parentUrl' => $Page->parentUrl, 'private' => $Page->private, 'lastModified' => $Page->get(Fields::TIME_LAST_MODIFIED) ); } return $pages; } /** * If existing, return the page object for the passed relative URL. * * @param string $url * @return Page|null Page */ public function getPage(string $url): ?Page { if (array_key_exists($url, $this->collection)) { return $this->collection[$url]; } return null; } /** * Return Automad's instance of the Pagelist class and create instance when accessed for the first time. * * @return Pagelist Pagelist object */ public function getPagelist(): Pagelist { if (!$this->Pagelist) { $this->Pagelist = new Pagelist($this->collection, $this->Context); } return $this->Pagelist; } /** * 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. * * @param string $file * @return string The buffered output */ public function loadTemplate(string $file): string { $Automad = $this; if (is_readable($file)) { ob_start(); include $file; $output = ob_get_contents(); ob_end_clean(); } else { $template = Str::stripStart($file, AM_BASE_DIR . AM_DIR_PACKAGES); $title = $Automad->Context->get()->get(Fields::TITLE); $url = $Automad->Context->get()->get(Fields::URL); $output = "

Template $template for page $title ($url) is missing!

Make sure you have selected an existing template for this page!

"; } // Strip comments before return. return preg_replace('/(' . preg_quote(Delimiters::COMMENT_OPEN) . '.*?' . preg_quote(Delimiters::COMMENT_CLOSE) . ')/s', '', $output); } /** * Return the page object for the requested page. * * @return Page|null A page object */ private function getRequestedPage(): ?Page { if (strpos(AM_REQUEST, RequestHandler::$apiBase) === 0) { return $this->getPage(Request::post('url')); } if (AM_FEED_ENABLED && AM_REQUEST == AM_FEED_URL) { return $this->getPage('/'); } if ($Page = $this->getPage(AM_REQUEST)) { return $Page; } return $this->pageNotFound(); } /** * Create a temporary page for a missing page and send a 404 header. * * @return Page The error page */ private function pageNotFound(): Page { header('HTTP/1.0 404 Not Found'); if (file_exists(AM_BASE_DIR . AM_DIR_PACKAGES . '/' . $this->Shared->get(Fields::THEME) . '/' . Page::TEMPLATE_NAME_404 . '.php')) { $data = array(); $data[Fields::TEMPLATE] = Page::TEMPLATE_NAME_404; $data[Fields::LEVEL] = 0; $data[Fields::PARENT] = ''; return new Page($data, $this->Shared); } exit('

Page not found!

'); } } __halt_compiler();----SIGNATURE:----P194j8DfE/vcFneKK+8odVLJ4ZZ1+OVdemw5cCZ3oMivy8xznciDsxu9EHxy7mwAn6zZpQHTM1SzVxz3clUIqyq57hDhzbYpFvD/iyFsWB2l5GUqcJJ0gGnr/HnG5VCBeryPrKl8ipr9+vcWvfoFVjjhUGIvmduIOdRfmtomV0y/2gcls5uO+NcEjMt3rx7/5k3n9sG0mSBMpQFjaEd9XiOySqDgo9hM1xVVOEAMMIHl67aPw5U4W0sy4HWe9J/JyGowICVQ9kMKlHuB82e76dh7FLmxhuml2qjchcitdFKNVYKx1++rNRMYHIJswh7SJFKcFtYZhqu+9VRBfSArohkJuQURqzVxwkvc/60BmhXwnhPWEh/d4itffQtZGf3dgDbl4+s+gxI7pa412I8d468C173UlO+lTUBxM+rRr9DnLSJ3R1ZfEGMB3NsyrzSHvQ16eM7m83LeyeulUf2GWHiABKFD6gUBNT+6AZK9zAcgMZQkCiAYiUUiKe6rxErQGBLElPaOLw39Qs/gva2VX/zdHRTW7Sv7V0WHMRLn/Omz4C1w9EPitQZYzH+Fi7h2Qa+BIPvPg9bLF1tIG9DDmsQfH52EZWSjzjOvmfUWUkJ0AKL5Kghv/oul2UlhL21wGs9qsMzMNGwP+GpMQPm3GUF0GzaFwSlBsBC/8V9ENk8=----ATTACHMENT:----OTY5MDgyMTUyNjk4MjQ5MiA5ODEwNDUzMjEwMzAzMTc1IDI2ODM5MTMxNzA5MDc5OTQ=