/** * 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)); }
/** * Exception Handler * * @param Exception $exception */ static function exceptionHandler($exception) { if (!self::$customHandler) { throw $exception; } if (self::$cleanBufferBeforeOutput) { CHOQ_OutputManager::cleanAllBuffers(); } self::setHeader($exception->getCode() ? $exception->getCode() : 500, $exception->getMessage()); if (method_exists($exception, "getHtml")) { $exception->getHtml(); } else { echo '<pre style="overflow-x:auto; overflow-y:auto; font-family:courier new; font-size:13px; line-height: 17px; background:white; margin:5px; padding:5px; border-left:5px solid red; color:black;">'; echo '<h3 style="color:red; font-family:arial; padding:0px; margin:0px; margin-bottom:10px;">' . nl2br(s($exception->getMessage())) . '</h3>'; if (CHOQ::isMode(CHOQ::MODE_DEV)) { echo s(str_replace(CHOQ_ROOT_DIRECTORY, ".", $exception->getTraceAsString())); } echo '</pre>'; } if (self::$errorLog) { $dir = CHOQ_ACTIVE_MODULE_DIRECTORY . DS . "logs"; if (is_dir($dir) && is_writable($dir)) { $count = 0; $fileBase = $dir . DS . "error.log"; $filePHP = $fileBase . ".php"; if (file_exists($filePHP) && filesize($filePHP) > 1024 * 1024 * 20) { rename($filePHP, $fileBase . "." . time() . ".php"); } if (!file_exists($filePHP)) { file_put_contents($filePHP, "<?php\nif(!defined(\"CHOQ\")) die();\n?>\n\n"); } $message = "[" . date("d.m.Y H:i:s") . "] " . $exception->getMessage() . "\n"; $message .= $exception->getTraceAsString() . "\n===============\n"; file_put_contents($filePHP, $message, FILE_APPEND); } } die; }
/** * Load the View */ public function onLoad() { needRole(null, true); if (get("token")) { $token = explode(".", get("token")); if (count($token) == 2 && saltedHash("sha256", $token[0]) == $token[1]) { session("user.id", $token[0]); if (user()) { $max = min(array(200, (int) get("max"))); $catmax = get("catmax") ? min(array($max, (int) get("catmax"))) : $max; $feedmax = get("feedmax") ? min(array($max, (int) get("feedmax"))) : $max; $feedIds = explode(",", get("f")); $rss = new SimpleXMLElement('<' . '?xml version="1.0" encoding="utf-8"?><rss></rss>'); $rss->addAttribute("version", "2.0"); $channel = $rss->addChild("channel"); $channel->addChild("title", get("title")); $channel->addChild("description", get("desc")); $channel->addChild("pubDate", dt("now")->format("r")); $feeds = user()->getFeeds(); $catCount = $feedCount = array(); $count = 0; $allEntries = array(); $offset = 0; $limit = 50; while (true) { if (!$feeds) { break; } $entries = RDR_Entry::getByCondition("feed IN {0} && id > {1}", array($feeds, (int) user()->setting("init.entry")), array("-datetime", "-id"), $limit, $offset); $offset += $limit; if (!$entries) { break; } user()->loadReadedFlags(array_keys($entries)); foreach ($entries as $entry) { if (isset(user()->_cacheReaded[$entry->getId()])) { continue; } if ($count >= $max) { break 2; } $feed = $entry->feed; $category = user()->getCategoryToFeed($feed); $feedId = $feed->getId(); $catId = $category->getId(); if (!isset($catCount[$catId])) { $catCount[$catId] = 0; } if (!isset($feedCount[$feedId])) { $feedCount[$feedId] = 0; } if ($feedCount[$feedId] >= $feedmax) { if (isset($feeds[$feedId])) { unset($feeds[$feedId]); } continue; } if ($catCount[$catId] >= $catmax) { continue; } $entry->category = $category; $entry->time = $entry->datetime->getUnixtime(); $allEntries[] = $entry; $feedCount[$feedId]++; $catCount[$catId]++; $count++; } } foreach ($allEntries as $entry) { $feed = $entry->feed; $category = $entry->category; $item = $channel->addChild("item"); $this->addCData($item->addChild("title"), $entry->title); $this->addCData($item->addChild("link"), $entry->link); $this->addCData($item->addChild("description"), $entry->text); $this->addCData($item->addChild("category"), $category->name); $item->addChild("guid", $entry->getId()); $item->addChild("pubDate", $entry->datetime->format("r")); } $data = $rss->asXML(); CHOQ_OutputManager::cleanAllBuffers(); header("Content-type: application/rss+xml"); echo $data; die; } } } view("RDR_BasicFrame", array("view" => $this)); }