예제 #1
0
 /**
  * Build default home page object,
  * Check to see if group have a home page override
  *
  * @param    object    $group    \Hubzero\User\Group Object
  * @param    array     $pages    \Hubzero\Base\ItemList
  * @return   object
  */
 public static function addHomePage($group, $pages = null)
 {
     // check to see if we have a home page override
     if ($pages->fetch('home', 1) !== null) {
         $home = $pages->fetch('home', 1);
         $home->set('alias', 'overview');
         return $pages;
     }
     // create page object
     $home = new Page(0);
     $home->set('id', 0)->set('gidNumber', $group->get('gidNumber'))->set('title', 'Home')->set('alias', 'overview')->set('ordering', 0)->set('state', 1)->set('privacy', 'default')->set('home', 1)->set('parent', 0);
     // create page version object
     $homeVersion = new Page\Version(0);
     $homeVersion->set('pageid', 0)->set('version', 1)->set('approved', 1)->set('content', self::getDefaultHomePage($group));
     // add the version to home page object
     $home->versions()->add($homeVersion);
     // add default home page to view
     $pages->add($home);
     // return updated pages
     return $pages;
 }
예제 #2
0
 /**
  * Saves changes to a group or saves a new entry if creating
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $g = Request::getVar('group', array(), 'post', 'none', 2);
     $g = $this->_multiArrayMap('trim', $g);
     // Instantiate a Group object
     $group = new Group();
     // Is this a new entry or updating?
     $isNew = false;
     if (!$g['gidNumber']) {
         $isNew = true;
         // Set the task - if anything fails and we re-enter edit mode
         // we need to know if we were creating new or editing existing
         $this->_task = 'new';
         $before = new Group();
     } else {
         $this->_task = 'edit';
         // Load the group
         $group->read($g['gidNumber']);
         $before = clone $group;
     }
     $task = $this->_task == 'edit' ? 'edit' : 'create';
     if (!$this->authorize($task, $group)) {
         return;
     }
     // Check for any missing info
     if (!$g['cn']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_ID'));
     }
     if (!$g['description']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_TITLE'));
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     $g['cn'] = strtolower($g['cn']);
     // Ensure the data passed is valid
     if (!$this->_validCn($g['cn'], true)) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_INVALID_ID'));
     }
     //only check if cn exists if we are creating or have changed the cn
     if ($this->_task == 'new' || $group->get('cn') != $g['cn']) {
         if (Group::exists($g['cn'], true)) {
             $this->setError(Lang::txt('COM_GROUPS_ERROR_GROUP_ALREADY_EXIST'));
         }
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     // group params
     $gparams = new Registry($group->get('params'));
     $gparams->merge(new Registry($g['params']));
     // set membership control param
     $membership_control = isset($g['params']['membership_control']) ? 1 : 0;
     $gparams->set('membership_control', $membership_control);
     $params = $gparams->toString();
     // Set the group changes and save
     $group->set('cn', $g['cn']);
     $group->set('type', $g['type']);
     if ($isNew) {
         $group->create();
         $group->set('published', 1);
         $group->set('approved', 1);
         $group->set('created', Date::toSql());
         $group->set('created_by', User::get('id'));
         $group->add('managers', array(User::get('id')));
         $group->add('members', array(User::get('id')));
     }
     $group->set('description', $g['description']);
     $group->set('discoverability', $g['discoverability']);
     $group->set('join_policy', $g['join_policy']);
     $group->set('public_desc', $g['public_desc']);
     $group->set('private_desc', $g['private_desc']);
     $group->set('restrict_msg', $g['restrict_msg']);
     $group->set('logo', $g['logo']);
     $group->set('plugins', $g['plugins']);
     $group->set('discussion_email_autosubscribe', $g['discussion_email_autosubscribe']);
     $group->set('params', $params);
     $group->update();
     // create home page
     if ($isNew) {
         // create page
         $page = new Page(array('gidNumber' => $group->get('gidNumber'), 'parent' => 0, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'alias' => 'overview', 'title' => 'Overview', 'state' => 1, 'privacy' => 'default', 'home' => 1));
         $page->store(false);
         // create page version
         $version = new Page\Version(array('pageid' => $page->get('id'), 'version' => 1, 'content' => "<!-- {FORMAT:HTML} -->\n<p>[[Group.DefaultHomePage()]]</p>", 'created' => Date::of('now')->toSql(), 'created_by' => User::get('id'), 'approved' => 1));
         $version->store(false);
     }
     // Get plugins
     Event::trigger('groups.onGroupAfterSave', array($before, $group));
     // log edit
     Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => 'group_edited', 'comments' => 'edited by administrator'));
     // handle special groups
     if ($group->isSuperGroup()) {
         $this->_handleSuperGroup($group);
         // git lab stuff
         $this->_handSuperGroupGitlab($group);
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_GROUPS_SAVED'));
 }
예제 #3
0
 /**
  * Restore Page Version
  *
  * @return  void
  */
 public function restoreTask()
 {
     // get reqest vars
     $pageid = Request::getInt('pageid', 0, 'get');
     $version = Request::getInt('version', null, '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_PAGE_NOT_AUTH'));
     }
     // load page version
     $pageVersion = $page->version($version);
     // do we have a page version
     if ($pageVersion === null) {
         App::abort(404, Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_NOT_FOUND'));
     }
     // get the current version for this page
     $currentVersionNumber = $page->version('current')->get('version');
     // duplicate page version unsetting the id & updating version #
     $newVersion = clone $pageVersion;
     $newVersion->set('id', null);
     $newVersion->set('version', $currentVersionNumber + 1);
     // attempt to save new version
     if (!$newVersion->store(false, $this->group->isSuperGroup())) {
         $this->setNotification($newVersion->getError(), 'error');
         $this->versionsTask();
         return;
     }
     // redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages&task=versions&pageid=' . $page->get('id')), Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_RESTORED', $page->get('title'), $version, Date::of($pageVersion->get('created'))->format('M d, Y @ g:ia')), 'passed');
 }
