예제 #1
0
 /**
  * Register the service provider.
  *
  * @return  void
  */
 public function register()
 {
     $this->app['menu.manager'] = function ($app) {
         return $manager = new Manager();
     };
     $this->app['menu'] = function ($app) {
         $options = ['language_filter' => null, 'language' => null, 'access' => \User::getAuthorisedViewLevels()];
         $options['db'] = $app->get('db');
         if ($app->has('language.filter')) {
             $options['language_filter'] = $app->get('language.filter');
             $options['language'] = $app->get('language')->getTag();
         }
         return $app['menu.manager']->menu($app['client']->name, $options);
     };
     $this->app['menu.params'] = function ($app) {
         $params = new Registry();
         $menu = $app['menu']->getActive();
         if (is_object($menu)) {
             $params->parse($menu->params);
         } else {
             if ($app->has('component')) {
                 $temp = clone $app['component']->params('com_menus');
                 $params->merge($temp);
             }
         }
         return $params;
     };
 }
예제 #2
0
 /**
  * Display module contents
  *
  * @return  void
  */
 public function display()
 {
     if (!App::isAdmin()) {
         return;
     }
     $return = self::getReturnURI();
     $freturn = base64_encode('index.php?' . Request::getQueryString());
     $returnQueryString = !empty($return) ? "&return={$return}" : '';
     $authenticators = [];
     $plugins = \Plugin::byType('authentication');
     foreach ($plugins as $p) {
         $pparams = new Registry($p->params);
         // Make sure it supports admin login
         if (!$pparams->get('admin_login', false)) {
             continue;
         }
         // If it's the default hubzero plugin, don't include it in the list (we'll include it separately)
         if ($p->name == 'hubzero') {
             $site_display = $pparams->get('display_name', \Config::get('sitename'));
             $basic = true;
         } else {
             $display = $pparams->get('display_name', ucfirst($p->name));
             $authenticators[$p->name] = array('name' => $p->name, 'display' => $display);
         }
     }
     require $this->getLayoutPath($this->params->get('layout', 'default'));
 }
예제 #3
0
 /**
  * Renders a module script and returns the results as a string
  *
  * @param   string  $module   The name of the module to render
  * @param   array   $attribs  Associative array of values
  * @param   string  $content  If present, module information from the buffer will be used
  * @return  string  The output of the script
  */
 public function render($module, $attribs = array(), $content = null)
 {
     if (!is_object($module)) {
         $title = isset($attribs['title']) ? $attribs['title'] : null;
         $module = \App::get('module')->byName($module, $title);
         if (!is_object($module)) {
             if (is_null($content)) {
                 return '';
             } else {
                 // If module isn't found in the database but data has been pushed in the buffer
                 // we want to render it
                 $tmp = $module;
                 $module = new stdClass();
                 $module->params = null;
                 $module->module = $tmp;
                 $module->id = 0;
                 $module->user = 0;
             }
         }
     }
     // Set the module content
     if (!is_null($content)) {
         $module->content = $content;
     }
     // Get module parameters
     $params = new Registry($module->params);
     // Use parameters from template
     if (isset($attribs['params'])) {
         $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
         $params->merge($template_params);
         $module = clone $module;
         $module->params = (string) $params;
     }
     return \App::get('module')->render($module, $attribs);
 }
 /**
  * Register the service provider.
  *
  * @return  void
  */
 public function register()
 {
     $this->app['menu.manager'] = function ($app) {
         return $manager = new Manager();
     };
     $this->app['menu'] = function ($app) {
         return $app['menu.manager']->menu($app['client']->name);
     };
     $this->app['menu.params'] = function ($app) {
         $params = new Registry();
         $menu = $app['menu']->getActive();
         if (is_object($menu)) {
             $params->parse($menu->params);
         } else {
             if ($app->has('component')) {
                 $temp = clone $app['component']->params('com_menus');
                 $params->merge($temp);
             }
         }
         return $params;
     };
 }
예제 #5
0
 /**
  * Constructor
  *
  * @param   string  $data  The raw parms text.
  * @param   string  $path  Path to the XML setup file.
  * @return  void
  */
 public function __construct($data = '', $path = '')
 {
     parent::__construct('_default');
     // Set base path.
     $this->_elementPath[] = __DIR__ . DS . 'Parameter' . DS . 'Element';
     if ($data = trim($data)) {
         $this->parse($data);
     }
     if ($path) {
         $this->loadSetupFile($path);
     }
     $this->_raw = $data;
 }
