/** * Add a tag to an item * * @return void */ public function addTask() { $this->requiresAuthentication(); $name = Request::getWord('tag', ''); $id = Request::getInt('id', 0); $id = $id ? $id : $name; //$tag = new Tag($id); $tag = $id ? Tag::oneOrFail($id) : Tag::oneByTag($name); if (!$tag->get('id')) { throw new Exception(Lang::txt('Specified tag does not exist.'), 404); } $scope = Request::getWord('scope', ''); $scope_id = Request::getInt('scope_id', 0); $tagger = Request::getInt('tagger', 0); if (!$scope || !$scope_id) { throw new Exception(Lang::txt('Invalid scope and/or scope_id.'), 500); } if (!$tag->addTo($scope, $scope_id, $tagger)) { throw new Exception(Lang::txt('Failed to add tag to object.'), 500); } $this->send(null, 202); }
/** * Get the ID of a normalized tag * * @param string $tag Normalized tag * @return mixed False if errors, integer on success */ public function get_tag_id($tag) { if (!isset($tag)) { $this->setError('get_tag_id argument missing'); return false; } $t = \Components\Tags\Models\Tag::oneByTag($tag); return $t->get('id'); }
/** * 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::oneByTag($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->get('id')) { $tags[] = $tagobj; } } // Paging variables $limitstart = Request::getInt('limitstart', 0); $limit = Request::getInt('limit', Config::get('list_limit')); $areas = Event::trigger('tags.onTagAreas'); // Get the active category $area = Request::getVar('area', ''); $sort = Request::getVar('sort', ''); // Get the search results if (!$area) { $sqls = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, '')); if ($sqls) { $s = array(); foreach ($sqls as $response) { if (is_array($response['sql'])) { continue; } if (trim($response['sql']) != '') { $s[] = $response['sql']; } if (isset($response['children'])) { foreach ($response['children'] as $sresponse) { if (is_array($sresponse['sql'])) { continue; } if (trim($sresponse['sql']) != '') { $s[] = $sresponse['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; } if ($limit != 'all' && $limit > 0) { $query .= " LIMIT " . $limitstart . "," . $limit; } } $this->database->setQuery($query); $rows = $this->database->loadObjectList(); } else { $results = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, $area)); // 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['results'])) { $rows = $result['results']; break; } if (isset($result['children'])) { foreach ($result['children'] as $sresponse) { if (is_array($sresponse['results'])) { $rows = $sresponse['results']; 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(strip_tags(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 = \Route::url($row->href); $item->description = '<![CDATA[' . $description . ']]>'; $item->date = $date; $item->category = isset($row->data1) && $row->data1 ? $row->data1 : $row->section; $item->author = $author; // Loads item info into rss array $doc->addItem($item); } } }
/** * Append a tag to the internal cloud * * @param mixed $tag * @return object */ public function append($tag) { if (!$this->_cache['tags.list'] instanceof ItemList) { $this->_cache['tags.list'] = new ItemList(array()); } if (!$tag) { return $this; } if (!$tag instanceof Tag) { if (is_array($tag)) { foreach ($tag as $t) { $t = is_object($t) ? $t->tag : $t; $this->_cache['tags.list']->add(Tag::oneByTag($t)); } return $this; } else { $tag = Tag::oneByTag($tag); } } $this->_cache['tags.list']->add($tag); return $this; }
/** * Merge two tags into one * * @return void */ public function mergeTask() { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.manage', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $step = Request::getInt('step', 1); $step = $step ? $step : 1; // Make sure we have some IDs to work with if ($step == 1 && (!$ids || count($ids) < 1)) { return $this->cancelTask(); } $idstr = implode(',', $ids); switch ($step) { case 1: Request::setVar('hidemainmenu', 1); $tags = array(); // Loop through the IDs of the tags we want to merge foreach ($ids as $id) { // Add the tag object to an array $tags[] = Tag::oneOrFail(intval($id)); } // Output the HTML $this->view->set('step', 2)->set('idstr', $idstr)->set('tags', $tags)->display(); break; case 2: // Check for request forgeries Request::checkToken(); // Get the string of tag IDs we plan to merge $ind = Request::getVar('ids', '', 'post'); if ($ind) { $ids = explode(',', $ind); } else { $ids = array(); } // Incoming $tag_exist = Request::getInt('existingtag', 0, 'post'); $tag_new = Request::getVar('newtag', '', 'post'); // Are we merging tags into a totally new tag? if ($tag_new) { // Yes, we are $newtag = Tag::oneByTag($tag_new); if (!$newtag->get('id')) { $newtag->set('raw_tag', $tag_new); } if (!$newtag->save()) { $this->setError($newtag->getError()); } $mtag = $newtag->get('id'); } else { // No, we're merging into an existing tag $existtag = Tag::oneOrFail($tag_exist); $mtag = $existtag->get('id'); } if ($this->getError()) { Notyf::error($this->getError()); return $this->cancelTask(); } if (!$mtag) { Notify::error(Lang::txt('Failed to find destination tag.')); return $this->cancelTask(); } foreach ($ids as $id) { if ($mtag == $id) { continue; } $oldtag = Tag::oneOrFail(intval($id)); if (!$oldtag->mergeWith($mtag)) { $this->setError($oldtag->getError()); } } if ($this->getError()) { Notify::error($this->getError()); } else { Notify::success(Lang::txt('COM_TAGS_TAGS_MERGED')); } $this->cancelTask(); break; } }
/** * Save a type * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Initiate extended database class $fields = Request::getVar('fields', array(), 'post', 'none', 2); $fields = array_map('trim', $fields); $row = \Plugins\Resources\Sponsors\Models\Sponsor::oneOrNew($fields['id'])->set($fields); // Store new content if (!$row->save()) { $this->setError($row->getError()); return $this->editTask($row); } require_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'models' . DS . 'cloud.php'; $t = \Components\Tags\Models\Tag::oneByTag($row->get('alias')); if ($t->isNew()) { // Add new tag! $t->set('tag', $row->get('alias')); $t->set('raw_tag', addslashes($row->get('title'))); if (!$t->save()) { $this->setError($t->getError()); } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=manage&plugin=sponsors', false), Lang::txt('PLG_RESOURCES_SPONSORS_ITEM_SAVED')); }
$supported = null; if ($this->bits['supportedtag']) { $supported = $rt->checkTagUsage($this->bits['supportedtag'], $resource->id); } $xtra = ''; if ($params->get('show_audience')) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'audience.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'audiencelevel.php'; $ra = new \Components\Resources\Tables\Audience($database); $audience = $ra->getAudience($resource->id, 0, 1, 4); $view = $this->view('_audience', 'view')->set('audience', $audience)->set('showtips', 0)->set('numlevels', 4)->set('audiencelink', $params->get('audiencelink')); $xtra .= $view->loadTemplate(); } if ($this->bits['supportedtag'] && $supported) { include_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'models' . DS . 'cloud.php'; $tag = \Components\Tags\Models\Tag::oneByTag($config->get('supportedtag')); $sl = $config->get('supportedlink'); if ($sl) { $link = $sl; } else { $link = Route::url('index.php?option=com_tags&tag=' . $tag->get('tag')); } $xtra .= '<p class="supported"><a href="' . $link . '">' . $tag->get('raw_tag') . '</a></p>'; } if ($params->get('show_metadata')) { $view = $this->view('_metadata', 'view'); $view->option = 'com_resources'; $view->sections = $sections; $view->model = \Components\Resources\Models\Resource::getInstance($resource->id); $html .= $view->loadTemplate(); }
/** * Append a tag to the existing tag list * * @param mixed $tag * @return void */ public function append($tag) { if (!isset($this->_cache['tags'])) { $this->_cache['tags'] = new ItemList(array()); } if (!$tag) { return; } if (!$tag instanceof Tag) { $tg = Tag::oneByTag($tag); $tg->set('raw_tag', $tag); $tag = $tg; } $this->_cache['tags']->add($tag); }
/** * Get the ID of a normalized tag * * @param string $tag Normalized tag * @return mixed False if errors, integer on success */ private function _getTagId($tag) { if (!isset($tag)) { $this->setError(__CLASS__ . '::' . __METHOD__ . ' - Tag argument missing.'); return false; } $t = Tag::oneByTag($tag); return $t->get('id'); }
</dd> </dl> <?php } if ($this->model->params->get('show_audience')) { include_once PATH_CORE . DS . 'components' . DS . $this->option . DS . 'tables' . DS . 'audience.php'; include_once PATH_CORE . DS . 'components' . DS . $this->option . DS . 'tables' . DS . 'audiencelevel.php'; $ra = new \Components\Resources\Tables\Audience($database); $audience = $ra->getAudience($this->model->resource->id, $versionid = 0, $getlabels = 1, $numlevels = 4); $this->view('_audience', 'view')->set('audience', $audience)->set('showtips', 1)->set('numlevels', 4)->set('audiencelink', $this->model->params->get('audiencelink'))->display(); } if ($this->model->params->get('supportedtag')) { $rt = new \Components\Resources\Helpers\Tags($this->model->resource->id); if ($rt->checkTagUsage($this->model->params->get('supportedtag'), $this->model->resource->id)) { include_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'models' . DS . 'cloud.php'; $tag = \Components\Tags\Models\Tag::oneByTag($this->model->params->get('supportedtag')); ?> <p class="supported"> <a href="<?php echo $this->model->params->get('supportedlink', Route::url('index.php?option=com_tags&tag=' . $tag->get('tag'))); ?> "><?php echo $this->escape(stripslashes($tag->get('raw_tag'))); ?> </a> </p> <?php } } echo $data; ?>
</div><!-- / #tagbrowser --> <p id="viewalltools"><a href="<?php echo Route::url('index.php?option=' . $this->option . '&type=' . $this->filters['type']); ?> "><?php echo Lang::txt('COM_RESOURCES_VIEW_MORE'); ?> </a></p> <div class="clear"></div> <?php if ($this->supportedtag) { $database = App::get('db'); include_once Component::path('com_tags') . DS . 'models' . DS . 'cloud.php'; $tag = \Components\Tags\Models\Tag::oneByTag($this->supportedtag); if ($sl = $this->config->get('supportedlink')) { $link = $sl; } else { $link = Route::url('index.php?option=com_tags&tag=' . $tag->get('tag')); } ?> <p class="supported"> <?php echo Lang::txt('COM_RESOURCES_WHATS_THIS'); ?> <a href="<?php echo $link; ?> "><?php echo Lang::txt('COM_RESOURCES_ABOUT_TAG', $tag->get('raw_tag'));