function updated($fallback = true, $default = -1) { $date = ''; # As far as I know, only dcterms and Atom have reliable ways to # specify when something was *modified* last. If neither is # available, then we'll try to get the time of publication. if (isset($this->item['dc']['modified'])) { // Not really correct $date = $this->item['dc']['modified']; } elseif (isset($this->item['dcterms']['modified'])) { // Dublin Core extensions $date = $this->item['dcterms']['modified']; } elseif (isset($this->item['modified'])) { // Atom 0.3 $date = $this->item['modified']; } elseif (isset($this->item['updated'])) { // Atom 1.0 $date = $this->item['updated']; } if (strlen($date) > 0) { $time = new FeedTime($date); $epoch = $time->timestamp(); } elseif ($fallback) { // Fall back to issued / dc:date $epoch = $this->published(false, $default); } # If everything failed, then default to the current time. if (is_null($epoch)) { if (-1 == $default) { $epoch = time(); } else { $epoch = $default; } } return $epoch; }
function updated($params = array(), $default = -1) { $fallback = true; $unfiltered = false; if (!is_array($params)) { // Old style $fallback = $params; } else { // New style extract($params); } $date = ''; $ts = null; # As far as I know, only dcterms and Atom have reliable ways to # specify when something was *modified* last. If neither is # available, then we'll try to get the time of publication. if (isset($this->item['dc']['modified'])) { // Not really correct $date = $this->item['dc']['modified']; } elseif (isset($this->item['dcterms']['modified'])) { // Dublin Core extensions $date = $this->item['dcterms']['modified']; } elseif (isset($this->item['modified'])) { // Atom 0.3 $date = $this->item['modified']; } elseif (isset($this->item['updated'])) { // Atom 1.0 $date = $this->item['updated']; } if (strlen($date) > 0) { $time = new FeedTime($date); $ts = $time->timestamp(); } elseif ($fallback) { // Fall back to issued / dc:date $ts = $this->published(false, $default); } # If everything failed, then default to the current time. if (is_null($ts)) { if (-1 == $default) { $ts = time(); } else { $ts = $default; } } if (!$unfiltered) { apply_filters('syndicated_item_updated', $ts, $this); } return $ts; }
/** * MagpieFromSimplePie::normalize * * @uses MagpieFromSimplePie::is_atom * @uses MagpieFromSimplePie::is_rss * @uses MagpieFromSimplePie::normalize_element * @uses MagpieFromSimplePie::normalize_author_inheritance * @uses MagpieFromSimplePie::normalize_atom_person * @uses MagpieFromSimplePie::normalize_enclosure * @uses MagpieFromSimplePie::normalize_category * @uses MagpieFromSimplePie::normalize_dc_subject * @uses FeedTime * @uses FeedTime::timestamp */ function normalize() { do_action('feedwordpress_magpiefromsimplepie_normalize_pre', $this); if (!is_null($this->channel)) { // Normalize channel data if ($this->is_atom()) { // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!) if ($this->feed_version() < 1.0) { $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle'); $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights'); $this->normalize_element($this->channel, 'modified', $this->channel, 'updated'); } else { $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline'); $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright'); $this->normalize_element($this->channel, 'updated', $this->channel, 'modified'); } $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person'); $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person'); // Atom elements to RSS elements $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description'); if (isset($this->channel['logo'])) { $this->normalize_element($this->channel, 'logo', $this->image, 'url'); $this->normalize_element($this->channel, 'link', $this->image, 'link'); $this->normalize_element($this->channel, 'title', $this->image, 'title'); } } elseif ($this->is_rss()) { // Normalize image element from where stupid MagpieRSS puts it //$this->normalize_element($this->channel, 'image_title', $this->image, 'title'); //$this->normalize_element($this->channel, 'image_link', $this->image, 'link'); //$this->normalize_element($this->channel, 'image_url', $this->image, 'url'); // ... and, gag, textInput //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title'); //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link'); //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name'); //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description'); // RSS elements to Atom elements $this->normalize_element($this->channel, 'description', $this->channel, 'tagline'); // Atom 0.3 $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle'); // Atom 1.0 (yay wordsmithing!) $this->normalize_element($this->image, 'url', $this->channel, 'logo'); } } if (!is_null($this->items)) { // Now loop through and normalize item data for ($i = 0; $i < count($this->items); $i++) { $item = $this->items[$i]; // if atom populate rss fields and normalize 0.3 and 1.0 feeds if ($this->is_atom()) { // Atom 1.0 elements <=> Atom 0.3 elements if ($this->feed_version() < 1.0) { $this->normalize_element($item, 'modified', $item, 'updated'); $this->normalize_element($item, 'issued', $item, 'published'); } else { $this->normalize_element($item, 'updated', $item, 'modified'); $this->normalize_element($item, 'published', $item, 'issued'); } $this->normalize_author_inheritance($item, $this->originals[$i]); // Atom elements to RSS elements $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person'); $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person'); $this->normalize_element($item, 'summary', $item, 'description'); $this->normalize_element($item, 'atom_content', $item['content'], 'encoded'); $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure'); // Categories if (isset($item['category#'])) { // Atom 1.0 categories to dc:subject and RSS 2.0 categories $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); } elseif (isset($item['dc']['subject#'])) { // dc:subject to Atom 1.0 and RSS 2.0 categories $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); } // Normalized item timestamp $item_date = isset($item['published']) ? $item['published'] : $item['updated']; } elseif ($this->is_rss()) { // RSS elements to Atom elements $this->normalize_element($item, 'description', $item, 'summary'); $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure'); // Categories if (isset($item['category#'])) { // RSS 2.0 categories to dc:subject and Atom 1.0 categories $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); } elseif (isset($item['dc']['subject#'])) { // dc:subject to Atom 1.0 and RSS 2.0 categories $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); } // Normalized item timestamp if (isset($item['pubdate'])) { $item_date = $item['pubdate']; } elseif (isset($item['dc']['date'])) { $item_date = $item['dc']['date']; } else { $item_date = null; } } if ($item_date) { $date_timestamp = new FeedTime($item_date); if (!$date_timestamp->failed()) { $item['date_timestamp'] = $date_timestamp->timestamp(); } } $this->items[$i] = $item; } } do_action('feedwordpress_magpiefromsimplepie_normalize_post', $this); }