Beispiel #1
0
 public function admin_init()
 {
     if (!empty($_GET['developer_plugin_reset']) && current_user_can('manage_options')) {
         delete_option(self::OPTION);
     }
     $this->recommended_plugins = array('debug-bar' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar', 'a8c-developer'), 'active' => class_exists('Debug_Bar')), 'debug-bar-console' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar Console', 'a8c-developer'), 'active' => function_exists('debug_bar_console_panel')), 'debug-bar-cron' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar Cron', 'a8c-developer'), 'active' => function_exists('zt_add_debug_bar_cron_panel')), 'debug-bar-extender' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar Extender', 'a8c-developer'), 'active' => class_exists('Debug_Bar_Extender')), 'rewrite-rules-inspector' => array('project_type' => 'all', 'name' => esc_html__('Rewrite Rules Inspector', 'a8c-developer'), 'active' => class_exists('Rewrite_Rules_Inspector')), 'log-deprecated-notices' => array('project_type' => 'all', 'name' => esc_html__('Log Deprecated Notices', 'a8c-developer'), 'active' => class_exists('Deprecated_Log')), 'log-viewer' => array('project_type' => 'all', 'name' => esc_html__('Log Viewer', 'a8c-developer'), 'active' => class_exists('ciLogViewer')), 'vip-scanner' => array('project_type' => 'wpcom-vip', 'name' => esc_html__('VIP Scanner', 'a8c-developer'), 'active' => class_exists('VIP_Scanner')), 'jetpack' => array('project_type' => 'wpcom-vip', 'name' => esc_html__('Jetpack', 'a8c-developer'), 'active' => class_exists('Jetpack')), 'polldaddy' => array('project_type' => 'wpcom-vip', 'name' => esc_html__('Polldaddy Polls & Ratings', 'a8c-developer'), 'active' => class_exists('WP_Polldaddy')), 'monster-widget' => array('project_type' => 'all', 'name' => esc_html__('Monster Widget', 'a8c-developer'), 'active' => class_exists('Monster_Widget')), 'user-switching' => array('project_type' => 'all', 'name' => esc_html__('User Switching', 'a8c-developer'), 'active' => class_exists('user_switching')), 'piglatin' => array('project_type' => array('wporg-theme', 'wporg'), 'name' => esc_html__('Pig Latin', 'a8c-developer'), 'active' => class_exists('PigLatin')), 'rtl-tester' => array('project_type' => 'wporg-theme', 'name' => esc_html__('RTL Tester', 'a8c-developer'), 'active' => class_exists('RTLTester')), 'regenerate-thumbnails' => array('project_type' => 'wporg-theme', 'name' => esc_html__('Regenerate Thumbnails', 'a8c-developer'), 'active' => class_exists('RegenerateThumbnails')), 'simply-show-ids' => array('project_type' => 'wporg-theme', 'name' => esc_html__('Simply Show IDs', 'a8c-developer'), 'active' => function_exists('ssid_add')), 'theme-test-drive' => array('project_type' => 'wporg-theme', 'name' => esc_html__('Theme Test Drive', 'a8c-developer'), 'active' => function_exists('TTD_filters'), 'filename' => 'themedrive.php'), 'theme-check' => array('project_type' => 'wporg-theme', 'name' => esc_html__('Theme Check', 'a8c-developer'), 'active' => function_exists('tc_add_headers')));
     if (!self::is_dev_version()) {
         $this->recommended_plugins['wordpress-beta-tester'] = array('project_type' => 'all', 'name' => esc_html__('Beta Tester', 'a8c-developer'), 'active' => class_exists('wp_beta_tester'), 'filename' => 'wp-beta-tester.php');
     }
     $this->recommended_constants = array('WP_DEBUG' => array('project_type' => 'all', 'description' => __('Enables <a href="http://codex.wordpress.org/Debugging_in_WordPress" target="_blank">debug mode</a> which helps identify and resolve issues', 'a8c-developer')), 'SAVEQUERIES' => array('project_type' => 'all', 'description' => esc_html__('Logs database queries to an array so you can review them. The Debug Bar plugin will list out database queries if you set this constant.', 'a8c-developer')), 'JETPACK_DEV_DEBUG' => array('project_type' => 'wpcom-vip', 'description' => __('Enables <a href="http://jetpack.me/2013/03/28/jetpack-dev-mode-release/">Development Mode</a> in Jetpack for testing features without a connection to WordPress.com.', 'a8c-developer')));
     register_setting(self::OPTION, self::OPTION, array($this, 'settings_validate'));
     wp_register_script('a8c-developer', plugins_url('developer.js', __FILE__), array('jquery'), self::VERSION);
     $strings = array('settings_slug' => self::PAGE_SLUG, 'go_to_step_2' => current_user_can('install_plugins') && current_user_can('activate_plugins') && 'direct' == get_filesystem_method() ? 'yes' : 'no', 'lightbox_title' => __('Developer: Plugin Setup', 'a8c-developer'), 'saving' => __('Saving...', 'a8c-developer'), 'installing' => '<img src="images/loading.gif" alt="" /> ' . esc_html__('Installing...', 'a8c-developer'), 'installed' => __('Installed', 'a8c-developer'), 'activating' => '<img src="images/loading.gif" alt="" /> ' . esc_html__('Activating...', 'a8c-developer'), 'activated' => __('Activated', 'a8c-developer'), 'error' => __('Error!', 'a8c-developer'), 'ACTIVE' => __('ACTIVE', 'a8c-developer'), 'INSTALLED' => __('INSTALLED', 'a8c-developer'), 'ERROR' => __('ERROR!', 'a8c-developer'));
     wp_localize_script('a8c-developer', 'a8c_developer_i18n', $strings);
     wp_register_style('a8c-developer', plugins_url('developer.css', __FILE__), array(), self::VERSION);
     // Handle the submission of the lightbox form if step 2 won't be shown
     if (!empty($_POST['action']) && 'a8c_developer_lightbox_step_1' == $_POST['action'] && !empty($_POST['a8c_developer_project_type']) && check_admin_referer('a8c_developer_lightbox_step_1')) {
         $this->save_project_type($_POST['a8c_developer_project_type']);
         add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
     }
     if (!get_option(self::OPTION)) {
         if (!empty($_GET['a8cdev_errorsaving'])) {
             add_settings_error(self::PAGE_SLUG, self::PAGE_SLUG . '_error_saving', __('Error saving settings. Please try again.', 'a8c-developer'));
         } elseif (!is_network_admin() && current_user_can('manage_options')) {
             add_action('admin_enqueue_scripts', array($this, 'load_lightbox_scripts_and_styles'));
             add_action('admin_footer', array($this, 'output_setup_box_html'));
         }
     }
 }
