| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * @param array<FreshRSS_Feed> $feeds
- * @return array<array<string,string|null>>
- */
- function feedsToOutlines(array $feeds, bool $excludeMutedFeeds = false): array {
- $outlines = [];
- foreach ($feeds as $feed) {
- if ($feed->mute() && $excludeMutedFeeds) {
- continue;
- }
- $outline = [
- 'text' => htmlspecialchars_decode($feed->name(), ENT_QUOTES),
- 'type' => FreshRSS_Export_Service::TYPE_RSS_ATOM,
- 'xmlUrl' => htmlspecialchars_decode($feed->url(), ENT_QUOTES),
- 'htmlUrl' => htmlspecialchars_decode($feed->website(), ENT_QUOTES),
- 'description' => htmlspecialchars_decode($feed->description(), ENT_QUOTES),
- ];
- if ($feed->kind() === FreshRSS_Feed::KIND_HTML_XPATH || $feed->kind() === FreshRSS_Feed::KIND_XML_XPATH) {
- switch ($feed->kind()) {
- case FreshRSS_Feed::KIND_HTML_XPATH:
- $outline['type'] = FreshRSS_Export_Service::TYPE_HTML_XPATH;
- break;
- case FreshRSS_Feed::KIND_XML_XPATH:
- $outline['type'] = FreshRSS_Export_Service::TYPE_XML_XPATH;
- break;
- }
- /** @var array<string,string> */
- $xPathSettings = $feed->attributes('xpath');
- $outline['frss:xPathItem'] = $xPathSettings['item'] ?? null;
- $outline['frss:xPathItemTitle'] = $xPathSettings['itemTitle'] ?? null;
- $outline['frss:xPathItemContent'] = $xPathSettings['itemContent'] ?? null;
- $outline['frss:xPathItemUri'] = $xPathSettings['itemUri'] ?? null;
- $outline['frss:xPathItemAuthor'] = $xPathSettings['itemAuthor'] ?? null;
- $outline['frss:xPathItemTimestamp'] = $xPathSettings['itemTimestamp'] ?? null;
- $outline['frss:xPathItemTimeformat'] = $xPathSettings['itemTimeformat'] ?? null;
- $outline['frss:xPathItemThumbnail'] = $xPathSettings['itemThumbnail'] ?? null;
- $outline['frss:xPathItemCategories'] = $xPathSettings['itemCategories'] ?? null;
- $outline['frss:xPathItemUid'] = $xPathSettings['itemUid'] ?? null;
- }
- if (!empty($feed->filtersAction('read'))) {
- $filters = '';
- foreach ($feed->filtersAction('read') as $filterRead) {
- $filters .= $filterRead->getRawInput() . "\n";
- }
- $filters = trim($filters);
- $outline['frss:filtersActionRead'] = $filters;
- }
- if ($feed->pathEntries() != '') {
- $outline['frss:cssFullContent'] = htmlspecialchars_decode($feed->pathEntries(), ENT_QUOTES);
- }
- if ($feed->attributes('path_entries_filter') != '') {
- $outline['frss:cssFullContentFilter'] = $feed->attributes('path_entries_filter');
- }
- $outlines[] = $outline;
- }
- return $outlines;
- }
- /** @var FreshRSS_View $this */
- $opml_array = [
- 'namespaces' => [
- 'frss' => FreshRSS_Export_Service::FRSS_NAMESPACE,
- ],
- 'head' => [
- 'title' => FreshRSS_Context::$system_conf->title,
- 'dateCreated' => new DateTime(),
- ],
- 'body' => [],
- ];
- if (!empty($this->categories)) {
- foreach ($this->categories as $cat) {
- $outline = [
- 'text' => htmlspecialchars_decode($cat->name(), ENT_QUOTES),
- '@outlines' => feedsToOutlines($cat->feeds(), $this->excludeMutedFeeds),
- ];
- if ($cat->kind() === FreshRSS_Category::KIND_DYNAMIC_OPML) {
- $outline['frss:opmlUrl'] = $cat->attributes('opml_url');
- }
- $opml_array['body'][] = $outline;
- }
- }
- if (!empty($this->feeds)) {
- $opml_array['body'] = array_merge($opml_array['body'], feedsToOutlines($this->feeds, $this->excludeMutedFeeds));
- }
- $libopml = new \marienfressinaud\LibOpml\LibOpml(true);
- $opml = $libopml->render($opml_array);
- /** @var string $opml */
- echo $opml;
|