1 <?php 2 3 declare(strict_types=1); 4 /** 5 * SimplePie 6 * 7 * A PHP-Based RSS and Atom Feed Framework. 8 * Takes the hard work out of managing a complete RSS/Atom solution. 9 * 10 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without modification, are 14 * permitted provided that the following conditions are met: 15 * 16 * * Redistributions of source code must retain the above copyright notice, this list of 17 * conditions and the following disclaimer. 18 * 19 * * Redistributions in binary form must reproduce the above copyright notice, this list 20 * of conditions and the following disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * * Neither the name of the SimplePie Team nor the names of its contributors may be used 24 * to endorse or promote products derived from this software without specific prior 25 * written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 28 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 30 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @package SimplePie 38 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue 39 * @author Ryan Parman 40 * @author Sam Sneddon 41 * @author Ryan McCue 42 * @link http://simplepie.org/ SimplePie 43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 44 */ 45 46 namespace SimplePie; 47 48 use SimplePie\XML\Declaration\Parser as DeclarationParser; 49 50 /** 51 * Parses XML into something sane 52 * 53 * 54 * This class can be overloaded with {@see \SimplePie\SimplePie::set_parser_class()} 55 * 56 * @package SimplePie 57 * @subpackage Parsing 58 */ 59 class Parser implements RegistryAware 60 { 61 public $error_code; 62 public $error_string; 63 public $current_line; 64 public $current_column; 65 public $current_byte; 66 public $separator = ' '; 67 public $namespace = ['']; 68 public $element = ['']; 69 public $xml_base = ['']; 70 public $xml_base_explicit = [false]; 71 public $xml_lang = ['']; 72 public $data = []; 73 public $datas = [[]]; 74 public $current_xhtml_construct = -1; 75 public $encoding; 76 protected $registry; 77 78 public function set_registry(\SimplePie\Registry $registry)/* : void */ 79 { 80 $this->registry = $registry; 81 } 82 83 public function parse(&$data, $encoding, $url = '') 84 { 85 if (class_exists('DOMXpath') && function_exists('Mf2\parse')) { 86 $doc = new \DOMDocument(); 87 @$doc->loadHTML($data); 88 $xpath = new \DOMXpath($doc); 89 // Check for both h-feed and h-entry, as both a feed with no entries 90 // and a list of entries without an h-feed wrapper are both valid. 91 $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '. 92 'contains(concat(" ", @class, " "), " h-entry ")]'; 93 $result = $xpath->query($query); 94 if ($result->length !== 0) { 95 return $this->parse_microformats($data, $url); 96 } 97 } 98 99 // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character 100 if (strtoupper($encoding) === 'US-ASCII') { 101 $this->encoding = 'UTF-8'; 102 } else { 103 $this->encoding = $encoding; 104 } 105 106 // Strip BOM: 107 // UTF-32 Big Endian BOM 108 if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") { 109 $data = substr($data, 4); 110 } 111 // UTF-32 Little Endian BOM 112 elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") { 113 $data = substr($data, 4); 114 } 115 // UTF-16 Big Endian BOM 116 elseif (substr($data, 0, 2) === "\xFE\xFF") { 117 $data = substr($data, 2); 118 } 119 // UTF-16 Little Endian BOM 120 elseif (substr($data, 0, 2) === "\xFF\xFE") { 121 $data = substr($data, 2); 122 } 123 // UTF-8 BOM 124 elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") { 125 $data = substr($data, 3); 126 } 127 128 if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false) { 129 $declaration = $this->registry->create(DeclarationParser::class, [substr($data, 5, $pos - 5)]); 130 if ($declaration->parse()) { 131 $data = substr($data, $pos + 2); 132 $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' ."\n". $this->declare_html_entities() . $data; 133 } else { 134 $this->error_string = 'SimplePie bug! Please report this!'; 135 return false; 136 } 137 } 138 139 $return = true; 140 141 static $xml_is_sane = null; 142 if ($xml_is_sane === null) { 143 $parser_check = xml_parser_create(); 144 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values); 145 xml_parser_free($parser_check); 146 $xml_is_sane = isset($values[0]['value']); 147 } 148 149 // Create the parser 150 if ($xml_is_sane) { 151 $xml = xml_parser_create_ns($this->encoding, $this->separator); 152 xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); 153 xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0); 154 xml_set_object($xml, $this); 155 xml_set_character_data_handler($xml, 'cdata'); 156 xml_set_element_handler($xml, 'tag_open', 'tag_close'); 157 158 // Parse! 159 $wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory'; 160 if (($stream = fopen($wrapper, 'r+')) && 161 fwrite($stream, $data) && 162 rewind($stream)) { 163 //Parse by chunks not to use too much memory 164 do { 165 $stream_data = fread($stream, 1048576); 166 if (!xml_parse($xml, $stream_data === false ? '' : $stream_data, feof($stream))) { 167 $this->error_code = xml_get_error_code($xml); 168 $this->error_string = xml_error_string($this->error_code); 169 $return = false; 170 break; 171 } 172 } while (!feof($stream)); 173 fclose($stream); 174 } else { 175 $return = false; 176 } 177 178 $this->current_line = xml_get_current_line_number($xml); 179 $this->current_column = xml_get_current_column_number($xml); 180 $this->current_byte = xml_get_current_byte_index($xml); 181 xml_parser_free($xml); 182 return $return; 183 } 184 185 libxml_clear_errors(); 186 $xml = new \XMLReader(); 187 $xml->xml($data); 188 while (@$xml->read()) { 189 switch ($xml->nodeType) { 190 case constant('XMLReader::END_ELEMENT'): 191 if ($xml->namespaceURI !== '') { 192 $tagName = $xml->namespaceURI . $this->separator . $xml->localName; 193 } else { 194 $tagName = $xml->localName; 195 } 196 $this->tag_close(null, $tagName); 197 break; 198 case constant('XMLReader::ELEMENT'): 199 $empty = $xml->isEmptyElement; 200 if ($xml->namespaceURI !== '') { 201 $tagName = $xml->namespaceURI . $this->separator . $xml->localName; 202 } else { 203 $tagName = $xml->localName; 204 } 205 $attributes = []; 206 while ($xml->moveToNextAttribute()) { 207 if ($xml->namespaceURI !== '') { 208 $attrName = $xml->namespaceURI . $this->separator . $xml->localName; 209 } else { 210 $attrName = $xml->localName; 211 } 212 $attributes[$attrName] = $xml->value; 213 } 214 $this->tag_open(null, $tagName, $attributes); 215 if ($empty) { 216 $this->tag_close(null, $tagName); 217 } 218 break; 219 case constant('XMLReader::TEXT'): 220 221 case constant('XMLReader::CDATA'): 222 $this->cdata(null, $xml->value); 223 break; 224 } 225 } 226 if ($error = libxml_get_last_error()) { 227 $this->error_code = $error->code; 228 $this->error_string = $error->message; 229 $this->current_line = $error->line; 230 $this->current_column = $error->column; 231 return false; 232 } 233 234 return true; 235 } 236 237 public function get_error_code() 238 { 239 return $this->error_code; 240 } 241 242 public function get_error_string() 243 { 244 return $this->error_string; 245 } 246 247 public function get_current_line() 248 { 249 return $this->current_line; 250 } 251 252 public function get_current_column() 253 { 254 return $this->current_column; 255 } 256 257 public function get_current_byte() 258 { 259 return $this->current_byte; 260 } 261 262 public function get_data() 263 { 264 return $this->data; 265 } 266 267 public function tag_open($parser, $tag, $attributes) 268 { 269 [$this->namespace[], $this->element[]] = $this->split_ns($tag); 270 271 $attribs = []; 272 foreach ($attributes as $name => $value) { 273 [$attrib_namespace, $attribute] = $this->split_ns($name); 274 $attribs[$attrib_namespace][$attribute] = $value; 275 } 276 277 if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'])) { 278 $base = $this->registry->call(Misc::class, 'absolutize_url', [$attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'], end($this->xml_base)]); 279 if ($base !== false) { 280 $this->xml_base[] = $base; 281 $this->xml_base_explicit[] = true; 282 } 283 } else { 284 $this->xml_base[] = end($this->xml_base); 285 $this->xml_base_explicit[] = end($this->xml_base_explicit); 286 } 287 288 if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang'])) { 289 $this->xml_lang[] = $attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang']; 290 } else { 291 $this->xml_lang[] = end($this->xml_lang); 292 } 293 294 if ($this->current_xhtml_construct >= 0) { 295 $this->current_xhtml_construct++; 296 if (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_XHTML) { 297 $this->data['data'] .= '<' . end($this->element); 298 if (isset($attribs[''])) { 299 foreach ($attribs[''] as $name => $value) { 300 $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"'; 301 } 302 } 303 $this->data['data'] .= '>'; 304 } 305 } else { 306 $this->datas[] =& $this->data; 307 $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][]; 308 $this->data = ['data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang)]; 309 if ((end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_03 && in_array(end($this->element), ['title', 'tagline', 'copyright', 'info', 'summary', 'content']) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml') 310 || (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_10 && in_array(end($this->element), ['rights', 'subtitle', 'summary', 'info', 'title', 'content']) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml') 311 || (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_20 && in_array(end($this->element), ['title'])) 312 || (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_090 && in_array(end($this->element), ['title'])) 313 || (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_10 && in_array(end($this->element), ['title']))) { 314 $this->current_xhtml_construct = 0; 315 } 316 } 317 } 318 319 public function cdata($parser, $cdata) 320 { 321 if ($this->current_xhtml_construct >= 0) { 322 $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding); 323 } else { 324 $this->data['data'] .= $cdata; 325 } 326 } 327 328 public function tag_close($parser, $tag) 329 { 330 if ($this->current_xhtml_construct >= 0) { 331 $this->current_xhtml_construct--; 332 if (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_XHTML && !in_array(end($this->element), ['area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param'])) { 333 $this->data['data'] .= '</' . end($this->element) . '>'; 334 } 335 } 336 if ($this->current_xhtml_construct === -1) { 337 $this->data =& $this->datas[count($this->datas) - 1]; 338 array_pop($this->datas); 339 } 340 341 array_pop($this->element); 342 array_pop($this->namespace); 343 array_pop($this->xml_base); 344 array_pop($this->xml_base_explicit); 345 array_pop($this->xml_lang); 346 } 347 348 public function split_ns($string) 349 { 350 static $cache = []; 351 if (!isset($cache[$string])) { 352 if ($pos = strpos($string, $this->separator)) { 353 static $separator_length; 354 if (!$separator_length) { 355 $separator_length = strlen($this->separator); 356 } 357 $namespace = substr($string, 0, $pos); 358 $local_name = substr($string, $pos + $separator_length); 359 if (strtolower($namespace) === \SimplePie\SimplePie::NAMESPACE_ITUNES) { 360 $namespace = \SimplePie\SimplePie::NAMESPACE_ITUNES; 361 } 362 363 // Normalize the Media RSS namespaces 364 if ($namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG || 365 $namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG2 || 366 $namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG3 || 367 $namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG4 || 368 $namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG5) { 369 $namespace = \SimplePie\SimplePie::NAMESPACE_MEDIARSS; 370 } 371 $cache[$string] = [$namespace, $local_name]; 372 } else { 373 $cache[$string] = ['', $string]; 374 } 375 } 376 return $cache[$string]; 377 } 378 379 private function parse_hcard($data, $category = false) 380 { 381 $name = ''; 382 $link = ''; 383 // Check if h-card is set and pass that information on in the link. 384 if (isset($data['type']) && in_array('h-card', $data['type'])) { 385 if (isset($data['properties']['name'][0])) { 386 $name = $data['properties']['name'][0]; 387 } 388 if (isset($data['properties']['url'][0])) { 389 $link = $data['properties']['url'][0]; 390 if ($name === '') { 391 $name = $link; 392 } else { 393 // can't have commas in categories. 394 $name = str_replace(',', '', $name); 395 } 396 $person_tag = $category ? '<span class="person-tag"></span>' : ''; 397 return '<a class="h-card" href="'.$link.'">'.$person_tag.$name.'</a>'; 398 } 399 } 400 return $data['value'] ?? ''; 401 } 402 403 private function parse_microformats(&$data, $url) 404 { 405 $feed_title = ''; 406 $feed_author = null; 407 $author_cache = []; 408 $items = []; 409 $entries = []; 410 $mf = \Mf2\parse($data, $url); 411 // First look for an h-feed. 412 $h_feed = []; 413 foreach ($mf['items'] as $mf_item) { 414 if (in_array('h-feed', $mf_item['type'])) { 415 $h_feed = $mf_item; 416 break; 417 } 418 // Also look for h-feed or h-entry in the children of each top level item. 419 if (!isset($mf_item['children'][0]['type'])) { 420 continue; 421 } 422 if (in_array('h-feed', $mf_item['children'][0]['type'])) { 423 $h_feed = $mf_item['children'][0]; 424 // In this case the parent of the h-feed may be an h-card, so use it as 425 // the feed_author. 426 if (in_array('h-card', $mf_item['type'])) { 427 $feed_author = $mf_item; 428 } 429 break; 430 } elseif (in_array('h-entry', $mf_item['children'][0]['type'])) { 431 $entries = $mf_item['children']; 432 // In this case the parent of the h-entry list may be an h-card, so use 433 // it as the feed_author. 434 if (in_array('h-card', $mf_item['type'])) { 435 $feed_author = $mf_item; 436 } 437 break; 438 } 439 } 440 if (isset($h_feed['children'])) { 441 $entries = $h_feed['children']; 442 // Also set the feed title and store author from the h-feed if available. 443 if (isset($mf['items'][0]['properties']['name'][0])) { 444 $feed_title = $mf['items'][0]['properties']['name'][0]; 445 } 446 if (isset($mf['items'][0]['properties']['author'][0])) { 447 $feed_author = $mf['items'][0]['properties']['author'][0]; 448 } 449 } elseif (count($entries) === 0) { 450 $entries = $mf['items']; 451 } 452 for ($i = 0; $i < count($entries); $i++) { 453 $entry = $entries[$i]; 454 if (in_array('h-entry', $entry['type'])) { 455 $item = []; 456 $title = ''; 457 $description = ''; 458 if (isset($entry['properties']['url'][0])) { 459 $link = $entry['properties']['url'][0]; 460 if (isset($link['value'])) { 461 $link = $link['value']; 462 } 463 $item['link'] = [['data' => $link]]; 464 } 465 if (isset($entry['properties']['uid'][0])) { 466 $guid = $entry['properties']['uid'][0]; 467 if (isset($guid['value'])) { 468 $guid = $guid['value']; 469 } 470 $item['guid'] = [['data' => $guid]]; 471 } 472 if (isset($entry['properties']['name'][0])) { 473 $title = $entry['properties']['name'][0]; 474 if (isset($title['value'])) { 475 $title = $title['value']; 476 } 477 $item['title'] = [['data' => $title]]; 478 } 479 if (isset($entry['properties']['author'][0]) || isset($feed_author)) { 480 // author is a special case, it can be plain text or an h-card array. 481 // If it's plain text it can also be a url that should be followed to 482 // get the actual h-card. 483 $author = $entry['properties']['author'][0] ?? $feed_author; 484 if (!is_string($author)) { 485 $author = $this->parse_hcard($author); 486 } elseif (strpos($author, 'http') === 0) { 487 if (isset($author_cache[$author])) { 488 $author = $author_cache[$author]; 489 } else { 490 $mf = \Mf2\fetch($author); 491 foreach ($mf['items'] as $hcard) { 492 // Only interested in an h-card by itself in this case. 493 if (!in_array('h-card', $hcard['type'])) { 494 continue; 495 } 496 // It must have a url property matching what we fetched. 497 if (!isset($hcard['properties']['url']) || 498 !(in_array($author, $hcard['properties']['url']))) { 499 continue; 500 } 501 // Save parse_hcard the trouble of finding the correct url. 502 $hcard['properties']['url'][0] = $author; 503 // Cache this h-card for the next h-entry to check. 504 $author_cache[$author] = $this->parse_hcard($hcard); 505 $author = $author_cache[$author]; 506 break; 507 } 508 } 509 } 510 $item['author'] = [['data' => $author]]; 511 } 512 if (isset($entry['properties']['photo'][0])) { 513 // If a photo is also in content, don't need to add it again here. 514 $content = ''; 515 if (isset($entry['properties']['content'][0]['html'])) { 516 $content = $entry['properties']['content'][0]['html']; 517 } 518 $photo_list = []; 519 for ($j = 0; $j < count($entry['properties']['photo']); $j++) { 520 $photo = $entry['properties']['photo'][$j]; 521 if (!empty($photo) && strpos($content, $photo) === false) { 522 $photo_list[] = $photo; 523 } 524 } 525 // When there's more than one photo show the first and use a lightbox. 526 // Need a permanent, unique name for the image set, but don't have 527 // anything unique except for the content itself, so use that. 528 $count = count($photo_list); 529 if ($count > 1) { 530 $image_set_id = preg_replace('/[[:^alnum:]]/', '', $photo_list[0]); 531 $description = '<p>'; 532 for ($j = 0; $j < $count; $j++) { 533 $hidden = $j === 0 ? '' : 'class="hidden" '; 534 $description .= '<a href="'.$photo_list[$j].'" '.$hidden. 535 'data-lightbox="image-set-'.$image_set_id.'">'. 536 '<img src="'.$photo_list[$j].'"></a>'; 537 } 538 $description .= '<br><b>'.$count.' photos</b></p>'; 539 } elseif ($count == 1) { 540 $description = '<p><img src="'.$photo_list[0].'"></p>'; 541 } 542 } 543 if (isset($entry['properties']['content'][0]['html'])) { 544 // e-content['value'] is the same as p-name when they are on the same 545 // element. Use this to replace title with a strip_tags version so 546 // that alt text from images is not included in the title. 547 if ($entry['properties']['content'][0]['value'] === $title) { 548 $title = strip_tags($entry['properties']['content'][0]['html']); 549 $item['title'] = [['data' => $title]]; 550 } 551 $description .= $entry['properties']['content'][0]['html']; 552 if (isset($entry['properties']['in-reply-to'][0])) { 553 $in_reply_to = ''; 554 if (is_string($entry['properties']['in-reply-to'][0])) { 555 $in_reply_to = $entry['properties']['in-reply-to'][0]; 556 } elseif (isset($entry['properties']['in-reply-to'][0]['value'])) { 557 $in_reply_to = $entry['properties']['in-reply-to'][0]['value']; 558 } 559 if ($in_reply_to !== '') { 560 $description .= '<p><span class="in-reply-to"></span> '. 561 '<a href="'.$in_reply_to.'">'.$in_reply_to.'</a><p>'; 562 } 563 } 564 $item['description'] = [['data' => $description]]; 565 } 566 if (isset($entry['properties']['category'])) { 567 $category_csv = ''; 568 // Categories can also contain h-cards. 569 foreach ($entry['properties']['category'] as $category) { 570 if ($category_csv !== '') { 571 $category_csv .= ', '; 572 } 573 if (is_string($category)) { 574 // Can't have commas in categories. 575 $category_csv .= str_replace(',', '', $category); 576 } else { 577 $category_csv .= $this->parse_hcard($category, true); 578 } 579 } 580 $item['category'] = [['data' => $category_csv]]; 581 } 582 if (isset($entry['properties']['published'][0])) { 583 $timestamp = strtotime($entry['properties']['published'][0]); 584 $pub_date = date('F j Y g:ia', $timestamp).' GMT'; 585 $item['pubDate'] = [['data' => $pub_date]]; 586 } 587 // The title and description are set to the empty string to represent 588 // a deleted item (which also makes it an invalid rss item). 589 if (isset($entry['properties']['deleted'][0])) { 590 $item['title'] = [['data' => '']]; 591 $item['description'] = [['data' => '']]; 592 } 593 $items[] = ['child' => ['' => $item]]; 594 } 595 } 596 // Mimic RSS data format when storing microformats. 597 $link = [['data' => $url]]; 598 $image = ''; 599 if (!is_string($feed_author) && 600 isset($feed_author['properties']['photo'][0])) { 601 $image = [['child' => ['' => ['url' => 602 [['data' => $feed_author['properties']['photo'][0]]]]]]]; 603 } 604 // Use the name given for the h-feed, or get the title from the html. 605 if ($feed_title !== '') { 606 $feed_title = [['data' => htmlspecialchars($feed_title)]]; 607 } elseif ($position = strpos($data, '<title>')) { 608 $start = $position < 200 ? 0 : $position - 200; 609 $check = substr($data, $start, 400); 610 $matches = []; 611 if (preg_match('/<title>(.+)<\/title>/', $check, $matches)) { 612 $feed_title = [['data' => htmlspecialchars($matches[1])]]; 613 } 614 } 615 $channel = ['channel' => [['child' => ['' => 616 ['link' => $link, 'image' => $image, 'title' => $feed_title, 617 'item' => $items]]]]]; 618 $rss = [['attribs' => ['' => ['version' => '2.0']], 619 'child' => ['' => $channel]]]; 620 $this->data = ['child' => ['' => ['rss' => $rss]]]; 621 return true; 622 } 623 624 private function declare_html_entities() 625 { 626 // This is required because the RSS specification says that entity-encoded 627 // html is allowed, but the xml specification says they must be declared. 628 return '<!DOCTYPE html [ <!ENTITY nbsp " "> <!ENTITY iexcl "¡"> <!ENTITY cent "¢"> <!ENTITY pound "£"> <!ENTITY curren "¤"> <!ENTITY yen "¥"> <!ENTITY brvbar "¦"> <!ENTITY sect "§"> <!ENTITY uml "¨"> <!ENTITY copy "©"> <!ENTITY ordf "ª"> <!ENTITY laquo "«"> <!ENTITY not "¬"> <!ENTITY shy "­"> <!ENTITY reg "®"> <!ENTITY macr "¯"> <!ENTITY deg "°"> <!ENTITY plusmn "±"> <!ENTITY sup2 "²"> <!ENTITY sup3 "³"> <!ENTITY acute "´"> <!ENTITY micro "µ"> <!ENTITY para "¶"> <!ENTITY middot "·"> <!ENTITY cedil "¸"> <!ENTITY sup1 "¹"> <!ENTITY ordm "º"> <!ENTITY raquo "»"> <!ENTITY frac14 "¼"> <!ENTITY frac12 "½"> <!ENTITY frac34 "¾"> <!ENTITY iquest "¿"> <!ENTITY Agrave "À"> <!ENTITY Aacute "Á"> <!ENTITY Acirc "Â"> <!ENTITY Atilde "Ã"> <!ENTITY Auml "Ä"> <!ENTITY Aring "Å"> <!ENTITY AElig "Æ"> <!ENTITY Ccedil "Ç"> <!ENTITY Egrave "È"> <!ENTITY Eacute "É"> <!ENTITY Ecirc "Ê"> <!ENTITY Euml "Ë"> <!ENTITY Igrave "Ì"> <!ENTITY Iacute "Í"> <!ENTITY Icirc "Î"> <!ENTITY Iuml "Ï"> <!ENTITY ETH "Ð"> <!ENTITY Ntilde "Ñ"> <!ENTITY Ograve "Ò"> <!ENTITY Oacute "Ó"> <!ENTITY Ocirc "Ô"> <!ENTITY Otilde "Õ"> <!ENTITY Ouml "Ö"> <!ENTITY times "×"> <!ENTITY Oslash "Ø"> <!ENTITY Ugrave "Ù"> <!ENTITY Uacute "Ú"> <!ENTITY Ucirc "Û"> <!ENTITY Uuml "Ü"> <!ENTITY Yacute "Ý"> <!ENTITY THORN "Þ"> <!ENTITY szlig "ß"> <!ENTITY agrave "à"> <!ENTITY aacute "á"> <!ENTITY acirc "â"> <!ENTITY atilde "ã"> <!ENTITY auml "ä"> <!ENTITY aring "å"> <!ENTITY aelig "æ"> <!ENTITY ccedil "ç"> <!ENTITY egrave "è"> <!ENTITY eacute "é"> <!ENTITY ecirc "ê"> <!ENTITY euml "ë"> <!ENTITY igrave "ì"> <!ENTITY iacute "í"> <!ENTITY icirc "î"> <!ENTITY iuml "ï"> <!ENTITY eth "ð"> <!ENTITY ntilde "ñ"> <!ENTITY ograve "ò"> <!ENTITY oacute "ó"> <!ENTITY ocirc "ô"> <!ENTITY otilde "õ"> <!ENTITY ouml "ö"> <!ENTITY divide "÷"> <!ENTITY oslash "ø"> <!ENTITY ugrave "ù"> <!ENTITY uacute "ú"> <!ENTITY ucirc "û"> <!ENTITY uuml "ü"> <!ENTITY yacute "ý"> <!ENTITY thorn "þ"> <!ENTITY yuml "ÿ"> <!ENTITY OElig "Œ"> <!ENTITY oelig "œ"> <!ENTITY Scaron "Š"> <!ENTITY scaron "š"> <!ENTITY Yuml "Ÿ"> <!ENTITY fnof "ƒ"> <!ENTITY circ "ˆ"> <!ENTITY tilde "˜"> <!ENTITY Alpha "Α"> <!ENTITY Beta "Β"> <!ENTITY Gamma "Γ"> <!ENTITY Epsilon "Ε"> <!ENTITY Zeta "Ζ"> <!ENTITY Eta "Η"> <!ENTITY Theta "Θ"> <!ENTITY Iota "Ι"> <!ENTITY Kappa "Κ"> <!ENTITY Lambda "Λ"> <!ENTITY Mu "Μ"> <!ENTITY Nu "Ν"> <!ENTITY Xi "Ξ"> <!ENTITY Omicron "Ο"> <!ENTITY Pi "Π"> <!ENTITY Rho "Ρ"> <!ENTITY Sigma "Σ"> <!ENTITY Tau "Τ"> <!ENTITY Upsilon "Υ"> <!ENTITY Phi "Φ"> <!ENTITY Chi "Χ"> <!ENTITY Psi "Ψ"> <!ENTITY Omega "Ω"> <!ENTITY alpha "α"> <!ENTITY beta "β"> <!ENTITY gamma "γ"> <!ENTITY delta "δ"> <!ENTITY epsilon "ε"> <!ENTITY zeta "ζ"> <!ENTITY eta "η"> <!ENTITY theta "θ"> <!ENTITY iota "ι"> <!ENTITY kappa "κ"> <!ENTITY lambda "λ"> <!ENTITY mu "μ"> <!ENTITY nu "ν"> <!ENTITY xi "ξ"> <!ENTITY omicron "ο"> <!ENTITY pi "π"> <!ENTITY rho "ρ"> <!ENTITY sigmaf "ς"> <!ENTITY sigma "σ"> <!ENTITY tau "τ"> <!ENTITY upsilon "υ"> <!ENTITY phi "φ"> <!ENTITY chi "χ"> <!ENTITY psi "ψ"> <!ENTITY omega "ω"> <!ENTITY thetasym "ϑ"> <!ENTITY upsih "ϒ"> <!ENTITY piv "ϖ"> <!ENTITY ensp " "> <!ENTITY emsp " "> <!ENTITY thinsp " "> <!ENTITY zwnj "‌"> <!ENTITY zwj "‍"> <!ENTITY lrm "‎"> <!ENTITY rlm "‏"> <!ENTITY ndash "–"> <!ENTITY mdash "—"> <!ENTITY lsquo "‘"> <!ENTITY rsquo "’"> <!ENTITY sbquo "‚"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY bdquo "„"> <!ENTITY dagger "†"> <!ENTITY Dagger "‡"> <!ENTITY bull "•"> <!ENTITY hellip "…"> <!ENTITY permil "‰"> <!ENTITY prime "′"> <!ENTITY Prime "″"> <!ENTITY lsaquo "‹"> <!ENTITY rsaquo "›"> <!ENTITY oline "‾"> <!ENTITY frasl "⁄"> <!ENTITY euro "€"> <!ENTITY image "ℑ"> <!ENTITY weierp "℘"> <!ENTITY real "ℜ"> <!ENTITY trade "™"> <!ENTITY alefsym "ℵ"> <!ENTITY larr "←"> <!ENTITY uarr "↑"> <!ENTITY rarr "→"> <!ENTITY darr "↓"> <!ENTITY harr "↔"> <!ENTITY crarr "↵"> <!ENTITY lArr "⇐"> <!ENTITY uArr "⇑"> <!ENTITY rArr "⇒"> <!ENTITY dArr "⇓"> <!ENTITY hArr "⇔"> <!ENTITY forall "∀"> <!ENTITY part "∂"> <!ENTITY exist "∃"> <!ENTITY empty "∅"> <!ENTITY nabla "∇"> <!ENTITY isin "∈"> <!ENTITY notin "∉"> <!ENTITY ni "∋"> <!ENTITY prod "∏"> <!ENTITY sum "∑"> <!ENTITY minus "−"> <!ENTITY lowast "∗"> <!ENTITY radic "√"> <!ENTITY prop "∝"> <!ENTITY infin "∞"> <!ENTITY ang "∠"> <!ENTITY and "∧"> <!ENTITY or "∨"> <!ENTITY cap "∩"> <!ENTITY cup "∪"> <!ENTITY int "∫"> <!ENTITY there4 "∴"> <!ENTITY sim "∼"> <!ENTITY cong "≅"> <!ENTITY asymp "≈"> <!ENTITY ne "≠"> <!ENTITY equiv "≡"> <!ENTITY le "≤"> <!ENTITY ge "≥"> <!ENTITY sub "⊂"> <!ENTITY sup "⊃"> <!ENTITY nsub "⊄"> <!ENTITY sube "⊆"> <!ENTITY supe "⊇"> <!ENTITY oplus "⊕"> <!ENTITY otimes "⊗"> <!ENTITY perp "⊥"> <!ENTITY sdot "⋅"> <!ENTITY lceil "⌈"> <!ENTITY rceil "⌉"> <!ENTITY lfloor "⌊"> <!ENTITY rfloor "⌋"> <!ENTITY lang "〈"> <!ENTITY rang "〉"> <!ENTITY loz "◊"> <!ENTITY spades "♠"> <!ENTITY clubs "♣"> <!ENTITY hearts "♥"> <!ENTITY diams "♦"> ]>'; 629 } 630 } 631 632 class_alias('SimplePie\Parser', 'SimplePie_Parser');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body