/** * Get a list of resource types * Accepts either a numeric array index or a string [id, name] * If index, it'll return the entry matching that index in the list * If string, it'll return either a list of IDs or names * * @param mixed $idx Index value * @return array */ public function types($idx = null) { if (!$this->exists()) { return array(); } if (!isset($this->types)) { $this->types = array(); $rt = new Tables\Type($this->_db); if ($types = $rt->getMajorTypes()) { foreach ($types as $key => $type) { if (!$type->alias) { $types[$key]->alias = $rt->normalize($type->type); } } $this->types = $types; } } if ($idx !== null) { if (is_numeric($idx)) { foreach ($this->types as $type) { if ($type->id == $idx) { return $type; } } } else { if (is_string($idx)) { $idx = trim($idx); foreach ($this->types as $type) { if ($type->alias == $idx) { return $type; } } } } $this->setError(Lang::txt('Index not found: ') . __CLASS__ . '::' . __METHOD__ . '[' . $idx . ']'); return false; } return $this->types; }
/** * Gets the full name of a user from their ID # * * @return string */ public function authorTask() { $this->view->id = Request::getVar('u', ''); $this->view->role = Request::getVar('role', ''); $rid = Request::getInt('rid', 0); // Get the member's info $profile = new \Hubzero\User\Profile(); $profile->load($this->view->id); if (!is_object($profile) || !$profile->get('uidNumber')) { $this->database->setQuery("SELECT id FROM `#__users` WHERE `name`=" . $this->database->Quote($this->view->id)); if ($id = $this->database->loadResult()) { $profile->load($id); } } if (is_object($profile) && $profile->get('uidNumber')) { if (!$profile->get('name')) { $this->view->name = $profile->get('givenName') . ' '; $this->view->name .= $profile->get('middleName') ? $profile->get('middleName') . ' ' : ''; $this->view->name .= $profile->get('surname'); } else { $this->view->name = $profile->get('name'); } $this->view->org = $profile->get('organization'); $this->view->id = $profile->get('uidNumber'); } else { $this->view->name = null; include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor.php'; $rcc = new Contributor($this->database); if (is_numeric($this->view->id)) { $this->database->setQuery("SELECT name, organization FROM `#__author_assoc` WHERE authorid=" . $this->database->Quote($this->view->id) . " LIMIT 1"); $author = $this->database->loadObject(); if (is_object($author) && $author->name) { $this->view->name = $author->name; $this->view->org = $author->organization; } } if (!$this->view->name) { $this->view->org = ''; $this->view->name = str_replace('_', ' ', $this->view->id); $this->view->id = $rcc->getUserId($this->view->name); } } $row = new Resource($this->database); $row->load($rid); $rt = new Type($this->database); $this->view->roles = $rt->getRolesForType($row->type); $this->view->display(); }
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; }
/** * Display an RSS feed * * @return void */ public function feedTask() { Document::setType('feed'); // Start a new feed object $doc = Document::instance(); // Incoming $id = Request::getInt('id', 0); $alias = Request::getVar('alias', ''); // 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 $resource = new Resource($this->database); if ($alias) { $resource->load($alias); $id = $resource->id; } else { $resource->load($id); $alias = $resource->alias; } // Make sure we got a result from the database if (!$resource) { App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND')); return; } // Make sure the resource is published and standalone if ($resource->published == 0 || $resource->standalone != 1) { App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } // Make sure they have access to view this resource if ($this->checkGroupAccess($resource)) { App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH')); return; } // Incoming $filters = array(); if ($resource->type == 2) { $filters['sortby'] = Request::getVar('sortby', 'ordering'); } else { $filters['sortby'] = Request::getVar('sortby', 'ranking'); } $filters['limit'] = Request::getInt('limit', 100); $filters['start'] = Request::getInt('limitstart', 0); $filters['year'] = Request::getInt('year', 0); $filters['id'] = $resource->id; $feedtype = Request::getVar('content', 'audio'); // Initiate a resource helper class $helper = new Helper($resource->id, $this->database); $rows = $helper->getStandaloneChildren($filters); $base = rtrim(Request::base(), '/'); $title = $resource->title; $feedtypes_abr = array(" ", "slides", "audio", "video", "sd_video", "hd_video"); $feedtypes_full = array(" & ", "Slides", "Audio", "Video", "SD full", "HD"); $type = str_replace($feedtypes_abr, $feedtypes_full, $feedtype); $title = '[' . $type . '] ' . $title; // Build some basic RSS document information $dtitle = \Hubzero\Utility\Sanitize::clean(stripslashes($title)); $doc->title = trim(\Hubzero\Utility\String::truncate(html_entity_decode($dtitle), 250)); $doc->description = htmlspecialchars(html_entity_decode(\Hubzero\Utility\Sanitize::clean(stripslashes($resource->introtext))), ENT_COMPAT, 'UTF-8'); $doc->copyright = \Lang::txt('COM_RESOURCES_RSS_COPYRIGHT', date("Y"), Config::get('sitename')); $doc->category = Lang::txt('COM_RESOURCES_RSS_CATEGORY'); $doc->link = Route::url('index.php?option=' . $this->_option . '&id=' . $resource->id); $rt = new Tags($resource->id); $rtags = $rt->tags(); $tagarray = array(); $categories = array(); $subcategories = array(); if ($rtags) { foreach ($rtags as $tag) { if (substr($tag->get('tag'), 0, 6) == 'itunes') { $tbits = explode(':', $tag->get('raw_tag')); if (count($tbits) > 2) { $subcategories[] = end($tbits); } else { $categories[] = str_replace('itunes:', '', $tag->get('raw_tag')); } } elseif ($tag->get('admin') == 0) { $tagarray[] = $tag->get('raw_tag'); } } } $tags = implode(', ', $tagarray); $tags = trim(\Hubzero\Utility\String::truncate($tags, 250)); $tags = rtrim($tags, ','); $helper->getUnlinkedContributors(); $cons = $helper->ul_contributors; $cons = explode(';', $cons); $author = ''; foreach ($cons as $con) { if ($con) { $author = trim($con); break; } } $doc->itunes_summary = html_entity_decode(\Hubzero\Utility\Sanitize::clean(stripslashes($resource->introtext))); if (count($categories) > 0) { $doc->itunes_category = $categories[0]; if (count($subcategories) > 0) { $doc->itunes_subcategories = $subcategories; } } $doc->itunes_explicit = 'no'; $doc->itunes_keywords = $tags; $doc->itunes_author = $author; $itunes_image_name = 'itunes_' . str_replace(' ', '_', strtolower($feedtype)); $dimg = $this->_checkForImage($itunes_image_name, $this->config->get('uploadpath'), $resource->created, $resource->id); if ($dimg) { $dimage = new \Hubzero\Document\Type\Feed\Image(); $dimage->url = $dimg; $dimage->title = trim(\Hubzero\Utility\String::truncate(html_entity_decode($dtitle . ' ' . Lang::txt('COM_RESOURCES_RSS_ARTWORK')), 250)); $dimage->link = $base . $doc->link; $doc->itunes_image = $dimage; } $owner = new \Hubzero\Document\Type\Feed\ItunesOwner(); $owner->email = Config::get('mailfrom'); $owner->name = Config::get('sitename'); $doc->itunes_owner = $owner; // Start outputing results if any found if (count($rows) > 0) { foreach ($rows as $row) { // Prepare the title $title = strip_tags($row->title); $title = html_entity_decode($title); // URL link to resource $link = DS . ltrim(Route::url('index.php?option=' . $this->_option . '&id=' . $row->id), DS); // Strip html from feed item description text $description = html_entity_decode(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->introtext))); $author = ''; @($date = $row->publish_up ? date('r', strtotime($row->publish_up)) : ''); // Instantiate a resource helper $rhelper = new Helper($row->id, $this->database); // Get any podcast/vodcast files $podcast = ''; $type_model = new Type($this->database); $all_logical_types = $type_model->getTypes(28); // 28 means 'logical' types. $queried_logical_types = @explode(' ', $feedtype); if (is_null($queried_logical_types) || !is_array($queried_logical_types)) { App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_FEED_BAD_REQUEST')); return; } $relevant_logical_types_by_id = array(); foreach ($queried_logical_types as $queried) { $as_mnemonic = preg_replace('/[_-]/', ' ', $queried); foreach ($all_logical_types as $logical_type) { if (preg_match_all('/Podcast \\(([^()]+)\\)/', $logical_type->type, $matches) == 1 && strcasecmp($matches[1][0], $as_mnemonic) == 0) { $relevant_logical_types_by_id[$logical_type->id] = $logical_type; break; } elseif ($as_mnemonic == 'slides' && $logical_type->type == 'Presentation Slides') { $relevant_logical_types_by_id[$logical_type->id] = $logical_type; break; } elseif ($as_mnemonic == 'notes' && $logical_type->type == 'Lecture Notes') { $relevant_logical_types_by_id[$logical_type->id] = $logical_type; break; } } } $rhelper->getChildren(); $podcasts = array(); $children = array(); if ($rhelper->children && count($rhelper->children) > 0) { $grandchildren = $rhelper->children; foreach ($grandchildren as $grandchild) { if (isset($relevant_logical_types_by_id[(int) $grandchild->logicaltype])) { if (stripslashes($grandchild->introtext) != '') { $gdescription = html_entity_decode(\Hubzero\Utility\Sanitize::clean(stripslashes($grandchild->introtext))); } array_push($podcasts, $grandchild->path); array_push($children, $grandchild); } } } // Get the contributors of this resource $rhelper->getContributors(); $author = strip_tags($rhelper->contributors); $rtt = new Tags($row->id); $rtags = $rtt->render('string'); if (trim($rtags)) { $rtags = trim(\Hubzero\Utility\String::truncate($rtags, 250)); $rtags = rtrim($rtags, ','); } // Get attributes //$attribs = new \Hubzero\Config\Registry($row->attribs); if ($children) { $attribs = new \Hubzero\Config\Registry($children[0]->attribs); } foreach ($podcasts as $podcast) { // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = $row->typetitle ? $row->typetitle : ''; $item->author = $author; $img = $this->_checkForImage('ituness_artwork', $this->config->get('uploadpath'), $row->created, $row->id); if ($img) { $image = new \Hubzero\Document\Type\Feed\Image(); $image->url = $img; $image->title = $title . ' ' . Lang::txt('COM_RESOURCES_RSS_ARTWORK'); $image->link = $base . $link; $item->itunes_image = $image; } $item->itunes_summary = $description; $item->itunes_explicit = 'no'; $item->itunes_keywords = $rtags; $item->itunes_author = $author; if ($attribs->get('duration')) { $item->itunes_duration = $attribs->get('duration'); } if ($podcast) { $podcastp = $podcast; $podcast = DS . ltrim($this->_fullPath($podcast), DS); if (substr($podcastp, 0, strlen($this->config->get('uploadpath'))) == $this->config->get('uploadpath')) { // Do nothing } else { $podcastp = trim($this->config->get('uploadpath'), DS) . DS . ltrim($podcastp, DS); } $podcastp = PATH_APP . DS . ltrim($podcastp, DS); if (file_exists($podcastp)) { $fs = filesize($podcastp); $enclosure = new \Hubzero\Document\Type\Feed\Enclosure(); $enclosure->url = $podcast; switch (Html::getFileExtension($podcast)) { case 'm4v': $enclosure->type = 'video/x-m4v'; break; case 'mp4': $enclosure->type = 'video/mp4'; break; case 'wmv': $enclosure->type = 'video/wmv'; break; case 'mov': $enclosure->type = 'video/quicktime'; break; case 'qt': $enclosure->type = 'video/quicktime'; break; case 'mpg': $enclosure->type = 'video/mpeg'; break; case 'mpeg': $enclosure->type = 'video/mpeg'; break; case 'mpe': $enclosure->type = 'video/mpeg'; break; case 'mp2': $enclosure->type = 'video/mpeg'; break; case 'mpv2': $enclosure->type = 'video/mpeg'; break; case 'mp3': $enclosure->type = 'audio/mpeg'; break; case 'm4a': $enclosure->type = 'audio/x-m4a'; break; case 'aiff': $enclosure->type = 'audio/x-aiff'; break; case 'aif': $enclosure->type = 'audio/x-aiff'; break; case 'wav': $enclosure->type = 'audio/x-wav'; break; case 'ra': $enclosure->type = 'audio/x-pn-realaudio'; break; case 'ram': $enclosure->type = 'audio/x-pn-realaudio'; break; case 'ppt': $enclosure->type = 'application/vnd.ms-powerpoint'; break; case 'pps': $enclosure->type = 'application/vnd.ms-powerpoint'; break; case 'pdf': $enclosure->type = 'application/pdf'; break; case 'doc': $enclosure->type = 'application/msword'; break; case 'txt': $enclosure->type = 'text/plain'; break; case 'html': $enclosure->type = 'text/html'; break; case 'htm': $enclosure->type = 'text/html'; break; } $enclosure->length = $fs; $item->guid = $podcast; $item->enclosure = $enclosure; } // Loads item info into rss array $doc->addItem($item); } } } } }
/** * Process the compose step * * @return void */ public function step_compose_process() { // Initiate extended database class $row = new Resource($this->database); $row->load(Request::getInt('id', 0)); if (!$row->bind($_POST)) { throw new Exception($row->getError(), 500); } $isNew = $row->id < 1 || substr($row->id, 0, 4) == '9999'; $row->created = $row->created ? $row->created : Date::toSql(); $row->created_by = $row->created_by ? $row->created_by : User::get('id'); // Set status to "composing" if ($isNew) { $row->published = 2; } else { $row->published = $row->published ?: 2; } $row->publish_up = $row->publish_up && $row->publish_up != '0000-00-00 00:00:00' ? $row->publish_up : Date::toSql(); $row->publish_down = $row->publish_down && $row->publish_down != '0000-00-00 00:00:00' ? $row->publish_down : '0000-00-00 00:00:00'; $row->modified = Date::toSql(); $row->modified_by = User::get('id'); $row->access = $row->access ?: 0; $row->fulltxt = trim(preg_replace('/\\\\/', "%5C", $row->fulltxt)); $row->introtext = String::truncate(strip_tags($row->fulltxt), 500); //$row->fulltxt = $this->_txtAutoP($row->fulltxt, 1); // Get custom areas, add wrapper tags, and compile into fulltxt $type = new Type($this->database); $type->load($row->type); include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'elements.php'; $elements = new Elements(array(), $type->customFields); $schema = $elements->getSchema(); $fields = array(); if (is_object($schema)) { foreach ($schema->fields as $field) { $fields[$field->name] = $field; } } $nbtag = isset($_POST['nbtag']) ? $_POST['nbtag'] : array(); $found = array(); foreach ($nbtag as $tagname => $tagcontent) { $f = ''; $row->fulltxt .= "\n" . '<nb:' . $tagname . '>'; if (is_array($tagcontent)) { $c = count($tagcontent); $num = 0; foreach ($tagcontent as $key => $val) { if (trim($val)) { $num++; } $row->fulltxt .= '<' . $key . '>' . trim($val) . '</' . $key . '>'; } if ($c == $num) { $f = 'found'; } } else { $f = trim($tagcontent); if ($f) { $row->fulltxt .= trim($tagcontent); //(isset($fields[$tagname]) && $fields[$tagname]->type == 'textarea') ? $this->_txtAutoP(trim($tagcontent), 1) : trim($tagcontent); } } $row->fulltxt .= '</nb:' . $tagname . '>' . "\n"; if (!$f && isset($fields[$tagname]) && $fields[$tagname]->required) { $this->setError(Lang::txt('COM_CONTRIBUTE_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_CONTRIBUTE_REQUIRED_FIELD_CHECK', $field->label)); } } $row->title = preg_replace('/\\s+/', ' ', $row->title); $row->title = $this->_txtClean($row->title); // Strip any scripting there may be if (trim($row->fulltxt)) { $row->fulltxt = \Components\Resources\Helpers\Html::stripStyles($row->fulltxt); $row->fulltxt = $this->_txtClean($row->fulltxt); //$row->fulltxt = $this->_txtAutoP($row->fulltxt, 1); $row->footertext = $this->_txtClean($row->footertext); } // Check content if (!$row->check()) { $this->setError($row->getError()); } // Fall back to step if any errors found if ($this->getError()) { $this->step--; $this->view->step = $this->step; $this->view->setLayout('compose'); $this->step_compose($row); return; } // reset id if ($isNew) { $row->id = null; } // Store new content if (!$row->store()) { $this->setError(Lang::txt('Error: Failed to store changes.')); $this->step--; $this->view->step = $this->step; $this->view->setLayout('compose'); $this->step_compose($row); return; } // build path to temp upload folder and future permanent folder $session = App::get('session'); $created = Date::format('Y-m-d 00:00:00'); $oldPath = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($created, $session->get('resources_temp_id'), ''); $newPath = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($row->created, $row->id, ''); // if we have a temp dir, move it to permanent location if (is_dir($oldPath)) { \Filesystem::move($oldPath, $newPath); $old = DS . $session->get('resources_temp_id') . DS; $new = DS . $row->id . DS; // update all images in abstract $row->introtext = str_replace($old, $new, $row->introtext); $row->fulltxt = str_replace($old, $new, $row->fulltxt); $row->store(); // clear temp id $session->clear('resources_temp_id'); } // Checkin the resource $row->checkin(); // Is it a new resource? if ($isNew) { // Get the resource ID if (!$row->id) { $row->id = $row->insertid(); } // Automatically attach this user as the first author Request::setVar('pid', $row->id); Request::setVar('id', $row->id); Request::setVar('authid', User::get('id')); include_once __DIR__ . DS . 'authors.php'; $authors = new Authors(); $authors->saveTask(0); } }
/** * Get a list of resources * * @apiMethod GET * @apiUri /resources/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "type": "integer", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "type", * "description": "Type of resource to filter results.", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "sortby", * "description": "Value to sort results by.", * "type": "string", * "required": false, * "default": "date", * "allowedValues": "date, title, random" * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "type": "string", * "required": false, * "default": "" * } * @return void */ public function listTask() { // Incoming $filters = array('type' => Request::getVar('type', ''), 'sortby' => Request::getCmd('sortby', 'date'), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', '')); if (!in_array($filters['sortby'], array('date', 'date_published', 'date_created', 'date_modified', 'title', 'rating', 'ranking', 'random'))) { App::abort(404, Lang::txt('Invalid sort value of "%s" used.', $filters['sortby'])); } require_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; require_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php'; $database = App::get('db'); // Instantiate a resource object $rr = new Resource($database); // encode results and return response $response = new stdClass(); $response->records = array(); $response->total = $rr->getCount($filters); if ($response->total) { // Get major types $t = new Type($database); $types = array(); foreach ($t->getMajorTypes() as $type) { unset($type->params); unset($type->customFields); $types[$type->id] = $type; } $response->records = $rr->getRecords($filters); $base = rtrim(Request::base(), '/'); foreach ($response->records as $i => $entry) { $entry->url = str_replace('/api', '', $base . '/' . ltrim(Route::url('index.php?option=com_resources&' . ($entry->alias ? 'alias=' . $entry->alias : 'id=' . $entry->id)), '/')); if (isset($types[$entry->type])) { $entry->type = $types[$entry->type]; } $response->records[$i] = $entry; } } $response->success = true; $this->send($response); }
/** * Remove one or more types * * @return void Redirects back to main listing */ public function removeTask() { // Check for request forgeries Request::checkToken(); // Incoming (expecting an array) $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Ensure we have an ID to work with if (empty($ids)) { // Redirect with error message App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'), 'error'); return; } $rt = new Type($this->database); foreach ($ids as $id) { // Check if the type is being used $total = $rt->checkUsage($id); if ($total > 0) { // Redirect with error message App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_RESOURCES_TYPE_BEING_USED', $id), 'error'); return; } // Delete the type $rt->delete($id); } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_RESOURCES_ITEMS_REMOVED', count($ids))); }