Beispiel #2
0
 public function admin_init()
 {
     $this->recommended_plugins = array('debug-bar' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar', 'a8c-developer'), 'active' => class_exists('Debug_Bar')), 'debug-bar-cron' => array('project_type' => 'all', 'name' => esc_html__('Debug Bar Cron', 'a8c-developer'), 'active' => function_exists('zt_add_debug_bar_cron_panel')), 'rewrite-rules-inspector' => array('project_type' => 'all', 'name' => esc_html__('Rewrite Rules Inspector', 'a8c-developer'), 'active' => class_exists('Rewrite_Rules_Inspector')), 'log-deprecated-notices' => array('project_type' => 'all', 'name' => esc_html__('Log Deprecated Notices', 'a8c-developer'), 'active' => class_exists('Deprecated_Log')), 'vip-scanner' => array('project_type' => 'all', 'name' => esc_html__('VIP Scanner', 'a8c-developer'), 'active' => class_exists('VIP_Scanner')), 'grunion-contact-form' => array('project_type' => 'wpcom-vip', 'name' => esc_html__('Grunion Contact Form', 'a8c-developer'), 'active' => defined('GRUNION_PLUGIN_DIR')), 'polldaddy' => array('project_type' => 'wpcom-vip', 'name' => esc_html__('Polldaddy Polls & Ratings', 'a8c-developer'), 'active' => class_exists('WP_Polldaddy')), 'monster-widget' => array('project_type' => 'all', 'name' => esc_html__('Monster Widget', 'a8c-developer'), 'active' => class_exists('Monster_Widget')), 'wordpress-beta-tester' => array('project_type' => 'all', 'name' => esc_html__('Beta Tester', 'a8c-developer'), 'active' => class_exists('wp_beta_tester'), 'filename' => 'wp-beta-tester.php'));
     $this->recommended_constants = array('WP_DEBUG' => __('Enables <a href="http://codex.wordpress.org/Debugging_in_WordPress" target="_blank">debug mode</a> which helps identify and resolve issues', 'a8c-developer'), 'SAVEQUERIES' => esc_html__('Logs database queries to an array so you can review them. The Debug Bar plugin will list out database queries if you set this constant.', 'a8c-developer'));
     register_setting(self::OPTION, self::OPTION, array($this, 'settings_validate'));
     wp_register_script('a8c-developer', plugins_url('developer.js', __FILE__), array('jquery'), self::VERSION);
     $strings = array('settings_slug' => self::PAGE_SLUG, 'go_to_step_2' => current_user_can('install_plugins') && current_user_can('activate_plugins') && 'direct' == get_filesystem_method() ? 'yes' : 'no', 'lightbox_title' => __('Developer: Plugin Setup', 'a8c-developer'), 'saving' => __('Saving...', 'a8c-developer'), 'installing' => '<img src="images/loading.gif" alt="" /> ' . esc_html__('Installing...', 'a8c-developer'), 'installed' => __('Installed', 'a8c-developer'), 'activating' => '<img src="images/loading.gif" alt="" /> ' . esc_html__('Activating...', 'a8c-developer'), 'activated' => __('Activated', 'a8c-developer'), 'error' => __('Error!', 'a8c-developer'), 'ACTIVE' => __('ACTIVE', 'a8c-developer'), 'INSTALLED' => __('INSTALLED', 'a8c-developer'), 'ERROR' => __('ERROR!', 'a8c-developer'));
     wp_localize_script('a8c-developer', 'a8c_developer_i18n', $strings);
     wp_register_style('a8c-developer', plugins_url('developer.css', __FILE__), array(), self::VERSION);
     // Handle the submission of the lightbox form if step 2 won't be shown
     if (!empty($_POST['a8c_developer_action'])) {
         if ('lightbox_step_1' == $_POST['a8c_developer_action'] && !empty($_POST['a8c_developer_project_type']) && check_admin_referer('a8c_developer_action_lightbox_step_1')) {
             $this->save_project_type($_POST['a8c_developer_project_type']);
             add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
         }
     }
     if (!get_option(self::OPTION)) {
         if (!empty($_GET['a8cdev_errorsaving'])) {
             add_settings_error(self::PAGE_SLUG, self::PAGE_SLUG . '_error_saving', __('Error saving settings. Please try again.', 'a8c-developer'));
         } elseif (current_user_can('manage_options')) {
             add_action('admin_enqueue_scripts', array($this, 'load_lightbox_scripts_and_styles'));
             add_action('admin_footer', array($this, 'output_setup_box_html'));
         }
     }
 }
Beispiel #3
0
 public function install_branch()
 {
     include_once ABSPATH . '/wp-admin/includes/file.php';
     if (get_filesystem_method() === 'direct' && !is_dir(WP_CONTENT_DIR . '/thesis') && is_dir(THESIS_SKINS)) {
         // first, set up wp_filesystem
         WP_Filesystem();
         $f = $GLOBALS['wp_filesystem'];
         // directories
         $directories = array('thesis/', 'thesis/boxes/', 'thesis/packages/', 'thesis/skins/');
         foreach ($directories as $dir) {
             $f->mkdir($f->wp_content_dir() . $dir);
         }
         // master.php
         $f->put_contents($f->wp_content_dir() . 'thesis/master.php', "<?php\n// This is the Thesis master.php file.\n// Use this file to affect every site on your network.\n// Note: this is the last file included in Thesis!\n");
         // move skins
         $from = trailingslashit($f->find_folder(THESIS_SKINS));
         $to = $f->wp_content_dir() . 'thesis/skins/';
         $skins = array_keys($f->dirlist($from));
         foreach ($skins as $skin) {
             $f->move($from . $skin, $to . $skin);
             if (!$f->exists($to . $skin . '/images')) {
                 $f->mkdir($to . $skin . '/images');
             }
             if (!$f->exists($to . $skin . '/custom.php')) {
                 $f->put_contents($to . $skin . '/custom.php', "<?php\n/*\n\tThis file is for skin specific customizations. Be careful not to change your skin's skin.php file as that will be upgraded in the future and your work will be lost.\n\tIf you are more comfortable with PHP, we recommend using the super powerful Thesis Box system to create elements that you can interact with in the Thesis HTML Editor.\n*/");
             }
         }
         // clean up
         if (($lib = array_keys($f->dirlist(THESIS_SKINS))) && empty($lib)) {
             $f->delete(THESIS_SKINS);
         }
     }
 }
 function render()
 {
     $css = $this->ctc()->css;
     $themes = $this->ctc()->themes;
     $child = $css->get_prop('child');
     $hidechild = count($themes['child']) ? '' : 'style="display:none"';
     $enqueueset = isset($css->enqueue) && $child;
     $this->ctc()->debug('Enqueue set: ' . ($enqueueset ? 'TRUE' : 'FALSE'), __FUNCTION__);
     if (empty($css->nowarn)) {
         $this->parent_theme_check();
     }
     $imports = $css->get_prop('imports');
     $id = 0;
     $this->ctc()->fs_method = get_filesystem_method();
     add_thickbox();
     add_filter('chld_thm_cfg_files_tab_filter', array($this, 'render_files_tab_options'));
     add_action('chld_thm_cfg_tabs', array($this, 'render_addl_tabs'), 10, 4);
     add_action('chld_thm_cfg_panels', array($this, 'render_addl_panels'), 10, 4);
     add_action('chld_thm_cfg_related_links', array($this, 'lilaea_plug'));
     if ($this->ctc()->is_debug) {
         $this->ctc()->debug('adding new debug action...', __FUNCTION__);
         add_action('chld_thm_cfg_print_debug', array($this->ctc(), 'print_debug'));
     }
     include CHLD_THM_CFG_DIR . '/includes/forms/main.php';
 }
Beispiel #5
0
 function is_server_writable()
 {
     if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && get_filesystem_method(array(), ABSPATH) != 'direct') {
         return false;
     } else {
         return true;
     }
 }
/**
 * Check custom css directory
 */
function pre_check_custom_css_writable()
{
    // custom css directory
    $the_dir = get_template_directory() . "/lib/css";
    if (!get_filesystem_method(array(), $the_dir) == "direct") {
        add_action("admin_notices", "pre_notice_custom_css_permission");
    }
}
 public static function check_filesystem_api()
 {
     global $gfpdfe_data;
     $access_type = get_filesystem_method();
     $gfpdfe_data->automated = false;
     if ($access_type === 'direct') {
         $gfpdfe_data->automated = true;
     }
 }
 private function get_creds()
 {
     $access_type = get_filesystem_method();
     if ($access_type === 'direct') {
         $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, array());
     } else {
         $creds = $this->get_ftp_creds($access_type);
     }
     return $creds;
 }
 public function __construct()
 {
     require_once ABSPATH . 'wp-admin/includes/file.php';
     $upload_dir = wp_upload_dir();
     if (get_filesystem_method(array(), $upload_dir['basedir']) !== 'direct' || !WP_Filesystem(request_filesystem_credentials(admin_url()))) {
         self::$useFS = false;
         add_action('wp_ajax_wpservefile', array($this, 'serve_file'));
         add_action('wp_ajax_nopriv_wpservefile', array($this, 'serve_file'));
     } else {
         self::$useFS = true;
     }
 }
 function can_write_files()
 {
     $access_type = get_filesystem_method();
     ob_start();
     $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, null);
     $_c = ob_get_clean();
     if ($access_type === 'direct' || WP_Filesystem($creds)) {
         return true;
     }
     $this->errors[] = "WordPress does not have access to it's own file system!";
     $this->consequences[] = "Images, CSS Files, Cache Files will be included with an alternative inline method, which is slower.";
     $this->solutions[] = "\r\n        <ol>\r\n        <li>\r\n        You will have to fill in FTP credentials into the wp-config.php file.<br><br>\r\n        <strong>define( 'FTP_USER', 'username' );<br>\r\n        define( 'FTP_PASS', 'password' );<br>\r\n        define( 'FTP_HOST', 'ftp.example.org' );</strong> <br><br>\r\n        In some cases more constants might be required. <br>\r\n        Please read: <a href='https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants'>WordPress Upgrage Constants</a> \r\n        </li>\r\n        <li>\r\n        ADVANCED USERS ONLY!<br><br>\r\n        Change ownership of the WordPress directory and all of its contents via SSH for the <strong>www-data</strong> process.<br><br>\r\n        \r\n        <a href='http://stackoverflow.com/questions/18352682/correct-file-permissions-for-wordpress'>Changing Ownership if WordPress is in the ROOT directory</a>\r\n        </li>\r\n        </ol>";
     return false;
 }
 function update_theme()
 {
     if (isset($_REQUEST['page'])) {
         // Sanitize page being requested.
         $_page = esc_attr($_REQUEST['page']);
         if ('spyropress-update' == $_page) {
             //Setup Filesystem
             $method = get_filesystem_method();
             if (isset($_POST['spyropress_ftp_cred'])) {
                 $cred = spyropress_decode($_POST['spyropress_ftp_cred']);
                 $filesystem = WP_Filesystem($cred);
             } else {
                 $filesystem = WP_Filesystem();
             }
             if (false == $filesystem && 'Proceed' != $_POST['upgrade']) {
                 add_error_message(sprintf(__('Failed: Filesystem preventing downloads. (%s)', 'spyropress'), $method));
                 return;
             }
             if (isset($_REQUEST['spyropress_updater'])) {
                 // Sanitize action being requested.
                 $_action = esc_attr($_REQUEST['spyropress_updater']);
                 if ('framework' == $_action) {
                     locate_template('framework/utilities/envato/class-envato-wordpress-theme-upgrader.php', true);
                     $envato_api_key = get_option('_spyropress_envato_api_key_' . get_internal_name());
                     $envato_username = get_option('_spyropress_envato_username_' . get_internal_name());
                     $upgrader = new Envato_WordPress_Theme_Upgrader($envato_username, $envato_api_key);
                     $result = $upgrader->upgrade_theme();
                     // Successfully Updated
                     if ($result->success) {
                         $message = __('New version successfully downloaded, extracted and updated.', 'spyropress');
                         $message .= '<script type="text/javascript">
                             //<![CDATA[
                                 window.location.replace("' . admin_url('admin.php?page=spyropress-update') . '");
                             //]]>
                         </script>';
                         add_success_message($message);
                     } else {
                         add_error_message($result->errors[0]);
                     }
                 }
             }
         }
         // END UPDATE HERE
     }
 }
 /**
  * Returns true if the site has file write access false otherwise.
  * @return string ( '1' | '0' )
  **/
 public static function file_system_write_access()
 {
     if (!function_exists('get_filesystem_method')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     require_once ABSPATH . 'wp-admin/includes/template.php';
     $filesystem_method = get_filesystem_method();
     if ($filesystem_method === 'direct') {
         return 1;
     }
     ob_start();
     $filesystem_credentials_are_stored = request_filesystem_credentials(self_admin_url());
     ob_end_clean();
     if ($filesystem_credentials_are_stored) {
         return 1;
     }
     return 0;
 }
Beispiel #13
0
 function vstrsnln_insert_rows($number_file = false, $noscript = false)
 {
     global $wpdb, $wp_filesystem;
     if (false == $noscript) {
         check_ajax_referer('bws_plugin', 'vstrsnln_ajax_nonce_field');
     }
     $prefix_bws = $wpdb->base_prefix . 'bws_';
     $vstrsnln_access_type = get_filesystem_method();
     if ($vstrsnln_access_type == 'direct') {
         $vstrsnln_creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, array());
         if (!WP_Filesystem($vstrsnln_creds)) {
             if ($number_file == false) {
                 echo false;
             } else {
                 return false;
             }
         }
         if ($number_file == false) {
             if (isset($_POST['count']) && file_exists(plugin_dir_path(__FILE__) . 'file_' . $_POST['count'] . '.csv')) {
                 $filename = plugin_dir_path(__FILE__) . 'file_' . $_POST['count'] . '.csv';
                 $data_array = $wp_filesystem->get_contents_array($filename);
                 if (false !== $data_array && is_array($data_array) && !empty($data_array)) {
                     $sql = "INSERT IGNORE INTO `" . $prefix_bws . "country`\n                            ( `ip_from`, `ip_to`, `ip_from_int`, `ip_to_int`, `short_country`, `name_country` )\n                            VALUES ( " . implode(" ) , ( ", $data_array) . " );";
                     $result = $wpdb->query($sql);
                     unlink($filename);
                     echo $result;
                 }
             }
         } else {
             if ($number_file > 0 && file_exists(plugin_dir_path(__FILE__) . 'file_' . $number_file . '.csv')) {
                 $filename = plugin_dir_path(__FILE__) . 'file_' . $number_file . '.csv';
                 $data_array = $wp_filesystem->get_contents_array($filename);
                 if (false !== $data_array && is_array($data_array) && !empty($data_array)) {
                     $sql = "INSERT IGNORE INTO `" . $prefix_bws . "country`\n                            ( `ip_from`, `ip_to`, `ip_from_int`, `ip_to_int`, `short_country`, `name_country` )\n                            VALUES ( " . implode(" ) , ( ", $data_array) . " );";
                     $result = $wpdb->query($sql);
                     unlink($filename);
                     return $result;
                 }
             }
         }
     }
     /* This is required to terminate immediately and return a proper response */
     wp_die();
 }
