|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Popularity Feedback Plugin |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
require_once(DOKU_PLUGIN.'action.php'); |
|
9
|
|
|
require_once(DOKU_PLUGIN.'popularity/admin.php'); |
|
10
|
|
|
|
|
11
|
|
|
class action_plugin_popularity extends Dokuwiki_Action_Plugin { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var helper_plugin_popularity |
|
15
|
|
|
*/ |
|
16
|
|
|
var $helper; |
|
17
|
|
|
|
|
18
|
|
|
function __construct(){ |
|
|
|
|
|
|
19
|
|
|
$this->helper = $this->loadHelper('popularity', false); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Register its handlers with the dokuwiki's event controller |
|
24
|
|
|
*/ |
|
25
|
|
|
function register(Doku_Event_Handler $controller) { |
|
|
|
|
|
|
26
|
|
|
$controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
function _autosubmit(Doku_Event &$event, $param){ |
|
|
|
|
|
|
30
|
|
|
//Do we have to send the data now |
|
31
|
|
|
if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){ |
|
32
|
|
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
//Actually send it |
|
36
|
|
|
$status = $this->helper->sendData( $this->helper->gatherAsString() ); |
|
37
|
|
|
|
|
38
|
|
|
if ( $status !== '' ){ |
|
39
|
|
|
//If an error occured, log it |
|
40
|
|
|
io_saveFile( $this->helper->autosubmitErrorFile, $status ); |
|
|
|
|
|
|
41
|
|
|
} else { |
|
42
|
|
|
//If the data has been sent successfully, previous log of errors are useless |
|
43
|
|
|
@unlink($this->helper->autosubmitErrorFile); |
|
|
|
|
|
|
44
|
|
|
//Update the last time we sent data |
|
45
|
|
|
touch ( $this->helper->autosubmitFile ); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$event->stopPropagation(); |
|
49
|
|
|
$event->preventDefault(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Check if it's time to send autosubmit data |
|
54
|
|
|
* (we should have check if autosubmit is enabled first) |
|
55
|
|
|
*/ |
|
56
|
|
|
function _isTooEarlyToSubmit(){ |
|
|
|
|
|
|
57
|
|
|
$lastSubmit = $this->helper->lastSentTime(); |
|
58
|
|
|
return $lastSubmit + 24*60*60*30 > time(); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.