mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-04-09 17:07:42 -04:00
Export is fully implemented
- Export list of feeds (OPML) - Export list of favourites (JSON) - Export list of articles per feed (JSON)
This commit is contained in:
@@ -13,16 +13,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
|
||||
}
|
||||
|
||||
public function indexAction() {
|
||||
$catDAO = new FreshRSS_CategoryDAO ();
|
||||
$this->view->categories = $catDAO->listCategories ();
|
||||
$catDAO = new FreshRSS_CategoryDAO();
|
||||
$this->view->categories = $catDAO->listCategories();
|
||||
|
||||
$feedDAO = new FreshRSS_FeedDAO ();
|
||||
$this->view->feeds = $feedDAO->listFeeds ();
|
||||
$feedDAO = new FreshRSS_FeedDAO();
|
||||
$this->view->feeds = $feedDAO->listFeeds();
|
||||
|
||||
// au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
|
||||
$this->view->flux = false;
|
||||
|
||||
Minz_View::prependTitle (Minz_Translate::t ('import_export') . ' · ');
|
||||
Minz_View::prependTitle(Minz_Translate::t('import_export') . ' · ');
|
||||
}
|
||||
|
||||
public function importAction() {
|
||||
@@ -62,7 +62,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
|
||||
|
||||
$export_opml = Minz_Request::param('export_opml', false);
|
||||
$export_starred = Minz_Request::param('export_starred', false);
|
||||
$export_all = Minz_Request::param('export_all', false);
|
||||
$export_feeds = Minz_Request::param('export_feeds', false);
|
||||
|
||||
// code from https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly
|
||||
$file = tempnam('tmp', 'zip');
|
||||
@@ -76,11 +76,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
|
||||
if ($export_starred) {
|
||||
$zip->addFromString('starred.json', $this->generate_articles('starred'));
|
||||
}
|
||||
if ($export_all) {
|
||||
$zip->addFromString('all.json', $this->generate_articles('all'));
|
||||
$feedDAO = new FreshRSS_FeedDAO ();
|
||||
foreach ($export_feeds as $feed_id) {
|
||||
$feed = $feedDAO->searchById($feed_id);
|
||||
$zip->addFromString(
|
||||
'feed_' . $feed->category() . '_' . $feed->id() . '.json',
|
||||
$this->generate_articles('feed', $feed)
|
||||
);
|
||||
}
|
||||
|
||||
// Close and send to users
|
||||
// Close and send to user
|
||||
$zip->close();
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-Length: ' . filesize($file));
|
||||
@@ -104,8 +109,28 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
|
||||
return $this->view->helperToString('export/opml');
|
||||
}
|
||||
|
||||
private function generate_articles($type) {
|
||||
// TODO: we should get articles according to $type
|
||||
private function generate_articles($type, $feed = NULL) {
|
||||
$entryDAO = new FreshRSS_EntryDAO();
|
||||
|
||||
$catDAO = new FreshRSS_CategoryDAO();
|
||||
$this->view->categories = $catDAO->listCategories();
|
||||
|
||||
if ($type == 'starred') {
|
||||
$this->view->list_title = Minz_Translate::t("starred_list");
|
||||
$this->view->type = 'starred';
|
||||
$this->view->entries = $entryDAO->listWhere(
|
||||
's', '', 'all', 'ASC',
|
||||
$entryDAO->countUnreadReadFavorites()['all']
|
||||
);
|
||||
} elseif ($type == 'feed' && !is_null($feed)) {
|
||||
$this->view->list_title = Minz_Translate::t("feed_list", $feed->name());
|
||||
$this->view->type = 'feed/' . $feed->id();
|
||||
$this->view->entries = $entryDAO->listWhere(
|
||||
'f', $feed->id(), 'all', 'ASC',
|
||||
$this->view->conf->posts_per_page
|
||||
);
|
||||
$this->view->feed = $feed;
|
||||
}
|
||||
return $this->view->helperToString('export/articles');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +137,13 @@ return array (
|
||||
'auto_share' => 'Share',
|
||||
'auto_share_help' => 'If there is only one sharing mode, it is used. Else modes are accessible by their number.',
|
||||
|
||||
'file_to_import' => 'File to import',
|
||||
'file_to_import' => 'File to import (OPML)',
|
||||
'import' => 'Import',
|
||||
'export' => 'Export',
|
||||
'export_opml' => 'Export list of feeds (OPML)',
|
||||
'export_starred' => 'Export your favourites',
|
||||
'starred_list' => 'List of favourite articles',
|
||||
'feed_list' => 'List of %s articles',
|
||||
'or' => 'or',
|
||||
|
||||
'informations' => 'Information',
|
||||
|
||||
@@ -137,9 +137,13 @@ return array (
|
||||
'auto_share' => 'Partager',
|
||||
'auto_share_help' => 'Si il n’y a qu’un mode de partage, celui ci est utilisé automatiquement. Sinon ils sont accessibles par leur numéro.',
|
||||
|
||||
'file_to_import' => 'Fichier à importer',
|
||||
'file_to_import' => 'Fichier à importer (OPML)',
|
||||
'import' => 'Importer',
|
||||
'export' => 'Exporter',
|
||||
'export_opml' => 'Exporter la liste des flux (OPML)',
|
||||
'export_starred' => 'Exporter les favoris',
|
||||
'starred_list' => 'Liste des articles favoris',
|
||||
'feed_list' => 'Liste des articles de %s',
|
||||
'or' => 'ou',
|
||||
|
||||
'informations' => 'Informations',
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</div>
|
||||
</form></li>
|
||||
|
||||
<li class="item<?php echo Minz_Request::actionName () == 'importExport' ? ' active' : ''; ?>">
|
||||
<li class="item<?php echo Minz_Request::controllerName () == 'importExport' ? ' active' : ''; ?>">
|
||||
<a href="<?php echo _url ('importExport', 'index'); ?>"><?php echo Minz_Translate::t ('import_export'); ?></a>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
<?php
|
||||
// TODO: A lot have to be done!
|
||||
$username = Minz_Session::param('currentUser', '_');
|
||||
$type_id = "TODO";
|
||||
$title = Minz_Translate::t("TODO");
|
||||
$entries = [];
|
||||
?>{
|
||||
"id": "user/<?php echo str_replace("\"", "", $username); ?>/state/org.freshrss/<?php echo $type_id; ?>",
|
||||
"title": "<?php echo addslashes($title); ?>",
|
||||
"author": "<?php echo addslashes($username); ?>",
|
||||
"items": [
|
||||
<?php $i = 0; foreach($entries as $entry) { $i++;
|
||||
echo $i > 1 ? ', ': ''; ?>{
|
||||
"id": "<?php echo $entry->id(); ?>",
|
||||
"categories": [<?php /* TODO */ ?>],
|
||||
"title": "<?php echo addslashes($entry->title()); ?>",
|
||||
"published": <?php echo $entry->date(true); ?>,
|
||||
"updated": <?php echo $entry->date(true); ?>,
|
||||
"content": "<?php echo addslashes($entry->content()); ?>",
|
||||
"origin": {
|
||||
<?php /* TODO */ ?>
|
||||
"streamId": "",
|
||||
"title": "",
|
||||
"htmlUrl": "",
|
||||
"feedUrl": ""
|
||||
}
|
||||
|
||||
$articles = array(
|
||||
'id' => 'user/' . str_replace('/', '', $username) . '/state/org.freshrss/' . $this->type,
|
||||
'title' => $this->list_title,
|
||||
'author' => $username,
|
||||
'items' => array()
|
||||
);
|
||||
|
||||
foreach ($this->entries as $entry) {
|
||||
if (!isset($this->feed)) {
|
||||
$feed = FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feed ());
|
||||
} else {
|
||||
$feed = $this->feed;
|
||||
}
|
||||
<?php } ?>
|
||||
]
|
||||
}
|
||||
|
||||
$articles['items'][] = array(
|
||||
'id' => $entry->id(),
|
||||
'categories' => array_values($entry->tags()),
|
||||
'title' => $entry->title(),
|
||||
'published' => $entry->date(true),
|
||||
'updated' => $entry->date(true),
|
||||
'content' => $entry->content(),
|
||||
'origin' => array(
|
||||
'streamId' => $feed->id(),
|
||||
'title' => $feed->name(),
|
||||
'htmlUrl' => $feed->website(),
|
||||
'feedUrl' => $feed->url()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$options = 0;
|
||||
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
$options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
|
||||
}
|
||||
|
||||
echo json_encode($articles, $options);
|
||||
?>
|
||||
|
||||
@@ -33,11 +33,11 @@
|
||||
<?php echo Minz_Translate::t ('export_starred'); ?>
|
||||
</label>
|
||||
|
||||
<label class="checkbox" for="export_all">
|
||||
<input type="checkbox" name="export_all" id="export_all" value="1" />
|
||||
<?php echo Minz_Translate::t ('export_all'); ?>
|
||||
<?php echo FreshRSS_Themes::icon('help'); ?> <?php echo Minz_Translate::t('export_all_is_long'); ?>
|
||||
</label>
|
||||
<select name="export_feeds[]" size="10" multiple="multiple">
|
||||
<?php foreach ($this->feeds as $feed) { ?>
|
||||
<option value="<?php echo $feed->id(); ?>"><?php echo $feed->name(); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class Minz_View {
|
||||
*/
|
||||
public function helperToString($helper) {
|
||||
ob_start();
|
||||
renderHelper($helper);
|
||||
$this->renderHelper($helper);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user