예제 #6
0
 /**
  * Create a new configuration repository.
  *
  * @param   string  $path
  * @return  void
  */
 public function __construct($path = null)
 {
     if (!$path) {
         $path = PATH_ROOT;
     }
     $this->file = $path . DS . 'configuration.php';
     if ($this->file) {
         $data = $this->read($this->file);
         $data = \Hubzero\Utility\Arr::fromObject($data);
         $config = array();
         foreach ($data as $key => $value) {
             foreach ($this->map as $group => $values) {
                 if (!isset($config[$group])) {
                     $config[$group] = array();
                 }
                 if (in_array($key, $values)) {
                     $config[$group][$key] = $value;
                 }
             }
         }
         parent::__construct($config);
     }
 }
예제 #7
0
 /**
  * Add membership request for user
  *
  * @return  array
  */
 public function dorequestTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_REQUEST'));
         return;
     }
     Request::checkToken();
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //make sure group has restricted policy
     if ($this->view->group->get('join_policy') != 1) {
         return;
     }
     //add user to applicants
     $this->view->group->add('applicants', array(User::get('id')));
     $this->view->group->update();
     // Instantiate the reason object and bind the incoming data
     $row = new Reason($this->database);
     $row->uidNumber = User::get('id');
     $row->gidNumber = $this->view->group->get('gidNumber');
     $row->reason = Request::getVar('reason', Lang::txt('GROUPS_NO_REASON_GIVEN'), 'post');
     $row->reason = \Hubzero\Utility\Sanitize::stripAll($row->reason);
     $row->date = Date::toSql();
     // Check and store the reason
     if (!$row->check()) {
         return App::abort(500, $row->getError());
     }
     if (!$row->store()) {
         return App::abort(500, $row->getError());
     }
     // Log the membership request
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_requested', 'comments' => array(User::get('id'))));
     // Log activity
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn'));
     $recipients = array(['group', $this->view->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->view->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'requested', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_REQUESTED', '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => $recipients]);
     // E-mail subject
     $subject = Lang::txt('COM_GROUPS_JOIN_REQUEST_EMAIL_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'request'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $eview->row = $row;
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Get the system administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Build the "from" portion of the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name));
     $from['email'] = Config::get('mailfrom');
     // build array of managers
     $managers = array();
     foreach ($this->view->group->get('managers') as $m) {
         $profile = User::getInstance($m);
         if ($profile) {
             $managers[$profile->get('email')] = $profile->get('name');
         }
     }
     // create new message
     $message = new \Hubzero\Mail\Message();
     // build message object and send
     $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($managers)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_membership_requested')->addPart($html, 'text/plain')->send();
     //tell the user they just did good
     $this->setNotification(Lang::txt('COM_GROUPS_INVITE_REQUEST_FORWARDED'), 'passed');
     // Push through to the groups listing
     App::redirect($url);
 }
예제 #8
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'));
 }
예제 #9
0
 /**
  * Method to validate form data.
  *
  * Validation warnings will be pushed into Form::errors and should be
  * retrieved with Form::getErrors() when validate returns boolean false.
  *
  * @param   array   $data   An array of field values to validate.
  * @param   string  $group  The optional dot-separated form group path on which to filter the fields to be validated.
  * @return  mixed   True on sucess.
  */
 public function validate($data, $group = null)
 {
     // Make sure there is a valid Form XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     // Initialise variables.
     $return = true;
     // Create an input registry object from the data to validate.
     $input = new Registry($data);
     // Get the fields for which to validate the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Validate the fields.
     foreach ($fields as $field) {
         // Initialise variables.
         $value = null;
         $name = (string) $field['name'];
         // Get the group names as strings for ancestor fields elements.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         // Get the value from the input data.
         if ($group) {
             $value = $input->get($group . '.' . $name);
         } else {
             $value = $input->get($name);
         }
         // Validate the field.
         $valid = $this->validateField($field, $group, $value, $input);
         // Check for an error.
         if ($valid instanceof Exception) {
             if ($valid instanceof MissingData || $valid instanceof InvalidData) {
                 $this->errors[$name] = $valid;
                 $return = false;
             } else {
                 throw new Exception($valid->getMessage());
                 return false;
             }
         }
     }
     return $return;
 }
