/**
  * Generate html
  *
  * @param string $id
  * @param array $option Option array merged with _get_defaults()
  * @param array $data {value => _get_value_from_input(), id_prefix => ..., name_prefix => ...}
  *
  * @return string HTML
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     $defaults = $this->_get_defaults();
     $option['preview'] = array_merge($defaults['preview'], $option['preview']);
     $option['attr'] = array_merge($defaults['attr'], $option['attr']);
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), compact('id', 'option', 'data'));
 }
Example #2
0
/**
 * @param null|string $type
 * @return FW_Option_Storage_Type|FW_Option_Storage_Type[]|null
 * @since 2.5.0
 */
function fw_db_option_storage_type($type = null)
{
    static $types = null;
    if (is_null($types)) {
        $dir = fw_get_framework_directory('/includes/option-storage');
        if (!class_exists('FW_Option_Storage_Type')) {
            require_once $dir . '/class-fw-option-storage-type.php';
        }
        if (!class_exists('_FW_Option_Storage_Type_Register')) {
            require_once $dir . '/class--fw-option-storage-type-register.php';
        }
        $access_key = new FW_Access_Key('fw:option-storage-register');
        $register = new _FW_Option_Storage_Type_Register($access_key->get_key());
        require_once $dir . '/type/class-fw-option-storage-type-post-meta.php';
        $register->register(new FW_Option_Storage_Type_Post_Meta());
        require_once $dir . '/type/class-fw-option-storage-type-wp-option.php';
        $register->register(new FW_Option_Storage_Type_WP_Option());
        do_action('fw:option-storage-types:register', $register);
        $types = $register->_get_types($access_key);
    }
    if (empty($type)) {
        return $types;
    } elseif (isset($types[$type])) {
        return $types[$type];
    } else {
        return null;
    }
}
 private static function load_from_extensions_recursive($extensions)
 {
     /*
      * Loop each extension
      * if it has a shortcodes folder load the shortcodes from it
      * if an extension has subextensions then recursion
      */
     foreach ($extensions as $ext_name => $children) {
         $extension = fw()->extensions->get($ext_name);
         $rel_path = $extension->get_rel_path();
         // framework
         $fw_path = fw_get_framework_directory('/extensions' . $rel_path . '/shortcodes');
         if (file_exists($fw_path)) {
             self::load_from_shortcodes_folder(array('path' => $fw_path, 'uri' => fw_get_framework_directory_uri('/extensions' . $rel_path . '/shortcodes')));
         }
         // parent theme framework-customizations
         $parent_fws_path = fw_get_template_customizations_directory('/extensions' . $rel_path . '/shortcodes');
         if (file_exists($parent_fws_path)) {
             self::load_from_shortcodes_folder(array('path' => $parent_fws_path, 'uri' => fw_get_template_customizations_directory_uri('/extensions' . $rel_path . '/shortcodes')));
         }
         // child theme framework-customizations
         if (is_child_theme()) {
             $child_fws_path = fw_get_stylesheet_customizations_directory('/extensions' . $rel_path . '/shortcodes');
             if (file_exists($child_fws_path)) {
                 self::load_from_shortcodes_folder(array('path' => $child_fws_path, 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions' . $rel_path . '/shortcodes')));
             }
         }
         if (!empty($children)) {
             self::load_from_extensions_recursive($children);
         }
     }
 }
 /**
  * Generate option's html from option array
  * @param string $id
  * @param array $option
  * @param array $data
  * @return string HTML
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     unset($option['attr']['name'], $option['attr']['value']);
     $option['attr']['data-for-js'] = json_encode(array('title' => empty($option['popup-title']) ? $option['label'] : $option['popup-title'], 'options' => $this->transform_options($option['popup-options']), 'template' => $option['template'], 'size' => $option['size'], 'limit' => $option['limit']));
     $sortable_image = fw_get_framework_directory_uri('/static/img/sort-vertically.png');
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/views/view.php'), compact('id', 'option', 'data', 'sortable_image'));
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array(), fw()->manifest->get_version());
     wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/scripts.js'), array('jquery'), fw()->manifest->get_version());
     $output = fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data));
     return $output;
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array('fw-selectize'), fw()->manifest->get_version());
     wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/scripts.js'), array('jquery', 'underscore', 'fw', 'fw-selectize'), fw()->manifest->get_version());
     if (!self::$googleFontsPrinted) {
         wp_localize_script('fw-option-' . $this->get_type(), 'googleFonts', self::$fonts['google']);
         self::$googleFontsPrinted = true;
     }
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'fonts' => self::$fonts));
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     $option['properties']['type'] = 'single';
     $option['properties']['from'] = isset($data['value']) ? $data['value'] : $option['value'];
     if (isset($option['properties']['values']) && is_array($option['properties']['values'])) {
         $option['properties']['from'] = array_search($option['properties']['from'], $option['properties']['values']);
     }
     $option['attr']['data-fw-irs-options'] = json_encode($this->default_properties($option['properties']));
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'value' => $data['value']));
 }
 /**
  * Generate option's html from option array
  * @param string $id
  * @param array $option
  * @param array $data
  * @return string HTML
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     unset($option['attr']['name'], $option['attr']['value']);
     wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array('fw'), fw()->manifest->get_version());
     wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/' . $this->get_type() . '.js'), array('underscore', 'fw-events', 'jquery-ui-sortable', 'fw'), fw()->manifest->get_version(), true);
     $transformed_options = $this->transform_options($option['popup-options']);
     $localize_var_name = 'fw_option_type_' . str_replace('-', '_', $this->get_type()) . '_localize_' . md5(json_encode($transformed_options));
     wp_localize_script('fw-option-' . $this->get_type(), $localize_var_name, array('title' => empty($option['popup-title']) ? $option['label'] : $option['popup-title'], 'options' => $this->transform_options($option['popup-options']), 'template' => $option['template']));
     $option['attr']['data-localize-var-name'] = $localize_var_name;
     fw()->backend->render_options($option['popup-options']);
     // This makes sure that the option's static is enqueued
     $sortable_image = fw_get_framework_directory_uri('/static/img/sort-vertically.png');
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/views/view.php'), compact('id', 'option', 'data', 'sortable_image'));
 }
 /**
  * Generate option's html from option array
  *
  * @param string $id
  * @param array $option
  * @param array $data
  *
  * @return string HTML
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     unset($option['attr']['name'], $option['attr']['value']);
     $option['attr']['data-for-js'] = json_encode(array('title' => isset($option['popup-title']) ? $option['popup-title'] : (string) $option['label'], 'options' => $this->transform_options($option['popup-options']), 'button' => $option['button'], 'size' => $option['size'], 'custom-events' => $option['custom-events']));
     if (!empty($data['value'])) {
         if (is_array($data['value'])) {
             $data['value'] = json_encode($data['value']);
         }
     } else {
         $data['value'] = '';
     }
     $sortable_image = fw_get_framework_directory_uri('/static/img/sort-vertically.png');
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/views/view.php'), compact('id', 'option', 'data', 'sortable_image'));
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array(), fw()->manifest->get_version());
     wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/scripts.js'), array('fw-events', 'jquery-ui-sortable'), fw()->manifest->get_version(), true);
     if (empty($data['value']) || !is_array($data['value'])) {
         $data['value'] = array();
     }
     $controls = array_merge(array('delete' => '<small class="dashicons dashicons-no-alt" title="' . esc_attr(__('Remove', 'fw')) . '"></small>'), $option['box-controls']);
     if (isset($controls['delete'])) {
         $_delete = $controls['delete'];
         unset($controls['delete']);
         $controls['delete'] = $_delete;
         unset($_delete);
     }
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'controls' => $controls));
 }
 /**
  * @internal
  * {@inheritdoc}
  */
 protected function _render($id, $option, $data)
 {
     if (empty($data['value']) || !is_array($data['value'])) {
         $data['value'] = array();
     }
     $controls = array_merge(array('delete' => '<small class="dashicons dashicons-no-alt" title="' . esc_attr__('Remove', 'fw') . '"></small>'), $option['box-controls']);
     if (isset($controls['delete'])) {
         $_delete = $controls['delete'];
         unset($controls['delete']);
         $controls['delete'] = $_delete;
         unset($_delete);
     }
     $box_options = array();
     fw_collect_options($box_options, $option['box-options'], array('limit_option_types' => false, 'limit_container_types' => array('group'), 'limit_level' => 1));
     $option['attr']['data-for-js'] = json_encode(array('options' => $this->transform_options($box_options), 'template' => $option['template']));
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'controls' => $controls, 'box_options' => $box_options));
 }
 /**
  * @param $color string
  * @return html string of rendered widgets for current page
  */
 public function render_sidebar($color)
 {
     if (!in_array($color, _FW_Extension_Sidebars_Config::$allowed_colors)) {
         return false;
     }
     $preset = $this->get_current_page_preset();
     //get available sidebar by color
     $sidebar = isset($preset['sidebars'][$color]) ? $preset['sidebars'][$color] : null;
     ob_start();
     //check if sidebar is active
     if (!empty($sidebar)) {
         $sidebars_widgets = wp_get_sidebars_widgets();
         if (!empty($sidebars_widgets[$sidebar])) {
             dynamic_sidebar($sidebar);
         } else {
             echo fw_render_view(fw_get_framework_directory('/extensions/sidebars/views/frontend-no-widgets.php'), array('sidebar_id' => $sidebar));
         }
     }
     return ob_get_clean();
 }
