Example #1
0
 /**
  * Method that generates the OAuth signature
  *
  * In order for this method to correctly generate a signature, setToken()
  * MUST be called to set the token and token secret within the instance of
  * phpSmug.
  *
  * @access	private
  * @param	string		$apicall The API method.
  * @param	mixed		$apiargs The arguments passed to the API method.
  * @return string
  **/
 private function generate_signature($apicall, $apiargs = NULL, $url = NULL)
 {
     $this->oauth_timestamp = time();
     $this->oauth_nonce = md5(time() . mt_rand());
     if (!is_null($apicall) && $apicall != 'Upload') {
         if (substr($apicall, 0, 8) != 'smugmug.') {
             $apicall = 'smugmug.' . $apicall;
         }
     }
     if ($this->oauth_signature_method == 'PLAINTEXT') {
         return phpSmug::urlencodeRFC3986($this->OAuthSecret) . '&' . phpSmug::urlencodeRFC3986($this->oauth_token_secret);
     } else {
         $this->oauth_signature_method = 'HMAC-SHA1';
         $encKey = phpSmug::urlencodeRFC3986($this->OAuthSecret) . '&' . phpSmug::urlencodeRFC3986($this->oauth_token_secret);
         if (is_null($apicall) && !is_null($url)) {
             $endpoint = $url;
         } else {
             if (strpos($apicall, 'Token') || $this->secure && $apicall != 'Upload') {
                 $endpoint = "https://secure.smugmug.com/services/api/php/{$this->APIVer}/";
             } else {
                 if ($apicall == 'Upload') {
                     //$proto = ( $this->oauth_signature_method == 'PLAINTEXT' || $this->secure ) ? 'https' : 'http';
                     //$endpoint = $proto . '://upload.smugmug.com/'.$apiargs['FileName'];	// No support for secure uploads yet
                     $endpoint = 'http://upload.smugmug.com/' . $apiargs['FileName'];
                 } else {
                     $endpoint = "http://api.smugmug.com/services/api/php/{$this->APIVer}/";
                 }
             }
         }
         if (is_null($apicall)) {
             $method = 'GET';
         } else {
             if ($apicall == 'Upload') {
                 $method = 'PUT';
             } else {
                 $method = 'POST';
             }
         }
         $params = array('oauth_version' => '1.0', 'oauth_nonce' => $this->oauth_nonce, 'oauth_timestamp' => $this->oauth_timestamp, 'oauth_consumer_key' => $this->APIKey, 'oauth_signature_method' => $this->oauth_signature_method);
         if (!is_null($apicall) && $apicall != 'Upload') {
             $params = array_merge($params, array('method' => $apicall));
         }
         $params = !empty($this->oauth_token) ? array_merge($params, array('oauth_token' => $this->oauth_token)) : $params;
         if ($apicall != 'Upload') {
             $params = !empty($apiargs) ? array_merge($params, $apiargs) : $params;
         }
         $keys = array_map(array('phpSmug', 'urlencodeRFC3986'), array_keys($params));
         $values = array_map(array('phpSmug', 'urlencodeRFC3986'), array_values($params));
         $params = array_combine($keys, $values);
         // Sort by keys (natsort)
         uksort($params, 'strnatcmp');
         // We can't use implode() here as it plays havoc with array keys with empty values.
         $count = count($params);
         $string = '';
         foreach ($params as $key => $value) {
             $count--;
             $string .= $key . '=' . $value;
             if ($count) {
                 $string .= '&';
             }
         }
         $base_string = $method . '&' . phpSmug::urlencodeRFC3986($endpoint) . '&' . phpSmug::urlencodeRFC3986($string);
         $sig = base64_encode(hash_hmac('sha1', $base_string, $encKey, true));
         return $sig;
     }
 }
Example #2
0
 *
 * You'll need to replace:
 * - <API KEY> with one provided by SmugMug: http://www.smugmug.com/hack/apikeys 
 * - <APP NAME/VER (URL)> with your application name, version and URL
 * - <EMAILADDRESS> with your email address
 * - <PASSWORD> with your SmugMug password
 *
 * The <APP NAME/VER (URL)> is NOT required, but it's encouraged as it will
 * allow SmugMug diagnose any issues users may have with your application if
 * they request help on the SmugMug forums.
 *
 * You can see this example in action at http://phpsmug.com/examples/
 */
