/** * Pulling BBPress search into a function * * @Param: Search string * @return: An array which contains the BBPress results. * @author: pete kuhn * @version 1.0 **/ function forums_search_results($q) { global $bbdb; $bb_query_form = new BB_Query_Form(); if ($q = stripslashes($q)) { add_filter('bb_recent_search_fields', create_function('$f', 'return $f . ", MAX(post_time) AS post_time";')); add_filter('bb_recent_search_group_by', create_function('', 'return "t.topic_id";')); $bb_query_form->BB_Query_Form('post', array(), array('per_page' => 5, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_recent_search'); $recent = $bb_query_form->results; $bb_query_form->BB_Query_Form('topic', array('search' => $q), array('post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_relevant_search'); $relevant = $bb_query_form->results; $q = $bb_query_form->get('search'); } do_action('do_search', $q); // Cache topics if ($recent) { $topic_ids = array(); foreach ($recent as $bb_post) { $topic_ids[] = (int) $bb_post->topic_id; $bb_post_cache[$bb_post->post_id] = $bb_post; } $topic_ids = join($topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN ({$topic_ids})")) { $topics = bb_append_meta($topics, 'topic'); } } return $recent; }
function get_topic($id, $cache = true) { global $bbdb; if (!is_numeric($id)) { list($slug, $sql) = bb_get_sql_from_slug('topic', $id); $id = wp_cache_get($slug, 'bb_topic_slug'); } // not else if (is_numeric($id)) { $id = (int) $id; $sql = "topic_id = {$id}"; } if (0 === $id || !$sql) { return false; } // &= not =& $cache &= 'AND topic_status = 0' == ($where = apply_filters('get_topic_where', 'AND topic_status = 0')); if (($cache || !$where) && is_numeric($id) && false !== ($topic = wp_cache_get($id, 'bb_topic'))) { return $topic; } // $where is NOT bbdb:prepared $topic = $bbdb->get_row("SELECT * FROM {$bbdb->topics} WHERE {$sql} {$where}"); $topic = bb_append_meta($topic, 'topic'); if ($cache) { wp_cache_set($topic->topic_id, $topic, 'bb_topic'); wp_cache_add($topic->topic_slug, $topic->topic_id, 'bb_topic_slug'); } return $topic; }
} $bb_query_form = new BB_Query_Form(); if ($q = stripslashes($q)) { $per_page = ceil((int) bb_get_option('page_topics') / 2); /* Recent */ add_filter('bb_recent_search_fields', create_function('$f', 'return $f . ", MAX(post_time) AS post_time";')); add_filter('bb_recent_search_group_by', create_function('', 'return "t.topic_id";')); $bb_query_form->BB_Query_Form('post', array(), array('order_by' => 'p.post_time', 'count' => true, 'per_page' => $per_page, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_recent_search'); $recent = $bb_query_form->results; $recent_count = $recent ? $bb_query_form->found_rows : 0; /* Relevant */ $bb_query_form->BB_Query_Form('topic', array('search' => $q), array('per_page' => $per_page, 'count' => true, 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_relevant_search'); $relevant = $bb_query_form->results; $relevant_count = $relevant ? $bb_query_form->found_rows : 0; $search_count = max($recent_count, $relevant_count); $q = $bb_query_form->get('search'); } do_action('do_search', $q); // Cache topics // NOT bbdb::prepared if ($recent) { $topic_ids = array(); foreach ($recent as $bb_post) { $topic_ids[] = (int) $bb_post->topic_id; } $topic_ids = join($topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN ({$topic_ids})")) { $topics = bb_append_meta($topics, 'topic'); } } bb_load_template('search.php', array('q', 'recent', 'relevant', 'per_page', 'search_count'), $q);
function &query() { global $bbdb; if ($args = func_get_args()) { call_user_func_array(array(&$this, 'init'), $args); } if (!$this->generate_query()) { return; } do_action_ref_array('bb_query', array(&$this)); $key = md5($this->request); if (false === ($cached_ids = wp_cache_get($key, 'bb_query'))) { if ('post' == $this->type) { $this->results = bb_cache_posts($this->request, $this->query_vars['post_id_only']); // This always appends meta $_the_id = 'post_id'; $this->query_vars['append_meta'] = false; } else { $this->results = $bbdb->get_results($this->request); $_the_id = 'topic_id'; } $cached_ids = array(); if (is_array($this->results)) { foreach ($this->results as $object) { $cached_ids[] = $object->{$_the_id}; } } wp_cache_set($key, $cached_ids, 'bb_query'); } else { if ('post' == $this->type) { $_query_ids = array(); $_cached_posts = array(); foreach ($cached_ids as $_cached_id) { if (false !== ($_post = wp_cache_get($_cached_id, 'bb_post'))) { $_cached_posts[$_post->post_id] = $_post; } else { $_query_ids[] = $_cached_id; } } if (count($_query_ids)) { $_query_ids = join(',', array_map('intval', $_query_ids)); $results = $bbdb->get_results("SELECT * FROM {$bbdb->posts} WHERE post_id IN({$_query_ids})"); $results = array_merge($results, $_cached_posts); } else { $results = $_cached_posts; } $_the_id = 'post_id'; } else { $_query_ids = array(); $_cached_topics = array(); foreach ($cached_ids as $_cached_id) { if (false !== ($_topic = wp_cache_get($_cached_id, 'bb_topic'))) { $_cached_topics[$_topic->topic_id] = $_topic; } else { $_query_ids[] = $_cached_id; } } if (count($_query_ids)) { $_query_ids = join(',', array_map('intval', $_query_ids)); $results = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN({$_query_ids})"); $results = array_merge($results, $_cached_topics); } else { $results = $_cached_topics; } $_the_id = 'topic_id'; } $this->results = array(); $trans = array(); foreach ($results as $object) { $trans[$object->{$_the_id}] = $object; } foreach ($cached_ids as $cached_id) { $this->results[] = $trans[$cached_id]; } } $this->count = count($this->results); if (false === $this->found_rows && $this->query_vars['count']) { // handles FOUND_ROWS() or COUNT(*) $this->found_rows = bb_count_last_query($this->request); } if ('post' == $this->type) { if ($this->query_vars['append_meta']) { $this->results = bb_append_meta($this->results, 'post'); } if ($this->query_vars['cache_users']) { bb_post_author_cache($this->results); } if ($this->query_vars['cache_topics']) { bb_cache_post_topics($this->results); } } else { if ($this->query_vars['append_meta']) { $this->results = bb_append_meta($this->results, 'topic'); } } return $this->results; }
function bb_user_search($args = '') { global $bbdb, $bb_last_countable_query; if ($args && is_string($args) && false === strpos($args, '=')) { $args = array('query' => $args); } $defaults = array('query' => '', 'append_meta' => true, 'user_login' => true, 'display_name' => true, 'user_nicename' => false, 'user_url' => true, 'user_email' => false, 'user_meta' => false, 'users_per_page' => false, 'page' => false, 'roles' => false); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); $query = trim($query); if ($query && strlen(preg_replace('/[^a-z0-9]/i', '', $query)) < 3) { return new nxt_Error('invalid-query', __('Your search term was too short')); } $query = $bbdb->escape($query); if (!$page) { $page = $GLOBALS['page']; } $page = (int) $page; $limit = 0 < (int) $users_per_page ? (int) $users_per_page : bb_get_option('page_topics'); if (1 < $page) { $limit = $limit * ($page - 1) . ", {$limit}"; } $likeit = preg_replace('/\\s+/', '%', like_escape($query)); $fields = array(); foreach (array('user_login', 'display_name', 'user_nicename', 'user_url', 'user_email') as $field) { if (${$field}) { $fields[] = $field; } } if ($roles) { $roles = (array) $roles; } if ($roles && !empty($roles) && false === ($role_user_ids = apply_filters('bb_user_search_role_user_ids', false, $roles, $args))) { $role_meta_key = $bbdb->escape($bbdb->prefix . 'capabilities'); $role_sql_terms = array(); foreach ($roles as $role) { $role_sql_terms[] = "`meta_value` LIKE '%" . $bbdb->escape(like_escape($role)) . "%'"; } $role_sql_terms = join(' OR ', $role_sql_terms); $role_sql = "SELECT `user_id` FROM `{$bbdb->usermeta}` WHERE `meta_key` = '{$role_meta_key}' AND ({$role_sql_terms});"; $role_user_ids = $bbdb->get_col($role_sql, 0); if (is_nxt_error($role_user_ids)) { return false; } } if (is_array($role_user_ids) && empty($role_user_ids)) { return false; } if ($query && $user_meta && false === ($meta_user_ids = apply_filters('bb_user_search_meta_user_ids', false, $args))) { $meta_sql = "SELECT `user_id` FROM `{$bbdb->usermeta}` WHERE `meta_value` LIKE ('%{$likeit}%')"; if (empty($fields)) { $meta_sql .= " LIMIT {$limit}"; } $meta_user_ids = $bbdb->get_col($meta_sql, 0); if (is_nxt_error($meta_user_ids)) { $meta_user_ids = false; } } $user_ids = array(); if ($role_user_ids && $meta_user_ids) { $user_ids = array_intersect((array) $role_user_ids, (array) $meta_user_ids); } elseif ($role_user_ids) { $user_ids = (array) $role_user_ids; } elseif ($meta_user_ids) { $user_ids = (array) $meta_user_ids; } $sql = "SELECT * FROM {$bbdb->users}"; $sql_terms = array(); if ($query && count($fields)) { foreach ($fields as $field) { $sql_terms[] = "{$field} LIKE ('%{$likeit}%')"; } } $user_ids_sql = ''; if ($user_ids) { $user_ids_sql = "AND ID IN (" . join(',', $user_ids) . ")"; } if ($query && empty($sql_terms)) { return new nxt_Error('invalid-query', __('Your query parameters are invalid')); } if (count($sql_terms) || count($user_ids)) { $sql .= ' WHERE '; } if (count($sql_terms)) { $sql .= '(' . implode(' OR ', $sql_terms) . ')'; } if (count($sql_terms) && count($user_ids)) { $sql .= ' AND '; } if (count($user_ids)) { $sql .= '`ID` IN (' . join(',', $user_ids) . ')'; } $sql .= " ORDER BY user_login LIMIT {$limit}"; $bb_last_countable_query = $sql; do_action('bb_user_search', $sql, $args); if (($users = $bbdb->get_results($sql)) && $append_meta) { return bb_append_meta($users, 'user'); } return $users ? $users : false; }
function append_user_meta($user) { bb_log_deprecated('class::function', __CLASS__ . '::' . __FUNCTION__, 'bb_append_meta'); return bb_append_meta($user, 'user'); }
function bb_cache_post_topics($posts) { global $bbdb; if (!$posts) { return; } $topic_ids = array(); foreach ($posts as $post) { if (false === nxt_cache_get($post->topic_id, 'bb_topic')) { $topic_ids[] = (int) $post->topic_id; } } if (!$topic_ids) { return; } sort($topic_ids); $topic_ids = join(',', $topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN({$topic_ids})")) { bb_append_meta($topics, 'topic'); } }
function best_answer_views($view) { global $bbdb, $topics, $view_count, $page; if ($view == 'best-answer' || $view == 'no-best-answer') { $limit = bb_get_option('page_topics'); $offset = ($page - 1) * $limit; $where = apply_filters('get_latest_topics_where', "WHERE topic_status=0 "); if ($view == 'best-answer') { if (defined('BACKPRESS_PATH')) { $query = " FROM {$bbdb->topics} AS t1 \r\n\t\t\tLEFT JOIN {$bbdb->meta} as t2 ON t1.topic_id=t2.object_id \r\n\t\t\t{$where} AND object_type='bb_topic' AND meta_key='best_answer' "; } else { $query = " FROM {$bbdb->topics} AS t1 \r\n\t\t\tLEFT JOIN {$bbdb->topicmeta} as t2 ON t1.topic_id=t2.topic_id \r\n\t\t\t{$where} AND meta_key='best_answer' "; } } else { if (defined('BACKPRESS_PATH')) { $query = " FROM {$bbdb->topics} {$where} AND topic_id NOT IN \r\n\t\t\t(SELECT object_id as topic_id FROM {$bbdb->meta} WHERE object_type='bb_topic' AND meta_key='best_answer') "; } else { $query = " FROM {$bbdb->topics} {$where} AND topic_id NOT IN \t\r\n\t\t\t(SELECT topic_id FROM {$bbdb->topicmeta} WHERE meta_key='best_answer') "; } } $restrict = " ORDER BY topic_time DESC LIMIT {$limit} OFFSET {$offset}"; $view_count = $bbdb->get_var("SELECT count(*) " . $query); $topics = $bbdb->get_results("SELECT * " . $query . $restrict); $topics = bb_append_meta($topics, 'topic'); bb_cache_last_posts(); } }
function nm_get_all_forums_hot_topics($limit) { global $bbdb, $topics, $view_count, $page; $view = 'most-posts'; $sort = "DESC"; $limit = '5'; $where = apply_filters('get_latest_topics_where', ''); $query = " FROM {$bbdb->topics} WHERE topic_status=0 {$where}"; $restrict = " ORDER BY cast(topic_posts as UNSIGNED) {$sort} LIMIT {$limit}"; $view_count = $bbdb->get_var("SELECT count(*) " . $query); // bb_count_last_query(); // count($topics); $hot_topics = $bbdb->get_results("SELECT * " . $query . $restrict); $hot_topics = bb_append_meta($hot_topics, 'topic'); if ($hot_topics) { foreach ($hot_topics as $topic) { $hot_topics_content .= '<div class="arrowLink"><li><a href="' . get_bloginfo("url") . '/forums/topic.php?id=' . $topic->topic_id . '" style="padding-left:9px;">' . nm_trim_topic_title($topic->topic_title, 20) . '</a></div></li>'; } } return $hot_topics_content; }
function bb_get_forum($id) { global $bbdb; if (!is_numeric($id)) { list($slug, $sql) = bb_get_sql_from_slug('forum', $id); $id = wp_cache_get($slug, 'bb_forum_slug'); } // not else if (is_numeric($id)) { $id = (int) $id; $sql = "forum_id = {$id}"; } if (0 === $id || !$sql) { return false; } // $where is NOT bbdb:prepared if ($where = apply_filters('get_forum_where', '')) { $forum = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->forums} WHERE forum_id = %d", $id) . " {$where}"); return bb_append_meta($forum, 'forum'); } if (is_numeric($id) && false !== ($forum = wp_cache_get($id, 'bb_forum'))) { return $forum; } $forum = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->forums} WHERE {$sql}", $id)); $forum = bb_append_meta($forum, 'forum'); wp_cache_set($forum->forum_id, $forum, 'bb_forum'); wp_cache_add($forum->forum_slug, $forum, 'bb_forum_slug'); return $forum; }
function mass_edit() { if (!bb_current_user_can('browse_deleted')) { die(__("Now how'd you get here? And what did you think you'd be doing?")); } add_action('bb_get_option_page_topics', 'mass_edit_topic_limit', 250); global $bbdb, $bb_post_cache, $bb_user_cache, $bb_posts, $bb_post, $page, $mass_edit_options; if (isset($_GET['mass_edit_reset'])) { bb_delete_option('mass_edit_options'); wp_redirect(remove_query_arg(array('mass_edit_options', 'mass_edit_reset'))); } if (!empty($_POST['mass_edit_save_options'])) { $mass_edit_options['mass_edit_columns'] = implode(",", array_unique(array_map('trim', explode(",", strtolower(stripslashes($_POST['mass_edit_columns'] . ", checkbox , excerpt , name , meta , actions")))))); $mass_edit_options['mass_edit_css'] = stripslashes($_POST['mass_edit_css']); bb_update_option('mass_edit_options', $mass_edit_options); wp_redirect(remove_query_arg(array('mass_edit_options', 'mass_edit_reset'))); // may not work since headers are already sent } echo '<div style="text-align:right;margin-bottom:-1.5em;">'; if (isset($_GET['mass_edit_options'])) { echo '[ <a href="' . bb_get_admin_tab_link("mass_edit") . '&mass_edit_reset=1">Reset To Defaults</a> ]'; } else { echo '[ <a href="' . bb_get_admin_tab_link("mass_edit") . '&mass_edit_options=1">Settings</a> ]'; } echo '</div>'; echo "<h2><a style='color:black;border:0;text-decoration:none;' href='" . bb_get_admin_tab_link("mass_edit") . "'>" . __('Mass Edit') . "</a></h2>"; if (!isset($mass_edit_options)) { $mass_edit_options = bb_get_option('mass_edit_options'); } if (!isset($mass_edit_options['mass_edit_columns']) || is_array($mass_edit_options['mass_edit_columns'])) { $mass_edit_options['mass_edit_columns'] = "checkbox , excerpt , name , meta , actions"; bb_update_option('mass_edit_options', $mass_edit_options); } $mass_edit_columns = explode(",", strtolower($mass_edit_options['mass_edit_columns'])); array_walk($mass_edit_columns, create_function('&$arr', '$arr=trim($arr);')); if (isset($_GET['mass_edit_options'])) { ?> <form action="<?php echo bb_get_admin_tab_link("mass_edit"); ?> " method="post" id="mass-edit-options"> <fieldset><legend><strong>Mass Edit Column Order</strong> - default: checkbox , excerpt , name , meta , actions</legend> <input name="mass_edit_columns" id="mass_edit_columns" type="text" size="50" value="<?php echo $mass_edit_options['mass_edit_columns']; ?> " /> <span style="padding-left:2em;" class=submit><input class=submit type="submit" name="mass_edit_save_options" value="<?php _e('Save Options'); ?> »" /></span> </fieldset> <fieldset><legend><b>Mass Edit CSS</b></legend> <textarea name="mass_edit_css" id="mass_edit_css" cols="100" rows="10"><?php echo $mass_edit_options['mass_edit_css']; ?> </textarea> </fieldset> </form> <br clear=both /> <hr /> <?php } /* add_filter( 'get_topic_where', 'no_where' ); add_filter( 'get_topic_link', 'bb_make_link_view_all' ); $bb_post_query = new BB_Query_Form( 'post',array( 'post_status' => 0, 'count' => true )); $bb_posts =& $bb_post_query->results; $total = $bb_post_query->found_rows; */ if (!empty($_POST['mass_edit_delete_posts'])) { bb_check_admin_referer('mass-edit-bulk-posts'); $i = 0; $bbdb->hide_errors(); // bbPress still has some db function issues with topic delete/undelete foreach ($_POST['mass_edit_delete_posts'] as $bb_post_id) { // Check the permissions on each $bb_post_id = (int) $bb_post_id; // $bb_post_id = $bbdb->get_var("SELECT post_id FROM $bbdb->posts WHERE post_id = $bb_post"); // $authordata = bb_get_usermeta( $bbdb->get_var("SELECT poster_id FROM $bbdb->posts WHERE ID = $bb_post_id") ); if (bb_current_user_can('delete_posts', $bb_post_id)) { if (!empty($_POST['mass_edit_spam_button'])) { bb_delete_post($bb_post_id, 2); } if (!empty($_POST['mass_edit_delete_button'])) { bb_delete_post($bb_post_id, 1); } if (!empty($_POST['mass_edit_undelete_button'])) { bb_delete_post($bb_post_id, 0); } ++$i; } } $bbdb->show_errors(); // bbPress still has some db function issues with topic delete/undelete // $bbdb->flush(); // global $bb_cache,$bb_post_cache, $bb_topic_cache; unset($bb_cache); unset($bb_post_cache); unset($bb_topic_cache); echo '<div id="message" class="updated fade" style="clear:both;"><p>'; if (!empty($_POST['mass_edit_spam_button'])) { printf(__('%s posts marked as spam.'), $i); } if (!empty($_POST['mass_edit_delete_button'])) { printf(__('%s posts deleted.'), $i); } if (!empty($_POST['mass_edit_undelete_button'])) { printf(__('%s posts undeleted.'), $i); } echo '</p></div>'; } if (isset($_GET['post_text'])) { $post_text = substr($bbdb->escape($_GET['post_text']), 0, 100); } else { $post_text = ""; } if (isset($_GET['post_author'])) { $post_author = substr($bbdb->escape($_GET['post_author']), 0, 30); } else { $post_author = ""; } if (isset($_GET['post_status'])) { $post_status = substr($bbdb->escape($_GET['post_status']), 0, 3); } else { $post_status = "0"; } if (isset($_GET['post_order'])) { $post_order = $_GET['post_order'] == "ASC" ? "ASC" : "DESC"; } else { $post_order = "DESC"; } if (isset($_GET['exact_match'])) { $exact_match = intval($_GET['exact_match']); } else { $exact_match = 0; } if (isset($_GET['per_page'])) { $per_page = intval(substr($bbdb->escape($_GET['per_page']), 0, 3)); } else { $per_page = "20"; } $offset = (intval($page) - 1) * $per_page; // if (isset($_GET['page'])) {} else {$offset = 0;} $query = " FROM {$bbdb->posts} "; if ($post_text || $post_author || $post_status != "all") { $query .= " WHERE "; } if ($post_text) { if ($exact_match) { $query .= " (post_text REGEXP '[[:<:]]" . $post_text . "[[:>:]]'\tOR poster_ip = '" . $post_text . "') "; } else { $query .= " (post_text LIKE '%{$post_text}%' OR poster_ip LIKE '%{$post_text}%' ) "; } } if ($post_author) { $authors = "SELECT ID FROM {$bbdb->users} WHERE "; $authors .= $exact_match ? " (user_login REGEXP '[[:<:]]" . $post_author . "[[:>:]]') " : " (user_login LIKE '%{$post_author}%') "; $authors .= " LIMIT 99"; if ($authors = $bbdb->get_results($authors)) { if (is_array($authors)) { foreach ($authors as $key => $value) { $trans[] = $value->ID; } $authors = join(',', $trans); } } else { $authors = "-1"; } $query .= ($post_text ? " AND " : "") . " poster_id IN ({$authors}) "; } if ($post_status != "all") { $query .= ($post_text || $authors ? " AND " : "") . " post_status = '{$post_status}' "; } $restrict = " ORDER BY post_time {$post_order} LIMIT {$offset},{$per_page}"; // echo $query; // diagnostic $total = $bbdb->get_var("SELECT COUNT(*) " . $query); // intval(bb_count_last_query($query)); if ($total) { $bb_posts = $bbdb->get_results("SELECT * " . $query . $restrict); } else { unset($bb_posts); } ?> <form action="<?php echo bb_get_admin_tab_link("mass_edit"); ?> " method="get" id="post-search-form" class="search-form"> <fieldset><legend><?php _e('Show Posts or IPs That Contain …'); ?> </legend> <input name="post_text" id="post-text" class="text-input" type="text" value="<?php echo wp_specialchars($post_text); ?> " size="30" /> </fieldset> <?php /* selection by forum and tag not included in initial versions <fieldset><legend>Forum …</legend> <select name="forum_id" id="forum-id" tabindex="5"> <option value="0">Any</option> <option value="1"> bbPress chat</option> </select> </fieldset> <fieldset><legend>Tag…</legend> <input name="tag" id="topic-tag" class="text-input" value="" type="text" /> </fieldset> */ ?> <fieldset><legend>Post Author…</legend> <input name="post_author" id="post-author" class="text-input" type="text" value="<?php if (isset($_GET['post_author'])) { echo wp_specialchars($_GET['post_author'], 1); } ?> " /> </fieldset> <fieldset><legend>Post Status …</legend> <select name="post_status" id="post-status"> <option value="0" <?php echo $post_status == 0 ? 'selected="selected"' : ''; ?> >Visible</option> <option value="1" <?php echo $post_status == 1 ? 'selected="selected"' : ''; ?> >Deleted</option> <option value="2" <?php echo $post_status == 2 ? 'selected="selected"' : ''; ?> >Spam</option> <option value="all" <?php echo $post_status == "all" ? 'selected="selected"' : ''; ?> >All</option> </select> </fieldset> <fieldset><legend>Sort Order …</legend> <select name="post_order" id="post-order"> <option value="DESC" <?php echo $post_order == "DESC" ? 'selected="selected"' : ''; ?> >Newest</option> <option value="ASC" <?php echo $post_order == "ASC" ? 'selected="selected"' : ''; ?> >Oldest</option> </select> </fieldset> <fieldset><legend>Per Page</legend> <select name="per_page" id="per-page"> <option value="20" <?php echo $per_page == 20 ? 'selected="selected"' : ''; ?> >20</option> <option value="50" <?php echo $per_page == 50 ? 'selected="selected"' : ''; ?> >50</option> <option value="100" <?php echo $per_page == 100 ? 'selected="selected"' : ''; ?> >100</option> </select> </fieldset> <fieldset><legend>Exact Match</legend> <input type="hidden" name="plugin" value="mass_edit" /> <span style="padding-left:1em;"><input style="height:1.4em;width:1.4em;" name="exact_match" id="exact-match" class="checkbox" type="checkbox" value="1" <?php echo $exact_match ? 'checked="checked"' : ''; ?> /></span> <span style="padding-left:1em;" class=submit><input class=submit type="submit" name="submit" value="<?php _e('Search'); ?> »" /></span> </fieldset> </form> <?php if ($total) { echo $pagelinks = "<p style='clear:left'>[ " . ($total > $per_page ? "showing " . (($page - 1) * $per_page + 1) . " - " . ($total < $page * $per_page ? $total : $page * $per_page) . " of " : "") . "{$total} posts found ] " . '<span style="padding-left:1em">' . get_page_number_links($page, $total) . "</span></p>"; } if ($bb_posts) { // lazy cache loading to radically reduce query count foreach ($bb_posts as $bb_post) { $users[$bb_post->poster_id] = $bb_post->poster_id; $topics[$bb_post->topic_id] = $bb_post->topic_id; } bb_cache_users($users); unset($users); $topics = join(',', $topics); $topics = $bbdb->get_results("SELECT topic_id,topic_title,topic_slug FROM {$bbdb->topics} WHERE topic_id IN ({$topics})"); $topics = bb_append_meta($topics, 'topic'); unset($topics); echo '<form name="deleteposts" id="deleteposts" action="" method="post"> '; bb_nonce_field('mass-edit-bulk-posts'); echo '<table class="widefat"> <thead> <tr>'; foreach ($mass_edit_columns as $position) { switch ($position) { case "checkbox": echo '<th scope="col"><input type="checkbox" onclick="checkAll(this,document.getElementById(\'deleteposts\'));" /></th>'; break; case "excerpt": echo '<th scope="col" width="90%">' . __('Post Excerpt') . '</th>'; break; case "name": echo '<th scope="col">' . __('Name') . '</th>'; break; case "meta": echo '<th scope="col">' . __('Meta') . '</th>'; break; case 'actions': echo '<th scope="col" colspan="2">' . __('Actions') . '</th>'; break; } } echo '</tr></thead>'; foreach ($bb_posts as $bb_post) { $bb_post_cache[$bb_post->post_id] = $bb_post; // yes this is naughty but lazy workaround for using internal functions without extra mysql queries switch ($bb_post->post_status) { case 0: $del_class = ''; break; case 1: $del_class = 'deleted'; break; case 2: $del_class = 'spam'; break; default: $del_class = apply_filters('post_del_class', $bb_post->post_status, $bb_post->post_id); } ?> <tr id="post-<?php echo $bb_post->post_id; ?> " <?php alt_class('post', $del_class); ?> > <?php foreach ($mass_edit_columns as $position) { switch ($position) { case "checkbox": ?> <td><?php if (bb_current_user_can('edit_post', $bb_post->post_id)) { ?> <input type="checkbox" name="mass_edit_delete_posts[]" value="<?php echo $bb_post->post_id; ?> " /><?php } ?> </td> <?php break; case "excerpt": ?> <td><?php echo "<a class=metext href='" . mass_edit_get_post_link() . "'>[<strong>" . get_topic_title($bb_post->topic_id) . "</strong>] " . mass_edit_scrub_text($bb_post->post_text, $post_text, 45, $exact_match) . '</a>'; ?> </td> <?php break; case "name": ?> <td><a href="<?php echo attribute_escape(get_user_profile_link($bb_post->poster_id)); ?> "><?php echo get_user_name($bb_post->poster_id); ?> </a></td> <?php break; case "meta": ?> <td><span class=timetitle title="<?php echo date("r", strtotime(bb_get_post_time())); ?> "><?php printf(__('%s ago'), bb_get_post_time()); ?> </span> <?php post_ip_link(); ?> </td> <?php break; case "actions": ?> <td><a href="<?php post_link(); ?> "><?php _e('View'); ?> </a> <?php if (bb_current_user_can('edit_post', $bb_post->post_id)) { post_edit_link(); } ?> </td> <td><?php if (bb_current_user_can('edit_post', $bb_post->post_id)) { post_delete_link(); } ?> </td> <?php } } echo '</tr>'; } // end foreach unset($bb_posts); ?> </table> <?php if ($total) { echo $pagelinks; } ?> <p class="submit"> <input type="submit" class="deleted" name="mass_edit_delete_button" value="<?php _e('Delete Checked posts »'); ?> " onclick="var numchecked = getNumChecked(document.getElementById('deleteposts')); if(numchecked < 1) { alert('<?php _e("Please select some posts to delete"); ?> '); return false } return confirm('<?php printf(__("You are about to delete %s posts \\n \\'Cancel\\' to stop, \\'OK\\' to delete."), "' + numchecked + '"); ?> ')" /> <input type="submit" class="spam" name="mass_edit_spam_button" value="<?php _e('Mark Checked posts as Spam »'); ?> " onclick="var numchecked = getNumChecked(document.getElementById('deleteposts')); if(numchecked < 1) { alert('<?php _e("Please select some posts to mark as spam"); ?> '); return false } return confirm('<?php printf(__("You are about to mark %s posts as spam \\n \\'Cancel\\' to stop, \\'OK\\' to spam."), "' + numchecked + '"); ?> ')" /> <input type="submit" class="normal" name="mass_edit_undelete_button" value="<?php _e('Undelete Checked posts »'); ?> " onclick="var numchecked = getNumChecked(document.getElementById('deleteposts')); if(numchecked < 1) { alert('<?php _e("Please select some posts to delete"); ?> '); return false } return confirm('<?php printf(__("You are about to undelete %s posts \\n \\'Cancel\\' to stop, \\'OK\\' to undelete."), "' + numchecked + '"); ?> ')" /> </form> <div id="ajax-response"></div> <?php } else { ?> <p style="clear:both;"> <?php if ($exact_match) { echo " <strong>" . __('No results found for exact match.') . " "; echo ' <a href="' . attribute_escape(remove_query_arg('exact_match')) . '">' . __("Try non-exact?") . '</a></strong> '; } else { echo "<strong>" . __('No results found.') . "</strong>"; } ?> </p> <?php } // end if ($bb_posts) ?> </div> <?php }