Beispiel #1
0
 /**
  * getPhotoInfo 
  * 
  * @return string
  */
 private function getPhotoInfo()
 {
     $config = getInstagramConfigData();
     $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], $this->accessToken);
     try {
         if (isset($_GET['show']) && $_GET['show'] == 'more') {
             $feed = $instagram->get('users/self/media/recent/');
         } else {
             $feed = $instagram->get('users/self/media/recent/', array('count' => 8));
         }
     } catch (InstagramApiError $e) {
         $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Instagram User data.'), 'error' => $e->getMessage(), 'file' => __FILE__, 'line' => __LINE__));
         return false;
     }
     $photos = '';
     $automaticSelect = '';
     if (!$this->autoUpload) {
         $photos .= '<h2>' . T_('Manual') . '</h2>';
         $photos .= '<p>' . T_('Choose photo to add.') . '</p>';
         $photos .= '<ul>';
         $i = 1;
         foreach ($feed->data as $photo) {
             $sourceId = $photo->id;
             $thumbnail = $photo->images->thumbnail->url;
             $medium = $photo->images->low_resolution->url;
             $full = $photo->images->standard_resolution->url;
             $caption = isset($photo->caption) ? $photo->caption->text : '';
             $caption .= ' [' . sprintf(T_('Instagram filter: %s.'), $photo->filter) . ']';
             $value = "{$sourceId}|{$thumbnail}|{$medium}|{$full}|{$caption}";
             $photos .= '<li>';
             $photos .= '<label for="instagram' . $i . '">';
             $photos .= '<img src="' . $thumbnail . '" alt="' . $caption . '"/><br/>';
             $photos .= '<input type="checkbox" id="instagram' . $i . '" name="photos[]" value="' . $value . '"/>';
             $photos .= '</label>';
             $photos .= '</li>';
             $i++;
         }
         // They probably have more
         if ($i == 8) {
             $photos .= '<li><a href="index.php?action=upload&amp;type=instagram&amp;show=more">' . T_('See more') . '</a></li>';
         }
         $photos .= '</ul>';
     }
     return $photos . '
                     <h2>' . T_('Automatic') . '</h2>
                     <label>
                         <input type="checkbox" id="automatic" name="automatic" value="1" ' . ($this->autoUpload ? 'checked="checked"' : '') . '/>
                         ' . T_('Have all photos automatically imported.') . '
                     </label>';
 }
session_start();
require_once 'src/config.php';
require_once 'src/Instagram.php';
$access_token = isset($_SESSION['access_token']) ? $_SESSION['access_token'] : null;
$instagram = new Instagram(CLIENT_ID, CLIENT_SECRET, $access_token);
if (!$access_token) {
    // If there is no access token in the session, let's have the user authenticate our application...
    /*
    /   You pass the Redirect Uri you registered with your app and an array of "scope" (aka permissions) you
    /   want to grab from the user. There is also a third parameter "response_type" which defaults to "code"
    */
    $loginUrl = $instagram->authorizeUrl(REDIRECT_URI, array('basic', 'comments', 'likes', 'relationships'));
} else {
    try {
        $feed = $instagram->get('users/self/feed');
    } catch (InstagramApiError $e) {
        die($e->getMessage());
    }
}
?>

<?php 
if (isset($loginUrl)) {
    ?>
<a href="<?php 
    echo $loginUrl;
    ?>
">Log in</a>
<?php 
} else {
Beispiel #3
0
 /**
  * displayEditInstagram 
  * 
  * @return void
  */
 function displayEditInstagram()
 {
     $this->displayHeader();
     $config = getInstagramConfigData();
     $callbackUrl = getDomainAndDir();
     $callbackUrl .= 'settings.php?view=instagram';
     $accessToken = getUserInstagramAccessToken($this->fcmsUser->id);
     $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], $accessToken);
     if (!$accessToken) {
         $url = $instagram->authorizeUrl($callbackUrl, array('basic', 'comments', 'likes', 'relationships'));
         $status = T_('Not Connected');
         $link = '<a href="' . $url . '">' . T_('Connect') . '</a>';
     } else {
         try {
             $feed = $instagram->get('users/self');
         } catch (InstagramApiError $e) {
             die($e->getMessage());
         }
         $status = sprintf(T_('Currently connected as: %s'), $feed->data->username);
         $status .= '<br/><br/><img src="' . $feed->data->profile_picture . '"/>';
         $link = '<a class="disconnect" href="?revoke=instagram">' . T_('Disconnect') . '</a>';
     }
     echo '
     <div class="social-media-connect">
         <img class="icon" src="ui/img/instagram.png" alt="Instagram"/>
         <h2>Instagram</h2>
         <p>' . T_('Connecting with Instagram will allow you to:') . '</p>
         <ul>
             <li>' . T_('Share your Instagram photos with this site.') . '</li>
         </ul>
         <div class="status">' . $status . '</div>
         <div class="action">' . $link . '</div>
     </div>';
     $this->displayFooter();
 }
