Edit File by line
/home/zeestwma/ajeebong.../wp-inclu.../SimplePi.../src
File: Parser.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* SimplePie
[3] Fix | Delete
*
[4] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[5] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[6] Fix | Delete
*
[7] Fix | Delete
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[8] Fix | Delete
* All rights reserved.
[9] Fix | Delete
*
[10] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[11] Fix | Delete
* permitted provided that the following conditions are met:
[12] Fix | Delete
*
[13] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[14] Fix | Delete
* conditions and the following disclaimer.
[15] Fix | Delete
*
[16] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[17] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[18] Fix | Delete
* provided with the distribution.
[19] Fix | Delete
*
[20] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[21] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[22] Fix | Delete
* written permission.
[23] Fix | Delete
*
[24] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[25] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[26] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[27] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[28] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[29] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[30] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[31] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[32] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[33] Fix | Delete
*
[34] Fix | Delete
* @package SimplePie
[35] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[36] Fix | Delete
* @author Ryan Parman
[37] Fix | Delete
* @author Sam Sneddon
[38] Fix | Delete
* @author Ryan McCue
[39] Fix | Delete
* @link http://simplepie.org/ SimplePie
[40] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[41] Fix | Delete
*/
[42] Fix | Delete
[43] Fix | Delete
namespace SimplePie;
[44] Fix | Delete
[45] Fix | Delete
use SimplePie\XML\Declaration\Parser as DeclarationParser;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Parses XML into something sane
[49] Fix | Delete
*
[50] Fix | Delete
*
[51] Fix | Delete
* This class can be overloaded with {@see \SimplePie\SimplePie::set_parser_class()}
[52] Fix | Delete
*
[53] Fix | Delete
* @package SimplePie
[54] Fix | Delete
* @subpackage Parsing
[55] Fix | Delete
*/
[56] Fix | Delete
class Parser implements RegistryAware
[57] Fix | Delete
{
[58] Fix | Delete
public $error_code;
[59] Fix | Delete
public $error_string;
[60] Fix | Delete
public $current_line;
[61] Fix | Delete
public $current_column;
[62] Fix | Delete
public $current_byte;
[63] Fix | Delete
public $separator = ' ';
[64] Fix | Delete
public $namespace = [''];
[65] Fix | Delete
public $element = [''];
[66] Fix | Delete
public $xml_base = [''];
[67] Fix | Delete
public $xml_base_explicit = [false];
[68] Fix | Delete
public $xml_lang = [''];
[69] Fix | Delete
public $data = [];
[70] Fix | Delete
public $datas = [[]];
[71] Fix | Delete
public $current_xhtml_construct = -1;
[72] Fix | Delete
public $encoding;
[73] Fix | Delete
protected $registry;
[74] Fix | Delete
[75] Fix | Delete
public function set_registry(\SimplePie\Registry $registry)/* : void */
[76] Fix | Delete
{
[77] Fix | Delete
$this->registry = $registry;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
public function parse(&$data, $encoding, $url = '')
[81] Fix | Delete
{
[82] Fix | Delete
if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
[83] Fix | Delete
$doc = new \DOMDocument();
[84] Fix | Delete
@$doc->loadHTML($data);
[85] Fix | Delete
$xpath = new \DOMXpath($doc);
[86] Fix | Delete
// Check for both h-feed and h-entry, as both a feed with no entries
[87] Fix | Delete
// and a list of entries without an h-feed wrapper are both valid.
[88] Fix | Delete
$query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
[89] Fix | Delete
'contains(concat(" ", @class, " "), " h-entry ")]';
[90] Fix | Delete
$result = $xpath->query($query);
[91] Fix | Delete
if ($result->length !== 0) {
[92] Fix | Delete
return $this->parse_microformats($data, $url);
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
// Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
[97] Fix | Delete
if (strtoupper($encoding) === 'US-ASCII') {
[98] Fix | Delete
$this->encoding = 'UTF-8';
[99] Fix | Delete
} else {
[100] Fix | Delete
$this->encoding = $encoding;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
// Strip BOM:
[104] Fix | Delete
// UTF-32 Big Endian BOM
[105] Fix | Delete
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
[106] Fix | Delete
$data = substr($data, 4);
[107] Fix | Delete
}
[108] Fix | Delete
// UTF-32 Little Endian BOM
[109] Fix | Delete
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
[110] Fix | Delete
$data = substr($data, 4);
[111] Fix | Delete
}
[112] Fix | Delete
// UTF-16 Big Endian BOM
[113] Fix | Delete
elseif (substr($data, 0, 2) === "\xFE\xFF") {
[114] Fix | Delete
$data = substr($data, 2);
[115] Fix | Delete
}
[116] Fix | Delete
// UTF-16 Little Endian BOM
[117] Fix | Delete
elseif (substr($data, 0, 2) === "\xFF\xFE") {
[118] Fix | Delete
$data = substr($data, 2);
[119] Fix | Delete
}
[120] Fix | Delete
// UTF-8 BOM
[121] Fix | Delete
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
[122] Fix | Delete
$data = substr($data, 3);
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false) {
[126] Fix | Delete
$declaration = $this->registry->create(DeclarationParser::class, [substr($data, 5, $pos - 5)]);
[127] Fix | Delete
if ($declaration->parse()) {
[128] Fix | Delete
$data = substr($data, $pos + 2);
[129] Fix | Delete
$data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' ."\n". $this->declare_html_entities() . $data;
[130] Fix | Delete
} else {
[131] Fix | Delete
$this->error_string = 'SimplePie bug! Please report this!';
[132] Fix | Delete
return false;
[133] Fix | Delete
}
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$return = true;
[137] Fix | Delete
[138] Fix | Delete
static $xml_is_sane = null;
[139] Fix | Delete
if ($xml_is_sane === null) {
[140] Fix | Delete
$parser_check = xml_parser_create();
[141] Fix | Delete
xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
[142] Fix | Delete
xml_parser_free($parser_check);
[143] Fix | Delete
$xml_is_sane = isset($values[0]['value']);
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// Create the parser
[147] Fix | Delete
if ($xml_is_sane) {
[148] Fix | Delete
$xml = xml_parser_create_ns($this->encoding, $this->separator);
[149] Fix | Delete
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
[150] Fix | Delete
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
[151] Fix | Delete
xml_set_character_data_handler($xml, [$this, 'cdata']);
[152] Fix | Delete
xml_set_element_handler($xml, [$this, 'tag_open'], [$this, 'tag_close']);
[153] Fix | Delete
[154] Fix | Delete
// Parse!
[155] Fix | Delete
$wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory';
[156] Fix | Delete
if (($stream = fopen($wrapper, 'r+')) &&
[157] Fix | Delete
fwrite($stream, $data) &&
[158] Fix | Delete
rewind($stream)) {
[159] Fix | Delete
//Parse by chunks not to use too much memory
[160] Fix | Delete
do {
[161] Fix | Delete
$stream_data = fread($stream, 1048576);
[162] Fix | Delete
if (!xml_parse($xml, $stream_data === false ? '' : $stream_data, feof($stream))) {
[163] Fix | Delete
$this->error_code = xml_get_error_code($xml);
[164] Fix | Delete
$this->error_string = xml_error_string($this->error_code);
[165] Fix | Delete
$return = false;
[166] Fix | Delete
break;
[167] Fix | Delete
}
[168] Fix | Delete
} while (!feof($stream));
[169] Fix | Delete
fclose($stream);
[170] Fix | Delete
} else {
[171] Fix | Delete
$return = false;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$this->current_line = xml_get_current_line_number($xml);
[175] Fix | Delete
$this->current_column = xml_get_current_column_number($xml);
[176] Fix | Delete
$this->current_byte = xml_get_current_byte_index($xml);
[177] Fix | Delete
xml_parser_free($xml);
[178] Fix | Delete
return $return;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
libxml_clear_errors();
[182] Fix | Delete
$xml = new \XMLReader();
[183] Fix | Delete
$xml->xml($data);
[184] Fix | Delete
while (@$xml->read()) {
[185] Fix | Delete
switch ($xml->nodeType) {
[186] Fix | Delete
case constant('XMLReader::END_ELEMENT'):
[187] Fix | Delete
if ($xml->namespaceURI !== '') {
[188] Fix | Delete
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
[189] Fix | Delete
} else {
[190] Fix | Delete
$tagName = $xml->localName;
[191] Fix | Delete
}
[192] Fix | Delete
$this->tag_close(null, $tagName);
[193] Fix | Delete
break;
[194] Fix | Delete
case constant('XMLReader::ELEMENT'):
[195] Fix | Delete
$empty = $xml->isEmptyElement;
[196] Fix | Delete
if ($xml->namespaceURI !== '') {
[197] Fix | Delete
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
[198] Fix | Delete
} else {
[199] Fix | Delete
$tagName = $xml->localName;
[200] Fix | Delete
}
[201] Fix | Delete
$attributes = [];
[202] Fix | Delete
while ($xml->moveToNextAttribute()) {
[203] Fix | Delete
if ($xml->namespaceURI !== '') {
[204] Fix | Delete
$attrName = $xml->namespaceURI . $this->separator . $xml->localName;
[205] Fix | Delete
} else {
[206] Fix | Delete
$attrName = $xml->localName;
[207] Fix | Delete
}
[208] Fix | Delete
$attributes[$attrName] = $xml->value;
[209] Fix | Delete
}
[210] Fix | Delete
$this->tag_open(null, $tagName, $attributes);
[211] Fix | Delete
if ($empty) {
[212] Fix | Delete
$this->tag_close(null, $tagName);
[213] Fix | Delete
}
[214] Fix | Delete
break;
[215] Fix | Delete
case constant('XMLReader::TEXT'):
[216] Fix | Delete
[217] Fix | Delete
case constant('XMLReader::CDATA'):
[218] Fix | Delete
$this->cdata(null, $xml->value);
[219] Fix | Delete
break;
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
if ($error = libxml_get_last_error()) {
[223] Fix | Delete
$this->error_code = $error->code;
[224] Fix | Delete
$this->error_string = $error->message;
[225] Fix | Delete
$this->current_line = $error->line;
[226] Fix | Delete
$this->current_column = $error->column;
[227] Fix | Delete
return false;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
return true;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
public function get_error_code()
[234] Fix | Delete
{
[235] Fix | Delete
return $this->error_code;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
public function get_error_string()
[239] Fix | Delete
{
[240] Fix | Delete
return $this->error_string;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
public function get_current_line()
[244] Fix | Delete
{
[245] Fix | Delete
return $this->current_line;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
public function get_current_column()
[249] Fix | Delete
{
[250] Fix | Delete
return $this->current_column;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
public function get_current_byte()
[254] Fix | Delete
{
[255] Fix | Delete
return $this->current_byte;
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
public function get_data()
[259] Fix | Delete
{
[260] Fix | Delete
return $this->data;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
public function tag_open($parser, $tag, $attributes)
[264] Fix | Delete
{
[265] Fix | Delete
[$this->namespace[], $this->element[]] = $this->split_ns($tag);
[266] Fix | Delete
[267] Fix | Delete
$attribs = [];
[268] Fix | Delete
foreach ($attributes as $name => $value) {
[269] Fix | Delete
[$attrib_namespace, $attribute] = $this->split_ns($name);
[270] Fix | Delete
$attribs[$attrib_namespace][$attribute] = $value;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'])) {
[274] Fix | Delete
$base = $this->registry->call(Misc::class, 'absolutize_url', [$attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'], end($this->xml_base)]);
[275] Fix | Delete
if ($base !== false) {
[276] Fix | Delete
$this->xml_base[] = $base;
[277] Fix | Delete
$this->xml_base_explicit[] = true;
[278] Fix | Delete
}
[279] Fix | Delete
} else {
[280] Fix | Delete
$this->xml_base[] = end($this->xml_base);
[281] Fix | Delete
$this->xml_base_explicit[] = end($this->xml_base_explicit);
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang'])) {
[285] Fix | Delete
$this->xml_lang[] = $attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang'];
[286] Fix | Delete
} else {
[287] Fix | Delete
$this->xml_lang[] = end($this->xml_lang);
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
if ($this->current_xhtml_construct >= 0) {
[291] Fix | Delete
$this->current_xhtml_construct++;
[292] Fix | Delete
if (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_XHTML) {
[293] Fix | Delete
$this->data['data'] .= '<' . end($this->element);
[294] Fix | Delete
if (isset($attribs[''])) {
[295] Fix | Delete
foreach ($attribs[''] as $name => $value) {
[296] Fix | Delete
$this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
[297] Fix | Delete
}
[298] Fix | Delete
}
[299] Fix | Delete
$this->data['data'] .= '>';
[300] Fix | Delete
}
[301] Fix | Delete
} else {
[302] Fix | Delete
$this->datas[] = &$this->data;
[303] Fix | Delete
$this->data = &$this->data['child'][end($this->namespace)][end($this->element)][];
[304] Fix | Delete
$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)];
[305] Fix | Delete
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')
[306] Fix | Delete
|| (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')
[307] Fix | Delete
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_20 && in_array(end($this->element), ['title']))
[308] Fix | Delete
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_090 && in_array(end($this->element), ['title']))
[309] Fix | Delete
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_10 && in_array(end($this->element), ['title']))) {
[310] Fix | Delete
$this->current_xhtml_construct = 0;
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
public function cdata($parser, $cdata)
[316] Fix | Delete
{
[317] Fix | Delete
if ($this->current_xhtml_construct >= 0) {
[318] Fix | Delete
$this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
[319] Fix | Delete
} else {
[320] Fix | Delete
$this->data['data'] .= $cdata;
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
public function tag_close($parser, $tag)
[325] Fix | Delete
{
[326] Fix | Delete
if ($this->current_xhtml_construct >= 0) {
[327] Fix | Delete
$this->current_xhtml_construct--;
[328] Fix | Delete
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'])) {
[329] Fix | Delete
$this->data['data'] .= '</' . end($this->element) . '>';
[330] Fix | Delete
}
[331] Fix | Delete
}
[332] Fix | Delete
if ($this->current_xhtml_construct === -1) {
[333] Fix | Delete
$this->data = &$this->datas[count($this->datas) - 1];
[334] Fix | Delete
array_pop($this->datas);
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
array_pop($this->element);
[338] Fix | Delete
array_pop($this->namespace);
[339] Fix | Delete
array_pop($this->xml_base);
[340] Fix | Delete
array_pop($this->xml_base_explicit);
[341] Fix | Delete
array_pop($this->xml_lang);
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
public function split_ns($string)
[345] Fix | Delete
{
[346] Fix | Delete
static $cache = [];
[347] Fix | Delete
if (!isset($cache[$string])) {
[348] Fix | Delete
if ($pos = strpos($string, $this->separator)) {
[349] Fix | Delete
static $separator_length;
[350] Fix | Delete
if (!$separator_length) {
[351] Fix | Delete
$separator_length = strlen($this->separator);
[352] Fix | Delete
}
[353] Fix | Delete
$namespace = substr($string, 0, $pos);
[354] Fix | Delete
$local_name = substr($string, $pos + $separator_length);
[355] Fix | Delete
if (strtolower($namespace) === \SimplePie\SimplePie::NAMESPACE_ITUNES) {
[356] Fix | Delete
$namespace = \SimplePie\SimplePie::NAMESPACE_ITUNES;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
// Normalize the Media RSS namespaces
[360] Fix | Delete
if ($namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG ||
[361] Fix | Delete
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG2 ||
[362] Fix | Delete
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG3 ||
[363] Fix | Delete
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG4 ||
[364] Fix | Delete
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG5) {
[365] Fix | Delete
$namespace = \SimplePie\SimplePie::NAMESPACE_MEDIARSS;
[366] Fix | Delete
}
[367] Fix | Delete
$cache[$string] = [$namespace, $local_name];
[368] Fix | Delete
} else {
[369] Fix | Delete
$cache[$string] = ['', $string];
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
return $cache[$string];
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
private function parse_hcard($data, $category = false)
[376] Fix | Delete
{
[377] Fix | Delete
$name = '';
[378] Fix | Delete
$link = '';
[379] Fix | Delete
// Check if h-card is set and pass that information on in the link.
[380] Fix | Delete
if (isset($data['type']) && in_array('h-card', $data['type'])) {
[381] Fix | Delete
if (isset($data['properties']['name'][0])) {
[382] Fix | Delete
$name = $data['properties']['name'][0];
[383] Fix | Delete
}
[384] Fix | Delete
if (isset($data['properties']['url'][0])) {
[385] Fix | Delete
$link = $data['properties']['url'][0];
[386] Fix | Delete
if ($name === '') {
[387] Fix | Delete
$name = $link;
[388] Fix | Delete
} else {
[389] Fix | Delete
// can't have commas in categories.
[390] Fix | Delete
$name = str_replace(',', '', $name);
[391] Fix | Delete
}
[392] Fix | Delete
$person_tag = $category ? '<span class="person-tag"></span>' : '';
[393] Fix | Delete
return '<a class="h-card" href="'.$link.'">'.$person_tag.$name.'</a>';
[394] Fix | Delete
}
[395] Fix | Delete
}
[396] Fix | Delete
return $data['value'] ?? '';
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
private function parse_microformats(&$data, $url)
[400] Fix | Delete
{
[401] Fix | Delete
$feed_title = '';
[402] Fix | Delete
$feed_author = null;
[403] Fix | Delete
$author_cache = [];
[404] Fix | Delete
$items = [];
[405] Fix | Delete
$entries = [];
[406] Fix | Delete
$mf = \Mf2\parse($data, $url);
[407] Fix | Delete
// First look for an h-feed.
[408] Fix | Delete
$h_feed = [];
[409] Fix | Delete
foreach ($mf['items'] as $mf_item) {
[410] Fix | Delete
if (in_array('h-feed', $mf_item['type'])) {
[411] Fix | Delete
$h_feed = $mf_item;
[412] Fix | Delete
break;
[413] Fix | Delete
}
[414] Fix | Delete
// Also look for h-feed or h-entry in the children of each top level item.
[415] Fix | Delete
if (!isset($mf_item['children'][0]['type'])) {
[416] Fix | Delete
continue;
[417] Fix | Delete
}
[418] Fix | Delete
if (in_array('h-feed', $mf_item['children'][0]['type'])) {
[419] Fix | Delete
$h_feed = $mf_item['children'][0];
[420] Fix | Delete
// In this case the parent of the h-feed may be an h-card, so use it as
[421] Fix | Delete
// the feed_author.
[422] Fix | Delete
if (in_array('h-card', $mf_item['type'])) {
[423] Fix | Delete
$feed_author = $mf_item;
[424] Fix | Delete
}
[425] Fix | Delete
break;
[426] Fix | Delete
} elseif (in_array('h-entry', $mf_item['children'][0]['type'])) {
[427] Fix | Delete
$entries = $mf_item['children'];
[428] Fix | Delete
// In this case the parent of the h-entry list may be an h-card, so use
[429] Fix | Delete
// it as the feed_author.
[430] Fix | Delete
if (in_array('h-card', $mf_item['type'])) {
[431] Fix | Delete
$feed_author = $mf_item;
[432] Fix | Delete
}
[433] Fix | Delete
break;
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
if (isset($h_feed['children'])) {
[437] Fix | Delete
$entries = $h_feed['children'];
[438] Fix | Delete
// Also set the feed title and store author from the h-feed if available.
[439] Fix | Delete
if (isset($mf['items'][0]['properties']['name'][0])) {
[440] Fix | Delete
$feed_title = $mf['items'][0]['properties']['name'][0];
[441] Fix | Delete
}
[442] Fix | Delete
if (isset($mf['items'][0]['properties']['author'][0])) {
[443] Fix | Delete
$feed_author = $mf['items'][0]['properties']['author'][0];
[444] Fix | Delete
}
[445] Fix | Delete
} elseif (count($entries) === 0) {
[446] Fix | Delete
$entries = $mf['items'];
[447] Fix | Delete
}
[448] Fix | Delete
for ($i = 0; $i < count($entries); $i++) {
[449] Fix | Delete
$entry = $entries[$i];
[450] Fix | Delete
if (in_array('h-entry', $entry['type'])) {
[451] Fix | Delete
$item = [];
[452] Fix | Delete
$title = '';
[453] Fix | Delete
$description = '';
[454] Fix | Delete
if (isset($entry['properties']['url'][0])) {
[455] Fix | Delete
$link = $entry['properties']['url'][0];
[456] Fix | Delete
if (isset($link['value'])) {
[457] Fix | Delete
$link = $link['value'];
[458] Fix | Delete
}
[459] Fix | Delete
$item['link'] = [['data' => $link]];
[460] Fix | Delete
}
[461] Fix | Delete
if (isset($entry['properties']['uid'][0])) {
[462] Fix | Delete
$guid = $entry['properties']['uid'][0];
[463] Fix | Delete
if (isset($guid['value'])) {
[464] Fix | Delete
$guid = $guid['value'];
[465] Fix | Delete
}
[466] Fix | Delete
$item['guid'] = [['data' => $guid]];
[467] Fix | Delete
}
[468] Fix | Delete
if (isset($entry['properties']['name'][0])) {
[469] Fix | Delete
$title = $entry['properties']['name'][0];
[470] Fix | Delete
if (isset($title['value'])) {
[471] Fix | Delete
$title = $title['value'];
[472] Fix | Delete
}
[473] Fix | Delete
$item['title'] = [['data' => $title]];
[474] Fix | Delete
}
[475] Fix | Delete
if (isset($entry['properties']['author'][0]) || isset($feed_author)) {
[476] Fix | Delete
// author is a special case, it can be plain text or an h-card array.
[477] Fix | Delete
// If it's plain text it can also be a url that should be followed to
[478] Fix | Delete
// get the actual h-card.
[479] Fix | Delete
$author = $entry['properties']['author'][0] ?? $feed_author;
[480] Fix | Delete
if (!is_string($author)) {
[481] Fix | Delete
$author = $this->parse_hcard($author);
[482] Fix | Delete
} elseif (strpos($author, 'http') === 0) {
[483] Fix | Delete
if (isset($author_cache[$author])) {
[484] Fix | Delete
$author = $author_cache[$author];
[485] Fix | Delete
} else {
[486] Fix | Delete
$mf = \Mf2\fetch($author);
[487] Fix | Delete
foreach ($mf['items'] as $hcard) {
[488] Fix | Delete
// Only interested in an h-card by itself in this case.
[489] Fix | Delete
if (!in_array('h-card', $hcard['type'])) {
[490] Fix | Delete
continue;
[491] Fix | Delete
}
[492] Fix | Delete
// It must have a url property matching what we fetched.
[493] Fix | Delete
if (!isset($hcard['properties']['url']) ||
[494] Fix | Delete
!(in_array($author, $hcard['properties']['url']))) {
[495] Fix | Delete
continue;
[496] Fix | Delete
}
[497] Fix | Delete
// Save parse_hcard the trouble of finding the correct url.
[498] Fix | Delete
$hcard['properties']['url'][0] = $author;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function