/** * Generate module contents * * @return void */ public function run() { include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; $database = \App::get('db'); //Get the admin configured settings $filters = array('limit' => 1, 'start' => 0, 'type' => trim($this->params->get('type')), 'sortby' => 'random', 'minranking' => trim($this->params->get('minranking')), 'tag' => trim($this->params->get('tag')), 'access' => 'public', 'toolState' => 7); $row = null; // No - so we need to randomly choose one // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($database); // Get records $rows = $rr->getRecords($filters, false); if (count($rows) > 0) { $row = $rows[0]; } $this->cls = trim($this->params->get('moduleclass_sfx')); $this->txt_length = trim($this->params->get('txt_length')); // Did we get any results? if ($row) { $config = Component::params('com_resources'); // Resource $id = $row->id; include_once Component::path('com_resources') . DS . 'helpers' . DS . 'html.php'; $path = DS . trim($config->get('uploadpath', '/site/resources'), DS); $path = \Components\Resources\Helpers\Html::build_path($row->created, $row->id, $path); if ($row->type == 7) { include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php'; $tv = new \Components\Tools\Tables\Version($database); $versionid = $tv->getVersionIdFromResource($id, 'current'); $picture = $this->getToolImage($path, $versionid); } else { $picture = $this->getImage($path); } $thumb = $path . DS . $picture; if (!is_file(PATH_APP . $thumb)) { $thumb = DS . trim($config->get('defaultpic')); } $row->typetitle = trim(stripslashes($row->typetitle)); if (substr($row->typetitle, -1, 1) == 's' && substr($row->typetitle, -3, 3) != 'ies') { $row->typetitle = substr($row->typetitle, 0, strlen($row->typetitle) - 1); } $this->id = $id; $this->thumb = $thumb; } $this->row = $row; require $this->getLayoutPath(); }
/** * Format an entry * * @param object $row Database row * @param string $tbl Format type * @param number $txtLength Max text length to display * @param integer $getid Just return the ID or not * @return string HTML */ private function _composeEntry($row, $tbl, $txtLength = 100, $getid = 0) { $yearFormat = 'Y'; $monthFormat = 'm'; $out = ''; // Do we have a picture? $thumb = ''; switch ($tbl) { case 'profiles': if ($getid) { return $row->uidNumber; } // Load their bio $profile = \Hubzero\User\Profile::getInstance($row->uidNumber); $title = $row->name; if (!trim($title)) { $title = $row->givenName . ' ' . $row->surname; } $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_members&id=' . $row->uidNumber) . '"><img width="30" height="30" src="' . $profile->getPicture() . '" alt="' . htmlentities($title) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_members&id=' . $row->uidNumber) . '">' . $title . '</a></span>, ' . $row->organization . "\n"; $out .= ' - ' . Lang::txt('Contributions') . ': ' . $this->_countContributions($row->uidNumber) . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; case 'blog': $thumb = trim($this->params->get('default_blogpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $profile = \Hubzero\User\Profile::getInstance($row->created_by); if ($getid) { return $row->id; } if (!$row->title) { $out = ''; } else { $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '">' . $row->title . '</a></span> '; $out .= ' by <a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by) . '">' . $profile->get('name') . '</a> - ' . Lang::txt('in Blogs') . "\n"; $out .= '<div class="clear"></div>' . "\n"; } break; case 'topics': if ($getid) { return $row->id; } $url = $row->group_cn && $row->scope ? 'groups' . DS . $row->scope . DS . $row->pagename : 'topics' . DS . $row->pagename; $thumb = trim($this->params->get('default_topicpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_topics&pagename=' . $row->pagename) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . $url . '">' . stripslashes($row->title) . '</a></span> '; $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_topics') . '">' . Lang::txt('Topics') . '</a>' . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; case 'answers': if ($getid) { return $row->id; } $thumb = trim($this->params->get('default_questionpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $name = Lang::txt('Anonymous'); if ($row->anonymous == 0) { $user = User::getInstance($row->created_by); if (is_object($user)) { $name = $user->get('name'); } } $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->subject)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '">' . stripslashes($row->subject) . '</a></span> '; $out .= ' - ' . Lang::txt('asked by') . ' ' . $name . ', ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_answers') . '">' . Lang::txt('Answers') . '</a>' . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; default: if ($getid) { return $row->id; } if ($tbl == 'itunes') { $thumb = trim($this->params->get('default_itunespic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } } else { $rconfig = Component::params('com_resources'); $path = substr(PATH_APP, strlen(PATH_ROOT)) . DS . trim($rconfig->get('uploadpath', '/site/resources'), DS); $path = DS . trim($path, DS); $path = $this->_buildPath($row->created, $row->id, $path); if ($row->type == 7) { include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php'; $tv = new \Components\Tools\Tables\Version($this->database); $versionid = $tv->getVersionIdFromResource($row->id, 'current'); $picture = $this->_getToolImage($path, $versionid); } else { $picture = $this->_getImage($path); } $thumb = $path . DS . $picture; if (!is_file(PATH_ROOT . $thumb) or !$picture) { $thumb = DS . trim($rconfig->get('defaultpic', '/core/modules/mod_spotlight/assets/img/default.gif'), DS); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } } if (substr($thumb, 0, strlen('/modules')) == '/modules' || substr($thumb, 0, strlen('/components')) == '/components') { $thumb = '/core' . $thumb; } $thumb = str_replace('com_resources/assets', 'com_resources/site/assets', $thumb); } $normalized = preg_replace("/[^a-zA-Z0-9]/", '', strtolower($row->typetitle)); $row->typetitle = trim(stripslashes($row->typetitle)); $row->title = stripslashes($row->title); $chars = strlen($row->title . $row->typetitle); $remaining = $txtLength - $chars; $remaining = $remaining <= 0 ? 0 : $remaining; $titlecut = $remaining ? 0 : $txtLength - strlen($row->typetitle); if ($titlecut) { $title = \Hubzero\Utility\String::truncate($row->title, $titlecut); } else { $title = $row->title; } // resources $out .= '<span class="spotlight-img">'; $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . "\n"; $out .= "\t\t" . '<img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities($row->title) . '" />' . "\n"; $out .= "\t" . '</a>' . "\n"; $out .= '</span>' . "\n"; $out .= '<span class="spotlight-item">' . "\n"; $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . $title . '</a>' . "\n"; $out .= '</span>' . "\n"; if ($row->type == 7 && $remaining > 30) { // Show bit of description for tools if ($row->introtext) { $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->introtext)), $txtLength); } else { $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->fulltxt)), $txtLength); } } if ($tbl == 'itunes') { $out .= ' - ' . Lang::txt('featured on') . ' <a href="/itunes">' . Lang::txt('iTunes') . ' U</a>' . "\n"; } else { $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_resources&type=' . $normalized) . '">' . $row->typetitle . '</a>' . "\n"; } $out .= '<div class="clear"></div>' . "\n"; break; } return $out; }
/** * Update a tool version * * @return void */ public function updateTask() { // 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); } } if (!$this->_error) { $this->_error = Request::getVar('error', ''); } $error = ''; //$id = $this->_toolid; // make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } $newstate = Request::getVar('newstate', ''); $priority = Request::getVar('priority', 3); $comment = Request::getVar('comment', ''); $access = Request::getInt('access', 0); $newversion = Request::getVar('newversion', ''); $editversion = Request::getVar('editversion', 'dev'); $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hztv = $hzt->getRevision($editversion); $oldstatus = $hztv ? $hztv->toArray() : array(); $oldstatus['toolstate'] = $hzt->state; if ($newstate && !intval($newstate)) { $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate); } if (intval($newstate) && $newstate != $oldstatus['toolstate']) { Log::debug(__FUNCTION__ . "() state changing"); if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved') && \Components\Tools\Models\Tool::validateVersion($oldstatus['version'], $error, $hzt->id)) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action confirm"); $this->_action = 'confirm'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved')) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action new"); $this->_action = 'new'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { Log::debug(__FUNCTION__ . "() state changing to published"); $hzt->published = '1'; } } } $this->_error = $error; // update dev screenshots of a published tool changes status if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Published')) { // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); Log::debug(__FUNCTION__ . "() state changing away from published"); // Get version ids $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id); $to = $objV->getVersionIdFromResource($rid, 'dev'); $from = $objV->getVersionIdFromResource($rid, 'current'); $dev_hztv = $hzt->getRevision('dev'); $current_hztv = $hzt->getRevision('current'); Log::debug("update: to={$to} from={$from} dev=" . $dev_hztv->id . " current=" . $current_hztv->id); if ($to && $from) { require_once __DIR__ . DS . 'screenshots.php'; $ss = new Screenshots(); $ss->transfer($from, $to, $rid); } } // If the tool was cancelled ... if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) { include_once __DIR__ . DS . 'resource.php'; $r = new \Components\Resources\Tables\Resource($this->database); $r->loadAlias($hzt->toolname); if ($r && $r->id) { $rstatus = 2; if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { $rstatus = 1; } $resource = new Resource(); $resource->updatePage($r->id, $oldstatus, $rstatus); } } Log::debug(__FUNCTION__ . "() state changing to {$newstate}"); $hzt->state = $newstate; $hzt->state_changed = Date::toSql(); } // if priority changes if (intval($priority) && $priority != $oldstatus['priority']) { $hzt->priority = $priority; } // save tool info $hzt->update(); $hztv->update(); //@FIXME: look // get tool status after updates $status = $hztv->toArray(); $status['toolstate'] = $hzt->state; // update history ticket Log::debug(__FUNCTION__ . "() before newUpdateTicket test"); if ($oldstatus != $status || !empty($comment)) { Log::debug(__FUNCTION__ . "() before newUpdateTicket"); $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, $access, 1); Log::debug(__FUNCTION__ . "() after newUpdateTicket"); } $this->_msg = Lang::txt('COM_TOOLS_NOTICE_STATUS_CHANGED'); $this->statusTask(); }
/** * Display a list of screenshots for this entry * * @param integer $rid Resource ID * @param string $version Tool version * @return void */ public function displayTask($rid = NULL, $version = NULL) { $this->view->setLayout('display'); // Incoming if (!$rid) { $rid = Request::getInt('rid', 0); } if (!$version) { $version = Request::getVar('version', 'dev'); } // Ensure we have an ID to work with if (!$rid) { App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); return; } // Get resource information $resource = new \Components\Resources\Tables\Resource($this->database); $resource->load($rid); // Get version id $objV = new \Components\Tools\Tables\Version($this->database); $vid = $objV->getVersionIdFromResource($rid, $version); // Do we have a published tool? $this->view->published = $objV->getCurrentVersionProperty($resource->alias, 'id'); // Get screenshot information for this resource $ss = new \Components\Resources\Tables\Screenshot($this->database); $this->view->shots = $ss->getScreenshots($rid, $vid); // Build paths include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; $path = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, ''); $this->view->upath = PATH_APP . DS . trim($this->rconfig->get('uploadpath'), DS) . $path; $this->view->wpath = DS . trim($this->rconfig->get('uploadpath'), DS) . $path; if ($vid) { $this->view->upath .= DS . $vid; $this->view->wpath .= DS . $vid; } // Make sure wpath is preceded by app if (substr($this->view->wpath, 0, 4) != DS . 'app') { $this->view->wpath = DS . 'app' . $this->view->wpath; } // get config $this->view->cparams = Component::params('com_resources'); $this->view->version = $version; $this->view->rid = $rid; foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output HTML $this->view->display(); }
/** * Method to get tool information * * @apiMethod GET * @apiUri /tools/{tool} * @apiParameter { * "name": "tool", * "description": "Tool identifier", * "type": "string", * "required": true, * "default": "" * } * @apiParameter { * "name": "version", * "description": "Tool version", * "type": "string", * "required": true, * "default": "current" * } * @return void */ public function infoTask() { $database = \App::get('db'); $tool = Request::getVar('tool', ''); $version = Request::getVar('version', 'current'); //we need a tool to continue if ($tool == '') { throw new Exception(Lang::txt('Tool Alias Required.'), 400); } //poll database for tool matching alias $sql = "SELECT r.id, r.alias, tv.toolname, tv.title, tv.description, tv.toolaccess as access, tv.mw, tv.instance, tv.revision, r.fulltxt as abstract, r.created\n\t\t\t\tFROM #__resources as r, #__tool_version as tv\n\t\t\t\tWHERE r.published=1\n\t\t\t\tAND r.type=7\n\t\t\t\tAND r.standalone=1\n\t\t\t\tAND r.access!=4\n\t\t\t\tAND r.alias=tv.toolname\n\t\t\t\tAND tv.state=1\n\t\t\t\tAND r.alias='{$tool}'\n\t\t\t\tORDER BY revision DESC"; $database->setQuery($sql); $tool_info = $database->loadObject(); //veryify we have result if ($tool_info == null) { throw new Exception(Lang::txt('No Tool Found Matching the Alias: "%s"', $tool), 404); } //add tool alias to tool info from db $tool_info->alias = $tool; //remove tags and slashes from abastract $tool_info->abstract = stripslashes(strip_tags($tool_info->abstract)); //get the supported tag $rconfig = Component::params('com_resources'); $supportedtag = $rconfig->get('supportedtag', ''); //get supportedtag usage include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php'; $this->rt = new \Components\Resources\Helpers\Tags(0); $supportedtagusage = $this->rt->getTagUsage($supportedtag, 'alias'); $tool_info->supported = in_array($tool_info->alias, $supportedtagusage) ? 1 : 0; //get screenshots include_once Component::path('com_resources') . DS . 'tables' . DS . 'screenshot.php'; include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php'; $ts = new \Components\Resources\Tables\Screenshot($database); $tv = new \Components\Tools\Tables\Version($database); $vid = $tv->getVersionIdFromResource($tool_info->id, $version); $shots = $ts->getScreenshots($tool_info->id, $vid); //get base path $path = \Components\Tools\Helpers\Utils::getResourcePath($tool_info->created, $tool_info->id, $vid); //add full path to screenshot $s = array(); foreach ($shots as $shot) { $s[] = $path . DS . $shot->filename; } $tool_info->screenshots = $s; $object = new stdClass(); $object->tool = $tool_info; $this->send($object); }