Просмотр исходного кода

affichage par catégories + meilleur exportation opml

Marien Fressinaud 13 лет назад
Родитель
Сommit
fca236dc6d

+ 15 - 8
app/App_FrontController.php

@@ -10,14 +10,9 @@ class App_FrontController extends FrontController {
 		$this->loadLibs ();
 		$this->loadLibs ();
 		$this->loadModels ();
 		$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 () {
 	private function loadLibs () {
@@ -31,4 +26,16 @@ class App_FrontController extends FrontController {
 		include (APP_PATH . '/models/Feed.php');
 		include (APP_PATH . '/models/Feed.php');
 		include (APP_PATH . '/models/Entry.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 ()));
+	}
 }
 }

+ 11 - 2
app/controllers/configureController.php

@@ -99,12 +99,21 @@ class configureController extends ActionController {
 			header('Content-type: text/xml');
 			header('Content-type: text/xml');
 			
 			
 			$feedDAO = new FeedDAO ();
 			$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) {
 			if ($_FILES['file']['error'] == 0) {
 				$content = file_get_contents ($_FILES['file']['tmp_name']);
 				$content = file_get_contents ($_FILES['file']['tmp_name']);
 				$feeds = opml_import ($content);
 				$feeds = opml_import ($content);
 				
 				
+				Request::_param ('q');
 				Request::_param ('feeds', $feeds);
 				Request::_param ('feeds', $feeds);
 				Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
 				Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
 			}
 			}

+ 18 - 5
app/controllers/indexController.php

@@ -3,25 +3,38 @@
 class indexController extends ActionController {
 class indexController extends ActionController {
 	public function indexAction () {
 	public function indexAction () {
 		$entryDAO = new EntryDAO ();
 		$entryDAO = new EntryDAO ();
+		$catDAO = new CategoryDAO ();
 		
 		
 		$mode = Session::param ('mode', $this->view->conf->defaultView ());
 		$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') {
 		if ($this->view->conf->sortOrder () == 'high_to_low') {
 			usort ($entries, 'sortReverseEntriesByDate');
 			usort ($entries, 'sortReverseEntriesByDate');
 		} else {
 		} else {
 			usort ($entries, 'sortEntriesByDate');
 			usort ($entries, 'sortEntriesByDate');
 		}
 		}
 		
 		
-		//gestion pagination
+		// Gestion pagination
 		$page = Request::param ('page', 1);
 		$page = Request::param ('page', 1);
 		$this->view->entryPaginator = new Paginator ($entries);
 		$this->view->entryPaginator = new Paginator ($entries);
 		$this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
 		$this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
 		$this->view->entryPaginator->_currentPage ($page);
 		$this->view->entryPaginator->_currentPage ($page);
+		
+		$this->view->cat_aside = $catDAO->listCategories ();
 	}
 	}
 	
 	
 	public function changeModeAction () {
 	public function changeModeAction () {

+ 8 - 0
app/layout/aside.phtml

@@ -7,6 +7,14 @@
 	<ul id="menu">
 	<ul id="menu">
 		<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
 		<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
 			<a href="<?php echo Url::display (array ()); ?>">Flux RSS</a>
 			<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>
 		<li <?php echo Request::controllerName () == 'configure' ? 'class="active"' : ''; ?>>
 		<li <?php echo Request::controllerName () == 'configure' ? 'class="active"' : ''; ?>>
 			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Configurer</a>
 			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'flux')); ?>">Configurer</a>

+ 36 - 20
app/models/Entry.php

@@ -133,31 +133,44 @@ class EntryDAO extends Model_array {
 		}
 		}
 	}
 	}
 	
 	
-	public function listEntries () {
+	public function listEntries ($mode) {
 		$list = $this->array;
 		$list = $this->array;
 		
 		
 		if (!is_array ($list)) {
 		if (!is_array ($list)) {
 			$list = array ();
 			$list = array ();
 		}
 		}
 		
 		
-		return HelperEntry::daoToEntry ($list);
+		return HelperEntry::daoToEntry ($list, $mode);
 	}
 	}
 	
 	
