first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,357 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
class FW_Extension_Sidebars extends FW_Extension {
/** @var _FW_Extension_Sidebars_Backend */
private $backend;
/** @var _FW_Extension_Sidebars_Frontend */
private $frontend;
/**
* key for saving/get data from wp_option
*/
public function get_fw_option_sidebars_settings_key() {
$current_theme = wp_get_theme();
return $current_theme->get_stylesheet() . '-fw-sidebars-options';
}
public function is_missing_config() {
$positions = $this->backend->config->get_sidebar_positions();
if ( empty( $positions ) or false === is_array( $positions ) ) {
return true;
}
return false;
}
public function get_sidebars_for_select() {
$sidebars = $this->get_sidebars();
$collector = array();
foreach ( $sidebars as $sidebar ) {
$collector[ $sidebar->get_id() ] = $sidebar->get_name();
}
return array(
'choices' => $collector
);
}
public function save_sidebar_settings( $settings ) {
return $this->backend->save_sidebar_settings( $settings );
}
/**
* @param $args
* @return array
* @since 1.0.10
*/
public function delete_sidebar_preset( $args ) {
return $this->backend->remove_preset( $args );
}
/**
* @internal
*/
protected function _init() {
$this->backend = new _FW_Extension_Sidebars_Backend();
$this->backend->init_sidebars();
add_filter( 'fw_post_options', array( $this, '_admin_filter_render_sidebar_picker' ), 10, 2 );
if ( is_admin() ) {
$this->add_admin_actions();
} else {
$this->add_theme_actions();
}
add_action('fw_option_types_init', array($this, '_action_option_types_init'));
add_action('fw:option-storage-types:register', array($this, '_action_register_option_storage_types'));
}
public function _action_option_types_init() {
require_once dirname(__FILE__) .'/includes/option-type/sidebar-picker/class-fw-option-type-sidebar-picker.php';
}
public function _action_register_option_storage_types(_FW_Option_Storage_Type_Register $register) {
require_once dirname(__FILE__) .'/includes/option-storage-type/class-fw-option-storage-type-fw-ext-sidebar-picker.php';
$register->register(new FW_Option_Storage_Type_FW_Ext_Sidebar_Picker());
}
private function add_theme_actions() {
if ( $this->is_missing_config() ) {
add_filter( 'sidebars_widgets', array( $this->get_frontend_instance(), 'replace_sidebars' ) );
}
}
private function add_admin_actions() {
add_action( 'admin_enqueue_scripts', array( $this, '_admin_action_enqueue_scripts' ) );
add_action( 'sidebar_admin_page', array( $this, '_admin_action_render_partial' ) );
if ( current_user_can( 'edit_theme_options' ) ) {
add_action( 'wp_ajax_add_new_sidebar_ajax', array( $this, '_admin_action_add_new_sidebar_ajax' ) );
add_action( 'wp_ajax_sidebar_autocomplete_ajax', array($this, '_admin_action_sidebar_autocomplete_ajax') );
add_action( 'wp_ajax_save_sidebar_preset_ajax', array( $this, '_admin_action_save_sidebar_preset_ajax' ) );
add_action( 'wp_ajax_remove_sidebar_preset_ajax', array($this, '_admin_action_remove_sidebar_preset_ajax') );
add_action( 'wp_ajax_delete_sidebar_ajax', array( $this, '_admin_action_delete_sidebar_ajax' ) );
add_action( 'wp_ajax_load_sidebar_preset_ajax', array( $this, '_admin_action_load_sidebar_preset_ajax' ) );
}
}
public function _admin_filter_render_sidebar_picker($options, $post_type) {
$post_type_array = $this->get_config('post_types_support');
if ($this->get_config('show_in_post_types') === true) {
if ( ! empty($post_type_array) && ! in_array($post_type, $post_type_array) ) {
return $options;
}
return array_merge($options, array(
'sidebar-picker' => array(
'title' => __('Sidebar Picker', 'fw'),
'type' => 'box',
'context' => 'side',
'options' => array(
'sidebar' => array(
'type' => 'sidebar-picker',
'label' => false,
'fw-storage' => 'fw-ext-sidebar-picker',
)
),
),
));
}
return $options;
}
/**
* @internal
*/
public function _admin_action_enqueue_scripts( $hook ) {
if ( 'widgets.php' === $hook ) {
wp_enqueue_style(
'fw-extension-' . $this->get_name() . '-css',
$this->get_declared_URI( '/static/css/sidebar.css' ),
array( 'fw', 'fw-selectize', 'fw-backend-options' ),
fw()->manifest->get_version()
);
wp_enqueue_script( 'fw-extension-' . $this->get_name() . '-autocomplete-js',
$this->get_declared_URI( '/static/js/sidebar-autocomplete.js' ),
array( 'fw-events', 'jquery', 'jquery-ui-autocomplete', 'fw' ),
fw()->manifest->get_version()
);
wp_localize_script( 'fw-extension-' . $this->get_name() . '-autocomplete-js', 'noMatchesFoundMsg', __( 'No matches found', 'fw' ) );
wp_enqueue_script( 'fw-extension-' . $this->get_name() . '-general-js',
$this->get_declared_URI( '/static/js/sidebar-general.js' ),
array( 'fw-events', 'jquery', 'fw', 'fw-selectize', 'jquery-ui-tabs' ),
fw()->manifest->get_version()
);
wp_localize_script( 'fw-extension-' . $this->get_name() . '-general-js', 'PhpVar', array(
'confirmMessage' => __( 'Do you realy want to change without saving?', 'fw' ),
'dynamicSidebars' => $this->backend->get_dynamic_sidebars_ids(),
'missingIdMessage' => __( 'Missing ID. Check that you provided all mandatory data.', 'fw' ),
'createdTabName' => __( 'Created', 'fw' ),
'groupedTabDesc' => __( '(For Grouped Pages)', 'fw' ),
'specificTabDesc' => __( '(For Specific Pages)', 'fw' ),
'missingSidebarName' => __( 'No sidebar name specified', 'fw' ),
'newSidebarPlaceholder' => __( 'Sidebar Name', 'fw' ),
'newSidebarLabel' => __( 'New Sidebar', 'fw' ),
'addSidebarButtonTxt' => __( 'Add', 'fw' ),
'msgToConfirmDelete' => __( 'Are you sure you want to delete it?', 'fw' ),
) );
}
}
/**
* @internal
*/
public function _admin_action_delete_sidebar_ajax() {
$sidebar_id = FW_Request::POST( 'sidebar' );
$result = $this->backend->delete_sidebar( $sidebar_id );
$this->ajax_response( $result );
}
/**
* @internal
*/
public function _admin_action_load_sidebar_preset_ajax() {
$params = FW_Request::POST( 'params' );
$result = $this->backend->get_preset( $params );
$this->ajax_response( $result );
}
/**
* @internal
*/
public function _admin_action_remove_sidebar_preset_ajax() {
$args = FW_Request::POST( 'data' );
$result = $this->backend->remove_preset( $args );
$this->ajax_response( $result );
}
/**
* @internal
*/
public function _admin_action_save_sidebar_preset_ajax() {
$settings = FW_Request::POST( 'settings' );
$result = $this->backend->save_sidebar_settings( $settings );
$this->ajax_response( $result );
}
/**
* @internal
*/
public function _admin_action_sidebar_autocomplete_ajax() {
$search_type = FW_Request::POST( 'searchType' );
$search_term = FW_Request::POST( 'searchTerm' );
$result = $this->backend->get_autocomplete_results( $search_type, $search_term );
$this->ajax_response( $result );
}
public function get_data_positions_options() {
$sidebar_positions = $this->backend->config->get_sidebar_positions();
$choices = array();
foreach ( $sidebar_positions as $key => $position ) {
$choices[ $key ] = array(
'label' => false,
'small' => $position['icon_url'],
'data' => array(
'colors' => fw_akg( _FW_Extension_Sidebars_Config::SIDEBARS_NR_KEY, $position )
)
);
}
$data_positions_options = array(
'type' => 'image-picker',
'choices' => $choices,
'value' => '',
'attr' => array( 'class' => 'fw-ext-sidebars-positions' )
);
return $data_positions_options;
}
/**
* Render partial on widgets.php page
* @internal
*/
public function _admin_action_render_partial() {
$specific_options = array(
'type' => 'select',
'choices' => $this->backend->config->get_specific_labels(),
'value' => ''
);
$grouped_options = array(
'type' => 'select',
'choices' => $this->backend->config->get_grouped_labels(),
'value' => ''
);
$created_sidebars = $this->backend->get_presets_sidebars();
$sidebars = $this->backend->get_all_sidebars();
echo $this->render_view( 'backend-main-view', array(
'grouped_options' => $grouped_options, //options for select grouped pages tab
'specific_options' => $specific_options, //options for select specific page tab
'created_sidebars' => $created_sidebars, //used for removable items on created tab
'data_positions_options' => $this->get_data_positions_options(), //used for image-picker
'sidebars' => $sidebars, //used for selectize options on grouped and specific tabs
) );
}
public function get_presets_sidebars() {
return $this->backend->get_presets_sidebars();
}
public function get_sidebars() {
return $this->backend->get_all_sidebars();
}
/**
* @internal
*/
public function _admin_action_add_new_sidebar_ajax() {
$name = FW_Request::POST( 'name' );
$result = $this->backend->save_new_sidebar( $name );
$this->ajax_response( $result );
}
/**
* return standards WP AJAX responses
*/
private function ajax_response( $result ) {
if ( isset( $result['status'] ) ) {
if ( $result['status'] ) {
unset( $result['status'] );
wp_send_json_success( $result );
} else {
unset( $result['status'] );
wp_send_json_error( $result );
}
} else {
wp_send_json( $result );
}
}
public function get_specific_preset_by_id( $id ) {
return $this->backend->get_specific_preset_by_id( $id );
}
private function get_frontend_instance() {
if ( ! $this->frontend ) {
$this->frontend = new _FW_Extension_Sidebars_Frontend();
}
return $this->frontend;
}
public function render_sidebar( $color ) {
return $this->get_frontend_instance()->render_sidebar( $color );
}
public function get_current_preset() {
return $this->get_frontend_instance()->get_current_page_preset();
}
/**
* @since 1.0.6
*/
public function get_current_position() {
return $this->get_frontend_instance()->get_preset_position();
}
/**
* Old method with typo in name.
* We didn't deleted it because there may be someone that is calling it (because it is public)
* @deprecated
*/
public function get_current_positon() {
return $this->get_current_position();
}
/**
* @return array
*/
public function get_allowed_places() {
return $this->backend->_fw_get_allowed_places();
}
/**
* {@inheritdoc}
*/
public function _get_link() {
return self_admin_url( 'widgets.php' );
}
}

View File

@@ -0,0 +1,40 @@
<?php
$cfg = array();
/**
* Config example
*/
/*
$cfg['sidebar_positions'] = array(
'full' => array(
'icon_url' => 'full.png',
'sidebars_number' => 0
),
'left' => array(
'icon_url' => 'left.png',
'sidebars_number' => 1
),
'right' => array(
'icon_url' => 'right.png',
'sidebars_number' => 1
),
'left_right' => array(
'icon_url' => 'left_right.png',
'sidebars_number' => 2
),
);
$cfg['dynamic_sidebar_args'] = array(
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
);
*/
/**
* Render sidebar metabox in post types.
*/
$cfg['show_in_post_types'] = false;

View File

