Permalink
Browse files

adding tag iterating and updating readme

  • Loading branch information...
1 parent 43137b1 commit bae77e786f7d80b98bb4fd5e163a741ae98dd6f4 @bryantAXS committed Jan 24, 2012
Showing with 280 additions and 18 deletions.
  1. +230 −2 README.md
  2. +50 −16 system/expressionengine/third_party/tgl_instagram/mod.tgl_instagram.php
View
232 README.md
@@ -1,5 +1,233 @@
# TGL Instagram API
-## This module is not ready to be relased yet, I should have it finalized in the next day or so and will upload it to Devot-ee. Feel free to test if you would like, however it should not be considered production worthy.
+Version 1.0
+
+This is an ExpressionEngine 2 module for interacting with the Instagram API. Currently, the module only retrieves information from the authenticated user's feed and a specified user's feed. The module has a CP backend, which directs the user through the oAuth process.
+
+## Tag Pairs
+
+The following tags can be used for looping through images:
+
+ {exp:tgl_instagram:feed}{/exp:tgl_instagram}
+
+This tag loops through the authenticated user's feed. The feed displays pictures from other instagram user's the authenticated user follows as well as their own images.
+
+__Parameters__
+
+ limit
+
+the number of images you want to see
+
+ {exp:tgl_instagram:user_feed}{/exp:tgl_instagram}
+
+This tag loops though a specified user's feed, and only displays image they have shared.
+
+__Parameters__
+
+ limit
+
+the number of images you want to display
+
+ username
+
+the username of the specific user, who you want to display images from.
+
+## Image Data
+
+These tags can be used within the above tag pairs.
+
+ {filter}
+
+The filer used on the image
+
+ {created_at}
+
+Timestamp of when the image was created
+
+ {link}
+
+Link to Instagram's site displaying the picture
+
+ {caption}
+
+Image's caption
+
+ {username}
+
+The username of the user who submitted the image
+
+ {website}
+
+The website of the user who submitted the image
+
+ {bio}
+
+The bio of the user who submitted the image
+
+ {profile_picture}
+
+The profile picture of the user who submitted the image
+
+ {full_name}
+
+The full name of the user who sumitted the image
+
+ {thumbnail_url}
+
+The url to the thumbnail version of the image (150px x 150px)
+
+ {thumbnail}
+
+The thumbnail version of the image, wrapped in an <img> tag (150px x 150px)
+
+ {low_resolution_url}
+
+The url to the low resolution version of the image (306px x 306px)
+
+ {low_resolution}
+
+The low resolution version of the image, wrapped in an <img> tag (306px x 306px)
+
+ {standard_resolution_url}
+
+The url to the standard resolution version of the image (612px x 612px)
+
+ {standard_resolution}
+
+The standard resolution version of the image, wrapped in an <img> tag (612px x 612px)
+
+ {tag_count}
+
+Number of tags for the specific images
+
+ {likes_count}
+
+Number of "likes" for the specific image
+
+ {comment_count}
+
+Number of comments for the specific image
+
+
+## Image Data Tag Pairs
+
+Within each image's loop, there are a few more items you can loop over to get more information about each image
+
+### Comments
+
+ {comments}{/comments}
+
+Loop over the comments for each picture
+
+#### Single Tags
+
+ {comment_text}
+
+Text from a specific comment
+
+ {comment_usernam}
+
+Username from the user who submitted the comment
+
+ {comment_profile_picture}
+
+The profile picture from the user who submitted the comment
+
+ {comment_full_name}
+
+The full name of the user who submitted the comment
+
+### Likes
+
+ {likes}{/likes}
+
+Loop over each image's likes
+
+#### Single Tags
+
+ {like_username}
+
+Username of the user who liked the photo
+
+ {like_full_name}
+
+Full name of the user who liked the photo
+
+ {like_profile_picture}
+
+Profile picture of the user who liked the photo
+
+### Tags
+
+ {tags}{/tags}
+
+Loop over each images tags
+
+#### Single Tags
+
+ {tag}
+
+The tag name
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-This is an ExpressionEngine 2 module for interacting with the Instagram API. Currently, the module only retrieves information from the authenticated user's feed and a specified user's feed. The module has a CP backend, which directs the user through the oAuth process.
View
66 system/expressionengine/third_party/tgl_instagram/mod.tgl_instagram.php
@@ -56,11 +56,15 @@ function feed(){
//params from the template tag
$params = array();
+ $params['cache'] = (integer) $this->EE->TMPL->fetch_param('cache', $this->refresh_cache);
$params['limit'] = $this->EE->TMPL->fetch_param('limit', null);
//check to see if we have cached data to use
if($cached_data = $this->_check_cache($params)){
- return $cached_data;
+ if(! $this->cache_expired){
+ echo 'cached';
+ return $cached_data;
+ }
}
//no cache data to use, lets hit the api
@@ -114,15 +118,19 @@ function user_feed(){
$params = array();
$params['user_name'] = $this->EE->TMPL->fetch_param('username');
$params['limit'] = $this->EE->TMPL->fetch_param('limit');
+ $params['cache'] = (integer) $this->EE->TMPL->fetch_param('cache', $this->refresh_cache);
//make sure we have the required parameters
if(! isset($params['user_name']))
{
return FALSE;
}
+ //check to see if we have cached data to use
if($cached_data = $this->_check_cache($params)){
- return $cached_data;
+ if(! $this->cache_expired){
+ return $cached_data;
+ }
}
//get the user id for the api call
@@ -175,46 +183,53 @@ function _parse_row_data($data, $row_variables = null)
if(! $row_variables) $row_variables = array();
//static data
- //$row_variables['tags'] = $data['tags'];
$row_variables['filter'] = $data['filter'];
$row_variables['created_at'] = $data['created_time'];
$row_variables['link'] = $data['link'];
+ $row_variables['tag_count'] = count($data['tags']);
+ if(count($data['tags']) > 0){
+ $row_variables['tags'] = $this->_parse_tags($data['tags']);
+ }else{
+ $row_variables['tags'] = array();
+ }
+
//caption
if(count($data['caption']) > 0){
$row_variables['caption'] = $data['caption']['text'];
+ }else{
+ $row_variables['caption'] = "";
}
//comments
if(count($data['comments']) > 0){
-
$row_variables['comment_count'] = $data['comments']['count'];
$row_variables['comments'] = $this->_parse_comments($data['comments']['data']);
}
+ //likes
+ if(count($data['likes']) > 0){
+ $row_variables['likes_count'] = $data['likes']['count'];
+ $row_variables['likes'] = $this->_parse_likes($data['likes']['data']);
+ }
+
//user
$row_variables['username'] = $data['user']['username'];
$row_variables['website'] = $data['user']['website'];
$row_variables['bio'] = $data['user']['bio'];
$row_variables['profile_picture'] = $data['user']['profile_picture'];
$row_variables['full_name'] = $data['user']['full_name'];
+
//images
$row_variables['thumbnail_url'] = $data['images']['thumbnail']['url'];
$row_variables['thumbnail'] = "<img src='".$data['images']['thumbnail']['url']."' width='".$data['images']['thumbnail']['width']."' height='".$data['images']['thumbnail']['height']."'/>";
- //likes
- if(count($data['likes']) > 0){
-
- $row_variables['likes_count'] = $data['likes']['count'];
- $row_variables['likes'] = $this->_parse_likes($data['likes']['data']);
- }
-
- $row_variables['low_url'] = $data['images']['low_resolution']['url'];
- $row_variables['low'] = "<img src='".$data['images']['low_resolution']['url']."' width='".$data['images']['low_resolution']['width']."' height='".$data['images']['low_resolution']['height']."'/>";
+ $row_variables['low_resolution_url'] = $data['images']['low_resolution']['url'];
+ $row_variables['low_resolution'] = "<img src='".$data['images']['low_resolution']['url']."' width='".$data['images']['low_resolution']['width']."' height='".$data['images']['low_resolution']['height']."'/>";
- $row_variables['standard_url'] = $data['images']['standard_resolution']['url'];
- $row_variables['standard'] = "<img src='".$data['images']['standard_resolution']['url']."' width='".$data['images']['standard_resolution']['width']."' height='".$data['images']['standard_resolution']['height']."'/>";
+ $row_variables['standard_resolution_url'] = $data['images']['standard_resolution']['url'];
+ $row_variables['standard_resolution'] = "<img src='".$data['images']['standard_resolution']['url']."' width='".$data['images']['standard_resolution']['width']."' height='".$data['images']['standard_resolution']['height']."'/>";
return $row_variables;
@@ -269,6 +284,25 @@ function _parse_likes($data)
}
/**
+ * set tags data from the api
+ * @param array $data tags data from the api
+ * @return array
+ */
+ function _parse_tags($data)
+ {
+
+ $tags = array();
+
+ foreach ($data as $tag_name)
+ {
+ $tags[] = array('tag' => $tag_name);
+ }
+
+ return $tags;
+
+ }
+
+ /**
* Given the user's user name, it will return the user id
* @param string $username user's instagram hand;e
* @return string/int
@@ -354,7 +388,7 @@ function _check_cache($cache_params)
$timestamp = substr($cache, 0, $eol);
$cache = trim((substr($cache, $eol)));
- if ( time() > ($timestamp + ($this->refresh_cache * 60)) )
+ if((time() > ($timestamp + ($cache_params['cache'] * 60))) || $cache_params['cache'] == 0)
{
$this->cache_expired = TRUE;
}

0 comments on commit bae77e7

Please sign in to comment.