Example #1
0
 /**
  * Convenienve method extracting author data according to the microformats authorship algorithm
  * 
  * @param \int $entry										h-entry index
  * @return \Jkphl\Micrometa\Parser\Microformats2\Item		Author micro information item
  * @see http://indiewebcamp.com/authorship
  */
 public function author($entry = 0)
 {
     try {
         // 1. Look for the appropriate h-entry within the document
         $hEntry = $this->hEntry($entry);
         // 2. Try to find p-author property respectively a nested h-card
         $authorItem = $hEntry->author;
         if ($authorItem instanceof \Jkphl\Micrometa\Parser\Microformats2\Item && $authorItem->isOfType('h-card')) {
             return $authorItem;
         }
         // 3. If there's no p-author property / nested h-card
         $authorUrl = trim($this->rel('author', 0));
         // 3.1. If there's an author page
         if (strlen($authorUrl)) {
             $authorProfileUrl = \Jkphl\Utility\Url::instance($authorUrl, true, $this->baseUrl);
             $authorUrl = "{$authorProfileUrl}";
             $authorProfile = new self($authorProfileUrl);
             $hCards = array();
             // Run through all h-cards on the author profile page
             foreach ((array) $authorProfile->hCard() as $hCard) {
                 if ($hCard instanceof \Jkphl\Micrometa\Parser\Microformats2\Item && $hCard->isOfType('h-card')) {
                     // Run through all uid properties (there should only be one!)
                     try {
                         foreach ((array) $hCard->uid() as $uidUrl) {
                             if (strval(\Jkphl\Utility\Url::instance($uidUrl, true, $authorProfileUrl)) == $authorUrl) {
                                 // Compare with each URL registered with the h-card
                                 foreach ((array) $hCard->url() as $hCardUrl) {
                                     // 3.1.2. In case of a match: Use this h-card as the author
                                     if (\Jkphl\Utility\Url::instance($hCardUrl, true, $authorProfileUrl) == $authorUrl) {
                                         return $hCard;
                                     }
                                 }
                             }
                         }
                     } catch (\Jkphl\Micrometa\Parser\Microformats2\Exception $e) {
                     }
                     $hCards[] = $hCard;
                 }
             }
             // Gather all rel-me URLs on the author profile page
             $meUrls = array();
             foreach ((array) $authorProfile->rel('me') as $meUrl) {
                 if (strlen($meUrl)) {
                     $meUrls[] = strval(\Jkphl\Utility\Url::instance($meUrl, true, $authorProfileUrl));
                 }
             }
             // Run through all the h-cards on the author profile page again
             foreach ($hCards as $hCard) {
                 // Compare the rel-me URLS with every h-card URL
                 foreach ((array) $hCard->url() as $hCardUrl) {
                     // 3.1.3. In case of a match: Use this h-card as the author
                     if (in_array(strval(\Jkphl\Utility\Url::instance($hCardUrl, true, $authorProfileUrl)), $meUrls)) {
                         return $hCard;
                     }
                 }
             }
             // Final try: Run through all h-cards on the h-entry's page
             foreach ((array) $this->hCard() as $hCard) {
                 // Compare the rel-author URL with every h-card URL
                 foreach ((array) $hCard->url() as $hCardUrl) {
                     // 3.1.4. In case of a match: Use this h-card as the author
                     if ($authorUrl == strval(\Jkphl\Utility\Url::instance($hCardUrl, true, $authorProfileUrl))) {
                         return $hCard;
                     }
                 }
             }
         }
     } catch (\Jkphl\Micrometa\Parser\Microformats2\Exception $exception) {
     }
     return null;
 }
Example #2
0
 /**
  * Sanitize URL values
  * 
  * @param \string $property		Property name
  * @param \mixed $value			Value
  * @return mixed 				URL resolved value
  */
 protected function _resolveUrlValue($property, $value)
 {
     return in_array($property, self::$urlProperties) ? strval(\Jkphl\Utility\Url::instance($value, true, $this->_url)) : $value;
 }