@@ -0,0 +1,28 @@
<?php if (!defined('FW')) die('Forbidden');
/**
* Returns the sidebar HTML or warning message
*
* @param $color look in _FW_Extension_Sidebars_Config::$allowed_colors
*/
function fw_ext_sidebars_show($color)
{
return fw()->extensions->get('sidebars')->render_sidebar($color);
}
/**
* Returns string (position-id) if DB has preset for current page else return false
*
*/
function fw_ext_sidebars_get_current_position()
{
return fw()->extensions->get('sidebars')->get_current_position();
}
/**
* Returns array if DB has preset for current page else return null
*/
function fw_ext_sidebars_get_current_preset()
{
return fw()->extensions->get('sidebars')->get_current_preset();
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Add ability to WP_Query to find out posts by title for the sidebars auto-complete
* @internal
*/
function _filter_fw_ext_sidebars_title_like_posts_where( $where, $wp_query ) {
/**
* @var WPDB $wpdb
*/
global $wpdb;
if ( $post_title_like = $wp_query->get( 'fw_ext_sidebars_post_title_like' ) ) {
$where .= $wpdb->prepare(' AND ' . $wpdb->posts . '.post_title LIKE %s', '%'. $wpdb->esc_like( $post_title_like ) .'%' );
}
return $where;
}
add_filter( 'posts_where', '_filter_fw_ext_sidebars_title_like_posts_where', 10, 2);
function _filter_fw_ext_sidebars_ext_backups_db_restore_option_names_replace($option_names, $params) {
if (isset($params['stylesheet'])) {
/** @see FW_Extension_Sidebars::get_fw_option_sidebars_settings_key() */
$option_names[$params['stylesheet'] . '-fw-sidebars-options'] = get_stylesheet() . '-fw-sidebars-options';
}
return $option_names;
}
add_filter(
'fw_ext_backups_db_restore_option_names_replace',
'_filter_fw_ext_sidebars_ext_backups_db_restore_option_names_replace',
10, 2
);

View File

@@ -0,0 +1,930 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
/**
* Working with DB models and config on Backend
* @internal
*/
class _FW_Extension_Sidebars_Backend {
/** @var _FW_Extension_Sidebars_Model_Sidebar[] */
private $sidebars;
/** @var _FW_Extension_Sidebars_Config */
public $config;
/** @var _FW_Extension_Sidebars_Model_Sidebar[] */
public $static_sidebars;
//Key for update_option/get_option
private $wp_option_sidebar_settings;
public function __construct() {
//get static registered sidebars, which are registered before fw loaded
global $wp_registered_sidebars;
$this->wp_option_sidebar_settings = fw()->extensions->get( 'sidebars' )->get_fw_option_sidebars_settings_key();
$this->config = new _FW_Extension_Sidebars_Config();
if ( is_array( $wp_registered_sidebars ) ) {
foreach ( $wp_registered_sidebars as $sidebar_args ) {
$this->set_static_sidebars( $sidebar_args );
}
}
}
public function init_sidebars() {
$this->init_dynamic_sidebars();
add_action( 'register_sidebar', array( $this, 'set_static_sidebars' ) );
}
/**
* Register dynamic sidebars
*/
private function init_dynamic_sidebars() {
$sidebars = (array) $this->get_sidebars();
if ( is_array( $sidebars ) ) {
foreach ( $sidebars as $sidebar ) {
$sidebar->register();
}
}
}
/**
* Get dynamic & static sidebars
*/
public function get_all_sidebars() {
$dynamic_sidebars = $this->get_sidebars();
return array_merge( (array) $dynamic_sidebars, (array) $this->static_sidebars );
}
/**
* Get array of saved settings from db
*/
public function get_db() {
$db = get_option( $this->wp_option_sidebar_settings );
if ( empty( $db ) ) {
$db = array();
}
return $db;
}
/**
* Fill static_sidebars array with new sidebar model
*/
public function set_static_sidebars( $sidebar_args ) {
if ( $sidebar_args['id'] === 'wp_inactive_widgets' ) {
return;
}
if ( preg_match( '(inactive-sidebar)', $sidebar_args['class'] ) ) {
return;
}
if ( in_array( $sidebar_args['id'], $this->get_dynamic_sidebars_ids() ) ) {
return;
}
$this->static_sidebars[ $sidebar_args['id'] ] = new _FW_Extension_Sidebars_Model_Sidebar( $sidebar_args );
}
/**
* Get array of dynamic sidebars models
*/
public function get_sidebars() {
$dynamic_sidebars_args = $this->config->get_dynamic_sidebar_args();
if ( $this->sidebars === null ) {
$sidebars_array = $this->get_db();
if ( isset( $sidebars_array['sidebars'] ) && count( $sidebars_array['sidebars'] ) ) {
foreach ( $sidebars_array['sidebars'] as $sidebar_args ) {
$sidebar_args = array_merge( $dynamic_sidebars_args,
$sidebar_args ); //merge DB settings with config settings
$this->sidebars[ $sidebar_args['id'] ] = new _FW_Extension_Sidebars_Model_Sidebar( $sidebar_args );
}
unset( $sidebars_array );
return $this->sidebars;
}
}
return $this->sidebars;
}
public function get_dynamic_sidebars_ids() {
return is_array( $this->get_sidebars() ) ? array_keys( $this->get_sidebars() ) : array();
}
public function get_preset( $params ) {
if ( preg_match( '/^\d+$/', $params['preset'] ) ) {
return $this->get_preset_specific( $params );
} else {
return $this->get_preset_grouped( $params );
}
}
/**
* Get preset for grouped pages with ajax request params
*/
private function get_preset_grouped( $params ) {
//get preset data
$sub_type = $this->config->parse_sub_type( $params['slug'] );
$prefix = $this->config->parse_prefix( $params['slug'] );
$type = $this->config->get_type_by_prefix( $prefix );
$path = 'settings/' . $type . '/' . $sub_type . '/common';
$db = $this->get_db();
$result['preset'] = fw_akg( $path, $db, null );
if ( is_array( $result['preset'] ) ) {
$result['status'] = true;
$result['preset'] = array_merge( $result['preset'], $params );
$ids = fw_akg( 'preset/ids', $result );
if ( is_array( $ids ) ) {
$result['preset']['ids'] = $this->build_preset_ids_list( $prefix, $ids, $sub_type );
}
} else {
$result['status'] = false;
}
return $result;
}
/**
* Get preset for specific pages by ajax request params
*/
private function get_preset_specific( $args ) {
$db = $this->get_db();
$saved_presets = fw_akg( 'settings/saved_presets', $db, array() );
if ( ! in_array( $args['preset'], $saved_presets ) ) {
return array( 'status' => false );
}
$db_keys = $this->get_db_keys( $db );
$result = array();
foreach ( $db_keys as $db_key ) {
$preset = fw_akg( $db_key['path'] . '/by_ids/' . $args['preset'], $db );
if ( ! empty( $preset ) ) {
$singular_label = $this->config->get_label_singular( $db_key['type'], $db_key['sub_type'] );
$ids_list = $this->build_preset_ids_list( $db_key['prefix'], $preset['ids'],
$db_key['sub_type'] );
$result['by_ids'][] = array(
'slug' => $singular_label,
'ids' => $ids_list
);
unset( $preset['ids'] );
$result['preset'] = $preset;
$result['preset']['preset'] = $args['preset'];
$result['status'] = true;
}
}
return $result;
}
/**
* @param $id
*
* @return type _FW_Extension_Sidebars_Model_Sidebar or FALSE
*/
public function get_sidebar_by_id( $id ) {
$sidebars = $this->get_sidebars();
if ( ! is_array( $sidebars ) ) {
return false;
}
if ( array_key_exists( $id, $sidebars ) ) {
return $sidebars[ $id ];
} else {
return false;
}
}
/**
* Generate valid unique sidebar id from name
*/
public function generate_sidebar_id( $name ) {
$result = preg_replace( array( '/\s+/', '/[^a-z0-9\-]/i', ), array( '-', '' ), $name );
if ( ! strlen( $result ) ) {
$result = 'fw-sidebar';
}
if ( preg_match( '/^(aa|jj|hh|\d+)$/i', $name ) ) {
$result = 'fw-sidebar-' . $name;
}
$k = 0;
do {
$new_id = $result . ( $k ++ == 0 ? '' : ( '-' . ( $k - 1 ) ) );
if ( $this->get_sidebar_by_id( $new_id ) === false && ! isset( $this->static_sidebars[ $new_id ] ) ) {
$result = $new_id;
break;
}
} while ( 1 );
return $result;
}
/**
* Save new sidebar to DB
*
* @param $save_sidebar_fields 'general' - save only sidebar id and sidebar name, 'all' - save all info
* @param $name string - sidebar name
*
* @return array
*/
public function save_new_sidebar( $name, $save_sidebar_fields = 'general' ) {
if ( ! strlen( trim( $name ) ) ) {
return array( 'status' => false, 'message' => __( 'No sidebar name specified.', 'fw' ) );
}
$sidebar_args = $this->config->get_dynamic_sidebar_args();
$sidebar_args['name'] = $name;
$sidebar = new _FW_Extension_Sidebars_Model_Sidebar( $sidebar_args );
$db = $this->get_db();
$sidebar->set_id( $this->generate_sidebar_id( $sidebar->get_name() ) );
$db['sidebars'][ $sidebar->get_id() ] = $sidebar->to_array( $save_sidebar_fields );
$result['status'] = update_option( $this->wp_option_sidebar_settings, array_filter( $db ), false );
if ( $result['status'] ) {
$result['sidebar'] = $sidebar->to_array( $save_sidebar_fields );
}
return $result;
}
/**
* Remove sidebar from db's sidebars list
*/
public function delete_sidebar( $sidebar_id ) {
$db = $this->get_db();
if ( ! isset( $db['sidebars'][ $sidebar_id ] ) ) {
return array( 'status' => false, 'message' => __( 'Dynamic sidebar doesn\'t exixt', 'fw' ) );
}
$sidebar_used_key = $this->recursive_array_search( $sidebar_id, fw_akg( 'settings', $db, array() ) );
if ( $sidebar_used_key !== false ) {
return array(
'status' => false,
'message' => __( "The placeholder can't be deleted because it is used in one of sidebars below.",
'fw' ) .
"<br/><br/><b>" .
__( 'Please replace it first so that you will not have visual gaps in your layout.',
'fw' ) .
"<b/>"
);
}
fw_aku( 'sidebars/' . $sidebar_id, $db );
update_option( $this->wp_option_sidebar_settings, array_filter( $db ), false );
$sidebar_obj = new _FW_Extension_Sidebars_Model_Sidebar( array( 'id' => $sidebar_id ) );
$sidebar_obj->remove_widgets();
return array( 'status' => true, 'message' => __( 'Successfully removed', 'fw' ) );
}
/**
* Get results by user query for autocomplete
*/
public function get_autocomplete_results( $search_slug, $search_term, $max_autocomplete_results = 50 ) {
$search_type = $this->config->get_type_by_prefix( $this->config->parse_prefix( $search_slug ) );
$search_sub_type = $this->config->parse_sub_type( $search_slug );
$result = array(
'status' => false,
'items' => array(),
);
switch ( $search_type ) {
case 'post_types':
case 'archives':
$wp_query = new WP_Query( array(
'post_type' => $search_sub_type,
'fw_ext_sidebars_post_title_like' => $search_term,
'numberposts' => $max_autocomplete_results,
'post_status' => 'any'
) );
$items = $wp_query->get_posts();
wp_reset_query();
foreach ( $items as $item ) {
$result['items'][ $item->ID ] = $item->post_title;
}
$result['status'] = true;
unset( $items );
break;
case 'taxonomies':
$items = get_terms( $search_sub_type, array(
'name__like' => $search_term,
'hide_empty' => false,
'number' => $max_autocomplete_results
) );
foreach ( $items as $item ) {
$result['items'][ $item->term_id ] = $item->name;
}
$result['status'] = true;
unset( $items );
break;
default:
$result['status'] = false;
break;
}
return $result;
}
public function recursive_array_search( $needle, $haystack ) {
foreach ( $haystack as $key => $value ) {
$current_key = $key;
if ( $needle === $value OR ( is_array( $value ) && $this->recursive_array_search( $needle,
$value ) !== false )
) {
return $current_key;
}
}
return false;
}
/**
* Specifies the type of preset by ajax arguments and calls the appropriate method.
*/
public function remove_preset( $args ) {
if ( $args['slug'] ) {
return array(
'status' => $this->remove_preset_grouped( $args )
);
} else {
return array(
'status' => $this->remove_preset_specific( $args )
);
}
}
/**
* Remove preset from DB, which has ids inside
*/
private function remove_preset_specific( $args ) {
if ( ! preg_match( '/^\d+$/', $args['preset'] ) ) {
return false;
}
$db = $this->get_db();
$saved_presets = fw_akg( 'settings/saved_presets', $db, array() );
if ( ! in_array( $args['preset'], $saved_presets ) ) {
return false;
}
$db_keys = $this->get_db_keys( $db );
fw_aku( 'settings/saved_presets/' . array_search( $args['preset'], $saved_presets ), $db );
foreach ( $db_keys as $db_key ) {
fw_aku( $db_key['path'] . '/by_ids/' . $args['preset'], $db );
$this->recalculate_saved_ids( $db, $db_key['type'], $db_key['sub_type'] );
$this->clean_unused_arrays( $db, $db_key['type'], $db_key['sub_type'] );
}
return update_option( $this->wp_option_sidebar_settings, $db, false );
}
/**
* Remove common preset from DB
*/
private function remove_preset_grouped( $item ) {
$db = $this->get_db();
$sub_type = $this->config->parse_sub_type( $item['slug'] );
$prefix = $this->config->parse_prefix( $item['slug'] );
$type = $this->config->get_type_by_prefix( $prefix );
if ( empty( $type ) or empty( $sub_type ) ) {
return false;
}
unset( $db['settings'][ $type ][ $sub_type ]['common'] );
$this->clean_unused_arrays( $db, $type, $sub_type );
return update_option( $this->wp_option_sidebar_settings, $db, false );
}
protected function clean_unused_arrays( &$db, $type, $sub_type ) {
if ( $type === 'saved_presets' ) {
return false;
}
if ( isset( $db['settings'][ $type ][ $sub_type ]['by_ids'] ) and empty( $db['settings'][ $type ][ $sub_type ]['by_ids'] ) ) {
unset( $db['settings'][ $type ][ $sub_type ]['by_ids'] );
}
if ( isset( $db['settings'][ $type ][ $sub_type ]['saved_ids'] ) and empty( $db['settings'][ $type ][ $sub_type ]['saved_ids'] ) ) {
unset( $db['settings'][ $type ][ $sub_type ]['saved_ids'] );
}
if ( isset( $db['settings'][ $type ][ $sub_type ] ) and empty( $db['settings'][ $type ][ $sub_type ] ) ) {
unset( $db['settings'][ $type ][ $sub_type ] );
}
if ( isset( $db['settings'][ $type ] ) and empty( $db['settings'][ $type ] ) ) {
unset( $db['settings'][ $type ] );
}
}
public function get_saved_ids( $type, $sub_type ) {
$db = $this->get_db();
return fw_akg( 'settings/' . $type . '/' . $sub_type . '/saved_ids', $db, array() );
}
/*
* Make unique array with ids in &$db parameter
*/
public function recalculate_saved_ids( &$db, $type, $sub_type ) {
if ( $type === $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::CONDITIONAL_TAGS_PREFIX ) or $type === 'saved_presets' ) {
return false;
}
$result = array();
$presets = fw_akg( 'settings/' . $type . '/' . $sub_type . '/by_ids', $db );
if ( is_array( $presets ) ) {
foreach ( $presets as $preset ) {
$result = array_merge( $result, $preset['ids'] );
}
}
$result = array_unique( $result );
fw_aks( 'settings/' . $type . '/' . $sub_type . '/saved_ids', $result, $db );
return true;
}
public function get_specific_preset_by_id( $id ) {
$result = array();
$settings = $this->get_db();
$type = 'post_types';
$subtype = get_post_type( $id );
$presets = fw_akg( 'settings/' . $type . '/' . $subtype, $settings );
if ( ! is_null( $presets ) && ! empty( $presets['saved_ids'] ) ) {
if ( in_array( $id, $presets['saved_ids'] ) ) {
foreach ( $presets['by_ids'] as $key => $preset ) {
if ( in_array( $id, $preset['ids'] ) ) {
$result[] = array_merge(
array(
'preset_id' => $key,
),
$preset
);
}
}
}
usort( $result, array( $this, 'preset_timestamp_cmp' ) );
$result = (array) array_pop( $result );
}
return $result;
}
/**
* GET presets settings for Created Tab
*/
public function get_presets_sidebars() {
$result = array();
$settings = $this->get_db();
if ( ! isset( $settings['settings'] ) ) {
return $result;
}
$db_keys = $this->get_db_keys( $settings );
//build by_ids presets
if ( isset( $settings['settings']['saved_presets'] ) ) {
foreach ( $settings['settings']['saved_presets'] as $preset_id ) {
foreach ( $db_keys as $db_key ) {
if ( count( fw_akg( $db_key['path'] . '/saved_ids', $settings, array() ) ) ) {
$preset = fw_akg( $db_key['path'] . '/by_ids/' . $preset_id, $settings );
if ( is_array( $preset ) ) {
$singular_label = $this->config->get_label_singular( $db_key['type'], $db_key['sub_type'] );
$page_names = reset( $singular_label ) . ' - ' . implode( ', ',
$this->build_preset_ids_list( $db_key['prefix'], $preset['ids'],
$db_key['sub_type'] ) );
$result[ $preset_id ] = array(
'label' => reset( $singular_label ),
'preset_id' => $preset_id,
'page_names' => ( isset( $result[ $preset_id ]['page_names'] ) ? $result[ $preset_id ]['page_names'] : '' ) . $page_names . ' ',
'timestamp' => isset( $preset['timestamp'] ) ? $preset['timestamp'] : 0
);
}
}
}
}
}
//build common presets
foreach ( $db_keys as $slug => $db_key ) {
$preset = fw_akg( $db_key['path'] . '/common', $settings );
if ( is_array( $preset ) ) {
$grouped_label = $this->config->get_label_grouped( $db_key['type'], $db_key['sub_type'] );
$result[] = array(
'type' => $slug,
'label' => $db_key['sub_type'] === 'common' ? __( 'Default for all pages',
'fw' ) : reset( $grouped_label ),
'timestamp' => isset( $preset['timestamp'] ) ? $preset['timestamp'] : 0
);
}
}
usort( $result, array( $this, 'preset_timestamp_cmp' ) );
return $result;
}
private function preset_timestamp_cmp( $a, $b ) {
if ( $a['timestamp'] === $b['timestamp'] ) {
return 0;
}
return ( $a['timestamp'] < $b['timestamp'] ) ? - 1 : 1;
}
/**
* Generate existing keys in array for fw_akg/fw_aks/fw_aku helpers
*/
public function get_db_keys( &$settings ) {
$result = array();
if ( ! isset( $settings['settings'] ) ) {
return $result;
}
foreach ( $settings['settings'] as $type => $sub_types ) {
if ( $type === 'saved_presets' ) {
continue;
}
$prefix = $this->config->get_prefix_by_type( $type );
foreach ( $sub_types as $sub_type => $presets ) {
$result[ $prefix . '_' . $sub_type ] = array(
'path' => "settings/$type/$sub_type",
'prefix' => $prefix,
'type' => $type,
'sub_type' => $sub_type
);
}
}
return $result;
}
/**
* Make array with [id] => (post / term) name
*/
public function build_preset_ids_list( $prefix, &$ids, $sub_type ) {
$result = array();
foreach ( $ids as $id ) {
if ( $prefix === _FW_Extension_Sidebars_Config::POST_TYPES_PREFIX ) {
$obj = get_post( $id );
$this->_set_title_from_object( $obj, $id, 'post_title', $result );
} else if ( $prefix === _FW_Extension_Sidebars_Config::TAXONOMIES_PREFIX ) {
$obj = get_term( $id, $sub_type );
$this->_set_title_from_object( $obj, $id, 'name', $result );
}
}
return $result;
}
private function _set_title_from_object( $obj, $id, $field_name, &$result ) {
if ( ! empty( $obj ) ) {
$vars = get_object_vars( $obj );
if ( isset( $vars[ $field_name ] ) ) {
$result[ $id ] = empty( $vars[ $field_name ] ) ? '#' . $id . __( ' (no title)',
'fw' ) : $vars[ $field_name ];
} else {
$result[ $id ] = $prefix . '_' . $sub_type . '_' . $id;
}
}
}
/**
* Save settings for specific pages/grouped pages/conditional tags
*/
public function update_preset( $preset ) {
$db = $this->get_db();
$path = 'settings/' . $preset['type'] . '/' . $preset['sub_type'];
$value['position'] = $preset['position'];
$value['sidebars'] = $preset['sidebars'];
$value['timestamp'] = time();
if ( is_array( $preset['ids'] ) and ! empty( $preset['ids'] ) ) {
$value['ids'] = $preset['ids'];
}
if ( is_array( $preset['ids'] ) ) {
$path .= '/by_ids/' . $preset['preset'];
} else {
$path .= '/common';
}
fw_aks( $path, $value, $db );
if ( is_array( $preset['ids'] ) ) {
$this->recalculate_saved_ids( $db, $preset['type'], $preset['sub_type'] );
$this->clean_unused_arrays( $db, $preset['type'], $preset['sub_type'] );
$saved_presets = fw_akg( 'settings/saved_presets', $db, array() );
if ( ! in_array( $preset['preset'], $saved_presets ) ) {
$saved_presets[] = $preset['preset'];
fw_aks( 'settings/saved_presets', $saved_presets, $db );
}
}
update_option( $this->wp_option_sidebar_settings, $db, false );
return true;
}
/**
* Remove presets from db which was removed on specific pages
*/
public function clean_unused_presets( $slugs, $preset_id ) {
if ( $preset_id === null ) {
return false;
}
$db = $this->get_db();
foreach ( $db['settings'] as $type => $data ) {
foreach ( $data as $sub_type => $data2 ) {
$prefix = $this->config->get_prefix_by_type( $type );
if ( ! in_array( $prefix . '_' . $sub_type, $slugs ) ) {
fw_aku( 'settings/' . $type . '/' . $sub_type . '/by_ids/' . $preset_id, $db );
$this->recalculate_saved_ids( $db, $type, $sub_type );
$this->clean_unused_arrays( $db, $type, $sub_type );
}
}
}
update_option( $this->wp_option_sidebar_settings, $db, false );
return true;
}
/**
* Generate unique preset id for specific pages tab
*/
public function generate_preset_id() {
$saved_presets = $this->get_db();
$saved_presets = fw_akg( 'settings/saved_presets', $saved_presets, array() );
$key = 0;
while ( in_array( $key, $saved_presets ) ) {
$key ++;
}
return $key;
}
/**
* Save grouped pages tab or specific page tab settings
*/
public function save_sidebar_settings( $settings ) {
try {
// Preset validate & saving for grouped pages tab
if ( isset( $settings['slug'] ) and $settings['slug'] ) {
$preset = $this->validate_preset( $settings );
$result['status'] = $this->update_preset( $preset );
if ( $result['status'] ) {
$grouped_label = $this->config->get_label_grouped( $preset['type'], $preset['sub_type'] );
$result['label'] = reset( $grouped_label );
$result['slug'] = key( $grouped_label );
}
} else {
// Preset validate & saving for specific tab
$new_key_preset = $this->generate_preset_id();
$slugs = array();
$preset_id = null;
$db = $this->get_db();
$saved_settings = fw_akg( 'settings/saved_presets', $db, array() );
if ( ! isset( $settings['selected'] ) or empty( $settings['selected'] ) ) {
throw new Exception( 'Error: Selection is empty' );
}
foreach ( $settings['selected'] as $preset ) {
$preset['sidebars'] = isset( $settings['sidebars'] ) ? $settings['sidebars'] : array();
$preset['position'] = isset( $settings['position'] ) ? $settings['position'] : null;
$preset['preset'] = isset( $settings['preset'] ) ? $settings['preset'] : null;
if ( ! isset( $preset['preset'] ) or ! preg_match( '/^\d+$/',
$preset['preset'] ) or ! in_array( $preset['preset'], $saved_settings )
) {
$preset['preset'] = $new_key_preset;
}
$preset = $this->validate_preset( $preset );
$result['status'] = $this->update_preset( $preset );
$slugs[] = $preset['slug'];
$preset_id = $preset['preset'];
if ( $result['status'] ) {
$singular_label = $this->config->get_label_singular( $preset['type'], $preset['sub_type'] );
$prefix = $this->config->get_prefix_by_type( $preset['type'] );
$page_names = reset( $singular_label ) . ' - ' . implode( ', ',
$this->build_preset_ids_list( $prefix, $preset['ids'], $preset['sub_type'] ) );
$result['preset'] = $preset_id;
$result['label'] = ( isset( $result['label'] ) ? $result['label'] : '' ) . $page_names . ' ';
}
}
$slugs = array_unique( $slugs );
$this->clean_unused_presets( $slugs, $preset_id );
}
} catch ( Exception $e ) {
$result['status'] = false;
$result['message'] = $e->getMessage();
if ( $e instanceof _FW_Extension_Sidebars_MissingSidebar_Exception ) {
$result['colors'] = $e->get_colors();
}
}
return $result;
}
/**
* validate ajax params
*/
private function validate_preset( $preset ) {
$prefix = $this->config->parse_prefix( $preset['slug'] );
$sub_type = $this->config->parse_sub_type( $preset['slug'] );
$type = $this->config->get_type_by_prefix( $prefix );
if ( ! $sub_type or ! $type ) {
throw new Exception( __( 'Error: Type or sub_type error', 'fw' ) );
}
$preset['type'] = $type;
$preset['sub_type'] = $sub_type;
if ( $this->config->is_enabled_select_option( $type, $sub_type ) === false ) {
throw new Exception( __( sprintf( 'Error this option (%s) is disabled', $type . '-' . $sub_type ), 'fw' ) );
}
if ( fw()->extensions->get( 'sidebars' )->is_missing_config() ) {
$this->_fw_check_allowed_replace_positions( $preset );
} else {
$this->_fw_check_allowed_colors( $preset );
}
//remove duplicates in array
if ( is_array( $preset['ids'] ) ) {
$preset['ids'] = array_unique( $preset['ids'] );
}
return $preset;
}
public function _fw_get_allowed_places() {
if ( fw()->extensions->get( 'sidebars' )->is_missing_config() ) {
$result = array();
if ( is_admin() ) {
$static_sidebars = array_keys( $this->static_sidebars );
$i = 0;
foreach ( $static_sidebars as $static_sidebar_id ) {
if ( $static_sidebar_id === 'wp_inactive_widgets' ) {
continue;
}
$result[ $static_sidebar_id ] = isset( _FW_Extension_Sidebars_Config::$allowed_colors[ $i ] ) ? _FW_Extension_Sidebars_Config::$allowed_colors[ $i ] : $static_sidebar_id;
$i ++;
}
}
$this->_fw_update_adapter( $result );
return $result;
}
$positions = $this->config->get_sidebar_positions();
$colors = _FW_Extension_Sidebars_Config::$allowed_colors;
$max = 1;
if( count( $positions ) && is_array( $positions ) ) {
foreach( $positions as $key => $sidebar ) {
$count = fw_akg( _FW_Extension_Sidebars_Config::SIDEBARS_NR_KEY, $sidebar );
if( $count > $max ) {
$max = $count;
}
}
}
if( $max > count( $colors ) ) {
return $colors;
} else {
return array_slice( $colors, 0, $max );
}
}
private function _fw_update_adapter( $allowed_places ) {
$db = $this->get_db();
fw_aks( 'allowed_places', $allowed_places, $db );
update_option( $this->wp_option_sidebar_settings, $db, false );
}
private function _fw_check_allowed_replace_positions( &$preset ) {
$exceptionMsg = __( 'Error: Sidebars not set', 'fw' );
if ( isset( $preset['sidebars'] ) and is_array( $preset['sidebars'] ) ) {
$exception = new _FW_Extension_Sidebars_MissingSidebar_Exception( $exceptionMsg );
$all_sidebars = $this->get_all_sidebars();
foreach ( $preset['sidebars'] as $replaced_sidebar => $sidebar_id ) {
if ( empty( $sidebar_id ) or ! in_array( $sidebar_id,
array_keys( $all_sidebars ) ) or ! in_array( $replaced_sidebar,
fw()->extensions->get( 'sidebars' )->get_allowed_places() )
) {
unset( $preset['sidebars'][ $replaced_sidebar ] );
$exception->add_color( $replaced_sidebar );
}
}
if ( $exception->has_colors() ) {
throw $exception;
}
} else {
$preset['sidebars'] = array();
}
$preset['position'] = '';
}
private function _fw_check_allowed_colors( &$preset ) {
if ( ! isset( $preset['position'] ) or ! $this->config->has_position( $preset['position'] ) ) {
throw new Exception( __( "Error: Position doesn't exists. Please check config file.", 'fw' ) );
}
$position_allowed_colors = $this->config->get_allowed_color_by_position( $preset['position'] );
//removing invalid data from $preset['sidebars']
$exceptionMsg = __( 'Error: Sidebars not set', 'fw' );
if ( isset( $preset['sidebars'] ) and is_array( $preset['sidebars'] ) ) {
$exception = new _FW_Extension_Sidebars_MissingSidebar_Exception( $exceptionMsg );
array_walk( $preset['sidebars'], array( $this, 'clear_preset_sidebars' ), $position_allowed_colors );
foreach ( $preset['sidebars'] as $color => $sidebar_id ) {
if ( empty( $sidebar_id ) ) {
//if added invalid sidebarId, add 'color' to exception
unset( $preset['sidebars'][ $color ] );
$exception->add_color( $color );
}
}
if ( $exception->has_colors() ) {
throw $exception;
}
} else if ( ! empty( $position_allowed_colors ) ) {
//if not set sidebars, but it is in position throw exception
throw new Exception( $exceptionMsg );
} else {
$preset['sidebars'] = array();
}
}
//Used in validate_preset method
private function clear_preset_sidebars( &$sidebar_id, $color, $position_allowed_colors ) {
//check if allowed color
if ( ! in_array( $color, $position_allowed_colors ) ) {
$sidebar_id = false;
}
//check if existing sidebar id
if ( $sidebar_id ) {
$sidebar_static = isset( $this->static_sidebars[ $sidebar_id ] ) ? $this->static_sidebars[ $sidebar_id ] : false;
$sidebar_obj = $this->get_sidebar_by_id( $sidebar_id ) ? $this->get_sidebar_by_id( $sidebar_id ) : $sidebar_static;
if ( ! $sidebar_obj ) {
$sidebar_id = false;
}
}
}
}

