Пример #1
0
 /**
  * Display a list of blog entries
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('entry_id' => Request::getState($this->_option . '.' . $this->_controller . '.entry_id', 'entry_id', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     $entry = Entry::oneOrFail($filters['entry_id']);
     $comments = Comment::all();
     if ($filters['search']) {
         $comments->whereLike('title', strtolower((string) $filters['search']));
     }
     if ($filters['entry_id']) {
         $comments->whereEquals('entry_id', $filters['entry_id']);
     }
     $rows = $comments->ordered('filter_order', 'filter_order_Dir')->rows();
     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
     $list = array();
     $children = array();
     if ($rows) {
         // First pass - collect children
         foreach ($rows as $k) {
             $pt = $k->get('parent');
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $k);
             $children[$pt] = $list;
         }
         // Second pass - get an indent list of the items
         $list = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('entry', $entry)->set('total', count($list))->set('rows', array_slice($list, $filters['start'], $filters['limit']))->display();
 }
Пример #2
0
 /**
  * Retrieves a row from the database
  *
  * @param      string $refid    ID of the database table row
  * @param      string $category Element type (determines table to look in)
  * @param      string $parent   If the element has a parent element
  * @return     array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $query = "SELECT rc.id, rc.entry_id, rc.content as `text`, rc.created_by as author, rc.created, NULL as subject, rc.anonymous as anon, 'blog' AS parent_category\n\t\t\t\t\tFROM `#__blog_comments` AS rc\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         foreach ($rows as $key => $row) {
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             $entry = \Components\Blog\Models\Entry::oneOrFail($rows[$key]->entry_id);
             $rows[$key]->text = strip_tags($rows[$key]->text);
             $rows[$key]->href = Route::url($entry->link() . '#c' . $rows[$key]->id);
         }
     }
     return $rows;
 }
Пример #3
0
 /**
  * Delete a comment
  *
  * @return  void
  */
 public function deletecommentTask()
 {
     // Ensure the user is logged in
     if (User::isGuest()) {
         $this->setError(Lang::txt('COM_BLOG_LOGIN_NOTICE'));
         return $this->entryTask();
     }
     // Incoming
     $id = Request::getInt('comment', 0);
     $year = Request::getVar('year', '');
     $month = Request::getVar('month', '');
     $alias = Request::getVar('alias', '');
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&year=' . $year . '&month=' . $month . '&alias=' . $alias, false));
         return;
     }
     // Initiate a blog comment object
     $comment = Comment::oneOrFail($id);
     if (User::get('id') != $comment->get('created_by') && !$this->config->get('access-delete-comment')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&year=' . $year . '&month=' . $month . '&alias=' . $alias, false));
         return;
     }
     // Mark all comments as deleted
     $comment->set('state', Comment::STATE_DELETED);
     $comment->save();
     // Log the activity
     $entry = \Components\Blog\Models\Entry::oneOrFail($comment->get('entry_id'));
     $recipients = array($comment->get('created_by'));
     if ($comment->get('created_by') != $entry->get('created_by')) {
         $recipients[] = $entry->get('created_by');
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'blog.entry.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('COM_BLOG_ACTIVITY_COMMENT_DELETED', $comment->get('id'), '<a href="' . Route::url($entry->link()) . '">' . $entry->get('title') . '</a>'), 'details' => array('title' => $entry->get('title'), 'entry_id' => $entry->get('id'), 'url' => $entry->link())], 'recipients' => $recipients]);
     // Return the topics list
     App::redirect(Route::url('index.php?option=' . $this->_option . '&year=' . $year . '&month=' . $month . '&alias=' . $alias), $this->getError() ? $this->getError() : null, $this->getError() ? 'error' : null);
 }
