foreach ($children as $child) { if ($child->access == 0 || $child->access == 1 && !User::isGuest() || $child->access == 3 && in_array($this->model->resource->group_owner, $usersgroups)) { $i++; $ftype = Filesystem::extension($child->path); if (substr($child->path, 0, 4) == 'http') { $ftype = 'html'; } $class = ''; $action = ''; if ($child->standalone == 1) { $liclass = ' class="html"'; $title = stripslashes($child->title); } else { $rt = \Components\Resources\Tables\Type::getRecordInstance($child->type); $tparams = new \Hubzero\Config\Registry($rt->params); $lt = \Components\Resources\Tables\Type::getRecordInstance($child->logicaltype); $ltparams = new \Hubzero\Config\Registry($lt->params); // Check the link action by child's type if ($child->logicaltype) { $rtLinkAction = $ltparams->get('linkAction', 'extension'); } else { $rtLinkAction = $tparams->get('linkAction', 'extension'); } switch ($rtLinkAction) { case 'download': $class = 'download'; $linkAction = 3; break; case 'lightbox': $class = 'play'; $linkAction = 2;
/** * Display the primary child * For most resources, this will be the first child of a standalone resource * Tools are the only exception in which case the button launches a tool session * * @param string $option Component name * @param object $resource Resource * @param object $firstChild First resource child * @param string $xact Extra parameters to add * @return string */ public static function primary_child($option, $resource, $firstChild, $xact = '') { $database = \App::get('db'); $html = ''; switch ($resource->type) { case 7: $authorized = User::authorise('core.manage', 'com_tools.' . $resource->id); $mconfig = Component::params('com_tools'); // Ensure we have a connection to the middleware if (!$mconfig->get('mw_on') || $mconfig->get('mw_on') > 1 && !$authorized) { $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_SESSION_INVOKE_DISABLED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); return $html; } //get tool params $params = Component::params('com_tools'); $launchOnIpad = $params->get('launch_ipad', 0); // Generate the URL that launches a tool session $lurl = ''; $database = \App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'tool_version'; if (in_array($table, $tables)) { if (isset($resource->revision) && $resource->toolpublished) { $sess = $resource->tool ? $resource->tool : $resource->alias . '_r' . $resource->revision; $v = (!isset($resource->revision) or $resource->revision == 'dev') ? 'test' : $resource->revision; $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=' . $v; } elseif (!isset($resource->revision) or $resource->revision == 'dev') { // serve dev version $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=dev'; } } else { $lurl = 'index.php?option=com_tools&task=invoke&app=' . $resource->alias; } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; // Create some tool objects $hztv = \Components\Tools\Models\Version::getInstance($resource->tool); $ht = \Components\Tools\Models\Tool::getInstance($hztv->toolid); if ($ht) { // @FIXME: this only seems to fail on hubbub VMs where workspace resource is incomplete/incorrect (bad data in DB?) $toolgroups = $ht->getToolGroupsRestriction($hztv->toolid, $resource->tool); } // Get current users groups $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members'); $ingroup = false; $groups = array(); if ($xgroups) { foreach ($xgroups as $xgroup) { $groups[] = $xgroup->cn; } // Check if they're in the admin tool group $admingroup = Component::params('com_tools')->get('admingroup'); if ($admingroup && in_array($admingroup, $groups)) { $ingroup = true; } else { if ($toolgroups) { foreach ($toolgroups as $toolgroup) { if (in_array($toolgroup->cn, $groups)) { $ingroup = true; } } } } } if (!User::isGuest() && !$ingroup && $toolgroups) { // see if tool is restricted to a group and if current user is in that group $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_IS_RESTRICTED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } else { if (isset($resource->revision) && $resource->toolpublished or !isset($resource->revision)) { // dev or published tool //if (User::isGuest()) { // Not logged-in = show message //$html .= self::primaryButton('launchtool disabled', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL')); //$html .= self::warning('You must <a href="'.Route::url('index.php?option=com_users&view=login').'">log in</a> before you can run this tool.')."\n"; //} else { $pop = User::isGuest() ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN') . '</p>' : ''; $pop = $resource->revision == 'dev' ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT') . '</p>' : $pop; $html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop); //} } else { // tool unpublished $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNPUBLISHED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } } break; case 4: // write primary button and downloads for a Learning Module $html .= self::primaryButton('', Route::url('index.php?option=com_resources&id=' . $resource->id . '&task=play'), 'Start learning module'); break; case 6: case 8: case 31: case 2: // do nothing $mesg = Lang::txt('COM_RESOURCES_VIEW') . ' '; $mesg .= $resource->type == 6 ? 'Course Lectures' : ''; $mesg .= $resource->type == 2 ? 'Workshop ' : ''; $mesg .= $resource->type == 6 ? '' : 'Series'; $html .= self::primaryButton('download', Route::url('index.php?option=com_resources&id=' . $resource->id) . '#series', $mesg, '', $mesg, ''); break; default: $firstChild->title = str_replace('"', '"', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $mesg = ''; $class = ''; $action = ''; $xtra = ''; //$lt = new \Components\Resources\Tables\Type($database); //$lt->load($firstChild->logicaltype); $lt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->logicaltype); $ltparams = new \Hubzero\Config\Registry($lt->params); //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); $rt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->type); $tparams = new \Hubzero\Config\Registry($rt->params); if ($firstChild->logicaltype) { $rtLinkAction = $ltparams->get('linkAction', 'extension'); } else { $rtLinkAction = $tparams->get('linkAction', 'extension'); } switch ($rtLinkAction) { case 'download': $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; //$action = 'rel="download"'; $linkAction = 3; break; case 'lightbox': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; //$action = 'rel="internal"'; $linkAction = 2; break; case 'newwindow': case 'external': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; $linkAction = 1; break; case 'extension': default: $linkAction = 0; $mediatypes = array('elink', 'quicktime', 'presentation', 'presentation_audio', 'breeze', 'quiz', 'player', 'video_stream', 'video', 'hubpresenter'); $downtypes = array('thesis', 'handout', 'manual', 'software_download'); if (in_array($lt->alias, $downtypes)) { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } elseif (in_array($rt->alias, $mediatypes)) { $mesg = Lang::txt('COM_RESOURCES_VIEW_PRESENTATION'); $mediatypes = array('flash_paper', 'breeze', '32', '26'); if (in_array($firstChild->type, $mediatypes)) { $class = 'play'; } } else { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } if ($firstChild->standalone == 1) { $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = ''; //'play'; } if (substr($firstChild->path, 0, 7) == 'http://' || substr($firstChild->path, 0, 8) == 'https://' || substr($firstChild->path, 0, 6) == 'ftp://' || substr($firstChild->path, 0, 9) == 'mainto://' || substr($firstChild->path, 0, 9) == 'gopher://' || substr($firstChild->path, 0, 7) == 'file://' || substr($firstChild->path, 0, 7) == 'news://' || substr($firstChild->path, 0, 7) == 'feed://' || substr($firstChild->path, 0, 6) == 'mms://') { $mesg = Lang::txt('COM_RESOURCES_VIEW_LINK'); } break; } // IF (not a simulator) THEN show the first child as the primary button if ($firstChild->access == 1 && User::isGuest()) { // first child is for registered users only and the visitor is not logged in $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_LOGIN_REQUIRED_TO_DOWNLOAD') . '</p>' . "\n"; $html .= self::primaryButton($class . ' disabled', Route::url('index.php?option=com_users&view=login'), $mesg, '', '', '', '', $pop); } else { $childParams = new \Hubzero\Config\Registry($firstChild->params); $linkAction = intval($childParams->get('link_action', $linkAction)); $url = self::processPath($option, $firstChild, $resource->id, $linkAction); switch ($linkAction) { case 3: $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; break; case 2: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; break; case 1: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; break; case 0: default: // Do nothing break; } $attribs = new \Hubzero\Config\Registry($firstChild->attribs); $width = intval($attribs->get('width', 640)); $height = intval($attribs->get('height', 360)); if ($width > 0 && $height > 0) { $class .= ' ' . $width . 'x' . $height; } //$xtra = ''; //if ($firstChild->type == 13 || $firstChild->type == 15 || $firstChild->type == 33) { //$xtra = ' '. self::getFileAttribs($firstChild->path); //} //load a resouce type object on child resource type //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); //if we are a hubpresenter resource type, do not show file type in button if ($rt->alias == 'hubpresenter') { //$xtra = ""; //$class = "play 1000x600"; $class = 'hubpresenter'; } else { $mesg .= ' ' . self::getFileAttribs($firstChild->path); } if ($rt->alias == 'video') { $class = 'video'; } $pt = \Components\Resources\Tables\Type::getRecordInstance($resource->type); if ($pt->alias == 'databases') { $mesg = "Dataview"; } if ($xact) { $action = $xact; } $html .= self::primaryButton($class, $url, $mesg, $xtra, $firstChild->title, $action); } break; } return $html; }