From 97c3c7575a586382ea87f8faa1e9e78afb64710a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 10 Nov 2013 19:45:48 +0100 Subject: Suppression des warnings liés à filemtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ajout de "@" pour éviter les warnings, touch.txt sera créé un peu plus tard --- app/App_FrontController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 82499ada3..5569d73a3 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -54,18 +54,18 @@ class App_FrontController extends FrontController { $theme = RSSThemes::get_infos($this->conf->theme()); if ($theme) { foreach($theme["files"] as $file) { - View::appendStyle (Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file))); + View::appendStyle (Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file))); } } - View::appendStyle (Url::display ('/themes/printer/style.css?' . filemtime(PUBLIC_PATH . '/themes/printer/style.css')), 'print'); + View::appendStyle (Url::display ('/themes/printer/style.css?' . @filemtime(PUBLIC_PATH . '/themes/printer/style.css')), 'print'); if (login_is_conf ($this->conf)) { View::appendScript ('https://login.persona.org/include.js'); } - View::appendScript (Url::display ('/scripts/jquery.min.js?' . filemtime(PUBLIC_PATH . '/scripts/jquery.min.js'))); + View::appendScript (Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js'))); if ($this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { - View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js?' . filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); + View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); } - View::appendScript (Url::display ('/scripts/main.js?' . filemtime(PUBLIC_PATH . '/scripts/main.js'))); + View::appendScript (Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js'))); } private function loadNotifications () { -- cgit v1.2.3 From 58cb842966f437a44f58644439f513b94f9dccac Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 12 Nov 2013 18:22:41 +0100 Subject: Suppression multiples requêtes count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suppression de plusieurs requêtes count inutiles (genre `$entryDAO->countNotRead()` avant un UPDATE), et suppression de l'affichage du nombre d'articles total. Corrige https://github.com/marienfressinaud/FreshRSS/issues/246 --- app/App_FrontController.php | 4 ---- app/controllers/indexController.php | 28 ++++++++++++++++------------ app/i18n/en.php | 2 +- app/i18n/fr.php | 2 +- app/layout/aside_flux.phtml | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 5569d73a3..950956555 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -43,10 +43,6 @@ class App_FrontController extends FrontController { private function loadParamsView () { $this->conf = Session::param ('conf', new RSSConfiguration ()); View::_param ('conf', $this->conf); - - $entryDAO = new EntryDAO (); - View::_param ('nb_not_read', $entryDAO->countNotRead ()); - Session::_param ('language', $this->conf->language ()); } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 2f86034ee..e99ae2e44 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -2,7 +2,6 @@ class indexController extends ActionController { private $get = false; - private $nb_not_read = 0; private $nb_not_read_cat = 0; public function indexAction () { @@ -56,19 +55,12 @@ class indexController extends ActionController { } } - $nb_not_read = $this->view->nb_not_read; - if($nb_not_read > 0) { - View::appendTitle (' (' . $nb_not_read . ')'); - } - View::prependTitle (' - '); - $entryDAO = new EntryDAO (); $feedDAO = new FeedDAO (); $catDAO = new CategoryDAO (); $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); - $this->view->nb_total = $entryDAO->count (); $this->view->currentName = ''; $this->view->get_c = ''; @@ -78,6 +70,12 @@ class indexController extends ActionController { $error = $this->checkAndProcessType ($type); // mise à jour des titres + $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); + if ($this->view->nb_not_read > 0) { + View::appendTitle (' (' . $this->view->nb_not_read . ')'); + } + View::prependTitle (' - '); + $this->view->rss_title = $this->view->currentName . ' - ' . $this->view->rss_title; View::prependTitle ( $this->view->currentName . @@ -166,8 +164,11 @@ class indexController extends ActionController { $this->view->get_c = $type['type']; return false; } elseif ($type['type'] == 'c') { - $catDAO = new CategoryDAO (); - $cat = $catDAO->searchById ($type['id']); + $cat = isset($this->view->cat_aside[$type['id']]) ? $this->view->cat_aside[$type['id']] : null; + if ($cat === null) { + $catDAO = new CategoryDAO (); + $cat = $catDAO->searchById ($type['id']); + } if ($cat) { $this->view->currentName = $cat->name (); $this->nb_not_read_cat = $cat->nbNotRead (); @@ -177,8 +178,11 @@ class indexController extends ActionController { return true; } } elseif ($type['type'] == 'f') { - $feedDAO = new FeedDAO (); - $feed = $feedDAO->searchById ($type['id']); + $feed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); + if (empty($feed)) { + $feedDAO = new FeedDAO (); + $feed = $feedDAO->searchById ($type['id']); + } if ($feed) { $this->view->currentName = $feed->name (); $this->nb_not_read_cat = $feed->nbNotRead (); diff --git a/app/i18n/en.php b/app/i18n/en.php index 2f9232160..0a9ca2cb0 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -19,7 +19,7 @@ return array ( 'import_export_opml' => 'Import / export (OPML)', 'subscription_management' => 'Subscriptions management', - 'all_feeds' => 'Main stream (%d)', + 'all_feeds' => 'Main stream', 'favorite_feeds' => 'Favourites (%d)', 'not_read' => '%d unread', 'not_reads' => '%d unread', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 922bda134..063c0cad7 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -19,7 +19,7 @@ return array ( 'import_export_opml' => 'Importer / exporter (OPML)', 'subscription_management' => 'Gestion des abonnements', - 'all_feeds' => 'Flux principal (%d)', + 'all_feeds' => 'Flux principal', 'favorite_feeds' => 'Favoris (%d)', 'not_read' => '%d non lu', 'not_reads' => '%d non lus', diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index aa1624f69..511bb4564 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -15,7 +15,7 @@ -- cgit v1.2.3 From 190e724aee234eb4ef0e476f20e89a9aaefce778 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 15 Nov 2013 17:42:15 +0100 Subject: Suppression référence lib_text et optimisation lazyimg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimisation du regex de lazyimg. Et une référence à lib_text avait été oubliée dans https://github.com/marienfressinaud/FreshRSS/commit/5dfe281d60e21fd59bfa780fad0aa177a8feaf14 --- app/App_FrontController.php | 1 - lib/lib_rss.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 950956555..2a7b86f1b 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -23,7 +23,6 @@ class App_FrontController extends FrontController { require (LIB_PATH . '/lib_phpQuery.php'); require (LIB_PATH . '/lib_rss.php'); require (LIB_PATH . '/SimplePie_autoloader.php'); - require (LIB_PATH . '/lib_text.php'); } private function loadModels () { diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 473531707..e4518ab4b 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -210,8 +210,8 @@ function dowload_favicon ($website, $id) { */ function lazyimg($content) { return preg_replace( - '//i', - '', + '/]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i', + '', $content ); } -- cgit v1.2.3 From 8c8e5257d8d092822ca956d014ee74521d147744 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 17 Nov 2013 11:59:20 +0100 Subject: Corrige bug chargement JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lorsque la vue par défaut était le mode lecture, le JS ne se chargeait pas. La faute au script LazyLoad qui n'était pas chargé correctement --- app/App_FrontController.php | 10 +++++++++- app/controllers/indexController.php | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 2a7b86f1b..b175442d6 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -43,6 +43,12 @@ class App_FrontController extends FrontController { $this->conf = Session::param ('conf', new RSSConfiguration ()); View::_param ('conf', $this->conf); Session::_param ('language', $this->conf->language ()); + + $output = Request::param ('output'); + if(!$output) { + $output = $this->conf->viewMode(); + Request::_param ('output', $output); + } } private function loadStylesAndScripts () { @@ -53,11 +59,13 @@ class App_FrontController extends FrontController { } } View::appendStyle (Url::display ('/themes/printer/style.css?' . @filemtime(PUBLIC_PATH . '/themes/printer/style.css')), 'print'); + if (login_is_conf ($this->conf)) { View::appendScript ('https://login.persona.org/include.js'); } View::appendScript (Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js'))); - if ($this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { + if ($this->conf->lazyload () === 'yes' && + ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); } View::appendScript (Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js'))); diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 392abd3e1..e4462e543 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -43,11 +43,6 @@ class indexController extends ActionController { $this->view->_useLayout (false); header('Content-Type: application/rss+xml; charset=utf-8'); } else { - if(!$output) { - $output = $this->view->conf->viewMode(); - Request::_param ('output', $output); - } - View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); if ($output == 'global') { -- cgit v1.2.3 From 0167d550c83a614df540427ae270f4cb460034ac Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 17 Nov 2013 16:20:09 +0100 Subject: Corrige bug chargement lazyload en mode déplié MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En désactivant le chargement asynchrone de JQuery uniquement dans ce cas. Corrige https://github.com/marienfressinaud/FreshRSS/issues/276 --- app/App_FrontController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index b175442d6..3a980349a 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -63,9 +63,9 @@ class App_FrontController extends FrontController { if (login_is_conf ($this->conf)) { View::appendScript ('https://login.persona.org/include.js'); } - View::appendScript (Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js'))); - if ($this->conf->lazyload () === 'yes' && - ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader')) { + $includeLazyLoad = $this->conf->lazyload () === 'yes' && ($this->conf->displayPosts () === 'yes' || Request::param ('output') === 'reader'); + View::appendScript (Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')), false, !$includeLazyLoad, !$includeLazyLoad); + if ($includeLazyLoad) { View::appendScript (Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js'))); } View::appendScript (Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js'))); -- cgit v1.2.3 From cebf1d9fd9e8479dac300e2fad5ba1c41927b850 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 19 Nov 2013 12:04:56 +0100 Subject: Message d'erreur si fichier conf innaccessible Voir #282 --- app/App_FrontController.php | 10 +++++++++- lib/minz/dao/Model_txt.php | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 3a980349a..b1e6787dc 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -40,7 +40,15 @@ class App_FrontController extends FrontController { } private function loadParamsView () { - $this->conf = Session::param ('conf', new RSSConfiguration ()); + try { + $this->conf = Session::param ('conf', new RSSConfiguration ()); + } catch(MinzException $e) { + // Permission denied or conf file does not exist + // it's critical! + print $e->getMessage(); + exit(); + } + View::_param ('conf', $this->conf); Session::_param ('language', $this->conf->language ()); diff --git a/lib/minz/dao/Model_txt.php b/lib/minz/dao/Model_txt.php index c9d5cfe77..aed653068 100755 --- a/lib/minz/dao/Model_txt.php +++ b/lib/minz/dao/Model_txt.php @@ -27,10 +27,17 @@ class Model_txt { */ public function __construct ($nameFile, $mode = 'a+') { $this->filename = $nameFile; + if (!file_exists($this->filename)) { + throw new FileNotExistException ( + $this->filename, + MinzException::WARNING + ); + } + $this->file = @fopen ($this->filename, $mode); if (!$this->file) { - throw new FileNotExistException ( + throw new PermissionDeniedException ( $this->filename, MinzException::WARNING ); -- cgit v1.2.3 From eae19e13634593d919811f527eff9e1efd34c03b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 24 Nov 2013 23:05:06 +0100 Subject: Refactorise RSSThemes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Évite de charger les informations de tous les thèmes lorsque ce n'est pas nécessaire (c.à.d. en dehors de la page de configuration). * Permettra de choisir des icônes différentes selon les thèmes sans nécessairement passer par une CSS. * Contribue à https://github.com/marienfressinaud/FreshRSS/issues/284 --- app/App_FrontController.php | 1 - app/models/RSSConfiguration.php | 1 + app/models/RSSThemes.php | 69 +++++++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 31 deletions(-) (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index b1e6787dc..1f270c0b1 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -11,7 +11,6 @@ class App_FrontController extends FrontController { $this->loadModels (); Session::init (); - RSSThemes::init (); Translate::init (); $this->loadParamsView (); diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index 741dd84a1..ef562bdcb 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -49,6 +49,7 @@ class RSSConfiguration extends Model { $this->_markWhen ($confDAO->mark_when); $this->_urlShaarli ($confDAO->url_shaarli); $this->_theme ($confDAO->theme); + RSSThemes::setThemeId ($confDAO->theme); $this->_anonAccess ($confDAO->anon_access); $this->_token ($confDAO->token); $this->_autoLoadMore ($confDAO->auto_load_more); diff --git a/app/models/RSSThemes.php b/app/models/RSSThemes.php index 54420048b..6e4ddbf6d 100644 --- a/app/models/RSSThemes.php +++ b/app/models/RSSThemes.php @@ -1,48 +1,50 @@ '⚐', 'up' => '△', ); - $alt = isset($alts[$name]) ? $alts[$name] : '?'; + if (!isset($alts[$name])) { + return ''; + } + + $url = $name . '.svg'; + $url = isset(self::$themeIcons[$url]) ? (self::$themeIconsUrl . $url) : + (self::$defaultIconsUrl . $url); + return '' . $alts[$name] . ''; - //return '' . $alts[$name] . ''; + //return '' . $alts[$name] . ''; } } -- cgit v1.2.3 From c8a7913f79955e284288468ef88adc90aa788c50 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 25 Nov 2013 21:31:00 +0100 Subject: Page Speed : bouge le style 'print' dans la CSS principale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bouge le petit style dédié à l'impression dans la CSS principale, pour de meilleures performances, et aussi pour permettre aux thèmes de changer le rendu à l'impression. Au passage, ajout de `@charset "UTF-8";` en tête de CSS --- app/App_FrontController.php | 1 - lib/minz/View.php | 5 +++-- public/themes/default/freshrss.css | 39 ++++++++++++++++++++++++++++++++++ public/themes/default/global.css | 2 ++ public/themes/flat-design/freshrss.css | 39 ++++++++++++++++++++++++++++++++++ public/themes/flat-design/global.css | 2 ++ public/themes/printer/style.css | 34 ----------------------------- 7 files changed, 85 insertions(+), 37 deletions(-) delete mode 100644 public/themes/printer/style.css (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 1f270c0b1..40e31f549 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -65,7 +65,6 @@ class App_FrontController extends FrontController { View::appendStyle (Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file))); } } - View::appendStyle (Url::display ('/themes/printer/style.css?' . @filemtime(PUBLIC_PATH . '/themes/printer/style.css')), 'print'); if (login_is_conf ($this->conf)) { View::appendScript ('https://login.persona.org/include.js'); diff --git a/lib/minz/View.php b/lib/minz/View.php index fd92762b3..12202542f 100755 --- a/lib/minz/View.php +++ b/lib/minz/View.php @@ -150,8 +150,9 @@ class View { $styles .= ''; diff --git a/public/themes/default/freshrss.css b/public/themes/default/freshrss.css index 7d30c1806..468f18dc8 100644 --- a/public/themes/default/freshrss.css +++ b/public/themes/default/freshrss.css @@ -1,3 +1,5 @@ +@charset "UTF-8"; + /* STRUCTURE */ .header { display: table; @@ -820,3 +822,40 @@ -ms-transition: width 200ms linear; } } + +@media print { + .header, + .aside, + .nav_menu, + .day, + .flux_header, + .flux_content .bottom, + .pagination { + display: none; + } + + html, body { + background: #fff; + color: #000; + font-family: Serif; + font-size: 12pt; + } + + #global, + .flux_content { + display: block !important; + } + + .flux_content .content { + width: 100% !important; + text-align: justify; + } + + .flux_content .content a { + color: #000; + } + .flux_content .content a:after { + content: " (" attr(href) ") "; + text-decoration: underline; + } +} diff --git a/public/themes/default/global.css b/public/themes/default/global.css index 2004a1936..1c554d2dc 100644 --- a/public/themes/default/global.css +++ b/public/themes/default/global.css @@ -1,3 +1,5 @@ +@charset "UTF-8"; + /* FONTS */ @font-face { font-family: "OpenSans"; diff --git a/public/themes/flat-design/freshrss.css b/public/themes/flat-design/freshrss.css index 04c61085b..c2e824c22 100644 --- a/public/themes/flat-design/freshrss.css +++ b/public/themes/flat-design/freshrss.css @@ -1,3 +1,5 @@ +@charset "UTF-8"; + /* STRUCTURE */ body { background: #fafafa; @@ -752,3 +754,40 @@ body { -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); } + +@media print { + .header, + .aside, + .nav_menu, + .day, + .flux_header, + .flux_content .bottom, + .pagination { + display: none; + } + + html, body { + background: #fff; + color: #000; + font-family: Serif; + font-size: 12pt; + } + + #global, + .flux_content { + display: block !important; + } + + .flux_content .content { + width: 100% !important; + text-align: justify; + } + + .flux_content .content a { + color: #000; + } + .flux_content .content a:after { + content: " (" attr(href) ") "; + text-decoration: underline; + } +} diff --git a/public/themes/flat-design/global.css b/public/themes/flat-design/global.css index c53ec863c..8cf6412b3 100644 --- a/public/themes/flat-design/global.css +++ b/public/themes/flat-design/global.css @@ -1,3 +1,5 @@ +@charset "UTF-8"; + /* FONTS */ @font-face { font-family: "OpenSans"; diff --git a/public/themes/printer/style.css b/public/themes/printer/style.css deleted file mode 100644 index 87d019c58..000000000 --- a/public/themes/printer/style.css +++ /dev/null @@ -1,34 +0,0 @@ -.header, -.aside, -.nav_menu, -.day, -.flux_header, -.flux_content .bottom, -.pagination { - display: none; -} - -html, body { - background: #fff; - color: #000; - font-family: Serif; - font-size: 12pt; -} - -#global, -.flux_content { - display: block !important; -} - -.flux_content .content { - width: 100% !important; - text-align: justify; -} - -.flux_content .content a { - color: #000; -} -.flux_content .content a:after { - content: " (" attr(href) ") "; - text-decoration: underline; -} \ No newline at end of file -- cgit v1.2.3 From 37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 30 Nov 2013 17:21:26 +0100 Subject: Recherche côté SQL avec LIKE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Premier essai de recherche côté base de données (à améliorer) https://github.com/marienfressinaud/FreshRSS/issues/204 Pour l'instant fait avec du LIKE et pas d'indexation texte complet. * Suppression de EntriesGetter car le code est devenu plus simple grâce au filtrage côté SQL * Uniformisation de get_c à une lettre ('all' devient 'a','favoris' devient 's' - pour "starred") pour simplifier le code * low_to_high par DESC, high_to_low par ASC * Réduction du nombre de créations de *DAO dans indexController * Refactorisation de checkAndProcessType() Pas encore trop testé... --- app/App_FrontController.php | 1 - app/controllers/configureController.php | 4 +- app/controllers/indexController.php | 254 +++++++++++++++----------------- app/layout/aside_flux.phtml | 4 +- app/layout/nav_menu.phtml | 13 +- app/models/EntriesGetter.php | 148 ------------------- app/models/Entry.php | 213 ++++++++++---------------- app/models/RSSConfiguration.php | 8 +- app/views/configure/display.phtml | 4 +- 9 files changed, 214 insertions(+), 435 deletions(-) delete mode 100644 app/models/EntriesGetter.php (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 40e31f549..d701e2944 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -33,7 +33,6 @@ class App_FrontController extends FrontController { include (APP_PATH . '/models/Category.php'); include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); - include (APP_PATH . '/models/EntriesGetter.php'); include (APP_PATH . '/models/RSSPaginator.php'); include (APP_PATH . '/models/Log_Model.php'); } diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index af6140b5d..424e3834a 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -158,12 +158,12 @@ class configureController extends ActionController { $language = Request::param ('language', 'en'); $nb = Request::param ('posts_per_page', 10); $mode = Request::param ('view_mode', 'normal'); - $view = Request::param ('default_view', 'all'); + $view = Request::param ('default_view', 'a'); $auto_load_more = Request::param ('auto_load_more', 'no'); $display = Request::param ('display_posts', 'no'); $onread_jump_next = Request::param ('onread_jump_next', 'no'); $lazyload = Request::param ('lazyload', 'no'); - $sort = Request::param ('sort_order', 'low_to_high'); + $sort = Request::param ('sort_order', 'DESC'); $old = Request::param ('old_entries', 3); $mail = Request::param ('mail_login', false); $anon = Request::param ('anon_access', 'no'); diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index 8e6abd682..cf0e5024a 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -3,19 +3,29 @@ class indexController extends ActionController { private $get = false; private $nb_not_read_cat = 0; + private $entryDAO; + private $feedDAO; + private $catDAO; + + function __construct($router) { + parent::__construct($router); + $this->entryDAO = new EntryDAO (); + $this->feedDAO = new FeedDAO (); + $this->catDAO = new CategoryDAO (); + } public function indexAction () { $output = Request::param ('output'); $token = $this->view->conf->token(); $token_param = Request::param ('token', ''); - $token_is_ok = ($token != '' && $token == $token_param); + $token_is_ok = ($token != '' && $token === $token_param); // check if user is log in if(login_is_conf ($this->view->conf) && !is_logged() && - $this->view->conf->anonAccess() == 'no' && - !($output == 'rss' && $token_is_ok)) { + $this->view->conf->anonAccess() === 'no' && + !($output === 'rss' && $token_is_ok)) { return; } @@ -26,7 +36,7 @@ class indexController extends ActionController { $params['search'] = urlencode ($params['search']); } if (login_is_conf($this->view->conf) && - $this->view->conf->anonAccess() == 'no' && + $this->view->conf->anonAccess() === 'no' && $token != '') { $params['token'] = $token; } @@ -38,32 +48,25 @@ class indexController extends ActionController { $this->view->rss_title = View::title(); - if ($output == 'rss') { + if ($output === 'rss') { // no layout for RSS output $this->view->_useLayout (false); header('Content-Type: application/rss+xml; charset=utf-8'); } else { View::appendScript (Url::display ('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js'))); - if ($output == 'global') { + if ($output === 'global') { View::appendScript (Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } } - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); - - $this->view->cat_aside = $catDAO->listCategories (); - $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); + $this->view->cat_aside = $this->catDAO->listCategories (); + $this->view->nb_favorites = $this->entryDAO->countUnreadReadFavorites (); $this->view->currentName = ''; $this->view->get_c = ''; $this->view->get_f = ''; - $type = $this->getType (); - $error = $this->checkAndProcessType ($type); - // mise à jour des titres $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); if ($this->view->nb_not_read > 0) { @@ -77,63 +80,73 @@ class indexController extends ActionController { ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') ); - if (!$error) { - // On récupère les différents éléments de filtrage - $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); - $filter = Request::param ('search', ''); - $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ()); - $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); - $first = Request::param ('next', ''); - - if ($state === 'not_read') { //Any unread article in this category at all? - switch ($type['type']) { - case 'all': - $hasUnread = $this->view->nb_not_read > 0; - break; - case 'favoris': - $hasUnread = $this->view->nb_favorites['unread'] > 0; - break; - case 'c': - $hasUnread = (!isset($this->view->cat_aside[$type['id']])) || ($this->view->cat_aside[$type['id']]->nbNotRead() > 0); - break; - case 'f': - $myFeed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); - $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0); - break; - default: - $hasUnread = true; - break; - } - if (!$hasUnread) { - $this->view->state = $state = 'all'; - } + $get = Request::param ('get', 'a'); + $getType = $get[0]; + $getId = substr ($get, 2); + if (!$this->checkAndProcessType ($getType, $getId)) { + Minz_Log::record ('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG); + Error::error ( + 404, + array ('error' => array (Translate::t ('page_not_found'))) + ); + return; + } + + // On récupère les différents éléments de filtrage + $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); + $filter = Request::param ('search', ''); + if (!empty($filter)) { + $state = 'all'; //Search always in read and unread articles + } + $this->view->order = $order = Request::param ('order', $this->view->conf->sortOrder ()); + $nb = Request::param ('nb', $this->view->conf->postsPerPage ()); + $first = Request::param ('next', ''); + + if ($state === 'not_read') { //Any unread article in this category at all? + switch ($getType) { + case 'a': + $hasUnread = $this->view->nb_not_read > 0; + break; + case 's': + $hasUnread = $this->view->nb_favorites['unread'] > 0; + break; + case 'c': + $hasUnread = (!isset($this->view->cat_aside[$getId])) || ($this->view->cat_aside[$getId]->nbNotRead() > 0); + break; + case 'f': + $myFeed = HelperCategory::findFeed($this->view->cat_aside, $getId); + $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0); + break; + default: + $hasUnread = true; + break; } + if (!$hasUnread) { + $this->view->state = $state = 'all'; + } + } - try { - // EntriesGetter permet de déporter la complexité du filtrage - $getter = new EntriesGetter ($type, $state, $filter, $order, $nb, $first); - $getter->execute (); - $entries = $getter->getPaginator (); - - // Si on a récupéré aucun article "non lus" - // on essaye de récupérer tous les articles - if ($state === 'not_read' && $entries->isEmpty ()) { //TODO: Remove in v0.8 - Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); - $this->view->state = 'all'; - $getter->_state ('all'); - $getter->execute (); - $entries = $getter->getPaginator (); - } + try { + $entries = $this->entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter); + + // Si on a récupéré aucun article "non lus" + // on essaye de récupérer tous les articles + if ($state === 'not_read' && empty($entries)) { //TODO: Remove in v0.8 + Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG); + $this->view->state = 'all'; + $entries = $this->entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter); + } - $this->view->entryPaginator = $entries; - } catch (EntriesGetterException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); - Error::error ( - 404, - array ('error' => array (Translate::t ('page_not_found'))) - ); + if (count($entries) <= $nb) { + $next = ''; + } else { //We have more elements for pagination + $lastEntry = array_pop($entries); + $next = $lastEntry->id(); } - } else { + + $this->view->entryPaginator = new RSSPaginator ($entries, $next); + } catch (EntriesGetterException $e) { + Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); Error::error ( 404, array ('error' => array (Translate::t ('page_not_found'))) @@ -141,79 +154,50 @@ class indexController extends ActionController { } } - /* - * Détermine le type d'article à récupérer : - * "tous", "favoris", "public", "catégorie" ou "flux" - */ - private function getType () { - $get = Request::param ('get', 'all'); - $typeGet = $get[0]; - $id = substr ($get, 2); - - $type = null; - if ($get == 'all' || $get == 'favoris' || $get == 'public') { - $type = array ( - 'type' => $get, - 'id' => $get - ); - } elseif ($typeGet == 'f' || $typeGet == 'c') { - $type = array ( - 'type' => $typeGet, - 'id' => $id - ); - } - - return $type; - } /* * Vérifie que la catégorie / flux sélectionné existe * + Initialise correctement les variables de vue get_c et get_f * + Met à jour la variable $this->nb_not_read_cat */ - private function checkAndProcessType ($type) { - if ($type['type'] == 'all') { - $this->view->currentName = Translate::t ('your_rss_feeds'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'favoris') { - $this->view->currentName = Translate::t ('your_favorites'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'public') { - $this->view->currentName = Translate::t ('public'); - $this->view->get_c = $type['type']; - return false; - } elseif ($type['type'] == 'c') { - $cat = isset($this->view->cat_aside[$type['id']]) ? $this->view->cat_aside[$type['id']] : null; - if ($cat === null) { - $catDAO = new CategoryDAO (); - $cat = $catDAO->searchById ($type['id']); - } - if ($cat) { - $this->view->currentName = $cat->name (); - $this->nb_not_read_cat = $cat->nbNotRead (); - $this->view->get_c = $type['id']; - return false; - } else { + private function checkAndProcessType ($getType, $getId) { + switch ($getType) { + case 'a': + $this->view->currentName = Translate::t ('your_rss_feeds'); + $this->view->get_c = $getType; return true; - } - } elseif ($type['type'] == 'f') { - $feed = HelperCategory::findFeed($this->view->cat_aside, $type['id']); - if (empty($feed)) { - $feedDAO = new FeedDAO (); - $feed = $feedDAO->searchById ($type['id']); - } - if ($feed) { - $this->view->currentName = $feed->name (); - $this->nb_not_read_cat = $feed->nbNotRead (); - $this->view->get_f = $type['id']; - $this->view->get_c = $feed->category (); - return false; - } else { + case 's': + $this->view->currentName = Translate::t ('your_favorites'); + $this->view->get_c = $getType; return true; - } - } else { - return true; + case 'c': + $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null; + if ($cat === null) { + $cat = $this->catDAO->searchById ($getId); + } + if ($cat) { + $this->view->currentName = $cat->name (); + $this->nb_not_read_cat = $cat->nbNotRead (); + $this->view->get_c = $getId; + return true; + } else { + return false; + } + case 'f': + $feed = HelperCategory::findFeed($this->view->cat_aside, $getId); + if (empty($feed)) { + $feed = $this->feedDAO->searchById ($getId); + } + if ($feed) { + $this->view->currentName = $feed->name (); + $this->nb_not_read_cat = $feed->nbNotRead (); + $this->view->get_f = $getId; + $this->view->get_c = $feed->category (); + return true; + } else { + return false; + } + default: + return false; } } @@ -270,7 +254,7 @@ class indexController extends ActionController { curl_close ($ch); $res = json_decode ($result, true); - if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { + if ($res['status'] === 'okay' && $res['email'] === $this->view->conf->mailLogin ()) { Session::_param ('mail', $res['email']); invalidateHttpCache(); } else { diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 918a44e01..ce5ded230 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -15,7 +15,7 @@
  • - + @@ -24,7 +24,7 @@
  • - + nb_favorites['all']); ?> diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 0b95b4b02..289fe6542 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -11,9 +11,8 @@ $get = 'f_' . $this->get_f; $string_mark = Translate::t ('mark_feed_read'); } elseif ($this->get_c && - $this->get_c != 'all' && - $this->get_c != 'favoris' && - $this->get_c != 'public') { + $this->get_c != 'a' && + $this->get_c != 's') { $get = 'c_' . $this->get_c; $string_mark = Translate::t ('mark_cat_read'); } @@ -34,7 +33,7 @@ $anotherUnreadId = $cat->id (); if ($foundCurrent) break; } - $nextGet = empty ($anotherUnreadId) ? 'all' : 'c_' . $anotherUnreadId; + $nextGet = empty ($anotherUnreadId) ? 'a' : 'c_' . $anotherUnreadId; break; case 'f': foreach ($this->cat_aside as $cat) { @@ -149,15 +148,15 @@
  • order == 'low_to_high') { - $url_order['params']['order'] = 'high_to_low'; + if ($this->order === 'DESC') { + $url_order['params']['order'] = 'ASC'; ?> diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php deleted file mode 100644 index ce026f252..000000000 --- a/app/models/EntriesGetter.php +++ /dev/null @@ -1,148 +0,0 @@ - 'all', - 'id' => 'all' - ); - private $state = 'all'; - private $filter = array ( - 'words' => array (), - 'tags' => array (), - ); - private $order = 'high_to_low'; - private $entries = array (); - - private $nb = 1; - private $first = ''; - private $next = ''; - - public function __construct ($type, $state, $filter, $order, $nb, $first = '') { - $this->_type ($type); - $this->_state ($state); - $this->_filter ($filter); - $this->_order ($order); - $this->nb = $nb; - $this->first = $first; - } - - public function type () { - return $this->type; - } - public function state () { - return $this->state; - } - public function filter () { - return $this->filter; - } - public function order () { - return $this->order; - } - public function entries () { - return $this->entries; - } - - public function _type ($value) { - if (!is_array ($value) || - !isset ($value['type']) || - !isset ($value['id'])) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $type = $value['type']; - $id = $value['id']; - - if ($type != 'all' && $type != 'favoris' && $type != 'public' && $type != 'c' && $type != 'f') { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - if (($type == 'all' || $type == 'favoris' || $type == 'public') && - ($type != $id)) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->type = $value; - } - public function _state ($value) { - if ($value != 'all' && $value != 'not_read' && $value != 'read') { - throw new EntriesGetterException ('Bad state line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->state = $value; - } - public function _filter ($value) { - $value = trim ($value); - $terms = explode (' ', $value); - - foreach ($terms as $word) { - if (!empty ($word) && $word[0] == '#' && isset ($word[1])) { - $tag = substr ($word, 1); - $this->filter['tags'][$tag] = $tag; - } elseif (!empty ($word)) { - $this->filter['words'][$word] = $word; - } - } - } - public function _order ($value) { - if ($value != 'high_to_low' && $value != 'low_to_high') { - throw new EntriesGetterException ('Bad order line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->order = $value; - } - - public function execute () { - $entryDAO = new EntryDAO (); - - HelperEntry::$nb = $this->nb; //TODO: Update: Now done in SQL - HelperEntry::$first = $this->first; //TODO: Update: Now done in SQL - HelperEntry::$filter = $this->filter; - - $sqlLimit = (empty ($this->filter['words']) && empty ($this->filter['tags'])) ? $this->nb : ''; //Disable SQL LIMIT optimisation during search //TODO: Do better! - - switch ($this->type['type']) { - case 'all': - list ($this->entries, $this->next) = $entryDAO->listEntries ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'favoris': - list ($this->entries, $this->next) = $entryDAO->listFavorites ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'c': - list ($this->entries, $this->next) = $entryDAO->listByCategory ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'f': - list ($this->entries, $this->next) = $entryDAO->listByFeed ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - default: - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - } - - public function getPaginator () { - $paginator = new RSSPaginator ($this->entries, $this->next); - - return $paginator; - } -} diff --git a/app/models/Entry.php b/app/models/Entry.php index 894985ece..915fbccc8 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -15,7 +15,7 @@ class Entry extends Model { private $tags; public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '', - $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) { + $link = '', $pubdate = 0, $is_read = false, $is_favorite = false, $tags = '') { $this->_guid ($guid); $this->_title ($title); $this->_author ($author); @@ -25,7 +25,7 @@ class Entry extends Model { $this->_isRead ($is_read); $this->_isFavorite ($is_favorite); $this->_feed ($feed); - $this->_tags (array ()); + $this->_tags (preg_split('/[\s#]/', $tags)); } public function id () { @@ -81,11 +81,7 @@ class Entry extends Model { } public function tags ($inString = false) { if ($inString) { - if (!empty ($this->tags)) { - return '#' . implode(' #', $this->tags); - } else { - return ''; - } + return empty ($this->tags) ? '' : '#' . implode(' #', $this->tags); } else { return $this->tags; } @@ -110,8 +106,8 @@ class Entry extends Model { $this->link = $value; } public function _date ($value) { - if (is_int (intval ($value))) { - $this->date = $value; + if (is_int ($value)) { + $this->date = intval ($value); } else { $this->date = time (); } @@ -448,13 +444,8 @@ class EntryDAO extends Model_pdo { $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); - list ($entry, $next) = HelperEntry::daoToEntry ($res); - - if (isset ($entry[0])) { - return $entry[0]; - } else { - return false; - } + $entries = HelperEntry::daoToEntry ($res); + return isset ($entries[0]) ? $entries[0] : false; } public function searchById ($id) { @@ -466,60 +457,79 @@ class EntryDAO extends Model_pdo { $stm->execute ($values); $res = $stm->fetchAll (PDO::FETCH_ASSOC); - list ($entry, $next) = HelperEntry::daoToEntry ($res); - - if (isset ($entry[0])) { - return $entry[0]; - } else { - return false; + $entries = HelperEntry::daoToEntry ($res); + return isset ($entries[0]) ? $entries[0] : false; + } + + public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = -1, $filter = '') { + $where = ''; + $values = array(); + switch ($type) { + case 'a': + $where .= 'priority > 0 '; + break; + case 's': + $where .= 'is_favorite = 1 '; + break; + case 'c': + $where .= 'category = ? '; + $values[] = intval($id); + break; + case 'f': + $where .= 'id_feed = ? '; + $values[] = intval($id); + break; + default: + throw new EntriesGetterException ('Bad type in Entry->listByType: [' . $type . ']!'); } - } - - private function listWhere ($where, $state, $order, $limitFromId = '', $limitCount = '', $values = array ()) { - if ($state === 'not_read') { - $where .= ' AND is_read = 0'; - } elseif ($state === 'read') { - $where .= ' AND is_read = 1'; + switch ($state) { + case 'all': + break; + case 'not_read': + $where .= 'AND is_read = 0 '; + break; + case 'read': + $where .= 'AND is_read = 1 '; + break; + default: + throw new EntriesGetterException ('Bad state in Entry->listByType: [' . $state . ']!'); } - if (!empty($limitFromId)) { - $where .= ' AND e.id ' . ($order === 'low_to_high' ? '<=' : '>=') . $limitFromId; + switch ($order) { + case 'DESC': + case 'ASC': + break; + default: + throw new EntriesGetterException ('Bad order in Entry->listByType: [' . $order . ']!'); } - - if ($order === 'low_to_high') { - $order = ' DESC'; - } else { - $order = ''; + if ($firstId > 0) { + $where .= 'AND e.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; + } + $terms = explode(' ', trim($filter)); + sort($terms); //Put #tags first + foreach ($terms as $word) { + if (!empty($word)) { + if ($word[0] === '#' && isset($word[1])) { + $where .= 'AND tags LIKE "%' . $word . '%" '; + } elseif (!empty($word)) { + $where .= 'AND (e.title LIKE "%' . $word . '%" OR UNCOMPRESS(e.content_bin) LIKE "%' . $word . '%") '; + } + } } $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 ' . 'FROM `' . $this->prefix . 'entry` e ' - . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id ' . $where - . ' ORDER BY e.id' . $order; + . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE ' . $where + . 'ORDER BY e.id ' . $order; - if (empty($limitCount)) { - $limitCount = 20000; //TODO: FIXME: Hack temporaire en attendant la recherche côté base-de-données + if ($limit > 0) { + $sql .= ' LIMIT ' . $limit; //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ } - //if (!empty($limitCount)) { - $sql .= ' LIMIT ' . ($limitCount + 2); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ - //} $stm = $this->bd->prepare ($sql); $stm->execute ($values); return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC)); } - public function listEntries ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE priority > 0', $state, $order, $limitFromId, $limitCount); - } - public function listFavorites ($state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE is_favorite = 1', $state, $order, $limitFromId, $limitCount); - } - public function listByCategory ($cat, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE category = ?', $state, $order, $limitFromId, $limitCount, array ($cat)); - } - public function listByFeed ($feed, $state, $order = 'high_to_low', $limitFromId = '', $limitCount = '') { - return $this->listWhere ('WHERE id_feed = ?', $state, $order, $limitFromId, $limitCount, array ($feed)); - } public function listLastGuidsByFeed($id, $n) { $sql = 'SELECT guid FROM `' . $this->prefix . 'entry` WHERE id_feed=? ORDER BY id DESC LIMIT ' . intval($n); @@ -579,14 +589,6 @@ class EntryDAO extends Model_pdo { } class HelperEntry { - public static $nb = 1; - public static $first = ''; - - public static $filter = array ( - 'words' => array (), - 'tags' => array (), - ); - public static function daoToEntry ($listDAO) { $list = array (); @@ -594,80 +596,27 @@ class HelperEntry { $listDAO = array ($listDAO); } - $count = 0; - $first_is_found = false; - $break_after = false; - $next = ''; foreach ($listDAO as $key => $dao) { - $dao['tags'] = preg_split('/[\s#]/', $dao['tags']); - - if (self::tagsMatchEntry ($dao) && - self::searchMatchEntry ($dao)) { - if ($break_after) { - $next = $dao['id']; - break; - } - if ($first_is_found || $dao['id'] == self::$first || self::$first == '') { - $list[$key] = self::createEntry ($dao); - - $count++; - $first_is_found = true; //TODO: Update: Now done in SQL - } - if ($count >= self::$nb) { - $break_after = true; - } + $entry = new Entry ( + $dao['id_feed'], + $dao['guid'], + $dao['title'], + $dao['author'], + $dao['content'], + $dao['link'], + $dao['date'], + $dao['is_read'], + $dao['is_favorite'], + $dao['tags'] + ); + if (isset ($dao['id'])) { + $entry->_id ($dao['id']); } + $list[] = $entry; } unset ($listDAO); - return array ($list, $next); - } - - private static function createEntry ($dao) { - $entry = new Entry ( - $dao['id_feed'], - $dao['guid'], - $dao['title'], - $dao['author'], - $dao['content'], - $dao['link'], - $dao['date'], - $dao['is_read'], - $dao['is_favorite'] - ); - - $entry->_tags ($dao['tags']); - - if (isset ($dao['id'])) { - $entry->_id ($dao['id']); - } - - return $entry; - } - - private static function tagsMatchEntry ($dao) { - $tags = self::$filter['tags']; - foreach ($tags as $tag) { - if (!in_array ($tag, $dao['tags'])) { - return false; - } - } - - return true; - } - private static function searchMatchEntry ($dao) { - $words = self::$filter['words']; - - foreach ($words as $word) { - $word = strtolower ($word); - if (strpos (strtolower ($dao['title']), $word) === false && - strpos (strtolower ($dao['content']), $word) === false && - strpos (strtolower ($dao['link']), $word) === false) { - return false; - } - } - - return true; + return $list; } } diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php index 37f26b1dd..007c1c0f5 100755 --- a/app/models/RSSConfiguration.php +++ b/app/models/RSSConfiguration.php @@ -213,11 +213,7 @@ class RSSConfiguration extends Model { } } public function _sortOrder ($value) { - if ($value == 'high_to_low') { - $this->sort_order = 'high_to_low'; - } else { - $this->sort_order = 'low_to_high'; - } + $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC'; } public function _oldEntries ($value) { if (is_int (intval ($value)) && $value > 0) { @@ -334,7 +330,7 @@ class RSSConfigurationDAO extends Model_array { public $display_posts = 'no'; public $onread_jump_next = 'yes'; public $lazyload = 'yes'; - public $sort_order = 'low_to_high'; + public $sort_order = 'DESC'; public $old_entries = 3; public $shortcuts = array ( 'mark_read' => 'r', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 52fd80185..90416145a 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -73,8 +73,8 @@
    -- cgit v1.2.3 From 1e077160fca3306a273ecae5a366fd756c32baee Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 30 Nov 2013 22:47:48 +0100 Subject: Optimisation recherche et pagination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Optimisation recherche SQL avec utilisation de HAVING plutôt que WHERE * Simplification et amélioration des performances en supprimant de RSSPaginator qui n'aidait plus vraiment et nécessitait plus de code et des copies de données. * Correction d'un bug dans le titre de la page introduit récemment, et simplification --- app/App_FrontController.php | 1 - app/controllers/indexController.php | 33 +++++++++++++--------------- app/layout/layout.phtml | 5 ++--- app/layout/nav_menu.phtml | 4 ++-- app/models/Entry.php | 11 +++++++--- app/models/RSSPaginator.php | 37 -------------------------------- app/views/helpers/pagination.phtml | 4 ++-- app/views/helpers/view/normal_view.phtml | 8 +++---- app/views/helpers/view/reader_view.phtml | 7 +++--- app/views/helpers/view/rss_view.phtml | 3 +-- 10 files changed, 36 insertions(+), 77 deletions(-) delete mode 100644 app/models/RSSPaginator.php (limited to 'app/App_FrontController.php') diff --git a/app/App_FrontController.php b/app/App_FrontController.php index d701e2944..176677781 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -33,7 +33,6 @@ class App_FrontController extends FrontController { include (APP_PATH . '/models/Category.php'); include (APP_PATH . '/models/Feed.php'); include (APP_PATH . '/models/Entry.php'); - include (APP_PATH . '/models/RSSPaginator.php'); include (APP_PATH . '/models/Log_Model.php'); } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index cf0e5024a..b3ae40847 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -46,8 +46,6 @@ class indexController extends ActionController { 'params' => $params ); - $this->view->rss_title = View::title(); - if ($output === 'rss') { // no layout for RSS output $this->view->_useLayout (false); @@ -67,19 +65,6 @@ class indexController extends ActionController { $this->view->get_c = ''; $this->view->get_f = ''; - // mise à jour des titres - $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); - if ($this->view->nb_not_read > 0) { - View::appendTitle (' (' . $this->view->nb_not_read . ')'); - } - View::prependTitle (' - '); - - $this->view->rss_title = $this->view->currentName . ' - ' . $this->view->rss_title; - View::prependTitle ( - $this->view->currentName . - ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') - ); - $get = Request::param ('get', 'a'); $getType = $get[0]; $getId = substr ($get, 2); @@ -92,6 +77,18 @@ class indexController extends ActionController { return; } + $this->view->nb_not_read = HelperCategory::CountUnreads($this->view->cat_aside, 1); + + // mise à jour des titres + if ($this->view->nb_not_read > 0) { + View::appendTitle (' (' . $this->view->nb_not_read . ')'); + } + View::prependTitle ( + $this->view->currentName . + ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') . + ' - ' + ); + // On récupère les différents éléments de filtrage $this->view->state = $state = Request::param ('state', $this->view->conf->defaultView ()); $filter = Request::param ('search', ''); @@ -138,13 +135,13 @@ class indexController extends ActionController { } if (count($entries) <= $nb) { - $next = ''; + $this->view->nextId = ''; } else { //We have more elements for pagination $lastEntry = array_pop($entries); - $next = $lastEntry->id(); + $this->view->nextId = $lastEntry->id(); } - $this->view->entryPaginator = new RSSPaginator ($entries, $next); + $this->view->entries = $entries; } catch (EntriesGetterException $e) { Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); Error::error ( diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index 9b502275c..6fc5c1cf0 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -10,10 +10,9 @@ renderHelper ('javascript_vars'); ?> //]]> entryPaginator) ? $this->entryPaginator->next() : ''; - if (!empty($next)) { + if (!empty($this->nextId)) { $params = Request::params (); - $params['next'] = $next; + $params['next'] = $this->nextId; ?> diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 289fe6542..4b4945108 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -17,8 +17,6 @@ $string_mark = Translate::t ('mark_cat_read'); } $nextGet = $get; - $p = $this->entryPaginator->peek(); - $idMax = $p === null ? '0' : $p->id(); if (($this->conf->onread_jump_next () === 'yes') && (strlen ($get) > 2)) { $anotherUnreadId = ''; $foundCurrent = false; @@ -54,6 +52,8 @@ break; } } + $p = isset($this->entries[0]) ? $this->entries[0] : null; + $idMax = $p === null ? '0' : $p->id(); $markReadUrl = _url ('entry', 'read', 'is_read', 1, 'get', $get, 'nextGet', $nextGet, 'idMax', $idMax); Session::_param ('markReadUrl', $markReadUrl); ?> diff --git a/app/models/Entry.php b/app/models/Entry.php index 915fbccc8..ae8facf68 100755 --- a/app/models/Entry.php +++ b/app/models/Entry.php @@ -504,14 +504,18 @@ class EntryDAO extends Model_pdo { if ($firstId > 0) { $where .= 'AND e.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' '; } - $terms = explode(' ', trim($filter)); + $terms = array_unique(explode(' ', trim($filter))); sort($terms); //Put #tags first + $having = ''; foreach ($terms as $word) { if (!empty($word)) { if ($word[0] === '#' && isset($word[1])) { - $where .= 'AND tags LIKE "%' . $word . '%" '; + $having .= 'AND tags LIKE ? '; + $values[] = '%' . $word .'%'; } elseif (!empty($word)) { - $where .= 'AND (e.title LIKE "%' . $word . '%" OR UNCOMPRESS(e.content_bin) LIKE "%' . $word . '%") '; + $having .= 'AND (e.title LIKE ? OR content LIKE ?) '; + $values[] = '%' . $word .'%'; + $values[] = '%' . $word .'%'; } } } @@ -519,6 +523,7 @@ class EntryDAO extends Model_pdo { $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 ' . 'FROM `' . $this->prefix . 'entry` e ' . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE ' . $where + . (empty($having) ? '' : 'HAVING' . substr($having, 3)) . 'ORDER BY e.id ' . $order; if ($limit > 0) { diff --git a/app/models/RSSPaginator.php b/app/models/RSSPaginator.php deleted file mode 100644 index 39146f1ba..000000000 --- a/app/models/RSSPaginator.php +++ /dev/null @@ -1,37 +0,0 @@ -items = $items; - $this->next = $next; - } - - public function isEmpty () { - return empty ($this->items); - } - - public function items () { - return $this->items; - } - - public function next () { - return $this->next; - } - - public function peek () { - return isset($this->items[0]) ? $this->items[0] : null; - } - - public function render ($view, $getteur) { - $view = APP_PATH . '/views/helpers/'.$view; - - if (file_exists ($view)) { - include ($view); - } - } -} diff --git a/app/views/helpers/pagination.phtml b/app/views/helpers/pagination.phtml index 0b0d2f5ba..408cfca1b 100755 --- a/app/views/helpers/pagination.phtml +++ b/app/views/helpers/pagination.phtml @@ -8,8 +8,8 @@
    diff --git a/app/views/helpers/pagination.phtml b/app/views/helpers/pagination.phtml index 408cfca1b..d4983a32e 100755 --- a/app/views/helpers/pagination.phtml +++ b/app/views/helpers/pagination.phtml @@ -1,25 +1,25 @@
    • nextId)) { ?> nextId; ?> - + -
      +

      - +
      -
      +
    • diff --git a/app/views/helpers/view/global_view.phtml b/app/views/helpers/view/global_view.phtml index ac17d608a..bc6e24e37 100644 --- a/app/views/helpers/view/global_view.phtml +++ b/app/views/helpers/view/global_view.phtml @@ -32,5 +32,5 @@
      conf->displayPosts () === 'no' ? ' class="hide_posts"' : ''; ?>> - +
      \ No newline at end of file diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index 1a7efa58f..094017957 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -24,23 +24,23 @@ if (!empty($this->entries)) { ?> entries as $item) { ?> - isDay (Days::TODAY)) { ?> + isDay (FreshRSS_Days::TODAY)) { ?>
      - + - currentName; ?>
      - isDay (Days::YESTERDAY)) { ?> + isDay (FreshRSS_Days::YESTERDAY)) { ?>
      - + - currentName; ?>
      - isDay (Days::BEFORE_YESTERDAY)) { ?> + isDay (FreshRSS_Days::BEFORE_YESTERDAY)) { ?>
      - + currentName; ?>
      @@ -51,13 +51,13 @@ if (!empty($this->entries)) { if ($this->conf->toplineRead ()) { ?>
    • isRead () ? 'read' : 'unread'); ?>isRead () ? 'read' : 'unread'); ?>
    • conf->toplineFavorite ()) { ?>
    • isFavorite () ? 'starred' : 'non-starred'); ?>isFavorite () ? 'starred' : 'non-starred'); ?>
    • entries)) {
    • ✇ name(); ?>
    • title (); ?>
    • conf->toplineDate ()) { ?>
    • date (); ?> 
    • - conf->toplineLink ()) { ?> + conf->toplineLink ()) { ?>
    @@ -75,7 +75,7 @@ if (!empty($this->entries)) {

    title (); ?>

    author (); - echo $author != '' ? '
    ' . Translate::t ('by_author', $author) . '
    ' : ''; + echo $author != '' ? '
    ' . Minz_Translate::t ('by_author', $author) . '
    ' : ''; if($this->conf->lazyload() == 'yes') { echo lazyimg($item->content ()); } else { @@ -83,19 +83,18 @@ if (!empty($this->entries)) { } ?>
    -
      conf) || is_logged ()) { if ($this->conf->bottomlineRead ()) { ?>
    • isRead () ? 'read' : 'unread'); ?>isRead () ? 'read' : 'unread'); ?>
    • conf->bottomlineFavorite ()) { ?>
    • isFavorite () ? 'starred' : 'non-starred'); ?>isFavorite () ? 'starred' : 'non-starred'); ?>
    • @@ -111,8 +110,8 @@ if (!empty($this->entries)) { @@ -204,6 +203,6 @@ if (!empty($this->entries)) {
      - +
      \ No newline at end of file diff --git a/app/views/helpers/view/reader_view.phtml b/app/views/helpers/view/reader_view.phtml index 30226af42..29b2be04c 100644 --- a/app/views/helpers/view/reader_view.phtml +++ b/app/views/helpers/view/reader_view.phtml @@ -21,7 +21,7 @@ if (!empty($this->entries)) {
      author (); ?> - + date (); ?>
      @@ -42,6 +42,6 @@ if (!empty($this->entries)) {
      - +
      \ No newline at end of file diff --git a/app/views/helpers/view/rss_view.phtml b/app/views/helpers/view/rss_view.phtml index 460146dc0..620bf1388 100755 --- a/app/views/helpers/view/rss_view.phtml +++ b/app/views/helpers/view/rss_view.phtml @@ -2,11 +2,11 @@ <?php echo $this->rss_title; ?> - - rss_title); ?> + + rss_title); ?> GMT - + entries as $item) { ?> diff --git a/app/views/index/about.phtml b/app/views/index/about.phtml index fa799154b..b5c00a1ed 100644 --- a/app/views/index/about.phtml +++ b/app/views/index/about.phtml @@ -1,24 +1,24 @@
      - + -

      +

      -
      +
      -
      -
      Marien Fressinaud -
      +
      +
      Marien Fressinaud -
      -
      -
      +
      +
      -
      -
      +
      +
      -

      +

      -

      -

      +

      +

      diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index bd18d2d77..cf98060c4 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -1,8 +1,8 @@ conf->token(); -$token_param = Request::param ('token', ''); +$token_param = Minz_Request::param ('token', ''); $token_is_ok = ($token != '' && $token == $token_param); if(!login_is_conf ($this->conf) || @@ -21,9 +21,9 @@ if(!login_is_conf ($this->conf) || } else { ?>
      -

      -

      -

      +

      +

      +

      - + -

      +

      - +

      logsPaginator->items (); ?> @@ -20,6 +20,6 @@ logsPaginator->render ('logs_pagination.phtml','page'); ?> -

      +

      diff --git a/app/views/javascript/actualize.phtml b/app/views/javascript/actualize.phtml index f39540a9a..69689133c 100644 --- a/app/views/javascript/actualize.phtml +++ b/app/views/javascript/actualize.phtml @@ -1,12 +1,12 @@ var feeds = new Array (); feeds as $feed) { ?> -feeds.push (" 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>"); +feeds.push (" 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>"); function initProgressBar (init) { if (init) { $("body").after ("\
      \ - 0 / " + feeds.length + "
      \ + 0 / " + feeds.length + "
      \ \
      "); } else { diff --git a/lib/Minz/ActionException.php b/lib/Minz/ActionException.php new file mode 100644 index 000000000..c566a076f --- /dev/null +++ b/lib/Minz/ActionException.php @@ -0,0 +1,9 @@ + +*/ + +/** + * La classe Cache permet de gérer facilement les pages en cache + */ +class Minz_Cache { + /** + * $expire timestamp auquel expire le cache de $url + */ + private $expire = 0; + + /** + * $file est le nom du fichier de cache + */ + private $file = ''; + + /** + * $enabled permet de déterminer si le cache est activé + */ + private static $enabled = true; + + /** + * Constructeur + */ + public function __construct () { + $this->_fileName (); + $this->_expire (); + } + + /** + * Setteurs + */ + public function _fileName () { + $file = md5 (Minz_Request::getURI ()); + + $this->file = CACHE_PATH . '/'.$file; + } + + public function _expire () { + if ($this->exist ()) { + $this->expire = filemtime ($this->file) + + Minz_Configuration::delayCache (); + } + } + + /** + * Permet de savoir si le cache est activé + * @return true si activé, false sinon + */ + public static function isEnabled () { + return Minz_Configuration::cacheEnabled () && self::$enabled; + } + + /** + * Active / désactive le cache + */ + public static function switchOn () { + self::$enabled = true; + } + public static function switchOff () { + self::$enabled = false; + } + + /** + * Détermine si le cache de $url a expiré ou non + * @return true si il a expiré, false sinon + */ + public function expired () { + return time () > $this->expire; + } + + /** + * Affiche le contenu du cache + * @print le code html du cache + */ + public function render () { + if ($this->exist ()) { + include ($this->file); + } + } + + /** + * Enregistre $html en cache + * @param $html le html à mettre en cache + */ + public function cache ($html) { + file_put_contents ($this->file, $html); + } + + /** + * Permet de savoir si le cache existe + * @return true si il existe, false sinon + */ + public function exist () { + return file_exists ($this->file); + } + + /** + * Nettoie le cache en supprimant tous les fichiers + */ + public static function clean () { + $files = opendir (CACHE_PATH); + + while ($fic = readdir ($files)) { + if ($fic != '.' && $fic != '..') { + unlink (CACHE_PATH.'/'.$fic); + } + } + + closedir ($files); + } +} diff --git a/lib/Minz/ControllerNotActionControllerException.php b/lib/Minz/ControllerNotActionControllerException.php new file mode 100644 index 000000000..535a1377e --- /dev/null +++ b/lib/Minz/ControllerNotActionControllerException.php @@ -0,0 +1,9 @@ + +*/ + +/** + * La classe Log permet de logger des erreurs + */ +class Minz_Log { + /** + * Les différents niveau de log + * ERROR erreurs bloquantes de l'application + * WARNING erreurs pouvant géner le bon fonctionnement, mais non bloquantes + * NOTICE erreurs mineures ou messages d'informations + * DEBUG Informations affichées pour le déboggage + */ + const ERROR = 2; + const WARNING = 4; + const NOTICE = 8; + const DEBUG = 16; + + /** + * Enregistre un message dans un fichier de log spécifique + * Message non loggué si + * - environment = SILENT + * - level = WARNING et environment = PRODUCTION + * - level = NOTICE et environment = PRODUCTION + * @param $information message d'erreur / information à enregistrer + * @param $level niveau d'erreur + * @param $file_name fichier de log, par défaut LOG_PATH/application.log + */ + public static function record ($information, $level, $file_name = null) { + $env = Minz_Configuration::environment (); + + if (! ($env === Minz_Configuration::SILENT + || ($env === Minz_Configuration::PRODUCTION + && ($level >= Minz_Log::NOTICE)))) { + if (is_null ($file_name)) { + $file_name = LOG_PATH . '/application.log'; + } + + switch ($level) { + case Minz_Log::ERROR : + $level_label = 'error'; + break; + case Minz_Log::WARNING : + $level_label = 'warning'; + break; + case Minz_Log::NOTICE : + $level_label = 'notice'; + break; + case Minz_Log::DEBUG : + $level_label = 'debug'; + break; + default : + $level_label = 'unknown'; + } + + if ($env == Minz_Configuration::PRODUCTION) { + $file = @fopen ($file_name, 'a'); + } else { + $file = fopen ($file_name, 'a'); + } + + if ($file !== false) { + $log = '[' . date('r') . ']'; + $log .= ' [' . $level_label . ']'; + $log .= ' --- ' . $information . "\n"; + fwrite ($file, $log); + fclose ($file); + } else { + throw new Minz_PermissionDeniedException ( + $file_name, + Minz_Exception::ERROR + ); + } + } + } + + /** + * Automatise le log des variables globales $_GET et $_POST + * Fait appel à la fonction record(...) + * Ne fonctionne qu'en environnement "development" + * @param $file_name fichier de log, par défaut LOG_PATH/application.log + */ + public static function recordRequest($file_name = null) { + $msg_get = str_replace("\n", '', '$_GET content : ' . print_r($_GET, true)); + $msg_post = str_replace("\n", '', '$_POST content : ' . print_r($_POST, true)); + + self::record($msg_get, Minz_Log::DEBUG, $file_name); + self::record($msg_post, Minz_Log::DEBUG, $file_name); + } +} diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php new file mode 100644 index 000000000..4ba022143 --- /dev/null +++ b/lib/Minz/ModelArray.php @@ -0,0 +1,122 @@ + +*/ + +/** + * La classe Model_array représente le modèle interragissant avec les fichiers de type texte gérant des tableaux php + */ +class Minz_ModelArray extends Minz_ModelTxt { + /** + * $array Le tableau php contenu dans le fichier $nameFile + */ + protected $array = array (); + + /** + * Ouvre le fichier indiqué, charge le tableau dans $array et le $nameFile + * @param $nameFile le nom du fichier à ouvrir contenant un tableau + * Remarque : $array sera obligatoirement un tableau + */ + public function __construct ($nameFile) { + parent::__construct ($nameFile); + + if (!$this->getLock ('read')) { + throw new Minz_PermissionDeniedException ($this->filename); + } else { + $this->array = include ($this->filename); + $this->releaseLock (); + + if (!is_array ($this->array)) { + $this->array = array (); + } + + $this->array = $this->decodeArray ($this->array); + } + } + + /** + * Écrit un tableau dans le fichier $nameFile + * @param $array le tableau php à enregistrer + **/ + public function writeFile ($array) { + if (!$this->getLock ('write')) { + throw new Minz_PermissionDeniedException ($this->namefile); + } else { + $this->erase (); + + $this->writeLine ('writeLine ('return ', false); + $this->writeArray ($array); + $this->writeLine (';'); + + $this->releaseLock (); + } + } + + private function writeArray ($array, $profondeur = 0) { + $tab = ''; + for ($i = 0; $i < $profondeur; $i++) { + $tab .= "\t"; + } + $this->writeLine ('array ('); + + foreach ($array as $key => $value) { + if (is_int ($key)) { + $this->writeLine ($tab . "\t" . $key . ' => ', false); + } else { + $this->writeLine ($tab . "\t" . '\'' . $key . '\'' . ' => ', false); + } + + if (is_array ($value)) { + $this->writeArray ($value, $profondeur + 1); + $this->writeLine (','); + } else { + if (is_numeric ($value)) { + $this->writeLine ($value . ','); + } else { + $this->writeLine ('\'' . addslashes ($value) . '\','); + } + } + } + + $this->writeLine ($tab . ')', false); + } + + private function decodeArray ($array) { + $new_array = array (); + + foreach ($array as $key => $value) { + if (is_array ($value)) { + $new_array[$key] = $this->decodeArray ($value); + } else { + $new_array[$key] = stripslashes ($value); + } + } + + return $new_array; + } + + private function getLock ($type) { + if ($type == 'write') { + $lock = LOCK_EX; + } else { + $lock = LOCK_SH; + } + + $count = 1; + while (!flock ($this->file, $lock) && $count <= 50) { + $count++; + } + + if ($count >= 50) { + return false; + } else { + return true; + } + } + + private function releaseLock () { + flock ($this->file, LOCK_UN); + } +} diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php new file mode 100644 index 000000000..9655539b2 --- /dev/null +++ b/lib/Minz/ModelPdo.php @@ -0,0 +1,111 @@ + +*/ + +/** + * La classe Model_sql représente le modèle interragissant avec les bases de données + * Seul la connexion MySQL est prise en charge pour le moment + */ +class Minz_ModelPdo { + + /** + * Partage la connexion à la base de données entre toutes les instances. + */ + public static $useSharedBd = true; + private static $sharedBd = null; + private static $sharedPrefix; + + /** + * $bd variable représentant la base de données + */ + protected $bd; + + protected $prefix; + + /** + * Créé la connexion à la base de données à l'aide des variables + * HOST, BASE, USER et PASS définies dans le fichier de configuration + */ + public function __construct () { + if (self::$useSharedBd && self::$sharedBd != null) { + $this->bd = self::$sharedBd; + $this->prefix = self::$sharedPrefix; + return; + } + + $db = Minz_Configuration::dataBase (); + $driver_options = null; + + try { + $type = $db['type']; + if($type == 'mysql') { + $string = $type + . ':host=' . $db['host'] + . ';dbname=' . $db['base'] + . ';charset=utf8'; + $driver_options = array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' + ); + } 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 + } + + $this->bd = new FreshPDO ( + $string, + $db['user'], + $db['password'], + $driver_options + ); + self::$sharedBd = $this->bd; + + $userPrefix = Minz_Configuration::currentUser (); + $this->prefix = $db['prefix'] . (empty($userPrefix) ? '' : ($userPrefix . '_')); + self::$sharedPrefix = $this->prefix; + } catch (Exception $e) { + throw new Minz_PDOConnectionException ( + $string, + $db['user'], Minz_Exception::ERROR + ); + } + } + + public function beginTransaction() { + $this->bd->beginTransaction(); + } + public function commit() { + $this->bd->commit(); + } + public function rollBack() { + $this->bd->rollBack(); + } + + public function size() { + $db = Minz_Configuration::dataBase (); + $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = ?'; + $stm = $this->bd->prepare ($sql); + $values = array ($db['base']); + $stm->execute ($values); + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return $res[0]; + } +} + +class FreshPDO extends PDO { + private static function check($statement) { + if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { + invalidateHttpCache(); + } + } + + public function prepare ($statement, $driver_options = array()) { + FreshPDO::check($statement); + return parent::prepare($statement, $driver_options); + } + + public function exec ($statement) { + FreshPDO::check($statement); + return parent::exec($statement); + } +} diff --git a/lib/Minz/ModelTxt.php b/lib/Minz/ModelTxt.php new file mode 100644 index 000000000..8c5973f4d --- /dev/null +++ b/lib/Minz/ModelTxt.php @@ -0,0 +1,84 @@ + +*/ + +/** + * La classe Model_txt représente le modèle interragissant avec les fichiers de type texte + */ +class Minz_ModelTxt { + /** + * $file représente le fichier à ouvrir + */ + protected $file; + + /** + * $filename est le nom du fichier + */ + protected $filename; + + /** + * Ouvre un fichier dans $file + * @param $nameFile nom du fichier à ouvrir + * @param $mode mode d'ouverture du fichier ('a+' par défaut) + * @exception FileNotExistException si le fichier n'existe pas + * > ou ne peux pas être ouvert + */ + public function __construct ($nameFile, $mode = 'a+') { + $this->filename = $nameFile; + if (!file_exists($this->filename)) { + throw new Minz_FileNotExistException ( + $this->filename, + Minz_Exception::WARNING + ); + } + + $this->file = @fopen ($this->filename, $mode); + + if (!$this->file) { + throw new Minz_PermissionDeniedException ( + $this->filename, + Minz_Exception::WARNING + ); + } + } + + /** + * Lit une ligne de $file + * @return une ligne du fichier + */ + public function readLine () { + return fgets ($this->file); + } + + /** + * Écrit une ligne dans $file + * @param $line la ligne à écrire + */ + public function writeLine ($line, $newLine = true) { + $char = ''; + if ($newLine) { + $char = "\n"; + } + + fwrite ($this->file, $line . $char); + } + + /** + * Efface le fichier $file + * @return true en cas de succès, false sinon + */ + public function erase () { + return ftruncate ($this->file, 0); + } + + /** + * Ferme $file + */ + public function __destruct () { + if (isset ($this->file)) { + fclose ($this->file); + } + } +} diff --git a/lib/Minz/PDOConnectionException.php b/lib/Minz/PDOConnectionException.php new file mode 100644 index 000000000..faf2e0fe9 --- /dev/null +++ b/lib/Minz/PDOConnectionException.php @@ -0,0 +1,9 @@ +route = $route; + + $message = 'Route `' . $route . '` not found'; + + parent::__construct ($message, $code); + } + + public function route () { + return $this->route; + } +} diff --git a/lib/SimplePie_autoloader.php b/lib/SimplePie_autoloader.php deleted file mode 100644 index 3f67635b0..000000000 --- a/lib/SimplePie_autoloader.php +++ /dev/null @@ -1,86 +0,0 @@ -path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'SimplePie'; - } - - /** - * Autoloader - * - * @param string $class The name of the class to attempt to load. - */ - public function autoload($class) - { - // Only load the class if it starts with "SimplePie" - if (strpos($class, 'SimplePie') !== 0) - { - return; - } - - $filename = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; - include $filename; - } -} diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 4f5b90b61..2fdfd4bd8 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -15,6 +15,31 @@ if (!function_exists('json_encode')) { } } +// +function classAutoloader($class) { + if (strpos($class, 'FreshRSS') === 0) { + $components = explode('_', $class); + switch (count($components)) { + case 1: + include(APP_PATH . '/' . $components[0] . '.php'); + return; + case 2: + include(APP_PATH . '/Models/' . $components[1] . '.php'); + return; + case 3: //Controllers, Exceptions + include(APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php'); + return; + } + } elseif (strpos($class, 'Minz') === 0) { + include(LIB_PATH . '/' . str_replace('_', '/', $class) . '.php'); + } elseif (strpos($class, 'SimplePie') === 0) { + include(LIB_PATH . '/SimplePie/' . str_replace('_', '/', $class) . '.php'); + } +} + +spl_autoload_register('classAutoloader'); +// + function checkUrl($url) { if (empty ($url)) { return ''; @@ -33,7 +58,7 @@ function checkUrl($url) { // vérifie qu'on est connecté function is_logged () { - return Session::param ('mail') != false; + return Minz_Session::param ('mail') != false; } // vérifie que le système d'authentification est configuré @@ -63,11 +88,11 @@ function formatBytes($bytes, $precision = 2, $system = 'IEC') { } function timestamptodate ($t, $hour = true) { - $month = Translate::t (date('M', $t)); + $month = Minz_Translate::t (date('M', $t)); if ($hour) { - $date = Translate::t ('format_date_hour', $month); + $date = Minz_Translate::t ('format_date_hour', $month); } else { - $date = Translate::t ('format_date', $month); + $date = Minz_Translate::t ('format_date', $month); } return @date ($date, $t); @@ -123,10 +148,10 @@ function opml_import ($xml) { $opml = simplexml_import_dom($dom); if (!$opml) { - throw new OpmlException (); + throw new FreshRSS_Opml_Exception (); } - $catDAO = new CategoryDAO(); + $catDAO = new FreshRSS_CategoryDAO(); $catDAO->checkDefault(); $defCat = $catDAO->getDefault(); @@ -152,10 +177,10 @@ function opml_import ($xml) { // 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_QUOTES, 'UTF-8'); - $catDAO = new CategoryDAO (); + $catDAO = new FreshRSS_CategoryDAO (); $cat = $catDAO->searchByName ($title); if ($cat === false) { - $cat = new Category ($title); + $cat = new FreshRSS_Category ($title); $values = array ( 'name' => $cat->name (), 'color' => $cat->color () @@ -204,7 +229,7 @@ function getFeed ($outline, $cat_id) { $title = (string) $outline['title']; } $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); - $feed = new Feed ($url); + $feed = new FreshRSS_Feed ($url); $feed->_category ($cat_id); $feed->_name ($title); if (isset($outline['htmlUrl'])) { @@ -250,7 +275,7 @@ function get_content_by_parsing ($url, $path) { function lazyimg($content) { return preg_replace( '/]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i', - '', + '', $content ); } diff --git a/lib/minz/ActionController.php b/lib/minz/ActionController.php index ab9389dbd..409d9611f 100755 --- a/lib/minz/ActionController.php +++ b/lib/minz/ActionController.php @@ -7,7 +7,7 @@ /** * La classe ActionController représente le contrôleur de l'application */ -class ActionController { +class Minz_ActionController { protected $router; protected $view; @@ -18,7 +18,7 @@ class ActionController { */ public function __construct ($router) { $this->router = $router; - $this->view = new View (); + $this->view = new Minz_View (); $this->view->attributeParams (); } diff --git a/lib/minz/Configuration.php b/lib/minz/Configuration.php index 7d6e3743e..9fc913964 100755 --- a/lib/minz/Configuration.php +++ b/lib/minz/Configuration.php @@ -7,7 +7,7 @@ /** * La classe Configuration permet de gérer la configuration de l'application */ -class Configuration { +class Minz_Configuration { const CONF_PATH_NAME = '/application.ini'; /** @@ -43,7 +43,7 @@ class Configuration { * - base le nom de la base de données */ private static $sel_application = ''; - private static $environment = Configuration::PRODUCTION; + private static $environment = Minz_Configuration::PRODUCTION; private static $base_url = ''; private static $use_url_rewriting = false; private static $title = ''; @@ -99,30 +99,30 @@ class Configuration { /** * Initialise les variables de configuration - * @exception FileNotExistException si le CONF_PATH_NAME n'existe pas - * @exception BadConfigurationException si CONF_PATH_NAME mal formaté + * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas + * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté */ public static function init () { try { self::parseFile (); self::setReporting (); - } catch (FileNotExistException $e) { + } catch (Minz_FileNotExistException $e) { throw $e; - } catch (BadConfigurationException $e) { + } catch (Minz_BadConfigurationException $e) { throw $e; } } /** * Parse un fichier de configuration de type ".ini" - * @exception FileNotExistException si le CONF_PATH_NAME n'existe pas - * @exception BadConfigurationException si CONF_PATH_NAME mal formaté + * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas + * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté */ private static function parseFile () { if (!file_exists (DATA_PATH . self::CONF_PATH_NAME)) { - throw new FileNotExistException ( + throw new Minz_FileNotExistException ( DATA_PATH . self::CONF_PATH_NAME, - MinzException::ERROR + Minz_Exception::ERROR ); } @@ -132,17 +132,17 @@ class Configuration { ); if (!$ini_array) { - throw new PermissionDeniedException ( + throw new Minz_PermissionDeniedException ( DATA_PATH . self::CONF_PATH_NAME, - MinzException::ERROR + Minz_Exception::ERROR ); } // [general] est obligatoire if (!isset ($ini_array['general'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( '[general]', - MinzException::ERROR + Minz_Exception::ERROR ); } $general = $ini_array['general']; @@ -150,9 +150,9 @@ class Configuration { // sel_application est obligatoire if (!isset ($general['sel_application'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'sel_application', - MinzException::ERROR + Minz_Exception::ERROR ); } self::$sel_application = $general['sel_application']; @@ -160,18 +160,18 @@ class Configuration { if (isset ($general['environment'])) { switch ($general['environment']) { case 'silent': - self::$environment = Configuration::SILENT; + self::$environment = Minz_Configuration::SILENT; break; case 'development': - self::$environment = Configuration::DEVELOPMENT; + self::$environment = Minz_Configuration::DEVELOPMENT; break; case 'production': - self::$environment = Configuration::PRODUCTION; + self::$environment = Minz_Configuration::PRODUCTION; break; default: - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'environment', - MinzException::ERROR + Minz_Exception::ERROR ); } @@ -194,7 +194,7 @@ class Configuration { if (CACHE_PATH === false && self::$cache_enabled) { throw new FileNotExistException ( 'CACHE_PATH', - MinzException::ERROR + Minz_Exception::ERROR ); } } @@ -213,27 +213,27 @@ class Configuration { } if ($db) { if (!isset ($db['host'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'host', - MinzException::ERROR + Minz_Exception::ERROR ); } if (!isset ($db['user'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'user', - MinzException::ERROR + Minz_Exception::ERROR ); } if (!isset ($db['password'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'password', - MinzException::ERROR + Minz_Exception::ERROR ); } if (!isset ($db['base'])) { - throw new BadConfigurationException ( + throw new Minz_BadConfigurationException ( 'base', - MinzException::ERROR + Minz_Exception::ERROR ); } diff --git a/lib/minz/Dispatcher.php b/lib/minz/Dispatcher.php index 0cfdd8e75..2898b5f00 100644 --- a/lib/minz/Dispatcher.php +++ b/lib/minz/Dispatcher.php @@ -9,8 +9,8 @@ * déterminée dans la Request * C'est un singleton */ -class Dispatcher { - const CONTROLLERS_PATH_NAME = '/controllers'; +class Minz_Dispatcher { + const CONTROLLERS_PATH_NAME = '/Controllers'; /* singleton */ private static $instance = null; @@ -23,7 +23,7 @@ class Dispatcher { */ public static function getInstance ($router) { if (is_null (self::$instance)) { - self::$instance = new Dispatcher ($router); + self::$instance = new Minz_Dispatcher ($router); } return self::$instance; } @@ -38,7 +38,7 @@ class Dispatcher { /** * Lance le controller indiqué dans Request * Remplit le body de Response à partir de la Vue - * @exception MinzException + * @exception Minz_Exception */ public function run () { $cache = new Minz_Cache(); @@ -53,29 +53,25 @@ class Dispatcher { $cache->render (); $text = ob_get_clean(); } else { - while (Request::$reseted) { - Request::$reseted = false; + while (Minz_Request::$reseted) { + Minz_Request::$reseted = false; try { - $this->createController ( - Request::controllerName () - . 'Controller' - ); - + $this->createController ('FreshRSS_' . Minz_Request::controllerName () . '_Controller'); $this->controller->init (); $this->controller->firstAction (); $this->launchAction ( - Request::actionName () + Minz_Request::actionName () . 'Action' ); $this->controller->lastAction (); - if (!Request::$reseted) { + if (!Minz_Request::$reseted) { ob_start (); $this->controller->view ()->build (); $text = ob_get_clean(); } - } catch (MinzException $e) { + } catch (Minz_Exception $e) { throw $e; } } @@ -85,14 +81,12 @@ class Dispatcher { } } - Response::setBody ($text); + Minz_Response::setBody ($text); } /** * Instancie le Controller * @param $controller_name le nom du controller à instancier - * @exception FileNotExistException le fichier correspondant au - * > controller n'existe pas * @exception ControllerNotExistException le controller n'existe pas * @exception ControllerNotActionControllerException controller n'est * > pas une instance de ActionController @@ -101,26 +95,18 @@ class Dispatcher { $filename = APP_PATH . self::CONTROLLERS_PATH_NAME . '/' . $controller_name . '.php'; - if (!file_exists ($filename)) { - throw new FileNotExistException ( - $filename, - MinzException::ERROR - ); - } - require_once ($filename); - if (!class_exists ($controller_name)) { - throw new ControllerNotExistException ( + throw new Minz_ControllerNotExistException ( $controller_name, - MinzException::ERROR + Minz_Exception::ERROR ); } $this->controller = new $controller_name ($this->router); - if (! ($this->controller instanceof ActionController)) { - throw new ControllerNotActionControllerException ( + if (! ($this->controller instanceof Minz_ActionController)) { + throw new Minz_ControllerNotActionControllerException ( $controller_name, - MinzException::ERROR + Minz_Exception::ERROR ); } } @@ -129,18 +115,18 @@ class Dispatcher { * Lance l'action sur le controller du dispatcher * @param $action_name le nom de l'action * @exception ActionException si on ne peut pas exécuter l'action sur - * > le controller + * le controller */ private function launchAction ($action_name) { - if (!Request::$reseted) { + if (!Minz_Request::$reseted) { if (!is_callable (array ( $this->controller, $action_name ))) { - throw new ActionException ( + throw new Minz_ActionException ( get_class ($this->controller), $action_name, - MinzException::ERROR + Minz_Exception::ERROR ); } call_user_func (array ( diff --git a/lib/minz/Error.php b/lib/minz/Error.php index 0e8c2f60b..1ad0d313c 100755 --- a/lib/minz/Error.php +++ b/lib/minz/Error.php @@ -1,5 +1,5 @@ */ @@ -7,7 +7,7 @@ /** * La classe Error permet de lancer des erreurs HTTP */ -class Error { +class Minz_Error { public function __construct () { } /** @@ -21,28 +21,28 @@ class Error { */ public static function error ($code = 404, $logs = array (), $redirect = false) { $logs = self::processLogs ($logs); - $error_filename = APP_PATH . '/controllers/errorController.php'; - + $error_filename = APP_PATH . '/Controllers/ErrorController.php'; + if (file_exists ($error_filename)) { $params = array ( 'code' => $code, 'logs' => $logs ); - - Response::setHeader ($code); + + Minz_Response::setHeader ($code); if ($redirect) { - Request::forward (array ( + Minz_Request::forward (array ( 'c' => 'error' ), true); } else { - Request::forward (array ( + Minz_Request::forward (array ( 'c' => 'error', 'params' => $params ), false); } } else { $text = '

      An error occured

      '."\n"; - + if (!empty ($logs)) { $text .= '
        '."\n"; foreach ($logs as $log) { @@ -50,14 +50,14 @@ class Error { } $text .= '
      '."\n"; } - - Response::setHeader ($code); - Response::setBody ($text); - Response::send (); + + Minz_Response::setHeader ($code); + Minz_Response::setBody ($text); + Minz_Response::send (); exit (); } } - + /** * Permet de retourner les logs de façon à n'avoir que * ceux que l'on veut réellement @@ -66,12 +66,12 @@ class Error { * > en fonction de l'environment */ private static function processLogs ($logs) { - $env = Configuration::environment (); + $env = Minz_Configuration::environment (); $logs_ok = array (); $error = array (); $warning = array (); $notice = array (); - + if (isset ($logs['error'])) { $error = $logs['error']; } @@ -81,14 +81,14 @@ class Error { if (isset ($logs['notice'])) { $notice = $logs['notice']; } - - if ($env == Configuration::PRODUCTION) { + + if ($env == Minz_Configuration::PRODUCTION) { $logs_ok = $error; } - if ($env == Configuration::DEVELOPMENT) { + if ($env == Minz_Configuration::DEVELOPMENT) { $logs_ok = array_merge ($error, $warning, $notice); } - + return $logs_ok; } } diff --git a/lib/minz/FrontController.php b/lib/minz/FrontController.php index d48d43d04..eb9835fe5 100755 --- a/lib/minz/FrontController.php +++ b/lib/minz/FrontController.php @@ -2,109 +2,79 @@ # ***** BEGIN LICENSE BLOCK ***** # MINZ - a free PHP Framework like Zend Framework # Copyright (C) 2011 Marien Fressinaud -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # ***** END LICENSE BLOCK ***** /** - * La classe FrontController est le noyau du framework, elle lance l'application + * La classe FrontController est le Dispatcher du framework, elle lance l'application * Elle est appelée en général dans le fichier index.php à la racine du serveur */ -class FrontController { +class Minz_FrontController { protected $dispatcher; protected $router; - + /** * Constructeur * Initialise le router et le dispatcher */ public function __construct () { - $this->loadLib (); - if (LOG_PATH === false) { $this->killApp ('Path doesn\'t exist : LOG_PATH'); } - + try { - Configuration::init (); + Minz_Configuration::init (); - Request::init (); + Minz_Request::init (); - $this->router = new Router (); + $this->router = new Minz_Router (); $this->router->init (); - } catch (RouteNotFoundException $e) { + } catch (Minz_RouteNotFoundException $e) { Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - Error::error ( + Minz_Error::error ( 404, array ('error' => array ($e->getMessage ())) ); - } catch (MinzException $e) { + } catch (Minz_Exception $e) { Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); $this->killApp ($e->getMessage ()); } - - $this->dispatcher = Dispatcher::getInstance ($this->router); - } - - /** - * Inclue les fichiers de la librairie - */ - private function loadLib () { - require ('ActionController.php'); - require ('Minz_Cache.php'); - require ('Configuration.php'); - require ('Dispatcher.php'); - require ('Error.php'); - require ('Helper.php'); - require ('Minz_Log.php'); - require ('Model.php'); - require ('Paginator.php'); - require ('Request.php'); - require ('Response.php'); - require ('Router.php'); - require ('Session.php'); - require ('Translate.php'); - require ('Url.php'); - require ('View.php'); - - require ('dao/Model_pdo.php'); - require ('dao/Model_txt.php'); - require ('dao/Model_array.php'); - - require ('exceptions/MinzException.php'); + + $this->dispatcher = Minz_Dispatcher::getInstance ($this->router); } - + /** * Démarre l'application (lance le dispatcher et renvoie la réponse */ public function run () { try { $this->dispatcher->run (); - Response::send (); - } catch (MinzException $e) { + Minz_Response::send (); + } catch (Minz_Exception $e) { try { Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - } catch (PermissionDeniedException $e) { + } catch (Minz_PermissionDeniedException $e) { $this->killApp ($e->getMessage ()); } - if ($e instanceof FileNotExistException || - $e instanceof ControllerNotExistException || - $e instanceof ControllerNotActionControllerException || - $e instanceof ActionException) { - Error::error ( + if ($e instanceof Minz_FileNotExistException || + $e instanceof Minz_ControllerNotExistException || + $e instanceof Minz_ControllerNotActionControllerException || + $e instanceof Minz_ActionException) { + Minz_Error::error ( 404, array ('error' => array ($e->getMessage ())), true @@ -114,7 +84,7 @@ class FrontController { } } } - + /** * Permet d'arrêter le programme en urgence */ diff --git a/lib/minz/Helper.php b/lib/minz/Helper.php index 4f64ba218..b058211d3 100755 --- a/lib/minz/Helper.php +++ b/lib/minz/Helper.php @@ -7,7 +7,7 @@ /** * La classe Helper représente une aide pour des tâches récurrentes */ -class Helper { +class Minz_Helper { /** * Annule les effets des magic_quotes pour une variable donnée * @param $var variable à traiter (tableau ou simple variable) diff --git a/lib/minz/Minz_Cache.php b/lib/minz/Minz_Cache.php deleted file mode 100644 index 6848e3350..000000000 --- a/lib/minz/Minz_Cache.php +++ /dev/null @@ -1,116 +0,0 @@ - -*/ - -/** - * La classe Cache permet de gérer facilement les pages en cache - */ -class Minz_Cache { - /** - * $expire timestamp auquel expire le cache de $url - */ - private $expire = 0; - - /** - * $file est le nom du fichier de cache - */ - private $file = ''; - - /** - * $enabled permet de déterminer si le cache est activé - */ - private static $enabled = true; - - /** - * Constructeur - */ - public function __construct () { - $this->_fileName (); - $this->_expire (); - } - - /** - * Setteurs - */ - public function _fileName () { - $file = md5 (Request::getURI ()); - - $this->file = CACHE_PATH . '/'.$file; - } - - public function _expire () { - if ($this->exist ()) { - $this->expire = filemtime ($this->file) - + Configuration::delayCache (); - } - } - - /** - * Permet de savoir si le cache est activé - * @return true si activé, false sinon - */ - public static function isEnabled () { - return Configuration::cacheEnabled () && self::$enabled; - } - - /** - * Active / désactive le cache - */ - public static function switchOn () { - self::$enabled = true; - } - public static function switchOff () { - self::$enabled = false; - } - - /** - * Détermine si le cache de $url a expiré ou non - * @return true si il a expiré, false sinon - */ - public function expired () { - return time () > $this->expire; - } - - /** - * Affiche le contenu du cache - * @print le code html du cache - */ - public function render () { - if ($this->exist ()) { - include ($this->file); - } - } - - /** - * Enregistre $html en cache - * @param $html le html à mettre en cache - */ - public function cache ($html) { - file_put_contents ($this->file, $html); - } - - /** - * Permet de savoir si le cache existe - * @return true si il existe, false sinon - */ - public function exist () { - return file_exists ($this->file); - } - - /** - * Nettoie le cache en supprimant tous les fichiers - */ - public static function clean () { - $files = opendir (CACHE_PATH); - - while ($fic = readdir ($files)) { - if ($fic != '.' && $fic != '..') { - unlink (CACHE_PATH.'/'.$fic); - } - } - - closedir ($files); - } -} diff --git a/lib/minz/Minz_Log.php b/lib/minz/Minz_Log.php deleted file mode 100644 index 12005aa88..000000000 --- a/lib/minz/Minz_Log.php +++ /dev/null @@ -1,94 +0,0 @@ - -*/ - -/** - * La classe Log permet de logger des erreurs - */ -class Minz_Log { - /** - * Les différents niveau de log - * ERROR erreurs bloquantes de l'application - * WARNING erreurs pouvant géner le bon fonctionnement, mais non bloquantes - * NOTICE erreurs mineures ou messages d'informations - * DEBUG Informations affichées pour le déboggage - */ - const ERROR = 2; - const WARNING = 4; - const NOTICE = 8; - const DEBUG = 16; - - /** - * Enregistre un message dans un fichier de log spécifique - * Message non loggué si - * - environment = SILENT - * - level = WARNING et environment = PRODUCTION - * - level = NOTICE et environment = PRODUCTION - * @param $information message d'erreur / information à enregistrer - * @param $level niveau d'erreur - * @param $file_name fichier de log, par défaut LOG_PATH/application.log - */ - public static function record ($information, $level, $file_name = null) { - $env = Configuration::environment (); - - if (! ($env === Configuration::SILENT - || ($env === Configuration::PRODUCTION - && ($level >= Minz_Log::NOTICE)))) { - if (is_null ($file_name)) { - $file_name = LOG_PATH . '/application.log'; - } - - switch ($level) { - case Minz_Log::ERROR : - $level_label = 'error'; - break; - case Minz_Log::WARNING : - $level_label = 'warning'; - break; - case Minz_Log::NOTICE : - $level_label = 'notice'; - break; - case Minz_Log::DEBUG : - $level_label = 'debug'; - break; - default : - $level_label = 'unknown'; - } - - if ($env == Configuration::PRODUCTION) { - $file = @fopen ($file_name, 'a'); - } else { - $file = fopen ($file_name, 'a'); - } - - if ($file !== false) { - $log = '[' . date('r') . ']'; - $log .= ' [' . $level_label . ']'; - $log .= ' --- ' . $information . "\n"; - fwrite ($file, $log); - fclose ($file); - } else { - throw new PermissionDeniedException ( - $file_name, - MinzException::ERROR - ); - } - } - } - - /** - * Automatise le log des variables globales $_GET et $_POST - * Fait appel à la fonction record(...) - * Ne fonctionne qu'en environnement "development" - * @param $file_name fichier de log, par défaut LOG_PATH/application.log - */ - public static function recordRequest($file_name = null) { - $msg_get = str_replace("\n", '', '$_GET content : ' . print_r($_GET, true)); - $msg_post = str_replace("\n", '', '$_POST content : ' . print_r($_POST, true)); - - self::record($msg_get, Minz_Log::DEBUG, $file_name); - self::record($msg_post, Minz_Log::DEBUG, $file_name); - } -} diff --git a/lib/minz/Model.php b/lib/minz/Model.php index 37fc19ed1..adbaba942 100755 --- a/lib/minz/Model.php +++ b/lib/minz/Model.php @@ -7,6 +7,6 @@ /** * La classe Model représente un modèle de l'application (représentation MVC) */ -class Model { +class Minz_Model { } diff --git a/lib/minz/Paginator.php b/lib/minz/Paginator.php index 1a8376e75..5858e76a5 100755 --- a/lib/minz/Paginator.php +++ b/lib/minz/Paginator.php @@ -7,7 +7,7 @@ /** * La classe Paginator permet de gérer la pagination de l'application facilement */ -class Paginator { +class Minz_Paginator { /** * $items tableau des éléments à afficher/gérer */ diff --git a/lib/minz/Request.php b/lib/minz/Request.php index 3e508d8f1..c8ffa4a42 100644 --- a/lib/minz/Request.php +++ b/lib/minz/Request.php @@ -7,7 +7,7 @@ /** * Request représente la requête http */ -class Request { +class Minz_Request { private static $controller_name = ''; private static $action_name = ''; private static $params = array (); @@ -96,7 +96,7 @@ class Request { * @return la base de l'url */ public static function getBaseUrl () { - return Configuration::baseUrl (); + return Minz_Configuration::baseUrl (); } /** @@ -124,10 +124,10 @@ class Request { * > sinon, le dispatcher recharge en interne */ public static function forward ($url = array (), $redirect = false) { - $url = Url::checkUrl ($url); + $url = Minz_Url::checkUrl ($url); if ($redirect) { - header ('Location: ' . Url::display ($url, 'php')); + header ('Location: ' . Minz_Url::display ($url, 'php')); exit (); } else { self::$reseted = true; @@ -185,9 +185,9 @@ class Request { */ private static function magicQuotesOff () { if (get_magic_quotes_gpc ()) { - $_GET = Helper::stripslashes_r ($_GET); - $_POST = Helper::stripslashes_r ($_POST); - $_COOKIE = Helper::stripslashes_r ($_COOKIE); + $_GET = Minz_Helper::stripslashes_r ($_GET); + $_POST = Minz_Helper::stripslashes_r ($_POST); + $_COOKIE = Minz_Helper::stripslashes_r ($_COOKIE); } } @@ -195,5 +195,3 @@ class Request { return !empty ($_POST) || !empty ($_FILES); } } - - diff --git a/lib/minz/Response.php b/lib/minz/Response.php index fcf53c5b1..f8ea3d946 100644 --- a/lib/minz/Response.php +++ b/lib/minz/Response.php @@ -7,7 +7,7 @@ /** * Response représente la requête http renvoyée à l'utilisateur */ -class Response { +class Minz_Response { private static $header = 'HTTP/1.0 200 OK'; private static $body = ''; diff --git a/lib/minz/Router.php b/lib/minz/Router.php index c5d6f5baa..1ccd72597 100755 --- a/lib/minz/Router.php +++ b/lib/minz/Router.php @@ -8,7 +8,7 @@ * La classe Router gère le routage de l'application * Les routes sont définies dans APP_PATH.'/configuration/routes.php' */ -class Router { +class Minz_Router { const ROUTES_PATH_NAME = '/configuration/routes.php'; private $routes = array (); @@ -19,7 +19,7 @@ class Router { * et que l'on utilise l'url rewriting */ public function __construct () { - if (Configuration::useUrlRewriting ()) { + if (Minz_Configuration::useUrlRewriting ()) { if (file_exists (APP_PATH . self::ROUTES_PATH_NAME)) { $routes = include ( APP_PATH . self::ROUTES_PATH_NAME @@ -34,9 +34,9 @@ class Router { $routes ); } else { - throw new FileNotExistException ( + throw new Minz_FileNotExistException ( self::ROUTES_PATH_NAME, - MinzException::ERROR + Minz_Exception::ERROR ); } } @@ -51,10 +51,10 @@ class Router { public function init () { $url = array (); - if (Configuration::useUrlRewriting ()) { + if (Minz_Configuration::useUrlRewriting ()) { try { $url = $this->buildWithRewriting (); - } catch (RouteNotFoundException $e) { + } catch (Minz_RouteNotFoundException $e) { throw $e; } } else { @@ -63,10 +63,10 @@ class Router { $url['params'] = array_merge ( $url['params'], - Request::fetchPOST () + Minz_Request::fetchPOST () ); - Request::forward ($url); + Minz_Request::forward ($url); } /** @@ -77,15 +77,15 @@ class Router { public function buildWithoutRewriting () { $url = array (); - $url['c'] = Request::fetchGET ( + $url['c'] = Minz_Request::fetchGET ( 'c', - Request::defaultControllerName () + Minz_Request::defaultControllerName () ); - $url['a'] = Request::fetchGET ( + $url['a'] = Minz_Request::fetchGET ( 'a', - Request::defaultActionName () + Minz_Request::defaultActionName () ); - $url['params'] = Request::fetchGET (); + $url['params'] = Minz_Request::fetchGET (); // post-traitement unset ($url['params']['c']); @@ -103,7 +103,7 @@ class Router { */ public function buildWithRewriting () { $url = array (); - $uri = Request::getURI (); + $uri = Minz_Request::getURI (); $find = false; foreach ($this->routes as $route) { @@ -121,14 +121,14 @@ class Router { } if (!$find && $uri != '/') { - throw new RouteNotFoundException ( + throw new Minz_RouteNotFoundException ( $uri, - MinzException::ERROR + Minz_Exception::ERROR ); } // post-traitement - $url = Url::checkUrl ($url); + $url = Minz_Url::checkUrl ($url); return $url; } diff --git a/lib/minz/Session.php b/lib/minz/Session.php index f9c9c6754..878caa556 100755 --- a/lib/minz/Session.php +++ b/lib/minz/Session.php @@ -4,7 +4,7 @@ * La classe Session gère la session utilisateur * C'est un singleton */ -class Session { +class Minz_Session { /** * $session stocke les variables de session */ @@ -15,7 +15,7 @@ class Session { */ public static function init () { // démarre la session - session_name (md5 (Configuration::selApplication ())); + session_name (md5 (Minz_Configuration::selApplication ())); session_start (); if (isset ($_SESSION)) { @@ -55,7 +55,7 @@ class Session { if($p == 'language') { // reset pour remettre à jour le fichier de langue à utiliser - Translate::reset (); + Minz_Translate::reset (); } } } diff --git a/lib/minz/Translate.php b/lib/minz/Translate.php index e8cbe4852..e14f783f7 100644 --- a/lib/minz/Translate.php +++ b/lib/minz/Translate.php @@ -8,7 +8,7 @@ * La classe Translate se charge de la traduction * Utilise les fichiers du répertoire /app/i18n/ */ -class Translate { +class Minz_Translate { /** * $language est la langue à afficher */ @@ -25,8 +25,8 @@ class Translate { * l'enregistre dans $translates */ public static function init () { - $l = Configuration::language (); - self::$language = Session::param ('language', $l); + $l = Minz_Configuration::language (); + self::$language = Minz_Session::param ('language', $l); $l_path = APP_PATH . '/i18n/' . self::$language . '.php'; diff --git a/lib/minz/Url.php b/lib/minz/Url.php index ce051ebd9..30f7f6231 100755 --- a/lib/minz/Url.php +++ b/lib/minz/Url.php @@ -3,7 +3,7 @@ /** * La classe Url permet de gérer les URL à travers MINZ */ -class Url { +class Minz_Url { /** * Affiche une Url formatée selon que l'on utilise l'url_rewriting ou non * si oui, on cherche dans la table de routage la correspondance pour formater @@ -29,16 +29,16 @@ class Url { } else { $protocol = 'http:'; } - $url_string = $protocol . '//' . Request::getDomainName () . Request::getBaseUrl (); + $url_string = $protocol . '//' . Minz_Request::getDomainName () . Minz_Request::getBaseUrl (); } else { $url_string = '.'; } if (is_array ($url)) { - $router = new Router (); + $router = new Minz_Router (); - if (Configuration::useUrlRewriting ()) { + if (Minz_Configuration::useUrlRewriting ()) { $url_string .= $router->printUriRewrited ($url); } else { $url_string .= self::printUri ($url, $encodage); @@ -67,13 +67,13 @@ class Url { } if (isset ($url['c']) - && $url['c'] != Request::defaultControllerName ()) { + && $url['c'] != Minz_Request::defaultControllerName ()) { $uri .= $separator . 'c=' . $url['c']; $separator = $and; } if (isset ($url['a']) - && $url['a'] != Request::defaultActionName ()) { + && $url['a'] != Minz_Request::defaultActionName ()) { $uri .= $separator . 'a=' . $url['a']; $separator = $and; } @@ -98,10 +98,10 @@ class Url { if (is_array ($url)) { if (!isset ($url['c'])) { - $url_checked['c'] = Request::defaultControllerName (); + $url_checked['c'] = Minz_Request::defaultControllerName (); } if (!isset ($url['a'])) { - $url_checked['a'] = Request::defaultActionName (); + $url_checked['a'] = Minz_Request::defaultActionName (); } if (!isset ($url['params'])) { $url_checked['params'] = array (); @@ -125,5 +125,5 @@ function _url ($controller, $action) { $params[$args[$i]] = $args[$i + 1]; } - return Url::display (array ('c' => $controller, 'a' => $action, 'params' => $params)); + return Minz_Url::display (array ('c' => $controller, 'a' => $action, 'params' => $params)); } diff --git a/lib/minz/View.php b/lib/minz/View.php index 12202542f..c8d0aefed 100755 --- a/lib/minz/View.php +++ b/lib/minz/View.php @@ -7,7 +7,7 @@ /** * La classe View représente la vue de l'application */ -class View { +class Minz_View { const VIEWS_PATH_NAME = '/views'; const LAYOUT_PATH_NAME = '/layout'; const LAYOUT_FILENAME = '/layout.phtml'; @@ -28,8 +28,8 @@ class View { public function __construct () { $this->view_filename = APP_PATH . self::VIEWS_PATH_NAME . '/' - . Request::controllerName () . '/' - . Request::actionName () . '.phtml'; + . Minz_Request::controllerName () . '/' + . Minz_Request::actionName () . '.phtml'; if (file_exists (APP_PATH . self::LAYOUT_PATH_NAME @@ -37,7 +37,7 @@ class View { $this->use_layout = true; } - self::$title = Configuration::title (); + self::$title = Minz_Configuration::title (); } /** @@ -232,7 +232,7 @@ class View { self::$params[$key] = $value; } public function attributeParams () { - foreach (View::$params as $key => $value) { + foreach (Minz_View::$params as $key => $value) { $this->$key = $value; } } diff --git a/lib/minz/dao/Model_array.php b/lib/minz/dao/Model_array.php deleted file mode 100755 index 0b9ccf071..000000000 --- a/lib/minz/dao/Model_array.php +++ /dev/null @@ -1,122 +0,0 @@ - -*/ - -/** - * La classe Model_array représente le modèle interragissant avec les fichiers de type texte gérant des tableaux php - */ -class Model_array extends Model_txt { - /** - * $array Le tableau php contenu dans le fichier $nameFile - */ - protected $array = array (); - - /** - * Ouvre le fichier indiqué, charge le tableau dans $array et le $nameFile - * @param $nameFile le nom du fichier à ouvrir contenant un tableau - * Remarque : $array sera obligatoirement un tableau - */ - public function __construct ($nameFile) { - parent::__construct ($nameFile); - - if (!$this->getLock ('read')) { - throw new PermissionDeniedException ($this->filename); - } else { - $this->array = include ($this->filename); - $this->releaseLock (); - - if (!is_array ($this->array)) { - $this->array = array (); - } - - $this->array = $this->decodeArray ($this->array); - } - } - - /** - * Écrit un tableau dans le fichier $nameFile - * @param $array le tableau php à enregistrer - **/ - public function writeFile ($array) { - if (!$this->getLock ('write')) { - throw new PermissionDeniedException ($this->namefile); - } else { - $this->erase (); - - $this->writeLine ('writeLine ('return ', false); - $this->writeArray ($array); - $this->writeLine (';'); - - $this->releaseLock (); - } - } - - private function writeArray ($array, $profondeur = 0) { - $tab = ''; - for ($i = 0; $i < $profondeur; $i++) { - $tab .= "\t"; - } - $this->writeLine ('array ('); - - foreach ($array as $key => $value) { - if (is_int ($key)) { - $this->writeLine ($tab . "\t" . $key . ' => ', false); - } else { - $this->writeLine ($tab . "\t" . '\'' . $key . '\'' . ' => ', false); - } - - if (is_array ($value)) { - $this->writeArray ($value, $profondeur + 1); - $this->writeLine (','); - } else { - if (is_numeric ($value)) { - $this->writeLine ($value . ','); - } else { - $this->writeLine ('\'' . addslashes ($value) . '\','); - } - } - } - - $this->writeLine ($tab . ')', false); - } - - private function decodeArray ($array) { - $new_array = array (); - - foreach ($array as $key => $value) { - if (is_array ($value)) { - $new_array[$key] = $this->decodeArray ($value); - } else { - $new_array[$key] = stripslashes ($value); - } - } - - return $new_array; - } - - private function getLock ($type) { - if ($type == 'write') { - $lock = LOCK_EX; - } else { - $lock = LOCK_SH; - } - - $count = 1; - while (!flock ($this->file, $lock) && $count <= 50) { - $count++; - } - - if ($count >= 50) { - return false; - } else { - return true; - } - } - - private function releaseLock () { - flock ($this->file, LOCK_UN); - } -} diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php deleted file mode 100755 index a93291fc8..000000000 --- a/lib/minz/dao/Model_pdo.php +++ /dev/null @@ -1,111 +0,0 @@ - -*/ - -/** - * La classe Model_sql représente le modèle interragissant avec les bases de données - * Seul la connexion MySQL est prise en charge pour le moment - */ -class Model_pdo { - - /** - * Partage la connexion à la base de données entre toutes les instances. - */ - public static $useSharedBd = true; - private static $sharedBd = null; - private static $sharedPrefix; - - /** - * $bd variable représentant la base de données - */ - protected $bd; - - protected $prefix; - - /** - * Créé la connexion à la base de données à l'aide des variables - * HOST, BASE, USER et PASS définies dans le fichier de configuration - */ - public function __construct () { - if (self::$useSharedBd && self::$sharedBd != null) { - $this->bd = self::$sharedBd; - $this->prefix = self::$sharedPrefix; - return; - } - - $db = Configuration::dataBase (); - $driver_options = null; - - try { - $type = $db['type']; - if($type == 'mysql') { - $string = $type - . ':host=' . $db['host'] - . ';dbname=' . $db['base'] - . ';charset=utf8'; - $driver_options = array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' - ); - } 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 - } - - $this->bd = new FreshPDO ( - $string, - $db['user'], - $db['password'], - $driver_options - ); - self::$sharedBd = $this->bd; - - $userPrefix = Configuration::currentUser (); - $this->prefix = $db['prefix'] . (empty($userPrefix) ? '' : ($userPrefix . '_')); - self::$sharedPrefix = $this->prefix; - } catch (Exception $e) { - throw new PDOConnectionException ( - $string, - $db['user'], MinzException::ERROR - ); - } - } - - public function beginTransaction() { - $this->bd->beginTransaction(); - } - public function commit() { - $this->bd->commit(); - } - public function rollBack() { - $this->bd->rollBack(); - } - - public function size() { - $db = Configuration::dataBase (); - $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = ?'; - $stm = $this->bd->prepare ($sql); - $values = array ($db['base']); - $stm->execute ($values); - $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); - return $res[0]; - } -} - -class FreshPDO extends PDO { - private static function check($statement) { - if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { - invalidateHttpCache(); - } - } - - public function prepare ($statement, $driver_options = array()) { - FreshPDO::check($statement); - return parent::prepare($statement, $driver_options); - } - - public function exec ($statement) { - FreshPDO::check($statement); - return parent::exec($statement); - } -} diff --git a/lib/minz/dao/Model_txt.php b/lib/minz/dao/Model_txt.php deleted file mode 100755 index aed653068..000000000 --- a/lib/minz/dao/Model_txt.php +++ /dev/null @@ -1,84 +0,0 @@ - -*/ - -/** - * La classe Model_txt représente le modèle interragissant avec les fichiers de type texte - */ -class Model_txt { - /** - * $file représente le fichier à ouvrir - */ - protected $file; - - /** - * $filename est le nom du fichier - */ - protected $filename; - - /** - * Ouvre un fichier dans $file - * @param $nameFile nom du fichier à ouvrir - * @param $mode mode d'ouverture du fichier ('a+' par défaut) - * @exception FileNotExistException si le fichier n'existe pas - * > ou ne peux pas être ouvert - */ - public function __construct ($nameFile, $mode = 'a+') { - $this->filename = $nameFile; - if (!file_exists($this->filename)) { - throw new FileNotExistException ( - $this->filename, - MinzException::WARNING - ); - } - - $this->file = @fopen ($this->filename, $mode); - - if (!$this->file) { - throw new PermissionDeniedException ( - $this->filename, - MinzException::WARNING - ); - } - } - - /** - * Lit une ligne de $file - * @return une ligne du fichier - */ - public function readLine () { - return fgets ($this->file); - } - - /** - * Écrit une ligne dans $file - * @param $line la ligne à écrire - */ - public function writeLine ($line, $newLine = true) { - $char = ''; - if ($newLine) { - $char = "\n"; - } - - fwrite ($this->file, $line . $char); - } - - /** - * Efface le fichier $file - * @return true en cas de succès, false sinon - */ - public function erase () { - return ftruncate ($this->file, 0); - } - - /** - * Ferme $file - */ - public function __destruct () { - if (isset ($this->file)) { - fclose ($this->file); - } - } -} diff --git a/lib/minz/exceptions/MinzException.php b/lib/minz/exceptions/MinzException.php deleted file mode 100644 index 4568c4da8..000000000 --- a/lib/minz/exceptions/MinzException.php +++ /dev/null @@ -1,94 +0,0 @@ -route = $route; - - $message = 'Route `' . $route . '` not found'; - - parent::__construct ($message, $code); - } - - public function route () { - return $this->route; - } -} -class PDOConnectionException extends MinzException { - public function __construct ($string_connection, $user, $code = self::ERROR) { - $message = 'Access to database is denied for `' . $user . '`' - . ' (`' . $string_connection . '`)'; - - parent::__construct ($message, $code); - } -} -class CurrentPagePaginationException extends MinzException { - public function __construct ($page) { - $message = 'Page number `' . $page . '` doesn\'t exist'; - - parent::__construct ($message, self::ERROR); - } -} diff --git a/public/index.php b/public/index.php index 3a2bcd3ae..829e418f9 100755 --- a/public/index.php +++ b/public/index.php @@ -37,18 +37,10 @@ if (file_exists ('install.php')) { } } - set_include_path (get_include_path () - . PATH_SEPARATOR - . LIB_PATH - . PATH_SEPARATOR - . LIB_PATH . '/minz' - . PATH_SEPARATOR - . APP_PATH); - - require (APP_PATH . '/App_FrontController.php'); + require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader try { - $front_controller = new App_FrontController (); + $front_controller = new FreshRSS(); $front_controller->init (); $front_controller->run (); } catch (Exception $e) { -- cgit v1.2.3