View File

@@ -0,0 +1,456 @@
<?php if (!defined('FW')) die('Forbidden');
/**
* Description of FW_Extension_Sidebars_config
* Working with config
* @internal
*/
class _FW_Extension_Sidebars_Config
{
private $config = array();
const TAXONOMIES_PREFIX = 'tx';
const POST_TYPES_PREFIX = 'pt';
const ARCHIVES_PREFIX = 'ar';
const CONDITIONAL_TAGS_PREFIX = 'ct';
const DEFAULT_PREFIX = 'df';
const DEFAULT_SUB_TYPE = 'all';
const DEFAULT_SLUG = 'df_all';
const SIDEBARS_NR_KEY = 'sidebars_number';
private static $config_keys = array(
self::POST_TYPES_PREFIX => 'post_types',
self::ARCHIVES_PREFIX => 'archives',
self::TAXONOMIES_PREFIX => 'taxonomies',
self::CONDITIONAL_TAGS_PREFIX => 'conditional_tags',
self::DEFAULT_PREFIX => 'default'
);
/*
* Conditional tag with params example
*
'front_page_slug' => array(
'order_option' => 1, - optional: default 1 position in the other lists
'check_priority' => 'last' // type string 'first' | 'last', - optional: defaults 'last'
'name' => 'Pages with Front-Page template',
'conditional_tag' => array(
'callback' => 'is_page_template',
'params' => array('page-templates/front-page.php')
)
),*/
private function get_config_defaults() {
return array(
'select_options' => array(
'post_types' => array(
'attachment' => false,
'revision' => false,
'nav_menu_item' => false,
'post' => array(
'name' => array(
'singular' => __('Blog Post','fw'),
'plural' => __('Blog Posts', 'fw')
)
),
'page' => array(
'name' => array(
'singular' => __('Page','fw'),
'plural' => __('Pages', 'fw')
),
),
'fw-portfolio'=> array(
'name' => array(
'singular' => __('Portfolio Project', 'fw'),
'plural' => __('Portfolio Projects', 'fw'),
)
)
),
'taxonomies' => array(
'post_tag' => true,
'post_format' => false,
'nav_menu' => false,
'link_category' => false,
'category' => array(
'name' => array(
'singular' => __('Blog Category', 'fw'),
'plural' =>__('Blog Categories', 'fw')
)
),
'fw-project-category'=> array(
'name' => array(
'singular' => __('Portfolio Category','fw')
)
)
),
'conditional_tags' => array(
'is_front_page' => array(
'name' => __('Home Page', 'fw'),
'order_option' => 3,
'check_priority' => 'first'
),
'is_search' => array(
'name' => __('Search Page', 'fw'),
'order_option' => 2,
'check_priority' => 'last'
),
'is_404' => array(
'name' => __('404 Page', 'fw'),
'order_option' => 4,
'check_priority' => 'last'
),
'is_author' => array(
'name' => __('Author Page', 'fw'),
'order_option' => 1,
'check_priority' => 'last'
),
'is_archive' => array(
'name' => __('Archive Page','fw'),
'order_option' => 5,
'check_priority' => 'last'
)
)
)
);
}
public static $allowed_colors = array( 'blue', 'yellow', 'green', 'red' );
public function __construct()
{
$user_config = fw()->extensions->get('sidebars')->get_config();
$this->config['sidebar_positions'] = fw_akg('sidebar_positions', $user_config, array() );
$this->config['dynamic_sidebar_args'] = fw_akg('dynamic_sidebar_args', $user_config, array() );
$this->config = array_merge($this->config, $this->get_config_defaults());
$this->config['select_options']['conditional_tags'] = apply_filters('fw_ext_sidebars_conditional_tags', $this->config['select_options']['conditional_tags']);
$this->_fw_set_conditional_tags_defaults($this->config['select_options']['conditional_tags']);
}
private function _fw_set_conditional_tags_defaults(&$conditional_tags) {
foreach($conditional_tags as &$conditional_tag) {
if (!isset($conditional_tag['check_priority']) and empty($conditional_tag['check_priority'])) {
$conditional_tag['check_priority'] = 'last';
}
if (!isset($conditional_tag['order_option']) or !preg_match('/^\d+$/', $conditional_tag['order_option'])) {
$conditional_tag['order_option'] = 1;
}
}
}
public function get_dynamic_sidebar_args()
{
return fw_akg('dynamic_sidebar_args', $this->config, array());
}
/**
* Collect data of choices for grouped pages tab
*/
public function get_grouped_labels()
{
$result = array();
$result[self::DEFAULT_SLUG] = __('All Pages','fw');
{
$result['posts'] = array(
'attr' => array('label' => __('Pages', 'fw')),
'choices' => array()
);
$post_types = $this->get_post_types();
foreach($post_types as $post_type) {
$result['posts']['choices'] = array_merge(
$result['posts']['choices'],
$this->get_label_grouped('post_types', $post_type)
);
}
}
{
$result['taxonomies'] = array(
'attr' => array('label' => __('Categories', 'fw')),
'choices' => array()
);
$taxonomies = $this->get_taxonomies();
foreach($taxonomies as $taxonomy) {
$result['taxonomies']['choices'] = array_merge(
$result['taxonomies']['choices'],
$this->get_label_grouped('taxonomies',$taxonomy)
);
}
}
{
$result['archives'] = array(
'attr' => array('label' => __('Archives', 'fw')),
'choices' => array()
);
$post_types = get_post_types(array(
'public' => true,
'has_archive' => true
));
foreach($post_types as $post_type) {
$result['archives']['choices'] = array_merge(
$result['archives']['choices'],
$this->get_label_grouped('archives',$post_type)
);
}
}
// array_merge conditional_tags from config
{
$result['conditional-tags'] = array(
'attr' => array('label' => __('Others', 'fw')),
'choices' => array()
);
$result['conditional-tags']['choices'] = array_merge(
$result['conditional-tags']['choices'],
$this->get_conditional_tags_labels(true)
);
}
return $result;
}
private function conditional_tag_cmp($a, $b){
if ($a['order_option'] < $b['order_option']){
return -1;
} elseif ($a['order_option'] > $b['order_option']) {
return 1;
}
return 0;
}
private function get_taxonomies(){
return apply_filters( 'fw_ext_sidebars_taxonomies',
get_taxonomies(array(
'public' => true
))
);
}
private function get_post_types() {
return apply_filters( 'fw_ext_sidebars_post_types',
get_post_types(array(
'public' => true
))
);
}
/**
* Get conditional_tags from config
*/
public function get_conditional_tags_labels($with_ordering = false)
{
$conditional_tags = $this->get_conditional_tags();
if ($with_ordering) {
uasort($conditional_tags, array($this, 'conditional_tag_cmp'));
}
if (empty($conditional_tags))
return array();
$result = array();
foreach($conditional_tags as $sub_type => $ct) {
// ct_is_home => Home page
if ($ct !== false)
$result[self::CONDITIONAL_TAGS_PREFIX . '_' . $sub_type] = empty($ct['name']) ? ucfirst($sub_type) : ucfirst($ct['name']);
}
return $result;
}
/**
* Collect data of choices for specific pages tab
*/
public function get_specific_labels()
{
{
$result['posts'] = array(
'attr' => array('label' => __('Page', 'fw')),
'choices' => array()
);
$post_types = $this->get_post_types();
foreach($post_types as $post_type) {
$result['posts']['choices'] = array_merge(
$result['posts']['choices'],
$this->get_label_singular('post_types',$post_type)
);
}
}
{
$result['taxonomies'] = array(
'attr' => array('label' => __('Category', 'fw')),
'choices' => array()
);
$taxonomies = $this->get_taxonomies();
foreach($taxonomies as $taxonomy) {
$result['taxonomies']['choices'] = array_merge(
$result['taxonomies']['choices'],
$this->get_label_singular('taxonomies',$taxonomy)
);
}
}
return $result;
}
/**
* Get singular name by type and sub_type (e.g. type = post_types / sub_type = post)
*/
public function get_label_singular($type, $sub_type)
{
$result = array();
$type_key = $this->get_prefix_by_type($type);
$default = ucfirst($this->get_name_from_db($sub_type, $type_key,true));
if ( $this->is_enabled_select_option($type, $sub_type) )
$result[$type_key . '_' . $sub_type] = isset($this->config['select_options'][$type][$sub_type]['name']['singular']) ? ucfirst($this->config['select_options'][$type][$sub_type]['name']['singular']) : $default;
return $result;
}
/**
* Get plural name by type and sub_type (e.g. type = post_types / sub_type = post)
*/
public function get_label_grouped($type, $sub_type)
{
$result = array();
$prefix = $this->get_prefix_by_type($type);
if ( $type === $this->get_type_by_prefix(self::DEFAULT_PREFIX) and $sub_type === self::DEFAULT_SUB_TYPE )
return array(self::DEFAULT_SLUG => __('All Pages', 'fw'));
if($type === 'post_types' or $type === 'taxonomies' or $type === 'archives')
$default_label = $this->get_name_from_db($sub_type, $prefix, false);
else
$default_label = fw_akg('select_options/' . $type . '/' . $sub_type . '/name', $this->config, $type . '_' . $sub_type);
$default_label = ucfirst($default_label);
if ( $this->is_enabled_select_option($type, $sub_type) )
$result[$prefix . '_' . $sub_type] = isset($this->config['select_options'][$type][$sub_type]['name']['plural']) ? ucfirst($this->config['select_options'][$type][$sub_type]['name']['plural']) : $default_label;
return $result;
}
/**
* Retrieve info about registered post_types or taxonomies
*/
protected function get_name_from_db($slug, $type_key, $is_singular)
{
$result = $slug;
$get_object = $type_key === self::POST_TYPES_PREFIX || $type_key === self::ARCHIVES_PREFIX ? 'get_post_type_object' : 'get_taxonomy';
$obj = call_user_func_array($get_object, array($slug));
if($obj) {
if($is_singular) {
//singular name
$result = $obj->labels->singular_name;
} else {
//plural name
$result = $obj->labels->name;
}
}
return $result;
}
public function get_prefix_by_type($type)
{
return array_search($type, self::$config_keys);
}
public function get_type_by_prefix($prefix)
{
return isset(self::$config_keys[$prefix]) ? self::$config_keys[$prefix] : null;
}
public function parse_prefix($val)
{
return substr($val, 0, 2);
}
public function parse_sub_type($val)
{
return substr($val, 3, strlen($val)-3);
}
/**
* Get valid sidebar positions from config
*/
public function get_sidebar_positions()
{
$sidebars_positions = fw_akg('sidebar_positions', $this->config, array());
foreach($sidebars_positions as $position_key => $position)
{
$icon_url = fw_akg('icon_url', $position);
if (empty($icon_url)) {
fw_aku($position_key, $sidebars_positions);
continue;
}
$sidebars_positions[$position_key]['icon_url'] = fw()->extensions->get('sidebars')->locate_URI('/static/images/' . $icon_url );
}
return $sidebars_positions;
}
/**
* Get valid sidebar positions from config
*/
public function get_allowed_color_by_position($sidebar_position)
{
$colorsCnt = fw_akg('sidebar_positions/' . $sidebar_position . '/' . _FW_Extension_Sidebars_Config::SIDEBARS_NR_KEY, $this->config);
if (empty($colorsCnt))
return array();
return array_slice(self::$allowed_colors, 0 , $colorsCnt);
}
/**
* Check position exists in config
*/
public function has_position($position)
{
return (isset($this->config['sidebar_positions'][$position]) and is_array($this->config['sidebar_positions'][$position]));
}
/**
* @param $priority null| string
*
* @return mixed|null
*/
public function get_conditional_tags($priority = null)
{
$conditional_tags = fw_akg('select_options/conditional_tags', $this->config, array()) ;
if ($priority) {
foreach($conditional_tags as $key => $conditional_tag) {
if ($conditional_tag['check_priority'] != $priority) {
unset($conditional_tags[$key]);
}
}
}
return $conditional_tags;
}
/**
* Check if option is not disabled in config
*/
public function is_enabled_select_option($type, $sub_type)
{
if (self::DEFAULT_SUB_TYPE === $sub_type and $this->get_type_by_prefix(self::DEFAULT_PREFIX) === $type)
return true;
if (isset($this->config['select_options'][$type][$sub_type]) and $this->config['select_options'][$type][$sub_type] === false)
return false;
return true;
}
}

