/** * Save an entry * * @return void */ private function _save() { // Check for request forgeries Request::checkToken(); // Login check if (User::isGuest()) { return $this->_login(); } // Access check if (!$this->params->get('access-edit-item') || !$this->params->get('access-create-item')) { $this->setError(Lang::txt('PLG_GROUPS_' . strtoupper($this->_name) . '_NOT_AUTHORIZED')); return $this->_collections(); } // Incoming $fields = Request::getVar('fields', array(), 'post', 'none', 2); if ($fields['id'] && !is_numeric($fields['id'])) { App::abort(404, Lang::txt('Post does not exist')); } // Get model $row = new \Components\Collections\Models\Item(intval($fields['id'])); // Bind content if (!$row->bind($fields)) { $this->setError($row->getError()); return $this->_edit($row); } // Add some data if ($files = Request::getVar('fls', '', 'files', 'array')) { $row->set('_files', $files); } $row->set('_assets', Request::getVar('assets', null, 'post')); $row->set('_tags', trim(Request::getVar('tags', ''))); $row->set('state', 1); if (!$row->exists()) { $row->set('access', 0); } // Store new content if (!$row->store()) { $this->setError($row->getError()); return $this->_edit($row); } // Create a post entry linking the item to the board $p = Request::getVar('post', array(), 'post'); $post = new \Components\Collections\Models\Post($p['id']); if (!$post->exists()) { $post->set('item_id', $row->get('id')); $post->set('original', 1); } if (!isset($p['collection_id'])) { $p['collection_id'] = 0; if ($coltitle = Request::getVar('collection_title', '', 'post')) { $collection = new \Components\Collections\Models\Collection(); $collection->set('title', $coltitle); $collection->set('object_id', $this->group->get('gidNumber')); $collection->set('object_type', 'group'); $collection->set('access', $this->params->get('access-plugin')); $collection->store(); $p['collection_id'] = $collection->get('id'); } } $post->set('collection_id', $p['collection_id']); if (isset($p['description'])) { $post->set('description', $p['description']); } if (!$post->store()) { $this->setError($post->getError()); } // Check for any errors if ($this->getError()) { Request::setVar('post', $p['id']); return $this->_edit($post->item()->bind($fields)); } App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name . '&scope=' . $this->model->collection($p['collection_id'])->get('alias'))); }
/** * Save a comment * * @return string */ private function _savecomment() { // Check for request forgeries Request::checkToken(); // Ensure the user is logged in if (User::isGuest()) { return $this->_login(); } // Incoming $data = Request::getVar('comment', array(), 'post'); // Instantiate a new comment object and pass it the data $comment = \Hubzero\Item\Comment::oneOrNew($data['id'])->set($data); // Store new content if (!$comment->save()) { $this->setError($comment->getError()); return $this->_post(); } // Log activity $post = new \Components\Collections\Models\Post(Request::getInt('post', 0)); $recipients = array(['group', $this->group->get('gidNumber')], ['collection', $post->get('collection_id')], ['user', $comment->get('created_by')]); if ($comment->get('parent')) { $recipients[] = ['user', $comment->parent()->get('created_by')]; } foreach ($this->group->get('managers') as $recipient) { $recipients[] = ['user', $recipient]; } $title = $post->item()->get('title'); $title = $title ? $title : $post->item()->get('description', '#' . $post->get('id')); $title = \Hubzero\Utility\String::truncate(strip_tags($title), 70); $url = Route::url('index.php?option=com_collections&controller=posts&post=' . $post->get('id') . '&task=comment'); Event::trigger('system.logActivity', ['activity' => ['action' => $data['id'] ? 'updated' : 'created', 'scope' => 'collections.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('PLG_GROUPS_COLLECTIONS_ACTIVITY_COMMENT_' . ($data['id'] ? 'UPDATED' : 'CREATED'), $comment->get('id'), '<a href="' . $url . '#c' . $comment->get('id') . '">' . $title . '</a>'), 'details' => array('collection_id' => $post->get('collection_id'), 'post_id' => $post->get('id'), 'item_id' => $row->get('item_id'), 'url' => $url . '#c' . $comment->get('id'))], 'recipients' => $recipients]); return $this->_post(); }