[ Index ]

PHP Cross Reference of Wordpress 2.9.1

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Edit plugin editor administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('admin.php');
  11  
  12  if ( !current_user_can('edit_plugins') )
  13      wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
  14  
  15  $title = __("Edit Plugins");
  16  $parent_file = 'plugins.php';
  17  
  18  wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
  19  
  20  wp_admin_css( 'theme-editor' );
  21  
  22  $plugins = get_plugins();
  23  
  24  if ( isset($_REQUEST['file']) )
  25      $plugin = stripslashes($_REQUEST['file']);
  26  
  27  if ( empty($plugin) ) {
  28      $plugin = array_keys($plugins);
  29      $plugin = $plugin[0];
  30  }
  31  
  32  $plugin_files = get_plugin_files($plugin);
  33  
  34  if ( empty($file) )
  35      $file = $plugin_files[0];
  36  else
  37      $file = stripslashes($file);
  38  
  39  $file = validate_file_to_edit($file, $plugin_files);
  40  $real_file = WP_PLUGIN_DIR . '/' . $file;
  41  $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
  42  
  43  switch ( $action ) {
  44  
  45  case 'update':
  46  
  47      check_admin_referer('edit-plugin_' . $file);
  48  
  49      $newcontent = stripslashes($_POST['newcontent']);
  50      if ( is_writeable($real_file) ) {
  51          $f = fopen($real_file, 'w+');
  52          fwrite($f, $newcontent);
  53          fclose($f);
  54  
  55          // Deactivate so we can test it.
  56          if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
  57              if ( is_plugin_active($file) )
  58                  deactivate_plugins($file, true);
  59              wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto"));
  60              exit;
  61          }
  62          wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
  63      } else {
  64          wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto");
  65      }
  66      exit;
  67  
  68  break;
  69  
  70  default:
  71  
  72      if ( isset($_GET['liveupdate']) ) {
  73          check_admin_referer('edit-plugin-test_' . $file);
  74  
  75          $error = validate_plugin($file);
  76          if ( is_wp_error($error) )
  77              wp_die( $error );
  78  
  79          if ( ! is_plugin_active($file) )
  80              activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
  81  
  82          wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
  83          exit;
  84      }
  85  
  86      // List of allowable extensions
  87      $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
  88      $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
  89  
  90      if ( ! is_file($real_file) ) {
  91          wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
  92      } else {
  93          // Get the extension of the file
  94          if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
  95              $ext = strtolower($matches[1]);
  96              // If extension is not in the acceptable list, skip it
  97              if ( !in_array( $ext, $editable_extensions) )
  98                  wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
  99          }
 100      }
 101  
 102      require_once ('admin-header.php');
 103  
 104      update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
 105  
 106      $content = file_get_contents( $real_file );
 107  
 108      if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
 109          $functions = wp_doc_link_parse( $content );
 110  
 111          if ( !empty($functions) ) {
 112              $docs_select = '<select name="docs-list" id="docs-list">';
 113              $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
 114              foreach ( $functions as $function) {
 115                  $docs_select .= '<option value="' . esc_attr( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
 116              }
 117              $docs_select .= '</select>';
 118          }
 119      }
 120  
 121      $content = htmlspecialchars( $content );
 122      $codepress_lang = codepress_get_lang($real_file);
 123  
 124      ?>
 125  <?php if (isset($_GET['a'])) : ?>
 126   <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
 127  <?php elseif (isset($_GET['phperror'])) : ?>
 128   <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
 129      <?php
 130          if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
 131      <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo esc_attr($file); ?>&amp;_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe>
 132      <?php } ?>
 133  </div>
 134  <?php endif; ?>
 135  <div class="wrap">
 136  <?php screen_icon(); ?>
 137  <h2><?php echo esc_html( $title ); ?></h2>
 138  
 139  <div class="fileedit-sub">
 140  <div class="alignleft">
 141  <big><?php
 142      if ( is_plugin_active($plugin) ) {
 143          if ( is_writeable($real_file) )
 144              echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
 145          else
 146              echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
 147      } else {
 148          if ( is_writeable($real_file) )
 149              echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
 150          else
 151              echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
 152      }
 153      ?></big>
 154  </div>
 155  <div class="alignright">
 156      <form action="plugin-editor.php" method="post">
 157          <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
 158          <select name="plugin" id="plugin">
 159  <?php
 160      foreach ( $plugins as $plugin_key => $a_plugin ) {
 161          $plugin_name = $a_plugin['Name'];
 162          if ( $plugin_key == $plugin )
 163              $selected = " selected='selected'";
 164          else
 165              $selected = '';
 166          $plugin_name = esc_attr($plugin_name);
 167          $plugin_key = esc_attr($plugin_key);
 168          echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
 169      }
 170  ?>
 171          </select>
 172          <input type="submit" name="Submit" value="<?php esc_attr_e('Select') ?>" class="button" />
 173      </form>
 174  </div>
 175  <br class="clear" />
 176  </div>
 177  
 178  <div id="templateside">
 179      <h3><?php _e('Plugin Files'); ?></h3>
 180  
 181      <ul>
 182  <?php
 183  foreach ( $plugin_files as $plugin_file ) :
 184      // Get the extension of the file
 185      if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {
 186          $ext = strtolower($matches[1]);
 187          // If extension is not in the acceptable list, skip it
 188          if ( !in_array( $ext, $editable_extensions ) )
 189              continue;
 190      } else {
 191          // No extension found
 192          continue;
 193      }
 194  ?>
 195          <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&amp;plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li>
 196  <?php endforeach; ?>
 197      </ul>
 198  </div>
 199  <form name="template" id="template" action="plugin-editor.php" method="post">
 200      <?php wp_nonce_field('edit-plugin_' . $file) ?>
 201          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
 202          <input type="hidden" name="action" value="update" />
 203          <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
 204          <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
 205          <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
 206          </div>
 207          <?php if ( !empty( $docs_select ) ) : ?>
 208          <div id="documentation"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" /></div>
 209          <?php endif; ?>
 210  <?php if ( is_writeable($real_file) ) : ?>
 211      <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
 212          <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended.  If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>
 213      <?php } ?>
 214      <p class="submit">
 215      <?php
 216          if ( isset($_GET['phperror']) )
 217              echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File and Attempt to Reactivate') . "' tabindex='2' />";
 218          else
 219              echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />";
 220      ?>
 221      </p>
 222  <?php else : ?>
 223      <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>
 224  <?php endif; ?>
 225  </form>
 226  <br class="clear" />
 227  </div>
 228  <script type="text/javascript">
 229  /* <![CDATA[ */
 230  jQuery(document).ready(function($){
 231      $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
 232      $('#newcontent').scrollTop( $('#scrollto').val() );
 233  });
 234  /* ]]> */
 235  </script>
 236  <?php
 237      break;
 238  }
 239  include ("admin-footer.php");


Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7