Esempio n. 1
0
File: index.php Progetto: lmcro/fcms
 /**
  * getAjaxFacebookPhotos 
  * 
  * Will print a list of photos from facebook.
  * 
  * @return null
  */
 function getAjaxFacebookPhotos()
 {
     $config = getFacebookConfigData();
     $accessToken = getUserFacebookAccessToken($this->fcmsUser->id);
     $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret']));
     $facebook->setAccessToken($accessToken);
     $albumId = (int) $_POST['albumId'];
     $photos = '';
     $i = 1;
     $_SESSION['facebook_photos'] = array();
     try {
         $fbPhotos = $facebook->api("/{$albumId}/photos");
         foreach ($fbPhotos['data'] as $photo) {
             $w = $photo['width'];
             $h = $photo['height'];
             $width = '100%;';
             $height = 'auto;';
             if ($w > $h) {
                 $width = 'auto;';
                 $height = '100%;';
             }
             $sourceId = $photo['id'];
             $thumbnail = $photo['picture'];
             $_SESSION['facebook_photos'][$sourceId] = array('thumbnail' => $thumbnail, 'width' => $width, 'height' => $height);
             $photos .= '<li>';
             $photos .= '<label for="facebook' . $i . '">';
             $photos .= '<img src="' . $thumbnail . '" style="width:' . $width . ' height:' . $height . '"/>';
             $photos .= '<span style="display:none"></span>';
             $photos .= '</label>';
             $photos .= '<input type="checkbox" id="facebook' . $i . '" name="photos[]" value="' . $sourceId . '"/>';
             $photos .= '</li>';
             $i++;
         }
     } catch (FacebookApiException $e) {
         echo '<p class="error-alert">' . T_('Could not get Facebook photos.') . '</p>';
         $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook photos.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__));
         return;
     }
     if ($i <= 1 && empty($photos)) {
         $photos = '<p class="info-alert">' . T_('No photos were found in this album') . '</p>';
     }
     echo $photos;
 }
Esempio n. 2
0
 /**
  * displayEditFacebook 
  * 
  * @return void
  */
 function displayEditFacebook()
 {
     $this->displayHeader();
     $config = getFacebookConfigData();
     $accessToken = getUserFacebookAccessToken($this->fcmsUser->id);
     if (!empty($config['fb_app_id']) && !empty($config['fb_secret'])) {
         // Setup url for callbacks
         $callbackUrl = getDomainAndDir();
         $callbackUrl .= 'settings.php?view=facebook';
         $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret']));
         // Check if the user is logged in and authed
         $fbUser = $facebook->getUser();
         $fbProfile = '';
         if ($fbUser) {
             try {
                 $fbProfile = $facebook->api('/me');
             } catch (FacebookApiException $e) {
                 $fbUser = null;
             }
         }
         if ($fbUser) {
             $user = '******' . $fbProfile['link'] . '">' . $fbProfile['email'] . '</a>';
             $status = sprintf(T_('Currently connected as: %s'), $user);
             $status .= '<br/><br/><img src="https://graph.facebook.com/' . $fbUser . '/picture" alt="Facebook">';
             $link = '<a class="disconnect" href="?revoke=facebook">' . T_('Disconnect') . '</a>';
         } else {
             $params = array('scope' => 'user_about_me,user_photos,user_birthday,user_location,email,publish_actions', 'redirect_uri' => $callbackUrl);
             $status = T_('Not Connected');
             $link = '<a href="' . $facebook->getLoginUrl($params) . '">' . T_('Connect') . '</a>';
         }
     }
     echo '
     <div class="social-media-connect">
         <img class="icon" src="ui/img/facebook.png" alt="Facebook"/>
         <h2>Facebook</h2>
         <p>' . T_('Connecting with Facebook will allow you to:') . '</p>
         <ul>
             <li>' . T_('Login to this site using your Facebook credentials.') . '</li>
             <li>' . T_('Share status updates from this site to Facebook.') . '</li>
         </ul>
         <div class="status">' . $status . '</div>
         <div class="action">' . $link . '</div>
     </div>';
     $this->displayFooter();
 }