Пример #4
0
 /**
  * Delete a comment
  *
  * @return     string
  */
 private function _deletecomment()
 {
     // Ensure the user is logged in
     if (User::isGuest()) {
         $this->setError(Lang::txt('GROUPS_LOGIN_NOTICE'));
         return;
     }
     // Incoming
     $id = Request::getInt('comment', 0);
     if (!$id) {
         return $this->_entry();
     }
     // Initiate a blog comment object
     $comment = \Components\Blog\Models\Comment::oneOrFail($id);
     // Delete all comments on an entry
     $comment->set('state', $comment::STATE_DELETED);
     // Delete the entry itself
     if (!$comment->save()) {
         $this->setError($comment->getError());
     }
     // Record the activity
     $recipients = array(['group', $this->group->get('gidNumber')]);
     if (!in_array($comment->get('created_by'), $this->group->get('managers'))) {
         $recipients[] = ['user', $comment->get('created_by')];
     }
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     $entry = \Components\Blog\Models\Entry::oneOrFail($comment->get('entry_id'));
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'blog.entry.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('PLG_GROUPS_BLOG_ACTIVITY_COMMENT_DELETED', $comment->get('id'), '<a href="' . Route::url($entry->link()) . '">' . $entry->get('title') . '</a>'), 'details' => array('title' => $entry->get('title'), 'entry_id' => $entry->get('id'), 'url' => $entry->link())], 'recipients' => $recipients]);
     // Return the topics list
     return $this->_entry();
 }
Пример #5
0
 /**
  * Mark an entry as deleted
  *
  * @return  void
  */
 public function deleteTask()
 {
     if (User::isGuest()) {
         $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option, false, true), 'server');
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('COM_BLOG_LOGIN_NOTICE'), 'warning');
         return;
     }
     if (!$this->config->get('access-delete-entry')) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_BLOG_NOT_AUTHORIZED'), 'error');
         return;
     }
     // Incoming
     $id = Request::getInt('entry', 0);
     if (!$id) {
         return $this->displayTask();
     }
     $process = Request::getVar('process', '');
     $confirmdel = Request::getVar('confirmdel', '');
     // Initiate a blog entry object
     $entry = Entry::oneOrFail($id);
     // Did they confirm delete?
     if (!$process || !$confirmdel) {
         if ($process && !$confirmdel) {
             $this->setError(Lang::txt('COM_BLOG_ERROR_CONFIRM_DELETION'));
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->set('archive', $this->model)->set('config', $this->config)->set('entry', $entry)->display();
         return;
     }
     // Check for request forgeries
     Request::checkToken();
     // Delete the entry itself
     $entry->set('state', 2);
     if (!$entry->save()) {
         Notify::error($entry->getError());
     }
     // Return the topics list
     App::redirect(Route::url('index.php?option=' . $this->_option));
     return;
 }
Пример #6
0
 /**
  * Update an entry
  *
  * @apiMethod PUT
  * @apiUri    /blog/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Blog entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "content",
  * 		"description": "Entry content",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "created",
  * 		"description": "Created timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "created_by",
  * 		"description": "User ID of entry creator",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "Published state (0 = unpublished, 1 = published)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "access",
  * 		"description": "Access level (0 = public, 1 = registered users, 4 = private)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "allow_comments",
  * 		"description": "Allow comments on the entry?",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     1
  * }
  * @apiParameter {
  * 		"name":        "publish_up",
  * 		"description": "Publish start timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "publish_down",
  * 		"description": "Publish end timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "hits",
  * 		"description": "Record hits",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "tags",
  * 		"description": "Comma-separated list of tags",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return    void
  */
 public function updateTask()
 {
     $this->requiresAuthentication();
     $fields = array('id' => Request::getInt('id', 0, 'post'), 'scope' => Request::getVar('scope', '', 'post'), 'scope_id' => Request::getInt('scope_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'alias' => Request::getVar('alias', 0, 'post'), 'content' => Request::getVar('content', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 0, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'allow_comments' => Request::getInt('allow_comments', 0, 'post'), 'publish_up' => Request::getVar('publish_up', null, 'post'), 'publish_down' => Request::getVar('publish_down', null, 'post'), 'hits' => Request::getInt('hits', 0, 'post'), 'tags' => Request::getVar('tags', null, 'post'));
     $row = Entry::oneOrFail($fields['id']);
     if ($row->isNew()) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_RECORD'), 404);
     }
     if (!$row->set($fields)) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_BINDING_DATA'), 422);
     }
     $row->set('email', isset($fields['email']) ? 1 : 0);
     $row->set('anonymous', isset($fields['anonymous']) ? 1 : 0);
     if (!$row->save()) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_DATA'), 500);
     }
     if (isset($fields['tags'])) {
         if (!$row->tag($fields['tags'], User::get('id'))) {
             throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_TAGS'), 500);
         }
     }
     $this->send($row->toObject());
 }
