true, 'simple-view' => false, 'hover-effects' => true, 'pre-completed' => true, 'column-visual' => true, 'mfn-modern-nav' => false, ]; $options = get_site_option( 'betheme_builder_'. $user_id ); if( ! is_array( $options ) ){ $options = []; } $options = array_merge( $defaults, $options ); return $options; } /** * All Fonts of BeBuilder * Get all BeBuilder related fonts */ public static function get_bebuilder_fonts(){ $items = get_posts( array( 'post_type' => array('page', 'post', 'portfolio', 'product', 'template'), 'post_status' => 'publish', 'posts_per_page' => -1, ) ); $fonts = []; if(count($items) > 0){ foreach($items as $item){ $remove_signs = function($value) { $value = preg_replace("/[^A-Za-z0-9 ]/", '', $value); return $value; }; if ( $response = get_post_meta($item->ID, 'mfn-page-fonts', true) ){ $response = explode(',', $response); // post meta returns it as a string $fonts = array_merge($fonts, array_map($remove_signs, $response)); } } } return array_unique($fonts); } /** * Unique ID * Generate unique ID and check for collisions */ public static function unique_ID($uids = array()){ if (function_exists('openssl_random_pseudo_bytes')) { // openssl_random_pseudo_bytes $uid = substr(bin2hex(openssl_random_pseudo_bytes(5)), 0, 9); } else { // fallback $keyspace = '0123456789abcdefghijklmnopqrstuvwxyz'; $keyspace_length = 36; $uid = ''; for ($i = 0; $i < 9; $i++) { $uid .= $keyspace[rand(0, $keyspace_length - 1)]; } } if( in_array( $uid, $uids ) ){ return self::unique_ID($uids); } return $uid; } /** * Set new uniqueID for all builder sections, wrap and items * This function also checks for possible collisions */ public static function unique_ID_reset($data, $uids = []){ if (! is_array($data)) { return false; } foreach($data as $section_k => $section){ $uids[] = self::unique_ID($uids); $data[$section_k]['uid'] = end($uids); if(isset($section['wraps']) && is_array($section['wraps'])){ foreach($section['wraps'] as $wrap_k => $wrap){ if( !is_array($data[$section_k]['wraps'][$wrap_k]) ){ continue; } $uids[] = self::unique_ID($uids); $data[$section_k]['wraps'][$wrap_k]['uid'] = end($uids); if(isset($wrap['items']) && is_array($wrap['items'])){ foreach($wrap['items'] as $item_k => $item){ if( !is_array( $data[$section_k]['wraps'][$wrap_k]['items'][$item_k] ) ){ continue; } $uids[] = self::unique_ID($uids); $data[$section_k]['wraps'][$wrap_k]['items'][$item_k]['uid'] = end($uids); if( !empty($item['item_is_wrap']) ){ if(isset($item['items']) && is_array($item['items'])){ foreach($item['items'] as $ni => $nested_item){ if( !is_array( $data[$section_k]['wraps'][$wrap_k]['items'][$item_k]['items'][$ni] ) ){ continue; } $uids[] = self::unique_ID($uids); $data[$section_k]['wraps'][$wrap_k]['items'][$item_k]['items'][$ni]['uid'] = end($uids); } } } } } } } } return $data; } /** * GET current builder uniqueIDs form $_POST */ public static function get_current_uids(){ $uids_section = isset( $_POST['mfn-section-id'] ) ? $_POST['mfn-section-id'] : array(); $uids_wrap = isset( $_POST['mfn-wrap-id'] ) ? $_POST['mfn-wrap-id'] : array(); $uids_item = isset( $_POST['mfn-item-id'] ) ? $_POST['mfn-item-id'] : array(); return array_merge( $uids_section, $uids_wrap, $uids_item ); } /** * GET Sliders * Layer Slider * Revolution Slider */ public static function get_sliders( $plugin = 'rev' ){ global $wpdb; $sliders = array( 0 => esc_html__('-- Select --', 'mfn-opts') ); if( 'layer' == $plugin ){ // layer slider if (function_exists('layerslider')) { $table_prefix = mfn_opts_get('table_prefix', 'base_prefix'); if ($table_prefix == 'base_prefix') { $table_prefix = $wpdb->base_prefix; } else { $table_prefix = $wpdb->prefix; } $table_name = $table_prefix . "layerslider"; $array = $wpdb->get_results($wpdb->prepare("SELECT `id`, `name` FROM `$table_name` WHERE `flag_hidden` = %d AND `flag_deleted` = %d ORDER BY `name` ASC", 0, 0)); if (is_array($array)) { foreach ($array as $v) { $sliders[$v->id] = $v->name; } } } } else { // revolution slider if ( method_exists('RevSlider','get_sliders') ) { $slider = new RevSlider(); $objSliders = $slider->get_sliders(); foreach( $objSliders as $slider ) { $sliders[$slider->alias] = $slider->title; } /*if ( 'base_prefix' == mfn_opts_get('table_prefix', 'base_prefix') ) { $table_prefix = $wpdb->base_prefix; } else { $table_prefix = $wpdb->prefix; } $table_name = $table_prefix . "revslider_sliders"; $array = $wpdb->get_results($wpdb->prepare("SELECT `alias`, `title` FROM `$table_name` WHERE `type` != %s ORDER BY `title` ASC", 'template')); if (is_array($array)) { foreach ($array as $v) { $sliders[$v->alias] = $v->title; } }*/ } } return $sliders; } /** * Get all revisions for the post */ public static function get_revisions( $post_id ){ $array = [ 'autosave' => [], 'update' => [], 'revision' => [], 'backup' => [], ]; // $types = ['autosave', 'update', 'revision', 'backup']; $date_format = get_option( 'date_format' ); $time_format = get_option( 'time_format' ); foreach( $array as $type => $value ){ $meta_key = $meta_key = 'mfn-builder-revision-'. $type; $revisions = get_post_meta( $post_id, $meta_key, true ); if( is_array( $revisions ) ){ foreach( $revisions as $rev_key => $rev_val ){ $array[$type][$rev_key] = date( $date_format .' '. $time_format , $rev_key ); } } } return $array; } /** * Allowed HTML for wp_kses in builder preview */ public static function allowed_html(){ $allowed = [ 'a' => [ 'href' => [], ], 'b' => [], 'blockquote' => [], 'br' => [], 'em' => [], 'h1' => [], 'h2' => [], 'h3' => [], 'h4' => [], 'h5' => [], 'h6' => [], 'i' => [ 'class' => [], ], 'img' => [ 'src' => [], ], 'li' => [], 'ol' => [], 'p' => [], 'span' => [], 'strong' => [], 'u' => [], 'ul' => [], 'table' => [], 'tr' => [], 'th' => [ 'colspan' => [], ], 'td' => [ 'colspan' => [], ], ]; return $allowed; } /** * Fiter for: GET builder items */ public static function filter_builder_get($builder){ // FIX | Muffin builder 2 compatibility if( ( ! $builder ) || is_array($builder) ){ return $builder; } return unserialize(call_user_func('base'.'64_decode', $builder), ['allowed_classes' => false]); } /** * Live Builder * Header tools for sections */ public static function sectionTools($section = false){ $html = '
Wrap Divider'; $html .= '
'; return $html; } /** * Live Builder * Header tools for wraps */ public static function wrapTools($wrap = false){ $html = 'Add element
'; if($wrap['size'] != 'divider'){ $html .= ' '.(!empty($wrap['attr']['style:.mcb-section .mcb-wrap-mfnuidelement:flex']) ? $wrap['attr']['style:.mcb-section .mcb-wrap-mfnuidelement:flex'] : $wrap['size']).' '; } $html .= '
Add
'; $html .= ''; $html .= ''; if($wrap['size'] != 'divider'){ $html .= ''; } $html .= '
'; return $html; } /** * Live Builder * Header tools for items */ public static function itemTools($size){ $html = '
'.$size.'
'; return $html; } /** * GET Shape dividers * @param primary_key special values: * 'options' - get single dimensional array with key, value * 'invert' - get coma separated list of invert dividers (for conditions) */ public static function get_shape_divider( $primary_key = false, $secondary_key = false, $uid = false ){ if( ! $uid ){ $uid = 'mfn-uid-'.rand(0, 999).'-'.rand(0, 999); } // NOTICE: keys MUST contain _NUMBER $shape_dividers = [ 'arc_opacity_1' => [ 'title' => __('Arc Opacity','mfn-opts'), 'viewbox' => '0 0 1000 100', 'svg' => '', ], 'arc_opacity_2' => [ 'title' => __('Arc Opacity 2','mfn-opts'), 'viewbox' => '0 0 1000 100', 'svg' => '', ], 'arrow_1' => [ 'title' => __('Arrow','mfn-opts'), 'svg' => '', 'invert' => '', ], 'blobs_1' => [ 'title' => __('Blobs','mfn-opts'), 'viewbox' => '0 0 1000 78', 'svg' => '', ], 'blobs_2' => [ 'title' => __('Blobs 2','mfn-opts'), 'viewbox' => '0 0 1000 78', 'svg' => '', ], 'book_1' => [ 'title' => __('Book','mfn-opts'), 'svg' => '', 'invert' => '', ], 'christmas_trees_1' => [ 'title' => __('Christmas Trees','mfn-opts'), 'viewbox' => '0 0 500 95.32', 'svg' => '', ], 'clouds_1' => [ 'title' => __('Clouds','mfn-opts'), 'viewbox' => '0 0 500.01 95.43', 'svg' => '', ], 'clouds_2' => [ 'title' => __('Clouds 2','mfn-opts'), 'viewbox' => '0 0 500.01 129', 'svg' => '', ], 'curve_1' => [ 'title' => __('Curve','mfn-opts'), 'svg' => '', 'invert' => '', ], 'curve_corner_opacity_1' => [ 'title' => __('Curve Corner Opacity','mfn-opts'), 'viewbox' => '0 0 35.278 3.62', 'svg' => '', ], 'curve_asymmetrical_1' => [ 'title' => __('Curve Asymmetrical','mfn-opts'), 'svg' => '', 'invert' => '', ], 'crazy_waves_1' => [ 'title' => __('Crazy Waves','mfn-opts'), 'viewbox' => '0 0 1000 84.2', 'svg' => '', ], 'gradient_opacity_1' => [ 'title' => __('Gradient Opacity','mfn-opts'), 'viewbox' => '0 0 400 60', 'svg' => '', ], 'hexagons_opacity_1' => [ 'title' => __('Hexagons Opacity','mfn-opts'), 'viewbox' => '0 0 750 77', 'svg' => '', ], 'hills_1' => [ 'title' => __('Hills','mfn-opts'), 'viewbox' => '0 0 1143.58 27.83', 'svg' => '', ], 'hills_opacity_1' => [ 'title' => __('Hills Opacity','mfn-opts'), 'viewbox' => '0 0 78 7', 'svg' => '', ], 'mountains_1' => [ 'title' => __('Mountains','mfn-opts'), 'viewbox' => '0 0 1000 100', 'svg' => '', ], 'mountains_2' => [ 'title' => __('Mountains 2','mfn-opts'), 'viewbox' => '0 0.1 35.33 3.38', 'svg' => '', ], 'spikes_opacity_1' => [ 'title' => __('Spikes Opacity','mfn-opts'), 'viewbox' => '0 0 2003.4 89.5', 'svg' => '', ], 'split_1' => [ 'title' => __('Split','mfn-opts'), 'svg' => '', 'invert' => '', ], 'tilt_opacity_1' => [ 'title' => __('Tilt Opacity','mfn-opts'), 'viewbox' => '0 0 381 77.25', 'svg' => '', ], 'tilt_opacity_2' => [ 'title' => __('Tilt Opacity 2','mfn-opts'), 'viewbox' => '0 0 381 59.27', 'svg' => '', ], 'triangle_1' => [ 'title' => __('Triangle','mfn-opts'), 'svg' => '', 'invert' => '', ], 'triangle_asymmetrical_1' => [ 'title' => __('Triangle Asymmetrical','mfn-opts'), 'svg' => '', 'invert' => '', ], 'tilt' => [ 'title' => __('Tilt','mfn-opts'), 'svg' => '', ], 'waves_1' => [ 'title' => __('Waves','mfn-opts'), 'svg' => '', 'invert' => '', ], 'waves_opacity_1' => [ 'title' => __('Waves Opacity','mfn-opts'), 'svg' => ' ', ], 'waves_opacity_2' => [ 'title' => __('Waves Opacity 2','mfn-opts'), 'viewbox' => '0 0 35.28 2.17', 'svg' => '', ], 'waves_opacity_3' => [ 'title' => __('Waves Opacity 3','mfn-opts'), 'viewbox' => '0 0 2000.4 78.7', 'svg' => '', ], 'waves_opacity_4' => [ 'title' => __('Waves Opacity 4','mfn-opts'), 'viewbox' => '0 0 381 76.2', 'svg' => '', ], ]; // get single dimensional array with key, value if( 'options' == $primary_key ){ $array = [ '' => __('None','mfn-opts'), ]; foreach( $shape_dividers as $key => $value ){ $array[$key] = $value['title']; } return $array; } // get coma separated list of invert dividers (for conditions) if( 'invert' == $primary_key ){ $array = []; foreach( $shape_dividers as $key => $value ){ if( !empty( $value['invert'] ) ){ $array[] = $key; } } $string = implode(',',$array); return $string; } if( $primary_key ){ if( $secondary_key ){ if( !empty($shape_dividers[$primary_key][$secondary_key]) ){ return $shape_dividers[$primary_key][$secondary_key]; } } else { return $shape_dividers[$primary_key]; } return false; } return $shape_dividers; } /** * GET Shape divider html */ public static function shapedDivider( $name = false, $position = false, $is_inverted = false, $is_flipped = false, $bring_front = false ){ $viewbox = '0 0 1200 120'; if( 'empty' == $name ){ $html = '
'; $html .= ''; $html .= '
'; return $html; } // viewbox if( self::get_shape_divider( $name, 'viewbox' ) ){ $viewbox = self::get_shape_divider( $name, 'viewbox' ); } // invert $key = 'svg'; if( $is_inverted && self::get_shape_divider( $name, 'invert' ) ){ $key = 'invert'; } else { $is_inverted = 0; } $html = '
'; $html .= ''; $html .= self::get_shape_divider( $name, $key ); $html .= ''; $html .= '
'; return $html; } }