5 * @author Galen Grover <galenjr@gmail.com>
6 * @license http://opensource.org/licenses/mit-license.php The MIT License
11 use \Instagram\Comment;
13 use \Instagram\Location;
14 use \Instagram\Collection\CommentCollection;
15 use \Instagram\Collection\TagCollection;
16 use \Instagram\Collection\UserCollection;
21 * @see \Instagram\Instagram->getLocation()
22 * {@link https://github.com/galen/PHP-Instagram-API/blob/master/Examples/media.php}
23 * {@link http://galengrover.com/projects/instagram/?example=media.php}
25 class Media extends \Instagram\Core\BaseObjectAbstract {
30 * @var \Instagram\User
32 protected $user = null;
37 * @var \Instagram\Collection\CommentCollection
39 protected $comments = null;
44 * @var \Instagram\Location
46 protected $location = null;
51 * @var \Instagram\Collection\TagCollection
53 protected $tags = null;
62 public function getId() {
63 return $this->data->id;
72 public function getType() {
73 return $this->data->type;
82 public function getThumbnail() {
83 return $this->data->images->thumbnail;
87 * Get the standard resolution video
92 public function getStandardResVideo() {
93 return $this->data->videos->standard_resolution;
97 * Get the low resolution video
102 public function getLowResVideo() {
103 return $this->data->videos->low_resolution;
107 * Get the standard resolution image
112 public function getStandardResImage() {
113 return $this->data->images->standard_resolution;
117 * Get the low resolution image
122 public function getLowResImage() {
123 return $this->data->images->low_resolution;
127 * Get the standard resolution image
129 * Alias for getStandardResImage since Instagram added videos
134 public function getStandardRes() {
135 return $this->getStandardResImage();
139 * Get the low resolution image
141 * Alias for getLowResImage since Instagram added videos
146 public function getLowRes() {
147 return $this->getLowResImage();
151 * Get the media caption
156 public function getCaption() {
157 if ( $this->data->caption ) {
158 return new Comment( $this->data->caption );
164 * Get the created time
166 * @param string $format {@link http://php.net/manual/en/function.date.php}
170 public function getCreatedTime( $format = null ) {
172 $date = date( $format, $this->data->created_time );
175 $date = $this->data->created_time;
181 * Get the user that posted the media
183 * @return \Instagram\User
186 public function getUser() {
187 if ( !$this->user ) {
188 $this->user = new User( $this->data->user, $this->proxy );
196 * Return all the comments associated with a media
198 * @return \Instagram\CommentCollection
201 public function getComments() {
202 if ( !$this->comments ) {
203 $this->comments = new CommentCollection( $this->proxy->getMediaComments( $this->getApiId() ), $this->proxy );
205 return $this->comments;
209 * Get the media filter
214 public function getFilter() {
215 return $this->data->filter;
219 * Get the media's tags
221 * @return \Instagram\Collection\TagCollection
224 public function getTags() {
225 if ( !$this->tags ) {
226 $this->tags = new TagCollection( $this->data->tags, $this->proxy );
232 * Get the media's link
237 public function getLink() {
238 return $this->data->link;
242 * Get the media's likes count
247 public function getLikesCount() {
248 return (int)$this->data->likes->count;
254 * Media objects contain the first 10 likes. You can get these likes by passing `false`
255 * to this method. Using the internal likes of a media object cause issues when liking/disliking media.
257 * @param bool $fetch_from_api Query the API or use internal
258 * @return \Instagram\UserCollection
261 public function getLikes( $fetch_from_api = true ) {
262 if ( !$fetch_from_api ) {
263 return new UserCollection( $this->data->likes );
265 $user_collection = new UserCollection( $this->proxy->getMediaLikes( $this->getApiId() ), $this->proxy );
266 $user_collection->setProxies( $this->proxy );
267 $this->likes = $user_collection;
272 * Get location status
274 * Will return true if any location data is associated with the media
279 public function hasLocation() {
280 return isset( $this->data->location->latitude ) && isset( $this->data->location->longitude );
284 * Get location status
286 * Will return true if the media has a named location attached to it
288 * Some media only has lat/lng data
293 public function hasNamedLocation() {
294 return isset( $this->data->location->id );
300 * Returns the location associated with the media or null if no location data is available
302 * @param bool $force_fetch Don't use the cache
303 * @return \Instagram\Location|null
306 public function getLocation( $force_fetch = false ) {
307 if ( !$this->hasLocation() ) {
310 if ( !$this->location || (bool)$force_fetch ) {
311 $this->location = new Location( $this->data->location, isset( $this->data->location->id ) ? $this->proxy : null );
313 return $this->location;
317 * Magic toString method
319 * Returns the media's thumbnail url
324 public function __toString() {
325 return $this->getThumbnail()->url;