Beispiel #14
0
 /**
  * @return WP_Filesystem_Direct
  */
 private function _getFileSystem()
 {
     if (!function_exists('get_filesystem_method')) {
         require_once ABSPATH . '/wp-admin/includes/file.php';
         $fileSystem = WP_Filesystem();
     } else {
         global $wp_filesystem;
         $fileSystem = $wp_filesystem;
     }
     $method = get_filesystem_method();
     if ($method != 'direct') {
         $notificationText = __('Fresh Framework requires File System Direct to install itself. If you cant achieve this, ', 'zero');
         $notificationText .= _('please install Fresh Framework plugin, otherwise our theme will not work<br><br>', 'zero');
         $notificationText .= __('Plugin could be found here: ', 'zero') . get_template_directory() . '/install/fresh-framework.zip';
         $this->_addNotification($notificationText);
         return false;
     }
     return $fileSystem;
 }
Beispiel #15
0
 function render()
 {
     // load web fonts for this theme
     if ($imports = $this->css()->get_prop('imports')) {
         $ext = 0;
         foreach ($imports as $import) {
             $this->ctc()->convert_import_to_enqueue($import, ++$ext, TRUE);
         }
     }
     $themes = $this->ctc()->themes;
     $child = $this->css()->get_prop('child');
     $hidechild = apply_filters('chld_thm_cfg_hidechild', count($themes['child']) ? '' : 'style="display:none"');
     $enqueueset = isset($this->css()->enqueue) && $child;
     $this->ctc()->debug('Enqueue set: ' . ($enqueueset ? 'TRUE' : 'FALSE'), __FUNCTION__, __CLASS__);
     $imports = $this->css()->get_prop('imports');
     $id = 0;
     $this->ctc()->fs_method = get_filesystem_method();
     add_thickbox();
     include CHLD_THM_CFG_DIR . '/includes/forms/main.php';
 }
Beispiel #16
0
 /**
  * Sets up the filesystem to be able to write to the server.
  *
  * If filesystem credentials are required and haven't been entered yet,
  * a form to enter them will be shown and the request will exit afterwards.
  *
  * @since 1.0.0
  * @access public
  * @static
  *
  * @param string $form_post    The location to post the form to.
  * @param array  $extra_fields Additional fields to include in the form post request.
  * @return bool True if the filesystem was setup successfully, false otherwise.
  */
 public static function setup_filesystem($form_post, $extra_fields = array())
 {
     global $wp_filesystem;
     $paths = self::get_filesystem_paths();
     $type = 'direct';
     $is_direct = true;
     foreach ($paths as $key => $path) {
         $type = get_filesystem_method(array(), $paths[$key], true);
         if ('direct' !== $type) {
             $is_direct = false;
             break;
         }
     }
     ob_start();
     if (false === ($credentials = request_filesystem_credentials($form_post, $type, false, $paths[0], $extra_fields, true))) {
         $data = ob_get_clean();
         if (!empty($data)) {
             include_once ABSPATH . 'wp-admin/admin-header.php';
             echo $data;
             include ABSPATH . 'wp-admin/admin-footer.php';
             exit;
         }
         return false;
     }
     if (!WP_Filesystem($credentials, $paths[0], true)) {
         $error = isset($wp_filesystem) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ? $wp_filesystem->errors : true;
         request_filesystem_credentials($form_post, $type, $error, $paths[0], $extra_fields, true);
         $data = ob_get_clean();
         if (!empty($data)) {
             include_once ABSPATH . 'wp-admin/admin-header.php';
             echo $data;
             include ABSPATH . 'wp-admin/admin-footer.php';
             exit;
         }
         return false;
     }
     if (!is_object($wp_filesystem) || is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
         return false;
     }
     return true;
 }
 /**
  * Request WP Filesystem access
  * @param string $context
  * @param string $url
  * @param array $extra_fields
  * @return bool
  */
 public static final function request_access($context, $url, $extra_fields = array())
 {
     if (get_filesystem_method() === 'direct') {
         // in case if direct access is available
         /* you can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
         $creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, null);
         /* initialize the API */
         if (!WP_Filesystem($creds)) {
             /* any problems and we exit */
             trigger_error(__('Cannot connect to Filesystem directly', 'fw'), E_USER_WARNING);
             return false;
         }
     } else {
         $creds = request_filesystem_credentials($url, '', false, $context, $extra_fields);
         if (!$creds) {
             // the form was printed to the user
             return false;
         }
         /* initialize the API */
         if (!WP_Filesystem($creds)) {
             /* any problems and we exit */
             request_filesystem_credentials($url, '', true, $context, $extra_fields);
             // the third parameter is true to show error to the user
             return false;
         }
     }
     global $wp_filesystem;
     if (!is_object($wp_filesystem)) {
         return false;
     }
     if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
         return false;
     }
     if ($wp_filesystem->abspath() && $wp_filesystem->wp_content_dir() && $wp_filesystem->wp_plugins_dir() && $wp_filesystem->wp_themes_dir() && $wp_filesystem->find_folder($context)) {
         // ok
     } else {
         return false;
     }
     return true;
 }
Beispiel #18
0
    /**
     * Fix issue with WordPress FTP credential form stripping params from URL
     */
    function extension_ftp_fix()
    {
        // if no pl GET param then do nothing. Or if using direct fs
        if (!isset($_GET['pl']) || 'direct' == get_filesystem_method()) {
            return false;
        }
        // The WordPress FTP form strips our custom parameters for fetching the zip
        // So we need to add these back in.
        ?>
<script>
      ! function($) {
        $(document).ready(function(){
          var url = window.location.href
          var form = $('#request-filesystem-credentials-form')
          if( $(form).length ) {
            $(form).closest('form').attr('action',url)
          }
        })
      }(window.jQuery)
    </script>
    <?php 
    }
function uncode_init_admin_css()
{
    wp_enqueue_style('ot-admin', get_template_directory_uri() . '/core/theme-options/assets/css/ot-admin.css', false, UNCODE_VERSION);
    wp_enqueue_style('admin-uncode-icons', get_template_directory_uri() . '/library/css/uncode-icons.css', false, UNCODE_VERSION);
    global $wp_filesystem;
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    $access_type = get_filesystem_method();
    if ($access_type === 'direct') {
        wp_enqueue_style('custom-style', get_template_directory_uri() . '/core/assets/css/admin-custom.css', false, UNCODE_VERSION);
    } else {
        $styles = uncode_create_dynamic_css();
        wp_add_inline_style('ot-admin', uncode_compress_css_inline($styles['admin']));
    }
    $fonts = get_option('uncode_font_options');
    if (isset($fonts['font_stack']) && $fonts['font_stack'] !== '[]') {
        $upload_dir = wp_upload_dir();
        if (@file_exists(trailingslashit($upload_dir['basedir']) . 'uncode-fonts/uncodefont.css')) {
            wp_enqueue_style('uf-font-squirrel', $upload_dir['baseurl'] . '/uncode-fonts/uncodefont.css', false, UNCODE_VERSION);
        }
    }
}
Beispiel #20
0
/**
 * Print the filesystem credentials modal when needed.
 *
 * @since 4.2.0
 */
function wp_print_request_filesystem_credentials_modal() {
	$filesystem_method = get_filesystem_method();
	ob_start();
	$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
	ob_end_clean();
	$request_filesystem_credentials = ( $filesystem_method != 'direct' && ! $filesystem_credentials_are_stored );
	if ( ! $request_filesystem_credentials ) {
		return;
	}
	?>
	<div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
		<div class="notification-dialog-background"></div>
		<div class="notification-dialog" role="dialog" aria-labelledby="request-filesystem-credentials-title" tabindex="0">
			<div class="request-filesystem-credentials-dialog-content">
				<?php request_filesystem_credentials( site_url() ); ?>
			<div>
		</div>
	</div>
	<?php
}
/**
 * Displays a form to the user to request for their FTP/SSH details in order to  connect to the filesystem.
 * All chosen/entered details are saved, Excluding the Password.
 *
 * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port.
 *
 * Plugins may override this form by returning true|false via the <code>request_filesystem_credentials</code> filter.
 *
 * @since 2.5.0
 *
 * @param string $form_post the URL to post the form to
 * @param string $type the chosen Filesystem method in use
 * @param boolean $error if the current request has failed to connect
 * @param string $context The directory which is needed access to, The write-test will be performed on  this directory by get_filesystem_method()
 * @return boolean False on failure. True on success.
 */
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false)
{
    $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context);
    if ('' !== $req_cred) {
        return $req_cred;
    }
    if (empty($type)) {
        $type = get_filesystem_method(array(), $context);
    }
    if ('direct' == $type) {
        return true;
    }
    $credentials = get_option('ftp_credentials', array('hostname' => '', 'username' => ''));
    // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? stripslashes($_POST['hostname']) : $credentials['hostname']);
    $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? stripslashes($_POST['username']) : $credentials['username']);
    $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? stripslashes($_POST['password']) : '');
    // Check to see if we are setting the public/private keys for ssh
    $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? stripslashes($_POST['public_key']) : '');
    $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? stripslashes($_POST['private_key']) : '');
    //sanitize the hostname, Some people might pass in odd-data:
    $credentials['hostname'] = preg_replace('|\\w+://|', '', $credentials['hostname']);
    //Strip any schemes off
    if (strpos($credentials['hostname'], ':')) {
        list($credentials['hostname'], $credentials['port']) = explode(':', $credentials['hostname'], 2);
        if (!is_numeric($credentials['port'])) {
            unset($credentials['port']);
        }
    } else {
        unset($credentials['port']);
    }
    if (defined('FTP_SSH') && FTP_SSH || defined('FS_METHOD') && 'ssh' == FS_METHOD) {
        $credentials['connection_type'] = 'ssh';
    } else {
        if (defined('FTP_SSL') && FTP_SSL && 'ftpext' == $type) {
            //Only the FTP Extension understands SSL
            $credentials['connection_type'] = 'ftps';
        } else {
            if (!empty($_POST['connection_type'])) {
                $credentials['connection_type'] = stripslashes($_POST['connection_type']);
            } else {
                if (!isset($credentials['connection_type'])) {
                    //All else fails (And its not defaulted to something else saved), Default to FTP
                    $credentials['connection_type'] = 'ftp';
                }
            }
        }
    }
    if (!$error && (!empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) || 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']))) {
        $stored_credentials = $credentials;
        if (!empty($stored_credentials['port'])) {
            //save port as part of hostname to simplify above code.
            $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
        }
        unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
        update_option('ftp_credentials', $stored_credentials);
        return $credentials;
    }
    $hostname = '';
    $username = '';
    $password = '';
    $connection_type = '';
    if (!empty($credentials)) {
        extract($credentials, EXTR_OVERWRITE);
    }
    if ($error) {
        $error_string = __('<strong>Error:</strong> There was an error connecting to the server, Please verify the settings are correct.');
        if (is_wp_error($error)) {
            $error_string = $error->get_error_message();
        }
        echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    }
    $types = array();
    if (extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen')) {
        $types['ftp'] = __('FTP');
    }
    if (extension_loaded('ftp')) {
        //Only this supports FTPS
        $types['ftps'] = __('FTPS (SSL)');
    }
    if (extension_loaded('ssh2') && function_exists('stream_get_contents')) {
        $types['ssh'] = __('SSH2');
    }
    $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
    ?>
