* @source http://www.dokuwiki.org/plugin:flmod */ // http://www.dokuwiki.org/plugin:avtaskbox?s[]=doku&s[]=lexer&s[]=exit source of the preg_match // http://www.brightcherry.co.uk/scribbles/php-adding-and-subtracting-dates/ source of the date subtraction /* * *** Config *** * Enable shellexecute only if you are on a private Wiki. It will implement a HUGE security hole * To enable shellexecute change it to true. * shellexecute = TRUE; */ $_shellexecute = FALSE; if (!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/'); if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); require_once(DOKU_PLUGIN . 'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_filelastmodified extends DokuWiki_Syntax_Plugin { function getInfo() { return array( 'author' => 'Per-Nils Snygg', 'email' => 'pernils@smpparts.com', 'date' => '2012-05-01', 'name' => 'File last modified/saved', 'desc' => 'Give notifcation if the file have been saved/modified in current timeframe', 'url' => 'http://www.dokuwiki.org/plugin:flmod', ); } function getType() { return 'substition'; } function getAllowedTypes() { return array(); } function getPType() { return 'normal'; } function getSort() { return 999; } function connectTo($mode) { $this->Lexer->addEntryPattern('', $mode, 'plugin_filelastmodified'); } function postConnect() { $this->Lexer->addExitPattern('', 'plugin_filelastmodified'); } function _help_text() { // string heredoc $output = <<< HEREDOC Syntax :
filename: your_file.txt
timeframe: how many days to look back on
shellexec: your_shell_comand
text: Here you put your text that will be displayed when the file is newer then the timeframe. Here you can also get some output from variables.
The variables is :
@filename (the same as filename: )
@timeframe (the same as timeframe: )
@filedate (the date of the file )
@days (how many days it was to it was last modified
@today (current date)
Always start the text area with @filename because it have some debugging information. You can remove it when it works
To enable shellexec: you must set the _shellexecute to true in the beginning of syntax.php in the plugin folder.
To remove this help text include
show_help: disable

Example..
<flmod>
filename: /var/www/index.html
timeframe: 6
shellexec: cp /var/www/index.html /home/backup/index.html
show_help: disable
text: The @filename was updated on @filedate.
It was @days ago. Today it is @today.
I have now made a backup to /home/backup
</flmod> HEREDOC; return ($output); } function handle($match, $state, $pos, &$handler) { GLOBAL $_shellexecute; switch ($state) { case DOKU_LEXER_ENTER : break; case DOKU_LEXER_MATCHED : break; case DOKU_LEXER_UNMATCHED : preg_match('/^Filename:(.*?)$/isxm', $match, $matches); $filename = (!empty($matches[1]) && strlen(trim($matches[1])) > 0) ? trim($matches[1]) : 'No file is given! e.g Filename: [path]/your_file.txt'; preg_match('/^Timeframe:(.*?)$/isxm', $match, $matches); $timeframe = (!empty($matches[1]) && strlen(trim($matches[1])) > 0) ? intval(preg_replace('[^0-9]', '', $matches[1])) : 0; preg_match('/^ShellExec:(.*?)$/isxm', $match, $matches); $shellexec = (!empty($matches[1]) && strlen(trim($matches[1])) > 0) ? trim($matches[1]) : ''; preg_match('/^Show_help:(.*?)$/isxm', $match, $matches); $show_help = (!empty($matches[1]) && strlen(trim($matches[1])) > 0) ? trim($matches[1]) : 'enabled'; preg_match('/Text:(.*)/isx', $match, $matches); $text = (!empty($matches[1]) && strlen(trim($matches[1])) > 0) ? trim($matches[1]) : ''; ($show_help == 'enabled') ? $match = $this->_help_text() : $match = ''; // include help text or not if (file_exists($filename)) { $filedate = date("Y-m-d", filemtime($filename)); // $filedate .. date of the file $today_array = getdate(); // $today .. current date $today = $today_array[year] . '-' . $today_array[mon] . '-' . $today_array[mday]; $days = (strtotime($today) - strtotime($filedate)) / (60 * 60 * 24); // $days .. is how many days ago it was modified } else { $filename = '
The file :' . $filename . ' couldn\ be found!
'; } if ($timeframe > $days || $timeframe == 0) { // simpel parser $search = array("\r\n", "@filename", "@filedate", "@days", "@today", "@timeframe"); $replace = array('
', $filename, $filedate, $days, $today, $timeframe); $str = str_replace($search, $replace, $text); $match .= $str; } if ($_shellexecute) { $output = shell_exec($shellexec); $match .=$output; } return array($state, $match); case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : break; } return array(); } function render($mode, &$renderer, $data) { if ($mode == 'xhtml') { list($state, $match) = $data; switch ($state) { case DOKU_LEXER_ENTER : break; case DOKU_LEXER_MATCHED : break; case DOKU_LEXER_UNMATCHED : $renderer->doc .= $match . '
'; break; case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : break; } return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>