public function run()
{
// lock Pico
$this->locked = true;
// load plugins
$this->loadPlugins();
$this->triggerEvent('onPluginsLoaded', array(&$this->plugins));
// load config
$this->loadConfig();
$this->triggerEvent('onConfigLoaded', array(&$this->config));
// check content dir
if (!is_dir($this->getConfig('content_dir'))) {
throw new RuntimeException('Invalid content directory "' . $this->getConfig('content_dir') . '"');
}
// evaluate request url
$this->evaluateRequestUrl();
$this->triggerEvent('onRequestUrl', array(&$this->requestUrl));
// discover requested file
$this->discoverRequestFile();
$this->triggerEvent('onRequestFile', array(&$this->requestFile));
// load raw file content
$this->triggerEvent('onContentLoading', array(&$this->requestFile));
$notFoundFile = '404' . $this->getConfig('content_ext');
if (file_exists($this->requestFile) && basename($this->requestFile) !== $notFoundFile) {
$this->rawContent = $this->loadFileContent($this->requestFile);
} else {
$this->triggerEvent('on404ContentLoading', array(&$this->requestFile));
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
$this->rawContent = $this->load404Content($this->requestFile);
$this->triggerEvent('on404ContentLoaded', array(&$this->rawContent));
}
$this->triggerEvent('onContentLoaded', array(&$this->rawContent));
// parse file meta
$headers = $this->getMetaHeaders();
$this->triggerEvent('onMetaParsing', array(&$this->rawContent, &$headers));
$this->meta = $this->parseFileMeta($this->rawContent, $headers);
$this->triggerEvent('onMetaParsed', array(&$this->meta));
// register parsedown
$this->triggerEvent('onParsedownRegistration');
$this->registerParsedown();
// parse file content
$this->triggerEvent('onContentParsing', array(&$this->rawContent));
$this->content = $this->prepareFileContent($this->rawContent, $this->meta);
$this->triggerEvent('onContentPrepared', array(&$this->content));
$this->content = $this->parseFileContent($this->content);
$this->triggerEvent('onContentParsed', array(&$this->content));
// read pages
$this->triggerEvent('onPagesLoading');
$this->readPages();
$this->sortPages();
$this->discoverCurrentPage();
$this->triggerEvent('onPagesLoaded', array(&$this->pages, &$this->currentPage, &$this->previousPage, &$this->nextPage));
// register twig
$this->triggerEvent('onTwigRegistration');
$this->registerTwig();
// render template
$this->twigVariables = $this->getTwigVariables();
if (isset($this->meta['template']) && $this->meta['template']) {
$templateName = $this->meta['template'];
} else {
$templateName = 'index';
}
if (file_exists($this->getThemesDir() . $this->getConfig('theme') . '/' . $templateName . '.twig')) {
$templateName .= '.twig';
} else {
$templateName .= '.html';
}
$this->triggerEvent('onPageRendering', array(&$this->twig, &$this->twigVariables, &$templateName));
$output = $this->twig->render($templateName, $this->twigVariables);
$this->triggerEvent('onPageRendered', array(&$output));
return $output;
}