View File

@@ -0,0 +1,307 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
/**
* Working with DB models and config on Frontend
* @internal
*/
class _FW_Extension_Sidebars_Frontend {
/** @var _FW_Extension_Sidebars_Config */
private $config;
private $current_page_preset;
private $wp_option_sidebar_settings;
private $after_widgets_init;
public function __construct() {
$this->wp_option_sidebar_settings = fw()->extensions->get( 'sidebars' )->get_fw_option_sidebars_settings_key();
$this->config = new _FW_Extension_Sidebars_Config();
$this->register_actions();
}
private function register_actions() {
add_action( 'widgets_init', array( $this, '_fw_enable_replace' ) );
}
public function _fw_enable_replace() {
$this->after_widgets_init = true;
}
public function replace_sidebars( $sidebars_widgets ) {
if ( ! $this->after_widgets_init ) {
return $sidebars_widgets;
}
$db_settings = $this->get_db();
$places = array();
if ( isset( $db_settings['allowed_places'] ) ) {
$places = $db_settings['allowed_places'];
}
$preset = $this->get_current_page_preset();
if ( false === empty( $places ) ) {
foreach ( $places as $sidebar_id => $color ) {
if ( isset( $preset['sidebars'][ $color ] ) ) {
if ( isset( $sidebars_widgets[ $preset['sidebars'][ $color ] ] ) ) {
$sidebars_widgets[ $sidebar_id ] = $sidebars_widgets[ $preset['sidebars'][ $color ] ];
} else {
unset( $sidebars_widgets[ $sidebar_id ] );
}
}
}
}
return $sidebars_widgets;
}
/**
* @return array database data
*/
private function get_db() {
$db = get_option( $this->wp_option_sidebar_settings );
return ! empty( $db ) ? $db : array();
}
/**
* If DB has preset for current page position
* @return string | false
*/
public function get_preset_position() {
$preset = $this->get_current_page_preset();
return ! empty( $preset['position'] ) ? $preset['position'] : false;
}
/**
* @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 {
fw_render_view( fw()->extensions->get( 'sidebars' )->locate_path( '/views/frontend-no-widgets.php' ), array( 'sidebar_id' => $sidebar ), false );
}
}
return ob_get_clean();
}
/**
* Generate current page requirements and return array with available sidebars for current page
*/
public function get_current_page_preset() {
$result = $this->_fw_check_conditional_tags( 'first' );
if ( $result ) {
return $result;
}
// wooCommerce support
if( function_exists( 'is_shop') && is_shop() ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::POST_TYPES_PREFIX );
$data['sub_type'] = 'page';
$data['id'] = get_option( 'woocommerce_shop_page_id' );
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
// Custom post types archives support
if( is_post_type_archive() ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::ARCHIVES_PREFIX );
$data['sub_type'] = get_post_type();
$data['id'] = get_post_type();
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
//static page which show blog posts
if ( is_home() && get_option( 'page_for_posts' ) != '0' && get_option( 'show_on_front' ) == 'page' ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::POST_TYPES_PREFIX );
$data['sub_type'] = 'page';
$data['id'] = get_queried_object_id();
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
if ( is_singular() ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::POST_TYPES_PREFIX );
$data['sub_type'] = get_post_type();
$data['id'] = get_queried_object_id();
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
if ( is_category() ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::TAXONOMIES_PREFIX );
$data['sub_type'] = 'category';
$data['id'] = get_query_var( 'cat' );
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
if ( is_tag() ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::TAXONOMIES_PREFIX );
$data['sub_type'] = 'post_tag';
$data['id'] = get_query_var( 'tag' );
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
if ( is_tax() ) {
$term_obj = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::TAXONOMIES_PREFIX );
$data['sub_type'] = $term_obj->taxonomy;
$data['id'] = $term_obj->term_id;
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
$result = $this->_fw_check_conditional_tags( 'last' );
if ( $result ) {
return $result;
}
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::DEFAULT_PREFIX );
$data['sub_type'] = _FW_Extension_Sidebars_Config::DEFAULT_SUB_TYPE;
$result = $this->get_preset_sidebars( $data ); //return preset default for all pages
return $result;
}
private function _fw_check_conditional_tags( $priority ) {
$conditional_tags = $this->config->get_conditional_tags( $priority );
foreach ( $conditional_tags as $key => $cond_tag ) {
$function = null;
if ( isset( $cond_tag['conditional_tag'] ) ) {
$function = isset( $cond_tag['conditional_tag']['callback'] ) ? $cond_tag['conditional_tag']['callback'] : '';
if ( is_callable( $function ) ) {
$params = array();
if ( isset( $cond_tag['conditional_tag']['params'] ) and is_array( $cond_tag['conditional_tag']['params'] ) ) {
$params = $cond_tag['conditional_tag']['params'];
}
if ( call_user_func_array( $function, $params ) ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::CONDITIONAL_TAGS_PREFIX );
$data['sub_type'] = $key;
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
}
} else {
$function = $key;
if ( is_callable( $function ) ) {
if ( call_user_func( $function ) ) {
$data['type'] = $this->config->get_type_by_prefix( _FW_Extension_Sidebars_Config::CONDITIONAL_TAGS_PREFIX );
$data['sub_type'] = $key;
$result = $this->get_preset_sidebars( $data );
if ( $result ) {
return $result;
}
}
}
}
}
}
private function preset_timestamp_cmp( $a, $b ) {
if ( $a['timestamp'] === $b['timestamp'] ) {
return 0;
}
return ( $a['timestamp'] > $b['timestamp'] ) ? - 1 : 1;
}
/**
* Get avaible preset from DB by current page requirements
*/
private function get_preset_sidebars( $data ) {
if ( $this->config->is_enabled_select_option( $data['type'], $data['sub_type'] ) ) {
$settings = $this->get_db();
if ( ! empty( $data['id'] ) ) { //get by ids preset
if ( isset( $settings['settings'][ $data['type'] ][ $data['sub_type'] ]['saved_ids'] ) ) { //check if id in saved_ids
if ( in_array( $data['id'], $settings['settings'][ $data['type'] ][ $data['sub_type'] ]['saved_ids'] ) ) {
$by_ids_presets = $settings['settings'][ $data['type'] ][ $data['sub_type'] ]['by_ids'];
usort( $by_ids_presets, array( $this, 'preset_timestamp_cmp' ) );
foreach ( $by_ids_presets as $preset_key => $preset ) {
if ( in_array( $data['id'], $preset['ids'] ) ) {
$this->current_page_preset = $preset;
if ( isset( $this->current_page_preset['timestamp'] ) ) {
unset( $this->current_page_preset['timestamp'] );
}
return $this->current_page_preset;
}
}
}
}
}
$this->current_page_preset = fw_akg( 'settings/' . $data['type'] . '/' . $data['sub_type'] . '/common', $settings, false );
if ( isset( $this->current_page_preset['timestamp'] ) ) {
unset( $this->current_page_preset['timestamp'] );
}
return $this->current_page_preset;
}
return false;
}
}

