We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    Here’s the code that powers the Gallery script...

    <?php
    class WingedGallery {
    	var $path;
    	var $htpath;
    	var $docroot;
    	var $datapath;
    	var $template;
    	var $url;
    	var $thumb_small;
    	var $thumb_big;
    	var $name;
    	
    	function WingedGallery() {
    		$this->path = str_replace('\\', '/', dirname(__FILE__));
    		$this->docroot = $_SERVER['DOCUMENT_ROOT'];
    		$this->htpath = str_replace($this->docroot, '', $this->path);
    		$this->datapath = $this->path . '/data/';
    		$this->template = $this->path . '/template/Tales2.0/';
    		$this->url = './index.php?';
    		$this->thumb_small = 75;
    		$this->thumb_big = 250;
    		$this->name = 'Gallery';
    	}
    	
    	function setDocumentRoot($docroot) {
    		$this->docroot = $docroot[strlen($docroot)-1]=='/'? substr($docroot, 0, -1) : $docroot;
    		$this->htpath = str_replace($this->docroot, '', $this->path);
    	}
    	
    	function setTemplate($tpl) {
    		$this->template = $this->path . '/template/' . $tpl . '/';
    	}
    	
    	function setURL($url) {
    		$this->url = $url;
    	}
    	
    	function setSmallThumbSize($size) {
    		$this->thumb_small = $size;
    	}
    	
    	function setBigThumbSize($size) {
    		$this->thumb_big = $size;
    	}
    	
    	function setGalleryName($name) {
    		$this->name = $name;
    	}
    	
    	function getDirDetails($dir='') {
    		$details = array('dirs'=>array(), 'files'=>array());
    		$details['dirs'][0]['DIR_NAME'] = $this->name;
    		$details['dirs'][0]['DIR_PATH'] = $this->url;
    		$dirs = explode('/', $dir);
    		for ($i=1, $n=count($dirs); $i<$n; $i++) {
    			$details['dirs'][$i]['DIR_NAME'] = $dirs[$i];
    			$details['dirs'][$i]['DIR_PATH'] = $this->url . 'file=';
    			for ($j=0; $j<=$i; $j++) {
    				$details['dirs'][$i]['DIR_PATH'] .= urlencode($dirs[$j]) . '/';
    			}
    			$details['dirs'][$i]['DIR_PATH'] = substr($details['dirs'][$i]['DIR_PATH'], 0, -1);
    		}
    		
    		$sorts = array();
    		$count = 0;
    		$handle = opendir($this->datapath . $dir);
    		while (($file=readdir($handle))!==false) {
    			if ($file[0]=='.') continue;
    			$fullpath = $this->datapath . $dir . '/' . $file;
    			$encodedpath = str_replace('%2F', '/', urlencode($dir . '/' . $file));
    			if (is_dir($fullpath)) {
    				$details['files'][$count]['IF_DIR'] = 'dir';
    				$details['files'][$count]['THUMB'] = $file;			
    			} else if (is_file($fullpath)) {
    				$info = @getimagesize($fullpath);
    				if ($info===false) continue;
    				$details['files'][$count]['IF_DIR'] = '';
    				$details['files'][$count]['THUMB'] =
    					'<img alt="' . $file .
    					'" width="' . $this->thumb_small . '" height="' . $this->thumb_small .
    					'" src="' . $this->htpath . '/thumb.php?image=' . $encodedpath .
    					'&size=' . $this->thumb_small . '" />';
    			} else continue;
    			$details['files'][$count]['NAME'] = $file;
    			$details['files'][$count]['LINK'] = $this->url . 'file=' . $encodedpath;
    			$sorts[] = $fullpath;
    			$count++;
    		}
    		closedir($handle);
    		array_multisort($sorts, SORT_ASC, $details['files']);
    		return $details;
    	}
    	
    	function getFileDetails($file) {
    		$details = array('dirs'=>array(), 'files'=>array());
    		$capfile = 'caption.txt';
    		$dirs = explode('/', $file);
    		$details['dirs'][0]['DIR_NAME'] = $this->name;
    		$details['dirs'][0]['DIR_PATH'] = $this->url;
    		$num_dir = count($dirs)-1;
    		for ($i=1; $i<$num_dir; $i++) {
    			$details['dirs'][$i]['DIR_NAME'] = $dirs[$i];
    			$details['dirs'][$i]['DIR_PATH'] = $this->url . 'file=';
    			for ($j=0; $j<=$i; $j++) {
    				$details['dirs'][$i]['DIR_PATH'] .= urlencode($dirs[$j]) . '/';
    			}
    			$details['dirs'][$i]['DIR_PATH'] = substr($details['dirs'][$i]['DIR_PATH'], 0, -1);
    			$capfile = $dirs[$i] . '/' . $capfile;
    		}
    		
    		$fullpath = $this->datapath . $file;
    		$info = @getimagesize($fullpath);
    		if ($info===false) return $details;
    		$encodedpath = str_replace('%2F', '/', rawurlencode($file));
    		$details['files']['NAME'] = $dirs[$num_dir];
    		$details['files']['DATE'] = gmdate('j F Y', filemtime($fullpath));
    		$details['files']['SIZE'] = $this->convertUnit(filesize($fullpath));
    		$details['files']['DIMENSION'] = $info[0] . 'x' . $info[1] . ' pixels';
    		$details['files']['LINK'] = $this->htpath . '/data' . $encodedpath;
    		$details['files']['CAPTION'] = 'No description';
    		$details['files']['THUMB'] =
    				'<img alt="' . $details['files']['NAME'] .
    				'" src="' . $this->htpath . '/thumb.php?image=' . $encodedpath .
    				'&size=' . $this->thumb_big . '&preview=1" />';
    		
    		if (is_file($this->datapath . $capfile)) {
    			$captions = parse_ini_file($this->datapath . $capfile);
    			if (array_key_exists($details['files']['NAME'], $captions)) {
    				$details['files']['CAPTION'] = $captions[$details['files']['NAME']];
    			}
    		}
    		return $details;
    	}
    	
    	function convertUnit($byte) {
    		$kb = 1024;
    		$mb = $kb*$kb;
    		if ($byte>$mb) {
    			while (($byte/=$mb)>=$mb);
    			return round($byte, 2) . ' MB';
    		} else if ($byte>$kb) {
    			while (($byte/=$kb)>=$kb);
    			return round($byte, 2) . ' KB';
    		}
    		return $byte . ' B';
    	}
    	
    	function display() {
    		$details = array('dirs'=>array(), 'files'=>array());
    		if (isset($_GET['file'])) {
    			if (strpos($_GET['file'], '/.')===false && strpos($_GET['file'], '\\.')===false) {
    				if (is_dir($this->datapath . $_GET['file'])) {
    					$details = $this->getDirDetails($_GET['file']);
    				} else if (is_file($this->datapath . $_GET['file'])) {
    					$details = $this->getFileDetails($_GET['file']);
    					print $this->parseRecTemplate($this->parseTemplate(file_get_contents($this->template . 'preview.tpl'), $details['files']), '<!-- BEGIN -->', '<!-- END -->', $details['dirs']);
    					return;
    				} else {
    					$details = $this->getDirDetails();
    				}
    			} else {
    				$details = $this->getDirDetails();
    			}
    		} else {
    			$details = $this->getDirDetails();
    		}
    		print $this->parseRecTemplate($this->parseRecTemplate(file_get_contents($this->template . 'main.tpl'), '<!-- BEGIN1 -->', '<!-- END1 -->', $details['dirs']), '<!-- BEGIN -->', '<!-- END -->', $details['files']);
    	}
    	
    	function parseTemplate($tpl, $keys) {
    		$content = '';
    		$vars = array_keys($keys);
    		for ($i=0, $n=count($vars); $i<$n; $i++) {
    			$vars[$i] = '{' . strtoupper($vars[$i]) . '}';
    		}
    		$content = str_replace($vars, $keys, $tpl);
    		return $content;
    	}
    	
    	function parseRecTemplate($tpl, $begin, $end, $keys) {
    		$content = '';
    		$begin_pos = strpos($tpl, $begin) + strlen($begin);
    		$end_pos = strpos($tpl, $end);
    		$length = $end_pos - $begin_pos;
    		$subtpl = substr($tpl, $begin_pos, $length);
    		$num_key = count($keys);
    		$vars = $num_key>0? array_keys($keys[0]) : null;
    		for ($i=0, $n=count($vars); $i<$n; $i++) {
    			$vars[$i] = '{' . strtoupper($vars[$i]) . '}';
    		}
    		for ($i=0; $i<$num_key; $i++) {
    			$content .= str_replace($vars, $keys[$i], $subtpl);
    		}
    		return substr_replace($tpl, $content, $begin_pos, $length);
    	}
    }
    ?>


    Now, I need to implement Highslide JS, using this format...

    <a id="gallery" href="/boxart/psx/full/destiny_na.png" class="highslide" onclick="return hs.expand(this)">...</a>


    The IMG tag isn’t important, since nothing is being applied to it. The issue I’m having is trying to get the URL wrapped around it. The script’s author is using a method I’m not used to, so I can’t edit it. Like before, whoever can help me on this will be recognized in the Gallery’s "credits". smiley

    Note that the URL has the "full" link, while the IMG tag holds the thumbnail.
      My Snippets
      -> PopUpChunk v1.0
      • 4310
      • 2,310 Posts
      I did a quick port of the HighSlide Gallery a while ago.
      Your PHP code is a lot more ambitious and complex but this is the relevant piece of mine:
      echo '<a id="' . htmlspecialchars(ucfirst(preg_replace('#\..*$#', '', $file))) . '" href="' . $file_dir . '' . rawurlencode($file) . '" class="highslide" onclick="return hs.expand(this)">
      		<img src="'.$thumbs_dir.''. rawurlencode($file) . '" class="'.$Tclass.'" alt="' . htmlspecialchars(ucfirst(preg_replace('#\..*$#', '', $file))) . '" 	title="Click to enlarge" /></a>';
              echo "\r\n";

      Feel free to download my version from my signature and use whatever you want.

      David
        • 28033
        • 925 Posts
        Thanks. I’ll see if I can get that to work w/ my script. smiley
          My Snippets
          -> PopUpChunk v1.0