xref: /plugin/popupviewer/action.php (revision 886a8c8f8579aeee28c9f50393d7bd8370231f0e)
1<?php
2/**
3 * Imageflow Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'action.php');
15
16class action_plugin_popupviewer extends DokuWiki_Action_Plugin {
17
18    function getInfo(){
19    	return array_merge(confToHash(dirname(__FILE__).'/plugin.info.txt'), array(
20				'name' => 'PopUpViewer Action Component',
21				'desc' => 'Delivers pages back to the browser'
22				));
23    }
24
25    function register(&$controller) {
26        // Support given via AJAX
27        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax_viewer_provider');
28    }
29
30    function ajax_viewer_provider( &$event ) {
31        global $JSINFO;
32        global $INFO;
33        global $ID;
34        global $ACT;
35
36        if ( $event->data != '_popup_load_file' && $event->data != '_popup_load_image_meta' ) {
37            return;
38        }
39
40        // Registers ACT
41        if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])){
42            $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
43        } elseif (!empty($_REQUEST['idx'])) {
44            $ACT = 'index';
45        } elseif (isset($_REQUEST['do'])) {
46            $ACT = $_REQUEST['do'];
47        } else {
48            $ACT = 'show';
49        }
50
51        $event->preventDefault();
52        $event->stopPropagation();
53
54        $data = "";
55        $head = array();
56		$ID = getID('id');
57
58        switch($event->data) {
59            case '_popup_load_file' :
60                $INFO = pageinfo();
61                $json = new JSON();
62                $JSINFO['id'] = $ID;
63                $JSINFO['namespace'] = (string) $INFO['namespace'];
64                trigger_event('POPUPVIEWER_DOKUWIKI_STARTED',$head,null,true);
65
66                $script = 'var JSINFO = '.$json->encode($JSINFO).';';
67                $popupscript = p_get_metadata($ID, 'popupscript', true);
68                $script .= "try{(function($){".$popupscript."}(jQuery))}catch(e){alert('Could not execute popupscript: '+e);}";
69                $head['popupscript'][] = array( 'type'=>'text/popupscript', '_data'=> $json->encode($script));
70
71                $data = '<div class="dokuwiki" style="padding-bottom: 10px;">' . p_wiki_xhtml($ID,'',true) . '</div>';
72                break;
73            case '_popup_load_image_meta' :
74
75				global $SRC;
76				$SRC = mediaFN($ID);
77                $title = hsc(tpl_img_getTag('IPTC.Headline'));
78                $caption = hsc(tpl_img_getTag('IPTC.Caption'));
79
80                if ( !empty($title) ) { $title = "<h3 class=\"title\">$title</h3>"; }
81                if ( !empty($caption) ) { $caption = "<div class=\"text\"><p>$caption</p></div>"; }
82                $data = preg_replace("%(\n|\r)%", '', nl2br($title.$caption));
83                break;
84        }
85
86        header('Content-Type: text/html; charset=utf-8');
87
88        if ( !empty($head) ) {
89            trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
90        }
91
92        print $data;
93        return;
94    }
95}