Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../SimplePi.../src
File: Item.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
[2] Fix | Delete
// SPDX-License-Identifier: BSD-3-Clause
[3] Fix | Delete
[4] Fix | Delete
declare(strict_types=1);
[5] Fix | Delete
[6] Fix | Delete
namespace SimplePie;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Manages all item-related data
[10] Fix | Delete
*
[11] Fix | Delete
* Used by {@see \SimplePie\SimplePie::get_item()} and {@see \SimplePie\SimplePie::get_items()}
[12] Fix | Delete
*
[13] Fix | Delete
* This class can be overloaded with {@see \SimplePie\SimplePie::set_item_class()}
[14] Fix | Delete
*/
[15] Fix | Delete
class Item implements RegistryAware
[16] Fix | Delete
{
[17] Fix | Delete
/**
[18] Fix | Delete
* Parent feed
[19] Fix | Delete
*
[20] Fix | Delete
* @access private
[21] Fix | Delete
* @var \SimplePie\SimplePie
[22] Fix | Delete
*/
[23] Fix | Delete
public $feed;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Raw data
[27] Fix | Delete
*
[28] Fix | Delete
* @access private
[29] Fix | Delete
* @var array<string, mixed>
[30] Fix | Delete
*/
[31] Fix | Delete
public $data = [];
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Registry object
[35] Fix | Delete
*
[36] Fix | Delete
* @see set_registry
[37] Fix | Delete
* @var \SimplePie\Registry
[38] Fix | Delete
*/
[39] Fix | Delete
protected $registry;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* @var Sanitize|null
[43] Fix | Delete
*/
[44] Fix | Delete
private $sanitize = null;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Create a new item object
[48] Fix | Delete
*
[49] Fix | Delete
* This is usually used by {@see \SimplePie\SimplePie::get_items} and
[50] Fix | Delete
* {@see \SimplePie\SimplePie::get_item}. Avoid creating this manually.
[51] Fix | Delete
*
[52] Fix | Delete
* @param \SimplePie\SimplePie $feed Parent feed
[53] Fix | Delete
* @param array<string, mixed> $data Raw data
[54] Fix | Delete
*/
[55] Fix | Delete
public function __construct(\SimplePie\SimplePie $feed, array $data)
[56] Fix | Delete
{
[57] Fix | Delete
$this->feed = $feed;
[58] Fix | Delete
$this->data = $data;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Set the registry handler
[63] Fix | Delete
*
[64] Fix | Delete
* This is usually used by {@see \SimplePie\Registry::create}
[65] Fix | Delete
*
[66] Fix | Delete
* @since 1.3
[67] Fix | Delete
* @param \SimplePie\Registry $registry
[68] Fix | Delete
* @return void
[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
/**
[76] Fix | Delete
* Get a string representation of the item
[77] Fix | Delete
*
[78] Fix | Delete
* @return string
[79] Fix | Delete
*/
[80] Fix | Delete
public function __toString()
[81] Fix | Delete
{
[82] Fix | Delete
return md5(serialize($this->data));
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Remove items that link back to this before destroying this object
[87] Fix | Delete
*/
[88] Fix | Delete
public function __destruct()
[89] Fix | Delete
{
[90] Fix | Delete
if (!gc_enabled()) {
[91] Fix | Delete
unset($this->feed);
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Get data for an item-level element
[97] Fix | Delete
*
[98] Fix | Delete
* This method allows you to get access to ANY element/attribute that is a
[99] Fix | Delete
* sub-element of the item/entry tag.
[100] Fix | Delete
*
[101] Fix | Delete
* See {@see \SimplePie\SimplePie::get_feed_tags()} for a description of the return value
[102] Fix | Delete
*
[103] Fix | Delete
* @since 1.0
[104] Fix | Delete
* @see http://simplepie.org/wiki/faq/supported_xml_namespaces
[105] Fix | Delete
* @param string $namespace The URL of the XML namespace of the elements you're trying to access
[106] Fix | Delete
* @param string $tag Tag name
[107] Fix | Delete
* @return array<array<string, mixed>>|null
[108] Fix | Delete
*/
[109] Fix | Delete
public function get_item_tags(string $namespace, string $tag)
[110] Fix | Delete
{
[111] Fix | Delete
if (isset($this->data['child'][$namespace][$tag])) {
[112] Fix | Delete
return $this->data['child'][$namespace][$tag];
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return null;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Get base URL of the item itself.
[120] Fix | Delete
* Returns `<xml:base>` or feed base URL.
[121] Fix | Delete
* Similar to `Item::get_base()` but can safely be used during initialisation methods
[122] Fix | Delete
* such as `Item::get_links()` (`Item::get_base()` and `Item::get_links()` call each-other)
[123] Fix | Delete
* and is not affected by enclosures.
[124] Fix | Delete
*
[125] Fix | Delete
* @param array<string, mixed> $element
[126] Fix | Delete
* @see get_base
[127] Fix | Delete
*/
[128] Fix | Delete
private function get_own_base(array $element = []): string
[129] Fix | Delete
{
[130] Fix | Delete
if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) {
[131] Fix | Delete
return $element['xml_base'];
[132] Fix | Delete
}
[133] Fix | Delete
return $this->feed->get_base();
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Get the base URL value.
[138] Fix | Delete
* Uses `<xml:base>`, or item link, or enclosure link, or feed base URL.
[139] Fix | Delete
*
[140] Fix | Delete
* @param array<string, mixed> $element
[141] Fix | Delete
* @return string
[142] Fix | Delete
*/
[143] Fix | Delete
public function get_base(array $element = [])
[144] Fix | Delete
{
[145] Fix | Delete
if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) {
[146] Fix | Delete
return $element['xml_base'];
[147] Fix | Delete
}
[148] Fix | Delete
$link = $this->get_permalink();
[149] Fix | Delete
if ($link != null) {
[150] Fix | Delete
return $link;
[151] Fix | Delete
}
[152] Fix | Delete
return $this->feed->get_base($element);
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Sanitize feed data
[157] Fix | Delete
*
[158] Fix | Delete
* @access private
[159] Fix | Delete
* @see \SimplePie\SimplePie::sanitize()
[160] Fix | Delete
* @param string $data Data to sanitize
[161] Fix | Delete
* @param int-mask-of<SimplePie::CONSTRUCT_*> $type
[162] Fix | Delete
* @param string $base Base URL to resolve URLs against
[163] Fix | Delete
* @return string Sanitized data
[164] Fix | Delete
*/
[165] Fix | Delete
public function sanitize(string $data, int $type, string $base = '')
[166] Fix | Delete
{
[167] Fix | Delete
// This really returns string|false but changing encoding is uncommon and we are going to deprecate it, so let’s just lie to PHPStan in the interest of cleaner annotations.
[168] Fix | Delete
return $this->feed->sanitize($data, $type, $base);
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Get the parent feed
[173] Fix | Delete
*
[174] Fix | Delete
* Note: this may not work as you think for multifeeds!
[175] Fix | Delete
*
[176] Fix | Delete
* @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
[177] Fix | Delete
* @since 1.0
[178] Fix | Delete
* @return \SimplePie\SimplePie
[179] Fix | Delete
*/
[180] Fix | Delete
public function get_feed()
[181] Fix | Delete
{
[182] Fix | Delete
return $this->feed;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Get the unique identifier for the item
[187] Fix | Delete
*
[188] Fix | Delete
* This is usually used when writing code to check for new items in a feed.
[189] Fix | Delete
*
[190] Fix | Delete
* Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
[191] Fix | Delete
* for RDF. If none of these are supplied (or `$hash` is true), creates an
[192] Fix | Delete
* MD5 hash based on the permalink, title and content.
[193] Fix | Delete
*
[194] Fix | Delete
* @since Beta 2
[195] Fix | Delete
* @param bool $hash Should we force using a hash instead of the supplied ID?
[196] Fix | Delete
* @param string|false $fn User-supplied function to generate an hash
[197] Fix | Delete
* @return string|null
[198] Fix | Delete
*/
[199] Fix | Delete
public function get_id(bool $hash = false, $fn = 'md5')
[200] Fix | Delete
{
[201] Fix | Delete
if (!$hash) {
[202] Fix | Delete
if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'id')) {
[203] Fix | Delete
return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[204] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'id')) {
[205] Fix | Delete
return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[206] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'guid')) {
[207] Fix | Delete
return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[208] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'identifier')) {
[209] Fix | Delete
return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[210] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'identifier')) {
[211] Fix | Delete
return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[212] Fix | Delete
} elseif (isset($this->data['attribs'][\SimplePie\SimplePie::NAMESPACE_RDF]['about'])) {
[213] Fix | Delete
return $this->sanitize($this->data['attribs'][\SimplePie\SimplePie::NAMESPACE_RDF]['about'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
if ($fn === false) {
[217] Fix | Delete
return null;
[218] Fix | Delete
} elseif (!is_callable($fn)) {
[219] Fix | Delete
trigger_error('User-supplied function $fn must be callable', E_USER_WARNING);
[220] Fix | Delete
$fn = 'md5';
[221] Fix | Delete
}
[222] Fix | Delete
return call_user_func(
[223] Fix | Delete
$fn,
[224] Fix | Delete
$this->get_permalink().$this->get_title().$this->get_content()
[225] Fix | Delete
);
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Get the title of the item
[230] Fix | Delete
*
[231] Fix | Delete
* Uses `<atom:title>`, `<title>` or `<dc:title>`
[232] Fix | Delete
*
[233] Fix | Delete
* @since Beta 2 (previously called `get_item_title` since 0.8)
[234] Fix | Delete
* @return string|null
[235] Fix | Delete
*/
[236] Fix | Delete
public function get_title()
[237] Fix | Delete
{
[238] Fix | Delete
if (!isset($this->data['title'])) {
[239] Fix | Delete
if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'title')) {
[240] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0]));
[241] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'title')) {
[242] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0]));
[243] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10, 'title')) {
[244] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
[245] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_090, 'title')) {
[246] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
[247] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'title')) {
[248] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
[249] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'title')) {
[250] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[251] Fix | Delete
} elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'title')) {
[252] Fix | Delete
$this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[253] Fix | Delete
} else {
[254] Fix | Delete
$this->data['title'] = null;
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
return $this->data['title'];
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
/**
[261] Fix | Delete
* Get the content for the item
[262] Fix | Delete
*
[263] Fix | Delete
* Prefers summaries over full content , but will return full content if a
[264] Fix | Delete
* summary does not exist.
[265] Fix | Delete
*
[266] Fix | Delete
* To prefer full content instead, use {@see get_content}
[267] Fix | Delete
*
[268] Fix | Delete
* Uses `<atom:summary>`, `<description>`, `<dc:description>` or
[269] Fix | Delete
* `<itunes:subtitle>`
[270] Fix | Delete
*
[271] Fix | Delete
* @since 0.8
[272] Fix | Delete
* @param bool $description_only Should we avoid falling back to the content?
[273] Fix | Delete
* @return string|null
[274] Fix | Delete
*/
[275] Fix | Delete
public function get_description(bool $description_only = false)
[276] Fix | Delete
{
[277] Fix | Delete
if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'summary')) &&
[278] Fix | Delete
($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) {
[279] Fix | Delete
return $return;
[280] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'summary')) &&
[281] Fix | Delete
($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) {
[282] Fix | Delete
return $return;
[283] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10, 'description')) &&
[284] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0])))) {
[285] Fix | Delete
return $return;
[286] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'description')) &&
[287] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) {
[288] Fix | Delete
return $return;
[289] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'description')) &&
[290] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) {
[291] Fix | Delete
return $return;
[292] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'description')) &&
[293] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) {
[294] Fix | Delete
return $return;
[295] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'summary')) &&
[296] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) {
[297] Fix | Delete
return $return;
[298] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'subtitle')) &&
[299] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) {
[300] Fix | Delete
return $return;
[301] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_090, 'description')) &&
[302] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML))) {
[303] Fix | Delete
return $return;
[304] Fix | Delete
} elseif (!$description_only) {
[305] Fix | Delete
return $this->get_content(true);
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
return null;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
/**
[312] Fix | Delete
* Get the content for the item
[313] Fix | Delete
*
[314] Fix | Delete
* Prefers full content over summaries, but will return a summary if full
[315] Fix | Delete
* content does not exist.
[316] Fix | Delete
*
[317] Fix | Delete
* To prefer summaries instead, use {@see get_description}
[318] Fix | Delete
*
[319] Fix | Delete
* Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
[320] Fix | Delete
*
[321] Fix | Delete
* @since 1.0
[322] Fix | Delete
* @param bool $content_only Should we avoid falling back to the description?
[323] Fix | Delete
* @return string|null
[324] Fix | Delete
*/
[325] Fix | Delete
public function get_content(bool $content_only = false)
[326] Fix | Delete
{
[327] Fix | Delete
if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'content')) &&
[328] Fix | Delete
($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_10_content_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) {
[329] Fix | Delete
return $return;
[330] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'content')) &&
[331] Fix | Delete
($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) {
[332] Fix | Delete
return $return;
[333] Fix | Delete
} elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) &&
[334] Fix | Delete
($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) {
[335] Fix | Delete
return $return;
[336] Fix | Delete
} elseif (!$content_only) {
[337] Fix | Delete
return $this->get_description(true);
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
return null;
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* Get the media:thumbnail of the item
[345] Fix | Delete
*
[346] Fix | Delete
* Uses `<media:thumbnail>`
[347] Fix | Delete
*
[348] Fix | Delete
*
[349] Fix | Delete
* @return array{url: string, height?: string, width?: string, time?: string}|null
[350] Fix | Delete
*/
[351] Fix | Delete
public function get_thumbnail()
[352] Fix | Delete
{
[353] Fix | Delete
if (!isset($this->data['thumbnail'])) {
[354] Fix | Delete
if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) {
[355] Fix | Delete
$thumbnail = $return[0]['attribs'][''];
[356] Fix | Delete
if (empty($thumbnail['url'])) {
[357] Fix | Delete
$this->data['thumbnail'] = null;
[358] Fix | Delete
} else {
[359] Fix | Delete
$thumbnail['url'] = $this->sanitize($thumbnail['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($return[0]));
[360] Fix | Delete
$this->data['thumbnail'] = $thumbnail;
[361] Fix | Delete
}
[362] Fix | Delete
} else {
[363] Fix | Delete
$this->data['thumbnail'] = null;
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
return $this->data['thumbnail'];
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
/**
[370] Fix | Delete
* Get a category for the item
[371] Fix | Delete
*
[372] Fix | Delete
* @since Beta 3 (previously called `get_categories()` since Beta 2)
[373] Fix | Delete
* @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
[374] Fix | Delete
* @return \SimplePie\Category|null
[375] Fix | Delete
*/
[376] Fix | Delete
public function get_category(int $key = 0)
[377] Fix | Delete
{
[378] Fix | Delete
$categories = $this->get_categories();
[379] Fix | Delete
if (isset($categories[$key])) {
[380] Fix | Delete
return $categories[$key];
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
return null;
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
/**
[387] Fix | Delete
* Get all categories for the item
[388] Fix | Delete
*
[389] Fix | Delete
* Uses `<atom:category>`, `<category>` or `<dc:subject>`
[390] Fix | Delete
*
[391] Fix | Delete
* @since Beta 3
[392] Fix | Delete
* @return \SimplePie\Category[]|null List of {@see \SimplePie\Category} objects
[393] Fix | Delete
*/
[394] Fix | Delete
public function get_categories()
[395] Fix | Delete
{
[396] Fix | Delete
$categories = [];
[397] Fix | Delete
[398] Fix | Delete
$type = 'category';
[399] Fix | Delete
foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, $type) as $category) {
[400] Fix | Delete
$term = null;
[401] Fix | Delete
$scheme = null;
[402] Fix | Delete
$label = null;
[403] Fix | Delete
if (isset($category['attribs']['']['term'])) {
[404] Fix | Delete
$term = $this->sanitize($category['attribs']['']['term'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[405] Fix | Delete
}
[406] Fix | Delete
if (isset($category['attribs']['']['scheme'])) {
[407] Fix | Delete
$scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[408] Fix | Delete
}
[409] Fix | Delete
if (isset($category['attribs']['']['label'])) {
[410] Fix | Delete
$label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[411] Fix | Delete
}
[412] Fix | Delete
$categories[] = $this->registry->create(Category::class, [$term, $scheme, $label, $type]);
[413] Fix | Delete
}
[414] Fix | Delete
foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, $type) as $category) {
[415] Fix | Delete
// This is really the label, but keep this as the term also for BC.
[416] Fix | Delete
// Label will also work on retrieving because that falls back to term.
[417] Fix | Delete
$term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[418] Fix | Delete
if (isset($category['attribs']['']['domain'])) {
[419] Fix | Delete
$scheme = $this->sanitize($category['attribs']['']['domain'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[420] Fix | Delete
} else {
[421] Fix | Delete
$scheme = null;
[422] Fix | Delete
}
[423] Fix | Delete
$categories[] = $this->registry->create(Category::class, [$term, $scheme, null, $type]);
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
$type = 'subject';
[427] Fix | Delete
foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, $type) as $category) {
[428] Fix | Delete
$categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null, $type]);
[429] Fix | Delete
}
[430] Fix | Delete
foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, $type) as $category) {
[431] Fix | Delete
$categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null, $type]);
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
if (!empty($categories)) {
[435] Fix | Delete
return array_unique($categories);
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
return null;
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
/**
[442] Fix | Delete
* Get an author for the item
[443] Fix | Delete
*
[444] Fix | Delete
* @since Beta 2
[445] Fix | Delete
* @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
[446] Fix | Delete
* @return \SimplePie\Author|null
[447] Fix | Delete
*/
[448] Fix | Delete
public function get_author(int $key = 0)
[449] Fix | Delete
{
[450] Fix | Delete
$authors = $this->get_authors();
[451] Fix | Delete
if (isset($authors[$key])) {
[452] Fix | Delete
return $authors[$key];
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
return null;
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Get a contributor for the item
[460] Fix | Delete
*
[461] Fix | Delete
* @since 1.1
[462] Fix | Delete
* @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
[463] Fix | Delete
* @return \SimplePie\Author|null
[464] Fix | Delete
*/
[465] Fix | Delete
public function get_contributor(int $key = 0)
[466] Fix | Delete
{
[467] Fix | Delete
$contributors = $this->get_contributors();
[468] Fix | Delete
if (isset($contributors[$key])) {
[469] Fix | Delete
return $contributors[$key];
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
return null;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
/**
[476] Fix | Delete
* Get all contributors for the item
[477] Fix | Delete
*
[478] Fix | Delete
* Uses `<atom:contributor>`
[479] Fix | Delete
*
[480] Fix | Delete
* @since 1.1
[481] Fix | Delete
* @return \SimplePie\Author[]|null List of {@see \SimplePie\Author} objects
[482] Fix | Delete
*/
[483] Fix | Delete
public function get_contributors()
[484] Fix | Delete
{
[485] Fix | Delete
$contributors = [];
[486] Fix | Delete
foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'contributor') as $contributor) {
[487] Fix | Delete
$name = null;
[488] Fix | Delete
$uri = null;
[489] Fix | Delete
$email = null;
[490] Fix | Delete
if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'])) {
[491] Fix | Delete
$name = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[492] Fix | Delete
}
[493] Fix | Delete
if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]['data'])) {
[494] Fix | Delete
$uri = $contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0];
[495] Fix | Delete
$uri = $this->sanitize($uri['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($uri));
[496] Fix | Delete
}
[497] Fix | Delete
if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) {
[498] Fix | Delete
$email = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function