예제 #4
0
 /**
  * Set page state
  *
  * @return 	void
  */
 public function setStateTask($state = 1, $status = 'published')
 {
     //get request vars
     $pageid = Request::getInt('pageid', 0, 'get');
     // load page model
     $page = new \Components\Groups\Models\Page($pageid);
     // make sure its out page
     if (!$page->belongsToGroup($this->group)) {
         App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH'));
     }
     // make sure state is a valid state
     if (!in_array($state, array(0, 1, 2))) {
         $state = 1;
     }
     // set the page state
     $page->set('state', $state);
     // make sure the home page cant be deleted
     if ($page->get('home') == 1 && $page->get('state') != 1) {
         $page->set('state', 1);
     }
     // save
     if (!$page->store(false)) {
         $this->setNotification($page->getError(), 'error');
         $this->displayTask();
         return;
     }
     // get page children
     $children = $page->getChildren();
     // if we are publishing/unpublishing
     if ($state == 0 || $state == 1) {
         // lets mark each child the same as parent
         foreach ($children as $child) {
             $child->set('state', $state);
             $child->store(false);
         }
     } else {
         if ($state == 2) {
             // update the first childs parent
             if ($firstChild = $children->first()) {
                 $firstChild->set('parent', $page->get('parent'));
                 $firstChild->store(false);
             }
             // adjust depth foreach child
             // the proper depth is needed when viewing pages
             foreach ($children as $child) {
                 $child->set('depth', $child->get('depth') - 1);
                 $child->store(false);
             }
         }
     }
     //inform user & redirect
     $return = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages');
     if ($r = Request::getVar('return', '', 'get')) {
         $return = base64_decode($r);
     }
     App::redirect($return, Lang::txt('COM_GROUPS_PAGES_PAGE_STATUS_CHANGE', $status));
 }
예제 #5
0
 /**
  * Get Parents Recursively
  *
  * @param  [type] $page      [description]
  * @param  string $direction [description]
  * @return [type]            [description]
  */
 public function getRecursiveParents($page, $sort = 'ASC')
 {
     // new item list object to store parents
     // this way we have access to all page vars
     $parents = new ItemList();
     // starting at current page loop through in
     // reverse order until our parent page doesnt have a parent
     while ($page->get('parent') != 0) {
         $page = new Page($page->get('parent'));
         $parents->add($page);
     }
     // return parents
     return $sort == 'ASC' ? $parents->reverse() : $parents;
 }
