[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

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  
  60              update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated'));
  61  
  62              wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto"));
  63              exit;
  64          }
  65          wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
  66      } else {
  67          wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto");
  68      }
  69      exit;
  70  
  71  break;
  72  
  73  default:
  74  
  75      if ( isset($_GET['liveupdate']) ) {
  76          check_admin_referer('edit-plugin-test_' . $file);
  77  
  78          $error = validate_plugin($file);
  79          if ( is_wp_error($error) )
  80              wp_die( $error );
  81  
  82          if ( ! is_plugin_active($file) )
  83              activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
  84  
  85          wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
  86          exit;
  87      }
  88  
  89      // List of allowable extensions
  90      $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
  91      $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
  92  
  93      if ( ! is_file($real_file) ) {
  94          wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
  95      } else {
  96          // Get the extension of the file
  97          if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
  98              $ext = strtolower($matches[1]);
  99              // If extension is not in the acceptable list, skip it
 100              if ( !in_array( $ext, $editable_extensions) )
 101                  wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
 102          }
 103      }
 104  
 105      require_once ('admin-header.php');
 106  
 107      update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
 108  
 109      $content = file_get_contents( $real_file );
 110  
 111      if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
 112          $functions = wp_doc_link_parse( $content );
 113  
 114          if ( !empty($functions) ) {
 115              $docs_select = '<select name="docs-list" id="docs-list">';
 116              $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
 117              foreach ( $functions as $function) {
 118                  $docs_select .= '<option value="' . esc_attr( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
 119              }
 120              $docs_select .= '</select>';
 121          }
 122      }
 123  
 124      $content = htmlspecialchars( $content );
 125      $codepress_lang = codepress_get_lang($real_file);
 126  
 127      ?>
 128  <?php if (isset($_GET['a'])) : ?>
 129   <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div>
 130  <?php elseif (isset($_GET['phperror'])) : ?>
 131   <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
 132      <?php
 133          if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
 134      <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>
 135      <?php } ?>
 136  </div>
 137  <?php endif; ?>
 138  <div class="wrap">
 139  <?php screen_icon(); ?>
 140  <h2><?php echo esc_html( $title ); ?></h2>
 141  
 142  <div class="fileedit-sub">
 143  <div class="alignleft">
 144  <big><?php
 145      if ( is_plugin_active($plugin) ) {
 146          if ( is_writeable($real_file) )
 147              echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
 148          else
 149              echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
 150      } else {
 151          if ( is_writeable($real_file) )
 152              echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
 153          else
 154              echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
 155      }
 156      ?></big>
 157  </div>
 158  <div class="alignright">
 159      <form action="plugin-editor.php" method="post">
 160          <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
 161          <select name="plugin" id="plugin">
 162  <?php
 163      foreach ( $plugins as $plugin_key => $a_plugin ) {
 164          $plugin_name = $a_plugin['Name'];
 165          if ( $plugin_key == $plugin )
 166              $selected = " selected='selected'";
 167          else
 168              $selected = '';
 169          $plugin_name = esc_attr($plugin_name);
 170          $plugin_key = esc_attr($plugin_key);
 171          echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
 172      }
 173  ?>
 174          </select>
 175          <input type="submit" name="Submit" value="<?php esc_attr_e('Select') ?>" class="button" />
 176      </form>
 177  </div>
 178  <br class="clear" />
 179  </div>
 180  
 181  <div id="templateside">
 182      <h3><?php _e('Plugin Files'); ?></h3>
 183  
 184      <ul>
 185  <?php
 186  foreach ( $plugin_files as $plugin_file ) :
 187      // Get the extension of the file
 188      if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {
 189          $ext = strtolower($matches[1]);
 190          // If extension is not in the acceptable list, skip it
 191          if ( !in_array( $ext, $editable_extensions ) )
 192              continue;
 193      } else {
 194          // No extension found
 195          continue;
 196      }
 197  ?>
 198          <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>
 199  <?php endforeach; ?>
 200      </ul>
 201  </div>
 202  <form name="template" id="template" action="plugin-editor.php" method="post">
 203      <?php wp_nonce_field('edit-plugin_' . $file) ?>
 204          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
 205          <input type="hidden" name="action" value="update" />
 206          <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
 207          <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
 208          <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
 209          </div>
 210          <?php if ( !empty( $docs_select ) ) : ?>
 211          <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>
 212          <?php endif; ?>
 213  <?php if ( is_writeable($real_file) ) : ?>
 214      <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
 215          <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>
 216      <?php } ?>
 217      <p class="submit">
 218      <?php
 219          if ( isset($_GET['phperror']) )
 220              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' />";
 221          else
 222              echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />";
 223      ?>
 224      </p>
 225  <?php else : ?>
 226      <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>
 227  <?php endif; ?>
 228  </form>
 229  <br class="clear" />
 230  </div>
 231  <script type="text/javascript">
 232  /* <![CDATA[ */
 233  jQuery(document).ready(function($){
 234      $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
 235      $('#newcontent').scrollTop( $('#scrollto').val() );
 236  });
 237  /* ]]> */
 238  </script>
 239  <?php
 240      break;
 241  }
 242  include ("admin-footer.php");


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7