Example #13
0
 public function __construct()
 {
     if (self::$loaded) {
         trigger_error('Framework already loaded', E_USER_ERROR);
     } else {
         self::$loaded = true;
     }
     require fw_get_framework_directory('/core/class-fw-manifest.php');
     require fw_get_framework_directory('/manifest.php');
     /** @var array $manifest */
     $this->manifest = new FW_Framework_Manifest($manifest);
     add_action('fw_init', array($this, '_check_requirements'));
     require fw_get_framework_directory('/core/extends/class-fw-extension.php');
     require fw_get_framework_directory('/core/extends/class-fw-option-type.php');
     require fw_get_framework_directory('/core/components/extensions.php');
     $this->extensions = new _FW_Component_Extensions();
     require fw_get_framework_directory('/core/components/backend.php');
     $this->backend = new _FW_Component_Backend();
     require fw_get_framework_directory('/core/components/theme.php');
     $this->theme = new _FW_Component_Theme();
 }
Example #14
0
 function _action_init_framework()
 {
     remove_action('after_setup_theme', '_action_init_framework');
     include dirname(__FILE__) . '/bootstrap-helpers.php';
     include dirname(__FILE__) . '/deprecated-constants.php';
     require fw_get_framework_directory('/core/Fw.php');
     fw();
     /**
      * Load helpers
      */
     foreach (array('meta', 'class-fw-access-key', 'class-fw-dumper', 'general', 'class-fw-wp-filesystem', 'class-fw-cache', 'class-fw-form', 'class-fw-request', 'class-fw-session', 'class-fw-wp-option', 'class-fw-wp-post-meta', 'database', 'class-fw-flash-messages', 'class-fw-resize') as $file) {
         require fw_get_framework_directory('/helpers/' . $file . '.php');
     }
     /**
      * Load (includes) other functionality
      */
     foreach (array('hooks', 'option-types') as $file) {
         require fw_get_framework_directory('/includes/' . $file . '.php');
     }
     /**
      * Init components
      */
     foreach (fw() as $component_name => $component) {
         if ($component_name === 'manifest') {
             continue;
         }
         /** @var FW_Component $component */
         $component->_call_init();
     }
     /**
      * For Flash Message Helper:
      * just start session before headers sent
      * to prevent: Warning: session_start(): Cannot send session cookie - headers already sent, if flash added to late
      */
     FW_Session::get(-1);
     do_action('fw_init');
 }