Beispiel #4
0
/**
 * runInstagramJob 
 * 
 * @return void
 */
function runInstagramJob()
{
    require_once 'inc/config_inc.php';
    require_once 'inc/constants.php';
    require_once 'inc/socialmedia.php';
    require_once 'inc/utils.php';
    require_once THIRDPARTY . 'gettext.inc';
    require_once THIRDPARTY . 'Instagram.php';
    $fcmsError = FCMS_Error::getInstance();
    $fcmsDatabase = Database::getInstance($fcmsError);
    // Get user's access tokens
    $sql = "SELECT u.`id`, s.`instagram_access_token`\n            FROM `fcms_user_settings` AS s, `fcms_users` AS u\n            WHERE s.`user` = u.`id`\n            AND s.`instagram_auto_upload` = 1\n            AND s.`instagram_access_token` IS NOT NULL";
    $rows = $fcmsDatabase->getRows($sql);
    if ($rows === false) {
        logError(__FILE__ . ' [' . __LINE__ . '] - Could not get instagram access tokens.');
        die;
    }
    $accessTokens = array();
    foreach ($rows as $row) {
        $accessTokens[$row['id']] = $row['instagram_access_token'];
    }
    $config = getInstagramConfigData();
    $existingIds = getExistingInstagramIds();
    // Get pics for each user
    foreach ($accessTokens as $userId => $token) {
        $categoryId = getUserInstagramCategory($userId);
        $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], $token);
        try {
            $feed = $instagram->get('users/self/media/recent');
        } catch (InstagramApiError $e) {
            logError(__FILE__ . ' [' . __LINE__ . '] - Could not get user instagram data. - ' . $e->getMessage());
            die;
        }
        $sql = "INSERT INTO `fcms_gallery_photos`\n                    (`date`, `path`, `caption`, `category`, `user`)\n                VALUES ";
        foreach ($feed->data as $photo) {
            $sourceId = $photo->id;
            $thumbnail = $photo->images->thumbnail->url;
            $medium = $photo->images->low_resolution->url;
            $full = $photo->images->standard_resolution->url;
            $caption = $photo->caption->text;
            $caption .= ' [' . sprintf(T_('Filter: %s.'), $photo->filter) . ']';
            // Skip existing photos
            if (isset($existingIds[$sourceId])) {
                continue;
            }
            // Save external paths
            $sql = "INSERT INTO `fcms_gallery_external_photo`\n                        (`source_id`, `thumbnail`, `medium`, `full`)\n                    VALUES\n                        (?, ?, ?, ?)";
            $params = array($sourceId, $thumbnail, $medium, $full);
            $id = $fcmsDatabase->insert($sql, $params);
            if ($id === false) {
                logError(__FILE__ . ' [' . __LINE__ . '] - Could not save external photos.');
                die;
            }
            // Insert new photo
            $sql = "INSERT INTO `fcms_gallery_photos`\n                        (`date`, `external_id`, `caption`, `category`, `user`)\n                    VALUES\n                        (NOW(), ?, ?, ?, ?)";
            $params = array($id, $caption, $categoryId, $userId);
            if (!$fcmsDatabase->insert($sql, $params)) {
                logError(__FILE__ . ' [' . __LINE__ . '] - Could not insert new photo.');
                die;
            }
        }
    }
    // Update date we last ran this job
    updateLastRun(date('Y-m-d H:i:s'), 'instagram');
}