From dbdda1d0c19b48d06b30879e8fe78679f79cc0c4 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 16 Mar 2014 19:34:04 +0100 Subject: Move import/export operations into an independant class - import and export are now two methods of importExportController - "opml" has been removed from the title --- app/Controllers/importExportController.php | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 app/Controllers/importExportController.php (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php new file mode 100644 index 000000000..7ed142b33 --- /dev/null +++ b/app/Controllers/importExportController.php @@ -0,0 +1,77 @@ +view->loginOk) { + Minz_Error::error ( + 403, + array ('error' => array (Minz_Translate::t ('access_denied'))) + ); + } + + require_once(LIB_PATH . '/lib_opml.php'); + } + + public function indexAction() { + $catDAO = new FreshRSS_CategoryDAO (); + $this->view->categories = $catDAO->listCategories (); + + $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') . ' · '); + } + + public function importAction() { + if (Minz_Request::isPost() && $_FILES['file']['error'] == 0) { + invalidateHttpCache(); + // on parse le fichier OPML pour récupérer les catégories et les flux associés + try { + list ($categories, $feeds) = opml_import ( + file_get_contents ($_FILES['file']['tmp_name']) + ); + + // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD + // les flux sont mis au préalable dans des variables de Request + Minz_Request::_param ('categories', $categories); + Minz_Request::_param ('feeds', $feeds); + Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport')); + } catch (FreshRSS_Opml_Exception $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); + + $notif = array ( + 'type' => 'bad', + 'content' => Minz_Translate::t ('bad_opml_file') + ); + Minz_Session::_param ('notification', $notif); + + Minz_Request::forward (array ( + 'c' => 'configure', + 'a' => 'importExport' + ), true); + } + } + } + + public function exportAction() { + Minz_View::_title ('freshrss_feeds.opml'); + + $this->view->_useLayout (false); + header('Content-Type: application/xml; charset=utf-8'); + header('Content-disposition: attachment; filename=freshrss_feeds.opml'); + + $feedDAO = new FreshRSS_FeedDAO (); + $catDAO = new FreshRSS_CategoryDAO (); + + $list = array (); + foreach ($catDAO->listCategories () as $key => $cat) { + $list[$key]['name'] = $cat->name (); + $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ()); + } + + $this->view->categories = $list; + } +} -- cgit v1.2.3 From d1c5db7461ecb69c529149536718baf9b73a1f2c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 18 Mar 2014 22:42:47 +0100 Subject: New version to export articles + opml It does not work yet! A lot of work has still to be done. Next versions should fix TODOs - OPML export works fine but can be improved - a framework has been created for articles export --- app/Controllers/importExportController.php | 48 +++++++++++++++++++++++++++--- app/views/helpers/export/articles.phtml | 30 +++++++++++++++++++ app/views/helpers/export/opml.phtml | 15 ++++++++++ app/views/importExport/export.phtml | 15 ---------- app/views/importExport/index.phtml | 33 ++++++++++++++++++-- 5 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 app/views/helpers/export/articles.phtml create mode 100644 app/views/helpers/export/opml.phtml delete mode 100644 app/views/importExport/export.phtml (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 7ed142b33..458814676 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -57,12 +57,40 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } public function exportAction() { - Minz_View::_title ('freshrss_feeds.opml'); + if (Minz_Request::isPost()) { + $this->view->_useLayout (false); - $this->view->_useLayout (false); - header('Content-Type: application/xml; charset=utf-8'); - header('Content-disposition: attachment; filename=freshrss_feeds.opml'); + $export_opml = Minz_Request::param('export_opml', false); + $export_starred = Minz_Request::param('export_starred', false); + $export_all = Minz_Request::param('export_all', false); + // code from https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly + $file = tempnam("tmp", "zip"); + $zip = new ZipArchive(); + $zip->open($file, ZipArchive::OVERWRITE); + + // Stuff with content + if ($export_opml) { + $zip->addFromString('feeds.opml', $this->generate_opml()); + } + if ($export_starred) { + $zip->addFromString('starred.json', $this->generate_articles('starred')); + } + if ($export_all) { + $zip->addFromString('all.json', $this->generate_articles('all')); + } + + // Close and send to users + $zip->close(); + header('Content-Type: application/zip'); + header('Content-Length: ' . filesize($file)); + header('Content-Disposition: attachment; filename="freshrss_export.zip"'); + readfile($file); + unlink($file); + } + } + + private function generate_opml() { $feedDAO = new FreshRSS_FeedDAO (); $catDAO = new FreshRSS_CategoryDAO (); @@ -73,5 +101,17 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $this->view->categories = $list; + + // TODO: add a parameter to renderHelper in order to get a variable + ob_start(); + $this->view->renderHelper('export/opml'); + return ob_get_clean(); + } + + private function generate_articles($type) { + // TODO: same here + we should get articles according to $type + ob_start(); + $this->view->renderHelper('export/articles'); + return ob_get_clean(); } } diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml new file mode 100644 index 000000000..b7df58caf --- /dev/null +++ b/app/views/helpers/export/articles.phtml @@ -0,0 +1,30 @@ +{ + "id": "user//state/org.freshrss/", + "title": "", + "author": "", + "items": [ + 1 ? ', ': ''; ?>{ + "id": "id(); ?>", + "categories": [], + "title": "title()); ?>", + "published": date(true); ?>, + "updated": date(true); ?>, + "content": "content()); ?>", + "origin": { + + "streamId": "", + "title": "", + "htmlUrl": "", + "feedUrl": "" + } + } + + ] +} \ No newline at end of file diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml new file mode 100644 index 000000000..2e66e5054 --- /dev/null +++ b/app/views/helpers/export/opml.phtml @@ -0,0 +1,15 @@ +'; +?> + + + + <?php echo Minz_Configuration::title (); ?> OPML Feed + + + +categories); ?> + + diff --git a/app/views/importExport/export.phtml b/app/views/importExport/export.phtml deleted file mode 100644 index 2e66e5054..000000000 --- a/app/views/importExport/export.phtml +++ /dev/null @@ -1,15 +0,0 @@ -'; -?> - - - - <?php echo Minz_Configuration::title (); ?> OPML Feed - - - -categories); ?> - - diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index c7db752a7..d8c76543e 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -4,7 +4,7 @@
- +
@@ -15,8 +15,35 @@
- - +
+
+ + +
+ +
+
+ + + + + +
+
+ +
+
+
-- cgit v1.2.3 From 5081ffaf39699398f83be97e47b72444e5bcd5d1 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 22 Mar 2014 17:56:07 +0100 Subject: Minz: remove one layer of ob_ (experimental) https://github.com/marienfressinaud/FreshRSS/issues/303#issuecomment-38351311 https://github.com/marienfressinaud/FreshRSS/issues/163 * Remove Minz_Response (not needed anymore) * Move Minz_Request::reseted to Minz_Dispatcher::reset() --- app/Controllers/importExportController.php | 14 ++---- app/actualize_script.php | 1 - lib/Minz/Dispatcher.php | 73 +++++++++++++----------------- lib/Minz/Error.php | 32 +++++++++---- lib/Minz/FrontController.php | 16 +------ lib/Minz/Request.php | 5 +- lib/Minz/Response.php | 60 ------------------------ lib/Minz/View.php | 10 ++++ lib/lib_rss.php | 2 +- 9 files changed, 73 insertions(+), 140 deletions(-) delete mode 100644 lib/Minz/Response.php (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 458814676..f697f4c9e 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -65,7 +65,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $export_all = Minz_Request::param('export_all', false); // code from https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly - $file = tempnam("tmp", "zip"); + $file = tempnam('tmp', 'zip'); $zip = new ZipArchive(); $zip->open($file, ZipArchive::OVERWRITE); @@ -101,17 +101,11 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $this->view->categories = $list; - - // TODO: add a parameter to renderHelper in order to get a variable - ob_start(); - $this->view->renderHelper('export/opml'); - return ob_get_clean(); + return $this->view->helperToString('export/opml'); } private function generate_articles($type) { - // TODO: same here + we should get articles according to $type - ob_start(); - $this->view->renderHelper('export/articles'); - return ob_get_clean(); + // TODO: we should get articles according to $type + return $this->view->helperToString('export/articles'); } } diff --git a/app/actualize_script.php b/app/actualize_script.php index 8d81e0189..4c306b8da 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -28,7 +28,6 @@ foreach ($users as $myUser) { $_SERVER['HTTP_HOST'] = ''; $freshRSS = new FreshRSS(); - $freshRSS->_useOb(false); Minz_Configuration::_authType('none'); diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index 819f4cd5c..ca1fd1f5c 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -14,6 +14,7 @@ class Minz_Dispatcher { /* singleton */ private static $instance = null; + private static $needsReset; private $router; private $controller; @@ -40,44 +41,36 @@ class Minz_Dispatcher { * Remplit le body de Response à partir de la Vue * @exception Minz_Exception */ - public function run ($ob = true) { - // Le ob_start est dupliqué : sans ça il y a un bug sous Firefox - // ici on l'appelle avec 'ob_gzhandler', après sans. - // Vraisemblablement la compression fonctionne mais c'est sale - // J'ignore les effets de bord :( - if ($ob) { - ob_start ('ob_gzhandler'); - } - - $text = ''; //TODO: Clean this code - while (Minz_Request::$reseted) { - Minz_Request::$reseted = false; + public function run () { + do { + self::$needsReset = false; try { $this->createController ('FreshRSS_' . Minz_Request::controllerName () . '_Controller'); $this->controller->init (); $this->controller->firstAction (); - $this->launchAction ( - Minz_Request::actionName () - . 'Action' - ); + if (!self::$needsReset) { + $this->launchAction ( + Minz_Request::actionName () + . 'Action' + ); + } $this->controller->lastAction (); - if (!Minz_Request::$reseted) { - if ($ob) { - ob_start (); - } - $this->controller->view ()->build (); - if ($ob) { - $text = ob_get_clean(); - } + if (!self::$needsReset) { + echo $this->controller->view ()->build (); } } catch (Minz_Exception $e) { throw $e; } - } + } while (self::$needsReset); + } - Minz_Response::setBody ($text); + /** + * Informe le contrôleur qu'il doit recommancer car la requête a été modifiée + */ + public static function reset() { + self::$needsReset = true; } /** @@ -114,21 +107,19 @@ class Minz_Dispatcher { * le controller */ private function launchAction ($action_name) { - if (!Minz_Request::$reseted) { - if (!is_callable (array ( - $this->controller, - $action_name - ))) { - throw new Minz_ActionException ( - get_class ($this->controller), - $action_name, - Minz_Exception::ERROR - ); - } - call_user_func (array ( - $this->controller, - $action_name - )); + if (!is_callable (array ( + $this->controller, + $action_name + ))) { + throw new Minz_ActionException ( + get_class ($this->controller), + $action_name, + Minz_Exception::ERROR + ); } + call_user_func (array ( + $this->controller, + $action_name + )); } } diff --git a/lib/Minz/Error.php b/lib/Minz/Error.php index 337ab6c0a..c8222a430 100644 --- a/lib/Minz/Error.php +++ b/lib/Minz/Error.php @@ -23,13 +23,32 @@ class Minz_Error { $logs = self::processLogs ($logs); $error_filename = APP_PATH . '/Controllers/errorController.php'; + switch ($code) { + case 200 : + header('HTTP/1.1 200 OK'); + break; + case 403 : + header('HTTP/1.1 403 Forbidden'); + break; + case 404 : + header('HTTP/1.1 404 Not Found'); + break; + case 500 : + header('HTTP/1.1 500 Internal Server Error'); + break; + case 503 : + header('HTTP/1.1 503 Service Unavailable'); + break; + default : + header('HTTP/1.1 500 Internal Server Error'); + } + if (file_exists ($error_filename)) { $params = array ( 'code' => $code, 'logs' => $logs ); - Minz_Response::setHeader ($code); if ($redirect) { Minz_Request::forward (array ( 'c' => 'error' @@ -41,19 +60,16 @@ class Minz_Error { ), false); } } else { - $text = '

An error occured

'."\n"; + echo '

An error occured

' . "\n"; if (!empty ($logs)) { - $text .= '
    '."\n"; + echo '
      ' . "\n"; foreach ($logs as $log) { - $text .= '
    • ' . $log . '
    • '."\n"; + echo '
    • ' . $log . '
    • ' . "\n"; } - $text .= '
    '."\n"; + echo '
' . "\n"; } - Minz_Response::setHeader ($code); - Minz_Response::setBody ($text); - Minz_Response::send (); exit (); } } diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php index 80eda8877..3e50db1cf 100644 --- a/lib/Minz/FrontController.php +++ b/lib/Minz/FrontController.php @@ -26,8 +26,6 @@ class Minz_FrontController { protected $dispatcher; protected $router; - private $useOb = true; - /** * Constructeur * Initialise le router et le dispatcher @@ -63,8 +61,7 @@ class Minz_FrontController { */ public function run () { try { - $this->dispatcher->run ($this->useOb); - Minz_Response::send (); + $this->dispatcher->run(); } catch (Minz_Exception $e) { try { Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); @@ -96,15 +93,4 @@ class Minz_FrontController { } exit ('### Application problem ###
'."\n".$txt); } - - public function useOb() { - return $this->useOb; - } - - /** - * Use ob_start('ob_gzhandler') or not. - */ - public function _useOb($ob) { - return $this->useOb = (bool)$ob; - } } diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 282d47a77..7e3c59990 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -15,8 +15,6 @@ class Minz_Request { private static $default_controller_name = 'index'; private static $default_action_name = 'index'; - public static $reseted = true; - /** * Getteurs */ @@ -137,14 +135,13 @@ class Minz_Request { header ('Location: ' . Minz_Url::display ($url, 'php')); exit (); } else { - self::$reseted = true; - self::_controllerName ($url['c']); self::_actionName ($url['a']); self::_params (array_merge ( self::$params, $url['params'] )); + Minz_Dispatcher::reset(); } } diff --git a/lib/Minz/Response.php b/lib/Minz/Response.php deleted file mode 100644 index f8ea3d946..000000000 --- a/lib/Minz/Response.php +++ /dev/null @@ -1,60 +0,0 @@ - -*/ - -/** - * Response représente la requête http renvoyée à l'utilisateur - */ -class Minz_Response { - private static $header = 'HTTP/1.0 200 OK'; - private static $body = ''; - - /** - * Mets à jour le body de la Response - * @param $text le texte à incorporer dans le body - */ - public static function setBody ($text) { - self::$body = $text; - } - - /** - * Mets à jour le header de la Response - * @param $code le code HTTP, valeurs possibles - * - 200 (OK) - * - 403 (Forbidden) - * - 404 (Forbidden) - * - 500 (Forbidden) -> par défaut si $code erroné - * - 503 (Forbidden) - */ - public static function setHeader ($code) { - switch ($code) { - case 200 : - self::$header = 'HTTP/1.0 200 OK'; - break; - case 403 : - self::$header = 'HTTP/1.0 403 Forbidden'; - break; - case 404 : - self::$header = 'HTTP/1.0 404 Not Found'; - break; - case 500 : - self::$header = 'HTTP/1.0 500 Internal Server Error'; - break; - case 503 : - self::$header = 'HTTP/1.0 503 Service Unavailable'; - break; - default : - self::$header = 'HTTP/1.0 500 Internal Server Error'; - } - } - - /** - * Envoie la Response à l'utilisateur - */ - public static function send () { - header (self::$header); - echo self::$body; - } -} diff --git a/lib/Minz/View.php b/lib/Minz/View.php index e170bd406..00d9a1a6d 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -102,6 +102,16 @@ class Minz_View { } } + /** + * Retourne renderHelper() dans une chaîne + * @param $helper l'élément à traîter + */ + public function helperToString($helper) { + ob_start(); + renderHelper($helper); + return ob_get_clean(); + } + /** * Permet de choisir si on souhaite utiliser le layout * @param $use true si on souhaite utiliser le layout, false sinon diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 83edbf015..2077fe63f 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -27,7 +27,7 @@ function classAutoloader($class) { include(APP_PATH . '/Models/' . $components[1] . '.php'); return; case 3: //Controllers, Exceptions - include(APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php'); + @include(APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php'); return; } } elseif (strpos($class, 'Minz') === 0) { -- cgit v1.2.3 From 9d87f2f0aa8306c3e07a79d1a100b4d41ea8bc72 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 27 Mar 2014 20:36:51 +0100 Subject: Export is fully implemented - Export list of feeds (OPML) - Export list of favourites (JSON) - Export list of articles per feed (JSON) --- app/Controllers/importExportController.php | 47 +++++++++++++++++----- app/i18n/en.php | 6 ++- app/i18n/fr.php | 6 ++- app/layout/aside_feed.phtml | 2 +- app/views/helpers/export/articles.phtml | 64 +++++++++++++++++------------- app/views/importExport/index.phtml | 10 ++--- lib/Minz/View.php | 2 +- 7 files changed, 90 insertions(+), 47 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index f697f4c9e..040cf3f7b 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -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'); } } diff --git a/app/i18n/en.php b/app/i18n/en.php index e9bed39a7..1a0c80249 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -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', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 24f3741c8..0cc835142 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -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', diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index 899cafe02..ae16efd96 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -43,7 +43,7 @@
-
  • +
  • diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml index b7df58caf..71ac22f44 100644 --- a/app/views/helpers/export/articles.phtml +++ b/app/views/helpers/export/articles.phtml @@ -1,30 +1,40 @@ { - "id": "user//state/org.freshrss/", - "title": "", - "author": "", - "items": [ - 1 ? ', ': ''; ?>{ - "id": "id(); ?>", - "categories": [], - "title": "title()); ?>", - "published": date(true); ?>, - "updated": date(true); ?>, - "content": "content()); ?>", - "origin": { - - "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; } - - ] -} \ No newline at end of file + + $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); +?> diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index d8c76543e..b82e0d26b 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -33,11 +33,11 @@ - +
    diff --git a/lib/Minz/View.php b/lib/Minz/View.php index 00d9a1a6d..f034ab10b 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -108,7 +108,7 @@ class Minz_View { */ public function helperToString($helper) { ob_start(); - renderHelper($helper); + $this->renderHelper($helper); return ob_get_clean(); } -- cgit v1.2.3 From 05cc97a8f43d779fbea52f5ef47fe6a71c3ab692 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 28 Mar 2014 18:44:52 +0100 Subject: Export form is not displayed if there is nothing to export --- app/Controllers/importExportController.php | 1 + app/views/importExport/index.phtml | 2 ++ 2 files changed, 3 insertions(+) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 040cf3f7b..51f0708fd 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -131,6 +131,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); $this->view->feed = $feed; } + return $this->view->helperToString('export/articles'); } } diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index b82e0d26b..386c88648 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -19,6 +19,7 @@ + feeds) > 0) { ?>
    @@ -47,4 +48,5 @@
    + -- cgit v1.2.3 From d464833922e9cc00948698aed0a2af1f0b55e101 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 28 Mar 2014 22:13:42 +0100 Subject: Improve import / export functionnality It is not finished yet and does not even work at all!! - ZIP archive can be uploaded - Entries are imported from starred.json and feed*.json but not added in DB for the moment. - Fix export (add author, id -> guid, content -> content.content and add alternate) See https://github.com/marienfressinaud/FreshRSS/issues/163 --- app/Controllers/feedController.php | 2 + app/Controllers/importExportController.php | 260 ++++++++++++++++++++++++----- app/views/helpers/export/articles.phtml | 11 +- 3 files changed, 228 insertions(+), 45 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 16516ad39..43435d99d 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -328,6 +328,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } public function massiveImportAction () { + # TODO: this function has moved to importExportController.php + # I keep it for the moment but should be deleted in a near future. @set_time_limit(300); $this->catDAO = new FreshRSS_CategoryDAO (); diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 51f0708fd..6194ce214 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -3,21 +3,22 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { public function firstAction() { if (!$this->view->loginOk) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (Minz_Translate::t ('access_denied'))) + array('error' => array(Minz_Translate::t('access_denied'))) ); } require_once(LIB_PATH . '/lib_opml.php'); + + $this->catDAO = new FreshRSS_CategoryDAO(); + $this->entryDAO = new FreshRSS_EntryDAO(); + $this->feedDAO = new FreshRSS_FeedDAO(); } public function indexAction() { - $catDAO = new FreshRSS_CategoryDAO(); - $this->view->categories = $catDAO->listCategories(); - - $feedDAO = new FreshRSS_FeedDAO(); - $this->view->feeds = $feedDAO->listFeeds(); + $this->view->categories = $this->catDAO->listCategories(); + $this->view->feeds = $this->feedDAO->listFeeds(); // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste $this->view->flux = false; @@ -27,38 +28,218 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { public function importAction() { if (Minz_Request::isPost() && $_FILES['file']['error'] == 0) { - invalidateHttpCache(); - // on parse le fichier OPML pour récupérer les catégories et les flux associés + @set_time_limit(300); + + $file = $_FILES['file']; + $type_file = $this->guess_file_type($file['name']); + + $list_files = array( + 'opml' => array(), + 'json_starred' => array(), + 'json_feed' => array() + ); + + // We try to list all files according to their type + // A zip file is first opened and then its files are listed + $list = array(); + if ($type_file === 'zip') { + $zip = zip_open($file['tmp_name']); + + while (($zipfile = zip_read($zip)) !== false) { + $type_zipfile = $this->guess_file_type(zip_entry_name($zipfile)); + + if ($type_file !== 'unknown') { + $list_files[$type_zipfile][] = zip_entry_read( + $zipfile, + zip_entry_filesize($zipfile) + ); + } + } + + zip_close($zip); + } elseif ($type_file !== 'unknown') { + $list_files[$type_file][] = file_get_contents($file['tmp_name']); + } + + // Import different files. + // OPML first(so categories and feeds are imported) + // Starred articles then so the "favourite" status is already set + // And finally all other files. + $error = false; + foreach ($list_files['opml'] as $opml_file) { + $error = $this->import_opml($opml_file); + } + foreach ($list_files['json_starred'] as $article_file) { + $error = $this->import_articles($article_file, true); + } + foreach ($list_files['json_feed'] as $article_file) { + $error = $this->import_articles($article_file); + } + + // And finally, we get import status and redirect to the home page + $notif = null; + if ($error === true) { + $notif = array( + 'type' => 'good', + 'content' => Minz_Translate::t('feeds_imported_with_errors') + ); + } else { + $notif = array( + 'type' => 'good', + 'content' => Minz_Translate::t('feeds_imported') + ); + } + + Minz_Session::_param('notification', $notif); + Minz_Session::_param('actualize_feeds', true); + + Minz_Request::forward(array( + 'c' => 'index', + 'a' => 'index' + ), true); + } + + // What are you doing? you have to call this controller + // with a POST request! + Minz_Request::forward(array( + 'c' => 'importExport', + 'a' => 'index' + )); + } + + private function guess_file_type($filename) { + // A *very* basic guess file type function. Only based on filename + // That's could be improved but should be enough, at least for a first + // implementation. + // TODO: improve this function? + + if (substr_compare($filename, '.zip', -4) === 0) { + return 'zip'; + } elseif (substr_compare($filename, '.opml', -5) === 0) { + return 'opml'; + } elseif (strcmp($filename, 'starred.json') === 0) { + return 'json_starred'; + } elseif (substr_compare($filename, '.json', -5) === 0 && + strpos($filename, 'feed_') === 0) { + return 'json_feed'; + } else { + return 'unknown'; + } + } + + private function import_opml($opml_file) { + $categories = array(); + $feeds = array(); + try { + list($categories, $feeds) = opml_import($opml_file); + } catch (FreshRSS_Opml_Exception $e) { + Minz_Log::warning($e->getMessage()); + return true; + } + + $this->catDAO->checkDefault(); + + // on ajoute les catégories en masse dans une fonction à part + $this->addCategories($categories); + + // on calcule la date des articles les plus anciens qu'on accepte + $nb_month_old = $this->view->conf->old_entries; + $date_min = time() -(3600 * 24 * 30 * $nb_month_old); + + // la variable $error permet de savoir si une erreur est survenue + // Le but est de ne pas arrêter l'import même en cas d'erreur + // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais + // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées + $error = false; + foreach ($feeds as $feed) { try { - list ($categories, $feeds) = opml_import ( - file_get_contents ($_FILES['file']['tmp_name']) + $values = array( + 'id' => $feed->id(), + 'url' => $feed->url(), + 'category' => $feed->category(), + 'name' => $feed->name(), + 'website' => $feed->website(), + 'description' => $feed->description(), + 'lastUpdate' => 0, + 'httpAuth' => $feed->httpAuth() ); - // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD - // les flux sont mis au préalable dans des variables de Request - Minz_Request::_param ('categories', $categories); - Minz_Request::_param ('feeds', $feeds); - Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport')); - } catch (FreshRSS_Opml_Exception $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); - - $notif = array ( - 'type' => 'bad', - 'content' => Minz_Translate::t ('bad_opml_file') + // ajout du flux que s'il n'est pas déjà en BDD + if (!$this->feedDAO->searchByUrl($values['url'])) { + $id = $this->feedDAO->addFeed($values); + if ($id) { + $feed->_id($id); + $feed->faviconPrepare(); + } else { + $error = true; + } + } + } catch (FreshRSS_Feed_Exception $e) { + $error = true; + Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + } + } + + return $error; + } + + private function addCategories($categories) { + foreach ($categories as $cat) { + if (!$this->catDAO->searchByName($cat->name())) { + $values = array( + 'id' => $cat->id(), + 'name' => $cat->name(), ); - Minz_Session::_param ('notification', $notif); + $this->catDAO->addCategory($values); + } + } + } + + private function import_articles($article_file, $starred = false) { + $article_object = json_decode($article_file, true); + if (is_null($article_object)) { + Minz_Log::warning('Try to import a non-JSON file'); + return true; + } + + $google_compliant = (strpos($article_object['id'], 'com.google') !== false); + + foreach ($article_object['items'] as $item) { + $key = $google_compliant ? 'htmlUrl' : 'feedUrl'; + $feed = $this->feedDAO->searchByUrl($item['origin'][$key]); + if (is_null($feed)) { + $feed = new FreshRSS_Feed($item['origin'][$key]); + $feed->_name ($item['origin']['title']); + $feed->_website ($item['origin']['htmlUrl']); + + $error = $this->addFeed($feed); // TODO - Minz_Request::forward (array ( - 'c' => 'configure', - 'a' => 'importExport' - ), true); + if ($error) { + continue; + } } + + $author = isset($item['author']) ? $item['author'] : ''; + $key_content = $google_compliant && !isset($item['content']) ? 'summary' : 'content'; + $tags = $item['categories']; + if ($google_compliant) { + $tags = array_filter($tags, function($var) { + return strpos($var, '/state/com.google') === false; + }); + } + $entry = new FreshRSS_Entry( + $feed->id(), $item['id'], $item['title'], $author, + $item[$key_content]['content'], $item['alternate'][0]['href'], + $item['published'], false, $starred, $tags + ); + + Minz_Log::debug(print_r($entry, true)); // TODO } } public function exportAction() { if (Minz_Request::isPost()) { - $this->view->_useLayout (false); + $this->view->_useLayout(false); $export_opml = Minz_Request::param('export_opml', false); $export_starred = Minz_Request::param('export_starred', false); @@ -76,9 +257,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if ($export_starred) { $zip->addFromString('starred.json', $this->generate_articles('starred')); } - $feedDAO = new FreshRSS_FeedDAO (); foreach ($export_feeds as $feed_id) { - $feed = $feedDAO->searchById($feed_id); + $feed = $this->feedDAO->searchById($feed_id); $zip->addFromString( 'feed_' . $feed->category() . '_' . $feed->id() . '.json', $this->generate_articles('feed', $feed) @@ -96,13 +276,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function generate_opml() { - $feedDAO = new FreshRSS_FeedDAO (); - $catDAO = new FreshRSS_CategoryDAO (); - - $list = array (); - foreach ($catDAO->listCategories () as $key => $cat) { - $list[$key]['name'] = $cat->name (); - $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ()); + $list = array(); + foreach ($this->catDAO->listCategories() as $key => $cat) { + $list[$key]['name'] = $cat->name(); + $list[$key]['feeds'] = $this->feedDAO->listByCategory($cat->id()); } $this->view->categories = $list; @@ -110,22 +287,19 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function generate_articles($type, $feed = NULL) { - $entryDAO = new FreshRSS_EntryDAO(); - - $catDAO = new FreshRSS_CategoryDAO(); - $this->view->categories = $catDAO->listCategories(); + $this->view->categories = $this->catDAO->listCategories(); if ($type == 'starred') { $this->view->list_title = Minz_Translate::t("starred_list"); $this->view->type = 'starred'; - $this->view->entries = $entryDAO->listWhere( + $this->view->entries = $this->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( + $this->view->entries = $this->entryDAO->listWhere( 'f', $feed->id(), 'all', 'ASC', $this->view->conf->posts_per_page ); diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml index 71ac22f44..ffdca1daa 100644 --- a/app/views/helpers/export/articles.phtml +++ b/app/views/helpers/export/articles.phtml @@ -16,12 +16,19 @@ } $articles['items'][] = array( - 'id' => $entry->id(), + 'id' => $entry->guid(), 'categories' => array_values($entry->tags()), 'title' => $entry->title(), + 'author' => $entry->author(), 'published' => $entry->date(true), 'updated' => $entry->date(true), - 'content' => $entry->content(), + 'alternate' => array(array( + 'href' => $entry->link(), + 'type' => 'text/html' + )), + 'content' => array( + 'content' => $entry->content() + ), 'origin' => array( 'streamId' => $feed->id(), 'title' => $feed->name(), -- cgit v1.2.3 From 7676a197a4767f735dabae6ad9cf40ef65e91aa7 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 29 Mar 2014 19:10:18 +0100 Subject: Fix typo + improve detection OPML file --- app/Controllers/importExportController.php | 7 ++++--- app/views/importExport/index.phtml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 6194ce214..cbadeb6ca 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -115,7 +115,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if (substr_compare($filename, '.zip', -4) === 0) { return 'zip'; - } elseif (substr_compare($filename, '.opml', -5) === 0) { + } elseif (substr_compare($filename, '.opml', -5) === 0 || + substr_compare($filename, '.xml', -4) === 0) { return 'opml'; } elseif (strcmp($filename, 'starred.json') === 0) { return 'json_starred'; @@ -144,7 +145,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = $this->view->conf->old_entries; - $date_min = time() -(3600 * 24 * 30 * $nb_month_old); + $date_min = time() - (3600 * 24 * 30 * $nb_month_old); // la variable $error permet de savoir si une erreur est survenue // Le but est de ne pas arrêter l'import même en cas d'erreur @@ -294,7 +295,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->type = 'starred'; $this->view->entries = $this->entryDAO->listWhere( 's', '', 'all', 'ASC', - $entryDAO->countUnreadReadFavorites()['all'] + $this->entryDAO->countUnreadReadFavorites()['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { $this->view->list_title = Minz_Translate::t("feed_list", $feed->name()); diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index 386c88648..309058959 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -34,7 +34,7 @@ - feeds as $feed) { ?> -- cgit v1.2.3 From 9ea3819402746d8425d4a608f2d5f3c0f5bc29fb Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 29 Mar 2014 20:18:57 +0100 Subject: Better OPML import / export - use a new OPML library (https://github.com/marienfressinaud/lib_opml) - import has been completely rewritten (far better!) - introduce addFeedObject and addCategoryObject (in DAO for the moment). Permit to add easily feeds and categories (check if they already exist in DB) - introduce html_chars_utf8 (wrap htmlspecialchars for UTF-8) --- app/Controllers/importExportController.php | 124 ++++++++----- app/Exceptions/OpmlException.php | 6 - app/Models/CategoryDAO.php | 12 ++ app/Models/FeedDAO.php | 29 +++ app/views/helpers/export/opml.phtml | 43 +++-- lib/lib_opml.php | 277 ++++++++++++++++++++--------- lib/lib_rss.php | 4 + 7 files changed, 345 insertions(+), 150 deletions(-) delete mode 100644 app/Exceptions/OpmlException.php (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index cbadeb6ca..b6b4d0fed 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -129,71 +129,101 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function import_opml($opml_file) { - $categories = array(); - $feeds = array(); + $opml_array = array(); try { - list($categories, $feeds) = opml_import($opml_file); - } catch (FreshRSS_Opml_Exception $e) { + $opml_array = libopml_parse_string($opml_file); + } catch (LibOPML_Exception $e) { Minz_Log::warning($e->getMessage()); return true; } $this->catDAO->checkDefault(); - // on ajoute les catégories en masse dans une fonction à part - $this->addCategories($categories); - - // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->old_entries; - $date_min = time() - (3600 * 24 * 30 * $nb_month_old); + return $this->addOpmlElements($opml_array['body']); + } - // la variable $error permet de savoir si une erreur est survenue - // Le but est de ne pas arrêter l'import même en cas d'erreur - // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais - // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées + private function addOpmlElements($opml_elements, $parent_cat = null) { $error = false; - foreach ($feeds as $feed) { - try { - $values = array( - 'id' => $feed->id(), - 'url' => $feed->url(), - 'category' => $feed->category(), - 'name' => $feed->name(), - 'website' => $feed->website(), - 'description' => $feed->description(), - 'lastUpdate' => 0, - 'httpAuth' => $feed->httpAuth() - ); + foreach ($opml_elements as $elt) { + $res = false; + if (isset($elt['xmlUrl'])) { + $res = $this->addFeedOpml($elt, $parent_cat); + } else { + $res = $this->addCategoryOpml($elt, $parent_cat); + } - // ajout du flux que s'il n'est pas déjà en BDD - if (!$this->feedDAO->searchByUrl($values['url'])) { - $id = $this->feedDAO->addFeed($values); - if ($id) { - $feed->_id($id); - $feed->faviconPrepare(); - } else { - $error = true; - } - } - } catch (FreshRSS_Feed_Exception $e) { - $error = true; - Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + if (!$error && $res) { + // oops: there is at least one error! + $error = $res; } } return $error; } - private function addCategories($categories) { - foreach ($categories as $cat) { - if (!$this->catDAO->searchByName($cat->name())) { - $values = array( - 'id' => $cat->id(), - 'name' => $cat->name(), - ); - $this->catDAO->addCategory($values); + private function addFeedOpml($feed_elt, $parent_cat) { + if (is_null($parent_cat)) { + // This feed has no parent category so we get the default one + $parent_cat = $catDAO->getDefault()->name(); + } + + $cat = $this->catDAO->searchByName($parent_cat); + + if (!$cat) { + return true; + } + + // We get different useful information + $url = html_chars_utf8($feed_elt['xmlUrl']); + $name = html_chars_utf8($feed_elt['text']); + $website = ''; + if (isset($feed_elt['htmlUrl'])) { + $website = html_chars_utf8($feed_elt['htmlUrl']); + } + $description = ''; + if (isset($feed_elt['description'])) { + $description = html_chars_utf8($feed_elt['description']); + } + + $error = false; + try { + // Create a Feed object and add it in DB + $feed = new FreshRSS_Feed($url); + $feed->_category($cat->id()); + $feed->_name($name); + $feed->_website($website); + $feed->_description($description); + + // addFeedObject checks if feed is already in DB so nothing else to + // check here + $id = $this->feedDAO->addFeedObject($feed); + $error = ($id === false); + } catch (FreshRSS_Feed_Exception $e) { + Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + $error = true; + } + + return $error; + } + + private function addCategoryOpml($cat_elt, $parent_cat) { + // Create a new Category object + $cat = new FreshRSS_Category(html_chars_utf8($cat_elt['text'])); + + $id = $this->catDAO->addCategoryObject($cat); + $error = ($id === false); + + if (isset($cat_elt['@outlines'])) { + // Our cat_elt contains more categories or more feeds, so we + // add them recursively. + // Note: FreshRSS does not support yet category arborescence + $res = $this->addOpmlElements($cat_elt['@outlines'], $cat->name()); + if (!$error && $res) { + $error = true; } } + + return $error; } private function import_articles($article_file, $starred = false) { diff --git a/app/Exceptions/OpmlException.php b/app/Exceptions/OpmlException.php deleted file mode 100644 index e0ea3e493..000000000 --- a/app/Exceptions/OpmlException.php +++ /dev/null @@ -1,6 +0,0 @@ -searchByName($category->name())) { + // Category does not exist yet in DB so we add it before continue + $values = array( + 'name' => $category->name(), + ); + return $this->addCategory($values); + } + + return false; + } + public function updateCategory ($id, $valuesTmp) { $sql = 'UPDATE `' . $this->prefix . 'category` SET name=? WHERE id=?'; $stm = $this->bd->prepare ($sql); diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index ca25c3aeb..eac21df7e 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -24,6 +24,35 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } } + public function addFeedObject($feed) { + // TODO: not sure if we should write this method in DAO since DAO + // should not be aware about feed class + + // Add feed only if we don't find it in DB + if (!$this->searchByUrl($feed->url())) { + $values = array( + 'id' => $feed->id(), + 'url' => $feed->url(), + 'category' => $feed->category(), + 'name' => $feed->name(), + 'website' => $feed->website(), + 'description' => $feed->description(), + 'lastUpdate' => 0, + 'httpAuth' => $feed->httpAuth() + ); + + $id = $this->addFeed($values); + if ($id) { + $feed->_id($id); + $feed->faviconPrepare(); + } + + return $id; + } + + return false; + } + public function updateFeed ($id, $valuesTmp) { $set = ''; foreach ($valuesTmp as $key => $v) { diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml index 2e66e5054..adbac904d 100644 --- a/app/views/helpers/export/opml.phtml +++ b/app/views/helpers/export/opml.phtml @@ -1,15 +1,30 @@ '; -?> - - - - <?php echo Minz_Configuration::title (); ?> OPML Feed - - - -categories); ?> - - + +$opml_array = array( + 'head' => array( + 'title' => Minz_Configuration::title(), + 'dateCreated' => date('D, d M Y H:i:s') + ), + 'body' => array() +); + +foreach ($this->categories as $key => $cat) { + $opml_array['body'][$key] = array( + 'text' => $cat['name'], + '@outlines' => array() + ); + + foreach ($cat['feeds'] as $feed) { + $opml_array['body'][$key]['@outlines'][] = array( + 'text' => $feed->name(), + 'type' => 'rss', + 'xmlUrl' => $feed->url(), + 'htmlUrl' => $feed->website(), + 'description' => htmlspecialchars( + $feed->description(), ENT_COMPAT, 'UTF-8' + ) + ); + } +} + +echo libopml_render($opml_array); diff --git a/lib/lib_opml.php b/lib/lib_opml.php index 05e54d85e..16a9921ea 100644 --- a/lib/lib_opml.php +++ b/lib/lib_opml.php @@ -1,23 +1,86 @@ ' . "\n"; - - foreach ($cat['feeds'] as $feed) { - $txt .= "\t" . '' . "\n"; +/* * + * lib_opml is a free library to manage OPML format in PHP. + * It takes in consideration only version 2.0 (http://dev.opml.org/spec2.html). + * Basically it means "text" attribute for outline elements is required. + * + * lib_opml requires SimpleXML (http://php.net/manual/en/book.simplexml.php) + * + * Usages: + * > include('lib_opml.php'); + * > $filename = 'my_opml_file.xml'; + * > $opml_array = libopml_parse_file($filename); + * > print_r($opml_array); + * + * > $opml_string = [...]; + * > $opml_array = libopml_parse_string($opml_string); + * > print_r($opml_array); + * + * > $opml_array = [...]; + * > $opml_string = libopml_render($opml_array); + * > $opml_object = libopml_render($opml_array, true); + * > echo $opml_string; + * > print_r($opml_object); + * + * If parsing fails for any reason (e.g. not an XML string, does not match with + * the specifications), a LibOPML_Exception is raised. + * + * Author: Marien Fressinaud + * Url: https://github.com/marienfressinaud/lib_opml + * Version: 0.1 + * Date: 2014-03-29 + * License: public domain + * + * */ + +class LibOPML_Exception extends Exception {} + + +// These elements are optional +define('HEAD_ELEMENTS', serialize(array( + 'title', 'dateCreated', 'dateModified', 'ownerName', 'ownerEmail', + 'ownerId', 'docs', 'expansionState', 'vertScrollState', 'windowTop', + 'windowLeft', 'windowBottom', 'windowRight' +))); + + +function libopml_parse_outline($outline_xml) { + $outline = array(); + + // An outline may contain any kind of attributes but "text" attribute is + // required ! + $text_is_present = false; + foreach ($outline_xml->attributes() as $key => $value) { + $outline[$key] = (string)$value; + + if ($key === 'text') { + $text_is_present = true; } + } - $txt .= '' . "\n"; + if (!$text_is_present) { + throw new LibOPML_Exception( + 'Outline does not contain any text attribute' + ); } - return $txt; + foreach ($outline_xml->children() as $key => $value) { + // An outline may contain any number of outline children + if ($key === 'outline') { + $outline['@outlines'][] = libopml_parse_outline($value); + } else { + throw new LibOPML_Exception( + 'Body can contain only outline elements' + ); + } + } + + return $outline; } -function opml_import ($xml) { - $xml = html_only_entity_decode($xml); //!\ Assume UTF-8 +function libopml_parse_string($xml) { $dom = new DOMDocument(); $dom->recover = true; $dom->strictErrorChecking = false; @@ -27,94 +90,142 @@ function opml_import ($xml) { $opml = simplexml_import_dom($dom); if (!$opml) { - throw new FreshRSS_Opml_Exception (); + throw new LibOPML_Exception(); } - $catDAO = new FreshRSS_CategoryDAO(); - $catDAO->checkDefault(); - $defCat = $catDAO->getDefault(); + $array = array( + 'version' => (string)$opml['version'], + 'head' => array(), + 'body' => array() + ); + + // First, we get all "head" elements. Head is required but its sub-elements + // are optional. + foreach ($opml->head->children() as $key => $value) { + if (in_array($key, unserialize(HEAD_ELEMENTS), true)) { + $array['head'][$key] = (string)$value; + } else { + throw new LibOPML_Exception( + $key . 'is not part of OPML format' + ); + } + } - $categories = array (); - $feeds = array (); + // Then, we get body oulines. Body must contain at least one outline + // element. + $at_least_one_outline = false; + foreach ($opml->body->children() as $key => $value) { + if ($key === 'outline') { + $at_least_one_outline = true; + $array['body'][] = libopml_parse_outline($value); + } else { + throw new LibOPML_Exception( + 'Body can contain only outline elements' + ); + } + } + + if (!$at_least_one_outline) { + throw new LibOPML_Exception( + 'Body must contain at least one outline element' + ); + } - foreach ($opml->body->outline as $outline) { - if (!isset ($outline['xmlUrl'])) { - // Catégorie - $title = ''; + return $array; +} - if (isset ($outline['text'])) { - $title = (string) $outline['text']; - } elseif (isset ($outline['title'])) { - $title = (string) $outline['title']; - } - if ($title) { - // Permet d'éviter les soucis au niveau des id : - // ceux-ci sont générés en fonction de la date, - // un flux pourrait être dans une catégorie X avec l'id Y - // alors qu'il existe déjà la catégorie X mais avec l'id Z - // Y ne sera pas ajouté et le flux non plus vu que l'id - // de sa catégorie n'exisera pas - $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); - $catDAO = new FreshRSS_CategoryDAO (); - $cat = $catDAO->searchByName ($title); - if ($cat == null) { - $cat = new FreshRSS_Category ($title); - $values = array ( - 'name' => $cat->name () - ); - $cat->_id ($catDAO->addCategory ($values)); - } - - $feeds = array_merge ($feeds, getFeedsOutline ($outline, $cat->id ())); +function libopml_parse_file($filename) { + $file_content = file_get_contents($filename); + + if ($file_content === false) { + throw new LibOPML_Exception( + $filename . ' cannot be found' + ); + } + + return libopml_parse_string($file_content); +} + + +function libopml_render_outline($parent_elt, $outline) { + // Outline MUST be an array! + if (!is_array($outline)) { + throw new LibOPML_Exception( + 'Outline element must be defined as array' + ); + } + + $outline_elt = $parent_elt->addChild('outline'); + $text_is_present = false; + foreach ($outline as $key => $value) { + // Only outlines can be an array and so we consider children are also + // outline elements. + if ($key === '@outlines' && is_array($value)) { + foreach ($value as $outline_child) { + libopml_render_outline($outline_elt, $outline_child); } + } elseif (is_array($value)) { + throw new LibOPML_Exception( + 'Type of outline elements cannot be array: ' . $key + ); } else { - // Flux rss sans catégorie, on récupère l'ajoute dans la catégorie par défaut - $feeds[] = getFeed ($outline, $defCat->id()); + // Detect text attribute is present, that's good :) + if ($key === 'text') { + $text_is_present = true; + } + + $outline_elt->addAttribute($key, $value); } } - return array ($categories, $feeds); + if (!$text_is_present) { + throw new LibOPML_Exception( + 'You must define at least a text element for all outlines' + ); + } } -/** - * import all feeds of a given outline tag - */ -function getFeedsOutline ($outline, $cat_id) { - $feeds = array (); - foreach ($outline->children () as $child) { - if (isset ($child['xmlUrl'])) { - $feeds[] = getFeed ($child, $cat_id); - } else { - $feeds = array_merge( - $feeds, - getFeedsOutline ($child, $cat_id) - ); +function libopml_render($array, $as_xml_object = false) { + $opml = new SimpleXMLElement(''); + + // Create head element. $array['head'] is optional but head element will + // exist in the final XML object. + $head = $opml->addChild('head'); + if (isset($array['head'])) { + foreach ($array['head'] as $key => $value) { + if (in_array($key, unserialize(HEAD_ELEMENTS), true)) { + $head->addChild($key, $value); + } } } - return $feeds; -} + // Check body is set and contains at least one element + if (!isset($array['body'])) { + throw new LibOPML_Exception( + '$array must contain a body element' + ); + } + if (count($array['body']) <= 0) { + throw new LibOPML_Exception( + 'Body element must contain at least one element (array)' + ); + } -function getFeed ($outline, $cat_id) { - $url = (string) $outline['xmlUrl']; - $url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8'); - $title = ''; - if (isset ($outline['text'])) { - $title = (string) $outline['text']; - } elseif (isset ($outline['title'])) { - $title = (string) $outline['title']; - } - $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); - $feed = new FreshRSS_Feed ($url); - $feed->_category ($cat_id); - $feed->_name ($title); - if (isset($outline['htmlUrl'])) { - $feed->_website(htmlspecialchars((string)$outline['htmlUrl'], ENT_COMPAT, 'UTF-8')); - } - if (isset($outline['description'])) { - $feed->_description(sanitizeHTML((string)$outline['description'])); - } - return $feed; + // Create outline elements + $body = $opml->addChild('body'); + foreach ($array['body'] as $outline) { + libopml_render_outline($body, $outline); + } + + // And return the final result + if ($as_xml_object) { + return $opml; + } else { + $dom = dom_import_simplexml($opml)->ownerDocument; + $dom->formatOutput = true; + $dom->encoding = 'UTF-8'; + return $dom->saveXML(); + } } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 2077fe63f..0f8161129 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -244,3 +244,7 @@ function cryptAvailable() { } return false; } + +function html_chars_utf8($str) { + return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); +} -- cgit v1.2.3 From 779afe9c4ee00f8099a423e1fceee40197a90cfa Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 30 Mar 2014 14:28:13 +0200 Subject: Import of articles is implemented! - Remove massiveImportAction and addCategories from FeedController - Fix typo for some methods (camelCase) - addCategoryObject and addFeedObject return id if corresponding object already exists in DB - introduce addEntryObject. Return -1 if Entry already exist (in order to keep quite good performances) - Complete importArticles method Need some more tests + better performance --- app/Controllers/feedController.php | 88 ---------------------------- app/Controllers/importExportController.php | 92 +++++++++++++++++++++--------- app/Models/CategoryDAO.php | 5 +- app/Models/EntryDAO.php | 30 ++++++++++ app/Models/FeedDAO.php | 5 +- 5 files changed, 100 insertions(+), 120 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 43435d99d..95c9c1e9c 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -327,82 +327,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - public function massiveImportAction () { - # TODO: this function has moved to importExportController.php - # I keep it for the moment but should be deleted in a near future. - @set_time_limit(300); - - $this->catDAO = new FreshRSS_CategoryDAO (); - $this->catDAO->checkDefault (); - - $entryDAO = new FreshRSS_EntryDAO (); - $feedDAO = new FreshRSS_FeedDAO (); - - $categories = Minz_Request::param ('categories', array (), true); - $feeds = Minz_Request::param ('feeds', array (), true); - - // on ajoute les catégories en masse dans une fonction à part - $this->addCategories ($categories); - - // on calcule la date des articles les plus anciens qu'on accepte - $nb_month_old = $this->view->conf->old_entries; - $date_min = time () - (3600 * 24 * 30 * $nb_month_old); - - // la variable $error permet de savoir si une erreur est survenue - // Le but est de ne pas arrêter l'import même en cas d'erreur - // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais - // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées - $error = false; - $i = 0; - foreach ($feeds as $feed) { - try { - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - 'lastUpdate' => 0, - 'httpAuth' => $feed->httpAuth () - ); - - // ajout du flux que s'il n'est pas déjà en BDD - if (!$feedDAO->searchByUrl ($values['url'])) { - $id = $feedDAO->addFeed ($values); - if ($id) { - $feed->_id ($id); - $feed->faviconPrepare(); - } else { - $error = true; - } - } - } catch (FreshRSS_Feed_Exception $e) { - $error = true; - Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); - } - } - - if ($error) { - $res = Minz_Translate::t ('feeds_imported_with_errors'); - } else { - $res = Minz_Translate::t ('feeds_imported'); - } - - $notif = array ( - 'type' => 'good', - 'content' => $res - ); - Minz_Session::_param ('notification', $notif); - Minz_Session::_param ('actualize_feeds', true); - - // et on redirige vers la page d'accueil - Minz_Request::forward (array ( - 'c' => 'index', - 'a' => 'index' - ), true); - } - public function deleteAction () { if (Minz_Request::isPost ()) { $type = Minz_Request::param ('type', 'feed'); @@ -446,16 +370,4 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } } - - private function addCategories ($categories) { - foreach ($categories as $cat) { - if (!$this->catDAO->searchByName ($cat->name ())) { - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - ); - $catDAO->addCategory ($values); - } - } - } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index b6b4d0fed..3b6bf2c5c 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -31,7 +31,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { @set_time_limit(300); $file = $_FILES['file']; - $type_file = $this->guess_file_type($file['name']); + $type_file = $this->guessFileType($file['name']); $list_files = array( 'opml' => array(), @@ -46,7 +46,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $zip = zip_open($file['tmp_name']); while (($zipfile = zip_read($zip)) !== false) { - $type_zipfile = $this->guess_file_type(zip_entry_name($zipfile)); + $type_zipfile = $this->guessFileType(zip_entry_name($zipfile)); if ($type_file !== 'unknown') { $list_files[$type_zipfile][] = zip_entry_read( @@ -67,13 +67,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // And finally all other files. $error = false; foreach ($list_files['opml'] as $opml_file) { - $error = $this->import_opml($opml_file); + $error = $this->importOpml($opml_file); } foreach ($list_files['json_starred'] as $article_file) { - $error = $this->import_articles($article_file, true); + $error = $this->importArticles($article_file, true); } foreach ($list_files['json_feed'] as $article_file) { - $error = $this->import_articles($article_file); + $error = $this->importArticles($article_file); } // And finally, we get import status and redirect to the home page @@ -107,7 +107,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { )); } - private function guess_file_type($filename) { + private function guessFileType($filename) { // A *very* basic guess file type function. Only based on filename // That's could be improved but should be enough, at least for a first // implementation. @@ -128,7 +128,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } } - private function import_opml($opml_file) { + private function importOpml($opml_file) { $opml_array = array(); try { $opml_array = libopml_parse_string($opml_file); @@ -164,7 +164,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { private function addFeedOpml($feed_elt, $parent_cat) { if (is_null($parent_cat)) { // This feed has no parent category so we get the default one - $parent_cat = $catDAO->getDefault()->name(); + $parent_cat = $this->catDAO->getDefault()->name(); } $cat = $this->catDAO->searchByName($parent_cat); @@ -199,7 +199,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $id = $this->feedDAO->addFeedObject($feed); $error = ($id === false); } catch (FreshRSS_Feed_Exception $e) { - Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + Minz_Log::warning($e->getMessage()); $error = true; } @@ -226,28 +226,23 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $error; } - private function import_articles($article_file, $starred = false) { + private function importArticles($article_file, $starred = false) { $article_object = json_decode($article_file, true); if (is_null($article_object)) { Minz_Log::warning('Try to import a non-JSON file'); return true; } + $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; + $google_compliant = (strpos($article_object['id'], 'com.google') !== false); + $error = false; foreach ($article_object['items'] as $item) { - $key = $google_compliant ? 'htmlUrl' : 'feedUrl'; - $feed = $this->feedDAO->searchByUrl($item['origin'][$key]); + $feed = $this->addFeedArticles($item['origin'], $google_compliant); if (is_null($feed)) { - $feed = new FreshRSS_Feed($item['origin'][$key]); - $feed->_name ($item['origin']['title']); - $feed->_website ($item['origin']['htmlUrl']); - - $error = $this->addFeed($feed); // TODO - - if ($error) { - continue; - } + $error = true; + continue; } $author = isset($item['author']) ? $item['author'] : ''; @@ -258,14 +253,55 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return strpos($var, '/state/com.google') === false; }); } + $entry = new FreshRSS_Entry( $feed->id(), $item['id'], $item['title'], $author, $item[$key_content]['content'], $item['alternate'][0]['href'], - $item['published'], false, $starred, $tags + $item['published'], $is_read, $starred ); + $entry->_tags($tags); - Minz_Log::debug(print_r($entry, true)); // TODO + $id = $this->entryDAO->addEntryObject( + $entry, $this->view->conf, $feed->keepHistory() + ); + + if (!$error && ($id === false)) { + $error = true; + } } + + return $error; + } + + private function addFeedArticles($origin, $google_compliant) { + $default_cat = $this->catDAO->getDefault(); + + $return = null; + $key = $google_compliant ? 'htmlUrl' : 'feedUrl'; + $url = $origin[$key]; + $name = $origin['title']; + $website = $origin['htmlUrl']; + $error = false; + try { + // Create a Feed object and add it in DB + $feed = new FreshRSS_Feed($url); + $feed->_category($default_cat->id()); + $feed->_name($name); + $feed->_website($website); + + // addFeedObject checks if feed is already in DB so nothing else to + // check here + $id = $this->feedDAO->addFeedObject($feed); + + if ($id !== false) { + $feed->_id($id); + $return = $feed; + } + } catch (FreshRSS_Feed_Exception $e) { + Minz_Log::warning($e->getMessage()); + } + + return $return; } public function exportAction() { @@ -283,16 +319,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // Stuff with content if ($export_opml) { - $zip->addFromString('feeds.opml', $this->generate_opml()); + $zip->addFromString('feeds.opml', $this->generateOpml()); } if ($export_starred) { - $zip->addFromString('starred.json', $this->generate_articles('starred')); + $zip->addFromString('starred.json', $this->generateArticles('starred')); } foreach ($export_feeds as $feed_id) { $feed = $this->feedDAO->searchById($feed_id); $zip->addFromString( 'feed_' . $feed->category() . '_' . $feed->id() . '.json', - $this->generate_articles('feed', $feed) + $this->generateArticles('feed', $feed) ); } @@ -306,7 +342,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } } - private function generate_opml() { + private function generateOpml() { $list = array(); foreach ($this->catDAO->listCategories() as $key => $cat) { $list[$key]['name'] = $cat->name(); @@ -317,7 +353,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $this->view->helperToString('export/opml'); } - private function generate_articles($type, $feed = NULL) { + private function generateArticles($type, $feed = NULL) { $this->view->categories = $this->catDAO->listCategories(); if ($type == 'starred') { diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 8be732b98..6a9b839b9 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -19,7 +19,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { } public function addCategoryObject($category) { - if (!$this->searchByName($category->name())) { + $cat = $this->searchByName($category->name()); + if (!$cat) { // Category does not exist yet in DB so we add it before continue $values = array( 'name' => $category->name(), @@ -27,7 +28,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { return $this->addCategory($values); } - return false; + return $cat->id(); } public function updateCategory ($id, $valuesTmp) { diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index e4cf128ea..6d00967fc 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -35,6 +35,36 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { } } + public function addEntryObject($entry, $conf, $feedHistory) { + $existingGuids = array_fill_keys( + $this->listLastGuidsByFeed($entry->feed(), 20), 1 + ); + + $nb_month_old = max($conf->old_entries, 1); + $date_min = time() - (3600 * 24 * 30 * $nb_month_old); + + $eDate = $entry->date(true); + + if ($feedHistory == -2) { + $feedHistory = $conf->keep_history_default; + } + + if (!isset($existingGuids[$entry->guid()]) && + ($feedHistory != 0 || $eDate >= $date_min)) { + $values = $entry->toArray(); + + $useDeclaredDate = empty($existingGuids); + $values['id'] = ($useDeclaredDate || $eDate < $date_min) ? + min(time(), $eDate) . uSecString() : + uTimeString(); + + return $this->addEntry($values); + } + + // We don't return Entry object to avoid a research in DB + return -1; + } + public function markFavorite($ids, $is_favorite = true) { if (!is_array($ids)) { $ids = array($ids); diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index eac21df7e..b65ff4af0 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -29,7 +29,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { // should not be aware about feed class // Add feed only if we don't find it in DB - if (!$this->searchByUrl($feed->url())) { + $feed_search = $this->searchByUrl($feed->url()); + if (!$feed_search) { $values = array( 'id' => $feed->id(), 'url' => $feed->url(), @@ -50,7 +51,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { return $id; } - return false; + return $feed_search->id(); } public function updateFeed ($id, $valuesTmp) { -- cgit v1.2.3 From 34b17b748efb996f0202815dcf095a45d28e38da Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 30 Mar 2014 14:55:29 +0200 Subject: Fix coding style --- app/Controllers/importExportController.php | 49 ++++++++++++++++++------------ app/layout/aside_feed.phtml | 2 +- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 3b6bf2c5c..02d62c890 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -20,9 +20,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->categories = $this->catDAO->listCategories(); $this->view->feeds = $this->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') . ' · '); } @@ -46,7 +43,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $zip = zip_open($file['tmp_name']); while (($zipfile = zip_read($zip)) !== false) { - $type_zipfile = $this->guessFileType(zip_entry_name($zipfile)); + $type_zipfile = $this->guessFileType( + zip_entry_name($zipfile) + ); if ($type_file !== 'unknown') { $list_files[$type_zipfile][] = zip_entry_read( @@ -58,7 +57,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { zip_close($zip); } elseif ($type_file !== 'unknown') { - $list_files[$type_file][] = file_get_contents($file['tmp_name']); + $list_files[$type_file][] = file_get_contents( + $file['tmp_name'] + ); } // Import different files. @@ -79,18 +80,19 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // And finally, we get import status and redirect to the home page $notif = null; if ($error === true) { - $notif = array( - 'type' => 'good', - 'content' => Minz_Translate::t('feeds_imported_with_errors') + $content_notif = Minz_Translate::t( + 'feeds_imported_with_errors' ); } else { - $notif = array( - 'type' => 'good', - 'content' => Minz_Translate::t('feeds_imported') + $content_notif = Minz_Translate::t( + 'feeds_imported' ); } - Minz_Session::_param('notification', $notif); + Minz_Session::_param('notification', array( + 'type' => 'good', + 'content' => $content_notif + )); Minz_Session::_param('actualize_feeds', true); Minz_Request::forward(array( @@ -235,7 +237,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; - $google_compliant = (strpos($article_object['id'], 'com.google') !== false); + $google_compliant = ( + strpos($article_object['id'], 'com.google') !== false + ); $error = false; foreach ($article_object['items'] as $item) { @@ -246,7 +250,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $author = isset($item['author']) ? $item['author'] : ''; - $key_content = $google_compliant && !isset($item['content']) ? 'summary' : 'content'; + $key_content = ($google_compliant && !isset($item['content'])) ? + 'summary' : 'content'; $tags = $item['categories']; if ($google_compliant) { $tags = array_filter($tags, function($var) { @@ -312,17 +317,21 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $export_starred = Minz_Request::param('export_starred', false); $export_feeds = Minz_Request::param('export_feeds', false); - // code from https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly + // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly $file = tempnam('tmp', 'zip'); $zip = new ZipArchive(); $zip->open($file, ZipArchive::OVERWRITE); // Stuff with content if ($export_opml) { - $zip->addFromString('feeds.opml', $this->generateOpml()); + $zip->addFromString( + 'feeds.opml', $this->generateOpml() + ); } if ($export_starred) { - $zip->addFromString('starred.json', $this->generateArticles('starred')); + $zip->addFromString( + 'starred.json', $this->generateArticles('starred') + ); } foreach ($export_feeds as $feed_id) { $feed = $this->feedDAO->searchById($feed_id); @@ -357,14 +366,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->categories = $this->catDAO->listCategories(); if ($type == 'starred') { - $this->view->list_title = Minz_Translate::t("starred_list"); + $this->view->list_title = Minz_Translate::t('starred_list'); $this->view->type = 'starred'; $this->view->entries = $this->entryDAO->listWhere( 's', '', 'all', 'ASC', $this->entryDAO->countUnreadReadFavorites()['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { - $this->view->list_title = Minz_Translate::t("feed_list", $feed->name()); + $this->view->list_title = Minz_Translate::t( + 'feed_list', $feed->name() + ); $this->view->type = 'feed/' . $feed->id(); $this->view->entries = $this->entryDAO->listWhere( 'f', $feed->id(), 'all', 'ASC', diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml index ae16efd96..1fad60af5 100644 --- a/app/layout/aside_feed.phtml +++ b/app/layout/aside_feed.phtml @@ -56,7 +56,7 @@ feeds)) { ?> feeds as $feed) { ?> nbEntries (); ?> -
  • +
  • ✇ name (); ?> -- cgit v1.2.3 From 8ef32a10c6fd8e4ace44a5e797f6176f80b9560e Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 30 Mar 2014 20:47:00 +0200 Subject: Improve compatibility PHP 5.3 --- app/Controllers/importExportController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 02d62c890..a9b103a34 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -368,9 +368,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if ($type == 'starred') { $this->view->list_title = Minz_Translate::t('starred_list'); $this->view->type = 'starred'; + $unread_fav = $this->entryDAO->countUnreadReadFavorites(); $this->view->entries = $this->entryDAO->listWhere( 's', '', 'all', 'ASC', - $this->entryDAO->countUnreadReadFavorites()['all'] + $unread_fav['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { $this->view->list_title = Minz_Translate::t( -- cgit v1.2.3 From 86066b1659e33eb5fdfbcae5fb7f0bd93604d442 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 13 Apr 2014 07:28:41 -0400 Subject: Add a new status for 'ALL' I made the conversion in every file I can think of. It should not have any reference to the string 'all' for the state context --- app/Controllers/importExportController.php | 4 ++-- app/Controllers/indexController.php | 8 ++++---- app/Models/Configuration.php | 3 ++- app/Models/EntryDAO.php | 9 ++++++--- app/views/configure/reading.phtml | 2 +- p/api/greader.php | 8 ++++---- 6 files changed, 19 insertions(+), 15 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index a9b103a34..b8253b7bd 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -370,7 +370,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->type = 'starred'; $unread_fav = $this->entryDAO->countUnreadReadFavorites(); $this->view->entries = $this->entryDAO->listWhere( - 's', '', 'all', 'ASC', + 's', '', FreshRSS_Configuration::STATE_ALL, 'ASC', $unread_fav['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { @@ -379,7 +379,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); $this->view->type = 'feed/' . $feed->id(); $this->view->entries = $this->entryDAO->listWhere( - 'f', $feed->id(), 'all', 'ASC', + 'f', $feed->id(), FreshRSS_Configuration::STATE_ALL, 'ASC', $this->view->conf->posts_per_page ); $this->view->feed = $feed; diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 243d887ac..48471b480 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -85,7 +85,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $state_param = Minz_Request::param ('state', null); $filter = Minz_Request::param ('search', ''); if (!empty($filter)) { - $state = 'all'; //Search always in read and unread articles + $state = FreshRSS_Configuration::STATE_ALL; //Search always in read and unread articles } $this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sort_order); $nb = Minz_Request::param ('nb', $this->view->conf->posts_per_page); @@ -108,7 +108,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { break; } if (!$hasUnread && ($state_param === null)) { - $this->view->state = $state = 'all'; + $this->view->state = $state = FreshRSS_Configuration::STATE_ALL; } } @@ -127,8 +127,8 @@ class FreshRSS_index_Controller extends Minz_ActionController { // on essaye de récupérer tous les articles if ($state === FreshRSS_Configuration::STATE_NOT_READ && empty($entries) && ($state_param === null)) { Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); - $this->view->state = 'all'; - $entries = $entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min, true, $keepHistoryDefault); + $this->view->state = FreshRSS_Configuration::STATE_ALL; + $entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter, $date_min, true, $keepHistoryDefault); } if (count($entries) <= $nb) { diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index f9ea47be6..e693542e0 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -1,6 +1,7 @@ data['default_view'] = $value === 'all' ? 'all' : self::STATE_NOT_READ; + $this->data['default_view'] = $value === self::STATE_ALL ? self::STATE_ALL : self::STATE_NOT_READ; } public function _display_posts ($value) { $this->data['display_posts'] = ((bool)$value) && $value !== 'no'; diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 2f5a9e1f6..b9cbfd584 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -406,7 +406,10 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { return isset ($entries[0]) ? $entries[0] : null; } - private function sqlListWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { + private function sqlListWhere($type = 'a', $id = '', $state = null , $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { + if (!$state) { + $state = FreshRSS_Configuration::STATE_ALL; + } $where = ''; $joinFeed = false; $values = array(); @@ -532,7 +535,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { . ($limit > 0 ? ' LIMIT ' . $limit : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ } - public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { + public function listWhere($type = 'a', $id = '', $state = null, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault); $sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags ' @@ -548,7 +551,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { return self::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listIdsWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { //For API + public function listIdsWhere($type = 'a', $id = '', $state = null, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { //For API list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault); $stm = $this->bd->prepare($sql); diff --git a/app/views/configure/reading.phtml b/app/views/configure/reading.phtml index b778a4d22..b277397b1 100644 --- a/app/views/configure/reading.phtml +++ b/app/views/configure/reading.phtml @@ -32,7 +32,7 @@ state & FreshRSS_Configuration::STATE_NOT_READ) { - $url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_NOT_READ; + if ($this->state & FreshRSS_Entry::STATE_NOT_READ) { + $url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_READ; $checked = 'true'; } else { - $url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_NOT_READ; + $url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_READ; $checked = 'false'; } ?> @@ -40,11 +40,11 @@ state & FreshRSS_Configuration::STATE_FAVORITE) { - $url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_FAVORITE; + if ($this->state & FreshRSS_Entry::STATE_FAVORITE) { + $url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_FAVORITE; $checked = 'true'; } else { - $url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_FAVORITE; + $url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_FAVORITE; $checked = 'false'; } ?> @@ -56,11 +56,11 @@ state & FreshRSS_Configuration::STATE_NOT_FAVORITE) { - $url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_NOT_FAVORITE; + if ($this->state & FreshRSS_Entry::STATE_NOT_FAVORITE) { + $url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_FAVORITE; $checked = 'true'; } else { - $url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_NOT_FAVORITE; + $url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_FAVORITE; $checked = 'false'; } ?> diff --git a/app/views/configure/reading.phtml b/app/views/configure/reading.phtml index b277397b1..456ab9522 100644 --- a/app/views/configure/reading.phtml +++ b/app/views/configure/reading.phtml @@ -32,11 +32,11 @@ diff --git a/p/api/greader.php b/p/api/greader.php index 9836f2f02..8a8623966 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -353,10 +353,10 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex switch ($exclude_target) { case 'user/-/state/com.google/read': - $state = FreshRSS_Configuration::STATE_NOT_READ; + $state = FreshRSS_Entry::STATE_NOT_READ; break; default: - $state = FreshRSS_Configuration::STATE_ALL; + $state = FreshRSS_Entry::STATE_ALL; break; } @@ -451,10 +451,10 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude switch ($exclude_target) { case 'user/-/state/com.google/read': - $state = FreshRSS_Configuration::STATE_NOT_READ; + $state = FreshRSS_Entry::STATE_NOT_READ; break; default: - $state = FreshRSS_Configuration::STATE_ALL; + $state = FreshRSS_Entry::STATE_ALL; break; } -- cgit v1.2.3 From d6f414108667f32fe2b480adeb7ec9c218db2f4a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 3 Jul 2014 21:26:30 +0200 Subject: Preparation for SQLite https://github.com/marienfressinaud/FreshRSS/issues/100 --- app/Controllers/configureController.php | 2 +- app/Controllers/entryController.php | 6 +- app/Controllers/feedController.php | 4 +- app/Controllers/importExportController.php | 2 +- app/Controllers/indexController.php | 2 +- app/Controllers/usersController.php | 6 +- app/Models/CategoryDAO.php | 12 ++-- app/Models/Entry.php | 2 +- app/Models/EntryDAO.php | 101 +++++++++++++++++------------ app/Models/EntryDAO_SQLite.php | 42 ++++++++++++ app/Models/Factory.php | 13 ++++ app/Models/FeedDAO.php | 46 ++++++------- app/Models/UserDAO.php | 31 ++++++--- app/SQL/install.sql.mysql.php | 60 +++++++++++++++++ app/SQL/install.sql.sqlite.php | 57 ++++++++++++++++ app/sql.php | 58 ----------------- lib/Minz/Configuration.php | 80 ++++++++++++++--------- lib/Minz/ModelPdo.php | 52 +++++++++------ 18 files changed, 375 insertions(+), 201 deletions(-) create mode 100644 app/Models/EntryDAO_SQLite.php create mode 100644 app/Models/Factory.php create mode 100644 app/SQL/install.sql.mysql.php create mode 100644 app/SQL/install.sql.sqlite.php delete mode 100644 app/sql.php (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 89130cae4..cb8e6528f 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -291,7 +291,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · '); - $entryDAO = new FreshRSS_EntryDAO(); + $entryDAO = FreshRSS_Factory::createEntryDao(); $this->view->nb_total = $entryDAO->count(); $this->view->size_user = $entryDAO->size(); diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index bbcb990f5..c2d897cf3 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -43,7 +43,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $nextGet = Minz_Request::param ('nextGet', $get); $idMax = Minz_Request::param ('idMax', 0); - $entryDAO = new FreshRSS_EntryDAO (); + $entryDAO = FreshRSS_Factory::createEntryDao(); if ($id == false) { if (!$get) { $entryDAO->markReadEntries ($idMax); @@ -85,7 +85,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $id = Minz_Request::param ('id'); if ($id) { - $entryDAO = new FreshRSS_EntryDAO (); + $entryDAO = FreshRSS_Factory::createEntryDao(); $entryDAO->markFavorite ($id, (bool)(Minz_Request::param ('is_favorite', true))); } } @@ -97,7 +97,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { // La table des entrées a tendance à grossir énormément // Cette action permet d'optimiser cette table permettant de grapiller un peu de place // Cette fonctionnalité n'est à appeler qu'occasionnellement - $entryDAO = new FreshRSS_EntryDAO(); + $entryDAO = FreshRSS_Factory::createEntryDao(); $entryDAO->optimizeTable(); $feedDAO = new FreshRSS_FeedDAO(); diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 5f5a40bc7..149557a48 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -102,7 +102,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; - $entryDAO = new FreshRSS_EntryDAO (); + $entryDAO = FreshRSS_Factory::createEntryDao(); $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order // on calcule la date des articles les plus anciens qu'on accepte @@ -217,7 +217,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { @set_time_limit(300); $feedDAO = new FreshRSS_FeedDAO (); - $entryDAO = new FreshRSS_EntryDAO (); + $entryDAO = FreshRSS_Factory::createEntryDao(); Minz_Session::_param('actualize_feeds', false); $id = Minz_Request::param ('id'); diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 3cd791781..12154d9b6 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -12,7 +12,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { require_once(LIB_PATH . '/lib_opml.php'); $this->catDAO = new FreshRSS_CategoryDAO(); - $this->entryDAO = new FreshRSS_EntryDAO(); + $this->entryDAO = FreshRSS_Factory::createEntryDao(); $this->feedDAO = new FreshRSS_FeedDAO(); } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index c3f39fbe5..46c9518c9 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -45,7 +45,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { } $catDAO = new FreshRSS_CategoryDAO(); - $entryDAO = new FreshRSS_EntryDAO(); + $entryDAO = FreshRSS_Factory::createEntryDao(); $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php index 38b8f829b..35fa3675f 100644 --- a/app/Controllers/usersController.php +++ b/app/Controllers/usersController.php @@ -99,7 +99,8 @@ class FreshRSS_users_Controller extends Minz_ActionController { public function createAction() { if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) { - require_once(APP_PATH . '/sql.php'); + $db = Minz_Configuration::dataBase(); + require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php'); $new_user_language = Minz_Request::param('new_user_language', $this->view->conf->language); if (!in_array($new_user_language, $this->view->conf->availableLanguages())) { @@ -170,7 +171,8 @@ class FreshRSS_users_Controller extends Minz_ActionController { public function deleteAction() { if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) { - require_once(APP_PATH . '/sql.php'); + $db = Minz_Configuration::dataBase(); + require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php'); $username = Minz_Request::param('username'); $ok = ctype_alnum($username); diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 6a9b839b9..3003dea0d 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -12,8 +12,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $this->bd->lastInsertId(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error addCategory: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -43,8 +43,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error updateCategory: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -58,8 +58,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error deleteCategory: ' . $info[2], Minz_Log::ERROR); return false; } } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index fa9066d5b..a24a902d5 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -154,7 +154,7 @@ class FreshRSS_Entry extends Minz_Model { // Gestion du contenu // On cherche à récupérer les articles en entier... même si le flux ne le propose pas if ($pathEntries) { - $entryDAO = new FreshRSS_EntryDAO(); + $entryDAO = FreshRSS_Factory::createEntryDao(); $entry = $entryDAO->searchByGuid($this->feed, $this->guid); if($entry) { diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 4e24541dc..9ba0d2128 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -1,9 +1,18 @@ prefix . 'entry`(id, guid, title, author, content_bin, link, date, is_read, is_favorite, id_feed, tags) ' - . 'VALUES(?, ?, ?, ?, COMPRESS(?), ?, ?, ?, ?, ?, ?)'; + $sql = 'INSERT INTO `' . $this->prefix . 'entry`(id, guid, title, author, ' + . ($this->isCompressed() ? 'content_bin' : 'content') + . ', link, date, is_read, is_favorite, id_feed, tags) ' + . 'VALUES(?, ?, ?, ?, ' + . ($this->isCompressed() ? 'COMPRESS(?)' : '?') + . ', ?, ?, ?, ?, ?, ?)'; $stm = $this->bd->prepare ($sql); $values = array ( @@ -23,9 +32,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $this->bd->lastInsertId(); } else { - $info = $stm->errorInfo(); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); if ((int)($info[0] / 1000) !== 23) { //Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries - Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2] + Minz_Log::record('SQL error addEntry: ' . $info[0] . ': ' . $info[1] . ' ' . $info[2] . ' while adding entry in feed ' . $valuesTmp['id_feed'] . ' with title: ' . $valuesTmp['title'], Minz_Log::ERROR); } /*else { Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2] @@ -78,14 +87,14 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markFavorite: ' . $info[2], Minz_Log::ERROR); return false; } } public function markRead($ids, $is_read = true) { - if (is_array($ids)) { + if (is_array($ids)) { //Many IDs at once if (count($ids) < 6) { //Speed heuristics $affected = 0; foreach ($ids as $id) { @@ -102,8 +111,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array_merge($values, $ids); $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute($values))) { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack(); return false; } @@ -121,8 +130,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { . 'SET f.cache_nbEntries=x.nbEntries, f.cache_nbUnreads=x.nbUnreads'; $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute())) { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack(); return false; } @@ -134,14 +143,14 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id ' . 'SET e.is_read = ?,' . 'f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' - . 'WHERE e.id=?'; - $values = array($is_read ? 1 : 0, $ids); + . 'WHERE e.id=? AND e.is_read<>?'; + $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); $stm = $this->bd->prepare($sql); if ($stm && $stm->execute($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -161,8 +170,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ()) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadEntries: ' . $info[2], Minz_Log::ERROR); return false; } } else { @@ -179,8 +188,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array ($idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadEntries: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -198,8 +207,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0)'; $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ())) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadEntries: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -220,8 +229,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCat: ' . $info[2], Minz_Log::ERROR); return false; } } else { @@ -233,8 +242,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array ($id, $idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCat: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -254,8 +263,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array ($id); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCat: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -278,8 +287,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCatName: ' . $info[2], Minz_Log::ERROR); return false; } } else { @@ -293,8 +302,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array($name, $idMax); $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute($values))) { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCatName: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack(); return false; } @@ -315,8 +324,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array($name); $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute($values))) { - $info = $stm->errorInfo(); - Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadCatName: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack(); return false; } @@ -337,8 +346,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadFeed: ' . $info[2], Minz_Log::ERROR); return false; } } else { @@ -350,8 +359,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array ($id, $idMax); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadFeed: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -364,8 +373,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $values = array ($id); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markReadFeed: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -378,7 +387,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { public function searchByGuid ($feed_id, $id) { // un guid est unique pour un flux donné - $sql = 'SELECT id, guid, title, author, UNCOMPRESS(content_bin) AS content, link, date, is_read, is_favorite, id_feed, tags ' + $sql = 'SELECT id, guid, title, author, ' + . ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content') + . ', link, date, is_read, is_favorite, id_feed, tags ' . 'FROM `' . $this->prefix . 'entry` WHERE id_feed=? AND guid=?'; $stm = $this->bd->prepare ($sql); @@ -394,7 +405,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { } public function searchById ($id) { - $sql = 'SELECT id, guid, title, author, UNCOMPRESS(content_bin) AS content, link, date, is_read, is_favorite, id_feed, tags ' + $sql = 'SELECT id, guid, title, author, ' + . ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content') + . ', link, date, is_read, is_favorite, id_feed, tags ' . 'FROM `' . $this->prefix . 'entry` WHERE id=?'; $stm = $this->bd->prepare ($sql); @@ -520,7 +533,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { $search .= 'AND e1.tags LIKE ? '; $values[] = '%' . $word .'%'; } else { - $search .= 'AND CONCAT(e1.title, UNCOMPRESS(e1.content_bin)) LIKE ? '; + $search .= 'AND CONCAT(e1.title, ' . ($this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ') LIKE ? '; $values[] = '%' . $word .'%'; } } @@ -539,7 +552,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) { list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault); - $sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags ' + $sql = 'SELECT e.id, e.guid, e.title, e.author, ' + . ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content') + . ', e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags ' . 'FROM `' . $this->prefix . 'entry` e ' . 'INNER JOIN (' . $sql diff --git a/app/Models/EntryDAO_SQLite.php b/app/Models/EntryDAO_SQLite.php new file mode 100644 index 000000000..f148f3c63 --- /dev/null +++ b/app/Models/EntryDAO_SQLite.php @@ -0,0 +1,42 @@ +markRead($id, $is_read); + } + return $affected; + } + } else { + $this->bd->beginTransaction(); + $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?'; + $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + if ($affected > 0) { + $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' + . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; + $values = array($ids); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } + $this->bd->commit(); + return $affected; + } + } +} diff --git a/app/Models/Factory.php b/app/Models/Factory.php new file mode 100644 index 000000000..bea89c114 --- /dev/null +++ b/app/Models/Factory.php @@ -0,0 +1,13 @@ +execute ($values)) { return $this->bd->lastInsertId(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error addFeed: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -76,8 +76,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error updateFeed: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -106,8 +106,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error updateLastUpdate: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -130,8 +130,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error changeCategory: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -155,8 +155,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error deleteFeed: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -181,8 +181,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ($values)) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error deleteFeedByCategory: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -301,8 +301,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute()) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error updateCachedValues: ' . $info[2], Minz_Log::ERROR); return false; } } @@ -313,11 +313,11 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $values = array($id); $this->bd->beginTransaction (); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); - $this->bd->rollBack (); - return false; - } + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error truncate: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } $affected = $stm->rowCount(); $sql = 'UPDATE `' . $this->prefix . 'feed` f ' @@ -325,8 +325,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $values = array ($id); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error truncate: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } @@ -350,8 +350,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { if ($stm && $stm->execute ()) { return $stm->rowCount(); } else { - $info = $stm->errorInfo(); - Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error cleanOldEntries: ' . $info[2], Minz_Log::ERROR); return false; } } diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php index a25b57f89..dcf847a62 100644 --- a/app/Models/UserDAO.php +++ b/app/Models/UserDAO.php @@ -2,33 +2,44 @@ class FreshRSS_UserDAO extends Minz_ModelPdo { public function createUser($username) { - require_once(APP_PATH . '/sql.php'); $db = Minz_Configuration::dataBase(); + require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php'); + + if (defined('SQL_CREATE_TABLES')) { + $sql = sprintf(SQL_CREATE_TABLES, $db['prefix'] . $username . '_', Minz_Translate::t('default_category')); + $stm = $c->prepare($sql); + $ok = $stm && $stm->execute(); + } else { + global $SQL_CREATE_TABLES; + if (is_array($SQL_CREATE_TABLES)) { + $ok = true; + foreach ($SQL_CREATE_TABLES as $instruction) { + $sql = sprintf($instruction, '', Minz_Translate::t('default_category')); + $stm = $c->prepare($sql); + $ok &= ($stm && $stm->execute()); + } + } + } - $sql = sprintf(SQL_CREATE_TABLES, $db['prefix'] . $username . '_'); - $stm = $this->bd->prepare($sql, array(PDO::ATTR_EMULATE_PREPARES => true)); - $values = array( - 'catName' => Minz_Translate::t('default_category'), - ); - if ($stm && $stm->execute($values)) { + if ($ok) { return true; } else { - $info = $stm->errorInfo(); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } } public function deleteUser($username) { - require_once(APP_PATH . '/sql.php'); $db = Minz_Configuration::dataBase(); + require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php'); $sql = sprintf(SQL_DROP_TABLES, $db['prefix'] . $username . '_'); $stm = $this->bd->prepare($sql); if ($stm && $stm->execute()) { return true; } else { - $info = $stm->errorInfo(); + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR); return false; } diff --git a/app/SQL/install.sql.mysql.php b/app/SQL/install.sql.mysql.php new file mode 100644 index 000000000..d509cb4a8 --- /dev/null +++ b/app/SQL/install.sql.mysql.php @@ -0,0 +1,60 @@ +bd = self::$sharedBd; $this->prefix = self::$sharedPrefix; return; } - $db = Minz_Configuration::dataBase (); - $driver_options = null; + $db = Minz_Configuration::dataBase(); try { $type = $db['type']; - if($type == 'mysql') { - $string = $type - . ':host=' . $db['host'] + if ($type === 'mysql') { + $string = 'mysql:host=' . $db['host'] . ';dbname=' . $db['base'] . ';charset=utf8'; $driver_options = array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + ); + $this->prefix = $db['prefix'] . Minz_Session::param('currentUser', '_') . '_'; + } elseif ($type === 'sqlite') { + $string = 'sqlite:' . DATA_PATH . '/' . Minz_Session::param('currentUser', '_') . '.sqlite'; + $driver_options = array( + //PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + ); + $this->prefix = ''; + } else { + throw new Minz_PDOConnectionException( + 'Invalid database type!', + $db['user'], Minz_Exception::ERROR ); - } elseif($type == 'sqlite') { - $string = $type . ':/' . DATA_PATH . $db['base'] . '.sqlite'; //TODO: DEBUG UTF-8 http://www.siteduzero.com/forum/sujet/sqlite-connexion-utf-8-18797 } + self::$sharedDbType = $type; + self::$sharedPrefix = $this->prefix; - $this->bd = new FreshPDO ( + $this->bd = new FreshPDO( $string, $db['user'], $db['password'], $driver_options ); self::$sharedBd = $this->bd; - - $this->prefix = $db['prefix'] . Minz_Session::param('currentUser', '_') . '_'; - self::$sharedPrefix = $this->prefix; } catch (Exception $e) { - throw new Minz_PDOConnectionException ( + throw new Minz_PDOConnectionException( $string, $db['user'], Minz_Exception::ERROR ); @@ -81,15 +93,15 @@ class Minz_ModelPdo { } public function size($all = false) { - $db = Minz_Configuration::dataBase (); + $db = Minz_Configuration::dataBase(); $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = ?'; - $values = array ($db['base']); + $values = array($db['base']); if (!$all) { $sql .= ' AND table_name LIKE ?'; $values[] = $this->prefix . '%'; } - $stm = $this->bd->prepare ($sql); - $stm->execute ($values); + $stm = $this->bd->prepare($sql); + $stm->execute($values); $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); return $res[0]; } @@ -107,12 +119,12 @@ class FreshPDO extends PDO { } } - public function prepare ($statement, $driver_options = array()) { + public function prepare($statement, $driver_options = array()) { FreshPDO::check($statement); return parent::prepare($statement, $driver_options); } - public function exec ($statement) { + public function exec($statement) { FreshPDO::check($statement); return parent::exec($statement); } -- cgit v1.2.3 From b34f59e85aa851b82210fdc50074918034f960db Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 3 Jul 2014 22:48:29 +0200 Subject: Preparation #3 for SQLite https://github.com/marienfressinaud/FreshRSS/issues/100 --- app/Controllers/configureController.php | 6 +++--- app/Controllers/entryController.php | 4 ++-- app/Controllers/feedController.php | 8 ++++---- app/Controllers/importExportController.php | 2 +- app/Controllers/indexController.php | 4 ++-- app/Controllers/javascriptController.php | 2 +- app/Models/Category.php | 2 +- app/Models/Entry.php | 2 +- app/Models/EntryDAOSQLite.php | 10 +++++----- app/Models/Factory.php | 9 +++++++++ app/Models/Feed.php | 4 ++-- app/Models/FeedDAO.php | 16 ++++++++-------- app/Models/FeedDAOSQLite.php | 5 +++++ p/api/greader.php | 2 +- 14 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 app/Models/FeedDAOSQLite.php (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index cb8e6528f..a608df162 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -14,7 +14,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } public function categorizeAction () { - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $catDAO = new FreshRSS_CategoryDAO (); $defaultCategory = $catDAO->getDefault (); $defaultId = $defaultCategory->id (); @@ -70,7 +70,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $catDAO = new FreshRSS_CategoryDAO (); $this->view->categories = $catDAO->listCategories (false); - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->view->feeds = $feedDAO->listFeeds (); $id = Minz_Request::param ('id'); @@ -336,7 +336,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { ); break; case 'f': - $dao = new FreshRSS_FeedDAO(); + $dao = FreshRSS_Factory::createFeedDao(); $feed = $dao->searchById(substr($query['get'], 2)); $this->view->query_get[$key] = array( 'type' => 'feed', diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index c2d897cf3..2d7fa718a 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -100,7 +100,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $entryDAO = FreshRSS_Factory::createEntryDao(); $entryDAO->optimizeTable(); - $feedDAO = new FreshRSS_FeedDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao(); $feedDAO->updateCachedValues(); invalidateHttpCache(); @@ -124,7 +124,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $nb_month_old = max($this->view->conf->old_entries, 1); $date_min = time() - (3600 * 24 * 30 * $nb_month_old); - $feedDAO = new FreshRSS_FeedDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao(); $feeds = $feedDAO->listFeedsOrderUpdate(); $nbTotal = 0; diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 149557a48..d30b60877 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -31,7 +31,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { ), true); } - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->catDAO = new FreshRSS_CategoryDAO (); $this->catDAO->checkDefault (); @@ -201,7 +201,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { public function truncateAction () { if (Minz_Request::isPost ()) { $id = Minz_Request::param ('id'); - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $n = $feedDAO->truncate($id); $notif = array( 'type' => $n === false ? 'bad' : 'good', @@ -216,7 +216,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { public function actualizeAction () { @set_time_limit(300); - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $entryDAO = FreshRSS_Factory::createEntryDao(); Minz_Session::_param('actualize_feeds', false); @@ -375,7 +375,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $type = Minz_Request::param ('type', 'feed'); $id = Minz_Request::param ('id'); - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); if ($type == 'category') { if ($feedDAO->deleteFeedByCategory ($id)) { $notif = array ( diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 12154d9b6..6b4c3e81a 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -13,7 +13,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->catDAO = new FreshRSS_CategoryDAO(); $this->entryDAO = FreshRSS_Factory::createEntryDao(); - $this->feedDAO = new FreshRSS_FeedDAO(); + $this->feedDAO = FreshRSS_Factory::createFeedDao(); } public function indexAction() { diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 46c9518c9..4340865ec 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -126,7 +126,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { // on essaye de récupérer tous les articles if ($state === FreshRSS_Entry::STATE_NOT_READ && empty($entries) && ($state_param === null)) { Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); - $feedDAO = new FreshRSS_FeedDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao(); try { $feedDAO->updateCachedValues(); } catch (Exception $ex) { @@ -187,7 +187,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { case 'f': $feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId); if (empty($feed)) { - $feedDAO = new FreshRSS_FeedDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao(); $feed = $feedDAO->searchById($getId); } if ($feed) { diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index 3d741e298..737908c91 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -7,7 +7,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { public function actualizeAction () { header('Content-Type: text/javascript; charset=UTF-8'); - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->view->feeds = $feedDAO->listFeedsOrderUpdate(); } diff --git a/app/Models/Category.php b/app/Models/Category.php index 328bae799..0a0dbd3ca 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -44,7 +44,7 @@ class FreshRSS_Category extends Minz_Model { } public function feeds () { if ($this->feeds === null) { - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->feeds = $feedDAO->listByCategory ($this->id ()); $this->nbFeed = 0; $this->nbNotRead = 0; diff --git a/app/Models/Entry.php b/app/Models/Entry.php index a24a902d5..0bf1f2616 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -74,7 +74,7 @@ class FreshRSS_Entry extends Minz_Model { } public function feed ($object = false) { if ($object) { - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); return $feedDAO->searchById ($this->feed); } else { return $this->feed; diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 45d3a3ea9..0a837b3aa 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -13,24 +13,24 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { } } else { $this->bd->beginTransaction(); - $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?'; + $sql = 'UPDATE `' . $this->prefix . 'entry` SET is_read=? WHERE id=? AND is_read<>?'; $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute ($values))) { $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); - Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + Minz_Log::record('SQL error markRead 1: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } $affected = $stm->rowCount(); if ($affected > 0) { - $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' - . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; + $sql = 'UPDATE `' . $this->prefix . 'feed` SET cache_nbUnreads=cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' + . 'WHERE id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; $values = array($ids); $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute ($values))) { $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); - Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + Minz_Log::record('SQL error markRead 2: ' . $info[2], Minz_Log::ERROR); $this->bd->rollBack (); return false; } diff --git a/app/Models/Factory.php b/app/Models/Factory.php index 3ef68c41d..95d21a277 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -2,6 +2,15 @@ class FreshRSS_Factory { + public static function createFeedDao() { + $db = Minz_Configuration::dataBase(); + if ($db['type'] === 'sqlite') { + return new FreshRSS_FeedDAOSQLite(); + } else { + return new FreshRSS_FeedDAO(); + } + } + public static function createEntryDao() { $db = Minz_Configuration::dataBase(); if ($db['type'] === 'sqlite') { diff --git a/app/Models/Feed.php b/app/Models/Feed.php index ba142c8c8..8093b2bfd 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -87,7 +87,7 @@ class FreshRSS_Feed extends Minz_Model { } public function nbEntries () { if ($this->nbEntries < 0) { - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->nbEntries = $feedDAO->countEntries ($this->id ()); } @@ -95,7 +95,7 @@ class FreshRSS_Feed extends Minz_Model { } public function nbNotRead () { if ($this->nbNotRead < 0) { - $feedDAO = new FreshRSS_FeedDAO (); + $feedDAO = FreshRSS_Factory::createFeedDao(); $this->nbNotRead = $feedDAO->countNotRead ($this->id ()); } diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 3f3847aa4..9534d61bd 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -84,15 +84,15 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { public function updateLastUpdate ($id, $inError = 0, $updateCache = true) { if ($updateCache) { - $sql = 'UPDATE `' . $this->prefix . 'feed` f ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE - . 'SET f.cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=f.id),' - . 'f.cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=f.id AND e2.is_read=0),' + $sql = 'UPDATE `' . $this->prefix . 'feed` ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE + . 'SET cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=feed.id),' + . 'cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=feed.id AND e2.is_read=0),' . 'lastUpdate=?, error=? ' - . 'WHERE f.id=?'; + . 'WHERE id=?'; } else { - $sql = 'UPDATE `' . $this->prefix . 'feed` f ' + $sql = 'UPDATE `' . $this->prefix . 'feed` ' . 'SET lastUpdate=?, error=? ' - . 'WHERE f.id=?'; + . 'WHERE id=?'; } $values = array ( @@ -320,8 +320,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } $affected = $stm->rowCount(); - $sql = 'UPDATE `' . $this->prefix . 'feed` f ' - . 'SET f.cache_nbEntries=0, f.cache_nbUnreads=0 WHERE f.id=?'; + $sql = 'UPDATE `' . $this->prefix . 'feed` ' + . 'SET cache_nbEntries=0, cache_nbUnreads=0 WHERE id=?'; $values = array ($id); $stm = $this->bd->prepare ($sql); if (!($stm && $stm->execute ($values))) { diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.php new file mode 100644 index 000000000..f3c92149e --- /dev/null +++ b/app/Models/FeedDAOSQLite.php @@ -0,0 +1,5 @@ +arrayFeedCategoryNames(); switch ($path) { -- cgit v1.2.3 From 439a0e2991231db51232646736a4bf78cfb2bffd Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 7 Jul 2014 18:25:48 +0200 Subject: SQL: improved performance for adding new articles --- app/Controllers/feedController.php | 28 +++++++++++++++++----------- app/Controllers/importExportController.php | 1 + app/Models/EntryDAO.php | 8 ++++++-- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 36425ca9b..3326b2059 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -109,18 +109,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $nb_month_old = $this->view->conf->old_entries; $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + //MySQL: http://docs.oracle.com/cd/E17952_01/refman-5.5-en/optimizing-innodb-transaction-management.html + //SQLite: http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite + $preparedStatement = $entryDAO->addEntryPrepare(); $transactionStarted = true; - $feedDAO->beginTransaction (); + $feedDAO->beginTransaction(); // on ajoute les articles en masse sans vérification foreach ($entries as $entry) { - $values = $entry->toArray (); - $values['id_feed'] = $feed->id (); - $values['id'] = min(time(), $entry->date (true)) . uSecString(); + $values = $entry->toArray(); + $values['id_feed'] = $feed->id(); + $values['id'] = min(time(), $entry->date(true)) . uSecString(); $values['is_read'] = $is_read; - $entryDAO->addEntry ($values); + $entryDAO->addEntry($values, $preparedStatement); + } + $feedDAO->updateLastUpdate($feed->id()); + if ($transactionStarted) { + $feedDAO->commit(); } - $feedDAO->updateLastUpdate ($feed->id ()); - $feedDAO->commit (); $transactionStarted = false; // ok, ajout terminé @@ -265,22 +270,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedHistory = $this->view->conf->keep_history_default; } + $preparedStatement = $entryDAO->addEntryPrepare(); $hasTransaction = true; $feedDAO->beginTransaction(); // On ne vérifie pas strictement que l'article n'est pas déjà en BDD // La BDD refusera l'ajout car (id_feed, guid) doit être unique foreach ($entries as $entry) { - $eDate = $entry->date (true); - if ((!isset ($existingGuids[$entry->guid ()])) && + $eDate = $entry->date(true); + if ((!isset($existingGuids[$entry->guid()])) && (($feedHistory != 0) || ($eDate >= $date_min))) { - $values = $entry->toArray (); + $values = $entry->toArray(); //Use declared date at first import, otherwise use discovery date $values['id'] = ($useDeclaredDate || $eDate < $date_min) ? min(time(), $eDate) . uSecString() : uTimeString(); $values['is_read'] = $is_read; - $entryDAO->addEntry ($values); + $entryDAO->addEntry($values, $preparedStatement); } } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 6b4c3e81a..ba172cc6d 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -266,6 +266,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); $entry->_tags($tags); + //FIME: Use entryDAO->addEntryPrepare(). Do not call entryDAO->listLastGuidsByFeed() for each entry. Consider using a transaction. $id = $this->entryDAO->addEntryObject( $entry, $this->view->conf, $feed->keepHistory() ); diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 1775af63c..6f3f472f6 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -6,14 +6,18 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { return parent::$sharedDbType !== 'sqlite'; } - public function addEntry($valuesTmp) { + public function addEntryPrepare() { $sql = 'INSERT INTO `' . $this->prefix . 'entry`(id, guid, title, author, ' . ($this->isCompressed() ? 'content_bin' : 'content') . ', link, date, is_read, is_favorite, id_feed, tags) ' . 'VALUES(?, ?, ?, ?, ' . ($this->isCompressed() ? 'COMPRESS(?)' : '?') . ', ?, ?, ?, ?, ?, ?)'; - $stm = $this->bd->prepare($sql); + return $this->bd->prepare($sql); + } + + public function addEntry($valuesTmp, $preparedStatement = null) { + $stm = $preparedStatement === null ? addEntryPrepare() : $preparedStatement; $values = array( $valuesTmp['id'], -- cgit v1.2.3 From 84826491a3fac3bde21c07ad69b114e5b56ed297 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 8 Aug 2014 23:53:16 +0200 Subject: Improve export function If there is only one file to export, we don't need of a .zip archive. So it is exported as a simple file (.json or .opml) See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 74 ++++++++++++++++++++---------- app/views/importExport/export.phtml | 0 2 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 app/views/importExport/export.phtml (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index ba172cc6d..67c6eb867 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -316,39 +316,42 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $export_opml = Minz_Request::param('export_opml', false); $export_starred = Minz_Request::param('export_starred', false); - $export_feeds = Minz_Request::param('export_feeds', false); + $export_feeds = Minz_Request::param('export_feeds', array ()); - // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly - $file = tempnam('tmp', 'zip'); - $zip = new ZipArchive(); - $zip->open($file, ZipArchive::OVERWRITE); - - // Stuff with content + $export_files = array (); if ($export_opml) { - $zip->addFromString( - 'feeds.opml', $this->generateOpml() - ); + $export_files['feeds.opml'] = $this->generateOpml(); } + if ($export_starred) { - $zip->addFromString( - 'starred.json', $this->generateArticles('starred') - ); + $export_files['starred.json'] = $this->generateArticles('starred'); } + foreach ($export_feeds as $feed_id) { $feed = $this->feedDAO->searchById($feed_id); - $zip->addFromString( - 'feed_' . $feed->category() . '_' . $feed->id() . '.json', - $this->generateArticles('feed', $feed) + $filename = 'feed_' . $feed->category() . '_' + . $feed->id() . '.json'; + $export_files[$filename] = $this->generateArticles( + 'feed', $feed ); } - // Close and send to user - $zip->close(); - header('Content-Type: application/zip'); - header('Content-Length: ' . filesize($file)); - header('Content-Disposition: attachment; filename="freshrss_export.zip"'); - readfile($file); - unlink($file); + $nb_files = count($export_files); + if ($nb_files > 1) { + // If there are more than 1 file to export, we need an .zip + $this->exportZip($export_files); + } elseif ($nb_files === 1) { + // Only one file? Guess its type and export it. + $filename = key($export_files); + $type = null; + if (substr_compare($filename, '.opml', -5) === 0) { + $type = "text/xml"; + } elseif (substr_compare($filename, '.json', -5) === 0) { + $type = "text/json"; + } + + $this->exportFile($filename, $export_files[$filename], $type); + } } } @@ -388,4 +391,29 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $this->view->helperToString('export/articles'); } + + private function exportZip($files) { + // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly + $zip_file = tempnam('tmp', 'zip'); + $zip = new ZipArchive(); + $zip->open($zip_file, ZipArchive::OVERWRITE); + + foreach ($files as $filename => $content) { + $zip->addFromString($filename, $content); + } + + // Close and send to user + $zip->close(); + header('Content-Type: application/zip'); + header('Content-Length: ' . filesize($zip_file)); + header('Content-Disposition: attachment; filename="freshrss_export.zip"'); + readfile($zip_file); + unlink($zip_file); + } + + private function exportFile($filename, $content, $type) { + header('Content-Type: ' . $type . '; charset=utf-8'); + header('Content-disposition: attachment; filename=' . $filename); + print($content); + } } diff --git a/app/views/importExport/export.phtml b/app/views/importExport/export.phtml new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From fda8eba4d147a7624f64c03001df1d317804c0d4 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 9 Aug 2014 00:12:37 +0200 Subject: Add a test to check presence of Zip archive. A notification is shown if we cannot use ZipArchive. See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 22 +++++++++++++++++++++- app/i18n/en.php | 1 + app/i18n/fr.php | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 67c6eb867..ba4ca4eb0 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -339,7 +339,17 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $nb_files = count($export_files); if ($nb_files > 1) { // If there are more than 1 file to export, we need an .zip - $this->exportZip($export_files); + try { + $this->exportZip($export_files); + } catch (Exception $e) { + # Oops, there is no Zip extension! + $notif = array( + 'type' => 'bad', + 'content' => _t('export_no_zip_extension') + ); + Minz_Session::_param('notification', $notif); + Minz_Request::forward(array('c' => 'importExport'), true); + } } elseif ($nb_files === 1) { // Only one file? Guess its type and export it. $filename = key($export_files); @@ -351,6 +361,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $this->exportFile($filename, $export_files[$filename], $type); + } else { + Minz_Request::forward(array('c' => 'importExport'), true); } } } @@ -393,6 +405,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function exportZip($files) { + if (!extension_loaded('zip')) { + throw new Exception(); + } + // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly $zip_file = tempnam('tmp', 'zip'); $zip = new ZipArchive(); @@ -412,6 +428,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function exportFile($filename, $content, $type) { + if (is_null($type)) { + return; + } + header('Content-Type: ' . $type . '; charset=utf-8'); header('Content-disposition: attachment; filename=' . $filename); print($content); diff --git a/app/i18n/en.php b/app/i18n/en.php index 9e5bfb223..532327e4a 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -185,6 +185,7 @@ return array ( 'export' => 'Export', 'export_opml' => 'Export list of feeds (OPML)', 'export_starred' => 'Export your favourites', + 'export_no_zip_extension' => 'Zip extension is not present on your server. Please try to export files one by one.', 'starred_list' => 'List of favourite articles', 'feed_list' => 'List of %s articles', 'or' => 'or', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 94d2e5f06..1f2844d47 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -185,6 +185,7 @@ return array ( 'export' => 'Exporter', 'export_opml' => 'Exporter la liste des flux (OPML)', 'export_starred' => 'Exporter les favoris', + 'export_no_zip_extension' => 'L’extension Zip n’est pas présente sur votre serveur. Veuillez essayer d’exporter les fichiers un par un.', 'starred_list' => 'Liste des articles favoris', 'feed_list' => 'Liste des articles de %s', 'or' => 'ou', -- cgit v1.2.3 From d007b22beb701b78968db420c3be6336ee98a350 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 9 Aug 2014 00:23:22 +0200 Subject: Change view import/export if no zip extension Show a select with only one choice is there is no zip extension on the server. Fix typo. See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 12 +++++++----- app/views/importExport/index.phtml | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index ba4ca4eb0..2b3353d93 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -329,11 +329,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { foreach ($export_feeds as $feed_id) { $feed = $this->feedDAO->searchById($feed_id); - $filename = 'feed_' . $feed->category() . '_' - . $feed->id() . '.json'; - $export_files[$filename] = $this->generateArticles( - 'feed', $feed - ); + if ($feed) { + $filename = 'feed_' . $feed->category() . '_' + . $feed->id() . '.json'; + $export_files[$filename] = $this->generateArticles( + 'feed', $feed + ); + } } $nb_files = count($export_files); diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index 309058959..d7df1619d 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -1,12 +1,12 @@ -partial ('aside_feed'); ?> +partial('aside_feed'); ?>
    - +
    - +
    - +
    @@ -14,27 +14,34 @@
    - +
    feeds) > 0) { ?>
    - +
    - > + '; ?> feeds as $feed) { ?> @@ -44,7 +51,7 @@
    - +
    -- cgit v1.2.3 From 94570aaf5a23dfc02bf1120d168ec30c2ab3f044 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 11 Aug 2014 19:02:27 +0200 Subject: Improve system import/export Miss checking presence of zip extension during import See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 10 +++++++++- app/i18n/en.php | 2 ++ app/i18n/fr.php | 2 ++ app/views/importExport/index.phtml | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2b3353d93..dd6c23322 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -39,7 +39,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // We try to list all files according to their type // A zip file is first opened and then its files are listed $list = array(); - if ($type_file === 'zip') { + if ($type_file === 'zip' && extension_loaded('zip')) { $zip = zip_open($file['tmp_name']); while (($zipfile = zip_read($zip)) !== false) { @@ -56,6 +56,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } zip_close($zip); + } elseif ($type_file === 'zip') { + // Zip extension is not loaded + Minz_Session::_param('notification', array( + 'type' => 'bad', + 'content' => _t('no_zip_extension') + )); + + Minz_Request::forward(array('c' => 'importExport'), true); } elseif ($type_file !== 'unknown') { $list_files[$type_file][] = file_get_contents( $file['tmp_name'] diff --git a/app/i18n/en.php b/app/i18n/en.php index 748d9a81b..0c87f52be 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -182,7 +182,9 @@ return array ( 'focus_search' => 'Access search box', 'file_to_import' => 'File to import
    (OPML, Json or Zip)', + 'file_to_import_no_zip' => 'File to import
    (OPML or Json)', 'import' => 'Import', + 'no_zip_extension' => 'Zip extension is not present on your server.', 'export' => 'Export', 'export_opml' => 'Export list of feeds (OPML)', 'export_starred' => 'Export your favourites', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index ba8c8686a..57ddebc20 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -182,7 +182,9 @@ return array ( 'focus_search' => 'Accéder à la recherche', 'file_to_import' => 'Fichier à importer
    (OPML, Json ou Zip)', + 'file_to_import_no_zip' => 'Fichier à importer
    (OPML ou Json)', 'import' => 'Importer', + 'no_zip_extension' => 'L’extension Zip n’est pas présente sur votre serveur.', 'export' => 'Exporter', 'export_opml' => 'Exporter la liste des flux (OPML)', 'export_starred' => 'Exporter les favoris', diff --git a/app/views/importExport/index.phtml b/app/views/importExport/index.phtml index e1458e916..35371faca 100644 --- a/app/views/importExport/index.phtml +++ b/app/views/importExport/index.phtml @@ -6,7 +6,9 @@
    - +
    -- cgit v1.2.3 From 8ffd59f34ac458827f2a0217e4630caf69705853 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 11 Aug 2014 19:18:12 +0200 Subject: Improve import system Catch errors of zip_open and log it. A notification is shown to indicate something went wrong. See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 14 ++++++++++++++ app/i18n/en.php | 1 + app/i18n/fr.php | 1 + 3 files changed, 16 insertions(+) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index dd6c23322..15871ed80 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -42,6 +42,20 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if ($type_file === 'zip' && extension_loaded('zip')) { $zip = zip_open($file['tmp_name']); + if (!is_resource($zip)) { + Minz_Log::error( + 'Zip file cannot be imported. Error code: ' . $zip + ); + + // zip_open cannot open file: something is wrong + Minz_Session::_param('notification', array( + 'type' => 'bad', + 'content' => _t('zip_error') + )); + + Minz_Request::forward(array('c' => 'importExport'), true); + } + while (($zipfile = zip_read($zip)) !== false) { $type_zipfile = $this->guessFileType( zip_entry_name($zipfile) diff --git a/app/i18n/en.php b/app/i18n/en.php index 0c87f52be..416ca851f 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -184,6 +184,7 @@ return array ( 'file_to_import' => 'File to import
    (OPML, Json or Zip)', 'file_to_import_no_zip' => 'File to import
    (OPML or Json)', 'import' => 'Import', + 'zip_error' => 'An error occured during Zip import.', 'no_zip_extension' => 'Zip extension is not present on your server.', 'export' => 'Export', 'export_opml' => 'Export list of feeds (OPML)', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 57ddebc20..d68006a87 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -184,6 +184,7 @@ return array ( 'file_to_import' => 'Fichier à importer
    (OPML, Json ou Zip)', 'file_to_import_no_zip' => 'Fichier à importer
    (OPML ou Json)', 'import' => 'Importer', + 'zip_error' => 'Une erreur est survenue durant l’import du fichier Zip.', 'no_zip_extension' => 'L’extension Zip n’est pas présente sur votre serveur.', 'export' => 'Exporter', 'export_opml' => 'Exporter la liste des flux (OPML)', -- cgit v1.2.3 From 1b20f6bd025a08a7a741b2751d837f736758eb2d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 12 Aug 2014 20:59:27 +0200 Subject: New wrappers Minz_Request::good() and bad() 1. Set a notification message in session variable 2. Redirect to a specific url First use in importExportController.php See https://github.com/marienfressinaud/FreshRSS/conversations/576 --- app/Controllers/importExportController.php | 57 ++++++------------------------ lib/Minz/Request.php | 25 +++++++++++++ 2 files changed, 35 insertions(+), 47 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 15871ed80..92b39b575 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -43,17 +43,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $zip = zip_open($file['tmp_name']); if (!is_resource($zip)) { - Minz_Log::error( - 'Zip file cannot be imported. Error code: ' . $zip - ); - // zip_open cannot open file: something is wrong - Minz_Session::_param('notification', array( - 'type' => 'bad', - 'content' => _t('zip_error') - )); - - Minz_Request::forward(array('c' => 'importExport'), true); + Minz_Log::error('Zip file cannot be imported. Error code: ' . $zip); + Minz_Request::bad(_t('zip_error'), array('c' => 'importExport')); } while (($zipfile = zip_read($zip)) !== false) { @@ -72,12 +64,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { zip_close($zip); } elseif ($type_file === 'zip') { // Zip extension is not loaded - Minz_Session::_param('notification', array( - 'type' => 'bad', - 'content' => _t('no_zip_extension') - )); - - Minz_Request::forward(array('c' => 'importExport'), true); + Minz_Request::bad(_t('no_zip_extension'), array('c' => 'importExport')); } elseif ($type_file !== 'unknown') { $list_files[$type_file][] = file_get_contents( $file['tmp_name'] @@ -100,35 +87,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } // And finally, we get import status and redirect to the home page - $notif = null; - if ($error === true) { - $content_notif = Minz_Translate::t( - 'feeds_imported_with_errors' - ); - } else { - $content_notif = Minz_Translate::t( - 'feeds_imported' - ); - } - - Minz_Session::_param('notification', array( - 'type' => 'good', - 'content' => $content_notif - )); Minz_Session::_param('actualize_feeds', true); - Minz_Request::forward(array( - 'c' => 'index', - 'a' => 'index' - ), true); + $content_notif = $error === true ? _t('feeds_imported_with_errors') : + _t('feeds_imported'); + Minz_Request::good($content_notif); } // What are you doing? you have to call this controller // with a POST request! - Minz_Request::forward(array( - 'c' => 'importExport', - 'a' => 'index' - )); + Minz_Request::forward(array('c' => 'importExport')); } private function guessFileType($filename) { @@ -362,17 +330,12 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $nb_files = count($export_files); if ($nb_files > 1) { - // If there are more than 1 file to export, we need an .zip + // If there are more than 1 file to export, we need a zip archive. try { $this->exportZip($export_files); } catch (Exception $e) { # Oops, there is no Zip extension! - $notif = array( - 'type' => 'bad', - 'content' => _t('export_no_zip_extension') - ); - Minz_Session::_param('notification', $notif); - Minz_Request::forward(array('c' => 'importExport'), true); + Minz_Request::bad(_t('export_no_zip_extension'), array('c' => 'importExport')); } } elseif ($nb_files === 1) { // Only one file? Guess its type and export it. @@ -386,7 +349,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->exportFile($filename, $export_files[$filename], $type); } else { - Minz_Request::forward(array('c' => 'importExport'), true); + Minz_Request::forward(array('c' => 'importExport')); } } } diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 755784522..2f745a04c 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -146,6 +146,31 @@ class Minz_Request { } } + + /** + * Wrappers good notifications + redirection + * @param $msg notification content + * @param $url url array to where we should be forwarded + */ + public static function good($msg, $url = array()) { + Minz_Session::_param('notification', array( + 'type' => 'good', + 'content' => $msg + )); + + Minz_Request::forward($url, true); + } + + public static function bad($msg, $url = array()) { + Minz_Session::_param('notification', array( + 'type' => 'bad', + 'content' => $msg + )); + + Minz_Request::forward($url, true); + } + + /** * Permet de récupérer une variable de type $_GET * @param $param nom de la variable -- cgit v1.2.3 From 7900c5e550acafaf0b877635840a8a270eb06078 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 12 Aug 2014 21:56:34 +0200 Subject: Move htmlspecialchars_utf8 from Request to Helper And remove html_chars_utf8 to use htmlspecialchars_utf8 instead in importExportController --- app/Controllers/importExportController.php | 10 +++++----- lib/Minz/Helper.php | 11 +++++++++++ lib/Minz/Request.php | 8 +------- lib/lib_rss.php | 4 ---- 4 files changed, 17 insertions(+), 16 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 92b39b575..a8e2c2bc2 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -166,15 +166,15 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } // We get different useful information - $url = html_chars_utf8($feed_elt['xmlUrl']); - $name = html_chars_utf8($feed_elt['text']); + $url = Minz_Helper::htmlspecialchars_utf8($feed_elt['xmlUrl']); + $name = Minz_Helper::htmlspecialchars_utf8($feed_elt['text']); $website = ''; if (isset($feed_elt['htmlUrl'])) { - $website = html_chars_utf8($feed_elt['htmlUrl']); + $website = Minz_Helper::htmlspecialchars_utf8($feed_elt['htmlUrl']); } $description = ''; if (isset($feed_elt['description'])) { - $description = html_chars_utf8($feed_elt['description']); + $description = Minz_Helper::htmlspecialchars_utf8($feed_elt['description']); } $error = false; @@ -200,7 +200,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { private function addCategoryOpml($cat_elt, $parent_cat) { // Create a new Category object - $cat = new FreshRSS_Category(html_chars_utf8($cat_elt['text'])); + $cat = new FreshRSS_Category(Minz_Helper::htmlspecialchars_utf8($cat_elt['text'])); $id = $this->catDAO->addCategoryObject($cat); $error = ($id === false); diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php index b058211d3..13bfdd93e 100644 --- a/lib/Minz/Helper.php +++ b/lib/Minz/Helper.php @@ -19,4 +19,15 @@ class Minz_Helper { return stripslashes($var); } } + + /** + * Wrapper for htmlspecialchars. + * Force UTf-8 value and can be used on array too. + */ + public static function htmlspecialchars_utf8($p) { + if (is_array($p)) { + return array_map('self::htmlspecialchars_utf8', $p); + } + return htmlspecialchars($p, ENT_COMPAT, 'UTF-8'); + } } diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index f3ecaf55c..52f53012f 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -27,19 +27,13 @@ class Minz_Request { public static function params() { return self::$params; } - static function htmlspecialchars_utf8($p) { - if (is_array($p)) { - return array_map('self::htmlspecialchars_utf8', $p); - } - return htmlspecialchars($p, ENT_COMPAT, 'UTF-8'); - } public static function param($key, $default = false, $specialchars = false) { if (isset(self::$params[$key])) { $p = self::$params[$key]; if (is_object($p) || $specialchars) { return $p; } else { - return self::htmlspecialchars_utf8($p); + return Minz_Helper::htmlspecialchars_utf8($p); } } else { return $default; diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 86c0a4ae4..823f53716 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -230,7 +230,3 @@ function cryptAvailable() { } return false; } - -function html_chars_utf8($str) { - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); -} -- cgit v1.2.3 From 775ff40780935471dcd74b0d81c04b80e3e4603c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 12 Aug 2014 22:55:43 +0200 Subject: Improve import system Catch more errors Code refactoring --- app/Controllers/importExportController.php | 125 ++++++++++++++++------------- app/i18n/en.php | 1 + app/i18n/fr.php | 1 + 3 files changed, 70 insertions(+), 57 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index a8e2c2bc2..c7f47fc13 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -24,35 +24,49 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } public function importAction() { - if (Minz_Request::isPost() && $_FILES['file']['error'] == 0) { - @set_time_limit(300); + if (!Minz_Request::isPost()) { + // What are you doing? you have to call this controller + // with a POST request! + Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); + } - $file = $_FILES['file']; - $type_file = $this->guessFileType($file['name']); + $file = $_FILES['file']; + $status_file = $file['error']; - $list_files = array( - 'opml' => array(), - 'json_starred' => array(), - 'json_feed' => array() - ); + if ($status_file !== 0) { + Minz_Log::error('File cannot be imported. Error code: ' . $status_file); + Minz_Request::bad(_t('file_cannot_be_imported'), + array('c' => 'importExport', 'a' => 'index')); + } - // We try to list all files according to their type - // A zip file is first opened and then its files are listed - $list = array(); - if ($type_file === 'zip' && extension_loaded('zip')) { - $zip = zip_open($file['tmp_name']); + @set_time_limit(300); - if (!is_resource($zip)) { - // zip_open cannot open file: something is wrong - Minz_Log::error('Zip file cannot be imported. Error code: ' . $zip); - Minz_Request::bad(_t('zip_error'), array('c' => 'importExport')); - } + $type_file = $this->guessFileType($file['name']); - while (($zipfile = zip_read($zip)) !== false) { - $type_zipfile = $this->guessFileType( - zip_entry_name($zipfile) - ); + $list_files = array( + 'opml' => array(), + 'json_starred' => array(), + 'json_feed' => array() + ); + // We try to list all files according to their type + // A zip file is first opened and then its files are listed + $list = array(); + if ($type_file === 'zip' && extension_loaded('zip')) { + $zip = zip_open($file['tmp_name']); + + if (!is_resource($zip)) { + // zip_open cannot open file: something is wrong + Minz_Log::error('Zip archive cannot be imported. Error code: ' . $zip); + Minz_Request::bad(_t('zip_error'), array('c' => 'importExport')); + } + + while (($zipfile = zip_read($zip)) !== false) { + if (!is_resource($zipfile)) { + // zip_entry() can also return an error code! + Minz_Log::error('Zip file cannot be imported. Error code: ' . $zipfile); + } else { + $type_zipfile = $this->guessFileType(zip_entry_name($zipfile)); if ($type_file !== 'unknown') { $list_files[$type_zipfile][] = zip_entry_read( $zipfile, @@ -60,43 +74,39 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); } } - - zip_close($zip); - } elseif ($type_file === 'zip') { - // Zip extension is not loaded - Minz_Request::bad(_t('no_zip_extension'), array('c' => 'importExport')); - } elseif ($type_file !== 'unknown') { - $list_files[$type_file][] = file_get_contents( - $file['tmp_name'] - ); } - // Import different files. - // OPML first(so categories and feeds are imported) - // Starred articles then so the "favourite" status is already set - // And finally all other files. - $error = false; - foreach ($list_files['opml'] as $opml_file) { - $error = $this->importOpml($opml_file); - } - foreach ($list_files['json_starred'] as $article_file) { - $error = $this->importArticles($article_file, true); - } - foreach ($list_files['json_feed'] as $article_file) { - $error = $this->importArticles($article_file); - } - - // And finally, we get import status and redirect to the home page - Minz_Session::_param('actualize_feeds', true); + zip_close($zip); + } elseif ($type_file === 'zip') { + // Zip extension is not loaded + Minz_Request::bad(_t('no_zip_extension'), array('c' => 'importExport')); + } elseif ($type_file !== 'unknown') { + $list_files[$type_file][] = file_get_contents( + $file['tmp_name'] + ); + } - $content_notif = $error === true ? _t('feeds_imported_with_errors') : - _t('feeds_imported'); - Minz_Request::good($content_notif); + // Import different files. + // OPML first(so categories and feeds are imported) + // Starred articles then so the "favourite" status is already set + // And finally all other files. + $error = false; + foreach ($list_files['opml'] as $opml_file) { + $error = $this->importOpml($opml_file); + } + foreach ($list_files['json_starred'] as $article_file) { + $error = $this->importArticles($article_file, true); } + foreach ($list_files['json_feed'] as $article_file) { + $error = $this->importArticles($article_file); + } + + // And finally, we get import status and redirect to the home page + Minz_Session::_param('actualize_feeds', true); - // What are you doing? you have to call this controller - // with a POST request! - Minz_Request::forward(array('c' => 'importExport')); + $content_notif = $error === true ? _t('feeds_imported_with_errors') : + _t('feeds_imported'); + Minz_Request::good($content_notif); } private function guessFileType($filename) { @@ -335,7 +345,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->exportZip($export_files); } catch (Exception $e) { # Oops, there is no Zip extension! - Minz_Request::bad(_t('export_no_zip_extension'), array('c' => 'importExport')); + Minz_Request::bad(_t('export_no_zip_extension'), + array('c' => 'importExport', 'a' => 'index')); } } elseif ($nb_files === 1) { // Only one file? Guess its type and export it. @@ -349,7 +360,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->exportFile($filename, $export_files[$filename], $type); } else { - Minz_Request::forward(array('c' => 'importExport')); + Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); } } } diff --git a/app/i18n/en.php b/app/i18n/en.php index 416ca851f..f4a15e747 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -184,6 +184,7 @@ return array ( 'file_to_import' => 'File to import
    (OPML, Json or Zip)', 'file_to_import_no_zip' => 'File to import
    (OPML or Json)', 'import' => 'Import', + 'file_cannot_be_uploaded' => 'File cannot be uploaded!', 'zip_error' => 'An error occured during Zip import.', 'no_zip_extension' => 'Zip extension is not present on your server.', 'export' => 'Export', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index d68006a87..4675e17ee 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -184,6 +184,7 @@ return array ( 'file_to_import' => 'Fichier à importer
    (OPML, Json ou Zip)', 'file_to_import_no_zip' => 'Fichier à importer
    (OPML ou Json)', 'import' => 'Importer', + 'file_cannot_be_uploaded' => 'Le fichier ne peut pas être téléchargé!', 'zip_error' => 'Une erreur est survenue durant l’import du fichier Zip.', 'no_zip_extension' => 'L’extension Zip n’est pas présente sur votre serveur.', 'export' => 'Exporter', -- cgit v1.2.3 From 0f1133ddfe8e3967470ea50f235e12ad04dc71a7 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 17 Aug 2014 21:03:01 +0200 Subject: Fix some forward() actions See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index c7f47fc13..2f5fcc137 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -34,8 +34,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $status_file = $file['error']; if ($status_file !== 0) { - Minz_Log::error('File cannot be imported. Error code: ' . $status_file); - Minz_Request::bad(_t('file_cannot_be_imported'), + Minz_Log::error('File cannot be uploaded. Error code: ' . $status_file); + Minz_Request::bad(_t('file_cannot_be_uploaded'), array('c' => 'importExport', 'a' => 'index')); } @@ -50,7 +50,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); // We try to list all files according to their type - // A zip file is first opened and then its files are listed $list = array(); if ($type_file === 'zip' && extension_loaded('zip')) { $zip = zip_open($file['tmp_name']); @@ -58,7 +57,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if (!is_resource($zip)) { // zip_open cannot open file: something is wrong Minz_Log::error('Zip archive cannot be imported. Error code: ' . $zip); - Minz_Request::bad(_t('zip_error'), array('c' => 'importExport')); + Minz_Request::bad(_t('zip_error'), + array('c' => 'importExport', 'a' => 'index')); } while (($zipfile = zip_read($zip)) !== false) { @@ -79,14 +79,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { zip_close($zip); } elseif ($type_file === 'zip') { // Zip extension is not loaded - Minz_Request::bad(_t('no_zip_extension'), array('c' => 'importExport')); + Minz_Request::bad(_t('no_zip_extension'), + array('c' => 'importExport', 'a' => 'index')); } elseif ($type_file !== 'unknown') { - $list_files[$type_file][] = file_get_contents( - $file['tmp_name'] - ); + $list_files[$type_file][] = file_get_contents($file['tmp_name']); } - // Import different files. + // Import file contents. // OPML first(so categories and feeds are imported) // Starred articles then so the "favourite" status is already set // And finally all other files. @@ -103,7 +102,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // And finally, we get import status and redirect to the home page Minz_Session::_param('actualize_feeds', true); - $content_notif = $error === true ? _t('feeds_imported_with_errors') : _t('feeds_imported'); Minz_Request::good($content_notif); -- cgit v1.2.3 From e3bb80de17c79cf32a2e3a606f216aebf48f92e5 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 17 Aug 2014 22:14:13 +0200 Subject: Refactor import / export source code See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 107 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 54 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2f5fcc137..2197c3af5 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -5,7 +5,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if (!$this->view->loginOk) { Minz_Error::error( 403, - array('error' => array(Minz_Translate::t('access_denied'))) + array('error' => array(_t('access_denied'))) ); } @@ -20,13 +20,11 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->categories = $this->catDAO->listCategories(); $this->view->feeds = $this->feedDAO->listFeeds(); - Minz_View::prependTitle(Minz_Translate::t('import_export') . ' · '); + Minz_View::prependTitle(_t('import_export') . ' · '); } public function importAction() { if (!Minz_Request::isPost()) { - // What are you doing? you have to call this controller - // with a POST request! Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); } @@ -309,57 +307,53 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } public function exportAction() { - if (Minz_Request::isPost()) { - $this->view->_useLayout(false); + if (!Minz_Request::isPost()) { + Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); + } - $export_opml = Minz_Request::param('export_opml', false); - $export_starred = Minz_Request::param('export_starred', false); - $export_feeds = Minz_Request::param('export_feeds', array ()); + $this->view->_useLayout(false); - $export_files = array (); - if ($export_opml) { - $export_files['feeds.opml'] = $this->generateOpml(); - } + $export_opml = Minz_Request::param('export_opml', false); + $export_starred = Minz_Request::param('export_starred', false); + $export_feeds = Minz_Request::param('export_feeds', array()); - if ($export_starred) { - $export_files['starred.json'] = $this->generateArticles('starred'); - } + $export_files = array(); + if ($export_opml) { + $export_files['feeds.opml'] = $this->generateOpml(); + } - foreach ($export_feeds as $feed_id) { - $feed = $this->feedDAO->searchById($feed_id); - if ($feed) { - $filename = 'feed_' . $feed->category() . '_' - . $feed->id() . '.json'; - $export_files[$filename] = $this->generateArticles( - 'feed', $feed - ); - } - } + if ($export_starred) { + $export_files['starred.json'] = $this->generateArticles('starred'); + } - $nb_files = count($export_files); - if ($nb_files > 1) { - // If there are more than 1 file to export, we need a zip archive. - try { - $this->exportZip($export_files); - } catch (Exception $e) { - # Oops, there is no Zip extension! - Minz_Request::bad(_t('export_no_zip_extension'), - array('c' => 'importExport', 'a' => 'index')); - } - } elseif ($nb_files === 1) { - // Only one file? Guess its type and export it. - $filename = key($export_files); - $type = null; - if (substr_compare($filename, '.opml', -5) === 0) { - $type = "text/xml"; - } elseif (substr_compare($filename, '.json', -5) === 0) { - $type = "text/json"; - } + foreach ($export_feeds as $feed_id) { + $feed = $this->feedDAO->searchById($feed_id); + if ($feed) { + $filename = 'feed_' . $feed->category() . '_' + . $feed->id() . '.json'; + $export_files[$filename] = $this->generateArticles( + 'feed', $feed + ); + } + } - $this->exportFile($filename, $export_files[$filename], $type); - } else { - Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); + $nb_files = count($export_files); + if ($nb_files > 1) { + // If there are more than 1 file to export, we need a zip archive. + try { + $this->exportZip($export_files); + } catch (Exception $e) { + # Oops, there is no Zip extension! + Minz_Request::bad(_t('export_no_zip_extension'), + array('c' => 'importExport', 'a' => 'index')); } + } elseif ($nb_files === 1) { + // Only one file? Guess its type and export it. + $filename = key($export_files); + $type = $this->guessFileType($filename); + $this->exportFile('freshrss_' . $filename, $export_files[$filename], $type); + } else { + Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); } } @@ -378,7 +372,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->categories = $this->catDAO->listCategories(); if ($type == 'starred') { - $this->view->list_title = Minz_Translate::t('starred_list'); + $this->view->list_title = _t('starred_list'); $this->view->type = 'starred'; $unread_fav = $this->entryDAO->countUnreadReadFavorites(); $this->view->entries = $this->entryDAO->listWhere( @@ -386,9 +380,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $unread_fav['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { - $this->view->list_title = Minz_Translate::t( - 'feed_list', $feed->name() - ); + $this->view->list_title = _t('feed_list', $feed->name()); $this->view->type = 'feed/' . $feed->id(); $this->view->entries = $this->entryDAO->listWhere( 'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC', @@ -424,11 +416,18 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } private function exportFile($filename, $content, $type) { - if (is_null($type)) { + if ($type === 'unknown') { return; } - header('Content-Type: ' . $type . '; charset=utf-8'); + $content_type = ''; + if ($type === 'opml') { + $content_type = "text/opml"; + } elseif ($type === 'json_feed' || $type === 'json_starred') { + $content_type = "text/json"; + } + + header('Content-Type: ' . $content_type . '; charset=utf-8'); header('Content-disposition: attachment; filename=' . $filename); print($content); } -- cgit v1.2.3 From ae54a143860bad200a0ef319052ccec512ef99e3 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 23 Aug 2014 21:37:37 +0200 Subject: Fix problem with starred files for import/export Improve guessFileType method See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2197c3af5..b3683f385 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -116,7 +116,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } elseif (substr_compare($filename, '.opml', -5) === 0 || substr_compare($filename, '.xml', -4) === 0) { return 'opml'; - } elseif (strcmp($filename, 'starred.json') === 0) { + } elseif (substr_compare($filename, '.json', -5) === 0 && + strpos($filename, 'starred') !== false) { return 'json_starred'; } elseif (substr_compare($filename, '.json', -5) === 0 && strpos($filename, 'feed_') === 0) { -- cgit v1.2.3 From 1316ada15260e8f2fdb486595d5953bef9badc50 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 23 Aug 2014 22:02:22 +0200 Subject: Fix bug add favorite entry See https://github.com/marienfressinaud/FreshRSS/issues/494 --- app/Controllers/importExportController.php | 2 +- app/Models/EntryDAO.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index b3683f385..5adf3878a 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -284,7 +284,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $url = $origin[$key]; $name = $origin['title']; $website = $origin['htmlUrl']; - $error = false; + try { // Create a Feed object and add it in DB $feed = new FreshRSS_Feed($url); diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 488b70fb6..75a8aeba4 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -65,7 +65,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo { } if (!isset($existingGuids[$entry->guid()]) && - ($feedHistory != 0 || $eDate >= $date_min)) { + ($feedHistory != 0 || $eDate >= $date_min || $entry->isFavorite())) { $values = $entry->toArray(); $useDeclaredDate = empty($existingGuids); -- cgit v1.2.3 From 3fa726a81eb1889f29115cf4d8349d15f68b03f9 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 12 Sep 2014 21:34:42 +0200 Subject: Import all .json files Before, only feed_*.json and *starred*.json was imported. Now, all *.json files are imported. --- app/Controllers/importExportController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 5adf3878a..07c097c4a 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -119,8 +119,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } elseif (substr_compare($filename, '.json', -5) === 0 && strpos($filename, 'starred') !== false) { return 'json_starred'; - } elseif (substr_compare($filename, '.json', -5) === 0 && - strpos($filename, 'feed_') === 0) { + } elseif (substr_compare($filename, '.json', -5) === 0) { return 'json_feed'; } else { return 'unknown'; @@ -238,6 +237,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { strpos($article_object['id'], 'com.google') !== false ); + $error = false; foreach ($article_object['items'] as $item) { $feed = $this->addFeedArticles($item['origin'], $google_compliant); @@ -263,7 +263,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { ); $entry->_tags($tags); - //FIME: Use entryDAO->addEntryPrepare(). Do not call entryDAO->listLastGuidsByFeed() for each entry. Consider using a transaction. + // FIXME + // Use entryDAO->addEntryPrepare(). + // Do not call entryDAO->listLastGuidsByFeed() for each entry. + // Consider using a transaction. $id = $this->entryDAO->addEntryObject( $entry, $this->view->conf, $feed->keepHistory() ); -- cgit v1.2.3 From 021457657186f019a9227e7a2a0b32148ffe4002 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 12 Sep 2014 21:46:37 +0200 Subject: FIXME (import/export) Use entryDAO addEntryPrepare --- app/Controllers/importExportController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 07c097c4a..e7d364efd 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -239,6 +239,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $error = false; + $prepared_statement = $this->entryDAO->addEntryPrepare(); foreach ($article_object['items'] as $item) { $feed = $this->addFeedArticles($item['origin'], $google_compliant); if (is_null($feed)) { @@ -261,15 +262,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $item[$key_content]['content'], $item['alternate'][0]['href'], $item['published'], $is_read, $starred ); + $entry->_id(min(time(), $entry->date(true)) . uSecString()); $entry->_tags($tags); // FIXME - // Use entryDAO->addEntryPrepare(). // Do not call entryDAO->listLastGuidsByFeed() for each entry. // Consider using a transaction. - $id = $this->entryDAO->addEntryObject( - $entry, $this->view->conf, $feed->keepHistory() - ); + $values = $entry->toArray(); + $id = $this->entryDAO->addEntry($values, $prepared_statement); if (!$error && ($id === false)) { $error = true; -- cgit v1.2.3 From b7b05ca3cefbb35a5174da4d4d734107f19c24a1 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 15 Sep 2014 15:34:56 +0200 Subject: Import/Export: use transactions List of articles must be iterated twice since feeds must be in DB before using transaction for articles. It may be improved? See https://github.com/marienfressinaud/FreshRSS/issues/591 --- app/Controllers/importExportController.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index e7d364efd..a44991335 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -237,16 +237,28 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { strpos($article_object['id'], 'com.google') !== false ); - $error = false; - $prepared_statement = $this->entryDAO->addEntryPrepare(); + $article_to_feed = array(); + + // First, we check feeds of articles are in DB (and add them if needed). foreach ($article_object['items'] as $item) { $feed = $this->addFeedArticles($item['origin'], $google_compliant); if (is_null($feed)) { $error = true; + } else { + $article_to_feed[$item['id']] = $feed->id(); + } + } + + // Then, articles are imported. + $prepared_statement = $this->entryDAO->addEntryPrepare(); + $this->entryDAO->beginTransaction(); + foreach ($article_object['items'] as $item) { + if (!isset($article_to_feed[$item['id']])) { continue; } + $feed_id = $article_to_feed[$item['id']]; $author = isset($item['author']) ? $item['author'] : ''; $key_content = ($google_compliant && !isset($item['content'])) ? 'summary' : 'content'; @@ -258,16 +270,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $entry = new FreshRSS_Entry( - $feed->id(), $item['id'], $item['title'], $author, + $feed_id, $item['id'], $item['title'], $author, $item[$key_content]['content'], $item['alternate'][0]['href'], $item['published'], $is_read, $starred ); $entry->_id(min(time(), $entry->date(true)) . uSecString()); $entry->_tags($tags); - // FIXME - // Do not call entryDAO->listLastGuidsByFeed() for each entry. - // Consider using a transaction. $values = $entry->toArray(); $id = $this->entryDAO->addEntry($values, $prepared_statement); @@ -275,6 +284,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $error = true; } } + $this->entryDAO->commit(); return $error; } -- cgit v1.2.3 From 69c7c1aa48d42656f73c724d7e9062ca19914133 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 15 Sep 2014 15:55:35 +0200 Subject: Change loading of base-theme css If metadata.json indicates it should use "_template.css" or "_base.css", base-theme/template|base.css is used. It facilitates theme maintenance. --- app/Controllers/importExportController.php | 1 - app/FreshRSS.php | 13 +- p/themes/Dark/metadata.json | 2 +- p/themes/Dark/template.css | 698 ----------------------------- p/themes/Flat/metadata.json | 2 +- p/themes/Flat/template.css | 698 ----------------------------- p/themes/Origine/metadata.json | 2 +- p/themes/Origine/template.css | 698 ----------------------------- p/themes/Screwdriver/metadata.json | 2 +- p/themes/Screwdriver/template.css | 698 ----------------------------- 10 files changed, 15 insertions(+), 2799 deletions(-) delete mode 100644 p/themes/Dark/template.css delete mode 100644 p/themes/Flat/template.css delete mode 100644 p/themes/Origine/template.css delete mode 100644 p/themes/Screwdriver/template.css (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index a44991335..f329766b8 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -109,7 +109,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { // A *very* basic guess file type function. Only based on filename // That's could be improved but should be enough, at least for a first // implementation. - // TODO: improve this function? if (substr_compare($filename, '.zip', -4) === 0) { return 'zip'; diff --git a/app/FreshRSS.php b/app/FreshRSS.php index cf6390f68..6cca27f78 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -139,11 +139,20 @@ class FreshRSS extends Minz_FrontController { } } - private function loadStylesAndScripts ($loginOk) { + private function loadStylesAndScripts($loginOk) { $theme = FreshRSS_Themes::load($this->conf->theme); if ($theme) { foreach($theme['files'] as $file) { - Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['id'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['id'] . '/' . $file))); + $theme_id = $theme['id']; + $filename = $file; + if ($file[0] == '_') { + $theme_id = 'base-theme'; + $filename = substr($file, 1); + } + $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename); + Minz_View::appendStyle(Minz_Url::display( + '/themes/' . $theme_id . '/' . $filename . '?' . $filetime + )); } } diff --git a/p/themes/Dark/metadata.json b/p/themes/Dark/metadata.json index 5eb3a05e8..bdc068c2e 100644 --- a/p/themes/Dark/metadata.json +++ b/p/themes/Dark/metadata.json @@ -3,5 +3,5 @@ "author": "AD", "description": "Le coté obscur du thème “Origine”", "version": 0.2, - "files": ["template.css", "dark.css"] + "files": ["_template.css", "dark.css"] } diff --git a/p/themes/Dark/template.css b/p/themes/Dark/template.css deleted file mode 100644 index 466ec4603..000000000 --- a/p/themes/Dark/template.css +++ /dev/null @@ -1,698 +0,0 @@ -@charset "UTF-8"; - -/*=== GENERAL */ -/*============*/ -html, body { - margin: 0; - padding: 0; - font-size: 100%; -} - -/*=== Links */ -a { - text-decoration: none; -} -a:hover { - text-decoration: underline; -} - -/*=== Lists */ -ul, ol, dd { - margin: 0; - padding: 0; -} - -/*=== Titles */ -h1 { - margin: 0.6em 0 0.3em; - font-size: 1.5em; - line-height: 1.6em; -} -h2 { - margin: 0.5em 0 0.25em; - font-size: 1.3em; - line-height: 2em; -} -h3 { - margin: 0.5em 0 0.25em; - font-size: 1.1em; - line-height: 2em; -} - -/*=== Paragraphs */ -p { - margin: 1em 0 0.5em; - font-size: 1em; -} - -/*=== Images */ -img { - height: auto; - max-width: 100%; -} -img.favicon { - height: 16px; - width: 16px; - vertical-align: middle; -} - -/*=== Videos */ -iframe, embed, object, video { - max-width: 100%; -} - -/*=== Forms */ -legend { - display: block; - width: 100%; - clear: both; -} -label { - display: block; -} -input { - width: 180px; -} -textarea { - width: 300px; -} -input, select, textarea { - display: inline-block; - max-width: 100%; -} -input[type="radio"], -input[type="checkbox"] { - width: 15px !important; - min-height: 15px !important; -} -input.extend:focus { - width: 300px; -} - -/*=== COMPONENTS */ -/*===============*/ -/*=== Forms */ -.form-group:after { - content: ""; - display: block; - clear: both; -} -.form-group.form-actions { - min-width: 250px; -} -.form-group .group-name { - display: block; - float: left; - width: 200px; -} -.form-group .group-controls { - min-width: 250px; - margin: 0 0 0 220px; -} -.form-group .group-controls .control { - display: block; -} - -/*=== Buttons */ -.stick { - display: inline-block; - white-space: nowrap; -} -.btn, -a.btn { - display: inline-block; - cursor: pointer; - overflow: hidden; -} -.btn-important { - font-weight: bold; -} - -/*=== Navigation */ -.nav-list .nav-header, -.nav-list .item { - display: block; -} -.nav-list .item, -.nav-list .item > a { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.nav-head { - display: block; -} -.nav-head .item { - display: inline-block; -} - -/*=== Horizontal-list */ -.horizontal-list { - display: table; - table-layout: fixed; - width: 100%; -} -.horizontal-list .item { - display: table-cell; -} - -/*=== Dropdown */ -.dropdown { - position: relative; - display: inline-block; -} -.dropdown-target { - display: none; -} -.dropdown-menu { - display: none; - min-width: 200px; - margin: 0; - position: absolute; - right: 0; - background: #fff; - border: 1px solid #aaa; -} -.dropdown-header { - display: block; -} -.dropdown-menu > .item { - display: block; -} -.dropdown-menu > .item > a, -.dropdown-menu > .item > span { - display: block; -} -.dropdown-menu > .item[aria-checked="true"] > a:before { - content: '✓'; -} -.dropdown-menu .input { - display: block; -} -.dropdown-menu .input select, -.dropdown-menu .input input { - display: block; - max-width: 95%; -} -.dropdown-target:target ~ .dropdown-menu { - display: block; - z-index: 10; -} -.dropdown-close { - display: inline; -} -.dropdown-close a { - font-size: 0; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; - z-index: -10; -} -.separator { - display: block; - height: 0; - border-bottom: 1px solid #aaa; -} - -/*=== Alerts */ -.alert { - display: block; - width: 90%; -} -.group-controls .alert { - width: 100% -} -.alert-head { - margin: 0; - font-weight: bold; -} -.alert ul { - margin: 5px 20px; -} - -/*=== Icons */ -.icon { - display: inline-block; - width: 16px; - height: 16px; - vertical-align: middle; - line-height: 16px; -} - -/*=== Pagination */ -.pagination { - display: table; - width: 100%; - margin: 0; - padding: 0; - table-layout: fixed; -} -.pagination .item { - display: table-cell; -} -.pagination .pager-first, -.pagination .pager-previous, -.pagination .pager-next, -.pagination .pager-last { - width: 100px; -} - -/*=== STRUCTURE */ -/*===============*/ -/*=== Header */ -.header { - display: table; - width: 100%; - table-layout: fixed; -} -.header > .item { - display: table-cell; -} -.header > .item.title { - width: 250px; - white-space: nowrap; -} -.header > .item.title h1 { - display: inline-block; -} -.header > .item.title .logo { - display: inline-block; - height: 32px; - width: 32px; - vertical-align: middle; -} -.header > .item.configure { - width: 100px; -} - -/*=== Body */ -#global { - display: table; - width: 100%; - height: 100%; - table-layout: fixed; -} -.aside { - display: table-cell; - height: 100%; - width: 250px; - vertical-align: top; -} -.aside.aside_flux { - background: #fff; -} - -/*=== Aside main page (categories) */ -.categories { - list-style: none; - margin: 0; -} -.state_unread li:not(.active)[data-unread="0"] { - display: none; -} -.category { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.category .btn:not([data-unread="0"]):after { - content: attr(data-unread); -} - -/*=== Aside main page (feeds) */ -.categories .feeds { - width: 100%; - list-style: none; -} -.categories .feeds:not(.active) { - display: none; -} -.categories .feeds .feed { - display: inline-block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - vertical-align: middle; -} -.categories .feeds .feed:not([data-unread="0"]):before { - content: "(" attr(data-unread) ") "; -} -.categories .feeds .dropdown-menu { - left: 0; -} -.categories .feeds .item .dropdown-toggle > .icon { - visibility: hidden; - cursor: pointer; - vertical-align: top; -} -.categories .feeds .item .dropdown-target:target ~ .dropdown-toggle > .icon, -.categories .feeds .item:hover .dropdown-toggle > .icon, -.categories .feeds .item.active .dropdown-toggle > .icon { - visibility: visible; -} - -/*=== New article notification */ -#new-article { - display: none; -} -#new-article > a { - display: block; -} - -/*=== Day indication */ -.day .name { - position: absolute; - right: 0; - width: 50%; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} - -/*=== Feed article header and footer */ -.flux_header { - position: relative; -} -.flux .item { - line-height: 40px; - white-space: nowrap; -} -.flux .item.manage, -.flux .item.link { - width: 40px; - text-align: center; -} -.flux .item.website { - width: 200px; -} -.flux.not_read .item.title, -.flux.current .item.title { - font-weight: bold; -} -.flux:not(.current):hover .item.title { - position: absolute; - max-width: calc(100% - 320px); - background: #fff; -} -.flux .item.title a { - color: #000; - text-decoration: none; -} -.flux .item.date { - width: 145px; - text-align: right; -} -.flux .item > a { - display: block; -} -.flux .item > a { - display: block; - text-decoration: none; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; -} -.flux .item.share > a { - display: list-item; - list-style-position: inside; - list-style-type: decimal; -} - -/*=== Feed article content */ -.hide_posts > .flux:not(.active) > .flux_content { - display: none; -} -.content { - min-height: 20em; - margin: auto; - line-height: 1.7em; - word-wrap: break-word; -} -.content.large { - max-width: 1000px; -} -.content.medium { - max-width: 800px; -} -.content.thin { - max-width: 550px; -} -.content ul, -.content ol, -.content dd { - margin: 0 0 0 15px; - padding: 0 0 5px 15px; -} -.content pre { - overflow: auto; -} - -/*=== Notification and actualize notification */ -.notification { - position: absolute; - top: 1em; - left: 25%; right: 25%; - z-index: 10; - background: #fff; - border: 1px solid #aaa; -} -.notification.closed { - display: none; -} -.notification a.close { - position: absolute; - top: 0; bottom: 0; - right: 0; - display: inline-block; -} - -#actualizeProgress { - position: fixed; -} -#actualizeProgress progress { - max-width: 100%; - vertical-align: middle; -} -#actualizeProgress .progress { - vertical-align: middle; -} - -/*=== Navigation menu (for articles) */ -#nav_entries { - position: fixed; - bottom: 0; left: 0; - display: table; - width: 250px; - background: #fff; - table-layout: fixed; -} -#nav_entries .item { - display: table-cell; - width: 30%; -} -#nav_entries a { - display: block; -} - -/*=== "Load more" part */ -#load_more { - min-height: 40px; -} -.loading { - background: url("loader.gif") center center no-repeat; - font-size: 0; -} -#bigMarkAsRead { - display: block; - padding: 3em 0; - text-align: center; -} -.bigTick { - font-size: 7em; - line-height: 1.6em; -} - -/*=== Statistiques */ -.stat > table { - width: 100%; -} - -/*=== GLOBAL VIEW */ -/*================*/ -/*=== Category boxes */ -#stream.global .box-category { - display: inline-block; - width: 19em; - max-width: 95%; - margin: 20px 10px; - border: 1px solid #ccc; - vertical-align: top; -} -#stream.global .category { - width: 100%; -} -#stream.global .btn { - display: block; -} -#stream.global .box-category .feeds { - display: block; - overflow: auto; -} -#stream.global .box-category .feed { - width: 19em; - max-width: 90%; -} - -/*=== Panel */ -#overlay { - display: none; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - background: rgba(0, 0, 0, 0.9); -} -#panel { - display: none; - position: fixed; - top: 1em; bottom: 1em; - left: 2em; right: 2em; - overflow: auto; - background: #fff; -} -#panel .close { - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; -} -#panel .close img { - display: none; -} - -/*=== DIVERS */ -/*===========*/ -.nav-login, -.nav_menu .search, -.nav_menu .toggle_aside { - display: none; -} - -.aside .toggle_aside { - position: absolute; - right: 0; - display: none; - width: 30px; - height: 30px; - line-height: 30px; - text-align: center; -} - -/*=== MOBILE */ -/*===========*/ -@media(max-width: 840px) { - .header, - .aside .btn-important, - .aside .feeds .dropdown, - .flux_header .item.website span, - .item.date, .day .date, - .dropdown-menu > .no-mobile, - .no-mobile { - display: none; - } - .nav-login { - display: block; - } - .nav_menu .toggle_aside, - .aside .toggle_aside, - .nav_menu .search, - #panel .close img { - display: inline-block; - } - - .aside { - position: fixed; - top: 0; bottom: 0; - left: 0; - width: 0; - overflow: hidden; - z-index: 100; - } - .aside:target { - width: 90%; - overflow: auto; - } - .aside .categories { - margin: 10px 0 75px; - } - - .flux_header .item.website { - width: 40px; - } - - .flux:not(.current):hover .item.title { - position: relative; - width: auto; - white-space: nowrap; - } - - .notification { - top: 0; - left: 0; - right: 0; - } - - #nav_entries { - width: 100%; - } - - #stream.global .box-category { - margin: 10px 0; - } - - #panel { - top: 0; bottom: 0; - left: 0; right: 0; - } - #panel .close { - top: 0; right: 0; - left: auto; bottom: auto; - display: inline-block; - width: 30px; - height: 30px; - } -} - -/*=== PRINTER */ -/*============*/ -@media print { - .header, .aside, - .nav_menu, .day, - .flux_header, - .flux_content .bottom, - .pagination, - #nav_entries { - display: none; - } - html, body { - background: #fff; - color: #000; - font-family: Serif; - } - #global, - .flux_content { - display: block !important; - } - .flux_content .content { - width: 100% !important; - } - .flux_content .content a { - color: #000; - } - .flux_content .content a:after { - content: " [" attr(href) "] "; - font-style: italic; - } -} diff --git a/p/themes/Flat/metadata.json b/p/themes/Flat/metadata.json index 182c82470..3afdc98af 100644 --- a/p/themes/Flat/metadata.json +++ b/p/themes/Flat/metadata.json @@ -3,5 +3,5 @@ "author": "Marien Fressinaud", "description": "Thème plat pour FreshRSS", "version": 0.2, - "files": ["template.css", "flat.css"] + "files": ["_template.css", "flat.css"] } \ No newline at end of file diff --git a/p/themes/Flat/template.css b/p/themes/Flat/template.css deleted file mode 100644 index 466ec4603..000000000 --- a/p/themes/Flat/template.css +++ /dev/null @@ -1,698 +0,0 @@ -@charset "UTF-8"; - -/*=== GENERAL */ -/*============*/ -html, body { - margin: 0; - padding: 0; - font-size: 100%; -} - -/*=== Links */ -a { - text-decoration: none; -} -a:hover { - text-decoration: underline; -} - -/*=== Lists */ -ul, ol, dd { - margin: 0; - padding: 0; -} - -/*=== Titles */ -h1 { - margin: 0.6em 0 0.3em; - font-size: 1.5em; - line-height: 1.6em; -} -h2 { - margin: 0.5em 0 0.25em; - font-size: 1.3em; - line-height: 2em; -} -h3 { - margin: 0.5em 0 0.25em; - font-size: 1.1em; - line-height: 2em; -} - -/*=== Paragraphs */ -p { - margin: 1em 0 0.5em; - font-size: 1em; -} - -/*=== Images */ -img { - height: auto; - max-width: 100%; -} -img.favicon { - height: 16px; - width: 16px; - vertical-align: middle; -} - -/*=== Videos */ -iframe, embed, object, video { - max-width: 100%; -} - -/*=== Forms */ -legend { - display: block; - width: 100%; - clear: both; -} -label { - display: block; -} -input { - width: 180px; -} -textarea { - width: 300px; -} -input, select, textarea { - display: inline-block; - max-width: 100%; -} -input[type="radio"], -input[type="checkbox"] { - width: 15px !important; - min-height: 15px !important; -} -input.extend:focus { - width: 300px; -} - -/*=== COMPONENTS */ -/*===============*/ -/*=== Forms */ -.form-group:after { - content: ""; - display: block; - clear: both; -} -.form-group.form-actions { - min-width: 250px; -} -.form-group .group-name { - display: block; - float: left; - width: 200px; -} -.form-group .group-controls { - min-width: 250px; - margin: 0 0 0 220px; -} -.form-group .group-controls .control { - display: block; -} - -/*=== Buttons */ -.stick { - display: inline-block; - white-space: nowrap; -} -.btn, -a.btn { - display: inline-block; - cursor: pointer; - overflow: hidden; -} -.btn-important { - font-weight: bold; -} - -/*=== Navigation */ -.nav-list .nav-header, -.nav-list .item { - display: block; -} -.nav-list .item, -.nav-list .item > a { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.nav-head { - display: block; -} -.nav-head .item { - display: inline-block; -} - -/*=== Horizontal-list */ -.horizontal-list { - display: table; - table-layout: fixed; - width: 100%; -} -.horizontal-list .item { - display: table-cell; -} - -/*=== Dropdown */ -.dropdown { - position: relative; - display: inline-block; -} -.dropdown-target { - display: none; -} -.dropdown-menu { - display: none; - min-width: 200px; - margin: 0; - position: absolute; - right: 0; - background: #fff; - border: 1px solid #aaa; -} -.dropdown-header { - display: block; -} -.dropdown-menu > .item { - display: block; -} -.dropdown-menu > .item > a, -.dropdown-menu > .item > span { - display: block; -} -.dropdown-menu > .item[aria-checked="true"] > a:before { - content: '✓'; -} -.dropdown-menu .input { - display: block; -} -.dropdown-menu .input select, -.dropdown-menu .input input { - display: block; - max-width: 95%; -} -.dropdown-target:target ~ .dropdown-menu { - display: block; - z-index: 10; -} -.dropdown-close { - display: inline; -} -.dropdown-close a { - font-size: 0; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; - z-index: -10; -} -.separator { - display: block; - height: 0; - border-bottom: 1px solid #aaa; -} - -/*=== Alerts */ -.alert { - display: block; - width: 90%; -} -.group-controls .alert { - width: 100% -} -.alert-head { - margin: 0; - font-weight: bold; -} -.alert ul { - margin: 5px 20px; -} - -/*=== Icons */ -.icon { - display: inline-block; - width: 16px; - height: 16px; - vertical-align: middle; - line-height: 16px; -} - -/*=== Pagination */ -.pagination { - display: table; - width: 100%; - margin: 0; - padding: 0; - table-layout: fixed; -} -.pagination .item { - display: table-cell; -} -.pagination .pager-first, -.pagination .pager-previous, -.pagination .pager-next, -.pagination .pager-last { - width: 100px; -} - -/*=== STRUCTURE */ -/*===============*/ -/*=== Header */ -.header { - display: table; - width: 100%; - table-layout: fixed; -} -.header > .item { - display: table-cell; -} -.header > .item.title { - width: 250px; - white-space: nowrap; -} -.header > .item.title h1 { - display: inline-block; -} -.header > .item.title .logo { - display: inline-block; - height: 32px; - width: 32px; - vertical-align: middle; -} -.header > .item.configure { - width: 100px; -} - -/*=== Body */ -#global { - display: table; - width: 100%; - height: 100%; - table-layout: fixed; -} -.aside { - display: table-cell; - height: 100%; - width: 250px; - vertical-align: top; -} -.aside.aside_flux { - background: #fff; -} - -/*=== Aside main page (categories) */ -.categories { - list-style: none; - margin: 0; -} -.state_unread li:not(.active)[data-unread="0"] { - display: none; -} -.category { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.category .btn:not([data-unread="0"]):after { - content: attr(data-unread); -} - -/*=== Aside main page (feeds) */ -.categories .feeds { - width: 100%; - list-style: none; -} -.categories .feeds:not(.active) { - display: none; -} -.categories .feeds .feed { - display: inline-block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - vertical-align: middle; -} -.categories .feeds .feed:not([data-unread="0"]):before { - content: "(" attr(data-unread) ") "; -} -.categories .feeds .dropdown-menu { - left: 0; -} -.categories .feeds .item .dropdown-toggle > .icon { - visibility: hidden; - cursor: pointer; - vertical-align: top; -} -.categories .feeds .item .dropdown-target:target ~ .dropdown-toggle > .icon, -.categories .feeds .item:hover .dropdown-toggle > .icon, -.categories .feeds .item.active .dropdown-toggle > .icon { - visibility: visible; -} - -/*=== New article notification */ -#new-article { - display: none; -} -#new-article > a { - display: block; -} - -/*=== Day indication */ -.day .name { - position: absolute; - right: 0; - width: 50%; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} - -/*=== Feed article header and footer */ -.flux_header { - position: relative; -} -.flux .item { - line-height: 40px; - white-space: nowrap; -} -.flux .item.manage, -.flux .item.link { - width: 40px; - text-align: center; -} -.flux .item.website { - width: 200px; -} -.flux.not_read .item.title, -.flux.current .item.title { - font-weight: bold; -} -.flux:not(.current):hover .item.title { - position: absolute; - max-width: calc(100% - 320px); - background: #fff; -} -.flux .item.title a { - color: #000; - text-decoration: none; -} -.flux .item.date { - width: 145px; - text-align: right; -} -.flux .item > a { - display: block; -} -.flux .item > a { - display: block; - text-decoration: none; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; -} -.flux .item.share > a { - display: list-item; - list-style-position: inside; - list-style-type: decimal; -} - -/*=== Feed article content */ -.hide_posts > .flux:not(.active) > .flux_content { - display: none; -} -.content { - min-height: 20em; - margin: auto; - line-height: 1.7em; - word-wrap: break-word; -} -.content.large { - max-width: 1000px; -} -.content.medium { - max-width: 800px; -} -.content.thin { - max-width: 550px; -} -.content ul, -.content ol, -.content dd { - margin: 0 0 0 15px; - padding: 0 0 5px 15px; -} -.content pre { - overflow: auto; -} - -/*=== Notification and actualize notification */ -.notification { - position: absolute; - top: 1em; - left: 25%; right: 25%; - z-index: 10; - background: #fff; - border: 1px solid #aaa; -} -.notification.closed { - display: none; -} -.notification a.close { - position: absolute; - top: 0; bottom: 0; - right: 0; - display: inline-block; -} - -#actualizeProgress { - position: fixed; -} -#actualizeProgress progress { - max-width: 100%; - vertical-align: middle; -} -#actualizeProgress .progress { - vertical-align: middle; -} - -/*=== Navigation menu (for articles) */ -#nav_entries { - position: fixed; - bottom: 0; left: 0; - display: table; - width: 250px; - background: #fff; - table-layout: fixed; -} -#nav_entries .item { - display: table-cell; - width: 30%; -} -#nav_entries a { - display: block; -} - -/*=== "Load more" part */ -#load_more { - min-height: 40px; -} -.loading { - background: url("loader.gif") center center no-repeat; - font-size: 0; -} -#bigMarkAsRead { - display: block; - padding: 3em 0; - text-align: center; -} -.bigTick { - font-size: 7em; - line-height: 1.6em; -} - -/*=== Statistiques */ -.stat > table { - width: 100%; -} - -/*=== GLOBAL VIEW */ -/*================*/ -/*=== Category boxes */ -#stream.global .box-category { - display: inline-block; - width: 19em; - max-width: 95%; - margin: 20px 10px; - border: 1px solid #ccc; - vertical-align: top; -} -#stream.global .category { - width: 100%; -} -#stream.global .btn { - display: block; -} -#stream.global .box-category .feeds { - display: block; - overflow: auto; -} -#stream.global .box-category .feed { - width: 19em; - max-width: 90%; -} - -/*=== Panel */ -#overlay { - display: none; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - background: rgba(0, 0, 0, 0.9); -} -#panel { - display: none; - position: fixed; - top: 1em; bottom: 1em; - left: 2em; right: 2em; - overflow: auto; - background: #fff; -} -#panel .close { - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; -} -#panel .close img { - display: none; -} - -/*=== DIVERS */ -/*===========*/ -.nav-login, -.nav_menu .search, -.nav_menu .toggle_aside { - display: none; -} - -.aside .toggle_aside { - position: absolute; - right: 0; - display: none; - width: 30px; - height: 30px; - line-height: 30px; - text-align: center; -} - -/*=== MOBILE */ -/*===========*/ -@media(max-width: 840px) { - .header, - .aside .btn-important, - .aside .feeds .dropdown, - .flux_header .item.website span, - .item.date, .day .date, - .dropdown-menu > .no-mobile, - .no-mobile { - display: none; - } - .nav-login { - display: block; - } - .nav_menu .toggle_aside, - .aside .toggle_aside, - .nav_menu .search, - #panel .close img { - display: inline-block; - } - - .aside { - position: fixed; - top: 0; bottom: 0; - left: 0; - width: 0; - overflow: hidden; - z-index: 100; - } - .aside:target { - width: 90%; - overflow: auto; - } - .aside .categories { - margin: 10px 0 75px; - } - - .flux_header .item.website { - width: 40px; - } - - .flux:not(.current):hover .item.title { - position: relative; - width: auto; - white-space: nowrap; - } - - .notification { - top: 0; - left: 0; - right: 0; - } - - #nav_entries { - width: 100%; - } - - #stream.global .box-category { - margin: 10px 0; - } - - #panel { - top: 0; bottom: 0; - left: 0; right: 0; - } - #panel .close { - top: 0; right: 0; - left: auto; bottom: auto; - display: inline-block; - width: 30px; - height: 30px; - } -} - -/*=== PRINTER */ -/*============*/ -@media print { - .header, .aside, - .nav_menu, .day, - .flux_header, - .flux_content .bottom, - .pagination, - #nav_entries { - display: none; - } - html, body { - background: #fff; - color: #000; - font-family: Serif; - } - #global, - .flux_content { - display: block !important; - } - .flux_content .content { - width: 100% !important; - } - .flux_content .content a { - color: #000; - } - .flux_content .content a:after { - content: " [" attr(href) "] "; - font-style: italic; - } -} diff --git a/p/themes/Origine/metadata.json b/p/themes/Origine/metadata.json index 59a45e8f6..774320eb4 100644 --- a/p/themes/Origine/metadata.json +++ b/p/themes/Origine/metadata.json @@ -3,5 +3,5 @@ "author": "Marien Fressinaud", "description": "Le thème par défaut pour FreshRSS", "version": 0.2, - "files": ["template.css", "origine.css"] + "files": ["_template.css", "origine.css"] } diff --git a/p/themes/Origine/template.css b/p/themes/Origine/template.css deleted file mode 100644 index 466ec4603..000000000 --- a/p/themes/Origine/template.css +++ /dev/null @@ -1,698 +0,0 @@ -@charset "UTF-8"; - -/*=== GENERAL */ -/*============*/ -html, body { - margin: 0; - padding: 0; - font-size: 100%; -} - -/*=== Links */ -a { - text-decoration: none; -} -a:hover { - text-decoration: underline; -} - -/*=== Lists */ -ul, ol, dd { - margin: 0; - padding: 0; -} - -/*=== Titles */ -h1 { - margin: 0.6em 0 0.3em; - font-size: 1.5em; - line-height: 1.6em; -} -h2 { - margin: 0.5em 0 0.25em; - font-size: 1.3em; - line-height: 2em; -} -h3 { - margin: 0.5em 0 0.25em; - font-size: 1.1em; - line-height: 2em; -} - -/*=== Paragraphs */ -p { - margin: 1em 0 0.5em; - font-size: 1em; -} - -/*=== Images */ -img { - height: auto; - max-width: 100%; -} -img.favicon { - height: 16px; - width: 16px; - vertical-align: middle; -} - -/*=== Videos */ -iframe, embed, object, video { - max-width: 100%; -} - -/*=== Forms */ -legend { - display: block; - width: 100%; - clear: both; -} -label { - display: block; -} -input { - width: 180px; -} -textarea { - width: 300px; -} -input, select, textarea { - display: inline-block; - max-width: 100%; -} -input[type="radio"], -input[type="checkbox"] { - width: 15px !important; - min-height: 15px !important; -} -input.extend:focus { - width: 300px; -} - -/*=== COMPONENTS */ -/*===============*/ -/*=== Forms */ -.form-group:after { - content: ""; - display: block; - clear: both; -} -.form-group.form-actions { - min-width: 250px; -} -.form-group .group-name { - display: block; - float: left; - width: 200px; -} -.form-group .group-controls { - min-width: 250px; - margin: 0 0 0 220px; -} -.form-group .group-controls .control { - display: block; -} - -/*=== Buttons */ -.stick { - display: inline-block; - white-space: nowrap; -} -.btn, -a.btn { - display: inline-block; - cursor: pointer; - overflow: hidden; -} -.btn-important { - font-weight: bold; -} - -/*=== Navigation */ -.nav-list .nav-header, -.nav-list .item { - display: block; -} -.nav-list .item, -.nav-list .item > a { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.nav-head { - display: block; -} -.nav-head .item { - display: inline-block; -} - -/*=== Horizontal-list */ -.horizontal-list { - display: table; - table-layout: fixed; - width: 100%; -} -.horizontal-list .item { - display: table-cell; -} - -/*=== Dropdown */ -.dropdown { - position: relative; - display: inline-block; -} -.dropdown-target { - display: none; -} -.dropdown-menu { - display: none; - min-width: 200px; - margin: 0; - position: absolute; - right: 0; - background: #fff; - border: 1px solid #aaa; -} -.dropdown-header { - display: block; -} -.dropdown-menu > .item { - display: block; -} -.dropdown-menu > .item > a, -.dropdown-menu > .item > span { - display: block; -} -.dropdown-menu > .item[aria-checked="true"] > a:before { - content: '✓'; -} -.dropdown-menu .input { - display: block; -} -.dropdown-menu .input select, -.dropdown-menu .input input { - display: block; - max-width: 95%; -} -.dropdown-target:target ~ .dropdown-menu { - display: block; - z-index: 10; -} -.dropdown-close { - display: inline; -} -.dropdown-close a { - font-size: 0; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; - z-index: -10; -} -.separator { - display: block; - height: 0; - border-bottom: 1px solid #aaa; -} - -/*=== Alerts */ -.alert { - display: block; - width: 90%; -} -.group-controls .alert { - width: 100% -} -.alert-head { - margin: 0; - font-weight: bold; -} -.alert ul { - margin: 5px 20px; -} - -/*=== Icons */ -.icon { - display: inline-block; - width: 16px; - height: 16px; - vertical-align: middle; - line-height: 16px; -} - -/*=== Pagination */ -.pagination { - display: table; - width: 100%; - margin: 0; - padding: 0; - table-layout: fixed; -} -.pagination .item { - display: table-cell; -} -.pagination .pager-first, -.pagination .pager-previous, -.pagination .pager-next, -.pagination .pager-last { - width: 100px; -} - -/*=== STRUCTURE */ -/*===============*/ -/*=== Header */ -.header { - display: table; - width: 100%; - table-layout: fixed; -} -.header > .item { - display: table-cell; -} -.header > .item.title { - width: 250px; - white-space: nowrap; -} -.header > .item.title h1 { - display: inline-block; -} -.header > .item.title .logo { - display: inline-block; - height: 32px; - width: 32px; - vertical-align: middle; -} -.header > .item.configure { - width: 100px; -} - -/*=== Body */ -#global { - display: table; - width: 100%; - height: 100%; - table-layout: fixed; -} -.aside { - display: table-cell; - height: 100%; - width: 250px; - vertical-align: top; -} -.aside.aside_flux { - background: #fff; -} - -/*=== Aside main page (categories) */ -.categories { - list-style: none; - margin: 0; -} -.state_unread li:not(.active)[data-unread="0"] { - display: none; -} -.category { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.category .btn:not([data-unread="0"]):after { - content: attr(data-unread); -} - -/*=== Aside main page (feeds) */ -.categories .feeds { - width: 100%; - list-style: none; -} -.categories .feeds:not(.active) { - display: none; -} -.categories .feeds .feed { - display: inline-block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - vertical-align: middle; -} -.categories .feeds .feed:not([data-unread="0"]):before { - content: "(" attr(data-unread) ") "; -} -.categories .feeds .dropdown-menu { - left: 0; -} -.categories .feeds .item .dropdown-toggle > .icon { - visibility: hidden; - cursor: pointer; - vertical-align: top; -} -.categories .feeds .item .dropdown-target:target ~ .dropdown-toggle > .icon, -.categories .feeds .item:hover .dropdown-toggle > .icon, -.categories .feeds .item.active .dropdown-toggle > .icon { - visibility: visible; -} - -/*=== New article notification */ -#new-article { - display: none; -} -#new-article > a { - display: block; -} - -/*=== Day indication */ -.day .name { - position: absolute; - right: 0; - width: 50%; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} - -/*=== Feed article header and footer */ -.flux_header { - position: relative; -} -.flux .item { - line-height: 40px; - white-space: nowrap; -} -.flux .item.manage, -.flux .item.link { - width: 40px; - text-align: center; -} -.flux .item.website { - width: 200px; -} -.flux.not_read .item.title, -.flux.current .item.title { - font-weight: bold; -} -.flux:not(.current):hover .item.title { - position: absolute; - max-width: calc(100% - 320px); - background: #fff; -} -.flux .item.title a { - color: #000; - text-decoration: none; -} -.flux .item.date { - width: 145px; - text-align: right; -} -.flux .item > a { - display: block; -} -.flux .item > a { - display: block; - text-decoration: none; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; -} -.flux .item.share > a { - display: list-item; - list-style-position: inside; - list-style-type: decimal; -} - -/*=== Feed article content */ -.hide_posts > .flux:not(.active) > .flux_content { - display: none; -} -.content { - min-height: 20em; - margin: auto; - line-height: 1.7em; - word-wrap: break-word; -} -.content.large { - max-width: 1000px; -} -.content.medium { - max-width: 800px; -} -.content.thin { - max-width: 550px; -} -.content ul, -.content ol, -.content dd { - margin: 0 0 0 15px; - padding: 0 0 5px 15px; -} -.content pre { - overflow: auto; -} - -/*=== Notification and actualize notification */ -.notification { - position: absolute; - top: 1em; - left: 25%; right: 25%; - z-index: 10; - background: #fff; - border: 1px solid #aaa; -} -.notification.closed { - display: none; -} -.notification a.close { - position: absolute; - top: 0; bottom: 0; - right: 0; - display: inline-block; -} - -#actualizeProgress { - position: fixed; -} -#actualizeProgress progress { - max-width: 100%; - vertical-align: middle; -} -#actualizeProgress .progress { - vertical-align: middle; -} - -/*=== Navigation menu (for articles) */ -#nav_entries { - position: fixed; - bottom: 0; left: 0; - display: table; - width: 250px; - background: #fff; - table-layout: fixed; -} -#nav_entries .item { - display: table-cell; - width: 30%; -} -#nav_entries a { - display: block; -} - -/*=== "Load more" part */ -#load_more { - min-height: 40px; -} -.loading { - background: url("loader.gif") center center no-repeat; - font-size: 0; -} -#bigMarkAsRead { - display: block; - padding: 3em 0; - text-align: center; -} -.bigTick { - font-size: 7em; - line-height: 1.6em; -} - -/*=== Statistiques */ -.stat > table { - width: 100%; -} - -/*=== GLOBAL VIEW */ -/*================*/ -/*=== Category boxes */ -#stream.global .box-category { - display: inline-block; - width: 19em; - max-width: 95%; - margin: 20px 10px; - border: 1px solid #ccc; - vertical-align: top; -} -#stream.global .category { - width: 100%; -} -#stream.global .btn { - display: block; -} -#stream.global .box-category .feeds { - display: block; - overflow: auto; -} -#stream.global .box-category .feed { - width: 19em; - max-width: 90%; -} - -/*=== Panel */ -#overlay { - display: none; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - background: rgba(0, 0, 0, 0.9); -} -#panel { - display: none; - position: fixed; - top: 1em; bottom: 1em; - left: 2em; right: 2em; - overflow: auto; - background: #fff; -} -#panel .close { - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; -} -#panel .close img { - display: none; -} - -/*=== DIVERS */ -/*===========*/ -.nav-login, -.nav_menu .search, -.nav_menu .toggle_aside { - display: none; -} - -.aside .toggle_aside { - position: absolute; - right: 0; - display: none; - width: 30px; - height: 30px; - line-height: 30px; - text-align: center; -} - -/*=== MOBILE */ -/*===========*/ -@media(max-width: 840px) { - .header, - .aside .btn-important, - .aside .feeds .dropdown, - .flux_header .item.website span, - .item.date, .day .date, - .dropdown-menu > .no-mobile, - .no-mobile { - display: none; - } - .nav-login { - display: block; - } - .nav_menu .toggle_aside, - .aside .toggle_aside, - .nav_menu .search, - #panel .close img { - display: inline-block; - } - - .aside { - position: fixed; - top: 0; bottom: 0; - left: 0; - width: 0; - overflow: hidden; - z-index: 100; - } - .aside:target { - width: 90%; - overflow: auto; - } - .aside .categories { - margin: 10px 0 75px; - } - - .flux_header .item.website { - width: 40px; - } - - .flux:not(.current):hover .item.title { - position: relative; - width: auto; - white-space: nowrap; - } - - .notification { - top: 0; - left: 0; - right: 0; - } - - #nav_entries { - width: 100%; - } - - #stream.global .box-category { - margin: 10px 0; - } - - #panel { - top: 0; bottom: 0; - left: 0; right: 0; - } - #panel .close { - top: 0; right: 0; - left: auto; bottom: auto; - display: inline-block; - width: 30px; - height: 30px; - } -} - -/*=== PRINTER */ -/*============*/ -@media print { - .header, .aside, - .nav_menu, .day, - .flux_header, - .flux_content .bottom, - .pagination, - #nav_entries { - display: none; - } - html, body { - background: #fff; - color: #000; - font-family: Serif; - } - #global, - .flux_content { - display: block !important; - } - .flux_content .content { - width: 100% !important; - } - .flux_content .content a { - color: #000; - } - .flux_content .content a:after { - content: " [" attr(href) "] "; - font-style: italic; - } -} diff --git a/p/themes/Screwdriver/metadata.json b/p/themes/Screwdriver/metadata.json index f45f1a98a..46095e507 100644 --- a/p/themes/Screwdriver/metadata.json +++ b/p/themes/Screwdriver/metadata.json @@ -3,5 +3,5 @@ "author": "Mister aiR", "description": "C'est un cocktail ! C'est chaud mais « fresh » à la fois. Ce thème tue du chaton.", "version": 1.1, - "files": ["template.css","screwdriver.css"] + "files": ["_template.css","screwdriver.css"] } diff --git a/p/themes/Screwdriver/template.css b/p/themes/Screwdriver/template.css deleted file mode 100644 index ddb3f376f..000000000 --- a/p/themes/Screwdriver/template.css +++ /dev/null @@ -1,698 +0,0 @@ -@charset "UTF-8"; - -/*=== GENERAL */ -/*============*/ -html, body { - margin: 0; - padding: 0; - font-size: 92%; -} - -/*=== Links */ -a { - text-decoration: none; -} -a:hover { - text-decoration: underline; -} - -/*=== Lists */ -ul, ol, dd { - margin: 0; - padding: 0; -} - -/*=== Titles */ -h1 { - margin: 0.6em 0 0.3em; - font-size: 1.5em; - line-height: 1.6em; -} -h2 { - margin: 0.5em 0 0.25em; - font-size: 1.3em; - line-height: 2em; -} -h3 { - margin: 0.5em 0 0.25em; - font-size: 1.1em; - line-height: 2em; -} - -/*=== Paragraphs */ -p { - margin: 1em 0 0.5em; - font-size: 1em; -} - -/*=== Images */ -img { - height: auto; - max-width: 100%; -} -img.favicon { - height: 16px; - width: 16px; - vertical-align: middle; -} - -/*=== Videos */ -iframe, embed, object, video { - max-width: 100%; -} - -/*=== Forms */ -legend { - display: block; - width: 100%; - clear: both; -} -label { - display: block; -} -input { - width: 180px; -} -textarea { - width: 300px; -} -input, select, textarea { - display: inline-block; - max-width: 100%; -} -input[type="radio"], -input[type="checkbox"] { - width: 15px !important; - min-height: 15px !important; -} -input.extend:focus { - width: 300px; -} - -/*=== COMPONENTS */ -/*===============*/ -/*=== Forms */ -.form-group:after { - content: ""; - display: block; - clear: both; -} -.form-group.form-actions { - min-width: 250px; -} -.form-group .group-name { - display: block; - float: left; - width: 200px; -} -.form-group .group-controls { - min-width: 250px; - margin: 0 0 0 220px; -} -.form-group .group-controls .control { - display: block; -} - -/*=== Buttons */ -.stick { - display: inline-block; - white-space: nowrap; -} -.btn, -a.btn { - display: inline-block; - cursor: pointer; - overflow: hidden; -} -.btn-important { - font-weight: bold; -} - -/*=== Navigation */ -.nav-list .nav-header, -.nav-list .item { - display: block; -} -.nav-list .item, -.nav-list .item > a { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.nav-head { - display: block; -} -.nav-head .item { - display: inline-block; -} - -/*=== Horizontal-list */ -.horizontal-list { - display: table; - table-layout: fixed; - width: 100%; -} -.horizontal-list .item { - display: table-cell; -} - -/*=== Dropdown */ -.dropdown { - position: relative; - display: inline-block; -} -.dropdown-target { - display: none; -} -.dropdown-menu { - display: none; - min-width: 200px; - margin: 0; - position: absolute; - right: 0; - background: #fff; - border: 1px solid #aaa; -} -.dropdown-header { - display: block; -} -.dropdown-menu > .item { - display: block; -} -.dropdown-menu > .item > a, -.dropdown-menu > .item > span { - display: block; -} -.dropdown-menu > .item[aria-checked="true"] > a:before { - content: '✓'; -} -.dropdown-menu .input { - display: block; -} -.dropdown-menu .input select, -.dropdown-menu .input input { - display: block; - max-width: 95%; -} -.dropdown-target:target ~ .dropdown-menu { - display: block; - z-index: 10; -} -.dropdown-close { - display: inline; -} -.dropdown-close a { - font-size: 0; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; - z-index: -10; -} -.separator { - display: block; - height: 0; - border-bottom: 1px solid #aaa; -} - -/*=== Alerts */ -.alert { - display: block; - width: 90%; -} -.group-controls .alert { - width: 100% -} -.alert-head { - margin: 0; - font-weight: bold; -} -.alert ul { - margin: 5px 20px; -} - -/*=== Icons */ -.icon { - display: inline-block; - width: 16px; - height: 16px; - vertical-align: middle; - line-height: 16px; -} - -/*=== Pagination */ -.pagination { - display: table; - width: 100%; - margin: 0; - padding: 0; - table-layout: fixed; -} -.pagination .item { - display: table-cell; -} -.pagination .pager-first, -.pagination .pager-previous, -.pagination .pager-next, -.pagination .pager-last { - width: 100px; -} - -/*=== STRUCTURE */ -/*===============*/ -/*=== Header */ -.header { - display: table; - width: 100%; - table-layout: fixed; -} -.header > .item { - display: table-cell; -} -.header > .item.title { - width: 250px; - white-space: nowrap; -} -.header > .item.title h1 { - display: inline-block; -} -.header > .item.title .logo { - display: inline-block; - height: 32px; - width: 32px; - vertical-align: middle; -} -.header > .item.configure { - width: 100px; -} - -/*=== Body */ -#global { - display: table; - width: 100%; - height: 100%; - table-layout: fixed; -} -.aside { - display: table-cell; - height: 100%; - width: 250px; - vertical-align: top; -} -.aside.aside_flux { - background: #fff; -} - -/*=== Aside main page (categories) */ -.categories { - list-style: none; - margin: 0; -} -.state_unread li:not(.active)[data-unread="0"] { - display: none; -} -.category { - display: block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} -.category .btn:not([data-unread="0"]):after { - content: attr(data-unread); -} - -/*=== Aside main page (feeds) */ -.categories .feeds { - width: 100%; - list-style: none; -} -.categories .feeds:not(.active) { - display: none; -} -.categories .feeds .feed { - display: inline-block; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - vertical-align: middle; -} -.categories .feeds .feed:not([data-unread="0"]):before { - content: "(" attr(data-unread) ") "; -} -.categories .feeds .dropdown-menu { - left: 0; -} -.categories .feeds .item .dropdown-toggle > .icon { - visibility: hidden; - cursor: pointer; - vertical-align: top; -} -.categories .feeds .item .dropdown-target:target ~ .dropdown-toggle > .icon, -.categories .feeds .item:hover .dropdown-toggle > .icon, -.categories .feeds .item.active .dropdown-toggle > .icon { - visibility: visible; -} - -/*=== New article notification */ -#new-article { - display: none; -} -#new-article > a { - display: block; -} - -/*=== Day indication */ -.day .name { - position: absolute; - right: 0; - width: 50%; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; -} - -/*=== Feed article header and footer */ -.flux_header { - position: relative; -} -.flux .item { - line-height: 40px; - white-space: nowrap; -} -.flux .item.manage, -.flux .item.link { - width: 40px; - text-align: center; -} -.flux .item.website { - width: 200px; -} -.flux.not_read .item.title, -.flux.current .item.title { - font-weight: bold; -} -.flux:not(.current):hover .item.title { - position: absolute; - max-width: calc(100% - 320px); - background: #fff; -} -.flux .item.title a { - color: #000; - text-decoration: none; -} -.flux .item.date { - width: 145px; - text-align: right; -} -.flux .item > a { - display: block; -} -.flux .item > a { - display: block; - text-decoration: none; - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; -} -.flux .item.share > a { - display: list-item; - list-style-position: inside; - list-style-type: decimal; -} - -/*=== Feed article content */ -.hide_posts > .flux:not(.active) > .flux_content { - display: none; -} -.content { - min-height: 20em; - margin: auto; - line-height: 1.7em; - word-wrap: break-word; -} -.content.large { - max-width: 1000px; -} -.content.medium { - max-width: 800px; -} -.content.thin { - max-width: 550px; -} -.content ul, -.content ol, -.content dd { - margin: 0 0 0 15px; - padding: 0 0 5px 15px; -} -.content pre { - overflow: auto; -} - -/*=== Notification and actualize notification */ -.notification { - position: absolute; - top: 1em; - left: 25%; right: 25%; - z-index: 10; - background: #fff; - border: 1px solid #aaa; -} -.notification.closed { - display: none; -} -.notification a.close { - position: absolute; - top: 0; bottom: 0; - right: 0; - display: inline-block; -} - -#actualizeProgress { - position: fixed; -} -#actualizeProgress progress { - max-width: 100%; - vertical-align: middle; -} -#actualizeProgress .progress { - vertical-align: middle; -} - -/*=== Navigation menu (for articles) */ -#nav_entries { - position: fixed; - bottom: 0; left: 0; - display: table; - width: 250px; - background: #fff; - table-layout: fixed; -} -#nav_entries .item { - display: table-cell; - width: 30%; -} -#nav_entries a { - display: block; -} - -/*=== "Load more" part */ -#load_more { - min-height: 40px; -} -.loading { - background: url("loader.gif") center center no-repeat; - font-size: 0; -} -#bigMarkAsRead { - display: block; - padding: 3em 0; - text-align: center; -} -.bigTick { - font-size: 7em; - line-height: 1.6em; -} - -/*=== Statistiques */ -.stat > table { - width: 100%; -} - -/*=== GLOBAL VIEW */ -/*================*/ -/*=== Category boxes */ -#stream.global .box-category { - display: inline-block; - width: 19em; - max-width: 95%; - margin: 20px 10px; - border: 1px solid #ccc; - vertical-align: top; -} -#stream.global .category { - width: 100%; -} -#stream.global .btn { - display: block; -} -#stream.global .box-category .feeds { - display: block; - overflow: auto; -} -#stream.global .box-category .feed { - width: 19em; - max-width: 90%; -} - -/*=== Panel */ -#overlay { - display: none; - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - background: rgba(0, 0, 0, 0.9); -} -#panel { - display: none; - position: fixed; - top: 1em; bottom: 1em; - left: 2em; right: 2em; - overflow: auto; - background: #fff; -} -#panel .close { - position: fixed; - top: 0; bottom: 0; - left: 0; right: 0; - display: block; -} -#panel .close img { - display: none; -} - -/*=== DIVERS */ -/*===========*/ -.nav-login, -.nav_menu .search, -.nav_menu .toggle_aside { - display: none; -} - -.aside .toggle_aside { - position: absolute; - right: 0; - display: none; - width: 30px; - height: 30px; - line-height: 30px; - text-align: center; -} - -/*=== MOBILE */ -/*===========*/ -@media(max-width: 840px) { - .header, - .aside .btn-important, - .aside .feeds .dropdown, - .flux_header .item.website span, - .item.date, .day .date, - .dropdown-menu > .no-mobile, - .no-mobile { - display: none; - } - .nav-login { - display: block; - } - .nav_menu .toggle_aside, - .aside .toggle_aside, - .nav_menu .search, - #panel .close img { - display: inline-block; - } - - .aside { - position: fixed; - top: 0; bottom: 0; - left: 0; - width: 0; - overflow: hidden; - z-index: 100; - } - .aside:target { - width: 90%; - overflow: auto; - } - .aside .categories { - margin: 10px 0 75px; - } - - .flux_header .item.website { - width: 40px; - } - - .flux:not(.current):hover .item.title { - position: relative; - width: auto; - white-space: nowrap; - } - - .notification { - top: 0; - left: 0; - right: 0; - } - - #nav_entries { - width: 100%; - } - - #stream.global .box-category { - margin: 10px 0; - } - - #panel { - top: 0; bottom: 0; - left: 0; right: 0; - } - #panel .close { - top: 0; right: 0; - left: auto; bottom: auto; - display: inline-block; - width: 30px; - height: 30px; - } -} - -/*=== PRINTER */ -/*============*/ -@media print { - .header, .aside, - .nav_menu, .day, - .flux_header, - .flux_content .bottom, - .pagination, - #nav_entries { - display: none; - } - html, body { - background: #fff; - color: #000; - font-family: Serif; - } - #global, - .flux_content { - display: block !important; - } - .flux_content .content { - width: 100% !important; - } - .flux_content .content a { - color: #000; - } - .flux_content .content a:after { - content: " [" attr(href) "] "; - font-style: italic; - } -} -- cgit v1.2.3