Esempio n. 3
0
 /**
  * setFormData 
  * 
  * Saves all the data passed in from the form upload.
  * 
  * @param array $formData
  * 
  * @return void
  */
 public function setFormData($formData)
 {
     $this->formData = $formData;
     $albumId = $formData['albums'];
     $config = getFacebookConfigData();
     $accessToken = getUserFacebookAccessToken($this->fcmsUser->id);
     $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret']));
     $facebook->setAccessToken($accessToken);
     try {
         $fbPhotos = $facebook->api("/{$albumId}/photos");
     } catch (FacebookApiException $e) {
         $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook photos.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__));
         return false;
     }
     $this->albumFeed = $fbPhotos;
 }
Esempio n. 4
0
 /**
  * display 
  * 
  * @return void
  */
 public function display()
 {
     $_SESSION['fcms_uploader_type'] = 'facebook';
     $config = getFacebookConfigData();
     $accessToken = getUserFacebookAccessToken($this->fcmsUser->id);
     $facebook = new Facebook(array('appId' => $config['fb_app_id'], 'secret' => $config['fb_secret']));
     $facebook->setAccessToken($accessToken);
     $fbUser = $facebook->getUser();
     if ($fbUser) {
         try {
             $fbProfile = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $fbUser = null;
         }
     }
     $facebookInfo = '';
     $js = '';
     if ($this->fcmsError->hasError()) {
         $this->fcmsError->displayError();
         return;
     } elseif (!$fbUser) {
         $facebookInfo = '
         <div class="info-alert">
             <h2>' . T_('Not connected to Facebook.') . '</h2>
             <p>' . T_('You must connect your Family Connections account to Facebook before you can begin importing photos from Facebook.') . '</p>
             <p><a href="../settings.php?view=facebook">' . T_('Connect to Facebook') . '</a></p>
         </div>';
     } else {
         try {
             $fbAlbums = $facebook->api('/me/albums');
             $albumOptions = '';
             foreach ($fbAlbums['data'] as $album) {
                 $albumOptions .= '<option value="' . $album['id'] . '">' . $album['name'] . '</option>';
             }
         } catch (FacebookApiException $e) {
             $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Facebook albums.'), 'error' => $e, 'file' => __FILE__, 'line' => __LINE__));
             $this->fcmsError->displayError();
             return;
         }
         $facebookInfo = '
         <p>
             <select id="albums" name="albums">
                 ' . $albumOptions . '
             </select>
         </p>
         <div id="selector">
             <a href="#" onclick="photoGallerySelectAll(event, \'facebook\');" id="select-all">' . T_('Select All') . '</a>
             <a href="#" onclick="photoGallerySelectNone(event, \'facebook\');" id="select-none">' . T_('Select None') . '</a>
         </div>
         <ul id="photo_list"></ul>';
         $js = 'loadPhotoGalleryPhotos("facebook", "' . T_('Could not get Facebook photos.') . '");';
         $js .= 'loadPhotoGalleryPhotoEvents("facebook", "' . T_('Could not get Facebook photos.') . '");';
     }
     // Display the form
     echo '
         <form method="post" class="photo-uploader" action="index.php?action=upload&amp;type=facebook">
             <div class="header">
                 <label>' . T_('Category') . '</label>
                 ' . $this->getCategoryInputs() . '
             </div>
             <ul class="upload-types">
                 ' . $this->getUploadTypesNavigation('facebook') . '
             </ul>
             <div class="upload-area">
                 <div class="facebook">
                     ' . $facebookInfo . '
                 </div>
             </div>
             <div class="footer">
                 <input class="sub1" type="submit" value="' . T_('Upload') . '" id="submit-photos" name="facebook"/>
             </div>
         </form>
         <script type="text/javascript">
         ' . $js . '
         $("#submit-photos").click(function(e) {
         ' . $this->getJsUploadValidation() . '
         });
         </script>';
 }
Esempio n. 5
0
File: utils.php Progetto: lmcro/fcms
/**
 * userConnectedSocialMedia 
 * 
 * @param int $userId 
 * 
 * @return boolean
 */
function userConnectedSocialMedia($userId)
{
    // Get Social Media data
    $facebook = getUserFacebookAccessToken($userId);
    $foursquare = getFoursquareUserData($userId);
    $google = getGoogleUserData($userId);
    // Facebook
    if (!empty($facebook)) {
        return true;
    }
    // Foursquare
    if (!empty($foursquare['fs_user_id']) && !empty($foursquare['fs_access_token'])) {
        return true;
    }
    // Google
    if (!empty($google['google_session_token'])) {
        return true;
    }
    return false;
}