コード例 #1
0
ファイル: categories.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * 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();
 }
コード例 #2
0
ファイル: manager.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Get categories for this forum
  *
  * @param   array    $filters  Filters to apply to the query
  * @return  object
  */
 public function categories($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $model = Category::all();
     if ($filters['scope']) {
         $model->whereEquals('scope', $filters['scope']);
     }
     if ($filters['scope_id'] >= 0) {
         $model->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state'])) {
         $model->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         if (!is_array($filters['access'])) {
             $filters['access'] = array($filters['access']);
         }
         $model->whereIn('access', $filters['access']);
     }
     return $model;
 }
コード例 #3
0
ファイル: threads.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Displays a question response for editing
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $parent = Request::getInt('parent', 0);
     if (!is_object($post)) {
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = intval($id[0]);
         }
         $post = Post::oneOrNew($id);
     }
     if ($post->isNew()) {
         $post->set('parent', $parent);
         $post->set('created_by', User::get('id'));
     }
     if ($post->get('parent')) {
         $threads = Post::all()->whereEquals('category_id', $post->get('category_id'))->whereEquals('parent', 0)->ordered()->rows();
     }
     // Get the category
     $category = Category::oneOrNew($post->get('category_id'));
     $categories = array();
     foreach (Category::all()->rows() as $c) {
         if (!isset($categories[$c->section_id])) {
             $categories[$c->section_id] = array();
         }
         $categories[$c->section_id][] = $c;
         asort($categories[$c->section_id]);
     }
     // Get the section
     $section = Section::oneOrNew($category->get('section_id'));
     // Get the sections for this group
     $sections = array();
     foreach (Section::all()->rows() as $s) {
         $ky = $s->scope . ' (' . $s->scope_id . ')';
         if ($s->scope == 'site') {
             $ky = '[ site ]';
         }
         if (!isset($sections[$ky])) {
             $sections[$ky] = array();
         }
         $s->categories = isset($categories[$s->id]) ? $categories[$s->id] : array();
         $sections[$ky][] = $s;
         asort($sections[$ky]);
     }
     User::setState('com_forum.edit.thread.data', array('id' => $post->get('id'), 'asset_id' => $post->get('asset_id')));
     $m = new AdminThread();
     $form = $m->getForm();
     // Get tags on this article
     $this->view->set('row', $post)->set('sections', $sections)->set('categories', $categories)->set('form', $form)->setLayout('edit')->display();
 }
コード例 #4
0
ファイル: threads.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Show a form for editing an entry
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     $id = Request::getInt('thread', 0);
     $category = Request::getCmd('category', '');
     $section = Request::getCmd('section', '');
     if (User::isGuest()) {
         $return = Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category . '&task=new');
         if ($id) {
             $return = Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category . '&thread=' . $id . '&task=edit');
         }
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)) . Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
     }
     // Section
     $section = Section::all()->whereEquals('alias', $section)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Section::STATE_DELETED)->row();
     if (!$section->get('id')) {
         App::abort(404, Lang::txt('COM_FORUM_SECTION_NOT_FOUND'));
     }
     // Get the category
     $category = Category::all()->whereEquals('alias', $category)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Category::STATE_DELETED)->row();
     if (!$category->get('id')) {
         App::abort(404, Lang::txt('COM_FORUM_CATEGORY_NOT_FOUND'));
     }
     // Incoming
     if (!is_object($post)) {
         $post = Post::oneOrNew($id);
     }
     $this->_authorize('thread', $id);
     if ($post->isNew()) {
         $post->set('scope', $this->forum->get('scope'));
         $post->set('created_by', User::get('id'));
     } elseif ($post->get('created_by') != User::get('id') && !$this->config->get('access-edit-thread')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning');
     }
     // Set the page title
     $this->buildTitle($section, $category, $post);
     // Set the pathway
     $this->buildPathway($section, $category, $post);
     $this->view->set('config', $this->config)->set('forum', $this->forum)->set('section', $section)->set('category', $category)->set('post', $post)->setErrors($this->getErrors())->setLayout('edit')->display();
 }