예제 #10
0
 /**
  * Display an offering asset
  *
  * @return     void
  */
 public function assetTask()
 {
     $sparams = new Registry($this->course->offering()->section()->get('params'));
     $section_id = $this->course->offering()->section()->get('id');
     $asset = new Models\Asset(Request::getInt('asset_id', null));
     $asset->set('section_id', $section_id);
     // First, check if current user has access to course
     if (!$this->course->offering()->access('view')) {
         // Is a preview available?
         $preview = $sparams->get('preview', 0);
         // If no preview is available or if type  is form (i.e. you can never preview forms)
         if (!$preview || $asset->get('type') == 'form') {
             // Check if they're logged in
             if (User::isGuest()) {
                 $this->loginTask(Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'));
                 return;
             } else {
                 // Redirect back to the course outline
                 App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'), 'warning');
                 return;
             }
         } elseif ($preview == 2) {
             $units = $asset->units();
             if ($units && count($units) > 0) {
                 foreach ($units as $unit) {
                     if ($unit->get('ordering') > 1) {
                         // Check if they're logged in
                         if (User::isGuest()) {
                             $this->loginTask(Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'));
                             return;
                         } else {
                             // Redirect back to the course outline
                             App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'), 'warning');
                             return;
                         }
                     }
                 }
             }
         }
     }
     // If not a manager and either the offering or section is unpublished...
     if (!$this->course->offering()->access('manage') && (!$this->course->offering()->isPublished() || !$this->course->offering()->section()->isPublished())) {
         return App::abort(403, Lang::txt('COM_COURSES_ERROR_ASSET_UNAVAILABLE'));
     }
     if (!$this->course->offering()->access('manage') && !$asset->isAvailable()) {
         // Allow expired forms to pass through (i.e. so students can see their results)
         if (!$asset->get('type') == 'form' || !$asset->ended()) {
             // Redirect back to the course outline
             App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ERROR_ASSET_UNAVAILABLE'), 'warning');
             return;
         }
     }
     // Check prerequisites
     $member = $this->course->offering()->section()->member(User::get('id'));
     if (is_null($member->get('section_id'))) {
         $member->set('section_id', $section_id);
     }
     $prerequisites = $member->prerequisites($this->course->offering()->gradebook());
     if (!$this->course->offering()->access('manage') && !$prerequisites->hasMet('asset', $asset->get('id'))) {
         $prereqs = $prerequisites->get('asset', $asset->get('id'));
         $requirements = array();
         foreach ($prereqs as $pre) {
             $reqAsset = new Models\Asset($pre['scope_id']);
             $requirements[] = $reqAsset->get('title');
         }
         $requirements = implode(', ', $requirements);
         // Redirect back to the course outline
         App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ERROR_ASSET_HAS_PREREQ', $requirements), 'warning');
         return;
     }
     // If requesting a file from a wiki type asset, then serve that up directly
     if ($asset->get('subtype') == 'wiki' && Request::getVar('file', false)) {
         echo $asset->download($this->course);
     }
     echo $asset->render($this->course);
 }
예제 #11
0
 /**
  * Load the editor
  *
  * @param   array  $config  Associative array of editor config paramaters
  * @return  void
  */
 private function load($config = array())
 {
     // Check if editor is already loaded
     if (!is_null($this->editor)) {
         return;
     }
     // Build the path to the needed editor plugin
     $name = (string) preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->name);
     $name = ltrim($name, '.');
     $path = PATH_CORE . DS . 'plugins' . DS . 'wiki' . DS . $name . DS . $name . '.php';
     if (!is_file($path)) {
         throw new Exception(Lang::txt('Cannot load the editor'), 500);
         return false;
     }
     // Require plugin file
     require_once $path;
     // Get the plugin
     $plugin = Plugin::byType('wiki', $this->name);
     $params = new Registry($plugin->params);
     $params->toArray($config);
     $plugin->params = $params;
     // Build editor plugin classname
     $name = 'plgWiki' . $this->name;
     if ($this->editor = new $name($this, (array) $plugin)) {
         // Load plugin parameters
         $this->initialise();
     }
 }
예제 #12
0
 /**
  * Get current progress
  *
  * At this point, this method only takes into account what students have viewed.
  * This makes sense on a PDF download, for example, but not on a quiz.  This
  * should be expanded to account for views on simpler asset types, and more complex
  * criteria on assets where it can be tracked (ex: videos, where we can track an
  * entire view, or an exam, where we know when they've actually finished it).
  *
  * @param      int $member_id
  * @return     array $progress
  */
 public function progress($member_id = null)
 {
     static $instances;
     $key = !is_null($member_id) ? serialize($member_id) : 'all';
     if (isset($instances[$key])) {
         return $instances[$key];
     }
     $offeringParams = new Registry($this->course->offering()->get('params'));
     $sectionParams = new Registry($this->course->offering()->section()->get('params'));
     $progress_calculation = $this->course->config()->get('progress_calculation', 'all');
     $progress_calculation = $offeringParams->get('progress_calculation', false) ? $offeringParams->get('progress_calculation') : $progress_calculation;
     $progress_calculation = $sectionParams->get('progress_calculation', false) ? $sectionParams->get('progress_calculation') : $progress_calculation;
     $filters = array('section_id' => $this->course->offering()->section()->get('id'), 'member_id' => $member_id);
     $dbo = \App::get('db');
     switch ($progress_calculation) {
         // Support legacy label of 'forms', as well as new, more accurate label of 'graded'
         case 'forms':
         case 'graded':
             // Get count of graded items taken
             $filters = array('member_id' => $member_id, 'scope' => 'asset', 'graded' => true);
             $grades = $this->_grades($filters);
             $views = array();
             foreach ($grades as $g) {
                 if (!is_null($g->score) || !is_null($g->override)) {
                     $views[] = (object) array('member_id' => $g->member_id, 'grade_weight' => $g->grade_weight, 'unit_id' => $g->unit_id, 'asset_id' => $g->scope_id);
                 }
             }
             break;
         case 'manual':
             $filters['progress_calculation'] = true;
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
         case 'videos':
             // Add another filter
             $filters['asset_type'] = 'video';
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
         case 'all':
         default:
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
     }
     $progress = array();
     // Restructure array
     foreach ($views as $v) {
         $progress[$v->member_id][$v->unit_id][$v->asset_id] = 1;
     }
     $counts = array();
     // Calculate unit completion percentage for each student
     // Note: this is not their score, but rather, simply how many items within the unit they have viewed/completed
     foreach ($progress as $member_id => $m) {
         foreach ($m as $unit_id => $unit) {
             if (!isset($counts[$unit_id])) {
                 // Get the assets
                 $asset = new Tables\Asset($dbo);
                 $filters = array('w' => array('course_id' => $this->course->get('id'), 'unit_id' => $unit_id, 'state' => 1, 'asset_scope' => 'asset_group'));
                 switch ($progress_calculation) {
                     // Support legacy label of 'forms', as well as new, more accurate label of 'graded'
                     case 'forms':
                     case 'graded':
                         $filters['w']['graded'] = true;
                         break;
                     case 'manual':
                         $filters['w']['section_id'] = $this->course->offering()->section()->get('id');
                         $filters['w']['progress_calculation'] = true;
                         break;
                     case 'videos':
                         $filters['w']['asset_type'] = 'video';
                         break;
                 }
                 $counts[$unit_id] = $asset->count($filters);
                 $counts[$unit_id] = $counts[$unit_id] ? $counts[$unit_id] : 1;
                 // Enforce 1. Can't divide by zero.
             }
             $progress[$member_id][$unit_id]['percentage_complete'] = round(array_sum($unit) / $counts[$unit_id] * 100, 2);
         }
     }
     $instances[$key] = $progress;
     return $progress;
 }
예제 #13
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     // [!] Legacy compatibility for older view overrides
     $params = $this->params;
     $module = $this->module;
     // Make sure we're using a secure connection
     if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
         \App::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         die('insecure connection and redirection failed');
     }
     // Get and add the js and extra css to the page
     $this->css('login.css', 'com_users');
     $this->css('providers.css', 'com_users');
     $this->js('login', 'com_users');
     $this->css('uniform.css', 'system');
     $this->js('jquery.uniform', 'system');
     $this->js('jquery.hoverIntent', 'system');
     $type = self::getType();
     $return = Request::getVar('return', null);
     $freturn = base64_encode($_SERVER['REQUEST_URI']);
     // If we have a return set with an authenticator in it, we're linking an existing account
     // Parse the return to retrive the authenticator, and remove it from the list below
     $auth = '';
     if ($areturn = Request::getVar('return', null)) {
         $areturn = base64_decode($areturn);
         $query = parse_url($areturn);
         if (is_array($query) && isset($query['query'])) {
             $query = $query['query'];
             $query = explode('&', $query);
             $auth = '';
             foreach ($query as $q) {
                 $n = explode('=', $q);
                 if ($n[0] == 'authenticator') {
                     $auth = $n[1];
                 }
             }
         }
     }
     // Figure out whether or not any of our third party auth plugins are turned on
     // Don't include the 'hubzero' plugin, or the $auth plugin as described above
     $multiAuth = false;
     $plugins = Plugin::byType('authentication');
     $authenticators = array();
     foreach ($plugins as $p) {
         if ($p->name != 'hubzero' && $p->name != $auth) {
             $pparams = new Registry($p->params);
             $display = $pparams->get('display_name', ucfirst($p->name));
             $authenticators[] = array('name' => $p->name, 'display' => $display);
             $multiAuth = true;
         } else {
             if ($p->name == 'hubzero') {
                 $pparams = new Registry($p->params);
                 $remember_me_default = $pparams->get('remember_me_default', 0);
             }
         }
     }
     Plugin::import('authentication');
     // Set the return if we have it...
     $returnQueryString = $return ? "&return={$return}" : '';
     require $this->getLayoutPath();
 }