예제 #6
0
 /**
  * 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;
 }
예제 #7
0
 /**
  *  Save group settings
  *
  * @return 		void
  */
 public function saveTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_CREATE_MUST_BE_LOGGED_IN'));
         return;
     }
     Request::checkToken();
     // Incoming
     $g_gidNumber = Request::getInt('gidNumber', 0, 'post');
     $c_gidNumber = Request::getVar('gidNumber', 0, 'post');
     if ((string) $g_gidNumber !== (string) $c_gidNumber) {
         App::abort(404, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     if (!$g_gidNumber && !User::authorise('core.create', $this->_option) || $g_gidNumber && !User::authorise('core.edit', $this->_option)) {
         return App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'), 'warning');
     }
     $g_cn = trim(Request::getVar('cn', '', 'post'));
     $g_description = preg_replace('/\\s+/', ' ', trim(Request::getVar('description', Lang::txt('NONE'), 'post')));
     $g_discoverability = Request::getInt('discoverability', 0, 'post');
     $g_public_desc = Sanitize::stripScripts(trim(Request::getVar('public_desc', '', 'post', 'none', 2)));
     $g_private_desc = Sanitize::stripScripts(trim(Request::getVar('private_desc', '', 'post', 'none', 2)));
     $g_restrict_msg = Sanitize::stripScripts(trim(Request::getVar('restrict_msg', '', 'post', 'none', 2)));
     $g_join_policy = Request::getInt('join_policy', 0, 'post');
     $tags = trim(Request::getVar('tags', ''));
     $lid = Request::getInt('lid', 0, 'post');
     $customization = Request::getVar('group', '', 'POST', 'none', 2);
     $plugins = Request::getVar('group_plugin', '', 'POST');
     $params = Request::getVar('params', array(), 'POST');
     $g_discussion_email_autosubscribe = Request::getInt('discussion_email_autosubscribe', 0, 'post');
     //Check authorization
     if ($this->_authorize() != 'manager' && $g_gidNumber != 0 && !$this->_authorizedForTask('group.edit')) {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     //are we editing or creating
     if ($g_gidNumber) {
         $group = Group::getInstance($g_gidNumber);
         $this->_task = 'edit';
         $before = Group::getInstance($g_gidNumber);
     } else {
         $this->_task = 'new';
         $group = new Group();
         $before = new Group();
     }
     // Check for any missing info
     if (!$g_cn) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_DETAILS_FIELD_CN'), 'error');
     }
     if (!$g_description) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_DETAILS_FIELD_DESCRIPTION'), 'error');
     }
     // Ensure the data passed is valid
     if ($g_cn == 'new' || $g_cn == 'browse') {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'), 'error');
     }
     if (!$this->_validCn($g_cn)) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'), 'error');
     }
     if ($this->_task == 'new' && Group::exists($g_cn, true)) {
         $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_ID_TAKEN'), 'error');
     }
     // Get the logo
     $logo = '';
     if (isset($customization['logo'])) {
         $logo_parts = explode("/", $customization['logo']);
         $logo = array_pop($logo_parts);
     }
     // Plugin settings
     $plugin_access = '';
     foreach ($plugins as $plugin) {
         $plugin_access .= $plugin['name'] . '=' . $plugin['access'] . ',' . "\n";
     }
     // Run content through validation and spam filters
     if (trim($g_public_desc)) {
         $results = Event::trigger('content.onContentBeforeSave', array('com_groups.group.public_desc', &$g_public_desc, $this->_task == 'new'));
         foreach ($results as $result) {
             if ($result === false) {
                 $this->setNotification(Lang::txt('COM_GROUPS_SAVE_ERROR_FAILED_VALIDATION'), 'error');
                 break;
             }
         }
     }
     // Push back into edit mode if any errors
     if ($this->getNotifications()) {
         $group->set('cn', $g_cn);
         $group->set('description', $g_description);
         $group->set('public_desc', $g_public_desc);
         $group->set('private_desc', $g_private_desc);
         $group->set('join_policy', $g_join_policy);
         $group->set('restrict_msg', $g_restrict_msg);
         $group->set('discoverability', $g_discoverability);
         $group->set('discussion_email_autosubscribe', $g_discussion_email_autosubscribe);
         $group->set('logo', $logo);
         $group->set('plugins', $plugin_access);
         $this->lid = $lid;
         $this->group = $group;
         $this->tags = $tags;
         $this->editTask();
         return;
     }
     // Build the e-mail message
     if ($this->_task == 'new') {
         $subject = Lang::txt('COM_GROUPS_SAVE_EMAIL_REQUESTED_SUBJECT', $g_cn);
         $type = 'groups_created';
     } else {
         $subject = Lang::txt('COM_GROUPS_SAVE_EMAIL_UPDATED_SUBJECT', $g_cn);
         $type = 'groups_changed';
     }
     if ($this->_task == 'new') {
         $group->set('cn', $g_cn);
         $group->set('type', 1);
         $group->set('published', 1);
         $group->set('approved', $this->config->get('auto_approve', 1));
         $group->set('created', Date::toSql());
         $group->set('created_by', User::get('id'));
         $group->add('managers', array(User::get('id')));
         $group->add('members', array(User::get('id')));
         $group->create();
     }
     // merge incoming settings with existing params
     $params = new Registry($params);
     $gParams = new Registry($group->get('params'));
     $gParams->merge($params);
     //set group vars & Save group
     $group->set('description', $g_description);
     $group->set('public_desc', $g_public_desc);
     $group->set('private_desc', $g_private_desc);
     $group->set('join_policy', $g_join_policy);
     $group->set('restrict_msg', $g_restrict_msg);
     $group->set('discoverability', $g_discoverability);
     $group->set('logo', $logo);
     $group->set('plugins', $plugin_access);
     $group->set('discussion_email_autosubscribe', $g_discussion_email_autosubscribe);
     $group->set('params', $gParams->toString());
     $group->update();
     // Process tags
     $gt = new Tags($group->get('gidNumber'));
     $gt->setTags($tags, User::get('id'));
     // Rename the temporary upload directory if it exist
     $log_comments = '';
     Event::trigger('groups.onGroupAfterSave', array($before, $group));
     if ($this->_task == 'new') {
         if ($lid != $group->get('gidNumber')) {
             $config = $this->config;
             $bp = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS);
             if (is_dir($bp . DS . $lid)) {
                 rename($bp . DS . $lid, $bp . DS . $group->get('gidNumber'));
             }
         }
         $log_action = 'group_created';
         // Trigger the functions that delete associated content
         // Should return logs of what was deleted
         $logs = Event::trigger('groups.onGroupNew', array($group));
         if (count($logs) > 0) {
             $log_comments .= implode('', $logs);
         }
     } else {
         $log_action = 'group_edited';
     }
     // log invites
     Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => $log_action, 'comments' => $log_comments));
     // Build the e-mail message
     // Note: this is done *before* pushing the changes to the group so we can show, in the message, what was changed
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'saved'));
     $eview->option = $this->_option;
     $eview->user = User::getRoot();
     $eview->group = $group;
     $message['plaintext'] = $eview->loadTemplate();
     $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
     $eview->setLayout('saved');
     $message['multipart'] = $eview->loadTemplate();
     $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
     // Get the administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Get the "from" info
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name)), 'email' => Config::get('mailfrom'));
     //only email managers if updating group
     if ($type == 'groups_changed') {
         // build array of managers
         $managers = $group->get('managers');
         // create new message
         Plugin::import('xmessage');
         if (!Event::trigger('onSendMessage', array($type, $subject, $message, $from, $managers, $this->_option))) {
             $this->setNotification(Lang::txt('GROUPS_ERROR_EMAIL_MANAGERS_FAILED'), 'error');
         }
     }
     //only inform site admin if the group wasn't auto-approved
     if (!$this->config->get('auto_approve', 1) && $group->get('approved') == 0) {
         // create approval subject
         $subject = Lang::txt('COM_GROUPS_SAVE_WAITING_APPROVAL', Config::get('sitename'));
         // build approval message
         $link = 'https://' . trim($_SERVER['HTTP_HOST'], DS) . DS . 'groups' . DS . $group->get('cn');
         $link2 = 'https://' . trim($_SERVER['HTTP_HOST'], DS) . DS . 'administrator';
         $html = Lang::txt('COM_GROUPS_SAVE_WAITING_APPROVAL_DESC', $group->get('description'), $link, $link2);
         $plain = Lang::txt('COM_GROUPS_SAVE_WAITING_APPROVAL_DESC', $group->get('description'), $link, $link2);
         // create new message
         $message = new \Hubzero\Mail\Message();
         // build message object and send
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($emailadmin)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_pending_approval')->addHeader('X-Component-ObjectId', $group->get('gidNumber'))->addPart($plain, 'text/plain')->addPart($html, 'text/html')->send();
     }
     // create home page
     if ($this->_task == 'new') {
         // create page
         $page = new Page(array('gidNumber' => $group->get('gidNumber'), 'parent' => 0, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'alias' => 'overview', 'title' => 'Overview', 'state' => 1, 'privacy' => 'default', 'home' => 1));
         $page->store(false);
         // create page version
         $version = new Page\Version(array('pageid' => $page->get('id'), 'version' => 1, 'content' => "<!-- {FORMAT:HTML} -->\n<p>[[Group.DefaultHomePage()]]</p>", 'created' => Date::toSql(), 'created_by' => User::get('id'), 'approved' => 1));
         $version->store(false);
     }
     // Show success message to user
     if ($this->_task == 'new') {
         $this->setNotification(Lang::txt('COM_GROUPS_CREATED_SUCCESS', $group->get('description')), 'passed');
     } else {
         $this->setNotification(Lang::txt('COM_GROUPS_UPDATED_SUCCESS', $group->get('description')), 'passed');
     }
     // Redirect back to the group page
     App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $group->get('cn')));
     return;
 }
