/** * 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 opml_import($xml) { $xml = html_only_entity_decode($xml); //!\ Assume UTF-8 $dom = new DOMDocument(); $dom->recover = true; $dom->strictErrorChecking = false; $dom->loadXML($xml); $dom->encoding = 'UTF-8'; $opml = simplexml_import_dom($dom); if (!$opml) { throw new FreshRSS_Opml_Exception(); } $catDAO = new FreshRSS_CategoryDAO(); $catDAO->checkDefault(); $defCat = $catDAO->getDefault(); $categories = array(); $feeds = array(); foreach ($opml->body->outline as $outline) { if (!isset($outline['xmlUrl'])) { // Catégorie $title = ''; if (isset($outline['text'])) { $title = (string) $outline['text']; } elseif (isset($outline['title'])) { $title = (string) $outline['title']; } if ($title) { // Permet d'éviter les soucis au niveau des id : // ceux-ci sont générés en fonction de la date, // un flux pourrait être dans une catégorie X avec l'id Y // alors qu'il existe déjà la catégorie X mais avec l'id Z // Y ne sera pas ajouté et le flux non plus vu que l'id // de sa catégorie n'exisera pas $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $catDAO = new FreshRSS_CategoryDAO(); $cat = $catDAO->searchByName($title); if ($cat === false) { $cat = new FreshRSS_Category($title); $values = array('name' => $cat->name()); $cat->_id($catDAO->addCategory($values)); } $feeds = array_merge($feeds, getFeedsOutline($outline, $cat->id())); } } else { // Flux rss sans catégorie, on récupère l'ajoute dans la catégorie par défaut $feeds[] = getFeed($outline, $defCat->id()); } } return array($categories, $feeds); }
public function categorizeAction() { $feedDAO = new FreshRSS_FeedDAO(); $catDAO = new FreshRSS_CategoryDAO(); $defaultCategory = $catDAO->getDefault(); $defaultId = $defaultCategory->id(); if (Minz_Request::isPost()) { $cats = Minz_Request::param('categories', array()); $ids = Minz_Request::param('ids', array()); $newCat = trim(Minz_Request::param('new_category', '')); foreach ($cats as $key => $name) { if (strlen($name) > 0) { $cat = new FreshRSS_Category($name); $values = array('name' => $cat->name()); $catDAO->updateCategory($ids[$key], $values); } elseif ($ids[$key] != $defaultId) { $feedDAO->changeCategory($ids[$key], $defaultId); $catDAO->deleteCategory($ids[$key]); } } if ($newCat != '') { $cat = new FreshRSS_Category($newCat); $values = array('id' => $cat->id(), 'name' => $cat->name()); if ($catDAO->searchByName($newCat) == false) { $catDAO->addCategory($values); } } invalidateHttpCache(); $notif = array('type' => 'good', 'content' => Minz_Translate::t('categories_updated')); Minz_Session::_param('notification', $notif); Minz_Request::forward(array('c' => 'configure', 'a' => 'categorize'), true); } $this->view->categories = $catDAO->listCategories(false); $this->view->defaultCategory = $catDAO->getDefault(); $this->view->feeds = $feedDAO->listFeeds(); $this->view->flux = false; Minz_View::prependTitle(Minz_Translate::t('categories_management') . ' · '); }
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 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 = new FreshRSS_CategoryDAO(); $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); }
/** * 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 = new FreshRSS_CategoryDAO(); $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); } }