diff options
author | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-23 10:39:45 +0100 |
---|---|---|
committer | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-23 10:39:45 +0100 |
commit | 35838d22a57707952f630eaf9f9e9ab4c6c3cfb0 (patch) | |
tree | 3603e2e56314af40a4b7922e14e52c0bc06f6f9d /lib/plugins/popularity/action.php | |
parent | c4bb7947fcb2d4a5e5f8a15d9e3bbec333e44e13 (diff) | |
parent | ee1214abb2c14cf0f86ff6d9a5b49536c6b01e18 (diff) | |
download | rpg-35838d22a57707952f630eaf9f9e9ab4c6c3cfb0.tar.gz rpg-35838d22a57707952f630eaf9f9e9ab4c6c3cfb0.tar.bz2 |
jQuery rewrite branch merged into master branch of whole project
Diffstat (limited to 'lib/plugins/popularity/action.php')
-rw-r--r-- | lib/plugins/popularity/action.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php new file mode 100644 index 000000000..bf11efba6 --- /dev/null +++ b/lib/plugins/popularity/action.php @@ -0,0 +1,57 @@ +<?php +/** + * Popularity Feedback Plugin + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + */ + +require_once(DOKU_PLUGIN.'action.php'); +require_once(DOKU_PLUGIN.'popularity/admin.php'); + +class action_plugin_popularity extends Dokuwiki_Action_Plugin { + var $helper; + + function action_plugin_popularity(){ + $this->helper = $this->loadHelper('popularity', false); + } + + /** + * Register its handlers with the dokuwiki's event controller + */ + function register(&$controller) { + $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); + } + + function _autosubmit(&$event, $param){ + //Do we have to send the data now + if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){ + return; + } + + //Actually send it + $status = $this->helper->sendData( $this->helper->gatherAsString() ); + + + if ( $status !== '' ){ + //If an error occured, log it + io_saveFile( $this->helper->autosubmitErrorFile, $status ); + } else { + //If the data has been sent successfully, previous log of errors are useless + @unlink($this->helper->autosubmitErrorFile); + //Update the last time we sent data + touch ( $this->helper->autosubmitFile ); + } + + $event->stopPropagation(); + $event->preventDefault(); + } + + /** + * Check if it's time to send autosubmit data + * (we should have check if autosubmit is enabled first) + */ + function _isTooEarlyToSubmit(){ + $lastSubmit = $this->helper->lastSentTime(); + return $lastSubmit + 24*60*60*30 > time(); + } +} |