예제 #8
0
    /**
     * Preview Group Module
     *
     * @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_MODULES_AUTHORIZED_APPROVERS_ONLY'), 'error');
            return;
        }
        // get reqest vars
        $moduleid = Request::getInt('moduleid', 0, 'get');
        // page object
        $module = new Module($moduleid);
        // make sure page belongs to this group
        if (!$module->belongsToGroup($this->group)) {
            App::abort(403, Lang::txt('COM_GROUPS_MODULES_NOT_AUTHORIZED'));
        }
        // get first module menu's page id
        $pageid = $module->menu()->first()->get('pageid');
        // check if pageid 0
        if ($pageid == 0) {
            // get a list of all pages
            $pageArchive = Page\Archive::getInstance();
            $pages = $pageArchive->pages('list', array('gidNumber' => $this->group->get('gidNumber'), 'state' => array(1), 'orderby' => 'ordering'));
            // get first page
            $pageid = $pages->first()->get('id');
        }
        // load page
        $page = new Page($pageid);
        // load page version
        $content = $page->version()->content('parsed');
        // create new group document helper
        $groupDocument = new Helpers\Document();
        // strip out scripts & php tags if not super group
        if (!$this->group->isSuperGroup()) {
            $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
            $content = preg_replace('/<\\?[\\s\\S]*?\\?>/', '', $content);
        }
        // are we allowed to display group modules
        if (!$this->group->isSuperGroup() && !$this->config->get('page_modules', 0)) {
            $groupDocument->set('allowed_tags', array());
        }
        // set group doc needed props
        // parse and render content
        $groupDocument->set('group', $this->group)->set('page', $page)->set('document', $content)->set('allMods', true)->parse()->render();
        // get doc content
        $content = $groupDocument->output();
        // only parse php if Super Group
        if ($this->group->isSuperGroup()) {
            // run as closure to ensure no $this scope
            $eval = function () use($content) {
                ob_start();
                unset($this);
                eval("?> {$content} <?php ");
                $content = ob_get_clean();
                return $content;
            };
            $content = $eval();
        }
        // get group css
        $pageCss = Helpers\View::getPageCss($this->group);
        $css = '';
        foreach ($pageCss as $p) {
            $css .= '<link rel="stylesheet" href="' . $p . '" />';
        }
        // output html
        $html = '<!DOCTYPE html>
				<html>
					<head>
						<title>' . $this->group->get('description') . '</title>
						' . $css . '
					</head>
					<body>
						' . $content . '
					</body>
				</html>';
        //echo content and exit
        echo $html;
        exit;
    }
예제 #9
0
 /**
  * Return a URL to this page
  *
  * @param   string  $to  Format
  * @return  string
  */
 public function url($to = 'raw')
 {
     $page = new Page($this->get('pageid'));
     $group = \Hubzero\User\Group::getInstance($page->get('gidNumber'));
     $url = 'index.php?option=com_groups&cn=' . $group->get('cn');
     switch ($to) {
         case 'restore':
             $url .= '&controller=pages&task=restore&pageid=' . $page->get('id') . '&version=' . $this->get('version');
             break;
         case 'raw':
         default:
             $url .= '&controller=pages&task=raw&pageid=' . $page->get('id') . '&version=' . $this->get('version');
     }
     return \Route::url($url);
 }
