<?php
/***                                                                        ***\
    mythgalley.php                            Last Updated: 2003.08.22 (sg_m_dev)

    main configuration index
\***                                                                        ***/

class Theme_settings extends Theme {

    function print_page() {
        $this->print_header();
?>
<?php

// Symlink to mythgallery photo storage directory

if ( ! file_exists(gallery)) {
	$gallery_dir = get_backend_setting('GalleryDir');
	echo 'ERROR: before using please run this<br>';
	echo 'ln -s '.$gallery_dir.' gallery';
	}

$path = "gallery/";

$moverse = $_GET['moverse'];

if (strrpos($moverse,'..')) {
	$moverse = str_replace('/..','',$moverse);
	$moverse = substr($moverse,0,strrpos($moverse,'/'));
	}

if (strpos($moverse,'..')===false) { // php is weakly typed
	} else if (strpos($moverse,'..')==0) {
	echo '<span style="font-size: 150%;"><b>Bad Hacker = No caffeine</b></span>';
	$moverse="";
	}

if($moverse) {
    $moverse = $moverse."/";
    if (strpos($moverse,"\'")) { // This corrects a uri that includes single quote(s), which I think gets messed up by GET
	    $moverse = str_replace("\'","'",$moverse);
	    }
    }

?>
<table width="100%" border="0" cellpadding="4" cellspacing="2" class="recorded">
<tr>
<?php

$handle=opendir($path.$moverse);

$col = 0;
while ($file = readdir($handle)) {
   if ( $col > 5 ) {
       echo '</tr>'."\n".'<tr>';
       $col = 0;
       }
   if(is_dir($path.$moverse.$file) && $file != ".") {
       // A directory
       if (($file == ".." && $moverse == "") || $file ==".thumbcache" ) {
           // Skip directory 
       } else {
	       if ( $file == ".." ) {
               // up directory
               echo '<td class="command"><a href="?moverse='.$uri.'">';
               // Left arrow from Apache gif dir
               echo '<img alt="Left Arrow" src="/gif/l_arrow.gif" width="120" height="120" align="middle" >';
	       } else {
               $uri=str_replace(" ","%20",$moverse.$file);
               $thumburi=str_replace(" ","%20",$path.$moverse.'.thumbcache/'.$file);
               $thumbfile=$path.$moverse.'.thumbcache/'.$file;
               echo '<td class="list"><a href="?moverse='.$uri.'">';
               if ( file_exists( $thumbfile ) ) {
	               echo '<img alt="'.$file.'" src="'.$thumburi.'" width="160" height="120" align="middle" border=5  >';
	           } else {
	               echo $file;
               }
           }
        echo '</a></td class="list">'."\n";
        $col++;
       }
   } else if ($file != "." && $file != "index.php") {
   // A file - ie picture
       $uri=str_replace(" ","%20",$path.$moverse.$file);
       $thumburi=str_replace(" ","%20",$path.$moverse.'.thumbcache/'.$file);
       $thumbfile=$path.$moverse.'.thumbcache/'.$file;
       echo '<td class="list"><a href="'.$uri.'">';
       if ( file_exists( $thumbfile ) ) {
	       echo '<img alt="'.$file.'" src="'.$thumburi.'" width="160" height="120" align="middle" >';
	   } else {
	       echo $file;
	   }
	   echo '</a></td class="list">'."\n";
       $col++;
   }
}
?></tr></table>
<?php
//        $this->print_footer();
    }

    function print_menu_content() {
    $moverse = $_GET['moverse'];
    echo "<b>Directory /".$moverse."</b><br/>"."\n";
    }

    function print_header() {
        parent::print_header("MythGallery");
    }

    function print_footer() {
        parent::print_footer();
    }

}
?>
