/** * 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]'); } // add required helper lib require_once PATH_CORE . DS . 'components' . DS . 'com_groups' . DS . 'helpers' . DS . 'pages.php'; // get default home page $html = \Components\Groups\Helpers\Pages::getDefaultHomePage($this->group); //return rendered events return $html; }
/** * Preview Group Page * * @return void */ public function previewTask() { // get reqest vars $pageid = Request::getInt('pageid', 0, 'get'); $version = Request::getInt('version', 0, 'get'); if (!$pageid) { App::abort(404, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_FOUND')); } if ((string) $pageid !== (string) Request::getVar('pageid', 0, 'get')) { App::abort(404, Lang::txt('COM_GROUPS_ERROR_NO_ID')); } // page object $page = new Page($pageid); // render preview echo Helpers\Pages::generatePreview($page, $version); exit; }
/** * Preview Group Page * * @return void */ public function previewTask() { // make sure we are approvers if (!Helpers\Pages::isPageApprover()) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_MUST_BE_AUTHORIZED'), 'error'); return; } // get reqest vars $pageid = Request::getInt('pageid', 0, 'get'); $version = Request::getInt('version', 0, 'get'); // page object $page = new Page($pageid); // make sure page belongs to this group if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_NOT_AUTH')); } // get preview echo Helpers\Pages::generatePreview($page, $version); exit; }
/** * View Group * * @return array */ public function viewTask() { // set the needed layout $this->view->setLayout('view'); // validate the incoming cname if (!$this->_validCn($this->cn, true)) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND')); } // Load the group object $this->view->group = Group::getInstance($this->cn); // check to make sure we were able to load group if (!is_object($this->view->group) || !$this->view->group->get('gidNumber') || !$this->view->group->get('cn')) { $this->suggestNonExistingGroupTask(); return; } // Ensure it's an allowable group type to display if (!in_array($this->view->group->get('type'), array(1, 3))) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND')); } // ensure the group is published if ($this->view->group->get('published') != 1) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND')); } // Ensure the group has been published or has been approved if ($this->view->group->get('approved') != 1) { //get list of members & managers & invitees $managers = $this->view->group->get('managers'); $members = $this->view->group->get('members'); $invitees = $this->view->group->get('invitees'); $members_invitees = array_merge($members, $invitees); $managers_members_invitees = array_merge($managers, $members, $invitees); //if user is not member, manager, or invitee deny access if (!in_array(User::get('id'), $managers_members_invitees)) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND')); } //if user is NOT manager but member or invitee if (!in_array(User::get('id'), $managers) && in_array(User::get('id'), $members_invitees)) { $this->unapprovedGroupTask(); return; } //set notification and clear after $this->setNotification(Lang::txt('COM_GROUPS_PENDING_APPROVAL_WARNING'), 'warning'); } // Get the group params $this->view->gparams = new \Hubzero\Config\Registry($this->view->group->get('params')); // Check authorization $this->view->authorized = Helpers\View::authorize($this->view->group); // get active tab $this->view->tab = Helpers\View::getTab($this->view->group); $this->view->trueTab = strtolower(Request::getVar('active', 'overview')); // get group pages if any $pageArchive = Page\Archive::getInstance(); $pages = $pageArchive->pages('list', array('gidNumber' => $this->view->group->get('gidNumber'), 'state' => array(0, 1), 'orderby' => 'lft ASC')); // custom error handling for super groups Helpers\View::attachCustomErrorHandler($this->view->group); // add the overview content $overviewContent = ''; $activePage = null; if ($this->view->tab == 'overview') { // add home page to pages list $pages = Helpers\Pages::addHomePage($this->view->group, $pages); // fetch the active page $activePage = Helpers\Pages::getActivePage($this->view->group, $pages); // are we on the login if ($this->view->trueTab == 'login') { $overviewContent = Helpers\View::superGroupLogin($this->view->group); } // check to see if we have super group component or php page if ($overviewContent == null && $this->config->get('super_components', 0)) { $overviewContent = Helpers\View::superGroupComponents($this->view->group, $this->view->trueTab); } // do we have group php pages if ($overviewContent == null) { $overviewContent = Helpers\View::superGroupPhpPages($this->view->group); } //set overview content if ($overviewContent == null) { $overviewContent = Helpers\Pages::displayPage($this->view->group, $activePage); } } // build the title $this->_buildTitle($pages); // build pathway $this->_buildPathway($pages); //set some vars for view $this->view->title = $this->_title; $this->view->content = Helpers\View::displaySectionsContent($this->view->group, $overviewContent); $this->view->activePage = $activePage; $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array(); //is this a super group? if ($this->view->group->isSuperGroup()) { //use group template file if we have it Request::setVar('tmpl', 'group'); // must call here cause otherwise doesnt load template $this->view->css()->js(); // load super group template // parse & render $superGroupTemplate = new Helpers\Template(); $superGroupTemplate->set('group', $this->view->group)->set('tab', $this->view->trueTab)->set('content', $this->view->content)->set('page', $this->view->activePage)->parse()->render(); // echo content & stop execution return $superGroupTemplate->output(true); } //display view $this->view->display(); }
if (count($this->pages) > 0) { ?> <?php foreach ($this->pages as $page) { ?> <?php // get page details $category = $this->categories->fetch('id', $page->get('category')); $version = $page->versions()->first(); // page class $cls = ''; if ($page->get('home') == 1) { $cls .= ' root'; } //get file check outs $checkout = \Components\Groups\Helpers\Pages::getCheckout($page->get('id')); ?> <li id="<?php echo $page->get('id'); ?> " class="<?php echo $cls; ?> "> <?php $this->view('item')->set('page', $page)->set('category', $category)->set('group', $this->group)->set('version', $version)->set('checkout', $checkout)->display(); // display page children if ($children = $page->get('children')) { $this->view('list')->set('level', 10)->set('pages', $children)->set('categories', $this->categories)->set('group', $this->group)->display(); } ?>
/** * Approve a group page * * @return void */ public function approveTask() { // make sure we are approvers if (!Helpers\Pages::isPageApprover()) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_MODULES_AUTHORIZED_APPROVERS_ONLY'), 'error'); return; } // get request vars $id = Request::getInt('id', 0); // load page $module = new Module($id); // make sure version is unapproved if ($module->get('approved') == 1) { //inform user & redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_MODULES_ALREADY_APPROVED'), 'warning'); return; } // set approved and approved date and approver $module->set('approved', 1); $module->set('approved_on', Date::toSql()); $module->set('approved_by', User::get('id')); if (!is_object($this->group->params)) { $this->group->params = new \Hubzero\Config\Registry($this->group->params); } $module->set('page_trusted', $this->group->params->get('page_trusted', 0)); // DONT RUN CHECK ON STORE METHOD (pass false as first arg to store() method) $module->store(false, $this->group->isSuperGroup()); // send approved notifcation Helpers\Pages::sendApprovedNotification('module', $module); // log change Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'group_modules_approved', 'comments' => array($module->get('id')))); // inform user and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_MODULES_APPROVED'), 'passed'); }
/** * Save Module * * @return void */ public function saveTask() { // get request vars $module = Request::getVar('module', array(), 'post', 'none', JREQUEST_ALLOWRAW); $menu = Request::getVar('menu', array(), 'post'); // set gid number $module['gidNumber'] = $this->group->get('gidNumber'); // clean title & position $module['title'] = preg_replace("/[^-_ a-zA-Z0-9]+/", "", $module['title']); $module['position'] = preg_replace("/[^-_a-zA-Z0-9]+/", "", $module['position']); // get the category object $this->module = new Module($module['id']); // ordering change $ordering = null; if (isset($module['ordering']) && $module['ordering'] != $this->module->get('ordering')) { $ordering = $module['ordering']; unset($module['ordering']); } // if this is new module or were changing position, // get next order possible for position if (!isset($module['id']) || $module['id'] == '' || $module['position'] != $this->module->get('position')) { $ordering = null; $module['ordering'] = $this->module->getNextOrder($module['position']); } // did the module content change? $contentChanged = false; $oldContent = trim($this->module->get('content')); $newContent = isset($module['content']) ? trim($module['content']) : ''; if (!is_object($this->group->params)) { $this->group->params = new \Hubzero\Config\Registry($this->group->params); } if (!$this->group->params->get('page_trusted', 0)) { $newContent = Module::purify($newContent, $this->group->isSuperGroup()); } // is the new and old content different? if ($oldContent != $newContent) { $contentChanged = true; } // bind request vars to module model if (!$this->module->bind($module)) { $this->setNotification($this->module->getError(), 'error'); return $this->editTask(); } // module is approved unless contains php or scripts (checked below) $this->module->set('approved', 1); // if we have php or script tags we must get module approved by admin if (strpos($this->module->get('content'), '<?') !== false || strpos($this->module->get('content'), '<?php') !== false || strpos($this->module->get('content'), '<script') !== false) { // only change approve status if content changed if ($contentChanged) { $this->module->set('approved', 0); $this->module->set('approved_on', NULL); $this->module->set('approved_by', NULL); $this->module->set('checked_errors', 0); $this->module->set('scanned', 0); } } // set created if new module if (!$this->module->get('id')) { $this->module->set('created', Date::toSql()); $this->module->set('created_by', User::get('id')); } // set modified $this->module->set('modified', Date::toSql()); $this->module->set('modified_by', User::get('id')); // check module again (because were not on store() method) if (!$this->module->check()) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // save version settings // dont run check on module store, skips onContentBeforeSave in Html format hadler if (!$this->module->store(false, $this->group->isSuperGroup())) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // create module menu if (!$this->module->buildMenu($menu)) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // do we need to reorder if ($ordering !== null) { $move = (int) $ordering - (int) $this->module->get('ordering'); $this->module->move($move, $this->module->get('position')); } // send to approvers if unapproved if ($this->module->get('approved', 0) == 0) { Helpers\Pages::sendApproveNotification('module', $this->module); } // Push success message and redirect $this->setNotification(Lang::txt('COM_GROUPS_PAGES_MODULE_SAVED'), 'passed'); App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages#modules')); if ($return = Request::getVar('return', '', 'post')) { App::redirect(base64_decode($return)); } }
/** * Output menu * * @param [type] $pageArray [description] * @return [type] [description] */ public static function buildRecursivePageMenu($group, $pageArray) { // get overview section access $access = \Hubzero\User\Group\Helper::getPluginAccess($group, 'overview'); $out = ''; if (sizeof($pageArray) > 0) { $out = '<ul>'; foreach ($pageArray as $key => $page) { // dont show page links if there isnt an approved version if ($page->approvedVersion() === null) { continue; } // page access settings $pageAccess = $page->get('privacy') == 'default' ? $access : $page->get('privacy'); // is this the active page? $cls = Pages::isPageActive($page) ? 'active' : ''; //page menu item if ($pageAccess == 'registered' && User::isGuest() || $pageAccess == 'members' && !in_array(User::get("id"), $group->get('members'))) { $out .= "<li class=\"protected\"><span class=\"page\">" . $page->get('title') . "</span></li>"; } else { $out .= '<li class="' . $cls . '">'; $out .= '<a class="page" title="' . $page->get('title') . '" href="' . $page->url() . '">' . $page->get('title') . '</a>'; } // do we have child menu items if (!is_array($page->get('children'))) { $out .= '</li>'; } else { $out .= self::buildRecursivePageMenu($group, $page->get('children')) . '</li>'; } } $out .= '</ul>'; } return $out; }
?> <img align="left" width="20" src="<?php echo \Hubzero\User\Profile\Helper::getMemberPhoto($profile->get('uidNumber')); ?> " /> <?php } ?> <?php echo $approved_by; ?> </div> </div> <div class="version-content"> <?php echo \Components\Groups\Helpers\Pages::generatePreview($this->page, $pageVersion->get('version'), true); ?> </div> <div class="version-code"> <?php $current = explode("\n", $pageVersion->content('raw')); $previousVersion = $pageVersion->get('version') - 1; if ($previousVersion == 0) { $previous = array(); } else { $previous = $this->page->version($previousVersion); // make view OK with the LIMIT if (!empty($previous)) { $previous = explode("\n", $previous->content('raw')); } }