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 { 1238479cbbSDominik Eckelmann 1338479cbbSDominik Eckelmann /** 1438479cbbSDominik Eckelmann * @var helper_plugin_popularity 1538479cbbSDominik Eckelmann */ 16*3dc2d50cSAndreas Gohr protected $helper; 178596046dSAndreas Gohr 18*3dc2d50cSAndreas Gohr public function __construct(){ 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 */ 25*3dc2d50cSAndreas Gohr public function register(Doku_Event_Handler $controller) { 268596046dSAndreas Gohr $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); 278596046dSAndreas Gohr } 288596046dSAndreas Gohr 29*3dc2d50cSAndreas Gohr /** 30*3dc2d50cSAndreas Gohr * Event handler 31*3dc2d50cSAndreas Gohr * 32*3dc2d50cSAndreas Gohr * @param Doku_Event $event 33*3dc2d50cSAndreas Gohr * @param $param 34*3dc2d50cSAndreas Gohr */ 35*3dc2d50cSAndreas Gohr public function _autosubmit(Doku_Event &$event, $param){ 368596046dSAndreas Gohr //Do we have to send the data now 378596046dSAndreas Gohr if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){ 388596046dSAndreas Gohr return; 398596046dSAndreas Gohr } 408596046dSAndreas Gohr 418596046dSAndreas Gohr //Actually send it 428596046dSAndreas Gohr $status = $this->helper->sendData( $this->helper->gatherAsString() ); 438596046dSAndreas Gohr 448596046dSAndreas Gohr if ( $status !== '' ){ 458596046dSAndreas Gohr //If an error occured, log it 468596046dSAndreas Gohr io_saveFile( $this->helper->autosubmitErrorFile, $status ); 478596046dSAndreas Gohr } else { 488596046dSAndreas Gohr //If the data has been sent successfully, previous log of errors are useless 498596046dSAndreas Gohr @unlink($this->helper->autosubmitErrorFile); 508596046dSAndreas Gohr //Update the last time we sent data 518596046dSAndreas Gohr touch ( $this->helper->autosubmitFile ); 528596046dSAndreas Gohr } 538596046dSAndreas Gohr 548596046dSAndreas Gohr $event->stopPropagation(); 558596046dSAndreas Gohr $event->preventDefault(); 568596046dSAndreas Gohr } 578596046dSAndreas Gohr 588596046dSAndreas Gohr /** 598596046dSAndreas Gohr * Check if it's time to send autosubmit data 605827ba0bSGuillaume Turri * (we should have check if autosubmit is enabled first) 618596046dSAndreas Gohr */ 62*3dc2d50cSAndreas Gohr protected function _isTooEarlyToSubmit(){ 635827ba0bSGuillaume Turri $lastSubmit = $this->helper->lastSentTime(); 648596046dSAndreas Gohr return $lastSubmit + 24*60*60*30 > time(); 658596046dSAndreas Gohr } 668596046dSAndreas Gohr} 67