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