PHP Класс Pico

Pico is a stupidly simple, blazing fast, flat file CMS. - Stupidly Simple: Pico makes creating and maintaining a website as simple as editing text files. - Blazing Fast: Pico is seriously lightweight and doesn't use a database, making it super fast. - No Database: Pico is a "flat file" CMS, meaning no database woes, no MySQL queries, nothing. - Markdown Formatting: Edit your website in your favourite text editor using simple Markdown formatting. - Twig Templates: Pico uses the Twig templating engine, for powerful and flexible themes. - Open Source: Pico is completely free and open source, released under the MIT license. See for more info.
Автор: Gilbert Pellegrom
Автор: Daniel Rudolf
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$config array | null Current configuration of this Pico instance
$configDir string Config directory of this Pico instance
$content string | null Parsed content being served
$currentPage array | null Data of the page being served
$locked boolean Boolean indicating whether Pico started processing yet
$meta array | null Meta data of the page to serve
$nextPage array | null Data of the next page relative to the page being served
$pages array[] | null List of known pages
$parsedown ParsedownExtra | null Parsedown Extra instance used for markdown parsing
$plugins object[] | null List of loaded plugins
$pluginsDir string Plugins directory of this Pico instance
$previousPage array | null Data of the previous page relative to the page being served
$rawContent string | null Raw, not yet parsed contents to serve
$requestFile string | null Absolute path to the content file being served
$requestUrl string | null Part of the URL describing the requested contents
$rootDir string Root directory of this Pico instance
$themesDir string Themes directory of this Pico instance
$twig Twig_Environment | null Twig instance used for template parsing
$twigVariables array | null Variables passed to the twig template

Открытые методы

Метод Описание
__construct ( string $rootDir, string $configDir, string $pluginsDir, string $themesDir ) Constructs a new Pico instance
getAbsolutePath ( string $path ) : string Makes a relative path absolute to Pico's root dir
getBaseUrl ( ) : string Returns the base URL of this Pico instance
getConfig ( string $configName = null ) : mixed Returns either the value of the specified config variable or the config array
getConfigDir ( ) : string Returns the config directory of this Pico instance
getCurrentPage ( ) : array | null Returns the data of the requested page
getFileContent ( ) : string | null Returns the cached contents of the requested page
getFileMeta ( ) : array | null Returns the parsed meta data of the requested page
getMetaHeaders ( ) : string[] Returns known meta headers and triggers the onMetaHeaders event
getNextPage ( ) : array | null Returns the data of the next page relative to the page being served
getPageUrl ( string $page, array | string $queryData = null ) : string Returns the URL to a given page
getPages ( ) : array[] | null Returns the list of known pages
getParsedown ( ) : ParsedownExtra | null Returns the Parsedown Extra markdown parser
getPlugin ( string $pluginName ) : object Returns the instance of a named plugin
getPlugins ( ) : object[] | null Returns all loaded plugins
getPluginsDir ( ) : string Returns the plugins directory of this Pico instance
getPreviousPage ( ) : array | null Returns the data of the previous page relative to the page being served
getRawContent ( ) : string | null Returns the raw contents, either of the requested or the 404 file
getRequestFile ( ) : string | null Returns the absolute path to the content file to serve
getRequestUrl ( ) : string | null Returns the URL where a user requested the page
getRootDir ( ) : string Returns the root directory of this Pico instance
getThemesDir ( ) : string Returns the themes directory of this Pico instance
getTwig ( ) : Twig_Environment | null Returns the twig template engine
isUrlRewritingEnabled ( ) : boolean Returns true if URL rewriting is enabled
load404Content ( string $file ) : string Returns the raw contents of the first found 404 file when traversing up from the directory the requested file is in
loadFileContent ( string $file ) : string Returns the raw contents of a file
parseFileContent ( string $content ) : string Parses the contents of a page using ParsedownExtra
parseFileMeta ( string $rawContent, array $headers ) : array Parses the file meta from raw file contents
prepareFileContent ( string $rawContent, array $meta ) : string Applies some static preparations to the raw contents of a page, e.g. removing the meta header and replacing %base_url%
run ( ) : string Runs this Pico instance
setConfig ( array $config ) : void Sets Pico's config before calling Pico::run()

