18596046dSAndreas Gohr<?php 28596046dSAndreas Gohr/** 38596046dSAndreas Gohr * Popularity Feedback Plugin 48596046dSAndreas Gohr * 58596046dSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 68596046dSAndreas Gohr */ 78596046dSAndreas Gohr 88596046dSAndreas Gohrrequire_once(DOKU_PLUGIN.'action.php'); 98596046dSAndreas Gohrrequire_once(DOKU_PLUGIN.'popularity/admin.php'); 108596046dSAndreas Gohr 118596046dSAndreas Gohrclass action_plugin_popularity extends Dokuwiki_Action_Plugin { 12*38479cbbSDominik Eckelmann 13*38479cbbSDominik Eckelmann /** 14*38479cbbSDominik Eckelmann * @var helper_plugin_popularity 15*38479cbbSDominik Eckelmann */ 168596046dSAndreas Gohr var $helper; 178596046dSAndreas Gohr 188596046dSAndreas Gohr function action_plugin_popularity(){ 198596046dSAndreas Gohr $this->helper = $this->loadHelper('popularity', false); 208596046dSAndreas Gohr } 218596046dSAndreas Gohr 228596046dSAndreas Gohr /** 238596046dSAndreas Gohr * Register its handlers with the dokuwiki's event controller 248596046dSAndreas Gohr */ 25e8b5a4f9SAndreas Gohr function register(Doku_Event_Handler $controller) { 268596046dSAndreas Gohr $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); 278596046dSAndreas Gohr } 288596046dSAndreas Gohr 29*38479cbbSDominik Eckelmann function _autosubmit(Doku_Event &$event, $param){ 308596046dSAndreas Gohr //Do we have to send the data now 318596046dSAndreas Gohr if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){ 328596046dSAndreas Gohr return; 338596046dSAndreas Gohr } 348596046dSAndreas Gohr 358596046dSAndreas Gohr //Actually send it 368596046dSAndreas Gohr $status = $this->helper->sendData( $this->helper->gatherAsString() ); 378596046dSAndreas Gohr 388596046dSAndreas Gohr 398596046dSAndreas Gohr if ( $status !== '' ){ 408596046dSAndreas Gohr //If an error occured, log it 418596046dSAndreas Gohr io_saveFile( $this->helper->autosubmitErrorFile, $status ); 428596046dSAndreas Gohr } else { 438596046dSAndreas Gohr //If the data has been sent successfully, previous log of errors are useless 448596046dSAndreas Gohr @unlink($this->helper->autosubmitErrorFile); 458596046dSAndreas Gohr //Update the last time we sent data 468596046dSAndreas Gohr touch ( $this->helper->autosubmitFile ); 478596046dSAndreas Gohr } 488596046dSAndreas Gohr 498596046dSAndreas Gohr $event->stopPropagation(); 508596046dSAndreas Gohr $event->preventDefault(); 518596046dSAndreas Gohr } 528596046dSAndreas Gohr 538596046dSAndreas Gohr /** 548596046dSAndreas Gohr * Check if it's time to send autosubmit data 555827ba0bSGuillaume Turri * (we should have check if autosubmit is enabled first) 568596046dSAndreas Gohr */ 578596046dSAndreas Gohr function _isTooEarlyToSubmit(){ 585827ba0bSGuillaume Turri $lastSubmit = $this->helper->lastSentTime(); 598596046dSAndreas Gohr return $lastSubmit + 24*60*60*30 > time(); 608596046dSAndreas Gohr } 618596046dSAndreas Gohr} 62