', namespaceOrPrefix: 'http://xmlpull.org/v1/doc/features.html#indent-output'); $xml->addAttribute('version', '2.0'); $dateCreated = new \DateTime(); $head = $xml->addChild('head'); if (isset($head)) { $head->addChild('title', $this->l10n->t('RePod Subscriptions')); $head->addChild('dateCreated', $dateCreated->format(\DateTime::RFC822)); } $body = $xml->addChild('body'); if (isset($body)) { $subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID()); foreach ($subscriptions as $subscription) { try { $podcast = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID()); } catch (\Exception) { continue; } if ($podcast) { $outline = $body->addChild('outline'); if (isset($outline)) { $outline->addAttribute('xmlUrl', $subscription->getUrl()); $title = $podcast->getTitle(); $link = $podcast->getLink(); if (isset($title)) { $outline->addAttribute('text', $title); $outline->addAttribute('title', $title); } if (isset($link)) { $outline->addAttribute('htmlUrl', $link); } } } } } return new DataDownloadResponse((string) $xml->asXML(), 'repod-'.$dateCreated->getTimestamp().'.opml', ' application/xml'); } #[NoAdminRequired] #[NoCSRFRequired] #[FrontpageRoute(verb: 'POST', url: '/opml/import')] public function import(): Response { $file = $this->request->getUploadedFile('import'); if ($file) { $xml = new \SimpleXMLElement(file_get_contents((string) $file['tmp_name'])); /** @var \SimpleXMLElement[] $outlines */ $outlines = $xml->body->children(); $toSubscribe = []; foreach ($outlines as $outline) { $toSubscribe[] = (string) $outline['xmlUrl']; } $this->subscriptionChangeSaver->saveSubscriptionChanges($toSubscribe, [], $this->userService->getUserUID()); } return new Response(); } }