예제 #14
0
 /**
  * Send Newsletter
  *
  * @param   $newsletter
  * @param   $newsletterHtmlContent
  * @param   $newsletterPlainContent
  * @param   $newsletterContacts
  * @param   $newsletterMailinglist
  * @param   $sendingTest
  * @return  object
  */
 private function _send($newsletter, $newsletterHtmlContent, $newsletterPlainContent, $newsletterContacts, $newsletterMailinglist, $sendingTest = false)
 {
     //set default mail from and reply-to names and addresses
     $defaultMailFromName = Config::get("sitename") . ' Newsletter';
     $defaultMailFromAddress = 'contact@' . $_SERVER['HTTP_HOST'];
     $defaultMailReplytoName = Config::get("sitename") . ' Newsletter - Do Not Reply';
     $defaultMailReplytoAddress = 'do-not-reply@' . $_SERVER['HTTP_HOST'];
     //get the config mail from and reply-to names and addresses
     $mailFromName = $this->config->get('newsletter_from_name', $defaultMailFromName);
     $mailFromAddress = $this->config->get('newsletter_from_address', $defaultMailFromAddress);
     $mailReplytoName = $this->config->get('newsletter_replyto_name', $defaultMailReplytoName);
     $mailReplytoAddress = $this->config->get('newsletter_replyto_address', $defaultMailReplytoAddress);
     //parse newsletter specific emails
     $params = new Registry($newsletter->params);
     $mailFromName = $params->get('from_name', $mailFromName);
     $mailFromAddress = $params->get('from_address', $mailFromAddress);
     $mailReplytoName = $params->get('replyto_name', $mailReplytoName);
     $mailReplytoAddress = $params->get('replyto_address', $mailReplytoAddress);
     //set final mail from and reply-to
     $mailFrom = '"' . $mailFromName . '" <' . $mailFromAddress . '>';
     $mailReplyTo = '"' . $mailReplytoName . '" <' . $mailReplytoAddress . '>';
     //set subject and body
     $mailSubject = $newsletter->name ? $newsletter->name : 'Your ' . Config::get("sitename") . '.org Newsletter';
     $mailHtmlBody = $newsletterHtmlContent;
     $mailPlainBody = $newsletterPlainContent;
     //set mail headers
     //$mailHeaders  = "MIME-Version: 1.0" . "\r\n";
     //$mailHeaders .= "Content-type: text/html; charset=\"UTF-8\"" . "\r\n";
     $mailHeaders = "From: {$mailFrom}" . "\r\n";
     $mailHeaders .= "Reply-To: {$mailReplyTo}" . "\r\n";
     //set mail priority
     $mailHeaders .= "X-Priority: 3" . "\r\n";
     //$mailHeaders .= "X-MSMail-Priority: Normal" . "\r\n";
     //$mailHeaders .= "Importance: Normal\n";
     //set extra headers
     $mailHeaders .= "X-Mailer: PHP/" . phpversion() . "\r\n";
     $mailHeaders .= "X-Component: " . $this->_option . "\r\n";
     $mailHeaders .= "X-Component-Object: Campaign Mailing" . "\r\n";
     $mailHeaders .= "X-Component-ObjectId: {{CAMPAIGN_MAILING_ID}}" . "\r\n";
     //$mailHeaders .= "List-Unsubscribe: <mailto:{{UNSUBSCRIBE_MAILTO_LINK}}>, <{{UNSUBSCRIBE_LINK}}>";
     //set mail args
     $mailArgs = '';
     //$mailArgs = '-f hubmail-bounces@' . $_SERVER['HTTP_HOST'];
     //are we sending test mailing
     if ($sendingTest) {
         foreach ($newsletterContacts as $contact) {
             // get tracking & unsubscribe token
             $recipient = new stdClass();
             $recipient->email = $contact;
             $recipient->mailingid = $newsletterMailinglist ? $newsletterMailinglist : -1;
             $emailToken = \Components\Newsletter\Helpers\Helper::generateMailingToken($recipient);
             // create unsubscribe link
             $unsubscribeMailtoLink = '';
             $unsubscribeLink = 'https://' . $_SERVER['SERVER_NAME'] . '/newsletter/unsubscribe?e=' . urlencode($contact) . '&t=' . $emailToken;
             // add unsubscribe link - placeholder & in header (must do after adding tracking!!)
             $mailHtmlBody = str_replace("{{UNSUBSCRIBE_LINK}}", $unsubscribeLink, $mailHtmlBody);
             $mailPlainBody = str_replace("{{UNSUBSCRIBE_LINK}}", $unsubscribeLink, $mailPlainBody);
             // create new message
             $message = new \Hubzero\Mail\Message();
             foreach (explode("\r\n", $mailHeaders) as $header) {
                 $parts = array_map("trim", explode(':', $header));
                 switch ($parts[0]) {
                     case 'From':
                         if (preg_match("/\\\"([^\"]*)\\\"\\s<([^>]*)>/ux", $parts[1], $matches)) {
                             $message->setFrom(array($matches[2] => $matches[1]));
                         }
                         break;
                     case 'Reply-To':
                         if (preg_match("/\\\"([^\"]*)\\\"\\s<([^>]*)>/ux", $parts[1], $matches)) {
                             $message->setReplyTo(array($matches[2] => $matches[1]));
                         }
                         break;
                     case 'Importance':
                     case 'X-Priority':
                     case 'X-MSMail-Priority':
                         $priority = isset($parts[1]) && in_array($parts[1], array(1, 2, 3, 4, 5)) ? $parts[1] : 3;
                         $message->setPriority($priority);
                         break;
                     default:
                         if (isset($parts[1])) {
                             $message->addHeader($parts[0], $parts[1]);
                         }
                 }
             }
             // build message object and send
             $message->setSubject('[SENDING TEST] - ' . $mailSubject)->setTo($contact)->addPart($mailHtmlBody, 'text/html')->addPart($mailPlainBody, 'text/plain')->send();
         }
         return true;
     }
     //get the scheduling
     $scheduler = Request::getInt('scheduler', 1);
     if ($scheduler == '1') {
         $scheduledDate = Date::toSql();
     } else {
         $schedulerDate = Request::getVar('scheduler_date', '');
         $schedulerHour = Request::getVar('scheduler_date_hour', '00');
         $schedulerMinute = Request::getVar('scheduler_date_minute', '00');
         $schedulerMeridian = Request::getVar('scheduler_date_meridian', 'AM');
         //make sure we have at least the date or we use now
         if (!$schedulerDate) {
             $scheduledDate = Date::toSql();
         }
         //break apart parts of date
         $schedulerDateParts = explode('/', $schedulerDate);
         //make sure its in 24 time
         if ($schedulerMeridian == 'pm') {
             $schedulerHour += 12;
         }
         //build scheduled time
         $scheduledTime = $schedulerDateParts[2] . '-' . $schedulerDateParts[0] . '-' . $schedulerDateParts[1];
         $scheduledTime .= ' ' . $schedulerHour . ':' . $schedulerMinute . ':00';
         $scheduledDate = Date::of(strtotime($scheduledTime))->toSql();
     }
     //create mailing object
     $mailing = new stdClass();
     $mailing->nid = $newsletter->id;
     $mailing->lid = $newsletterMailinglist;
     $mailing->subject = $mailSubject;
     $mailing->html_body = $mailHtmlBody;
     $mailing->plain_body = $mailPlainBody;
     $mailing->headers = $mailHeaders;
     $mailing->args = $mailArgs;
     $mailing->tracking = $newsletter->tracking;
     $mailing->date = $scheduledDate;
     //save mailing object
     $newsletterMailing = new Mailing($this->database);
     if (!$newsletterMailing->save($mailing)) {
         $this->setError(Lang::txt('COM_NEWSLETTER_NEWSLETTER_SEND_FAIL'));
         $this->sendNewsletterTask();
         return;
     }
     // create recipients
     $this->_sendTo($newsletterMailing, $newsletterContacts);
     return $newsletterMailing;
 }
