/** * TODO: be more careful * INSERT INTO {tag2post} / SELECT $master_tag->ID,post_ID FROM {tag2post} WHERE tag_id = $tag->id" and then "DELETE FROM {tag2post} WHERE tag_id = $tag->id" * Renames tags. * If the master tag exists, the tags will be merged with it. * If not, it will be created first. * * @param Array tags The tag text, slugs or ids to be renamed * @param mixed master The Tag to which they should be renamed, or the slug, text or id of it **/ public static function rename($master, $tags) { if (!is_array($tags)) { $tags = array($tags); } $tag_names = array(); // get array of existing tags first to make sure we don't conflict with a new master tag foreach ($tags as $tag) { $posts = array(); $post_ids = array(); $tag = Tags::get_one($tag); // get all the post ID's tagged with this tag $posts = DB::get_results('SELECT post_id FROM {tag2post} WHERE tag_id = ?', array($tag->id)); if (count($posts) > 0) { // build a list of all the post_id's we need for the new tag foreach ($posts as $post) { $post_ids[] = $post->post_id; } $tag_names[] = $tag->tag; } Tags::delete($tag); } // get the master tag $master_tag = Tags::get_one($master); if (!isset($master_tag->slug)) { // it didn't exist, so we assume it's tag text and create it $master_tag = Tag::create(array('tag_slug' => Utils::slugify($master), 'tag_text' => $master)); $master_ids = array(); } else { // get the posts the tag is already on so we don't duplicate them $master_posts = DB::get_results('SELECT post_id FROM {tag2post} WHERE tag_id = ?', array($master_tag->id)); $master_ids = array(); foreach ($master_posts as $master_post) { $master_ids[] = $master_post->post_id; } } if (count($post_ids) > 0) { // only try and add the master tag to posts it's not already on $post_ids = array_diff($post_ids, $master_ids); // link the master tag to each distinct post we removed tags from foreach ($post_ids as $post_id) { DB::query('INSERT INTO {tag2post} ( tag_id, post_id ) VALUES ( ?, ? )', array($master_tag->id, $post_id)); } } EventLog::log(sprintf(_n('Tag %s has been renamed to %s.', 'Tags %s have been renamed to %s.', count($tags)), implode($tag_names, ', '), $master), 'info', 'tag', 'habari'); }
$msg = _("You must type a name for the tab."); } else { $id = Tags::insert($conn, $name, $bgcolor, $fgcolor, $italic, $bold); $msg = _("Tag successfully created."); } } elseif (GET('mode') == "update" && $id != "") { if ($name == "") { $msg = _("You must type a name for the tab."); } else { Tags::update($conn, $id, $name, $bgcolor, $fgcolor, $italic, $bold); $msg = _("Tag successfully saved."); } $id = ""; } if (GET('delete') != "") { Tags::delete($conn, $delete); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> <?php echo _("Control Panel"); ?> </title> <meta http-equiv="Pragma" content="no-cache"/> <link rel="stylesheet" href="../style/av_common.css?t=<?php echo Util::get_css_id(); ?> "/> <style type='text/css'>
function onRemoveTag() { if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS'])) { echo 'CATS has lost your session data!'; return; } $tags = new Tags($this->_siteID); $tags->delete($_POST['tag_id']); return; }
function removeTag($tagId, $user, $removeFromAllResources = false) { require_once ROOT_DIR . '/services/MyResearch/lib/Tags.php'; require_once ROOT_DIR . '/services/MyResearch/lib/Resource_tags.php'; $rTag = new Resource_tags(); if (!$removeFromAllResources) { $rTag->resource_id = $this->id; } $rTag->tag_id = $tagId; $rTag->user_id = $user->id; $rTag->find(); if ($rTag->N > 0) { while ($rTag->fetch()) { $rTag->delete(); } } else { //the tag was not found. return false; } //Check to see if the tag is still in use by any user for any resource. $rTag = new Resource_tags(); $rTag->tag_id = $tagId; $rTag->find(); if ($rTag->N == 0) { //Tag is still in use, delete it. $tags = new Tags(); $tags->id = $tagId; if ($tags->find(true)) { $tags->delete(); } } return true; }
/** * Handles AJAX from /admin/tags * Used to delete and rename tags */ public function ajax_tags($handler_vars) { Utils::check_request_method(array('POST')); $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']); if ($handler_vars['digest'] != $wsse['digest']) { Session::error(_t('WSSE authentication failed.')); echo Session::messages_get(true, array('Format', 'json_messages')); return; } $tag_names = array(); $action = $this->handler_vars['action']; switch ($action) { case 'delete': foreach ($_POST as $id => $delete) { // skip POST elements which are not tag ids if (preg_match('/^tag_\\d+/', $id) && $delete) { $id = substr($id, 4); $tag = Tags::get_by_id($id); $tag_names[] = $tag->tag; Tags::delete($tag); } } $msg_status = sprintf(_n('Tag %s has been deleted.', 'Tags %s have been deleted.', count($tag_names)), implode($tag_names, ', ')); Session::notice($msg_status); echo Session::messages_get(true, array('Format', 'json_messages')); break; case 'rename': if (isset($this->handler_vars['master'])) { $theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', TRUE)); $this->theme = Themes::create('admin', 'RawPHPEngine', $theme_dir); $master = $this->handler_vars['master']; $tag_names = array(); foreach ($_POST as $id => $rename) { // skip POST elements which are not tag ids if (preg_match('/^tag_\\d+/', $id) && $rename) { $id = substr($id, 4); $tag = Tags::get_by_id($id); $tag_names[] = $tag->tag; } } Tags::rename($master, $tag_names); $msg_status = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master); Session::notice($msg_status); $this->theme->tags = Tags::get(); $this->theme->max = Tags::max_count(); echo json_encode(array('msg' => Session::messages_get(true, 'array'), 'tags' => $this->theme->fetch('tag_collection'))); } break; } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Tags $tags) { $tags->delete(); return redirect()->route('admin.advertisement.index'); }