Esempio n. 1
0
 public static function saveFile()
 {
     $error = '';
     try {
         if (isset($_POST['new_content']) && isset($_POST['real_file'])) {
             $real_file = $_POST['real_file'];
             if (file_exists($real_file)) {
                 if (is_writable($real_file)) {
                     $new_content = stripslashes($_POST['new_content']);
                     if (file_get_contents($real_file) === $new_content) {
                         WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
                     } else {
                         $f = fopen($real_file, 'w+');
                         fwrite($f, $new_content);
                         fclose($f);
                         WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to {$real_file}");
                     }
                 } else {
                     $error = __('This file is not writable', 'wpeditor');
                 }
             } else {
                 $error = __('This file does not exist', 'wpeditor');
             }
         } else {
             $error = __('Invalid Content', 'wpeditor');
         }
     } catch (WPEditorException $e) {
         $error = $e->getMessage();
         WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Caught WPEditor exception: " . $e->getMessage());
     }
     if ($error) {
         $result[0] = 'WPEditorAjaxError';
         $result[1] = '<h3>' . __('Warning', 'wpeditor') . "</h3><p>{$error}</p>";
     } else {
         $result[0] = 'WPEditorAjaxSuccess';
         $result[1] = '<h3>' . __('Success', 'wpeditor') . '</h3><p>' . $_REQUEST['_success'] . '</p>';
     }
     if (isset($_POST['extension'])) {
         $result[2] = $_POST['extension'];
     }
     $out = json_encode($result);
     echo $out;
     die;
 }
Esempio n. 2
0
 public static function addThemesPage()
 {
     if (!current_user_can('edit_themes')) {
         wp_die('<p>' . __('You do not have sufficient permissions to edit templates for this site.', 'wpeditor') . '</p>');
     }
     if (isset($_POST['create_theme_new']) && wp_verify_nonce($_POST['create_theme_new'], 'create_theme_new')) {
         self::create_new_theme();
     }
     if (isset($_POST['download_theme'])) {
         WPEditorBrowser::download_theme($_POST['file']);
     }
     if (isset($_POST['download_theme_file'])) {
         WPEditorBrowser::download_file($_POST['file_path'], 'theme');
     }
     if (WP_34) {
         $themes = wp_get_themes();
     } else {
         $themes = get_themes();
     }
     if (empty($themes)) {
         wp_die('<p>' . __('There are no themes installed on this site.', 'wpeditor') . '</p>');
     }
     if (isset($_REQUEST['theme'])) {
         $theme = stripslashes($_REQUEST['theme']);
     }
     if (isset($_REQUEST['file'])) {
         $file = stripslashes($_REQUEST['file']);
         $theme = $_REQUEST['file'];
     }
     if (empty($theme)) {
         if (WP_34) {
             $theme = wp_get_theme();
         } else {
             $theme = get_current_theme();
         }
     }
     $stylesheet = '';
     if ($theme && WP_34) {
         $stylesheet = urldecode($theme);
         if (is_object($theme)) {
             $stylesheet = urldecode($theme->stylesheet);
         }
     } elseif (WP_34) {
         $stylesheet = get_stylesheet();
     }
     if (WP_34) {
         $wp_theme = wp_get_theme($stylesheet);
     } else {
         $wp_theme = '';
     }
     if (empty($file)) {
         if (WP_34) {
             $file = basename($wp_theme['Stylesheet Dir']) . '/style.css';
         } else {
             $file = basename($themes[$theme]['Stylesheet Dir']) . '/style.css';
         }
     } else {
         $file = stripslashes($file);
     }
     if (WP_34) {
         $tf = WPEditorBrowser::getFilesAndFolders(WPWINDOWS ? str_replace("/", "\\", $wp_theme['Theme Root'] . '/' . $file) : $wp_theme['Theme Root'] . '/' . $file, 0, 'theme');
     } else {
         $tf = WPEditorBrowser::getFilesAndFolders(WPWINDOWS ? str_replace("/", "\\", $themes[$theme]['Theme Root'] . '/' . $file) : $themes[$theme]['Theme Root'] . '/' . $file, 0, 'theme');
     }
     foreach ($tf as $theme_file) {
         foreach ($theme_file as $k => $t) {
             if ($k == 'file') {
                 $theme_files[] = $t;
             }
         }
     }
     $file = validate_file_to_edit(WPWINDOWS ? str_replace("/", "\\", $file) : $file, $theme_files);
     if (WP_34) {
         $current_theme_root = $wp_theme['Theme Root'] . '/' . dirname($file) . '/';
     } else {
         $current_theme_root = $themes[$theme]['Theme Root'] . '/' . dirname($file) . '/';
     }
     $real_file = $current_theme_root . basename($file);
     if (isset($_POST['new-content']) && file_exists($real_file) && is_writable($real_file)) {
         $new_content = stripslashes($_POST['new-content']);
         if (file_get_contents($real_file) === $new_content) {
             WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
         } else {
             $f = fopen($real_file, 'w+');
             fwrite($f, $new_content);
             fclose($f);
             WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to {$real_file}");
         }
     }
     $content = file_get_contents($real_file);
     $content = esc_textarea($content);
     $scroll_to = isset($_REQUEST['scroll_to']) ? (int) $_REQUEST['scroll_to'] : 0;
     $data = array('themes' => $themes, 'theme' => $theme, 'wp_theme' => $wp_theme, 'stylesheet' => $stylesheet, 'theme_files' => $theme_files, 'current_theme_root' => $current_theme_root, 'real_file' => $real_file, 'content' => $content, 'scroll_to' => $scroll_to, 'file' => $file, 'content-type' => 'theme');
     echo WPEditor::getView('views/theme-editor.php', $data);
 }
