need help with sort
Posted: Mon May 25, 2009 12:01 am
Hello, I'm new to this forum. Right now I'm using this free script called Captivate to display my website's free icons and textures, the only thing I am unable to do is have them list in reverse order. They are currently named 001.png, 002.png, ...etc. And I need them to list reverse so the "newest" images are display at the very top.
Here is the current script being used. (There is also a config.php page but I don't think it's required to perform this)
Any help would be greatly appreciated, as I am not yet skilled with PHP. Thanks!
Here is the current script being used. (There is also a config.php page but I don't think it's required to perform this)
Code: Select all
<?php
// DON'T EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
// ----------------------------------------------------------------------------------
include_once("config1.php");
//get script start time if requested
if (($showtime == "y") OR ($showtime =="Y")); {
$starttime = explode(' ', microtime());
$scriptstart = $starttime[0] + $starttime[1];
}
//calculate number of pages according to number of images
$pagecalc = ($imagecount / $perpage);
$pagecount = ceil($pagecalc);
//direct invalid page requests back to the first page
$page = $_GET["page"];
if (($page > $pagecount) || ($page == "0")) {
$start = 0;
echo "<p>Page $page does not exist! You have been taken to the first page.</p>";
} elseif (!$page) {
$start = 0;
$page = 1;
} elseif (!is_numeric($page)) {
$start = 0;
$page = 1;
echo "<p>Page $page does not exist! You have been taken to the first page.</p>";
} else {
$start = (($page * $perpage) - $perpage);
}
//put put jpg, jpeg, and jpe images in thumbs directory into array
$thumbhandle=opendir($thumbdirectory);
while ($file = readdir($thumbhandle)) {
if (eregi(".png$|.jpg$", $file)) {
$thumbarray[] = $file;
}
}
closedir($thumbhandle);
//make array of all images that also have thumbs
$combinedarray = @array_intersect($imagearray, $thumbarray);
if (!$combinedarray) {
echo "<p>An error has occurred. You probably haven't made or uploaded any thumbnails yet so the gallery can't be created!</p>";
echo $footer;
exit;
}
$combinedarraycount = count($combinedarray);
//if image isn't set, show gallery
$image = $_GET["image"];
if (!$image) {
//make array from above array of images to be displayed on requested page
$pagearray = array_slice($combinedarray, $start, $perpage);
$pagearraycount = count($pagearray);
//open gallery table
echo "<table align=\"center\" id=\"gallery\">\n";
//open top menu if requested
if (($topmenu == "y") OR ($topmenu =="Y")) {
echo "<tr><td colspan=\"$perrow\" class=\"topmenu\" style=\"text-align: center\">\n";
//menu calculation
$j = 1;
while ($j <= $pagecount) {
$pagespanstart = ((($j * $perpage) - $perpage) + 1);
$pagespanend = ($j * $perpage);
//determine link style
if ($menustyle == "page") {
$pagelink = "page $j";
} elseif ($menustyle == "number") {
$pagelink = "$j";
} else {
if ($j == $pagecount) {
$lastpagecount = ($perpage - (($perpage * $pagecount) - $combinedarraycount));
$lastpagespanend = (($pagespanstart + $lastpagecount) - 1);
$pagelink = "$pagespanstart - $lastpagespanend";
} else {
$pagelink = "$pagespanstart - $pagespanend";
}
}
//actual menu links
if ($returnlink == "y") {
if ($j == $pagecount) {
if ( $j == $page) {
echo "$pagelink | <a href=\"$returnlinkname\">$returnlinktext</a>";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | <a href=\"$returnlinkname\">$returnlinktext</a>";
}
} else {
if ($j == $page) {
echo "$pagelink | ";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | ";
}
}
} else {
if ($j == $pagecount) {
if ( $j == $page) {
echo "$pagelink";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a>";
}
} else {
if ($j == $page) {
echo "$pagelink | ";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | ";
}
}
}
$j++;
}
echo "</td></tr>";
}
//build gallery
$i=0;
foreach($pagearray as $pic) {
//make a new row if the remainder of $i divided by $perrow is 0
if($i % $perrow == 0) {
echo "<tr>\n";
}
//get size of thumbnail
$thumbsize = getimagesize("$thumbdirectory/$pic");
//determine method to open full-size image
if ($openstyle == "gallery") {
echo "<td><img class=\"imgbord\" src=\"$thumbdirectory/$pic\" $thumbsize[3] border=\"0\" alt=\"\" /></td>\n";
} elseif ($openstyle == "samepage") {
echo "<td><a href=\"$imagedirectory/$pic\"><img class=\"imgbord\" src=\"$thumbdirectory/$pic\" $thumbsize[3] border=\"0\" alt=\"\" /></a></td>\n";
} else {
echo "<td><a href=\"$imagedirectory/$pic\" target=\"_blank\"><img class=\"imgbord\" src=\"$thumbdirectory/$pic\" $thumbsize[3] border=\"0\" alt=\"\" /></a></td>\n";
}
//add an extra cells if there are not enough columns
if($i == ($pagearraycount - 1)) {
while(($i + 1) % $perrow != 0) {
echo "<td> </td>\n";
$i++;
}
}
//end table row if the remainder of $i+1 divided by $perrow is 0
if(($i + 1) % $perrow == 0) {
echo "</tr>\n";
}
$i++;
}
//bottom menu
if (($bottommenu == "y") OR ($bottommenu =="Y")) {
echo "<tr>\n<td colspan=\"$perrow\" class=\"bottommenu\" style=\"text-align: center\">\n";
//menu calculation
$j = 1;
while ($j <= $pagecount) {
$pagespanstart = ((($j * $perpage) - $perpage) + 1);
$pagespanend = ($j * $perpage);
//determine link style
if ($menustyle == "page") {
$pagelink = "page $j";
} elseif ($menustyle == "number") {
$pagelink = "$j";
} else {
if ($j == $pagecount) {
$lastpagecount = ($perpage - (($perpage * $pagecount) - $combinedarraycount));
$lastpagespanend = (($pagespanstart + $lastpagecount) - 1);
$pagelink = "$pagespanstart - $lastpagespanend";
} else {
$pagelink = "$pagespanstart - $pagespanend";
}
}
//actual menu links
if ($returnlink == "y") {
if ($j == $pagecount) {
if ( $j == $page) {
echo "$pagelink | <a href=\"$returnlinkname\">$returnlinktext</a>";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | <a href=\"$returnlinkname\">$returnlinktext</a>";
}
} else {
if ($j == $page) {
echo "$pagelink | ";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | ";
}
}
} else {
if ($j == $pagecount) {
if ( $j == $page) {
echo "$pagelink";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a>";
}
} else {
if ($j == $page) {
echo "$pagelink | ";
} else {
echo "<a href=\"$gallery?page=$j\">$pagelink</a> | ";
}
}
}
$j++;
}
echo "</td>\n</tr>\n";
}
//show gallery generation time
if (($showtime == "y") OR ($showtime =="Y")) {
echo "<tr><td colspan=\"$perrow\" style=\"font-size: 9px; padding-top: 10px; margin: 0px; text-align: center;\">";
$endtime = explode(' ', microtime());
$scriptend = $endtime[0] + $endtime[1];
$totaltime = round($scriptend - $scriptstart, 5);
echo "<span>Gallery generated in $totaltime seconds.</span></td></tr>";
}
//close table
echo "</table>";
// else, if image is set, show single image
} elseif ($image) {
$combinedarray = array_values($combinedarray);
$combinedarraycount = count($combinedarray);
//get key of current image
$imagekey = array_search($image, $combinedarray);
//set back and next images
if ($imagekey > 0) {
$backkey = ($imagekey - 1);
$backimage = "<a href=\"$gallery?image=$combinedarray[$backkey]\">« previous</a>";
} else {
$backimage = "« previous";
}
if ($imagekey < ($combinedarraycount - 1)) {
$nextkey = ($imagekey + 1);
$nextimage = "<a href=\"$gallery?image=$combinedarray[$nextkey]\">next »</a>";
} else {
$nextimage = "next »";
}
//calculate gallery page of image
$sourcepage = ceil(($imagekey +1) / $perpage);
//display single image
$imagesize = getimagesize("$imagedirectory/$image");
echo "<table id=\"image\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td style=\"text-align: center;\"><table cellpadding=\"0\" cellspacing=\"0\" style=\"margin-left: auto; margin-right: auto;\"><tr><td style=\"text-align: right;\">$backimage </td><td style=\"text-align: center;\"> | <a href=\"$gallery?page=$sourcepage\">back to thumbnails</a> |</td><td style=\"text-align: left;\"> $nextimage</td></tr></table></td>\n</tr>\n";
echo "<tr>\n<td ><img src=\"$imagedirectory/$combinedarray[$imagekey]\" $imagesize[3] alt=\"\" /></td>\n</tr>\n";
echo "<tr>\n<td style=\"text-align: center;\"><table cellpadding=\"0\" cellspacing=\"0\" style=\"margin-left: auto; margin-right: auto;\"><tr><td style=\"text-align: right;\">$backimage </td><td style=\"text-align: center;\"> | <a href=\"$gallery?page=$sourcepage\">back to thumbnails</a> |</td><td style=\"text-align: left;\"> $nextimage</td></tr></table></td>\n</tr>\n";
if (($imageinfo == "y") OR ($imageinfo == "Y")) {
echo "<tr>\n<td class=\"imageinfo\" style=\"font-size: 9px; margin: 0px; padding-top: 10px; text-align: center;\">$imageinfotext</td>\n</tr>\n</table>";
} else {
echo "</table>";
}
}
// ----------------------------------------------------------------------------------
// DON'T EDIT ABOVE THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
?>