public static function getValue($key, $entities = false) { $value = false; global $wpdb; $settingsTable = WPEditor::getTableName('settings'); $value = $wpdb->get_var("SELECT `value` from {$settingsTable} where `key`='{$key}'"); if (!empty($value) && $entities) { $value = htmlentities($value); } return $value; }
<?php if (!defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN')) { exit; } define('WPEDITOR_PATH', plugin_dir_path(__FILE__)); // e.g. /var/www/example.com/wordpress/wp-content/plugins/wpeditor require_once WPEDITOR_PATH . 'classes/WPEditor.php'; require_once WPEDITOR_PATH . 'classes/WPEditorSetting.php'; //if(WPEditorSetting::getValue('uninstall_db')) { global $wpdb; $prefix = WPEditor::getTablePrefix(); $sqlFile = WPEDITOR_PATH . 'sql/uninstall.sql'; $sql = str_replace('[prefix]', $prefix, file_get_contents($sqlFile)); $queries = explode(";\n", $sql); foreach ($queries as $sql) { if (strlen($sql) > 5) { $wpdb->query($sql); } } //}
public static function addSettingsPage() { $view = WPEditor::getView('views/settings.php'); echo $view; }
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); }
public static function getTableName($name) { return WPEditor::getTablePrefix() . $name; }
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); }