Пример #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);
 }