Пример #1
0
function afg_display_gallery($atts)
{
    global $size_heading_map, $afg_text_color_map, $pf;
    if (!get_option('afg_pagination')) {
        update_option('afg_pagination', 'on');
    }
    extract(shortcode_atts(array('id' => '0'), $atts));
    $cur_page = 1;
    $cur_page_url = afg_get_cur_url();
    preg_match("/afg{$id}_page_id=(?P<page_id>\\d+)/", $cur_page_url, $matches);
    if ($matches) {
        $cur_page = $matches['page_id'];
        $match_pos = strpos($cur_page_url, "afg{$id}_page_id={$cur_page}") - 1;
        $cur_page_url = substr($cur_page_url, 0, $match_pos);
        if (function_exists('qtrans_convertURL')) {
            $cur_page_url = qtrans_convertURL($cur_page_url);
        }
    }
    if (strpos($cur_page_url, '?') === false) {
        $url_separator = '?';
    } else {
        $url_separator = '&';
    }
    $galleries = get_option('afg_galleries');
    if (!isset($galleries) || array_key_exists($id, $galleries) == false) {
        return afg_error("Gallery ID {$id} has been either deleted or not configured.");
    }
    $gallery = $galleries[$id];
    $api_key = get_option('afg_api_key');
    $user_id = get_option('afg_user_id');
    $disable_slideshow = get_afg_option($gallery, 'slideshow_option') == 'disable';
    $slideshow_option = get_afg_option($gallery, 'slideshow_option');
    $per_page = get_afg_option($gallery, 'per_page');
    $sort_order = get_afg_option($gallery, 'sort_order');
    $photo_size = get_afg_option($gallery, 'photo_size');
    $photo_title = get_afg_option($gallery, 'captions');
    $photo_descr = get_afg_option($gallery, 'descr');
    $bg_color = get_afg_option($gallery, 'bg_color');
    $columns = get_afg_option($gallery, 'columns');
    $credit_note = get_afg_option($gallery, 'credit_note');
    $gallery_width = get_afg_option($gallery, 'width');
    $pagination = get_afg_option($gallery, 'pagination');
    $cache_refresh_interval = get_afg_option($gallery, 'cache_refresh_interval');
    if ($photo_size == 'custom') {
        $custom_size = get_afg_option($gallery, 'custom_size');
        $custom_size_square = get_afg_option($gallery, 'custom_size_square');
        if ($custom_size <= 70) {
            $photo_size = '_s';
        } else {
            if ($custom_size <= 90) {
                $photo_size = '_t';
            } else {
                if ($custom_size <= 220) {
                    $photo_size = '_m';
                } else {
                    if ($custom_size <= 500) {
                        $photo_size = 'NULL';
                    }
                }
            }
        }
    } else {
        $custom_size = 0;
        $custom_size_square = 'false';
    }
    $photoset_id = NULL;
    $gallery_id = NULL;
    $group_id = NULL;
    $tags = NULL;
    $popular = false;
    if (!isset($gallery['photo_source'])) {
        $gallery['photo_source'] = 'photostream';
    }
    if ($gallery['photo_source'] == 'photoset') {
        $photoset_id = $gallery['photoset_id'];
    } else {
        if ($gallery['photo_source'] == 'gallery') {
            $gallery_id = $gallery['gallery_id'];
        } else {
            if ($gallery['photo_source'] == 'group') {
                $group_id = $gallery['group_id'];
            } else {
                if ($gallery['photo_source'] == 'tags') {
                    $tags = $gallery['tags'];
                } else {
                    if ($gallery['photo_source'] == 'popular') {
                        $popular = true;
                    }
                }
            }
        }
    }
    $extras = 'url_l, description, date_upload, date_taken, owner_name';
    if (!DEBUG) {
        $photos = get_transient('afg_id_' . $id);
    }
    if ($photos === false) {
        $photos = array();
        if (isset($photoset_id) && $photoset_id) {
            $rsp_obj = $pf->photosets_getInfo($photoset_id);
            if ($pf->error_code) {
                return afg_error($pf->error_msg);
            }
            $total_photos = $rsp_obj['photos'];
        } else {
            if (isset($gallery_id) && $gallery_id) {
                $rsp_obj = $pf->galleries_getInfo($gallery_id);
                if ($pf->error_code) {
                    return afg_error($pf->error_msg);
                }
                $total_photos = $rsp_obj['gallery']['count_photos']['_content'];
            } else {
                if (isset($group_id) && $group_id) {
                    $rsp_obj = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, NULL, 1, 1);
                    if ($pf->error_code) {
                        return afg_error($pf->error_msg);
                    }
                    $total_photos = $rsp_obj['photos']['total'];
                    if ($total_photos > 500) {
                        $total_photos = 500;
                    }
                } else {
                    if (isset($tags) && $tags) {
                        $rsp_obj = $pf->photos_search(array('user_id' => $user_id, 'tags' => $tags, 'extras' => $extras, 'per_page' => 1));
                        if ($pf->error_code) {
                            return afg_error($pf->error_msg);
                        }
                        $total_photos = $rsp_obj['photos']['total'];
                    } else {
                        if (isset($popular) && $popular) {
                            $rsp_obj = $pf->photos_search(array('user_id' => $user_id, 'sort' => 'interestingness-desc', 'extras' => $extras, 'per_page' => 1));
                            if ($pf->error_code) {
                                return afg_error($pf->error_msg);
                            }
                            $total_photos = $rsp_obj['photos']['total'];
                        } else {
                            $rsp_obj = $pf->people_getInfo($user_id);
                            if ($pf->error_code) {
                                return afg_error($pf->error_msg);
                            }
                            $total_photos = $rsp_obj['photos']['count']['_content'];
                        }
                    }
                }
            }
        }
        for ($i = 1; $i < $total_photos / 500 + 1; $i++) {
            if ($photoset_id) {
                $flickr_api = 'photoset';
                $rsp_obj_total = $pf->photosets_getPhotos($photoset_id, $extras, NULL, 500, $i);
                if ($pf->error_code) {
                    return afg_error($pf->error_msg);
                }
            } else {
                if ($gallery_id) {
                    $flickr_api = 'photos';
                    $rsp_obj_total = $pf->galleries_getPhotos($gallery_id, $extras, 500, $i);
                    if ($pf->error_code) {
                        return afg_error($pf->error_msg);
                    }
                } else {
                    if ($group_id) {
                        $flickr_api = 'photos';
                        $rsp_obj_total = $pf->groups_pools_getPhotos($group_id, NULL, NULL, NULL, $extras, 500, $i);
                        if ($pf->error_code) {
                            return afg_error($pf->error_msg);
                        }
                    } else {
                        if ($tags) {
                            $flickr_api = 'photos';
                            $rsp_obj_total = $pf->photos_search(array('user_id' => $user_id, 'tags' => $tags, 'extras' => $extras, 'per_page' => 500, 'page' => $i));
                            if ($pf->error_code) {
                                return afg_error($pf->error_msg);
                            }
                        } else {
                            if ($popular) {
                                $flickr_api = 'photos';
                                $rsp_obj_total = $pf->photos_search(array('user_id' => $user_id, 'sort' => 'interestingness-desc', 'extras' => $extras, 'per_page' => 500, 'page' => $i));
                                if ($pf->error_code) {
                                    return afg_error($pf->error_msg);
                                }
                            } else {
                                $flickr_api = 'photos';
                                if (get_option('afg_flickr_token')) {
                                    $rsp_obj_total = $pf->people_getPhotos($user_id, array('extras' => $extras, 'per_page' => 500, 'page' => $i));
                                } else {
                                    $rsp_obj_total = $pf->people_getPublicPhotos($user_id, NULL, $extras, 500, $i);
                                }
                                if ($pf->error_code) {
                                    return afg_error($pf->error_msg);
                                }
                            }
                        }
                    }
                }
            }
            $photos = array_merge($photos, $rsp_obj_total[$flickr_api]['photo']);
        }
        if (!DEBUG) {
            set_transient('afg_id_' . $id, $photos, afg_get_cache_refresh_interval_secs($cache_refresh_interval));
        }
    } else {
        $total_photos = count($photos);
    }
    if ($total_photos % $per_page == 0) {
        $total_pages = (int) ($total_photos / $per_page);
    } else {
        $total_pages = (int) ($total_photos / $per_page) + 1;
    }
    if ($gallery_width == 'auto') {
        $gallery_width = 100;
    }
    $text_color = isset($afg_text_color_map[$bg_color]) ? $afg_text_color_map[$bg_color] : '';
    $disp_gallery .= "<div class='afg-gallery' id='afg-{$id}'>";
    if ($slideshow_option == 'highslide') {
        $photo_count = 1;
    }
    if (!$popular && $sort_order != 'flickr') {
        if ($sort_order == 'random') {
            shuffle($photos);
        } else {
            usort($photos, $sort_order);
        }
    }
    if ($disable_slideshow) {
        $class = '';
        $rel = '';
        $click_event = '';
    } else {
        if ($slideshow_option == 'colorbox') {
            $class = "class='afgcolorbox'";
            $rel = "rel='example4{$id}'";
            $click_event = "";
        } else {
            if ($slideshow_option == 'highslide') {
                $class = "class='highslide'";
                $rel = "";
                $click_event = "onclick='return hs.expand(this, {slideshowGroup: {$id} })'";
            } else {
                if ($slideshow_option == 'flickr') {
                    $class = "";
                    $rel = "";
                    $click_event = "target='_blank'";
                }
            }
        }
    }
    if ($photo_size == '_s') {
        $photo_width = "width='75'";
        $photo_height = "height='75'";
    } else {
        $photo_width = '';
        $photo_height = '';
    }
    foreach ($photos as $pid => $photo) {
        $p_title = esc_attr($photo['title']);
        $p_description = esc_attr($photo['description']['_content']);
        $p_description = preg_replace("/\n/", "<br />", $p_description);
        $photo_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], $photo_size);
        if ($slideshow_option != 'none') {
            if (isset($photo['url_l']) ? $photo['url_l'] : '') {
                $photo_page_url = $photo['url_l'];
            } else {
                $photo_page_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], '_z');
            }
            if ($photoset_id) {
                $photo['owner'] = $user_id;
            }
            $photo_title_text = $p_title;
            if ($slideshow_option == 'highslide' && $p_description) {
                $photo_title_text .= '<br /><span>' . $p_description . '</span>';
            }
            $photo_title_text .= ' • <a href="https://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" target="_blank">View on Flickr</a>';
            $photo_title_text = esc_attr($photo_title_text);
            if ($slideshow_option == 'flickr') {
                $photo_page_url = "https://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'];
            }
        }
        if ($photo_count <= $per_page * $cur_page && $photo_count > $per_page * ($cur_page - 1)) {
            $pid_len = strlen($photo['id']);
            if ($slideshow_option != 'none') {
                $disp_gallery .= "<a {$class} {$rel} {$click_event} href='{$photo_page_url}' title='{$photo['title']}'>";
            }
            if ($custom_size) {
                $timthumb_script = BASE_URL . "/afg_img_rsz.php?src=";
                if ($photo['width_l'] > $photo['height_l']) {
                    $timthumb_params = "&q=100&w={$custom_size}";
                    if ($custom_size_square == 'true') {
                        $timthumb_params .= "&h={$custom_size}";
                    }
                } else {
                    $timthumb_params = "&q=100&h={$custom_size}";
                    if ($custom_size_square == 'true') {
                        $timthumb_params .= "&w={$custom_size}";
                    }
                }
            } else {
                $timthumb_script = "";
                $timthumb_params = "";
            }
            $disp_gallery .= "<img title='{$photo['title']}' src='{$timthumb_script}{$photo_url}{$timthumb_params}' alt='{$photo_title_text}'/>";
            if ($slideshow_option != 'none') {
                $disp_gallery .= "</a>";
            }
            if ($size_heading_map[$photo_size] && $photo_title == 'on') {
                if ($group_id || $gallery_id) {
                    $owner_title = "- by <a href='https://www.flickr.com/photos/{$photo['owner']}/' target='_blank'>{$photo['ownername']}</a>";
                } else {
                    $owner_title = '';
                }
                $disp_gallery .= "<div class='afg-title'>{$p_title} {$owner_title}</div>";
            }
            if ($photo_descr == 'on' && $photo_size != '_s' && $photo_size != '_t') {
                $disp_gallery .= "<div class='afg-description'>" . $photo['description']['_content'] . "</div>";
            }
        } else {
            if ($pagination == 'on' && $slideshow_option != 'none') {
                if ($slideshow_option == 'highslide') {
                    $photo_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], '_s');
                } else {
                    $photo_url = '';
                }
                if ($slideshow_option == 'highslide') {
                    $photo_src_text = "src='{$photo_url}'";
                } else {
                    $photo_src_text = "";
                }
                $disp_gallery .= "<a style='display:none' {$class} {$rel} {$click_event} href='{$photo_page_url}'" . " title='{$photo['title']}'>" . " <img class='afg-img' alt='{$photo_title_text}' {$photo_src_text} width='75' height='75'></a> ";
            }
        }
        $photo_count += 1;
    }
    // Pagination
    if ($pagination == 'on' && $total_pages > 1) {
        $disp_gallery .= "<div class='afg-pagination'>";
        if ($cur_page == 1) {
            $disp_gallery .= "<span>&#171; prev </span>";
            $disp_gallery .= "<span class='afg-cur-page'> 1 </span>";
        } else {
            $prev_page = $cur_page - 1;
            $disp_gallery .= "<a href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$prev_page}#afg-{$id}' title='Prev Page'>&nbsp;&#171; prev </a>&nbsp;&nbsp;&nbsp;&nbsp;";
            $disp_gallery .= "<a href='{$cur_page_url}{$url_separator}afg{$id}_page_id=1#afg-{$id}' title='Page 1'> 1 </a>&nbsp;";
        }
        if ($cur_page - 2 > 2) {
            $start_page = $cur_page - 2;
            $end_page = $cur_page + 2;
            $disp_gallery .= " ... ";
        } else {
            $start_page = 2;
            $end_page = 6;
        }
        for ($count = $start_page; $count <= $end_page; $count += 1) {
            if ($count > $total_pages) {
                break;
            }
            if ($cur_page == $count) {
                $disp_gallery .= "<span>{$count}</span>";
            } else {
                $disp_gallery .= "<a href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$count}#afg-{$id}' title='Page {$count}'>&nbsp;{$count} </a>&nbsp;";
            }
        }
        if ($count < $total_pages) {
            $disp_gallery .= " ... ";
        }
        if ($count <= $total_pages) {
            $disp_gallery .= "<a href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$total_pages}#afg-{$id}' title='Page {$total_pages}'>&nbsp;{$total_pages} </a>";
        }
        if ($cur_page == $total_pages) {
            $disp_gallery .= "<span>next &#187;</span>";
        } else {
            $next_page = $cur_page + 1;
            $disp_gallery .= "<a class='afg-page' href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$next_page}#afg-{$id}' title='Next Page'> next &#187; </a>";
        }
        $disp_gallery .= "<br />({$total_photos} Photos)";
        $disp_gallery .= "</div>";
    }
    if ($credit_note == 'on') {
        $disp_gallery .= "<div class='afg-credit'>Powered by " . "<a href='http://www.ronakg.com/projects/awesome-flickr-gallery-wordpress-plugin'" . "title='Awesome Flickr Gallery by Ronak Gandhi'/>AFG</a>";
        $disp_gallery .= "</div>";
    }
    $disp_gallery .= "</div>";
    return $disp_gallery;
}
Пример #2
0
function afg_display_gallery($atts)
{
    global $size_heading_map, $afg_text_color_map, $pf, $wpdb;
    wp_enqueue_script('ajax-afg_report_scripts');
    if (!get_option('afg_pagination')) {
        update_option('afg_pagination', 'on');
    }
    $rset = array('used' => array(), 'min' => 1, 'max' => 8);
    extract(shortcode_atts(array('id' => '0'), $atts));
    $disp_singleuser = array();
    if (isset($_REQUEST['id'])) {
        $did = intval($_REQUEST['id']);
        $dtype = '';
        if ($_REQUEST['type'] == 'c') {
            $dtype = 'c';
            $row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' AND id='" . intval($_REQUEST['id']) . "'");
        } elseif ($_REQUEST['type'] == 't') {
            $dtype = 't';
            $row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}flickrtwins  WHERE published = '1' AND id='" . intval($_REQUEST['id']) . "'");
        } else {
            $dtype = 'u';
            $row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}flickruploads  WHERE status <> '-1' AND id='" . intval($_REQUEST['id']) . "'");
        }
        if ($row !== null) {
            $owner = get_option('afg_user_id');
            if (isset($_REQUEST['showtwin'])) {
                $twin = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}flickrtwins  WHERE published = '1' AND id='" . intval($row->twinlid) . "'");
                $disp_singleuser[0] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'twin' => $row->twinlid, 'twinid' => $twin->photoid, 'twinsecret' => $twin->photosecret, 'twinfarm' => $twin->farm, 'twinserver' => $twin->server, 'twintitle' => stripslashes(substr(strip_tags($twin->imagetitle), 0, 80)), 'twindescription' => array('_content' => stripslashes(substr(strip_tags($twin->imagestory), 0, 200))), 'flatid' => $row->flatid, 'flatsecret' => $row->flatsecret, 'flatfarm' => $row->flatfarm, 'flatserver' => $row->flatserver, 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'did' => $row->id, 'dtype' => $dtype, 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
            } else {
                $disp_singleuser[0] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'did' => $row->id, 'dtype' => $dtype, 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
            }
        } else {
            //klaxon - this image has been banned or does not exist
        }
    }
    $cur_page = 1;
    $cur_page_url = afg_get_cur_url();
    preg_match("/afg{$id}_page_id=(?P<page_id>\\d+)/", $cur_page_url, $matches);
    if ($matches) {
        $cur_page = $matches['page_id'];
        $match_pos = strpos($cur_page_url, "afg{$id}_page_id={$cur_page}") - 1;
        $cur_page_url = substr($cur_page_url, 0, $match_pos);
        if (function_exists('qtrans_convertURL')) {
            $cur_page_url = qtrans_convertURL($cur_page_url);
        }
    }
    if (strpos($cur_page_url, '?') === false) {
        $url_separator = '?';
    } else {
        $url_separator = '&';
    }
    $galleries = get_option('afg_galleries');
    $gallery = $galleries[$id];
    $api_key = get_option('afg_api_key');
    $user_id = get_option('afg_user_id');
    $disable_slideshow = get_afg_option($gallery, 'slideshow_option') == 'disable';
    $slideshow_option = get_afg_option($gallery, 'slideshow_option');
    $per_page = get_afg_option($gallery, 'per_page');
    $sort_order = get_afg_option($gallery, 'sort_order');
    $photo_size = get_afg_option($gallery, 'photo_size');
    $photo_title = get_afg_option($gallery, 'captions');
    $photo_descr = get_afg_option($gallery, 'descr');
    $bg_color = get_afg_option($gallery, 'bg_color');
    $columns = get_afg_option($gallery, 'columns');
    $credit_note = get_afg_option($gallery, 'credit_note');
    $gallery_width = get_afg_option($gallery, 'width');
    $pagination = get_afg_option($gallery, 'pagination');
    if ($photo_size == 'custom') {
        $custom_size = get_afg_option($gallery, 'custom_size');
        $custom_size_square = get_afg_option($gallery, 'custom_size_square');
        if ($custom_size <= 70) {
            $photo_size = '_s';
        } else {
            if ($custom_size <= 90) {
                $photo_size = '_t';
            } else {
                if ($custom_size <= 220) {
                    $photo_size = '_m';
                } else {
                    if ($custom_size <= 500) {
                        $photo_size = 'NULL';
                    }
                }
            }
        }
    } else {
        $custom_size = 0;
        $custom_size_square = 'false';
    }
    $photoset_id = NULL;
    $gallery_id = NULL;
    $group_id = NULL;
    $tags = NULL;
    $popular = false;
    $users = false;
    $celebs = false;
    $userscelebs = false;
    $disp_gallery = '';
    $extras = 'url_l, description, date_upload, date_taken, owner_name';
    $total_photos = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickruploads  WHERE status <> '-1' ");
    $total_photos += $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' ");
    $total_photos += $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickrtwins  WHERE published = '1' ");
    if (isset($_REQUEST['sport']) && intval($_REQUEST['sport']) != 0 || isset($_REQUEST['category']) && $_REQUEST['category'] != '') {
        $total_photos = 0;
        if (isset($_REQUEST['category']) && $_REQUEST['category'] != '') {
            $whereit = '';
            if ($_REQUEST['sport'] != '' && intval($_REQUEST['sport']) != 0) {
                $whereit = " AND sport='" . intval($_REQUEST['sport']) . "' ";
            }
            if ($_REQUEST['category'] == 'child') {
                $total_photos += $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickrtwins  WHERE published = '1'" . $whereit);
            }
            if ($_REQUEST['category'] == 'ambassador') {
                $total_photos += $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' AND unicef='1'" . $whereit);
            }
            if ($_REQUEST['category'] == 'supporter') {
                $total_photos += $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' AND unicef='0'" . $whereit);
            }
        } else {
            $whereit = '';
            if ($_REQUEST['sport'] != '' && intval($_REQUEST['sport']) != 0) {
                $whereit = " AND sport='" . intval($_REQUEST['sport']) . "' ";
            }
            $total_photos = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}flickruploads  WHERE status <> '-1' " . $whereit);
        }
    } else {
        if (isset($disp_singleuser['id']) && (!isset($_REQUEST['page_id']) || $_REQUEST['page_id'] == 1)) {
            $total_photos += 1;
        }
    }
    $photos = get_transient('afg_id_' . $id);
    if (DEBUG || isset($_GET['id']) && intval($_GET['id']) > 0) {
        $photos = NULL;
    }
    $flickr_api = 'photos';
    $rsp_obj_total[$flickr_api] = array();
    $rsp_obj_total[$flickr_api]['photo'] = array();
    $twins = array();
    if ($photos == false || $total_photos != count($photos)) {
        $photos = array();
        for ($i = 1; $i < $total_photos / 500 + 1; $i++) {
            $flickr_api = 'photos';
            if (isset($_REQUEST['category']) && $_REQUEST['category'] != '') {
                $owner = get_option('afg_user_id');
                $kids = array();
                $celebs = array();
                $whereit = '';
                if ($_REQUEST['sport'] != '' && intval($_REQUEST['sport']) != 0) {
                    $whereit = " AND sport='" . intval($_REQUEST['sport']) . "' ";
                }
                $rows = null;
                if ($_REQUEST['category'] == 'ambassador') {
                    $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' AND unicef='1'" . $whereit . " ORDER BY RAND()  ");
                } else {
                    $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1' AND unicef='0'" . $whereit . " ORDER BY RAND()  ");
                }
                if ($_REQUEST['category'] != 'child') {
                    foreach ($rows as $row) {
                        if (isset($disp_singleuser[0]['did']) && ($disp_singleuser[0]['did'] == $row->id && $disp_singleuser[0]['dtype'] == 'c')) {
                            continue;
                        }
                        $celebs[] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'did' => $row->id, 'dtype' => 'c', 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
                    }
                }
                if ($_REQUEST['category'] == 'child') {
                    $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickrtwins  WHERE published = '1'" . $whereit . " ORDER BY RAND()  ");
                    foreach ($rows as $row) {
                        if (isset($disp_singleuser[0]['did']) && ($disp_singleuser[0]['did'] == $row->id && $disp_singleuser[0]['dtype'] == 't')) {
                            continue;
                        }
                        $twins[$row->id] = $row;
                        $kids[] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'did' => $row->id, 'dtype' => 't', 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
                    }
                }
                if (count($celebs) > 0) {
                    $rset = rando($rset);
                    if (count($celebs) > 1) {
                        $count = 1;
                        foreach ($celebs as $key => $celeb) {
                            if ($count > 2) {
                                $rset['min'] = 8;
                                $rset['max'] = count($rsp_obj_total[$flickr_api]);
                            }
                            $rset = rando($rset);
                            array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($celeb));
                            unset($celebs[$key]);
                        }
                    } else {
                        array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($celebs[0]));
                        unset($celebs[0]);
                    }
                }
                if (count($kids) > 0) {
                    $rset['min'] = 1;
                    $rset['max'] = 8;
                    $rset = rando($rset);
                    if (count($kids) > 1) {
                        $count = 1;
                        foreach ($kids as $key => $kid) {
                            if ($count > 2) {
                                $rset['min'] = 8;
                                $rset['max'] = count($rsp_obj_total[$flickr_api]);
                            }
                            $rset = rando($rset);
                            array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($kid));
                            unset($kids[$key]);
                        }
                    }
                }
                //print_R($rsp_obj_total[$flickr_api]);
            } else {
                $owner = get_option('afg_user_id');
                $kids = array();
                $celebs = array();
                $whereit = '';
                if ($_REQUEST['sport'] != '' && intval($_REQUEST['sport']) != 0) {
                    $whereit = " AND sport='" . intval($_REQUEST['sport']) . "' ";
                }
                $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickrcelebs  WHERE published = '1'" . $whereit . " ORDER BY RAND()  ");
                foreach ($rows as $row) {
                    if (isset($disp_singleuser[0]['did']) && ($disp_singleuser[0]['did'] == $row->id && $disp_singleuser[0]['dtype'] == 'c')) {
                        continue;
                    }
                    $celebs[] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'did' => $row->id, 'dtype' => 'c', 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
                }
                //print_R($rsp_obj_total[$flickr_api]);
                $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickruploads  WHERE status <> '-1'" . $whereit . " ORDER BY submittedtime DESC");
                foreach ($rows as $row) {
                    /*
                    echo $disp_singleuser[0]['did'] .'|'.
                        $row->id  .'|'.
                        $disp_singleuser[0]['dtype'] ."\n";
                    */
                    if (isset($disp_singleuser[0]['did']) && ($disp_singleuser[0]['did'] == $row->id && $disp_singleuser[0]['dtype'] == 'u')) {
                        continue;
                    }
                    $rsp_obj_total[$flickr_api]['photo'][] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'did' => $row->id, 'dtype' => 'u', 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime, 'twinned' => $row->twinlid);
                }
                $rows = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}flickrtwins  WHERE published = '1'" . $whereit . " ORDER BY RAND()  ");
                foreach ($rows as $row) {
                    if (isset($disp_singleuser[0]['did']) && ($disp_singleuser[0]['did'] == $row->id && $disp_singleuser[0]['dtype'] == 't')) {
                        continue;
                    }
                    $twins[$row->id] = $row;
                    $kids[] = array('id' => $row->photoid, 'owner' => $owner, 'secret' => $row->photosecret, 'server' => $row->server, 'farm' => $row->farm, 'title' => stripslashes(substr(strip_tags($row->imagetitle), 0, 80)), 'ispublic' => 0, 'isfriend' => 0, 'isfamily' => 0, 'description' => array('_content' => stripslashes(substr(strip_tags($row->imagestory), 0, 200))), 'did' => $row->id, 'dtype' => 't', 'dateupload' => strtotime($row->lastmodified), 'datetaken' => $row->submittedtime);
                }
                if (count($celebs) > 0) {
                    $rset = rando($rset);
                    if (count($celebs) > 1) {
                        $count = 1;
                        foreach ($celebs as $key => $celeb) {
                            if ($count > 2) {
                                $rset['min'] = 8;
                                $rset['max'] = count($rsp_obj_total[$flickr_api]);
                            }
                            $rset = rando($rset);
                            if (count($rsp_obj_total[$flickr_api]['photo']) > 0) {
                                array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($celeb));
                            } else {
                                array_splice($rsp_obj_total[$flickr_api], $rset['chose'], 0, $celeb);
                            }
                            unset($celebs[$key]);
                        }
                    } else {
                        array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($celebs[0]));
                        unset($celebs[0]);
                    }
                }
                if (count($kids) > 0) {
                    $rset['min'] = 1;
                    $rset['max'] = 8;
                    $rset = rando($rset);
                    if (count($kids) > 1) {
                        $count = 1;
                        foreach ($kids as $key => $kid) {
                            if ($count > 2) {
                                $rset['min'] = 8;
                                $rset['max'] = count($rsp_obj_total[$flickr_api]);
                            }
                            $rset = rando($rset);
                            if (count($rsp_obj_total[$flickr_api]['photo']) > 0) {
                                array_splice($rsp_obj_total[$flickr_api]['photo'], $rset['chose'], 0, array($kid));
                            } else {
                                array_splice($rsp_obj_total[$flickr_api], $rset['chose'], 0, $kid);
                            }
                            unset($kids[$key]);
                        }
                    }
                }
                //print_R($rsp_obj_total[$flickr_api]);
                //$shuffled = shuffle($rsp_obj_total[$flickr_api]['photo']);
                //print_R($rsp_obj_total[$flickr_api]);
            }
            $photos = array_merge($photos, $rsp_obj_total[$flickr_api]['photo']);
        }
        //print_R($photos);
        if (isset($disp_singleuser[0]['id'])) {
            array_splice($photos, 0, 0, array($disp_singleuser[0]));
        }
        if (!DEBUG && (!isset($_GET['id']) || intval($_GET['id']) == 0)) {
            set_transient('afg_id_' . $id, $photos, 60 * 60 * 24);
        }
    }
    $ids = array();
    $tmpphotos = array();
    foreach ($photos as $photo) {
        if (!in_array($photo['id'], $ids)) {
            $ids[] = $photo['id'];
            $tmpphotos[] = $photo;
        }
    }
    $photos = $tmpphotos;
    //print_R($photos);
    if ($total_photos % $per_page == 0) {
        $total_pages = (int) ($total_photos / $per_page);
    } else {
        $total_pages = (int) ($total_photos / $per_page) + 1;
    }
    if ($gallery_width == 'auto') {
        $gallery_width = 100;
    }
    $text_color = isset($afg_text_color_map[$bg_color]) ? $afg_text_color_map[$bg_color] : '';
    $disp_gallery .= '<form class="filters">';
    $disp_gallery .= '<label for="image-filters" class="image-filters">Sort the Sport Firsts</label>';
    $disp_gallery .= '<div class="styled-select styled-select-1">';
    $disp_gallery .= '<label for="filter-sport">';
    $disp_gallery .= '<select name="filter-sport" class="filter-sport" id="image-filters">';
    $disp_gallery .= '<option class="disabled" value="" ';
    $disp_gallery .= $_REQUEST['sport'] == '' ? ' selected="selected"' : '';
    $disp_gallery .= '>Sort by sport</option>';
    $sporresults = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "flickrsports WHERE published = 1");
    foreach ($sporresults as $sprow) {
        $disp_gallery .= '<option value="' . $sprow->id . '"';
        $disp_gallery .= $sprow->id == $_REQUEST['sport'] ? ' selected="selected"' : '';
        $disp_gallery .= '>' . $sprow->sport . '</option>&gt';
    }
    $disp_gallery .= '<option value="">Show All</option>';
    $disp_gallery .= '</select>';
    $disp_gallery .= '</label>';
    $disp_gallery .= '</div>';
    $disp_gallery .= '<div class="styled-select styled-select-2">';
    $disp_gallery .= '<label for="filter-category">';
    $disp_gallery .= '<select name="filter-category" class="filter-category">';
    $disp_gallery .= '<option class="disabled" value=""';
    $disp_gallery .= $_REQUEST['category'] == '' ? ' selected="selected"' : '';
    $disp_gallery .= '>Sort by category</option>';
    $disp_gallery .= '<option value="ambassador" ';
    $disp_gallery .= 'ambassador' == $_REQUEST['category'] ? ' selected="selected"' : '';
    $disp_gallery .= '>UNICEF Celebrity Supporters</option>';
    $disp_gallery .= '<option value="supporter" ';
    $disp_gallery .= 'supporter' == $_REQUEST['category'] ? ' selected="selected"' : '';
    $disp_gallery .= '>Personalities</option>';
    $disp_gallery .= '<option value="child" ';
    $disp_gallery .= 'child' == $_REQUEST['category'] ? ' selected="selected"' : '';
    $disp_gallery .= '>UNICEF stories</option>';
    $disp_gallery .= '<option value="">Show All</option>';
    $disp_gallery .= '</select>';
    $disp_gallery .= '</label>';
    $disp_gallery .= '</div>';
    $disp_gallery .= '</form>';
    $disp_gallery .= '<div class="afg-gallery custom-gallery-' . $id . '" id="afg-' . $id . '" style="background-color:' . $bg_color . '; width:' . $gallery_width . '%; color:' . $text_color . '; border-color:' . $bg_color . ';">';
    if ($slideshow_option == 'highslide') {
        $disp_gallery .= '<div class="highslide-gallery">';
    }
    if ($slideshow_option == 'googleimage') {
        $disp_gallery .= '<div class="og-grid">';
    } else {
        $disp_gallery .= '<div class="afg-table" style="width:100%">';
    }
    $photo_count = 1;
    $column_width = (int) ($gallery_width / $columns);
    if ($disable_slideshow) {
        $class = '';
        $rel = '';
        $click_event = '';
    } else {
        if ($slideshow_option == 'colorbox') {
            $class = 'class="afgcolorbox"';
            $rel = 'rel="example4' . $id . '"';
            $click_event = "";
        } else {
            if ($slideshow_option == 'highslide') {
                $class = 'class="highslide"';
                $rel = "";
                $click_event = 'onclick="return hs.expand(this, {slideshowGroup: ' . $id . ' })"';
            } else {
                if ($slideshow_option == 'flickr') {
                    $class = "";
                    $rel = "";
                    $click_event = 'target="_blank"';
                } else {
                    if ($slideshow_option == 'googleimage') {
                        $class = '';
                        $rel = "";
                        $click_event = "";
                    }
                }
            }
        }
    }
    if ($photo_size == '_s') {
        $photo_width = "width='75'";
        $photo_height = "height='75'";
    } else {
        $photo_width = '';
        $photo_height = '';
    }
    $cur_col = 0;
    //print_R($photos);
    if ($total_photos == 0) {
        $disp_gallery .= 'Sorry &ndash; no images available';
    }
    foreach ($photos as $pid => $photo) {
        $p_title = esc_attr($photo['title']);
        $p_description = esc_attr($photo['description']['_content']);
        $p_description = preg_replace("/\n/", "<br />", $p_description);
        $photo_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], $photo_size);
        if ($slideshow_option != 'none') {
            if (isset($photo['url_l']) ? $photo['url_l'] : '') {
                $photo_page_url = $photo['url_l'];
            } else {
                $photo_page_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], '_z');
            }
            if ($photoset_id) {
                $photo['owner'] = $user_id;
            }
            $photo_title_text = $p_title;
            if ($slideshow_option == 'highslide' && $p_description) {
                $photo_title_text .= '<br /><span style="font-size:0.8em;">' . $p_description . '</span>';
            }
            //$photo_title_text .= ' • <a style="font-size:0.8em;" href="http://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" target="_blank">View on Flickr</a>';
            $photo_title_text = esc_attr($photo_title_text);
            if ($slideshow_option == 'flickr') {
                $photo_page_url = "http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'];
            }
        } else {
            $photo_title_text = '';
        }
        //if ($cur_col % $columns == 0) $disp_gallery .= "<div class='afg-row'>";
        if ($photo_count <= $per_page * $cur_page && $photo_count > $per_page * ($cur_page - 1)) {
            $percentpercolumn = floor(100 / $columns);
            $mobile = $percentpercolumn;
            if ($percentpercolumn * 2 <= 100) {
                $mobile = $percentpercolumn * 2;
            }
            $extraclass = '';
            if ($slideshow_option == 'googleimage') {
                $extraclass = 'og-child';
            } else {
                $extraclass = 'afg-cell';
            }
            if ($cur_col % $columns == 0) {
                $disp_gallery .= "<div class='grid-" . $percentpercolumn . " " . $extraclass . " mobile-grid-50 first' >";
            } elseif ($cur_col % $columns == $columns - 1) {
                $disp_gallery .= "<div class='grid-" . $percentpercolumn . " " . $extraclass . " mobile-grid-50 last'>";
            } else {
                $disp_gallery .= "<div class='grid-" . $percentpercolumn . " " . $extraclass . " mobile-grid-50' >";
            }
            $pid_len = strlen($photo['id']);
            //print_R($kids[$photo['twinned']]);
            if ($slideshow_option == 'googleimage') {
                $lrg_photo_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], null);
                if (isset($photo['twin']) && $_REQUEST['id'] == $photo['did'] && $_REQUEST['showtwin'] == 1) {
                    $twn_photo_url = afg_get_photo_url($photo['twinfarm'], $photo['twinserver'], $photo['twinid'], $photo['twinsecret'], null);
                    $flat = afg_get_photo_url($photo['flatfarm'], $photo['flatserver'], $photo['flatid'], $photo['flatsecret'], null);
                    $disp_gallery .= '<a ' . $class . $rel . $click_event . ' href="' . $photo_page_url . '" title="' . htmlspecialchars($photo['title']) . '" data-did="' . $photo['did'] . '" data-dtype="' . $photo['dtype'] . '" data-largesrc="' . $lrg_photo_url . '" data-title="' . htmlspecialchars(substr(strip_tags($photo['title']), 0, 80)) . '" data-description="' . htmlspecialchars(substr(strip_tags($photo['description']['_content']), 0, 200)) . '" data-twin="' . $twn_photo_url . '" data-twintitle="' . htmlspecialchars(substr(strip_tags($photo['twintitle']), 0, 80)) . '" data-twindesc="' . htmlspecialchars(substr(strip_tags($photo['twindescription']['_content']), 0, 200)) . '" data-flat="' . $flat . '" >';
                } else {
                    $disp_gallery .= '<a ' . $class . $rel . $click_event . ' href="' . $photo_page_url . '" title="' . htmlspecialchars($photo['title']) . '" data-did="' . $photo['did'] . '" data-dtype="' . $photo['dtype'] . '" data-largesrc="' . $lrg_photo_url . '" data-title="' . htmlspecialchars(substr(strip_tags($photo['title']), 0, 80)) . '" data-description="' . htmlspecialchars(substr(strip_tags($photo['description']['_content']), 0, 200)) . '" >';
                }
            } elseif ($slideshow_option != 'none') {
                $disp_gallery .= "<a {$class} {$rel} {$click_event} href='{$photo_page_url}' title='{$photo['title']}'>";
            }
            if ($custom_size) {
                $timthumb_script = BASE_URL . "/afg_img_rsz.php?src=";
                if ($photo['width_l'] > $photo['height_l']) {
                    $timthumb_params = "&q=100&w={$custom_size}";
                    if ($custom_size_square == 'true') {
                        $timthumb_params .= "&h={$custom_size}";
                    }
                } else {
                    $timthumb_params = "&q=100&h={$custom_size}";
                    if ($custom_size_square == 'true') {
                        $timthumb_params .= "&w={$custom_size}";
                    }
                }
            } else {
                $timthumb_script = "";
                $timthumb_params = "";
            }
            $disp_gallery .= '<img class="afg-img" title="' . htmlspecialchars($photo['title']) . '" src="' . $timthumb_script . $photo_url . $timthumb_params . '" alt="' . htmlspecialchars($photo_title_text) . '" />';
            if ($slideshow_option != 'none') {
                $disp_gallery .= "</a>";
            }
            if ($size_heading_map[$photo_size] && $photo_title == 'on') {
                if ($group_id || $gallery_id) {
                    $owner_title = "- by <a href='http://www.flickr.com/photos/{$photo['owner']}/' target='_blank'>{$photo['ownername']}</a>";
                } else {
                    $owner_title = '';
                }
                $disp_gallery .= "<div class='afg-title' style='font-size:{$size_heading_map[$photo_size]}'>{$p_title} {$owner_title}</div>";
            }
            if ($photo_descr == 'on' && $photo_size != '_s' && $photo_size != '_t') {
                $disp_gallery .= "<div class='afg-description'>" . $photo['description']['_content'] . "</div>";
            }
            $cur_col += 1;
            $disp_gallery .= '</div>';
        } else {
            if ($pagination == 'on' && $slideshow_option != 'none') {
                if ($slideshow_option == 'highslide') {
                    $photo_url = afg_get_photo_url($photo['farm'], $photo['server'], $photo['id'], $photo['secret'], '_s');
                } else {
                    $photo_url = '';
                }
                if ($slideshow_option == 'highslide') {
                    $photo_src_text = "src='{$photo_url}'";
                } else {
                    $photo_src_text = "";
                }
                if ($slideshow_option != 'googleimage') {
                    $disp_gallery .= "<a style='display:none' {$class} {$rel} {$click_event} href='{$photo_page_url}'" . " title='{$photo['title']}'>" . ' <img class="afg-img" alt="' . $photo_title_text . '" ' . $photo_src_text . ' width="75" height="75"></a> ';
                }
            }
        }
        //if ($cur_col % $columns == 0) $disp_gallery .= '</div>';
        $photo_count += 1;
    }
    if ($cur_col % $columns != 0) {
        $disp_gallery .= '</div>';
    }
    if ($slideshow_option !== 'googleimage') {
        $disp_gallery .= '</div>';
    }
    if ($slideshow_option == 'highslide') {
        $disp_gallery .= "</div>";
    }
    // Pagination
    if ($pagination == 'on' && $total_pages > 1) {
        $disp_gallery .= "<div class='afg-pagination'>";
        if ($cur_page == 1) {
            $disp_gallery .= "<span class='afg-page afg-prev'>&nbsp;&#171; previous&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;";
            $disp_gallery .= "<span class='afg-cur-page afg-pagin'> 1 </span>&nbsp;";
        } else {
            $prev_page = $cur_page - 1;
            $disp_gallery .= "<a class='afg-page afg-prev' href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$prev_page}#afg-{$id}' title='Prev Page'>&nbsp;&#171; previous </a>&nbsp;&nbsp;&nbsp;&nbsp;";
            $disp_gallery .= "<a class='afg-page afg-pagin' href='{$cur_page_url}{$url_separator}afg{$id}_page_id=1#afg-{$id}' title='Page 1'> 1 </a>&nbsp;";
        }
        if ($cur_page - 2 > 2) {
            $start_page = $cur_page - 2;
            $end_page = $cur_page + 2;
            $disp_gallery .= " ... ";
        } else {
            $start_page = 2;
            $end_page = 6;
        }
        for ($count = $start_page; $count <= $end_page; $count += 1) {
            if ($count > $total_pages) {
                break;
            }
            if ($cur_page == $count) {
                $disp_gallery .= "<span class='afg-cur-page afg-pagin'>&nbsp;{$count}&nbsp;</span>&nbsp;";
            } else {
                $disp_gallery .= "<a class='afg-page afg-pagin' href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$count}#afg-{$id}' title='Page {$count}'>&nbsp;{$count} </a>&nbsp;";
            }
        }
        if ($count < $total_pages) {
            $disp_gallery .= " ... ";
        }
        if ($count <= $total_pages) {
            $disp_gallery .= "<a class='afg-page afg-pagin' href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$total_pages}#afg-{$id}' title='Page {$total_pages}'>&nbsp;{$total_pages} </a>&nbsp;";
        }
        if ($cur_page == $total_pages) {
            $disp_gallery .= "&nbsp;&nbsp;&nbsp;<span class='afg-page afg-next'>&nbsp;next &#187;&nbsp;</span>";
        } else {
            $next_page = $cur_page + 1;
            $disp_gallery .= "&nbsp;&nbsp;&nbsp;<a class='afg-page afg-next' href='{$cur_page_url}{$url_separator}afg{$id}_page_id={$next_page}#afg-{$id}' title='Next Page'> next &#187; </a>&nbsp;";
        }
        $disp_gallery .= "</div>";
    }
    if ($credit_note == 'on') {
        $disp_gallery .= "<br />";
        $disp_gallery .= "<div class='afg-credit'>Powered by " . "<a href='http://www.ronakg.com/projects/awesome-flickr-gallery-wordpress-plugin'" . "title='Awesome Flickr Gallery by Ronak Gandhi'/>AFG</a>";
        $disp_gallery .= "</div>";
    }
    $disp_gallery .= "</div>";
    preg_match("/afg_pic_id=((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s\"]*))/", urldecode($cur_page_url), $pmatches);
    $photoInfo = array();
    $displayImage = False;
    if ($pmatches) {
        $cur_pic = $pmatches[1];
        //echo $cur_pic;
        //$match_pos = strpos($cur_page_url, "afg{$id}_pic_id=$cur_page") - 1;
        $regexstr = '~https?:\\/\\/(?:[\\w]+\\.)*(?:flic\\.kr|flickr\\.com|staticflickr\\.com)(?:\\/photos)?\\/[^\\/]+\\/([0-9a-zA-Z]+)[^\\s]*~ix';
        preg_match_all($regexstr, $cur_pic, $jmatches, PREG_SET_ORDER);
        //print_R($jmatches);
        $photoID = $jmatches[0][1];
        if (strpos($jmatches[0][0], "flic.kr") !== false) {
            $photoID = $flickrDecode($photoID);
        }
        //echo $photoID;
        $displayImage = True;
        $photoInfo = $pf->photos_getInfo($photoID);
        //echo $photoInfo['photo']['title']['_content'];
    }
    if ($displayImage && $slideshow_option != 'googleimage') {
        $disp_gallery .= '<script type="text/javascript"> ' . "\n";
        $disp_gallery .= 'jQuery(document).ready(function(){' . "\n";
        $disp_gallery .= '  jQuery.afgcolorbox({' . "\n";
        $disp_gallery .= '      title:"' . $photoInfo['photo']['title']['_content'] . '", ' . "\n";
        $disp_gallery .= '      href:"' . $cur_pic . '",' . "\n";
        $disp_gallery .= '      maxWidth: "70%",' . "\n";
        $disp_gallery .= '      maxHeight: "70%",' . "\n";
        $disp_gallery .= '      onComplete:function(){' . "\n";
        $disp_gallery .= '          var imsrc = jQuery(\'#afgcolorbox\').find(\'img\').attr(\'src\');' . "\n";
        $disp_gallery .= '          var hhref = \'\';' . "\n";
        $disp_gallery .= '          if (window.location.href.indexOf("?") != -1){' . "\n";
        $disp_gallery .= '              hhref = window.location.href +\'&\' + \'afg_pic_id=\'+ encodeURIComponent(imsrc);' . "\n";
        $disp_gallery .= '          }' . "\n";
        $disp_gallery .= '          else{' . "\n";
        $disp_gallery .= '              hhref = window.location.href +\'?\' + \'afg_pic_id=\'+ encodeURIComponent(imsrc);' . "\n";
        $disp_gallery .= '          }' . "\n";
        $disp_gallery .= '          jQuery(\'#cboxTitle\').append(\'<div id="extra-info"><ul class="gallery-social"><li class="twitter"><a href="http://www.twitter.com/share?url=\'+ hhref +\'&text=%23RAMPUP"><span>Twitter</span></a></li><li class="facebook"><a href="http://www.facebook.com/sharer/sharer.php?u=\'+ hhref +\'"><span>Facebook</span></a></li></ul></div>\');' . "\n";
        $disp_gallery .= '      },' . "\n";
        $disp_gallery .= '  });' . "\n";
        $disp_gallery .= '}); ' . "\n";
        $disp_gallery .= '</script>';
    }
    if ($slideshow_option == 'googleimage') {
        $disp_gallery .= "\n" . '<script type="text/javascript">';
        $disp_gallery .= "\n\t" . '$jq = jQuery.noConflict();';
        $disp_gallery .= "\n\t" . '$jq(function() {';
        $disp_gallery .= "\n\t\t" . 'Grid.init();';
        $disp_gallery .= "\n\t" . '});';
        /*       
                $disp_gallery.= "\n".'$jq(window).load(function() {(';
                $disp_gallery.= "\n".'function() {';
                $disp_gallery.= "\n".'Grid.init();})';
                $disp_gallery.= "\n".'});';
        */
        $disp_gallery .= "\n" . '</script>';
    }
    return $disp_gallery;
}