Example #1
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);
 }
Example #2
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);
 }
Example #3
0
 public static function ajaxFolders()
 {
     $dir = urldecode($_REQUEST['dir']);
     if (isset($_REQUEST['contents'])) {
         $contents = $_REQUEST['contents'];
     } else {
         $contents = 0;
     }
     $type = null;
     if (isset($_REQUEST['type'])) {
         $type = $_REQUEST['type'];
     }
     $out = json_encode(WPEditorBrowser::getFilesAndFolders($dir, $contents, $type));
     echo $out;
     die;
 }
Example #4
0
 public static function getFilesAndFolders($dir, $contents, $type)
 {
     $slash = '/';
     if (WPWINDOWS) {
         $slash = '\\';
     }
     $output = array();
     if (is_dir($dir)) {
         if ($handle = opendir($dir)) {
             $size_document_root = strlen($_SERVER['DOCUMENT_ROOT']);
             $pos = strrpos($dir, $slash);
             $topdir = substr($dir, 0, $pos + 1);
             $i = 0;
             while (false !== ($file = readdir($handle))) {
                 if ($file != '.' && $file != '..' && substr($file, 0, 1) != '.' && self::allowedFiles($dir, $file)) {
                     $rows[$i]['data'] = $file;
                     $rows[$i]['dir'] = is_dir($dir . $slash . $file);
                     $i++;
                 }
             }
             closedir($handle);
         }
         if (isset($rows)) {
             $size = count($rows);
             $rows = self::sortRows($rows);
             for ($i = 0; $i < $size; ++$i) {
                 $topdir = $dir . $slash . $rows[$i]['data'];
                 $output[$i]['name'] = $rows[$i]['data'];
                 $output[$i]['path'] = $topdir;
                 if ($rows[$i]['dir']) {
                     $output[$i]['filetype'] = 'folder';
                     $output[$i]['extension'] = 'folder';
                     $output[$i]['filesize'] = '';
                 } else {
                     $output[$i]['writable'] = false;
                     if (is_writable($output[$i]['path'])) {
                         $output[$i]['writable'] = true;
                     }
                     $output[$i]['filetype'] = 'file';
                     $path = pathinfo($output[$i]['name']);
                     if (isset($path['extension'])) {
                         $output[$i]['extension'] = $path['extension'];
                     }
                     $output[$i]['filesize'] = '(' . round(filesize($topdir) * 0.0009765625, 2) . ' KB)';
                     if ($type == 'theme') {
                         $output[$i]['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output[$i]['path']);
                         $output[$i]['url'] = get_theme_root_uri() . $slash . $output[$i]['file'];
                     } else {
                         $output[$i]['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output[$i]['path']);
                         $output[$i]['url'] = plugins_url() . $slash . $output[$i]['file'];
                     }
                 }
             }
         } else {
             $output[-1] = 'this folder has no contents';
         }
     } elseif (is_file($dir)) {
         if (isset($contents) && $contents == 1) {
             $output['name'] = basename($dir);
             $output['path'] = $dir;
             $output['filetype'] = 'file';
             $path = pathinfo($output['name']);
             if (isset($path['extension'])) {
                 $output['extension'] = $path['extension'];
             }
             $output['content'] = file_get_contents($dir);
             $output['writable'] = false;
             if (is_writable($output['path'])) {
                 $output['writable'] = true;
             }
             if ($type == 'theme') {
                 $output['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output['path']);
                 $output['url'] = get_theme_root_uri() . $slash . $output['file'];
             } else {
                 $output['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output['path']);
                 $output['url'] = plugins_url() . $slash . $output['file'];
             }
         } else {
             $pos = strrpos($dir, $slash);
             $newdir = substr($dir, 0, $pos);
             if ($handle = opendir($newdir)) {
                 $size_document_root = strlen($_SERVER['DOCUMENT_ROOT']);
                 $pos = strrpos($newdir, $slash);
                 $topdir = substr($newdir, 0, $pos + 1);
                 $i = 0;
                 while (false !== ($file = readdir($handle))) {
                     if ($file != '.' && $file != '..' && substr($file, 0, 1) != '.' && WPEditorBrowser::allowedFiles($newdir, $file)) {
                         $rows[$i]['data'] = $file;
                         $rows[$i]['dir'] = is_dir($newdir . $slash . $file);
                         $i++;
                     }
                 }
                 closedir($handle);
             }
             if (isset($rows)) {
                 $size = count($rows);
                 $rows = self::sortRows($rows);
                 for ($i = 0; $i < $size; ++$i) {
                     $topdir = $newdir . $slash . $rows[$i]['data'];
                     $output[$i]['name'] = $rows[$i]['data'];
                     $output[$i]['path'] = $topdir;
                     if ($rows[$i]['dir']) {
                         $output[$i]['filetype'] = 'folder';
                         $output[$i]['extension'] = 'folder';
                         $output[$i]['filesize'] = '';
                     } else {
                         $output[$i]['writable'] = false;
                         if (is_writable($output[$i]['path'])) {
                             $output[$i]['writable'] = true;
                         }
                         $output[$i]['filetype'] = 'file';
                         $path = pathinfo($rows[$i]['data']);
                         if (isset($path['extension'])) {
                             $output[$i]['extension'] = $path['extension'];
                         }
                         $output[$i]['filesize'] = '(' . round(filesize($topdir) * 0.0009765625, 2) . ' KB)';
                     }
                     if ($output[$i]['path'] == $dir) {
                         $output[$i]['content'] = file_get_contents($dir);
                     }
                     $output[$i]['writable'] = false;
                     if (is_writable($output[$i]['path'])) {
                         $output[$i]['writable'] = true;
                     }
                     if ($type == 'theme') {
                         $output[$i]['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output[$i]['path']);
                         $output[$i]['url'] = get_theme_root_uri() . $slash . $output[$i]['file'];
                     } else {
                         $output[$i]['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output[$i]['path']);
                         $output[$i]['url'] = plugins_url() . $slash . $output[$i]['file'];
                     }
                 }
             } else {
                 $output[-1] = 'bad file or unable to open';
             }
         }
     } else {
         $output[-1] = 'bad file or unable to open';
     }
     return $output;
 }