[ Index ]

WordPress Source Cross Reference

title

Body

[close]

/wp-admin/ -> theme-editor.php (source)

   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  $themes = get_themes();
  10  
  11  if (empty($theme)) {
  12      $theme = get_current_theme();
  13  } else {
  14      $theme = stripslashes($theme);
  15   }
  16  
  17  
  18  if ( ! isset($themes[$theme]) )
  19      wp_die(__('The requested theme does not exist.'));
  20  
  21  $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
  22  
  23  if (empty($file)) {
  24      $file = $allowed_files[0];
  25  }
  26  
  27  $file = validate_file_to_edit($file, $allowed_files);
  28  $real_file = get_real_file_to_edit($file);
  29  
  30  $file_show = basename( $file );
  31  
  32  switch($action) {
  33  
  34  case 'update':
  35  
  36      check_admin_referer('edit-theme_' . $file . $theme);
  37  
  38      if ( !current_user_can('edit_themes') )
  39          wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
  40  
  41      $newcontent = stripslashes($_POST['newcontent']);
  42      $theme = urlencode($theme);
  43      if (is_writeable($real_file)) {
  44          $f = fopen($real_file, 'w+');
  45          fwrite($f, $newcontent);
  46          fclose($f);
  47          wp_redirect("theme-editor.php?file=$file&theme=$theme&a=te");
  48      } else {
  49          wp_redirect("theme-editor.php?file=$file&theme=$theme");
  50      }
  51  
  52      exit();
  53  
  54  break;
  55  
  56  default:
  57  
  58      require_once ('admin-header.php');
  59      if ( !current_user_can('edit_themes') )
  60          wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
  61  
  62      update_recently_edited($file);
  63  
  64      if (!is_file($real_file))
  65          $error = 1;
  66  
  67      if (!$error && filesize($real_file) > 0) {
  68          $f = fopen($real_file, 'r');
  69          $content = fread($f, filesize($real_file));
  70          $content = htmlspecialchars($content);
  71      }
  72  
  73      ?>
  74  <?php if (isset($_GET['a'])) : ?>
  75   <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
  76  <?php endif; ?>
  77   <div class="wrap">
  78    <form name="theme" action="theme-editor.php" method="post"> 
  79          <?php _e('Select theme to edit:') ?>
  80          <select name="theme" id="theme">
  81      <?php
  82          foreach ($themes as $a_theme) {
  83          $theme_name = $a_theme['Name'];
  84          if ($theme_name == $theme) $selected = " selected='selected'";
  85          else $selected = '';
  86          $theme_name = wp_specialchars($theme_name, true);
  87          echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
  88      }
  89  ?>
  90   </select>
  91   <input type="submit" name="Submit" value="<?php _e('Select &raquo;') ?>" />
  92   </form>
  93   </div>
  94  
  95   <div class="wrap"> 
  96    <?php
  97      if ( is_writeable($real_file) ) {
  98          echo '<h2>' . sprintf(__('Editing <code>%s</code>'), $file_show) . '</h2>';
  99      } else {
 100          echo '<h2>' . sprintf(__('Browsing <code>%s</code>'), $file_show) . '</h2>';
 101      }
 102      ?>
 103      <div id="templateside">
 104    <h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
 105  
 106  <?php
 107  if ($allowed_files) :
 108  ?>
 109    <ul>
 110  <?php foreach($allowed_files as $allowed_file) : ?>
 111           <li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&amp;theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description($allowed_file); ?></a></li>
 112  <?php endforeach; ?>
 113    </ul>
 114  <?php endif; ?>
 115  </div> 
 116      <?php
 117      if (!$error) {
 118      ?> 
 119    <form name="template" id="template" action="theme-editor.php" method="post">
 120    <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
 121           <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
 122       <input type="hidden" name="action" value="update" /> 
 123       <input type="hidden" name="file" value="<?php echo $file ?>" /> 
 124       <input type="hidden" name="theme" value="<?php echo $theme ?>" />
 125           </div>
 126  <?php if ( is_writeable($real_file) ) : ?>
 127       <p class="submit">
 128  <?php
 129      echo "<input type='submit' name='submit' value='    " . __('Update File &raquo;') . "' tabindex='2' />";
 130  ?>
 131  </p>
 132  <?php else : ?>
 133  <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
 134  <?php endif; ?>
 135     </form> 
 136    <?php
 137      } else {
 138          echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
 139      }
 140      ?>
 141  <div class="clear"> &nbsp; </div>
 142  </div> 
 143  <?php
 144  break;
 145  }
 146  
 147  include ("admin-footer.php") ?> 

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana