static function plugin_editor()
 {
     check_ajax_referer('sns_plugin_editor');
     if (!current_user_can('edit_plugins')) {
         exit('Insufficient Privileges.');
     }
     $active = false;
     $plugin = '';
     $debug = array();
     $need_update = false;
     $plugins = array_keys(get_plugins());
     $file = $_REQUEST['file'];
     $short = substr($file, 0, strpos($file, '/'));
     if (!in_array($file, $plugins)) {
         $need_update = true;
         if (in_array($_REQUEST['plugin'], $plugins)) {
             $plugin = $_REQUEST['plugin'];
         } else {
             foreach ($plugins as $maybe) {
                 if (false !== strpos($maybe, $short)) {
                     $plugin = $maybe;
                     break;
                 }
             }
         }
     } else {
         $plugin = $file;
         while (1 < substr_count($plugin, "/")) {
             $plugin = dirname($plugin);
         }
     }
     $active = is_plugin_active($plugin) || is_plugin_active_for_network($plugin);
     $files = get_plugin_files($plugin);
     add_filter('editable_extensions', array('SnS_Admin_Code_Editor', 'extend'));
     $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
     $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
     $ul = '';
     foreach ($files as $plugin_file) {
         // Get the extension of the file
         if (preg_match('/\\.([^.]+)$/', $plugin_file, $matches)) {
             $ext = strtolower($matches[1]);
             // If extension is not in the acceptable list, skip it
             if (!in_array($ext, $editable_extensions)) {
                 continue;
             }
         } else {
             // No extension found
             continue;
         }
         $ul .= '<li';
         $ul .= $file == $plugin_file ? ' class="highlight">' : '>';
         $ul .= '<a href="plugin-editor.php?file=' . urlencode($plugin_file) . '&amp;plugin=' . urlencode($plugin) . '">';
         $ul .= str_replace($short . '/', '', $plugin_file);
         $ul .= '</a>';
         $ul .= '</li>';
     }
     header('Content-Type: application/json; charset=UTF-8');
     echo json_encode(array("plugin" => $plugin, "active" => $active, "files" => $files, "need_update" => $need_update, "ul" => $ul));
     exit;
 }
Esempio n. 2
0
$title = __("Edit Plugins");
$parent_file = 'plugins.php';
wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
wp_admin_css('theme-editor');
$plugins = get_plugins();
if (empty($plugins)) {
    wp_die(__('There are no plugins installed on this site.'));
}
if (isset($_REQUEST['file'])) {
    $plugin = stripslashes($_REQUEST['file']);
}
if (empty($plugin)) {
    $plugin = array_keys($plugins);
    $plugin = $plugin[0];
}
$plugin_files = get_plugin_files($plugin);
if (empty($file)) {
    $file = $plugin_files[0];
} else {
    $file = stripslashes($file);
}
$file = validate_file_to_edit($file, $plugin_files);
$real_file = WP_PLUGIN_DIR . '/' . $file;
$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
switch ($action) {
    case 'update':
        check_admin_referer('edit-plugin_' . $file);
        $newcontent = stripslashes($_POST['newcontent']);
        if (is_writeable($real_file)) {
            $f = fopen($real_file, 'w+');
            fwrite($f, $newcontent);
 /**
  * @covers ::get_plugin_files
  */
 public function test_get_plugin_files_single()
 {
     $name = 'hello.php';
     $this->assertEquals(array($name), get_plugin_files($name));
 }
Esempio n. 4
0
function hmdev_phpunit_load_all_test_files()
{
    if (!empty($_POST['tests'])) {
        foreach ((array) $_POST['tests'] as $test_file) {
            if (strpos($test_file, '.php')) {
                include_once WP_PLUGIN_DIR . '/' . $test_file;
            } else {
                $files = wptest_get_all_test_files(WP_PLUGIN_DIR . '/' . $test_file);
                foreach ($files as $file) {
                    require_once $file;
                }
            }
        }
    } else {
        $plugins = get_plugins();
        foreach ($plugins as $plugin_path => $plugin) {
            if (is_plugin_active($plugin_path)) {
                foreach (get_plugin_files($plugin_path) as $file) {
                    if (strpos($file, '/tests/') && end(explode('.', $file)) == 'php') {
                        include_once WP_PLUGIN_DIR . '/' . $file;
                    }
                }
            }
        }
        if (is_dir(get_template_directory() . '/tests/')) {
            foreach (glob(get_template_directory() . '/tests/*.php') as $file) {
                include_once $file;
            }
        }
        if (is_dir(WPMU_PLUGIN_DIR)) {
            foreach (glob(WPMU_PLUGIN_DIR . '/*/tests/*.php') as $file) {
                include_once $file;
            }
        }
    }
}
Esempio n. 5
0
function pgc_scanPluginsForDbTablesUse(&$tables)
{
    update_option('pgc_scanprogress_current', 1);
    update_option('pgc_scanprogress_status', 'Start scanning...');
    $plugins_list = get_plugins();
    update_option('pgc_scanprogress_total', count($plugins_list));
    $i = 1;
    foreach ($plugins_list as $key => $plugin) {
        $i++;
        update_option('pgc_scanprogress_current', $i);
        update_option('pgc_scanprogress_status', $plugin['Title']);
        $plugin_files = get_plugin_files($key);
        foreach ($plugin_files as $plugin_file) {
            $ext = pathinfo($plugin_file, PATHINFO_EXTENSION);
            if ($ext == 'php' || $ext == 'PHP') {
                $fh = fopen(WP_PLUGIN_DIR . '/' . $plugin_file, 'r');
                if (!$fh) {
                    continue;
                }
                while (!feof($fh)) {
                    $s = fgets($fh);
                    $s = strtolower($s);
                    foreach ($tables as $table) {
                        if (!$table->plugin_name && strpos($s, $table->name_without_prefix) !== false) {
                            $table->plugin_name = $plugin['Title'] . ' ' . $plugin['Version'];
                            $table->plugin_file = $key;
                        }
                    }
                }
                fclose($fh);
            }
        }
    }
    $active_plugins = get_option('active_plugins');
    foreach ($tables as $table) {
        if ($table->plugin_file) {
            $pluginActive = false;
            foreach ($active_plugins as $active_plugin) {
                if ($table->plugin_file == $active_plugin) {
                    $pluginActive = true;
                    break;
                }
            }
            if ($pluginActive) {
                $table->plugin_state = 'active';
            } else {
                $table->plugin_state = 'deactivated';
            }
        } else {
            $table->plugin_state = 'deleted?';
        }
        $table->plugin_state = $table->plugin_state;
    }
    delete_option('pgc_scanprogress_current');
    delete_option('pgc_scanprogress_total');
    delete_option('pgc_scanprogress_status');
}