$download_allowed = intval($result['images']) > 0; $additional_sql = ""; if (!empty($additional_image_fields)) { foreach ($additional_image_fields as $key => $val) { $additional_sql .= ", i." . $key; } } $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits" . $additional_sql . ", c.cat_name" . get_user_table_field(", u.", "user_name") . "\n FROM (" . IMAGES_TABLE . " i, " . CATEGORIES_TABLE . " c)\n LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = i.user_id)\n WHERE i.image_active = 1 AND i.image_id IN ({$image_id_sql}) AND c.cat_id = i.cat_id AND i.cat_id NOT IN (" . get_auth_cat_sql("auth_viewcat", "NOTIN") . ")\n ORDER BY i." . $config['image_order'] . " " . $config['image_sort'] . ", i.image_id " . $config['image_sort'] . "\n LIMIT {$offset}, {$perpage}"; $result = $site_db->query($sql); $num_rows = $site_db->get_numrows($result); } if (!$num_rows) { $thumbnails = ""; $msg .= $msg != "" ? "<p>" . $lang['lightbox_no_images'] : $lang['lightbox_no_images']; } else { set_download_token($user_info['lightbox_image_ids']); $thumbnails = "<table width=\"" . $config['image_table_width'] . "\" border=\"0\" cellpadding=\"" . $config['image_table_cellpadding'] . "\" cellspacing=\"" . $config['image_table_cellspacing'] . "\">\n"; $count = 0; $bgcounter = 0; while ($image_row = $site_db->fetch_array($result)) { if (!$download_allowed && check_permission("auth_download", $image_row['cat_id'])) { $download_allowed = true; } if ($count == 0) { $row_bg_number = $bgcounter++ % 2 == 0 ? 1 : 2; $thumbnails .= "<tr class=\"imagerow" . $row_bg_number . "\">\n"; } $thumbnails .= "<td width=\"" . $imgtable_width . "\" valign=\"top\">\n"; show_image($image_row, "lightbox"); $thumbnails .= $site_template->parse_template("thumbnail_bit"); $thumbnails .= "\n</td>\n";
function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) { global $self_url, $site_template, $site_sess, $user_info, $config, $cat_cache, $lang, $additional_image_fields, $user_table_fields, $url_show_profile; $is_new = $image_row['image_date'] >= time() - 60 * 60 * 24 * $config['new_cutoff'] ? 1 : 0; $description = !empty($image_row['image_description']) ? format_text($image_row['image_description'], 1, 0, 1) : REPLACE_EMPTY; if (!empty($image_row['image_keywords'])) { $split_keywords = explode(",", $image_row['image_keywords']); $keywords = ""; foreach ($split_keywords as $key => $val) { $url_val = $val; if (preg_match('/[^a-z0-9]+/i', $url_val)) { $url_val = '"' . $url_val . '"'; } $keywords .= ($keywords != "" ? ", " : "") . "<a href=\"" . $site_sess->url(ROOT_PATH . "search.php?search_keywords=" . urlencode($url_val)) . "\">" . format_text($val, 2) . "</a>"; } } else { $keywords = REPLACE_EMPTY; } if (!check_permission("auth_readcomment", $image_row['cat_id'])) { $image_row['image_allow_comments'] = 0; } $num_comments = $image_row['image_allow_comments'] == 1 ? $image_row['image_comments'] : ""; if ($user_info['user_level'] != GUEST) { $lightbox_url = $self_url; $lightbox_url .= !empty($mode) ? (strpos($lightbox_url, '?') !== false ? "&" : "?") . "mode=" . $mode : ""; $lightbox_url .= strpos($lightbox_url, '?') !== false ? "&" : "?"; if (check_lightbox($image_row['image_id'])) { $lightbox_url .= "action=removefromlightbox&id=" . $image_row['image_id']; $lightbox_button = "<a href=\"" . $site_sess->url($lightbox_url) . "\"><img src=\"" . get_gallery_image("lightbox_yes.gif") . "\" border=\"0\" alt=\"\" /></a>"; } else { $lightbox_url .= "action=addtolightbox&id=" . $image_row['image_id']; $lightbox_button = "<a href=\"" . $site_sess->url($lightbox_url) . "\"><img src=\"" . get_gallery_image("lightbox_no.gif") . "\" border=\"0\" alt=\"\" /></a>"; } } else { $lightbox_button = "<img src=\"" . get_gallery_image("lightbox_off.gif") . "\" border=\"0\" alt=\"\" />"; } if (!check_permission("auth_download", $image_row['cat_id'])) { $download_button = "<img src=\"" . get_gallery_image("download_off.gif") . "\" border=\"0\" alt=\"\" />"; $download_zip_button = function_exists("gzcompress") && function_exists("crc32") ? "<img src=\"" . get_gallery_image("download_zip_off.gif") . "\" border=\"0\" alt=\"\" />" : ""; $allow_download = 0; clear_download_token($image_row['image_id']); } else { $target = !empty($image_row['image_download_url']) && !is_remote_file($image_row['image_download_url']) && !is_local_file($image_row['image_download_url']) ? "target=\"_blank\"" : ""; $download_button = "<a href=\"" . $site_sess->url(ROOT_PATH . "download.php?" . URL_IMAGE_ID . "=" . $image_row['image_id']) . "\"" . $target . "><img src=\"" . get_gallery_image("download.gif") . "\" border=\"0\" alt=\"\" /></a>"; $download_zip_button = $target == "" && function_exists("gzcompress") && function_exists("crc32") ? "<a href=\"" . $site_sess->url(ROOT_PATH . "download.php?action=zip&" . URL_IMAGE_ID . "=" . $image_row['image_id']) . "\"" . $target . "><img src=\"" . get_gallery_image("download_zip.gif") . "\" border=\"0\" alt=\"\" /></a>" : ""; $allow_download = 1; set_download_token($image_row['image_id']); } if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) { $postcard_button = "<img src=\"" . get_gallery_image("postcard_off.gif") . "\" border=\"0\" alt=\"\" />"; } else { $postcard_button = "<a href=\"" . $site_sess->url(ROOT_PATH . "postcards.php?" . URL_IMAGE_ID . "=" . $image_row['image_id'] . (!empty($mode) ? "&mode=" . $mode : "")) . "\"><img src=\"" . get_gallery_image("postcard.gif") . "\" border=\"0\" alt=\"\" /></a>"; } if (!check_permission("auth_viewimage", $image_row['cat_id']) || !check_permission("auth_viewcat", $image_row['cat_id'])) { $show_link = 0; } $file_size = "n/a"; if (!is_remote($image_row['image_media_file'])) { if ($file_size = @filesize(MEDIA_PATH . "/" . $image_row['cat_id'] . "/" . $image_row['image_media_file'])) { $file_size = format_file_size($file_size); } } elseif ($detailed_view) { $file_size = get_remote_file_size($image_row['image_media_file']); } if (isset($image_row[$user_table_fields['user_name']]) && $image_row['user_id'] != GUEST) { $user_name = format_text($image_row[$user_table_fields['user_name']], 2); $user_profile_link = !empty($url_show_profile) ? str_replace("{user_id}", $image_row['user_id'], $url_show_profile) : ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $image_row['user_id']; $user_name_link = "<a href=\"" . $site_sess->url($user_profile_link) . "\">" . $user_name . "</a>"; } else { $user_name = format_text($lang['userlevel_guest'], 2); $user_name_link = $user_name; } $site_template->register_vars(array("image_id" => $image_row['image_id'], "user_id" => $image_row['user_id'], "user_name" => $user_name, "user_name_link" => $user_name_link, "image_name" => format_text($image_row['image_name'], 2), "image_description" => $description, "image_keywords" => $keywords, "image_date" => format_date($config['date_format'] . " " . $config['time_format'], $image_row['image_date']), "image_is_new" => $is_new, "lang_new" => $lang['new'], "image_active" => $image_row['image_active'], "cat_id" => $image_row['cat_id'], "cat_name" => format_text($image_row['cat_name'], 2), "cat_url" => $site_sess->url(ROOT_PATH . "categories.php?" . URL_CAT_ID . "=" . $image_row['cat_id']), "image_downloads" => $image_row['image_downloads'], "image_votes" => $image_row['image_votes'], "image_rating" => $image_row['image_rating'], "image_hits" => $image_row['image_hits'], "allow_comments" => $image_row['image_allow_comments'], "lang_comments" => $lang['comments'], "image_comments" => $num_comments, "lightbox_button" => $lightbox_button, "postcard_button" => $postcard_button, "download_button" => $download_button, "download_zip_button" => $download_zip_button, "image_download_url" => $image_row['image_download_url'], "allow_download" => $allow_download, "url_download" => $site_sess->url(ROOT_PATH . "download.php?" . URL_IMAGE_ID . "=" . $image_row['image_id']), "image_file_size" => $file_size, "image_url" => $show_link ? $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_row['image_id'] . (!empty($mode) ? "&mode=" . $mode : "")) : "", "thumbnail" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link), "thumbnail_openwindow" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, 1), "image_file_name" => $image_row['image_media_file'], "thumbnail_file_name" => $image_row['image_thumb_file'])); if (!empty($additional_image_fields)) { $additional_field_array = array(); foreach ($additional_image_fields as $key => $val) { $additional_field_array[$key] = !empty($image_row[$key]) ? format_text($image_row[$key], 1) : REPLACE_EMPTY; $additional_field_array['lang_' . $key] = $val[0]; } if (!empty($additional_field_array)) { $site_template->register_vars($additional_field_array); } } $rate_form = ""; if (check_permission("auth_vote", $image_row['cat_id'])) { $site_template->register_vars("rate", $lang['rate']); $rate_form = $site_template->parse_template("rate_form"); } $site_template->register_vars("rate_form", $rate_form); $site_template->register_vars(array("image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view))); return true; }