\d+)/i', $agent, $B) && $B['v'] <= 7 ) || // Chrome lte 25 ( preg_match('/Chrome\/(?P\d+)/i', $agent, $B) && $B['v'] <= 25 ) || // Firefox lte 21 ( preg_match('/Firefox\/(?P\d+)/i', $agent, $B) && $B['v'] <= 21 ) || // Safari lte 7 ( preg_match('/Version\/(?P\d+).*?Safari\/\d+/i', $agent, $B) && $B['v'] <= 6 ); } /** * Autoload Page Builder specific classses. * * @param $class */ public static function autoloader( $class ) { $filename = false; if ( strpos( $class, 'SiteOrigin_Panels_Widgets_' ) === 0 ) { $filename = str_replace( 'SiteOrigin_Panels_Widgets_', '', $class ); $filename = str_replace( '_', '-', $filename ); $filename = strtolower( preg_replace( '/([a-z])([A-Z])/', '$1-$2', $filename ) ); $filename = plugin_dir_path( __FILE__ ) . 'inc/widgets/' . $filename . '.php'; } elseif ( strpos( $class, 'SiteOrigin_Panels_Compat_' ) === 0 ) { $filename = str_replace( array( 'SiteOrigin_Panels_Compat_', '_' ), array( '', '-' ), $class ); $filename = plugin_dir_path( __FILE__ ) . 'compat/' . strtolower( $filename ) . '.php'; } elseif ( strpos( $class, 'SiteOrigin_Panels_' ) === 0 ) { $filename = str_replace( array( 'SiteOrigin_Panels_', '_' ), array( '', '-' ), $class ); $filename = plugin_dir_path( __FILE__ ) . 'inc/' . strtolower( $filename ) . '.php'; } if ( ! empty( $filename ) && file_exists( $filename ) ) { include $filename; } } public static function activate() { add_option( 'siteorigin_panels_initial_version', SITEORIGIN_PANELS_VERSION, '', 'no' ); } /** * Initialize SiteOrigin Page Builder * * @action plugins_loaded */ public function init() { if ( ! is_admin() && siteorigin_panels_setting( 'sidebars-emulator' ) && ( ! get_option( 'permalink_structure' ) || get_option( 'rewrite_rules' ) ) ) { // Initialize the sidebars emulator. SiteOrigin_Panels_Sidebars_Emulator::single(); } // Initialize the language. load_plugin_textdomain( 'siteorigin-panels', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); // Initialize all the extra classes. SiteOrigin_Panels_Home::single(); // Check if we need to initialize the admin class. if ( is_admin() ) { SiteOrigin_Panels_Admin::single(); } } /** * Loads Page Builder compatibility to allow other plugins/themes */ public function init_compat() { // Compatibility with Widget Options plugin. if ( class_exists( 'WP_Widget_Options' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/widget-options.php'; } // Compatibility with Yoast plugins. if ( defined( 'WPSEO_FILE' ) || function_exists( 'yoast_wpseo_video_seo_init' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/yoast.php'; } // Compatibility with AMP plugin. if ( is_admin() && function_exists( 'amp_bootstrap_plugin' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/amp.php'; } // Compatibility with Gravity Forms. if ( class_exists( 'GFCommon' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/gravity-forms.php'; } $load_lazy_load_compat = false; // LazyLoad by WP Rocket. if ( defined( 'ROCKET_LL_VERSION' ) ) { $lazy_load_settings = get_option( 'rocket_lazyload_options' ); $load_lazy_load_compat = ! empty( $lazy_load_settings ) && ! empty( $lazy_load_settings['images'] ); // WP Rocket. } elseif ( function_exists( 'get_rocket_option' ) && ! defined( 'DONOTROCKETOPTIMIZE' ) ) { $load_lazy_load_compat = get_rocket_option( 'lazyload' ) && apply_filters( 'do_rocket_lazyload', true ); } if ( apply_filters( 'siteorigin_lazyload_compat', $load_lazy_load_compat ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/lazy-load-backgrounds.php'; } if ( class_exists( 'Jetpack' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/jetpack.php'; } if ( class_exists( 'Polylang' ) ) { require_once plugin_dir_path( __FILE__ ) . 'compat/polylang.php'; } } /** * @return mixed|void Are we currently viewing the home page. */ public static function is_home() { $home = ( is_front_page() && is_page() && get_option( 'show_on_front' ) == 'page' && get_option( 'page_on_front' ) == get_the_ID() && get_post_meta( get_the_ID(), 'panels_data' ) ); return apply_filters( 'siteorigin_panels_is_home', $home ); } /** * Check if we're currently viewing a page builder page. * * @param bool $can_edit Also check if the user can edit this page * * @return bool */ public static function is_panel( $can_edit = false ) { // Check if this is a panel $is_panel = ( siteorigin_panels_is_home() || ( is_singular() && get_post_meta( get_the_ID(), 'panels_data', false ) ) ); return $is_panel && ( ! $can_edit || ( ( is_singular() && current_user_can( 'edit_post', get_the_ID() ) ) || ( siteorigin_panels_is_home() && current_user_can( 'edit_theme_options' ) ) ) ); } /** * Check if we're in the Live Editor in the frontend. * * @return bool */ static function is_live_editor() { return ! empty( $_GET['siteorigin_panels_live_editor'] ); } public static function preview_url() { global $post, $wp_post_types; if ( empty( $post ) || empty( $wp_post_types ) || empty( $wp_post_types[ $post->post_type ] ) || ! $wp_post_types[ $post->post_type ]->public ) { $preview_url = add_query_arg( 'siteorigin_panels_live_editor', 'true', admin_url( 'admin-ajax.php?action=so_panels_live_editor_preview' ) ); } else { $preview_url = add_query_arg( 'siteorigin_panels_live_editor', 'true', set_url_scheme( get_permalink() ) ); } $preview_url = wp_nonce_url( $preview_url, 'live-editor-preview', '_panelsnonce' ); return $preview_url; } public static function container_settings() { $container = array( 'selector' => apply_filters( 'siteorigin_panels_theme_container_selector', '' ), 'width' => apply_filters( 'siteorigin_panels_theme_container_width', '' ), 'full_width' => false, ); $container['css_override'] = ! empty( $container['selector'] ) && ! empty( $container['width'] ); return $container; } /** * Get the Page Builder data for the home page. * * @return bool|mixed */ public function get_home_page_data() { $page_id = get_option( 'page_on_front' ); if ( empty( $page_id ) ) { $page_id = get_option( 'siteorigin_panels_home_page_id' ); } if ( empty( $page_id ) ) { return false; } $panels_data = get_post_meta( $page_id, 'panels_data', true ); if ( is_null( $panels_data ) ) { // Load the default layout $layouts = apply_filters( 'siteorigin_panels_prebuilt_layouts', array() ); $panels_data = ! empty( $layouts['default_home'] ) ? $layouts['default_home'] : current( $layouts ); } return $panels_data; } /** * Generate post content for WooCommerce shop page if it's using a PB layout. * * @param $content * * @return string * * @filter woocommerce_format_content */ public function generate_woocommerce_content( $content ) { if ( class_exists( 'WooCommerce' ) && is_shop() ) { return $this->generate_post_content( $content ); } return $content; } /** * Generate post content for the current post. * * @param $content * * @return string * * @filter the_content */ public function generate_post_content( $content ) { global $post, $preview; if ( empty( $post ) && ! in_the_loop() ) { return $content; } if ( ! apply_filters( 'siteorigin_panels_filter_content_enabled', true ) ) { return $content; } $post_id = $this->get_post_id(); // Check if this post has panels_data. if ( get_post_meta( $post_id, 'panels_data', true ) ) { $panel_content = SiteOrigin_Panels::renderer()->render( $post_id, // Add CSS if this is not the main single post, this is handled by add_single_css. $preview || $post_id !== get_queried_object_id() ); if ( ! empty( $panel_content ) ) { $content = $panel_content; if ( ! is_singular() ) { // This is an archive page, so try strip out anything after the more text. if ( preg_match( '//', $content, $matches ) ) { $content = explode( $matches[0], $content, 2 ); $content = $content[0]; $content = force_balance_tags( $content ); if ( ! empty( $matches[1] ) ) { $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); } else { $more_link_text = __( 'Read More', 'siteorigin-panels' ); } $more_link = apply_filters( 'the_content_more_link', ' ID}\" class=\"more-link\">$more_link_text", $more_link_text ); $content .= '

