Example #1
0
 /**
  * Get the count of images in this account
  * @return int
  **/
 public function getImageCount()
 {
     return -1;
     // This currently returns a 404.  Huh.
     $data = Imgur::sendGET(Imgur::$api_url, '/account/images_count');
     var_export($data);
     $json = json_decode($data, true);
     Imgur::checkError($json);
     if (array_key_exists('images_count', $json)) {
         return (int) $json['images_count']['count'];
     }
 }
Example #2
0
 public function load()
 {
     $data = Imgur::sendGET($this->getURL());
     $json = json_decode($data, true);
     Imgur::checkError($json);
     $class = $this->getImageClass();
     foreach ($json['images'] as $image) {
         $img = new $class();
         $img->loadFromJSON($image);
         $this[$img->hash] = $img;
     }
 }
Example #3
0
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $access_token->getToken();
    $_SESSION['token_secret'] = $access_token->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // Once again, this is why they have you serialize it in their example code...
    $access_token = new Zend_Oauth_Token_Access();
    $access_token->setToken($_SESSION['token']);
    $access_token->setTokenSecret($_SESSION['token_secret']);
    // setOAuth wants to work only with the result of this call, which will be
    // a Zend_Oauth_Client, a subclass of Zend_Http_Client.
    Imgur::setOAuth($access_token->getHttpClient($zend_oauth_config));
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Example #4
0
} else {
    $mo_y = $imheight / 3 * 2 - 22;
}
switch ($_GET['twitter_username']) {
    case 'cutegecko':
        // 135, 210
        $dstx = 150;
        $dsty = 95;
        break;
    case 'seanyo':
        //210, 200
        $dstx = 193;
        $dsty = 160;
        break;
    case 'robdrimmie':
        //210, 200
        $dstx = 250;
        $dsty = 170;
        break;
}
$imgur = new Imgur();
$original = $imgur->upload($im);
imagecopy($im, $stache, $mo_x, $mo_y, 0, 0, 80, 45);
$moified = $imgur->upload($im);
//header("Content-type: image/png");
//imagepng($im);
imagedestroy($im);
echo "<br /><br /><br />";
echo "<h2>database</h2>";
$db = new Moify_DB();
$db->add($twitter_username, $original['upload']['links']['original'], $moified['upload']['links']['original'], $mo_file, $mo_y, $mo_x);
Example #5
0
 /**
  * Perform the requested upload.
  * @param string $file
  * @param string $type
  * @return array JSON
  **/
 protected function uploadImage($data, $type = 'base64')
 {
     $post = Imgur::sendPOST(Imgur::$api_url . '/upload', array('image' => $data, 'type' => $type, 'name' => $this->name, 'title' => $this->title, 'caption' => $this->caption));
     $json = json_decode($post, true);
     return $json;
 }
/**
 * PHP Interface to v2 of the Imgur API
 * HTTP Adapter Demo
 * 
 * @author "McGlockenshire"
 * @link http://github.com/McGlockenshire/Imgur-API-for-PHP
 * @license http://www.gnu.org/licenses/lgpl-3.0.txt
 **/
