$v) {
if ( is_array($v) ) {
$array[$k] = bb_global_sanitize($v);
} else {
if ( !get_magic_quotes_gpc() )
$array[$k] = addslashes($v);
if ( $trim )
$array[$k] = trim($array[$k]);
}
}
return $array;
}
function bb_is_installed() { // Maybe grab all the forums and cache them
global $bbdb;
$bbdb->suppress_errors();
$forums = (array) @get_forums();
$bbdb->suppress_errors(false);
if ( !$forums )
return false;
return true;
}
function bb_set_custom_user_tables() {
global $bb;
// Check for older style custom user table
// TODO: Completely remove old constants on version 1.0
if ( !isset($bb->custom_tables['users']) ) { // Don't stomp new setting style
if ( !$bb->custom_user_table = bb_get_option('custom_user_table') ) // Maybe get from database or old config setting
if ( defined('CUSTOM_USER_TABLE') ) // Maybe user has set old constant
$bb->custom_user_table = CUSTOM_USER_TABLE;
if ( $bb->custom_user_table ) {
if ( !isset($bb->custom_tables) )
$bb->custom_tables = array();
$bb->custom_tables['users'] = $bb->custom_user_table;
}
}
// Check for older style custom user meta table
// TODO: Completely remove old constants on version 1.0
if ( !isset($bb->custom_tables['usermeta']) ) { // Don't stomp new setting style
if ( !$bb->custom_user_meta_table = bb_get_option('custom_user_meta_table') ) // Maybe get from database or old config setting
if ( defined('CUSTOM_USER_META_TABLE') ) // Maybe user has set old constant
$bb->custom_user_meta_table = CUSTOM_USER_META_TABLE;
if ( $bb->custom_user_meta_table ) {
if ( !isset($bb->custom_tables) )
$bb->custom_tables = array();
$bb->custom_tables['usermeta'] = $bb->custom_user_meta_table;
}
}
// Check for older style wp_table_prefix
// TODO: Completely remove old constants on version 1.0
if ( $bb->wp_table_prefix = bb_get_option('wp_table_prefix') ) { // User has set old constant
if ( !isset($bb->custom_tables) ) {
$bb->custom_tables = array(
'users' => $bb->wp_table_prefix . 'users',
'usermeta' => $bb->wp_table_prefix . 'usermeta'
);
} else {
if ( !isset($bb->custom_tables['users']) ) // Don't stomp new setting style
$bb->custom_tables['users'] = $bb->wp_table_prefix . 'users';
if ( !isset($bb->custom_tables['usermeta']) )
$bb->custom_tables['usermeta'] = $bb->wp_table_prefix . 'usermeta';
}
}
// Check for older style user database
// TODO: Completely remove old constants on version 1.0
if ( !isset($bb->custom_databases) )
$bb->custom_databases = array();
if ( !isset($bb->custom_databases['user']) ) {
if ( !$bb->user_bbdb_name = bb_get_option('user_bbdb_name') )
if ( defined('USER_BBDB_NAME') ) // User has set old constant
$bb->user_bbdb_name = USER_BBDB_NAME;
if ( $bb->user_bbdb_name )
$bb->custom_databases['user']['name'] = $bb->user_bbdb_name;
if ( !$bb->user_bbdb_user = bb_get_option('user_bbdb_user') )
if ( defined('USER_BBDB_USER') ) // User has set old constant
$bb->user_bbdb_user = USER_BBDB_USER;
if ( $bb->user_bbdb_user )
$bb->custom_databases['user']['user'] = $bb->user_bbdb_user;
if ( !$bb->user_bbdb_password = bb_get_option('user_bbdb_password') )
if ( defined('USER_BBDB_PASSWORD') ) // User has set old constant
$bb->user_bbdb_password = USER_BBDB_PASSWORD;
if ( $bb->user_bbdb_password )
$bb->custom_databases['user']['password'] = $bb->user_bbdb_password;
if ( !$bb->user_bbdb_host = bb_get_option('user_bbdb_host') )
if ( defined('USER_BBDB_HOST') ) // User has set old constant
$bb->user_bbdb_host = USER_BBDB_HOST;
if ( $bb->user_bbdb_host )
$bb->custom_databases['user']['host'] = $bb->user_bbdb_host;
if ( !$bb->user_bbdb_charset = bb_get_option('user_bbdb_charset') )
if ( defined('USER_BBDB_CHARSET') ) // User has set old constant
$bb->user_bbdb_charset = USER_BBDB_CHARSET;
if ( $bb->user_bbdb_charset )
$bb->custom_databases['user']['charset'] = $bb->user_bbdb_charset;
if ( !$bb->user_bbdb_collate = bb_get_option('user_bbdb_collate') )
if ( defined('USER_BBDB_COLLATE') ) // User has set old constant
$bb->user_bbdb_collate = USER_BBDB_COLLATE;
if ( $bb->user_bbdb_collate )
$bb->custom_databases['user']['collate'] = $bb->user_bbdb_collate;
if ( isset( $bb->custom_databases['user'] ) ) {
if ( isset($bb->custom_tables['users']) )
$bb->custom_tables['users'] = array('user', $bb->custom_tables['users']);
if ( isset($bb->custom_tables['usermeta']) )
$bb->custom_tables['usermeta'] = array('user', $bb->custom_tables['usermeta']);
}
}
}
/* HTTP Helpers */
/**
* Set the headers for caching for 10 days with JavaScript content type.
*
* @since 1.0
*/
function bb_cache_javascript_headers() {
$expiresOffset = 864000; // 10 days
header( "Content-Type: text/javascript; charset=utf-8" );
header( "Vary: Accept-Encoding" ); // Handle proxies
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
}
/* Pagination */
/**
* Retrieve paginated links for pages.
*
* Technically, the function can be used to create paginated link list for any
* area. The 'base' argument is used to reference the url, which will be used to
* create the paginated links. The 'format' argument is then used for replacing
* the page number. It is however, most likely and by default, to be used on the
* archive post pages.
*
* The 'type' argument controls format of the returned value. The default is
* 'plain', which is just a string with the links separated by a newline
* character. The other possible values are either 'array' or 'list'. The
* 'array' value will return an array of the paginated link list to offer full
* control of display. The 'list' value will place all of the paginated links in
* an unordered HTML list.
*
* The 'total' argument is the total amount of pages and is an integer. The
* 'current' argument is the current page number and is also an integer.
*
* An example of the 'base' argument is "http://example.com/all_posts.php%_%"
* and the '%_%' is required. The '%_%' will be replaced by the contents of in
* the 'format' argument. An example for the 'format' argument is "?page=%#%"
* and the '%#%' is also required. The '%#%' will be replaced with the page
* number.
*
* You can include the previous and next links in the list by setting the
* 'prev_next' argument to true, which it is by default. You can set the
* previous text, by using the 'prev_text' argument. You can set the next text
* by setting the 'next_text' argument.
*
* If the 'show_all' argument is set to true, then it will show all of the pages
* instead of a short list of the pages near the current page. By default, the
* 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
* arguments. The 'end_size' argument is how many numbers on either the start
* and the end list edges, by default is 1. The 'mid_size' argument is how many
* numbers to either side of current page, but not including current page.
*
* It is possible to add query vars to the link by using the 'add_args' argument
* and see {@link add_query_arg()} for more information.
*
* @since 1.0
*
* @param string|array $args Optional. Override defaults.
* @return array|string String of page links or array of page links.
*/
function bb_paginate_links( $args = '' ) {
$defaults = array(
'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
'total' => 1,
'current' => 0,
'show_all' => false,
'prev_next' => true,
'prev_text' => __( '« Previous' ),
'next_text' => __( 'Next »' ),
'end_size' => 1, // How many numbers on either end including the end
'mid_size' => 2, // How many numbers to either side of current not including current
'type' => 'plain',
'add_args' => false, // array of query args to add
'add_fragment' => '',
'n_title' => __( 'Page %d' ), // Not from WP version
'prev_title' => __( 'Previous page' ), // Not from WP version
'next_title' => __( 'Next page' ) // Not from WP version
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
// Who knows what else people pass in $args
$total = (int) $total;
if ( $total < 2 )
return;
$current = (int) $current;
$end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
$add_args = is_array($add_args) ? $add_args : false;
$r = '';
$page_links = array();
$n = 0;
$dots = false;
if ( $prev_next && $current && 1 < $current ) {
$link = str_replace( '%_%', 2 == $current ? '' : $format, $base );
$link = str_replace( '%#%', $current - 1, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
$page_links[] = '' . $prev_text . '';
}
for ( $n = 1; $n <= $total; $n++ ) {
$n_display = bb_number_format_i18n( $n );
$n_display_title = attribute_escape( sprintf( $n_title, $n ) );
if ( $n == $current ) {
$page_links[] = '' . $n_display . '';
$dots = true;
} else {
if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) {
$link = str_replace( '%_%', 1 == $n ? '' : $format, $base );
$link = str_replace( '%#%', $n, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
$page_links[] = '' . $n_display . '';
$dots = true;
} elseif ( $dots && !$show_all ) {
$page_links[] = '…';
$dots = false;
}
}
}
if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) {
$link = str_replace( '%_%', $format, $base );
$link = str_replace( '%#%', $current + 1, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $add_fragment;
$page_links[] = '$next_text';
}
switch ( $type ) {
case 'array':
return $page_links;
break;
case 'list':
$r .= '
' . "\n\t" . '
';
$r .= join( '
' . "\n\t" . '
', $page_links );
$r .= '
' . "\n" . '
' . "\n";
break;
default:
$r = join( "\n", $page_links );
break;
}
return $r;
}
function bb_get_uri_page() {
if ( isset($_GET['page']) && is_numeric($_GET['page']) && 1 < (int) $_GET['page'] )
return (int) $_GET['page'];
if ( isset($_SERVER['PATH_INFO']) )
$path = $_SERVER['PATH_INFO'];
else
if ( !$path = strtok($_SERVER['REQUEST_URI'], '?') )
return 1;
if ( $page = strstr($path, '/page/') ) {
$page = (int) substr($page, 6);
if ( 1 < $page )
return $page;
}
return 1;
}
//expects $item = 1 to be the first, not 0
function get_page_number( $item, $per_page = 0 ) {
if ( !$per_page )
$per_page = bb_get_option('page_topics');
return intval( ceil( $item / $per_page ) ); // page 1 is the first page
}
/* Time */
function bb_timer_stop($display = 0, $precision = 3) { //if called like bb_timer_stop(1), will echo $timetotal
global $bb_timestart, $timeend;
$mtime = explode(' ', microtime());
$timeend = $mtime[1] + $mtime[0];
$timetotal = $timeend - $bb_timestart;
if ($display)
echo bb_number_format_i18n($timetotal, $precision);
return bb_number_format_i18n($timetotal, $precision);
}
// GMT -> so many minutes ago
function bb_since( $original, $do_more = 0 ) {
$today = time();
if ( !is_numeric($original) ) {
if ( $today < $_original = bb_gmtstrtotime( str_replace(',', ' ', $original) ) ) // Looks like bb_since was called twice
return $original;
else
$original = $_original;
}
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , __('year') , __('years')),
array(60 * 60 * 24 * 30 , __('month') , __('months')),
array(60 * 60 * 24 * 7, __('week') , __('weeks')),
array(60 * 60 * 24 , __('day') , __('days')),
array(60 * 60 , __('hour') , __('hours')),
array(60 , __('minute') , __('minutes')),
array(1 , __('second') , __('seconds')),
);
$since = $today - $original;
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
$names = $chunks[$i][2];
if ( 0 != $count = floor($since / $seconds) )
break;
}
$print = sprintf(__('%1$d %2$s'), $count, (1 == $count) ? $name : $names);
if ( $do_more && $i + 1 < $j) {
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
$names2 = $chunks[$i + 1][2];
if ( 0 != $count2 = floor( ($since - $seconds * $count) / $seconds2) )
$print .= sprintf(__(', %1$d %2$s'), $count2, (1 == $count2) ? $name2 : $names2);
}
return $print;
}
function bb_current_time( $type = 'timestamp' ) {
switch ($type) {
case 'mysql':
$d = gmdate('Y-m-d H:i:s');
break;
case 'timestamp':
$d = time();
break;
}
return $d;
}
// GMT -> Local
// in future versions this could eaily become a user option.
function bb_offset_time( $time, $args = null ) {
if ( isset($args['format']) && 'since' == $args['format'] )
return $time;
if ( !is_numeric($time) ) {
if ( -1 !== $_time = bb_gmtstrtotime( $time ) )
return gmdate('Y-m-d H:i:s', $_time + bb_get_option( 'gmt_offset' ) * 3600);
else
return $time; // Perhaps should return -1 here
} else {
return $time + bb_get_option( 'gmt_offset' ) * 3600;
}
}
/* Permalinking / URLs / Paths */
function get_path( $level = 1, $base = false, $request = false ) {
if ( !$request )
$request = $_SERVER['REQUEST_URI'];
if ( is_string($request) )
$request = parse_url($request);
if ( !is_array($request) || !isset($request['path']) )
return '';
$path = rtrim($request['path'], '/');
if ( !$base )
$base = rtrim(bb_get_option('path'), '/');
$path = preg_replace('|' . preg_quote($base, '|') . '/?|','',$path,1);
if ( !$path )
return '';
if ( strpos($path, '/') === false )
return '';
$url = explode('/',$path);
if ( !isset($url[$level]) )
return '';
return urldecode($url[$level]);
}
function bb_find_filename( $text ) {
if ( preg_match('|.*?/([a-z\-]+\.php)/?.*|', $text, $matches) )
return $matches[1];
else {
$path = bb_get_option( 'path' );
$text = preg_replace("#^$path#", '', $text);
$text = preg_replace('#/.+$#', '', $text);
return $text . '.php';
}
return false;
}
function bb_send_headers() {
if ( bb_is_user_logged_in() )
nocache_headers();
@header('Content-Type: ' . bb_get_option( 'html_type' ) . '; charset=' . bb_get_option( 'charset' ));
do_action( 'bb_send_headers' );
}
function bb_pingback_header() {
if (bb_get_option('enable_pingback'))
@header('X-Pingback: '. bb_get_uri('xmlrpc.php', null, BB_URI_CONTEXT_HEADER + BB_URI_CONTEXT_BB_XMLRPC));
}
// Inspired by and adapted from Yung-Lung Scott YANG's http://scott.yang.id.au/2005/05/permalink-redirect/ (GPL)
function bb_repermalink() {
global $page;
$location = bb_get_location();
$uri = $_SERVER['REQUEST_URI'];
if ( isset($_GET['id']) )
$id = $_GET['id'];
else
$id = 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 = 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 = get_path();
$_original_id = $id;
if ( !$id )
$user = bb_get_current_user(); // Attempt to go to the current users profile
elseif ( !is_numeric( $id ) && is_string( $id ) )
$user = bb_get_user_by_nicename( $id ); // Get by the user_nicename
else
$user = bb_get_user( $id ); // Get by the ID
if ( !$user || ( 1 == $user->user_status && !bb_current_user_can( 'moderate' ) ) )
bb_die(__('User not found.'), '', 404);
$user_id = $user->ID;
global_profile_menu_structure();
$valid = false;
if ( $tab = isset($_GET['tab']) ? $_GET['tab'] : 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);
endif;
break;
case 'favorites-page':
$permalink = get_favorites_link();
break;
case 'tag-page': // It's not an integer and tags.php pulls double duty.
if ( isset($_GET['tag']) )
$id = $_GET['tag'];
$_original_id = $id;
if ( !$id )
$permalink = bb_get_tag_page_link();
else {
global $tag, $tag_name;
$tag_name = $id;
$tag = bb_get_tag( (string) $tag_name );
$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 = get_path();
$_original_id = $id;
global $view;
$view = $id;
$permalink = get_view_link( $view, $page );
break;
default:
return;
break;
}
wp_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, '?' );
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($_SERVER['PATH_INFO'], 'bb_repermalink() ' . __('PATH_INFO'));
if ( $check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri) ) {
if ( $issue_404 ) {
status_header( 404 );
bb_load_template( '404.php' );
} else {
wp_redirect( $permalink );
}
exit;
}
do_action( 'post_permalink', $permalink );
}
/* Profile/Admin */
function global_profile_menu_structure() {
global $user_id, $profile_menu, $profile_hooks;
// Menu item name
// The capability required for own user to view the tab ('' to allow non logged in access)
// The capability required for other users to view the tab ('' to allow non logged in access)
// The URL of the item's file
// Item name for URL (nontranslated)
$profile_menu[0] = array(__('Edit'), 'edit_profile', 'edit_users', 'profile-edit.php', 'edit');
$profile_menu[5] = array(__('Favorites'), 'edit_favorites', 'edit_others_favorites', 'favorites.php', 'favorites');
// Create list of page plugin hook names the current user can access
$profile_hooks = array();
foreach ($profile_menu as $profile_tab)
if ( can_access_tab( $profile_tab, bb_get_current_user_info( 'id' ), $user_id ) )
$profile_hooks[bb_sanitize_with_dashes($profile_tab[4])] = $profile_tab[3];
do_action('bb_profile_menu');
ksort($profile_menu);
}
function add_profile_tab($tab_title, $users_cap, $others_cap, $file, $arg = false) {
global $profile_menu, $profile_hooks, $user_id;
$arg = $arg ? $arg : $tab_title;
$profile_tab = array($tab_title, $users_cap, $others_cap, $file, $arg);
$profile_menu[] = $profile_tab;
if ( can_access_tab( $profile_tab, bb_get_current_user_info( 'id' ), $user_id ) )
$profile_hooks[bb_sanitize_with_dashes($arg)] = $file;
}
function can_access_tab( $profile_tab, $viewer_id, $owner_id ) {
global $bb_current_user;
$viewer_id = (int) $viewer_id;
$owner_id = (int) $owner_id;
if ( $viewer_id == bb_get_current_user_info( 'id' ) )
$viewer =& $bb_current_user;
else
$viewer = new WP_User( $viewer_id );
if ( !$viewer )
return '' === $profile_tab[2];
if ( $owner_id == $viewer_id ) {
if ( '' === $profile_tab[1] )
return true;
else
return $viewer->has_cap($profile_tab[1]);
} else {
if ( '' === $profile_tab[2] )
return true;
else
return $viewer->has_cap($profile_tab[2]);
}
}
//meta_key => (required?, Label, hCard property). Don't use user_{anything} as the name of your meta_key.
function get_profile_info_keys() {
return apply_filters( 'get_profile_info_keys', array(
'first_name' => array(0, __('First name')),
'last_name' => array(0, __('Last name')),
'display_name' => array(1, __('Display name as')),
'user_email' => array(1, __('Email'), 'email'),
'user_url' => array(0, __('Website'), 'url'),
'from' => array(0, __('Location')),
'occ' => array(0, __('Occupation'), 'role'),
'interest' => array(0, __('Interests')),
) );
}
function get_profile_admin_keys() {
global $bbdb;
return apply_filters( 'get_profile_admin_keys', array(
$bbdb->prefix . 'title' => array(0, __('Custom Title'))
) );
}
function get_assignable_caps() {
$caps = array();
if ( $throttle_time = bb_get_option( 'throttle_time' ) )
$caps['throttle'] = sprintf( __('Ignore the %d second post throttling limit'), $throttle_time );
return apply_filters( 'get_assignable_caps', $caps );
}
/* Views */
function bb_get_views() {
global $bb_views;
$views = array();
foreach ( (array) $bb_views as $view => $array )
$views[$view] = $array['title'];
return $views;
}
function bb_register_view( $view, $title, $query_args = '', $feed = TRUE ) {
global $bb_views;
$view = bb_slug_sanitize( $view );
$title = wp_specialchars( $title );
if ( !$view || !$title )
return false;
$query_args = wp_parse_args( $query_args );
if ( !$sticky_set = isset($query_args['sticky']) )
$query_args['sticky'] = 'no';
$bb_views[$view]['title'] = $title;
$bb_views[$view]['query'] = $query_args;
$bb_views[$view]['sticky'] = !$sticky_set; // No sticky set => split into stickies and not
$bb_views[$view]['feed'] = $feed;
return $bb_views[$view];
}
function bb_deregister_view( $view ) {
global $bb_views;
$view = bb_slug_sanitize( $view );
if ( !isset($bb_views[$view]) )
return false;
unset($GLOBALS['bb_views'][$view]);
return true;
}
function bb_view_query( $view, $new_args = '' ) {
global $bb_views;
$view = bb_slug_sanitize( $view );
if ( !isset($bb_views[$view]) )
return false;
if ( $new_args ) {
$new_args = wp_parse_args( $new_args );
$query_args = array_merge( $bb_views[$view]['query'], $new_args );
} else {
$query_args = $bb_views[$view]['query'];
}
return new BB_Query( 'topic', $query_args, "bb_view_$view" );
}
function bb_get_view_query_args( $view ) {
global $bb_views;
$view = bb_slug_sanitize( $view );
if ( !isset($bb_views[$view]) )
return false;
return $bb_views[$view]['query'];
}
function bb_register_default_views() {
// no posts (besides the first one), older than 2 hours
bb_register_view( 'no-replies', __('Topics with no replies'), array( 'post_count' => 1, 'started' => '<' . gmdate( 'YmdH', time() - 7200 ) ) );
bb_register_view( 'untagged' , __('Topics with no tags') , array( 'tag_count' => 0 ) );
}
/* Feeds */
/**
* Send status headers for clients supporting Conditional Get
*
* The function sends the Last-Modified and ETag headers for all clients. It
* then checks both the If-None-Match and If-Modified-Since headers to see if
* the client has used them. If so, and the ETag does matches the client ETag
* or the last modified date sent by the client is newer or the same as the
* generated last modified, the function sends a 304 Not Modified and exits.
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
* @param string $bb_last_modified Last modified time. Must be a HTTP-date
*/
function bb_send_304( $bb_last_modified ) {
$bb_etag = '"' . md5($bb_last_modified) . '"';
@header("Last-Modified: $bb_last_modified");
@header ("ETag: $bb_etag");
// Support for Conditional GET
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
else $client_etag = false;
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']);
// If string is empty, return 0. If not, attempt to parse into a timestamp
$client_modified_timestamp = $client_last_modified ? bb_gmtstrtotime($client_last_modified) : 0;
// Make a timestamp for our most recent modification...
$bb_modified_timestamp = bb_gmtstrtotime($bb_last_modified);
if ( ($client_last_modified && $client_etag) ?
(($client_modified_timestamp >= $bb_modified_timestamp) && ($client_etag == $bb_etag)) :
(($client_modified_timestamp >= $bb_modified_timestamp) || ($client_etag == $bb_etag)) ) {
status_header( 304 );
exit;
}
}
/* Nonce */
function bb_nonce_url($actionurl, $action = -1) {
return add_query_arg( '_wpnonce', bb_create_nonce( $action ), $actionurl );
}
function bb_nonce_field($action = -1, $name = "_wpnonce", $referer = true) {
$name = attribute_escape($name);
echo '';
if ( $referer )
wp_referer_field();
}
function bb_nonce_ays( $action ) {
$title = __( 'bbPress Failure Notice' );
$html .= "\t