Example #1
0
 /**
  * Display forms for editing/creating a reosurce
  *
  * @return     void
  */
 public function displayTask()
 {
     // Incoming
     $alias = Request::getVar('app', '');
     $version = Request::getVar('editversion', 'dev');
     $step = Request::getInt('step', 1);
     // Load the tool
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolId($alias);
     if (!$this->_toolid) {
         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;
     }
     $nextstep = $step + 1;
     // get tool version (dev or current) information
     $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
     // get resource information
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->loadAlias($alias);
     $row->alias = $row->alias ? $row->alias : $alias;
     if (!$status['fulltxt']) {
         $status['fulltxt'] = $row->fulltxt;
     }
     // process first step
     if ($nextstep == 3 && (isset($_POST['nbtag']) || isset($_POST['fulltxt']))) {
         if (!isset($_POST['fulltxt']) || !trim($_POST['fulltxt'])) {
             $this->setError(Lang::txt('COM_TOOLS_REQUIRED_FIELD_CHECK', 'Abstract'));
             $step = 1;
             $nextstep--;
         }
         $hztv = \Components\Tools\Helpers\Version::getToolRevision($this->_toolid, $version);
         $objV = new \Components\Tools\Tables\Version($this->database);
         if (!$objV->bind($_POST)) {
             $this->setError($objV->getError());
             return;
         }
         $body = $this->txtClean($_POST['fulltxt']);
         if (preg_match("/([\\<])([^\\>]{1,})*([\\>])/i", $body)) {
             // Do nothing
             $status['fulltxt'] = trim(stripslashes($body));
         } else {
             // Wiki format will be used
             $status['fulltxt'] = Request::getVar('fulltxt', $status['fulltxt'], 'post');
         }
         // Get custom areas, add wrapper tags, and compile into fulltxt
         $type = new \Components\Resources\Tables\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 = Request::getVar('nbtag', array());
         $found = array();
         foreach ($nbtag as $tagname => $tagcontent) {
             $f = '';
             $status['fulltxt'] .= "\n" . '<nb:' . $tagname . '>';
             if (is_array($tagcontent)) {
                 $c = count($tagcontent);
                 $num = 0;
                 foreach ($tagcontent as $key => $val) {
                     if (trim($val)) {
                         $num++;
                     }
                     $status['fulltxt'] .= '<' . $key . '>' . trim($val) . '</' . $key . '>';
                 }
                 if ($c == $num) {
                     $f = 'found';
                 }
             } else {
                 $f = trim($tagcontent);
                 if ($f) {
                     $status['fulltxt'] .= trim($tagcontent);
                 }
             }
             $status['fulltxt'] .= '</nb:' . $tagname . '>' . "\n";
             if (!$f && isset($fields[$tagname]) && $fields[$tagname]->required) {
                 $this->setError(Lang::txt('COM_TOOLS_REQUIRED_FIELD_CHECK', $fields[$tagname]->label));
             }
             $found[] = $tagname;
         }
         foreach ($fields as $field) {
             if (!in_array($field->name, $found) && $field->required) {
                 $found[] = $field->name;
                 $this->setError(Lang::txt('COM_TOOLS_REQUIRED_FIELD_CHECK', $field->label));
             }
         }
         $hztv->fulltxt = $objV->fulltxt = $status['fulltxt'];
         $hztv->description = $objV->description = \Hubzero\Utility\String::truncate(Request::getVar('description', $status['description'], 'post'), 500);
         $hztv->title = $objV->title = \Hubzero\Utility\String::truncate(preg_replace('/\\s+/', ' ', Request::getVar('title', $status['title'], 'post')), 500);
         if (!$hztv->update()) {
             throw new Exception(Lang::txt('COM_TOOLS_ERROR_UPDATING_TOOL'), 500);
         } else {
             // get updated tool status
             $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
         }
         if ($version == 'dev') {
             // update resource page
             $this->updatePage($row->id, $status);
         }
     }
     // Group access
     //$accesses = array('Public', 'Registered', 'Special', 'Protected', 'Private');
     //$lists = array();
     //$lists['access'] = \Components\Tools\Helpers\Html::selectAccess($accesses, $row->access);
     //$groups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
     // get authors
     $objA = new \Components\Tools\Tables\Author($this->database);
     $authors = $version == 'current' ? $objA->getToolAuthors($version, $row->id, $status['toolname']) : array();
     // Tags
     $tags = Request::getVar('tags', '', 'post');
     $tagfa = Request::getVar('tagfa', '', 'post');
     // Get any HUB focus areas
     // These are used where any resource is required to have one of these tags
     $tconfig = Component::params('com_tags');
     $fa1 = $tconfig->get('focus_area_01');
     $fa2 = $tconfig->get('focus_area_02');
     $fa3 = $tconfig->get('focus_area_03');
     $fa4 = $tconfig->get('focus_area_04');
     $fa5 = $tconfig->get('focus_area_05');
     $fa6 = $tconfig->get('focus_area_06');
     $fa7 = $tconfig->get('focus_area_07');
     $fa8 = $tconfig->get('focus_area_08');
     $fa9 = $tconfig->get('focus_area_09');
     $fa10 = $tconfig->get('focus_area_10');
     // Instantiate our tag object
     $tagcloud = new \Components\Resources\Helpers\Tags($row->id);
     // Normalize the focus areas
     $tagfa1 = $tagcloud->normalize($fa1);
     $tagfa2 = $tagcloud->normalize($fa2);
     $tagfa3 = $tagcloud->normalize($fa3);
     $tagfa4 = $tagcloud->normalize($fa4);
     $tagfa5 = $tagcloud->normalize($fa5);
     $tagfa6 = $tagcloud->normalize($fa6);
     $tagfa7 = $tagcloud->normalize($fa7);
     $tagfa8 = $tagcloud->normalize($fa8);
     $tagfa9 = $tagcloud->normalize($fa9);
     $tagfa10 = $tagcloud->normalize($fa10);
     // process new tags
     if ($tags or $tagfa) {
         $newtags = '';
         if ($tagfa) {
             $newtags = $tagfa . ', ';
         }
         if ($tags) {
             $newtags .= $tags;
         }
         $tagcloud->setTags($newtags, User::get('id'));
     }
     // Get all the tags on this resource
     $tags_men = $tagcloud->tags();
     $mytagarray = array();
     $fas = array($tagfa1, $tagfa2, $tagfa3, $tagfa4, $tagfa5, $tagfa6, $tagfa7, $tagfa8, $tagfa9, $tagfa10);
     $fats = array();
     if ($fa1) {
         $fats[$fa1] = $tagfa1;
     }
     if ($fa2) {
         $fats[$fa2] = $tagfa2;
     }
     if ($fa3) {
         $fats[$fa3] = $tagfa3;
     }
     if ($fa4) {
         $fats[$fa4] = $tagfa4;
     }
     if ($fa5) {
         $fats[$fa5] = $tagfa5;
     }
     if ($fa6) {
         $fats[$fa6] = $tagfa6;
     }
     if ($fa7) {
         $fats[$fa7] = $tagfa7;
     }
     if ($fa8) {
         $fats[$fa8] = $tagfa8;
     }
     if ($fa9) {
         $fats[$fa9] = $tagfa9;
     }
     if ($fa10) {
         $fats[$fa10] = $tagfa10;
     }
     // Loop through all the tags and pull out the focus areas - those will be displayed differently
     foreach ($tags_men as $tag_men) {
         if (in_array($tag_men->get('tag'), $fas)) {
             $tagfa = $tag_men->get('tag');
         } else {
             $mytagarray[] = $tag_men->get('raw_tag');
         }
     }
     $tags = implode(', ', $mytagarray);
     // Set the document title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE') . ' (' . $status['toolname'] . ')';
     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', $status['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->row = $row;
     $this->view->step = $step;
     $this->view->version = $version;
     $this->view->status = $status;
     $this->view->tags = $tags;
     $this->view->tagfa = $tagfa;
     $this->view->fats = $fats;
     $this->view->authors = $authors;
     // Pass error messages to the view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
Example #2
0
 /**
  * Short description for 'getRevision'
  *
  * Long description (if any) ...
  *
  * @param	  string $revision Parameter description (if any) ...
  * @return	 string Return description (if any) ...
  */
 public function getRevision($revision = 'dev')
 {
     return Helpers\Version::getToolRevision($this->id, $revision);
 }
Example #3
0
 /**
  * Apply a license
  *
  * @return     void
  */
 public function savelicenseTask()
 {
     $id = Request::getInt('toolid', 0, 'post');
     $error = '';
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller));
     }
     $hztv = \Components\Tools\Helpers\Version::getDevelopmentToolVersion($id);
     $this->license_choice = array('text' => Request::getVar('license', ''), 'template' => Request::getVar('templates', 'c1'), 'authorize' => Request::getInt('authorize', 0));
     $hztv->codeaccess = Request::getVar('t_code', '@OPEN');
     $action = Request::getWord('action', 'dev');
     // Closed source
     if ($hztv->codeaccess == '@DEV') {
         $reason = Request::getVar('reason', '');
         if (!$reason) {
             $this->view->license_choice = $this->license_choice;
             $this->view->code = $hztv->codeaccess;
             // display license page with error
             $this->setError(Lang::txt('COM_TOOLS_LICENSE_CLOSED_SOURCE_NEED_REASON'));
             $this->licenseTask();
             return;
         } else {
             $path = DS . 'site/protected';
             if (is_dir(PATH_APP . $path)) {
                 $log = 'By: ' . User::get('name') . ' (' . User::get('username') . ') ' . "\n";
                 $log .= 'Tool: ' . $hztv->toolname . ' (id #' . $id . ')' . ' - ' . $hztv->instance . "\n";
                 $log .= 'Time : ' . date('c') . "\n";
                 $log .= 'Reason for closed source: ' . "\n";
                 $log .= $reason . "\n";
                 $log .= '-----------------------------------------' . "\n";
                 // Log reason for closed source
                 $this->_writeToFile($log, PATH_APP . $path . DS . 'closed_source_reasons.txt', true);
             }
             // code for saving license
             $hztv->license = NULL;
             // save version info
             $hztv->update();
             //@FIXME: look
             $this->_setTracAccess($hztv->toolname, $hztv->codeaccess, null);
             if ($action != 'confirm') {
                 $this->_msg = Lang::txt('COM_TOOLS_NOTICE_CHANGE_LICENSE_SAVED');
                 $this->statusTask();
             } else {
                 $this->finalizeTask();
             }
             return;
         }
     }
     // Open source
     if (\Components\Tools\Models\Tool::validateLicense($this->license_choice, $hztv->codeaccess, $error)) {
         // code for saving license
         $hztv->license = strip_tags($this->license_choice['text']);
         // save version info
         $hztv->update();
         //@FIXME: look
         $this->_setTracAccess($hztv->toolname, $hztv->codeaccess, null);
         if ($action != 'confirm') {
             $this->_msg = Lang::txt('COM_TOOLS_NOTICE_CHANGE_LICENSE_SAVED');
             $this->statusTask();
         } else {
             $this->finalizeTask();
         }
     } else {
         $this->view->code = $hztv->codeaccess;
         $this->view->license_choice = $this->license_choice;
         // display license page with error
         $this->setError($error);
         $this->licenseTask();
     }
 }
