/** * Ensure a tag exists with the given ID. * @param integer Tag ID */ function tag_ensure_exists($p_tag_id) { if (!tag_exists($p_tag_id)) { error_parameters($p_tag_id); trigger_error(ERROR_TAG_NOT_FOUND, ERROR); } }
/** * Validates the Attach Tags group action. * Gets called for every bug, but performs the real tag validation only * the first time. Any invalid tags will be skipped, as there is no simple * or clean method of presenting these errors to the user. * @param integer Bug ID * @return boolean True */ function action_attach_tags_validate($p_bug_id) { global $g_action_attach_tags_valid; if (!isset($g_action_attach_tags_valid)) { $f_tag_string = gpc_get_string('tag_string'); $f_tag_select = gpc_get_string('tag_select'); global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; $g_action_attach_tags_attach = array(); $g_action_attach_tags_create = array(); $g_action_attach_tags_failed = array(); $t_tags = tag_parse_string($f_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $g_action_attach_tags_create[] = $t_tag_row; } else { $g_action_attach_tags_failed[] = $t_tag_row; } } elseif (-2 == $t_tag_row['id']) { $g_action_attach_tags_failed[] = $t_tag_row; } else { $g_action_attach_tags_attach[] = $t_tag_row; } } if (0 < $f_tag_select && tag_exists($f_tag_select)) { $g_action_attach_tags_attach[] = tag_get($f_tag_select); } } global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; return true; }
function convert_them() { global $wpdb; if ((!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { echo '<div class="narrow">'; echo '<p>' . sprintf(__('Uh, oh. Something didn’t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>'; echo '</div>'; return; } if (empty($this->categories_to_convert)) { $this->categories_to_convert = $_POST['cats_to_convert']; } $hier = _get_term_hierarchy('category'); echo '<ul>'; foreach ((array) $this->categories_to_convert as $cat_id) { $cat_id = (int) $cat_id; echo '<li>' . sprintf(__('Converting category #%s ... '), $cat_id); if (!$this->_category_exists($cat_id)) { _e('Category doesn\'t exist!'); } else { $category =& get_category($cat_id); if (tag_exists($wpdb->escape($category->name))) { _e('Category is already a tag.'); echo '</li>'; continue; } // If the category is the default, leave category in place and create tag. if (get_option('default_category') == $category->term_id) { $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); $id = $id['term_taxonomy_id']; $posts = get_objects_in_term($category->term_id, 'category'); foreach ($posts as $post) { if (!$wpdb->get_var("SELECT object_id FROM {$wpdb->term_relationships} WHERE object_id = '{$post}' AND term_taxonomy_id = '{$id}'")) { $wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id) VALUES ('{$post}', '{$id}')"); } clean_post_cache($post); } } else { $tt_ids = $wpdb->get_col("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); if ($tt_ids) { $posts = $wpdb->get_col("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); foreach ((array) $posts as $post) { clean_post_cache($post); } } // Change the category to a tag. $wpdb->query("UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); $terms = $wpdb->get_col("SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); foreach ((array) $terms as $term) { clean_category_cache($term); } // Set all parents to 0 (root-level) if their parent was the converted tag $wpdb->query("UPDATE {$wpdb->term_taxonomy} SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); } // Clean the cache clean_category_cache($category->term_id); _e('Converted successfully.'); } echo '</li>'; } echo '</ul>'; echo '<p>' . sprintf(__('We’re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag') . '</p>'; }
/** * * Deletes a tag * * @param string $p_username The user's username * @param string $p_password The user's password * @param unknown_type $p_tag_id * @param int $p_tag_id The id of the tag * @return soap_fault|boolean */ function mc_tag_delete($p_username, $p_password, $p_tag_id) { $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_edit_threshold'))) { return mci_soap_fault_access_denied($t_user_id); } if (!tag_exists($p_tag_id)) { return SoapObjectsFactory::newSoapFault('Client', 'No tag with id ' . $p_tag_id); } return tag_delete($p_tag_id); }
function test_query_tag__in_but__not_in() { $tag_a = tag_exists('tag-a'); $tag_b = tag_exists('tag-b'); $posts = $this->q->query("tag__in[]=" . $tag_a['term_id'] . "&tag__not_in[]=" . $tag_b['term_id']); // there are 4 posts with Tag A, only 2 when we exclude Tag B $this->assertCount(2, $posts); $this->assertEquals('tags-a-and-c', $posts[0]->post_name); $this->assertEquals('tag-a', $posts[1]->post_name); }
function wp_create_tag($tag_name) { if ( $id = tag_exists($tag_name) ) return $id; return wp_insert_term($tag_name, 'post_tag'); }
} } if ($changed) { $str_changed = tag_name_from_string(implode($changed, ',')); $str_changed = str_replace(',', ', ', $str_changed); $notice = $str_changed . ' -- ' . get_string('typechanged', 'tag'); } break; case 'changename': if (!data_submitted or !confirm_sesskey()) { break; } $tags_names_changed = array(); foreach ($tagschecked as $tag_id) { if ($newnames[$tag_id] != '') { if (tag_exists($newnames[$tag_id])) { $err_notice .= $newnames[$tag_id] . '-- ' . get_string('namesalreadybeeingused', 'tag') . '<br />'; } else { $tags_names_changed[$tag_id] = $newnames[$tag_id]; } } } $tags_names_updated = tag_update_name($tags_names_changed); //notice to inform what tags had their names effectively updated if ($tags_names_updated) { $notice = implode($tags_names_updated, ', '); $notice .= ' -- ' . get_string('updated', 'tag'); } break; } echo '<br/>';
/** * 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; }
<?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 } }
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null) { log_event(LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY'); $t_bug_table = config_get('mantis_bug_table'); $t_bug_text_table = config_get('mantis_bug_text_table'); $t_bugnote_table = config_get('mantis_bugnote_table'); $t_custom_field_string_table = config_get('mantis_custom_field_string_table'); $t_bugnote_text_table = config_get('mantis_bugnote_text_table'); $t_project_table = config_get('mantis_project_table'); $t_bug_monitor_table = config_get('mantis_bug_monitor_table'); $t_limit_reporters = config_get('limit_reporters'); $t_bug_relationship_table = config_get('mantis_bug_relationship_table'); $t_report_bug_threshold = config_get('report_bug_threshold'); $t_current_user_id = auth_get_current_user_id(); if (null === $p_user_id) { $t_user_id = $t_current_user_id; } else { $t_user_id = $p_user_id; } $c_user_id = db_prepare_int($t_user_id); if (null === $p_project_id) { # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project. $t_project_id = helper_get_current_project(); } else { $t_project_id = $p_project_id; } if ($p_custom_filter === null) { # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports # cookies set by previous version of the code. if ($t_user_id == $t_current_user_id) { $t_filter = current_user_get_bug_filter(); } else { $t_filter = user_get_bug_filter($t_user_id, $t_project_id); } } else { $t_filter = $p_custom_filter; } $t_filter = filter_ensure_valid_filter($t_filter); if (false === $t_filter) { return false; # signify a need to create a cookie #@@@ error instead? } $t_view_type = $t_filter['_view_type']; $t_where_clauses = array("{$t_project_table}.enabled = 1", "{$t_project_table}.id = {$t_bug_table}.project_id"); $t_select_clauses = array("{$t_bug_table}.*"); $t_join_clauses = array(); $t_from_clauses = array(); // normalize the project filtering into an array $t_project_ids if ('simple' == $t_view_type) { log_event(LOG_FILTERING, 'FILTERING: Simple Filter'); $t_project_ids = array($t_project_id); $t_include_sub_projects = true; } else { log_event(LOG_FILTERING, 'FILTERING: Advanced Filter'); if (!is_array($t_filter['project_id'])) { $t_project_ids = array(db_prepare_int($t_filter['project_id'])); } else { $t_project_ids = array_map('db_prepare_int', $t_filter['project_id']); } $t_include_sub_projects = count($t_project_ids) == 1 && $t_project_ids[0] == META_FILTER_CURRENT; } log_event(LOG_FILTERING, 'FILTERING: project_ids = ' . implode(',', $t_project_ids)); log_event(LOG_FILTERING, 'FILTERING: include sub-projects = ' . ($t_include_sub_projects ? '1' : '0')); // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS. // replace META_FILTER_CURRENT with the actualy current project id. $t_all_projects_found = false; $t_new_project_ids = array(); foreach ($t_project_ids as $t_pid) { if ($t_pid == META_FILTER_CURRENT) { $t_pid = $t_project_id; } if ($t_pid == ALL_PROJECTS) { $t_all_projects_found = true; log_event(LOG_FILTERING, 'FILTERING: all projects selected'); break; } // filter out inaccessible projects. if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) { continue; } $t_new_project_ids[] = $t_pid; } $t_projects_query_required = true; if ($t_all_projects_found) { if (user_is_administrator($t_user_id)) { log_event(LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.'); $t_projects_query_required = false; } else { $t_project_ids = user_get_accessible_projects($t_user_id); } } else { $t_project_ids = $t_new_project_ids; } if ($t_projects_query_required) { // expand project ids to include sub-projects if ($t_include_sub_projects) { $t_top_project_ids = $t_project_ids; foreach ($t_top_project_ids as $t_pid) { log_event(LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid); $t_project_ids = array_merge($t_project_ids, user_get_all_accessible_subprojects($t_user_id, $t_pid)); } $t_project_ids = array_unique($t_project_ids); } // if no projects are accessible, then return an empty array. if (count($t_project_ids) == 0) { log_event(LOG_FILTERING, 'FILTERING: no accessible projects'); return array(); } log_event(LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode(',', $t_project_ids)); // this array is to be populated with project ids for which we only want to show public issues. This is due to the limited // access of the current user. $t_public_only_project_ids = array(); // this array is populated with project ids that the current user has full access to. $t_private_and_public_project_ids = array(); $t_access_required_to_view_private_bugs = config_get('private_bug_threshold'); foreach ($t_project_ids as $t_pid) { if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) { $t_private_and_public_project_ids[] = $t_pid; } else { $t_public_only_project_ids[] = $t_pid; } } log_event(LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode(',', $t_private_and_public_project_ids)); log_event(LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode(',', $t_public_only_project_ids)); $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids); if ($t_count_private_and_public_project_ids == 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )"; } else { if ($t_count_private_and_public_project_ids > 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )"; } else { $t_private_and_public_query = null; } } $t_count_public_only_project_ids = count($t_public_only_project_ids); $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )"; if ($t_count_public_only_project_ids == 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )"; } else { if ($t_count_public_only_project_ids > 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )"; } else { $t_public_only_query = null; } } // both queries can't be null, so we either have one of them or both. if ($t_private_and_public_query === null) { $t_project_query = $t_public_only_query; } else { if ($t_public_only_query === null) { $t_project_query = $t_private_and_public_query; } else { $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )"; } } log_event(LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query); array_push($t_where_clauses, $t_project_query); } # view state $t_view_state = db_prepare_int($t_filter['view_state']); if ($t_filter['view_state'] !== META_FILTER_ANY && !is_blank($t_filter['view_state'])) { $t_view_state_query = "({$t_bug_table}.view_state='{$t_view_state}')"; log_event(LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query); array_push($t_where_clauses, $t_view_state_query); } else { log_event(LOG_FILTERING, 'FILTERING: no view_state query'); } # reporter $t_any_found = false; foreach ($t_filter['reporter_id'] as $t_filter_member) { if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['reporter_id']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['reporter_id'] as $t_filter_member) { if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "0"); } else { $c_reporter_id = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_reporter_id) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_reporter_id); } } } if (1 < count($t_clauses)) { $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query); array_push($t_where_clauses, $t_reporter_query); } else { log_event(LOG_FILTERING, 'FILTERING: no reporter query'); } # limit reporter # @@@ thraxisp - access_has_project_level checks greater than or equal to, # this assumed that there aren't any holes above REPORTER where the limit would apply # if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) { $c_reporter_id = $c_user_id; array_push($t_where_clauses, "({$t_bug_table}.reporter_id='{$c_reporter_id}')"); } # handler $t_any_found = false; foreach ($t_filter['handler_id'] as $t_filter_member) { if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['handler_id']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['handler_id'] as $t_filter_member) { if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, 0); } else { $c_handler_id = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_handler_id) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_handler_id); } } } if (1 < count($t_clauses)) { $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query); array_push($t_where_clauses, $t_handler_query); } else { log_event(LOG_FILTERING, 'FILTERING: no handler query'); } # category if (!_filter_is_any($t_filter['show_category'])) { $t_clauses = array(); foreach ($t_filter['show_category'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_category = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_category}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.category in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.category={$t_clauses['0']} )"); } } # severity $t_any_found = false; foreach ($t_filter['show_severity'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_severity']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_severity'] as $t_filter_member) { $c_show_severity = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_severity); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.severity={$t_clauses['0']} )"); } } # show / hide status # take a list of all available statuses then remove the ones that we want hidden, then make sure # the ones we want shown are still available $t_status_arr = explode_enum_string(config_get('status_enum_string')); $t_available_statuses = array(); $t_desired_statuses = array(); foreach ($t_status_arr as $t_this_status) { $t_this_status_arr = explode_enum_arr($t_this_status); $t_available_statuses[] = $t_this_status_arr[0]; } if ('simple' == $t_filter['_view_type']) { # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide $t_any_found = false; $t_this_status = $t_filter['show_status'][0]; $t_this_hide_status = $t_filter['hide_status'][0]; if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) { $t_any_found = true; } if ($t_any_found) { foreach ($t_available_statuses as $t_this_available_status) { if ($t_this_hide_status > $t_this_available_status) { $t_desired_statuses[] = $t_this_available_status; } } } else { $t_desired_statuses[] = $t_this_status; } } else { # advanced filtering: ignore the hide $t_any_found = false; foreach ($t_filter['show_status'] as $t_this_status) { $t_desired_statuses[] = $t_this_status; if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) { $t_any_found = true; } } if ($t_any_found) { $t_desired_statuses = array(); } } if (count($t_desired_statuses) > 0) { $t_clauses = array(); foreach ($t_desired_statuses as $t_filter_member) { $c_show_status = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_status); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.status={$t_clauses['0']} )"); } } # resolution $t_any_found = false; foreach ($t_filter['show_resolution'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_resolution']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_resolution'] as $t_filter_member) { $c_show_resolution = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_resolution); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.resolution={$t_clauses['0']} )"); } } # priority $t_any_found = false; foreach ($t_filter['show_priority'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_priority']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_priority'] as $t_filter_member) { $c_show_priority = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_priority); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.priority={$t_clauses['0']} )"); } } # product build $t_any_found = false; foreach ($t_filter['show_build'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) { $t_any_found = true; } } if (count($t_filter['show_build']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_build'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_build = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_build}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.build={$t_clauses['0']} )"); } } # product version if (!_filter_is_any($t_filter['show_version'])) { $t_clauses = array(); foreach ($t_filter['show_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_version}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.version={$t_clauses['0']} )"); } } # profile if (!_filter_is_any($t_filter['show_profile'])) { $t_clauses = array(); foreach ($t_filter['show_profile'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "0"); } else { $c_show_profile = db_prepare_int($t_filter_member); array_push($t_clauses, "{$c_show_profile}"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.profile_id={$t_clauses['0']} )"); } } # platform if (!_filter_is_any($t_filter['platform'])) { $t_clauses = array(); foreach ($t_filter['platform'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_platform = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_platform}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.platform = {$t_clauses['0']} )"); } } # os if (!_filter_is_any($t_filter['os'])) { $t_clauses = array(); foreach ($t_filter['os'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_os = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_os}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.os = {$t_clauses['0']} )"); } } # os_build if (!_filter_is_any($t_filter['os_build'])) { $t_clauses = array(); foreach ($t_filter['os_build'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_os_build = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_os_build}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.os_build = {$t_clauses['0']} )"); } } # date filter if ('on' == $t_filter['do_filter_by_date'] && is_numeric($t_filter['start_month']) && is_numeric($t_filter['start_day']) && is_numeric($t_filter['start_year']) && is_numeric($t_filter['end_month']) && is_numeric($t_filter['end_day']) && is_numeric($t_filter['end_year'])) { $t_start_string = db_prepare_string($t_filter['start_year'] . "-" . $t_filter['start_month'] . "-" . $t_filter['start_day'] . " 00:00:00"); $t_end_string = db_prepare_string($t_filter['end_year'] . "-" . $t_filter['end_month'] . "-" . $t_filter['end_day'] . " 23:59:59"); array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN '{$t_start_string}' AND '{$t_end_string}' )"); } # fixed in version if (!_filter_is_any($t_filter['fixed_in_version'])) { $t_clauses = array(); foreach ($t_filter['fixed_in_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_fixed_in_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_fixed_in_version}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version={$t_clauses['0']} )"); } } # target version if (!_filter_is_any($t_filter['target_version'])) { $t_clauses = array(); foreach ($t_filter['target_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_target_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_target_version}'"); } } #echo var_dump( $t_clauses ); exit; if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.target_version={$t_clauses['0']} )"); } } # users monitoring a bug $t_any_found = false; foreach ($t_filter['user_monitor'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['user_monitor']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); $t_table_name = 'user_monitor'; array_push($t_from_clauses, $t_bug_monitor_table); array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id"); foreach ($t_filter['user_monitor'] as $t_filter_member) { $c_user_monitor = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_user_monitor) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_user_monitor); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_table_name}.user_id={$t_clauses['0']} )"); } } # bug relationship $t_any_found = false; $c_rel_type = $t_filter['relationship_type']; $c_rel_bug = $t_filter['relationship_bug']; if (-1 == $c_rel_type || 0 == $c_rel_bug) { $t_any_found = true; } if (!$t_any_found) { # use the complementary type $t_comp_type = relationship_get_complementary_type($c_rel_type); $t_clauses = array(); $t_table_name = 'relationship'; array_push($t_from_clauses, $t_bug_relationship_table); array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id"); array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id"); // get reverse relationships array_push($t_clauses, "({$t_table_name}.relationship_type='{$t_comp_type}' AND {$t_table_name}.source_bug_id='{$c_rel_bug}')"); array_push($t_clauses, "({$t_table_name}" . "2.relationship_type='{$c_rel_type}' AND {$t_table_name}" . "2.destination_bug_id='{$c_rel_bug}')"); array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')'); } # tags $c_tag_string = trim($t_filter['tag_string']); if (!is_blank($c_tag_string)) { $t_tags = tag_parse_filters($c_tag_string); if (count($t_tags)) { $t_tags_all = array(); $t_tags_any = array(); $t_tags_none = array(); foreach ($t_tags as $t_tag_row) { switch ($t_tag_row['filter']) { case 1: $t_tags_all[] = $t_tag_row; break; case 0: $t_tags_any[] = $t_tag_row; break; case -1: $t_tags_none[] = $t_tag_row; break; } } if (0 < $t_filter['tag_select'] && tag_exists($t_filter['tag_select'])) { $t_tags_any[] = tag_get($t_filter['tag_select']); } $t_bug_tag_table = config_get('mantis_bug_tag_table'); if (count($t_tags_all)) { $t_clauses = array(); foreach ($t_tags_all as $t_tag_row) { array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )"); } array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')'); } if (count($t_tags_any)) { $t_clauses = array(); foreach ($t_tags_any as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } if (count($t_tags_none)) { $t_clauses = array(); foreach ($t_tags_none as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } } } # custom field filters if (ON == config_get('filter_by_custom_fields')) { # custom field filtering # @@@ At the moment this gets the linked fields relating to the current project # It should get the ones relating to the project in the filter or all projects # if multiple projects. $t_custom_fields = custom_field_get_linked_ids($t_project_id); foreach ($t_custom_fields as $t_cfid) { $t_custom_where_clause = ''; # Ignore all custom filters that are not set, or that are set to '' or "any" $t_any_found = false; foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) { $t_any_found = true; } } if (!isset($t_filter['custom_fields'][$t_cfid])) { $t_any_found = true; } if (!$t_any_found) { $t_def = custom_field_get_definition($t_cfid); $t_table_name = $t_custom_field_string_table . '_' . $t_cfid; # We need to filter each joined table or the result query will explode in dimensions # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields # and only after this process ends (if it is able to) the result query will be filtered # by the WHERE clause and by the DISTINCT clause $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id AND {$t_table_name}.field_id = {$t_cfid} "; if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) { switch ($t_filter['custom_fields'][$t_cfid][0]) { case CUSTOM_FIELD_DATE_ANY: break; case CUSTOM_FIELD_DATE_NONE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)'; break; case CUSTOM_FIELD_DATE_BEFORE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')'; break; case CUSTOM_FIELD_DATE_AFTER: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1); break; default: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2]; break; } } else { array_push($t_join_clauses, $t_cf_join_clause); $t_filter_array = array(); foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { # coerce filter value if selecting META_FILTER_NONE so it will match empty fields $t_filter_member = ''; # but also add those _not_ present in the custom field string table array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})"); } switch ($t_def['type']) { case CUSTOM_FIELD_TYPE_MULTILIST: case CUSTOM_FIELD_TYPE_CHECKBOX: array_push($t_filter_array, db_helper_like("{$t_table_name}.value", '%|' . db_prepare_string($t_filter_member) . '|%')); break; default: array_push($t_filter_array, "{$t_table_name}.value = '" . db_prepare_string($t_filter_member) . "'"); } } $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array); } if (!is_blank($t_custom_where_clause)) { array_push($t_where_clauses, $t_custom_where_clause . ')'); } } } } $t_textsearch_where_clause = ''; $t_textsearch_wherejoin_clause = ''; # Simple Text Search - Thanks to Alan Knowles if (!is_blank($t_filter['search'])) { $c_search = db_prepare_string($t_filter['search']); $c_search_int = db_prepare_int($t_filter['search']); $t_textsearch_where_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . " OR ( {$t_bug_table}.id = '{$c_search_int}' ) )"; $t_textsearch_wherejoin_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_table}.id", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note", "%{$c_search}%") . ' )'; array_push($t_where_clauses, "({$t_bug_text_table}.id = {$t_bug_table}.bug_text_id)"); $t_from_clauses = array($t_bug_text_table, $t_project_table, $t_bug_table); } else { $t_from_clauses = array($t_project_table, $t_bug_table); } $t_select = implode(', ', array_unique($t_select_clauses)); $t_from = 'FROM ' . implode(', ', array_unique($t_from_clauses)); $t_join = implode(' ', $t_join_clauses); if (count($t_where_clauses) > 0) { $t_where = 'WHERE ' . implode(' AND ', $t_where_clauses); } else { $t_where = ''; } # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that # have bugnotes that match the text search if necessary. $t_id_array = array(); for ($i = 0; $i < 2; $i++) { $t_id_where = $t_where; $t_id_join = $t_join; if ($i == 0) { if (!is_blank($t_id_where) && !is_blank($t_textsearch_where_clause)) { $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause; } } else { if (!is_blank($t_textsearch_wherejoin_clause)) { $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause; $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_table} ON {$t_bugnote_table}.bug_id = {$t_bug_table}.id"; $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_text_table} ON {$t_bugnote_text_table}.id = {$t_bugnote_table}.bugnote_text_id"; } } $query = "SELECT DISTINCT {$t_bug_table}.id AS id\r\n\t\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t\t{$t_id_join}\r\n\t\t\t\t\t\t{$t_id_where}"; if ($i == 0 || !is_blank($t_textsearch_wherejoin_clause)) { $result = db_query($query); $row_count = db_num_rows($result); for ($j = 0; $j < $row_count; $j++) { $row = db_fetch_array($result); $t_id_array[] = db_prepare_int($row['id']); } } } $t_id_array = array_unique($t_id_array); # Get the total number of bugs that meet the criteria. $bug_count = count($t_id_array); $rows = array(); if ($bug_count > 0) { $t_where = "WHERE {$t_bug_table}.id in (" . implode(", ", $t_id_array) . ")"; } else { return $rows; } $t_from = 'FROM ' . $t_bug_table; # write the value back in case the caller wants to know $p_bug_count = $bug_count; if (null === $p_per_page) { $p_per_page = (int) $t_filter['per_page']; } else { if (-1 == $p_per_page) { $p_per_page = $bug_count; } } # Guard against silly values of $f_per_page. if (0 == $p_per_page) { $p_per_page = $bug_count; // 0 - means show all } $p_per_page = (int) abs($p_per_page); # Use $bug_count and $p_per_page to determine how many pages # to split this list up into. # For the sake of consistency have at least one page, even if it # is empty. $t_page_count = ceil($bug_count / $p_per_page); if ($t_page_count < 1) { $t_page_count = 1; } # write the value back in case the caller wants to know $p_page_count = $t_page_count; # Make sure $p_page_number isn't past the last page. if ($p_page_number > $t_page_count) { $p_page_number = $t_page_count; } # Make sure $p_page_number isn't before the first page if ($p_page_number < 1) { $p_page_number = 1; } # Now add the rest of the criteria i.e. sorting, limit. # if sort is blank then default the sort and direction. This is to fix the # symptoms of #3953. Note that even if the main problem is fixed, we may # have to keep this code for a while to handle filters saved with this blank field. if (is_blank($t_filter['sort'])) { $t_filter['sort'] = 'last_updated'; $t_filter['dir'] = 'DESC'; } $t_order_array = array(); $t_sort_fields = split(',', $t_filter['sort']); $t_dir_fields = split(',', $t_filter['dir']); if ('on' == $t_filter['sticky_issues'] && NULL !== $p_show_sticky) { $t_order_array[] = "sticky DESC"; } $t_join = ''; for ($i = 0; $i < count($t_sort_fields); $i++) { $c_sort = db_prepare_string($t_sort_fields[$i]); if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) { # if sorting by a custom field if (strpos($c_sort, 'custom_') === 0) { $t_custom_field = substr($c_sort, strlen('custom_')); $t_custom_field_id = custom_field_get_id_from_name($t_custom_field); $t_join .= " LEFT JOIN {$t_custom_field_string_table} ON ( ( {$t_custom_field_string_table}.bug_id = {$t_bug_table}.id ) AND ( {$t_custom_field_string_table}.field_id = {$t_custom_field_id} ) )"; $c_sort = "{$t_custom_field_string_table}.value"; $t_select_clauses[] = "{$t_custom_field_string_table}.value"; } if ('DESC' == $t_dir_fields[$i]) { $c_dir = 'DESC'; } else { $c_dir = 'ASC'; } $t_order_array[] = "{$c_sort} {$c_dir}"; } } # add basic sorting if necessary if (!in_array('last_updated', $t_sort_fields)) { $t_order_array[] = 'last_updated DESC'; } if (!in_array('date_submitted', $t_sort_fields)) { $t_order_array[] = 'date_submitted DESC'; } $t_order = " ORDER BY " . implode(', ', $t_order_array); $t_select = implode(', ', array_unique($t_select_clauses)); $query2 = "SELECT DISTINCT {$t_select}\r\n\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t{$t_join}\r\n\t\t\t\t\t{$t_where}\r\n\t\t\t\t\t{$t_order}"; # Figure out the offset into the db query # # for example page number 1, per page 5: # t_offset = 0 # for example page number 2, per page 5: # t_offset = 5 $c_per_page = db_prepare_int($p_per_page); $c_page_number = db_prepare_int($p_page_number); $t_offset = ($c_page_number - 1) * $c_per_page; # perform query $result2 = db_query($query2, $c_per_page, $t_offset); $row_count = db_num_rows($result2); $t_id_array_lastmod = array(); for ($i = 0; $i < $row_count; $i++) { $row = db_fetch_array($result2); $t_id_array_lastmod[] = db_prepare_int($row['id']); $row['date_submitted'] = db_unixtimestamp($row['date_submitted']); $row['last_updated'] = db_unixtimestamp($row['last_updated']); array_push($rows, $row); } $t_id_array_lastmod = array_unique($t_id_array_lastmod); // paulr: it should be impossible for t_id_array_lastmod to be array(): // that would imply that $t_id_array is null which aborts this function early //if ( count( $t_id_array_lastmod ) > 0 ) { $t_where = "WHERE {$t_bugnote_table}.bug_id in (" . implode(", ", $t_id_array_lastmod) . ")"; $query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM {$t_bugnote_table} {$t_where} GROUP BY bug_id"; # perform query $result3 = db_query($query3); $row_count = db_num_rows($result3); for ($i = 0; $i < $row_count; $i++) { $row = db_fetch_array($result3); $t_stats[$row['bug_id']] = $row; } foreach ($rows as $row) { if (!isset($t_stats[$row['id']])) { bug_cache_database_result($row, false); } else { bug_cache_database_result($row, $t_stats[$row['id']]); } } return $rows; }
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 < $f_tag_select && tag_exists($f_tag_select)) { $t_tags_attach[] = tag_get($f_tag_select); } // failed to attach at least one tag if (count($t_tags_failed) > 0) { html_page_top(lang_get('tag_attach_long') . ' ' . bug_format_summary($f_bug_id, SUMMARY_CAPTION)); ?> <br/> <table class="width75"> <tr class="row-category"> <td colspan="2"><?php echo lang_get('tag_attach_failed'); ?> </td> </tr> <tr class="spacer"><td colspan="2"></td></tr>
function save_tags($tag1, $tag2, $tag3, $uid, $lid, $cid) { global $connection; $save = 0; // First checking if the tags already exist in the respective tables //category table $ctagarray = array(); $utagarray = array(); $i = 0; $j = 0; $tagscore = 0; if (!empty($tag1) && strlen($tag1) >= 3) { if (tag_exists($tag1, $cid, 0, "category") == 0) { $ctagarray[$i] = $tag1; $i += 1; } if (tag_exists($tag1, 0, $uid, "user") == 0) { $utagarray[$j] = $tag1; $j += 1; } } if (!empty($tag2 && strlen($tag2) >= 3)) { if (tag_exists($tag2, $cid, 0, "category") == 0) { $ctagarray[$i] = $tag2; $i += 1; } if (tag_exists($tag2, 0, $uid, "user") == 0) { $utagarray[$j] = $tag2; $j += 1; } } if (!empty($tag3 && strlen($tag3) >= 3)) { if (tag_exists($tag3, $cid, 0, "category") == 0) { $ctagarray[$i] = $tag3; $i += 1; } if (tag_exists($tag3, 0, $uid, "user") == 0) { $utagarray[$j] = $tag3; $j += 1; } } //print_r($ctagarray); //print_r($utagarray); //updating to category table if (!empty($ctagarray)) { //first fetch the existing tag string for this category and then append $query1 = "SELECT tags from category WHERE cid={$cid}"; $result1 = mysqli_query($connection, $query1); confirm_query($result1); $row = mysqli_fetch_assoc($result1); if (!empty($row['tags'])) { $ctagstring = $row['tags'] . "," . implode(",", $ctagarray); } else { $ctagstring = implode(",", $ctagarray); } $query2 = "UPDATE category SET tags ='{$ctagstring}' WHERE cid={$cid}"; // echo "<br>".$query2; $result2 = mysqli_query($connection, $query2); confirm_query($result2); $save = 1; } if (!empty($utagarray)) { //first fetch teh existing tag cloud string for this user and then append $query3 = "SELECT tag_cloud from user WHERE uid={$uid}"; $result3 = mysqli_query($connection, $query3); confirm_query($result3); $row = mysqli_fetch_assoc($result3); if (!empty($row['tag_cloud'])) { $utagstring = $row['tag_cloud'] . "," . implode(",", $utagarray); } else { $utagstring = implode(",", $utagarray); } $query4 = "UPDATE user SET tag_cloud ='{$utagstring}' WHERE uid={$uid}"; // echo "<br>".$query4; $result4 = mysqli_query($connection, $query4); confirm_query($result4); //update the user tag score $tagarray = explode(",", $utagstring); $tagscore = count($tagarray); $query5 = "UPDATE user_category_popularity SET u_tag_score = {$tagscore} WHERE uid = {$uid}"; // echo "scoring..".$query5; $result5 = mysqli_query($connection, $query5); confirm_query($result5); $save = 1; } if ($save == 1) { return "<br/><span class=\"label label-success\" style=\"font-size: 1.5em;\">Your tags are saved!</span>"; } //need to update 3 tables after //user_category_popularity }
$runner_id = clean_chaser_id($_POST['runner_id']); $loc_lat = $_POST['latitude']; $loc_long = $_POST['longitude']; $loc_addr = $_POST['address']; if (empty($loc_lat)) { $loc_lat = 0; } if (empty($loc_long)) { $loc_long = 0; } print '<p><span style="color:red;">Chaser ' . get_runner_name($tagger_id) . '</span> tagged <span style="color:blue;">Runner ' . get_runner_name($runner_id) . '</span> at ' . $loc_lat . ',' . $loc_long . '.<br />'; if (is_valid_runner($tagger_id) && is_valid_runner($runner_id)) { if (register_tag($tagger_id, $runner_id, $loc_lat, $loc_long, $loc_addr)) { print '<div style="font-size:14em;color:green;text-align: center;">✓</div><h3>Your tag is checked in!</h3>'; } else { if (tag_exists($tagger_id, $runner_id)) { print '<h3>You\'ve already tagged this runner!</h3><div style="font-size:14em;color:red;text-align: center;">X</div>'; } else { print '<h3>Oops, something is broken</h3><div style="font-size:14em;color:red;text-align: center;">X</div>'; } } } else { if (DEBUG) { print '<h3>Invalid tagger or runner</h3><div style="font-size:14em;color:red;text-align: center;">X</div>'; } } } else { ?> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script> navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
function discussion_create($options) { /* Required info title author discussion_type category (A tag label) Optional info timestamp owner (Mainly for group-discussions where the group owns the discussion and the user id is stored as author) handle (This will be generated from the title if omitted) parent_discussion tags (Must be an array) desired_quality (range -1 to +1) */ $category = tag_exists($options['category']); if ($category['status'] != 'exists') { $category['id'] = 0; } else { $options['tags'][] = $options['category']; } $handle = isset($options['handle']) ? $options['handle'] : discussions_create_handle($options['title']); $timestamp = isset($options['timestamp']) ? $options['timestamp'] : time(); $title = htmlspecialchars(shorten_string($options['title'])); $query = 'INSERT INTO discussions (timestamp, author, owner, title, handle, discussion_type, parent_discussion, category_tag, desired_quality)'; $query .= ' VALUES("' . $timestamp . '", "' . $options['author'] . '", "' . $options['owner'] . '", "' . $options['title'] . '"'; $query .= ', "' . $handle . '", "' . $options['discussion_type'] . '", "' . $options['parent_discussion'] . '", "' . $category['id'] . '", "' . $options['desired_quality'] . '")'; mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__)); $discussion_id = mysql_insert_id(); tag_set_wrap(array('tag_label' => $options['tags'], 'object_type' => 'discussion', 'item_id' => $discussion_id)); unset($return); $return['id'] = $discussion_id; $return['handle'] = $handle; $return['category_handle'] = $category['handle']; return $return; }
function create_hashtag($dbh, $tagname) { $tagname = pg_escape_string($tagname); // check whether the tag exists $exists_tag = tag_exists($dbh, $tagname); if ($exists_tag["status"] == 0 || $exists_tag["exists"]) { return array("status" => 0); } $sql = pg_prepare($dbh, "create_hashtag", 'INSERT INTO hashtag VALUES ($1)'); $sql = pg_execute($dbh, "create_hashtag", array($tagname)); if ($sql) { return array("status" => 1); } else { return array("status" => 0); } }
/** * print tag fields * @return void */ function print_filter_tag_string() { if (!access_has_global_level(config_get('tag_view_threshold'))) { return; } global $g_filter; $t_tag_string = $g_filter[FILTER_PROPERTY_TAG_STRING]; if ($g_filter[FILTER_PROPERTY_TAG_SELECT] != 0 && tag_exists($g_filter[FILTER_PROPERTY_TAG_SELECT])) { $t_tag_string .= is_blank($t_tag_string) ? '' : config_get('tag_separator'); $t_tag_string .= tag_get_field($g_filter[FILTER_PROPERTY_TAG_SELECT], 'name'); } ?> <input type="hidden" id="tag_separator" value="<?php echo config_get('tag_separator'); ?> " /> <input type="text" name="<?php echo FILTER_PROPERTY_TAG_STRING; ?> " id="<?php echo FILTER_PROPERTY_TAG_STRING; ?> " size="40" value="<?php echo string_attribute($t_tag_string); ?> " /> <select <?php echo helper_get_tab_index(); ?> name="<?php echo FILTER_PROPERTY_TAG_SELECT; ?> " id="<?php echo FILTER_PROPERTY_TAG_SELECT; ?> "> <?php print_tag_option_list(); ?> </select> <?php }
/** * Function that updates tags names. * Updates only if the new name suggested for a tag doesn´t exist already. * * @param Array $tags_names_changed array of new tag names indexed by tag ids. * @return Array array of tags names that were effectively updated, indexed by tag ids. */ function tag_update_name($tags_names_changed) { $tags_names_updated = array(); foreach ($tags_names_changed as $id => $newname) { $norm_newname = tag_normalize($newname); if (!tag_exists($norm_newname) && is_tag_name_valid($norm_newname)) { $tag = tag_by_id($id); $tags_names_updated[$id] = $tag->name; // rawname keeps the original casing of the string $tag->rawname = tag_normalize($newname, false); // name lowercases the string $tag->name = $norm_newname; $tag->timemodified = time(); update_record('tag', $tag); } } return $tags_names_updated; }