Защищенные методы

Метод Описание
discoverCurrentPage ( ) : void Walks through the list of known pages and discovers the requested page as well as the previous and next page relative to it
discoverRequestFile ( ) : void Uses the request URL to discover the content file to serve
evaluateRequestUrl ( ) : void Evaluates the requested URL
getFiles ( string $directory, string $fileExtension = '', integer $order = self::SORT_ASC ) : array Recursively walks through a directory and returns all containing files matching the specified file extension
getTwigVariables ( ) : array Returns the variables passed to the template
loadConfig ( ) : void Loads the config.php from Pico::$configDir
loadPlugins ( ) : void Loads plugins from Pico::$pluginsDir in alphabetical order
readPages ( ) : void Reads the data of all pages known to Pico
registerParsedown ( ) : void Registers the Parsedown Extra markdown parser
registerTwig ( ) : void Registers the twig template engine
sortPages ( ) : void Sorts all pages known to Pico
triggerEvent ( string $eventName, array $params = [] ) : void Triggers events on plugins which implement PicoPluginInterface

Описание методов

__construct() публичный Метод

To carry out all the processing in Pico, call {@link Pico::run()}.
public __construct ( string $rootDir, string $configDir, string $pluginsDir, string $themesDir )
$rootDir string root directory of this Pico instance
$configDir string config directory of this Pico instance
$pluginsDir string plugins directory of this Pico instance
$themesDir string themes directory of this Pico instance

discoverCurrentPage() защищенный Метод

Walks through the list of known pages and discovers the requested page as well as the previous and next page relative to it
См. также: Pico::getCurrentPage()
См. также: Pico::getPreviousPage()
См. также: Pico::getNextPage()
protected discoverCurrentPage ( ) : void
Результат void

discoverRequestFile() защищенный Метод

Uses the request URL to discover the content file to serve
См. также: Pico::getRequestFile()
protected discoverRequestFile ( ) : void
Результат void

evaluateRequestUrl() защищенный Метод

Pico 1.0 uses the QUERY_STRING routing method (e.g. /pico/?sub/page) to support SEO-like URLs out-of-the-box with any webserver. You can still setup URL rewriting (e.g. using mod_rewrite on Apache) to basically remove the ? from URLs, but your rewritten URLs must follow the new QUERY_STRING principles. URL rewriting requires some special configuration on your webserver, but this should be "basic work" for any webmaster... Pico 0.9 and older required Apache with mod_rewrite enabled, thus old plugins, templates and contents may require you to enable URL rewriting to work. If you're upgrading from Pico 0.9, you will probably have to update your rewriting rules. We recommend you to use the link filter in templates to create internal links, e.g. {{ "sub/page"|link }} is equivalent to {{ base_url }}/sub/page and {{ base_url }}?sub/page, depending on enabled URL rewriting. In content files you can use the %base_url% variable; e.g. %base_url%?sub/page will be replaced accordingly.
См. также: Pico::getRequestUrl()
protected evaluateRequestUrl ( ) : void
Результат void

getAbsolutePath() публичный Метод

This method also guarantees a trailing slash.
public getAbsolutePath ( string $path ) : string
$path string relative or absolute path
Результат string absolute path

getBaseUrl() публичный Метод

Security Notice: You MUST configure Pico's base URL explicitly when using the base URL in contexts that are potentially vulnerable to HTTP Host Header Injection attacks (e.g. when generating emails).
public getBaseUrl ( ) : string
Результат string the base url

getConfig() публичный Метод

Returns either the value of the specified config variable or the config array
См. также: Pico::setConfig()
См. также: Pico::loadConfig()
public getConfig ( string $configName = null ) : mixed
$configName string optional name of a config variable
Результат mixed returns either the value of the named config variable, null if the config variable doesn't exist or the config array if no config name was supplied

