Pico/plugins/DummyPlugin.php

517 lines
13 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of Pico. It's copyrighted by the contributors recorded
* in the version control history of the file, available from the following
* original location:
*
* <https://github.com/picocms/Pico/blob/master/plugins/DummyPlugin.php>
*
* SPDX-License-Identifier: MIT
* License-Filename: LICENSE
*/
/**
* Pico dummy plugin - a template for plugins
*
* You're a plugin developer? This template may be helpful :-)
* Simply remove the events you don't need and add your own logic.
*
* @author Daniel Rudolf
* @link http://picocms.org
2016-05-23 13:13:56 +00:00
* @license http://opensource.org/licenses/MIT The MIT License
2016-12-12 14:31:06 +00:00
* @version 2.0
*/
2017-05-07 12:15:24 +00:00
class DummyPlugin extends AbstractPicoPlugin
{
2017-05-10 15:00:48 +00:00
/**
* API version used by this plugin
*
* @var int
*/
const API_VERSION = 2;
/**
2017-05-07 12:15:24 +00:00
* This plugin is disabled by default
*
* If you want to enable your plugin by default, simply remove this class
* property.
*
* @see AbstractPicoPlugin::$enabled
* @var bool
*/
protected $enabled = false;
/**
* This plugin depends on ...
*
2017-05-07 12:15:24 +00:00
* If your plugin doesn't depend on any other plugin, remove this class
* property.
*
* @see AbstractPicoPlugin::$dependsOn
* @var string[]
*/
protected $dependsOn = array();
/**
2015-10-09 18:51:07 +00:00
* Triggered after Pico has loaded all available plugins
*
* This event is triggered nevertheless the plugin is enabled or not.
* It is NOT guaranteed that plugin dependencies are fulfilled!
*
2017-11-18 17:27:20 +00:00
* @see Pico::loadPlugin()
* @see Pico::getPlugin()
* @see Pico::getPlugins()
*
* @param object[] $plugins loaded plugin instances
*
* @return void
*/
public function onPluginsLoaded(array $plugins)
{
// your code
}
/**
* Triggered when Pico manually loads a plugin
*
2017-11-18 17:27:20 +00:00
* @see Pico::loadPlugin()
* @see Pico::getPlugin()
* @see Pico::getPlugins()
*
* @param object $plugin loaded plugin instance
*
* @return void
*/
public function onPluginManuallyLoaded($plugin)
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has read its configuration
*
* @see Pico::getConfig()
2017-11-18 17:27:20 +00:00
* @see Pico::getBaseUrl()
* @see Pico::getBaseThemeUrl()
* @see Pico::isUrlRewritingEnabled()
*
* @param array &$config array of config variables
*
* @return void
*/
2015-11-25 03:07:46 +00:00
public function onConfigLoaded(array &$config)
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has evaluated the request URL
*
* @see Pico::getRequestUrl()
*
* @param string &$url part of the URL describing the requested contents
*
* @return void
*/
public function onRequestUrl(&$url)
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has discovered the content file to serve
*
2017-11-18 17:27:20 +00:00
* @see Pico::resolveFilePath()
* @see Pico::getRequestFile()
*
* @param string &$file absolute path to the content file to serve
*
* @return void
*/
public function onRequestFile(&$file)
{
// your code
}
/**
* Triggered before Pico reads the contents of the file to serve
*
* @see Pico::loadFileContent()
* @see DummyPlugin::onContentLoaded()
*
* @return void
*/
public function onContentLoading()
{
// your code
}
/**
2017-05-13 16:17:58 +00:00
* Triggered before Pico reads the contents of a 404 file
*
* @see Pico::load404Content()
* @see DummyPlugin::on404ContentLoaded()
*
* @return void
*/
public function on404ContentLoading()
{
// your code
}
/**
2017-05-13 16:17:58 +00:00
* Triggered after Pico has read the contents of the 404 file
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::on404ContentLoading()
* @see Pico::getRawContent()
2017-11-18 17:27:20 +00:00
* @see Pico::is404Content()
*
* @param string &$rawContent raw file contents
*
* @return void
*/
2017-05-13 16:17:58 +00:00
public function on404ContentLoaded(&$rawContent)
{
// your code
}
/**
2017-05-13 16:17:58 +00:00
* Triggered after Pico has read the contents of the file to serve
*
* If Pico serves a 404 file, this event is triggered with the raw contents
* of said 404 file. Use {@see Pico::is404Content()} to check for this
* case when necessary.
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onContentLoading()
* @see Pico::getRawContent()
2017-11-18 17:27:20 +00:00
* @see Pico::is404Content()
*
* @param string &$rawContent raw file contents
*
* @return void
*/
2017-05-13 16:17:58 +00:00
public function onContentLoaded(&$rawContent)
{
// your code
}
/**
* Triggered before Pico parses the meta header
*
* @see Pico::parseFileMeta()
* @see DummyPlugin::onMetaParsed()
*
* @return void
*/
public function onMetaParsing()
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has parsed the meta header
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onMetaParsing()
* @see Pico::getFileMeta()
*
* @param string[] &$meta parsed meta data
*
* @return void
*/
2015-11-25 03:07:46 +00:00
public function onMetaParsed(array &$meta)
{
// your code
}
/**
* Triggered before Pico parses the pages content
*
* @see Pico::prepareFileContent()
2017-11-18 17:27:20 +00:00
* @see Pico::substituteFileContent()
* @see DummyPlugin::onContentPrepared()
* @see DummyPlugin::onContentParsed()
*
* @return void
*/
public function onContentParsing()
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has prepared the raw file contents for parsing
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onContentParsing()
* @see Pico::parseFileContent()
* @see DummyPlugin::onContentParsed()
*
* @param string &$markdown Markdown contents of the requested page
*
* @return void
*/
2017-07-14 18:50:38 +00:00
public function onContentPrepared(&$markdown)
{
// your code
}
/**
2015-10-09 15:35:15 +00:00
* Triggered after Pico has parsed the contents of the file to serve
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onContentParsing()
* @see DummyPlugin::onContentPrepared()
* @see Pico::getFileContent()
*
* @param string &$content parsed contents (HTML) of the requested page
*
* @return void
*/
public function onContentParsed(&$content)
{
// your code
}
/**
* Triggered before Pico reads all known pages
*
* @see DummyPlugin::onPagesDiscovered()
* @see DummyPlugin::onPagesLoaded()
*
* @return void
*/
public function onPagesLoading()
{
// your code
}
/**
2017-05-07 12:15:24 +00:00
* Triggered before Pico loads a single page
*
* Set the `$skipFile` parameter to TRUE to remove this page from the pages
* array. Pico usually passes NULL by default, unless it is a conflicting
* page (i.e. `content/sub.md`, but there's also a `content/sub/index.md`),
* then it passes TRUE. Don't change this value incautiously if it isn't
* NULL! Someone likely set it to TRUE or FALSE on purpose...
*
* @see DummyPlugin::onSinglePageContent()
* @see DummyPlugin::onSinglePageLoaded()
*
* @param string $id relative path to the content file
* @param bool|null $skipPage set this to TRUE to remove this page from the
* pages array, otherwise leave it unchanged
*
2017-05-07 12:15:24 +00:00
* @return void
*/
public function onSinglePageLoading($id, &$skipPage)
2017-05-07 12:15:24 +00:00
{
// your code
}
2017-05-13 23:26:29 +00:00
/**
* Triggered when Pico loads the raw contents of a single page
*
* Please note that this event isn't triggered when the currently processed
* page is the requested page. The reason for this exception is that the
* raw contents of this page were loaded already.
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onSinglePageLoading()
* @see DummyPlugin::onSinglePageLoaded()
*
* @param string $id relative path to the content file
* @param string &$rawContent raw file contents
*
2017-05-13 23:26:29 +00:00
* @return void
*/
public function onSinglePageContent($id, &$rawContent)
{
// your code
}
2017-05-07 12:15:24 +00:00
/**
* Triggered when Pico loads a single page
*
2017-11-18 17:27:20 +00:00
* Please refer to {@see Pico::readPages()} for information about the
* structure of a single page's data.
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onSinglePageLoading()
* @see DummyPlugin::onSinglePageContent()
*
* @param array &$pageData data of the loaded page
2017-05-07 12:15:24 +00:00
*
* @return void
*/
2015-11-25 03:07:46 +00:00
public function onSinglePageLoaded(array &$pageData)
{
// your code
}
/**
* Triggered after Pico has discovered all known pages
*
2017-11-18 17:27:20 +00:00
* Pico's pages array isn't sorted until the `onPagesLoaded` event is
* triggered. Please refer to {@see Pico::readPages()} for information
* about the structure of Pico's pages array and the structure of a single
* page's data.
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onPagesLoading()
* @see DummyPlugin::onPagesLoaded()
*
2017-11-18 17:27:20 +00:00
* @param array[] &$pages list of all known pages
*
* @return void
*/
public function onPagesDiscovered(array &$pages)
{
// your code
}
/**
* Triggered after Pico has sorted the pages array
*
2017-11-18 17:27:20 +00:00
* Please refer to {@see Pico::readPages()} for information about the
* structure of Pico's pages array and the structure of a single page's
* data.
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onPagesLoading()
* @see DummyPlugin::onPagesDiscovered()
* @see Pico::getPages()
*
2017-11-18 17:27:20 +00:00
* @param array[] &$pages sorted list of all known pages
*
* @return void
*/
public function onPagesLoaded(array &$pages)
{
// your code
}
/**
* Triggered when Pico discovered the current, previous and next pages
*
2017-11-18 17:27:20 +00:00
* If Pico isn't serving a regular page, but a plugin's virtual page, there
* will neither be a current, nor previous or next pages. Please refer to
* {@see Pico::readPages()} for information about the structure of a single
* page's data.
*
* @see Pico::getCurrentPage()
* @see Pico::getPreviousPage()
* @see Pico::getNextPage()
*
* @param array|null &$currentPage data of the page being served
* @param array|null &$previousPage data of the previous page
* @param array|null &$nextPage data of the next page
*
* @return void
*/
public function onCurrentPageDiscovered(
array &$currentPage = null,
array &$previousPage = null,
array &$nextPage = null
) {
// your code
}
/**
Add Pico::buildPageTree() Pico's page tree is a list of all the tree's branches (no matter the depth). Thus, by iterating a array element, you get the nodes of a given branch. All leaf nodes do represent a page, but inner nodes may or may not represent a page (e.g. if there's a `sub/page.md`, but neither a `sub/index.md` nor a `sub.md`, the inner node `sub`, that is the parent of the `sub/page` node, represents no page itself). A page's file path describes its node's path in the tree (e.g. the page `sub/page.md` is represented by the `sub/page` node, thus a child of the `sub` node and a element of the `sub` branch). However, the index page of a folder (e.g. `sub/index.md`), is *not* a node of the `sub` branch, but rather of the `/` branch. The page's node is not `sub/index`, but `sub`. If two pages are described by the same node (e.g. if both a `sub/index.md` and a `sub.md` exist), the index page takes precedence. Pico's main index page (i.e. `index.md`) is represented by the tree's root node `/` and a special case: it is the only node of the `` (i.e. the empty string) branch. A node is represented by an array with the keys `id`, `page` and `children`. The `id` key contains a string with the node's name. If the node represents a page, the `page` key is a reference to the page's data array. If the node is a inner node, the `children` key is a reference to its matching branch (i.e. a list of the node's children). The order of a node's children matches the order in Pico's pages array. If you want to walk the whole page tree, start with the tree's root node at `$pageTree[""]["/"]`. The root node's `children` key is a reference to the `/` branch at `$pageTree["/"]`, that is a list of the root node's direct child nodes and their siblings. You MUST NOT iterate the page tree itself (i.e. the list of the tree's branches), its order is undefined and the array will be replaced by a non-iterable data structure with Pico 3.0.
2017-11-18 17:34:57 +00:00
* Triggered after Pico built the page tree
*
* Please refer to {@see Pico::buildPageTree()} for information about
* the structure of Pico's page tree array.
*
* @see Pico::getPageTree()
*
* @param array &$pageTree page tree
*
* @return void
*/
public function onPageTreeBuilt(array &$pageTree)
{
// your code
}
/**
* Triggered before Pico renders the page
*
* @see DummyPlugin::onPageRendered()
*
* @param string &$templateName file name of the template
* @param array &$twigVariables template variables
*
* @return void
*/
public function onPageRendering(&$templateName, array &$twigVariables)
{
// your code
}
/**
* Triggered after Pico has rendered the page
*
2017-11-18 17:27:20 +00:00
* @see DummyPlugin::onPageRendering()
*
* @param string &$output contents which will be sent to the user
*
* @return void
*/
public function onPageRendered(&$output)
{
// your code
}
2017-05-13 23:25:10 +00:00
/**
* Triggered when Pico reads its known meta header fields
*
* @see Pico::getMetaHeaders()
*
* @param string[] &$headers list of known meta header fields; the array
* key specifies the YAML key to search for, the array value is later
* used to access the found value
*
2017-05-13 23:25:10 +00:00
* @return void
*/
public function onMetaHeaders(array &$headers)
{
// your code
}
/**
* Triggered when Pico registers the YAML parser
*
* @see Pico::getYamlParser()
*
* @param \Symfony\Component\Yaml\Parser &$yamlParser YAML parser instance
*
* @return void
*/
public function onYamlParserRegistered(\Symfony\Component\Yaml\Parser &$yamlParser)
{
// your code
}
/**
* Triggered when Pico registers the Parsedown parser
*
* @see Pico::getParsedown()
*
* @param Parsedown &$parsedown Parsedown instance
*
* @return void
*/
public function onParsedownRegistered(Parsedown &$parsedown)
{
// your code
}
/**
* Triggered when Pico registers the twig template engine
*
* @see Pico::getTwig()
*
* @param Twig_Environment &$twig Twig instance
*
* @return void
*/
public function onTwigRegistered(Twig_Environment &$twig)
{
// your code
}
}