コード例 #5
0
ファイル: discussions.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Show a form for editing a post
  *
  * @param   object  $post
  * @return  string
  */
 public function editthread($post = null)
 {
     $id = Request::getInt('post', 0);
     $category = Request::getVar('category', '');
     $section = Request::getVar('section', '');
     if (User::isGuest()) {
         $return = Route::url($this->offering->link() . '&active=' . $this->_name . '&unit=' . $section . '&b=' . $category . '&c=new');
         if ($id) {
             $return = Route::url($this->offering->link() . '&active=' . $this->_name . '&unit=' . $section . '&b=' . $category . '&c=' . $id . '/edit');
         }
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)));
         return;
     }
     // Get the category
     $category = Category::all()->whereEquals('alias', $category)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->row();
     if (!$category->get('id')) {
         App::abort(404, Lang::txt('PLG_GROUPS_FORUM_ERROR_CATEGORY_NOT_FOUND'));
     }
     // Incoming
     if (!is_object($post)) {
         $post = Post::oneOrNew($id);
     }
     // Get authorization
     $this->_authorize('thread', $id);
     if ($post->isNew()) {
         $post->set('scope', $this->forum->get('scope'));
         $post->set('created_by', User::get('id'));
     } elseif ($post->get('created_by') != User::get('id') && !$this->params->get('access-edit-thread')) {
         App::redirect(Route::url($this->base . '&unit=manage&b=' . $section . '&c=' . $category));
     }
     return $this->view('edit', 'threads')->set('option', $this->option)->set('course', $this->course)->set('offering', $this->offering)->set('config', $this->params)->set('forum', $this->forum)->set('section', $section)->set('category', $category)->set('post', $post)->set('name', $this->_name)->setErrors($this->getErrors())->loadTemplate();
 }
コード例 #6
0
ファイル: threadsv1_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Create a thread or post in a thread
  *
  * @apiMethod POST
  * @apiUri    /forum
  * @apiParameter {
  * 		"name":        "category_id",
  * 		"description": "Category ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (site, group, etc.)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     "site"
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     "0"
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "comment",
  * 		"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":     1
  * }
  * @apiParameter {
  * 		"name":        "access",
  * 		"description": "Access level (1 = public, 2 = registered users, 5 = private)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     1
  * }
  * @apiParameter {
  * 		"name":        "anonymous",
  * 		"description": "Commentor is anonymous?",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "parent",
  * 		"description": "ID of the parent post this post is in reply to.",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "thread",
  * 		"description": "ID of the forum thread the post belongs to. 0 if new thread.",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "sticky",
  * 		"description": "If the thread is sticky or not. Only applies to thread starter posts.",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "closed",
  * 		"description": "If the thread is closed (no more new posts) or not. Only applies to thread starter posts.",
  * 		"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 createTask()
 {
     $this->requiresAuthentication();
     $fields = array('category_id' => Request::getInt('category_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'comment' => Request::getVar('comment', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', Post::STATE_PUBLISHED, 'post'), 'sticky' => Request::getInt('sticky', 0, 'post'), 'parent' => Request::getInt('parent', 0, 'post'), 'scope' => Request::getVar('scope', 'site', 'post'), 'scope_id' => Request::getInt('scope_id', 0, 'post'), 'access' => Request::getInt('access', Post::ACCESS_PUBLIC, 'post'), 'anonymous' => Request::getInt('anonymous', 0, 'post'), 'thread' => Request::getInt('thread', 0, 'post'), 'closed' => Request::getInt('closed', 0, 'post'), 'hits' => Request::getInt('hits', 0, 'post'));
     if (!$fields['category_id']) {
         throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_ID_MISSING'), 400);
     }
     $row = Post::blank();
     if (!$row->set($fields)) {
         throw new Exception(Lang::txt('COM_FORUM_ERROR_BINDING_DATA'), 500);
     }
     $row->set('anonymous', $fields['anonymous'] ? 1 : 0);
     $category = Category::all()->whereEquals('id', $row->get('category_id'))->whereEquals('scope', $row->get('scope'))->whereEquals('scope_id', $row->get('scope_id'))->where('state', '!=', Category::STATE_DELETED)->row();
     if (!$category->get('id')) {
         throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_NOT_FOUND'), 400);
     }
     if (!$row->save()) {
         throw new Exception(Lang::txt('COM_FORUM_ERROR_SAVING_DATA'), 500);
     }
     if ($fields['created_by']) {
         $row->set('created_by', (int) $fields['created_by']);
         $row->save();
     }
     if ($tags = Request::getVar('tags', null, 'post')) {
         if (!$row->tag($tags, User::get('id'))) {
             throw new Exception(Lang::txt('COM_FORUM_ERROR_SAVING_TAGS'), 500);
         }
     }
     // Record the activity
     $base = rtrim(Request::base(), '/');
     $url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/'));
     $recipients = array(['forum.site', 1], ['forum.section', $category->get('section_id')], ['user', $row->get('created_by')]);
     $type = 'thread';
     $desc = Lang::txt('COM_FORUM_ACTIVITY_' . strtoupper($type) . '_CREATED', '<a href="' . $url . '">' . $row->get('title') . '</a>');
     // If this is a post in a thread and not the thread starter...
     if ($row->get('parent')) {
         $thread = Post::oneOrFail($row->get('thread'));
         $thread->set('last_activity', $fields['id'] ? $row->get('modified') : $row->get('created'));
         $thread->save();
         $type = 'post';
         $desc = Lang::txt('COM_FORUM_ACTIVITY_' . strtoupper($type) . '_CREATED', $row->get('id'), '<a href="' . $url . '">' . $thread->get('title') . '</a>');
         // If the parent post is not the same as the
         // thread starter (i.e., this is a reply)
         if ($row->get('parent') != $row->get('thread')) {
             $parent = Post::oneOrFail($row->get('parent'));
             $recipients[] = ['user', $parent->get('created_by')];
         }
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'forum.' . $type, 'scope_id' => $row->get('id'), 'anonymous' => $row->get('anonymous', 0), 'description' => $desc, 'details' => array('thread' => $row->get('thread'), 'url' => $url)], 'recipients' => $recipients]);
     $obj = $row->toObject();
     $obj->creator = new stdClass();
     $obj->creator->id = 0;
     $obj->creator->name = Lang::txt('COM_FORUM_ANONYMOUS');
     if (!$row->get('anonymous')) {
         $obj->creator->id = $row->get('created_by');
         $obj->creator->name = $row->creator->get('name');
     }
     $this->send($obj);
 }
