public function changeCategory($idOldCat, $idNewCat) { $catDAO = new FreshRSS_CategoryDAO(); $newCat = $catDAO->searchById($idNewCat); if (!$newCat) { $newCat = $catDAO->getDefault(); } $sql = 'UPDATE `' . $this->prefix . 'feed` SET category=? WHERE category=?'; $stm = $this->bd->prepare($sql); $values = array($newCat->id(), $idOldCat); if ($stm && $stm->execute($values)) { return $stm->rowCount(); } else { $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); Minz_Log::error('SQL error changeCategory: ' . $info[2]); return false; } }
/** * This action updates the given category. * * Request parameters are: * - id * - name */ public function updateAction() { $catDAO = new FreshRSS_CategoryDAO(); $url_redirect = array('c' => 'subscription', 'a' => 'index'); if (Minz_Request::isPost()) { invalidateHttpCache(); $id = Minz_Request::param('id'); $name = Minz_Request::param('name', ''); if (strlen($name) <= 0) { Minz_Request::bad(_t('feedback.sub.category.no_name'), $url_redirect); } if ($catDAO->searchById($id) == null) { Minz_Request::bad(_t('feedback.sub.category.not_exist'), $url_redirect); } $cat = new FreshRSS_Category($name); $values = array('name' => $cat->name()); if ($catDAO->updateCategory($id, $values)) { Minz_Request::good(_t('feedback.sub.category.updated'), $url_redirect); } else { Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect); } } Minz_Request::forward($url_redirect, true); }
/** * This action handles the user queries configuration page. * * If this action is reached through a POST request, it stores all new * configuration values then sends a notification to the user then * redirect to the same page. * If this action is not reached through a POST request, it displays the * configuration page and verifies that every user query is runable by * checking if categories and feeds are still in use. */ public function queriesAction() { if (Minz_Request::isPost()) { $queries = Minz_Request::param('queries', array()); foreach ($queries as $key => $query) { if (!$query['name']) { $query['name'] = _t('conf.query.number', $key + 1); } } FreshRSS_Context::$user_conf->queries = $queries; FreshRSS_Context::$user_conf->save(); Minz_Request::good(_t('feedback.conf.updated'), array('c' => 'configure', 'a' => 'queries')); } else { $this->view->query_get = array(); $cat_dao = new FreshRSS_CategoryDAO(); $feed_dao = FreshRSS_Factory::createFeedDao(); foreach (FreshRSS_Context::$user_conf->queries as $key => $query) { if (!isset($query['get'])) { continue; } switch ($query['get'][0]) { case 'c': $category = $cat_dao->searchById(substr($query['get'], 2)); $deprecated = true; $cat_name = ''; if ($category) { $cat_name = $category->name(); $deprecated = false; } $this->view->query_get[$key] = array('type' => 'category', 'name' => $cat_name, 'deprecated' => $deprecated); break; case 'f': $feed = $feed_dao->searchById(substr($query['get'], 2)); $deprecated = true; $feed_name = ''; if ($feed) { $feed_name = $feed->name(); $deprecated = false; } $this->view->query_get[$key] = array('type' => 'feed', 'name' => $feed_name, 'deprecated' => $deprecated); break; case 's': $this->view->query_get[$key] = array('type' => 'favorite', 'name' => 'favorite', 'deprecated' => false); break; case 'a': $this->view->query_get[$key] = array('type' => 'all', 'name' => 'all', 'deprecated' => false); break; } } } Minz_View::prependTitle(_t('conf.query.title') . ' · '); }
/** * Set the current $get attribute. * * Valid $get parameter are: * - a * - s * - f_<feed id> * - c_<category id> * * $name and $get_unread attributes are also updated as $next_get * Raise an exception if id or $get is invalid. */ public static function _get($get) { $type = $get[0]; $id = substr($get, 2); $nb_unread = 0; switch ($type) { case 'a': self::$current_get['all'] = true; self::$name = _t('index.feed.title'); self::$get_unread = self::$total_unread; break; case 's': self::$current_get['starred'] = true; self::$name = _t('index.feed.title_fav'); self::$get_unread = self::$total_starred['unread']; // Update state if favorite is not yet enabled. self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; break; case 'f': // We try to find the corresponding feed. $feed = FreshRSS_CategoryDAO::findFeed(self::$categories, $id); if ($feed === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); $feed = $feedDAO->searchById($id); if (!$feed) { throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); } } self::$current_get['feed'] = $id; self::$current_get['category'] = $feed->category(); self::$name = $feed->name(); self::$get_unread = $feed->nbNotRead(); break; case 'c': // We try to find the corresponding category. self::$current_get['category'] = $id; if (!isset(self::$categories[$id])) { $catDAO = new FreshRSS_CategoryDAO(); $cat = $catDAO->searchById($id); if (!$cat) { throw new FreshRSS_Context_Exception('Invalid category: ' . $id); } } else { $cat = self::$categories[$id]; } self::$name = $cat->name(); self::$get_unread = $cat->nbNotRead(); break; default: throw new FreshRSS_Context_Exception('Invalid getter: ' . $get); } self::_nextGet(); }
private function checkAndProcessType($getType, $getId) { switch ($getType) { case 'a': $this->view->currentName = Minz_Translate::t('your_rss_feeds'); $this->nb_not_read_cat = $this->view->nb_not_read; $this->view->get_c = $getType; return true; case 's': $this->view->currentName = Minz_Translate::t('your_favorites'); $this->nb_not_read_cat = $this->view->nb_favorites['unread']; $this->view->get_c = $getType; return true; case 'c': $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null; if ($cat === null) { $catDAO = new FreshRSS_CategoryDAO(); $cat = $catDAO->searchById($getId); } if ($cat) { $this->view->currentName = $cat->name(); $this->nb_not_read_cat = $cat->nbNotRead(); $this->view->get_c = $getId; return true; } else { return false; } case 'f': $feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId); if (empty($feed)) { $feedDAO = new FreshRSS_FeedDAO(); $feed = $feedDAO->searchById($getId); } if ($feed) { $this->view->currentName = $feed->name(); $this->nb_not_read_cat = $feed->nbNotRead(); $this->view->get_f = $getId; $this->view->get_c = $feed->category(); return true; } else { return false; } default: return false; } }