Exemplo n.º 1
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask();
         return;
     }
     Request::checkToken();
     // get the posted vars
     $id = Request::getInt('id', 0, 'post');
     $c = Request::getVar('fields', array(), 'post');
     $c['id'] = $id;
     // clean vars
     foreach ($c as $key => $val) {
         if (!is_array($val)) {
             $val = html_entity_decode(urldecode($val));
             $val = Sanitize::stripAll($val);
             $c[$key] = Sanitize::clean($val);
         }
     }
     // Bind incoming data to object
     $row = new Citation($this->database);
     if (!$row->bind($c)) {
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // New entry so set the created date
     if (!$row->id) {
         $row->created = Date::toSql();
     }
     if (!filter_var($row->url, FILTER_VALIDATE_URL)) {
         $row->url = null;
     }
     // Check content for missing required data
     if (!$row->check()) {
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Incoming associations
     $arr = Request::getVar('assocs', array(), 'post');
     $ignored = array();
     foreach ($arr as $a) {
         $a = array_map('trim', $a);
         // Initiate extended database class
         $assoc = new Association($this->database);
         //check to see if we should delete
         if (isset($a['id']) && $a['tbl'] == '' && $a['oid'] == '') {
             // Delete the row
             if (!$assoc->delete($a['id'])) {
                 $this->setError($assoc->getError());
                 $this->editTask();
                 return;
             }
         } else {
             if ($a['tbl'] != '' || $a['oid'] != '') {
                 $a['cid'] = $row->id;
                 // bind the data
                 if (!$assoc->bind($a)) {
                     $this->setError($assoc->getError());
                     $this->editTask();
                     return;
                 }
                 // Check content
                 if (!$assoc->check()) {
                     $this->setError($assoc->getError());
                     $this->editTask();
                     return;
                 }
                 // Store new content
                 if (!$assoc->store()) {
                     $this->setError($assoc->getError());
                     $this->editTask();
                     return;
                 }
             }
         }
     }
     //check if we are allowing tags
     if ($this->config->get('citation_allow_tags', 'no') == 'yes') {
         $tags = trim(Request::getVar('tags', '', 'post'));
         $ct1 = new Tags($row->id);
         $ct1->setTags($tags, User::get('id'), 0, 1, '');
     }
     //check if we are allowing badges
     if ($this->config->get('citation_allow_badges', 'no') == 'yes') {
         $badges = trim(Request::getVar('badges', '', 'post'));
         $ct2 = new Tags($row->id);
         $ct2->setTags($badges, User::get('id'), 0, 1, 'badge');
     }
     // Redirect
     $task = '&task=browse';
     if ($this->config->get('citation_single_view', 1)) {
         $task = '&task=view&id=' . $row->id;
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . $task), Lang::txt('COM_CITATIONS_CITATION_SAVED'));
 }
Exemplo n.º 2
0
 /**
  * Save a citation
  *
  * @return	void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $citation = array_map('trim', Request::getVar('citation', array(), 'post'));
     $exclude = Request::getVar('exclude', '', 'post');
     $rollover = Request::getInt("rollover", 0);
     $this->tags = Request::getVar('tags', '');
     $this->badges = Request::getVar('badges', '');
     $this->sponsors = Request::getVar('sponsors', array(), 'post');
     // toggle the affiliation
     if (!isset($citation['affiliated']) || $citation['affiliated'] == NULL) {
         $citation['affiliated'] = 0;
     }
     // toggle fundeby
     if (!isset($citation['fundedby']) || $citation['fundedby'] == NULL) {
         $citation['fundedby'] = 0;
     }
     // Bind incoming data to object
     $row = new Citation($this->database);
     if (!$row->bind($citation)) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     //set params
     $cparams = new Registry($this->_getParams($row->id));
     $cparams->set('exclude', $exclude);
     $cparams->set('rollover', $rollover);
     $row->params = $cparams->toString();
     // New entry so set the created date
     if (!$row->id) {
         $row->created = \Date::toSql();
     }
     // Check content for missing required data
     if (!$row->check()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Incoming associations
     $arr = Request::getVar('assocs', array(), 'post');
     $ignored = array();
     foreach ($arr as $a) {
         $a = array_map('trim', $a);
         // Initiate extended database class
         $assoc = new Association($this->database);
         //check to see if we should delete
         if (isset($a['id']) && $a['tbl'] == '' && $a['oid'] == '') {
             // Delete the row
             if (!$assoc->delete($a['id'])) {
                 throw new Exception($assoc->getError(), 500);
             }
         } else {
             if ($a['tbl'] != '' || $a['oid'] != '') {
                 $a['cid'] = $row->id;
                 // bind the data
                 if (!$assoc->bind($a)) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Check content
                 if (!$assoc->check()) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Store new content
                 if (!$assoc->store()) {
                     throw new Exception($assoc->getError(), 500);
                 }
             }
         }
     }
     //save sponsors on citation
     if ($this->sponsors) {
         $cs = new Sponsor($this->database);
         $cs->addSponsors($row->id, $this->sponsors);
     }
     //add tags & badges
     $ct = new Tags($row->id);
     $ct->setTags($this->tags, User::get('id'), 0, 1, '');
     $ct->setTags($this->badges, User::get('id'), 0, 1, 'badge');
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_SAVED'));
 }