From 743c1b740bd8ec0b70f7058d4b52101b346a5e9c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 16 Jan 2019 22:26:43 +0100 Subject: Export labels (#2217) * Export labels https://github.com/FreshRSS/FreshRSS/issues/2196 * Small fixes * Backport code from 1.14.0 https://github.com/FreshRSS/FreshRSS/pull/2199/commits/4888f919f104b2d170302565e481a0b731eb4145 * More fixes --- app/Controllers/importExportController.php | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2d8d4e01d..3f2947c7a 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -650,7 +650,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $return; } - public function exportFile($export_opml = true, $export_starred = false, $export_feeds = array(), $maxFeedEntries = 50, $username = null) { + public function exportFile($export_opml = true, $export_starred = false, $export_labelled = false, $export_feeds = array(), $maxFeedEntries = 50, $username = null) { require_once(LIB_PATH . '/lib_opml.php'); $this->catDAO = new FreshRSS_CategoryDAO($username); @@ -674,8 +674,11 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $export_files["feeds_${day}.opml.xml"] = $this->generateOpml(); } - if ($export_starred) { - $export_files["starred_${day}.json"] = $this->generateEntries('starred'); + if ($export_starred || $export_labelled) { + $export_files["starred_${day}.json"] = $this->generateEntries( + ($export_starred ? 'S' : '') . + ($export_labelled ? 'T' : '') + ); } foreach ($export_feeds as $feed_id) { @@ -683,7 +686,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if ($feed) { $filename = "feed_${day}_" . $feed->category() . '_' . $feed->id() . '.json'; - $export_files[$filename] = $this->generateEntries('feed', $feed, $maxFeedEntries); + $export_files[$filename] = $this->generateEntries('f', $feed, $maxFeedEntries); } } @@ -725,6 +728,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $nb_files = $this->exportFile( Minz_Request::param('export_opml', false), Minz_Request::param('export_starred', false), + Minz_Request::param('export_labelled', false), Minz_Request::param('export_feeds', array()) ); } catch (FreshRSS_ZipMissing_Exception $zme) { @@ -758,27 +762,29 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { /** * This method returns a JSON file content. * - * @param string $type must be "starred" or "feed" + * @param string $type must be one of: + * 'S' (starred/favourite), 'f' (feed), 'T' (taggued/labelled), 'ST' (starred or labelled) * @param FreshRSS_Feed $feed feed of which we want to get entries. * @return string the JSON file content. */ private function generateEntries($type, $feed = null, $maxFeedEntries = 50) { $this->view->categories = $this->catDAO->listCategories(); + $tagDAO = FreshRSS_Factory::createTagDao(); - if ($type == 'starred') { + if ($type === 's' || $type === 'S' || $type === 'T' || $type === 'ST') { $this->view->list_title = _t('sub.import_export.starred_list'); $this->view->type = 'starred'; - $unread_fav = $this->entryDAO->countUnreadReadFavorites(); - $this->view->entriesRaw = $this->entryDAO->listWhereRaw( - 's', '', FreshRSS_Entry::STATE_ALL, 'ASC', $unread_fav['all'] - ); - } elseif ($type === 'feed' && $feed != null) { + $this->view->entriesId = $this->entryDAO->listIdsWhere($type, '', FreshRSS_Entry::STATE_ALL, 'ASC', -1); + $this->view->entryIdsTagNames = $tagDAO->getEntryIdsTagNames($this->view->entriesId); + //The following is a streamable query, i.e. must be last + $this->view->entriesRaw = $this->entryDAO->listWhereRaw($type, '', FreshRSS_Entry::STATE_ALL, 'ASC', -1); + } elseif ($type === 'f' && $feed != null) { $this->view->list_title = _t('sub.import_export.feed_list', $feed->name()); $this->view->type = 'feed/' . $feed->id(); - $this->view->entriesRaw = $this->entryDAO->listWhereRaw( - 'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC', - $maxFeedEntries - ); + $this->view->entriesId = $this->entryDAO->listIdsWhere($type, $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC', $maxFeedEntries); + $this->view->entryIdsTagNames = $tagDAO->getEntryIdsTagNames($this->view->entriesId); + //The following is a streamable query, i.e. must be last + $this->view->entriesRaw = $this->entryDAO->listWhereRaw($type, $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC', $maxFeedEntries); $this->view->feed = $feed; } -- cgit v1.2.3