[ create a new paste ] login | about

Link: http://codepad.org/w5lUcaDp    [ raw code | output | fork ]

suebriquet - PHP, pasted on May 30:
<?php
include ('header.php');
$catdirs = array();
$dh = opendir(".");
$totaldirs = 2;
$i = 0;
while (($file = readdir($dh)) !== false) {
	if (is_dir($file) && ($file != ".") && ($file != "..")) {
	$catdirs[] = $file; // the icon categories folder (see step 1)
	}
}
closedir($dh);

$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 = 15;          // the number of icons shown on each page (set to a really high number to turn off pagination)
$divider = '&nbsp;';     // the divider between the numbers and front/back arrows in the page navigation
// passthru('find . -regex ".*\.jpg"');
// DO NOT EDIT THE PHP BELOW THIS LINE.  Scroll down to edit the text above the menu, and to add your footer.
// ----------------------------------------------
// get category folders and sort
while ($i < $totaldirs) {
$catdir = $catdirs[$i];   // the icon categories folder
$i++;
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;
	}
}
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);

// build main menu
if ((!$_GET['cat']) || (!in_array($_GET['cat'], $cats))) {
	?>

	<!-- Content Above Menu -->

	<!-- End Content Above Menu -->

	<?php
	echo '<ul id="iconmenu">';
	foreach ($cats as $value) {
		$catname = str_replace('_', ' ', $value);
      echo '<li><a href="' . $_SERVER['PHP_SELF'] . '?cat=' . $value . '">' . $catname . '</a>';
      if ($getcount) {
         $icons = array();
			$getcount = opendir($catdir . '/' . $value);
			while (($icon = readdir($getcount)) !== false) {
				if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
					$icons[] = $value;
				}
			}
			$count = count($icons);
         if ($count == 1) {
				echo ' (' . $count . ' icon)';
			} else {
				echo ' (' . $count . ' icons)';
			}
      }
      echo '</li>';
	}
	echo '</ul>';
}

// get icons and sort
if (in_array($_GET['cat'], $cats)) {
	$icons = array();
	$geticons = opendir($catdir.'/'.$_GET['cat']);
	while (($icon = readdir($geticons)) !== false) {
		if (eregi(".jpg$|.jpeg$|.gif$|.png$|.bmp$", $icon)) {
			$icons[] = array("name" => $icon, "modified" => filemtime($catdir . '/' . $_GET['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);
		}

      // show category name and total icon count
		$catname = str_replace('_', ' ', $_GET['cat']);
      echo '<p><strong>' . $catname . ': ' . $count;
		if ($count == 1) {
			echo ' icon';
		} else {
         echo ' icons';
		}
		echo '</strong></p>';

      // configure pagination
		if ((!$perpage) || ($perpage < 1) || (!is_numeric($perpage))) {
			$perpage = 20;
		}
		$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=' . $_GET['cat'] . '&amp;page=' . $backpagecalc . '">&laquo;</a> ' . $divider;
			}
			if ($page < $pagecount) {
				$nextpagecalc = ($page + 1);
				$nextpage = $divider . ' <a href="?cat=' . $_GET['cat'] . '&amp;page=' . $nextpagecalc . '">&raquo;</a>';
			}
			echo '<p class="pagemenu">Pages: &nbsp;' . $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=' . $_GET['cat'] . '&amp;page=' . $i . '">' . $i . '</a>';
               }
            } else {
               if ($i == $page) {
                  echo $i . ' ' . $divider . ' ';
               } else {
                  echo '<a href="?cat=' . $_GET['cat'] . '&amp;page=' . $i . '">' . $i . '</a> ' . $divider . ' ';
               }
            }
            $i++;
			}			
			echo ' ' . $nextpage . '</p>';
		}
		
		// show the icons
			foreach ($pagearray as $value) {
				$iconsize = getimagesize($catdir . '/' . $_GET['cat'] . '/' . $value['name']);
				echo '<p class="icons"><a href="/go.php?/wp-content/avatars/page.php?catdir=' . $catdir . '&cat=' . $_GET['cat'] . '&val=' . $value['name'] . '" onClick="return popup(this,\'avatarwindow\')"><img src="' . $catdir . '/' . $_GET['cat'] . '/' . $value['name'] . '" ' . $iconsize[3] . ' alt="' . $value['name'] . '" /></a></p>';
			}
	} else {
		echo '<p>There are no icons in this category.</p>';
	}
	echo '<div style="float:left;width:400px;height:15px"><p>&laquo; <a href="' . $_SERVER['PHP_SELF'] . '">back</a></p></div>';
}
}

?>
</body>
</html>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Warning: include(header.php): failed to open stream: No such file or directory on line 2

Warning: include(): Failed opening 'header.php' for inclusion (include_path='.:/usr/lib/php') on line 2

	<!-- Content Above Menu -->

	<!-- End Content Above Menu -->

	<ul id="iconmenu"><li><a href="t.php?cat=bin">bin</a> (0 icons)</li><li><a href="t.php?cat=lib">lib</a> (0 icons)</li></ul>
	<!-- Content Above Menu -->

	<!-- End Content Above Menu -->

	<ul id="iconmenu"><li><a href="t.php?cat=bin">bin</a>
Warning: opendir(lib/bin): failed to open dir: No such file or directory on line 57

Warning: readdir(): supplied argument is not a valid Directory resource on line 58
 (0 icons)</li><li><a href="t.php?cat=lib">lib</a></li></ul></body>
</html>



Create a new paste based on this one


Comments: