Exemple #1
0
 /**
  * Generate module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once Component::path('com_tags') . DS . 'models' . DS . 'cloud.php';
     require_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php';
     $database = \App::get('db');
     $this->tags = Tag::all()->whereEquals('admin', 0)->limit((int) $this->params->get('limit', 25))->order('objects', 'desc')->rows();
     // Get major types
     $t = new \Components\Resources\Tables\Type($database);
     $this->categories = $t->getMajorTypes();
     require $this->getLayoutPath();
 }
 /**
  * Up
  **/
 public function up()
 {
     if ($this->db->tableExists('#__tags')) {
         // We need to clean out duplicates first
         $query = "SELECT *, count(id) as cnt FROM `#__tags` GROUP BY `tag` HAVING cnt > 1;";
         $this->db->setQuery($query);
         if ($results = $this->db->loadObjectList()) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'models' . DS . 'cloud.php';
             $cls = '\\Components\\Tags\\Models\\Tag';
             // [!] - Backwards compatibility
             if (class_exists('TagsModelTag')) {
                 $cls = 'TagsModelTag';
             }
             foreach ($results as $result) {
                 // Get all duplicate tags
                 $query = "SELECT * FROM `#__tags` WHERE `tag`=" . $this->db->quote($result->tag) . ";";
                 $this->db->setQuery($query);
                 if ($tags = $this->db->loadObjectList()) {
                     foreach ($tags as $tag) {
                         if ($tag->id == $result->id) {
                             continue;
                         }
                         $oldtag = new $cls($tag->id);
                         if ($oldtag instanceof \Hubzero\Database\Relational) {
                             $oldtag = \Components\Tags\Models\Tag::oneOrNew($tag->id);
                         }
                         if (!$oldtag->mergeWith($result->id)) {
                             continue;
                         }
                     }
                 }
             }
         }
         if ($this->db->tableHasKey('#__tags', 'idx_tag')) {
             $query = "ALTER TABLE `#__tags` DROP INDEX `idx_tag`;";
             $this->db->setQuery($query);
             $this->db->query();
         }
         $query = "CREATE UNIQUE INDEX `idx_tag` ON `#__tags` (`tag`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
 }
Exemple #3
0
}
?>
		</select>

		<input type="hidden" name="tagid" value="<?php 
echo $this->filters['tagid'];
?>
" />
	</fieldset>

	<table class="adminlist">
		<?php 
if ($this->filters['tagid']) {
    ?>
			<caption><?php 
    $tag = \Components\Tags\Models\Tag::oneOrFail($this->filters['tagid']);
    echo Lang::txt('COM_TAGS_TAG') . ': ' . $this->escape($tag->get('raw_tag')) . ' (' . $this->escape($tag->get('tag')) . ')';
    ?>
</caption>
		<?php 
}
?>
		<thead>
			<tr>
				<th scope="col"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php 
echo $this->rows->count();
?>
);" /></th>
				<th scope="col" class="priority-5"><?php 
echo Html::grid('sort', 'COM_TAGS_COL_ID', 'id', @$this->filters['sort_Dir'], @$this->filters['sort']);
?>
Exemple #4
0
 /**
  * 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;
 }
Exemple #5
0
 /**
  * Delete one or more tags
  *
  * @return  void
  */
 public function deleteTask()
 {
     // Check that the user is authorized
     if (!$this->config->get('access-delete-tag')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
     }
     // Incoming
     $ids = Request::getVar('id', array());
     if (!is_array($ids)) {
         $ids = array();
     }
     // Make sure we have an ID
     if (empty($ids)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=browse'));
         return;
     }
     foreach ($ids as $id) {
         $id = intval($id);
         // Remove references to the tag
         Event::trigger('tags.onTagDelete', array($id));
         // Remove the tag
         $tag = new Tag($id);
         $tag->delete();
     }
     $this->cleancacheTask(false);
     // Get the browse filters so we can go back to previous view
     $search = Request::getVar('search', '');
     $sortby = Request::getVar('sortby', '');
     $limit = Request::getInt('limit', 25);
     $start = Request::getInt('limitstart', 0);
     $count = Request::getInt('count', 1);
     // Redirect back to browse mode
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=browse&search=' . $search . '&sortby=' . $sortby . '&limit=' . $limit . '&limitstart=' . $start . '#count' . $count));
 }
