/** * Display a list of sections and their categories * * @return void */ public function displayTask() { // Get authorization $this->_authorize('section'); $this->_authorize('category'); $forum = new Manager('site', 0); // Filters $filters = array('scope' => $forum->get('scope'), 'scope_id' => $forum->get('scope_id'), 'state' => Section::STATE_PUBLISHED, 'search' => '', 'access' => User::getAuthorisedViewLevels()); // Flag to indicate if a section is being put into edit mode $edit = null; if ($this->getTask() == 'edit' && $this->config->get('access-edit-section')) { $edit = Request::getVar('section', ''); } $sections = $forum->sections($filters); if (!$sections->count() && $this->config->get('access-create-section') && Request::getWord('action') == 'populate') { if (!$forum->setup()) { $this->setError($forum->getError()); } $sections = $forum->sections($filters); } // Set the page title App::get('document')->setTitle(Lang::txt(strtoupper($this->_option))); // Set the pathway Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); $this->view->set('filters', $filters)->set('config', $this->config)->set('forum', $forum)->set('sections', $sections)->set('edit', $edit)->display(); }
/** * Display all sections * * @return void */ public function displayTask() { // Filters $this->view->filters = array('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', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($this->view->filters['scopeinfo'], ':')) { $bits = explode(':', $this->view->filters['scopeinfo']); $this->view->filters['scope'] = $bits[0]; $this->view->filters['scope_id'] = intval(end($bits)); } else { $this->view->filters['scope'] = ''; $this->view->filters['scope_id'] = -1; } $model = new Manager($this->view->filters['scope'], $this->view->filters['scope_id']); // Get a record count $this->view->total = $model->sections('count', $this->view->filters); // Get records $this->view->results = $model->sections('list', $this->view->filters); $this->view->forum = $model; // Output the HTML $this->view->display(); }
/** * Display all sections * * @return void */ public function displayTask() { // Filters $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', '-1', 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', '-1', 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($filters['scopeinfo'], ':')) { $bits = explode(':', $filters['scopeinfo']); $filters['scope'] = $bits[0]; $filters['scope_id'] = intval(end($bits)); } else { $filters['scope'] = ''; $filters['scope_id'] = -1; } $entries = Section::all()->including(['categories', function ($category) { $category->select('id')->select('section_id'); }]); if ($filters['search']) { $entries->whereLike('title', strtolower((string) $filters['search'])); } if ($filters['scope']) { $entries->whereEquals('scope', $filters['scope']); } if ($filters['scope_id'] >= 0) { $entries->whereEquals('scope_id', (int) $filters['scope_id']); } if ($filters['state'] >= 0) { $entries->whereEquals('state', (int) $filters['state']); } if ($filters['access'] >= 0) { $entries->whereEquals('access', (int) $filters['access']); } // Get records $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows(); $forum = new Manager($filters['scope'], $filters['scope_id']); // Output the HTML $this->view->set('rows', $rows)->set('filters', $filters)->set('scopes', $forum->scopes())->display(); }
/** * Display all categories in a section * * @return void */ public function displayTask() { // Filters $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', -1, 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', -1, 'int'), 'section_id' => Request::getState($this->_option . '.' . $this->_controller . '.section_id', 'section_id', -1, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($filters['scopeinfo'], ':')) { $bits = explode(':', $filters['scopeinfo']); $filters['scope'] = $bits[0]; $filters['scope_id'] = intval(end($bits)); } else { $filters['scope'] = ''; $filters['scope_id'] = -1; } $filters['admin'] = true; // Load the current section if (!$filters['section_id'] || $filters['section_id'] <= 0) { // No section? Load a default blank section $section = Section::blank(); } else { $section = Section::oneOrFail($filters['section_id']); $filters['scope'] = $section->get('scope'); $filters['scope_id'] = $section->get('scope_id'); $filters['scopeinfo'] = $filters['scope'] . ':' . $filters['scope_id']; } $sections = array(); if ($filters['scope_id'] >= 0) { $sections = Section::all()->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id'])->ordered('title', 'ASC')->rows(); } $entries = Category::all()->including(['posts', function ($post) { $post->select('id')->select('category_id'); }]); if ($filters['search']) { $entries->whereLike('title', strtolower((string) $filters['search'])); } if ($filters['scope']) { $entries->whereEquals('scope', $filters['scope']); } if ($filters['scope_id'] >= 0) { $entries->whereEquals('scope_id', (int) $filters['scope_id']); } if ($filters['state'] >= 0) { $entries->whereEquals('state', (int) $filters['state']); } if ($filters['access'] >= 0) { $entries->whereEquals('access', (int) $filters['access']); } if ($filters['section_id'] > 0) { $entries->whereEquals('section_id', (int) $filters['section_id']); } // Get records $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows(); $forum = new Manager($filters['scope'], $filters['scope_id']); // Output the HTML $this->view->set('rows', $rows)->set('filters', $filters)->set('section', $section)->set('sections', $sections)->set('scopes', $forum->scopes())->display(); }
/** * Display module contents * * @return void */ public function run() { $database = \App::get('db'); //get the params $this->limit = $this->params->get('limit', 5); $this->charlimit = $this->params->get('charlimit', 100); include_once Component::path('com_forum') . DS . 'models' . DS . 'manager.php'; $forum = new Manager(); //based on param decide what to include switch ($this->params->get('forum', 'both')) { case 'site': $posts = $forum->posts('list', array('scope' => 'site', 'scope_id' => 0, 'state' => 1, 'limit' => 100, 'sort' => 'created', 'sort_Dir' => 'DESC')); break; case 'group': $posts = $forum->posts('list', array('scope' => 'site', 'scope_id' => -1, 'state' => 1, 'limit' => 100, 'sort' => 'created', 'sort_Dir' => 'DESC')); break; case 'both': default: $posts = $forum->posts('list', array('scope' => array('site', 'group'), 'scope_id' => -1, 'state' => 1, 'limit' => 100, 'sort' => 'created', 'sort_Dir' => 'DESC')); break; } //make sure that the group for each forum post has the right privacy setting $categories = array(); $ids = array(); $threads = array(); $t = array(); $p = array(); // Run through all the posts and collect some data foreach ($posts as $k => $post) { if ($post->get('scope') == 'group') { $group = Group::getInstance($post->get('scope_id')); if (is_object($group)) { $forum_access = Group\Helper::getPluginAccess($group, 'forum'); if ($forum_access == 'nobody' || $forum_access == 'registered' && User::isGuest() || $forum_access == 'members' && !in_array(User::get('id'), $group->get('members'))) { $posts->remove($k); continue; } } else { $posts->remove($k); continue; } $post->set('group_alias', $group->get('cn')); $post->set('group_title', $group->get('description')); } if ($post->get('parent') == 0) { $threads[$post->get('id')] = $post->get('title'); } else { $threads[$post->get('thread')] = isset($threads[$post->get('thread')]) ? $threads[$post->get('thread')] : ''; if (!$threads[$post->get('thread')]) { $t[] = $post->get('thread'); } } $ids[] = $post->get('category_id'); $p[] = $post; } $this->posts = new \Hubzero\Base\ItemList($p); // Get any threads not found above if (count($t) > 0) { $thrds = $forum->posts('list', array('scope' => array('site', 'group'), 'scope_id' => -1, 'state' => 1, 'sort' => 'created', 'sort_Dir' => 'DESC', 'id' => $t)); foreach ($thrds as $thread) { $threads[$thread->get('id')] = $thread->get('title'); } } if (count($ids) > 0) { $database->setQuery("SELECT c.id, c.alias, s.alias as section FROM `#__forum_categories` c LEFT JOIN `#__forum_sections` as s ON s.id=c.section_id WHERE c.id IN (" . implode(',', $ids) . ") AND c.state='1'"); $cats = $database->loadObjectList(); if ($cats) { foreach ($cats as $category) { $categories[$category->id] = $category; } } } //set posts to view $this->threads = $threads; //$this->posts = $posts; $this->categories = $categories; require $this->getLayoutPath(); }
/** * Display all threads in a category * * @return void */ public function displayTask() { // Filters $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', '-1', 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', '-1', 'int'), 'section_id' => Request::getState($this->_option . '.' . $this->_controller . '.section_id', 'section_id', -1, 'int'), 'category_id' => Request::getState($this->_option . '.' . $this->_controller . '.category_id', 'category_id', -1, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', '')); if (strstr($filters['scopeinfo'], ':')) { $bits = explode(':', $filters['scopeinfo']); $filters['scope'] = $bits[0]; $filters['scope_id'] = intval(end($bits)); } else { $filters['scope'] = ''; $filters['scope_id'] = -1; } // Get the category $category = Category::oneOrNew($filters['category_id']); // Get the category if ($category->get('id')) { $filters['scope'] = $category->get('scope'); $filters['scope_id'] = $category->get('scope_id'); $filters['scopeinfo'] = $filters['scope'] . ':' . $filters['scope_id']; $filters['section_id'] = $category->get('section_id'); } // Get the section $section = Section::oneOrNew($filters['section_id']); if ($section->get('id') && !$filters['scopeinfo']) { $filters['scope'] = $section->get('scope'); $filters['scope_id'] = $section->get('scope_id'); $filters['scopeinfo'] = $filters['scope'] . ':' . $filters['scope_id']; } // Get sections $sections = array(); if ($filters['scopeinfo']) { $sections = Section::all()->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id'])->ordered('title', 'ASC')->rows(); } // Get categories $categories = array(); if ($filters['section_id']) { $categories = Category::all()->whereEquals('section_id', $filters['section_id'])->rows(); if (!$filters['category_id'] || $filters['category_id'] <= 0) { $filters['category_id'] = array(); foreach ($categories as $cat) { $filters['category_id'][] = $cat->id; } } } // Get threads $entries = Post::all()->whereEquals('parent', 0); if ($filters['search']) { $entries->whereLike('comment', strtolower((string) $filters['search'])); } if ($filters['scope']) { $entries->whereEquals('scope', $filters['scope']); } if ($filters['scope_id'] >= 0) { $entries->whereEquals('scope_id', (int) $filters['scope_id']); } if ($filters['state'] >= 0) { $entries->whereEquals('state', (int) $filters['state']); } if ($filters['access'] >= 0) { $entries->whereEquals('access', (int) $filters['access']); } if (is_array($filters['category_id'])) { if (!empty($filters['category_id'])) { $entries->whereIn('category_id', $filters['category_id']); } $filters['category_id'] = -1; } elseif ($filters['category_id'] > 0) { $entries->whereEquals('category_id', (int) $filters['category_id']); } $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows(); $forum = new Manager($filters['scope'], $filters['scope_id']); // Output the HTML $this->view->set('rows', $rows)->set('filters', $filters)->set('section', $section)->set('category', $category)->set('sections', $sections)->set('categories', $categories)->set('scopes', $forum->scopes())->display(); }
/** * Retrieve a thread * * @apiMethod GET * @apiUri /forum/{thread} * @apiParameter { * "name": "id", * "description": "Thread identifier", * "type": "integer", * "required": true, * "default": 0 * } * @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": "section", * "description": "Section alias to filter by", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "category", * "description": "Category alias to filter by", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": 1 * } * @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 * } * @apiParameter { * "name": "scope_sub_id", * "description": "Scope sub-ID", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "object_id", * "description": "Object ID", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "start_id", * "description": "ID of record to start with", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "start_at", * "description": "Start timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "type": "string", * "required": false, * "default": "newest", * "allowedValues": "newest, oldest" * } * @return void */ public function readTask() { $find = strtolower(Request::getWord('find', 'results')); $filters = array('limit' => Request::getInt('limit', Config::get('list_limit', 25)), 'start' => Request::getInt('limitstart', 0), 'section' => Request::getCmd('section', ''), 'category' => Request::getCmd('category', ''), 'state' => Request::getInt('state', Post::STATE_PUBLISHED), 'scope' => Request::getWord('scope', ''), 'scope_id' => Request::getInt('scope_id', 0), 'scope_sub_id' => Request::getInt('scope_sub_id', 0), 'object_id' => Request::getInt('object_id', 0), 'start_id' => Request::getInt('start_id', 0), 'start_at' => Request::getVar('start_at', ''), 'sticky' => false); $forum = new Manager($filters['scope'], $filters['scope_id']); if ($thread = Request::getInt('thread', 0)) { $filters['thread'] = $thread; } $sort = Request::getVar('sort', 'newest'); switch ($sort) { case 'oldest': $filters['sort_Dir'] = 'ASC'; break; case 'newest': default: $filters['sort_Dir'] = 'DESC'; break; } $filters['sort'] = 'c.created'; if ($filters['start_id']) { $filters['limit'] = 0; $filters['start'] = 0; } $data = new stdClass(); $data->code = 0; if ($find == 'count') { $data->count = 0; $data->threads = 0; if (isset($filters['thread'])) { $data->count = $forum->posts($filters)->total(); } $post = Post::all()->whereEquals('object_id', $filters['object_id'])->whereEquals('scope_id', $filters['scope_id'])->whereEquals('scope', $filters['scope'])->row(); if ($post->get('id')) { $filters['start_at'] = Request::getVar('threads_start', ''); $filters['parent'] = 0; } $data->threads = $forum->posts($filters)->total(); } else { $rows = $forum->posts($filters)->rows(); if ($rows) { if ($filters['start_id']) { $filters['limit'] = Request::getInt('limit', Config::get('list_limit')); $children = array(0 => array()); $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit']; foreach ($rows as $v) { $v->set('created', with(new Date($v->get('created')))->format('Y-m-d\\TH:i:s\\Z')); $pt = $v->get('parent'); $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } $list = $this->treeRecurse($post->get('id'), '', array(), $children, max(0, $levellimit - 1)); $inc = false; $newlist = array(); foreach ($list as $l) { if ($l->id == $filters['start_id']) { $inc = true; } else { if ($inc) { $newlist[] = $l; } } } $rows = array_slice($newlist, $filters['start'], $filters['limit']); } } $data->response = $rows; } $this->send($data); }