Created
July 14, 2019 12:21
-
-
Save PhrozenByte/e8d73c2aa8013efa679d78e25ceec97e 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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']) { | |
$fileName = $this->getConfig('content_dir') . $pageData['id'] . $this->getConfig('content_ext'); | |
if (is_file($fileName) && !isset($pageData['modificationTime'])) { | |
$pageData['modificationTime'] = filemtime($fileName); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PhrozenByte That's a great idea!
By the way, I read this: https://github.com/picocms/Pico/blob/master/plugins/DummyPlugin.php
I just don't have the best idea where to put the HTTP Caching script. I normally put it on index.php. Something like this:
I wish I could done it better.
EDIT:
Was it
onMetaParsed
oronContentParsing
? I assumed it's safe to executeexit;
under a Pico plugin.