示例#1
0
 /**
  * Get the update date/time for the item
  *
  * Uses `<atom:updated>`
  *
  * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  * {@see get_gmdate}
  *
  * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  * @return int|string|null
  */
 public function get_updated_date($date_format = 'j F Y, g:i a')
 {
     if (!isset($this->data['updated'])) {
         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) {
             $this->data['updated']['raw'] = $return[0]['data'];
         }
         if (!empty($this->data['updated']['raw'])) {
             $parser = $this->registry->call('Parse_Date', 'get');
             $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
         } else {
             $this->data['updated'] = null;
         }
     }
     if ($this->data['updated']) {
         $date_format = (string) $date_format;
         switch ($date_format) {
             case '':
                 return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
             case 'U':
                 return $this->data['updated']['parsed'];
             default:
                 return date($date_format, $this->data['updated']['parsed']);
         }
     } else {
         return null;
     }
 }
示例#2
0
文件: Item.php 项目: oparoz/core-1
 /**
  * Get all links for the item
  *
  * Uses `<atom:link>`, `<link>` or `<guid>`
  *
  * @since Beta 2
  * @param string $rel The relationship of links to return
  * @return array|null Links found for the item (strings)
  */
 public function get_links($rel = 'alternate')
 {
     if (!isset($this->data['links'])) {
         $this->data['links'] = array();
         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) {
             if (isset($link['attribs']['']['href'])) {
                 $link_rel = isset($link['attribs']['']['rel']) ? $link['attribs']['']['rel'] : 'alternate';
                 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
             }
         }
         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) {
             if (isset($link['attribs']['']['href'])) {
                 $link_rel = isset($link['attribs']['']['rel']) ? $link['attribs']['']['rel'] : 'alternate';
                 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
             }
         }
         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) {
             $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
         }
         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) {
             $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
         }
         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) {
             $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
         }
         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid')) {
             if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true') {
                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
             }
         }
         $keys = array_keys($this->data['links']);
         foreach ($keys as $key) {
             if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) {
                 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) {
                     $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
                     $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
                 } else {
                     $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
                 }
             } elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) {
                 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
             }
             $this->data['links'][$key] = array_unique($this->data['links'][$key]);
         }
     }
     if (isset($this->data['links'][$rel])) {
         return $this->data['links'][$rel];
     } else {
         return null;
     }
 }
示例#3
0
 /**
  * Get the copyright info for the feed
  *
  * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
  *
  * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
  * @return string|null
  */
 public function get_copyright()
 {
     if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) {
         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
     } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) {
         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
     } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) {
         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
     } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) {
         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
     } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) {
         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
     } else {
         return null;
     }
 }