getConfigDir() публичный Метод

Returns the config directory of this Pico instance
public getConfigDir ( ) : string
Результат string config directory path

getCurrentPage() публичный Метод

Returns the data of the requested page
См. также: Pico::discoverCurrentPage()
public getCurrentPage ( ) : array | null
Результат array | null page data

getFileContent() публичный Метод

Returns the cached contents of the requested page
См. также: Pico::prepareFileContent()
См. также: Pico::parseFileContent()
public getFileContent ( ) : string | null
Результат string | null parsed contents

getFileMeta() публичный Метод

Returns the parsed meta data of the requested page
См. также: Pico::parseFileMeta()
public getFileMeta ( ) : array | null
Результат array | null parsed meta data

getFiles() защищенный Метод

Recursively walks through a directory and returns all containing files matching the specified file extension
protected getFiles ( string $directory, string $fileExtension = '', integer $order = self::SORT_ASC ) : array
$directory string start directory
$fileExtension string return files with the given file extension only (optional)
$order integer specify whether and how files should be sorted; use Pico::SORT_ASC for a alphabetical ascending order (this is the default behaviour), Pico::SORT_DESC for a descending order or Pico::SORT_NONE to leave the result unsorted
Результат array list of found files

getMetaHeaders() публичный Метод

Heads up! Calling this method triggers the onMetaHeaders event. Keep this in mind to prevent a infinite loop!
public getMetaHeaders ( ) : string[]
Результат string[] known meta headers; the array value specifies the YAML key to search for, the array key is later used to access the found value

getNextPage() публичный Метод

Returns the data of the next page relative to the page being served
См. также: Pico::discoverCurrentPage()
public getNextPage ( ) : array | null
Результат array | null page data

getPageUrl() публичный Метод

Returns the URL to a given page
public getPageUrl ( string $page, array | string $queryData = null ) : string
$page string identifier of the page to link to
$queryData array | string either an array containing properties to create a URL-encoded query string from, or a already encoded string
Результат string URL

getPages() публичный Метод

Returns the list of known pages
См. также: Pico::readPages()
См. также: Pico::sortPages()
public getPages ( ) : array[] | null
Результат array[] | null the data of all pages

getParsedown() публичный Метод

Returns the Parsedown Extra markdown parser
См. также: Pico::registerParsedown()
public getParsedown ( ) : ParsedownExtra | null
Результат ParsedownExtra | null Parsedown Extra markdown parser

getPlugin() публичный Метод

Plugins SHOULD implement {@link PicoPluginInterface}, but you MUST NOT rely on it. For more information see {@link PicoPluginInterface}.
См. также: Pico::loadPlugins()
См. также: Pico::getPlugins()
public getPlugin ( string $pluginName ) : object
$pluginName string name of the plugin
Результат object instance of the plugin

getPlugins() публичный Метод

Returns all loaded plugins
См. также: Pico::loadPlugins()
См. также: Pico::getPlugin()
public getPlugins ( ) : object[] | null
Результат object[] | null

getPluginsDir() публичный Метод

Returns the plugins directory of this Pico instance
public getPluginsDir ( ) : string
Результат string plugins directory path

getPreviousPage() публичный Метод

Returns the data of the previous page relative to the page being served
См. также: Pico::discoverCurrentPage()
public getPreviousPage ( ) : array | null
Результат array | null page data

getRawContent() публичный Метод

Returns the raw contents, either of the requested or the 404 file
См. также: Pico::loadFileContent()
См. также: Pico::load404Content()
public getRawContent ( ) : string | null
Результат string | null raw contents

getRequestFile() публичный Метод

Returns the absolute path to the content file to serve
См. также: Pico::discoverRequestFile()
public getRequestFile ( ) : string | null
Результат string | null file path

getRequestUrl() публичный Метод

Returns the URL where a user requested the page
См. также: Pico::evaluateRequestUrl()
public getRequestUrl ( ) : string | null
Результат string | null request URL

getRootDir() публичный Метод

