Skip to content

Commit

Permalink
feat(podcastindex): add rss tag podcast:person on item
Browse files Browse the repository at this point in the history
  • Loading branch information
eteubert committed Feb 24, 2021
1 parent d3ce9d1 commit 08d5242
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/modules/contributors/contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ public static function orderContributions($contributions, $args)
// Order by via attribute comperator
if (isset($args['orderby'])) {
$comperareFunc = null;

switch (strtoupper($args['orderby'])) {
case 'COMMENT':
$comperareFunc = 'Podlove\\Modules\\Contributors\\Model\\EpisodeContribution::sortByComment';

break;

case 'POSITION':
$comperareFunc = 'Podlove\\Modules\\Contributors\\Model\\EpisodeContribution::sortByPosition';

Expand Down Expand Up @@ -888,9 +890,14 @@ private function prepare_contributions_for_feed($raw_contributions, $feed)
$contributions = apply_filters('podlove_feed_contributions', $contributions, $feed);

$contributor_xml = '';
// atom:contributor
foreach ($contributions as $contribution) {
$contributor_xml .= $this->getContributorXML($contribution['contributor']);
}
// podcast:person
foreach ($contributions as $contribution) {
$contributor_xml .= $this->getPodcastindexContributorXML($contribution['contributor'], $contribution['contribution']);
}

return $contributor_xml;
}
Expand Down Expand Up @@ -923,4 +930,66 @@ private function getContributorXML($contributor)

return $contributor_xml;
}

/**
* get contributor xml in podcastindex "person" format.
*
* @todo take first social URL and add it as href attribute
*
* @see https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#person
*
* @param mixed $contributor
* @param mixed $contribution
*/
private function getPodcastindexContributorXML($contributor, $contribution)
{
$contributor_xml = '';

if ($contributor->visibility == 1) {
$dom = new \Podlove\DomDocumentFragment();

$xml = $dom->createElement('podcast:person');

$name_text = $dom->createTextNode($contributor->getName());
$xml->appendChild($name_text);

$dom->appendChild($xml);

$xml->setAttribute('img', $contributor->avatar()->url());

// proof of concept for roles/groups
// next implementation should fully support all options
// @see https://github.com/Podcastindex-org/podcast-namespace/blob/main/taxonomy.json
if ($role = $contribution->getRole()) {
$role_title = strtolower($role->title);

switch ($role_title) {
case 'guest':
case 'gast':
$matching_role = 'guest';

break;

case 'host':
case 'team':
$matching_role = 'host';

break;

default:
$matching_role = null;

break;
}

if ($matching_role) {
$xml->setAttribute('role', $matching_role);
}
}

$contributor_xml .= (string) $dom;
}

return $contributor_xml;
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ This product includes GeoLite2 data created by MaxMind, available from http://ww
= 2021-02-24 =

* podcastindex namespace: add support for feed tag [`podcast:transcript`](https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#transcript), linking to the transcript in various formats (json, webvtt, xml)
* podcastindex namespace: add support for feed tag [`podcast:person`](https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#person) on episode level

= 2021-02-22 =

Expand Down

0 comments on commit 08d5242

Please sign in to comment.