Location: PHPKode > scripts > SelectaPix Image Gallery > classes/cat.php
<?php
/* +----------------------------------------------------------------------+
   |SelectaPix Open Source Gallery	                                      |
   +----------------------------------------------------------------------+
   | Copyright (c) 2004 OutOfTheTrees			                          |
   |                                                                      |
   | http://www.outofthetrees.co.uk/index.php                             |
   | 												                      |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.0 of the GPL license,       |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.outofthetrees.co.uk/license/2_0.txt.                      |
   | If you did not receive a copy of the SelectaPix license and are 	  |
   | unable to obtain it through the world-wide-web, please send a note   |
   | to hide@address.com so we can mail you a copy immediately.|
   +----------------------------------------------------------------------+ */
if (!defined("ACCESS")) {
    die ("Direct request denied");
}

class Page {
	var $f;

	function Page($f) {
		$this->f =& $f;
		$this->stylesheet = STYLESHEET;
		$this->site_name = SITE_NAME;
		$this->site_url = SITE_URL;
		$this->site_path = SITE_PATH;
		$this->site_dir = SITE_DIR;
		$this->img_dir = IMAGE_DIR;
		$this->top_cat = TOP_CAT_NAME;
		$this->album_table = SQL_ABM_TBL;
		$this->image_table = SQL_IMG_TBL;
		$this->images_per_page = IMAGES_PER_PAGE;
	}

	function stylesheet() {
		return $this->stylesheet;
	}

	function pagetitle() {
		return $this->GetPageTitle();
	}

	function crumbs() {
		echo $this->breadcrumbs($_GET['albumID']);
	}

	function SetPageTitle($newpagetitle) {
    	$this->pagetitle = $newpagetitle;
  	}

  	function GetPageTitle() {
  		return $this->pagetitle;
  	}

  	// Expand albumID to whole trail
	function breadcrumbs($albumID='') {
		if(empty($albumID)) {
			$trail .= $this->top_cat;
		}
		$albumID = $this->f->util->ForceInt($albumID, 0);
		$this->get_ParentsInt($albumID);
		$path = $this->trail;
		if(!empty($path)) {
			for($i=0; $i<count($path); $i++) {
				if($this->IsURLCurrentPage('albumID='.$path[$i]['albumID'])==false) {
					$trail = "&nbsp;&gt;&gt;&nbsp;<a href=\"view_album.php?albumID=".$path[$i]['albumID']."\" title=\"Jump to this category\">".$path[$i]['album_name']."</a>$trail\n";
				}
				else {
					$trail = $trail."&nbsp;&gt;&gt;&nbsp;".$path[$i]['album_name']."\n";
				}
				if($i==(count($path)-1)) {
					$trail = '<a href="index.php" title="Back to the '.$this->top_cat.' page">'.$this->top_cat.'</a>'.$trail;
				}
			}
		}
		else {
			$trail = $this->top_cat;
		}
		$trail = '<div id="breadcrumbtrail">'.$trail.'</div>';
		return $trail;
	}

	// The primer for a recursive query
	function get_ParentsInt($albumID='') {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		if((empty($albumID)) || ($albumID == "0")) {
			return false;
		}
		unset($this->trail);
		$this->trail = array();
		$this->get_Parents($albumID);
	}

