Exemplo n.º 1
0
 /**
  * Delete the feed
  */
 public function delete()
 {
     if (!$this->getId()) {
         return;
     }
     db()->deleteMultiple(RDR_Entry::getByCondition("feed = {0}", array($this)));
     $cats = RDR_Category::getByQuery("\n            SELECT o FROM RDR_Category_feeds\n            WHERE k = " . $this->getId() . "\n        ");
     foreach ($cats as $category) {
         $feeds = $category->feeds;
         if ($feeds) {
             foreach ($feeds as $key => $feed) {
                 if (compare($this, $feed)) {
                     unset($feeds[$key]);
                 }
                 if (count($feeds) != count($category->feeds)) {
                     $category->store();
                 }
             }
         }
     }
     parent::delete();
     RDR_Cleanup::cleanupFlags();
 }
Exemplo n.º 2
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(null, true);
     # OPML
     if (get("opml")) {
         $categories = user()->getCategories();
         $opml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><opml></opml>');
         $opml->addAttribute("version", "1.0");
         $head = $opml->addChild("head");
         $head->addChild("title", "Subscriptions from nReeda");
         $body = $opml->addChild("body");
         foreach ($categories as $category) {
             $cat = $body->addChild("outline");
             $cat->addAttribute("title", $category->name);
             $cat->addAttribute("text", $category->name);
             $feeds = $category->feeds;
             if ($feeds) {
                 foreach ($feeds as $feed) {
                     $f = $cat->addChild("outline");
                     $f->addAttribute("type", "rss");
                     $f->addAttribute("text", $feed->getCustomName($category));
                     $f->addAttribute("title", $feed->getCustomName($category));
                     $f->addAttribute("xmlUrl", $feed->url);
                 }
             }
         }
         $data = $opml->asXML();
         CHOQ_OutputManager::cleanAllBuffers();
         header("Content-type: application/octet-stream");
         header("Content-Disposition: filename=\"nreeda.opml\"");
         echo $data;
         die;
     }
     # textfile
     if (get("file")) {
         $categories = user()->getCategories();
         $lines = array();
         foreach ($categories as $category) {
             $feeds = $category->feeds;
             if ($feeds) {
                 foreach ($feeds as $feed) {
                     $lines[] = $feed->url;
                 }
             }
         }
         $data = implode("\n", $lines);
         CHOQ_OutputManager::cleanAllBuffers();
         header("Content-type: application/octet-stream");
         header("Content-Disposition: filename=\"nreeda.txt\"");
         echo $data;
         die;
     }
     # Import
     if (isset($_FILES["file"]["tmp_name"])) {
         $data = file_get_contents($_FILES["file"]["tmp_name"]);
         if (strpos($data, "<?xml") === false || strpos($data, "</opml>") === false) {
             $event = RDR_Import::importFromFile($_FILES["file"]["tmp_name"]);
             if ($event->type == RDR_Event::TYPE_FILE_OK) {
                 RDR_Import::updateAllFeeds();
             }
             v("message", $event->getText());
         } else {
             $event = RDR_Import::importFromOPML($_FILES["file"]["tmp_name"]);
             if ($event->type == RDR_Event::TYPE_OPML_OK) {
                 RDR_Import::updateAllFeeds();
             }
             v("message", $event->getText());
         }
     }
     if (post("new") && trim(post("val"))) {
         RDR_Category::get(post("val"));
         redirect(url()->getUri(), 302);
     }
     if (req()->isAjax()) {
         $categories = user()->getCategories();
         $feeds = user()->getFeeds();
         if (post("action") == "edit" && post("val")) {
             if (isset($categories[post("category")])) {
                 $category = $categories[post("category")];
                 if (post("feed")) {
                     $feed = arrayValue($feeds, post("feed"));
                     if ($feed) {
                         $feed->setCustomName($category, post("val"));
                         $category->store();
                     }
                 } else {
                     $category->name = post("val");
                     $category->store();
                 }
             }
         }
         if (post("action") == "move") {
             if (isset($categories[post("categoryOld")])) {
                 $categoryOld = $categories[post("categoryOld")];
                 $categoryNew = $categories[post("categoryNew")];
                 if (post("feed")) {
                     $feed = arrayValue($feeds, post("feed"));
                     if ($feed) {
                         $name = $feed->getCustomName($categoryOld);
                         $categoryOld->remove("feedsData", $feed->getId() . "-name");
                         $categoryOld->remove("feeds", $feed->getId());
                         $categoryOld->store();
                         $feed->setCustomName($categoryNew, $name);
                         $categoryNew->add("feeds", $feed);
                         $categoryNew->store();
                     }
                 }
             }
         }
         if (post("action") == "delete") {
             if (isset($categories[post("category")])) {
                 $category = $categories[post("category")];
                 if (post("feed")) {
                     $feed = arrayValue($feeds, post("feed"));
                     if ($feed) {
                         $category->remove("feedsData", $feed->getId() . "-name");
                         $category->remove("feeds", $feed);
                         $category->store();
                     }
                 } else {
                     $category->delete();
                 }
             }
         }
         RDR_Cleanup::cleanupFeeds();
         RDR_Cleanup::cleanupFlags();
         user()->updateNewsCache();
         return;
     }
     view("RDR_BasicFrame", array("view" => $this));
 }