home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / tinymce-advanced / tinymce-advanced.php < prev   
Encoding:
PHP Script  |  2008-02-20  |  32.1 KB  |  677 lines

  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.
  6. Version: 2.2
  7. Author: Andrew Ozz
  8. Author URI: http://www.laptoptips.ca/
  9.  
  10. Some code and ideas from WordPress(http://wordpress.org/). The options page for this plugin uses Prototype.js by Sam Stephenson(http://prototype.conio.net/) and Scriptaculous by Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us). The Javascript files have been compressed and concatenated for faster loading.
  11.  
  12. Released under the GPL, http://www.gnu.org/copyleft/gpl.html
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18. */
  19.  
  20. if ('tinymce-advanced.php' == basename($_SERVER['SCRIPT_NAME']))
  21.     exit;
  22.  
  23. if( ! function_exists('tadv_admin_head') ) {
  24. function tadv_admin_head() {
  25.     global $is_winIE;
  26. ?>
  27. <script type="text/javascript" src="<?php bloginfo('wpurl'); ?>/wp-content/plugins/tinymce-advanced/js/tadv-all.js?ver=1.7.0-2.1"></script>
  28. <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-content/plugins/tinymce-advanced/css/tadv-styles.css?ver=2.1" type="text/css" />
  29. <?php
  30. } } // end tadv_admin_head
  31.  
  32. if( ! function_exists('tadv_page') ) {
  33. function tadv_page() {
  34.     global $is_winIE;
  35.  
  36. if ( ! current_user_can('edit_themes') )
  37.     wp_die( __( 'Cheatin’ uh?' ));
  38.  
  39. $tadv_toolbars = (array) get_option('tadv_toolbars');
  40. $tadv_options = (array) get_option('tadv_options');
  41. $imgpath = get_bloginfo('wpurl') . '/wp-content/plugins/tinymce-advanced/images/';
  42.  
  43. if( isset( $_POST['save'] ) ) {
  44.     check_admin_referer( 'tadv-save-buttons-order' );
  45.     parse_str( $_POST['toolbar-1order'], $tb1 );
  46.     parse_str( $_POST['toolbar-2order'], $tb2 );
  47.     parse_str( $_POST['toolbar-3order'], $tb3 );
  48.     $tadv_toolbars = $tb1 + $tb2 + $tb3;
  49.     update_option( 'tadv_toolbars', $tadv_toolbars );
  50.  
  51.     $tadv_options['advlink'] = $_POST['advlink'] ? '1' : '';
  52.     $tadv_options['advimage'] = $_POST['advimage'] ? '1' : '';
  53.     $tadv_options['contextmenu'] = $_POST['contextmenu'] ? '1' : '';
  54.     $tadv_options['importcss'] = $_POST['importcss'] ? '1' : '';
  55.     $tadv_options['fixcss'] = $_POST['fixcss'] ? '1' : '';
  56.     $update_tadv_options = true;
  57. }
  58.     
  59. if( isset( $_POST['reset'] ) ) {
  60.     check_admin_referer( 'tadv-save-buttons-order' );
  61.     $tadv_toolbars = '';
  62.     $tadv_options = '';
  63. }
  64.  
  65. if( empty($tadv_toolbars) ) {
  66.     $tb1 = array( 'bold', 'italic', 'strikethrough', 'underline', 'separator1', 'bullist', 'numlist', 'outdent',  'indent', 'separator2', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'separator3', 'link', 'unlink', 'separator4', 'image', 'styleprops', 'separator12', 'wp_more', 'wp_page', 'separator5', 'spellchecker', 'search', 'separator6', 'wp_help', 'fullscreen' );
  67.  
  68.     $tb2 = '';
  69.  
  70.     $tb3 = array( 'styleselect', 'formatselect', 'paste', 'pastetext', 'pasteword', 'separator7', 'cleanup', 'separator8', 'charmap', 'print', 'separator9', 'emotions', 'separator10', 'sup', 'sub', 'separator11', 'undo', 'redo', 'attribs' );
  71.     
  72.     $tadv_toolbars = array( 'toolbar-1' => $tb1, 'toolbar-2' => $tb2, 'toolbar-3' => $tb3 );
  73.     $tadv_options = array( 'advlink' => '1', 'advimage' => '1', 'importcss' => '1', 'refresh' => '1' );
  74.     
  75.     update_option( 'tadv_toolbars', $tadv_toolbars );
  76.     $update_tadv_options = true;
  77. }
  78.  
  79. if( is_array($tadv_toolbars['toolbar-1']) ) {
  80.     $btns1 = $tadv_toolbars['toolbar-1'];
  81.     
  82.     foreach( $btns1 as $k => $v ) {
  83.         if( strpos($v, 'separator') !== false ) $btns1[$k] = 'separator';
  84.         if( $v == 'layer' ) $l = $k;
  85.         if( empty($v) ) unset($btns1[$k]);
  86.     }
  87.     if( $l ) array_splice( $btns1, $l, 1, array('insertlayer', 'moveforward', 'movebackward', 'absolute') );
  88. }
  89.  
  90. if( is_array($tadv_toolbars['toolbar-2']) ) {
  91.     $btns2 = $tadv_toolbars['toolbar-2'];
  92.     
  93.     foreach( $btns2 as $k => $v ) {
  94.         if( strpos($v, 'separator') !== false ) $btns2[$k] = 'separator';
  95.         if( $v == 'layer' ) $l = $k;
  96.         if( empty($v) ) unset($btns2[$k]);
  97.     }
  98.     if( $l ) array_splice( $btns2, $l, 1, array('insertlayer', 'moveforward', 'movebackward', 'absolute') );
  99.     if( empty($btns1) ) {
  100.         $btns1 = $btns2;
  101.         $btns2 = array();
  102.     }    
  103. }
  104.  
  105. if( is_array($tadv_toolbars['toolbar-3']) ) {
  106.     $btns3 = $tadv_toolbars['toolbar-3'];
  107.     foreach( $btns3 as $k => $v ) {
  108.         if( strpos($v, 'separator') !== false ) $btns3[$k] = 'separator';
  109.         if( $v == 'layer' ) $l = $k;
  110.     }
  111.     if( $l ) array_splice( $btns3, $l, 1, array('insertlayer', 'moveforward', 'movebackward', 'absolute') );
  112.     if( is_array($btns2) && ! empty($btns2) ) {
  113.         $btns2[] = 'wp_adv';
  114.         $btns2[] = 'wp_adv_start';
  115.         $btns3[] = 'wp_adv_end';
  116.         $btns2 = array_merge( $btns2, $btns3 );
  117.     } elseif ( is_array($btns1) && ! empty($btns1) ) {
  118.         $btns1[] = 'wp_adv';
  119.         $btns1[] = 'wp_adv_start';
  120.         $btns3[] = 'wp_adv_end';
  121.         $btns1 = array_merge( $btns1, $btns3 );
  122.     } else {
  123.         $btns1 = $btns3;
  124.         $btns3 = '';
  125.     }
  126. }
  127.  
  128. if( empty($btns1) && empty($btns2) ) {
  129.     $allbtns = array();
  130.     ?><div class="error" id="message"><p>All toolbars are empty!</p></div><?php
  131. } else {
  132.     $allbtns = array_merge( (array) $btns1, (array) $btns2 );
  133. }
  134.  
  135. if( in_array('advhr', $allbtns) ) $plugins[] = 'advhr';
  136. if( in_array('fullscreen', $allbtns) ) $plugins[] = 'fullscreen';
  137. if( in_array('insertlayer', $allbtns) ) $plugins[] = 'layer';
  138. if( in_array('visualchars', $allbtns) ) $plugins[] = 'visualchars';
  139.  
  140. if( in_array('iespell', $allbtns) ) $plugins[] = 'iespell';
  141. if( in_array('nonbreaking', $allbtns) ) $plugins[] = 'nonbreaking';
  142. if( in_array('styleprops', $allbtns) ) $plugins[] = 'style';
  143. if( in_array('emotions', $allbtns) ) $plugins[] = 'emotions';
  144.  
  145. if( in_array('print', $allbtns) ) $plugins[] = 'print';
  146. if( in_array('search', $allbtns) ||
  147.     in_array('replace', $allbtns) ) $plugins[] = 'searchreplace';
  148.  
  149. if( in_array('cite', $allbtns) || 
  150.     in_array('ins', $allbtns) ||
  151.     in_array('del', $allbtns) ||
  152.     in_array('abbr', $allbtns) ||
  153.     in_array('acronym', $allbtns) ||
  154.     in_array('attribs', $allbtns) ) $plugins[] = 'xhtmlxtras';
  155.  
  156. if ( $tadv_options['advlink'] == '1' ) $plugins[] = 'advlink';
  157. if ( $tadv_options['advimage'] == '1' ) $plugins[] = 'advimage';
  158. if ( $tadv_options['contextmenu'] == '1' ) $plugins[] = 'contextmenu';
  159. $plugins = array_merge( array( 'table', 'media' ), (array) $plugins );
  160.  
  161. if( get_option('tadv_plugins') != $plugins ) update_option( 'tadv_plugins', $plugins ); 
  162. if( get_option('tadv_btns1') != $btns1 ) update_option( 'tadv_btns1', $btns1 );
  163. if( get_option('tadv_btns2') != $btns2 ) update_option( 'tadv_btns2', $btns2 ); 
  164.  
  165. $buttons = array( 'Bold' => 'bold', 'Italic' => 'italic', 'Strikethrough' => 'strikethrough', 'Underline' => 'underline', 'Bullet List' => 'bullist', 'Numbered List' => 'numlist', 'Outdent' => 'outdent', 'Indent' => 'indent', 'Allign Left' => 'justifyleft', 'Center' => 'justifycenter', 'Alligh Right' => 'justifyright', 'Justify' => 'justifyfull', 'Cut' => 'cut', 'Copy' => 'copy', 'Paste' => 'paste', 'Link' => 'link', 'Remove Link' => 'unlink', 'Insert Image' => 'image', 'More Tag' => 'wp_more', 'Split Page' => 'wp_page', 'Search' => 'search', 'Replace' => 'replace', 'Select Font' => 'fontselect', 'Font Size' => 'fontsizeselect', 'Help' => 'wp_help', 'Full Screen' => 'fullscreen', 'CSS Styles' => 'styleselect', 'Format' => 'formatselect', 'Text Color' => 'forecolor', 'Paste as Text' => 'pastetext', 'Paste from Word' => 'pasteword', 'Remove Format' => 'removeformat', 'Clean Code' => 'cleanup', 'Check Spelling' => 'spellchecker', 'IE Spell' => 'iespell', 'Character Map' => 'charmap', 'Print' => 'print', 'Undo' => 'undo', 'Redo' => 'redo', 'Table' => 'tablecontrols', 'Citation' => 'cite', 'Inserted Text' => 'ins', 'Deleted Text' => 'del', 'Abbreviation' => 'abbr', 'Acronym' => 'acronym', 'XHTML Attribs' => 'attribs', 'Layer' => 'layer', 'Advanced HR' => 'advhr', 'View HTML' => 'code', 'Hidden Chars' => 'visualchars', 'NB Space' => 'nonbreaking', 'Sub' => 'sub', 'Sup' => 'sup', 'Visual Aids' => 'visualaid', 'Anchor' => 'anchor', 'Style' => 'styleprops', 'Smilies' => 'emotions' );  
  166.  
  167. if( ! $is_winIE ) $buttons['Insert Movie'] = 'media';
  168.  
  169. $active_plugins = get_settings('active_plugins');
  170. $add = array();
  171. foreach( $active_plugins as $plug ) {
  172.     if( strpos( $plug, 'wpg2' ) !== false ) $add['Gallery 2'] = 'g2image';
  173.     if( strpos( $plug, 'nextgen-gallery' ) !== false ) $add['Nextgen Gallery'] = 'NextGEN';
  174.     if( strpos( $plug, 'vipers-video' ) !== false ) $add["Viper's Video"] = 'vipersvideoquicktags';
  175.     if( strpos( $plug, 'embedded-video' ) !== false ) $add['EmbeddedVideo'] = 'embeddedvideo';
  176.     if( strpos( $plug, 'imagemanager' ) !== false ) $add['Image Manager'] = 'ps_imagemanager_tinymceplugin';
  177. }
  178.  
  179. if( ! empty($add) ) $buttons += $add;
  180.  
  181. $separators = array( 's1' => 'separator1', 's2' => 'separator2', 's3' => 'separator3', 's4' => 'separator4', 's5' => 'separator5', 's6' => 'separator6', 's7' => 'separator7', 's8' => 'separator8', 's9' => 'separator9', 's10' => 'separator10', 's11' => 'separator11', 's12' => 'separator12', 's13' => 'separator13', 's14' => 'separator14', 's15' => 'separator15', 's16' => 'separator16', 's17' => 'separator17', 's18' => 'separator18', 's19' => 'separator19', 's20' => 'separator20' );
  182.  
  183. $buttons += $separators;
  184.  
  185. if ( isset( $_POST['tadv'] ) ) { 
  186.     if( isset($_POST['save']) ) { ?><div class="updated" id="message"><p>Options saved</p></div><?php }
  187.     if( isset($_POST['reset']) ) { ?><div class="updated" id="message"><p>Defaults loaded</p></div><?php }
  188.     
  189.     $tadv_options['refresh'] = '1';
  190.     $update_tadv_options = true;
  191. } ?>
  192.  
  193. <div class="wrap">
  194.     <h2>TinyMCE Buttons Arrangement</h2>
  195.  
  196.     <form id="tadvadmin" method="post" onsubmit="tadvSerializeAll();">
  197.     <p>Drag and drop buttons onto the toolbars below.</p>
  198.     
  199.         <input id="toolbar-1order" name="toolbar-1order" value="" type="hidden" />
  200.         <input id="toolbar-2order" name="toolbar-2order" value="" type="hidden" />
  201.         <input id="toolbar-3order" name="toolbar-3order" value="" type="hidden" />
  202.         <input name="tadv" value="1" type="hidden" />        
  203.         <div id="tadvzones">
  204.         
  205.         <div class="tadvdropzone">
  206.         <ul style="position: relative;" id="toolbar-1">
  207. <?php
  208. if( is_array($tadv_toolbars['toolbar-1']) ) {
  209.     $tb1 = array();
  210.     foreach( $tadv_toolbars['toolbar-1'] as $k ) {
  211.         $t = array_intersect( $buttons, (array) $k );
  212.         $tb1 = $tb1 + $t;
  213.     }
  214.  
  215.     foreach( $tb1 as $name => $btn ) { 
  216.         if( strpos( $btn, 'eparator' ) ) { ?>
  217.  
  218. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="separator" id="pre_<?php echo $btn; ?>">
  219. <div class="tadvitem"><img src="<?php echo $imgpath . 'separator.gif'; ?>" alt="Separator" title="Separator" /></div></li>
  220. <?php
  221.         } else { ?>
  222.  
  223. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="tadvmodule" id="pre_<?php echo $btn; ?>">
  224. <div class="tadvitem"><img src="<?php echo $imgpath . $btn . '.gif'; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" />
  225. <span class="descr"> <?php echo $name; ?></span></div></li>
  226. <?php   }
  227.     }
  228.     $buttons = array_diff( $buttons, $tb1 );
  229. } ?>
  230.  
  231.         </ul></div>
  232.         <br class="clear" />
  233.         
  234.         <div class="tadvdropzone">
  235.         <ul style="position: relative;" id="toolbar-2">
  236. <?php
  237. if( is_array($tadv_toolbars['toolbar-2']) ) {
  238.     $tb2 = array();
  239.     foreach( $tadv_toolbars['toolbar-2'] as $k ) {
  240.         $t = array_intersect( $buttons, (array) $k );
  241.         $tb2 = $tb2 + $t;
  242.     }
  243.     foreach( $tb2 as $name => $btn ) { 
  244.         if( strpos( $btn, 'eparator' ) ) { ?>
  245.  
  246. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="separator" id="pre_<?php echo $btn; ?>">
  247. <div class="tadvitem"><img src="<?php echo $imgpath . 'separator.gif'; ?>" alt="Separator" title="Separator" /></div></li>
  248. <?php
  249.         } else { ?>
  250.  
  251. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="tadvmodule" id="pre_<?php echo $btn; ?>">
  252. <div class="tadvitem"><img src="<?php echo $imgpath . $btn . '.gif'; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" />
  253. <span class="descr"> <?php echo $name; ?></span></div></li>
  254. <?php   }
  255.     }
  256.     $buttons = array_diff( $buttons, $tb2 );
  257. } ?>
  258.         
  259.         </ul></div>
  260.         <br class="clear" />
  261.         
  262.         <div class="tadvdropzone">
  263.         <ul style="position: relative;" id="toolbar-3">
  264. <?php   
  265. if( is_array($tadv_toolbars['toolbar-3']) ) {
  266.     $tb3 = array();
  267.     foreach( $tadv_toolbars['toolbar-3'] as $k ) {
  268.         $t = array_intersect( $buttons, (array) $k );
  269.         $tb3 = $tb3 + $t;
  270.     }
  271.     foreach( $tb3 as $name => $btn ) { 
  272.         if( strpos( $btn, 'eparator' ) ) { ?>
  273.  
  274. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="separator" id="pre_<?php echo $btn; ?>">
  275. <div class="tadvitem"><img src="<?php echo $imgpath . 'separator.gif'; ?>" alt="Separator" title="Separator" /></div></li>
  276. <?php
  277.         } else { ?>
  278.  
  279. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="tadvmodule" id="pre_<?php echo $btn; ?>">
  280. <div class="tadvitem"><img src="<?php echo $imgpath . $btn . '.gif'; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" />
  281. <span class="descr"> <?php echo $name; ?></span></div></li>
  282. <?php   }
  283.     }
  284.     $buttons = array_diff( $buttons, $tb3 );
  285. }
  286.  
  287. $tadv_btns4 = is_array($buttons) ? array_values($buttons) : array();
  288. if( get_option('tadv_btns4') != $tadv_btns4 ) update_option( 'tadv_btns4', $tadv_btns4 ); ?>
  289.  
  290.         </ul></div>
  291.         <br class="clear" />
  292.         </div>
  293.         
  294.         <div id="tadvWarnmsg" ></div>
  295.         
  296.         <div id="tadvpalettediv">
  297.         <ul style="position: relative;" id="tadvpalette">
  298. <?php
  299. if( is_array($buttons) ) {
  300.     foreach( $buttons as $name => $btn ) { 
  301.         if( strpos( $btn, 'eparator' ) ) { ?>
  302.  
  303. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="separator" id="pre_<?php echo $btn; ?>">
  304. <div class="tadvitem"><img src="<?php echo $imgpath . 'separator.gif'; ?>" alt="Separator" title="Separator" /></div></li>
  305. <?php
  306.         } else { ?>
  307.  
  308. <li style="position: relative; top: 0px; left: 0px; z-index: 0; opacity: 0.999999;" class="tadvmodule" id="pre_<?php echo $btn; ?>">
  309. <div class="tadvitem"><img src="<?php echo $imgpath . $btn . '.gif'; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" />
  310. <span class="descr"> <?php echo $name; ?></span></div></li>
  311. <?php   }
  312.     } 
  313. } ?>
  314.         </ul>
  315.        </div>
  316.  
  317.         <table class="clear" style="margin:10px 0"><tr><td style="padding:2px 12px 8px;">
  318.         Also enable: 
  319.         <label for="advlink" class="tadv-box">Advanced Link  
  320.         <input type="checkbox" class="tadv-chk"  name="advlink" id="advlink" <?php if ( $tadv_options['advlink'] == '1' ) echo ' checked="checked"'; ?> /></label> •
  321.  
  322.         <label for="advimage" class="tadv-box">Advanced Image  
  323.         <input type="checkbox" class="tadv-chk"  name="advimage" id="advimage" <?php if ( $tadv_options['advimage'] == '1' ) echo ' checked="checked"'; ?> /></label> •
  324.  
  325.         <label for="contextmenu" class="tadv-box">Context Menu  
  326.         <input type="checkbox" class="tadv-chk"  name="contextmenu" id="contextmenu" <?php if ( $tadv_options['contextmenu'] == '1' ) echo ' checked="checked"'; ?> /></label>
  327.         (to show the browser's context menu in Firefox and use the spellchecker, hold down the "Ctrl" key).
  328.         </td></tr>
  329.  
  330.         <tr><td style="border:1px solid #CD0000;padding:2px 12px 8px;">
  331.         <p style="font-weight:bold;color:#CD0000;">Advanced</p> 
  332.         
  333.         <p>· Import the current theme's 
  334.         <label for="importcss" class="tadv-box">CSS classes  
  335.         <input type="checkbox" class="tadv-chk"  name="importcss" id="importcss" <?php if ( $tadv_options['importcss'] == '1' ) echo ' checked="checked"'; ?> /></label></p>
  336.         
  337.          <p>· If the editor doesn't look right, 
  338.         <label for="fixcss" class="tadv-box">reset some of the CSS styles  
  339.         <input type="checkbox" class="tadv-chk"  name="fixcss" id="fixcss" <?php if ( $tadv_options['fixcss'] == '1' ) echo ' checked="checked"'; ?> /></label></p> 
  340.         
  341.         <p>You can also disable the importing of your theme's css and <a href="templates.php?file=wp-content/plugins/tinymce-advanced/css/tadv-tinymce.css" >add the names of CSS classes</a> that are defined in your theme and you want them to appear in the "Styles" drop-down menu. You don't need to copy the whole CSS classes, just add their names, like: <code>.my-class{}</code>, <code>.my-other-class{}</code>, etc. (add each name on a new line).</p>
  342.         </td></tr>
  343. <?php
  344.     $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower(get_locale());
  345.     if ( $mce_locale != 'en' ) {
  346.         
  347.         if( ! file_exists(ABSPATH . PLUGINDIR . '/tinymce-advanced/mce/advlink/langs/' . $mce_locale . '.js') ) {
  348.             $mce_locale_lang = substr($mce_locale, 0, 2);
  349.                 
  350.             if( strlen($mce_locale) == 2 ) {
  351.                 if( file_exists(ABSPATH . PLUGINDIR . '/tinymce-advanced/mce/advlink/langs/' . $mce_locale . '_' . $mce_locale . '.js') ) {
  352.                     $lang = $mce_locale . '_' . $mce_locale;
  353.                 }
  354.             } elseif( file_exists(ABSPATH . PLUGINDIR . '/tinymce-advanced/mce/advlink/langs/' . $mce_locale_lang . '.js') ) {
  355.                 $lang = $mce_locale_lang;
  356.             }
  357.             
  358.             if( isset($lang) ) {
  359.                 if( $tadv_options['tadv_lang'] != $lang ) {
  360.                     $tadv_options['tadv_lang'] = $lang;
  361.                     $update_tadv_options = true;
  362.                 }
  363.             } else {
  364.             
  365.                 $open = opendir(ABSPATH . PLUGINDIR . '/tinymce-advanced/mce/advlink/langs/');
  366.                 $tadv_langs = array();
  367.                 while( false !== ($file = readdir($open)) ) {
  368.                     if( '.' == $file || '..' == $file ) continue;
  369.                     $tadv_langs[] = substr($file, 0, -3);
  370.                     if( substr($file, 0, 2) == $mce_locale_lang )
  371.                         $closest_lang = substr($file, 0, -3);
  372.                 }
  373.             
  374.                 if( isset( $_POST['tadv_lang'] ) ) {
  375.                     check_admin_referer( 'tadv-save-buttons-order' );
  376.                     if( in_array( $_POST['tadv_lang'], (array) $tadv_langs ) ) {
  377.                         if( $tadv_options['tadv_lang'] != $_POST['tadv_lang'] ) {
  378.                             $tadv_options['tadv_lang'] = $_POST['tadv_lang'];
  379.                             $update_tadv_options = true;
  380.                         }
  381.                     }
  382.                 }
  383. ?>
  384.         <tr><td style="padding:2px 12px 8px;">
  385.         <p style="font-weight:bold;">Language Settings</p>
  386.         <p>Your WordPress language is set to <strong><?php echo get_locale(); ?></strong>. However there is no matching language installed for TinyMCE's plugins. <?php if( isset($closest_lang) ) { ?>The closest match seem to be <strong><?php echo $closest_lang . '</strong>.'; } ?></p>
  387.         <p>Please select one of the installed languages 
  388.  
  389.         <select name="tadv_lang" id="tadv_lang" style="width:100px;padding:0;">
  390.         <option value="en">en(default)</option>
  391.             <?php if( ! empty($tadv_langs) ) { ?>
  392.                 <?php foreach( $tadv_langs as $la ) { 
  393.                     if( $la == 'en' ) continue; ?>
  394.         <option value="<?php echo $la; if( $tadv_options['tadv_lang'] == $la ) echo '" selected="selected' ?>"><?php echo $la; ?></option>
  395.                 <?php } ?>
  396.             <?php } ?>
  397.         </select>
  398.  
  399.         </p></td></tr>
  400. <?php       }
  401.         }
  402.     } // end mce_locale
  403. ?>      </table>
  404.         
  405. <script type="text/javascript">
  406. // <![CDATA[
  407. Sortable.create("toolbar-1", {
  408.   dropOnEmpty: true, 
  409.   containment: ["tadvpalette","toolbar-1","toolbar-2","toolbar-3"], 
  410.   starteffect: function(element){new Effect.Opacity(element, {duration:0, from:1.0, to:0.7}); },
  411.   endeffect: function(element){new Effect.Opacity(element, {duration:0, from:0.7, to:1.0}); },
  412.   overlap: 'horizontal', 
  413.   constraint: false, onUpdate: tadvUpdateAll, 
  414.   format: /^pre_(.*)$/
  415. });
  416. Sortable.create("toolbar-2", {
  417.   dropOnEmpty: true, 
  418.   containment: ["tadvpalette","toolbar-1","toolbar-2","toolbar-3"], 
  419.   starteffect: function(element){new Effect.Opacity(element, {duration:0, from:1.0, to:0.7}); },
  420.   endeffect: function(element){new Effect.Opacity(element, {duration:0, from:0.7, to:1.0}); },
  421.   overlap: 'horizontal', 
  422.   constraint: false, onUpdate: tadvUpdateAll, 
  423.   format: /^pre_(.*)$/
  424. });
  425. Sortable.create("toolbar-3", {
  426.   dropOnEmpty: true, 
  427.   containment: ["tadvpalette","toolbar-1","toolbar-2","toolbar-3"], 
  428.   starteffect: function(element){new Effect.Opacity(element, {duration:0, from:1.0, to:0.7}); },
  429.   endeffect: function(element){new Effect.Opacity(element, {duration:0, from:0.7, to:1.0}); },
  430.   overlap: 'horizontal', 
  431.   constraint: false, onUpdate: tadvUpdateAll, 
  432.   format: /^pre_(.*)$/
  433. });
  434. Sortable.create("tadvpalette", {
  435.   dropOnEmpty: true, 
  436.   containment: ["tadvpalette","toolbar-1","toolbar-2","toolbar-3"], 
  437.   starteffect: function(element){new Effect.Opacity(element, {duration:0, from:1.0, to:0.7}); },
  438.   endeffect: function(element){new Effect.Opacity(element, {duration:0, from:0.7, to:1.0}); },
  439.   overlap: 'horizontal', 
  440.   constraint: false, onUpdate: tadvUpdateAll, 
  441.   format: /^pre_(.*)$/
  442. });
  443. // ]]>
  444. </script>
  445.         
  446. <p class="submit">
  447.     <?php wp_nonce_field( 'tadv-save-buttons-order' ); ?>
  448.     <input type="submit" name="reset" id="reset" value="<?php _e( 'Load Defaults' ); ?>" />
  449.     <input type="submit" name="save" id="save" value="<?php _e( 'Save Changes' ); ?>" />
  450. </p>
  451. </form>
  452.         
  453. <br class="clear" />
  454. </div>
  455. <?php 
  456.     if( $update_tadv_options )
  457.         update_option( 'tadv_options', $tadv_options );
  458.  
  459. } } // end tadv_page
  460.  
  461. if( ! class_exists('tadv_mceClass') ) {
  462. class tadv_mceClass {
  463.     var $extra_btns = array();
  464.  
  465.     function tadv_mceClass() {
  466.     
  467.         if ( 'plugins.php' == basename($_SERVER['SCRIPT_NAME']) || 'plugins.php' == basename($_SERVER['PHP_SELF']) ) 
  468.             if ( isset($_GET['action']) && $_GET['action'] == 'deactivate' && $_GET['plugin'] == 'tinymce-advanced/tinymce-advanced.php') 
  469.                 $this->tadv_deactivate();
  470.     }
  471.  
  472.     function tadv_mce_opt() { 
  473. ?>
  474.         valid_child_elements : "table[thead|tbody|tfoot|tr|td|th],object[param|embed|%itrans|#text]",
  475.         extended_valid_elements : "object[*],param[name|value|valuetype|type|id],embed[*]",
  476.         fix_table_elements : true,
  477.         convert_fonts_to_spans : true,
  478.         font_size_style_values : "8pt,10pt,12pt,14pt,18pt,24pt,36pt",
  479.         paste_auto_cleanup_on_paste : true,
  480.         cleanup_on_startup : false,
  481.         force_hex_style_colors : true,
  482.         inline_styles : true,
  483. <?php 
  484.         $tadv_options = (array) get_option('tadv_options');
  485.         $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower(get_locale());
  486.  
  487.         if ( $mce_locale != 'en' ) {
  488.             if( ! file_exists(ABSPATH . PLUGINDIR . '/tinymce-advanced/mce/advlink/langs/' . $mce_locale . '.js') ) {
  489.                 if( isset($tadv_options['tadv_lang']) )  echo 'language : "' . $tadv_options['tadv_lang'] . '",' . "\n";
  490.                 else echo 'language : "en",' . "\n";
  491.             }
  492.         }
  493.     }
  494.  
  495.     function tdav_css($wp) {
  496.         $tadv_options = (array) get_option('tadv_options');
  497.         
  498.         if( $tadv_options['importcss'] == '1' ) $add = get_bloginfo('stylesheet_url') . ',';
  499.         else $add = '';
  500.  
  501.         $add .=  get_bloginfo('wpurl') . '/wp-content/plugins/tinymce-advanced/css/tadv-tinymce.css?r=' . $tadv_options['refresh'];
  502.         
  503.         if( $tadv_options['fixcss'] == '1' )
  504.             $add .= ',' . get_bloginfo('wpurl') . '/wp-content/plugins/tinymce-advanced/css/tadv-fixstyle.css';
  505.         
  506.         return $add;
  507.     }
  508.  
  509.     function tadv_mce_plugins($plug) {
  510.  
  511.         $tadv_plugins = (array) get_option('tadv_plugins');
  512.         return array_merge($plug, $tadv_plugins);
  513.     }
  514.  
  515.     function tadv_mce_btns($orig) {
  516.         global $is_winIE;
  517.     
  518.         $tadv_btns1 = (array) get_option('tadv_btns1');
  519.  
  520.         $this->extra_btns = array_merge( (array) $this->extra_btns, (array) $orig );
  521.         $this->extra_btns = array_diff( $this->extra_btns, $tadv_btns1 );
  522.  
  523.         if( $is_winIE ) $tadv_btns1 = array_diff( $tadv_btns1, array('media') );
  524.     
  525.         return $tadv_btns1;
  526.     }
  527.  
  528.     function tadv_mce_btns2($orig) {
  529.         global $is_winIE;
  530.     
  531.         $tadv_btns2 = (array) get_option('tadv_btns2');
  532.         $tadv_btns4 = (array) get_option('tadv_btns4');
  533.     
  534.         $orig = array_merge( (array) $this->extra_btns, (array) $orig );
  535.         $orig = array_diff( $orig, $tadv_btns2, $tadv_btns4, array('wp_adv_start', 'wp_adv', 'wp_adv_end', 'separator') );
  536.         
  537.         if( ! empty($orig) )
  538.             $tadv_btns2 = array_merge($orig, $tadv_btns2);
  539.  
  540.         if( $is_winIE ) $tadv_btns2 = array_diff( $tadv_btns2, array('media') );
  541.     
  542.         return $tadv_btns2;
  543.     }
  544.  
  545.     function tadv_mce_btns3($orig) {
  546.  
  547.         if( is_array($orig) && ! empty($orig) ) 
  548.             $this->extra_btns = $orig;
  549.  
  550.         return array();
  551.     }
  552.     
  553.     function tadv_load_plugins() { 
  554.         $tadv_plugins = (array) get_option('tadv_plugins');
  555.         $plugpath = get_bloginfo('wpurl') . '/wp-content/plugins/tinymce-advanced/mce/';
  556.         
  557.         foreach( $tadv_plugins as $plug )
  558.             echo 'tinyMCE.loadPlugin("' . $plug . '","' . $plugpath . $plug . '");' . "\n";
  559.     }
  560.     
  561.     function tadv_refresh_mceconfig($loc) {
  562.         
  563.         $tadv_options = (array) get_option('tadv_options');
  564.         $tadv_options['refresh'] = isset($tadv_options['refresh']) ? $tadv_options['refresh'] : '';
  565.         
  566.         if( $tadv_options['refresh'] == '1' ) {
  567.             $tadv_options['refresh'] = rand(1000, 9999);
  568.             update_option( 'tadv_options', $tadv_options );
  569.         } 
  570.         return $loc . '?r=' . $tadv_options['refresh'];
  571.     }
  572.     
  573.     function tadv_activate() {
  574.         global $wp_version;
  575.         
  576.         if ( empty($wp_version) || version_compare($wp_version, '2.2.1', '<') ) // if WP 2.2 or less
  577.         exit('<h2>This plugin requires WordPress version 2.2.1 or newer. Please upgrade your WordPress installation or remove the plugin.</h2>');
  578.         
  579.         $tb1 = array( 'bold', 'italic', 'strikethrough', 'underline', 'separator1', 'bullist', 'numlist', 'outdent',  'indent', 'separator2', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'separator3', 'link', 'unlink', 'separator4', 'image', 'styleprops', 'separator12', 'wp_more', 'wp_page', 'separator5', 'spellchecker', 'search', 'separator6', 'wp_help', 'fullscreen' );
  580.  
  581.         $tb2 = '';
  582.  
  583.         $tb3 = array( 'styleselect', 'formatselect', 'paste', 'pastetext', 'pasteword', 'separator7', 'cleanup', 'separator8', 'charmap', 'print', 'separator9', 'emotions', 'separator10', 'sup', 'sub', 'separator11', 'undo', 'redo', 'attribs' );
  584.     
  585.         $tadv_toolbars = array( 'toolbar-1' => $tb1, 'toolbar-2' => $tb2, 'toolbar-3' => $tb3 );
  586.         $tadv_options = array( 'advlink' => '1', 'advimage' => '1', 'importcss' => '1', 'refresh' => '1', 'fixcss' => '1' );
  587.         $tadv_plugins = array( 'table', 'media', 'fullscreen', 'style', 'emotions', 'print', 'searchreplace', 'xhtmlxtras', 'advlink', 'advimage' );
  588.         $btns1 = array( 'bold', 'italic', 'strikethrough', 'underline', 'separator', 'bullist', 'numlist', 'outdent', 'indent', 'separator', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'separator', 'link', 'unlink', 'separator', 'image', 'styleprops', 'separator', 'wp_more', 'wp_page', 'separator', 'spellchecker', 'search', 'separator', 'wp_help', 'fullscreen', 'wp_adv', 'wp_adv_start', 'styleselect', 'formatselect', 'paste', 'pastetext', 'pasteword', 'separator', 'cleanup', 'separator', 'charmap', 'print', 'separator', 'emotions', 'separator', 'sup', 'sub', 'separator', 'undo', 'redo', 'attribs', 'wp_adv_end' );
  589.  
  590.         add_option( 'tadv_toolbars', $tadv_toolbars, 'TinyMCE Advanced', 'no' );
  591.         add_option( 'tadv_options', $tadv_options, 'TinyMCE Advanced', 'no' );
  592.         add_option( 'tadv_plugins', $tadv_plugins, 'TinyMCE Advanced', 'no' );
  593.         add_option( 'tadv_btns1', $btns1, 'TinyMCE Advanced', 'no' );
  594.         add_option( 'tadv_btns2', array(), 'TinyMCE Advanced', 'no' );
  595.         add_option( 'tadv_btns4', array( 'forecolor', 'removeformat' ), 'TinyMCE Advanced', 'no' );
  596.     }
  597.     
  598.     function tadv_deactivate() {
  599.         
  600.         if ($_GET['action'] == 'deactivate-all') return;
  601.         
  602.         $rem = isset($_GET['tadv_remove']) ? $_GET['tadv_remove'] : '';
  603.         switch ($rem) {
  604.             case 'all':
  605.                 delete_option('tadv_options');
  606.                 delete_option('tadv_toolbars');
  607.                 delete_option('tadv_plugins');
  608.                 delete_option('tadv_btns1');
  609.                 delete_option('tadv_btns2');
  610.                 delete_option('tadv_btns4');
  611.                 break;
  612.             case 'none':
  613.                 break;
  614.             default: 
  615.  
  616. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  617. ?>
  618. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  619. <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
  620. <head>
  621. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
  622. <title><?php bloginfo('name') ?> › <?php echo wp_specialchars( strip_tags( $title ) ); ?> — WordPress</title>
  623. <?php wp_admin_css(); ?>
  624. </head>
  625. <body class="wp-admin <?php echo apply_filters( 'admin_body_class', '' ); ?>">
  626. <div id="wphead">
  627. <h1><?php bloginfo('name'); ?> <span id="viewsite">(<a href="<?php echo get_option('home') . '/'; ?>"><?php _e('View site »') ?></a>)</span></h1>
  628. </div>
  629.  
  630. <div class="wrap">
  631. <h2>TinyMCE Advanced deactivation options</h2>
  632. <table class="optiontable" style="width:80%;margin:auto;">
  633.     <tr>
  634.     <td style="padding:30px;width:50%;vertical-align:top;">
  635.     <p class="button" style="background-color:#eee;border:1px solid #ddd;"><a href="plugins.php?action=deactivate&plugin=tinymce-advanced/tinymce-advanced.php&tadv_remove=all&_wpnonce=<?php echo $_GET['_wpnonce']; ?>" class="delete" title="Uninstall TinyMCE Advanced"><strong>Uninstall</strong></a></p>
  636.     <p>Uninstalling will remove all saved settings and buttons arrangement from the database. Choose it if you are not planning to use TinyMCE Advanced any more.</p>
  637.     
  638.     </td><td style="padding:30px;width:50%;vertical-align:top;">
  639.     
  640.     <p class="button" style="background-color:#eee;border:1px solid #ddd;"><a href="plugins.php?action=deactivate&plugin=tinymce-advanced/tinymce-advanced.php&tadv_remove=none&_wpnonce=<?php echo $_GET['_wpnonce']; ?>" class="edit" title="Deactivate TinyMCE Advanced"><strong>Deactivate</strong></a></p>
  641.     <p>Deactivating will not remove the settings and the buttons arrangement from the database. Choose it if you are planning to use TinyMCE Advanced again and do not want to loose your settings.</p>
  642.     
  643.     </td></tr>
  644.     <tr><td colspan="2" style="padding:0 25%;">
  645.     <p class="button" style="background-color:#eee;border:1px solid #ddd;"><a href="plugins.php" class="edit" title="Cancel"><strong>Cancel</strong></a></p>
  646.     </td></tr>
  647.     </table>
  648. </div>
  649. <?php
  650.             include(ABSPATH . 'wp-admin/admin-footer.php');
  651.             exit;
  652.         }
  653.     }
  654.     
  655. } } //end tadv_mceClass
  656.  
  657. function tadv_menu() {
  658.     if( function_exists('add_management_page') ) 
  659.        $page = add_management_page( 'TinyMCE Advanced', 'TinyMCE Advanced', 9, __FILE__, 'tadv_page' );
  660.        add_action("admin_print_scripts-$page", 'tadv_admin_head');
  661. }
  662.  
  663. if ( class_exists("tadv_mceClass") ) {
  664.     $tadv_mce = new tadv_mceClass();
  665.  
  666.     add_action( 'tinymce_before_init', array(&$tadv_mce, 'tadv_load_plugins') );
  667.     add_filter( 'mce_css', array(&$tadv_mce, 'tdav_css') );
  668.     add_filter( 'tiny_mce_config_url', array(&$tadv_mce, 'tadv_refresh_mceconfig') );
  669.     add_action( 'mce_options', array(&$tadv_mce, 'tadv_mce_opt') );
  670.     add_filter( 'mce_plugins', array(&$tadv_mce, 'tadv_mce_plugins'), 99 );
  671.     add_filter( 'mce_buttons_3', array(&$tadv_mce, 'tadv_mce_btns3'), 98 );
  672.     add_filter( 'mce_buttons', array(&$tadv_mce, 'tadv_mce_btns'), 99 );
  673.     add_filter( 'mce_buttons_2', array(&$tadv_mce, 'tadv_mce_btns2'), 99 );
  674.     add_action( 'activate_tinymce-advanced/tinymce-advanced.php', array(&$tadv_mce, 'tadv_activate') );
  675. }
  676. add_action( 'admin_menu', 'tadv_menu' );
  677. ?>