Location: PHPKode > projects > Banshee PHP Framework > controllers/photo.php
<?php
	class photo_controller extends controller {
		private $extension = array(
			"image/gif"  => "gif",
			"image/jpeg" => "jpg",
			"image/png"  => "png");

		private function show_albums() {
			if (($count = $this->model->count_albums()) === false) {
				$this->output->add_tag("result", "Database error counting albums");
				return;
			}

			$paging = new pagination($this->output, "photo_albums", $this->settings->photo_page_size, $count);

			if (($albums = $this->model->get_albums($paging->offset, $paging->size)) === false) {
				$this->output->add_tag("result", "Database error retrieving albums");
				return;
			} else if (count($albums) == 0) {
				$this->output->add_tag("result", "No photo albums have been created.");
				return;
			}

			$this->output->open_tag("overview");

			$this->output->open_tag("albums");
			foreach ($albums as $album) {
				if (isset($album["content_type"])) {
					$album["extension"] = $this->extension[$album["content_type"]];
				}
				$this->output->record($album, "album");
			}
			$this->output->close_tag();

			$paging->show_browse_links();

			$this->output->close_tag();
		}

		private function show_album($album_id) {
			if (($photos = $this->model->get_photo_info($album_id)) === false) {
				$this->output->add_tag("result", "Database error retrieving photos");
				return;
			} else if (count($photos) == 0) {
				$this->output->add_tag("result", "Photo album is empty.");
				return;
			}

			$this->output->open_tag("photos");
			foreach ($photos as $photo) {
				$photo["extension"] = $this->extension[$photo["content_type"]];
				$this->output->record($photo, "photo");
			}
			$this->output->close_tag();

			$this->output->add_javascript("jquery/jquery.js");
			$this->output->add_javascript("jquery/lightbox.js");
			$this->output->add_javascript("photo.js");

			$this->output->add_css("includes/lightbox.css");
		}

		private function show_photo($photo, $type) {
			list($photo_id, $extension) = explode(".", $photo, 2);

			if (in_array($extension, $this->extension) == false) {
				header("Status: 404");
				return;
			}

			$function = "get_".$type;
			$photo = $this->model->$function($photo_id);

			if ($photo == false) {
				header("Status: 500");
				return;
			}

			if ($this->extension[$photo["content_type"]] != $extension) {
				header("Status: 404");
				return;
			}

			header("Content-Type: ".$photo["content_type"]);
			print $photo[$type];

			$this->output->disabled = true;
		}

		public function execute() {
			if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
				$this->show_album($this->page->pathinfo[1]);
			} else if (substr($this->page->pathinfo[1], 0, 6) == "image_") {
				$this->show_photo(substr($this->page->pathinfo[1], 6), "image");
			} else if (substr($this->page->pathinfo[1], 0, 10) == "thumbnail_") {
				$this->show_photo(substr($this->page->pathinfo[1], 10), "thumbnail");
			} else {
				$this->show_albums();
			}
		}
	}
?>
Return current item: Banshee PHP Framework