Example #4
0
 /**
  * Install the tool
  *
  * @return     void
  */
 public function installTask()
 {
     // Set the layout (note: all the views for this controller use the same layout)
     $this->view->setLayout('display');
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     // Do we have an alias?
     if ($alias = Request::getVar('app', '')) {
         $this->_toolid = $obj->getToolId($alias);
     }
     // Do we have a tool ID
     if (!$this->_toolid) {
         App::abort(403, Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND'));
         return;
     }
     // Get the tool status
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     // Check for a status
     if (count($status) <= 0) {
         App::abort(500, Lang::txt('COM_TOOLS_ERR_CANNOT_RETRIEVE'));
         return;
     }
     // Github connection?
     if ($status['github']) {
         $command = '/usr/bin/sudo -u apps ' . PATH_CORE . '/components/com_tools/scripts/git2svn.sh -g ' . $status['github'] . ' -s ' . $status['toolname'] . ' -c ' . PATH_CORE . '/..';
         if (!$this->_invokeScript($command, Lang::txt('Github repository connection successful'))) {
             $this->setError(Lang::txt('Github connection error'));
         }
     }
     // Build the exec command
     $command = '/usr/bin/sudo -u apps /usr/bin/installtool -type raw -hubdir ' . PATH_CORE . '/../ ' . $status['toolname'];
     error_log($command);
     // Invoke the script
     if (!$this->getError() && $this->_invokeScript($command, Lang::txt('COM_TOOLS_NOTICE_REV_INSTALLED'))) {
         // Extract revision number
         $rev = explode('installed revision: ', $this->getMessage());
         if (!isset($rev[1]) || !intval($rev[1])) {
             $this->setError(Lang::txt('COM_TOOLS_ERR_CANNOT_SAVE_REVISION_INFO'));
         } else {
             // Update the revision number
             $hztv = \Components\Tools\Helpers\Version::getDevelopmentToolVersion($this->_toolid);
             $hztv->revision = intval($rev[1]);
             if (!$hztv->update()) {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_SAVING_REVISION_UPDATE'));
             }
         }
     }
     // Set errors to view
     if ($this->getError()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
     }
     // Set messages to view
     $this->view->messages = $this->getMessages();
     // Output HTML
     if (!($no_html = Request::getInt('no_html', 0))) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias));
         return;
     }
     $this->view->display();
 }