Completed
Push — sidebaracl ( 7a112d...7c3e4a )
by Andreas
04:38
created

lib/plugins/popularity/action.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 );
0 ignored issues
show
The property autosubmitErrorFile cannot be accessed from this context as it is declared private in class helper_plugin_popularity.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
41
        } else {
42
            //If the data has been sent successfully, previous log of errors are useless
43
            @unlink($this->helper->autosubmitErrorFile);
0 ignored issues
show
The property autosubmitErrorFile cannot be accessed from this context as it is declared private in class helper_plugin_popularity.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
44
            //Update the last time we sent data
45
            touch ( $this->helper->autosubmitFile );
0 ignored issues
show
The property autosubmitFile cannot be accessed from this context as it is declared private in class helper_plugin_popularity.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
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