self::get_templates(), 'forms' => self::get_forms(), 'is_lightspeed' => areoi_is_lightspeed(), 'pattern' => get_option( 'areoi-lightspeed-styles-strip-pattern', false ), 'divider' => get_option( 'areoi-lightspeed-styles-strip-divider', false ), 'transition' => get_option( 'areoi-lightspeed-transition-transition', false ), 'parallax' => get_option( 'areoi-lightspeed-parallax-parallax', false ), ) ); wp_set_script_translations( 'areoi-lightspeed-blocks', AREOI__TEXT_DOMAIN ); } } public static function add_block_categories( $categories, $post ) { $new_category = [ 'slug' => 'areoi-lightspeed', 'title' => __( 'Lightspeed', AREOI__TEXT_DOMAIN ), 'icon' => '' ]; $new_categories[] = $new_category; return array_merge( $new_categories, $categories); } public static function add_scripts() { $enqueue = 'assets/js/global.js'; wp_enqueue_script( 'areoi-lightspeed', AREOI__PLUGIN_LIGHTSPEED_URI . $enqueue, array( 'jquery' ), filemtime( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ); $scripts = ''; ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'assets/js/site.js' ); $scripts .= ob_get_clean(); $transition = get_option( 'areoi-lightspeed-transition-transition', false ); if ( $transition ) { $enqueue = 'assets/js/transition.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $page_transition = get_option( 'areoi-lightspeed-transition-page', false ); if ( $page_transition ) { $enqueue = 'assets/js/transition-page.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $background_transition = get_option( 'areoi-lightspeed-transition-background', false ); if ( $background_transition ) { $enqueue = 'assets/js/transition-background.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $parallax = get_option( 'areoi-lightspeed-parallax-parallax', false ); if ( $parallax ) { $enqueue = 'assets/js/parallax.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $gallery = get_option( 'areoi-lightspeed-gallery-include', false ); if ( $gallery ) { $enqueue = 'assets/js/gallery.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } if ( $scripts ) { $scripts = ' jQuery(document).ready(function($){ ' . $scripts . ' }); '; wp_add_inline_script( 'areoi-lightspeed', areoi_minify_js( $scripts ) ); } } public static function add_admin_scripts() { $enqueue = 'assets/js/admin.js'; wp_enqueue_script( 'areoi-lightspeed-admin', AREOI__PLUGIN_LIGHTSPEED_URI . $enqueue, array( 'jquery' ), filemtime( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ); self::add_custom_fonts(); } public static function get_templates() { $block_folders = array( 'hero' => 'hero/templates', 'header_main' => 'header/templates/main', 'header_top_bar' => 'header/templates/top_bar', 'header_search' => 'header/templates/search', 'header_more' => 'header/templates/more', 'header_feature' => 'header/templates/feature', 'footer' => 'footer/templates', 'content_with_media'=> 'content-with-media/templates', 'content_with_items'=> 'content-with-items/templates', 'media' => 'media/templates', 'post_grid' => 'post-grid/templates', 'call_to_action' => 'call-to-action/templates', 'next_and_previous' => 'next-and-previous/templates', 'logos' => 'logos/templates', 'contact' => 'contact/templates', ); $templates = array(); foreach ( $block_folders as $block_folder_key => $block_folder ) { $directory = AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/' . $block_folder . '/'; $plugin_templates = lightspeed_list_files( $directory ); $theme_directory = get_template_directory() . '/all-bootstrap-blocks/lightspeed/' . $block_folder . '/'; $theme_templates = lightspeed_list_files( $theme_directory ); $all_templates = array_merge( $plugin_templates, $theme_templates ); sort( $all_templates, SORT_NATURAL | SORT_FLAG_CASE ); $block_templates = array( array( 'value' => '', 'label' => 'Default' ) ); foreach ( $all_templates as $template ) { $block_templates[] = array( 'value' => $template, 'label' => 'Template (' . $template . ')' ); } $templates[$block_folder_key] = $block_templates; } return $templates; } public static function get_forms() { $forms = array( array( 'value' => '', 'label' => 'None' ) ); if ( class_exists( 'Ninja_Forms' ) ) { $ninja_forms = Ninja_Forms()->form()->get_forms(); foreach ( $ninja_forms as $form_key => $form ) { $forms[] = array( 'value' => $form->get_id(), 'label' => $form->get_setting( 'title' ) ); } } return $forms; } public static function add_custom_fonts() { $fonts = array(); $heading_font = get_option( 'areoi-lightspeed-company-heading-font-url', '' ); $body_font = get_option( 'areoi-lightspeed-company-body-font-url', '' ); if ( $heading_font ) $fonts['areoi-heading-font'] = $heading_font; if ( $body_font && $body_font != $heading_font ) $fonts['areoi-body-font'] = $body_font; if ( !empty( $fonts ) ) { foreach ( $fonts as $font_key => $font ) { wp_enqueue_style( $font_key, $font, array(), '' ); } } } public static function add_styles() { self::add_custom_fonts(); ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'assets/css/lightspeed.css' ); $styles = ob_get_clean(); $styles .= self::generate_header_and_footer_styles(); $frame = get_option( 'areoi-lightspeed-styles-frame', false ); if ( $frame ) { add_action( 'wp_body_open', function() { echo '
'; }); $frame_color = get_option( 'areoi-lightspeed-styles-frame-color', '#fff' ); $styles .= ' .areoi-frame { background-color: ' . $frame_color . '; } .areoi-frame path { fill: ' . $frame_color . '; } '; } $gallery = get_option( 'areoi-lightspeed-gallery-include', false ); if ( $gallery ) { add_action( 'wp_body_open', function() { echo ' '; }); } function body_classes( $classes ) { $transition = get_option( 'areoi-lightspeed-transition-transition', false ); $page_transition = get_option( 'areoi-lightspeed-transition-page', false ); $background_transition = get_option( 'areoi-lightspeed-transition-background', false ); $hover_transition = get_option( 'areoi-lightspeed-transition-hover', false ); $parallax = get_option( 'areoi-lightspeed-parallax-parallax', false ); $background_parallax = get_option( 'areoi-lightspeed-parallax-background', false ); $components_parallax = get_option( 'areoi-lightspeed-parallax-components', false ); $patterns_parallax = get_option( 'areoi-lightspeed-parallax-patterns', false ); $frame = get_option( 'areoi-lightspeed-styles-frame', false ); $gallery = get_option( 'areoi-lightspeed-gallery-include', false ); if ( $transition ) $classes[] = 'has-areoi-transition areoi-transition-' . $transition; if ( $page_transition ) $classes[] = 'has-areoi-page-transition'; if ( $background_transition ) $classes[] = 'has-areoi-background-transition'; if ( $hover_transition ) $classes[] = 'has-areoi-hover-transition areoi-hover-transition-' . $hover_transition; if ( $parallax ) $classes[] = 'has-areoi-parallax'; if ( $background_parallax ) $classes[] = 'has-areoi-parallax-background'; if ( $components_parallax ) $classes[] = 'has-areoi-parallax-components'; if ( $patterns_parallax ) $classes[] = 'has-areoi-parallax-patterns'; if ( $frame ) $classes[] = 'has-areoi-frame areoi-frame-' . $frame; if ( $gallery ) $classes[] = 'has-areoi-gallery'; return $classes; } add_filter( 'body_class','body_classes' ); if ( $styles ) { $styles = str_replace( 'url(../', 'url(' . AREOI__PLUGIN_LIGHTSPEED_URI . '/assets/', $styles ); wp_add_inline_style( 'areoi-style-index', areoi_minify_css( $styles ) ); } } public static function generate_header_and_footer_styles() { $post = get_post(); $header_template_part = get_block_template( get_stylesheet() . '//' . 'header', 'wp_template_part' ); $footer_template_part = get_block_template( get_stylesheet() . '//' . 'footer', 'wp_template_part' ); $blocks = array(); if ( !empty( $header_template_part->content ) && has_blocks( $header_template_part->content ) ) { $blocks = array_merge( $blocks, parse_blocks( $header_template_part->content ) ); } if ( !empty( $footer_template_part->content ) && has_blocks( $footer_template_part->content ) ) { $blocks = array_merge( $blocks, parse_blocks( $footer_template_part->content ) ); } if ( !empty( $post->post_content ) && has_blocks( $post->post_content ) ) { $blocks = array_merge( $blocks, parse_blocks( $post->post_content ) ); } ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/header/styles/global.css' ); $global_header_styles = ob_get_clean(); ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/footer/styles/global.css' ); $global_footer_styles = ob_get_clean(); $styles = ''; $scripts = ''; $css_templates_used = array(); $js_templates_used = array(); $has_header = false; $has_footer = false; foreach ( $blocks as $block_key => $block ) { if ( in_array( $block['blockName'], array( 'areoi-lightspeed/header', 'areoi-lightspeed/footer' ) ) ) { $template = $block['blockName'] == 'areoi-lightspeed/footer' ? 'footer' : 'header'; if ( $template == 'header' ) $has_header = true; if ( $template == 'footer' ) $has_footer = true; } } if ( $has_header ) { $styles = $global_header_styles . $styles; } if ( $has_footer ) { $styles = $global_footer_styles . $styles; } return $styles; } } if ( areoi_is_lightspeed() ) add_action( 'init', array( 'AREOI_Lightspeed', 'init' ) );