WordPress.org

Make WordPress Core

Changeset 7402


Ignore:
Timestamp:
03/19/2008 06:53:01 PM (10 years ago)
Author:
ryan
Message:

TinyMCE cache fixes from markjaquith and azaozz. fixes #6295

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/tiny_mce_config.php

    r7378 r7402  
    3737        return @file_put_contents( $path, $content );
    3838
     39    $newfile = false;
    3940    $fp = @fopen( $path, 'wb' );
    4041    if ($fp) {
    41         fwrite( $fp, $content );
     42        $newfile = fwrite( $fp, $content );
    4243        fclose($fp);
    4344    }
     45    return $newfile;
    4446}
    4547
     
    5961Setting mce_valid_elements to *[*] skips all of the internal cleanup and can cause problems.
    6062The minimal setting would be -strong/-b[*],-em/-i[*],*[*].
    61 Best is to use the default cleanup by not specifying mce_valid_elements,
    62 and then use extended_valid_elements to add to it.
     63Best is to use the default cleanup by not specifying mce_valid_elements. It contains full set of XHTML 1.0.
     64If others are needed, mce_extended_valid_elements can be used to add to it, or mce_invalid_elements to remove.
    6365*/
    6466$valid_elements = apply_filters('mce_valid_elements', '');
    6567$invalid_elements = apply_filters('mce_invalid_elements', '');
    66 
    67 $extended_valid_elements = '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],bdo,code,col[*],colgroup[*],dfn,fieldset,form[*],input[*],kbd,label[*],legend[*],noscript,optgroup[*],option[*],q[cite|class],samp,textarea[*],title,var';
    68 
    69 $extended_valid_elements = apply_filters('mce_extended_valid_elements', $extended_valid_elements);
     68$extended_valid_elements = apply_filters('mce_extended_valid_elements', '');
    7069
    7170/*
     
    106105    if ( ! empty($mce_external_languages) ) {
    107106        foreach ( $mce_external_languages as $name => $path ) {
    108             $loaded_langs[] = $name;
    109        
    110             if ( is_file($path) ) include_once($path);
    111             $ext_plugins .= $strings;
     107            if ( is_readable($path) ) {
     108                include_once($path);
     109                $ext_plugins .= $strings;
     110                $loaded_langs[] = $name;
     111            }
    112112        }
    113113    }
     
    175175
    176176if ( $valid_elements ) $initArray['valid_elements'] = $valid_elements;
    177 //if ( $extended_valid_elements ) $initArray['extended_valid_elements'] = $extended_valid_elements;
     177if ( $extended_valid_elements ) $initArray['extended_valid_elements'] = $extended_valid_elements;
    178178if ( $invalid_elements ) $initArray['invalid_elements'] = $invalid_elements;
    179179
     
    243243
    244244// Use cached file if exists
    245 if ( $disk_cache && is_file($cache_file) ) {
     245if ( $disk_cache && is_file($cache_file) && is_readable($cache_file) ) {
    246246
    247247    $mtime = gmdate("D, d M Y H:i:s", filemtime($cache_file)) . " GMT";
     
    303303
    304304// Write file
    305 if ( '' != $cacheKey ) {
    306     if ( is_dir($cache_path) ) {       
    307 
    308         $old_cache = array();
    309         $handle = opendir($cache_path);
    310         while ( false !== ( $file = readdir($handle) ) ) {
    311             if ( $file == '.' || $file == '..' ) continue;
    312             $saved = filectime("$cache_path/$file");
    313             if ( strpos($file, 'tinymce_') !== false && substr($file, -3) == $cache_ext ) $old_cache["$saved"] = $file;
    314         }
    315         closedir($handle);
     305if ( '' != $cacheKey && is_dir($cache_path) && is_readable($cache_path) ) {
     306
     307    $old_cache = array();
     308    $handle = opendir($cache_path);
     309    while ( false !== ( $file = readdir($handle) ) ) {
     310        if ( $file == '.' || $file == '..' ) continue;
     311        $saved = filectime("$cache_path/$file");
     312        if ( strpos($file, 'tinymce_') !== false && substr($file, -3) == $cache_ext ) $old_cache["$saved"] = $file;
     313    }
     314    closedir($handle);
    316315           
    317         krsort($old_cache);
    318         if ( 1 >= $old_cache_max ) $del_cache = $old_cache;
    319         else $del_cache = array_slice( $old_cache, ($old_cache_max - 1) );
    320            
    321         foreach ( $del_cache as $key )
    322             @unlink("$cache_path/$key");
    323     }
    324 
    325     putFileContents( $cache_file, $content );
    326 
    327     $mtime = gmdate( "D, d M Y H:i:s", filemtime($cache_file) ) . " GMT";
    328     header( 'Last-Modified: ' . $mtime );
     316    krsort($old_cache);
     317    if ( 1 >= $old_cache_max ) $del_cache = $old_cache;
     318    else $del_cache = array_slice( $old_cache, ($old_cache_max - 1) );
     319
     320    foreach ( $del_cache as $key )
     321        @unlink("$cache_path/$key");
     322
     323    if ( putFileContents( $cache_file, $content ) && is_readable($cache_file) ) {
     324        $mtime = gmdate( "D, d M Y H:i:s", filemtime($cache_file) ) . " GMT";
     325        header( 'Last-Modified: ' . $mtime );
     326        header( 'Cache-Control: must-revalidate', false );
     327    }
    329328}
    330329
    331330// Stream to client
    332 header( 'Cache-Control: must-revalidate', false );
    333331header( 'Content-Length: ' . strlen($content) );
    334332echo $content;
Note: See TracChangeset for help on using the changeset viewer.