Ejemplo n.º 1
0
 /**
  * Render the module.
  *
  * @param   object  $module   A module object.
  * @param   array   $attribs  An array of attributes for the module (probably from the XML).
  * @return  string  The HTML content of the module output.
  */
 public function render($module, $attribs = array())
 {
     static $chrome;
     if (null !== $this->profiler) {
         $this->profiler->mark('beforeRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     // Record the scope.
     $scope = $this->app->has('scope') ? $this->app->get('scope') : null;
     // Set scope to component name
     $this->app->set('scope', $module->module);
     // Get module parameters
     $params = new Registry($module->params);
     if (isset($attribs['params'])) {
         $customparams = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
         $params->merge($customparams);
         $module->params = $params->toString();
     }
     // Get module path
     $module->module = preg_replace('/[^A-Z0-9_\\.-]/i', '', $module->module);
     $path = PATH_CORE . DS . 'modules' . DS . $module->module . DS . $module->module . '.php';
     // Load the module
     // $module->user is a check for 1.0 custom modules and is deprecated refactoring
     if (file_exists($path)) {
         $this->app['language']->load($module->module, PATH_APP . DS . 'bootstrap' . DS . $this->app['client']->name, null, false, true) || $this->app['language']->load($module->module, dirname($path), null, false, true);
         $content = '';
         ob_start();
         include $path;
         $module->content = ob_get_contents() . $content;
         ob_end_clean();
     }
     // Load the module chrome functions
     if (!$chrome) {
         $chrome = array();
     }
     include_once PATH_CORE . DS . 'templates' . DS . 'system' . DS . 'html' . DS . 'modules.php';
     $chromePath = $this->app['template']->path . DS . 'html' . DS . 'modules.php';
     if (!isset($chrome[$chromePath])) {
         if (file_exists($chromePath)) {
             include_once $chromePath;
         }
         $chrome[$chromePath] = true;
     }
     // Make sure a style is set
     if (!isset($attribs['style'])) {
         $attribs['style'] = 'none';
     }
     // Dynamically add outline style
     if ($this->outline()) {
         $attribs['style'] .= ' outline';
     }
     foreach (explode(' ', $attribs['style']) as $style) {
         $chromeMethod = 'modChrome_' . $style;
         // Apply chrome and render module
         if (function_exists($chromeMethod)) {
             $module->style = $attribs['style'];
             ob_start();
             $chromeMethod($module, $params, $attribs);
             $module->content = ob_get_contents();
             ob_end_clean();
         }
     }
     // Revert the scope
     $this->app->forget('scope');
     $this->app->set('scope', $scope);
     if (null !== $this->profiler) {
         $this->profiler->mark('afterRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     return $module->content;
 }
Ejemplo n.º 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'));
 }
Ejemplo n.º 3
0
 /**
  * Save a citation
  *
  * @return	void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $citation = array_map('trim', Request::getVar('citation', array(), 'post'));
     $exclude = Request::getVar('exclude', '', 'post');
     $rollover = Request::getInt("rollover", 0);
     $this->tags = Request::getVar('tags', '');
     $this->badges = Request::getVar('badges', '');
     $this->sponsors = Request::getVar('sponsors', array(), 'post');
     // toggle the affiliation
     if (!isset($citation['affiliated']) || $citation['affiliated'] == NULL) {
         $citation['affiliated'] = 0;
     }
     // toggle fundeby
     if (!isset($citation['fundedby']) || $citation['fundedby'] == NULL) {
         $citation['fundedby'] = 0;
     }
     // Bind incoming data to object
     $row = new Citation($this->database);
     if (!$row->bind($citation)) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     //set params
     $cparams = new Registry($this->_getParams($row->id));
     $cparams->set('exclude', $exclude);
     $cparams->set('rollover', $rollover);
     $row->params = $cparams->toString();
     // New entry so set the created date
     if (!$row->id) {
         $row->created = \Date::toSql();
     }
     // Check content for missing required data
     if (!$row->check()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Incoming associations
     $arr = Request::getVar('assocs', array(), 'post');
     $ignored = array();
     foreach ($arr as $a) {
         $a = array_map('trim', $a);
         // Initiate extended database class
         $assoc = new Association($this->database);
         //check to see if we should delete
         if (isset($a['id']) && $a['tbl'] == '' && $a['oid'] == '') {
             // Delete the row
             if (!$assoc->delete($a['id'])) {
                 throw new Exception($assoc->getError(), 500);
             }
         } else {
             if ($a['tbl'] != '' || $a['oid'] != '') {
                 $a['cid'] = $row->id;
                 // bind the data
                 if (!$assoc->bind($a)) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Check content
                 if (!$assoc->check()) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Store new content
                 if (!$assoc->store()) {
                     throw new Exception($assoc->getError(), 500);
                 }
             }
         }
     }
     //save sponsors on citation
     if ($this->sponsors) {
         $cs = new Sponsor($this->database);
         $cs->addSponsors($row->id, $this->sponsors);
     }
     //add tags & badges
     $ct = new Tags($row->id);
     $ct->setTags($this->tags, User::get('id'), 0, 1, '');
     $ct->setTags($this->badges, User::get('id'), 0, 1, 'badge');
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_SAVED'));
 }
Ejemplo n.º 4
0
 /**
  * Saves an asset group
  *
  * @apiMethod POST
  * @apiUri    /courses/assetgroup/save
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Asset group ID to edit",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Asset group title",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "New asset group"
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "State of asset group",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "description",
  * 		"description": "Short description",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "unit_id",
  * 		"description": "ID of parent unit",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "parent",
  * 		"description": "ID of parent asset group",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "params",
  * 		"description": "Parameters related to the asset group",
  * 		"type":        "array",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return    void
  */
 public function saveTask()
 {
     // Require authentication and authorization
     $this->authorizeOrFail();
     // Check for an incoming 'id'
     $id = Request::getInt('id', null);
     // Create an asset group instance
     $assetGroup = new Assetgroup($id);
     // Check to make sure we have an asset group object
     if (!is_object($assetGroup)) {
         App::abort(500, 'Failed to create an asset group object');
     }
     // We'll always save the title again, even if it's just to the same thing
     $title = $assetGroup->get('title');
     $title = !empty($title) ? $title : 'New asset group';
     // Set our variables
     $assetGroup->set('title', Request::getString('title', $title));
     $assetGroup->set('alias', strtolower(str_replace(' ', '', $assetGroup->get('title'))));
     // Save the asset group
     if (!$assetGroup->get('title')) {
         App::abort(400, 'No title provided');
     }
     $state = Request::getInt('state', null);
     if (!is_null($state)) {
         $assetGroup->set('state', $state);
     }
     $assetGroup->set('description', Request::getVar('description', $assetGroup->get('description')));
     // When creating a new asset group
     if (!$id) {
         $assetGroup->set('unit_id', Request::getInt('unit_id', 0));
         $assetGroup->set('parent', Request::getInt('parent', 0));
         $assetGroup->set('created', Date::toSql());
         $assetGroup->set('created_by', App::get('authn')['user_id']);
     }
     if (($params = Request::getVar('params', false, 'post')) || !$id) {
         $p = new Registry('');
         $db = App::get('db');
         $query = $db->getQuery(true);
         $query->select('folder AS type, element AS name, params')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->quote('plugin'))->where('state >= 0')->where('folder =' . $db->quote('courses'))->order('ordering');
         if ($plugins = $db->setQuery($query)->loadObjectList()) {
             foreach ($plugins as $plugin) {
                 $default = new Registry($plugin->params);
                 foreach ($default->toArray() as $k => $v) {
                     if (substr($k, 0, strlen('default_')) == 'default_') {
                         $p->set(substr($k, strlen('default_')), $default->get($k, $v));
                     }
                 }
             }
         }
         if ($params) {
             $p->parse($params);
         }
         $assetGroup->set('params', $p->toString());
     }
     // Save the asset group
     if (!$assetGroup->store()) {
         App::abort(500, 'Asset group save failed');
     }
     // Return message
     $this->send(['assetgroup_id' => $assetGroup->get('id'), 'assetgroup_title' => $assetGroup->get('title'), 'assetgroup_state' => (int) $assetGroup->get('state'), 'assetgroup_style' => 'display:none', 'course_id' => $this->course_id, 'offering_alias' => $this->offering_alias], $id ? 200 : 201);
 }
Ejemplo 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;
 }
Ejemplo n.º 6
0
 /**
  * Save an Import
  *
  * @param   boolean  $redirect  Redirect after save?
  * @return  void
  */
 public function saveTask($redirect = true)
 {
     // check token
     Session::checkToken();
     // Get request vars
     $import = Request::getVar('import', array());
     $hooks = Request::getVar('hooks', array());
     $params = Request::getVar('params', array());
     $fields = Request::getVar('mapping', array());
     $file = Request::getVar('file', array(), 'FILES');
     // Create import model object
     $model = Import::oneOrNew(isset($import['id']) ? $import['id'] : 0);
     // Set our hooks
     $model->set('hooks', json_encode($hooks));
     // Set our fields
     $model->set('fields', json_encode($fields));
     // Load current params
     $iparams = new Registry($model->get('params'));
     // Bind incoming params
     $iparams->parse($params);
     // Set params on import object
     $model->set('params', $iparams->toString());
     // Bind input to model
     if (!$model->set($import)) {
         $this->setError($model->getError());
         return $this->editTask($model);
     }
     // Is this a new import?
     $isNew = false;
     if ($model->isNew()) {
         $isNew = true;
         // Set the created by/at
         $model->set('created_by', User::get('id'));
         $model->set('created_at', Date::toSql());
     }
     // Attempt to save
     if (!$model->save()) {
         $this->setError($model->getError());
         return $this->editTask();
     }
     // create folder for files
     if (!$this->_createImportFilespace($model)) {
         return $this->editTask();
     }
     // If we have a file
     if (is_array($file) && !empty($file) && $file['size'] > 0 && $file['error'] == 0) {
         move_uploaded_file($file['tmp_name'], $model->fileSpacePath() . DS . $file['name']);
         $model->set('file', $file['name']);
         $model->set('fields', '');
         // Force into the field map view
         $isNew = true;
     }
     // Do we have a data file?
     if ($model->get('file')) {
         // get record count
         $importImporter = new Importer();
         $model->set('count', $importImporter->count($model));
     }
     // Save again with import count
     if (!$model->save()) {
         $this->setError($model->getError());
         return $this->editTask($model);
     }
     Notify::success(Lang::txt('COM_MEMBERS_IMPORT_CREATED'));
     // Inform user & redirect
     if ($redirect) {
         if ($isNew) {
             $this->view->set('import', $model)->setLayout('fields')->display();
             return;
         }
         return $this->cancelTask();
     }
     $this->editTask($model);
 }
Ejemplo n.º 7
0
 /**
  * Save campaign task
  *
  * @return 	void
  */
 public function saveTask($apply = false)
 {
     //get post
     $newsletter = Request::getVar("newsletter", array(), 'post', 'ARRAY', JREQUEST_ALLOWHTML);
     //make sure we have valid alias
     if ($newsletter['alias']) {
         $newsletter['alias'] = str_replace(" ", "", strtolower($newsletter['alias']));
     } else {
         $newsletter['alias'] = str_replace(" ", "", strtolower($newsletter['name']));
     }
     //get unique newsletter name
     $newsletterId = isset($newsletter['id']) ? $newsletter['id'] : null;
     $newsletter['alias'] = $this->_getUniqueNewsletterAlias($newsletter['alias'], $newsletterId);
     //instantiate campaign object
     $newsletterNewsletter = new Letter($this->database);
     //do we need to set the created and created_by
     if (!isset($newsletter['id'])) {
         //update the modified info
         $newsletter['created'] = Date::toSql();
         $newsletter['created_by'] = User::get('id');
     } else {
         $newsletterNewsletter->load($newsletter['id']);
     }
     //did we have params
     if (isset($newsletter['params'])) {
         //load previous params
         $params = new Registry($newsletterNewsletter->params);
         //set from name
         if (isset($newsletter['params']['from_name'])) {
             $params->set('from_name', $newsletter['params']['from_name']);
         }
         //set from address
         if (isset($newsletter['params']['from_address'])) {
             $params->set('from_address', $newsletter['params']['from_address']);
         }
         //set reply-to name
         if (isset($newsletter['params']['replyto_name'])) {
             $params->set('replyto_name', $newsletter['params']['replyto_name']);
         }
         //set reply-to address
         if (isset($newsletter['params']['replyto_address'])) {
             $params->set('replyto_address', $newsletter['params']['replyto_address']);
         }
         //newsletter params to string
         $newsletter['params'] = $params->toString();
     }
     //update the modified info
     $newsletter['modified'] = Date::toSql();
     $newsletter['modified_by'] = User::get('id');
     // if no plain text was entered lets take the html content
     if (isset($newsletter['plain_content'])) {
         if ($newsletter['plain_content'] == '') {
             $newsletter['plain_content'] = strip_tags($newsletter['html_content']);
             $newsletter['plain_content'] = preg_replace('/(?:(?:\\r\\n|\\r|\\n)\\s*){2}\\n/', '', $newsletter['plain_content']);
         }
         // remove html from plain content
         $newsletter['plain_content'] = strip_tags($newsletter['plain_content']);
     }
     //save campaign
     if (!$newsletterNewsletter->save($newsletter)) {
         $this->newsletter = new stdClass();
         $this->newsletter->id = $newsletterNewsletter->id;
         $this->newsletter->alias = $newsletterNewsletter->alias;
         $this->newsletter->name = $newsletterNewsletter->name;
         $this->newsletter->issue = $newsletterNewsletter->issue;
         $this->newsletter->type = $newsletterNewsletter->type;
         $this->newsletter->template = $newsletterNewsletter->template;
         $this->newsletter->published = $newsletterNewsletter->published;
         $this->newsletter->sent = $newsletterNewsletter->sent;
         $this->newsletter->html_content = $newsletterNewsletter->html_content;
         $this->newsletter->plain_content = $newsletterNewsletter->plain_content;
         $this->newsletter->tracking = $newsletterNewsletter->tracking;
         $this->newsletter->created = $newsletterNewsletter->created;
         $this->newsletter->created_by = $newsletterNewsletter->created_by;
         $this->newsletter->modified = $newsletterNewsletter->modified;
         $this->newsletter->modified_by = $newsletterNewsletter->modified_by;
         $this->newsletter->params = $newsletterNewsletter->params;
         // set the id so we can pick up the stories
         Request::setVar('id', array($this->newsletter->id));
         $this->setError($newsletterNewsletter->getError());
         $this->editTask();
         return;
     } else {
         // set success message
         Notify::success(Lang::txt('COM_NEWSLETTER_SAVED_SUCCESS'));
         // redirect back to campaigns list
         App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter', false));
         // if we just created campaign go back to edit form so we can add content
         if (!isset($newsletter['id']) || $apply) {
             App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter&task=edit&id=' . $newsletterNewsletter->id, false));
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Settings for group citations
  *
  * @param null
  * @return void
  *
  *
  */
 private function _settings()
 {
     if ($_POST) {
         $display = Request::getVar('display', '');
         $format = Request::getVar('citation-format', '');
         $params = json_decode($this->group->get('params'));
         if (!is_object($params)) {
             $params = new stdClass();
         }
         // craft a clever name
         $name = "custom-group-" . $this->group->cn;
         // fetch or create new format
         $citationFormat = \Components\Citations\Models\Format::oneOrNew($format);
         // if the setting a custom group citation type
         if ($citationFormat->isNew() || $citationFormat->style == $name && !$citationFormat->isNew()) {
             $citationFormat->set(array('format' => Request::getVar('template'), 'style' => $name));
             // save format
             $citationFormat->save();
             // update group
             $params->citationFormat = $citationFormat->id;
         } else {
             // returned value from format select box
             $params->citationFormat = $format;
         }
         // more parameters for citations
         $params->display = Request::getVar('display', '');
         $params->include_coins = Request::getVar('include_coins', '');
         $params->coins_only = Request::getVar('coins_only', '');
         $params->citations_show_tags = Request::getVar('citations_show_tags', '');
         $params->citations_show_badges = Request::getVar('citations_show_badges', '');
         // update the group parameters
         $gParams = new Registry($params);
         $gParams->merge($params);
         $this->group->set('params', $gParams->toString());
         $this->group->update();
         // redirect after save
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_SETTINGS_SAVED'), 'success');
         return;
     } else {
         // instansiate the view
         $view = $this->view('default', 'settings');
         // pass the group through
         $view->group = $this->group;
         // get group settings
         $params = json_decode($this->group->get('params'));
         $view->include_coins = isset($params->include_coins) ? $params->include_coins : "false";
         $view->coins_only = isset($params->coins_only) ? $params->coins_only : "false";
         $view->citations_show_tags = isset($params->citations_show_tags) ? $params->citations_show_tags : "true";
         $view->citations_show_badges = isset($params->citations_show_badges) ? $params->citations_show_badges : "true";
         $citationsFormat = isset($params->citationFormat) ? $params->citationFormat : 1;
         // intended for the case that the group's custom
         // format is removed from the jos_citations_format
         try {
             $view->currentFormat = \Components\Citations\Models\Format::oneOrFail($citationsFormat);
         } catch (\Exception $e) {
             $view->currentFormat = \Components\Citations\Models\Format::all()->where('style', 'like', 'ieee');
         }
         // get the name of the current format (see if it's custom)
         // the name of the custom format
         $name = "custom-group-" . $this->group->cn;
         $custom = \Components\Citations\Models\Format::all()->where('style', 'LIKE', $name)->count();
         if ($custom > 0) {
             // show the menu entry for the custom
             $view->customFormat = true;
         } else {
             // show menu item for new custom format
             $view->customFormat = false;
         }
         // get formats
         $view->formats = \Components\Citations\Models\Format::all()->where('style', 'NOT LIKE', '%custom-group-%')->where('style', 'NOT LIKE', '%custom-member-%')->orWhere('style', '=', $name)->rows()->toObject();
         $view->templateKeys = \Components\Citations\Models\Format::all()->getTemplateKeys();
         // Output HTML
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
 }
Ejemplo n.º 9
0
 /**
  * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version)
  *
  * @return   mixed  string update version if success, false if fail
  */
 public function fixUpdateVersion()
 {
     $table = \JTable::getInstance('Extension');
     $table->load('700');
     $cache = new Registry($table->manifest_cache);
     $updateVersion = $cache->get('version');
     $cmsVersion = new \JVersion();
     if ($updateVersion == $cmsVersion->getShortVersion()) {
         return $updateVersion;
     } else {
         $cache->set('version', $cmsVersion->getShortVersion());
         $table->manifest_cache = $cache->toString();
         if ($table->store()) {
             return $cmsVersion->getShortVersion();
         } else {
             return false;
         }
     }
 }