View File

@@ -0,0 +1,33 @@
<?php if (!defined('FW')) die('Forbidden');
/**
* Exception can collect not allowed colors
* @internal
*/
class _FW_Extension_Sidebars_MissingSidebar_Exception extends Exception
{
private $colors = array();
public function set_colors($colors)
{
$this->colors = $colors;
return $this;
}
public function add_color($color)
{
$this->colors[] = $color;
return $this;
}
public function get_colors()
{
return $this->colors;
}
public function has_colors(){
return empty($this->colors) ? false : true;
}
}

View File

@@ -0,0 +1,201 @@
<?php if (!defined('FW')) die('Forbidden');
/**
* @internal
*/
class _FW_Extension_Sidebars_Model_Sidebar
{
private $id = null;
private $name;
private $description;
private $class;
private $before_widget;
private $after_widget;
private $before_title;
private $after_title;
protected $wp_widget_prefix_option = 'widget_';
protected $wp_sidebars_widgets_option = 'sidebars_widgets';
protected $split_pattern = '/-(?=[^-]+$)/';
/**
* Fill object with sidebar args
*/
public function __construct($sidebar)
{
foreach ($sidebar as $key => $value)
{
$method = 'set_' . $key;
if(method_exists($this, $method)) {
call_user_func_array(array($this, $method), array($value));
}
}
}
public function set_class($class = null)
{
$this->class = $class;
return $this;
}
public function set_id($id = null)
{
$this->id = $id;
return $this;
}
public function get_class()
{
return $this->class;
}
public function get_id()
{
return $this->id;
}
public function set_name($name)
{
$this->name = trim(stripslashes($name));
return $this;
}
public function get_name()
{
return $this->name;
}
public function set_description($description)
{
$this->description = $description;
return $this;
}
public function get_description()
{
return $this->description;
}
public function set_before_widget($before_widget)
{
$this->before_widget = $before_widget;
return $this;
}
public function get_before_widget()
{
return $this->before_widget;
}
public function set_after_widget($after_widget)
{
$this->after_widget = $after_widget;
return $this;
}
public function get_after_widget()
{
return $this->after_widget;
}
public function set_before_title($before_title)
{
$this->before_title = $before_title;
return $this;
}
public function get_before_title()
{
return $this->before_title;
}
public function set_after_title($after_title)
{
$this->after_title = $after_title;
return $this;
}
public function get_after_title()
{
return $this->$after_title;
}
/**
* register sidebar with current object proprieties
*/
public function register()
{
add_action( 'widgets_init', array($this, '_action_register_sidebar') );
}
/**
* @internal
*/
public function _action_register_sidebar()
{
if (!$this->id) {
return false;
}
return register_sidebar($this->to_array());
}
public function unregister()
{
return unregister_sidebar($this->id);
}
/**
* Convert current object proprieties to array
* @var $sidebar_info 'general' = get only name and id, empty retrive all info
*/
public function to_array($sidebar_info = false)
{
$result = array(
'id' => $this->id,
'name' => $this->name,
);
if ($sidebar_info === 'general')
return $result;
$result = array_merge($result, array(
'description' => $this->description,
'class' => $this->class,
'before_widget' => $this->before_widget,
'after_widget' => $this->after_widget,
'before_title' => $this->before_title,
'after_title' => $this->after_title,
));
return $result;
}
/**
* Remove widgets from DB for current sidebar
*/
public function remove_widgets()
{
$widgets = get_option($this->wp_sidebars_widgets_option);
if (isset($widgets[$this->id]) and is_array($widgets[$this->id])) {
foreach($widgets[$this->id] as $widget) {
$widget_data = preg_split($this->split_pattern, $widget);
$widget_slug = $widget_data[0];
$widget_id = $widget_data[1];
$db = get_option( $this->wp_widget_prefix_option . $widget_slug);
if (is_array($db)) {
unset($db[$widget_id]);
}
update_option($this->wp_widget_prefix_option . $widget_slug, $db, false);
}
}
unset($widgets[$this->id]);
update_option($this->wp_sidebars_widgets_option, $widgets, false);
}
}