require_once "../phpSmug.php";
try {
    $f = new phpSmug("APIKey=<API KEY>", "AppName=<APP NAME/VER (URL)>");
    // Login With EmailAddress and Password
    $f->login("EmailAddress=<EMAILADDRESS>", "Password=<PASSWORD>");
    // Get list of  albums
    $albums = $f->albums_get();
    // Get list of images and other useful information
    $images = $f->images_get("AlbumID={$albums['0']['id']}", "AlbumKey={$albums['0']['Key']}", "Heavy=1");
    $images = $f->APIVer == "1.2.2" ? $images['Images'] : $images;
    // Display the thumbnails and link to the medium image for each image
    foreach ($images as $image) {
        echo '<a href="' . $image['MediumURL'] . '"><img src="' . $image['TinyURL'] . '" title="' . $image['Caption'] . '" alt="' . $image['id'] . '" /></a>';
    }
} catch (Exception $e) {
    echo "{$e->getMessage()} (Error Code: {$e->getCode()})";
}
?>
 * all the public images in the first album found.
 *
 * You'll want to replace:
 * - <API KEY> with one provided by SmugMug: http://www.smugmug.com/hack/apikeys 
 * - <APP NAME/VER (URL)> with your application name, version and URL
 * - <OAUTH SECRET> with the OAuth Secret associated with your API Key.
 *
 * The <APP NAME/VER (URL)> is NOT required, but it's encouraged as it will
 * allow SmugMug diagnose any issues users may have with your application if
 * they request help on the SmugMug forums.
 *
 * You can see this example in action at http://phpsmug.com/examples/
 */
