Exemplo n.º 1
0
 /**
  * Save a category record and redirects to listing
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     User::setState('com_forum.edit.category.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Initiate extended database class
     $category = Category::oneOrNew($fields['id'])->set($fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminCategory();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $category->assetRules = new \JAccessRules($validData['rules']);
     }
     if (!$category->get('scope')) {
         $section = Section::oneOrFail($fields['section_id']);
         $category->set('scope', $section->get('scope'));
         $category->set('scope_id', $section->get('scope_id'));
     }
     // Store new content
     if (!$category->save()) {
         Notify::error($category->getError());
         return $this->editTask($category);
     }
     Notify::success(Lang::txt('COM_FORUM_CATEGORY_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($category);
     }
     // Redirect
     $this->cancelTask();
 }
Exemplo n.º 2
0
 /**
  * Sets the access of one or more entries
  *
  * @return  void
  */
 public function accessTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $state = Request::getInt('access', 0);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for an ID
     if (count($ids) < 1) {
         Notify::warning(Lang::txt('COM_FORUM_SELECT_ENTRY_TO_CHANGE_ACCESS'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Update record(s)
         $row = Section::oneOrFail(intval($id));
         $row->set('access', $state);
         if (!$row->save()) {
             Notify::error($row->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_FORUM_ITEMS_ACCESS_CHANGED', $i));
     }
     $this->cancelTask();
 }
Exemplo n.º 3
0
 /**
  * Display a list of threads
  *
  * @apiMethod GET
  * @apiUri    /forum/list
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "limitstart",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "section",
  * 		"description":   "Section ID. Find all posts for all categories within a section.",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "category",
  * 		"description":   "Category ID. Find all posts within a category.",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "threads_only",
  * 		"description":   "Return only thread starter posts (true) or any post (false).",
  * 		"type":          "boolean",
  * 		"required":      false,
  *      "default":       false
  * }
  * @apiParameter {
  * 		"name":          "parent",
  * 		"description":   "Parent post ID. Find all immediate descendent (replies) posts.",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       null
  * }
  * @apiParameter {
  * 		"name":          "thread",
  * 		"description":   "Thread ID. Find all posts in a specified thread.",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "scope",
  * 		"description":   "Scope (site, groups, members, etc.)",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       "site"
  * }
  * @apiParameter {
  * 		"name":          "scope_id",
  * 		"description":   "Scope ID",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @return    void
  */
 public function listTask()
 {
     $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'section_id' => Request::getInt('section', 0), 'category_id' => Request::getInt('category', 0), 'parent' => Request::getInt('parent', 0), 'thread' => Request::getInt('thread', 0), 'threads' => Request::getVar('threads_only', false), 'search' => Request::getVar('search', ''), 'scope' => Request::getWord('scope', 'site'), 'scope_id' => Request::getInt('scope_id', 0), 'state' => Post::STATE_PUBLISHED, 'parent' => 0, 'access' => User::getAuthorisedViewLevels());
     $filters['threads'] = !$filters['threads'] || $filters['threads'] == 'false' ? false : true;
     if ($filters['scope'] == 'group') {
         $group = \Hubzero\User\Group::getInstance($filters['scope_id']);
         if ($group && in_array(User::get('id'), $group->get('members'))) {
             $filters['access'][] = 5;
             // Private
         }
     }
     $entries = Post::all()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id']);
     if ($filters['thread']) {
         $entries->whereEquals('thread', $filters['thread']);
     }
     if ($filters['parent']) {
         $entries->whereEquals('parent', $filters['parent']);
     }
     if ($filters['threads']) {
         $entries->whereEquals('parent', 0);
     }
     if ($filters['section_id']) {
         // Make sure the section exists and is available
         $section = Section::oneOrFail($filters['section_id']);
         if (!$section->get('id')) {
             throw new Exception(Lang::txt('COM_FORUM_ERROR_SECTION_NOT_FOUND'), 404);
         }
         if ($section->get('state') == Section::STATE_DELETED) {
             throw new Exception(Lang::txt('COM_FORUM_ERROR_SECTION_NOT_FOUND'), 404);
         }
         if (!$filters['category_id']) {
             $categories = $section->categories()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->rows();
             $filters['category_id'] = array();
             foreach ($categories as $category) {
                 $filters['category_id'][] = $category->get('id');
             }
         }
     }
     if ($filters['category_id']) {
         // If one category, make sure it exists and is available
         if (is_int($filters['category_id'])) {
             $category = Category::oneOrFail($filters['category_id']);
             if (!$category->get('id')) {
                 throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_NOT_FOUND'), 404);
             }
             if ($category->get('state') == Category::STATE_DELETED) {
                 throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_NOT_FOUND'), 404);
             }
             if ($filters['section_id'] && $category->get('section_id') != $filters['section_id']) {
                 throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_NOT_FOUND'), 404);
             }
         }
         $entries->whereIn('category_id', (array) $filters['category_id']);
     }
     if ($filters['search']) {
         $entries->whereLike('comment', $filters['search'], 1)->orWhereLike('title', $filters['search'], 1)->resetDepth();
     }
     $threads = $entries->ordered()->paginated()->rows();
     $response = new stdClass();
     $response->threads = array();
     $response->total = $threads->count();
     if ($response->total) {
         $base = str_replace('/api', '', rtrim(Request::base(), '/'));
         foreach ($threads as $thread) {
             $obj = new stdClass();
             $obj->id = $thread->get('id');
             $obj->title = $thread->get('title');
             $obj->created = with(new Date($thread->get('created')))->format('Y-m-d\\TH:i:s\\Z');
             $obj->modified = $thread->get('modified');
             $obj->anonymous = $thread->get('anonymous');
             //$obj->closed      = ($thread->get('closed') ? true : false);
             $obj->scope = $thread->get('scope');
             $obj->scope_id = $thread->get('scope_id');
             $obj->thread = $thread->get('thread');
             $obj->parent = $thread->get('parent');
             $obj->category_id = $thread->get('category_id');
             $obj->state = $thread->get('state');
             $obj->access = $thread->get('access');
             $obj->creator = new stdClass();
             $obj->creator->id = 0;
             $obj->creator->name = Lang::txt('COM_FORUM_ANONYMOUS');
             if (!$thread->get('anonymous')) {
                 $obj->creator->id = $thread->get('created_by');
                 $obj->creator->name = $thread->creator->get('name');
             }
             $obj->posts = $thread->thread()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->total();
             $obj->url = $base . '/' . ltrim(Route::url($thread->link()), '/');
             $response->threads[] = $obj;
         }
     }
     $response->success = true;
     $this->send($response);
 }