PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/tinymce-advanced/tinymce-advanced.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 312 lines | 225 code | 67 blank | 20 comment | 65 complexity | 93657635e842b0bb62eaf7d64c2f2877 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: TinyMCE Advanced
  4. Plugin URI: http://www.laptoptips.ca/projects/tinymce-advanced/
  5. Description: Enables advanced features and plugins in TinyMCE, the visual editor in WordPress.
  6. Version: 3.5.8
  7. Author: Andrew Ozz
  8. Author URI: http://www.laptoptips.ca/
  9. Some code and ideas from WordPress (http://wordpress.org/). The options page for this plugin uses jQuery (http://jquery.com/).
  10. Released under the GPL v.2, http://www.gnu.org/copyleft/gpl.html
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. */
  16. if ( ! function_exists('tadv_paths') ) {
  17. /*
  18. If using domain mapping or plugins that change the path dinamically, edit these to set the proper path and URL.
  19. */
  20. function tadv_paths() {
  21. if ( !defined('TADV_URL') )
  22. define('TADV_URL', plugin_dir_url(__FILE__));
  23. if ( !defined('TADV_PATH') )
  24. define('TADV_PATH', plugin_dir_path(__FILE__));
  25. }
  26. add_action( 'plugins_loaded', 'tadv_paths', 50 );
  27. }
  28. if ( ! function_exists('tadv_version') ) {
  29. function tadv_version() {
  30. $ver = get_option('tadv_version', 0);
  31. if ( $ver < 3420 ) {
  32. update_option('tadv_version', 3420);
  33. $plugins = array_diff( get_option('tadv_plugins', array()), array('media') );
  34. update_option('tadv_plugins', $plugins);
  35. }
  36. }
  37. add_action( 'admin_init', 'tadv_version' );
  38. }
  39. if ( ! function_exists('tadv_add_scripts') ) {
  40. function tadv_add_scripts($page) {
  41. if ( 'settings_page_tinymce-advanced' == $page ) {
  42. wp_enqueue_script( 'tadv-js', TADV_URL . 'js/tadv.js', array('jquery-ui-sortable'), '3.4.2', true );
  43. wp_enqueue_style( 'tadv-css', TADV_URL . 'css/tadv-styles.css', array(), '3.4.2' );
  44. }
  45. }
  46. }
  47. if ( ! function_exists('tadv_load_defaults') ) {
  48. function tadv_load_defaults() {
  49. $tadv_options = get_option('tadv_options');
  50. if ( ! empty($tadv_options) )
  51. return;
  52. @include_once('tadv_defaults.php');
  53. if ( isset($tadv_toolbars) ) {
  54. add_option( 'tadv_options', $tadv_options );
  55. add_option( 'tadv_toolbars', $tadv_toolbars, '', 'no' );
  56. add_option( 'tadv_plugins', $tadv_plugins, '', 'no' );
  57. add_option( 'tadv_btns1', $tadv_btns1, '', 'no' );
  58. add_option( 'tadv_btns2', $tadv_btns2, '', 'no' );
  59. add_option( 'tadv_btns3', $tadv_btns3, '', 'no' );
  60. add_option( 'tadv_btns4', $tadv_btns4, '', 'no' );
  61. add_option( 'tadv_allbtns', $tadv_allbtns, '', 'no' );
  62. }
  63. }
  64. add_action( 'admin_init', 'tadv_load_defaults' );
  65. }
  66. if ( ! function_exists('tdav_get_file') ) {
  67. function tdav_get_file($path) {
  68. if ( function_exists('realpath') )
  69. $path = realpath($path);
  70. if ( ! $path || ! @is_file($path) )
  71. return '';
  72. if ( function_exists('file_get_contents') )
  73. return @file_get_contents($path);
  74. $content = '';
  75. $fp = @fopen($path, 'r');
  76. if ( ! $fp )
  77. return '';
  78. while ( ! feof($fp) )
  79. $content .= fgets($fp);
  80. fclose($fp);
  81. return $content;
  82. }
  83. }
  84. $tadv_allbtns = array();
  85. $tadv_hidden_row = 0;
  86. if ( ! function_exists('tadv_mce_btns') ) {
  87. function tadv_mce_btns($orig) {
  88. global $tadv_allbtns, $tadv_hidden_row;
  89. $tadv_btns1 = (array) get_option('tadv_btns1', array());
  90. $tadv_allbtns = (array) get_option('tadv_allbtns', array());
  91. $tadv_options = get_option('tadv_options', array());
  92. if ( in_array( 'wp_adv', $tadv_btns1 ) )
  93. $tadv_hidden_row = 2;
  94. if ( is_array($orig) && ! empty($orig) ) {
  95. $orig = array_diff( $orig, $tadv_allbtns );
  96. $tadv_btns1 = array_merge( $tadv_btns1, $orig );
  97. }
  98. return $tadv_btns1;
  99. }
  100. add_filter( 'mce_buttons', 'tadv_mce_btns', 999 );
  101. }
  102. if ( ! function_exists('tadv_mce_btns2') ) {
  103. function tadv_mce_btns2($orig) {
  104. global $tadv_allbtns, $tadv_hidden_row;
  105. $tadv_btns2 = (array) get_option('tadv_btns2', array());
  106. if ( in_array( 'wp_adv', $tadv_btns2 ) )
  107. $tadv_hidden_row = 3;
  108. if ( is_array($orig) && ! empty($orig) ) {
  109. $orig = array_diff( $orig, $tadv_allbtns );
  110. $tadv_btns2 = array_merge( $tadv_btns2, $orig );
  111. }
  112. return $tadv_btns2;
  113. }
  114. add_filter( 'mce_buttons_2', 'tadv_mce_btns2', 999 );
  115. }
  116. if ( ! function_exists('tadv_mce_btns3') ) {
  117. function tadv_mce_btns3($orig) {
  118. global $tadv_allbtns, $tadv_hidden_row;
  119. $tadv_btns3 = (array) get_option('tadv_btns3', array());
  120. if ( in_array( 'wp_adv', $tadv_btns3 ) )
  121. $tadv_hidden_row = 4;
  122. if ( is_array($orig) && ! empty($orig) ) {
  123. $orig = array_diff( $orig, $tadv_allbtns );
  124. $tadv_btns3 = array_merge( $tadv_btns3, $orig );
  125. }
  126. return $tadv_btns3;
  127. }
  128. add_filter( 'mce_buttons_3', 'tadv_mce_btns3', 999 );
  129. }
  130. if ( ! function_exists('tadv_mce_btns4') ) {
  131. function tadv_mce_btns4($orig) {
  132. global $tadv_allbtns;
  133. $tadv_btns4 = (array) get_option('tadv_btns4', array());
  134. if ( is_array($orig) && ! empty($orig) ) {
  135. $orig = array_diff( $orig, $tadv_allbtns );
  136. $tadv_btns4 = array_merge( $tadv_btns4, $orig );
  137. }
  138. return $tadv_btns4;
  139. }
  140. add_filter( 'mce_buttons_4', 'tadv_mce_btns4', 999 );
  141. }
  142. if ( ! function_exists('tadv_mce_options') ) {
  143. function tadv_mce_options($init) {
  144. global $tadv_hidden_row;
  145. $tadv_options = get_option('tadv_options', array());
  146. if ( $tadv_hidden_row > 0 )
  147. $init['wordpress_adv_toolbar'] = 'toolbar' . $tadv_hidden_row;
  148. else
  149. $init['wordpress_adv_hidden'] = false;
  150. if ( isset($tadv_options['no_autop']) && $tadv_options['no_autop'] == 1 )
  151. $init['apply_source_formatting'] = true;
  152. if ( isset($tadv_options['hideclasses']) && $tadv_options['hideclasses'] == 1 )
  153. $init['class_filter'] = '[function(){return false;}]';
  154. return $init;
  155. }
  156. add_filter( 'tiny_mce_before_init', 'tadv_mce_options' );
  157. }
  158. if ( ! function_exists('tadv_htmledit') ) {
  159. function tadv_htmledit($c) {
  160. $tadv_options = get_option('tadv_options', array());
  161. if ( isset($tadv_options['no_autop']) && $tadv_options['no_autop'] == 1 ) {
  162. $c = str_replace( array('&amp;', '&lt;', '&gt;'), array('&', '<', '>'), $c );
  163. $c = wpautop($c);
  164. $c = htmlspecialchars($c, ENT_NOQUOTES);
  165. }
  166. return $c;
  167. }
  168. add_filter('htmledit_pre', 'tadv_htmledit', 999);
  169. }
  170. if ( ! function_exists('tmce_replace') ) {
  171. function tmce_replace() {
  172. $tadv_options = get_option('tadv_options', array());
  173. $tadv_plugins = get_option('tadv_plugins', array());
  174. if ( isset($tadv_options['no_autop']) && $tadv_options['no_autop'] == 1 ) { ?>
  175. <script type="text/javascript">
  176. if ( typeof(jQuery) != 'undefined' ) {
  177. jQuery('body').bind('afterPreWpautop', function(e, o){
  178. o.data = o.unfiltered
  179. .replace(/caption\]\[caption/g, 'caption] [caption')
  180. .replace(/<object[\s\S]+?<\/object>/g, function(a) {
  181. return a.replace(/[\r\n]+/g, ' ');
  182. });
  183. }).bind('afterWpautop', function(e, o){
  184. o.data = o.unfiltered;
  185. });
  186. }
  187. </script>
  188. <?php
  189. }
  190. }
  191. add_action( 'after_wp_tiny_mce', 'tmce_replace' );
  192. }
  193. if ( ! function_exists('tadv_load_plugins') ) {
  194. function tadv_load_plugins($plug) {
  195. $tadv_plugins = get_option('tadv_plugins');
  196. $tadv_options = get_option('tadv_options', array());
  197. if ( isset($tadv_options['editorstyle']) && $tadv_options['editorstyle'] == '1' )
  198. add_editor_style(); // import user created editor-style.css
  199. if ( empty($tadv_plugins) || !is_array($tadv_plugins) )
  200. return $plug;
  201. $plugpath = TADV_URL . 'mce/';
  202. $plug = (array) $plug;
  203. foreach( $tadv_plugins as $plugin )
  204. $plug["$plugin"] = $plugpath . $plugin . '/editor_plugin.js';
  205. return $plug;
  206. }
  207. add_filter( 'mce_external_plugins', 'tadv_load_plugins', 999 );
  208. }
  209. if ( ! function_exists('tadv_load_langs') ) {
  210. function tadv_load_langs($langs) {
  211. $tadv_plugins = get_option('tadv_plugins');
  212. if ( empty($tadv_plugins) || !is_array($tadv_plugins) )
  213. return $langs;
  214. $langpath = TADV_PATH . 'mce/';
  215. $dolangs = array( 'advhr', 'advimage', 'advlink', 'searchreplace', 'style', 'table', 'xhtmlxtras' );
  216. $langs = (array) $langs;
  217. foreach( $tadv_plugins as $plugin ) {
  218. if ( !in_array( $plugin, $dolangs ) )
  219. continue;
  220. $langs["$plugin"] = $langpath . $plugin . '/langs/langs.php';
  221. }
  222. return $langs;
  223. }
  224. add_filter( 'mce_external_languages', 'tadv_load_langs' );
  225. }
  226. if ( ! function_exists('tadv_page') ) {
  227. function tadv_page() {
  228. if ( !defined('TADV_ADMIN_PAGE') )
  229. define('TADV_ADMIN_PAGE', true);
  230. tadv_paths();
  231. include_once( TADV_PATH . 'tadv_admin.php');
  232. }
  233. }
  234. if ( ! function_exists('tadv_menu') ) {
  235. function tadv_menu() {
  236. if ( function_exists('add_options_page') ) {
  237. add_options_page( 'TinyMCE Advanced', 'TinyMCE Advanced', 'manage_options', 'tinymce-advanced', 'tadv_page' );
  238. add_action( 'admin_enqueue_scripts', 'tadv_add_scripts' );
  239. }
  240. }
  241. add_action( 'admin_menu', 'tadv_menu' );
  242. }