/** * Display a license for a resource * * @return void */ public function licenseTask() { // Get tool instance $resource = Request::getInt('resource', 0); $tool = Request::getVar('tool', ''); // Ensure we have a tool to work with if (!$tool && !$resource) { App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND')); return; } if ($tool) { // Load the tool version $row = new \Components\Tools\Tables\Version($this->database); $row->loadFromInstance($tool); } else { $row = new Resource($this->database); $row->load($resource); include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'license.php'; $rt = new License($this->database); $rt->load('custom' . $resource); $row->license = stripslashes($rt->text); } // Output HTML if (!$row) { App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND')); return; } // Set the page title $this->view->title = stripslashes($row->title) . ': ' . Lang::txt('COM_RESOURCES_LICENSE'); // Write title Document::setTitle($this->view->title); // Instantiate a new view $this->view->config = $this->config; $this->view->row = $row; $this->view->tool = $tool; $this->view->no_html = Request::getVar('no_html', 0); // Output HTML foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setName('license')->setLayout('default')->display(); }
/** * Reorders a resource child * Redirects to parent resource's children listing * * @return void */ public function reorderTask($dir = 0) { // Check for request forgeries Request::checkToken(); $dir = $this->_task == 'orderup' ? -1 : 1; // Incoming $id = Request::getVar('id', array(0), '', 'array'); // Load row $row = new License($this->database); $row->load((int) $id[0]); // Update order $row->move($dir); App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * 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(); }