1<?php 2 3if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); 4if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 5require_once(DOKU_PLUGIN.'action.php'); 6 7class action_plugin_ckgdoku_mediamanager extends DokuWiki_Action_Plugin { 8 function __construct() 9 { 10 $this->setupLocale(); 11 } 12 13 14 function register(Doku_Event_Handler $controller) 15 { 16 $controller->register_hook('MEDIAMANAGER_STARTED', 'AFTER', $this, 'mediaman_started'); 17 $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'upload_finish'); 18 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metafile'); 19 } 20 21 function handle_metafile(Doku_Event $event) { 22 $event->data['script'][] = 23 array( 24 'type'=>'text/javascript', 25 'charset'=>'utf-8', 26 '_data'=>'', 27 'src'=>DOKU_BASE.'lib/plugins/ckgdoku/scripts/mediamgr.js' 28 ); 29 } 30 function upload_finish(Doku_Event $event) { 31 if(!preg_match("#^image/#",$event->data[3]) && $_COOKIE['ckgFbType'] == 'image') { 32 if(!empty($event->data[3]) && strlen($event->data[3]) >30) { 33 $fname = substr($event->data[3],0,29) . '. . .'; 34 } 35 else $fname = $event->data[3]; 36 msg($this->getLang('mediamgr_imgonly') . $fname); 37 setcookie('ckgFbType', 'image',time()-10); 38 $event->preventDefault(); 39 } 40 } 41 42 function mediaman_started(Doku_Event $event) { 43 if ($_GET["onselect"] == "ckg_edit_mediaman_insert") { 44 setcookie('ckgFbType', 'image'); 45 } else if ($_GET["onselect"] == "ckg_edit_mediaman_insertlink") { 46 setcookie('ckgFbType', 'link'); 47 } 48 } 49} 50