/**
  * 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);
 }
示例#2
0
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') . ' · ');
 }
示例#4
0
 public function checkDefault()
 {
     $def_cat = $this->searchById(1);
     if ($def_cat == null) {
         $cat = new FreshRSS_Category(_t('gen.short.default_category'));
         $cat->_id(1);
         $values = array('id' => $cat->id(), 'name' => $cat->name());
         $this->addCategory($values);
     }
 }
示例#5
0
 public function test__construct_whenNoParameters_createsObjectWithDefaultValues()
 {
     $category = new FreshRSS_Category();
     $this->assertEquals(0, $category->id());
     $this->assertEquals('', $category->name());
 }
示例#6
0
 public function checkDefault()
 {
     $def_cat = $this->searchById(1);
     if ($def_cat === false) {
         $cat = new FreshRSS_Category(Minz_Translate::t('default_category'));
         $cat->_id(1);
         $values = array('id' => $cat->id(), 'name' => $cat->name());
         $this->addCategory($values);
     }
 }