' . $more_link . '

'; } } } } return $content; } /** * Generate an excerpt for the current post, if possible. * * @param $text * * @return mixed|string */ public function generate_post_excerpt( $text ) { global $post; if ( ( empty( $post ) && ! in_the_loop() ) || $text !== '' ) { return $text; } $post_id = $this->get_post_id(); $panels_data = get_post_meta( $post_id, 'panels_data', true ); // If no panels_data is detected, check if the post has blocks. if ( empty( $panels_data ) ) { if ( function_exists( 'has_blocks' ) && has_blocks( get_the_content() ) ) { $parsed_content = parse_blocks( get_the_content() ); // Check if the first block is an SO Layout Block, and extract panels_data if it is. if ( $parsed_content[0]['blockName'] == 'siteorigin-panels/layout-block' && isset( $parsed_content[0]['attrs'] ) && ! empty( $parsed_content[0]['attrs']['panelsData'] ) ) { $panels_data = $parsed_content[0]['attrs']['panelsData']; } } } if ( $panels_data && ! empty( $panels_data['widgets'] ) ) { $raw_excerpt = ''; $excerpt_length = apply_filters( 'excerpt_length', 55 ); foreach ( $panels_data['widgets'] as $widget ) { $panels_info = $widget['panels_info']; if ( $panels_info['grid'] > 1 ) { // Limiting search for a text type widget to the first two PB rows to avoid having excerpt content // that's very far down in a post. break; } if ( $panels_info['class'] == 'SiteOrigin_Widget_Editor_Widget' || $panels_info['class'] == 'WP_Widget_Text' || $panels_info['class'] == 'WP_Widget_Black_Studio_TinyMCE' ) { $raw_excerpt .= ' ' . $widget['text']; // This is all effectively default behavior for excerpts, copied from the `wp_trim_excerpt` function. // We're just applying it to text type widgets content in the first two rows. $text = strip_shortcodes( $raw_excerpt ); $text = str_replace( ']]>', ']]>', $text ); if ( $this->get_localized_word_count( $text ) >= $excerpt_length ) { break; } // Check for more quicktag. if ( strpos( $text, '