Pico::readPages PHP Method

readPages() protected method

The page data will be an array containing the following values: | Array key | Type | Description | | -------------- | ------ | ---------------------------------------- | | id | string | relative path to the content file | | url | string | URL to the page | | title | string | title of the page (YAML header) | | description | string | description of the page (YAML header) | | author | string | author of the page (YAML header) | | time | string | timestamp derived from the Date header | | date | string | date of the page (YAML header) | | date_formatted | string | formatted date of the page | | raw_content | string | raw, not yet parsed contents of the page | | meta | string | parsed meta data of the page |
See also: Pico::sortPages()
See also: Pico::getPages()
protected readPages ( ) : void
return void
    protected function readPages()
    {
        $this->pages = array();
        $files = $this->getFiles($this->getConfig('content_dir'), $this->getConfig('content_ext'), Pico::SORT_NONE);
        foreach ($files as $i => $file) {
            // skip 404 page
            if (basename($file) === '404' . $this->getConfig('content_ext')) {
                unset($files[$i]);
                continue;
            }
            $id = substr($file, strlen($this->getConfig('content_dir')), -strlen($this->getConfig('content_ext')));
            // drop inaccessible pages (e.g. drop "sub.md" if "sub/index.md" exists)
            $conflictFile = $this->getConfig('content_dir') . $id . '/index' . $this->getConfig('content_ext');
            if (in_array($conflictFile, $files, true)) {
                continue;
            }
            $url = $this->getPageUrl($id);
            if ($file != $this->requestFile) {
                $rawContent = file_get_contents($file);
                $headers = $this->getMetaHeaders();
                try {
                    $meta = $this->parseFileMeta($rawContent, $headers);
                } catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
                    $meta = $this->parseFileMeta('', $headers);
                    $meta['YAML_ParseError'] = $e->getMessage();
                }
            } else {
                $rawContent =& $this->rawContent;
                $meta =& $this->meta;
            }
            // build page data
            // title, description, author and date are assumed to be pretty basic data
            // everything else is accessible through $page['meta']
            $page = array('id' => $id, 'url' => $url, 'title' => &$meta['title'], 'description' => &$meta['description'], 'author' => &$meta['author'], 'time' => &$meta['time'], 'date' => &$meta['date'], 'date_formatted' => &$meta['date_formatted'], 'raw_content' => &$rawContent, 'meta' => &$meta);
            if ($file === $this->requestFile) {
                $page['content'] =& $this->content;
            }
            unset($rawContent, $meta);
            // trigger event
            $this->triggerEvent('onSinglePageLoaded', array(&$page));
            $this->pages[$id] = $page;
        }
    }