Sfoglia il codice sorgente

Move state constants from Configuration to Entry

Alexis Degrugillier 12 anni fa
parent
commit
3a736e902c

+ 2 - 2
app/Controllers/importExportController.php

@@ -370,7 +370,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			$this->view->type = 'starred';
 			$unread_fav = $this->entryDAO->countUnreadReadFavorites();
 			$this->view->entries = $this->entryDAO->listWhere(
-				's', '', FreshRSS_Configuration::STATE_ALL, 'ASC',
+				's', '', FreshRSS_Entry::STATE_ALL, 'ASC',
 				$unread_fav['all']
 			);
 		} elseif ($type == 'feed' && !is_null($feed)) {
@@ -379,7 +379,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			);
 			$this->view->type = 'feed/' . $feed->id();
 			$this->view->entries = $this->entryDAO->listWhere(
-				'f', $feed->id(), FreshRSS_Configuration::STATE_ALL, 'ASC',
+				'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC',
 				$this->view->conf->posts_per_page
 			);
 			$this->view->feed = $feed;

+ 5 - 5
app/Controllers/indexController.php

@@ -85,13 +85,13 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 		$state_param = Minz_Request::param ('state', null);
 		$filter = Minz_Request::param ('search', '');
 		if (!empty($filter)) {
-			$state = FreshRSS_Configuration::STATE_ALL;	//Search always in read and unread articles
+			$state = FreshRSS_Entry::STATE_ALL;	//Search always in read and unread articles
 		}
 		$this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sort_order);
 		$nb = Minz_Request::param ('nb', $this->view->conf->posts_per_page);
 		$first = Minz_Request::param ('next', '');
 
