/**
  * This action handles the feed configuration page.
  *
  * It displays the feed configuration page.
  * If this action is reached through a POST request, it stores all new
  * configuraiton values then sends a notification to the user.
  *
  * The options available on the page are:
  *   - name
  *   - description
  *   - website URL
  *   - feed URL
  *   - category id (default: default category id)
  *   - CSS path to article on website
  *   - display in main stream (default: 0)
  *   - HTTP authentication
  *   - number of article to retain (default: -2)
  *   - refresh frequency (default: -2)
  * Default values are empty strings unless specified.
  */
 public function feedAction()
 {
     if (Minz_Request::param('ajax')) {
         $this->view->_useLayout(false);
     }
     $feedDAO = FreshRSS_Factory::createFeedDao();
     $this->view->feeds = $feedDAO->listFeeds();
     $id = Minz_Request::param('id');
     if ($id === false || !isset($this->view->feeds[$id])) {
         Minz_Error::error(404);
         return;
     }
     $this->view->feed = $this->view->feeds[$id];
     Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $this->view->feed->name() . ' · ');
     if (Minz_Request::isPost()) {
         $user = Minz_Request::param('http_user', '');
         $pass = Minz_Request::param('http_pass', '');
         $httpAuth = '';
         if ($user != '' || $pass != '') {
             $httpAuth = $user . ':' . $pass;
         }
         $cat = intval(Minz_Request::param('category', 0));
         $values = array('name' => Minz_Request::param('name', ''), 'description' => sanitizeHTML(Minz_Request::param('description', '', true)), 'website' => Minz_Request::param('website', ''), 'url' => Minz_Request::param('url', ''), 'category' => $cat, 'pathEntries' => Minz_Request::param('path_entries', ''), 'priority' => intval(Minz_Request::param('priority', 0)), 'httpAuth' => $httpAuth, 'keep_history' => intval(Minz_Request::param('keep_history', -2)), 'ttl' => intval(Minz_Request::param('ttl', -2)));
         invalidateHttpCache();
         $url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
         if ($feedDAO->updateFeed($id, $values) !== false) {
             $this->view->feed->_category($cat);
             $this->view->feed->faviconPrepare();
             Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
         } else {
             Minz_Request::bad(_t('feedback.sub.feed.error'), $url_redirect);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * This action is the default one for the controller.
  *
  * It is called by Minz_Error::error() method.
  *
  * Parameters are passed by Minz_Session to have a proper url:
  *   - error_code (default: 404)
  *   - error_logs (default: array())
  */
 public function indexAction()
 {
     $code_int = Minz_Session::param('error_code', 404);
     $error_logs = Minz_Session::param('error_logs', array());
     Minz_Session::_param('error_code');
     Minz_Session::_param('error_logs');
     switch ($code_int) {
         case 200:
             header('HTTP/1.1 200 OK');
             break;
         case 403:
             header('HTTP/1.1 403 Forbidden');
             $this->view->code = 'Error 403 - Forbidden';
             $this->view->errorMessage = _t('feedback.access.denied');
             break;
         case 500:
             header('HTTP/1.1 500 Internal Server Error');
             $this->view->code = 'Error 500 - Internal Server Error';
             break;
         case 503:
             header('HTTP/1.1 503 Service Unavailable');
             $this->view->code = 'Error 503 - Service Unavailable';
             break;
         case 404:
         default:
             header('HTTP/1.1 404 Not Found');
             $this->view->code = 'Error 404 - Not found';
             $this->view->errorMessage = _t('feedback.access.not_found');
     }
     $error_message = trim(implode($error_logs));
     if ($error_message !== '') {
         $this->view->errorMessage = $error_message;
     }
     Minz_View::prependTitle($this->view->code . ' · ');
 }
Exemplo n.º 3
0
 /**
  * This action lists all the extensions available to the current user.
  */
 public function indexAction()
 {
     Minz_View::prependTitle(_t('admin.extensions.title') . ' · ');
     $this->view->extension_list = array('system' => array(), 'user' => array());
     $extensions = Minz_ExtensionManager::listExtensions();
     foreach ($extensions as $ext) {
         $this->view->extension_list[$ext->getType()][] = $ext;
     }
 }
Exemplo n.º 4
0
 public function init()
 {
     $this->registerTranslates();
     Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));
     $current_user = Minz_Session::param('currentUser');
     $filename = 'style.' . $current_user . '.css';
     $filepath = join_path($this->getPath(), 'static', $filename);
     if (file_exists($filepath)) {
         Minz_View::appendStyle($this->getFileUrl($filename, 'css'));
     }
 }
