Esempio n. 1
0
 /**
  * mark items as read. Allows one id or an array of ids
  * json
  *
  * @return void
  */
 public function mark()
 {
     if (\F3::get('PARAMS["item"]') != null) {
         $lastid = \F3::get('PARAMS["item"]');
     } else {
         if (isset($_POST['ids'])) {
             $lastid = $_POST['ids'];
         }
     }
     $itemDao = new \daos\Items();
     // validate id or ids
     if (!$itemDao->isValid('id', $lastid)) {
         $this->view->error('invalid id');
     }
     $itemDao->mark($lastid);
     $return = array('success' => true);
     // only for selfoss ui on mark all as read (update stats in navigation)
     if (isset($_POST['ajax'])) {
         // 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);
 }
Esempio n. 2
0
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * render spouts params
  * json
  *
  * @return void
  */
 public function write()
 {
     $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'];
     $isAjax = isset($data['ajax']);
     unset($data['title']);
     unset($data['spout']);
     unset($data['tags']);
     unset($data['ajax']);
     $spout = str_replace("_", "\\", $spout);
     $validation = $sourcesDao->validate($title, $spout, $data);
     if ($validation !== true) {
         $this->view->error(json_encode($validation));
     }
     // add/edit source
     $id = \F3::get('PARAMS["id"]');
     if (!$sourcesDao->isValid('id', $id)) {
         $id = $sourcesDao->add($title, $tags, $spout, $data);
     } else {
         $sourcesDao->edit($id, $title, $tags, $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);
 }