Пример #7
0
 /**
  * Turn comments on/off
  *
  * @return  void
  */
 public function setcommentsTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     $state = Request::getInt('state', 0);
     // Check for a resource
     if (count($ids) < 1) {
         Notify::warning(Lang::txt('COM_BLOG_SELECT_ENTRY_TO_COMMENTS', $this->_task));
         return $this->cancelTask();
     }
     // Loop through all the IDs
     $success = 0;
     foreach ($ids as $id) {
         // Load the article
         $row = Entry::oneOrFail(intval($id));
         $row->set('allow_comments', $state);
         // Store new content
         if (!$row->save()) {
             Notify::error($row->getError());
             continue;
         }
         $success++;
     }
     if ($success) {
         $message = $state ? Lang::txt('COM_BLOG_ITEMS_COMMENTS_ENABLED', $success) : Lang::txt('COM_BLOG_ITEMS_COMMENTS_DISABLED', $success);
         Notify::success($message);
     }
     // Set the redirect
     $this->cancelTask();
 }
Пример #8
0
 /**
  * Create an item entry
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $post = null;
     if (!$id) {
         $alias = Request::getVar('alias', '');
         $post = Entry::oneByScope($alias, 'site', 0);
         $id = $post->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$post) {
         $post = Entry::oneOrFail($id);
     }
     if (!$post->get('id')) {
         $this->setError(Lang::txt('Blog post not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $post->get('id'))->set('created', $post->get('created'))->set('created_by', $post->get('created_by'))->set('title', $post->get('title'))->set('description', \Hubzero\Utility\String::truncate(strip_tags($post->content()), 200))->set('url', Route::url($post->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Пример #9
0
 /**
  * Update an entry
  *
  * @apiMethod PUT
  * @apiUri    /blog/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Blog entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "content",
  * 		"description": "Entry content",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "created",
  * 		"description": "Created timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "created_by",
  * 		"description": "User ID of entry creator",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "Published state (0 = unpublished, 1 = published)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "access",
  * 		"description": "Access level (0 = public, 1 = registered users, 4 = private)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "allow_comments",
  * 		"description": "Allow comments on the entry?",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     1
  * }
  * @apiParameter {
  * 		"name":        "publish_up",
  * 		"description": "Publish start timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "publish_down",
  * 		"description": "Publish end timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "hits",
  * 		"description": "Record hits",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "tags",
  * 		"description": "Comma-separated list of tags",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return    void
  */
 public function updateTask()
 {
     $this->requiresAuthentication();
     $fields = array('id' => Request::getInt('id', 0, 'post'), 'scope' => Request::getVar('scope', '', 'post'), 'scope_id' => Request::getInt('scope_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'alias' => Request::getVar('alias', 0, 'post'), 'content' => Request::getVar('content', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 0, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'allow_comments' => Request::getInt('allow_comments', 0, 'post'), 'publish_up' => Request::getVar('publish_up', null, 'post'), 'publish_down' => Request::getVar('publish_down', null, 'post'), 'hits' => Request::getInt('hits', 0, 'post'), 'tags' => Request::getVar('tags', null, 'post'));
     $row = Entry::oneOrFail($fields['id']);
     if ($row->isNew()) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_RECORD'), 404);
     }
     if (!$row->set($fields)) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_BINDING_DATA'), 422);
     }
     $row->set('email', isset($fields['email']) ? 1 : 0);
     $row->set('anonymous', isset($fields['anonymous']) ? 1 : 0);
     if (!$row->save()) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_DATA'), 500);
     }
     if (isset($fields['tags'])) {
         if (!$row->tag($fields['tags'], User::get('id'))) {
             throw new Exception(Lang::txt('COM_BLOG_ERROR_SAVING_TAGS'), 500);
         }
     }
     $row->set('created', with(new Date($row->get('created')))->format('Y-m-d\\TH:i:s\\Z'));
     $row->set('publish_up', with(new Date($row->get('publish_up')))->format('Y-m-d\\TH:i:s\\Z'));
     if ($row->get('publish_down') && $row->get('publish_down') != '0000-00-00 00:00:00') {
         $row->set('publish_down', with(new Date($row->get('publish_down')))->format('Y-m-d\\TH:i:s\\Z'));
     }
     // Log activity
     $base = rtrim(Request::base(), '/');
     $url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/'));
     Event::trigger('system.logActivity', ['activity' => ['action' => 'updated', 'scope' => 'blog.entry', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_BLOG_ACTIVITY_ENTRY_UPDATED', '<a href="' . $url . '">' . $row->get('title') . '</a>'), 'details' => array('title' => $row->get('title'), 'url' => $url)], 'recipients' => [$row->get('created_by')]]);
     $this->send($row->toObject());
 }
Пример #10
0
 /**
  * Delete an entry
  *
  * @return     string
  */
 private function _delete()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('GROUPS_LOGIN_NOTICE'));
         return;
     }
     if (!$this->authorized) {
         $this->setError(Lang::txt('PLG_GROUPS_BLOG_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     if (!$this->_getPostingPermissions()) {
         $this->setError(Lang::txt('PLG_GROUPS_BLOG_ERROR_PERMISSION_DENIED'));
         return $this->_browse();
     }
     // Incoming
     $id = Request::getInt('entry', 0);
     if (!$id) {
         return $this->_browse();
     }
     $process = Request::getVar('process', '');
     $confirmdel = Request::getVar('confirmdel', '');
     // Initiate a blog entry object
     $entry = \Components\Blog\Models\Entry::oneOrFail($id);
     // Did they confirm delete?
     if (!$process || !$confirmdel) {
         if ($process && !$confirmdel) {
             $this->setError(Lang::txt('PLG_GROUPS_BLOG_ERROR_CONFIRM_DELETION'));
         }
         // Output HTML
         $view = $this->view('default', 'delete')->set('option', $this->option)->set('group', $this->group)->set('task', $this->action)->set('config', $this->params)->set('entry', $entry)->set('authorized', $this->authorized);
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
     // Delete the entry itself
     $entry->set('state', 2);
     if (!$entry->save()) {
         $this->setError($entry->getError());
     }
     // Return the topics list
     return $this->_browse();
 }
Пример #11
0
 /**
  * Turn comments on/off
  *
  * @return  void
  */
 public function setcommentsTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     $state = Request::getInt('state', 0);
     // Check for a resource
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BLOG_SELECT_ENTRY_TO_COMMENTS', $this->_task), 'error');
         return;
     }
     // Loop through all the IDs
     $success = 0;
     foreach ($ids as $id) {
         // Load the article
         $row = Entry::oneOrFail(intval($id));
         $row->set('allow_comments', $state);
         // Store new content
         if (!$row->save()) {
             Notify::error($row->getError());
             continue;
         }
         $success++;
     }
     $message = $state ? Lang::txt('COM_BLOG_ITEMS_COMMENTS_ENABLED', $success) : Lang::txt('COM_BLOG_ITEMS_COMMENTS_DISABLED', $success);
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message);
 }
