/** * Down **/ public function down() { $this->addPluginEntry('resources', 'abouttool'); if ($this->db->tableExists('#__resource_types')) { // Get all the "mine" queries $this->db->setQuery("SELECT id, params FROM `#__resource_types` WHERE `category`=27 AND `alias`='tools'"); if ($records = $this->db->loadObjectList()) { $path = PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'type.php'; if (!file_exists($path)) { $path = PATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'type.php'; } include_once $path; $tbl = '\\Components\\Resources\\Tables\\Type'; if (class_exists('ResourcesType')) { $tbl = 'ResourcesType'; } // Update the query foreach ($records as $record) { $row = new $tbl($this->db); $row->bind($record); $p = new \Hubzero\Config\Registry($row->params); $p->set('plg_about', 0); $p->set('plg_abouttool', 1); $row->params = $p->toString(); $row->store(); } } } }
/** * Up **/ public function up() { if ($this->db->tableExists('#__extensions')) { $query = "SELECT * FROM `#__extensions` WHERE `type`='plugin' AND `folder`='system' AND `element`='jquery' LIMIT 1;"; $this->db->setQuery($query); if ($plugin = $this->db->loadObject()) { $params = new \Hubzero\Config\Registry($plugin->params); $params->set('jquery', 1); $params->set('jqueryui', 1); $params->set('jqueryfb', 1); $params->set('activateAdmin', 0); $params->set('noconflictAdmin', 0); $params->set('activateSite', 1); $params->set('noconflictSite', 0); $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($params->toString()) . " WHERE `extension_id`=" . $this->db->quote($plugin->extension_id); $this->db->setQuery($query); $this->db->query(); } $query = "SELECT * FROM `#__extensions` WHERE `type`='plugin' AND `folder`='content' AND `element`='formatwiki' LIMIT 1;"; $this->db->setQuery($query); if ($plugin = $this->db->loadObject()) { $params = new \Hubzero\Config\Registry($plugin->params); $params->set('applyFormat', 1); $params->set('convertFormat', 1); $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($params->toString()) . " WHERE `extension_id`=" . $this->db->quote($plugin->extension_id); $this->db->setQuery($query); $this->db->query(); } $query = "SELECT * FROM `#__extensions` WHERE `type`='plugin' AND `folder`='content' AND `element`='formathtml' LIMIT 1;"; $this->db->setQuery($query); if ($plugin = $this->db->loadObject()) { $params = new \Hubzero\Config\Registry($plugin->params); $params->set('applyFormat', 1); $params->set('convertFormat', 0); $params->set('sanitizeBefore', 0); $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($params->toString()) . " WHERE `extension_id`=" . $this->db->quote($plugin->extension_id); $this->db->setQuery($query); $this->db->query(); if (!$plugin->enabled) { $this->enablePlugin('content', 'formathtml'); } } else { $params = new \Hubzero\Config\Registry(); $params->set('applyFormat', 1); $params->set('convertFormat', 0); $params->set('sanitizeBefore', 0); $this->addPluginEntry('content', 'formathtml', 1, $params->toString()); } } }
/** * Up **/ public function up() { if ($this->db->tableExists('#__extensions')) { $query = "SELECT * FROM `#__extensions` WHERE `element` IN ('com_users', 'com_members')"; $this->db->setQuery($query); $objs = $this->db->loadObjectList(); $users = null; $members = null; foreach ($objs as $obj) { if ($obj->element == 'com_users') { $users = new \Hubzero\Config\Registry($obj->params); } if ($obj->element == 'com_members') { $members = new \Hubzero\Config\Registry($obj->params); } } if ($users && $members) { $params = array('allowUserRegistration' => 1, 'new_usertype' => 2, 'guest_usergroup' => 1, 'sendpassword' => 1, 'useractivation' => 2, 'simple_registration' => 0, 'allow_duplicate_emails' => 0, 'mail_to_admin' => 1, 'captcha' => '', 'frontend_userparams' => 1, 'site_language' => 0, 'change_login_name' => 0, 'reset_count' => 10, 'reset_time' => 1, 'login_attempts_limit' => 10, 'login_attempts_timeframe' => 1); foreach ($params as $param => $dflt) { $members->set($param, $users->get('param', $dflt)); } $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($members->toString()) . " WHERE `element`='com_members'"; $this->db->setQuery($query); $this->db->query(); } } }
/** * Up **/ public function up() { $query = "CREATE TABLE IF NOT EXISTS `#__announcements` (\n\t\t\t\t\t`id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`scope` varchar(100) DEFAULT NULL,\n\t\t\t\t\t`scope_id` int(11) DEFAULT NULL,\n\t\t\t\t\t`content` text,\n\t\t\t\t\t`priority` tinyint(2) NOT NULL DEFAULT '0',\n\t\t\t\t\t`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t`created_by` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t`state` tinyint(2) NOT NULL DEFAULT '0',\n\t\t\t\t\t`publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t`publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t`sticky` tinyint(2) NOT NULL DEFAULT '0',\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $this->db->setQuery($query); $this->db->query(); $params = array('plugin_access' => 'members', 'display_tab' => 1); $this->addPluginEntry('groups', 'announcements', 1, $params); // get citation params if ($this->db->tableExists('#__extensions')) { $sql = "SELECT `params` FROM `#__extensions` WHERE `type`='plugin' AND `element`='messages' AND `folder` = 'groups'"; } else { $sql = "SELECT `params` FROM `#__plugins` WHERE `element`='messages' AND `folder`='groups'"; } $this->db->setQuery($sql); $p = $this->db->loadResult(); // load params object $params = new \Hubzero\Config\Registry($p); // set param to hide messages tab $params->set('display_tab', 0); // save new params if ($this->db->tableExists('#__extensions')) { $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote(json_encode($params->toArray())) . " WHERE `element`='messages' AND `folder`='groups'"; } else { $query = "UPDATE `#__plugins` SET `params`='" . $params->toString() . "' WHERE `element`='messages' AND `folder`='groups'"; } $this->db->setQuery($query); $this->db->query(); }
/** * Save changes to the registration * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); $settings = Request::getVar('settings', array(), 'post'); if (!is_array($settings) || empty($settings)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_MEMBERS_REGISTRATION_ERROR_MISSING_DATA'), 'error'); return; } $arr = array(); $component = new \JTableExtension($this->database); $component->load($component->find(array('element' => $this->_option, 'type' => 'component'))); $params = new \Hubzero\Config\Registry($component->params); foreach ($settings as $name => $value) { $r = $value['create'] . $value['proxy'] . $value['update'] . $value['edit']; $params->set('registration' . trim($name), trim($r)); } $component->params = $params->toString(); $component->store(); if (App::get('config')->get('caching')) { $handler = App::get('config')->get('cache_handler'); App::get('config')->set($handler, array('cachebase' => PATH_APP . '/cache/site')); $cache = new \Hubzero\Cache\Manager(\App::getRoot()); $cache->storage($handler); $cache->clean('_system'); } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_MEMBERS_REGISTRATION_SAVED')); }
/** * Short description for 'display' * * Long description (if any) ... * * @param unknown $tpl Parameter description (if any) ... * @return void */ function display($tpl = null) { // Initialize variables $image = ''; $menu = \App::get('menu'); $item = $menu->getActive(); if ($item) { $params = $menu->getParams($item->id); } else { $params = new \Hubzero\Config\Registry(''); $template = App::get('template')->template; $inifile = App::get('template')->path . DS . 'html' . DS . 'com_user' . DS . 'logout' . DS . 'config.ini'; if (file_exists($inifile)) { $params->parse(file_get_contents($inifile)); } $params->def('page_title', Lang::txt('Logout')); } $type = 'logout'; // Set some default page parameters if not set $params->def('show_page_title', 1); if (!$params->get('page_title')) { $params->set('page_title', Lang::txt('Logout')); } if (!$item) { $params->def('header_logout', ''); } $params->def('pageclass_sfx', ''); $params->def('logout', '/'); $params->def('description_logout', 1); $params->def('description_logout_text', Lang::txt('LOGOUT_DESCRIPTION')); $params->def('image_logout', 'key.jpg'); $params->def('image_logout_align', 'right'); $usersConfig = Component::params('com_users'); $params->def('registration', $usersConfig->get('allowUserRegistration')); $title = Lang::txt('Logout'); // Set page title Document::setTitle($title); // Build logout image if enabled if ($params->get('image_' . $type) != -1) { $image = '/images/stories/' . $params->get('image_' . $type); $image = '<img src="' . $image . '" align="' . $params->get('image_' . $type . '_align') . '" hspace="10" alt="" />'; } // Get the return URL if (!($url = Request::getVar('return', '', 'method', 'base64'))) { $url = base64_encode($params->get($type)); } $this->assign('image', $image); $this->assign('type', $type); $this->assign('return', $url); $this->assignRef('params', $params); parent::display($tpl); }
/** * Down **/ public function down() { $this->addComponentEntry('register'); $rparams = $this->getParams('com_members'); $values = $rparams->toArray(); $this->db->setQuery("SELECT * FROM `#__extensions` WHERE `type`='component' AND `element`='com_register' LIMIT 1"); if ($data = $this->db->loadAssoc()) { $component = new \JTableExtension($this->db); $component->bind($data); $mparams = new \Hubzero\Config\Registry($component->params); foreach ($values as $key => $value) { $mparams->set($key, $value); } $component->params = $mparams->toString(); $component->store(); } }
/** * Up **/ public function up() { if ($this->db->tableExists('#__extensions')) { $query = "SELECT * FROM `#__extensions` WHERE `element`=" . $this->db->quote('novnc') . " AND `folder`=" . $this->db->quote('tools'); $this->db->setQuery($query); $result = $this->db->loadObject(); if ($result && $result->extension_id) { $params = new \Hubzero\Config\Registry($result->params); $params->set('browsers', '*, safari 5.1 *, chrome 26.0 *, iceweasel 38.0 *, firefox 30.0 *, opera 23.0 *, mozilla 5.0 iOS, safari 1.0 Windows, msie 10.0 Windows, ie 10.0'); $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($params->toString()) . " WHERE `extension_id`=" . $this->db->quote($result->extension_id); $this->db->setQuery($query); $this->db->query(); } $query = "SELECT * FROM `#__extensions` WHERE `element`=" . $this->db->quote('java') . " AND `folder`=" . $this->db->quote('tools'); $this->db->setQuery($query); $result = $this->db->loadObject(); if ($result && $result->extension_id) { $params = new \Hubzero\Config\Registry($result->params); $params->set('browsers', '*, chrome 999999.0 *, safari 1.0 *, iceweasel 1.0 *, firefox 1.0 *, opera 1.0 *, IE 3.0 *, mozilla 5.0 iOS, Safari 9999.9'); $query = "UPDATE `#__extensions` SET `params`=" . $this->db->quote($params->toString()) . " WHERE `extension_id`=" . $this->db->quote($result->extension_id); $this->db->setQuery($query); $this->db->query(); } } }
/** * Method is called after user data is stored in the database * * @param array $user holds the new user data * @param boolean $isnew true if a new user is stored * @param boolean $success true if user was succesfully stored in the database * @param string $msg message * @return void */ public function onAfterStoreUser($user, $isnew, $succes, $msg) { $xprofile = \Hubzero\User\Profile::getInstance($user['id']); if (!is_object($xprofile)) { $params = Component::params('com_members'); $hubHomeDir = rtrim($params->get('homedir'), '/'); if (empty($hubHomeDir)) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } if (!empty($hubHomeDir)) { $db = App::get('db'); $component = new JTableExtension($this->database); $component->load($component->find(array('element' => 'com_members', 'type' => 'component'))); $params = new \Hubzero\Config\Registry($component->params); $params->set('homedir', $hubHomeDir); $component->params = $params->toString(); $component->store(); } } $xprofile = new \Hubzero\User\Profile(); $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $xprofile->set('gid', $params->get('gid', 'users')); $xprofile->set('uidNumber', $user['id']); $xprofile->set('homeDirectory', $hubHomeDir . DS . $user['username']); $xprofile->set('loginShell', '/bin/bash'); $xprofile->set('ftpShell', '/usr/lib/sftp-server'); $xprofile->set('name', $user['name']); $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', '3'); $xprofile->set('username', $user['username']); $xprofile->set('regIP', $_SERVER['REMOTE_ADDR']); $xprofile->set('emailConfirmed', -rand(1, pow(2, 31) - 1)); $xprofile->set('public', $params->get('privacy', 0)); if (isset($_SERVER['REMOTE_HOST'])) { $xprofile->set('regHost', $_SERVER['REMOTE_HOST']); } $xprofile->set('registerDate', Date::toSql()); $result = $xprofile->create(); if (!$result) { return new Exception('Unable to create \\Hubzero\\User\\Profile record', 500); } } else { $update = false; $params = Component::params('com_members'); if ($xprofile->get('username') != $user['username']) { $xprofile->set('username', $user['username']); $update = true; } if ($xprofile->get('name') != $user['name']) { $xprofile->set('name', $user['name']); $update = true; } if ($xprofile->get('email') != $user['email']) { $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', 0); $update = true; } if ($xprofile->get('emailConfirmed') == '') { $xprofile->set('emailConfirmed', '3'); $update = true; } if ($xprofile->get('gid') == '') { $xprofile->set('gid', $params->get('gid', 'users')); $update = true; } if ($xprofile->get('gidNumber') == '') { $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $update = true; } if ($xprofile->get('loginShell') == '') { $xprofile->set('loginShell', '/bin/bash'); $update = true; } if ($xprofile->get('ftpShell') == '') { $xprofile->set('ftpShell', '/usr/lib/sftp-server'); // This isn't right, but we're using an empty shell as an indicator that we should also update default privacy $xprofile->set('public', $params->get('privacy', 0)); $update = true; } if ($update) { $xprofile->update(); } } // Check if quota exists for the user $params = Component::params('com_members'); if ($params->get('manage_quotas', false)) { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'users_quotas.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'quotas_classes.php'; $quota = new \Components\Members\Tables\UsersQuotas($this->database); $quota->load(array('user_id' => $user['id'])); if (!$quota->id) { $class = new \Components\Members\Tables\QuotasClasses($this->database); $class->load(array('alias' => 'default')); if ($class->id) { $quota->set('user_id', $user['id']); $quota->set('class_id', $class->id); $quota->set('soft_blocks', $class->soft_blocks); $quota->set('hard_blocks', $class->hard_blocks); $quota->set('soft_files', $class->soft_files); $quota->set('hard_files', $class->hard_files); $quota->store(); } } } }
/** * Final submission * * @return void */ public function submitTask() { // Incoming $id = Request::getInt('id', 0); // Ensure we have an ID to work with if (!$id) { throw new Exception(Lang::txt('COM_CONTRIBUTE_NO_ID'), 500); } // Load resource info $resource = new Resource($this->database); $resource->load($id); // Set a flag for if the resource was already published or not $published = 0; if ($resource->published != 2) { $published = 1; } // Check if a newly submitted resource was authorized to be published $authorized = Request::getInt('authorization', 0); if (!$authorized && !$published) { $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_NOT_AUTHORIZED')); $this->_checkProgress($id); $this->step_review(); return; } // Is this a newly submitted resource? if (!$published) { // 0 = unpublished, 1 = published, 2 = composing, 3 = pending (submitted), 4 = deleted // Are submissions auto-approved? if ($this->config->get('autoapprove') == 1) { //checks if autoapproved content has children (configurable in options on backend) if ($this->config->get('autoapprove_content_check') == 1) { require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'resource.php'; $item = new \Components\Resources\Models\Resource($id); if (count($item->children()) < 1) { $this->setError(Lang::txt('COM_CONTRIBUTE_NO_CONTENT')); $this->step_review(); return; } } // Set status to published $resource->published = 1; $resource->publish_up = Date::toSql(); } else { $apu = $this->config->get('autoapproved_users'); $apu = explode(',', $apu); $apu = array_map('trim', $apu); if (in_array(User::get('username'), $apu)) { // Set status to published $resource->published = 1; $resource->publish_up = Date::toSql(); } else { // Set status to pending review (submitted) $resource->published = 3; } } // Get the resource's contributors $helper = new Helper($id, $this->database); $helper->getCons(); $contributors = $helper->_contributors; if (!$contributors || count($contributors) <= 0) { $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_HAS_NO_AUTHORS')); $this->_checkProgress($id); $this->step_review(); return; } // Get any set emails that should be notified of ticket submission $defs = explode(',', $this->config->get('email_when_submitted', '{config.mailfrom}')); if (!empty($defs)) { $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_RESOURCES_EMAIL_SUBJECT_NEW_SUBMISSION', $resource->id)); $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option))); // Plain text email $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'submitted_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->resource = $resource; $eview->delimiter = ''; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); $message->addPart($plain, 'text/plain'); // HTML email $eview->setLayout('submitted_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); $message->addPart($html, 'text/html'); // Loop through the addresses foreach ($defs as $def) { $def = trim($def); // Check if the address should come from config if ($def == '{config.mailfrom}') { $def = Config::get('mailfrom'); } // Check for a valid address if (\Hubzero\Utility\Validate::email($def)) { // Send e-mail $message->setTo(array($def)); $message->send(); } } } } // Is this resource licensed under Creative Commons? if ($this->config->get('cc_license')) { $license = Request::getVar('license', ''); if ($license == 'custom') { $license .= $resource->id; $licenseText = Request::getVar('license-text', ''); if ($licenseText == '[ENTER LICENSE HERE]') { $this->setError(Lang::txt('Please enter a license.')); $this->_checkProgress($id); $this->step_review(); return; } include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'license.php'; $rl = new License($this->database); $rl->load($license); $rl->name = $license; $rl->text = $licenseText; $rl->info = $resource->id; $rl->check(); $rl->store(); } // set license $params = new \Hubzero\Config\Registry($resource->params); $params->set('license', $license); $resource->params = $params->toString(); } // Save and checkin the resource $resource->store(); $resource->checkin(); // If a previously published resource, redirect to the resource page if ($published == 1) { if ($resource->alias) { $url = Route::url('index.php?option=com_resources&alias=' . $resource->alias); } else { $url = Route::url('index.php?option=com_resources&id=' . $resource->id); } App::redirect($url); return; } // Output HTML $this->setView($this->_controller, 'thanks'); $this->view->title = $this->_title; $this->view->config = $this->config; $this->view->resource = $resource; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }
echo Lang::txt('COM_MEMBERS_SPAM_COUNT_EXCEEDED'); ?> </p> <?php } ?> </div> <?php } ?> </fieldset> <?php // Create a new form $data = new Hubzero\Config\Registry(); $data->set('params', $this->profile->params->toArray()); $form = new Hubzero\Form\Form('fields', array('control' => 'fields')); $form->load(Hubzero\Form\Form::getXML(Component::path('com_members') . DS . 'models' . DS . 'forms' . DS . 'user.xml', true)); $form->bind($data); $fieldsets = $form->getFieldsets(); echo Html::sliders('start'); foreach ($fieldsets as $fieldset) { if ($fieldset->name == 'user_details') { continue; } echo Html::sliders('panel', Lang::txt($fieldset->label), $fieldset->name); ?> <fieldset class="panelform"> <?php foreach ($form->getFieldset($fieldset->name) as $field) { ?>
/** * Saves changes to a course or saves a new entry if creating * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post'); // Instantiate a Course object $model = \Components\Courses\Models\Offering::getInstance($fields['id']); if (!$model->bind($fields)) { $this->setError($model->getError()); $this->editTask($model); return; } $p = new \Hubzero\Config\Registry(''); $p->parse(Request::getVar('params', '', 'post')); // Make sure the logo gets carried over $op = new \Hubzero\Config\Registry($model->get('params')); $p->set('logo', $op->get('logo')); $model->set('params', $p->toString()); if (!$model->store(true)) { $this->setError($model->getError()); $this->editTask($model); return; } if ($this->_task == 'apply') { return $this->editTask($model); } // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&course=' . $model->get('course_id'), false), Lang::txt('COM_COURSES_ITEM_SAVED')); }
/** * Saves a resource * Redirects to main listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Initiate extended database class $row = new Resource($this->database); if (!$row->bind($_POST)) { throw new Exception($row->getError(), 400); } $isNew = 0; if ($row->id < 1) { $isNew = 1; } if ($isNew) { // New entry $row->created = $row->created ? $row->created : Date::toSql(); $row->created_by = $row->created_by ? $row->created_by : User::get('id'); $row->access = 0; } else { $old = new Resource($this->database); $old->load($row->id); $created_by_id = Request::getInt('created_by_id', 0); // Updating entry $row->modified = Date::toSql(); $row->modified_by = User::get('id'); if ($created_by_id) { $row->created_by = $row->created_by ? $row->created_by : $created_by_id; } else { $row->created_by = $row->created_by ? $row->created_by : User::get('id'); } } // publish up $row->publish_up = Date::of($row->publish_up, Config::get('offset'))->toSql(); // publish down if (!$row->publish_down || trim($row->publish_down) == '0000-00-00 00:00:00' || trim($row->publish_down) == 'Never') { $row->publish_down = '0000-00-00 00:00:00'; } else { $row->publish_down = Date::of($row->publish_down, Config::get('offset'))->toSql(); } // Get parameters $params = Request::getVar('params', array(), 'post'); if (is_array($params)) { $txt = new \Hubzero\Config\Registry(''); foreach ($params as $k => $v) { $txt->set($k, $v); } $row->params = $txt->toString(); } // Get attributes $attribs = Request::getVar('attrib', array(), 'post'); if (is_array($attribs)) { $txta = new \Hubzero\Config\Registry(''); foreach ($attribs as $k => $v) { if ($k == 'timeof') { if (strtotime(trim($v)) === false) { $v = NULL; } $v = trim($v) ? Date::of($v, Config::get('offset'))->toSql() : NULL; } $txta->set($k, $v); } $row->attribs = $txta->toString(); } // Get custom areas, add wrappers, and compile into fulltxt if (isset($_POST['nbtag'])) { $type = new Type($this->database); $type->load($row->type); include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'elements.php'; $elements = new \Components\Resources\Models\Elements(array(), $type->customFields); $schema = $elements->getSchema(); $fields = array(); foreach ($schema->fields as $field) { $fields[$field->name] = $field; } $nbtag = $_POST['nbtag']; $found = array(); foreach ($nbtag as $tagname => $tagcontent) { $f = ''; $row->fulltxt .= "\n" . '<nb:' . $tagname . '>'; if (is_array($tagcontent)) { $c = count($tagcontent); $num = 0; foreach ($tagcontent as $key => $val) { if (trim($val)) { $num++; } $row->fulltxt .= '<' . $key . '>' . trim($val) . '</' . $key . '>'; } if ($c == $num) { $f = 'found'; } } else { $f = trim($tagcontent); if ($f) { $row->fulltxt .= trim($tagcontent); } } $row->fulltxt .= '</nb:' . $tagname . '>' . "\n"; if (!$tagcontent && isset($fields[$tagname]) && $fields[$tagname]->required) { throw new Exception(Lang::txt('RESOURCES_REQUIRED_FIELD_CHECK', $fields[$tagname]->label), 500); } $found[] = $tagname; } foreach ($fields as $field) { if (!in_array($field->name, $found) && $field->required) { $found[] = $field->name; $this->setError(Lang::txt('COM_CONTRIBUTE_REQUIRED_FIELD_CHECK', $field->label)); } } } // Code cleaner for xhtml transitional compliance if ($row->type != 7) { $row->introtext = str_replace('<br>', '<br />', $row->introtext); $row->fulltxt = str_replace('<br>', '<br />', $row->fulltxt); } // Check content if (!$row->check()) { throw new Exception($row->getError(), 500); } // Store content if (!$row->store()) { throw new Exception($row->getError(), 500); } // Checkin resource $row->checkin(); // Rename the temporary upload directory if it exist $tmpid = Request::getInt('tmpid', 0, 'post'); if ($tmpid != Html::niceidformat($row->id)) { // Build the full paths $path = Html::dateToPath($row->created); $dir_id = Html::niceidformat($row->id); $tmppath = Utilities::buildUploadPath($path . DS . $tmpid); $newpath = Utilities::buildUploadPath($path . DS . $dir_id); // Attempt to rename the temp directory if (\Filesystem::exists($tmppath)) { $result = \Filesystem::move($tmppath, $newpath); if ($result !== true) { $this->setError($result); } } $row->path = str_replace($tmpid, Html::niceidformat($row->id), $row->path); $row->store(); } // Incoming tags $tags = Request::getVar('tags', '', 'post'); // Save the tags $rt = new Tags($row->id); $rt->setTags($tags, User::get('id'), 1, 1); // Incoming authors if ($row->type != 7) { $authorsOldstr = Request::getVar('old_authors', '', 'post'); $authorsNewstr = Request::getVar('new_authors', '', 'post'); if (!$authorsNewstr) { $authorsNewstr = $authorsOldstr; } include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor.php'; $authorsNew = explode(',', $authorsNewstr); $authorsOld = explode(',', $authorsOldstr); // We have either a new ordering or new authors or both if ($authorsNewstr) { for ($i = 0, $n = count($authorsNew); $i < $n; $i++) { $rc = new Contributor($this->database); $rc->subtable = 'resources'; $rc->subid = $row->id; if (is_numeric($authorsNew[$i])) { $rc->authorid = $authorsNew[$i]; } else { $rc->authorid = $rc->getUserId($authorsNew[$i]); } $rc->ordering = $i; $rc->role = trim(Request::getVar($authorsNew[$i] . '_role', '')); $rc->name = trim(Request::getVar($authorsNew[$i] . '_name', '')); $rc->organization = trim(Request::getVar($authorsNew[$i] . '_organization', '')); $authorsNew[$i] = $rc->authorid; if (in_array($authorsNew[$i], $authorsOld)) { //echo 'update: ' . $rc->authorid . ', ' . $rc->role . ', ' . $rc->name . ', ' . $rc->organization . '<br />'; // Updating record $rc->updateAssociation(); } else { //echo 'create: ' . $rc->authorid . ', ' . $rc->role . ', ' . $rc->name . ', ' . $rc->organization . '<br />'; // New record $rc->createAssociation(); } } } // Run through previous author list and check to see if any IDs had been dropped if ($authorsOldstr) { $rc = new Contributor($this->database); for ($i = 0, $n = count($authorsOld); $i < $n; $i++) { if (!in_array($authorsOld[$i], $authorsNew)) { $rc->deleteAssociation($authorsOld[$i], $row->id, 'resources'); } } } } // If this is a child, add parent/child association $pid = Request::getInt('pid', 0, 'post'); if ($isNew && $pid) { $this->_attachChild($row->id, $pid); } // Is this a standalone resource and we need to email approved submissions? if ($row->standalone == 1 && $this->config->get('email_when_approved')) { // If the state went from pending to published if ($row->published == 1 && $old->published == 3) { $this->_emailContributors($row, $this->database); } } // Redirect App::redirect($this->buildRedirectURL($pid), Lang::txt('COM_RESOURCES_ITEM_SAVED')); }
/** * Method is called after user data is stored in the database * * @param array $user holds the new user data * @param boolean $isnew true if a new user is stored * @param boolean $success true if user was succesfully stored in the database * @param string $msg message * @return void */ public function onAfterStoreUser($user, $isnew, $success, $msg) { $xprofile = \Hubzero\User\Profile::getInstance($user['id']); if (!is_object($xprofile)) { $params = Component::params('com_members'); $hubHomeDir = rtrim($params->get('homedir'), '/'); if (empty($hubHomeDir)) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } if (!empty($hubHomeDir)) { $db = App::get('db'); $component = new JTableExtension($this->database); $component->load($component->find(array('element' => 'com_members', 'type' => 'component'))); $params = new \Hubzero\Config\Registry($component->params); $params->set('homedir', $hubHomeDir); $component->params = $params->toString(); $component->store(); } } $xprofile = new \Hubzero\User\Profile(); $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $xprofile->set('gid', $params->get('gid', 'users')); $xprofile->set('uidNumber', $user['id']); $xprofile->set('homeDirectory', isset($user['homeDirectory']) ? $user['homeDirectory'] : $hubHomeDir . DS . $user['username']); $xprofile->set('loginShell', isset($user['loginShell']) ? $user['loginShell'] : '/bin/bash'); $xprofile->set('ftpShell', isset($user['ftpShell']) ? $user['ftpShell'] : '/usr/lib/sftp-server'); $xprofile->set('name', $user['name']); $xprofile->set('email', $user['email']); $xprofile->set('username', $user['username']); $xprofile->set('regIP', $_SERVER['REMOTE_ADDR']); //$xprofile->set('emailConfirmed', '3'); $xprofile->set('emailConfirmed', isset($user['activation']) ? $user['activation'] : -rand(1, pow(2, 31) - 1)); $xprofile->set('public', $params->get('privacy', 0)); if (isset($_SERVER['REMOTE_HOST'])) { $xprofile->set('regHost', $_SERVER['REMOTE_HOST']); } $xprofile->set('registerDate', Date::toSql()); $result = $xprofile->create(); if (!$result) { return new Exception('Unable to create \\Hubzero\\User\\Profile record', 500); } } else { $update = false; $params = Component::params('com_members'); if ($xprofile->get('username') != $user['username']) { $xprofile->set('username', $user['username']); $update = true; } if ($xprofile->get('name') != $user['name']) { $xprofile->set('name', $user['name']); $update = true; } // Fix missing surname/given name as well if ($xprofile->get('name') && (!$xprofile->get('surname') || !$xprofile->get('givenName'))) { $firstname = $xprofile->get('givenName'); $middlename = $xprofile->get('middleName'); $lastname = $xprofile->get('surname'); $words = array_map('trim', explode(' ', $xprofile->get('name'))); $count = count($words); if ($count == 1) { $firstname = $words[0]; } else { if ($count == 2) { $firstname = $words[0]; $lastname = $words[1]; } else { if ($count == 3) { $firstname = $words[0]; $middlename = $words[1]; $lastname = $words[2]; } else { $firstname = $words[0]; $lastname = $words[$count - 1]; $middlename = $words[1]; for ($i = 2; $i < $count - 1; $i++) { $middlename .= ' ' . $words[$i]; } } } } $firstname = trim($firstname); if ($firstname) { $xprofile->set('givenName', $firstname); } $middlename = trim($middlename); if ($middlename) { $xprofile->set('middleName', $middlename); } $lastname = trim($lastname); if ($lastname) { $xprofile->set('surname', $lastname); } $update = true; } if ($xprofile->get('email') != $user['email']) { $xprofile->set('email', $user['email']); $xprofile->set('emailConfirmed', 0); $update = true; } if ($xprofile->get('emailConfirmed') == '') { $xprofile->set('emailConfirmed', '3'); $update = true; } if ($xprofile->get('gid') == '') { $xprofile->set('gid', $params->get('gid', 'users')); $update = true; } if ($xprofile->get('gidNumber') == '') { $xprofile->set('gidNumber', $params->get('gidNumber', '100')); $update = true; } if ($xprofile->get('loginShell') == '') { $xprofile->set('loginShell', '/bin/bash'); $update = true; } if ($xprofile->get('ftpShell') == '') { $xprofile->set('ftpShell', '/usr/lib/sftp-server'); // This isn't right, but we're using an empty shell as an indicator that we should also update default privacy $xprofile->set('public', $params->get('privacy', 0)); $update = true; } if ($update) { $xprofile->update(); } } // Check if quota exists for the user $params = Component::params('com_members'); if ($params->get('manage_quotas', false)) { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'quota.php'; $quota = Components\Members\Models\Quota::all()->whereEquals('user_id', $user['id'])->row(); if (!$quota->get('id')) { $class = Components\Members\Models\Quota\Category::defaultEntry(); if ($class->get('id')) { $quota->set('user_id', $user['id']); $quota->set('class_id', $class->get('id')); $quota->set('soft_blocks', $class->get('soft_blocks')); $quota->set('hard_blocks', $class->get('hard_blocks')); $quota->set('soft_files', $class->get('soft_files')); $quota->set('hard_files', $class->get('hard_files')); $quota->save(); } } } if ($success) { Event::trigger('members.onMemberAfterSave', array($user, $isnew, $success, $msg)); } }
/** * Save an entry * * @return void */ public function saveTask() { $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@us' => 'us', '@PU' => 'pu', '@pu' => 'pu', '@D1' => 'd1', '@d1' => 'd1'); // set vars $tool = Request::getVar('tool', array(), 'post'); $tool = array_map('trim', $tool); // Sanitize the input a bit $noHtmlFilter = \JFilterInput::getInstance(); foreach ($tool as $i => $var) { $tool[$i] = $noHtmlFilter->clean($var); } $today = Date::toSql(); $group_prefix = $this->config->get('group_prefix', 'app-'); $dev_suffix = $this->config->get('dev_suffix', '_dev'); // pass data from forms $id = Request::getInt('toolid', 0); $this->_action = Request::getVar('action', ''); $comment = Request::getVar('comment', ''); $editversion = Request::getVar('editversion', 'dev', 'post'); //$toolname = strtolower($tool['toolname']); $oldstatus = array(); // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); if ($id) { // make sure user is authorized to go further if (!$this->_checkAccess($id)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } } if (!\Components\Tools\Models\Tool::validate($tool, $err, $id)) { // display form with errors //$title = Lang::txt(strtoupper($this->_option)).': '.Lang::txt('COM_TOOLS_EDIT_TOOL'); //Document::setTitle($title); if (is_array($err)) { foreach ($err as $error) { $this->setError($error); } } else { $this->setError($err); } if ($id) { // get tool status $obj->getToolStatus($id, $this->_option, $fstatus, $editversion); $tool['developers'] = $fstatus['developers']; $tool['membergroups'] = $fstatus['membergroups']; $tool['published'] = $fstatus['published']; } $this->editTask($tool); return; } $tool['vncGeometry'] = $tool['vncGeometryX'] . 'x' . $tool['vncGeometryY']; $tool['toolname'] = strtolower($tool['toolname']); $tool['developers'] = array_map('trim', explode(',', $tool['developers'])); $tool['membergroups'] = array_map('trim', explode(',', $tool['membergroups'])); $tool['hostreq'] = array_map('trim', explode(',', $tool['hostreq'])); // save tool info if (!$id) { $hzt = \Components\Tools\Models\Tool::createInstance($tool['toolname']); $hzt->toolname = $tool['toolname']; $hzt->title = $tool['title']; $hzt->published = 0; $hzt->state = 1; $hzt->priority = 3; $hzt->registered = $today; $hzt->state_changed = $today; $hzt->registered_by = User::get('username'); } else { $hzt = \Components\Tools\Models\Tool::getInstance($id); } // get tool id for newly registered tool $this->_toolid = $hzt->id; // save version info $hztv = $hzt->getRevision($editversion); if ($hztv) { $oldstatus = $hztv->toArray(); $oldstatus['toolstate'] = $hzt->state; $oldstatus['membergroups'] = $tool['membergroups']; if ($id) { $oldstatus['developers'] = $obj->getToolDevelopers($id); } } // NEW: save github repo as param $params = ''; $version = $objV->getVersionInfo($this->_toolid, 'dev'); if ($version && !empty($version[0])) { $txt = new \Hubzero\Config\Registry($version[0]->params); } else { $txt = new \Hubzero\Config\Registry(''); } $txt->set('github', $tool['github']); $ptype = empty($tool['publishType']) || $tool['publishType'] == 'standard' ? 'standard' : 'weber='; $txt->set('publishType', $ptype); $params = $txt->toString(); if ($editversion == 'dev') { if ($hztv === false) { Log::debug(__FUNCTION__ . "() HZTV createInstance dev_suffix={$dev_suffix}"); $hztv = \Components\Tools\Models\Version::createInstance($tool['toolname'], $tool['toolname'] . $dev_suffix); $oldstatus = $hztv->toArray(); $oldstatus['toolstate'] = $hzt->state; $oldstatus['membergroups'] = $tool['membergroups']; } if ($id) { $oldstatus['developers'] = $obj->getToolDevelopers($id); } $invokedir = $this->config->get('invokescript_dir', DS . 'apps'); $invokedir = rtrim($invokedir, DS); $hztv->toolid = $this->_toolid; $hztv->toolname = $tool['toolname']; $hztv->title = $tool['title']; $hztv->version = $tool['version']; $hztv->description = $tool['description']; $hztv->toolaccess = $tool['exec']; $hztv->codeaccess = $tool['code']; $hztv->wikiaccess = $tool['wiki']; $hztv->vnc_command = $invokedir . DS . $tool['toolname'] . DS . 'dev' . DS . 'middleware' . DS . 'invoke -T dev'; $hztv->vnc_geometry = $tool['vncGeometry']; $hztv->exportControl = $exportmap[$tool['exec']]; $hztv->state = 3; $hztv->instance = $tool['toolname'] . $dev_suffix; $hztv->mw = $this->config->get('default_mw', 'narwhal'); $hztv->hostreq = $tool['hostreq']; $hztv->params = $params; $hzt->add('version', $hztv->instance); } else { if ($hztv) { $hztv->toolid = $this->_toolid; $hztv->toolname = $tool['toolname']; $hztv->title = $tool['title']; $hztv->version = $tool['version']; $hztv->description = $tool['description']; $hztv->toolaccess = $tool['exec']; $hztv->codeaccess = $tool['code']; $hztv->wikiaccess = $tool['wiki']; $hztv->vnc_geometry = $tool['vncGeometry']; $hztv->exportControl = $exportmap[$tool['exec']]; $hztv->hostreq = $tool['hostreq']; $hzt->add('version', $hztv->instance); } } $this->_setTracAccess($tool['toolname'], $hztv->codeaccess, $hztv->wikiaccess); if ($this->_error) { App::abort(500, $this->_error); return; } // create/update developers group $gid = $hztv->getDevelopmentGroup(); if (empty($gid)) { $hzg = new \Hubzero\User\Group(); $hzg->cn = $group_prefix . strtolower($tool['toolname']); $hzg->create(); $hzg->set('type', 2); $hzg->set('description', Lang::txt('COM_TOOLS_DELEVOPMENT_GROUP', $tool['title'])); $hzg->set('created', Date::toSql()); $hzg->set('created_by', User::get('id')); } else { $hzg = \Hubzero\User\Group::getInstance($gid); } $hzg->set('members', $tool['developers']); $hztrac = \Hubzero\Trac\Project::find_or_create('app:' . $tool['toolname']); $hztrac->add_group_permission('apps', array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW')); $hztrac->add_group_permission($hzg->cn, array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW')); $hztv->set('owner', $hzg->cn); $hztv->add('owner', 'apps'); $hztv->set('member', $tool['membergroups']); // Add repo for new tools $auto_addrepo = $this->config->get('auto_addrepo', 1); if (!$id && $auto_addrepo) { $hzt->update(); // Make sure tool exists in database or gensvn won't configure apachce access to it $hztv->update(); // Make sure tool exists in database or gensvn won't configure apachce access to it // Run add repo $this->_addRepo($output, array('toolname' => $tool['toolname'], 'title' => $tool['title'], 'description' => $tool['description'])); if ($output['class'] != 'error') { $hzt->state = 2; $hzt->update(); } } // get ticket information if (empty($hzt->ticketid)) { $hzt->ticketid = $this->_createTicket($this->_toolid, $tool); } // create resource page $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id); if (empty($rid)) { include_once __DIR__ . DS . 'resource.php'; $resource = new Resource(); $rid = $resource->createPage($this->_toolid, $tool); // save authors by default //$objA = new \Components\Tools\Tables\Author($this->database); //if (!$id) { $objA->saveAuthors($tool['developers'], 'dev', $rid, '', $tool['toolname']); } if (!$id) { require_once __DIR__ . DS . 'authors.php'; $controller = new Authors(); $controller->saveTask(0, $rid, $tool['developers']); //$this->author_save(0, $rid, $tool['developers']); } } // display status page //$this->_task = 'status'; //$this->_msg = $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED'): Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED'); $hzg->update(); $hzt->update(); $hztv->update(); // @FIXME: look $status = $hztv->toArray(); $status['toolstate'] = $hzt->state; $status['membergroups'] = $tool['membergroups']; $status['toolname'] = $tool['toolname']; if ($id) { $status['developers'] = $obj->getToolDevelopers($id); } // update history ticket if ($id && $oldstatus != $status && $editversion != 'current') { $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, 0, 1); } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $hzt->toolname), $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED') : Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED')); }
// make sure roles match pattern "Expert: ..." $roles = array_map(function ($role) { if (preg_match('/Expert:(.*)/', $role['name'])) { return $role['name']; } }, $roles); // if we are in any expert role mark as expert if (count($roles) > 0) { $experts[] = $member; } } // mark comments for experts $params = new \Hubzero\Config\Registry(); $params->set('onCommentMark', function ($comment) use($experts) { if (in_array($comment->creator('id'), $experts)) { return 'expert'; } return ''; }); // lock comments if ($displayComments == 2) { $params->set('comments_locked', 1); $params->set('access-create-comment', 0); $params->set('access-edit-comment', 0); $params->set('access-delete-comment', 0); $params->set('access-manage-comment', 0); $params->set('access-vote-comment', 0); } if (in_array(User::get('id'), $this->group->get('managers'))) { $params->set('access-create-comment', 1); $params->set('access-edit-comment', 1); $params->set('access-delete-comment', 1);
// No direct access defined('_HZEXEC_') or die; include_once Component::path('com_members') . DS . 'models' . DS . 'profile' . DS . 'field.php'; $fields = Components\Members\Models\Profile\Field::all()->including(['options', function ($option) { $option->select('*'); }])->ordered()->rows(); $access = array(); foreach ($fields as $field) { $access[$field->get('name')] = $field->get('access'); } // Convert to XML so we can use the Form processor $xml = Components\Members\Models\Profile\Field::toXml($fields); $profiles = $this->profile->profiles()->ordered()->rows(); // Gather data to pass to the form processor $data = new Hubzero\Config\Registry(Components\Members\Models\Profile::collect($profiles)); $data->set('tags', $this->profile->tags('string')); foreach ($profiles as $profile) { $d = isset($access[$profile->get('profile_key')]) ? $access[$profile->get('profile_key')] : 1; $access[$profile->get('profile_key')] = $profile->get('access', $d); } // Create a new form Hubzero\Form\Form::addFieldPath(Component::path('com_members') . DS . 'models' . DS . 'fields'); $form = new Hubzero\Form\Form('profile', array('control' => 'profile')); $form->load($xml); $form->bind($data); $fields = $form->getFieldset('basic'); ?> <div class="grid"> <div class="col span7"> <fieldset class="adminform"> <legend><span><?php
/** * Saves changes to a course or saves a new entry if creating * * @return void */ public function saveTask($redirect = true) { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post'); // Instantiate a Course object $model = \Components\Courses\Models\Section::getInstance($fields['id']); if (!$model->bind($fields)) { $this->setError($model->getError()); $this->editTask($model); return; } $p = new \Hubzero\Config\Registry(Request::getVar('params', '', 'post')); // Make sure the logo gets carried over $op = new \Hubzero\Config\Registry($model->get('params')); $p->set('logo', $op->get('logo')); $model->set('params', $p->toString()); if (!$model->store(true)) { $this->setError($model->getError()); $this->editTask($model); return; } $dates = Request::getVar('dates', array(), 'post'); //$i=0; //$unit_up = ''; //$unit_down = ''; foreach ($dates as $i => $dt) { /*if (!$unit_up && $i == 0) { $unit_up = $dt['publish_up']; } if (!$unit_down && $i == 0) { $unit_down = $dt['publish_down']; }*/ $dt['section_id'] = $model->get('id'); $dt = $this->_datesToUTC($dt); $dtmodel = new \Components\Courses\Models\Section\Date($dt['id']); if (!$dtmodel->bind($dt)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } if (isset($dt['asset_group'])) { foreach ($dt['asset_group'] as $j => $ag) { $ag = $this->_datesToUTC($ag); if (!isset($ag['publish_up']) || !$ag['publish_up']) { $ag['publish_up'] = $dt['publish_up']; } if (!isset($ag['publish_down']) || !$ag['publish_down']) { $ag['publish_down'] = $dt['publish_down']; } $ag['section_id'] = $model->get('id'); $dtmodel = new \Components\Courses\Models\Section\Date($ag['id']); if (!$dtmodel->bind($ag)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } if (isset($ag['asset_group'])) { foreach ($ag['asset_group'] as $k => $agt) { $agt = $this->_datesToUTC($agt); if (!isset($agt['publish_up']) || !$agt['publish_up']) { $agt['publish_up'] = $ag['publish_up']; } if (!isset($agt['publish_down']) || !$agt['publish_down']) { $agt['publish_down'] = $ag['publish_down']; } $agt['section_id'] = $model->get('id'); $dtmodel = new \Components\Courses\Models\Section\Date($agt['id']); if (!$dtmodel->bind($agt)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } if (isset($agt['asset'])) { foreach ($agt['asset'] as $z => $a) { $a = $this->_datesToUTC($a); if (!isset($a['publish_up']) || !$a['publish_up']) { $a['publish_up'] = $agt['publish_up']; } if (!isset($a['publish_down']) || !$a['publish_down']) { $a['publish_down'] = $agt['publish_down']; } $a['section_id'] = $model->get('id'); $dtmodel = new \Components\Courses\Models\Section\Date($a['id']); if (!$dtmodel->bind($a)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } //$agt['asset'][$z] = $a; } } //$ag['asset_group'][$k] = $agt; } } if (isset($ag['asset'])) { foreach ($ag['asset'] as $z => $a) { $a = $this->_datesToUTC($a); if (!isset($a['publish_up']) || !$a['publish_up']) { $a['publish_up'] = $ag['publish_up']; } if (!isset($a['publish_down']) || !$a['publish_down']) { $a['publish_down'] = $ag['publish_down']; } $a['section_id'] = $model->get('id'); $dtmodel = new \Components\Courses\Models\Section\Date($a['id']); if (!$dtmodel->bind($a)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } } } } } if (isset($dt['asset'])) { foreach ($dt['asset'] as $z => $a) { $a = $this->_datesToUTC($a); if (!isset($a['publish_up']) || !$a['publish_up']) { $a['publish_up'] = $dt['publish_up']; } if (!isset($a['publish_down']) || !$a['publish_down']) { $a['publish_down'] = $dt['publish_down']; } $a['section_id'] = $model->get('id'); $dtmodel = new \Components\Courses\Models\Section\Date($a['id']); if (!$dtmodel->bind($a)) { $this->setError($dtmodel->getError()); continue; } if (!$dtmodel->store(true)) { $this->setError($dtmodel->getError()); continue; } //$agt['asset'][$z] = $a; } } } // Process badge info $badge = Request::getVar('badge', array(), 'post', 'array', JREQUEST_ALLOWHTML); if (isset($badge['published']) && $badge['published']) { // Get courses config $cconfig = Component::params('com_courses'); // Save the basic badge content $badge['section_id'] = $model->get('id'); $badgeObj = new \Components\Courses\Models\Section\Badge($badge['id']); $badgeObj->bind($badge); $badgeObj->store(); // See if we have an image coming in as well $badge_image = Request::getVar('badge_image', false, 'files', 'array'); // If so, proceed with saving the image if (isset($badge_image['name']) && $badge_image['name']) { // Get the file extension $pathinfo = pathinfo($badge_image['name']); $filename = $pathinfo['filename']; $ext = $pathinfo['extension']; // Check for square and at least 420 x 420 $dimensions = getimagesize($badge_image['tmp_name']); if ($dimensions[0] != $dimensions[1]) { $this->setError(Lang::txt('COM_COURSES_ERROR_IMG_MUST_BE_SQUARE')); } else { if ($dimensions[0] < 450) { $this->setError(Lang::txt('COM_COURSES_ERROR_IMG_MIN_WIDTH')); } else { // Build the upload path if it doesn't exist $uploadDirectory = PATH_APP . DS . trim($cconfig->get('uploadpath', '/site/courses'), DS); $uploadDirectory .= DS . 'badges' . DS . $badgeObj->get('id') . DS; // Make sure upload directory exists and is writable if (!is_dir($uploadDirectory)) { if (!\Filesystem::makeDirectory($uploadDirectory)) { $this->setError(Lang::txt('COM_COURSES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH')); } } if (!is_writable($uploadDirectory)) { $this->setError(Lang::txt('COM_COURSES_ERROR_UPLOAD_DIRECTORY_IS_NOT_WRITABLE')); } // Get the final file path $target_path = $uploadDirectory . 'badge.' . $ext; if (!($move = move_uploaded_file($badge_image['tmp_name'], $target_path))) { $this->setError(Lang::txt('COM_COURSES_ERROR_FILE_MOVE_FAILED')); } else { // Move successful, save the image url to the badge entry $img_url = DS . 'courses' . DS . 'badge' . DS . $badgeObj->get('id') . DS . 'image'; $badgeObj->bind(array('img_url' => $img_url)); $badgeObj->store(); } } } } // Process criteria text if (strcmp($badgeObj->get('criteria_text'), $badge['criteria'])) { $badgeObj->set('criteria_text_new', $badge['criteria']); $badgeObj->store(); $badgeObj->set('criteria_text_new', NULL); } // If we don't already have a provider badge id set, then we're processing our initial badge creation if ($badgeObj->get('provider_name') && !$badgeObj->get('provider_badge_id') && $badgeObj->get('img_url')) { $request_type = $cconfig->get('badges_request_type', 'oauth'); $badgesHandler = new \Hubzero\Badges\Wallet(strtoupper($badgeObj->get('provider_name')), $request_type); $badgesProvider = $badgesHandler->getProvider(); if (is_object($badgesProvider)) { $credentials = new stdClass(); $credentials->consumer_key = $cconfig->get($badgeObj->get('provider_name') . '_consumer_key', 0); $credentials->consumer_secret = $cconfig->get($badgeObj->get('provider_name') . '_consumer_secret', 0); $credentials->issuerId = $cconfig->get($badgeObj->get('provider_name') . '_issuer_id'); $badgesProvider->setCredentials($credentials); $offering = \Components\Courses\Models\Offering::getInstance($model->get('offering_id')); $course = \Components\Courses\Models\Course::getInstance($offering->get('course_id')); $data = array(); $data['Name'] = $course->get('title'); $data['Description'] = trim($course->get('title')) . ' Badge'; $data['CriteriaUrl'] = rtrim(Request::root(), '/') . '/courses/badge/' . $badgeObj->get('id') . '/criteria'; $data['Version'] = '1'; $data['BadgeImageUrl'] = rtrim(Request::root(), '/') . '/' . trim($badgeObj->get('img_url'), '/'); if (!$credentials->consumer_key || !$credentials->consumer_secret) { $this->setError(Lang::txt('COM_COURSES_ERROR_BADGE_MISSING_OPTIONS')); } else { try { $provider_badge_id = $badgesProvider->createBadge($data); } catch (Exception $e) { $this->setError($e->getMessage()); } if (isset($provider_badge_id) && $provider_badge_id) { // We've successfully created a badge, so save that id to the database $badgeObj->bind(array('provider_badge_id' => $provider_badge_id)); $badgeObj->store(); } else { $this->setError(Lang::txt('COM_COURSES_ERROR_FAILED_TO_SAVE_BADGE')); } } } } } elseif ($badge['id']) { $badgeObj = new \Components\Courses\Models\Section\Badge($badge['id']); $badgeObj->bind(array('published' => 0)); $badgeObj->store(); } if ($this->getError()) { $this->setError(implode('<br />', $this->getErrors())); $this->editTask($model); return; } if ($this->_task == 'apply') { return $this->editTask($model); } // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . $model->get('offering_id'), false), Lang::txt('COM_COURSES_ITEM_SAVED')); }
/** * Final submission * * @return void */ public function submitTask() { // Incoming $id = Request::getInt('id', 0); // Ensure we have an ID to work with if (!$id) { App::abort(404, Lang::txt('COM_CONTRIBUTE_NO_ID')); } // Load resource info $resource = Resource::oneOrFail($id); // Set a flag for if the resource was already published or not $published = 0; if ($resource->get('published') != 2) { $published = 1; } // Check if a newly submitted resource was authorized to be published $authorized = Request::getInt('authorization', 0); if (!$authorized && !$published) { $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_NOT_AUTHORIZED')); $this->_checkProgress($id); return $this->step_review(); } // Allow for any other validation $results = Event::trigger('resources.onResourceBeforeSubmit', array($resource)); foreach ($results as $result) { if ($result) { $this->setError($result); $this->_checkProgress($id); return $this->step_review(); } } // Is this a newly submitted resource? if (!$published) { $activity = 'submitted'; // 0 = unpublished, 1 = published, 2 = composing, 3 = pending (submitted), 4 = deleted // Are submissions auto-approved? if ($this->config->get('autoapprove') == 1) { //checks if autoapproved content has children (configurable in options on backend) if ($this->config->get('autoapprove_content_check') == 1) { if ($resource->children()->total() < 1) { $this->setError(Lang::txt('COM_CONTRIBUTE_NO_CONTENT')); return $this->step_review(); } } // Set status to published $resource->set('published', 1); $resource->set('publish_up', Date::toSql()); $activity = 'published'; } else { $apu = $this->config->get('autoapproved_users'); $apu = explode(',', $apu); $apu = array_map('trim', $apu); if (in_array(User::get('username'), $apu)) { // Set status to published $resource->set('published', 1); $resource->set('publish_up', Date::toSql()); } else { // Set status to pending review (submitted) $resource->set('published', 3); } } // Get the resource's contributors $authors = $resource->authors()->rows(); if ($authors->count() <= 0) { $this->setError(Lang::txt('COM_CONTRIBUTE_CONTRIBUTION_HAS_NO_AUTHORS')); $this->_checkProgress($id); return $this->step_review(); } // Get any set emails that should be notified of ticket submission $defs = explode(',', $this->config->get('email_when_submitted', '{config.mailfrom}')); if (!empty($defs)) { $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_RESOURCES_EMAIL_SUBJECT_NEW_SUBMISSION', $resource->id)); $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option))); // Plain text email $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'submitted_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->resource = $resource; $eview->delimiter = ''; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); $message->addPart($plain, 'text/plain'); // HTML email $eview->setLayout('submitted_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); $message->addPart($html, 'text/html'); // Loop through the addresses foreach ($defs as $def) { $def = trim($def); // Check if the address should come from config if ($def == '{config.mailfrom}') { $def = Config::get('mailfrom'); } // Check for a valid address if (\Hubzero\Utility\Validate::email($def)) { // Send e-mail $message->setTo(array($def)); $message->send(); } } } // Log activity $recipients = array(['resource', $resource->get('id')], ['user', $resource->get('created_by')]); foreach ($authors as $author) { if ($author->get('authorid') > 0) { $recipients[] = ['user', $author->get('authorid')]; } } Event::trigger('system.logActivity', ['activity' => ['action' => $activity, 'scope' => 'resource', 'scope_id' => $resource->get('title'), 'description' => Lang::txt('COM_RESOURCES_ACTIVITY_ENTRY_' . strtoupper($activity), '<a href="' . Route::url($resource->link()) . '">' . $resource->get('title') . '</a>'), 'details' => array('title' => $resource->get('title'), 'url' => Route::url($resource->link()))], 'recipients' => $recipients]); } // Is this resource licensed under Creative Commons? if ($this->config->get('cc_license')) { $license = Request::getVar('license', ''); if ($license == 'custom') { $license .= $resource->get('id'); $licenseText = Request::getVar('license-text', ''); if ($licenseText == '[ENTER LICENSE HERE]') { $this->setError(Lang::txt('Please enter a license.')); $this->_checkProgress($id); return $this->step_review(); } $rl = License::oneOrNew($license); $rl->set('name', $license); $rl->set('text', $licenseText); $rl->set('info', $resource->get('id')); $rl->save(); } // set license $params = new \Hubzero\Config\Registry($resource->get('params')); $params->set('license', $license); $resource->set('params', $params->toString()); } // Save the resource $resource->save(); Event::trigger('resources.onResourceAfterSubmit', array($resource)); // If a previously published resource, redirect to the resource page if ($published == 1) { App::redirect(Route::url($resource->link())); return; } // Output HTML $this->setView($this->_controller, 'thanks'); $this->view->set('title', $this->_title)->set('config', $this->config)->set('resource', $resource)->setErrors($this->getErrors())->display(); }
/** * Actions to perform after saving a course * * @param object $model \Components\Courses\Models\Course * @param boolean $isNew Is this a newly created entry? * @return void */ public function onOfferingSave($model) { if (!$model->exists()) { return; } $params = new \Hubzero\Config\Registry($model->get('params')); if ($params->get('store_product', 0)) { $course = \Components\Courses\Models\Course::getInstance($model->get('course_id')); $title = $course->get('title') . ' (' . $model->get('title') . ')'; $description = $course->get('blurb'); $price = $params->get('store_price', '30.00'); $duration = $params->get('store_membership_duration', '1 YEAR'); if (!$params->get('store_product_id', 0)) { include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Course.php'; $product = new StorefrontModelCourse(); $product->setName($title); $product->setDescription($description); $product->setPrice($price); // We don't want products showing up for non-published courses if ($model->get('state') != 1) { $product->setActiveStatus(0); } else { $product->setActiveStatus(1); } // Membership model: membership duration period (must me in MySQL date format: 1 DAY, 2 MONTH, 3 YEAR...) $product->setTimeToLive($duration); // Course alias id $product->setCourseId($course->get('alias')); $product->setOfferingId($model->get('alias')); try { // Returns object with values, pId is the new product ID to link to $info = $product->add(); $params->set('store_product_id', $info->pId); $model->set('params', $params->toString()); $model->store(); } catch (Exception $e) { $this->setError('ERROR: ' . $e->getMessage()); } } else { $warehouse = new StorefrontModelWarehouse(); try { // Get course by pID returned with $course->add() above $product = $warehouse->getCourse($params->get('store_product_id', 0)); $product->setName($title); $product->setDescription($description); $product->setPrice($price); $product->setTimeToLive($duration); if ($model->get('state') != 1) { $product->setActiveStatus(0); } else { $product->setActiveStatus(1); } $product->update(); } catch (Exception $e) { $this->setError('ERROR: ' . $e->getMessage()); } } } }
/** * Subscribe * * @return void */ private function _save() { // Check for request forgeries Request::checkToken(); // Login required if (User::isGuest() || !$this->project->exists()) { App::redirect(Route::url($this->project->link())); } // Incoming $email = User::get('email'); $categories = Request::getVar('category', array()); $frequency = Request::getWord('frequency', 'immediate'); // Save subscription $watch = \Hubzero\Item\Watch::oneByScope($this->project->get('id'), 'project', User::get('id'), $email); $watch->set('item_id', $this->project->get('id')); $watch->set('item_type', 'project'); $watch->set('created_by', User::get('id')); $watch->set('state', empty($categories) ? 2 : 1); $cats = array('blog' => 0, 'quote' => 0, 'team' => 0, 'files' => 0, 'publications' => 0, 'todo' => 0, 'notes' => 0); $params = new \Hubzero\Config\Registry($watch->get('params', '')); $params->set('frequency', $frequency); foreach ($cats as $param => $value) { if (isset($categories[$param])) { $value = intval($categories[$param]); } if ($param == 'quote' && isset($categories['blog'])) { $value = 1; } $params->set($param, $value); } $watch->set('params', $params->toString()); $watch->save(); if ($err = $watch->getError()) { Notify::error($err); } else { Notify::message(Lang::txt('PLG_PROJECTS_WATCH_SUCCESS_SAVED'), 'success', 'projects'); } App::redirect(Route::url($this->project->link())); }