home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / plugin-editor.php < prev    next >
Encoding:
PHP Script  |  2008-05-27  |  5.2 KB  |  156 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __("Edit Plugins");
  5. $parent_file = 'plugins.php';
  6.  
  7. wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
  8.  
  9. wp_admin_css( 'theme-editor' );
  10.  
  11. $plugins = get_plugins();
  12. $plugin_files = array_keys($plugins);
  13.  
  14. if (empty($file))
  15.     $file = $plugin_files[0];
  16.  
  17. $file = validate_file_to_edit($file, $plugin_files);
  18. $real_file = WP_PLUGIN_DIR . '/' . $file;
  19.  
  20. switch($action) {
  21.  
  22. case 'update':
  23.  
  24.     check_admin_referer('edit-plugin_' . $file);
  25.  
  26.     if ( !current_user_can('edit_plugins') )
  27.         wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
  28.  
  29.     $newcontent = stripslashes($_POST['newcontent']);
  30.     if ( is_writeable($real_file) ) {
  31.         $f = fopen($real_file, 'w+');
  32.         fwrite($f, $newcontent);
  33.         fclose($f);
  34.  
  35.         // Deactivate so we can test it.
  36.         if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
  37.             if ( is_plugin_active($file) )
  38.                 deactivate_plugins($file, true);
  39.             wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
  40.             exit;
  41.         }
  42.         wp_redirect("plugin-editor.php?file=$file&a=te");
  43.     } else {
  44.         wp_redirect("plugin-editor.php?file=$file");
  45.     }
  46.     exit;
  47.  
  48. break;
  49.  
  50. default:
  51.  
  52.     if ( !current_user_can('edit_plugins') )
  53.         wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
  54.  
  55.     if ( isset($_GET['liveupdate']) ) {
  56.         check_admin_referer('edit-plugin-test_' . $file);
  57.  
  58.         $error = validate_plugin($file);
  59.         if( is_wp_error($error) )
  60.             wp_die( $error );
  61.  
  62.         if ( ! is_plugin_active($file) )
  63.             activate_plugin($file, "plugin-editor.php?file=$file&phperror=1");// we'll override this later if the plugin can be included without fatal error
  64.  
  65.         wp_redirect("plugin-editor.php?file=$file&a=te");
  66.         exit;
  67.     }
  68.  
  69.     require_once('admin-header.php');
  70.  
  71.     update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
  72.  
  73.     if ( ! is_file($real_file) )
  74.         $error = 1;
  75.  
  76.     if ( ! $error )
  77.         $content = htmlspecialchars(file_get_contents($real_file));
  78.  
  79.     ?>
  80. <?php if (isset($_GET['a'])) : ?>
  81.  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
  82. <?php elseif (isset($_GET['phperror'])) : ?>
  83.  <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>
  84.     <?php
  85.         if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
  86.     <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo attribute_escape($file); ?>&_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
  87.     <?php } ?>
  88. </div>
  89. <?php endif; ?>
  90.  <div class="wrap">
  91. <div class="bordertitle">
  92.     <h2><?php _e('Plugin Editor'); ?></h2>
  93. </div>
  94. <div class="tablenav">
  95. <div class="alignleft">
  96. <big><strong><?php
  97.     if ( is_plugin_active($file) ) {
  98.         if ( is_writeable($real_file) )
  99.             echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
  100.         else
  101.             echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
  102.     } else {
  103.         if ( is_writeable($real_file) )
  104.             echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
  105.         else
  106.             echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
  107.     }
  108.     ?></strong></big>
  109. </div>
  110. <br class="clear" />
  111. </div>
  112. <br class="clear" />
  113.     <div id="templateside">
  114.     <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
  115.  
  116.     <h4><?php _e('Plugins'); ?></h4>
  117.     <ul>
  118. <?php foreach($plugin_files as $plugin_file) : ?>
  119.         <li><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
  120. <?php endforeach; ?>
  121.     </ul>
  122.     </div>
  123. <?php    if ( ! $error ) { ?>
  124.     <form name="template" id="template" action="plugin-editor.php" method="post">
  125.     <?php wp_nonce_field('edit-plugin_' . $file) ?>
  126.         <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
  127.         <input type="hidden" name="action" value="update" />
  128.         <input type="hidden" name="file" value="<?php echo $file ?>" />
  129.         </div>
  130. <?php if ( is_writeable($real_file) ) : ?>
  131.     <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
  132.         <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>
  133.     <?php } ?>
  134.     <p class="submit">
  135.     <?php
  136.         if ( isset($_GET['phperror']) )
  137.             echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' value='" . __('Update File and Attempt to Reactivate') . "' tabindex='2' />";
  138.         else
  139.             echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
  140.     ?>
  141.     </p>
  142. <?php else : ?>
  143.     <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>
  144. <?php endif; ?>
  145.  </form>
  146. <?php
  147.     } else {
  148.         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
  149.     }
  150. ?>
  151. <div class="clear">   </div>
  152. </div>
  153. <?php
  154.     break;
  155. }
  156. include("admin-footer.php") ?>