/** * Get a instance for a unique id and feed * * @param RDR_Feed $feed * @param mixed $uniqueId * @return self */ static function get(RDR_Feed $feed, $uniqueId) { $uniqueId = $feed->getId() . "-" . md5($uniqueId); $object = RDR_Entry::getByCondition("uniqueId = {1}", array($feed, $uniqueId)); if ($object) { return reset($object); } $object = new self(db()); $object->feed = $feed; $object->uniqueId = $uniqueId; return $object; }
/** * Old entries will be deleted automatically with this cleanup */ static function cleanupEntries() { $time = RDR_Setting::get("maxentrylifetime")->value; if (!$time) { return; } $updated = false; while (true) { $tmp = RDR_Entry::getByCondition("datetime < {0}", array(dt("now {$time}")), null, 1000); if (!$tmp) { break; } db()->deleteMultiple($tmp); $updated = true; } # after deleting some entries update readed/saved flags if ($updated) { self::cleanupFlags(); } }
/** * 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(); }
/** * 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)); }