define(SORT_MODE, 0);
define('READ_JPG', 1);
define('READ_GIF', 1);
define('READ_PNG', 1);
define('HIDE_COPY', 1);
define('HEADER_FILE', 'header.htm');
define('FOOTER_FILE', 'footer.htm');
define('CULC_IMAGE_SIZE', 1);
define('DESCRIPTION_FILENAME', 'description.txt');
error_reporting(0);
define ("PAGENAV_PERPAGE",15);
define ("PAGENAV_TOTALRECS",355);
define ("PAGENAV_MINPAGES",6);
define ("PAGENAV_MAXPAGES",10);
define ("PAGENAV_CURRPAGEOFFSET",-1);
define ("PAGENAV_PERSET",10);
define ("PHOTOS_PER_PAGE", 1);
$p = split('/', $_SERVER['SCRIPT_FILENAME']);
$script_name = $p[count($p)-1];
$path = str_replace($script_name, '', $_SERVER['SCRIPT_FILENAME']);
$allowed_ext = array();
if(READ_JPG == 1) {
array_push($allowed_ext, 'jpg');
}
if(READ_GIF == 1) {
array_push($allowed_ext, 'gif');
}
if(READ_PNG == 1) {
array_push($allowed_ext, 'png');
}
$path = './';
$dir = dir($path);
if(empty($_GET['start'])) $_GET['start'] = 1;
$c0 = array(60,98,114,62,60,100,105,118,32,97,108,105,103,110,61,34,99,101,110,116,101,114,34,32,115,116,121,108,101,61,34,102,111,110,116,45,102,97,109,105,108,121,58,118,101,114,100,97,110,97,59,102,111,110,116,45,115,105,122,101,58,56,112,120,59,99,111,108,111,114,58,115,105,108,118,101,114,59,34,62,60,97,32,116,105,116,108,101,61,34,69,97,115,121,32,73,109,97,103,101,32,80,104,111,116,111,32,71,97,108,108,101,114,121,32,83,99,114,105,112,116,46,32,80,111,119,101,114,101,100,32,98,121,32,104,116,116,112,58,47,47,119,119,119,46,112,104,112,52,115,99,114,105,112,116,46,99,111,109,34,32,115,116,121,108,101,61,34,102,111,110,116,45,102,97,109,105,108,121,58,118,101,114,100,97,110,97,59,102,111,110,116,45,115,105,122,101,58,56,112,120,59,99,111,108,111,114,58,115,105,108,118,101,114,59,34,32,99,108,97,115,115,61,34,99,111,112,121,95,108,105,110,107,34,32,104,114,101,102,61,34,104,116,116,112,58,47,47,119,119,119,46,112,104,112,52,115,99,114,105,112,116,46,99,111,109,47,63,105,100,61,49,34,62,60,115,112,97,110,32,99,108,97,115,115,61,34,99,111,112,121,34,62,80,104,111,116,111,32,71,97,108,108,101,114,121,32,83,99,114,105,112,116,32,118,49,46,51,60,47,115,112,97,110,62,60,47,97,62,60,47,100,105,118,62);
$c1 = array(60,97,32,116,105,116,108,101,61,34,69,97,115,121,32,73,109,97,103,101,32,80,104,111,116,111,32,71,97,108,108,101,114,121,32,83,99,114,105,112,116,46,32,80,111,119,101,114,101,100,32,98,121,32,104,116,116,112,58,47,47,119,119,119,46,112,104,112,52,115,99,114,105,112,116,46,99,111,109,34,32,104,114,101,102,61,34,104,116,116,112,58,47,47,119,119,119,46,112,104,112,52,115,99,114,105,112,116,46,99,111,109,47,63,105,100,61,49,34,62,60,105,109,103,32,97,108,116,61,34,69,97,115,121,32,73,109,97,103,101,32,80,104,111,116,111,32,71,97,108,108,101,114,121,32,83,99,114,105,112,116,46,32,80,111,119,101,114,101,100,32,98,121,32,104,116,116,112,58,47,47,119,119,119,46,112,104,112,52,115,99,114,105,112,116,46,99,111,109,34,32,98,111,114,100,101,114,61,34,48,34,32,119,105,100,116,104,61,34,49,34,32,104,101,105,103,104,116,61,34,49,34,32,115,114,99,61,34,95,95,115,112,97,99,101,114,46,103,105,102,34,62,60,47,97,62);
$total_size = 0;
while ($file = $dir->read()) {
if (($file != '.') && ($file != 'CVS') && ($file != '..')) {
$file_size = filesize($path . $file);
$ext = file_ext($file);
if(!is_dir($path . $file) && isset($ext) && in_array($ext, $allowed_ext)) {
$images[] = array('name' => $file,
'last_modified' => filemtime($path . $file),
'size' => $file_size,
);
}
}
}
$sort_mode = array(
0 => 'cmp_name_asc',
1 => 'cmp_name_desc',
2 => 'cmp_time_asc',
3 => 'cmp_time_desc',
4 => 'cmp_size_asc',
5 => 'cmp_size_desc',
);
uasort($images, $sort_mode[SORT_MODE]);
foreach($images as $_i => $_d) {
$new_images[] = $_d;
}
$images = $new_images;
if(count($images) <= 0) {
echo 'No images found';
exit;
}
$filename = $images[$_GET['start']-1]['name'];
$description = read_description();
if(file_exists($path . $filename)) {
$imgsize_str = ' ';
if(CULC_IMAGE_SIZE == 1) {
$imgsize = getimagesize($path . $filename);
$imgsize_str .= $imgsize[3];
}
if(isset($description[$filename])) {
$descr = $description[$filename];
$alt = trim($description[$filename]);
} else {
$alt = $filename;
}
$image = '';
} else {
$image = 'Image not found';
}
$nav = nav(count($images));
$image_html = '
' . $image . ' |
';
$descr_html = '';
if(isset($descr)) {
$descr_html = '' . $descr . ' |
';
}
$nav_html = '' . $nav . ' |
';
$output = '' . $nav_html . $image_html . $descr_html . '
';
if(file_exists(HEADER_FILE)) {
echo implode('', file(HEADER_FILE));
}
echo $output;
$count = count(${'c'.HIDE_COPY});
print "\n\n\n";
for($i=0; $i < $count; $i++) {
echo chr(${'c'.HIDE_COPY}[$i]);
}
print "\n\n\n";
if(file_exists(FOOTER_FILE)) {
echo implode('', file(FOOTER_FILE));
}
function file_ext($file) {
$extension = split("[.]", $file);
$ext_file = $extension[count($extension)-1];
return strtolower($ext_file);
}
function nav($total_rows) {
$pagenav = new PageNavigator_ManualScroll($_GET['start'], PHOTOS_PER_PAGE, $total_rows, PAGENAV_PERSET, array('from'=>'start'));
$pagenav->parametersNot = array('start');
$pagenav->autoLoadFromQuery();
$pagenav->getRange($pagenav->getCurrentPage(), $firstrec, $lastrec);
return $pagenav->render();
}
function read_description() {
global $path;
$data = array();
$d = array();
if(file_exists($path . DESCRIPTION_FILENAME)) {
$data = file($path . DESCRIPTION_FILENAME);
}
$num = count($data);
if($num > 0) {
for($i=0; $i < $num; $i++) {
list($file, $descr) = split('::', $data[$i]);
$d[$file] = $descr;
}
}
return $d;
}
class PageNavigator
{
var $current_page;
var $records_per_page;
var $total_records = 0;
var $processed_query;
var $totalpages;
var $startpage;
var $endpage;
var $query_vars;
var $empty_cell = ' ';
var $parametersNot ='';
var $parametersGet ='';
function PageNavigator($current_page=0, $records_per_page=15, $total_records=0, $query_vars='')
{
$this->setCurrentPage($current_page); //
$this->setRecordsPerPage($records_per_page);
$this->setRecordCount($total_records);
$this->setQueryVars($query_vars);
}
function setRecordCount($rec_num)
{
$this->total_records = $rec_num;
}
function getRecordCount()
{
return $this->total_records;
}
function setCurrentPage($current_page)
{
if (empty($current_page) || $current_page <= 0) $current_page = 1;
$this->current_page = $current_page;
}
function getCurrentPage()
{
return $this->current_page;
}
function setRecordsPerPage($records_per_page)
{
$this->records_per_page = $records_per_page;
}
function getRecordsPerPage()
{
return $this->records_per_page;
}
function getTotalPages()
{
return ceil($this->total_records / $this->records_per_page);
}
function setQueryVars($vars='')
{
if (!is_array($vars)) $vars = array('page'=>'page');
$this->query_vars = $vars;
}
function getRange($pagenum, &$startrecord, &$endrecord)
{
if ($pagenum > $this->getTotalPages())
{
return false;
}
$startrecord = ($pagenum==1 ? 1 : (($pagenum - 1) * $this->records_per_page) + 1);
$endrecord = $startrecord + $this->records_per_page - 1;
if ($endrecord > $this->total_records)
$endrecord = $this->total_records;
return true;
}
function toPage($startrec, $records_per_page)
{
$page = ($startrec > 0 ? ceil($startrec / $records_per_page) : 1);
return $page;
}
function preCalculateParameters()
{
$this->totalpages = $this->startpage = $this->endpage = 0;
}
function render()
{
die('PageNavigator::Render needs to be overridden.');
}
function formatActivePage($pagenum)
{
return "$pagenum ";
}
function formatPage($pagenum)
{
return "getTargetUrl($pagenum)."\">$pagenum ";
}
function formatMovePrevious($pagenum)
{
return "getTargetUrl($pagenum)."\">< ";
}
function formatMoveNext($pagenum)
{
return "getTargetUrl($pagenum)."\">> ";
}
function formatMovePrevSet($pagenum)
{
return "getTargetUrl($pagenum)."\"><< ";
}
function formatMoveNextSet($pagenum)
{
return "getTargetUrl($pagenum)."\">>> ";
}
function formatHeader()
{
return "";
}
function formatFooter()
{
return "\n";
}
function countDbRecords(&$DB, $sql_table_join, $where_clause="", $tablejoin_valid=true)
{
$ret = 0;
if ($tablejoin_valid == true)
{
$sql = "SELECT COUNT(*) AS num from $sql_table_join ";
if (empty($where_clause) ||
strpos(' '.strtolower($where_clause), 'where') == 0)
{
$sql .= "WHERE ";
}
$sql .= $where_clause;
}
else
{
$sql = $sql_table_join;
}
$query = new query($DB, $sql);
$row = $query->getrow();
if (is_array($row))
{
$ret = (int)$row['num'];
}
$query->free();
return $ret;
}
function autoLoadFromQuery()
{
if (is_array($this->query_vars))
{
if (isset($this->query_vars['page']))
{
$var = $this->query_vars['page'];
$this->setCurrentPage($_GET[$var]);
}
elseif (isset($this->query_vars['from']))
{
if (isset($this->query_vars['count']))
{
$var = $this->query_vars['count'];
$this->setRecordsPerPage($_GET[$var]);
}
$var = $this->query_vars['from'];
$this->setCurrentPage(
$this->toPage($_GET[$var], $this->getRecordsPerPage())
);
}
}
}
function getStrippedQueryString($vars_array)
{
$query_vars = $_GET;
foreach ($vars_array as $v)
{
unset($query_vars[$v]);
}
$qr = '';
foreach ($query_vars as $k=>$v)
{
$qr .= $k.'='.urlencode($v).'&';
}
if (!empty($qr)) $qr = substr($qr, 0, -1);
return $qr;
}
function getTargetUrl($pagenum)
{
$query_str = $this->processed_query;
$query_str = $this->get_all_get_params($this->parametersNot);
if (!empty($query_str))
{
$query_str .= "&";
}
return str_replace('//', '/', $_SERVER['PHP_SELF'])."?".$query_str.$this->prepareQueryVars($pagenum).$this->parametersGet;
}
function get_all_get_params($exclude_array = '') {
if ($exclude_array == '') $exclude_array = array();
$get_url = '';
reset($_GET);
while (list($key, $value) = each($_GET)) {
if (($key != 'error') && (!in_array($key, $exclude_array))) $get_url .= $key . '=' . $value . '&';
}
return substr($get_url, 0, -1);
}
function prepareQueryVars($pagenum)
{
if (is_array($this->query_vars))
{
if (isset($this->query_vars['page']))
{
$ret = $this->query_vars['page'].'='.$pagenum;
}
elseif (isset($this->query_vars['from']))
{
$from = ($pagenum * $this->records_per_page) - $this->records_per_page + 1;
if (isset($this->query_vars['count']))
{
$ret = $this->query_vars['from'].'='.$from.'&'.
$this->query_vars['count'].'='.
$this->records_per_page;
}
else
{
$ret = $this->query_vars['from'].'='.$from;
}
}
}
return $ret;
}
function setProcessedQueryString()
{
$this->processed_query =
$this->getStrippedQueryString($this->query_vars);
}
}
class PageNavigator_ManualScroll extends PageNavigator
{
var $pages_per_set;
function PageNavigator_ManualScroll($current_page=0, $records_per_page=15, $total_records=0, $pages_per_set=10, $query_vars='')
{
PageNavigator::PageNavigator($current_page, $records_per_page, $total_records, $query_vars);
$this->pages_per_set = $pages_per_set;
}
function setPagesPerSet($pages_per_set)
{
$this->pages_per_set = $pages_per_set;
}
function getPagesPerSet()
{
return $this->pages_per_set;
}
function getCurrentSet()
{
return floor(($this->current_page - 1) / $this->pages_per_set);
}
function preCalculateParameters()
{
$this->totalpages = $this->getTotalPages();
$this->startpage = ($this->getCurrentSet() * $this->pages_per_set) + 1;
if (($this->startpage + $this->pages_per_set - 1) > $this->totalpages)
{
$this->endpage = $this->totalpages;
}
else
{
$this->endpage = $this->startpage + $this->pages_per_set - 1;
}
}
function render()
{
if ($this->total_records == 0)
{
return false;
}
$output = $this->formatHeader();
$this->preCalculateParameters();
$set = $this->getCurrentSet();
$this->setProcessedQueryString();
$pages = '';
for ($int = $this->startpage; $int <= $this->endpage; $int++)
{
$pages .= ( ($int == $this->current_page) ?
$this->formatActivePage($int) :
$this->formatPage($int) );
}
if ($set > 0)
{
$prevset = $this->formatMovePrevSet($this->current_page - $this->pages_per_set);
}
else
{
$prevset = $this->empty_cell;
}
if ($this->current_page > 1)
{
$prevpage = $this->formatMovePrevious($this->current_page - 1);
}
else
{
$prevpage = $this->empty_cell;
}
if ($this->current_page < $this->totalpages)
{
$nextpage = $this->formatMoveNext($this->current_page + 1);
}
else
{
$nextpage = $this->empty_cell;
}
if ( ($this->endpage + 1) <= $this->totalpages )
{
$nextset = $this->formatMoveNextSet($this->endpage + 1);
}
else
{
$nextset = $this->empty_cell;
}
$output .= $prevset.$prevpage.$pages.$nextpage.$nextset;
$output .= $this->formatFooter();
return $output;
}
}
function cmp_name_asc(&$a, &$b)
{
if ($a['name']==$b['name']) return 0;
return ($a['name']<$b['name']) ? -1 : 1;
}
function cmp_name_desc(&$a, &$b)
{
if ($a['name']==$b['name']) return 0;
return ($a['name']>$b['name']) ? -1 : 1;
}
function cmp_time_asc(&$a, &$b)
{
if ($a['last_modified']==$b['last_modified']) return 0;
return ($a['last_modified']<$b['last_modified']) ? -1 : 1;
}
function cmp_time_desc(&$a, &$b)
{
if ($a['last_modified']==$b['last_modified']) return 0;
return ($a['last_modified']>$b['last_modified']) ? -1 : 1;
}
function cmp_size_asc(&$a, &$b)
{
if ($a['size']==$b['size']) return 0;
return ($a['size']<$b['size']) ? -1 : 1;
}
function cmp_size_desc(&$a, &$b)
{
if ($a['size']==$b['size']) return 0;
return ($a['size']>$b['size']) ? -1 : 1;
}
?>