function sb_social_tumblr($account, $limit = 10)
{
    $client = new Tumblr\API\Client(TUMBLR_API_KEY);
    $data = $client->getBlogPosts($account, array("limit" => $limit, "filter" => "text"));
    $output = array();
    foreach ($data->posts as $status) {
        $content = "";
        $image = "";
        switch ($status->type) {
            case "text":
                $content = "<a href=\"{$status->post_url}\">{$status->summary}</a> ";
                break;
            case "link":
                $content = "<a href=\"{$status->url}\">{$status->title}</a> &mdash; {$status->description}";
                break;
            case "photo":
                $content = $status->summary;
                $image = $status->photos[0]->alt_sizes[3]->url;
                break;
            case "video":
                $content = $status->summary;
                $image = $status->thumbnail_url;
                break;
        }
        $output[] = array("source" => "tumblr", "permalink" => $status->post_url, "timestamp" => strtotime($status->date), "content" => $content, "image" => $image);
    }
    return $output;
}
function getBlogData($marketName)
{
    //create client
    $consumerKey = "Add your Key";
    $consumerSecret = "Add Secret key";
    $blogName = 'yr_username.tumblr.com';
    $client = new Tumblr\API\Client($consumerKey, $consumerSecret);
    $response = $client->getBlogPosts($blogName, array('tag' => $marketName));
    // get posts
    $posts = $response->posts;
    $blogs = $response->blog;
    global $dataId;
    $x = 0;
    foreach ($posts as $post) {
        if (isset($post->title)) {
            if (isset($post->body)) {
                $dataArray[] = array('imageSrc' => getImgSrc($post->body, "<img", "/>"), 'title' => $post->title, 'tags' => convertTagsIntoString(array_map('strval', $post->tags)), 'description' => trimblanklines(trimblankspaces(shortenedDescription(getDescription($post->body, "</p>", $dataId), 250))), 'postId' => $post->id);
            }
        }
        $x++;
    }
    return $dataArray;
}
 /**
  * Get posts for a given blog
  *
  * @param integer $limit   number of results to return, max DEFAULT_LIMIT
  * @param integer $offset  number of beginning position for retrieval 
  * @param string  $type    the type of post to retrieve, or blank for all
  * @param array   $options associative array of API options
  *
  * @return \StdClass containing json decoded API results
  */
 public function TumblrPostsList($limit = self::DEFAULT_LIMIT, $offset = 0, $type = "", $options = array())
 {
     $config = SiteConfig::current_site_config();
     if (!$this->checkConfig($config)) {
         return new ArrayList();
     } else {
         $cache_key = __FUNCTION__ . '_' . md5($limit . $offset . $type . implode($options));
         $cache = SS_Cache::factory('tumblr_api_cache');
         if (!($results = unserialize($cache->load($cache_key)))) {
             $results = new ArrayList();
             if (!empty($type) && defined('self::POST_TYPE_' . strtoupper($type))) {
                 $options[self::OPTION_TYPE] = $type;
             }
             if (is_numeric($limit) && $limit > 0 && $limit <= self::DEFAULT_LIMIT) {
                 $options[self::OPTION_LIMIT] = $limit;
             }
             if (is_numeric($offset) && $offset > 0) {
                 $options[self::OPTION_OFFSET] = $offset;
             }
             $client = new Tumblr\API\Client($config->TumblrConsumerKey, $config->TumblrConsumerSecret);
             try {
                 $response = $client->getBlogPosts($config->TumblrBlogName, $options);
                 foreach ($response->posts as $post) {
                     $results->push(self::recursive_conversion_iterator($post));
                 }
             } catch (RequestException $e) {
                 // *** maybe we should do something?
             }
             $cache->save(serialize($results), $cache_key);
         }
     }
     return $results;
 }
 public function likes()
 {
     $display = '';
     // Authenticate via OAuth
     $client = new \Tumblr\API\Client(env('BH_TUMBLR_CONSUMER_KEY'), env('BH_TUMBLR_CONSUMER_SECRET'), env('BH_TUMBLR_TOKEN'), env('BH_TUMBLR_TOKEN_SECRET'));
     $continue = TRUE;
     $offset = 0;
     while ($continue) {
         // Make the request
         $reply = $client->getBlogPosts('bobhumphreyphotography', array('offset' => $offset, 'reblog_info' => true, 'notes_info' => true));
         $posts = $reply->posts;
         if (count($posts)) {
             foreach ($posts as $post) {
                 $note_count = 0;
                 $note_count_last10 = 0;
                 $note_count_last30 = 0;
                 if (property_exists($post, 'notes')) {
                     $notes = $post->notes;
                     foreach ($notes as $note) {
                         $timestamp = $note->timestamp;
                         $noteTime = Carbon::createFromTimestamp($timestamp);
                         $daysAgo = $noteTime->diffInDays();
                         $note_count++;
                         if ($daysAgo <= 10) {
                             $note_count_last10++;
                         }
                         if ($daysAgo <= 30) {
                             $note_count_last30++;
                         }
                     }
                 }
                 $post_url = $post->post_url;
                 $photo = DB::table('photo')->where('url', $post_url)->first();
                 if ($photo) {
                     DB::table('photo')->where('url', $post_url)->update(['notes' => $note_count, 'notes_last30' => $note_count_last30, 'notes_last10' => $note_count_last10]);
                 }
                 //$notes_count = count($notes);
                 //\Debugbar::info($photo->url);
                 \Debugbar::info($note_count . '--' . $note_count_last30 . '--' . $note_count_last10);
             }
             $offset = $offset + 20;
         } else {
             $continue = FALSE;
         }
     }
     //\Debugbar::info($posts);
     return view('photos.likes');
 }