	// Do not call this function directly - use get_ParentsInt() instead
	function get_Parents ($albumID='') {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		if((empty($albumID)) || ($albumID == 'NULL')) {
			return false;
		}
		$result = $this->f->conn->query("SELECT albumID, parent_albumID, album_name
										 FROM $this->album_table
										 WHERE albumID = $albumID");
		if(!$result) {
			$this->f->conn->freeResult();
			return false;
		}
		for($i=0; $i<count($result); $i++) {
			$trail = $this->trail;
			$count = count($trail);
			$trail[$count] = $result[$i];
			$this->trail = $trail;
			$id = $result[$i]['parent_albumID'];
			$this->get_Parents($id);
		}
		return true;
	}

  	function IsURLCurrentPage($url) {
  		if(strstr($_SERVER["PHP_SELF"].$_SERVER['QUERY_STRING'], $url )==false) {
			return false;
		}
		else {
			return true;
		}
	}

	function get_album_name($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT album_name
				   	  		 FROM $this->album_table
				      		 WHERE albumid = $albumID";
	}

	function get_album_images($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT *
					   	     FROM $this->image_table AS i
					         LEFT JOIN $this->album_table AS a ON i.albumID = a.albumID
					         WHERE i.albumid = '$albumID'
					         AND i.approved = 'yes'
							 AND i.active = 'yes'";
	}

	function get_album_images_count($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT COUNT(*)
					   	     FROM $this->image_table AS i
					         LEFT JOIN $this->album_table AS a ON i.albumID = a.albumID
					         WHERE i.albumid = '$albumID'
					         AND i.approved = 'yes'
							 AND i.active = 'yes'";
	}

	function get_album_images_by_limit($albumID, $start, $limit) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT *
					   	     FROM $this->image_table AS i
					         LEFT JOIN $this->album_table AS a ON i.albumID = a.albumID
					         WHERE i.albumid = '$albumID'
					         AND i.approved = 'yes'
							 AND i.active = 'yes'
							 LIMIT ".$start.", ".$limit;
	}

	function get_min_albumid() {
		return $this->sql = "SELECT MIN(albumid)
						   	 FROM $this->album_table
							 WHERE album_name <> 'upload_temp'
							 AND active = 'yes'";
	}

	function get_albums_by_parentID($parent_albumID) {
		$parent_albumID = $this->f->util->ForceInt($parent_albumID, 0);
		return $this->sql = "SELECT a.albumID, a.album_name, a.album_descr, COUNT(i.imageID)
							 FROM $this->album_table AS a
							 LEFT JOIN $this->image_table AS i ON a.albumID = i.albumID
							 WHERE a.parent_albumID = '$parent_albumID'
							 AND a.active = 'yes'
							 GROUP BY a.albumID";
	}

	function is_parent($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT IF(parent_albumID = '0', 1, 0)
							 FROM $this->album_table
							 WHERE albumID = '$albumID'";
	}

	function get_parent_albums() {
		return $this->sql = "SELECT albumID, album_name, album_descr
							 FROM $this->album_table
							 WHERE album_name <> 'upload_temp'
							 AND parent_albumID = 0
							 AND active = 'yes'";
	}

	function get_children_by_parentID($parent_albumID) {
		$parent_albumID = $this->f->util->ForceInt($parent_albumID, 0);
		return $this->sql = "SELECT albumID, album_name
							 FROM $this->album_table
							 WHERE album_name <> 'upload_temp'
							 AND parent_albumID = '$parent_albumID'
							 AND active = 'yes'";
	}

	function get_latest_image($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT MAX(upload_date), imageID, image_url, caption, description
					   	     FROM $this->image_table
					         WHERE albumid = '$albumID'
					         AND approved = 'yes'
							 AND active = 'yes'
							 GROUP BY upload_date
							 ORDER BY upload_date DESC
							 LIMIT 1";
	}

	function get_siblings($albumID) {
		$albumID = $this->f->util->ForceInt($albumID, 0);
		return $this->sql = "SELECT a2.albumID, a2.album_name
							 FROM $this->album_table AS a1
							 LEFT JOIN $this->album_table AS a2 ON a1.parent_albumID = a2.parent_albumID
							 WHERE a2.album_name <> 'upload_temp'
							 AND a1.albumID = '$albumID'
							 AND a2.albumID <> '$albumID'
							 AND a2.active = 'yes'";
	}

	function get_image_data($imageID) {
		$imageID = $this->f->util->ForceInt($imageID, 0);
		return $this->sql = "SELECT *
							 FROM $this->image_table
							 WHERE imageID = '$imageID'";
	}
}
?>
Return current item: SelectaPix Image Gallery