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;
}
}