Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-user-listing-2'; $_options = array( 'defaults' => array( 'columns' => 1, 'style' => 'user-listing-2', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, 'query_type' => 'user', ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } parent::__construct( $id, $_options ); } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { publisher_set_prop( $this->id, $atts ); publisher_set_prop( 'user-query', $this->get_query() ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_get_view( 'loop', 'listing-user-2' ); } /** * @return array */ public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'General', 'publisher' ), 'id' => 'general', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), ), ), ), parent::get_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( 'name' => __( 'User 2', 'publisher' ), "base" => $this->id, "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-2.png', ) ); } // page_builder_settings } // Publisher_User_Listing_2_Shortcode /** * Publisher User Listing 2 Widget */ class Publisher_User_Listing_2_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { $this->defaults['columns'] = 1; parent::__construct( 'bs-user-listing-2', __( 'Listing - User 2', 'publisher' ), array( 'description' => __( 'Widget for Listing Authors', 'publisher' ) ), false, 'user' ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-2-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } /** * Publisher User Listing 3 */ class Publisher_User_Listing_3_Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-user-listing-3'; $_options = array( 'defaults' => array( 'columns' => '', 'style' => 'user-listing-3', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, 'query_type' => 'user', ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } parent::__construct( $id, $_options ); } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { publisher_set_prop( $this->id, $atts ); publisher_set_prop( 'user-query', $this->get_query() ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_set_prop( 'listing-columns', $atts['columns'] ); publisher_get_view( 'loop', 'listing-user-3' ); } /** * @return array */ public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'General', 'publisher' ), 'id' => 'general', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), ), ), ), parent::get_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( 'name' => __( 'User 3', 'publisher' ), "base" => $this->id, "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-3.png', ) ); } // page_builder_settings } // Publisher_User_Listing_3_Shortcode /** * Publisher User Listing 3 Widget */ class Publisher_User_Listing_3_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { $this->defaults['columns'] = 1; parent::__construct( 'bs-user-listing-3', __( 'Listing - User 3', 'publisher' ), array( 'description' => __( 'Widget for Listing Authors', 'publisher' ) ), false, 'user' ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-3-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } /** * Publisher User Listing 4 */ class Publisher_User_Listing_4_Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-user-listing-4'; $_options = array( 'defaults' => array( 'columns' => 3, 'style' => 'user-listing-4', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, 'query_type' => 'user', ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } parent::__construct( $id, $_options ); } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { publisher_set_prop( $this->id, $atts ); publisher_set_prop( 'user-query', $this->get_query() ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_get_view( 'loop', 'listing-user-4' ); } /** * @return array */ public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'General', 'publisher' ), 'id' => 'general', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), '4' => __( '4 Column', 'publisher' ), '5' => __( '5 Column', 'publisher' ), ), ), ), parent::get_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( 'name' => __( 'User 4', 'publisher' ), "base" => $this->id, "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-4.png', ) ); } // page_builder_settings } // Publisher_User_Listing_4_Shortcode /** * Publisher User Listing 4 Widget */ class Publisher_User_Listing_4_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { $this->defaults['columns'] = 1; parent::__construct( 'bs-user-listing-4', __( 'Listing - User 4', 'publisher' ), array( 'description' => __( 'Widget for Listing Authors', 'publisher' ) ), false, 'user' ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-4-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } /** * Publisher User Listing 5 */ class Publisher_User_Listing_5_Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-user-listing-5'; $_options = array( 'defaults' => array( 'columns' => 3, 'style' => 'user-listing-5', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, 'query_type' => 'user', ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } parent::__construct( $id, $_options ); } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { publisher_set_prop( $this->id, $atts ); publisher_set_prop( 'user-query', $this->get_query() ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_get_view( 'loop', 'listing-user-5' ); } /** * @return array */ public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'General', 'publisher' ), 'id' => 'general', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), '4' => __( '4 Column', 'publisher' ), '5' => __( '5 Column', 'publisher' ), ), ), ), parent::get_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( 'name' => __( 'User 5', 'publisher' ), "base" => $this->id, "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-5.png', ) ); } // page_builder_settings } // Publisher_User_Listing_5_Shortcode /** * Publisher User Listing 5 Widget */ class Publisher_User_Listing_5_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { $this->defaults['columns'] = 1; parent::__construct( 'bs-user-listing-5', __( 'Listing - User 5', 'publisher' ), array( 'description' => __( 'Widget for Listing Authors', 'publisher' ) ), false, 'user' ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-user-listing-5-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } urn string */ public static function path( $append = '' ) { return bf_get_dir( 'editor-shortcodes/' . ltrim( $append, '/' ) ); } /** * Register Hooks */ public function init() { add_action( 'better-framework/after_setup', array( $this, 'setup_shortcodes' ) ); } /** * Print dynamic editor css */ public function load_editor_css() { if ( isset( $_GET['bf-editor-shortcodes'] ) ) { @header( 'Content-Type: text/css; charset=UTF-8' ); ob_start(); // IF post ID was bigger than 0 == valid post if ( intval( $_GET['bf-editor-shortcodes'] ) > 0 ) { if ( ! empty( self::$config['editor-style'] ) ) { @include self::$config['editor-style']; } else { include self::path( '/assets/css/editor-style.php' ); } // Injects dynamics generated CSS codes from PHP files outside of library if ( ! empty( self::$config['editor-dynamic-style'] ) ) { if ( is_array( self::$config['editor-dynamic-style'] ) ) { foreach ( self::$config['editor-dynamic-style'] as $_file ) { @include $_file; } } else { @include self::$config['editor-dynamic-style']; } } } $output = ob_get_clean(); $fonts = ''; // Move all @import to the beginning of generated CSS { preg_match_all( '/@import .*/', $output, $matched ); if ( ! empty( $matched[0] ) ) { foreach ( $matched[0] as $item ) { $fonts .= $item . "\n\n"; $output = str_replace( $item, '', $output ); } } } echo $fonts; echo $output; exit; } } /** * Is gutenberg active? * * @since 3.9.0 * @return bool */ public static function is_gutenberg_active() { if ( ! is_admin() || bf_is_doing_ajax( 'bf_ajax' ) || bf_is_block_render_request() || in_array( $GLOBALS['pagenow'], array( 'post.php', 'post-new.php' ) ) ) { if ( function_exists( 'disable_gutenberg' ) ) { return ! disable_gutenberg(); } if ( class_exists( 'Classic_Editor' ) ) { return self::active_editor() === 'block'; } return function_exists( 'register_block_type' ); } return false; } /** * Check default active editor in 'Classic Editor' plugin. * * @since 3.10.6 * @return string */ protected static function active_editor() { if ( ! class_exists( 'Classic_Editor' ) ) { return ''; } $status = bf_call_static_method( 'Classic_Editor', 'is_classic' ); if ( is_bool( $status ) ) { return $status ? 'classic' : 'block'; } $default_editor = get_option( 'classic-editor-replace' ); if ( get_option( 'classic-editor-allow-users' ) === 'allow' ) { $user_options = get_user_option( 'classic-editor-settings' ); if ( $user_options === 'block' || $user_options === 'classic' ) { $default_editor = $user_options; } } return $default_editor; } /** * Adds custom dynamic editor css * * @param array $stylesheets list of stylesheets uri * * @return array */ public function prepare_editor_style_uri( $stylesheets = array() ) { // Detect current active editor { $editor = 'tinymce'; if ( self::is_gutenberg_active() ) { $editor = 'gutenberg'; } } $url = home_url( '?bf-editor-shortcodes=' . bf_get_admin_current_post_id() . '&editor=' . $editor . '&cacheid=' . md5( json_encode( self::$config ) ) ); $url = set_url_scheme( $url ); // Add dynamic css file $stylesheets[] = $url; // Enqueue font awesome library from better framework $stylesheets[] = BF_URI . 'assets/css/font-awesome.min.css'; return $stylesheets; } /** * Add custom editor script */ public function append_editor_script() { wp_enqueue_script( 'bf-editor-script', $this->url( 'assets/js/edit-post-script.js' ), '', Better_Framework()->version ); } /** * Used for retrieving instance * * @param $fresh * * @return mixed */ public static function editor_instance( $fresh = false ) { if ( self::$editor_instance != null && ! $fresh ) { return self::$editor_instance; } if ( ! class_exists( 'BF_Editor_Shortcodes_TinyMCE' ) ) { require self::path( 'includes/class-bf-editor-shortcodes-tinymce.php' ); } return self::$editor_instance = new BF_Editor_Shortcodes_TinyMCE(); } /** * */ public function setup_shortcodes() { /** * Retrieves configurations * * @since 1.0.0 * * @param string $args reset panel data */ self::$config = apply_filters( 'better-framework/editor-shortcodes/config', self::$config ); // injects all our custom styles to TinyMCE add_filter( 'editor_stylesheets', array( $this, 'prepare_editor_style_uri' ), 100 ); // Register style for the Gutenberg add_action( 'enqueue_block_editor_assets', array( $this, 'gutenberg_styles' ) ); // Prints dynamic custom css if needed add_action( 'template_redirect', array( $this, 'load_editor_css' ), 1 ); add_action( 'admin_init', array( $this, 'load_editor_css' ), 1 ); $this->load_all_shortcodes(); // registers shortcodes add_action( 'init', array( $this, 'register_all_shortcodes' ), 50 ); global $pagenow; // Initiate custom shortcodes only in post edit editor if ( is_admin() && ( bf_is_doing_ajax() || in_array( $pagenow, array( 'post-new.php', 'post.php' ) ) ) ) { add_action( 'load-post.php', array( $this, 'append_editor_script' ) ); add_action( 'load-post-new.php', array( $this, 'append_editor_script' ) ); self::editor_instance(); } } /** * Loads all active shortcodes */ public function load_all_shortcodes() { self::set_shortcodes( apply_filters( 'better-framework/editor-shortcodes/shortcodes-array', array() ) ); } /** * Register shortcode from nested array * * @param $shortcode_key * @param $shortcode */ public function register_shortcode( $shortcode_key, $shortcode ) { // Menu if ( isset( $shortcode['type'] ) && $shortcode['type'] == 'menu' ) { foreach ( (array) $shortcode['items'] as $_shortcode_key => $_shortcode_value ) { $this->register_shortcode( $_shortcode_key, $_shortcode_value ); } return; } // Do not register shortcode if ( isset( $shortcode['register'] ) && $shortcode['register'] === false ) { return; } // External callback if ( isset( $shortcode['external-callback'] ) && $shortcode['external-callback'] ) { call_user_func( 'add' . '_' . 'shortcode', $shortcode_key, $shortcode['external-callback'] ); } elseif ( isset( $shortcode['callback'] ) ) { call_user_func( 'add' . '_' . 'shortcode', $shortcode_key, array( $this, $shortcode['callback'] ) ); } } /** * Registers all active shortcodes */ public function register_all_shortcodes() { foreach ( (array) self::get_shortcodes() as $shortcode_key => $shortcode ) { $this->register_shortcode( $shortcode_key, $shortcode ); } } /** * Enqueue WordPress theme styles within Gutenberg */ function gutenberg_styles() { $list = $this->prepare_editor_style_uri(); foreach ( $list as $k => $style ) { wp_enqueue_style( "bf-gutenberg-$k", $style, false, Better_Framework()->version, 'all' ); } } /** * Shortcode: Columns */ public function columns( $atts, $content = null ) { extract( shortcode_atts( array( 'class' => '' ), $atts ) ); $classes = array( 'row', 'bs-row-shortcode' ); if ( $class ) { $classes = array_merge( $classes, explode( ' ', $class ) ); } $output = '
'; $this->temp['columns'] = array(); // parse nested shortcodes and collect data do_shortcode( $content ); foreach ( $this->temp['columns'] as $column ) { $output .= $column; } unset( $this->temp['columns'] ); return $output . '
'; } /** * Shortcode Helper: Column */ public function column( $atts, $content = null ) { extract( shortcode_atts( array( 'size' => '1/1', 'class' => '', 'text_align' => '' ), $atts ), EXTR_SKIP ); $classes = array( 'column' ); if ( $class ) { $classes = array_merge( $classes, explode( ' ', $class ) ); } if ( stristr( $size, '/' ) ) { $size = str_replace( array( '1/1', '1/2', '1/3', '1/4', ), array( 'col-lg-12', 'col-lg-6', 'col-lg-4', 'col-lg-3', ), $size ); } else { $size = 'col-lg-6'; } // Add size to column classes array_push( $classes, $size ); // Add style such as text-align $style = ''; if ( in_array( $text_align, array( 'left', 'center', 'right' ) ) ) { array_push( $classes, esc_attr( strip_tags( $text_align ) ) ); } $this->temp['columns'][] = $column = '
' . do_shortcode( $content ) . '
'; return $column; } /** * Shortcode: List */ public function list_shortcode( $atts, $content = null ) { extract( shortcode_atts( array( 'style' => 'check', 'class' => '' ), $atts ), EXTR_SKIP ); $this->temp['list_style'] = $style; // parse nested shortcodes and collect data $content = do_shortcode( $content ); $content = preg_replace( '#^<\/p>|
|<\/div>|

$#', '', $content ); $content = preg_replace( '#<\/li>
#', '', $content ); // no list? if ( ! preg_match( '#<(ul|ol)[^<]*>#i', $content ) ) { $content = '

'; // escaped before } $content = preg_replace( '#