Example #15
0
 /**
  * Search relative path in: child theme -> parent theme -> framework extensions directory and return URI
  *
  * @param string $rel_path '/<extension>/path_to_dir' or '/<extension>/extensions/<another_extension>/path_to_file.php'
  * @param   bool $search_in_framework
  * @param   bool $search_in_parent_theme
  * @param   bool $search_in_child_theme
  * @return false|string URI or false if not found
  */
 public function locate_path_URI($rel_path, $search_in_framework = true, $search_in_parent_theme = true, $search_in_child_theme = true)
 {
     if ($search_in_child_theme && is_child_theme()) {
         if (file_exists(fw_get_stylesheet_customizations_directory('/extensions' . $rel_path))) {
             return fw_get_stylesheet_customizations_directory_uri('/extensions' . $rel_path);
         }
     }
     if ($search_in_parent_theme) {
         if (file_exists(fw_get_template_customizations_directory('/extensions' . $rel_path))) {
             return fw_get_template_customizations_directory_uri('/extensions' . $rel_path);
         }
     }
     if ($search_in_framework) {
         if (file_exists(fw_get_framework_directory('/extensions' . $rel_path))) {
             return fw_get_framework_directory_uri('/extensions' . $rel_path);
         }
     }
     return false;
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array(), fw()->manifest->get_version());
     wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/scripts.js'), array('fw-events', 'jquery-ui-sortable'), fw()->manifest->get_version(), true);
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'move_img_src' => fw_get_framework_directory_uri('/static/img/sort-vertically.png')));
 }
 private function display_delete_page()
 {
     $flash_id = 'fw_extensions_delete';
     if (!$this->can_install()) {
         FW_Flash_Messages::add($flash_id, __('You are not allowed to delete extensions.', 'fw'), 'error');
         $this->js_redirect();
         return;
     }
     $extensions = array_fill_keys(array_map('trim', explode(',', FW_Request::GET('extension', ''))), array());
     if (!class_exists('_FW_Extensions_Delete_Upgrader_Skin')) {
         fw_include_file_isolated(dirname(__FILE__) . '/includes/class--fw-extensions-delete-upgrader-skin.php');
     }
     $skin = new _FW_Extensions_Delete_Upgrader_Skin(array('title' => _n('Delete Extension', 'Delete Extensions', count($extensions), 'fw')));
     $skin->header();
     do {
         $nonce = $this->get_nonce('delete');
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
             if (!isset($_POST[$nonce['name']]) || !wp_verify_nonce($_POST[$nonce['name']], $nonce['action'])) {
                 $skin->error(__('Invalid nonce.', 'fw'));
             }
             if (!FW_WP_Filesystem::request_access(fw_get_framework_directory('/extensions'), fw_current_url(), array($nonce['name']))) {
                 break;
             }
             $uninstall_result = $this->uninstall_extensions($extensions, array('verbose' => $skin));
             if (is_wp_error($uninstall_result)) {
                 $skin->error($uninstall_result);
             } elseif (is_array($uninstall_result)) {
                 $error = array();
                 foreach ($uninstall_result as $extension_name => $extension_result) {
                     if (is_wp_error($extension_result)) {
                         $error[] = $extension_result->get_error_message();
                     }
                 }
                 $error = '<ul><li>' . implode('</li><li>', $error) . '</li></ul>';
                 $skin->error($error);
             } elseif ($uninstall_result === true) {
                 $skin->set_result(true);
             }
             $skin->after(array('extensions_page_link' => $this->get_link()));
         } else {
             echo '<form method="post">';
             wp_nonce_field($nonce['action'], $nonce['name']);
             fw_render_view(dirname(__FILE__) . '/views/delete-form.php', array('extension_names' => array_keys($extensions), 'installed_extensions' => $this->get_installed_extensions(), 'list_page_link' => $this->get_link()), false);
             echo '</form>';
         }
     } while (false);
     $skin->footer();
 }