예제 #10
0
 /**
  * Restore Page Version
  *
  * @return  void
  */
 public function restoreTask()
 {
     // get reqest vars
     $pageid = Request::getInt('pageid', 0, 'get');
     $version = Request::getInt('version', null, '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_PAGE_NOT_AUTH'));
     }
     // load page version
     $pageVersion = $page->version($version);
     // do we have a page version
     if ($pageVersion === null) {
         App::abort(404, Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_NOT_FOUND'));
     }
     // get the current version for this page
     $currentVersionNumber = $page->version('current')->get('version');
     // duplicate page version unsetting the id & updating version #
     $newVersion = clone $pageVersion;
     $newVersion->set('id', null);
     $newVersion->set('version', $currentVersionNumber + 1);
     // attempt to save new version
     if (!$newVersion->store(false, $this->group->isSuperGroup())) {
         $this->setNotification($newVersion->getError(), 'error');
         return $this->versionsTask();
     }
     // Log activity
     $recipients = array(['group', $this->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'updated', 'scope' => 'group.page', 'scope_id' => $page->get('id'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_PAGE_RESTORED', $page->get('title'), $version, '<a href="' . $url . '">' . $this->group->get('description') . '</a>'), 'details' => array('title' => $page->get('title'), 'url' => $url, 'gidNumber' => $this->group->get('gidNumber'))], 'recipients' => $recipients]);
     // redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages&task=versions&pageid=' . $page->get('id')), Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_RESTORED', $page->get('title'), $version, Date::of($pageVersion->get('created'))->format('M d, Y @ g:ia')), 'passed');
 }
예제 #11
0
 /**
  * Set page state
  *
  * @param   integer  $state
  * @param   string   $status
  * @return  void
  */
 public function setStateTask($state = 1, $status = 'published')
 {
     //get request vars
     $pageid = Request::getInt('pageid', 0, 'get');
     // load page model
     $page = new \Components\Groups\Models\Page($pageid);
     // make sure its out page
     if (!$page->belongsToGroup($this->group)) {
         App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH'));
     }
     // make sure state is a valid state
     if (!in_array($state, array(0, 1, 2))) {
         $state = 1;
     }
     // set the page state
     $page->set('state', $state);
     // make sure the home page cant be deleted
     if ($page->get('home') == 1 && $page->get('state') != 1) {
         $page->set('state', 1);
     }
     // save
     if (!$page->store(false)) {
         $this->setNotification($page->getError(), 'error');
         return $this->displayTask();
     }
     // get page children
     $children = $page->getChildren();
     // if we are publishing/unpublishing
     if ($state == 0 || $state == 1) {
         // lets mark each child the same as parent
         foreach ($children as $child) {
             $child->set('state', $state);
             $child->store(false);
         }
     } else {
         if ($state == 2) {
             // update the first childs parent
             if ($firstChild = $children->first()) {
                 $firstChild->set('parent', $page->get('parent'));
                 $firstChild->store(false);
             }
             // adjust depth foreach child
             // the proper depth is needed when viewing pages
             foreach ($children as $child) {
                 $child->set('depth', $child->get('depth') - 1);
                 $child->store(false);
             }
         }
     }
     //inform user & redirect
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages');
     if ($r = Request::getVar('return', '', 'get')) {
         $url = base64_decode($r);
     }
     // Log activity
     $recipients = array(['group', $this->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => $state == 2 ? 'deleted' : 'updated', 'scope' => 'group.page', 'scope_id' => $page->get('id'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_PAGE_' . ($state == 2 ? 'DELETED' : ($state == 1 ? 'PUBLISHED' : 'UNPUBLISHED')), $page->get('title'), '<a href="' . $url . '">' . $this->group->get('description') . '</a>'), 'details' => array('title' => $page->get('title'), 'url' => $url, 'gidNumber' => $this->group->get('gidNumber'))], 'recipients' => $recipients]);
     App::redirect($url, Lang::txt('COM_GROUPS_PAGES_PAGE_STATUS_CHANGE', $status));
 }