Ejemplo n.º 1
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!inNormalMode()) {
         return;
     }
     # set time limit to max 10 minutes
     # if this limit is reached than the script stops and continue at next cron
     set_time_limit(RDR_Cron::MAXTIME);
     $cronPidFile = self::getPIDFile();
     # skip when cron is already running
     if (self::isRunning()) {
         RDR_Event::log(RDR_Event::TYPE_CRON_RUNNING);
         return;
     }
     # create a tmp file that show us the cron pid
     file_put_contents($cronPidFile, time());
     $param = $this->getParam("param");
     if ($param != self::getHash()) {
         die("Not allowed");
     }
     RDR_Event::log(RDR_Event::TYPE_CRON_START);
     RDR_Import::updateAllFeeds();
     RDR_Event::log(RDR_Event::TYPE_CRON_END);
     RDR_Cleanup::cleanupEvents();
     RDR_Cleanup::cleanupEntries();
     RDR_FileContents::cleanupTmpFiles();
     RDR_Proxy::cleanupTmpFiles();
     # optimizing tables
     $generator = CHOQ_DB_Generator::create(db());
     if ($generator instanceof CHOQ_DB_Generator_Mysql) {
         $generator->addModule("RDR");
         $generator->optimizeTables();
     }
     # delete tmp file that show us the cron pid
     unlink(CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/cron.pid");
 }
Ejemplo 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));
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 /**
  * Delete
  */
 public function delete()
 {
     parent::delete();
     RDR_Cleanup::cleanupFeeds();
 }