View File

@@ -0,0 +1,35 @@
<?php if (!defined('FW')) die('Forbidden');
class FW_Option_Storage_Type_FW_Ext_Sidebar_Picker extends FW_Option_Storage_Type {
public function get_type()
{
return 'fw-ext-sidebar-picker';
}
protected function _load($id, array $option, $value, array $params)
{
return fw_ext( 'sidebars' )->get_specific_preset_by_id(
isset($params['post-id']) ? $params['post-id'] : get_the_ID()
);
}
protected function _save($id, array $option, $value, array $params)
{
$ext = fw_ext( 'sidebars' ); /** @var FW_Extension_Sidebars $ext */
if (empty($value)) {
return $value;
}
if ( $value['position'] === 'default' ) {
$ext->delete_sidebar_preset( array(
'slug' => false,
'preset' => $value['preset']
) );
} else {
$ext->save_sidebar_settings( $value );
}
return array();
}
}

View File

@@ -0,0 +1,114 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
class FW_Option_Type_Sidebar_Picker extends FW_Option_Type {
/**
* Option's unique type, used in option array in 'type' key
* @return string
*/
public function get_type() {
return 'sidebar-picker';
}
protected function _enqueue_static( $id, $option, $data ) {
$uri = fw_get_framework_directory_uri( '/extensions/sidebars/includes/option-type/' . $this->get_type() );
wp_enqueue_style(
'fw-option-type' . $this->get_type(),
$uri . '/static/css/style.css',
array(),
fw()->manifest->get_version()
);
wp_enqueue_script(
'fw-option-type' . $this->get_type(),
$uri . '/static/js/sidebar-picker.js',
array( 'jquery', 'fw-events' ),
fw()->manifest->get_version(),
true
);
fw()->backend->option_type('image-picker')->enqueue_static();
}
/**
* Generate option's html from option array
*
* @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 ) {
$data_positions_options = fw_ext( 'sidebars' )->is_missing_config() ? array() : fw_ext( 'sidebars' )->get_data_positions_options();
$data_positions_options['choices'] = array_merge(
array(
'default' => array(
'label' => false,
'small' => fw()->extensions->get('sidebars')->locate_URI('/includes/option-type/sidebar-picker/static/images/default.png'),
'data' => array(
'colors' => 0,
),
),
),
$data_positions_options['choices']
);
return fw_render_view( fw_ext( 'sidebars' )->get_declared_path( '/includes/option-type/sidebar-picker/view.php' ), array(
'data_positions_options' => $data_positions_options,
'id' => $id,
'sidebars' => fw_ext( 'sidebars' )->get_sidebars(),
'colors' => fw_ext( 'sidebars' )->get_allowed_places(),
'data' => $data,
'image_picker' => fw_ext( 'sidebars' )->get_sidebars_for_select(),
'attr' => $option['attr']
), false );
}
/**
* Extract correct value for $option['value'] from input array
* If input value is empty, will be returned $option['value']
*
* @param array $option Option array merged with _get_defaults()
* @param array|string|null $input_value
*
* @return string|array|int|bool Correct value
* @internal
*/
protected function _get_value_from_input( $option, $input_value ) {
return ( is_null( $input_value ) ? $option['value'] : $input_value );
}
/**
* 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
*
* array(
* 'value' => '',
* ...
* )
* @internal
*/
protected function _get_defaults() {
return array(
'value' => array(),
);
}
public function _get_backend_width_type() {
return 'full';
}
}
FW_Option_Type::register( 'FW_Option_Type_Sidebar_Picker' );

View File

@@ -0,0 +1,100 @@
.fw-ext-sidebars-delete-button.dashicons.fw-x {
cursor: pointer;
display: block;
float: left;
text-indent: 0;
overflow: hidden;
position: absolute;
top: 14px;
right: 30px;
margin: 0;
padding: 0;
}
.fw-ext-sidebars-deleting {
position: absolute;
top: 20px;
right: 50px;
padding: 0;
background: url('../images/spinner.gif') no-repeat;
background-size: 20px 20px;
display: none;
opacity: .7;
width: 20px;
height: 20px;
margin: -5px 5px;
float: none;
}
#submit-settings-specific-positions,
#submit-settings-grouped-positions {
float: left;
}
#fw-ext-sidebars-new-sidebar-name {
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#specific-field-id,
#fw-ext-sidebars-new-sidebar-name {
line-height: 20px;
}
#fw-option-sidebars-for-grouped {
width: 100%;
}
/* selectize styles */
#fw-ext-sidebars-new-sidebar-container {
padding: 15px 10px;
background: #f1f1f1;
}
#fw-ext-sidebars-new-sidebar-container #fw-ext-sidebars-new-sidebar-label {
margin-bottom: 5px;
}
#fw-add-button {
margin-top: 25px
}
.fw-ext-sidebars-autocomplete-menu {
overflow: auto;
max-height: 270px;
}
/* (i) tips */
.qtip.qtip-fw-info-sidebars {
max-width: 320px;
}
.qtip.qtip-fw-info-sidebars .qtip-content {
padding: 15px;
}
/* end: (i) tips */
div.widget-liquid-left {
margin: 0;
width: 50%;
float: left;
padding: 0 15px 0;
box-sizing: border-box;
}
div.widget-liquid-right {
float: left;
width: 50%;
padding: 0 15px 0;
margin: 0;
box-sizing: border-box;
}
.wrap {
margin: 10px 20px 0 2px;
}

View File

@@ -0,0 +1,32 @@
(function ($, fwe) {
var init = function () {
var $this = $(this),
elements = {
$image_picker: $this.find('.fw-option-type-image-picker select'),
$choicesGroups: $this.find('> .choice-group')
};
$this.on('fw:option-type:image-picker:clicked', function (e, data) {
methods.showSidebarsLocation(data.data.colors);
});
methods = {
showSidebarsLocation: function ($colors) {
$this.find('.fw-ext-sidebars-location').addClass('empty').find('select').attr('disabled', true).end()
.slice(0, $colors)
.removeClass('empty').find('select').attr('disabled', false);
}
}
//first run.
if (elements.$image_picker.length) {
methods.showSidebarsLocation(elements.$image_picker.find('option:selected').data('extraData').colors);
}
};
fwe.on('fw:options:init', function (data) {
data.$elements
.find('.fw-option-type-sidebar-picker:not(.fw-option-initialized)').each(init)
.addClass('fw-option-initialized');
});
})(jQuery, fwEvents);

View File

@@ -0,0 +1,129 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
$attr['class'] .= ' fw-ext-sidebars-wrap ';
unset( $attr['name'] );
?>
<div <?php echo fw_attr_to_html( $attr ); ?>>
<?php echo fw()->backend->option_type( 'hidden' )->render( 'slug',
array(
'value' => _FW_Extension_Sidebars_Config::POST_TYPES_PREFIX . '_' . get_post_type()
),
array(
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . '][selected][0]',
) ) ?>
<?php echo fw()->backend->option_type( 'hidden' )->render( '',
array(
'value' => get_the_ID()
),
array(
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . '][selected][0][ids]',
) ) ?>
<?php echo fw()->backend->option_type( 'hidden' )->render( 'preset',
array(
'value' => empty( $data['value']['preset_id'] ) ? '' : $data['value']['preset_id']
),
array(
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . ']',
)
) ?>
<?php if ( ! empty( $data_positions_options ) ): ?>
<!--MODE INSERT START-->
<div class="fw-row fw-ext-sidebars-image-picker-box-<?php echo esc_attr($id) ?>">
<div class="fw-ext-sidebars-option-label fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-select-sidebar-for-<?php echo esc_attr($id) ?>"><?php _e( 'Sidebar', 'fw' ) ?></label>
<div class="fw-clear"></div>
</div>
</div>
<div class="fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<div class="fw-backend-option-fixed-width">
<?php echo fw()->backend->option_type( 'image-picker' )->render( 'position', $data_positions_options,
array(
'value' => empty( $data['value']['position'] ) ? '' : $data['value']['position'],
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . ']',
)
); ?>
</div>
</div>
<div class="fw-clear"></div>
<div
class="fw-ext-sidebars-desc fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php _e( 'Choose the position for your sidebar(s)', 'fw' ) ?>
</div>
</div>
<div class="fw-clear"></div>
<div
class="placeholders fw-insert-mode fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php foreach ( $colors as $color ) : ?>
<div class="fw-ext-sidebars-location empty <?php echo esc_attr($id) ?> <?php echo esc_attr($color); ?>"
data-color="<?php echo esc_attr($color); ?>">
<?php echo fw()->backend->option_type( 'select' )->render(
$color,
$image_picker,
array(
'value' => empty( $data['value']['sidebars'][ $color ] ) ? '' : $data['value']['sidebars'][ $color ],
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . '][sidebars]',
)
); ?>
</div>
<?php endforeach; ?>
</div>
<div class="fw-clear"></div>
<!--MOD INSERT END-->
<?php else: ?>
<!--MOD REPLACE START-->
<div class="placeholders fw-replace-mode fw-row">
<div class="fw-ext-sidebars-option-label fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-select-sidebar-for-<?php echo esc_attr($id) ?>"><?php _e( 'Sidebar', 'fw' ) ?></label>
<div class="fw-clear"></div>
</div>
</div>
<input type="hidden" class="fw-sidebars-count" value="<?php echo count( $colors ); ?>">
<div class="fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<?php foreach ( $colors as $sidebar_id => $color ) : ?>
<div class="fw-ext-sidebars-location <?php echo esc_attr($id) ?> <?php echo esc_attr($color); ?>"
data-color="<?php echo esc_attr($color); ?>">
<?php $short_sidebar_name = strlen( $sidebars[ $sidebar_id ]->get_name() ) > 20 ? mb_substr( $sidebars[ $sidebar_id ]->get_name(), 0, 20 ) . '...' : $sidebars[ $sidebar_id ]->get_name(); ?>
<small
class="fw-ext-sidebars-placeholder-title"><?php echo __( sprintf( 'Replace %s with:', $short_sidebar_name ), 'fw' ) ?></small>
<?php echo fw()->backend->option_type( 'select' )->render(
$color,
$image_picker,
array(
'value' => empty( $data['value']['sidebars'][ $color ] ) ? '' : $data['value']['sidebars'][ $color ],
'id_prefix' => $data['id_prefix'] . $id . '-',
'name_prefix' => $data['name_prefix'] . '[' . $id . '][sidebars]',
) ); ?>
</div>
<?php endforeach; ?>
</div>
<div class="fw-clear"></div>
<div
class="fw-ext-sidebars-desc fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php _e( 'Select sidebar you wish to replace.', 'fw' ) ?>
</div>
</div>
<div class="fw-clear"></div>
<!--MOD REPLACE END-->
<?php endif; ?>
</div>

View File

@@ -0,0 +1,6 @@
<?php if (!defined('FW')) die('Forbidden');
$curr_dir = dirname(__FILE__);
require $curr_dir .'/model/class-fw-extension-sidebars-model-sidebar.php';

View File

@@ -0,0 +1,26 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
$manifest = array();
$manifest['name'] = __( 'Sidebars', 'fw' );
$manifest['description'] = __(
'Brings a new layer of customization freedom to your website by letting you add more than one sidebar to a page,'
.' or different sidebars on different pages.',
'fw'
);
$manifest['version'] = '1.0.19';
$manifest['display'] = true;
$manifest['standalone'] = true;
$manifest['requirements'] = array(
'framework' => array(
'min_version' => '2.2.2', // in this version was added option handler
)
);
$manifest['github_repo'] = 'https://github.com/ThemeFuse/Unyson-Sidebars-Extension';
$manifest['uri'] = 'http://manual.unyson.io/en/latest/extension/sidebars/index.html#content';
$manifest['author'] = 'ThemeFuse';
$manifest['author_uri'] = 'http://themefuse.com/';
$manifest['github_update'] = 'ThemeFuse/Unyson-Sidebars-Extension';