<script type="text/javascript">
<!--
jQuery(function($){
	jQuery("#ssh").click(function () {
		jQuery("#ssh_keys").show();
	});
	jQuery("#ftp, #ftps").click(function () {
		jQuery("#ssh_keys").hide();
	});
	jQuery('form input[value=""]:first').focus();
});
-->
</script>
<form action="<?php 
    echo $form_post;
    ?>
" method="post">
<div class="wrap">
<?php 
    screen_icon();
    ?>
<h2><?php 
    _e('Connection Information');
    ?>
</h2>
<p><?php 
    _e('To perform the requested action, connection information is required.');
    ?>
</p>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="hostname"><?php 
    _e('Hostname');
    ?>
</label></th>
<td><input name="hostname" type="text" id="hostname" value="<?php 
    echo esc_attr($hostname);
    if (!empty($port)) {
        echo ":{$port}";
    }
    ?>
"<?php 
    if (defined('FTP_HOST')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /></td>
</tr>

<tr valign="top">
<th scope="row"><label for="username"><?php 
    _e('Username');
    ?>
</label></th>
<td><input name="username" type="text" id="username" value="<?php 
    echo esc_attr($username);
    ?>
"<?php 
    if (defined('FTP_USER')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /></td>
</tr>

<tr valign="top">
<th scope="row"><label for="password"><?php 
    _e('Password');
    ?>
</label></th>
<td><input name="password" type="password" id="password" value="<?php 
    if (defined('FTP_PASS')) {
        echo '*****';
    }
    ?>
"<?php 
    if (defined('FTP_PASS')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /></td>
</tr>

<?php 
    if (isset($types['ssh'])) {
        ?>
<tr id="ssh_keys" valign="top" style="<?php 
        if ('ssh' != $connection_type) {
            echo 'display:none';
        }
        ?>
">
<th scope="row"><?php 
        _e('Authentication Keys');
        ?>
<div class="key-labels textright">
<label for="public_key"><?php 
        _e('Public Key:');
        ?>
</label ><br />
<label for="private_key"><?php 
        _e('Private Key:');
        ?>
</label>
</div></th>
<td><br /><input name="public_key" type="text" id="public_key" value="<?php 
        echo esc_attr($public_key);
        ?>
"<?php 
        if (defined('FTP_PUBKEY')) {
            echo ' disabled="disabled"';
        }
        ?>
 size="40" /><br /><input name="private_key" type="text" id="private_key" value="<?php 
        echo esc_attr($private_key);
        ?>
"<?php 
        if (defined('FTP_PRIKEY')) {
            echo ' disabled="disabled"';
        }
        ?>
 size="40" />
<div><?php 
        _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.');
        ?>
</div></td>
</tr>
<?php 
    }
    ?>

<tr valign="top">
<th scope="row"><?php 
    _e('Connection Type');
    ?>
</th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php 
    _e('Connection Type');
    ?>
</span></legend>
<?php 
    $disabled = defined('FTP_SSL') && FTP_SSL || defined('FTP_SSH') && FTP_SSH ? ' disabled="disabled"' : '';
    foreach ($types as $name => $text) {
        ?>
	<label for="<?php 
        echo esc_attr($name);
        ?>
">
		<input type="radio" name="connection_type" id="<?php 
        echo esc_attr($name);
        ?>
" value="<?php 
        echo esc_attr($name);
        ?>
" <?php 
        checked($name, $connection_type);
        echo $disabled;
        ?>
/>
		<?php 
        echo $text;
        ?>
	</label>
	<?php 
    }
    ?>
</fieldset>
</td>
</tr>
</table>

<?php 
    if (isset($_POST['version'])) {
        ?>
<input type="hidden" name="version" value="<?php 
        echo esc_attr(stripslashes($_POST['version']));
        ?>
" />
<?php 
    }
    if (isset($_POST['locale'])) {
        ?>
<input type="hidden" name="locale" value="<?php 
        echo esc_attr(stripslashes($_POST['locale']));
        ?>
" />
<?php 
    }
    ?>
<p class="submit">
<input id="upgrade" name="upgrade" type="submit" class="button" value="<?php 
    esc_attr_e('Proceed');
    ?>
" />
</p>
</div>
</form>
<?php 
    return false;
}
Beispiel #22
0
function bpsSetupWizardPrechecks()
{
    $successTextBegin = '<font color="green"><strong>';
    $successMessage = __(' DB Table created Successfully!', 'bulletproof-security');
    $successTextEnd = '</strong></font><br>';
    $failTextBegin = '<font color="red"><strong>';
    $failMessage = __('Error: Unable to create DB Table ', 'bulletproof-security');
    $failTextEnd = '</strong></font><br>';
    $sapi_type = php_sapi_name();
    echo '<h3>' . __('Setup Wizard Pre-Installation Checks:', 'bulletproof-security') . '</h3>
	<div style="font-size:12px;margin:-10px 0px 10px 0px;font-weight:bold;">' . __('If you see any Red font or Blue font messages displayed below, click the Read Me help button above and read the "Notes" help section before clicking the Setup Wizard button.', 'bulletproof-security') . '</div>';
    echo '<div id="Wizard-background" style="max-height:250px;width:85%;overflow:auto;margin:0px;padding:10px;border:2px solid black;background-color:#ffffe0;">';
    echo '<span class="setup-wizard-checks-text">';
    if (@substr($sapi_type, 0, 6) != 'apache' && get_filesystem_method() == 'direct') {
        echo $successTextBegin . __('Pass! Compatible Server Configuration: Server API: CGI | WP Filesystem API Method: direct.', 'bulletproof-security') . $successTextEnd;
    } elseif (@substr($sapi_type, 0, 6) == 'apache' && preg_match('#\\\\#', ABSPATH, $matches) && get_filesystem_method() == 'direct') {
        echo $successTextBegin . __('Pass! Compatible Server Configuration: Server Type Apache: XAMPP, WAMP, MAMP or LAMP | WP Filesystem API Method: direct.', 'bulletproof-security') . $successTextEnd;
    } elseif (@substr($sapi_type, 0, 6) == 'apache' && !preg_match('#\\\\#', ABSPATH, $matches) && get_filesystem_method() == 'direct') {
        echo $successTextBegin . __('Pass! Compatible Server Configuration: Server API: DSO | WP Filesystem API Method: direct.', 'bulletproof-security') . $successTextEnd;
    } elseif (@substr($sapi_type, 0, 6) == 'apache' && get_filesystem_method() != 'direct') {
        echo $failTextBegin . __('Server API: Apache DSO Server Configuration | WP Filesystem API Method: ', 'bulletproof-security') . get_filesystem_method() . $failTextEnd . '<br>' . __('Your Server type is DSO and the WP Filesystem API Method is NOT "direct". You can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a></strong><br><br>';
    }
    $memoryLimitM = get_cfg_var('memory_limit');
    $memoryLimit = str_replace('M', '', $memoryLimitM);
    if ($memoryLimit == '' || !$memoryLimitM) {
        echo '<strong><font color="blue">' . __('Unable to get the PHP Configuration Memory Limit value from the Server. It is recommended that your PHP Configuration Memory Limit is set to at least 128M. Contact your Web Host and ask them what your PHP Configuration Memory Limit is for your website.', 'bulletproof-security') . '</font></strong><br>';
    } else {
        switch ($memoryLimit) {
            case $memoryLimit >= '128':
                echo $successTextBegin . __('Pass! PHP Configuration Memory Limit is set to: ', 'bulletproof-security') . $memoryLimit . 'M' . $successTextEnd;
                break;
            case $memoryLimit >= '64' && $memoryLimit < '128':
                echo $successTextBegin . __('Pass! PHP Configuration Memory Limit is set to: ', 'bulletproof-security') . $memoryLimit . 'M. ' . __('It is recommended that you increase your memory limit to at least 128M. Contact your Web Host and ask them to increase your memory limit to the maximum memory limit setting allowed by your Host.', 'bulletproof-security') . $successTextEnd;
                break;
            case $memoryLimit > '0' && $memoryLimit < '64':
                echo '<br>' . $failTextBegin . __('Error: Your PHP Configuration Memory Limit is set to: ', 'bulletproof-security') . $memoryLimit . 'M. ' . __('WordPress needs a bare minimum Memory Limit setting of 64M to perform well. Contact your Web Host and ask them to increase your memory limit to the maximum memory limit setting allowed by your Host.', 'bulletproof-security') . $failTextEnd . '<br>';
                break;
        }
    }
    // PHP/php.ini htaccess code pre-check - Check if root .htaccess file has php.ini handler code and if that code has been added to BPS Custom Code
    bpsSetupWizardPhpiniHandlerCheck();
    // writable checks:
    // folders: /bps-backup/ and /htaccess/ folder
    // files: default.htaccess, secure.htaccess and wpadmin-secure.htaccess
    $htaccess_dir = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess';
    $bps_backup_dir = WP_CONTENT_DIR . '/bps-backup';
    $secureHtaccess = $htaccess_dir . '/secure.htaccess';
    $wpadminHtaccess = $htaccess_dir . '/wpadmin-secure.htaccess';
    $defaultHtaccess = $htaccess_dir . '/default.htaccess';
    if (is_writable($htaccess_dir)) {
        echo $successTextBegin . __('Pass! The ', 'bulletproof-security') . $htaccess_dir . __(' Folder is writable.', 'bulletproof-security') . $successTextEnd;
    } else {
        echo $failTextBegin . __('Error: The ', 'bulletproof-security') . $htaccess_dir . __(' Folder is NOT writable. If your Server type is DSO and the WP Filesystem API Method is NOT "direct" you can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a>' . __(' If your Server type is CGI check the folder permissions. Folder permissions should be either 755 or 705.', 'bulletproof-security') . $failTextEnd . '<br>';
    }
    if (is_writable($bps_backup_dir)) {
        echo $successTextBegin . __('Pass! The ', 'bulletproof-security') . $bps_backup_dir . __(' Folder is writable.', 'bulletproof-security') . $successTextEnd;
    } else {
        echo $failTextBegin . __('Error: The ', 'bulletproof-security') . $bps_backup_dir . __(' Folder is NOT writable. If your Server type is DSO and the WP Filesystem API Method is NOT "direct" you can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a>' . __(' If your Server type is CGI check the folder permissions. Folder permissions should be either 755 or 705.', 'bulletproof-security') . $failTextEnd . '<br>';
    }
    if (is_writable($secureHtaccess)) {
        echo $successTextBegin . __('Pass! The ', 'bulletproof-security') . $secureHtaccess . __(' File is writable.', 'bulletproof-security') . $successTextEnd;
    } else {
        echo $failTextBegin . __('Error: The ', 'bulletproof-security') . $secureHtaccess . __(' File is NOT writable. If your Server type is DSO and the WP Filesystem API Method is NOT "direct" you can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a>' . __(' If your Server type is CGI check the file permissions. File permissions should be either 644 or 604.', 'bulletproof-security') . $failTextEnd . '<br>';
    }
    if (is_writable($wpadminHtaccess)) {
        echo $successTextBegin . __('Pass! The ', 'bulletproof-security') . $wpadminHtaccess . __(' File is writable.', 'bulletproof-security') . $successTextEnd;
    } else {
        echo $failTextBegin . __('Error: The ', 'bulletproof-security') . $wpadminHtaccess . __(' File is NOT writable. If your Server type is DSO and the WP Filesystem API Method is NOT "direct" you can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a>' . __(' If your Server type is CGI check the file permissions. File permissions should be either 644 or 604.', 'bulletproof-security') . $failTextEnd . '<br>';
    }
    if (is_writable($defaultHtaccess)) {
        echo $successTextBegin . __('Pass! The ', 'bulletproof-security') . $defaultHtaccess . __(' File is writable.', 'bulletproof-security') . $successTextEnd;
    } else {
        echo $failTextBegin . __('Error: The ', 'bulletproof-security') . $defaultHtaccess . __(' File is NOT writable. If your Server type is DSO and the WP Filesystem API Method is NOT "direct" you can use the Setup Wizard, but you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security') . '<a href="http://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window"><strong>' . __('DSO Setup Steps', 'bulletproof-security') . '</a>' . __(' If your Server type is CGI check the file permissions. File permissions should be either 644 or 604.', 'bulletproof-security') . $failTextEnd . '<br>';
    }
    echo '</span>';
    echo '</div>';
}
Beispiel #23
0
 public function pre_init_stats($params)
 {
     include_once ABSPATH . 'wp-includes/update.php';
     include_once ABSPATH . 'wp-admin/includes/update.php';
     $stats = $this->mmb_parse_action_params('pre_init_stats', $params, $this);
     extract($params);
     if ($params['refresh'] == 'transient') {
         global $wp_current_filter;
         $wp_current_filter[] = 'load-update-core.php';
         wp_version_check();
         wp_update_themes();
         // THIS IS INTENTIONAL, please do not delete one of the calls to wp_update_plugins(), it is required for
         // some custom plugins (read premium) to work with ManageWP :)
         // the second call is not going to trigger the remote post invoked from the wp_update_plugins call
         wp_update_plugins();
         array_pop($wp_current_filter);
         do_action('load-plugins.php');
     }
     /** @var $wpdb wpdb */
     global $wpdb, $wp_version;
     $stats['worker_version'] = $GLOBALS['MMB_WORKER_VERSION'];
     $stats['worker_revision'] = $GLOBALS['MMB_WORKER_REVISION'];
     $stats['wordpress_version'] = $wp_version;
     $stats['wordpress_locale_pckg'] = get_locale();
     $stats['php_version'] = phpversion();
     $stats['mysql_version'] = $wpdb->db_version();
     $stats['server_functionality'] = $this->get_backup_instance()->getServerInformationForStats();
     $stats['wp_multisite'] = $this->mmb_multisite;
     $stats['network_install'] = $this->network_admin_install;
     $stats['cookies'] = $this->get_stat_cookies();
     $stats['admin_usernames'] = $this->getUserList();
     $stats['site_title'] = get_bloginfo('name');
     $stats['site_tagline'] = get_bloginfo('description');
     $stats['blog_public'] = get_option('blog_public');
     $stats['timezone'] = get_option('timezone_string');
     $stats['timezone_offset'] = get_option('gmt_offset');
     $stats['server_ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null;
     $stats['hostname'] = php_uname('n');
     if (!function_exists('get_filesystem_method')) {
         include_once ABSPATH . 'wp-admin/includes/file.php';
     }
     $stats['fs_method'] = get_filesystem_method();
     $mmode = get_option('mwp_maintenace_mode');
     if (!empty($mmode) && isset($mmode['active']) && $mmode['active'] == true) {
         $stats['maintenance'] = true;
     }
     $stats['writable'] = $this->is_server_writable();
     return $stats;
 }
Beispiel #24
0
/**
 * Displays a form to the user to request for their FTP/SSH details in order
 * to connect to the filesystem.
 *
 * All chosen/entered details are saved, Excluding the Password.
 *
 * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467)
 * to specify an alternate FTP/SSH port.
 *
 * Plugins may override this form by returning true|false via the
 * {@see 'request_filesystem_credentials'} filter.
 *
 * @since 2.5.
 *
 * @todo Properly mark optional arguments as such
 *
 * @param string $form_post the URL to post the form to
 * @param string $type the chosen Filesystem method in use
 * @param boolean $error if the current request has failed to connect
 * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
 * @param string $extra_fields Extra POST fields which should be checked for to be included in the post.
 * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
 * @return boolean False on failure. True on success.
 */
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null, $allow_relaxed_file_ownership = false)
{
    /**
     * Filter the filesystem credentials form output.
     *
     * Returning anything other than an empty string will effectively short-circuit
     * output of the filesystem credentials form, returning that value instead.
     *
     * @since 2.5.0
     *
     * @param mixed  $output       Form output to return instead. Default empty.
     * @param string $form_post    URL to POST the form to.
     * @param string $type         Chosen type of filesystem.
     * @param bool   $error        Whether the current request has failed to connect.
     *                             Default false.
     * @param string $context      Full path to the directory that is tested for
     *                             being writable.
     * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
     * @param array  $extra_fields Extra POST fields.
     */
    $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership);
    if ('' !== $req_cred) {
        return $req_cred;
    }
    if (empty($type)) {
        $type = get_filesystem_method(array(), $context, $allow_relaxed_file_ownership);
    }
    if ('direct' == $type) {
        return true;
    }
    if (is_null($extra_fields)) {
        $extra_fields = array('version', 'locale');
    }
    $credentials = get_option('ftp_credentials', array('hostname' => '', 'username' => ''));
    // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? wp_unslash($_POST['hostname']) : $credentials['hostname']);
    $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? wp_unslash($_POST['username']) : $credentials['username']);
    $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? wp_unslash($_POST['password']) : '');
    // Check to see if we are setting the public/private keys for ssh
    $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? wp_unslash($_POST['public_key']) : '');
    $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? wp_unslash($_POST['private_key']) : '');
    // Sanitize the hostname, Some people might pass in odd-data:
    $credentials['hostname'] = preg_replace('|\\w+://|', '', $credentials['hostname']);
    //Strip any schemes off
    if (strpos($credentials['hostname'], ':')) {
        list($credentials['hostname'], $credentials['port']) = explode(':', $credentials['hostname'], 2);
        if (!is_numeric($credentials['port'])) {
            unset($credentials['port']);
        }
    } else {
        unset($credentials['port']);
    }
    if (defined('FTP_SSH') && FTP_SSH || defined('FS_METHOD') && 'ssh2' == FS_METHOD) {
        $credentials['connection_type'] = 'ssh';
    } else {
        if (defined('FTP_SSL') && FTP_SSL && 'ftpext' == $type) {
            //Only the FTP Extension understands SSL
            $credentials['connection_type'] = 'ftps';
        } else {
            if (!empty($_POST['connection_type'])) {
                $credentials['connection_type'] = wp_unslash($_POST['connection_type']);
            } else {
                if (!isset($credentials['connection_type'])) {
                    //All else fails (And it's not defaulted to something else saved), Default to FTP
                    $credentials['connection_type'] = 'ftp';
                }
            }
        }
    }
    if (!$error && (!empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) || 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']))) {
        $stored_credentials = $credentials;
        if (!empty($stored_credentials['port'])) {
            //save port as part of hostname to simplify above code.
            $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
        }
        unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
        if (!defined('WP_INSTALLING')) {
            update_option('ftp_credentials', $stored_credentials);
        }
        return $credentials;
    }
    $hostname = isset($credentials['hostname']) ? $credentials['hostname'] : '';
    $username = isset($credentials['username']) ? $credentials['username'] : '';
    $public_key = isset($credentials['public_key']) ? $credentials['public_key'] : '';
    $private_key = isset($credentials['private_key']) ? $credentials['private_key'] : '';
    $port = isset($credentials['port']) ? $credentials['port'] : '';
    $connection_type = isset($credentials['connection_type']) ? $credentials['connection_type'] : '';
    if ($error) {
        $error_string = __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.');
        if (is_wp_error($error)) {
            $error_string = esc_html($error->get_error_message());
        }
        echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    }
    $types = array();
    if (extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen')) {
        $types['ftp'] = __('FTP');
    }
    if (extension_loaded('ftp')) {
        //Only this supports FTPS
        $types['ftps'] = __('FTPS (SSL)');
    }
    if (extension_loaded('ssh2') && function_exists('stream_get_contents')) {
        $types['ssh'] = __('SSH2');
    }
    /**
     * Filter the connection types to output to the filesystem credentials form.
     *
     * @since 2.9.0
     *
     * @param array  $types       Types of connections.
     * @param array  $credentials Credentials to connect with.
     * @param string $type        Chosen filesystem method.
     * @param object $error       Error object.
     * @param string $context     Full path to the directory that is tested
     *                            for being writable.
     */
    $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
    ?>
<script type="text/javascript">
<!--
jQuery(function($){
	jQuery("#ssh").click(function () {
		jQuery("#ssh_keys").show();
	});
	jQuery("#ftp, #ftps").click(function () {
		jQuery("#ssh_keys").hide();
	});
	jQuery('form input[value=""]:first').focus();
});
-->
</script>
<form action="<?php 
    echo esc_url($form_post);
    ?>
" method="post">
<div>
<h3><?php 
    _e('Connection Information');
    ?>
</h3>
<p><?php 
    $label_user = __('Username');
    $label_pass = __('Password');
    _e('To perform the requested action, WordPress needs to access your web server.');
    echo ' ';
    if (isset($types['ftp']) || isset($types['ftps'])) {
        if (isset($types['ssh'])) {
            _e('Please enter your FTP or SSH credentials to proceed.');
            $label_user = __('FTP/SSH Username');
            $label_pass = __('FTP/SSH Password');
        } else {
            _e('Please enter your FTP credentials to proceed.');
            $label_user = __('FTP Username');
            $label_pass = __('FTP Password');
        }
        echo ' ';
    }
    _e('If you do not remember your credentials, you should contact your web host.');
    ?>
</p>
<table class="form-table">
<tr>
<th scope="row"><label for="hostname"><?php 
    _e('Hostname');
    ?>
</label></th>
<td><input name="hostname" type="text" id="hostname" value="<?php 
    echo esc_attr($hostname);
    if (!empty($port)) {
        echo ":{$port}";
    }
    ?>
"<?php 
    disabled(defined('FTP_HOST'));
    ?>
 size="40" /></td>
</tr>

<tr>
<th scope="row"><label for="username"><?php 
    echo $label_user;
    ?>
</label></th>
<td><input name="username" type="text" id="username" value="<?php 
    echo esc_attr($username);
    ?>
"<?php 
    disabled(defined('FTP_USER'));
    ?>
 size="40" /></td>
</tr>

<tr>
<th scope="row"><label for="password"><?php 
    echo $label_pass;
    ?>
</label></th>
<td><div><input name="password" type="password" id="password" value="<?php 
    if (defined('FTP_PASS')) {
        echo '*****';
    }
    ?>
"<?php 
    disabled(defined('FTP_PASS'));
    ?>
 size="40" /></div>
<div><em><?php 
    if (!defined('FTP_PASS')) {
        _e('This password will not be stored on the server.');
    }
    ?>
</em></div></td>
</tr>

<?php 
    if (isset($types['ssh'])) {
        ?>
<tr id="ssh_keys" style="<?php 
        if ('ssh' != $connection_type) {
            echo 'display:none';
        }
        ?>
">
<th scope="row"><?php 
        _e('Authentication Keys');
        ?>
<div class="key-labels textright">
<label for="public_key"><?php 
        _e('Public Key:');
        ?>
</label ><br />
<label for="private_key"><?php 
        _e('Private Key:');
        ?>
</label>
</div></th>
<td><br /><input name="public_key" type="text" id="public_key" value="<?php 
        echo esc_attr($public_key);
        ?>
"<?php 
        disabled(defined('FTP_PUBKEY'));
        ?>
 size="40" />
	<br /><input name="private_key" type="text" id="private_key" value="<?php 
        echo esc_attr($private_key);
        ?>
"<?php 
        disabled(defined('FTP_PRIKEY'));
        ?>
 size="40" />
<div><?php 
        _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.');
        ?>
</div></td>
</tr>
<?php 
    }
    ?>

<tr>
<th scope="row"><?php 
    _e('Connection Type');
    ?>
</th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php 
    _e('Connection Type');
    ?>
</span></legend>
<?php 
    $disabled = disabled(defined('FTP_SSL') && FTP_SSL || defined('FTP_SSH') && FTP_SSH, true, false);
    foreach ($types as $name => $text) {
        ?>
	<label for="<?php 
        echo esc_attr($name);
        ?>
">
		<input type="radio" name="connection_type" id="<?php 
        echo esc_attr($name);
        ?>
" value="<?php 
        echo esc_attr($name);
        ?>
"<?php 
        checked($name, $connection_type);
        echo $disabled;
        ?>
 />
		<?php 
        echo $text;
        ?>
	</label>
	<?php 
    }
    ?>
</fieldset>
</td>
</tr>
</table>

<?php 
    foreach ((array) $extra_fields as $field) {
        if (isset($_POST[$field])) {
            echo '<input type="hidden" name="' . esc_attr($field) . '" value="' . esc_attr(wp_unslash($_POST[$field])) . '" />';
        }
    }
    submit_button(__('Proceed'), 'button', 'upgrade');
    ?>
</div>
</form>
<?php 
    return false;
}
 protected static function getFileSystemMethod()
 {
     $fs = get_filesystem_method();
     return $fs;
 }
 /**
  * Can the plugins be automatically downloaded?
  */
 function _can_auto_download_project($type)
 {
     $root = $writable = false;
     $is_direct_access_fs = 'direct' == get_filesystem_method() ? true : false;
     if ('plugin' == $type) {
         $root = WP_PLUGIN_DIR;
         if (empty($root)) {
             $root = ABSPATH . 'wp-content/plugins';
         }
     } else {
         $root = WP_CONTENT_DIR . '/themes';
         if (empty($root)) {
             $root = ABSPATH . 'wp-content/themes';
         }
     }
     if ($is_direct_access_fs) {
         $writable = $root ? is_writable($root) : false;
     }
     // If we don't have write permissions, do we have FTP settings?
     $writable = $writable ? $writable : defined('FTP_USER') && defined('FTP_PASS') && defined('FTP_HOST');
     // Lastly, if no other option worked, do we have SSH settings?
     $writable = $writable ? $writable : defined('FTP_USER') && defined('FTP_PUBKEY') && defined('FTP_PRIKEY');
     return $writable;
 }
 function woothemes_framework_update_filesystem_warning()
 {
     $method = get_filesystem_method();
     echo "<div id='filesystem-warning' class='updated fade'><p>Failed: Filesystem preventing downloads. ( " . $method . ")</p></div>";
 }
Beispiel #28
0
function WP_Filesystem($args = false)
{
    global $wp_filesystem;
    require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
    $method = get_filesystem_method();
    if (!$method) {
        return false;
    }
    $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
    if (!file_exists($abstraction_file)) {
        return;
    }
    require_once $abstraction_file;
    $method = "WP_Filesystem_{$method}";
    $wp_filesystem = new $method($args);
    if ($wp_filesystem->errors->get_error_code()) {
        return false;
    }
    if (!$wp_filesystem->connect()) {
        return false;
    }
    //There was an erorr connecting to the server.
    return true;
}
Beispiel #29
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $form_post
 * @param unknown_type $type
 * @param unknown_type $error
 * @return unknown
 */
function request_filesystem_credentials($form_post, $type = '', $error = false)
{
    $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error);
    if ('' !== $req_cred) {
        return $req_cred;
    }
    if (empty($type)) {
        $type = get_filesystem_method();
    }
    if ('direct' == $type) {
        return true;
    }
    $credentials = get_option('ftp_credentials', array());
    // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
    $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
    $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']);
    // Check to see if we are setting the public/private keys for ssh
    $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? $_POST['public_key'] : $credentials['public_key']);
    $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? $_POST['private_key'] : $credentials['private_key']);
    //sanitize the hostname, Some people might pass in odd-data:
    $credentials['hostname'] = preg_replace('|\\w+://|', '', $credentials['hostname']);
    //Strip any schemes off
    if (strpos($credentials['hostname'], ':')) {
        list($credentials['hostname'], $credentials['port']) = explode(':', $credentials['hostname'], 2);
    } else {
        unset($credentials['port']);
    }
    if (defined('FTP_SSH') || isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) {
        $credentials['connection_type'] = 'ssh';
    } else {
        if (defined('FTP_SSL') || isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) {
            $credentials['connection_type'] = 'ftps';
        } else {
            if (!isset($credentials['connection_type']) || isset($_POST['connection_type']) && 'ftp' == $_POST['connection_type']) {
                $credentials['connection_type'] = 'ftp';
            }
        }
    }
    if (!$error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname'])) {
        $stored_credentials = $credentials;
        if (!empty($stored_credentials['port'])) {
            //save port as part of hostname to simplify above code.
            $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
        }
        unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']);
        update_option('ftp_credentials', $stored_credentials);
        return $credentials;
    }
    $hostname = '';
    $username = '';
    $password = '';
    $connection_type = '';
    if (!empty($credentials)) {
        extract($credentials, EXTR_OVERWRITE);
    }
    if ($error) {
        $error_string = __('<strong>Error:</strong> There was an error connecting to the server, Please verify the settings are correct.');
        if (is_wp_error($error)) {
            $error_string = $error->get_error_message();
        }
        echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    }
    ?>
