$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 ) {
$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';
}
return $color;
}
function lightspeed_get_logo( $type, $color = null )
{
$logos = array(
'dark' => get_option( 'areoi-lightspeed-company-logo-dark', null ),
'light' => get_option( 'areoi-lightspeed-company-logo-light', null ),
);
$icons = array(
'dark' => get_option( 'areoi-lightspeed-company-icon-dark', null ),
'light' => 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_get_heading( $level, $item = null )
{
$content = '';
$heading_template = '';
if ( $level < 3 ) $heading_template = get_option( 'areoi-lightspeed-styles-headings', null );
$level_class = '';
if ( $level == 3 && !lightspeed_get_attribute( 'heading', null ) ) {
$level = 2;
$level_class = 'h3';
}
$heading = lightspeed_get_attribute( 'heading', null );
$heading_color = lightspeed_get_attribute( 'heading_color', lightspeed_get_default_color( 'text' ) );
$sub_heading = lightspeed_get_attribute( 'sub_heading', null );
$sub_heading_color = lightspeed_get_attribute( 'sub_heading_color', lightspeed_get_default_color( 'text' ) );
if ( $item ) {
$heading = $item['heading'];
if ( !empty( $item['background_color'] ) ) $heading_color = lightspeed_get_default_color( 'text', $item['background_color'] );
if ( !empty( $item['heading_color'] ) ) $heading_color = $item['heading_color'];
}
$border_color = str_replace( 'text-', 'border-', $heading_color );
if ( $heading ) {
$include_icon = get_option( 'areoi-lightspeed-styles-heading-icon', null );
if ( $include_icon && $level < 3 ) {
$content .= '
' . lightspeed_get_logo( 'icon' ) . '
';
}
if ( $sub_heading && $level < 3 ) {
$content .= '' . $sub_heading . '
';
}
switch ( $heading_template ) {
case 'basic':
case 'dotted':
case 'wide':
$content .= '
' . $heading . '
';
break;
case 'basic-top':
case 'dotted-top':
case 'wide-top':
$content .= '
' . $heading . '
';
break;
default:
$content .= '
' . $heading . '
';
break;
}
}
return $content;
}
function lightspeed_heading( $level, $item = null )
{
echo lightspeed_get_heading( $level, $item );
}
function lightspeed_get_introduction( $item = null )
{
$content = '';
$introduction = lightspeed_get_attribute( 'introduction', null );
$introduction_color = lightspeed_get_attribute( 'introduction_color', lightspeed_get_default_color( 'text' ) );
$introduction_class = 'lead';
if ( $item ) {
$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 = '';
}
if ( strip_tags( $introduction ) ) {
$content .= '
' . $introduction . '
';
}
return $content;
}
function lightspeed_introduction( $item = null )
{
echo lightspeed_get_introduction( $item );
}
function lightspeed_get_cta( $item = null )
{
$content = '';
$include = lightspeed_get_attribute( 'include_cta', true );
$href = lightspeed_get_href( $item );
$size = lightspeed_get_attribute( 'cta_size', 'btn-lg' );
$color = lightspeed_get_attribute( 'cta_color', lightspeed_get_default_color( 'btn' ) );
$cta = lightspeed_get_attribute( 'cta', null );
if ( $item ) {
$include = $item['include_cta'];
$size = $item['cta_size'];
$cta = $item['cta'];
if ( !empty( $item['background_color'] ) ) $color = lightspeed_get_default_color( 'btn', $item['background_color'] );
if ( !empty( $item['cta_color'] ) ) $color = $item['cta_color'];
}
if ( $include && $cta ) {
$content .= '
' . lightspeed_get_btn_content( $cta ) . '
';
}
return $content;
}
function lightspeed_cta( $item = null )
{
echo lightspeed_get_cta( $item );
}
function lightspeed_get_media( $item = null )
{
$content = '';
$video = lightspeed_get_attribute( 'video', null );
$image = lightspeed_get_attribute( 'image', null );
if ( $item ) {
$video = $item['video'];
$image = $item['image'];
}
if ( $video ) {
$content .= '';
} elseif ( $image ) {
$content .= '
';
}
return $content;
}
function lightspeed_media( $item = null )
{
echo lightspeed_get_media( $item );
}
function lightspeed_get_btn_content( $content )
{
$selected_icon = get_option( 'areoi-lightspeed-styles-btn-icon', null );
$icon = '';
if ( $selected_icon ) {
$icon = '
';
}
return $content . ' ' . $icon;
}
function lightspeed_get_href( $item = null )
{
$link = '';
$url = lightspeed_get_attribute( 'url', null );
$open_in_new_tab = lightspeed_get_attribute( 'openInNewTab', null );
if ( $item ) {
$url = $item['url'];
$open_in_new_tab = $item['opensInNewTab'];
}
if ( $url ) {
$link = ' href="' . $url . '"';
if ( $open_in_new_tab ) $link .= ' href="' . $url . '"';
}
return $link;
}
function lightspeed_href( $item = null )
{
echo lightspeed_get_href( $item );
}
function lightspeed_get_stretched_link()
{
$link = '';
if ( lightspeed_get_href() ) $link .= '';
return $link;
}
function lightspeed_stretched_link()
{
echo lightspeed_get_stretched_link();
}
function lightspeed_btn_content()
{
echo lightspeed_get_btn_content();
}
function lightspeed_media_carousel( $medias, $type = 'square' )
{
?>
$item ) :
$heading_color = lightspeed_get_attribute( 'heading_color', lightspeed_get_default_color( 'text' ) );
if ( !empty( $item['heading_color'] ) ) $heading_color = $item['heading_color'];
$border_color = str_replace( 'text', 'border', lightspeed_get_attribute( 'heading_color', lightspeed_get_default_color( 'border' ) ) );
?>
';
}
function lightspeed_rectangle_spacer()
{
echo '
';
}
function lightspeed_get_posts()
{
$post_type = lightspeed_get_attribute( 'post_type', 'post' );
$display_posts = lightspeed_get_attribute( 'display_posts', 'selected' );
$posts_per_page = lightspeed_get_attribute( 'posts_per_page', '8' );
$orderby = lightspeed_get_attribute( 'orderby', 'title' );
$order = lightspeed_get_attribute( 'order', 'asc' );
$post_ids = lightspeed_get_attribute( 'post_ids', array() );
$show_all = in_array( 'all', $post_ids );
$post__in = $post_ids;
$post_parent__in = array();
$post_parent__not_in = array();
if ( $post_type == 'child-pages' || $display_posts == 'children' ) {
$post_parent__in = $post_ids;
$post__in = array();
}
if ( $show_all ) {
$post__in = array();
$post_parent__in = array('0');
}
if ( $show_all && $display_posts == 'children' ) {
$post__in = array();
$post_parent__in = array();
$post_parent__not_in = array('0');
}
$paged = get_query_var('paged') ? get_query_var('paged') : get_query_var('page');
$args = array(
'posts_per_page' => $posts_per_page,
'post_type' => $post_type,
'post_parent__in' => $post_parent__in,
'post_parent__not_in'=> $post_parent__not_in,
'post__in' => $post__in,
'orderby' => $orderby,
'order' => $order,
'paged' => $paged,
'ignore_sticky_posts' => 1
);
return new WP_Query( $args );
}
function lightspeed_post_pagination( $the_query )
{
if ( lightspeed_get_attribute( 'include_pagination', false ) ) :
$paged = get_query_var('paged') ? get_query_var('paged') : get_query_var('page');
$big = 999999999;
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages,
) );
$pages = str_replace( 'page-numbers', 'page-numbers btn ' . lightspeed_get_attribute( 'pagination_color', lightspeed_get_default_color( 'btn' ) ), $pages );
$pages = str_replace( 'current', 'current active', $pages );
?>
' . get_the_title() . '' . $heading_tag . '>';
}
return $content;
}
function lightspeed_get_post_introduction( $background_color = null )
{
$content = '';
$color = lightspeed_get_attribute( 'heading_color', lightspeed_get_default_color( 'text' ) );
if ( !empty( $background_color ) ) $color = lightspeed_get_default_color( 'text', $background_color );
if ( !empty( lightspeed_get_attribute( 'post_excerpt_color', null ) ) ) $color = lightspeed_get_attribute( 'post_excerpt_color', null );
if ( lightspeed_get_attribute( 'include_excerpt', true ) ) {
$content .= '
' . get_the_excerpt() . '
';
}
return $content;
}
function lightspeed_get_post_permalink()
{
$content = '';
if ( lightspeed_get_attribute( 'include_permalink', true ) ) {
$content .= '';
}
return $content;
}
function lightspeed_item( $item, $is_post = false )
{
if ( $is_post ) {
global $post;
$background_color = !empty( lightspeed_get_attribute( 'post_background_color', null ) ) ? lightspeed_get_attribute( 'post_background_color', null ) : '';
$media = get_the_post_thumbnail() && lightspeed_get_attribute( 'include_media', true ) ? get_the_post_thumbnail() : '';
$heading = lightspeed_get_post_heading( $background_color );
$introduction = lightspeed_get_post_introduction( $background_color );
$cta = lightspeed_get_post_permalink();
} else {
$background_color = !empty( $item['background_color'] ) ? $item['background_color'] : '';
$item['background_color'] = $background_color;
$media = lightspeed_get_media( $item );
$heading = lightspeed_get_heading( 3, $item );
$introduction = lightspeed_get_introduction( $item );
$cta = lightspeed_get_cta( $item );
}
?>
';
}
?>