<?php
//include ('header.php');
$j = 0;
$k = 0;
$sort = 'first'; // set 'first' to show newest icons first, 'last' to show newest icons last
$getcount = true; // true shows the icon count per category in the menu, and false turns it off
$perpage = 9; // the number of icons shown on each page (set to a really high number to turn off pagination)
$divider = ' '; // the divider between the numbers and front/back arrows in the page navigation
$catdirs = array();
$getfolders = opendir(".");
while (($file = readdir($getfolders)) !== false) {
if (is_dir($file) && ($file != ".") && ($file != "..")) {
$catdirs[] = $file; // the icon categories folder (see step 1)
} $totaldirs = count($catdirs); // count total number of directories
}
closedir($getfolders);
// get category folders and sort
while ($j < $totaldirs-1) {
$catdir = $catdirs[$j]; // the icon categories folder
$j++;
if (!file_exists($catdir)) {
echo 'Error! The folder named <strong>' . $catdir . '</strong>, as specified in the config, does not exist in this directory. The value of the variable $catdir must match the name of the created folder (case-sensitive), and that folder must be in this directory for the script to work. Create the folder and put the individual icon category folders inside it.';
exit();
}
$getfolders = opendir($catdir);
while (($file = readdir($getfolders)) !== false) {
if (($file != '.' && $file != '..') && (is_dir($catdir.'/'.$file))) {
$cats[] = $file;
}$numcats = count($cats);
}
if (!$cats) {
echo 'No category folders were found inside the folder named <strong>' . $catdir . '</strong>. Create your individual category folders inside that folder and the menu will appear.';
exit();
}
natcasesort($cats);
while ($k < $numcats) {
$cat = $cats[$k];
$k++;
if ((!$cat) || (!in_array($cat, $cats))) {
foreach ($cats as $value) {
$catname = str_replace('_', ' ', $value);
if ($getcount) {
$icons = array();
$dir = $catdir . '/' . $value;
if ($dir !== 'anime/Miscellaneous') {
if ($dir !== 'other/anime') {
$getcount = opendir($dir);
}
}
while (($icon = readdir($getcount)) !== false) {
if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
$icons[] = $value;
}
}
$count = count($icons);
$numicons += $count;
}
}
}
// get icons and sort
if (in_array($cat, $cats)) {
$icons = array();
$dir = $catdir.'/'.$cat;
if ($dir !== 'anime/Miscellaneous') {
if ($dir !=='other/anime') {
$geticons = opendir($catdir.'/'.$cat);
}
}
while (($icon = readdir($geticons)) !== false) {
if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
$icons[] = array("name" => $icon, "modified" => filemtime($catdir . '/' . $cat . '/' . $icon));
}
}
$count = count($icons);
if ($count > 0) {
function modcmp($a, $b) {
return strcmp($a['modified'], $b['modified']);
}
usort($icons, 'modcmp');
if ($sort == 'first') {
$icons = array_reverse($icons);
}
// configure pagination
if ((!$perpage) || ($perpage < 1) || (!is_numeric($perpage))) {
$perpage = 9;
}
$pagecalc = ($count / $perpage);
$pagecount = ceil($pagecalc);
$page = $_GET['page'];
if (($page > $pagecount) || ($page == '0')) {
$start = 0;
} elseif (!$page) {
$start = 0;
$page = 1;
} elseif (!is_numeric($page)) {
$start = 0;
$page = 1;
} else {
$start = (($page * $perpage) - $perpage);
}
$pagearray = array_slice($icons, $start, $perpage);
// if there is more than one page, show the page menu
if ($pagecount > 1) {
if (($page <= $pagecount) && ($page > 1)) {
$backpagecalc = ($page - 1);
$backpage = '<a href="?cat=' . $cat . '&page=' . $backpagecalc . '">«</a> ' . $divider;
}
if ($page < $pagecount) {
$nextpagecalc = ($page + 1);
$nextpage = $divider . ' <a href="?cat=' . $cat . '&page=' . $nextpagecalc . '">»</a>';
}
echo '<p class="pagemenu">Pages: ' . $backpage . ' ';
$i = 1;
while ($i <= $pagecount) {
$pagespanstart = ((($i * $perpage) - $perpage) + 1);
$pagespanend = ($i * $perpage);
if ($i == $pagecount) {
if ( $i == $page) {
echo $i;
} else {
echo '<a href="?cat=' . $cat . '&page=' . $i . '">' . $i . '</a>';
}
} else {
if ($i == $page) {
echo $i . ' ' . $divider . ' ';
} else {
echo '<a href="?cat=' . $cat . '&page=' . $i . '">' . $i . '</a> ' . $divider . ' ';
}
}
$i++;
}
echo ' ' . $nextpage . '</p>';
}
// show the icons
foreach ($pagearray as $value) {
$iconsize = getimagesize($catdir . '/' . $cat . '/' . $value['name']);
echo '<p class="icons"><a href="/go.php?/wp-content/avatars/page.php?catdir=' . $catdir . '&cat=' . $cat . '&val=' . $value['name'] . '" onClick="return popup(this,\'avatarwindow\')"><img src="' . $catdir . '/' . $cat . '/' . $value['name'] . '" ' . $iconsize[3] . ' alt="' . $value['name'] . '" /></a></p>';
}
} else {
echo '<p>There are no icons in this category.</p>';
}
}
}
}
?>
</body>
</html>