Example #18
0
 /**
  * Return config key value, or entire config array
  * Config array is merged from child configs
  * @param string|null $key Multi key format accepted: 'a/b/c'
  * @return mixed|null
  */
 public final function get_config($key = null)
 {
     $cache_key = $this->get_cache_key() . '/config';
     try {
         $config = FW_Cache::get($cache_key);
     } catch (FW_Cache_Not_Found_Exception $e) {
         list($search_in_framework, $search_in_parent_theme, $search_in_child_theme) = $this->correct_search_in_locations(true, true, true);
         $rel_path = $this->get_rel_path() . '/config.php';
         $config = array();
         $paths = array();
         if ($search_in_framework) {
             $paths[] = fw_get_framework_directory('/extensions' . $rel_path);
         }
         if ($search_in_parent_theme) {
             $paths[] = fw_get_template_customizations_directory('/extensions' . $rel_path);
         }
         if ($search_in_child_theme) {
             $paths[] = fw_get_stylesheet_customizations_directory('/extensions' . $rel_path);
         }
         foreach ($paths as $path) {
             if (file_exists($path)) {
                 $variables = fw_get_variables_from_file($path, array('cfg' => null));
                 if (!empty($variables['cfg'])) {
                     $config = array_merge($config, $variables['cfg']);
                     unset($variables);
                 }
             }
         }
         unset($path);
         FW_Cache::set($cache_key, $config);
     }
     return $key === null ? $config : fw_akg($key, $config);
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'fonts' => $this->get_fonts()));
 }
 public function get_default_icon_packs()
 {
     return array('font-awesome' => array('name' => 'font-awesome', 'title' => 'Font Awesome', 'css_class_prefix' => 'fa', 'css_file' => fw_get_framework_directory('/static/libs/font-awesome/css/font-awesome.min.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/font-awesome/css/font-awesome.min.css')), 'entypo' => array('name' => 'entypo', 'title' => 'Entypo', 'css_class_prefix' => 'entypo', 'css_file' => fw_get_framework_directory('/static/libs/entypo/css/entypo.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/entypo/css/entypo.css')), 'linecons' => array('name' => 'linecons', 'title' => 'Linecons', 'css_class_prefix' => 'linecons', 'css_file' => fw_get_framework_directory('/static/libs/linecons/css/linecons.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/linecons/css/linecons.css')), 'linearicons' => array('name' => 'linearicons', 'title' => 'Linearicons Free', 'css_class_prefix' => 'lnr', 'css_file' => fw_get_framework_directory('/static/libs/lnr/css/lnr.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/lnr/css/lnr.css')), 'typicons' => array('name' => 'typicons', 'title' => 'Typicons', 'css_class_prefix' => 'typcn', 'css_file' => fw_get_framework_directory('/static/libs/typcn/css/typcn.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/typcn/css/typcn.css')), 'unycon' => array('name' => 'unycon', 'title' => 'Unycon', 'css_class_prefix' => 'unycon', 'css_file' => fw_get_framework_directory('/static/libs/unycon/unycon.css'), 'css_file_uri' => fw_get_framework_directory_uri('/static/libs/unycon/unycon.css')));
 }
 /**
  * @internal
  */
 public function _action_update_framework()
 {
     $nonce_name = '_nonce_fw_ext_update_framework';
     if (!isset($_POST[$nonce_name]) || !wp_verify_nonce($_POST[$nonce_name])) {
         wp_die(__('Invalid nonce.', 'fw'));
     }
     if (!class_exists('_FW_Ext_Update_Framework_Upgrader_Skin')) {
         fw_include_file_isolated($this->get_declared_path('/includes/classes/class--fw-ext-update-framework-upgrader-skin.php'));
     }
     $skin = new _FW_Ext_Update_Framework_Upgrader_Skin(array('title' => __('Update Framework', 'fw')));
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $skin->header();
     $update = $this->get_framework_update(true);
     do {
         if ($update === false) {
             $skin->error(__('Failed to get framework latest version.', 'fw'));
             break;
         } elseif (is_wp_error($update)) {
             $skin->error($update);
             break;
         }
         $context = $this->context;
         if (!FW_WP_Filesystem::request_access($context, fw_current_url(), array($nonce_name))) {
             break;
         }
         $this->maintenance_mode(true);
         /** @var WP_Filesystem_Base $wp_filesystem */
         global $wp_filesystem;
         $tmp_download_dir = FW_WP_Filesystem::real_path_to_filesystem_path(fw_fix_path(WP_CONTENT_DIR) . '/cache/framework/update');
         // just in case it already exists, clear everything, it may contain broken/old files
         $wp_filesystem->rmdir($tmp_download_dir, true);
         if (!FW_WP_Filesystem::mkdir_recursive($tmp_download_dir)) {
             $skin->error(__('Cannot create directory: ' . $tmp_download_dir, 'fw'));
             break;
         }
         $skin->feedback(__('Downloading framework...', 'fw'));
         /** @var FW_Ext_Update_Service $service */
         $service = $this->get_child($update['service']);
         $downloaded_files_dir = $service->_download_framework($update['latest_version'], $tmp_download_dir);
         if (!$downloaded_files_dir) {
             $skin->error(__('Failed to download framework.', 'fw'));
             break;
         } elseif (is_wp_error($downloaded_files_dir)) {
             $skin->error($downloaded_files_dir);
             break;
         }
         $skin->feedback(__('Installing framework...', 'fw'));
         $framework_dir = FW_WP_Filesystem::real_path_to_filesystem_path(fw_get_framework_directory());
         // remove entire framework directory
         $wp_filesystem->rmdir($framework_dir, true);
         // move downloaded directory as new framework directory
         $wp_filesystem->move($downloaded_files_dir, $framework_dir);
         $skin->feedback(__('Framework updated.', 'fw'));
         $wp_filesystem->delete($tmp_download_dir, true, 'd');
         $skin->set_result(true);
         $skin->after();
     } while (false);
     $this->maintenance_mode(false);
     $skin->footer();
     require_once ABSPATH . 'wp-admin/admin-footer.php';
 }
