Move OPML export to handlers

This commit is contained in:
Frederic Guillot 2016-08-23 21:38:09 -04:00
parent 05af9d0d4d
commit b05ad87028
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
7 changed files with 40 additions and 31 deletions

View File

@ -226,7 +226,7 @@ Router\action('subscribe', function () {
// OPML export // OPML export
Router\get_action('export', function () { Router\get_action('export', function () {
Response\force_download('feeds.opml'); Response\force_download('feeds.opml');
Response\xml(Model\Feed\export_opml()); Response\xml(Handler\Opml\export_all_feeds());
}); });
// OPML import form // OPML import form

34
app/handlers/opml.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace Handler\Opml;
use Model\Feed;
use Model\Group;
use PicoFeed\Serialization\Subscription;
use PicoFeed\Serialization\SubscriptionList;
use PicoFeed\Serialization\SubscriptionListBuilder;
function export_all_feeds()
{
$feeds = Feed\get_all();
$subscriptionList = SubscriptionList::create()->setTitle(t('Subscriptions'));
foreach ($feeds as $feed) {
$groups = Group\get_feed_groups($feed['id']);
$category = '';
if (!empty($groups)) {
$category = $groups[0]['title'];
}
$subscriptionList->addSubscription(Subscription::create()
->setTitle($feed['title'])
->setSiteUrl($feed['site_url'])
->setFeedUrl($feed['feed_url'])
->setCategory($category)
);
}
return SubscriptionListBuilder::create($subscriptionList)->build();
}

View File

@ -2,9 +2,6 @@
namespace Model\Feed; namespace Model\Feed;
use PicoFeed\Serialization\Subscription;
use PicoFeed\Serialization\SubscriptionList;
use PicoFeed\Serialization\SubscriptionListBuilder;
use PicoFeed\Serialization\SubscriptionListParser; use PicoFeed\Serialization\SubscriptionListParser;
use UnexpectedValueException; use UnexpectedValueException;
use Model\Config; use Model\Config;
@ -51,31 +48,6 @@ function update(array $values)
return $result; return $result;
} }
// Export all feeds
function export_opml()
{
$feeds = get_all();
$subscriptionList = SubscriptionList::create()->setTitle(t('Subscriptions'));
foreach ($feeds as $feed) {
$groups = Group\get_feed_groups($feed['id']);
$category = '';
if (!empty($groups)) {
$category = $groups[0]['title'];
}
$subscriptionList->addSubscription(Subscription::create()
->setTitle($feed['title'])
->setSiteUrl($feed['site_url'])
->setFeedUrl($feed['feed_url'])
->setCategory($category)
);
}
return SubscriptionListBuilder::create($subscriptionList)->build();
}
// Import OPML file // Import OPML file
function import_opml($content) function import_opml($content)
{ {

View File

@ -29,8 +29,8 @@ function version_43(PDO $pdo)
CREATE TABLE "favicons_feeds" ( CREATE TABLE "favicons_feeds" (
feed_id INTEGER NOT NULL, feed_id INTEGER NOT NULL,
favicon_id INTEGER NOT NULL, favicon_id INTEGER NOT NULL,
PRIMARY KEY(feed_id, favicon_id) PRIMARY KEY(feed_id, favicon_id),
FOREIGN KEY(favicon_id) REFERENCES favicons(id) ON DELETE CASCADE FOREIGN KEY(favicon_id) REFERENCES favicons(id) ON DELETE CASCADE,
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE
) )
'); ');

View File

@ -40,6 +40,7 @@
"app/core/template.php", "app/core/template.php",
"app/handlers/scraper.php", "app/handlers/scraper.php",
"app/handlers/service.php", "app/handlers/service.php",
"app/handlers/opml.php",
"app/handlers/proxy.php", "app/handlers/proxy.php",
"app/models/config.php", "app/models/config.php",
"app/models/search.php", "app/models/search.php",

View File

@ -21,6 +21,7 @@ return array(
'93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php', '93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php',
'9de087554be89ca71a2ed558a4e35fde' => $baseDir . '/app/handlers/scraper.php', '9de087554be89ca71a2ed558a4e35fde' => $baseDir . '/app/handlers/scraper.php',
'45d63f4d04cfb927b889e126b91aa553' => $baseDir . '/app/handlers/service.php', '45d63f4d04cfb927b889e126b91aa553' => $baseDir . '/app/handlers/service.php',
'bf8c8992b55a0d6166f67a273960030e' => $baseDir . '/app/handlers/opml.php',
'081a26ac825aa2a7e4cb00c18e0510d5' => $baseDir . '/app/handlers/proxy.php', '081a26ac825aa2a7e4cb00c18e0510d5' => $baseDir . '/app/handlers/proxy.php',
'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php',
'b59348c9973f21f2c58eb493d9fea5be' => $baseDir . '/app/models/search.php', 'b59348c9973f21f2c58eb493d9fea5be' => $baseDir . '/app/models/search.php',

View File

@ -22,6 +22,7 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4
'93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php', '93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php',
'9de087554be89ca71a2ed558a4e35fde' => __DIR__ . '/../..' . '/app/handlers/scraper.php', '9de087554be89ca71a2ed558a4e35fde' => __DIR__ . '/../..' . '/app/handlers/scraper.php',
'45d63f4d04cfb927b889e126b91aa553' => __DIR__ . '/../..' . '/app/handlers/service.php', '45d63f4d04cfb927b889e126b91aa553' => __DIR__ . '/../..' . '/app/handlers/service.php',
'bf8c8992b55a0d6166f67a273960030e' => __DIR__ . '/../..' . '/app/handlers/opml.php',
'081a26ac825aa2a7e4cb00c18e0510d5' => __DIR__ . '/../..' . '/app/handlers/proxy.php', '081a26ac825aa2a7e4cb00c18e0510d5' => __DIR__ . '/../..' . '/app/handlers/proxy.php',
'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php',
'b59348c9973f21f2c58eb493d9fea5be' => __DIR__ . '/../..' . '/app/models/search.php', 'b59348c9973f21f2c58eb493d9fea5be' => __DIR__ . '/../..' . '/app/models/search.php',