action.php
author Andreas Boehler <andreas@aboehler.at>
Tue, 23 Sep 2014 20:56:16 +0200
changeset 3 88d936428bed
parent 1 347546fd9315
child 5 11ccac7668ec
permissions -rw-r--r--
Make datapopup handle links with a revision or other action in them
(remove everything after "?")
0
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     1
<?php
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     2
/**
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     3
 * DokuWiki Plugin datapopup (Action Component)
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     4
 *
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     5
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     6
 * @author  Andreas Boehler <dev@aboehler.at>
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     7
 */
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     8
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
     9
// must be run within Dokuwiki
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    10
if (!defined('DOKU_INC')) die();
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    11
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    12
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    13
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    14
require_once(DOKU_PLUGIN.'action.php');
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    15
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    16
class action_plugin_datapopup extends DokuWiki_Action_Plugin {
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    17
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    18
    var $dthlp = null;
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    19
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    20
    function action_plugin_datapopup() {
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    21
        $this->dthlp =& plugin_load('helper', 'data');
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    22
    }
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    23
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    24
    function register(&$controller) {
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    25
        global $JSINFO;
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    26
        $JSINFO['plugin']['datapopup']['registered_types'] = $this->getConf('registered_types');
1
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    27
        
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    28
        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
0
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    29
    }
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    30
1
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    31
    protected function _getFields($link, $name) {
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    32
        if(!$this->dthlp)
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    33
          return "The datapopup plugin reported an error. Please report.";
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    34
        
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    35
        $sqlite = $this->dthlp->_getDB();
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    36
        if(!$sqlite) return "The datapopup had an error retrieving the SQLite plugin. Please report.";
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    37
        $query = "SELECT data.value FROM data JOIN pages ON data.pid=pages.pid WHERE pages.page='".$link."' AND data.key='".strtolower($name)."';";
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    38
        $res = $sqlite->query($query);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    39
        $rows = $sqlite->res2arr($res);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    40
        return $rows[0]['value'];
0
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    41
    }
1
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    42
    
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    43
    public function handle_ajax_call_unknown(Doku_Event &$event, $param) {
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    44
        if($event->data != 'plugin_datapopup') return;    
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    45
        global $auth;
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    46
        global $INPUT;
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    47
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    48
        $link = $INPUT->str('link');
3
88d936428bed Make datapopup handle links with a revision or other action in them
Andreas Boehler <andreas@aboehler.at>
parents: 1
diff changeset
    49
        $link = preg_replace('/\?.*/', '', $link);
1
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    50
        
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    51
        $fields = explode(',',$this->getConf('fields'));
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    52
        $fields = array_map('trim',$fields);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    53
        $fields = array_filter($fields);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    54
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    55
        echo '<ul>';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    56
        foreach($fields as $name){
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    57
            $val = $this->_getFields($link, $name);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    58
            if($val != "")
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    59
            {
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    60
                echo '<li class="dataov_name">';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    61
                echo '<div class="li">';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    62
                echo hsc($name);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    63
                echo '</div></li>';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    64
                echo '<li class="dataov_'.hsc($name).'">';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    65
                echo '<div class="li">';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    66
                echo hsc($val);
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    67
                echo '</div></li>';
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    68
            }
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    69
        }
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    70
        echo '</ul>';                
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    71
    
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    72
        
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    73
        $event->preventDefault();
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    74
        $event->stopPropagation();
347546fd9315 Port datapopup plugin to new Ajax-Plugin, jQuery Interface and SQLite
Andreas Boehler <andreas@aboehler.at>
parents: 0
diff changeset
    75
    }        
0
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    76
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    77
}
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    78
11a7dcc4af7a Initial import of datapopup
Andreas Boehler <andreas@aboehler.at>
parents:
diff changeset
    79
// vim:ts=4:sw=4:et:enc=utf-8: