/** * Edit form for a resource * * @param integer $isnew Flag for editing (0) or creating new (1) * @return void */ public function editTask($isnew = 0) { Request::setVar('hidemainmenu', 1); $this->view->isnew = $isnew; // Get the resource component config $this->view->rconfig = $this->config; // Push some needed styles to the tmeplate $this->css('resources.css'); // Incoming resource ID $id = Request::getVar('id', array(0)); if (is_array($id)) { $id = !empty($id) ? $id[0] : 0; } // Incoming parent ID - this determines if the resource is standalone or not $this->view->pid = Request::getInt('pid', 0); // Grab some filters for returning to place after editing $this->view->return = array(); $this->view->return['type'] = Request::getVar('type', ''); $this->view->return['sort'] = Request::getVar('sort', ''); $this->view->return['status'] = Request::getVar('status', ''); // Instantiate our resource object $this->view->row = new Resource($this->database); $this->view->row->load($id); // Fail if checked out not by 'me' if ($this->view->row->checked_out && $this->view->row->checked_out != User::get('id')) { $task = ''; if ($this->view->pid) { $task = '&task=children&pid=' . $this->view->pid; } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . $task, false), Lang::txt('COM_RESOURCES_WARNING_CHECKED_OUT'), 'notice'); return; } // Is this a new resource? if (!$id) { $this->view->row->created = Date::toSql(); $this->view->row->created_by = User::get('id'); $this->view->row->modified = $this->database->getNullDate(); $this->view->row->modified_by = 0; $this->view->row->publish_up = Date::toSql(); $this->view->row->publish_down = Lang::txt('COM_RESOURCES_NEVER'); if ($this->view->pid) { $this->view->row->published = 1; $this->view->row->standalone = 0; } else { $this->view->row->published = 3; // default to "new" status $this->view->row->standalone = 1; } $this->view->row->access = 0; } // Editing existing $this->view->row->checkout(User::get('id')); if (trim($this->view->row->publish_down) == '0000-00-00 00:00:00') { $this->view->row->publish_down = Lang::txt('COM_RESOURCES_NEVER'); } // Get name of resource creator $creator = User::getInstance($this->view->row->created_by); $this->view->row->created_by_name = $creator->get('name'); $this->view->row->created_by_name = $this->view->row->created_by_name ? $this->view->row->created_by_name : Lang::txt('Unknown'); // Get name of last person to modify resource if ($this->view->row->modified_by) { $modifier = User::getInstance($this->view->row->modified_by); $this->view->row->modified_by_name = $modifier->get('name'); $this->view->row->modified_by_name = $this->view->row->modified_by_name ? $this->view->row->modified_by_name : Lang::txt('Unknown'); } else { $this->view->row->modified_by_name = ''; } // Get params definitions $this->view->params = new \Hubzero\Html\Parameter($this->view->row->params, dirname(dirname(__DIR__)) . DS . 'resources.xml'); $this->view->attribs = new \Hubzero\Config\Registry($this->view->row->attribs); // Build selects of various types $rt = new Type($this->database); if ($this->view->row->standalone != 1) { $this->view->lists['type'] = Html::selectType($rt->getTypes(30), 'type', $this->view->row->type, '', '', '', ''); $this->view->lists['logical_type'] = Html::selectType($rt->getTypes(28), 'logical_type', $this->view->row->logical_type, '[ none ]', '', '', ''); $this->view->lists['sub_type'] = Html::selectType($rt->getTypes(30), 'logical_type', $this->view->row->logical_type, '[ none ]', '', '', ''); } else { $this->view->lists['type'] = Html::selectType($rt->getTypes(27), 'type', $this->view->row->type, '', '', '', ''); $this->view->lists['logical_type'] = Html::selectType($rt->getTypes(21), 'logical_type', $this->view->row->logical_type, '[ none ]', '', '', ''); } // Build the <select> of admin users $this->view->lists['created_by'] = $this->userSelect('created_by', 0, 1); // Build the <select> for the group access $this->view->lists['access'] = Html::selectAccess($this->view->rconfig->get('accesses'), $this->view->row->access); // Is this a standalone resource? if ($this->view->row->standalone == 1) { $this->view->lists['tags'] = ''; // Get groups $filters = array('authorized' => 'admin', 'fields' => array('cn', 'description', 'published', 'gidNumber', 'type'), 'type' => array(1, 3), 'sortby' => 'description'); $groups = \Hubzero\User\Group::find($filters); // Build <select> of groups $this->view->lists['groups'] = Html::selectGroup($groups, $this->view->row->group_owner); include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'profile.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'association.php'; // Get all contributors $mp = new \Components\Members\Tables\Profile($this->database); $members = null; //$mp->getRecords(array('sortby'=>'surname DESC','limit'=>'all','search'=>'','show'=>''), true); // Get all contributors linked to this resource $authnames = array(); if ($this->view->row->id) { $ma = new \Components\Members\Tables\Association($this->database); $sql = "SELECT n.uidNumber AS id, a.authorid, a.name, n.givenName, n.middleName, n.surname, a.role, a.organization\n\t\t\t\t\t\tFROM " . $ma->getTableName() . " AS a\n\t\t\t\t\t\tLEFT JOIN " . $mp->getTableName() . " AS n ON n.uidNumber=a.authorid\n\t\t\t\t\t\tWHERE a.subtable='resources'\n\t\t\t\t\t\tAND a.subid=" . $this->view->row->id . "\n\t\t\t\t\t\tORDER BY a.ordering"; $this->database->setQuery($sql); $authnames = $this->database->loadObjectList(); // Get the tags on this item $tagger = new Tags($this->view->row->id); $this->view->lists['tags'] = $tagger->render('string'); } // Build <select> of contributors $authorslist = new \Hubzero\Component\View(array('name' => $this->_controller, 'layout' => 'authors')); $authorslist->authnames = $authnames; $authorslist->attribs = $this->view->attribs; $authorslist->option = $this->_option; $authorslist->roles = $rt->getRolesForType($this->view->row->type); $this->view->lists['authors'] = $authorslist->loadTemplate(); } // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Get a tag cloud for this resource * * @param integer $admin Include admin tags? * @return boolean False if errors, string on success */ public function getTagCloud($admin = 0) { if ($this->_id == 0) { return false; } include_once __DIR__ . DS . 'tags.php'; $rt = new Tags($this->_id); $this->tagCloud = $rt->render('cloud'); return $this->tagCloud; }
/** * 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); } } } } }