Esempio n. 1
4
function hs_authenticate_tumblr()
{
    $consumerKey = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW";
    // Put your consumer key here.
    $consumerSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    // Put your consumer secret here.
    $client = new Tumblr\API\Client($consumerKey, $consumerSecret);
    $requestHandler = $client->getRequestHandler();
    $requestHandler->setBaseUrl("https://www.tumblr.com/");
    // If we are visiting the first time
    if (!$_GET["oauth_verifier"]) {
        // Grab the oauth token.
        $resp = $requestHandler->request("POST", "oauth/request_token", array());
        $out = $result = $resp->body;
        $data = array();
        parse_str($out, $data);
        // Tell the user where to go.
        echo '<a href="https://www.tumblr.com/oauth/authorize?oauth_token=' . $data["oauth_token"] . '"> GO </a>';
        $_SESSION["t"] = $data["oauth_token"];
        $_SESSION["s"] = $data["oauth_token_secret"];
    } else {
        $verifier = $_GET["oauth_verifier"];
        // Use the stored tokens.
        $client->setToken($_SESSION["t"], $_SESSION["s"]);
        // To grab the access tokens.
        $resp = $requestHandler->request("POST", "oauth/access_token", array("oauth_verifier" => $verifier));
        $out = $result = $resp->body;
        $data = array();
        parse_str($out, $data);
        // And print out our new keys we got back.
        $token = $data["oauth_token"];
        $secret = $data["oauth_token_secret"];
        echo "token: " . $token . "<br/>secret: " . $secret;
        $client = new Tumblr\API\Client($consumerKey, $consumerSecret, $token, $secret);
        $info = $client->getUserInfo();
        echo "<br/><br/>congrats " . $info->user->name . "!";
    }
}
Esempio n. 2
0
 function CreateLinkPost()
 {
     $config = (include "/config.php");
     $client = new Tumblr\API\Client($config['tumblr_consumer_key'], $config['tumblr_consumer_secret']);
     $client->setToken($_SESSION['tumblr_token'], $_SESSION['tumblr_secret']);
     if (!isset($_POST['url']) || $_POST['url'] == "") {
         return "Missing required param: url";
         exit;
     }
     if (!isset($_POST['blogName']) || $_POST['blogName'] == "") {
         return "Missing required param: blogName";
         exit;
     }
     $blogName = $_POST['blogName'];
     $data = array("type" => "link", "url" => $_POST['url']);
     if (isset($_POST['description']) && $_POST['description'] != "") {
         $data['description'] = FilterText($_POST['description']);
     }
     if (isset($_POST['thumbnail']) && $_POST['thumbnail'] != "") {
         $data['thumbnail'] = $_POST['thumbnail'];
     }
     if (isset($_POST['author']) && $_POST['author'] != "") {
         $data['author'] = FilterText($_POST['author']);
     }
     try {
         $client->createPost($blogName, $data);
     } catch (Exception $ex) {
         return "That blog does not exist";
     }
     return "success";
 }
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;
}
Esempio n. 4
0
 function GetUserBlogs()
 {
     $config = (include "/config.php");
     $client = new Tumblr\API\Client($config['tumblr_consumer_key'], $config['tumblr_consumer_secret']);
     $client->setToken($_SESSION['tumblr_token'], $_SESSION['tumblr_secret']);
     $r = array();
     foreach ($client->getUserInfo()->user->blogs as $blog) {
         array_push($r, $blog->name);
     }
     return $r;
 }
Esempio n. 5
0
 public function testRequestPost()
 {
     $client = new Tumblr\API\Client(API_KEY);
     $rh = $client->getRequestHandler();
     $rh->client = $this->guzzle;
     $rh->setBaseUrl('/');
     // Test with one file
     $options = array('data' => 'fake data');
     $rh->request('POST', 'meh', $options);
     // Test with array of files
     $options = array('data' => array('foo', 'bar'));
     $rh->request('POST', 'meh', $options);
 }
 function HandleResponse()
 {
     $config = (include "/config.php");
     $client = new Tumblr\API\Client($config['tumblr_consumer_key'], $config['tumblr_consumer_secret']);
     $requestHandler = $client->getRequestHandler();
     $requestHandler->setBaseUrl('https://www.tumblr.com/');
     $client->setToken($_SESSION['tumblr_temp_token'], $_SESSION['tumblr_temp_secret']);
     // exchange the verifier for the keys
     $verifier = $_GET['oauth_verifier'];
     // exchange the verifier for the keys
     $resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier));
     $out = $result = $resp->body;
     $data = array();
     parse_str($out, $data);
     // and print out our new keys
     $token = $data['oauth_token'];
     $secret = $data['oauth_token_secret'];
     $_SESSION['tumblr_token'] = $token;
     $_SESSION['tumblr_secret'] = $secret;
     echo "<script>window.close();</script>";
     die;
 }
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;
}
Esempio n. 8
0
<?php

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/constants.php';
require __DIR__ . '/functions.php';
$storage = file_get_contents(__DIR__ . '/storage.txt');
$storage = unserialize($storage);
$client = new Tumblr\API\Client(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, SECRET);
$response = $client->getDashboardPosts(array('limit' => 1));
$post = $response->posts[0];
$lastPostId = $post->id;
if ($post->type == 'photo' && $post->followed == 1) {
    if ($storage['last_post_id'] != $lastPostId) {
        deleteThumb($storage['last_post_id']);
        saveThumb($post);
        $storage['last_post_id'] = $lastPostId;
        echo json_encode(['blog_name' => $post->blog_name, 'image' => getThumbPath($lastPostId)]);
    } else {
        echo "FALSE";
    }
} else {
    echo "FALSE";
}
file_put_contents(__DIR__ . '/storage.txt', serialize($storage));
 /**
  * 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');
 }