Entry.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_Entry extends Minz_Model {
  4. use FreshRSS_AttributesTrait;
  5. public const STATE_READ = 1;
  6. public const STATE_NOT_READ = 2;
  7. public const STATE_ALL = 3;
  8. public const STATE_FAVORITE = 4;
  9. public const STATE_NOT_FAVORITE = 8;
  10. /** @var numeric-string */
  11. private string $id = '0';
  12. private string $guid;
  13. private string $title;
  14. /** @var array<string> */
  15. private array $authors;
  16. private string $content;
  17. private string $link;
  18. private int $date;
  19. private int $lastSeen = 0;
  20. /** In microseconds */
  21. private string $date_added = '0';
  22. private string $hash = '';
  23. private ?bool $is_read;
  24. private ?bool $is_favorite;
  25. private bool $is_updated = false;
  26. private int $feedId;
  27. private ?FreshRSS_Feed $feed;
  28. /** @var array<string> */
  29. private array $tags = [];
  30. /**
  31. * @param string|array<string> $tags
  32. */
  33. public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '',
  34. string $link = '', int|string $pubdate = 0, bool|int|null $is_read = false, bool|int|null $is_favorite = false, $tags = '') {
  35. $this->_title($title);
  36. $this->_authors($authors);
  37. $this->_content($content);
  38. $this->_link($link);
  39. $this->_date($pubdate);
  40. $this->_isRead($is_read);
  41. $this->_isFavorite($is_favorite);
  42. $this->_feedId($feedId);
  43. $this->_tags($tags);
  44. $this->_guid($guid);
  45. }
  46. /** @param array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string,'lastSeen'?:int,
  47. * 'hash'?:string,'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array<string>,'attributes'?:?string,'thumbnail'?:string,'timestamp'?:string} $dao */
  48. public static function fromArray(array $dao): FreshRSS_Entry {
  49. FreshRSS_DatabaseDAO::pdoInt($dao, ['id_feed', 'date', 'lastSeen', 'is_read', 'is_favorite']);
  50. if (empty($dao['content'])) {
  51. $dao['content'] = '';
  52. }
  53. $dao['attributes'] = empty($dao['attributes']) ? [] : json_decode($dao['attributes'], true);
  54. if (!is_array($dao['attributes'])) {
  55. $dao['attributes'] = [];
  56. }
  57. if (!empty($dao['thumbnail'])) {
  58. $dao['attributes']['thumbnail'] = [
  59. 'url' => $dao['thumbnail'],
  60. ];
  61. }
  62. $entry = new FreshRSS_Entry(
  63. $dao['id_feed'] ?? 0,
  64. $dao['guid'] ?? '',
  65. $dao['title'] ?? '',
  66. $dao['author'] ?? '',
  67. $dao['content'],
  68. $dao['link'] ?? '',
  69. $dao['date'] ?? 0,
  70. $dao['is_read'] ?? false,
  71. $dao['is_favorite'] ?? false,
  72. $dao['tags'] ?? ''
  73. );
  74. if (!empty($dao['id'])) {
  75. $entry->_id($dao['id']);
  76. }
  77. if (!empty($dao['timestamp'])) {
  78. $entry->_date(strtotime($dao['timestamp']) ?: 0);
  79. }
  80. if (isset($dao['lastSeen'])) {
  81. $entry->_lastSeen($dao['lastSeen']);
  82. }
  83. if (!empty($dao['attributes'])) {
  84. $entry->_attributes($dao['attributes']);
  85. }
  86. if (!empty($dao['hash'])) {
  87. $entry->_hash($dao['hash']);
  88. }
  89. return $entry;
  90. }
  91. /**
  92. * @param Traversable<array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string,'lastSeen'?:int,
  93. * 'hash'?:string,'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array<string>,'attributes'?:?string,'thumbnail'?:string,'timestamp'?:string}> $daos
  94. * @return Traversable<FreshRSS_Entry>
  95. */
  96. public static function fromTraversable(Traversable $daos): Traversable {
  97. foreach ($daos as $dao) {
  98. yield FreshRSS_Entry::fromArray($dao);
  99. }
  100. }
  101. /** @return numeric-string */
  102. public function id(): string {
  103. return $this->id;
  104. }
  105. public function guid(): string {
  106. return $this->guid;
  107. }
  108. public function title(): string {
  109. $title = '';
  110. if ($this->title === '') {
  111. // used while fetching the article from feed and store it in the database
  112. $title = $this->guid();
  113. } else {
  114. // used while fetching from the database
  115. if ($this->title !== $this->guid) {
  116. $title = $this->title;
  117. } else {
  118. $content = trim(strip_tags($this->content(false)));
  119. $title = trim(mb_substr($content, 0, MAX_CHARS_EMPTY_FEED_TITLE, 'UTF-8'));
  120. if ($title === '') {
  121. $title = $this->guid();
  122. } elseif (strlen($content) > strlen($title)) {
  123. $title .= '…';
  124. }
  125. }
  126. }
  127. return $title;
  128. }
  129. /** @deprecated */
  130. public function author(): string {
  131. return $this->authors(true);
  132. }
  133. /**
  134. * @phpstan-return ($asString is true ? string : array<string>)
  135. * @return string|array<string>
  136. */
  137. public function authors(bool $asString = false): string|array {
  138. if ($asString) {
  139. return $this->authors == null ? '' : ';' . implode('; ', $this->authors);
  140. } else {
  141. return $this->authors;
  142. }
  143. }
  144. /**
  145. * Basic test without ambition to catch all cases such as unquoted addresses, variants of entities, HTML comments, etc.
  146. */
  147. private static function containsLink(string $html, string $link): bool {
  148. return preg_match('/(?P<delim>[\'"])' . preg_quote($link, '/') . '(?P=delim)/', $html) == 1;
  149. }
  150. /** @param array{'url'?:string,'length'?:int,'medium'?:string,'type'?:string} $enclosure */
  151. private static function enclosureIsImage(array $enclosure): bool {
  152. $elink = $enclosure['url'] ?? '';
  153. $length = $enclosure['length'] ?? 0;
  154. $medium = $enclosure['medium'] ?? '';
  155. $mime = $enclosure['type'] ?? '';
  156. return ($elink != '' && $medium === 'image') || str_starts_with($mime, 'image') ||
  157. ($mime == '' && $length == 0 && preg_match('/[.](avif|gif|jpe?g|png|svg|webp)([?#]|$)/i', $elink));
  158. }
  159. /**
  160. * Provides the original content without additional content potentially added by loadCompleteContent().
  161. */
  162. public function originalContent(): string {
  163. return $this->attributeString('original_content') ??
  164. preg_replace('#<!-- FULLCONTENT start //-->.*<!-- FULLCONTENT end //-->#s', '', $this->content) ?? '';
  165. }
  166. /**
  167. * @param bool $withEnclosures Set to true to include the enclosures in the returned HTML, false otherwise.
  168. * @param bool $allowDuplicateEnclosures Set to false to remove obvious enclosure duplicates (based on simple string comparison), true otherwise.
  169. * @return string HTML content
  170. */
  171. public function content(bool $withEnclosures = true, bool $allowDuplicateEnclosures = false): string {
  172. if (!$withEnclosures) {
  173. return $this->content;
  174. }
  175. $content = $this->content;
  176. $thumbnailAttribute = $this->attributeArray('thumbnail') ?? [];
  177. if (!empty($thumbnailAttribute['url'])) {
  178. $elink = $thumbnailAttribute['url'];
  179. if (is_string($elink) && ($allowDuplicateEnclosures || !self::containsLink($content, $elink))) {
  180. $content .= <<<HTML
  181. <figure class="enclosure">
  182. <p class="enclosure-content">
  183. <img class="enclosure-thumbnail" src="{$elink}" alt="" />
  184. </p>
  185. </figure>
  186. HTML;
  187. }
  188. }
  189. $attributeEnclosures = $this->attributeArray('enclosures');
  190. if (empty($attributeEnclosures)) {
  191. return $content;
  192. }
  193. foreach ($attributeEnclosures as $enclosure) {
  194. if (!is_array($enclosure)) {
  195. continue;
  196. }
  197. $elink = $enclosure['url'] ?? '';
  198. if ($elink == '' || !is_string($elink)) {
  199. continue;
  200. }
  201. if (!$allowDuplicateEnclosures && self::containsLink($content, $elink)) {
  202. continue;
  203. }
  204. $credits = $enclosure['credit'] ?? '';
  205. $description = nl2br($enclosure['description'] ?? '', true);
  206. $length = $enclosure['length'] ?? 0;
  207. $medium = $enclosure['medium'] ?? '';
  208. $mime = $enclosure['type'] ?? '';
  209. $thumbnails = $enclosure['thumbnails'] ?? null;
  210. if (!is_array($thumbnails)) {
  211. $thumbnails = [];
  212. }
  213. $etitle = $enclosure['title'] ?? '';
  214. $content .= "\n";
  215. $content .= '<figure class="enclosure">';
  216. foreach ($thumbnails as $thumbnail) {
  217. $content .= '<p><img class="enclosure-thumbnail" src="' . $thumbnail . '" alt="" title="' . $etitle . '" /></p>';
  218. }
  219. if (self::enclosureIsImage($enclosure)) {
  220. $content .= '<p class="enclosure-content"><img src="' . $elink . '" alt="" title="' . $etitle . '" /></p>';
  221. } elseif ($medium === 'audio' || str_starts_with($mime, 'audio')) {
  222. $content .= '<p class="enclosure-content"><audio preload="none" src="' . $elink
  223. . ($length == null ? '' : '" data-length="' . (int)$length)
  224. . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8'))
  225. . '" controls="controls" title="' . $etitle . '"></audio> <a download="" href="' . $elink . '">💾</a></p>';
  226. } elseif ($medium === 'video' || str_starts_with($mime, 'video')) {
  227. $content .= '<p class="enclosure-content"><video preload="none" src="' . $elink
  228. . ($length == null ? '' : '" data-length="' . (int)$length)
  229. . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8'))
  230. . '" controls="controls" title="' . $etitle . '"></video> <a download="" href="' . $elink . '">💾</a></p>';
  231. } else { //e.g. application, text, unknown
  232. $content .= '<p class="enclosure-content"><a download="" href="' . $elink
  233. . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8'))
  234. . ($medium == '' ? '' : '" data-medium="' . htmlspecialchars($medium, ENT_COMPAT, 'UTF-8'))
  235. . '" title="' . $etitle . '">💾</a></p>';
  236. }
  237. if ($credits != '') {
  238. if (!is_array($credits)) {
  239. $credits = [$credits];
  240. }
  241. foreach ($credits as $credit) {
  242. $content .= '<p class="enclosure-credits">© ' . $credit . '</p>';
  243. }
  244. }
  245. if ($description != '') {
  246. $content .= '<figcaption class="enclosure-description">' . $description . '</figcaption>';
  247. }
  248. $content .= "</figure>\n";
  249. }
  250. return $content;
  251. }
  252. /** @return Traversable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string|array<string>,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> */
  253. public function enclosures(bool $searchBodyImages = false): Traversable {
  254. $attributeEnclosures = $this->attributeArray('enclosures');
  255. if (is_iterable($attributeEnclosures)) {
  256. // FreshRSS 1.20.1+: The enclosures are saved as attributes
  257. /** @var iterable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string|array<string>,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> $attributeEnclosures */
  258. yield from $attributeEnclosures;
  259. }
  260. try {
  261. $searchEnclosures = !is_iterable($attributeEnclosures) && (str_contains($this->content, '<p class="enclosure-content'));
  262. $searchBodyImages &= (stripos($this->content, '<img') !== false);
  263. $xpath = null;
  264. if ($searchEnclosures || $searchBodyImages) {
  265. $dom = new DOMDocument();
  266. $dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);
  267. $xpath = new DOMXPath($dom);
  268. }
  269. if ($searchEnclosures && $xpath !== null) {
  270. // Legacy code for database entries < FreshRSS 1.20.1
  271. $enclosures = $xpath->query('//div[@class="enclosure"]/p[@class="enclosure-content"]/*[@src]');
  272. if (!empty($enclosures)) {
  273. foreach ($enclosures as $enclosure) {
  274. if (!($enclosure instanceof DOMElement)) {
  275. continue;
  276. }
  277. $result = [
  278. 'url' => $enclosure->getAttribute('src'),
  279. 'type' => $enclosure->getAttribute('data-type'),
  280. 'medium' => $enclosure->getAttribute('data-medium'),
  281. 'length' => (int)($enclosure->getAttribute('data-length')),
  282. ];
  283. if (empty($result['medium'])) {
  284. switch (strtolower($enclosure->nodeName)) {
  285. case 'img': $result['medium'] = 'image'; break;
  286. case 'video': $result['medium'] = 'video'; break;
  287. case 'audio': $result['medium'] = 'audio'; break;
  288. }
  289. }
  290. yield Minz_Helper::htmlspecialchars_utf8($result);
  291. }
  292. }
  293. }
  294. if ($searchBodyImages && $xpath !== null) {
  295. $images = $xpath->query('//img');
  296. if (!empty($images)) {
  297. foreach ($images as $img) {
  298. if (!($img instanceof DOMElement)) {
  299. continue;
  300. }
  301. $src = $img->getAttribute('src');
  302. if ($src == null) {
  303. $src = $img->getAttribute('data-src');
  304. }
  305. if ($src != null) {
  306. $result = [
  307. 'url' => $src,
  308. 'medium' => 'image',
  309. ];
  310. yield Minz_Helper::htmlspecialchars_utf8($result);
  311. }
  312. }
  313. }
  314. }
  315. } catch (Exception $ex) {
  316. Minz_Log::debug(__METHOD__ . ' ' . $ex->getMessage());
  317. }
  318. }
  319. /**
  320. * @return array{'url':string,'height'?:int,'width'?:int,'time'?:string}|null
  321. */
  322. public function thumbnail(bool $searchEnclosures = true): ?array {
  323. $thumbnail = $this->attributeArray('thumbnail') ?? [];
  324. // First, use the provided thumbnail, if any
  325. if (!empty($thumbnail['url'])) {
  326. /** @var array{'url':string,'height'?:int,'width'?:int,'time'?:string} $thumbnail */
  327. return $thumbnail;
  328. }
  329. if ($searchEnclosures) {
  330. foreach ($this->enclosures(true) as $enclosure) {
  331. // Second, search each enclosure’s thumbnails
  332. if (!empty($enclosure['thumbnails'][0])) {
  333. foreach ($enclosure['thumbnails'] as $src) {
  334. if (is_string($src)) {
  335. return [
  336. 'url' => $src,
  337. 'medium' => 'image',
  338. ];
  339. }
  340. }
  341. }
  342. // Third, check whether each enclosure itself is an appropriate image
  343. if (self::enclosureIsImage($enclosure)) {
  344. return $enclosure;
  345. }
  346. }
  347. }
  348. return null;
  349. }
  350. /**
  351. * @param bool $raw Set to true to return the raw link,
  352. * false (default) to attempt a fallback to the GUID if the link is empty.
  353. * @return string HTML-encoded link of the entry
  354. */
  355. public function link(bool $raw = false): string {
  356. if ($this->link === '' && !$raw) {
  357. // Use the GUID as a fallback if it looks like a URL
  358. if (filter_var($this->guid, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE) !== null) {
  359. return $this->guid;
  360. }
  361. }
  362. return $this->link;
  363. }
  364. /**
  365. * @phpstan-return ($raw is false ? string : int)
  366. */
  367. public function date(bool $raw = false): int|string {
  368. if ($raw) {
  369. return $this->date;
  370. }
  371. return timestamptodate($this->date);
  372. }
  373. public function machineReadableDate(): string {
  374. return @date(DATE_ATOM, $this->date);
  375. }
  376. public function lastSeen(): int {
  377. return $this->lastSeen;
  378. }
  379. /**
  380. * @phpstan-return ($raw is false ? string : ($microsecond is true ? string : int))
  381. */
  382. public function dateAdded(bool $raw = false, bool $microsecond = false): int|string {
  383. if ($raw) {
  384. if ($microsecond) {
  385. return $this->date_added;
  386. } else {
  387. return (int)substr($this->date_added, 0, -6);
  388. }
  389. } else {
  390. $date = (int)substr($this->date_added, 0, -6);
  391. return timestamptodate($date);
  392. }
  393. }
  394. public function isRead(): ?bool {
  395. return $this->is_read;
  396. }
  397. public function isFavorite(): ?bool {
  398. return $this->is_favorite;
  399. }
  400. /**
  401. * Returns whether the entry has been modified since it was inserted in database.
  402. * @returns bool `true` if the entry already existed (and has been modified), `false` if the entry is new (or unmodified).
  403. */
  404. public function isUpdated(): ?bool {
  405. return $this->is_updated;
  406. }
  407. public function _isUpdated(bool $value): void {
  408. $this->is_updated = $value;
  409. }
  410. public function feed(): ?FreshRSS_Feed {
  411. if ($this->feed === null) {
  412. $feedDAO = FreshRSS_Factory::createFeedDao();
  413. $this->feed = $feedDAO->searchById($this->feedId);
  414. }
  415. return $this->feed;
  416. }
  417. public function feedId(): int {
  418. return $this->feedId;
  419. }
  420. /**
  421. * @phpstan-return ($asString is true ? string : array<string>)
  422. * @return string|array<string>
  423. */
  424. public function tags(bool $asString = false): array|string {
  425. if ($asString) {
  426. return $this->tags == null ? '' : '#' . implode(' #', $this->tags);
  427. } else {
  428. return $this->tags;
  429. }
  430. }
  431. public function hash(): string {
  432. if ($this->hash === '') {
  433. //Do not include $this->date because it may be automatically generated when lacking
  434. $this->hash = md5($this->link . $this->title . $this->authors(true) . $this->originalContent() . $this->tags(true));
  435. }
  436. return $this->hash;
  437. }
  438. public function _hash(string $value): string {
  439. $value = trim($value);
  440. if (ctype_xdigit($value)) {
  441. $this->hash = substr($value, 0, 32);
  442. }
  443. return $this->hash;
  444. }
  445. /** @param int|numeric-string $value String is for compatibility with 32-bit platforms */
  446. public function _id($value): void {
  447. if (is_int($value)) {
  448. $value = (string)$value;
  449. }
  450. $this->id = $value;
  451. if ($this->date_added == 0) {
  452. $this->date_added = $value;
  453. }
  454. }
  455. public function _guid(string $value): void {
  456. $this->guid = trim($value);
  457. }
  458. public function _title(string $value): void {
  459. $this->hash = '';
  460. $this->title = trim($value);
  461. }
  462. /** @deprecated */
  463. public function _author(string $value): void {
  464. $this->_authors($value);
  465. }
  466. /** @param array<string>|string $value */
  467. public function _authors($value): void {
  468. $this->hash = '';
  469. if (!is_array($value)) {
  470. if (str_contains($value, ';')) {
  471. $value = htmlspecialchars_decode($value, ENT_QUOTES);
  472. $value = preg_split('/\s*[;]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
  473. $value = Minz_Helper::htmlspecialchars_utf8($value);
  474. } else {
  475. $value = preg_split('/\s*[,]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
  476. }
  477. }
  478. $this->authors = $value;
  479. }
  480. public function _content(string $value): void {
  481. $this->hash = '';
  482. $this->content = $value;
  483. }
  484. public function _link(string $value): void {
  485. $this->hash = '';
  486. $this->link = trim($value);
  487. }
  488. /** @param int|string $value */
  489. public function _date($value): void {
  490. $value = (int)$value;
  491. $this->date = $value > 1 ? $value : time();
  492. }
  493. public function _lastSeen(int $value): void {
  494. $this->lastSeen = $value > 0 ? $value : 0;
  495. }
  496. /** @param int|string $value */
  497. public function _dateAdded($value, bool $microsecond = false): void {
  498. if ($microsecond) {
  499. $this->date_added = (string)($value);
  500. } else {
  501. $this->date_added = $value . '000000';
  502. }
  503. }
  504. /** @param bool|int|null $value */
  505. public function _isRead($value): void {
  506. $this->is_read = $value === null ? null : (bool)$value;
  507. }
  508. /** @param bool|int|null $value */
  509. public function _isFavorite($value): void {
  510. $this->is_favorite = $value === null ? null : (bool)$value;
  511. }
  512. public function _feed(?FreshRSS_Feed $feed): void {
  513. $this->feed = $feed;
  514. $this->feedId = $this->feed == null ? 0 : $this->feed->id();
  515. }
  516. /** @param int|string $id */
  517. private function _feedId($id): void {
  518. $this->feed = null;
  519. $this->feedId = (int)$id;
  520. }
  521. /** @param array<string>|string $value */
  522. public function _tags($value): void {
  523. $this->hash = '';
  524. if (!is_array($value)) {
  525. $value = preg_split('/\s*[#,]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
  526. }
  527. $this->tags = $value;
  528. }
  529. public function matches(FreshRSS_BooleanSearch $booleanSearch): bool {
  530. $ok = true;
  531. foreach ($booleanSearch->searches() as $filter) {
  532. if ($filter instanceof FreshRSS_BooleanSearch) {
  533. // BooleanSearches are combined by AND (default) or OR or AND NOT (special cases) operators and are recursive
  534. match ($filter->operator()) {
  535. 'AND' => $ok &= $this->matches($filter),
  536. 'OR' => $ok |= $this->matches($filter),
  537. 'AND NOT' => $ok &= !$this->matches($filter),
  538. 'OR NOT' => $ok |= !$this->matches($filter),
  539. default => $ok &= $this->matches($filter),
  540. };
  541. } elseif ($filter instanceof FreshRSS_Search) {
  542. // Searches are combined by OR and are not recursive
  543. $ok = true;
  544. if ($filter->getEntryIds() !== null) {
  545. $ok &= in_array($this->id, $filter->getEntryIds(), true);
  546. }
  547. if ($ok && $filter->getNotEntryIds() !== null) {
  548. $ok &= !in_array($this->id, $filter->getNotEntryIds(), true);
  549. }
  550. if ($ok && $filter->getMinDate() !== null) {
  551. $ok &= strnatcmp($this->id, $filter->getMinDate() . '000000') >= 0;
  552. }
  553. if ($ok && $filter->getNotMinDate() !== null) {
  554. $ok &= strnatcmp($this->id, $filter->getNotMinDate() . '000000') < 0;
  555. }
  556. if ($ok && $filter->getMaxDate() !== null) {
  557. $ok &= strnatcmp($this->id, $filter->getMaxDate() . '000000') <= 0;
  558. }
  559. if ($ok && $filter->getNotMaxDate() !== null) {
  560. $ok &= strnatcmp($this->id, $filter->getNotMaxDate() . '000000') > 0;
  561. }
  562. if ($ok && $filter->getMinPubdate() !== null) {
  563. $ok &= $this->date >= $filter->getMinPubdate();
  564. }
  565. if ($ok && $filter->getNotMinPubdate() !== null) {
  566. $ok &= $this->date < $filter->getNotMinPubdate();
  567. }
  568. if ($ok && $filter->getMaxPubdate() !== null) {
  569. $ok &= $this->date <= $filter->getMaxPubdate();
  570. }
  571. if ($ok && $filter->getNotMaxPubdate() !== null) {
  572. $ok &= $this->date > $filter->getNotMaxPubdate();
  573. }
  574. if ($ok && $filter->getFeedIds() !== null) {
  575. $ok &= in_array($this->feedId, $filter->getFeedIds(), true);
  576. }
  577. if ($ok && $filter->getNotFeedIds() !== null) {
  578. $ok &= !in_array($this->feedId, $filter->getNotFeedIds(), true);
  579. }
  580. if ($ok && $filter->getAuthor() !== null) {
  581. foreach ($filter->getAuthor() as $author) {
  582. $ok &= stripos(implode(';', $this->authors), $author) !== false;
  583. }
  584. }
  585. if ($ok && $filter->getAuthorRegex() !== null) {
  586. foreach ($filter->getAuthorRegex() as $author) {
  587. $ok &= preg_match($author, implode("\n", $this->authors)) === 1;
  588. }
  589. }
  590. if ($ok && $filter->getNotAuthor() !== null) {
  591. foreach ($filter->getNotAuthor() as $author) {
  592. $ok &= stripos(implode(';', $this->authors), $author) === false;
  593. }
  594. }
  595. if ($ok && $filter->getNotAuthorRegex() !== null) {
  596. foreach ($filter->getNotAuthorRegex() as $author) {
  597. $ok &= preg_match($author, implode("\n", $this->authors)) === 0;
  598. }
  599. }
  600. if ($ok && $filter->getIntitle() !== null) {
  601. foreach ($filter->getIntitle() as $title) {
  602. $ok &= stripos($this->title, $title) !== false;
  603. }
  604. }
  605. if ($ok && $filter->getIntitleRegex() !== null) {
  606. foreach ($filter->getIntitleRegex() as $title) {
  607. $ok &= preg_match($title, $this->title) === 1;
  608. }
  609. }
  610. if ($ok && $filter->getNotIntitle() !== null) {
  611. foreach ($filter->getNotIntitle() as $title) {
  612. $ok &= stripos($this->title, $title) === false;
  613. }
  614. }
  615. if ($ok && $filter->getNotIntitleRegex() !== null) {
  616. foreach ($filter->getNotIntitleRegex() as $title) {
  617. $ok &= preg_match($title, $this->title) === 0;
  618. }
  619. }
  620. if ($ok && $filter->getTags() !== null) {
  621. foreach ($filter->getTags() as $tag2) {
  622. $found = false;
  623. foreach ($this->tags as $tag1) {
  624. $tag1 = ltrim($tag1, '#');
  625. if (strcasecmp($tag1, $tag2) === 0) {
  626. $found = true;
  627. break;
  628. }
  629. }
  630. $ok &= $found;
  631. }
  632. }
  633. if ($ok && $filter->getTagsRegex() !== null) {
  634. foreach ($filter->getTagsRegex() as $tag2) {
  635. $found = false;
  636. foreach ($this->tags as $tag1) {
  637. $tag1 = ltrim($tag1, '#');
  638. if (preg_match($tag2, $tag1) === 1) {
  639. $found = true;
  640. break;
  641. }
  642. }
  643. $ok &= $found;
  644. }
  645. }
  646. if ($ok && $filter->getNotTags() !== null) {
  647. foreach ($filter->getNotTags() as $tag2) {
  648. $found = false;
  649. foreach ($this->tags as $tag1) {
  650. $tag1 = ltrim($tag1, '#');
  651. if (strcasecmp($tag1, $tag2) === 0) {
  652. $found = true;
  653. break;
  654. }
  655. }
  656. $ok &= !$found;
  657. }
  658. }
  659. if ($ok && $filter->getNotTagsRegex() !== null) {
  660. foreach ($filter->getNotTagsRegex() as $tag2) {
  661. $found = false;
  662. foreach ($this->tags as $tag1) {
  663. $tag1 = ltrim($tag1, '#');
  664. if (preg_match($tag2, $tag1) === 1) {
  665. $found = true;
  666. break;
  667. }
  668. }
  669. $ok &= !$found;
  670. }
  671. }
  672. if ($ok && $filter->getInurl() !== null) {
  673. foreach ($filter->getInurl() as $url) {
  674. $ok &= stripos($this->link, $url) !== false;
  675. }
  676. }
  677. if ($ok && $filter->getInurlRegex() !== null) {
  678. foreach ($filter->getInurlRegex() as $url) {
  679. $ok &= preg_match($url, $this->link) === 1;
  680. }
  681. }
  682. if ($ok && $filter->getNotInurl() !== null) {
  683. foreach ($filter->getNotInurl() as $url) {
  684. $ok &= stripos($this->link, $url) === false;
  685. }
  686. }
  687. if ($ok && $filter->getNotInurlRegex() !== null) {
  688. foreach ($filter->getNotInurlRegex() as $url) {
  689. $ok &= preg_match($url, $this->link) === 0;
  690. }
  691. }
  692. if ($ok && $filter->getSearch() !== null) {
  693. foreach ($filter->getSearch() as $needle) {
  694. $ok &= (stripos($this->title, $needle) !== false || stripos($this->content, $needle) !== false);
  695. }
  696. }
  697. if ($ok && $filter->getNotSearch() !== null) {
  698. foreach ($filter->getNotSearch() as $needle) {
  699. $ok &= (stripos($this->title, $needle) === false && stripos($this->content, $needle) === false);
  700. }
  701. }
  702. if ($ok && $filter->getSearchRegex() !== null) {
  703. foreach ($filter->getSearchRegex() as $needle) {
  704. $ok &= (preg_match($needle, $this->title) === 1 || preg_match($needle, $this->content) === 1);
  705. }
  706. }
  707. if ($ok && $filter->getNotSearchRegex() !== null) {
  708. foreach ($filter->getNotSearchRegex() as $needle) {
  709. $ok &= (preg_match($needle, $this->title) === 0 && preg_match($needle, $this->content) === 0);
  710. }
  711. }
  712. if ($ok) {
  713. return true;
  714. }
  715. }
  716. }
  717. return (bool)$ok;
  718. }
  719. /** @param array<string,bool|int> $titlesAsRead */
  720. public function applyFilterActions(array $titlesAsRead = []): void {
  721. $feed = $this->feed;
  722. if ($feed === null) {
  723. return;
  724. }
  725. if (!$this->isRead()) {
  726. if ($feed->attributeBoolean('read_upon_reception') ?? FreshRSS_Context::userConf()->mark_when['reception']) {
  727. $this->_isRead(true);
  728. Minz_ExtensionManager::callHook('entry_auto_read', $this, 'upon_reception');
  729. }
  730. if (!empty($titlesAsRead[$this->title()])) {
  731. Minz_Log::debug('Mark title as read: ' . $this->title());
  732. $this->_isRead(true);
  733. Minz_ExtensionManager::callHook('entry_auto_read', $this, 'same_title_in_feed');
  734. }
  735. }
  736. FreshRSS_Context::userConf()->applyFilterActions($this);
  737. $feed->category()?->applyFilterActions($this);
  738. $feed->applyFilterActions($this);
  739. }
  740. public function isDay(int $day, int $today): bool {
  741. $date = $this->dateAdded(true);
  742. switch ($day) {
  743. case FreshRSS_Days::TODAY:
  744. $tomorrow = $today + 86400;
  745. return $date >= $today && $date < $tomorrow;
  746. case FreshRSS_Days::YESTERDAY:
  747. $yesterday = $today - 86400;
  748. return $date >= $yesterday && $date < $today;
  749. case FreshRSS_Days::BEFORE_YESTERDAY:
  750. $yesterday = $today - 86400;
  751. return $date < $yesterday;
  752. default:
  753. return false;
  754. }
  755. }
  756. /**
  757. * @param string $url Overridden URL. Will default to the entry URL.
  758. * @throws Minz_Exception
  759. */
  760. public function getContentByParsing(string $url = '', int $maxRedirs = 3): string {
  761. $url = $url ?: htmlspecialchars_decode($this->link(), ENT_QUOTES);
  762. $feed = $this->feed();
  763. if ($url === '' || $feed === null || $feed->pathEntries() === '') {
  764. return '';
  765. }
  766. if (!empty($feed->attributeArray('path_entries_condition'))) {
  767. $found = false;
  768. foreach ($feed->attributeArray('path_entries_condition') as $condition) {
  769. if (trim($condition) === '') {
  770. continue;
  771. }
  772. $booleanSearch = new FreshRSS_BooleanSearch($condition);
  773. if ($this->matches($booleanSearch)) {
  774. $found = true;
  775. break;
  776. }
  777. }
  778. if (!$found) {
  779. return '';
  780. }
  781. }
  782. $cachePath = $feed->cacheFilename($url . '#' . $feed->pathEntries());
  783. $html = httpGet($url, $cachePath, 'html', $feed->attributes(), $feed->curlOptions());
  784. if (strlen($html) > 0) {
  785. $doc = new DOMDocument();
  786. $doc->loadHTML($html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);
  787. $xpath = new DOMXPath($doc);
  788. if ($maxRedirs > 0) {
  789. //Follow any HTML redirection
  790. $metas = $xpath->query('//meta[@content]') ?: [];
  791. foreach ($metas as $meta) {
  792. if ($meta instanceof DOMElement && strtolower(trim($meta->getAttribute('http-equiv'))) === 'refresh') {
  793. $refresh = preg_replace('/^[0-9.; ]*\s*(url\s*=)?\s*/i', '', trim($meta->getAttribute('content')));
  794. $refresh = is_string($refresh) ? \SimplePie\Misc::absolutize_url($refresh, $url) : false;
  795. if ($refresh != false && $refresh !== $url) {
  796. return $this->getContentByParsing($refresh, $maxRedirs - 1);
  797. }
  798. }
  799. }
  800. }
  801. $base = $xpath->evaluate('normalize-space(//base/@href)');
  802. if ($base == false || !is_string($base)) {
  803. $base = $url;
  804. } elseif (str_starts_with($base, '//')) {
  805. //Protocol-relative URLs "//www.example.net"
  806. $base = (parse_url($url, PHP_URL_SCHEME) ?? 'https') . ':' . $base;
  807. }
  808. unset($xpath, $doc);
  809. $html = sanitizeHTML($html, $base);
  810. $doc = new DOMDocument();
  811. $utf8BOM = "\xEF\xBB\xBF";
  812. $doc->loadHTML($utf8BOM . $html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);
  813. $xpath = new DOMXPath($doc);
  814. $html = '';
  815. $cssSelector = htmlspecialchars_decode($feed->pathEntries(), ENT_QUOTES);
  816. $cssSelector = trim($cssSelector, ', ');
  817. $nodes = $xpath->query((new Gt\CssXPath\Translator($cssSelector, '//'))->asXPath());
  818. if ($nodes != false) {
  819. $path_entries_filter = trim($feed->attributeString('path_entries_filter') ?? '');
  820. $filter_xpath = $path_entries_filter === '' ? '' : (new Gt\CssXPath\Translator($path_entries_filter, 'descendant-or-self::'))->asXPath();
  821. foreach ($nodes as $node) {
  822. if ($filter_xpath !== '') {
  823. $filterednodes = $xpath->query($filter_xpath, $node) ?: [];
  824. foreach ($filterednodes as $filterednode) {
  825. if ($filterednode === $node) {
  826. continue 2;
  827. }
  828. if (!($filterednode instanceof DOMElement) || $filterednode->parentNode === null) {
  829. continue;
  830. }
  831. $filterednode->parentNode->removeChild($filterednode);
  832. }
  833. }
  834. $html .= $doc->saveHTML($node) . "\n";
  835. }
  836. }
  837. return trim($html);
  838. } else {
  839. throw new Minz_Exception();
  840. }
  841. }
  842. /**
  843. * @return bool True if the content was modified, false otherwise
  844. */
  845. public function loadCompleteContent(bool $force = false): bool {
  846. // Gestion du contenu
  847. // Trying to fetch full article content even when feeds do not propose it
  848. $feed = $this->feed();
  849. if ($feed === null) {
  850. return false;
  851. }
  852. if (trim($feed->pathEntries()) != '') {
  853. $entryDAO = FreshRSS_Factory::createEntryDao();
  854. $entry = $force ? null : $entryDAO->searchByGuid($this->feedId, $this->guid);
  855. if ($entry !== null) {
  856. // l’article existe déjà en BDD, en se contente de recharger ce contenu
  857. $this->content = $entry->content(false);
  858. } else {
  859. try {
  860. // The article is not yet in the database, so let’s fetch it
  861. $fullContent = $this->getContentByParsing();
  862. if ('' !== $fullContent) {
  863. $fullContent = "<!-- FULLCONTENT start //-->{$fullContent}<!-- FULLCONTENT end //-->";
  864. $originalContent = $this->originalContent();
  865. switch ($feed->attributeString('content_action')) {
  866. case 'prepend':
  867. $this->_attribute('original_content');
  868. $this->content = $fullContent . $originalContent;
  869. break;
  870. case 'append':
  871. $this->_attribute('original_content');
  872. $this->content = $originalContent . $fullContent;
  873. break;
  874. case 'replace':
  875. default:
  876. $this->_attribute('original_content', $originalContent);
  877. $this->content = $fullContent;
  878. break;
  879. }
  880. return true;
  881. }
  882. } catch (Exception $e) {
  883. // rien à faire, on garde l’ancien contenu(requête a échoué)
  884. Minz_Log::warning($e->getMessage());
  885. }
  886. }
  887. } elseif (trim($feed->attributeString('path_entries_filter') ?? '') !== '') {
  888. $originalContent = $this->attributeString('original_content') ?? $this->content;
  889. $doc = new DOMDocument();
  890. $utf8BOM = "\xEF\xBB\xBF";
  891. if (!$doc->loadHTML($utf8BOM . $originalContent, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING)) {
  892. return false;
  893. }
  894. $xpath = new DOMXPath($doc);
  895. $filterednodes = $xpath->query((new Gt\CssXPath\Translator($feed->attributeString('path_entries_filter') ?? '', '//'))->asXPath()) ?: [];
  896. foreach ($filterednodes as $filterednode) {
  897. if (!($filterednode instanceof DOMElement) || $filterednode->parentNode === null) {
  898. continue;
  899. }
  900. $filterednode->parentNode->removeChild($filterednode);
  901. }
  902. $html = $doc->saveHTML($doc->getElementsByTagName('body')->item(0) ?? $doc->firstElementChild);
  903. if (!is_string($html)) {
  904. return false;
  905. }
  906. $html = preg_replace('%^\s*<body>\s*|\s*</body>\s*$%i', '', $html);
  907. $this->_attribute('original_content');
  908. if (is_string($html) && $this->content !== $html) {
  909. $this->_attribute('original_content', $originalContent);
  910. $this->content = $html;
  911. return true;
  912. }
  913. } else {
  914. $originalContent = $this->originalContent();
  915. if ($originalContent !== $this->content) {
  916. $this->content = $originalContent;
  917. return true;
  918. }
  919. }
  920. return false;
  921. }
  922. /**
  923. * @return array{'id':string,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,'lastSeen':int,
  924. * 'hash':string,'is_read':?bool,'is_favorite':?bool,'id_feed':int,'tags':string,'attributes':array<string,mixed>}
  925. */
  926. public function toArray(): array {
  927. return [
  928. 'id' => $this->id(),
  929. 'guid' => $this->guid(),
  930. 'title' => $this->title(),
  931. 'author' => $this->authors(true),
  932. 'content' => $this->content(false),
  933. 'link' => $this->link(raw: true),
  934. 'date' => $this->date(true),
  935. 'lastSeen' => $this->lastSeen(),
  936. 'hash' => $this->hash(),
  937. 'is_read' => $this->isRead(),
  938. 'is_favorite' => $this->isFavorite(),
  939. 'id_feed' => $this->feedId(),
  940. 'tags' => $this->tags(true),
  941. 'attributes' => $this->attributes(),
  942. ];
  943. }
  944. /**
  945. * @return array{array<string>,array<string>} Array of first tags to show, then array of remaining tags
  946. */
  947. public function tagsFormattingHelper(): array {
  948. $firstTags = [];
  949. $remainingTags = [];
  950. if (FreshRSS_Context::hasUserConf() && in_array(FreshRSS_Context::userConf()->show_tags, ['b', 'f', 'h'], true)) {
  951. $maxTagsDisplayed = (int)FreshRSS_Context::userConf()->show_tags_max;
  952. $tags = $this->tags();
  953. if (!empty($tags)) {
  954. if ($maxTagsDisplayed > 0) {
  955. $firstTags = array_slice($tags, 0, $maxTagsDisplayed);
  956. $remainingTags = array_slice($tags, $maxTagsDisplayed);
  957. } else {
  958. $firstTags = $tags;
  959. }
  960. }
  961. }
  962. return [$firstTags,$remainingTags];
  963. }
  964. /**
  965. * Integer format conversion for Google Reader API format
  966. * @param numeric-string|int $dec Decimal number
  967. * @return string 64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
  968. */
  969. private static function dec2hex($dec): string {
  970. return PHP_INT_SIZE < 8 ? // 32-bit ?
  971. str_pad(gmp_strval(gmp_init($dec, 10), 16), 16, '0', STR_PAD_LEFT) :
  972. str_pad(dechex((int)($dec)), 16, '0', STR_PAD_LEFT);
  973. }
  974. /**
  975. * Some clients (tested with News+) would fail if sending too long item content
  976. * @var int
  977. */
  978. public const API_MAX_COMPAT_CONTENT_LENGTH = 500000;
  979. /**
  980. * N.B.: To avoid expensive lookups, ensure to set `$entry->_feed($feed)` before calling this function.
  981. * @param string $mode Set to `'compat'` to use an alternative Unicode representation for problematic HTML special characters not decoded by some clients;
  982. * set to `'freshrss'` for using FreshRSS additions for internal use (e.g. export/import).
  983. * @param array<string> $labels List of labels associated to this entry.
  984. * @return array<string,mixed> A representation of this entry in a format compatible with Google Reader API
  985. */
  986. public function toGReader(string $mode = '', array $labels = []): array {
  987. $feed = $this->feed();
  988. $category = $feed == null ? null : $feed->category();
  989. $item = [
  990. 'id' => 'tag:google.com,2005:reader/item/' . self::dec2hex($this->id()),
  991. 'crawlTimeMsec' => substr($this->dateAdded(true, true), 0, -3),
  992. 'timestampUsec' => '' . $this->dateAdded(true, true), //EasyRSS & Reeder
  993. 'published' => $this->date(true),
  994. // 'updated' => $this->date(true),
  995. 'title' => $this->title(),
  996. 'canonical' => [
  997. ['href' => htmlspecialchars_decode($this->link(), ENT_QUOTES)],
  998. ],
  999. 'alternate' => [
  1000. [
  1001. 'href' => htmlspecialchars_decode($this->link(), ENT_QUOTES),
  1002. 'type' => 'text/html',
  1003. ],
  1004. ],
  1005. 'categories' => [
  1006. 'user/-/state/com.google/reading-list',
  1007. ],
  1008. 'origin' => [
  1009. 'streamId' => 'feed/' . $this->feedId,
  1010. ],
  1011. ];
  1012. if ($mode === 'compat') {
  1013. $item['title'] = escapeToUnicodeAlternative($this->title(), false);
  1014. unset($item['alternate'][0]['type']);
  1015. $item['summary'] = [
  1016. 'content' => mb_strcut($this->content(true), 0, self::API_MAX_COMPAT_CONTENT_LENGTH, 'UTF-8'),
  1017. ];
  1018. } else {
  1019. $item['content'] = [
  1020. 'content' => $this->content(false),
  1021. ];
  1022. }
  1023. if ($mode === 'freshrss') {
  1024. $item['guid'] = $this->guid();
  1025. }
  1026. if ($category != null && $mode !== 'freshrss') {
  1027. $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($category->name(), ENT_QUOTES);
  1028. }
  1029. if ($feed !== null) {
  1030. $item['origin']['htmlUrl'] = htmlspecialchars_decode($feed->website());
  1031. $item['origin']['title'] = $feed->name(); //EasyRSS
  1032. if ($mode === 'compat') {
  1033. $item['origin']['title'] = escapeToUnicodeAlternative($feed->name(), true);
  1034. } elseif ($mode === 'freshrss') {
  1035. $item['origin']['feedUrl'] = htmlspecialchars_decode($feed->url());
  1036. }
  1037. }
  1038. foreach ($this->enclosures() as $enclosure) {
  1039. if (!empty($enclosure['url'])) {
  1040. $media = [
  1041. 'href' => $enclosure['url'],
  1042. 'type' => $enclosure['type'] ?? $enclosure['medium'] ??
  1043. (self::enclosureIsImage($enclosure) ? 'image' : ''),
  1044. ];
  1045. if (!empty($enclosure['length'])) {
  1046. $media['length'] = (int)$enclosure['length'];
  1047. }
  1048. $item['enclosure'][] = $media;
  1049. }
  1050. }
  1051. $author = $this->authors(true);
  1052. $author = trim($author, '; ');
  1053. if ($author != '') {
  1054. if ($mode === 'compat') {
  1055. $item['author'] = escapeToUnicodeAlternative($author, false);
  1056. } else {
  1057. $item['author'] = $author;
  1058. }
  1059. }
  1060. if ($this->isRead()) {
  1061. $item['categories'][] = 'user/-/state/com.google/read';
  1062. } elseif ($mode === 'freshrss') {
  1063. $item['categories'][] = 'user/-/state/com.google/unread';
  1064. }
  1065. if ($this->isFavorite()) {
  1066. $item['categories'][] = 'user/-/state/com.google/starred';
  1067. }
  1068. foreach ($labels as $labelName) {
  1069. $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($labelName, ENT_QUOTES);
  1070. }
  1071. foreach ($this->tags() as $tagName) {
  1072. $item['categories'][] = htmlspecialchars_decode($tagName, ENT_QUOTES);
  1073. }
  1074. return $item;
  1075. }
  1076. }