예제 #15
0
 /**
  * Display an order
  *
  * @return     void
  */
 public function orderTask()
 {
     $this->view->store_enabled = $this->config->get('store_enabled');
     // Incoming
     $id = Request::getInt('id', 0);
     // Load data
     $this->view->row = new Order($this->database);
     $this->view->row->load($id);
     $oi = new OrderItem($this->database);
     $this->view->orderitems = array();
     $this->view->customer = null;
     $this->view->funds = 0;
     if ($id) {
         // Get order items
         $this->view->orderitems = $oi->getOrderItems($id);
         if (count($this->view->orderitems) > 0) {
             foreach ($this->view->orderitems as $r) {
                 $params = new Registry($r->params);
                 $selections = new Registry($r->selections);
                 // Get size selection
                 $r->sizes = $params->get('size', '');
                 $r->sizes = str_replace(' ', '', $r->sizes);
                 $r->sizes = preg_split('#,#', $r->sizes);
                 $r->selectedsize = trim($selections->get('size', ''));
                 $r->sizeavail = in_array($r->selectedsize, $r->sizes) ? 1 : 0;
                 // Get color selection
                 $r->colors = $params->get('color', '');
                 $r->colors = str_replace(' ', '', $r->colors);
                 $r->colors = preg_split('#,#', $r->colors);
                 $r->selectedcolor = trim($selections->get('color', ''));
             }
         }
         $this->view->customer = User::getInstance($this->view->row->uid);
         // Check available user funds
         $BTL = new Teller($this->database, $this->view->row->uid);
         $balance = $BTL->summary();
         $credit = $BTL->credit_summary();
         $this->view->funds = $balance;
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
예제 #16
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();
     }
 }
