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'); 6require_once(DOKU_PLUGIN.'ckgedit/scripts/setsamesite.php'); 7class action_plugin_ckgedit_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/ckgedit/scripts/mediamgr.js' 28 ) + ([ 'defer' => 'defer']); 29 } 30 31 function upload_finish(Doku_Event $event) { 32 if(!preg_match("#^image/#",$event->data[3]) && $_COOKIE['ckgFbType'] == 'image') { 33 if(!empty($event->data[3]) && strlen($event->data[3]) >30) { 34 $fname = substr($event->data[3],0,29) . '. . .'; 35 } 36 else $fname = $event->data[3]; 37 msg($this->getLang('mediamgr_imgonly') . $fname); 38 setcookieSameSite('ckgFbType', 'image',time()-10); 39 $event->preventDefault(); 40 } 41 } 42 43 function mediaman_started(Doku_Event $event) { 44 if ($_GET["onselect"] == "ckg_edit_mediaman_insert") { 45 setcookieSameSite('ckgFbType', 'image'); 46 } else if ($_GET["onselect"] == "ckg_edit_mediaman_insertlink") { 47 setcookieSameSite('ckgFbType', 'link'); 48 } 49 } 50} 51