소스 검색

ajout de la fonctionnalité pour paramétrer les raccourcis

Marien Fressinaud 13 년 전
부모
커밋
48a1aa7d52

+ 36 - 1
app/controllers/configureController.php

@@ -85,7 +85,7 @@ class configureController extends ActionController {
 			);
 		
 			$confDAO = new RSSConfigurationDAO ();
-			$confDAO->save ($values);
+			$confDAO->update ($values);
 			Session::_param ('conf', $this->view->conf);
 		}
 	}
@@ -120,4 +120,39 @@ class configureController extends ActionController {
 			}
 		}
 	}
+	
+	public function shortcutAction () {
+		$list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
+		                    'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
+		                    'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
+		                    's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
+		                    'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
+		                    '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
+		                    'f10', 'f11', 'f12');
+		$this->view->list_keys = $list_keys;
+		$list_names = array ('mark_read', 'mark_favorite', 'go_website', 'next_entry',
+		                     'prev_entry', 'next_page', 'prev_page');
+		
+		if (Request::isPost ()) {
+			$shortcuts = Request::param ('shortcuts');
+			$shortcuts_ok = array ();
+			
+			foreach ($shortcuts as $key => $value) {
+				if (in_array ($key, $list_names)
+				 && in_array ($value, $list_keys)) {
+					$shortcuts_ok[$key] = $value;
+				}
+			}
+			
+			$this->view->conf->_shortcuts ($shortcuts_ok);
+			
+			$values = array (
+				'shortcuts' => $this->view->conf->shortcuts ()
+			);
+			
+			$confDAO = new RSSConfigurationDAO ();
+			$confDAO->update ($values);
+			Session::_param ('conf', $this->view->conf);
+		}
+	}
 }

+ 9 - 0
app/controllers/feedController.php

@@ -129,4 +129,13 @@ class feedController extends ActionController {
 	
 		Request::forward (array ('c' => 'configure', 'a' => 'importExport'));
 	}
+	
+	public function deleteAction () {
+		$id = Request::param ('id');
+		
+		$feedDAO = new FeedDAO ();
+		$feedDAO->deleteFeed ($id);
+		
+		Request::forward (array ('c' => 'configure', 'a' => 'flux'));
+	}
 }

+ 3 - 0
app/layout/aside.phtml

@@ -44,6 +44,9 @@
 		<li <?php echo Request::actionName () == 'importExport' ? 'class="active"' : ''; ?>>
 			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'importExport')); ?>">Import / Export OPML</a>
 		</li>
+		<li <?php echo Request::actionName () == 'shortcut' ? 'class="active"' : ''; ?>>
+			<a href="<?php echo Url::display (array ('c' => 'configure', 'a' => 'shortcut')); ?>">Raccourcis</a>
+		</li>
 	</ul>
 </div>
 <?php } ?>

+ 13 - 0
app/models/Feed.php

@@ -146,6 +146,19 @@ class FeedDAO extends Model_pdo {
 		}
 	}
 	