-	public function listNotReadEntries () {
+	public function listFavorites ($mode) {
 		$list = $this->array;
 		$list = $this->array;
-		$list_not_read = array ();
 		
 		
 		if (!is_array ($list)) {
 		if (!is_array ($list)) {
 			$list = array ();
 			$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 () {
 	public function count () {
@@ -166,7 +179,7 @@ class EntryDAO extends Model_array {
 }
 }
 
 
 class HelperEntry {
 class HelperEntry {
-	public static function daoToEntry ($listDAO) {
+	public static function daoToEntry ($listDAO, $mode = 'all', $favorite = false) {
 		$list = array ();
 		$list = array ();
 
 
 		if (!is_array ($listDAO)) {
 		if (!is_array ($listDAO)) {
@@ -174,17 +187,20 @@ class HelperEntry {
 		}
 		}
 
 
 		foreach ($listDAO as $key => $dao) {
 		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;
 		return $list;

+ 12 - 0
app/models/Feed.php

@@ -159,6 +159,18 @@ class FeedDAO extends Model_array {
 		return HelperFeed::daoToFeed ($list);
 		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 () {
 	public function count () {
 		return count ($this->array);
 		return count ($this->array);
 	}
 	}

+ 2 - 2
app/views/configure/importExport.phtml

@@ -7,12 +7,12 @@
 		<dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
 		<dateCreated><?php echo date('D, d M Y H:i:s'); ?></dateCreated>
 	</head>
 	</head>
 	<body>
 	<body>
-<?php echo opml_export ($this->feeds); ?>
+<?php echo opml_export ($this->categories); ?>
 	</body>
 	</body>
 </opml>
 </opml>
 <?php } else { ?>
 <?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>
 	<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>
 	<a class="button" href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport', 'params' => array ('q' => 'export'))); ?>">Exporter</a>
 	
 	

+ 2 - 2
app/views/index/index.phtml

@@ -16,10 +16,10 @@
 	<div class="post flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>">
 	<div class="post flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>">
 		<?php $author = $item->author (); ?>
 		<?php $author = $item->author (); ?>
 		<div class="before">
 		<div class="before">
+			<?php $feed = $item->feed (true); ?>
 			<?php echo $author != '' ? $author . ' a écrit' : ''; ?>
 			<?php echo $author != '' ? $author . ' a écrit' : ''; ?>
 			le <?php echo $item->date (); ?>
 			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>
 		</div>
 		
 		
 		<h1><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1>
 		<h1><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1>

+ 4 - 13
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
 	// Touches de navigation
-	shortcut.add("up", function () {
+	/*shortcut.add("up", function () {
 		old_active = $(".post.flux.active");
 		old_active = $(".post.flux.active");
 		last_active = $(".post.flux:last");
 		last_active = $(".post.flux:last");
 		new_active = old_active.prev ();
 		new_active = old_active.prev ();
@@ -89,15 +80,15 @@ $(document).ready (function () {
 		} else {
 		} else {
 			slide (last_active, old_active);
 			slide (last_active, old_active);
 		}
 		}
-	});
-	shortcut.add("down", function () {
+	});*/
+	shortcut.add("space", function () {
 		old_active = $(".post.flux.active");
 		old_active = $(".post.flux.active");
 		first_active = $(".post.flux:first");
 		first_active = $(".post.flux:first");
 		new_active = old_active.next ();
 		new_active = old_active.next ();
 		
 		
 		if (new_active[0] instanceof HTMLDivElement) {
 		if (new_active[0] instanceof HTMLDivElement) {
 			slide (new_active, old_active);
 			slide (new_active, old_active);
-		} else {
+		} else if (new_active[0] === undefined) {
 			slide (first_active, old_active);
 			slide (first_active, old_active);
 		}
 		}
 	});
 	});

+ 14 - 7
lib/lib_rss.php

@@ -69,16 +69,23 @@ function sortReverseEntriesByDate ($entry1, $entry2) {
 	return $entry1->date (true) - $entry2->date (true);
 	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;
 	return $txt;
 }
 }
 
 

+ 29 - 9
public/theme/base.css

@@ -40,9 +40,9 @@ ul, ol {
 
 
 /* TITRES */
 /* TITRES */
 h1, h2, h3 {
 h1, h2, h3 {
-	min-height: 50px;
-	padding: 10px 0 20px;
-	line-height: 50px;
+	min-height: 40px;
+	padding: 10px 0 0;
+	line-height: 40px;
 }
 }
 
 
 /* IMG */
 /* IMG */
@@ -132,10 +132,6 @@ form {
 				overflow: hidden;
 				overflow: hidden;
 				line-height: 50px;
 				line-height: 50px;
 			}
 			}
-				.aside li.active a {
-					background: #0062BE !important;
-					color: #fff;
-				}
 				.aside li a, .aside li span {
 				.aside li a, .aside li span {
 					display: block;
 					display: block;
 					width: 230px;
 					width: 230px;
@@ -148,6 +144,10 @@ form {
 					.aside li.disable span {
 					.aside li.disable span {
 						background: #fff;
 						background: #fff;
 					}
 					}
+				.aside li.active a {
+					background: #0062BE;
+					color: #fff;
+				}
 				.aside li h2 {
 				.aside li h2 {
 					height: 50px;
 					height: 50px;
 					padding: 0;
 					padding: 0;
@@ -186,6 +186,23 @@ form {
 					border: none;
 					border: none;
 					border-radius: 0;
 					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 {
 	#main {
 		display: table-cell;
 		display: table-cell;
 		height: 100%;
 		height: 100%;
@@ -233,7 +250,6 @@ form {
 }
 }
 	.post.flux {
 	.post.flux {
 		margin: 40px auto;
 		margin: 40px auto;
-		padding: 25px 20px;
 		font-family: Palatino, "Times New Roman", serif;
 		font-family: Palatino, "Times New Roman", serif;
 		line-height: 170%;
 		line-height: 170%;
 		border-left: 5px solid #aaa;
 		border-left: 5px solid #aaa;
@@ -246,6 +262,7 @@ form {
 		transition: border-color .10s ease-out;
 		transition: border-color .10s ease-out;
 	}
 	}
 		.post.flux .before {
 		.post.flux .before {
+			padding: 20px;
 			color: #666;
 			color: #666;
 			font-size: 80%;
 			font-size: 80%;
 			text-align: center;
 			text-align: center;
@@ -268,8 +285,11 @@ form {
 					border-radius: 0 0 5px 5px;
 					border-radius: 0 0 5px 5px;
 					box-shadow: 0 1px 3px #aaa;
 					box-shadow: 0 1px 3px #aaa;
 				}
 				}
+		.post.flux > h1 {
+			padding: 10px 20px;
+		}
 		.post.flux .content {
 		.post.flux .content {
-			/*display: none;*/
+			padding: 10px 20px;
 		}
 		}
 			.post.flux .content img {
 			.post.flux .content img {
 				border-radius: 5px;
 				border-radius: 5px;