Plugin Directory

Changeset 138258


Ignore:
Timestamp:
07/23/2009 09:00:29 AM (17 years ago)
Author:
sakuratan
Message:

It renamed wp-content/cache/external-css/custom.css
wp-content/uploads/external-css/custom.css.
external_css_activation function fix this change automatically.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external-css/trunk/external-css.php

    r138256 r138258  
    3131*/
    3232
    33 /*
    34  * Returns path of the css file.
    35  */
    36 function external_css_path( $base ) {
    37     return "{$base}/wp-content/cache/external-css/custom.css";
     33define( 'EXTERNAL_CSS_CSSDIR', '/uploads' );
     34define( 'EXTERNAL_CSS_CUSTOM_CSS', EXTERNAL_CSS_CSSDIR . '/custom.css' );
     35
     36function external_css_get_cssdir() {
     37    $upload = wp_upload_dir();
     38    if ( $upload['error'] )
     39    return false;
     40    $dir = "{$upload['basedir']}/external-css";
     41    if ( is_dir( $dir ) ) {
     42    return $dir;
     43    }
     44    if ( !wp_mkdir_p( $dir ) )
     45    return false;
     46    return $dir;
     47}
     48
     49function external_css_get_cssbaseurl() {
     50    $upload = wp_upload_dir();
     51    if ( $upload['error'] )
     52    return false;
     53    return "{$upload['baseurl']}/external-css";
    3854}
    3955
     
    4258 */
    4359function external_css_embed_link_tag() {
    44     $url = htmlspecialchars( external_css_path( get_option( 'siteurl' ) ) );
     60    $base = external_css_get_cssbaseurl();
     61    if ( !$base )
     62    return;
     63    $url = htmlspecialchars( "{$base}/custom.css" );
    4564    echo "<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" media=\"screen,projection\" />";
    4665}
     
    5877 * Save the css file.
    5978 */
    60 function external_css_save( $css ) {
    61     $path = external_css_path( ABSPATH );
     79function external_css_save( $path, $css ) {
    6280    $dir = dirname( $path );
    63     if ( !is_dir( $dir ) ) {
    64     if ( !mkdir( $dir, 0755, true ) ) {
    65         external_css_error( __( 'Failed to create directory', 'external-css' ) );
    66         return;
    67     }
    68     }
    69 
    7081    $tmpfile = tempnam( $dir, 'tmp' );
    7182    if ( !$tmpfile ) {
     
    7788    if ( !$fh ) {
    7889    external_css_error( __( 'Failed to open temporary file', 'external-css' ) );
     90    unlink( $tmpfile );
    7991    return false;
    8092    }
     
    100112 */
    101113function external_css_theme_page() {
    102     $path = external_css_path( ABSPATH );
     114    $dir = external_css_get_cssdir();
     115    if ( !$dir ) {
     116    external_css_error( sprintf( __( 'External CSS cannot continue the process because missing permissions for %s. Add the read and write permissions of the directory to the user of the web server to fix the problem.', 'external-css' ), $dir ) );
     117    return;
     118    }
     119
     120    $path = "{$dir}/custom.css";
    103121    if ( array_key_exists( 'external_css', $_POST ) ) {
    104     if ( external_css_save( stripslashes( $_POST['external_css'] ) ) ) {
     122    if ( external_css_save( $path, stripslashes( $_POST['external_css'] ) ) ) {
    105123        echo '<div class="updated"><p><strong>';
    106124        _e( 'Options saved.', 'external-css'  );
    107125        echo '</strong></p></div>';
    108126    }
    109     } else {
    110     $dir = dirname( $path );
    111     if ( !is_dir( $dir ) || !is_writable( $dir ) ) {
    112         if ( !mkdir( $dir, 0755, true ) ) {
    113         external_css_error( sprintf( __( 'External CSS cannot continue the process because missing permissions for %s. Add the read and write permissions of the directory to the user of the web server to fix the problem.', 'external-css' ), $dir ) );
    114         return;
    115         }
    116     }
    117     if ( !file_exists( $path ) ) {
    118         external_css_save( '/* Edit this css file */' );
    119     }
    120127    }
    121128
     
    126133
    127134<textarea cols="70" rows="25" name="external_css" style="overflow-y:scroll"><?php
    128     readfile( $path );
     135    @readfile( $path );
    129136?></textarea>
    130137
     
    156163add_action( 'init', 'external_css_init' );
    157164
     165/*
     166 * Fix path of CSS file.
     167 */
     168function external_css_activation() {
     169    $cssdir = external_css_get_cssdir();
     170    if ( !$cssdir )
     171    return;
     172    $path = "{$cssdir}/custom.css";
     173
     174    $files = array(
     175    // 0.2.0 or older
     176    WP_PLUGIN_DIR . '/external-css/css/custom.css' => array(
     177        WP_PLUGIN_DIR . '/external-css/css'
     178    ),
     179    // 0.2.1
     180    WP_CONTENT_DIR . '/cache/external-css/custom.css' => array(
     181        WP_CONTENT_DIR . '/cache/external-css',
     182        WP_CONTENT_DIR . '/cache'
     183    )
     184    );
     185
     186    $havenewfile = @file_exists( $path );
     187
     188    foreach ( $files as $oldpath => $cleandirs ) {
     189    if ( !file_exists( $oldpath ) )
     190        continue;
     191    if ( !$havenewfile ) {
     192        if ( !copy( $oldpath, $path ) )
     193        continue;
     194    }
     195    if ( unlink( $oldpath ) ) {
     196        foreach ( $cleandirs as $dir ) {
     197        if ( !@rmdir( $dir ) )
     198            break;
     199        }
     200    }
     201    }
     202
     203    if ( !@file_exists( $path ) ) {
     204    $fh = fopen( $path, 'wb' );
     205    if ( $fh ) {
     206        fwrite( $fh, "/* Edit this */\n" );
     207        fclose( $fh );
     208    }
     209    }
     210}
     211
     212register_activation_hook( __FILE__, 'external_css_activation' );
     213
    158214?>
Note: See TracChangeset for help on using the changeset viewer.