require_once "../phpSmug.php";
try {
    $f = new phpSmug("APIKey=<API KEY>", "AppName=<APP NAME/VER (URL)>", "OAuthSecret=<OAUTH SECRET>");
    // Perform the 3 step OAuth Authorisation process.
    // NOTE: This is a very simplified example that does NOT store the final token.
    // You will need to ensure your application does.
    if (!isset($_SESSION['SmugGalReqToken'])) {
        // Step 1: Get a Request Token
        $d = $f->auth_getRequestToken();
        $_SESSION['SmugGalReqToken'] = serialize($d);
        // Step 2: Get the User to login to SmugMug and Authorise this demo
        echo "<p>Click <a href='" . $f->authorize() . "' target='_blank'><strong>HERE</strong></a> to Authorize This Demo.</p>";
        echo "<p>A new window/tab will open asking you to login to SmugMug (if not already logged in).  Once you've logged it, SmugMug will redirect you to a page asking you to approve the access (it's read only) to your public photos.  Approve the request and come back to this page and click REFRESH below.</p>";
        echo "<p><a href='" . $_SERVER['PHP_SELF'] . "'><strong>REFRESH</strong></a></p>";
    } else {
        $reqToken = unserialize($_SESSION['SmugGalReqToken']);
        unset($_SESSION['SmugGalReqToken']);
        // Step 3: Use the Request token obtained in step 1 to get an access token
Example #4
0
 /**
  * Method that generates the OAuth signature
  *
  * In order for this method to correctly generate a signature, setToken()
  * MUST be called to set the token and token secret within the instance of
  * phpSmug.
  *
  * @return string
  * @access private
  * @param string $apicall The API method.
  * @param mixed $apiargs The arguments passed to the API method.
  **/
 private function generate_signature($apicall, $apiargs = NULL)
 {
     $this->oauth_timestamp = time();
     $this->oauth_nonce = md5(time() . mt_rand());
     if ($apicall != 'Upload') {
         if (substr($apicall, 0, 8) != 'smugmug.') {
             $apicall = 'smugmug.' . $apicall;
         }
     }
     if ($this->oauth_signature_method == 'PLAINTEXT') {
         return phpSmug::urlencodeRFC3986($this->OAuthSecret) . '&' . phpSmug::urlencodeRFC3986($this->oauth_token_secret);
     } else {
         $this->oauth_signature_method = 'HMAC-SHA1';
         $encKey = phpSmug::urlencodeRFC3986($this->OAuthSecret) . '&' . phpSmug::urlencodeRFC3986($this->oauth_token_secret);
         $endpoint = $apicall == 'Upload' ? 'http://api.smugmug.com/' . $apiargs['FileName'] : 'http://api.smugmug.com/services/api/php/' . $this->APIVer . '/';
         $method = $apicall == 'Upload' ? 'PUT' : 'POST';
         $params = array('oauth_version' => '1.0', 'oauth_nonce' => $this->oauth_nonce, 'oauth_timestamp' => $this->oauth_timestamp, 'oauth_consumer_key' => $this->APIKey, 'oauth_signature_method' => $this->oauth_signature_method);
         if ($apicall != 'Upload') {
             $params = array_merge($params, array('method' => $apicall));
         }
         $params = !empty($this->oauth_token) ? array_merge($params, array('oauth_token' => $this->oauth_token)) : $params;
         if ($apicall != 'Upload') {
             $params = !empty($apiargs) ? array_merge($params, $apiargs) : $params;
         }
         $keys = array_map(array('phpSmug', 'urlencodeRFC3986'), array_keys($params));
         $values = array_map(array('phpSmug', 'urlencodeRFC3986'), array_values($params));
         $params = array_combine($keys, $values);
         // Sort by keys (natsort)
         uksort($params, 'strnatcmp');
         $pairs = array();
         foreach ($params as $key => $value) {
             if (is_array($value)) {
                 natsort($value);
                 foreach ($value as $v2) {
                     $pairs[] = "{$key}={$v2}";
                 }
             } else {
                 $pairs[] = "{$key}={$value}";
             }
         }
         $string = implode('&', $pairs);
         $base_string = $method . '&' . phpSmug::urlencodeRFC3986($endpoint) . '&' . phpSmug::urlencodeRFC3986($string);
         $sig = base64_encode(hash_hmac('sha1', $base_string, $encKey, true));
         return $sig;
     }
 }
    die;
}
//Setup stat variables
$categoriesAdded = 0;
$albumsAdded = 0;
$filesAdded = 0;
$filesReplaced = 0;
$filesMDUpdated = 0;
$filesSkipped = 0;
//Begin processing things
echo "Determining file structure...";
$structure = get_local_structure($argv[1]);
echo "done\n";
try {
    echo "Connecting to SmugMug...";
    $smug = new phpSmug("APIKey={$apiKey}", "AppName={$appInfo}", "APIVer={$apiVersion}");
    $smug->login("EmailAddress={$username}", "Password={$password}");
    echo "done\n";
    echo "Fetching category list from server...";
    $categories = $smug->categories_get();
    echo "done\n";
    echo "Fetching album list from server...";
    $serverAlbums = $smug->albums_get("Heavy=1");
    echo "done\n";
    foreach ($structure as $category => $albums) {
        echo "\nCategory: {$category}\n";
        //Check to see if the category already exists
        $serverCat = false;
        foreach ($categories as $cat) {
            if ($cat['Name'] == $category) {
                $serverCat = $cat;
Example #6
0
if (count($argv) < 3) {
    echo "Usage: php upload.php 'Album Title' pic1.jpg <pic2.jpg ...>\n";
    die;
}
$albumTitle = $argv[1];
$added = 0;
$mdUpdated = 0;
$replaced = 0;
echo "Preparing file information...";
for ($i = 2; $i < count($argv); $i++) {
    $uploads[] = prepare_file($argv[$i]);
}
echo "done\n";
try {
    echo "Connecting to SmugMug...";
    $smug = new phpSmug("APIKey={$apiKey}", "AppName={$appInfo}", "APIVer={$apiVersion}");
    $smug->login("EmailAddress={$username}", "Password={$password}");
    echo "done\n";
    echo "Finding album information...";
    $albums = $smug->albums_get("Heavy=1");
    // Check each album to find the one we want to work on
    foreach ($albums as $current) {
        if ($current['Title'] == $albumTitle) {
            $album = $current;
        }
    }
    if (empty($album)) {
        echo "Unable to find album information\n";
        die;
    } else {
        echo "done\n";
 * This is how you can display images from galleries that have the 
 * "External links" gallery setting set to "No".
 *
 * You'll want to replace:
 * - <API KEY> with one provided by SmugMug: http://www.smugmug.com/hack/apikeys 
 * - <APP NAME/VER (URL)> with your application name, version and URL
 * - <OAUTH SECRET> with the OAuth Secret associated with your API Key.
 *
 * The <APP NAME/VER (URL)> is NOT required, but it's encouraged as it will
 * allow SmugMug diagnose any issues users may have with your application if
 * they request help on the SmugMug forums.
 *
 */
require_once "../phpSmug.php";
try {
    $f = new phpSmug("APIKey=<API KEY>", "AppName=<APP NAME/VER (URL)>", "OAuthSecret=<OAUTH SECRET>");
    // Perform the 3 step OAuth Authorisation process.
    // NOTE: This is a very simplified example that does NOT store the final token.
    // You will need to ensure your application does.
    if (!isset($_SESSION['SmugGalReqToken'])) {
        // Step 1: Get a Request Token
        $d = $f->auth_getRequestToken();
        $_SESSION['SmugGalReqToken'] = serialize($d);
        // Step 2: Get the User to login to SmugMug and Authorise this demo
        echo "<p>Click <a href='" . $f->authorize() . "' target='_blank'><strong>HERE</strong></a> to Authorize This Demo.</p>";
        echo "<p>A new window/tab will open asking you to login to SmugMug (if not already logged in).  Once you've logged it, SmugMug will redirect you to a page asking you to approve the access (it's read only) to your public photos.  Approve the request and come back to this page and click REFRESH below.</p>";
        echo "<p><a href='" . $_SERVER['PHP_SELF'] . "'><strong>REFRESH</strong></a></p>";
    } else {
        $reqToken = unserialize($_SESSION['SmugGalReqToken']);
        unset($_SESSION['SmugGalReqToken']);
        // Step 3: Use the Request token obtained in step 1 to get an access token
Example #8
0
<?php

/* Last updated with phpSmug 1.0.2
 *
 * This example file shows you how to get a list of public albums for a 
 * particular SmugMug user, using their nickname.
 *
 * You'll want to replace:
 * - <API KEY> with one provided by SmugMug: http://www.smugmug.com/hack/apikeys 
 * - <APP NAME/VER (URL)> with your application name, version and URL
 * - <NICKNAME> with a SmugMug nickname.
 *
 * The <APP NAME/VER (URL)> is NOT required, but it's encouraged as it will
 * allow SmugMug diagnose any issues users may have with your application if
 * they request help on the SmugMug forums.
 */
require_once "phpSmug.php";
$f = new phpSmug("<API KEY>", "<APP NAME/VER (URL)>");
$f->login_anonymously();
$albums = $f->albums_get('<NICKNAME>');
foreach ($albums as $album) {
    echo $album['Title'] . " (ID: " . $album['id'] . ")<br />";
}
Example #9
0
 * all the public images in the first album found.
 *
 * You'll need to replace:
 * - <API KEY> with one provided by SmugMug: http://www.smugmug.com/hack/apikeys 
 * - <APP NAME/VER (URL)> with your application name, version and URL
 * - <NICKNAME> with a SmugMug nickname.
 *
 * The <APP NAME/VER (URL)> is NOT required, but it's encouraged as it will
 * allow SmugMug diagnose any issues users may have with your application if
 * they request help on the SmugMug forums.
 *
 * You can see this example in action at http://phpsmug.com/examples/
 */
require_once "../phpSmug.php";
try {
    $f = new phpSmug("APIKey=<API KEY>", "AppName=<APP NAME/VER (URL)>");
    // Login Anonymously
    $f->login();
    // Get list of public albums
    $albums = $f->albums_get('NickName=<NICKNAME>');
    // Get list of public images and other useful information
    $images = $f->images_get("AlbumID={$albums['0']['id']}", "AlbumKey={$albums['0']['Key']}", "Heavy=1");
    $images = $f->APIVer == "1.2.2" ? $images['Images'] : $images;
    // Display the thumbnails and link to the medium image for each image
    foreach ($images as $image) {
        echo '<a href="' . $image['MediumURL'] . '"><img src="' . $image['TinyURL'] . '" title="' . $image['Caption'] . '" alt="' . $image['id'] . '" /></a>';
    }
} catch (Exception $e) {
    echo "{$e->getMessage()} (Error Code: {$e->getCode()})";
}
?>