예제 #17
0
 /**
  * Display a list of all citations, with filtering&search options.
  *
  * @return		 string HTML
  */
 private function _browse()
 {
     // Instantiate a new citations object
     $obj = $this->_filterHandler(Request::getVar('filters', array()), $this->group->get('gidNumber'));
     $count = clone $obj['citations'];
     $count = $count->count();
     $isManager = $this->authorized == 'manager' ? true : false;
     $config = new \Hubzero\Config\Registry($this->group->get('params'));
     $display = $config->get('display');
     $total = \Components\Citations\Models\Citation::all()->where('scope', '=', self::PLUGIN_SCOPE)->where('scope_id', '=', $this->group->get('gidNumber'))->where('published', '=', \Components\Citations\Models\Citation::STATE_PUBLISHED)->count();
     // for first-time use
     if ($count == 0 && $isManager && !isset($display)) {
         // have a group manager set the settings
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations&action=settings'), Lang::txt('Please select your settings for this group.'), 'warning');
     } elseif ((int) $count == 0 && $isManager && isset($display) && $total <= 0) {
         $view = $this->view('intro', 'browse');
         $view->group = $this->group;
         $view->isManager = $this->authorized == 'manager' ? true : false;
     } else {
         // initialize the view
         $view = $this->view('default', 'browse');
         // push objects to the view
         $view->group = $this->group;
         $view->option = $this->option;
         $view->task = $this->_name;
         $view->database = $this->database;
         $view->title = Lang::txt(strtoupper($this->_name));
         $view->isManager = $this->authorized == 'manager' ? true : false;
         $view->config = $config;
     }
     // get applied filters
     $view->filters = $obj['filters'];
     // only display published citations to non-managers.
     if ($view->isManager) {
         // get filtered citations
         $view->citations = $obj['citations']->paginated()->rows();
     } else {
         $view->citations = $obj['citations']->where('published', '=', \Components\Citations\Models\Citation::STATE_PUBLISHED)->paginated()->rows();
     }
     // get the earliest year we have citations for
     $view->earliest_year = 2001;
     // Contribution filter
     $view->filterlist = array('all' => Lang::txt('PLG_GROUPS_CITATIONS_ALL'), 'member' => Lang::txt('PLG_GROUPS_CITATIONS_MEMBERCONTRIB'));
     // set default values for required filters for this view.
     $view->filters['search'] = isset($view->filters['search']) ? $view->filters['search'] : "";
     $view->filters['type'] = isset($view->filters['type']) ? $view->filters['type'] : "";
     $view->filters['tag'] = isset($view->filters['tag']) ? $view->filters['tag'] : "";
     $view->filters['author'] = isset($view->filters['author']) ? $view->filters['author'] : "";
     $view->filters['publishedin'] = isset($view->filters['publishedin']) ? $view->filters['publishedin'] : "";
     $view->filters['year_start'] = isset($view->filters['year_start']) ? $view->filters['year_start'] : "";
     $view->filters['year_end'] = isset($view->filters['year_end']) ? $view->filters['year_end'] : "";
     $view->filters['startuploaddate'] = isset($view->filters['startuploaddate']) ? $view->filters['startuploaddate'] : "";
     $view->filters['enduploaddate'] = isset($view->filters['enduploaddate']) ? $view->filters['enduploaddate'] : "";
     $view->filters['sort'] = isset($view->filters['sort']) ? $view->filters['sort'] : "";
     $view->filters['filter'] = isset($view->filters['filter']) ? $view->filters['filter'] : "";
     // Sort Filter
     $view->sorts = array('year DESC' => Lang::txt('PLG_GROUPS_CITATIONS_YEAR'), 'created DESC' => Lang::txt('PLG_GROUPS_CITATIONS_NEWEST'), 'title ASC' => Lang::txt('PLG_GROUPS_CITATIONS_TITLE'), 'author ASC' => Lang::txt('PLG_GROUPS_CITATIONS_AUTHOR'), 'journal ASC' => Lang::txt('PLG_GROUPS_CITATIONS_JOURNAL'));
     // Handling ids of the the boxes checked for download
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $session = App::get('session');
     // If it's new search remove all user citation checkmarks
     if (isset($_POST['filter'])) {
         $view->filters['idlist'] = "";
         $session->set('idlist', $view->filters['idlist']);
     } else {
         $view->filters['idlist'] = Request::getVar('idlist', $session->get('idlist'));
         $session->set('idlist', $view->filters['idlist']);
     }
     // Reset the filter if the user came from a different section
     if (strpos($referer, "/citations/browse") == false) {
         $view->filters['idlist'] = "";
         $session->set('idlist', $view->filters['idlist']);
     }
     // get the preferred labeling scheme
     $view->label = "both";
     if ($view->label == "none") {
         $view->citations_label_class = "no-label";
     } elseif ($view->label == "number") {
         $view->citations_label_class = "number-label";
     } elseif ($view->label == "type") {
         $view->citations_label_class = "type-label";
     } elseif ($view->label == "both") {
         $view->citations_label_class = "both-label";
     } else {
         $view->citations_label_class = "both-label";
     }
     // enable coins support
     $view->coins = 1;
     // types
     $ct = \Components\Citations\Models\Type::all();
     $view->types = $ct;
     // OpenURL
     $openURL = $this->_handleOpenURL();
     $view->openurl['link'] = $openURL['link'];
     $view->openurl['text'] = $openURL['text'];
     $view->openurl['icon'] = $openURL['icon'];
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     return $view->loadTemplate();
 }
