/** * Generate an RSS feed * * @return string RSS */ public function feedTask() { // Incoming $tagstring = trim(Request::getVar('tag', '', 'request', 'none', 2)); // Ensure we were passed a tag if (!$tagstring) { throw new Exception(Lang::txt('COM_TAGS_NO_TAG'), 404); } // Break the string into individual tags $tgs = explode(',', $tagstring); // Sanitize the tag $tags = array(); $added = array(); foreach ($tgs as $tag) { // Load the tag $tagobj = Tag::getInstance($tag); if (in_array($tagobj->get('tag'), $added)) { continue; } $added[] = $tagobj->get('tag'); // Ensure we loaded the tag's info from the database if ($tagobj->exists()) { $tags[] = $tagobj; } } // Paging variables $limitstart = Request::getInt('limitstart', 0); $limit = Request::getInt('limit', Config::get('list_limit')); $areas = array(); $searchareas = Event::trigger('tags.onTagAreas'); foreach ($searchareas as $area) { $areas = array_merge($areas, $area); } // Get the active category $area = Request::getVar('area', ''); $sort = Request::getVar('sort', ''); if ($area) { $activeareas = array($area); } else { $activeareas = $areas; } // Get the search results if (count($activeareas) > 1) { $sqls = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, $activeareas)); if ($sqls) { $s = array(); foreach ($sqls as $sql) { if (!is_string($sql)) { continue; } if (trim($sql) != '') { $s[] = $sql; } } $query = "("; $query .= implode(") UNION (", $s); $query .= ") ORDER BY "; switch ($sort) { case 'title': $query .= 'title ASC, publish_up'; break; case 'id': $query .= "id DESC"; break; case 'date': default: $query .= 'publish_up DESC, title'; break; } $query .= $limit != 'all' && $limit > 0 ? " LIMIT {$limitstart}, {$limit}" : ""; } $this->database->setQuery($query); $results = array($this->database->loadObjectList()); } else { $results = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, $activeareas)); } // Run through the array of arrays returned from plugins and find the one that returned results $rows = array(); if ($results) { foreach ($results as $result) { if (is_array($result) && !empty($result)) { $rows = $result; break; } } } // Build some basic RSS document information $title = Lang::txt(strtoupper($this->_option)) . ': '; for ($i = 0, $n = count($tags); $i < $n; $i++) { if ($i > 0) { $title .= '+ '; } $title .= $tags[$i]->get('raw_tag') . ' '; } $title = trim($title); $title .= ': ' . $area; // Set the mime encoding for the document Document::setType('feed'); // Start a new feed object $doc = Document::instance(); $doc->link = Route::url('index.php?option=' . $this->_option); $doc->title = Config::get('sitename') . ' - ' . $title; $doc->description = Lang::txt('COM_TAGS_RSS_DESCRIPTION', Config::get('sitename'), $title); $doc->copyright = Lang::txt('COM_TAGS_RSS_COPYRIGHT', gmdate("Y"), Config::get('sitename')); $doc->category = Lang::txt('COM_TAGS_RSS_CATEGORY'); // Start outputing results if any found if (count($rows) > 0) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php'; foreach ($rows as $row) { // Prepare the title $title = strip_tags($row->title); $title = html_entity_decode($title); // Strip html from feed item description text $description = html_entity_decode(String::truncate(Sanitize::stripAll(stripslashes($row->ftext)), 300)); $author = ''; @($date = $row->publish_up ? date('r', strtotime($row->publish_up)) : ''); if (isset($row->data3) || isset($row->rcount)) { $resourceEx = new \Components\Resources\Helpers\Helper($row->id, $this->database); $resourceEx->getCitationsCount(); $resourceEx->getLastCitationDate(); $resourceEx->getContributors(); $author = strip_tags($resourceEx->contributors); } // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $row->href; $item->description = $description; $item->date = $date; $item->category = isset($row->data1) ? $row->data1 : ''; $item->author = $author; // Loads item info into rss array $doc->addItem($item); } } }
/** * Remove tags from an item * * @param mixed $tags Array or string of tags * @param integer $tagger ID of user to remove tags for * @return mixed False if errors, integer on success */ public function remove($tags, $tagger = 0) { if (!$this->_scope_id) { $this->setError('Unable to remove tags: No objct ID provided.'); return false; } if (!$tags) { $this->setError('Unable to remove tags: No tag(s) provided.'); return false; } foreach ($this->_parse($tags) as $tg) { $tag = Tag::getInstance((string) $tg); // Does the tag exist? if (!$tag->exists()) { // Tag doesn't exist, no point in going any further continue; } // Remove tag from object if (!$tag->removeFrom($this->_scope, $this->_scope_id, $tagger)) { $this->setError($tag->getError()); } } return true; }