/** * Load the View */ public function onLoad() { needRole(null, true); $p = $this->getParam("param"); $explodeParam = explode("-", $p); $pType = arrayValue($explodeParam, 0); $pVal = arrayValue($explodeParam, 1); $title = t("sidebar.10"); $categories = user()->getCategories(); $feeds = user()->getFeeds(); switch ($pType) { case "cat": if (isset($categories[$pVal])) { $this->category = $categories[$pVal]; $title = $this->category->name; $feeds = $this->category->feeds; if (isset($exp[1]) && isset($feeds[$exp[1]])) { $this->feed = $feeds[$exp[1]]; $title = $this->feed->name; } } break; case "feed": if (isset($feeds[$pVal])) { $this->feed = $feeds[$pVal]; $this->category = user()->getCategoryToFeed($this->feed); $title = $this->feed->getCustomName($this->category); } elseif (needRole(RDR_User::ROLE_ADMIN)) { $this->feed = RDR_Feed::getById($pVal); if ($this->feed) { $this->feed = $feeds[$pVal]; $title = $this->feed->name; } } break; case "search": $this->readedLayoutEnabled = false; $title = sprintf(t("feeds.1"), s(get("q"))); break; case "archive": $this->readedLayoutEnabled = false; $title = t("archive.title"); break; case "saved": $this->readedLayoutEnabled = false; $title = t("sidebar.11"); break; } if (req()->isAjax()) { # fetch all html to pass it to the json output ob_start(); if (!post("requestCounter")) { $hasUnreaded = false; $cache = session("entry.cache"); if (!$categories) { $ids = array(); } elseif ($pType == "search") { $feeds = user()->getFeeds(); $query = "\n SELECT t0.id\n FROM RDR_Entry as t0\n WHERE t0.feed IN " . db()->toDb($feeds) . " && t0.title LIKE " . db()->toDb("%" . get("q") . "%") . "\n ORDER BY datetime DESC\n "; $ids = db()->fetchColumn($query); } elseif ($pType == "archive") { $feeds = user()->getFeeds(); $condition = "1 "; if (get("from") && dt(get("from"))->valid) { $condition .= " && t0.datetime >= " . db()->toDb(dt(get("from"))->getSQLDate()); } if (get("to") && dt(get("to"))->valid) { $condition .= " && t0.datetime <= " . db()->toDb(dt(get("to"))->getSQLDate()); } $query = "\n SELECT t0.id\n FROM RDR_Entry as t0\n WHERE t0.feed IN " . db()->toDb($feeds) . " && {$condition}\n ORDER BY datetime DESC\n "; $ids = db()->fetchColumn($query); } elseif ($pType == "saved") { $ids = user()->saved; if ($ids) { $ids = array_keys($ids); } if (!$ids) { $ids = array(); } } else { $ids = array(); if ($cache) { user()->loadReadedFlags(array_keys($cache)); foreach ($cache as $id => $row) { # if already readed than hide the entry if (isset(user()->_cacheReaded[$id])) { continue; } # feed mode if ($this->feed) { if ($row["feed"] == $this->feed->getId()) { $ids[$id] = $id; } continue; } # category mode if ($this->category) { if ($row["category"] == $this->category->getId()) { $ids[$id] = $id; } continue; } # all mode $ids[$id] = $id; } } } # load readed flags only if required if ($this->readedLayoutEnabled) { user()->loadReadedFlags($ids); } # if view all and no article exist, update init entry to latest read id if ($pType == "all" && !$ids) { if ($feeds) { $id = db()->fetchOne("\n SELECT MAX(CAST(t0.k as signed))\n FROM RDR_User_readed as t0\n WHERE t0.o = " . user()->getId() . "\n "); user()->updateInitEntry($id); user()->updateNewsCache(); user()->readed = null; user()->store(); } } session("entry.ids", $ids); session("entry.ids.original", $ids); } $max = RDR_Entry::ENTRIES_PER_PAGE; $ids = session("entry.ids"); if (!$ids) { $ids = array(); } $entryIds = array_slice($ids, 0, $max); session("entry.ids", array_slice($ids, $max)); $entries = RDR_Entry::getByIds($entryIds, true); foreach ($entries as $entry) { $this->displayEntry($entry); } $c = count($entries); if ($c == $max) { ?> <div id="feed-view-trigger"></div> <?php } else { ?> <div class="feeds-footer"> <div style="display: none;"><input type="button" value="<?php echo t("mark.all.category"); ?> " class="btn" id="all-read-btn"/></div> <?php echo t("end.newssection.1"); ?> <br/> <div class="small"><?php echo t("end.newssection.2"); ?> </div> </div> <?php } $jsonData = user()->getAjaxData(); $jsonData["count"] = count(session("entry.ids.original")); if ($pType == "archive") { $jsonData["archive"] = count($ids); } $jsonData["content"] = ob_get_contents(); ob_end_clean(); echo json_encode($jsonData); return; } $this->parameters["title"] = $title; view("RDR_BasicFrame", array("view" => $this)); }