init
This commit is contained in:
65
wp-content/themes/flatsome/inc/helpers/helpers-frontend.php
Normal file
65
wp-content/themes/flatsome/inc/helpers/helpers-frontend.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Load a template.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $vars
|
||||
* @return string
|
||||
*/
|
||||
function flatsome_template( $name, array $vars = array() ) {
|
||||
$located_template = locate_template( 'template-parts/' . $name . '.php' );
|
||||
if ( $located_template != '' ) {
|
||||
extract( $vars );
|
||||
ob_start();
|
||||
include $located_template;
|
||||
return ob_get_clean();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array into html attributes.
|
||||
*
|
||||
* @param array $atts
|
||||
* @return string
|
||||
*/
|
||||
function flatsome_html_atts( array $atts ) {
|
||||
$string = '';
|
||||
foreach ( $atts as $key => $value ) {
|
||||
if ( is_array( $value ) ) $value = implode( ' ', $value );
|
||||
$string .= "${key}=\"${value}\" ";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Flatsome Icon classes
|
||||
*/
|
||||
function get_flatsome_icon_class($style, $size = null){
|
||||
|
||||
$classes = array();
|
||||
if($style == 'small'){ $classes[] = 'icon plain';}
|
||||
if($style == 'outline'){ $classes[] = 'icon button circle is-outline';}
|
||||
if($style == 'outline-round'){ $classes[] = 'icon button round is-outline';}
|
||||
if($style == 'fill'){ $classes[] = 'icon primary button circle';}
|
||||
if($style == 'fill-round'){ $classes[] = 'icon primary button round';}
|
||||
if($size){ $classes[] = 'is-'.$size;}
|
||||
|
||||
return implode(' ', $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify CSS
|
||||
*/
|
||||
function flatsome_minify_css($css){
|
||||
//$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
|
||||
$css = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $css);
|
||||
return $css;
|
||||
}
|
||||
|
||||
|
||||
function flatsome_dummy_text(){
|
||||
$content = '<p><strong>This is a dummy text for demo purpose</strong>. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p><p> Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>';
|
||||
return apply_filters( 'flatsome_dummy_text', $content );
|
||||
}
|
187
wp-content/themes/flatsome/inc/helpers/helpers-grid.php
Normal file
187
wp-content/themes/flatsome/inc/helpers/helpers-grid.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
function flatsome_get_grid_height($height, $id){
|
||||
|
||||
$height_sm = null;
|
||||
$height_md = null;
|
||||
|
||||
if(is_array($height)){
|
||||
$height_md = intval($height[1]);
|
||||
$height_sm = intval($height[2]);
|
||||
$height = intval($height[0]);
|
||||
} else {
|
||||
$height_md = intval($height)/1.5;
|
||||
$height_sm = intval($height)/1.5;
|
||||
$height = intval($height);
|
||||
}
|
||||
?>
|
||||
<style>
|
||||
#<?php echo $id;?> .grid-col-1{height: <?php echo $height; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-2{height: <?php echo $height / 2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-3{height:<?php echo $height / 3; ?>px}
|
||||
#<?php echo $id;?> .grid-col-2-3{height: <?php echo $height / 3 *2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-4{height: <?php echo $height / 4; ?>px}
|
||||
#<?php echo $id;?> .grid-col-3-4{height: <?php echo $height / 4 *3; ?>px}
|
||||
|
||||
|
||||
<?php if($height_md) { ?>
|
||||
/* Tablet */
|
||||
@media (max-width: 850px){
|
||||
#<?php echo $id;?> .grid-col-1{height: <?php echo $height_md; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-2{height: <?php echo $height_md / 2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-3{height:<?php echo $height_md / 3; ?>px}
|
||||
#<?php echo $id;?> .grid-col-2-3{height: <?php echo $height_md / 3 *2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-4{height: <?php echo $height_md / 4; ?>px}
|
||||
#<?php echo $id;?> .grid-col-3-4{height: <?php echo $height_md / 4 *3; ?>px}
|
||||
}
|
||||
<?php } ?>
|
||||
|
||||
<?php if($height_sm) { ?>
|
||||
/* Mobile */
|
||||
@media (max-width: 550px){
|
||||
#<?php echo $id;?> .grid-col-1{height: <?php echo $height_sm; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-2{height: <?php echo $height_sm / 2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-3{height:<?php echo $height_sm / 3; ?>px}
|
||||
#<?php echo $id;?> .grid-col-2-3{height: <?php echo $height_sm / 3 *2; ?>px}
|
||||
#<?php echo $id;?> .grid-col-1-4{height: <?php echo $height_sm / 4; ?>px}
|
||||
#<?php echo $id;?> .grid-col-3-4{height: <?php echo $height_sm / 4 *3; ?>px}
|
||||
}
|
||||
<?php } ?>
|
||||
|
||||
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
if( ! function_exists( 'flatsome_get_grid' ) ) {
|
||||
function flatsome_get_grid($grid = 1){
|
||||
|
||||
$g = array();
|
||||
|
||||
if($grid == '1'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '6', 'size' => 'medium','md' => '12'),
|
||||
array('height' => '1','span' => '3', 'size' => 'medium','md' => '6'),
|
||||
array('height' => '1-2','span' => '3', 'size' => 'thumbnail','md' => '6'),
|
||||
array('height' => '1-2','span' => '3', 'size' => 'thumbnail','md' => '6'),
|
||||
);
|
||||
}
|
||||
if($grid == '2'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '12', 'size' => 'large','md' => '12'),
|
||||
array('height' => '1-3','span' => '4','size' => 'thumbnail','md' => '12'),
|
||||
array('height' => '1-3','span' => '4','size' => 'thumbnail','md' => '12'),
|
||||
array('height' => '1-3','span' => '4','size' => 'thumbnail','md' => '12'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '3'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '6','size' => 'large','md' => '12'),
|
||||
array('height' => '1-2','span' => '6','size' => 'medium','md' => '6'),
|
||||
array('height' => '1-2','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '4'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '3','size' => 'large','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '5'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '4','size' => 'large','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '6'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '9','size' => 'large','md' => '12'),
|
||||
array('height' => '1-2','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
array('height' => '1-2','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if($grid == '7'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '3','size' => 'medium', 'md' => '12'),
|
||||
array('height' => '1','span' => '6','size' => 'large','md' => '6'),
|
||||
array('height' => '1-2','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '8'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '3','size' => 'medium','md' => '12'),
|
||||
array('height' => '1','span' => '6','size' => 'large','md' => '6'),
|
||||
array('height' => '1','span' => '3','size' => 'medium','md' => '6'),
|
||||
array('height' => '1','span' => '3','size' => 'medium','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '9'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '6','size' => 'large','md' => '12'),
|
||||
array('height' => '1','span' => '3','size' => 'medium','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '10'){
|
||||
$g = array(
|
||||
array('height' => '1','span' => '6','size' => 'large','md' => '12'),
|
||||
array('height' => '1-3','span' => '6','size' => 'medium','md' => '6'),
|
||||
array('height' => '1-3','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
array('height' => '1-3','span' => '3','size' => 'thumbnail','md' => '6'),
|
||||
array('height' => '1-3','span' => '6','size' => 'medium','md' => '6'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '11'){
|
||||
$g = array(
|
||||
array('height' => '2-3','span' => '6','md' => '12','size' => 'large'),
|
||||
array('height' => '2-3','span' => '3','md' => '6','size' => 'medium'),
|
||||
array('height' => '1','span' => '3','md' => '6','size' => 'medium'),
|
||||
array('height' => '2-3','span' => '3','md' => '6','size' => 'medium'),
|
||||
array('height' => '1-3','span' => '6','md' => '12','size' => 'medium'),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '12'){
|
||||
$g = array(
|
||||
array('height' => '1-2','span' => '8','md' => '12','size' => 'large'),
|
||||
array('height' => '1','span' => '4','md' => '6','size' => 'large',),
|
||||
array('height' => '1','span' => '4','md' => '6','size' => 'large',),
|
||||
array('height' => '1-2','span' => '8','md' => '6','size' => 'large'),
|
||||
array('height' => '1-2','span' => '8','md' => '6','size' => 'large'),
|
||||
array('height' => '1','span' => '4','md' => '6','size' => 'large'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if($grid == '13'){
|
||||
$g = array(
|
||||
array('height' => '2-3','span' => '6','md' => '12','size' => 'large'),
|
||||
array('height' => '1-2','span' => '3','md' => '6','size' => 'thumbnail'),
|
||||
array('height' => '1','span' => '3','md' => '6','size' => 'medium'),
|
||||
array('height' => '1-2','span' => '3','md' => '6','size' => 'thumbnail'),
|
||||
array('height' => '1-3','span' => '6','md' => '12','size' => 'medium'),
|
||||
);
|
||||
}
|
||||
|
||||
if($grid == '14'){
|
||||
$g = array(
|
||||
array('height' => '1-2','span' => '8', 'md' => '12','size' => 'medium'),
|
||||
array('height' => '1','span' => '4', 'md' => '6','size' => 'medium'),
|
||||
array('height' => '1','span' => '4', 'md' => '6','size' => 'medium'),
|
||||
array('height' => '1','span' => '2','md' => '6','size' => 'medium'),
|
||||
array('height' => '1','span' => '2','md' => '6','size' => 'medium'),
|
||||
array('height' => '1-2','span' => '4','md' => '6','size' => 'medium'),
|
||||
);
|
||||
}
|
||||
|
||||
return $g;
|
||||
}
|
||||
}
|
31
wp-content/themes/flatsome/inc/helpers/helpers-icons.php
Normal file
31
wp-content/themes/flatsome/inc/helpers/helpers-icons.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
function get_flatsome_icon( $name, $size = null ) {
|
||||
if ( $size ) $size = 'style="font-size:' . $size . ';"';
|
||||
|
||||
return '<i class="' . $name . '" ' . $size . '></i>';
|
||||
}
|
||||
|
||||
function flatsome_add_icons_css() {
|
||||
$theme = wp_get_theme( get_template() );
|
||||
$version = $theme->get( 'Version' );
|
||||
$fonts_url = get_template_directory_uri() . '/assets/css/icons';
|
||||
|
||||
wp_add_inline_style(
|
||||
'flatsome-main',
|
||||
'@font-face {
|
||||
font-family: "fl-icons";
|
||||
font-display: block;
|
||||
src: url(' . $fonts_url . '/fl-icons.eot?v=' . $version . ');
|
||||
src:
|
||||
url(' . $fonts_url . '/fl-icons.eot#iefix?v=' . $version . ') format("embedded-opentype"),
|
||||
url(' . $fonts_url . '/fl-icons.woff2?v=' . $version . ') format("woff2"),
|
||||
url(' . $fonts_url . '/fl-icons.ttf?v=' . $version . ') format("truetype"),
|
||||
url(' . $fonts_url . '/fl-icons.woff?v=' . $version . ') format("woff"),
|
||||
url(' . $fonts_url . '/fl-icons.svg?v=' . $version . '#fl-icons) format("svg");
|
||||
}'
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_enqueue_scripts', 'flatsome_add_icons_css', 150 );
|
||||
|
548
wp-content/themes/flatsome/inc/helpers/helpers-shortcode.php
Normal file
548
wp-content/themes/flatsome/inc/helpers/helpers-shortcode.php
Normal file
@@ -0,0 +1,548 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generate position classes for banner content.
|
||||
*
|
||||
* @param string $axis
|
||||
* @param string $default
|
||||
* @param string $sm
|
||||
* @param string $md
|
||||
* @return string
|
||||
*/
|
||||
function flatsome_position_classes ( $axis, $default, $sm, $md ) {
|
||||
$classes = array();
|
||||
|
||||
if ( $md && ! strlen( $sm ) ) $sm = $md; // Small should inherit from medium if not set
|
||||
if ( ! strlen( $sm ) ) $sm = $default; // Inherit small from default value
|
||||
if ( ! strlen( $md ) ) $md = $default; // Inherit medium from default value
|
||||
|
||||
$classes[] = $axis . $sm;
|
||||
$classes[] = 'md-' . $axis . $md;
|
||||
$classes[] = 'lg-' . $axis . $default;
|
||||
|
||||
return implode( ' ', $classes );
|
||||
}
|
||||
|
||||
function get_flatsome_repeater_start( $atts ) {
|
||||
$atts = wp_parse_args( $atts, array(
|
||||
'class' => '',
|
||||
'visibility' => '',
|
||||
'title' => '',
|
||||
'style' => '',
|
||||
'columns' => '',
|
||||
'columns__sm' => '',
|
||||
'columns__md' => '',
|
||||
'slider_nav_position' => '',
|
||||
'slider_bullets' => 'false',
|
||||
'slider_nav_color' => '',
|
||||
'auto_slide' => 'false',
|
||||
'infinitive' => 'true',
|
||||
'format' => '',
|
||||
) );
|
||||
|
||||
$row_classes = array();
|
||||
$row_classes_full = array();
|
||||
|
||||
if ( $atts['class'] ) {
|
||||
$row_classes[] = $atts['class'];
|
||||
$row_classes_full[] = $atts['class'];
|
||||
}
|
||||
|
||||
if ( $atts['visibility'] ) {
|
||||
$row_classes[] = $atts['visibility'];
|
||||
$row_classes_full[] = $atts['visibility'];
|
||||
}
|
||||
|
||||
if($atts['type'] == 'slider-full'){
|
||||
$atts['columns'] = false;
|
||||
$atts['columns__sm'] = false;
|
||||
$atts['columns__md'] = false;
|
||||
}
|
||||
|
||||
if(empty($atts)) return;
|
||||
|
||||
if(!empty($atts['filter'])){
|
||||
$row_classes[] = 'row-isotope';
|
||||
}
|
||||
|
||||
$rtl = 'false';
|
||||
|
||||
if(is_rtl()) {
|
||||
$rtl = 'true';
|
||||
}
|
||||
|
||||
if(empty($atts['auto_slide'])) $atts['auto_slide'] = 'false';
|
||||
|
||||
// Group slider cells
|
||||
$group_cells = '"100%"';
|
||||
|
||||
// Add column classes
|
||||
if(!empty($atts['columns']) && $atts['type'] !== 'grid'){
|
||||
if($atts['columns']) $row_classes[] = 'large-columns-'.$atts['columns'];
|
||||
|
||||
if(empty($atts['columns__md']) && $atts['columns'] > 3) {$row_classes[] = 'medium-columns-3';}
|
||||
else{$row_classes[] = 'medium-columns-'.$atts['columns__md'];}
|
||||
|
||||
if(empty($atts['columns__sm']) && $atts['columns'] > 2) {$row_classes[] = 'small-columns-2';}
|
||||
else{$row_classes[] = 'small-columns-'.$atts['columns__sm'];}
|
||||
}
|
||||
|
||||
// Add Row spacing
|
||||
if(!empty($atts['row_spacing'])){
|
||||
$row_classes[] = 'row-'.$atts['row_spacing'];
|
||||
}
|
||||
|
||||
// Add row width
|
||||
if(!empty($atts['row_width'])){
|
||||
if($atts['row_width'] == 'full-width') $row_classes[] = 'row-full-width';
|
||||
}
|
||||
|
||||
// Add Shadows
|
||||
if(!empty($atts['depth'])){
|
||||
$row_classes[] = 'has-shadow';
|
||||
$row_classes_full[] = 'box-shadow-'.$atts['depth'];
|
||||
$row_classes[] = 'row-box-shadow-'.$atts['depth'];
|
||||
}
|
||||
if(!empty($atts['depth_hover'])){
|
||||
$row_classes[] = 'has-shadow';
|
||||
$row_classes_full[] = 'box-shadow-'.$atts['depth_hover'].'-hover';
|
||||
$row_classes[] = 'row-box-shadow-'.$atts['depth_hover'].'-hover';
|
||||
}
|
||||
|
||||
if($atts['type'] == 'masonry'){
|
||||
wp_enqueue_script('flatsome-masonry-js');
|
||||
$row_classes[] = 'row-masonry';
|
||||
}
|
||||
|
||||
if($atts['type'] == 'grid'){
|
||||
wp_enqueue_script('flatsome-masonry-js');
|
||||
$row_classes[] = 'row-grid';
|
||||
}
|
||||
|
||||
if($atts['type'] == 'slider'){
|
||||
$row_classes[] = 'slider row-slider';
|
||||
|
||||
if($atts['slider_style']) $row_classes[] = 'slider-nav-'.$atts['slider_style'];
|
||||
|
||||
if($atts['slider_nav_position']) $row_classes[] = 'slider-nav-'.$atts['slider_nav_position'];
|
||||
|
||||
if($atts['slider_nav_color']) $row_classes[] = 'slider-nav-'.$atts['slider_nav_color'];
|
||||
|
||||
// Add slider push class to normal text boxes
|
||||
if(!$atts['style'] || $atts['style'] == 'default' || $atts['style'] == 'normal' || $atts['style'] == 'bounce') $row_classes[] = 'slider-nav-push';
|
||||
|
||||
$slider_options = '{"imagesLoaded": true, "groupCells": '.$group_cells.', "dragThreshold" : 5, "cellAlign": "left","wrapAround": '.$atts['infinitive'].',"prevNextButtons": true,"percentPosition": true,"pageDots": '.$atts['slider_bullets'].', "rightToLeft": '.$rtl.', "autoPlay" : '.$atts['auto_slide'].'}';
|
||||
|
||||
} else if($atts['type'] == 'slider-full'){
|
||||
$row_classes_full[] = 'slider slider-auto-height row-collapse';
|
||||
|
||||
if($atts['slider_nav_position']) $row_classes_full[] = 'slider-nav-'.$atts['slider_nav_position'];
|
||||
|
||||
if($atts['slider_style']) $row_classes_full[] = 'slider-nav-'.$atts['slider_style'];
|
||||
|
||||
$slider_options = '{"imagesLoaded": true, "dragThreshold" : 5, "cellAlign": "left","wrapAround": '.$atts['infinitive'].',"prevNextButtons": true,"percentPosition": true,"pageDots": '.$atts['slider_bullets'].', "rightToLeft": '.$rtl.', "autoPlay" : '.$atts['auto_slide'].'}';
|
||||
}
|
||||
|
||||
$row_classes_full = array_unique( $row_classes_full );
|
||||
$row_classes = array_unique( $row_classes );
|
||||
|
||||
$row_classes_full = implode( ' ', $row_classes_full );
|
||||
$row_classes = implode( ' ', $row_classes );
|
||||
?>
|
||||
|
||||
<?php if($atts['title']){?>
|
||||
<div class="row">
|
||||
<div class="large-12 col">
|
||||
<h3 class="section-title"><span><?php echo $atts['title']; ?></span></h3>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if($atts['type'] == 'slider') { // Slider grid ?>
|
||||
<div class="row <?php echo $row_classes; ?>" data-flickity-options='<?php echo $slider_options; ?>'>
|
||||
|
||||
<?php } else if($atts['type'] == 'slider-full') { // Full slider ?>
|
||||
<div id="<?php echo $atts['id']; ?>" class="<?php echo $row_classes_full; ?>" data-flickity-options='<?php echo $slider_options; ?>'>
|
||||
|
||||
<?php } else if($atts['type'] == 'masonry') { // Masonry grid ?>
|
||||
<div id="<?php echo $atts['id']; ?>" class="row <?php echo $row_classes; ?>" data-packery-options='{"itemSelector": ".col", "gutter": 0, "presentageWidth" : true}'>
|
||||
|
||||
<?php } else if($atts['type'] == 'grid') { ?>
|
||||
<div id="<?php echo $atts['id']; ?>" class="row <?php echo $row_classes; ?>" data-packery-options='{"itemSelector": ".col", "gutter": 0, "presentageWidth" : true}'>
|
||||
|
||||
<?php } else if($atts['type'] == 'blank') { //Blank type ?>
|
||||
<div class="container">
|
||||
|
||||
<?php } else { // Normal Rows ?>
|
||||
<div class="row <?php echo $row_classes; ?>">
|
||||
<?php }
|
||||
}
|
||||
|
||||
function get_flatsome_repeater_end($type){
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/* Fix Normal Shortcodes */
|
||||
function flatsome_contentfix($content){
|
||||
if ( ! is_string( $content ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$fix = array (
|
||||
'<p>_____</p>' => '<div class="is-divider large"></div>',
|
||||
'<p>____</p>' => '<div class="is-divider medium"></div>',
|
||||
'<p>___</p>' => '<div class="is-divider small"></div>',
|
||||
'</div></p>' => '</div>',
|
||||
'<p><div' => '<div',
|
||||
']<br />' => ']',
|
||||
'<br />[' => '[',
|
||||
'<p>[' => '[',
|
||||
']</p>' => ']',
|
||||
|
||||
// For Gutenberg blocks that is encoded by UX Builder.
|
||||
'<!–' => '<!--',
|
||||
'–>' => '-->',
|
||||
);
|
||||
|
||||
return strtr( $content, $fix );
|
||||
}
|
||||
|
||||
add_filter( 'the_content', 'flatsome_contentfix' );
|
||||
add_filter( 'widget_text', 'flatsome_contentfix' );
|
||||
add_filter( 'widget_text', 'do_shortcode' );
|
||||
add_filter( 'the_excerpt', 'flatsome_contentfix' );
|
||||
add_filter( 'the_excerpt', 'do_shortcode' );
|
||||
|
||||
/**
|
||||
* Remove whitespace characters \r\n\t\f\v from HTML between > and <
|
||||
* (Prevents wpautop from adding <p> or <br>)
|
||||
*
|
||||
* @param $html
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function flatsome_sanitize_whitespace_chars( $html ) {
|
||||
$html = preg_replace( '/(?<=>)\s+(?=<)/', '', $html );
|
||||
return trim( $html );
|
||||
}
|
||||
|
||||
// Get Shortcode Inline CSS
|
||||
function get_shortcode_inline_css($args){
|
||||
$style = '';
|
||||
foreach ($args as $key => $value) {
|
||||
$unit = array_key_exists( 'unit', $value ) ? $value['unit'] : null;
|
||||
if($value['value']) $style .= $value['attribute'].':'.$value['value'].$unit.';';
|
||||
}
|
||||
if($style) return 'style="'.$style.'"';
|
||||
}
|
||||
|
||||
|
||||
// Get Parallax Options
|
||||
function get_parallax_option($strength){
|
||||
return 'data-velocity="0.'.$strength.'"';
|
||||
}
|
||||
|
||||
function flatsome_get_image_url($id, $size = 'large'){
|
||||
|
||||
if(!$id) return get_template_directory_uri().'/assets/img/missing.jpg';
|
||||
|
||||
if (!is_numeric($id)) {
|
||||
return $id;
|
||||
} else {
|
||||
$image = wp_get_attachment_image_src($id, $size);
|
||||
$image = $image ? $image[0] : '';
|
||||
return $image;
|
||||
}
|
||||
}
|
||||
|
||||
function flatsome_get_image($id, $size = 'large', $alt = 'bg_image', $inline = false){
|
||||
|
||||
if(!$id) return '<img src="'.get_template_directory_uri().'/assets/img/missing.jpg'.'" />';
|
||||
|
||||
if (!is_numeric($id)) {
|
||||
return '<img src="'.$id.'" alt="'.$alt.'" />';
|
||||
} else {
|
||||
$meta = get_post_mime_type($id);
|
||||
|
||||
if ( $meta == 'image/svg+xml' && $inline ){
|
||||
$file = get_attached_file( $id );
|
||||
if ( $file && file_exists( $file ) ) {
|
||||
return preg_replace(
|
||||
'#<script(.*?)>(.*?)</script>#is',
|
||||
'',
|
||||
file_get_contents( $file )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return wp_get_attachment_image( $id, $size );
|
||||
}
|
||||
}
|
||||
|
||||
function flatsome_string_limit_words($string, $word_limit) {
|
||||
$words = explode(' ', $string, ($word_limit + 1));
|
||||
if(count($words) > $word_limit)
|
||||
array_pop($words);
|
||||
return implode(' ', $words);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Create RGBA color of a #HEX color */
|
||||
function flatsome_hex2rgba($color, $opacity = false) {
|
||||
$default = 'rgb(0,0,0)';
|
||||
//Return default if no color provided
|
||||
if(empty($color))
|
||||
return $default;
|
||||
|
||||
//Sanitize $color if "#" is provided
|
||||
if ($color[0] == '#' ) {
|
||||
$color = substr( $color, 1 );
|
||||
}
|
||||
|
||||
//Check if color has 6 or 3 characters and get values
|
||||
if (strlen($color) == 6) {
|
||||
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
|
||||
} elseif ( strlen( $color ) == 3 ) {
|
||||
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
|
||||
//Convert hexadec to rgb
|
||||
$rgb = array_map('hexdec', $hex);
|
||||
|
||||
//Check if opacity is set(rgba or rgb)
|
||||
if($opacity){
|
||||
if(abs($opacity) > 1)
|
||||
$opacity = 1.0;
|
||||
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
|
||||
} else {
|
||||
$output = 'rgb('.implode(",",$rgb).')';
|
||||
}
|
||||
//Return rgb(a) color string
|
||||
return $output;
|
||||
}
|
||||
|
||||
function flatsome_fix_span($span){
|
||||
switch ($span) {
|
||||
case "1/1":
|
||||
$span = '12'; break;
|
||||
case "1/4":
|
||||
$span = '3'; break;
|
||||
case "2/4":
|
||||
$span ='6'; break;
|
||||
case "3/4":
|
||||
$span = '9'; break;
|
||||
case "1/3":
|
||||
$span = '4'; break;
|
||||
case "2/3":
|
||||
$span = '8'; break;
|
||||
case "1/2":
|
||||
$span = '6'; break;
|
||||
case "1/6":
|
||||
$span = '2'; break;
|
||||
case "2/6":
|
||||
$span = '4'; break;
|
||||
case "3/6":
|
||||
$span = '6'; break;
|
||||
case "4/6":
|
||||
$span = '8'; break;
|
||||
case "5/6":
|
||||
$span = '10'; break;
|
||||
case "1/12":
|
||||
$span = '1'; break;
|
||||
case "2/12":
|
||||
$span = '2'; break;
|
||||
case "3/12":
|
||||
$span = '3'; break;
|
||||
case "4/12":
|
||||
$span = '4'; break;
|
||||
case "5/12":
|
||||
$span = '5'; break;
|
||||
case "6/12":
|
||||
$span = '6'; break;
|
||||
case "7/12":
|
||||
$span = '7'; break;
|
||||
case "8/12":
|
||||
$span = '8'; break;
|
||||
case "9/12":
|
||||
$span = '9'; break;
|
||||
case "10/12":
|
||||
$span = '10'; break;
|
||||
case "11/12":
|
||||
$span = '11'; break;
|
||||
}
|
||||
return $span;
|
||||
}
|
||||
|
||||
|
||||
function flatsome_smart_links($link){
|
||||
if($link == 'shop' && is_woocommerce_activated()){
|
||||
$link = get_permalink( wc_get_page_id( 'shop' ) );
|
||||
}
|
||||
else if($link == 'cart' && is_woocommerce_activated()) {
|
||||
$link = wc_get_cart_url();
|
||||
}
|
||||
else if($link == 'checkout' && is_woocommerce_activated()) {
|
||||
$link = wc_get_checkout_url();
|
||||
}
|
||||
else if($link == 'account' && is_woocommerce_activated()){
|
||||
$link = get_permalink( get_option('woocommerce_myaccount_page_id') );
|
||||
}
|
||||
|
||||
else if($link == 'home'){
|
||||
$link = get_home_url();
|
||||
}
|
||||
|
||||
else if($link == 'blog'){
|
||||
$link = get_permalink( get_option( 'page_for_posts' ) );
|
||||
}
|
||||
|
||||
else if($link == 'wishlist' && class_exists('YITH_WCWL')){
|
||||
$link = YITH_WCWL()->get_wishlist_url();
|
||||
}
|
||||
// Get link by page title
|
||||
else if(strpos($link, '/') === false && !is_numeric($link)){
|
||||
$get_page = get_page_by_title($link);
|
||||
if( $get_page ) $link = get_permalink($get_page->ID);
|
||||
}
|
||||
|
||||
$protocols = wp_allowed_protocols();
|
||||
array_push( $protocols, 'sms' );
|
||||
|
||||
return esc_url( $link, $protocols );
|
||||
}
|
||||
|
||||
function flatsome_to_dashed($className) {
|
||||
return strtolower(preg_replace('/([\S\s])\s/', '$1-', $className));
|
||||
}
|
||||
|
||||
/*
|
||||
function flatsome_get_gradient($primary){ ?>
|
||||
<style>
|
||||
.target{
|
||||
background: <?php echo $primary; ?>
|
||||
background: -moz-linear-gradient(<?php echo $direction; ?>, <?php echo $primary; ?> 0%, <?php echo $secondary; ?> 100%);
|
||||
background: -webkit-linear-gradient(<?php echo $direction; ?>, <?php echo $primary; ?> 0%, <?php echo $secondary; ?> 100%);
|
||||
background: linear-gradient(<?php echo $direction; ?>, <?php echo $primary; ?> 0%, <?php echo $secondary; ?> 100%);
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
} */
|
||||
|
||||
/**
|
||||
* Parse rel attribute values based on target value.
|
||||
* Adds 'noopener noreferrer' to rel when target is _blank.
|
||||
*
|
||||
* @param array $link_atts Link attributes 'target' and 'rel'.
|
||||
* @param bool $trim Trim start and end whitespaces?
|
||||
*
|
||||
* @return string Parsed target/rel string.
|
||||
*/
|
||||
function flatsome_parse_target_rel( array $link_atts, $trim = false ) {
|
||||
$attrs = array();
|
||||
|
||||
if ( $link_atts['target'] == '_blank' ) {
|
||||
$attrs[] = "target=\"{$link_atts['target']}\"";
|
||||
$link_atts['rel'][] = 'noopener';
|
||||
$link_atts['rel'][] = 'noreferrer';
|
||||
}
|
||||
|
||||
if ( isset( $link_atts['rel'] ) && is_array( $link_atts['rel'] ) && ! empty( array_filter( $link_atts['rel'] ) ) ) {
|
||||
$relations = array_unique( array_filter( $link_atts['rel'] ) );
|
||||
$rel = implode( ' ', $relations );
|
||||
$attrs[] = "rel=\"{$rel}\"";
|
||||
}
|
||||
|
||||
$attrs = ' ' . implode( ' ', $attrs ) . ' ';
|
||||
|
||||
return $trim ? trim( $attrs ) : $attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collection of ux_products shortcode box item hooks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function flatsome_ux_product_box_items() {
|
||||
|
||||
return array(
|
||||
'cat' => array(
|
||||
'tag' => 'woocommerce_shop_loop_item_title',
|
||||
'function' => 'flatsome_woocommerce_shop_loop_category',
|
||||
),
|
||||
'title' => array(
|
||||
'tag' => 'woocommerce_shop_loop_item_title',
|
||||
'function' => 'woocommerce_template_loop_product_title',
|
||||
),
|
||||
'rating' => array(
|
||||
'tag' => 'woocommerce_after_shop_loop_item_title',
|
||||
'function' => 'woocommerce_template_loop_rating',
|
||||
),
|
||||
'price' => array(
|
||||
'tag' => 'woocommerce_after_shop_loop_item_title',
|
||||
'function' => 'woocommerce_template_loop_price',
|
||||
),
|
||||
'add_to_cart' => array(
|
||||
'tag' => 'flatsome_product_box_after',
|
||||
'function' => 'flatsome_woocommerce_shop_loop_button',
|
||||
),
|
||||
'add_to_cart_icon' => array(
|
||||
'tag' => 'flatsome_product_box_actions',
|
||||
'function' => 'flatsome_product_box_actions_add_to_cart',
|
||||
),
|
||||
'quick_view' => array(
|
||||
'tag' => 'flatsome_product_box_actions',
|
||||
'function' => 'flatsome_lightbox_button',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the toggle of box item hooks.
|
||||
*
|
||||
* @param array $items A collection of box items of a specific element.
|
||||
*
|
||||
* @return array $items Box items with additional data.
|
||||
*/
|
||||
function flatsome_box_item_toggle_start( $items ) {
|
||||
|
||||
foreach ( $items as $key => $data ) {
|
||||
if ( isset( $data['show'] ) && ! $data['show'] ) {
|
||||
$priority = has_action( $data['tag'], $data['function'] );
|
||||
if ( $priority !== false ) {
|
||||
remove_action( $data['tag'], $data['function'], $priority );
|
||||
$items[ $key ]['priority'] = $priority;
|
||||
$items[ $key ]['re_hook'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the toggle of box item hooks.
|
||||
*
|
||||
* @param array $items A collection of box items of a specific element.
|
||||
*/
|
||||
function flatsome_box_item_toggle_end( $items ) {
|
||||
foreach ( $items as $item ) {
|
||||
if ( isset( $item['re_hook'] ) && $item['re_hook'] == true ) {
|
||||
add_action( $item['tag'], $item['function'], $item['priority'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts items at offset in an associative array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $values
|
||||
* @param int $offset
|
||||
* @return array
|
||||
*/
|
||||
function flatsome_array_insert( array $array, array $values, $offset ) {
|
||||
return array_slice( $array, 0, $offset, true ) + $values + array_slice( $array, $offset, null, true );
|
||||
}
|
146
wp-content/themes/flatsome/inc/helpers/helpers-woocommerce.php
Normal file
146
wp-content/themes/flatsome/inc/helpers/helpers-woocommerce.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Get category product block.
|
||||
*
|
||||
* @param WC_Product $product Product.
|
||||
*
|
||||
* @return int|false Block ID or false if none assigned.
|
||||
*/
|
||||
function flatsome_get_cat_product_block( $product ) {
|
||||
|
||||
// Primary based.
|
||||
$primary_term_id = apply_filters( 'flatsome_product_block_primary_term_id', false, $product );
|
||||
|
||||
if ( $primary_term_id ) {
|
||||
$cat_meta = get_term_meta( $primary_term_id, 'cat_meta' );
|
||||
if ( ! empty( $cat_meta ) && ! empty( $cat_meta[0]['cat_product_block'] ) ) {
|
||||
return $cat_meta[0]['cat_product_block'];
|
||||
}
|
||||
}
|
||||
|
||||
// Regular.
|
||||
$terms = wc_get_product_terms( $product->get_Id(), 'product_cat', apply_filters(
|
||||
'flatsome_product_block_product_terms_args',
|
||||
array(
|
||||
'orderby' => 'parent',
|
||||
'order' => 'DESC',
|
||||
)
|
||||
) );
|
||||
|
||||
if ( $terms ) {
|
||||
foreach ( $terms as $term ) {
|
||||
$cat_meta = get_term_meta( $term->term_id, 'cat_meta' );
|
||||
if ( ! empty( $cat_meta ) && ! empty( $cat_meta[0]['cat_product_block'] ) ) {
|
||||
return $cat_meta[0]['cat_product_block'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single product block.
|
||||
*
|
||||
* @param WC_Product $product Product.
|
||||
*
|
||||
* @return int|false Block ID or false if none assigned.
|
||||
*/
|
||||
function flatsome_get_single_product_block( $product ) {
|
||||
global $wc_cpdf;
|
||||
|
||||
$block = $wc_cpdf->get_value( $product->get_Id(), '_product_block' );
|
||||
|
||||
return $block ? $block : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves product block data if one is assigned in any scope per priority.
|
||||
*
|
||||
* @param string|int $product_id Product ID.
|
||||
*
|
||||
* @return array|false Block data or false if none assigned.
|
||||
*/
|
||||
function flatsome_product_block( $product_id ) {
|
||||
|
||||
static $cache;
|
||||
if ( ! is_array( $cache ) ) $cache = array();
|
||||
if ( array_key_exists( $product_id, $cache ) ) {
|
||||
return $cache[ $product_id ];
|
||||
}
|
||||
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( ! is_a( $product, 'WC_Product' ) ) {
|
||||
$cache[ $product_id ] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Start collecting.
|
||||
$block = false;
|
||||
$scope = '';
|
||||
|
||||
if ( 'custom' === get_theme_mod( 'product_layout' ) && get_theme_mod( 'product_custom_layout' ) ) {
|
||||
$block = get_theme_mod( 'product_custom_layout' );
|
||||
$scope = 'global';
|
||||
}
|
||||
|
||||
if ( $cat = flatsome_get_cat_product_block( $product ) ) {
|
||||
$block = $cat;
|
||||
$scope = 'category';
|
||||
}
|
||||
|
||||
if ( $single = flatsome_get_single_product_block( $product ) ) {
|
||||
$block = $single;
|
||||
$scope = 'single';
|
||||
}
|
||||
|
||||
$filtered = apply_filters( 'flatsome_product_block', $block, $product );
|
||||
|
||||
if ( $filtered != $block ) {
|
||||
$scope = 'filter';
|
||||
}
|
||||
|
||||
$block_data = $filtered
|
||||
? array(
|
||||
'id' => flatsome_get_block_id( $filtered ),
|
||||
'scope' => $scope,
|
||||
)
|
||||
: false;
|
||||
|
||||
$cache[ $product_id ] = $block_data;
|
||||
|
||||
return $block_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of attribute taxonomies.
|
||||
*
|
||||
* @param array|string $args Optional. Array or string of arguments.
|
||||
*
|
||||
* @return array|false List of attributes taxonomies matching defaults or `$args`.
|
||||
*/
|
||||
function flatsome_get_product_attribute_taxonomies_list_by_id( $args = '' ) {
|
||||
$defaults = array(
|
||||
'option_none' => '',
|
||||
);
|
||||
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
|
||||
$attributes = array();
|
||||
|
||||
if ( $parsed_args['option_none'] ) {
|
||||
$attributes = array( '' => $parsed_args['option_none'] );
|
||||
}
|
||||
|
||||
$taxonomies = wc_get_attribute_taxonomies();
|
||||
|
||||
if ( $taxonomies ) {
|
||||
foreach ( wc_get_attribute_taxonomies() as $attribute ) {
|
||||
$attributes[ $attribute->attribute_id ] = $attribute->attribute_label;
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
Reference in New Issue
Block a user