Example #1
0
 /**
  * Get actual avatar data (jpeg binary data)
  *
  * @param $since
  * @param $etag
  * @return unknown_type
  */
 public function fetchGravatar($since = null, $etag = null)
 {
     $oHTTP = new Curl();
     if (!isset($this->url)) {
         $this->setAvatarUrl();
     }
     try {
         $this->oResponse = $oHTTP->getDocument($this->url, $since, $etag)->checkResponse();
         $this->gravatar = $this->oResponse->getResponseBody();
         $this->gravatarExists = 'Y';
         d('has gravatar = Y');
     } catch (Exception $e) {
         $this->gravatarExists = 'U';
         if ($e instanceof Http404Exception) {
             d('No gravatar');
             $this->gravatarExists = 'N';
         }
     }
     return $this;
 }
 /**
  * Get JSON data from the server for this user
  * If timeout, then what? Then we will throw our own
  * Exception and user will see a message
  * that timeout has occured
  *
  *
  * @param string $fcauth value of fcauth cookie
  */
 protected function getGfcData()
 {
     $url = 'http://www.google.com/friendconnect/api/people/@viewer/@self?fcauth=' . $this->fcauth;
     $oHTTP = new Curl();
     try {
         d('cp');
         $this->oResponse = $oHTTP->getDocument($url)->checkResponse();
         $gfcJson = $this->oResponse->getResponseBody();
         d('gfcJson ' . $gfcJson);
         $aGfcData = json_decode($gfcJson, true);
         d('$gGfcData: ' . print_r($aGfcData, 1));
         if (empty($aGfcData) || !is_array($aGfcData) || !array_key_exists('entry', $aGfcData) || empty($aGfcData['entry']['id'])) {
             throw new GFCAuthException('Invalid data returned by FriendConnect server');
         }
         $this->aGfcData = $aGfcData['entry'];
         /**
         * this->gGfcData: Array
         (
         [entry] => Array
         (
         [isViewer] => 1
         [id] => 11683420763934692837
         [thumbnailUrl] => http://www.google.com/friendconnect/scs/images/NoPictureDark.png
         [photos] => Array
         (
         [0] => Array
         (
         [value] => http://www.google.com/friendconnect/scs/images/NoPictureDark.png
         [type] => thumbnail
         )
         
         )
         
         [displayName] => David Smith
         )
         
         )
         */
     } catch (HttpTimeoutException $e) {
         d('Request to GFC server timedout');
         throw new GFCAuthException('Request to Google Friend connect server timed out. Please try again later');
     } catch (Http401Exception $e) {
         d('Unauthorized to get data from gfc, most likely user unjoined the site');
         $this->revokeFcauth();
         throw new GFCAuthException('Anauthorized with Friend Connect server');
     } catch (HttpResponseCodeException $e) {
         e('LampcmsError gfc response exception: ' . $e->getHttpCode() . ' ' . $e->getMessage());
         /**
          * The non-200 response code means there is some kind
          * of error, maybe authorization failed or something like that,
          * or maybe Friend Connect server was acting up,
          * in this case it is better to delete fcauth cookies
          * so that we dont go through these steps again.
          * User will just have to re-do the login fir GFC step
          */
         Cookie::delete(array('fcauth' . $this->gfcSiteId . '-s', 'fcauth' . $this->gfcSiteId));
         throw new GFCAuthException('Error during authentication with Friend Connect server');
     }
 }
Example #3
0
 /**
  * Ping a bunch of search engines to tell
  * them about our new sitemap file
  *
  * @return object $this
  */
 protected function pingSearchSites()
 {
     $Http = new Curl();
     $url = $this->baseUrl . '/w/sitemap/' . $this->siteMapName;
     foreach ($this->aPingUrls as $key => $val) {
         try {
             $pingUrl = sprintf($val, $url);
             d('going to ping ' . $key . ' url: ' . $pingUrl);
             $Http->getDocument($url);
             $code = $Http->getHttpResponseCode();
             d('pinged ' . $key . ' response code: ' . $code);
         } catch (\Exception $e) {
             $err = 'Unable to ping ' . $key . ' got error: ' . $e->getMessage();
             e('Error: ' . $err);
         }
     }
     return $this;
 }