View File

@@ -0,0 +1,5 @@
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
$options = apply_filters( 'fw_ext_sidebars_settings_options', array() );

View File

@@ -0,0 +1,518 @@
.fw-ext-sidebars-delete-button.dashicons.fw-x {
cursor: pointer;
display: block;
float: left;
text-indent: 0;
overflow: hidden;
position: absolute;
top: 14px;
right: 30px;
margin: 0;
padding: 0;
}
.fw-ext-sidebars-deleting {
position: absolute;
top: 20px;
right: 50px;
padding: 0;
background: url('../images/spinner.gif') no-repeat;
background-size: 20px 20px;
display: none;
opacity: .7;
width: 20px;
height: 20px;
margin: -5px 5px;
float: none;
}
#submit-settings-specific-positions,
#submit-settings-grouped-positions {
float: left;
}
.fw-ext-sidebars-wrap-container {
margin-top: 25px;
float: right;
width: 58%;
}
@media (max-width: 768px) {
.fw-ext-sidebars-wrap-container {
width: 100%;
}
}
.fw-ext-sidebars-wrap-container .spinner {
visibility: visible;
display: none;
}
div.wrap br.clear {
clear: none !important;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-error {
border: 1px solid #F31414 !important;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.fw-ext-sidebars-wrap .selectize-control.single .selectize-input input {
display: none;
}
.fw-ext-sidebars-wrap .selectize-control.single .selectize-input.input-active {
cursor: default !important;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-editing {
float: left;
margin-left: 10px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-submiting-grouped-positions,
.fw-ext-sidebars-wrap .fw-ext-sidebars-submiting-specific-positions {
float: left;
margin-left: 7px;
margin-top: 5px;
}
.fw-ext-sidebars-wrap label {
font-weight: bold;
}
.fw-ext-sidebars-wrap .fw-search-term {
color: red;
text-decoration:underline;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-removing {
position: absolute;
right: 26px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-remove-span {
float: right;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-remove {
top: 14px;
right: 7px;
}
.fw-ext-sidebars-wrap {
width: 98%;
clear: both;
}
.fw-ext-sidebars-wrap .ui-autocomplete-loading {
background: white url('../images/ui-anim_basic_16x16.gif') right center no-repeat;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-location {
padding: 12px 10px 9px;
float: left;
margin: 10px 10px 0 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
min-width: 226px;
max-width: 100%;
}
.fw-ext-sidebars-wrap .fw-replace-mode-specific-positions .fw-ext-sidebars-location,
.fw-ext-sidebars-wrap .fw-replace-mode-grouped-positions .fw-ext-sidebars-location {
padding: 0 10px 10px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-placeholder-title {
padding: 6px 0;
display: block;
font-size: 12px;
}
.fw-ext-sidebars-wrap .placeholders {
margin-bottom: -10px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-location select {
width: 100%;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-location {
background-color: #FAFAFA;
border: 1px #cccccc solid;
}
.fw-ext-sidebars-wrap .blue {
background-color: #ceecf7;
border: 1px #7fd1d9 solid;
}
.fw-ext-sidebars-wrap .yellow {
background-color: #fbefa8;
border: 1px #f0d831 solid;
}
.fw-ext-sidebars-wrap .green {
background-color: #ccf7cf;
border: 1px #86c531 solid;
}
.fw-ext-sidebars-wrap .red {
background-color: #fbbfb7;
border: 1px #ba7135 solid;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-image-picker-box-grouped-positions,
.fw-ext-sidebars-wrap .placeholders {
padding-top: 25px;
}
.fw-ext-sidebars-wrap .placeholders.fw-replace-mode-specific-positions {
padding-top: 0;
}
/* remove specific page id styles*/
.fw-ext-sidebars-wrap .sidebars-specific-pages {
font-weight: bold;
padding-bottom: 25px;
min-height: 0;
}
.fw-ext-sidebars-wrap .sidebars-specific-pages > div {
padding-top: 2px;
padding-bottom: 2px;
}
.fw-ext-sidebars-wrap .sidebars-specific-pages > div:first-child {
padding-top: 10px;
}
.fw-ext-sidebars-wrap .sidebars-specific-pages > div:last-child {
padding-bottom: 0;
}
.fw-ext-sidebars-wrap .sidebars-specific-pages span {
margin-right: 25px;
display: block;
float: left;
font-size: 13px;
line-height: 1.8em;
white-space: nowrap;
cursor: default;
}
.fw-ext-sidebars-wrap .sidebars-specific-pages span a {
margin: 1px 0 0 -17px;
cursor: pointer;
width: 20px;
height: 20px;
display: block;
float: left;
text-indent: 0;
overflow: hidden;
position: absolute;
}
#fw-ext-sidebars-new-sidebar-name {
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#specific-field-id,
#fw-ext-sidebars-new-sidebar-name {
line-height: 20px;
}
.fw-ext-sidebars-wrap .nav-tab:hover,
.fw-ext-sidebars-wrap .nav-tab:active,
.fw-ext-sidebars-wrap .nav-tab:focus,
.fw-ext-sidebars-wrap .nav-tab {
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
margin-right: 0;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li.ui-state-active a.nav-tab {
color: #000;
background: 0 0;
border-bottom-color: #F1F1F1;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li a.nav-tab {
padding: 6px 12px;
font-weight: 700;
font-size: 15px;
line-height: 24px;
text-decoration: none;
color: #555;
border-bottom: 1px solid #CCC;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul {
margin: 0;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul:after {
display: block;
content: '';
clear: both;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li {
float: left;
/*margin-left: 10px;*/
margin-bottom: -1px;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list {
border-bottom: 1px solid #CCC;
}
.fw-ext-sidebars-wrap .fw-backend-sidebars-list {
font-style: italic;
color: #999;
}
#fw-option-sidebars-for-grouped {
width: 100%;
}
/* selectize styles */
#fw-ext-sidebars-new-sidebar-container {
padding: 15px 10px;
background: #f1f1f1;
}
#fw-ext-sidebars-new-sidebar-container #fw-ext-sidebars-new-sidebar-label {
margin-bottom: 5px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-created-tab-preset,
.fw-ext-sidebars-wrap .fw-ext-sidebars-created-tab-title {
border-bottom: solid 1px #ccc;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-created-tab-title {
font-size: 15px;
padding: 1px 0 15px 12px;
line-height: 20px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-created-tab-preset {
padding: 10px 5px 10px 5px;
position: relative;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-desc {
font-style: italic;
color: #999;
padding-top: 7px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-box-holder {
margin: 30px 0 0 10px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-box-holder.fw-ext-sidebars-created {
margin: 25px 0 0 0;
}
.fw-ext-sidebars-wrap .selectize-dropdown.dropdown-top {
top: auto !important;
bottom: 35px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-specific-input select {
width: 100%;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-specific-input .ui-widget {
padding-left: 10px;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-specific-input .ui-widget input {
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.fw-ext-sidebars-wrap .selectize-input {
padding: 5px 8px;
line-height: 16px;
}
.fw-ext-sidebars-wrap .selectize-input .item {
overflow: hidden;
width: 90% !important;
padding-top: 2px;
}
.fw-ext-sidebars-wrap .selectize-dropdown-content .selectize-item {
padding-top: 4px;
padding-bottom: 10px;
}
.fw-ext-sidebars-wrap .selectize-dropdown .active {
background: none;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-edit-span,
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-remove-span a.fw-x {
line-height: 27px;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list {
margin-top: 32px;
}
#fw-ext-sidebars-new-sidebar-label,
.fw-ext-sidebars-wrap .selectize-item,
.fw-ext-sidebars-wrap .selectize-input,
.fw-ext-sidebars-wrap select {
font-weight: bold;
}
#fw-add-button {
margin-top: 25px
}
.fw-ext-sidebars-wrap label {
font-size: 14px;
}
@media (max-width: 782px) {
.fw-ext-sidebars-wrap .fw-ext-sidebars-option-label {
padding-bottom: 10px;
}
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-box-holder input.ui-autocomplete-loading {
background: transparent url(../images/loading.gif) no-repeat 98% center;
}
.fw-ext-sidebars-wrap .nav-tab .spinner {
margin-left: 10px;
margin-right: 0px;
}
.fw-ext-sidebars-wrap .dropdown-top .selectize-dropdown-content .selectize-item:first-child {
padding-top: 8px;
}
.fw-ext-sidebars-wrap h4 {
margin-bottom: 15px;
margin-left: 10px;
}
.fw-ext-sidebars-wrap .fw-backend-option-grouped-pages-wrap,
.fw-ext-sidebars-wrap .fw-backend-option-specific-pages-wrap {
margin-top: 4px;
}
.fw-ext-sidebars-wrap .empty {
display: none;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-preset-edit {
font-size: 15px;
margin-left: 7px;
}
.fw-ext-sidebars-wrap h3 {
margin-bottom: 10px;
}
.fw-ext-sidebars-autocomplete-menu {
overflow: auto;
max-height: 270px;
}
/* (i) tips */
.qtip.qtip-fw-info-sidebars {
max-width: 320px;
}
.qtip.qtip-fw-info-sidebars .qtip-content {
padding: 15px;
}
/* end: (i) tips */
div.widget-liquid-left {
margin: 0;
width: 50%;
float: left;
padding: 0 15px 0;
box-sizing: border-box;
}
div.widget-liquid-right {
float: left;
width: 50%;
padding: 0 15px 0;
margin: 0;
box-sizing: border-box;
}
body.rtl div.widget-liquid-left {
float: right;
}
.wrap {
margin: 10px 20px 0 2px;
}
.fw-ext-sidebars-wrap-container {
float: left;
width: 50%;
padding: 0 15px 0;
box-sizing: border-box;
}
@media (max-width: 1250px) {
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list {
border-bottom: none;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li {
width: 100%;
float: none;
margin-bottom: 10px;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li:last-child {
margin-bottom: 0;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li.ui-state-active a.nav-tab {
border-bottom-color: #ccc;
}
.fw-ext-sidebars-wrap .fw-sidebars-tabs-list ul li a.nav-tab {
float: none;
display: block;
overflow: hidden;
margin-left: 0;
}
.fw-ext-sidebars-wrap .fw-ext-sidebars-box-holder {
margin-left: 0;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -0,0 +1,117 @@
(function($,fwe){
$(document).ready(function(){
/**
* clear autocomplete when unfocused
*/
$('#specific-field-id').on('blur', function(){
$(this).val('');
});
$( "#specific-field-id" ).autocomplete({
minLength: 2,
source: function( request, response ) {
var searchTypeSlug = $('#fw-option-sidebars-for-specific').val();
$.ajax({
url: ajaxurl,
dataType: "json",
data: {
action: 'sidebar_autocomplete_ajax',
searchTerm: request.term,
searchType: searchTypeSlug
},
type: 'POST',
success: function( data ) {
$('#specific-field-id').removeClass('ui-autocomplete-loading');
if (data.success === false || typeof data.data.items === 'undefined') {
return false;
}
if (data.data.items.length === 0) {
response({
label: noMatchesFoundMsg
});
} else {
response( $.map( data.data.items, function( val, index) {
return {
label: val,
value: val,
id: index,
slug: searchTypeSlug
}
}));
}
},
error: function (e) {
$('#specific-field-id').removeClass('ui-autocomplete-loading');
return false;
}
});
},
select: function( event, ui ) {
$('#specific-field-id').removeClass('fw-ext-sidebars-error');
onItemSelected(ui.item);
$(this).val('');
return event.preventDefault();
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
$(this).data("uiAutocomplete").menu.element.addClass("fw-ext-sidebars-autocomplete-menu");
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
$('.sidebars-specific-pages').on('click','a.fw-sidebars-remove-page',function(e){
e.preventDefault();
$(this).parent().remove();
});
/**
* Highlighting for autocomplete results
*/
$.extend( $.ui.autocomplete.prototype, {
_renderItem: function( ul, item ) {
var term = this.element.val(),
html = item.label.replace(new RegExp(term, "i"), "<span class='fw-search-term'>$&</span>" );
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( $("<a></a>").html(html) )
.appendTo( ul );
}
});
});
/**
* @param item.value, item.id, item.label
*/
function onItemSelected( item ) {
var addedItems = [];
var slug = $('#fw-option-sidebars-for-specific').val();
var name = $('#fw-option-sidebars-for-specific option:selected').text();
if (typeof item.id === 'undefined' ) {
return false;
}
$('.fw-sidebars-remove-page').each(function(){
var item = {
id: parseInt($(this).data('id')),
slug: $(this).data('slug')
};
addedItems[addedItems.length] = item;
});
//if item exists exit
for (var i=0; i<addedItems.length; i++){
if ( addedItems[i].id === parseInt(item.id) && addedItems[i].slug === item.slug ) {
return false;
}
}
fwSidebars.addRemovableItem(item.id, item.value, slug, name);
}
})(jQuery,fwEvents);

View File

@@ -0,0 +1,66 @@
<?php if (!defined('FW')) die('Forbidden');
global $wp_version;
?>
<?php $cnt_created_sidebars = count($created_sidebars); ?>
<?php if ( fw()->extensions->get( 'sidebars' )->is_missing_config() or (false === fw()->extensions->get( 'sidebars' )->is_missing_config() and !empty($data_positions_options['choices'])) or $cnt_created_sidebars) : ?>
<div class="fw-ext-sidebars-wrap-container">
<div class="fw-ext-sidebars-wrap">
<?php if (version_compare($wp_version, '4.4', '>=')): ?>
<h2 class="hndle">
<span><?php _e('Manage Sidebars', 'fw');?></span>
</h2>
<?php else: ?>
<h3 class="hndle">
<span><?php _e('Manage Sidebars', 'fw');?></span>
</h3>
<?php endif; ?>
<div class="fw-ext-sidebars-desc"><?php _e('Use this section to create and/or set different sidebar(s) for different page(s)','fw')?></div>
<div class="fw-sidebars-tabs-wrapper" style="opacity: 0;" >
<div class="fw-sidebars-tabs-list">
<ul>
<?php if (fw()->extensions->get( 'sidebars' )->is_missing_config() or (false === fw()->extensions->get( 'sidebars' )->is_missing_config() and !empty($data_positions_options['choices']) ) ) : ?>
<li><a href="#fw-sidebars-tab-1" class="nav-tab" ><span class="spinner"></span><?php echo __('For Grouped Pages','fw'); ?></a></li>
<li><a href="#fw-sidebars-tab-2" class="nav-tab" ><span class="spinner"></span><?php echo __('For Specific Pages','fw'); ?></a></li>
<?php endif ?>
<li <?php echo $cnt_created_sidebars ? '' : 'class="empty"'; ?> ><a href="#fw-sidebars-tab-3" class="nav-tab" ><?php echo $cnt_created_sidebars . ' ' . __('Created','fw'); ?></a></li>
</ul>
<div class="fw-clear"></div>
</div>
<div class="fw-sidebars-tabs">
<div class="fw-inner">
<?php if (fw()->extensions->get( 'sidebars' )->is_missing_config() or (false === fw()->extensions->get( 'sidebars' )->is_missing_config() and !empty($data_positions_options['choices']) ) ) : ?>
<div id="fw-sidebars-tab-1" role="tabpanel" >
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-tab-grouped.php'), array(
'grouped_options' => $grouped_options,
'data_positions_options' => $data_positions_options,
'id' => 'grouped',
'sidebars' => $sidebars,
), false); ?>
</div>
<div id="fw-sidebars-tab-2" role="tabpanel" >
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-tab-specific.php'), array(
'specific_options' => $specific_options,
'data_positions_options' => $data_positions_options,
'id' => 'specific',
'sidebars' => $sidebars,
), false); ?>
</div>
<?php endif ?>
<div id="fw-sidebars-tab-3" role="tabpanel" <?php echo ($cnt_created_sidebars ? '' : 'class="empty"') ?> >
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-tab-created-sidebars.php'), compact('created_sidebars'), false ); ?>
</div>
</div>
</div>
<div class="fw-clear"></div>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,47 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<div class="fw-row fw-ext-sidebars-image-picker-box-<?php echo esc_attr($id) ?>">
<div class="fw-ext-sidebars-option-label fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-select-sidebar-for-<?php echo esc_attr($id) ?>"><?php _e('Sidebar','fw') ?></label>
<div class="fw-clear"></div>
</div>
</div>
<div class="fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<div class="fw-backend-option-fixed-width">
<?php echo fw()->backend->option_type('image-picker')->render('positions', $data_positions_options, array('value' => '')); ?>
</div>
</div>
<div class="fw-clear"></div>
<div class="fw-ext-sidebars-desc fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php _e('Choose the position for your sidebar(s)', 'fw')?>
</div>
</div>
<div class="fw-clear"></div>
<?php $colors = fw()->extensions->get('sidebars')->get_allowed_places() ?>
<div class="placeholders fw-insert-mode fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php foreach($colors as $color) : ?>
<div class="fw-ext-sidebars-location empty <?php echo esc_attr($id)?> <?php echo esc_attr($color);?>" data-color="<?php echo esc_attr($color);?>">
<select class="sidebar-selectize <?php echo esc_attr($id) ?>-select">
<?php if (isset($sidebars) and is_array($sidebars)) :?>
<?php foreach($sidebars as $sidebar):?>
<option value="<?php echo esc_attr($sidebar->get_id()) ?>"><?php echo $sidebar->get_name(); ?></option>
<?php endforeach;?>
<?php endif;?>
</select>
</div>
<?php endforeach; ?>
</div>
<div class="fw-clear"></div>
<div id="fw-add-button" class="fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<input id="submit-settings-<?php echo esc_attr($id) ?>" type="button" class="button button-primary button-large" value="<?php _e('Add Sidebar','fw')?>" />
<span class="spinner fw-ext-sidebars-submiting-<?php echo esc_attr($id) ?>"></span>
</div>
<div class="fw-clear"></div>

View File

@@ -0,0 +1,44 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<?php $colors = fw()->extensions->get('sidebars')->get_allowed_places() ?>
<div class="placeholders fw-replace-mode-<?php echo esc_attr($id) ?> fw-row">
<div class="fw-ext-sidebars-option-label fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-select-sidebar-for-<?php echo esc_attr($id) ?>"><?php _e('Sidebar','fw') ?></label>
<div class="fw-clear"></div>
</div>
</div>
<input type="hidden" class="fw-sidebars-count" value="<?php echo esc_attr(count($colors)); ?>">
<div class="fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<?php foreach($colors as $sidebar_id => $color) : ?>
<div class="fw-ext-sidebars-location empty <?php echo esc_attr($id)?> <?php echo esc_attr($color);?>" data-color="<?php echo esc_attr($color);?>">
<?php $short_sidebar_name = strlen($sidebars[$sidebar_id]->get_name()) > 20 ? mb_substr($sidebars[$sidebar_id]->get_name(), 0, 20) . '...' : $sidebars[$sidebar_id]->get_name(); ?>
<small class="fw-ext-sidebars-placeholder-title"><?php echo __(sprintf('Replace %s with:', $short_sidebar_name ), 'fw') ?></small>
<select class="sidebar-selectize <?php echo esc_attr($id); ?>-select">
<?php if (isset($sidebars) and is_array($sidebars)) :?>
<?php foreach($sidebars as $sidebar):?>
<option value="<?php echo esc_attr($sidebar->get_id()) ?>"><?php echo $sidebar->get_name(); ?></option>
<?php endforeach;?>
<?php endif;?>
</select>
</div>
<?php endforeach; ?>
</div>
<div class="fw-clear"></div>
<div class="fw-ext-sidebars-desc fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<?php _e('Select sidebar you wish to replace.', 'fw')?>
</div>
</div>
<div class="fw-clear"></div>
<div id="fw-add-button" class="fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<input id="submit-settings-<?php echo esc_attr($id) ?>" type="button" class="button button-primary button-large" value="<?php _e('Add Sidebar','fw')?>" />
<span class="spinner fw-ext-sidebars-submiting-<?php echo esc_attr($id) ?>"></span>
</div>
<div class="fw-clear"></div>

View File

@@ -0,0 +1,30 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<div class="fw-ext-sidebars-box-holder fw-ext-sidebars-created" data-tab-name="created" >
<div class="fw-ext-sidebars-created-tab-title"><?php _e('Sidebars for', 'fw') ?></div>
<div class="fw-ext-sidebars-preset-list">
<?php if (is_array($created_sidebars)) : ?>
<?php foreach($created_sidebars as $item) : ?>
<div class="fw-ext-sidebars-created-tab-preset" data-type="<?php echo isset($item['type']) ? $item['type'] : ''?>" data-preset-id="<?php echo isset($item['preset_id']) ? $item['preset_id'] : ''?>">
<span class="fw-ext-sidebars-preset-edit-span">
<span class="spinner fw-ext-sidebars-preset-editing"></span>
<a href="#" class="fw-ext-sidebars-preset-edit">
<?php echo isset($item['page_names']) ? $item['page_names'] : $item['label']?>
</a>
<span class="fw-ext-sidebars-desc">&nbsp;(<?php echo isset($item['page_names']) ? __('For Specific Page', 'fw') : __('For Grouped Page', 'fw') ?>)</span>
</span>
<span class="fw-ext-sidebars-preset-remove-span">
<a href="#" class="fw-ext-sidebars-preset-remove dashicons fw-x"></a>
</span>
<span class="spinner fw-ext-sidebars-preset-removing"></span>
</div>
<?php endforeach;?>
<?php endif;?>
</div>
</div>

View File

@@ -0,0 +1,43 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<div class="fw-ext-sidebars-box-holder" data-tab-name="grouped">
<div class="fw-ext-sidebars-option-label fw-backend-option-grouped-pages-wrap fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-option-sidebars-for-<?php echo esc_attr($id) ?>"><?php _e('For group','fw') ?></label>
<div class="fw-clear"></div>
</div>
</div>
<div class="fw-ext-sidebars-selector fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<div class="fw-inner fw-backend-option-fixed-width">
<?php
echo fw()->backend->option_type('select')->render($id, $grouped_options, array(
'id_prefix' => 'fw-option-sidebars-for-',
'value' => ''
));
?>
</div>
</div>
<div class="fw-clear"></div>
<div class="fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<div class="fw-ext-sidebars-desc"><?php _e('Select group of pages you want to set a sidebar for.','fw')?></div>
</div>
<div class="fw-clear"></div>
<?php if ( fw()->extensions->get('sidebars')->is_missing_config() ) : ?>
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-sidebars-positions-mode-replace.php'), array(
'id' => $id. '-positions',
'sidebars' => $sidebars,
), false); ?>
<?php else : ?>
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-sidebars-positions-mode-insert.php'), array(
'data_positions_options' => $data_positions_options,
'id' => $id. '-positions',
'sidebars' => $sidebars,
), false); ?>
<?php endif; ?>
</div>

View File

@@ -0,0 +1,51 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<div class="fw-ext-sidebars-box-holder" data-tab-name="specific">
<div class="fw-ext-sidebars-option-label fw-backend-option-specific-pages-wrap fw-col-sm-4 fw-col-md-3 fw-col-lg-2">
<div class="fw-inner">
<label for="fw-select-sidebar-for-<?php echo esc_attr($id) ?>"><?php _e('For specific','fw') ?></label>
<div class="fw-clear"></div>
</div>
</div>
<div class="fw-ext-sidebars-specific-input fw-ext-sidebars-selector fw-col-sm-8 fw-col-md-9 fw-col-lg-10">
<div class="fw-inner fw-row fw-backend-option-fixed-width">
<div class="fw-col-xs-4">
<?php
echo fw()->backend->option_type('select')->render($id, $specific_options, array(
'id_prefix' => 'fw-option-sidebars-for-',
'value' => ''
));
?>
</div>
<div class="fw-col-xs-8">
<div class="ui-widget fw-border-box-sizing" >
<input id="specific-field-id" type="text" class="autocomplete-ui fw-option" name="specific-field-id" placeholder="<?php echo esc_attr(__('Type to search ...', 'fw')) ?>" />
</div>
</div>
</div>
</div>
<div class="fw-col-sm-8 fw-col-sm-offset-4 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2">
<div class="fw-ext-sidebars-desc"><?php _e('Search for a specific page you want to set a sidebar for','fw')?></div>
</div>
<div class="fw-clear"></div>
<div class="sidebars-specific-pages fw-col-sm-8 fw-col-md-9 fw-col-md-offset-3 fw-col-lg-10 fw-col-lg-offset-2"><!-- Here will be appear specific pages --></div>
<div class="fw-clear"></div>
<?php if ( fw()->extensions->get('sidebars')->is_missing_config() ) : ?>
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-sidebars-positions-mode-replace.php'), array(
'data_positions_options' => $data_positions_options,
'id' => $id. '-positions',
'sidebars' => $sidebars,
), false); ?>
<?php else : ?>
<?php fw_render_view(fw()->extensions->get('sidebars')->get_declared_path('/views/backend-sidebars-positions-mode-insert.php'), array(
'data_positions_options' => $data_positions_options,
'id' => $id. '-positions',
'sidebars' => $sidebars,
), false); ?>
<?php endif; ?>
</div>

View File

@@ -0,0 +1,7 @@
<?php if (!defined('FW')) die('Forbidden'); ?>
<aside id="no-widget" class="widget before-widget-class widget widget_calendar">
<p class="fw-frontend-ext-sidebars-no-widget" >
<?php _e(sprintf('The sidebar (%s) you added has no widgets. Please add some from the ', $sidebar_id), 'fw'); ?>
<a href="<?php echo admin_url('widgets.php') ?>" target="_blank"><?php _e('Widgets Page', 'fw'); ?></a>
</p>
</aside>