home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-includes / js / tinymce / tiny_mce_config.php < prev    next >
Encoding:
PHP Script  |  2008-08-10  |  11.4 KB  |  331 lines

  1. <?php 
  2. // some code below is from:
  3. /**
  4.  * $Id: tiny_mce_gzip.php 315 2007-10-25 14:03:43Z spocke $
  5.  *
  6.  * @author Moxiecode
  7.  * @copyright Copyright ┬⌐ 2005-2006, Moxiecode Systems AB, All rights reserved.
  8.  *
  9.  * This file compresses the TinyMCE JavaScript using GZip.
  10.  **/
  11.  
  12. // Discard any buffers
  13. while ( @ob_end_clean() );
  14.  
  15. @ require('../../../wp-load.php');
  16.  
  17. function getFileContents($path) {
  18.  
  19.     if ( function_exists('realpath') )
  20.         $path = realpath($path);
  21.  
  22.     if ( ! $path || ! @is_file($path) )
  23.         return '';
  24.  
  25.     if ( function_exists('file_get_contents') )
  26.         return @file_get_contents($path);
  27.  
  28.     $content = '';
  29.     $fp = @fopen($path, 'r');
  30.     if ( ! $fp )
  31.         return '';
  32.  
  33.     while ( ! feof($fp) )
  34.         $content .= fgets($fp);
  35.  
  36.     fclose($fp);
  37.     return $content;
  38. }
  39.  
  40. function putFileContents( $path, $content ) {
  41.     if ( function_exists('file_put_contents') )
  42.         return @file_put_contents( $path, $content );
  43.  
  44.     $newfile = false;
  45.     $fp = @fopen( $path, 'wb' );
  46.     if ($fp) {
  47.         $newfile = fwrite( $fp, $content );
  48.         fclose($fp);
  49.     }
  50.     return $newfile;
  51. }
  52.  
  53. // Set up init variables
  54. $baseurl = includes_url('js/tinymce');
  55.  
  56. $mce_css = $baseurl . '/wordpress.css';
  57. $mce_css = apply_filters('mce_css', $mce_css);
  58.  
  59. $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
  60.  
  61. /*
  62. The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
  63. By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
  64. The + sign marks the default language. More information:
  65. http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  66. */
  67. $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');
  68.  
  69. $plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage' );
  70.  
  71. /* 
  72. The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
  73. It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin. 
  74. The url should be absolute and should include the js file name to be loaded. Example: 
  75. array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
  76. If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
  77. */
  78. $mce_external_plugins = apply_filters('mce_external_plugins', array());
  79.  
  80. $ext_plugins = "\n";
  81. if ( ! empty($mce_external_plugins) ) {
  82.     
  83.     /*
  84.     The following filter loads external language files for TinyMCE plugins.
  85.     It takes an associative array 'plugin_name' => 'path', where path is the 
  86.     include path to the file. The language file should follow the same format as 
  87.     /tinymce/langs/wp-langs.php and should define a variable $strings that 
  88.     holds all translated strings. Example: 
  89.     $strings = 'tinyMCE.addI18n("' . $mce_locale . '.mypluginname_dlg",{tab_general:"General", ... })';
  90.     */
  91.     $mce_external_languages = apply_filters('mce_external_languages', array()); 
  92.     
  93.     $loaded_langs = array();
  94.     $strings = '';
  95.     
  96.     if ( ! empty($mce_external_languages) ) {
  97.         foreach ( $mce_external_languages as $name => $path ) {
  98.             if ( is_file($path) && is_readable($path) ) { 
  99.                 include_once($path);
  100.                 $ext_plugins .= $strings;
  101.                 $loaded_langs[] = $name;
  102.             }
  103.         }
  104.     }
  105.  
  106.     foreach ( $mce_external_plugins as $name => $url ) {
  107.         
  108.         if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
  109.         
  110.         $plugins[] = '-' . $name;
  111.  
  112.         if ( in_array($name, $loaded_langs) ) {
  113.             $plugurl = dirname($url);
  114.             $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
  115.         }
  116.         $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
  117.     }
  118. }
  119. $plugins = implode($plugins, ',');
  120.  
  121. $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));
  122. $mce_buttons = implode($mce_buttons, ',');
  123.  
  124. $mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ));
  125. $mce_buttons_2 = implode($mce_buttons_2, ',');
  126.  
  127. $mce_buttons_3 = apply_filters('mce_buttons_3', array());
  128. $mce_buttons_3 = implode($mce_buttons_3, ',');
  129.     
  130. $mce_buttons_4 = apply_filters('mce_buttons_4', array());
  131. $mce_buttons_4 = implode($mce_buttons_4, ',');
  132.  
  133. $no_captions = ( apply_filters( 'disable_captions', '' ) ) ? true : false;
  134.  
  135. // TinyMCE init settings
  136. $initArray = array (
  137.     'mode' => 'none',
  138.     'onpageload' => 'wpEditorInit',
  139.     'width' => '100%',
  140.     'theme' => 'advanced',
  141.     'skin' => 'wp_theme',
  142.     'theme_advanced_buttons1' => "$mce_buttons",
  143.     'theme_advanced_buttons2' => "$mce_buttons_2",
  144.     'theme_advanced_buttons3' => "$mce_buttons_3",
  145.     'theme_advanced_buttons4' => "$mce_buttons_4",
  146.     'language' => "$mce_locale",
  147.     'spellchecker_languages' => "$mce_spellchecker_languages",
  148.     'theme_advanced_toolbar_location' => 'top',
  149.     'theme_advanced_toolbar_align' => 'left',
  150.     'theme_advanced_statusbar_location' => 'bottom',
  151.     'theme_advanced_resizing' => true,
  152.     'theme_advanced_resize_horizontal' => false,
  153.     'dialog_type' => 'modal',
  154.     'relative_urls' => false,
  155.     'remove_script_host' => false,
  156.     'convert_urls' => false,
  157.     'apply_source_formatting' => false,
  158.     'remove_linebreaks' => true,
  159.     'paste_convert_middot_lists' => true,
  160.     'paste_remove_spans' => true,
  161.     'paste_remove_styles' => true,
  162.     'gecko_spellcheck' => true,
  163.     'entities' => '38,amp,60,lt,62,gt',
  164.     'accessibility_focus' => false,
  165.     'tab_focus' => ':next',
  166.     'content_css' => "$mce_css",
  167.     'save_callback' => 'switchEditors.saveCallback',
  168.     'wpeditimage_disable_captions' => $no_captions,
  169.     'plugins' => "$plugins",
  170.     // pass-through the settings for compression and caching, so they can be changed with "tiny_mce_before_init"
  171.     'disk_cache' => true,
  172.     'compress' => true,
  173.     'old_cache_max' => '1' // number of cache files to keep
  174. );
  175.  
  176. // For people who really REALLY know what they're doing with TinyMCE
  177. // You can modify initArray to add, remove, change elements of the config before tinyMCE.init (changed from action to filter)
  178. $initArray = apply_filters('tiny_mce_before_init', $initArray);
  179.  
  180. // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
  181. // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
  182.  
  183. // support for deprecated actions
  184. ob_start();
  185. do_action('mce_options');
  186. $mce_deprecated = ob_get_contents();
  187. ob_end_clean();
  188.  
  189. $mce_deprecated = (string) $mce_deprecated;
  190. if ( strlen( $mce_deprecated ) < 10 || ! strpos( $mce_deprecated, ':' ) || ! strpos( $mce_deprecated, ',' ) )    
  191.     $mce_deprecated = '';
  192.  
  193. // Settings for the gzip compression and cache
  194. $disk_cache = ( ! isset($initArray['disk_cache']) || false == $initArray['disk_cache'] ) ? false : true;
  195. $compress = ( ! isset($initArray['compress']) || false == $initArray['compress'] ) ? false : true;
  196. $old_cache_max = ( isset($initArray['old_cache_max']) ) ? (int) $initArray['old_cache_max'] : 0;
  197.  
  198. $initArray['disk_cache'] = $initArray['compress'] = $initArray['old_cache_max'] = null;
  199. unset( $initArray['disk_cache'], $initArray['compress'], $initArray['old_cache_max'] );
  200.  
  201. // Anybody still using IE5/5.5? It can't handle gzip compressed js well.
  202. if ( $msie = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) {
  203.     $ie_ver = (int) substr( $_SERVER['HTTP_USER_AGENT'] , $msie + 5, 3 );
  204.     if ( $ie_ver && $ie_ver < 6 ) $compress = false;
  205. }
  206.  
  207. // Cache path, this is where the .gz files will be stored
  208. $cache_path = WP_CONTENT_DIR . '/uploads/js_cache'; 
  209. if ( $disk_cache && ! is_dir($cache_path) )
  210.     $disk_cache = wp_mkdir_p($cache_path);
  211.  
  212. $cache_ext = '.js';
  213. $plugins = explode( ',', $initArray['plugins'] );
  214. $theme = ( 'simple' == $initArray['theme'] ) ? 'simple' : 'advanced';
  215. $language = ( isset($initArray['language']) && ! empty($initArray['language']) ) ? substr( $initArray['language'], 0, 2 ) : 'en';
  216. $cacheKey = $mce_options = '';    
  217.  
  218. // Check if browser supports gzip
  219. if ( $compress && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
  220.     if ( ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') || isset($_SERVER['---------------']) ) && function_exists('gzencode') && ! ini_get('zlib.output_compression') ) {
  221.         $cache_ext = '.gz';
  222.     }
  223. }
  224.  
  225. // Setup cache info
  226. if ( $disk_cache ) {
  227.  
  228.     $cacheKey = apply_filters('tiny_mce_version', '20080810');
  229.  
  230.     foreach ( $initArray as $v )
  231.         $cacheKey .= $v;
  232.  
  233.     if ( ! empty($mce_external_plugins) ) {
  234.         foreach ( $mce_external_plugins as $n => $v )
  235.             $cacheKey .= $n;
  236.     }
  237.     
  238.     $cacheKey = md5( $cacheKey );
  239.     $cache_file = $cache_path . '/tinymce_' . $cacheKey . $cache_ext;
  240. }
  241.  
  242. $expiresOffset = 864000; // 10 days
  243. header( 'Content-Type: application/x-javascript; charset=UTF-8' );
  244. header( 'Vary: Accept-Encoding' ); // Handle proxies
  245. header( 'Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . ' GMT' );
  246.  
  247. // Use cached file if exists
  248. if ( $disk_cache && is_file($cache_file) && is_readable($cache_file) ) {
  249.  
  250.     $mtime = gmdate("D, d M Y H:i:s", filemtime($cache_file)) . " GMT";
  251.     
  252.     if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $mtime ) {
  253.         header('HTTP/1.1 304 Not Modified');
  254.         exit;
  255.     }
  256.     header("Last-Modified: " . $mtime);
  257.     header("Cache-Control: must-revalidate", false);
  258.  
  259.     $content = getFileContents( $cache_file );
  260.     
  261.     if ( '.gz' == $cache_ext )
  262.         header( 'Content-Encoding: gzip' );
  263.  
  264.     echo $content;
  265.     exit;
  266. }
  267.  
  268. foreach ( $initArray as $k => $v ) 
  269.     $mce_options .= $k . ':"' . $v . '",';
  270.  
  271. if ( $mce_deprecated ) $mce_options .= $mce_deprecated;
  272.  
  273. $mce_options = rtrim( trim($mce_options), '\n\r,' );
  274.  
  275. $content = 'var tinyMCEPreInit = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false }, base : "' . $baseurl . '", suffix : "", query : "ver=311" };';
  276.  
  277. // Load patch
  278. $content .= getFileContents( 'tiny_mce_ext.js' );
  279.  
  280. // Add core
  281. $content .= getFileContents( 'tiny_mce.js' );
  282.  
  283. // Patch loading functions
  284. $content .= 'tinyMCEPreInit.start();';
  285.  
  286. // Add all languages (WP)
  287. include_once( dirname(__FILE__).'/langs/wp-langs.php' );
  288. $content .= $strings;
  289.  
  290. // Add themes
  291. $content .= getFileContents( 'themes/' . $theme . '/editor_template.js' );
  292.  
  293. // Add plugins
  294. foreach ( $plugins as $plugin ) 
  295.     $content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin.js' );
  296.  
  297. // Add external plugins and init 
  298. $content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});';
  299.  
  300. // Generate GZIP'd content
  301. if ( '.gz' == $cache_ext ) {
  302.     header('Content-Encoding: gzip');
  303.     $content = gzencode( $content, 9, FORCE_GZIP );
  304. }
  305.  
  306. // Stream to client
  307. echo $content;
  308.  
  309. // Write file
  310. if ( '' != $cacheKey && is_dir($cache_path) && is_readable($cache_path) ) {    
  311.  
  312.     $old_cache = array();
  313.     $handle = opendir($cache_path);
  314.     while ( false !== ( $file = readdir($handle) ) ) {
  315.         if ( $file == '.' || $file == '..' ) continue;
  316.         $saved = filectime("$cache_path/$file");
  317.         if ( strpos($file, 'tinymce_') !== false && substr($file, -3) == $cache_ext ) $old_cache["$saved"] = $file;
  318.     }
  319.     closedir($handle);
  320.             
  321.     krsort($old_cache);
  322.     if ( 1 >= $old_cache_max ) $del_cache = $old_cache;
  323.     else $del_cache = array_slice( $old_cache, ($old_cache_max - 1) );
  324.  
  325.     foreach ( $del_cache as $key )
  326.         @unlink("$cache_path/$key");
  327.  
  328.     putFileContents( $cache_file, $content );
  329. }
  330.  
  331. ?>