/** * Generate macro output * * @return string */ public function render() { // check if we can render if (!parent::canRender()) { return \Lang::txt('[This macro is designed for Groups only]'); } // get args $args = $this->getArgs(); //array of filters $filters = array('limit' => count($args) == 1 && is_numeric($args[0]) ? $args[0] : 12); // get members $members = $this->getGroupMembers($this->group, $filters); //are we a group member $isMember = in_array(\User::get('id'), $this->group->get('members')) ? true : false; //get the members plugin access for this group $memberAccess = \Hubzero\User\Group\Helper::getPluginAccess($this->group, 'members'); // make sure we can actually display for the current user if ($memberAccess == 'anyone' || $memberAccess == 'registered' && !\User::isGuest() || $memberAccess == 'members' && $isMember) { $html = $this->renderMembers($this->group, $members); } else { $html = ''; } //return rendered events return $html; }
/** * Return content that is to be displayed before group main area * * @return string */ public function onBeforeGroup($group, $authorized) { //creat view object $view = $this->view('sticky', 'browse'); //vars for view $view->authorized = $authorized; $view->option = 'com_groups'; $view->group = $group; $view->name = $this->_name; $view->database = App::get('db'); // get plugin access $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'announcements'); //if set to nobody make sure cant access //check if guest and force login if plugin access is registered or members //check to see if user is member and plugin access requires members if ($access == 'nobody' || User::isGuest() && $access == 'registered' || !in_array(User::get('id'), $group->get('members')) && $access == 'members') { return ''; } //build array of filters $view->filters = array(); $view->filters['scope'] = 'group'; $view->filters['scope_id'] = $view->group->get('gidNumber'); $view->filters['state'] = 1; $view->filters['sticky'] = 1; $view->filters['published'] = 1; //create new announcement Object $hubzeroAnnouncement = new \Hubzero\Item\Announcement($view->database); $view->total = $hubzeroAnnouncement->count($view->filters); $view->rows = $hubzeroAnnouncement->find($view->filters); //pass thru permissions for CRUD $view->isManager = $group->isManager(User::get('id')); //display list of announcements return $view->loadTemplate(); }
/** * Build search query and add it to the $results * * @param object $request \Components\Search\Models\Basic\Request * @param object &$results \Components\Search\Models\Basic\Result\Set * @param object $authz \Components\Search\Models\Basic\Authorization * @return void */ public static function onSearch($request, &$results, $authz) { $terms = $request->get_term_ar(); $weight = 'match(e.title, e.content) against(\'' . join(' ', $terms['stemmed']) . '\')'; $addtl_where = array(); foreach ($terms['mandatory'] as $mand) { $addtl_where[] = "(e.title LIKE '%{$mand}%' OR e.content LIKE '%{$mand}%')"; } foreach ($terms['forbidden'] as $forb) { $addtl_where[] = "(e.title NOT LIKE '%{$forb}%' AND e.content NOT LIKE '%{$forb}%')"; } // Commenting out Access check as it was never used and column was removed from table // during events refactoring // // @author Chris Smoak // @date 4/20/2014 // // $addtl_where[] = '(e.access IN (' . implode(',', User::getAuthorisedViewLevels()) . '))'; $rows = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t\t\te.title,\n\t\t\t\te.content AS description,\n\t\t\t\te.scope,\n\t\t\t\te.scope_id,\n\t\t\t\tconcat('index.php?option=com_events&task=details&id=', e.id) AS link,\n\t\t\t\t{$weight} AS weight,\n\t\t\t\tpublish_up AS date,\n\t\t\t\t'Events' AS section\n\t\t\tFROM `#__events` e\n\t\t\tWHERE\n\t\t\t\tstate = 1 AND\n\t\t\t\tapproved AND {$weight} > 0" . ($addtl_where ? ' AND ' . join(' AND ', $addtl_where) : '') . " ORDER BY {$weight} DESC"); foreach ($rows->to_associative() as $row) { if (!$row) { continue; } // check group perms if ($row->scope == 'group') { // load group $group = \Hubzero\User\Group::getInstance($row->scope_id); // make sure we found one if (!$group) { continue; } // get group calendar access $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'calendar'); // is calendar off // is calendar for registered users & not logged in // is calendar for members only and we are not a member if ($access == 'nobody' || $access == 'registered' && User::isGuest() || $access == 'members' && !in_array(User::get('id'), $group->get('members'))) { continue; } } $row->set_description(preg_replace('/(\\[+.*?\\]+|\\{+.*?\\}+|[=*])/', '', $row->get_description())); $results->add($row); } }
/** * Return content that is to be displayed before group main area * * @param object $group * @param string $authorized * @return string */ public function onBeforeGroup($group, $authorized) { // Get plugin access $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'announcements'); // if set to nobody make sure cant access // check if guest and force login if plugin access is registered or members // check to see if user is member and plugin access requires members if ($access == 'nobody' || User::isGuest() && $access == 'registered' || !in_array(User::get('id'), $group->get('members')) && $access == 'members') { return ''; } // Find announcements $rows = \Hubzero\Item\Announcement::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $group->get('gidNumber'))->whereEquals('state', \Hubzero\Item\Announcement::STATE_PUBLISHED)->whereEquals('sticky', 1)->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', Date::toSql(), 1)->resetDepth()->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>=', Date::toSql(), 1)->rows(); // Create view and assign data $view = $this->view('sticky', 'browse')->set('option', 'com_groups')->set('authorized', $authorized)->set('group', $group)->set('name', $this->_name)->set('rows', $rows)->setError($this->getErrors()); // Pass thru permissions for CRUD $view->set('isManager', $group->isManager(User::get('id'))); // Display list of announcements return $view->loadTemplate(); }
/** * Display module contents * * @return void */ public function run() { Lang::load('com_blog', Component::path('com_blog') . '/site'); include_once \Component::path('com_blog') . DS . 'models' . DS . 'archive.php'; $this->pullout = $this->params->get('pullout', 'yes'); $this->feedlink = $this->params->get('feedlink', 'yes'); $this->limit = $this->params->get('limit', 5); $filters = array('limit' => $this->params->get('limit', 5), 'start' => 0, 'scope' => $this->params->get('blog', 'site'), 'scope_id' => 0, 'state' => 1, 'access' => User::getAuthorisedViewLevels()); if ($filters['scope'] == 'both' || $filters['scope'] == 'group') { $filters['limit'] = $filters['limit'] * 5; // Since some groups May have private entries, we need to up the limit to try and catch more } if ($filters['scope'] == 'both') { $filters['scope'] = ''; } $archive = new Archive('site', 0); $rows = $archive->entries($filters)->ordered()->rows(); $posts = array(); foreach ($rows as $k => $gf) { if ($this->params->get('blog', 'site') == 'group' || $this->params->get('blog', 'site') == 'both') { //make sure that the group for each blog post has the right privacy setting if (!$gf->get('scope_id')) { continue; } $group = $gf->item(); if (is_object($group)) { $blog_access = GroupHelper::getPluginAccess($group, 'blog'); if ($blog_access == 'nobody' || $blog_access == 'registered' && User::isGuest() || $blog_access == 'members' && !in_array(User::get('id'), $group->get('members'))) { continue; } } else { continue; } } $posts[] = $gf; } $this->posts = $posts; require $this->getLayoutPath(); }
/** * Override Execute Method * * @return void */ public function execute() { // disable default task $this->disableDefaultTask(); //get request vars $this->cn = Request::getVar('cn', ''); //check to make sure we have cname if (!$this->cn) { $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID')); } // Load the group page $this->group = Group::getInstance($this->cn); // Load plugin access groups $pluginAccess = \Hubzero\User\Group\Helper::getPluginAccess($this->group); // Ensure we found the group info if (!$this->group || !$this->group->get('gidNumber')) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND')); } // Kick user out if not logged in and should be if (User::isGuest() && $pluginAccess['files'] == 'registered') { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH')); } // Check if they're logged in and not everyone can view files if (User::isGuest() && $pluginAccess['files'] != 'anyone') { $this->loginTask(Lang::txt('COM_GROUPS_MEDIA_MUST_BE_LOGGED_IN')); return; } // Check authorization if (!in_array(User::get('id'), $this->group->get('members')) && $pluginAccess['files'] == 'members') { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH')); } //build path to the group folder $this->path = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS) . DS . $this->group->get('gidNumber'); //continue with parent execute method parent::execute(); }
/** * Generate a unique page alias or slug * * @return string */ public function uniqueAlias() { // if we didnt set an alias lets build one from the title $alias = trim($this->get('alias')); if ($alias == null) { $alias = str_replace(' ', '_', trim($this->get('title'))); } // force lowercase letters $alias = strtolower($alias); // allow only alpha numeric chars, dashes, and underscores $alias = preg_replace("/[^-_a-z0-9]+/", '', $alias); // make sure alias isnt a reserved term $group = \Hubzero\User\Group::getInstance($this->get('gidNumber')); $plugins = \Hubzero\User\Group\Helper::getPluginAccess($group); $reserved = array_keys($plugins); // make sure dont use a reserved alias on the first level if (in_array($alias, $reserved) && $this->get('depth') <= 2 && $this->get('home') == 0) { $alias .= '_page'; } // get current page as it exists in db $page = new Page($this->get('id')); $currentAlias = $page->get('alias'); // only against our pages if alias has changed if ($currentAlias != $alias) { // make sure we dont already have a page with the same alias // get group pages $pageArchive = Page\Archive::getInstance(); $aliases = $pageArchive->pages('alias', array('gidNumber' => $group->get('gidNumber'), 'state' => array(0, 1), 'depth' => $this->get('depth'))); // Append random number if page already exists while (in_array($alias, $aliases)) { $alias .= mt_rand(1, 9); } } // return sanitized alias return $alias; }
switch ($this->group->get('discoverability')) { case 1: $discoverability = Lang::txt('Hidden'); break; case 0: default: $discoverability = Lang::txt('Visible'); break; } $message .= $discoverability . "\n\n"; $message .= "\t" . Lang::txt('Access Permissions:') . "\n"; $levels = array('anyone' => 'Any HUB Visitor', 'registered' => 'Only Registered User of the HUB', 'members' => 'Only Group Members', 'nobody' => 'Disabled/Off'); // Get plugins $group_plugins = Event::trigger('groups.onGroupAreas', array()); array_unshift($group_plugins, array('name' => 'overview', 'title' => 'Overview', 'default_access' => 'anyone', 'display_menu_tab' => true)); $access = \Hubzero\User\Group\Helper::getPluginAccess($this->group); foreach ($group_plugins as $plugin) { if ($plugin['display_menu_tab'] == 1) { $title = $plugin['title']; $perm = $access[$plugin['name']]; $message .= "\t\t" . $title . ' => ' . $levels[$perm] . "\n"; } } $message .= "\n"; $params = Component::params('com_groups'); if ($params->get('email_comment_processing')) { $message .= "\t" . Lang::txt('Discussion Group Emails Autosubscribe:') . ' ' . ($this->group->get('discussion_email_autosubscribe') ? Lang::txt('On') : Lang::txt('Off')) . "\n\n"; } $message .= "\t" . Lang::txt('Page Comments:') . ' '; if ($gparams->get('page_comments') == 2) { $message .= Lang::txt('COM_GROUPS_PAGES_PAGE_COMMENTS_LOCK');
/** * Download a file * * @param string $filename File name * @return void */ public function downloadTask($filename = "") { //get the group $group = Group::getInstance($this->cn); // make sure we have a group if (!is_object($group)) { return; } //authorize $authorized = $this->_authorize(); //get the file name if (substr(strtolower($filename), 0, 5) == 'image') { $file = urldecode(substr($filename, 6)); } elseif (substr(strtolower($filename), 0, 4) == 'file') { $file = urldecode(substr($filename, 5)); } else { return; } // clean up file, strip double "uploads" & trim directory sep $file = str_replace('uploads', '', $file); $file = ltrim($file, DS); // get extension $extension = pathinfo($file, PATHINFO_EXTENSION); //if were on the wiki we need to output files a specific way if ($this->active == 'wiki') { //get access level for wiki $access = Group\Helper::getPluginAccess($group, 'wiki'); //check to make sure user has access to wiki section if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } //load wiki page from db require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php'; $page = new \Components\Wiki\Tables\Page($this->database); $pagename = Request::getVar('pagename'); $scope = Request::getVar('scope', $group->get('cn') . DS . 'wiki'); if ($scope) { $parts = explode('/', $scope); if (count($parts) > 2) { $pagename = array_pop($parts); if (strtolower($filename) == strtolower($pagename)) { $pagename = array_pop($parts); } $scope = implode('/', $parts); } } $page->load($pagename, $scope); //check specific wiki page access if ($page->get('access') == 1 && !in_array(User::get('id'), $group->get('members')) && $authorized != 'admin') { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); return; } //get the config and build base path $wiki_config = \Component::params('com_wiki'); $base_path = $wiki_config->get('filepath') . DS . $page->get('id'); } elseif ($this->active == 'blog') { //get access setting of group blog $access = Group\Helper::getPluginAccess($group, 'blog'); //make sure user has access to blog if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } //make sure we have a group id of the proper length $groupID = Group\Helper::niceidformat($group->get('gidNumber')); //buld path to blog folder $base_path = $this->config->get('uploadpath') . DS . $groupID . DS . 'blog'; if (!file_exists(PATH_APP . DS . $base_path . DS . $file)) { $base_path = $this->config->get('uploadpath') . DS . $group->get('gidNumber') . DS . 'uploads' . DS . 'blog'; } } else { //get access level for overview or other group pages $access = Group\Helper::getPluginAccess($group, 'overview'); //check to make sure we can access it if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } // Build the path $base_path = $this->config->get('uploadpath'); $base_path .= DS . $group->get('gidNumber') . DS . 'uploads'; } // trim base path $base_path = ltrim($base_path, DS); // only can serve files from within /site/groups/{group_id}/uploads/ $pathCheck = PATH_APP . DS . $base_path; // Final path of file $file_path = $base_path . DS . $file; $alt_file_path = null; // if super group offer alt path outside uploads if ($group->isSuperGroup()) { $alt_file_path = str_replace('/uploads', '', $base_path) . DS . $file; // if super group can serve files anywhere inside /site/groups/{group_id} $altPathCheck = PATH_APP . DS . ltrim($alt_file_path); } // Ensure the file exist if (!file_exists(PATH_APP . DS . $file_path)) { if ($alt_file_path == null || !file_exists(PATH_APP . DS . $alt_file_path)) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_FILE_NOT_FOUND') . ' ' . $file); return; } else { $file_path = $alt_file_path; $pathCheck = $altPathCheck; } } // get full path, expanding ../ if ($realPath = realpath(PATH_APP . DS . $file_path)) { // make sure requested file is within acceptable dir if (strpos($realPath, $pathCheck) === false) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_FILE_NOT_FOUND') . ' ' . $file); return; } } // new content server $contentServer = new \Hubzero\Content\Server(); $contentServer->filename(PATH_APP . DS . $file_path); $contentServer->disposition('attachment'); $contentServer->acceptranges(false); // do we need to manually set mime type if ($extension == 'css') { $contentServer->setContentType('text/css'); } // Serve up the file if (!$contentServer->serve()) { App::abort(404, Lang::txt('COM_GROUPS_SERVER_ERROR')); } else { exit; } return; }
<?php $states = array(1 => Lang::txt('COM_GROUPS_PAGES_STATE_PUBLISHED'), 0 => Lang::txt('COM_GROUPS_PAGES_STATE_UNPUBLISHED'), 2 => Lang::txt('COM_GROUPS_PAGES_STATE_DELETED')); foreach ($states as $k => $v) { $sel = $this->page->get('state') == $k ? 'selected="selected"' : ''; echo '<option ' . $sel . ' value="' . $k . '">' . $v . '</option>'; } ?> </select> </div> <div class="input-wrap"> <label for="field-privacy"><?php echo Lang::txt('COM_GROUPS_PAGES_PRIVACY'); ?> :</label><br /> <?php $access = \Hubzero\User\Group\Helper::getPluginAccess($this->group, 'overview'); switch ($access) { case 'anyone': $name = 'Any HUB Visitor'; break; case 'registered': $name = 'Registered HUB Users'; break; case 'members': $name = 'Group Members Only'; break; } ?> <select name="page[privacy]" id="page[privacy]"> <option value="default" <?php if ($this->page->get('privacy') == "default") {
/** * 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(); }
//get this groups params $gparams = new \Hubzero\Config\Registry($this->group->get('params')); $displaySystemUsers = $gparams->get('display_system_users', $displaySystemUsers); //get the group members $members = $this->group->get('members'); shuffle($members); //if we dont want to display system users //filter values through callback above and then reset array keys if ($displaySystemUsers == 'no') { $members = array_map("isSystemUser", $members); $members = array_values(array_filter($members)); } //are we a group member $isMember = in_array(User::get('id'), $this->group->get('members')) ? true : false; //get the members plugin access for this group $memberAccess = \Hubzero\User\Group\Helper::getPluginAccess($this->group, 'members'); ?> <div class="group-content-header"> <h3><?php echo Lang::txt('COM_GROUPS_OVERVIEW_ABOUT_HEADING'); ?> </h3> <?php if ($isMember && $this->privateDesc != '') { ?> <div class="group-content-header-extra"> <a id="toggle_description" class="hide" href="#"><?php echo Lang::txt('COM_GROUPS_SHOW_PUBLIC_DESCRIPTION'); ?> </a>
/** * * Gets Events addresses * * @param string year * @param array event IDs * @return object */ public function getEvents($year = '', $eids = array()) { $where = ""; if ($eids != "") { $i = 0; foreach ($eids as $eid) { $where .= "e.id = " . $this->_db->quote($eid); $i++; if (count($eids) > 1 && $i < count($eids)) { $where .= " OR "; } } $where = "AND ({$where})"; } $sql = "SELECT e.id, e.scope, e.scope_id, e.adresse_info, e.publish_up, e.publish_down, m.addressLatitude, m.addressLongitude\n\t\t\t\tFROM #__events e LEFT JOIN {$this->_tbl} m ON (e.id = m.scope_id AND m.scope = " . $this->_db->quote('event') . ")\n\t\t\t\tWHERE e.publish_up LIKE '" . $this->_db->escape($year) . "%' AND (e.publish_down >= '" . $this->_db->getEscaped($year) . "%' OR e.publish_down = " . $this->_db->quote('0000-00-00 00:00:00') . ")\n\t\t\t\tAND e.state = " . $this->_db->quote('1') . " AND e.adresse_info NOT LIKE " . $this->_db->quote('%online%') . " {$where}"; $this->_db->setQuery($sql); $events = $this->_db->loadObjectList(); foreach ($events as $k => $event) { if ($event->scope == 'group') { $group = \Hubzero\User\Group::getInstance($event->scope_id); if (!$group) { unset($events[$k]); continue; } // only show group events with a $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'calendar'); if ($access == 'nobody' || $access == 'registered' && User::isGuest() || $access == 'members' && !in_array(User::get('id'), $group->get('members'))) { unset($events[$k]); continue; } } $now = Date::of('now')->toSql(); $down = Date::of($event->publish_down)->toSql(); if ($now > $down) { unset($events[$k]); } } return array_values(array_filter($events)); }
/** * Show a form for creating a new entry * * @return void */ public function latestTask() { // Set the mime encoding for the document Document::setType('feed'); // Start a new feed object $doc = Document::instance(); $doc->link = Route::url('index.php?option=' . $this->_option); // Paging variables $start = Request::getInt('limitstart', 0); $limit = Request::getInt('limit', Config::get('list_limit')); // Build some basic RSS document information $doc->title = Config::get('sitename') . ' - ' . Lang::txt('COM_FORUM_RSS_TITLE'); $doc->description = Lang::txt('COM_FORUM_RSS_DESCRIPTION', Config::get('sitename')); $doc->copyright = Lang::txt('COM_FORUM_RSS_COPYRIGHT', date("Y"), Config::get('sitename')); $doc->category = Lang::txt('COM_FORUM_RSS_CATEGORY'); // get all forum posts on site forum $this->database->setQuery("SELECT f.* FROM `#__forum_posts` f WHERE f.scope_id='0' AND scope='site' AND f.state='1'"); $site_forum = $this->database->loadAssocList(); // get any group posts $this->database->setQuery("SELECT f.* FROM `#__forum_posts` f WHERE f.scope_id<>'0' AND scope='group' AND f.state='1'"); $group_forum = $this->database->loadAssocList(); // make sure that the group for each forum post has the right privacy setting foreach ($group_forum as $k => $gf) { $group = \Hubzero\User\Group::getInstance($gf['scope_id']); if (is_object($group)) { $forum_access = \Hubzero\User\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'))) { unset($group_forum[$k]); } } else { unset($group_forum[$k]); } } //based on param decide what to include switch ($this->config->get('forum', 'both')) { case 'site': $rows = $site_forum; break; case 'group': $rows = $group_forum; break; case 'both': default: $rows = array_merge($site_forum, $group_forum); break; } $categories = array(); $ids = array(); foreach ($rows as $post) { $ids[] = $post['category_id']; } $this->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 = $this->database->loadObjectList(); if ($cats) { foreach ($cats as $category) { $categories[$category->id] = $category; } } //function to sort by created date function sortbydate($a, $b) { $d1 = date("Y-m-d H:i:s", strtotime($a['created'])); $d2 = date("Y-m-d H:i:s", strtotime($b['created'])); return $d1 > $d2 ? -1 : 1; } //sort using function above - date desc usort($rows, 'sortbydate'); // Start outputing results if any found if (count($rows) > 0) { foreach ($rows as $row) { // Prepare the title $title = strip_tags(stripslashes($row['title'])); $title = html_entity_decode($title); // Get URL if ($row['scope_id'] == 0) { $link = 'index.php?option=com_forum§ion=' . $categories[$row['category_id']]->section . '&category=' . $categories[$row['category_id']]->alias . '&thread=' . ($row['parent'] ? $row['parent'] : $row['id']); } else { $group = \Hubzero\User\Group::getInstance($row['scope_id']); $link = 'index.php?option=com_groups&gid=' . $group->get('cn') . '&active=forum&scope=' . $categories[$row['category_id']]->section . '/' . $categories[$row['category_id']]->alias . '/' . ($row['parent'] ? $row['parent'] : $row['id']); } $link = Route::url($link); $link = DS . ltrim($link, DS); // Get description $description = stripslashes($row['comment']); $description = String::truncate($description, 300, 0); // Get author $user = User::getInstance($row['created_by']); $author = stripslashes($user->get('name')); // Get date @($date = $row->created ? date('r', strtotime($row->created)) : ''); // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = $row['scope_id'] == 0 ? Lang::txt('COM_FORUM') : stripslashes($group->get('description')); $item->author = $author; // Loads item info into rss array $doc->addItem($item); } } }
/** * Return data on a group view (this will be some form of HTML) * * @param object $group Current group * @param string $option Name of the component * @param string $authorized User's authorization level * @param integer $limit Number of records to pull * @param integer $limitstart Start of records to pull * @param string $action Action to perform * @param array $access What can be accessed * @param array $areas Active area(s) * @return array */ public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null) { $returnhtml = true; $active = 'members'; // The output array we're returning $arr = array('html' => '', 'metadata' => ''); //get this area details $this_area = $this->onGroupAreas(); // Check if our area is in the array of areas we want to return results for if (is_array($areas) && $limit) { if (!in_array($this_area['name'], $areas)) { $returnhtml = false; } } // Set some variables so other functions have access $this->authorized = $authorized; $this->action = $action; $this->_option = $option; $this->group = $group; $this->name = substr($option, 4, strlen($option)); // Only perform the following if this is the active tab/plugin if ($returnhtml) { //set group members plugin access level $group_plugin_acl = $access[$active]; //get the group members $members = $group->get('members'); //if set to nobody make sure cant access if ($group_plugin_acl == 'nobody') { $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>'; return $arr; } //check if guest and force login if plugin access is registered or members if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) { $url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active, false, true); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning'); return; } //check to see if user is member and plugin access requires members if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') { $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>'; return $arr; } // Set the page title //Document::setTitle(Lang::txt(strtoupper($this->_option)).': '.$this->group->description.': '.Lang::txt('PLG_GROUPS_MEMBERS')); $this->css('members.css')->js('members.js'); $gparams = new \Hubzero\Config\Registry($group->get('params')); $this->membership_control = $gparams->get('membership_control', 1); $oparams = Component::params($this->_option); $this->display_system_users = $oparams->get('display_system_users', 'no'); switch ($gparams->get('display_system_users', "global")) { case 'yes': $this->display_system_users = 'yes'; break; case 'no': $this->display_system_users = 'no'; break; case 'global': $this->display_system_users = $this->display_system_users; break; } // Do we need to perform any actions? if ($action) { if (is_numeric($action)) { Request::setVar('member', $action); $action = 'profile'; } $action = strtolower(trim($action)); if (!method_exists($this, $action)) { App::abort(404, Lang::txt('PLG_GROUPS_MESSAGES_ERROR_ACTION_NOTFOUND')); } // Perform the action $this->{$action}(); // Did the action return anything? (HTML) if (isset($this->_output) && $this->_output != '') { $arr['html'] = $this->_output; } } if (!$arr['html']) { // Get group members based on their status // Note: this needs to happen *after* any potential actions ar performed above $view = $this->view('default', 'browse'); $view->membership_control = $this->membership_control; $view->option = $option; $view->group = $group; $view->authorized = $authorized; $this->database = App::get('db'); $view->q = Request::getVar('q', ''); $view->filter = Request::getVar('filter', ''); if (!in_array($view->filter, array('members', 'managers', 'invitees', 'pending'))) { $view->filter = ''; } $view->role_filter = Request::getVar('role_filter', ''); if ($view->authorized != 'manager' && $view->authorized != 'admin') { $view->filter = $view->filter == 'managers' ? $view->filter : 'members'; } try { // Get messages plugin access level $view->messages_acl = \Hubzero\User\Group\Helper::getPluginAccess($group, 'messages'); } catch (Exception $e) { // Plugin is not enabled. $view->messages_acl = 'nobody'; } //get all member roles $db = App::get('db'); $sql = "SELECT * FROM `#__xgroups_roles` WHERE gidNumber=" . $db->quote($group->get('gidNumber')); $db->setQuery($sql); $view->member_roles = $db->loadAssocList(); $group_inviteemails = new \Hubzero\User\Group\InviteEmail(); $view->current_inviteemails = $group_inviteemails->getInviteEmails($this->group->get('gidNumber'), true); switch ($view->filter) { case 'invitees': $view->groupusers = $view->q ? $group->search('invitees', $view->q) : $group->get('invitees'); foreach ($view->current_inviteemails as $ie) { $view->groupusers[] = $ie; } $view->managers = array(); break; case 'pending': $view->groupusers = $view->q ? $group->search('applicants', $view->q) : $group->get('applicants'); $view->managers = array(); break; case 'managers': $view->groupusers = $view->q ? $group->search('managers', $view->q) : $group->get('managers'); $view->groupusers = $view->role_filter ? \Hubzero\User\Group\Helper::search_roles($group, $view->role_filter) : $view->groupusers; $view->managers = $group->get('managers'); break; case 'members': default: $view->groupusers = $view->q ? $group->search('members', $view->q) : $group->get('members'); $view->groupusers = $view->role_filter ? \Hubzero\User\Group\Helper::search_roles($group, $view->role_filter) : $view->groupusers; $view->managers = $group->get('managers'); break; } //if we dont want to display system users //filter values through callback above and then reset array keys if ($this->display_system_users == 'no' && is_array($view->groupusers)) { $view->groupusers = array_map(array($this, "isSystemUser"), $view->groupusers); $view->groupusers = array_values(array_filter($view->groupusers)); } // sort users before display $view->groupusers = $this->sortAlphabetically($view->groupusers); $view->limit = Request::getInt('limit', $this->params->get('display_limit', 50)); $view->start = Request::getInt('limitstart', 0); $view->start = $view->limit == 0 ? 0 : $view->start; $view->no_html = Request::getInt('no_html', 0); $view->params = $this->params; if ($this->getError()) { $view->setError($this->getError()); } $arr['html'] = $view->loadTemplate(); } } //return metadata $arr['metadata']['count'] = count($group->get('members')); //do we have any pending requests $pending = $group->get("applicants"); if (count($pending) > 0 && in_array(User::get('id'), $group->get("managers"))) { $title = Lang::txt('PLG_GROUPS_MEMBERS_GROUP_HAS_REQUESTS', $group->get('description'), count($pending)); $link = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=members&filter=pending'); $arr['metadata']['alert'] = '<a class="alrt" href="' . $link . '"><span><h5>' . Lang::txt('PLG_GROUPS_MEMBERS_ALERT') . '</h5>' . $title . '</span></a>'; } // Return the output return $arr; }
/** * Display group content based on sections and active tab * * @return string */ public static function displaySectionsContent($group, $overviewSection = null) { // create view object $view = new \Hubzero\Component\View(array('name' => 'groups', 'layout' => '_content')); // need objects $content = ''; $tab = self::getTab($group); $categories = self::getSections(); $sections = self::getSectionsContent($group); // add overview section to sections if ($overviewSection !== null) { $sections[0]['html'] = $overviewSection; } // set content for tab foreach ($categories as $k => $cat) { if ($tab == $cat['name']) { $content = $sections[$k]['html']; } } //get true tab $trueTab = Request::getVar('active', 'overview'); // do overview page checks if ($tab == 'overview' && $trueTab != 'login') { //user has access to page $userHasAccess = true; //get overview page access $overviewPageAccess = \Hubzero\User\Group\Helper::getPluginAccess($group, 'overview'); //if user isnt logged in and access level is set to registered users or members only if (User::isGuest() && ($overviewPageAccess == 'registered' || $overviewPageAccess == 'members')) { $userHasAccess = false; } // if the user is not a group member or site admin if (!in_array(User::get('id'), $group->get('members')) && $overviewPageAccess == 'members') { $userHasAccess = false; } //if user does not have access if (!$userHasAccess) { // if the group is not supposed to be discoverable throw 404 if ($group->get('discoverability') == 1) { App::abort(404, Lang::txt('Group Access Denied')); return; } // return message letting user know they dont have access $content = '<p class="info">' . Lang::txt('You do not have the permissions to access this group page.') . '</p>'; } } // pass vars to view $view->group = $group; $view->content = $content; // return template return $view->loadTemplate(); }