Changeset 138256
- Timestamp:
- 07/23/2009 08:58:15 AM (17 years ago)
- File:
-
- 1 edited
-
external-css/trunk/external-css.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
external-css/trunk/external-css.php
r136987 r138256 34 34 * Returns path of the css file. 35 35 */ 36 function external_css_path( $base) {36 function external_css_path( $base ) { 37 37 return "{$base}/wp-content/cache/external-css/custom.css"; 38 38 } … … 42 42 */ 43 43 function external_css_embed_link_tag() { 44 $url = htmlspecialchars( external_css_path(get_option('siteurl')));44 $url = htmlspecialchars( external_css_path( get_option( 'siteurl' ) ) ); 45 45 echo "<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" media=\"screen,projection\" />"; 46 46 } … … 49 49 * Display errors. 50 50 */ 51 function external_css_error( $s) {51 function external_css_error( $s ) { 52 52 echo '<p class="error">'; 53 echo htmlspecialchars( $s);53 echo htmlspecialchars( $s ); 54 54 echo '</p>'; 55 55 } … … 58 58 * Save the css file. 59 59 */ 60 function external_css_save( $css) {61 $path = external_css_path( ABSPATH);62 $dir = dirname( $path);63 if ( !is_dir($dir)) {64 if ( !mkdir($dir, 0755, true)) {65 external_css_error( __('Failed to create directory', 'external-css'));60 function external_css_save( $css ) { 61 $path = external_css_path( ABSPATH ); 62 $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 66 return; 67 67 } 68 68 } 69 69 70 $tmpfile = tempnam( $dir, 'tmp');71 if ( !$tmpfile) {72 external_css_error( __('Failed to create temporary file', 'external-css'));70 $tmpfile = tempnam( $dir, 'tmp' ); 71 if ( !$tmpfile ) { 72 external_css_error( __( 'Failed to create temporary file', 'external-css' ) ); 73 73 return false; 74 74 } 75 75 76 $fh = fopen( $tmpfile, 'wb');77 if ( !$fh) {78 external_css_error( __('Failed to open temporary file', 'external-css'));76 $fh = fopen( $tmpfile, 'wb' ); 77 if ( !$fh ) { 78 external_css_error( __( 'Failed to open temporary file', 'external-css' ) ); 79 79 return false; 80 80 } 81 fwrite( $fh, $css);82 fclose( $fh);81 fwrite( $fh, $css ); 82 fclose( $fh ); 83 83 84 if ( !chmod($tmpfile, 0644)) {85 external_css_error( __('Failed to chmod temporary file', 'external-css'));84 if ( !chmod( $tmpfile, 0644 ) ) { 85 external_css_error( __( 'Failed to chmod temporary file', 'external-css' ) ); 86 86 return false; 87 87 } 88 88 89 89 /* Update css with POSIX atomic function */ 90 if ( !rename($tmpfile, $path)) {91 external_css_error( __('Failed to rename CSS', 'external-css'));90 if ( !rename( $tmpfile, $path ) ) { 91 external_css_error( __( 'Failed to rename CSS', 'external-css' ) ); 92 92 return false; 93 93 } … … 100 100 */ 101 101 function external_css_theme_page() { 102 $path = external_css_path( ABSPATH);103 if ( array_key_exists('external_css', $_POST)) {104 if ( external_css_save(stripslashes($_POST['external_css']))) {102 $path = external_css_path( ABSPATH ); 103 if ( array_key_exists( 'external_css', $_POST ) ) { 104 if ( external_css_save( stripslashes( $_POST['external_css'] ) ) ) { 105 105 echo '<div class="updated"><p><strong>'; 106 _e( 'Options saved.', 'external-css');106 _e( 'Options saved.', 'external-css' ); 107 107 echo '</strong></p></div>'; 108 108 } 109 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));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 114 return; 115 115 } 116 116 } 117 if ( !file_exists($path)) {118 external_css_save( '/* Edit this css file */');117 if ( !file_exists( $path ) ) { 118 external_css_save( '/* Edit this css file */' ); 119 119 } 120 120 } … … 123 123 <h2>External CSS Options</h2> 124 124 125 <form method="post" action="<?php echo htmlspecialchars( $_SERVER['REQUEST_URI']) ?>">125 <form method="post" action="<?php echo htmlspecialchars( $_SERVER['REQUEST_URI'] ) ?>"> 126 126 127 127 <textarea cols="70" rows="25" name="external_css" style="overflow-y:scroll"><?php 128 readfile( $path);128 readfile( $path ); 129 129 ?></textarea> 130 130 131 <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'external-css') ?>" /></p>131 <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'external-css' ) ?>" /></p> 132 132 133 133 </form> … … 139 139 */ 140 140 function external_css_admin_menu() { 141 add_theme_page( 'External CSS Options', 'External CSS', 'switch_themes',142 __FILE__, 'external_css_theme_page' );141 add_theme_page( 'External CSS Options', 'External CSS', 'switch_themes', 142 __FILE__, 'external_css_theme_page' ); 143 143 } 144 144 … … 147 147 */ 148 148 function external_css_init() { 149 load_plugin_textdomain( 'external-css',150 'wp-content/plugins/external-css/po',151 'external-css/po');152 add_action( 'admin_menu', 'external_css_admin_menu');153 add_action( 'wp_head', 'external_css_embed_link_tag', 100);149 load_plugin_textdomain( 'external-css', 150 'wp-content/plugins/external-css/po', 151 'external-css/po' ); 152 add_action( 'admin_menu', 'external_css_admin_menu' ); 153 add_action( 'wp_head', 'external_css_embed_link_tag', 100 ); 154 154 } 155 155 156 add_action( 'init', 'external_css_init');156 add_action( 'init', 'external_css_init' ); 157 157 158 158 ?>
Note: See TracChangeset
for help on using the changeset viewer.