-		if ($state === FreshRSS_Configuration::STATE_NOT_READ) {	//Any unread article in this category at all?
+		if ($state === FreshRSS_Entry::STATE_NOT_READ) {	//Any unread article in this category at all?
 			switch ($getType) {
 				case 'a':
 					$hasUnread = $this->view->nb_not_read > 0;
@@ -112,7 +112,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 					break;
 			}
 			if (!$hasUnread && ($state_param === null)) {
-				$this->view->state = $state = FreshRSS_Configuration::STATE_ALL;
+				$this->view->state = $state = FreshRSS_Entry::STATE_ALL;
 			}
 		}
 
@@ -129,9 +129,9 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 
 			// Si on a récupéré aucun article "non lus"
 			// on essaye de récupérer tous les articles
-			if ($state === FreshRSS_Configuration::STATE_NOT_READ && empty($entries) && ($state_param === null)) {
+			if ($state === FreshRSS_Entry::STATE_NOT_READ && empty($entries) && ($state_param === null)) {
 				Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
-				$this->view->state = FreshRSS_Configuration::STATE_ALL;
+				$this->view->state = FreshRSS_Entry::STATE_ALL;
 				$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter, $date_min, true, $keepHistoryDefault);
 			}
 

+ 2 - 8
app/Models/Configuration.php

@@ -1,12 +1,6 @@
 <?php
 
 class FreshRSS_Configuration {
-	const STATE_ALL = 0;
-	const STATE_READ = 1;
-	const STATE_NOT_READ = 2;
-	const STATE_FAVORITE = 4;
-	const STATE_NOT_FAVORITE = 8;
-
 	private $filename;
 
 	private $data = array(
@@ -19,7 +13,7 @@ class FreshRSS_Configuration {
 		'apiPasswordHash' => '',	//CRYPT_BLOWFISH
 		'posts_per_page' => 20,
 		'view_mode' => 'normal',
-		'default_view' => self::STATE_NOT_READ,
+		'default_view' => FreshRSS_Entry::STATE_NOT_READ,
 		'auto_load_more' => true,
 		'display_posts' => false,
 		'onread_jump_next' => true,
@@ -137,7 +131,7 @@ class FreshRSS_Configuration {
 		}
 	}
 	public function _default_view ($value) {
-		$this->data['default_view'] = $value === self::STATE_ALL ? self::STATE_ALL : self::STATE_NOT_READ;
+		$this->data['default_view'] = $value === FreshRSS_Entry::STATE_ALL ? FreshRSS_Entry::STATE_ALL : FreshRSS_Entry::STATE_NOT_READ;
 	}
 	public function _display_posts ($value) {
 		$this->data['display_posts'] = ((bool)$value) && $value !== 'no';

+ 5 - 0
app/Models/Entry.php

@@ -1,6 +1,11 @@
 <?php
 
 class FreshRSS_Entry extends Minz_Model {
+	const STATE_ALL = 0;
+	const STATE_READ = 1;
+	const STATE_NOT_READ = 2;
+	const STATE_FAVORITE = 4;
+	const STATE_NOT_FAVORITE = 8;
 
 	private $id = 0;
 	private $guid;

+ 9 - 9
app/Models/EntryDAO.php

@@ -408,7 +408,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 
 	private function sqlListWhere($type = 'a', $id = '', $state = null , $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
 		if (!$state) {
-			$state = FreshRSS_Configuration::STATE_ALL;
+			$state = FreshRSS_Entry::STATE_ALL;
 		}
 		$where = '';
 		$joinFeed = false;
@@ -438,23 +438,23 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 				throw new FreshRSS_EntriesGetter_Exception ('Bad type in Entry->listByType: [' . $type . ']!');
 		}
 
-		if ($state & FreshRSS_Configuration::STATE_NOT_READ) {
-			if (!($state & FreshRSS_Configuration::STATE_READ)) {
+		if ($state & FreshRSS_Entry::STATE_NOT_READ) {
+			if (!($state & FreshRSS_Entry::STATE_READ)) {
 				$where .= 'AND e1.is_read = 0 ';
 			}
 		}
-		if ($state & FreshRSS_Configuration::STATE_READ) {
-			if (!($state & FreshRSS_Configuration::STATE_NOT_READ)) {
+		if ($state & FreshRSS_Entry::STATE_READ) {
+			if (!($state & FreshRSS_Entry::STATE_NOT_READ)) {
 				$where .= 'AND e1.is_read = 1 ';
 			}
 		}
-		if ($state & FreshRSS_Configuration::STATE_NOT_FAVORITE) {
-			if (!($state & FreshRSS_Configuration::STATE_FAVORITE)) {
+		if ($state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
+			if (!($state & FreshRSS_Entry::STATE_FAVORITE)) {
 				$where .= 'AND e1.is_favorite = 0 ';
 			}
 		}
-		if ($state & FreshRSS_Configuration::STATE_FAVORITE) {
-			if (!($state & FreshRSS_Configuration::STATE_NOT_FAVORITE)) {
+		if ($state & FreshRSS_Entry::STATE_FAVORITE) {
+			if (!($state & FreshRSS_Entry::STATE_NOT_FAVORITE)) {
 				$where .= 'AND e1.is_favorite = 1 ';
 			}
 		}

+ 12 - 12
app/layout/nav_menu.phtml

@@ -8,11 +8,11 @@
 
 	<?php if ($this->loginOk) { ?>
 	<?php $url_state = $this->url;
-		if ($this->state & FreshRSS_Configuration::STATE_READ) {
-			$url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_READ;
+		if ($this->state & FreshRSS_Entry::STATE_READ) {
+			$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_READ;
 			$checked = 'true';
 		} else {
-			$url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_READ;
+			$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_READ;
 			$checked = 'false';
 		}
 	?>
@@ -24,11 +24,11 @@
 		<?php echo FreshRSS_Themes::icon('read'); ?>
 	</a>
 	<?php
-		if ($this->state & FreshRSS_Configuration::STATE_NOT_READ) {
-			$url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_NOT_READ;
+		if ($this->state & FreshRSS_Entry::STATE_NOT_READ) {
+			$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_READ;
 			$checked = 'true';
 		} else {
-			$url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_NOT_READ;
+			$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_READ;
 			$checked = 'false';
 		}
 	?>
@@ -40,11 +40,11 @@
 		<?php echo FreshRSS_Themes::icon('unread'); ?>
 	</a>
 	<?php
-		if ($this->state & FreshRSS_Configuration::STATE_FAVORITE) {
-			$url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_FAVORITE;
+		if ($this->state & FreshRSS_Entry::STATE_FAVORITE) {
+			$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_FAVORITE;
 			$checked = 'true';
 		} else {
-			$url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_FAVORITE;
+			$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_FAVORITE;
 			$checked = 'false';
 		}
 	?>
@@ -56,11 +56,11 @@
 		<?php echo FreshRSS_Themes::icon('starred'); ?>
 	</a>
 	<?php
-		if ($this->state & FreshRSS_Configuration::STATE_NOT_FAVORITE) {
-			$url_state['params']['state'] = $this->state - FreshRSS_Configuration::STATE_NOT_FAVORITE;
+		if ($this->state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
+			$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_FAVORITE;
 			$checked = 'true';
 		} else {
-			$url_state['params']['state'] = $this->state + FreshRSS_Configuration::STATE_NOT_FAVORITE;
+			$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_FAVORITE;
 			$checked = 'false';
 		}
 	?>

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

@@ -32,11 +32,11 @@
 					<option value="global"<?php echo $this->conf->view_mode === 'global' ? ' selected="selected"' : ''; ?>><?php echo Minz_Translate::t ('global_view'); ?></option>
 				</select>
 				<label class="radio" for="radio_all">
-					<input type="radio" name="default_view" id="radio_all" value="<?php echo FreshRSS_Configuration::STATE_ALL; ?>"<?php echo $this->conf->default_view === FreshRSS_Configuration::STATE_ALL ? ' checked="checked"' : ''; ?> />
+					<input type="radio" name="default_view" id="radio_all" value="<?php echo FreshRSS_Entry::STATE_ALL; ?>"<?php echo $this->conf->default_view === FreshRSS_Entry::STATE_ALL ? ' checked="checked"' : ''; ?> />
 					<?php echo Minz_Translate::t ('show_all_articles'); ?>
 				</label>
 				<label class="radio" for="radio_not_read">
-					<input type="radio" name="default_view" id="radio_not_read" value="<?php echo FreshRSS_Configuration::STATE_NOT_READ; ?>"<?php echo $this->conf->default_view === FreshRSS_Configuration::STATE_NOT_READ ? ' checked="checked"' : ''; ?> />
+					<input type="radio" name="default_view" id="radio_not_read" value="<?php echo FreshRSS_Entry::STATE_NOT_READ; ?>"<?php echo $this->conf->default_view === FreshRSS_Entry::STATE_NOT_READ ? ' checked="checked"' : ''; ?> />
 					<?php echo Minz_Translate::t ('show_not_reads'); ?>
 				</label>
 			</div>

+ 4 - 4
p/api/greader.php

@@ -353,10 +353,10 @@ function streamContents($path, $include_target, $start_time, $count, $order, $ex
 
 	switch ($exclude_target) {
 		case 'user/-/state/com.google/read':
-			$state = FreshRSS_Configuration::STATE_NOT_READ;
+			$state = FreshRSS_Entry::STATE_NOT_READ;
 			break;
 		default:
-			$state = FreshRSS_Configuration::STATE_ALL;
+			$state = FreshRSS_Entry::STATE_ALL;
 			break;
 	}
 
@@ -451,10 +451,10 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude
 
 	switch ($exclude_target) {
 		case 'user/-/state/com.google/read':
-			$state = FreshRSS_Configuration::STATE_NOT_READ;
+			$state = FreshRSS_Entry::STATE_NOT_READ;
 			break;
 		default:
-			$state = FreshRSS_Configuration::STATE_ALL;
+			$state = FreshRSS_Entry::STATE_ALL;
 			break;
 	}