miniflux-legacy/vendor/PicoFeed/Export.php

90 lines
1.9 KiB
PHP
Raw Normal View History

2013-02-18 03:48:21 +01:00
<?php
namespace PicoFeed;
2014-05-20 20:20:27 +02:00
use SimpleXMLElement;
/**
* OPML export class
*
* @author Frederic Guillot
* @package picofeed
*/
2013-02-18 03:48:21 +01:00
class Export
{
2014-05-20 20:20:27 +02:00
/**
* List of feeds to exports
*
* @access private
* @var array
*/
2013-02-18 03:48:21 +01:00
private $content = array();
2014-05-20 20:20:27 +02:00
/**
* List of required properties for each feed
*
* @access private
* @var array
*/
private $required_fields = array(
'title',
'site_url',
2014-05-20 20:20:27 +02:00
'feed_url',
);
2014-05-20 20:20:27 +02:00
/**
* Constructor
*
* @access public
* @param array $content List of feeds
*/
2013-02-18 03:48:21 +01:00
public function __construct(array $content)
{
$this->content = $content;
}
2014-05-20 20:20:27 +02:00
/**
* Get the OPML document
*
* @access public
* @return string
*/
2013-02-18 03:48:21 +01:00
public function execute()
{
2014-05-20 20:20:27 +02:00
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><opml/>');
2013-02-18 03:48:21 +01:00
$head = $xml->addChild('head');
$head->addChild('title', 'OPML Export');
$body = $xml->addChild('body');
foreach ($this->content as $feed) {
$valid = true;
foreach ($this->required_fields as $field) {
if (! isset($feed[$field])) {
$valid = false;
break;
}
}
2014-05-20 20:20:27 +02:00
if (! $valid) {
continue;
}
2013-02-18 03:48:21 +01:00
$outline = $body->addChild('outline');
$outline->addAttribute('xmlUrl', $feed['feed_url']);
$outline->addAttribute('htmlUrl', $feed['site_url']);
$outline->addAttribute('title', $feed['title']);
$outline->addAttribute('text', $feed['title']);
$outline->addAttribute('description', isset($feed['description']) ? $feed['description'] : $feed['title']);
$outline->addAttribute('type', 'rss');
$outline->addAttribute('version', 'RSS');
}
return $xml->asXML();
}
2014-05-20 20:20:27 +02:00
}