/** * insert layer */ public function insert_layer($layer, $demo = false, $masonry = false) { $base = new Essential_Grid_Base(); $m = new Essential_Grid_Meta(); $is_post = !empty($this->layer_values) ? false : true; if ($demo === false) { $post = $this->post; $layer_values = $this->layer_values; } else { $post['ID'] = '0'; //set default if we are in demo mode } //check advanced rules $show = $this->check_advanced_rules($layer, $post); if ($show === false) { return false; } $position = $base->getVar($layer, 'container', 'tl'); $class = 'top'; switch ($position) { case 'tl': $class = 'top'; break; case 'br': $class = 'bottom'; break; case 'c': $class = 'center'; break; case 'm': $class = 'content'; break; } if (!isset($layer['settings'])) { return false; } $this->register_layer_css($layer, $demo); $unique_class = 'eg-' . esc_attr($this->handle) . '-element-' . $layer['id']; $special_item = $base->getVar($layer['settings'], 'special', 'false'); $special_item_type = $base->getVar($layer['settings'], 'special-type', 'line-break'); /*if($special_item != 'true'){ $this->add_element_css($layer['settings'], $unique_class); //add css to queue }*/ //check if absolute positioned, remove class depending on it $absolute = $this->is_absolute_position($unique_class); if ($absolute) { $class = 'absolute'; } $hideunderHTML = ''; $hideunderClass = ''; $hideunder = $base->getVar($layer['settings'], 'hideunder', 0, 'i'); $hideunderheight = $base->getVar($layer['settings'], 'hideunderheight', 0, 'i'); $hideundertype = $base->getVar($layer['settings'], 'hidetype', 'visibility'); if ($hideunder > 0) { $hideunderHTML .= ' data-hideunder="' . $hideunder . '"'; $hideunderClass = 'eg-handlehideunder '; } if ($hideunderheight > 0) { $hideunderHTML .= ' data-hideunderheight="' . $hideunderheight . '"'; $hideunderClass = 'eg-handlehideunder '; } if ($hideunderHTML !== '') { $hideunderHTML .= ' data-hidetype="' . $hideundertype . '"'; } $delay = ''; $transition_split = ''; if ($masonry) { $transition = ''; //$transition_split = ''; } else { $transition = ' esg-' . $base->getVar($layer['settings'], 'transition', 'fade') . $base->getVar($layer['settings'], 'transition-type', ''); //$transition_split = ' data-split="'.$base->getVar($layer['settings'], 'split', 'line').'"'; $meta_tran = $this->get_meta_element_change($layer['id'], 'transition'); //check if we have meta transition set if ($meta_tran !== false) { $transition = ' esg-' . $meta_tran; } if ($transition == ' esg-none' || $transition == ' esg-noneout' || $base->getVar($layer['settings'], 'transition-type', '') == 'always') { //no transition $transition = ''; //$transition_split = ''; } else { $delay = ' data-delay="' . round($base->getVar($layer['settings'], 'delay', 0) / 100, 2) . '"'; $meta_tran_delay = $this->get_meta_element_change($layer['id'], 'transition-delay'); //check if we have meta transition-delay set if ($meta_tran_delay !== false) { $delay = ' data-delay="' . round($meta_tran_delay / 100, 2) . '"'; } } } $text = ''; $do_limit = true; $do_display = true; $do_full = false; $do_ignore_styles = false; $is_woo_cats = false; $is_woo_button = false; $is_html_source = false; $is_filter_cat = false; $demo_element_type = ' data-custom-type="%s"'; if (isset($layer['settings']['source'])) { $separator = $base->getVar($layer['settings'], 'source-separate', ','); $meta = $base->getVar($layer['settings'], 'source-meta', ''); $func = $base->getVar($layer['settings'], 'source-function', 'link'); switch ($layer['settings']['source']) { case 'post': if ($demo === false) { if ($is_post) { $text = $this->get_post_value($layer['settings']['source-post'], $separator, $func, $meta); } else { $text = $this->get_custom_element_value($layer['settings']['source-post'], $separator, $meta); } if ($func == 'filter') { $is_filter_cat = true; } } elseif ($demo === 'custom') { $text = $this->get_custom_element_value($layer['settings']['source-post'], $separator, $meta); } else { $post_text = Essential_Grid_Item_Element::getPostElementsArray(); if (array_key_exists(@$layer['settings']['source-post'], $post_text)) { $text = $post_text[@$layer['settings']['source-post']]['name']; } if ($layer['settings']['source-post'] == 'date') { $da = get_option('date_format'); if ($da !== false) { $text = date(get_option('date_format')); } else { $text = date('Y.m.d'); } } } $demo_element_type = str_replace('%s', $layer['settings']['source-post'], $demo_element_type); if ($layer['settings']['source-post'] == 'cat_list' || $layer['settings']['source-post'] == 'tag_list') { //no limiting if category or tag list $do_limit = false; $do_display = false; $do_full = true; } break; case 'event': if ($demo === false) { } else { $event = Essential_Grid_Item_Element::getEventElementsArray(); if (array_key_exists(@$layer['settings']['source-event'], $event)) { $text = $event[@$layer['settings']['source-event']]['name']; } } $demo_element_type = str_replace('%s', $layer['settings']['source-event'], $demo_element_type); break; case 'woocommerce': //check if woocommerce is installed if ($demo === false) { if (Essential_Grid_Woocommerce::is_woo_exists()) { if ($is_post) { $text = $this->get_woocommerce_value($layer['settings']['source-woocommerce'], $separator); } else { $text = $this->get_custom_element_value($layer['settings']['source-woocommerce'], $separator, ''); } if ($layer['settings']['source-woocommerce'] == 'wc_categories') { $do_limit = false; $do_display = false; $do_full = true; $is_woo_cats = true; } elseif ($layer['settings']['source-woocommerce'] == 'wc_add_to_cart_button') { $do_limit = false; $is_woo_button = true; } } } elseif ($demo === 'custom') { if (Essential_Grid_Woocommerce::is_woo_exists()) { $text = $this->get_custom_element_value($layer['settings']['source-woocommerce'], $separator, ''); if ($layer['settings']['source-woocommerce'] == 'wc_categories') { $do_limit = false; $do_display = false; $do_full = true; $is_woo_cats = true; } elseif ($layer['settings']['source-woocommerce'] == 'wc_add_to_cart_button') { $do_limit = false; $is_woo_button = true; } } } else { if (Essential_Grid_Woocommerce::is_woo_exists()) { $tmp_wc = Essential_Grid_Woocommerce::get_meta_array(); foreach ($tmp_wc as $handle => $name) { $woocommerce[$handle]['name'] = $name; } if (array_key_exists(@$layer['settings']['source-woocommerce'], $woocommerce)) { $text = $woocommerce[@$layer['settings']['source-woocommerce']]['name']; } } } $demo_element_type = str_replace('%s', $layer['settings']['source-woocommerce'], $demo_element_type); break; case 'icon': $text = '<i class="' . @$layer['settings']['source-icon'] . '"></i>'; $demo_element_type = ''; break; case 'text': $text = @$layer['settings']['source-text']; if ($demo === false) { //check for metas by %meta% if ($is_post) { $text = $m->replace_all_meta_in_text($this->post['ID'], $text); } else { $text = $m->replace_all_custom_element_meta_in_text($this->layer_values, $text); } } if (@$layer['settings']['source-text-style-disable']) { $do_ignore_styles = true; } $do_display = false; $demo_element_type = ''; $is_html_source = true; break; default: $demo_element_type = ''; } if ($do_limit) { $limit_by = $base->getVar($layer['settings'], 'limit-type', 'none'); if ($limit_by !== 'none') { switch ($layer['settings']['source']) { case 'post': case 'event': case 'woocommerce': $text = $base->get_text_intro($text, $base->getVar($layer['settings'], 'limit-num', 10, 'i'), $limit_by); break; } } } } $link_to = $base->getVar($layer['settings'], 'link-type', 'none'); $link_target = $base->getVar($layer['settings'], 'link-target', '_self'); if ($link_target !== 'disabled') { $link_target = ' target="' . $link_target . '"'; } else { $link_target = ''; } $video_play = ''; $ajax_class = ''; $ajax_attr = ''; $lb_class = ''; switch ($link_to) { case 'post': if ($demo === false) { if ($is_post) { $text = '<a href="' . get_permalink($post['ID']) . '"' . $link_target . '>' . $text . '</a>'; } else { $get_link = $this->get_custom_element_value('post-link', $separator, ''); //get the post link if ($get_link == '') { $text = '<a href="javascript:void(0);"' . $link_target . '>' . $text . '</a>'; } else { $text = '<a href="' . $get_link . '"' . $link_target . '>' . $text . '</a>'; } } } else { $text = '<a href="javasccript:void(0);"' . $link_target . '>' . $text . '</a>'; } break; case 'url': $lurl = $base->getVar($layer['settings'], 'link-type-url', 'javascript:void(0);'); if (strpos($lurl, '://') === false && trim($lurl) !== '' && $lurl !== 'javascript:void(0);') { $lurl = is_ssl() ? 'https://' . $lurl : 'http://' . $lurl; } $text = '<a href="' . $lurl . '"' . $link_target . '>' . $text . '</a>'; break; case 'meta': if ($demo === false) { if ($is_post) { $meta_key = $base->getVar($layer['settings'], 'link-type-meta', 'javascript:void(0);'); $meta_link = $m->get_meta_value_by_handle($post['ID'], $meta_key); if ($meta_link == '') { // if empty, link to nothing $text = '<a href="javascript:void(0);"' . $link_target . '>' . $text . '</a>'; } else { $text = '<a href="' . $meta_link . '"' . $link_target . '>' . $text . '</a>'; } } else { $meta_key = $base->getVar($layer['settings'], 'link-type-meta', ''); $get_link = $this->get_custom_element_value('post-link', $separator, $meta_key); //get the post link if ($get_link == '') { $text = '<a href="javascript:void(0);"' . $link_target . '>' . $text . '</a>'; } else { $text = '<a href="' . $get_link . '"' . $link_target . '>' . $text . '</a>'; } } } else { $text = '<a href="javascript:void(0);"' . $link_target . '>' . $text . '</a>'; } break; case 'javascript': $text = '<a href="javascript:' . $base->getVar($layer['settings'], 'link-type-javascript', 'void(0);') . '"' . $link_target . '>' . $text . '</a>'; //javascript-link break; case 'lightbox': if (!Essential_Grid_Jackbox::is_active() && !Essential_Grid_Social_Gallery::is_active()) { //enqueue only if default LightBox is selected wp_enqueue_script('themepunchboxext'); wp_enqueue_style('themepunchboxextcss'); } $lb_source = '#'; $lb_addition = ''; $lb_rel = $this->lb_rel !== false ? ' rel="' . $this->lb_rel . '"' : ''; if (!empty($this->default_lightbox_source_order)) { //only show if something is checked foreach ($this->default_lightbox_source_order as $order) { //go through the order and set media as wished if (isset($this->media_sources[$order]) && $this->media_sources[$order] !== '' && $this->media_sources[$order] !== false) { //found entry $do_continue = false; if (!empty($this->lightbox_additions['items']) && $this->lightbox_additions['base'] == 'on') { $lb_source = $this->lightbox_additions['items'][0]; $lb_class = ' esgbox'; } else { switch ($order) { case 'featured-image': case 'alternate-image': case 'content-image': if ($order == 'content-image') { $lb_source = $this->media_sources[$order]; } else { $lb_source = $this->media_sources[$order . '-full']; } $lb_class = ' esgbox'; break; case 'youtube': $http = is_ssl() ? 'https' : 'http'; $lb_source = $http . '://www.youtube.com/watch?v=' . $this->media_sources[$order]; $lb_class = ' esgbox'; break; case 'vimeo': $http = is_ssl() ? 'https' : 'http'; $lb_source = $http . '://vimeo.com/' . $this->media_sources[$order]; $lb_class = ' esgbox'; break; case 'iframe': //$lb_source = html_entity_decode($this->media_sources[$order]); //$lb_class = ' esgbox'; $do_continue = true; break; case 'html5': if (trim($this->media_sources[$order]['mp4']) === '' && trim($this->media_sources[$order]['ogv']) === '' && trim($this->media_sources[$order]['webm'] === '')) { $do_continue = true; } else { $lb_mp4 = $this->media_sources[$order]['mp4']; $lb_ogv = $this->media_sources[$order]['ogv']; $lb_webm = $this->media_sources[$order]['webm']; $lb_source = "#"; $lb_class = ' esgbox esgboxhtml5'; $lb_addition = ' data-mp4="' . $lb_mp4 . '" data-ogv="' . $lb_ogv . '" data-webm="' . $lb_webm . '"'; } break; default: $do_continue = true; break; } } if ($do_continue) { continue; } break; } } } if ($demo !== false) { $lb_title = __('demo mode', EG_TEXTDOMAIN); } else { if ($is_post) { $lb_title = $base->getVar($this->post, 'post_title', ''); } else { $lb_title = $this->get_custom_element_value('title', $separator, ''); } //the title from Post Title will be used } $text = '<a href="' . $lb_source . '"' . $lb_addition . ' lgtitle="' . $lb_title . '"' . $lb_rel . '>' . $text . '</a>'; $this->load_lightbox = true; //set that jQuery is written break; case 'embedded_video': $video_play = ' esg-click-to-play-video'; break; case 'ajax': $ajax_class = ''; if (!empty($this->default_ajax_source_order)) { //only show if something is checked $ajax_class = ' eg-ajaxclicklistener'; foreach ($this->default_ajax_source_order as $order) { //go through the order and set media as wished $do_continue = false; if (isset($this->media_sources[$order]) && $this->media_sources[$order] !== '' && $this->media_sources[$order] !== false || $order == 'post-content') { //found entry switch ($order) { case 'youtube': $vid_ratio = $this->video_ratios['youtube'] == '0' ? '4:3' : '16:9'; $ajax_attr = ' data-ajaxtype="youtubeid"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="' . $this->media_sources[$order] . '"'; //depending on type $ajax_attr .= ' data-ajaxvideoaspect="' . $vid_ratio . '"'; //depending on type break; case 'vimeo': $vid_ratio = $this->video_ratios['vimeo'] == '0' ? '4:3' : '16:9'; $ajax_attr = ' data-ajaxtype="vimeoid"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="' . $this->media_sources[$order] . '"'; //depending on type $ajax_attr .= ' data-ajaxvideoaspect="' . $vid_ratio . '"'; //depending on type break; case 'html5': if ($this->media_sources[$order]['mp4'] == '' && $this->media_sources[$order]['webm'] == '' && $this->media_sources[$order]['ogv'] == '') { $do_continue = true; } else { //mp4/webm/ogv $vid_ratio = $this->video_ratios['html5'] == '0' ? '4:3' : '16:9'; $ajax_attr = ' data-ajaxtype="html5vid"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="'; $ajax_attr .= @$this->media_sources[$order]['mp4'] . '|'; $ajax_attr .= @$this->media_sources[$order]['webm'] . '|'; $ajax_attr .= @$this->media_sources[$order]['ogv']; $ajax_attr .= '"'; $ajax_attr .= ' data-ajaxvideoaspect="' . $vid_ratio . '"'; //depending on type } break; case 'soundcloud': $ajax_attr = ' data-ajaxtype="soundcloudid"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="' . $this->media_sources[$order] . '"'; //depending on type break; case 'post-content': if ($is_post) { $ajax_attr = ' data-ajaxtype="postid"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="' . @$this->post['ID'] . '"'; //depending on type } else { $do_continue = true; //$ajax_class = ''; } break; case 'featured-image': case 'alternate-image': case 'content-image': $img_url = ''; if ($order == 'content-image') { $img_url = $this->media_sources[$order]; } else { $img_url = $this->media_sources[$order . '-full']; } $ajax_attr = ' data-ajaxtype="imageurl"'; // postid, html5vid youtubeid vimeoid soundcloud revslider $ajax_attr .= ' data-ajaxsource="' . $img_url . '"'; //depending on type break; default: $ajax_class = ''; $do_continue = true; break; } if ($do_continue) { continue; } break; } else { //some custom entry maybe $postobj = $is_post ? $this->post : false; $ajax_attr = apply_filters('essgrid_handle_ajax_content', $order, $this->media_sources, $postobj, $this->grid_id); if (empty($ajax_attr)) { //$ajax_class = ''; $do_continue = true; } if ($do_continue) { continue; } break; } } } //$ajax_attr .= ' data-ajaxcallback=""'; //functionname //$ajax_attr .= ' data-ajaxcsstoload=""'; //css source //$ajax_attr .= ' data-ajaxjstoload=""'; //js source if ($ajax_class !== '') { //set ajax loading to true so that the grid can decide to put ajax container in top/bottom $this->ajax_loading = true; } break; } if ($link_to !== 'none') { $do_display = true; } //set back to true if a link is set on layer $text = trim($text); //check for special styling coming from post option and set css to the queue $this->set_meta_element_changes($layer['id'], $unique_class); $post_class = !isset($post['ID']) ? '' : ' eg-post-' . $post['ID']; if ($base->text_has_certain_tag($text, 'a') && !$do_ignore_styles) { //check if a tag exists, if yes, class will be set to a tags and not the wrapping div, also the div will receive the position and other stylings // && @$layer['settings']['source'] !== 'text' if ($is_woo_cats && strpos($text, 'class="') !== false || $is_woo_button || $is_filter_cat && strpos($text, 'class="') !== false) { //add to the classes instead of creating own class attribute if it is woocommerce cats AND a class can be found $text = str_replace('class="', 'class="' . $unique_class . $post_class . $lb_class . ' ', $text); } elseif ($is_html_source && strpos($text, 'class="') !== false) { $text = str_replace('<a', '<a class="' . $unique_class . $post_class . $lb_class . '"', $text); } else { $text = str_replace('<a', '<a class="' . $unique_class . $post_class . $lb_class . '"', $text); } //moved to more global css generation process @version: 2.0 //$this->add_css_wrap[$unique_class]['a']['display'] = $do_display; //do_display defines if we should write display: block; //$this->add_css_wrap[$unique_class]['a']['full'] = $do_full; //do full styles (for categories and tags separator) $unique_class .= '-a'; } if ($do_ignore_styles) { $unique_class = 'eg-' . esc_attr($this->handle) . '-nostyle-element-' . $layer['id']; } //replace all the normal shortcodes $text = do_shortcode($text); if ($special_item == 'true' && $special_item_type == 'line-break') { //line break element echo ' <div class="esg-' . $class . ' ' . $unique_class . ' esg-none esg-clear" style="height: 5px; visibility: hidden;"></div>' . "\n"; } elseif (trim($text) !== '') { //}elseif(!empty($text)){ $use_tag = $base->getVar($layer['settings'], 'tag-type', 'div'); echo ' <' . $use_tag . ' class="esg-' . $class . $post_class . $video_play . $ajax_class . ' ' . $hideunderClass . $unique_class . $transition . '"' . $ajax_attr . $transition_split . $delay . $hideunderHTML; echo $demo == 'custom' ? $demo_element_type : ''; echo '>'; echo $text; echo '</' . $use_tag . '>' . "\n"; } }