/** * This action creates a new category. * * Request parameter is: * - new-category */ public function createAction() { $catDAO = new FreshRSS_CategoryDAO(); $url_redirect = array('c' => 'subscription', 'a' => 'index'); $limits = FreshRSS_Context::$system_conf->limits; $this->view->categories = $catDAO->listCategories(false); if (count($this->view->categories) >= $limits['max_categories']) { Minz_Request::bad(_t('feedback.sub.category.over_max', $limits['max_categories']), $url_redirect); } if (Minz_Request::isPost()) { invalidateHttpCache(); $cat_name = Minz_Request::param('new-category'); if (!$cat_name) { Minz_Request::bad(_t('feedback.sub.category.no_name'), $url_redirect); } $cat = new FreshRSS_Category($cat_name); if ($catDAO->searchByName($cat->name()) != null) { Minz_Request::bad(_t('feedback.sub.category.name_exists'), $url_redirect); } $values = array('id' => $cat->id(), 'name' => $cat->name()); if ($catDAO->addCategory($values)) { Minz_Request::good(_t('feedback.sub.category.created', $cat->name()), $url_redirect); } else { Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect); } } Minz_Request::forward($url_redirect, true); }
/** * Initialize the context. * * Set the correct configurations and $categories variables. */ public static function init() { // Init configuration. self::$system_conf = Minz_Configuration::get('system'); self::$user_conf = Minz_Configuration::get('user'); $catDAO = new FreshRSS_CategoryDAO(); self::$categories = $catDAO->listCategories(); }
/** * 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 = new FreshRSS_CategoryDAO(); $catDAO->checkDefault(); $this->view->categories = $catDAO->listCategories(false); $this->view->default_category = $catDAO->getDefault(); }
function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count logMe("unreadCount()\n"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; $totalLastUpdate = 0; $categoryDAO = new FreshRSS_CategoryDAO(); foreach ($categoryDAO->listCategories(true, true) as $cat) { $catLastUpdate = 0; foreach ($cat->feeds() as $feed) { $lastUpdate = $feed->lastUpdate(); $unreadcounts[] = array('id' => 'feed/' . $feed->id(), 'count' => $feed->nbNotRead(), 'newestItemTimestampUsec' => $lastUpdate . '000000'); if ($catLastUpdate < $lastUpdate) { $catLastUpdate = $lastUpdate; } } $unreadcounts[] = array('id' => 'user/-/label/' . $cat->name(), 'count' => $cat->nbNotRead(), 'newestItemTimestampUsec' => $catLastUpdate . '000000'); $totalUnreads += $cat->nbNotRead(); if ($totalLastUpdate < $catLastUpdate) { $totalLastUpdate = $catLastUpdate; } } $unreadcounts[] = array('id' => 'user/-/state/com.google/reading-list', 'count' => $totalUnreads, 'newestItemTimestampUsec' => $totalLastUpdate . '000000'); echo json_encode(array('max' => $totalUnreads, 'unreadcounts' => $unreadcounts)), "\n"; exit; }
/** * 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 = new FreshRSS_CategoryDAO(); $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); }
public function importExportAction() { require_once LIB_PATH . '/lib_opml.php'; $catDAO = new FreshRSS_CategoryDAO(); $this->view->categories = $catDAO->listCategories(); $this->view->req = Minz_Request::param('q'); if ($this->view->req == 'export') { Minz_View::_title('freshrss_feeds.opml'); $this->view->_useLayout(false); header('Content-Type: application/xml; charset=utf-8'); header('Content-disposition: attachment; filename=freshrss_feeds.opml'); $feedDAO = new FreshRSS_FeedDAO(); $catDAO = new FreshRSS_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' && Minz_Request::isPost()) { if ($_FILES['file']['error'] == 0) { invalidateHttpCache(); // on parse le fichier OPML pour récupérer les catégories et les flux associés try { list($categories, $feeds) = opml_import(file_get_contents($_FILES['file']['tmp_name'])); // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD // les flux sont mis au préalable dans des variables de Request Minz_Request::_param('q', 'null'); Minz_Request::_param('categories', $categories); Minz_Request::_param('feeds', $feeds); Minz_Request::forward(array('c' => 'feed', 'a' => 'massiveImport')); } catch (FreshRSS_Opml_Exception $e) { Minz_Log::record($e->getMessage(), Minz_Log::WARNING); $notif = array('type' => 'bad', 'content' => Minz_Translate::t('bad_opml_file')); Minz_Session::_param('notification', $notif); Minz_Request::forward(array('c' => 'configure', 'a' => 'importExport'), true); } } } $feedDAO = new FreshRSS_FeedDAO(); $this->view->feeds = $feedDAO->listFeeds(); // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste $this->view->flux = false; Minz_View::prependTitle(Minz_Translate::t('import_export_opml') . ' · '); }
public function nbUnreadsPerFeedAction() { header('Content-Type: application/json; charset=UTF-8'); $catDAO = new FreshRSS_CategoryDAO(); $this->view->categories = $catDAO->listCategories(true, false); }
public function indexAction() { $output = Minz_Request::param('output'); $token = $this->view->conf->token; // check if user is logged in if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous()) { $token_param = Minz_Request::param('token', ''); $token_is_ok = $token != '' && $token === $token_param; if ($output === 'rss' && !$token_is_ok) { Minz_Error::error(403, array('error' => array(Minz_Translate::t('access_denied')))); return; } elseif ($output !== 'rss') { // "hard" redirection is not required, just ask dispatcher to // forward to the login form without 302 redirection Minz_Request::forward(array('c' => 'index', 'a' => 'formLogin')); return; } } // construction of RSS url of this feed $params = Minz_Request::params(); $params['output'] = 'rss'; if (isset($params['search'])) { $params['search'] = urlencode($params['search']); } if (!Minz_Configuration::allowAnonymous()) { $params['token'] = $token; } $this->view->rss_url = array('c' => 'index', 'a' => 'index', 'params' => $params); if ($output === 'rss') { // no layout for RSS output $this->view->_useLayout(false); header('Content-Type: application/rss+xml; charset=utf-8'); } elseif ($output === 'global') { Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } $catDAO = new FreshRSS_CategoryDAO(); $entryDAO = new FreshRSS_EntryDAO(); $this->view->cat_aside = $catDAO->listCategories(); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites(); $this->view->nb_not_read = FreshRSS_CategoryDAO::CountUnreads($this->view->cat_aside, 1); $this->view->currentName = ''; $this->view->get_c = ''; $this->view->get_f = ''; $get = Minz_Request::param('get', 'a'); $getType = $get[0]; $getId = substr($get, 2); if (!$this->checkAndProcessType($getType, $getId)) { Minz_Log::record('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG); Minz_Error::error(404, array('error' => array(Minz_Translate::t('page_not_found')))); return; } // mise à jour des titres $this->view->rss_title = $this->view->currentName . ' | ' . Minz_View::title(); if ($this->view->nb_not_read > 0) { Minz_View::appendTitle(' (' . formatNumber($this->view->nb_not_read) . ')'); } Minz_View::prependTitle($this->view->currentName . ($this->nb_not_read_cat > 0 ? ' (' . formatNumber($this->nb_not_read_cat) . ')' : '') . ' · '); // On récupère les différents éléments de filtrage $this->view->state = $state = Minz_Request::param('state', $this->view->conf->default_view); $filter = Minz_Request::param('search', ''); if (!empty($filter)) { $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 === 'not_read') { //Any unread article in this category at all? switch ($getType) { case 'a': $hasUnread = $this->view->nb_not_read > 0; break; case 's': $hasUnread = $this->view->nb_favorites['unread'] > 0; break; case 'c': $hasUnread = !isset($this->view->cat_aside[$getId]) || $this->view->cat_aside[$getId]->nbNotRead() > 0; break; case 'f': $myFeed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId); $hasUnread = $myFeed === null || $myFeed->nbNotRead() > 0; break; default: $hasUnread = true; break; } if (!$hasUnread) { $this->view->state = $state = 'all'; } } $today = @strtotime('today'); $this->view->today = $today; // on calcule la date des articles les plus anciens qu'on affiche $nb_month_old = $this->view->conf->old_entries; $date_min = $today - 3600 * 24 * 30 * $nb_month_old; //Do not use a fast changing value such as time() to allow SQL caching $keepHistoryDefault = $this->view->conf->keep_history_default; try { $entries = $entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter, $date_min, $keepHistoryDefault); // Si on a récupéré aucun article "non lus" // on essaye de récupérer tous les articles if ($state === 'not_read' && empty($entries)) { Minz_Log::record('Conflicting information about nbNotRead!', Minz_Log::DEBUG); $this->view->state = 'all'; $entries = $entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min, $keepHistoryDefault); } if (count($entries) <= $nb) { $this->view->nextId = ''; } else { //We have more elements for pagination $lastEntry = array_pop($entries); $this->view->nextId = $lastEntry->id(); } $this->view->entries = $entries; } catch (FreshRSS_EntriesGetter_Exception $e) { Minz_Log::record($e->getMessage(), Minz_Log::NOTICE); Minz_Error::error(404, array('error' => array(Minz_Translate::t('page_not_found')))); } }
public function getFeedTree() { $include_empty = $this->param('include_empty', true); $tree = array('identifier' => 'id', 'label' => 'name', 'items' => array()); $categoryDAO = new FreshRSS_CategoryDAO(); $categories = $categoryDAO->listCategories(true, true); foreach ($categories as $cat) { $tree_cat = array('id' => 'CAT:' . $cat->id(), 'name' => $cat->name(), 'unread' => $cat->nbNotRead(), 'type' => 'category', 'bare_id' => $cat->id(), 'items' => array()); foreach ($cat->feeds() as $feed) { $tree_cat['items'][] = array('id' => 'FEED:' . $feed->id(), 'name' => $feed->name(), 'unread' => $feed->nbNotRead(), 'type' => 'feed', 'error' => $feed->inError(), 'updated' => $feed->lastUpdate(), 'bare_id' => $feed->id()); } if (count($tree_cat['items']) > 0 || $include_empty) { $tree['items'][] = $tree_cat; } } $this->good(array('categories' => $tree)); }