action.php
changeset 1 347546fd9315
parent 0 11a7dcc4af7a
child 3 88d936428bed
--- a/action.php	Fri Sep 12 07:01:55 2014 +0200
+++ b/action.php	Fri Sep 12 07:02:44 2014 +0200
@@ -24,11 +24,54 @@
     function register(&$controller) {
         global $JSINFO;
         $JSINFO['plugin']['datapopup']['registered_types'] = $this->getConf('registered_types');
+        
+        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
     }
 
-    function getFields($link, $name) {
-        return $this->dthlp->_resolveSummary($link, $name);
+    protected function _getFields($link, $name) {
+        if(!$this->dthlp)
+          return "The datapopup plugin reported an error. Please report.";
+        
+        $sqlite = $this->dthlp->_getDB();
+        if(!$sqlite) return "The datapopup had an error retrieving the SQLite plugin. Please report.";
+        $query = "SELECT data.value FROM data JOIN pages ON data.pid=pages.pid WHERE pages.page='".$link."' AND data.key='".strtolower($name)."';";
+        $res = $sqlite->query($query);
+        $rows = $sqlite->res2arr($res);
+        return $rows[0]['value'];
     }
+    
+    public function handle_ajax_call_unknown(Doku_Event &$event, $param) {
+        if($event->data != 'plugin_datapopup') return;    
+        global $auth;
+        global $INPUT;
+
+        $link = $INPUT->str('link');
+        
+        $fields = explode(',',$this->getConf('fields'));
+        $fields = array_map('trim',$fields);
+        $fields = array_filter($fields);
+
+        echo '<ul>';
+        foreach($fields as $name){
+            $val = $this->_getFields($link, $name);
+            if($val != "")
+            {
+                echo '<li class="dataov_name">';
+                echo '<div class="li">';
+                echo hsc($name);
+                echo '</div></li>';
+                echo '<li class="dataov_'.hsc($name).'">';
+                echo '<div class="li">';
+                echo hsc($val);
+                echo '</div></li>';
+            }
+        }
+        echo '</ul>';                
+    
+        
+        $event->preventDefault();
+        $event->stopPropagation();
+    }        
 
 }