All pastes #348067 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-09 21:55 UTC
rendered paste body
<?php



$listdir = "comics";        // Customizeable
$listid  = $_GET['id'];  // Leave this alone

/*  This function is the one I've been using forever.  It just goes and grabs
    an alphabetical array of files in the specified directory.  */

function getlist_alpha(&$afiles, $listdir) {
    if (is_dir($listdir)) {
        if ($thisdir = opendir($listdir)) {
            while (($afile = readdir($thisdir)) !== false) {
                if (!is_dir($afile) && preg_match("/.*\.(gif|jp(e)?g|png)/i", $afile)) {
                        $afiles[] = $afile;
                    }
            }
            closedir($thisdir);
            return $afiles;
        }
    }
}

/*  This function actually creates the strings to be put in the selection list.  */

function printoptions($item1, $key, $listdir) {
     if (strpos($item1, ".")) {  $item1   = explode(".", $item1);
    $item1   = $item1[0]; }
	$ffile   = "$listdir/$item1";
	if ($item1 == $_GET['id']) echo "\n<option selected>"; else echo "\n<option>"; echo "$item1</option>";
}

/*  This function sorts a collected array and then uses printoptions to make the list.  */

function comiclist($listdir, $listid) {
echo "<center><form name=\"comiclist\">\n<select name=\"id\" id=\"id\">";
	$alisting = getlist_alpha($listcomics, $listdir);
	rsort($alisting);
	array_walk($alisting, 'printoptions', $listdir);
echo "</select>\n<input type=\"submit\" value=\"Go\" action=\"selection.php\" method=\"get\">\n</form></center>";
}

comiclist($listdir, $listid);


?></p>
										<div align="center">
											<p><?php
$cdir		=	'comics';
$getc		=	$_GET['id'];	
$phpfile		=	$_SERVER['PHP_SELF']; 

function check_zeros($num) {
	$digits	= 3;
     $pad		= strval(0);
     $num		= strval($num);

	if (strlen($num) != $digits) {
		$num = str_pad($num, $digits, $pad, STR_PAD_LEFT);
	}
	return $num;
}


function find_comic($idnum, $dir) {
	if (is_dir($dir)) {
		if ($cdir = opendir($dir)) {
			if ($idnum != 'all') $idnum = check_zeros($idnum);
			if ($idnum == 'all') $num = 0;
			while (($file = readdir($cdir)) !== false) {
				if ($file != '.' && $file != '..') {
					if ($idnum != 'all') {
						if (preg_match("/$idnum\.(gif|jp(e?)g|png)/i", $file)) {
							$idnum = $file;
						}
					}
					else if (preg_match("/.*\.(gif|jp(e?)g|png)/i", $file)) {
						$num++;
					}					
				}
			}
		}
		closedir($cdir);
	}
	if ($idnum == 'all') return $num;
	else return $idnum;
}



$max_comics	=	find_comic("all", $cdir);

if ($getc < 1 || $getc == NULL || $getc > $max_comics)
$getc = $max_comics;

if ($getc > 1)
$getp	=	$getc - 1;
else
$getp 	= 	NULL;

$getn	=	$getc + 1;
$cshow	=	find_comic($getc, $cdir);

echo "<img src=\"$cdir/$cshow\" border=\"0\" /><br>";

echo "<br><br>";

if ($getc > 2)
echo "<a href=\"$phpfile?id=1\"><img src=\"first.gif\" border=\"0\"></a>";

if ($getc > 1)
echo "<a href=\"$phpfile?id=$getp\"><img src=\"back.gif\" border=\"0\"></a>";

echo "<a href=\"http://www.sagmnet.com/5181994/wordpress\"><img src=\"home.gif\" border=\"0\"></a>";

if ($getc < $max_comics)
echo "<a href=\"$phpfile?id=$getn\"><img src=\"next.gif\" border=\"0\"></a>";

if ($getc != $max_comics && $getc < $max_comics - 1)
echo "<a href=\"$phpfile?id=$max_comics\"><img src=\"newest.gif\" border=\"0\"></a>";
?>