예제 #18
0
 /**
  * Load the editor
  *
  * @param   array  $config  Associative array of editor config paramaters
  * @return  mixed
  */
 protected function load($config = array())
 {
     // Check whether editor is already loaded
     if (!is_null($this->editor)) {
         return;
     }
     // Build the path to the needed editor plugin
     $name = (string) preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->name);
     $name = ltrim($name, '.');
     $path = PATH_CORE . '/plugins/editors/' . $name . '/' . $name . '.php';
     if (!is_file($path)) {
         \Notify::error(Lang::txt('JLIB_HTML_EDITOR_CANNOT_LOAD'));
         return false;
     }
     // Require plugin file
     require_once $path;
     // Get the plugin
     $plugin = Plugin::byType('editors', $this->name);
     $params = new Registry($plugin->params);
     $params->merge($config);
     $plugin->params = $params;
     // Build editor plugin classname
     $name = 'plgEditor' . $this->name;
     if ($this->editor = new $name($this, (array) $plugin)) {
         // Load plugin parameters
         $this->initialise();
         Plugin::import('editors-xtd');
     }
 }
예제 #19
0
 /**
  * For version 2.5.x only
  * Check if com_config parameters are blank. If so, populate with com_content text filters.
  *
  * @return  mixed  boolean true if params are updated, null otherwise
  */
 public function fixDefaultTextFilters()
 {
     $table = \JTable::getInstance('Extension');
     $table->load($table->find(array('name' => 'com_config')));
     // Check for empty $config and non-empty content filters
     if (!$table->params) {
         // Get filters from com_content and store if you find them
         $contentParams = Component::params('com_content');
         if ($contentParams->get('filters')) {
             $newParams = new Registry();
             $newParams->set('filters', $contentParams->get('filters'));
             $table->params = (string) $newParams;
             $table->store();
             return true;
         }
     }
 }
