home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / theme-editor.php < prev    next >
Encoding:
PHP Script  |  2008-06-28  |  5.7 KB  |  184 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __("Edit Themes");
  5. $parent_file = 'themes.php';
  6.  
  7. wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
  8.  
  9. wp_admin_css( 'theme-editor' );
  10.  
  11. $themes = get_themes();
  12.  
  13. if (empty($theme)) {
  14.     $theme = get_current_theme();
  15. } else {
  16.     $theme = stripslashes($theme);
  17.  }
  18.  
  19.  
  20. if ( ! isset($themes[$theme]) )
  21.     wp_die(__('The requested theme does not exist.'));
  22.  
  23. $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
  24.  
  25. if (empty($file)) {
  26.     $file = $allowed_files[0];
  27. }
  28.  
  29. $file = validate_file_to_edit($file, $allowed_files);
  30. $real_file = get_real_file_to_edit($file);
  31.  
  32. $file_show = basename( $file );
  33.  
  34. switch($action) {
  35.  
  36. case 'update':
  37.  
  38.     check_admin_referer('edit-theme_' . $file . $theme);
  39.  
  40.     if ( !current_user_can('edit_themes') )
  41.         wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
  42.  
  43.     $newcontent = stripslashes($_POST['newcontent']);
  44.     $theme = urlencode($theme);
  45.     if (is_writeable($real_file)) {
  46.         //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
  47.         $f = fopen($real_file, 'w+');
  48.         if ($f !== FALSE) {
  49.             fwrite($f, $newcontent);
  50.             fclose($f);
  51.             $location = "theme-editor.php?file=$file&theme=$theme&a=te";
  52.         } else {
  53.             $location = "theme-editor.php?file=$file&theme=$theme";
  54.         }
  55.     } else {
  56.         $location = "theme-editor.php?file=$file&theme=$theme";
  57.     }
  58.  
  59.     $location = wp_kses_no_null($location);
  60.     $strip = array('%0d', '%0a');
  61.     $location = str_replace($strip, '', $location);
  62.     header("Location: $location");
  63.     exit();
  64.  
  65. break;
  66.  
  67. default:
  68.  
  69.     if ( !current_user_can('edit_themes') )
  70.         wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
  71.  
  72.     require_once('admin-header.php');
  73.  
  74.     update_recently_edited($file);
  75.  
  76.     if (!is_file($real_file))
  77.         $error = 1;
  78.  
  79.     if (!$error && filesize($real_file) > 0) {
  80.         $f = fopen($real_file, 'r');
  81.         $content = fread($f, filesize($real_file));
  82.         $content = htmlspecialchars($content);
  83.     }
  84.  
  85.     ?>
  86. <?php if (isset($_GET['a'])) : ?>
  87.  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
  88. <?php endif;
  89.  
  90. $description = get_file_description($file);
  91. $desc_header = ( $description != $file_show ) ? "$description</strong> (%s)" : "%s";
  92. ?>
  93. <div class="wrap">
  94. <div class="bordertitle">
  95.     <h2><?php _e('Theme Editor'); ?></h2>
  96.     <form id="themeselector" name="theme" action="theme-editor.php" method="post">
  97.         <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
  98.         <select name="theme" id="theme">
  99. <?php
  100.     foreach ($themes as $a_theme) {
  101.     $theme_name = $a_theme['Name'];
  102.     if ($theme_name == $theme) $selected = " selected='selected'";
  103.     else $selected = '';
  104.     $theme_name = attribute_escape($theme_name);
  105.     echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
  106. }
  107. ?>
  108.         </select>
  109.         <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
  110.     </form>
  111. </div>
  112. <div class="tablenav">
  113. <div class="alignleft">
  114. <big><strong><?php echo sprintf($desc_header, $file_show); ?></big>
  115. </div>
  116. <br class="clear" />
  117. </div>
  118. <br class="clear" />
  119.     <div id="templateside">
  120.     <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
  121.  
  122. <?php
  123. if ($allowed_files) :
  124. ?>
  125.     <h4><?php _e('Templates'); ?></h4>
  126.     <ul>
  127. <?php foreach($themes[$theme]['Template Files'] as $template_file) :
  128.         $description = get_file_description($template_file);
  129.         $template_show = basename($template_file);
  130.         $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
  131.         $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
  132.         ?>
  133.         <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
  134. <?php endforeach; ?>
  135.     </ul>
  136.     <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
  137.     <ul>
  138. <?php foreach($themes[$theme]['Stylesheet Files'] as $style_file) :
  139.         $description = get_file_description($style_file);
  140.         $style_show = basename($style_file);
  141.         $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
  142.         $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
  143.         ?>
  144.         <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
  145. <?php endforeach; ?>
  146.     </ul>
  147. <?php endif; ?>
  148. </div>
  149.     <?php
  150.     if (!$error) {
  151.     ?>
  152.     <form name="template" id="template" action="theme-editor.php" method="post">
  153.     <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
  154.          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
  155.          <input type="hidden" name="action" value="update" />
  156.          <input type="hidden" name="file" value="<?php echo $file ?>" />
  157.          <input type="hidden" name="theme" value="<?php echo $theme ?>" />
  158.          </div>
  159.  
  160.         <div>
  161. <?php if ( is_writeable($real_file) ) : ?>
  162.             <p class="submit">
  163. <?php
  164.     echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
  165. ?>
  166. </p>
  167. <?php else : ?>
  168. <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>
  169. <?php endif; ?>
  170.         </div>
  171.     </form>
  172.     <?php
  173.     } else {
  174.         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
  175.     }
  176.     ?>
  177. <div class="clear">   </div>
  178. </div>
  179. <?php
  180. break;
  181. }
  182.  
  183. include("admin-footer.php") ?>
  184.