$list ) {
$files[$list] = $directory . $list;
}
return $files;
}
return array();
}
function lightspeed_list_files_with_uri( $directory, $uri )
{
if ( file_exists( $directory ) ) {
$lists = array_values( array_diff( scandir( $directory ), array( '..', '.', 'index.php' ) ) );
$files = array();
foreach ( $lists as $list_key => $list ) {
$files[$list] = $uri . $list;
}
return $files;
}
return array();
}
function lightspeed_get_custom_directory( $is_child = false )
{
if ( $is_child ) {
$template = get_stylesheet_directory();
} else {
$template = get_template_directory();
}
return $template . '/all-bootstrap-blocks/lightspeed/custom/';
}
function lightspeed_get_custom_directory_uri( $is_child = false )
{
if ( $is_child ) {
$template = get_stylesheet_directory_uri();
} else {
$template = get_template_directory_uri();
}
return $template . '/all-bootstrap-blocks/lightspeed/custom/';
}
function lightspeed_get_placeholder_path()
{
$placeholder = areoi2_get_option( 'areoi-lightspeed-company-stock-media', 'default' );
if ( !$placeholder ) $placeholder = 'default';
$directory = AREOI__PLUGIN_LIGHTSPEED_DIR . 'placeholders/';
$theme_directory = get_template_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
if ( file_exists( $theme_directory . $placeholder ) ) {
$directory = get_template_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
}
$theme_directory = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
if ( file_exists( $theme_directory . $placeholder ) ) {
$directory = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
}
return $directory . $placeholder;
}
function lightspeed_get_placeholder_uri()
{
$placeholder = areoi2_get_option( 'areoi-lightspeed-company-stock-media', 'default' );
if ( !$placeholder ) $placeholder = 'default';
$directory = AREOI__PLUGIN_LIGHTSPEED_URI . 'placeholders/';
$theme_directory = get_template_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
if ( file_exists( $theme_directory . $placeholder ) ) {
$directory = get_template_directory_uri() . '/all-bootstrap-blocks/lightspeed/placeholders/';
}
$theme_directory = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/placeholders/';
if ( file_exists( $theme_directory . $placeholder ) ) {
$directory = get_stylesheet_directory_uri() . '/all-bootstrap-blocks/lightspeed/placeholders/';
}
return $directory . $placeholder;
}
function lightspeed_get_block_templates( $block_folders, $is_blocks = true )
{
$templates = array();
foreach ( $block_folders as $block_folder_key => $block_folder ) {
$directory = AREOI__PLUGIN_LIGHTSPEED_DIR . ( $is_blocks ? '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 );
$child_templates = array();
if ( is_child_theme() ) {
$child_directory = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/' . $block_folder . '/';
$child_templates = lightspeed_list_files( $child_directory );
}
$all_templates = array_merge( $plugin_templates, $theme_templates, $child_templates );
sort( $all_templates, SORT_NATURAL | SORT_FLAG_CASE );
$block_templates = array(
array( 'value' => '', 'label' => 'Default' )
);
foreach ( $all_templates as $template ) {
$label = str_replace( '.php', '', $template );
$label = str_replace( '.svg', '', $label );
$label = str_replace( '-', ' ', $label );
$label = ucwords( $label );
$block_templates[] = array(
'value' => $template,
'label' => $label
);
}
$templates[$block_folder_key] = $block_templates;
}
return $templates;
}
function lightspeed_get_template( $block_type, $block_order, $with_path = true )
{
$alternate = ( $block_order % 2 == 0 && in_array( $block_type, array( 'content-with-media' ) ) ) ? '-alternate' : '';
$fallback = areoi2_get_option( 'areoi-lightspeed-blocks-' . $block_type . $alternate );
if ( !$fallback ) $fallback = areoi2_get_option( 'areoi-lightspeed-blocks-' . $block_type );
if ( !$fallback ) $fallback = 'basic.php';
$template = lightspeed_get_template_directory(
$block_type,
'templates/' . lightspeed_get_attribute( 'filename', $fallback )
);
if ( $with_path ) return $template;
return lightspeed_get_attribute( 'filename', $fallback );
}
function lightspeed_get_is_first_strip()
{
global $lightspeed_block_order;
$header_template_part = get_block_template( get_stylesheet() . '//' . 'header', 'wp_template_part' );
$position = null;
if ( $header_template_part ) {
$header_blocks = parse_blocks( $header_template_part->content );
foreach ( $header_blocks as $block_key => $block ) {
if ( !empty( $block['attrs']['position'] ) && in_array( $block['attrs']['position'], array( 'position-fixed', 'position-absolute' ) ) ) {
$position = true;
}
}
}
$is_first_strip = false;
if ( $position && $lightspeed_block_order == 1 ) $is_first_strip = true;
return $is_first_strip;
}
function lightspeed_get_block_styles( $is_first_strip, $padding, $padding_top, $mobile_padding, $mobile_padding_top )
{
$styles = '
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block,
.' . lightspeed_get_block_id() . ' .areoi-background-pattern-media {
padding: ' . $mobile_padding . 'px 0;
padding-top: ' . $mobile_padding_top . 'px;
}
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block img,
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block video {
display: block;
}
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block > div.container > .row:not(.block-editor-block-preview__content-iframe .row),
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block > div.container-fluid > .row:not(.block-editor-block-preview__content-iframe .row) {
min-height: calc( ' . lightspeed_get_attribute( 'size', '100vh' ) . ' - ' . ( $mobile_padding + $mobile_padding_top ) . 'px );
}
@media only screen and (min-width: ' . areoi2_get_option( 'areoi-layout-grid-grid-breakpoint-lg', '992px' ) . ') {
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block,
.' . lightspeed_get_block_id() . ' .areoi-background-pattern-media {
padding: ' . $padding . 'px 0;
padding-top: ' . $padding_top . 'px;
}
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block > div.container > .row:not(.block-editor-block-preview__content-iframe .row),
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block > div.container-fluid > .row:not(.block-editor-block-preview__content-iframe .row) {
min-height: calc( ' . lightspeed_get_attribute( 'size', '100vh' ) . ' - ' . ( $padding + $padding_top ) . 'px );
}
}
';
$mask = null;
if ( lightspeed_get_attribute( 'mask', false ) ) $mask = lightspeed_get_attribute( 'mask', false );
$mask_template = lightspeed_get_masks_directory_uri( $mask );
if ( $mask ) {
$styles .= '
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block .areoi-has-mask {
mask-image: url(' . $mask_template . ');
-webkit-mask-image: url(' . $mask_template . ');
}
';
}
$introduction_color = lightspeed_get_attribute( 'introduction_color', lightspeed_get_default_color( 'text' ) );
$link_color = lightspeed_get_theme_color( $introduction_color );
$styles .= '
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block a:not(.btn) {
color: ' . $link_color . ';
}
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block .bg-dark a:not(.btn) {
color: ' . lightspeed_get_theme_color( 'light' ) . ';
}
.' . lightspeed_get_block_id() . '.areoi-lightspeed-block .bg-light a:not(.btn) {
color: ' . lightspeed_get_theme_color( 'dark' ) . ';
}
';
return $styles;
}
function lightspeed_get_divider( $block_order )
{
$divider = areoi2_get_option( 'areoi-lightspeed-styles-strip-divider', 'none.svg' );
if ( $block_order == 1 ) $divider = 'none.svg';
if ( lightspeed_get_attribute( 'divider', false ) ) $divider = lightspeed_get_attribute( 'divider', false );
return $divider;
}
function lightspeed_get_divider_styles( $block_order )
{
$divider = null;
if ( $block_order == 1 ) $divider = 'none.svg';
if ( lightspeed_get_attribute( 'divider', false ) ) $divider = lightspeed_get_attribute( 'divider', false );
$divider_template = lightspeed_get_dividers_directory_uri( $divider );
$divider_styles = '';
if ( $divider ) {
$divider_styles .= '
mask-image: url(' . $divider_template . ');
-webkit-mask-image: url(' . $divider_template . ');
';
}
return $divider_styles;
}
function lightspeed_set_attribute( $key, $value )
{
global $lightspeed_attributes;
$lightspeed_attributes[$key] = $value;
}
function lightspeed_get_attribute( $key, $default = null )
{
global $lightspeed_attributes;
if (
isset( $lightspeed_attributes[$key] ) &&
( !empty( $lightspeed_attributes[$key] ) || $lightspeed_attributes[$key] === false ) &&
$lightspeed_attributes[$key] !== 'Default'
) {
return $lightspeed_attributes[$key];
}
return $default;
}
function lightspeed_attribute( $key, $default = null )
{
echo lightspeed_get_attribute( $key, $default );
}
function lightspeed_get_block_id_append()
{
global $lightspeed_attributes;
if ( !empty( $lightspeed_attributes['block_id'] ) ) {
return $lightspeed_attributes['block_id'];
}
return md5( serialize( $lightspeed_attributes ) . date( 'H:i:s' ) );
}
function lightspeed_get_block_id()
{
return 'block-' . lightspeed_get_block_id_append();
}
function lightspeed_block_id()
{
echo lightspeed_get_block_id();
}
function lightspeed_get_block_classes( $block )
{
$classes = array();
$classes[] = lightspeed_get_block_id();
$classes[] = 'areoi-lightspeed-block';
$classes[] = 'areoi-lightspeed-' . $block;
$classes[] = 'areoi-divider';
if ( lightspeed_get_attribute( 'align', false ) ) {
$classes[] = 'align' . lightspeed_get_attribute( 'align', false );
}
$divider = areoi2_get_option( 'areoi-lightspeed-styles-strip-divider', false );
if ( $divider && $divider != 'none.svg' ) {
$classes[] = 'areoi-divider-styled';
}
$pattern = areoi2_get_option( 'areoi-lightspeed-styles-strip-pattern', false );
if ( $pattern && !empty( lightspeed_get_attribute( 'exclude_pattern', false ) ) ) {
$classes[] = 'areoi-pattern-none';
}
$transition = areoi2_get_option( 'areoi-lightspeed-transition-transition', false );
if ( $transition && !empty( lightspeed_get_attribute( 'exclude_transition', false ) ) ) {
$classes[] = 'areoi-transition-none';
}
$parallax = areoi2_get_option( 'areoi-lightspeed-parallax-parallax', false );
if ( $parallax && !empty( lightspeed_get_attribute( 'exclude_parallax', false ) ) ) {
$classes[] = 'areoi-parallax-none';
}
if ( lightspeed_get_attribute( 'utilities_bg', null ) && lightspeed_get_attribute( 'utilities_bg', null ) != 'Default' ) $classes[] = lightspeed_get_attribute( 'utilities_bg', null );
if ( lightspeed_get_attribute( 'utilities_text', null ) && lightspeed_get_attribute( 'utilities_text', null ) != 'Default' ) $classes[] = lightspeed_get_attribute( 'utilities_text', null );
if ( lightspeed_get_attribute( 'utilities_border', null ) && lightspeed_get_attribute( 'utilities_border', null ) != 'Default' ) $classes[] = lightspeed_get_attribute( 'utilities_border', null );
return implode( ' ', $classes );
}
function lightspeed_get_media_col_class()
{
$media_fit = lightspeed_get_attribute( 'media_fit', 'cover' );
$classes = array();
$classes[] = 'areoi-media-col';
$classes[] = 'areoi-media-col-' . $media_fit;
return implode( ' ', $classes );
}
function lightspeed_media_col_class()
{
echo lightspeed_get_media_col_class();
}
function lightspeed_block_classes( $block )
{
echo implode( ' ', lightspeed_get_block_classes( $block ) );
}
function lightspeed_get_template_directory( $block, $filename )
{
$template = '';
$theme_dir = get_template_directory() . '/all-bootstrap-blocks/lightspeed/' . $block . '/' . $filename;
$theme_dir_custom = get_template_directory() . '/all-bootstrap-blocks/lightspeed/custom/' . $block . '/' . $filename;
$child_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/' . $block . '/' . $filename;
$child_custom_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/custom/' . $block . '/' . $filename;
if ( file_exists( $child_dir ) ) {
$template = $child_dir;
} elseif ( file_exists( $child_custom_dir ) ) {
$template = $child_custom_dir;
} elseif ( file_exists( $theme_dir ) ) {
$template = $theme_dir;
} elseif ( file_exists( $theme_dir_custom ) ) {
$template = $theme_dir_custom;
} else {
$template = AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/' . $block . '/' . $filename;
}
return $template;
}
function lightspeed_get_content_directory( $filename )
{
$template = '';
$theme_dir = get_template_directory() . '/all-bootstrap-blocks/lightspeed/content/' . $filename;
$child_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/content/' . $filename;
if ( file_exists( $child_dir ) ) {
$template = $child_dir;
} elseif ( file_exists( $theme_dir ) ) {
$template = $theme_dir;
} else {
$template = AREOI__PLUGIN_LIGHTSPEED_DIR . 'content/' . $filename;
}
return $template;
}
function lightspeed_get_patterns_directory( $filename )
{
$template = '';
$theme_dir = get_template_directory() . '/all-bootstrap-blocks/lightspeed/patterns/' . $filename;
$child_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/patterns/' . $filename;
if ( file_exists( $child_dir ) ) {
$template = $child_dir;
} elseif ( file_exists( $theme_dir ) ) {
$template = $theme_dir;
} else {
$template = AREOI__PLUGIN_LIGHTSPEED_DIR . 'patterns/' . $filename;
}
return $template;
}
function lightspeed_get_dividers_directory_uri( $filename )
{
$template = '';
$theme_dir = get_template_directory() . '/all-bootstrap-blocks/lightspeed/dividers/' . $filename;
$theme_uri = get_template_directory_uri() . '/all-bootstrap-blocks/lightspeed/dividers/' . $filename;
$child_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/dividers/' . $filename;
$child_theme_uri = get_stylesheet_directory_uri() . '/all-bootstrap-blocks/lightspeed/dividers/' . $filename;
if ( file_exists( $child_dir ) ) {
$template = $child_theme_uri;
} elseif ( file_exists( $theme_dir ) ) {
$template = $theme_uri;
} else {
$template = AREOI__PLUGIN_LIGHTSPEED_URI . 'dividers/' . $filename;
}
return $template;
}
function lightspeed_get_masks_directory_uri( $filename )
{
$template = '';
$theme_dir = get_template_directory() . '/all-bootstrap-blocks/lightspeed/masks/' . $filename;
$theme_uri = get_template_directory_uri() . '/all-bootstrap-blocks/lightspeed/masks/' . $filename;
$child_dir = get_stylesheet_directory() . '/all-bootstrap-blocks/lightspeed/masks/' . $filename;
$child_theme_uri = get_stylesheet_directory_uri() . '/all-bootstrap-blocks/lightspeed/masks/' . $filename;
if ( file_exists( $child_dir ) ) {
$template = $child_theme_uri;
} elseif ( file_exists( $theme_dir ) ) {
$template = $theme_uri;
} else {
$template = AREOI__PLUGIN_LIGHTSPEED_URI . 'masks/' . $filename;
}
return $template;
}
function lightspeed_get_theme_color( $col )
{
global $areoi_theme_colors;
$theme_colors = $areoi_theme_colors;
if ( !is_array( $col ) ) {
$clean_col = str_replace( 'bg-', '', $col );
$clean_col = str_replace( 'text-', '', $clean_col );
$clean_col = str_replace( 'border-', '', $clean_col );
$clean_col = str_replace( 'hex-', '', $clean_col );
if ( isset( $theme_colors[$clean_col] ) ) {
$col = $theme_colors[$clean_col];
}
}
return $col;
}
function lightspeed_hex_to_rgb( $hex )
{
$R1 = hexdec(substr($hex, 1, 2));
$G1 = hexdec(substr($hex, 3, 2));
$B1 = hexdec(substr($hex, 5, 2));
return [
'r' => $R1,
'g' => $G1,
'b' => $B1,
];
}
function lightspeed_get_contrast_color( $col )
{
if ( !is_array( $col ) ) {
$col = lightspeed_get_theme_color( $col );
}
// hex_color RGB
if ( !is_array( $col ) && str_starts_with( $col, '#' ) ) {
$rgb = lightspeed_hex_to_rgb( $col );
$R1 = $rgb['r'];
$G1 = $rgb['g'];
$B1 = $rgb['b'];
} else {
$R1 = $col['r'];
$G1 = $col['g'];
$B1 = $col['b'];
}
// Black RGB
$blackColor = "#000000";
$R2BlackColor = hexdec(substr($blackColor, 1, 2));
$G2BlackColor = hexdec(substr($blackColor, 3, 2));
$B2BlackColor = hexdec(substr($blackColor, 5, 2));
// Calc contrast ratio
$L1 = 0.2126 * pow($R1 / 255, 2.2) +
0.7152 * pow($G1 / 255, 2.2) +
0.0722 * pow($B1 / 255, 2.2);
$L2 = 0.2126 * pow($R2BlackColor / 255, 2.2) +
0.7152 * pow($G2BlackColor / 255, 2.2) +
0.0722 * pow($B2BlackColor / 255, 2.2);
$contrastRatio = 0;
if ($L1 > $L2) {
$contrastRatio = (int)(($L1 + 0.05) / ($L2 + 0.05));
} else {
$contrastRatio = (int)(($L2 + 0.05) / ($L1 + 0.05));
}
// If contrast is more than 5, return black color
if ($contrastRatio > 5) {
return '#000000';
} else {
// if not, return white color.
return '#FFFFFF';
}
}
function lightspeed_get_default_color( $type, $override_color = null )
{
$color = $type == 'btn' ? 'btn-primary' : null;
$contrast = null;
if ( lightspeed_get_attribute( 'background_display', null ) ) {
if ( lightspeed_get_attribute( 'background_display_overlay', null ) && lightspeed_get_attribute( 'background_overlay', null ) ) {
$contrast = lightspeed_get_contrast_color( lightspeed_get_attribute( 'background_overlay', null )['rgb'] );
} elseif ( lightspeed_get_attribute( 'background_utility', null ) ) {
$contrast = lightspeed_get_contrast_color( lightspeed_get_attribute( 'background_utility', null ) );
} elseif ( lightspeed_get_attribute( 'background_color', null ) ) {
$contrast = lightspeed_get_contrast_color( lightspeed_get_attribute( 'background_color', null )['rgb'] );
} elseif ( lightspeed_get_attribute( 'main_background_color', null ) ) {
$contrast = lightspeed_get_contrast_color( lightspeed_get_attribute( 'main_background_color', null )['rgb'] );
}
}
if ( $override_color ) {
if ( $override_color == 'bg-transparent' && lightspeed_get_attribute( 'block_type', null ) == 'header' ) {
$contrast = lightspeed_get_contrast_color( 'bg-primary' );
} else {
$contrast = lightspeed_get_contrast_color( $override_color );
}
}
if ( $contrast == '#FFFFFF' ) {
$color = $type != 'logo' ? $type . '-light' : 'light';
} elseif ( $contrast == '#000000' ) {
$color = $type != 'logo' ? $type . '-dark' : 'dark';
}
if ( $type == 'hex' ) $color = lightspeed_get_theme_color( $color );
return $color;
}
function lightspeed_get_logo( $type, $color = null )
{
$logos = array(
'dark' => areoi2_get_option( 'areoi-lightspeed-company-logo-dark', null ),
'light' => areoi2_get_option( 'areoi-lightspeed-company-logo-light', null ),
);
$icons = array(
'dark' => areoi2_get_option( 'areoi-lightspeed-company-icon-dark', null ),
'light' => areoi2_get_option( 'areoi-lightspeed-company-icon-light', null ),
);
if ( !$color ) {
$color = lightspeed_get_default_color( 'logo' );
}
$content = '';
switch ( $type ) {
case 'icon':
if ( !empty( $icons[$color] ) ) {
$content .= '
';
}
break;
default:
if ( !empty( $logos[$color] ) ) {
$content .= '
';
}
break;
}
return $content;
}
function lightspeed_logo( $color = 'dark' )
{
if ( !empty( lightspeed_get_logo( lightspeed_get_attribute( 'logo', null ), lightspeed_get_attribute( 'logo_color', $color ) ) ) ) : ?>
' . lightspeed_get_logo( 'icon' ) . '
';
}
if ( $sub_heading && $original_level < 3 ) {
$content .= '
' . $sub_heading . '
'; } if ( trim( $heading ) || trim( $sub_heading ) ) { switch ( $heading_template ) { case 'basic': case 'dotted': case 'wide': $content .= '' . get_the_excerpt() . '
'; if ( is_archive() ) $introduction = get_the_archive_description(); } $introduction_color = lightspeed_get_attribute( 'introduction_color', lightspeed_get_default_color( 'text' ) ); $introduction_class = ''; $modal_id = 'modal-' . lightspeed_get_block_id(); $heading = lightspeed_get_attribute( 'heading', 'Continue Reading' ); if ( $item ) { $has_cta = $item['cta']; $introduction = $item['introduction']; if ( !empty( $item['background_color'] ) ) $introduction_color = lightspeed_get_default_color( 'text', $item['background_color'] ); if ( !empty( $item['introduction_color'] ) ) $introduction_color = $item['introduction_color']; $introduction_class = ''; $modal_id .= '-item-' . $item['id']; $heading = !empty( $item['heading'] ) ? $item['heading'] : 'Continue Reading'; $limit = 220; } $introduction_strlen = strlen( wp_strip_all_tags( $introduction ) ); $introduction_short = $introduction; if ( ( lightspeed_get_attribute( 'include_read_more', null ) || ( isset( $item['include_read_more'] ) && $item['include_read_more'] ) ) && $introduction_strlen > ($limit*2) ) { $introduction_short = substr( strip_tags( str_replace( '', "' . $introduction_short . '
'; global $areoi_introduction_modals; $areoi_introduction_modals[$modal_id] = '' . get_the_excerpt() . '
', $company_address ) : $company_address ?>