Esempio n. 3
0
 public static function addPluginsPage()
 {
     if (!current_user_can('edit_plugins')) {
         wp_die('<p>' . __('You do not have sufficient permissions to edit plugins for this site.', 'wp-editor') . '</p>');
     }
     if (isset($_POST['create_plugin_new']) && wp_verify_nonce($_POST['create_plugin_new'], 'create_plugin_new')) {
         self::create_new_plugin();
     }
     if (isset($_POST['download_plugin'])) {
         WPEditorBrowser::download_plugin($_POST['file']);
     }
     if (isset($_POST['download_plugin_file'])) {
         WPEditorBrowser::download_file($_POST['file_path'], 'plugin');
     }
     $plugins = get_plugins();
     if (empty($plugins)) {
         wp_die('<p>' . __('There are no plugins installed on this site.', 'wp-editor') . '</p>');
     }
     if (isset($_REQUEST['plugin'])) {
         $plugin = stripslashes($_REQUEST['plugin']);
     }
     if (isset($_REQUEST['file'])) {
         $file = stripslashes($_REQUEST['file']);
     }
     if (empty($plugin)) {
         $plugin = array_keys($plugins);
         $plugin = $plugin[0];
     }
     $plugin_files[] = $plugin;
     if (empty($file)) {
         $file = $plugin_files[0];
     } else {
         $file = stripslashes($file);
         $plugin = $file;
     }
     $pf = WPEditorBrowser::getFilesAndFolders(WPWINDOWS ? str_replace("/", "\\", WP_PLUGIN_DIR . '/' . $file) : WP_PLUGIN_DIR . '/' . $file, 0, 'plugin');
     foreach ($pf as $plugin_file) {
         foreach ($plugin_file as $k => $p) {
             if ($k == 'file') {
                 $plugin_files[] = $p;
             }
         }
     }
     $file = validate_file_to_edit(WPWINDOWS ? str_replace("/", "\\", $file) : $file, $plugin_files);
     $current_plugin_root = WP_PLUGIN_DIR . '/' . dirname($file);
     $real_file = WP_PLUGIN_DIR . '/' . $plugin;
     if (isset($_POST['new-content']) && file_exists($real_file) && is_writable($real_file)) {
         $new_content = stripslashes($_POST['new-content']);
         if (file_get_contents($real_file) === $new_content) {
             WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
         } else {
             $f = fopen($real_file, 'w+');
             fwrite($f, $new_content);
             fclose($f);
             WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to {$real_file}");
         }
     }
     $content = file_get_contents($real_file);
     $content = esc_textarea($content);
     $scroll_to = isset($_REQUEST['scroll_to']) ? (int) $_REQUEST['scroll_to'] : 0;
     $data = array('plugins' => $plugins, 'plugin' => $plugin, 'plugin_files' => $plugin_files, 'current_plugin_root' => $current_plugin_root, 'real_file' => $real_file, 'content' => $content, 'scroll_to' => $scroll_to, 'file' => $file, 'content-type' => 'plugin');
     echo WPEditor::getView('views/plugin-editor.php', $data);
 }