Esempio n. 1
0
 /**
  *
  * Parse $xml and return array of blogs
  * each element in that array is an array
  * with keys: 'id', 'title' and 'url'
  *
  * @param string $xml xml returned by Blogger API
  * in response to request https://www.blogger.com/feeds/default/blogs
  * by an authenticated user (using OAuth credentials)
  *
  * @throws \Exception
  */
 public function getBlogs($xml)
 {
     $aBlogs = array();
     $XML = new \Lampcms\Dom\Document();
     if (false === $XML->loadXML($xml)) {
         $err = 'Unexpected Error parsing response XML';
         throw new \Exception($err);
     }
     $xp = new \DOMXPath($XML);
     $xp->registerNamespace('atom', "http://www.w3.org/2005/Atom");
     $aParsed = $XML->getElementsByTagName('entry');
     if (0 === $aParsed->length) {
         e('Looks like user does not have any blogs: $xml: ' . $xml);
         $err = 'Looks like you have Blogger account but do not have any blogs setup yet';
         throw new \Exception($err);
     }
     foreach ($aParsed as $blog) {
         $aBlog = array();
         $aBlog['id'] = $this->getId($blog);
         $aBlog['title'] = $blog->getElementsByTagName('title')->item(0)->nodeValue;
         $r = $xp->query('atom:link[@type = "text/html"]/@href', $blog);
         $aBlog['url'] = $r->length > 0 ? $r->item(0)->nodeValue : null;
         if (!empty($aBlog['url']) && !empty($aBlog['id'])) {
             $aBlogs[] = $aBlog;
         }
     }
     return $aBlogs;
 }
Esempio n. 2
0
 /**
  * Parses the XML returned from LinkedIn API
  * and creates array of $this->aData from it
  *
  * @param string xml xml string received from LinkedIn API
  *
  * @return object $this
  *
  * @throws \Lampcms\Exception if xml could not
  * be parsed for any reason
  */
 protected function parseXML($xml)
 {
     d('xml: ' . $xml);
     $oXML = new \Lampcms\Dom\Document();
     if (false === $oXML->loadXML($xml)) {
         $err = 'Unexpected Error parsing response XML';
         throw new \Lampcms\DevException($err);
     }
     $lid = $oXML->evaluate('string(/person/id[1])');
     // it will be string!
     if (!$lid) {
         throw new \Lampcms\Exception('Unable to get LinkedIn ID');
     }
     $this->aData['linkedin_id'] = (string) $lid;
     if ('' !== ($industry = $oXML->evaluate('string(/person/industry[1])'))) {
         $this->aData['industry'] = $industry;
     }
     if ('' !== ($summary = $oXML->evaluate('string(/person/summary[1])'))) {
         $this->aData['description'] = $summary;
     }
     if ('' !== ($city = $oXML->evaluate('string(/person/location/name[1])'))) {
         $this->aData['city'] = $city;
     }
     if ('' !== ($cc = $oXML->evaluate('string(/person/location/country/code[1])'))) {
         $this->aData['cc'] = \strtoupper($cc);
     }
     if ('' !== ($avtr = $oXML->evaluate('string(/person/picture-url[1])'))) {
         $this->aData['avatar_external'] = $avtr;
     }
     if ('' !== ($fn = $oXML->evaluate('string(/person/first-name[1])'))) {
         $this->aData['fn'] = $fn;
     }
     if ('' !== ($ln = $oXML->evaluate('string(/person/last-name[1])'))) {
         $this->aData['ln'] = $ln;
     }
     $this->aData['linkedin'] = array('tokens' => $this->aAccessToken);
     if ('' !== ($url = $oXML->evaluate('string(/person/public-profile-url[1])'))) {
         $this->aData['linkedin']['url'] = $url;
     }
     d('$this->aData: ' . print_r($this->aData, 1));
     return $this;
 }
 /**
  * Get email address from LinkedIN API
  *
  */
 protected function getEmailAddress()
 {
     d('cp');
     try {
         $this->oAuth->fetch(self::EMAIL_URL, null, OAUTH_HTTP_METHOD_GET, array('Connection' => 'close'));
         $resp = $this->oAuth->getLastResponse();
         /**
          * May return empty element
          *
          * $resp: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          * <email-address />
          *
          */
         d('EMAIL ADDRESS RESPONSE: ' . $resp);
         $oXML = new \Lampcms\Dom\Document();
         if (false === $oXML->loadXML($resp)) {
             $err = 'Unexpected Error parsing email address response XML';
             e($err);
             return;
         }
         $email = $oXML->evaluate('string(/email-address[1])');
         d('email: ' . $email);
         if (!empty($email)) {
             $this->email = \mb_strtolower($email);
         }
     } catch (\OAuthException $e) {
         e('Unable to fetch email address. OAuthException: ' . $e->getMessage());
         $aDebug = $this->oAuth->getLastResponseInfo();
         d('debug: ' . print_r($aDebug, 1));
     }
 }