You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
<?php
|
|
/** @license MIT
|
|
* Copyright 2018 J. King et al.
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
declare(strict_types=1);
|
|
namespace JKingWeb\Lax\XML;
|
|
|
|
trait XMLFeedPrimitives {
|
|
|
|
/** Primitive to fetch an Atom feed summary
|
|
*
|
|
* Atom does not have a 'description' element like the RSSes, but it does have 'subtitle', which fills roughly the same function
|
|
*/
|
|
protected function getSummaryAtom() {
|
|
return $this->fetchTextAtom("atom:subtitle");
|
|
}
|
|
|
|
/** Primitive to fetch an RSS feed summary */
|
|
protected function getSummaryRss2() {
|
|
return $this->fetchText("description");
|
|
}
|
|
|
|
/** Primitive to fetch an RDF feed summary */
|
|
protected function getSummaryRss1() {
|
|
return $this->fetchText("rss1:description|rss0:description");
|
|
}
|
|
|
|
/** Primitive to fetch a Dublin Core feed summary */
|
|
protected function getSummaryDC() {
|
|
return $this->fetchText("dc:description");
|
|
}
|
|
|
|
/** Primitive to fetch a podcast summary */
|
|
protected function getSummaryPod() {
|
|
return $this->fetchText("apple:summary|gplay:description") ?? $this->fetchText("apple:subtitle");
|
|
}
|
|
|
|
/** Primitive to fetch a collection of people associated with an RSS feed */
|
|
protected function getPeopleRss2() {
|
|
$nodes = $this->fetchElements("managingEditor|webMaster|author");
|
|
if (!$nodes->length) {
|
|
return null;
|
|
}
|
|
$out = new PersonCollection;
|
|
$roles = [
|
|
'managingEditor' => "editor",
|
|
'webMaster' => "webmaster",
|
|
'author' => "author",
|
|
];
|
|
foreach ($nodes as $node) {
|
|
$text = $this->trimText($node->textContent);
|
|
if (strlen($text)) {
|
|
$p = $this->parsePersonText($text);
|
|
$p->role = $roles[$node->localName];
|
|
$out[] = $p;
|
|
}
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
/** Primitive to fetch a collection of people associated with an Atom feed */
|
|
protected function getPeopleAtom() {
|
|
$nodes = $this->fetchElements("atom:author|atom:contributor");
|
|
if (!$nodes->length) {
|
|
return null;
|
|
}
|
|
$out = new PersonCollection;
|
|
foreach ($nodes as $node) {
|
|
$p = $this->parsePersonAtom($node);
|
|
if ($p) {
|
|
$out[] = $p;
|
|
}
|
|
}
|
|
return $out;
|
|
}
|
|
}
|
|
|