Exemplo n.º 5
0
 /**
  * This action displays the user management page.
  */
 public function manageAction()
 {
     if (!FreshRSS_Auth::hasAccess('admin')) {
         Minz_Error::error(403);
     }
     Minz_View::prependTitle(_t('admin.user.title') . ' · ');
     // Get the correct current user.
     $username = Minz_Request::param('u', Minz_Session::param('currentUser'));
     if (!FreshRSS_UserDAO::exist($username)) {
         $username = Minz_Session::param('currentUser');
     }
     $this->view->current_user = $username;
     // Get information about the current user.
     $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user);
     $this->view->nb_articles = $entryDAO->count();
     $this->view->size_user = $entryDAO->size();
 }
Exemplo n.º 6
0
 public function indexAction()
 {
     switch (Minz_Request::param('code')) {
         case 403:
             $this->view->code = 'Error 403 - Forbidden';
             break;
         case 404:
             $this->view->code = 'Error 404 - Not found';
             break;
         case 500:
             $this->view->code = 'Error 500 - Internal Server Error';
             break;
         case 503:
             $this->view->code = 'Error 503 - Service Unavailable';
             break;
         default:
             $this->view->code = 'Error 404 - Not found';
     }
     $this->view->logs = Minz_Request::param('logs');
     Minz_View::prependTitle($this->view->code . ' · ');
 }
Exemplo n.º 7
0
 public function archivingAction()
 {
     if (Minz_Request::isPost()) {
         $old = Minz_Request::param('old_entries', 3);
         $keepHistoryDefault = Minz_Request::param('keep_history_default', 0);
         $this->view->conf->_old_entries($old);
         $this->view->conf->_keep_history_default($keepHistoryDefault);
         $this->view->conf->save();
         invalidateHttpCache();
         $notif = array('type' => 'good', 'content' => Minz_Translate::t('configuration_updated'));
         Minz_Session::_param('notification', $notif);
         Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true);
     }
     Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · ');
     $entryDAO = new FreshRSS_EntryDAO();
     $this->view->nb_total = $entryDAO->count();
     $this->view->size_user = $entryDAO->size();
     if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
         $this->view->size_total = $entryDAO->size(true);
     }
 }
