public function nbNotRead() { if ($this->nbNotRead < 0) { $catDAO = FreshRSS_Factory::createCategoryDAO(); $this->nbNotRead = $catDAO->countNotRead($this->id()); } return $this->nbNotRead; }
/** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the * underlying framework. */ public function firstAction() { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); } $catDAO = FreshRSS_Factory::createCategoryDAO(); $catDAO->checkDefault(); $this->view->categories = $catDAO->listCategories(false); $this->view->default_category = $catDAO->getDefault(); }
/** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the * underlying framework. */ public function firstAction() { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); } require_once LIB_PATH . '/lib_opml.php'; $this->catDAO = FreshRSS_Factory::createCategoryDAO(); $this->entryDAO = FreshRSS_Factory::createEntryDao(); $this->feedDAO = FreshRSS_Factory::createFeedDao(); }
public function changeCategory($idOldCat, $idNewCat) { $catDAO = FreshRSS_Factory::createCategoryDAO(); $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; } }
/** * 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. When allowing robots, always retrieve the full feed including description $catDAO = FreshRSS_Factory::createCategoryDAO(); $feed = FreshRSS_Context::$system_conf->allow_robots ? null : $catDAO->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::$description = $feed->description(); 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 = FreshRSS_Factory::createCategoryDAO(); $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(); }
/** * This action handles the article repartition statistic page. * * It displays the number of article and the average of article for the * following periods: * - hour of the day * - day of the week * - month * * @todo verify that the metrics used here make some sense. Especially * for the average. */ public function repartitionAction() { $statsDAO = FreshRSS_Factory::createStatsDAO(); $categoryDAO = FreshRSS_Factory::createCategoryDAO(); $feedDAO = FreshRSS_Factory::createFeedDao(); Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); $id = Minz_Request::param('id', null); $this->view->categories = $categoryDAO->listCategories(); $this->view->feed = $feedDAO->searchById($id); $this->view->days = $statsDAO->getDays(); $this->view->months = $statsDAO->getMonths(); $this->view->repartition = $statsDAO->calculateEntryRepartitionPerFeed($id); $this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id); $this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id); $this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id); $this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id); $this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id); $this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id); }
/** * This action deletes a category. * Feeds in the given category are moved in the default category. * Related user queries are deleted too. * * Request parameter is: * - id (of a category) */ public function deleteAction() { $feedDAO = FreshRSS_Factory::createFeedDao(); $catDAO = FreshRSS_Factory::createCategoryDAO(); $default_category = $catDAO->getDefault(); $url_redirect = array('c' => 'subscription', 'a' => 'index'); if (Minz_Request::isPost()) { invalidateHttpCache(); $id = Minz_Request::param('id'); if (!$id) { Minz_Request::bad(_t('feedback.sub.category.no_id'), $url_redirect); } if ($id === $default_category->id()) { Minz_Request::bad(_t('feedback.sub.category.not_delete_default'), $url_redirect); } if ($feedDAO->changeCategory($id, $default_category->id()) === false) { Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect); } if ($catDAO->deleteCategory($id) === false) { Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect); } // Remove related queries. FreshRSS_Context::$user_conf->queries = remove_query_by_get('c_' . $id, FreshRSS_Context::$user_conf->queries); FreshRSS_Context::$user_conf->save(); Minz_Request::good(_t('feedback.sub.category.deleted'), $url_redirect); } Minz_Request::forward($url_redirect, true); }
public function nbUnreadsPerFeedAction() { header('Content-Type: application/json; charset=UTF-8'); $catDAO = FreshRSS_Factory::createCategoryDAO(); $this->view->categories = $catDAO->listCategories(true, false); }
/** * This action changes the category of a feed. * * This page must be reached by a POST request. * * Parameters are: * - f_id (default: false) * - c_id (default: false) * If c_id is false, default category is used. * * @todo should handle order of the feed inside the category. */ public function moveAction() { if (!Minz_Request::isPost()) { Minz_Request::forward(array('c' => 'subscription'), true); } $feed_id = Minz_Request::param('f_id'); $cat_id = Minz_Request::param('c_id'); if ($cat_id === false) { // If category was not given get the default one. $catDAO = FreshRSS_Factory::createCategoryDAO(); $catDAO->checkDefault(); $def_cat = $catDAO->getDefault(); $cat_id = $def_cat->id(); } $feedDAO = FreshRSS_Factory::createFeedDao(); $values = array('category' => $cat_id); $feed = $feedDAO->searchById($feed_id); if ($feed && ($feed->category() == $cat_id || $feedDAO->updateFeed($feed_id, $values))) { // TODO: return something useful } else { Minz_Log::warning('Cannot move feed `' . $feed_id . '` ' . 'in the category `' . $cat_id . '`'); Minz_Error::error(404); } }
function markAllAsRead($streamId, $olderThanId) { //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); $entryDAO->markReadFeed($f_id, $olderThanId); } elseif (strpos($streamId, 'user/-/label/') === 0) { $c_name = basename($streamId); $categoryDAO = FreshRSS_Factory::createCategoryDAO(); $cat = $categoryDAO->searchByName($c_name); $entryDAO->markReadCat($cat === null ? -1 : $cat->id(), $olderThanId); } elseif ($streamId === 'user/-/state/com.google/reading-list') { $entryDAO->markReadEntries($olderThanId, false, -1); } echo 'OK'; exit; }
/** * This action handles the creation of a user query. * * It gets the GET parameters and stores them in the configuration query * storage. Before it is saved, the unwanted parameters are unset to keep * lean data. */ public function addQueryAction() { $category_dao = FreshRSS_Factory::createCategoryDAO(); $feed_dao = FreshRSS_Factory::createFeedDao(); $queries = array(); foreach (FreshRSS_Context::$user_conf->queries as $key => $query) { $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao); } $params = Minz_Request::params(); $params['url'] = Minz_Url::display(array('params' => $params)); $params['name'] = _t('conf.query.number', count($queries) + 1); $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao); FreshRSS_Context::$user_conf->queries = $queries; FreshRSS_Context::$user_conf->save(); Minz_Request::good(_t('feedback.conf.query_created', $query['name']), array('c' => 'configure', 'a' => 'queries')); }