Пример #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
 /**
  * Save group page
  *
  * @return 	void
  */
 public function saveTask($apply = false)
 {
     Request::checkToken();
     // Get the page vars being posted
     $page = Request::getVar('page', array(), 'post');
     $version = Request::getVar('pageversion', array(), 'post', 'none', JREQUEST_ALLOWRAW);
     // are we updating or creating a new page
     $task = $page['id'] ? 'update' : 'create';
     // load page and version objects
     $this->page = new Page($page['id']);
     $this->version = new Page\Version();
     // bind new page properties
     if (!$this->page->bind($page)) {
         $this->setNotification($this->page->getError(), 'error');
         $this->editTask();
         return;
     }
     // bind new page version properties
     if (!$this->version->bind($version)) {
         $this->setNotification($this->version->getError(), 'error');
         $this->editTask();
         return;
     }
     // make sure page belongs to group
     if ($task == 'update' && !$this->page->belongsToGroup($this->group)) {
         App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH'));
     }
     // set page vars
     $this->page->set('gidNumber', $this->group->get('gidNumber'));
     // only get unique alias if not home page
     if ($this->page->get('home') == 0) {
         $this->page->set('alias', $this->page->uniqueAlias());
     }
     // update our depth
     $parent = $this->page->getParent();
     $depth = $parent->get('id') ? $parent->get('depth') + 1 : 0;
     $this->page->set('depth', $depth);
     // make sure we can create both the page and version
     if (!$this->page->check() || !$this->version->check()) {
         $error = $this->page->getError() ? $this->page->getError() : $this->version->getError();
         $this->setNotification($error, 'error');
         $this->editTask();
         return;
     }
     // our start should be our left (order) or the parents right - 1
     $start = $this->page->get('left');
     if (!$start) {
         $start = $parent->get('rgt') - 1;
     }
     // update current rights
     $sql = "UPDATE `#__xgroups_pages` SET rgt=rgt+2 WHERE rgt>" . ($start - 1) . " AND gidNumber=1053;";
     $this->database->setQuery($sql);
     $this->database->query();
     // update current lefts
     $sql2 = "UPDATE `#__xgroups_pages` SET lft=lft+2 WHERE lft>" . ($start - 1) . " AND gidNumber=1053;";
     $this->database->setQuery($sql2);
     $this->database->query();
     // set this pages left & right
     $this->page->set('lft', $start);
     $this->page->set('rgt', $start + 1);
     // save page settings
     if (!$this->page->store(true)) {
         $this->setNotification($this->page->getError(), 'error');
         $this->editTask();
         return;
     }
     if (!is_object($this->group->params)) {
         $this->group->params = new \Hubzero\Config\Registry($this->group->params);
     }
     $this->version->set('page_trusted', $this->group->params->get('page_trusted', 0));
     // get currrent version #
     $currentVersionNumber = $this->page->version() ? $this->page->version()->get('version') : 0;
     // did the module content change?
     $contentChanged = false;
     $oldContent = $this->page->version() ? trim($this->page->version()->get('content')) : '';
     $newContent = isset($version['content']) ? trim($version['content']) : '';
     if (!$this->version->get('page_trusted', 0)) {
         $newContent = Page\Version::purify($newContent, $this->group->isSuperGroup());
     }
     // is the new and old content different?
     if ($oldContent != $newContent) {
         $contentChanged = true;
     }
     // set page version vars
     $this->version->set('pageid', $this->page->get('id'));
     $this->version->set('version', $currentVersionNumber + 1);
     $this->version->set('created', Date::toSql());
     $this->version->set('created_by', User::get('id'));
     $this->version->set('approved', 1);
     $this->version->set('approved_on', Date::toSql());
     $this->version->set('approved_by', User::get('id'));
     // if we have php or script tags we must get page approved by admin
     // check the $newContent var since its already been purified
     // and has has php/script tags removed if not super group
     if (strpos($newContent, '<?') !== false || strpos($newContent, '<?php') !== false || strpos($newContent, '<script') !== false) {
         $this->version->set('approved', 0);
         $this->version->set('approved_on', NULL);
         $this->version->set('approved_by', NULL);
     }
     // only create a new version and send approve notif if content has changed
     if ($contentChanged) {
         // check version again (because were not on store() method)
         if (!$this->version->check()) {
             $this->setNotification($this->version->getError(), 'error');
             $this->editTask();
             return;
         }
         // save version settings
         // dont run check on version store, skips onContentBeforeSave in Html format hadler
         if (!$this->version->store(false, $this->group->isSuperGroup())) {
             $this->setNotification($this->version->getError(), 'error');
             $this->editTask();
             return;
         }
         // send to approvers
         if ($this->version->get('approved', 0) == 0) {
             Helpers\Pages::sendApproveNotification('page', $this->page);
         }
     }
     // check page back in
     Helpers\Pages::checkin($this->page->get('id'));
     // redirect to return url
     if ($return = Request::getVar('return', '', 'post')) {
         $this->setNotification(Lang::txt('COM_GROUPS_PAGES_PAGE_SAVED', $task), 'passed');
         App::redirect(base64_decode($return));
         return;
     }
     // are we applying or saving?
     if ($apply) {
         $notification = Lang::txt('COM_GROUPS_PAGES_PAGE_SAVED_AND_LINK', $task, $this->page->url());
         $redirect = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages&task=edit&pageid=' . $this->page->get('id'));
     } else {
         $notification = Lang::txt('COM_GROUPS_PAGES_PAGE_SAVED', $task);
         $redirect = Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&controller=pages');
     }
     // Push success message and redirect
     $this->setNotification($notification, 'passed');
     App::redirect($redirect);
 }
Пример #4
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;
 }