Exemplo n.º 8
0
 /**
  * This action subscribes to a feed.
  *
  * It can be reached by both GET and POST requests.
  *
  * GET request displays a form to add and configure a feed.
  * Request parameter is:
  *   - url_rss (default: false)
  *
  * POST request adds a feed in database.
  * Parameters are:
  *   - url_rss (default: false)
  *   - category (default: false)
  *   - new_category (required if category == 'nc')
  *   - http_user (default: false)
  *   - http_pass (default: false)
  * It tries to get website information from RSS feed.
  * If no category is given, feed is added to the default one.
  *
  * If url_rss is false, nothing happened.
  */
 public function addAction()
 {
     $url = Minz_Request::param('url_rss');
     if ($url === false) {
         // No url, do nothing
         Minz_Request::forward(array('c' => 'subscription', 'a' => 'index'), true);
     }
     $feedDAO = FreshRSS_Factory::createFeedDao();
     $this->catDAO = new FreshRSS_CategoryDAO();
     $url_redirect = array('c' => 'subscription', 'a' => 'index', 'params' => array());
     $limits = FreshRSS_Context::$system_conf->limits;
     $this->view->feeds = $feedDAO->listFeeds();
     if (count($this->view->feeds) >= $limits['max_feeds']) {
         Minz_Request::bad(_t('feedback.sub.feed.over_max', $limits['max_feeds']), $url_redirect);
     }
     if (Minz_Request::isPost()) {
         @set_time_limit(300);
         $cat = Minz_Request::param('category');
         if ($cat === 'nc') {
             // User want to create a new category, new_category parameter
             // must exist
             $new_cat = Minz_Request::param('new_category');
             if (empty($new_cat['name'])) {
                 $cat = false;
             } else {
                 $cat = $this->catDAO->addCategory($new_cat);
             }
         }
         if ($cat === false) {
             // If category was not given or if creating new category failed,
             // get the default category
             $this->catDAO->checkDefault();
             $def_cat = $this->catDAO->getDefault();
             $cat = $def_cat->id();
         }
         // HTTP information are useful if feed is protected behind a
         // HTTP authentication
         $user = trim(Minz_Request::param('http_user', ''));
         $pass = Minz_Request::param('http_pass', '');
         $http_auth = '';
         if ($user != '' && $pass != '') {
             //TODO: Sanitize
             $http_auth = $user . ':' . $pass;
         }
         $transaction_started = false;
         try {
             $feed = new FreshRSS_Feed($url);
         } catch (FreshRSS_BadUrl_Exception $e) {
             // Given url was not a valid url!
             Minz_Log::warning($e->getMessage());
             Minz_Request::bad(_t('feedback.sub.feed.invalid_url', $url), $url_redirect);
         }
         try {
             $feed->load(true);
         } catch (FreshRSS_Feed_Exception $e) {
             // Something went bad (timeout, server not found, etc.)
             Minz_Log::warning($e->getMessage());
             Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
         } catch (Minz_FileNotExistException $e) {
             // Cache directory doesn't exist!
             Minz_Log::error($e->getMessage());
             Minz_Request::bad(_t('feedback.sub.feed.internal_problem', _url('index', 'logs')), $url_redirect);
         }
         if ($feedDAO->searchByUrl($feed->url())) {
             Minz_Request::bad(_t('feedback.sub.feed.already_subscribed', $feed->name()), $url_redirect);
         }
         $feed->_category($cat);
         $feed->_httpAuth($http_auth);
         // Call the extension hook
         $name = $feed->name();
         $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed);
         if ($feed === null) {
             Minz_Request::bad(_t('feedback.sub.feed.not_added', $name), $url_redirect);
         }
         $values = array('url' => $feed->url(), 'category' => $feed->category(), 'name' => $feed->name(), 'website' => $feed->website(), 'description' => $feed->description(), 'lastUpdate' => time(), 'httpAuth' => $feed->httpAuth());
         $id = $feedDAO->addFeed($values);
         if (!$id) {
             // There was an error in database... we cannot say what here.
             Minz_Request::bad(_t('feedback.sub.feed.not_added', $feed->name()), $url_redirect);
         }
         // Ok, feed has been added in database. Now we have to refresh entries.
         $feed->_id($id);
         $feed->faviconPrepare();
         //$feed->pubSubHubbubPrepare();	//TODO: prepare PubSubHubbub already when adding the feed
         $is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
         $entryDAO = FreshRSS_Factory::createEntryDao();
         // We want chronological order and SimplePie uses reverse order.
         $entries = array_reverse($feed->entries());
         // Calculate date of oldest entries we accept in DB.
         $nb_month_old = FreshRSS_Context::$user_conf->old_entries;
         $date_min = time() - 3600 * 24 * 30 * $nb_month_old;
         // Use a shared statement and a transaction to improve a LOT the
         // performances.
         $feedDAO->beginTransaction();
         foreach ($entries as $entry) {
             // Entries are added without any verification.
             $entry->_feed($feed->id());
             $entry->_id(min(time(), $entry->date(true)) . uSecString());
             $entry->_isRead($is_read);
             $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
             if ($entry === null) {
                 // An extension has returned a null value, there is nothing to insert.
                 continue;
             }
             $values = $entry->toArray();
             $entryDAO->addEntry($values);
         }
         $feedDAO->updateLastUpdate($feed->id());
         $feedDAO->commit();
         // Entries are in DB, we redirect to feed configuration page.
         $url_redirect['params']['id'] = $feed->id();
         Minz_Request::good(_t('feedback.sub.feed.added', $feed->name()), $url_redirect);
     } else {
         // GET request: we must ask confirmation to user before adding feed.
         Minz_View::prependTitle(_t('sub.feed.title_add') . ' · ');
         $this->view->categories = $this->catDAO->listCategories(false);
         $this->view->feed = new FreshRSS_Feed($url);
         try {
             // We try to get more information about the feed.
             $this->view->feed->load(true);
             $this->view->load_ok = true;
         } catch (Exception $e) {
             $this->view->load_ok = false;
         }
         $feed = $feedDAO->searchByUrl($this->view->feed->url());
         if ($feed) {
             // Already subscribe so we redirect to the feed configuration page.
             $url_redirect['params']['id'] = $feed->id();
             Minz_Request::good(_t('feedback.sub.feed.already_subscribed', $feed->name()), $url_redirect);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * This action gives possibility to a user to create an account.
  */
 public function registerAction()
 {
     if (max_registrations_reached()) {
         Minz_Error::error(403);
     }
     Minz_View::prependTitle(_t('gen.auth.registration.title') . ' · ');
 }
Exemplo n.º 10
0
 /**
  * This action displays logs of FreshRSS for the current user.
  */
 public function logsAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     Minz_View::prependTitle(_t('index.log.title') . ' · ');
     if (Minz_Request::isPost()) {
         FreshRSS_LogDAO::truncate();
     }
     $logs = FreshRSS_LogDAO::lines();
     //TODO: ask only the necessary lines
     //gestion pagination
     $page = Minz_Request::param('page', 1);
     $this->view->logsPaginator = new Minz_Paginator($logs);
     $this->view->logsPaginator->_nbItemsPerPage(50);
     $this->view->logsPaginator->_currentPage($page);
 }
Exemplo n.º 11
0
 /**
  * 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()
 {
     $category_dao = FreshRSS_Factory::createCategoryDAO();
     $feed_dao = FreshRSS_Factory::createFeedDao();
     if (Minz_Request::isPost()) {
         $params = Minz_Request::param('queries', array());
         foreach ($params as $key => $query) {
             if (!$query['name']) {
                 $query['name'] = _t('conf.query.number', $key + 1);
             }
             $queries[] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
         }
         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->queries = array();
         foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
             $this->view->queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
         }
     }
     Minz_View::prependTitle(_t('conf.query.title') . ' · ');
 }
Exemplo n.º 12
0
 /**
  * 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);
 }
Exemplo n.º 13
0
 /**
  * This action displays information about installation.
  */
 public function checkInstallAction()
 {
     Minz_View::prependTitle(_t('admin.check_install.title') . ' · ');
     $this->view->status_php = check_install_php();
     $this->view->status_files = check_install_files();
     $this->view->status_database = check_install_database();
 }
Exemplo n.º 14
0
 public function init()
 {
     Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));
     Minz_View::appendScript($this->getFileUrl('script.js', 'js'));
 }
