function get_tag_id($tag) { bb_log_deprecated('function', __FUNCTION__, 'bb_get_tag_id'); return bb_get_tag_id($tag); }
function generate_post_sql($_part_of_topic_query = false) { global $bbdb; $q =& $this->query_vars; $distinct = ''; $sql_calc_found_rows = 'found_rows' === $q['count'] ? 'SQL_CALC_FOUND_ROWS' : ''; // unfiltered $fields = 'p.*'; $index_hint = ''; $join = ''; $where = ''; $group_by = ''; $having = ''; $order_by = ''; $topic_where = ''; $topic_queries = array('topic_author_id', 'topic_author', 'topic_status', 'post_count', 'tag_count', 'started', 'updated', 'open', 'sticky', 'meta_key', 'meta_value', 'topic_title'); if (!$_part_of_topic_query && array_diff($topic_queries, $this->not_set)) { $join .= " JOIN {$bbdb->topics} as t ON ( t.topic_id = p.topic_id )"; $topic_where = $this->generate_topic_sql(true); } if (!$_part_of_topic_query) { if ($q['post_id']) { $where .= $this->parse_value('p.post_id', $q['post_id']); } if ($q['topic_id']) { $where .= $this->parse_value('p.topic_id', $q['topic_id']); } elseif ($q['topic']) { if (!($q['topic_id'] = bb_get_id_from_slug('topic', $q['topic']))) { $this->error('query_var:topic', 'No topic by that name'); } $where .= " AND p.topic_id = " . $q['topic_id']; } if ($q['forum_id']) { $where .= $this->parse_value('p.forum_id', $q['forum_id']); } elseif ($q['forum']) { if (!($q['forum_id'] = bb_get_id_from_slug('forum', $q['forum']))) { $this->error('query_var:forum', 'No forum by that name'); } $where .= " AND p.forum_id = " . $q['forum_id']; } if ($q['tag'] && !is_int($q['tag_id'])) { $q['tag_id'] = (int) bb_get_tag_id($q['tag']); } if (is_numeric($q['tag_id'])) { $join .= " JOIN `{$bbdb->term_relationships}` AS tr ON ( p.`topic_id` = tr.`object_id` AND tr.`term_taxonomy_id` = {$q['tag_id']} )"; } if (is_numeric($q['favorites']) && ($f_user = bb_get_user($q['favorites']))) { $where .= $this->parse_value('p.topic_id', $f_user->favorites); } } // !_part_of_topic_query if ($q['post_text']) { $where .= ' AND ' . $this->generate_post_text_sql($q['post_text']); if ($this->match_query) { $fields .= ", {$this->match_query} AS search_score"; if (!$q['order_by']) { $q['order_by'] = 'search_score'; } } else { $fields .= ', 0 AS search_score'; } } if ($q['posted']) { $where .= $this->date('p.post_time', $q['posted']); } if ($q['post_author_id']) { $where .= $this->parse_value('p.poster_id', $q['post_author_id']); } elseif ($q['post_author']) { $user = bb_get_user($q['post_author'], array('by' => 'login')); if (!($q['post_author_id'] = (int) $user->ID)) { $this->error('query_var:user', 'No user by that name'); } $where .= " AND p.poster_id = {$q['post_author_id']}"; } if (!$q['post_status']) { $where .= " AND p.post_status = '0'"; } elseif (false === strpos($q['post_status'], 'all')) { $stati = array('normal' => 0, 'deleted' => 1); $q['post_status'] = str_replace(array_keys($stati), array_values($stati), $q['post_status']); $where .= $this->parse_value('p.post_status', $q['post_status']); } if (false !== $q['position']) { $where .= $this->parse_value('p.post_position', $q['position']); } if (false !== $q['poster_ip']) { $where .= " AND poster_ip = '" . $q['poster_ip'] . "'"; } // Just getting post part for inclusion in topic query if ($_part_of_topic_query) { return $where; } $where .= $topic_where; if ($where) { // Get rid of initial " AND " (this is pre-filters) $where = substr($where, 5); } if ($q['index_hint']) { $index_hint = $q['index_hint']; } if ($q['order_by']) { $order_by = $q['order_by']; } else { $order_by = 'p.post_time'; } $bits = compact(array('distinct', 'sql_calc_found_rows', 'fields', 'index_hint', 'join', 'where', 'group_by', 'having', 'order_by')); $this->request = $this->_filter_sql($bits, "{$bbdb->posts} AS p"); return $this->request; }
function bb_get_tag_remove_link($args = null) { if (is_scalar($args) || is_object($args)) { $args = array('tag' => $args); } $defaults = array('tag' => 0, 'topic' => 0, 'list_id' => 'tags-list'); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); if (is_object($tag) && isset($tag->tag_id)) { } elseif (!($tag = bb_get_tag(bb_get_tag_id($tag)))) { return false; } if (!($topic = get_topic(get_topic_id($topic)))) { return false; } if (!bb_current_user_can('edit_tag_by_on', $tag->user_id, $topic->topic_id)) { return false; } $url = bb_get_uri('tag-remove.php', array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $topic->topic_id)); $url = esc_url(bb_nonce_url($url, 'remove-tag_' . $tag->tag_id . '|' . $topic->topic_id)); $title = esc_attr__('Remove this tag'); $list_id = esc_attr($list_id); return "[<a href='{$url}' class='delete:{$list_id}:tag-{$tag->tag_id}_{$tag->user_id}' title='{$title}'>×</a>]"; }