Returns the root directory of this Pico instance
public getRootDir ( ) : string
Результат string root directory path

getThemesDir() публичный Метод

Returns the themes directory of this Pico instance
public getThemesDir ( ) : string
Результат string themes directory path

getTwig() публичный Метод

Returns the twig template engine
См. также: Pico::registerTwig()
public getTwig ( ) : Twig_Environment | null
Результат Twig_Environment | null Twig template engine

getTwigVariables() защищенный Метод

URLs and paths (namely base_dir, base_url, theme_dir and theme_url) don't add a trailing slash for historic reasons.
protected getTwigVariables ( ) : array
Результат array template variables

isUrlRewritingEnabled() публичный Метод

Returns true if URL rewriting is enabled
public isUrlRewritingEnabled ( ) : boolean
Результат boolean true if URL rewriting is enabled, false otherwise

load404Content() публичный Метод

Returns the raw contents of the first found 404 file when traversing up from the directory the requested file is in
См. также: Pico::getRawContent()
public load404Content ( string $file ) : string
$file string path to requested (but not existing) file
Результат string raw contents of the 404 file

loadConfig() защищенный Метод

Loads the config.php from Pico::$configDir
См. также: Pico::setConfig()
См. также: Pico::getConfig()
protected loadConfig ( ) : void
Результат void

loadFileContent() публичный Метод

Returns the raw contents of a file
См. также: Pico::getRawContent()
public loadFileContent ( string $file ) : string
$file string file path
Результат string raw contents of the file

loadPlugins() защищенный Метод

Plugin files MAY be prefixed by a number (e.g. 00-PicoDeprecated.php) to indicate their processing order. Plugins without a prefix will be loaded last. If you want to use a prefix, you MUST consider the following directives: - 00 to 19: Reserved - 20 to 39: Low level code helper plugins - 40 to 59: Plugins manipulating routing or the pages array - 60 to 79: Plugins hooking into template or markdown parsing - 80 to 99: Plugins using the onPageRendered event
См. также: Pico::getPlugin()
См. также: Pico::getPlugins()
protected loadPlugins ( ) : void
Результат void

parseFileContent() публичный Метод

Parses the contents of a page using ParsedownExtra
См. также: Pico::prepareFileContent()
См. также: Pico::getFileContent()
public parseFileContent ( string $content ) : string
$content string raw contents of a page (Markdown)
Результат string parsed contents (HTML)

parseFileMeta() публичный Метод

Meta data MUST start on the first line of the file, either opened and closed by --- or C-style block comments (deprecated). The headers are parsed by the YAML component of the Symfony project, keys are lowered. If you're a plugin developer, you MUST register new headers during the onMetaHeaders event first. The implicit availability of headers is for users and pure (!) theme developers ONLY.
См. также: Pico::getFileMeta()
См. также: http://symfony.com/doc/current/components/yaml/introduction.html
public parseFileMeta ( string $rawContent, array $headers ) : array
$rawContent string the raw file contents
$headers array known meta headers
Результат array parsed meta data

prepareFileContent() публичный Метод

Applies some static preparations to the raw contents of a page, e.g. removing the meta header and replacing %base_url%
См. также: Pico::parseFileContent()
См. также: Pico::getFileContent()
public prepareFileContent ( string $rawContent, array $meta ) : string
$rawContent string raw contents of a page
$meta array meta data to use for %meta.*% replacement
Результат string contents prepared for parsing

readPages() защищенный Метод

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 |
См. также: Pico::sortPages()
См. также: Pico::getPages()
protected readPages ( ) : void
Результат void

registerParsedown() защищенный Метод

Registers the Parsedown Extra markdown parser
См. также: Pico::getParsedown()
protected registerParsedown ( ) : void
Результат void

registerTwig() защищенный Метод

This method also registers Pico's core Twig filters link and content as well as Pico's {@link PicoTwigExtension} Twig extension.
См. также: Pico::getTwig()
protected registerTwig ( ) : void
Результат void

run() публичный Метод

