Location: PHPKode > scripts > phpFlickrSynch > phpflickrsynch/_publicApi/class_Photo.php
<?php
	/**
	  * Class to access a specific photo in the photo collection
	  */
	class Photo {
	
		private $porId = 0;
		private $imgId = 0;
		private $flickrId = '';
		private $DB = NULL;
		private $details = array();
		private $previousnextones = NULL;
			
		/**
		  * Constructor.
		  * Checks if a photo with the given ID exists in the DB
		  * Retrieve properties of the photo
		  * @param $imgId Photo ID
		  */	
		function __construct($imgId) {
			$this->imgId = $imgId;			
			$this->DB = new TableFlickrPhoto();
			$res = $this->DB->checkImage($imgId);
			
			if ($res == NULL) { 
				throw new Exception('Photo ' . $imgId . ' not found in local database');
			} else {
				$this->porId = $res[1];
				$this->flickrId = $res[0];
				$this->details = $this->DB->getDetails($imgId);
			}
		}

		/**
		  * @return the ID of the photo album this photo belongs to
		  */
		public function getPhotoAlbumId() { return $this->porId;}

		/**
		  * @return the ID of the previous photo in the photo album
		  */
		public function getPreviousPhoto() {
			$res = $this->getPreviousNextOnes();
			return $res[0];
		}
		
		/**
		  * @return the ID of the next photo in the photo album
		  */
		public function getNextPhoto() {
			$res = $this->getPreviousNextOnes();
			return $res[1];
		}
		
		/**
		  * @return Array with 0 index containing the photo ID of the previous one ; 1 index the ID of the next ones
		  */
		private function getPreviousNextOnes() {
			if ($this->previousnextones == NULL) {
				$this->previousnextones = $this->DB->getPreviousNextOnes($this->porId, $this->imgId);
			}
			return $this->previousnextones;
		}
		
		/**
		  * @return the title of the photo
		  */
		public function getTitle() { return $this->details['title'];}
		
		/**
		  * @return the description of the photo
		  */
		public function getDescription() { return $this->details['description'];}

		/**
		  * @param $size The size of the photo according to Flickr ('Medium', 'Thumbnail'...)
		  * @return An array containing the URL of the image, its width and height
		  */
		public function getImage($size = 'Medium') {
			$F = new FlickrUtils();	
			$field = $F->getSizeField($size);											
			return $F->buildPhotoURL($this->details['farm'], $this->details['server'], $this->flickrId, $this->details['secret'], $this->details['originalsecret'], $this->details['originalformat'], $size, $this->details[$field]);								 		
		}

		/**
		  * Apply some transformation on raw description for better display
		  * Transform carriage returns into <br> tags
		  * @return description to be displayed
		  */
		public function getDisplayDescription() {
			$order = array("\r\n", "\n", "\r");
			$replace = '<br/>';
			return str_replace($order, $replace, $this->getDescription());			
		}

		/**
		  * Remove all HTML tags from the description
		  * @return stripped descripion
		  */
		public function getStrippedDescription() {
			return strip_tags($this->getDescription());
		}

		/**
		  * Retrieve all the tags associated to the photo
		  * @return a list of (tagId / tagName)
		  */
		public function getTags() {
			$T = new TableFlickrTag();
			return $T->getImageTags($this->imgId);
		}

		/**
		  * @return the camera model the photo has been taken with. I.E: Canon EOS 40D
		  */		
		public function getCameraModel() { return $this->details['model']; }
		
		/**
		  * @return the exposure of the photo (formatted to be displayed). I.E: "0.002 sec (1/640)"
		  */			
		public function getCameraExposure() { return $this->details['exposure']; }
		
		/**
		  * @return the focal length of the photo
		  */		
		public function getCameraFocalLength() { return $this->details['focal_length']; }

		/**
		  * @return the aperture used to take the photo
		  */	
		public function getCameraAperture() { return $this->details['aperture']; }
		
		/**
		  * @return the ISO speed used to take the photo
		  */			
		public function getIsoSpeed() { return $this->details['iso_speed']; }
		
		/**
		  * @return the shot date
		  */			
		public function getShotDate() { return $this->details['datetime']; }

		/**
		  * @return the WhereOnEarth ID of the place where the photo was taken - see http://developer.yahoo.com/geo/ for reference
		  */
		public function getWoeid() { return $this->details['woeid']; }

		/**
		  * @return A string indicated the precise location of the place where the photo was taken. I.e: "Les Allues, Savoy, Rhone-Alpes, France"
		  */
		public function getLocation() {
			if ($this->getWoeid() != 0) {
				$L = new Location($this->getWoeid());
				return $L->getName();
			} else {
				return NULL;
			}
		}

		/**
		  * @return The URL of the corresponding Flickr page
		  */
		public function getFlickrURL() {
			return $this->details['flickr_url'];
		}

		/**
		  * @return true/false if the photo is geo-tagged or not
		  */
		public function hasCoordinates() { return isset($this->details['lat']); }

		/**
		  * @return The latitude where the photo has been taken in numerical value
		  */
		public function getLatitude() { return $this->details['lat'];}
		
		/**
		  * @return The longitude where the photo has been taken in numerical value
		  */		
		public function getLongitude() { return $this->details['lon'];}
		
		/**
		  * @return The latitude where the photo has been taken in Degree/Minute/Second
		  */		
		public function getDMSLatitude() { $G = new GeoUtils();return $G->getDMSLatitude($this->getLatitude());}
		
		/**
		  * @return The latitude where the photo has been taken in Degree/Minute/Second
		  */		
		public function getDMSLongitude() { $G = new GeoUtils(); return $G->getDMSLongitude($this->getLongitude());}


		/**
		  * Returns a list of photos taken near-by the current photo
		  * @param $limit Max number of photos to be retrieved
		  * @return An array containing list of photos
		  */
		public function getNearbyPhotos($limit = 10) {
			$res = array();
			$woeid = $this->getWoeid();			
			if ($woeid > 0) {
				$res = $this->DB->getNearbyPhotos($woeid, $limit);			
			}
			return $res;
		}
		
		/**
		  * Returns a list of geotagged photos in the same photo album as the current photo 
		  * @param $limit Max number of photos to be retrieved
		  * @return An array containing list of photos
		  */		
		public function getPhotosInSameAlbumWithGeoData($limit = 50) {
			return $this->DB->getPhotosWithGeoData($this->porId, $limit);
		}
	}
?>
Return current item: phpFlickrSynch