Пример #12
0
 /**
  * Delete an entry
  *
  * @return  string
  */
 private function _delete()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('MEMBERS_LOGIN_NOTICE'));
         return;
     }
     if (User::get('id') != $this->member->get('uidNumber')) {
         $this->setError(Lang::txt('PLG_MEMBERS_BLOG_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     // Incoming
     $id = Request::getInt('entry', 0);
     if (!$id) {
         return $this->_browse();
     }
     $process = Request::getVar('process', '');
     $confirmdel = Request::getVar('confirmdel', '');
     // Initiate a blog entry object
     $entry = \Components\Blog\Models\Entry::oneOrFail($id);
     // Did they confirm delete?
     if (!$process || !$confirmdel) {
         if ($process && !$confirmdel) {
             $this->setError(Lang::txt('PLG_MEMBERS_BLOG_ERROR_CONFIRM_DELETION'));
         }
         // Output HTML
         $view = $this->view('default', 'delete')->set('option', $this->option)->set('member', $this->member)->set('task', $this->task)->set('config', $this->params)->set('entry', $entry)->set('authorized', true);
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
     // Delete the entry itself
     $entry->set('state', 2);
     if (!$entry->save()) {
         $this->setError($entry->getError());
     }
     // Return the topics list
     App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name));
 }