Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
 /**
  * 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);
 }