include '../Imgur.php';
Imgur::registerSPLAutoloader();
echo "Please enter your anonymous access key: ";
Imgur::$key = trim(fgets(STDIN));
// Comment out these two lines to use the PHPStream adapter, which is the default.
include_once 'HTTP/Request2.php';
Imgur::$http_adapter_class = 'Imgur_HTTPAdapter_PEARHTTPRequest2';
// And uncomment these two lines to use Zend_Http_Client instead.
#include_once 'Zend/Loader/Autoloader.php';
#$zal = Zend_Loader_Autoloader::getInstance();
#Imgur::$http_adapter_class = 'Imgur_HTTPAdapter_ZendHttpClient';
$u = new Imgur_Upload();
$u->name = 'spacer.gif';
$u->title = 'A 1x1 transparent GIF file.';
$u->caption = 'For the entertainment value.';
try {
    $i = $u->uploadImageFromDisk('./spacer.gif');
} catch (Imgur_Exception $e) {
    echo "OH NOES!  ", $e->getMessage(), "\n";
    if (method_exists($e, 'getPrevious')) {
        $p = $e->getPrevious();
        if ($p && $p instanceof Exception) {
Example #7
0
 public static function run($method, $params)
 {
     $url = '';
     self::$imgur_format = Config::get('imgur::imgur.imgur_format');
     self::$imgur_xml_type = Config::get('imgur::imgur.imgur_xml_type');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     if ($method === 'move_image') {
         if ($params['edit'] === TRUE) {
             $url .= self::$imgur_baseurl . 'upload?edit&';
             unset($params['edit']);
         } else {
             $url .= self::$imgur_baseurl . 'upload?';
             unset($params['edit']);
         }
         $url .= http_build_query($params, NULL, '&');
         curl_setopt($ch, CURLOPT_URL, $url);
     } elseif ($method === 'upload') {
         $url .= self::$imgur_baseurl . $method . '.' . self::$imgur_format;
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, TRUE);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
     } else {
         if ($method === 'oembed') {
             self::$imgur_baseurl = substr(self::$imgur_baseurl, 0, -2);
         }
         // if $params is an array
         if (is_array($params)) {
             // if there are params
             if (count($params)) {
                 // if format parameter is set, we use it instead of pre-set value
                 if (array_key_exists('format', $params)) {
                     $url .= self::$imgur_baseurl . $method . '?';
                 } else {
                     $url .= self::$imgur_baseurl . $method . '.' . self::$imgur_format . '?';
                 }
             } else {
                 $url .= self::$imgur_baseurl . $method . '.' . self::$imgur_format;
             }
             $url .= http_build_query($params, NULL, '&');
         } else {
             $url .= self::$imgur_baseurl . $method . '/' . $params . '.' . self::$imgur_format;
         }
         curl_setopt($ch, CURLOPT_URL, $url);
     }
     if ($response = curl_exec($ch)) {
         switch (self::$imgur_format) {
             case 'json':
                 self::$response = $response;
                 break;
             case 'xml':
                 // convert string response to xml object or array
                 $simplexml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
                 if (self::$imgur_xml_type === 'array') {
                     self::$response = self::xml_to_array($simplexml);
                 } else {
                     self::$response = $simplexml;
                 }
                 break;
         }
         curl_close($ch);
         return TRUE;
     } else {
         throw new Exception('cURL error: ' . curl_error($ch) . '. Error code: ' . curl_errno($ch));
         curl_close($ch);
     }
 }
Example #8
0
    $access_token = $oauth_pecl->getAccessToken(Imgur::$oauth1a_access_token_url);
    // Replace the user's request token with their access token.
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $access_token['oauth_token'];
    $_SESSION['token_secret'] = $access_token['oauth_token_secret'];
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // Just like in the previous state, we need to update the object with the
    // current token+secret pair.
    $oauth_pecl->setToken($_SESSION['token'], $_SESSION['token_secret']);
    // And, off we go, setOAuth detects the class and does the right thing.
    Imgur::setOAuth($oauth_pecl);
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Example #9
0
<?php

/**
 * PHP Imgur wrapper 0.1
 * Imgur API wrapper for easy use.
 * @author Vadim Kr.
 * @copyright (c) 2013 bndr
 * @license http://creativecommons.org/licenses/by-sa/3.0/legalcode
 */
//Include the main file
include "Imgur.php";
//Set up your api key and secret
$api_key = "";
$api_secret = "";
$imgur = new Imgur($api_key, $api_secret);
/*-----------------------------------------------------------------------------------*/
/* Authorization
/*-----------------------------------------------------------------------------------*/
//We create a new instance of imgur class.
// Imgur oAuth will return code as GET parameter after the user allows access
if (isset($_GET['code'])) {
    $tokens = $imgur->authorize(false, $_GET['code']);
    //First parameter is for refresh_tokens
    //The user is authorized. You can save the $tokens['refresh_token'] and $tokens['access_token'] for future use;
} else {
    // GET parameter doesn't exist, so we will have to ask user to allow access for our application
    $imgur->authorize();
}
/*-----------------------------------------------------------------------------------*/
/* Account
/*-----------------------------------------------------------------------------------*/
Example #10
0
    // This can probably throw a variety of exceptions as well, but I haven't
    // encountered any of them.  Also note the express passing of oauth_verifier here.
    $oauth_pear->getAccessToken(Imgur::$oauth1a_access_token_url, array_key_exists('oauth_verifier', $_REQUEST) ? $_REQUEST['oauth_verifier'] : null);
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.  It's worth noting again that on subsequent pageviews,
    // the new Access Token & Secret are automatically passed into the OAuth Consumer.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $oauth_pear->getToken();
    $_SESSION['token_secret'] = $oauth_pear->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // setOAuth will detect the type of object and automatically load the proper
    // HTTP adapter, so we don't need to do any special work.
    Imgur::setOAuth($oauth_pear);
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Example #11
0
 /**
  * Nuke it from orbit.  It's the only way to be sure.
  * @return bool Or throws an exception on failure.
  **/
 public function delete()
 {
     if (!$this->deletehash) {
         return false;
     }
     $json = json_decode(Imgur::sendGET(Imgur::$api_url . '/delete/' . $this->deletehash, array('_method' => 'delete')), true);
     Imgur::checkError($json);
     return $json['delete']['message'] == 'Success';
 }
Example #12
0
 /**
  * Suck an HTTP adapter out of an OAuth instance
  * @param object $oauth
  **/
 public static function setOAuth($oauth)
 {
     // We support the following adapters officially:
     // PEAR's HTTP_OAuth_Consumer
     // Zend's Zend_Oauth_Consumer
     // The PECL extension "OAuth"
     // For all other objects, we'll strip underscores.
     // Let's say we have a custom OAuth class called My_Super_OAuth_Thing
     // We'll then look for "Imgur_HTTPAdapter_OAuth_MySuperOAuthThing"
     $adapter_class = '';
     if (extension_loaded('oauth') && $oauth instanceof OAuth) {
         $adapter_class = 'PECLOAuth';
     } else {
         $adapter_class = str_replace('_', '', get_class($oauth));
     }
     $adapter_class = 'Imgur_HTTPAdapter_OAuth_' . $adapter_class;
     $adapter = $adapter_class::createByWrapping($oauth);
     self::setHTTPAdapter($adapter);
     self::$has_oauth = true;
 }