/** * 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->get(); // load items $itemsHtml = $this->loadItems($options, $tags); $this->view->content = $itemsHtml; // load stats $itemsDao = new \daos\Items(); $this->view->statsAll = $itemsDao->numberOfItems(); $this->view->statsUnread = $itemsDao->numberOfUnread(); $this->view->statsStarred = $itemsDao->numberOfStarred(); // prepare tags display list $tagsController = new \controllers\Tags(); $this->view->tags = $tagsController->renderTags($tags); // prepare sources display list $sourcesDao = new \daos\Sources(); $sources = $sourcesDao->get(); $sourcesController = new \controllers\Sources(); $this->view->sources = $sourcesController->renderSources($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'); }
/** * render spouts params * json * * @return void */ public function write() { $this->needsLoggedIn(); $sourcesDao = new \daos\Sources(); // read data parse_str(\F3::get('BODY'), $data); if (!isset($data['title'])) { $this->view->jsonError(array('title' => 'no data for title given')); } if (!isset($data['spout'])) { $this->view->jsonError(array('spout' => 'no data for spout given')); } // clean up title and tag data to prevent XSS $title = htmlspecialchars($data['title']); $tags = htmlspecialchars($data['tags']); $spout = $data['spout']; $filter = $data['filter']; $isAjax = isset($data['ajax']); unset($data['title']); unset($data['spout']); unset($data['filter']); unset($data['tags']); unset($data['ajax']); $spout = str_replace("_", "\\", $spout); // check if source already exists $id = \F3::get('PARAMS["id"]'); $sourceExists = $sourcesDao->isValid('id', $id); // load password value if not changed for spouts containing passwords if ($sourceExists) { $spoutLoader = new \helpers\SpoutLoader(); $spoutInstance = $spoutLoader->get($spout); foreach ($spoutInstance->params as $spoutParamName => $spoutParam) { if ($spoutParam['type'] == 'password' && empty($data[$spoutParamName])) { if (!isset($oldSource)) { $oldSource = $sourcesDao->get($id); $oldParams = json_decode(html_entity_decode($oldSource['params']), true); } $data[$spoutParamName] = $oldParams[$spoutParamName]; } } } $validation = $sourcesDao->validate($title, $spout, $data); if ($validation !== true) { $this->view->error(json_encode($validation)); } // add/edit source if (!$sourceExists) { $id = $sourcesDao->add($title, $tags, $filter, $spout, $data); } else { $sourcesDao->edit($id, $title, $tags, $filter, $spout, $data); } // autocolor tags $tagsDao = new \daos\Tags(); $tags = explode(",", $tags); foreach ($tags as $tag) { $tagsDao->autocolorTag(trim($tag)); } // cleanup tags $tagsDao->cleanup($sourcesDao->getAllTags()); $return = array('success' => true, 'id' => $id); // only for selfoss ui (update stats in navigation) if ($isAjax) { // get new tag list with updated count values $tagController = new \controllers\Tags(); $return['tags'] = $tagController->tagsListAsString(); // get new sources list $sourcesController = new \controllers\Sources(); $return['sources'] = $sourcesController->sourcesListAsString(); } $this->view->jsonSuccess($return); }
/** * 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); }