public function getPictures($blogName)
    {
        $dotenv = new \Dotenv\Dotenv('.');
        $dotenv->load();
        $consumer = getenv('TUMBLR_ACCESS_TOKEN');
        $client = new Client($consumer);
        try {
            $blog = $client->getBlogPosts($blogName . '.tumblr.com');
        } catch (Exception $e) {
            echo $e->getMessage('Unknown blog ', $blogName, '');
            return false;
        }
        $post = $blog->posts;
        $images = array();
        echo '<div class="container">
             <div class="row">';
        for ($i = 0; $i < count($post); $i++) {
            if (isset($post[$i]->image_permalink)) {
                ?>
                <div class="col-md-3 col-sm-4 col-xs-6 thumb">
                    <img class="img-responsive"
                         src="<?php 
                echo $images[$i] = $post[$i]->photos[0]->original_size->url;
                ?>
"/>
                </div>
                <?php 
                $images[$i] = $post[$i]->photos[0]->original_size->url;
            }
        }
        echo '</div>
              </div> ';
        return $images;
    }
Example #2
0
 /**
  * @return array
  */
 public function getPosts() : array
 {
     if ($this->redisClient !== null) {
         $posts = $this->redisClient->get('posts');
         if ($posts) {
             return json_decode($posts, true);
         }
     }
     $blog = $this->getBlogInfo();
     $posts = $this->thumblrClient->getBlogPosts($blog['name'], ['type' => 'text'])->posts;
     $posts = json_encode($posts, JSON_PRETTY_PRINT);
     if ($this->redisClient !== null) {
         $this->redisClient->set('posts', $posts);
         $this->redisClient->expireat('posts', time() + 3600);
     }
     return json_decode($posts, true);
 }
Example #3
0
 public static function latest()
 {
     $cacheKey = 'posts_latest';
     if ($cached = Cache::read('default', $cacheKey)) {
         return $cached;
     }
     $config = static::$_serviceConfig;
     try {
         $client = new Tumblr($config['consumerKey'], $config['consumerSecret'], $config['token'], $config['tokenSecret']);
         $results = $client->getBlogPosts($config['name'], ['limit' => 2]);
         $results = $results->posts;
     } catch (CurlException $e) {
         return [];
     } catch (Exception $e) {
         return [];
     }
     $results = (new Collection(['data' => $results]))->find(function ($item) {
         return $item->timestamp >= strtotime('-2 months');
     })->each(function ($item) {
         return static::create((array) $item);
     });
     Cache::write('default', $cacheKey, $results, '+1 hour');
     return $results;
 }
Example #4
0
 public function __construct($consumerKey, $consumerSecret = null, $token = null, $secret = null)
 {
     parent::__construct($consumerKey, $consumerSecret, $token, $secret);
     $this->requestHandler = new RequestHandler();
     $this->setConsumer($consumerKey, $consumerSecret);
 }
Example #5
0
 /**
  * Reblog the post from post array.
  * 
  * @param string $blogName
  * @param object $post
  * 
  * @return array the response array
  */
 protected function reblogPost($blogName, $post, array $options = null)
 {
     $id = $post->id;
     $reblogKey = $post->reblog_key;
     return $this->client->reblogPost($blogName, $id, $reblogKey, $options);
 }
Example #6
0
<?php

ini_set('display_errors', 1);
include __DIR__ . '/tumblr/vendor/autoload.php';
session_start();
use Tumblr\API\Client as TClient;
$consumerKey = $_SESSION['client_id'];
$consumerSecret = $_SESSION['client_secret'];
$token = $_SESSION['token'];
$tokenSecret = $_SESSION['secret'];
$client = new TClient($consumerKey, $consumerSecret);
$client->setToken($_SESSION['token'], $_SESSION['secret']);
session_start();
print_r($client->getUserInfo());