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 13class action_plugin_popupviewer extends DokuWiki_Action_Plugin { 14 15 function getInfo(){ 16 return array_merge(confToHash(dirname(__FILE__).'/plugin.info.txt'), array( 17 'name' => 'PopUpViewer Action Component', 18 'desc' => 'Delivers pages back to the browser' 19 )); 20 } 21 22 function register(Doku_Event_Handler $controller) { 23 // Support given via AJAX 24 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax_viewer_provider'); 25 $controller->register_hook('MULTIORPHAN_INSTRUCTION_LINKED', 'BEFORE', $this, 'multiorphan_link_check'); 26 } 27 28 function ajax_viewer_provider( Doku_Event &$event ) { 29 global $JSINFO; 30 global $INFO; 31 global $ID; 32 global $ACT; 33 34 if ( $event->data != '_popup_load_file' && $event->data != '_popup_load_image_meta' ) { 35 return; 36 } 37 38 // Registers ACT 39 if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])){ 40 $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO'])); 41 } elseif (!empty($_REQUEST['idx'])) { 42 $ACT = 'index'; 43 } elseif (isset($_REQUEST['do'])) { 44 $ACT = $_REQUEST['do']; 45 } else { 46 $ACT = 'show'; 47 } 48 49 $event->preventDefault(); 50 $event->stopPropagation(); 51 52 $data = ""; 53 $head = array( 54 'script' => array(array()), 55 'link' => array(array()), 56 'meta' => array(array()), 57 'popupscript' => array() 58 ); 59 $ID = getID('id'); 60 61 if (auth_quickaclcheck($ID) < AUTH_READ) { 62 echo "read permission error"; 63 return; 64 } 65 66 switch($event->data) { 67 case '_popup_load_file' : 68 $INFO = pageinfo(); 69 $json = new JSON(); 70 $JSINFO['id'] = $ID; 71 $JSINFO['namespace'] = (string) $INFO['namespace']; 72 trigger_event('POPUPVIEWER_DOKUWIKI_STARTED',$head,null,true); 73 74 $script = 'var JSINFO = '.$json->encode($JSINFO).';'; 75 76 if ( $this->getConf('allowpopupscript') ) { 77 $popupscript = p_get_metadata($ID, 'popupscript', true); 78 $script .= "try{(function($){".$popupscript."}(jQuery))}catch(e){alert('Could not execute popupscript: '+e);}"; 79 80 if ( ($google =& plugin_load('action', 'googleanalytics')) ) { 81 $dest = str_replace(":", "/", $ID); 82 if ( isset($_REQUEST['do']) ) { 83 $dest .= "?do=".$_REQUEST['do']; 84 } 85 $script .= "if(window.ga) window.ga('send', 'event', 'popupviewer', 'wiki-action', '".$dest."', { nonInteraction: false} );"; 86 } 87 } 88 89 $head['popupscript'][] = array( 'type'=>'text/popupscript', '_data'=> $script ); 90 91 $data = '<div class="dokuwiki" style="padding-bottom: 10px;">' . p_wiki_xhtml($ID,'',true) . '</div>'; 92 break; 93 case '_popup_load_image_meta' : 94 95 global $SRC; 96 $SRC = mediaFN($ID); 97 $title = hsc(tpl_img_getTag('IPTC.Headline')); 98 $caption = hsc(tpl_img_getTag('IPTC.Caption')); 99 100 if ( !empty($title) ) { $title = "<h3 class=\"title\">$title</h3>"; } 101 if ( !empty($caption) ) { $caption = "<div class=\"text\"><p>$caption</p></div>"; } 102 $data = preg_replace("%(\n|\r)%", '', nl2br($title.$caption)); 103 break; 104 } 105 106 header('Content-Type: text/html; charset=utf-8'); 107 108 if ( !empty($head['popupscript']) ) { 109 trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); 110 } 111 112 print $data; 113 return; 114 } 115 116 function multiorphan_link_check(Doku_Event &$event) { 117 118 $instructions = $event->data['instructions']; 119 if ( !strstr($instructions[0], 'popupviewer') ) { 120 return; 121 } 122 123 $event->data['entryID'] = $id = cleanID($instructions[1][0]); 124 125 $page = resolve_id(getNS($event->data['checkNamespace']),$id); 126 $file = mediaFN($page); 127 128 $event->data['exists'] = $exists = @file_exists($file) && @is_file($file); 129 $event->data['type'] = $exists ? 'media' : 'pages'; 130 131 if ( !$exists ) { 132 resolve_pageid(getNS($event->data['checkNamespace']),$id,$event->data['exists']); 133 } 134 } 135} 136