示例#1
0
    wp_die(__('The requested theme does not exist.'));
}
$allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
if (empty($file)) {
    $file = $allowed_files[0];
} else {
    $file = stripslashes($file);
    if ('theme' == $dir) {
        $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file;
    } else {
        if ('style' == $dir) {
            $file = dirname(dirname($themes[$theme]['Stylesheet Dir'])) . $file;
        }
    }
}
validate_file_to_edit($file, $allowed_files);
$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
$file_show = basename($file);
switch ($action) {
    case 'update':
        check_admin_referer('edit-theme_' . $file . $theme);
        $newcontent = stripslashes($_POST['newcontent']);
        $theme = urlencode($theme);
        if (is_writeable($file)) {
            //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
            $f = fopen($file, 'w+');
            if ($f !== FALSE) {
                fwrite($f, $newcontent);
                fclose($f);
                $location = "theme-editor.php?file={$file}&theme={$theme}&a=te&scrollto={$scrollto}";
            } else {
            if (empty($_GET["{$wpvar}"])) {
                ${$wpvar} = '';
            } else {
                ${$wpvar} = $_GET["{$wpvar}"];
            }
        } else {
            ${$wpvar} = $_POST["{$wpvar}"];
        }
    }
}
$plugins = get_plugins();
$plugin_files = array_keys($plugins);
if (empty($file)) {
    $file = $plugin_files[0];
}
$file = validate_file_to_edit($file, $plugin_files);
$real_file = get_real_file_to_edit("wp-content/plugins/{$file}");
switch ($action) {
    case 'update':
        check_admin_referer('edit-plugin_' . $file);
        if (!current_user_can('edit_plugins')) {
            die('<p>' . __('You have do not have sufficient permissions to edit templates for this blog.') . '</p>');
        }
        $newcontent = stripslashes($_POST['newcontent']);
        if (is_writeable($real_file)) {
            $f = fopen($real_file, 'w+');
            fwrite($f, $newcontent);
            fclose($f);
            wp_redirect("plugin-editor.php?file={$file}&a=te");
        } else {
            wp_redirect("plugin-editor.php?file={$file}");
			$$wpvar = $_POST["$wpvar"];
		}
	}
}

$recents = get_option('recently_edited');

if (empty($file)) {
	if ($recents) {
		$file = $recents[0];
	} else {
		$file = 'index.php';
	}
}

$file = validate_file_to_edit($file);
$real_file = get_real_file_to_edit($file);

switch($action) {

case 'update':

	if ($user_level < 5) {
		die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
	}

	$newcontent = stripslashes($_POST['newcontent']);
	if (is_writeable($real_file)) {
		$f = fopen($real_file, 'w+');
		fwrite($f, $newcontent);
		fclose($f);
示例#4
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);
 }
 /**
  * Handles file actions of page post
  *
  * TODO - FUTURE :
  *    - adding update_recently_edited of wp core?
  *    - reimplementing message handling
  *
  * @param $fileaction   action to handle
  * @param $file         file to target
  *
  * @return $this|bool|int
  */
 private function _handle_fileaction($fileaction, $file)
 {
     $files = Log_Viewer_Admin::getFiles();
     validate_file_to_edit($file, $files);
     $realfile = Log_Viewer_Admin::transformFilePath($file);
     switch ($fileaction) {
         case self::$_KEYS_FILEACTIONS_DUMP:
             $dumped = $this->_dumpFile($realfile);
             // BUG: better redirect but not working cause already present output
             // wp_redirect( $this->getPageUrl() );
             //exit();
             // Workaround:
             unset($_POST[self::$_KEYS_FILEACTION_ACTION], $_POST[self::$_KEYS_FILEACTION_FILE], $_POST[self::$_KEYS_FILEACTION_SUBMIT], $_POST[self::$_KEYS_FILEACTION_SCROLLTO], $_REQUEST['file']);
             $this->_currentFile = false;
             break;
         case self::$_KEYS_FILEACTIONS_EMPTY:
             $handle = $this->_emptyFile($realfile);
             return $handle;
             break;
         case self::$_KEYS_FILEACTIONS_BREAK:
             $handle = $this->_appendBreak($realfile);
             return $handle;
             break;
         default:
             break;
     }
     return $this;
 }
