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 | var $helper;
|
---|
13 |
|
---|
14 | function action_plugin_popularity(){
|
---|
15 | $this->helper = $this->loadHelper('popularity', false);
|
---|
16 | }
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Register its handlers with the dokuwiki's event controller
|
---|
20 | */
|
---|
21 | function register(&$controller) {
|
---|
22 | $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array());
|
---|
23 | }
|
---|
24 |
|
---|
25 | function _autosubmit(&$event, $param){
|
---|
26 | //Do we have to send the data now
|
---|
27 | if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){
|
---|
28 | return;
|
---|
29 | }
|
---|
30 |
|
---|
31 | //Actually send it
|
---|
32 | $status = $this->helper->sendData( $this->helper->gatherAsString() );
|
---|
33 |
|
---|
34 |
|
---|
35 | if ( $status !== '' ){
|
---|
36 | //If an error occured, log it
|
---|
37 | io_saveFile( $this->helper->autosubmitErrorFile, $status );
|
---|
38 | } else {
|
---|
39 | //If the data has been sent successfully, previous log of errors are useless
|
---|
40 | @unlink($this->helper->autosubmitErrorFile);
|
---|
41 | //Update the last time we sent data
|
---|
42 | touch ( $this->helper->autosubmitFile );
|
---|
43 | }
|
---|
44 |
|
---|
45 | $event->stopPropagation();
|
---|
46 | $event->preventDefault();
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Check if it's time to send autosubmit data
|
---|
51 | * (we should have check if autosubmit is enabled first)
|
---|
52 | */
|
---|
53 | function _isTooEarlyToSubmit(){
|
---|
54 | $lastSubmit = $this->helper->lastSentTime();
|
---|
55 | return $lastSubmit + 24*60*60*30 > time();
|
---|
56 | }
|
---|
57 | }
|
---|