Loads plugins, evaluates the config file, does URL routing, parses meta headers, processes Markdown, does Twig processing and returns the rendered contents.
public run ( ) : string
Результат string rendered Pico contents

setConfig() публичный Метод

This method allows you to modify Pico's config without creating a {@path "config/config.php"} or changing some of its variables before Pico starts processing. You can call this method between {@link Pico::__construct()} and {@link Pico::run()} only. Options set with this method cannot be overwritten by {@path "config/config.php"}.
См. также: Pico::loadConfig()
См. также: Pico::getConfig()
public setConfig ( array $config ) : void
$config array array with config variables
Результат void

sortPages() защищенный Метод

Sorts all pages known to Pico
См. также: Pico::readPages()
См. также: Pico::getPages()
protected sortPages ( ) : void
Результат void

triggerEvent() защищенный Метод

Deprecated events (as used by plugins not implementing {@link PicoPluginInterface}) are triggered by {@link PicoDeprecated}.
См. также: PicoPluginInterface
См. также: AbstractPicoPlugin
См. также: DummyPlugin
protected triggerEvent ( string $eventName, array $params = [] ) : void
$eventName string name of the event to trigger
$params array optional parameters to pass
Результат void

Описание свойств

$config защищенное свойство

Current configuration of this Pico instance
См. также: Pico::getConfig()
protected array|null $config
Результат array | null

$configDir защищенное свойство

Config directory of this Pico instance
См. также: Pico::getConfigDir()
protected string $configDir
Результат string

$content защищенное свойство

Parsed content being served
См. также: Pico::getFileContent()
protected string|null $content
Результат string | null

$currentPage защищенное свойство

Data of the page being served
См. также: Pico::getCurrentPage()
protected array|null $currentPage
Результат array | null

$locked защищенное свойство

Boolean indicating whether Pico started processing yet
protected bool $locked
Результат boolean

$meta защищенное свойство

Meta data of the page to serve
См. также: Pico::getFileMeta()
protected array|null $meta
Результат array | null

$nextPage защищенное свойство

Data of the next page relative to the page being served
См. также: Pico::getNextPage()
protected array|null $nextPage
Результат array | null

$pages защищенное свойство

List of known pages
См. также: Pico::getPages()
protected array[]|null $pages
Результат array[] | null

$parsedown защищенное свойство

Parsedown Extra instance used for markdown parsing
См. также: Pico::getParsedown()
protected ParsedownExtra|null $parsedown
Результат ParsedownExtra | null

$plugins защищенное свойство

List of loaded plugins
См. также: Pico::getPlugins()
protected object[]|null $plugins
Результат object[] | null

$pluginsDir защищенное свойство

Plugins directory of this Pico instance
См. также: Pico::getPluginsDir()
protected string $pluginsDir
Результат string

$previousPage защищенное свойство

Data of the previous page relative to the page being served
См. также: Pico::getPreviousPage()
protected array|null $previousPage
Результат array | null

$rawContent защищенное свойство

Raw, not yet parsed contents to serve
См. также: Pico::getRawContent()
protected string|null $rawContent
Результат string | null

$requestFile защищенное свойство

Absolute path to the content file being served
См. также: Pico::getRequestFile()
protected string|null $requestFile
Результат string | null

$requestUrl защищенное свойство

Part of the URL describing the requested contents
См. также: Pico::getRequestUrl()
protected string|null $requestUrl
Результат string | null

$rootDir защищенное свойство

Root directory of this Pico instance
См. также: Pico::getRootDir()
protected string $rootDir
Результат string

$themesDir защищенное свойство

Themes directory of this Pico instance
См. также: Pico::getThemesDir()
protected string $themesDir
Результат string

$twig защищенное свойство

Twig instance used for template parsing
См. также: Pico::getTwig()
protected Twig_Environment|null $twig
Результат Twig_Environment | null

$twigVariables защищенное свойство

Variables passed to the twig template
См. также: Pico::getTwigVariables
protected array|null $twigVariables
Результат array | null