Exemplo n.º 15
0
 /**
  * Register the views in order to be accessible by the application.
  */
 public function registerViews()
 {
     Minz_View::addBasePathname($this->path);
 }
Exemplo n.º 16
0
 public static function appendTitle($title)
 {
     self::$title = self::$title . $title;
 }
Exemplo n.º 17
0
 private function loadNotifications()
 {
     $notif = Minz_Session::param('notification');
     if ($notif) {
         Minz_View::_param('notification', $notif);
         Minz_Session::_param('notification');
     }
 }
Exemplo n.º 18
0
 /**
  * This action displays the main page for import / export system.
  */
 public function indexAction()
 {
     $this->view->feeds = $this->feedDAO->listFeeds();
     Minz_View::prependTitle(_t('sub.import_export.title') . ' · ');
 }
Exemplo n.º 19
0
 public function logsAction()
 {
     if (!$this->view->loginOk) {
         Minz_Error::error(403, array('error' => array(Minz_Translate::t('access_denied'))));
     }
     Minz_View::prependTitle(Minz_Translate::t('logs') . ' · ');
     if (Minz_Request::isPost()) {
         FreshRSS_LogDAO::truncate();
     }
     $logs = FreshRSS_LogDAO::lines();
     //TODO: ask only the necessary lines
     //gestion pagination
     $page = Minz_Request::param('page', 1);
     $this->view->logsPaginator = new Minz_Paginator($logs);
     $this->view->logsPaginator->_nbItemsPerPage(50);
     $this->view->logsPaginator->_currentPage($page);
 }
Exemplo n.º 20
0
 /**
  * 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') . ' · ');
 }
Exemplo n.º 21
0
 /**
  * This action resets the authentication system.
  *
  * After reseting, form auth is set by default.
  */
 public function resetAction()
 {
     Minz_View::prependTitle(_t('admin.auth.title_reset') . ' · ');
     Minz_View::appendScript(Minz_Url::display('/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js')));
     $this->view->no_form = false;
     // Enable changement of auth only if Persona!
     if (FreshRSS_Context::$system_conf->auth_type != 'persona') {
         $this->view->message = array('status' => 'bad', 'title' => _t('gen.short.damn'), 'body' => _t('feedback.auth.not_persona'));
         $this->view->no_form = true;
         return;
     }
     $conf = get_user_configuration(FreshRSS_Context::$system_conf->default_user);
     if (is_null($conf)) {
         return;
     }
     // Admin user must have set its master password.
     if (!$conf->passwordHash) {
         $this->view->message = array('status' => 'bad', 'title' => _t('gen.short.damn'), 'body' => _t('feedback.auth.no_password_set'));
         $this->view->no_form = true;
         return;
     }
     invalidateHttpCache();
     if (Minz_Request::isPost()) {
         $nonce = Minz_Session::param('nonce');
         $username = Minz_Request::param('username', '');
         $challenge = Minz_Request::param('challenge', '');
         $ok = FreshRSS_FormAuth::checkCredentials($username, $conf->passwordHash, $nonce, $challenge);
         if ($ok) {
             FreshRSS_Context::$system_conf->auth_type = 'form';
             $ok = FreshRSS_Context::$system_conf->save();
             if ($ok) {
                 Minz_Request::good(_t('feedback.auth.form.set'));
             } else {
                 Minz_Request::bad(_t('feedback.auth.form.not_set'), array('c' => 'auth', 'a' => 'reset'));
             }
         } else {
             Minz_Log::warning('Password mismatch for' . ' user='******', nonce=' . $nonce . ', c=' . $challenge);
             Minz_Request::bad(_t('feedback.auth.login.invalid'), array('c' => 'auth', 'a' => 'reset'));
         }
     }
 }