コード例 #7
0
ファイル: categories.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Delete a category
  *
  * @return  void
  */
 public function deleteTask()
 {
     $url = 'index.php?option=' . $this->_option;
     // Is the user logged in?
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url($url, false, true))), Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
     }
     // Load the category
     $category = Category::all()->whereEquals('alias', Request::getVar('category', ''))->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Category::STATE_DELETED)->row();
     // Make the sure the category exist
     if (!$category->get('id')) {
         App::redirect(Route::url($url), Lang::txt('COM_FORUM_MISSING_ID'), 'error');
     }
     // Check if user is authorized to delete entries
     $this->_authorize('category', $category->get('id'));
     if (!$this->config->get('access-delete-category')) {
         App::redirect(Route::url($url), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning');
     }
     // Set the category to "deleted"
     $category->set('state', $category::STATE_DELETED);
     if (!$category->save()) {
         App::redirect(Route::url($url), $category->getError(), 'error');
     }
     // Log activity
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'forum.category', 'scope_id' => $category->get('id'), 'description' => Lang::txt('COM_FORUM_ACTIVITY_CATEGORY_DELETED', '<a href="' . Route::url($url) . '">' . $category->get('title') . '</a>'), 'details' => array('title' => $category->get('title'), 'url' => Route::url($url))], 'recipients' => array(['forum.site', 1], ['forum.section', $category->get('section_id')], ['user', $category->get('created_by')])]);
     // Redirect to main listing
     App::redirect(Route::url($url), Lang::txt('COM_FORUM_CATEGORY_DELETED'), 'message');
 }
コード例 #8
0
ファイル: forum.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Show a form for editing a post
  *
  * @param   object  $post
  * @return  string
  */
 public function editthread($post = null)
 {
     $id = Request::getInt('thread', 0);
     $category = Request::getVar('category', '');
     $section = Request::getVar('section', '');
     // Login check is handled in the onGroup() method
     /*if (User::isGuest())
     		{
     			$return = Route::url($this->base . '&scope=' . $sectionAlias . '/' . $category . '/new', false, true);
     			if ($id)
     			{
     				$return = Route::url($this->base . '&scope=' . $sectionAlias . '/' . $category . '/' . $id . '/edit', false, true);
     			}
     			App::redirect(
     				Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return))
     			);
     			return;
     		}*/
     // Section
     $section = Section::all()->whereEquals('alias', $section)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->row();
     if (!$section->get('id')) {
         App::abort(404, Lang::txt('PLG_GROUPS_FORUM_ERROR_SECTION_NOT_FOUND'));
     }
     // Get the category
     $category = Category::all()->whereEquals('alias', $category)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->row();
     if (!$category->get('id')) {
         App::abort(404, Lang::txt('PLG_GROUPS_FORUM_ERROR_CATEGORY_NOT_FOUND'));
     }
     // Incoming
     if (!is_object($post)) {
         $post = Post::oneOrNew($id);
     }
     // Get authorization
     $this->_authorize('thread', $id);
     if ($post->isNew()) {
         $post->set('scope', $this->forum->get('scope'));
         $post->set('created_by', User::get('id'));
     } elseif ($post->get('created_by') != User::get('id') && !$this->params->get('access-edit-thread')) {
         App::redirect(Route::url($this->base . '&scope=' . $section . '/' . $category));
     }
     return $this->view('edit', 'threads')->set('option', $this->option)->set('group', $this->group)->set('config', $this->params)->set('forum', $this->forum)->set('section', $section)->set('category', $category)->set('post', $post)->setErrors($this->getErrors())->loadTemplate();
 }