aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-23 18:29:43 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-23 18:29:43 +0200
commitfca236dc6d6ff6e09182c560f3566904cbc7a70a (patch)
tree850bfab52359702dad2a9eccd03f01b5c68c9bcb
parent9a95cb844e80512205c519da69ec373e046b7f52 (diff)
affichage par catégories + meilleur exportation opml
-rw-r--r--app/App_FrontController.php23
-rwxr-xr-xapp/controllers/configureController.php13
-rwxr-xr-xapp/controllers/indexController.php23
-rw-r--r--app/layout/aside.phtml8
-rwxr-xr-xapp/models/Entry.php56
-rw-r--r--app/models/Feed.php12
-rw-r--r--app/views/configure/importExport.phtml4
-rw-r--r--app/views/index/index.phtml4
-rw-r--r--app/views/javascript/main.phtml17
-rw-r--r--lib/lib_rss.php21
-rw-r--r--public/theme/base.css38
11 files changed, 151 insertions, 68 deletions
diff --git a/app/App_FrontController.php b/app/App_FrontController.php
index 5a1009436..d61927c9e 100644
--- a/app/App_FrontController.php
+++ b/app/App_FrontController.php
@@ -10,14 +10,9 @@ class App_FrontController extends FrontController {
$this->loadLibs ();
$this->loadModels ();
- Session::init ();
-
- View::prependStyle (Url::display ('/theme/base.css'));
- View::appendScript (Url::display ('/scripts/jquery.js'));
- View::appendScript (Url::display ('/scripts/smoothscroll.js'));
- View::appendScript (Url::display ('/scripts/shortcut.js'));
- View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
- View::_param ('conf', Session::param ('conf', new RSSConfiguration ()));
+ Session::init (); // lancement de la session doit se faire après chargement des modèles sinon bug (pourquoi ?)
+ $this->loadStylesAndScripts ();
+ $this->loadParamsView ();
}
private function loadLibs () {
@@ -31,4 +26,16 @@ class App_FrontController extends FrontController {
include (APP_PATH . '/models/Feed.php');
include (APP_PATH . '/models/Entry.php');
}
+
+ private function loadStylesAndScripts () {
+ View::prependStyle (Url::display ('/theme/base.css'));
+ View::appendScript (Url::display ('/scripts/jquery.js'));
+ View::appendScript (Url::display ('/scripts/smoothscroll.js'));
+ View::appendScript (Url::display ('/scripts/shortcut.js'));
+ View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
+ }
+
+ private function loadParamsView () {
+ View::_param ('conf', Session::param ('conf', new RSSConfiguration ()));
+ }
}
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
index c501e5242..e61eb3872 100755
--- a/app/controllers/configureController.php
+++ b/app/controllers/configureController.php
@@ -99,12 +99,21 @@ class configureController extends ActionController {
header('Content-type: text/xml');
$feedDAO = new FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
- } elseif (Request::isPost ()) {
+ $catDAO = new CategoryDAO ();
+
+ $list = array ();
+ foreach ($catDAO->listCategories () as $key => $cat) {
+ $list[$key]['name'] = $cat->name ();
+ $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
+ }
+
+ $this->view->categories = $list;
+ } elseif ($this->view->req == 'import' && Request::isPost ()) {
if ($_FILES['file']['error'] == 0) {
$content = file_get_contents ($_FILES['file']['tmp_name']);
$feeds = opml_import ($content);
+ Request::_param ('q');
Request::_param ('feeds', $feeds);
Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
}
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php
index b9d770e81..b8908dee3 100755
--- a/app/controllers/indexController.php
+++ b/app/controllers/indexController.php
@@ -3,25 +3,38 @@
class indexController extends ActionController {
public function indexAction () {
$entryDAO = new EntryDAO ();
+ $catDAO = new CategoryDAO ();
$mode = Session::param ('mode', $this->view->conf->defaultView ());
- if ($mode == 'not_read') {
- $entries = $entryDAO->listNotReadEntries ();
- } elseif ($mode == 'all') {
- $entries = $entryDAO->listEntries ();
+ $get = Request::param ('get');
+
+ // Récupère les flux par catégorie, favoris ou tous
+ if ($get == 'favoris') {
+ $entries = $entryDAO->listFavorites ($mode);
+ } elseif ($get != false) {
+ $entries = $entryDAO->listByCategory ($get, $mode);
}
+ // Cas où on ne choisie ni catégorie ni les favoris
+ // ou si la catégorie ne correspond à aucune
+ if (!isset ($entries)) {
+ $entries = $entryDAO->listEntries ($mode);
+ }
+
+ // Tri par date
if ($this->view->conf->sortOrder () == 'high_to_low') {
usort ($entries, 'sortReverseEntriesByDate');
} else {
usort ($entries, 'sortEntriesByDate');
}
- //gestion pagination
+ // Gestion pagination
$page = Request::param ('page', 1);
$this->view->entryPaginator = new Paginator ($entries);
$this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
$this->view->entryPaginator->_currentPage ($page);
+
+ $this->view->cat_aside = $catDAO->listCategories ();
}
public function changeModeAction () {
diff --git a/app/layout/aside.phtml b/app/layout/aside.phtml
index b154c5ea3..265a0902b 100644
--- a/app/layout/aside.phtml
+++ b/app/layout/aside.phtml
@@ -7,6 +7,14 @@
<ul id="menu">
<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
<a href="<?php echo Url::display (array ()); ?>">Flux RSS</a>
+ <?php if (isset ($this->cat_aside)) { ?>
+ <ul id="flux_menu">
+ <li><a href="<?php echo Url::display (array ('params' => array ('get' => 'favoris'))); ?>">Favoris</a></li>
+ <?php foreach ($this->cat_aside as $cat) { ?>
+ <li><a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>"><?php echo $cat->name (); ?></a></li>
+ <?php } ?>
+ </ul>
+ <?php } ?>
</li>
<li <?php echo Request::controllerName () == 'configure' ? 'class="active"' : ''; ?>>
<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Configurer</a>
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 67d255c55..dbbdc1362 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -133,31 +133,44 @@ class EntryDAO extends Model_array {
}
}
- public function listEntries () {
+ public function listEntries ($mode) {
$list = $this->array;
if (!is_array ($list)) {
$list = array ();
}
- return HelperEntry::daoToEntry ($list);
+ return HelperEntry::daoToEntry ($list, $mode);
}
- public function listNotReadEntries () {
+ public function listFavorites ($mode) {
$list = $this->array;
- $list_not_read = array ();
if (!is_array ($list)) {
$list = array ();
}
- foreach ($list as $key => $entry) {
- if (!$entry['is_read']) {
- $list_not_read[$key] = $entry;
+ return HelperEntry::daoToEntry ($list, $mode, true);
+ }
+
+ public function listByCategory ($cat, $mode) {
+ $feedDAO = new FeedDAO ();
+ $feeds = $feedDAO->listByCategory ($cat);
+
+ $list = array ();
+ foreach ($feeds as $feed) {
+ foreach ($feed->entries () as $id) {
+ if (isset ($this->array[$id])) {
+ $list[$id] = $this->array[$id];
+ }
}
}
- return HelperEntry::daoToEntry ($list_not_read);
+ return HelperEntry::daoToEntry ($list, $mode);
+ }
+
+ public function listNotReadEntries () {
+
}
public function count () {
@@ -166,7 +179,7 @@ class EntryDAO extends Model_array {
}
class HelperEntry {
- public static function daoToEntry ($listDAO) {
+ public static function daoToEntry ($listDAO, $mode = 'all', $favorite = false) {
$list = array ();
if (!is_array ($listDAO)) {
@@ -174,17 +187,20 @@ class HelperEntry {
}
foreach ($listDAO as $key => $dao) {
- $list[$key] = new Entry (
- $dao['feed'],
- $dao['guid'],
- $dao['title'],
- $dao['author'],
- $dao['content'],
- $dao['link'],
- $dao['date'],
- $dao['is_read'],
- $dao['is_favorite']
- );
+ if (($mode != 'not_read' || !$dao['is_read'])
+ && ($favorite == false || $dao['is_favorite'])) {
+ $list[$key] = new Entry (
+ $dao['feed'],
+ $dao['guid'],
+ $dao['title'],
+ $dao['author'],
+ $dao['content'],
+ $dao['link'],
+ $dao['date'],
+ $dao['is_read'],
+ $dao['is_favorite']
+ );
+ }
}
return $list;
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 57696f64d..90656de15 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -159,6 +159,18 @@ class FeedDAO extends Model_array {
return HelperFeed::daoToFeed ($list);
}
+ public function listByCategory ($cat) {
+ $list = array ();
+
+ foreach ($this->array as $key => $feed) {
+ if ($feed['category'] == $cat) {
+ $list[$key] = $feed;
+ }
+ }
+
+ return HelperFeed::daoToFeed ($list);
+ }
+
public function count () {
return count ($this->array);
}
diff --git a/app/views/configure/importExport.phtml b/app/views/configure/importExport.phtml
index 634800157..7f2fbd7c5 100644
--- a/app/views/configure/importExport.phtml
+++ b/app/views/configure/importExport.phtml
@@ -7,12 +7,12 @@
<dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
</head>
<body>
-<?php echo opml_export ($this->feeds); ?>
+<?php echo opml_export ($this->categories); ?>
</body>
</opml>
<?php } else { ?>
-<form method="post" action="" enctype="multipart/form-data">
+<form method="post" action="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'import'))); ?>" enctype="multipart/form-data">
<h1>Exporter au format OPML</h1>
<a class="button" href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'export'))); ?>">Exporter</a>
diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml
index af01f3fd2..c3f4242c4 100644
--- a/app/views/index/index.phtml
+++ b/app/views/index/index.phtml
@@ -16,10 +16,10 @@
<div class="post flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>">
<?php $author = $item->author (); ?>
<div class="before">
+ <?php $feed = $item->feed (true); ?>
<?php echo $author != '' ? $author . ' a écrit' : ''; ?>
le <?php echo $item->date (); ?>
- <?php $feed = $item->feed (true); ?>
- sur <a target="_blank" href="<?php echo $feed->website (); ?>"><?php echo $feed->name (); ?></a>,
+ sur <a target="_blank" href="<?php echo $feed->website (); ?>"><?php echo $feed->name (); ?> <img src="http://www.google.com/s2/favicons?domain=<?php echo get_domain ($feed->website ()); ?>" alt="" /></a>,
</div>
<h1><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1>
diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml
index 87b53ca9a..f5682d1f0 100644
--- a/app/views/javascript/main.phtml
+++ b/app/views/javascript/main.phtml
@@ -68,18 +68,9 @@ $(document).ready (function () {
}
});
});
- shortcut.add("space", function () {
- // On plie / déplie l'article
- active = $(".post.flux.active");
- active.children (".content").slideToggle (200, function () {
- $.smoothScroll({
- offset: active.position ().top + 25
- });
- });
- });
// Touches de navigation
- shortcut.add("up", function () {
+ /*shortcut.add("up", function () {
old_active = $(".post.flux.active");
last_active = $(".post.flux:last");
new_active = old_active.prev ();
@@ -89,15 +80,15 @@ $(document).ready (function () {
} else {
slide (last_active, old_active);
}
- });
- shortcut.add("down", function () {
+ });*/
+ shortcut.add("space", function () {
old_active = $(".post.flux.active");
first_active = $(".post.flux:first");
new_active = old_active.next ();
if (new_active[0] instanceof HTMLDivElement) {
slide (new_active, old_active);
- } else {
+ } else if (new_active[0] === undefined) {
slide (first_active, old_active);
}
});
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index c695b64b7..74a86558c 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -69,16 +69,23 @@ function sortReverseEntriesByDate ($entry1, $entry2) {
return $entry1->date (true) - $entry2->date (true);
}
-function opml_export ($feeds) {
- // TODO gérer les catégories
- $txt = '<outline text="default">' . "\n";
+function get_domain ($url) {
+ return parse_url($url, PHP_URL_HOST);
+}
+
+function opml_export ($cats) {
+ $txt = '';
- foreach ($feeds as $feed) {
- $txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" />' . "\n";
+ foreach ($cats as $cat) {
+ $txt .= '<outline text="' . $cat['name'] . '">' . "\n";
+
+ foreach ($cat['feeds'] as $feed) {
+ $txt .= "\t" . '<outline text="' . $feed->name () . '" type="rss" xmlUrl="' . $feed->url () . '" htmlUrl="' . $feed->website () . '" />' . "\n";
+ }
+
+ $txt .= '</outline>' . "\n";
}
- $txt .= '</outline>' . "\n";
-
return $txt;
}
diff --git a/public/theme/base.css b/public/theme/base.css
index e6a427c76..e4bb55081 100644
--- a/public/theme/base.css
+++ b/public/theme/base.css
@@ -40,9 +40,9 @@ ul, ol {
/* TITRES */
h1, h2, h3 {
- min-height: 50px;
- padding: 10px 0 20px;
- line-height: 50px;
+ min-height: 40px;
+ padding: 10px 0 0;
+ line-height: 40px;
}
/* IMG */
@@ -132,10 +132,6 @@ form {
overflow: hidden;
line-height: 50px;
}
- .aside li.active a {
- background: #0062BE !important;
- color: #fff;
- }
.aside li a, .aside li span {
display: block;
width: 230px;
@@ -148,6 +144,10 @@ form {
.aside li.disable span {
background: #fff;
}
+ .aside li.active a {
+ background: #0062BE;
+ color: #fff;
+ }
.aside li h2 {
height: 50px;
padding: 0;
@@ -186,6 +186,23 @@ form {
border: none;
border-radius: 0;
}
+ .aside #flux_menu {
+ display: none;
+ position: absolute;
+ top: 48px; left: 250px;
+ border-top: 2px solid #0062BE;
+ border-bottom: 2px solid #0062BE;
+ }
+ .aside li:hover #flux_menu {
+ display: block;
+ }
+ .aside #flux_menu a {
+ background: #fff;
+ color: #0062BE;
+ }
+ .aside #flux_menu a:hover {
+ background: #fafafa;
+ }
#main {
display: table-cell;
height: 100%;
@@ -233,7 +250,6 @@ form {
}
.post.flux {
margin: 40px auto;
- padding: 25px 20px;
font-family: Palatino, "Times New Roman", serif;
line-height: 170%;
border-left: 5px solid #aaa;
@@ -246,6 +262,7 @@ form {
transition: border-color .10s ease-out;
}
.post.flux .before {
+ padding: 20px;
color: #666;
font-size: 80%;
text-align: center;
@@ -268,8 +285,11 @@ form {
border-radius: 0 0 5px 5px;
box-shadow: 0 1px 3px #aaa;
}
+ .post.flux > h1 {
+ padding: 10px 20px;
+ }
.post.flux .content {
- /*display: none;*/
+ padding: 10px 20px;
}
.post.flux .content img {
border-radius: 5px;