Exemplo n.º 1
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'));
 }
Exemplo n.º 2
0
 /**
  * Set Group Home Page
  *
  * @return 	void
  */
 public function setHomeTask()
 {
     // get request vars
     $pageid = Request::getInt('pageid', 0, 'get');
     // load page model
     $page = new 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 we have an approved version
     $version = $page->approvedVersion();
     if ($version === null) {
         $this->setNotification(Lang::txt('COM_GROUPS_PAGES_PAGE_HOME_ERROR', $page->get('title')), 'error');
         App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages'));
         return;
     }
     // remove any current home page
     $pageArchive = Page\Archive::getInstance();
     $pageArchive->reset('home', 0, array('gidNumber' => $this->group->get('gidNumber')));
     // toggle home state
     $home = 1;
     if ($page->get('home') == 1) {
         $home = 0;
     }
     $page->set('home', $home);
     // store new group home page
     if (!$page->store()) {
         $this->setNotification($page->getError(), 'error');
         return $this->displayTask();
     }
     // inform user
     $this->setNotification(Lang::txt('COM_GROUPS_PAGES_PAGE_HOME_SET', $page->get('title')), 'passed');
     // redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages'));
     if ($return = Request::getVar('return', '', 'get')) {
         App::redirect(base64_decode($return));
     }
 }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 /**
  * Delete Page
  *
  * @return void
  */
 public function deleteTask()
 {
     // get request vars
     $ids = Request::getVar('id', array());
     // delete each module
     foreach ($ids as $pageid) {
         // load modules
         $page = new Page($pageid);
         // cant delete home
         if ($page->get('home') == 1) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_CANT_DELETE_HOME'), 'error');
             return;
         }
         //set to deleted state
         $page->set('state', $page::APP_STATE_DELETED);
         // set ordering to 999 when deleting
         $page->set('ordering', 999);
         // save module
         if (!$page->store(true)) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), $page->getError(), 'error');
             return;
         }
     }
     // log change
     Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'group_page_deleted', 'comments' => $ids));
     //inform user & redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_DELETED'), 'passed');
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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));
 }