Example #22
0
?>
" ><?php 
_e('No, Return me to the extension list', 'fw');
?>
</a>

<p>
	<a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php 
_e('Click to view entire list of directories which will be deleted', 'fw');
?>
</a>
</p>
<div id="files-list" style="display: none;">
	<ul class="code">
		<?php 
$replace_regex = '/^' . preg_quote(fw_get_framework_directory('/extensions'), '/') . '/';
?>
		<?php 
foreach ($extension_names as $extension_name) {
    ?>
			<?php 
    if (!isset($installed_extensions[$extension_name])) {
        continue;
    }
    ?>
			<li><?php 
    echo preg_replace($replace_regex, '', $installed_extensions[$extension_name]['path']);
    ?>
/</li>
		<?php 
}
Example #23
0
 /**
  * @param WP_Customize_Manager $wp_customize
  * @param array $options
  * @param array $parent_data {'type':'...','id':'...'}
  */
 private function customizer_register_options($wp_customize, $options, $parent_data = array())
 {
     $collected = array();
     fw_collect_options($collected, $options, array('limit_option_types' => false, 'limit_container_types' => false, 'limit_level' => 1, 'info_wrapper' => true));
     if (empty($collected)) {
         return;
     }
     foreach ($collected as &$opt) {
         switch ($opt['group']) {
             case 'container':
                 $_collected = array();
                 fw_collect_options($_collected, $opt['option']['options'], array('limit_option_types' => array(), 'limit_container_types' => false, 'limit_level' => 1, 'limit' => 1, 'info_wrapper' => false));
                 $has_containers = !empty($_collected);
                 unset($_collected);
                 $children_data = array('group' => 'container', 'id' => $opt['id']);
                 $args = array('title' => empty($opt['option']['title']) ? fw_id_to_title($opt['id']) : $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']);
                 if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) {
                     $args = array_merge($opt['option']['wp-customizer-args'], $args);
                 }
                 if ($has_containers) {
                     if ($parent_data) {
                         trigger_error($opt['id'] . ' panel can\'t have a parent (' . $parent_data['id'] . ')', E_USER_WARNING);
                         break;
                     }
                     $wp_customize->add_panel($opt['id'], $args);
                     $children_data['customizer_type'] = 'panel';
                 } else {
                     if ($parent_data) {
                         if ($parent_data['customizer_type'] === 'panel') {
                             $args['panel'] = $parent_data['id'];
                         } else {
                             trigger_error($opt['id'] . ' section can have only panel parent (' . $parent_data['id'] . ')', E_USER_WARNING);
                             break;
                         }
                     }
                     $wp_customize->add_section($opt['id'], $args);
                     $children_data['customizer_type'] = 'section';
                 }
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], $children_data);
                 unset($children_data);
                 break;
             case 'option':
                 $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']';
                 $args = array('label' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id);
                 if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) {
                     $args = array_merge($opt['option']['wp-customizer-args'], $args);
                 }
                 if ($parent_data) {
                     if ($parent_data['customizer_type'] === 'section') {
                         $args['section'] = $parent_data['id'];
                     } else {
                         trigger_error('Invalid control parent: ' . $parent_data['customizer_type'], E_USER_WARNING);
                         break;
                     }
                 } else {
                     // the option is not placed in a section, create a section automatically
                     $args['section'] = 'fw_option_auto_section_' . $opt['id'];
                     $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label']));
                 }
                 if (!class_exists('_FW_Customizer_Setting_Option')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-setting-option.php');
                 }
                 if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php');
                 }
                 $wp_customize->add_setting(new _FW_Customizer_Setting_Option($wp_customize, $setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null), 'fw_option' => $opt['option'])));
                 $wp_customize->add_control(new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args));
                 break;
             default:
                 trigger_error('Unknown group: ' . $opt['group'], E_USER_WARNING);
         }
     }
 }
