| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * class MagpieFromSimplePie: compatibility layer to prevent existing filters |
| 6 | 6 | * from breaking. |
| 7 | 7 | * |
| 8 | 8 | * @since 2010.0203 |
| 9 | - * @version 2010.0612 | |
| 9 | + * | |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | class MagpieFromSimplePie { |
| 13 | 13 | var $pie; |
| @@ -19,42 +19,40 @@ | ||
| 19 | 19 | var $image = array(); |
| 20 | 20 | |
| 21 | 21 | var $feed_type; |
| 22 | 22 | var $feed_version; |
| 23 | - /** @var string MIME ncoding (was missing). */ | |
| 24 | - var $encoding; | |
| 25 | 23 | |
| 26 | 24 | var $_XMLNS_FAMILIAR = array ( |
| 27 | 25 | 'http://www.w3.org/2005/Atom' => 'atom' /* 1.0 */, |
| 28 | - 'http://purl.org/atom/ns#' => 'atom' /* pre-1.0 */, | |
| 29 | - 'http://purl.org/rss/1.0/' => 'rss' /* 1.0 */, | |
| 30 | - 'http://backend.userland.com/RSS2' => 'rss' /* 2.0 */, | |
| 31 | - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf', | |
| 32 | - 'http://www.w3.org/1999/xhtml' => 'xhtml', | |
| 33 | - 'http://purl.org/dc/elements/1.1/' => 'dc', | |
| 34 | - 'http://purl.org/dc/terms/' => 'dcterms', | |
| 35 | - 'http://purl.org/rss/1.0/modules/content/' => 'content', | |
| 36 | - 'http://purl.org/rss/1.0/modules/syndication/' => 'sy', | |
| 37 | - 'http://purl.org/rss/1.0/modules/taxonomy/' => 'taxo', | |
| 38 | - 'http://purl.org/rss/1.0/modules/dc/' => 'dc', | |
| 39 | - 'http://wellformedweb.org/CommentAPI/' => 'wfw', | |
| 40 | - 'http://webns.net/mvcb/' => 'admin', | |
| 41 | - 'http://purl.org/rss/1.0/modules/annotate/' => 'annotate', | |
| 42 | - 'http://xmlns.com/foaf/0.1/' => 'foaf', | |
| 43 | - 'http://madskills.com/public/xml/rss/module/trackback/' => 'trackback', | |
| 44 | - 'http://web.resource.org/cc/' => 'cc', | |
| 45 | - 'http://search.yahoo.com/mrss' => 'media', | |
| 46 | - 'http://search.yahoo.com/mrss/' => 'media', | |
| 47 | - 'http://video.search.yahoo.com/mrss' => 'media', | |
| 48 | - 'http://video.search.yahoo.com/mrss/' => 'media', | |
| 49 | - 'http://purl.org/syndication/thread/1.0' => 'thr', | |
| 50 | - 'http://purl.org/syndication/thread/1.0/' => 'thr', | |
| 51 | - 'http://www.w3.org/XML/1998/namespace' => 'xml', | |
| 52 | - 'http://www.itunes.com/dtds/podcast-1.0.dtd' => 'itunes', | |
| 53 | - 'http://a9.com/-/spec/opensearchrss/1.0/' => 'openSearch', | |
| 54 | - 'http://purl.org/rss/1.0/modules/slash/' => 'slash', | |
| 55 | - 'http://www.google.com/schemas/reader/atom/' => 'gr', | |
| 56 | - 'urn:atom-extension:indexing' => 'indexing', | |
| 26 | + 'http://purl.org/atom/ns#' => 'atom' /* pre-1.0 */, | |
| 27 | + 'http://purl.org/rss/1.0/' => 'rss' /* 1.0 */, | |
| 28 | + 'http://backend.userland.com/RSS2' => 'rss' /* 2.0 */, | |
| 29 | + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf', | |
| 30 | + 'http://www.w3.org/1999/xhtml' => 'xhtml', | |
| 31 | + 'http://purl.org/dc/elements/1.1/' => 'dc', | |
| 32 | + 'http://purl.org/dc/terms/' => 'dcterms', | |
| 33 | + 'http://purl.org/rss/1.0/modules/content/' => 'content', | |
| 34 | + 'http://purl.org/rss/1.0/modules/syndication/' => 'sy', | |
| 35 | + 'http://purl.org/rss/1.0/modules/taxonomy/' => 'taxo', | |
| 36 | + 'http://purl.org/rss/1.0/modules/dc/' => 'dc', | |
| 37 | + 'http://wellformedweb.org/CommentAPI/' => 'wfw', | |
| 38 | + 'http://webns.net/mvcb/' => 'admin', | |
| 39 | + 'http://purl.org/rss/1.0/modules/annotate/' => 'annotate', | |
| 40 | + 'http://xmlns.com/foaf/0.1/' => 'foaf', | |
| 41 | + 'http://madskills.com/public/xml/rss/module/trackback/' => 'trackback', | |
| 42 | + 'http://web.resource.org/cc/' => 'cc', | |
| 43 | + 'http://search.yahoo.com/mrss' => 'media', | |
| 44 | + 'http://search.yahoo.com/mrss/' => 'media', | |
| 45 | + 'http://video.search.yahoo.com/mrss' => 'media', | |
| 46 | + 'http://video.search.yahoo.com/mrss/' => 'media', | |
| 47 | + 'http://purl.org/syndication/thread/1.0' => 'thr', | |
| 48 | + 'http://purl.org/syndication/thread/1.0/' => 'thr', | |
| 49 | + 'http://www.w3.org/XML/1998/namespace' => 'xml', | |
| 50 | + 'http://www.itunes.com/dtds/podcast-1.0.dtd' => 'itunes', | |
| 51 | + 'http://a9.com/-/spec/opensearchrss/1.0/' => 'openSearch', | |
| 52 | + 'http://purl.org/rss/1.0/modules/slash/' => 'slash', | |
| 53 | + 'http://www.google.com/schemas/reader/atom/' => 'gr', | |
| 54 | + 'urn:atom-extension:indexing' => 'indexing', | |
| 57 | 55 | ); |
| 58 | 56 | |
| 59 | 57 | /** |
| 60 | 58 | * MagpieFromSimplePie constructor |
| @@ -59,77 +57,40 @@ | ||
| 59 | 57 | /** |
| 60 | 58 | * MagpieFromSimplePie constructor |
| 61 | 59 | * |
| 62 | 60 | * @param SimplePie $pie The feed to convert to MagpieRSS format. |
| 63 | - * @param mixed $item | |
| 64 | 61 | * |
| 65 | - * @uses SimplePie::get_items | |
| 66 | - * @uses MagpieFromSimplePie::processFeedData | |
| 67 | 62 | * @uses MagpieFromSimplePie::processItemData |
| 68 | - * @uses MagpieFromSimplePie::normalize | |
| 69 | - * @uses MagpieFromSimplePie::is_atom | |
| 63 | + * @uses MagpieFromSimplePie::normalize | |
| 70 | 64 | */ |
| 71 | - function __construct( $pie, $item = true ) { | |
| 65 | + function MagpieFromSimplePie ($pie) { | |
| 72 | 66 | $this->pie = $pie; |
| 67 | + $this->originals = $this->pie->get_items(); | |
| 73 | 68 | |
| 74 | - // item in {NULL, true} = process channel data | |
| 75 | - if ( !is_a($item, 'SimplePie_Item')) : | |
| 76 | - $this->originals = $this->pie->get_items(); | |
| 69 | + $this->channel = $this->processFeedData($this->pie->data); | |
| 70 | + foreach ($this->originals as $key => $item) : | |
| 71 | + $this->items[$key] = $this->processItemData($item->data); | |
| 72 | + endforeach; | |
| 77 | 73 | |
| 78 | - $this->channel = $this->processFeedData($this->pie->data); | |
| 79 | - else : | |
| 80 | - $this->originals = array($item); | |
| 81 | - $this->channel = NULL; | |
| 82 | - endif; | |
| 83 | - | |
| 84 | - // item in {true, SimplePie_Item} = process item data | |
| 85 | - if ( !is_null($item)) : | |
| 86 | - foreach ($this->originals as $key => $item) : | |
| 87 | - $this->items[$key] = $this->processItemData($item->data); | |
| 88 | - endforeach; | |
| 89 | - else : | |
| 90 | - $this->items = NULL; | |
| 91 | - endif; | |
| 92 | - | |
| 93 | 74 | $this->normalize(); |
| 94 | 75 | |
| 95 | 76 | // In case anyone goes poking around our private members (uh...) |
| 96 | 77 | $this->feed_type = ($this->is_atom() ? 'Atom' : 'RSS'); |
| 97 | 78 | $this->feed_version = $this->feed_version(); |
| 98 | - $this->encoding = $pie->get_encoding(); | |
| 99 | 79 | } /* MagpieFromSimplePie constructor */ |
| 100 | - | |
| 101 | - function MagpieFromSimplePie( $pie, $item = true ) { | |
| 102 | - self::__construct( $pie, $item ); | |
| 103 | - } | |
| 104 | - | |
| 80 | + | |
| 105 | 81 | /** |
| 106 | - * MagpieFromSimplePie::get_items: returns an array of MagpieRSS format arrays | |
| 107 | - * equivalent to the SimplePie_Item objects in the SimplePie object from which this | |
| 82 | + * MagpieFromSimplePie::get_item: returns a MagpieRSS format array | |
| 83 | + * which is equivalent to the SimplePie_Item object from which this | |
| 108 | 84 | * object was constructed. |
| 109 | - * | |
| 110 | - * @return array An array of MagpieRSS-format arrays representing the items on this feed | |
| 85 | + * | |
| 86 | + * @return array A MagpieRSS format array representing this feed item. | |
| 111 | 87 | */ |
| 112 | 88 | function get_items () { |
| 113 | 89 | return $this->items; |
| 114 | - } /* MagpieFromSimplePie::get_items () */ | |
| 115 | - | |
| 90 | + } /* MagpieFromSimplePie::get_item */ | |
| 91 | + | |
| 116 | 92 | /** |
| 117 | - * MagpieFromSimplePie::get_item: returns a single MagpieRSS format array equivalent | |
| 118 | - * to a SimplePie_Item object from which this object was constructed. | |
| 119 | - * | |
| 120 | - * @return array A MagpieRSS-format array representing an item on this feed | |
| 121 | - */ | |
| 122 | - function get_item () { | |
| 123 | - if (is_array($this->items)) : | |
| 124 | - $ret = reset($this->items); | |
| 125 | - else : | |
| 126 | - $ret = NULL; | |
| 127 | - endif; | |
| 128 | - return $ret; | |
| 129 | - } /* MagpieFromSimplePie::get_item () */ | |
| 130 | - | |
| 131 | - /** | |
| 132 | 93 | * MagpieFromSimplePie::processFeedData |
| 133 | 94 | * |
| 134 | 95 | * @param array $data |
| 135 | 96 | * @return array |
| @@ -151,9 +112,9 @@ | ||
| 151 | 112 | ) as $ns) : |
| 152 | 113 | if (isset($element['child'][$ns]['entry'])) : unset($element['child'][$ns]['entry']); endif; |
| 153 | 114 | if (isset($element['child'][$ns]['item'])) : unset($element['child'][$ns]['item']); endif; |
| 154 | 115 | endforeach; |
| 155 | - | |
| 116 | + | |
| 156 | 117 | $ret = $this->processChannelData($element) + $ret; |
| 157 | 118 | elseif (in_array(strtolower($name), array('rss', 'rdf'))) : |
| 158 | 119 | // Drop down to get to <channel> element |
| 159 | 120 | $ret = $this->processFeedData($element) + $ret; |
| @@ -160,10 +121,9 @@ | ||
| 160 | 121 | endif; |
| 161 | 122 | endforeach; |
| 162 | 123 | endforeach; |
| 163 | 124 | endforeach; endif; |
| 164 | - | |
| 165 | - return apply_filters('feedwordpress_magpiefromsimplepie_processfeeddata', $ret, $data, $this); | |
| 125 | + return $ret; | |
| 166 | 126 | } /* MagpieFromSimplePie::processFeedData() */ |
| 167 | 127 | |
| 168 | 128 | /** |
| 169 | 129 | * MagpieFromSimplePie::processChannelData |
| @@ -177,9 +137,9 @@ | ||
| 177 | 137 | */ |
| 178 | 138 | function processChannelData ($data, $path = array()) { |
| 179 | 139 | $ret = array(); |
| 180 | 140 | $tagPath = strtolower(implode('_', $path)); |
| 181 | - | |
| 141 | + | |
| 182 | 142 | // Only process at the right level |
| 183 | 143 | if (strlen($tagPath) > 0 |
| 184 | 144 | and isset($data['data']) |
| 185 | 145 | and strlen($data['data']) > 0) : |
| @@ -184,14 +144,14 @@ | ||
| 184 | 144 | and isset($data['data']) |
| 185 | 145 | and strlen($data['data']) > 0) : |
| 186 | 146 | $ret[$tagPath] = $data['data']; |
| 187 | 147 | endif; |
| 188 | - | |
| 148 | + | |
| 189 | 149 | $ret = $this->handleAttributes($data, $path) |
| 190 | 150 | + $this->handleChildren($data, $path, 'processChannelData') |
| 191 | 151 | + $ret; |
| 192 | 152 | |
| 193 | - return apply_filters('feedwordpress_magpiefromsimplepie_processchanneldata', $ret, $data, $path, $this); | |
| 153 | + return $ret; | |
| 194 | 154 | } /* MagpieFromSimplePie::processChannelData() */ |
| 195 | 155 | |
| 196 | 156 | /** |
| 197 | 157 | * MagpieFromSimplePie::processItemData |
| @@ -205,23 +165,23 @@ | ||
| 205 | 165 | */ |
| 206 | 166 | function processItemData ($data, $path = array()) { |
| 207 | 167 | $ret = array(); |
| 208 | 168 | $tagPath = strtolower(implode('_', $path)); |
| 209 | - | |
| 169 | + | |
| 210 | 170 | if (strlen($tagPath) > 0 and isset($data['data']) and strlen($data['data']) > 0) : |
| 211 | 171 | $ret[$tagPath] = $data['data']; |
| 212 | 172 | endif; |
| 213 | - | |
| 173 | + | |
| 214 | 174 | // Set up xml:base to be recorded in array |
| 215 | 175 | if (isset($data['xml_base_explicit']) and $data['xml_base_explicit']) : |
| 216 | 176 | $data['attribs']['']['xml:base'] = $data['xml_base']; |
| 217 | 177 | endif; |
| 218 | - | |
| 178 | + | |
| 219 | 179 | $ret = $this->handleAttributes($data, $path) |
| 220 | 180 | + $this->handleChildren($data, $path, 'processItemData') |
| 221 | 181 | + $ret; |
| 222 | 182 | |
| 223 | - return apply_filters('feedwordpress_magpiefromsimplepie_processitemdata', $ret, $data, $path, $this); | |
| 183 | + return $ret; | |
| 224 | 184 | } /* MagpieFromSimplePie::processItemData() */ |
| 225 | 185 | |
| 226 | 186 | /** |
| 227 | 187 | * MagpieFromSimplePie::handleAttributes |
| @@ -256,12 +216,11 @@ | ||
| 256 | 216 | $ret[$tagPath.'@'] .= $attr; |
| 257 | 217 | endif; |
| 258 | 218 | endforeach; |
| 259 | 219 | endforeach; endif; |
| 260 | - | |
| 261 | - return apply_filters('feedwordpress_magpiefromsimplepie_handleattributes', $ret, $data, $path, $this); | |
| 220 | + return $ret; | |
| 262 | 221 | } /* MagpieFromSimplePie::handleAttributes() */ |
| 263 | - | |
| 222 | + | |
| 264 | 223 | var $inImage = false; |
| 265 | 224 | var $inTextInput = false; |
| 266 | 225 | |
| 267 | 226 | /** |
| @@ -276,9 +235,9 @@ | ||
| 276 | 235 | * @uses MagpieFromSimplePie::increment_element |
| 277 | 236 | * @uses MagpieFromSimplePie::processItemData |
| 278 | 237 | */ |
| 279 | 238 | function handleChildren ($data, $path = array(), $method = 'processItemData') { |
| 280 | - $tagPath = strtolower(implode('_', $path)); // what is this for? It's never used... (gwyneth 20230918) | |
| 239 | + $tagPath = strtolower(implode('_', $path)); | |
| 281 | 240 | $ret = array(); |
| 282 | 241 | if (isset($data['child'])) : foreach ($data['child'] as $ns => $elements) : |
| 283 | 242 | if (isset($this->_XMLNS_FAMILIAR[$ns])) : |
| 284 | 243 | $ns = $this->_XMLNS_FAMILIAR[$ns]; |
| @@ -317,13 +276,13 @@ | ||
| 317 | 276 | ); |
| 318 | 277 | elseif ('content'==$tag and 'atom'==$ns) : |
| 319 | 278 | $childTag = 'atom_'.$tag; |
| 320 | 279 | endif; |
| 321 | - | |
| 280 | + | |
| 322 | 281 | $childTag = $this->increment_element($ret, $childTag, $ns, $path); |
| 323 | - $childPath = $path; $childPath[] = strtolower($childTag); | |
| 282 | + $childPath = $path; $childPath[] = strtolower($childTag); | |
| 324 | 283 | |
| 325 | - if ( !is_null($copyOver)) : | |
| 284 | + if (!is_null($copyOver)) : | |
| 326 | 285 | $co = array(); |
| 327 | 286 | $co[implode('_', $childPath)] = $copyOver; |
| 328 | 287 | else : |
| 329 | 288 | $co = NULL; |
| @@ -333,30 +292,29 @@ | ||
| 333 | 292 | $arr = $this->{$method}($element, $childPath); |
| 334 | 293 | if ($co) : |
| 335 | 294 | $arr = $co + $arr; // Left-hand overwrites right-hand |
| 336 | 295 | endif; |
| 337 | - | |
| 296 | + | |
| 338 | 297 | if ($this->inImage) : |
| 339 | 298 | $this->image = $arr + $this->image; |
| 340 | - | |
| 299 | + | |
| 341 | 300 | // Close tag |
| 342 | 301 | if ('image'==$tag and 'rss'==$ns) : $this->inImage = false; endif; |
| 343 | 302 | elseif ($this->inTextInput) : |
| 344 | 303 | $this->textinput = $arr + $this->textinput; |
| 345 | - | |
| 304 | + | |
| 346 | 305 | // Close tag |
| 347 | 306 | if ('textinput'==$tag and 'rss'==$ns) : $this->inTextInput = false; endif; |
| 348 | 307 | elseif ($this->is_namespaced($ns)) : |
| 349 | - if ( !isset($ret[$ns])) : $ret[$ns] = array(); endif; | |
| 308 | + if (!isset($ret[$ns])) : $ret[$ns] = array(); endif; | |
| 350 | 309 | $ret[$ns] = $arr + $ret[$ns]; |
| 351 | 310 | else : |
| 352 | 311 | $ret = $arr + $ret; |
| 353 | 312 | endif; |
| 354 | 313 | endforeach; endforeach; |
| 355 | - | |
| 314 | + | |
| 356 | 315 | endforeach; endif; |
| 357 | - | |
| 358 | - return apply_filters('feedwordpress_magpiefromsimplepie_handlechildren', $ret, $data, $path, $method, $this); | |
| 316 | + return $ret; | |
| 359 | 317 | } /* MagpieFromSimplePie::handleChildren() */ |
| 360 | 318 | |
| 361 | 319 | /** |
| 362 | 320 | * MagpieFromSimplePie::get_attrib |
| @@ -394,123 +352,115 @@ | ||
| 394 | 352 | * @uses FeedTime |
| 395 | 353 | * @uses FeedTime::timestamp |
| 396 | 354 | */ |
| 397 | 355 | function normalize () { |
| 398 | - do_action('feedwordpress_magpiefromsimplepie_normalize_pre', $this); | |
| 356 | + // Normalize channel data | |
| 357 | + if ( $this->is_atom() ) : | |
| 358 | + // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!) | |
| 359 | + if ($this->feed_version() < 1.0) : | |
| 360 | + $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle'); | |
| 361 | + $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights'); | |
| 362 | + $this->normalize_element($this->channel, 'modified', $this->channel, 'updated'); | |
| 363 | + else : | |
| 364 | + $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline'); | |
| 365 | + $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright'); | |
| 366 | + $this->normalize_element($this->channel, 'updated', $this->channel, 'modified'); | |
| 367 | + endif; | |
| 368 | + $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person'); | |
| 369 | + $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person'); | |
| 370 | + | |
| 371 | + // Atom elements to RSS elements | |
| 372 | + $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description'); | |
| 373 | + | |
| 374 | + if ( isset($this->channel['logo']) ) : | |
| 375 | + $this->normalize_element($this->channel, 'logo', $this->image, 'url'); | |
| 376 | + $this->normalize_element($this->channel, 'link', $this->image, 'link'); | |
| 377 | + $this->normalize_element($this->channel, 'title', $this->image, 'title'); | |
| 378 | + endif; | |
| 399 | 379 | |
| 400 | - if ( !is_null($this->channel)) : | |
| 401 | - // Normalize channel data | |
| 380 | + elseif ( $this->is_rss() ) : | |
| 381 | + // Normalize image element from where stupid MagpieRSS puts it | |
| 382 | + //$this->normalize_element($this->channel, 'image_title', $this->image, 'title'); | |
| 383 | + //$this->normalize_element($this->channel, 'image_link', $this->image, 'link'); | |
| 384 | + //$this->normalize_element($this->channel, 'image_url', $this->image, 'url'); | |
| 385 | + | |
| 386 | + // ... and, gag, textInput | |
| 387 | + //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title'); | |
| 388 | + //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link'); | |
| 389 | + //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name'); | |
| 390 | + //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description'); | |
| 391 | + | |
| 392 | + // RSS elements to Atom elements | |
| 393 | + $this->normalize_element($this->channel, 'description', $this->channel, 'tagline'); // Atom 0.3 | |
| 394 | + $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle'); // Atom 1.0 (yay wordsmithing!) | |
| 395 | + $this->normalize_element($this->image, 'url', $this->channel, 'logo'); | |
| 396 | + endif; | |
| 397 | + | |
| 398 | + // Now loop through and normalize item data | |
| 399 | + for ( $i = 0; $i < count($this->items); $i++) : | |
| 400 | + $item = $this->items[$i]; | |
| 401 | + | |
| 402 | + // if atom populate rss fields and normalize 0.3 and 1.0 feeds | |
| 402 | 403 | if ( $this->is_atom() ) : |
| 403 | - // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!) | |
| 404 | + // Atom 1.0 elements <=> Atom 0.3 elements | |
| 404 | 405 | if ($this->feed_version() < 1.0) : |
| 405 | - $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle'); | |
| 406 | - $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights'); | |
| 407 | - $this->normalize_element($this->channel, 'modified', $this->channel, 'updated'); | |
| 406 | + $this->normalize_element($item, 'modified', $item, 'updated'); | |
| 407 | + $this->normalize_element($item, 'issued', $item, 'published'); | |
| 408 | 408 | else : |
| 409 | - $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline'); | |
| 410 | - $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright'); | |
| 411 | - $this->normalize_element($this->channel, 'updated', $this->channel, 'modified'); | |
| 409 | + $this->normalize_element($item, 'updated', $item, 'modified'); | |
| 410 | + $this->normalize_element($item, 'published', $item, 'issued'); | |
| 412 | 411 | endif; |
| 413 | - $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person'); | |
| 414 | - $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person'); | |
| 415 | 412 | |
| 413 | + $this->normalize_author_inheritance($item, $this->originals[$i]); | |
| 414 | + | |
| 416 | 415 | // Atom elements to RSS elements |
| 417 | - $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description'); | |
| 416 | + $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person'); | |
| 417 | + $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person'); | |
| 418 | + $this->normalize_element($item, 'summary', $item, 'description'); | |
| 419 | + $this->normalize_element($item, 'atom_content', $item['content'], 'encoded'); | |
| 420 | + $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure'); | |
| 418 | 421 | |
| 419 | - if ( isset($this->channel['logo']) ) : | |
| 420 | - $this->normalize_element($this->channel, 'logo', $this->image, 'url'); | |
| 421 | - $this->normalize_element($this->channel, 'link', $this->image, 'link'); | |
| 422 | - $this->normalize_element($this->channel, 'title', $this->image, 'title'); | |
| 422 | + // Categories | |
| 423 | + if ( isset($item['category#']) ) : // Atom 1.0 categories to dc:subject and RSS 2.0 categories | |
| 424 | + $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); | |
| 425 | + elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories | |
| 426 | + $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); | |
| 423 | 427 | endif; |
| 424 | 428 | |
| 429 | + // Normalized item timestamp | |
| 430 | + $item_date = (isset($item['published']) ) ? $item['published'] : $item['updated']; | |
| 425 | 431 | elseif ( $this->is_rss() ) : |
| 426 | - // Normalize image element from where stupid MagpieRSS puts it | |
| 427 | - //$this->normalize_element($this->channel, 'image_title', $this->image, 'title'); | |
| 428 | - //$this->normalize_element($this->channel, 'image_link', $this->image, 'link'); | |
| 429 | - //$this->normalize_element($this->channel, 'image_url', $this->image, 'url'); | |
| 430 | - | |
| 431 | - // ... and, gag, textInput | |
| 432 | - //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title'); | |
| 433 | - //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link'); | |
| 434 | - //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name'); | |
| 435 | - //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description'); | |
| 436 | - | |
| 437 | 432 | // RSS elements to Atom elements |
| 438 | - $this->normalize_element($this->channel, 'description', $this->channel, 'tagline'); // Atom 0.3 | |
| 439 | - $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle'); // Atom 1.0 (yay wordsmithing!) | |
| 440 | - $this->normalize_element($this->image, 'url', $this->channel, 'logo'); | |
| 433 | + $this->normalize_element($item, 'description', $item, 'summary'); | |
| 434 | + $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure'); | |
| 435 | + | |
| 436 | + // Categories | |
| 437 | + if ( isset($item['category#']) ) : // RSS 2.0 categories to dc:subject and Atom 1.0 categories | |
| 438 | + $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); | |
| 439 | + elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories | |
| 440 | + $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); | |
| 441 | + endif; | |
| 442 | + | |
| 443 | + // Normalized item timestamp | |
| 444 | + if (isset($item['pubdate'])) : | |
| 445 | + $item_date = $item['pubdate']; | |
| 446 | + elseif (isset($item['dc']['date'])) : | |
| 447 | + $item_date = $item['dc']['date']; | |
| 448 | + else : | |
| 449 | + $item_date = null; | |
| 450 | + endif; | |
| 441 | 451 | endif; |
| 442 | - endif; | |
| 443 | 452 | |
| 444 | - if ( !is_null($this->items)) : | |
| 445 | - // Now loop through and normalize item data | |
| 446 | - for ( $i = 0; $i < count($this->items); $i++) : | |
| 447 | - $item = $this->items[$i]; | |
| 448 | - | |
| 449 | - // if atom populate rss fields and normalize 0.3 and 1.0 feeds | |
| 450 | - if ( $this->is_atom() ) : | |
| 451 | - // Atom 1.0 elements <=> Atom 0.3 elements | |
| 452 | - if ($this->feed_version() < 1.0) : | |
| 453 | - $this->normalize_element($item, 'modified', $item, 'updated'); | |
| 454 | - $this->normalize_element($item, 'issued', $item, 'published'); | |
| 455 | - else : | |
| 456 | - $this->normalize_element($item, 'updated', $item, 'modified'); | |
| 457 | - $this->normalize_element($item, 'published', $item, 'issued'); | |
| 458 | - endif; | |
| 459 | - | |
| 460 | - $this->normalize_author_inheritance($item, $this->originals[$i]); | |
| 461 | - | |
| 462 | - // Atom elements to RSS elements | |
| 463 | - $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person'); | |
| 464 | - $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person'); | |
| 465 | - $this->normalize_element($item, 'summary', $item, 'description'); | |
| 466 | - $this->normalize_element($item, 'atom_content', $item['content'], 'encoded'); | |
| 467 | - $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure'); | |
| 468 | - | |
| 469 | - // Categories | |
| 470 | - if ( isset($item['category#']) ) : // Atom 1.0 categories to dc:subject and RSS 2.0 categories | |
| 471 | - $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); | |
| 472 | - elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories | |
| 473 | - $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); | |
| 474 | - endif; | |
| 475 | - | |
| 476 | - // Normalized item timestamp | |
| 477 | - $item_date = (isset($item['published']) ) ? $item['published'] : $item['updated']; | |
| 478 | - elseif ( $this->is_rss() ) : | |
| 479 | - // RSS elements to Atom elements | |
| 480 | - $this->normalize_element($item, 'description', $item, 'summary'); | |
| 481 | - $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure'); | |
| 482 | - | |
| 483 | - // Categories | |
| 484 | - if ( isset($item['category#']) ) : // RSS 2.0 categories to dc:subject and Atom 1.0 categories | |
| 485 | - $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); | |
| 486 | - elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories | |
| 487 | - $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); | |
| 488 | - endif; | |
| 489 | - | |
| 490 | - // Normalized item timestamp | |
| 491 | - if (isset($item['pubdate'])) : | |
| 492 | - $item_date = $item['pubdate']; | |
| 493 | - elseif (isset($item['dc']['date'])) : | |
| 494 | - $item_date = $item['dc']['date']; | |
| 495 | - else : | |
| 496 | - $item_date = null; | |
| 497 | - endif; | |
| 453 | + if ( $item_date ) : | |
| 454 | + $date_timestamp = new FeedTime($item_date); | |
| 455 | + | |
| 456 | + if (!$date_timestamp->failed()) : | |
| 457 | + $item['date_timestamp'] = $date_timestamp->timestamp(); | |
| 498 | 458 | endif; |
| 459 | + endif; | |
| 499 | 460 | |
| 500 | - if ( $item_date ) : | |
| 501 | - $date_timestamp = new FeedTime($item_date); | |
| 502 | - | |
| 503 | - if ( ! $date_timestamp->failed()) : | |
| 504 | - $item['date_timestamp'] = $date_timestamp->timestamp(); | |
| 505 | - endif; | |
| 506 | - endif; | |
| 507 | - | |
| 508 | - $this->items[$i] = $item; | |
| 509 | - endfor; | |
| 510 | - endif; | |
| 511 | - | |
| 512 | - do_action('feedwordpress_magpiefromsimplepie_normalize_post', $this); | |
| 461 | + $this->items[$i] = $item; | |
| 462 | + endfor; | |
| 513 | 463 | } /* MagpieFromSimplePie::normalize() */ |
| 514 | 464 | |
| 515 | 465 | /** |
| 516 | 466 | * MagpieFromSimplePie::normalize_author_inheritance |
| @@ -531,9 +481,9 @@ | ||
| 531 | 481 | // elements of the containing atom:feed element are |
| 532 | 482 | // considered to apply to the entry if there are no |
| 533 | 483 | // atom:author elements in the locations described |
| 534 | 484 | // above." <http://atompub.org/2005/08/17/draft-ietf-atompub-format-11.html#rfc.section.4.2.1> |
| 535 | - if ( !isset($item["author#"])) : | |
| 485 | + if (!isset($item["author#"])) : | |
| 536 | 486 | $authors = $original->get_authors(); |
| 537 | 487 | foreach ($authors as $author) : |
| 538 | 488 | $tag = $this->increment_element($item, 'author', 'atom', array()); |
| 539 | 489 | $item[$tag] = $item["{$tag}_name"] = $author->get_name(); |
| @@ -541,11 +491,11 @@ | ||
| 541 | 491 | if ($author->get_email()) : $item["{$tag}_email"] = $author->get_email(); endif; |
| 542 | 492 | endforeach; |
| 543 | 493 | endif; |
| 544 | 494 | } /* MagpieFromSimplePie::normalize_author_inheritance() */ |
| 545 | - | |
| 495 | + | |
| 546 | 496 | /** |
| 547 | - * MagpieFromSimplePie::normalize_element | |
| 497 | + * MagpieFromSimplePie::normalize_element | |
| 548 | 498 | * Simplify the logic for normalize(). Makes sure that count of elements |
| 549 | 499 | * and each of multiple elements is normalized properly. If you need to |
| 550 | 500 | * mess with things like attributes or change formats or the like, pass |
| 551 | 501 | * it a callback to handle each element. |
| @@ -570,9 +520,9 @@ | ||
| 570 | 520 | $this->{$via}($source, $from, $dest, $to, $i); |
| 571 | 521 | else : // just make it the same |
| 572 | 522 | $from_id = $this->element_id($from, $i); |
| 573 | 523 | $to_id = $this->element_id($to, $i); |
| 574 | - | |
| 524 | + | |
| 575 | 525 | if (isset($source[$from_id])) : // Avoid PHP notice nastygrams |
| 576 | 526 | $dest[$to_id] = $source[$from_id]; |
| 577 | 527 | endif; |
| 578 | 528 | endif; |
| @@ -683,9 +633,9 @@ | ||
| 683 | 633 | |
| 684 | 634 | // Now put the identifier into dc:subject |
| 685 | 635 | $dest[$dc_id] = $source[$cat_id]; |
| 686 | 636 | } /* MagpieFromSimplePie::normalize_category */ |
| 687 | - | |
| 637 | + | |
| 688 | 638 | /** |
| 689 | 639 | * MagpieFromSimplePie::normalize_dc_subject: Normalize Dublin Core |
| 690 | 640 | * "subject" elements to Atom 1.0 and RSS 2.0 categories. |
| 691 | 641 | * |
| @@ -728,18 +678,18 @@ | ||
| 728 | 678 | */ |
| 729 | 679 | function increment_element (&$data, $childTag, $ns, $path) { |
| 730 | 680 | $counterIndex = strtolower(implode('_', array_merge($path, array($childTag.'#')))); |
| 731 | 681 | if ($this->is_namespaced($ns)) : |
| 732 | - if ( !isset($data[$ns])) : $data[$ns] = array(); endif; | |
| 733 | - if ( !isset($data[$ns][$counterIndex])) : $data[$ns][$counterIndex] = 0; endif; | |
| 682 | + if (!isset($data[$ns])) : $data[$ns] = array(); endif; | |
| 683 | + if (!isset($data[$ns][$counterIndex])) : $data[$ns][$counterIndex] = 0; endif; | |
| 734 | 684 | $data[$ns][$counterIndex] += 1; |
| 735 | 685 | $N = $data[$ns][$counterIndex]; |
| 736 | 686 | else : |
| 737 | - if ( !isset($data[$counterIndex])) : $data[$counterIndex] = 0; endif; | |
| 687 | + if (!isset($data[$counterIndex])) : $data[$counterIndex] = 0; endif; | |
| 738 | 688 | $data[$counterIndex] += 1; |
| 739 | 689 | $N = $data[$counterIndex]; |
| 740 | 690 | endif; |
| 741 | - | |
| 691 | + | |
| 742 | 692 | if ($N > 1) : |
| 743 | 693 | $childTag .= '#'.$N; |
| 744 | 694 | endif; |
| 745 | 695 | return $childTag; |
| @@ -758,11 +708,11 @@ | ||
| 758 | 708 | // Atom vs. RSS |
| 759 | 709 | if ($this->is_atom()) : $root = array('', 'atom'); |
| 760 | 710 | else : $root = array('', 'rss'); |
| 761 | 711 | endif; |
| 762 | - | |
| 712 | + | |
| 763 | 713 | // RDF formats; namespaced in attribs but not in elements |
| 764 | - if ( ! $attribute and $this->is_rdf()) : | |
| 714 | + if (!$attribute and $this->is_rdf()) : | |
| 765 | 715 | $root[] = 'rdf'; |
| 766 | 716 | endif; |
| 767 | 717 | |
| 768 | 718 | return !in_array(strtolower($ns), $root); |
| @@ -775,9 +725,9 @@ | ||
| 775 | 725 | */ |
| 776 | 726 | function is_atom () { |
| 777 | 727 | return $this->pie->get_type() & SIMPLEPIE_TYPE_ATOM_ALL; |
| 778 | 728 | } /* MagpieFromSimplePie::increment_element */ |
| 779 | - | |
| 729 | + | |
| 780 | 730 | /** |
| 781 | 731 | * MagpieFromSimplePie::is_rss |
| 782 | 732 | * |
| 783 | 733 | * @return bool |
| @@ -784,9 +734,9 @@ | ||
| 784 | 734 | */ |
| 785 | 735 | function is_rss () { |
| 786 | 736 | return $this->pie->get_type() & SIMPLEPIE_TYPE_RSS_ALL; |
| 787 | 737 | } /* MagpieFromSimplePie::is_rss */ |
| 788 | - | |
| 738 | + | |
| 789 | 739 | /** |
| 790 | 740 | * MagpieFromSimplePie::is_rdf |
| 791 | 741 | * |
| 792 | 742 | * @return bool |