function bb_repermalink() { global $page; $location = bb_get_location(); $uri = $_SERVER['REQUEST_URI']; if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = bb_get_path(); } $_original_id = $id; do_action('pre_permalink', $id); $id = apply_filters('bb_repermalink', $id); switch ($location) { case 'front-page': $path = null; $querystring = null; if ($page > 1) { if (bb_get_option('mod_rewrite')) { $path = 'page/' . $page; } else { $querystring = array('page' => $page); } } $permalink = bb_get_uri($path, $querystring, BB_URI_CONTEXT_HEADER); $issue_404 = true; break; case 'forum-page': if (empty($id)) { $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER); break; } global $forum_id, $forum; $forum = bb_get_forum($id); $forum_id = $forum->forum_id; $permalink = get_forum_link($forum->forum_id, $page); break; case 'topic-edit-page': case 'topic-page': if (empty($id)) { $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER); break; } global $topic_id, $topic; $topic = get_topic($id); $topic_id = $topic->topic_id; $permalink = get_topic_link($topic->topic_id, $page); break; case 'profile-page': // This handles the admin side of the profile as well. global $user_id, $user, $profile_hooks, $self; if (isset($_GET['id'])) { $id = $_GET['id']; } elseif (isset($_GET['username'])) { $id = $_GET['username']; } else { $id = bb_get_path(); } $_original_id = $id; if (!$id) { $user = bb_get_current_user(); // Attempt to go to the current users profile } else { if (bb_get_option('mod_rewrite') === 'slugs') { if (!($user = bb_get_user_by_nicename($id))) { $user = bb_get_user($id); } } else { if (!($user = bb_get_user($id))) { $user = bb_get_user_by_nicename($id); } } } if (!$user || 1 == $user->user_status && !bb_current_user_can('moderate')) { bb_die(__('User not found.'), '', 404); } $user_id = $user->ID; bb_global_profile_menu_structure(); $valid = false; if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) { foreach ($profile_hooks as $valid_tab => $valid_file) { if ($tab == $valid_tab) { $valid = true; $self = $valid_file; } } } if ($valid) { $permalink = get_profile_tab_link($user->ID, $tab, $page); } else { $permalink = get_user_profile_link($user->ID, $page); unset($self, $tab); } break; case 'favorites-page': $permalink = get_favorites_link(); break; case 'tag-page': // It's not an integer and tags.php pulls double duty. $id = isset($_GET['tag']) ? $_GET['tag'] : false; if (!$id || !bb_get_tag((string) $id)) { $permalink = bb_get_tag_page_link(); } else { global $tag, $tag_name; $tag_name = $id; $tag = bb_get_tag((string) $id); $permalink = bb_get_tag_link(0, $page); // 0 => grabs $tag from global. } break; case 'view-page': // Not an integer if (isset($_GET['view'])) { $id = $_GET['view']; } else { $id = bb_get_path(); } $_original_id = $id; global $view; $view = $id; $permalink = get_view_link($view, $page); break; default: return; break; } nxt_parse_str($_SERVER['QUERY_STRING'], $args); $args = urlencode_deep($args); if ($args) { $permalink = add_query_arg($args, $permalink); if (bb_get_option('mod_rewrite')) { $pretty_args = array('id', 'page', 'tag', 'tab', 'username'); // these are already specified in the path if ($location == 'view-page') { $pretty_args[] = 'view'; } foreach ($pretty_args as $pretty_arg) { $permalink = remove_query_arg($pretty_arg, $permalink); } } } $permalink = apply_filters('bb_repermalink_result', $permalink, $location); $domain = bb_get_option('domain'); $domain = preg_replace('/^https?/', '', $domain); $check = preg_replace('|^.*' . trim($domain, ' /') . '|', '', $permalink, 1); $uri = rtrim($uri, " \t\n\r\v?"); $uri = str_replace('/index.php', '/', $uri); global $bb_log; $bb_log->debug($uri, 'bb_repermalink() ' . __('REQUEST_URI')); $bb_log->debug($check, 'bb_repermalink() ' . __('should be')); $bb_log->debug($permalink, 'bb_repermalink() ' . __('full permalink')); $bb_log->debug(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null, 'bb_repermalink() ' . __('PATH_INFO')); if ($check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri)) { if ($issue_404 && rtrim($check, " \t\n\r\v/") !== rtrim($uri, " \t\n\r\v/")) { status_header(404); bb_load_template('404.php'); } else { nxt_redirect($permalink); } exit; } do_action('post_permalink', $permalink); }
/** * Get a forum by ID. * * Wrapper for {@link bb_get_forum()}. * * @param int $forum_id ID of the forum being fetched. * @return object bbPress forum object. */ function bp_forums_get_forum($forum_id) { /** This action is documented in bp-forums/bp-forums-screens */ do_action('bbpress_init'); return bb_get_forum($forum_id); }
/** * Returns the hot tags in order of hotness in a given forum or all hot tags * * @since 1.0 * @return integer|object The tag data when successfully executed or an IXR_Error object on failure * @param array $args Arguments passed by the XML-RPC call * @param string $args[0] The username for authentication * @param string $args[1] The password for authentication * @param integer $args[2] The number of tags to return (optional) * @param integer|string $args[3] The forum id or slug (optional) * * XML-RPC request to get the 20 hottest tags in the forum with slug "hawtness" * <methodCall> * <methodName>bb.getTopicTags</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><int>20</int></value></param> * <param><value><string>hawtness</string></value></param> * </params> * </methodCall> */ function bb_getHotTopicTags($args) { do_action('bb_xmlrpc_call', 'bb.getHotTopicTags'); // Escape args $this->escape($args); // Get the login credentials $username = $args[0]; $password = (string) $args[1]; // Check the user is valid if ($this->auth_readonly) { $user = $this->authenticate($username, $password); } do_action('bb_xmlrpc_call_authenticated', 'bb.getHotTopicTags'); // If an error was raised by authentication or by an action then return it if ($this->error) { return $this->error; } // Must be a number $per_page = isset($args[2]) ? (int) $args[2] : false; // Can be numeric id or slug $forum_id = isset($args[3]) ? $args[3] : false; if ($forum_id) { // Check for bad data if (!is_string($forum_id) && !is_integer($forum_id)) { $this->error = new IXR_Error(400, __('The forum id is invalid.')); return $this->error; } // Check the requested forum exists if (!($forum = bb_get_forum($forum_id))) { $this->error = new IXR_Error(404, __('No forum found.')); return $this->error; } global $bbdb; $topic_ids = $bbdb->get_col($bbdb->prepare("SELECT topic_id FROM `" . $bbdb->topics . "` WHERE `topic_status` = 0 AND `topic_open` = 1 AND `tag_count` > 0 AND `forum_id` = %s;", $forum_id)); if (!count($topic_ids)) { $this->error = new IXR_Error(400, __('No topics found.')); return $this->error; } global $nxt_taxonomy_object; $tags = $nxt_taxonomy_object->get_object_terms($topic_ids, 'bb_topic_tag', array('fields' => 'all_with_object_id', 'orderby' => 'count', 'order' => 'DESC')); if (!$tags || is_nxt_error($tags)) { $this->error = new IXR_Error(500, __('Could not retrieve hot topic tags.')); return $this->error; } if (!count($tags)) { $this->error = new IXR_Error(500, __('No hot topic tags found.')); return $this->error; } global $bb_log; $bb_log->debug($tags); for ($i = 0; isset($tags[$i]); $i++) { _bb_make_tag_compat($tags[$i]); } $bb_log->debug($tags); // Only include "safe" data in the array $_tags = array(); foreach ($tags as $tag) { $_tag = $this->prepare_topic_tag($tag); if (!in_array($_tag, $_tags)) { $_tags[] = $_tag; } } if ($per_page) { $_tags = array_slice($_tags, 0, $per_page); } } else { if (!($tags = bb_get_top_tags(array('get' => 'all', 'number' => $per_page)))) { $this->error = new IXR_Error(500, __('No hot topic tags found.')); return $this->error; } // Only include "safe" data in the array $_tags = array(); foreach ($tags as $tag) { $_tags[] = $this->prepare_topic_tag($tag); } } do_action('bb_xmlrpc_call', 'bb.getHotTopicTags'); return $_tags; }
/** * bb_get_new_topic_link() - Get the link to the form for a new topic * * @since 1.0 * @param mixed The arguments for this function. * @return string The link to the new topic form */ function bb_get_new_topic_link($args = null) { $defaults = array('text' => __('Add New »'), 'forum' => 0, 'tag' => ''); if ($args && is_string($args) && false === strpos($args, '=')) { $args = array('text' => $args); } $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); if ($forum && ($forum = bb_get_forum($forum))) { $url = get_forum_link($forum->forum_id) . '#postform'; } elseif ($tag && ($tag = bb_get_tag($tag))) { $url = bb_get_tag_link($tag->tag) . '#postform'; } elseif (bb_is_forum()) { global $forum; $url = get_forum_link($forum->forum_id) . '#postform'; } elseif (bb_is_tag()) { global $tag; $url = bb_get_tag_link($tag) . '#postform'; } elseif (bb_is_topic()) { $url = get_forum_link() . '#postform'; } elseif (bb_is_front()) { $url = bb_get_uri(null, array('new' => 1)); } if (!bb_is_user_logged_in()) { $url = bb_get_uri('bb-login.php', array('re' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS); } elseif (bb_is_forum() || bb_is_topic()) { if (!bb_current_user_can('write_topic', get_forum_id())) { return; } } else { if (!bb_current_user_can('write_topics')) { return; } } if ($url = esc_attr(apply_filters('new_topic_url', $url, $args))) { return '<a href="' . $url . '" class="new-topic">' . $text . '</a>' . "\n"; } }
function get_forum($forum_id) { bb_log_deprecated('class::function', __CLASS__ . '::' . __FUNCTION__, 'bb_get_forum'); return bb_get_forum($forum_id); }
<?php $forum_options=gf_forum_prepare_fields(gf_get_current_forum_id()); $deleted_forum = bb_get_forum( gf_get_current_forum_id() ); ?> <form class="delete-forum standard-form" method="post" id="delete-forums" action=""> <fieldset> <legend><?php _e('Delete Forum','gf'); ?></legend> <p><?php _e('This forum contains:','gf'); ?></p> <ul> <li><?php printf(__('%d topic','gf'), $deleted_forum->topics); ?></li> <li><?php printf(__('%d post','gf'), $deleted_forum->posts); ?></li> </ul> <div id="option-forum-delete-contents"> <div class="label"><?php _e( 'Action','gf' ); ?></div> <div class="inputs"> <label class="radios"> <input type="radio" name="move_topics" id="move-topics-delete" value="delete" /> <?php _e('Delete all topics and posts in this forum. <em>This can never be undone.</em>','gf'); ?> </label> <label class="radios"> <input type="radio" name="move_topics" id="move-topics-move" value="move" checked="checked" /> <?php _e('Move topics from this forum into the replacement forum below.','gf'); ?> </label> </div> </div> <div id="option-forum-delete-contents"> <label for="move-topics-forum"><?php _e( 'Replacement forum','gf' ); ?></label> <div class="inputs"> <?php echo gf_get_forum_dropdown( array('id' => 'move_topics_forum', 'callback' => 'strcmp', 'callback_args' => array($deleted_forum->forum_id), 'selected' => $deleted_forum->forum_parent) ); ?> </div> </div> </fieldset>
// Tag recent topics $feed = 'tag-topics'; } else { // Tag recent posts $feed = 'tag-posts'; } $feed_id = isset($_GET['tag']) ? $_GET['tag'] : bb_get_path(2); } elseif (isset($_GET['forum']) || bb_get_path() == 'forum') { if (isset($_GET['topics']) || bb_get_path(3) == 'topics') { // Forum recent topics $feed = 'forum-topics'; } else { // Forum recent posts $feed = 'forum-posts'; } $forum = bb_get_forum(isset($_GET['forum']) ? $_GET['forum'] : bb_get_path(2)); $feed_id = $forum->forum_id; } elseif (isset($_GET['topics']) || bb_get_path() == 'topics') { // Recent topics $feed = 'all-topics'; } else { // Recent posts $feed = 'all-posts'; } // Initialise the override variable $bb_db_override = false; do_action('bb_rss.php_pre_db'); if (!$bb_db_override) { // Get the posts and the title for the given feed switch ($feed) { case 'view':
<?php require_once 'admin-action.php'; $topic_id = absint($_POST['topic_id']); $forum_id = absint($_POST['forum_id']); if (!is_numeric($topic_id) || !is_numeric($forum_id)) { bb_die(__('Invalid topic or forum.')); } if (!bb_current_user_can('move_topic', $topic_id, $forum_id)) { nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); exit; } bb_check_admin_referer('move-topic_' . $topic_id); $topic = get_topic($topic_id); $forum = bb_get_forum($forum_id); if (!$topic || !$forum) { bb_die(__('Your topic or forum caused all manner of confusion')); } bb_move_topic($topic_id, $forum_id); if (!($redirect = nxt_get_referer())) { $redirect = get_topic_link($topic_id); } bb_safe_redirect($redirect); exit;
/** Forum Functions ***********************************************************/ function bp_forums_get_forum($forum_id) { do_action('bbpress_init'); return bb_get_forum($forum_id); }
function bb_export_forum($forum_id) { if (!($_forum = bb_get_forum($forum_id))) { return; } $_forum = get_object_vars($_forum); $translate = array('forum_name' => '!title', 'forum_desc' => '?!content', 'forum_parent' => '?parent'); $forum = _bb_translate_for_export($translate, $_forum); return _bb_export_object(array('type' => 'forum', 'id' => $_forum['forum_id']), $forum); }
<?php require_once 'admin.php'; $forums = bb_get_forums(); $forums_count = $forums ? count($forums) : 0; if (isset($_GET['action']) && 'delete' == $_GET['action']) { $forum_to_delete = (int) $_GET['id']; $deleted_forum = bb_get_forum($forum_to_delete); if (!$deleted_forum || $forums_count < 2 || !bb_current_user_can('delete_forum', $forum_to_delete)) { bb_safe_redirect(add_query_arg(array('action' => false, 'id' => false))); exit; } } if (isset($_GET['message'])) { switch ($_GET['message']) { case 'updated': bb_admin_notice(__('<strong>Forum Updated.</strong>')); break; case 'deleted': bb_admin_notice(sprintf(__('<strong>Forum deleted.</strong> You should <a href="%s">recount your site information</a>.'), bb_get_uri('bb-admin/tools-recount.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN))); break; } } if (!isset($_GET['action'])) { nxt_enqueue_script('admin-forums'); } elseif ('delete' == @$_GET['action']) { bb_admin_notice(sprintf(__('Are you sure you want to delete the "<strong>%s</strong>" forum?'), $deleted_forum->forum_name)); } $bb_admin_body_class = ' bb-admin-forums'; bb_get_admin_header(); ?>
<?php if ( gf_current_user_can_admin()||gf_current_user_can_mod() ) : ?> <!-- mimick bbpress dashboard--> <div class="admin"> <div class="dashboard" id="dashboard-right-now"> <h3><?php _e("Right Now","gf");?></h3> <?php $forum=bb_get_forum(gf_get_root_forum_id()); ?> <div class="table"> <table cellspacing="0" cellpadding="0"> <thead> <tr> <th>Totals</th> <th>Per Day</th> </tr> </thead> <tbody> <tr> <td><a href="<?php echo gf_get_forum_manage_link();?>"><span> <?php echo gf_get_total_forums_count();?></span> <?php _e("forums","gf");?></a></td> <td>N/A</td> </tr> <tr> <td><span><?php echo gf_get_total_topic_count();?></span> topics</td> <td><span>N/A</span> </td> </tr> <tr> <td><span><?php echo gf_get_total_posts_count();?></span> posts</td> <td><span>N/A</span> </td> </tr> <tr> <td><span><?php echo gf_get_total_tags();?></span> tags</td>
$x->send(); break; case 'order-forums': if (!bb_current_user_can('manage_forums')) { die('-1'); } bb_check_ajax_referer($action); if (!is_array($_POST['order'])) { die('0'); } global $bbdb; $forums = array(); bb_get_forums(); // cache foreach ($_POST['order'] as $pos => $forum_id) { $forum = $bbdb->escape_deep(get_object_vars(bb_get_forum($forum_id))); $forum['forum_order'] = $pos; $forums[(int) $forum_id] = $forum; } foreach ($_POST['root'] as $root => $ids) { foreach ($ids as $forum_id) { $forums[(int) $forum_id]['forum_parent'] = (int) $root; } } foreach ($forums as $forum) { bb_update_forum($forum); } die('1'); break; default: do_action('bb_ajax_' . $_POST['action']);
$view_deleted = true; } bb_repermalink(); if (!$topic) { bb_die(__('Topic not found.')); } if ($view_deleted) { add_filter('get_thread_where', create_function('', 'return "p.topic_id = ' . $topic_id . '";')); add_filter('get_thread_post_ids', create_function('', 'return "p.topic_id = ' . $topic_id . '";')); add_filter('post_edit_uri', 'bb_make_link_view_all'); } $bb_db_override = false; do_action('bb_topic.php_pre_db', $topic_id); if (!$bb_db_override) { $posts = get_thread($topic_id, $page); $forum = bb_get_forum($topic->forum_id); $tags = bb_get_topic_tags($topic_id); if ($tags && ($bb_current_id = bb_get_current_user_info('id'))) { $user_tags = bb_get_user_tags($topic_id, $bb_current_id); $other_tags = bb_get_other_tags($topic_id, $bb_current_id); $public_tags = bb_get_public_tags($topic_id); } elseif (is_array($tags)) { $user_tags = false; $other_tags = bb_get_public_tags($topic_id); $public_tags =& $other_tags; } else { $user_tags = $other_tags = $public_tags = false; } $list_start = ($page - 1) * bb_get_option('page_topics') + 1; bb_post_author_cache($posts); }
function bb_move_forum_topics($from_forum_id, $to_forum_id) { global $bbdb; $from_forum_id = (int) $from_forum_id; $to_forum_id = (int) $to_forum_id; add_filter('get_forum_where', 'bb_no_where'); // Just in case $from_forum = bb_get_forum($from_forum_id); if (!($to_forum = bb_get_forum($to_forum_id))) { return false; } $posts = $to_forum->posts + ($from_forum ? $from_forum->posts : 0); $topics = $to_forum->topics + ($from_forum ? $from_forum->topics : 0); $bbdb->update($bbdb->forums, compact('topics', 'posts'), array('forum_id' => $to_forum_id)); $bbdb->update($bbdb->forums, array('topics' => 0, 'posts' => 0), array('forum_id' => $from_forum_id)); $bbdb->update($bbdb->posts, array('forum_id' => $to_forum_id), array('forum_id' => $from_forum_id)); $topic_ids = $bbdb->get_col($bbdb->prepare("SELECT topic_id FROM {$bbdb->topics} WHERE forum_id = %d", $from_forum_id)); $return = $bbdb->update($bbdb->topics, array('forum_id' => $to_forum_id), array('forum_id' => $from_forum_id)); nxt_cache_flush('bb_post'); if ($topic_ids) { foreach ($topic_ids as $topic_id) { // should maybe just flush these groups nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); } } nxt_cache_delete($from_forum_id, 'bb_forum'); nxt_cache_delete($to_forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); return $return; }
function bb_get_forummeta($forum_id, $meta_key) { if (!($forum = bb_get_forum($forum_id))) { return; } $meta_key = bb_sanitize_meta_key($meta_key); if (!isset($forum->{$meta_key})) { return; } return $forum->{$meta_key}; }
function bb_move_topic($topic_id, $forum_id) { global $bbdb; $topic = get_topic($topic_id); $forum = bb_get_forum($forum_id); $topic_id = (int) $topic->topic_id; $forum_id = (int) $forum->forum_id; if ($topic && $forum && $topic->forum_id != $forum_id) { $bbdb->update($bbdb->posts, compact('forum_id'), compact('topic_id')); $bbdb->update($bbdb->topics, compact('forum_id'), compact('topic_id')); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1, posts = posts + %d WHERE forum_id = %d", $topic->topic_posts, $forum_id)); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics - 1, posts = posts - %d WHERE forum_id = %d", $topic->topic_posts, $topic->forum_id)); wp_cache_flush('bb_post'); wp_cache_delete($topic_id, 'bb_topic'); wp_cache_delete($forum_id, 'bb_forum'); wp_cache_flush('bb_forums'); wp_cache_flush('bb_query'); wp_cache_flush('bb_cache_posts_post_ids'); do_action('bb_move_topic', $topic_id, $forum_id, $topic->forum_id); return $forum_id; } return false; }
if (defined('W2BC_DEBUG') && W2BC_DEBUG == true && ($all_mem_size = @ini_get('memory_limit'))) { echo "<li>Allocated memory is {$all_mem_size}</li>\n"; } if (defined('W2BC_ALLOW_SYNC') && W2BC_ALLOW_SYNC == true) { $notposts = array(); } $last_comment_date = '1970-01-02 00:00:01'; foreach ((array) $posts as $post) { echo "<li>Processing post #{$post->ID} (<a href='{$post->guid}'>{$post->post_title}</a>)\n<ul>\n"; if (defined('W2BC_CONVERT_FROM_TIME') && W2BC_CONVERT_FROM_TIME !== false && defined('W2BC_DEBUG') && W2BC_DEBUG == true) { echo "<li>Post date/time is {$post->post_date} (GMT - {$post->post_date_gmt})</li>\n"; } /* Category <-> Forum */ $cats = get_the_category($post->ID); $cat = $cats[0]; if (!($forum = bb_get_forum(bb_slug_sanitize($cat->name)))) { if ($forum_id = bb_new_forum(array('forum_name' => $cat->name, 'forum_desc' => $cat->description))) { echo "<li>Added category #{$cat->term_id} ({$cat->name}) as forum #{$forum_id}</li>\n"; } else { echo "<li><em>There was a problem in adding category #{$cat->term_id} ({$cat->name}) as a forum and thus post #{$post->ID} couldn't be added as a topic.</em></li></ul></li>\n"; continue; } } else { $forum_id = $forum->forum_id; } if (defined('W2BC_DEBUG') && W2BC_DEBUG == true) { echo "<li>Topic's forum is <a href=\"" . bb_get_uri('forum.php', array('id' => $forum_id)) . "\">#{$forum_id}</a> ({$cat->name})</li>\n"; } /* Post Tag <-> Topic Tag */ $tags = ''; if ($posttags = get_the_tags()) {