示例#6
0
function read_tag($tag, $contents)
{
    $theTag = strstr($contents, 'get_' . $tag . '(');
    //when the tag doesnt exist, return nothing, or it will take the standard file
    if (!$theTag) {
        return '';
    }
    $theTag = str_replace('get_' . $tag . '(', '', $theTag);
    if (strpos($theTag, ')') != 0) {
        $theTag = substr($theTag, 0, strpos($theTag, ')'));
    } else {
        $theTag = '';
    }
    $theTag = str_replace('\'', '', $theTag);
    //remove '
    $theTag = str_replace('&quot;', '', $theTag);
    //remove "
    $fileToRead = get_template_directory_uri() . '/';
    $fileToRead .= $tag;
    if ($theTag) {
        $fileToRead .= '-' . $theTag;
    }
    $fileToRead .= '.php';
    $fileToRead = strstr($fileToRead, '/themes/');
    $fileToRead = validate_file_to_edit($fileToRead, $allowed_files);
    $fileToRead = get_real_file_to_edit($fileToRead);
    //first try to read the child theme, otherwise use the normal theme
    $themes = get_themes();
    $theme = $themes[get_current_theme()];
    $current_theme_url = $theme['Template'];
    $child_theme_url = str_replace('themes/', '', strstr(get_stylesheet_directory_uri(), 'themes/'));
    if (fopen(str_replace($current_theme_url, $child_theme_url, $fileToRead), 'r')) {
        //child theme exists
        $fileToRead = str_replace($current_theme_url, $child_theme_url, $fileToRead);
        $f = fopen($fileToRead, 'r');
    } else {
        $f = fopen($fileToRead, 'r');
    }
    $tagContents = fread($f, filesize($fileToRead));
    $tagContents = htmlspecialchars($tagContents);
    return $tagContents;
}
示例#7
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);
 }
