Changeset 138258
- Timestamp:
- 07/23/2009 09:00:29 AM (17 years ago)
- File:
-
- 1 edited
-
external-css/trunk/external-css.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
external-css/trunk/external-css.php
r138256 r138258 31 31 */ 32 32 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"; 33 define( 'EXTERNAL_CSS_CSSDIR', '/uploads' ); 34 define( 'EXTERNAL_CSS_CUSTOM_CSS', EXTERNAL_CSS_CSSDIR . '/custom.css' ); 35 36 function 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 49 function external_css_get_cssbaseurl() { 50 $upload = wp_upload_dir(); 51 if ( $upload['error'] ) 52 return false; 53 return "{$upload['baseurl']}/external-css"; 38 54 } 39 55 … … 42 58 */ 43 59 function 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" ); 45 64 echo "<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" media=\"screen,projection\" />"; 46 65 } … … 58 77 * Save the css file. 59 78 */ 60 function external_css_save( $css ) { 61 $path = external_css_path( ABSPATH ); 79 function external_css_save( $path, $css ) { 62 80 $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 70 81 $tmpfile = tempnam( $dir, 'tmp' ); 71 82 if ( !$tmpfile ) { … … 77 88 if ( !$fh ) { 78 89 external_css_error( __( 'Failed to open temporary file', 'external-css' ) ); 90 unlink( $tmpfile ); 79 91 return false; 80 92 } … … 100 112 */ 101 113 function 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"; 103 121 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'] ) ) ) { 105 123 echo '<div class="updated"><p><strong>'; 106 124 _e( 'Options saved.', 'external-css' ); 107 125 echo '</strong></p></div>'; 108 126 } 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 }120 127 } 121 128 … … 126 133 127 134 <textarea cols="70" rows="25" name="external_css" style="overflow-y:scroll"><?php 128 readfile( $path );135 @readfile( $path ); 129 136 ?></textarea> 130 137 … … 156 163 add_action( 'init', 'external_css_init' ); 157 164 165 /* 166 * Fix path of CSS file. 167 */ 168 function 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 212 register_activation_hook( __FILE__, 'external_css_activation' ); 213 158 214 ?>
Note: See TracChangeset
for help on using the changeset viewer.