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 'script' => array(array()), 58 'link' => array(array()), 59 'meta' => array(array()), 60 'popupscript' => array() 61 ); 62 $ID = getID('id'); 63 64 if (auth_quickaclcheck($ID) < AUTH_READ) { 65 echo "read permission error"; 66 return; 67 } 68 69 switch($event->data) { 70 case '_popup_load_file' : 71 $INFO = pageinfo(); 72 $json = new JSON(); 73 $JSINFO['id'] = $ID; 74 $JSINFO['namespace'] = (string) $INFO['namespace']; 75 trigger_event('POPUPVIEWER_DOKUWIKI_STARTED',$head,null,true); 76 77 $script = 'var JSINFO = '.$json->encode($JSINFO).';'; 78 79 if ( $this->getConf('allowpopupscript') ) { 80 $popupscript = p_get_metadata($ID, 'popupscript', true); 81 $script .= "try{(function($){".$popupscript."}(jQuery))}catch(e){alert('Could not execute popupscript: '+e);}"; 82 83 if ( ($google =& plugin_load('action', 'googleanalytics')) ) { 84 $dest = str_replace(":", "/", $ID); 85 if ( isset($_REQUEST['do']) ) { 86 $dest .= "?do=".$_REQUEST['do']; 87 } 88 $script .= "if(window.ga) window.ga('send', 'event', 'wiki-action', 'popupviewer', '".$dest."', { nonInteraction: false} );"; 89 } 90 } 91 92 $head['popupscript'][] = array( 'type'=>'text/popupscript', '_data'=> $script ); 93 94 $data = '<div class="dokuwiki" style="padding-bottom: 10px;">' . p_wiki_xhtml($ID,'',true) . '</div>'; 95 break; 96 case '_popup_load_image_meta' : 97 98 global $SRC; 99 $SRC = mediaFN($ID); 100 $title = hsc(tpl_img_getTag('IPTC.Headline')); 101 $caption = hsc(tpl_img_getTag('IPTC.Caption')); 102 103 if ( !empty($title) ) { $title = "<h3 class=\"title\">$title</h3>"; } 104 if ( !empty($caption) ) { $caption = "<div class=\"text\"><p>$caption</p></div>"; } 105 $data = preg_replace("%(\n|\r)%", '', nl2br($title.$caption)); 106 break; 107 } 108 109 header('Content-Type: text/html; charset=utf-8'); 110 111 if ( !empty($head['popupscript']) ) { 112 trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); 113 } 114 115 print $data; 116 return; 117 } 118 119 function multiorphan_link_check(Doku_Event &$event) { 120 121 $instructions = $event->data['instructions']; 122 if ( !strstr($instructions[0], 'popupviewer') ) { 123 return; 124 } 125 126 $event->data['entryID'] = $id = cleanID($instructions[1][0]); 127 128 $page = resolve_id(getNS($event->data['checkNamespace']),$id); 129 $file = mediaFN($page); 130 131 $event->data['exists'] = $exists = @file_exists($file) && @is_file($file); 132 $event->data['type'] = $exists ? 'media' : 'pages'; 133 134 if ( !$exists ) { 135 resolve_pageid(getNS($event->data['checkNamespace']),$id,$event->data['exists']); 136 } 137 } 138} 139