+	public function deleteFeed ($id) {
+		$sql = 'DELETE FROM feed WHERE id=?';
+		$stm = $this->bd->prepare ($sql);
+
+		$values = array ($id);
+
+		if ($stm && $stm->execute ($values)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
 	public function searchById ($id) {
 		$sql = 'SELECT * FROM feed WHERE id=?';
 		$stm = $this->bd->prepare ($sql);

+ 23 - 3
app/models/RSSConfiguration.php

@@ -6,6 +6,7 @@ class RSSConfiguration extends Model {
 	private $display_posts;
 	private $sort_order;
 	private $old_entries;
+	private $shortcuts = array ();
 	
 	public function __construct () {
 		$confDAO = new RSSConfigurationDAO ();
@@ -14,6 +15,7 @@ class RSSConfiguration extends Model {
 		$this->_displayPosts ($confDAO->display_posts);
 		$this->_sortOrder ($confDAO->sort_order);
 		$this->_oldEntries ($confDAO->old_entries);
+		$this->_shortcuts ($confDAO->shortcuts);
 	}
 	
 	public function postsPerPage () {
@@ -31,6 +33,9 @@ class RSSConfiguration extends Model {
 	public function oldEntries () {
 		return $this->old_entries;
 	}
+	public function shortcuts () {
+		return $this->shortcuts;
+	}
 	
 	public function _postsPerPage ($value) {
 		if (is_int ($value)) {
@@ -67,6 +72,11 @@ class RSSConfiguration extends Model {
 			$this->old_entries = 3;
 		}
 	}
+	public function _shortcuts ($values) {
+		foreach ($values as $key => $value) {
+			$this->shortcuts[$key] = $value;
+		}
+	}
 }
 
 class RSSConfigurationDAO extends Model_array {
@@ -75,6 +85,15 @@ class RSSConfigurationDAO extends Model_array {
 	public $display_posts = 'no';
 	public $sort_order = 'low_to_high';
 	public $old_entries = 3;
+	public $shortcuts = array (
+		'mark_read' => 'r',
+		'mark_favorite' => 'f',
+		'go_website' => 'enter',
+		'next_entry' => 'page_down',
+		'prev_entry' => 'page_up',
+		'next_page' => 'right',
+		'prev_page' => 'left',
+	);
 
 	public function __construct () {
 		parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
@@ -94,11 +113,12 @@ class RSSConfigurationDAO extends Model_array {
 		if (isset ($this->array['old_entries'])) {
 			$this->old_entries = $this->array['old_entries'];
 		}
+		if (isset ($this->array['shortcuts'])) {
+			$this->shortcuts = $this->array['shortcuts'];
+		}
 	}
 	
-	public function save ($values) {
-		$this->array[0] = array ();
-	
+	public function update ($values) {
 		foreach ($values as $key => $value) {
 			$this->array[0][$key] = $value;
 		}

+ 2 - 0
app/views/configure/flux.phtml

@@ -36,6 +36,8 @@
 		</div>
 		
 		<input type="submit" value="Valider" />
+		
+		<button formaction="<?php echo Url::display (array ('c' => 'feed', 'a' => 'delete', 'params' => array ('id' => $this->flux->id ()))); ?>">Supprimer</button>
 		<?php } ?>
 	</form>
 	<?php } else { ?>

+ 34 - 0
app/views/configure/shortcut.phtml

@@ -0,0 +1,34 @@
+<datalist id="keys">
+	<?php foreach ($this->list_keys as $key) { ?>
+	<option value="<?php echo $key; ?>">
+	<?php } ?>
+</datalist> 
+
+<?php $s = $this->conf->shortcuts (); ?>
+
+<form method="post" action="">
+	<h1>Gérer les raccourcis</h1>
+	
+	<label for="mark_read">Marquer l'article comme lu</label>
+	<input type="text" id="mark_read" name="shortcuts[mark_read]" list="keys" value="<?php echo $s['mark_read']; ?>" />
+	
+	<label for="mark_favorite">Mettre l'article  en favori</label>
+	<input type="text" id="mark_favorite" name="shortcuts[mark_favorite]" list="keys" value="<?php echo $s['mark_favorite']; ?>" />
+	
+	<label for="go_website">Afficher l'article sur le site d'origine</label>
+	<input type="text" id="go_website" name="shortcuts[go_website]" list="keys" value="<?php echo $s['go_website']; ?>" />
+	
+	<label for="next_entry">Passer à l'article suivant</label>
+	<input type="text" id="next_entry" name="shortcuts[next_entry]" list="keys" value="<?php echo $s['next_entry']; ?>" />
+	
+	<label for="prev_entry">Passer à l'article précédent</label>
+	<input type="text" id="prev_entry" name="shortcuts[prev_entry]" list="keys" value="<?php echo $s['prev_entry']; ?>" />
+	
+	<label for="next_page">Passer à la page suivant</label>
+	<input type="text" id="next_page" name="shortcuts[next_page]" list="keys" value="<?php echo $s['next_page']; ?>" />
+	
+	<label for="prev_page">Passer à la page précédente</label>
+	<input type="text" id="prev_page" name="shortcuts[prev_page]" list="keys" value="<?php echo $s['prev_page']; ?>" />
+	
+	<input type="submit" value="Valider" />
+</form>

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

@@ -22,7 +22,7 @@
 			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>
+		<h1 class="title"><a target="_blank" href="<?php echo $item->link (); ?>"> <?php echo $item->title (); ?></a></h1>
 		<div class="content"><?php echo $item->content (); ?></div>
 		
 		<div class="after">

+ 19 - 8
app/views/javascript/main.phtml

@@ -4,9 +4,15 @@ var hide_posts = true;
 var hide_posts = false;
 <?php } ?>
 
-function redirect (url) {
+<?php $s = $this->conf->shortcuts (); ?>
+
+function redirect (url, new_tab = false) {
 	if (url) {
-		location.href = url;
+		if (new_tab) {
+			window.open (url);
+		} else {
+			location.href = url;
+		}
 	}
 }
 
@@ -98,19 +104,19 @@ $(document).ready (function () {
 	});
 
 	// Touches de manipulation
-	shortcut.add("m", function () {
+	shortcut.add("<?php echo $s['mark_read']; ?>", function () {
 		// on marque comme lu ou non lu
 		active = $(".post.flux.active");
 		mark_read (active);
 	});
-	shortcut.add("f", function () {
+	shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
 		// on marque comme favori ou non favori
 		active = $(".post.flux.active");
 		mark_favorite (active);
 	});
 	
 	// Touches de navigation
-	shortcut.add("page_up", function () {
+	shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
 		old_active = $(".post.flux.active");
 		last_active = $(".post.flux:last");
 		new_active = old_active.prev ();
@@ -121,7 +127,7 @@ $(document).ready (function () {
 			slide (last_active, old_active);
 		}
 	});
-	shortcut.add("page_down", function () {
+	shortcut.add("<?php echo $s['next_entry']; ?>", function () {
 		old_active = $(".post.flux.active");
 		first_active = $(".post.flux:first");
 		new_active = old_active.next ();
@@ -132,7 +138,7 @@ $(document).ready (function () {
 			slide (first_active, old_active);
 		}
 	});
-	shortcut.add("right", function () {
+	shortcut.add("<?php echo $s['next_page']; ?>", function () {
 		url = $(".pager-next a").attr ("href");
 		if (url === undefined) {
 			url = $(".pager-first a").attr ("href");
@@ -140,7 +146,7 @@ $(document).ready (function () {
 		
 		redirect (url);
 	});
-	shortcut.add("left", function () {
+	shortcut.add("<?php echo $s['prev_page']; ?>", function () {
 		url = $(".pager-previous a").attr ("href");
 		if (url === undefined) {
 			url = $(".pager-last a").attr ("href");
@@ -148,4 +154,9 @@ $(document).ready (function () {
 		
 		redirect (url);
 	});
+	shortcut.add("<?php echo $s['go_website']; ?>", function () {
+		url = $(".post.flux.active h1.title a").attr ("href");
+		
+		redirect (url, true);
+	});
 });