isStatusChanged()) { $this->setEnabled(true, true, true); } break; } } if ($this->isEnabled()) { $this->triggerEvent('plugins_loaded'); } } /** * Triggers the deprecated event config_loaded($config), tries to read * {@path "config.php"} in Picos root dir, enables the plugins * {@link PicoParsePagesContent} and {@link PicoExcerpt} and defines some * deprecated constants (ROOT_DIR, CONTENT_DIR etc.) * * @see DummyPlugin::onConfigLoaded() */ public function onConfigLoaded(&$config) { if (file_exists($this->getRootDir() . 'config.php')) { // config.php in Pico::$rootDir is deprecated; use Pico::$configDir instead $newConfig = require($this->getRootDir() . 'config.php'); if (is_array($newConfig)) { $config = $newConfig + $config; } } // enable PicoParsePagesContent and PicoExcerpt // we can't enable them during onPluginsLoaded because we can't know // if the user disabled us (PicoDeprecated) manually in the config $plugins = $this->getPlugins(); if (isset($plugins['PicoParsePagesContent'])) { // parse all pages content if this plugin hasn't // be explicitly enabled/disabled yet if (!$plugins['PicoParsePagesContent']->isStatusChanged()) { $plugins['PicoParsePagesContent']->setEnabled(true, true, true); } } if (isset($plugins['PicoExcerpt'])) { // enable excerpt plugin if it hasn't be explicitly enabled/disabled yet if (!$plugins['PicoExcerpt']->isStatusChanged()) { $plugins['PicoExcerpt']->setEnabled(true, true, true); } } // CONTENT_DIR constant is deprecated since v0.9, // ROOT_DIR, LIB_DIR, PLUGINS_DIR, THEMES_DIR and CONTENT_EXT constants since v1.0, // CONFIG_DIR constant existed just for a short time between v0.9 and v1.0, // CACHE_DIR constant was dropped with v1.0 without a replacement if (!defined('ROOT_DIR')) { define('ROOT_DIR', $this->getRootDir()); } if (!defined('CONFIG_DIR')) { define('CONFIG_DIR', $this->getConfigDir()); } if (!defined('LIB_DIR')) { $picoReflector = new ReflectionClass('Pico'); define('LIB_DIR', dirname($picoReflector->getFileName() . '/')); } if (!defined('PLUGINS_DIR')) { define('PLUGINS_DIR', $this->getPluginsDir()); } if (!defined('THEMES_DIR')) { define('THEMES_DIR', $this->getThemesDir()); } if (!defined('CONTENT_DIR')) { define('CONTENT_DIR', $config['content_dir']); } if (!defined('CONTENT_EXT')) { define('CONTENT_EXT', $config['content_ext']); } $this->triggerEvent('config_loaded', array(&$config)); } /** * Triggers the deprecated event request_url($url) * * @see DummyPlugin::onRequestUrl() */ public function onRequestUrl(&$url) { $this->triggerEvent('request_url', array(&$url)); } /** * Sets {@link PicoDeprecated::$requestFile} to trigger the deprecated * events after_load_content() and after_404_load_content() * * @see DummyPlugin::onRequestFile() */ public function onRequestFile(&$file) { $this->requestFile = &$file; } /** * Triggers the deprecated before_load_content($file) * * @see DummyPlugin::onContentLoading() */ public function onContentLoading(&$file) { $this->triggerEvent('before_load_content', array(&$file)); } /** * Triggers the deprecated event after_load_content($file, $rawContent) * * @see DummyPlugin::onContentLoaded() */ public function onContentLoaded(&$rawContent) { $this->triggerEvent('after_load_content', array(&$this->requestFile, &$rawContent)); } /** * Triggers the deprecated before_404_load_content($file) * * @see DummyPlugin::on404ContentLoading() */ public function on404ContentLoading(&$file) { $this->triggerEvent('before_404_load_content', array(&$file)); } /** * Triggers the deprecated event after_404_load_content($file, $rawContent) * * @see DummyPlugin::on404ContentLoaded() */ public function on404ContentLoaded(&$rawContent) { $this->triggerEvent('after_404_load_content', array(&$this->requestFile, &$rawContent)); } /** * Triggers the deprecated event before_read_file_meta($headers) * * @see DummyPlugin::onMetaHeaders() */ public function onMetaHeaders(&$headers) { $this->triggerEvent('before_read_file_meta', array(&$headers)); } /** * Triggers the deprecated event file_meta($meta) * * @see DummyPlugin::onMetaParsed() */ public function onMetaParsed(&$meta) { $this->triggerEvent('file_meta', array(&$meta)); } /** * Triggers the deprecated event before_parse_content($rawContent) * * @see DummyPlugin::onContentParsing() */ public function onContentParsing(&$rawContent) { $this->triggerEvent('before_parse_content', array(&$rawContent)); } /** * Triggers the deprecated events after_parse_content($content) and * content_parsed($content) * * @see DummyPlugin::onContentParsed() */ public function onContentParsed(&$content) { $this->triggerEvent('after_parse_content', array(&$content)); // deprecated since v0.8 $this->triggerEvent('content_parsed', array(&$content)); } /** * Triggers the deprecated event get_page_data($pages, $meta) * * @see DummyPlugin::onSinglePageLoaded() */ public function onSinglePageLoaded(&$pageData) { $this->triggerEvent('get_page_data', array(&$pageData, $pageData['meta'])); } /** * Triggers the deprecated event get_pages($pages, $currentPage, $previousPage, $nextPage) * * @see DummyPlugin::onPagesLoaded() */ public function onPagesLoaded(&$pages, &$currentPage, &$previousPage, &$nextPage) { // remove keys of pages array $plainPages = array(); foreach ($pages as &$pageData) { $plainPages[] = &$pageData; } unset($pageData); $this->triggerEvent('get_pages', array(&$plainPages, &$currentPage, &$previousPage, &$nextPage)); // re-index pages array $pages = array(); foreach ($plainPages as &$pageData) { if (!isset($pageData['id'])) { $urlPrefixLength = strlen($this->getBaseUrl()) + intval(!$this->isUrlRewritingEnabled()); $pageData['id'] = substr($pageData['url'], $urlPrefixLength); } // prevent duplicates $id = $pageData['id']; for ($i = 1; isset($pages[$id]); $i++) { $id = $pageData['id'] . '~dup' . $i; } $pages[$id] = &$pageData; } } /** * Triggers the deprecated event before_twig_register() * * @see DummyPlugin::onTwigRegistration() */ public function onTwigRegistration() { $this->triggerEvent('before_twig_register'); } /** * Triggers the deprecated event before_render($twigVariables, $twig, $templateName) * * @see DummyPlugin::onPageRendering() */ public function onPageRendering(&$twig, &$twigVariables, &$templateName) { // template name contains file extension since Pico 1.0 $fileExtension = ''; if (($fileExtensionPos = strrpos($templateName, '.')) !== false) { $fileExtension = substr($templateName, $fileExtensionPos); $templateName = substr($templateName, 0, $fileExtensionPos); } $this->triggerEvent('before_render', array(&$twigVariables, &$twig, &$templateName)); // add original file extension $templateName = $templateName . $fileExtension; } /** * Triggers the deprecated event after_render($output) * * @see DummyPlugin::onPageRendered() */ public function onPageRendered(&$output) { $this->triggerEvent('after_render', array(&$output)); } /** * Triggers a deprecated event on all plugins * * @param string $eventName event to trigger * @param array $params parameters to pass * @return void */ protected function triggerEvent($eventName, array $params = array()) { foreach ($this->getPlugins() as $plugin) { if (method_exists($plugin, $eventName)) { call_user_func_array(array($plugin, $eventName), $params); } } } }