Example #1
0
 /**
  * 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();
 }
Example #2
0
 /**
  * Reorders a resource child
  * Redirects to parent resource's children listing
  *
  * @return  void
  */
 public function reorderTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $dir = $this->_task == 'orderup' ? -1 : 1;
     // Incoming
     $id = Request::getVar('id', array(0), '', 'array');
     // Load row
     $row = License::oneOrFail((int) $id[0]);
     // Update order
     if (!$row->move($dir)) {
         Notify::error($row->getError());
     }
     $this->cancelTask();
 }