Esempio n. 1
0
 /**
  * Returns a post language code reading it from WPML tables.
  *
  * @param int $post_id
  *
  * @return bool|string Either the language code string (e.g. `en`) or `false` on failure.
  */
 private function get_post_language_code_from_db($post_id)
 {
     $language_information = wpml_get_language_information(null, $post_id);
     if (empty($language_information) || empty($language_information['language_code'])) {
         return false;
     }
     return $language_information['language_code'];
 }
Esempio n. 2
0
 function wpml_jetpack_widget_get_top_posts($posts, $post_ids, $count)
 {
     global $sitepress;
     foreach ($posts as $k => $post) {
         $lang_information = wpml_get_language_information($post['post_id']);
         $post_language = substr($lang_information['locale'], 0, 2);
         if ($post_language !== $sitepress->get_current_language()) {
             unset($posts[$k]);
         }
     }
     return $posts;
 }
 /**
  * Assign linked posts managed by The Events Calendar a language.
  *
  * We use the filter as an action to assign linked posts a language.
  * WPML will not "see" posts that have not a language assigned: here we make sure that linked posts like
  * venues and organizers will be assigned the language of the event they are being linked to.
  *
  * @param int    $id               The linked post ID; this would be `null` by default but we know TEC is inserting
  *                                 the post at priority 10.
  * @param array  $data             Unused, an array of data representing the linked post submission.
  * @param string $linked_post_type The linked post type, e.g. `tribe_venue` or `tribe_organizer`.
  * @param string $post_status      Unused, the linked post type post status.
  * @param int    $event_id         The post ID of the event this post is linked to; this will be null for newly created events.
  *
  * @return int The untouched linked post ID.
  */
 public function filter_tribe_events_linked_post_create($id, $data, $linked_post_type, $post_status, $event_id)
 {
     if (empty($id) || empty($event_id)) {
         return $id;
     }
     $event_language_info = wpml_get_language_information($event_id);
     $language_code = !empty($event_language_info['language_code']) ? $event_language_info['language_code'] : ICL_LANGUAGE_CODE;
     $added = wpml_add_translatable_content('post_' . $linked_post_type, $id, $language_code);
     if (WPML_API_ERROR === $added) {
         $log = new Tribe__Log();
         $entry = "Could not set language for linked post type '{$linked_post_type}' with id '{$id}' to '{$language_code}'";
         $log->log_error($entry, __CLASS__);
     }
     return $id;
 }
Esempio n. 4
0
        function jig_init_shortcode($atts)
        {
            if ($this->settings['take_over_gallery'] === 'hide') {
                remove_shortcode('gallery');
                add_shortcode('gallery', array($this, 'jig_blank_gallery'));
            }
            global $justified_image_grid_instance;
            $justified_image_grid_instance++;
            $jig_id = $justified_image_grid_instance;
            global $post;
            extract(shortcode_atts(array('preset' => NULL, 'mobile_preset' => NULL), $atts));
            if (!empty($mobile_preset)) {
                if (!class_exists("Mobile_Detect")) {
                    include 'mobiledetect.php';
                }
                $detect = new Mobile_Detect();
                if ($detect->isMobile()) {
                    $preset = $mobile_preset;
                }
            }
            if (!empty($preset)) {
                // takes the default values that are overridden by the preset's values, this ensures a clean preset view
                // BUT overrides with the protected values (system settings) AND the 'settings_flexbile'
                $this->settings_backup = $this->settings;
                if (substr($preset, 0, 1) !== 'c') {
                    if (!empty($this->presets[$preset])) {
                        $this->settings = array_merge(array_merge($this->defaults, $this->presets[$preset]), $this->settings_override);
                    }
                } else {
                    if (!empty($this->custom_presets[(int) substr($preset, 1)])) {
                        $this->settings = array_merge(array_merge($this->defaults, $this->custom_presets[(int) substr($preset, 1)]), $this->settings_override);
                    }
                }
            }
            if (function_exists('icl_translate')) {
                $icl_context = 'admin_texts_plugin_' . self::PAGE_NAME;
                $icl_name = '[' . self::SETTINGS_NAME . ']';
                // NOT shortcode attributes
                $please_log_in = icl_translate($icl_context, $icl_name . 'please_log_in', $this->settings['please_log_in']);
                $view_rest_of_gallery = icl_translate($icl_context, $icl_name . 'view_rest_of_gallery', $this->settings['view_rest_of_gallery']);
                $download_link_text = icl_translate($icl_context, $icl_name . 'download_link_text', $this->settings['download_link_text']);
                $flickr_link_text = icl_translate($icl_context, $icl_name . 'flickr_link_text', $this->settings['flickr_link_text']);
                $instagram_link_text = icl_translate($icl_context, $icl_name . 'instagram_link_text', $this->settings['instagram_link_text']);
                $developer_link_text = icl_translate($icl_context, $icl_name . 'developer_link_text', $this->settings['developer_link_text']);
                $notice_before = icl_translate($icl_context, $icl_name . 'text_before', $this->settings['text_before']);
                $notice_after = icl_translate($icl_context, $icl_name . 'text_after', $this->settings['text_after']);
                // shortcode attributes
                $load_more_text = icl_translate($icl_context, $icl_name . 'load_more_text', $this->settings['load_more_text']);
                $load_more_count_text = icl_translate($icl_context, $icl_name . 'load_more_count_text', $this->settings['load_more_count_text']);
                $filter_all_text = icl_translate($icl_context, $icl_name . 'filter_all_text', $this->settings['filter_all_text']);
                $l2_filter_all_text = icl_translate($icl_context, $icl_name . 'l2_filter_all_text', $this->settings['l2_filter_all_text']);
                $rss_link_text = icl_translate($icl_context, $icl_name . 'rss_link_text', $this->settings['rss_link_text']);
            } else {
                $please_log_in = $this->settings['please_log_in'];
                $view_rest_of_gallery = $this->settings['view_rest_of_gallery'];
                $download_link_text = $this->settings['download_link_text'];
                $flickr_link_text = $this->settings['flickr_link_text'];
                $instagram_link_text = $this->settings['instagram_link_text'];
                $developer_link_text = $this->settings['developer_link_text'];
                $notice_before = $this->settings['text_before'];
                $notice_after = $this->settings['text_after'];
                $load_more_text = $this->settings['load_more_text'];
                $load_more_count_text = $this->settings['load_more_count_text'];
                $filter_all_text = $this->settings['filter_all_text'];
                $l2_filter_all_text = $this->settings['l2_filter_all_text'];
                $rss_link_text = $this->settings['rss_link_text'];
            }
            extract(shortcode_atts(array('ids' => '', 'thumbs_spacing' => $this->settings['thumbs_spacing'], 'animation_speed' => $this->settings['animation_speed'], 'row_height' => $this->settings['row_height'], 'height_deviation' => $this->settings['height_deviation'], 'mobile_row_height' => $this->settings['mobile_row_height'], 'mobile_height_dev' => $this->settings['mobile_height_dev'], 'limit' => $this->settings['limit'], 'hidden_limit' => $this->settings['hidden_limit'], 'load_more' => $this->settings['load_more'], 'load_more_mobile' => $this->settings['load_more_mobile'], 'load_more_limit' => $this->settings['load_more_limit'], 'load_more_text' => $load_more_text, 'load_more_count_text' => $load_more_count_text, 'load_more_offset' => $this->settings['load_more_offset'], 'load_more_auto_width' => $this->settings['load_more_auto_width'], 'max_rows' => $this->settings['max_rows'], 'custom_width' => $this->settings['custom_width'], 'width_mode' => $this->settings['width_mode'], 'last_row' => $this->settings['last_row'], 'aspect_ratio' => $this->settings['aspect_ratio'], 'disable_cropping' => $this->settings['disable_cropping'], 'randomize_width' => $this->settings['randomize_width'], 'link_target' => $this->settings['link_target'], 'orderby' => $this->settings['orderby'], 'filterby' => $this->settings['filterby'], 'filter_style' => $this->settings['filter_style'], 'filter_all_text' => $filter_all_text, 'filter_orderby' => $this->settings['filter_orderby'], 'filter_custom_order' => $this->settings['filter_custom_order'], 'filter_min_count' => $this->settings['filter_min_count'], 'filter_top_x' => $this->settings['filter_top_x'], 'filter_all_button' => $this->settings['filter_all_button'], 'filter_multiple' => $this->settings['filter_multiple'], 'l2_filterby' => $this->settings['l2_filterby'], 'l2_filter_style' => $this->settings['l2_filter_style'], 'l2_filter_all_text' => $l2_filter_all_text, 'l2_filter_orderby' => $this->settings['l2_filter_orderby'], 'l2_filter_custom_order' => $this->settings['l2_filter_custom_order'], 'l2_filter_min_count' => $this->settings['l2_filter_min_count'], 'l2_filter_top_x' => $this->settings['l2_filter_top_x'], 'l2_filter_all_button' => $this->settings['l2_filter_all_button'], 'l2_filter_multiple' => $this->settings['l2_filter_multiple'], 'allow_animated_gifs' => $this->settings['allow_animated_gifs'], 'allow_transp_pngs' => $this->settings['allow_transp_pngs'], 'process_shortcodes' => $this->settings['process_shortcodes'], 'wrap_text' => $this->settings['wrap_text'], 'reading_direction' => $this->settings['reading_direction'], 'link_class' => $this->settings['link_class'], 'link_rel' => $this->settings['link_rel'], 'link_attribute_name' => $this->settings['link_attribute_name'], 'link_attribute_value' => $this->settings['link_attribute_value'], 'use_link_attributes' => $this->settings['use_link_attributes'], 'link_title_field' => $this->settings['link_title_field'], 'img_alt_field' => $this->settings['img_alt_field'], 'lightbox_custom_field' => $this->settings['lightbox_custom_field'], 'prettyphoto_social' => $this->settings['prettyphoto_social'], 'pp_social_buttons' => $this->settings['pp_social_buttons'], 'prettyphoto_theme' => $this->settings['prettyphoto_theme'], 'prettyphoto_analytics' => $this->settings['prettyphoto_analytics'], 'prettyphoto_title_pos' => $this->settings['prettyphoto_title_pos'], 'photoswipe_social' => $this->settings['photoswipe_social'], 'ps_social_buttons' => $this->settings['ps_social_buttons'], 'magnific_zoom' => $this->settings['magnific_zoom'], 'private_lightbox' => $this->settings['private_lightbox'], 'load_bundled_lightbox' => $this->settings['load_bundled_lightbox'], 'title_field' => $this->settings['title_field'], 'caption_field' => $this->settings['caption_field'], 'caption_custom_field' => $this->settings['caption_custom_field'], 'custom_link_follow' => $this->settings['custom_link_follow'], 'only_for_logged_in' => $this->settings['only_for_logged_in'], 'caption' => $this->settings['caption'], 'mobile_caption' => $this->settings['mobile_caption'], 'caption_opacity' => $this->settings['caption_opacity'], 'caption_bg_color' => $this->settings['caption_bg_color'], 'caption_match_width' => $this->settings['caption_match_width'], 'caption_text_color' => $this->settings['caption_text_color'], 'caption_height' => $this->settings['caption_height'], 'mobile_caption_height' => $this->settings['mobile_caption_height'], 'caption_title_size' => $this->settings['caption_title_size'], 'caption_desc_size' => $this->settings['caption_desc_size'], 'caption_align' => $this->settings['caption_align'], 'v_center_captions' => $this->settings['v_center_captions'], 'custom_fonts' => $this->settings['custom_fonts'], 'caption_text_shadow' => $this->settings['caption_text_shadow'], 'gradient_caption_bg' => $this->settings['gradient_caption_bg'], 'overlay' => $this->settings['overlay'], 'mobile_overlay' => $this->settings['mobile_overlay'], 'overlay_color' => $this->settings['overlay_color'], 'overlay_opacity' => $this->settings['overlay_opacity'], 'overlay_icon' => $this->settings['overlay_icon'], 'overlay_icon_opacity' => $this->settings['overlay_icon_opacity'], 'overlay_icon_url' => $this->settings['overlay_icon_url'], 'overlay_icon_retina' => $this->settings['overlay_icon_retina'], 'outer_shadow' => $this->settings['outer_shadow'], 'inner_shadow' => $this->settings['inner_shadow'], 'outer_border_width' => $this->settings['outer_border_width'], 'outer_border_color' => $this->settings['outer_border_color'], 'outer_border' => $this->settings['outer_border'], 'middle_border_width' => $this->settings['middle_border_width'], 'middle_border_color' => $this->settings['middle_border_color'], 'middle_border' => $this->settings['middle_border'], 'inner_border_width' => $this->settings['inner_border_width'], 'inner_border_color' => $this->settings['inner_border_color'], 'inner_border' => $this->settings['inner_border'], 'inner_border_animate' => $this->settings['inner_border_animate'], 'desaturate' => '', 'specialfx' => $this->settings['specialfx'], 'mobile_specialfx' => $this->settings['mobile_specialfx'], 'specialfx_type' => $this->settings['specialfx_type'], 'specialfx_blend' => $this->settings['specialfx_blend'], 'caption_fx_visibility' => $this->settings['caption_fx_visibility'], 'specialfx_options' => $this->settings['specialfx_options'], 'lightbox' => $this->settings['lightbox'], 'mobile_lightbox' => $this->settings['mobile_lightbox'], 'lightbox_max_size' => $this->settings['lightbox_max_size'], 'min_height' => $this->settings['min_height'], 'loading_background' => $this->settings['loading_background'], 'link_override' => '', 'separator_character' => $this->settings['separator_character'], 'show_text_before' => 'yes', 'show_text_after' => 'yes', 'margin' => $this->settings['margin'], "retina_ready" => $this->settings['retina_ready'], 'quality' => $this->settings['quality'], 'retina_quality' => $this->settings['retina_quality'], 'min_retina_quality' => $this->settings['min_retina_quality'], 'max_retina_density' => $this->settings['max_retina_density'], 'timthumb_path' => $this->settings['timthumb_path'], 'timthumb_crop_zone' => $this->settings['timthumb_crop_zone'], 'use_timthumb' => $this->settings['use_timthumb'], 'mouse_disable' => $this->settings['mouse_disable'], 'disable_mobile_hover' => $this->settings['disable_mobile_hover'], 'error_checking' => $this->settings['error_checking'], 'id' => !empty($post->ID) ? $post->ID : '', 'nggallery' => '', 'ngalbum' => '', 'ng_gallery' => '', 'ng_album' => '', 'ng_pics' => '', 'ng_tags_gallery' => '', 'ng_tags_album' => '', 'ng_recent_images' => '', 'ng_random_images' => '', 'ng_search_query' => '', 'ng_search_options' => '', 'ng_count' => $this->settings['ng_count'], 'ng_lightbox_gallery' => $this->settings['ng_lightbox_gallery'], 'ng_description' => $this->settings['ng_description'], 'ng_intersect_tags' => $this->settings['ng_intersect_tags'], 'ng_narrow_by_tags' => '', 'ng_display_tags' => $this->settings['ng_display_tags'], 'ng_breadcrumb' => 'no', 'ng_bc_separator' => 'default', 'ng_bc_base' => __('You are here:', 'jig_td'), 'ng_bc_home' => 'post_title', 'ng_bc_home_text' => __('Home', 'jig_td'), 'ng_bc_home_clickable' => 'yes', 'ng_bc_last_clickable' => 'no', 'ng_bc_top_level' => 'yes', 'ng_bc_add_separator' => 'no', 'nextgen_cf_link' => $this->settings['nextgen_cf_link'], 'exclude' => '', 'include' => '', 'image_tags' => '', 'image_categories' => '', 'image_taxonomy' => '', 'image_tax_term' => '', 'parent_id' => '', 'facebook_id' => '', 'facebook_album' => '', 'facebook_image_size' => $this->settings['facebook_image_size'], 'facebook_caching' => $this->settings['facebook_caching'], 'facebook_count' => $this->settings['facebook_count'], 'facebook_description' => $this->settings['facebook_description'], 'fb_lightbox_album' => $this->settings['fb_lightbox_album'], 'fb_actual_cover_photo' => $this->settings['fb_actual_cover_photo'], 'fb_album_exclude' => 'no', 'fb_breadcrumb' => 'yes', 'fb_bc_separator' => 'default', 'fb_bc_home_text' => '', 'flickr_user' => '', 'flickr_photostream' => '', 'flickr_favorites' => '', 'flickr_group' => '', 'flickr_photoset' => '', 'flickr_collection' => '', 'flickr_gallery' => '', 'flickr_search_text' => '', 'flickr_search_tags' => '', 'flickr_search_tags_m' => '', 'flickr_search_user' => '', 'flickr_search_group' => '', 'flickr_search_sort' => 'date-posted-desc', 'flickr_search_license' => '', 'flickr_search_geo' => '', 'flickr_caching' => $this->settings['flickr_caching'], 'flickr_count' => $this->settings['flickr_count'], 'flickr_description' => $this->settings['flickr_description'], 'flickr_lightbox_set' => $this->settings['flickr_lightbox_set'], 'flickr_breadcrumb' => 'yes', 'flickr_bc_separator' => 'default', 'flickr_bc_home_text' => '', 'instagram_feed' => '', 'instagram_recents' => '', 'instagram_liked' => '', 'instagram_tag' => '', 'instagram_location' => '', 'instagram_tag_filter' => '', 'instagram_tag_mode' => 'or', 'instagram_blacklist' => $this->settings['instagram_blacklist'], 'instagram_caching' => $this->settings['instagram_caching'], 'instagram_show_user' => $this->settings['instagram_show_user'], 'instagram_link' => $this->settings['instagram_link'], 'rss_url' => '', 'href' => '', 'rss_links_to' => $this->settings['rss_links_to'], 'rss_description' => $this->settings['rss_description'], 'rss_excerpt_length' => $this->settings['rss_excerpt_length'], 'rss_excerpt_ending' => $this->settings['rss_excerpt_ending'], 'rss_link' => $this->settings['rss_link'], 'rss_link_text' => $rss_link_text, 'rss_caching' => $this->settings['rss_caching'], 'developer_link' => $this->settings['developer_link'], 'download_link' => $this->settings['download_link'], 'flickr_link' => $this->settings['flickr_link'], 'recent_posts' => 'no', 'post_ids' => '', 'post_ids_exclude' => '', 'recents_description' => 'nothing', 'recents_description_2' => 'nothing', 'recents_description_3' => 'nothing', 'post_metadata_fields' => '', 'recents_title_override' => '', 'recents_exclude' => '', 'recents_include' => '', 'recents_tags' => '', 'recents_filter_tax' => '', 'recents_filter_term' => '', 'recents_author' => '', 'recents_placeholder' => '', 'recents_post_type' => 'post', 'recents_link_to' => 'post', 'recents_link' => 'no', 'recents_link_text' => __('Read more', 'jig_td'), 'recents_custom_links' => 'no', 'recents_sticky' => '', 'recents_date_range' => '', 'recents_last_x_days' => '', 'excerpt_length' => 20, 'excerpt_ending' => ' [...]', 'author_prefix' => __('by', 'jig_td'), 'comments_text' => __('comment', 'jig_td') . ' | ' . __('comments', 'jig_td'), 'recents_parent_id' => '', 'recents_tree_depth' => '', 'for_xml_sitemap' => 'no'), $atts));
            if ($show_text_before !== 'yes') {
                $notice_before = '';
            }
            if ($show_text_after !== 'yes') {
                $notice_after = '';
            }
            if ($only_for_logged_in == 'yes' && is_user_logged_in() == false) {
                return $this->frontend_stop(trim(__($please_log_in, 'jig_td')), false);
            }
            if ($private_lightbox == 'yes' && is_user_logged_in() == false) {
                $lightbox = 'links-off';
                $mobile_lightbox = 'links-off';
            }
            if ($this->settings['blog_view_limit'] && is_numeric($this->settings['blog_view_limit']) && !is_singular()) {
                $limit = (int) $this->settings['blog_view_limit'];
                $hidden_limit = '';
                if (__($view_rest_of_gallery, 'jig_td') !== '') {
                    $notice_after .= '<div id="jig' . $jig_id . '-viewRestOfGallery"><a href="' . get_permalink(get_the_ID()) . '">' . __($view_rest_of_gallery, 'jig_td') . '</a></div>';
                    $gallery_truncated_with_message = true;
                }
            }
            if ($caption_custom_field !== '') {
                $caption_custom_field_array = explode(',', str_replace(', ', ',', $caption_custom_field));
                if ($title_field == 'custom' && !empty($caption_custom_field_array)) {
                    $title_field = 'custom_field_' . array_shift($caption_custom_field_array);
                }
                if ($caption_field == 'custom' && !empty($caption_custom_field_array)) {
                    $caption_field = 'custom_field_' . array_shift($caption_custom_field_array);
                }
            }
            if ($lightbox_custom_field !== '') {
                $lightbox_custom_field_array = explode(',', str_replace(', ', ',', $lightbox_custom_field));
                if ($link_title_field == 'custom' && !empty($lightbox_custom_field_array)) {
                    $link_title_field = 'custom_field_' . array_shift($lightbox_custom_field_array);
                }
                if ($img_alt_field == 'custom' && !empty($lightbox_custom_field_array)) {
                    $img_alt_field = 'custom_field_' . array_shift($lightbox_custom_field_array);
                }
            }
            $photon_activated = class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules()) && function_exists('jetpack_photon_url');
            $carousel_activated = $lightbox == 'carousel' && (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('carousel', Jetpack::get_active_modules()) && class_exists('Jetpack_Carousel') || class_exists('CarouselWithoutJetpack'));
            if ($lightbox == 'carousel' && $carousel_activated === false) {
                $lightbox = 'prettyphoto';
            }
            if ($filterby !== 'off' || $l2_filterby !== 'off') {
                global $justified_image_grid_filtering_css_needed;
                $justified_image_grid_filtering_css_needed = true;
            }
            if (!empty($link_attribute_value)) {
                $link_attribute_value = str_replace('*instance*', $jig_id, $link_attribute_value);
            }
            $separator_character = !empty($separator_character) ? ' ' . $separator_character . ' ' : '';
            $gallery_type = 'wp_post_gallery';
            if ($hidden_limit) {
                $real_limit = $limit;
                $limit = $hidden_limit;
            }
            if ($nggallery !== '' && $ng_gallery == '') {
                $ng_gallery = $nggallery;
            }
            if ($ngalbum !== '' && $ng_album == '') {
                $ng_album = $ngalbum;
            }
            if ($id !== '' && $id != $post->ID) {
                $gallery_type = 'wp_post_gallery';
            } elseif ($recent_posts === 'yes') {
                $gallery_type = 'wp_recent_posts';
            } elseif ($ng_gallery !== '' || $ng_album !== '' || $ng_pics !== '' || $ng_tags_gallery !== '' || $ng_tags_album !== '' || $ng_recent_images !== '' || $ng_random_images !== '' || $ng_search_query !== '') {
                $gallery_type = 'nextgen';
            } elseif ($facebook_id && $facebook_album) {
                $gallery_type = 'facebook';
            } elseif ($flickr_photostream !== '' || $flickr_favorites !== '' || $flickr_user !== '' && ($flickr_group !== '' || $flickr_photoset !== '' || $flickr_collection !== '' || $flickr_gallery !== '') || $flickr_search_text !== '' || $flickr_search_tags !== '') {
                $gallery_type = 'flickr';
            } elseif ($instagram_feed !== '' || $instagram_recents !== '' || $instagram_liked !== '' || $instagram_tag !== '' || $instagram_location !== '') {
                $gallery_type = 'instagram';
            } elseif ($rss_url !== '') {
                $gallery_type = 'rss';
            }
            if ($for_xml_sitemap === 'yes' && ($gallery_type === 'flickr' || $gallery_type === 'facebook' || $gallery_type === 'instagram' || $gallery_type === 'rss')) {
                return $this->frontend_stop();
            }
            if ($lightbox == 'carousel' && $gallery_type !== "wp_post_gallery" && $gallery_type !== "wp_recent_posts") {
                $lightbox = 'prettyphoto';
            }
            // switch link rel to legacy mode to have old users still benefit from the unified hash
            if ($link_rel == 'auto' && $lightbox == 'prettyphoto' && $mobile_lightbox == 'photoswipe') {
                $link_rel = 'prettyPhoto[' . $jig_id . ']';
            } elseif ($link_rel == '') {
                $link_rel = 'jig[*instance*]';
            }
            $disable_hover = 'no';
            if ($mobile_lightbox !== 'no' || $mobile_caption !== 'same' || $mobile_overlay !== 'same' || $mobile_specialfx !== 'same' || $disable_mobile_hover !== 'no' || $load_more_mobile !== 'no' || $mobile_row_height !== '' || $mobile_height_dev !== '' || $mobile_caption_height !== '') {
                if (!class_exists("Mobile_Detect")) {
                    include 'mobiledetect.php';
                }
                if (empty($detect)) {
                    $detect = new Mobile_Detect();
                }
                if ($detect->isMobile()) {
                    if ($mobile_lightbox !== 'no') {
                        $lightbox = $mobile_lightbox;
                    }
                    if ($mobile_caption !== 'same') {
                        $caption = $mobile_caption;
                    }
                    if ($mobile_overlay !== 'same') {
                        $overlay = $mobile_overlay;
                    }
                    if ($mobile_specialfx !== 'same') {
                        $specialfx = $mobile_specialfx;
                    }
                    if ($disable_mobile_hover !== 'no') {
                        $disable_hover = $disable_mobile_hover;
                    }
                    if ($use_link_attributes == 'desktop') {
                        $link_class = '';
                        $link_rel = 'jig[*instance*]';
                        $link_attribute_name = '';
                        $link_attribute_value = '';
                    }
                    if ($this->settings['jquery_mobile'] == 'yes' && ($link_rel == 'auto' || $link_rel == 'jig[*instance*]')) {
                        $link_rel .= ' external';
                    }
                    if ($load_more_mobile !== 'no' && $load_more_mobile !== 'yes') {
                        $load_more = $load_more_mobile;
                    }
                    $row_height = $mobile_row_height !== '' ? $mobile_row_height : $row_height;
                    $height_deviation = $mobile_height_dev !== '' ? $mobile_height_dev : $height_deviation;
                    $caption_height = $mobile_caption_height !== '' ? $mobile_caption_height : $caption_height;
                } else {
                    if ($load_more_mobile == 'yes') {
                        $load_more = 'off';
                    }
                    if ($use_link_attributes == 'mobile') {
                        $link_class = '';
                        $link_rel = 'jig[*instance*]';
                        $link_attribute_name = '';
                        $link_attribute_value = '';
                    }
                }
            }
            if ($load_more !== 'off') {
                $max_rows = '';
            }
            $this->max_height = $max_height = $row_height + $height_deviation;
            $title_needed = $title_field == 'title' || $caption_field == 'title' || $link_title_field == 'title' || $img_alt_field == 'title' || $lightbox == 'carousel';
            $caption_needed = $title_field == 'caption' || $caption_field == 'caption' || $link_title_field == 'caption' || $img_alt_field == 'caption' || $lightbox == 'carousel';
            $description_needed = $title_field == 'description' || $caption_field == 'description' || $link_title_field == 'description' || $img_alt_field == 'description' || $lightbox == 'carousel';
            $alternate_needed = $title_field == 'alternate' || $caption_field == 'alternate' || $link_title_field == 'alternate' || $img_alt_field == 'alternate' || $lightbox == 'carousel';
            switch ($gallery_type) {
                case 'wp_post_gallery':
                    add_filter('editor_max_image_size', array($this, 'jig_bypass_editor_max_image_size'));
                    $order = 'ASC';
                    switch ($orderby) {
                        case 'title_asc':
                            $orderby = 'title';
                            break;
                        case 'title_desc':
                            $orderby = 'title';
                            $order = 'DESC';
                            break;
                        case 'date_desc':
                            $orderby = 'date';
                            $order = 'DESC';
                            break;
                        case 'date_asc':
                            $orderby = 'date';
                            break;
                        case 'custom':
                            $orderby = 'menu_order';
                            break;
                        default:
                    }
                    if ($limit === '' || $limit === '0') {
                        $limit = -1;
                    }
                    // 'featured' word gets replaced with actual ID
                    if (!empty($exclude) && !empty($post->ID)) {
                        $exclude = str_replace('featured', get_post_thumbnail_id($post->ID), $exclude);
                    }
                    if ($ids !== '') {
                        // if there is a list of image ids
                        if ($orderby === 'menu_order') {
                            $orderby = 'post__in';
                        }
                        if ($ids !== '*') {
                            if (strpos($ids, '-') !== false) {
                                $ids_exploded = explode(',', $ids);
                                foreach ($ids_exploded as &$single_id) {
                                    if (strpos($single_id, '-') !== false) {
                                        $id_range = explode('-', $single_id);
                                        $single_id = implode(',', range($id_range[0], $id_range[1]));
                                    }
                                }
                                $ids = implode(',', $ids_exploded);
                            }
                            $args = array('include' => $ids, 'post_status' => 'any', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby);
                        } else {
                            $args = array('post_status' => 'any', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'exclude' => $exclude, 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => -1);
                        }
                        $attachments = get_posts($args);
                        // Fetch the images with a WP query
                        if ($orderby == 'rand') {
                            $attachments = (array) $attachments;
                            shuffle($attachments);
                        }
                        if ($limit !== -1) {
                            $attachments = array_slice($attachments, 0, $limit);
                        }
                    } elseif ($image_tags !== '' || $image_categories !== '' || $image_taxonomy !== '' && $image_tax_term !== '') {
                        $image_tags = explode(',', str_replace(' ', '-', str_replace(', ', ',', $image_tags)));
                        $image_categories = explode(',', str_replace(' ', '-', str_replace(', ', ',', $image_categories)));
                        $attachment_tax = get_object_taxonomies('attachment');
                        if (empty($attachment_tax)) {
                            return $this->frontend_stop(__('Category or tag filtering for images is not enabled!', 'jig_td'));
                        }
                        // Base $args array for WP-Query
                        $args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'post_status' => null, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $limit);
                        // All category/tag/tax queries will be using the tax_query array
                        $args['tax_query'] = array();
                        // AND is the default relation even without tax_query (when just specifying them in the $args array)
                        $args['tax_query']['relation'] = 'AND';
                        // Exact taxonomy selected by the user
                        if ($image_taxonomy !== '' && $image_tax_term !== '') {
                            // this is the proper way to query for images using a specific taxonomy
                            $args['tax_query'][] = array('taxonomy' => $image_taxonomy, 'field' => 'slug', 'terms' => explode(',', str_replace(' ', '-', str_replace(', ', ',', $image_tax_term))));
                        }
                        // If MLA plugin is installed these taxonomies will available on images, assume the user uses these
                        if (in_array("attachment_category", $attachment_tax) && in_array("attachment_tag", $attachment_tax)) {
                            if ($image_categories[0] !== '') {
                                $args['tax_query'][] = array('taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => $image_categories);
                            }
                            if ($image_tags[0] !== '') {
                                $args['tax_query'][] = array('taxonomy' => 'attachment_tag', 'field' => 'slug', 'terms' => $image_tags);
                            }
                            $attachments = get_posts($args);
                            // Fetch the images with a WP query
                        }
                        // If this is empty or not yet created, it could be that the user was in fact just using the WP built-in taxonomies
                        if (empty($attachments)) {
                            // Remove the tax query (if the exact one is also used, keep it!)
                            if (!empty($args['tax_query'][0]) && $args['tax_query'][0]['taxonomy'] == $image_taxonomy) {
                                $args['tax_query'] = array('relation' => 'AND', $args['tax_query'][0]);
                            } else {
                                $args['tax_query'] = array('relation' => 'AND');
                            }
                            // Then add queries for the WP built-in taxonomies
                            if ($image_categories[0] !== '') {
                                $args['tax_query'][] = array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $image_categories);
                            }
                            if ($image_tags[0] !== '') {
                                $args['tax_query'][] = array('taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => $image_tags);
                            }
                            $attachments = get_posts($args);
                            // Fetch the images with a WP query
                        }
                        if (empty($attachments)) {
                            return $this->frontend_stop(__('No images found for your category or tag filters!', 'jig_td'));
                        }
                    } elseif ($include !== '') {
                        // If only one post's attached images are to be fetched
                        // build the image list json object for JS
                        $args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'post_status' => null, 'include' => $include, 'numberposts' => $limit);
                        $attachments = get_posts($args);
                        // Fetch the images with a WP query
                    } elseif ($id !== '') {
                        // If images from multiple posts are to be fetched
                        if ($parent_id !== '') {
                            $args = array('hierarchical' => 1, 'child_of' => $parent_id, 'parent' => -1, 'number' => 500, 'post_type' => 'page', 'post_status' => 'publish');
                            $page_children = get_pages($args);
                            $page_children_list = array();
                            if (!empty($page_children)) {
                                foreach ($page_children as $page_child) {
                                    $page_children_list[] = $page_child->ID;
                                }
                                $id = implode(',', $page_children_list);
                            }
                        }
                        $args = array('post_parent__in' => explode(',', $id), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'post_status' => null, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $limit);
                        $attachments = get_posts($args);
                        if (empty($attachments)) {
                            // If old WP that doesn't support post_parent__in
                            if (strpos($id, ',') !== false) {
                                $id = explode(',', $id);
                                $id = $id[0];
                            }
                            $args = array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'post_status' => null, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $limit);
                            $attachments = get_posts($args);
                        }
                    }
                    if ($attachments) {
                        // If there are images attached to the post
                        $this->images = $url_hash_list = array();
                        // Create a new array for the images
                        foreach ($attachments as &$attachment) {
                            // Loop through each
                            $image = $this->jig_wp_get_attachment_image_src($attachment->ID, $lightbox_max_size);
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                $question_mark_in_url = strpos($image[0], '?');
                                if ($question_mark_in_url !== false) {
                                    $image[3] = substr($image[0], 0, $question_mark_in_url);
                                    $url_hash_list[] = hash('md5', $image[3]);
                                } else {
                                    $url_hash_list[] = hash('md5', $image[0]);
                                }
                            }
                            $attachment->jig_image_src = $image;
                        }
                        unset($attachment);
                        // this prepopulates wp_cache with the dimensions, if found
                        if (!$this->jig_query_ext_images($url_hash_list)) {
                            $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                        }
                        foreach ($attachments as $attachment) {
                            // Loop through each
                            $image = $attachment->jig_image_src;
                            // Get URL [0], width [1], and height [2]
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                // If any of the dimensions are not a normal value
                                $image = $this->jig_get_ext_imagesize($image);
                            }
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                continue;
                            }
                            $data = $d = array();
                            // Create 2 arrays for this image one temporary and one that gets pushed
                            $data['url'] = $image[0];
                            // Store the full URL value
                            $data['width'] = $image[1];
                            $data['height'] = $image[2];
                            // Get title
                            if ($title_needed === true) {
                                $d['title'] = $attachment->post_title;
                                if ($d['title'] !== '') {
                                    $data['title'] = esc_attr(stripslashes($d['title']));
                                }
                            }
                            // Get caption
                            if ($caption_needed === true) {
                                $d['caption'] = $attachment->post_excerpt;
                                if ($d['caption'] !== '') {
                                    $data['caption'] = esc_attr(stripslashes($d['caption']));
                                }
                            }
                            // Get description
                            if ($description_needed === true) {
                                $d['description'] = $attachment->post_content;
                                if ($d['description'] !== '') {
                                    $data['description'] = esc_attr(stripslashes($d['description']));
                                }
                            }
                            // Get alternate
                            if ($alternate_needed === true) {
                                $d['alternate'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                                if ($d['alternate'] !== '') {
                                    $data['alternate'] = esc_attr(stripslashes($d['alternate']));
                                }
                            }
                            if ($caption_custom_field !== '' || $lightbox_custom_field !== '') {
                                $custom_fields_to_fetch = explode(',', str_replace(', ', '', trim(implode(',', array($caption_custom_field, $lightbox_custom_field)), ',')));
                                foreach ($custom_fields_to_fetch as $custom_field_name) {
                                    $custom_field_index = 'custom_field_' . $custom_field_name;
                                    $d[$custom_field_index] = esc_attr(stripslashes(get_post_meta($attachment->ID, $custom_field_name, true)));
                                    if ($d[$custom_field_index] !== '') {
                                        $data[$custom_field_index] = $d[$custom_field_index];
                                    }
                                }
                            }
                            // Get link
                            $d['link'] = esc_attr(stripslashes(get_post_meta($attachment->ID, '_jig_image_link', true)));
                            if ($d['link'] != '') {
                                $data['link'] = $d['link'];
                                // Get link target
                                $meta_link_target = get_post_meta($attachment->ID, '_jig_image_link_target', true);
                                if ($meta_link_target !== '' && $meta_link_target !== 'default') {
                                    $data['link_target'] = $meta_link_target;
                                } else {
                                    $data['link_target'] = $link_target;
                                }
                                $d['link_rel'] = array();
                                if ($data['link_target'] == '_blank') {
                                    $d['link_rel'][] = 'external';
                                }
                                if ($custom_link_follow == 'no') {
                                    $d['link_rel'][] = 'nofollow';
                                }
                                $d['link_rel_imploded'] = implode(' ', $d['link_rel']);
                                if ($d['link_rel_imploded'] != '') {
                                    $data['link_rel'] = $d['link_rel_imploded'];
                                }
                            } else {
                                if ($lightbox == 'attachment') {
                                    $data['link'] = get_attachment_link($attachment->ID);
                                    $data['link_target'] = $link_target;
                                }
                            }
                            $d['extra_class'] = array();
                            if ($this->settings['image_custom_classes'] === 'enable') {
                                $d['extra_class'][] = esc_attr(stripslashes(get_post_meta($attachment->ID, '_jig_custom_class', true)));
                                if (!$d['extra_class'][0]) {
                                    unset($d['extra_class'][0]);
                                }
                            }
                            if ($this->settings['image_custom_classes'] !== 'nothing') {
                                // don't set an ID if prettyPhoto is the lightbox AND link doesn't have ?iframe=true or a video
                                if (!(!empty($data['link']) && $lightbox == 'prettyphoto' && stripos($data['link'], '?iframe=true') === false && stripos($data['link'], 'youtube.com/watch') === false && stripos($data['link'], 'youtu.be') === false && stripos($data['link'], 'vimeo.com') === false)) {
                                    $d['extra_class'][] = 'jig-contentID-ML-' . $attachment->ID;
                                }
                            }
                            $d['extra_class_imploded'] = implode(' ', $d['extra_class']);
                            if ($d['extra_class_imploded'] != '') {
                                $data['extra_class'] = $d['extra_class_imploded'];
                            }
                            if ($download_link != 'no') {
                                $download_src = $this->jig_wp_get_attachment_image_src($attachment->ID, 'full');
                                $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($download_src[0]) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                            }
                            if ($carousel_activated) {
                                if ($link_target == '_blank') {
                                    $lightbox = 'no';
                                }
                                $data['carousel_data'] = $this->jig_add_carousel_data($attachment->ID, $link_title_field, $img_alt_field);
                            }
                            if ($filterby == 'on') {
                                $filterby = 'post_tag';
                            }
                            if ($l2_filterby == 'on') {
                                $l2_filterby = 'post_tag';
                            }
                            if ($filterby !== 'off' && taxonomy_exists($filterby)) {
                                $d['filters'] = wp_get_object_terms($attachment->ID, $filterby);
                                if (!empty($d['filters'])) {
                                    foreach ($d['filters'] as $filter_term) {
                                        $data['filters'][] = array($filter_term->slug, $filter_term->name);
                                    }
                                }
                            }
                            if ($l2_filterby !== 'off' && taxonomy_exists($l2_filterby)) {
                                $d['L2filters'] = wp_get_object_terms($attachment->ID, $l2_filterby);
                                if (!empty($d['L2filters'])) {
                                    foreach ($d['L2filters'] as $filter_term) {
                                        $data['L2filters'][] = array($filter_term->slug, $filter_term->name);
                                    }
                                }
                            }
                            // Add to the main images array
                            array_push($this->images, $data);
                        }
                    } else {
                        return $this->frontend_stop(sprintf(__('There are no photos with those IDs or post %1$s does not have any attached images!', 'jig_td'), $id));
                    }
                    remove_filter('editor_max_image_size', array($this, 'jig_bypass_editor_max_image_size'));
                    break;
                case 'wp_recent_posts':
                    add_filter('editor_max_image_size', array($this, 'jig_bypass_editor_max_image_size'));
                    $order = 'ASC';
                    switch ($orderby) {
                        case 'menu_order':
                            $orderby_original = 'menu_order';
                        case 'date_desc':
                            $orderby = 'date';
                            $order = 'DESC';
                            break;
                        case 'title_asc':
                            $orderby = 'title';
                            break;
                        case 'title_desc':
                            $orderby = 'title';
                            $order = 'DESC';
                            break;
                        case 'date_asc':
                            $orderby = 'date';
                            break;
                        case 'custom':
                            $orderby = 'menu_order';
                            $order = 'ASC';
                            break;
                        default:
                    }
                    if ($limit === '') {
                        $limit = 50;
                    } else {
                        if ($limit === '0') {
                            $limit = -1;
                        }
                    }
                    $cat = '';
                    $tag = '';
                    if ($recents_exclude != '') {
                        $recents_exclude = explode(',', str_replace(' ', '-', str_replace(', ', ',', $recents_exclude)));
                        foreach ($recents_exclude as &$recents_exclude_cat) {
                            if (!is_numeric($recents_exclude_cat)) {
                                $recents_exclude_cat = get_category_by_slug($recents_exclude_cat)->term_id;
                            }
                            $recents_exclude_cat = "-" . $recents_exclude_cat;
                        }
                        $cat = implode(',', $recents_exclude);
                    } elseif ($recents_include != '') {
                        $recents_include = explode(',', str_replace(' ', '-', str_replace(', ', ',', $recents_include)));
                        foreach ($recents_include as &$recents_include_cat) {
                            if (!is_numeric($recents_include_cat)) {
                                $recents_include_cat = get_category_by_slug($recents_include_cat)->term_id;
                            }
                        }
                        $cat = implode(',', $recents_include);
                    }
                    if ($recents_tags != '') {
                        $tag = str_replace(' ', '-', str_replace(', ', ',', $recents_tags));
                    }
                    if ($recents_tree_depth === '' || $recents_tree_depth === 0 || !is_numeric($recents_tree_depth)) {
                        $recents_tree_depth = 10;
                    }
                    $posts = array();
                    $recents_post_type = strpos($recents_post_type, ',') === false ? $recents_post_type : explode(',', $recents_post_type);
                    $args = array('post_type' => $recents_post_type, 'order' => $order, 'orderby' => $orderby, 'post_status' => array('publish'), 'category' => $cat, 'tag' => $tag, 'numberposts' => $limit, 'ignore_sticky_posts' => 1);
                    if ($recents_placeholder === '') {
                        $args['meta_key'] = '_thumbnail_id';
                    }
                    if ($post_ids !== '') {
                        // Regular recent posts call when the results are automatic, depending on settings
                        $args['post__in'] = explode(',', $post_ids);
                        if (isset($orderby_original)) {
                            $args['orderby'] = 'post__in';
                        }
                    } elseif ($post_ids_exclude !== '') {
                        // Regular recent posts call when the results are automatic, depending on settings
                        global $post;
                        $post_ids_exclude = str_replace('current', $post->ID, $post_ids_exclude);
                        $args['post__not_in'] = explode(',', $post_ids_exclude);
                    }
                    if ($recents_sticky === 'yes') {
                        $args['post__in'] = get_option('sticky_posts');
                    } elseif ($recents_sticky === 'no') {
                        unset($args['post__in']);
                        $args['post__not_in'] = get_option('sticky_posts');
                    }
                    if ($recents_filter_tax !== 'none' && !empty($recents_filter_term)) {
                        // this is the proper way to query for posts using a specific taxonomy
                        $args['tax_query'] = array(array('taxonomy' => $recents_filter_tax, 'field' => 'slug', 'terms' => explode(',', str_replace(' ', '-', str_replace(', ', ',', $recents_filter_term)))));
                    }
                    if (!empty($recents_author)) {
                        if ($recents_author !== 'currently_logged_in') {
                            $recents_user = get_user_by('login', $recents_author);
                            $args['author'] = $recents_user->ID;
                        } else {
                            $recents_current_user_id = get_current_user_id();
                            if ($recents_current_user_id !== 0) {
                                $args['author'] = $recents_current_user_id;
                            } else {
                                return $this->frontend_stop(sprintf(__('You need to be logged in to view your posts.', 'jig_td'), $id));
                            }
                        }
                    }
                    if ($recents_date_range !== '') {
                        $recents_date_range = trim(str_replace(' ', '', $recents_date_range));
                        $recents_date_range_after = array('year' => substr($recents_date_range, 0, 4), 'month' => ltrim(substr($recents_date_range, 5, 2), '0'), 'day' => ltrim(substr($recents_date_range, 8, 2), '0'), 'hour' => 0);
                        $recents_date_range_before = array('hour' => 23, 'minute' => 59, 'second' => 59);
                        if (strtolower(substr($recents_date_range, 11)) !== 'today') {
                            $recents_date_range_before['year'] = substr($recents_date_range, 11, 4);
                            $recents_date_range_before['month'] = ltrim(substr($recents_date_range, 16, 2), '0');
                            $recents_date_range_before['day'] = ltrim(substr($recents_date_range, 19, 2), '0');
                        } else {
                            $recents_date_range_today = getdate();
                            $recents_date_range_before['year'] = $recents_date_range_today['year'];
                            $recents_date_range_before['month'] = $recents_date_range_today['mon'];
                            $recents_date_range_before['day'] = $recents_date_range_today['mday'];
                        }
                        $args['date_query'] = array(array('after' => $recents_date_range_after, 'before' => $recents_date_range_before), 'inclusive' => true);
                    }
                    if ($recents_last_x_days !== '') {
                        $recents_last_x_days_today = getdate();
                        $recents_last_x_days_other_day = getdate(date('U') - (int) $recents_last_x_days * 86400);
                        $args['date_query'] = array(array('after' => array('year' => $recents_last_x_days_other_day['year'], 'month' => $recents_last_x_days_other_day['mon'], 'day' => $recents_last_x_days_other_day['mday'], 'hour' => $recents_last_x_days_other_day['hours'], 'minute' => $recents_last_x_days_other_day['minutes'], 'second' => $recents_last_x_days_other_day['seconds']), 'before' => array('year' => $recents_last_x_days_today['year'], 'month' => $recents_last_x_days_today['mon'], 'day' => $recents_last_x_days_today['mday'], 'hour' => $recents_last_x_days_today['hours'], 'minute' => $recents_last_x_days_today['minutes'], 'second' => $recents_last_x_days_today['seconds'])), 'inclusive' => true);
                    }
                    if ($orderby == 'menu_order' && $recents_post_type == 'page') {
                        $args['suppress_filters'] = false;
                        add_filter('posts_orderby', array($this, 'add_secondary_order_to_pages'));
                    }
                    if ($recents_parent_id === '') {
                        $posts = get_posts($args);
                    } else {
                        $args['post_parent'] = $recents_parent_id;
                        $posts = $this->get_recents_recursive($args, $recents_tree_depth, 0);
                    }
                    if ($orderby == 'menu_order' && $recents_post_type == 'page') {
                        remove_filter('posts_orderby', array($this, 'add_secondary_order_to_pages'));
                    } elseif ($orderby == 'rand') {
                        $posts = (array) $posts;
                        shuffle($posts);
                    }
                    $is_wpml = defined('ICL_SITEPRESS_VERSION') || function_exists('wpml_get_language_information');
                    if ($posts) {
                        // If there are images attached to the post
                        $this->images = $url_hash_list = array();
                        // Create a new array for the images
                        foreach ($posts as &$post) {
                            // Loop through each
                            if ($is_wpml === true) {
                                if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
                                    //Code for the new version greater than or equal to 3.2
                                    $post_language = apply_filters('wpml_post_language_details', NULL, $post->ID);
                                } else {
                                    //support for older WPML versions
                                    $post_language = wpml_get_language_information($post->ID);
                                }
                                if ($post_language['different_language'] == true) {
                                    $post->jig_image_src = 'skip';
                                    continue;
                                }
                            }
                            $post->post_thumbnail_id = get_post_thumbnail_id($post->ID);
                            $image = $this->jig_wp_get_attachment_image_src($post->post_thumbnail_id, $lightbox_max_size);
                            if ($image == false && !empty($post->post_thumbnail_id) && class_exists('nggdb')) {
                                global $wpdb;
                                $nggID = substr($post->post_thumbnail_id, 4);
                                if ($nggID !== false) {
                                    $nggImage = $this->jig_ng_find_images($nggID, true);
                                    if (!empty($nggImage)) {
                                        $image = array();
                                        $image[0] = $nggImage->imageURL;
                                        $image[1] = $nggImage->meta_data['width'];
                                        $image[2] = $nggImage->meta_data['height'];
                                    }
                                }
                            }
                            if ($image == false && $recents_placeholder !== '') {
                                $image[0] = $recents_placeholder;
                                $image[1] = $image[2] = 0;
                            }
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                $url_hash_list[] = hash('md5', $image[0]);
                            }
                            $post->jig_image_src = $image;
                        }
                        unset($post);
                        // this prepopulates wp_cache with the dimensions, if found
                        if (!$this->jig_query_ext_images($url_hash_list)) {
                            $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                        }
                        if ($post_metadata_fields !== '') {
                            $post_metadata_fields = explode(',', str_replace(', ', ',', $post_metadata_fields));
                        }
                        foreach ($posts as $post) {
                            // Loop through each
                            $image = $post->jig_image_src;
                            // Get URL [0], width [1], and height [2]
                            if ($image == "skip") {
                                continue;
                            }
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                // If any of the dimensions are not a normal value
                                $image = $this->jig_get_ext_imagesize($image);
                            }
                            if (!is_numeric($image[1]) || !is_numeric($image[2]) || $image[1] == 0 || $image[2] == 0) {
                                continue;
                            }
                            $data = $d = array();
                            // Create 2 arrays for this image one temporary and one that gets pushed
                            $data['url'] = $image[0];
                            // Store the full URL value
                            $data['width'] = $image[1];
                            $data['height'] = $image[2];
                            // Get title
                            if ($title_needed === true) {
                                if ($recents_title_override !== '') {
                                    $d['title'] = get_post_meta($post->ID, $recents_title_override, true);
                                }
                                if (empty($d['title'])) {
                                    $d['title'] = esc_attr(stripslashes($post->post_title));
                                }
                                if ($d['title'] != '') {
                                    $data['title'] = (empty($post->post_password) ? '' : __('Protected', 'jig_td') . ': ') . $d['title'];
                                }
                            }
                            if ($description_needed === true) {
                                if ($recents_description !== '') {
                                    $recents_descriptions['1'] = $recents_description;
                                }
                                if ($recents_description_2 !== '') {
                                    $recents_descriptions['2'] = $recents_description_2;
                                }
                                if ($recents_description_3 !== '') {
                                    $recents_descriptions['3'] = $recents_description_3;
                                }
                                if (!empty($post_metadata_fields)) {
                                    $d['post_metadata_fields'] = $post_metadata_fields;
                                    // temp copy as they'll get shifted
                                }
                                foreach ($recents_descriptions as $recents_desc_id => $recents_description_value) {
                                    // Get description
                                    switch ($recents_description_value) {
                                        case 'nothing':
                                            $d['description'][$recents_desc_id] = '';
                                            break;
                                        case 'categories':
                                            $d['description'][$recents_desc_id] = implode(", ", wp_get_post_categories($post->ID, array('fields' => 'names')));
                                            break;
                                        case 'tags':
                                            $d['description'][$recents_desc_id] = implode(", ", wp_get_post_tags($post->ID, array('fields' => 'names')));
                                            break;
                                        case 'auto_excerpt':
                                            $d['description'][$recents_desc_id] = $this->jig_the_excerpt($post, $excerpt_length, $excerpt_ending);
                                            break;
                                        case 'manual_excerpt':
                                            $d['description'][$recents_desc_id] = esc_attr(stripslashes($post->post_excerpt));
                                            break;
                                        case 'auto_manual_excerpt':
                                            $d['description'][$recents_desc_id] = esc_attr(stripslashes($post->post_excerpt));
                                            if ($d['description'][$recents_desc_id] == '') {
                                                $d['description'][$recents_desc_id] = $this->jig_the_excerpt($post, $excerpt_length, $excerpt_ending);
                                            }
                                            break;
                                        case 'datetime':
                                            $d['description'][$recents_desc_id] = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($post->post_date));
                                            break;
                                        case 'date':
                                            $d['description'][$recents_desc_id] = date(get_option('date_format'), strtotime($post->post_date));
                                            break;
                                        case 'nicetime':
                                            $d['description'][$recents_desc_id] = $this->jig_nice_time($post->post_date);
                                            break;
                                        case 'comments':
                                            $comments_count = get_comments_number($post->ID);
                                            if (!empty($comments_count)) {
                                                $comments_texts = explode('|', $comments_text);
                                                if ($comments_count != 1) {
                                                    $d['description'][$recents_desc_id] = $comments_count . ' ' . trim(!empty($comments_texts[1]) ? $comments_texts[1] : $comments_texts[0]);
                                                } else {
                                                    $d['description'][$recents_desc_id] = $comments_count . ' ' . trim($comments_texts[0]);
                                                }
                                            }
                                            $comments_count = null;
                                            unset($comments_count);
                                            break;
                                        case 'author':
                                            $author_data = get_userdata($post->post_author);
                                            $d['description'][$recents_desc_id] = ($author_prefix !== 'none' ? trim($author_prefix) . ' ' : '') . (!empty($author_data->display_name) ? $author_data->display_name : $author_data->user_login);
                                            unset($author_data);
                                            break;
                                        case 'woocommerce_price':
                                            $d['description'][$recents_desc_id] = get_post_meta($post->ID, '_regular_price', true);
                                            if ($d['description'][$recents_desc_id] && function_exists('wc_price')) {
                                                $d['description'][$recents_desc_id] = wc_price($d['description'][$recents_desc_id]);
                                            }
                                            break;
                                        case 'custom_post_metadata':
                                            if (!empty($d['post_metadata_fields'])) {
                                                $d['description'][$recents_desc_id] = get_post_meta($post->ID, array_shift($d['post_metadata_fields']), true);
                                            } else {
                                                $d['description'][$recents_desc_id] = '';
                                            }
                                            break;
                                        default:
                                            $d['description'][$recents_desc_id] = '';
                                            if (substr($recents_description_value, 0, 15) === 'custom_taxonomy') {
                                                $custom_taxonomy_for_recents_description = substr($recents_description_value, 16);
                                                if (taxonomy_exists($custom_taxonomy_for_recents_description)) {
                                                    $d['description'][$recents_desc_id] = implode(", ", wp_get_post_terms($post->ID, $custom_taxonomy_for_recents_description, array('fields' => 'names')));
                                                }
                                            }
                                    }
                                    if (empty($d['description'][$recents_desc_id])) {
                                        unset($d['description'][$recents_desc_id]);
                                    }
                                }
                                $d['description'] = implode('<br />', $d['description']);
                                if ($d['description'] != '') {
                                    $data['description'] = esc_attr($d['description']);
                                }
                            }
                            switch ($recents_link_to) {
                                case 'post':
                                    // Get link
                                    $data['link'] = esc_attr(stripslashes(get_permalink($post->ID)));
                                    // Get link target
                                    if ($recents_custom_links == 'yes') {
                                        $data['link_target'] = '_self';
                                    }
                                    break;
                                case 'attachment':
                                    $data['link'] = get_attachment_link($post->post_thumbnail_id);
                                    if (substr($data['link'], -1) == "=") {
                                        // If link is not valid (old NG?)
                                        $data['link'] = $data['url'];
                                    }
                                    if ($recents_custom_links == 'yes') {
                                        $data['link_target'] = '_self';
                                    }
                                    break;
                                case 'image':
                                default:
                                    if ($download_link != 'no') {
                                        $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                    }
                                    if ($recents_link != 'no') {
                                        $data['lightbox_link'] = esc_attr(stripslashes('<a href="' . esc_attr(stripslashes(get_permalink($post->ID))) . '" >' . $recents_link_text . '</a>'));
                                    }
                                    if ($carousel_activated) {
                                        $data['carousel_data'] = $this->jig_add_carousel_data($post->post_thumbnail_id, $link_title_field, $img_alt_field);
                                    }
                            }
                            if ($recents_custom_links == 'yes') {
                                $d['link'] = esc_attr(stripslashes(get_post_meta($post->post_thumbnail_id, '_jig_image_link', true)));
                                if ($d['link'] != '') {
                                    $data['link'] = $d['link'];
                                    // Get link target
                                    $meta_link_target = get_post_meta($post->post_thumbnail_id, '_jig_image_link_target', true);
                                    if ($meta_link_target !== '' && $meta_link_target !== 'default') {
                                        $data['link_target'] = $meta_link_target;
                                    } else {
                                        $data['link_target'] = $link_target;
                                    }
                                    $d['link_rel'] = array();
                                    if ($data['link_target'] == '_blank') {
                                        $d['link_rel'][] = 'external';
                                    }
                                    if ($custom_link_follow == 'no') {
                                        $d['link_rel'][] = 'nofollow';
                                    }
                                    $d['link_rel_imploded'] = implode(' ', $d['link_rel']);
                                    if ($d['link_rel_imploded'] != '') {
                                        $data['link_rel'] = $d['link_rel_imploded'];
                                    }
                                }
                            }
                            $d['extra_class'] = array();
                            if ($this->settings['image_custom_classes'] === 'enable') {
                                $d['extra_class'][] = esc_attr(stripslashes(get_post_meta($post->post_thumbnail_id, '_jig_custom_class', true)));
                                if (!$d['extra_class'][0]) {
                                    unset($d['extra_class'][0]);
                                }
                            }
                            if ($this->settings['image_custom_classes'] !== 'nothing') {
                                $d['extra_class'][] = 'jig-contentID-RP-' . $post->ID;
                            }
                            if (isset($post->extra_class)) {
                                $d['extra_class'][] = $post->extra_class;
                            }
                            $d['extra_class_imploded'] = implode(' ', $d['extra_class']);
                            if ($d['extra_class_imploded'] != '') {
                                $data['extra_class'] = $d['extra_class_imploded'];
                            }
                            if ($filterby == 'on') {
                                $filterby = 'post_tag';
                            }
                            if ($l2_filterby == 'on') {
                                $l2_filterby = 'post_tag';
                            }
                            if ($filterby !== 'off' && taxonomy_exists($filterby)) {
                                $d['filters'] = wp_get_object_terms($post->ID, $filterby);
                                if (!empty($d['filters'])) {
                                    foreach ($d['filters'] as $filter_term) {
                                        if ($filter_term->slug !== 'uncategorized') {
                                            $data['filters'][] = array($filter_term->slug, $filter_term->name);
                                        }
                                    }
                                }
                            }
                            if ($l2_filterby !== 'off' && taxonomy_exists($l2_filterby)) {
                                $d['L2filters'] = wp_get_object_terms($post->ID, $l2_filterby);
                                if (!empty($d['L2filters'])) {
                                    foreach ($d['L2filters'] as $filter_term) {
                                        if ($filter_term->slug !== 'uncategorized') {
                                            $data['L2filters'][] = array($filter_term->slug, $filter_term->name);
                                        }
                                    }
                                }
                            }
                            // Add to the main images array
                            array_push($this->images, $data);
                        }
                        if ($recents_custom_links == 'no' && ($recents_link_to == 'post' || $recents_link_to == 'attachment')) {
                            $lightbox = 'no';
                        }
                    } else {
                        return $this->frontend_stop(sprintf(__('There are no recent posts with featured images.', 'jig_td'), $id));
                    }
                    remove_filter('editor_max_image_size', array($this, 'jig_bypass_editor_max_image_size'));
                    break;
                case 'nextgen':
                    if (!class_exists('nggGallery')) {
                        return $this->frontend_stop(__('NextGEN gallery is not installed/inactive!', 'jig_td'));
                    }
                    $ngg_options = nggGallery::get_option('ngg_options');
                    switch ($orderby) {
                        case 'rand':
                            $ngg_options['galSort'] = 'RAND';
                            $ngg_options['galSortDir'] = $ngg_options['galSortDir'] == 'DESC' ? 'DESC' : 'ASC';
                            break;
                        case 'title_asc':
                            $ngg_options['galSort'] = 'alttext';
                            $ngg_options['galSortDir'] = 'ASC';
                            break;
                        case 'title_desc':
                            $ngg_options['galSort'] = 'alttext';
                            $ngg_options['galSortDir'] = 'DESC';
                            break;
                        case 'date_asc':
                            $ngg_options['galSort'] = 'imagedate';
                            $ngg_options['galSortDir'] = 'ASC';
                            break;
                        case 'date_desc':
                            $ngg_options['galSort'] = 'imagedate';
                            $ngg_options['galSortDir'] = 'DESC';
                            break;
                        default:
                            // menu_order and custom
                            $ngg_options['galSort'] = $ngg_options['galSort'] ? $ngg_options['galSort'] : 'pid';
                            $ngg_options['galSortDir'] = $ngg_options['galSortDir'] == 'DESC' ? 'DESC' : 'ASC';
                            break;
                    }
                    if (class_exists('C_NextGEN_Bootstrap')) {
                        $this->ng_version = 2;
                    } else {
                        $this->ng_version = 1;
                    }
                    $original_nextgen_limit = $limit;
                    if ($limit === '' || $limit === "0") {
                        $limit = 1000;
                    }
                    if ($ng_album !== '') {
                        $ng_bc_home_album = $ng_album;
                    }
                    if ($ng_narrow_by_tags !== '') {
                        $ng_narrow_by_tags = explode(',', str_replace(', ', ',', $ng_narrow_by_tags));
                    }
                    global $wpdb, $jigNgConnect;
                    $ng_gallerytag = false;
                    if (!isset($jigNgConnect)) {
                        if ($this->jig_ng_get_query_var('gallery') !== '') {
                            $ng_gallery = $this->jig_ng_get_query_var('gallery');
                            // Doesn't matter if it's ID or slug
                            $ng_album = '';
                            $jigNgConnect = true;
                        } else {
                            if ($this->jig_ng_get_query_var('album') !== '') {
                                $ng_album = $this->jig_ng_get_query_var('album');
                                // It's best if the album value is always an ID
                                if (!is_numeric($ng_album)) {
                                    $ng_album = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->nggalbum} WHERE slug = %s", $ng_album));
                                    if (empty($ng_album)) {
                                        $ng_album = '';
                                    }
                                }
                                $ng_gallery = '';
                                if ($ng_album !== '') {
                                    $jigNgConnect = true;
                                }
                            } else {
                                if ($this->jig_ng_get_query_var('gallerytag') !== '') {
                                    $ng_gallerytag = $this->jig_ng_get_query_var('gallerytag');
                                    // Doesn't matter if it's ID or slug
                                    $ng_gallery = '';
                                    $ng_album = '';
                                    $jigNgConnect = true;
                                    $ng_tags_gallery = $ng_gallerytag;
                                }
                            }
                        }
                    } else {
                        return $this->frontend_stop();
                        // Another instance is serving the gallery from the URL parameters
                    }
                    if ($ng_gallery !== '') {
                        // If a gallery is displayed
                        $ng_gallery = str_replace(' ', '', $ng_gallery);
                        $images = $this->jig_ng_get_galleries($ng_gallery, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                        if (empty($images)) {
                            return $this->frontend_stop(sprintf(__('The NextGEN gallery with ID/slug: %1$s does not exist or is empty.', 'jig_td'), $ng_gallery));
                        }
                        if (!empty($images)) {
                            $this->images = $url_hash_list = array();
                            // Create a new array for the images
                            foreach ($images as &$image) {
                                if (!$image->meta_data['width'] || !$image->meta_data['height']) {
                                    $url_hash_list[] = hash('md5', $image->imageURL);
                                }
                                $image->jig_image_src = array($image->imageURL, $image->meta_data['width'], $image->meta_data['height']);
                            }
                            unset($image);
                            // this prepopulates wp_cache with the dimensions, if found
                            if (!$this->jig_query_ext_images($url_hash_list)) {
                                $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                            }
                            foreach ($images as $image) {
                                if (!$image->jig_image_src[1] || !$image->jig_image_src[2]) {
                                    // If any of the dimensions are not a normal value
                                    $image->jig_image_src = $this->jig_get_ext_imagesize($image->jig_image_src);
                                }
                                $image->meta_data['width'] = $image->jig_image_src[1];
                                $image->meta_data['height'] = $image->jig_image_src[2];
                                if ($image->meta_data['width'] != 0 && $image->meta_data['height'] != 0) {
                                    // If none of the dimensions are 0
                                    $data = $d = array();
                                    // Create 2 arrays for this image one temporary and one that gets pushed
                                    $data['url'] = $image->imageURL;
                                    $data['width'] = $image->meta_data['width'];
                                    $data['height'] = $image->meta_data['height'];
                                    $d['title'] = esc_attr(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
                                    if ($d['title'] != '') {
                                        $data['title'] = $d['title'];
                                    }
                                    $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description'))));
                                    if ($ng_display_tags == 'yes') {
                                        $d['tags'] = ucwords(implode(', ', wp_get_object_terms($image->pid, 'ngg_tag', array('fields' => 'names'))));
                                        if (!empty($d['tags'])) {
                                            $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                        }
                                    }
                                    if ($d['description'] != '') {
                                        $data['description'] = $d['description'];
                                    }
                                    if ($download_link != 'no') {
                                        $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                    }
                                    if (isset($image->ng_cf_link)) {
                                        $data['link'] = $image->ng_cf_link;
                                        $data['link_target'] = $link_target;
                                    }
                                    if ($filterby == 'on') {
                                        $d['filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                        if (!empty($d['filters'])) {
                                            foreach ($d['filters'] as $filter_term) {
                                                $data['filters'][] = array($filter_term->slug, $filter_term->name);
                                            }
                                        }
                                    } elseif ($filterby == 'ng_galleries') {
                                        if (!empty($image->slug) && !empty($image->title)) {
                                            $data['filters'][] = array($image->slug, $image->title);
                                        }
                                    }
                                    if ($l2_filterby == 'on') {
                                        $d['L2filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                        if (!empty($d['L2filters'])) {
                                            foreach ($d['L2filters'] as $filter_term) {
                                                $data['L2filters'][] = array($filter_term->slug, $filter_term->name);
                                            }
                                        }
                                    } elseif ($l2_filterby == 'ng_galleries') {
                                        if (!empty($image->slug) && !empty($image->title)) {
                                            $data['L2filters'][] = array($image->slug, $image->title);
                                        }
                                    }
                                    if (!empty($ng_narrow_by_tags)) {
                                        $ng_image_tags = wp_get_object_terms($image->pid, 'ngg_tag');
                                        if (!empty($ng_image_tags)) {
                                            foreach ($ng_image_tags as $filter_term) {
                                                if (in_array($filter_term->slug, $ng_narrow_by_tags) || in_array($filter_term->name, $ng_narrow_by_tags)) {
                                                    $ng_tag_found_in_image = true;
                                                    break;
                                                }
                                            }
                                            if (!isset($ng_tag_found_in_image)) {
                                                unset($ng_tag_found_in_image);
                                                continue;
                                                // Don't add this image to the images if it's missing the tag(s)
                                            }
                                        } else {
                                            continue;
                                            // Don't add this image to the images if it's missing ANY tag(s)
                                        }
                                        unset($ng_image_tags, $ng_tag_found_in_image);
                                    }
                                    if ($ng_description == 'yes') {
                                        $ng_description = 'no';
                                        if ($image->galdesc) {
                                            $notice_before .= '<p class="jig-ngDescription">' . $image->galdesc . '</p>';
                                        }
                                    }
                                    if ($this->settings['image_custom_classes'] !== 'nothing') {
                                        $data['extra_class'] = 'jig-contentID-NG-' . $image->pid;
                                    }
                                    array_push($this->images, $data);
                                }
                            }
                        }
                    } else {
                        if ($ng_album !== '') {
                            // If an album (or overview album) is displayed
                            $albums = $wpdb->get_results("SELECT * FROM {$wpdb->nggalbum}");
                            if (!empty($albums)) {
                                foreach ($albums as $val) {
                                    wp_cache_set($val->id, $val, 'jig_ng_albums');
                                }
                            }
                            $album = $this->jig_ng_get_album($ng_album, $ngg_options['galSort'], $ngg_options['galSortDir']);
                            if (!empty($album)) {
                                if ($album->content_ids) {
                                    if ($ng_description == 'yes') {
                                        $ng_description = 'no';
                                        if ($album->albumdesc) {
                                            $notice_before .= '<p class="jig-ngDescription">' . $album->albumdesc . '</p>';
                                        }
                                    }
                                    $album_contents = $album->content_ids;
                                    if (!empty($album_contents)) {
                                        $photo_count_by_gallery_id = array();
                                        if ($album->id == 'all') {
                                            $album->slug = $album->id;
                                        }
                                        $album_contents_imploded = "'" . implode("','", $album_contents) . "'";
                                        if (empty($ng_narrow_by_tags)) {
                                            $picturesCounter = $wpdb->get_results("SELECT galleryid, COUNT(*) as counter FROM {$wpdb->nggpictures} WHERE galleryid IN ( {$album_contents_imploded} ) AND exclude != 1 GROUP BY galleryid", OBJECT_K);
                                        } else {
                                            $term_ids_string = $this->ng_get_term_id_from_tag($ng_narrow_by_tags);
                                            $picturesCounter = $this->ng_count_tagged_images_per_gallery($term_ids_string);
                                        }
                                        if (!empty($picturesCounter)) {
                                            foreach ($picturesCounter as $key => $value) {
                                                $photo_count_by_gallery_id[$key] = $value->counter;
                                            }
                                        }
                                        $this->images = $shadow_galleries = array();
                                        $counter = 0;
                                        foreach ($album_contents as $album_content) {
                                            // $album content can be a gallery on an album
                                            if (++$counter > $limit) {
                                                break;
                                            }
                                            if (substr($album_content, 0, 1) != "a") {
                                                // If it's a gallery
                                                if (empty($photo_count_by_gallery_id[$album_content])) {
                                                    continue;
                                                }
                                                $image = $this->ng_find_cover_image_for_gallery($album_content);
                                                // pass the gallery ID and get back a representative image that is processed
                                                if (!empty($image)) {
                                                    if (!empty($ng_narrow_by_tags)) {
                                                        $gallery_images_for_narrowing = $lightbox_images = $this->jig_ng_get_galleries($album_content, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                                                        if (!empty($gallery_images_for_narrowing)) {
                                                            $gallery_is_needed = false;
                                                            foreach ($gallery_images_for_narrowing as $image_for_narrowing) {
                                                                $ng_image_tags = wp_get_object_terms($image_for_narrowing->pid, 'ngg_tag');
                                                                if (!empty($ng_image_tags)) {
                                                                    foreach ($ng_image_tags as $filter_term) {
                                                                        if (in_array($filter_term->slug, $ng_narrow_by_tags) || in_array($filter_term->name, $ng_narrow_by_tags)) {
                                                                            $gallery_is_needed = true;
                                                                            break 2;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if ($gallery_is_needed == false) {
                                                                continue;
                                                            }
                                                        }
                                                    }
                                                    if ($ng_lightbox_gallery == 'yes') {
                                                        // If gallery should be displayed as a lightbox
                                                        $lightbox_images = $this->jig_ng_get_galleries($album_content, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                                                        if (!empty($lightbox_images)) {
                                                            $shadow_galleries[] = $shadow_group_id = "jig{$jig_id}-hiddenGalleryGroup-" . $album_content;
                                                            $shadow_gallery = '<div class="jig-hiddenGallery">';
                                                            if (stripos($link_rel, '*instance*') !== false) {
                                                                $shadow_rel = str_replace('*instance*', 'NG-' . $album_content, $link_rel);
                                                            } else {
                                                                switch ($lightbox) {
                                                                    case 'prettyphoto':
                                                                        $shadow_rel = 'prettyPhoto[ngg-' . $album_content . ']';
                                                                        break;
                                                                    case 'colorbox':
                                                                        $shadow_rel = 'colorBox[ngg-' . $album_content . ']';
                                                                        break;
                                                                    case 'foobox':
                                                                        $shadow_rel = 'foobox[ngg-' . $album_content . ']';
                                                                        break;
                                                                    default:
                                                                        $shadow_rel = 'jig[ngg-' . $album_content . ']';
                                                                        break;
                                                                }
                                                            }
                                                            if ($lightbox == 'photoswipe') {
                                                                foreach ($lightbox_images as &$lightbox_image) {
                                                                    if (!$lightbox_image->meta_data['width'] || !$lightbox_image->meta_data['height']) {
                                                                        $url_hash_list[] = hash('md5', $lightbox_image->imageURL);
                                                                    }
                                                                    $lightbox_image->jig_image_src = array($lightbox_image->imageURL, $lightbox_image->meta_data['width'], $lightbox_image->meta_data['height']);
                                                                }
                                                                unset($lightbox_image);
                                                                // this prepopulates wp_cache with the dimensions, if found
                                                                if (!$this->jig_query_ext_images($url_hash_list)) {
                                                                    $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                                                }
                                                            }
                                                            foreach ($lightbox_images as $lightbox_image) {
                                                                // Skip image from the hidden gallery if it's the same as the opener image
                                                                if ($lightbox_image->filename == $image->filename) {
                                                                    continue;
                                                                }
                                                                $data = $d = array();
                                                                // Create 2 arrays for this image one temporary and one that gets pushed
                                                                $data['url'] = $lightbox_image->imageURL;
                                                                $d['title'] = esc_attr(stripslashes(nggGallery::i18n($lightbox_image->alttext, 'pic_' . $lightbox_image->pid . '_alttext')));
                                                                $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($lightbox_image->description, 'pic_' . $lightbox_image->pid . '_description'))));
                                                                if ($ng_display_tags == 'yes') {
                                                                    $d['tags'] = ucwords(implode(', ', wp_get_object_terms($lightbox_image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                                    if (!empty($d['tags'])) {
                                                                        $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                                    }
                                                                }
                                                                $title_fragment = isset($d[$link_title_field]) ? $d[$link_title_field] : '';
                                                                $alt_fragment = isset($d[$img_alt_field]) ? $d[$img_alt_field] : '';
                                                                if ($download_link != 'no') {
                                                                    $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                                    if ($download_link == 'yes') {
                                                                        if ($title_fragment !== '') {
                                                                            $title_fragment .= $separator_character . $data['download'];
                                                                        } else {
                                                                            $title_fragment = $data['download'];
                                                                        }
                                                                    } else {
                                                                        if ($alt_fragment !== '') {
                                                                            $alt_fragment .= $separator_character . $data['download'];
                                                                        } else {
                                                                            $alt_fragment = $data['download'];
                                                                        }
                                                                    }
                                                                }
                                                                if ($lightbox == 'photoswipe') {
                                                                    if (!$lightbox_image->jig_image_src[1] || !$lightbox_image->jig_image_src[2]) {
                                                                        // If any of the dimensions are not a normal value
                                                                        $lightbox_image->jig_image_src = $this->jig_get_ext_imagesize($lightbox_image->jig_image_src);
                                                                    }
                                                                    $lightbox_image->meta_data['width'] = $lightbox_image->jig_image_src[1];
                                                                    $lightbox_image->meta_data['height'] = $lightbox_image->jig_image_src[2];
                                                                    if ($lightbox_image->meta_data['width'] != 0 && $lightbox_image->meta_data['height'] != 0) {
                                                                        // If none of the dimensions are 0
                                                                        $shadow_size = ' data-wh="' . $lightbox_image->meta_data['width'] . 'x' . $lightbox_image->meta_data['height'] . '"';
                                                                    } else {
                                                                        continue;
                                                                    }
                                                                } else {
                                                                    $shadow_size = '';
                                                                }
                                                                $shadow_class = 'class="jig-link jig-contentID-NG-' . $lightbox_image->pid . (empty($link_class) ? '' : ' ' . $link_class) . '" ';
                                                                $shadow_gallery .= '<a href="' . $data['url'] . '" rel="' . $shadow_rel . '" ' . $shadow_class . $shadow_size . ' title="' . $title_fragment . '"><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="' . $alt_fragment . '" /></a>';
                                                            }
                                                            $shadow_gallery .= "</div>";
                                                        }
                                                    }
                                                    $meta_data = $image->meta_data;
                                                    $url_hash_list = array();
                                                    // Create a new array for the images
                                                    if (!$meta_data['width'] || !$meta_data['height']) {
                                                        $url_hash_list[] = hash('md5', $image->imageURL);
                                                    }
                                                    $image->jig_image_src = array($image->imageURL, $meta_data['width'], $meta_data['height']);
                                                    // this prepopulates wp_cache with the dimensions, if found
                                                    if (!$this->jig_query_ext_images($url_hash_list)) {
                                                        $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                                    }
                                                    if (!$image->jig_image_src[1] || !$image->jig_image_src[2]) {
                                                        // If any of the dimensions are not a normal value
                                                        $image->jig_image_src = $this->jig_get_ext_imagesize($image->jig_image_src);
                                                    }
                                                    $meta_data['width'] = $image->jig_image_src[1];
                                                    $meta_data['height'] = $image->jig_image_src[2];
                                                    if ($meta_data['width'] != 0 && $meta_data['height'] != 0) {
                                                        // If none of the dimensions are 0
                                                        $data = $d = array();
                                                        // Create 2 arrays for this image one temporary and one that gets pushed
                                                        $data['url'] = $image->jig_image_src[0];
                                                        $data['width'] = $meta_data['width'];
                                                        $data['height'] = $meta_data['height'];
                                                        $d['title'] = esc_attr(nggGallery::i18n(stripslashes($image->title), 'gal_' . $image->gid . '_title'));
                                                        if ($d['title'] != '') {
                                                            $data['title'] = $d['title'];
                                                        }
                                                        if ($ng_count == 'yes') {
                                                            $description_fragments = array($photo_count_by_gallery_id[$album_content] . ' ' . _n('Photo', 'Photos', $photo_count_by_gallery_id[$album_content], 'jig_td'));
                                                            if ($image->galdesc !== '') {
                                                                $description_fragments[] = nggGallery::i18n(stripslashes($image->galdesc), 'gal_' . $image->gid . '_description');
                                                            }
                                                            $d['description'] = esc_attr(stripslashes(implode('<br />', $description_fragments)));
                                                        } else {
                                                            $d['description'] = esc_attr(nggGallery::i18n(stripslashes($image->galdesc), 'gal_' . $image->gid . '_description'));
                                                        }
                                                        if ($d['description'] != '') {
                                                            $data['description'] = $d['description'];
                                                        }
                                                        if ($this->ng_version == 2) {
                                                            if (empty($image->pageid)) {
                                                                $d['link'] = $this->jig_ng_get_permalink(array('album' => $album->slug, 'gallery' => $image->slug));
                                                            } else {
                                                                $d['link'] = get_permalink($image->pageid);
                                                            }
                                                        } else {
                                                            if ($ngg_options['galNoPages']) {
                                                                if ($ngg_options['usePermalinks']) {
                                                                    $d['link'] = $this->jig_ng_get_permalink(array('album' => $album->slug, 'gallery' => $image->slug));
                                                                } else {
                                                                    $d['link'] = $this->jig_ng_get_permalink(array('album' => $album->id, 'gallery' => $image->gid));
                                                                }
                                                            } else {
                                                                $d['link'] = get_permalink($image->pageid);
                                                            }
                                                        }
                                                        if ($ng_lightbox_gallery == 'yes' && isset($shadow_gallery)) {
                                                            $d['link'] = NULL;
                                                            $data['gallery']['html'] = $shadow_gallery;
                                                            $data['gallery']['rel'] = $shadow_rel;
                                                            $data['gallery']['id'] = $shadow_group_id;
                                                            if (isset($data['title'])) {
                                                                $data['gallery']['title'] = $data['title'];
                                                            }
                                                            if (isset($data['description'])) {
                                                                $data['gallery']['description'] = $data['description'];
                                                            }
                                                            $d['title'] = esc_attr(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
                                                            if ($d['title'] != '') {
                                                                $data['title'] = $d['title'];
                                                            } else {
                                                                unset($data['title']);
                                                            }
                                                            $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description'))));
                                                            if ($ng_display_tags == 'yes') {
                                                                $d['tags'] = ucwords(implode(', ', wp_get_object_terms($image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                                if (!empty($d['tags'])) {
                                                                    $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                                }
                                                            }
                                                            if ($d['description'] != '') {
                                                                $data['description'] = $d['description'];
                                                            } else {
                                                                unset($data['description']);
                                                            }
                                                            switch ($lightbox) {
                                                                case 'foobox':
                                                                    $data['gallery']['lightbox_class'] = 'jigFooBoxConnect';
                                                                    break;
                                                                case 'socialgallery':
                                                                    $data['gallery']['lightbox_class'] = 'jigSgConnect';
                                                                    break;
                                                                default:
                                                            }
                                                        }
                                                        if ($download_link != 'no') {
                                                            $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                        }
                                                        if ($d['link'] != '') {
                                                            $data['link'] = $d['link'];
                                                        }
                                                        if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                            $data['extra_class'] = 'jig-contentID-NG-' . $image->pid;
                                                        }
                                                        array_push($this->images, $data);
                                                    }
                                                }
                                            } else {
                                                // If it's an album
                                                $cover_image = $this->jig_ng_find_subalbums($album_content, 'needed', true);
                                                if (!is_null($cover_image)) {
                                                    $meta_data = $cover_image->meta_data;
                                                    $url_hash_list = array();
                                                    // Create a new array for the images
                                                    if (!$meta_data['width'] || !$meta_data['height']) {
                                                        $url_hash_list[] = hash('md5', $cover_image->imageURL);
                                                    }
                                                    $cover_image->jig_image_src = array($cover_image->imageURL, $meta_data['width'], $meta_data['height']);
                                                    // this prepopulates wp_cache with the dimensions, if found
                                                    if (!$this->jig_query_ext_images($url_hash_list)) {
                                                        $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                                    }
                                                    if (!$cover_image->jig_image_src[1] || !$cover_image->jig_image_src[2]) {
                                                        // If any of the dimensions are not a normal value
                                                        $cover_image->jig_image_src = $this->jig_get_ext_imagesize($cover_image->jig_image_src);
                                                    }
                                                    $meta_data['width'] = $cover_image->jig_image_src[1];
                                                    $meta_data['height'] = $cover_image->jig_image_src[2];
                                                    if ($meta_data['width'] != 0 && $meta_data['height'] != 0) {
                                                        // If none of the dimensions are 0
                                                        $data = $d = array();
                                                        // Create 2 arrays for this image one temporary and one that gets pushed
                                                        $data['url'] = $cover_image->jig_image_src[0];
                                                        $data['width'] = $meta_data['width'];
                                                        $data['height'] = $meta_data['height'];
                                                        $d['title'] = esc_attr(stripslashes($cover_image->jig['name']));
                                                        if ($d['title'] != '') {
                                                            $data['title'] = $d['title'];
                                                        }
                                                        if ($ng_count == 'yes') {
                                                            $description_fragments = $counter_fragments = array();
                                                            if ($cover_image->jig['albumCount'] > 0) {
                                                                $counter_fragments[] = $cover_image->jig['albumCount'] . '&nbsp;' . _n('Album', 'Albums', $cover_image->jig['albumCount'], 'jig_td');
                                                            }
                                                            if ($cover_image->jig['galleryCount'] > 0) {
                                                                $counter_fragments[] = $cover_image->jig['galleryCount'] . '&nbsp;' . _n('Gallery', 'Galleries', $cover_image->jig['galleryCount'], 'jig_td');
                                                            }
                                                            $description_fragments[] = implode(', ', $counter_fragments);
                                                            if (empty($description_fragments[0])) {
                                                                unset($description_fragments);
                                                            }
                                                            if ($cover_image->jig['albumdesc'] != '') {
                                                                $description_fragments[] = $cover_image->jig['albumdesc'];
                                                            }
                                                            $d['description'] = esc_attr(stripslashes(implode('<br />', $description_fragments)));
                                                        } else {
                                                            $d['description'] = esc_attr(stripslashes($cover_image->jig['albumdesc']));
                                                        }
                                                        if ($d['description'] != '') {
                                                            $data['description'] = $d['description'];
                                                        }
                                                        if (empty($cover_image->jig['pageid'])) {
                                                            if ($this->ng_version == 2) {
                                                                $d['link'] = $this->jig_ng_get_permalink(array('album' => $cover_image->jig['slug'], 'gallery' => false));
                                                            } else {
                                                                if ($ngg_options['usePermalinks']) {
                                                                    $d['link'] = $this->jig_ng_get_permalink(array('album' => $cover_image->jig['slug'], 'gallery' => false));
                                                                } else {
                                                                    $d['link'] = $this->jig_ng_get_permalink(array('album' => $cover_image->jig['id'], 'gallery' => false));
                                                                }
                                                            }
                                                        } else {
                                                            $d['link'] = get_permalink($cover_image->jig['pageid']);
                                                            $data['link_target'] = $link_target;
                                                        }
                                                        if ($d['link'] != '') {
                                                            $data['link'] = $d['link'];
                                                        }
                                                        if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                            $data['extra_class'] = 'jig-contentID-NG-' . $cover_image->pid;
                                                        }
                                                        array_push($this->images, $data);
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        return $this->frontend_stop(sprintf(__('There is no content in the NextGEN album: "%1$s"!', 'jig_td'), stripcslashes($album->name)));
                                    }
                                } else {
                                    return $this->frontend_stop(sprintf(__('There is no content in the NextGEN album: "%1$s"!', 'jig_td'), stripcslashes($album->name)));
                                }
                            } else {
                                return $this->frontend_stop(sprintf(__('There is no NextGEN album with the ID: "%1$s"!', 'jig_td'), $ng_album));
                            }
                        } else {
                            if ($ng_pics !== '' || $ng_recent_images !== '' || $ng_random_images !== '' || $ng_search_query !== '') {
                                if ($ng_pics) {
                                    if (strpos($ng_pics, '-') !== false) {
                                        $ng_pics_exploded = explode(',', $ng_pics);
                                        foreach ($ng_pics_exploded as &$single_ng_pic) {
                                            if (strpos($single_ng_pic, '-') !== false) {
                                                $ng_pic_range = explode('-', $single_ng_pic);
                                                $single_ng_pic = implode(',', range($ng_pic_range[0], $ng_pic_range[1]));
                                            }
                                        }
                                        $ng_pics = implode(',', $ng_pics_exploded);
                                    }
                                    $images = $this->jig_ng_find_images($ng_pics);
                                    if ($orderby == 'rand') {
                                        $images = (array) $images;
                                        shuffle($images);
                                    }
                                } else {
                                    if ($ng_recent_images) {
                                        if ($original_nextgen_limit === '') {
                                            $limit = 25;
                                        }
                                        $images = $this->jig_ng_get_recent_images($ng_recent_images, $limit);
                                        if ($orderby == 'rand') {
                                            $images = (array) $images;
                                            shuffle($images);
                                        }
                                    } else {
                                        if ($ng_random_images) {
                                            if ($original_nextgen_limit === '') {
                                                $limit = 25;
                                            }
                                            $images = $this->jig_ng_get_random_images($limit, $ng_random_images);
                                        } else {
                                            if ($ng_search_query) {
                                                $this->ng_intersect_tags = $ng_intersect_tags;
                                                $images = $this->jig_ng_image_search($ng_search_query, $ng_search_options, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                                                if (empty($images)) {
                                                    return $this->frontend_stop(__('There are no photos that match your search query.', 'jig_td'));
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!empty($images)) {
                                    $this->images = $url_hash_list = array();
                                    // Create a new array for the images
                                    foreach ($images as &$image) {
                                        if (!$image->meta_data['width'] || !$image->meta_data['height']) {
                                            $url_hash_list[] = hash('md5', $image->imageURL);
                                        }
                                        $image->jig_image_src = array($image->imageURL, $image->meta_data['width'], $image->meta_data['height']);
                                    }
                                    unset($image);
                                    if (!$this->jig_query_ext_images($url_hash_list)) {
                                        $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                    }
                                    foreach ($images as $image) {
                                        if (!$image->jig_image_src[1] || !$image->jig_image_src[2]) {
                                            // If any of the dimensions are not a normal value
                                            $image->jig_image_src = $this->jig_get_ext_imagesize($image->jig_image_src);
                                        }
                                        $image->meta_data['width'] = $image->jig_image_src[1];
                                        $image->meta_data['height'] = $image->jig_image_src[2];
                                        if ($image->meta_data['width'] != 0 && $image->meta_data['height'] != 0) {
                                            // If none of the dimensions are 0
                                            $data = $d = array();
                                            // Create 2 arrays for this image one temporary and one that gets pushed
                                            $data['url'] = $image->imageURL;
                                            $data['width'] = $image->meta_data['width'];
                                            $data['height'] = $image->meta_data['height'];
                                            $d['title'] = esc_attr(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
                                            if ($d['title'] != '') {
                                                $data['title'] = $d['title'];
                                            }
                                            $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description'))));
                                            if ($ng_display_tags == 'yes') {
                                                $d['tags'] = ucwords(implode(', ', wp_get_object_terms($image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                if (!empty($d['tags'])) {
                                                    $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                }
                                            }
                                            if ($d['description'] != '') {
                                                $data['description'] = $d['description'];
                                            }
                                            if ($download_link != 'no') {
                                                $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                            }
                                            if (isset($image->ng_cf_link)) {
                                                $data['link'] = $image->ng_cf_link;
                                                $data['link_target'] = $link_target;
                                            }
                                            if ($filterby == 'on') {
                                                $d['filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                                if (!empty($d['filters'])) {
                                                    foreach ($d['filters'] as $filter_term) {
                                                        $data['filters'][] = array($filter_term->slug, $filter_term->name);
                                                    }
                                                }
                                            } elseif ($filterby == 'ng_galleries') {
                                                if (!empty($image->slug) && !empty($image->title)) {
                                                    $data['filters'][] = array($image->slug, $image->title);
                                                }
                                            }
                                            if ($l2_filterby == 'on') {
                                                $d['L2filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                                if (!empty($d['L2filters'])) {
                                                    foreach ($d['L2filters'] as $filter_term) {
                                                        $data['L2filters'][] = array($filter_term->slug, $filter_term->name);
                                                    }
                                                }
                                            } elseif ($l2_filterby == 'ng_galleries') {
                                                if (!empty($image->slug) && !empty($image->title)) {
                                                    $data['L2filters'][] = array($image->slug, $image->title);
                                                }
                                            }
                                            if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                $data['extra_class'] = 'jig-contentID-NG-' . $image->pid;
                                            }
                                            array_push($this->images, $data);
                                        }
                                    }
                                } else {
                                    return $this->frontend_stop(__('There are no NextGEN images that could be displayed.', 'jig_td'));
                                }
                            } else {
                                if ($ng_tags_gallery) {
                                    $this->ng_intersect_tags = $ng_intersect_tags;
                                    $images = $this->jig_ng_find_images_for_tags($ng_tags_gallery, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                                    if (!empty($images)) {
                                        $this->images = $url_hash_list = array();
                                        // Create a new array for the images
                                        $counter = 0;
                                        $images = $this->jig_ng_process_images($images);
                                        // Very important, sets up the image objects, mimics NG
                                        foreach ($images as &$image) {
                                            if (++$counter > $limit) {
                                                break;
                                            }
                                            if (!$image->meta_data['width'] || !$image->meta_data['height']) {
                                                $url_hash_list[] = hash('md5', $image->imageURL);
                                            }
                                            $image->jig_image_src = array($image->imageURL, $image->meta_data['width'], $image->meta_data['height']);
                                        }
                                        unset($image);
                                        if (!$this->jig_query_ext_images($url_hash_list)) {
                                            $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                        }
                                        $counter = 0;
                                        foreach ($images as $image) {
                                            if (++$counter > $limit) {
                                                break;
                                            }
                                            if (!$image->jig_image_src[1] || !$image->jig_image_src[2]) {
                                                // If any of the dimensions are not a normal value
                                                $image->jig_image_src = $this->jig_get_ext_imagesize($image->jig_image_src);
                                            }
                                            $image->meta_data['width'] = $image->jig_image_src[1];
                                            $image->meta_data['height'] = $image->jig_image_src[2];
                                            if ($image->meta_data['width'] != 0 && $image->meta_data['height'] != 0) {
                                                // If none of the dimensions are 0
                                                $data = $d = array();
                                                // Create 2 arrays for this image one temporary and one that gets pushed
                                                $data['url'] = $image->imageURL;
                                                $data['width'] = $image->meta_data['width'];
                                                $data['height'] = $image->meta_data['height'];
                                                $d['title'] = esc_attr(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
                                                if ($d['title'] != '') {
                                                    $data['title'] = $d['title'];
                                                }
                                                $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description'))));
                                                if ($ng_display_tags == 'yes') {
                                                    $d['tags'] = ucwords(implode(', ', wp_get_object_terms($image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                    if (!empty($d['tags'])) {
                                                        $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                    }
                                                }
                                                if ($d['description'] != '') {
                                                    $data['description'] = $d['description'];
                                                }
                                                if ($download_link != 'no') {
                                                    $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                }
                                                if (isset($image->ng_cf_link)) {
                                                    $data['link'] = $image->ng_cf_link;
                                                    $data['link_target'] = $link_target;
                                                }
                                                if ($filterby == 'on') {
                                                    $d['filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                                    if (!empty($d['filters'])) {
                                                        foreach ($d['filters'] as $filter_term) {
                                                            $data['filters'][] = array($filter_term->slug, $filter_term->name);
                                                        }
                                                    }
                                                } elseif ($filterby == 'ng_galleries') {
                                                    if (!empty($image->slug) && !empty($image->title)) {
                                                        $data['filters'][] = array($image->slug, $image->title);
                                                    }
                                                }
                                                if ($l2_filterby == 'on') {
                                                    $d['L2filters'] = wp_get_object_terms($image->pid, 'ngg_tag');
                                                    if (!empty($d['L2filters'])) {
                                                        foreach ($d['L2filters'] as $filter_term) {
                                                            $data['L2filters'][] = array($filter_term->slug, $filter_term->name);
                                                        }
                                                    }
                                                } elseif ($l2_filterby == 'ng_galleries') {
                                                    if (!empty($image->slug) && !empty($image->title)) {
                                                        $data['L2filters'][] = array($image->slug, $image->title);
                                                    }
                                                }
                                                if (!empty($ng_narrow_by_tags)) {
                                                    $ng_image_tags = wp_get_object_terms($image->pid, 'ngg_tag');
                                                    if (!empty($ng_image_tags)) {
                                                        foreach ($ng_image_tags as $filter_term) {
                                                            if (in_array($filter_term->slug, $ng_narrow_by_tags) || in_array($filter_term->name, $ng_narrow_by_tags)) {
                                                                $ng_tag_found_in_image = true;
                                                                break;
                                                            }
                                                        }
                                                        if (!isset($ng_tag_found_in_image)) {
                                                            unset($ng_tag_found_in_image);
                                                            continue;
                                                            // Don't add this image to the images if it's missing the tag(s)
                                                        }
                                                    } else {
                                                        continue;
                                                        // Don't add this image to the images if it's missing ANY tag(s)
                                                    }
                                                    unset($ng_image_tags, $ng_tag_found_in_image);
                                                }
                                                if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                    $data['extra_class'] = 'jig-contentID-NG-' . $image->pid;
                                                }
                                                array_push($this->images, $data);
                                            }
                                        }
                                    } else {
                                        return $this->frontend_stop(__('No images could be found with that tag.', 'jig_td'));
                                    }
                                } else {
                                    if ($ng_tags_album) {
                                        $this->ng_intersect_tags = $ng_intersect_tags;
                                        $images = $this->jig_ng_find_images_for_tags($ng_tags_album, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit, true);
                                        if (!empty($images)) {
                                            $this->images = $url_hash_list = array();
                                            // Create a new array for the images
                                            $images = $this->jig_ng_process_images($images);
                                            // Very important, sets up the image objects, mimics NG
                                            foreach ($images as &$image) {
                                                if (empty($image)) {
                                                    unset($image);
                                                    continue;
                                                }
                                                if (!$image->meta_data['width'] || !$image->meta_data['height']) {
                                                    $url_hash_list[] = hash('md5', $image->imageURL);
                                                }
                                                $image->jig_image_src = array($image->imageURL, $image->meta_data['width'], $image->meta_data['height']);
                                            }
                                            unset($image);
                                            if (!$this->jig_query_ext_images($url_hash_list)) {
                                                $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                            }
                                            foreach ($images as $image) {
                                                if (empty($image)) {
                                                    unset($image);
                                                    continue;
                                                }
                                                if ($ng_lightbox_gallery == 'yes') {
                                                    // If gallery should be displayed as a lightbox
                                                    $lightbox_images = $this->jig_ng_find_images_for_tags($image->slug, $ngg_options['galSort'], $ngg_options['galSortDir'], $limit);
                                                    if (!empty($lightbox_images)) {
                                                        $lightbox_images = $this->jig_ng_process_images($lightbox_images);
                                                        // Very important, sets up the image objects, mimics NG
                                                        $shadow_galleries[] = $shadow_group_id = "jig{$jig_id}-hiddenGalleryGroup-" . $image->slug;
                                                        $shadow_gallery = '<div class="jig-hiddenGallery">';
                                                        if (stripos($link_rel, '*instance*') !== false) {
                                                            $shadow_rel = str_replace('*instance*', 'NG-' . $image->slug, $link_rel);
                                                        } else {
                                                            switch ($lightbox) {
                                                                case 'prettyphoto':
                                                                    $shadow_rel = 'prettyPhoto[ngg-' . $image->slug . ']';
                                                                    break;
                                                                case 'colorbox':
                                                                    $shadow_rel = 'colorBox[ngg-' . $image->slug . ']';
                                                                    break;
                                                                case 'foobox':
                                                                    $shadow_rel = 'foobox[ngg-' . $image->slug . ']';
                                                                    break;
                                                                default:
                                                                    $shadow_rel = 'jig[ngg-' . $image->slug . ']';
                                                                    break;
                                                            }
                                                        }
                                                        if ($lightbox == 'photoswipe') {
                                                            foreach ($lightbox_images as &$lightbox_image) {
                                                                if (!$lightbox_image->meta_data['width'] || !$lightbox_image->meta_data['height']) {
                                                                    $url_hash_list[] = hash('md5', $lightbox_image->imageURL);
                                                                }
                                                                $lightbox_image->jig_image_src = array($lightbox_image->imageURL, $lightbox_image->meta_data['width'], $lightbox_image->meta_data['height']);
                                                            }
                                                            unset($lightbox_image);
                                                            // this prepopulates wp_cache with the dimensions, if found
                                                            if (!$this->jig_query_ext_images($url_hash_list)) {
                                                                $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                                                            }
                                                        }
                                                        foreach ($lightbox_images as $lightbox_image) {
                                                            // Skip image from the hidden gallery if it's the same as the opener image
                                                            if ($lightbox_image->filename == $image->filename) {
                                                                continue;
                                                            }
                                                            $data = $d = array();
                                                            // Create 2 arrays for this image one temporary and one that gets pushed
                                                            $data['url'] = $lightbox_image->imageURL;
                                                            $d['title'] = esc_attr(stripslashes(nggGallery::i18n($lightbox_image->alttext, 'pic_' . $lightbox_image->pid . '_alttext')));
                                                            $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($lightbox_image->description, 'pic_' . $lightbox_image->pid . '_description'))));
                                                            if ($ng_display_tags == 'yes') {
                                                                $d['tags'] = ucwords(implode(', ', wp_get_object_terms($lightbox_image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                                if (!empty($d['tags'])) {
                                                                    $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                                }
                                                            }
                                                            $title_fragment = isset($d[$link_title_field]) ? $d[$link_title_field] : '';
                                                            $alt_fragment = isset($d[$img_alt_field]) ? $d[$img_alt_field] : '';
                                                            if ($download_link != 'no') {
                                                                $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                                if ($download_link == 'yes') {
                                                                    if ($title_fragment !== '') {
                                                                        $title_fragment .= $separator_character . $data['download'];
                                                                    } else {
                                                                        $title_fragment = $data['download'];
                                                                    }
                                                                } else {
                                                                    if ($alt_fragment !== '') {
                                                                        $alt_fragment .= $separator_character . $data['download'];
                                                                    } else {
                                                                        $alt_fragment = $data['download'];
                                                                    }
                                                                }
                                                            }
                                                            if ($lightbox == 'photoswipe') {
                                                                if (!$lightbox_image->jig_image_src[1] || !$lightbox_image->jig_image_src[2]) {
                                                                    // If any of the dimensions are not a normal value
                                                                    $lightbox_image->jig_image_src = $this->jig_get_ext_imagesize($lightbox_image->jig_image_src);
                                                                }
                                                                $lightbox_image->meta_data['width'] = $lightbox_image->jig_image_src[1];
                                                                $lightbox_image->meta_data['height'] = $lightbox_image->jig_image_src[2];
                                                                if ($lightbox_image->meta_data['width'] != 0 && $lightbox_image->meta_data['height'] != 0) {
                                                                    // If none of the dimensions are 0
                                                                    $shadow_size = ' data-wh="' . $lightbox_image->meta_data['width'] . 'x' . $lightbox_image->meta_data['height'] . '"';
                                                                } else {
                                                                    continue;
                                                                }
                                                            } else {
                                                                $shadow_size = '';
                                                            }
                                                            $shadow_class = 'class="jig-link jig-contentID-NG-' . $lightbox_image->pid . (empty($link_class) ? '' : ' ' . $link_class) . '" ';
                                                            $shadow_gallery .= '<a href="' . $data['url'] . '" rel="' . $shadow_rel . '" ' . $shadow_class . $shadow_size . ' title="' . $title_fragment . '"><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="' . $alt_fragment . '" /></a>';
                                                        }
                                                        $shadow_gallery .= "</div>";
                                                        $image->count = count((array) $lightbox_images);
                                                    }
                                                }
                                                if (!$image->jig_image_src[1] || !$image->jig_image_src[2]) {
                                                    // If any of the dimensions are not a normal value
                                                    $image->jig_image_src = $this->jig_get_ext_imagesize($image->jig_image_src);
                                                }
                                                $image->meta_data['width'] = $image->jig_image_src[1];
                                                $image->meta_data['height'] = $image->jig_image_src[2];
                                                if ($image->meta_data['width'] != 0 && $image->meta_data['height'] != 0) {
                                                    // If none of the dimensions are 0
                                                    $data = $d = array();
                                                    // Create 2 arrays for this image one temporary and one that gets pushed
                                                    $data['url'] = $image->imageURL;
                                                    $data['width'] = $image->meta_data['width'];
                                                    $data['height'] = $image->meta_data['height'];
                                                    $d['title'] = esc_attr(stripslashes($image->name));
                                                    if ($d['title'] != '') {
                                                        $data['title'] = ucfirst(nggGallery::i18n($d['title'], 'tag_' . $d['title']));
                                                    }
                                                    $d['description'] = esc_attr(stripslashes($image->count . ' ' . __('Photos', 'nggallery')));
                                                    if ($d['description'] != '') {
                                                        $data['description'] = $d['description'];
                                                    }
                                                    $d['link'] = $this->jig_ng_get_permalink(array('gallerytag' => $image->slug));
                                                    if ($ng_lightbox_gallery == 'yes' && isset($shadow_gallery)) {
                                                        $d['link'] = NULL;
                                                        $data['gallery']['html'] = $shadow_gallery;
                                                        $data['gallery']['rel'] = $shadow_rel;
                                                        $data['gallery']['id'] = $shadow_group_id;
                                                        if (isset($data['title'])) {
                                                            $data['gallery']['title'] = $data['title'];
                                                        }
                                                        if (isset($data['description'])) {
                                                            $data['gallery']['description'] = $data['description'];
                                                        }
                                                        $d['title'] = esc_attr(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
                                                        if ($d['title'] != '') {
                                                            $data['title'] = $d['title'];
                                                        } else {
                                                            unset($data['title']);
                                                        }
                                                        $d['description'] = trim(esc_attr(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description'))));
                                                        if ($ng_display_tags == 'yes') {
                                                            $d['tags'] = ucwords(implode(', ', wp_get_object_terms($image->pid, 'ngg_tag', array('fields' => 'names'))));
                                                            if (!empty($d['tags'])) {
                                                                $d['description'] = esc_attr(($d['description'] != '' ? $d['description'] . $separator_character : '') . '<i>' . $d['tags'] . '</i>');
                                                            }
                                                        }
                                                        if ($d['description'] != '') {
                                                            $data['description'] = $d['description'];
                                                        } else {
                                                            unset($data['description']);
                                                        }
                                                        switch ($lightbox) {
                                                            case 'foobox':
                                                                $data['gallery']['lightbox_class'] = 'jigFooBoxConnect';
                                                                break;
                                                            case 'socialgallery':
                                                                $data['gallery']['lightbox_class'] = 'jigSgConnect';
                                                                break;
                                                            default:
                                                        }
                                                    }
                                                    if ($download_link != 'no') {
                                                        $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                    }
                                                    if ($d['link']) {
                                                        $data['link'] = $d['link'];
                                                    }
                                                    if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                        $data['extra_class'] = 'jig-contentID-NG-' . $image->pid;
                                                    }
                                                    array_push($this->images, $data);
                                                }
                                            }
                                        } else {
                                            return $this->frontend_stop(__('No images could be found with that tag.', 'jig_td'));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // NG custom breadcrumb
                    $ng_bc_album_need = true;
                    if ($ng_breadcrumb == 'yes') {
                        // If the breadcrumb feature is enabled
                        $query_gallery = $this->jig_ng_get_query_var('gallery');
                        $query_album = $this->jig_ng_get_query_var('album');
                        $query_tags = $this->jig_ng_get_query_var('gallerytag');
                        $ng_breadcrumb_output = array();
                        if ($ng_bc_base !== '' && $ng_bc_base !== 'none') {
                            $ng_breadcrumb_output[0] = $ng_bc_base . ' ';
                        }
                        if (isset($ng_bc_home_album)) {
                            // If there was an album id originally
                            if ($ng_bc_home_album !== 'all' && $ng_bc_home_album != "0") {
                                // And it was a single particular album
                                // Get the album's name from the cache or the db
                                $ng_bc_home_album_object = wp_cache_get($ng_bc_home_album, 'jig_ng_albums');
                                if ($ng_bc_home_album_object !== false) {
                                    $ng_bc_home_output = stripcslashes(nggGallery::i18n($ng_bc_home_album_object->name, 'album_' . $ng_bc_home_album_object->id . '_name'));
                                } else {
                                    $ng_bc_home_album_object = $wpdb->get_row($wpdb->prepare("SELECT name,slug,id FROM {$wpdb->nggalbum} WHERE id = %d", $ng_bc_home_album));
                                    $ng_bc_home_output = stripcslashes(nggGallery::i18n($ng_bc_home_album_object->name, 'album_' . $ng_bc_home_album_object->id . '_name'));
                                }
                                // If the original album is the same as the currently displayed album, don't show the album part of the breadcrumb
                                if (!empty($query_album) && ($ng_bc_home_album_object->slug == $query_album || $ng_bc_home_album_object->id == $query_album)) {
                                    $ng_bc_album_need = false;
                                }
                            } else {
                                // If the album was an overview
                                $ng_bc_home_output = __('Album overview', 'jig_td');
                            }
                        } else {
                            // If the original shortcode wasn't an album, fall back to post title
                            $ng_bc_home_output = $post->post_title;
                        }
                        switch ($ng_bc_home) {
                            // Different home styles
                            case 'post_title':
                                $ng_bc_home_output = $post->post_title;
                                break;
                            case 'custom_text':
                                $ng_bc_home_output = $ng_bc_home_text;
                                break;
                            case 'album_name':
                                // Leave $ng_bc_home_output as it is, it was previously created
                                break;
                            case 'none':
                            default:
                                $ng_bc_home_output = '';
                        }
                        if ($ng_bc_home !== 'none' && $ng_bc_home_clickable == 'yes' && empty($query_album) && empty($query_gallery) && empty($query_tags) && $ng_bc_last_clickable == 'yes' || $ng_bc_home !== 'none' && $ng_bc_home_clickable == 'yes' && (!empty($query_album) || !empty($query_gallery) || !empty($query_tags))) {
                            // Get the current URL using WP Class
                            global $wp, $wp_rewrite;
                            $ng_home_permalink = home_url(add_query_arg(array(), $wp->request));
                            $ngoptions = get_option('ngg_options');
                            $ng_permalink_slug = !empty($ngoptions['router_param_slug']) ? $ngoptions['router_param_slug'] : $ngoptions['permalinkSlug'];
                            // If the permalink slug is in the URL, return the true base URL
                            $slug_position = strripos($ng_home_permalink, $ng_permalink_slug);
                            if ($slug_position !== false) {
                                $ng_home_permalink = substr($ng_home_permalink, 0, $slug_position);
                            }
                            // Trailing slash it
                            $ng_home_permalink = trailingslashit($ng_home_permalink);
                            // If WP permalinks are off this makes the home element detect the origin page or post...
                            global $query_string;
                            if ($wp_rewrite->using_permalinks() !== true && !empty($query_string)) {
                                $ng_home_permalink .= '?' . remove_query_arg(array('album', 'gallery', 'gallerytag'), $query_string);
                                $ng_home_permalink = untrailingslashit(urldecode($ng_home_permalink));
                            }
                            $ng_breadcrumb_output[0] .= '<a href="' . esc_url($ng_home_permalink) . '" >' . $ng_bc_home_output . '</a>';
                        } else {
                            // If it's not clickable just show it as-is
                            $ng_breadcrumb_output[0] .= $ng_bc_home_output;
                        }
                        // Album part
                        if (!empty($query_album) && $query_album !== 'all' && $ng_bc_album_need === true) {
                            if (is_numeric($query_album)) {
                                $album = $wpdb->get_row($wpdb->prepare("SELECT name,id FROM {$wpdb->nggalbum} WHERE id = %d LIMIT 0,1", $query_album));
                            }
                            if (!is_numeric($query_album) || is_numeric($query_album) && empty($album)) {
                                $album = $wpdb->get_row($wpdb->prepare("SELECT name,id FROM {$wpdb->nggalbum} WHERE slug = %s LIMIT 0,1", $query_album));
                            }
                            $album_text = stripcslashes(nggGallery::i18n($album->name, 'album_' . $album->id . '_name'));
                            if (empty($query_gallery) && $ng_bc_last_clickable == 'no') {
                                $ng_breadcrumb_output[] = $album_text;
                            } else {
                                global $wp_query;
                                $wp_query->set('gallery', false);
                                $ng_breadcrumb_output[] = '<a href="' . $this->jig_ng_get_permalink(array('gallery' => false, 'album' => $query_album, 'nggpage' => false)) . '">' . $album_text . '</a>';
                                $wp_query->set('gallery', $query_gallery);
                            }
                        }
                        // Gallery part
                        if (!empty($query_gallery)) {
                            // Needed by the breadcrumb
                            if (is_numeric($query_gallery)) {
                                $gallery = $wpdb->get_row($wpdb->prepare("SELECT title,gid FROM {$wpdb->nggallery} WHERE gid = %d LIMIT 0,1", $query_gallery));
                            }
                            if (!is_numeric($query_gallery) || is_numeric($query_gallery) && empty($gallery)) {
                                $gallery = $wpdb->get_row($wpdb->prepare("SELECT title,gid FROM {$wpdb->nggallery} WHERE slug = %s LIMIT 0,1", $query_gallery));
                            }
                            $gallery_text = nggGallery::i18n(stripslashes($gallery->title), 'gal_' . $gallery->gid . '_title');
                            if ($ng_bc_last_clickable == 'no') {
                                $ng_breadcrumb_output[] = $gallery_text;
                            } else {
                                $ng_breadcrumb_output[] = '<a href="' . $this->jig_ng_get_permalink(array('album' => !empty($query_album) ? $query_album : false, 'gallery' => !empty($query_gallery) ? $query_gallery : false)) . '" >' . $gallery_text . '</a>';
                            }
                        }
                        // Tags (gallery) part
                        if (!empty($query_tags)) {
                            $tagname = ucfirst($wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->terms} WHERE slug = %s", $query_tags)));
                            if ($ng_bc_last_clickable == 'no') {
                                $ng_breadcrumb_output[] = nggGallery::i18n($tagname, 'tag_' . $tagname);
                            } else {
                                $ng_breadcrumb_output[] = '<a href="' . $this->jig_ng_get_permalink(array('gallerytag' => $query_tags)) . '" >' . nggGallery::i18n($tagname, 'tag_' . $tagname) . '</a>';
                            }
                        }
                        switch ($ng_bc_separator) {
                            case 'default':
                                $ng_bc_separator = ' &raquo;';
                                break;
                            case 'greater':
                                $ng_bc_separator = ' &gt;';
                                break;
                            case 'comma':
                                $ng_bc_separator = ',';
                                break;
                            case 'slash':
                                $ng_bc_separator = ' /';
                                break;
                            case 'doubleslash':
                                $ng_bc_separator = ' //';
                                break;
                            case 'minus':
                                $ng_bc_separator = ' -';
                                break;
                            case 'plus':
                                $ng_bc_separator = ' +';
                                break;
                            case 'arrow':
                                $ng_bc_separator = ' &rarr;';
                                break;
                            case 'bslash':
                                $ng_bc_separator = ' \\';
                                break;
                            case 'doublebslash':
                                $ng_bc_separator = ' \\\\';
                                break;
                            case 'middledot':
                                $ng_bc_separator = ' ·';
                                break;
                            case 'dobulecolon':
                                $ng_bc_separator = ' ::';
                                break;
                            case 'numbersign':
                                $ng_bc_separator = ' #';
                                break;
                        }
                        // Join the breadcrumb parts together with the separator as a glue, with spaces
                        $ng_breadcrumb_output_joined = implode($ng_bc_separator . ' ', $ng_breadcrumb_output);
                        // If an extra separator is needed at the end, add it
                        if ($ng_bc_add_separator == 'yes') {
                            $ng_breadcrumb_output_joined .= $ng_bc_separator;
                        }
                        // Display it if this is the jig-connected NG instance or the top level is forced
                        if (isset($jigNgConnect) || $ng_bc_top_level == 'yes') {
                            $notice_before = '<div class="jig-ngBreadcrumb">' . $ng_breadcrumb_output_joined . '</div>' . $notice_before;
                        }
                    }
                    // end of NG custom breadcrumb
                    break;
                case 'facebook':
                    if (!isset($this->settings['fb_authed'][$facebook_id])) {
                        return $this->frontend_stop(__('That Facebook ID is unauthorized for use, please go to Settings and add it.', 'jig_td'));
                    }
                    $user = $this->settings['fb_authed'][$facebook_id];
                    $token = $user['access_token'];
                    if (empty($token) || $token == 'public') {
                        if (!empty($this->settings['fb_app_id']) && !empty($this->settings['fb_app_secret'])) {
                            $token = $this->settings['fb_app_id'] . '|' . $this->settings['fb_app_secret'];
                        } else {
                            $output = array('error' => __('Justified Image Grid: To access any Facebook content, you must create a simple Facebook App first (and fill App ID and App Secret fields).', 'jig_td'));
                            echo json_encode($output);
                            die;
                        }
                    }
                    if ($limit === "0") {
                        $limit = 500;
                        $limit_parameter = "&limit=500";
                    } else {
                        if ($limit !== '') {
                            $limit_parameter = "&limit=" . $limit;
                        } else {
                            $limit = 25;
                            // mimic the default limit
                            $limit_parameter = '';
                        }
                    }
                    $facebook_album = str_replace(' ', '', $facebook_album);
                    // Multi album mode
                    if (strpos($facebook_album, ',') !== false || $fb_album_exclude == 'yes' || $facebook_album == 'latestone') {
                        $facebook_album_multi = explode(',', $facebook_album);
                        $facebook_album = 'overview';
                        $limit = 500;
                        $limit_parameter = "&limit=500";
                        // When user selects some from the bottom, don't cut it off because of the default 25 limit
                    }
                    // For any of the overview modes
                    if ($facebook_album == 'overview' || $facebook_album == 'overview_only_albums') {
                        if ($fb_lightbox_album == 'yes') {
                            if (empty($facebook_album_multi) || !empty($facebook_album_multi) && $fb_album_exclude == 'yes') {
                                // Preventing showing everything at once with lightbox albums.
                                $preliminary_count_check_albums_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '?fields=albums.limit(' . $limit . ').fields(count)&access_token=' . $token;
                                $preliminary_count_check_albums = $this->facebook_api_call($preliminary_count_check_albums_url, $facebook_caching, $limit);
                                if (!empty($preliminary_count_check_albums) && empty($preliminary_count_check_albums['message'])) {
                                    $total_count = 0;
                                    foreach ($preliminary_count_check_albums as $preliminary_count_check_album) {
                                        if (!empty($preliminary_count_check_album->count)) {
                                            $total_count += min($preliminary_count_check_album->count, $limit);
                                        }
                                    }
                                } else {
                                    if (!empty($preliminary_count_check_albums['message'])) {
                                        return $this->frontend_stop(__('Justified Image Grid: The Facebook content cannot be displayed, the error from Facebook:', 'jig_td') . ' ' . $preliminary_count_check_albums['message']);
                                    } else {
                                        return $this->frontend_stop(__('There are no albums.', 'jig_td'));
                                    }
                                }
                                if ($total_count > 2000) {
                                    return $this->frontend_stop(sprintf(__('Too many photos for lightbox albums. Disable "Open albums in lightbox" as you have %d photos. This feature is only suitable for max 2000 photos!', 'jig_td'), $total_count));
                                } else {
                                    $auto_limit = 500;
                                }
                            } else {
                                $auto_limit = 1;
                            }
                            $albums_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '?fields=albums.limit(' . $limit . ').fields(id,cover_photo,link,count,name,description,type,photos.limit(' . $auto_limit . ').fields(images,source,height,width,name))&access_token=' . $token;
                        } else {
                            $albums_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '?fields=albums.limit(' . $limit . ').fields(id,cover_photo,link,count,name,description,type,photos.limit(1).fields(images))&access_token=' . $token;
                        }
                        if (!empty($facebook_album_multi) && $facebook_album_multi[0] == 'latestone') {
                            $facebook_album = 'overview_only_albums';
                            if (count($facebook_album_multi) == 1) {
                                $fb_lightbox_album = 'yes';
                            }
                            $albums_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '?fields=albums.limit(5).fields(id,cover_photo,link,count,name,description,type,photos.limit(' . $limit . ').fields(images,source,height,width,name))&access_token=' . $token;
                            $albums = $this->facebook_api_call($albums_url, $facebook_caching, 5);
                        } else {
                            $albums = $this->facebook_api_call($albums_url, $facebook_caching, $limit);
                        }
                        if (!empty($albums) && empty($albums['message'])) {
                            if ($limit !== '' && count($albums) > $limit) {
                                $albums = array_slice($albums, 0, $limit);
                            }
                            if ($fb_lightbox_album == 'no') {
                                $facebook_album_from_slug = get_query_var($this->settings['fb_overview_slug']);
                                foreach ($albums as $album) {
                                    if ($album->id === $facebook_album_from_slug) {
                                        $album_name = $album->name;
                                        $facebook_album = $facebook_album_from_slug;
                                        break;
                                    }
                                }
                            }
                            global $wp, $query_string, $wp_rewrite, $wp_query;
                            if (!empty($album_name)) {
                                if ($fb_breadcrumb == 'yes') {
                                    $fb_home_permalink = home_url(add_query_arg(array(), $wp->request));
                                    $slug_position = strripos($fb_home_permalink, $this->settings['fb_overview_slug']);
                                    if ($slug_position !== false) {
                                        $fb_home_permalink = substr($fb_home_permalink, 0, $slug_position);
                                    }
                                    if (substr($fb_home_permalink, -1) != '/') {
                                        $fb_home_permalink .= '/';
                                    }
                                    if ($fb_home_permalink == home_url('/') && strlen($query_string) > 0 && strpos($query_string, $this->settings['fb_overview_slug']) !== false) {
                                        $fb_home_permalink .= '?' . remove_query_arg($this->settings['fb_overview_slug'], $query_string);
                                    }
                                    switch ($fb_bc_separator) {
                                        case 'default':
                                            $fb_bc_separator = ' &raquo;';
                                            break;
                                        case 'greater':
                                            $fb_bc_separator = ' &gt;';
                                            break;
                                        case 'comma':
                                            $fb_bc_separator = ',';
                                            break;
                                        case 'slash':
                                            $fb_bc_separator = ' /';
                                            break;
                                        case 'doubleslash':
                                            $fb_bc_separator = ' //';
                                            break;
                                        case 'minus':
                                            $fb_bc_separator = ' -';
                                            break;
                                        case 'plus':
                                            $fb_bc_separator = ' +';
                                            break;
                                        case 'arrow':
                                            $fb_bc_separator = ' &rarr;';
                                            break;
                                        case 'bslash':
                                            $fb_bc_separator = ' \\';
                                            break;
                                        case 'doublebslash':
                                            $fb_bc_separator = ' \\\\';
                                            break;
                                        case 'middledot':
                                            $fb_bc_separator = ' ·';
                                            break;
                                        case 'dobulecolon':
                                            $fb_bc_separator = ' ::';
                                            break;
                                        case 'numbersign':
                                            $fb_bc_separator = ' #';
                                            break;
                                    }
                                    $notice_before .= '<div class="jig-fbBreadcrumb"><a href="' . esc_url($fb_home_permalink) . '">' . ($fb_bc_home_text === '' ? $user['user_name'] : $fb_bc_home_text) . '</a> ' . $fb_bc_separator . ' ' . $album_name . '</div>';
                                    $fb_bc_CSS_needed = true;
                                    if ($facebook_description == 'yes' || $facebook_description == 'above') {
                                        $facebook_description_displayed_already = true;
                                        if (!empty($album->description)) {
                                            if (strpos($album->description, '@') === false) {
                                                $notice_before .= '<p class="jig-fbDescription">' . $album->description . '</p>';
                                            } else {
                                                $notice_before .= '<p class="jig-fbDescription">' . preg_replace('/@\\[[:\\d]+:(.+?)\\]/im', '$1', $album->description) . '</p>';
                                            }
                                        }
                                    }
                                }
                            } else {
                                $this->images = array();
                                // Create a new array for the images
                                $found = 0;
                                $facebook_overview_caching = $this->settings['facebook_overview_caching'];
                                if ($orderby == 'rand') {
                                    $albums = (array) $albums;
                                    shuffle($albums);
                                }
                                if ($retina_ready == 'yes') {
                                    $calculated_max_height = $max_height * 3;
                                } else {
                                    $calculated_max_height = $max_height;
                                }
                                foreach ($albums as $key => $album) {
                                    if ($facebook_album == 'overview_only_albums' && $album->type !== 'normal') {
                                        continue;
                                    } elseif (!empty($facebook_album_multi) && $facebook_album_multi[0] !== 'latestone' && ($fb_album_exclude == 'yes' && in_array($album->id, $facebook_album_multi) || $fb_album_exclude == 'no' && !in_array($album->id, $facebook_album_multi))) {
                                        continue;
                                    }
                                    if (!empty($album->count) && !empty($album->link) && !empty($album->photos->data)) {
                                        if ($fb_lightbox_album == 'no' && $fb_actual_cover_photo == 'yes' && !empty($album->cover_photo)) {
                                            // Since FB has a cover_photo in the album, it can be queried directly, this is a request for just one single photo.
                                            if (is_string($album->cover_photo)) {
                                                $fb_cover_photo_url = 'https://graph.facebook.com/v2.4/' . $album->cover_photo . '?fields=images&access_token=' . $token;
                                            } elseif (!empty($album->cover_photo->id)) {
                                                $fb_cover_photo_url = 'https://graph.facebook.com/v2.4/' . $album->cover_photo->id . '?fields=images&access_token=' . $token;
                                            }
                                            // Shared album (created by multiple people) cover photo (manual) is not sent properly by the Facebook API
                                            if ($facebook_overview_caching > 0) {
                                                if (get_transient('jigfb_' . md5($fb_cover_photo_url . $facebook_overview_caching)) == true) {
                                                    $fb_cover_photo_result = get_transient('jigfb_' . md5($fb_cover_photo_url . $facebook_overview_caching));
                                                } else {
                                                    $fb_cover_photo_result = json_decode($this->file_get_contents_curl($fb_cover_photo_url));
                                                    set_transient('jigfb_' . md5($fb_cover_photo_url . $facebook_overview_caching), $fb_cover_photo_result, 60 * $facebook_overview_caching);
                                                }
                                            } else {
                                                $fb_cover_photo_result = json_decode($this->file_get_contents_curl($fb_cover_photo_url));
                                            }
                                            // This is necessary because sometimes the FB result has a data object, sometimes doesn't...
                                            if (!empty($fb_cover_photo_result->data)) {
                                                $album->photos->data[0] = $fb_cover_photo_result->data[0];
                                            } else {
                                                $album->photos->data[0] = $fb_cover_photo_result;
                                            }
                                        }
                                        if (!empty($album->photos)) {
                                            $subalbum = new stdClass();
                                            $subalbum->data = $album->photos->data;
                                            $data = array();
                                            // Create a new array for this image
                                            if (isset($album->name)) {
                                                $data['title'] = esc_attr(stripslashes($album->name));
                                            }
                                            if ($facebook_count == 'yes') {
                                                $description_fragments = array(min($album->count, $limit) . ' ' . _n('Photo', 'Photos', $album->count, 'jig_td'));
                                                if ($facebook_description == 'yes' || $facebook_description == 'thumbnails') {
                                                    if (!empty($album->description)) {
                                                        if (strpos($album->description, '@') === false) {
                                                            $description_fragments[] = esc_attr(stripslashes($album->description));
                                                        } else {
                                                            $description_fragments[] = esc_attr(stripslashes(preg_replace('/@\\[[:\\d]+:(.+?)\\]/im', '$1', $album->description)));
                                                        }
                                                    }
                                                }
                                                $data['description'] = esc_attr(stripslashes(implode('<br />', $description_fragments)));
                                            } else {
                                                if (($facebook_description == 'yes' || $facebook_description == 'thumbnails') && !empty($album->description)) {
                                                    if (strpos($album->description, '@') === false) {
                                                        $data['description'] = esc_attr(stripslashes($album->description));
                                                    } else {
                                                        $data['description'] = esc_attr(stripslashes(preg_replace('/@\\[[:\\d]+:(.+?)\\]/im', '$1', $album->description)));
                                                    }
                                                }
                                            }
                                            $show_on_front = get_option('show_on_front');
                                            $page_on_front = get_option('page_on_front');
                                            $args[$this->settings['fb_overview_slug']] = $album->id;
                                            if ($wp_rewrite->using_permalinks()) {
                                                if (is_singular()) {
                                                    $post =& get_post(get_the_ID());
                                                    $url = trailingslashit(get_permalink($post->ID));
                                                    if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                                        $url = trailingslashit(home_url($post->page_name ? $post->page_name : $post->post_name));
                                                    }
                                                } else {
                                                    $url = 'http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                                                }
                                                $url .= $this->settings['fb_overview_slug'] . '/' . $args[$this->settings['fb_overview_slug']];
                                                $data['link'] = $url;
                                            } else {
                                                if (is_home()) {
                                                    $args['pageid'] = get_the_ID();
                                                }
                                                if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                                    $args['page_id'] = get_the_ID();
                                                }
                                                if (is_singular()) {
                                                    $query = htmlspecialchars(add_query_arg($args, get_permalink(get_the_ID())));
                                                } else {
                                                    $query = htmlspecialchars(add_query_arg($args));
                                                }
                                                $data['link'] = esc_url($query);
                                            }
                                            if ($fb_lightbox_album == 'yes') {
                                                $data['url'] = $subalbum->data[0]->source;
                                                $data['width'] = $subalbum->data[0]->width;
                                                $data['height'] = $subalbum->data[0]->height;
                                            } elseif ($photon_activated || $aspect_ratio || $randomize_width > 0) {
                                                $data['url'] = $subalbum->data[0]->images[0]->source;
                                                $data['width'] = $subalbum->data[0]->images[0]->width;
                                                $data['height'] = $subalbum->data[0]->images[0]->height;
                                            } else {
                                                for ($i = count($subalbum->data[0]->images) - 1; $i >= 0; $i--) {
                                                    if ($subalbum->data[0]->images[$i]->height >= $calculated_max_height) {
                                                        $data['url'] = $subalbum->data[0]->images[$i]->source;
                                                        $data['width'] = $subalbum->data[0]->images[$i]->width;
                                                        $data['height'] = $subalbum->data[0]->images[$i]->height;
                                                        break;
                                                    }
                                                }
                                                if (empty($data['url'])) {
                                                    $data['url'] = $subalbum->data[0]->images[0]->source;
                                                    $data['width'] = $subalbum->data[0]->images[0]->width;
                                                    $data['height'] = $subalbum->data[0]->images[0]->height;
                                                }
                                            }
                                            if ($this->settings['image_custom_classes'] !== 'nothing') {
                                                $data['extra_class'] = 'jig-contentID-FB-' . $subalbum->data[0]->id;
                                            }
                                            if ($fb_lightbox_album == 'yes') {
                                                // If gallery should be displayed as a lightbox
                                                $shadow_galleries[] = $shadow_group_id = "jig{$jig_id}-hiddenGalleryGroup-" . $album->id;
                                                $shadow_gallery = '<div class="jig-hiddenGallery">';
                                                if (stripos($link_rel, '*instance*') !== false) {
                                                    $shadow_rel = str_replace('*instance*', 'FB-' . $album->id, $link_rel);
                                                } else {
                                                    switch ($lightbox) {
                                                        case 'prettyphoto':
                                                            $shadow_rel = 'prettyPhoto[fb-' . $album->id . ']';
                                                            break;
                                                        case 'colorbox':
                                                            $shadow_rel = 'colorBox[fb-' . $album->id . ']';
                                                            break;
                                                        case 'foobox':
                                                            $shadow_rel = 'foobox[fb-' . $album->id . ']';
                                                            break;
                                                        default:
                                                            $shadow_rel = 'jig[fb-' . $album->id . ']';
                                                            break;
                                                    }
                                                }
                                                if (isset($data['title'])) {
                                                    $data['gallery']['title'] = $data['title'];
                                                }
                                                if (isset($data['description'])) {
                                                    $data['gallery']['description'] = $data['description'];
                                                }
                                                if ($album->count !== count($subalbum->data) && count($subalbum->data) < $limit) {
                                                    // Facebook returned less images than desired. The reason is their paging limits or in case of JIG lightbox albums, the album contents are initialized by a tiny amount images first to not exhaust Facebook. Thus the internal limit is increased.
                                                    $auto_limit = empty($auto_limit) ? 0 : $auto_limit;
                                                    $additional_photos = $this->facebook_api_call(str_replace('limit=1&', 'limit=' . ($limit < 500 ? max(array($auto_limit - 1, 1)) : 500 - $auto_limit) . '&', $album->photos->paging->next), $facebook_caching, $limit, count($subalbum->data));
                                                    if (!empty($additional_photos) && is_array($additional_photos)) {
                                                        $subalbum->data = array_merge($subalbum->data, $additional_photos);
                                                        // This corrects the amount of photos in the lightbox gallery because FB sometimes says there are more photos than the amount available
                                                        if ($facebook_count == 'yes' && $album->count !== count($subalbum->data)) {
                                                            $data['description'] = str_replace($album->count, count($subalbum->data), $data['description']);
                                                        }
                                                    }
                                                }
                                                foreach ($subalbum->data as $subalbum_image) {
                                                    $shadow_data = $sd = array();
                                                    // Create 2 arrays for this image one temporary and one that gets pushed
                                                    $shadow_size = '';
                                                    if ($facebook_image_size == 'larger') {
                                                        if ($subalbum_image->images[0]->height < 2048 && $subalbum_image->images[0]->width < 2048) {
                                                            $shadow_data['url'] = $subalbum_image->images[0]->source;
                                                            if ($lightbox == 'photoswipe') {
                                                                $shadow_size = ' data-wh="' . $subalbum_image->images[0]->width . 'x' . $subalbum_image->images[0]->height . '"';
                                                            }
                                                        } else {
                                                            $shadow_data['url'] = $subalbum_image->images[1]->source;
                                                            if ($lightbox == 'photoswipe') {
                                                                $shadow_size = ' data-wh="' . $subalbum_image->images[1]->width . 'x' . $subalbum_image->images[1]->height . '"';
                                                            }
                                                        }
                                                    } else {
                                                        if ($facebook_image_size == 'maximum') {
                                                            $shadow_data['url'] = $subalbum_image->images[0]->source;
                                                            if ($lightbox == 'photoswipe') {
                                                                $shadow_size = ' data-wh="' . $subalbum_image->images[0]->width . 'x' . $subalbum_image->images[0]->height . '"';
                                                            }
                                                        } else {
                                                            $shadow_data['url'] = $subalbum_image->source;
                                                            if ($lightbox == 'photoswipe') {
                                                                $shadow_size = ' data-wh="' . $subalbum_image->width . 'x' . $subalbum_image->height . '"';
                                                            }
                                                        }
                                                    }
                                                    // Skip image from the hidden gallery if it's the same as the opener image
                                                    if ($subalbum_image->id == $subalbum->data[0]->id) {
                                                        // These show up as captions on the thumbnail that launches the lightbox gallery
                                                        if (isset($data['description'])) {
                                                            $data['gallery']['description'] = $data['description'];
                                                        }
                                                        unset($data['description']);
                                                        // Have to set the image's own title and desc, once opened in the lightbox
                                                        if (isset($subalbum_image->name)) {
                                                            $data['description'] = esc_attr(stripslashes($subalbum_image->name));
                                                        }
                                                        if ($download_link != 'no') {
                                                            $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($shadow_data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                        }
                                                        // And don't create the opener picture again in the shadow gallery
                                                        continue;
                                                    }
                                                    $sd['title'] = esc_attr(stripslashes($album->name));
                                                    if (isset($subalbum_image->name)) {
                                                        $sd['description'] = esc_attr(stripslashes($subalbum_image->name));
                                                    }
                                                    $title_fragment = isset($sd[$link_title_field]) ? $sd[$link_title_field] : '';
                                                    $alt_fragment = isset($sd[$img_alt_field]) ? $sd[$img_alt_field] : '';
                                                    if ($download_link != 'no') {
                                                        $shadow_data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($shadow_data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                        if ($download_link == 'yes') {
                                                            if ($title_fragment !== '') {
                                                                $title_fragment .= $separator_character . $shadow_data['download'];
                                                            } else {
                                                                $title_fragment = $shadow_data['download'];
                                                            }
                                                        } else {
                                                            if ($alt_fragment !== '') {
                                                                $alt_fragment .= $separator_character . $shadow_data['download'];
                                                            } else {
                                                                $alt_fragment = $shadow_data['download'];
                                                            }
                                                        }
                                                    }
                                                    $shadow_class = 'class="jig-link jig-contentID-FB-' . $subalbum_image->id . (empty($link_class) ? '' : ' ' . $link_class) . '" ';
                                                    $shadow_gallery .= '<a href="' . $shadow_data['url'] . '" rel="' . $shadow_rel . '" ' . $shadow_class . $shadow_size . ' title="' . $title_fragment . '"><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="' . $alt_fragment . '" /></a>';
                                                }
                                                $shadow_gallery .= "</div>";
                                                $data['link'] = null;
                                                unset($data['link']);
                                                $data['thumbUrl'] = $data['url'];
                                                if ($facebook_image_size == 'larger') {
                                                    if ($subalbum->data[0]->images[0]->height < 2048 && $subalbum->data[0]->images[0]->width < 2048) {
                                                        $data['url'] = $subalbum->data[0]->images[0]->source;
                                                        $data['width'] = $subalbum->data[0]->images[0]->width;
                                                        $data['height'] = $subalbum->data[0]->images[0]->height;
                                                    } else {
                                                        $data['url'] = $subalbum->data[0]->images[1]->source;
                                                        $data['width'] = $subalbum->data[0]->images[1]->width;
                                                        $data['height'] = $subalbum->data[0]->images[1]->height;
                                                    }
                                                } else {
                                                    if ($facebook_image_size == 'maximum') {
                                                        $data['url'] = $subalbum->data[0]->images[0]->source;
                                                        $data['width'] = $subalbum->data[0]->images[0]->width;
                                                        $data['height'] = $subalbum->data[0]->images[0]->height;
                                                    } else {
                                                        $data['url'] = $data['thumbUrl'];
                                                        $data['thumbUrl'] = null;
                                                        unset($data['thumbUrl']);
                                                    }
                                                }
                                                $data['gallery']['html'] = $shadow_gallery;
                                                $data['gallery']['rel'] = $shadow_rel;
                                                $data['gallery']['id'] = $shadow_group_id;
                                                switch ($lightbox) {
                                                    case 'foobox':
                                                        $data['gallery']['lightbox_class'] = 'jigFooBoxConnect';
                                                        break;
                                                    case 'socialgallery':
                                                        $data['gallery']['lightbox_class'] = 'jigSgConnect';
                                                        break;
                                                    default:
                                                }
                                            }
                                            if (!empty($facebook_album_multi) && $facebook_album_multi[0] == 'latestone') {
                                                $facebook_album_multi[0] = '';
                                            }
                                            array_push($this->images, $data);
                                            // Add to the main images array
                                        }
                                    }
                                    $found++;
                                }
                                if ($found == 0 || empty($this->images)) {
                                    return $this->frontend_stop(__('There are no pictures in any of the albums.', 'jig_td'));
                                }
                            }
                        } else {
                            if (!empty($albums['message'])) {
                                return $this->frontend_stop(__('Justified Image Grid: The Facebook content cannot be displayed, the error from Facebook:', 'jig_td') . ' ' . $albums['message']);
                            } else {
                                return $this->frontend_stop(__('There are no albums.', 'jig_td'));
                            }
                        }
                    }
                    // For displaying the feed
                    if ($facebook_album == 'feed') {
                        if ($limit > 250) {
                            $limit = 250;
                            $limit_parameter = "&limit=250";
                        }
                        $feed_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '/feed?fields=picture,caption,description,message,object_id' . $limit_parameter . '&access_token=' . $token;
                        $photos = $this->facebook_api_call($feed_url, $facebook_caching, $limit);
                        if (!empty($photos)) {
                            $this->images = array();
                            // Create a new array for the images
                            if ($orderby == 'rand') {
                                $photos = (array) $photos;
                                shuffle($photos);
                            }
                            // Since this is just a request for the image sizes, it could be cached for a very very long time (as album covers)
                            $facebook_overview_caching = $this->settings['facebook_overview_caching'];
                            foreach ($photos as &$feed_post) {
                                if (!(isset($feed_post->picture) && isset($feed_post->object_id))) {
                                    continue;
                                    // It is not a photo object
                                } else {
                                    $photo_object_url = 'https://graph.facebook.com/v2.4/' . $feed_post->object_id . '?fields=images,source,height,width&access_token=' . $token;
                                    $photo_object = $this->facebook_api_call($photo_object_url, $facebook_overview_caching, -1);
                                    if (isset($photo_object->images)) {
                                        $data = $d = array();
                                        // Create a new array for this image
                                        $data['thumbUrl'] = $photo_object->source;
                                        // Store the full URL value
                                        $data['width'] = $photo_object->width;
                                        $data['height'] = $photo_object->height;
                                        if ($facebook_image_size == 'larger') {
                                            if ($photo_object->images[0]->height < 2048 && $photo_object->images[0]->width < 2048) {
                                                $data['url'] = $photo_object->images[0]->source;
                                                $data['width'] = $photo_object->images[0]->width;
                                                $data['height'] = $photo_object->images[0]->height;
                                            } else {
                                                $data['url'] = $photo_object->images[1]->source;
                                                $data['width'] = $photo_object->images[1]->width;
                                                $data['height'] = $photo_object->images[1]->height;
                                            }
                                        } else {
                                            if ($facebook_image_size == 'maximum') {
                                                $data['url'] = $photo_object->images[0]->source;
                                                $data['width'] = $photo_object->images[0]->width;
                                                $data['height'] = $photo_object->images[0]->height;
                                            } else {
                                                $data['url'] = $data['thumbUrl'];
                                                $data['thumbUrl'] = null;
                                                unset($data['thumbUrl']);
                                            }
                                        }
                                        if (!empty($feed_post->message)) {
                                            $d['text'][] = $feed_post->message;
                                        }
                                        if (!empty($feed_post->caption)) {
                                            $d['text'][] = $feed_post->caption;
                                        }
                                        if (!empty($feed_post->description)) {
                                            $d['text'][] = $feed_post->description;
                                        }
                                        if (!empty($d['text'])) {
                                            $d['text'] = array_values(array_unique($d['text']));
                                            $d['textCount'] = count($d['text']);
                                            for ($i = 0; $i < $d['textCount']; $i++) {
                                                if ($i == 0) {
                                                    $data['title'] = esc_attr(stripslashes($d['text'][$i]));
                                                } else {
                                                    if (empty($data['description'])) {
                                                        $data['description'] = esc_attr(stripslashes($d['text'][$i]));
                                                    } else {
                                                        $data['description'] .= '<br />' . esc_attr(stripslashes($d['text'][$i]));
                                                    }
                                                }
                                            }
                                        }
                                        if ($download_link != 'no') {
                                            $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode(!empty($photo_object->images[0]->source) ? $photo_object->images[0]->source : $data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                        }
                                        if ($this->settings['image_custom_classes'] !== 'nothing') {
                                            $data['extra_class'] = 'jig-contentID-FB-' . $photo_object->id;
                                        }
                                        if (!in_array($data, $this->images)) {
                                            $found = false;
                                            foreach ($this->images as $existing_feed_item) {
                                                if ($existing_feed_item['thumbUrl'] == $data['thumbUrl']) {
                                                    $found = true;
                                                    break;
                                                }
                                            }
                                            if ($found === false) {
                                                array_push($this->images, $data);
                                                // Add to the main images array
                                            }
                                            unset($existing_feed_item, $found);
                                        }
                                    }
                                }
                            }
                            unset($feed_post, $photo_object);
                        }
                    }
                    // For displaying single albums
                    if ($facebook_album !== 'overview' && $facebook_album !== 'overview_only_albums' && $facebook_album !== 'feed') {
                        if ($facebook_album == 'latest') {
                            $albums_url = 'https://graph.facebook.com/v2.4/' . $facebook_id . '?fields=albums.limit(5).fields(id,cover_photo,link,count,name,description,type,photos.limit(' . $limit . ').fields(images,source,height,width,name))&access_token=' . $token;
                            $albums = $this->facebook_api_call($albums_url, $facebook_caching, 5);
                            if (!empty($albums) && empty($albums['message'])) {
                                foreach ($albums as $key => $album) {
                                    if ($album->type == 'normal' && !empty($album->count)) {
                                        $facebook_album = $album->id;
                                        if (($facebook_description == 'yes' || $facebook_description == 'above') && !empty($album->name)) {
                                            $facebook_description_displayed_already = true;
                                            $notice_before .= '<p class="jig-fbDescription"><strong>' . $album->name . '</strong>' . (!empty($album->description) ? '<br/>' . $album->description : '') . '</p>';
                                        }
                                        break;
                                    }
                                }
                                if ($facebook_album == 'latest') {
                                    return $this->frontend_stop(__('There are no pictures in any of the normal albums.', 'jig_td'));
                                }
                            } else {
                                if (!empty($albums['message'])) {
                                    return $this->frontend_stop(__('Justified Image Grid: The Facebook content cannot be displayed, the error from Facebook:', 'jig_td') . ' ' . $albums['message']);
                                } else {
                                    return $this->frontend_stop(__('There are no albums.', 'jig_td'));
                                }
                            }
                        }
                        $photos_url = "https://graph.facebook.com/v2.4/" . $facebook_album . "/photos?fields=source,height,width,name" . ($facebook_image_size == 'normal' ? '' : ',images') . $limit_parameter . '&access_token=' . $token;
                        $photos = $this->facebook_api_call($photos_url, $facebook_caching, $limit);
                        if (!empty($photos) && empty($photos['message'])) {
                            if ($limit !== '' && count($photos) > $limit) {
                                $photos = array_slice($photos, 0, $limit);
                            }
                            $this->images = array();
                            // Create a new array for the images
                            if ($orderby == 'rand') {
                                $photos = (array) $photos;
                                shuffle($photos);
                            }
                            foreach ($photos as $image) {
                                $data = array();
                                // Create a new array for this image
                                if (isset($image->name)) {
                                    $data['title'] = esc_attr(stripslashes($image->name));
                                }
                                $data['thumbUrl'] = $image->source;
                                // Store the full URL value
                                $data['width'] = $image->width;
                                $data['height'] = $image->height;
                                if ($facebook_image_size == 'larger') {
                                    if ($image->images[0]->height < 2048 && $image->images[0]->width < 2048) {
                                        $data['url'] = $image->images[0]->source;
                                        $data['width'] = $image->images[0]->width;
                                        $data['height'] = $image->images[0]->height;
                                    } else {
                                        $data['url'] = $image->images[1]->source;
                                        $data['width'] = $image->images[1]->width;
                                        $data['height'] = $image->images[1]->height;
                                    }
                                } else {
                                    if ($facebook_image_size == 'maximum') {
                                        $data['url'] = $image->images[0]->source;
                                        $data['width'] = $image->images[0]->width;
                                        $data['height'] = $image->images[0]->height;
                                    } else {
                                        $data['url'] = $data['thumbUrl'];
                                        $data['thumbUrl'] = null;
                                        unset($data['thumbUrl']);
                                    }
                                }
                                if ($download_link != 'no') {
                                    $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode(!empty($image->images[0]->source) ? $image->images[0]->source : $data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                }
                                if ($this->settings['image_custom_classes'] !== 'nothing') {
                                    $data['extra_class'] = 'jig-contentID-FB-' . $image->id;
                                }
                                array_push($this->images, $data);
                                // Add to the main images array
                            }
                            // If you want to show the facebook album description then the album needs to be retrieved from FB
                            if (($facebook_description == 'yes' || $facebook_description == 'above') && empty($facebook_description_displayed_already)) {
                                $facebook_album_url = "https://graph.facebook.com/v2.4/" . $facebook_album . "?fields=description" . '&access_token=' . $token;
                                if ($facebook_caching > 0) {
                                    if (get_transient('jigfb_' . md5($facebook_album_url . $facebook_caching)) == true) {
                                        $facebook_album_rsp = get_transient('jigfb_' . md5($facebook_album_url . $facebook_caching));
                                    } else {
                                        $facebook_album_rsp = json_decode($this->file_get_contents_curl($facebook_album_url));
                                        set_transient('jigfb_' . md5($facebook_album_url . $facebook_caching), $facebook_album_rsp, 60 * $facebook_caching);
                                    }
                                } else {
                                    $facebook_album_rsp = json_decode($this->file_get_contents_curl($facebook_album_url));
                                }
                                if (!empty($facebook_album_rsp->description)) {
                                    if (strpos($facebook_album_rsp->description, '@') === false) {
                                        $notice_before .= '<p class="jig-fbDescription">' . $facebook_album_rsp->description . '</p>';
                                    } else {
                                        $notice_before .= '<p class="jig-fbDescription">' . preg_replace('/@\\[[:\\d]+:(.+?)\\]/im', '$1', $facebook_album_rsp->description) . '</p>';
                                    }
                                }
                            }
                        } else {
                            return $this->frontend_stop(__('The requested album cannot be loaded at this time.', 'jig_td') . ($photos['message'] ? ' ' . $photos['message'] : ''));
                        }
                    }
                    break;
                case 'flickr':
                    if ($limit === '0') {
                        $limit_parameter = "&per_page=500";
                    } else {
                        if ($limit !== '') {
                            $limit_parameter = "&per_page=" . $limit;
                        } else {
                            $limit_parameter = "&per_page=25";
                        }
                    }
                    if ($flickr_collection !== '') {
                        global $wp, $query_string, $wp_rewrite, $wp_query;
                        // Everything related to the collection mode
                        $collection_var = get_query_var($this->settings['flickr_collections_slug']);
                        if (!empty($collection_var)) {
                            $collection_vars = explode('/', $collection_var);
                            foreach ($collection_vars as $collection_path_element_index => $collection_path_element) {
                                if (strlen($collection_path_element) > 21) {
                                    // If it's a collection ID
                                    $flickr_collection_ids[] = $collection_path_element;
                                } else {
                                    $flickr_photoset = $collection_path_element;
                                }
                            }
                        }
                        if ($flickr_collection !== 'complete-overview') {
                            $collections_url = 'https://api.flickr.com/services/rest?api_key=' . trim($this->settings['fli_api_key']) . '&format=php_serial&method=flickr.collections.getTree&collection_id=' . $flickr_collection . '&user_id=' . $flickr_user;
                        } else {
                            $collections_url = 'https://api.flickr.com/services/rest?api_key=' . trim($this->settings['fli_api_key']) . '&format=php_serial&method=flickr.collections.getTree&user_id=' . $flickr_user;
                        }
                        if ($flickr_caching > 0) {
                            if (get_transient('jigfli_' . md5($collections_url . $flickr_caching)) == true) {
                                $collections_raw = get_transient('jigfli_' . md5($collections_url . $flickr_caching));
                            } else {
                                $collections_raw = maybe_unserialize($this->file_get_contents_curl($collections_url));
                                set_transient('jigfli_' . md5($collections_url . $flickr_caching), $collections_raw, 60 * $flickr_caching);
                            }
                        } else {
                            $collections_raw = maybe_unserialize($this->file_get_contents_curl($collections_url));
                        }
                        if (!empty($collections_raw) && $collections_raw['stat'] == 'ok') {
                            $collections = $this->flickr_parse_collection($collections_raw['collections']);
                            if ($flickr_collection == 'complete-overview') {
                                $collections['complete-overview'] = $collections_raw['collections'];
                                $collections['complete-overview']['title'] = 'Overview';
                                if (!empty($this->settings['fli_added'])) {
                                    foreach ($this->settings['fli_added'] as $single_flickr_user) {
                                        if ($single_flickr_user['user_id'] == $flickr_user) {
                                            $collections['complete-overview']['title'] = $single_flickr_user['user_name'];
                                            break;
                                        }
                                    }
                                }
                            }
                            // Disallow showing a set if the shortcode flickr user ID does not have it, and fall back to what the shortcode would show by default - this allows multiple JIG instsances with Flickr collections AND does some security by disallowing foreign set IDs
                            if (!empty($flickr_photoset) && empty($collections[$flickr_photoset])) {
                                $flickr_photoset = '';
                                $collection_var = false;
                            }
                            if (!empty($flickr_collection_ids)) {
                                $found_flickr_collection_id = false;
                                foreach ($flickr_collection_ids as $flickr_collection_id) {
                                    if (!empty($collections[$flickr_collection_id])) {
                                        $found_flickr_collection_id = true;
                                    }
                                }
                                if ($found_flickr_collection_id == false) {
                                    $flickr_collection_ids = false;
                                    $collection_var = false;
                                }
                            }
                            $flickr_set_list_needed = false;
                            foreach ($collections as $collection_id => $collection_value) {
                                if (strlen($collection_id) < 21) {
                                    $flickr_set_list_needed = true;
                                    break;
                                }
                            }
                            if ($flickr_set_list_needed === true) {
                                $flickr_set_list_url = 'https://api.flickr.com/services/rest?api_key=' . trim($this->settings['fli_api_key']) . '&format=php_serial&method=flickr.photosets.getList&user_id=' . $flickr_user . '&per_page=500&primary_photo_extras=description,url_o,url_k,url_h,url_l,url_c,url_z,url_m,url_n,url_s,url_t';
                                if ($flickr_caching > 0) {
                                    if (get_transient('jigfli_' . md5($flickr_set_list_url . $flickr_caching)) == true) {
                                        $flickr_set_list = get_transient('jigfli_' . md5($flickr_set_list_url . $flickr_caching));
                                    } else {
                                        $flickr_set_list = maybe_unserialize($this->file_get_contents_curl($flickr_set_list_url));
                                        set_transient('jigfli_' . md5($flickr_set_list_url . $flickr_caching), $flickr_set_list, 60 * $flickr_caching);
                                    }
                                } else {
                                    $flickr_set_list = maybe_unserialize($this->file_get_contents_curl($flickr_set_list_url));
                                }
                                if (!empty($flickr_set_list) && $flickr_set_list['stat'] == 'ok') {
                                    $flickr_set_list = $flickr_set_list['photosets']['photoset'];
                                    foreach ($flickr_set_list as $key => $value) {
                                        $flickr_set_list_mod[$value['id']] = $value;
                                    }
                                    $flickr_set_list = $flickr_set_list_mod;
                                    unset($flickr_set_list_mod);
                                }
                            }
                            if ($flickr_breadcrumb == 'yes' && !empty($collection_var)) {
                                $flickr_home_permalink = home_url(add_query_arg(array(), $wp->request));
                                $slug_position = strripos($flickr_home_permalink, $this->settings['flickr_collections_slug']);
                                if ($slug_position !== false) {
                                    $flickr_home_permalink = substr($flickr_home_permalink, 0, $slug_position);
                                }
                                if (substr($flickr_home_permalink, -1) != '/') {
                                    $flickr_home_permalink .= '/';
                                }
                                if ($flickr_home_permalink == home_url('/') && strlen($query_string) > 0 && strpos($query_string, $this->settings['flickr_collections_slug']) !== false) {
                                    $flickr_home_permalink .= '?' . remove_query_arg($this->settings['flickr_collections_slug'], $query_string);
                                }
                                switch ($flickr_bc_separator) {
                                    case 'default':
                                        $flickr_bc_separator = ' &raquo;';
                                        break;
                                    case 'greater':
                                        $flickr_bc_separator = ' &gt;';
                                        break;
                                    case 'comma':
                                        $flickr_bc_separator = ',';
                                        break;
                                    case 'slash':
                                        $flickr_bc_separator = ' /';
                                        break;
                                    case 'doubleslash':
                                        $flickr_bc_separator = ' //';
                                        break;
                                    case 'minus':
                                        $flickr_bc_separator = ' -';
                                        break;
                                    case 'plus':
                                        $flickr_bc_separator = ' +';
                                        break;
                                    case 'arrow':
                                        $flickr_bc_separator = ' &rarr;';
                                        break;
                                    case 'bslash':
                                        $flickr_bc_separator = ' \\';
                                        break;
                                    case 'doublebslash':
                                        $flickr_bc_separator = ' \\\\';
                                        break;
                                    case 'middledot':
                                        $flickr_bc_separator = ' ·';
                                        break;
                                    case 'dobulecolon':
                                        $flickr_bc_separator = ' ::';
                                        break;
                                    case 'numbersign':
                                        $flickr_bc_separator = ' #';
                                        break;
                                }
                                $flickr_breadcrumb_inner = '';
                                if (!empty($flickr_collection_ids)) {
                                    foreach ($flickr_collection_ids as $flickr_collection_id_index => $flickr_collection_id) {
                                        if ($flickr_collection_id !== end($flickr_collection_ids) || !empty($flickr_photoset)) {
                                            $show_on_front = get_option('show_on_front');
                                            $page_on_front = get_option('page_on_front');
                                            $args[$this->settings['flickr_collections_slug']] = implode('/', array_slice($flickr_collection_ids, 0, $flickr_collection_id_index + 1));
                                            if ($wp_rewrite->using_permalinks()) {
                                                if (is_singular()) {
                                                    $post =& get_post(get_the_ID());
                                                    $url = trailingslashit(get_permalink($post->ID));
                                                    if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                                        $url = trailingslashit(home_url($post->page_name ? $post->page_name : $post->post_name));
                                                    }
                                                } else {
                                                    $url = 'http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                                                }
                                                $url .= $this->settings['flickr_collections_slug'] . '/' . $args[$this->settings['flickr_collections_slug']];
                                            } else {
                                                if (is_home()) {
                                                    $args['pageid'] = get_the_ID();
                                                }
                                                if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                                    $args['page_id'] = get_the_ID();
                                                }
                                                if (is_singular()) {
                                                    $url = htmlspecialchars(add_query_arg($args, get_permalink(get_the_ID())));
                                                } else {
                                                    $url = htmlspecialchars(add_query_arg($args));
                                                }
                                            }
                                            $flickr_breadcrumb_inner .= $flickr_bc_separator . ' <a href="' . esc_url($url) . '">';
                                            $flickr_breadcrumb_inner .= $collections[$flickr_collection_id]['title'] . '</a>';
                                        } else {
                                            $flickr_breadcrumb_inner .= $flickr_bc_separator . ' ' . $collections[$flickr_collection_id]['title'];
                                        }
                                    }
                                }
                                if (!empty($flickr_photoset)) {
                                    $flickr_breadcrumb_inner .= $flickr_bc_separator . ' ' . esc_attr(stripslashes($flickr_set_list[$flickr_photoset]['title']['_content']));
                                }
                                $notice_before .= '<div class="jig-flickrBreadcrumb"><a href="' . esc_url($flickr_home_permalink) . '">' . ($flickr_bc_home_text === '' ? $collections[$flickr_collection]['title'] : $flickr_bc_home_text) . '</a> ' . $flickr_breadcrumb_inner . '</div>';
                                $flickr_bc_CSS_needed = true;
                            }
                        }
                        if (empty($flickr_photoset)) {
                            // display a collection
                            $flickr_collection = !empty($flickr_collection_ids) ? end($flickr_collection_ids) : $flickr_collection;
                            if (($flickr_description == 'yes' || $flickr_description == 'above') && !empty($collections[$flickr_collection]['description'])) {
                                $notice_before .= '<p class="jig-fliDescription">' . $collections[$flickr_collection]['description'] . '</p>';
                            }
                        }
                        // otherwise display a photoset
                        if ($flickr_photoset === '' && (!empty($collections[$flickr_collection]['set']) && count($collections[$flickr_collection]['set']) > 0 || !empty($collections[$flickr_collection]['collection']) && count($collections[$flickr_collection]['collection']) > 0)) {
                            $this->images = array();
                            // Create a new array for the images
                            if (!empty($collections[$flickr_collection]['set']) && count($collections[$flickr_collection]['set']) > 0) {
                                // If the collection only includes sets
                                if ($retina_ready == 'yes') {
                                    $calculated_max_height = $max_height * 3;
                                } else {
                                    $calculated_max_height = $max_height;
                                }
                                foreach ($collections[$flickr_collection]['set'] as $single_set) {
                                    $single_set = $flickr_set_list[$single_set['id']];
                                    $photo = $single_set['primary_photo_extras'];
                                    $data = array();
                                    // Create a new array for this image
                                    if (isset($photo['height_t']) && $photo['height_t'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_t'];
                                    } elseif (isset($photo['height_s']) && $photo['height_s'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_s'];
                                    } elseif (isset($photo['height_n']) && $photo['height_n'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_n'];
                                    } elseif (isset($photo['height_m']) && $photo['height_m'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_m'];
                                    } elseif (isset($photo['height_z']) && $photo['height_z'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_z'];
                                    } elseif (isset($photo['height_c']) && $photo['height_c'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_c'];
                                    } elseif (isset($photo['height_l']) && $photo['height_l'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_l'];
                                    } elseif (isset($photo['height_h']) && $photo['height_h'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_h'];
                                    } elseif (isset($photo['height_k']) && $photo['height_k'] >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo['url_k'];
                                    } else {
                                        if ($this->settings['flickr_too_small_images'] !== 'upscale') {
                                            continue;
                                        } else {
                                            $flickr_upscale_this = true;
                                        }
                                    }
                                    if ($this->settings['flickr_allow_big_images'] === 'original' && isset($photo['url_o'])) {
                                        $data['url'] = $photo['url_o'];
                                        $data['width'] = $photo['width_o'];
                                        $data['height'] = $photo['height_o'];
                                    } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($photo['url_k'])) {
                                        $data['url'] = $photo['url_k'];
                                        $data['width'] = $photo['width_k'];
                                        $data['height'] = $photo['height_k'];
                                    } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($photo['url_h'])) {
                                        $data['url'] = $photo['url_h'];
                                        $data['width'] = $photo['width_h'];
                                        $data['height'] = $photo['height_h'];
                                    } elseif (isset($photo['url_l'])) {
                                        $data['url'] = $photo['url_l'];
                                        $data['width'] = $photo['width_l'];
                                        $data['height'] = $photo['height_l'];
                                    } elseif (isset($photo['url_c'])) {
                                        $data['url'] = $photo['url_c'];
                                        $data['width'] = $photo['width_c'];
                                        $data['height'] = $photo['height_c'];
                                    } elseif (isset($photo['url_z'])) {
                                        $data['url'] = $photo['url_z'];
                                        $data['width'] = $photo['width_z'];
                                        $data['height'] = $photo['height_z'];
                                    } elseif (isset($photo['url_m'])) {
                                        $data['url'] = $photo['url_m'];
                                        $data['width'] = $photo['width_m'];
                                        $data['height'] = $photo['height_m'];
                                    } elseif (isset($photo['url_n'])) {
                                        $data['url'] = $photo['url_n'];
                                        $data['width'] = $photo['width_n'];
                                        $data['height'] = $photo['height_n'];
                                    } elseif (isset($photo['url_s'])) {
                                        $data['url'] = $photo['url_s'];
                                        $data['width'] = $photo['width_s'];
                                        $data['height'] = $photo['height_s'];
                                    } elseif (isset($photo['url_t'])) {
                                        $data['url'] = $photo['url_t'];
                                        $data['width'] = $photo['width_t'];
                                        $data['height'] = $photo['height_t'];
                                    } else {
                                        unset($flickr_upscale_this);
                                        continue;
                                    }
                                    if (isset($flickr_upscale_this)) {
                                        unset($flickr_upscale_this);
                                        $flickr_upscale_key = array_search($data['url'], $photo, true);
                                        if ($flickr_upscale_key !== false) {
                                            $flickr_upscale_key = substr($flickr_upscale_key, -1);
                                            $data['width'] = $photo['width_' . $flickr_upscale_key];
                                            $data['height'] = $photo['height_' . $flickr_upscale_key];
                                        } else {
                                            continue;
                                        }
                                    }
                                    if (!empty($single_set['title']['_content'])) {
                                        $data['title'] = esc_attr(stripslashes($single_set['title']['_content']));
                                    }
                                    if ($flickr_count == 'yes') {
                                        $description_fragments = array($single_set['photos'] . ' ' . _n('Photo', 'Photos', $single_set['photos'], 'jig_td'));
                                        if (($flickr_description == 'yes' || $flickr_description == 'thumbnails') && !empty($single_set['description']['_content'])) {
                                            $description_fragments[] = esc_attr(stripslashes($single_set['description']['_content']));
                                        }
                                        $d['description'] = esc_attr(stripslashes(implode('<br />', $description_fragments)));
                                    } else {
                                        if (($flickr_description == 'yes' || $flickr_description == 'thumbnails') && !empty($single_set['description']['_content'])) {
                                            $d['description'] = esc_attr(stripslashes($single_set['description']['_content']));
                                        }
                                    }
                                    if ($d['description'] != '') {
                                        $data['description'] = $d['description'];
                                    }
                                    $data['link'] = $single_set['id'];
                                    if ($this->settings['image_custom_classes'] !== 'nothing') {
                                        $data['extra_class'] = 'jig-contentID-FL-' . $single_set['primary'];
                                    }
                                    if ($flickr_lightbox_set == 'yes') {
                                        // If gallery should be displayed as a lightbox
                                        $shadow_galleries[] = $shadow_group_id = "jig{$jig_id}-hiddenGalleryGroup-" . $single_set['id'];
                                        $shadow_gallery = '<div class="jig-hiddenGallery">';
                                        if (stripos($link_rel, '*instance*') !== false) {
                                            $shadow_rel = str_replace('*instance*', 'FL-' . $single_set['id'], $link_rel);
                                        } else {
                                            switch ($lightbox) {
                                                case 'prettyphoto':
                                                    $shadow_rel = 'prettyPhoto[fli-' . $single_set['id'] . ']';
                                                    break;
                                                case 'colorbox':
                                                    $shadow_rel = 'colorBox[fli-' . $single_set['id'] . ']';
                                                    break;
                                                case 'foobox':
                                                    $shadow_rel = 'foobox[fli-' . $single_set['id'] . ']';
                                                    break;
                                                default:
                                                    $shadow_rel = 'jig[fli-' . $single_set['id'] . ']';
                                                    break;
                                            }
                                        }
                                        $photoset_url = 'https://api.flickr.com/services/rest?api_key=' . trim($this->settings['fli_api_key']) . '&format=php_serial&method=flickr.photosets.getPhotos&photoset_id=' . $single_set['id'] . $limit_parameter . '&extras=description,tags,geo,url_o,url_k,url_h,url_l,url_c,url_z,url_m,url_n,url_s,url_t';
                                        if ($flickr_caching > 0) {
                                            if (get_transient('jigfli_' . md5($photoset_url . $flickr_caching)) == true) {
                                                $single_photoset = get_transient('jigfli_' . md5($photoset_url . $flickr_caching));
                                            } else {
                                                $single_photoset = maybe_unserialize($this->file_get_contents_curl($photoset_url));
                                                set_transient('jigfli_' . md5($photoset_url . $flickr_caching), $single_photoset, 60 * $flickr_caching);
                                            }
                                        } else {
                                            $single_photoset = maybe_unserialize($this->file_get_contents_curl($photoset_url));
                                        }
                                        if (!empty($single_photoset) && $single_photoset['stat'] == "ok") {
                                            foreach ($single_photoset['photoset']['photo'] as $shadow_photo) {
                                                // Skip image from the hidden gallery if it's the same as the opener image
                                                if ($shadow_photo['id'] == $single_set['primary']) {
                                                    // These show up as captions on the thumbnail that launches the lightbox gallery
                                                    if (isset($data['title'])) {
                                                        $data['gallery']['title'] = $data['title'];
                                                    }
                                                    if (isset($data['description'])) {
                                                        $data['gallery']['description'] = $data['description'];
                                                    }
                                                    unset($data['title'], $data['description']);
                                                    // Have to set the image's own title and desc, once opened in the lightbox
                                                    if (isset($shadow_photo['title'])) {
                                                        $data['title'] = esc_attr(stripslashes($shadow_photo['title']));
                                                    }
                                                    if (isset($shadow_photo['description']['_content'])) {
                                                        $data['description'] = esc_attr(stripslashes($shadow_photo['description']['_content']));
                                                    }
                                                    if ($download_link != 'no') {
                                                        $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                    }
                                                    if ($flickr_link != 'no') {
                                                        $data['lightbox_link'] = esc_attr(stripslashes('<a href="http://www.flickr.com/photos/' . $flickr_user . '/' . $shadow_photo['id'] . '" target="' . $this->settings['flickr_link_target'] . '">' . __($flickr_link_text, 'jig_td') . '</a>'));
                                                    }
                                                    // And don't create the opener picture again in the shadow gallery
                                                    continue;
                                                }
                                                $shadow_data = $sd = array();
                                                // Create 2 arrays for this image one temporary and one that gets pushed
                                                $shadow_size = '';
                                                if ($this->settings['flickr_allow_big_images'] === 'original' && isset($shadow_photo['url_o'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_o'];
                                                    $shadow_data['width'] = $shadow_photo['width_o'];
                                                    $shadow_data['height'] = $shadow_photo['height_o'];
                                                } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($shadow_photo['url_k'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_k'];
                                                    $shadow_data['width'] = $shadow_photo['width_k'];
                                                    $shadow_data['height'] = $shadow_photo['height_k'];
                                                } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($shadow_photo['url_h'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_h'];
                                                    $shadow_data['width'] = $shadow_photo['width_h'];
                                                    $shadow_data['height'] = $shadow_photo['height_h'];
                                                } elseif (isset($shadow_photo['url_l'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_l'];
                                                    $shadow_data['width'] = $shadow_photo['width_l'];
                                                    $shadow_data['height'] = $shadow_photo['height_l'];
                                                } elseif (isset($shadow_photo['url_c'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_c'];
                                                    $shadow_data['width'] = $shadow_photo['width_c'];
                                                    $shadow_data['height'] = $shadow_photo['height_c'];
                                                } elseif (isset($shadow_photo['url_z'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_z'];
                                                    $shadow_data['width'] = $shadow_photo['width_z'];
                                                    $shadow_data['height'] = $shadow_photo['height_z'];
                                                } elseif (isset($shadow_photo['url_m'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_m'];
                                                    $shadow_data['width'] = $shadow_photo['width_m'];
                                                    $shadow_data['height'] = $shadow_photo['height_m'];
                                                } elseif (isset($shadow_photo['url_n'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_n'];
                                                    $shadow_data['width'] = $shadow_photo['width_n'];
                                                    $shadow_data['height'] = $shadow_photo['height_n'];
                                                } elseif (isset($shadow_photo['url_s'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_s'];
                                                    $shadow_data['width'] = $shadow_photo['width_s'];
                                                    $shadow_data['height'] = $shadow_photo['height_s'];
                                                } elseif (isset($shadow_photo['url_t'])) {
                                                    $shadow_data['url'] = $shadow_photo['url_t'];
                                                    $shadow_data['width'] = $shadow_photo['width_t'];
                                                    $shadow_data['height'] = $shadow_photo['height_t'];
                                                } else {
                                                    continue;
                                                }
                                                if ($lightbox == 'photoswipe') {
                                                    $shadow_size = ' data-wh="' . $shadow_data['width'] . 'x' . $shadow_data['height'] . '"';
                                                }
                                                if (isset($shadow_photo['title'])) {
                                                    $sd['title'] = esc_attr(stripslashes($shadow_photo['title']));
                                                }
                                                if (isset($shadow_photo['description']['_content'])) {
                                                    $sd['description'] = esc_attr(stripslashes($shadow_photo['description']['_content']));
                                                }
                                                $title_fragment = isset($sd[$link_title_field]) ? trim($sd[$link_title_field]) : '';
                                                $alt_fragment = isset($sd[$img_alt_field]) ? trim($sd[$img_alt_field]) : '';
                                                if ($download_link != 'no') {
                                                    $shadow_data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($shadow_data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                    if ($download_link == 'yes') {
                                                        if ($title_fragment !== '') {
                                                            $title_fragment .= $separator_character . $shadow_data['download'];
                                                        } else {
                                                            $title_fragment = $shadow_data['download'];
                                                        }
                                                    } else {
                                                        if ($alt_fragment !== '') {
                                                            $alt_fragment .= $separator_character . $shadow_data['download'];
                                                        } else {
                                                            $alt_fragment = $shadow_data['download'];
                                                        }
                                                    }
                                                }
                                                if ($flickr_link != 'no') {
                                                    $shadow_data['lightbox_link'] = esc_attr(stripslashes('<a href="http://www.flickr.com/photos/' . $flickr_user . '/' . $shadow_photo['id'] . '" target="' . $this->settings['flickr_link_target'] . '">' . __($flickr_link_text, 'jig_td') . '</a>'));
                                                    if ($flickr_link == 'yes') {
                                                        if ($title_fragment !== '') {
                                                            $title_fragment .= $separator_character . $shadow_data['lightbox_link'];
                                                        } else {
                                                            $title_fragment = $shadow_data['lightbox_link'];
                                                        }
                                                    } else {
                                                        if ($alt_fragment !== '') {
                                                            $alt_fragment .= $separator_character . $shadow_data['lightbox_link'];
                                                        } else {
                                                            $alt_fragment = $shadow_data['lightbox_link'];
                                                        }
                                                    }
                                                }
                                                $shadow_class = 'class="jig-link jig-contentID-FB-' . $shadow_photo['id'] . (empty($link_class) ? '' : ' ' . $link_class) . '" ';
                                                $shadow_gallery .= '<a href="' . $shadow_data['url'] . '" rel="' . $shadow_rel . '" ' . $shadow_class . $shadow_size . ' title="' . $title_fragment . '"><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="' . $alt_fragment . '" /></a>';
                                            }
                                            if (empty($data['gallery'])) {
                                                if (isset($data['title'])) {
                                                    $data['gallery']['title'] = $data['title'];
                                                }
                                                if (isset($data['description'])) {
                                                    $data['gallery']['description'] = $data['description'];
                                                }
                                                unset($data['title'], $data['description']);
                                                // Sadly Flickr doesn't provide the title as part of the the primary image's extras
                                                if (isset($data['gallery']['title'])) {
                                                    $data['title'] = esc_attr(stripslashes($data['gallery']['title']));
                                                }
                                                if (isset($photo['description']['_content'])) {
                                                    $data['description'] = esc_attr(stripslashes($photo['description']['_content']));
                                                }
                                                if ($download_link != 'no') {
                                                    $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                                }
                                                if ($flickr_link != 'no') {
                                                    $data['lightbox_link'] = esc_attr(stripslashes('<a href="http://www.flickr.com/photos/' . $flickr_user . '/' . $single_set['primary'] . '" target="' . $this->settings['flickr_link_target'] . '">' . __($flickr_link_text, 'jig_td') . '</a>'));
                                                }
                                            }
                                        }
                                        $shadow_gallery .= "</div>";
                                        unset($data['link']);
                                        $data['gallery']['html'] = $shadow_gallery;
                                        $data['gallery']['rel'] = $shadow_rel;
                                        $data['gallery']['id'] = $shadow_group_id;
                                        switch ($lightbox) {
                                            case 'foobox':
                                                $data['gallery']['lightbox_class'] = 'jigFooBoxConnect';
                                                break;
                                            case 'socialgallery':
                                                $data['gallery']['lightbox_class'] = 'jigSgConnect';
                                                break;
                                            default:
                                        }
                                    }
                                    array_push($this->images, $data);
                                }
                            } elseif (!empty($collections[$flickr_collection]['collection']) && count($collections[$flickr_collection]['collection']) > 0) {
                                // If the collection only includes subcollections
                                // some overwrites due to the very small size of the Flickr collection icons :(
                                $row_height = $max_height = 134;
                                $height_deviation = 0;
                                $disable_cropping = 'yes';
                                $aspect_ratio = '';
                                $retina_ready = 'no';
                                $use_timthumb = 'no';
                                foreach ($collections[$flickr_collection]['collection'] as $single_collection) {
                                    $data['url'] = substr($single_collection['iconlarge'], 0, 1) !== '/' ? $single_collection['iconlarge'] : 'http://www.flickr.com/images/collection_default_l.gif';
                                    $data['width'] = 179;
                                    $data['height'] = 134;
                                    if (!empty($single_collection['title'])) {
                                        $data['title'] = esc_attr(stripslashes($single_collection['title']));
                                    }
                                    if ($flickr_count == 'yes') {
                                        $description_fragments = array();
                                        if (!empty($single_collection['set']) && count($single_collection['set']) > 0) {
                                            $description_fragments[] = count($single_collection['set']) . ' ' . _n('Album', 'Albums', count($single_collection['set']), 'jig_td');
                                        } elseif (count($single_collection['collection']) > 0) {
                                            $description_fragments[] = count($single_collection['collection']) . ' ' . _n('Collection', 'Collections', count($single_collection['collection']), 'jig_td');
                                        }
                                        if (($flickr_description == 'yes' || $flickr_description == 'thumbnails') && !empty($single_collection['description'])) {
                                            $description_fragments[] = esc_attr(stripslashes($single_collection['description']));
                                        }
                                        $d['description'] = esc_attr(stripslashes(implode('<br />', $description_fragments)));
                                    } else {
                                        if (($flickr_description == 'yes' || $flickr_description == 'thumbnails') && !empty($single_collection['description'])) {
                                            $d['description'] = esc_attr(stripslashes($single_collection['description']));
                                        }
                                    }
                                    if ($d['description'] != '') {
                                        $data['description'] = $d['description'];
                                    }
                                    $data['link'] = $single_collection['id'];
                                    array_push($this->images, $data);
                                }
                            }
                            // Setting the proper links
                            foreach ($this->images as $image_index => &$data) {
                                if (!isset($data['link'])) {
                                    // Permalink is not needed when sets are opened in the lightbox
                                    continue;
                                }
                                $show_on_front = get_option('show_on_front');
                                $page_on_front = get_option('page_on_front');
                                $args[$this->settings['flickr_collections_slug']] = (!empty($collection_var) ? $collection_var . '/' : '') . $data['link'];
                                if ($wp_rewrite->using_permalinks()) {
                                    if (is_singular()) {
                                        $post = get_post(get_the_ID());
                                        $url = trailingslashit(get_permalink($post->ID));
                                        if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                            $url = trailingslashit(home_url($post->page_name ? $post->page_name : $post->post_name));
                                        }
                                    } else {
                                        $url = 'http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                                    }
                                    $url .= $this->settings['flickr_collections_slug'] . '/' . $args[$this->settings['flickr_collections_slug']];
                                    $data['link'] = $url;
                                } else {
                                    if (is_home()) {
                                        $args['pageid'] = get_the_ID();
                                    }
                                    if ($show_on_front == 'page' && $page_on_front == get_the_ID()) {
                                        $args['page_id'] = get_the_ID();
                                    }
                                    if (is_singular()) {
                                        $query = htmlspecialchars(add_query_arg($args, get_permalink(get_the_ID())));
                                    } else {
                                        $query = htmlspecialchars(add_query_arg($args));
                                    }
                                    $data['link'] = esc_url($query);
                                }
                            }
                            unset($image_index, $data);
                            break;
                        }
                    }
                    if ($flickr_photostream !== '') {
                        $photos_url_bit = 'flickr.people.getPublicPhotos&user_id=' . $flickr_photostream;
                    } elseif ($flickr_favorites !== '') {
                        $photos_url_bit = 'flickr.favorites.getPublicList&user_id=' . $flickr_favorites;
                    } elseif ($flickr_group !== '') {
                        $photos_url_bit = 'flickr.groups.pools.getPhotos&group_id=' . $flickr_group;
                    } elseif ($flickr_photoset !== '') {
                        $photos_url_bit = 'flickr.photosets.getPhotos&photoset_id=' . $flickr_photoset;
                    } elseif ($flickr_gallery !== '') {
                        $photos_url_bit = 'flickr.galleries.getPhotos&gallery_id=' . $flickr_gallery;
                    } elseif ($flickr_search_text !== '' || $flickr_search_tags !== '') {
                        $photos_url_bit = 'flickr.photos.search&content_type=1';
                        if ($flickr_search_text !== '') {
                            $photos_url_bit .= '&text=' . urlencode($flickr_search_text);
                        }
                        if ($flickr_search_tags !== '') {
                            $photos_url_bit .= '&tags=' . urlencode($flickr_search_tags);
                        }
                        if ($flickr_search_tags_m !== '') {
                            $photos_url_bit .= '&tag_mode=' . $flickr_search_tags_m;
                        }
                        if ($flickr_search_user !== '') {
                            $photos_url_bit .= '&user_id=' . $flickr_search_user;
                        }
                        if ($flickr_search_group !== '') {
                            $photos_url_bit .= '&group_id=' . $flickr_search_group;
                        }
                        if ($flickr_search_sort !== 'date-posted-desc') {
                            $photos_url_bit .= '&sort=' . $flickr_search_sort;
                        }
                        if ($flickr_search_license !== '') {
                            $photos_url_bit .= '&license=' . $flickr_search_license;
                        }
                        if ($flickr_search_geo !== '') {
                            $photos_url_bit .= '&has_geo=' . $flickr_search_geo;
                        }
                    }
                    $photos_url = 'https://api.flickr.com/services/rest?api_key=' . trim($this->settings['fli_api_key']) . '&format=php_serial&method=' . $photos_url_bit . $limit_parameter . '&extras=description,tags,geo,url_o,url_k,url_h,url_l,url_c,url_z,url_m,url_n,url_s,url_t';
                    if ($flickr_caching > 0) {
                        if (get_transient('jigfli_' . md5($photos_url . $flickr_caching)) == true) {
                            $photos = get_transient('jigfli_' . md5($photos_url . $flickr_caching));
                        } else {
                            $photos = maybe_unserialize($this->file_get_contents_curl($photos_url));
                            set_transient('jigfli_' . md5($photos_url . $flickr_caching), $photos, 60 * $flickr_caching);
                        }
                    } else {
                        $photos = maybe_unserialize($this->file_get_contents_curl($photos_url));
                    }
                    if (!empty($photos) && $photos['stat'] == "ok") {
                        if ($retina_ready == 'yes') {
                            $calculated_max_height = $max_height * 3;
                        } else {
                            $calculated_max_height = $max_height;
                        }
                        $this->images = array();
                        // Create a new array for the images
                        if (isset($photos['photos']) && count($photos['photos']['photo']) > 0 || isset($photos['photoset']) && count($photos['photoset']['photo'])) {
                            // Make photoset mimic the other sources
                            if (isset($photos['photoset'])) {
                                $photos['photos'] = $photos['photoset'];
                            }
                            if ($orderby == 'rand') {
                                $photos['photos']['photo'] = (array) $photos['photos']['photo'];
                                shuffle($photos['photos']['photo']);
                            }
                            //$too_small_flickr_images = 0;
                            foreach ($photos['photos']['photo'] as $photo) {
                                $data = array();
                                // Create a new array for this image
                                if (!empty($photo['longitude']) && !empty($photo['latitude']) && !empty($photo['accuracy'])) {
                                    $data['geo'] = $photo['latitude'] . ',' . $photo['longitude'] . ',' . $photo['accuracy'];
                                }
                                if (isset($photo['height_t']) && $photo['height_t'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_t'];
                                } elseif (isset($photo['height_s']) && $photo['height_s'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_s'];
                                } elseif (isset($photo['height_n']) && $photo['height_n'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_n'];
                                } elseif (isset($photo['height_m']) && $photo['height_m'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_m'];
                                } elseif (isset($photo['height_z']) && $photo['height_z'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_z'];
                                } elseif (isset($photo['height_c']) && $photo['height_c'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_c'];
                                } elseif (isset($photo['height_l']) && $photo['height_l'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_l'];
                                } elseif (isset($photo['height_h']) && $photo['height_h'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_h'];
                                } elseif (isset($photo['height_k']) && $photo['height_k'] >= $calculated_max_height) {
                                    $data['thumbUrl'] = $photo['url_k'];
                                } else {
                                    //$too_small_flickr_images++;
                                    if ($this->settings['flickr_too_small_images'] !== 'upscale') {
                                        continue;
                                    } else {
                                        //$randomize_width = 0;
                                        $flickr_upscale_this = true;
                                    }
                                }
                                if ($this->settings['flickr_allow_big_images'] === 'original' && isset($photo['url_o'])) {
                                    $data['url'] = $photo['url_o'];
                                    $data['width'] = $photo['width_o'];
                                    $data['height'] = $photo['height_o'];
                                } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($photo['url_k'])) {
                                    $data['url'] = $photo['url_k'];
                                    $data['width'] = $photo['width_k'];
                                    $data['height'] = $photo['height_k'];
                                } elseif ($this->settings['flickr_allow_big_images'] !== 'no' && isset($photo['url_h'])) {
                                    $data['url'] = $photo['url_h'];
                                    $data['width'] = $photo['width_h'];
                                    $data['height'] = $photo['height_h'];
                                } elseif (isset($photo['url_l'])) {
                                    $data['url'] = $photo['url_l'];
                                    $data['width'] = $photo['width_l'];
                                    $data['height'] = $photo['height_l'];
                                } elseif (isset($photo['url_c'])) {
                                    $data['url'] = $photo['url_c'];
                                    $data['width'] = $photo['width_c'];
                                    $data['height'] = $photo['height_c'];
                                } elseif (isset($photo['url_z'])) {
                                    $data['url'] = $photo['url_z'];
                                    $data['width'] = $photo['width_z'];
                                    $data['height'] = $photo['height_z'];
                                } elseif (isset($photo['url_m'])) {
                                    $data['url'] = $photo['url_m'];
                                    $data['width'] = $photo['width_m'];
                                    $data['height'] = $photo['height_m'];
                                } elseif (isset($photo['url_n'])) {
                                    $data['url'] = $photo['url_n'];
                                    $data['width'] = $photo['width_n'];
                                    $data['height'] = $photo['height_n'];
                                } elseif (isset($photo['url_s'])) {
                                    $data['url'] = $photo['url_s'];
                                    $data['width'] = $photo['width_s'];
                                    $data['height'] = $photo['height_s'];
                                } elseif (isset($photo['url_t'])) {
                                    $data['url'] = $photo['url_t'];
                                    $data['width'] = $photo['width_t'];
                                    $data['height'] = $photo['height_t'];
                                } else {
                                    unset($flickr_upscale_this);
                                    continue;
                                }
                                if (isset($flickr_upscale_this)) {
                                    unset($flickr_upscale_this);
                                    $flickr_upscale_key = array_search($data['url'], $photo, true);
                                    if ($flickr_upscale_key !== false) {
                                        $flickr_upscale_key = substr($flickr_upscale_key, -1);
                                        $data['width'] = $photo['width_' . $flickr_upscale_key];
                                        $data['height'] = $photo['height_' . $flickr_upscale_key];
                                    } else {
                                        continue;
                                    }
                                }
                                if (!empty($photo['title'])) {
                                    $d['title'] = esc_attr(stripslashes(trim($photo['title'])));
                                    if ($d['title'] != '') {
                                        $data['title'] = $d['title'];
                                    }
                                }
                                if (!empty($photo['description']['_content'])) {
                                    $d['description'] = esc_attr(stripslashes(trim($photo['description']['_content'])));
                                    if ($d['description'] != '') {
                                        $data['description'] = $d['description'];
                                    }
                                }
                                if ($download_link != 'no') {
                                    $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                }
                                if ($flickr_link != 'no') {
                                    $data['lightbox_link'] = esc_attr(stripslashes('<a href="http://www.flickr.com/photos/' . (!empty($photo['owner']) ? $photo['owner'] : $flickr_user) . '/' . $photo['id'] . '" target="' . $this->settings['flickr_link_target'] . '">' . __($flickr_link_text, 'jig_td') . '</a>'));
                                }
                                if ($flickr_link != 'no') {
                                    if ($flickr_link != 'direct') {
                                        $data['lightbox_link'] = esc_attr(stripslashes('<a href="http://www.flickr.com/photos/' . (!empty($photo['owner']) ? $photo['owner'] : $flickr_user) . '/' . $photo['id'] . '" target="' . $this->settings['flickr_link_target'] . '">' . __($flickr_link_text, 'jig_td') . '</a>'));
                                    } else {
                                        $data['link'] = 'http://www.flickr.com/photos/' . (!empty($photo['owner']) ? $photo['owner'] : $flickr_user) . '/' . $photo['id'];
                                        $data['link_target'] = $this->settings['flickr_link_target'];
                                    }
                                }
                                if ($filterby == 'on') {
                                    $d['filters'] = $photo['tags'];
                                    if (!empty($d['filters'])) {
                                        $d['filters'] = explode(' ', $d['filters']);
                                        foreach ($d['filters'] as $filter_term) {
                                            if (strstr($filter_term, ':') === false) {
                                                $data['filters'][] = array($filter_term, ucfirst($filter_term));
                                            }
                                        }
                                    }
                                }
                                if ($this->settings['image_custom_classes'] !== 'nothing') {
                                    $data['extra_class'] = 'jig-contentID-FL-' . $photo['id'];
                                }
                                array_push($this->images, $data);
                            }
                            if ($flickr_photoset !== '' && !empty($flickr_set_list) && !empty($this->images) && $flickr_description == 'yes') {
                                if (($flickr_description == 'yes' || $flickr_description == 'above') && !empty($flickr_set_list[$flickr_photoset]['description']['_content'])) {
                                    $notice_before .= '<p class="jig-fliDescription">' . $flickr_set_list[$flickr_photoset]['description']['_content'] . '</p>';
                                }
                            }
                            /*  if($too_small_flickr_images !== 0 && $this->settings['flickr_too_small_images'] == 'error'){
                            					$notice_after .= sprintf(__('Justified Image Grid: %d Flickr images are not shown because they are too small. Decrease row_height and height_deviation until all your photos show up. Tip: Start with a combined value of no larger than 200. Your current maximum height is %d (%d row_height + %d height_deviation).', 'jig_td'),$too_small_flickr_images,$calculated_max_height,$row_height,$height_deviation);
                            				}*/
                        } else {
                            if ($flickr_search_text !== '' || $flickr_search_tags !== '') {
                                return $this->frontend_stop(__('There are no photos that match your search criteria.', 'jig_td'));
                            } else {
                                return $this->frontend_stop(__('The requested photo source is not recognized.', 'jig_td'));
                            }
                        }
                    } else {
                        return $this->frontend_stop(__('The requested photo source cannot be loaded at this time.', 'jig_td') . ($photos['message'] ? ' ' . $photos['message'] : ''));
                    }
                    break;
                case 'instagram':
                    $endpoint_url = 'https://api.instagram.com/v1';
                    $first_valid_access_token = '';
                    if (!empty($this->settings['ig_authed'])) {
                        foreach ($this->settings['ig_authed'] as $user) {
                            $authed_user = $user['id'];
                            $first_valid_access_token = $user['access_token'];
                            break;
                        }
                    }
                    if ($first_valid_access_token === '') {
                        return $this->frontend_stop(__('No access token found, please authorize an Instagram user.', 'jig_td'));
                    }
                    if ($instagram_feed !== '') {
                        $authed_user = $instagram_feed;
                        $endpoint_url .= '/users/self/feed?access_token=' . $this->settings['ig_authed'][$instagram_feed]['access_token'];
                    } elseif ($instagram_recents !== '') {
                        $endpoint_url .= '/users/' . $instagram_recents . '/media/recent?access_token=' . $first_valid_access_token;
                    } elseif ($instagram_liked !== '') {
                        $endpoint_url .= '/users/self/media/liked?access_token=' . $this->settings['ig_authed'][$instagram_liked]['access_token'];
                        $authed_user = $instagram_liked;
                    } elseif ($instagram_tag !== '') {
                        $endpoint_url .= '/tags/' . $instagram_tag . '/media/recent?access_token=' . $first_valid_access_token;
                    } elseif ($instagram_location !== '') {
                        $endpoint_url .= '/locations/' . $instagram_location . '/media/recent?access_token=' . $first_valid_access_token;
                    }
                    if ($limit === '0') {
                        $endpoint_url .= "&count=100";
                        $limit = 100;
                    } else {
                        if ($limit !== '') {
                            $endpoint_url .= "&count=" . $limit;
                            $limit = (int) $limit;
                        } else {
                            $endpoint_url .= "&count=20";
                            $limit = 20;
                        }
                    }
                    $photos = $this->instagram_api_call($endpoint_url, $instagram_caching, $limit);
                    if ($limit !== '' && count($photos) > $limit) {
                        $photos = array_slice($photos, 0, $limit);
                    }
                    $instagram_blacklist = explode(',', str_replace(', ', ',', $instagram_blacklist));
                    if (!isset($photos['message'])) {
                        $this->images = array();
                        // Create a new array for the images
                        if (count($photos) > 0) {
                            if ($orderby == 'rand') {
                                $photos = (array) $photos;
                                shuffle($photos);
                            }
                            if ($retina_ready == 'yes') {
                                $calculated_max_height = $max_height * 3;
                            } else {
                                $calculated_max_height = $max_height;
                            }
                            foreach ($photos as $photo) {
                                if (isset($photo->images) && ($photo->type == 'image' || $photo->type == 'video')) {
                                    if ($instagram_blacklist !== '') {
                                        if (in_array($photo->user->username, $instagram_blacklist) || in_array($photo->user->id, $instagram_blacklist)) {
                                            continue;
                                        }
                                    }
                                    $data = array();
                                    // Create a new array for this image
                                    if ($photo->type == 'image') {
                                        $data['url'] = $photo->images->standard_resolution->url;
                                    } else {
                                        $data['link'] = $photo->videos->standard_resolution->url;
                                        $data['link_target'] = 'videoplayer';
                                        $data['url'] = $photo->images->standard_resolution->url;
                                    }
                                    if ($photo->images->thumbnail->height >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo->images->thumbnail->url;
                                        $data['width'] = $photo->images->thumbnail->width;
                                        $data['height'] = $photo->images->thumbnail->height;
                                    } elseif ($photo->images->low_resolution->height >= $calculated_max_height) {
                                        $data['thumbUrl'] = $photo->images->low_resolution->url;
                                        $data['width'] = $photo->images->low_resolution->width;
                                        $data['height'] = $photo->images->low_resolution->height;
                                    } else {
                                        $data['width'] = $photo->images->standard_resolution->width;
                                        $data['height'] = $photo->images->standard_resolution->height;
                                    }
                                    if (!empty($photo->caption->text)) {
                                        $data['title'] = esc_attr(stripslashes($photo->caption->text));
                                    }
                                    if ($instagram_show_user == 'title') {
                                        $data['title'] = (!empty($data['title']) ? $data['title'] . $separator_character : '') . esc_attr(stripslashes('<a href="http://instagram.com/' . $photo->user->username . '" target="_blank">' . $photo->user->username . '</a>'));
                                    } elseif ($instagram_show_user == 'description') {
                                        $data['description'] = esc_attr(stripslashes('<a href="http://instagram.com/' . $photo->user->username . '" target="_blank">' . $photo->user->username . '</a>'));
                                    }
                                    if ($download_link != 'no') {
                                        $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                                    }
                                    if ($instagram_link != 'no') {
                                        if ($instagram_link != 'direct') {
                                            $data['lightbox_link'] = esc_attr(stripslashes('<a href="' . $photo->link . '" target="' . $this->settings['instagram_link_target'] . '">' . ($photo->type == 'image' ? __($instagram_link_text, 'jig_td') : str_replace(__('photo', 'jig_td'), __('video', 'jig_td'), __($instagram_link_text, 'jig_td'))) . '</a>'));
                                        } else {
                                            $data['link'] = $photo->link;
                                            $data['link_target'] = $this->settings['instagram_link_target'];
                                        }
                                    }
                                    if ($filterby == 'on' || $instagram_tag_filter) {
                                        $d['filters'] = $photo->tags;
                                        if (!empty($d['filters'])) {
                                            foreach ($d['filters'] as $filter_term) {
                                                $data['filters'][] = array($filter_term, ucfirst($filter_term));
                                            }
                                        }
                                    }
                                    if ($this->settings['image_custom_classes'] !== 'nothing') {
                                        $data['extra_class'] = 'jig-contentID-IG-' . $photo->id;
                                    }
                                    array_push($this->images, $data);
                                }
                            }
                        } else {
                            return $this->frontend_stop(__('The requested photo source is empty.', 'jig_td'));
                        }
                    } else {
                        if (isset($photos['error_type']) && $photos['error_type'] == "OAuthAccessTokenException") {
                            if (!empty($this->settings_backup)) {
                                // restoring the settings after a preset has changed it
                                $this->settings = $this->settings_backup;
                            }
                            $this->settings['ig_authed'][$authed_user]['validity'] = 'expired';
                            update_option(self::SETTINGS_NAME, $this->settings);
                        }
                        return $this->frontend_stop(__('The requested photo source cannot be loaded at this time.', 'jig_td') . ' ' . $photos['message']);
                    }
                    break;
                case 'rss':
                    if ($limit === '0') {
                        $limit = 0;
                    } else {
                        if ($limit !== '') {
                            $limit = (int) $limit;
                        } else {
                            $limit = 0;
                        }
                    }
                    $rss_url = htmlspecialchars_decode($rss_url);
                    $is_youtube = stripos($rss_url, 'youtube.com') !== false;
                    if ($rss_url !== '<a') {
                        $rss_url = explode(',', $rss_url);
                        // Accept multiple URLs
                    } elseif ($href !== '') {
                        $rss_url = explode(',', $href);
                        // Accept multiple URLs
                    }
                    $rss_url = str_replace('uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile', 'uploads?max-results=50', $rss_url);
                    // If there is only just 1 feed, do not use an array because it triggers Simplepie's multifeed features which force-sorts by item date, resulting undesired order in e.g. Picasa feeds -.-
                    if (count($rss_url) == 1) {
                        $rss_url = $rss_url[0];
                    }
                    $this->images = array();
                    // Create a new array for the images
                    if (!$is_youtube) {
                        include_once ABSPATH . WPINC . '/feed.php';
                        add_action('wp_feed_options', array($this, 'jig_add_force_rss'), 10, 2);
                        if (!is_numeric($rss_caching)) {
                            $rss = fetch_feed($rss_url);
                        } else {
                            $this->rss_cache_override = $rss_caching;
                            add_filter('wp_feed_cache_transient_lifetime', array($this, 'jig_set_rss_cache'));
                            $rss = fetch_feed($rss_url);
                            remove_filter('wp_feed_cache_transient_lifetime', array($this, 'jig_set_rss_cache'));
                        }
                        remove_action('wp_feed_options', array($this, 'jig_add_force_rss'), 10);
                        if (is_wp_error($rss)) {
                            $rss_sp_error_message = $rss->get_error_message();
                            return $this->frontend_stop(__('The requested RSS feed cannot be loaded at this time.', 'jig_td') . ' ' . (is_string($rss_sp_error_message) ? $rss_sp_error_message : $rss_sp_error_message[0]));
                        }
                        $rss_items = $rss->get_items(0, $rss->get_item_quantity($limit));
                    } else {
                        // If this is a youtube URL
                        if (is_array($rss_url)) {
                            $rss_url_count = count($rss_url);
                        } else {
                            $rss_url = array($rss_url);
                            $rss_url_count = 1;
                        }
                        $rss_items = array();
                        foreach ($rss_url as $rss_url_index => $single_rss_url) {
                            $rss_caching = (int) $rss_caching;
                            if ($rss_caching !== 0) {
                                $actual_rss_caching = $rss_caching ? $rss_caching : 720;
                                $cached_value = get_transient('jigrss_' . md5($single_rss_url . $actual_rss_caching . $limit));
                                if (!empty($cached_value) == true) {
                                    $rss_items[$rss_url_index] = $cached_value;
                                }
                                if (empty($rss_items[$rss_url_index])) {
                                    $rss_items[$rss_url_index] = $this->scrape_youtube($single_rss_url, $limit, $rss_description);
                                    if (!is_string($cached_value)) {
                                        set_transient('jigrss_' . md5($single_rss_url . $actual_rss_caching . $limit), $rss_items[$rss_url_index], 60 * $actual_rss_caching);
                                    }
                                }
                            }
                            if (empty($rss_items[$rss_url_index])) {
                                $rss_items[$rss_url_index] = $this->scrape_youtube($single_rss_url, $limit, $rss_description);
                            }
                            if (is_string($rss_items[$rss_url_index])) {
                                return $this->frontend_stop($rss_items[$rss_url_index]);
                            }
                        }
                        unset($rss_url_index, $single_rss_url);
                        if ($rss_url_count > 1) {
                            // merge n arrays
                            // sort by a custom funtion, strtotime each value of each array
                            // result a single array that looks just like one normal rss_items
                            $merged_rss_items = array();
                            foreach ($rss_items as $single_rss_items_list) {
                                $merged_rss_items = array_merge($merged_rss_items, $single_rss_items_list);
                            }
                            unset($single_rss_items_list);
                            foreach ($merged_rss_items as $merged_rss_items_index => &$single_rss_item) {
                                // The time index is substracted from the unix time so the original is preserved
                                // The exact time is not known as the nice time is pretty vague ("1 year ago")
                                $single_rss_item->unix_date = strtotime($single_rss_item->get_date) - $merged_rss_items_index;
                            }
                            unset($merged_rss_items_index, $single_rss_item);
                            usort($merged_rss_items, array($this, 'sort_youtube_rss'));
                            $rss_items = $merged_rss_items;
                        } else {
                            $rss_items = $rss_items[0];
                        }
                    }
                    if (count($rss_items) === 0) {
                        return $this->frontend_stop(__('The requested RSS feed is empty.', 'jig_td'));
                    }
                    if ($orderby == 'rand') {
                        $rss_items = (array) $rss_items;
                        shuffle($rss_items);
                    }
                    $url_hash_list = array();
                    foreach ($rss_items as $rss_item_index => &$item) {
                        $imageURL = false;
                        $enclosure_links = $item->get_enclosures();
                        $enclosure_image = false;
                        // Find enclosures, if possible
                        if (!empty($enclosure_links)) {
                            // Gravatar images are skipped for WP
                            foreach ($enclosure_links as $enclosure_entry) {
                                if (!empty($enclosure_entry)) {
                                    $enclosure_link = $enclosure_entry->get_link();
                                    if (!empty($enclosure_link) && strpos($enclosure_link, 'gravatar') === false && $enclosure_link !== '//?#' && preg_match('/\\.(jpe?g|gif|png|bmp|webp)/im', $enclosure_link)) {
                                        // Test for images
                                        $enclosure_image = $enclosure_link;
                                    } else {
                                        if (!empty($enclosure_entry->thumbnails[0])) {
                                            if (preg_match('%.*vimeocdn\\.com/video/[^_]*%im', $enclosure_entry->thumbnails[0], $regs)) {
                                                $enclosure_image = $regs[0] . '.jpg';
                                            } else {
                                                continue;
                                            }
                                        } else {
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                        // 1. Use enclosures if any good found
                        if (!empty($enclosure_image)) {
                            $imageURL = $enclosure_image;
                        } else {
                            // 2. Find article images in HTML
                            $text = html_entity_decode($item->get_content(), ENT_QUOTES, 'UTF-8');
                            if (preg_match("/<img[^>]+\\>/i", $text, $matches) === 1) {
                                if (preg_match('/src=[\'"]?([^\'">]+)[\'" >]/', $matches[0], $link) === 1) {
                                    $imageURL = urldecode($link[1]);
                                }
                            }
                        }
                        // 3. Fall back for article thumbnail, if any
                        if (empty($imageURL) && ($thumb = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))) {
                            $imageURL = $thumb[0]['attribs']['']['url'];
                        }
                        if (empty($imageURL)) {
                            // if no image is found, skip that RSS item
                            unset($rss_items[$rss_item_index]);
                            continue;
                        }
                        // Handle protocol flexible links in RSS
                        if (substr($imageURL, 0, 2) == '//') {
                            $imageURL = (!is_ssl() ? 'http:' : 'https:') . $imageURL;
                        }
                        $rss_parsed_imageURL = parse_url($imageURL);
                        // Handle relative links in RSS
                        if (empty($rss_parsed_imageURL['host'])) {
                            $rss_parsed_url = parse_url($item->get_feed()->subscribe_url());
                            // get the current feed URL (needs to be like this because of multifeed)
                            $imageURL = $rss_parsed_url['scheme'] . '://' . $rss_parsed_url['host'] . $imageURL;
                        }
                        $imageURL = str_replace(' ', '%2B', $imageURL);
                        $url_hash_list[] = hash('md5', $imageURL);
                        $item->jig_image_src = array($imageURL);
                    }
                    unset($item, $imageURL);
                    if (!$this->jig_query_ext_images($url_hash_list)) {
                        $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                    }
                    foreach ($rss_items as $item) {
                        $item->jig_image_src = $this->jig_get_ext_imagesize($item->jig_image_src);
                        if (!empty($item->jig_image_src[1]) && !empty($item->jig_image_src[2]) && $item->jig_image_src[1] > 16) {
                            $data = $d = array();
                            // Create a new array for this image
                            $data['url'] = $item->jig_image_src[0];
                            $data['width'] = $item->jig_image_src[1];
                            $data['height'] = $item->jig_image_src[2];
                            $data['title'] = esc_attr(stripslashes($item->get_title()));
                            switch ($rss_description) {
                                case 'none':
                                    break;
                                case 'excerpt':
                                    // Excerpt is a controlled, textual story-based short description display that disallows html to aboid broken tags and has a fixed length
                                    $d['description'] = stripslashes(trim(strip_tags($item->get_description(), '<br>')));
                                    // This is stronger for matching individual words, as it disregards any whitespace between them and later recombines with single space
                                    preg_match_all('/\\S+/m', $d['description'], $rss_words, PREG_PATTERN_ORDER);
                                    $rss_words = $rss_words[0];
                                    if (count($rss_words) > (int) $rss_excerpt_length) {
                                        // this checks if the length is really longer than desired (could be exactly that long or shorter)
                                        $d['description'] = implode(' ', array_slice($rss_words, 0, (int) $rss_excerpt_length));
                                        if ($rss_excerpt_ending !== 'none') {
                                            $d['description'] .= strtr($rss_excerpt_ending, array("(" => "[", ")" => "]"));
                                        }
                                    }
                                    break;
                                case 'description':
                                    // regex removes the broken or unnecessary (p) and br tags in the beginning and the end as well as empty links, : at the end
                                    $d['description'] = stripslashes(trim(preg_replace('%<a[^>]*></a>%m', '', preg_replace('%(^(<(br|/p|p></p)\\s*+(/>|>))*+)|(((<(br|p></p)\\s*+(/>|>))|:)*+$)%m', '', strip_tags($item->get_description(), '<font><span><i><b><strong><italic><br><a>')))));
                                    break;
                                case 'datetime':
                                    $d['description'] = $item->get_date(get_option('date_format') . ' ' . get_option('time_format'));
                                    break;
                                case 'date':
                                    $d['description'] = $item->get_date(get_option('date_format'));
                                    break;
                                case 'nicetime':
                                    $d['description'] = $this->jig_nice_time($item->get_date());
                                    break;
                            }
                            if (!empty($d['description'])) {
                                $data['description'] = esc_attr($d['description']);
                            }
                            if ($rss_links_to === 'permalink') {
                                $data['link'] = $item->get_permalink();
                                $data['link_target'] = $link_target;
                                if ($data['link_target'] == 'video' && $lightbox === 'prettyphoto' && preg_match('%(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\\.(?:jpg|gif|png))(?:\\?([^#]*))?(?:#(.*))?%m', $data['link']) !== 1) {
                                    $data['link'] .= '?iframe=true';
                                }
                                $d['link_rel'] = array();
                                if ($data['link_target'] == '_blank') {
                                    $d['link_rel'][] = 'external';
                                }
                                if ($custom_link_follow == 'no') {
                                    $d['link_rel'][] = 'nofollow';
                                }
                                $d['link_rel_imploded'] = implode(' ', $d['link_rel']);
                                if ($d['link_rel_imploded'] != '') {
                                    $data['link_rel'] = $d['link_rel_imploded'];
                                }
                            }
                            if ($download_link != 'no') {
                                $data['download'] = esc_attr(stripslashes('<a href="' . plugins_url('download.php', __FILE__) . '?file=' . urlencode($data['url']) . '">' . __($download_link_text, 'jig_td') . '</a>'));
                            }
                            if ($rss_link != 'no') {
                                $data['lightbox_link'] = esc_attr(stripslashes('<a href="' . $item->get_permalink() . '" target="' . $this->settings['rss_link_target'] . '">' . __($rss_link_text, 'jig_td') . '</a>'));
                            }
                            array_push($this->images, $data);
                        }
                    }
                    break;
            }
            // end of the big switch()
            if (empty($this->images)) {
                return $this->frontend_stop(__('Justified Image Grid error: there are no images to show, the items are empty.', 'jig_td'));
            }
            if ($link_rel) {
                $link_rel = strtr($link_rel, array("(" => "[", ")" => "]"));
            }
            $borders_total = 0;
            if ($outer_border_width || $middle_border_width) {
                $borders_total = (intval($outer_border_width) + intval($middle_border_width)) * 2;
            }
            $outer_border_CSS = '';
            $middle_border_color_CSS = '';
            $middle_border_width_CSS = '';
            $inner_border_CSS = '';
            $inner_border_display = '';
            $inner_border_width_fragment = $inner_border_width;
            $caption_wrapper_additional_css = '';
            if ($inner_border === "hovered") {
                if ($inner_border_animate === "width") {
                    $inner_border_width_fragment = 0;
                } else {
                    $inner_border_display = 'display:none;';
                }
            }
            if ($inner_border_width) {
                $inner_border_CSS = "#jig{$jig_id} .jig-border {\r\n\t\t\t\t\t\t\t\tbottom: 0;\r\n\t\t\t\t\t\t\t\tright: 0;\r\n\t\t\t\t\t\t\t\tleft: 0;\r\n\t\t\t\t\t\t\t\ttop: 0;\r\n\t\t\t\t\t\t\t\tposition: absolute;\r\n\t\t\t\t\t\t\t\tmargin:0;\r\n\t\t\t\t\t\t\t\tpadding:0;\r\n\t\t\t\t\t\t\t\tz-index:120;\r\n\t\t\t\t\t\t\t\toverflow:hidden;\r\n\t\t\t\t\t\t\t\tborder: {$inner_border_width_fragment}px solid {$inner_border_color}; /*   1px solid rgba(0, 0, 0, 0.9) */\r\n\t\t\t\t\t\t\t\t{$inner_border_display}\r\n\t\t\t\t\t\t\t}";
            }
            if ($outer_border_width) {
                $outer_border_CSS = "border-style: solid;\r\n\t\t\t\t\t\t\t\t\tborder-width: {$outer_border_width}px;";
                if ($outer_border === 'hovered') {
                    $outer_border_CSS .= "border-color: transparent;";
                } else {
                    $outer_border_CSS .= "border-color: {$outer_border_color};";
                }
            }
            if ($middle_border_width) {
                if ($middle_border === 'hovered') {
                    $middle_border_color_CSS = "background-color: transparent;";
                } else {
                    $middle_border_color_CSS = "background-color: {$middle_border_color};";
                }
                if ($caption == 'below' && $middle_border !== 'always') {
                    if ($middle_border_width && $inner_border == 'always') {
                        $caption_wrapper_additional_css = "margin-left: {$middle_border_width}px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmargin-right: {$middle_border_width}px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-left: {$inner_border_width}px solid {$inner_border_color};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-right: {$inner_border_width}px solid {$inner_border_color};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-bottom: {$inner_border_width}px solid {$inner_border_color};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmargin-top: -{$middle_border_width}px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmargin-bottom: {$middle_border_width}px;";
                    } else {
                        $caption_wrapper_additional_css = "margin-top: -{$middle_border_width}px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmargin-bottom: {$middle_border_width}px;";
                    }
                }
                $middle_border_width_CSS = "margin: {$middle_border_width}px;";
            }
            if ($outer_border_width && $middle_border_width && $outer_border !== 'always' && $middle_border !== 'always') {
                $animation_speed_seconds = $animation_speed / 1000;
                $outer_border_CSS .= "-webkit-transition:border-color {$animation_speed_seconds}s, background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-moz-transition:border-color {$animation_speed_seconds}s, background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-o-transition:border-color {$animation_speed_seconds}s, background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\ttransition:border-color {$animation_speed_seconds}s, background {$animation_speed_seconds}s";
            } elseif ($outer_border_width && $outer_border !== 'always') {
                $animation_speed_seconds = $animation_speed / 1000;
                $outer_border_CSS .= "-webkit-transition:border-color {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-moz-transition:border-color {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-o-transition:border-color {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\ttransition:border-color {$animation_speed_seconds}s";
            } elseif ($middle_border_width && $middle_border !== 'always') {
                $animation_speed_seconds = $animation_speed / 1000;
                $middle_border_color_CSS .= "-webkit-transition:background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-moz-transition:background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\t-o-transition:background {$animation_speed_seconds}s;\r\n\t\t\t\t\t\t\t\t\t\t\t\ttransition:background {$animation_speed_seconds}s";
            }
            $outer_shadow_CSS = '';
            $inner_shadow_CSS = '';
            if ($outer_shadow !== 'none') {
                $outer_shadow_CSS = "box-shadow: {$outer_shadow};";
            }
            if ($inner_shadow !== 'none') {
                $inner_shadow_CSS = "box-shadow: {$inner_shadow} inset;";
            }
            $overlay_CSS = '';
            if ($overlay != 'off') {
                $overlay_appearance_CSS = '';
                if ($overlay == 'hovered') {
                    $overlay_appearance_CSS .= 'display:none;';
                }
                $overlay_CSS = "#jig{$jig_id} .jig-overlay {\r\n\t\t\t\t\t\t\tbackground:{$overlay_color};\r\n\t\t\t\t\t\t\topacity: {$overlay_opacity};\r\n\t\t\t\t\t\t\t-moz-opacity: {$overlay_opacity};\r\n\t\t\t\t\t\t\tfilter:alpha(opacity=" . $overlay_opacity * 100 . ");\r\n\t\t\t\t\t\t\theight:100%;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-overlay-wrapper {\r\n\t\t\t\t\t\t\t{$overlay_appearance_CSS}\r\n\t\t\t\t\t\t\tposition: absolute;\r\n\t\t\t\t\t\t\tbottom: 0;\r\n\t\t\t\t\t\t\tleft: 0;\r\n\t\t\t\t\t\t\tright: 0;\r\n\t\t\t\t\t\t\ttop: 0;\r\n\t\t\t\t\t\t\t{$inner_shadow_CSS}\r\n\t\t\t\t\t\t}";
                if ($overlay_icon === 'on') {
                    $overlay_CSS .= "#jig{$jig_id} .jig-overlay-icon-wrapper {\r\n\t\t\t\t\t\t\t{$overlay_appearance_CSS}\r\n\t\t\t\t\t\t\tposition: absolute;\r\n\t\t\t\t\t\t\tbottom: 0;\r\n\t\t\t\t\t\t\tleft: 0;\r\n\t\t\t\t\t\t\tright: 0;\r\n\t\t\t\t\t\t\ttop: 0;\r\n\t\t\t\t\t\t}";
                    $overlay_icon_url_for_CSS = $overlay_icon_url ? $overlay_icon_url : plugins_url('images/magnifier.png', __FILE__);
                    $overlay_CSS .= "#jig{$jig_id} .jig-overlay-icon {\r\n\t\t\t\t\t\t\t\t\t\tbackground: url(" . $overlay_icon_url_for_CSS . ") no-repeat center center;\r\n\t\t\t\t\t\t\t\t\t\topacity: {$overlay_icon_opacity};\r\n\t\t\t\t\t\t\t\t\t\t-moz-opacity: {$overlay_icon_opacity};\r\n\t\t\t\t\t\t\t\t\t\tfilter:alpha(opacity=" . $overlay_icon_opacity * 100 . ");\r\n\t\t\t\t\t\t\t\t\t\theight:100%;\r\n\t\t\t\t\t\t\t\t\t}";
                    if ($retina_ready == 'yes') {
                        $overlay_icon_retina_for_CSS = $overlay_icon_retina ? $overlay_icon_retina : ($overlay_icon_url ? $overlay_icon_url : plugins_url('images/magnifier@2x.png', __FILE__));
                        if (empty($overlay_icon_url)) {
                            $ov_icon_px = "56px 56px";
                        } else {
                            if (!$this->jig_query_ext_images(array(hash('md5', $overlay_icon_url_for_CSS)))) {
                                $notice_after .= __('Cannot create database for caching external image dimensions.', 'jig_td');
                            }
                            $overlay_icon_image_for_CSS = $this->jig_get_ext_imagesize(array($overlay_icon_url_for_CSS));
                            $ov_icon_px = $overlay_icon_image_for_CSS[1] . "px " . $overlay_icon_image_for_CSS[2] . "px";
                        }
                        $overlay_CSS .= "@media only screen and (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx), (min-resolution: 124dpi){\r\n\t\t\t\t\t\t\t\t\t\t\t\t#jig{$jig_id} .jig-overlay-icon {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbackground: url(" . $overlay_icon_retina_for_CSS . ") no-repeat center center;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-webkit-background-size:" . $ov_icon_px . ";\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-moz-background-size:" . $ov_icon_px . ";\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-o-background-size:" . $ov_icon_px . ";\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t \t\tbackground-size:" . $ov_icon_px . ";\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t}";
                    }
                }
            }
            $nextgen_bc_CSS = '';
            if ($ng_breadcrumb == 'yes') {
                $nextgen_bc_CSS = '.jig-ngBreadcrumb {
							' . $this->settings['nextgen_breadcrumb_css'] . '
						}';
            }
            $fb_bc_CSS = '';
            if (isset($fb_bc_CSS_needed)) {
                $fb_bc_CSS = '.jig-fbBreadcrumb {
							' . $this->settings['fb_breadcrumb_css'] . '
						}';
            }
            $flickr_bc_CSS = '';
            if (isset($flickr_bc_CSS_needed)) {
                $flickr_bc_CSS = '.jig-flickrBreadcrumb {
							' . $this->settings['flickr_breadcrumb_css'] . '
						}';
            }
            $carousel_extra_CSS = '';
            if ($lightbox == 'carousel') {
                $carousel_extra_CSS = '.jp-carousel-comment-post-success{
					width:auto !important;
				}';
            }
            $load_more_CSS_actual = '';
            if ($load_more !== 'off') {
                $load_more_CSS_actual = "#jig{$jig_id} .jig-loadMoreButton{" . ($wrap_text == "no" ? '' : "\r\n\t\t\t\t\tfloat:left;\r\n\t\t\t\t\tmargin-right: " . $thumbs_spacing * 2 . "px !important;") . "\r\n\t\t\t\t\t" . $this->settings['load_more_css'] . "\r\n\t\t\t\t}\r\n\t\t\t\t#jig{$jig_id} .jig-loadMoreButton:hover{\r\n\t\t\t\t\t" . $this->settings['load_more_hover_css'] . "\r\n\t\t\t\t}";
            }
            $caption_CSS = $image_container_additional_CSS = '';
            if ($loading_background !== '') {
                $image_container_additional_CSS = "background: {$loading_background};";
            }
            if ($caption != 'off') {
                $caption_appearance_CSS = $caption_desc_appearance_CSS = $caption_title_additional_CSS = $caption_desc_additional_CSS = '';
                if ($caption == 'slide' || $caption == 'fade') {
                    $caption_appearance_CSS = 'display:none;';
                }
                if ($caption == 'below') {
                    $caption_match_width = 'no';
                    $v_center_captions = 'off';
                }
                if ($gradient_caption_bg == 'yes') {
                    $caption_match_width = 'no';
                    $caption_opacity = 1;
                }
                if ($caption == 'mixed') {
                    $caption_desc_appearance_CSS = "#jig{$jig_id} .jig-caption-description-wrapper {display:none;}";
                }
                if ($caption_title_size) {
                    $caption_title_additional_CSS .= 'font-size: ' . $caption_title_size . ' !important;';
                }
                if ($caption_desc_size) {
                    $caption_desc_additional_CSS .= 'font-size: ' . $caption_desc_size . ' !important;';
                }
                if ($v_center_captions == 'yes' || $v_center_captions == 'simple') {
                    $caption_appearance_CSS .= 'text-align: center !important;';
                    $caption_title_additional_CSS .= 'text-align: center !important;';
                    $caption_desc_additional_CSS .= 'text-align: center !important;';
                    $caption_align = 'center';
                    //if($caption_match_width == 'yes-rounded') $caption_match_width = 'yes';
                } else {
                    if ($caption_align !== 'css') {
                        $caption_appearance_CSS .= 'text-align: ' . $caption_align . ' !important;';
                        $caption_title_additional_CSS .= 'text-align: ' . $caption_align . ' !important;';
                        $caption_desc_additional_CSS .= 'text-align: ' . $caption_align . ' !important;';
                    }
                }
                if ($caption_match_width == 'no') {
                    $caption_title_additional_CSS .= "padding:5px 0 5px;";
                    $caption_desc_additional_CSS .= "padding-bottom: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tmargin-top: -3px;";
                } else {
                    $caption_title_additional_CSS .= "padding: 5px 7px 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tvertical-align:bottom;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbackground: {$caption_bg_color};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tdisplay:inline-block;";
                    if ($caption_match_width == 'yes-rounded') {
                        switch ($caption_align) {
                            case 'center':
                                $caption_title_additional_CSS .= "-webkit-border-top-left-radius: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-webkit-border-top-right-radius: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-moz-border-radius-topleft: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-moz-border-radius-topright: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-top-left-radius: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-top-right-radius: 5px;";
                                break;
                            case 'right':
                                $caption_title_additional_CSS .= "-webkit-border-top-left-radius: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-moz-border-radius-topleft: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-top-left-radius: 5px;";
                                break;
                            case 'left':
                            default:
                                $caption_title_additional_CSS .= "-webkit-border-top-right-radius: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-moz-border-radius-topright: 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tborder-top-right-radius: 5px;";
                                break;
                        }
                        /*   IE glitch (all versions) */
                        $caption_title_additional_CSS .= "margin-bottom: -1px;";
                    }
                    $caption_desc_additional_CSS .= "padding: 3px 7px 5px;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tbackground: {$caption_bg_color};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tdisplay:block;";
                }
                if ($caption_match_width == 'no' && $caption !== 'below') {
                    if ($gradient_caption_bg == 'no') {
                        $caption_appearance_CSS .= "background: {$caption_bg_color};";
                    }
                    $caption_appearance_CSS .= "padding:0 7px;";
                } else {
                    if ($caption !== 'below') {
                        $caption_appearance_CSS .= "padding:0;";
                    } else {
                        if ($caption_bg_color == 'transparent' || $caption_bg_color == 'none') {
                            switch ($caption_align) {
                                case 'center':
                                    $caption_appearance_CSS .= "padding:0 7px;";
                                    break;
                                case 'right':
                                    $caption_appearance_CSS .= "padding:0 0 0 7px;";
                                    break;
                                case 'left':
                                default:
                                    $caption_appearance_CSS .= "padding:0 7px 0 0;";
                                    break;
                            }
                        } else {
                            $caption_appearance_CSS .= "padding:0 7px;";
                        }
                    }
                }
                if ($gradient_caption_bg == 'yes') {
                    $caption_appearance_CSS .= $this->settings['gradient_caption_bg_css'];
                }
                if ($caption_opacity == 1 && $caption_text_shadow != '') {
                    $caption_appearance_CSS .= "text-shadow: {$caption_text_shadow};";
                }
                if ($specialfx == 'captions' && $caption_opacity == 1 && strpos($caption_bg_color, 'rgba') === false && $caption_bg_color !== 'transparent' && $gradient_caption_bg == 'no') {
                    // If the caption background is not translucent in any way, there is no point to use special effects
                    $specialfx = 'off';
                }
                $caption_CSS = "#jig{$jig_id} .jig-caption-wrapper {\r\n\t\t\t\t\t\t\tmax-height:100%;\r\n\t\t\t\t\t\t\tbottom: 0;\r\n\t\t\t\t\t\t\tright: 0;\r\n\t\t\t\t\t\t\tleft: 0;" . ($caption !== 'below' ? 'position: absolute;' : "height:{$caption_height}px;background: {$caption_bg_color};") . "\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tmargin:0 auto;\r\n\t\t\t\t\t\t\tpadding:0;\r\n\t\t\t\t\t\t\tz-index:100;\r\n\t\t\t\t\t\t\toverflow:hidden;\r\n\t\t\t\t\t\t\topacity: {$caption_opacity};\r\n\t\t\t\t\t\t\t-moz-opacity: {$caption_opacity};\r\n\t\t\t\t\t\t\tfilter:alpha(opacity=" . $caption_opacity * 100 . ");\r\n\t\t\t\t\t\t\t{$caption_wrapper_additional_css}\r\n\t\t\t\t\t\t}" . ($specialfx == 'captions' && $overlay !== 'off' && $caption_fx_visibility == 'in_front_of_overlay' ? '' : "#jig{$jig_id} .jig-cw-role-effect {\r\n\t\t\t\t\t\t\tz-index: 0;\r\n\t\t\t\t\t\t}") . ($specialfx == 'captions' ? "#jig{$jig_id} .jig-cw-role-effect{\r\n\t\t\t\t\t\t\topacity: {$specialfx_blend};\r\n\t\t\t\t\t\t\t-moz-opacity: {$specialfx_blend};\r\n\t\t\t\t\t\t\tfilter:alpha(opacity=" . $specialfx_blend * 100 . ");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-cw-role-effect .jig-caption{\r\n\t\t\t\t\t\t\tbackground: transparent;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-cw-role-effect .jig-caption-title,\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-cw-role-effect .jig-caption-description{\r\n\t\t\t\t\t\t\tcolor: transparent !important;\r\n\t\t\t\t\t\t\tbackground: transparent;\r\n\t\t\t\t\t\t}" : "") . "\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-caption {\r\n\t\t\t\t\t\t\t{$caption_appearance_CSS}\r\n\t\t\t\t\t\t\tmargin: 0;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-caption-title {\r\n\t\t\t\t\t\t\toverflow: hidden;\r\n\t\t\t\t\t\t\tline-height: normal;\r\n\t\t\t\t\t\t\tbox-sizing: content-box !important;\r\n\t\t\t\t\t\t\tcolor:{$caption_text_color} !important;\r\n\t\t\t\t\t\t\t" . $this->settings['caption_title_css'] . "\r\n\t\t\t\t\t\t\t{$caption_title_additional_CSS}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t{$caption_desc_appearance_CSS}\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-caption-description {\r\n\t\t\t\t\t\t\toverflow: hidden;\r\n\t\t\t\t\t\t\tline-height: normal;\r\n\t\t\t\t\t\t\tcolor:{$caption_text_color} !important;\r\n\t\t\t\t\t\t\t" . $this->settings['caption_desc_css'] . "\r\n\t\t\t\t\t\t\t{$caption_desc_additional_CSS}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\t\t#jig{$jig_id} .jig-alone{\r\n\t\t\t\t\t\t\tpadding-top:5px !important;\r\n\t\t\t\t\t\t\tmargin-top: 0 !important;\r\n\t\t\t\t\t\t}";
            }
            $instance_css = "#jig{$jig_id} {\r\n\t\t\t\t\t\t\t\tmargin:{$margin};\r\n\t\t\t\t\t\t\t\tmin-height:{$min_height}px;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t#jig{$jig_id} .jig-imageContainer {\r\n\t\t\t\t\t\t\t\tmargin-bottom: {$thumbs_spacing}px;\r\n\t\t\t\t\t\t\t\t" . ($reading_direction == "ltr" ? "\r\n\t\t\t\t\t\t\t\tmargin-right: {$thumbs_spacing}px;\r\n\t\t\t\t\t\t\t\tfloat: left;" : "\r\n\t\t\t\t\t\t\t\tmargin-left: {$thumbs_spacing}px;\r\n\t\t\t\t\t\t\t\tfloat: right;") . "\r\n\t\t\t\t\t\t\t\tpadding: 0;\r\n\t\t\t\t\t\t\t\twidth: auto;\r\n\t\t\t\t\t\t\t\t{$outer_border_CSS}\r\n\t\t\t\t\t\t\t\t{$middle_border_color_CSS}\r\n\t\t\t\t\t\t\t\t{$outer_shadow_CSS}\r\n\t\t\t\t\t\t\t\t{$image_container_additional_CSS}\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t#jig{$jig_id} .jig-imageContainer img {\r\n\t\t\t\t\t\t\t\tmax-width: none !important;\r\n\t\t\t\t\t\t\t\t" . ($allow_transp_pngs !== 'yes' ? "background-color: white !important;" : '') . ($specialfx !== 'off' ? "image-rendering:optimizeQuality;" : '') . "\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t#jig{$jig_id} .jig-overflow {\r\n\t\t\t\t\t\t\t\tposition: relative; \r\n\t\t\t\t\t\t\t\toverflow:hidden;\r\n\t\t\t\t\t\t\t\tvertical-align:baseline;\r\n\t\t\t\t\t\t\t\t{$middle_border_width_CSS}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t{$caption_CSS}\r\n\t\t\t\t\t\t\t{$overlay_CSS}\r\n\t\t\t\t\t\t\t{$nextgen_bc_CSS}\r\n\t\t\t\t\t\t\t{$fb_bc_CSS}\r\n\t\t\t\t\t\t\t{$flickr_bc_CSS}\r\n\t\t\t\t\t\t\t{$inner_border_CSS}\r\n\t\t\t\t\t\t\t{$load_more_CSS_actual}\r\n\t\t\t\t\t\t\t{$carousel_extra_CSS}\r\n\t\t\t\t\t\t\t#jig{$jig_id} .jig-clearfix:after { clear: " . ($wrap_text == "no" ? "both" : "none") . "; }\r\n\t\t\t\t\t\t\t.jig-last {" . ($reading_direction == "ltr" ? "\r\n\t\t\t\t\t\t\t\tmargin-right: 0 !important;" : "\r\n\t\t\t\t\t\t\t\tmargin-left: 0 !important;") . "\r\n\t\t\t\t\t\t\t}";
            if ($last_row == 'center' || $last_row == 'flexible-center' || $last_row == 'flexible-match-center' || $last_row == 'match-center') {
                if ($developer_link == 'show') {
                    $instance_css .= "#jig{$jig_id}-developerLink{text-align:center;}";
                }
                if (!empty($gallery_truncated_with_message)) {
                    $instance_css .= "#jig{$jig_id}-viewRestOfGallery{text-align:center;}";
                }
            }
            if ($this->settings['conditional_script_loading'] == 'yes') {
                if ($this->settings['jquery'] !== 'legacy') {
                    if ($this->settings['jquery_location'] == 'footer') {
                        wp_enqueue_script('jquery');
                    }
                } else {
                    wp_register_script('jig-jq', plugins_url('js/jquery-1.8.3.min.js', __FILE__), array(), '1.8.3', true);
                    wp_enqueue_script('jig-jq');
                }
            }
            // create a hidden container
            // data-lazy-src prevents lazyload, apparently!
            $noscript_output = '<noscript id="jig' . $jig_id . '-html" class="justified-image-grid-html" data-lazy-src="skiplazyload" data-src="skipunveillazyload"><ul>';
            $rss_output = '';
            $site_host = explode('/', str_replace(array('http://', 'https://'), '', site_url()));
            // calculate timthumb path, take CDN into account
            $timthumb_calculated_path = plugins_url('timthumb.php', __FILE__);
            if ($timthumb_path) {
                $timthumb_calculated_path = $timthumb_path;
            } else {
                if ($this->settings['cdn_host'] !== '') {
                    $timthumb_calculated_path = str_replace($site_host[0], $this->settings['cdn_host'], $timthumb_calculated_path);
                }
            }
            if ($aspect_ratio) {
                if (strrpos($aspect_ratio, ':') !== false) {
                    $aspect_ratio_numbers = explode(':', $aspect_ratio);
                    $aspect_ratio = (double) $aspect_ratio_numbers[0] / (double) $aspect_ratio_numbers[1];
                } elseif (strrpos($aspect_ratio, '/') !== false) {
                    $aspect_ratio_numbers = explode('/', $aspect_ratio);
                    $aspect_ratio = (double) $aspect_ratio_numbers[0] / (double) $aspect_ratio_numbers[1];
                }
                if (is_numeric($aspect_ratio)) {
                    $aspect_ratio = round($aspect_ratio, 4);
                    $max_width = round($max_height * $aspect_ratio);
                } else {
                    $aspect_ratio = '';
                }
            }
            if ($instagram_tag_filter !== '') {
                $instagram_tag_filter_exploded = explode(',', str_replace(array(', ', '#'), array(',', ''), strtolower($instagram_tag_filter)));
                $instagram_tag_filter_count = count($instagram_tag_filter_exploded);
            }
            if ($orderby == 'rand') {
                // Necessary to circumvent object caching
                shuffle($this->images);
            }
            // Post processing all images data
            foreach ($this->images as $image_index => &$image_element) {
                // Instagram tag filter feature
                if ($gallery_type == 'instagram' && $instagram_tag_filter !== '') {
                    $matched_a_filter_in_image = false;
                    $matches_count_for_instagram_filter = 0;
                    // Only if the image has tags (filters)
                    if (isset($image_element['filters'])) {
                        foreach ($image_element['filters'] as $filter) {
                            if (in_array($filter[0], $instagram_tag_filter_exploded)) {
                                if ($instagram_tag_mode == 'or') {
                                    $matched_a_filter_in_image = true;
                                    break;
                                } else {
                                    // If all filters must be found in the image tags, don't stop searching
                                    $matches_count_for_instagram_filter += 1;
                                }
                            }
                        }
                        unset($filter);
                    }
                    if ($matches_count_for_instagram_filter == $instagram_tag_filter_count) {
                        $matched_a_filter_in_image = true;
                    }
                    if ($matched_a_filter_in_image === false) {
                        unset($this->images[$image_index]);
                        continue;
                    }
                    if ($filterby == 'off') {
                        unset($this->images[$image_index]['filters']);
                    }
                }
                if ($lightbox == 'photoswipe') {
                    $image_element['wh'] = $image_element['width'] . 'x' . $image_element['height'];
                }
                $image_element['width'] = $image_element['width'] / $image_element['height'] * $max_height;
                unset($this->images[$image_index]['height']);
                if (!$photon_activated) {
                    $image_element['width'] = floor($image_element['width']);
                    // Calculate new width of TimThumb
                } else {
                    $image_element['width'] = round($image_element['width']);
                    // Calculate new width of Photon
                }
                // ? + in the filename drives timthumb crazy and convert backslashes, remove doubleslashes
                $image_element['unencoded_url'] = $image_element['url'] = str_replace(array('\\', '+'), array('/', '%2B'), $image_element['url']);
                if (!empty($image_element['thumbUrl'])) {
                    //$image_element['thumbUrl'] = preg_replace('%(?<!:)/{2,}%m', '/', str_replace(array('\\','+','&','?'),array('/','%2B','%26','%3F'),$image_element['thumbUrl']));
                    $image_element['thumbUrl'] = urlencode(preg_replace('%(?<!:)/{2,}%m', '/', str_replace('\\', '/', $image_element['thumbUrl'])));
                    $image_element['url'] = preg_replace('%(?<!:)/{2,}%m', '/', $image_element['url']);
                } else {
                    //$image_element['url'] = preg_replace('%(?<!:)/{2,}%m', '/', str_replace(array('\\','+','&'),array('/','%2B','%26'),$image_element['url']));
                    $image_element['url'] = urlencode(preg_replace('%(?<!:)/{2,}%m', '/', $image_element['url']));
                }
                // This can allow animated gifs by not modifying the aspect ratio or width, just relays the img src as is
                if (!($allow_animated_gifs === 'yes' && stripos($image_element['unencoded_url'], '.gif') !== false || $use_timthumb == 'no')) {
                    if ($aspect_ratio) {
                        $image_element['width'] = $max_width;
                    }
                    if ($randomize_width > 0) {
                        $randomize_width_only_this = $randomize_width;
                        if ($image_element['width'] - $randomize_width / 2 < $image_element['width'] / 2) {
                            $randomize_width_only_this = $image_element['width'] / 2;
                        }
                        mt_srand(intval(substr(base_convert(md5($image_element['unencoded_url'] . $max_height), 16, 10), -8), 10));
                        $randomize_width_only_this /= 2;
                        $image_element_original_width = $image_element['width'];
                        $image_element['width'] -= mt_rand(-$randomize_width_only_this, $randomize_width_only_this);
                    }
                } else {
                    $image_element['photon'] = $image_element['unencoded_url'];
                    $skip_photon_for_animated_gif = true;
                }
                if (!empty($link_override)) {
                    $image_element['link'] = $link_override;
                }
                // Disregard custom links
                if ($link_target == 'off' && !($gallery_type == 'facebook' && $image_element['link_target'] == 'video')) {
                    unset($image_element['link'], $image_element['link_target']);
                } elseif (!empty($image_element['link_target']) && !empty($image_element['link'])) {
                    // If there are links on the images
                    if ($image_element['link_target'] == 'videoplayer') {
                        // If it's specifically the videoplayer mode
                        if ($lightbox !== 'prettyphoto' || $lightbox == 'prettyphoto' && $this->settings['prettyphoto_deeplinking'] !== 'advanced_deeplinking' && $this->settings['prettyphoto_deeplinking'] !== 'smart_deeplinking') {
                            // Create the video player URL with the video file and its cover photo as parameters
                            $image_element['link'] = home_url('/') . '?' . $this->settings['video_slug'] . '=' . $image_element['link'] . ($this->settings['video_poster'] == 'yes' ? '&poster=' . $image_element['url'] : '');
                            if ($lightbox == 'photoswipe' || $lightbox == 'photoswipe3' || $lightbox == 'colorbox' || $lightbox == 'carousel' || $lightbox == 'socialgallery') {
                                // These lightboxes don't support iframe so skip them
                                $image_element['link_target'] = '_blank';
                            } elseif ($lightbox == 'prettyphoto') {
                                // If there is just simple prettyPhoto deeplinking there is no worry about the long or ugly URL, so just add the suffix
                                $image_element['link'] .= '?iframe=true';
                            }
                        } else {
                            // In advanced deeplinking the source URL is visible in the address bar so make it a bit shorter.
                            $image_element['link'] .= str_replace('&', '|', ($this->settings['video_poster'] == 'yes' ? '&poster=' . $image_element['url'] : '') . '&videoplayer');
                            // Will pass the video player URL to prettyPhoto as a setting
                            $prettyphoto_videoplayer_url = true;
                        }
                    } elseif ($image_element['link_target'] == 'video') {
                        if ((strpos($image_element['link'], 'youtube.com/') !== false || strpos($image_element['link'], 'youtu.be/') !== false || strpos($image_element['link'], 'vimeo.com/') !== false) && ($lightbox == 'photoswipe' || $lightbox == 'photoswipe3' || $lightbox == 'colorbox' || $lightbox == 'carousel' || $lightbox == 'socialgallery')) {
                            // These lightboxes don't support videos so skip them
                            $image_element['link_target'] = '_blank';
                        }
                    }
                    if (($lightbox == 'foobox' || $lightbox == 'magnific') && ($image_element['link_target'] == 'video' || $image_element['link_target'] == 'videoplayer')) {
                        if ($image_element['link_target'] == 'video' && preg_match('%https?://[^/\\s]+/\\S+\\.(jpe?g|png|[tg]iff?|svg|bmp|webp)%m', $image_element['link'])) {
                            // It's an image and shouldn't open in an iframe of FooBox, just normally!
                            $image_element['thumbUrl'] = $image_element['url'];
                            $image_element['url'] = $image_element['link'];
                            $image_element['unencoded_url'] = $image_element['link'];
                            $image_element['link'] = $image_element['link_target'] = null;
                            unset($image_element['link'], $image_element['link_target']);
                        } elseif ($lightbox == 'foobox') {
                            // It's needed by FooBox to act on iframes and videos
                            $image_element['link_target'] = 'foobox';
                        }
                    }
                }
                // Process shortcodes
                if ($process_shortcodes === 'yes') {
                    if (isset($image_element['title'])) {
                        $image_element['title'] = esc_attr(do_shortcode($image_element['title']));
                    }
                    if (isset($image_element['caption'])) {
                        $image_element['caption'] = esc_attr(do_shortcode($image_element['caption']));
                    }
                    if (isset($image_element['description'])) {
                        $image_element['description'] = esc_attr(do_shortcode($image_element['description']));
                    }
                    if (isset($image_element['alternate'])) {
                        $image_element['alternate'] = esc_attr(do_shortcode($image_element['alternate']));
                    }
                }
                if ($for_xml_sitemap === 'yes') {
                    $sitemap_images[$image_index] = $image_element;
                }
                // rewrite URL to photon URL
                if ($photon_activated && empty($skip_photon_for_animated_gif)) {
                    $photon_url = jetpack_photon_url($image_element['unencoded_url']);
                    $photon_url = str_replace(' ', '+', $photon_url);
                    // still serve the normal sized images from the social pages' CDNs
                    if ($gallery_type == 'wp_post_gallery' || $gallery_type == 'wp_recent_posts' || $gallery_type == 'nextgen') {
                        $image_element['url'] = $photon_url;
                    }
                    if (strpos($photon_url, '?') === false) {
                        $image_element['photon'] = $photon_url . '?h=' . $max_height;
                        if ($aspect_ratio || $randomize_width > 0) {
                            $image_element['photon'] = $photon_url . '?resize=' . $image_element['width'] . ',' . $max_height;
                        }
                    } else {
                        $image_element['photon'] = substr($photon_url, 0, strpos($photon_url, '?')) . '?h=' . $max_height;
                        if ($aspect_ratio || $randomize_width > 0) {
                            $image_element['photon'] = substr($photon_url, 0, strpos($photon_url, '?')) . '?resize=' . $image_element['width'] . ',' . $max_height;
                        }
                    }
                    unset($photon_url);
                    // or rewrite to CDN url
                } elseif ($this->settings['cdn_host'] !== '' && $gallery_type !== 'flickr' && $gallery_type !== 'facebook' && $gallery_type !== 'rss' && ($gallery_type !== 'wp_recent_posts' || $gallery_type == 'wp_recent_posts' && $recents_link_to == 'image')) {
                    $image_element['url'] = str_replace($site_host[0], $this->settings['cdn_host'], $image_element['url']);
                    $image_element['unencoded_url'] = str_replace($site_host[0], $this->settings['cdn_host'], $image_element['unencoded_url']);
                    if ($this->settings['cdn_custom_links'] == 'yes' && !empty($image_element['link'])) {
                        $image_element['link'] = str_replace($site_host[0], $this->settings['cdn_host'], $image_element['link']);
                    }
                    if ($for_xml_sitemap === 'yes') {
                        $sitemap_images[$image_index] = $image_element;
                    }
                }
                // make images findable by google
                if (!empty($image_element[$link_title_field])) {
                    $title_fragment = $image_element[$link_title_field];
                } else {
                    if (preg_match('%(?<=/)(\\w*)(?=\\.[:\\w]{2,5}(?:$|\\?|#|&))%m', $image_element['unencoded_url'], $regs)) {
                        $title_fragment = $regs[0];
                    } else {
                        $title_fragment = '';
                    }
                }
                $alt_fragment = isset($image_element[$img_alt_field]) ? $image_element[$img_alt_field] : $title_fragment;
                if (!empty($title_fragment)) {
                    $title_fragment_full = ' title="' . $title_fragment . '"';
                } else {
                    $title_fragment_full = '';
                }
                if (!isset($image_element['photon'])) {
                    $image_src = !isset($image_element['thumbUrl']) ? $image_element['url'] : $image_element['thumbUrl'];
                    $ext = '';
                    if ($this->settings['thumbnail_filename'] == 'normal' && preg_match('/.*\\.(jpe?g|gif|bmp|png|webp)/im', $image_src, $regs)) {
                        $ext = "&f=." . $regs[1];
                    }
                    if (!$aspect_ratio) {
                        $image_src = $timthumb_calculated_path . "?src=" . $image_src . "&h=" . $max_height . "&q=" . $quality . $ext;
                    } else {
                        $image_src = $timthumb_calculated_path . "?src=" . $image_src . "&h=" . $max_height . "&w=" . $image_element['width'] . "&q=" . $quality . $ext;
                    }
                } else {
                    $image_src = $image_element['photon'];
                }
                $rel_fragments = array();
                if (isset($image_element['link_target']) && $image_element['link_target'] == '_blank') {
                    $rel_fragments[] = 'external';
                }
                if (isset($image_element['link']) && isset($image_element['link_target']) && $custom_link_follow === 'no' && $image_element['link_target'] == '_blank') {
                    $rel_fragments[] = 'nofollow';
                }
                if (empty($rel_fragments)) {
                    $rel_fragment = '';
                } else {
                    $rel_fragment = ' rel="' . implode(' ', $rel_fragments) . '"';
                }
                $description_text = ($alt_fragment !== $title_fragment ? $alt_fragment . '<br/>' : '') . $title_fragment;
                if (!empty($description_text)) {
                    $description_text = '<p class="jig-HTMLdescription">' . html_entity_decode($description_text) . '</p>';
                }
                $noscript_output .= '<li><a href="' . (!isset($image_element['link']) ? $image_element['unencoded_url'] : $image_element['link']) . '"' . $title_fragment_full . $rel_fragment . '><img ' . $this->class_for_noscript_img . 'src="' . str_replace('&', '&amp;', $image_src) . '" alt="' . $alt_fragment . '" width="' . (!isset($image_element_original_width) ? $image_element['width'] : $image_element_original_width) . '" height="' . $max_height . '" /></a>' . $description_text . '</li>';
                if ($this->settings['show_up_in_feeds'] == 'yes' && is_feed()) {
                    $image_rss_src = !isset($image_element['thumbUrl']) ? $image_element['url'] : $image_element['thumbUrl'];
                    if ($photon_activated && empty($skip_photon_for_animated_gif)) {
                        if (strpos($image_element['photon'], '?') !== false) {
                            $image_rss_src = substr($image_element['photon'], 0, strpos($image_element['photon'], '?')) . '?resize=150,150';
                        } else {
                            $image_rss_src = $image_element['photon'] . '?resize=150,150';
                        }
                    } else {
                        if ($use_timthumb == 'yes') {
                            $ext = '';
                            if ($this->settings['thumbnail_filename'] == 'normal' && preg_match('/.*\\.(jpe?g|gif|bmp|png|webp)/im', $image_rss_src, $regs)) {
                                $ext = "&f=." . $regs[1];
                            }
                            $image_rss_src = $timthumb_calculated_path . "?src=" . $image_rss_src . "&h=150&w=150&q=" . $quality . "&jigrss=yes" . $ext;
                            $rss_output .= '<img src="' . str_replace('&', '&amp;', $image_rss_src) . '" width="150" height="150" /> ';
                        } else {
                            $image_rss_src = !isset($image_element['thumbUrl']) ? $image_element['unencoded_url'] : $image_element['thumbUrl'];
                        }
                    }
                    $rss_output .= '<img src="' . str_replace('&', '&amp;', $image_rss_src) . '" width="150" /> ';
                    // Height will be automatic
                }
                unset($image_element['unencoded_url']);
                // not needed for JS!
                unset($image_element_original_width);
                // Filtering features
                if ($filterby !== 'off') {
                    if (!empty($image_element['filters'])) {
                        foreach ($image_element['filters'] as &$filter) {
                            // only adds unique tags to the filters for JS
                            if (strpos($filter[0], '%') !== false) {
                                $filter[0] = md5($filter[0]);
                            } elseif (is_numeric($filter[0])) {
                                $filter[0] = '_' . $filter[0];
                            }
                            $filters_for_JS[$filter[0]] = $filter[1];
                            if (!empty($filters_for_JS_counter[$filter[0]])) {
                                $filters_for_JS_counter[$filter[0]]++;
                            } else {
                                $filters_for_JS_counter[$filter[0]] = 1;
                            }
                        }
                        unset($filter);
                    }
                }
                if ($l2_filterby !== 'off') {
                    if (!empty($image_element['L2filters'])) {
                        foreach ($image_element['L2filters'] as &$filter) {
                            // only adds unique tags to the l2_filters for JS
                            if (strpos($filter[0], '%') !== false) {
                                $filter[0] = md5($filter[0]);
                            } elseif (is_numeric($filter[0])) {
                                $filter[0] = '_' . $filter[0];
                            }
                            $l2_filters_for_JS[$filter[0]] = $filter[1];
                            if (!empty($l2_filters_for_JS_counter[$filter[0]])) {
                                $l2_filters_for_JS_counter[$filter[0]]++;
                            } else {
                                $l2_filters_for_JS_counter[$filter[0]] = 1;
                            }
                        }
                        unset($filter);
                    }
                }
                if (empty($image_element['width'])) {
                    unset($this->images[$image_index]);
                }
            }
            if (!empty($prettyphoto_videoplayer_url)) {
                $prettyphoto_videoplayer_url = home_url('/') . '?' . $this->settings['video_slug'] . '=';
            }
            // end of 'post processing'
            // Level 1 filtering (original concept)
            if ($filterby !== 'off' && !empty($filters_for_JS)) {
                if ($filter_orderby == 'custom' && empty($filter_custom_order)) {
                    $filter_orderby = 'appearance';
                }
                $filters_for_JS = (array) $filters_for_JS;
                if ($filter_orderby == 'popularity' || $filter_top_x !== '' || $filter_min_count) {
                    natcasesort($filters_for_JS_counter);
                    $filters_for_JS_counter = array_reverse($filters_for_JS_counter, true);
                    // Preserve numerical keys like years
                }
                $filters_for_JS_custom = array();
                switch ($filter_orderby) {
                    case 'title_asc':
                        natcasesort($filters_for_JS);
                        break;
                    case 'title_desc':
                        natcasesort($filters_for_JS);
                        $filters_for_JS = array_reverse($filters_for_JS, true);
                        // Preserve numerical keys like years
                        break;
                    case 'random':
                        $filters_for_JS = $this->shuffle_assoc($filters_for_JS);
                        break;
                    case 'custom':
                        $filter_custom_order = explode(',', $filter_custom_order);
                        $filters_for_JS_custom_key = '';
                        foreach ($filter_custom_order as $filter_name) {
                            $filter_name = trim($filter_name);
                            if (strpos($filter_name, '&') !== false && strpos($filter_name, '&amp;') === false) {
                                $filter_name = str_replace('&', '&amp;', $filter_name);
                            }
                            $filters_for_JS_custom_key = array_search($filter_name, $filters_for_JS);
                            if ($filters_for_JS_custom_key !== false) {
                                $filters_for_JS_custom[$filters_for_JS_custom_key] = $filter_name;
                            }
                        }
                        $filters_for_JS = $filters_for_JS_custom;
                        break;
                    case 'popularity':
                        // Order by the number of images with that tag
                        foreach ($filters_for_JS_counter as $filter_slug => $image_count_for_filter) {
                            $filters_for_JS_custom[$filter_slug] = $filters_for_JS[$filter_slug];
                        }
                        unset($filter_slug, $image_count_for_filter);
                        $filters_for_JS = $filters_for_JS_custom;
                        break;
                    case 'appearance':
                    default:
                        break;
                }
                if ($filter_top_x !== '') {
                    $filters_for_JS_custom = array_slice($filters_for_JS_counter, 0, (int) $filter_top_x);
                    $filters_for_JS = array_intersect_key($filters_for_JS, $filters_for_JS_custom);
                }
                if ($filter_min_count) {
                    $filters_for_JS_custom = array();
                    foreach ($filters_for_JS as $filter_slug => $filter_value) {
                        if ($filters_for_JS_counter[$filter_slug] >= $filter_min_count) {
                            $filters_for_JS_custom[$filter_slug] = $filters_for_JS[$filter_slug];
                        }
                    }
                    unset($filter_slug, $image_count_for_filter);
                    $filters_for_JS = $filters_for_JS_custom;
                }
                if ($filter_all_button == 'yes') {
                    $filters_for_JS['all-items-nofilter'] = __($filter_all_text, 'jig_td');
                }
            }
            // Level 2 filtering (shameless copy paste)
            if ($l2_filterby !== 'off' && !empty($l2_filters_for_JS)) {
                if ($l2_filter_orderby == 'custom' && empty($l2_filter_custom_order)) {
                    $l2_filter_orderby = 'appearance';
                }
                $l2_filters_for_JS = (array) $l2_filters_for_JS;
                if ($l2_filter_orderby == 'popularity' || $l2_filter_top_x !== '' || $l2_filter_min_count) {
                    natcasesort($l2_filters_for_JS_counter);
                    $l2_filters_for_JS_counter = array_reverse($l2_filters_for_JS_counter, true);
                    // Preserve numerical keys like years
                }
                $l2_filters_for_JS_custom = array();
                switch ($l2_filter_orderby) {
                    case 'title_asc':
                        natcasesort($l2_filters_for_JS);
                        break;
                    case 'title_desc':
                        natcasesort($l2_filters_for_JS);
                        $l2_filters_for_JS = array_reverse($l2_filters_for_JS, true);
                        // Preserve numerical keys like years
                        break;
                    case 'random':
                        $l2_filters_for_JS = $this->shuffle_assoc($l2_filters_for_JS);
                        break;
                    case 'custom':
                        $l2_filter_custom_order = explode(',', $l2_filter_custom_order);
                        $l2_filters_for_JS_custom_key = '';
                        foreach ($l2_filter_custom_order as $filter_name) {
                            $filter_name = trim($filter_name);
                            if (strpos($filter_name, '&') !== false && strpos($filter_name, '&amp;') === false) {
                                $filter_name = str_replace('&', '&amp;', $filter_name);
                            }
                            $l2_filters_for_JS_custom_key = array_search($filter_name, $l2_filters_for_JS);
                            if ($l2_filters_for_JS_custom_key !== false) {
                                $l2_filters_for_JS_custom[$l2_filters_for_JS_custom_key] = $filter_name;
                            }
                        }
                        $l2_filters_for_JS = $l2_filters_for_JS_custom;
                        break;
                    case 'popularity':
                        // Order by the number of images with that tag
                        foreach ($l2_filters_for_JS_counter as $filter_slug => $image_count_for_filter) {
                            $l2_filters_for_JS_custom[$filter_slug] = $l2_filters_for_JS[$filter_slug];
                        }
                        unset($filter_slug, $image_count_for_filter);
                        $l2_filters_for_JS = $l2_filters_for_JS_custom;
                        break;
                    case 'appearance':
                    default:
                        break;
                }
                if ($l2_filter_top_x !== '') {
                    $l2_filters_for_JS_custom = array_slice($l2_filters_for_JS_counter, 0, (int) $l2_filter_top_x);
                    $l2_filters_for_JS = array_intersect_key($l2_filters_for_JS, $l2_filters_for_JS_custom);
                }
                if ($l2_filter_min_count) {
                    $l2_filters_for_JS_custom = array();
                    foreach ($l2_filters_for_JS as $l2_filter_slug => $l2_filter_value) {
                        if ($l2_filters_for_JS_counter[$l2_filter_slug] >= $l2_filter_min_count) {
                            $l2_filters_for_JS_custom[$l2_filter_slug] = $l2_filters_for_JS[$l2_filter_slug];
                        }
                    }
                    unset($l2_filter_slug, $image_count_for_filter);
                    $l2_filters_for_JS = $l2_filters_for_JS_custom;
                }
                if ($l2_filter_all_button == 'yes') {
                    $l2_filters_for_JS['all-items-nofilter'] = __($l2_filter_all_text, 'jig_td');
                }
            }
            if (empty($this->images)) {
                //needs to be checked again
                return $this->frontend_stop(__('Justified Image Grid error: there are no images to show, the "items" are empty.', 'jig_td'));
            }
            if ($for_xml_sitemap === 'yes') {
                global $jig_images_for_xml_sitemap;
                if (empty($sitemap_images)) {
                    $jig_images_for_xml_sitemap = array_merge($jig_images_for_xml_sitemap, $this->images);
                } else {
                    $jig_images_for_xml_sitemap = array_merge($jig_images_for_xml_sitemap, $sitemap_images);
                }
                return $this->frontend_stop();
            }
            if ($this->settings['show_up_in_feeds'] == 'yes' && is_feed()) {
                return $this->frontend_stop($rss_output, false);
            }
            $noscript_output .= '</ul></noscript>';
            $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){return};";
            $lightbox_class = $lightbox_narrow = '';
            if ($ng_lightbox_gallery == 'yes' && isset($shadow_gallery)) {
                $lightbox_class = '';
                $lightbox_narrow = '.jig-imageContainer ';
            }
            $output = '';
            switch ($lightbox) {
                case 'prettyphoto':
                    if (!defined('JIG_SKIP_PRETTYPHOTO')) {
                        global $jig_prettyphoto_activation_needed;
                        $jig_prettyphoto_activation_needed = true;
                        if ($this->settings['conditional_script_loading'] == 'yes' && $load_bundled_lightbox == 'yes') {
                            wp_register_script('jig-prettyphoto', plugins_url('js/jquery.prettyphoto.custom-min.js', __FILE__), 'jquery', '3.1.6.' . self::PLUGIN_VERSION, true);
                            wp_enqueue_script('jig-prettyphoto');
                            wp_register_style('jig-prettyphoto-style', plugins_url('css/prettyphoto.css', __FILE__), false, '3.1.6.' . self::PLUGIN_VERSION);
                            wp_enqueue_style('jig-prettyphoto-style');
                        }
                    }
                    switch ($this->settings['prettyphoto_deeplinking']) {
                        case 'smart_deeplinking':
                            $prettyphoto_deeplinking_fragment = "\tsmart_deeplinking: true,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tadvanced_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdeeplinking:true,";
                            break;
                        case 'advanced_deeplinking':
                            $prettyphoto_deeplinking_fragment = "\tsmart_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tadvanced_deeplinking: true,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdeeplinking:true,";
                            break;
                        case 'deeplinking':
                            $prettyphoto_deeplinking_fragment = "\tsmart_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tadvanced_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdeeplinking:true,";
                            break;
                        default:
                            $prettyphoto_deeplinking_fragment = "\tsmart_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tadvanced_deeplinking: false,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdeeplinking:false,";
                            break;
                    }
                    $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){\r\n\t\t\t\t\t\t\t\t\t\tif(typeof \$.prettyPhoto === 'undefined'\r\n\t\t\t\t\t\t\t\t\t\t\t&& typeof loadJustifiedImageGrid !== 'undefined'\r\n\t\t\t\t\t\t\t\t\t\t\t&& typeof loadJIGprettyPhoto !== 'undefined'){\r\n\t\t\t\t\t\t\t\t\t\t\tloadJIGprettyPhoto(\$);\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\$('#jig{$jig_id} {$lightbox_narrow}a.jig-link').prettyPhoto({\r\n\t\t\t\t\t\t\t\t\t\t\tjig_call: true," . ($pp_social_buttons !== 'FTPG' ? '
											jig_socials: "' . $pp_social_buttons . '",' : '') . ($prettyphoto_social == 'no' ? '
											social_tools: false,' : '') . ($prettyphoto_analytics == 'yes' ? '
											analytics: true,' : '') . ($prettyphoto_title_pos == 'outside' ? '
											title_position: "outside",' : '') . (!empty($prettyphoto_videoplayer_url) ? '
											videoplayer: "' . $prettyphoto_videoplayer_url . '",' : '') . $prettyphoto_deeplinking_fragment . '
											theme: "' . $prettyphoto_theme . '",
											' . $this->settings['prettyphoto_settings'] . "\r\n\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\t};";
                    break;
                case 'colorbox':
                    if ($this->settings['conditional_script_loading'] == 'yes' && $load_bundled_lightbox == 'yes') {
                        wp_deregister_script('colorbox');
                        wp_register_script('colorbox', plugins_url('js/jquery.colorbox-min.js', __FILE__), 'jquery', '1.6.3', true);
                        wp_enqueue_script('colorbox');
                        wp_register_style('colorbox-style', plugins_url('css/colorbox' . $this->settings['colorbox_design'] . '.css', __FILE__), false, '1.6.3');
                        wp_enqueue_style('colorbox-style');
                    }
                    $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\$('#jig{$jig_id} {$lightbox_narrow}a.jig-link').colorbox({\r\n\t\t\t\t\t\t\t\t\t\t\t" . $this->settings['colorbox_settings'] . "\r\n\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\t};";
                    break;
                case 'magnific':
                    if ($this->settings['conditional_script_loading'] == 'yes' && $load_bundled_lightbox == 'yes') {
                        wp_deregister_script('magnific-popup');
                        wp_register_script('magnific-popup', plugins_url('js/jquery.magnific-popup.min.js', __FILE__), 'jquery', '1.0.0', true);
                        wp_enqueue_script('magnific-popup');
                        wp_register_style('magnific-popup-style', plugins_url('css/magnific-popup.css', __FILE__), false, '1.0.0');
                        wp_enqueue_style('magnific-popup-style');
                    }
                    $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){";
                    // Magnific needs different treatment for multiple galleries
                    if (empty($shadow_galleries)) {
                        $lightbox_JS .= "\$('#jig{$jig_id} a.jig-link')";
                    } else {
                        $lightbox_JS .= "\$('#jig{$jig_id} .jig-imageContainer').each(function() { \$(this).find('a')";
                    }
                    $lightbox_JS .= ".magnificPopup({\r\n\t\t\t\t\t\t\t\t\t\t\ttype: 'image',\r\n\t\t\t\t\t\t\t\t\t\t\tgallery: {\r\n\t\t\t\t\t\t\t\t\t\t\t\tenabled:true,\r\n\t\t\t\t\t\t\t\t\t\t\t\ttCounter:\t'%curr% / %total%',\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\r\n\t\t\t\t\t\t\t\t\t\t\timage: {\r\n\t\t\t\t\t\t\t\t\t\t\t\ttitleSrc: function(item) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar title = item.el.find('img').attr('alt');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(typeof title === 'undefined') title = '';\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar description = item.el.attr('title');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescription = typeof description !== 'undefined' ? '<small>' + description + '</small>' : '';\r\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn title + description;\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\r\n\t\t\t\t\t\t\t\t\t\t\tiframe: {\r\n\t\t\t\t\t\t\t\t\t\t\t\tmarkup: '<div class=\"mfp-iframe-scaler\"><div class=\"mfp-close\"></div><iframe class=\"mfp-iframe\" frameborder=\"0\" allowfullscreen></iframe><div class=\"mfp-bottom-bar\"><div class=\"mfp-title\"></div><div class=\"mfp-counter\"></div></div></div>',\r\n\t\t\t\t\t\t\t\t\t\t\t  patterns: {\r\n\t\t\t\t\t\t\t\t\t\t\t    youtube: {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tid: function(url) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar match = /^(?:https?:\\/\\/)?(?:www\\.)?(?:youtube\\.com(?:\\/embed\\/|\\/v\\/|\\/watch\\?v=|\\/watch\\?.+&v=))([\\w\\-]{9,13})(?:.+)?\$/im.exec(url);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (match != null) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn match[1];\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t} \r\n\t\t\t\t\t\t\t\t\t\t\t    },\r\n\t\t\t\t\t\t\t\t\t\t\t  },\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\tcallbacks: {\r\n\t\t\t\t\t\t\t\t\t\t\t    markupParse: function(template, values, item) {\r\n\t\t\t\t\t\t\t\t\t\t\t    \tif(item.type == 'iframe'){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar title = item.el.find('img').attr('alt');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(typeof title === 'undefined') title = '';\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar description = item.el.attr('title');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription = typeof description !== 'undefined' ? '<small>' + description + '</small>' : '';\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalues.title = title + description;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t    }\r\n\t\t\t\t\t\t\t\t\t\t\t  },\r\n\t\t\t\t\t\t\t\t\t\t\t" . ($magnific_zoom == 'yes' ? "\r\n\t\t\t\t\t\t\t\t\t\t\tmainClass: 'mfp-with-zoom',\r\n\t\t\t\t\t\t\t\t\t\t\tzoom: {\r\n\t\t\t\t\t\t\t\t\t\t\t\tenabled: true,\r\n\t\t\t\t\t\t\t\t\t\t\t\tduration: 300,\r\n\t\t\t\t\t\t\t\t\t\t\t\teasing: 'ease-in-out',\r\n\t\t\t\t\t\t\t\t\t\t\t\topener: function(openerElement) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(openerElement.parent().attr('class') !== 'jig-overflow' ){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\topenerElement.offset = function(){ return {top: \$(window).height()/2, left: \$(window).width()/2 };};\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn openerElement;\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn openerElement.find('img');\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t}," : "") . "\r\n\t\t\t\t\t\t\t\t\t\t\t" . $this->settings['magnific_settings'] . "\r\n\t\t\t\t\t\t\t\t\t\t});";
                    // Different closing of JS
                    if (empty($shadow_galleries)) {
                        $lightbox_JS .= "};";
                    } else {
                        $lightbox_JS .= "})};";
                    }
                    break;
                case 'foobox':
                    if (class_exists('fooboxV2') || class_exists('foobox')) {
                        $lightbox_class = 'jigFooBoxConnect';
                        $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){\r\n\t\t\t\t\t\t\twindow.FOOBOX.init();\r\n\t\t\t\t\t\t};";
                    }
                    break;
                case 'photoswipe':
                    if ($this->settings['conditional_script_loading'] == 'yes' && $load_bundled_lightbox == 'yes') {
                        wp_deregister_script('photoswipe');
                        wp_register_script('photoswipe', plugins_url('js/photoswipe4-min.js', __FILE__), 'jquery', '4.1.0', true);
                        wp_enqueue_script('photoswipe');
                        wp_register_style('photoswipe-style', plugins_url('css/photoswipe4.css', __FILE__), 'jquery', '4.1.0');
                        wp_enqueue_style('photoswipe-style');
                    }
                    // if button is shareEl disabled but then enabled specifically
                    if ($photoswipe_social == 'yes' && (stripos($this->settings['photoswipe4_settings'], 'shareEl: false') !== false || stripos($this->settings['photoswipe4_settings'], 'shareEl:false') !== false)) {
                        $this->settings['photoswipe4_settings'] = str_replace(array('shareEl: false', 'shareEl:false'), 'shareEl: true', $this->settings['photoswipe4_settings']);
                    }
                    //if button is shareEl true, but disabled in the setting, change it in the shareEl
                    if ($photoswipe_social == 'no' || $photoswipe_social == 'inherit' && $prettyphoto_social == 'no' || empty($ps_social_buttons)) {
                        if (stripos($this->settings['photoswipe4_settings'], 'shareEl: true') !== false || stripos($this->settings['photoswipe4_settings'], 'shareEl:true') !== false) {
                            $this->settings['photoswipe4_settings'] = str_replace(array('shareEl: true', 'shareEl:true'), 'shareEl: false', $this->settings['photoswipe4_settings']);
                        }
                        if (stripos($this->settings['photoswipe4_settings'], 'shareEl') === false) {
                            $photoswipe_add_sharel = true;
                        }
                    }
                    $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){";
                    $lightbox_JS .= "\$('#jig{$jig_id} {$lightbox_narrow}a.jig-link').JIGphotoSwipe({\r\n\t\t\t\t\t\t\t\t\t\t\t" . ($aspect_ratio ? 'aspectRatioMismatch: true, ' : '') . ($this->settings['photoswipe_caption_align'] != 'center' ? 'captionAlign: "' . $this->settings['photoswipe_caption_align'] . '", ' : '') . ($this->settings['photoswipe_deeplinking'] == 'auto' && $this->settings['prettyphoto_deeplinking'] != 'smart_deeplinking' || $this->settings['photoswipe_deeplinking'] == 'no' ? 'history:false,' : '') . ($download_link == 'no' ? '' : 'allowDownload: true, ') . (empty($photoswipe_add_sharel) ? '' : 'shareEl: false, ') . ($ps_social_buttons !== 'FTPG' ? '
											socialButtons: "' . $ps_social_buttons . '",' : '') . $this->settings['photoswipe4_settings'] . "\r\n\t\t\t\t\t\t\t\t\t\t});";
                    $lightbox_JS .= "};";
                    break;
                case 'photoswipe3':
                    if ($this->settings['conditional_script_loading'] == 'yes' && $load_bundled_lightbox == 'yes') {
                        wp_deregister_script('klass');
                        wp_register_script("klass", plugins_url('js/klass.min.js', __FILE__), 'jquery', '1.0', true);
                        wp_enqueue_script("klass");
                        wp_deregister_script('photoswipe3');
                        wp_register_script('photoswipe3', plugins_url('js/code.photoswipe.jquery-3.0.5.min.js', __FILE__), 'jquery', '3.0.5', true);
                        wp_enqueue_script('photoswipe3');
                        wp_register_style('photoswipe3-style', plugins_url('css/photoswipe3.css', __FILE__), false, '3.0.5');
                        wp_enqueue_style('photoswipe3-style');
                    }
                    $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){";
                    // This fakes 1 ID-less shadow gallery when no shadow galleries are present
                    if (empty($shadow_galleries)) {
                        $shadow_galleries[] = '';
                    }
                    foreach ($shadow_galleries as $gallery_id) {
                        $gallery_id_numeric = '_' . substr($gallery_id, strrpos($gallery_id, '-') + 1);
                        if ($gallery_id !== '') {
                            $gallery_id = '#' . $gallery_id . ' ';
                        }
                        $lightbox_JS .= "if(\$('#jig{$jig_id} {$gallery_id}a.jig-link').length !== 0){\r\n\t\t\t\t\t\t\t\t\t\t\tif(typeof(JIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric}) != 'undefined' && JIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric} !== null) {\r\n\t\t\t\t\t\t\t\t\t\t\t\twindow.Code.PhotoSwipe.unsetActivateInstance(JIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric});\r\n\t\t\t\t\t\t\t\t\t\t\t\twindow.Code.PhotoSwipe.detatch(JIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric}); \r\n\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\tJIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric} = \$('#jig{$jig_id} {$gallery_id}a.jig-link').photoSwipe({\r\n\t\t\t\t\t\t\t\t\t\t\t\t" . $this->settings['photoswipe_settings'] . "\r\n\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\t\t\tJIGPhotoSwipeResized = false;\r\n\r\n\t\t\t\t\t\t\t\t\t\t\tJIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric}.addEventHandler(window.Code.PhotoSwipe.EventTypes.onHide, function(e){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').each(function( index ) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$(this).data('justifiedImageGrid').createGallery('resize');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').css('pointer-events','none');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar reenablePointerEvents = window.setTimeout(function(){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').css('pointer-events','auto');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t}, 200);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tJIGPhotoSwipeResized = true;\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\t\t\t\tJIGPhotoSwipeInstance{$jig_id}{$gallery_id_numeric}.addEventHandler(window.Code.PhotoSwipe.EventTypes.onToolbarTap, function(e){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(e.toolbarAction === 'close'){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(JIGPhotoSwipeResized == false){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').each(function( index ) {\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$(this).data('justifiedImageGrid').createGallery('resize');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').css('pointer-events','none');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar reenablePointerEvents = window.setTimeout(function(){\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$('.justified-image-grid').css('pointer-events','auto');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}, 200);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\t";
                    }
                    $lightbox_JS .= "};";
                    break;
                case 'socialgallery':
                    $lightbox_class = 'jigSgConnect';
                    break;
                case 'carousel':
                    $lightbox_class = 'tiled-gallery gallery-caption';
                    remove_all_filters('post_gallery', 1500);
                    $Jetpack_Carousel = new Jetpack_Carousel();
                    add_filter('post_gallery', array($Jetpack_Carousel, 'enqueue_assets'), 1600, 2);
                    apply_filters('post_gallery', '', $atts, $justified_image_grid_instance);
                    break;
                case 'custom':
                    if ($this->settings['custom_lightbox_js'] !== '$(JIG_selector).exampleLightbox();') {
                        $lightbox_JS = "window['jigAddLightbox{$jig_id}'] = function(){\r\n\t\t\t\t\t\t\t" . str_replace('JIG_selector', "'#jig{$jig_id} {$lightbox_narrow}a.jig-link'", $this->settings['custom_lightbox_js']) . "\r\n\t\t\t\t\t\t};";
                    }
                    break;
            }
            // Lightbox class is set up for each shadow gallery instead
            if (!empty($shadow_gallery)) {
                $lightbox_class = '';
            }
            if ($notice_before !== '') {
                $output .= $notice_before;
            }
            if (!$carousel_activated) {
                $output .= '<div id="jig' . $jig_id . '" class="justified-image-grid jig-' . hash('md5', serialize($atts)) . ' jig-preset-' . (empty($preset) ? 'global' : $preset) . ($lightbox_class == '' ? '' : ' ' . $lightbox_class) . '"><div class="jig-clearfix"></div>' . $noscript_output . '</div>';
            } else {
                if (empty($Jetpack_Carousel)) {
                    $Jetpack_Carousel = new Jetpack_Carousel();
                }
                $output .= $Jetpack_Carousel->add_data_to_container('<div id="jig' . $jig_id . '" class="justified-image-grid jig-' . hash('md5', serialize($atts)) . ($lightbox_class == '' ? '' : ' ' . $lightbox_class) . '">');
                $output .= '<div class="jig-clearfix"></div></div>';
            }
            if ($notice_after !== '') {
                $output .= $notice_after;
            }
            if ($developer_link == 'show') {
                $output .= '<div id="jig' . $jig_id . '-developerLink" class="jig-developerLink"><a href="http://codecanyon.net/item/justified-image-grid-premium-wordpress-gallery/2594251' . ($this->settings['envato_user'] != '' ? '?ref=' . $this->settings['envato_user'] : '') . '" target="_blank" title="Justified Image Grid - Premium WordPress Gallery">' . __($developer_link_text, 'jig_td') . '</a></div>';
            }
            $mouse_JS = '';
            if ($mouse_disable == 'yes') {
                $mouse_JS = "\$('#jig{$jig_id}').on('contextmenu', function(e){\r\n\t\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\$(document).on('click', \$('#jig{$jig_id}'), function(event){\r\n\t\t\t\t\t\t\t\tif(event.which === 2){\r\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t});";
                switch ($lightbox) {
                    case 'prettyphoto':
                        $mouse_JS .= '$("body").on("contextmenu", "#pp_full_res", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    case 'photoswipe':
                        $mouse_JS .= '$("body").on("contextmenu", ".pswp", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    case 'colorbox':
                        $mouse_JS .= '$("body").on("contextmenu", "#colorbox", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    case 'foobox':
                        $mouse_JS .= '$("body").on("contextmenu", ".foobox-modal", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    case 'magnific':
                        $mouse_JS .= '$("body").on("contextmenu", ".mfp-img", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    case 'carousel':
                        $mouse_JS .= '$("body").on("contextmenu", ".jp-carousel-slide.selected", function(e){
													e.preventDefault();
													return false;
												});';
                        break;
                    default:
                        break;
                }
            }
            // legacy desaturation setting support
            if ($desaturate !== '') {
                $specialfx = $desaturate;
                $specialfx_type = 'desaturate';
            }
            // remove desaturation if the thumbs are from another host as pixastic is not compatible with that
            if ($this->settings['cdn_host'] !== '' || $photon_activated) {
                $specialfx = 'off';
            }
            // A new object that'll hold all the settings, eventually will get passed to JS as JSON
            $this->JS_settings = array();
            // These settings have no defaults in the jQuery plugin
            $this->JS_settings['timthumb'] = $timthumb_calculated_path;
            $this->JS_settings['items'] = array_values((array) $this->images);
            // These settings have thes defaults in the jQuery plugin and only need to be included in the calling script, if they differ
            if ($row_height != 190) {
                $this->JS_settings['targetHeight'] = (int) $row_height;
            }
            if ($height_deviation != 40) {
                $this->JS_settings['heightDeviation'] = (int) $height_deviation;
            }
            if ($aspect_ratio) {
                $this->JS_settings['aspectRatio'] = $aspect_ratio;
            }
            if ($disable_cropping !== 'no') {
                $this->JS_settings['disableCropping'] = $disable_cropping;
            }
            if ($randomize_width) {
                $this->JS_settings['randomizeWidth'] = $randomize_width;
            }
            if ($thumbs_spacing != 4) {
                $this->JS_settings['margins'] = (int) $thumbs_spacing;
            }
            if ($animation_speed != 300) {
                $this->JS_settings['animSpeed'] = (int) $animation_speed;
            }
            if ($max_rows) {
                $this->JS_settings['maxRows'] = (int) $max_rows;
            }
            if ($link_class) {
                $this->JS_settings['linkClass'] = $link_class;
            }
            if ($link_rel !== 'jig[*instance*]') {
                $this->JS_settings['linkRel'] = $link_rel;
            }
            if ($link_attribute_name !== '') {
                $this->JS_settings['linkAttributeName'] = $link_attribute_name;
            }
            if ($link_attribute_value !== '') {
                $this->JS_settings['linkAttributeValue'] = $link_attribute_value;
            }
            if ($link_title_field !== 'description') {
                $this->JS_settings['linkTitleField'] = $link_title_field;
            }
            if ($img_alt_field !== 'title') {
                $this->JS_settings['imgAltField'] = $img_alt_field;
            }
            if ($wrap_text !== 'no') {
                $this->JS_settings['wrapText'] = $wrap_text;
            }
            if ($reading_direction !== 'ltr') {
                $this->JS_settings['readingDirection'] = $reading_direction;
            }
            if ($retina_ready !== 'yes') {
                $this->JS_settings['retinaReady'] = $retina_ready;
            }
            if ($quality != 90) {
                $this->JS_settings['quality'] = (int) $quality;
            }
            if ($retina_quality !== 'auto') {
                $this->JS_settings['retinaQuality'] = (int) $retina_quality;
            }
            if ($min_retina_quality != 30) {
                $this->JS_settings['minRetinaQuality'] = (int) $min_retina_quality;
            }
            if ($max_retina_density != 3) {
                $this->JS_settings['maxRetinaDensity'] = (int) $max_retina_density;
            }
            if ($download_link !== 'no') {
                $this->JS_settings['downloadLink'] = $download_link;
            }
            if ($caption !== 'fade') {
                $this->JS_settings['caption'] = $caption;
            }
            if ($caption_match_width !== 'no') {
                $this->JS_settings['captionMatchWidth'] = $caption_match_width;
            }
            if ($title_field !== 'title') {
                $this->JS_settings['titleField'] = $title_field;
            }
            if ($caption_field !== 'description') {
                $this->JS_settings['captionField'] = $caption_field;
            }
            if ($disable_hover !== 'no') {
                $this->JS_settings['disableHover'] = $disable_hover;
            }
            if ($lightbox !== 'prettyphoto') {
                $this->JS_settings['lightbox'] = $lightbox;
            }
            if ($overlay !== 'hovered') {
                $this->JS_settings['overlay'] = $overlay;
            }
            if ($overlay_icon !== 'off') {
                $this->JS_settings['overlayIcon'] = $overlay_icon;
            }
            if ($borders_total !== 0) {
                $this->JS_settings['bordersTotal'] = (int) $borders_total;
            }
            if ($specialfx !== 'off') {
                $this->JS_settings['specialFx'] = $specialfx;
            }
            if ($specialfx_type !== 'desaturate') {
                $this->JS_settings['specialFxType'] = $specialfx_type;
            }
            if ($specialfx_blend != 1) {
                $this->JS_settings['specialFxBlend'] = $specialfx_blend;
            }
            if ($specialfx_options !== '') {
                $this->JS_settings['specialFxOptions'] = explode(',', $specialfx_options);
            }
            if ($last_row !== 'normal') {
                $this->JS_settings['incompleteLastRow'] = $last_row;
            }
            if ($error_checking !== 'yes') {
                $this->JS_settings['errorChecking'] = $error_checking;
            }
            if ($separator_character !== ' - ') {
                $this->JS_settings['separatorCharacter'] = $separator_character;
            }
            if ($timthumb_crop_zone !== 'c') {
                $this->JS_settings['cropZone'] = '&a=' . $timthumb_crop_zone;
            }
            if ($this->settings['thumbnail_filename'] !== 'normal') {
                $this->JS_settings['thumbnailFilename'] = $this->settings['thumbnail_filename'];
            }
            // These have more complicated logic
            if ($jig_id !== 1) {
                $this->JS_settings['instance'] = $jig_id;
                $this->JS_settings['lightboxInit'] = 'jigAddLightbox' . $jig_id;
            }
            if ($load_more !== 'off') {
                $this->JS_settings['limit'] = (int) $load_more_limit;
                $this->JS_settings['loadMore'] = $load_more;
                if (__($load_more_text, 'jig_td') !== 'Load more') {
                    $this->JS_settings['loadMoreText'] = __($load_more_text, 'jig_td');
                }
                if (__($load_more_count_text, 'jig_td') !== '(*count* images remaining)') {
                    $this->JS_settings['loadMoreCountText'] = __($load_more_count_text, 'jig_td');
                }
                if ($load_more_offset !== 100) {
                    $this->JS_settings['loadMoreOffset'] = $load_more_offset;
                }
                if ($load_more_auto_width !== 'on') {
                    $this->JS_settings['loadMoreAutoWidth'] = $load_more_auto_width;
                }
            } elseif ($hidden_limit) {
                if ($real_limit) {
                    $this->JS_settings['limit'] = (int) $real_limit;
                } else {
                    $this->JS_settings['limit'] = 0;
                }
            }
            if ($custom_width) {
                if ($width_mode == 'responsive_fallback') {
                    $this->JS_settings['fallbackWidth'] = (int) $custom_width;
                } elseif ($width_mode == 'fixed' || $width_mode == 'fixed-mobile' && $detect->isMobile() || $width_mode == 'fixed-desktop' && !$detect->isMobile()) {
                    $this->JS_settings['fixedWidth'] = (int) $custom_width;
                }
            }
            if ($caption !== 'off') {
                if ($v_center_captions !== 'off') {
                    $this->JS_settings['verticalCenterCaptions'] = $v_center_captions;
                }
                if ($custom_fonts !== 'yes') {
                    $this->JS_settings['customFonts'] = $custom_fonts;
                }
            }
            if ($caption == 'below' && $caption_height != 54) {
                $this->JS_settings['captionHeight'] = (int) $caption_height;
            }
            if ($flickr_link !== 'no' && $gallery_type == 'flickr') {
                $this->JS_settings['lightboxLink'] = $flickr_link;
            } elseif ($instagram_link !== 'no' && $gallery_type == 'instagram') {
                $this->JS_settings['lightboxLink'] = $instagram_link;
            } elseif ($rss_link !== 'no' && $gallery_type == 'rss') {
                $this->JS_settings['lightboxLink'] = $rss_link;
            } elseif ($recents_link !== 'no' && $gallery_type == 'wp_recent_posts') {
                $this->JS_settings['lightboxLink'] = $recents_link;
            }
            if ($middle_border !== 'always') {
                $this->JS_settings['middleBorder'] = $middle_border;
                if ($middle_border_color !== 'white') {
                    $this->JS_settings['middleBorderColor'] = $middle_border_color;
                }
                if ($middle_border_width !== 0) {
                    $this->JS_settings['middleBorderWidth'] = (int) $middle_border_width;
                }
            }
            if ($inner_border !== 'always') {
                $this->JS_settings['innerBorder'] = $inner_border;
                if ($inner_border_animate !== 'width') {
                    $this->JS_settings['innerBorderAnimate'] = $inner_border_animate;
                }
            }
            if ($outer_border !== 'always') {
                $this->JS_settings['outerBorder'] = $outer_border;
                if ($outer_border_color !== 'black') {
                    $this->JS_settings['outerBorderColor'] = $outer_border_color;
                }
            }
            if ($inner_border_width !== 0) {
                $this->JS_settings['innerBorderWidth'] = (int) $inner_border_width;
            }
            if (!empty($filters_for_JS)) {
                $this->JS_settings['filters'] = $filters_for_JS;
                if ($filter_multiple !== 'no') {
                    $this->JS_settings['filterMultiple'] = $filter_multiple;
                }
                if ($filter_style !== 'buttons') {
                    $this->JS_settings['filterStyle'] = $filter_style;
                }
            }
            if (!empty($l2_filters_for_JS)) {
                $this->JS_settings['L2filters'] = $l2_filters_for_JS;
                if ($l2_filter_multiple !== 'no') {
                    $this->JS_settings['L2filterMultiple'] = $l2_filter_multiple;
                }
                if ($l2_filter_style !== 'buttons') {
                    $this->JS_settings['L2filterStyle'] = $l2_filter_style;
                }
            }
            if (!empty($filters_for_JS) || !empty($l2_filters_for_JS)) {
                if ($this->settings['filter_smallest_color'] !== '#A3A3A3') {
                    $this->JS_settings['filterSmallestColor'] = $this->settings['filter_smallest_color'];
                }
                if ($this->settings['filter_smallest_size'] != '11') {
                    $this->JS_settings['filterSmallestSize'] = (int) $this->settings['filter_smallest_size'];
                }
                if ($this->settings['filter_largest_color'] !== '#000000') {
                    $this->JS_settings['filterLargestColor'] = $this->settings['filter_largest_color'];
                }
                if ($this->settings['filter_largest_size'] != '22') {
                    $this->JS_settings['filterLargestSize'] = (int) $this->settings['filter_largest_size'];
                }
            }
            // convert all settings for JS to JSON
            $JS_settings_JSON = json_encode($this->JS_settings);
            $instance_js = "{$lightbox_JS}\r\n\t\t\t\t\t\t\t\$('#jig{$jig_id}').justifiedImageGrid({$JS_settings_JSON});\r\n\t\t\t\t\t\t\t{$mouse_JS}";
            global $justified_image_grid_js, $justified_image_grid_css, $justified_image_grid_ie_css, $justified_image_grid_filtering_css_needed, $jig_prettyphoto_activation_needed;
            $justified_image_grid_js .= $instance_js;
            $justified_image_grid_css .= $instance_css;
            $justified_image_grid_ie_css .= ($this->settings['center_filter_buttons'] == 'yes' ? ".jig-filterButton{display:inline !important;}" : "") . ($this->settings['center_tag_cloud'] == 'yes' ? ".jig-filterTag{display:inline !important;}" : "") . $this->jig_rgbaIE($caption_bg_color, $jig_id, $caption_match_width, $gradient_caption_bg);
            if (isset($jig_prettyphoto_activation_needed)) {
                $js_print = "if(typeof \$.prettyPhoto.JIG === 'undefined'\r\n\t\t\t\t\t\t\t\t&& typeof loadJustifiedImageGrid !== 'undefined'\r\n\t\t\t\t\t\t\t\t&& typeof loadJIGprettyPhoto !== 'undefined'){\r\n\t\t\t\t\t\t\t\tloadJIGprettyPhoto(\$);\r\n\t\t\t\t\t\t\t}" . $justified_image_grid_js . "\r\n\t\t\t\t\t\t\tif(typeof jigOtherPrettyPhotoIsPresent !== 'undefined'){\r\n\t\t\t\t\t\t\t\t\$(document).ready(function(){\r\n\t\t\t\t\t\t\t\t\tsetTimeout(function(){\r\n\t\t\t\t\t\t\t\t\t\t\$(window).trigger('jigPrettyPhotoActivation');\r\n\t\t\t\t\t\t\t\t\t}, 50);\r\n\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t}else{\r\n\t\t\t\t\t\t\t\t\$(window).trigger('jigPrettyPhotoActivation');\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}";
            } else {
                $js_print = $justified_image_grid_js . "}";
            }
            $css_print = '	.justified-image-grid {
								max-width: none !important;
								padding:0;
								clear:both;
								line-height: normal;
								display: block !important;
							}
							.jig-hiddenGallery{
								display:none !important;
							}
							.justified-image-grid .jig-imageContainer img,
							.justified-image-grid .jig-pixastic {
								position:absolute;
								top:0;
								left:0;
								margin: 0;
								padding: 0;
								border-style: none !important;
								vertical-align: baseline;
								max-width: none !important;
								max-height: none !important;
								min-height: 0 !important;
								min-width: 0 !important;
								box-shadow: none !important;
								z-index: auto !important;
								visibility: visible !important;
							}
							.justified-image-grid .jig-imageContainer a {
								margin: 0 !important;
								padding: 0 !important;
								position: static !important;
								display: inline;
							}
							.justified-image-grid div {
								position: static;
							}
							.justified-image-grid a:link,
							.justified-image-grid a:hover,
							.justified-image-grid a:visited {
								text-decoration:none;
							}
							.justified-image-grid .jig-removeThis {
								visibility:hidden;
							}
							.justified-image-grid .jig-hiddenLink,
							.justified-image-grid .jig-hiddenImg{
								display:none !important;
							}
							.jig-last:after {
								clear:both;
							}
							.justified-image-grid .tiled-gallery-caption{
								display: none !important;
							}
							.jig-developerLink{
								line-height: 10px;
								margin-bottom: 5px;
							}
							.jig-developerLink a{
								font-size: 9px;
							}
							.jig-fontCheck{
								display: block !important;
								position: absolute !important;
								left: -99999px !important;
								top: -99999px !important;
								visibility: hidden !important;
								font-size: 100px !important;
								white-space: nowrap !important;
								max-width: none !important;
								width: auto !important;
							}
							.justified-image-grid-html li {
								float:left;
								position: relative;
								list-style:none;
								overflow:hidden;
							}
							.justified-image-grid-html .jig-HTMLdescription{
								position: absolute;
								bottom: 0;
								left: 0;
								right: 0;
								background-color: rgba(0,0,0,0.5);
								color: white;
								margin: 0;
								padding: 5px;
							}
							.justified-image-grid > p, .justified-image-grid > li {
							    display: none;
							}
							noscript.justified-image-grid-html p{
								display:block;
							}
							noscript.justified-image-grid-html li {
							    display: list-item;
							}
							.justified-image-grid-html li
							.jig-clearfix:before,
							.jig-clearfix:after,
							.justified-image-grid-html:before,
							.justified-image-grid-html:after {
							    content: "";
							    display: table;
							}
							.jig-clearfix:after,
							.justified-image-grid-html:after {
							    clear: both;
							}
							.jig-clearfix,
							.justified-image-grid-html {
								-webkit-backface-visibility: visible;
							    zoom: 1; /*   For IE 6/7 (trigger hasLayout) */
							}' . (isset($justified_image_grid_filtering_css_needed) ? "\r\n\t\t\t\t\t\t\t.jig-filterButtons,\r\n\t\t\t\t\t\t\t.jig-filterTags{\r\n\t\t\t\t\t\t\t\tclear:both;\r\n\t\t\t\t\t\t\t\tmargin-bottom: 10px;\r\n\t\t\t\t\t\t\t\t-webkit-touch-callout: none;\r\n\t\t\t\t\t\t\t\t-webkit-user-select: none;\r\n\t\t\t\t\t\t\t\t-khtml-user-select: none;\r\n\t\t\t\t\t\t\t\t-moz-user-select: none;\r\n\t\t\t\t\t\t\t\t-ms-user-select: none;\r\n\t\t\t\t\t\t\t\tuser-select: none;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t.jig-filterButton{\r\n\t\t\t\t\t\t\t\tdisplay:inline-block;\r\n\t\t\t\t\t\t\t\tcursor:pointer;\r\n\t\t\t\t\t\t\t\t" . $this->settings['filter_button_css'] . "\r\n\t\t\t\t\t\t\t\tfloat:none;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t.jig-filterTag{\r\n\t\t\t\t\t\t\t\tdisplay:inline-block;\r\n\t\t\t\t\t\t\t\tvertical-align: baseline;\r\n\t\t\t\t\t\t\t\tcursor:pointer;\r\n\t\t\t\t\t\t\t\t" . $this->settings['filter_tag_css'] . "\r\n\t\t\t\t\t\t\t\tline-height: 1.2;\r\n\t\t\t\t\t\t\t}" . ($this->settings['center_filter_buttons'] == 'yes' ? "\r\n\t\t\t\t\t\t\t.jig-filterButtons {\r\n\t\t\t\t\t\t\t\ttext-align: center;\r\n\t\t\t\t\t\t\t}" : "") . ($this->settings['center_tag_cloud'] == 'yes' ? "\r\n\t\t\t\t\t\t\t.jig-filterTags {\r\n\t\t\t\t\t\t\t\ttext-align: center;\r\n\t\t\t\t\t\t\t}" : "") . "\r\n\t\t\t\t\t\t\t.jig-filterButton.jig-filterButtonSelected:hover,\r\n\t\t\t\t\t\t\t.jig-filterTag.jig-filterTagSelected:hover{\r\n\t\t\t\t\t\t\t\tcursor:default;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t.jig-filterButton:hover,\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t.jig-filterButton.jig-filterButtonSelected:hover,\r\n\t\t\t\t\t\t\t.jig-filterButton.jig-filterButtonSelected{\r\n\t\t\t\t\t\t\t\t" . $this->settings['filter_button_hover_css'] . "\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t.jig-filterTag:hover,\r\n\t\t\t\t\t\t\t.jig-filterTag.jig-filterTagSelected:hover,\r\n\t\t\t\t\t\t\t.jig-filterTag.jig-filterTagSelected{\r\n\t\t\t\t\t\t\t\t" . $this->settings['filter_tag_hover_css'] . "\r\n\t\t\t\t\t\t\t}" : "") . $justified_image_grid_css . $this->settings['custom_CSS'];
            $this->dynamic_script = "<script type='text/javascript'>\r\n" . $this->slib_compress_script('
							(function initJIG ($,ready) {
								if(typeof $.justifiedImageGrid !== "undefined"){
									' . $js_print . '
								}else if(typeof $.justifiedImageGrid === "undefined" && ready == true){
									if(typeof loadJustifiedImageGrid !== "undefined"){
										loadJustifiedImageGrid($);
										initJIG($,true);
										return;
									}
									$(".justified-image-grid").html("<span style=\\"color:red;font-weight:bold\\">' . __('The Justified Image Grid JS is not loaded. Try disabling Conditional script loading in the General settings.', 'jig_td') . '</span>");
								}else{
									$(document).ready(function(){
										initJIG($,true);
									});
								}
						 	})(jQuery,false);') . $this->settings['custom_JS'] . "\r\n</script>\r\n";
            $this->dynamic_style = "<style type='text/css'>\r\n" . str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $css_print) . "\r\n</style>\r\n" . ($justified_image_grid_ie_css ? "<!--[if IE]><style type='text/css'>" . str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $justified_image_grid_ie_css . '.jig-caption-wrapper-clone {filter: alpha(opacity=0) !important;}') . '</style><![endif]-->' : '') . "<!--[if lt IE 8]><style type='text/css'>.justified-image-grid .jig-overlay, .justified-image-grid .jig-overlay-icon-wrapper, .justified-image-grid .jig-overlay-icon {position:absolute;top:0;right:0;bottom:0;left:0;} .justified-image-grid .jig-overflow, .jig-overflow div {cursor: pointer;} .jig-caption-wrapper{margin:0 !important;} </style><![endif]-->\r\n";
            if ($this->settings['conditional_script_loading'] == 'yes') {
                add_action('wp_print_footer_scripts', array($this, 'jig_print_style'), 100);
                add_action('wp_print_footer_scripts', array($this, 'jig_print_script'), 100);
                if ($specialfx != 'off') {
                    wp_enqueue_script('pixastic.custom.jig', plugins_url('js/pixastic.custom.jig.min.js', __FILE__), 'jquery', self::PLUGIN_VERSION, true);
                }
                if ($caption == 'below') {
                    wp_enqueue_script('dotdotdot', plugins_url('js/jquery.dotdotdot.min.js', __FILE__), 'jquery', '1.7.4', true);
                }
                wp_enqueue_script('justified-image-grid', plugins_url('js/justified-image-grid-min.js', __FILE__), 'jquery', self::PLUGIN_VERSION, true);
            } else {
                $output .= $this->dynamic_script . $this->dynamic_style;
            }
            return $this->frontend_stop($output, false);
        }
Esempio n. 5
0
    function shortcode_post_cycle($atts, $content = null)
    {
        extract(shortcode_atts(array('num' => '5', 'type' => 'post', 'meta' => '', 'effect' => 'slide', 'thumb' => 'true', 'thumb_width' => '200', 'thumb_height' => '180', 'more_text_single' => theme_locals('read_more'), 'category' => '', 'custom_category' => '', 'excerpt_count' => '15', 'pagination' => 'true', 'navigation' => 'true', 'custom_class' => ''), $atts));
        $type_post = $type;
        $slider_pagination = $pagination;
        $slider_navigation = $navigation;
        $random = gener_random(10);
        $i = 0;
        $rand = rand();
        $output = '<script type="text/javascript">
						jQuery(window).load(function() {
							jQuery("#flexslider_' . $random . '").flexslider({
								animation: "' . $effect . '",
								smoothHeight : true,
								directionNav: ' . $slider_navigation . ',
								controlNav: ' . $slider_pagination . '
							});
						});';
        $output .= '</script>';
        $output .= '<div id="flexslider_' . $random . '" class="flexslider no-bg ' . $custom_class . '">';
        $output .= '<ul class="slides">';
        global $post;
        global $my_string_limit_words;
        // WPML filter
        $suppress_filters = get_option('suppress_filters');
        $args = array('post_type' => $type_post, 'category_name' => $category, $type_post . '_category' => $custom_category, 'numberposts' => $num, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => $suppress_filters);
        $latest = get_posts($args);
        foreach ($latest as $key => $post) {
            // Unset not translated posts
            if (function_exists('wpml_get_language_information')) {
                global $sitepress;
                $check = wpml_get_language_information($post->ID);
                $language_code = substr($check['locale'], 0, 2);
                if ($language_code != $sitepress->get_current_language()) {
                    unset($latest[$key]);
                }
                // Post ID is different in a second language Solution
                if (function_exists('icl_object_id')) {
                    $post = get_post(icl_object_id($post->ID, $type_post, true));
                }
            }
            setup_postdata($post);
            $excerpt = get_the_excerpt();
            $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
            $url = $attachment_url['0'];
            $image = aq_resize($url, $thumb_width, $thumb_height, true);
            $output .= '<li>';
            if ($thumb == 'true') {
                if (has_post_thumbnail($post->ID)) {
                    $output .= '<figure class="thumbnail featured-thumbnail"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                    $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                    $output .= '</a></figure>';
                } else {
                    $thumbid = 0;
                    $thumbid = get_post_thumbnail_id($post->ID);
                    $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
                    if ($images) {
                        $k = 0;
                        //looping through the images
                        foreach ($images as $attachment_id => $attachment) {
                            // $prettyType = "prettyPhoto-".$rand ."[gallery".$i."]";
                            //if( $attachment->ID == $thumbid ) continue;
                            $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                            // returns an array
                            $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true);
                            //resize & crop img
                            $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                            $image_title = $attachment->post_title;
                            if ($k == 0) {
                                $output .= '<figure class="featured-thumbnail">';
                                $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                                $output .= '<img  src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                                $output .= '</a></figure>';
                            }
                            break;
                            $k++;
                        }
                    }
                }
            }
            $output .= '<h5><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
            $output .= get_the_title($post->ID);
            $output .= '</a></h5>';
            if ($meta == 'true') {
                $output .= '<span class="meta">';
                $output .= '<span class="post-date">';
                $output .= get_the_date();
                $output .= '</span>';
                $output .= '<span class="post-comments">' . theme_locals('comments') . ": ";
                $output .= '<a href="' . get_comments_link($post->ID) . '">';
                $output .= get_comments_number($post->ID);
                $output .= '</a>';
                $output .= '</span>';
                $output .= '</span>';
            }
            //display post options
            $output .= '<div class="post_options">';
            switch ($type_post) {
                case "team":
                    $teampos = get_post_meta($post->ID, 'my_team_pos', true) ? get_post_meta($post->ID, 'my_team_pos', true) : "";
                    $teaminfo = get_post_meta($post->ID, 'my_team_info', true) ? get_post_meta($post->ID, 'my_team_info', true) : "";
                    $output .= "<span class='page-desc'>" . $teampos . "</span><br><span class='team-content post-content'>" . $teaminfo . "</span>";
                    $output .= cherry_get_post_networks(array('post_id' => $post->ID, 'display_title' => false, 'output_type' => 'return'));
                    break;
                case "testi":
                    $testiname = get_post_meta($post->ID, 'my_testi_caption', true) ? get_post_meta($post->ID, 'my_testi_caption', true) : "";
                    $testiurl = get_post_meta($post->ID, 'my_testi_url', true) ? get_post_meta($post->ID, 'my_testi_url', true) : "";
                    $testiinfo = get_post_meta($post->ID, 'my_testi_info', true) ? get_post_meta($post->ID, 'my_testi_info', true) : "";
                    $output .= "<span class='user'>" . $testiname . "</span>, <span class='info'>" . $testiinfo . "</span><br><a href='" . $testiurl . "'>" . $testiurl . "</a>";
                    break;
                case "portfolio":
                    $portfolioClient = get_post_meta($post->ID, 'tz_portfolio_client', true) ? get_post_meta($post->ID, 'tz_portfolio_client', true) : "";
                    $portfolioDate = get_post_meta($post->ID, 'tz_portfolio_date', true) ? get_post_meta($post->ID, 'tz_portfolio_date', true) : "";
                    $portfolioInfo = get_post_meta($post->ID, 'tz_portfolio_info', true) ? get_post_meta($post->ID, 'tz_portfolio_info', true) : "";
                    $portfolioURL = get_post_meta($post->ID, 'tz_portfolio_url', true) ? get_post_meta($post->ID, 'tz_portfolio_url', true) : "";
                    $output .= "<strong class='portfolio-meta-key'>" . theme_locals('client') . ": </strong><span> " . $portfolioClient . "</span><br>";
                    $output .= "<strong class='portfolio-meta-key'>" . theme_locals('date') . ": </strong><span> " . $portfolioDate . "</span><br>";
                    $output .= "<strong class='portfolio-meta-key'>" . theme_locals('info') . ": </strong><span> " . $portfolioInfo . "</span><br>";
                    $output .= "<a href='" . $portfolioURL . "'>" . theme_locals('launch_project') . "</a><br>";
                    break;
                default:
                    $output .= "";
            }
            $output .= '</div>';
            if ($excerpt_count >= 1) {
                $output .= '<p class="excerpt">';
                $output .= my_string_limit_words($excerpt, $excerpt_count);
                $output .= '</p>';
            }
            if ($more_text_single != "") {
                $output .= '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary" title="' . get_the_title($post->ID) . '">';
                $output .= $more_text_single;
                $output .= '</a>';
            }
            $output .= '</li>';
        }
        $output .= '</ul>';
        $output .= '</div>';
        return $output;
    }
Esempio n. 6
0
 private function get_product_from_post($post_id)
 {
     $woocommerce_ver_below_2_1 = false;
     if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
         $woocommerce_ver_below_2_1 = true;
     }
     if ($woocommerce_ver_below_2_1) {
         $product = new WC_Product_Simple($post_id);
     } else {
         $product = new WC_Product($post_id);
     }
     //$post_categories = wp_get_post_categories( $post_id );
     //$categories = get_the_category();
     try {
         $thumbnail = $product->get_image();
         if ($thumbnail) {
             if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                 $thumbnail = $match[1];
             } else {
                 if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
                     $thumbnail = $match[1];
                 } else {
                     if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                         // Animate Lazy Load Wordpress Plugin
                         $thumbnail = $match[1];
                     } else {
                         if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
                             $thumbnail = $match[1];
                         } else {
                             preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
                             $thumbnail = array_pop($result);
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in thumbnails";
         self::send_error_report($err_msg);
         $thumbnail = '';
     }
     // handling scheduled sale price update
     if (!$woocommerce_ver_below_2_1) {
         $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
         $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
         if ($sale_price_dates_from || $sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, null);
         }
         if ($sale_price_dates_from) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_from);
         }
         if ($sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_to);
         }
     }
     $product_tags = array();
     foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
         $product_tags[] = $tag->name;
     }
     $product_brands = array();
     if (taxonomy_exists('product_brand')) {
         foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
             $product_brands[] = $brand->name;
         }
     }
     $taxonomies = array();
     try {
         $all_taxonomies = get_option('wcis_taxonomies');
         if (is_array($all_taxonomies)) {
             foreach ($all_taxonomies as $taxonomy) {
                 if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
                     foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
                         if (!array_key_exists($taxonomy, $taxonomies)) {
                             $taxonomies[$taxonomy] = array();
                         }
                         $taxonomies[$taxonomy][] = $taxonomy_value->name;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
         $variations = $variable->get_available_variations();
         $variations_sku = '';
         if (!empty($variations)) {
             foreach ($variations as $variation) {
                 if ($product->get_sku() != $variation['sku']) {
                     $variations_sku .= $variation['sku'] . ' ';
                 }
             }
         }
         $send_product['variations_sku'] = $variations_sku;
         $all_attributes = $product->get_attributes();
         $attributes = array();
         if (!empty($all_attributes)) {
             foreach ($all_attributes as $attr_mame => $value) {
                 if ($all_attributes[$attr_mame]['is_taxonomy']) {
                     if (!$woocommerce_ver_below_2_1) {
                         $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
                     } else {
                         $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
                     }
                 } else {
                     $attributes[$attr_mame] = $product->get_attribute($attr_mame);
                 }
             }
         }
         $send_product['attributes'] = $attributes;
         $send_product['total_variable_stock'] = $variable->get_total_stock();
         try {
             if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
                 if (function_exists('wc_get_product')) {
                     $original_product = wc_get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             } else {
                 if (function_exists('get_product')) {
                     $original_product = get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             }
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in attributes";
         self::send_error_report($err_msg);
     }
     if (!$woocommerce_ver_below_2_1) {
         try {
             $send_product['price_compare_at_price'] = $product->get_regular_price();
             $send_product['price_min'] = $variable->get_variation_price('min');
             $send_product['price_max'] = $variable->get_variation_price('max');
             $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min');
             $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max');
         } catch (Exception $e) {
             $send_product['price_compare_at_price'] = null;
             $send_product['price_min'] = null;
             $send_product['price_max'] = null;
             $send_product['price_min_compare_at_price'] = null;
             $send_product['price_max_compare_at_price'] = null;
         }
     } else {
         $send_product['price_compare_at_price'] = null;
         $send_product['price_min'] = null;
         $send_product['price_max'] = null;
         $send_product['price_min_compare_at_price'] = null;
         $send_product['price_max_compare_at_price'] = null;
     }
     $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']);
     $send_product['description'] = self::content_filter_shortcode($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']);
     try {
         if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) {
             if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
                 $language_info = apply_filters('wpml_post_language_details', NULL, $post_id);
             } else {
                 $language_info = wpml_get_language_information($post_id);
             }
             if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) {
                 // WP_Error could be returned from wpml_get_language_information(...)
                 $send_product['lang'] = $language_info['locale'];
             }
         }
     } catch (Exception $e) {
     }
     return $send_product;
 }
 /**
  * For even datetime range row create custom 'fw-events-tags' post. Also save search query tags as meta values.
  *
  * @param int $post_id
  *
  * @return bool
  */
 private function _fw_insert_all_event_children_data($post_id)
 {
     $options_values = fw_get_db_post_option($post_id);
     if (is_array($options_values) === false) {
         return false;
     }
     $container_id = $this->parent->get_event_option_id();
     $meta_rows_data = fw_akg($container_id . '/event_children', $options_values);
     $all_day_event = fw_akg($container_id . '/all_day', $options_values);
     if (is_array($meta_rows_data) && count($meta_rows_data) > 0) {
         foreach ($meta_rows_data as $meta_row) {
             $start_date = fw_akg('event_date_range/from', $meta_row);
             $end_date = fw_akg('event_date_range/to', $meta_row);
             $from_timestamp = strtotime($start_date);
             $to_timestamp = strtotime($end_date);
             if (!$from_timestamp || !$to_timestamp || -1 === $from_timestamp || -1 === $to_timestamp) {
                 continue;
             }
             $terms = wp_get_post_terms($post_id, $this->parent->get_taxonomy_name(), array('fields' => 'ids'));
             $event_post_tag_id = wp_insert_post(array('post_parent' => $post_id, 'post_type' => $this->post_type, 'post_status' => 'publish', 'tax_input' => array($this->parent->get_taxonomy_name() => $terms)), true);
             if ($event_post_tag_id == 0 || $event_post_tag_id instanceof WP_Error) {
                 return false;
             }
             add_post_meta($event_post_tag_id, $this->from_date, $from_timestamp - (date('H', $from_timestamp) * 3600 + date('i', $from_timestamp) * 60));
             add_post_meta($event_post_tag_id, $this->to_date, $to_timestamp - (date('H', $to_timestamp) * 3600 + date('i', $to_timestamp) * 60));
             add_post_meta($event_post_tag_id, $this->from_time, date('H', $from_timestamp) * 3600 + date('i', $from_timestamp) * 60);
             add_post_meta($event_post_tag_id, $this->to_time, date('H', $to_timestamp) * 3600 + date('i', $to_timestamp) * 60);
             add_post_meta($event_post_tag_id, $this->all_day, $all_day_event);
             if (function_exists('wpml_get_language_information') && function_exists('wpml_add_translatable_content')) {
                 $lang = wpml_get_language_information($post_id);
                 $language = substr(fw_akg('locale', $lang), 0, 2);
                 if (!empty($language)) {
                     wpml_add_translatable_content('post_' . $this->post_type, $event_post_tag_id, $language);
                 }
             }
             $users = fw_akg('event-user', $meta_row);
             if (is_array($users) && count($users) > 0) {
                 foreach ($users as $user) {
                     add_post_meta($event_post_tag_id, 'event-user', $user);
                 }
             }
         }
     }
     return true;
 }
Esempio n. 8
0
 function posts_list_shortcode($atts, $content = null, $shortcodename = '')
 {
     extract(shortcode_atts(array('type' => 'post', 'thumbs' => '', 'thumb_width' => '', 'thumb_height' => '', 'post_content' => '', 'numb' => '5', 'order_by' => '', 'order' => '', 'link' => '', 'link_text' => __('Read more', CHERRY_PLUGIN_DOMAIN), 'tag' => '', 'tags' => '', 'custom_class' => ''), $atts));
     // check what order by method user selected
     switch ($order_by) {
         case 'date':
             $order_by = 'post_date';
             break;
         case 'title':
             $order_by = 'title';
             break;
         case 'popular':
             $order_by = 'comment_count';
             break;
         case 'random':
             $order_by = 'rand';
             break;
     }
     // check what order method user selected (DESC or ASC)
     switch ($order) {
         case 'DESC':
             $order = 'DESC';
             break;
         case 'ASC':
             $order = 'ASC';
             break;
     }
     global $post;
     global $my_string_limit_words;
     global $_wp_additional_image_sizes;
     // WPML filter
     $suppress_filters = get_option('suppress_filters');
     $args = array('post_type' => $type, 'tag' => $tag, 'numberposts' => $numb, 'orderby' => $order_by, 'order' => $order, 'suppress_filters' => $suppress_filters);
     $posts = get_posts($args);
     $i = 0;
     // thumbnail size
     $thumb_x = 0;
     $thumb_y = 0;
     if ($thumbs == 'large') {
         $thumb_x = 620;
         $thumb_y = 300;
     } else {
         $thumb_x = $_wp_additional_image_sizes['post-thumbnail']['width'];
         $thumb_y = $_wp_additional_image_sizes['post-thumbnail']['height'];
     }
     // thumbnail class
     $thumbs_class = '';
     if ($thumbs == 'large') {
         $thumbs_class = 'large';
     }
     $output = '<div class="posts-list ' . $custom_class . '">';
     foreach ($posts as $key => $post) {
         // Unset not translated posts
         if (function_exists('wpml_get_language_information')) {
             global $sitepress;
             $check = wpml_get_language_information($post->ID);
             $language_code = substr($check['locale'], 0, 2);
             if ($language_code != $sitepress->get_current_language()) {
                 unset($posts[$key]);
             }
             // Post ID is different in a second language Solution
             if (function_exists('icl_object_id')) {
                 $post = get_post(icl_object_id($post->ID, $type, true));
             }
         }
         setup_postdata($post);
         $excerpt = get_the_excerpt();
         $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
         $url = $attachment_url['0'];
         if ($thumb_width != '' && $thumb_height != '') {
             $image = aq_resize($url, $thumb_width, $thumb_height, true);
         } else {
             $image = aq_resize($url, $thumb_x, $thumb_y, true);
         }
         $mediaType = get_post_meta($post->ID, 'tz_portfolio_type', true);
         $format = get_post_format();
         $output .= '<div class="row-fluid list-item-' . $i . '">';
         $output .= '<article class="span12 post__holder">';
         //post header
         $output .= '<header class="post-header">';
         $output .= '<h2 class="post-title"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
         $output .= get_the_title($post->ID);
         $output .= '</a></h2>';
         // post meta
         $output .= '<div class="post_meta">';
         // post category
         $output .= '<span class="post_category">';
         if ($type != '' && $type != 'post') {
             $terms = get_the_terms($post->ID, $type . '_category');
             if ($terms && !is_wp_error($terms)) {
                 $out = array();
                 $output .= __('Posted in', CHERRY_PLUGIN_DOMAIN) . ' ';
                 foreach ($terms as $term) {
                     $out[] = '<a href="' . get_term_link($term->slug, $type . '_category') . '">' . $term->name . '</a>';
                 }
                 $output .= join(', ', $out);
             }
         } else {
             $categories = get_the_category();
             if ($categories) {
                 $out = array();
                 $output .= __('Posted in', CHERRY_PLUGIN_DOMAIN) . ' ';
                 foreach ($categories as $category) {
                     $out[] = '<a href="' . get_category_link($category->term_id) . '" title="' . $category->name . '">' . $category->cat_name . '</a> ';
                 }
                 $output .= join(', ', $out);
             }
         }
         $output .= '</span>';
         // post date
         $output .= '<span class="post_date">';
         $output .= '<time datetime="' . get_the_time('Y-m-d\\TH:i:s', $post->ID) . '">' . get_the_date() . '</time>';
         $output .= '</span>';
         // post author
         $output .= '<span class="post_author">';
         $output .= __('by ', CHERRY_PLUGIN_DOMAIN) . ' ';
         $output .= '<a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a>';
         $output .= '</span>';
         // post comment count
         $num = 0;
         $post_id = $post->ID;
         $queried_post = get_post($post_id);
         $cc = $queried_post->comment_count;
         if ($cc == $num || $cc > 1) {
             $cc = $cc . ' ' . __('Comments', CHERRY_PLUGIN_DOMAIN);
         } else {
             $cc = $cc . ' ' . __('Comments', CHERRY_PLUGIN_DOMAIN);
         }
         $permalink = get_permalink($post_id);
         $output .= '<span class="post_comment">';
         $output .= '<a href="' . $permalink . '" class="comments_link">' . $cc . '</a>';
         $output .= '</span>';
         $output .= '</div>';
         $output .= cherry_get_post_networks(array('post_id' => $post_id, 'display_title' => false, 'output_type' => 'return'));
         $output .= '</header>';
         //post thumbnail
         if (has_post_thumbnail($post->ID) && ($format == 'image' || $mediaType == 'Image')) {
             $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
             $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
             $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             $output .= '</a></figure>';
         } elseif ($mediaType != 'Video' && $mediaType != 'Audio') {
             $thumbid = 0;
             $thumbid = get_post_thumbnail_id($post->ID);
             $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
             if ($images) {
                 $k = 0;
                 //looping through the images
                 foreach ($images as $attachment_id => $attachment) {
                     $image_attributes_t = wp_get_attachment_image_src($attachment_id);
                     // returns an array (thumbnail size)
                     $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                     // returns an array (full size)
                     if ($thumb_width != '' && $thumb_height != '') {
                         $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true);
                         //resize & crop img
                     } else {
                         $img = aq_resize($url, $thumb_x, $thumb_y, true);
                     }
                     $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                     $image_title = $attachment->post_title;
                     if ($k == 0) {
                         $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
                         $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                         $output .= '<img  src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                     }
                     $output .= '</a></figure>';
                     break;
                 }
             } elseif (has_post_thumbnail($post->ID)) {
                 $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
                 $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                 if ($thumb_width != '' && $thumb_height != '') {
                     $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                 } else {
                     if ($thumbs == 'normal') {
                         $output .= get_the_post_thumbnail($post->ID);
                     } else {
                         $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                     }
                 }
                 $output .= '</a></figure>';
             }
         } else {
             // for Video and Audio post format - no lightbox
             $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
             if ($thumb_width != '' && $thumb_height != '') {
                 $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             } else {
                 if ($thumbs == 'normal') {
                     $output .= get_the_post_thumbnail($post->ID);
                 } else {
                     $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                 }
             }
             $output .= '</a></figure>';
         }
         // post content
         if ($post_content != 'none' || $link == 'yes') {
             $output .= '<div class="post_content">';
             switch ($post_content) {
                 case 'excerpt':
                     $output .= '<p class="excerpt">';
                     $output .= wp_trim_words(get_the_excerpt(), 50);
                     $output .= '</p>';
                     break;
                 case 'content':
                     $output .= '<div class="full-post-content">';
                     $output .= get_the_content();
                     $output .= '</div>';
                     break;
                 case 'none':
                     break;
             }
             if ($link == 'yes') {
                 $output .= '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary" title="' . get_the_title($post->ID) . '">';
                 $output .= $link_text;
                 $output .= '</a>';
             }
             $output .= '</div>';
         }
         //post footer
         if ($tags == 'yes') {
             $posttags = get_the_tags();
             if ($posttags) {
                 $output .= '<footer class="post_footer">' . __('Tags', CHERRY_PLUGIN_DOMAIN) . ": ";
                 foreach ($posttags as $tag) {
                     $output .= '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a> ';
                 }
                 $output .= '</footer>';
             }
         }
         $output .= '</article>';
         $output .= '</div><!-- .row-fluid (end) -->';
         $i++;
     }
     // end foreach
     wp_reset_postdata();
     // restore the global $post variable
     $output .= '</div><!-- .posts-list (end) -->';
     $output = apply_filters('cherry_plugin_shortcode_output', $output, $atts, $shortcodename);
     return $output;
 }
 /**
  * Generates the query based on the post and the toke array and inserts into DB
  *
  * @param object $the_post the post
  * @param array $tokens tokens array
  *
  * @return bool
  */
 private function insertTokensToDB($the_post, $tokens)
 {
     global $wpdb;
     $asp_index_table = $this->asp_index_table;
     $args = $this->args;
     $values = array();
     $lang = '';
     if (count($tokens) <= 0) {
         return false;
     }
     foreach ($tokens as $term => $d) {
         // If it's numeric, delete the leading space
         $term = trim($term);
         if (function_exists('wpml_get_language_information')) {
             $lang_info = wpml_get_language_information($the_post->ID);
             $lang_arr = explode('_', $lang_info['locale']);
             $lang = $lang_arr[0];
         }
         $value = $wpdb->prepare("(%d, %s, REVERSE(%s), %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %s, %d, %s)", $the_post->ID, $term, $term, $args['blog_id'], $d['content'], $d['title'], $d['comment'], $d['tag'], $d['link'], $d['author'], $d['category'], $d['excerpt'], $d['taxonomy'], $d['customfield'], $the_post->post_type, 0, $lang);
         $values[] = $value;
     }
     if (count($values) > 0) {
         $values = implode(', ', $values);
         $query = "INSERT INTO {$asp_index_table}\n\t\t\t\t(`doc`, `term`, `term_reverse`, `blogid`, `content`, `title`, `comment`, `tag`, `link`, `author`,\n\t\t\t\t `category`, `excerpt`, `taxonomy`, `customfield`, `post_type`, `item`, `lang`)\n\t\t\t\tVALUES {$values}";
         $wpdb->query($query);
         $this->keywords_found += count($tokens);
     }
     return true;
 }
Esempio n. 10
0
    function shortcode_roundabout($atts, $content = null)
    {
        extract(shortcode_atts(array('title' => '', 'num' => '3', 'type' => '', 'thumb_width' => '375', 'thumb_height' => '250', 'category' => '', 'custom_category' => '', 'more_button_text' => '', 'more_button_link' => '', 'custom_class' => ''), $atts));
        wp_enqueue_script('roundabout_script', CHERRY_PLUGIN_URL . 'includes/assets/js/jquery.roundabout.min.js', array('jquery'));
        wp_enqueue_script('roundabout_shape', CHERRY_PLUGIN_URL . 'includes/assets/js/jquery.roundabout-shapes.min.js', array('jquery'));
        $ra_id = uniqid();
        // check what type of post user selected
        switch ($type) {
            case 'blog':
                $type_post = 'post';
                break;
            case 'portfolio':
                $type_post = 'portfolio';
                break;
            case 'testimonial':
                $type_post = 'testi';
                break;
            case 'our team':
                $type_post = 'team';
                break;
            default:
                $type_post = 'post';
                break;
        }
        $output = '<div class="roundabout-holder ' . $custom_class . '">';
        if ($title != '') {
            $output .= '<h2>' . $title . '</h2>';
        }
        $output .= '<ul id="roundabout-list-' . $ra_id . '" class="unstyled">';
        global $post;
        // WPML filter
        $suppress_filters = get_option('suppress_filters');
        $args = array('post_type' => $type_post, 'category_name' => $category, $type_post . '_category' => $custom_category, 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => $suppress_filters);
        $posts = get_posts($args);
        $i = 1;
        foreach ($posts as $key => $post) {
            // Unset not translated posts
            if (function_exists('wpml_get_language_information')) {
                global $sitepress;
                $check = wpml_get_language_information($post->ID);
                $language_code = substr($check['locale'], 0, 2);
                if ($language_code != $sitepress->get_current_language()) {
                    unset($posts[$key]);
                }
                // Post ID is different in a second language Solution
                if (function_exists('icl_object_id')) {
                    $post = get_post(icl_object_id($post->ID, $type_post, true));
                }
            }
            setup_postdata($post);
            if ($num == -1) {
                $num = count($posts);
            }
            if ($num >= $i) {
                if (has_post_thumbnail($post->ID)) {
                    $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
                    $url = $attachment_url['0'];
                    $image = aq_resize($url, $thumb_width, $thumb_height, true);
                    $output .= '<li>';
                    $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                    $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                    $output .= '</a>';
                    $output .= '</li>';
                    $i++;
                }
            }
        }
        wp_reset_postdata();
        // restore the global $post variable
        $output .= '</ul>';
        if ($more_button_text != '' && $more_button_link != '') {
            $output .= '<a class="btn btn-primary" href="' . $more_button_link . '">' . $more_button_text . '</a>';
        }
        $output .= '<script>
				jQuery(document).ready(function() {
					jQuery("#roundabout-list-' . $ra_id . '").roundabout({
						minOpacity: 1,
						minScale: 0.6,
						minZ: 0,
						shape: "square",
						responsive: true
					});
				});
				jQuery(window).bind("resize", function() {
					jQuery("#roundabout-list-' . $ra_id . ' li").removeAttr("style");
					jQuery("#roundabout-list-' . $ra_id . '").roundabout({
						minOpacity: 1,
						minScale: 0.6,
						responsive: false
					});
				});';
        $output .= '</script>';
        $output .= '</div>';
        return $output;
    }
Esempio n. 11
0
					<h3 class="archive_h"><?php 
        echo theme_locals("last_posts");
        ?>
</h3>
					<div class="list styled check-list">
						<ul>
							<?php 
        // WPML filter
        $suppress_filters = get_option('suppress_filters');
        $archive_args = array('numberposts' => 30, 'suppress_filters' => $suppress_filters);
        $archive_30 = get_posts($archive_args);
        foreach ($archive_30 as $key => $post) {
            // Unset not translated posts
            if (function_exists('wpml_get_language_information')) {
                global $sitepress;
                $check = wpml_get_language_information($post->ID);
                $language_code = substr($check['locale'], 0, 2);
                if ($language_code != $sitepress->get_current_language()) {
                    unset($posts[$key]);
                }
                // Post ID is different in a second language Solution
                if (function_exists('icl_object_id')) {
                    $post = get_post(icl_object_id($post->ID, $type, true));
                }
            }
            ?>

									<li><a href="<?php 
            the_permalink();
            ?>
"><?php 
function shortcode_recenttesti($atts, $content = null)
{
    extract(shortcode_atts(array('num' => '5', 'thumb' => 'true', 'excerpt_count' => '30', 'custom_class' => ''), $atts));
    // WPML filter
    $suppress_filters = get_option('suppress_filters');
    $args = array('post_type' => 'testi', 'numberposts' => $num, 'orderby' => 'post_date', 'suppress_filters' => $suppress_filters);
    $testi = get_posts($args);
    $output = '<div class="testimonials ' . $custom_class . '">';
    global $post;
    global $my_string_limit_words;
    foreach ($testi as $k => $post) {
        // Unset not translated posts
        if (function_exists('wpml_get_language_information')) {
            global $sitepress;
            $check = wpml_get_language_information($post->ID);
            $language_code = substr($check['locale'], 0, 2);
            if ($language_code != $sitepress->get_current_language()) {
                unset($testi[$k]);
            }
            // Post ID is different in a second language Solution
            if (function_exists('icl_object_id')) {
                $post = get_post(icl_object_id($post->ID, 'testi', true));
            }
        }
        setup_postdata($post);
        $excerpt = get_the_excerpt();
        $testiname = get_post_meta(get_the_ID(), 'my_testi_caption', true);
        $testiurl = get_post_meta(get_the_ID(), 'my_testi_url', true);
        $testiinfo = get_post_meta(get_the_ID(), 'my_testi_info', true);
        $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
        $url = $attachment_url['0'];
        $image = aq_resize($url, 280, 240, true);
        $output .= '<div class="testi-item">';
        $output .= '<div class="testi-meta">';
        if (isset($testiname)) {
            $output .= '<div class="user">';
            $output .= $testiname;
            $output .= '</div>';
        }
        if (isset($testiinfo)) {
            $output .= '<div class="info">(';
            $output .= $testiinfo;
            $output .= ')</div>';
        }
        $output .= '</div>';
        $output .= '<blockquote class="testi-item_blockquote">';
        if ($thumb == 'true') {
            if (has_post_thumbnail($post->ID)) {
                $output .= '<figure class="featured-thumbnail">';
                $output .= '<img src="' . $image . '" alt="" />';
                $output .= '</figure>';
            }
        }
        $output .= '<a href="' . get_permalink($post->ID) . '">';
        $output .= my_string_limit_words($excerpt, $excerpt_count);
        $output .= '</a><span class="close_quote"></span><div class="clear"></div>';
        $output .= '</blockquote>';
        $output .= '</div>';
    }
    wp_reset_postdata();
    // restore the global $post variable
    $output .= '</div>';
    return $output;
}
Esempio n. 13
0
 function posts_grid_shortcode($atts, $content = null)
 {
     extract(shortcode_atts(array('type' => 'post', 'category' => '', 'custom_category' => '', 'columns' => '3', 'rows' => '3', 'order_by' => 'date', 'order' => 'DESC', 'thumb_width' => '370', 'thumb_height' => '250', 'meta' => '', 'excerpt_count' => '15', 'link' => 'yes', 'link_text' => __('Read more', CHERRY_PLUGIN_DOMAIN), 'custom_class' => ''), $atts));
     $spans = $columns;
     $rand = rand();
     // columns
     switch ($spans) {
         case '1':
             $spans = 'span12';
             break;
         case '2':
             $spans = 'span6';
             break;
         case '3':
             $spans = 'span4';
             break;
         case '4':
             $spans = 'span3';
             break;
         case '6':
             $spans = 'span2';
             break;
     }
     // check what order by method user selected
     switch ($order_by) {
         case 'date':
             $order_by = 'post_date';
             break;
         case 'title':
             $order_by = 'title';
             break;
         case 'popular':
             $order_by = 'comment_count';
             break;
         case 'random':
             $order_by = 'rand';
             break;
     }
     // check what order method user selected (DESC or ASC)
     switch ($order) {
         case 'DESC':
             $order = 'DESC';
             break;
         case 'ASC':
             $order = 'ASC';
             break;
     }
     // show link after posts?
     switch ($link) {
         case 'yes':
             $link = true;
             break;
         case 'no':
             $link = false;
             break;
     }
     global $post;
     global $my_string_limit_words;
     $numb = $columns * $rows;
     // WPML filter
     $suppress_filters = get_option('suppress_filters');
     $args = array('post_type' => $type, 'category_name' => $category, $type . '_category' => $custom_category, 'numberposts' => $numb, 'orderby' => $order_by, 'order' => $order, 'suppress_filters' => $suppress_filters);
     $posts = get_posts($args);
     $i = 0;
     $count = 1;
     $output_end = '';
     if ($numb > count($posts)) {
         $output_end = '</ul>';
     }
     $output = '<ul class="posts-grid row-fluid unstyled ' . $custom_class . '">';
     for ($j = 0; $j < count($posts); $j++) {
         // Unset not translated posts
         if (function_exists('wpml_get_language_information')) {
             global $sitepress;
             $check = wpml_get_language_information($posts[$j]->ID);
             $language_code = substr($check['locale'], 0, 2);
             if ($language_code != $sitepress->get_current_language()) {
                 unset($posts[$j]);
             }
             // Post ID is different in a second language Solution
             if (function_exists('icl_object_id')) {
                 $posts[$j] = get_post(icl_object_id($posts[$j]->ID, $type, true));
             }
         }
         $post_id = $posts[$j]->ID;
         setup_postdata($posts[$j]);
         $excerpt = get_the_excerpt();
         $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full');
         $url = $attachment_url['0'];
         $image = aq_resize($url, $thumb_width, $thumb_height, true);
         $mediaType = get_post_meta($post_id, 'tz_portfolio_type', true);
         $prettyType = 0;
         if ($count > $columns) {
             $count = 1;
             $output .= '<ul class="posts-grid row-fluid unstyled ' . $custom_class . '">';
         }
         $output .= '<li class="' . $spans . '">';
         if (has_post_thumbnail($post_id) && $mediaType == 'Image') {
             $prettyType = 'prettyPhoto-' . $rand;
             $output .= '<figure class="featured-thumbnail thumbnail">';
             $output .= '<a href="' . $url . '" title="' . get_the_title($post_id) . '" rel="' . $prettyType . '">';
             $output .= '<img  src="' . $image . '" alt="' . get_the_title($post_id) . '" />';
             $output .= '<span class="zoom-icon"></span></a></figure>';
         } elseif ($mediaType != 'Video' && $mediaType != 'Audio') {
             $thumbid = 0;
             $thumbid = get_post_thumbnail_id($post_id);
             $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
             if ($images) {
                 $k = 0;
                 //looping through the images
                 foreach ($images as $attachment_id => $attachment) {
                     $prettyType = "prettyPhoto-" . $rand . "[gallery" . $i . "]";
                     //if( $attachment->ID == $thumbid ) continue;
                     $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                     // returns an array
                     $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true);
                     //resize & crop img
                     $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                     $image_title = $attachment->post_title;
                     if ($k == 0) {
                         if (has_post_thumbnail($post_id)) {
                             $output .= '<figure class="featured-thumbnail thumbnail">';
                             $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post_id) . '" rel="' . $prettyType . '">';
                             $output .= '<img src="' . $image . '" alt="' . get_the_title($post_id) . '" />';
                         } else {
                             $output .= '<figure class="featured-thumbnail thumbnail">';
                             $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post_id) . '" rel="' . $prettyType . '">';
                             $output .= '<img  src="' . $img . '" alt="' . get_the_title($post_id) . '" />';
                         }
                     } else {
                         $output .= '<figure class="featured-thumbnail thumbnail" style="display:none;">';
                         $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post_id) . '" rel="' . $prettyType . '">';
                     }
                     $output .= '<span class="zoom-icon"></span></a></figure>';
                     $k++;
                 }
             } elseif (has_post_thumbnail($post_id)) {
                 $prettyType = 'prettyPhoto-' . $rand;
                 $output .= '<figure class="featured-thumbnail thumbnail">';
                 $output .= '<a href="' . $url . '" title="' . get_the_title($post_id) . '" rel="' . $prettyType . '">';
                 $output .= '<img  src="' . $image . '" alt="' . get_the_title($post_id) . '" />';
                 $output .= '<span class="zoom-icon"></span></a></figure>';
             }
         } else {
             // for Video and Audio post format - no lightbox
             $output .= '<figure class="featured-thumbnail thumbnail"><a href="' . get_permalink($post_id) . '" title="' . get_the_title($post_id) . '">';
             $output .= '<img  src="' . $image . '" alt="' . get_the_title($post_id) . '" />';
             $output .= '</a></figure>';
         }
         $output .= '<div class="clear"></div>';
         $output .= '<h5><a href="' . get_permalink($post_id) . '" title="' . get_the_title($post_id) . '">';
         $output .= get_the_title($post_id);
         $output .= '</a></h5>';
         if ($meta == 'yes') {
             // begin post meta
             $output .= '<div class="post_meta">';
             // post category
             $output .= '<span class="post_category">';
             if ($type != '' && $type != 'post') {
                 $terms = get_the_terms($post_id, $type . '_category');
                 if ($terms && !is_wp_error($terms)) {
                     $out = array();
                     $output .= '<em>Posted in </em>';
                     foreach ($terms as $term) {
                         $out[] = '<a href="' . get_term_link($term->slug, $type . '_category') . '">' . $term->name . '</a>';
                     }
                     $output .= join(', ', $out);
                 }
             } else {
                 $categories = get_the_category($post_id);
                 if ($categories) {
                     $out = array();
                     $output .= '<em>Posted in </em>';
                     foreach ($categories as $category) {
                         $out[] = '<a href="' . get_category_link($category->term_id) . '" title="' . $category->name . '">' . $category->cat_name . '</a> ';
                     }
                     $output .= join(', ', $out);
                 }
             }
             $output .= '</span>';
             // post date
             $output .= '<span class="post_date">';
             $output .= '<time datetime="' . get_the_time('Y-m-d\\TH:i:s', $post_id) . '">' . get_the_date() . '</time>';
             $output .= '</span>';
             // post author
             $output .= '<span class="post_author">';
             $output .= '<em> by </em>';
             $output .= '<a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a>';
             $output .= '</span>';
             // post comment count
             $num = 0;
             $queried_post = get_post($post_id);
             $cc = $queried_post->comment_count;
             if ($cc == $num || $cc > 1) {
                 $cc = $cc . ' Comments';
             } else {
                 $cc = $cc . ' Comment';
             }
             $permalink = get_permalink($post_id);
             $output .= '<span class="post_comment">';
             $output .= '<a href="' . $permalink . '" class="comments_link">' . $cc . '</a>';
             $output .= '</span>';
             $output .= '</div>';
             // end post meta
         }
         $output .= cherry_get_post_networks(array('post_id' => $post_id, 'display_title' => false, 'output_type' => 'return'));
         if ($excerpt_count >= 1) {
             $output .= '<p class="excerpt">';
             $output .= my_string_limit_words($excerpt, $excerpt_count);
             $output .= '</p>';
         }
         if ($link) {
             $output .= '<a href="' . get_permalink($post_id) . '" class="btn btn-primary" title="' . get_the_title($post_id) . '">';
             $output .= $link_text;
             $output .= '</a>';
         }
         $output .= '</li>';
         if ($j == count($posts) - 1) {
             $output .= $output_end;
         }
         if ($count % $columns == 0) {
             $output .= '</ul><!-- .posts-grid (end) -->';
         }
         $count++;
         $i++;
     }
     // end for
     wp_reset_postdata();
     // restore the global $post variable
     return $output;
 }
Esempio n. 14
0
/**
* @return return the slider data for dunction st_slider
*/
function st_get_setup_post_slider_data($get_posts_args = array())
{
    if (empty($get_posts_args)) {
        return array();
    }
    $r = wp_parse_args($get_posts_args, array('cats' => '', 'numpost' => 5, 'exclude' => '', 'orderby' => 'ID', 'order' => 'DESC'));
    extract($r);
    if ($numpost <= 0) {
        $numpost = 5;
    }
    if (!is_array($cats)) {
        $cats = explode(',', $cats);
    }
    /**
     * @Since ver 1.3
     */
    $args = array('posts_per_page' => $numpost);
    if ($exclude != '') {
        $exclude = explode(',', $exclude);
        $args['post__not_in'] = $exclude;
    }
    if ($cats) {
        $args['category__in'] = $cats;
    }
    $args['meta_key'] = '_thumbnail_id';
    $args['meta_query'] = array(array('key' => '_thumbnail_id', 'value' => 0, 'type' => 'numeric', 'compare' => '>'));
    $args['orderby'] = $orderby;
    $args['order'] = $order;
    $args['post_status'] = 'publish';
    if (st_is_wpml()) {
        if (is_admin()) {
            // this function calling in admin page
            global $post;
            $lang_data = wpml_get_language_information($post->ID);
            //  echo var_dump($lang_data,$post->ID); die();
            $args['language'] = $lang_data['locale'];
        } else {
            $args['language'] = get_bloginfo('language');
        }
        $args['sippress_filters'] = true;
    }
    // echo var_dump($args);
    $new_query = new WP_Query($args);
    $myposts = $new_query->posts;
    $data['images'] = array();
    $data['meta'] = array();
    if (count($myposts)) {
        $i = 0;
        foreach ($myposts as $post) {
            $id = get_post_thumbnail_id($post->ID);
            if ($id > 0) {
                $data['images'][$i] = $id;
                $data['meta'][$i]['title'] = get_the_title($post->ID);
                $data['meta'][$i]['url'] = get_permalink($post->ID);
                $data['meta'][$i]['date'] = mysql2date('M j, Y', $post->post_date);
                $content = '';
                if (preg_match('/<!--more(.*?)?-->/', $post->post_content, $matches)) {
                    $content = explode($matches[0], $post->post_content, 2);
                    $content = $content[0];
                } else {
                    $content = st_get_substr(strip_tags($post->post_content), st_get_setting("limit_char", 70), '');
                }
                if ($content != '') {
                    $content .= st_excerpt_more();
                }
                $data['meta'][$i]['caption'] = $content;
                $i++;
            }
        }
    }
    return $data;
}
Esempio n. 15
0
 function posts_list_shortcode($atts, $content = null, $shortcodename = '')
 {
     extract(shortcode_atts(array('type' => 'post', 'thumbs' => '', 'thumb_width' => '', 'thumb_height' => '', 'post_content' => '', 'numb' => '5', 'order_by' => '', 'order' => '', 'link' => '', 'link_text' => __('Read more', CHERRY_PLUGIN_DOMAIN), 'tag' => '', 'tags' => '', 'custom_class' => ''), $atts));
     // check what order by method user selected
     switch ($order_by) {
         case 'date':
             $order_by = 'post_date';
             break;
         case 'title':
             $order_by = 'title';
             break;
         case 'popular':
             $order_by = 'comment_count';
             break;
         case 'random':
             $order_by = 'rand';
             break;
     }
     // check what order method user selected (DESC or ASC)
     switch ($order) {
         case 'DESC':
             $order = 'DESC';
             break;
         case 'ASC':
             $order = 'ASC';
             break;
     }
     global $post;
     global $my_string_limit_words;
     global $_wp_additional_image_sizes;
     // WPML filter
     $suppress_filters = get_option('suppress_filters');
     $args = array('post_type' => $type, 'tag' => $tag, 'numberposts' => $numb, 'orderby' => $order_by, 'order' => $order, 'suppress_filters' => $suppress_filters);
     $posts = get_posts($args);
     $i = 0;
     // thumbnail size
     $thumb_x = 0;
     $thumb_y = 0;
     if ($thumbs == 'large') {
         $thumb_x = 620;
         $thumb_y = 300;
     } else {
         $thumb_x = $_wp_additional_image_sizes['post-thumbnail']['width'];
         $thumb_y = $_wp_additional_image_sizes['post-thumbnail']['height'];
     }
     // thumbnail class
     $thumbs_class = '';
     if ($thumbs == 'large') {
         $thumbs_class = 'large';
     }
     $output = '<ul class="posts-list ' . $custom_class . '">';
     foreach ($posts as $key => $post) {
         // Unset not translated posts
         if (function_exists('wpml_get_language_information')) {
             global $sitepress;
             $check = wpml_get_language_information($post->ID);
             $language_code = substr($check['locale'], 0, 2);
             if ($language_code != $sitepress->get_current_language()) {
                 unset($posts[$key]);
             }
             // Post ID is different in a second language Solution
             if (function_exists('icl_object_id')) {
                 $post = get_post(icl_object_id($post->ID, $type, true));
             }
         }
         setup_postdata($post);
         $excerpt = get_the_excerpt();
         $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
         $url = $attachment_url['0'];
         if ($thumb_width != '' && $thumb_height != '') {
             $image = aq_resize($url, $thumb_width, $thumb_height, true);
         } else {
             $image = aq_resize($url, $thumb_x, $thumb_y, true);
         }
         $mediaType = get_post_meta($post->ID, 'tz_portfolio_type', true);
         $format = get_post_format();
         $output .= '<li class="row-fluid list-item-' . $i . '">';
         $output .= '<article class="span12 post__holder">';
         //post thumbnail
         if (has_post_thumbnail($post->ID) && ($format == 'image' || $mediaType == 'Image')) {
             $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
             $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
             $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             $output .= '</a></figure>';
         } elseif ($mediaType != 'Video' && $mediaType != 'Audio') {
             $thumbid = 0;
             $thumbid = get_post_thumbnail_id($post->ID);
             $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
             if ($images) {
                 $k = 0;
                 //looping through the images
                 foreach ($images as $attachment_id => $attachment) {
                     $image_attributes_t = wp_get_attachment_image_src($attachment_id);
                     // returns an array (thumbnail size)
                     $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                     // returns an array (full size)
                     if ($thumb_width != '' && $thumb_height != '') {
                         $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true);
                         //resize & crop img
                     } else {
                         $img = aq_resize($url, $thumb_x, $thumb_y, true);
                     }
                     $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                     $image_title = $attachment->post_title;
                     if ($k == 0) {
                         $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
                         $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                         $output .= '<img  src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                     }
                     $output .= '</a></figure>';
                     break;
                 }
             } elseif (has_post_thumbnail($post->ID)) {
                 $output .= '<div class="image_box">';
                 $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '">';
                 $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                 if ($thumb_width != '' && $thumb_height != '') {
                     $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                 } else {
                     if ($thumbs == 'normal') {
                         $output .= get_the_post_thumbnail($post->ID);
                     } else {
                         $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                     }
                 }
                 $output .= '</a></figure>';
                 // post category
                 $output .= '<span class="post_category">';
                 if ($type != '' && $type != 'post') {
                     $terms = get_the_terms($post->ID, $type . '_category');
                     if ($terms && !is_wp_error($terms)) {
                         $out = array();
                         foreach ($terms as $term) {
                             $out[] = '<a href="' . get_term_link($term->slug, $type . '_category') . '">' . $term->name . '</a>';
                         }
                         $output .= join(', ', $out);
                     }
                 } else {
                     $categories = get_the_category();
                     if ($categories) {
                         $out = array();
                         foreach ($categories as $category) {
                             $out[] = '<a href="' . get_category_link($category->term_id) . '" title="' . $category->name . '">' . $category->cat_name . '</a> ';
                         }
                         $output .= join(', ', $out);
                     }
                 }
                 $output .= '</span>';
                 $output .= '</div>';
             }
         } else {
             // for Video and Audio post format - no lightbox
             $output .= '<figure class="featured-thumbnail thumbnail ' . $thumbs_class . '"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
             if ($thumb_width != '' && $thumb_height != '') {
                 $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             } else {
                 if ($thumbs == 'normal') {
                     $output .= get_the_post_thumbnail($post->ID);
                 } else {
                     $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                 }
             }
             $output .= '</a></figure>';
         }
         $output .= '<h5 class="post-title"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
         $output .= get_the_title($post->ID);
         $output .= '</a></h5>';
         $output .= cherry_get_post_networks(array('post_id' => $post_id, 'display_title' => false, 'output_type' => 'return'));
         // post content
         if ($post_content != 'none' || $link == 'yes') {
             $output .= '<div class="post_content">';
             switch ($post_content) {
                 case 'excerpt':
                     $output .= '<p class="excerpt">';
                     $output .= my_string_limit_words(get_the_excerpt(), 50);
                     $output .= '</p>';
                     break;
                 case 'content':
                     $output .= '<div class="full-post-content">';
                     $output .= get_the_content();
                     $output .= '</div>';
                     break;
                 case 'none':
                     break;
             }
             // begin post meta
             $output .= '<span class="meta">';
             $output .= '<span class="post_count">';
             $output .= $icon_tips_before . custom_getPostViews($post->ID) . $icon_tips_after;
             $output .= '</span>';
             $output .= '<span class="post-comments">';
             $output .= '<a href="' . get_comments_link($post->ID) . '">';
             $output .= get_comments_number($post->ID);
             $output .= '</a>';
             $output .= '</span>';
             $post_ID = get_the_ID();
             $post_type = get_post_type($post_ID);
             $icon_tips_before = $post_meta_type == 'icon' ? '<div class="tips">' : '';
             $icon_tips_after = $post_meta_type == 'icon' ? '</div>' : '';
             $user_login = is_user_logged_in() ? true : false;
             $user_id = $user_login ? get_current_user_id() : "";
             $voting_class = $user_login ? 'ajax_voting ' : 'not_voting ';
             $voting_url = PARENT_URL . '/includes/voting.php?post_ID=' . $post_ID . '&amp;get_user_ID=' . $user_id;
             $get_voting_array = cherry_getPostVoting($post_ID, $user_id);
             $user_voting = $get_voting_array['user_voting'];
             $like_url = $user_login && $user_voting == 'none' ? 'href="' . $voting_url . '&amp;voting=like"' : '';
             $like_count = $get_voting_array['like_count'];
             $like_title = $user_login ? theme_locals('like') : theme_locals('not_voting');
             $like_class = $user_voting == 'like' ? 'user_like ' : '';
             if ($user_voting != 'none') {
                 $voting_class = "user_voting ";
             }
             $output .= '<span class="post_like">';
             $output .= '<a ' . $like_url . ' class="' . $voting_class . $like_class . '" title="' . $like_title . '" date-type="like" >';
             $output .= '<i class="icon-thumbs-up"></i>';
             $output .= $icon_tips_before . '<span class="voting_count">' . $like_count . '</span>' . $icon_tips_after;
             $output .= '</a>';
             $output .= '</span>';
             $output .= '</span>';
             // end post meta
             if ($link == 'yes') {
                 $output .= '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary" title="' . get_the_title($post->ID) . '">';
                 $output .= $link_text;
                 $output .= '</a>';
             }
             $output .= '</div>';
         }
         //post footer
         if ($tags == 'yes') {
             $posttags = get_the_tags();
             if ($posttags) {
                 $output .= '<footer class="post_footer">' . __('Tags', CHERRY_PLUGIN_DOMAIN) . ": ";
                 foreach ($posttags as $tag) {
                     $output .= '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a> ';
                 }
                 $output .= '</footer>';
             }
         }
         $output .= '</article>';
         $output .= '</li><!-- .row-fluid (end) -->';
         $i++;
     }
     // end foreach
     wp_reset_postdata();
     // restore the global $post variable
     $output .= '</ul><!-- .posts-list (end) -->';
     $output = apply_filters('cherry_plugin_shortcode_output', $output, $atts, $shortcodename);
     return $output;
 }
Esempio n. 16
0
    function shortcode_carousel($atts, $content = null)
    {
        extract(shortcode_atts(array('title' => '', 'num' => '8', 'type' => '', 'thumb' => 'true', 'thumb_width' => '220', 'thumb_height' => '180', 'more_text_single' => theme_locals('read_more'), 'category' => '', 'custom_category' => '', 'excerpt_count' => '12', 'date' => '', 'author' => '', 'min_items' => '3', 'spacer' => '18', 'custom_class' => ''), $atts));
        $template_url = get_stylesheet_directory_uri();
        // check what type of post user selected
        switch ($type) {
            case 'blog':
                $type_post = 'post';
                break;
            case 'portfolio':
                $type_post = 'portfolio';
                break;
            case 'testimonial':
                $type_post = 'testi';
                break;
        }
        $output = '<div class="carousel-wrap ' . $custom_class . '">';
        if ($title != '') {
            $output .= '<h2>' . $title . '</h2>';
        }
        $output .= '<div id="carousel-' . $type . '" class="es-carousel-wrapper">';
        $output .= '<div class="es-carousel">';
        $output .= '<ul class="es-carousel_list unstyled">';
        global $post;
        global $my_string_limit_words;
        // WPML filter
        $suppress_filters = get_option('suppress_filters');
        $args = array('post_type' => $type_post, 'category_name' => $category, $type_post . '_category' => $custom_category, 'numberposts' => $num, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => $suppress_filters);
        $latest = get_posts($args);
        $i = 0;
        foreach ($latest as $key => $post) {
            // Unset not translated posts
            if (function_exists('wpml_get_language_information')) {
                global $sitepress;
                $check = wpml_get_language_information($post->ID);
                $language_code = substr($check['locale'], 0, 2);
                if ($language_code != $sitepress->get_current_language()) {
                    unset($latest[$key]);
                }
                // Post ID is different in a second language Solution
                if (function_exists('icl_object_id')) {
                    $post = get_post(icl_object_id($post->ID, $type_post, true));
                }
            }
            setup_postdata($post);
            $excerpt = get_the_excerpt();
            $format = get_post_format();
            $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
            $url = $attachment_url['0'];
            $image = aq_resize($url, $thumb_width, $thumb_height, true);
            $link_format_url = get_post_meta(get_the_ID(), 'tz_link_url', true);
            $output .= '<li class="es-carousel_li ' . $format . '">';
            if ($thumb == 'true') {
                if (has_post_thumbnail($post->ID) && $format == 'image') {
                    $output .= '<figure class="featured-thumbnail">';
                    $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                    $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                    $output .= '</a></figure>';
                } elseif ($format != 'video' && $format != 'audio') {
                    $thumbid = 0;
                    $thumbid = get_post_thumbnail_id($post->ID);
                    $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
                    if ($images) {
                        $k = 0;
                        //looping through the images
                        foreach ($images as $attachment_id => $attachment) {
                            //if( $attachment->ID == $thumbid ) continue;
                            $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                            // returns an array
                            $img = aq_resize($image_attributes[0], $thumb_width, $thumb_height, true);
                            //resize & crop img
                            $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                            $image_title = $attachment->post_title;
                            if ($k == 0) {
                                $output .= '<figure class="featured-thumbnail">';
                                $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                                $output .= '<img src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                            } else {
                                $output .= '<figure class="featured-thumbnail" style="display:none;">';
                                $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                                $output .= '<img src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                            }
                            $output .= '</a></figure>';
                            $k++;
                        }
                    } elseif (has_post_thumbnail($post->ID)) {
                        $output .= '<figure class="featured-thumbnail">';
                        $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                        $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                        $output .= '</a></figure>';
                    }
                    /*else {
                    			// empty_featured_thumb.gif - for post without featured thumbnail
                    			$output .= '<figure class="featured-thumbnail">';
                    			$output .= '<a href="'.get_permalink($post->ID).'" title="'.get_the_title($post->ID).'">';
                    			$output .= '<img  src="'.$template_url.'/images/empty_thumb.gif" alt="'.get_the_title($post->ID).'" />';
                    			$output .= '</a></figure>';
                    		}*/
                } else {
                    if (has_post_thumbnail($post->ID)) {
                        // for Video and Audio post format - no lightbox
                        $output .= '<figure class="featured-thumbnail"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                        $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                        $output .= '</a></figure>';
                    }
                    /*else {
                    			// empty_featured_thumb.gif - for post without featured thumbnail
                    			$output .= '<figure class="featured-thumbnail">';
                    			$output .= '<a href="'.get_permalink($post->ID).'" title="'.get_the_title($post->ID).'">';
                    			$output .= '<img  src="'.$template_url.'/images/empty_thumb.gif" alt="'.get_the_title($post->ID).'" />';
                    			$output .= '</a></figure>';
                    		}*/
                }
            }
            $output .= '<div class="desc">';
            if ($date == "yes") {
                $output .= '<time datetime="' . get_the_time('Y-m-d\\TH:i:s', $post->ID) . '">' . get_the_date() . '</time>';
            }
            if ($author == "yes") {
                $output .= '<em class="author">, ' . theme_locals("by") . ' <a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a></em>';
            }
            //Link format
            if ($format == "link") {
                $output .= '<h5><a href="' . $link_format_url . '" title="' . get_the_title($post->ID) . '">';
                $output .= get_the_title($post->ID);
                $output .= '</a></h5>';
                //Other formats
            } else {
                $output .= '<h5><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                $output .= get_the_title($post->ID);
                $output .= '</a></h5>';
            }
            if ($excerpt_count >= 1) {
                $output .= '<p class="excerpt">';
                $output .= my_string_limit_words($excerpt, $excerpt_count);
                $output .= '</p>';
            }
            if ($more_text_single != "") {
                $output .= '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary" title="' . get_the_title($post->ID) . '">';
                $output .= $more_text_single;
                $output .= '</a>';
            }
            $output .= '</div>';
            $output .= '</li>';
        }
        $output .= '</ul>';
        $output .= '</div></div>';
        $output .= '<script>
					jQuery("#carousel-' . $type . '").elastislide({
						imageW 		: ' . $thumb_width . ',
						minItems	: ' . $min_items . ',
						speed		: 600,
						easing		: "easeOutQuart",
						margin		: ' . $spacer . ',
						border		: 0,
						onClick		: function() {}
					});';
        $output .= '</script>';
        $output .= '</div>';
        return $output;
    }
Esempio n. 17
0
 /**
  * Filters the "all" fragment of the all recurrences link.
  *
  * @param string $all_frag
  * @param int    $post_id
  */
 public function filter_tribe_events_pro_all_link_frag($all_frag, $post_id)
 {
     $language_information = wpml_get_language_information(null, $post_id);
     if (!is_array($language_information) || empty($language_information['locale'])) {
         return $all_frag;
     }
     $locale = $language_information['locale'];
     $all_frags = Tribe__Events__Integrations__WPML__Utils::get_wpml_i18n_strings(array('all'), $locale);
     if (empty($all_frags[0]) || !is_array($all_frags[0])) {
         return $all_frag;
     }
     // the last translation is the one in the language we seek
     return end($all_frags[0]);
 }
Esempio n. 18
0
			<div class="filter-wrapper clearfix">
				<div class="pull-right">
					<strong><?php 
            echo theme_locals("tags");
            ?>
: </strong>
					<ul id="tags" class="filter nav nav-pills">
						<?php 
            // query
            $args = array('post_type' => 'portfolio', 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'name', 'order' => 'ASC', 'suppress_filters' => $suppress_filters);
            $portfolio_posts = get_posts($args);
            foreach ($portfolio_posts as $k => $portfolio) {
                // Unset not translated posts
                if (function_exists('wpml_get_language_information')) {
                    global $sitepress;
                    $check = wpml_get_language_information($portfolio->ID);
                    $language_code = substr($check['locale'], 0, 2);
                    if ($language_code != $sitepress->get_current_language()) {
                        unset($portfolio_posts[$k]);
                    }
                    // Post ID is different in a second language Solution
                    if (function_exists('icl_object_id')) {
                        $portfolio = get_post(icl_object_id($portfolio->ID, 'portfolio', true));
                    }
                }
            }
            $count_posts = count($portfolio_posts);
            ?>

						<li class="active"><a href="#" data-count="<?php 
            echo $count_posts;
 function mini_posts_grid_shortcode($atts, $content = null)
 {
     extract(shortcode_atts(array('type' => 'post', 'numb' => '8', 'thumbs' => '', 'thumb_width' => '', 'thumb_height' => '', 'order_by' => 'date', 'order' => 'DESC', 'align' => '', 'custom_class' => ''), $atts));
     $template_url = get_stylesheet_directory_uri();
     // check what order by method user selected
     switch ($order_by) {
         case 'date':
             $order_by = 'post_date';
             break;
         case 'title':
             $order_by = 'title';
             break;
         case 'popular':
             $order_by = 'comment_count';
             break;
         case 'random':
             $order_by = 'rand';
             break;
     }
     // check what order method user selected (DESC or ASC)
     switch ($order) {
         case 'DESC':
             $order = 'DESC';
             break;
         case 'ASC':
             $order = 'ASC';
             break;
     }
     // thumbnail size
     $thumb_x = 0;
     $thumb_y = 0;
     if ($thumb_width != '' && $thumb_height != '') {
         $thumbs = 'custom_thumb';
         $thumb_x = $thumb_width;
         $thumb_y = $thumb_height;
     } else {
         switch ($thumbs) {
             case 'small':
                 $thumb_x = 110;
                 $thumb_y = 110;
                 break;
             case 'smaller':
                 $thumb_x = 90;
                 $thumb_y = 90;
                 break;
             case 'smallest':
                 $thumb_x = 60;
                 $thumb_y = 60;
                 break;
         }
     }
     global $post;
     global $my_string_limit_words;
     // WPML filter
     $suppress_filters = get_option('suppress_filters');
     $args = array('post_type' => $type, 'numberposts' => $numb, 'orderby' => $order_by, 'order' => $order, 'suppress_filters' => $suppress_filters);
     $posts = get_posts($args);
     $i = 0;
     $output = '<ul class="mini-posts-grid grid-align-' . $align . ' unstyled ' . $custom_class . '">';
     foreach ($posts as $key => $post) {
         // Unset not translated posts
         if (function_exists('wpml_get_language_information')) {
             global $sitepress;
             $check = wpml_get_language_information($post->ID);
             $language_code = substr($check['locale'], 0, 2);
             if ($language_code != $sitepress->get_current_language()) {
                 unset($posts[$key]);
             }
             // Post ID is different in a second language Solution
             if (function_exists('icl_object_id')) {
                 $post = get_post(icl_object_id($post->ID, $type, true));
             }
         }
         setup_postdata($post);
         $excerpt = get_the_excerpt();
         $attachment_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
         $url = $attachment_url['0'];
         $image = aq_resize($url, $thumb_x, $thumb_y, true);
         $mediaType = get_post_meta($post->ID, 'tz_portfolio_type', true);
         $prettyType = 0;
         $output .= '<li class="' . $thumbs . '">';
         if (has_post_thumbnail($post->ID) && $mediaType == 'Image') {
             $prettyType = 'prettyPhoto';
             $output .= '<figure class="featured-thumbnail thumbnail">';
             $output .= '<a href="' . $url . '" title="' . get_the_title($post->ID) . '" rel="' . $prettyType . '">';
             $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             $output .= '<span class="zoom-icon"></span></a></figure>';
         } elseif ($mediaType != 'Video' && $mediaType != 'Audio') {
             $thumbid = 0;
             $thumbid = get_post_thumbnail_id($post->ID);
             $images = get_children(array('orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, 'numberposts' => -1));
             if ($images) {
                 $k = 0;
                 //looping through the images
                 foreach ($images as $attachment_id => $attachment) {
                     $prettyType = "prettyPhoto[gallery" . $i . "]";
                     //if( $attachment->ID == $thumbid ) continue;
                     $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
                     // returns an array
                     $img = aq_resize($image_attributes[0], $thumb_x, $thumb_y, true);
                     //resize & crop img
                     $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                     $image_title = $attachment->post_title;
                     if ($k == 0) {
                         if (has_post_thumbnail($post->ID)) {
                             $output .= '<figure class="featured-thumbnail thumbnail">';
                             $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post->ID) . '" rel="' . $prettyType . '">';
                             $output .= '<img src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                         } else {
                             $output .= '<figure class="featured-thumbnail thumbnail">';
                             $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post->ID) . '" rel="' . $prettyType . '">';
                             $output .= '<img  src="' . $img . '" alt="' . get_the_title($post->ID) . '" />';
                         }
                     } else {
                         $output .= '<figure class="featured-thumbnail thumbnail" style="display:none;">';
                         $output .= '<a href="' . $image_attributes[0] . '" title="' . get_the_title($post->ID) . '" rel="' . $prettyType . '">';
                     }
                     $output .= '<span class="zoom-icon"></span></a></figure>';
                     $k++;
                 }
             } elseif (has_post_thumbnail($post->ID)) {
                 $prettyType = 'prettyPhoto';
                 $output .= '<figure class="featured-thumbnail thumbnail">';
                 $output .= '<a href="' . $url . '" title="' . get_the_title($post->ID) . '" rel="' . $prettyType . '">';
                 $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
                 $output .= '<span class="zoom-icon"></span></a></figure>';
             } else {
                 // empty_featured_thumb.gif - for post without featured thumbnail
                 $output .= '<figure class="featured-thumbnail thumbnail">';
                 $output .= '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
                 $output .= '<img  src="' . $template_url . '/images/empty_thumb.gif" alt="' . get_the_title($post->ID) . '" />';
                 $output .= '</a></figure>';
             }
         } else {
             // for Video and Audio post format - no lightbox
             $output .= '<figure class="featured-thumbnail thumbnail"><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">';
             $output .= '<img  src="' . $image . '" alt="' . get_the_title($post->ID) . '" />';
             $output .= '</a></figure>';
         }
         $output .= '</li>';
         $i++;
     }
     // end foreach
     $output .= '</ul><!-- .posts-grid (end) -->';
     $output .= '<div class="clear"></div>';
     return $output;
 }
Esempio n. 20
0
				});
			}
		});
//    });
</script>

<div id="camera<?php 
echo $motopress_cam_id;
?>
" class="camera_wrap camera">
	<?php 
foreach ($slides as $k => $slide) {
    // Unset not translated posts
    if (function_exists('wpml_get_language_information')) {
        global $sitepress;
        $check = wpml_get_language_information($slide->ID);
        $language_code = substr($check['locale'], 0, 2);
        if ($language_code != $sitepress->get_current_language()) {
            unset($slides[$k]);
        }
        // Post ID is different in a second language Solution
        if (function_exists('icl_object_id')) {
            $slide = get_post(icl_object_id($slide->ID, 'slider', true));
        }
    }
    $caption = get_post_meta($slide->ID, 'my_slider_caption', true);
    $url = get_post_meta($slide->ID, 'my_slider_url', true);
    $sl_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($slide->ID), 'slider-post-thumbnail');
    $sl_small_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($slide->ID), 'slider-thumb');
    $banner_animation = of_get_option('sl_banner');
    if (has_post_thumbnail($slide->ID)) {
Esempio n. 21
0
/**
 * Retrieve the current locale
 *
 * @param array $object Details of current post.
 * @param string $field_name Name of field.
 * @param WP_REST_Request $request Current request
 *
 * @return mixed
 */
function wpmlretapi_slug_get_current_locale($object, $field_name, $request)
{
    $langInfo = wpml_get_language_information($object);
    return $langInfo['locale'];
}