You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

366 lines
11 KiB

  1. <?php
  2. /**
  3. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  4. * @author Myron Turner <turnermm02@shaw.ca>
  5. */
  6. // must be run within Dokuwiki
  7. if (!defined('DOKU_INC')) die();
  8. class helper_plugin_ckgedit extends DokuWiki_Plugin {
  9. function getMethods(){
  10. $result = array();
  11. $result[] = array(
  12. 'name' => 'registerOnLoad',
  13. 'desc' => 'register some javascript to the window.onload js event',
  14. 'params' => array('js' => 'string'),
  15. 'return' => array('html' => 'string'),
  16. );
  17. return $result;
  18. }
  19. /**
  20. * Convert string configuration value into an array
  21. */
  22. function get_conf_array($val) {
  23. $str = $this->getConf($val);
  24. $str = preg_replace('/\s+/',"",$str);
  25. return explode(',', $str);
  26. }
  27. function get_ckgedit_ImageAllowedExtensions() {
  28. $uploadImageTypes = ARRAY();
  29. foreach (getMimeTypes() as $ext=>$mtype) {
  30. if(preg_match("/image/", $mtype)) {
  31. $uploadImageTypes[] = $ext;
  32. }
  33. }
  34. return '.(' . implode('|',$uploadImageTypes) .')$';
  35. }
  36. function is_outOfScope(&$which="") {
  37. if(isset($_REQUEST['target']) && $_REQUEST['target'] == 'plugin_data') return true;
  38. return false;
  39. }
  40. function has_plugin($plugin) {
  41. $plugins_list = plugin_list();
  42. return in_array($plugin, $plugins_list);
  43. }
  44. /**
  45. * function dw_edit_displayed
  46. * @author Myron Turner
  47. * determines whether or not to show or hide the
  48. * 'DW Edit' button
  49. */
  50. function dw_edit_displayed()
  51. {
  52. global $INFO;
  53. $dw_edit_display = @$this->getConf('dw_edit_display');
  54. if(!isset($dw_edit_display))return ""; //version 0.
  55. if($dw_edit_display != 'all') {
  56. $admin_exclusion = false;
  57. if($dw_edit_display == 'admin' && ($INFO['isadmin'] || $INFO['ismanager']) ) {
  58. $admin_exclusion = true;
  59. }
  60. if($dw_edit_display == 'none' || $admin_exclusion === false) {
  61. return ' style = "display:none"; ';
  62. }
  63. return "";
  64. }
  65. return "";
  66. }
  67. function registerOnLoad($js){
  68. global $ID;
  69. global $lang;
  70. global $skip_styling;
  71. global $JSINFO;
  72. $ckgedit_conf_direction = $this->getConf('direction');
  73. if($ckgedit_conf_direction == "dokuwiki") {
  74. $ckgedit_lang_direction = $lang['direction'];
  75. }
  76. else {
  77. $ckgedit_lang_direction = $ckgedit_conf_direction;
  78. }
  79. $ImageUploadAllowedExtensions = $this->get_ckgedit_ImageAllowedExtensions() ;
  80. $media_tmp_ns = preg_match('/:/',$ID) ? preg_replace('/:\w+$/',"",$ID,1) : "";
  81. $locktimer_msg = "Your lock for editing this page is about to expire in a minute.\\n"
  82. . "You can reset the timer by clicking the Back-up button.";
  83. $meta_fn = metaFN($ID,'.ckgedit');
  84. $meta_id = 'meta/' . str_replace(':','/',$ID) . '.ckgedit';
  85. global $INFO;
  86. global $conf;
  87. global $USERINFO;
  88. $_OS = strtolower(PHP_OS);
  89. $cname = getCacheName($INFO['client'].$ID,'.draft');
  90. $useheading = $conf['useheading'];
  91. if($useheading && $useheading != 'navigation') {
  92. $useheading = 'y';
  93. }
  94. else $useheading = 'n';
  95. //msg('uh='.$useheading);
  96. $open_upload = $this->getConf('open_upload');
  97. $editor_backup = $this->getConf('editor_bak');
  98. $create_folder = $this->getConf('create_folder');
  99. $interface_lang = $this->getConf('other_lang');
  100. $scayt_lang = $this->getConf('scayt_lang');
  101. list($name,$scayt_lang) = explode('/', $scayt_lang);
  102. $scayt_auto = $this->getConf('scayt_auto');
  103. $color_opts = $this->getConf('color_options');
  104. $font_opts = $this->getConf('font_options');
  105. $toolbar_opts = $this->getConf('alt_toolbar');
  106. $mfiles = $this->getConf('mfiles');
  107. $extra_plugins = $this->getConf('extra_plugins');
  108. $ckg_gui = $this->getConf('gui');
  109. if(!isset($INFO['userinfo']) && !$open_upload) {
  110. $user_type = 'visitor';
  111. }
  112. else {
  113. $user_type = 'user';
  114. }
  115. $save_dir = DOKU_BASE . ltrim($conf['savedir'],'/.\/');
  116. $fbsz_increment = isset($_COOKIE['fbsz']) && $_COOKIE['fbsz'] ? $_COOKIE['fbsz'] : '0';
  117. $use_pastebase64 = (isset($_COOKIE['ckgEdPaste']) && $_COOKIE['ckgEdPaste'] == 'on' ) ? 'on' : 'off';
  118. // if no ACL is used always return upload rights
  119. if($conf['useacl']) {
  120. $client = $_SERVER['REMOTE_USER'];
  121. }
  122. else $client = "";
  123. $user_name = $USERINFO['name'];
  124. $user_email = $USERINFO['mail'];
  125. $fnencode = isset($conf['fnencode']) ? $conf['fnencode'] : 'url';
  126. $user_groups = $USERINFO['grps'];
  127. if(!$user_groups) $user_groups = array();
  128. if (@in_array("guest", $user_groups)) {
  129. $create_folder = 'n';
  130. $user_type = 'visitor';
  131. }
  132. $user_groups = str_replace('"','\"',implode(";;",$user_groups));
  133. if($INFO['isadmin'] || $INFO['ismanager']) {
  134. $client = "";
  135. }
  136. $ver_anteater = mktime(0,0,0,11,7,2010);
  137. $dwiki_version=mktime(0,0,0,01,01,2008);
  138. if(isset($conf['fnencode'])) {
  139. $ver_anteater = mktime(0,0,0,11,7,2010);
  140. $dwiki_version=mktime(0,0,0,11,7,2010);
  141. }
  142. else if(function_exists('getVersionData')) {
  143. $verdata= getVersionData();
  144. if(isset($verdata) && preg_match('/(\d+)-(\d+)-(\d+)/',$verdata['date'],$ver_date)) {
  145. if($ver_date[1] >= 2005 && ($ver_date[3] > 0 && $ver_date[3] < 31) && ($ver_date[2] > 0 && $ver_date[2] <= 12)) {
  146. // month day year
  147. $dwiki_version=@mktime(0, 0, 0, $ver_date[2],$ver_date[3], $ver_date[1]);
  148. if(!$dwiki_version) $dwiki_version = mktime(0,0,0,01,01,2008);
  149. $ver_anteater = mktime(0,0,0,11,7,2010);
  150. }
  151. }
  152. }
  153. $ckg_brokenimg = $this->getLang('broken_image');
  154. $default_fb = $this->getConf('default_fb');
  155. if($default_fb == 'none') {
  156. $client = "";
  157. }
  158. $doku_base = DOKU_BASE;
  159. return <<<end_of_string
  160. <script type='text/javascript'>
  161. //<![CDATA[
  162. if(window.dw_locktimer) {
  163. var locktimer = dw_locktimer;
  164. }
  165. var FCKRecovery = "";
  166. var oldonload = window.onload;
  167. var ourLockTimerINI = false;
  168. var ckgedit_onload = function() { $js };
  169. window.onload = ckgedit_onload;
  170. function getCurrentWikiNS() {
  171. var DWikiMediaManagerCommand_ns = '$media_tmp_ns';
  172. return DWikiMediaManagerCommand_ns;
  173. }
  174. var ourFCKEditorNode = null;
  175. function revert_to_prev() {
  176. if(!(GetE('saved_wiki_html').innerHTML.length)) {
  177. if(!confirm(backup_empty)) {
  178. return;
  179. }
  180. }
  181. CKEDITOR.instances.wiki__text.setData( GetE('saved_wiki_html').innerHTML);
  182. window.dwfckTextChanged = true;
  183. }
  184. function draft_delete() {
  185. var debug = false;
  186. var params = "draft_id=$cname";
  187. jQuery.ajax({
  188. url: DOKU_BASE + 'lib/plugins/ckgedit/scripts/draft_delete.php',
  189. data: params,
  190. type: 'POST',
  191. dataType: 'html',
  192. success: function(data){
  193. if(debug) {
  194. alert(data);
  195. }
  196. }
  197. });
  198. window.textChanged = false;
  199. }
  200. var DWFCK_EditorWinObj;
  201. function FCKEditorWindowObj(w) {
  202. DWFCK_EditorWinObj = w;
  203. }
  204. function ckgedit_isRTL() {
  205. var direction = "$ckgedit_lang_direction";
  206. return direction == 'rtl';
  207. }
  208. function remove_styling() {
  209. //'TextColor,BGColor, FontAssist,Font,FontSize';
  210. var opts = "";
  211. var color_opts = parseInt( "$color_opts");
  212. var font_opts = parseInt("$font_opts");
  213. var skip_styling=parseInt("$skip_styling");
  214. if(color_opts) {
  215. opts ='TextColor,BGColor,FontAssist';
  216. }
  217. else if(!skip_styling) {
  218. opts = 'FontAssist';
  219. }
  220. if(font_opts) {
  221. if(color_opts || !skip_styling) opts+=',';
  222. opts +='Font,FontSize';
  223. }
  224. if("$toolbar_opts") {
  225. if(opts) opts+=',';
  226. opts+="$toolbar_opts";
  227. }
  228. return opts;
  229. }
  230. function extra_plugins(config) {
  231. if("$use_pastebase64" == 'on') config.addPaste();
  232. return "$extra_plugins";
  233. }
  234. function ckgedit_language_chk(config) {
  235. if("$scayt_auto" == 'on') {
  236. config.scayt_autoStartup = true;
  237. }
  238. else config.scayt_autoStartup = false;
  239. if("$scayt_auto" == 'disable') {
  240. config.scayt__disable = true;
  241. }
  242. config.scayt_sLang="$scayt_lang";
  243. var lang = "$interface_lang";
  244. if(lang == 'default') return; ;
  245. config.language = lang;
  246. }
  247. function getCKEditorGUI() {
  248. return "$ckg_gui";
  249. }
  250. var oDokuWiki_FCKEditorInstance;
  251. function FCKeditor_OnComplete( editorInstance )
  252. {
  253. oDokuWiki_FCKEditorInstance = editorInstance;
  254. editorInstance.on( 'key', handlekeypress, editorInstance );
  255. CKEDITOR.instances.wiki__text.on('change', function(event) {
  256. window.dwfckTextChanged = true;
  257. window.textChanged = true;
  258. });
  259. editorInstance.on("focus", function(e) {
  260. window.dwfckTextChanged = true;
  261. });
  262. var broken_image ='http://' + location.host + DOKU_BASE + '/lib/plugins/ckgedit/fckeditor/userfiles/blink.jpg?nolink&33x34';
  263. editorInstance.on("paste", function(e) {
  264. // https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
  265. var formatBytes = function(bytes,decimals) {
  266. if(bytes == 0) return '0 Bytes';
  267. var k = 1024,
  268. dm = decimals <= 0 ? 0 : decimals || 2,
  269. sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
  270. i = Math.floor(Math.log(bytes) / Math.log(k));
  271. return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
  272. }
  273. var len = e.data.dataValue.length;
  274. var len = e.data.dataValue.length - 'data:image/png;base64,'.length;
  275. var size = formatBytes(len,1);
  276. var broken_msg = ckg_RawImgMsg();
  277. broken_msg += " " + size;
  278. if(e.data.dataValue.match(/data:image\/\w+;base64/) && len > 2500000) {
  279. alert(broken_msg);
  280. e.data.dataValue = '<img src ='+ broken_image + '/>';
  281. }
  282. });
  283. oDokuWiki_FCKEditorInstance.dwiki_user = "$user_type";
  284. oDokuWiki_FCKEditorInstance.dwiki_client = "$client";
  285. oDokuWiki_FCKEditorInstance.dwiki_usergroups = "$user_groups";
  286. oDokuWiki_FCKEditorInstance.dwiki_doku_base = "$doku_base";
  287. oDokuWiki_FCKEditorInstance.dwiki_create_folder = "$create_folder";
  288. oDokuWiki_FCKEditorInstance.dwiki_fnencode = "$fnencode";
  289. oDokuWiki_FCKEditorInstance.dwiki_version = $dwiki_version;
  290. oDokuWiki_FCKEditorInstance.dwiki_anteater = $ver_anteater;
  291. oDokuWiki_FCKEditorInstance.isLocalDwikiBrowser = false;
  292. oDokuWiki_FCKEditorInstance.isUrlExtern = false;
  293. oDokuWiki_FCKEditorInstance.isDwikiMediaFile = false;
  294. oDokuWiki_FCKEditorInstance.imageUploadAllowedExtensions="$ImageUploadAllowedExtensions";
  295. oDokuWiki_FCKEditorInstance.fckgUserName = "$user_name";
  296. oDokuWiki_FCKEditorInstance.fckgUserMail="$user_email";
  297. oDokuWiki_FCKEditorInstance.useheading = "$useheading";
  298. oDokuWiki_FCKEditorInstance.mfiles = parseInt("$mfiles");
  299. oDokuWiki_FCKEditorInstance.fbsz_increment=parseInt("$fbsz_increment");
  300. }
  301. window.DWikifnEncode = "$fnencode";
  302. //]]>
  303. </script>
  304. end_of_string;
  305. }
  306. }
  307. ?>