aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controllers/importExportController.php84
-rw-r--r--app/Models/FeedDAO.php7
-rw-r--r--app/views/importExport/index.phtml2
-rw-r--r--cli/_cli.php4
-rwxr-xr-xcli/create-user.php14
-rwxr-xr-xcli/delete-user.php2
-rw-r--r--cli/export-opml-for-user.php24
-rw-r--r--cli/export-zip-for-user.php30
-rwxr-xr-xcli/import-for-user.php3
-rw-r--r--p/themes/Pafat/pafat.css3
10 files changed, 128 insertions, 45 deletions
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index fbebb2a78..bb22ac739 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -522,26 +522,21 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
return $return;
}
- /**
- * This action handles export action.
- *
- * This action must be reached by a POST request.
- *
- * Parameters are:
- * - export_opml (default: false)
- * - export_starred (default: false)
- * - export_feeds (default: array()) a list of feed ids
- */
- public function exportAction() {
- if (!Minz_Request::isPost()) {
- Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
- }
+ public function exportFile($export_opml = true, $export_starred = false, $export_feeds = array(), $maxFeedEntries = 50, $username = null) {
+ require_once(LIB_PATH . '/lib_opml.php');
- $this->view->_useLayout(false);
+ $this->catDAO = new FreshRSS_CategoryDAO($username);
+ $this->entryDAO = FreshRSS_Factory::createEntryDao($username);
+ $this->feedDAO = FreshRSS_Factory::createFeedDao($username);
+
+ if ($export_feeds === true) {
+ //All feeds
+ $export_feeds = $this->feedDAO->listFeedsIds();
+ }
+ if (!is_array($export_feeds)) {
+ $export_feeds = array();
+ }
- $export_opml = Minz_Request::param('export_opml', false);
- $export_starred = Minz_Request::param('export_starred', false);
- $export_feeds = Minz_Request::param('export_feeds', array());
$day = date('Y-m-d');
$export_files = array();
@@ -558,7 +553,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);
+ $export_files[$filename] = $this->generateEntries('feed', $feed, $maxFeedEntries);
}
}
@@ -566,18 +561,49 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
if ($nb_files > 1) {
// If there are more than 1 file to export, we need a ZIP archive.
try {
- $this->exportZip($export_files);
+ $this->sendZip($export_files);
} catch (Exception $e) {
- # Oops, there is no ZIP extension!
- Minz_Request::bad(_t('feedback.import_export.export_no_zip_extension'),
- array('c' => 'importExport', 'a' => 'index'));
+ throw new FreshRSS_ZipMissing_Exception($e);
}
} elseif ($nb_files === 1) {
// Only one file? Guess its type and export it.
$filename = key($export_files);
$type = self::guessFileType($filename);
- $this->exportFile('freshrss_' . $filename, $export_files[$filename], $type);
- } else {
+ $this->sendFile('freshrss_' . $filename, $export_files[$filename], $type);
+ }
+ return $nb_files;
+ }
+
+ /**
+ * This action handles export action.
+ *
+ * This action must be reached by a POST request.
+ *
+ * Parameters are:
+ * - export_opml (default: false)
+ * - export_starred (default: false)
+ * - export_feeds (default: array()) a list of feed ids
+ */
+ public function exportAction() {
+ if (!Minz_Request::isPost()) {
+ Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
+ }
+ $this->view->_useLayout(false);
+
+ $nb_files = 0;
+ try {
+ $nb_files = $this->exportFile(
+ Minz_Request::param('export_opml', false),
+ Minz_Request::param('export_starred', false),
+ Minz_Request::param('export_feeds', array())
+ );
+ } catch (FreshRSS_ZipMissing_Exception $zme) {
+ # Oops, there is no ZIP extension!
+ Minz_Request::bad(_t('feedback.import_export.export_no_zip_extension'),
+ array('c' => 'importExport', 'a' => 'index'));
+ }
+
+ if ($nb_files < 1) {
// Nothing to do...
Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
}
@@ -606,7 +632,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
* @param FreshRSS_Feed $feed feed of which we want to get entries.
* @return string the JSON file content.
*/
- private function generateEntries($type, $feed = NULL) {
+ private function generateEntries($type, $feed = NULL, $maxFeedEntries = 50) {
$this->view->categories = $this->catDAO->listCategories();
if ($type == 'starred') {
@@ -621,7 +647,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
$this->view->type = 'feed/' . $feed->id();
$this->view->entries = $this->entryDAO->listWhere(
'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC',
- FreshRSS_Context::$user_conf->posts_per_page
+ $maxFeedEntries
);
$this->view->feed = $feed;
}
@@ -635,7 +661,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
* @param array $files list of files where key is filename and value the content.
* @throws Exception if Zip extension is not loaded.
*/
- private function exportZip($files) {
+ private function sendZip($files) {
if (!extension_loaded('zip')) {
throw new Exception();
}
@@ -667,7 +693,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
* @param string $type the file type (opml, json_feed or json_starred).
* If equals to unknown, nothing happens.
*/
- private function exportFile($filename, $content, $type) {
+ private function sendFile($filename, $content, $type) {
if ($type === 'unknown') {
return;
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index b21f19b66..68398efd5 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -212,6 +212,13 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
}
+ public function listFeedsIds() {
+ $sql = 'SELECT id FROM `' . $this->prefix . 'feed`';
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ return $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ }
+
public function listFeeds() {
$sql = 'SELECT * FROM `' . $this->prefix . 'feed` ORDER BY name';
$stm = $this->bd->prepare($sql);
diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml
index c0bc412c3..c5049e3ea 100644
--- a/app/views/importExport/index.phtml
+++ b/app/views/importExport/index.phtml
@@ -44,7 +44,7 @@
$select_args = ' size="' . min(10, count($this->feeds)) .'" multiple="multiple"';
}
?>
- <select name="export_feeds[]"<?php echo $select_args; ?>>
+ <select name="export_feeds[]"<?php echo $select_args; ?> size="10">
<?php echo extension_loaded('zip') ? '' : '<option></option>'; ?>
<?php foreach ($this->feeds as $feed) { ?>
<option value="<?php echo $feed->id(); ?>"><?php echo $feed->name(); ?></option>
diff --git a/cli/_cli.php b/cli/_cli.php
index d81d83d66..66506f07a 100644
--- a/cli/_cli.php
+++ b/cli/_cli.php
@@ -10,7 +10,7 @@ Minz_Configuration::register('system',
DATA_PATH . '/config.php',
DATA_PATH . '/config.default.php');
FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
-Minz_Translate::init();
+Minz_Translate::init('en');
FreshRSS_Context::$isCli = true;
@@ -39,6 +39,6 @@ function cliInitUser($username) {
}
function done($ok) {
- echo 'Result: ', ($ok ? 'success' : 'fail'), ".\n";
+ fwrite(STDERR, 'Result: ' . ($ok ? 'success' : 'fail') . "\n");
exit($ok ? 0 : 1);
}
diff --git a/cli/create-user.php b/cli/create-user.php
index 387b503b6..243e65a35 100755
--- a/cli/create-user.php
+++ b/cli/create-user.php
@@ -4,16 +4,16 @@ require('_cli.php');
$options = getopt('', array(
'user:',
- 'password::',
- 'api-password::',
- 'language::',
- 'email::',
- 'token::',
+ 'password:',
+ 'api-password:',
+ 'language:',
+ 'email:',
+ 'token:',
));
if (empty($options['user'])) {
- fail('Usage: ' . basename(__FILE__) . " --user=username --password='password' --api-password='api_password'" .
- " --language=en --email=user@example.net --token='longRandomString'");
+ fail('Usage: ' . basename(__FILE__) . " --user username --password 'password' --api-password 'api_password'" .
+ " --language en --email user@example.net --token 'longRandomString'");
}
$username = $options['user'];
if (!ctype_alnum($username)) {
diff --git a/cli/delete-user.php b/cli/delete-user.php
index da48103f7..6f0e86e17 100755
--- a/cli/delete-user.php
+++ b/cli/delete-user.php
@@ -7,7 +7,7 @@ $options = getopt('', array(
));
if (empty($options['user'])) {
- fail('Usage: ' . basename(__FILE__) . " --user=username");
+ fail('Usage: ' . basename(__FILE__) . " --user username");
}
$username = $options['user'];
if (!ctype_alnum($username)) {
diff --git a/cli/export-opml-for-user.php b/cli/export-opml-for-user.php
new file mode 100644
index 000000000..bce4efd63
--- /dev/null
+++ b/cli/export-opml-for-user.php
@@ -0,0 +1,24 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$options = getopt('', array(
+ 'user:',
+ ));
+
+if (empty($options['user'])) {
+ fail('Usage: ' . basename(__FILE__) . " --user username > /path/to/file.opml.xml'");
+}
+
+$username = cliInitUser($options['user']);
+
+fwrite(STDERR, 'FreshRSS exporting OPML for user “' . $username . "”…\n");
+
+$importController = new FreshRSS_importExport_Controller();
+
+$ok = false;
+$ok = $importController->exportFile(true, false, array(), 0, $username);
+
+invalidateHttpCache($username);
+
+done($ok);
diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.php
new file mode 100644
index 000000000..f8d24238b
--- /dev/null
+++ b/cli/export-zip-for-user.php
@@ -0,0 +1,30 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$options = getopt('', array(
+ 'user:',
+ 'max-feed-entries:',
+ ));
+
+if (empty($options['user'])) {
+ fail('Usage: ' . basename(__FILE__) . " --user username --max-feed-entries 100 > /path/to/file.zip'");
+}
+
+$username = cliInitUser($options['user']);
+
+fwrite(STDERR, 'FreshRSS exporting ZIP for user “' . $username . "”…\n");
+
+$importController = new FreshRSS_importExport_Controller();
+
+$ok = false;
+try {
+ $ok = $importController->exportFile(true, true, true,
+ empty($options['max-feed-entries']) ? 100 : intval($options['max-feed-entries']),
+ $username);
+} catch (FreshRSS_ZipMissing_Exception $zme) {
+ fail('FreshRSS error: Lacking php-zip extension!');
+}
+invalidateHttpCache($username);
+
+done($ok);
diff --git a/cli/import-for-user.php b/cli/import-for-user.php
index 308786599..29084f062 100755
--- a/cli/import-for-user.php
+++ b/cli/import-for-user.php
@@ -5,11 +5,10 @@ require('_cli.php');
$options = getopt('', array(
'user:',
'filename:',
- 'clear-existing',
));
if (empty($options['user']) || empty($options['filename'])) {
- fail('Usage: ' . basename(__FILE__) . " --user=username --filename='/path/to/file.ext' --clear-existing");
+ fail('Usage: ' . basename(__FILE__) . " --user username --filename /path/to/file.ext");
}
$username = cliInitUser($options['user']);
diff --git a/p/themes/Pafat/pafat.css b/p/themes/Pafat/pafat.css
index 5e46a63ca..abe808eab 100644
--- a/p/themes/Pafat/pafat.css
+++ b/p/themes/Pafat/pafat.css
@@ -48,9 +48,6 @@ input, select, textarea {
vertical-align: middle;
}
-select{
- height:29px;
-}
option {
padding: 0 .5em;
}