Exemple #6
0
 /**
  * Copy all tag associations from one tag to another
  *
  * @return     void
  */
 public function pierceTask()
 {
     // 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)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     $idstr = implode(',', $ids);
     switch ($step) {
         case 1:
             Request::setVar('hidemainmenu', 1);
             $this->view->step = 2;
             $this->view->idstr = $idstr;
             $this->view->tags = array();
             // Loop through the IDs of the tags we want to merge
             foreach ($ids as $id) {
                 // Load the tag's info
                 $this->view->tags[] = new Tag(intval($id));
             }
             // Get all tags
             $cloud = new Cloud();
             // Set any errors
             if ($this->getError()) {
                 $this->view->setError($this->getError());
             }
             // Output the HTML
             $this->view->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 = new Tag($tag_new);
                 if (!$newtag->exists()) {
                     $newtag->set('raw_tag', $tag_new);
                 }
                 if (!$newtag->store(true)) {
                     $this->setError($newtag->getError());
                 }
                 $mtag = $newtag->get('id');
             } else {
                 // No, we're merging into an existing tag
                 $mtag = $tag_exist;
             }
             foreach ($ids as $id) {
                 if ($mtag == $id) {
                     continue;
                 }
                 $oldtag = new Tag(intval($id));
                 if (!$oldtag->copyTo($mtag)) {
                     $this->setError($oldtag->getError());
                 }
             }
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TAGS_TAGS_COPIED'));
             break;
     }
 }
Exemple #7
0
 /**
  * Generates automatic tag field
  *
  * @param   array   $data  the data being saved
  * @return  string
  */
 public function automaticTag($data)
 {
     $tag = isset($data['raw_tag']) && $data['raw_tag'] ? $data['raw_tag'] : $data['tag'];
     return Tag::blank()->normalize($tag);
 }
Exemple #8
0
				</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;
    ?>
Exemple #9
0
 /**
  * Copy all tag associations from one tag to another
  *
  * @return  void
  */
 public function pierceTask()
 {
     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) {
                 // Load the tag's info
                 $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::oneByAlias($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
                 $mtag = $tag_exist;
             }
             foreach ($ids as $id) {
                 if ($mtag == $id) {
                     continue;
                 }
                 $oldtag = Tag::oneOrFail(intval($id));
                 if (!$oldtag->copyTo($mtag)) {
                     $this->setError($oldtag->getError());
                 }
             }
             if ($this->getError()) {
                 Notify::error($this->getError());
             } else {
                 Lang::txt('COM_TAGS_TAGS_COPIED');
             }
             $this->cancelTask();
             break;
     }
 }
Exemple #10
0
 $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();
 }
Exemple #11
0
 /**
  * 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;
 }
Exemple #12
0
 /**
  * Get module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once \Component::path('com_tags') . DS . 'models' . DS . 'cloud.php';
     $this->tags = Tag::all()->whereEquals('admin', 0)->limit((int) $this->params->get('numtags', 25))->order('objects', 'desc')->rows();
     require $this->getLayoutPath();
 }
Exemple #13
0
 /**
  * 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);
 }
Exemple #14
0
 /**
  * Normalize a raw tag
  * Strips all non-alphanumeric characters
  *
  * @param   string  $tag  Raw tag
  * @return  string
  */
 public function normalize($tag)
 {
     return Tag::blank()->normalize($tag);
 }
Exemple #15
0
 /**
  * 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);
 }
Exemple #16
0
 /**
  * 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'));
 }
Exemple #17
0
 /**
  * Get a count of tags
  *
  * @param      integer $admin     Show admin tags?
  * @return     integer
  */
 public function count_tags($admin = 0)
 {
     $t = \Components\Tags\Models\Tag::all();
     if (!$admin) {
         $t->whereEquals('admin', 0);
     }
     return $t->total();
 }
Exemple #18
0
		</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'));