Example #24
0
 public function get_locations()
 {
     $cache_key = 'fw_extensions_locations';
     try {
         return FW_Cache::get($cache_key);
     } catch (FW_Cache_Not_Found_Exception $e) {
         /**
          * { '/hello/world/extensions' => 'https://hello.com/world/extensions' }
          */
         $custom_locations = apply_filters('fw_extensions_locations', array());
         $customizations_locations = array();
         if (is_child_theme()) {
             $customizations_locations[fw_get_stylesheet_customizations_directory('/extensions')] = fw_get_stylesheet_customizations_directory_uri('/extensions');
         }
         $customizations_locations[fw_get_template_customizations_directory('/extensions')] = fw_get_template_customizations_directory_uri('/extensions');
         $customizations_locations += $custom_locations;
         $locations = array();
         $locations[fw_get_framework_directory('/extensions')] = array('path' => fw_get_framework_directory('/extensions'), 'uri' => fw_get_framework_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => true, 'custom' => false, 'theme' => false));
         foreach ($custom_locations as $path => $uri) {
             unset($customizations_locations[$path]);
             $locations[$path] = array('path' => $path, 'uri' => $uri, 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => true, 'theme' => false));
         }
         array_pop($customizations_locations);
         $locations[fw_get_template_customizations_directory('/extensions')] = array('path' => fw_get_template_customizations_directory('/extensions'), 'uri' => fw_get_template_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true));
         if (is_child_theme()) {
             array_pop($customizations_locations);
             $locations[fw_get_stylesheet_customizations_directory('/extensions')] = array('path' => fw_get_stylesheet_customizations_directory('/extensions'), 'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions'), 'customizations_locations' => $customizations_locations, 'is' => array('framework' => false, 'custom' => false, 'theme' => true));
         }
         FW_Cache::set($cache_key, $locations);
         return $locations;
     }
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     $data['value']['coordinates'] = isset($data['value']['coordinates']) ? json_encode($data['value']['coordinates']) : '';
     $path = fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/views/view.php');
     return fw_render_view($path, array('id' => $id, 'option' => $option, 'data' => $data));
 }
 /**
  * @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
  */
 protected function _render($id, $option, $data)
 {
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'move_img_src' => fw_get_framework_directory_uri('/static/img/sort-vertically.png')));
 }
 /**
  * @internal
  */
 protected function _render($id, $option, $data)
 {
     $option = $this->check_parameters($option);
     $data = $this->check_data($option, $data);
     return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data));
 }
 /**
  * {@inheritdoc}
  * @param array $args
  * * source_dir
  * * destinations - {'dir_id': 'destination_path'}
  * * [filesystem_args] - {}|{hostname: '', username: '', password: '', connection_type: ''}
  */
 public function execute(array $args, array $state = array())
 {
     $backups = fw_ext('backups');
     /** @var FW_Extension_Backups $backups */
     $upload_dir = wp_upload_dir();
     $upload_dir = fw_fix_path($upload_dir['basedir']);
     if (empty($args['source_dir'])) {
         return new WP_Error('no_source_dir', __('Source dir not specified', 'fw'));
     } else {
         $args['source_dir'] = fw_fix_path($args['source_dir']);
         if (empty($args['source_dir']) || !file_exists($args['source_dir'])) {
             return new WP_Error('invalid_source_dir', __('Invalid source dir', 'fw'));
         }
     }
     if (empty($args['destinations'])) {
         return new WP_Error('no_source', __('Source dirs not specified', 'fw'));
     } else {
         $args['destinations'] = array_map('fw_fix_path', $args['destinations']);
     }
     if (empty($args['skip_dirs'])) {
         $args['skip_dirs'] = array();
     }
     $args['skip_dirs'] = array_merge($args['skip_dirs'], array($backups->get_tmp_dir() => true, $backups->get_backups_dir() => true, $upload_dir . '/backup' => true, fw_get_framework_directory() => true));
     if (empty($state)) {
         $fs_required = false;
         $upload_dir_regex = '/^' . preg_quote($upload_dir, '/') . '/';
         $destinations = array('no_fs' => array(), 'fs' => array());
         foreach ($args['destinations'] as $dir_id => $dir_path) {
             $dir_path = fw_fix_path($dir_path);
             if (!file_exists($args['source_dir'] . '/' . $dir_id) || !file_exists($dir_path)) {
                 continue;
             }
             $is_in_uploads = preg_match($upload_dir_regex, $dir_path);
             $destinations[$is_in_uploads ? 'no_fs' : 'fs'][$dir_id] = array('fs' => !$is_in_uploads, 'dir' => $dir_path);
             if (!$is_in_uploads) {
                 $fs_required = true;
             }
         }
         $destinations = array_merge($destinations['no_fs'], $destinations['fs']);
         if (empty($destinations)) {
             return true;
         }
         $state = array('pending_destinations' => $destinations, 'current_destination' => array('id' => null, 'data' => null), 'fs_required' => $fs_required);
         unset($destinations);
         $state['current_destination']['id'] = key($state['pending_destinations']);
         $state['current_destination']['data'] = array_shift($state['pending_destinations']);
     }
     if ($state['fs_required']) {
         if (!FW_WP_Filesystem::has_direct_access(ABSPATH)) {
             if (empty($args['filesystem_args'])) {
                 return new WP_Error('fs_no_access', __('No filesystem access, credentials required', 'fw'));
             } elseif (!WP_Filesystem($args['filesystem_args'])) {
                 return new WP_Error('invalid_fs_credentials', __('No filesystem access, invalid credentials', 'fw'));
             }
         } else {
             if (!WP_Filesystem()) {
                 return new WP_Error('fs_init_fail', __('Filesystem init failed', 'fw'));
             }
         }
         global $wp_filesystem;
         /** @var WP_Filesystem_Base $wp_filesystem */
         if (!$wp_filesystem || is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
             return new WP_Error('fs_init_fail', __('Filesystem init failed', 'fw'));
         }
     }
     while ($state['current_destination']['id']) {
         if (is_wp_error($result = $this->clear_dir($state['current_destination']['data']['dir'], $state['current_destination']['data']['fs'], $args['skip_dirs']))) {
             return $result;
         }
         if (is_wp_error($result = $this->copy_dir($args['source_dir'] . '/' . $state['current_destination']['id'], $state['current_destination']['data']['dir'], $state['current_destination']['data']['fs'], $args['skip_dirs']))) {
             return $result;
         }
         $state['current_destination']['id'] = key($state['pending_destinations']);
         $state['current_destination']['data'] = array_shift($state['pending_destinations']);
     }
     return true;
 }
 /**
  * @param WP_Customize_Manager $wp_customize
  * @param array $options
  * @param array $parent_data {'type':'...','id':'...'}
  */
 private function customizer_register_options($wp_customize, $options, $parent_data = array())
 {
     $collected = array();
     fw_collect_first_level_options($collected, $options);
     if (empty($collected['all'])) {
         return;
     }
     foreach ($collected['all'] as &$opt) {
         switch ($opt['type']) {
             case 'tab':
                 $args = array('title' => $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']);
                 if ($parent_data) {
                     trigger_error('Not supported panel parent, type: ' . $parent_data['type'], E_USER_WARNING);
                     break;
                 }
                 $wp_customize->add_panel($opt['id'], $args);
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'panel', 'id' => $opt['id']));
                 break;
             case 'box':
                 $args = array('title' => $opt['option']['title']);
                 if ($parent_data) {
                     if ($parent_data['type'] === 'panel') {
                         $args['panel'] = $parent_data['id'];
                     } else {
                         trigger_error('Not supported section parent, type: ' . $parent_data['type'], E_USER_WARNING);
                         break;
                     }
                 }
                 $wp_customize->add_section($opt['id'], $args);
                 $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'section', 'id' => $opt['id']));
                 break;
             case 'option':
                 $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']';
                 $args = array('label' => empty($opt['option']['label']) ? '' : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id, 'type' => 'radio', 'choices' => array('a' => 'Demo A', 'b' => 'Demo B'));
                 if ($parent_data) {
                     if ($parent_data['type'] === 'section') {
                         $args['section'] = $parent_data['id'];
                     } else {
                         trigger_error('Not supported control parent, type: ' . $parent_data['type'], E_USER_WARNING);
                         break;
                     }
                 } else {
                     // the option is not placed in a section, create a section automatically
                     $args['section'] = 'fw_option_auto_section_' . $opt['id'];
                     $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label']));
                 }
                 if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) {
                     require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php');
                 }
                 $wp_customize->add_setting($setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null)));
                 $control = new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args, array('fw_option' => $opt['option']));
                 add_filter("customize_sanitize_{$setting_id}", array($control, 'setting_sanitize_callback'), 10, 2);
                 $wp_customize->add_control($control);
                 break;
             default:
                 trigger_error('Not supported option in customizer, type: ' . $opt['type'], E_USER_WARNING);
                 // todo: uncomment
         }
     }
 }