<script type="text/javascript">
<!--
jQuery(function($){
	jQuery("#ssh").click(function () {
		jQuery("#ssh_keys").show();
	});
	jQuery("#ftp, #ftps").click(function () {
		jQuery("#ssh_keys").hide();
	});
});
-->
</script>
<form action="<?php 
    echo $form_post;
    ?>
" method="post">
<div class="wrap">
<h2><?php 
    _e('Connection Information');
    ?>
</h2>
<p><?php 
    _e('To perform the requested action, connection information is required.');
    ?>
</p>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="hostname"><?php 
    _e('Hostname');
    ?>
</label></th>
<td><input name="hostname" type="text" id="hostname" value="<?php 
    echo attribute_escape($hostname);
    if (!empty($port)) {
        echo ":{$port}";
    }
    ?>
"<?php 
    if (defined('FTP_HOST')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /></td>
</tr>

<tr valign="top">
<th scope="row"><label for="username"><?php 
    _e('Username');
    ?>
</label></th>
<td><input name="username" type="text" id="username" value="<?php 
    echo attribute_escape($username);
    ?>
"<?php 
    if (defined('FTP_USER')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /></td>
</tr>

<tr valign="top">
<th scope="row"><label for="password"><?php 
    _e('Password');
    ?>
</label></th>
<td><input name="password" type="password" id="password" value=""<?php 
    if (defined('FTP_PASS')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /><?php 
    if (defined('FTP_PASS') && !empty($password)) {
        echo '<em>' . __('(Password not shown)') . '</em>';
    }
    ?>
</td>
</tr>

<tr id="ssh_keys" valign="top" style="<?php 
    if ('ssh' != $connection_type) {
        echo 'display:none';
    }
    ?>
">
<th scope="row"><?php 
    _e('Authentication Keys');
    ?>
<div class="key-labels textright">
<label for="public_key"><?php 
    _e('Public Key:');
    ?>
</label ><br />
<label for="private_key"><?php 
    _e('Private Key:');
    ?>
</label>
</div></th>
<td><br /><input name="public_key" type="text" id="public_key" value=""<?php 
    if (defined('FTP_PUBKEY')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" /><br /><input name="private_key" type="text" id="private_key" value=""<?php 
    if (defined('FTP_PRIKEY')) {
        echo ' disabled="disabled"';
    }
    ?>
 size="40" />
<div><?php 
    _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.');
    ?>
</div></td>
</tr>

<tr valign="top">
<th scope="row"><?php 
    _e('Connection Type');
    ?>
</th>
<td>
<fieldset><legend class="hidden"><?php 
    _e('Connection Type');
    ?>
</legend>
<label><input id="ftp" name="connection_type"  type="radio" value="ftp" <?php 
    checked('ftp', $connection_type);
    if (defined('FTP_SSL') || defined('FTP_SSH')) {
        echo ' disabled="disabled"';
    }
    ?>
/> <?php 
    _e('FTP');
    ?>
</label><br />
<label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php 
    checked('ftps', $connection_type);
    if (defined('FTP_SSH') || defined('FTP_SSH')) {
        echo ' disabled="disabled"';
    }
    ?>
/> <?php 
    _e('FTPS (SSL)');
    ?>
</label><br />
<?php 
    if (extension_loaded('ssh2')) {
        ?>
<label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php 
        checked('ssh', $connection_type);
        if (defined('FTP_SSL') || defined('FTP_SSH')) {
            echo ' disabled="disabled"';
        }
        ?>
/> <?php 
        _e('SSH');
        ?>
</label><?php 
    }
    ?>
</fieldset>
</td>
</tr>
</table>

<?php 
    if (isset($_POST['version'])) {
        ?>
<input type="hidden" name="version" value="<?php 
        echo attribute_escape($_POST['version']);
        ?>
" />
<?php 
    }
    if (isset($_POST['locale'])) {
        ?>
<input type="hidden" name="locale" value="<?php 
        echo attribute_escape($_POST['locale']);
        ?>
" />
<?php 
    }
    ?>
<p class="submit">
<input id="upgrade" name="upgrade" type="submit" class="button" value="<?php 
    _e('Proceed');
    ?>
" />
</p>
</div>
</form>
<?php 
    return false;
}
 function handle_job($job_id, $job_data, $app_config, $task_list)
 {
     $job_user = $job_data['user'];
     $task_count = count($task_list);
     $done_count = 0;
     $skip_count = 0;
     $task_list_result = array();
     wp_set_current_user($job_user);
     /* This block does all of the filesystem magic:
      * - determines web paths based on FTP paths
      * - initializes the WP_Filesystem mechanism in case this host doesn't support direct file access
      *   (this might not be 100% reliable right now due to NG core not making use of WP_Filesystem)
      */
     // $ftp_path is assumed to be WP_CONTENT_DIR as accessed through the FTP mount point
     $ftp_path = rtrim($app_config['ftp_path'], '/\\');
     $full_path = rtrim($app_config['full_path'], '/\\');
     $root_path = rtrim(WP_CONTENT_DIR, '/\\');
     $creds = true;
     // WP_Filesystem(true) requests direct filesystem access
     $fs_sep = DIRECTORY_SEPARATOR;
     $wp_fs = null;
     require_once ABSPATH . 'wp-admin/includes/file.php';
     if (get_filesystem_method() !== 'direct') {
         $fs_sep = '/';
         $ftp_method = isset($app_config['ftp_method']) ? $app_config['ftp_method'] : 'ftp';
         $creds = array('connection_type' => $ftp_method == 'sftp' ? 'ssh' : 'ftp', 'hostname' => $app_config['ftp_host'], 'port' => $app_config['ftp_port'], 'username' => $app_config['ftp_user'], 'password' => $app_config['ftp_pass']);
     }
     if (WP_Filesystem($creds)) {
         $wp_fs = $GLOBALS['wp_filesystem'];
         $path_prefix = $full_path;
         if ($wp_fs->method === 'direct') {
             $path_prefix = str_replace($ftp_path, $root_path, $full_path);
         }
     }
     foreach ($task_list as &$task_item) {
         $task_id = isset($task_item['id']) ? $task_item['id'] : null;
         $task_name = isset($task_item['name']) ? $task_item['name'] : null;
         $task_type = isset($task_item['type']) ? $task_item['type'] : null;
         $task_auth = isset($task_item['auth']) ? $task_item['auth'] : null;
         $task_query = isset($task_item['query']) ? $task_item['query'] : null;
         $task_object = isset($task_item['object']) ? $task_item['object'] : null;
         $task_status = isset($task_item['status']) ? $task_item['status'] : null;
         $task_result = isset($task_item['result']) ? $task_item['result'] : null;
         // make sure we don't repeat execution of already finished tasks
         if ($task_status == 'done') {
             $done_count++;
             // for previously finished tasks, store the result as it may be needed by future tasks
             if ($task_id != null && $task_result != null) {
                 $task_list_result[$task_id] = $task_result;
             }
             continue;
         }
         // make sure only valid and authorized tasks are executed
         if ($task_status == 'error' || $task_auth != 'allow') {
             $skip_count++;
             continue;
         }
         // the task query ID can be a simple (integer) ID or more complex ID that gets converted to a simple ID, for instance to point to an object that is the result of a previously finished task
         if (isset($task_query['id'])) {
             $task_query['id'] = $this->get_object_id($task_query['id'], $task_list_result);
         }
         $task_error = null;
         switch ($task_type) {
             case 'gallery_add':
                 $mapper = C_Gallery_Mapper::get_instance();
                 $gallery = null;
                 $gal_errors = '';
                 if (isset($task_query['id'])) {
                     $gallery = $mapper->find($task_query['id'], true);
                 }
                 if ($gallery == null) {
                     $title = isset($task_object['title']) ? $task_object['title'] : '';
                     $gallery = $mapper->create(array('title' => $title));
                     if (!$gallery || !$gallery->save()) {
                         if ($gallery != null) {
                             $gal_errors = $gallery->get_errors();
                             if ($gal_errors != null) {
                                 $gal_errors = ' [' . json_encode($gal_errors) . ']';
                             }
                         }
                         $gallery = null;
                     }
                 }
                 if ($gallery != null) {
                     $task_status = 'done';
                     $task_result['object_id'] = $gallery->id();
                 } else {
                     $task_status = 'error';
                     $task_error = array('level' => 'fatal', 'message' => sprintf(__('Gallery creation failed for "%1$s"%2$s.', 'nggallery'), $title, $gal_errors));
                 }
                 break;
             case 'gallery_remove':
             case 'gallery_edit':
                 if (isset($task_query['id'])) {
                     $mapper = C_Gallery_Mapper::get_instance();
                     $gallery = $mapper->find($task_query['id'], true);
                     $error = null;
                     if ($gallery != null) {
                         if ($task_type == 'gallery_remove') {
                             if (!$mapper->destroy($gallery, true)) {
                                 $error = __('Failed to remove gallery (%1$s).', 'nggallery');
                             }
                         } else {
                             if ($task_type == 'gallery_edit') {
                                 if (isset($task_object['name'])) {
                                     $gallery->name = $task_object['name'];
                                 }
                                 if (isset($task_object['title'])) {
                                     $gallery->title = $task_object['title'];
                                 }
                                 if (isset($task_object['description'])) {
                                     $gallery->galdesc = $task_object['description'];
                                 }
                                 if (isset($task_object['preview_image'])) {
                                     $gallery->previewpic = $task_object['preview_image'];
                                 }
                                 if (isset($task_object['property_list'])) {
                                     $properties = $task_object['property_list'];
                                     foreach ($properties as $key => $value) {
                                         $gallery->{$key} = $value;
                                     }
                                 }
                                 // this is used to determine whether the task is complete
                                 $image_list_unfinished = false;
                                 if (isset($task_object['image_list']) && $wp_fs != null) {
                                     $storage_path = isset($task_object['storage_path']) ? $task_object['storage_path'] : null;
                                     $storage_path = trim($storage_path, '/\\');
                                     $storage = C_Gallery_Storage::get_instance();
                                     $image_mapper = C_Image_Mapper::get_instance();
                                     $creds = true;
                                     $images_folder = $path_prefix . $fs_sep . $storage_path . $fs_sep;
                                     $images_folder = str_replace(array('\\', '/'), $fs_sep, $images_folder);
                                     $images = $task_object['image_list'];
                                     $result_images = isset($task_result['image_list']) ? $task_result['image_list'] : array();
                                     $image_count = count($images);
                                     $result_image_count = count($result_images);
                                     for ($image_index = $result_image_count; $image_index < $image_count; $image_index++) {
                                         $image = $images[$image_index];
                                         $image_id = isset($image['id']) ? $image['id'] : null;
                                         $image_filename = isset($image['filename']) ? $image['filename'] : null;
                                         $image_path = isset($image['path']) ? $image['path'] : null;
                                         $image_action = isset($image['action']) ? $image['action'] : null;
                                         $image_status = 'skip';
                                         if ($image_filename == null) {
                                             $image_filename = basename($image_path);
                                         }
                                         $ngg_image = $image_mapper->find($image_id, TRUE);
                                         // ensure that we don't transpose the image from one gallery to another in case a remoteId is passed in for the image but the gallery associated to the collection cannot be found
                                         if ($ngg_image && $ngg_image->galleryid != $gallery->id()) {
                                             $ngg_image = null;
                                             $image_id = null;
                                         }
                                         $image_error = null;
                                         if ($image_action == "delete") {
                                             // image was deleted
                                             if ($ngg_image != null) {
                                                 $settings = C_NextGen_Settings::get_instance();
                                                 $delete_fine = true;
                                                 if ($settings->deleteImg) {
                                                     if (!$storage->delete_image($ngg_image)) {
                                                         $image_error = __('Could not delete image file(s) from disk (%1$s).', 'nggallery');
                                                     }
                                                 } else {
                                                     if (!$image_mapper->destroy($ngg_image)) {
                                                         $image_error = __('Could not remove image from gallery (%1$s).', 'nggallery');
                                                     }
                                                 }
                                                 if ($image_error == null) {
                                                     do_action('ngg_delete_picture', $ngg_image->{$ngg_image->id_field});
                                                     $image_status = 'done';
                                                 }
                                             } else {
                                                 $image_error = __('Could not remove image because image was not found (%1$s).', 'nggallery');
                                             }
                                         } else {
                                             /* image was added or edited and needs updating */
                                             $image_path = $images_folder . $image_path;
                                             if ($image_path != null && $wp_fs->exists($image_path)) {
                                                 try {
                                                     $ngg_image = $storage->upload_base64_image($gallery, $wp_fs->get_contents($image_path), $image_filename, $image_id, true);
                                                     if ($ngg_image != null) {
                                                         $image_status = 'done';
                                                         $image_id = $ngg_image->{$ngg_image->id_field};
                                                     }
                                                 } catch (E_NoSpaceAvailableException $e) {
                                                     $image_error = __('No space available for image (%1$s).', 'nggallery');
                                                 } catch (E_UploadException $e) {
                                                     $image_error = $e->getMessage . __(' (%1$s).', 'nggallery');
                                                 } catch (E_No_Image_Library_Exception $e) {
                                                     $error = __('No image library present, image uploads will fail (%1$s).', 'nggallery');
                                                     // no point in continuing if the image library is not present but we don't break here to ensure that all images are processed (otherwise they'd be processed in further fruitless handle_job calls)
                                                 } catch (E_InsufficientWriteAccessException $e) {
                                                     $image_error = __('Inadequate system permissions to write image (%1$s).', 'nggallery');
                                                 } catch (E_InvalidEntityException $e) {
                                                     $image_error = __('Requested image with id (%2$s) doesn\'t exist (%1$s).', 'nggallery');
                                                 } catch (E_EntityNotFoundException $e) {
                                                     // gallery doesn't exist - already checked above so this should never happen
                                                 }
                                                 // delete temporary image
                                                 $wp_fs->delete($image_path);
                                             } else {
                                                 $image_error = __('Could not find image file for image (%1$s).', 'nggallery');
                                             }
                                         }
                                         if ($image_error != null) {
                                             $image_status = 'error';
                                             $image['error'] = array('level' => 'fatal', 'message' => sprintf($image_error, $image_filename, $image_id));
                                         }
                                         if ($image_id) {
                                             $image['id'] = $image_id;
                                         }
                                         if ($image_status) {
                                             $image['status'] = $image_status;
                                         }
                                         // append processed image to result image_list array
                                         $result_images[] = $image;
                                         if ($this->should_stop_execution()) {
                                             break;
                                         }
                                     }
                                     $task_result['image_list'] = $result_images;
                                     $image_list_unfinished = count($result_images) < $image_count;
                                     // if images have finished processing, remove the folder used to store the temporary images (the folder should be empty due to delete() calls above)
                                     if (!$image_list_unfinished) {
                                         $wp_fs->rmdir($images_folder);
                                     }
                                 } else {
                                     if ($wp_fs == null) {
                                         $error = __('Could not access file system for gallery (%1$s).', 'nggallery');
                                     }
                                 }
                                 if (!$gallery->save()) {
                                     if ($error == null) {
                                         $gal_errors = '[' . json_encode($gallery->get_errors()) . ']';
                                         $error = __('Failed to save modified gallery (%1$s). ' . $gal_errors, 'nggallery');
                                     }
                                 }
                             }
                         }
                     } else {
                         $error = __('Could not find gallery (%1$s).', 'nggallery');
                     }
                     // XXX workaround for $gallery->save() returning false even if successful
                     if (isset($task_result['image_list'])) {
                         $task_result['object_id'] = $gallery->id();
                     }
                     if ($error == null) {
                         $task_status = 'done';
                         $task_result['object_id'] = $gallery->id();
                     } else {
                         $task_status = 'error';
                         $task_error = array('level' => 'fatal', 'message' => sprintf($error, (string) $task_query['id']));
                     }
                     if ($image_list_unfinished) {
                         // we override the status of the task when the image list has not finished processing
                         $task_status = 'unfinished';
                     }
                 } else {
                     $task_status = 'error';
                     $task_error = array('level' => 'fatal', 'message' => __('No gallery was specified to edit.', 'nggallery'));
                 }
                 break;
             case 'album_add':
                 $mapper = C_Album_Mapper::get_instance();
                 $name = isset($task_object['name']) ? $task_object['name'] : '';
                 $desc = isset($task_object['description']) ? $task_object['description'] : '';
                 $previewpic = isset($task_object['preview_image']) ? $task_object['preview_image'] : 0;
                 $sortorder = isset($task_object['sort_order']) ? $task_object['sort_order'] : '';
                 $page_id = isset($task_object['page_id']) ? $task_object['page_id'] : 0;
                 $album = null;
                 if (isset($task_query['id'])) {
                     $album = $mapper->find($task_query['id'], true);
                 }
                 if ($album == null) {
                     $album = $mapper->create(array('name' => $name, 'previewpic' => $previewpic, 'albumdesc' => $desc, 'sortorder' => $sortorder, 'pageid' => $page_id));
                     if (!$album || !$album->save()) {
                         $album = null;
                     }
                 }
                 if ($album != null) {
                     $task_status = 'done';
                     $task_result['object_id'] = $album->id();
                 } else {
                     $task_status = 'error';
                     $task_error = array('level' => 'fatal', 'message' => __('Album creation failed.', 'nggallery'));
                 }
                 break;
             case 'album_remove':
             case 'album_edit':
                 if (isset($task_query['id'])) {
                     $mapper = C_Album_Mapper::get_instance();
                     $album = $mapper->find($task_query['id'], true);
                     $error = null;
                     if ($album) {
                         if ($task_type == 'album_remove') {
                             if (!$album->destroy()) {
                                 $error = __('Failed to remove album (%1$s).', 'nggallery');
                             }
                         } else {
                             if ($task_type == 'album_edit') {
                                 if (isset($task_object['name'])) {
                                     $album->name = $task_object['name'];
                                 }
                                 if (isset($task_object['description'])) {
                                     $album->albumdesc = $task_object['description'];
                                 }
                                 if (isset($task_object['preview_image'])) {
                                     $album->previewpic = $task_object['preview_image'];
                                 }
                                 if (isset($task_object['property_list'])) {
                                     $properties = $task_object['property_list'];
                                     foreach ($properties as $key => $value) {
                                         $album->{$key} = $value;
                                     }
                                 }
                                 if (isset($task_object['item_list'])) {
                                     $item_list = $task_object['item_list'];
                                     $sortorder = $album->sortorder;
                                     $count = count($sortorder);
                                     $album_items = array();
                                     for ($index = 0; $index < $count; $index++) {
                                         $album_items[$sortorder[$index]] = $index;
                                     }
                                     foreach ($item_list as $item_info) {
                                         $item_id = isset($item_info['id']) ? $item_info['id'] : null;
                                         $item_type = isset($item_info['type']) ? $item_info['type'] : null;
                                         $item_index = isset($item_info['index']) ? $item_info['index'] : null;
                                         // translate ID in case this gallery has been created as part of this job
                                         $item_id = $this->get_object_id($item_id, $task_list_result);
                                         if ($item_id != null) {
                                             if ($item_type == 'album') {
                                                 $item_id = 'a' . $item_id;
                                             }
                                             $album_items[$item_id] = $count + $item_index;
                                         }
                                     }
                                     asort($album_items);
                                     $album->sortorder = array_keys($album_items);
                                 }
                                 if (!$mapper->save($album)) {
                                     $error = __('Failed to save modified album (%1$s).', 'nggallery');
                                 }
                             }
                         }
                     } else {
                         $error = __('Could not find album (%1$s).', 'nggallery');
                     }
                     if ($error == null) {
                         $task_status = 'done';
                         $task_result['object_id'] = $album->id();
                     } else {
                         $task_status = 'error';
                         $task_error = array('level' => 'fatal', 'message' => sprintf($error, (string) $task_query['id']));
                     }
                 } else {
                     $task_status = 'error';
                     $task_error = array('level' => 'fatal', 'message' => __('No album was specified to edit.', 'nggallery'));
                 }
                 break;
             case 'gallery_list_get':
                 $mapper = C_Gallery_Mapper::get_instance();
                 $gallery_list = $mapper->find_all();
                 $result_list = array();
                 foreach ($gallery_list as $gallery) {
                     $gallery_result = array('id' => $gallery->id(), 'name' => $gallery->name, 'title' => $gallery->title, 'description' => $gallery->galdesc, 'preview_image' => $gallery->previewpic);
                     $result_list[] = $gallery_result;
                 }
                 $task_status = 'done';
                 $task_result['gallery_list'] = $result_list;
                 break;
             case 'image_list_move':
                 break;
         }
         $task_item['result'] = $task_result;
         $task_item['status'] = $task_status;
         $task_item['error'] = $task_error;
         // for previously finished tasks, store the result as it may be needed by future tasks
         if ($task_id != null && $task_result != null) {
             $task_list_result[$task_id] = $task_result;
         }
         // if the task has finished, either successfully or unsuccessfully, increase count for done tasks
         if ($task_status != 'unfinished') {
             $done_count++;
         }
         if ($this->should_stop_execution()) {
             break;
         }
     }
     $this->set_job_task_list($job_id, $task_list);
     if ($task_count > $done_count + $skip_count) {
         // unfinished tasks, return false
         return false;
     } else {
         // everything was finished, remove job and write status file
         $this->remove_job($job_id);
         $status_file = '_ngg_job_status_' . strval($job_id) . '.txt';
         $status_content = json_encode($task_list);
         if ($wp_fs != null) {
             $status_path = $path_prefix . $fs_sep . $status_file;
             $status_path = str_replace(array('\\', '/'), $fs_sep, $status_path);
             $wp_fs->put_contents($status_path, $status_content);
         } else {
             // if WP_Filesystem failed try one last desperate attempt at direct file writing
             $status_path = str_replace($ftp_path, $root_path, $full_path) . DIRECTORY_SEPARATOR . $status_file;
             $status_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $status_path);
             file_put_contents($status_path, $status_content);
         }
         return true;
     }
 }