function mg_lightbox($post_id, $prev_item = false, $next_item = false) { include_once MG_DIR . '/functions.php'; $post_data = get_post($post_id); $GLOBALS['post'] = $post_data; // post type and layout if ($post_data->post_type == 'product') { // simulate standard type and add flag $wc_prod = new WC_Product($post_id); $wc_gallery = $wc_prod->get_gallery_attachment_ids(); $type = is_array($wc_gallery) && count($wc_gallery) > 0 ? 'img_gallery' : 'single_img'; } else { $type = get_post_meta($post_id, 'mg_main_type', true); $wc_prod = false; } // layout $layout = get_post_meta($post_id, 'mg_layout', true); $touchswipe = get_option('mg_lb_touchswipe') ? 'mg_touchswipe' : ''; $img_max_h = (int) get_post_meta($post_id, 'mg_img_maxheight', true); $item_title = $post_data->post_title; // canvas color for TT $tt_canvas = substr(get_option('mg_item_bg_color', '#ffffff'), 1); // maxwidth control $lb_max_w = (int) get_option('mg_item_maxwidth', 960); if ($lb_max_w == 0) { $lb_max_w = 960; } // Thumb center $tt_center = get_post_meta($post_id, 'mg_thumb_center', true) ? get_post_meta($post_id, 'mg_thumb_center', true) : 'c'; // lightbox max width for the item $fc_max_w = (int) get_post_meta($post_id, 'mg_lb_max_w', true); if (!$fc_max_w || $fc_max_w < 280) { $fc_max_w = false; } // item featured image for socials $fi_img_id = get_post_thumbnail_id($post_id); $fi_src = wp_get_attachment_image_src($fi_img_id, 'medium'); $fi_src_pt = wp_get_attachment_image_src($fi_img_id, 'full'); // pinterest - use full one /////////////////////////// // TYPES if ($type == 'single_img') { $img_id = get_post_thumbnail_id($post_id); $featured = mg_preloader() . '<img src="' . mg_lb_image_optimizer($img_id, $layout, $img_max_h, $tt_center, $resize = 3) . '" alt="' . mg_sanitize_input(strip_tags($item_title)) . '" />'; } elseif ($type == 'img_gallery') { $slider_img = isset($wc_gallery) ? $wc_gallery : get_post_meta($post_id, 'mg_slider_img', true); $style = get_option('mg_slider_style', 'light'); $unique_id = uniqid(); $autoplay = get_post_meta($post_id, 'mg_slider_autoplay', true) ? 'true' : 'false'; // slider height $def_h_val = get_option('mg_slider_main_w_val', 55); $def_h_type = get_option('mg_slider_main_w_type', '%'); $h_val = get_post_meta($post_id, 'mg_slider_w_val', true); $h_type = get_post_meta($post_id, 'mg_slider_w_type', true); if (!$h_val) { $h_val = $def_h_val; } if (!$h_type) { $h_type = $def_h_type; } $height = $h_val . $h_type; // slider proportions parameter if (strpos($height, '%') !== false) { $val = (int) str_replace("%", "", $height) / 100; $proportions_param = 'asp-ratio="' . $val . '"'; $proportions_class = "mg_galleria_responsive"; $slider_h = ''; $stage_max_h = $val; } else { $proportions_param = ''; $proportions_class = ""; $slider_h = 'height: ' . $height . ';'; $stage_max_h = $h_val; } // images management $crop = get_post_meta($post_id, 'mg_slider_crop', true); if (!$crop) { $crop = 'true'; } // slider thumbs visibility $thumbs_visibility = get_post_meta($post_id, 'mg_slider_thumbs', true); $thumbs_class = $thumbs_visibility == 'yes' || $thumbs_visibility == 'always' ? 'mg_galleria_slider_show_thumbs' : ''; // thumbs CSS code if ($thumbs_visibility == 'always' || $thumbs_visibility == 'never') { $css_code = '.mg_galleria_slider_wrap .galleria-mg-toggle-thumb {display: none !important;}'; } else { $css_code = ''; } if (!$thumbs_visibility || $thumbs_visibility == 'no' || $thumbs_visibility == 'never') { $css_code .= '.mg_galleria_slider_wrap .galleria-thumbnails-container {opacity: 0; filter: alpha(opacity=0);}'; } $featured = ' <style type="text/css"> ' . $css_code . ' .mg_item_featured {max-height: 0px; overflow: hidden;} </style> <script type="text/javascript"> mg_galleria_img_crop = "' . $crop . '"; mg_slider_autoplay["#' . $unique_id . '"] = ' . $autoplay . '; </script> <div id="' . $unique_id . '" class="mg_galleria_slider_wrap mg_show_loader mg_galleria_slider_' . $style . ' ' . $thumbs_class . ' ' . $proportions_class . ' mgs_' . $post_id . ' noSwipe" style="width: 100%; ' . $slider_h . '" ' . $proportions_param . ' >'; if (is_array($slider_img)) { if (get_post_meta($post_id, 'mg_slider_random', true)) { shuffle($slider_img); } // woocommerce - if prepend first image if (isset($wc_gallery) && get_post_meta($post_id, 'mg_slider_add_featured', true)) { array_unshift($slider_img, $fi_img_id); } // compose slider structure foreach ($slider_img as $img_id) { // WPML integration - get translated ID if (function_exists('icl_object_id')) { $img_id = icl_object_id($img_id, 'attachment', true); } if (get_post_meta($post_id, 'mg_slider_captions', true) == 1) { $img_data = get_post($img_id); $caption = trim(strip_tags(apply_filters('the_content', $img_data->post_content), 'br')); $caption == '' ? $caption_code = '' : ($caption_code = $caption); } else { $caption_code = ''; } $img_url = mg_lb_image_optimizer($img_id, $layout, false, 'c', $resize = 3); $thumb = mg_thumb_src($img_id, 100, 69, $thumb_q = 85, 'c'); $featured .= ' <a href="' . $img_url . '"> <img src="' . mg_sanitize_input($thumb) . '" data-big="' . $img_url . '" data-description="' . mg_sanitize_input($caption_code) . '" /> </a>'; } } $featured .= '<div style="clear: both;"></div> </div>'; // slider wrap closing // slider init $featured .= '<script type="text/javascript"> jQuery(document).ready(function($) { if(typeof(mg_galleria_init) == "function") { mg_galleria_show("#' . $unique_id . '"); setTimeout(function() { mg_galleria_init("#' . $unique_id . '"); }, 150); } }); </script>'; } elseif ($type == 'video') { $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full'); $video_url = get_post_meta($post_id, 'mg_video_url', true); $video_w = $layout == 'full' ? 960 : 960 * 0.675; $video_h = $video_w * 0.5600000000000001; // poster if (get_post_meta($post_id, 'mg_video_use_poster', true) == 1) { $img_id = get_post_thumbnail_id($post_id); $poster = true; $poster_h = $lb_max_w * 0.5600000000000001; $poster_img = mg_lb_image_optimizer($img_id, $layout, $poster_h, $tt_center, $resize = 1); } else { $poster = false; $poster_img = ''; } if (lcwp_video_embed_url($video_url) == 'wrong_url') { $autoplay = get_option('mg_video_autoplay') && !$poster ? 'autoplay="on"' : ''; // get video sources $ok_src = array(); $allowed = array('mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv'); $sources = explode(',', $video_url); foreach ($sources as $v_src) { $ext = substr(trim(lcwp_stringToExt($v_src)), 1); if (in_array($ext, $allowed)) { $ok_src[$ext] = trim($v_src); } } $man_src = array(); foreach ($ok_src as $v_type => $url) { $man_src[] = $v_type . '="' . $url . '"'; } if (count($ok_src) == 0) { $featured = '<p><em>Video extension not supported ..</em></p>'; } else { $poster_attr = !empty($poster_img) ? 'poster="' . $poster_img . '"' : ''; $featured = '<div id="mg_wp_video_wrap" class="mg_self-hosted-video">' . do_shortcode('[video ' . implode(' ', $man_src) . ' ' . $poster_attr . ' ' . $autoplay . ' preload="auto"][/video]') . '</div>'; $featured .= "\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<link rel='stylesheet' id='mediaelement-css' href='" . includes_url() . "js/mediaelement/mediaelementplayer.min.css?ver=2.13.0' type='text/css' media='all' />\n\t\t\t\t<link rel='stylesheet' id='wp-mediaelement-css' href='" . includes_url() . "js/mediaelement/wp-mediaelement.css?ver=3.6' type='text/css' media='all' />\n\t\t\t\t\n\t\t\t\t<script type='text/javascript'>\n\t\t\t\t/* <![CDATA[ */\n\t\t\t\tvar mejsL10n = {'language':'en-US','strings':{\n\t\t\t\t\t'Close':'Close',\n\t\t\t\t\t'Fullscreen': '" . __('Fullscreen', 'mg_ml') . "',\n\t\t\t\t\t'Download File': '" . __('Download File', 'mg_ml') . "',\n\t\t\t\t\t'Download Video': '" . __('Download Video', 'mg_ml') . "',\n\t\t\t\t\t'Play\\/Pause': '" . __('Play\\/Pause', 'mg_ml') . "',\n\t\t\t\t\t'Mute Toggle': '" . __('Mute Toggle', 'mg_ml') . "',\n\t\t\t\t\t'None': '" . __('None', 'mg_ml') . "',\n\t\t\t\t\t'Turn off Fullscreen': '" . __('Turn off Fullscreen', 'mg_ml') . "',\n\t\t\t\t\t'Go Fullscreen': '" . __('Go Fullscreen', 'mg_ml') . "',\n\t\t\t\t\t'Unmute': '" . __('Unmute', 'mg_ml') . "',\n\t\t\t\t\t'Mute': '" . __('Mute', 'mg_ml') . "',\n\t\t\t\t\t'Captions\\/Subtitles': '" . __('Captions\\/Subtitles', 'mg_ml') . "'\n\t\t\t\t}};\n\t\t\t\t/* ]]> */\n\t\t\t\t</script>\n\t\t\t\t<script type='text/javascript' src='" . includes_url() . "js/mediaelement/mediaelement-and-player.min.js'></script>\n\t\t\t\t<script type='text/javascript'>\n\t\t\t\t/* <![CDATA[ */\n\t\t\t\tvar _wpmejsSettings = {'pluginPath':'" . str_replace('/', '\\/', includes_url()) . "js\\/mediaelement\\/'};\n\t\t\t\t/* ]]> */\n\t\t\t\t</script>\n\t\t\t\t\n\t\t\t\t<script type='text/javascript' src='" . includes_url() . "js/mediaelement/wp-mediaelement.js'></script>"; } } else { if ($poster) { $autop_url = lcwp_video_embed_url($video_url, true); $v_url = lcwp_video_embed_url($video_url, false); $ifp = mg_preloader() . '<div id="mg_ifp_ol" class="fa fa-play" style="display: none;"></div> <img src="' . $poster_img . '" alt="' . mg_sanitize_input(strip_tags($item_title)) . '" autoplay-url="' . $autop_url . '" style="display: none;" class="mg_lb_video_poster" />'; $poster_bg = 'style="background-image: url(' . $poster_img . ')"'; $vis = 'style="display: none;"'; } else { $ifp = ''; $autoplay = ''; $vis = ''; $poster_bg = ''; $v_url = lcwp_video_embed_url($video_url); } $featured = ' <div id="mg_lb_video_wrap" ' . $poster_bg . '> ' . $ifp . ' <iframe class="mg_video_iframe" width="' . $video_w . '" height="' . $video_h . '" src="' . $v_url . '" frameborder="0" allowfullscreen ' . $vis . '></iframe> </div> '; } } elseif ($type == 'audio') { // check for soundcloud embedding $soundcloud = get_post_meta($post_id, 'mg_soundcloud_url', true); if (!empty($soundcloud)) { $featured = mg_get_soundcloud_embed($soundcloud); } else { $img_id = get_post_thumbnail_id($post_id); $tracklist = get_post_meta($post_id, 'mg_audio_tracks', true); $tot = is_array($tracklist) ? count($tracklist) : 0; $tot == 1 || !get_option('mg_audio_tracklist') ? $tl_class = 'jp_hide_tracklist' : ($tl_class = 'jp_full_tracklist'); // inlude jplayer script $script_name = 'mg_pack.js'; //(get_option('mg_old_js_mode')) ? 'mg_pack.js' : 'mg_pack_old_js.js'; $featured = '<script type="text/javascript" src="' . MG_URL . '/js/jPlayer/' . $script_name . '"></script>'; $featured .= mg_preloader() . '<img src="' . mg_lb_image_optimizer($img_id, $layout, $img_max_h, $tt_center, $resize = 3) . '" alt="' . mg_sanitize_input(strip_tags($item_title)) . '" />'; $featured .= ' <div id="mg_audio_player_' . $post_id . '" class="jp-jplayer"></div> <div id="mg_audio_wrap_' . $post_id . '" class="jp-audio noSwipe" style="display: none;"> <div class="jp-type-playlist"> <div class="jp-gui jp-interface"> <div class="jp-cmd-wrap">'; if ($tot > 1) { $featured .= '<a href="javascript:;" class="jp-previous">previous</a>'; } $featured .= ' <a href="javascript:;" class="jp-play">play</a> <a href="javascript:;" class="jp-pause">pause</a>'; if ($tot > 1) { $featured .= '<a href="javascript:;" class="jp-next">next</a>'; } $featured .= ' <div class="jp-time-holder"> <div class="jp-current-time"></div> <span>/</span> <div class="jp-duration"></div> </div> <div class="jp-progress"> <div class="jp-seek-bar"> <div class="jp-play-bar"></div> </div> </div>'; $featured .= ' <div class="jp-volume-group"> <a href="javascript:;" class="jp-mute" title="mute">mute</a> <a href="javascript:;" class="jp-unmute" title="unmute">unmute</a> <div class="jp-volume-bar"> <div class="jp-volume-bar-value"></div> </div> </div> </div>'; $featured .= ' <div class="jp-track-title"> <div class="jp-playlist ' . $tl_class . '"> <ul> <li></li> </ul> </div> </div> </div> </div> </div>'; if (is_array($tracklist) && count($tracklist) > 0) { // js code $featured .= ' <script type="text/javascript"> jQuery(function(){ mg_lb_jplayer = function() { new jPlayerPlaylist({ jPlayer: "#mg_audio_player_' . $post_id . '", cssSelectorAncestor: "#mg_audio_wrap_' . $post_id . '", }, ['; $a = 1; foreach ($tracklist as $track) { $track_data = get_post($track); $tot > 1 ? $counter = '<em>' . $a . '/' . $tot . '</em>) ' : ($counter = ''); $track_json[] = ' { title:"' . $counter . addslashes($track_data->post_title) . '", mp3:"' . $track_data->guid . '" } '; $a++; } $featured .= implode(',', $track_json) . ' ], {'; // autoplay $autoplay = get_option('mg_audio_autoplay') ? 'autoPlay: true,' : ''; $featured .= ' playlistOptions: { ' . $autoplay . ' displayTime: 0, }, swfPath: "' . MG_URL . '/js/jPlayer/", supplied: "mp3" }); } }); </script> '; } } } // force the layout for the lightbox custom contents if ($type == 'lb_text') { $layout = 'full'; } /////////////////////////// // custom CSS to manage image's height if (($type == 'single_img' || $type == 'audio') && isset($img_max_h) && $img_max_h > 0) { ?> <style type="text/css"> .mg_item_featured { text-align: center; } .mg_item_featured .jp-audio { text-align: left; } .mg_item_featured > img { display: inline-block; margin: auto; width: auto !important; max-height: <?php echo $img_max_h; ?> px; } </style> <?php } /////////////////////////// // builder /*** lightbox command codes ***/ $cmd_mode = get_option('mg_lb_cmd_pos', 'inside'); ?> <div id="mg_inside_close" class="mg_close_lb" <?php if ($cmd_mode != 'inside' && $cmd_mode != 'ins_hidden') { echo 'style="display: none;"'; } ?> ></div> <div id="mg_lb_inside_nav" class="noSwipe" <?php if ($cmd_mode != 'inside') { echo 'style="display: none;"'; } ?> > <?php echo mg_lb_nav_code(array('prev' => $prev_item, 'next' => $next_item), 'inside'); ?> </div> <?php if ($cmd_mode != 'inside' && $cmd_mode != 'ins_hidden') { if ($cmd_mode == 'top') { $code = ' <div id="mg_top_close" class="mg_close_lb" style="display: none;"></div> <div id="mg_lb_top_nav" style="display: none;">' . mg_lb_nav_code(array('prev' => $prev_item, 'next' => $next_item), $cmd_mode) . '</div>'; } else { $code = ' <div id="mg_top_close" class="mg_close_lb" style="display: none;"></div>' . mg_lb_nav_code(array('prev' => $prev_item, 'next' => $next_item), $cmd_mode); } echo ' <script type="text/javascript"> jQuery("#mg_overlay_content").before("' . str_replace(array("\r", "\n", "\t", "\v"), '', str_replace('"', '\\"', $code)) . '"); jQuery("#mg_lb_top_nav, .mg_side_nav, #mg_top_close").fadeIn(350); if(navigator.appVersion.indexOf("MSIE 8.") != -1) { jQuery(".mg_side_nav > div").css("top", 0); } </script>'; } ?> <?php /*** internal contents ***/ ?> <div class="mg_layout_<?php echo $layout; ?> mg_lb_<?php echo $type; ?> "> <div> <?php if ($type != 'lb_text') { ?> <div class="mg_item_featured" <?php if ($fc_max_w) { echo 'rel="' . $fc_max_w . 'px"'; } ?> > <?php echo $featured; ?> </div> <?php } ?> <div class="mg_item_content"> <?php /* custom options - woocommerce attributes */ $opts = mg_lb_cust_opts_code($post_id, $type, $wc_prod); /* title and options wrap */ if ($layout == 'full' && !empty($opts)) { echo '<div class="mg_content_left">'; } echo '<h1 class="mg_item_title">' . apply_filters('the_title', $item_title) . '</h1>'; echo $opts; if ($layout == 'full' && !empty($opts)) { echo '</div>'; } ?> <div class="mg_item_text <?php if ($layout == 'full' && empty($cust_opt)) { echo 'mg_widetext'; } ?> "> <?php echo do_shortcode(wpautop(apply_filters('the_content', $post_data->post_content))); ?> <?php if ($wc_prod && !get_option('mg_wc_hide_add_to_cart')) { echo do_shortcode('[add_to_cart id="' . $post_id . '" style=""]'); } ?> </div> <?php // SOCIALS if (get_option('mg_facebook') || get_option('mg_twitter') || get_option('mg_pinterest')) { $dl_part = get_option('mg_disable_dl') ? '' : '#!mg_ld_' . $post_id; ?> <div id="mg_socials" class="mgls_<?php echo get_option('mg_lb_socials_style', 'squared'); ?> "> <ul> <?php if (get_option('mg_facebook')) { ?> <li id="mg_fb_share"> <a onClick="window.open('https://www.facebook.com/dialog/feed?app_id=425190344259188&display=popup&name=<?php echo urlencode(get_the_title($post_id)); ?> &description=<?php echo urlencode(substr(strip_tags(strip_shortcodes(get_post_field('post_content', $post_id))), 0, 1000)); ?> &picture=<?php echo urlencode($fi_src[0]); ?> &link=<?php echo urlencode(lcwp_curr_url() . $dl_part); ?> &redirect_uri=http://www.lcweb.it/lcis_redirect.php','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)"><span title="<?php _e('Share it!', 'mg_ml'); ?> "></span></a> </li> <?php } ?> <?php if (get_option('mg_twitter')) { ?> <li id="mg_tw_share"> <a onClick="window.open('https://twitter.com/share?text=<?php echo urlencode('Check out "' . get_the_title($post_id) . '" on ' . get_bloginfo('name')); ?> &url=<?php echo urlencode(lcwp_curr_url() . $dl_part); ?> ','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)"><span title="<?php _e('Tweet it!', 'mg_ml'); ?> "></span></a> </li> <?php } ?> <?php if (get_option('mg_pinterest')) { ?> <?php // $pt_resized_img = mg_thumb_src($fi_src_pt[0], 736, false); ?> <li id="mg_pn_share"> <a onClick="window.open('http://pinterest.com/pin/create/button/?url=<?php echo urlencode(lcwp_curr_url() . $dl_part); ?> &media=<?php echo urlencode($fi_src_pt[0]); ?> &description=<?php echo urlencode(get_the_title($post_id)); ?> ','sharer','toolbar=0,status=0,width=575,height=330');" href="javascript: void(0)"><span title="<?php _e('Pin it!', 'mg_ml'); ?> "></span></a> </li> <?php } ?> <?php if (get_option('mg_googleplus') && !get_option('mg_disable_dl')) { ?> <li id="mg_gp_share"> <a onClick="window.open('https://plus.google.com/share?url=<?php echo urlencode(lcwp_curr_url() . $dl_part); ?> ','sharer','toolbar=0,status=0,width=490,height=360');" href="javascript: void(0)"><span title="<?php _e('Share it!', 'mg_ml'); ?> "></span></a> </li> <?php } ?> </ul> </div> <?php } ?> <br style="clear: both;" /> </div> </div> </div> <?php }
function mg_shortcode($atts, $content = null) { include_once MG_DIR . '/functions.php'; include_once MG_DIR . '/classes/overlay_manager.php'; extract(shortcode_atts(array('cat' => '', 'filter' => 0, 'r_width' => 'auto', 'title_under' => 0, 'hide_all' => 0, 'def_filter' => 0, 'overlay' => 'default'), $atts)); if ($cat == '') { return ''; } // deeplinking class $dl_class = get_option('mg_disable_dl') ? '' : 'mg_deeplink'; // init $grid = ''; // filter if ($filter) { $filter_code = mg_grid_terms_data($cat, 'html', $def_filter, $hide_all); if ($filter_code) { $filter_type = get_option('mg_use_old_filters') ? 'mg_old_filters' : 'mg_new_filters'; $grid .= '<div id="mgf_' . $cat . '" class="mg_filter ' . $filter_type . '">' . $filter_code . '</div>'; } // mobile dropdown if (get_option('mg_dd_mobile_filter')) { $filter_code = mg_grid_terms_data($cat, 'dropdown', $def_filter, $hide_all); if ($filter_code) { $grid .= '<div id="mgmf_' . $cat . '" class="mg_mobile_filter">' . $filter_code . '<i></i></div>'; } } } // title under - wrap class $tit_under_class = $title_under == 1 ? 'mg_grid_title_under' : ''; // image overlay code $ol_man = new mg_overlay_manager($overlay, $title_under); $grid .= ' <div class="mg_grid_wrap ' . $dl_class . '"> ' . mg_preloader() . ' <div id="mg_grid_' . $cat . '" class="mg_container ' . $tit_under_class . ' ' . $ol_man->txt_vis_class . '" rel="' . $r_width . '" ' . $ol_man->img_fx_attr . '>'; ///////////////////////// // grid contents $term = get_term_by('id', $cat, 'mg_grids'); $grid_data = empty($term->description) ? array('items' => array(), 'cats' => array()) : unserialize($term->description); if (count($grid_data['items']) == 0) { return ''; } $max_width = get_option('mg_maxwidth', 1200); $mobile_treshold = get_option('mg_mobile_treshold', 800); $thumb_q = get_option('mg_thumb_q', 85); foreach ($grid_data['items'] as $item) { $post_id = $item['id']; // check post status if (get_post_status($post_id) != 'publish') { continue; } // WPML - check translation if (function_exists('icl_object_id')) { $post_id = icl_object_id($post_id, 'mg_items', true); } $main_type = get_post_type($post_id) == 'product' ? 'woocom' : get_post_meta($post_id, 'mg_main_type', true); $item_layout = get_post_meta($post_id, 'mg_layout', true); // image-based operations if ($main_type != 'spacer') { // thumbs image size $thb_w = ceil($max_width * mg_size_to_perc($item['w'])); $thb_h = ceil($max_width * mg_size_to_perc($item['h'])); if (!isset($item['m_w'])) { $item['m_w'] = $item['w']; $item['m_h'] = $item['h']; } $m_thb_w = ceil($mobile_treshold * mg_size_to_perc($item['m_w'])); $m_thb_h = ceil($mobile_treshold * mg_size_to_perc($item['m_h'])); if (!in_array($main_type, array('inl_slider', 'inl_text'))) { // thumb url and center $img_id = get_post_thumbnail_id($post_id); $thumb_center = get_post_meta($post_id, 'mg_thumb_center', true) ? get_post_meta($post_id, 'mg_thumb_center', true) : 'c'; if ($img_id) { // main thumb if ($item['h'] != 'auto') { $thumb_url = mg_thumb_src($img_id, $thb_w, $thb_h, $thumb_q, $thumb_center); } else { $thumb_url = mg_thumb_src($img_id, $thb_w, false, $thumb_q, $thumb_center); } // mobile thumb if ($item['m_h'] != 'auto') { $mobile_url = mg_thumb_src($img_id, $m_thb_w, $m_thb_h, $thumb_q, $thumb_center); } else { $mobile_url = mg_thumb_src($img_id, $m_thb_w, false, $thumb_q, $thumb_center); } } else { $thumb_url = ''; $mobile_url = ''; } } // item title $item_title = get_the_title($post_id); // image ALT attribute $img_alt = strip_tags(mg_sanitize_input($item_title)); // title under switch if ($title_under == 1) { $img_ol = '<div class="overlays">' . $ol_man->get_img_ol($post_id) . '</div>'; $txt_under = $ol_man->get_txt_under($post_id); } else { $img_ol = '<div class="overlays">' . $ol_man->get_img_ol($post_id) . '</div>'; $txt_under = ''; } // image proportions for the "auto" height if (($item['h'] == 'auto' || $item['m_h'] == 'auto') && $main_type != 'inl_text') { $img_info = wp_get_attachment_image_src($img_id, 'full'); $ratio_val = (double) $img_info[2] / (double) $img_info[1]; $ratio = 'ratio="' . $ratio_val . '"'; } else { $ratio = ''; } } //////////////////////////// /*** item types ***/ // type class switch ($main_type) { case 'single_img': $type_class = 'mg_image'; break; case 'img_gallery': $type_class = 'mg_gallery'; break; case 'simple_img': $type_class = 'mg_static_img'; break; default: $type_class = 'mg_' . $main_type; break; } // transitions class $trans_class = !in_array($main_type, array('inl_slider', 'inl_video', 'inl_text', 'spacer')) ? 'mg_transitions' : ''; // lightbox trigger class $lb_class = !in_array($main_type, array('simple_img', 'link', 'inl_slider', 'inl_video', 'inl_text', 'spacer')) ? 'mg_closed' : ''; // no overlay class fot static items $static_img_no_ol = $type_class != 'mg_static_img' || $type_class == 'mg_static_img' && get_post_meta($post_id, 'mg_static_show_overlay', true) ? '' : 'mg_static_no_ol'; // classes variable $add_classes = 'mgi_' . $post_id . ' ' . $type_class . ' ' . $trans_class . ' ' . $lb_class . ' ' . $static_img_no_ol . ' ' . mg_item_terms_classes($post_id); //////////////////////////// /*** items custom css ***/ // inline texts custom colors if ($main_type == 'inl_text') { $img_wrap_css = 'style="'; if (get_post_meta($post_id, 'mg_inl_txt_color', true)) { $img_wrap_css .= 'color: ' . get_post_meta($post_id, 'mg_inl_txt_color', true) . ';'; } if (get_post_meta($post_id, 'mg_inl_txt_box_bg', true)) { $img_wrap_css .= 'background-color: ' . get_post_meta($post_id, 'mg_inl_txt_box_bg', true) . ';'; } if ((int) get_post_meta($post_id, 'mg_inl_txt_bg_alpha', true)) { $alpha = (int) get_post_meta($post_id, 'mg_inl_txt_bg_alpha', true) / 100; $img_wrap_css .= 'background-color: ' . mg_hex2rgba(get_post_meta($post_id, 'mg_inl_txt_box_bg', true), $alpha) . ';'; } $img_wrap_css .= '"'; } else { $img_wrap_css = ''; } /*** item block ***/ // first part $grid .= ' <div id="' . uniqid() . '" class="mg_box mg_pre_show col' . $item['w'] . ' row' . $item['h'] . ' m_col' . $item['m_w'] . ' m_row' . $item['m_h'] . ' ' . $add_classes . '" rel="pid_' . $post_id . '" ' . $ratio . ' mgi_w="' . mg_size_to_perc($item['w'], 1) . '" mgi_h="' . mg_size_to_perc($item['h'], 1) . '" mgi_mw="' . mg_size_to_perc($item['m_w'], 1) . '" mgi_mh="' . mg_size_to_perc($item['m_h'], 1) . '">'; if ($main_type != 'spacer') { $grid .= ' <div class="mg_shadow_div"> <div class="img_wrap" ' . $img_wrap_css . '> <div>'; // link type - start tag if ($main_type == 'link') { $nofollow = get_post_meta($post_id, 'mg_link_nofollow', true) == '1' ? 'rel="nofollow"' : ''; $grid .= '<a href="' . get_post_meta($post_id, 'mg_link_url', true) . '" target="_' . get_post_meta($post_id, 'mg_link_target', true) . '" ' . $nofollow . ' class="mg_link_elem">'; } /*** inner contents for lightbox types ***/ // inline slider if ($main_type == 'inl_slider') { $slider_img = get_post_meta($post_id, 'mg_slider_img', true); $autoplay = get_post_meta($post_id, 'mg_inl_slider_autoplay', true) ? 'mg_autoplay_slider' : ''; $captions = get_post_meta($post_id, 'mg_inl_slider_captions', true); $grid .= ' <div id="' . uniqid() . '" class="mg_inl_slider_wrap ' . $autoplay . '">'; if (is_array($slider_img)) { if (get_post_meta($post_id, 'mg_inl_slider_random', true)) { shuffle($slider_img); } $seo_slider = '<noscript>'; foreach ($slider_img as $img_id) { // WPML integration - get translated ID if (function_exists('icl_object_id')) { $img_id = icl_object_id($img_id, 'attachment', true); } $src = wp_get_attachment_image_src($img_id, 'full'); // resize if is not an animated gif if (substr(strtolower($src[0]), -4) != '.gif' && substr(strtolower($src[0]), -4) != '.png') { $sizes = mg_inl_slider_img_sizes($src, $max_width, $item); $slider_thumb = mg_thumb_src($img_id, $sizes['w'], $sizes['h'], $thumb_q); } else { $slider_thumb = $src[0]; } if ($captions == 1) { $img_data = get_post($img_id); $caption = trim($img_data->post_content); $caption_code = $caption == '' ? '' : $caption; } else { $caption_code = ''; } $grid .= '<img src="" lazy-slider-img="' . $slider_thumb . '" data-description="' . mg_sanitize_input($caption_code) . '">'; $seo_slider .= '<img src="' . $slider_thumb . '" alt="' . mg_sanitize_input($caption_code) . '">'; } } // slider wrap closing + seo slider $grid .= '</div>' . $seo_slider . '</noscript>'; } // inline video if ($main_type == 'inl_video') { $poster = get_post_meta($post_id, 'mg_video_use_poster', true) == 1 && $thumb_url ? true : false; $autoplay = empty($poster) ? '' : true; $visibility = $poster ? 'style="display: none;"' : ''; $video_url = lcwp_video_embed_url(get_post_meta($post_id, 'mg_video_url', true), $autoplay); $url_to_use = $poster && $autoplay ? lcwp_video_embed_url(get_post_meta($post_id, 'mg_video_url', true), false) : $video_url; // fix for chrome autoplay $grid .= '<iframe class="mg_video_iframe" width="100%" height="100%" src="' . $url_to_use . '" frameborder="0" allowfullscreen ' . $visibility . '></iframe>'; } // inline text if ($main_type == 'inl_text') { $grid .= '<table class="mg_inl_txt_table"><tbody><tr> <td class="mg_inl_txt_td" style="vertical-align: ' . get_post_meta($post_id, 'mg_inl_txt_vert_align', true) . ';"> ' . do_shortcode(wpautop(get_post_field('post_content', $post_id))) . ' </td> </tr></tbody></table>'; } // standard lightbox types and inline video with poster if (!in_array($main_type, array('inl_slider', 'inl_video', 'inl_text')) || $main_type == 'inl_video' && $poster) { // video poster attribute if autoplay $poster_attr = $main_type == 'inl_video' && $autoplay ? 'autoplay-url="' . $video_url . '"' : ''; $grid .= ' <img src="" class="thumb" alt="' . $img_alt . '" fullurl="' . $thumb_url . '" mobileurl="' . $mobile_url . '" ' . $poster_attr . ' /> <noscript> <img src="' . $thumb_url . '" alt="' . $img_alt . '" ' . $poster_attr . ' /> </noscript>'; // overlays if ($main_type != 'simple_img' || $main_type == 'simple_img' && empty($static_img_no_ol)) { $grid .= $img_ol; } } // SEO deeplink trick if (!empty($dl_class) && !in_array($main_type, array('simple_img', 'inl_slider', 'inl_video', 'inl_text', 'link'))) { $grid .= '<a href="' . lcwp_curr_url() . '#!mg_ld_' . $post_id . '" class="mg_seo_dl_link">\'</a>'; } // link type - end tag if ($main_type == 'link') { $grid .= '</a>'; } $grid .= ' </div> </div>'; // overlays under if ($main_type != 'inl_text' && $main_type != 'simple_img' || $main_type == 'simple_img' && empty($static_img_no_ol)) { $grid .= $txt_under; } $grid .= '</div>'; } // close main div $grid .= '</div>'; } // end foreach and close grid $grid .= '</div></div>'; ////////////////////////////////////////////////// // OVERLAY MANAGER ADD-ON if (defined('MGOM_URL')) { $grid .= ' <script type="text/javascript"> jQuery(document).ready(function($) { if(typeof(mgom_hub) == "function" ) { mgom_hub(' . $cat . '); } }); </script> '; } ////////////////////////////////////////////////// // Ajax init if (get_option('mg_enable_ajax')) { $grid .= ' <script type="text/javascript"> jQuery(document).ready(function($) { if(typeof(mg_ajax_init) == "function" ) { mg_ajax_init(' . $cat . '); } }); </script> '; } return str_replace(array("\r", "\n", "\t", "\v"), '', $grid); }