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_item_opt_box() { require_once MG_DIR . '/functions.php'; global $post; $main_type = get_post_meta($post->ID, 'mg_main_type', true); if (!$main_type) { $main_type = ''; } $item_layout = get_post_meta($post->ID, 'mg_layout', true); $lb_maxwidth = get_post_meta($post->ID, 'mg_lb_max_w', true); $img_maxheight = get_post_meta($post->ID, 'mg_img_maxheight', true); ?> <div class="lcwp_mainbox_meta"> <table class="widefat lcwp_table lcwp_metabox_table"> <tr> <td class="lcwp_label_td"><?php _e("Item Type", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <select data-placeholder="<?php _e('Select a type', 'mg_ml'); ?> .." name="mg_main_type" id="mg_main_type" class="lcweb-chosen" autocomplete="off"> <?php $types = mg_item_types(); if (isset($types['woocom'])) { unset($types['woocom']); } foreach ($types as $key => $val) { $key == $main_type ? $sel = 'selected="selected"' : ($sel = ''); echo '<option value="' . $key . '" ' . $sel . '>' . $val . '</option>'; } ?> </select> </td> <td><span class="info"><?php _e('Choose the item type', 'mg_ml'); ?> </span></td> </tr> </table> <div id="mg_layout_wrap" <?php if (!$main_type || in_array($main_type, array('simple_img', 'link', 'lb_text', 'inl_slider', 'inl_video', 'inl_text', 'spacer'))) { echo 'style="display: none;"'; } ?> > <table class="widefat lcwp_table lcwp_metabox_table"> <tr> <td class="lcwp_label_td"><?php _e("Lightbox Layout", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <select data-placeholder="<?php _e('Select a layout', 'mg_ml'); ?> .." name="mg_layout" id="mg_layout" class="lcweb-chosen" autocomplete="off"> <option value="full"><?php _e('Full Width', 'mg_ml'); ?> </option> <option value="side" <?php if ($item_layout == 'side') { echo 'selected="selected"'; } ?> ><?php _e('Text on side', 'mg_ml'); ?> </option> </select> </td> <td><span class="info"></span></td> </tr> <tr> <td class="lcwp_label_td"><?php _e("Lightbox content max-width", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <input type="text" name="mg_lb_max_w" value="<?php echo (int) $lb_maxwidth == 0 ? '' : $lb_maxwidth; ?> " maxlength="4" style="width: 50px;" /> px </td> <td><span class="info"><?php _e('Leave blank to fit the content to the lightbox size', 'mg_ml'); ?> </span></td> </tr> </table> </div> <div id="mg_img_maxheight_wrap" <?php if (!in_array($main_type, array('single_img', 'audio'))) { echo 'style="display: none;"'; } ?> > <h4><?php _e('Full-size image control', 'mg_ml'); ?> </h4> <table class="widefat lcwp_table lcwp_metabox_table"> <tr> <td class="lcwp_label_td"><?php _e("Full image max-height", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <input type="text" name="mg_img_maxheight" value="<?php echo (int) $img_maxheight == 0 ? '' : $img_maxheight; ?> " maxlength="4" style="width: 50px;" /> px </td> <td><span class="info"><?php _e('Leave blank to use the full-size image', 'mg_ml'); ?> </span></td> </tr> </table> </div> <?php // USER CUSTOM OPTIONS ////////// ?> <div id="mg_cust_opt_wrap"> <div id="mg_cust_opt_img" <?php if ($main_type != 'single_img') { echo 'style="display: none;"'; } ?> > <?php echo mg_get_type_opt_fields('image', $post); ?> </div> <div id="mg_cust_opt_img_gallery" <?php if ($main_type != 'img_gallery') { echo 'style="display: none;"'; } ?> > <?php echo mg_get_type_opt_fields('img_gallery', $post); ?> </div> <div id="mg_cust_opt_video" <?php if ($main_type != 'video') { echo 'style="display: none;"'; } ?> > <?php echo mg_get_type_opt_fields('video', $post); ?> </div> <div id="mg_cust_opt_audio" <?php if ($main_type != 'audio') { echo 'style="display: none;"'; } ?> > <?php echo mg_get_type_opt_fields('audio', $post); ?> </div> </div> <?php // TYPE OPTIONS ////////// ?> <div id="mg_builder_wrap"> <?php // static image options ?> <div id="mg_builder_simple_img" class="lcwp_form" <?php if ($main_type && $main_type != 'simple_img') { echo 'style="display: none;"'; } ?> > <?php echo mg_meta_opt_generator('simple_img', $post); ?> </div> <?php // image gallery builder ?> <div id="mg_builder_img_gallery" <?php if (!in_array($main_type, array('img_gallery', 'inl_slider'))) { echo 'style="display: none;"'; } ?> > <?php $images = mg_existing_sel(get_post_meta($post->ID, 'mg_slider_img', true)); $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 = get_option('mg_slider_main_w_val', 55); } if (!$h_type) { $h_type = $def_h_type = get_option('mg_slider_main_w_type', '%'); } ?> <div id="mg_lb_slider_opt" <?php if ($main_type != 'img_gallery') { echo 'style="display: none;"'; } ?> > <h4><?php _e('Slider Options', 'mg_ml'); ?> </h4> <table class="widefat lcwp_table lcwp_metabox_table" style="margin-bottom: 0px;"> <tr> <td class="lcwp_label_td"><?php _e("Height", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <input type="text" class="lcwp_slider_input" name="mg_slider_w_val" value="<?php echo $h_val; ?> " maxlength="3" style="width: 50px; display: inline-block; text-align: center;" > <select name="mg_slider_w_type" style="width: 50px; margin-left: -5px;" autocomplete="off"> <option value="%">%</option> <option value="px" <?php if ($h_type == 'px') { echo 'selected="selected"'; } ?> >px</option> </select> </td> <td><span class="info"><?php _e("Slider height (% is related to its width)", 'mg_ml'); ?> </span></td> </tr> </table> <div style="border-bottom: 1px solid #DFDFDF; border-top: 1px solid #DFDFDF; margin-bottom: 17px;" class="lcwp_form"> <?php echo mg_meta_opt_generator('img_gallery', $post); ?> </div> </div> <div id="mg_inl_slider_opt" <?php if ($main_type != 'inl_slider') { echo 'style="display: none;"'; } ?> class="lcwp_form"> <h4><?php _e('Slider Options', 'mg_ml'); ?> </h4> <?php echo mg_meta_opt_generator('inl_slider', $post); ?> </div> <h4><?php _e('Slider Images', 'mg_ml'); ?> </h4> <div id="gallery_img_wrap"> <ul> <?php if (is_array($images)) { foreach ($images as $img_id) { echo ' <li> <input type="hidden" name="mg_slider_img[]" value="' . $img_id . '" /> <img src="' . mg_thumb_src($img_id, 90, 90) . '" /> <span title="remove image"></span> </li>'; } } else { echo '<p>' . __('No images selected', 'mg_ml') . ' .. </p>'; } ?> </ul> <br class="lcwp_clear"> </div> <div style="clear: both; height: 20px;"></div> <div id="mg_img_search_wrap"> <input type="text" placeholder="<?php _e('search', 'mg_ml'); ?> .." class="mg_search_field" /> <span class="mg_search_btn" title="search"></span> </div> <h4><?php _e('Choose images', 'mg_ml'); ?> <span class="mg_TB mg_upload_img add-new-h2"><?php _e('Manage Images', 'mg_ml'); ?> </span></h4> <div id="gallery_img_picker"></div> </div> <?php // video builder ?> <div id="mg_builder_video" class="lcwp_form" <?php if ($main_type != 'video' && $main_type != 'inl_video') { echo 'style="display: none;"'; } ?> > <h4><?php _e('Video Options', 'mg_ml'); ?> </h4> <table class="widefat lcwp_table lcwp_metabox_table"> <tr> <td class="lcwp_label_td"><?php _e('Video URL', 'mg_ml'); ?> </td> <td colspan="2"> <input type="text" value="<?php echo get_post_meta($post->ID, 'mg_video_url', true); ?> " name="mg_video_url" style="width: 60%; min-width: 217px;" /> <?php // self hosted video - lightbox trigger if ((double) substr(get_bloginfo('version'), 0, 3) >= 3.6 && $main_type == 'video') { ?> <img src="<?php echo MG_URL; ?> /img/media-library-src.png" title="search in media library" style="margin: 0 0 -6px 1px; cursor: pointer;" id="mg_video_src" /> <?php } ?> <br/> <span class="info"><?php _e('Insert Youtube (<strong>http://youtu.be</strong>), Vimeo or Dailymotion clean video url', 'mg_ml'); ?> .</span> <span class="info lb_video_info" <?php if ($main_type != 'video') { echo 'style="display: none;"'; } ?> > <?php if ((double) substr(get_bloginfo('version'), 0, 3) >= 3.6) { _e('Otherwise select a video from your media library', 'mg_ml'); } ?> </span> </td> </tr> <tr> <td class="lcwp_label_td"><?php _e("Use featured image as video poster?", 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <?php get_post_meta($post->ID, 'mg_video_use_poster', true) == 1 ? $sel = 'checked="checked"' : ($sel = ''); ?> <input type="checkbox" value="1" name="mg_video_use_poster" class="ip-checkbox" <?php echo $sel; ?> /> </td> <td> <span class="info"><?php _e('If checked, set the featured image as poster', 'mg_ml'); ?> </span> </td> </tr> </table> </div> <?php // audio builder ?> <div id="mg_builder_audio" <?php if ($main_type != 'audio') { echo 'style="display: none;"'; } ?> > <h4><?php _e('Audio Options', 'mg_ml'); ?> </h4> <table class="widefat lcwp_table lcwp_metabox_table"> <tr> <td class="lcwp_label_td"><?php _e('Soundcloud track URL', 'mg_ml'); ?> </td> <td class="lcwp_field_td"> <input type="text" value="<?php echo get_post_meta($post->ID, 'mg_soundcloud_url', true); ?> " name="mg_soundcloud_url" /> </td> <td><span class="info"><?php _e('Using this field, the selected tracklist <strong>will be ignored</strong>', 'mg_ml'); ?> </span></td> </tr> </table> <?php $tracks = mg_existing_sel(get_post_meta($post->ID, 'mg_audio_tracks', true)); ?> <h4><?php _e('Tracklist', 'mg_ml'); ?> </h4> <div id="audio_tracks_wrap"> <ul> <?php if (is_array($tracks)) { foreach ($tracks as $track_id) { $track_title = html_entity_decode(get_the_title($track_id), ENT_NOQUOTES, 'UTF-8'); // if WP > 3.9 use iconic font if ((double) substr(get_bloginfo('version'), 0, 3) >= 3.9) { $icon = '<div class="mg_audio_icon dashicons-media-audio dashicons"></div>'; } else { $icon = '<img src="' . MG_URL . '/img/audio_icon.png" />'; } echo ' <li id="mgtl_' . $track_id . '"> <input type="hidden" name="mg_audio_tracks[]" value="' . $track_id . '" /> ' . $icon . ' <span title="remove track"></span> <p title="' . $track_title . '">' . mg_excerpt($track_title, 25) . '</p> </li>'; } } else { echo '<p>' . __('No tracks selected', 'mg_ml') . ' .. </p>'; } ?> </ul> <br class="lcwp_clear" /> </div> <div style="clear: both; height: 20px;"></div> <div id="mg_audio_search_wrap"> <input type="text" placeholder="<?php _e('search', 'mg_ml'); ?> .." class="mg_search_field" /> <span class="mg_search_btn" title="search"></span> </div> <h4><?php _e('Choose tracks', 'mg_ml'); ?> <span class="mg_TB mg_upload_audio add-new-h2"><?php _e('Manage Tracks', 'mg_ml'); ?> </span></h4> <div id="audio_tracks_picker"></div> </div> <?php // link builder ?> <div id="mg_builder_link" <?php if ($main_type != 'link') { echo 'style="display: none;"'; } ?> > <h4><?php _e('Link Options', 'mg_ml'); ?> </h4> <?php echo mg_meta_opt_generator('link', $post); ?> </div> <?php // inline text options ?> <div id="mg_builder_inl_text" class="lcwp_form" <?php if ($main_type != 'inl_text') { echo 'style="display: none;"'; } ?> > <h4><?php _e('Inline Text Options', 'mg_ml'); ?> </h4> <?php echo mg_meta_opt_generator('inl_text', $post); ?> </div> </div> </div> <?php // security nonce ?> <input type="hidden" name="mg_item_noncename" value="<?php echo wp_create_nonce('lcwp_nonce'); ?> " /> <?php // ////////////////////// ?> <?php // SCRIPTS ?> <script src="<?php echo MG_URL; ?> /js/colpick/js/colpick.min.js" type="text/javascript"></script> <script src="<?php echo MG_URL; ?> /js/chosen/chosen.jquery.min.js" type="text/javascript"></script> <script src="<?php echo MG_URL; ?> /js/lc-switch/lc_switch.min.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(document).ready(function($) { /////////////////////////// // live preview link <?php if (!get_option('mg_disable_dl') && !empty($main_type) && !in_array($main_type, array('simple_img', 'link', 'inl_slider', 'inl_video', 'inl_text', 'spacer'))) { ?> var mg_live_preview = '<div class="misc-pub-section-last">\ <a href="<?php echo site_url(); ?> ?_escaped_fragment_=mg_ld=<?php echo $post->ID; ?> " target="_blank" id="mg_item_preview_link"><?php echo mg_sanitize_input(__("Item's lightbox preview", 'mg_ml')); ?> »</a></div>'; jQuery('#submitpost').parent().append(mg_live_preview); jQuery('#major-publishing-actions').addClass('misc-pub-section'); <?php } ?> // video upload and select jQuery(document).delegate('#mg_video_src', "click", function (e) { e.preventDefault(); var wp_selector = wp.media({ title: 'WP Videos Management', button: { text: '<?php echo mg_sanitize_input(__('Select')); ?> ' }, library : { type : 'video'}, multiple: false }) .on('select', function() { var selection = wp_selector.state().get('selection').first().toJSON(); var itemurl = selection.url; var video_pattern = /(^.*\.mp4|m4v|webm|ogv|wmv|flv*)/gi; if(itemurl.match(video_pattern) ) { jQuery('#mg_video_src').siblings('input[type=text]').val(itemurl); } else { alert('<?php echo mg_sanitize_input(__('Please select a valid video file for the WP player. Supported extensions:', 'mg_ml')); ?> mp4, m4v, webm, ogv, wmv, flv'); } }) .open(); }); //////////////////////// // custom file uploader for gallery and audio mg_TB = 0; // open tb and hide tabs jQuery('body').delegate('.mg_TB', 'click', function(e) { if( jQuery(this).hasClass('mg_upload_img') ) {mg_TB_type = 'img';} else {mg_TB_type = 'audio';} // thickBox if(typeof(wp.media) == 'undefined') { mg_TB = 1; post_id = jQuery('#post_ID').val(); if(mg_TB_type == 'img') { tb_show('', '<?php echo admin_url(); ?> media-upload.php?post_id='+post_id+'&type=image&TB_iframe=true'); } else { tb_show('', '<?php echo admin_url(); ?> media-upload.php?post_id='+post_id+'&type=audio&TB_iframe=true'); } setInterval(function() { if(mg_TB == 1) { if( jQuery('#TB_iframeContent').contents().find('#tab-type_url').is('hidden') ) { return false; } jQuery('#TB_iframeContent').contents().find('#tab-type_url').hide(); jQuery('#TB_iframeContent').contents().find('#tab-gallery').hide(); } }, 1); } // new lightbox management else { e.preventDefault(); var title = (mg_TB_type == 'img') ? 'Images' : 'Audio'; var subj = (mg_TB_type == 'img') ? 'image' : 'audio'; var custom_uploader = wp.media({ title: 'WP '+ title +' Management', button: { text: 'Ok' }, library : { type : subj}, multiple: false }) .on('select close', function() { if(mg_TB_type == 'img') { mg_load_img_picker(1); mg_sel_img_reload(); } else { mg_load_audio_picker(1); mg_sel_tracks_reload(); } }) .open(); } }); // reload picker on thickbox unload jQuery(window).bind('tb_unload', function() { if(mg_TB == 1) { if(mg_TB_type == 'img') { mg_load_img_picker(1); mg_sel_img_reload(); } else { mg_load_audio_picker(1); mg_sel_tracks_reload(); } mg_TB = 0; } }); //////////////////////// // audio mg_audio_pp = 15; mg_load_audio_picker(1); // reload the selected tracks to refresh their titles function mg_sel_tracks_reload() { var sel_tracks = jQuery.makeArray(); jQuery('#audio_tracks_wrap li').each(function() { var track_id = jQuery(this).children('input').val(); sel_tracks.push(track_id); }); jQuery('#audio_tracks_wrap ul').html('<div style="height: 30px;" class="lcwp_loading"></div>'); var data = { action: 'mg_sel_audio_reload', tracks: sel_tracks }; jQuery.post(ajaxurl, data, function(response) { jQuery('#audio_tracks_wrap ul').html(response); }); } // change tracks picker page jQuery('body').delegate('.mg_audio_pick_back, .mg_audio_pick_next', 'click', function() { var page = jQuery(this).attr('id').substr(4); mg_load_audio_picker(page); }); // change tracks per page jQuery('body').delegate('#mg_audio_pick_pp', 'change', function() { var pp = jQuery(this).val(); if( pp.length >= 2 ) { if( parseInt(pp) < 15 ) { mg_audio_pp = 15;} else {mg_audio_pp = pp;} mg_load_audio_picker(1); } }); // on search jQuery('body').delegate('#mg_audio_search_wrap .mg_search_btn', 'click', function() { mg_load_audio_picker(1); }); // load audio tracks picker function mg_load_audio_picker(page) { var data = { action: 'mg_audio_picker', page: page, per_page: mg_audio_pp, mg_search: jQuery('#mg_audio_search_wrap .mg_search_field').val() }; jQuery('#audio_tracks_picker').html('<div style="height: 30px;" class="lcwp_loading"></div>'); jQuery.post(ajaxurl, data, function(response) { jQuery('#audio_tracks_picker').html(response); }); return true; } // add audio track jQuery('body').delegate('#audio_tracks_picker li', 'click', function() { var track_id = jQuery(this).attr('id').substr(5); var track_tit = jQuery(this).children('p').text(); if( jQuery('#audio_tracks_wrap ul > p').size() > 0 ) {jQuery('#audio_tracks_wrap ul').empty();} <?php // if WP > 3.9 use iconic font if ((double) substr(get_bloginfo('version'), 0, 3) >= 3.9) { $icon = '<div class="mg_audio_icon dashicons-media-audio dashicons"></div>'; } else { $icon = '<img src="' . MG_URL . '/img/audio_icon.png" />'; } ?> if( jQuery('#audio_tracks_wrap li#mgtl_'+ track_id).size() == 0) { jQuery('#audio_tracks_wrap ul').append('\ <li id="mgtl_'+ track_id +'">\ <input type="hidden" name="mg_audio_tracks[]" value="'+ track_id +'" />\ <?php echo $icon; ?> \ <span title="remove track"></span>\ <p>'+ track_tit +'</p>\ </li>'); mg_sort(); } }); //////////////////////// // images mg_img_pp = 15; mg_load_img_picker(1); // reload the selected images to check changes function mg_sel_img_reload() { var sel_img = jQuery.makeArray(); jQuery('#gallery_img_wrap li').each(function() { var img_id = jQuery(this).children('input').val(); sel_img.push(img_id); }); jQuery('#gallery_img_wrap ul').html('<div style="height: 30px;" class="lcwp_loading"></div>'); var data = { action: 'mg_sel_img_reload', images: sel_img }; jQuery.post(ajaxurl, data, function(response) { jQuery('#gallery_img_wrap ul').html(response); }); } // change slider imges picker page jQuery('body').delegate('.mg_img_pick_back, .mg_img_pick_next', 'click', function() { var page = jQuery(this).attr('id').substr(4); mg_load_img_picker(page); }); // change images per page jQuery('body').delegate('#mg_img_pick_pp', 'change', function() { var pp = jQuery(this).val(); if( pp.length >= 2 ) { if( parseInt(pp) < 15 ) { mg_img_pp = 15;} else {mg_img_pp = pp;} mg_load_img_picker(1); } }); // on search jQuery('body').delegate('#mg_img_search_wrap .mg_search_btn', 'click', function() { mg_load_img_picker(1); }); // load slider images picker function mg_load_img_picker(page) { var data = { action: 'mg_img_picker', page: page, per_page: mg_img_pp, mg_search: jQuery('#mg_img_search_wrap .mg_search_field').val() }; jQuery('#gallery_img_picker').html('<div style="height: 30px;" class="lcwp_loading"></div>'); jQuery.post(ajaxurl, data, function(response) { jQuery('#gallery_img_picker').html(response); }); return true; } // add slider images jQuery('body').delegate('#gallery_img_picker li', 'click', function() { var img_id = jQuery(this).children('img').attr('id'); var img_url = jQuery(this).children('img').attr('src'); if( jQuery('#gallery_img_wrap ul > p').size() > 0 ) {jQuery('#gallery_img_wrap ul').empty();} jQuery('#gallery_img_wrap ul').append('\ <li>\ <input type="hidden" name="mg_slider_img[]" value="'+ img_id +'" />\ <img src="'+ img_url +'" />\ <span title="remove image"></span>\ </li>'); mg_sort(); }); //////////////////////// // images & audio // remove jQuery('body').delegate('#gallery_img_wrap ul li span, #audio_tracks_wrap ul li span', 'click', function() { jQuery(this).parent().remove(); if( jQuery('#gallery_img_wrap ul li').size() == 0 ) {jQuery('#gallery_img_wrap ul').html('<p><?php echo mg_sanitize_input(__('No images selected', 'mg_ml')); ?> .. </p>');} if( jQuery('#audio_tracks_wrap ul li').size() == 0 ) {jQuery('#audio_tracks_wrap ul').html('<p><?php echo mg_sanitize_input(__('No tracks selected', 'mg_ml')); ?> .. </p>');} }); // sort function mg_sort() { jQuery( "#gallery_img_wrap ul, #audio_tracks_wrap ul" ).sortable(); jQuery( "#gallery_img_wrap ul, #audio_tracks_wrap ul" ).disableSelection(); } mg_sort(); //////////////////////// // toggle elements jQuery('body').delegate('#mg_main_type', "change", function() { var main_type = jQuery(this).val(); // layout toggle if( jQuery.inArray(main_type, ['simple_img','link','lb_text','inl_slider','inl_video','inl_text','spacer']) == -1 ) { jQuery('#mg_layout_wrap').slideDown(); } else { jQuery('#mg_layout_wrap').slideUp(); } // full img max-height toggle if( jQuery.inArray(main_type, ['single_img', 'audio']) != -1) { jQuery('#mg_img_maxheight_wrap').slideDown(); } else { jQuery('#mg_img_maxheight_wrap').slideUp(); } // main opt toggle jQuery('#mg_cust_opt_wrap > div').each(function() { if(main_type == 'single_img') {var copt_id = 'img';} else {var copt_id = main_type;} if( jQuery(this).attr('id') == 'mg_cust_opt_' + copt_id) { jQuery(this).slideDown(); } else { jQuery(this).slideUp(); } }); // type builder toggle jQuery('#mg_builder_wrap > div').each(function() { if( jQuery(this).attr('id') == 'mg_builder_' + main_type) { jQuery(this).slideDown(); } else { jQuery(this).slideUp(); } }); // slider lightbox option if(main_type == 'img_gallery') { jQuery('#mg_lb_slider_opt').slideDown(); } else { jQuery('#mg_lb_slider_opt').slideUp(); } // self-hosted video trigger if(main_type == 'video') { jQuery('#mg_video_src, .lb_video_info').show(); } //// exception for inline video if(main_type == 'inl_video') { jQuery('#mg_builder_video').slideDown(); jQuery('#mg_video_src, .lb_video_info').hide(); } //// exception for inline slider if(main_type == 'inl_slider') { jQuery('#mg_builder_img_gallery, #mg_inl_slider_opt').slideDown(); } else {jQuery('#mg_inl_slider_opt').slideUp();} }); // fix for chosen overflow jQuery('#wpbody, #wpbody-content').css('overflow', 'visible'); // fix for subcategories jQuery('#mg_item_categories-adder').remove(); }); </script> <?php return true; }
function mg_sel_img_reload() { require_once MG_DIR . '/functions.php'; if (!isset($_POST['images'])) { $images = array(); } else { $images = $_POST['images']; } // get the titles and recreate tracks $images = mg_existing_sel($images); $new_img = ''; if (!$images) { $new_img = '<p>' . __('No images selected', 'mg_ml') . ' .. </p>'; } else { foreach ($images as $img_id) { $new_img .= ' <li> <input type="hidden" name="mg_slider_img[]" value="' . $img_id . '" /> <img src="' . mg_thumb_src($img_id, 90, 90) . '" /> <span title="remove image"></span> </li> '; } } echo $new_img; die; }
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); }
function mg_lb_nav_code($prev_next = array('prev' => 0, 'next' => 0), $layout = 'inside') { if (!$prev_next['prev'] && !$prev_next['next'] || $layout == 'hidden') { return ''; } // thumb sizes for layout switch ($layout) { case 'inside': $ts = array('w' => 60, 'h' => 60); break; case 'top': $ts = array('w' => 150, 'h' => 150); break; case 'side': $ts = array('w' => 340, 'h' => 120); break; } $code = ''; foreach ($prev_next as $dir => $item_id) { $active = !empty($item_id) ? 'mg_nav_active' : ''; $side_class = $layout == 'side' ? 'mg_side_nav' : ''; $side_vis = $layout == 'side' ? 'style="display: none;"' : ''; $thumb_center = get_post_meta($item_id, 'mg_thumb_center', true) ? get_post_meta($item_id, 'mg_thumb_center', true) : 'c'; $code .= ' <div class="mg_nav_' . $dir . ' mg_' . $layout . '_nav_' . $dir . ' ' . $active . ' ' . $side_class . '" rel="' . $item_id . '" ' . $side_vis . '> <i></i>'; if ($layout == 'side') { $code .= '<span></span>'; } if (!empty($item_id)) { $title = get_the_title($item_id); if ($layout == 'inside') { $code .= '<div>' . $title . '</div>'; } elseif ($layout == 'top') { $thumb = mg_thumb_src(get_post_thumbnail_id($item_id), $ts['w'], $ts['h'], 80, $thumb_center); $code .= '<div>' . $title . '<img src="' . $thumb . '" alt="' . mg_sanitize_input($title) . '" /></div>'; } elseif ($layout == 'side') { $thumb = mg_thumb_src(get_post_thumbnail_id($item_id), $ts['w'], $ts['h'], 70, $thumb_center); $code .= '<div>' . $title . '</div><img src="' . $thumb . '" alt="' . mg_sanitize_input($title) . '" />'; } } $code .= '</div>'; } return $code; }