Location: PHPKode > projects > PHP-Comics > php-comics/index.php
<?php
include_once('inc/inc.php');
?>
<?php $options['base'] = DB::Setting("ComicsDirectory",0);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>PHP-Comics : Directory :  <?=preg_replace("(.*/)","",isset($_GET['path']) ? $_GET['path'] : $options['base']) ?></title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<?=site::showsidemenu();?>
<h1>PHP Comic Viewer</h1>
	</tr>
</table>
<?php

if ($_GET['path']) {
	if (preg_match(":$options[base]:",$_GET['path']))
	{
		$path = stripslashes($_GET['path']);
	} else {
		$path = $options['base'];
	}
} else {
	$path = $options['base'];
};
$path = addslashes($path);
$FolderID = DB::QueryResult("SELECT ID FROM Folder WHERE Path = '$path'");
if(empty($FolderID))
{
	DB::Query("INSERT INTO Folder(Path) VALUES('$path')");
	$FolderID = mysql_insert_id();
}

$folderarray = DB::QueryToArray("SELECT * FROM Folder WHERE Path LIKE '$path%' AND Path != '$path'",'Path');
$bookarray = DB::QueryToArray("SELECT b.*,bm.IsRead FROM Book b LEFT JOIN Bookmark bm ON b.ID = bm.Book AND bm.UID = $_SESSION[UID] WHERE Folder = $FolderID",'Name');
$bookid = DB::QueryResult("SELECT MAX(ID) AS ID FROM Book","ID");

$bookid++;
$path = stripslashes($path);
if (preg_match('/[.][.]/',$path)) {
	$path = preg_replace('#/[^/]*/[.][.]#','',$path);
	if (preg_match("#^$options[base]#",$path)) { }
	else {
		$path = $options['base'];
	}
}

$dir_handle = @opendir($path) or die("Unable to open $path");

echo "<h2>Directory Listing of $path</h2><br />\n";

$files = array();

while ($file = readdir($dir_handle))
{
	if($file == '.' || $file == '.DS_Store') continue;
	array_push($files,$file);

}

closedir($dir_handle);

natcasesort($files);
$folderinsert = array();
$bookinsert = array();
$comicarray = array();

foreach($files as $file) {
	$fullpath = $path . "/" . $file;
	if (preg_match('/^[.][.]$/',$file)) {
		//Is the ../
		echo "<div class='item folder'><a href='index.php?path=".preg_replace('|/[^/]+$|','',$path) . "' class='prev'><img src='img/arrow_up_green_48.png'/>Go Up</a><br /></div>\n";
	} elseif (is_dir($path."/".$file)) {
		//Is a Folder
		if($folderarray[$fullpath]==null)
		{
			array_push($folderinsert,$fullpath);
		}
		echo '<div class="item folder"><a  href="index.php?path='.rawurlencode($path).'/'.rawurlencode($file).'" class="dir"><img src="img/folder_48.png"/>'.$file.'</a></div>
';
	} elseif (preg_match('/^._/',$file)) {
		//?
		continue;
      } else {
	if ((preg_match('/[.]cb[rz]$/i',$file))||(preg_match('/[.]zip$/i',$file))||(preg_match('/[.]rar$/i',$file))) {
		//Is a book

			if($bookarray[$file]==null)
			{
				$thebook = $bookid;
				array_push($bookinsert,$file);
				$coverpreview =  img::getcoverpreview($bookid++,DB::Setting('CoversDirectory',0),$path.'/'.$file);
			}
			else
			{
				$thebook = $bookarray[$file]['ID'];
				$coverpreview =  img::getcoverpreview($bookarray[$file]['ID'],DB::Setting('CoversDirectory',0),$path.'/'.$file);
			}
			if(empty($bookarray[$file]['IsRead']))
			{
				$isread = "<a id='read$thebook' href='javascript:markRead($thebook)'><img src='img/circle_green.png'/></a>";
			}
			else
			{
				$isread = "<a id='read$thebook' href='javascript:markUnread($thebook)'><img src='img/accepted_48.png'/></a>";
			}
			if($coverpreview=='<img src=\'img/nocover.png\' width = \'100px\'>')
			{
				$corruptclass = "corrupt";

			}
	        array_push($comicarray,"<div class='item comicview' id='comic$thebook'>$isread<a class='book $corruptclass' href='book.php?path=".rawurlencode($path)."&book=".rawurlencode($file)."' class='cbr'>$coverpreview $file</a></div>\n");
			$corruptclass="";
			$hidelink = "";
		}
      };
}
foreach($comicarray as $value)
{
	echo $value;
}
if(!empty($bookinsert))
{
	$insertstring = "";
	foreach($bookinsert as $value)
	{
		$insertstring .="($FolderID,'".addslashes($value)."'),";

	}
	$insertstring = rtrim($insertstring,",");
	DB::Query("INSERT INTO Book(Folder,Name) VALUES $insertstring");
}
if(!empty($folderinsert))
{
	$insertstring = "";
	foreach($folderinsert as $value)
	{
		$insertstring .="('".addslashes($value)."'),";
	}
	$insertstring = rtrim($insertstring,",");
	DB::Query("INSERT INTO Folder(Path) VALUES $insertstring");
}
?>
</body></html>
Return current item: PHP-Comics