/** * Manage tags on a resource * * @return void */ public function displayTask() { $id = Request::getInt('id', 0); // Get resource title $row = new Resource($this->database); $row->load($id); if (!$row->get('id')) { Notify::error(Lang::txt('COM_RESOURCES_NOTFOUND')); return $this->cancelTask(); } // Get tags for this resource $rt = new TagCloud($id); $mytagarray = array(); $myrawtagarray = array(); foreach ($rt->tags() as $tagMen) { $mytagarray[] = $tagMen->get('tag'); $myrawtagarray[] = $tagMen->get('raw_tag'); } // Get all tags $tags = $rt->tags('list', array('scope' => null, 'scope_id' => 0), true); $objtags = new stdClass(); $objtags->tagMen = implode(', ', $myrawtagarray); // Output the HTML $this->view->set('id', $id)->set('row', $row)->set('tags', $tags)->set('mytagarray', $mytagarray)->set('objtags', $objtags)->setErrors($this->getErrors())->display(); }
/** * Manage tags on a resource * * @return void */ public function displayTask() { $this->view->id = Request::getInt('id', 0); // Get resource title $this->view->row = new Resource($this->database); $this->view->row->load($this->view->id); // Get all tags $query = "SELECT id, tag, raw_tag, admin FROM `#__tags` ORDER BY raw_tag ASC"; $this->database->setQuery($query); $this->view->tags = $this->database->loadObjectList(); if ($this->database->getErrorNum()) { echo $this->database->stderr(); return false; } // Get tags for this resource $rt = new TagCloud($this->view->id); $mytagarray = array(); $myrawtagarray = array(); foreach ($rt->tags() as $tagMen) { $mytagarray[] = $tagMen->get('tag'); $myrawtagarray[] = $tagMen->get('raw_tag'); } $this->view->mytagarray = $mytagarray; $this->view->objtags = new stdClass(); $this->view->objtags->tagMen = implode(', ', $myrawtagarray); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); }
/** * Get tags on this resource * * @param integer $tagger_id Tagger ID * @param integer $strength Tag strength * @param integer $admin Include admin tags? * @return mixed False if errors, array on success */ public function getTags($tagger_id = 0, $strength = 0, $admin = 0) { if ($this->_id == 0) { return false; } include_once __DIR__ . DS . 'tags.php'; $rt = new Tags($this->_id); $filters = array(); if ($tagger_id) { $filters['tagger_id'] = $tagger_id; } if ($strength) { $filters['strength'] = $strength; } if (!$admin) { $filters['admin'] = $admin; } $this->tags = $rt->tags('list', $filters); return $this->tags; }
/** * Get a list of tags on this resource * Accepts either a numeric array index or a string [id, raw] * If index, it'll return the entry matching that index in the list * If string, it'll return either a list of IDs or raw tags * * @param mixed $idx Index value * @return array */ public function tags($idx = null) { if (!$this->exists()) { return array(); } if (!isset($this->tags)) { $this->tags = array(); include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'tags.php'; $rt = new Helpers\Tags($this->resource->id); if ($results = $rt->tags('list')) { $this->tags = $results; } } if ($idx !== null) { if (is_numeric($idx)) { if (isset($this->tags[$idx])) { return $this->tags[$idx]; } else { $this->setError(Lang::txt('Index not found: ') . __CLASS__ . '::' . __METHOD__ . '[' . $idx . ']'); return false; } } else { if (is_string($idx)) { switch (strtolower($idx)) { case 'id': $ids = array(); foreach ($this->tags as $tag) { $ids[] = (int) $tag->id; } return $ids; break; case 'raw': $raw = array(); foreach ($this->tags as $tag) { $raw[] = stripslashes($tag->raw_tag); } return $raw; break; default: return $this->tags; break; } } } } return $this->tags; }
/** * 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); } } } } }
/** * Check if the tags step is completed * * @param integer $id Resource ID * @return integer 1 = step completed, 0 = not completed */ public function step_tags_check($id) { if ($id) { $rt = new Tags($id); $tags = $rt->tags()->count(); if ($tags > 0) { return 1; } } return 0; }
/** * Build and return the url * * @return string */ public function tags($as = 'list') { require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'tags.php'; $cloud = new Tags($this->get('id')); if ($as == 'list') { $tags = array(); foreach ($cloud->tags() as $tag) { array_push($tags, $tag->tag); } return $tags; } else { return $cloud->tags(); } }