affichage par catégories + meilleur exportation opml

This commit is contained in:
Marien Fressinaud
2012-10-23 18:29:43 +02:00
parent 9a95cb844e
commit fca236dc6d
11 changed files with 151 additions and 68 deletions

View File

@@ -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 ()));
}
}

View File

@@ -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'));
}

View File

@@ -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 () {

View File

@@ -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>

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
});

View File

@@ -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;
}

View File

@@ -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;