/** * Creates a tag * * @param string $p_username The user's username * @param string $p_password The user's password * @param array $p_tag The tag to create * @return soap_fault|integer */ function mc_tag_add($p_username, $p_password, $p_tag) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!access_has_global_level(config_get('tag_create_threshold'))) { return mci_soap_fault_access_denied($t_user_id); } $t_valid_matches = array(); $t_tag_name = $p_tag['name']; $t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : ''; if (!tag_name_is_valid($t_tag_name, $t_valid_matches)) { return new soap_fault('client', '', 'Invalid tag name : "' . $t_tag_name . '"'); } $t_matching_by_name = tag_get_by_name($t_tag_name); if ($t_matching_by_name != false) { return new soap_fault('client', '', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']); } return tag_create($t_tag_name, $t_user_id, $t_tag_description); }
/** * Creates a tag * * @param string $p_username The user's username * @param string $p_password The user's password * @param array $p_tag The tag to create * @return soap_fault|integer */ function mc_tag_add($p_username, $p_password, $p_tag) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!access_has_global_level(config_get('tag_create_threshold'))) { return mci_soap_fault_access_denied($t_user_id); } $t_valid_matches = array(); $p_tag = SoapObjectsFactory::unwrapObject($p_tag); $t_tag_name = $p_tag['name']; $t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : ''; if (!tag_name_is_valid($t_tag_name, $t_valid_matches)) { return SoapObjectsFactory::newSoapFault('Client', 'Invalid tag name : "' . $t_tag_name . '"'); } $t_matching_by_name = tag_get_by_name($t_tag_name); if ($t_matching_by_name != false) { return SoapObjectsFactory::newSoapFault('Client', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']); } log_event(LOG_WEBSERVICE, "creating tag '{$t_tag_name}' for user '{$t_user_id}'"); return tag_create($t_tag_name, $t_user_id, $t_tag_description); }
/** * function to attach tags into a post * @param int postid - id of the blog */ function add_tags_info($postid) { global $USER; $post = get_record('post', 'id', $postid); /// Attach official tags if ($otags = optional_param('otags', '', PARAM_INT)) { foreach ($otags as $otag) { $tag->tagid = $otag; //insert_record('blog_tag_instance', $tag); tag_an_item('blog', $postid, $otag, 'official'); } } /// Attach Personal Tags if ($ptags = optional_param('ptags', '', PARAM_NOTAGS)) { $ptags = explode(',', $ptags); foreach ($ptags as $ptag) { $ptag = trim($ptag); // check for existance // it does not matter whether it is an offical tag or personal tag // we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag) if ($ctag = tag_by_id($ptag)) { tag_an_item('blog', $postid, $ctag); } else { // create a personal tag if ($tagid = tag_create($ptag)) { if ($tagid = array_shift($tagid)) { tag_an_item('blog', $postid, $tagid); } } } } } }
/** * Attaches all the tags to each bug in the group action. * @param integer Bug ID * @return boolean True if all tags attach properly */ function action_attach_tags_process($p_bug_id) { global $g_action_attach_tags_attach, $g_action_attach_tags_create; $t_user_id = auth_get_current_user_id(); foreach ($g_action_attach_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name'], $t_user_id); $g_action_attach_tags_attach[] = $t_tag_row; } $g_action_attach_tags_create = array(); foreach ($g_action_attach_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $p_bug_id)) { tag_bug_attach($t_tag_row['id'], $p_bug_id, $t_user_id); } } return true; }
* @package MantisBT * @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net * @link http://www.mantisbt.org * * @uses core.php * @uses authentication_api.php * @uses form_api.php * @uses gpc_api.php * @uses print_api.php * @uses tag_api.php */ require_once 'core.php'; require_api('authentication_api.php'); require_api('form_api.php'); require_api('gpc_api.php'); require_api('print_api.php'); require_api('tag_api.php'); form_security_validate('tag_create'); $f_tag_name = gpc_get_string('name'); $f_tag_description = gpc_get_string('description'); $t_tag_user = auth_get_current_user_id(); if (!is_null($f_tag_name)) { $t_tags = tag_parse_string($f_tag_name); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { tag_create($t_tag_row['name'], $t_tag_user, $f_tag_description); } } } form_security_purge('tag_create'); print_successful_redirect('manage_tags_page.php');
<?php require '../include/core/common.php'; require PATHS_INCLUDE . 'libraries/forum.php'; // NOTE: if(false)! (This file is deprecated) if (false) { if ($_GET['action'] == 'update_tags') { /* Remove all old tags */ $tags = tag_get_by_item('discussion', $_GET['discussion_id']); foreach ($tags as $tag) { $tag_ids[] = $tag['tag_id']; } tag_remove($_GET['discussion_id'], 'discussion', $tag_ids); /* Set the new tags */ $tags = explode(' ', str_replace(',', ' ', $_GET['tags'])); foreach ($tags as $key => $tag) { $tags[$key] = trim($tag); } $tags = array_unique($tags); foreach ($tags as $tag_label) { $return = tag_exists($tag_label); if ($return['status'] == 'exists') { $set_tag_ids[] = array('tag_id' => $return['tag_id']); } else { $set_tag_ids[] = array('tag_id' => tag_create($taglabel)); } } tag_set($_GET['discussion_id'], 'discussion', $set_tag_ids); // Äntligen kan vi börja sätta de nya taggarna } }
?> <tr class="spacer"><td colspan="2"></td></tr> <tr> <th class="category"><?php echo lang_get('tag_attach_long'); ?> </th> <td> <?php print_tag_attach_form($f_bug_id, $t_tag_string); ?> </td> </tr> </table> <?php html_page_bottom(); // end failed to attach tag } else { foreach ($t_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name'], $t_user_id); $t_tags_attach[] = $t_tag_row; } foreach ($t_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $f_bug_id)) { tag_bug_attach($t_tag_row['id'], $f_bug_id, $t_user_id); } } event_signal('EVENT_TAG_ATTACHED', array($f_bug_id, $t_tags_attach)); form_security_purge('tag_attach'); print_successful_redirect_to_bug($f_bug_id); }
/** * Attaches a bunch of tags to the specified issue. * * @param int $p_bug_id The bug id. * @param string $p_tag_string String of tags separated by configured separator. * @param int $p_tag_id Tag id to add or 0 to skip. * @return array|bool true for success, otherwise array of failures. The array elements follow the tag_parse_string() * format. */ function tag_attach_many($p_bug_id, $p_tag_string, $p_tag_id = 0) { # If no work, then there is no need to do access check. if ($p_tag_id === 0 && is_blank($p_tag_string)) { return true; } access_ensure_bug_level(config_get('tag_attach_threshold'), $p_bug_id); $t_tags = tag_parse_string($p_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); $t_tags_create = array(); $t_tags_attach = array(); $t_tags_failed = array(); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } else { if (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else { $t_tags_attach[] = $t_tag_row; } } } if (0 < $p_tag_id && tag_exists($p_tag_id)) { $t_tags_attach[] = tag_get($p_tag_id); } # failed to attach at least one tag if (count($t_tags_failed) > 0) { return $t_tags_failed; } foreach ($t_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name']); $t_tags_attach[] = $t_tag_row; } foreach ($t_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $p_bug_id)) { tag_bug_attach($t_tag_row['id'], $p_bug_id); } } event_signal('EVENT_TAG_ATTACHED', array($p_bug_id, $t_tags_attach)); return true; }
/** * Associates a tag with an item * * Ex 1: tag_an_item('user', '1', 'hisTOrY, RELIGIONS, roman' ) * This will tag an user whose id is 1 with "history", "religions", "roman" * If the tag names passed do not exist, they will get created. * * Ex 2: tag_an_item('user', '1', 'hisTory, 12, 11, roman') * This will tag an user whose id is 1 with 'history', 'roman' and with tags of ids 12 and 11 * * @param string $item_type name of the table where the item is stored. Ex: 'user' * @param string $item_id id of the item to be tagged * @param string $tag_names_or_ids_csv comma separated tag names (can be unormalized) or ids of existing tags * @param string $tag_type type of the tags that are beeing added (optional, default value is "default") */ function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type = "default") { global $CFG; //convert any tag ids passed to their corresponding tag names $tag_names_csv = tag_name_from_string($tag_names_or_ids_csv); //create the tags $tags_created_ids = tag_create($tag_names_csv, $tag_type); //tag instances of an item are ordered, get the last one $query = "\n SELECT\n MAX(ordering) max_order\n FROM\n {$CFG->prefix}tag_instance ti\n WHERE\n ti.itemtype = '{$item_type}'\n AND\n ti.itemid = '{$item_id}'\n "; $max_order = get_field_sql($query); $tag_names = explode(',', tag_normalize($tag_names_csv)); $ordering = array(); foreach ($tag_names as $tag_name) { $ordering[$tag_name] = ++$max_order; } //setup tag_instance object $tag_instance = new StdClass(); $tag_instance->itemtype = $item_type; $tag_instance->itemid = $item_id; //create tag instances foreach ($tags_created_ids as $tag_normalized_name => $tag_id) { $tag_instance->tagid = $tag_id; $tag_instance->ordering = $ordering[$tag_normalized_name]; $tag_instance->timemodified = time(); $tag_instance_exists = get_record('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id); if (!$tag_instance_exists) { insert_record('tag_instance', $tag_instance); } else { $tag_instance_exists->timemodified = time(); $tag_instance_exists->ordering = $ordering[$tag_normalized_name]; update_record('tag_instance', $tag_instance_exists); } } // update_tag_correlations($item_type, $item_id); }
function tag_set_wrap($options) { /* Obs! Removes all old tags options array support possible values item_id no object_type no 'discussion', 'post', 'wallpaper', 'article', 'survey', 'game', 'clip', 'a1' tag_handle yes handle_type_values tag_label yes Free text values tag_id yes 1, 2, 3.. add no set to true if tags should be added to old tags */ if (644314 == $_SESSION['login']['id']) { preint_r($options); } $keys = array('tag_handle', 'tag_label', 'tag_id'); foreach ($keys as $key) { if (isset($options[$key])) { $options[$key] = is_array($options[$key]) ? $options[$key] : array($options[$key]); $keytype = $key; } } if ($keytype == 'tag_label') { foreach ($options['tag_label'] as $label) { if (!($tag = tag_get_by_handle(url_secure_string($label)))) { $tag_id = tag_create($label); } else { $tag_id = $tag['id']; } $tag_ids[] = $tag_id; } } elseif ($keytype == 'tag_handle') { $tags = tag_get_by_handle($options['tag_handle']); unset($tag_ids); foreach ($tags as $tag) { $tag_ids[] = $tag['id']; } } if (!isset($options['add'])) { $query = 'DELETE FROM object_tags WHERE object_type = "' . $options['object_type'] . '" AND reference_id = "' . $options['item_id'] . '"'; mysql_query($query); } foreach ($tag_ids as $tag_id) { $query = 'INSERT INTO object_tags (tag_id, object_type, reference_id)'; $query .= ' VALUES ("' . $tag_id . '", "' . $options['object_type'] . '", "' . $options['item_id'] . '")'; mysql_query($query); //todo! annan felhantering här då det kan hända att man försöker sätta redan satta taggar, or die(report_sql_error($query, __FILE__, __LINE__)); } }