PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/magic-fields-2/admin/mf_tiny_mce.php

https://bitbucket.org/rossberenson/michael-karas
PHP | 327 lines | 219 code | 49 blank | 59 comment | 56 complexity | 2bad6e176c406e50b75993d4a11d3283 MD5 | raw file
  1. <?php
  2. /**
  3. * Direct copy from latest Wordpress 3.2 wp-admin/includes/post.php
  4. * This was deprecated in 3.3, but we need it
  5. */
  6. /**
  7. * Adds the TinyMCE editor used on the Write and Edit screens.
  8. *
  9. * @package WordPress
  10. * @since 2.7.0
  11. *
  12. * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated
  13. * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded
  14. * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string
  15. * to the URL when queueing them with the mce_external_plugins filter.
  16. *
  17. * @param bool $teeny optional Output a trimmed down version used in Press This.
  18. * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.
  19. */
  20. //function wp_tiny_mce( $teeny = false, $settings = false ) {
  21. function mf_tiny_mce( $teeny = false, $settings = false ) {
  22. global $concatenate_scripts, $compress_scripts, $tinymce_version, $editor_styles;
  23. if ( ! user_can_richedit() )
  24. return;
  25. $baseurl = includes_url('js/tinymce');
  26. $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
  27. /*
  28. The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
  29. By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
  30. The + sign marks the default language. More information:
  31. http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  32. */
  33. $mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
  34. if ( $teeny ) {
  35. $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs') );
  36. $ext_plugins = '';
  37. } else {
  38. $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'wordpress', 'wpfullscreen', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );
  39. /*
  40. The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
  41. It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
  42. The url should be absolute and should include the js file name to be loaded. Example:
  43. array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
  44. If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
  45. */
  46. $mce_external_plugins = apply_filters('mce_external_plugins', array());
  47. $ext_plugins = '';
  48. if ( ! empty($mce_external_plugins) ) {
  49. /*
  50. The following filter loads external language files for TinyMCE plugins.
  51. It takes an associative array 'plugin_name' => 'path', where path is the
  52. include path to the file. The language file should follow the same format as
  53. /tinymce/langs/wp-langs.php and should define a variable $strings that
  54. holds all translated strings.
  55. When this filter is not used, the function will try to load {mce_locale}.js.
  56. If that is not found, en.js will be tried next.
  57. */
  58. $mce_external_languages = apply_filters('mce_external_languages', array());
  59. $loaded_langs = array();
  60. $strings = '';
  61. if ( ! empty($mce_external_languages) ) {
  62. foreach ( $mce_external_languages as $name => $path ) {
  63. if ( @is_file($path) && @is_readable($path) ) {
  64. include_once($path);
  65. $ext_plugins .= $strings . "\n";
  66. $loaded_langs[] = $name;
  67. }
  68. }
  69. }
  70. foreach ( $mce_external_plugins as $name => $url ) {
  71. if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
  72. $plugins[] = '-' . $name;
  73. $plugurl = dirname($url);
  74. $strings = $str1 = $str2 = '';
  75. if ( ! in_array($name, $loaded_langs) ) {
  76. $path = str_replace( WP_PLUGIN_URL, '', $plugurl );
  77. $path = WP_PLUGIN_DIR . $path . '/langs/';
  78. if ( function_exists('realpath') )
  79. $path = trailingslashit( realpath($path) );
  80. if ( @is_file($path . $mce_locale . '.js') )
  81. $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
  82. if ( @is_file($path . $mce_locale . '_dlg.js') )
  83. $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
  84. if ( 'en' != $mce_locale && empty($strings) ) {
  85. if ( @is_file($path . 'en.js') ) {
  86. $str1 = @file_get_contents($path . 'en.js');
  87. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
  88. }
  89. if ( @is_file($path . 'en_dlg.js') ) {
  90. $str2 = @file_get_contents($path . 'en_dlg.js');
  91. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
  92. }
  93. }
  94. if ( ! empty($strings) )
  95. $ext_plugins .= "\n" . $strings . "\n";
  96. }
  97. $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
  98. $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
  99. }
  100. }
  101. }
  102. if ( $teeny ) {
  103. $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );
  104. $mce_buttons = implode($mce_buttons, ',');
  105. $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = '';
  106. } else {
  107. $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));
  108. $mce_buttons = implode($mce_buttons, ',');
  109. $mce_buttons_2 = array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' );
  110. $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2);
  111. $mce_buttons_2 = implode($mce_buttons_2, ',');
  112. $mce_buttons_3 = apply_filters('mce_buttons_3', array());
  113. $mce_buttons_3 = implode($mce_buttons_3, ',');
  114. $mce_buttons_4 = apply_filters('mce_buttons_4', array());
  115. $mce_buttons_4 = implode($mce_buttons_4, ',');
  116. }
  117. $no_captions = (bool) apply_filters( 'disable_captions', '' );
  118. // TinyMCE init settings
  119. $initArray = array (
  120. 'mode' => 'specific_textareas',
  121. 'editor_selector' => 'theEditor',
  122. 'width' => '100%',
  123. 'theme' => 'advanced',
  124. 'skin' => 'wp_theme',
  125. 'theme_advanced_buttons1' => $mce_buttons,
  126. 'theme_advanced_buttons2' => $mce_buttons_2,
  127. 'theme_advanced_buttons3' => $mce_buttons_3,
  128. 'theme_advanced_buttons4' => $mce_buttons_4,
  129. 'language' => $mce_locale,
  130. 'spellchecker_languages' => $mce_spellchecker_languages,
  131. 'theme_advanced_toolbar_location' => 'top',
  132. 'theme_advanced_toolbar_align' => 'left',
  133. 'theme_advanced_statusbar_location' => 'bottom',
  134. 'theme_advanced_resizing' => true,
  135. 'theme_advanced_resize_horizontal' => false,
  136. 'dialog_type' => 'modal',
  137. 'formats' => "{
  138. alignleft : [
  139. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  140. {selector : 'img,table', classes : 'alignleft'}
  141. ],
  142. aligncenter : [
  143. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  144. {selector : 'img,table', classes : 'aligncenter'}
  145. ],
  146. alignright : [
  147. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  148. {selector : 'img,table', classes : 'alignright'}
  149. ],
  150. strikethrough : {inline : 'del'}
  151. }",
  152. 'relative_urls' => false,
  153. 'remove_script_host' => false,
  154. 'convert_urls' => false,
  155. 'apply_source_formatting' => false,
  156. 'remove_linebreaks' => true,
  157. 'gecko_spellcheck' => true,
  158. 'keep_styles' => false,
  159. 'entities' => '38,amp,60,lt,62,gt',
  160. 'accessibility_focus' => true,
  161. 'tabfocus_elements' => 'major-publishing-actions',
  162. 'media_strict' => false,
  163. 'paste_remove_styles' => true,
  164. 'paste_remove_spans' => true,
  165. 'paste_strip_class_attributes' => 'all',
  166. 'paste_text_use_dialog' => true,
  167. 'extended_valid_elements' => 'article[*],aside[*],audio[*],canvas[*],command[*],datalist[*],details[*],embed[*],figcaption[*],figure[*],footer[*],header[*],hgroup[*],keygen[*],mark[*],meter[*],nav[*],output[*],progress[*],section[*],source[*],summary,time[*],video[*],wbr',
  168. 'wpeditimage_disable_captions' => $no_captions,
  169. 'wp_fullscreen_content_css' => "$baseurl/plugins/wpfullscreen/css/wp-fullscreen.css",
  170. 'plugins' => implode( ',', $plugins ),
  171. );
  172. if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {
  173. $mce_css = array();
  174. $style_uri = get_stylesheet_directory_uri();
  175. if ( ! is_child_theme() ) {
  176. foreach ( $editor_styles as $file )
  177. $mce_css[] = "$style_uri/$file";
  178. } else {
  179. $style_dir = get_stylesheet_directory();
  180. $template_uri = get_template_directory_uri();
  181. $template_dir = get_template_directory();
  182. foreach ( $editor_styles as $file ) {
  183. if ( file_exists( "$template_dir/$file" ) )
  184. $mce_css[] = "$template_uri/$file";
  185. if ( file_exists( "$style_dir/$file" ) )
  186. $mce_css[] = "$style_uri/$file";
  187. }
  188. }
  189. $mce_css = implode( ',', $mce_css );
  190. } else {
  191. $mce_css = '';
  192. }
  193. $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
  194. if ( ! empty($mce_css) )
  195. $initArray['content_css'] = $mce_css;
  196. if ( is_array($settings) )
  197. $initArray = array_merge($initArray, $settings);
  198. // For people who really REALLY know what they're doing with TinyMCE
  199. // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
  200. // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
  201. // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
  202. if ( $teeny ) {
  203. $initArray = apply_filters('teeny_mce_before_init', $initArray);
  204. } else {
  205. $initArray = apply_filters('tiny_mce_before_init', $initArray);
  206. }
  207. if ( empty($initArray['theme_advanced_buttons3']) && !empty($initArray['theme_advanced_buttons4']) ) {
  208. $initArray['theme_advanced_buttons3'] = $initArray['theme_advanced_buttons4'];
  209. $initArray['theme_advanced_buttons4'] = '';
  210. }
  211. if ( ! isset($concatenate_scripts) )
  212. script_concat_settings();
  213. $language = $initArray['language'];
  214. $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
  215. && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
  216. /**
  217. * Deprecated
  218. *
  219. * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
  220. * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter.
  221. * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
  222. */
  223. $version = apply_filters('tiny_mce_version', '');
  224. $version = 'ver=' . $tinymce_version . $version;
  225. if ( 'en' != $language )
  226. //include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
  227. include_once(MF_PATH . '/admin/mf_tiny_mce_langs.php');
  228. $mce_options = '';
  229. foreach ( $initArray as $k => $v ) {
  230. if ( is_bool($v) ) {
  231. $val = $v ? 'true' : 'false';
  232. $mce_options .= $k . ':' . $val . ', ';
  233. continue;
  234. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
  235. $mce_options .= $k . ':' . $v . ', ';
  236. continue;
  237. }
  238. $mce_options .= $k . ':"' . $v . '", ';
  239. }
  240. $mce_options = rtrim( trim($mce_options), '\n\r,' );
  241. do_action('before_wp_tiny_mce', $initArray); ?>
  242. <script type="text/javascript">
  243. /* <![CDATA[ */
  244. tinyMCEPreInit = {
  245. base : "<?php echo $baseurl; ?>",
  246. suffix : "",
  247. query : "<?php echo $version; ?>",
  248. mceInit : {<?php echo $mce_options; ?>},
  249. load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
  250. };
  251. /* ]]> */
  252. </script>
  253. <?php
  254. if ( $compressed )
  255. echo "<script type='text/javascript' src='$baseurl/wp-tinymce.php?c=1&amp;$version'></script>\n";
  256. else
  257. echo "<script type='text/javascript' src='$baseurl/tiny_mce.js?$version'></script>\n";
  258. if ( 'en' != $language && isset($lang) )
  259. echo "<script type='text/javascript'>\n$lang\n</script>\n";
  260. else
  261. echo "<script type='text/javascript' src='$baseurl/langs/wp-langs-en.js?$version'></script>\n";
  262. ?>
  263. <script type="text/javascript">
  264. /* <![CDATA[ */
  265. <?php
  266. if ( $ext_plugins )
  267. echo "$ext_plugins\n";
  268. //if ( ! $compressed ) { // the stock language files also need to be marked loaded when compressed scripts are used
  269. ?>
  270. (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.mceInit.language,th=t.mceInit.theme,pl=t.mceInit.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();
  271. <?php //} ?>
  272. tinyMCE.init(tinyMCEPreInit.mceInit);
  273. /* ]]> */
  274. </script>
  275. <?php
  276. do_action('after_wp_tiny_mce', $initArray);
  277. }
  278. ?>