/** * 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(); }
/** * View a resource * * @return void */ public function viewTask() { // Incoming $id = Request::getInt('id', 0); // Rsource ID (primary method of identifying a resource) $alias = Request::getVar('alias', ''); // Alternate method of identifying a resource $fsize = Request::getVar('fsize', ''); // A parameter to see file size without formatting // XSS fix. Revision gets pumped all over and dumped in URLs via plugins, easier to fix at the input instead of risking missing an output. See ticket 1416 $revision = htmlentities(Request::getVar('rev', '')); // Get svk revision of a tool $tab = Request::getVar('active', 'about'); // The active tab (section) // Ensure we have an ID or alias to work with if (!$id && !$alias) { App::redirect(Route::url('index.php?option=' . $this->_option)); return; } // Load the resource include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'resource.php'; $this->model = Models\Resource::getInstance($alias ? $alias : $id, $revision); // Make sure we got a result from the database if (!$this->model->exists() || $this->model->deleted()) { App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND')); return; } // Make sure the resource is published and standalone if (!$this->model->resource->standalone) { App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } // Is the visitor authorized to view this resource? if (!$this->model->access('view')) { App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } // // Make sure they have access to view this resource //if ($this->checkGroupAccess($this->model->resource)) //{ // App::abort(403, \Lang::txt('COM_RESOURCES_ALERTNOTAUTH_GROUP', $this->model->resource->group_owner, Route::url('index.php?option=com_groups&cn=' . $this->model->resource->group_owner))); // return; //} // Initiate a resource helper class $helper = new Helper($this->model->resource->id, $this->database); // Build the pathway if ($this->model->inGroup()) { // Alter the pathway to reflect a group owned resource $group = \Hubzero\User\Group::getInstance($this->model->resource->group_owner); if ($group) { Pathway::clear(); Pathway::append('Groups', Route::url('index.php?option=com_groups')); Pathway::append(stripslashes($group->get('description')), Route::url('index.php?option=com_groups&cn=' . $this->model->resource->group_owner)); Pathway::append('Resources', Route::url('index.php?option=com_groups&cn=' . $this->model->resource->group_owner . '&active=resources')); Pathway::append(stripslashes($this->model->type->type), Route::url('index.php?option=com_groups&cn=' . $this->model->resource->group_owner . '&active=resources&area=' . $this->model->type->alias)); } else { Pathway::append(stripslashes($this->model->type->type), Route::url('index.php?option=' . $this->_option . '&type=' . $this->model->type->alias)); } } else { Pathway::append(stripslashes($this->model->type->type), Route::url('index.php?option=' . $this->_option . '&type=' . $this->model->type->alias)); } // Tool development version requested if (User::isGuest() && $revision == 'dev') { App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } // Access check for tools if ($this->model->isTool()) { // if (development revision // or (specific revision that is NOT published)) if ($revision == 'dev' or !$revision && $this->model->resource->published != 1) { // Check if the user has access to the tool $objT = new \Components\Tools\Tables\Tool($this->database); $toolid = $objT->getToolId($this->model->resource->alias); if (!$this->_checkToolaccess($toolid)) { // Denied, punk! How do you like them apples?! App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } } } // Whew! Finally passed all the checks // Let's get down to business... // Get contribtool params $tconfig = \Component::params('com_tools'); $sections = array(); $cats = array(); // We need to do this here because we need some stats info to pass to the body if (!isset($this->model->thistool) || !$this->model->thistool) { // Trigger the functions that return the areas we'll be using $cats = Event::trigger('resources.onResourcesAreas', array($this->model)); } elseif (isset($this->model->revision) && $this->model->revision) { $cats = Event::trigger('resources.onResourcesAreas', array($this->model)); $cts = array(); foreach ($cats as $cat) { if (empty($cat)) { $cts[] = $cat; continue; } foreach ($cat as $name => $title) { if ($name == 'about' || $name == 'versions' || $name == 'supportingdocs') { $cts[] = $cat; } } } $cats = $cts; } // Get the sections $sections = Event::trigger('resources.onResources', array($this->model, $this->_option, array($tab), 'all')); $available = array('play'); foreach ($cats as $cat) { $name = key($cat); if ($name != '') { $available[] = $name; } } if ($tab != 'about' && !in_array($tab, $available)) { $tab = 'about'; } // Display different main text if "playing" a resource if ($this->_task == 'play') { $activechild = NULL; if (is_object($this->activechild)) { $activechild = $this->activechild; } $view = new \Hubzero\Component\View(array('base_path' => $this->_base_path, 'name' => 'view', 'layout' => 'play')); $view->option = $this->_option; $view->config = $this->config; $view->tconfig = $tconfig; $view->database = $this->database; $view->resource = $this->model->resource; $view->helper = $helper; $view->resid = $this->resid; $view->activechild = $activechild; $view->no_html = 0; $view->fsize = 0; if ($this->getError()) { foreach ($this->getErrors() as $error) { $view->setError($error); } } $body = $view->loadTemplate(); $cats[] = array('play' => Lang::txt('COM_RESOURCES_PLAY')); $sections[] = array('html' => $body, 'metadata' => '', 'area' => 'play'); $tab = 'play'; } elseif ($this->_task == 'watch') { //test to make sure HUBpresenter is ready to go $pre = $this->preWatch(); //get the errors $errors = $pre['errors']; //get the manifest $manifest = $pre['manifest']; //get the content path $content_folder = $pre['content_folder']; //if we have no errors if (count($errors) > 0) { // Instantiate a new view $this->view = new \Hubzero\Component\View(array('name' => 'view', 'layout' => 'watch_error')); $this->view->errors = $errors; $body = $this->view->loadTemplate(); } else { // Instantiate a new view $view = new \Hubzero\Component\View(array('base_path' => $this->_base_path, 'name' => 'view', 'layout' => 'watch')); $view->config = $this->config; $view->tconfig = $tconfig; $view->database = $this->database; $view->manifest = $manifest; $view->content_folder = $content_folder; $view->pid = $id; $view->resid = Request::getVar('resid', ''); $view->doc = Document::getRoot(); // Output HTML if ($this->getError()) { foreach ($this->getErrors() as $error) { $view->setError($error); } } $body = $view->loadTemplate(); } $cats[] = array('watch' => Lang::txt('Watch Presentation')); $sections[] = array('html' => $body, 'metadata' => '', 'area' => 'watch'); $tab = 'watch'; } // Write title Document::setTitle(Lang::txt(strtoupper($this->_option)) . ': ' . stripslashes($this->model->resource->title)); if ($canonical = $this->model->attribs->get('canonical', '')) { if (!preg_match('/^(https?:|mailto:|ftp:|gopher:|news:|file:|rss:)/i', $canonical)) { $canonical = rtrim(Request::base(), '/') . '/' . ltrim($canonical, '/'); } Document::addHeadLink($canonical, 'canonical'); } Pathway::append(stripslashes($this->model->resource->title), Route::url('index.php?option=' . $this->_option . '&id=' . $this->model->resource->id)); // Normalize the title // This is so we can determine the type of resource template to display // For example, Learning Modules => learningmodules $type_alias = $this->model->type->alias ? $this->model->type->alias : $this->model->type->normalize($this->model->type->type); // Determine the layout we're using $layout = 'default'; if ($type_alias && (is_file(PATH_CORE . DS . 'templates' . DS . App::get('template')->template . DS . 'html' . DS . $this->_option . DS . 'view' . DS . $type_alias . '.php') || is_file(dirname(__DIR__) . DS . 'views' . DS . 'view' . DS . 'tmpl' . DS . $type_alias . '.php'))) { $layout = $type_alias; } // Instantiate a new view $this->view->setLayout($layout); if ($this->model->isTool()) { $this->view->thistool = $this->model->thistool; $this->view->curtool = $this->model->curtool; $this->view->alltools = $this->model->alltools; $this->view->revision = $this->model->revision; } $this->view->model = $this->model; $this->view->tconfig = $tconfig; $this->view->option = $this->_option; $this->view->fsize = $fsize; $this->view->cats = $cats; $this->view->tab = $tab; $this->view->sections = $sections; $this->view->database = $this->database; $this->view->helper = $helper; foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output HTML $this->view->setName('view')->display(); }
/** * Cancel a tool contribution * * @return void */ public function cancelTask() { // get vars if (!$this->_toolid) { $this->_toolid = Request::getInt('toolid', 0); } // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); // do we have an alias? if ($this->_toolid == 0) { if ($alias = Request::getVar('app', '')) { $this->_toolid = $obj->getToolId($alias); } } // check access rights if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } // get tool status $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev'); if (!$status) { App::abort(404, Lang::txt('COM_TOOLS_ERR_EDIT_CANNOT_FIND')); return; } if ($status['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) { App::abort(404, Lang::txt('COM_TOOLS_ERR_ALREADY_CANCELLED')); return; } if ($status['published'] == 1) { App::abort(404, Lang::txt('COM_TOOLS_ERR_CANNOT_CANCEL_PUBLISHED_TOOL')); return; } // unpublish resource page include_once __DIR__ . DS . 'resource.php'; $resource = new Resource(); $resource->updatePage($status['resourceid'], $status, '4'); // change tool status to 'abandoned' and priority to 'lowest' $obj->updateTool($this->_toolid, \Components\Tools\Helpers\Html::getStatusNum('Abandoned'), 5); // add comment to ticket $this->_updateTicket($this->_toolid, '', '', Lang::txt('COM_TOOLS_NOTICE_TOOL_CANCELLED'), 0, 1, 5); // continue output App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=pipeline'), Lang::txt('COM_TOOLS_NOTICE_TOOL_CANCELLED')); }
/** * Publish a tool * * @return void */ public function publishTask() { // 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; } $result = true; Log::debug("publish(): checkpoint 1:{$result}"); // get config // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); $objV->getToolVersions($this->_toolid, $tools, '', 1); // make checks if (!is_numeric($status['revision'])) { // bad format $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_MISSING_REVISION_OR_BAD_FORMAT')); } else { if (count($tools) > 0 && $status['revision']) { // check for duplicate revision foreach ($tools as $t) { if ($t->revision == $status['revision']) { $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_EXISTS') . ' ' . $status['revision']); } } // check that revision number is greater than in previous version $currentrev = $objV->getCurrentVersionProperty($status['toolname'], 'revision'); if ($currentrev && intval($currentrev) > intval($status['revision'])) { $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_GREATER')); } } } // Log checkpoint Log::debug("publish(): checkpoint 2:{$result}, check revision"); // check if version is valid if (!\Components\Tools\Models\Tool::validateVersion($status['version'], $error_v, $this->_toolid)) { $result = false; $this->setError($error_v); } // Log checkpoint Log::debug("publish(): checkpoint 3:{$result}, running finalize tool"); // Run finalizetool if (!$this->getError()) { if ($this->_finalizeTool($out)) { $this->setMessage(Lang::txt('COM_TOOLS_Version finalized.')); } else { $this->setError($out); $result = false; } } Log::debug("publish(): checkpoint 4:{$result}, running doi stuff"); // Register DOI handle if ($result && $this->config->get('new_doi', 0)) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'doi.php'; // Collect metadata $url = Request::base() . ltrim(Route::url('index.php?option=com_resources&id=' . $status['resourceid'] . '&rev=' . $status['revision']), DS); // Check if DOI exists for this revision $objDOI = new \Components\Resources\Tables\Doi($this->database); $bingo = $objDOI->getDoi($status['resourceid'], $status['revision'], '', 1); // DOI already exists for this revision if ($bingo) { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_ALREADY_EXISTS') . ': ' . $bingo); } else { // Get latest DOI label $latestdoi = $objDOI->getLatestDoi($status['resourceid']); $newlabel = $latestdoi ? intval($latestdoi) + 1 : 1; // Collect metadata $metadata = array('targetURL' => $url, 'title' => htmlspecialchars(stripslashes($status['title'])), 'version' => $status['version'], 'abstract' => htmlspecialchars(stripslashes($status['description']))); // Get authors $objA = new \Components\Tools\Tables\Author($this->database); $authors = $objA->getAuthorsDOI($status['resourceid']); // Register DOI $doiSuccess = $objDOI->registerDOI($authors, $this->config, $metadata, $doierr); // Save [new] DOI record if ($doiSuccess) { if (!$objDOI->loadDOI($status['resourceid'], $status['revision'])) { if ($objDOI->saveDOI($status['revision'], $newlabel, $status['resourceid'], $status['toolname'], 0, $doiSuccess)) { $this->setMessage(Lang::txt('COM_TOOLS_SUCCESS_DOI_CREATED') . ' ' . $doiSuccess); } else { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED')); $result = false; } } else { $this->setError(Lang::txt('COM_TOOLS_DOI already exists: ') . $objDOI->doi); } } else { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED')); $this->setError($doierr); $result = false; } } } if ($result) { $invokedir = rtrim($this->config->get('invokescript_dir', DS . 'apps'), "\\/"); $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hztv_cur = $hzt->getCurrentVersion(); $hztv_dev = $hzt->getDevelopmentVersion(); Log::debug("publish(): checkpoint 6:{$result}, running database stuff"); // create tool instance in the database $newtool = $status['toolname'] . '_r' . $status['revision']; // get version id $currentid = is_object($hztv_cur) ? $hztv_cur->id : null; $new = $currentid ? 0 : 1; $devid = $hztv_dev->id; $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@PU' => 'pu', '@D1' => 'd1'); $new_hztv = \Components\Tools\Models\Version::createInstance($status['toolname'], $newtool); $new_hztv->toolname = $status['toolname']; $new_hztv->instance = $newtool; $new_hztv->toolid = $this->_toolid; $new_hztv->state = 1; $new_hztv->title = $status['title']; $new_hztv->version = $status['version']; $new_hztv->revision = $status['revision']; $new_hztv->description = $status['description']; $new_hztv->toolaccess = $status['exec']; $new_hztv->codeaccess = $status['code']; $new_hztv->wikiaccess = $status['wiki']; $new_hztv->vnc_geometry = $status['vncGeometry']; $new_hztv->vnc_command = $invokedir . DS . $status['toolname'] . DS . 'r' . $status['revision'] . DS . 'middleware' . DS . 'invoke -T r' . $status['revision']; $new_hztv->mw = $status['mw']; $new_hztv->released = Date::toSql(); $new_hztv->released_by = User::get('username'); $new_hztv->license = $status['license']; $new_hztv->fulltxt = $status['fulltxt']; $new_hztv->exportControl = $exportmap[strtoupper($status['exec'])]; $new_hztv->owner = $hztv_dev->owner; $new_hztv->member = $hztv_dev->member; $new_hztv->vnc_timeout = $hztv_dev->vnc_timeout; $new_hztv->hostreq = $hztv_dev->hostreq; $new_hztv->params = $status['params']; if (!$new_hztv->update()) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE')); $result = false; } else { $this->_setTracAccess($new_hztv->toolname, $new_hztv->codeaccess, $new_hztv->wikiaccess); // update tool entry $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hzt->add('version', $new_hztv->instance); $hzt->update(); if ($hzt->published != 1) { $hzt->published = 1; // save tool info if (!$hzt->update()) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE')); } else { $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_TOOL_MARKED_PUBLISHED')); } } // unpublish previous version if (!$new) { if ($hzt->unpublishVersion($hztv_cur->instance)) { $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_UNPUBLISHED_PREV_VERSION_DB')); } else { $this->setError(Lang::txt('COM_TOOLS_ERR_FAILED_TO_UNPUBLISH_PREV_VERSION_DB')); } } // get version id $currentid = $new_hztv->id; // save authors for this version $objA = new \Components\Tools\Tables\Author($this->database); if ($objA->saveAuthors($status['developers'], $currentid, $status['resourceid'], $status['revision'], $status['toolname'])) { $this->setMessage(Lang::txt('COM_TOOLS_AUTHORS_SAVED')); } else { $this->setError(Lang::txt('COM_TOOLS_ERROR_SAVING_AUTHORS', $currentid)); } // transfer screenshots if ($devid && $currentid) { include_once __DIR__ . DS . 'screenshots.php'; $screenshots = new Screenshots(); if ($screenshots->transfer($devid, $currentid, $status['resourceid'])) { $this->setMessage(Lang::txt('COM_TOOLS_SCREENSHOTS_TRANSFERRED')); } else { $this->setError(Lang::txt('COM_TOOLS_ERROR_TRANSFERRING_SCREENSHOTS')); } } include_once __DIR__ . DS . 'resource.php'; $resource = new Resource(); // update and publish resource page $resource->updatePage($status['resourceid'], $status, '1', $new); } } Log::debug("publish(): checkpoint 7:{$result}, gather output"); // Set errors to view 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(); }