$query : failed - " . mysql_errno() . " : " . mysql_error()); return($result); } // parse a string with elements separated by { } into an array function parse_brackets($string) { $list1 = explode("} {",$string); if ($list1[0]{0} == "{") $list1[0] = substr($list1[0],1); if (substr($list1[count($list1)-1],-1,1) == "}") $list1[count($list1)-1] = substr($list1[count($list1)-1],0,-1); return($list1); } function search_call($script,$new_options,$order="first") { $new_search_call = ""; if ($order == "first") { foreach ($new_options as $name => $value) { if ($value != "") { if ($new_search_call != "") $new_search_call .= "&"; $value_enc = urlencode($value); $new_search_call .= "$name=$value_enc"; } } } foreach ($_GET as $name => $value) { if ($value != "") { if (!array_key_exists($name, $new_options)) { $value_enc = urlencode($value); if ($new_search_call != "") $new_search_call .= "&"; $new_search_call .= "$name=$value_enc"; } } } if ($order != "first") { foreach ($new_options as $name => $value) { if ($value != "") { if ($new_search_call != "") $new_search_call .= "&"; $value_enc = urlencode($value); $new_search_call .= "$name=$value_enc"; } } } return("$script?$new_search_call"); } $mysql = mysql_connect("localhost","qtl1","tgdbtgdb;;") or die("could not connect to mysql"); mysql_select_db('photo', $mysql) or die ('Could not select database'); $res_ref = mysql_photo_query("select * from images where ref = '$ref'"); $array = mysql_fetch_row($res_ref); $src = trim($array[1]); $url = trim($array[2]); $caption = trim($array[3]); $caption_no_tags = strip_tags($caption); $location = trim($array[7]); $categories = trim($array[8]); $this_author = trim($array[19]); $cat_string = ""; $rss = ""; $ref_link = "$ref"; $up_link = ""; $path_search = ""; // parent page and path if ($dt == "keyword") { $cat_res = mysql_photo_query("select * from keywords where keyword = '$cat'"); $array_cat = mysql_fetch_row($cat_res); $simp_id = explode(" ",$array_cat[8]); $images_list = $array_cat[8]; $nb_images_total = $array_cat[6]; $cat_name = $array_cat[1]; $cat_string = "($cat_name)"; $child = $array_cat[7]; $all_images_list = explode(" ",$images_list); $pos = array_search($ref, $all_images_list); if (($row == "") && ($col == "")) { $nb_images_per_page = 40; } else { if ($row == "") $row=10; if ($col == "") $col=4; $nb_images_per_page = $row * $col; } $page = floor($pos/$nb_images_per_page) + 1; if ($page != 1) $up_url = search_call($search_url,array("page" => "$page","rating" => "","ref_prev" => "","id"=>""),"last"); else $up_url = search_call($search_url,array("rating" => "","ref_prev" => "","id"=>"")); $up_link = "$cat_name"; $path_search = "Home / $up_link"; } if (($dt == "cat") || ($dt == "catsearch") || ($dt == "view100")) { $cat_res = mysql_photo_query("select * from categories where cat = '$cat'"); $array_cat = mysql_fetch_row($cat_res); $simp_id = explode(" ",$array_cat[7]); $nb_images_total = $array_cat[5]; $cat_name = $array_cat[1]; $cat_string = "($cat_name)"; $child = $array_cat[6]; if ($images_list == "") { $images_list = $array_cat[7]; } $all_images_list = explode(" ",$images_list); $pos = array_search($ref, $all_images_list); if (($dt == "catsearch") || ($dt == "view100")) { if (($row == "") && ($col == "") && ($dt == "view100")) { if ($nb == "") $nb_images_per_page = 100; else $nb_images_per_page = $nb; } else { if ($row == "") $row=4; if ($col == "") $col=5; $nb_images_per_page = $row * $col; } $start_image = $nb_images_per_page * floor($pos/$nb_images_per_page) + 1; if ($start_image != 1) { $up_url = search_call($search_url,array("s" => "$start_image","rating" => "","ref_prev" => "","id"=>""),"last"); } else { $up_url = search_call($search_url,array("rating" => "","ref_prev" => "","id"=>"")); } $rss = search_call($search_url,array("c"=>"rss","rating" => "","ref_prev" => "","id"=>"")); } if ($dt == "cat") { $nb_images_per_page = 20; $start_page = floor($pos/$nb_images_per_page) + 1; if (($start_page == 1) || ($nb_images_total <= 30)) $up_url = "/pictures-subjects/$cat"; else $up_url = "/pictures-subjects/$cat/$cat.$start_page.html"; $rss = "/pictures-subjects/$cat.rss"; } $up_link = "$cat_name"; $path_list = parse_brackets($array_cat[3]); $path_search = ""; $number_cats = 1; foreach ($path_list as $path) { $cat_list = explode(" ",$path); $path_search .= "Home / Pictures by subjects"; foreach ($cat_list as $category) { $result_single = mysql_photo_query("select name,nb_ima_total from categories where cat = '$category'"); $array = mysql_fetch_row($result_single); if ($dt== "catsearch") $new_call = search_call($search_url,array("cat"=>"$category","t"=>"cat","q"=>"","s"=>"1","rating" => "","ref_prev" => "")); elseif ($dt== "cat") $new_call = "/pictures-subjects/$category"; elseif ($dt== "view100") $new_call = "/pictures-subjects/$category/$category.all.html"; $path_search .= " / $array[0]"; } $path_search .= " / $up_link / $ref
"; } } if ($dt == "search") { $up_url = search_call($search_url,array("rating" => "","ref_prev" => "")); $rss = search_call($search_url,array("c"=>"rss","rating" => "","ref_prev" => "")); $up_link = "$title"; $path_search = "Home / $up_link / $ref
"; } // categories $categories_link = ""; if ($categories != "") { $categories_list = explode(" ",$categories); foreach ($categories_list as $category) { $result_single = mysql_photo_query("select name,nb_ima_total from categories where cat = '$category'"); $array = mysql_fetch_row($result_single); if (($dt == "catsearch") || ($dt == "search")) $new_call = search_call($search_url,array("cat"=>"$category","t"=>"cat","q"=>"","s"=>"1","rating" => "","ref_prev" => "")); else $new_call = "/pictures-subjects/$category"; if ($categories_link != "") $categories_link .= ", "; $name_cat = str_replace(" "," ",$array[0]); $categories_link .= "$name_cat"; } } // next and prev arrows $all_images_list = explode(" ",$images_list); $nb_images = count($all_images_list); $pos = array_search($ref, $all_images_list); $pos_next = $pos + 1; $pos_plus = $pos + 1; if ($pos_next == $nb_images) $pos_next = 0; $pos_prev = $pos - 1; if ($pos_prev == -1) $pos_prev = $nb_images - 1; $ref_previous = $all_images_list[$pos_prev]; $ref_next = $all_images_list[$pos_next]; $page_url = search_call("$photo_url",array("rating"=> "","ref_prev" => "")); $page_url_prev = search_call("$photo_url",array("id"=>"$ref_previous","rating"=> "","ref_prev" => "")); $page_url_next = search_call("$photo_url",array("id"=>"$ref_next","rating"=> "","ref_prev" => "")); $page_url_e = urlencode(substr($page_url,1)); $page_url_next_e = urlencode(substr($page_url_next,1)); // ratings if ($rating == "") { $rating_string = " "; } else { $result_rating=mysql_photo_query("select ratings_nb,ratings_av from image_stats where ref = '$ref'"); if (mysql_num_rows($result_rating) > 0) { $array = mysql_fetch_row($result_rating); $nb = $array[0]; $av = $array[1]; } if ($nb == 1) { $rating_string = "You were the first to rate this image. Thanks !"; } else { $rating_string = sprintf("Thank you for the rating. This image has been rated $nb times with an average of %.1f/10 ",$av); } } if ($ref_prev != "") { $result_rating=mysql_photo_query("select ratings_nb,ratings_av from image_stats where ref = '$ref_prev'"); if (mysql_num_rows($result_rating) > 0) { $array = mysql_fetch_row($result_rating); $nb = $array[0]; $av = $array[1]; } if ($nb == 1) { $rating_string .= "

You were the first to rate the previous image $ref_prev. Thanks !
"; } else { $rating_string .= sprintf( "

Thanks for your rating. Previous image $ref_prev has been rated $nb times with an average of %.1f/10
",$av); } } $form_selection=<<< end0
end0; $form_selection_jump=<<< end1
end1; $form_license=<<< end2
end2; $form_printorder=<<< end3
end3; $form_wallpaper=<<< end4
end4; $form_download=<<< end5
end5; $google_script=<<< end6 end6; $addthis_string=<<< end7

end7; if ($this_author != "") { $form_license = ""; $form_wallpaper = ""; } if ($categories_link != "") { $subjects_text = "

Subjects: $categories_link"; } else { $subjects_text = ""; } $selection_contents = ""; if (isset($_COOKIE['nbima'])) { $nbima = $_COOKIE['nbima']; if ($nbima == 1) { $selection_contents = "View selection (1 image)"; } else { $selection_contents = "View selection ($nbima images)"; } } $cart_contents = ""; if (isset($_COOKIE['cart'])) { $nbima = $_COOKIE['cart']; if ($nbima != 0) { if ($nbima == 1) { $cart_contents = "View cart (1 image)"; } else { $cart_contents = "View cart ($nbima images)"; } } } $no_follow = ""; if ($dt != "keyword") $no_follow = ""; $page=<<< endofpage Picture/photo $cat_string: $caption_no_tags $no_follow
terragalleria.com · the photography of QT Luong
$path_search
previous image $pos_plus / $nb_images next image
$selection_contents   $cart_contents
$caption_no_tags

$caption

$form_selection
$form_license
$form_printorder
$form_wallpaper
$form_download
$rating_string $addthis_string
Photo ID# $ref_link

Location: $location $subjects_text

Up to thumbnail page$up_link

$google_script

previous photo $pos_plus / $nb_images next photo
endofpage; print $page; mysql_photo_query("update image_stats set views = views + 1 where ref = '$ref'"); mysql_close($mysql); ?>