示例#8
0
    public function onViewPage()
    {
        global $action, $file, $file2, $display, $autorefresh, $Apply;
        wp_reset_vars(array('action', 'file', 'file2', 'display', 'autorefresh', 'Apply'));
        $this->_loadUserSettings();
        $file = $file2;
        $newSettings = $this->_settings;
        if ($Apply) {
            !$autorefresh ? $newSettings["autorefresh"] = 0 : ($newSettings["autorefresh"] = 1);
            !$display ? $newSettings["display"] = $this->_settings["display"] : ($newSettings["display"] = $display);
        }
        //var_dump($newSettings);echo"<br/>";
        //var_dump($this->_settings);echo"<br/>";
        if ($this->_settings["autorefresh"] === 1) {
            ?>
            <script type="text/javascript">
                setTimeout("window.location.replace(document.URL);", <?php 
            echo $this->_settings["refreshtime"] * 1000;
            ?>
);
            </script>
        <?php 
        }
        if (is_user_logged_in()) {
            $this->_updateUserSettings($newSettings);
        }
        $this->_draw_header();
        if (!$this->_plugin->hasFiles()) {
            ?>
            <div id="message" class="updated">
                <p><?php 
            _e('No files found.');
            ?>
</p>
            </div>
            <?php 
            return;
        }
        $files = $this->_plugin->getFiles();
        if (isset($_REQUEST['file'])) {
            $file = stripslashes($_REQUEST['file']);
        } else {
            $file = $files[0];
        }
        $this->_currentFile = validate_file_to_edit($file, $this->_plugin->getFiles());
        $realfile = ciLogViewer::transformFilePath($this->_currentFile);
        $writeable = is_writeable($realfile);
        // TODO: Scroll to like plugin-editor.php
        //$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
        if (!$writeable) {
            $action = false;
            ?>
            <div id="message" class="updated">
                <p><?php 
            _e('You can not edit file ( not writeable ).');
            ?>
</p>
            </div>
        <?php 
        }
        switch ($action) {
            case 'dump':
                $dumped = unlink($realfile);
                if ($dumped) {
                    ?>
                    <div id="message" class="updated">
                        <p><?php 
                    _e('File dumped successfully.');
                    ?>
</p>
                    </div>
                    <?php 
                    return;
                } else {
                    ?>
                    <div id="message" class="error">
                        <p><?php 
                    _e('Could not dump file.');
                    ?>
</p>
                    </div>
                <?php 
                }
                break;
            case 'empty':
                $handle = fopen($realfile, 'w');
                if (!$handle) {
                    ?>
                    <div id="message" class="error">
                        <p><?php 
                    _e('Could not open file.');
                    ?>
</p>
                    </div>
                <?php 
                }
                $handle = fclose($handle);
                if (!$handle) {
                    ?>
                    <div id="message" class="error">
                        <p><?php 
                    _e('Could not empty file.');
                    ?>
</p>
                    </div>
                <?php 
                } else {
                    ?>
                    <div id="message" class="updated">
                        <p><?php 
                    _e('File empty successfull.');
                    ?>
</p>
                    </div>
                <?php 
                }
                break;
            case 'break':
                if (!error_log('------', 0)) {
                    ?>
                    <div id="message" class="error">
                        <p><?php 
                    _e('Could not update file.');
                    ?>
</p>
                    </div>
                <?php 
                } else {
                    ?>
                    <div id="message" class="updated">
                        <p><?php 
                    _e('File updated successfully.');
                    ?>
</p>
                    </div>
                <?php 
                }
                break;
            default:
                break;
        }
        ?>
        <div class="fileedit-sub">
            <strong>
                <?php 
        printf('%1$s <strong>%2$s</strong>', __('Showing'), str_replace(realpath(ABSPATH), "", $realfile));
        ?>
            </strong>

            <div class="tablenav top">

                <?php 
        if ($writeable) {
            ?>

                    <div class="alignleft">
                        <form method="post" action="<?php 
            echo $this->getPageUrl();
            ?>
">
                            <input type="hidden" value="<?php 
            echo $this->_currentFile;
            ?>
" name="file"/>
                            <input id="scrollto" type="hidden" value="0" name="scrollto">
                            <select name="action">
                                <option selected="selected" value="-1"><?php 
            _e('File Actions');
            ?>
</option>
                                <option value="dump"><?php 
            _e('Dump');
            ?>
</option>
                                <option value="empty"><?php 
            _e('Empty');
            ?>
</option>
                                <option value="break"><?php 
            _e('Break');
            ?>
</option>
                            </select>
                            <?php 
            submit_button(__('Do'), 'button', 'Do', false);
            ?>
                        </form>
                    </div>

                <?php 
        }
        ?>
                <div class="alignright">
                    <form method="post" action="<?php 
        echo $this->getPageUrl();
        ?>
">
                        <input type="hidden" value="<?php 
        echo $this->_currentFile;
        ?>
" name="file2"/>
                        <input type="checkbox" value="1" <?php 
        checked(1 == $this->_settings['autorefresh']);
        ?>
                               name="autorefresh"/>
                        <label for="autorefresh">Autorefresh</label>
                        <select name="display">
                            <option <?php 
        selected('fifo' == $this->_settings['display']);
        ?>
 value="fifo">FIFO</option>
                            <option <?php 
        selected('filo' == $this->_settings['display']);
        ?>
 value="filo">FILO</option>
                        </select>
                        <?php 
        submit_button(__('Apply'), 'button', 'Apply', false);
        ?>
                    </form>
                </div>
            </div>

        </div>
        <div id="templateside">
            <h3>Log Files</h3>
            <ul>
                <?php 
        foreach ($files as $file) {
            if ($this->_currentFile === $file) {
                ?>
                        <li class="highlight">
                    <?php 
            } else {
                ?>
                        <li>
                    <?php 
            }
            ?>
                    <a href="<?php 
            printf("%s&file=%s", $this->getPageUrl(), $file);
            ?>
">
                        <?php 
            echo $file;
            ?>
                    </a>
                    </li>
                <?php 
        }
        ?>
            </ul>
        </div>
        <div id="template">
            <div>
                <?php 
        if (!is_file($realfile)) {
            ?>
                    <div id="message" class="error">
                        <p><?php 
            _e('Could not load file.');
            ?>
</p>
                    </div>
                <?php 
        } else {
            ?>
                    <textarea id="newcontent" name="newcontent" rows="25" cols="70"
                              readonly="readonly"><?php 
            echo $this->_getCurrentFileContent();
            ?>
</textarea>
                <?php 
        }
        ?>
                <div>
                    <h3><?php 
        _e('Fileinfo');
        ?>
</h3>
                    <dl>
                        <dt><?php 
        _e('Fullpath:');
        ?>
</dt>
                        <dd><?php 
        echo $realfile;
        ?>
</dd>
                        <dt><?php 
        _e('Last updated: ');
        ?>
</dt>
                        <dd><?php 
        echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), filemtime($realfile));
        ?>
</dd>
                    </dl>
                </div>
            </div>
        </div>
        <?php 
        $this->_draw_footer();
    }