예제 #20
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);
 }
예제 #21
0
 /**
  *  Show confirm delete view
  *
  * @return  void
  */
 public function deleteTask()
 {
     // set the neeced layout
     $this->view->setLayout('delete');
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_DELETE_MUST_BE_LOGGED_IN'));
         return;
     }
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Check authorization
     if ($this->_authorize() != 'manager') {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //start log
     $this->view->log = Lang::txt('COM_GROUPS_DELETE_MEMBER_LOG', count($this->view->group->get('members')));
     // Trigger the functions that delete associated content
     // Should return logs of what was deleted
     $logs = Event::trigger('groups.onGroupDeleteCount', array($this->view->group));
     if (count($logs) > 0) {
         $this->view->log .= '<br />' . implode('<br />', $logs);
     }
     // build the title
     $this->_buildTitle();
     // build pathway
     $this->_buildPathway();
     // get view notifications
     $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array();
     //set some vars for view
     $this->view->title = Lang::txt('COM_GROUPS_DELETE_GROUP') . ': ' . $this->view->group->get('description');
     $this->view->msg = Request::getVar('msg', '');
     //display view
     $this->view->display();
 }
예제 #22
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;
 }
예제 #23
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  * @return  mixed    Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('plugin.id');
     if (!isset($this->_cache[$pk])) {
         $false = false;
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return $false;
         }
         // Convert to the Object before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = Arr::toObject($properties, '\\Hubzero\\Base\\Object');
         // Convert the params field to an array.
         $registry = new Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Get the plugin XML.
         $path = array('app' => Filesystem::cleanPath(PATH_APP . DS . 'plugins' . DS . $table->folder . DS . $table->element . DS . $table->element . '.xml'), 'core' => Filesystem::cleanPath(PATH_CORE . DS . 'plugins' . DS . $table->folder . DS . $table->element . DS . $table->element . '.xml'));
         if (file_exists($path['app'])) {
             $this->_cache[$pk]->xml = \JFactory::getXML($path['app']);
         } else {
             if (file_exists($path['core'])) {
                 $this->_cache[$pk]->xml = \JFactory::getXML($path['core']);
             } else {
                 $this->_cache[$pk]->xml = null;
             }
         }
     }
     return $this->_cache[$pk];
 }
예제 #24
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'));
 }
예제 #25
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);
 }