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(Doku_Event_Handler $controller) { 26 // Support given via AJAX 27 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax_viewer_provider'); 28 $controller->register_hook('MULTIORPHAN_INSTRUCTION_LINKED', 'BEFORE', $this, 'multiorphan_link_check'); 29 } 30 31 function ajax_viewer_provider( Doku_Event &$event ) { 32 global $JSINFO; 33 global $INFO; 34 global $ID; 35 global $ACT; 36 37 if ( $event->data != '_popup_load_file' && $event->data != '_popup_load_image_meta' ) { 38 return; 39 } 40 41 // Registers ACT 42 if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])){ 43 $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO'])); 44 } elseif (!empty($_REQUEST['idx'])) { 45 $ACT = 'index'; 46 } elseif (isset($_REQUEST['do'])) { 47 $ACT = $_REQUEST['do']; 48 } else { 49 $ACT = 'show'; 50 } 51 52 $event->preventDefault(); 53 $event->stopPropagation(); 54 55 $data = ""; 56 $head = array(); 57 $ID = getID('id'); 58 59 switch($event->data) { 60 case '_popup_load_file' : 61 $INFO = pageinfo(); 62 $json = new JSON(); 63 $JSINFO['id'] = $ID; 64 $JSINFO['namespace'] = (string) $INFO['namespace']; 65 trigger_event('POPUPVIEWER_DOKUWIKI_STARTED',$head,null,true); 66 67 $script = 'var JSINFO = '.$json->encode($JSINFO).';'; 68 69 if ( $this->getConf('allowpopupscript') ) { 70 $popupscript = p_get_metadata($ID, 'popupscript', true); 71 $script .= "try{(function($){".$popupscript."}(jQuery))}catch(e){alert('Could not execute popupscript: '+e);}"; 72 } 73 74 $head['popupscript'][] = array( 'type'=>'text/popupscript', '_data'=> $script); 75 76 $data = '<div class="dokuwiki" style="padding-bottom: 10px;">' . p_wiki_xhtml($ID,'',true) . '</div>'; 77 break; 78 case '_popup_load_image_meta' : 79 80 global $SRC; 81 $SRC = mediaFN($ID); 82 $title = hsc(tpl_img_getTag('IPTC.Headline')); 83 $caption = hsc(tpl_img_getTag('IPTC.Caption')); 84 85 if ( !empty($title) ) { $title = "<h3 class=\"title\">$title</h3>"; } 86 if ( !empty($caption) ) { $caption = "<div class=\"text\"><p>$caption</p></div>"; } 87 $data = preg_replace("%(\n|\r)%", '', nl2br($title.$caption)); 88 break; 89 } 90 91 header('Content-Type: text/html; charset=utf-8'); 92 93 if ( !empty($head) ) { 94 trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); 95 } 96 97 print $data; 98 return; 99 } 100 101 function multiorphan_link_check(Doku_Event &$event) { 102 103 $instructions = $event->data['instructions']; 104 if ( !strstr($instructions[0], 'popupviewer') ) { 105 return; 106 } 107 108 $event->data['entryID'] = $id = cleanID($instructions[1][0]); 109 110 $page = resolve_id(getNS($event->data['checkNamespace']),$id); 111 $file = mediaFN($page); 112 113 $event->data['exists'] = $exists = @file_exists($file) && @is_file($file); 114 $event->data['type'] = $exists ? 'media' : 'pages'; 115 116 if ( !$exists ) { 117 resolve_pageid(getNS($event->data['checkNamespace']),$id,$event->data['exists']); 118 } 119 } 120}