Ejemplo n.º 1
0
 /**
  * Preview the resource
  *
  * @return     void
  */
 public function previewTask()
 {
     // Incoming
     $alias = Request::getVar('app', '');
     $version = Request::getVar('editversion', 'dev');
     $rid = Request::getInt('rid', 0);
     // Load the tool
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolId($alias);
     if (!$this->_toolid) {
         // not a tool resource page
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline'));
         return;
     }
     // Make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Get tool version (dev or current) information
     $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
     // Instantiate our tag object
     $tagcloud = new \Components\Resources\Helpers\Tags($rid);
     $tags = Request::getVar('tags', '', 'post');
     $tagfa = Request::getVar('tagfa', '', 'post');
     // Process new tags
     $newtags = '';
     if ($tagfa) {
         $newtags = $tagfa . ', ';
     }
     if ($tags) {
         $newtags .= $tags;
     }
     $tagcloud->setTags($newtags, User::get('id'));
     // Get some needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     // Load the resource object
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->loadAlias($alias);
     if (!User::isGuest()) {
         $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
         // Get the groups the user has access to
         $usersgroups = $this->_getUsersGroups($xgroups);
     } else {
         $usersgroups = array();
     }
     // Get updated version
     $objV = new \Components\Tools\Tables\Version($this->database);
     $thistool = $objV->getVersionInfo('', $version, $resource->alias, '');
     $thistool = $thistool ? $thistool[0] : '';
     // Replace resource info with requested version
     $objV->compileResource($thistool, '', $resource, 'dev', $this->rconfig);
     // get language library
     $lang = Lang::getRoot();
     if (!$lang->load(strtolower('com_resources'), JPATH_BASE)) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_LOADING_LANGUAGE'));
     }
     // Set the document title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_PREVIEW_TOOL_PAGE') . ' (' . $resource->alias . ')';
     Document::setTitle($this->view->title);
     // Set the document pathway (breadcrumbs)
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
     }
     if (Pathway::count() <= 1) {
         Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $thistool->toolname), 'index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias);
         Pathway::append(Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&app=' . $alias . '&task=start&step=1');
     }
     $this->view->toolid = $this->_toolid;
     $this->view->step = 5;
     $this->view->version = $version;
     $this->view->resource = $resource;
     $this->view->config = $this->rconfig;
     $this->view->usersgroups = $usersgroups;
     $this->view->status = $status;
     // Pass error messages to the view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
Ejemplo n.º 2
0
 /**
  * Save a review
  *
  * @return     void
  */
 public function savereview()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $resource_id = Request::getInt('resource_id', 0);
     // Do we have a resource ID?
     if (!$resource_id) {
         // No ID - fail! Can't do anything else without an ID
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $database = App::get('db');
     // Bind the form data to our object
     $row = new \Components\Resources\Tables\Review($database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         return;
     }
     // Perform some text cleaning, etc.
     $row->id = Request::getInt('reviewid', 0);
     if (!$row->id) {
         $row->state = 1;
     }
     $row->comment = \Hubzero\Utility\Sanitize::stripImages(\Hubzero\Utility\Sanitize::clean($row->comment));
     $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0;
     $row->created = $row->created && $row->created != '0000-00-00 00:00:00' ? $row->created : Date::toSql();
     // Check for missing (required) fields
     if (!$row->check()) {
         $this->setError($row->getError());
         return;
     }
     // Save the data
     if (!$row->store()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent resource
     $resource =& $this->resource;
     $resource->calculateRating();
     $resource->updateRating();
     // Process tags
     $tags = trim(Request::getVar('review_tags', ''));
     if ($tags) {
         $rt = new \Components\Resources\Helpers\Tags($resource_id);
         $rt->setTags($tags, $row->user_id);
     }
     // Instantiate a helper object and get all the contributor IDs
     $helper = new \Components\Resources\Helpers\Helper($resource->id, $database);
     $helper->getContributorIDs();
     $users = $helper->contributorIDs;
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'resources', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->user = User::getRoot();
     $eview->resource = $resource;
     $eview->review = $row;
     $message = $eview->loadTemplate();
     // Build the "from" data for the e-mail
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS'), 'email' => Config::get('mailfrom'));
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('resources_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_FAILED_TO_MESSAGE'));
     }
 }