public function get_population_options($population_method, $multimedia_types = array(), $options = array()) { $population_method_instance = $this->get_child('population-method-' . $population_method); if (empty($population_method)) { FW_Flash_Messages::add('fw-ext-' . $this->get_name() . '-wrong-method', sprintf(__('Specified population method does not exists: %s', 'fw'), $population_method), 'error'); return array(); } return $population_method_instance->get_population_options($multimedia_types, $options); }
public function run() { $fs = new FW_Backup_Helper_File_System(); $db = new FW_Backup_Helper_Database(); $auto_install_dir = $this->backup()->get_auto_install_dir(); $upload_dir = wp_upload_dir(); $upload_dir = $upload_dir['basedir']; // This forces *Restore* page to be opened event if // request_filesystem_credentials is not required. In the // latter case JavaScript will submit the page automatically // which opens up a *Restore in Progress* popup. if ($_SERVER['REQUEST_METHOD'] != 'POST') { throw new FW_Backup_Exception_Method_Not_Allowed(); } $restore = new FW_Backup_Process_Restore(); $restore->request_filesystem_credentials(); // Increase time limit. Run, until user cancelled set_time_limit(0); try { $fs->check_permissions(); // Do Full Backup before Auto Install if (apply_filters('fw_ext_backup_do_backup_on_demo_content_install', true)) { @set_time_limit(30 * 60); $this->backup()->action()->do_backup_background_cron('cron_full'); } // Replace uploads directory $t = $fs->replace($fs->map($upload_dir), $fs->map("{$auto_install_dir}/uploads")); // Move backup directory from trashed dir into new upload dir if ($t) { $fs->move_existing("{$t}/backup", $fs->map("{$upload_dir}/backup")); // Remove trashed dir because we made Full Backup of the site $fs->rmdir($t); } if (file_exists("{$auto_install_dir}/database.txt")) { $file_with_sql = "{$auto_install_dir}/database.txt"; } else { $file_with_sql = "{$auto_install_dir}/database.sql"; } $db->import($file_with_sql, true, true, true); } catch (FW_Backup_Exception $exception) { FW_Flash_Messages::add('auto-install', $exception->getMessage(), 'error'); // otherwise flash messages wont show wp_redirect($this->backup()->action()->url_backup_auto_install_page()); exit; } if ($this->backup()->get_config('image_recovery')) { $image_recovery = new FW_Backup_Image_Recovery(); $image_recovery->generate_attachment_images(); } do_action('fw_ext_backup_after_import_demo_content'); // get rid of update notifications wp_redirect(admin_url('update-core.php?force-check=1&auto-install-redirect=' . esc_url(admin_url()))); exit; }
/** * Prevent Fatal Error if someone is registering option-types in old way (right away) * not in 'fw_option_types_init' action * @param string $class */ function _fw_autoload_option_types($class) { if ('FW_Option_Type' === $class) { require_once dirname(__FILE__) . '/../core/extends/class-fw-option-type.php'; if (is_admin() && defined('WP_DEBUG') && WP_DEBUG) { FW_Flash_Messages::add('option-type-register-wrong', __("Please register option-types on 'fw_option_types_init' action", 'fw'), 'warning'); } } elseif ('FW_Container_Type' === $class) { require_once dirname(__FILE__) . '/../core/extends/class-fw-container-type.php'; if (is_admin() && defined('WP_DEBUG') && WP_DEBUG) { FW_Flash_Messages::add('container-type-register-wrong', __("Please register container-types on 'fw_container_types_init' action", 'fw'), 'warning'); } } }
/** * Adds the extension settings box in Framework in SEO extension * * @param $options , holds the general options from extension config file * * @return array * @internal */ public function _admin_filter_set_framework_options($options) { $webmasters = $this->get_config('webmasters'); if (empty($webmasters)) { return $options; } $general_options = array($this->get_name() => array('title' => __('Webmasters', 'fw'), 'type' => 'box', 'options' => array())); foreach ($webmasters as $webmaster) { if (!isset($this->webmasters[$webmaster])) { FW_Flash_Messages::add('fw-ext-seo-add-tabs', sprintf(__('Webmaster %s already exists', 'fw'), $webmaster), 'warning'); continue; } $prefix = $this->get_name() . '-' . $webmaster; $general_options[$this->get_name()]['options'][$prefix] = array('label' => $this->webmasters[$webmaster]['name'], 'desc' => $this->webmasters[$webmaster]['desc'], 'type' => 'text', 'value' => ''); } if (empty($general_options[$this->get_name()]['options'])) { return $options; } $options = array_merge($options, $general_options); return $options; }
/** * Show warning message on widgets.php page * @internal */ public function _admin_action_flash_message($hook) { if ('widgets.php' === $hook and !count($this->backend->config->get_sidebar_positions())) { FW_Flash_Messages::add('fw-ext-' . $this->get_name() . '-no-config', sprintf(__('Config file is required for %s extension. Section [sidebar_positions] is missing or config file does not exists.', 'fw'), $this->get_name()), 'warning'); } }
/** * @param string $option_type * @return FW_Option_Type|FW_Option_Type_Undefined */ public function option_type($option_type) { if (is_array($this->option_types_pending_registration)) { // This method is called first time. Register pending option types $pending_option_types = $this->option_types_pending_registration; // clear this property, so register_option_type() will not add option types to pending anymore $this->option_types_pending_registration = false; foreach ($pending_option_types as $option_type_class) { $this->register_option_type($option_type_class); } unset($pending_option_types); } if (isset($this->option_types[$option_type])) { return $this->option_types[$option_type]; } else { if (is_admin()) { FW_Flash_Messages::add('fw-get-option-type-undefined-' . $option_type, sprintf(__('Undefined option type: %s', 'fw'), $option_type), 'warning'); } return $this->undefined_option_type; } }
/** * @internal */ public function _action_fw_extensions_init() { if (is_admin() && !fw()->theme->manifest->check_requirements()) { FW_Flash_Messages::add('fw_theme_requirements', __('Theme requirements not met:', 'fw') . ' ' . fw()->theme->manifest->get_not_met_requirement_text(), 'warning'); } }
/** * @internal */ public function _check_requirements() { if (is_admin() && !$this->manifest->check_requirements()) { FW_Flash_Messages::add('fw_requirements', __('Framework requirements not met: ') . $this->manifest->get_not_met_requirement_text(), 'warning'); } }
/** * Create the simep XSL style file */ private function create_xsl() { $file_path = fw_ext_seo_sitemap_get_home_path() . 'sitemap-xsl.xsl'; if (!fw_ext_seo_sitemap_try_make_file_writable($file_path)) { if (is_admin()) { FW_Flash_Messages::add('fw-ext-seo-sitemap-try-modify-file', sprintf(__('Could not create/write the %s. File is not writable', 'fw'), $file_path), 'warning'); } return; } $file = fopen($file_path, 'w'); fwrite($file, fw_render_view($this->locate_view_path('sitemap-style'))); }
/** * @param string $container_type * * @return FW_Container_Type|FW_Container_Type_Undefined */ public function container_type($container_type) { if (is_array($this->container_types_pending_registration)) { // This method is called first time do_action('fw_container_types_init'); $pending_container_types = $this->container_types_pending_registration; // clear this property, so register_container_type() will not add container types to pending anymore $this->container_types_pending_registration = false; foreach ($pending_container_types as $container_type_class) { $this->register_container_type($container_type_class); } unset($pending_container_types); } if (isset($this->container_types[$container_type])) { return $this->container_types[$container_type]; } else { if (is_admin()) { FW_Flash_Messages::add('fw-get-container-type-undefined-' . $container_type, sprintf(__('Undefined container type: %s', 'fw'), $container_type), 'warning'); } if (!$this->undefined_container_type) { require_once fw_get_framework_directory('/includes/container-types/class-fw-container-type-undefined.php'); $this->undefined_container_type = new FW_Container_Type_Undefined(); } return $this->undefined_container_type; } }
private function restore_run($post_id) { /** * @var FW_Backup_Service_Post_Meta $meta * @var FW_Backup_Interface_Storage $storage * @var FW_Backup_Process_Backup_Restore $backup_restore * @var WP_Filesystem_Base $wp_filesystem */ global $wp_filesystem; ob_start(); $credentials = request_filesystem_credentials(fw_current_url(), '', false, false, null); $this->request_filesystem_credentials = ob_get_clean(); if ($credentials) { if (!WP_Filesystem($credentials)) { ob_start(); request_filesystem_credentials(fw_current_url(), '', false, false, null); $this->request_filesystem_credentials = ob_get_clean(); } } if ($this->request_filesystem_credentials) { return false; } if ($_SERVER['REQUEST_METHOD'] == 'GET') { return false; } // ob_start(); // fw_print('Let\'s start the party!!!'); // $this->request_filesystem_credentials = ob_get_clean(); // return; set_time_limit(0); $meta = $this->service('shared.post.meta'); $meta->set_post_id($post_id); $storage = $this->service($meta->get_storage_id(), 'FW_Backup_Interface_Storage'); $backup_restore = $this->service('process.backup-restore', 'FW_Backup_Process_Backup_Restore'); // 1) Do we have enough permissions for restoring file system / database? // If no there is no need for fetching archive. if (in_array('fs', $meta->get_backup_contents())) { $backup_restore->check_permissions_fs(); } if (in_array('db', $meta->get_backup_contents())) { $backup_restore->check_permissions_db(); } // 2) Do restore $backup_restore->restore($storage, $meta->get_backup_file()); // 3) Actualize settings $this->reschedule(); FW_Flash_Messages::add(uniqid(), __('The site was restored from backup', 'fw')); return true; }
/** * @param array $data * @return array * @internal */ public function _extension_settings_form_save($data) { $extension = fw()->extensions->get(FW_Request::POST('fw_extension_name')); $options_before_save = (array) fw_get_db_ext_settings_option($extension->get_name()); fw_set_db_ext_settings_option($extension->get_name(), null, array_merge($options_before_save, fw_get_options_values_from_input($extension->get_settings_options()))); FW_Flash_Messages::add('fw_extension_settings_saved', __('Extensions settings successfully saved.', 'fw'), 'success'); $data['redirect'] = fw_current_url(); do_action('fw_extension_settings_form_saved:' . $extension->get_name(), $options_before_save); return $data; }
/** * Detect if form errors was not displayed in frontend then display them with default design * Do nothing if the theme already displayed the errors * @internal */ function _action_show_fw_form_errors_in_frontend() { $form = FW_Form::get_submitted(); if (!$form || $form->is_valid()) { return; } if ($form->errors_accessed()) { // already displayed return; } foreach ($form->get_errors() as $input_name => $error_message) { FW_Flash_Messages::add('fw-form-error-' . $input_name, $error_message, 'error'); } }
/** * Return SEO options array; * * @return array * @internal */ private function get_seo_options() { $seo_options = $this->get_seo_framework_options(); $general_settings = $seo_options['general-tab']['options']['general-settings']['options']; foreach (apply_filters('fw_ext_seo_general_setting_admin_options', $general_settings) as $opt_id => $options) { if (isset($general_settings[$opt_id])) { FW_Flash_Messages::add('fw-ext-seo-add-tabs', sprintf(__('Unable to set the %s option, as there is already present an option with such id', 'fw'), $opt_id), 'warning'); continue; } $general_settings[$opt_id] = $options; } $seo_options['general-tab']['options']['general-settings']['options'] = $general_settings; $general_tab = $seo_options['general-tab']['options']; foreach (apply_filters('fw_ext_seo_general_tab_admin_options', $general_tab) as $tab_id => $options) { $general_tab[$tab_id] = $options; } $seo_options['general-tab']['options'] = $general_tab; foreach (apply_filters('fw_ext_seo_admin_options', array()) as $tab_id => $options) { if (isset($seo_options[$tab_id])) { FW_Flash_Messages::add('fw-ext-seo-add-tabs', sprintf(__('Unable to set the %s tab, as it exists already', 'fw'), $tab_id), 'warning'); continue; } $seo_options[$tab_id] = $options; } return $seo_options; }
/** * @internal */ public function _action_update_extensions() { $nonce_name = '_nonce_fw_ext_update_extensions'; if (!isset($_POST[$nonce_name]) || !wp_verify_nonce($_POST[$nonce_name])) { wp_die(__('Invalid nonce.', 'fw')); } $form_input_name = 'extensions'; $extensions_list = FW_Request::POST($form_input_name); if (empty($extensions_list)) { FW_Flash_Messages::add('fw_ext_update', __('Please check the extensions you want to update.', 'fw'), 'warning'); wp_redirect(self_admin_url('update-core.php')); exit; } if (is_string($extensions_list)) { $extensions_list = json_decode($extensions_list); } else { $extensions_list = array_keys($extensions_list); } if (!class_exists('_FW_Ext_Update_Extensions_Upgrader_Skin')) { fw_include_file_isolated($this->get_declared_path('/includes/classes/class--fw-ext-update-extensions-upgrader-skin.php')); } $skin = new _FW_Ext_Update_Extensions_Upgrader_Skin(array('title' => __('Extensions Update', 'fw'))); require_once ABSPATH . 'wp-admin/admin-header.php'; $skin->header(); do { $original_post_value = $_POST[$form_input_name]; $_POST[$form_input_name] = wp_slash(json_encode($extensions_list)); if (!FW_WP_Filesystem::request_access(fw_get_framework_directory('/extensions'), fw_current_url(), array($nonce_name, $form_input_name))) { // revert hack changes $_POST[$form_input_name] = $original_post_value; unset($original_post_value); break; } // revert hack changes $_POST[$form_input_name] = $original_post_value; unset($original_post_value); $updates = $this->get_extensions_with_updates(); if (empty($updates)) { $skin->error(__('No extensions updates found.', 'fw')); break; } foreach ($extensions_list as $extension_name) { if (!($extension = fw()->extensions->get($extension_name))) { $skin->error(sprintf(__('Extension "%s" does not exist or is disabled.', 'fw'), $extension_name)); continue; } if (!isset($updates[$extension_name])) { $skin->error(sprintf(__('No update found for the "%s" extension.', 'fw'), $extension->manifest->get_name())); continue; } $update = $updates[$extension_name]; if (is_wp_error($update)) { $skin->error($update); continue; } /** @var FW_Ext_Update_Service $service */ $service = $this->get_child($update['service']); $update_result = $this->update(array('wp_fs_destination_dir' => FW_WP_Filesystem::real_path_to_filesystem_path($extension->get_declared_path()), 'download_callback' => array($service, '_download_extension'), 'download_callback_args' => array($extension, $update['latest_version'], $this->get_wp_fs_tmp_dir()), 'skin' => $skin, 'title' => sprintf(__('%s extension', 'fw'), $extension->manifest->get_name())), true); if (is_wp_error($update_result)) { $skin->error($update_result); continue; } $skin->set_result(true); if (!$this->get_config('extensions_as_one_update')) { $skin->decrement_extension_update_count($extension_name); } } if ($this->get_config('extensions_as_one_update')) { $skin->decrement_extension_update_count($extension_name); } $skin->after(); } while (false); $skin->footer(); require_once ABSPATH . 'wp-admin/admin-footer.php'; }
/** * @internal * * @var $post_id */ public function _action_before_delete_post($post_id) { if (get_post_type($post_id) != $this->get_post_type()) { return; } try { if ($backup_info = $this->backup()->get_backup_info($post_id)) { if ($backup_info->is_completed()) { $storage = fw()->extensions->get($backup_info->get_storage()); if ($storage instanceof FW_Backup_Interface_Storage) { // Initialize storage layer $storage_options = $this->backup()->settings()->get_cron_storage_options($backup_info->get_cron_job(), $backup_info->get_storage()); $storage->set_storage_options($storage_options); // Remove file from persistent storage $storage->remove($backup_info->get_storage_file(), new FW_Backup_Feedback_Void()); } } } } catch (FW_Backup_Exception $exception) { FW_Flash_Messages::add("backup-remove-{$post_id}", $exception->getMessage(), 'error'); } }
/** * Get repository latest release version * * @param string $user_slash_repo Github 'user/repo' * @param bool $force_check Bypass cache * @param string $title Used in messages * * @return string|WP_Error */ private function get_latest_version($user_slash_repo, $force_check, $title) { if (!preg_match($this->manifest_key_regex, $user_slash_repo)) { return new WP_Error('fw_ext_update_github_manifest_invalid', sprintf(__('%s manifest has invalid "github_update" parameter. Please use "user/repo" format.', 'fw'), $title)); } $transient_id = 'fw_ext_upd_gh_fw'; // the length must be 45 characters or less if ($force_check) { delete_site_transient($transient_id); $cache = array(); } else { $cache = get_site_transient($transient_id); if ($cache === false) { $cache = array(); } elseif (isset($cache[$user_slash_repo])) { return $cache[$user_slash_repo]; } } $latest_version = $this->fetch_latest_version($user_slash_repo); if (empty($latest_version)) { return new WP_Error('fw_ext_update_github_failed_fetch_latest_version', sprintf(__('Failed to fetch %s latest version from github "%s".', 'fw'), $title, $user_slash_repo)); } if (is_wp_error($latest_version)) { /** * Internet connection problems or Github API requests limit reached. * Cache fake version to prevent requests to Github API on every refresh. */ $cache = array_merge($cache, array($user_slash_repo => $this->fake_latest_version)); /** * Show the error to the user because it is not visible elsewhere */ FW_Flash_Messages::add('fw_ext_github_update_error', $latest_version->get_error_message(), 'error'); } else { $cache = array_merge($cache, array($user_slash_repo => $latest_version)); } set_site_transient($transient_id, $cache, $this->transient_expiration); return $latest_version; }
private function check_path() { if (!fw_ext_seo_sitemap_try_make_file_writable($this->get_path())) { if (is_admin()) { FW_Flash_Messages::add('fw-ext-seo-sitemap-try-edit-file', sprintf(__('Could not create/write the %s. File is not writable', 'fw'), $this->get_path()), 'warning'); } return false; } return true; }
/** * Display form errors in admin side */ function _action_show_fw_form_errors_in_admin() { $form = FW_Form::get_submitted(); if (!$form || $form->is_valid()) { return; } foreach ($form->get_errors() as $input_name => $error_message) { FW_Flash_Messages::add('fw-form-admin-' . $input_name, $error_message, 'error'); } }
/** * Default option array * * This makes possible an option array to have required only one parameter: array('type' => '...') * Other parameters are merged with array returned from this method * * @return array */ public final function get_defaults() { $option = $this->_get_defaults(); $option['type'] = $this->get_type(); if (!isset($option['value'])) { FW_Flash_Messages::add('fw-option-type-no-default-value', sprintf(__('Option type %s has no default value', 'fw'), $this->get_type()), 'warning'); $option['value'] = array(); } return $option; }
/** * @param string $extension_name * @return bool */ private function activate_extension($extension_name) { if (fw()->extensions->get($extension_name)) { // already active return false; } if (!self::$all_extensions[$extension_name]->manifest->requirements_met()) { trigger_error('Wrong ' . __METHOD__ . ' call', E_USER_WARNING); return false; } // add to active extensions so inside includes/ and extension it will be accessible from fw()->extensions->get(...) self::$active_extensions[$extension_name] =& self::$all_extensions[$extension_name]; $parent = self::$all_extensions[$extension_name]->get_parent(); if ($parent) { self::$extension_to_active_tree[$parent->get_name()][$extension_name] = array(); self::$extension_to_active_tree[$extension_name] =& self::$extension_to_active_tree[$parent->get_name()][$extension_name]; } else { self::$active_extensions_tree[$extension_name] = array(); self::$extension_to_active_tree[$extension_name] =& self::$active_extensions_tree[$extension_name]; } self::include_extension_directory_all($extension_name, '/includes'); self::include_extension_file_all($extension_name, '/helpers.php'); self::include_extension_file_all($extension_name, '/hooks.php'); if (self::$all_extensions[$extension_name]->_call_init() !== false) { $this->activate_extensions($extension_name); } // check if other extensions are waiting for this extension and try to activate them if (isset(self::$extensions_required_by_extensions[$extension_name])) { foreach (self::$extensions_required_by_extensions[$extension_name] as $waiting_extension_name) { if (self::$all_extensions[$waiting_extension_name]->manifest->check_requirements()) { $waiting_extension = self::$all_extensions[$waiting_extension_name]; if (isset(self::$blacklist[$waiting_extension_name])) { // do not activate blacklisted extensions } elseif ($waiting_extension->get_parent() && !$waiting_extension->get_parent()->_child_extension_is_valid($waiting_extension)) { // extension does not pass parent extension rules if (is_admin()) { // show warning only in admin side FW_Flash_Messages::add('fw-invalid-extension', sprintf(__('Extension %s is invalid.', 'fw'), $waiting_extension_name), 'warning'); } } else { $this->activate_extension($waiting_extension_name); } } } unset(self::$extensions_required_by_extensions[$extension_name]); } return true; }
/** * @internal */ public function _action_post_form_type_save() { if (!fw_ext_mailer_is_configured()) { FW_Flash_Messages::add('fw-ext-forms-' . $this->get_form_type() . '-mailer', str_replace(array('{mailer_link}'), array(version_compare(fw()->manifest->get_version(), '2.1.7', '>=') ? fw_html_tag('a', array('href' => fw()->extensions->manager->get_extension_link('forms')), __('Mailer', 'fw')) : __('Mailer', 'fw')), __('Please configure the {mailer_link} extension.', 'fw')), 'error'); } }
private function do_backup_auto_install() { try { $process = new FW_Backup_Process_Auto_Install(); $process->run(); } catch (FW_Backup_Exception_Request_File_System_Credentials $exception) { $this->backup()->set_request_filesystem_credentials($exception->get_html()); return; } catch (FW_Backup_Exception_Method_Not_Allowed $exception) { return; } catch (FW_Backup_Exception $exception) { FW_Flash_Messages::add('backup-auto-install', $exception->getMessage(), 'error'); } wp_redirect($this->url_backup_auto_install_page()); exit; }