Skip to content

Instantly share code, notes, and snippets.

@gphg
Forked from PhrozenByte/PicoPageModPlugin.php
Last active July 13, 2020 01:53
Show Gist options
  • Save gphg/8e265e4ebb3bf81378776251f6ad2766 to your computer and use it in GitHub Desktop.
Save gphg/8e265e4ebb3bf81378776251f6ad2766 to your computer and use it in GitHub Desktop.
A simple Pico plugin adding a page's last modification time to its page data. Pico is a stupidly simple, blazing fast, flat file CMS. http://picocms.org/
<?php
/**
* Pico page modification time plugin
*
* Adds a page's last modification time to its page data.
*
* Example:
*
* ```twig
* <p>Last modified: {{ current_page.modificationTime|date("Y-m-d H:i:s") }}</p>
* ```
*
* @author Daniel Rudolf
* @link http://picocms.org
* @license http://opensource.org/licenses/MIT The MIT License
* @version 0.0.1
*/
class PicoPageModPlugin extends AbstractPicoPlugin
{
const API_VERSION = 2;
public function onSinglePageLoaded(array &$pageData)
{
if ($pageData['id']) {
$pageData['modificationTime'] = (isset($pageData['modificationTime']) ? $pageData['modificationTime'] : null);
$pageData['modificationTime'] = (isset($pageData['meta']['modificationTime']) ? $pageData['meta']['modificationTime'] : $pageData['modificationTime']);
// Fallback to filemtime()
if (is_file($fileName) && is_null($pageData['modificationTime'])) {
$fileName = $this->getConfig('content_dir') . $pageData['id'] . $this->getConfig('content_ext');
$pageData['modificationTime'] = filemtime($fileName);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment