/** * updates all sources * * @return void */ public function update() { $sourcesDao = new \daos\Sources(); foreach ($sourcesDao->getByLastUpdate() as $source) { $this->fetch($source); } $this->cleanup(); }
/** * home site * html * * @return void */ public function home() { // check login $this->authentication(); // parse params $options = array(); if (\F3::get('homepage') != '') { $options = array('type' => \F3::get('homepage')); } // use ajax given params? if (count($_GET) > 0) { $options = $_GET; } // get search param if (isset($options['search']) && strlen($options['search']) > 0) { $this->view->search = $options['search']; } // load tags $tagsDao = new \daos\Tags(); $tags = $tagsDao->getWithUnread(); // load items $itemsHtml = $this->loadItems($options, $tags); $this->view->content = $itemsHtml; // load stats $itemsDao = new \daos\Items(); $stats = $itemsDao->stats(); $this->view->statsAll = $stats['total']; $this->view->statsUnread = $stats['unread']; $this->view->statsStarred = $stats['starred']; if ($tagsDao->hasTag("#")) { foreach ($tags as $tag) { if (strcmp($tag["tag"], "#") !== 0) { continue; } $this->view->statsUnread -= $tag["unread"]; } } // prepare tags display list $tagsController = new \controllers\Tags(); $this->view->tags = $tagsController->renderTags($tags); if (isset($options['sourcesNav']) && $options['sourcesNav'] == 'true') { // prepare sources display list $sourcesDao = new \daos\Sources(); $sources = $sourcesDao->getWithUnread(); $sourcesController = new \controllers\Sources(); $this->view->sources = $sourcesController->renderSources($sources); } else { $this->view->sources = ''; } // ajax call = only send entries and statistics not full template if (isset($options['ajax'])) { $this->view->jsonSuccess(array("entries" => $this->view->content, "all" => $this->view->statsAll, "unread" => $this->view->statsUnread, "starred" => $this->view->statsStarred, "tags" => $this->view->tags, "sources" => $this->view->sources)); } // show as full html page $this->view->publicMode = \F3::get('auth')->isLoggedin() !== true && \F3::get('public') == 1; $this->view->loggedin = \F3::get('auth')->isLoggedin() === true; echo $this->view->render('templates/home.phtml'); }
/** * returns current basic stats * json * * @return void */ public function stats() { $this->needsLoggedInOrPublicMode(); $itemsDao = new \daos\Items(); $stats = $itemsDao->stats(); $stats['unread'] -= $itemsDao->numberOfUnreadForTag("#"); $tagsDao = new \daos\Tags(); $tags = $tagsDao->getWithUnread(); if ($tagsDao->hasTag("#")) { foreach ($tags as $tag) { if (strcmp($tag["tag"], "#") !== 0) { continue; } $stats['unread'] -= $tag["unread"]; } } if (array_key_exists('tags', $_GET) && $_GET['tags'] == 'true') { $tagsDao = new \daos\Tags(); $tagsController = new \controllers\Tags(); $stats['tagshtml'] = $tagsController->renderTags($tagsDao->getWithUnread()); } if (array_key_exists('sources', $_GET) && $_GET['sources'] == 'true') { $sourcesDao = new \daos\Sources(); $sourcesController = new \controllers\Sources(); $stats['sourceshtml'] = $sourcesController->renderSources($sourcesDao->getWithUnread()); } $this->view->jsonSuccess($stats); }
/** * returns current basic stats * json * * @return void */ public function stats() { $this->needsLoggedInOrPublicMode(); $itemsDao = new \daos\Items(); $stats = $itemsDao->stats(); if (array_key_exists('tags', $_GET) && $_GET['tags'] == 'true') { $tagsDao = new \daos\Tags(); $tagsController = new \controllers\Tags(); $stats['tagshtml'] = $tagsController->renderTags($tagsDao->getWithUnread()); } if (array_key_exists('sources', $_GET) && $_GET['sources'] == 'true') { $sourcesDao = new \daos\Sources(); $sourcesController = new \controllers\Sources(); $stats['sourceshtml'] = $sourcesController->renderSources($sourcesDao->getWithUnread()); } $this->view->jsonSuccess($stats); }
/** * returns all sources with unread items * json * * @return void */ public function stats() { $this->needsLoggedInOrPublicMode(); $itemDao = new \daos\Items(); // load sources $sourcesDao = new \daos\Sources(); $sources = $sourcesDao->getWithUnread(); $this->view->jsonSuccess($sources); }
/** * rss feed * * @return void */ public function rss() { $this->needsLoggedInOrPublicMode(); $feedWriter = new \RSS2FeedWriter(); $feedWriter->setTitle(\F3::get('rss_title')); $feedWriter->setLink($this->view->base); // get sources $sourceDao = new \daos\Sources(); $lastSourceId = 0; $lastSourceName = ""; // set options $options = array(); if (count($_GET) > 0) { $options = $_GET; } $options['items'] = \F3::get('rss_max_items'); if (\F3::get('PARAMS["tag"]') != null) { $options['tag'] = \F3::get('PARAMS["tag"]'); } if (\F3::get('PARAMS["type"]') != null) { $options['type'] = \F3::get('PARAMS["type"]'); } // get items $newestEntryDate = false; $lastid = -1; $itemDao = new \daos\Items(); foreach ($itemDao->get($options) as $item) { if ($newestEntryDate === false) { $newestEntryDate = $item['datetime']; } $newItem = $feedWriter->createNewItem(); // get Source Name if ($item['source'] != $lastSourceId) { foreach ($sourceDao->get() as $source) { if ($source['id'] == $item['source']) { $lastSourceId = $source['id']; $lastSourceName = $source['title']; break; } } } $newItem->setTitle(str_replace('&', '&', $this->UTF8entities($item['title'] . " (" . $lastSourceName . ")"))); @$newItem->setLink($item['link']); $newItem->setDate($item['datetime']); $newItem->setDescription(str_replace('"', '"', $item['content'])); // add tags in category node $itemsTags = explode(",", $item['tags']); foreach ($itemsTags as $tag) { $tag = trim($tag); if (strlen($tag) > 0) { $newItem->addElement('category', $tag); } } $feedWriter->addItem($newItem); $lastid = $item['id']; // mark as read if (\F3::get('rss_mark_as_read') == 1 && $lastid != -1) { $itemDao->mark($lastid); } } if ($newestEntryDate === false) { $newestEntryDate = date(\DATE_ATOM, time()); } $feedWriter->setChannelElement('updated', $newestEntryDate); $feedWriter->generateFeed(); }
/** * returns all sources with unread items * json * * @return void */ public function stats() { $itemDao = new \daos\Items(); // load sources $sourcesDao = new \daos\Sources(); $sources = $sourcesDao->get(); // get stats $result = array(); for ($i = 0; $i < count($sources); $i++) { $result[] = array('id' => $sources[$i]['id'], 'title' => $sources[$i]['title'], 'unread' => $itemDao->numberOfUnreadForSource($sources[$i]['id'])); } $this->view->jsonSuccess($result); }