first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
{
"name": "bbpress/bbpress",
"description": "bbPress is forum software with a twist from the creators of WordPress.",
"type": "wordpress-plugin",
"keywords": [
"bulletin board",
"community",
"forum",
"support",
"wordpress"
],
"homepage": "https://bbpress.org",
"license": "GPL-2.0-or-later",
"authors": [ {
"name": "bbPress Contributors",
"homepage": "https://bbpress.org/about/"
} ],
"support": {
"forum": "https://bbpress.org/support/",
"irc": "irc://irc.freenode.net/bbpress-dev",
"issues": "https://bbpress.trac.wordpress.org/",
"wiki": "https://codex.bbpress.org/",
"source": "https://bbpress.trac.wordpress.org/browser"
},
"require": {
"composer/installers": "~1.0",
"php": ">=5.6.20"
}
}

View File

@@ -0,0 +1,59 @@
..=OO$,
~OO=. . . . .Z88
.78.. .,OOOOOOO .7O
IO. 7OOOOOOOOOOOOOOO. 8..
O. .OOOOOOOOOOOOOOOOOOOOO O.
7O OOOOOOOOOOOOOOOOOOOOOOOO8 O.
,O. OOOOOOO.. OOOOOOOO. O,
IO OO OOOOOOOOO. OOOOOOOOOO..O
.O .8OO OOOOOOOOO. OOOOOOOOOOO O
O OOOO 8OOOOOOOOO. OOOOOOOOOOOZ ,O
O .OOO. .OOOOOOOOOO OOOOOOOOOOOOO .8
.Z 7OOO .OOOOOOOOO .OOOOOOOOOOOOO 8.
.O OOOO. OOO~..ZOOO. .OOO. +OOOOOOO: O.
.O OOO. .OI. .$ Z..7O. .OOOOO~ O.
.Z $OO .ZOOOOOO ..OOOOOO OOOO O.
O O7 OOOOOOOO .OOOOOOO IOOO O
O 8 .OOOOOOOO OOOOOOOO OOOZ .O
8 .OOOOOOOO OOOOOOOO OOO .O.
?O OOOOOOOO OOOOOOO. .OO..O.
O+ OOOOOOO +OOOOOO? ..OO O,
78 OOOOI .,O8 OOOO8. .OO8 .O
O. . . OOOOOO7.. ..OOOO .8
.?O .7OOOOOOOOOOOOOOO.. .8.
78 .,OOOOOOO. 7O..
:OO+. .ZO8.
..=OO$,
We are the humans behind bbPress
/* TEAM */
Name: Matt Mullenweg
Title: Founding Developer
Twitter: photomatt
Favorite Food: BBQ
Name: John James Jacoby
Title: Lead Developer
Twitter: jjj
Favorite Food: Truffle Lasagna
Name: Jennifer M. Dodd
Title: Core Contributor
Twitter: jmdodd
Name: Stephen Edgar
Title: Core Contributor
Twitter: netweb
Favorite Food: Tacos 🌮
Name: Sergey Biryukov
Title: Core Contributor
Twitter: sergeybiryukov
/* THANKS */
Mike Adams, Gautam Gupta, Ben L, Justin Tadlock, Pippin Williamson, cnorris23, anointed, andy, nacin
/* META */
Updated: 2017/09/09
See: http://humanstxt.org/

View File

@@ -0,0 +1,344 @@
<?php
/**
* bbPress Admin Actions
*
* This file contains the actions that are used through-out bbPress Admin. They
* are consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional actions can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in class-bbp-admin.php
*
* @package bbPress
* @subpackage Administration
*
* @see bbp-core-actions.php
* @see bbp-core-filters.php
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_action( 'wpmu_new_blog', 'bbp_new_site', 10, 6 );
add_action( 'current_screen', 'bbp_current_screen' );
add_action( 'tool_box', 'bbp_admin_tool_box' );
add_action( 'admin_menu', 'bbp_admin_menu' );
add_action( 'admin_init', 'bbp_admin_init' );
add_action( 'admin_head', 'bbp_admin_head' );
add_action( 'admin_notices', 'bbp_admin_notices' );
add_action( 'menu_order', 'bbp_admin_menu_order' );
add_filter( 'custom_menu_order', 'bbp_admin_custom_menu_order' );
// Hook on to admin_init
add_action( 'bbp_admin_init', 'bbp_setup_updater', 999 );
add_action( 'bbp_admin_init', 'bbp_register_importers' );
add_action( 'bbp_admin_init', 'bbp_register_admin_styles' );
add_action( 'bbp_admin_init', 'bbp_register_admin_scripts' );
add_action( 'bbp_admin_init', 'bbp_register_admin_settings' );
// Hook on to current_screen (only in Site admin, not Network or User)
if ( is_blog_admin() ) {
add_action( 'bbp_current_screen', 'bbp_admin_forums' );
add_action( 'bbp_current_screen', 'bbp_admin_topics' );
add_action( 'bbp_current_screen', 'bbp_admin_replies' );
}
// Initialize the admin area
add_action( 'bbp_init', 'bbp_setup_admin' );
// Reset the menu order
add_action( 'bbp_admin_menu', 'bbp_admin_separator' );
// Activation
add_action( 'bbp_activation', 'bbp_setup_new_site' );
add_action( 'bbp_activation', 'bbp_add_activation_redirect' );
add_action( 'bbp_activation', 'bbp_delete_rewrite_rules' );
add_action( 'bbp_activation', 'bbp_make_current_user_keymaster' );
add_action( 'load-plugins.php', 'bbp_do_activation_redirect' );
// Deactivation
add_action( 'bbp_deactivation', 'bbp_remove_caps' );
add_action( 'bbp_deactivation', 'bbp_delete_rewrite_rules' );
// New Site
add_action( 'bbp_new_site', 'bbp_setup_new_site', 8 );
// Load the default repair tools
add_action( 'load-tools_page_bbp-repair', 'bbp_register_default_repair_tools' );
add_action( 'load-tools_page_bbp-upgrade', 'bbp_register_default_repair_tools' );
// Contextual Helpers
add_action( 'load-settings_page_bbpress', 'bbp_admin_settings_help' );
add_action( 'load-tools_page_bbp-repair', 'bbp_admin_tools_repair_help' );
add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_tools_repair_help' );
add_action( 'load-tools_page_bbp-converter', 'bbp_admin_tools_converter_help' );
add_action( 'load-tools_page_bbp-reset', 'bbp_admin_tools_reset_help' );
// Handle submission of Tools pages
add_action( 'load-tools_page_bbp-repair', 'bbp_admin_repair_handler' );
add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_repair_handler' );
add_action( 'load-tools_page_bbp-reset', 'bbp_admin_reset_handler' );
add_action( 'bbp_admin_tool_box', 'bbp_admin_tools_box' );
// Add sample permalink filter
add_filter( 'post_type_link', 'bbp_filter_sample_permalink', 10, 4 );
// Add quick stats to dashboard glance elements
add_filter( 'dashboard_glance_items', 'bbp_filter_dashboard_glance_items', -99 );
// Maybe use icons for column headers
add_filter( 'bbp_admin_forums_column_headers', 'bbp_filter_column_headers' );
add_filter( 'bbp_admin_topics_column_headers', 'bbp_filter_column_headers' );
add_filter( 'bbp_admin_replies_column_headers', 'bbp_filter_column_headers' );
// Load the converter early (page and AJAX)
add_action( 'load-tools_page_bbp-converter', 'bbp_setup_converter', 2 );
add_action( 'wp_ajax_bbp_converter_process', 'bbp_setup_converter', 2 );
// Add New User
add_action( 'user_new_form', 'bbp_add_user_form_role_field', 10, 1 );
/**
* Setup bbPress admin
*
* @since 2.0.0 bbPress (r1000)
* @since 2.6.0 bbPress (r6598) Moved to actions.php
*/
function bbp_admin() {
return bbp_setup_admin();
}
/**
* When a new site is created in a multisite installation, run the activation
* routine on that site
*
* @since 2.0.0 bbPress (r3283)
*
* @param int $blog_id
* @param int $user_id
* @param string $domain
* @param string $path
* @param int $site_id
* @param array() $meta
*/
function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
// Bail if plugin is not network activated
if ( ! is_plugin_active_for_network( bbpress()->basename ) ) {
return;
}
// Switch to the new site
bbp_switch_to_site( $blog_id );
// Do the bbPress activation routine
do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
// Restore original site
bbp_restore_current_site();
}
/**
* Show icons in list-table column headers instead of strings
*
* @since 2.6.0 bbPress (r5833)
*
* @param array $columns Column headers fed into list-table objects
*
* @return array Possibly altered column headers
*/
function bbp_filter_column_headers( $columns = array() ) {
// Do not filter column headers by default - maybe we'll turn it on later
if ( ! apply_filters( 'bbp_filter_column_headers', false ) ) {
return $columns;
}
/** Forums ****************************************************************/
// Forum topic count
if ( isset( $columns[ 'bbp_forum_topic_count' ] ) ) {
$columns[ 'bbp_forum_topic_count' ] = '<span class="vers bbp_topics_column" title="' . esc_attr__( 'Topics', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Topics', 'bbpress' ) . '</span></span>';
}
// Forum reply count
if ( isset( $columns[ 'bbp_forum_reply_count' ] ) ) {
$columns[ 'bbp_forum_reply_count' ] = '<span class="vers bbp_replies_column" title="' . esc_attr__( 'Replies', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Replies', 'bbpress' ) . '</span></span>';
}
/** Topics ****************************************************************/
// Topic forum
if ( isset( $columns[ 'bbp_topic_forum' ] ) ) {
$columns[ 'bbp_topic_forum' ] = '<span class="vers bbp_forums_column" title="' . esc_attr__( 'Forum', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Forum', 'bbpress' ) . '</span></span>';
}
// Topic reply count
if ( isset( $columns[ 'bbp_topic_reply_count' ] ) ) {
$columns[ 'bbp_topic_reply_count' ] = '<span class="vers bbp_replies_column" title="' . esc_attr__( 'Replies', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Replies', 'bbpress' ) . '</span></span>';
}
/** Replies ***************************************************************/
// Reply forum
if ( isset( $columns[ 'bbp_reply_forum' ] ) ) {
$columns[ 'bbp_reply_forum' ] = '<span class="vers bbp_forums_column" title="' . esc_attr__( 'Forum', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Forum', 'bbpress' ) . '</span></span>';
}
// Reply topic
if ( isset( $columns[ 'bbp_reply_topic' ] ) ) {
$columns[ 'bbp_reply_topic' ] = '<span class="vers bbp_topics_column" title="' . esc_attr__( 'Topic', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Topic', 'bbpress' ) . '</span></span>';
}
return $columns;
}
/**
* Filter sample permalinks so that certain languages display properly.
*
* @since 2.0.0 bbPress (r3336)
*
* @param string $post_link Custom post type permalink
* @param object $_post Post data object
* @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
* @param bool $sample Optional, defaults to false. Is it a sample permalink.
*
* @return string The custom post type permalink
*/
function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) {
// Bail if not on an admin page and not getting a sample permalink
if ( ! empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) {
return urldecode( $post_link );
}
// Return post link
return $post_link;
}
/** Sub-Actions ***************************************************************/
/**
* Piggy back admin_init action
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_admin_init() {
do_action( 'bbp_admin_init' );
}
/**
* Piggy back admin_menu action
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_admin_menu() {
do_action( 'bbp_admin_menu' );
}
/**
* Piggy back admin_head action
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_admin_head() {
do_action( 'bbp_admin_head' );
}
/**
* Piggy back admin_notices action
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_admin_notices() {
do_action( 'bbp_admin_notices' );
}
/**
* Dedicated action to register bbPress importers
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_register_importers() {
do_action( 'bbp_register_importers' );
}
/**
* Dedicated action to register admin styles
*
* @since 2.6.0 bbPress (r6912)
*/
function bbp_register_admin_styles() {
/**
* Action used to register the admin styling
*
* @since 2.1.0
* @deprecated 2.6.0
*/
do_action( 'bbp_register_admin_style' );
/**
* Action used to register all admin styling
*
* @since 2.6.0
*/
do_action( 'bbp_register_admin_styles' );
}
/**
* Dedicated action to register admin scripts
*
* @since 2.6.0 bbPress (r6912)
*/
function bbp_register_admin_scripts() {
do_action( 'bbp_register_admin_scripts' );
}
/**
* Dedicated action to register admin settings
*
* @since 2.1.0 bbPress (r3766)
*/
function bbp_register_admin_settings() {
do_action( 'bbp_register_admin_settings' );
}
/**
* Dedicated action to output admin tools.php sections
*
* @since 2.6.0 bbPress (r6273)
*/
function bbp_admin_tool_box() {
do_action( 'bbp_admin_tool_box' );
}
/**
* Dedicated action to hook into the current screen
*
* @since 2.6.0 bbPress (r6185)
*
* @param WP_Screen $current_screen
*/
function bbp_current_screen( $current_screen = '' ) {
do_action( 'bbp_current_screen', $current_screen );
}

View File

@@ -0,0 +1,653 @@
/* Kludge for too-wide forums dropdown */
#poststuff #bbp_forum_attributes select#parent_id,
#poststuff #bbp_topic_attributes select#parent_id,
#poststuff #bbp_reply_attributes select#bbp_forum_id,
#poststuff #bbp_reply_attributes select#bbp_reply_to {
max-width: 170px;
}
/* Version Badge */
.bbp-badge {
transform-origin: top right;
animation: swoop 16s infinite linear;
}
.bbp-bee {
font: 400 80px/1 dashicons !important;
color: #000;
position: absolute;
height: 60px;
width: 60px;
}
.bbp-hive {
font: 400 150px/1 dashicons !important;
color: #ccc;
position: absolute;
height: 150px;
width: 150px;
top: 0;
left: 0;
display: block;
}
.bbp-bee::before {
content: "\f451";
}
.bbp-hive::before {
content: "\f449";
}
.notice-bbpress {
border-right: 4px solid #78cd95;
padding-right: 36px;
background-color: rgb(235, 255, 235);
position: relative;
}
.notice-bbpress .bbpress-logo-icon {
position: absolute;
height: auto;
width: auto;
padding: 7px 9px;
top: 50%;
right: 0;
transform: translateY(-50%);
font: 400 24px/1 dashicons !important;
}
.notice-bbpress .bbpress-logo-icon::before {
content: "\f477";
color: #555;
}
@keyframes buzz {
0% {
left: -2px;
top: -1px;
}
25% {
left: 1px;
top: 2px;
}
50% {
left: -3px;
top: -1px;
}
75% {
left: 2px;
top: 1px;
}
0% {
left: -2px;
top: -1px;
}
}
@keyframes swoop {
0% {
transform: rotate(-95deg);
}
100% {
transform: rotate(-455deg);
}
}
.about-wrap .bbp-badge {
position: absolute;
left: 50px;
top: 50px;
height: 25px;
width: 25px;
}
body.rtl .about-wrap .bbp-badge {
left: auto;
right: 50px;
}
/* Dashicons */
th .bbp_forums_column::before,
#dashboard_right_now a.bbp-glance-forums::before,
#adminmenu #menu-posts-forum .wp-menu-image::before {
content: "\f449";
}
th .bbp_topics_column::before,
#dashboard_right_now a.bbp-glance-topics::before,
#adminmenu #menu-posts-topic .wp-menu-image::before {
content: "\f450";
}
th .bbp_replies_column::before,
#dashboard_right_now a.bbp-glance-replies::before,
#adminmenu #menu-posts-reply .wp-menu-image::before {
content: "\f451";
}
#dashboard_right_now a.bbp-glance-topic-tags::before {
content: "\f323";
}
#dashboard_right_now a.bbp-glance-users::before {
content: "\f110";
}
th .bbp_forums_column,
th .bbp_topics_column,
th .bbp_replies_column {
height: 16px;
width: 16px;
}
th .bbp_forums_column::before,
th .bbp_topics_column::before,
th .bbp_replies_column::before {
font: 400 20px/0.5 dashicons;
speak: none;
display: inline-block;
padding: 0;
top: 4px;
right: -4px;
position: relative;
vertical-align: top;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: none !important;
color: #444;
}
/* Deprecated Dashboard Metabox */
#bbp-dashboard-right-now p.sub,
#bbp-dashboard-right-now .table,
#bbp-dashboard-right-now .versions {
margin: -12px;
}
#bbp-dashboard-right-now .inside {
font-size: 12px;
padding-top: 20px;
margin-bottom: 0;
}
#bbp-dashboard-right-now p.sub {
padding: 5px 0 15px;
color: #8f8f8f;
font-size: 14px;
position: absolute;
top: -17px;
right: 15px;
}
body.rtl #bbp-dashboard-right-now p.sub {
left: 15px;
right: 0;
}
#bbp-dashboard-right-now .table {
margin: 0;
padding: 0;
position: relative;
}
#bbp-dashboard-right-now .table_content {
float: right;
border-top: #ececec 1px solid;
width: 45%;
}
body.rtl #bbp-dashboard-right-now .table_content {
float: left;
}
#bbp-dashboard-right-now .table_discussion {
float: left;
border-top: #ececec 1px solid;
width: 45%;
}
body.rtl #bbp-dashboard-right-now .table_discussion {
float: right;
}
#bbp-dashboard-right-now table td {
padding: 3px 0;
white-space: nowrap;
}
#bbp-dashboard-right-now table tr.first td {
border-top: none;
}
#bbp-dashboard-right-now td.b {
padding-left: 6px;
text-align: left;
font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
font-size: 14px;
width: 1%;
}
body.rtl #bbp-dashboard-right-now td.b {
padding-right: 6px;
padding-left: 0;
}
#bbp-dashboard-right-now td.b a {
font-size: 18px;
}
#bbp-dashboard-right-now td.b a:hover {
color: #d54e21;
}
#bbp-dashboard-right-now .t {
font-size: 12px;
padding-left: 12px;
padding-top: 6px;
color: #777;
}
body.rtl #bbp-dashboard-right-now .t {
padding-right: 12px;
padding-left: 0;
}
#bbp-dashboard-right-now .t a {
white-space: nowrap;
}
#bbp-dashboard-right-now .spam {
color: #f00;
}
#bbp-dashboard-right-now .waiting {
color: #e66f00;
}
#bbp-dashboard-right-now .approved {
color: #0f0;
}
#bbp-dashboard-right-now .versions {
padding: 6px 10px 12px;
clear: both;
}
#bbp-dashboard-right-now .versions .b {
font-weight: 700;
}
#bbp-dashboard-right-now a.button {
float: left;
clear: left;
position: relative;
top: -5px;
}
body.rtl #bbp-dashboard-right-now a.button {
float: right;
clear: right;
}
/* List Tables */
body.post-type-forum #minor-publishing,
body.post-type-forum #save-post {
display: none;
}
body.post-type-forum strong.label,
body.post-type-topic strong.label,
body.post-type-reply strong.label {
display: inline-block;
width: 60px;
}
.column-bbp_forum_topic_count,
.column-bbp_forum_reply_count,
.column-bbp_topic_reply_count,
.column-bbp_topic_voice_count {
width: 8% !important;
}
.column-author,
.column-bbp_forum_mods,
.column-bbp_reply_author,
.column-bbp_topic_author {
width: 10% !important;
}
.column-bbp_topic_forum,
.column-bbp_reply_forum,
.column-bbp_reply_topic {
width: 10% !important;
}
.column-bbp_forum_freshness,
.column-bbp_topic_freshness {
width: 10% !important;
}
.column-bbp_user_role,
.column-bbp_forum_created,
.column-bbp_topic_created,
.column-bbp_reply_created {
width: 15% !important;
}
.column-bbp_topic_reply_author,
.column-bbp_forum_topic_author {
width: 25% !important;
}
.column-bbp_topic_reply_author .avatar,
.column-bbp_forum_topic_author .avatar {
float: right;
margin-left: 10px;
}
#bbp_moderators {
width: 100%;
}
#bbp_forum_attributes hr {
border-style: solid;
border-width: 1px;
border-color: #ccc #ccc #fff #fff;
}
body.post-type-forum tbody .status-closed,
body.post-type-topic tbody .status-closed,
body.post-type-reply tbody .status-closed {
background-color: #f5f5f5;
}
body.post-type-forum tbody .status-closed:nth-child(odd),
body.post-type-topic tbody .status-closed:nth-child(odd),
body.post-type-reply tbody .status-closed:nth-child(odd) {
background-color: #f0f0f0;
}
body.post-type-forum tbody .status-spam,
body.post-type-topic tbody .status-spam,
body.post-type-reply tbody .status-spam,
#bbp-reply-list .status-trash {
background-color: #fee;
}
body.post-type-forum tbody .status-spam:nth-child(odd),
body.post-type-topic tbody .status-spam:nth-child(odd),
body.post-type-reply tbody .status-spam:nth-child(odd),
#bbp-reply-list .status-trash:nth-child(odd) {
background-color: #fdd;
}
body.post-type-forum tbody .status-pending,
body.post-type-topic tbody .status-pending,
body.post-type-reply tbody .status-pending {
background-color: #fff2e8;
}
body.post-type-forum tbody .status-pending:nth-child(odd),
body.post-type-topic tbody .status-pending:nth-child(odd),
body.post-type-reply tbody .status-pending:nth-child(odd) {
background-color: #fff7f1;
}
body.post-type-forum tbody .status-closed td,
body.post-type-topic tbody .status-closed td,
body.post-type-reply tbody .status-closed td,
body.post-type-forum tbody .status-spam td,
body.post-type-topic tbody .status-spam td,
body.post-type-reply tbody .status-spam td,
#bbp-reply-list .status-trash td {
color: #999;
}
body.post-type-forum tbody .row-actions .unspam a,
body.post-type-topic tbody .row-actions .unspam a,
body.post-type-reply tbody .row-actions .unspam a,
body.post-type-forum tbody .row-actions .approved a,
body.post-type-topic tbody .row-actions .approved a,
body.post-type-reply tbody .row-actions .approved a {
color: #006505;
}
/* User Relationships */
#bbp_topic_engagements_metabox .avatar,
#bbp_topic_favorites_metabox .avatar,
#bbp_topic_subscriptions_metabox .avatar {
margin: 3px;
}
/* Converter */
.bbp-converter-settings-wrap {
float: right;
width: 55%;
}
#poststuff.bbp-converter-monitor-wrap {
float: left;
width: 43%;
margin-right: 2%;
min-width: 200px;
}
#bbp-converter-monitor h2 {
position: relative;
}
#bbp-converter-monitor .inside {
margin: 0;
padding: 5px;
border-bottom: 1px solid #e5e5e5;
}
#bbp-converter-monitor div.actions {
padding: 10px;
background: #fafafa;
clear: both;
}
#bbp-converter-spinner {
margin: 4px 0;
}
div.bbp-converter-log,
div.bbp-converter-warning {
padding: 5px 5px 5px 0;
}
div.bbp-converter-log.started {
height: 300px;
overflow: auto;
}
div.bbp-converter-log p {
margin: 0;
padding: 2px;
}
div.bbp-converter-log p:only-child {
float: none;
margin-bottom: 0;
}
div.bbp-converter-log div {
padding: 10px;
margin: 5px;
background: #f4f4f4;
border: 1px solid #ddd;
}
div.bbp-converter-log div code {
margin-top: 5px;
display: block;
}
div.bbp-converter-log .step {
text-align: left;
font-weight: 600;
}
div.bbp-converter-log .output {
margin: 0 5px;
}
div.bbp-converter-log .mini-step {
padding: 3px 5px;
vertical-align: middle;
font-size: 8px;
font-weight: 600;
border-radius: 6px;
background-color: #aaa;
color: #fff;
}
#bbp-converter-monitor .bbp-progress-bar {
position: absolute;
right: 0;
height: 1px;
width: 0;
background-color: #00b9eb;
transition-property: width;
transition-timing-function: ease-out;
transition-duration: 1s;
}
#bbp-converter-monitor #bbp-converter-step-percentage {
bottom: 1px;
}
#bbp-converter-monitor #bbp-converter-total-percentage {
bottom: 0;
}
#bbp-converter-stop {
display: none;
}
#bbp-converter-status {
font-weight: 400;
font-size: 12px;
color: #aaa;
display: block;
margin-top: 2px;
}
.bbp-converter-db-password-wrapper {
display: inline-block;
position: relative;
}
.bbp-converter-db-pass::-webkit-credentials-auto-fill-button {
display: none;
visibility: hidden;
pointer-events: none;
position: absolute;
left: 0;
}
button.bbp-db-pass-toggle {
border: none;
background: transparent;
position: absolute;
left: 3px;
top: 3px;
padding: 0;
margin: 0;
cursor: pointer;
color: #aaa;
height: 25px;
width: 25px;
font: 400 20px/1 dashicons !important;
}
button.bbp-db-pass-toggle:hover {
color: #888;
}
button.bbp-db-pass-toggle.text::after {
content: "\f530";
}
button.bbp-db-pass-toggle.password::after {
content: "\f177";
}
@media screen and ( max-width: 782px ) {
.bbp-converter-db-password-wrapper {
width: 100%;
}
#poststuff.bbp-converter-monitor-wrap,
.bbp-converter-settings-wrap {
float: none;
width: 100%;
margin: 20px 0;
}
button.bbp-db-pass-toggle {
height: 35px;
width: 35px;
font: 400 20px/1 dashicons !important;
}
}
/* Tools */
td.bbp-tool-title strong {
display: block;
}
td.bbp-tool-title p {
margin: 0;
}
.manage-column.column-components {
width: 20%;
}
.manage-column.column-version {
width: 11%;
}
.manage-column.column-overhead {
width: 13%;
}
.nav-tab-wrapper a span.awaiting-mod {
display: inline-block;
vertical-align: top;
margin: 3px 1px 0 0;
padding: 0 5px;
min-width: 7px;
height: 17px;
border-radius: 11px;
background-color: #ca4a1f;
color: #fff;
font-size: 9px;
line-height: 17px;
text-align: center;
z-index: 26;
}
/* Retro TV corners for contributor avatars */
.dashboard_page_bbp-credits .wp-person img {
border-radius: 20px;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,653 @@
/* Kludge for too-wide forums dropdown */
#poststuff #bbp_forum_attributes select#parent_id,
#poststuff #bbp_topic_attributes select#parent_id,
#poststuff #bbp_reply_attributes select#bbp_forum_id,
#poststuff #bbp_reply_attributes select#bbp_reply_to {
max-width: 170px;
}
/* Version Badge */
.bbp-badge {
transform-origin: top left;
animation: swoop 16s infinite linear;
}
.bbp-bee {
font: 400 80px/1 dashicons !important;
color: #000;
position: absolute;
height: 60px;
width: 60px;
}
.bbp-hive {
font: 400 150px/1 dashicons !important;
color: #ccc;
position: absolute;
height: 150px;
width: 150px;
top: 0;
right: 0;
display: block;
}
.bbp-bee::before {
content: "\f451";
}
.bbp-hive::before {
content: "\f449";
}
.notice-bbpress {
border-left: 4px solid #78cd95;
padding-left: 36px;
background-color: rgb(235, 255, 235);
position: relative;
}
.notice-bbpress .bbpress-logo-icon {
position: absolute;
height: auto;
width: auto;
padding: 7px 9px;
top: 50%;
left: 0;
transform: translateY(-50%);
font: 400 24px/1 dashicons !important;
}
.notice-bbpress .bbpress-logo-icon::before {
content: "\f477";
color: #555;
}
@keyframes buzz {
0% {
right: -2px;
top: -1px;
}
25% {
right: 1px;
top: 2px;
}
50% {
right: -3px;
top: -1px;
}
75% {
right: 2px;
top: 1px;
}
0% {
right: -2px;
top: -1px;
}
}
@keyframes swoop {
0% {
transform: rotate(95deg);
}
100% {
transform: rotate(455deg);
}
}
.about-wrap .bbp-badge {
position: absolute;
right: 50px;
top: 50px;
height: 25px;
width: 25px;
}
body.rtl .about-wrap .bbp-badge {
right: auto;
left: 50px;
}
/* Dashicons */
th .bbp_forums_column::before,
#dashboard_right_now a.bbp-glance-forums::before,
#adminmenu #menu-posts-forum .wp-menu-image::before {
content: "\f449";
}
th .bbp_topics_column::before,
#dashboard_right_now a.bbp-glance-topics::before,
#adminmenu #menu-posts-topic .wp-menu-image::before {
content: "\f450";
}
th .bbp_replies_column::before,
#dashboard_right_now a.bbp-glance-replies::before,
#adminmenu #menu-posts-reply .wp-menu-image::before {
content: "\f451";
}
#dashboard_right_now a.bbp-glance-topic-tags::before {
content: "\f323";
}
#dashboard_right_now a.bbp-glance-users::before {
content: "\f110";
}
th .bbp_forums_column,
th .bbp_topics_column,
th .bbp_replies_column {
height: 16px;
width: 16px;
}
th .bbp_forums_column::before,
th .bbp_topics_column::before,
th .bbp_replies_column::before {
font: 400 20px/0.5 dashicons;
speak: none;
display: inline-block;
padding: 0;
top: 4px;
left: -4px;
position: relative;
vertical-align: top;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: none !important;
color: #444;
}
/* Deprecated Dashboard Metabox */
#bbp-dashboard-right-now p.sub,
#bbp-dashboard-right-now .table,
#bbp-dashboard-right-now .versions {
margin: -12px;
}
#bbp-dashboard-right-now .inside {
font-size: 12px;
padding-top: 20px;
margin-bottom: 0;
}
#bbp-dashboard-right-now p.sub {
padding: 5px 0 15px;
color: #8f8f8f;
font-size: 14px;
position: absolute;
top: -17px;
left: 15px;
}
body.rtl #bbp-dashboard-right-now p.sub {
right: 15px;
left: 0;
}
#bbp-dashboard-right-now .table {
margin: 0;
padding: 0;
position: relative;
}
#bbp-dashboard-right-now .table_content {
float: left;
border-top: #ececec 1px solid;
width: 45%;
}
body.rtl #bbp-dashboard-right-now .table_content {
float: right;
}
#bbp-dashboard-right-now .table_discussion {
float: right;
border-top: #ececec 1px solid;
width: 45%;
}
body.rtl #bbp-dashboard-right-now .table_discussion {
float: left;
}
#bbp-dashboard-right-now table td {
padding: 3px 0;
white-space: nowrap;
}
#bbp-dashboard-right-now table tr.first td {
border-top: none;
}
#bbp-dashboard-right-now td.b {
padding-right: 6px;
text-align: right;
font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
font-size: 14px;
width: 1%;
}
body.rtl #bbp-dashboard-right-now td.b {
padding-left: 6px;
padding-right: 0;
}
#bbp-dashboard-right-now td.b a {
font-size: 18px;
}
#bbp-dashboard-right-now td.b a:hover {
color: #d54e21;
}
#bbp-dashboard-right-now .t {
font-size: 12px;
padding-right: 12px;
padding-top: 6px;
color: #777;
}
body.rtl #bbp-dashboard-right-now .t {
padding-left: 12px;
padding-right: 0;
}
#bbp-dashboard-right-now .t a {
white-space: nowrap;
}
#bbp-dashboard-right-now .spam {
color: #f00;
}
#bbp-dashboard-right-now .waiting {
color: #e66f00;
}
#bbp-dashboard-right-now .approved {
color: #0f0;
}
#bbp-dashboard-right-now .versions {
padding: 6px 10px 12px;
clear: both;
}
#bbp-dashboard-right-now .versions .b {
font-weight: 700;
}
#bbp-dashboard-right-now a.button {
float: right;
clear: right;
position: relative;
top: -5px;
}
body.rtl #bbp-dashboard-right-now a.button {
float: left;
clear: left;
}
/* List Tables */
body.post-type-forum #minor-publishing,
body.post-type-forum #save-post {
display: none;
}
body.post-type-forum strong.label,
body.post-type-topic strong.label,
body.post-type-reply strong.label {
display: inline-block;
width: 60px;
}
.column-bbp_forum_topic_count,
.column-bbp_forum_reply_count,
.column-bbp_topic_reply_count,
.column-bbp_topic_voice_count {
width: 8% !important;
}
.column-author,
.column-bbp_forum_mods,
.column-bbp_reply_author,
.column-bbp_topic_author {
width: 10% !important;
}
.column-bbp_topic_forum,
.column-bbp_reply_forum,
.column-bbp_reply_topic {
width: 10% !important;
}
.column-bbp_forum_freshness,
.column-bbp_topic_freshness {
width: 10% !important;
}
.column-bbp_user_role,
.column-bbp_forum_created,
.column-bbp_topic_created,
.column-bbp_reply_created {
width: 15% !important;
}
.column-bbp_topic_reply_author,
.column-bbp_forum_topic_author {
width: 25% !important;
}
.column-bbp_topic_reply_author .avatar,
.column-bbp_forum_topic_author .avatar {
float: left;
margin-right: 10px;
}
#bbp_moderators {
width: 100%;
}
#bbp_forum_attributes hr {
border-style: solid;
border-width: 1px;
border-color: #ccc #fff #fff #ccc;
}
body.post-type-forum tbody .status-closed,
body.post-type-topic tbody .status-closed,
body.post-type-reply tbody .status-closed {
background-color: #f5f5f5;
}
body.post-type-forum tbody .status-closed:nth-child(odd),
body.post-type-topic tbody .status-closed:nth-child(odd),
body.post-type-reply tbody .status-closed:nth-child(odd) {
background-color: #f0f0f0;
}
body.post-type-forum tbody .status-spam,
body.post-type-topic tbody .status-spam,
body.post-type-reply tbody .status-spam,
#bbp-reply-list .status-trash {
background-color: #fee;
}
body.post-type-forum tbody .status-spam:nth-child(odd),
body.post-type-topic tbody .status-spam:nth-child(odd),
body.post-type-reply tbody .status-spam:nth-child(odd),
#bbp-reply-list .status-trash:nth-child(odd) {
background-color: #fdd;
}
body.post-type-forum tbody .status-pending,
body.post-type-topic tbody .status-pending,
body.post-type-reply tbody .status-pending {
background-color: #fff2e8;
}
body.post-type-forum tbody .status-pending:nth-child(odd),
body.post-type-topic tbody .status-pending:nth-child(odd),
body.post-type-reply tbody .status-pending:nth-child(odd) {
background-color: #fff7f1;
}
body.post-type-forum tbody .status-closed td,
body.post-type-topic tbody .status-closed td,
body.post-type-reply tbody .status-closed td,
body.post-type-forum tbody .status-spam td,
body.post-type-topic tbody .status-spam td,
body.post-type-reply tbody .status-spam td,
#bbp-reply-list .status-trash td {
color: #999;
}
body.post-type-forum tbody .row-actions .unspam a,
body.post-type-topic tbody .row-actions .unspam a,
body.post-type-reply tbody .row-actions .unspam a,
body.post-type-forum tbody .row-actions .approved a,
body.post-type-topic tbody .row-actions .approved a,
body.post-type-reply tbody .row-actions .approved a {
color: #006505;
}
/* User Relationships */
#bbp_topic_engagements_metabox .avatar,
#bbp_topic_favorites_metabox .avatar,
#bbp_topic_subscriptions_metabox .avatar {
margin: 3px;
}
/* Converter */
.bbp-converter-settings-wrap {
float: left;
width: 55%;
}
#poststuff.bbp-converter-monitor-wrap {
float: right;
width: 43%;
margin-left: 2%;
min-width: 200px;
}
#bbp-converter-monitor h2 {
position: relative;
}
#bbp-converter-monitor .inside {
margin: 0;
padding: 5px;
border-bottom: 1px solid #e5e5e5;
}
#bbp-converter-monitor div.actions {
padding: 10px;
background: #fafafa;
clear: both;
}
#bbp-converter-spinner {
margin: 4px 0;
}
div.bbp-converter-log,
div.bbp-converter-warning {
padding: 5px 0 5px 5px;
}
div.bbp-converter-log.started {
height: 300px;
overflow: auto;
}
div.bbp-converter-log p {
margin: 0;
padding: 2px;
}
div.bbp-converter-log p:only-child {
float: none;
margin-bottom: 0;
}
div.bbp-converter-log div {
padding: 10px;
margin: 5px;
background: #f4f4f4;
border: 1px solid #ddd;
}
div.bbp-converter-log div code {
margin-top: 5px;
display: block;
}
div.bbp-converter-log .step {
text-align: right;
font-weight: 600;
}
div.bbp-converter-log .output {
margin: 0 5px;
}
div.bbp-converter-log .mini-step {
padding: 3px 5px;
vertical-align: middle;
font-size: 8px;
font-weight: 600;
border-radius: 6px;
background-color: #aaa;
color: #fff;
}
#bbp-converter-monitor .bbp-progress-bar {
position: absolute;
left: 0;
height: 1px;
width: 0;
background-color: #00b9eb;
transition-property: width;
transition-timing-function: ease-out;
transition-duration: 1s;
}
#bbp-converter-monitor #bbp-converter-step-percentage {
bottom: 1px;
}
#bbp-converter-monitor #bbp-converter-total-percentage {
bottom: 0;
}
#bbp-converter-stop {
display: none;
}
#bbp-converter-status {
font-weight: 400;
font-size: 12px;
color: #aaa;
display: block;
margin-top: 2px;
}
.bbp-converter-db-password-wrapper {
display: inline-block;
position: relative;
}
.bbp-converter-db-pass::-webkit-credentials-auto-fill-button {
display: none;
visibility: hidden;
pointer-events: none;
position: absolute;
right: 0;
}
button.bbp-db-pass-toggle {
border: none;
background: transparent;
position: absolute;
right: 3px;
top: 3px;
padding: 0;
margin: 0;
cursor: pointer;
color: #aaa;
height: 25px;
width: 25px;
font: 400 20px/1 dashicons !important;
}
button.bbp-db-pass-toggle:hover {
color: #888;
}
button.bbp-db-pass-toggle.text::after {
content: "\f530";
}
button.bbp-db-pass-toggle.password::after {
content: "\f177";
}
@media screen and ( max-width: 782px ) {
.bbp-converter-db-password-wrapper {
width: 100%;
}
#poststuff.bbp-converter-monitor-wrap,
.bbp-converter-settings-wrap {
float: none;
width: 100%;
margin: 20px 0;
}
button.bbp-db-pass-toggle {
height: 35px;
width: 35px;
font: 400 20px/1 dashicons !important;
}
}
/* Tools */
td.bbp-tool-title strong {
display: block;
}
td.bbp-tool-title p {
margin: 0;
}
.manage-column.column-components {
width: 20%;
}
.manage-column.column-version {
width: 11%;
}
.manage-column.column-overhead {
width: 13%;
}
.nav-tab-wrapper a span.awaiting-mod {
display: inline-block;
vertical-align: top;
margin: 3px 0 0 1px;
padding: 0 5px;
min-width: 7px;
height: 17px;
border-radius: 11px;
background-color: #ca4a1f;
color: #fff;
font-size: 9px;
line-height: 17px;
text-align: center;
z-index: 26;
}
/* Retro TV corners for contributor avatars */
.dashboard_page_bbp-credits .wp-person img {
border-radius: 20px;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,46 @@
(function () {
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var field = document.getElementById( 'bbp-badge' ),
bee = document.getElementById( 'bbp-bee' ),
max_x = field.clientWidth - bee.offsetWidth,
max_y = field.clientHeight - bee.offsetHeight,
angle = 95,
offset = 95,
duration = 4,
canvas = 50,
start = null,
variance = 1;
function step( timestamp ) {
var progress, x, y;
if ( start === null ) {
start = timestamp;
variance = 1;
angle = 95;
}
progress = ( timestamp - start ) / duration / 1000;
angle = ( 360 * progress ) + offset;
x = variance * Math.sin( progress * 2 * Math.PI );
y = Math.cos( progress * 2 * Math.PI );
bee.style.left = max_x / 2 + ( canvas * x ) + 'px';
bee.style.bottom = max_y / 2 + ( canvas * y ) + 'px';
bee.style.transform = 'rotate(' + angle + 'deg)';
bee.style.webkitTransform = 'rotate(' + angle + 'deg)';
// Reset
if ( progress >= 1 ) {
start = null;
}
requestAnimationFrame( step );
}
requestAnimationFrame( step );
})();

View File

@@ -0,0 +1,3 @@
/*! This file is automatically generated. */
!function(){function e(t){var u,w,b;null===l&&(l=t,d=1,a=95),a=360*(u=(t-l)/r/1e3)+m,w=d*Math.sin(2*u*Math.PI),b=Math.cos(2*u*Math.PI),n.style.left=i/2+s*w+"px",n.style.bottom=o/2+s*b+"px",n.style.transform="rotate("+a+"deg)",n.style.webkitTransform="rotate("+a+"deg)",u>=1&&(l=null),requestAnimationFrame(e)}window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;var t=document.getElementById("bbp-badge"),n=document.getElementById("bbp-bee"),i=t.clientWidth-n.offsetWidth,o=t.clientHeight-n.offsetHeight,a=95,m=95,r=4,s=50,l=null,d=1;requestAnimationFrame(e)}();

View File

@@ -0,0 +1,15 @@
jQuery( document ).ready( function() {
var bbp_author_id = jQuery( '#bbp_author_id' );
bbp_author_id.suggest(
bbp_author_id.data( 'ajax-url' ),
{
minchars: 1, // Allow single-digit user IDs
onSelect: function() {
var value = this.value;
bbp_author_id.val( value.substr( 0, value.indexOf( ' ' ) ) );
}
}
);
} );

View File

@@ -0,0 +1,3 @@
/*! This file is automatically generated. */
jQuery(document).ready(function(){var a=jQuery("#bbp_author_id");a.suggest(a.data("ajax-url"),{minchars:1,onSelect:function(){var u=this.value;a.val(u.substr(0,u.indexOf(" ")))}})});

View File

@@ -0,0 +1,344 @@
/*jshint sub:true*/
/* global document, jQuery, ajaxurl, BBP_Converter */
jQuery( document ).ready( function ( $ ) {
'use strict';
// Variables
var message = $( '#bbp-converter-message' ),
stop = $( '#bbp-converter-stop' ),
start = $( '#bbp-converter-start' ),
restart = $( '#_bbp_converter_restart' ),
status = $( '#bbp-converter-status' ),
spinner = $( '#bbp-converter-spinner' ),
settings = $( '#bbp-converter-settings' ),
password = $( '#_bbp_converter_db_pass' ),
toggle = $( '.bbp-db-pass-toggle' ),
step_p = $( '#bbp-converter-step-percentage' ),
total_p = $( '#bbp-converter-total-percentage' ),
fields = settings.find( 'table:first-of-type input, table:first-of-type select' );
/**
* Show/hide db password button toggle
*
* @since 2.6.0 bbPress (r6676)
*
* @param {element} e
*/
toggle.on( 'click', function( e ) {
var type = ( password.attr( 'type' ) === 'password' ) ? 'text' : 'password';
password.attr( 'type', type );
toggle
.toggleClass( 'password' )
.toggleClass( 'text' );
e.preventDefault();
});
/**
* Start button click
*
* @since 2.6.0 bbPress (r6470)
*
* @param {element} e
*/
start.on( 'click', function( e ) {
bbp_converter_user_start();
e.preventDefault();
} );
/**
* Stop button click
*
* @since 2.6.0 bbPress (r6470)
*
* @param {element} e
*/
$( stop ).on( 'click', function( e ) {
bbp_converter_user_stop();
e.preventDefault();
} );
/**
* Start the converter
*
* @since 2.6.0 bbPress (r6470)
*
* @returns {void}
*/
function bbp_converter_user_start() {
bbp_converter_start();
}
/**
* Stop the converter
*
* @since 2.6.0 bbPress (r6470)
*
* @returns {void}
*/
function bbp_converter_user_stop() {
bbp_converter_stop(
BBP_Converter.strings.button_continue,
BBP_Converter.strings.import_stopped_user
);
}
/**
* Return values of converter settings
*
* @since 2.6.0 bbPress (r6470)
*
* @returns {converterL#2.bbp_converter_settings.values}
*/
function bbp_converter_settings() {
var values = {};
$.each( settings.serializeArray(), function( i, field ) {
values[ field.name ] = field.value;
} );
if ( values['_bbp_converter_restart'] ) {
restart.removeAttr( 'checked' );
}
if ( values['_bbp_converter_delay_time'] ) {
BBP_Converter.state.delay = parseInt( values['_bbp_converter_delay_time'], 10 ) * 1000;
}
values['action'] = 'bbp_converter_process';
values['_ajax_nonce'] = BBP_Converter.ajax_nonce;
return values;
}
/**
* Run the converter step
*
* @since 2.6.0 bbPress (r6470)
*
* @returns {void}
*/
function bbp_converter_post() {
$.post( ajaxurl, bbp_converter_settings(), function( response ) {
// Parse the json response
try {
var data = response.data;
// Success
if ( true === response.success ) {
bbp_converter_step( data );
// Failure
} else {
bbp_converter_stop();
}
} catch( e ) {
bbp_converter_stop();
}
}, 'json' );
}
/**
* Process the next step
*
* @since 2.6.0 bbPress (r6600)
*
* @param {object} data
* @returns {void}
*/
function bbp_converter_step( data ) {
// Bail if not running
if ( ! BBP_Converter.state.running ) {
return;
}
// Do the step
bbp_converter_log( data.progress );
bbp_converter_percentages( data.step_percent, data.total_percent );
bbp_converter_status( data );
bbp_converter_wait();
// Done
if ( data.current_step === data.final_step ) {
bbp_converter_stop(
BBP_Converter.strings.button_start,
BBP_Converter.strings.import_complete
);
}
}
/**
* Wait to do the next AJAX request
*
* @since 2.6.0 bbPress (r6600)
*
* @returns {void}
*/
function bbp_converter_wait() {
clearTimeout( BBP_Converter.state.running );
// Bail if not running
if ( ! BBP_Converter.state.running ) {
return;
}
// Wait, then POST
BBP_Converter.state.running = setTimeout( function() {
bbp_converter_post();
}, parseInt( BBP_Converter.state.delay, 10 ) );
}
/**
* Start the converter and set the various flags
*
* @since 2.6.0 bbPress (r6600)
*
* @returns {void}
*/
function bbp_converter_start() {
clearTimeout( BBP_Converter.state.running );
clearInterval( BBP_Converter.state.status );
BBP_Converter.state.running = true;
var log = BBP_Converter.strings.start_continue;
if ( false === BBP_Converter.state.started ) {
log = BBP_Converter.strings.start_start;
BBP_Converter.state.started = true;
}
bbp_converter_update(
BBP_Converter.strings.button_continue,
log,
BBP_Converter.strings.status_starting
);
message.addClass( 'started' );
start.hide();
stop.show();
console.log( fields );
spinner.css( 'visibility', 'visible' );
fields.prop( 'readonly', true );
bbp_converter_post();
}
/**
* Stop the converter, and update the UI
*
* @since 2.6.0 bbPress (r6470)
*
* @param {string} button New text for button
* @param {string} log New text to add to import monitor
*
* @returns {void}
*/
function bbp_converter_stop( button, log ) {
clearTimeout( BBP_Converter.state.running );
clearInterval( BBP_Converter.state.status );
BBP_Converter.state.running = false;
BBP_Converter.state.status = false;
if ( ! button ) {
button = BBP_Converter.strings.button_continue;
}
if ( ! log ) {
log = BBP_Converter.strings.status_stopped;
}
bbp_converter_update(
button,
log,
BBP_Converter.strings.status_stopped
);
start.show();
stop.hide();
spinner.css( 'visibility', 'hidden' );
fields.prop( 'readonly', false );
}
/**
* Update the various screen texts
*
* @since 2.6.0 bbPress (r6600)
*
* @param {string} b_text
* @param {string} p_text
* @param {string} s_text
*
* @returns {void}
*/
function bbp_converter_update( b_text, p_text, s_text ) {
start.val( b_text );
bbp_converter_log( p_text );
status.text( s_text );
}
/**
* Update the status
*
* @since 2.6.0 bbPress (r6513)
*
* @param {object} data
*
* @returns {void}
*/
function bbp_converter_status( data ) {
var remaining = parseInt( BBP_Converter.state.delay, 10 ) / 1000;
status.text( BBP_Converter.strings.status_counting.replace( '%s', remaining ) );
clearInterval( BBP_Converter.state.status );
BBP_Converter.state.status = setInterval( function() {
remaining--;
status.text( BBP_Converter.strings.status_counting.replace( '%s', remaining ) );
if ( remaining <= 0 ) {
clearInterval( BBP_Converter.state.status );
if ( parseInt( data.current_step, 10 ) < parseInt( data.final_step, 10 ) ) {
status.text( BBP_Converter.strings.status_up_next.replace( '%s', data.current_step ) );
} else {
status.text( BBP_Converter.strings.status_complete );
}
}
}, 1000 );
}
/**
* Prepend some text to the import monitor
*
* @since 2.6.0 bbPress (r6470)
*
* @param {string} text Text to prepend to the import monitor
*
* @returns {void}
*/
function bbp_converter_log( text ) {
text = '<p>' + text + '</p>';
message.prepend( text );
}
/**
* Prepend some text to the import monitor
*
* @since 2.6.0 bbPress (r6470)
*
* @returns {void}
*/
function bbp_converter_percentages( step_percent, total_percent ) {
step_p.width( step_percent + '%' );
total_p.width( total_percent + '%' );
}
} );

View File

@@ -0,0 +1,3 @@
/*! This file is automatically generated. */
jQuery(document).ready(function(t){"use strict";function e(){i()}function r(){c(BBP_Converter.strings.button_continue,BBP_Converter.strings.import_stopped_user)}function n(){var e={};return t.each(d.serializeArray(),function(t,r){e[r.name]=r.value}),e._bbp_converter_restart&&g.removeAttr("checked"),e._bbp_converter_delay_time&&(BBP_Converter.state.delay=1e3*parseInt(e._bbp_converter_delay_time,10)),e.action="bbp_converter_process",e._ajax_nonce=BBP_Converter.ajax_nonce,e}function s(){t.post(ajaxurl,n(),function(t){try{var e=t.data;!0===t.success?o(e):c()}catch(t){c()}},"json")}function o(t){BBP_Converter.state.running&&(p(t.progress),B(t.step_percent,t.total_percent),u(t),a(),t.current_step===t.final_step&&c(BBP_Converter.strings.button_start,BBP_Converter.strings.import_complete))}function a(){clearTimeout(BBP_Converter.state.running),BBP_Converter.state.running&&(BBP_Converter.state.running=setTimeout(function(){s()},parseInt(BBP_Converter.state.delay,10)))}function i(){clearTimeout(BBP_Converter.state.running),clearInterval(BBP_Converter.state.status),BBP_Converter.state.running=!0;var t=BBP_Converter.strings.start_continue;!1===BBP_Converter.state.started&&(t=BBP_Converter.strings.start_start,BBP_Converter.state.started=!0),_(BBP_Converter.strings.button_continue,t,BBP_Converter.strings.status_starting),v.addClass("started"),b.hide(),l.show(),console.log(h),P.css("visibility","visible"),h.prop("readonly",!0),s()}function c(t,e){clearTimeout(BBP_Converter.state.running),clearInterval(BBP_Converter.state.status),BBP_Converter.state.running=!1,BBP_Converter.state.status=!1,t||(t=BBP_Converter.strings.button_continue),e||(e=BBP_Converter.strings.status_stopped),_(t,e,BBP_Converter.strings.status_stopped),b.show(),l.hide(),P.css("visibility","hidden"),h.prop("readonly",!1)}function _(t,e,r){b.val(t),p(e),C.text(r)}function u(t){var e=parseInt(BBP_Converter.state.delay,10)/1e3;C.text(BBP_Converter.strings.status_counting.replace("%s",e)),clearInterval(BBP_Converter.state.status),BBP_Converter.state.status=setInterval(function(){e--,C.text(BBP_Converter.strings.status_counting.replace("%s",e)),e<=0&&(clearInterval(BBP_Converter.state.status),parseInt(t.current_step,10)<parseInt(t.final_step,10)?C.text(BBP_Converter.strings.status_up_next.replace("%s",t.current_step)):C.text(BBP_Converter.strings.status_complete))},1e3)}function p(t){t="<p>"+t+"</p>",v.prepend(t)}function B(t,e){m.width(t+"%"),x.width(e+"%")}var v=t("#bbp-converter-message"),l=t("#bbp-converter-stop"),b=t("#bbp-converter-start"),g=t("#_bbp_converter_restart"),C=t("#bbp-converter-status"),P=t("#bbp-converter-spinner"),d=t("#bbp-converter-settings"),f=t("#_bbp_converter_db_pass"),y=t(".bbp-db-pass-toggle"),m=t("#bbp-converter-step-percentage"),x=t("#bbp-converter-total-percentage"),h=d.find("table:first-of-type input, table:first-of-type select");y.on("click",function(t){var e="password"===f.attr("type")?"text":"password";f.attr("type",e),y.toggleClass("password").toggleClass("text"),t.preventDefault()}),b.on("click",function(t){e(),t.preventDefault()}),t(l).on("click",function(t){r(),t.preventDefault()})});

View File

@@ -0,0 +1,17 @@
jQuery( document ).ready(function() {
jQuery( '#misc-publishing-actions' ).find( '.misc-pub-section' ).first().remove();
jQuery( '#save-action' ).remove();
var bbp_topic_id = jQuery( '#bbp_topic_id' );
bbp_topic_id.suggest(
bbp_topic_id.data( 'ajax-url' ),
{
onSelect: function() {
var value = this.value;
bbp_topic_id.val( value.substr( 0, value.indexOf( ' ' ) ) );
}
}
);
} );

View File

@@ -0,0 +1,3 @@
/*! This file is automatically generated. */
jQuery(document).ready(function(){jQuery("#misc-publishing-actions").find(".misc-pub-section").first().remove(),jQuery("#save-action").remove();var e=jQuery("#bbp_topic_id");e.suggest(e.data("ajax-url"),{onSelect:function(){var i=this.value;e.val(i.substr(0,i.indexOf(" ")))}})});

View File

@@ -0,0 +1,4 @@
jQuery( document ).ready( function() {
jQuery( '#misc-publishing-actions' ).find( '.misc-pub-section' ).first().remove();
jQuery( '#save-action' ).remove();
} );

View File

@@ -0,0 +1,3 @@
/*! This file is automatically generated. */
jQuery(document).ready(function(){jQuery("#misc-publishing-actions").find(".misc-pub-section").first().remove(),jQuery("#save-action").remove()});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
<?php
/**
* bbPress Converter Database
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Converter_DB' ) && class_exists( 'wpdb' ) ) :
/**
* bbPress Converter Database Access Abstraction Object
*
* @since 2.6.0 bbPress (r6784)
*/
class BBP_Converter_DB extends wpdb {
/**
* Sets up the credentials used to connect to the database server, but does
* not actually connect to the database on construct.
*
* @since 2.6.0 bbPress (r6784)
*
* @param string $dbuser MySQL database user
* @param string $dbpassword MySQL database password
* @param string $dbname MySQL database name
* @param string $dbhost MySQL database host
*/
public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
register_shutdown_function( array( $this, '__destruct' ) );
if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
$this->show_errors();
}
// Use ext/mysqli if it exists unless WP_USE_EXT_MYSQL is defined as true
if ( function_exists( 'mysqli_connect' ) ) {
$this->use_mysqli = true;
if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
$this->use_mysqli = ! WP_USE_EXT_MYSQL;
}
}
// Setup credentials
$this->dbuser = $dbuser;
$this->dbpassword = $dbpassword;
$this->dbname = $dbname;
$this->dbhost = $dbhost;
// Normally wpdb would try to connect here, but we don't want to do that
// until we are good and ready, so instead we do nothing.
}
}
endif;

View File

@@ -0,0 +1,893 @@
<?php
/**
* bbPress Converter
*
* Based on the hard work of Adam Ellis
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Converter' ) ) :
/**
* Main BBP_Converter Class
*/
class BBP_Converter {
/**
* @var int Number of rows
*/
public $max = 0;
/**
* @var int Start
*/
public $start = 0;
/**
* @var int Step in converter process
*/
public $step = 0;
/**
* @var int Number of rows
*/
public $rows = 0;
/**
* @var int Maximum number of converter steps
*/
public $max_steps = 17;
/**
* @var int Number of rows in the current step
*/
public $rows_in_step = 0;
/**
* @var int Percent complete of current step
*/
public $step_percentage = 0;
/**
* @var int Percent complete of all step
*/
public $total_percentage = 0;
/**
* @var int Name of source forum platform
*/
public $platform = '';
/**
* @var BBP_Converter_Base Type of converter to use
*/
public $converter = null;
/**
* @var string Path to included platforms
*/
public $converters_dir = '';
/**
* @var array Map of steps to methods
*/
private $steps = array(
1 => 'sync_table',
2 => 'users',
3 => 'passwords',
4 => 'forums',
5 => 'forum_hierarchy',
6 => 'forum_subscriptions',
7 => 'topics',
8 => 'topics_authors',
9 => 'stickies',
10 => 'super_stickies',
11 => 'closed_topics',
12 => 'topic_tags',
13 => 'topic_subscriptions',
14 => 'topic_favorites',
15 => 'replies',
16 => 'reply_authors',
17 => 'reply_hierarchy'
);
/**
* The main bbPress Converter loader
*
* @since 2.1.0 bbPress (r3813)
*/
public function __construct() {
$this->setup_globals();
$this->setup_actions();
}
/**
* Admin globals
*
* @since 2.6.0 bbPress (r6598)
*/
public function setup_globals() {
$this->converters_dir = bbp_setup_admin()->admin_dir . 'converters/';
}
/**
* Setup the default actions
*
* @since 2.1.0 bbPress (r3813)
*/
public function setup_actions() {
// Attach to the admin head with our ajax requests cycle and css
add_action( 'admin_head-tools_page_bbp-converter', array( $this, 'admin_head' ) );
// Attach to the admin ajax request to process cycles
add_action( 'wp_ajax_bbp_converter_process', array( $this, 'process_callback' ) );
}
/**
* Admin scripts
*
* @since 2.1.0 bbPress (r3813)
*/
public function admin_head() {
// Enqueue scripts
wp_enqueue_script( 'bbp-converter' );
// Localize JS
wp_localize_script( 'bbp-converter', 'BBP_Converter', array(
// Nonce
'ajax_nonce' => wp_create_nonce( 'bbp_converter_process' ),
// UI State
'state' => array(
'delay' => (int) get_option( '_bbp_converter_delay_time', 2 ),
'started' => (bool) get_option( '_bbp_converter_step', 0 ),
'running' => false,
'status' => false,
'step_percent' => $this->step_percentage,
'total_percent' => $this->total_percentage
),
// Strings
'strings' => array(
// Button text
'button_start' => esc_html__( 'Start', 'bbpress' ),
'button_continue' => esc_html__( 'Continue', 'bbpress' ),
// Start button clicked
'start_start' => esc_html__( 'Starting Import...', 'bbpress' ),
'start_continue' => esc_html__( 'Continuing Import...', 'bbpress' ),
// Import
'import_complete' => esc_html__( 'Import Finished.', 'bbpress' ),
'import_stopped_user' => esc_html__( 'Import Stopped (by User.)', 'bbpress' ),
'import_error_halt' => esc_html__( 'Import Halted (Error.)', 'bbpress' ),
'import_error_db' => esc_html__( 'Database Connection Failed.', 'bbpress' ),
// Status
'status_complete' => esc_html__( 'Finished', 'bbpress' ),
'status_stopped' => esc_html__( 'Stopped', 'bbpress' ),
'status_starting' => esc_html__( 'Starting', 'bbpress' ),
'status_up_next' => esc_html__( 'Doing step %s...', 'bbpress' ),
'status_counting' => esc_html__( 'Next in %s seconds...', 'bbpress' )
)
) );
}
/**
* Callback processor
*
* @since 2.1.0 bbPress (r3813)
*/
public function process_callback() {
// Ready the converter
$this->check_access();
$this->maybe_set_memory();
$this->maybe_restart();
$this->setup_options();
$this->maybe_update_options();
// Bail if no converter
if ( ! empty( $this->converter ) ) {
$this->do_steps();
}
}
/**
* Wrap the converter output in HTML, so styling can be applied
*
* @since 2.1.0 bbPress (r4052)
*
* @param string $output
*/
private function converter_response( $output = '' ) {
// Sanitize output
$output = wp_kses_data( $output );
// Maybe prepend the step
if ( ! empty( $this->step ) ) {
// Include percentage
if ( ! empty( $this->rows_in_step ) ) {
$progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' );
// Don't include percentage
} else {
$progress = sprintf( '<span class="step">%s.</span><span class="output">%s</span>', $this->step, $output );
}
// Raw text
} else {
$progress = $output;
}
// Output
wp_send_json_success( array(
'query' => get_option( '_bbp_converter_query', '' ),
'current_step' => $this->step,
'final_step' => $this->max_steps,
'rows_in_step' => $this->rows_in_step,
'step_percent' => $this->step_percentage,
'total_percent' => $this->total_percentage,
'progress' => $progress
) );
}
/**
* Attempt to increase memory and set other system settings
*
* @since 2.6.0 bbPress (r6460)
*/
private function maybe_set_memory() {
// Filter args
$r = apply_filters( 'bbp_converter_php_ini_overrides', array(
'implicit_flush' => '1',
'memory_limit' => '256M',
'max_execution_time' => HOUR_IN_SECONDS * 6
) );
// Get disabled PHP functions (to avoid using them)
$disabled = explode( ',', @ini_get( 'disable_functions' ) );
// Maybe avoid terminating when the client goes away (if function is not disabled)
if ( ! in_array( 'ignore_user_abort', $disabled, true ) ) {
@ignore_user_abort( true );
}
// Maybe set memory & time limits, and flush style (if function is not disabled)
if ( ! in_array( 'ini_set', $disabled, true ) ) {
foreach ( $r as $key => $value ) {
@ini_set( $key, $value );
}
}
}
/**
* Maybe restart the converter
*
* @since 2.6.0 bbPress (r6460)
*/
private function maybe_restart() {
// Save step and count so that it can be restarted.
if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) {
$this->step = 1;
$this->start = 0;
$this->step_percentage = 0;
$this->total_percentage = 0;
$this->rows_in_step = 0;
$this->maybe_update_options();
}
}
/**
* Maybe update options
*
* @since 2.6.0 bbPress (r6637)
*/
private function maybe_update_options() {
// Default options
$options = array(
// Step & Start
'_bbp_converter_step' => $this->step,
'_bbp_converter_start' => $this->start,
'_bbp_converter_rows_in_step' => $this->rows_in_step,
// Halt
'_bbp_converter_halt' => ! empty( $_POST['_bbp_converter_halt'] )
? (int) $_POST['_bbp_converter_halt']
: 0,
// Rows (bound between 1 and 5000)
'_bbp_converter_rows' => ! empty( $_POST['_bbp_converter_rows'] )
? min( max( (int) $_POST['_bbp_converter_rows'], 1 ), 5000 )
: 0,
// Platform
'_bbp_converter_platform' => ! empty( $_POST['_bbp_converter_platform' ] )
? sanitize_text_field( $_POST['_bbp_converter_platform' ] )
: '',
// Convert Users
'_bbp_converter_convert_users' => ! empty( $_POST['_bbp_converter_convert_users'] )
? (bool) $_POST['_bbp_converter_convert_users']
: false,
// DB User
'_bbp_converter_db_user' => ! empty( $_POST['_bbp_converter_db_user'] )
? sanitize_text_field( $_POST['_bbp_converter_db_user'] )
: '',
// DB Password
'_bbp_converter_db_pass' => ! empty( $_POST['_bbp_converter_db_pass'] )
? sanitize_text_field( $_POST['_bbp_converter_db_pass'] )
: '',
// DB Name
'_bbp_converter_db_name' => ! empty( $_POST['_bbp_converter_db_name'] )
? sanitize_text_field( $_POST['_bbp_converter_db_name'] )
: '',
// DB Server
'_bbp_converter_db_server' => ! empty( $_POST['_bbp_converter_db_server'] )
? sanitize_text_field( $_POST['_bbp_converter_db_server'] )
: '',
// DB Port
'_bbp_converter_db_port' => ! empty( $_POST['_bbp_converter_db_port'] )
? (int) sanitize_text_field( $_POST['_bbp_converter_db_port'] )
: '',
// DB Table Prefix
'_bbp_converter_db_prefix' => ! empty( $_POST['_bbp_converter_db_prefix'] )
? sanitize_text_field( $_POST['_bbp_converter_db_prefix'] )
: ''
);
// Update/delete options
foreach ( $options as $key => $value ) {
update_option( $key, $value );
}
}
/**
* Setup converter options
*
* @since 2.6.0 bbPress (r6460)
*/
private function setup_options() {
// Set starting point & rows
$this->step = (int) get_option( '_bbp_converter_step', 1 );
$this->start = (int) get_option( '_bbp_converter_start', 0 );
$this->rows = (int) get_option( '_bbp_converter_rows', 100 );
$this->rows_in_step = (int) get_option( '_bbp_converter_rows_in_step', 0 );
// Set boundaries
$this->max = ( $this->start + $this->rows ) - 1;
// Set platform
$this->platform = get_option( '_bbp_converter_platform' );
// Total percentage
$this->total_percentage = round( ( $this->step / $this->max_steps ) * 100, 2 );
// Total mini steps
if ( $this->rows_in_step > 0 ) {
$total_mini_steps = ceil( $this->rows_in_step / $this->rows );
$current_mini_step = ceil( $this->start / $this->rows );
$this->step_percentage = round( ( $current_mini_step / $total_mini_steps ) * 100, 2 );
} else {
$this->step_percentage = 0;
}
// Maybe include the appropriate converter.
if ( ! empty( $this->platform ) ) {
$this->converter = bbp_new_converter( $this->platform );
}
}
/**
* Check that user can access the converter
*
* @since 2.6.0 bbPress (r6460)
*/
private function check_access() {
// Bail if user cannot view import page
if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
wp_die( '0' );
}
// Verify intent
check_ajax_referer( 'bbp_converter_process' );
}
/**
* Reset the converter
*
* @since 2.6.0 bbPress (r6460)
*/
private function reset() {
update_option( '_bbp_converter_step', 0 );
update_option( '_bbp_converter_start', 0 );
update_option( '_bbp_converter_rows_in_step', 0 );
update_option( '_bbp_converter_query', '' );
}
/**
* Bump the step and reset the start
*
* @since 2.6.0 bbPress (r6460)
*/
private function bump_step() {
// Next step
$next_step = (int) ( $this->step + 1 );
// Don't let step go over max
$step = ( $next_step <= $this->max_steps )
? $next_step
: 0;
// Update step and start at 0
update_option( '_bbp_converter_step', $step );
update_option( '_bbp_converter_start', 0 );
update_option( '_bbp_converter_rows_in_step', 0 );
}
/**
* Bump the start within the current step
*
* @since 2.6.0 bbPress (r6460)
*/
private function bump_start() {
// Set rows in step from option
$this->rows_in_step = get_option( '_bbp_converter_rows_in_step', 0 );
// Get rows to start from
$start = (int) ( $this->start + $this->rows );
// Enforce maximum if exists
if ( $this->rows_in_step > 0 ) {
// Start cannot be larger than total rows
if ( $start > $this->rows_in_step ) {
$start = $this->rows_in_step;
}
// Max can't be greater than total rows
if ( $this->max > $this->rows_in_step ) {
$this->max = $this->rows_in_step;
}
}
// Update the start option
update_option( '_bbp_converter_start', $start );
}
/**
* Do the converter step
*
* @since 2.6.0 bbPress (r6460)
*/
private function do_steps() {
// Step exists in map, and method exists
if ( isset( $this->steps[ $this->step ] ) && method_exists( $this, "step_{$this->steps[ $this->step ]}" ) ) {
return call_user_func( array( $this, "step_{$this->steps[ $this->step ]}" ) );
}
// Done!
$this->step_done();
}
/** Steps *****************************************************************/
/**
* Maybe clean the sync table
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_sync_table() {
if ( true === $this->converter->clean ) {
if ( $this->converter->clean() ) {
$this->bump_step();
$this->sync_table( true );
empty( $this->start )
? $this->converter_response( esc_html__( 'Readying sync-table', 'bbpress' ) )
: $this->converter_response( esc_html__( 'Sync-table ready', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) );
}
$this->converter->clean = false;
} else {
$this->bump_step();
$this->sync_table( false );
$this->converter_response( esc_html__( 'Skipping sync-table clean-up', 'bbpress' ) );
}
}
/**
* Maybe convert users
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_users() {
if ( true === $this->converter->convert_users ) {
if ( $this->converter->convert_users( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No users to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All users imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting users (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
} else {
$this->bump_step();
$this->converter_response( esc_html__( 'Skipping user clean-up', 'bbpress' ) );
}
}
/**
* Maybe clean up passwords
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_passwords() {
if ( true === $this->converter->convert_users ) {
if ( $this->converter->clean_passwords( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No passwords to clear', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All passwords cleared', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s)', 'bbpress' ), $this->start, $this->max ) );
}
} else {
$this->bump_step();
$this->converter_response( esc_html__( 'Skipping password clean-up', 'bbpress' ) );
}
}
/**
* Maybe convert forums
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_forums() {
if ( $this->converter->convert_forums( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No forums to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All forums imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe walk the forum hierarchy
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_forum_hierarchy() {
if ( $this->converter->convert_forum_parents( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No forum parents to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All forum parents imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert forum subscriptions
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_forum_subscriptions() {
if ( $this->converter->convert_forum_subscriptions( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No forum subscriptions to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All forum subscriptions imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert topics
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_topics() {
if ( $this->converter->convert_topics( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No topics to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All topics imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert topic authors (anonymous)
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_topics_authors() {
if ( $this->converter->convert_anonymous_topic_authors( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No anonymous topic authors to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All anonymous topic authors imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert sticky topics (not super stickies)
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_stickies() {
if ( $this->converter->convert_topic_stickies( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No stickies to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All stickies imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert super-sticky topics (not per-forum)
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_super_stickies() {
if ( $this->converter->convert_topic_super_stickies( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No super stickies to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All super stickies imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe close converted topics
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_closed_topics() {
if ( $this->converter->convert_topic_closed_topics( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No closed topics to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All closed topics imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert topic tags
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_topic_tags() {
if ( $this->converter->convert_tags( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No topic tags to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All topic tags imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert topic subscriptions
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_topic_subscriptions() {
if ( $this->converter->convert_topic_subscriptions( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No topic subscriptions to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All topic subscriptions imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert topic favorites
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_topic_favorites() {
if ( $this->converter->convert_favorites( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No favorites to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All favorites imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert replies
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_replies() {
if ( $this->converter->convert_replies( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No replies to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All replies imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert reply authors (anonymous)
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_reply_authors() {
if ( $this->converter->convert_anonymous_reply_authors( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No anonymous reply authors to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All anonymous reply authors imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Maybe convert the threaded reply hierarchy
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_reply_hierarchy() {
if ( $this->converter->convert_reply_to_parents( $this->start ) ) {
$this->bump_step();
empty( $this->start )
? $this->converter_response( esc_html__( 'No threaded replies to import', 'bbpress' ) )
: $this->converter_response( esc_html__( 'All threaded replies imported', 'bbpress' ) );
} else {
$this->bump_start();
$this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
}
}
/**
* Done!
*
* @since 2.6.0 bbPress (r6513)
*/
private function step_done() {
$this->reset();
$this->converter_response( esc_html__( 'Import Finished', 'bbpress' ) );
}
/** Helper Table **********************************************************/
/**
* Create Tables for fast syncing
*
* @since 2.1.0 bbPress (r3813)
*/
public static function sync_table( $drop = false ) {
// Setup DB
$bbp_db = bbp_db();
$table_name = $bbp_db->prefix . 'bbp_converter_translator';
$table_exists = $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name;
// Maybe drop the sync table
if ( ( true === $drop ) && ( true === $table_exists ) ) {
$bbp_db->query( "DROP TABLE {$table_name}" );
}
// Maybe include the upgrade functions, for dbDelta()
if ( ! function_exists( 'dbDelta' ) ) {
require_once ABSPATH . '/wp-admin/includes/upgrade.php';
}
// Defaults
$sql = array();
$charset_collate = '';
// https://bbpress.trac.wordpress.org/ticket/3145
$max_index_length = 75;
// Maybe override the character set
if ( ! empty( $bbp_db->charset ) ) {
$charset_collate .= "DEFAULT CHARACTER SET {$bbp_db->charset}";
}
// Maybe override the collation
if ( ! empty( $bbp_db->collate ) ) {
$charset_collate .= " COLLATE {$bbp_db->collate}";
}
/** Translator ********************************************************/
$sql[] = "CREATE TABLE {$table_name} (
meta_id mediumint(8) unsigned not null auto_increment,
value_type varchar(25) null,
value_id bigint(20) unsigned not null default '0',
meta_key varchar({$max_index_length}) null,
meta_value varchar({$max_index_length}) null,
PRIMARY KEY (meta_id),
KEY value_id (value_id),
KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length}))
) {$charset_collate}";
dbDelta( $sql );
}
}
endif;

View File

@@ -0,0 +1,346 @@
<?php
/**
* Topic Replies List Table class.
*
* @package bbPress
* @subpackage Administration
* @since 2.6.0
* @access private
*
* @see WP_Posts_List_Table
*/
// Include the main list table class if it's not included yet
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
if ( class_exists( 'WP_List_Table' ) ) :
/**
* Topic replies list table
*
* This list table is responsible for showing the replies to a topic in a
* meta-box, similar to comments in posts and pages.
*
* @since 2.6.0 bbPress (r5886)
*/
class BBP_Topic_Replies_List_Table extends WP_List_Table {
/**
* The main constructor method
*
* @since 2.6.0 bbPress (r5886)
*/
public function __construct( $args = array() ) {
// Parse arguments
$args = bbp_parse_args( $args, array(
'singular' => 'reply',
'plural' => 'replies',
'ajax' => false
), 'topic_replies_list_table' );
// Construct the list table
parent::__construct( $args ); }
/**
* Setup the list-table columns
*
* @since 2.6.0 bbPress (r5886)
*
* @see WP_List_Table::::single_row_columns()
*
* @return array An associative array containing column information
*/
public function get_columns() {
return array(
//'cb' => '<input type="checkbox" />',
'bbp_topic_reply_author' => esc_html__( 'Author', 'bbpress' ),
'bbp_reply_content' => esc_html__( 'Content', 'bbpress' ),
'bbp_reply_created' => esc_html__( 'Replied', 'bbpress' ),
);
}
/**
* Allow `bbp_reply_created` to be sortable
*
* @since 2.6.0 bbPress (r5886)
*
* @return array An associative array containing the `bbp_reply_created` column
*/
public function get_sortable_columns() {
return array(
'bbp_reply_created' => array( 'bbp_reply_created', false )
);
}
/**
* Setup the bulk actions
*
* @since 2.6.0 bbPress (r5886)
*
* @return array An associative array containing all the bulk actions
*/
public function get_bulk_actions() {
return array();
// @todo cap checks
return array(
'unapprove' => esc_html__( 'Unapprove', 'bbpress' ),
'spam' => esc_html__( 'Spam', 'bbpress' ),
'trash' => esc_html__( 'Trash', 'bbpress' )
);
}
/**
* Output the check-box column for bulk actions (if we implement them)
*
* @since 2.6.0 bbPress (r5886)
*/
public function column_cb( $item = '' ) {
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
$this->_args['singular'],
$item->ID
);
}
/**
* Output the contents of the `bbp_topic_reply_author` column
*
* @since 2.6.0 bbPress (r5886)
*/
public function column_bbp_topic_reply_author( $item = '' ) {
bbp_reply_author_avatar( $item->ID, 50 );
bbp_reply_author_display_name( $item->ID );
echo '<br>';
bbp_reply_author_email( $item->ID );
echo '<br>';
bbp_author_ip( array( 'post_id' => $item->ID ) );
}
/**
* Output the contents of the `bbp_reply_created` column
*
* @since 2.6.0 bbPress (r5886)
*/
public function column_bbp_reply_created( $item = '' ) {
return sprintf( '%1$s <br /> %2$s',
esc_attr( get_the_date( '', $item ) ),
esc_attr( get_the_time( '', $item ) )
);
}
/**
* Output the contents of the `bbp_reply_content` column
*
* @since 2.6.0 bbPress (r5886)
*/
public function column_bbp_reply_content( $item = '' ) {
// Define actions array
$actions = array(
'view' => '<a href="' . bbp_get_reply_url( $item->ID ) . '">' . esc_html__( 'View', 'bbpress' ) . '</a>'
);
// Prepend `edit` link
if ( current_user_can( 'edit_reply', $item->ID ) ) {
$actions['edit'] = '<a href="' . get_edit_post_link( $item->ID ) . '">' . esc_html__( 'Edit', 'bbpress' ) . '</a>';
$actions = array_reverse( $actions );
}
// Filter the reply content
$reply_content = apply_filters( 'bbp_get_reply_content', $item->post_content, $item->ID );
$reply_actions = $this->row_actions( $actions );
// Return content & actions
return $reply_content . $reply_actions;
}
/**
* Handle bulk action requests
*
* @since 2.6.0 bbPress (r5886)
*/
public function process_bulk_action() {
switch ( $this->current_action() ) {
case 'trash' :
break;
case 'unapprove' :
break;
case 'spam' :
break;
}
}
/**
* Prepare the list-table items for display
*
* @since 2.6.0 bbPress (r5886)
*/
public function prepare_items( $topic_id = 0 ) {
// Sanitize the topic ID
$topic_id = bbp_get_topic_id( $topic_id );
// Set column headers
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
// Handle bulk actions
$this->process_bulk_action();
// Query parameters
$per_page = 5;
$current_page = $this->get_pagenum();
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_key( $_REQUEST['orderby'] ) : 'date';
$order = ! empty( $_REQUEST['order'] ) ? sanitize_key( $_REQUEST['order'] ) : 'asc';
$statuses = bbp_get_public_reply_statuses();
// Maybe add private statuses to query
if ( current_user_can( 'edit_others_replies' ) ) {
// Default view=all statuses
$statuses = array_keys( bbp_get_topic_statuses() );
// Add support for private status
if ( current_user_can( 'read_private_replies' ) ) {
$statuses[] = bbp_get_private_status_id();
}
}
// Query for replies
$reply_query = new WP_Query( array(
'post_type' => bbp_get_reply_post_type(),
'post_status' => $statuses,
'post_parent' => $topic_id,
'posts_per_page' => $per_page,
'paged' => $current_page,
'orderby' => $orderby,
'order' => ucwords( $order ),
'hierarchical' => false,
'ignore_sticky_posts' => true
) );
// Get the total number of replies, for pagination
$total_items = bbp_get_topic_reply_count( $topic_id );
// Set list table items to queried posts
$this->items = $reply_query->posts;
// Set the pagination arguments
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page )
) );
}
/**
* Message to be displayed when there are no items
*
* @since 2.6.0 bbPress (r5930)
*/
public function no_items() {
esc_html_e( 'No replies to this topic.', 'bbpress' );
}
/**
* Display the list table
*
* This custom method is necessary because the one in `WP_List_Table` comes
* with a nonce and check that we do not need.
*
* @since 2.6.0 bbPress (r5930)
*/
public function display() {
// Top
$this->display_tablenav( 'top' ); ?>
<table id="bbp-reply-list" class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>
<tr>
<?php $this->print_column_headers(); ?>
</tr>
</thead>
<tbody data-wp-lists='list:<?php echo $this->_args['singular']; ?>'>
<?php $this->display_rows_or_placeholder(); ?>
</tbody>
<tfoot>
<tr>
<?php $this->print_column_headers( false ); ?>
</tr>
</tfoot>
</table>
<?php
// Bottom
$this->display_tablenav( 'bottom' );
}
/**
* Generate the table navigation above or below the table
*
* This custom method is necessary because the one in `WP_List_Table` comes
* with a nonce and check that we do not need.
*
* @since 2.6.0 bbPress (r5930)
*
* @param string $which
*/
protected function display_tablenav( $which = '' ) {
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<?php
$this->extra_tablenav( $which );
$this->pagination( $which );
?>
<br class="clear" />
</div>
<?php
}
/**
* Generates content for a single row of the table
*
* @since 2.6.0
* @access public
*
* @param object $item The current item
*/
public function single_row( $item ) {
// Author
$classes = 'author-' . ( get_current_user_id() == $item->post_author ? 'self' : 'other' );
// Locked
if ( wp_check_post_lock( $item->ID ) ) {
$classes .= ' wp-locked';
}
// Hierarchy
if ( ! empty( $item->post_parent ) ) {
$count = count( get_post_ancestors( $item->ID ) );
$classes .= ' level-'. $count;
} else {
$classes .= ' level-0';
} ?>
<tr id="post-<?php echo esc_attr( $item->ID ); ?>" class="<?php echo implode( ' ', get_post_class( $classes, $item->ID ) ); ?>">
<?php $this->single_row_columns( $item ); ?>
</tr>
<?php
}
}
endif;

View File

@@ -0,0 +1,185 @@
<?php
/**
* bbPress Admin Functions
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Admin Menus ***************************************************************/
/**
* Add a separator to the WordPress admin menus
*
* @since 2.0.0 bbPress (r2957)
*/
function bbp_admin_separator() {
// Caps necessary where a separator is necessary
$caps = array(
'bbp_forums_admin',
'bbp_topics_admin',
'bbp_replies_admin',
);
// Loop through caps, and look for a reason to show the separator
foreach ( $caps as $cap ) {
if ( current_user_can( $cap ) ) {
bbp_admin()->show_separator = true;
break;
}
}
// Bail if no separator
if ( false === bbp_admin()->show_separator ) {
return;
}
global $menu;
$menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' );
}
/**
* Tell WordPress we have a custom menu order
*
* @since 2.0.0 bbPress (r2957)
*
* @param bool $menu_order Menu order
* @return mixed True if separator, false if not
*/
function bbp_admin_custom_menu_order( $menu_order = false ) {
if ( false === bbp_admin()->show_separator ) {
return $menu_order;
}
return true;
}
/**
* Move our custom separator above our custom post types
*
* @since 2.0.0 bbPress (r2957)
*
* @param array $menu_order Menu Order
* @return array Modified menu order
*/
function bbp_admin_menu_order( $menu_order ) {
// Bail if user cannot see any top level bbPress menus
if ( empty( $menu_order ) || ( false === bbp_admin()->show_separator ) ) {
return $menu_order;
}
// Initialize our custom order array
$bbp_menu_order = array();
// Menu values
$second_sep = 'separator2';
$custom_menus = array(
'separator-bbpress', // Separator
'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums
'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics
'edit.php?post_type=' . bbp_get_reply_post_type() // Replies
);
// Loop through menu order and do some rearranging
foreach ( $menu_order as $item ) {
// Position bbPress menus above appearance
if ( $second_sep == $item ) {
// Add our custom menus
foreach ( $custom_menus as $custom_menu ) {
if ( array_search( $custom_menu, $menu_order ) ) {
$bbp_menu_order[] = $custom_menu;
}
}
// Add the appearance separator
$bbp_menu_order[] = $second_sep;
// Skip our menu items
} elseif ( ! in_array( $item, $custom_menus, true ) ) {
$bbp_menu_order[] = $item;
}
}
// Return our custom order
return $bbp_menu_order;
}
/**
* Sanitize permalink slugs when saving the settings page.
*
* @since 2.6.0 bbPress (r5364)
*
* @param string $slug
* @return string
*/
function bbp_sanitize_slug( $slug = '' ) {
// Don't allow multiple slashes in a row
$value = preg_replace( '#/+#', '/', str_replace( '#', '', $slug ) );
// Strip out unsafe or unusable chars
$value = esc_url_raw( $value );
// esc_url_raw() adds a scheme via esc_url(), so let's remove it
$value = str_replace( 'http://', '', $value );
// Trim off first and last slashes.
//
// We already prevent double slashing elsewhere, but let's prevent
// accidental poisoning of options values where we can.
$value = ltrim( $value, '/' );
$value = rtrim( $value, '/' );
// Filter & return
return apply_filters( 'bbp_sanitize_slug', $value, $slug );
}
/**
* Uninstall all bbPress options and capabilities from a specific site.
*
* @since 2.1.0 bbPress (r3765)
*
* @param int $site_id
*/
function bbp_do_uninstall( $site_id = 0 ) {
if ( empty( $site_id ) ) {
$site_id = get_current_blog_id();
}
bbp_switch_to_site( $site_id );
bbp_delete_options();
bbp_remove_roles();
bbp_remove_caps();
flush_rewrite_rules();
bbp_restore_current_site();
}
/**
* This tells WP to highlight the Tools > Forums menu item,
* regardless of which actual bbPress Tools screen we are on.
*
* The conditional prevents the override when the user is viewing settings or
* any third-party plugins.
*
* @since 2.1.0 bbPress (r3888)
*
* @global string $plugin_page
* @global array $submenu_file
*/
function bbp_tools_modify_menu_highlight() {
global $plugin_page, $submenu_file;
// This tweaks the Tools subnav menu to only show one bbPress menu item
if ( ! in_array( $plugin_page, array( 'bbp-settings' ), true ) ) {
$submenu_file = 'bbp-repair';
}
}

View File

@@ -0,0 +1,663 @@
<?php
/**
* bbPress AEF Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of AEF Forum converter.
*
* @since 2.5.0 bbPress (r5139)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/aef
*/
class AEF extends BBP_Converter_Base {
/**
* Main Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'par_board_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'ntopic',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'nposts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'ntopic',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'nposts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fname',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fname',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Unlocked = 1 or Locked = 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'status',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'n_posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'n_posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 't_bid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: We join the 'posts' table because 'topics' table does not include author id.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'posts' table because 'topics' table does not include author ip.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'posts' table because 'topics' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 't_bid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 't_sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
// Note: We join the 'posts' table because 'topics' table does not include topic dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.pid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open = 1 or Closed = 0, AEF v1.0.9)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 't_status',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* AEF v1.0.9 Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'pid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_fid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_tid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_tid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ptime',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'AEF'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'www',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'r_time',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'yim',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_yim'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_msn'
);
// Store Gmail (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'gmail',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_gmail'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'sig',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_sig',
'callback_method' => 'callback_html'
);
// Store Location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'location',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_location'
);
// Store PrivateText (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'users_text',
'to_type' => 'user',
'to_fieldname' => '_bbp_aef_user_private_text'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum status from AEF v1.0.9 numerics to WordPress's strings.
*
* @param int $status AEF v1.0.9 numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from AEF v1.0.9 numerics to WordPress's strings.
*
* @param int $status AEF v1.0.9 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from AEF 1.x numerics to WordPress's strings.
*
* @param int $status AEF 1.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // AEF Sticky 't_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // AEF normal topic 't_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count AEF v1.0.9 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,662 @@
<?php
/**
* bbPress Drupal7 Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Drupal v7.x Forum converter.
*
* @since 2.5.0 bbPress (r5138)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/drupal
*/
class Drupal7 extends BBP_Converter_Base {
/**
* Main Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'tid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_hierarchy',
'from_fieldname' => 'parent',
'join_tablename' => 'taxonomy_term_data',
'join_type' => 'INNER',
'join_expression' => 'USING (tid)',
'from_expression' => 'LEFT JOIN taxonomy_vocabulary AS taxonomy_vocabulary USING (vid) WHERE module = "forum"',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'weight',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'nid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'comment_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'comment_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: We join the 'node' table because 'forum_index' table does not include author id.
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'uid',
'join_tablename' => 'forum_index',
'join_type' => 'INNER',
'join_expression' => 'ON node.nid = forum_index.nid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id',
'default' => 'Anonymous'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'uid',
'join_tablename' => 'forum_index',
'join_type' => 'INNER',
'join_expression' => 'ON node.nid = forum_index.nid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic content.
// Note: We join the 'field_data_body' table because 'node' or 'forum_index' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'field_data_body',
'from_fieldname' => 'body_value',
'join_tablename' => 'node',
'join_type' => 'INNER',
'join_expression' => 'ON field_data_body.revision_id = node.vid',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Publish or Unpublished, Drupal v7.x publish = 1, pending = 0)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'status',
'join_tablename' => 'forum_index',
'join_type' => 'INNER',
'join_expression' => 'ON node.nid = forum_index.nid',
'to_type' => 'topic',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'created',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'created',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'last_comment_timestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'last_comment_timestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_index',
'from_fieldname' => 'last_comment_timestamp',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Drupal v7.x Comments Enabled no = 0, closed = 1 & open = 2)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'comment',
'join_tablename' => 'forum_index',
'join_type' => 'INNER',
'join_expression' => 'ON node.nid = forum_index.nid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'field_data_field_tags',
'from_fieldname' => 'entity_id',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'field_data_field_tags',
'from_fieldname' => 'field_tags_tid',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term name.
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'name',
'join_tablename' => 'field_data_field_tags',
'join_type' => 'INNER',
'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'name',
'join_tablename' => 'field_data_field_tags',
'join_type' => 'INNER',
'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
// Term description.
$this->field_map[] = array(
'from_tablename' => 'taxonomy_term_data',
'from_fieldname' => 'description',
'join_tablename' => 'field_data_field_tags',
'join_type' => 'INNER',
'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid',
'to_type' => 'tags',
'to_fieldname' => 'description'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'cid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'nid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'nid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply parent reply id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'pid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_to_id'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'hostname',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'uid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply status (Publish or Unpublished, Drupal v7.x publish = 1, pending = 0)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'status',
'to_type' => 'reply',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'name',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'uid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
// Note: We join the 'field_data_comment_body' table because 'comment' table does not include reply content.
$this->field_map[] = array(
'from_tablename' => 'field_data_comment_body',
'from_fieldname' => 'comment_body_value',
'join_tablename' => 'comment',
'join_type' => 'INNER',
'join_expression' => 'ON field_data_comment_body.entity_id = comment.cid',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'nid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'created',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'created',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'changed',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'comment',
'from_fieldname' => 'changed',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
// Don't import user uid = 0, this is Drupal 7's guest user
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'uid',
'from_expression' => 'WHERE uid != 0',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'pass',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
// 'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'pass',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'Drupal7'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'mail',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'created',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'signature',
'to_fieldname' => '_bbp_drupal7_user_sig',
'to_type' => 'user',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the post status from Drupal v7.x numerics to WordPress's
* strings.
*
* @param int $status Drupal v7.x numeric post status
* @return string WordPress safe
*/
public function callback_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'pending'; // bbp_get_pending_status_id()
break;
case 1 :
default :
$status = 'publish'; // bbp_get_public_status_id()
break;
}
return $status;
}
/**
* Translate the post status from Drupal v7.x numerics to WordPress's strings.
*
* @param int $status Drupal v7.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 2 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 2 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from Drupal v7.x numerics to WordPress's strings.
*
* @param int $status Drupal v7.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // Drupal Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // Drupal Normal Topic 'sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count Drupal v7.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,711 @@
<?php
/**
* bbPress Example Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Example converter base impoprter template for bbPress
*
* @since 2.3.0 bbPress (r4689)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/custom-import
*/
class Example extends BBP_Converter_Base {
/**
* Main Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Setup table joins for the forum section at the base of this section
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_topic_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_reply_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_total_topic_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_total_reply_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_title',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_slug',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 0 or Forum = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_type',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Unlocked = 0 or Locked = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums_table',
'from_fieldname' => 'the_forum_status',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
// Setup the table joins for the forum section
$this->field_map[] = array(
'from_tablename' => 'groups_table',
'from_fieldname' => 'forum_id',
'join_tablename' => 'forums_table',
'join_type' => 'INNER',
'join_expression' => 'USING groups_table.forum_id = forums_table.forum_id',
// 'from_expression' => 'WHERE forums_table.forum_id != 1',
'to_type' => 'forum'
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions_table',
'from_fieldname' => 'the_forum_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions_table',
'from_fieldname' => 'the_user_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Setup table joins for the topic section at the base of this section
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_reply_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_total_topic_reply_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_parent_forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_author_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_author_ip_address',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_content',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_slug',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_status',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_parent_forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_sticky_status',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_creation_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_creation_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_modified_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_modified_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_modified_date',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Setup any table joins needed for the topic section
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_topic_id',
'join_tablename' => 'topics_table',
'join_type' => 'INNER',
'join_expression' => 'USING replies_table.the_topic_id = topics_table.the_topic_id',
'from_expression' => 'WHERE forums_table.the_topic_id = 0',
'to_type' => 'topic'
);
/** Tags Section ******************************************************/
// Setup table joins for the tag section at the base of this section
// Setup any table joins needed for the tags section
$this->field_map[] = array(
'from_tablename' => 'tag_table',
'from_fieldname' => 'the_topic_id',
'join_tablename' => 'tagcontent_table',
'join_type' => 'INNER',
'join_expression' => 'USING tagcontent_table.tag_id = tags_table.tag_id',
'from_expression' => 'WHERE tagcontent_table.tag_id = tag_table.tag_id',
'to_type' => 'tags'
);
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'tagcontent_table',
'from_fieldname' => 'contentid',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'tagcontent_table',
'from_fieldname' => 'tagid',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'tag_table',
'from_fieldname' => 'tagtext',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'tag_table',
'from_fieldname' => 'tagslug',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
// Term description.
$this->field_map[] = array(
'from_tablename' => 'tag_table',
'from_fieldname' => 'tagdescription',
'to_type' => 'tags',
'to_fieldname' => 'description'
);
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'topic_subscriptions_table',
'from_fieldname' => 'the_topic_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'topic_subscriptions_table',
'from_fieldname' => 'the_user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Favorites Section *************************************************/
// Favorited topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'favorites_table',
'from_fieldname' => 'the_favorite_topic_id',
'to_type' => 'favorites',
'to_fieldname' => '_bbp_favorites'
);
// Favorited user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'favorites_table',
'from_fieldname' => 'the_user_id',
'to_type' => 'favorites',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Setup table joins for the reply section at the base of this section
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_parent_forum_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_parent_topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_author_ip_address',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_author_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply title and reply slugs
// Note: We don't actually want either a reply title or a reply slug as
// we want single replies to use their ID as the permalink.
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_content',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply order.
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_order',
'to_type' => 'reply',
'to_fieldname' => 'menu_order'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_parent_topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_creation_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_creation_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_modified_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'replies_table',
'from_fieldname' => 'the_reply_modified_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
// Setup any table joins needed for the reply section
$this->field_map[] = array(
'from_tablename' => 'topics_table',
'from_fieldname' => 'the_topic_id',
'join_tablename' => 'replies_table',
'join_type' => 'INNER',
'join_expression' => 'USING topics_table.the_topic_id = replies_table.the_topic_id',
'from_expression' => 'WHERE topics_table.first_post != 0',
'to_type' => 'reply'
);
/** User Section ******************************************************/
// Setup table joins for the user section at the base of this section
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_password_salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'Example'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_nicename',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_email_address',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_homepage_url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_registration_date',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User status.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_status',
'to_type' => 'user',
'to_fieldname' => 'user_status'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_display_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User Profile Field 1 (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_custom_profile_field_1',
'to_type' => 'user',
'to_fieldname' => '_bbp_example_profile_field_1'
);
// User Profile Field 2 (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_custom_profile_field_2',
'to_type' => 'user',
'to_fieldname' => '_bbp_example_profile_field_2'
);
// User Profile Field 3 (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users_table',
'from_fieldname' => 'the_users_custom_profile_field_3',
'to_type' => 'user',
'to_fieldname' => '_bbp_example_profile_field_3'
);
// Setup any table joins needed for the user section
$this->field_map[] = array(
'from_tablename' => 'users_profile_table',
'from_fieldname' => 'the_users_id',
'join_tablename' => 'users_table',
'join_type' => 'INNER',
'join_expression' => 'USING users_profile_table.the_user_id = users_table.the_user_id',
'from_expression' => 'WHERE users_table.the_user_id != -1',
'to_type' => 'user'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
}

View File

@@ -0,0 +1,664 @@
<?php
/**
* bbPress FluxBB Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of FluxBB Forum converter.
*
* @since 2.5.0 bbPress (r5138)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/fluxbb
*/
class FluxBB extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_desc',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'disp_position',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions',
'from_fieldname' => 'forum_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions',
'from_fieldname' => 'user_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: We join the 'posts' table because 'topics' table does include numeric user id.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'posts' table because 'topics' table does not include author IP addresses.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'posts' table because 'topics' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open = 0 or Closed = 1, FluxBB v1.5.3)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* FluxBB v1.5.3 Forums do not support topic tags out of the box
*/
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'topic_subscriptions',
'from_fieldname' => 'topic_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'topic_subscriptions',
'from_fieldname' => 'user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
// $this->field_map[] = array(
// 'from_tablename' => 'users',
// 'from_fieldname' => 'salt',
// 'to_type' => 'user',
// 'to_fieldname' => ''
// );
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'FluxBB'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'realname',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_yim'
);
// Store Jabber
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'jabber',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_jabber'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_msn'
);
// Store Location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'location',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_location'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'signature',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_sig',
'callback_method' => 'callback_html'
);
// Store Admin Note (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'admin_note',
'to_type' => 'user',
'to_fieldname' => '_bbp_fluxbb_user_admin_note'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the post status from FluxBB v1.5.3 numerics to WordPress's strings.
*
* @param int $status FluxBB v1.5.3 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from FluxBB v1.5.3 numerics to WordPress's strings.
*
* @param int $status FluxBB v1.5.3 numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // FluxBB Sticky 'sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // FluxBB Normal Topic 'sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count FluxBB v1.5.3 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,638 @@
<?php
/**
* bbPress Invision Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Invision Power Board v3.x converter.
*
* @since 2.3.0 bbPress (r4713)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/invision
*/
class Invision extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name_seo',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'position',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Forum = 0 or Category = -1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'starter_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic content.
// Note: We join the posts table because topics do not have content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'ON(topics.tid = posts.topic_id) WHERE posts.new_topic = 1',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'pinned',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'start_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'start_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'core_tags',
'from_fieldname' => 'tag_meta_id',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'core_tags',
'from_fieldname' => 'tag_text',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'pid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ip_address',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'author_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edit_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edit_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'member_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'members_pass_hash',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'members_pass_salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'Invision'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'joined',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'members_display_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* Translate the forum type from Invision numerics to WordPress's strings.
*
* @param int $status Invision numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == -1 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the topic sticky status type from Invision numerics to WordPress's strings.
*
* @param int $status Invision numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // Invision Pinned Topic 'pinned = 1'
break;
case 0 :
default :
$status = 'normal'; // Invision Normal Topic 'pinned = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count Invision reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
return array( 'hash' => $field, 'salt' => $row['members_pass_salt'] );
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $pass_array['salt'] ) . md5( $this->to_char( $password ) ) ) );
}
private function to_char( $input ) {
$output = "";
for ( $i = 0; $i < strlen( $input ); $i++ ) {
$j = ord( $input[$i] );
if ( ( $j >= 65 && $j <= 90 )
|| ( $j >= 97 && $j <= 122 )
|| ( $j >= 48 && $j <= 57 ) )
{
$output .= $input[$i];
} else {
$output .= "&#" . ord( $input[$i] ) . ";";
}
}
return $output;
}
/**
* This callback processes any custom BBCodes with parser.php
*/
protected function callback_html( $field ) {
// Strips Invision custom HTML first from $field before parsing $field to parser.php
$invision_markup = $field;
$invision_markup = html_entity_decode( $invision_markup );
// Replace '[html]' with '<pre><code>'
$invision_markup = preg_replace( '/\[html\]/', '<pre><code>', $invision_markup );
// Replace '[/html]' with '</code></pre>'
$invision_markup = preg_replace( '/\[\/html\]/', '</code></pre>', $invision_markup );
// Replace '[sql]' with '<pre><code>'
$invision_markup = preg_replace( '/\[sql\]/', '<pre><code>', $invision_markup );
// Replace '[/sql]' with '</code></pre>'
$invision_markup = preg_replace( '/\[\/sql\]/', '</code></pre>', $invision_markup );
// Replace '[php]' with '<pre><code>'
$invision_markup = preg_replace( '/\[php\]/', '<pre><code>', $invision_markup );
// Replace '[/php]' with '</code></pre>'
$invision_markup = preg_replace( '/\[\/php\]/', '</code></pre>', $invision_markup );
// Replace '[xml]' with '<pre><code>'
$invision_markup = preg_replace( '/\[xml\]/', '<pre><code>', $invision_markup );
// Replace '[/xml]' with '</code></pre>'
$invision_markup = preg_replace( '/\[\/xml\]/', '</code></pre>', $invision_markup );
// Replace '[CODE]' with '<pre><code>'
$invision_markup = preg_replace( '/\[CODE\]/', '<pre><code>', $invision_markup );
// Replace '[/CODE]' with '</code></pre>'
$invision_markup = preg_replace( '/\[\/CODE\]/', '</code></pre>', $invision_markup );
// Replace '[quote:XXXXXXX]' with '<blockquote>'
$invision_markup = preg_replace( '/\[quote:(.*?)\]/', '<blockquote>', $invision_markup );
// Replace '[quote="$1"]' with '<em>@$1 wrote:</em><blockquote>'
$invision_markup = preg_replace( '/\[quote="(.*?)":(.*?)\]/', '<em>@$1 wrote:</em><blockquote>', $invision_markup );
// Replace '[/quote:XXXXXXX]' with '</blockquote>'
$invision_markup = preg_replace( '/\[\/quote:(.*?)\]/', '</blockquote>', $invision_markup );
// Replace '[twitter]$1[/twitter]' with '<a href="https://twitter.com/$1">@$1</a>"
$invision_markup = preg_replace( '/\[twitter\](.*?)\[\/twitter\]/', '<a href="https://twitter.com/$1">@$1</a>', $invision_markup );
// Replace '[member='username']' with '@username"
$invision_markup = preg_replace( '/\[member=\'(.*?)\'\]/', '@$1 ', $invision_markup );
// Replace '[media]' with ''
$invision_markup = preg_replace( '/\[media\]/', '', $invision_markup );
// Replace '[/media]' with ''
$invision_markup = preg_replace( '/\[\/media\]/', '', $invision_markup );
// Replace '[list:XXXXXXX]' with '<ul>'
$invision_markup = preg_replace( '/\[list\]/', '<ul>', $invision_markup );
// Replace '[list=1:XXXXXXX]' with '<ul>'
$invision_markup = preg_replace( '/\[list=1\]/', '<ul>', $invision_markup );
// Replace '[*:XXXXXXX]' with '<li>'
$invision_markup = preg_replace( '/\[\*\](.*?)\<br \/\>/', '<li>$1</li>', $invision_markup );
// Replace '[/list:u:XXXXXXX]' with '</ul>'
$invision_markup = preg_replace( '/\[\/list\]/', '</ul>', $invision_markup );
// Replace '[hr]' with '<hr>"
$invision_markup = preg_replace( '/\[hr\]/', '<hr>', $invision_markup );
// Replace '[font=XXXXXXX]' with ''
$invision_markup = preg_replace( '/\[font=(.*?)\]/', '', $invision_markup );
// Replace '[/font]' with ''
$invision_markup = preg_replace( '/\[\/font\]/', '', $invision_markup );
// Replace any Invision smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
$invision_markup = preg_replace( '/\<img src=(.*?)EMO\_DIR(.*?)bbc_emoticon(.*?)alt=\'(.*?)\' \/\>/', '$4', $invision_markup );
$invision_markup = preg_replace( '/\:angry\:/', ':mad:', $invision_markup );
$invision_markup = preg_replace( '/\:mellow\:/', ':neutral:', $invision_markup );
$invision_markup = preg_replace( '/\:blink\:/', ':eek:', $invision_markup );
$invision_markup = preg_replace( '/B\)/', ':cool:', $invision_markup );
$invision_markup = preg_replace( '/\:rolleyes\:/', ':roll:', $invision_markup );
$invision_markup = preg_replace( '/\:unsure\:/', ':???:', $invision_markup );
// Now that Invision custom HTML has been stripped put the cleaned HTML back in $field
$field = $invision_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,523 @@
<?php
/**
* bbPress Kunena 1.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Kunena v1.x Forums for Joomla Forum converter.
*
* @since 2.5.0 bbPress (r5144)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/kunena/
*/
class Kunena1 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'ordering',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 0 or Forum > 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Open = 0 or Closed = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'locked',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'catid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'userid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages_text',
'from_fieldname' => 'message',
'join_tablename' => 'kunena_messages',
'join_type' => 'INNER',
'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id WHERE kunena_messages.parent = 0',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'catid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, Kunena v3.x 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'locked',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* Kunena v1.x Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'catid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
// Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages_text',
'from_fieldname' => 'message',
'join_tablename' => 'kunena_messages',
'join_type' => 'INNER',
'join_expression' => 'ON kunena_messages.id = kunena_messages_text.mesid WHERE kunena_messages.parent != 0',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
//Note: We are importing the Joomla User details and the Kunena v1.x user profile details.
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
// $this->field_map[] = array(
// 'from_tablename' => 'user',
// 'from_fieldname' => 'salt',
// 'to_type' => 'user',
// 'to_fieldname' => ''
// );
// User password verify class (Stored in usermeta for verifying password)
// $this->field_map[] = array(
// 'to_type' => 'user',
// 'to_fieldname' => '_bbp_class',
// 'default' => 'Kunena1'
// );
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'registerDate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass($field, $row) {
$pass_array = array('hash' => $field, 'salt' => $row['salt']);
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass($password, $serialized_pass) {
$pass_array = unserialize($serialized_pass);
return ( $pass_array['hash'] == md5(md5($password) . $pass_array['salt']) );
}
/**
* Translate the forum type from Kunena v1.x numerics to WordPress's strings.
*
* @param int $status Kunena v1.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == 0 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the forum status from Kunena v1.x numerics to WordPress's strings.
*
* @param int $status Kunena v1.x numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from Kunena v1.x numerics to WordPress's strings.
*
* @param int $status Kunena v1.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
}

View File

@@ -0,0 +1,564 @@
<?php
/**
* bbPress Kunena 2.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Kunena v2.x Forums for Joomla Forum converter.
*
* @since 2.5.0 bbPress (r5144)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/kunena/
*/
class Kunena2 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'alias',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'ordering',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 0 or Forum = >0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Open = 0 or Closed = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'locked',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'category_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_userid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'kunena_messages' table because 'kunena_topics' table does not include author ip.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'join_tablename' => 'kunena_topics',
'join_type' => 'LEFT',
'join_expression' => 'USING (id)',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_message',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'category_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, Kunena v2.x 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'locked',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* Kunena v2.x Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'catid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
// Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages_text',
'from_fieldname' => 'message',
'join_tablename' => 'kunena_messages',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id LEFT JOIN jos_kunena_topics AS kunena_topics ON kunena_messages.thread = kunena_topics.id WHERE kunena_messages.parent != 0',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
//Note: We are importing the Joomla User details and the Kunena v2.x user profile details.
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt. This is only used for the SELECT row info for the above password save
/*
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
*/
// User password verify class. Stores in usermeta for verifying password.
/*
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'Kunena2'
);
*/
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'registerDate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass($field, $row) {
$pass_array = array('hash' => $field, 'salt' => $row['salt']);
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass($password, $serialized_pass) {
$pass_array = unserialize($serialized_pass);
return ( $pass_array['hash'] == md5(md5($password) . $pass_array['salt']) );
}
/**
* Translate the forum type from Kunena v2.x numerics to WordPress's strings.
*
* @param int $status Kunena v2.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == 0 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the forum status from Kunena v2.x numerics to WordPress's strings.
*
* @param int $status Kunena v2.x numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from Kunena v2.x numerics to WordPress's strings.
*
* @param int $status Kunena v2.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count Kunena v2.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,789 @@
<?php
/**
* bbPress Kunena 3.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Kunena v3.x Forums for Joomla Forum converter.
*
* @since 2.5.0 bbPress (r5144)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/kunena/
*/
class Kunena3 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numTopics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'numPosts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'alias',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'ordering',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 0 or Forum = >0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Open = 0 or Closed = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_categories',
'from_fieldname' => 'locked',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'category_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_userid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'kunena_messages' table because 'kunena_topics' table does not include author ip.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'join_tablename' => 'kunena_topics',
'join_type' => 'LEFT',
'join_expression' => 'USING (id)',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_message',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'category_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'first_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'last_post_time',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, Kunena v3.x 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'kunena_topics',
'from_fieldname' => 'locked',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* Kunena v3.x Forums do not support topic tags out of the box
*/
/** Reply Section ******************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'catid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
// Note: We join the 'kunena_messages_text' table because 'kunena_messages' table does not include reply content.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages_text',
'from_fieldname' => 'message',
'join_tablename' => 'kunena_messages',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_messages_text.mesid = kunena_messages.id LEFT JOIN jos_kunena_topics AS kunena_topics ON kunena_messages.thread = kunena_topics.id WHERE kunena_messages.parent != 0',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'kunena_messages',
'from_fieldname' => 'time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
//Note: We are importing the Joomla User details and the Kunena v3.x user profile details.
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
// $this->field_map[] = array(
// 'from_tablename' => 'users',
// 'from_fieldname' => 'salt',
// 'to_type' => 'user',
// 'to_fieldname' => ''
// );
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'Kunena3'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'websiteurl',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'registerDate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'aim',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'yim',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_yim'
);
// Store Google Tak (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'gtalk',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_jabber'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'icq',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'msn',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_msn'
);
// Store Skype (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'skype',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_skype'
);
// Store Twitter (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'twitter',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_twitter'
);
// Store Facebook (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'facebook',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_facebook'
);
// Store myspace (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'myspace',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_myspace'
);
// Store linkedin (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'linkedin',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_linkedin'
);
// Store delicious (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'delicious',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_delicious'
);
// Store friendfeed (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'friendfeed',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_friendfeed'
);
// Store digg (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'digg',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_digg'
);
// Store blogspot (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'blogspot',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_blogspot'
);
// Store flickr (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'flickr',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_flickr'
);
// Store bebo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'bebo',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_bebo'
);
// Store websitename (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'websitename',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_websitename'
);
// Store location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'location',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_location'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'kunena_users',
'from_fieldname' => 'signature',
'join_tablename' => 'users',
'join_type' => 'LEFT',
'join_expression' => 'ON kunena_users.userid = users.id',
'to_type' => 'user',
'to_fieldname' => '_bbp_kunena3_user_sig',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from Kunena v3.x numerics to WordPress's strings.
*
* @param int $status Kunena v3.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == 0 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the forum status from Kunena v3.x numerics to WordPress's strings.
*
* @param int $status Kunena v3.x numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from Kunena v3.x numerics to WordPress's strings.
*
* @param int $status Kunena v3.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count Kunena v3.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,480 @@
<?php
/**
* bbPress Mingle Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Mingle Forums converter.
*
* @since 2.3.0 bbPress (r4691)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/mingle
*/
class Mingle extends BBP_Converter_Base {
/**
* Main constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section ******************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'sort',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section ******************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'parent_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'starter',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic content.
// Note: We join the forum_posts table because forum_topics do not have topic content.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'text',
'join_tablename' => 'forum_threads',
'join_type' => 'INNER',
'join_expression' => 'ON forum_posts.parent_id = forum_threads.id GROUP BY forum_threads.id',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'parent_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'status',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'date',
'to_type' => 'topic',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* Mingle Forums do not support topic tags
*/
/** Reply Section ******************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Setup reply section table joins
// We need join the 'forum_threads' table to only import replies
$this->field_map[] = array(
'from_tablename' => 'forum_threads',
'from_fieldname' => 'date',
'join_tablename' => 'forum_posts',
'join_type' => 'INNER',
'join_expression' => 'ON forum_posts.parent_id = forum_threads.id',
'from_expression' => 'WHERE forum_threads.subject != forum_posts.subject',
'to_type' => 'reply',
'to_fieldname' => '_bbp_last_active_time'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'parent_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'parent_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'author_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'text',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'parent_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'date',
'to_type' => 'reply',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'ID',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_pass',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_login',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_nicename',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered'
);
// User status.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_status',
'to_type' => 'user',
'to_fieldname' => 'user_status'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'display_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
return false;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
return false;
}
/**
* Translate the topic status from Mingle numerics to WordPress's strings.
*
* @param int $status Mingle v1.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from Mingle numerics to WordPress's strings.
*
* @param int $status Mingle numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 'sticky' :
$status = 'sticky'; // Mingle Sticky 'status = sticky'
break;
case 'open' :
default :
$status = 'normal'; // Mingle Normal Topic 'status = open'
break;
}
return $status;
}
}

View File

@@ -0,0 +1,590 @@
<?php
/**
* bbPress MyBB Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of MyBB Forum converter.
*
* @since 2.5.0 bbPress (r5140)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/mybb
*/
class MyBB extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'pid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'threads',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'disporder',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'uid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ipaddress',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE replyto = 0',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'posts' table because 'threads' table does not have content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE replyto = 0',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'lastpost',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'lastpost',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'lastpost',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, MyBB v1.6.10 open = null & closed = 1)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* MyBB v1.6.10 Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'pid',
'from_expression' => 'WHERE replyto != 0',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'fid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'ipaddress',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'uid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edittime',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edittime',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'uid',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'MyBB'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'website',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'regdate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'usertitle',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_mybb_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_mybb_user_yim'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_mybb_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_mybb_user_msn'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'signature',
'to_type' => 'user',
'to_fieldname' => '_bbp_mybb_user_sig',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the post status from MyBB v1.6.10 numerics to WordPress's strings.
*
* @param int $status MyBB v1.6.10 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from MyBB v1.6.10 numerics to WordPress's strings.
*
* @param int $status MyBB v1.6.10 numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // MyBB Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // MyBB Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count MyBB v1.6.10 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,620 @@
<?php
/**
* bbPress PHPFox3 Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of PHPFox v3.x Forum converter.
*
* @since 2.5.0 bbPress (r5146)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/phpfox
*/
class PHPFox3 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'total_thread',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'total_post',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'total_thread',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'total_post',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'name_url',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'ordering',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Forum = 0 or Category = 1, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'is_category',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (0=Open or 1=Closed, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'is_closed',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'thread_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'total_post',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'total_post',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic content.
// Note: We join the 'forum_post_text' table because 'forum_thread' table does not include content.
// Note: We can use 'text' for original text OR 'text_parsed' for pre-parsed text output
$this->field_map[] = array(
'from_tablename' => 'forum_post_text',
'from_fieldname' => 'text_parsed',
'join_tablename' => 'forum_thread',
'join_type' => 'LEFT',
'join_expression' => 'ON forum_thread.start_id = forum_post_text.post_id',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'title_url',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Open or Closed, PHPFox v3.5.x 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'is_closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'order_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'time_stamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'time_stamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'time_update',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'time_update',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'time_update',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'item_id',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tag_id',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tag_text',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tag_url',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'post_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_thread',
'from_fieldname' => 'forum_id',
'join_tablename' => 'forum_post',
'join_type' => 'LEFT',
'join_expression' => 'USING (thread_id)',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'thread_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
// Note: We join the 'forum_post_text' table because 'forum_post' table does not include content.
// Note: We can use 'text' for original text OR 'text_parsed' for pre-parsed text output
$this->field_map[] = array(
'from_tablename' => 'forum_post_text',
'from_fieldname' => 'text_parsed',
'join_tablename' => 'forum_post',
'join_type' => 'LEFT',
'join_expression' => 'ON forum_post_text.post_id = forum_post.post_id WHERE forum_thread.start_id != forum_post.post_id',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'thread_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'time_stamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'time_stamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'time_stamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_post',
'from_fieldname' => 'time_stamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password_salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'PHPFox3'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_name',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'joined',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'full_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from PHPFox v3.5.x numerics to WordPress's strings.
*
* @param int $status PHPFox v3.5.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'category';
break;
case 0 :
default :
$status = 'forum';
break;
}
return $status;
}
/**
* Translate the forum status from PHPFox v3.5.x numerics to WordPress's strings.
*
* @param int $status PHPFox v3.5.x numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from PHPFox v3.5.x numerics to WordPress's strings.
*
* @param int $status PHPFox v3.5.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from PHPFox v3.5.x numerics to WordPress's strings.
*
* @param int $status PHPFox v3.5.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // PHPFox Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // PHPFox Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count PHPFox v3.5.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,569 @@
<?php
/**
* bbPress PHPWind Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of PHPWind Forum converter.
*
* @since 2.5.0 bbPress (r5142)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/phpwind
*/
class PHPWind extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'fid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'parentid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
// Note: We join the 'bbs_forum_statistics' table because 'bbs_forum' table does not include topic and reply counts.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum_statistics',
'from_fieldname' => 'threads',
'join_tablename' => 'bbs_forum',
'join_type' => 'LEFT',
'join_expression' => 'USING (fid)',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
// Note: We join the 'bbs_forum_statistics' table because 'bbs_forum' table does not include topic and reply counts.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum_statistics',
'from_fieldname' => 'posts',
'join_tablename' => 'bbs_forum',
'join_type' => 'LEFT',
'join_expression' => 'USING (fid)',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
// Note: We join the 'bbs_forum_statistics' table because 'bbs_forum' table does not include topic and reply counts.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum_statistics',
'from_fieldname' => 'threads',
'join_tablename' => 'bbs_forum',
'join_type' => 'LEFT',
'join_expression' => 'USING (fid)',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
// Note: We join the 'bbs_forum_statistics' table because 'bbs_forum' table does not include topic and reply counts.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum_statistics',
'from_fieldname' => 'posts',
'join_tablename' => 'bbs_forum',
'join_type' => 'LEFT',
'join_expression' => 'USING (fid)',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'descrip',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'vieworder',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = category or Forum = forum, sub or sub2, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_forum',
'from_fieldname' => 'type',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'bbs_forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'bbs_forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'bbs_forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'bbs_forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'created_userid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'created_ip',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'bbs_threads_content' table because 'bbs_threads' table does not have content.
$this->field_map[] = array(
'from_tablename' => 'bbs_threads_content',
'from_fieldname' => 'content',
'join_tablename' => 'bbs_threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid)',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'created_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'created_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'lastpost_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'lastpost_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'lastpost_time',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, PHPWind v9.x 0=no, 1=closed & 2=open)
$this->field_map[] = array(
'from_tablename' => 'bbs_threads',
'from_fieldname' => 'tpcstatus',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* PHPWind v9.x Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'pid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'fid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'content',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'bbs_posts',
'from_fieldname' => 'created_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'uid',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
// 'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
/* $this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'pass',
'to_type' => 'user',
'to_fieldname' => ''
);
*/
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'PHPWind'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'regdate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'realname',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from PHPWind v9.x Capitalised case to WordPress's non-capatilise case strings.
*
* @param int $status PHPWind v9.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 1 ) {
switch ( $status ) {
case 'category' :
$status = 'category';
break;
case 'sub' :
$status = 'forum';
break;
case 'sub2' :
$status = 'forum';
break;
case 'forum' :
default :
$status = 'forum';
break;
}
return $status;
}
/**
* Translate the post status from PHPWind v9.x numerics to WordPress's strings.
*
* @param int $status PHPWind v9.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 2 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 2 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count PHPWind v9.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,590 @@
<?php
/**
* bbPress Phorum Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Phorum Forum converter.
*
* @since 2.5.0 bbPress (r5141)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/phorum
*/
class Phorum extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'parent_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'thread_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'message_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'display_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 1 or Forum = 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'folder_flag',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'thread',
'from_expression' => 'WHERE parent_id = 0',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'thread_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'thread_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'author',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'ip',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'body',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open = 0 or Closed = 1)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
/** Tags Section ******************************************************/
/**
* Phorum v5.2.19 Forums do not support topic tags out of the box
*/
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribers',
'from_fieldname' => 'thread',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribers',
'from_fieldname' => 'user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'message_id',
'from_expression' => 'WHERE parent_id != 0',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'forum_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'author',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'body',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'thread',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
// $this->field_map[] = array(
// 'from_tablename' => 'users',
// 'from_fieldname' => 'salt',
// 'to_type' => 'user',
// 'to_fieldname' => ''
// );
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'Phorum'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'display_name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'date_added',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'real_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'signature',
'to_type' => 'user',
'to_fieldname' => '_bbp_phorum_user_sig',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from Phorum v5.2.19 numerics to WordPress's strings.
*
* @param int $status Phorum v5.2.19 numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'category';
break;
case 0 :
default :
$status = 'forum';
break;
}
return $status;
}
/**
* Translate the post status from Phorum v5.2.19 numerics to WordPress's strings.
*
* @param int $status Phorum v5.2.19 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count Phorum v5.2.19 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,737 @@
<?php
/**
* bbPress PunBB Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of PunBB v1.4.2 Forum converter.
*
* @since 2.5.0 bbPress (r5153)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/punbb
*/
class PunBB extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_desc',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'disp_position',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions',
'from_fieldname' => 'forum_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_subscriptions',
'from_fieldname' => 'user_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: We join the 'posts' table because 'topics' table does not have user id's.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'poster',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'posts' table because 'topics' table does not have author ip.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'posts' table because 'topics' table does not have content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.first_post_id = posts.id',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Open or Closed, PunBB v1.4.2 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'posted',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'last_post',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
/**
* PunBB v1.4.2 Forums do not support topic tags out of the box
*/
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscriptions',
'from_fieldname' => 'topic_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscriptions',
'from_fieldname' => 'user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
// Note: We join the 'topics' table because 'posts' table does not have parent forum id's.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'join_tablename' => 'posts',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id = posts.topic_id WHERE topics.first_post_id != posts.id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'posted',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edited',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'edited',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
// Don't import user id 1, this is PunBB's guest user
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'id',
'from_expression' => 'WHERE id != 1',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'users',
'to_fieldname' => '_bbp_class',
'default' => 'PunBB'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'realname',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_yim'
);
// Store Jabber
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'jabber',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_jabber'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_msn'
);
// Store Facebook (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'facebook',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_facebook'
);
// Store Twitter (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'twitter',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_twitter'
);
// Store LinkedIn (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'linkedin',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_linkedin'
);
// Store Skype (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'skype',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_skype'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'signature',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_sig',
'callback_method' => 'callback_html'
);
// Store Location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'location',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_from'
);
// Store Admin Note (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'admin_note',
'to_type' => 'user',
'to_fieldname' => '_bbp_punbb_user_admin_note'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the post status from PunBB v1.4.2 numerics to WordPress's strings.
*
* @param int $status PunBB v1.4.2 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from PunBB v1.4.2 numerics to WordPress's strings.
*
* @param int $status PunBB v1.4.2 numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // PunBB Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // PunBB Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count PunBB v1.4.2 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,812 @@
<?php
/**
* bbPress SMF Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of SMF Forum converter.
*
* @since 2.5.0 bbPress (r5189)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/smf
*/
class SMF extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section ******************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'id_board',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'id_parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'num_topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'num_posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'boards',
'from_fieldname' => 'board_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'log_notify',
'from_fieldname' => 'id_board',
'from_expression' => 'WHERE log_notify.id_board != 0',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'log_notify',
'from_fieldname' => 'id_member',
'from_expression' => 'WHERE log_notify.id_board != 0',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section ******************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_topic',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'num_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_board',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_member_started',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_name',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_member_started',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'messages' table because 'topics' table does not have content.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'body',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'subject',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'subject',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_board',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Open or Closed, SMF v2.0.4 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'locked',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'is_sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'join_tablename' => 'topics',
'join_type' => 'LEFT',
'join_expression' => 'ON topics.id_first_msg = messages.id_msg',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
/**
* SMF v2.0.4 Forums do not support topic tags out of the box
*/
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'log_notify',
'from_fieldname' => 'id_topic',
'from_expression' => 'WHERE log_notify.id_topic != 0',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'log_notify',
'from_fieldname' => 'id_member',
'from_expression' => 'WHERE log_notify.id_topic != 0',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'id_msg',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'id_board',
'join_tablename' => 'messages',
'join_type' => 'LEFT',
'join_expression' => 'USING (id_topic) WHERE topics.id_first_msg != messages.id_msg',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'id_topic',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'id_member',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_name',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'id_member',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'body',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'id_topic',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'messages',
'from_fieldname' => 'poster_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'id_member',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'passwd',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'SMF'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'member_name',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'member_name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'email_address',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'website_url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'date_registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'real_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'yim',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_yim'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_msn'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'signature',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_sig',
'callback_method' => 'callback_html'
);
// Store Avatar (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'avatar',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_avatar',
'callback_method' => 'callback_html'
);
// Store Location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'location',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_location',
'callback_method' => 'callback_html'
);
// Store Personal Text (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'personal_text',
'to_type' => 'user',
'to_fieldname' => '_bbp_smf_user_personal_text',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'username' => $row['member_name'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] === sha1( strtolower( $pass_array['username'] ) . $password ) ? true : false );
}
/**
* Translate the post status from SMF v2.0.4 numerics to WordPress's strings.
*
* @param int $status SMF v2.0.4 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from SMF v2.0.4 numerics to WordPress's strings.
*
* @param int $status SMF v2.0.4 numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // SMF Sticky 'is_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // SMF normal topic 'is_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count SMF v2.0.4 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This callback processes any custom parser.php attributes and custom code with preg_replace
*/
protected function callback_html( $field ) {
// Strips SMF custom HTML first from $field before parsing $field to parser.php
$SMF_markup = $field;
$SMF_markup = html_entity_decode( $SMF_markup );
// Replace '[quote]' with '<blockquote>'
$SMF_markup = preg_replace( '/\[quote\]/', '<blockquote>', $SMF_markup );
// Replace '[quote ($1)]' with '<blockquote>"
$SMF_markup = preg_replace( '/\[quote (.*?)\]/' , '<blockquote>', $SMF_markup );
// Replace '[/quote]' with '</blockquote>'
$SMF_markup = preg_replace( '/\[\/quote\]/', '</blockquote>', $SMF_markup );
// Replace '[glow]' with ''
$SMF_markup = preg_replace( '/\[glow\]/', '', $SMF_markup );
// Replace '[glow]' with ''
$SMF_markup = preg_replace( '/\[glow=(.*?)\]/', '', $SMF_markup );
// Replace '[/glow]' with ''
$SMF_markup = preg_replace( '/\[\/glow\]/', '', $SMF_markup );
// Replace '[shadow]' with ''
$SMF_markup = preg_replace( '/\[shadow\]/', '', $SMF_markup );
// Replace '[shadow]' with ''
$SMF_markup = preg_replace( '/\[shadow=(.*?)\]/', '', $SMF_markup );
// Replace '[/shadow]' with ''
$SMF_markup = preg_replace( '/\[\/shadow\]/', '', $SMF_markup );
// Replace '[move]' with ''
$SMF_markup = preg_replace( '/\[move\]/', '', $SMF_markup );
// Replace '[/move]' with ''
$SMF_markup = preg_replace( '/\[\/move\]/', '', $SMF_markup );
// Replace '[table]' with '<table>'
$SMF_markup = preg_replace( '/\[table\]/', '<table>', $SMF_markup );
// Replace '[/table]' with '</table>'
$SMF_markup = preg_replace( '/\[\/table\]/', '</table>', $SMF_markup );
// Replace '[tr]' with '<tr>'
$SMF_markup = preg_replace( '/\[tr\]/', '<tr>', $SMF_markup );
// Replace '[/tr]' with '</tr>'
$SMF_markup = preg_replace( '/\[\/tr\]/', '</tr>', $SMF_markup );
// Replace '[td]' with '<td>'
$SMF_markup = preg_replace( '/\[td\]/', '<td>', $SMF_markup );
// Replace '[/td]' with '</td>'
$SMF_markup = preg_replace( '/\[\/td\]/', '</td>', $SMF_markup );
// Replace '[list]' with '<ul>'
$SMF_markup = preg_replace( '/\[list\]/', '<ul>', $SMF_markup );
// Replace '[liist type=decimal]' with '<ol type="a">'
$SMF_markup = preg_replace( '/\[list\ type=decimal\]/', '<ol type="a">', $SMF_markup );
// Replace '[li]' with '<li>'
$SMF_markup = preg_replace( '/\[li\]/', '<li>', $SMF_markup );
// Replace '[/li]' with '</li>'
$SMF_markup = preg_replace( '/\[\/li\]/', '</li>', $SMF_markup );
// Replace '[tt]' with '<tt>'
$SMF_markup = preg_replace( '/\[tt\]/', '<tt>', $SMF_markup );
// Replace '[/tt]' with '</tt>'
$SMF_markup = preg_replace( '/\[\/tt\]/', '</tt>', $SMF_markup );
// Replace '<br />' with '<br>'
$SMF_markup = preg_replace( '/\<br \/\>/', '<br>', $SMF_markup );
// Replace '[size=$1]' with '<span style="font-size:$1%;">$3</span>'
$SMF_markup = preg_replace( '/\[size=(.*?)\]/', '<span style="font-size:$1">', $SMF_markup );
// Replace '[/size]' with '</span>'
$SMF_markup = preg_replace( '/\[\/size\]/', '</span>', $SMF_markup );
// Replace non-break space '&nbsp;' with space ' '
$SMF_markup = preg_replace( '/&nbsp;/', ' ', $SMF_markup );
// Now that SMF custom HTML has been stripped put the cleaned HTML back in $field
$field = $SMF_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,616 @@
<?php
/**
* bbPress SimplePress5 Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of SimplePress v5 converter.
*
* @since 2.3.0 bbPress (r4638)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/simplepress/
*/
class SimplePress5 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'topic_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'post_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'topic_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'post_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'forum_desc',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'sfforums',
'from_fieldname' => 'forum_seq',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forums',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forums',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forums',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forums',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'post_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'sftopics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'guest_name',
'join_tablename' => 'sftopics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic content.
// Note: We join the sfposts table because sftopics do not have content.
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_content',
'join_tablename' => 'sftopics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE sfposts.post_index = 1',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_name',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_name',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_status',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_pinned',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'sftopics',
'from_fieldname' => 'topic_date',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time'
);
/** Tags Section ******************************************************/
/**
* SimplePress Forums do not support topic tags without paid extensions
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'forum_id',
'from_expression' => 'WHERE post_index != 1',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'guest_name',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_content',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'sfposts',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'ID',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_pass',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_login',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_nicename',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered'
);
// User status.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_status',
'to_type' => 'user',
'to_fieldname' => 'user_status'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'display_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
return false;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
return false;
}
/**
* Translate the post status from Simple:Press v5.x numerics to WordPress's strings.
*
* @param int $status Simple:Press numeric status
* @return string WordPress safe
*/
public function callback_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from Simple:Press v5.x numerics to WordPress's strings.
*
* @param int $status Simple:Press v5.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // Simple:Press Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // Simple:Press Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count Simple:Press v5.x reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This callback processes any custom parser.php attributes and custom HTML code with preg_replace
*/
protected function callback_html( $field ) {
// Strip any custom HTML not supported by parser.php first from $field before parsing $field to parser.php
$simplepress_markup = $field;
$simplepress_markup = html_entity_decode( $simplepress_markup );
// Replace any SimplePress smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-confused\.gif(.*?)\" \/>/', ':?' , $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cool\.gif(.*?)\" \/>/', ':cool:', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-cry\.gif(.*?)\" \/>/', ':cry:', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-embarassed\.gif(.*?)\" \/>/' , ':oops:', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-frown\.gif(.*?)\" \/>/', ':(', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-kiss\.gif(.*?)\" \/>/', ':P', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-laugh\.gif(.*?)\" \/>/', ':D', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-smile\.gif(.*?)\" \/>/', ':smile:', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-surprised\.gif(.*?)\" \/>/', ':o', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-wink\.gif(.*?)\" \/>/', ':wink:', $simplepress_markup );
$simplepress_markup = preg_replace( '/\<img src=(.*?)\/sp-resources\/forum-smileys\/sf-yell\.gif(.*?)\" \/>/', ':x', $simplepress_markup );
// Replace '<div class="sfcode">example code</div>' with '<code>*</code>'
$simplepress_markup = preg_replace( '/\<div class\=\"sfcode\"\>(.*?)\<\/div\>/' , '<code>$1</code>' , $simplepress_markup );
// Replace '<strong>username said </strong>' with '@username said:'
$simplepress_markup = preg_replace( '/\<strong\>(.*?)\ said\ \<\/strong\>/', '@$1 said:', $simplepress_markup );
// Replace '<p>&nbsp;</p>' with '<p>&nbsp;</p>'
$simplepress_markup = preg_replace( '/\n(&nbsp;|[\s\p{Z}\xA0\x{00A0}]+)\r/', '<br>', $simplepress_markup );
// Now that SimplePress' custom HTML codes have been stripped put the cleaned HTML back in $field
$field = $simplepress_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,608 @@
<?php
/**
* bbPress Vanilla Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of Vanilla 2.0.18.1 Converter
*
* @since 2.3.0 bbPress (r4717)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/vanilla
*/
class Vanilla extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'CategoryID',
'from_expression' => 'WHERE Category.CategoryID > 0',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'ParentCategoryID',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id',
'callback_method' => 'callback_forum_parent'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'CountDiscussions',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'CountComments',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'CountDiscussions',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'CountComments',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'Name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'Name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'Description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'Sort',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Set a default value 'forum', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'default' => 'forum'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'DateInserted',
'to_type' => 'forum',
'to_fieldname' => 'post_date',
);
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'DateInserted',
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
);
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'DateUpdated',
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
);
$this->field_map[] = array(
'from_tablename' => 'Category',
'from_fieldname' => 'DateUpdated',
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
// Don't import Vanilla 2's deleted topics
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DiscussionID',
'from_expression' => 'WHERE Format != "Deleted"',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'CountComments',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'CountComments',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'CategoryID',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'InsertUserID',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id',
'default' => 'Anonymous'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'InsertUserID',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'Name',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'Name',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'Body',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Topic author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'InsertIPAddress',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'CategoryID',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'Announce',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DateInserted',
'to_type' => 'topic',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DateInserted',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DateUpdated',
'to_type' => 'topic',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DateUpdated',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'Discussion',
'from_fieldname' => 'DateLastComment',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'TagDiscussion',
'from_fieldname' => 'DiscussionID',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'TagDiscussion',
'from_fieldname' => 'TagID',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'Tag',
'from_fieldname' => 'Name',
'join_tablename' => 'TagDiscussion',
'join_type' => 'INNER',
'join_expression' => 'USING (tagid)',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
// Don't import Vanilla 2's deleted replies
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'CommentID',
'from_expression' => 'WHERE Format != "Deleted"',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DiscussionID',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DiscussionID',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'InsertIPAddress',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'InsertUserID',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id',
'default' => 'Anonymous'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'InsertUserID',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'Body',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DiscussionID',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DateInserted',
'to_type' => 'reply',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DateInserted',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DateUpdated',
'to_type' => 'reply',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'Comment',
'from_fieldname' => 'DateUpdated',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
// Don't import user Vanilla's deleted users
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'UserID',
'from_expression' => 'WHERE Deleted !=1',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'Password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'Name',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'Name',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'Email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'DateInserted',
'to_type' => 'user',
'to_fieldname' => 'user_registered'
);
// Display Name
$this->field_map[] = array(
'from_tablename' => 'User',
'from_fieldname' => 'Name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* Translate the topic status from Vanilla v2.x numerics to WordPress's strings.
*
* @param int $status Vanilla v2.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'closed';
break;
case 0 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from Vanilla v2.x numerics to WordPress's strings.
*
* @param int $status Vanilla v2.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // Vanilla Sticky 'Announce = 1'
break;
case 0 :
default :
$status = 'normal'; // Vanilla normal topic 'Announce = 0'
break;
}
return $status;
}
/**
* Clean Root Parent ID -1 to 0
*
* @param int $parent Vanilla v2.x Parent ID
* @return int
*/
public function callback_forum_parent( $parent = 0 ) {
if ( $parent == -1 ) {
return 0;
} else {
return $parent;
}
}
/**
* Verify the topic reply count.
*
* @param int $count Vanilla v2.x reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
return false;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
return false;
}
}

View File

@@ -0,0 +1,721 @@
<?php
/**
* bbPress XMB Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of XMB Forum converter.
*
* @since 2.5.0 bbPress (r5143)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/xmb
*/
class XMB extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'fup',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'threads',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'threads',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'displayorder',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 'group', Forum = 'forum' or 'sub', Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'type',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'tid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: We join the 'members' table because 'threads' table does not have numerical author id.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'uid',
'join_tablename' => 'threads',
'join_type' => 'LEFT',
'join_expression' => 'ON threads.author = members.username',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'author',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'uid',
'join_tablename' => 'threads',
'join_type' => 'LEFT',
'join_expression' => 'ON threads.author = members.username WHERE posts.subject = ""',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'posts' table because 'threads' table does not have author ip.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'useip',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic content.
// Note: We join the 'posts' table because 'threads' table does not have content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'subject',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'fid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic status (Open or Closed, XMB v1.9.11.13 ''=open & 'yes'=closed)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'closed',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'threads',
'from_fieldname' => 'topped',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
// Note: We join the 'posts' table because 'threads' table does not include dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'join_tablename' => 'threads',
'join_type' => 'INNER',
'join_expression' => 'USING (tid) WHERE posts.subject != ""',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
/**
* XMB v1.9.11.13 Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'pid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'fid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'useip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
// Note: We join the 'members' table because 'posts' table does not have numerical author id.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'uid',
'join_tablename' => 'posts',
'join_type' => 'LEFT',
'join_expression' => 'ON posts.author = members.username WHERE posts.subject = ""',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'author',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'uid',
'join_tablename' => 'posts',
'join_type' => 'LEFT',
'join_expression' => 'ON posts.author = members.username WHERE posts.subject = ""',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'message',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'tid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'uid',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old User password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old User Salt (This is only used for the SELECT row info for the above password save)
// $this->field_map[] = array(
// 'from_tablename' => 'members',
// 'from_fieldname' => 'salt',
// 'to_type' => 'user',
// 'to_fieldname' => ''
// );
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'members',
'to_fieldname' => '_bbp_class',
'default' => 'XMB'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'site',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'regdate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_yim'
);
// Store ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_icq'
);
// Store MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_msn'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'sig',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_sig',
'callback_method' => 'callback_html'
);
// Store Bio (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'bio',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_bio',
'callback_method' => 'callback_html'
);
// Store Location (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'location',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_location'
);
// Store Avatar (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'avatar',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_avatar'
);
// Store Mood (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'members',
'from_fieldname' => 'mood',
'to_type' => 'user',
'to_fieldname' => '_bbp_xmb_user_mood'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from XMB v1.9.11.13 Capitalised case to WordPress's non-capatilise case strings.
*
* @param int $status XMB v1.9.11.13 numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 1 ) {
switch ( $status ) {
case 'group' :
$status = 'category';
break;
case 'sub' :
$status = 'forum';
break;
case 'forum' :
default :
$status = 'forum';
break;
}
return $status;
}
/**
* Translate the post status from XMB v1.9.11.13 numerics to WordPress's strings.
*
* @param int $status XMB v1.9.11.13 numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = '' ) {
switch ( $status ) {
case 'yes' :
$status = 'closed';
break;
case '' :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from XMB v1.9.11.13 numerics to WordPress's strings.
*
* @param int $status XMB v1.9.11.13 numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // XMB Sticky 'topped = 1'
break;
case 0 :
default :
$status = 'normal'; // XMB Normal Topic 'topped = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count XMB v1.9.11.13 topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
}

View File

@@ -0,0 +1,850 @@
<?php
/**
* bbPress XenForo Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of XenForo converter.
*
* @since 2.5.0 bbPress (r5145)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/xenforo
*/
class XenForo extends BBP_Converter_Base {
/**
* Main constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'node_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'parent_node_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
// Note: We join the 'forum' table because 'node' does not include topic counts.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'discussion_count',
'join_tablename' => 'node',
'join_type' => 'LEFT',
'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
// Note: We join the 'forum' table because 'node' does not include reply counts.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'message_count',
'join_tablename' => 'node',
'join_type' => 'LEFT',
'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
// Note: We join the 'forum' table because 'node' does not include topic counts.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'discussion_count',
'join_tablename' => 'node',
'join_type' => 'LEFT',
'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
// Note: We join the 'forum' table because 'node' does not include reply counts.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'message_count',
'join_tablename' => 'node',
'join_type' => 'LEFT',
'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'title',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
// 'node_name' only has slug for explictly named forums
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'node_name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'display_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = Category or Forum = Forum, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'node',
'from_fieldname' => 'node_type_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Unlocked = 1 or Locked = 0, Stored in postmeta)
// Note: We join the 'forum' table because 'node' does not include forum status.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'allow_posting',
'join_tablename' => 'node',
'join_type' => 'LEFT',
'join_expression' => 'USING (node_id) WHERE node.node_type_id = "Category" OR node.node_type_id = "Forum" ',
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'callback_method' => 'callback_forum_status'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_watch',
'from_fieldname' => 'node_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'forum_watch',
'from_fieldname' => 'user_id',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'thread_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'reply_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'reply_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'node_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'username',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic content.
// Note: We join the 'post' table because 'thread' table does not include content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'message',
'join_tablename' => 'thread',
'join_type' => 'INNER',
'join_expression' => 'ON thread.first_post_id = post.post_id',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic status (Visible or Deleted)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'discussion_state',
'to_type' => 'topic',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Topic status (Open = 1 or Closed = 0)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'discussion_open',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'node_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'post_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'post_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'last_post_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'last_post_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'last_post_date',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
/**
* XenForo Forums do not support topic tags out of the box
*/
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'thread_watch',
'from_fieldname' => 'thread_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'thread_watch',
'from_fieldname' => 'user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'post_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Join the 'thread' table to exclude topics from being imported as replies
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'thread_id',
'join_tablename' => 'post',
'join_type' => 'LEFT',
'join_expression' => 'USING (thread_id) WHERE thread.first_post_id != post.post_id',
'to_type' => 'reply'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'thread_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'thread_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply status (Visible or Deleted)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'message_state',
'to_type' => 'reply',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'username',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'message',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'thread_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'post_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
/* // User password.
// Note: We join the 'user_authenticate' table because 'user' does not include password.
$this->field_map[] = array(
'from_tablename' => 'user_authenticate',
'from_fieldname' => 'data',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => '_bbp_converter_password'
);
// Store old User password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old User Salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
*/
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'XenForo'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
// Note: We join the 'user_profile' table because 'user' does not include user homepage.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'homepage',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'register_date',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// Store Custom Title (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'custom_title',
'to_type' => 'user',
'to_fieldname' => '_bbp_xenforo_user_custom_title'
);
// Store Status (Stored in usermeta)
// Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user status.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'status',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => '_bbp_xenforo_user_status'
);
// Store Signature (Stored in usermeta)
// Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user signature.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'signature',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_fieldname' => '_bbp_xenforo_user_sig',
'to_type' => 'user',
'callback_method' => 'callback_html'
);
// Store Location (Stored in usermeta)
// Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user location.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'location',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => '_bbp_xenforo_user_location'
);
// Store Occupation (Stored in usermeta)
// Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user occupation.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'occupation',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => '_bbp_xenforo_user_occupation'
);
// Store About (Stored in usermeta)
// Note: We join the 'user_profile' table because 'user' does not include user custom XenForo field user about.
$this->field_map[] = array(
'from_tablename' => 'user_profile',
'from_fieldname' => 'about',
'join_tablename' => 'user',
'join_type' => 'LEFT',
'join_expression' => 'USING (user_id)',
'to_type' => 'user',
'to_fieldname' => '_bbp_xenforo_user_about',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function translate_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
switch( $pass_array['hashFunc'] ) {
case 'sha256':
return ( $pass_array['hash'] == hash( 'sha256', hash( 'sha256', $password ) . $pass_array['salt'] ) );
case 'sha1':
return ( $pass_array['hash'] == sha1( sha1( $password ) . $pass_array['salt'] ) );
}
}
/**
* Translate the forum type from XenForo Capitalised case to WordPress's non-capatilise case strings.
*
* @param int $status XenForo numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 1 ) {
switch ( $status ) {
case 'Category' :
$status = 'category';
break;
case 'Forum' :
default :
$status = 'forum';
break;
}
return $status;
}
/**
* Translate the forum status from XenForo numerics to WordPress's strings.
*
* @param int $status XenForo numeric forum status
* @return string WordPress safe
*/
public function callback_forum_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'open';
break;
}
return $status;
}
/**
* Translate the post status from XenForo to WordPress' strings.
*
* @param int $status XenForo post status
* @return string WordPress safe
*/
public function callback_status( $status = 1 ) {
switch ( $status ) {
case 'deleted' :
$status = 'pending'; // bbp_get_pending_status_id()
break;
case 'visible' :
default :
$status = 'publish'; // bbp_get_public_status_id()
break;
}
return $status;
}
/**
* Translate the topic status from XenForo numerics to WordPress's strings.
*
* @param int $status XenForo numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from XenForo numerics to WordPress's strings.
*
* @param int $status XenForo numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // XenForo Sticky 'sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // XenForo Normal Topic 'sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count XenForo reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This callback processes any custom parser.php attributes and custom code with preg_replace
*/
protected function callback_html( $field ) {
// Strips Xenforo custom HTML first from $field before parsing $field to parser.php
$xenforo_markup = $field;
$xenforo_markup = html_entity_decode( $xenforo_markup );
// Replace '[QUOTE]' with '<blockquote>'
$xenforo_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $xenforo_markup );
// Replace '[/QUOTE]' with '</blockquote>'
$xenforo_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $xenforo_markup );
// Replace '[QUOTE=User Name($1)]' with '<em>@$1 wrote:</em><blockquote>"
$xenforo_markup = preg_replace( '/\[quote=\"(.*?)\,\spost\:\s(.*?)\,\s\member\:\s(.*?)\"\](.*?)\[\/quote\]/', '<em>@$1 wrote:</em><blockquote>', $xenforo_markup );
// Replace '[/quote]' with '</blockquote>'
$xenforo_markup = preg_replace( '/\[\/quote\]/', '</blockquote>', $xenforo_markup );
// Replace '[media=youtube]$1[/media]' with '$1"
$xenforo_markup = preg_replace( '/\[media\=youtube\](.*?)\[\/media\]/', 'https://youtu.be/$1', $xenforo_markup );
// Replace '[media=dailymotion]$1[/media]' with '$1"
$xenforo_markup = preg_replace( '/\[media\=dailymotion\](.*?)\[\/media\]/', 'https://www.dailymotion.com/video/$1', $xenforo_markup );
// Replace '[media=vimeo]$1[/media]' with '$1"
$xenforo_markup = preg_replace( '/\[media\=vimeo\](.*?)\[\/media\]/', 'https://vimeo.com/$1', $xenforo_markup );
// Now that Xenforo custom HTML has been stripped put the cleaned HTML back in $field
$field = $xenforo_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,759 @@
<?php
/**
* bbPress 1.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* bbPress 1.1 Converter
*
* @since 2.1.0 bbPress (r3816)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/bbpress-1-x-buddypress-group-forums
*/
class bbPress1 extends BBP_Converter_Base {
/**
* Main constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'topics',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'posts',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_slug',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_desc',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forums',
'from_fieldname' => 'forum_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (bbPress v1.x Forum > 0 or Category = 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'meta',
'from_fieldname' => 'meta_value',
'join_tablename' => 'forums',
'join_type' => 'LEFT',
'join_expression' => 'ON meta.object_id = forums.forum_id AND meta.meta_key = "forum_is_category"',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Forum Subscriptions Section ***************************************/
/**
* bbPress 1.x Forums do not support forum subscriptions
*/
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_posts',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_poster',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_slug',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic content.
// Note: We join the 'posts' table because 'topics' table does not include content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_text',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic status (Spam, Trash or Publish, bbPress v1.x publish = 0, trash = 1 & spam = 2)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_status',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
'to_type' => 'topic',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Topic status (Publish or Closed to new replies)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_open',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Topic author ip (Stored in postmeta)
// Note: We join the 'posts' table because 'topics' table does not include author ip.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'join_tablename' => 'topics',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE posts.post_position IN (0,1)',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_start_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_start_time',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_time',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_time',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'term_relationships',
'from_fieldname' => 'object_id',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'term_taxonomy',
'from_fieldname' => 'term_taxonomy_id',
'join_tablename' => 'term_relationships',
'join_type' => 'INNER',
'join_expression' => 'USING (term_taxonomy_id)',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term description.
$this->field_map[] = array(
'from_tablename' => 'term_taxonomy',
'from_fieldname' => 'description',
'join_tablename' => 'term_relationships',
'join_type' => 'INNER',
'join_expression' => 'USING (term_taxonomy_id)',
'to_type' => 'tags',
'to_fieldname' => 'description',
'callback_method' => 'callback_html'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'terms',
'from_fieldname' => 'name',
'join_tablename' => 'term_taxonomy',
'join_type' => 'INNER',
'join_expression' => 'USING (term_id) WHERE term_taxonomy.taxonomy = "bb_topic_tag"',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'terms',
'from_fieldname' => 'slug',
'join_tablename' => 'term_taxonomy',
'join_type' => 'INNER',
'join_expression' => 'USING (term_id) WHERE term_taxonomy.taxonomy = "bb_topic_tag"',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
/** Topic Subscriptions Section ***************************************/
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'term_relationships',
'from_fieldname' => 'user_id',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
// Join the 'term_taxonomy' table to link 'terms' 'term_relationships' tables
$this->field_map[] = array(
'from_tablename' => 'term_taxonomy',
'from_fieldname' => 'term_taxonomy_id',
'join_tablename' => 'term_relationships',
'join_type' => 'INNER',
'join_expression' => 'USING (term_taxonomy_id)',
'to_type' => 'topic_subscriptions'
);
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'terms',
'from_fieldname' => 'name',
'join_tablename' => 'term_taxonomy',
'join_type' => 'INNER',
'join_expression' => 'USING (term_id) WHERE term_taxonomy.taxonomy = "bb_subscribe"',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions',
'callback_method' => 'callback_topic_subscriptions'
);
/** Favorites Section *************************************************/
// Favorited topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'usermeta',
'from_fieldname' => 'meta_value',
'from_expression' => 'WHERE usermeta.meta_key = "bb_favorites"',
'to_type' => 'favorites',
'to_fieldname' => '_bbp_favorites'
);
// Favorited user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'usermeta',
'from_fieldname' => 'user_id',
'from_expression' => 'WHERE usermeta.meta_key = "bb_favorites"',
'to_type' => 'favorites',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
// Note: We join the 'topics' table to limit the replies section to only import replies
$this->field_map[] = array(
'from_tablename' => 'topics',
'from_fieldname' => 'topic_id',
'join_tablename' => 'posts',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id) WHERE posts.post_position NOT IN (0,1)',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'forum_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_ip',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'poster_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply status (Spam, Trash or Publish, bbPress v1.x publish = 0, trash = 1 & spam = 2)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_status',
'to_type' => 'reply',
'to_fieldname' => 'post_status',
'callback_method' => 'callback_status'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_text',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply order.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_position',
'to_type' => 'reply',
'to_fieldname' => 'menu_order'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_time',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified'
);
$this->field_map[] = array(
'from_tablename' => 'posts',
'from_fieldname' => 'post_time',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'ID',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_pass',
'to_type' => 'user',
'to_fieldname' => '_bbp_password'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_login',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_nicename',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_url',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_registered',
'to_type' => 'user',
'to_fieldname' => 'user_registered'
);
// User status.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'user_status',
'to_type' => 'user',
'to_fieldname' => 'user_status'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'users',
'from_fieldname' => 'display_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* Translate the post status from bbPress 1's numerics to WordPress's
* strings.
*
* @param int $status bbPress 1.x numeric post status
* @return string WordPress safe
*/
public function callback_status( $status = 0 ) {
switch ( $status ) {
case 2 :
$status = 'spam'; // bbp_get_spam_status_id()
break;
case 1 :
$status = 'trash'; // bbp_get_trash_status_id()
break;
case 0 :
default :
$status = 'publish'; // bbp_get_public_status_id()
break;
}
return $status;
}
/**
* Translate the forum type from bbPress 1.x numerics to WordPress's strings.
*
* @param int $status bbPress 1.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == 1 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the topic status from bbPress 1's numerics to WordPress's
* strings.
*
* @param int $topic_status bbPress 1.x numeric status
* @return string WordPress safe
*/
public function callback_topic_status( $topic_status = 1 ) {
switch ( $topic_status ) {
case 0 :
$topic_status = 'closed'; // bbp_get_closed_status_id()
break;
case 1 :
default :
$topic_status = 'publish'; // bbp_get_public_status_id()
break;
}
return $topic_status;
}
/**
* Translate the topic sticky status type from bbPress 1.x numerics to WordPress's strings.
*
* @param int $status bbPress 1.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 2 :
$status = 'super-sticky'; // bbPress Super Sticky 'topic_sticky = 2'
break;
case 1 :
$status = 'sticky'; // bbPress Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // bbPress Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count bbPress 1.x topic and reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
return false;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
return false;
}
/**
* This callback strips `topic-` from topic subscriptions taxonomy
*
* @since 2.6.0 bbPress (r5572)
*
* @param string $field Topic ID
* @return integer WordPress safe
*/
protected function callback_topic_subscriptions( $field ) {
// Replace 'topic-' with '' so that only the original topic ID remains
$field = absint( (int) preg_replace( '/(topic-)(\d+)/', '$2', $field ) );
return $field;
}
}

View File

@@ -0,0 +1,637 @@
<?php
/**
* bbPress e107 1.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of e107 v1.x Forum converter.
*
* @since 2.6.0 bbPress (r5352)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/e107
*/
class e107v1 extends BBP_Converter_Base {
/**
* Main Constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_threads',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_replies',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_threads',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_replies',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_name',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_order',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = 0 or Forum > 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forum_parent',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date('Y-m-d H:i:s')
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date('Y-m-d H:i:s')
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_id',
'from_expression' => 'WHERE thread_parent = 0',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_total_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_total_replies',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
// Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_user',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_e107v1_userid'
);
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_thread',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_name',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_name',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic status (Open or Closed, e107 v1.x open = 1 & closed = 0)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_active',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_s',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
/**
* e107 v1.x Forums do not support topic tags out of the box
*/
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_id',
'from_expression' => 'WHERE thread_parent != 0',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_forum_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_parent',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author.
// Note: Uses a custom callback to transform user id from '1.Administrator e107v1' to numeric user id.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_user',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_e107v1_userid'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_thread',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_parent',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_t',
'from_fieldname' => 'thread_datestamp',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_id',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'e107v1'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_loginname',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User nice name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_loginname',
'to_type' => 'user',
'to_fieldname' => 'user_nicename'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_join',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User display name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_name',
'to_type' => 'user',
'to_fieldname' => 'display_name'
);
// Store Signature (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'user_signature',
'to_fieldname' => '_bbp_e107v1_user_sig',
'to_type' => 'user',
'callback_method' => 'callback_html'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) );
}
/**
* Translate the forum type from e107 v1.x numerics to WordPress's strings.
*
* @param int $status e107 v1.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == 0 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the post status from e107 v1.x numerics to WordPress's strings.
*
* @param int $status e107 v1.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* Translate the topic sticky status type from e107 v1.x numerics to WordPress's strings.
*
* @param int $status e107 v1.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 2 :
$status = 'super-sticky'; // e107 Announcement Sticky 'thread_s = 2'
break;
case 1 :
$status = 'sticky'; // e107 Sticky 'thread_s = 1'
break;
case 0 :
default :
$status = 'normal'; // e107 normal topic 'thread_s = 0'
break;
}
return $status;
}
/**
* Verify the topic/reply count.
*
* @param int $count e107 v1.x topic/reply counts
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* Override the `callback_user` function in 'converter.php' for custom e107v1 imports
*
* A mini cache system to reduce database calls to user ID's
*
* @param string $field
* @return string
*/
protected function callback_e107v1_userid( $field ) {
// Strip only the user id from the topic and reply authors
$field = preg_replace( '/(\d+?)+\.[\S\s]+/', '$1', $field );
if ( ! isset( $this->map_userid[ $field ] ) ) {
if ( ! empty( $this->sync_table ) ) {
$row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
} else {
$row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) );
}
if ( ! is_null( $row ) ) {
$this->map_userid[ $field ] = $row->value_id;
} else {
if ( true === $this->convert_users ) {
$this->map_userid[ $field ] = 0;
} else {
$this->map_userid[ $field ] = $field;
}
}
}
return $this->map_userid[ $field ];
}
/**
* This callback processes any custom parser.php attributes and custom code with preg_replace
*/
protected function callback_html( $field ) {
// Strips custom e107v1 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php
$e107v1_markup = $field;
$e107v1_markup = html_entity_decode( $e107v1_markup );
// Replace '[blockquote]' with '<blockquote>'
$e107v1_markup = preg_replace( '/\[blockquote\]/', '<blockquote>', $e107v1_markup );
// Replace '[/blockquote]' with '</blockquote>'
$e107v1_markup = preg_replace( '/\[\/blockquote\]/', '</blockquote>', $e107v1_markup );
// Replace '[quote$1=$2]' with '<em>$2 wrote:</em><blockquote>"
$e107v1_markup = preg_replace( '/\[quote(.*?)=(.*?)\]/', '<em>@$2 wrote:</em><blockquote>', $e107v1_markup );
// Replace '[/quote$1]' with '</blockquote>"
$e107v1_markup = preg_replace( '/\[\/quote(.*?)\]/' , '</blockquote>', $e107v1_markup );
// Remove '[justify]'
$e107v1_markup = preg_replace( '/\[justify\]/', '', $e107v1_markup );
// Remove '[/justify]'
$e107v1_markup = preg_replace( '/\[\/justify\]/', '', $e107v1_markup );
// Replace '[link=(https|http)://$2]$3[/link]' with '<a href="$1://$2">$3</a>'
$e107v1_markup = preg_replace( '/\[link\=(https|http)\:\/\/(.*?)\](.*?)\[\/link\]/i', '<a href="$1://$2">$3</a>', $e107v1_markup );
// Replace '[list=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)]' with '[list]'
$e107v1_markup = preg_replace( '/\[list\=(decimal|lower-roman|upper-roman|lower-alpha|upper-alpha)\]/i', '[list]', $e107v1_markup );
// Replace '[youtube]$1[/youtube]' with '$1"
$e107v1_markup = preg_replace( '/\[youtube\](.*?)\[\/youtube\]/', 'https://youtu.be/$1', $e107v1_markup );
// Now that e107v1 custom HTML has been stripped put the cleaned HTML back in $field
$field = $e107v1_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,756 @@
<?php
/**
* bbPress vBulletin 4.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of vBulletin v4.x Converter.
*
* @since 2.3.0 bbPress (r4724)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/vbulletin
*/
class vBulletin extends BBP_Converter_Base {
/**
* Main constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forumid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'parentid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'threadcount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'replycount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'threadcount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'replycount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'title',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'title_clean',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'displayorder',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = -1 or Forum > 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'parentid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date( 'Y-m-d H:i:s' )
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribeforum',
'from_fieldname' => 'forumid',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribeforum',
'from_fieldname' => 'userid',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'threadid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'forumid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'replycount',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'replycount',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postuserid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postusername',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postuserid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'post' table because 'thread' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'ipaddress',
'join_tablename' => 'thread',
'join_type' => 'INNER',
'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'forumid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic content.
// Note: We join the 'post' table because 'thread' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'pagetext',
'join_tablename' => 'thread',
'join_type' => 'INNER',
'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'open',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'lastpost',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'tagcontent',
'from_fieldname' => 'contentid',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'tagcontent',
'from_fieldname' => 'tagid',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tagtext',
'join_tablename' => 'tagcontent',
'join_type' => 'INNER',
'join_expression' => 'USING (tagid)',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tagtext',
'join_tablename' => 'tagcontent',
'join_type' => 'INNER',
'join_expression' => 'USING (tagid)',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribethread',
'from_fieldname' => 'threadid',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribethread',
'from_fieldname' => 'userid',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'postid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'from_expression' => 'WHERE parentid != 0',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'ipaddress',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'username',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'pagetext',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'userid',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => '_bbp_salt'
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'vBulletin'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'homepage',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'joindate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin_user_yim'
);
// User ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin_user_icq'
);
// User MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin_user_msn'
);
// User Skype (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'skype',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin_user_skype'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ) . $pass_array['salt'] ) );
}
/**
* Translate the forum type from vBulletin v4.x numerics to WordPress's strings.
*
* @param int $status vBulletin v4.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == -1 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the topic sticky status type from vBulletin v4.x numerics to WordPress's strings.
*
* @param int $status vBulletin v4.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 2 :
$status = 'super-sticky'; // vBulletin Super Sticky 'sticky = 2'
break;
case 1 :
$status = 'sticky'; // vBulletin Sticky 'sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // vBulletin Normal Topic 'sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count vBulletin v4.x reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* Translate the post status from vBulletin numerics to WordPress's strings.
*
* @param int $status vBulletin v4.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* This callback processes any custom parser.php attributes and custom code with preg_replace
*/
protected function callback_html( $field ) {
// Strips vBulletin custom HTML first from $field before parsing $field to parser.php
$vbulletin_markup = $field;
$vbulletin_markup = html_entity_decode( $vbulletin_markup );
// Replace '[QUOTE]' with '<blockquote>'
$vbulletin_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $vbulletin_markup );
// Replace '[QUOTE=User Name($1);PostID($2)]' with '<em>@$1 $2 wrote:</em><blockquote>"
$vbulletin_markup = preg_replace( '/\[QUOTE=(.*?);(.*?)\]/', '<em>@$1 $2 wrote:</em><blockquote>', $vbulletin_markup );
// Replace '[/QUOTE]' with '</blockquote>'
$vbulletin_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $vbulletin_markup );
// Replace '[MENTION=###($1)]User Name($2)[/MENTION]' with '@$2"
$vbulletin_markup = preg_replace( '/\[MENTION=(.*?)\](.*?)\[\/MENTION\]/', '@$2', $vbulletin_markup );
// Replace '[video=youtube;$1]$2[/video]' with '$2"
$vbulletin_markup = preg_replace( '/\[video\=youtube;(.*?)\](.*?)\[\/video\]/', '$2', $vbulletin_markup );
// Replace '[video=youtube_share;$1]$2[/video]' with '$2"
$vbulletin_markup = preg_replace( '/\[video\=youtube_share;(.*?)\](.*?)\[\/video\]/', '$2', $vbulletin_markup );
// Now that vBulletin custom HTML has been stripped put the cleaned HTML back in $field
$field = $vbulletin_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,754 @@
<?php
/**
* bbPress vBulletin 3.x Converter
*
* @package bbPress
* @subpackage Converters
*/
/**
* Implementation of vBulletin v3.x Converter.
*
* @since 2.5.0 bbPress (r5151)
*
* @link Codex Docs https://codex.bbpress.org/import-forums/vbulletin
*/
class vBulletin3 extends BBP_Converter_Base {
/**
* Main constructor
*
*/
public function __construct() {
parent::__construct();
}
/**
* Sets up the field mappings
*/
public function setup_globals() {
// Setup smiley URL & path
$this->bbcode_parser_properties = array(
'smiley_url' => false,
'smiley_dir' => false
);
/** Forum Section *****************************************************/
// Old forum id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'forumid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_id'
);
// Forum parent id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'parentid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_old_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'threadcount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'replycount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum total topic count (Includes unpublished topics, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'threadcount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_topic_count'
);
// Forum total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'replycount',
'to_type' => 'forum',
'to_fieldname' => '_bbp_total_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'title',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid confilcts)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'title_clean',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum display order (Starts from 1)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'displayorder',
'to_type' => 'forum',
'to_fieldname' => 'menu_order'
);
// Forum type (Category = -1 or Forum > 0, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum',
'from_fieldname' => 'parentid',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_type',
'callback_method' => 'callback_forum_type'
);
// Forum status (Set a default value 'open', Stored in postmeta)
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => '_bbp_status',
'default' => 'open'
);
// Forum dates.
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_date_gmt',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified',
'default' => date( 'Y-m-d H:i:s' )
);
$this->field_map[] = array(
'to_type' => 'forum',
'to_fieldname' => 'post_modified_gmt',
'default' => date( 'Y-m-d H:i:s' )
);
/** Forum Subscriptions Section ***************************************/
// Subscribed forum ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribeforum',
'from_fieldname' => 'forumid',
'to_type' => 'forum_subscriptions',
'to_fieldname' => '_bbp_forum_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribeforum',
'from_fieldname' => 'userid',
'to_type' => 'forum_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Topic Section *****************************************************/
// Old topic id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'threadid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_id'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'forumid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'replycount',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'replycount',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postuserid',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postusername',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_topic_author_name_id'
);
// Is the topic anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'postuserid',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_is_topic_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Topic Author ip (Stored in postmeta)
// Note: We join the 'post' table because 'thread' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'ipaddress',
'join_tablename' => 'thread',
'join_type' => 'INNER',
'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
'to_type' => 'topic',
'to_fieldname' => '_bbp_author_ip'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'forumid',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic content.
// Note: We join the 'post' table because 'thread' table does not include topic content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'pagetext',
'join_tablename' => 'thread',
'join_type' => 'INNER',
'join_expression' => 'USING (threadid) WHERE post.parentid = 0',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic status (Open or Closed)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'open',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_closed_status_id',
'callback_method' => 'callback_topic_status'
);
// Sticky status (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'sticky',
'to_type' => 'topic',
'to_fieldname' => '_bbp_old_sticky_status_id',
'callback_method' => 'callback_sticky_status'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'dateline',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'thread',
'from_fieldname' => 'lastpost',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
/** Tags Section ******************************************************/
// Topic id.
$this->field_map[] = array(
'from_tablename' => 'tagthread',
'from_fieldname' => 'threadid',
'to_type' => 'tags',
'to_fieldname' => 'objectid',
'callback_method' => 'callback_topicid'
);
// Taxonomy ID.
$this->field_map[] = array(
'from_tablename' => 'tagthread',
'from_fieldname' => 'tagid',
'to_type' => 'tags',
'to_fieldname' => 'taxonomy'
);
// Term text.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tagtext',
'join_tablename' => 'tagthread',
'join_type' => 'INNER',
'join_expression' => 'USING (tagid)',
'to_type' => 'tags',
'to_fieldname' => 'name'
);
// Term slug.
$this->field_map[] = array(
'from_tablename' => 'tag',
'from_fieldname' => 'tagtext',
'join_tablename' => 'tagthread',
'join_type' => 'INNER',
'join_expression' => 'USING (tagid)',
'to_type' => 'tags',
'to_fieldname' => 'slug',
'callback_method' => 'callback_slug'
);
/** Topic Subscriptions Section ***************************************/
// Subscribed topic ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribethread',
'from_fieldname' => 'threadid',
'to_type' => 'topic_subscriptions',
'to_fieldname' => '_bbp_subscriptions'
);
// Subscribed user ID (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'subscribethread',
'from_fieldname' => 'userid',
'to_type' => 'topic_subscriptions',
'to_fieldname' => 'user_id',
'callback_method' => 'callback_userid'
);
/** Reply Section *****************************************************/
// Old reply id (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'postid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_id'
);
// Reply parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'from_expression' => 'WHERE parentid != 0',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'ipaddress',
'to_type' => 'reply',
'to_fieldname' => '_bbp_author_ip'
);
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply author name (Stored in postmeta as _bbp_anonymous_name)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'username',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_reply_author_name_id'
);
// Is the reply anonymous (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'userid',
'to_type' => 'reply',
'to_fieldname' => '_bbp_old_is_reply_anonymous_id',
'callback_method' => 'callback_check_anonymous'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'pagetext',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'threadid',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'post',
'from_fieldname' => 'dateline',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
/** User Section ******************************************************/
// Store old user id (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'userid',
'to_type' => 'user',
'to_fieldname' => '_bbp_old_user_id'
);
// Store old user password (Stored in usermeta serialized with salt)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'password',
'to_type' => 'user',
'to_fieldname' => '_bbp_password',
'callback_method' => 'callback_savepass'
);
// Store old user salt (This is only used for the SELECT row info for the above password save)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'salt',
'to_type' => 'user',
'to_fieldname' => ''
);
// User password verify class (Stored in usermeta for verifying password)
$this->field_map[] = array(
'to_type' => 'user',
'to_fieldname' => '_bbp_class',
'default' => 'vBulletin3'
);
// User name.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'username',
'to_type' => 'user',
'to_fieldname' => 'user_login'
);
// User email.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'email',
'to_type' => 'user',
'to_fieldname' => 'user_email'
);
// User homepage.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'homepage',
'to_type' => 'user',
'to_fieldname' => 'user_url'
);
// User registered.
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'joindate',
'to_type' => 'user',
'to_fieldname' => 'user_registered',
'callback_method' => 'callback_datetime'
);
// User AIM (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'aim',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin3_user_aim'
);
// User Yahoo (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'yahoo',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin3_user_yim'
);
// User ICQ (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'icq',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin3_user_icq'
);
// User MSN (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'msn',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin3_user_msn'
);
// User Skype (Stored in usermeta)
$this->field_map[] = array(
'from_tablename' => 'user',
'from_fieldname' => 'skype',
'to_type' => 'user',
'to_fieldname' => '_bbp_vbulletin3_user_skype'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass( $field, $row ) {
$pass_array = array( 'hash' => $field, 'salt' => $row['salt'] );
return $pass_array;
}
/**
* This method is to take the pass out of the database and compare
* to a pass the user has typed in.
*
* vBulletin passwords do not work. Maybe use the below plugin's approach?
*
* @link https://wordpress.org/extend/plugins/vb-user-copy/
* @link https://plugins.trac.wordpress.org/browser/vb-user-copy/trunk/vb_user_copy.php
*/
public function authenticate_pass( $password, $serialized_pass ) {
$pass_array = unserialize( $serialized_pass );
return ( $pass_array['hash'] == md5( md5( $password ) . $pass_array['salt'] ) );
}
/**
* Translate the forum type from vBulletin v3.x numerics to WordPress's strings.
*
* @param int $status vBulletin v3.x numeric forum type
* @return string WordPress safe
*/
public function callback_forum_type( $status = 0 ) {
if ( $status == -1 ) {
$status = 'category';
} else {
$status = 'forum';
}
return $status;
}
/**
* Translate the topic sticky status type from vBulletin v3.x numerics to WordPress's strings.
*
* @param int $status vBulletin v3.x numeric forum type
* @return string WordPress safe
*/
public function callback_sticky_status( $status = 0 ) {
switch ( $status ) {
case 1 :
$status = 'sticky'; // vBulletin Sticky 'topic_sticky = 1'
break;
case 0 :
default :
$status = 'normal'; // vBulletin Normal Topic 'topic_sticky = 0'
break;
}
return $status;
}
/**
* Verify the topic reply count.
*
* @param int $count vBulletin v3.x reply count
* @return string WordPress safe
*/
public function callback_topic_reply_count( $count = 1 ) {
$count = absint( (int) $count - 1 );
return $count;
}
/**
* Translate the post status from vBulletin v3.x numerics to WordPress's strings.
*
* @param int $status vBulletin v3.x numeric topic status
* @return string WordPress safe
*/
public function callback_topic_status( $status = 1 ) {
switch ( $status ) {
case 0 :
$status = 'closed';
break;
case 1 :
default :
$status = 'publish';
break;
}
return $status;
}
/**
* This callback processes any custom parser.php attributes and custom code with preg_replace
*/
protected function callback_html( $field ) {
// Strips vBulletin custom HTML first from $field before parsing $field to parser.php
$vbulletin_markup = $field;
$vbulletin_markup = html_entity_decode( $vbulletin_markup );
// Replace '[QUOTE]' with '<blockquote>'
$vbulletin_markup = preg_replace( '/\[QUOTE\]/', '<blockquote>', $vbulletin_markup );
// Replace '[QUOTE=User Name($1);PostID($2)]' with '<em>@$1 $2 wrote:</em><blockquote>"
$vbulletin_markup = preg_replace( '/\[QUOTE=(.*?);(.*?)\]/' , '<em>@$1 $2 wrote:</em><blockquote>', $vbulletin_markup );
// Replace '[/QUOTE]' with '</blockquote>'
$vbulletin_markup = preg_replace( '/\[\/QUOTE\]/', '</blockquote>', $vbulletin_markup );
// Replace '[MENTION=###($1)]User Name($2)[/MENTION]' with '@$2"
$vbulletin_markup = preg_replace( '/\[MENTION=(.*?)\](.*?)\[\/MENTION\]/', '@$2', $vbulletin_markup );
// Replace '[video=youtube;$1]$2[/video]' with '$2"
$vbulletin_markup = preg_replace( '/\[video\=youtube;(.*?)\](.*?)\[\/video\]/', '$2', $vbulletin_markup );
// Now that vBulletin custom HTML has been stripped put the cleaned HTML back in $field
$field = $vbulletin_markup;
// Parse out any bbCodes in $field with the BBCode 'parser.php'
return parent::callback_html( $field );
}
}

View File

@@ -0,0 +1,794 @@
<?php
/**
* bbPress Forum Admin Class
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Forums_Admin' ) ) :
/**
* Loads bbPress forums admin area
*
* @package bbPress
* @subpackage Administration
* @since 2.0.0 bbPress (r2464)
*/
class BBP_Forums_Admin {
/** Variables *************************************************************/
/**
* @var string The post type of this admin component
*/
private $post_type = '';
/** Functions *************************************************************/
/**
* The main bbPress forums admin loader
*
* @since 2.0.0 bbPress (r2515)
*/
public function __construct() {
$this->setup_globals();
$this->setup_actions();
}
/**
* Setup the admin hooks, actions and filters
*
* @since 2.0.0 bbPress (r2646)
*
* @access private
*/
private function setup_actions() {
// Messages
add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
// Forum Column headers.
add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
// Forum Columns (in page row)
add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
// Metabox actions
add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
add_action( 'add_meta_boxes', array( $this, 'moderators_metabox' ) );
add_action( 'add_meta_boxes', array( $this, 'subscriptions_metabox' ) );
add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) );
add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
// Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed
add_action( 'load-edit.php', array( $this, 'toggle_forum' ) );
add_action( 'load-edit.php', array( $this, 'toggle_forum_notice' ) );
// Contextual Help
add_action( 'load-edit.php', array( $this, 'edit_help' ) );
add_action( 'load-post.php', array( $this, 'new_help' ) );
add_action( 'load-post-new.php', array( $this, 'new_help' ) );
}
/**
* Admin globals
*
* @since 2.0.0 bbPress (r2646)
*
* @access private
*/
private function setup_globals() {
$this->post_type = bbp_get_forum_post_type();
}
/** Contextual Help *******************************************************/
/**
* Contextual help for bbPress forum edit page
*
* @since 2.0.0 bbPress (r3119)
*/
public function edit_help() {
// Overview
get_current_screen()->add_help_tab( array(
'id' => 'overview',
'title' => __( 'Overview', 'bbpress' ),
'content' =>
'<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
) );
// Screen Content
get_current_screen()->add_help_tab( array(
'id' => 'screen-content',
'title' => __( 'Screen Content', 'bbpress' ),
'content' =>
'<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
'<ul>' .
'<li>' . __( 'You can hide/display columns based on your needs and decide how many forums to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
'<li>' . __( 'You can filter the list of forums by forum status using the text links in the upper left to show All, Published, or Trashed forums. The default view is to show all forums.', 'bbpress' ) . '</li>' .
'<li>' . __( 'You can refine the list to show only forums from a specific month by using the dropdown menus above the forums list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the forums list.', 'bbpress' ) . '</li>' .
'</ul>'
) );
// Available Actions
get_current_screen()->add_help_tab( array(
'id' => 'action-links',
'title' => __( 'Available Actions', 'bbpress' ),
'content' =>
'<p>' . __( 'Hovering over a row in the forums list will display action links that allow you to manage your forum. You can perform the following actions:', 'bbpress' ) . '</p>' .
'<ul>' .
'<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Close</strong> will mark the selected forum as &#8217;closed&#8217; and disable the ability to post new topics and replies in it.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Trash</strong> removes your forum from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>View</strong> will either show you what your draft forum will look like if you publish it, or take you to your live site to view it. Which link depends on your forum&#8217;s status.', 'bbpress' ) . '</li>' .
'</ul>'
) );
// Bulk Actions
get_current_screen()->add_help_tab( array(
'id' => 'bulk-actions',
'title' => __( 'Bulk Actions', 'bbpress' ),
'content' =>
'<p>' . __( 'You can also edit or move multiple forums to the trash at once. Select the forums you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'bbpress' ) . '</p>' .
'<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected forums at once. To remove a forum from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>'
) );
// Help Sidebar
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Contextual help for bbPress forum edit page
*
* @since 2.0.0 bbPress (r3119)
*/
public function new_help() {
$customize_display = '<p>' . __( 'The title field and the big forum editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>';
get_current_screen()->add_help_tab( array(
'id' => 'customize-display',
'title' => __( 'Customizing This Display', 'bbpress' ),
'content' => $customize_display,
) );
get_current_screen()->add_help_tab( array(
'id' => 'title-forum-editor',
'title' => __( 'Title and Forum Editor', 'bbpress' ),
'content' =>
'<p>' . __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
'<p>' . __( '<strong>Forum Editor</strong> - Enter the text for your forum. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the forum editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular forum editor.', 'bbpress' ) . '</p>'
) );
$publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your forum in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a forum or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a forum to be published in the future or backdate a forum.', 'bbpress' ) . '</p>';
if ( current_theme_supports( 'forum-thumbnails' ) && post_type_supports( 'forum', 'thumbnail' ) ) {
$publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your forum without inserting it. This is usually useful only if your theme makes use of the featured image as a forum thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
}
get_current_screen()->add_help_tab( array(
'id' => 'forum-attributes',
'title' => __( 'Forum Attributes', 'bbpress' ),
'content' =>
'<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' .
'<ul>' .
'<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Parent</strong> dropdown determines the parent forum. Select the forum or category from the dropdown, or leave the default "No parent" to create the forum at the root of your forums.', 'bbpress' ) . '</li>' .
'<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' .
'</ul>'
) );
get_current_screen()->add_help_tab( array(
'id' => 'publish-box',
'title' => __( 'Publish Box', 'bbpress' ),
'content' => $publish_box,
) );
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Add the forum attributes meta-box
*
* @since 2.0.0 bbPress (r2746)
*/
public function attributes_metabox() {
add_meta_box(
'bbp_forum_attributes',
esc_html__( 'Forum Attributes', 'bbpress' ),
'bbp_forum_metabox',
$this->post_type,
'side',
'high'
);
}
/**
* Add the forum moderators meta-box
*
* @since 2.6.0 bbPress
*/
public function moderators_metabox() {
// Bail if feature not active or user cannot assign moderators
if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) {
return;
}
// Moderators
add_meta_box(
'bbp_moderator_assignment_metabox',
esc_html__( 'Forum Moderators', 'bbpress' ),
'bbp_moderator_assignment_metabox',
$this->post_type,
'side',
'high'
);
}
/**
* Add the subscriptions meta-box
*
* Allows viewing of users who have subscribed to a forum.
*
* @since 2.6.0 bbPress (r6197)
*/
public function subscriptions_metabox() {
// Bail if post_type is not a reply
if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
return;
}
// Bail if no subscriptions
if ( ! bbp_is_subscriptions_active() ) {
return;
}
// Add the meta-box
add_meta_box(
'bbp_forum_subscriptions_metabox',
esc_html__( 'Subscriptions', 'bbpress' ),
'bbp_forum_subscriptions_metabox',
$this->post_type,
'normal',
'high'
);
}
/**
* Remove comments & discussion meta-boxes if comments are not supported
*
* @since 2.6.0 bbPress (r6186)
*/
public function comments_metabox() {
if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
remove_meta_box( 'commentsdiv', $this->post_type, 'normal' );
}
}
/**
* Pass the forum attributes for processing
*
* @since 2.0.0 bbPress (r2746)
*
* @param int $forum_id Forum id
* @return int Forum id
*/
public function save_meta_boxes( $forum_id ) {
// Bail if doing an autosave
if ( bbp_doing_autosave() ) {
return $forum_id;
}
// Bail if not a post request
if ( ! bbp_is_post_request() ) {
return $forum_id;
}
// Nonce check
if ( empty( $_POST['bbp_forum_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) {
return $forum_id;
}
// Only save for forum post-types
if ( ! bbp_is_forum( $forum_id ) ) {
return $forum_id;
}
// Bail if current user cannot edit this forum
if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
return $forum_id;
}
// Parent ID
$parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) )
? (int) $_POST['parent_id']
: 0;
// Update the forum meta bidness
bbp_update_forum( array(
'forum_id' => $forum_id,
'post_parent' => $parent_id
) );
do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
return $forum_id;
}
/**
* Toggle forum
*
* Handles the admin-side opening/closing of forums
*
* @since 2.6.0 bbPress (r5254)
*/
public function toggle_forum() {
// Bail if not a forum toggle action
if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['forum_id'] ) ) {
return;
}
// Bail if not an allowed action
$action = sanitize_key( $_GET['action'] );
if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
return;
}
// Bail if forum is missing
$forum_id = bbp_get_forum_id( $_GET['forum_id'] );
if ( ! bbp_get_forum( $forum_id ) ) {
wp_die( esc_html__( 'The forum was not found.', 'bbpress' ) );
}
// What is the user doing here?
if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
}
// Defaults
$post_data = array( 'ID' => $forum_id );
$message = '';
$success = false;
switch ( $action ) {
case 'bbp_toggle_forum_close' :
check_admin_referer( 'close-forum_' . $forum_id );
$is_open = bbp_is_forum_open( $forum_id );
$message = ( true === $is_open )
? 'closed'
: 'opened';
$success = ( true === $is_open )
? bbp_close_forum( $forum_id )
: bbp_open_forum( $forum_id );
break;
}
// Setup the message
$retval = array(
'bbp_forum_toggle_notice' => $message,
'forum_id' => $forum_id
);
// Prepare for failure
if ( ( false === $success ) || is_wp_error( $success ) ) {
$retval['failed'] = '1';
}
// Filter all message args
$retval = apply_filters( 'bbp_toggle_forum_action_admin', $retval, $forum_id, $action );
// Do additional forum toggle actions (admin side)
do_action( 'bbp_toggle_forum_admin', $success, $post_data, $action, $retval );
// Redirect back to the forum
$redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'forum_id' ) ) );
bbp_redirect( $redirect );
}
/**
* Toggle forum notices
*
* Display the success/error notices from
* {@link BBP_Admin::toggle_forum()}
*
* @since 2.6.0 bbPress (r5254)
*/
public function toggle_forum_notice() {
// Bail if missing forum toggle action
if ( ! bbp_is_get_request() || empty( $_GET['forum_id'] ) || empty( $_GET['bbp_forum_toggle_notice'] ) ) {
return;
}
// Bail if not an allowed notice
$notice = sanitize_key( $_GET['bbp_forum_toggle_notice'] );
if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
return;
}
// Bail if no forum_id or notice
$forum_id = bbp_get_forum_id( $_GET['forum_id'] );
if ( empty( $forum_id ) ) {
return;
}
// Bail if forum is missing
if ( ! bbp_get_forum( $forum_id ) ) {
return;
}
// Use the title in the responses
$forum_title = bbp_get_forum_title( $forum_id );
$is_failure = ! empty( $_GET['failed'] );
$message = '';
switch ( $notice ) {
case 'opened' :
$message = ( $is_failure === true )
? sprintf( esc_html__( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title )
: sprintf( esc_html__( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title );
break;
case 'closed' :
$message = ( $is_failure === true )
? sprintf( esc_html__( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title )
: sprintf( esc_html__( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title );
break;
}
// Do additional forum toggle notice filters (admin side)
$message = apply_filters( 'bbp_toggle_forum_notice_admin', $message, $forum_id, $notice, $is_failure );
$class = ( $is_failure === true )
? 'error'
: 'updated';
// Add the notice
bbp_admin()->add_notice( $message, $class, true );
}
/**
* Returns an array of keys used to sort row actions
*
* @since 2.6.0 bbPress (r6771)
*
* @return array
*/
private function get_row_action_sort_order() {
// Filter & return
return (array) apply_filters( 'bbp_admin_forum_row_action_sort_order', array(
'edit',
'closed',
'trash',
'untrash',
'delete',
'view'
) );
}
/**
* Returns an array of notice toggles
*
* @since 2.6.0 bbPress (r6396)
*
* @return array
*/
private function get_allowed_notice_toggles() {
// Filter & return
return apply_filters( 'bbp_admin_forums_allowed_notice_toggles', array(
'opened',
'closed'
) );
}
/**
* Returns an array of notice toggles
*
* @since 2.6.0 bbPress (r6396)
*
* @return array
*/
private function get_allowed_action_toggles() {
// Filter & return
return apply_filters( 'bbp_admin_forums_allowed_action_toggles', array(
'bbp_toggle_forum_close'
) );
}
/**
* Manage the column headers for the forums page
*
* @since 2.0.0 bbPress (r2485)
*
* @param array $columns The columns
*
* @return array $columns bbPress forum columns
*/
public function column_headers( $columns ) {
// Set list table column headers
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => esc_html__( 'Forum', 'bbpress' ),
'bbp_forum_topic_count' => esc_html__( 'Topics', 'bbpress' ),
'bbp_forum_reply_count' => esc_html__( 'Replies', 'bbpress' ),
'bbp_forum_mods' => esc_html__( 'Moderators', 'bbpress' ),
'author' => esc_html__( 'Creator', 'bbpress' ),
'bbp_forum_created' => esc_html__( 'Created' , 'bbpress' ),
'bbp_forum_freshness' => esc_html__( 'Last Post', 'bbpress' )
);
// Remove forum mods column if not enabled
if ( ! bbp_allow_forum_mods() ) {
unset( $columns['bbp_forum_mods'] );
}
// Filter & return
return apply_filters( 'bbp_admin_forums_column_headers', $columns );
}
/**
* Print extra columns for the forums page
*
* @since 2.0.0 bbPress (r2485)
*
* @param string $column Column
* @param int $forum_id Forum id
*/
public function column_data( $column, $forum_id ) {
switch ( $column ) {
case 'bbp_forum_topic_count' :
bbp_forum_topic_count( $forum_id );
break;
case 'bbp_forum_reply_count' :
bbp_forum_reply_count( $forum_id );
break;
case 'bbp_forum_mods' :
bbp_moderator_list( $forum_id, array(
'before' => '',
'after' => '',
'none' => esc_html__( '&mdash;', 'bbpress' )
) );
break;
case 'bbp_forum_created':
printf( '%1$s <br /> %2$s',
get_the_date(),
esc_attr( get_the_time() )
);
break;
case 'bbp_forum_freshness' :
$last_active = bbp_get_forum_last_active_time( $forum_id, false );
if ( ! empty( $last_active ) ) {
echo esc_html( $last_active );
} else {
esc_html_e( 'No Topics', 'bbpress' );
}
break;
default:
do_action( 'bbp_admin_forums_column_data', $column, $forum_id );
break;
}
}
/**
* Forum Row actions
*
* Remove the quick-edit action link and display the description under
* the forum title and add the open/close links
*
* @since 2.0.0 bbPress (r2577)
*
* @param array $actions Actions
* @param object $forum Forum object
*
* @return array $actions Actions
*/
public function row_actions( $actions = array(), $forum = false ) {
// Disable quick edit (too much to do here)
unset( $actions['inline hide-if-no-js'] );
// Only show the actions if the user is capable of viewing them :)
if ( current_user_can( 'edit_forum', $forum->ID ) ) {
// Show the 'close' and 'open' link on published, private, hidden and closed posts only
if ( in_array( $forum->post_status, array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id() ), true ) ) {
$close_uri = wp_nonce_url( add_query_arg( array( 'forum_id' => $forum->ID, 'action' => 'bbp_toggle_forum_close' ), remove_query_arg( array( 'bbp_forum_toggle_notice', 'forum_id', 'failed', 'super' ) ) ), 'close-forum_' . $forum->ID );
if ( bbp_is_forum_open( $forum->ID ) ) {
$actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this forum', 'bbpress' ) . '">' . _x( 'Close', 'Close a Forum', 'bbpress' ) . '</a>';
} else {
$actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this forum', 'bbpress' ) . '">' . _x( 'Open', 'Open a Forum', 'bbpress' ) . '</a>';
}
}
}
// Only show content if user can read it and there is no password
if ( current_user_can( 'read_forum', $forum->ID ) && ! post_password_required( $forum ) ) {
// Get the forum description
$content = bbp_get_forum_content( $forum->ID );
// Only proceed if there is a description
if ( ! empty( $content ) ) {
echo '<div class="bbp-escaped-content">' . esc_html( wp_trim_excerpt( $content, $forum ) ) . '</div>';
}
}
// Sort & return
return $this->sort_row_actions( $actions );
}
/**
* Sort row actions by key
*
* @since 2.6.0
*
* @param array $actions
*
* @return array
*/
private function sort_row_actions( $actions = array() ) {
// Return value
$retval = array();
// Known row actions, in sort order
$known_actions = $this->get_row_action_sort_order();
// Sort known actions, and keep any unknown ones
foreach ( $known_actions as $key ) {
if ( isset( $actions[ $key ] ) ) {
$retval[ $key ] = $actions[ $key ];
unset( $actions[ $key ] );
}
}
// Combine & return
return $retval + $actions;
}
/**
* Custom user feedback messages for forum post type
*
* @since 2.0.0 bbPress (r3080)
*
* @global int $post_ID
*
* @param array $messages
*
* @return array
*/
public function updated_messages( $messages ) {
global $post_ID;
// URL for the current forum
$forum_url = bbp_get_forum_permalink( $post_ID );
// Current forum's post_date
$post_date = bbp_get_global_post_field( 'post_date', 'raw' );
// Messages array
$messages[ $this->post_type ] = array(
0 => '', // Left empty on purpose
// Updated
1 => sprintf(
'%1$s <a href="%2$s">%3$s</a>',
esc_html__( 'Forum updated.', 'bbpress' ),
$forum_url,
esc_html__( 'View forum', 'bbpress' )
),
// Custom field updated
2 => esc_html__( 'Custom field updated.', 'bbpress' ),
// Custom field deleted
3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
// Forum updated
4 => esc_html__( 'Forum updated.', 'bbpress' ),
// Restored from revision
// translators: %s: date and time of the revision
5 => isset( $_GET['revision'] )
? sprintf( esc_html__( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
: false,
// Forum created
6 => sprintf(
'%1$s <a href="%2$s">%3$s</a>',
esc_html__( 'Forum created.', 'bbpress' ),
$forum_url,
esc_html__( 'View forum', 'bbpress' )
),
// Forum saved
7 => esc_html__( 'Forum saved.', 'bbpress' ),
// Forum submitted
8 => sprintf(
'%1$s <a href="%2$s" target="_blank">%3$s</a>',
esc_html__( 'Forum submitted.', 'bbpress' ),
esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
esc_html__( 'Preview forum', 'bbpress' )
),
// Forum scheduled
9 => sprintf(
'%1$s <a target="_blank" href="%2$s">%3$s</a>',
sprintf(
esc_html__( 'Forum scheduled for: %s.', 'bbpress' ),
// translators: Publish box date format, see http://php.net/date
'<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
),
$forum_url,
__( 'Preview forum', 'bbpress' )
),
// Forum draft updated
10 => sprintf(
'%1$s <a href="%2$s" target="_blank">%3$s</a>',
esc_html__( 'Forum draft updated.', 'bbpress' ),
esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
esc_html__( 'Preview forum', 'bbpress' )
),
);
return $messages;
}
}
endif; // class_exists check
/**
* Setup bbPress Forums Admin
*
* This is currently here to make hooking and unhooking of the admin UI easy.
* It could use dependency injection in the future, but for now this is easier.
*
* @since 2.0.0 bbPress (r2596)
*
* @param WP_Screen $current_screen Current screen object
*/
function bbp_admin_forums( $current_screen ) {
// Bail if not a forum screen
if ( empty( $current_screen->post_type ) || ( bbp_get_forum_post_type() !== $current_screen->post_type ) ) {
return;
}
// Init the forums admin
bbp_admin()->forums = new BBP_Forums_Admin();
}

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

View File

@@ -0,0 +1,832 @@
<?php
/**
* bbPress Admin Metaboxes
*
* @package bbPress
* @subpackage Administration
*/
/** Dashboard *****************************************************************/
/**
* Filter the Dashboard "at a glance" items and append bbPress elements to it.
*
* @since 2.6.0 bbPress (r5268)
*
* @param array $elements
* @return array
*/
function bbp_filter_dashboard_glance_items( $elements = array() ) {
// Bail if user cannot spectate
if ( ! current_user_can( 'spectate' ) ) {
return $elements;
}
// Get the statistics
$r = bbp_get_statistics( array(
'count_pending_topics' => false,
'count_private_topics' => false,
'count_spammed_topics' => false,
'count_trashed_topics' => false,
'count_pending_replies' => false,
'count_private_replies' => false,
'count_spammed_replies' => false,
'count_trashed_replies' => false,
'count_empty_tags' => false
) );
// Users
if ( isset( $r['user_count'] ) ) {
$link = admin_url( 'users.php' );
$text = sprintf( _n( '%s User', '%s Users', $r['user_count_int'], 'bbpress' ), $r['user_count'] );
$elements[] = current_user_can( 'edit_users' )
? '<a href="' . esc_url( $link ) . '" class="bbp-glance-users">' . esc_html( $text ) . '</a>'
: esc_html( $text );
}
// Forums
if ( isset( $r['forum_count'] ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_forum_post_type() ), admin_url( 'edit.php' ) );
$text = sprintf( _n( '%s Forum', '%s Forums', $r['forum_count_int'], 'bbpress' ), $r['forum_count'] );
$elements[] = current_user_can( 'publish_forums' )
? '<a href="' . esc_url( $link ) . '" class="bbp-glance-forums">' . esc_html( $text ) . '</a>'
: esc_html( $text );
}
// Topics
if ( isset( $r['topic_count'] ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) );
$text = sprintf( _n( '%s Topic', '%s Topics', $r['topic_count_int'], 'bbpress' ), $r['topic_count'] );
$elements[] = current_user_can( 'publish_topics' )
? '<a href="' . esc_url( $link ) . '" class="bbp-glance-topics">' . esc_html( $text ) . '</a>'
: esc_html( $text );
}
// Replies
if ( isset( $r['reply_count'] ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) );
$text = sprintf( _n( '%s Reply', '%s Replies', $r['reply_count_int'], 'bbpress' ), $r['reply_count'] );
$elements[] = current_user_can( 'publish_replies' )
? '<a href="' . esc_url( $link ) . '" class="bbp-glance-replies">' . esc_html( $text ) . '</a>'
: esc_html( $text );
}
// Topic Tags
if ( bbp_allow_topic_tags() && isset( $r['topic_tag_count'] ) ) {
$link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit-tags.php' ) );
$text = sprintf( _n( '%s Topic Tag', '%s Topic Tags', $r['topic_tag_count_int'], 'bbpress' ), $r['topic_tag_count'] );
$elements[] = current_user_can( 'manage_topic_tags' )
? '<a href="' . esc_url( $link ) . '" class="bbp-glance-topic-tags">' . esc_html( $text ) . '</a>'
: esc_html( $text );
}
// Filter & return
return apply_filters( 'bbp_dashboard_at_a_glance', $elements, $r );
}
/**
* bbPress Dashboard Right Now Widget
*
* Adds a dashboard widget with forum statistics
*
* @since 2.0.0 bbPress (r2770)
*
* @deprecated 2.6.0 bbPress (r5268)
*/
function bbp_dashboard_widget_right_now() {
// Get the statistics
$r = bbp_get_statistics(); ?>
<div class="table table_content">
<p class="sub"><?php esc_html_e( 'Discussion', 'bbpress' ); ?></p>
<table>
<tr class="first">
<?php
$num = $r['forum_count'];
$text = _n( 'Forum', 'Forums', $r['forum_count_int'], 'bbpress' );
if ( current_user_can( 'publish_forums' ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_forum_post_type() ), admin_url( 'edit.php' ) );
$num = '<a href="' . esc_url( $link ) . '">' . $num . '</a>';
$text = '<a href="' . esc_url( $link ) . '">' . $text . '</a>';
}
?>
<td class="first b b-forums"><?php echo $num; ?></td>
<td class="t forums"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = $r['topic_count'];
$text = _n( 'Topic', 'Topics', $r['topic_count_int'], 'bbpress' );
if ( current_user_can( 'publish_topics' ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) );
$num = '<a href="' . esc_url( $link ) . '">' . $num . '</a>';
$text = '<a href="' . esc_url( $link ) . '">' . $text . '</a>';
}
?>
<td class="first b b-topics"><?php echo $num; ?></td>
<td class="t topics"><?php echo $text; ?></td>
</tr>
<tr>
<?php
$num = $r['reply_count'];
$text = _n( 'Reply', 'Replies', $r['reply_count_int'], 'bbpress' );
if ( current_user_can( 'publish_replies' ) ) {
$link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) );
$num = '<a href="' . esc_url( $link ) . '">' . $num . '</a>';
$text = '<a href="' . esc_url( $link ) . '">' . $text . '</a>';
}
?>
<td class="first b b-replies"><?php echo $num; ?></td>
<td class="t replies"><?php echo $text; ?></td>
</tr>
<?php if ( bbp_allow_topic_tags() ) : ?>
<tr>
<?php
$num = $r['topic_tag_count'];
$text = _n( 'Topic Tag', 'Topic Tags', $r['topic_tag_count_int'], 'bbpress' );
if ( current_user_can( 'manage_topic_tags' ) ) {
$link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit-tags.php' ) );
$num = '<a href="' . esc_url( $link ) . '">' . $num . '</a>';
$text = '<a href="' . esc_url( $link ) . '">' . $text . '</a>';
}
?>
<td class="first b b-topic_tags"><span class="total-count"><?php echo $num; ?></span></td>
<td class="t topic_tags"><?php echo $text; ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'bbp_dashboard_widget_right_now_content_table_end' ); ?>
</table>
</div>
<div class="table table_discussion">
<p class="sub"><?php esc_html_e( 'Users &amp; Moderation', 'bbpress' ); ?></p>
<table>
<tr class="first">
<?php
$num = $r['user_count'];
$text = _n( 'User', 'Users', $r['user_count_int'], 'bbpress' );
if ( current_user_can( 'edit_users' ) ) {
$link = admin_url( 'users.php' );
$num = '<a href="' . $link . '">' . $num . '</a>';
$text = '<a href="' . $link . '">' . $text . '</a>';
}
?>
<td class="b b-users"><span class="total-count"><?php echo $num; ?></span></td>
<td class="last t users"><?php echo $text; ?></td>
</tr>
<?php if ( isset( $r['topic_count_hidden'] ) ) : ?>
<tr>
<?php
$num = $r['topic_count_hidden'];
$text = _n( 'Hidden Topic', 'Hidden Topics', $r['topic_count_hidden_int'], 'bbpress' );
$link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) );
if ( '0' !== $num ) {
$link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
}
$num = '<a href="' . esc_url( $link ) . '" title="' . esc_attr( $r['hidden_topic_title'] ) . '">' . $num . '</a>';
$text = '<a class="waiting" href="' . esc_url( $link ) . '" title="' . esc_attr( $r['hidden_topic_title'] ) . '">' . $text . '</a>';
?>
<td class="b b-hidden-topics"><?php echo $num; ?></td>
<td class="last t hidden-replies"><?php echo $text; ?></td>
</tr>
<?php endif; ?>
<?php if ( isset( $r['reply_count_hidden'] ) ) : ?>
<tr>
<?php
$num = $r['reply_count_hidden'];
$text = _n( 'Hidden Reply', 'Hidden Replies', $r['reply_count_hidden_int'], 'bbpress' );
$link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) );
if ( '0' !== $num ) {
$link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
}
$num = '<a href="' . esc_url( $link ) . '" title="' . esc_attr( $r['hidden_reply_title'] ) . '">' . $num . '</a>';
$text = '<a class="waiting" href="' . esc_url( $link ) . '" title="' . esc_attr( $r['hidden_reply_title'] ) . '">' . $text . '</a>';
?>
<td class="b b-hidden-replies"><?php echo $num; ?></td>
<td class="last t hidden-replies"><?php echo $text; ?></td>
</tr>
<?php endif; ?>
<?php if ( bbp_allow_topic_tags() && isset( $r['empty_topic_tag_count'] ) ) : ?>
<tr>
<?php
$num = $r['empty_topic_tag_count'];
$text = _n( 'Empty Topic Tag', 'Empty Topic Tags', $r['empty_topic_tag_count_int'], 'bbpress' );
$link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit-tags.php' ) );
$num = '<a href="' . esc_url( $link ) . '">' . $num . '</a>';
$text = '<a class="waiting" href="' . esc_url( $link ) . '">' . $text . '</a>';
?>
<td class="b b-hidden-topic-tags"><?php echo $num; ?></td>
<td class="last t hidden-topic-tags"><?php echo $text; ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'bbp_dashboard_widget_right_now_discussion_table_end' ); ?>
</table>
</div>
<?php do_action( 'bbp_dashboard_widget_right_now_table_end' ); ?>
<div class="versions">
<span id="wp-version-message">
<?php printf( __( 'You are using <span class="b">bbPress %s</span>.', 'bbpress' ), bbp_get_version() ); ?>
</span>
</div>
<br class="clear" />
<?php
do_action( 'bbp_dashboard_widget_right_now_end' );
}
/** Forums ********************************************************************/
/**
* Forum meta-box
*
* The meta-box that holds all of the additional forum information
*
* @since 2.0.0 bbPress (r2744)
*/
function bbp_forum_metabox( $post ) {
// Post ID
$post_parent = bbp_get_global_post_field( 'post_parent', 'raw' );
$menu_order = bbp_get_global_post_field( 'menu_order', 'edit' );
/** Type ******************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_forum_type_select"><?php esc_html_e( 'Type:', 'bbpress' ) ?></label>
<?php bbp_form_forum_type_dropdown( array( 'forum_id' => $post->ID ) ); ?>
</p>
<?php
/** Status ****************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_forum_status_select"><?php esc_html_e( 'Status:', 'bbpress' ) ?></label>
<?php bbp_form_forum_status_dropdown( array( 'forum_id' => $post->ID ) ); ?>
</p>
<?php
/** Visibility ************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Visibility:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_forum_visibility_select"><?php esc_html_e( 'Visibility:', 'bbpress' ) ?></label>
<?php bbp_form_forum_visibility_dropdown( array( 'forum_id' => $post->ID ) ); ?>
</p>
<hr />
<?php
/** Parent ****************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Parent:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="parent_id"><?php esc_html_e( 'Forum Parent', 'bbpress' ); ?></label>
<?php bbp_dropdown( array(
'post_type' => bbp_get_forum_post_type(),
'selected' => $post_parent,
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC',
'walker' => '',
'exclude' => $post->ID,
// Output-related
'select_id' => 'parent_id',
'options_only' => false,
'show_none' => esc_html__( '&mdash; No parent &mdash;', 'bbpress' ),
'disable_categories' => false,
'disabled' => ''
) ); ?>
</p>
<p>
<strong class="label"><?php esc_html_e( 'Order:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="menu_order"><?php esc_html_e( 'Forum Order', 'bbpress' ); ?></label>
<input name="menu_order" type="number" step="1" size="4" id="menu_order" value="<?php echo esc_attr( $menu_order ); ?>" />
</p>
<input name="ping_status" type="hidden" id="ping_status" value="open" />
<?php
wp_nonce_field( 'bbp_forum_metabox_save', 'bbp_forum_metabox' );
do_action( 'bbp_forum_metabox', $post );
}
/** Topics ********************************************************************/
/**
* Topic meta-box
*
* The meta-box that holds all of the additional topic information
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_topic_metabox( $post ) {
/** Type ******************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Type:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_stick_topic"><?php esc_html_e( 'Topic Type', 'bbpress' ); ?></label>
<?php bbp_form_topic_type_dropdown( array( 'topic_id' => $post->ID ) ); ?>
</p>
<?php
/** Status ****************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $post->post_status ) ? 'draft' : $post->post_status ); ?>" />
<label class="screen-reader-text" for="bbp_open_close_topic"><?php esc_html_e( 'Select whether to open or close the topic.', 'bbpress' ); ?></label>
<?php bbp_form_topic_status_dropdown( array( 'select_id' => 'post_status', 'topic_id' => $post->ID ) ); ?>
</p>
<?php
/** Parent *****************************************************************/
?>
<hr />
<p>
<strong class="label"><?php esc_html_e( 'Forum:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="parent_id"><?php esc_html_e( 'Forum', 'bbpress' ); ?></label>
<?php bbp_dropdown( array(
'post_type' => bbp_get_forum_post_type(),
'selected' => bbp_get_topic_forum_id( $post->ID ),
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC',
'walker' => '',
'exclude' => '',
// Output-related
'select_id' => 'parent_id',
'options_only' => false,
'show_none' => esc_html__( '&mdash; No forum &mdash;', 'bbpress' ),
'disable_categories' => current_user_can( 'edit_forums' ),
'disabled' => ''
) ); ?>
</p>
<input name="ping_status" type="hidden" id="ping_status" value="open" />
<?php
wp_nonce_field( 'bbp_topic_metabox_save', 'bbp_topic_metabox' );
do_action( 'bbp_topic_metabox', $post );
}
/** Replies *******************************************************************/
/**
* Reply meta-box
*
* The meta-box that holds all of the additional reply information
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_reply_metabox( $post ) {
// Get some meta
$reply_topic_id = bbp_get_reply_topic_id( $post->ID );
$reply_forum_id = bbp_get_reply_forum_id( $post->ID );
$topic_forum_id = bbp_get_topic_forum_id( $reply_topic_id );
/** Status ****************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Status:', 'bbpress' ); ?></strong>
<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $post->post_status ) ? 'draft' : $post->post_status ); ?>" />
<label class="screen-reader-text" for="post_status"><?php esc_html_e( 'Select what status to give the reply.', 'bbpress' ); ?></label>
<?php bbp_form_reply_status_dropdown( array( 'select_id' => 'post_status', 'reply_id' => $post->ID ) ); ?>
</p>
<hr />
<?php
/** Forum *****************************************************************/
// Only allow individual manipulation of reply forum if there is a mismatch
if ( ( $reply_forum_id !== $topic_forum_id ) && ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate', $post->ID ) ) ) : ?>
<p>
<strong class="label"><?php esc_html_e( 'Forum:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_forum_id"><?php esc_html_e( 'Forum', 'bbpress' ); ?></label>
<?php bbp_dropdown( array(
'post_type' => bbp_get_forum_post_type(),
'selected' => $reply_forum_id,
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC',
'walker' => '',
'exclude' => '',
// Output-related
'select_id' => 'bbp_forum_id',
'options_only' => false,
'show_none' => esc_html__( '&mdash; No reply &mdash;', 'bbpress' ),
'disable_categories' => current_user_can( 'edit_forums' ),
'disabled' => ''
) ); ?>
</p>
<?php endif;
/** Topic *****************************************************************/
?>
<p>
<strong class="label"><?php esc_html_e( 'Topic:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="parent_id"><?php esc_html_e( 'Topic', 'bbpress' ); ?></label>
<input name="parent_id" id="bbp_topic_id" type="text" value="<?php echo esc_attr( $reply_topic_id ); ?>" data-ajax-url="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_suggest_topic' ), admin_url( 'admin-ajax.php', 'relative' ) ), 'bbp_suggest_topic_nonce' ) ); ?>" />
</p>
<?php
/** Reply To **************************************************************/
// Only show reply-to drop-down when editing an existing reply
if ( ! empty( $reply_topic_id ) ) : ?>
<p>
<strong class="label"><?php esc_html_e( 'Reply To:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_reply_to"><?php esc_html_e( 'Reply To', 'bbpress' ); ?></label>
<?php bbp_reply_to_dropdown( $post->ID ); ?>
</p>
<?php
endif;
?>
<input name="ping_status" type="hidden" id="ping_status" value="open" />
<?php
wp_nonce_field( 'bbp_reply_metabox_save', 'bbp_reply_metabox' );
do_action( 'bbp_reply_metabox', $post );
}
/**
* Output the topic replies meta-box
*
* @since 2.6.0 bbPress (r5886)
*
* @param object $topic
*
* @return void
*/
function bbp_topic_replies_metabox( $topic = false ) {
// Bail if no topic to load replies for
if ( empty( $topic ) ) {
return;
}
// Pull in the list table class
if ( ! class_exists( 'BBP_Topic_Replies_List_Table' ) ) {
require_once bbp_admin()->admin_dir . '/classes/class-bbp-topic-replies-list-table.php';
}
// Look for pagination value
$page = isset( $_REQUEST['page'] )
? (int) $_REQUEST['page']
: 0;
// Load up the list table
$replies_list_table = new BBP_Topic_Replies_List_Table();
$replies_list_table->prepare_items( $topic->ID ); ?>
<form id="bbp-topic-replies" method="get">
<input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
<?php $replies_list_table->display(); ?>
</form>
<?php
}
/** Users *********************************************************************/
/**
* Anonymous user information meta-box
*
* @since 2.0.0 bbPress (r2828)
*
* @param WP_Post $post The current post object
*/
function bbp_author_metabox( $post ) {
// Show extra bits if topic/reply is anonymous
if ( bbp_is_reply_anonymous( $post->ID ) || bbp_is_topic_anonymous( $post->ID ) ) : ?>
<p>
<strong class="label"><?php esc_html_e( 'Name:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_anonymous_name"><?php esc_html_e( 'Name', 'bbpress' ); ?></label>
<input type="text" id="bbp_anonymous_name" name="bbp_anonymous_name" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_name', true ) ); ?>" />
</p>
<p>
<strong class="label"><?php esc_html_e( 'Email:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_anonymous_email"><?php esc_html_e( 'Email', 'bbpress' ); ?></label>
<input type="text" id="bbp_anonymous_email" name="bbp_anonymous_email" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_email', true ) ); ?>" />
</p>
<p>
<strong class="label"><?php esc_html_e( 'Website:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_anonymous_website"><?php esc_html_e( 'Website', 'bbpress' ); ?></label>
<input type="text" id="bbp_anonymous_website" name="bbp_anonymous_website" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_anonymous_website', true ) ); ?>" />
</p>
<?php else : ?>
<p>
<strong class="label"><?php esc_html_e( 'ID:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_author_id"><?php esc_html_e( 'ID', 'bbpress' ); ?></label>
<input type="text" id="bbp_author_id" name="post_author_override" value="<?php echo esc_attr( bbp_get_global_post_field( 'post_author' ) ); ?>" data-ajax-url="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_suggest_user' ), admin_url( 'admin-ajax.php', 'relative' ) ), 'bbp_suggest_user_nonce' ) ); ?>" />
</p>
<?php endif; ?>
<p>
<strong class="label"><?php esc_html_e( 'IP:', 'bbpress' ); ?></strong>
<label class="screen-reader-text" for="bbp_author_ip_address"><?php esc_html_e( 'IP Address', 'bbpress' ); ?></label>
<input type="text" id="bbp_author_ip_address" name="bbp_author_ip_address" value="<?php echo esc_attr( get_post_meta( $post->ID, '_bbp_author_ip', true ) ); ?>" disabled="disabled" />
</p>
<?php
do_action( 'bbp_author_metabox', $post );
}
/**
* Moderator assignment meta-box
*
* @since 2.6.0 bbPress (r2828)
*/
function bbp_moderator_assignment_metabox( $post ) {
// Get nicenames
$user_ids = bbp_get_moderator_ids( $post->ID );
$user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
$moderators = ! empty( $user_nicenames )
? implode( ', ', array_map( 'esc_attr', $user_nicenames ) )
: ''; ?>
<label class="screen-reader-text" for="bbp_moderators"><?php esc_html_e( 'Moderators', 'bbpress' ); ?></label>
<input type="text" id="bbp_moderators" name="bbp_moderators" value="<?php echo esc_attr( $moderators ); ?>" />
<p class="howto"><?php esc_html_e( 'Separate user-names with commas', 'bbpress' ); ?></p>
<?php
do_action( 'bbp_moderator_assignment_metabox', $post );
}
/**
* See who engaged with a topic
*
* @since 2.6.0 bbPress (r6333)
*/
function bbp_topic_engagements_metabox( $post ) {
// Get user IDs
$user_ids = bbp_get_topic_engagements( $post->ID );
// Output
?><p><?php
// Relationships
$args = array(
'include' => $user_ids
);
// Users were found
if ( ! empty( $user_ids ) && bbp_has_users( $args ) ) :
bbp_metabox_user_links();
// No users
else :
esc_html_e( 'No users have engaged to this topic.', 'bbpress' );
endif;
?></p><?php
do_action( 'bbp_topic_engagements_metabox', $post );
}
/**
* See who marked a topic as a favorite
*
* @since 2.6.0 bbPress (r6197)
* @since 2.6.0 bbPress (r6333) Updated to use BBP_User_Query
*/
function bbp_topic_favorites_metabox( $post ) {
// Get user IDs
$user_ids = bbp_get_topic_favoriters( $post->ID );
// Output
?><p><?php
// Relationships
$args = array(
'include' => $user_ids
);
// Users were found
if ( ! empty( $user_ids ) && bbp_has_users( $args ) ) :
bbp_metabox_user_links();
// No users
else :
esc_html_e( 'No users have favorited this topic.', 'bbpress' );
endif;
?></p><?php
do_action( 'bbp_favorites_metabox', $post );
}
/**
* See who is subscribed to a topic
*
* @since 2.6.0 bbPress (r6197)
* @since 2.6.0 bbPress (r6333) Updated to use BBP_User_Query
*/
function bbp_topic_subscriptions_metabox( $post ) {
// Current user subscription
$input_value = bbp_is_user_subscribed( bbp_get_current_user_id(), $post->ID )
? 'bbp_subscribe' // maintain existing subscription
: ''; // do not add or remove subscription
// Get user IDs
$user_ids = bbp_get_subscribers( $post->ID );
// Output
?>
<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="hidden" value="<?php echo esc_attr( $input_value ); ?>" />
<p><?php
// Relationships
$args = array(
'include' => $user_ids
);
// Users were found
if ( ! empty( $user_ids ) && bbp_has_users( $args ) ) :
bbp_metabox_user_links();
// No users
else :
esc_html_e( 'No users have subscribed to this topic.', 'bbpress' );
endif;
?></p><?php
do_action( 'bbp_subscriptions_metabox', $post );
}
/**
* See who is subscribed to a forum
*
* @since 2.6.0 bbPress (r6197)
* @since 2.6.0 bbPress (r6333) Updated to use BBP_User_Query
*/
function bbp_forum_subscriptions_metabox( $post ) {
// Get user IDs
$user_ids = bbp_get_subscribers( $post->ID );
// Output
?><p><?php
// Relationships
$args = array(
'include' => $user_ids
);
// Users were found
if ( ! empty( $user_ids ) && bbp_has_users( $args ) ) :
bbp_metabox_user_links();
// No users
else :
esc_html_e( 'No users have subscribed to this forum.', 'bbpress' );
endif;
?></p><?php
do_action( 'bbp_forum_subscriptions_metabox', $post );
}
/**
* Loop through queried metabox users, and output links to their avatars
*
* Developers Note: This function may change in a future release to include
* additional actions, so do not use this function in any third party plugin.
*
* @since 2.6.0 bbPress (r6913)
*/
function bbp_metabox_user_links() {
// Loop through users
while ( bbp_users() ) {
// Set the iterator
bbp_the_user();
// Get the user ID, URL, and Avatar
$user_id = bbp_get_user_id();
$user_url = bbp_get_user_profile_url( $user_id );
$user_avatar = get_avatar( $user_id, 32, '', '', array(
'force_display' => true
) );
// Output a link to the user avatar
echo '<a href="' . esc_url( $user_url ) . '">' . $user_avatar . '</a>';
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,499 @@
/*
* Button mixin- creates 3d-ish button effect with correct
* highlights/shadows, based on a base color.
*/
body {
background: #f1f1f1;
}
/* Links */
a {
color: #0073aa;
}
a:hover, a:active, a:focus {
color: #0096dd;
}
#media-upload a.del-link:hover,
div.dashboard-widget-submit input:hover,
.subsubsub a:hover,
.subsubsub a.current:hover {
color: #0096dd;
}
/* Forms */
input[type=checkbox]:checked:before {
color: #56b274;
}
input[type=radio]:checked:before {
background: #56b274;
}
.wp-core-ui input[type="reset"]:hover,
.wp-core-ui input[type="reset"]:active {
color: #0096dd;
}
/* Core UI */
.wp-core-ui .button-primary {
background: #56b274;
border-color: #43925d #3b8152 #3b8152;
color: #fff;
box-shadow: 0 1px 0 #3b8152;
text-shadow: 0 -1px 1px #3b8152, -1px 0 1px #3b8152, 0 1px 1px #3b8152, 1px 0 1px #3b8152;
}
.wp-core-ui .button-primary:hover, .wp-core-ui .button-primary:focus {
background: #61b77d;
border-color: #3b8152;
color: #fff;
box-shadow: 0 1px 0 #3b8152;
}
.wp-core-ui .button-primary:focus {
box-shadow: inset 0 1px 0 #43925d, 0 0 2px 1px #33b3db;
}
.wp-core-ui .button-primary:active, .wp-core-ui .button-primary.active, .wp-core-ui .button-primary.active:focus, .wp-core-ui .button-primary.active:hover {
background: #43925d;
border-color: #3b8152;
box-shadow: inset 0 2px 0 #3b8152;
}
.wp-core-ui .button-primary[disabled], .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary.button-primary-disabled, .wp-core-ui .button-primary.disabled {
color: #c7d1ca !important;
background: #469961 !important;
border-color: #3b8152 !important;
text-shadow: none !important;
}
.wp-core-ui .button-primary.button-hero {
box-shadow: 0 2px 0 #3b8152 !important;
}
.wp-core-ui .button-primary.button-hero:active {
box-shadow: inset 0 3px 0 #3b8152 !important;
}
.wp-core-ui .wp-ui-primary {
color: #fff;
background-color: #446950;
}
.wp-core-ui .wp-ui-text-primary {
color: #446950;
}
.wp-core-ui .wp-ui-highlight {
color: #fff;
background-color: #56b274;
}
.wp-core-ui .wp-ui-text-highlight {
color: #56b274;
}
.wp-core-ui .wp-ui-notification {
color: #fff;
background-color: #36b360;
}
.wp-core-ui .wp-ui-text-notification {
color: #36b360;
}
.wp-core-ui .wp-ui-text-icon {
color: #f1f3f2;
}
/* List tables */
.wrap .add-new-h2:hover,
.wrap .page-title-action:hover {
color: #fff;
background-color: #446950;
}
.view-switch a.current:before {
color: #446950;
}
.view-switch a:hover:before {
color: #36b360;
}
/* Admin Menu */
#adminmenuback,
#adminmenuwrap,
#adminmenu {
background: #446950;
}
#adminmenu a {
color: #fff;
}
#adminmenu div.wp-menu-image:before {
color: #f1f3f2;
}
#adminmenu a:hover,
#adminmenu li.menu-top:hover,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
color: #fff;
background-color: #56b274;
}
#adminmenu li.menu-top:hover div.wp-menu-image:before,
#adminmenu li.opensub > a.menu-top div.wp-menu-image:before {
color: #fff;
}
/* Active tabs use a bottom border color that matches the page background color. */
.about-wrap h2 .nav-tab-active,
.nav-tab-active,
.nav-tab-active:hover {
background-color: #f1f1f1;
border-bottom-color: #f1f1f1;
}
/* Admin Menu: submenu */
#adminmenu .wp-submenu,
#adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu,
.folded #adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu {
background: #36533f;
}
#adminmenu li.wp-has-submenu.wp-not-current-submenu.opensub:hover:after {
border-left-color: #36533f;
}
#adminmenu .wp-submenu .wp-submenu-head {
color: #c7d2cb;
}
#adminmenu .wp-submenu a,
#adminmenu .wp-has-current-submenu .wp-submenu a,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a {
color: #c7d2cb;
}
#adminmenu .wp-submenu a:focus, #adminmenu .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu .wp-submenu a:hover,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:focus,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:hover {
color: #56b274;
}
/* Admin Menu: current */
#adminmenu .wp-submenu li.current a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a {
color: #fff;
}
#adminmenu .wp-submenu li.current a:hover, #adminmenu .wp-submenu li.current a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:focus {
color: #56b274;
}
ul#adminmenu a.wp-has-current-submenu:after,
ul#adminmenu > li.current > a.current:after {
border-left-color: #f1f1f1;
}
#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.wp-has-current-submenu .wp-submenu .wp-submenu-head,
.folded #adminmenu li.current.menu-top {
color: #fff;
background: #56b274;
}
#adminmenu li.wp-has-current-submenu div.wp-menu-image:before,
#adminmenu a.current:hover div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu a:focus div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu.opensub div.wp-menu-image:before,
#adminmenu li:hover div.wp-menu-image:before,
#adminmenu li a:focus div.wp-menu-image:before,
#adminmenu li.opensub div.wp-menu-image:before,
.ie8 #adminmenu li.opensub div.wp-menu-image:before {
color: #fff;
}
/* Admin Menu: bubble */
#adminmenu .awaiting-mod,
#adminmenu .update-plugins {
color: #fff;
background: #36b360;
}
#adminmenu li.current a .awaiting-mod,
#adminmenu li a.wp-has-current-submenu .update-plugins,
#adminmenu li:hover a .awaiting-mod,
#adminmenu li.menu-top:hover > a .update-plugins {
color: #fff;
background: #36533f;
}
/* Admin Menu: collapse button */
#collapse-button {
color: #f1f3f2;
}
#collapse-button:hover,
#collapse-button:focus {
color: #56b274;
}
/* Admin Bar */
#wpadminbar {
color: #fff;
background: #446950;
}
#wpadminbar .ab-item,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon {
color: #fff;
}
#wpadminbar .ab-icon,
#wpadminbar .ab-icon:before,
#wpadminbar .ab-item:before,
#wpadminbar .ab-item:after {
color: #f1f3f2;
}
#wpadminbar:not(.mobile) .ab-top-menu > li:hover > .ab-item,
#wpadminbar:not(.mobile) .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojs .ab-top-menu > li.menupop:hover > .ab-item,
#wpadminbar .ab-top-menu > li.menupop.hover > .ab-item {
color: #56b274;
background: #36533f;
}
#wpadminbar:not(.mobile) > #wp-toolbar li:hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar li.hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar a:focus span.ab-label {
color: #56b274;
}
#wpadminbar:not(.mobile) li:hover .ab-icon:before,
#wpadminbar:not(.mobile) li:hover .ab-item:before,
#wpadminbar:not(.mobile) li:hover .ab-item:after,
#wpadminbar:not(.mobile) li:hover #adminbarsearch:before {
color: #fff;
}
/* Admin Bar: submenu */
#wpadminbar .menupop .ab-sub-wrapper {
background: #36533f;
}
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary,
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary .ab-submenu {
background: #597763;
}
#wpadminbar .ab-submenu .ab-item,
#wpadminbar .quicklinks .menupop ul li a,
#wpadminbar .quicklinks .menupop.hover ul li a,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a {
color: #c7d2cb;
}
#wpadminbar .quicklinks li .blavatar,
#wpadminbar .menupop .menupop > .ab-item:before {
color: #f1f3f2;
}
#wpadminbar .quicklinks .menupop ul li a:hover,
#wpadminbar .quicklinks .menupop ul li a:focus,
#wpadminbar .quicklinks .menupop ul li a:hover strong,
#wpadminbar .quicklinks .menupop ul li a:focus strong,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a,
#wpadminbar .quicklinks .menupop.hover ul li a:hover,
#wpadminbar .quicklinks .menupop.hover ul li a:focus,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:hover,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:focus,
#wpadminbar li:hover .ab-icon:before,
#wpadminbar li:hover .ab-item:before,
#wpadminbar li a:focus .ab-icon:before,
#wpadminbar li .ab-item:focus:before,
#wpadminbar li .ab-item:focus .ab-icon:before,
#wpadminbar li.hover .ab-icon:before,
#wpadminbar li.hover .ab-item:before,
#wpadminbar li:hover #adminbarsearch:before,
#wpadminbar li #adminbarsearch.adminbar-focused:before {
color: #56b274;
}
#wpadminbar .quicklinks li a:hover .blavatar,
#wpadminbar .quicklinks li a:focus .blavatar,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a .blavatar,
#wpadminbar .menupop .menupop > .ab-item:hover:before,
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: #56b274;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: #f1f3f2;
}
/* Admin Bar: search */
#wpadminbar #adminbarsearch:before {
color: #f1f3f2;
}
#wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus {
color: #fff;
background: #527f61;
}
/* Admin Bar: my account */
#wpadminbar .quicklinks li#wp-admin-bar-my-account.with-avatar > a img {
border-color: #527f61;
background-color: #527f61;
}
#wpadminbar #wp-admin-bar-user-info .display-name {
color: #fff;
}
#wpadminbar #wp-admin-bar-user-info a:hover .display-name {
color: #56b274;
}
#wpadminbar #wp-admin-bar-user-info .username {
color: #c7d2cb;
}
/* Pointers */
.wp-pointer .wp-pointer-content h3 {
background-color: #56b274;
border-color: #4ba468;
}
.wp-pointer .wp-pointer-content h3:before {
color: #56b274;
}
.wp-pointer.wp-pointer-top .wp-pointer-arrow,
.wp-pointer.wp-pointer-top .wp-pointer-arrow-inner,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow-inner {
border-bottom-color: #56b274;
}
/* Media */
.media-item .bar,
.media-progress-bar div {
background-color: #56b274;
}
.details.attachment {
box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #56b274;
}
.attachment.details .check {
background-color: #56b274;
box-shadow: 0 0 0 1px #fff, 0 0 0 2px #56b274;
}
.media-selection .attachment.selection.details .thumbnail {
box-shadow: 0 0 0 1px #fff, 0 0 0 3px #56b274;
}
/* Themes */
.theme-browser .theme.active .theme-name,
.theme-browser .theme.add-new-theme a:hover:after,
.theme-browser .theme.add-new-theme a:focus:after {
background: #56b274;
}
.theme-browser .theme.add-new-theme a:hover span:after,
.theme-browser .theme.add-new-theme a:focus span:after {
color: #56b274;
}
.theme-section.current,
.theme-filter.current {
border-bottom-color: #446950;
}
body.more-filters-opened .more-filters {
color: #fff;
background-color: #446950;
}
body.more-filters-opened .more-filters:before {
color: #fff;
}
body.more-filters-opened .more-filters:hover,
body.more-filters-opened .more-filters:focus {
background-color: #56b274;
color: #fff;
}
body.more-filters-opened .more-filters:hover:before,
body.more-filters-opened .more-filters:focus:before {
color: #fff;
}
/* Widgets */
.widgets-chooser li.widgets-chooser-selected {
background-color: #56b274;
color: #fff;
}
.widgets-chooser li.widgets-chooser-selected:before,
.widgets-chooser li.widgets-chooser-selected:focus:before {
color: #fff;
}
/* Responsive Component */
div#wp-responsive-toggle a:before {
color: #f1f3f2;
}
.wp-responsive-open div#wp-responsive-toggle a {
border-color: transparent;
background: #56b274;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle a {
background: #36533f;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle .ab-icon:before {
color: #f1f3f2;
}
/* TinyMCE */
.mce-container.mce-menu .mce-menu-item:hover,
.mce-container.mce-menu .mce-menu-item.mce-selected,
.mce-container.mce-menu .mce-menu-item:focus,
.mce-container.mce-menu .mce-menu-item-normal.mce-active,
.mce-container.mce-menu .mce-menu-item-preview.mce-active {
background: #56b274;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,499 @@
/*
* Button mixin- creates 3d-ish button effect with correct
* highlights/shadows, based on a base color.
*/
body {
background: #f1f1f1;
}
/* Links */
a {
color: #0073aa;
}
a:hover, a:active, a:focus {
color: #0096dd;
}
#media-upload a.del-link:hover,
div.dashboard-widget-submit input:hover,
.subsubsub a:hover,
.subsubsub a.current:hover {
color: #0096dd;
}
/* Forms */
input[type=checkbox]:checked:before {
color: #56b274;
}
input[type=radio]:checked:before {
background: #56b274;
}
.wp-core-ui input[type="reset"]:hover,
.wp-core-ui input[type="reset"]:active {
color: #0096dd;
}
/* Core UI */
.wp-core-ui .button-primary {
background: #56b274;
border-color: #43925d #3b8152 #3b8152;
color: #fff;
box-shadow: 0 1px 0 #3b8152;
text-shadow: 0 -1px 1px #3b8152, 1px 0 1px #3b8152, 0 1px 1px #3b8152, -1px 0 1px #3b8152;
}
.wp-core-ui .button-primary:hover, .wp-core-ui .button-primary:focus {
background: #61b77d;
border-color: #3b8152;
color: #fff;
box-shadow: 0 1px 0 #3b8152;
}
.wp-core-ui .button-primary:focus {
box-shadow: inset 0 1px 0 #43925d, 0 0 2px 1px #33b3db;
}
.wp-core-ui .button-primary:active, .wp-core-ui .button-primary.active, .wp-core-ui .button-primary.active:focus, .wp-core-ui .button-primary.active:hover {
background: #43925d;
border-color: #3b8152;
box-shadow: inset 0 2px 0 #3b8152;
}
.wp-core-ui .button-primary[disabled], .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary.button-primary-disabled, .wp-core-ui .button-primary.disabled {
color: #c7d1ca !important;
background: #469961 !important;
border-color: #3b8152 !important;
text-shadow: none !important;
}
.wp-core-ui .button-primary.button-hero {
box-shadow: 0 2px 0 #3b8152 !important;
}
.wp-core-ui .button-primary.button-hero:active {
box-shadow: inset 0 3px 0 #3b8152 !important;
}
.wp-core-ui .wp-ui-primary {
color: #fff;
background-color: #446950;
}
.wp-core-ui .wp-ui-text-primary {
color: #446950;
}
.wp-core-ui .wp-ui-highlight {
color: #fff;
background-color: #56b274;
}
.wp-core-ui .wp-ui-text-highlight {
color: #56b274;
}
.wp-core-ui .wp-ui-notification {
color: #fff;
background-color: #36b360;
}
.wp-core-ui .wp-ui-text-notification {
color: #36b360;
}
.wp-core-ui .wp-ui-text-icon {
color: #f1f3f2;
}
/* List tables */
.wrap .add-new-h2:hover,
.wrap .page-title-action:hover {
color: #fff;
background-color: #446950;
}
.view-switch a.current:before {
color: #446950;
}
.view-switch a:hover:before {
color: #36b360;
}
/* Admin Menu */
#adminmenuback,
#adminmenuwrap,
#adminmenu {
background: #446950;
}
#adminmenu a {
color: #fff;
}
#adminmenu div.wp-menu-image:before {
color: #f1f3f2;
}
#adminmenu a:hover,
#adminmenu li.menu-top:hover,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
color: #fff;
background-color: #56b274;
}
#adminmenu li.menu-top:hover div.wp-menu-image:before,
#adminmenu li.opensub > a.menu-top div.wp-menu-image:before {
color: #fff;
}
/* Active tabs use a bottom border color that matches the page background color. */
.about-wrap h2 .nav-tab-active,
.nav-tab-active,
.nav-tab-active:hover {
background-color: #f1f1f1;
border-bottom-color: #f1f1f1;
}
/* Admin Menu: submenu */
#adminmenu .wp-submenu,
#adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu,
.folded #adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu {
background: #36533f;
}
#adminmenu li.wp-has-submenu.wp-not-current-submenu.opensub:hover:after {
border-right-color: #36533f;
}
#adminmenu .wp-submenu .wp-submenu-head {
color: #c7d2cb;
}
#adminmenu .wp-submenu a,
#adminmenu .wp-has-current-submenu .wp-submenu a,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a {
color: #c7d2cb;
}
#adminmenu .wp-submenu a:focus, #adminmenu .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu .wp-submenu a:hover,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:focus,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:hover {
color: #56b274;
}
/* Admin Menu: current */
#adminmenu .wp-submenu li.current a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a {
color: #fff;
}
#adminmenu .wp-submenu li.current a:hover, #adminmenu .wp-submenu li.current a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:focus {
color: #56b274;
}
ul#adminmenu a.wp-has-current-submenu:after,
ul#adminmenu > li.current > a.current:after {
border-right-color: #f1f1f1;
}
#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.wp-has-current-submenu .wp-submenu .wp-submenu-head,
.folded #adminmenu li.current.menu-top {
color: #fff;
background: #56b274;
}
#adminmenu li.wp-has-current-submenu div.wp-menu-image:before,
#adminmenu a.current:hover div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu a:focus div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu.opensub div.wp-menu-image:before,
#adminmenu li:hover div.wp-menu-image:before,
#adminmenu li a:focus div.wp-menu-image:before,
#adminmenu li.opensub div.wp-menu-image:before,
.ie8 #adminmenu li.opensub div.wp-menu-image:before {
color: #fff;
}
/* Admin Menu: bubble */
#adminmenu .awaiting-mod,
#adminmenu .update-plugins {
color: #fff;
background: #36b360;
}
#adminmenu li.current a .awaiting-mod,
#adminmenu li a.wp-has-current-submenu .update-plugins,
#adminmenu li:hover a .awaiting-mod,
#adminmenu li.menu-top:hover > a .update-plugins {
color: #fff;
background: #36533f;
}
/* Admin Menu: collapse button */
#collapse-button {
color: #f1f3f2;
}
#collapse-button:hover,
#collapse-button:focus {
color: #56b274;
}
/* Admin Bar */
#wpadminbar {
color: #fff;
background: #446950;
}
#wpadminbar .ab-item,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon {
color: #fff;
}
#wpadminbar .ab-icon,
#wpadminbar .ab-icon:before,
#wpadminbar .ab-item:before,
#wpadminbar .ab-item:after {
color: #f1f3f2;
}
#wpadminbar:not(.mobile) .ab-top-menu > li:hover > .ab-item,
#wpadminbar:not(.mobile) .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojs .ab-top-menu > li.menupop:hover > .ab-item,
#wpadminbar .ab-top-menu > li.menupop.hover > .ab-item {
color: #56b274;
background: #36533f;
}
#wpadminbar:not(.mobile) > #wp-toolbar li:hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar li.hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar a:focus span.ab-label {
color: #56b274;
}
#wpadminbar:not(.mobile) li:hover .ab-icon:before,
#wpadminbar:not(.mobile) li:hover .ab-item:before,
#wpadminbar:not(.mobile) li:hover .ab-item:after,
#wpadminbar:not(.mobile) li:hover #adminbarsearch:before {
color: #fff;
}
/* Admin Bar: submenu */
#wpadminbar .menupop .ab-sub-wrapper {
background: #36533f;
}
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary,
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary .ab-submenu {
background: #597763;
}
#wpadminbar .ab-submenu .ab-item,
#wpadminbar .quicklinks .menupop ul li a,
#wpadminbar .quicklinks .menupop.hover ul li a,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a {
color: #c7d2cb;
}
#wpadminbar .quicklinks li .blavatar,
#wpadminbar .menupop .menupop > .ab-item:before {
color: #f1f3f2;
}
#wpadminbar .quicklinks .menupop ul li a:hover,
#wpadminbar .quicklinks .menupop ul li a:focus,
#wpadminbar .quicklinks .menupop ul li a:hover strong,
#wpadminbar .quicklinks .menupop ul li a:focus strong,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a,
#wpadminbar .quicklinks .menupop.hover ul li a:hover,
#wpadminbar .quicklinks .menupop.hover ul li a:focus,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:hover,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:focus,
#wpadminbar li:hover .ab-icon:before,
#wpadminbar li:hover .ab-item:before,
#wpadminbar li a:focus .ab-icon:before,
#wpadminbar li .ab-item:focus:before,
#wpadminbar li .ab-item:focus .ab-icon:before,
#wpadminbar li.hover .ab-icon:before,
#wpadminbar li.hover .ab-item:before,
#wpadminbar li:hover #adminbarsearch:before,
#wpadminbar li #adminbarsearch.adminbar-focused:before {
color: #56b274;
}
#wpadminbar .quicklinks li a:hover .blavatar,
#wpadminbar .quicklinks li a:focus .blavatar,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a .blavatar,
#wpadminbar .menupop .menupop > .ab-item:hover:before,
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: #56b274;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: #f1f3f2;
}
/* Admin Bar: search */
#wpadminbar #adminbarsearch:before {
color: #f1f3f2;
}
#wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus {
color: #fff;
background: #527f61;
}
/* Admin Bar: my account */
#wpadminbar .quicklinks li#wp-admin-bar-my-account.with-avatar > a img {
border-color: #527f61;
background-color: #527f61;
}
#wpadminbar #wp-admin-bar-user-info .display-name {
color: #fff;
}
#wpadminbar #wp-admin-bar-user-info a:hover .display-name {
color: #56b274;
}
#wpadminbar #wp-admin-bar-user-info .username {
color: #c7d2cb;
}
/* Pointers */
.wp-pointer .wp-pointer-content h3 {
background-color: #56b274;
border-color: #4ba468;
}
.wp-pointer .wp-pointer-content h3:before {
color: #56b274;
}
.wp-pointer.wp-pointer-top .wp-pointer-arrow,
.wp-pointer.wp-pointer-top .wp-pointer-arrow-inner,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow-inner {
border-bottom-color: #56b274;
}
/* Media */
.media-item .bar,
.media-progress-bar div {
background-color: #56b274;
}
.details.attachment {
box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #56b274;
}
.attachment.details .check {
background-color: #56b274;
box-shadow: 0 0 0 1px #fff, 0 0 0 2px #56b274;
}
.media-selection .attachment.selection.details .thumbnail {
box-shadow: 0 0 0 1px #fff, 0 0 0 3px #56b274;
}
/* Themes */
.theme-browser .theme.active .theme-name,
.theme-browser .theme.add-new-theme a:hover:after,
.theme-browser .theme.add-new-theme a:focus:after {
background: #56b274;
}
.theme-browser .theme.add-new-theme a:hover span:after,
.theme-browser .theme.add-new-theme a:focus span:after {
color: #56b274;
}
.theme-section.current,
.theme-filter.current {
border-bottom-color: #446950;
}
body.more-filters-opened .more-filters {
color: #fff;
background-color: #446950;
}
body.more-filters-opened .more-filters:before {
color: #fff;
}
body.more-filters-opened .more-filters:hover,
body.more-filters-opened .more-filters:focus {
background-color: #56b274;
color: #fff;
}
body.more-filters-opened .more-filters:hover:before,
body.more-filters-opened .more-filters:focus:before {
color: #fff;
}
/* Widgets */
.widgets-chooser li.widgets-chooser-selected {
background-color: #56b274;
color: #fff;
}
.widgets-chooser li.widgets-chooser-selected:before,
.widgets-chooser li.widgets-chooser-selected:focus:before {
color: #fff;
}
/* Responsive Component */
div#wp-responsive-toggle a:before {
color: #f1f3f2;
}
.wp-responsive-open div#wp-responsive-toggle a {
border-color: transparent;
background: #56b274;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle a {
background: #36533f;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle .ab-icon:before {
color: #f1f3f2;
}
/* TinyMCE */
.mce-container.mce-menu .mce-menu-item:hover,
.mce-container.mce-menu .mce-menu-item.mce-selected,
.mce-container.mce-menu .mce-menu-item:focus,
.mce-container.mce-menu .mce-menu-item-normal.mce-active,
.mce-container.mce-menu .mce-menu-item-preview.mce-active {
background: #56b274;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

View File

@@ -0,0 +1,499 @@
/*
* Button mixin- creates 3d-ish button effect with correct
* highlights/shadows, based on a base color.
*/
body {
background: #f1f1f1;
}
/* Links */
a {
color: #0073aa;
}
a:hover, a:active, a:focus {
color: #0096dd;
}
#media-upload a.del-link:hover,
div.dashboard-widget-submit input:hover,
.subsubsub a:hover,
.subsubsub a.current:hover {
color: #0096dd;
}
/* Forms */
input[type=checkbox]:checked:before {
color: #4f6d59;
}
input[type=radio]:checked:before {
background: #4f6d59;
}
.wp-core-ui input[type="reset"]:hover,
.wp-core-ui input[type="reset"]:active {
color: #0096dd;
}
/* Core UI */
.wp-core-ui .button-primary {
background: #4f6d59;
border-color: #3a4f41 #2f4035 #2f4035;
color: #fff;
box-shadow: 0 1px 0 #2f4035;
text-shadow: 0 -1px 1px #2f4035, -1px 0 1px #2f4035, 0 1px 1px #2f4035, 1px 0 1px #2f4035;
}
.wp-core-ui .button-primary:hover, .wp-core-ui .button-primary:focus {
background: #567560;
border-color: #2f4035;
color: #fff;
box-shadow: 0 1px 0 #2f4035;
}
.wp-core-ui .button-primary:focus {
box-shadow: inset 0 1px 0 #3a4f41, 0 0 2px 1px #33b3db;
}
.wp-core-ui .button-primary:active, .wp-core-ui .button-primary.active, .wp-core-ui .button-primary.active:focus, .wp-core-ui .button-primary.active:hover {
background: #3a4f41;
border-color: #2f4035;
box-shadow: inset 0 2px 0 #2f4035;
}
.wp-core-ui .button-primary[disabled], .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary.button-primary-disabled, .wp-core-ui .button-primary.disabled {
color: #c7d1ca !important;
background: #3e5546 !important;
border-color: #2f4035 !important;
text-shadow: none !important;
}
.wp-core-ui .button-primary.button-hero {
box-shadow: 0 2px 0 #2f4035 !important;
}
.wp-core-ui .button-primary.button-hero:active {
box-shadow: inset 0 3px 0 #2f4035 !important;
}
.wp-core-ui .wp-ui-primary {
color: #fff;
background-color: #5fb37c;
}
.wp-core-ui .wp-ui-text-primary {
color: #5fb37c;
}
.wp-core-ui .wp-ui-highlight {
color: #fff;
background-color: #4f6d59;
}
.wp-core-ui .wp-ui-text-highlight {
color: #4f6d59;
}
.wp-core-ui .wp-ui-notification {
color: #fff;
background-color: #33834e;
}
.wp-core-ui .wp-ui-text-notification {
color: #33834e;
}
.wp-core-ui .wp-ui-text-icon {
color: #f1f3f2;
}
/* List tables */
.wrap .add-new-h2:hover,
.wrap .page-title-action:hover {
color: #fff;
background-color: #5fb37c;
}
.view-switch a.current:before {
color: #5fb37c;
}
.view-switch a:hover:before {
color: #33834e;
}
/* Admin Menu */
#adminmenuback,
#adminmenuwrap,
#adminmenu {
background: #5fb37c;
}
#adminmenu a {
color: #fff;
}
#adminmenu div.wp-menu-image:before {
color: #f1f3f2;
}
#adminmenu a:hover,
#adminmenu li.menu-top:hover,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
color: #fff;
background-color: #4f6d59;
}
#adminmenu li.menu-top:hover div.wp-menu-image:before,
#adminmenu li.opensub > a.menu-top div.wp-menu-image:before {
color: #fff;
}
/* Active tabs use a bottom border color that matches the page background color. */
.about-wrap h2 .nav-tab-active,
.nav-tab-active,
.nav-tab-active:hover {
background-color: #f1f1f1;
border-bottom-color: #f1f1f1;
}
/* Admin Menu: submenu */
#adminmenu .wp-submenu,
#adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu,
.folded #adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu {
background: #4ca26a;
}
#adminmenu li.wp-has-submenu.wp-not-current-submenu.opensub:hover:after {
border-left-color: #4ca26a;
}
#adminmenu .wp-submenu .wp-submenu-head {
color: #cfe8d8;
}
#adminmenu .wp-submenu a,
#adminmenu .wp-has-current-submenu .wp-submenu a,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a {
color: #cfe8d8;
}
#adminmenu .wp-submenu a:focus, #adminmenu .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu .wp-submenu a:hover,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:focus,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:hover {
color: #4f6d59;
}
/* Admin Menu: current */
#adminmenu .wp-submenu li.current a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a {
color: #fff;
}
#adminmenu .wp-submenu li.current a:hover, #adminmenu .wp-submenu li.current a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:focus {
color: #4f6d59;
}
ul#adminmenu a.wp-has-current-submenu:after,
ul#adminmenu > li.current > a.current:after {
border-left-color: #f1f1f1;
}
#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.wp-has-current-submenu .wp-submenu .wp-submenu-head,
.folded #adminmenu li.current.menu-top {
color: #fff;
background: #4f6d59;
}
#adminmenu li.wp-has-current-submenu div.wp-menu-image:before,
#adminmenu a.current:hover div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu a:focus div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu.opensub div.wp-menu-image:before,
#adminmenu li:hover div.wp-menu-image:before,
#adminmenu li a:focus div.wp-menu-image:before,
#adminmenu li.opensub div.wp-menu-image:before,
.ie8 #adminmenu li.opensub div.wp-menu-image:before {
color: #fff;
}
/* Admin Menu: bubble */
#adminmenu .awaiting-mod,
#adminmenu .update-plugins {
color: #fff;
background: #33834e;
}
#adminmenu li.current a .awaiting-mod,
#adminmenu li a.wp-has-current-submenu .update-plugins,
#adminmenu li:hover a .awaiting-mod,
#adminmenu li.menu-top:hover > a .update-plugins {
color: #fff;
background: #4ca26a;
}
/* Admin Menu: collapse button */
#collapse-button {
color: #f1f3f2;
}
#collapse-button:hover,
#collapse-button:focus {
color: #4f6d59;
}
/* Admin Bar */
#wpadminbar {
color: #fff;
background: #5fb37c;
}
#wpadminbar .ab-item,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon {
color: #fff;
}
#wpadminbar .ab-icon,
#wpadminbar .ab-icon:before,
#wpadminbar .ab-item:before,
#wpadminbar .ab-item:after {
color: #f1f3f2;
}
#wpadminbar:not(.mobile) .ab-top-menu > li:hover > .ab-item,
#wpadminbar:not(.mobile) .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojs .ab-top-menu > li.menupop:hover > .ab-item,
#wpadminbar .ab-top-menu > li.menupop.hover > .ab-item {
color: #4f6d59;
background: #4ca26a;
}
#wpadminbar:not(.mobile) > #wp-toolbar li:hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar li.hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar a:focus span.ab-label {
color: #4f6d59;
}
#wpadminbar:not(.mobile) li:hover .ab-icon:before,
#wpadminbar:not(.mobile) li:hover .ab-item:before,
#wpadminbar:not(.mobile) li:hover .ab-item:after,
#wpadminbar:not(.mobile) li:hover #adminbarsearch:before {
color: #fff;
}
/* Admin Bar: submenu */
#wpadminbar .menupop .ab-sub-wrapper {
background: #4ca26a;
}
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary,
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary .ab-submenu {
background: #7eb892;
}
#wpadminbar .ab-submenu .ab-item,
#wpadminbar .quicklinks .menupop ul li a,
#wpadminbar .quicklinks .menupop.hover ul li a,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a {
color: #cfe8d8;
}
#wpadminbar .quicklinks li .blavatar,
#wpadminbar .menupop .menupop > .ab-item:before {
color: #f1f3f2;
}
#wpadminbar .quicklinks .menupop ul li a:hover,
#wpadminbar .quicklinks .menupop ul li a:focus,
#wpadminbar .quicklinks .menupop ul li a:hover strong,
#wpadminbar .quicklinks .menupop ul li a:focus strong,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a,
#wpadminbar .quicklinks .menupop.hover ul li a:hover,
#wpadminbar .quicklinks .menupop.hover ul li a:focus,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:hover,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:focus,
#wpadminbar li:hover .ab-icon:before,
#wpadminbar li:hover .ab-item:before,
#wpadminbar li a:focus .ab-icon:before,
#wpadminbar li .ab-item:focus:before,
#wpadminbar li .ab-item:focus .ab-icon:before,
#wpadminbar li.hover .ab-icon:before,
#wpadminbar li.hover .ab-item:before,
#wpadminbar li:hover #adminbarsearch:before,
#wpadminbar li #adminbarsearch.adminbar-focused:before {
color: #4f6d59;
}
#wpadminbar .quicklinks li a:hover .blavatar,
#wpadminbar .quicklinks li a:focus .blavatar,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a .blavatar,
#wpadminbar .menupop .menupop > .ab-item:hover:before,
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: #4f6d59;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: #f1f3f2;
}
/* Admin Bar: search */
#wpadminbar #adminbarsearch:before {
color: #f1f3f2;
}
#wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus {
color: #fff;
background: #77bf8f;
}
/* Admin Bar: my account */
#wpadminbar .quicklinks li#wp-admin-bar-my-account.with-avatar > a img {
border-color: #77bf8f;
background-color: #77bf8f;
}
#wpadminbar #wp-admin-bar-user-info .display-name {
color: #fff;
}
#wpadminbar #wp-admin-bar-user-info a:hover .display-name {
color: #4f6d59;
}
#wpadminbar #wp-admin-bar-user-info .username {
color: #cfe8d8;
}
/* Pointers */
.wp-pointer .wp-pointer-content h3 {
background-color: #4f6d59;
border-color: #455e4d;
}
.wp-pointer .wp-pointer-content h3:before {
color: #4f6d59;
}
.wp-pointer.wp-pointer-top .wp-pointer-arrow,
.wp-pointer.wp-pointer-top .wp-pointer-arrow-inner,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow-inner {
border-bottom-color: #4f6d59;
}
/* Media */
.media-item .bar,
.media-progress-bar div {
background-color: #4f6d59;
}
.details.attachment {
box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #4f6d59;
}
.attachment.details .check {
background-color: #4f6d59;
box-shadow: 0 0 0 1px #fff, 0 0 0 2px #4f6d59;
}
.media-selection .attachment.selection.details .thumbnail {
box-shadow: 0 0 0 1px #fff, 0 0 0 3px #4f6d59;
}
/* Themes */
.theme-browser .theme.active .theme-name,
.theme-browser .theme.add-new-theme a:hover:after,
.theme-browser .theme.add-new-theme a:focus:after {
background: #4f6d59;
}
.theme-browser .theme.add-new-theme a:hover span:after,
.theme-browser .theme.add-new-theme a:focus span:after {
color: #4f6d59;
}
.theme-section.current,
.theme-filter.current {
border-bottom-color: #5fb37c;
}
body.more-filters-opened .more-filters {
color: #fff;
background-color: #5fb37c;
}
body.more-filters-opened .more-filters:before {
color: #fff;
}
body.more-filters-opened .more-filters:hover,
body.more-filters-opened .more-filters:focus {
background-color: #4f6d59;
color: #fff;
}
body.more-filters-opened .more-filters:hover:before,
body.more-filters-opened .more-filters:focus:before {
color: #fff;
}
/* Widgets */
.widgets-chooser li.widgets-chooser-selected {
background-color: #4f6d59;
color: #fff;
}
.widgets-chooser li.widgets-chooser-selected:before,
.widgets-chooser li.widgets-chooser-selected:focus:before {
color: #fff;
}
/* Responsive Component */
div#wp-responsive-toggle a:before {
color: #f1f3f2;
}
.wp-responsive-open div#wp-responsive-toggle a {
border-color: transparent;
background: #4f6d59;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle a {
background: #4ca26a;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle .ab-icon:before {
color: #f1f3f2;
}
/* TinyMCE */
.mce-container.mce-menu .mce-menu-item:hover,
.mce-container.mce-menu .mce-menu-item.mce-selected,
.mce-container.mce-menu .mce-menu-item:focus,
.mce-container.mce-menu .mce-menu-item-normal.mce-active,
.mce-container.mce-menu .mce-menu-item-preview.mce-active {
background: #4f6d59;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,499 @@
/*
* Button mixin- creates 3d-ish button effect with correct
* highlights/shadows, based on a base color.
*/
body {
background: #f1f1f1;
}
/* Links */
a {
color: #0073aa;
}
a:hover, a:active, a:focus {
color: #0096dd;
}
#media-upload a.del-link:hover,
div.dashboard-widget-submit input:hover,
.subsubsub a:hover,
.subsubsub a.current:hover {
color: #0096dd;
}
/* Forms */
input[type=checkbox]:checked:before {
color: #4f6d59;
}
input[type=radio]:checked:before {
background: #4f6d59;
}
.wp-core-ui input[type="reset"]:hover,
.wp-core-ui input[type="reset"]:active {
color: #0096dd;
}
/* Core UI */
.wp-core-ui .button-primary {
background: #4f6d59;
border-color: #3a4f41 #2f4035 #2f4035;
color: #fff;
box-shadow: 0 1px 0 #2f4035;
text-shadow: 0 -1px 1px #2f4035, 1px 0 1px #2f4035, 0 1px 1px #2f4035, -1px 0 1px #2f4035;
}
.wp-core-ui .button-primary:hover, .wp-core-ui .button-primary:focus {
background: #567560;
border-color: #2f4035;
color: #fff;
box-shadow: 0 1px 0 #2f4035;
}
.wp-core-ui .button-primary:focus {
box-shadow: inset 0 1px 0 #3a4f41, 0 0 2px 1px #33b3db;
}
.wp-core-ui .button-primary:active, .wp-core-ui .button-primary.active, .wp-core-ui .button-primary.active:focus, .wp-core-ui .button-primary.active:hover {
background: #3a4f41;
border-color: #2f4035;
box-shadow: inset 0 2px 0 #2f4035;
}
.wp-core-ui .button-primary[disabled], .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary.button-primary-disabled, .wp-core-ui .button-primary.disabled {
color: #c7d1ca !important;
background: #3e5546 !important;
border-color: #2f4035 !important;
text-shadow: none !important;
}
.wp-core-ui .button-primary.button-hero {
box-shadow: 0 2px 0 #2f4035 !important;
}
.wp-core-ui .button-primary.button-hero:active {
box-shadow: inset 0 3px 0 #2f4035 !important;
}
.wp-core-ui .wp-ui-primary {
color: #fff;
background-color: #5fb37c;
}
.wp-core-ui .wp-ui-text-primary {
color: #5fb37c;
}
.wp-core-ui .wp-ui-highlight {
color: #fff;
background-color: #4f6d59;
}
.wp-core-ui .wp-ui-text-highlight {
color: #4f6d59;
}
.wp-core-ui .wp-ui-notification {
color: #fff;
background-color: #33834e;
}
.wp-core-ui .wp-ui-text-notification {
color: #33834e;
}
.wp-core-ui .wp-ui-text-icon {
color: #f1f3f2;
}
/* List tables */
.wrap .add-new-h2:hover,
.wrap .page-title-action:hover {
color: #fff;
background-color: #5fb37c;
}
.view-switch a.current:before {
color: #5fb37c;
}
.view-switch a:hover:before {
color: #33834e;
}
/* Admin Menu */
#adminmenuback,
#adminmenuwrap,
#adminmenu {
background: #5fb37c;
}
#adminmenu a {
color: #fff;
}
#adminmenu div.wp-menu-image:before {
color: #f1f3f2;
}
#adminmenu a:hover,
#adminmenu li.menu-top:hover,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
color: #fff;
background-color: #4f6d59;
}
#adminmenu li.menu-top:hover div.wp-menu-image:before,
#adminmenu li.opensub > a.menu-top div.wp-menu-image:before {
color: #fff;
}
/* Active tabs use a bottom border color that matches the page background color. */
.about-wrap h2 .nav-tab-active,
.nav-tab-active,
.nav-tab-active:hover {
background-color: #f1f1f1;
border-bottom-color: #f1f1f1;
}
/* Admin Menu: submenu */
#adminmenu .wp-submenu,
#adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu,
.folded #adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu {
background: #4ca26a;
}
#adminmenu li.wp-has-submenu.wp-not-current-submenu.opensub:hover:after {
border-right-color: #4ca26a;
}
#adminmenu .wp-submenu .wp-submenu-head {
color: #cfe8d8;
}
#adminmenu .wp-submenu a,
#adminmenu .wp-has-current-submenu .wp-submenu a,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a {
color: #cfe8d8;
}
#adminmenu .wp-submenu a:focus, #adminmenu .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu .wp-submenu a:hover,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:focus,
.folded #adminmenu .wp-has-current-submenu .wp-submenu a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu a:hover {
color: #4f6d59;
}
/* Admin Menu: current */
#adminmenu .wp-submenu li.current a,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a {
color: #fff;
}
#adminmenu .wp-submenu li.current a:hover, #adminmenu .wp-submenu li.current a:focus,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:hover,
#adminmenu a.wp-has-current-submenu:focus + .wp-submenu li.current a:focus,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:hover,
#adminmenu .wp-has-current-submenu.opensub .wp-submenu li.current a:focus {
color: #4f6d59;
}
ul#adminmenu a.wp-has-current-submenu:after,
ul#adminmenu > li.current > a.current:after {
border-right-color: #f1f1f1;
}
#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.wp-has-current-submenu .wp-submenu .wp-submenu-head,
.folded #adminmenu li.current.menu-top {
color: #fff;
background: #4f6d59;
}
#adminmenu li.wp-has-current-submenu div.wp-menu-image:before,
#adminmenu a.current:hover div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu a:focus div.wp-menu-image:before,
#adminmenu li.wp-has-current-submenu.opensub div.wp-menu-image:before,
#adminmenu li:hover div.wp-menu-image:before,
#adminmenu li a:focus div.wp-menu-image:before,
#adminmenu li.opensub div.wp-menu-image:before,
.ie8 #adminmenu li.opensub div.wp-menu-image:before {
color: #fff;
}
/* Admin Menu: bubble */
#adminmenu .awaiting-mod,
#adminmenu .update-plugins {
color: #fff;
background: #33834e;
}
#adminmenu li.current a .awaiting-mod,
#adminmenu li a.wp-has-current-submenu .update-plugins,
#adminmenu li:hover a .awaiting-mod,
#adminmenu li.menu-top:hover > a .update-plugins {
color: #fff;
background: #4ca26a;
}
/* Admin Menu: collapse button */
#collapse-button {
color: #f1f3f2;
}
#collapse-button:hover,
#collapse-button:focus {
color: #4f6d59;
}
/* Admin Bar */
#wpadminbar {
color: #fff;
background: #5fb37c;
}
#wpadminbar .ab-item,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon {
color: #fff;
}
#wpadminbar .ab-icon,
#wpadminbar .ab-icon:before,
#wpadminbar .ab-item:before,
#wpadminbar .ab-item:after {
color: #f1f3f2;
}
#wpadminbar:not(.mobile) .ab-top-menu > li:hover > .ab-item,
#wpadminbar:not(.mobile) .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus,
#wpadminbar.nojs .ab-top-menu > li.menupop:hover > .ab-item,
#wpadminbar .ab-top-menu > li.menupop.hover > .ab-item {
color: #4f6d59;
background: #4ca26a;
}
#wpadminbar:not(.mobile) > #wp-toolbar li:hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar li.hover span.ab-label,
#wpadminbar:not(.mobile) > #wp-toolbar a:focus span.ab-label {
color: #4f6d59;
}
#wpadminbar:not(.mobile) li:hover .ab-icon:before,
#wpadminbar:not(.mobile) li:hover .ab-item:before,
#wpadminbar:not(.mobile) li:hover .ab-item:after,
#wpadminbar:not(.mobile) li:hover #adminbarsearch:before {
color: #fff;
}
/* Admin Bar: submenu */
#wpadminbar .menupop .ab-sub-wrapper {
background: #4ca26a;
}
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary,
#wpadminbar .quicklinks .menupop ul.ab-sub-secondary .ab-submenu {
background: #7eb892;
}
#wpadminbar .ab-submenu .ab-item,
#wpadminbar .quicklinks .menupop ul li a,
#wpadminbar .quicklinks .menupop.hover ul li a,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a {
color: #cfe8d8;
}
#wpadminbar .quicklinks li .blavatar,
#wpadminbar .menupop .menupop > .ab-item:before {
color: #f1f3f2;
}
#wpadminbar .quicklinks .menupop ul li a:hover,
#wpadminbar .quicklinks .menupop ul li a:focus,
#wpadminbar .quicklinks .menupop ul li a:hover strong,
#wpadminbar .quicklinks .menupop ul li a:focus strong,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a,
#wpadminbar .quicklinks .menupop.hover ul li a:hover,
#wpadminbar .quicklinks .menupop.hover ul li a:focus,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:hover,
#wpadminbar.nojs .quicklinks .menupop:hover ul li a:focus,
#wpadminbar li:hover .ab-icon:before,
#wpadminbar li:hover .ab-item:before,
#wpadminbar li a:focus .ab-icon:before,
#wpadminbar li .ab-item:focus:before,
#wpadminbar li .ab-item:focus .ab-icon:before,
#wpadminbar li.hover .ab-icon:before,
#wpadminbar li.hover .ab-item:before,
#wpadminbar li:hover #adminbarsearch:before,
#wpadminbar li #adminbarsearch.adminbar-focused:before {
color: #4f6d59;
}
#wpadminbar .quicklinks li a:hover .blavatar,
#wpadminbar .quicklinks li a:focus .blavatar,
#wpadminbar .quicklinks .ab-sub-wrapper .menupop.hover > a .blavatar,
#wpadminbar .menupop .menupop > .ab-item:hover:before,
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: #4f6d59;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: #f1f3f2;
}
/* Admin Bar: search */
#wpadminbar #adminbarsearch:before {
color: #f1f3f2;
}
#wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus {
color: #fff;
background: #77bf8f;
}
/* Admin Bar: my account */
#wpadminbar .quicklinks li#wp-admin-bar-my-account.with-avatar > a img {
border-color: #77bf8f;
background-color: #77bf8f;
}
#wpadminbar #wp-admin-bar-user-info .display-name {
color: #fff;
}
#wpadminbar #wp-admin-bar-user-info a:hover .display-name {
color: #4f6d59;
}
#wpadminbar #wp-admin-bar-user-info .username {
color: #cfe8d8;
}
/* Pointers */
.wp-pointer .wp-pointer-content h3 {
background-color: #4f6d59;
border-color: #455e4d;
}
.wp-pointer .wp-pointer-content h3:before {
color: #4f6d59;
}
.wp-pointer.wp-pointer-top .wp-pointer-arrow,
.wp-pointer.wp-pointer-top .wp-pointer-arrow-inner,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow,
.wp-pointer.wp-pointer-undefined .wp-pointer-arrow-inner {
border-bottom-color: #4f6d59;
}
/* Media */
.media-item .bar,
.media-progress-bar div {
background-color: #4f6d59;
}
.details.attachment {
box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 7px #4f6d59;
}
.attachment.details .check {
background-color: #4f6d59;
box-shadow: 0 0 0 1px #fff, 0 0 0 2px #4f6d59;
}
.media-selection .attachment.selection.details .thumbnail {
box-shadow: 0 0 0 1px #fff, 0 0 0 3px #4f6d59;
}
/* Themes */
.theme-browser .theme.active .theme-name,
.theme-browser .theme.add-new-theme a:hover:after,
.theme-browser .theme.add-new-theme a:focus:after {
background: #4f6d59;
}
.theme-browser .theme.add-new-theme a:hover span:after,
.theme-browser .theme.add-new-theme a:focus span:after {
color: #4f6d59;
}
.theme-section.current,
.theme-filter.current {
border-bottom-color: #5fb37c;
}
body.more-filters-opened .more-filters {
color: #fff;
background-color: #5fb37c;
}
body.more-filters-opened .more-filters:before {
color: #fff;
}
body.more-filters-opened .more-filters:hover,
body.more-filters-opened .more-filters:focus {
background-color: #4f6d59;
color: #fff;
}
body.more-filters-opened .more-filters:hover:before,
body.more-filters-opened .more-filters:focus:before {
color: #fff;
}
/* Widgets */
.widgets-chooser li.widgets-chooser-selected {
background-color: #4f6d59;
color: #fff;
}
.widgets-chooser li.widgets-chooser-selected:before,
.widgets-chooser li.widgets-chooser-selected:focus:before {
color: #fff;
}
/* Responsive Component */
div#wp-responsive-toggle a:before {
color: #f1f3f2;
}
.wp-responsive-open div#wp-responsive-toggle a {
border-color: transparent;
background: #4f6d59;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle a {
background: #4ca26a;
}
.wp-responsive-open #wpadminbar #wp-admin-bar-menu-toggle .ab-icon:before {
color: #f1f3f2;
}
/* TinyMCE */
.mce-container.mce-menu .mce-menu-item:hover,
.mce-container.mce-menu .mce-menu-item.mce-selected,
.mce-container.mce-menu .mce-menu-item:focus,
.mce-container.mce-menu .mce-menu-item-normal.mce-active,
.mce-container.mce-menu .mce-menu-item-preview.mce-active {
background: #4f6d59;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,556 @@
<?php
/**
* bbPress Admin Tools Page
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Output a bbPress specific tools box
*
* @since 2.6.0 bbPress (r6273)
*/
function bbp_admin_tools_box() {
// Bail if user cannot access tools page
if ( ! current_user_can( 'bbp_tools_page' ) ) {
return;
}
// Get the tools pages
$links = array();
$tools = bbp_get_tools_admin_pages(); ?>
<div class="card">
<h3 class="title"><?php esc_html_e( 'Forums', 'bbpress' ) ?></h3>
<p><?php esc_html_e( 'bbPress provides the following tools to help you manage your forums:', 'bbpress' ); ?></p>
<?php
// Loop through tools and create links
foreach ( $tools as $tool ) {
// Skip if user cannot see this page
if ( ! current_user_can( $tool['cap'] ) ) {
continue;
}
// Add link to array
$links[] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $tool['page'] ), admin_url( 'tools.php' ) ) ), $tool['name'] );
}
// Output links
echo '<p class="bbp-tools-links">' . implode( ' &middot; ', $links ) . '</p>';
?></div>
<?php
}
/**
* Register an admin area repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $args
* @return
*/
function bbp_register_repair_tool( $args = array() ) {
// Parse arguments
$r = bbp_parse_args( $args, array(
'id' => '',
'type' => '',
'title' => '',
'description' => '',
'callback' => '',
'priority' => 0,
'overhead' => 'low',
'version' => '',
'components' => array(),
// @todo
'success' => esc_html__( 'The repair was completed successfully', 'bbpress' ),
'failure' => esc_html__( 'The repair was not successful', 'bbpress' )
), 'register_repair_tool' );
// Bail if missing required values
if ( empty( $r['id'] ) || empty( $r['priority'] ) || empty( $r['title'] ) || empty( $r['callback'] ) ) {
return;
}
// Add tool to the registered tools array
bbp_admin()->tools[ $r['id'] ] = array(
'type' => $r['type'],
'title' => $r['title'],
'description' => $r['description'],
'priority' => $r['priority'],
'callback' => $r['callback'],
'overhead' => $r['overhead'],
'components' => $r['components'],
'version' => $r['version'],
// @todo
'success' => $r['success'],
'failure' => $r['failure'],
);
}
/**
* Register the default repair tools
*
* @since 2.6.0 bbPress (r5885)
*/
function bbp_register_default_repair_tools() {
// Topic meta
bbp_register_repair_tool( array(
'id' => 'bbp-sync-topic-meta',
'type' => 'repair',
'title' => esc_html__( 'Recalculate parent topic for each reply', 'bbpress' ),
'description' => esc_html__( 'Run this if replies appear in the wrong topics.', 'bbpress' ),
'callback' => 'bbp_admin_repair_topic_meta',
'priority' => 5,
'overhead' => 'low',
'components' => array( bbp_get_reply_post_type() )
) );
// Forum meta
bbp_register_repair_tool( array(
'id' => 'bbp-sync-forum-meta',
'type' => 'repair',
'title' => esc_html__( 'Recalculate parent forum for each topic and reply', 'bbpress' ),
'description' => esc_html__( 'Run this if topics or replies appear in the wrong forums.', 'bbpress' ),
'callback' => 'bbp_admin_repair_forum_meta',
'priority' => 10,
'overhead' => 'low',
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
) );
// Forum visibility
bbp_register_repair_tool( array(
'id' => 'bbp-sync-forum-visibility',
'type' => 'repair',
'title' => esc_html__( 'Recalculate private and hidden forums', 'bbpress' ),
'description' => esc_html__( 'Run this if non-public forums are publicly visible.', 'bbpress' ),
'callback' => 'bbp_admin_repair_forum_visibility',
'priority' => 15,
'overhead' => 'low',
'components' => array( bbp_get_forum_post_type() )
) );
// Sync all topics in all forums
bbp_register_repair_tool( array(
'id' => 'bbp-sync-all-topics-forums',
'type' => 'repair',
'title' => esc_html__( 'Recalculate last activity in each topic and forum', 'bbpress' ),
'description' => esc_html__( 'Run this if freshness appears incorrectly.', 'bbpress' ),
'callback' => 'bbp_admin_repair_freshness',
'priority' => 20,
'overhead' => 'high',
'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() )
) );
// Sync all sticky topics in all forums
bbp_register_repair_tool( array(
'id' => 'bbp-sync-all-topics-sticky',
'type' => 'repair',
'title' => esc_html__( 'Recalculate sticky relationship of each topic', 'bbpress' ),
'description' => esc_html__( 'Run this if sticky topics appear incorrectly.', 'bbpress' ),
'callback' => 'bbp_admin_repair_sticky',
'priority' => 25,
'overhead' => 'low',
'components' => array( bbp_get_topic_post_type() )
) );
// Sync all hierarchical reply positions
bbp_register_repair_tool( array(
'id' => 'bbp-sync-all-reply-positions',
'type' => 'repair',
'title' => esc_html__( 'Recalculate position of each reply in each topic', 'bbpress' ),
'description' => esc_html__( 'Run this if replies appear in the wrong order.', 'bbpress' ),
'callback' => 'bbp_admin_repair_reply_menu_order',
'priority' => 30,
'overhead' => 'high',
'components' => array( bbp_get_reply_post_type() )
) );
// Sync all topic engagements for all users
bbp_register_repair_tool( array(
'id' => 'bbp-topic-engagements',
'type' => 'repair',
'title' => esc_html__( 'Recalculate engagements in each topic for each user', 'bbpress' ),
'description' => esc_html__( 'Run this if voices appear incorrectly.', 'bbpress' ),
'callback' => 'bbp_admin_repair_topic_voice_count',
'priority' => 35,
'overhead' => 'high',
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
) );
// Update closed topic counts
bbp_register_repair_tool( array(
'id' => 'bbp-sync-closed-topics',
'type' => 'repair',
'title' => esc_html__( 'Repair closed topic statuses', 'bbpress' ),
'description' => esc_html__( 'Run this if closed topics appear incorrectly.', 'bbpress' ),
'callback' => 'bbp_admin_repair_closed_topics',
'priority' => 40,
'overhead' => 'medium',
'components' => array( bbp_get_topic_post_type() )
) );
// Count topics
bbp_register_repair_tool( array(
'id' => 'bbp-forum-topics',
'type' => 'repair',
'title' => esc_html__( 'Recount topics in each forum', 'bbpress' ),
'description' => esc_html__( 'Run this if the number of topics in any forums are incorrect.', 'bbpress' ),
'callback' => 'bbp_admin_repair_forum_topic_count',
'priority' => 45,
'overhead' => 'medium',
'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type() )
) );
// Count topic tags
bbp_register_repair_tool( array(
'id' => 'bbp-topic-tags',
'type' => 'repair',
'title' => esc_html__( 'Recount topics in each topic-tag', 'bbpress' ),
'description' => esc_html__( 'Run this if the number of topics in any topic-tags are incorrect.', 'bbpress' ),
'callback' => 'bbp_admin_repair_topic_tag_count',
'priority' => 50,
'overhead' => 'medium',
'components' => array( bbp_get_topic_post_type(), bbp_get_topic_tag_tax_id() )
) );
// Count forum replies
bbp_register_repair_tool( array(
'id' => 'bbp-forum-replies',
'type' => 'repair',
'title' => esc_html__( 'Recount replies in each forum', 'bbpress' ),
'description' => esc_html__( 'Run this if the number of replies in any forums are incorrect.', 'bbpress' ),
'callback' => 'bbp_admin_repair_forum_reply_count',
'priority' => 55,
'overhead' => 'high',
'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() )
) );
// Count non-published replies to each forum
bbp_register_repair_tool( array(
'id' => 'bbp-forum-hidden-replies',
'type' => 'repair',
'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each forum', 'bbpress' ),
'description' => esc_html__( 'Run this if non-public replies display incorrectly in forums.', 'bbpress' ),
'callback' => 'bbp_admin_repair_forum_hidden_reply_count',
'priority' => 60,
'overhead' => 'high',
'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() )
) );
// Count topic replies
bbp_register_repair_tool( array(
'id' => 'bbp-topic-replies',
'type' => 'repair',
'title' => esc_html__( 'Recount replies in each topic', 'bbpress' ),
'description' => esc_html__( 'Run this if the number of replies in any topics are incorrect.', 'bbpress' ),
'callback' => 'bbp_admin_repair_topic_reply_count',
'priority' => 65,
'overhead' => 'high',
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
) );
// Count non-published replies to each topic
bbp_register_repair_tool( array(
'id' => 'bbp-topic-hidden-replies',
'type' => 'repair',
'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each topic', 'bbpress' ),
'description' => esc_html__( 'Run this if non-public replies display incorrectly in topics.', 'bbpress' ),
'callback' => 'bbp_admin_repair_topic_hidden_reply_count',
'priority' => 70,
'overhead' => 'high',
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
) );
// Recount topics for each user
bbp_register_repair_tool( array(
'id' => 'bbp-user-topics',
'type' => 'repair',
'title' => esc_html__( 'Recount topics for each user', 'bbpress' ),
'description' => esc_html__( 'Run this to get fresh topic counts for all users.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_topic_count',
'priority' => 75,
'overhead' => 'medium',
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
) );
// Recount topics for each user
bbp_register_repair_tool( array(
'id' => 'bbp-user-replies',
'type' => 'repair',
'title' => esc_html__( 'Recount replies for each user', 'bbpress' ),
'description' => esc_html__( 'Run this to get fresh reply counts for all users.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_reply_count',
'priority' => 80,
'overhead' => 'medium',
'components' => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() )
) );
// Remove unpublished topics from user favorites
bbp_register_repair_tool( array(
'id' => 'bbp-user-favorites',
'type' => 'repair',
'title' => esc_html__( 'Remove unpublished topics from user favorites', 'bbpress' ),
'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user favorites.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_favorites',
'priority' => 85,
'overhead' => 'medium',
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
) );
// Remove unpublished topics from user subscriptions
bbp_register_repair_tool( array(
'id' => 'bbp-user-topic-subscriptions',
'type' => 'repair',
'title' => esc_html__( 'Remove unpublished topics from user subscriptions', 'bbpress' ),
'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user subscriptions.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_topic_subscriptions',
'priority' => 90,
'overhead' => 'medium',
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
) );
// Remove unpublished forums from user subscriptions
bbp_register_repair_tool( array(
'id' => 'bbp-user-forum-subscriptions',
'type' => 'repair',
'title' => esc_html__( 'Remove unpublished forums from user subscriptions', 'bbpress' ),
'description' => esc_html__( 'Run this to remove trashed or deleted forums from all user subscriptions.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_forum_subscriptions',
'priority' => 95,
'overhead' => 'medium',
'components' => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() )
) );
// Remove unpublished forums from user subscriptions
bbp_register_repair_tool( array(
'id' => 'bbp-user-role-map',
'type' => 'repair',
'title' => esc_html__( 'Remap all users to default forum roles', 'bbpress' ),
'description' => esc_html__( 'Run this if users have issues accessing the forums.', 'bbpress' ),
'callback' => 'bbp_admin_repair_user_roles',
'priority' => 100,
'overhead' => 'low',
'components' => array( bbp_get_user_rewrite_id() )
) );
// Migrate topic engagements to post-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-topic-engagements-move',
'type' => 'upgrade',
'title' => esc_html__( 'Upgrade user topic engagements', 'bbpress' ),
'description' => esc_html__( 'Copies engagements from user meta to topic meta.', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_user_engagements',
'priority' => 105,
'version' => '2.6.0',
'overhead' => 'high',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_engagements_rewrite_id() )
) );
// Migrate favorites from user-meta to post-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-favorites-move',
'type' => 'upgrade',
'title' => esc_html__( 'Upgrade user topic favorites', 'bbpress' ),
'description' => esc_html__( 'Copies favorites from user meta to topic meta.', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_user_favorites',
'priority' => 110,
'version' => '2.6.0',
'overhead' => 'high',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_favorites_rewrite_id() )
) );
// Migrate topic subscriptions from user-meta to post-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-topic-subscriptions-move',
'type' => 'upgrade',
'title' => esc_html__( 'Upgrade user topic subscriptions', 'bbpress' ),
'description' => esc_html__( 'Copies topic subscriptions from user meta to topic meta.', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_user_topic_subscriptions',
'priority' => 115,
'version' => '2.6.0',
'overhead' => 'high',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() )
) );
// Migrate forum subscriptions from user-meta to post-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-forum-subscriptions-move',
'type' => 'upgrade',
'title' => esc_html__( 'Upgrade user forum subscriptions', 'bbpress' ),
'description' => esc_html__( 'Copies forum subscriptions from user meta to forum meta.', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_user_forum_subscriptions',
'priority' => 120,
'version' => '2.6.0',
'overhead' => 'high',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() )
) );
// Remove favorites from user-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-favorites-delete',
'type' => 'upgrade',
'title' => esc_html__( 'Remove favorites from user-meta', 'bbpress' ),
'description' => esc_html__( 'Run this to delete old data (after confirming successful favorites upgrade)', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_remove_favorites_from_usermeta',
'priority' => 125,
'version' => '2.6.1',
'overhead' => 'medium',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_favorites_rewrite_id() )
) );
// Remove topic subscriptions from user-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-topic-subscriptions-delete',
'type' => 'upgrade',
'title' => esc_html__( 'Remove topic subscriptions from user-meta', 'bbpress' ),
'description' => esc_html__( 'Run this to delete old data (after confirming successful topic subscriptions upgrade)', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta',
'priority' => 130,
'version' => '2.6.1',
'overhead' => 'medium',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() )
) );
// Remove forum subscriptions from user-meta
bbp_register_repair_tool( array(
'id' => 'bbp-user-forum-subscriptions-delete',
'type' => 'upgrade',
'title' => esc_html__( 'Remove forum subscriptions from user-meta', 'bbpress' ),
'description' => esc_html__( 'Run this to delete old data (after confirming successful forum subscriptions upgrade)', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta',
'priority' => 135,
'version' => '2.6.1',
'overhead' => 'medium',
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() )
) );
// Sync all BuddyPress group forum relationships
bbp_register_repair_tool( array(
'id' => 'bbp-group-forums',
'type' => 'upgrade',
'title' => esc_html__( 'Upgrade BuddyPress Group Forum relationships', 'bbpress' ),
'description' => esc_html__( 'Run this if you just upgraded BuddyPress Forums from Legacy.', 'bbpress' ),
'callback' => 'bbp_admin_upgrade_group_forum_relationship',
'priority' => 140,
'version' => esc_html__( 'Any', 'bbpress' ),
'overhead' => 'low',
'components' => array( bbp_get_forum_post_type() )
) );
}
/**
* Output the tabs in the admin area
*
* @since 2.1.0 bbPress (r3872)
*
* @param string $active_tab Name of the tab that is active
*/
function bbp_tools_admin_tabs( $active_tab = '' ) {
echo bbp_get_tools_admin_tabs( $active_tab );
}
/**
* Output the tabs in the admin area
*
* @since 2.1.0 bbPress (r3872)
*
* @param string $active_tab Name of the tab that is active
*/
function bbp_get_tools_admin_tabs( $active_tab = '' ) {
// Declare local variables
$tabs_html = '';
$idle_class = 'nav-tab';
$active_class = 'nav-tab nav-tab-active';
// Setup core admin tabs
$tabs = bbp_get_tools_admin_pages();
// Loop through tabs and build navigation
foreach ( $tabs as $tab ) {
// Skip if user cannot visit page
if ( ! current_user_can( $tab['cap'] ) ) {
continue;
}
// Setup tab HTML
$is_current = (bool) ( $tab['page'] === $active_tab );
$tab_class = $is_current ? $active_class : $idle_class;
$tab_url = add_query_arg( array( 'page' => $tab['page'] ), admin_url( 'tools.php' ) );
// Tab name is not escaped - may contain HTML
$tabs_html .= '<a href="' . esc_url( $tab_url ) . '" class="' . esc_attr( $tab_class ) . '">' . $tab['name'] . '</a>';
}
// Output the tabs
return $tabs_html;
}
/**
* Return possible tools pages
*
* @since 2.6.0 bbPress (r6273)
*
* @return array
*/
function bbp_get_tools_admin_pages() {
// Get tools URL one time & use in each tab
$tools_url = admin_url( 'tools.php' );
// Filter & return
return (array) apply_filters( 'bbp_tools_admin_tabs', array(
array(
'page' => 'bbp-repair',
'func' => 'bbp_admin_repair_page',
'cap' => 'bbp_tools_repair_page',
'name' => bbp_maybe_append_pending_upgrade_count( esc_html__( 'Repair Forums', 'bbpress' ), 'repair' ),
// Deprecated 2.6.0
'href' => add_query_arg( array( 'page' => 'bbp-repair' ), $tools_url )
),
array(
'page' => 'bbp-upgrade',
'func' => 'bbp_admin_upgrade_page',
'cap' => 'bbp_tools_upgrade_page',
'name' => bbp_maybe_append_pending_upgrade_count( esc_html__( 'Upgrade Forums', 'bbpress' ), 'upgrade' ),
// Deprecated 2.6.0
'href' => add_query_arg( array( 'page' => 'bbp-upgrade' ), $tools_url )
),
array(
'page' => 'bbp-converter',
'func' => 'bbp_converter_settings_page',
'cap' => 'bbp_tools_import_page',
'name' => esc_html__( 'Import Forums', 'bbpress' ),
// Deprecated 2.6.0
'href' => add_query_arg( array( 'page' => 'bbp-converter' ), $tools_url )
),
array(
'page' => 'bbp-reset',
'func' => 'bbp_admin_reset_page',
'cap' => 'bbp_tools_reset_page',
'name' => esc_html__( 'Reset Forums', 'bbpress' ),
// Deprecated 2.6.0
'href' => add_query_arg( array( 'page' => 'bbp-reset' ), $tools_url )
)
) );
}

View File

@@ -0,0 +1,933 @@
<?php
/**
* bbPress Admin Tools Common
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Return the current admin repair tool page
*
* @since 2.6.0 bbPress (r6894)
*
* @return string
*/
function bbp_get_admin_repair_tool_page() {
return sanitize_key( $_GET['page'] );
}
/**
* Return the current admin repair tool page ID
*
* @since 2.6.0 bbPress (r6894)
*
* @return string
*/
function bbp_get_admin_repair_tool_page_id() {
// Get the page
$page = bbp_get_admin_repair_tool_page();
// Maybe trim prefix off of page
if ( ! empty( $page ) && ( 0 === strpos( $page, 'bbp-' ) ) ) {
$page = str_replace( 'bbp-', '', $page );
} else {
$page = '';
}
return $page;
}
/**
* Return a URL to the repair tool page
*
* @since 2.6.0 bbPress (r6894)
*
* @param array $args
*
* @return string
*/
function bbp_get_admin_repair_tool_page_url( $args = array() ) {
// Parse arguments
$r = wp_parse_args( $args, array(
'page' => bbp_get_admin_repair_tool_page()
) );
return add_query_arg( $r, admin_url( 'tools.php' ) );
}
/**
* Output the URL to run a specific repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param string $component
*/
function bbp_admin_repair_tool_run_url( $component = array() ) {
echo esc_url( bbp_get_admin_repair_tool_run_url( $component ) );
}
/**
* Return the URL to run a specific repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param string $component
*/
function bbp_get_admin_repair_tool_run_url( $component = array() ) {
// Page
$page = ( 'repair' === $component['type'] )
? 'bbp-repair'
: 'bbp-upgrade';
// Arguments
$args = array(
'page' => $page,
'action' => 'run',
'checked' => array( $component['id'] )
);
// Url
$nonced = wp_nonce_url( bbp_get_admin_repair_tool_page_url( $args ), 'bbpress-do-counts' );
// Filter & return
return apply_filters( 'bbp_get_admin_repair_tool_run_url', $nonced, $component );
}
/**
* Assemble the admin notices
*
* @since 2.0.0 bbPress (r2613)
*
* @param string|WP_Error $message A message to be displayed or {@link WP_Error}
* @param string $class Optional. A class to be added to the message div
* @param bool $is_dismissible Optional. True to dismiss, false to persist
*
* @return string The message HTML
*/
function bbp_admin_tools_feedback( $message, $class = false, $is_dismissible = true ) {
return bbp_admin()->add_notice( $message, $class, $is_dismissible );
}
/**
* Handle the processing and feedback of the admin tools page
*
* @since 2.0.0 bbPress (r2613)
*
*/
function bbp_admin_repair_handler() {
// Bail if not an actionable request
if ( ! bbp_is_get_request() ) {
return;
}
// Get the current action or bail
if ( ! empty( $_GET['action'] ) ) {
$action = sanitize_key( $_GET['action'] );
} elseif ( ! empty( $_GET['action2'] ) ) {
$action = sanitize_key( $_GET['action2'] );
} else {
return;
}
// Bail if not running an action
if ( 'run' !== $action ) {
return;
}
check_admin_referer( 'bbpress-do-counts' );
// Parse list of checked repairs
$checked = ! empty( $_GET['checked'] )
? array_map( 'sanitize_key', $_GET['checked'] )
: array();
// Flush all caches before running tools
wp_cache_flush();
// Get the list
$list = bbp_get_admin_repair_tools();
// Stores messages
$messages = array();
// Run through checked repair tools
if ( count( $checked ) ) {
foreach ( $checked as $item_id ) {
if ( isset( $list[ $item_id ] ) && is_callable( $list[ $item_id ]['callback'] ) ) {
$messages[] = call_user_func( $list[ $item_id ]['callback'] );
// Remove from pending
bbp_remove_pending_upgrade( $item_id );
}
}
}
// Feedback
if ( count( $messages ) ) {
foreach ( $messages as $message ) {
bbp_admin_tools_feedback( $message[1] );
}
}
// Flush all caches after running tools
wp_cache_flush();
}
/**
* Get the array of available repair tools
*
* @since 2.6.0 bbPress (r5885)
*
* @param string $type repair|upgrade The type of tools to get. Default empty for all tools.
* @return array
*/
function bbp_get_admin_repair_tools( $type = '' ) {
// Get tools array
$tools = ! empty( bbp_admin()->tools )
? bbp_admin()->tools
: array();
// Maybe limit to type (otherwise return all tools)
if ( ! empty( $type ) ) {
$tools = wp_list_filter( bbp_admin()->tools, array( 'type' => $type ) );
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tools', $tools, $type );
}
/**
* Return array of components from the array of registered tools
*
* @since 2.5.0 bbPress (r5885)
*
* @return array
*/
function bbp_get_admin_repair_tool_registered_components() {
// Default return value
$retval = array();
// Get tools
$tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
// Loop through tools
if ( ! empty( $tools ) ) {
$plucked = wp_list_pluck( $tools, 'components' );
// Loop through components
if ( count( $plucked ) ) {
foreach ( $plucked as $components ) {
foreach ( $components as $component ) {
// Skip if already in array
if ( in_array( $component, $retval, true ) ) {
continue;
}
// Add component to the array
$retval[] = $component;
}
}
}
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_components', $retval );
}
/**
* Output the repair list search form
*
* @since 2.6.0 bbPress (r5885)
*/
function bbp_admin_repair_list_search_form() {
?>
<p class="search-box">
<label class="screen-reader-text" for="bbp-repair-search-input"><?php esc_html_e( 'Search Tools:', 'bbpress' ); ?></label>
<input type="search" id="bbp-repair-search-input" name="s" value="<?php _admin_search_query(); ?>">
<input type="submit" id="search-submit" class="button" value="<?php esc_html_e( 'Search Tools', 'bbpress' ); ?>">
</p>
<?php
}
/**
* Output a select drop-down of components to filter by
*
* @since 2.5.0 bbPress (r5885)
*/
function bbp_admin_repair_list_components_filter() {
// Sanitize component value, if exists
$selected = ! empty( $_GET['components'] )
? sanitize_key( $_GET['components'] )
: '';
// Get registered components
$components = bbp_get_admin_repair_tool_registered_components();
// Bail if no components
if ( empty( $components ) ) {
return;
} ?>
<label class="screen-reader-text" for="components"><?php esc_html_e( 'Filter by Component', 'bbpress' ); ?></label>
<select name="components" id="components" class="postform">
<option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Components', 'bbpress' ); ?></option>
<?php foreach ( $components as $component ) : ?>
<option class="level-0" value="<?php echo esc_attr( $component ); ?>" <?php selected( $selected, $component ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_component( $component ) ); ?></option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Return array of versions from the array of registered tools
*
* @since 2.6.0 bbPress (r6894)
*
* @return array
*/
function bbp_get_admin_repair_tool_registered_versions() {
// Default return value
$retval = array();
// Get tools
$tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
// Loop through tools
if ( ! empty( $tools ) ) {
$plucked = wp_list_pluck( $tools, 'version' );
// Loop through components
if ( count( $plucked ) ) {
foreach ( $plucked as $versions ) {
// Skip if empty
if ( empty( $versions ) ) {
continue;
// Cast to array if string
} elseif ( is_string( $versions ) ) {
$versions = (array) $versions;
}
// Loop through versions
foreach ( $versions as $version ) {
// Skip if already in array
if ( in_array( $version, $retval, true ) ) {
continue;
}
// Add component to the array
$retval[] = $version;
}
}
}
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_versions', $retval );
}
/**
* Output a select drop-down of versions to filter by
*
* @since 2.5.0 bbPress (r6894)
*/
function bbp_admin_repair_list_versions_filter() {
// Sanitize component value, if exists
$selected = ! empty( $_GET['version'] )
? sanitize_text_field( $_GET['version'] )
: '';
// Get registered components
$versions = bbp_get_admin_repair_tool_registered_versions();
// Bail if no components
if ( empty( $versions ) ) {
return;
} ?>
<label class="screen-reader-text" for="version"><?php esc_html_e( 'Filter by Version', 'bbpress' ); ?></label>
<select name="version" id="version" class="postform">
<option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Versions', 'bbpress' ); ?></option>
<?php foreach ( $versions as $version ) : ?>
<option class="level-0" value="<?php echo esc_attr( $version ); ?>" <?php selected( $selected, $version ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_version( $version ) ); ?></option>
<?php endforeach; ?>
</select>
<?php
}
/** Translations **************************************************************/
/**
* Maybe translate a repair tool overhead name
*
* @since 2.6.0 bbPress (r6177)
*
* @param string $overhead
* @return string
*/
function bbp_admin_repair_tool_translate_overhead( $overhead = '' ) {
// Get the name of the component
switch ( $overhead ) {
case 'low' :
$name = esc_html__( 'Low', 'bbpress' );
break;
case 'medium' :
$name = esc_html__( 'Medium', 'bbpress' );
break;
case 'high' :
$name = esc_html__( 'High', 'bbpress' );
break;
default :
$name = ucwords( $overhead );
break;
}
return $name;
}
/**
* Maybe translate a repair tool component name
*
* @since 2.6.0 bbPress (r5885)
*
* @param string $component
* @return string
*/
function bbp_admin_repair_tool_translate_component( $component = '' ) {
// Get the name of the component
switch ( $component ) {
case 'bbp_user' :
$name = esc_html__( 'Users', 'bbpress' );
break;
case bbp_get_forum_post_type() :
$name = esc_html__( 'Forums', 'bbpress' );
break;
case bbp_get_topic_post_type() :
$name = esc_html__( 'Topics', 'bbpress' );
break;
case bbp_get_reply_post_type() :
$name = esc_html__( 'Replies', 'bbpress' );
break;
case bbp_get_topic_tag_tax_id() :
$name = esc_html__( 'Topic Tags', 'bbpress' );
break;
case bbp_get_user_rewrite_id() :
$name = esc_html__( 'Users', 'bbpress' );
break;
case bbp_get_user_favorites_rewrite_id() :
$name = esc_html__( 'Favorites', 'bbpress' );
break;
case bbp_get_user_subscriptions_rewrite_id() :
$name = esc_html__( 'Subscriptions', 'bbpress' );
break;
case bbp_get_user_engagements_rewrite_id() :
$name = esc_html__( 'Engagements', 'bbpress' );
break;
default :
$name = ucwords( $component );
break;
}
return $name;
}
/**
* Maybe translate a repair tool overhead name
*
* @since 2.6.0 bbPress (r6894)
*
* @param string $version
* @return string
*/
function bbp_admin_repair_tool_translate_version( $version = '' ) {
// Get the version
switch ( $version ) {
case '2.5' :
case '2.5.0' :
$name = esc_html__( '2.5.0', 'bbpress' );
break;
case '2.6' :
case '2.6.0' :
$name = esc_html__( '2.6.0', 'bbpress' );
break;
default :
$name = sanitize_text_field( $version );
break;
}
return $name;
}
/** Lists *********************************************************************/
/**
* Get the array of the repairs to show in a list table.
*
* Uses known filters to reduce the registered results down to the most finite
* set of tools.
*
* @since 2.0.0 bbPress (r2613)
*
* @return array Repair list of options
*/
function bbp_admin_repair_list( $type = 'repair' ) {
// Define empty array
$repair_list = array();
// Get the available tools
$list = bbp_get_admin_repair_tools( $type );
// Get pending upgrades
$pending = bbp_get_pending_upgrades();
// Search
$search = ! empty( $_GET['s'] )
? stripslashes( $_GET['s'] )
: '';
// Status
$status = ! empty( $_GET['status'] )
? sanitize_key( $_GET['status'] )
: '';
// Overhead
$overhead = ! empty( $_GET['overhead'] )
? sanitize_key( $_GET['overhead'] )
: '';
// Component
$component = ! empty( $_GET['components'] )
? sanitize_key( $_GET['components'] )
: '';
// Version
$version = ! empty( $_GET['version'] )
? sanitize_text_field( $_GET['version'] )
: '';
// Orderby
$orderby = ! empty( $_GET['orderby'] )
? sanitize_key( $_GET['orderby'] )
: 'priority';
// Order
$order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
? strtolower( $_GET['order'] )
: 'asc';
// Overhead filter
if ( ! empty( $overhead ) ) {
$list = wp_list_filter( $list, array( 'overhead' => $overhead ) );
}
if ( count( $list ) ) {
// Loop through and key by priority for sorting
foreach ( $list as $id => $tool ) {
// Status filter
if ( ! empty( $status ) && ( 'pending' === $status ) ) {
if ( ! in_array( $id, (array) $pending, true ) ) {
continue;
}
}
// Component filter
if ( ! empty( $component ) ) {
if ( ! in_array( $component, (array) $tool['components'], true ) ) {
continue;
}
}
// Version filter
if ( ! empty( $version ) ) {
if ( ! in_array( $version, (array) $tool['version'], true ) ) {
continue;
}
}
// Search
if ( ! empty( $search ) ) {
if ( ! strstr( strtolower( $tool['title'] ), strtolower( $search ) ) ) {
continue;
}
}
// Add to repair list
$repair_list[ $tool['priority'] ] = array(
'id' => sanitize_key( $id ),
'type' => $tool['type'],
'title' => $tool['title'],
'priority' => $tool['priority'],
'description' => $tool['description'],
'callback' => $tool['callback'],
'overhead' => $tool['overhead'],
'version' => $tool['version'],
'components' => $tool['components']
);
}
}
// Sort
$retval = wp_list_sort( $repair_list, $orderby, $order, true );
// Filter & return
return (array) apply_filters( 'bbp_repair_list', $retval );
}
/**
* Get filter links for components for a specific admin repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $item
* @return array
*/
function bbp_get_admin_repair_tool_components( $item = array() ) {
// Get the tools URL
$tools_url = bbp_get_admin_repair_tool_page_url();
// Define links array
$links = array();
$components = ! empty( $item['components'] )
? (array) $item['components']
: array();
// Loop through tool components and build links
if ( count( $components ) ) {
foreach ( $components as $component ) {
$args = array( 'components' => $component );
$filter_url = add_query_arg( $args, $tools_url );
$name = bbp_admin_repair_tool_translate_component( $component );
$links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No components, so return a dash
} else {
$links[] = '&mdash;';
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_components', $links, $item );
}
/**
* Get filter links for versions for a specific admin repair tool
*
* @since 2.6.0 bbPress (r6894)
*
* @param array $item
* @return array
*/
function bbp_get_admin_repair_tool_version( $item = array() ) {
// Get the tools URL
$tools_url = bbp_get_admin_repair_tool_page_url();
// Define links array
$links = array();
$versions = ! empty( $item['version'] )
? (array) $item['version']
: array();
// Loop through tool versions and build links
if ( count( $versions ) ) {
foreach ( $versions as $version ) {
$args = array( 'version' => $version );
$filter_url = add_query_arg( $args, $tools_url );
$name = bbp_admin_repair_tool_translate_version( $version );
$links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No versions, so return a dash
} else {
$links[] = '&mdash;';
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_version', $links, $item );
}
/**
* Get filter links for overhead for a specific admin repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $item
* @return array
*/
function bbp_get_admin_repair_tool_overhead( $item = array() ) {
// Get the tools URL
$tools_url = bbp_get_admin_repair_tool_page_url();
// Define links array
$links = array();
$overheads = ! empty( $item['overhead'] )
? (array) $item['overhead']
: array();
// Loop through tool overhead and build links
if ( count( $overheads ) ) {
foreach ( $overheads as $overhead ) {
$args = array( 'overhead' => $overhead );
$filter_url = add_query_arg( $args, $tools_url );
$name = bbp_admin_repair_tool_translate_overhead( $overhead );
$links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No overhead, so return a single dash
} else {
$links[] = '&mdash;';
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item );
}
/** Overhead ******************************************************************/
/**
* Output filter links for overheads for a specific admin repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $args
*/
function bbp_admin_repair_tool_overhead_filters( $args = array() ) {
echo bbp_get_admin_repair_tool_overhead_filters( $args );
}
/**
* Get filter links for overheads for a specific admin repair tool
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $args
* @return array
*/
function bbp_get_admin_repair_tool_overhead_filters( $args = array() ) {
// Parse args
$r = bbp_parse_args( $args, array(
'before' => '<ul class="subsubsub">',
'after' => '</ul>',
'link_before' => '<li>',
'link_after' => '</li>',
'count_before' => ' <span class="count">(',
'count_after' => ')</span>',
'sep' => ' | ',
// Retired, use 'sep' instead
'separator' => false
), 'get_admin_repair_tool_overhead_filters' );
/**
* Necessary for backwards compatibility
* @see https://bbpress.trac.wordpress.org/ticket/2900
*/
if ( ! empty( $r['separator'] ) ) {
$r['sep'] = $r['separator'];
}
// Count the tools
$tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
// Get the tools URL
$tools_url = bbp_get_admin_repair_tool_page_url();
// Define arrays
$overheads = $links = array();
// Loop through tools and count overheads
if ( count( $tools ) ) {
foreach ( $tools as $tool ) {
// Get the overhead level
$overhead = $tool['overhead'];
// Set an empty count
if ( empty( $overheads[ $overhead ] ) ) {
$overheads[ $overhead ] = 0;
}
// Bump the overhead count
$overheads[ $overhead ]++;
}
}
// Get the current overhead, if any
$selected = ! empty( $_GET['overhead'] )
? sanitize_key( $_GET['overhead'] )
: '';
// Create the "All" link
$current = empty( $selected ) ? 'current' : '';
$links[] = $r['link_before'] . '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $r['count_before'] . count( $tools ) . $r['count_after'] ) . '</a>' . $r['link_after'];
// Loop through overheads and created links
if ( count( $overheads ) ) {
// Sort
ksort( $overheads );
// Loop through overheads and build filter
foreach ( $overheads as $overhead => $count ) {
// Build the filter URL
$key = sanitize_key( $overhead );
$args = array( 'overhead' => $key );
$filter_url = add_query_arg( $args, $tools_url );
// Figure out separator and active class
$current = ( $selected === $key )
? 'current'
: '';
// Counts to show
if ( ! empty( $count ) ) {
$overhead_count = $r['count_before'] . $count . $r['count_after'];
}
// Build the link
$links[] = $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $current ) . '">' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '</a>' . $r['link_after'];
}
}
// Surround output with before & after strings
$output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
// Filter & return
return apply_filters( 'bbp_get_admin_repair_tool_overhead_filters', $output, $r, $args );
}
/** Pending ******************************************************************/
/**
* Output filter links for statuses
*
* @since 2.6.0 bbPress (r6925)
*
* @param array $args
*/
function bbp_admin_repair_tool_status_filters( $args = array() ) {
echo bbp_get_admin_repair_tool_status_filters( $args );
}
/**
* Get filter links for statuses
*
* @since 2.6.0 bbPress (r5885)
*
* @param array $args
* @return array
*/
function bbp_get_admin_repair_tool_status_filters( $args = array() ) {
// Parse args
$r = bbp_parse_args( $args, array(
'before' => '<ul class="subsubsub">',
'after' => '</ul>',
'link_before' => '<li>',
'link_after' => '</li>',
'count_before' => ' <span class="count">(',
'count_after' => ')</span>',
'sep' => ' | ',
// Retired, use 'sep' instead
'separator' => false
), 'get_admin_repair_tool_status_filters' );
/**
* Necessary for backwards compatibility
* @see https://bbpress.trac.wordpress.org/ticket/2900
*/
if ( ! empty( $r['separator'] ) ) {
$r['sep'] = $r['separator'];
}
// Get the type of tool
$type = bbp_get_admin_repair_tool_page_id();
// Count the tools
$tools = bbp_get_admin_repair_tools( $type );
// Get the tools URL
$tools_url = bbp_get_admin_repair_tool_page_url();
// Get pending upgrades
$pending = bbp_get_pending_upgrades( $type );
// Get the current status, if any
$selected = ! empty( $_GET['status'] )
? sanitize_key( $_GET['status'] )
: '';
// Nothing is current?
$all_current = empty( $selected )
? 'current'
: '';
// Pending is current?
$pending_current = ( 'pending' === $selected )
? 'current'
: '';
// Sort
ksort( $pending );
// Build the filter URL
$filter_url = add_query_arg( array(
'status' => 'pending'
), $tools_url );
// Count HTML
$all_count = $r['count_before'] . count( $tools ) . $r['count_after'];
$pending_count = $r['count_before'] . count( $pending ) . $r['count_after'];
// Define links
$links = array(
$r['link_before'] . '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $all_current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $all_count ) . '</a>' . $r['link_after'],
$r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $pending_current ) . '">' . sprintf( esc_html__( 'Pending %s', 'bbpress' ), $pending_count ) . '</a>' . $r['link_after']
);
// Surround output with before & after strings
$output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
// Filter & return
return apply_filters( 'bbp_get_admin_repair_tool_status_filters', $output, $r, $args );
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* bbPress Converter
*
* Based on the hard work of Adam Ellis
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Return an array of available converters
*
* @since 2.6.0 bbPress (r6447)
*
* @return array
*/
function bbp_get_converters() {
static $files = array();
// Only hit the file system one time per page load
if ( empty( $files ) ) {
// Open the converter directory
$path = bbp_setup_converter()->converters_dir;
$curdir = opendir( $path );
// Look for the converter file in the converters directory
if ( false !== $curdir ) {
while ( $file = readdir( $curdir ) ) {
if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) {
$name = preg_replace( '/.php/', '', $file );
if ( 'Example' !== $name ) {
$files[ $name ] = $path . $file;
}
}
}
}
// Close the directory
closedir( $curdir );
// Sort keys alphabetically, ignoring upper/lower casing
if ( ! empty( $files ) ) {
natcasesort( $files );
}
}
// Filter & return
return (array) apply_filters( 'bbp_get_converters', $files );
}
/**
* This is a function that is purposely written to look like a "new" statement.
* It is basically a dynamic loader that will load in the platform conversion
* of your choice.
*
* @since 2.0.0
*
* @param string $platform Name of valid platform class.
*
* @return mixed Object if converter exists, null if not
*/
function bbp_new_converter( $platform = '' ) {
// Default converter
$converter = null;
// Bail if no platform
if ( empty( $platform ) ) {
return $converter;
}
// Get the available converters
$converters = bbp_get_converters();
// Get the converter file form converters array
$converter_file = isset( $converters[ $platform ] )
? $converters[ $platform ]
: '';
// Try to create a new converter object
if ( ! empty( $converter_file ) ) {
// Try to include the converter
@include_once $converter_file;
// Try to instantiate the converter object
if ( class_exists( $platform ) ) {
$converter = new $platform();
}
}
// Filter & return
return apply_filters( 'bbp_new_converter', $converter, $platform );
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* bbPress Admin Tools Help
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Contextual help for Repair Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_repair_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Repair Forums
$current_screen->add_help_tab( array(
'id' => 'repair_forums',
'title' => __( 'Repair Forums', 'bbpress' ),
'content' => '<p>' . __( 'There is more detailed information available on the bbPress and BuddyPress codex for the following:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'BuddyPress Group Forums: <a href="https://codex.buddypress.org/getting-started/installing-group-and-sitewide-forums/">Installing Group and Sitewide Forums</a> and <a href="https://codex.buddypress.org/getting-started/guides/migrating-from-old-forums-to-bbpress-2/">Migrating from old forums to bbPress 2.2+</a>.', 'bbpress' ) . '</li>' .
'<li>' . __( 'bbPress roles: <a href="https://codex.bbpress.org/bbpress-user-roles-and-capabilities/" target="_blank">bbPress User Roles and Capabilities</a>', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>' .
'<p>' . __( 'Also see <a href="https://codex.bbpress.org/repair-forums/">bbPress: Repair Forums</a>.', 'bbpress' ) . '</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Contextual help for Reset Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_reset_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Reset Forums
$current_screen->add_help_tab( array(
'id' => 'reset_forums',
'title' => __( 'Reset Forums', 'bbpress' ),
'content' => '<p>' . __( 'Also see <a href="https://codex.bbpress.org/reset-forums/">bbPress: Reset Forums</a>.', 'bbpress' ) . '</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Contextual help for Import Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_converter_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Overview
$current_screen->add_help_tab( array(
'id' => 'overview',
'title' => __( 'Overview', 'bbpress' ),
'content' => '<p>' . __( 'This screen provides access to all of the bbPress Import Forums settings and resources.', 'bbpress' ) . '</p>' .
'<p>' . __( 'Please see the additional help tabs for more information on each individual section.', 'bbpress' ) . '</p>' .
'<p>' . __( 'Also see the main article on the bbPress codex <a href="https://codex.bbpress.org/import-forums/">bbPress: Import Forums</a>.', 'bbpress' ) . '</p>'
) );
// Database Settings
$current_screen->add_help_tab( array(
'id' => 'database_settings',
'title' => __( 'Database Settings', 'bbpress' ),
'content' => '<p>' . __( 'In the Database Settings you have a number of options:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'The settings in this section refer to the database connection strings used by your old forum software. The best way to determine the exact settings you need is to copy them from your legacy forums configuration file or contact your web hosting provider.', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>'
) );
// Importer Options
$current_screen->add_help_tab( array(
'id' => 'importer_options',
'title' => __( 'Importer Options', 'bbpress' ),
'content' => '<p>' . __( 'In the Options you have a number of options:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'Depending on your MySQL configuration you can tweak the "Rows Limit" and "Delay Time" that may help to improve the overall time it takes to perform a complete forum import.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Convert Users" will import your legacy forum members as WordPress Users.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Start Over" will start the importer fresh, if your import failed for any reason leaving this setting unchecked the importer will begin from where it left off.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Purge Previous Import" will remove data imported from a failed import without removing your existing forum data.', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,272 @@
<?php
/**
* bbPress Admin Tools Reset
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Admin reset page
*
* @since 2.0.0 bbPress (r2613)
*
*/
function bbp_admin_reset_page() {
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
<hr class="wp-header-end">
<h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-reset' ); ?></h2>
<p><?php esc_html_e( 'Revert your forums back to a brand new installation, as if bbPress were never installed. This process cannot be undone.', 'bbpress' ); ?></p>
<form class="settings" method="post" action="">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'The following data will be removed:', 'bbpress' ) ?></th>
<td>
<?php esc_html_e( 'All Forums', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Topics', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Replies', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Topic Tags', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Meta Data', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Settings', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Activity', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum User Roles', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Moderators', 'bbpress' ); ?><br />
<?php esc_html_e( 'Importer Helper Data', 'bbpress' ); ?><br />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Delete imported users?', 'bbpress' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( "Say it ain't so!", 'bbpress' ); ?></span></legend>
<label><input type="checkbox" class="checkbox" name="bbpress-delete-imported-users" id="bbpress-delete-imported-users" value="1" /> <?php esc_html_e( 'This option will delete all previously imported users, and cannot be undone.', 'bbpress' ); ?></label>
<p class="description"><?php esc_html_e( 'Proceeding without this checked removes the meta-data necessary to delete these users later.', 'bbpress' ); ?></p>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Do you really want to do this?', 'bbpress' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( "Say it ain't so!", 'bbpress' ); ?></span></legend>
<label><input type="checkbox" class="checkbox" name="bbpress-are-you-sure" id="bbpress-are-you-sure" value="1" /> <?php esc_html_e( 'This process cannot be undone.', 'bbpress' ); ?></label>
<p class="description"><?php esc_html_e( 'Backup your database before proceeding.', 'bbpress' ); ?></p>
</fieldset>
</td>
</tr>
</tbody>
</table>
<fieldset class="submit">
<input class="button-primary" type="submit" name="submit" value="<?php esc_attr_e( 'Reset bbPress', 'bbpress' ); ?>" />
<?php wp_nonce_field( 'bbpress-reset' ); ?>
</fieldset>
</form>
</div>
<?php
}
/**
* Handle a bbPress admin area reset request.
*
* @since 2.0.0 bbPress (r2613)
*/
function bbp_admin_reset_handler() {
// Bail if not resetting.
if ( ! bbp_is_post_request() || empty( $_POST['bbpress-are-you-sure'] ) ) {
return;
}
// Only keymasters can proceed.
if ( ! bbp_is_user_keymaster() ) {
return;
}
// Bail if not referred from resetter
check_admin_referer( 'bbpress-reset' );
// Reset all of bbPress
bbp_admin_reset_database();
}
/**
* Wrapper for determining admin reset query feedback presented to a user.
*
* @since 2.6.0 bbPress (r6758)
*
* @param array $args Array of query, message, and possible responses
*
* @return string
*/
function bbp_admin_reset_query_feedback( $args = array() ) {
static $defaults = null;
// Only set defaults one time to avoid hitting the GetText API repeatedly
if ( null === $defaults ) {
$defaults = array(
'query' => '',
'message' => esc_html__( 'Resetting&hellip;', 'bbpress' ),
'responses' => array(
'success' => esc_html__( 'Success!', 'bbpress' ),
'failure' => esc_html__( 'Failed!', 'bbpress' ),
'skipped' => esc_html__( 'Skipped.', 'bbpress' )
)
);
}
// Parse arguments
$r = bbp_parse_args( $args, $defaults, 'admin_reset_query_feedback' );
// Success/Failure based on query error
if ( ! empty( $r['query'] ) ) {
$query = bbp_db()->query( $r['query'] );
$result = ! is_wp_error( $query )
? $r['responses']['success']
: $r['responses']['failure'];
// Skip if empty
} else {
$result = $r['responses']['skipped'];
}
// Return feedback
return sprintf( $r['message'], $result );
}
/**
* Perform a bbPress database reset.
*
* @since 2.6.0 bbPress
*/
function bbp_admin_reset_database() {
// Define variables.
$messages = array();
$sql_meta = array();
$bbp_db = bbp_db();
// Flush the whole cache; things are about to get ugly.
wp_cache_flush();
/** Posts *****************************************************************/
// Post types and status.
$fpt = bbp_get_forum_post_type();
$tpt = bbp_get_topic_post_type();
$rpt = bbp_get_reply_post_type();
// Get post IDs
$sql_posts = $bbp_db->get_results( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K );
if ( ! empty( $sql_posts ) ) {
// Meta data
foreach ( $sql_posts as $key => $value ) {
$sql_meta[] = $key;
}
$sql_meta = implode( "', '", $sql_meta );
// Delete posts
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')",
'message' => esc_html__( 'Removing Forums, Topics, and Replies&hellip; %s', 'bbpress' )
) );
/** Post Meta *********************************************************/
if ( ! empty( $sql_posts ) ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}')",
'message' => esc_html__( 'Removing Forum, Topic, and Reply Meta Data&hellip; %s', 'bbpress' )
) );
}
/** Post Revisions ****************************************************/
if ( ! empty( $sql_posts ) ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->posts}` WHERE `post_parent` IN ('{$sql_meta}') AND `post_type` = 'revision'",
'message' => esc_html__( 'Removing Revision Data&hellip; %s', 'bbpress' )
) );
}
}
/** Topic Tags ************************************************************/
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag'",
'message' => esc_html__( 'Deleting Topic Tags&hellip; %s', 'bbpress' )
) );
/** User ******************************************************************/
// First, if we're deleting previously imported users, delete them now
if ( ! empty( $_POST['bbpress-delete-imported-users'] ) ) {
$sql_users = $bbp_db->get_results( "SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_old_user_id'", OBJECT_K );
if ( ! empty( $sql_users ) ) {
$sql_meta = array();
foreach ( $sql_users as $key => $value ) {
$sql_meta[] = $key;
}
// Users
$sql_meta = implode( "', '", $sql_meta );
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}')",
'message' => esc_html__( 'Deleting Imported Users&hellip; %s', 'bbpress' )
) );
// User meta
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}')",
'message' => esc_html__( 'Deleting Imported User Meta&hellip; %s', 'bbpress' )
) );
}
}
// Next, if we still have users that were not imported delete that meta data
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%'",
'message' => esc_html__( 'Deleting bbPress Specific User Meta&hellip; %s', 'bbpress' )
) );
/** Converter *************************************************************/
$table_name = $bbp_db->prefix . 'bbp_converter_translator';
if ( $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DROP TABLE {$table_name}",
'message' => esc_html__( 'Dropping Conversion Table&hellip; %s', 'bbpress' )
) );
}
/** Options ***************************************************************/
bbp_delete_options();
$messages[] = esc_html__( 'Deleting Settings&hellip; Success!', 'bbpress' );
/** Roles *****************************************************************/
bbp_remove_roles();
bbp_remove_caps();
$messages[] = esc_html__( 'Removing Roles and Capabilities&hellip; Success!', 'bbpress' );
/** Output ****************************************************************/
if ( count( $messages ) ) {
foreach ( $messages as $message ) {
bbp_admin_tools_feedback( $message );
}
}
}

View File

@@ -0,0 +1,678 @@
<?php
/**
* bbPress Admin Upgrade Functions
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Admin repair page
*
* @since 2.6.0 bbPress (r6278)
*
*/
function bbp_admin_upgrade_page() {
// Get the registered upgrade tools
$tools = bbp_admin_repair_list( 'upgrade' );
// Orderby
$orderby = ! empty( $_GET['orderby'] )
? sanitize_key( $_GET['orderby'] )
: 'priority';
// Order
$order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
? strtolower( $_GET['order'] )
: 'asc';
// New order
$new_order = ( 'desc' === $order )
? 'asc'
: 'desc'; ?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
<hr class="wp-header-end">
<h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-upgrade' ); ?></h2>
<p><?php esc_html_e( 'As bbPress improves, occasionally database upgrades are required but some forums are too large to upgrade automatically. Use the tools below to manually run upgrade routines.', 'bbpress' ); ?></p>
<p class="description"><?php esc_html_e( 'Some of these tools create substantial database overhead. Use caution when running more than 1 upgrade at a time.', 'bbpress' ); ?></p>
<?php bbp_admin_repair_tool_status_filters(); ?>
<form class="settings" method="get" action="">
<?php bbp_admin_repair_list_search_form(); ?>
<input type="hidden" name="page" value="bbp-upgrade" />
<?php wp_nonce_field( 'bbpress-do-counts' ); ?>
<div class="tablenav top">
<div class="alignleft actions bulkactions">
<label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'bbpress' ); ?></label>
<select name="action" id="bulk-action-selector-top">
<option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'bbpress' ); ?></option>
<option value="run" class="hide-if-no-js"><?php esc_html_e( 'Run', 'bbpress' ); ?></option>
</select>
<input type="submit" id="doaction" class="button action" value="<?php esc_attr_e( 'Apply', 'bbpress' ); ?>">
</div>
<div class="alignleft actions">
<?php bbp_admin_repair_list_components_filter(); ?>
<?php bbp_admin_repair_list_versions_filter(); ?>
<input type="submit" name="filter_action" id="components-submit" class="button" value="<?php esc_html_e( 'Filter', 'bbpress' ); ?>">
</div>
<br class="clear">
</div>
<table class="wp-list-table widefat striped posts">
<thead>
<tr>
<td id="cb" class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-1">
<?php esc_html_e( 'Select All', 'bbpress' ); ?>
</label>
<input id="cb-select-all-1" type="checkbox">
</td>
<th scope="col" id="description" class="manage-column column-primary column-description sortable <?php echo ( 'priority' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'priority',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Description', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
<th scope="col" id="version" class="manage-column column-version sortable <?php echo ( 'version' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'version',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Version', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
<th scope="col" id="components" class="manage-column column-components"><?php esc_html_e( 'Components', 'bbpress' ); ?></th>
<th scope="col" id="overhead" class="manage-column column-overhead sortable <?php echo ( 'overhead' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'overhead',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Overhead', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
</tr>
</thead>
<tbody id="the-list">
<?php if ( ! empty( $tools ) ) : ?>
<?php foreach ( $tools as $item ) : ?>
<tr id="bbp-repair-tools" class="inactive">
<th scope="row" class="check-column">
<label class="screen-reader-text" for="<?php echo esc_attr( str_replace( '_', '-', $item['id'] ) ); ?>"></label>
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $item['id'] ); ?>" id="<?php echo esc_attr( str_replace( '_', '-', $item['id'] ) ); ?>">
</th>
<td class="bbp-tool-title column-primary column-description" data-colname="<?php esc_html_e( 'Description', 'bbpress' ); ?>">
<strong><?php echo esc_html( $item['title'] ); ?></strong><?php
// Optional description
if ( ! empty( $item['description'] ) ) :
echo '<p class="description">' . esc_html( $item['description'] ) . '</p>';
endif;
?><div class="row-actions hide-if-no-js">
<span class="run">
<a href="<?php bbp_admin_repair_tool_run_url( $item ); ?>" aria-label="<?php printf( esc_html__( 'Run %s', 'bbpress' ), $item['title'] ); ?>" id="<?php echo esc_attr( $item['id'] ); ?>" ><?php esc_html_e( 'Run', 'bbpress' ); ?></a>
</span>
</div>
<button type="button" class="toggle-row">
<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'bbpress' ); ?></span>
</button>
</td>
<td class="column-version desc" data-colname="<?php esc_html_e( 'Version', 'bbpress' ); ?>">
<div class="bbp-tool-version">
<?php echo implode( ', ', bbp_get_admin_repair_tool_version( $item ) ); ?>
</div>
</td>
<td class="column-components desc" data-colname="<?php esc_html_e( 'Components', 'bbpress' ); ?>">
<div class="bbp-tool-components">
<?php echo implode( ', ', bbp_get_admin_repair_tool_components( $item ) ); ?>
</div>
</td>
<td class="column-overhead desc" data-colname="<?php esc_html_e( 'Overhead', 'bbpress' ); ?>">
<div class="bbp-tool-overhead">
<?php echo implode( ', ', bbp_get_admin_repair_tool_overhead( $item ) ); ?>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="4">
<?php esc_html_e( 'No repair tools match this criteria.', 'bbpress' ); ?>
</td>
</tr>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<td class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-2">
<?php esc_html_e( 'Select All', 'bbpress' ); ?>
</label>
<input id="cb-select-all-2" type="checkbox">
</td>
<th scope="col" class="manage-column column-primary column-description"><?php esc_html_e( 'Description', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-version"><?php esc_html_e( 'Version', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-components"><?php esc_html_e( 'Components', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-overhead"><?php esc_html_e( 'Overhead', 'bbpress' ); ?></th>
</tr>
</tfoot>
</table>
<div class="tablenav bottom">
<div class="alignleft actions bulkactions">
<label for="bulk-action-selector-bottom" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'bbpress' ); ?></label>
<select name="action2" id="bulk-action-selector-bottom">
<option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'bbpress' ); ?></option>
<option value="run" class="hide-if-no-js"><?php esc_html_e( 'Run', 'bbpress' ); ?></option>
</select>
<input type="submit" id="doaction2" class="button action" value="<?php esc_attr_e( 'Apply', 'bbpress' ); ?>">
</div>
</div>
</form>
</div>
<?php
}
/**
* Upgrade user engagements for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6320)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_engagements() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user engagements&hellip; %s', 'bbpress' );
$result = esc_html__( 'No engagements to upgrade.', 'bbpress' );
// Delete previous engagements
$sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key = '_bbp_engagement'";
if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Post types and statuses
$tpt = bbp_get_topic_post_type();
$rpt = bbp_get_reply_post_type();
$pps = bbp_get_public_status_id();
$cps = bbp_get_closed_status_id();
$sql = "INSERT INTO {$bbp_db->postmeta} (post_id, meta_key, meta_value) (
SELECT postmeta.meta_value, '_bbp_engagement', posts.post_author
FROM {$bbp_db->posts} AS posts
LEFT JOIN {$bbp_db->postmeta} AS postmeta
ON posts.ID = postmeta.post_id
AND postmeta.meta_key = '_bbp_topic_id'
WHERE posts.post_type IN (%s, %s)
AND posts.post_status IN (%s, %s)
GROUP BY postmeta.meta_value, posts.post_author)";
// Run the big query
$prepare = $bbp_db->prepare( $sql, $tpt, $rpt, $pps, $cps );
$engagements = $bbp_db->query( $prepare );
// Bail if no closed topics found
if ( empty( $engagements ) || is_wp_error( $engagements ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Complete results
$result = sprintf( _n( 'Complete! %d engagement upgraded.', 'Complete! %d engagements upgraded.', $engagements, 'bbpress' ), bbp_number_format( $engagements ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade group forum ID mappings after a bbPress 1.x to bbPress 2.x conversion
*
* Previously named: bbp_admin_repair_group_forum_relationships()
*
* @since 2.6.0 bbPress (r4395)
*
* @return If a wp_error() occurs and no converted forums are found
*/
function bbp_admin_upgrade_group_forum_relationships() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading BuddyPress group-forum relationships&hellip; %s', 'bbpress' );
$g_count = 0;
$f_count = 0;
$s_count = 0;
// Copy the BuddyPress filter here, incase BuddyPress is not active
$prefix = apply_filters( 'bp_core_get_table_prefix', $bbp_db->base_prefix );
$groups_table = $prefix . 'bp_groups';
$groups_meta_table = $prefix . 'bp_groups_groupmeta';
// Get the converted forum IDs
$forum_ids = $bbp_db->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value`
FROM `{$bbp_db->posts}` AS `forum`
LEFT JOIN `{$bbp_db->postmeta}` AS `forummeta`
ON `forum`.`ID` = `forummeta`.`post_id`
AND `forummeta`.`meta_key` = '_bbp_old_forum_id'
WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "'
GROUP BY `forum`.`ID`" );
// Bail if forum IDs returned an error
if ( is_wp_error( $forum_ids ) || empty( $bbp_db->last_result ) ) {
return array( 2, sprintf( $statement, esc_html__( 'Failed!', 'bbpress' ) ) );
}
// Stash the last results
$results = $bbp_db->last_result;
// Update each group forum
foreach ( $results as $group_forums ) {
// Only update if is a converted forum
if ( empty( $group_forums->meta_value ) ) {
continue;
}
// Attempt to update group meta
$updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}'" );
// Bump the count
if ( ! empty( $updated ) && ! is_wp_error( $updated ) ) {
++$g_count;
}
// Update group to forum relationship data
$group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}'" );
if ( ! empty( $group_id ) ) {
// Update the group to forum meta connection in forums
update_post_meta( $group_forums->ID, '_bbp_group_ids', array( $group_id ) );
// Get the group status
$group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}'" );
// Sync up forum visibility based on group status
switch ( $group_status ) {
// Public groups have public forums
case 'public' :
bbp_publicize_forum( $group_forums->ID );
// Bump the count for output later
++$s_count;
break;
// Private/hidden groups have hidden forums
case 'private' :
case 'hidden' :
bbp_hide_forum( $group_forums->ID );
// Bump the count for output later
++$s_count;
break;
}
// Bump the count for output later
++$f_count;
}
}
// Make some logical guesses at the old group root forum
if ( function_exists( 'bp_forums_parent_forum_id' ) ) {
$old_default_forum_id = bp_forums_parent_forum_id();
} elseif ( defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
$old_default_forum_id = (int) BP_FORUMS_PARENT_FORUM_ID;
} else {
$old_default_forum_id = 1;
}
// Try to get the group root forum
$posts = get_posts( array(
'post_type' => bbp_get_forum_post_type(),
'meta_key' => '_bbp_old_forum_id',
'meta_type' => 'NUMERIC',
'meta_value' => $old_default_forum_id,
'numberposts' => 1
) );
// Found the group root forum
if ( ! empty( $posts ) ) {
// Rename 'Default Forum' since it's now visible in sitewide forums
if ( 'Default Forum' === $posts[0]->post_title ) {
wp_update_post( array(
'ID' => $posts[0]->ID,
'post_title' => esc_html__( 'Group Forums', 'bbpress' ),
'post_name' => esc_html__( 'group-forums', 'bbpress' ),
) );
}
// Update the group forums root metadata
update_option( '_bbp_group_forums_root_id', $posts[0]->ID );
}
// Remove old bbPress 1.1 roles (BuddyPress)
remove_role( 'member' );
remove_role( 'inactive' );
remove_role( 'blocked' );
remove_role( 'moderator' );
remove_role( 'keymaster' );
// Complete results
$result = sprintf( esc_html__( 'Complete! %s groups updated; %s forums updated; %s forum statuses synced.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ), bbp_number_format( $s_count ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user favorites for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6174)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_favorites() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user favorites&hellip; %s', 'bbpress' );
$result = esc_html__( 'No favorites to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_favorites';
$new_key = '_bbp_favorite';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s";
$prepare = $bbp_db->prepare( $query, $old_key );
$favs = $bbp_db->get_results( $prepare );
// Bail if no closed topics found
if ( empty( $favs ) || is_wp_error( $favs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's favorites
foreach ( $favs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all favorited posts
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $favs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d favorite upgraded.', 'Complete! %d favorites upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user topic subscriptions for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6174)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_topic_subscriptions() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user topic subscriptions&hellip; %s', 'bbpress' );
$result = esc_html__( 'No topic subscriptions to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_subscriptions';
$new_key = '_bbp_subscription';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $old_key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no topic subscriptions found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's topic subscriptions
foreach ( $subs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all subscribed topics
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $subs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d topic subscription upgraded.', 'Complete! %d topic subscriptions upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user forum subscriptions for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6193)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_forum_subscriptions() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user forum subscriptions&hellip; %s', 'bbpress' );
$result = esc_html__( 'No forum subscriptions to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_forum_subscriptions';
$new_key = '_bbp_subscription';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $old_key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum subscriptions found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's forum subscriptions
foreach ( $subs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all subscribed forums
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $subs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d forum subscription upgraded.', 'Complete! %d forum subscriptions upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove favorites data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_favorites_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove favorites from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No favorites to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_favorites';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$favs = $bbp_db->get_results( $prepare );
// Bail if no favorites found
if ( empty( $favs ) || is_wp_error( $favs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $favs );
// Complete results
$result = sprintf( _n( 'Complete! %d favorite deleted.', 'Complete! %d favorites deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove topic subscriptions data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove topic subscriptions from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No topic subscriptions to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_subscriptions';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum favorites found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $subs );
// Complete results
$result = sprintf( _n( 'Complete! %d topic subscription deleted.', 'Complete! %d topic subscriptions deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove topic subscriptions data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove forum subscriptions from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No forum subscriptions to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_forum_subscriptions';
// Query
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum favorites found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $subs );
// Complete results
$result = sprintf( _n( 'Complete! %d forum subscription deleted.', 'Complete! %d forum subscriptions deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,348 @@
<?php
/**
* bbPress Users Admin Class
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Users_Admin' ) ) :
/**
* Loads bbPress users admin area
*
* @package bbPress
* @subpackage Administration
* @since 2.0.0 bbPress (r2464)
*/
class BBP_Users_Admin {
/**
* The bbPress users admin loader
*
* @since 2.0.0 bbPress (r2515)
*/
public function __construct() {
$this->setup_actions();
}
/**
* Setup the admin hooks, actions and filters
*
* @since 2.0.0 bbPress (r2646)
*
* @access private
*/
function setup_actions() {
// Bail if in network admin
if ( is_network_admin() ) {
return;
}
// User profile edit/display actions
add_action( 'edit_user_profile', array( $this, 'secondary_role_display' ) );
// WordPress user screen
// Remvove the bottom list table "change forum role" dropdown from WordPress < 4.6.
// See https://bbpress.trac.wordpress.org/ticket/2906.
if ( bbp_get_major_wp_version() < 4.6 ) {
add_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
} else {
add_action( 'restrict_manage_users', array( $this, 'user_role_bulk_dropdown' ), 10, 1 );
}
add_filter( 'manage_users_columns', array( $this, 'user_role_column' ), 10, 1 );
add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 );
// Only list bbPress roles under Forum Role, remove from WordPress' > 4.4 Site Role list.
if ( bbp_get_major_wp_version() >= 4.4 ) {
add_filter( 'get_role_list', array( $this, 'user_role_list_filter' ), 10, 2 );
}
// User List Table
add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ), 10, 1 );
add_action( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 );
}
/**
* Default interface for setting a forum role
*
* @since 2.2.0 bbPress (r4285)
*
* @param WP_User $profileuser User data
* @return bool Always false
*/
public static function secondary_role_display( $profileuser ) {
// Bail if current user cannot edit users
if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) {
return;
}
// Get the roles
$dynamic_roles = bbp_get_dynamic_roles();
// Only keymasters can set other keymasters
if ( ! bbp_is_user_keymaster() ) {
unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
} ?>
<h2><?php esc_html_e( 'Forums', 'bbpress' ); ?></h2>
<table class="form-table">
<tbody>
<tr>
<th><label for="bbp-forums-role"><?php esc_html_e( 'Forum Role', 'bbpress' ); ?></label></th>
<td>
<?php $user_role = bbp_get_user_role( $profileuser->ID ); ?>
<select name="bbp-forums-role" id="bbp-forums-role">
<?php if ( ! empty( $user_role ) ) : ?>
<option value=""><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'bbpress' ); ?></option>
<?php else : ?>
<option value="" selected="selected"><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'bbpress' ); ?></option>
<?php endif; ?>
<?php foreach ( $dynamic_roles as $role => $details ) : ?>
<option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo bbp_translate_user_role( $details['name'] ); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
</tbody>
</table>
<?php
}
/**
* Add bulk forums role dropdown to the WordPress users table
*
* @since 2.2.0 bbPress (r4360)
* @since 2.6.0 bbPress (r6055) Introduced the `$which` parameter.
*
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
*/
public static function user_role_bulk_dropdown( $which ) {
// Remove the bottom list table "change forum role" dropdown from WordPress < 4.6.
// See https://bbpress.trac.wordpress.org/ticket/2906.
if ( bbp_get_major_wp_version() < 4.6 ) {
remove_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
}
// Bail if current user cannot promote users
if ( ! current_user_can( 'promote_users' ) ) {
return;
}
// Get the roles
$dynamic_roles = bbp_get_dynamic_roles();
// Only keymasters can set other keymasters
if ( ! bbp_is_user_keymaster() ) {
unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
}
$select_id = 'bottom' === $which ? 'bbp-new-role2' : 'bbp-new-role';
$button_id = 'bottom' === $which ? 'bbp-change-role2' : 'bbp-change-role';
?>
<label class="screen-reader-text" for="<?php echo $select_id; ?>"><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></label>
<select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>" style="display:inline-block; float:none;">
<option value=''><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></option>
<?php foreach ( $dynamic_roles as $role => $details ) : ?>
<option value="<?php echo esc_attr( $role ); ?>"><?php echo bbp_translate_user_role( $details['name'] ); ?></option>
<?php endforeach; ?>
</select><?php submit_button( esc_html__( 'Change', 'bbpress' ), 'secondary', $button_id, false );
wp_nonce_field( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
}
/**
* Process bulk dropdown form submission from the WordPress Users
* Table
*
* @since 2.2.0 bbPress (r4365)
*
* @return bool Always false
*/
public function user_role_bulk_change() {
// Bail if no users specified
if ( empty( $_REQUEST['users'] ) ) {
return;
}
// Bail if this isn't a bbPress action
if ( ( empty( $_REQUEST['bbp-new-role'] ) && empty( $_REQUEST['bbp-new-role2'] ) ) || ( empty( $_REQUEST['bbp-change-role'] ) && empty( $_REQUEST['bbp-change-role2'] ) ) ) {
return;
}
$new_role = false;
if ( ! empty( $_REQUEST['bbp-change-role2'] ) && ! empty( $_REQUEST['bbp-new-role2'] ) ) {
$new_role = $_REQUEST['bbp-new-role2'];
} elseif ( ! empty( $_REQUEST['bbp-change-role'] ) && ! empty( $_REQUEST['bbp-new-role'] ) ) {
$new_role = $_REQUEST['bbp-new-role'];
}
// Check that the new role exists
$dynamic_roles = bbp_get_dynamic_roles();
if ( ! $new_role || empty( $dynamic_roles[ $new_role ] ) ) {
return;
}
// Bail if nonce check fails
check_admin_referer( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
// Bail if current user cannot promote users
if ( ! current_user_can( 'promote_users' ) ) {
return;
}
// Get the current user ID
$current_user_id = (int) bbp_get_current_user_id();
// Run through user ids
foreach ( (array) $_REQUEST['users'] as $user_id ) {
$user_id = (int) $user_id;
// Don't let a user change their own role
if ( $user_id === $current_user_id ) {
continue;
}
// Set up user and role data
$user_role = bbp_get_user_role( $user_id );
$new_role = sanitize_text_field( $new_role );
// Only keymasters can set other keymasters
if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ), true ) && ! bbp_is_user_keymaster() ) {
continue;
}
// Set the new forums role
if ( $new_role !== $user_role ) {
bbp_set_user_role( $user_id, $new_role );
}
}
}
/**
* Add a "View" link for each user
*
* @since 2.6.0 bbPress (r6502)
*
* @param array $actions
* @param WP_User $user
*
* @return array Actions with 'view' link added to them
*/
public function user_row_actions( $actions = array(), $user = false ) {
// Reverse
$actions = array_reverse( $actions );
// Add the view action link
$actions['view'] = '<a href="' . esc_url( bbp_get_user_profile_url( $user->ID ) ) . '" class="bbp-user-profile-link">' . esc_html__( 'View', 'bbpress' ) . '</a>';
// Re-reverse
return array_reverse( $actions );
}
/**
* Add Forum Role column to the WordPress Users table, and change the
* core role title to "Site Role"
*
* @since 2.2.0 bbPress (r4337)
*
* @param array $columns Users table columns
* @return array $columns
*/
public static function user_role_column( $columns = array() ) {
// New title for old Role column
$columns['role'] = esc_html__( 'Site Role', 'bbpress' );
// New column
$bbp_user_role = array(
'bbp_user_role' => esc_html__( 'Forum Role', 'bbpress' )
);
// Make sure role columns are next to each other
$role_pos = array_search( 'role', array_keys( $columns ), true );
$result = array_slice( $columns, 0, $role_pos + 1 );
$result = array_merge( $result, $bbp_user_role );
// Merge and return
return array_merge( $result, array_slice( $columns, $role_pos ) );
}
/**
* Return user's forums role for display in the WordPress Users list table
*
* @since 2.2.0 bbPress (r4337)
*
* @param string $retval
* @param string $column_name
* @param int $user_id
*
* @return string Displayable bbPress user role
*/
public static function user_role_row( $retval = '', $column_name = '', $user_id = 0 ) {
// User role column
if ( 'bbp_user_role' === $column_name ) {
// Get the users role
$user_role = bbp_get_user_role( $user_id );
$retval = false;
// Translate user role for display
if ( ! empty( $user_role ) ) {
$roles = bbp_get_dynamic_roles();
$retval = bbp_translate_user_role( $roles[ $user_role ]['name'] );
}
}
// Pass retval through
return $retval;
}
/**
* Filter the list of roles included in the WordPress site role list
*
* Ensures forum roles are only displayed under the Forum Role list in the
* WordPress Users list table
*
* @since 2.6.0 bbPress (r6051)
*
* @return array $roles
*/
public static function user_role_list_filter( $roles, $user ) {
// Get the users role
$user_role = bbp_get_user_role( $user->ID );
if ( ! empty( $user_role ) ) {
unset( $roles[ $user_role ] );
}
return $roles;
}
}
new BBP_Users_Admin();
endif; // class exists

View File

@@ -0,0 +1,159 @@
<?php
/**
* bbPress Common AJAX Functions
*
* Common AJAX functions are ones that are used to setup and/or use during
* bbPress specific, theme-side AJAX requests.
*
* @package bbPress
* @subpackage Ajax
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Output the URL to use for theme-side bbPress AJAX requests
*
* @since 2.3.0 bbPress (r4543)
*/
function bbp_ajax_url() {
echo esc_url( bbp_get_ajax_url() );
}
/**
* Return the URL to use for theme-side bbPress AJAX requests
*
* @since 2.3.0 bbPress (r4543)
*
* @global WP $wp
* @return string
*/
function bbp_get_ajax_url() {
global $wp;
$ssl = bbp_get_url_scheme();
$url = trailingslashit( $wp->request );
$base_url = home_url( $url, $ssl );
$ajaxurl = add_query_arg( array( 'bbp-ajax' => 'true' ), $base_url );
// Filter & return
return apply_filters( 'bbp_get_ajax_url', $ajaxurl );
}
/**
* Is this a bbPress AJAX request?
*
* @since 2.3.0 bbPress (r4543)
*
* @return bool Looking for bbp-ajax
*/
function bbp_is_ajax() {
return (bool) ( ( isset( $_GET['bbp-ajax'] ) || isset( $_POST['bbp-ajax'] ) ) && ! empty( $_REQUEST['action'] ) );
}
/**
* Hooked to the 'bbp_template_redirect' action, this is also the custom
* theme-side AJAX handler.
*
* This is largely taken from admin-ajax.php, but adapted specifically for
* theme-side bbPress-only AJAX requests.
*
* @since 2.3.0 bbPress (r4543)
*
* @param string $action Sanitized action from bbp_post_request/bbp_get_request
*
* @return If not a bbPress AJAX request
*/
function bbp_do_ajax( $action = '' ) {
// Bail if not a bbPress specific AJAX request
if ( ! bbp_is_ajax() ) {
return;
}
// Set WordPress core AJAX constant for back-compat
if ( ! defined( 'DOING_AJAX' ) ) {
define( 'DOING_AJAX', true );
}
// Setup AJAX headers
bbp_ajax_headers();
// Compat for targeted action hooks (without $action param)
$action = empty( $action )
? sanitize_key( $_REQUEST['action'] ) // isset checked by bbp_is_ajax()
: $action;
// Setup action key
$key = "bbp_ajax_{$action}";
// Bail if no action is registered
if ( empty( $action ) || ! has_action( $key ) ) {
wp_die( '0', 400 );
}
// Everything is 200 OK.
bbp_set_200();
// Execute custom bbPress AJAX action
do_action( $key );
// All done
wp_die( '0' );
}
/**
* Send headers for AJAX specific requests
*
* This was abstracted from bbp_do_ajax() for use in custom theme-side AJAX
* implementations.
*
* @since 2.6.0 bbPress (r6757)
*/
function bbp_ajax_headers() {
// Set the header content type
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
@header( 'X-Robots-Tag: noindex' );
// Disable content sniffing in browsers that support it
send_nosniff_header();
// Disable browser caching for all AJAX requests
nocache_headers();
}
/**
* Helper method to return JSON response for bbPress AJAX calls
*
* @since 2.3.0 bbPress (r4542)
*
* @param bool $success
* @param string $content
* @param array $extras
*/
function bbp_ajax_response( $success = false, $content = '', $status = -1, $extras = array() ) {
// Set status to 200 if setting response as successful
if ( ( true === $success ) && ( -1 === $status ) ) {
$status = 200;
}
// Setup the response array
$response = array(
'success' => $success,
'status' => $status,
'content' => $content
);
// Merge extra response parameters in
if ( ! empty( $extras ) && is_array( $extras ) ) {
$response = array_merge( $response, $extras );
}
// Send back the JSON
@header( 'Content-type: application/json' );
echo json_encode( $response );
die();
}

View File

@@ -0,0 +1,511 @@
<?php
/**
* bbPress Classes
*
* @package bbPress
* @subpackage Classes
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Component' ) ) :
/**
* bbPress Component Class
*
* The bbPress component class is responsible for simplifying the creation
* of components that share similar behaviors and routines. It is used
* internally by bbPress to create forums, topics and replies, but can be
* extended to create other really neat things.
*
* @package bbPress
* @subpackage Classes
*
* @since 2.0.0 bbPress (r2688)
*/
class BBP_Component {
/**
* @var string Unique name (for internal identification)
* @internal
*/
var $name;
/**
* @var Unique ID (normally for custom post type)
*/
var $id;
/**
* @var string Unique slug (used in query string and permalinks)
*/
var $slug;
/**
* @var WP_Query The loop for this component
*/
var $query;
/**
* @var string The current ID of the queried object
*/
var $current_id;
/** Methods ***************************************************************/
/**
* bbPress Component loader
*
* @since 2.0.0 bbPress (r2700)
*
* @param array $args Required. Supports these args:
* - name: Unique name (for internal identification)
* - id: Unique ID (normally for custom post type)
* - slug: Unique slug (used in query string and permalinks)
* - query: The loop for this component (WP_Query)
* - current_id: The current ID of the queried object
*/
public function __construct( $args = array() ) {
if ( empty( $args ) ) {
return;
}
$this->setup_globals( $args );
$this->includes();
$this->setup_actions();
}
/**
* Component global variables
*
* @since 2.0.0 bbPress (r2700)
*
* @access private
*/
private function setup_globals( $args = array() ) {
$this->name = $args['name'];
$this->id = apply_filters( 'bbp_' . $this->name . '_id', $args['id'] );
$this->slug = apply_filters( 'bbp_' . $this->name . '_slug', $args['slug'] );
}
/**
* Include required files
*
* @since 2.0.0 bbPress (r2700)
*
* @access private
*/
private function includes() {
do_action( 'bbp_' . $this->name . 'includes' );
}
/**
* Setup the actions
*
* @since 2.0.0 bbPress (r2700)
*
* @access private
*/
private function setup_actions() {
add_action( 'bbp_register_post_types', array( $this, 'register_post_types' ), 10, 2 ); // Register post types
add_action( 'bbp_register_taxonomies', array( $this, 'register_taxonomies' ), 10, 2 ); // Register taxonomies
add_action( 'bbp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10, 2 ); // Add the rewrite tags
add_action( 'bbp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10, 2 ); // Generate rewrite rules
// Additional actions can be attached here
do_action( 'bbp_' . $this->name . 'setup_actions' );
}
/**
* Setup the component post types
*
* @since 2.0.0 bbPress (r2700)
*/
public function register_post_types() {
do_action( 'bbp_' . $this->name . '_register_post_types' );
}
/**
* Register component specific taxonomies
*
* @since 2.0.0 bbPress (r2700)
*/
public function register_taxonomies() {
do_action( 'bbp_' . $this->name . '_register_taxonomies' );
}
/**
* Add any additional rewrite tags
*
* @since 2.0.0 bbPress (r2700)
*/
public function add_rewrite_tags() {
do_action( 'bbp_' . $this->name . '_add_rewrite_tags' );
}
/**
* Generate any additional rewrite rules
*
* @since 2.0.0 bbPress (r2700)
*/
public function generate_rewrite_rules( $wp_rewrite ) {
do_action_ref_array( 'bbp_' . $this->name . '_generate_rewrite_rules', $wp_rewrite );
}
}
endif; // BBP_Component
if ( class_exists( 'Walker' ) ) :
/**
* Create HTML dropdown list of bbPress forums/topics.
*
* @package bbPress
* @subpackage Classes
*
* @since 2.0.0 bbPress (r2746)
*/
class BBP_Walker_Dropdown extends Walker {
/**
* @see Walker::$tree_type
*
* @since 2.0.0 bbPress (r2746)
*
* @var string
*/
public $tree_type = 'forum';
/**
* @see Walker::$db_fields
*
* @since 2.0.0 bbPress (r2746)
*
* @var array
*/
public $db_fields = array(
'parent' => 'post_parent',
'id' => 'ID'
);
/** Methods ***************************************************************/
/**
* Set the tree_type
*
* @since 2.0.0 bbPress (r2746)
*/
public function __construct() {
$this->tree_type = bbp_get_forum_post_type();
}
/**
* @see Walker::start_el()
*
* @since 2.0.0 bbPress (r2746)
*
* @param string $output Passed by reference. Used to append additional
* content.
* @param object $object Post data object.
* @param int $depth Depth of post in reference to parent posts. Used
* for padding.
* @param array $args Uses 'selected' argument for selected post to set
* selected HTML attribute for option element.
* @param int $current_object_id
*/
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
$pad = str_repeat( '&nbsp;', (int) $depth * 3 );
$output .= '<option class="level-' . (int) $depth . '"';
// Disable the <option> if:
// - we're told to do so
// - the post type is a forum
// - the forum is a category
// - forum is closed
if ( ( true === $args['disable_categories'] )
&& ( bbp_get_forum_post_type() === $object->post_type )
&& ( bbp_is_forum_category( $object->ID )
|| ( ! current_user_can( 'edit_forum', $object->ID ) && bbp_is_forum_closed( $object->ID )
)
) ) {
$output .= ' disabled="disabled" value=""';
} else {
$output .= ' value="' . (int) $object->ID .'"' . selected( $args['selected'], $object->ID, false );
}
$output .= '>';
$title = apply_filters( 'bbp_walker_dropdown_post_title', $object->post_title, $output, $object, $depth, $args );
$output .= $pad . esc_html( $title );
$output .= "</option>\n";
}
}
/**
* Create hierarchical list of bbPress replies.
*
* @package bbPress
* @subpackage Classes
*
* @since 2.4.0 bbPress (r4944)
*/
class BBP_Walker_Reply extends Walker {
/**
* @see Walker::$tree_type
*
* @since 2.4.0 bbPress (r4944)
*
* @var string
*/
public $tree_type = 'reply';
/**
* @see Walker::$db_fields
*
* @since 2.4.0 bbPress (r4944)
*
* @var array
*/
public $db_fields = array(
'parent' => 'reply_to',
'id' => 'ID'
);
/**
* Confirm the tree_type
*
* @since 2.6.0 bbPress (r5389)
*/
public function __construct() {
$this->tree_type = bbp_get_reply_post_type();
}
/**
* @see Walker::start_lvl()
*
* @since 2.4.0 bbPress (r4944)
*
* @param string $output Passed by reference. Used to append additional content
* @param int $depth Depth of reply
* @param array $args Uses 'style' argument for type of HTML list
*/
public function start_lvl( &$output = '', $depth = 0, $args = array() ) {
bbpress()->reply_query->reply_depth = (int) $depth + 1;
switch ( $args['style'] ) {
case 'div':
break;
case 'ol':
$output .= "<ol class='bbp-threaded-replies'>\n";
break;
case 'ul':
default:
$output .= "<ul class='bbp-threaded-replies'>\n";
break;
}
}
/**
* @see Walker::end_lvl()
*
* @since 2.4.0 bbPress (r4944)
*
* @param string $output Passed by reference. Used to append additional content
* @param int $depth Depth of reply
* @param array $args Will only append content if style argument value is 'ol' or 'ul'
*/
public function end_lvl( &$output = '', $depth = 0, $args = array() ) {
bbpress()->reply_query->reply_depth = (int) $depth + 1;
switch ( $args['style'] ) {
case 'div':
break;
case 'ol':
$output .= "</ol>\n";
break;
case 'ul':
default:
$output .= "</ul>\n";
break;
}
}
/**
* @since 2.4.0 bbPress (r4944)
*/
public function display_element( $element = false, &$children_elements = array(), $max_depth = 0, $depth = 0, $args = array(), &$output = '' ) {
if ( empty( $element ) ) {
return;
}
// Get element's id
$id_field = $this->db_fields['id'];
$id = $element->$id_field;
// Display element
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
// If we're at the max depth and the current element still has children, loop over those
// and display them at this level to prevent them being orphaned to the end of the list.
if ( ( $max_depth <= (int) $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
foreach ( $children_elements[ $id ] as $child ) {
$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
}
unset( $children_elements[ $id ] );
}
}
/**
* @see Walker:start_el()
*
* @since 2.4.0 bbPress (r4944)
*/
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Set up reply
$depth++;
bbpress()->reply_query->reply_depth = (int) $depth;
bbpress()->reply_query->post = $object;
bbpress()->current_reply_id = $object->ID;
// Check for a callback and use it if specified
if ( ! empty( $args['callback'] ) ) {
ob_start();
call_user_func( $args['callback'], $object, $args, $depth );
$output .= ob_get_clean();
return;
}
// Style for div or list element
if ( ! empty( $args['style'] ) && ( 'div' === $args['style'] ) ) {
$output .= "<div>\n";
} else {
$output .= "<li>\n";
}
$output .= bbp_buffer_template_part( 'loop', 'single-reply', false );
}
/**
* @since 2.4.0 bbPress (r4944)
*/
public function end_el( &$output = '', $object = false, $depth = 0, $args = array() ) {
// Check for a callback and use it if specified
if ( ! empty( $args['end-callback'] ) ) {
ob_start();
call_user_func( $args['end-callback'], $object, $args, $depth );
$output .= ob_get_clean();
return;
}
// Style for div or list element
if ( ! empty( $args['style'] ) && ( 'div' === $args['style'] ) ) {
$output .= "</div>\n";
} else {
$output .= "</li>\n";
}
}
}
/**
* Create HTML dropdown list of bbPress replies.
*
* @package bbPress
* @subpackage Classes
*
* @since 2.6.0 bbPress (r5389)
*/
class BBP_Walker_Reply_Dropdown extends Walker {
/**
* @see Walker::$tree_type
*
* @since 2.6.0 bbPress (r5389)
*
* @var string
*/
public $tree_type = 'reply';
/**
* @see Walker::$db_fields
*
* @since 2.6.0 bbPress (r5389)
*
* @var array
*/
public $db_fields = array(
'parent' => 'reply_to',
'id' => 'ID'
);
/** Methods ***************************************************************/
/**
* Confirm the tree_type
*
* @since 2.6.0 bbPress (r5389)
*/
public function __construct() {
$this->tree_type = bbp_get_reply_post_type();
}
/**
* @see Walker::start_el()
*
* @since 2.6.0 bbPress (r5389)
*
* @param string $output Passed by reference. Used to append additional
* content.
*
* @param object $object Post data object.
*
* @param int $depth Depth of post in reference to parent posts. Used
* for padding.
*
* @param array $args Uses 'selected' argument for selected post to set
* selected HTML attribute for option element.
*
* @param int $current_object_id Not Used
*/
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Set up reply
$depth++;
// Get the reply ID
if ( isset( $args['exclude'][0] ) ) {
$reply_id = (int) $args['exclude'][0];
} else {
$reply_id = bbp_get_reply_id();
}
// Get ancestors to determine which items to disable
$ancestors = bbp_get_reply_ancestors( $object->ID );
array_push( $ancestors, $object->ID );
// Determine the indentation
$pad = str_repeat( '&nbsp;', (int) $depth * 3 );
// Determine reply title (either post_title, or excerpt of post_content)
$title = ! empty( $object->post_title ) ? $object->post_title : wp_html_excerpt( $object->post_content, 10 );
$title = sprintf( esc_html__( '%1$s - %2$s', 'bbpress' ), (int) $object->ID, $title );
$title = apply_filters( 'bbp_walker_dropdown_post_title', $title, $output, $object, $depth, $args );
// Attributes
$class = 'level-' . (int) $depth;
$value = (int) $object->ID;
// Start an output buffer to make late escaping easier
ob_start(); ?>
<option class="<?php echo esc_attr( $class ); ?>" value="<?php echo esc_attr( $value ); ?>"<?php selected( $args['selected'], $object->ID ); ?> <?php disabled( in_array( $reply_id, $ancestors ), true ); ?>><?php echo $pad . esc_html( $title ); ?></option>
<?php
// Append the output buffer to the $output variable
$output .= ob_get_clean();
}
}
endif; // class_exists check

View File

@@ -0,0 +1,963 @@
<?php
/**
* bbPress Common Engagements
*
* This file contains the common classes and functions for interacting with the
* bbPress engagements API. See `includes/users/engagements.php` for more.
*
* @package bbPress
* @subpackage Common
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Return the strategy used for storing user engagements
*
* @since 2.6.0 bbPress (r6722)
*
* @param string $rel_key The key used to index this relationship
* @param string $rel_type The type of meta to look in
*
* @return string
*/
function bbp_user_engagements_interface( $rel_key = '', $rel_type = 'post' ) {
return apply_filters( 'bbp_user_engagements_interface', bbpress()->engagements, $rel_key, $rel_type );
}
/**
* Base strategy class for interfacing with User Engagements, which other
* classes will extend.
*
* @since 2.6.0 bbPress (r6722)
*/
class BBP_User_Engagements_Base {
/**
* Type of strategy being used.
*
* @since 2.6.0 bbPress (r6737)
*
* @var string
*/
public $type = '';
/**
* Add a user id to an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
* @param bool $unique Whether meta key should be unique to the object
*
* @return bool Returns true on success, false on failure
*/
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
}
/**
* Remove a user id from an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
}
/**
* Remove a user id from all objects
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
}
/**
* Remove an object from all users
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
}
/**
* Remove all users from all objects
*
* @since 2.6.0 bbPress (r6722)
*
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
}
/**
* Get users of an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param string $meta_key The key used to index this relationship
* @param string $meta_type The type of meta to look in
*
* @return array Returns ids of users
*/
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
}
/**
* Get the part of the query responsible for JOINing objects to relationships.
*
* @since 2.6.0 bbPress (r6737)
*
* @param array $args
* @param string $meta_key
* @param string $meta_type
*
* @return array
*/
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
}
}
/**
* Meta strategy for interfacing with User Engagements
*
* @since 2.6.0 bbPress (r6722)
*/
class BBP_User_Engagements_Meta extends BBP_User_Engagements_Base {
/**
* Type of strategy being used.
*
* @since 2.6.0 bbPress (r6737)
*
* @var string
*/
public $type = 'meta';
/**
* Add a user id to an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
* @param bool $unique Whether meta key should be unique to the object
*
* @return bool Returns true on success, false on failure
*/
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
return add_metadata( $meta_type, $object_id, $meta_key, $user_id, $unique );
}
/**
* Remove a user id from an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
return delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
}
/**
* Remove a user id from all objects
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
return delete_metadata( $meta_type, null, $meta_key, $user_id, true );
}
/**
* Remove an object from all users
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
return delete_metadata( $meta_type, $object_id, $meta_key, null, false );
}
/**
* Remove all users from all objects
*
* @since 2.6.0 bbPress (r6722)
*
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
return delete_metadata( $meta_type, null, $meta_key, null, true );
}
/**
* Get users of an object
*
* @since 2.6.0 bbPress (r6722)
*
* @param int $object_id The object id
* @param string $meta_key The key used to index this relationship
* @param string $meta_type The type of meta to look in
*
* @return array Returns ids of users
*/
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
return wp_parse_id_list( get_metadata( $meta_type, $object_id, $meta_key, false ) );
}
/**
* Get the part of the query responsible for JOINing objects to relationships.
*
* @since 2.6.0 bbPress (r6737)
*
* @param array $args
* @param string $meta_key
* @param string $meta_type
*
* @return array
*/
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
// Backwards compat for pre-2.6.0
if ( is_numeric( $args ) ) {
$args = array(
'meta_query' => array( array(
'key' => $meta_key,
'value' => bbp_get_user_id( $args, false, false ),
'compare' => 'NUMERIC'
) )
);
}
// Default arguments
$defaults = array(
'meta_query' => array( array(
'key' => $meta_key,
'value' => bbp_get_displayed_user_id(),
'compare' => 'NUMERIC'
) )
);
// Parse arguments
return bbp_parse_args( $args, $defaults, $context_key );
}
}
/**
* Term strategy for interfacing with User Engagements
*
* @since 2.6.0 bbPress (r6737)
*/
class BBP_User_Engagements_Term extends BBP_User_Engagements_Base {
/**
* Type of strategy being used.
*
* @since 2.6.0 bbPress (r6737)
*
* @var string
*/
public $type = 'term';
/**
* Register an engagement taxonomy just-in-time for immediate use
*
* @since 2.6.0 bbPress (r6737)
*
* @param string $tax_key
* @param string $object_type
*/
private function jit_taxonomy( $tax_key = '', $object_type = 'user' ) {
// Bail if taxonomy already exists
if ( taxonomy_exists( $tax_key ) ) {
return;
}
// Register the taxonomy
register_taxonomy( $tax_key, 'bbp_' . $object_type, array(
'labels' => array(),
'description' => '',
'public' => false,
'publicly_queryable' => false,
'hierarchical' => false,
'show_ui' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'show_in_quick_edit' => false,
'show_admin_column' => false,
'meta_box_cb' => false,
'capabilities' => array(),
'rewrite' => false,
'query_var' => '',
'update_count_callback' => '',
'show_in_rest' => false,
'rest_base' => false,
'rest_controller_class' => false,
'_builtin' => false
) );
}
/**
* Add a user id to an object
*
* @since 2.6.0 bbPress (r6737)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
* @param bool $unique Whether meta key should be unique to the object
*
* @return bool Returns true on success, false on failure
*/
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
$user_key = "{$meta_key}_user_id_{$user_id}";
$tax_key = "{$meta_key}_{$meta_type}";
$this->jit_taxonomy( $tax_key );
return wp_add_object_terms( $object_id, $user_key, $tax_key );
}
/**
* Remove a user id from an object
*
* @since 2.6.0 bbPress (r6737)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
$user_key = "{$meta_key}_user_id_{$user_id}";
$tax_key = "{$meta_key}_{$meta_type}";
$this->jit_taxonomy( $tax_key );
return wp_remove_object_terms( $object_id, $user_key, $tax_key );
}
/**
* Remove a user id from all objects
*
* @since 2.6.0 bbPress (r6737)
*
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
$user_key = "{$meta_key}_user_id_{$user_id}";
$tax_key = "{$meta_key}_{$meta_type}";
$this->jit_taxonomy( $tax_key );
$term = get_term_by( 'slug', $user_key, $tax_key );
return wp_delete_term( $term->term_id, $tax_key );
}
/**
* Remove an object from all users
*
* @since 2.6.0 bbPress (r6737)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
return wp_delete_object_term_relationships( $object_id, get_object_taxonomies( 'bbp_user' ) );
}
/**
* Remove all users from all objects
*
* @since 2.6.0 bbPress (r6737)
*
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
// TODO
}
/**
* Get users of an object
*
* @since 2.6.0 bbPress (r6737)
*
* @param int $object_id The object id
* @param string $meta_key The key used to index this relationship
* @param string $meta_type The type of meta to look in
*
* @return array Returns ids of users
*/
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
$user_key = "{$meta_key}_user_id_";
$tax_key = "{$meta_key}_{$meta_type}";
$this->jit_taxonomy( $tax_key );
// Get terms
$terms = get_terms( array(
'object_ids' => $object_id,
'taxonomy' => $tax_key
) );
// Slug part to replace
$user_ids = array();
// Loop through terms and get the user ID
foreach ( $terms as $term ) {
$user_ids[] = str_replace( $user_key, '', $term->slug );
}
// Parse & return
return wp_parse_id_list( $user_ids );
}
/**
* Get the part of the query responsible for JOINing objects to relationships.
*
* @since 2.6.0 bbPress (r6737)
*
* @param array $args
* @param string $meta_key
* @param string $meta_type
*
* @return array
*/
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
$tax_key = "{$meta_key}_{$meta_type}";
$user_key = "{$meta_key}_user_id_";
// Make sure the taxonomy is registered
$this->jit_taxonomy( $tax_key );
// Backwards compat for pre-2.6.0
if ( is_numeric( $args ) ) {
$args = array(
'tax_query' => array( array(
'taxonomy' => $tax_key,
'terms' => $user_key . bbp_get_user_id( $args, false, false ),
'field' => 'slug'
) )
);
}
// Default arguments
$defaults = array(
'tax_query' => array( array(
'taxonomy' => $tax_key,
'terms' => $user_key . bbp_get_displayed_user_id(),
'field' => 'slug'
) )
);
// Parse arguments
return bbp_parse_args( $args, $defaults, $context_key );
}
}
/**
* User strategy for interfacing with User Engagements
*
* This strategy largely exists for backwards compatibility with bbPress 2.5,
* or installations that have not upgraded their databases to 2.6 or above.
*
* Note: this strategy is going to be a bit less tidy than the others, because
* it needs to do weird things to maintain the 2.5 status-quo. Do not use this
* strategy as an example when building your own.
*
* @since 2.6.0 bbPress (r6844)
*/
class BBP_User_Engagements_User extends BBP_User_Engagements_Base {
/**
* Type of strategy being used.
*
* @since 2.6.0 bbPress (r6844)
*
* @var string
*/
public $type = 'user';
/**
* Private function to map 2.6 meta keys to 2.5 user-option keys.
*
* @since 2.6.0 bbPress (r6844)
*
* @param string $meta_key
* @param int $object_id
* @param bool $prefix
*
* @return string
*/
private function get_user_option_key( $meta_key = '', $object_id = 0, $prefix = false ) {
switch ( $meta_key ) {
// Favorites
case '_bbp_favorite' :
$key = '_bbp_favorites';
break;
// Subscriptions
case '_bbp_subscription' :
// Maybe guess at post type
$post_type = ! empty( $object_id )
? get_post_type( $object_id )
: bbp_get_topic_post_type();
// Forums & Topics used different keys :/
$key = ( bbp_get_forum_post_type() === $post_type )
? '_bbp_forum_subscriptions'
: '_bbp_subscriptions';
break;
// Unknown, so pluralize
default :
$key = "{$meta_key}s";
break;
}
// Maybe prefix the key (for use in raw database queries)
if ( true === $prefix ) {
$key = bbp_db()->get_blog_prefix() . $key;
}
// Return the old (pluralized) user option key
return $key;
}
/**
* Private function to get a 2.5 compatible cache key.
*
* This method exists to provide backwards compatibility with bbPress 2.5,
* which had caching surrounding the FIND_IN_SET usermeta queries.
*
* @since 2.6.3 bbPress (r6991)
*
* @param string $meta_key
* @param int $object_id
*
* @return string
*/
private function get_cache_key( $meta_key = '', $object_id = 0 ) {
// No negative numbers in cache keys (zero is weird, but not disallowed)
$object_id = absint( $object_id );
// Maybe guess at post type
$post_type = ! empty( $object_id )
? get_post_type( $object_id )
: bbp_get_topic_post_type();
switch ( $meta_key ) {
// Favorites
case '_bbp_favorite' :
$key = 'bbp_get_topic_favoriters_';
break;
// Subscriptions
case '_bbp_subscription' :
// Forums & Topics used different keys :/
$key = ( bbp_get_forum_post_type() === $post_type )
? 'bbp_get_forum_subscribers_'
: 'bbp_get_topic_subscribers_';
break;
// Unknown, so pluralize
default :
$nounize = rtrim( $meta_key, 'e' );
$key = "bbp_get_{$post_type}_{$nounize}ers_";
break;
}
// Return the old (pluralized) user option key with object ID appended
return "{$key}{$object_id}";
}
/**
* Get the user engagement cache for a given meta key and object ID.
*
* This method exists to provide backwards compatibility with bbPress 2.5,
* which had caching surrounding the FIND_IN_SET queries in usermeta.
*
* @since 2.6.3 bbPress (r6991)
*
* @param string $meta_key
* @param int $object_id
*
* @return mixed Results from cache get
*/
private function cache_get( $meta_key = '', $object_id = 0 ) {
$cache_key = $this->get_cache_key( $meta_key, $object_id );
return wp_cache_get( $cache_key, 'bbpress_engagements' );
}
/**
* Set the user engagement cache for a given meta key and object ID.
*
* This method exists to provide backwards compatibility with bbPress 2.5,
* which had caching surrounding the FIND_IN_SET queries in usermeta.
*
* @since 2.6.3 bbPress (r6991)
*
* @param string $meta_key
* @param int $object_id
*
* @return mixed Results from cache set
*/
private function cache_set( $meta_key = '', $object_id = 0, $user_ids = array() ) {
$cache_key = $this->get_cache_key( $meta_key, $object_id );
$user_ids = $this->parse_comma_list( $user_ids );
return wp_cache_set( $cache_key, $user_ids, 'bbpress_engagements' );
}
/**
* Delete the user engagement cache for a given meta key and object ID.
*
* This method exists to provide backwards compatibility with bbPress 2.5,
* which had caching surrounding the FIND_IN_SET queries in usermeta.
*
* @since 2.6.3 bbPress (r6991)
*
* @param string $meta_key
* @param int $object_id
*
* @return mixed Results from cache delete
*/
private function cache_delete( $meta_key = '', $object_id = 0 ) {
$cache_key = $this->get_cache_key( $meta_key, $object_id );
return wp_cache_delete( $cache_key, 'bbpress_engagements' );
}
/**
* Turn a comma-separated string into an array of integers
*
* @since 2.6.0 bbPress (r6844)
*
* @param string $results
* @return array
*/
private function parse_comma_list( $results = '' ) {
return array_filter( wp_parse_id_list( $results ) );
}
/**
* Add a user id to an object
*
* @since 2.6.0 bbPress (r6844)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
* @param bool $unique Whether meta key should be unique to the object
*
* @return bool Returns true on success, false on failure
*/
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
$retval = false;
$option_key = $this->get_user_option_key( $meta_key, $object_id );
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
$exists = array_search( $object_id, $object_ids );
// Not already added, so add it
if ( false === $exists ) {
$object_ids[] = $object_id;
$object_ids = implode( ',', $this->parse_comma_list( $object_ids ) );
$retval = update_user_option( $user_id, $option_key, $object_ids );
// Delete cache if successful (accounts for int & true)
if ( false !== $retval ) {
$this->cache_delete( $meta_key, $object_id );
}
}
// Return true if added, or false if not
return $retval;
}
/**
* Remove a user id from an object
*
* @since 2.6.0 bbPress (r6844)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
$retval = false;
$option_key = $this->get_user_option_key( $meta_key, $object_id );
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
$exists = array_search( $object_id, $object_ids );
// Exists, so remove it
if ( false !== $exists ) {
unset( $object_ids[ $exists ] );
$object_ids = implode( ',', $this->parse_comma_list( $object_ids ) );
$retval = ! empty( $object_ids )
? update_user_option( $user_id, $option_key, $object_ids )
: delete_user_option( $user_id, $option_key );
// Delete cache if successful (accounts for int & true)
if ( false !== $retval ) {
$this->cache_delete( $meta_key, $object_id );
}
}
// Return true if removed, or false if not
return $retval;
}
/**
* Remove a user id from all objects
*
* @since 2.6.0 bbPress (r6844)
*
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
// Get the key
$option_key = $this->get_user_option_key( $meta_key );
// Get the option
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
// Attempt to delete the user option
$retval = delete_user_option( $user_id, $option_key );
// Try to delete caches, but only if everything else succeeded
if ( ! empty( $retval ) && ! empty( $object_ids ) ) {
foreach ( $object_ids as $object_id ) {
$this->cache_delete( $meta_key, $object_id );
}
}
// Return true if user was removed, or false if not
return $retval;
}
/**
* Remove an object from all users
*
* @since 2.6.0 bbPress (r6844)
*
* @param int $object_id The object id
* @param int $user_id The user id
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
// Query for users
$user_ids = $this->get_users_for_object( $object_id, $meta_key, $meta_type );
$u_count = count( $user_ids );
// Count number of removals
$removed = array();
$r_count = 0;
// Users have engaged, so remove them
if ( ! empty( $u_count ) ) {
// Loop through users and remove them from the object
foreach ( $user_ids as $user_id ) {
$removed[] = $this->remove_user_from_object( $object_id, $user_id, $meta_key, $meta_type );
}
// Count the removed users
$r_count = count( $removed );
}
// Return true if successfully removed from all users
return ( $r_count === $u_count );
}
/**
* Remove all users from all objects
*
* @since 2.6.0 bbPress (r6844)
*
* @param string $meta_key The relationship key
* @param string $meta_type The relationship type (usually 'post')
*
* @return bool Returns true on success, false on failure
*/
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
// Query for users
$option_key = $this->get_user_option_key( $meta_key, 0, true );
$bbp_db = bbp_db();
$user_ids = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$option_key}'" );
$u_count = count( $user_ids );
// Count number of removals
$removed = array();
$r_count = 0;
// Users have engaged, so remove them
if ( ! empty( $u_count ) ) {
// Loop through users and remove their user options
foreach ( $user_ids as $user_id ) {
$removed[] = $this->remove_user_from_all_objects( $user_id, $meta_key );
}
// Count the removed users
$r_count = count( $removed );
}
// Return true if successfully removed from all users
return ( $r_count === $u_count );
}
/**
* Get users of an object
*
* The database queries in this function were cached in bbPress versions
* older than 2.6, but no longer are to avoid cache pollution.
*
* @since 2.6.0 bbPress (r6844)
*
* @param int $object_id The object id
* @param string $meta_key The key used to index this relationship
* @param string $meta_type The type of meta to look in
*
* @return array Returns ids of users
*/
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
// Try to get user IDs from cache
$user_ids = $this->cache_get( $meta_key, $object_id );
// Cache is empty, so hit the database
if ( false === $user_ids ) {
$option_key = $this->get_user_option_key( $meta_key, $object_id, true );
$bbp_db = bbp_db();
$user_ids = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$option_key}' and FIND_IN_SET('{$object_id}', meta_value) > 0" );
// Always cache results (even if empty, to prevent multiple misses)
$this->cache_set( $meta_key, $object_id, $user_ids );
}
// Return parsed IDs
return $this->parse_comma_list( $user_ids );
}
/**
* Get the part of the query responsible for JOINing objects to relationships.
*
* @since 2.6.0 bbPress (r6844)
*
* @param array $args
* @param string $meta_key
* @param string $meta_type
*
* @return array
*/
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
$user_id = bbp_get_user_id( $args, true, true );
$option_key = $this->get_user_option_key( $meta_key );
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
// Maybe trick WP_Query into ".ID IN (0)" to return no results
if ( empty( $object_ids ) ) {
$object_ids = array( 0 );
}
// Maybe include these post IDs
$args = array(
'post__in' => $object_ids
);
// Parse arguments
return bbp_parse_args( $args, array(), $context_key );
}
}

View File

@@ -0,0 +1,784 @@
<?php
/**
* bbPress Formatting
*
* @package bbPress
* @subpackage Formatting
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Kses **********************************************************************/
/**
* Custom allowed tags for forum topics and replies
*
* Allows all users to post links, quotes, code, formatting, lists, and images
*
* @since 2.3.0 bbPress (r4603)
*
* @return array Associative array of allowed tags and attributes
*/
function bbp_kses_allowed_tags() {
// Filter & return
return (array) apply_filters( 'bbp_kses_allowed_tags', array(
// Links
'a' => array(
'href' => true,
'title' => true,
'rel' => true,
'target' => true
),
// Quotes
'blockquote' => array(
'cite' => true
),
// Code
'code' => array(),
'pre' => array(
'class' => true
),
// Formatting
'em' => array(),
'strong' => array(),
'del' => array(
'datetime' => true,
'cite' => true
),
'ins' => array(
'datetime' => true,
'cite' => true
),
// Lists
'ul' => array(),
'ol' => array(
'start' => true,
),
'li' => array(),
// Images
'img' => array(
'src' => true,
'border' => true,
'alt' => true,
'height' => true,
'width' => true,
)
) );
}
/**
* Custom kses filter for forum topics and replies, for filtering incoming data
*
* @since 2.3.0 bbPress (r4603)
*
* @param string $data Content to filter, expected to be escaped with slashes
* @return string Filtered content
*/
function bbp_filter_kses( $data = '' ) {
return wp_slash( wp_kses( wp_unslash( $data ), bbp_kses_allowed_tags() ) );
}
/**
* Custom kses filter for forum topics and replies, for raw data
*
* @since 2.3.0 bbPress (r4603)
*
* @param string $data Content to filter, expected to not be escaped
* @return string Filtered content
*/
function bbp_kses_data( $data = '' ) {
return wp_kses( $data , bbp_kses_allowed_tags() );
}
/** Formatting ****************************************************************/
/**
* Filter the topic or reply content and output code and pre tags
*
* @since 2.3.0 bbPress (r4641)
*
* @param string $content Topic and reply content
* @return string Partially encoded content
*/
function bbp_code_trick( $content = '' ) {
$content = str_replace( array( "\r\n", "\r" ), "\n", $content );
$content = preg_replace_callback( "|(`)(.*?)`|", 'bbp_encode_callback', $content );
$content = preg_replace_callback( "!(^|\n)`(.*?)`!s", 'bbp_encode_callback', $content );
return $content;
}
/**
* When editing a topic or reply, reverse the code trick so the textarea
* contains the correct editable content.
*
* @since 2.3.0 bbPress (r4641)
*
* @param string $content Topic and reply content
* @return string Partially encoded content
*/
function bbp_code_trick_reverse( $content = '' ) {
// Setup variables
$openers = array( '<p>', '<br />' );
$content = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", 'bbp_decode_callback', $content );
// Do the do
$content = str_replace( $openers, '', $content );
$content = str_replace( '</p>', "\n", $content );
$content = str_replace( '<coded_br />', '<br />', $content );
$content = str_replace( '<coded_p>', '<p>', $content );
$content = str_replace( '</coded_p>', '</p>', $content );
return $content;
}
/**
* Filter the content and encode any bad HTML tags
*
* @since 2.3.0 bbPress (r4641)
*
* @param string $content Topic and reply content
* @return string Partially encoded content
*/
function bbp_encode_bad( $content = '' ) {
// Setup variables
$content = _wp_specialchars( $content, ENT_NOQUOTES );
$content = preg_split( '@(`[^`]*`)@m', $content, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE );
$allowed = bbp_kses_allowed_tags();
$empty = array(
'br' => true,
'hr' => true,
'img' => true,
'input' => true,
'param' => true,
'area' => true,
'col' => true,
'embed' => true
);
// Loop through allowed tags and compare for empty and normal tags
foreach ( $allowed as $tag => $args ) {
$preg = $args ? "{$tag}(?:\s.*?)?" : $tag;
// Which walker to use based on the tag and arguments
if ( isset( $empty[ $tag ] ) ) {
array_walk( $content, 'bbp_encode_empty_callback', $preg );
} else {
array_walk( $content, 'bbp_encode_normal_callback', $preg );
}
}
// Return the joined content array
return implode( '', $content );
}
/** Code Callbacks ************************************************************/
/**
* Callback to encode the tags in topic or reply content
*
* @since 2.3.0 bbPress (r4641)
*
* @param array $matches
* @return string
*/
function bbp_encode_callback( $matches = array() ) {
// Trim inline code, not pre blocks (to prevent removing indentation)
if ( "`" === $matches[1] ) {
$content = trim( $matches[2] );
} else {
$content = $matches[2];
}
// Do some replacing
$content = htmlspecialchars( $content, ENT_QUOTES );
$content = str_replace( array( "\r\n", "\r" ), "\n", $content );
$content = preg_replace( "|\n\n\n+|", "\n\n", $content );
$content = str_replace( '&amp;amp;', '&amp;', $content );
$content = str_replace( '&amp;lt;', '&lt;', $content );
$content = str_replace( '&amp;gt;', '&gt;', $content );
// Wrap in code tags
$content = '<code>' . $content . '</code>';
// Wrap blocks in pre tags
if ( "`" !== $matches[1] ) {
$content = "\n<pre>" . $content . "</pre>\n";
}
return $content;
}
/**
* Callback to decode the tags in topic or reply content
*
* @since 2.3.0 bbPress (r4641)
*
* @param array $matches
* @todo Experiment with _wp_specialchars()
* @return string
*/
function bbp_decode_callback( $matches = array() ) {
// Setup variables
$trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) );
$amps = array( '&#38;','&#038;', '&amp;' );
$single = array( '&#39;','&#039;' );
$content = $matches[2];
$content = strtr( $content, $trans_table );
// Do the do
$content = str_replace( '<br />', '<coded_br />', $content );
$content = str_replace( '<p>', '<coded_p>', $content );
$content = str_replace( '</p>', '</coded_p>', $content );
$content = str_replace( $amps, '&', $content );
$content = str_replace( $single, "'", $content );
// Return content wrapped in code tags
return '`' . $content . '`';
}
/**
* Callback to replace empty HTML tags in a content string
*
* @since 2.3.0 bbPress (r4641)
*
* @internal Used by bbp_encode_bad()
* @param string $content
* @param string $key Not used
* @param string $preg
*/
function bbp_encode_empty_callback( &$content = '', $key = '', $preg = '' ) {
if ( strpos( $content, '`' ) !== 0 ) {
$content = preg_replace( "|&lt;({$preg})\s*?/*?&gt;|i", '<$1 />', $content );
}
}
/**
* Callback to replace normal HTML tags in a content string
*
* @since 2.3.0 bbPress (r4641)
*
* @internal Used by bbp_encode_bad()
*
* @param string $content
* @param string $key
* @param string $preg
*/
function bbp_encode_normal_callback( &$content = '', $key = '', $preg = '') {
if ( strpos( $content, '`' ) !== 0 ) {
$content = preg_replace( "|&lt;(/?{$preg})&gt;|i", '<$1>', $content );
}
}
/** No Follow *****************************************************************/
/**
* Catches links so rel=nofollow can be added (on output, not save)
*
* @since 2.3.0 bbPress (r4865)
*
* @param string $text Post text
* @return string $text Text with rel=nofollow added to any links
*/
function bbp_rel_nofollow( $text = '' ) {
return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text );
}
/**
* Adds rel=nofollow to a link
*
* @since 2.3.0 bbPress (r4865)
*
* @param array $matches
* @return string $text Link with rel=nofollow added
*/
function bbp_rel_nofollow_callback( $matches = array() ) {
$text = $matches[1];
$atts = shortcode_parse_atts( $matches[1] );
$rel = 'nofollow';
$home_url = home_url();
// Bail on links that match the current domain
if ( preg_match( '%href=["\'](' . preg_quote( set_url_scheme( $home_url, 'http' ) ) . ')%i', $text ) ||
preg_match( '%href=["\'](' . preg_quote( set_url_scheme( $home_url, 'https' ) ) . ')%i', $text )
) {
return "<a {$text}>";
}
// Avoid collisions with existing "rel" attribute
if ( ! empty( $atts['rel'] ) ) {
$parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
if ( false === array_search( 'nofollow', $parts ) ) {
$parts[] = 'nofollow';
}
$rel = implode( ' ', $parts );
unset( $atts['rel'] );
$html = '';
foreach ( $atts as $name => $value ) {
$html .= "{$name}=\"{$value}\" ";
}
$text = trim( $html );
}
return "<a {$text} rel=\"{$rel}\">";
}
/** Make Clickable ************************************************************/
/**
* Convert plaintext URI to HTML links.
*
* Converts URI, www and ftp, and email addresses. Finishes by fixing links
* within links.
*
* This custom version of WordPress's make_clickable() skips links inside of
* pre and code tags.
*
* @since 2.4.0 bbPress (r4941)
*
* @param string $text Content to convert URIs.
* @return string Content with converted URIs.
*/
function bbp_make_clickable( $text = '' ) {
$r = '';
$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
foreach ( $textarr as $piece ) {
if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) ) {
$nested_code_pre++;
} elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) ) {
$nested_code_pre--;
}
if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
$r .= $piece;
continue;
}
// Long strings might contain expensive edge cases ...
if ( 10000 < strlen( $piece ) ) {
// ... break it up
foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses
if ( 2101 < strlen( $chunk ) ) {
$r .= $chunk; // Too big, no whitespace: bail.
} else {
$r .= bbp_make_clickable( $chunk );
}
}
} else {
$ret = " {$piece} "; // Pad with whitespace to simplify the regexes
$ret = apply_filters( 'bbp_make_clickable', $ret, $text );
$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
$r .= $ret;
}
}
// Cleanup of accidental links within links
return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a>([^<]*)</a>#i', "$1$3$4</a>", $r );
}
/**
* Make URLs clickable in content areas
*
* @since 2.6.0 bbPress (r6014)
*
* @param string $text
* @return string
*/
function bbp_make_urls_clickable( $text = '' ) {
$url_clickable = '~
([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation
( # 2: URL
[\\w]{1,20}+:// # Scheme and hier-part prefix
(?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character
(?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
[\'.,;:!?)] # Punctuation URL character
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
)*
)
(\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing)
~xS';
// The regex is a non-anchored pattern and does not have a single fixed starting character.
// Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
return preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $text );
}
/**
* Make FTP clickable in content areas
*
* @since 2.6.0 bbPress (r6014)
*
* @see make_clickable()
*
* @param string $text
* @return string
*/
function bbp_make_ftps_clickable( $text = '' ) {
return preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $text );
}
/**
* Make emails clickable in content areas
*
* @since 2.6.0 bbPress (r6014)
*
* @see make_clickable()
*
* @param string $text
* @return string
*/
function bbp_make_emails_clickable( $text = '' ) {
return preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $text );
}
/**
* Make mentions clickable in content areas
*
* @since 2.6.0 bbPress (r6014)
*
* @see make_clickable()
*
* @param string $text
* @return string
*/
function bbp_make_mentions_clickable( $text = '' ) {
return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
}
/**
* Callback to convert mention matches to HTML A tag.
*
* @since 2.6.0 bbPress (r6014)
*
* @param array $matches Regular expression matches in the current text blob.
*
* @return string Original text if no user exists, or link to user profile.
*/
function bbp_make_mentions_clickable_callback( $matches = array() ) {
// Bail if the match is empty malformed
if ( empty( $matches[2] ) || ! is_string( $matches[2] ) ) {
return $matches[0];
}
// Get user; bail if not found
$user = get_user_by( 'slug', $matches[2] );
if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) {
return $matches[0];
}
// Default anchor classes
$classes = array(
'bbp-user-mention',
'bbp-user-id-' . absint( $user->ID )
);
// Filter classes
$classes = (array) apply_filters( 'bbp_make_mentions_clickable_classes', $classes, $user );
// Escape & implode if not empty, otherwise an empty string
$class_str = ! empty( $classes )
? implode( ' ', array_map( 'sanitize_html_class', $classes ) )
: '';
// Setup as a variable to avoid a potentially empty class attribute
$class = ! empty( $class_str )
? ' class="' . esc_attr( $class_str ) . '"'
: '';
// Create the link to the user's profile
$html = '<a href="%1$s"' . $class . '>%2$s</a>';
$url = bbp_get_user_profile_url( $user->ID );
$anchor = sprintf( $html, esc_url( $url ), esc_html( $matches[0] ) );
// Prevent this link from being followed by bots
$link = bbp_rel_nofollow( $anchor );
// Concatenate the matches into the return value
$retval = $matches[1] . $link;
// Return the link
return $retval;
}
/** Numbers *******************************************************************/
/**
* Never let a numeric value be less than zero.
*
* @since 2.6.0 bbPress (r6300)
*
* @param int $number
*/
function bbp_number_not_negative( $number = 0 ) {
// Protect against formatted strings
if ( is_string( $number ) ) {
$number = strip_tags( $number ); // No HTML
$number = preg_replace( '/[^0-9-]/', '', $number ); // No number-format
// Protect against objects, arrays, scalars, etc...
} elseif ( ! is_numeric( $number ) ) {
$number = 0;
}
// Make the number an integer
$int = intval( $number );
// Pick the maximum value, never less than zero
$not_less_than_zero = max( 0, $int );
// Filter & return
return (int) apply_filters( 'bbp_number_not_negative', $not_less_than_zero, $int, $number );
}
/**
* A bbPress specific method of formatting numeric values
*
* @since 2.0.0 bbPress (r2486)
*
* @param string $number Number to format
* @param string $decimals Optional. Display decimals
*
* @return string Formatted string
*/
function bbp_number_format( $number = 0, $decimals = false, $dec_point = '.', $thousands_sep = ',' ) {
// If empty, set $number to (int) 0
if ( ! is_numeric( $number ) ) {
$number = 0;
}
// Filter & return
return apply_filters( 'bbp_number_format', number_format( $number, $decimals, $dec_point, $thousands_sep ), $number, $decimals, $dec_point, $thousands_sep );
}
/**
* A bbPress specific method of formatting numeric values
*
* @since 2.1.0 bbPress (r3857)
*
* @param string $number Number to format
* @param string $decimals Optional. Display decimals
*
* @return string Formatted string
*/
function bbp_number_format_i18n( $number = 0, $decimals = false ) {
// If empty, set $number to (int) 0
if ( ! is_numeric( $number ) ) {
$number = 0;
}
// Filter & return
return apply_filters( 'bbp_number_format_i18n', number_format_i18n( $number, $decimals ), $number, $decimals );
}
/** Dates *********************************************************************/
/**
* Convert time supplied from database query into specified date format.
*
* @since 2.0.0 bbPress (r2544)
*
* @param string $time Time to convert
* @param string $d Optional. Default is 'U'. Either 'G', 'U', or php date
* format
* @param bool $translate Optional. Default is false. Whether to translate the
*
* @return string Returns timestamp
*/
function bbp_convert_date( $time, $d = 'U', $translate = false ) {
$new_time = mysql2date( $d, $time, $translate );
// Filter & return
return apply_filters( 'bbp_convert_date', $new_time, $d, $translate, $time );
}
/**
* Output formatted time to display human readable time difference.
*
* @since 2.0.0 bbPress (r2544)
*
* @param string $older_date Unix timestamp from which the difference begins.
* @param string $newer_date Optional. Unix timestamp from which the
* difference ends. False for current time.
* @param int $gmt Optional. Whether to use GMT timezone. Default is false.
*/
function bbp_time_since( $older_date, $newer_date = false, $gmt = false ) {
echo bbp_get_time_since( $older_date, $newer_date, $gmt );
}
/**
* Return formatted time to display human readable time difference.
*
* @since 2.0.0 bbPress (r2544)
*
* @param string $older_date Unix timestamp from which the difference begins.
* @param string $newer_date Optional. Unix timestamp from which the
* difference ends. False for current time.
* @param int $gmt Optional. Whether to use GMT timezone. Default is false.
*
* @return string Formatted time
*/
function bbp_get_time_since( $older_date, $newer_date = false, $gmt = false ) {
// Setup the strings
$unknown_text = apply_filters( 'bbp_core_time_since_unknown_text', esc_html__( 'sometime', 'bbpress' ) );
$right_now_text = apply_filters( 'bbp_core_time_since_right_now_text', esc_html__( 'right now', 'bbpress' ) );
$ago_text = apply_filters( 'bbp_core_time_since_ago_text', esc_html__( '%s ago', 'bbpress' ) );
// array of time period chunks
$chunks = array(
array( YEAR_IN_SECONDS, _n_noop( '%s year', '%s years', 'bbpress' ) ),
array( MONTH_IN_SECONDS, _n_noop( '%s month', '%s months', 'bbpress' ) ),
array( WEEK_IN_SECONDS, _n_noop( '%s week', '%s weeks', 'bbpress' ) ),
array( DAY_IN_SECONDS, _n_noop( '%s day', '%s days', 'bbpress' ) ),
array( HOUR_IN_SECONDS, _n_noop( '%s hour', '%s hours', 'bbpress' ) ),
array( MINUTE_IN_SECONDS, _n_noop( '%s minute', '%s minutes', 'bbpress' ) ),
array( 1, _n_noop( '%s second', '%s seconds', 'bbpress' ) ),
);
// Attempt to parse non-numeric older date
if ( ! empty( $older_date ) && ! is_numeric( $older_date ) ) {
$time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
$date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
$older_date = gmmktime( (int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0] );
}
// Attempt to parse non-numeric newer date
if ( ! empty( $newer_date ) && ! is_numeric( $newer_date ) ) {
$time_chunks = explode( ':', str_replace( ' ', ':', $newer_date ) );
$date_chunks = explode( '-', str_replace( ' ', '-', $newer_date ) );
$newer_date = gmmktime( (int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0] );
}
// Set newer date to current time
if ( empty( $newer_date ) ) {
$newer_date = strtotime( current_time( 'mysql', $gmt ) );
}
// Cast both dates to ints to avoid notices & errors with invalid values
$newer_date = intval( $newer_date );
$older_date = intval( $older_date );
// Difference in seconds
$since = intval( $newer_date - $older_date );
// Something went wrong with date calculation and we ended up with a negative date.
if ( 0 > $since ) {
$output = $unknown_text;
// We only want to output two chunks of time here, eg:
// x years, xx months
// x days, xx hours
// so there's only two bits of calculation below:
} else {
// Default count values
$count = 0;
$count2 = 0;
// Step one: the first chunk
for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) {
$seconds = $chunks[ $i ][0];
// Finding the biggest chunk (if the chunk fits, break)
$count = floor( $since / $seconds );
if ( 0 != $count ) {
break;
}
}
// If $i iterates all the way to $j, then the event happened 0 seconds ago
if ( ! isset( $chunks[ $i ] ) ) {
$output = $right_now_text;
} else {
// Set output var
$output = sprintf( translate_nooped_plural( $chunks[ $i ][1], $count, 'bbpress' ), bbp_number_format_i18n( $count ) );
// Step two: the second chunk
if ( $i + 2 < $j ) {
$seconds2 = $chunks[ $i + 1 ][0];
$count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
// Add to output var
if ( 0 != $count2 ) {
$output .= _x( ',', 'Separator in time since', 'bbpress' ) . ' ';
$output .= sprintf( translate_nooped_plural( $chunks[ $i + 1 ][1], $count2, 'bbpress' ), bbp_number_format_i18n( $count2 ) );
}
}
// Empty counts, so fallback to right now
if ( empty( $count ) && empty( $count2 ) ) {
$output = $right_now_text;
}
}
}
// Append 'ago' to the end of time-since if not 'right now'
if ( $output != $right_now_text ) {
$output = sprintf( $ago_text, $output );
}
// Filter & return
return apply_filters( 'bbp_get_time_since', $output, $older_date, $newer_date );
}
/** Revisions *****************************************************************/
/**
* Formats the reason for editing the topic/reply.
*
* Does these things:
* - Trimming
* - Removing periods from the end of the string
* - Trimming again
*
* @since 2.0.0 bbPress (r2782)
*
* @param string $reason Optional. User submitted reason for editing.
* @return string Status of topic
*/
function bbp_format_revision_reason( $reason = '' ) {
$reason = (string) $reason;
// Bail if reason is empty
if ( empty( $reason ) ) {
return $reason;
}
// Trimming
$reason = trim( $reason );
// We add our own full stop.
while ( substr( $reason, -1 ) === '.' ) {
$reason = substr( $reason, 0, -1 );
}
// Trim again
$reason = trim( $reason );
return $reason;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

View File

@@ -0,0 +1,57 @@
<?php
/**
* bbPress Localization
*
* @package bbPress
* @subpackage Localization
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Translates role name.
*
* Since the role names are in the database and not in the source there
* are dummy gettext calls to get them into the POT file and this function
* properly translates them back.
*
* The before_last_bar() call is needed, because older installs keep the roles
* using the old context format: 'Role name|User role' and just skipping the
* content after the last bar is easier than fixing them in the DB. New installs
* won't suffer from that problem.
*
* @see translate_user_role()
*
* @since 2.6.0 bbPress
*
* @param string $name The role name.
* @return string Translated role name on success, original name on failure.
*/
function bbp_translate_user_role( $name ) {
return translate_with_gettext_context( before_last_bar( $name ), 'User role', 'bbpress' );
}
/**
* Dummy gettext calls to get strings in the catalog.
*
* @since 2.6.0 bbPress
*/
function bbp_dummy_role_names() {
/* translators: user role */
_x( 'Keymaster', 'User role', 'bbpress' );
/* translators: user role */
_x( 'Moderator', 'User role', 'bbpress' );
/* translators: user role */
_x( 'Participant', 'User role', 'bbpress' );
/* translators: user role */
_x( 'Spectator', 'User role', 'bbpress' );
/* translators: user role */
_x( 'Blocked', 'User role', 'bbpress' );
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* bbPress Locking
*
* @package bbPress
* @subpackage Common
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Check to see if the post is currently being edited by another user.
*
* @see wp_check_post_lock()
*
* @since 2.6.0 bbPress (r6340)
*
* @param int $post_id ID of the post to check for editing
* @return integer False: not locked or locked by current user. Int: user ID of user with lock.
*/
function bbp_check_post_lock( $post_id = 0 ) {
// Bail if no post
if ( !$post = get_post( $post_id ) ) {
return false;
}
// Bail if no lock
if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
return false;
}
// Get lock
$lock = explode( ':', $lock );
$time = $lock[0];
$user = (int) isset( $lock[1] )
? $lock[1]
: get_post_meta( $post->ID, '_edit_last', true );
// Filter editing window duration
$time_window = apply_filters( 'bbp_check_post_lock_window', 3 * MINUTE_IN_SECONDS );
// Return user who is or last edited
if ( ! empty( $time ) && ( $time > ( time() - $time_window ) ) && ( $user !== bbp_get_current_user_id() ) ) {
return (int) $user;
}
return false;
}
/**
* Mark the post as currently being edited by the current user
*
* @since 2.6.0 bbPress (r6340)
*
* @param int $post_id ID of the post to being edited
* @return bool|array Returns false if the post doesn't exist of there is no current user, or
* an array of the lock time and the user ID.
*/
function bbp_set_post_lock( $post_id = 0 ) {
// Bail if no post
if ( !$post = get_post( $post_id ) ) {
return false;
}
// Bail if no user
if ( 0 == ( $user_id = get_current_user_id() ) ) {
return false;
}
// Get time & lock value
$now = time();
$lock = "{$now}:{$user_id}";
// Set lock value
update_post_meta( $post->ID, '_edit_lock', $lock );
return array( $now, $user_id );
}

View File

@@ -0,0 +1,858 @@
<?php
/**
* bbPress Shortcodes
*
* @package bbPress
* @subpackage Shortcodes
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'BBP_Shortcodes' ) ) :
/**
* bbPress Shortcode Class
*
* @since 2.0.0 bbPress (r3031)
*/
class BBP_Shortcodes {
/** Vars ******************************************************************/
/**
* @var array Shortcode => function
*/
public $codes = array();
/** Functions *************************************************************/
/**
* Add the register_shortcodes action to bbp_init
*
* @since 2.0.0 bbPress (r3031)
*
*/
public function __construct() {
$this->setup_globals();
$this->add_shortcodes();
}
/**
* Shortcode globals
*
* @since 2.0.0 bbPress (r3143)
*
* @access private
*/
private function setup_globals() {
// Setup the shortcodes
$this->codes = apply_filters( 'bbp_shortcodes', array(
/** Forums ********************************************************/
'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index
'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form
'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute
/** Topics ********************************************************/
'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index
'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form
'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute
/** Topic Tags ****************************************************/
'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud
'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag
/** Replies *******************************************************/
'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form
'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute
/** Views *********************************************************/
'bbp-single-view' => array( $this, 'display_view' ), // Single view
/** Search ********************************************************/
'bbp-search-form' => array( $this, 'display_search_form' ), // Search form
'bbp-search' => array( $this, 'display_search' ), // Search
/** Account *******************************************************/
'bbp-login' => array( $this, 'display_login' ), // Login
'bbp-register' => array( $this, 'display_register' ), // Register
'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password
/** Others *******************************************************/
'bbp-stats' => array( $this, 'display_stats' ), // Stats
) );
}
/**
* Register the bbPress shortcodes
*
* @since 2.0.0 bbPress (r3031)
*/
private function add_shortcodes() {
foreach ( (array) $this->codes as $code => $function ) {
add_shortcode( $code, $function );
}
}
/**
* Unset some globals in the $bbp object that hold query related info
*
* @since 2.0.0 bbPress (r3034)
*/
private function unset_globals() {
$bbp = bbpress();
// Unset global queries
$bbp->forum_query = new WP_Query();
$bbp->topic_query = new WP_Query();
$bbp->reply_query = new WP_Query();
$bbp->search_query = new WP_Query();
// Unset global ID's
$bbp->current_view_id = 0;
$bbp->current_forum_id = 0;
$bbp->current_topic_id = 0;
$bbp->current_reply_id = 0;
$bbp->current_topic_tag_id = 0;
// Reset the post data
wp_reset_postdata();
}
/** Output Buffers ********************************************************/
/**
* Start an output buffer.
*
* This is used to put the contents of the shortcode into a variable rather
* than outputting the HTML at run-time. This allows shortcodes to appear
* in the correct location in the_content() instead of when it's created.
*
* @since 2.0.0 bbPress (r3079)
*
* @param string $query_name
*/
private function start( $query_name = '' ) {
// Set query name
bbp_set_query_name( $query_name );
// Start output buffer
ob_start();
}
/**
* Return the contents of the output buffer and flush its contents.
*
* @since 2.0.0 bbPress (r3079)
*
* @return string Contents of output buffer.
*/
private function end() {
// Unset globals
$this->unset_globals();
// Get the query name, for filter
$query_name = bbp_get_query_name();
// Reset the query name
bbp_reset_query_name();
// Return and flush the output buffer
$output = ob_get_clean();
// Filter & return
return apply_filters( 'bbp_display_shortcode', $output, $query_name );
}
/** Forum shortcodes ******************************************************/
/**
* Display an index of all visible root level forums in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @return string
*/
public function display_forum_index() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_forum_archive' );
bbp_get_template_part( 'content', 'archive-forum' );
// Return contents of output buffer
return $this->end();
}
/**
* Display the contents of a specific forum ID in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_forum( $attr, $content = '' ) {
// Sanity check required info
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
return $content;
}
// Set passed attribute to $forum_id for clarity
$forum_id = bbpress()->current_forum_id = $attr['id'];
// Bail if ID passed is not a forum
if ( ! bbp_is_forum( $forum_id ) ) {
return $content;
}
// Start output buffer
$this->start( 'bbp_single_forum' );
// Check forum caps
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
bbp_get_template_part( 'content', 'single-forum' );
// Forum is private and user does not have caps
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
bbp_get_template_part( 'feedback', 'no-access' );
}
// Return contents of output buffer
return $this->end();
}
/**
* Display the forum form in an output buffer and return to ensure
* post/page contents are displayed first.
*
* @since 2.1.0 bbPress (r3566)
*/
public function display_forum_form() {
// Start output buffer
$this->start( 'bbp_forum_form' );
// Output templates
bbp_get_template_part( 'form', 'forum' );
// Return contents of output buffer
return $this->end();
}
/** Topic shortcodes ******************************************************/
/**
* Display an index of all visible root level topics in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @return string
*/
public function display_topic_index() {
// Unset globals
$this->unset_globals();
// Filter the query
if ( ! bbp_is_topic_archive() ) {
add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) );
}
// Start output buffer
$this->start( 'bbp_topic_archive' );
// Output template
bbp_get_template_part( 'content', 'archive-topic' );
// Return contents of output buffer
return $this->end();
}
/**
* Display the contents of a specific topic ID in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_topic( $attr, $content = '' ) {
// Sanity check required info
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
return $content;
}
// Unset globals
$this->unset_globals();
// Set passed attribute to $forum_id for clarity
$topic_id = bbpress()->current_topic_id = $attr['id'];
$forum_id = bbp_get_topic_forum_id( $topic_id );
// Bail if ID passed is not a topic
if ( ! bbp_is_topic( $topic_id ) ) {
return $content;
}
// Reset the queries if not in theme compat
if ( ! bbp_is_theme_compat_active() ) {
$bbp = bbpress();
// Reset necessary forum_query attributes for topics loop to function
$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
$bbp->forum_query->in_the_loop = true;
$bbp->forum_query->post = get_post( $forum_id );
// Reset necessary topic_query attributes for topics loop to function
$bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
$bbp->topic_query->in_the_loop = true;
$bbp->topic_query->post = get_post( $topic_id );
}
// Start output buffer
$this->start( 'bbp_single_topic' );
// Check forum caps
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
bbp_get_template_part( 'content', 'single-topic' );
// Forum is private and user does not have caps
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
bbp_get_template_part( 'feedback', 'no-access' );
}
// Return contents of output buffer
return $this->end();
}
/**
* Display the topic form in an output buffer and return to ensure
* post/page contents are displayed first.
*
* Supports 'forum_id' attribute to display the topic form for a particular
* forum. This currently has styling issues from not being wrapped in
* <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later.
*
* @since 2.0.0 bbPress (r3031)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_topic_form( $attr = array(), $content = '' ) {
// Sanity check supplied info
if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) {
return $content;
}
// Unset globals
$this->unset_globals();
// If forum id is set, use the 'bbp_single_forum' query name
if ( ! empty( $attr['forum_id'] ) ) {
// Set the global current_forum_id for future requests
bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] );
// Start output buffer
$this->start( 'bbp_single_forum' );
// No forum id was passed
} else {
// Set the $forum_id variable to satisfy checks below
$forum_id = 0;
// Start output buffer
$this->start( 'bbp_topic_form' );
}
// If the forum id is set, check forum caps else display normal topic form
if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
bbp_get_template_part( 'form', 'topic' );
// Forum is private and user does not have caps
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
bbp_get_template_part( 'feedback', 'no-access' );
}
// Return contents of output buffer
return $this->end();
}
/** Replies ***************************************************************/
/**
* Display the contents of a specific reply ID in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_reply( $attr, $content = '' ) {
// Sanity check required info
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
return $content;
}
// Unset globals
$this->unset_globals();
// Set passed attribute to $reply_id for clarity
$reply_id = bbpress()->current_reply_id = $attr['id'];
$forum_id = bbp_get_reply_forum_id( $reply_id );
// Bail if ID passed is not a reply
if ( ! bbp_is_reply( $reply_id ) ) {
return $content;
}
// Reset the queries if not in theme compat
if ( ! bbp_is_theme_compat_active() ) {
$bbp = bbpress();
// Reset necessary forum_query attributes for reply loop to function
$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
$bbp->forum_query->in_the_loop = true;
$bbp->forum_query->post = get_post( $forum_id );
// Reset necessary reply_query attributes for reply loop to function
$bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
$bbp->reply_query->in_the_loop = true;
$bbp->reply_query->post = get_post( $reply_id );
}
// Start output buffer
$this->start( 'bbp_single_reply' );
// Check forum caps
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
bbp_get_template_part( 'content', 'single-reply' );
// Forum is private and user does not have caps
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
bbp_get_template_part( 'feedback', 'no-access' );
}
// Return contents of output buffer
return $this->end();
}
/**
* Display the reply form in an output buffer and return to ensure
* post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*/
public function display_reply_form() {
// Start output buffer
$this->start( 'bbp_reply_form' );
// Output templates
bbp_get_template_part( 'form', 'reply' );
// Return contents of output buffer
return $this->end();
}
/** Topic Tags ************************************************************/
/**
* Display a tag cloud of all topic tags in an output buffer and return to
* ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3110)
*
* @return string
*/
public function display_topic_tags() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_topic_tags' );
// Output the topic tags
wp_tag_cloud( array(
'smallest' => 9,
'largest' => 38,
'number' => 80,
'taxonomy' => bbp_get_topic_tag_tax_id()
) );
// Return contents of output buffer
return $this->end();
}
/**
* Display the contents of a specific topic tag in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3110)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_topics_of_tag( $attr, $content = '' ) {
// Sanity check required info
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
return $content;
}
// Unset globals
$this->unset_globals();
// Filter the query
if ( ! bbp_is_topic_tag() ) {
add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) );
}
// Start output buffer
$this->start( 'bbp_topic_tag' );
// Set passed attribute to $ag_id for clarity
bbpress()->current_topic_tag_id = $tag_id = $attr['id'];
// Output template
bbp_get_template_part( 'content', 'archive-topic' );
// Return contents of output buffer
return $this->end();
}
/**
* Display the contents of a specific topic tag in an output buffer
* and return to ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3346)
*
* @return string
*/
public function display_topic_tag_form() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_topic_tag_edit' );
// Output template
bbp_get_template_part( 'content', 'topic-tag-edit' );
// Return contents of output buffer
return $this->end();
}
/** Views *****************************************************************/
/**
* Display the contents of a specific view in an output buffer and return to
* ensure that post/page contents are displayed first.
*
* @since 2.0.0 bbPress (r3031)
*
* @param array $attr
* @param string $content
* @return string
*/
public function display_view( $attr, $content = '' ) {
// Sanity check required info
if ( empty( $attr['id'] ) ) {
return $content;
}
// Set passed attribute to $view_id for clarity
$view_id = $attr['id'];
// Start output buffer
$this->start( 'bbp_single_view' );
// Unset globals
$this->unset_globals();
// Set the current view ID
bbpress()->current_view_id = $view_id;
// Load the view
bbp_view_query( $view_id );
// Output template
bbp_get_template_part( 'content', 'single-view' );
// Return contents of output buffer
return $this->end();
}
/** Search ****************************************************************/
/**
* Display the search form in an output buffer and return to ensure
* post/page contents are displayed first.
*
* @since 2.3.0 bbPress (r4585)
*/
public function display_search_form() {
// Bail if search is disabled
if ( ! bbp_allow_search() ) {
return;
}
// Start output buffer
$this->start( 'bbp_search_form' );
// Output templates
bbp_get_template_part( 'form', 'search' );
// Return contents of output buffer
return $this->end();
}
/**
* Display the contents of search results in an output buffer and return to
* ensure that post/page contents are displayed first.
*
* @since 2.3.0 bbPress (r4579)
*
* @param array $attr
* @param string $content
*/
public function display_search( $attr, $content = '' ) {
// Sanity check required info
if ( ! empty( $content ) ) {
return $content;
}
// Bail if search is disabled
if ( ! bbp_allow_search() ) {
return;
}
// Trim search attribute if it's set
if ( isset( $attr['search'] ) ) {
$attr['search'] = trim( $attr['search'] );
}
// Set passed attribute to $search_terms for clarity
$search_terms = empty( $attr['search'] )
? bbp_get_search_terms()
: $attr['search'];
// Get the rewrite ID (one time, to avoid repeated calls)
$rewrite_id = bbp_get_search_rewrite_id();
// Unset globals
$this->unset_globals();
// Set terms for query
set_query_var( $rewrite_id, $search_terms );
// Start output buffer
$this->start( $rewrite_id );
// Output template
bbp_get_template_part( 'content', 'search' );
// Return contents of output buffer
return $this->end();
}
/** Account ***************************************************************/
/**
* Display a login form
*
* @since 2.0.0 bbPress (r3302)
*
* @return string
*/
public function display_login() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_login' );
// Output templates
if ( ! is_user_logged_in() ) {
bbp_get_template_part( 'form', 'user-login' );
} else {
bbp_get_template_part( 'feedback', 'logged-in' );
}
// Return contents of output buffer
return $this->end();
}
/**
* Display a register form
*
* @since 2.0.0 bbPress (r3302)
*
* @return string
*/
public function display_register() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_register' );
// Output templates
if ( ! is_user_logged_in() ) {
bbp_get_template_part( 'form', 'user-register' );
} else {
bbp_get_template_part( 'feedback', 'logged-in' );
}
// Return contents of output buffer
return $this->end();
}
/**
* Display a lost password form
*
* @since 2.0.0 bbPress (r3302)
*
* @return string
*/
public function display_lost_pass() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start( 'bbp_lost_pass' );
// Output templates
if ( ! is_user_logged_in() ) {
bbp_get_template_part( 'form', 'user-lost-pass' );
} else {
bbp_get_template_part( 'feedback', 'logged-in' );
}
// Return contents of output buffer
return $this->end();
}
/** Other *****************************************************************/
/**
* Display forum statistics
*
* @since 2.3.0 bbPress (r4509)
*
* @return string
*/
public function display_stats() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start();
// Output statistics
bbp_get_template_part( 'content', 'statistics' );
// Return contents of output buffer
return $this->end();
}
/**
* Display a breadcrumb
*
* @since 2.0.0 bbPress (r3302)
*
* @return string
*/
public function display_breadcrumb() {
// Unset globals
$this->unset_globals();
// Start output buffer
$this->start();
// Output breadcrumb
bbp_breadcrumb();
// Return contents of output buffer
return $this->end();
}
/** Query Filters *********************************************************/
/**
* Filter the query for the topic index
*
* @since 2.1.0 bbPress (r3637)
*
* @param array $args
* @return array
*/
public function display_topic_index_query( $args = array() ) {
$args['author'] = 0;
$args['show_stickies'] = true;
$args['order'] = 'DESC';
return $args;
}
/**
* Filter the query for topic tags
*
* @since 2.1.0 bbPress (r3637)
*
* @param array $args
* @return array
*/
public function display_topics_of_tag_query( $args = array() ) {
$args['tax_query'] = array( array(
'taxonomy' => bbp_get_topic_tag_tax_id(),
'field' => 'id',
'terms' => bbpress()->current_topic_tag_id
) );
return $args;
}
}
endif;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,498 @@
<?php
/**
* bbPress Abstractions
*
* This file contains functions for abstracting WordPress core functionality
* into convenient wrappers so they can be used more reliably.
*
* Many of the functions in this file are considered superfluous by
* WordPress coding standards, but they're handy for plugins of plugins to use.
*
* @package bbPress
* @subpackage Core
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Setup Admin
*
* This exists outside of "/includes/admin/" because the converter may need to
* be setup to convert the passwords of users that were migrated from another
* forum platform.
*
* @since 2.6.0 bbPress (r2596)
*/
function bbp_setup_admin() {
$bbp = bbpress();
// Skip if already setup
if ( empty( $bbp->admin ) ) {
// Require the admin class
require_once $bbp->includes_dir . 'admin/classes/class-bbp-admin.php';
// Setup
$bbp->admin = class_exists( 'BBP_Admin' )
? new BBP_Admin()
: new stdClass();
}
// Return the admin object
return $bbp->admin;
}
/**
* Setup Converter
*
* This exists outside of "/includes/admin/" because the converter may need to
* be setup to convert the passwords of users that were migrated from another
* forum platform.
*
* @since 2.6.0 bbPress (r2596)
*/
function bbp_setup_converter() {
$bbp_admin = bbp_setup_admin();
// Skip if already setup
if ( empty( $bbp_admin->converter ) ) {
// Require the converter files
require_once $bbp_admin->admin_dir . 'tools/converter.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-db.php';
require_once $bbp_admin->admin_dir . 'classes/class-bbp-converter-base.php';
// Setup
$bbp_admin->converter = class_exists( 'BBP_Converter' )
? new BBP_Converter()
: new stdClass();
}
// Return the converter
return $bbp_admin->converter;
}
/** Globals *******************************************************************/
/**
* Lookup and return a global variable
*
* @since 2.5.8 bbPress (r5814)
*
* @param string $name Name of global variable
* @param string $type Type of variable to check with `is_a()`
* @param mixed $default Default value to return if no global found
*
* @return mixed Verified object if valid, Default or null if invalid
*/
function bbp_get_global_object( $name = '', $type = '', $default = null ) {
// If no name passed
if ( empty( $name ) ) {
$retval = $default;
// If no global exists
} elseif ( ! isset( $GLOBALS[ $name ] ) ) {
$retval = $default;
// If not the correct type of global
} elseif ( ! empty( $type ) && ! is_a( $GLOBALS[ $name ], $type ) ) {
$retval = $default;
// Global variable exists
} else {
$retval = $GLOBALS[ $name ];
}
// Filter & return
return apply_filters( 'bbp_get_global_object', $retval, $name, $type, $default );
}
/**
* Get the `$wp_query` global without needing to declare it everywhere
*
* @since 2.6.0 bbPress (r6582)
*
* @return WP_Roles
*/
function bbp_get_wp_query() {
return bbp_get_global_object( 'wp_query', 'WP_Query' );
}
/**
* Get the `$wp_roles` global without needing to declare it everywhere
*
* @since 2.2.0 bbPress (r4293)
*
* @return WP_Roles
*/
function bbp_get_wp_roles() {
return bbp_get_global_object( 'wp_roles', 'WP_Roles' );
}
/**
* Return the database class being used to interface with the environment.
*
* This function is abstracted to avoid global touches to the primary database
* class. bbPress supports WordPress's `$wpdb` global by default, and can be
* filtered to support other configurations if needed.
*
* @since 2.5.8 bbPress (r5814)
*
* @return object
*/
function bbp_db() {
return bbp_get_global_object( 'wpdb', 'WPDB' );
}
/** Pagination ****************************************************************/
/**
* Return the rewrite rules class being used to interact with URLs.
*
* This function is abstracted to avoid global touches to the primary rewrite
* rules class. bbPress supports WordPress's `$wp_rewrite` by default, but can
* be filtered to support other configurations if needed.
*
* @since 2.5.8 bbPress (r5814)
*
* @return object
*/
function bbp_rewrite() {
return bbp_get_global_object( 'wp_rewrite', 'WP_Rewrite', (object) array(
'root' => '',
'pagination_base' => 'page',
) );
}
/**
* Get the root URL
*
* @since 2.5.8 bbPress (r5814)
*
* @return string
*/
function bbp_get_root_url() {
// Default
$retval = '';
$rewrite = bbp_rewrite();
// Use $wp_rewrite->root if available
if ( property_exists( $rewrite, 'root' ) ) {
$retval = $rewrite->root;
}
// Filter & return
return apply_filters( 'bbp_get_root_url', $retval );
}
/**
* Get the slug used for paginated requests
*
* @since 2.4.0 bbPress (r4926)
*
* @return string
*/
function bbp_get_paged_slug() {
// Default
$retval = 'page';
$rewrite = bbp_rewrite();
// Use $wp_rewrite->pagination_base if available
if ( property_exists( $rewrite, 'pagination_base' ) ) {
$retval = $rewrite->pagination_base;
}
// Filter & return
return apply_filters( 'bbp_get_paged_slug', $retval );
}
/**
* Is the environment using pretty URLs?
*
* @since 2.5.8 bbPress (r5814)
*
* @global object $wp_rewrite The WP_Rewrite object
*
* @return bool
*/
function bbp_use_pretty_urls() {
// Default
$retval = false;
$rewrite = bbp_rewrite();
// Use $wp_rewrite->using_permalinks() if available
if ( method_exists( $rewrite, 'using_permalinks' ) ) {
$retval = $rewrite->using_permalinks();
}
// Filter & return
return apply_filters( 'bbp_pretty_urls', $retval );
}
/**
* Remove the first-page from a pagination links result set, ensuring that it
* points to the canonical first page URL.
*
* This is a bit of an SEO hack, to guarantee that the first page in a loop will
* never have pagination appended to the end of it, regardless of what the other
* functions have decided for us.
*
* @since 2.6.0 bbPress (r6678)
*
* @param string $pagination_links The HTML links used for pagination
*
* @return string
*/
function bbp_make_first_page_canonical( $pagination_links = '' ) {
// Default value
$retval = $pagination_links;
// Remove first page from pagination
if ( ! empty( $pagination_links ) ) {
$retval = bbp_use_pretty_urls()
? str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links )
: preg_replace( '/&#038;paged=1(?=[^0-9])/m', '', $pagination_links );
}
// Filter & return
return apply_filters( 'bbp_make_first_page_canonical', $retval, $pagination_links );
}
/**
* A convenient wrapper for common calls to paginate_links(), complete with
* support for parameters that aren't used internally by bbPress.
*
* @since 2.6.0 bbPress (r6679)
*
* @param array $args
*
* @return string
*/
function bbp_paginate_links( $args = array() ) {
// Maybe add view-all args
$add_args = empty( $args['add_args'] ) && bbp_get_view_all()
? array( 'view' => 'all' )
: false;
// Pagination settings with filter
$r = bbp_parse_args( $args, array(
// Used by callers
'base' => '',
'total' => 1,
'current' => bbp_get_paged(),
'prev_next' => true,
'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
'next_text' => is_rtl() ? '&larr;' : '&rarr;',
'mid_size' => 1,
'end_size' => 3,
'add_args' => $add_args,
// Unused by callers
'show_all' => false,
'type' => 'plain',
'format' => '',
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
), 'paginate_links' );
// Return paginated links
return bbp_make_first_page_canonical( paginate_links( $r ) );
}
/**
* Parse the WordPress core version number
*
* @since 2.6.0 bbPress (r6051)
*
* @global string $wp_version
*
* @return string $wp_version
*/
function bbp_get_major_wp_version() {
global $wp_version;
return (float) $wp_version;
}
/** Multisite *****************************************************************/
/**
* Is this a large bbPress installation?
*
* @since 2.6.0 bbPress (r6242)
*
* @return bool True if more than 10000 users, false not
*/
function bbp_is_large_install() {
// Multisite has a function specifically for this
$retval = function_exists( 'wp_is_large_network' )
? wp_is_large_network( 'users' )
: ( bbp_get_total_users() > 10000 );
// Filter & return
return (bool) apply_filters( 'bbp_is_large_install', $retval );
}
/**
* Get the total number of users on the forums
*
* @since 2.0.0 bbPress (r2769)
*
* @return int Total number of users
*/
function bbp_get_total_users() {
$bbp_db = bbp_db();
$count = $bbp_db->get_var( "SELECT COUNT(ID) as c FROM {$bbp_db->users} WHERE user_status = '0'" );
// Filter & return
return (int) apply_filters( 'bbp_get_total_users', (int) $count );
}
/**
* Switch to a site in a multisite installation.
*
* If not a multisite installation, no switching will occur.
*
* @since 2.6.0 bbPress (r6733)
*
* @param int $site_id
*/
function bbp_switch_to_site( $site_id = 0 ) {
// Switch to a specific site
if ( is_multisite() ) {
switch_to_blog( $site_id );
}
}
/**
* Switch back to the original site in a multisite installation.
*
* If not a multisite installation, no switching will occur.
*
* @since 2.6.0 bbPress (r6733)
*/
function bbp_restore_current_site() {
// Switch back to the original site
if ( is_multisite() ) {
restore_current_blog();
}
}
/** Interception **************************************************************/
/**
* Generate a default intercept value.
*
* @since 2.6.0
*
* @staticvar mixed $rand Null by default, random string on first call
*
* @return string
*/
function bbp_default_intercept() {
static $rand = null;
// Generate a new random and unique string
if ( null === $rand ) {
// If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
$algo = function_exists( 'hash' )
? 'sha256'
: 'sha1';
// Old WP installs may not have AUTH_SALT defined.
$salt = defined( 'AUTH_SALT' ) && AUTH_SALT
? AUTH_SALT
: (string) wp_rand();
// Create unique ID
$rand = hash_hmac( $algo, uniqid( $salt, true ), $salt );
}
// Return random string (from locally static variable)
return $rand;
}
/**
* Whether a value has been intercepted
*
* @since 2.6.0
*
* @param bool $value
*/
function bbp_is_intercepted( $value = '' ) {
return ( bbp_default_intercept() !== $value );
}
/**
* Allow interception of a method or function call.
*
* @since 2.6.0
*
* @param string $action Typically the name of the caller function
* @param array $args Typically the results of caller function func_get_args()
*
* @return mixed Intercept results. Default bbp_default_intercept().
*/
function bbp_maybe_intercept( $action = '', $args = array() ) {
// Backwards compatibility juggle
$hook = ( false === strpos( $action, 'pre_' ) )
? "pre_{$action}"
: $action;
// Default value
$default = bbp_default_intercept();
// Parse args
$r = bbp_parse_args( (array) $args, array(), 'maybe_intercept' );
// Bail if no args
if ( empty( $r ) ) {
return $default;
}
// Filter
$args = array_merge( array( $hook ), $r );
$filtered = call_user_func_array( 'apply_filters', $args );
// Return filtered value, or default if not intercepted
return ( $filtered === reset( $r ) )
? $default
: $filtered;
}
/** Date/Time *****************************************************************/
/**
* Get an empty datetime value.
*
* @since 2.6.6 bbPress (r7094)
*
* @return string
*/
function bbp_get_empty_datetime() {
// Get the database version
$db_version = bbp_db()->db_version();
// Default return value
$retval = '0000-00-00 00:00:00';
// Filter & return
return (string) apply_filters( 'bbp_get_default_zero_date', $retval, $db_version );
}

View File

@@ -0,0 +1,465 @@
<?php
/**
* bbPress Actions
*
* This file contains the actions that are used through-out bbPress. They are
* consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional actions can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
*
* @package bbPress
* @subpackage Core
*
* @see /core/filters.php
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_action( 'plugins_loaded', 'bbp_loaded', 10 );
add_action( 'init', 'bbp_init', 0 ); // Early for bbp_register
add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides
add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 );
add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 );
add_action( 'setup_theme', 'bbp_setup_theme', 10 );
add_action( 'set_current_user', 'bbp_setup_current_user', 10 );
add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data
add_action( 'user_register', 'bbp_user_register', 10 );
add_action( 'login_form_login', 'bbp_login_form_login', 10 );
add_action( 'template_redirect', 'bbp_template_redirect', 8 ); // Before BuddyPress's 10 [BB2225]
add_action( 'widgets_init', 'bbp_widgets_init', 10 );
add_action( 'wp_roles_init', 'bbp_roles_init', 10 );
add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 );
add_action( 'wp_head', 'bbp_head', 10 );
add_action( 'wp_footer', 'bbp_footer', 10 );
add_action( 'transition_post_status', 'bbp_transition_post_status', 10, 3 );
/**
* bbp_loaded - Attached to 'plugins_loaded' above
*
* Attach various loader actions to the bbp_loaded action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_loaded', 'bbp_constants', 2 );
add_action( 'bbp_loaded', 'bbp_boot_strap_globals', 4 );
add_action( 'bbp_loaded', 'bbp_includes', 6 );
add_action( 'bbp_loaded', 'bbp_setup_globals', 8 );
add_action( 'bbp_loaded', 'bbp_setup_option_filters', 10 );
add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
add_action( 'bbp_loaded', 'bbp_pre_load_options', 14 );
/**
* bbp_init - Attached to 'init' above
*
* Attach various initialization actions to the init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_init', 'bbp_load_textdomain', 0 );
add_action( 'bbp_init', 'bbp_register', 10 );
add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20 );
add_action( 'bbp_init', 'bbp_add_rewrite_rules', 30 );
add_action( 'bbp_init', 'bbp_add_permastructs', 40 );
add_action( 'bbp_init', 'bbp_setup_engagements', 50 );
add_action( 'bbp_init', 'bbp_ready', 999 );
/**
* bbp_setup_theme - Attached to 'setup_theme' above
*
* Attach various theme related actions to the setup_theme action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_setup_theme', 'bbp_register_theme_packages', 2 ); // Lower than 5
/**
* bbp_roles_init - Attached to 'wp_roles_init' above
*
* Attach various role related actions to the wp_roles_init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_roles_init', 'bbp_add_forums_roles', 8 );
/**
* When setting up the current user, make sure they have a role for the forums.
*
* This is multisite aware, thanks to bbp_filter_user_roles_option(), hooked to
* the 'bbp_loaded' action above.
*/
add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
/**
* bbp_register - Attached to 'init' above on 0 priority
*
* Attach various initialization actions early to the init action.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_register', 'bbp_register_post_types', 2 );
add_action( 'bbp_register', 'bbp_register_post_statuses', 4 );
add_action( 'bbp_register', 'bbp_register_taxonomies', 6 );
add_action( 'bbp_register', 'bbp_register_views', 8 );
add_action( 'bbp_register', 'bbp_register_shortcodes', 10 );
add_action( 'bbp_register', 'bbp_register_meta', 12 );
// Autoembeds
add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 );
add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 );
/**
* bbp_ready - attached to end 'bbp_init' above
*
* Attach actions to the ready action after bbPress has fully initialized.
* The load order helps to execute code at the correct time.
* v---Load order
*/
add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies
add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
// Try to load the bbpress-functions.php file from the active themes
add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
// Widgets
add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget', 'register_widget' ), 10 );
// Notices
add_action( 'bbp_template_notices', 'bbp_template_notices', 20 );
add_action( 'bbp_template_notices', 'bbp_login_notices' );
add_action( 'bbp_template_notices', 'bbp_topic_notices' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_pending_email' );
add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
// Always exclude private/hidden forums if needed
add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 );
// Before Delete/Trash/Untrash Forum
add_action( 'wp_trash_post', 'bbp_trash_forum' );
add_action( 'trash_post', 'bbp_trash_forum' );
add_action( 'untrash_post', 'bbp_untrash_forum' );
add_action( 'before_delete_post', 'bbp_delete_forum' );
// After Deleted/Trashed/Untrashed Forum
add_action( 'trashed_post', 'bbp_trashed_forum' );
add_action( 'untrashed_post', 'bbp_untrashed_forum' );
add_action( 'deleted_post', 'bbp_deleted_forum' );
// Auto trash/untrash/delete a forums topics
add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 );
add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 );
add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
// New/Edit Forum
add_action( 'bbp_new_forum', 'bbp_update_forum', 10 );
add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
// Save forum extra metadata
add_action( 'bbp_new_forum_post_extras', 'bbp_save_forum_extras', 2 );
add_action( 'bbp_edit_forum_post_extras', 'bbp_save_forum_extras', 2 );
add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
// New/Edit Reply
add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 7 );
add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
// Before Delete/Trash/Untrash Reply
add_action( 'wp_trash_post', 'bbp_trash_reply' );
add_action( 'trash_post', 'bbp_trash_reply' );
add_action( 'untrash_post', 'bbp_untrash_reply' );
add_action( 'before_delete_post', 'bbp_delete_reply' );
// After Deleted/Trashed/Untrashed Reply
add_action( 'trashed_post', 'bbp_trashed_reply' );
add_action( 'untrashed_post', 'bbp_untrashed_reply' );
add_action( 'deleted_post', 'bbp_deleted_reply' );
// New/Edit Topic
add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 );
add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
// Split/Merge Topic
add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 );
add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
// Move Reply
add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 );
// Before Delete/Trash/Untrash Topic
add_action( 'wp_trash_post', 'bbp_trash_topic' );
add_action( 'trash_post', 'bbp_trash_topic' );
add_action( 'untrash_post', 'bbp_untrash_topic' );
add_action( 'before_delete_post', 'bbp_delete_topic' );
// After Deleted/Trashed/Untrashed Topic
add_action( 'trashed_post', 'bbp_trashed_topic' );
add_action( 'untrashed_post', 'bbp_untrashed_topic' );
add_action( 'deleted_post', 'bbp_deleted_topic' );
// Favorites
add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_favorites' );
add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' );
add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
// Subscriptions
add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' );
add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' );
// Subscription notifications
add_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 );
add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 );
// Sticky
add_action( 'bbp_stick_topic', 'bbp_unstick_topic' );
add_action( 'bbp_unapprove_topic', 'bbp_unstick_topic' );
add_action( 'bbp_spam_topic', 'bbp_unstick_topic' );
add_action( 'bbp_trash_topic', 'bbp_unstick_topic' );
add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
// Update topic branch
add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_approved_topic', 'bbp_update_topic_walker' );
add_action( 'bbp_unapproved_topic', 'bbp_update_topic_walker' );
// Update reply branch
add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_approved_reply', 'bbp_update_reply_walker' );
add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' );
// Update forum reply counts
add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_forum_reply_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_forum_reply_count' );
add_action( 'bbp_unapprove_reply', 'bbp_decrease_forum_reply_count' );
// Update forum hidden reply counts
add_action( 'bbp_trashed_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_spammed_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_unapproved_reply', 'bbp_increase_forum_reply_count_hidden' );
add_action( 'bbp_untrash_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_unspam_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_approve_reply', 'bbp_decrease_forum_reply_count_hidden' );
add_action( 'bbp_delete_reply', 'bbp_decrease_forum_reply_count_hidden' );
// Update forum topic counts
add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' );
add_action( 'bbp_trash_topic', 'bbp_decrease_forum_topic_count' );
add_action( 'bbp_spam_topic', 'bbp_decrease_forum_topic_count' );
add_action( 'bbp_unapprove_topic', 'bbp_decrease_forum_topic_count' );
// Update forum hidden topic counts
add_action( 'bbp_trashed_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_spammed_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
add_action( 'bbp_untrash_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_unspam_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_approve_topic', 'bbp_decrease_forum_topic_count_hidden' );
add_action( 'bbp_delete_topic', 'bbp_decrease_forum_topic_count_hidden' );
// Update topic reply counts
add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_topic_reply_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_topic_reply_count' );
add_action( 'bbp_unapprove_reply', 'bbp_decrease_topic_reply_count' );
// Update topic hidden reply counts
add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' );
add_action( 'bbp_untrash_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_unspam_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_approve_reply', 'bbp_decrease_topic_reply_count_hidden' );
add_action( 'bbp_delete_reply', 'bbp_decrease_topic_reply_count_hidden' );
// Update forum reply counts for approved/unapproved topics
add_action( 'bbp_approved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
// Users topic & reply counts
add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_untrash_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_untrash_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_unspam_topic', 'bbp_increase_user_topic_count' );
add_action( 'bbp_unspam_reply', 'bbp_increase_user_reply_count' );
add_action( 'bbp_trash_topic', 'bbp_decrease_user_topic_count' );
add_action( 'bbp_trash_reply', 'bbp_decrease_user_reply_count' );
add_action( 'bbp_spam_topic', 'bbp_decrease_user_topic_count' );
add_action( 'bbp_spam_reply', 'bbp_decrease_user_reply_count' );
// Topic status transition helpers for replies
add_action( 'bbp_trash_topic', 'bbp_trash_topic_replies' );
add_action( 'bbp_untrash_topic', 'bbp_untrash_topic_replies' );
add_action( 'bbp_delete_topic', 'bbp_delete_topic_replies' );
add_action( 'bbp_spam_topic', 'bbp_spam_topic_replies' );
add_action( 'bbp_unspam_topic', 'bbp_unspam_topic_replies' );
// Topic engagements on user creation
add_action( 'bbp_new_topic', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_new_reply', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_new_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_new_topic', 'bbp_update_topic_voice_count', 30 );
// Topic/reply counts on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
// Topic engagements on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_update_topic_engagements', 20 );
add_action( 'bbp_insert_reply', 'bbp_update_topic_engagements', 20 );
// Topic engagement counts on code insert (unit tests)
add_action( 'bbp_insert_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count', 30 );
// Recalculate engagements
add_action( 'bbp_trashed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_untrashed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_spammed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unspammed_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_approved_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unapproved_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_deleted_reply', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_trashed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_untrashed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_spammed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unspammed_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_approved_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_unapproved_topic', 'bbp_recalculate_topic_engagements' );
add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' );
// Update engagement counts
add_action( 'bbp_trashed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_untrashed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_spammed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unspammed_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_approved_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_deleted_reply', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_trashed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_untrashed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_spammed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unspammed_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_approved_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_unapproved_topic', 'bbp_update_topic_voice_count', 30 );
add_action( 'bbp_deleted_topic', 'bbp_update_topic_voice_count', 30 );
// User status
// @todo make these sub-actions
add_action( 'make_ham_user', 'bbp_make_ham_user' );
add_action( 'make_spam_user', 'bbp_make_spam_user' );
// User role
add_action( 'bbp_profile_update', 'bbp_profile_update_role' );
// Hook WordPress admin actions to bbPress profiles on save
add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
// Clean bbPress post caches when WordPress's is cleaned
add_action( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
// User Registration
add_action( 'added_existing_user', 'bbp_user_add_role_on_register', 10, 1 );
add_action( 'bbp_user_register', 'bbp_user_add_role_on_register', 10, 1 );
// Invite a New User
add_action( 'invite_user', 'bbp_user_add_role_on_invite', 10, 3 );
// Multisite Activation (does not work in wp-activate.php)
add_action( 'wpmu_activate_user', 'bbp_user_add_role_on_activate', 10, 3 );
/**
* bbPress needs to redirect the user around in a few different circumstances:
*
* 1. POST and GET requests
* 2. Accessing private or hidden content (forums/topics/replies)
* 3. Editing forums, topics, replies, users, and tags
* 4. bbPress specific AJAX requests
*/
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1 );
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', 1 );
add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1 );
add_action( 'bbp_template_redirect', 'bbp_post_request', 10 );
add_action( 'bbp_template_redirect', 'bbp_get_request', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 );
add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
// Must be after bbp_template_include_theme_compat
add_action( 'bbp_template_redirect', 'bbp_remove_adjacent_posts', 10 );
// Theme-side POST requests
add_action( 'bbp_post_request', 'bbp_do_ajax', 1 );
add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_user_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_forum_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_reply_handler', 1 );
add_action( 'bbp_post_request', 'bbp_edit_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_merge_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_split_topic_handler', 1 );
add_action( 'bbp_post_request', 'bbp_move_reply_handler', 1 );
add_action( 'bbp_post_request', 'bbp_new_forum_handler', 10 );
add_action( 'bbp_post_request', 'bbp_new_reply_handler', 10 );
add_action( 'bbp_post_request', 'bbp_new_topic_handler', 10 );
// Theme-side GET requests
add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 );
add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 );
add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
add_action( 'bbp_get_request', 'bbp_user_email_change_handler', 1 );
add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 );
// Maybe convert the users password
add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );

View File

@@ -0,0 +1,168 @@
<?php
/**
* bbPress Cache Helpers
*
* Helper functions used to communicate with WordPress's various caches. Many
* of these functions are used to work around specific WordPress nuances. They
* are subject to changes, tweaking, and will need iteration as performance
* improvements are made to WordPress core.
*
* @package bbPress
* @subpackage Cache
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Helpers *******************************************************************/
/**
* Skip invalidation of child post content when editing a parent.
*
* This prevents invalidating caches for topics and replies when editing a forum
* or a topic. Without this in place, WordPress will attempt to invalidate all
* child posts whenever a parent post is modified. This can cause thousands of
* cache invalidations to occur on a single edit, which is no good for anyone.
*
* @since 2.1.0 bbPress (r4011)
*
* @package bbPress
* @subpackage Cache
*/
class BBP_Skip_Children {
/**
* @var int Post ID being updated
*/
private $updating_post = 0;
/**
* @var bool The original value of $_wp_suspend_cache_invalidation global
*/
private $original_cache_invalidation = false;
/** Methods ***************************************************************/
/**
* Hook into the 'pre_post_update' action.
*
* @since 2.1.0 bbPress (r4011)
*/
public function __construct() {
add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
}
/**
* Only clean post caches for main bbPress posts.
*
* Check that the post being updated is a bbPress post type, saves the
* post ID to be used later, and adds an action to 'clean_post_cache' that
* prevents child post caches from being cleared.
*
* @since 2.1.0 bbPress (r4011)
*
* @param int $post_id The post ID being updated
* @return If invalid post data
*/
public function pre_post_update( $post_id = 0 ) {
// Bail if post ID is not a bbPress post type
if ( empty( $post_id ) || ! bbp_is_custom_post_type( $post_id ) ) {
return;
}
// Store the $post_id
$this->updating_post = $post_id;
// Skip related post cache invalidation. This prevents invalidating the
// caches of the child posts when there is no reason to do so.
add_action( 'clean_post_cache', array( $this, 'skip_related_posts' ) );
}
/**
* Skip cache invalidation of related posts if the post ID being invalidated
* is not the one that was just updated.
*
* @since 2.1.0 bbPress (r4011)
*
* @param int $post_id The post ID of the cache being invalidated
* @return If invalid post data
*/
public function skip_related_posts( $post_id = 0 ) {
// Bail if this post is not the current bbPress post
if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) ) {
return;
}
// Stash the current cache invalidation value in a variable, so we can
// restore back to it nicely in the future.
global $_wp_suspend_cache_invalidation;
$this->original_cache_invalidation = $_wp_suspend_cache_invalidation;
// Turn off cache invalidation
wp_suspend_cache_invalidation( true );
// Restore cache invalidation
add_action( 'wp_insert_post', array( $this, 'restore_cache_invalidation' ) );
}
/**
* Restore the cache invalidation to its previous value.
*
* @since 2.1.0 bbPress (r4011)
*/
public function restore_cache_invalidation() {
wp_suspend_cache_invalidation( $this->original_cache_invalidation );
}
}
new BBP_Skip_Children();
/** General *******************************************************************/
/**
* Will clean a post in the cache.
*
* Will call to clean the term object cache associated with the post ID.
*
* @since 2.1.0 bbPress (r4040)
* @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter.
*
* @param int $post_id The post id.
* @param WP_Post $post The WP_Post object.
*/
function bbp_clean_post_cache( $post_id = null, $post = null ) {
// Child query types to clean
$post_types = array(
bbp_get_forum_post_type(),
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
);
// Bail if not a bbPress post type
if ( ! in_array( $post->post_type, $post_types, true ) ) {
return;
}
/**
* Fires immediately after the given post cache is cleaned.
*
* @since 2.1.0
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
do_action( 'bbp_clean_post_cache', $post->ID, $post );
// Invalidate parent caches
if ( ! empty( $post->post_parent ) ) {
clean_post_cache( $post->post_parent );
// Only bump `last_changed` when forum-root is reached
} else {
wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
}
}

View File

@@ -0,0 +1,525 @@
<?php
/**
* bbPress Capabilites
*
* The functions in this file are used primarily as convenient wrappers for
* capability output in user profiles. This includes mapping capabilities and
* groups to human readable strings,
*
* @package bbPress
* @subpackage Capabilities
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Mapping *******************************************************************/
/**
* Returns an array of capabilities based on the role that is being requested.
*
* @since 2.0.0 bbPress (r2994)
*
* @todo Map all of these and deprecate
*
* @param string $role Optional. Defaults to The role to load caps for
*
* @return array Capabilities for $role
*/
function bbp_get_caps_for_role( $role = '' ) {
// Which role are we looking for?
switch ( $role ) {
// Keymaster
case bbp_get_keymaster_role() :
$caps = array(
// Keymasters only
'keep_gate' => true,
// Primary caps
'spectate' => true,
'participate' => true,
'moderate' => true,
'throttle' => true,
'view_trash' => true,
'assign_moderators' => true,
// Forum caps
'publish_forums' => true,
'edit_forums' => true,
'edit_others_forums' => true,
'delete_forums' => true,
'delete_others_forums' => true,
'read_private_forums' => true,
'read_hidden_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
'edit_others_topics' => true,
'delete_topics' => true,
'delete_others_topics' => true,
'read_private_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
'edit_others_replies' => true,
'delete_replies' => true,
'delete_others_replies' => true,
'read_private_replies' => true,
// Topic tag caps
'manage_topic_tags' => true,
'edit_topic_tags' => true,
'delete_topic_tags' => true,
'assign_topic_tags' => true
);
break;
// Moderator
case bbp_get_moderator_role() :
$caps = array(
// Primary caps
'spectate' => true,
'participate' => true,
'moderate' => true,
'throttle' => true,
'view_trash' => true,
'assign_moderators' => true,
// Forum caps
'publish_forums' => true,
'edit_forums' => true,
'read_private_forums' => true,
'read_hidden_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
'edit_others_topics' => true,
'delete_topics' => true,
'delete_others_topics' => true,
'read_private_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
'edit_others_replies' => true,
'delete_replies' => true,
'delete_others_replies' => true,
'read_private_replies' => true,
// Topic tag caps
'manage_topic_tags' => true,
'edit_topic_tags' => true,
'delete_topic_tags' => true,
'assign_topic_tags' => true,
);
break;
// Spectators can only read
case bbp_get_spectator_role() :
$caps = array(
// Primary caps
'spectate' => true,
);
break;
// Explicitly blocked
case bbp_get_blocked_role() :
$caps = array(
// Primary caps
'spectate' => false,
'participate' => false,
'moderate' => false,
'throttle' => false,
'view_trash' => false,
// Forum caps
'publish_forums' => false,
'edit_forums' => false,
'edit_others_forums' => false,
'delete_forums' => false,
'delete_others_forums' => false,
'read_private_forums' => false,
'read_hidden_forums' => false,
// Topic caps
'publish_topics' => false,
'edit_topics' => false,
'edit_others_topics' => false,
'delete_topics' => false,
'delete_others_topics' => false,
'read_private_topics' => false,
// Reply caps
'publish_replies' => false,
'edit_replies' => false,
'edit_others_replies' => false,
'delete_replies' => false,
'delete_others_replies' => false,
'read_private_replies' => false,
// Topic tag caps
'manage_topic_tags' => false,
'edit_topic_tags' => false,
'delete_topic_tags' => false,
'assign_topic_tags' => false,
);
break;
// Participant/Default
case bbp_get_participant_role() :
default :
$caps = array(
// Primary caps
'spectate' => true,
'participate' => true,
// Forum caps
'read_private_forums' => true,
// Topic caps
'publish_topics' => true,
'edit_topics' => true,
// Reply caps
'publish_replies' => true,
'edit_replies' => true,
// Topic tag caps
'assign_topic_tags' => true,
);
break;
}
// Filter & return
return apply_filters( 'bbp_get_caps_for_role', $caps, $role );
}
/**
* Adds capabilities to WordPress user roles.
*
* @since 2.0.0 bbPress (r2608)
*/
function bbp_add_caps() {
// Loop through available roles and add caps
foreach ( bbp_get_wp_roles()->role_objects as $role ) {
foreach ( bbp_get_caps_for_role( $role->name ) as $cap => $value ) {
$role->add_cap( $cap, $value );
}
}
do_action( 'bbp_add_caps' );
}
/**
* Removes capabilities from WordPress user roles.
*
* @since 2.0.0 bbPress (r2608)
*/
function bbp_remove_caps() {
// Loop through available roles and remove caps
foreach ( bbp_get_wp_roles()->role_objects as $role ) {
foreach ( array_keys( bbp_get_caps_for_role( $role->name ) ) as $cap ) {
$role->remove_cap( $cap );
}
}
do_action( 'bbp_remove_caps' );
}
/**
* Get the available roles, minus the dynamic roles that come with bbPress
*
* @since 2.4.0 bbPress (r5064)
*
* @return array
*/
function bbp_get_blog_roles() {
// Get WordPress's roles (returns $wp_roles global)
$wp_roles = bbp_get_wp_roles();
// Apply the WordPress 'editable_roles' filter to let plugins ride along.
//
// We use this internally via bbp_filter_blog_editable_roles() to remove
// any custom bbPress roles that are added to the global.
$the_roles = isset( $wp_roles->roles ) ? $wp_roles->roles : false;
$all_roles = apply_filters( 'editable_roles', $the_roles );
// Filter & return
return apply_filters( 'bbp_get_blog_roles', $all_roles, $wp_roles );
}
/** Forum Roles ***************************************************************/
/**
* Add the bbPress roles to the $wp_roles global.
*
* We do this to avoid adding these values to the database.
*
* Note: bbPress is purposely assertive here, overwriting any keys & values
* that may already exist in the $wp_roles array.
*
* @since 2.2.0 bbPress (r4290)
*
* @param WP_Roles $wp_roles The array of WP_Role objects that was initialized
*
* @return WP_Roles The main $wp_roles global
*/
function bbp_add_forums_roles( $wp_roles = null ) {
// Get the dynamic roles
$bbp_roles = bbp_get_dynamic_roles();
// Loop through dynamic roles and add them to the $wp_roles array
foreach ( $bbp_roles as $role_id => $details ) {
$wp_roles->roles[ $role_id ] = $details;
$wp_roles->role_objects[ $role_id ] = new WP_Role( $role_id, $details['capabilities'] );
$wp_roles->role_names[ $role_id ] = $details['name'];
}
// Return the modified $wp_roles array
return $wp_roles;
}
/**
* Helper function to add filter to option_wp_user_roles
*
* @since 2.2.0 bbPress (r4363)
* @deprecated 2.6.0 bbPress (r6105)
*
* @see _bbp_reinit_dynamic_roles()
*/
function bbp_filter_user_roles_option() {
$role_key = bbp_db()->prefix . 'user_roles';
add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' );
}
/**
* This is necessary because in a few places (noted below) WordPress initializes
* a blog's roles directly from the database option. When this happens, the
* $wp_roles global gets flushed, causing a user to magically lose any
* dynamically assigned roles or capabilities when $current_user in refreshed.
*
* Because dynamic multiple roles is a new concept in WordPress, we work around
* it here for now, knowing that improvements will come to WordPress core later.
*
* Also note that if using the $wp_user_roles global non-database approach,
* bbPress does not have an intercept point to add its dynamic roles.
*
* @see bbp_switch_to_site()
* @see bbp_restore_current_site()
* @see WP_Roles::_init()
*
* @since 2.2.0 bbPress (r4363)
* @deprecated 2.6.0 bbPress (r6105)
*
* @internal Used by bbPress to reinitialize dynamic roles on blog switch
*
* @param array $roles
* @return array Combined array of database roles and dynamic bbPress roles
*/
function _bbp_reinit_dynamic_roles( $roles = array() ) {
foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
$roles[ $role_id ] = $details;
}
return $roles;
}
/**
* Fetch a filtered list of forum roles that the current user is
* allowed to have.
*
* Simple function who's main purpose is to allow filtering of the
* list of forum roles so that plugins can remove inappropriate ones depending
* on the situation or user making edits.
*
* Specifically because without filtering, anyone with the edit_users
* capability can edit others to be administrators, even if they are
* only editors or authors. This filter allows admins to delegate
* user management.
*
* @since 2.2.0 bbPress (r4284)
* @since 2.6.0 bbPress (r6117) Use bbpress()->roles
*
* @return array
*/
function bbp_get_dynamic_roles() {
// Defaults
$to_array = array();
$roles = bbpress()->roles;
// Convert WP_Roles objects to arrays
foreach ( $roles as $role_id => $wp_role ) {
$to_array[ $role_id ] = (array) $wp_role;
}
// Filter & return
return (array) apply_filters( 'bbp_get_dynamic_roles', $to_array, $roles );
}
/**
* Gets a translated role name from a role ID
*
* @since 2.3.0 bbPress (r4792)
* @since 2.6.0 bbPress (r6117) Use bbp_translate_user_role()
*
* @param string $role_id
* @return string Translated role name
*/
function bbp_get_dynamic_role_name( $role_id = '' ) {
$roles = bbp_get_dynamic_roles();
$role = isset( $roles[ $role_id ] )
? bbp_translate_user_role( $roles[ $role_id ]['name'] )
: '';
// Filter & return
return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
}
/**
* Removes the bbPress roles from the editable roles array
*
* This used to use array_diff_assoc() but it randomly broke before 2.2 release.
* Need to research what happened, and if there's a way to speed this up.
*
* @since 2.2.0 bbPress (r4303)
*
* @param array $all_roles All registered roles
* @return array
*/
function bbp_filter_blog_editable_roles( $all_roles = array() ) {
// Loop through bbPress roles
foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
// Loop through WordPress roles
foreach ( array_keys( $all_roles ) as $wp_role ) {
// If keys match, unset
if ( $wp_role === $bbp_role ) {
unset( $all_roles[ $wp_role ] );
}
}
}
return $all_roles;
}
/**
* The keymaster role for bbPress users
*
* @since 2.2.0 bbPress (r4284)
*
* @return string
*/
function bbp_get_keymaster_role() {
// Filter & return
return apply_filters( 'bbp_get_keymaster_role', 'bbp_keymaster' );
}
/**
* The moderator role for bbPress users
*
* @since 2.0.0 bbPress (r3410)
*
* @return string
*/
function bbp_get_moderator_role() {
// Filter & return
return apply_filters( 'bbp_get_moderator_role', 'bbp_moderator' );
}
/**
* The participant role for registered user that can participate in forums
*
* @since 2.0.0 bbPress (r3410)
*
* @return string
*/
function bbp_get_participant_role() {
// Filter & return
return apply_filters( 'bbp_get_participant_role', 'bbp_participant' );
}
/**
* The spectator role is for registered users without any capabilities
*
* @since 2.1.0 bbPress (r3860)
*
* @return string
*/
function bbp_get_spectator_role() {
// Filter & return
return apply_filters( 'bbp_get_spectator_role', 'bbp_spectator' );
}
/**
* The blocked role is for registered users that cannot spectate or participate
*
* @since 2.2.0 bbPress (r4284)
*
* @return string
*/
function bbp_get_blocked_role() {
// Filter & return
return apply_filters( 'bbp_get_blocked_role', 'bbp_blocked' );
}
/**
* Adds bbPress-specific user roles.
*
* @since 2.0.0 bbPress (r2741)
*
* @deprecated 2.2.0 bbPress (r4164)
*/
function bbp_add_roles() {
_doing_it_wrong( 'bbp_add_roles', esc_html__( 'Editable forum roles no longer exist.', 'bbpress' ), '2.2' );
}
/**
* Removes bbPress-specific user roles from the `wp_user_roles` array.
*
* This is currently only used when updating, uninstalling, or resetting bbPress.
*
* @see bbp_admin_reset_handler()
* @see bbp_do_uninstall()
* @see bbp_version_updater()
*
* @since 2.0.0 bbPress (r2741)
*/
function bbp_remove_roles() {
// Remove the bbPress roles
foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
remove_role( $bbp_role );
}
// Some early adopters may have a deprecated visitor role. It was later
// replaced by the Spectator role.
remove_role( 'bbp_visitor' );
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* bbPress Extentions
*
* There's a world of really cool plugins out there, and bbPress comes with
* support for some of the most popular ones.
*
* @package bbPress
* @subpackage Extend
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Loads Akismet inside the bbPress global class
*
* @since 2.0.0 bbPress (r3277)
*
* @return If bbPress is not active
*/
function bbp_setup_akismet() {
// Bail if no akismet
if ( ! defined( 'AKISMET_VERSION' ) ) {
return;
}
// Bail if Akismet is turned off
if ( ! bbp_is_akismet_active() ) {
return;
}
// Include the Akismet Component
require_once bbpress()->includes_dir . 'extend/akismet.php';
// Instantiate Akismet for bbPress
bbpress()->extend->akismet = new BBP_Akismet();
}
/**
* Requires and creates the BuddyPress extension, and adds component creation
* action to bp_init hook. @see bbp_setup_buddypress_component()
*
* @since 2.0.0 bbPress (r3395)
*
* @return If BuddyPress is not active
*/
function bbp_setup_buddypress() {
if ( ! function_exists( 'buddypress' ) ) {
/**
* Helper for BuddyPress 1.6 and earlier
*
* @since 2.2.0 bbPress (r4395)
*
* @return BuddyPress
*/
function buddypress() {
return isset( $GLOBALS['bp'] ) ? $GLOBALS['bp'] : false;
}
}
// Bail if in maintenance mode
if ( ! buddypress() || buddypress()->maintenance_mode ) {
return;
}
// Include the BuddyPress Component
require_once bbpress()->includes_dir . 'extend/buddypress/loader.php';
// Instantiate BuddyPress for bbPress
bbpress()->extend->buddypress = new BBP_Forums_Component();
}

View File

@@ -0,0 +1,421 @@
<?php
/**
* bbPress Filters
*
* This file contains the filters that are used through-out bbPress. They are
* consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional filters can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
*
* @package bbPress
* @subpackage Core
*
* @see /core/actions.php
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_filter( 'request', 'bbp_request', 10 );
add_filter( 'template_include', 'bbp_template_include', 10 );
add_filter( 'wp_mail', 'bbp_mail', 10, 3 );
add_filter( 'wp_title', 'bbp_title', 10, 3 );
add_filter( 'body_class', 'bbp_body_class', 10, 2 );
add_filter( 'map_meta_cap', 'bbp_map_meta_caps', 10, 4 );
add_filter( 'allowed_themes', 'bbp_allowed_themes', 10 );
add_filter( 'redirect_canonical', 'bbp_redirect_canonical', 10 );
add_filter( 'login_redirect', 'bbp_redirect_login', 2, 3 );
add_filter( 'logout_url', 'bbp_logout_url', 2, 2 );
add_filter( 'plugin_locale', 'bbp_plugin_locale', 10, 2 );
// Fix post author id for anonymous posts (set it back to 0) when the post status is changed
add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 );
// Force comments_status on bbPress post types
add_filter( 'comments_open', 'bbp_force_comment_status' );
// Remove forums roles from list of all roles
add_filter( 'editable_roles', 'bbp_filter_blog_editable_roles' );
// Reply title fallback
add_filter( 'the_title', 'bbp_get_reply_title_fallback', 2, 2 );
// Avoid queries & 404s
add_filter( 'pre_handle_404', 'bbp_pre_handle_404', 10, 2 );
add_action( 'posts_pre_query', 'bbp_posts_pre_query', 10, 2 );
// User Creation
add_filter( 'signup_user_meta', 'bbp_user_add_role_to_signup_meta', 10 );
/**
* Emails
*
* bbPress sends emails for a few different reasons, largely related to user
* notifications or account changes. Because the `wp_mail` filter can be a
* crowded space, the `bbp_mail` subfilter should be used in conjunction with
* bbp_get_email_header() to narrow the results to only bbPress emails.
*/
add_filter( 'bbp_mail', 'bbp_chunk_emails' );
/**
* Feeds
*
* bbPress comes with a number of custom RSS2 feeds that get handled outside
* the normal scope of feeds that WordPress would normally serve. To do this,
* we filter every page request, listen for a feed request, and trap it.
*/
add_filter( 'bbp_request', 'bbp_request_feed_trap' );
/**
* Template Compatibility
*
* If you want to completely bypass this and manage your own custom bbPress
* template hierarchy, start here by removing this filter, then look at how
* bbp_template_include() works and do something similar. :)
*/
add_filter( 'bbp_template_include', 'bbp_template_include_theme_supports', 2, 1 );
add_filter( 'bbp_template_include', 'bbp_template_include_theme_compat', 4, 2 );
// Filter bbPress template locations
add_filter( 'bbp_get_template_stack', 'bbp_add_template_stack_locations' );
// Links
add_filter( 'paginate_links', 'bbp_add_view_all' );
add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_reply_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
// wp_filter_kses on new/edit forum/topic/reply title
add_filter( 'bbp_new_forum_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_forum_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' );
// Prevent posting malicious or malformed content on new/edit topic/reply
add_filter( 'bbp_new_reply_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_reply_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_reply_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_reply_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_topic_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_topic_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_new_forum_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_new_forum_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_reply_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_reply_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_topic_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_topic_pre_content', 'balanceTags', 40 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_encode_bad', 10 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_code_trick', 20 );
add_filter( 'bbp_edit_forum_pre_content', 'bbp_filter_kses', 30 );
add_filter( 'bbp_edit_forum_pre_content', 'balanceTags', 40 );
// No follow and wp_unslash on links
add_filter( 'bbp_get_reply_author_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_reply_author_link', 'wp_unslash' );
add_filter( 'bbp_get_reply_to_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_reply_to_link', 'wp_unslash' );
add_filter( 'bbp_get_topic_author_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_topic_author_link', 'wp_unslash' );
add_filter( 'bbp_get_topic_reply_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_topic_reply_link', 'wp_unslash' );
add_filter( 'bbp_get_user_favorites_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_favorites_link', 'wp_unslash' );
add_filter( 'bbp_get_user_subscribe_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_subscribe_link', 'wp_unslash' );
add_filter( 'bbp_get_user_profile_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_link', 'wp_unslash' );
add_filter( 'bbp_get_user_profile_edit_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_edit_link', 'wp_unslash' );
add_filter( 'bbp_get_cancel_reply_to_link', 'bbp_rel_nofollow' );
add_filter( 'bbp_get_cancel_reply_to_link', 'wp_unslash' );
// Run filters on reply content
add_filter( 'bbp_get_reply_content', 'wptexturize', 6 );
add_filter( 'bbp_get_reply_content', 'convert_chars', 8 );
add_filter( 'bbp_get_reply_content', 'capital_P_dangit', 10 );
add_filter( 'bbp_get_reply_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_reply_content', 'force_balance_tags', 30 );
add_filter( 'bbp_get_reply_content', 'bbp_make_clickable', 40 );
add_filter( 'bbp_get_reply_content', 'wpautop', 50 );
add_filter( 'bbp_get_reply_content', 'bbp_rel_nofollow', 60 );
// Run filters on topic content
add_filter( 'bbp_get_topic_content', 'wptexturize', 6 );
add_filter( 'bbp_get_topic_content', 'convert_chars', 8 );
add_filter( 'bbp_get_topic_content', 'capital_P_dangit', 10 );
add_filter( 'bbp_get_topic_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_topic_content', 'force_balance_tags', 30 );
add_filter( 'bbp_get_topic_content', 'bbp_make_clickable', 40 );
add_filter( 'bbp_get_topic_content', 'wpautop', 50 );
add_filter( 'bbp_get_topic_content', 'bbp_rel_nofollow', 60 );
// Admin-only
if ( is_admin() ) {
// Run wp_kses_data on topic/reply content in admin section
add_filter( 'bbp_get_reply_content', 'bbp_kses_data' );
add_filter( 'bbp_get_topic_content', 'bbp_kses_data' );
// Filters outside of wp-admin
} else {
// WordPress 5.5.x and above
if ( function_exists( 'wp_filter_content_tags' ) ) {
// Responsive images
add_filter( 'bbp_get_reply_content', 'wp_filter_content_tags', 60 );
add_filter( 'bbp_get_topic_content', 'wp_filter_content_tags', 60 );
// WordPress 5.4.x and below
} else {
// Responsive images
add_filter( 'bbp_get_reply_content', 'wp_make_content_images_responsive', 60 );
add_filter( 'bbp_get_topic_content', 'wp_make_content_images_responsive', 60 );
}
// Revisions
add_filter( 'bbp_get_reply_content', 'bbp_reply_content_append_revisions', 99, 2 );
add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_revisions', 99, 2 );
}
// Form textarea output - undo the code-trick done pre-save, and sanitize
add_filter( 'bbp_get_form_forum_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
add_filter( 'bbp_get_form_forum_content', 'trim' );
add_filter( 'bbp_get_form_topic_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
add_filter( 'bbp_get_form_topic_content', 'trim' );
add_filter( 'bbp_get_form_reply_content', 'bbp_code_trick_reverse' );
add_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
add_filter( 'bbp_get_form_reply_content', 'trim' );
// Form input/output - sanitize
add_filter( 'bbp_get_form_reply_edit_reason', 'esc_attr' );
add_filter( 'bbp_get_form_reply_edit_reason', 'trim' );
add_filter( 'bbp_get_form_topic_edit_reason', 'esc_attr' );
add_filter( 'bbp_get_form_topic_edit_reason', 'trim' );
add_filter( 'bbp_get_form_topic_title', 'esc_attr' );
add_filter( 'bbp_get_form_topic_title', 'trim' );
add_filter( 'bbp_get_form_topic_tags', 'esc_attr' );
add_filter( 'bbp_get_form_topic_tags', 'trim' );
add_filter( 'bbp_get_form_forum_type', 'esc_attr' );
add_filter( 'bbp_get_form_forum_type', 'trim' );
add_filter( 'bbp_get_form_forum_visibility', 'esc_attr' );
add_filter( 'bbp_get_form_forum_visibility', 'trim' );
add_filter( 'bbp_get_form_forum_moderators', 'esc_attr' );
add_filter( 'bbp_get_form_forum_moderators', 'trim' );
add_filter( 'bbp_get_form_topic_forum', 'intval' );
add_filter( 'bbp_get_form_forum_parent', 'intval' );
add_filter( 'bbp_get_form_reply_to', 'intval' );
// Add number format filter to functions requesting formatted values
add_filter( 'bbp_get_user_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_subforum_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_voice_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_revision_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_reply_revision_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_topic_count_hidden', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_reply_count_hidden', 'bbp_number_format', 10 );
// Add number-not-negative filter to values that can never be negative numbers
add_filter( 'bbp_get_user_topic_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_subforum_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_voice_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_post_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_hidden', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_hidden', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_revision_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_reply_revision_count', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_topic_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_user_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_subforum_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_voice_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_post_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_forum_topic_count_hidden_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_reply_count_hidden_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_topic_revision_count_int', 'bbp_number_not_negative', 8 );
add_filter( 'bbp_get_reply_revision_count_int', 'bbp_number_not_negative', 8 );
// Sanitize displayed user data
add_filter( 'bbp_get_displayed_user_field', 'bbp_sanitize_displayed_user_field', 10, 3 );
// Suppress private forum details
add_filter( 'bbp_get_forum_topic_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_post_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_freshness_link', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 );
// Allow private & hidden forum details for moderators
add_filter( 'bbp_get_excluded_forum_ids', 'bbp_allow_forums_of_user', 10, 2 );
// Topic and reply author display names
add_filter( 'bbp_get_topic_author_display_name', 'wptexturize' );
add_filter( 'bbp_get_topic_author_display_name', 'convert_chars' );
add_filter( 'bbp_get_topic_author_display_name', 'esc_html' );
add_filter( 'bbp_get_reply_author_display_name', 'wptexturize' );
add_filter( 'bbp_get_reply_author_display_name', 'convert_chars' );
add_filter( 'bbp_get_reply_author_display_name', 'esc_html' );
/**
* Add filters to anonymous post author data
*/
// Post author name
add_filter( 'bbp_pre_anonymous_post_author_name', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'sanitize_text_field', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'wp_filter_kses', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', '_wp_specialchars', 30 );
// Save email
add_filter( 'bbp_pre_anonymous_post_author_email', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'sanitize_email', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'wp_filter_kses', 10 );
// Save URL
add_filter( 'bbp_pre_anonymous_post_author_website', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_strip_all_tags', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'esc_url_raw', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_filter_kses', 10 );
// Queries
add_filter( 'posts_request', '_bbp_has_replies_where', 10, 2 );
// Capabilities
add_filter( 'bbp_map_meta_caps', 'bbp_map_primary_meta_caps', 10, 4 ); // Primary caps
add_filter( 'bbp_map_meta_caps', 'bbp_map_forum_meta_caps', 10, 4 ); // Forums
add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_meta_caps', 10, 4 ); // Topics
add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_tag_meta_caps', 10, 4 ); // Topic tags
add_filter( 'bbp_map_meta_caps', 'bbp_map_reply_meta_caps', 10, 4 ); // Replies
// Clickables
add_filter( 'bbp_make_clickable', 'bbp_make_urls_clickable', 2 ); // https://bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_ftps_clickable', 4 ); // ftps://bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_emails_clickable', 6 ); // jjj@bbpress.org
add_filter( 'bbp_make_clickable', 'bbp_make_mentions_clickable', 8 ); // @jjj
/** Deprecated ****************************************************************/
/**
* The following filters are deprecated.
*
* These filters were most likely replaced by bbp_parse_args(), which includes
* both passive and aggressive filters anywhere parse_args is used to compare
* default arguments to passed arguments, without sprinkling the project with
* _before_ and _after_ filters everywhere.
*/
/**
* Deprecated locale filter
*
* @since 2.2.0 bbPress (r4213)
*
* @param string $locale
* @return string $domain
*/
function _bbp_filter_locale( $locale = '', $domain = '' ) {
// Only apply to the bbPress text-domain
if ( bbpress()->domain !== $domain ) {
return $locale;
}
return apply_filters( 'bbpress_locale', $locale, $domain );
}
add_filter( 'bbp_plugin_locale', '_bbp_filter_locale', 10, 1 );
/**
* Deprecated forums query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_forums_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_forums_query', $args );
}
add_filter( 'bbp_after_has_forums_parse_args', '_bbp_has_forums_query' );
/**
* Deprecated topics query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_topics_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_topics_query', $args );
}
add_filter( 'bbp_after_has_topics_parse_args', '_bbp_has_topics_query' );
/**
* Deprecated replies query filter
*
* @since 2.1.0 bbPress (r3961)
*
* @param array $args
* @return array
*/
function _bbp_has_replies_query( $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_has_replies_query', $args );
}
add_filter( 'bbp_after_has_replies_parse_args', '_bbp_has_replies_query' );

View File

@@ -0,0 +1,702 @@
<?php
/**
* bbPress Core Functions
*
* @package bbPress
* @subpackage Functions
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Versions ******************************************************************/
/**
* Output the bbPress version
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_version() {
echo bbp_get_version();
}
/**
* Return the bbPress version
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The bbPress version
*/
function bbp_get_version() {
return bbpress()->version;
}
/**
* Output the bbPress asset version
*
* @since 2.6.7 bbPress (r7188)
*/
function bbp_asset_version() {
echo bbp_get_asset_version();
}
/**
* Return the bbPress asset version
*
* @since 2.6.7 bbPress (r7188)
*
* @retrun string The bbPress asset version
*/
function bbp_get_asset_version() {
return bbp_doing_script_debug()
? (string) time()
: bbp_get_version();
}
/**
* Output the bbPress database version
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_db_version() {
echo bbp_get_db_version();
}
/**
* Return the bbPress database version
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The bbPress version
*/
function bbp_get_db_version() {
return bbpress()->db_version;
}
/**
* Output the bbPress database version directly from the database
*
* @since 2.0.0 bbPress (r3468)
*/
function bbp_db_version_raw() {
echo bbp_get_db_version_raw();
}
/**
* Return the bbPress database version directly from the database
*
* @since 2.0.0 bbPress (r3468)
*
* @retrun string The current bbPress version
*/
function bbp_get_db_version_raw() {
return get_option( '_bbp_db_version', '' );
}
/** Post Meta *****************************************************************/
/**
* Update the forum meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $forum_id The forum
*/
function bbp_update_forum_id( $post_id = 0, $forum_id = 0 ) {
// Allow the forum ID to be updated 'just in time' before save
$forum_id = (int) apply_filters( 'bbp_update_forum_id', $forum_id, $post_id );
// Update the post meta forum ID
update_post_meta( $post_id, '_bbp_forum_id', $forum_id );
return $forum_id;
}
/**
* Update the topic meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $topic_id The topic
*/
function bbp_update_topic_id( $post_id = 0, $topic_id = 0 ) {
// Allow the topic ID to be updated 'just in time' before save
$topic_id = (int) apply_filters( 'bbp_update_topic_id', $topic_id, $post_id );
// Update the post meta topic ID
update_post_meta( $post_id, '_bbp_topic_id', $topic_id );
return $topic_id;
}
/**
* Update the reply meta ID of a post
*
* @since 2.0.0 bbPress (r3181)
*
* @param int $post_id The post to update
* @param int $reply_id The reply
*/
function bbp_update_reply_id( $post_id = 0, $reply_id = 0 ) {
// Allow the reply ID to be updated 'just in time' before save
$reply_id = (int) apply_filters( 'bbp_update_reply_id', $reply_id, $post_id );
// Update the post meta reply ID
update_post_meta( $post_id, '_bbp_reply_id', $reply_id );
return $reply_id;
}
/**
* Update the reply-to meta ID of a post
*
* @since 2.6.0 bbPress (r5735)
*
* @param int $post_id The post to update
* @param int $reply_id The reply ID
*/
function bbp_update_reply_to_id( $post_id = 0, $reply_id = 0 ) {
// Allow the reply ID to be updated 'just in time' before save
$reply_id = (int) apply_filters( 'bbp_update_reply_to_id', $reply_id, $post_id );
// Update the post meta reply ID
update_post_meta( $post_id, '_bbp_reply_to', $reply_id );
return $reply_id;
}
/** Views *********************************************************************/
/**
* Get the registered views
*
* Does nothing much other than return the {@link $bbp->views} variable
*
* @since 2.0.0 bbPress (r2789)
*
* @return array Views
*/
function bbp_get_views() {
return bbpress()->views;
}
/**
* Register a bbPress view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @param string $title View title
* @param mixed $query_args {@link bbp_has_topics()} arguments.
* @param bool $feed Have a feed for the view? Defaults to true.
* @param string $capability Capability that the current user must have
*
* @return array The just registered (but processed) view
*/
function bbp_register_view( $view, $title, $query_args = '', $feed = true, $capability = '' ) {
// Bail if user does not have capability
if ( ! empty( $capability ) && ! current_user_can( $capability ) ) {
return false;
}
$bbp = bbpress();
$view = sanitize_title( $view );
$title = esc_html( $title );
if ( empty( $view ) || empty( $title ) ) {
return false;
}
$query_args = bbp_parse_args( $query_args, '', 'register_view' );
// Set show_stickies to false if it wasn't supplied
if ( ! isset( $query_args['show_stickies'] ) ) {
$query_args['show_stickies'] = false;
}
$bbp->views[ $view ] = array(
'title' => $title,
'query' => $query_args,
'feed' => $feed
);
return $bbp->views[ $view ];
}
/**
* Deregister a bbPress view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @return bool False if the view doesn't exist, true on success
*/
function bbp_deregister_view( $view ) {
$bbp = bbpress();
$view = sanitize_title( $view );
if ( ! isset( $bbp->views[ $view ] ) ) {
return false;
}
unset( $bbp->views[ $view ] );
return true;
}
/**
* Run the query of a topic-view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view Optional. View id
* @param mixed $new_args New arguments. See {@link bbp_has_topics()}
* @return bool False if the view doesn't exist, otherwise if topics are there
*/
function bbp_view_query( $view = '', $new_args = '' ) {
// Get view, or bail
$view = bbp_get_view_id( $view );
if ( empty( $view ) ) {
return false;
}
$query_args = bbp_get_view_query_args( $view );
if ( ! empty( $new_args ) ) {
$new_args = bbp_parse_args( $new_args, '', 'view_query' );
$query_args = array_merge( $query_args, $new_args );
}
return bbp_has_topics( $query_args );
}
/**
* Return the query arguments of a topic-view
*
* @since 2.0.0 bbPress (r2789)
*
* @param string $view View name
* @return array Query arguments
*/
function bbp_get_view_query_args( $view = '' ) {
$bbp = bbpress();
$view = bbp_get_view_id( $view );
$retval = ! empty( $view ) && ! empty( $bbp->views[ $view ] )
? $bbp->views[ $view ]['query']
: array();
// Filter & return
return (array) apply_filters( 'bbp_get_view_query_args', $retval, $view );
}
/** Errors ********************************************************************/
/**
* Adds an error message to later be output in the theme
*
* @since 2.0.0 bbPress (r3381)
*
* @see WP_Error()
*
* @param string $code Unique code for the error message
* @param string $message Translated error message
* @param string $data Any additional data passed with the error message
*/
function bbp_add_error( $code = '', $message = '', $data = '' ) {
bbpress()->errors->add( $code, $message, $data );
}
/**
* Check if error messages exist in queue
*
* @since 2.0.0 bbPress (r3381)
*
* @see WP_Error()
*/
function bbp_has_errors() {
$has_errors = bbpress()->errors->get_error_codes()
? true
: false;
return (bool) apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors );
}
/** Mentions ******************************************************************/
/**
* Set the pattern used for matching usernames for mentions.
*
* Moved into its own function to allow filtering of the regex pattern
* anywhere mentions might be used.
*
* @since 2.4.0 bbPress (r4997)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @return string Pattern to match usernames with
*/
function bbp_find_mentions_pattern() {
// Filter & return
return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' );
}
/**
* Searches through the content to locate usernames, designated by an @ sign.
*
* @since 2.2.0 bbPress (r4323)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @param string $content The content
* @return bool|array $usernames Existing usernames. False if no matches.
*/
function bbp_find_mentions( $content = '' ) {
$pattern = bbp_find_mentions_pattern();
preg_match_all( $pattern, $content, $usernames );
$usernames = array_unique( array_filter( $usernames[1] ) );
// Bail if no usernames
if ( empty( $usernames ) ) {
$usernames = false;
}
// Filter & return
return apply_filters( 'bbp_find_mentions', $usernames, $pattern, $content );
}
/**
* Finds and links @-mentioned users in the content
*
* @since 2.2.0 bbPress (r4323)
* @deprecated 2.6.0 bbp_make_clickable()
*
* @return string $content Content filtered for mentions
*/
function bbp_mention_filter( $content = '' ) {
// Get Usernames and bail if none exist
$usernames = bbp_find_mentions( $content );
if ( empty( $usernames ) ) {
return $content;
}
// Loop through usernames and link to profiles
foreach ( (array) $usernames as $username ) {
// Skip if username does not exist or user is not active
$user = get_user_by( 'slug', $username );
if ( empty( $user->ID ) || bbp_is_user_inactive( $user->ID ) ) {
continue;
}
// Link
$profile_url = bbp_get_user_profile_url( $user->ID );
$profile_link = sprintf( '<a href="%1$s">@%2$s</a>', esc_url( $profile_url ), esc_html( $username ) );
$no_followed = bbp_rel_nofollow( $profile_link );
$pattern = "/(@{$username}\b)/";
// Replace name in content
$content = preg_replace( $pattern, $no_followed, $content );
}
// Return modified content
return $content;
}
/** Post Statuses *************************************************************/
/**
* Return the public post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_public_status_id() {
return bbpress()->public_status_id;
}
/**
* Return the pending post status ID
*
* @since 2.1.0 bbPress (r3581)
*
* @return string
*/
function bbp_get_pending_status_id() {
return bbpress()->pending_status_id;
}
/**
* Return the private post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_private_status_id() {
return bbpress()->private_status_id;
}
/**
* Return the hidden post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_hidden_status_id() {
return bbpress()->hidden_status_id;
}
/**
* Return the closed post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_closed_status_id() {
return bbpress()->closed_status_id;
}
/**
* Return the spam post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_spam_status_id() {
return bbpress()->spam_status_id;
}
/**
* Return the trash post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_trash_status_id() {
return bbpress()->trash_status_id;
}
/**
* Return the orphan post status ID
*
* @since 2.0.0 bbPress (r3504)
*
* @return string
*/
function bbp_get_orphan_status_id() {
return bbpress()->orphan_status_id;
}
/** Rewrite IDs ***************************************************************/
/**
* Return the unique ID for user profile rewrite rules
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_user_rewrite_id() {
return bbpress()->user_id;
}
/**
* Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user)
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_edit_rewrite_id() {
return bbpress()->edit_id;
}
/**
* Return the unique ID for all search rewrite rules
*
* @since 2.3.0 bbPress (r4579)
*
* @return string
*/
function bbp_get_search_rewrite_id() {
return bbpress()->search_id;
}
/**
* Return the unique ID for user topics rewrite rules
*
* @since 2.2.0 bbPress (r4321)
*
* @return string
*/
function bbp_get_user_topics_rewrite_id() {
return bbpress()->tops_id;
}
/**
* Return the unique ID for user replies rewrite rules
*
* @since 2.2.0 bbPress (r4321)
*
* @return string
*/
function bbp_get_user_replies_rewrite_id() {
return bbpress()->reps_id;
}
/**
* Return the unique ID for user favorites rewrite rules
*
* @since 2.2.0 bbPress (r4181)
*
* @return string
*/
function bbp_get_user_favorites_rewrite_id() {
return bbpress()->favs_id;
}
/**
* Return the unique ID for user subscriptions rewrite rules
*
* @since 2.2.0 bbPress (r4181)
*
* @return string
*/
function bbp_get_user_subscriptions_rewrite_id() {
return bbpress()->subs_id;
}
/**
* Return the unique ID for user engagement rewrite rules
*
* @since 2.6.0 bbPress (r6320)
*
* @return string
*/
function bbp_get_user_engagements_rewrite_id() {
return bbpress()->engagements_id;
}
/**
* Return the unique ID for topic view rewrite rules
*
* @since 2.1.0 bbPress (r3762)
*
* @return string
*/
function bbp_get_view_rewrite_id() {
return bbpress()->view_id;
}
/** Rewrite Extras ************************************************************/
/**
* Get the id used for paginated requests
*
* @since 2.4.0 bbPress (r4926)
*
* @return string
*/
function bbp_get_paged_rewrite_id() {
return bbpress()->paged_id;
}
/**
* Delete a blogs rewrite rules, so that they are automatically rebuilt on
* the subsequent page load.
*
* @since 2.2.0 bbPress (r4198)
*/
function bbp_delete_rewrite_rules() {
delete_option( 'rewrite_rules' );
}
/** Requests ******************************************************************/
/**
* Return true|false if this is a POST request
*
* @since 2.3.0 bbPress (r4790)
*
* @return bool
*/
function bbp_is_post_request() {
return (bool) ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
}
/**
* Return true|false if this is a GET request
*
* @since 2.3.0 bbPress (r4790)
*
* @return bool
*/
function bbp_is_get_request() {
return (bool) ( 'GET' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
}
/** Redirection ***************************************************************/
/**
* Perform a safe, local redirect somewhere inside the current site
*
* On some setups, passing the value of wp_get_referer() may result in an empty
* value for $location, which results in an error on redirection. If $location
* is empty, we can safely redirect back to the forum root. This might change
* in a future version, possibly to the site root.
*
* @since 2.6.0 bbPress (r5658)
*
* @see bbp_redirect_to_field()
*
* @param string $location The URL to redirect the user to.
* @param int $status Optional. The numeric code to give in the redirect
* headers. Default: 302.
*/
function bbp_redirect( $location = '', $status = 302 ) {
// Prevent errors from empty $location
if ( empty( $location ) ) {
$location = bbp_get_forums_url();
}
// Setup the safe redirect
wp_safe_redirect( $location, $status );
// Exit so the redirect takes place immediately
exit();
}
/** Global Helpers ************************************************************/
/**
* Return if debugging scripts or not
*
* @since 2.6.7 (r7188)
*
* @return bool True if debugging scripts. False if not debugging scripts.
*/
function bbp_doing_script_debug() {
return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
}
/**
* Return if auto-saving or not
*
* @since 2.6.7 (r7188)
*
* @return bool True if mid auto-save. False if not mid auto-save.
*/
function bbp_doing_autosave() {
return defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
}

View File

@@ -0,0 +1,5 @@
<?php
/**
* Do not modify the files in this folder.
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,553 @@
<?php
/**
* Plugin Dependency
*
* The purpose of the following hooks is to mimic the behavior of something
* called 'plugin dependency' which enables a plugin to have plugins of their
* own in a safe and reliable way.
*
* We do this in bbPress by mirroring existing WordPress hooks in many places
* allowing dependant plugins to hook into the bbPress specific ones, thus
* guaranteeing proper code execution only when bbPress is active.
*
* The following functions are wrappers for hooks, allowing them to be
* manually called and/or piggy-backed on top of other hooks if needed.
*
* @package bbPress
* @subpackage Core
*
* @todo use anonymous functions when PHP minimum requirement allows (5.3)
*/
/** Activation Actions ********************************************************/
/**
* Runs on bbPress activation
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_activation() {
do_action( 'bbp_activation' );
}
/**
* Runs on bbPress deactivation
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_deactivation() {
do_action( 'bbp_deactivation' );
}
/**
* Runs when uninstalling bbPress
*
* @since 2.0.0 bbPress (r2509)
*/
function bbp_uninstall() {
do_action( 'bbp_uninstall' );
}
/** Main Actions **************************************************************/
/**
* Main action responsible for constants, globals, and includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_loaded() {
do_action( 'bbp_loaded' );
}
/**
* Setup constants
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_constants() {
do_action( 'bbp_constants' );
}
/**
* Setup globals BEFORE includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_boot_strap_globals() {
do_action( 'bbp_boot_strap_globals' );
}
/**
* Include files
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_includes() {
do_action( 'bbp_includes' );
}
/**
* Setup globals AFTER includes
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_setup_globals() {
do_action( 'bbp_setup_globals' );
}
/**
* Register any objects before anything is initialized
*
* @since 2.2.0 bbPress (r4180)
*/
function bbp_register() {
do_action( 'bbp_register' );
}
/**
* Initialize any code after everything has been loaded
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_init() {
do_action( 'bbp_init' );
}
/**
* Initialize roles
*
* @since 2.6.0 bbPress (r6106)
*
* @param WP_Roles $wp_roles The array of WP_Role objects that was initialized
*/
function bbp_roles_init( $wp_roles ) {
do_action( 'bbp_roles_init', $wp_roles );
}
/**
* Initialize widgets
*
* @since 2.0.0 bbPress (r3389)
*/
function bbp_widgets_init() {
do_action( 'bbp_widgets_init' );
}
/**
* Setup the currently logged-in user
*
* @link https://bbpress.trac.wordpress.org/ticket/2309
* @link https://core.trac.wordpress.org/ticket/24169
*
* @since 2.0.0 bbPress (r2695)
*/
function bbp_setup_current_user() {
do_action( 'bbp_setup_current_user' );
}
/**
* Setup the user engagements strategy
*
* @since 2.6.0 bbPress (r6875)
*/
function bbp_setup_engagements() {
do_action( 'bbp_setup_engagements' );
}
/** Supplemental Actions ******************************************************/
/**
* Load translations for current language
*
* @since 2.0.0 bbPress (r2599)
*/
function bbp_load_textdomain() {
do_action( 'bbp_load_textdomain' );
}
/**
* Setup the post types
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_register_post_types() {
do_action( 'bbp_register_post_types' );
}
/**
* Setup the post statuses
*
* @since 2.0.0 bbPress (r2727)
*/
function bbp_register_post_statuses() {
do_action( 'bbp_register_post_statuses' );
}
/**
* Register the built in bbPress taxonomies
*
* @since 2.0.0 bbPress (r2464)
*/
function bbp_register_taxonomies() {
do_action( 'bbp_register_taxonomies' );
}
/**
* Register the default bbPress views
*
* @since 2.0.0 bbPress (r2789)
*/
function bbp_register_views() {
do_action( 'bbp_register_views' );
}
/**
* Register the default bbPress shortcodes
*
* @since 2.2.0 bbPress (r4211)
*/
function bbp_register_shortcodes() {
do_action( 'bbp_register_shortcodes' );
}
/**
* Register the default bbPress meta-data
*
* @since 2.6.0 bbPress (r46300)
*/
function bbp_register_meta() {
do_action( 'bbp_register_meta' );
}
/**
* Enqueue bbPress specific CSS and JS
*
* @since 2.0.0 bbPress (r3373)
*/
function bbp_enqueue_scripts() {
do_action( 'bbp_enqueue_scripts' );
}
/**
* Add the bbPress-specific rewrite tags
*
* @since 2.0.0 bbPress (r2753)
*/
function bbp_add_rewrite_tags() {
do_action( 'bbp_add_rewrite_tags' );
}
/**
* Add the bbPress-specific rewrite rules
*
* @since 2.4.0 bbPress (r4918)
*/
function bbp_add_rewrite_rules() {
do_action( 'bbp_add_rewrite_rules' );
}
/**
* Add the bbPress-specific permalink structures
*
* @since 2.4.0 bbPress (r4918)
*/
function bbp_add_permastructs() {
do_action( 'bbp_add_permastructs' );
}
/**
* Add the bbPress-specific login forum action
*
* @since 2.0.0 bbPress (r2753)
*/
function bbp_login_form_login() {
do_action( 'bbp_login_form_login' );
}
/**
* Add the bbPress-specific post status transition action
*
* @since 2.6.0 bbPress (r6792)
*
* @param string $new_status New post status
* @param string $old_status Old post status
* @param WP_Post $post Post object
*/
function bbp_transition_post_status( $new_status = '', $old_status = '', $post = false ) {
// Get bbPress post types
$post_type = get_post_type( $post );
$types = bbp_get_post_types();
// Bail if post is not a bbPress post type
if ( ! in_array( $post_type, $types, true ) ) {
return;
}
// Do the action
do_action( 'bbp_transition_post_status', $new_status, $old_status, $post );
}
/** User Actions **************************************************************/
/**
* The main action for hooking into when a user account is updated
*
* @since 2.2.0 bbPress (r4304)
*
* @param int $user_id ID of user being edited
* @param array $old_user_data The old, unmodified user data
*/
function bbp_profile_update( $user_id = 0, $old_user_data = array() ) {
do_action( 'bbp_profile_update', $user_id, $old_user_data );
}
/**
* The main action for hooking into a user being registered
*
* @since 2.2.0 bbPress (r4304)
*
* @param int $user_id ID of user being edited
*/
function bbp_user_register( $user_id = 0 ) {
do_action( 'bbp_user_register', $user_id );
}
/** Final Action **************************************************************/
/**
* bbPress has loaded and initialized everything, and is okay to go
*
* @since 2.0.0 bbPress (r2618)
*/
function bbp_ready() {
do_action( 'bbp_ready' );
}
/** Theme Permissions *********************************************************/
/**
* The main action used for redirecting bbPress theme actions that are not
* permitted by the current_user
*
* @since 2.1.0 bbPress (r3605)
*/
function bbp_template_redirect() {
do_action( 'bbp_template_redirect' );
}
/** Theme Helpers *************************************************************/
/**
* The main action used for executing code before the theme has been setup
*
* @since 2.1.0 bbPress (r3829)
*/
function bbp_register_theme_packages() {
do_action( 'bbp_register_theme_packages' );
}
/**
* The main action used for executing code before the theme has been setup
*
* @since 2.1.0 bbPress (r3732)
*/
function bbp_setup_theme() {
do_action( 'bbp_setup_theme' );
}
/**
* The main action used for executing code after the theme has been setup
*
* @since 2.1.0 bbPress (r3732)
*/
function bbp_after_setup_theme() {
do_action( 'bbp_after_setup_theme' );
}
/**
* The main action used for handling theme-side POST requests
*
* @since 2.3.0 bbPress (r4550)
*/
function bbp_post_request() {
// Bail if not a POST action
if ( ! bbp_is_post_request() ) {
return;
}
// Bail if no action, or if not a string (arrays not supported)
if ( empty( $_POST['action'] ) || ! is_string( $_POST['action'] ) ) {
return;
}
// Sanitize the POST action
$action = sanitize_key( $_POST['action'] );
// Bail if action was totally invalid
if ( empty( $action ) ) {
return;
}
// This dynamic action is probably the one you want to use. It narrows down
// the scope of the 'action' without needing to check it in your function.
do_action( 'bbp_post_request_' . $action );
// Use this static action if you don't mind checking the 'action' yourself.
do_action( 'bbp_post_request', $action );
}
/**
* The main action used for handling theme-side GET requests
*
* @since 2.3.0 bbPress (r4550)
*/
function bbp_get_request() {
// Bail if not a POST action
if ( ! bbp_is_get_request() ) {
return;
}
// Bail if no action, or if not a string (arrays not supported)
if ( empty( $_GET['action'] ) || ! is_string( $_GET['action'] ) ) {
return;
}
// Sanitize the GET action
$action = sanitize_key( $_GET['action'] );
// Bail if action was totally invalid
if ( empty( $action ) ) {
return;
}
// This dynamic action is probably the one you want to use. It narrows down
// the scope of the 'action' without needing to check it in your function.
do_action( 'bbp_get_request_' . $action );
// Use this static action if you don't mind checking the 'action' yourself.
do_action( 'bbp_get_request', $action );
}
/** Filters *******************************************************************/
/**
* Filter the plugin locale and domain.
*
* @since 2.2.0 bbPress (r4213)
*
* @param string $locale
* @param string $domain
*/
function bbp_plugin_locale( $locale = '', $domain = '' ) {
// Filter & return
return apply_filters( 'bbp_plugin_locale', $locale, $domain );
}
/**
* Piggy back filter for WordPress's 'request' filter
*
* @since 2.1.0 bbPress (r3758)
*
* @param array $query_vars
* @return array
*/
function bbp_request( $query_vars = array() ) {
// Filter & return
return apply_filters( 'bbp_request', $query_vars );
}
/**
* The main filter used for theme compatibility and displaying custom bbPress
* theme files.
*
* @since 2.0.0 bbPress (r3311)
*
* @param string $template
* @return string Template file to use
*/
function bbp_template_include( $template = '' ) {
// Filter & return
return apply_filters( 'bbp_template_include', $template );
}
/**
* Generate bbPress-specific rewrite rules
*
* @since 2.0.0 bbPress (r2688)
*
* @deprecated 2.4.0 bbPress (r4918)
*
* @param WP_Rewrite $wp_rewrite
*/
function bbp_generate_rewrite_rules( $wp_rewrite ) {
do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) );
}
/**
* Filter the allowed themes list for bbPress specific themes
*
* @since 2.0.0 bbPress (r2944)
*
* @param array $themes
*
* @return array Array of allowed themes
*/
function bbp_allowed_themes( $themes ) {
// Filter & return
return (array) apply_filters( 'bbp_allowed_themes', $themes );
}
/**
* Maps forum/topic/reply caps to built in WordPress caps
*
* @since 2.0.0 bbPress (r2593)
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Array of capabilities
*/
function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
// Filter & return
return (array) apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args );
}
/**
* Filter the arguments used by wp_mail for bbPress specific emails
*
* @since 2.6.0 bbPress (r6918)
*
* @param array $args A compacted array of wp_mail() arguments, including the "to" email,
* subject, message, headers, and attachments values.
*
* @return array Array of capabilities
*/
function bbp_mail( $args = array() ) {
// Bail if headers are missing/malformed
if ( empty( $args['headers'] ) || ! is_array( $args['headers'] ) ) {
return $args;
}
// Header to search all headers for
$bbp_header = bbp_get_email_header();
// Bail if no bbPress header found
if ( false === array_search( $bbp_header, $args['headers'], true ) ) {
return $args;
}
// Filter & return
return (array) apply_filters( 'bbp_mail', $args );
}

View File

@@ -0,0 +1,738 @@
<?php
/**
* bbPress Template Functions
*
* This file contains functions necessary to mirror the WordPress core template
* loading process. Many of those functions are not filterable, and even then
* would not be robust enough to predict where bbPress templates might exist.
*
* @package bbPress
* @subpackage TemplateFunctions
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Adds bbPress theme support to any active WordPress theme
*
* @since 2.0.0 bbPress (r3032)
*
* @param string $slug
* @param string $name Optional. Default null
*/
function bbp_get_template_part( $slug, $name = null ) {
// Execute code for this part
do_action( 'get_template_part_' . $slug, $slug, $name );
// Setup possible parts
$templates = array();
if ( isset( $name ) ) {
$templates[] = $slug . '-' . $name . '.php';
}
$templates[] = $slug . '.php';
// Allow template parst to be filtered
$templates = apply_filters( 'bbp_get_template_part', $templates, $slug, $name );
// Return the part that is found
return bbp_locate_template( $templates, true, false );
}
/**
* Retrieve the name of the highest priority template file that exists.
*
* Searches in the child theme before parent theme so that themes which
* inherit from a parent theme can just overload one file. If the template is
* not found in either of those, it looks in the theme-compat folder last.
*
* @since 2.1.0 bbPress (r3618)
*
* @param string|array $template_names Template file(s) to search for, in order.
* @param bool $load If true the template file will be loaded if it is found.
* @param bool $require_once Whether to require_once or require. Default true.
* Has no effect if $load is false.
* @return string The template filename if one is located.
*/
function bbp_locate_template( $template_names, $load = false, $require_once = true ) {
// No file found yet
$located = false;
$template_locations = bbp_get_template_stack();
// Try to find a template file
foreach ( (array) $template_names as $template_name ) {
// Continue if template is empty
if ( empty( $template_name ) ) {
continue;
}
// Trim off any slashes from the template name
$template_name = ltrim( $template_name, '/' );
// Loop through template stack
foreach ( (array) $template_locations as $template_location ) {
// Continue if $template_location is empty
if ( empty( $template_location ) ) {
continue;
}
// Check child theme first
if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) {
$located = trailingslashit( $template_location ) . $template_name;
break 2;
}
}
}
/**
* This action exists only to follow the standard bbPress coding convention,
* and should not be used to short-circuit any part of the template locator.
*
* If you want to override a specific template part, please either filter
* 'bbp_get_template_part' or add a new location to the template stack.
*/
do_action( 'bbp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once );
// Maybe load the template if one was located
if ( ( defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ) && ( true === $load ) && ! empty( $located ) ) {
load_template( $located, $require_once );
}
return $located;
}
/**
* Locate an enqueueable file on the server. Used before being enqueued.
*
* If SCRIPT_DEBUG is set and the file includes a .min suffix, this function
* will automatically attempt to locate a non-minified version of that file.
*
* If SCRIPT_DEBUG is not set and the file exclude a .min suffix, this function
* will automatically attempt to locate a minified version of that file.
*
* See: https://bbpress.trac.wordpress.org/ticket/3218
*
* @since 2.6.0
*
* @param string $file
*
* @return boolean
*/
function bbp_locate_enqueueable( $file = '' ) {
// Bail if no file to locate
if ( empty( $file ) ) {
return false;
}
// Add file to files array
$files = array( $file );
// Get the file variant (minified or not, but opposite of $file)
$file_is_min = ( false !== strpos( $file, '.min' ) );
$file_variant = ( false === $file_is_min )
? str_replace( array( '.css', '.js' ), array( '.min.css', '.min.js' ), $file )
: str_replace( '.min', '', $file );
// Are we debugging?
$script_debug = bbp_doing_script_debug();
// Debugging, so prefer unminified files
if ( true === $script_debug ) {
if ( true === $file_is_min ) {
array_unshift( $files, $file_variant );
} else {
array_push( $files, $file_variant );
}
// Not debugging, so prefer minified files
} elseif ( false === $script_debug ) {
if ( true === $file_is_min ) {
array_push( $files, $file_variant );
} else {
array_unshift( $files, $file_variant );
}
}
// Return first found file location in the stack
return bbp_locate_template( $files, false, false );
}
/**
* Convert an enqueueable file path to a URL
*
* @since 2.6.0
* @param string $file
*
* @return string
*/
function bbp_urlize_enqueueable( $file = '' ) {
// Get DIR and URL
$content_dir = constant( 'WP_CONTENT_DIR' );
$content_url = content_url();
// IIS (Windows) here
// Replace back slashes with forward slash
if ( false !== strpos( $file, '\\' ) ) {
$file = str_replace( '\\', '/', $file );
$content_dir = str_replace( '\\', '/', $content_dir );
}
// Return path to file relative to site URL
return str_replace( $content_dir, $content_url, $file );
}
/**
* Enqueue a script from the highest priority location in the template stack.
*
* Registers the style if file provided (does NOT overwrite) and enqueues.
*
* @since 2.5.0 bbPress (r5180)
*
* @param string $handle Name of the stylesheet.
* @param string|bool $file Relative path to stylesheet. Example: '/css/mystyle.css'.
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
* @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used
* to ensure that the correct version is sent to the client regardless of caching, and so
* should be included if a version number is available and makes sense for the stylesheet.
* @param string $media Optional. The media for which this stylesheet has been defined.
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
* 'screen', 'tty', or 'tv'.
*
* @return mixed The style filename if one is located. False if not.
*/
function bbp_enqueue_style( $handle = '', $file = '', $deps = array(), $ver = false, $media = 'all' ) {
// Attempt to locate an enqueueable
$located = bbp_locate_enqueueable( $file );
// Enqueue if located
if ( ! empty( $located ) ) {
// Make sure there is always a version
if ( empty( $ver ) ) {
$ver = bbp_get_asset_version();
}
// Make path to file relative to site URL
$located = bbp_urlize_enqueueable( $located );
// Register the style
wp_register_style( $handle, $located, $deps, $ver, $media );
// Enqueue the style
wp_enqueue_style( $handle );
}
return $located;
}
/**
* Enqueue a script from the highest priority location in the template stack.
*
* Registers the style if file provided (does NOT overwrite) and enqueues.
*
* @since 2.5.0 bbPress (r5180)
*
* @param string $handle Name of the script.
* @param string|bool $file Relative path to the script. Example: '/js/myscript.js'.
* @param array $deps An array of registered handles this script depends on. Default empty array.
* @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter
* is used to ensure that the correct version is sent to the client regardless of caching,
* and so should be included if a version number is available and makes sense for the script.
* @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
* Default 'false'. Accepts 'false' or 'true'.
*
* @return mixed The script filename if one is located. False if not.
*/
function bbp_enqueue_script( $handle = '', $file = '', $deps = array(), $ver = false, $in_footer = false ) {
// Attempt to locate an enqueueable
$located = bbp_locate_enqueueable( $file );
// Enqueue if located
if ( ! empty( $located ) ) {
// Make sure there is always a version
if ( empty( $ver ) ) {
$ver = bbp_get_asset_version();
}
// Make path to file relative to site URL
$located = bbp_urlize_enqueueable( $located );
// Register the style
wp_register_script( $handle, $located, $deps, $ver, $in_footer );
// Enqueue the style
wp_enqueue_script( $handle );
}
return $located;
}
/**
* This is really cool. This function registers a new template stack location,
* using WordPress's built in filters API.
*
* This allows for templates to live in places beyond just the parent/child
* relationship, to allow for custom template locations. Used in conjunction
* with bbp_locate_template(), this allows for easy template overrides.
*
* @since 2.2.0 bbPress (r4323)
*
* @param string $location_callback Callback function that returns the
* @param int $priority
*/
function bbp_register_template_stack( $location_callback = '', $priority = 10 ) {
// Bail if no location, or function/method is not callable
if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
return false;
}
// Add location callback to template stack
return add_filter( 'bbp_template_stack', $location_callback, (int) $priority );
}
/**
* Deregisters a previously registered template stack location.
*
* @since 2.3.0 bbPress (r4652)
*
* @param string $location_callback Callback function that returns the
* @param int $priority
* @return bool Whether stack was removed
*/
function bbp_deregister_template_stack( $location_callback = '', $priority = 10 ) {
// Bail if no location, or function/method is not callable
if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) {
return false;
}
// Remove location callback to template stack
return remove_filter( 'bbp_template_stack', $location_callback, (int) $priority );
}
/**
* Call the functions added to the 'bbp_template_stack' filter hook, and return
* an array of the template locations.
*
* @since 2.2.0 bbPress (r4323)
* @since 2.6.0 bbPress (r5944) Added support for `WP_Hook`
*
* @global array $wp_filter Stores all of the filters
* @global array $merged_filters Merges the filter hooks using this function.
* @global array $wp_current_filter stores the list of current filters with the current one last
*
* @return array The filtered value after all hooked functions are applied to it.
*/
function bbp_get_template_stack() {
global $wp_filter, $merged_filters, $wp_current_filter;
// Setup some default variables
$tag = 'bbp_template_stack';
$args = $stack = array();
// Add 'bbp_template_stack' to the current filter array
$wp_current_filter[] = $tag;
// Bail if no stack setup
if ( empty( $wp_filter[ $tag ] ) ) {
return array();
}
// Check if WP_Hook class exists, see #WP17817
if ( class_exists( 'WP_Hook' ) ) {
$filter = $wp_filter[ $tag ]->callbacks;
} else {
$filter = &$wp_filter[ $tag ];
// Sort
if ( ! isset( $merged_filters[ $tag ] ) ) {
ksort( $filter );
$merged_filters[ $tag ] = true;
}
}
// Ensure we're always at the beginning of the filter array
reset( $filter );
// Loop through 'bbp_template_stack' filters, and call callback functions
do {
foreach ( (array) current( $filter ) as $the_ ) {
if ( ! is_null( $the_['function'] ) ) {
$args[1] = $stack;
$stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) );
}
}
} while ( next( $filter ) !== false );
// Remove 'bbp_template_stack' from the current filter array
array_pop( $wp_current_filter );
// Remove empties and duplicates
$stack = array_unique( array_filter( $stack ) );
// Filter & return
return (array) apply_filters( 'bbp_get_template_stack', $stack ) ;
}
/**
* Get a template part in an output buffer, and return it
*
* @since 2.4.0 bbPress (r5043)
*
* @param string $slug
* @param string $name
* @return string
*/
function bbp_buffer_template_part( $slug, $name = null, $echo = true ) {
ob_start();
bbp_get_template_part( $slug, $name );
// Get the output buffer contents
$output = ob_get_clean();
// Echo or return the output buffer contents
if ( true === $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Retrieve path to a template
*
* Used to quickly retrieve the path of a template without including the file
* extension. It will also check the parent theme and theme-compat theme with
* the use of {@link bbp_locate_template()}. Allows for more generic template
* locations without the use of the other get_*_template() functions.
*
* @since 2.1.0 bbPress (r3629)
*
* @param string $type Filename without extension.
* @param array $templates An optional list of template candidates
* @return string Full path to file.
*/
function bbp_get_query_template( $type, $templates = array() ) {
$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
// Fallback template
if ( empty( $templates ) ) {
$templates = array( "{$type}.php" );
}
// Filter possible templates
$templates = apply_filters( "bbp_get_{$type}_template", $templates );
// Stash the possible templates for this query, for later use
bbp_set_theme_compat_templates( $templates );
// Try to locate a template in the stack
$template = bbp_locate_template( $templates );
// Stash the located template for this query, for later use
bbp_set_theme_compat_template( $template );
// Filter & return
return apply_filters( "bbp_{$type}_template", $template, $templates );
}
/**
* Get the possible subdirectories to check for templates in
*
* @since 2.1.0 bbPress (r3738)
*
* @param array $templates Templates we are looking for
* @return array Possible subdirectories to look in
*/
function bbp_get_template_locations( $templates = array() ) {
$locations = array(
'bbpress',
'forums',
''
);
// Filter & return
return apply_filters( 'bbp_get_template_locations', $locations, $templates );
}
/**
* Add template locations to template files being searched for
*
* @since 2.1.0 bbPress (r3738)
*
* @param array $stacks
* @return array()
*/
function bbp_add_template_stack_locations( $stacks = array() ) {
$retval = array();
// Get alternate locations
$locations = bbp_get_template_locations();
// Loop through locations and stacks and combine
foreach ( (array) $stacks as $stack ) {
foreach ( (array) $locations as $custom_location ) {
$retval[] = untrailingslashit( trailingslashit( $stack ) . $custom_location );
}
}
// Filter & return
return (array) apply_filters( 'bbp_add_template_stack_locations', array_unique( $retval ), $stacks );
}
/**
* Add checks for bbPress conditions to parse_query action
*
* If it's a user page, WP_Query::bbp_is_single_user is set to true.
*
* If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
* and the the 'wp-admin/includes/user.php' file is included.
*
* In addition, on user/user edit pages, WP_Query::home is set to false & query
* vars 'bbp_user_id' with the displayed user id is added.
*
* In 2.6.0, the 'author_name' variable is no longer set when viewing a single
* user, because of is_author() weirdness. If this removal causes problems, it
* may come back in a future release.
*
* If it's a forum edit, WP_Query::bbp_is_forum_edit is set to true
* If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true
* If it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
*
* If it's a view page, WP_Query::bbp_is_view is set to true
* If it's a search page, WP_Query::bbp_is_search is set to true
*
* @since 2.0.0 bbPress (r2688)
*
* @param WP_Query $posts_query
*/
function bbp_parse_query( $posts_query ) {
// Bail if $posts_query is not the main loop
if ( ! $posts_query->is_main_query() ) {
return;
}
// Bail if filters are suppressed on this query
if ( true === $posts_query->get( 'suppress_filters' ) ) {
return;
}
// Bail if in admin
if ( is_admin() ) {
return;
}
// Get query variables (default to null if not set)
$bbp_view = $posts_query->get( bbp_get_view_rewrite_id(), null );
$bbp_user = $posts_query->get( bbp_get_user_rewrite_id(), null );
$is_edit = $posts_query->get( bbp_get_edit_rewrite_id(), null );
$is_search = $posts_query->get( bbp_get_search_rewrite_id(), null );
// It is a user page - We'll also check if it is user edit
if ( ! is_null( $bbp_user ) ) {
/** Find User *********************************************************/
// Setup the default user variable
$the_user = false;
// If using pretty permalinks, always use slug
if ( get_option( 'permalink_structure' ) ) {
$the_user = get_user_by( 'slug', $bbp_user );
// If not using pretty permalinks, always use numeric ID
} elseif ( is_numeric( $bbp_user ) ) {
$the_user = get_user_by( 'id', $bbp_user );
}
// 404 and bail if user does not have a profile
if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) {
$posts_query->bbp_is_404 = true;
return;
}
/** User Exists *******************************************************/
$is_favs = $posts_query->get( bbp_get_user_favorites_rewrite_id() );
$is_subs = $posts_query->get( bbp_get_user_subscriptions_rewrite_id() );
$is_topics = $posts_query->get( bbp_get_user_topics_rewrite_id() );
$is_replies = $posts_query->get( bbp_get_user_replies_rewrite_id() );
$is_engagements = $posts_query->get( bbp_get_user_engagements_rewrite_id() );
// View or edit?
if ( ! is_null( $is_edit ) ) {
// We are editing a profile
$posts_query->bbp_is_single_user_edit = true;
// Load the core WordPress contact methods
if ( ! function_exists( '_wp_get_user_contactmethods' ) ) {
require_once ABSPATH . 'wp-includes/registration.php';
}
// Load the edit_user functions
if ( ! function_exists( 'edit_user' ) ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
// Load the grant/revoke super admin functions
if ( is_multisite() && ! function_exists( 'revoke_super_admin' ) ) {
require_once ABSPATH . 'wp-admin/includes/ms.php';
}
// Editing a user
$posts_query->bbp_is_edit = true;
// User favorites
} elseif ( ! empty( $is_favs ) ) {
$posts_query->bbp_is_single_user_favs = true;
// User subscriptions
} elseif ( ! empty( $is_subs ) ) {
$posts_query->bbp_is_single_user_subs = true;
// User topics
} elseif ( ! empty( $is_topics ) ) {
$posts_query->bbp_is_single_user_topics = true;
// User topics
} elseif ( ! empty( $is_replies ) ) {
$posts_query->bbp_is_single_user_replies = true;
// User engagements
} elseif ( ! empty( $is_engagements ) ) {
$posts_query->bbp_is_single_user_engagements = true;
// User profile
} else {
$posts_query->bbp_is_single_user_profile = true;
}
// Make sure 404 is not set
$posts_query->is_404 = false;
// Correct is_home variable
$posts_query->is_home = false;
// Looking at a single user
$posts_query->bbp_is_single_user = true;
// User found so don't 404 yet
$posts_query->bbp_is_404 = false;
// User is looking at their own profile
if ( bbp_get_current_user_id() === $the_user->ID ) {
$posts_query->bbp_is_single_user_home = true;
}
// Set bbp_user_id for future reference
$posts_query->set( 'bbp_user_id', $the_user->ID );
// Set the displayed user global to this user
bbpress()->displayed_user = $the_user;
// View Page
} elseif ( ! is_null( $bbp_view ) ) {
// Check if the view exists by checking if there are query args are set
$view_args = bbp_get_view_query_args( $bbp_view );
// Bail if view args are empty
if ( empty( $view_args ) ) {
$posts_query->bbp_is_404 = true;
return;
}
// Correct is_home variable
$posts_query->is_home = false;
// We are in a custom topic view
$posts_query->bbp_is_view = true;
// No 404 because views are all (currently) public
$posts_query->bbp_is_404 = false;
// Search Page
} elseif ( ! is_null( $is_search ) ) {
// Check if there are search query args set
$search_terms = bbp_get_search_terms();
if ( ! empty( $search_terms ) ) {
$posts_query->bbp_search_terms = $search_terms;
}
// Correct is_home variable
$posts_query->is_home = false;
// We are in a search query
$posts_query->bbp_is_search = true;
// No 404 because search is always public
$posts_query->bbp_is_404 = false;
// Forum/Topic/Reply Edit Page
} elseif ( ! is_null( $is_edit ) ) {
// Get the post type from the main query loop
$post_type = $posts_query->get( 'post_type' );
// Check which post_type we are editing, if any
if ( ! empty( $post_type ) ) {
switch ( $post_type ) {
// We are editing a forum
case bbp_get_forum_post_type() :
$posts_query->bbp_is_forum_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
// We are editing a topic
case bbp_get_topic_post_type() :
$posts_query->bbp_is_topic_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
// We are editing a reply
case bbp_get_reply_post_type() :
$posts_query->bbp_is_reply_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
break;
}
// We are editing a topic tag
} elseif ( bbp_is_topic_tag() ) {
$posts_query->bbp_is_topic_tag_edit = true;
$posts_query->bbp_is_edit = true;
$posts_query->bbp_is_404 = false;
}
// We save post revisions on our own
remove_action( 'pre_post_update', 'wp_save_post_revision' );
// Topic tag page
} elseif ( bbp_is_topic_tag() ) {
$posts_query->set( 'bbp_topic_tag', get_query_var( 'term' ) );
$posts_query->set( 'post_type', bbp_get_topic_post_type() );
$posts_query->set( 'posts_per_page', bbp_get_topics_per_page() );
// Do topics on forums root
} elseif ( is_post_type_archive( bbp_get_post_types( array( 'has_archive' => true ) ) ) && ( 'topics' === bbp_show_on_root() ) ) {
$posts_query->bbp_show_topics_on_root = true;
}
}

View File

@@ -0,0 +1,472 @@
<?php
/**
* bbPress Template Loader
*
* @package bbPress
* @subpackage TemplateLoader
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Possibly intercept the template being loaded
*
* Listens to the 'template_include' filter and waits for any bbPress specific
* template condition to be met. If one is met and the template file exists,
* it will be used; otherwise
*
* Note that the _edit() checks are ahead of their counterparts, to prevent them
* from being stomped on accident.
*
* @since 2.0.0 bbPress (r3032)
*
* @param string $template
*
* @return string The path to the template file that is being used
*/
function bbp_template_include_theme_supports( $template = '' ) {
// Editing a user
if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
// User favorites
elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) :
// User favorites
elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) :
// Viewing a user
elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
// Single View
elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
// Search
elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) :
// Forum edit
elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) :
// Single Forum
elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) :
// Forum Archive
elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) :
// Topic merge
elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
// Topic split
elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
// Topic edit
elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
// Single Topic
elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) :
// Topic Archive
elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) :
// Reply move
elseif ( bbp_is_reply_move() && ( $new_template = bbp_get_reply_move_template() ) ) :
// Editing a reply
elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
// Single Reply
elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) :
// Editing a topic tag
elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
// Viewing a topic tag
elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
endif;
// A bbPress template file was located, so override the WordPress template
// and use it to switch off theme compatibility.
if ( ! empty( $new_template ) ) {
$template = bbp_set_template_included( $new_template );
}
// Filter & return
return apply_filters( 'bbp_template_include_theme_supports', $template );
}
/**
* Set the included template
*
* @since 2.4.0 bbPress (r4975)
*
* @param mixed $template Default false
* @return mixed False if empty. Template name if template included
*/
function bbp_set_template_included( $template = false ) {
bbpress()->theme_compat->bbpress_template = $template;
return bbpress()->theme_compat->bbpress_template;
}
/**
* Is a bbPress template being included?
*
* @since 2.4.0 bbPress (r4975)
*
* @return bool True if yes, false if no
*/
function bbp_is_template_included() {
return ! empty( bbpress()->theme_compat->bbpress_template );
}
/** Custom Functions **********************************************************/
/**
* Attempt to load a custom bbPress functions file, similar to each themes
* functions.php file.
*
* @since 2.1.0 bbPress (r3732)
*
* @global string $pagenow
*/
function bbp_load_theme_functions() {
global $pagenow;
// If bbPress is being deactivated, do not load any more files
if ( bbp_is_deactivation() ) {
return;
}
if ( ! defined( 'WP_INSTALLING' ) || ( ! empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
bbp_locate_template( 'bbpress-functions.php', true );
}
}
/** Individual Templates ******************************************************/
/**
* Get the user profile template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_user_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-' . $nicename . '.php', // Single User nicename
'single-user-' . $user_id . '.php', // Single User ID
'single-user.php', // Single User
'user.php', // User
);
return bbp_get_query_template( 'profile', $templates );
}
/**
* Get the user profile edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_user_edit_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-edit-' . $nicename . '.php', // Single User Edit nicename
'single-user-edit-' . $user_id . '.php', // Single User Edit ID
'single-user-edit.php', // Single User Edit
'user-edit.php', // User Edit
'user.php', // User
);
return bbp_get_query_template( 'profile_edit', $templates );
}
/**
* Get the user favorites template
*
* @since 2.2.0 bbPress (r4225)
*
* @return string Path to template file
*/
function bbp_get_favorites_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-favorites-' . $nicename . '.php', // Single User Favs nicename
'single-user-favorites-' . $user_id . '.php', // Single User Favs ID
'favorites-' . $nicename . '.php', // Favorites nicename
'favorites-' . $user_id . '.php', // Favorites ID
'favorites.php', // Favorites
'user.php', // User
);
return bbp_get_query_template( 'favorites', $templates );
}
/**
* Get the user subscriptions template
*
* @since 2.2.0 bbPress (r4225)
*
* @return string Path to template file
*/
function bbp_get_subscriptions_template() {
$nicename = bbp_get_displayed_user_field( 'user_nicename' );
$user_id = bbp_get_displayed_user_id();
$templates = array(
'single-user-subscriptions-' . $nicename . '.php', // Single User Subs nicename
'single-user-subscriptions-' . $user_id . '.php', // Single User Subs ID
'subscriptions-' . $nicename . '.php', // Subscriptions nicename
'subscriptions-' . $user_id . '.php', // Subscriptions ID
'subscriptions.php', // Subscriptions
'user.php', // User
);
return bbp_get_query_template( 'subscriptions', $templates );
}
/**
* Get the view template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_single_view_template() {
$view_id = bbp_get_view_id();
$templates = array(
'single-view-' . $view_id . '.php', // Single View ID
'view-' . $view_id . '.php', // View ID
'single-view.php', // Single View
'view.php', // View
);
return bbp_get_query_template( 'single_view', $templates );
}
/**
* Get the search template
*
* @since 2.3.0 bbPress (r4579)
*
* @return string Path to template file
*/
function bbp_get_search_template() {
$templates = array(
'page-forum-search.php', // Single Search
'forum-search.php', // Search
);
return bbp_get_query_template( 'single_search', $templates );
}
/**
* Get the single forum template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_forum_template() {
$templates = array(
'single-' . bbp_get_forum_post_type() . '.php' // Single Forum
);
return bbp_get_query_template( 'single_forum', $templates );
}
/**
* Get the forum archive template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_forum_archive_template() {
$templates = array(
'archive-' . bbp_get_forum_post_type() . '.php' // Forum Archive
);
return bbp_get_query_template( 'forum_archive', $templates );
}
/**
* Get the forum edit template
*
* @since 2.1.0 bbPress (r3566)
*
* @return string Path to template file
*/
function bbp_get_forum_edit_template() {
$templates = array(
'single-' . bbp_get_forum_post_type() . '-edit.php' // Single Forum Edit
);
return bbp_get_query_template( 'forum_edit', $templates );
}
/**
* Get the single topic template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_topic_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '.php'
);
return bbp_get_query_template( 'single_topic', $templates );
}
/**
* Get the topic archive template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_topic_archive_template() {
$templates = array(
'archive-' . bbp_get_topic_post_type() . '.php' // Topic Archive
);
return bbp_get_query_template( 'topic_archive', $templates );
}
/**
* Get the topic edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_edit_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-edit.php' // Single Topic Edit
);
return bbp_get_query_template( 'topic_edit', $templates );
}
/**
* Get the topic split template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_split_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-split.php', // Topic Split
);
return bbp_get_query_template( 'topic_split', $templates );
}
/**
* Get the topic merge template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_merge_template() {
$templates = array(
'single-' . bbp_get_topic_post_type() . '-merge.php', // Topic Merge
);
return bbp_get_query_template( 'topic_merge', $templates );
}
/**
* Get the single reply template
*
* @since 2.1.0 bbPress (r3922)
*
* @return string Path to template file
*/
function bbp_get_single_reply_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '.php'
);
return bbp_get_query_template( 'single_reply', $templates );
}
/**
* Get the reply edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_reply_edit_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '-edit.php' // Single Reply Edit
);
return bbp_get_query_template( 'reply_edit', $templates );
}
/**
* Get the reply move template
*
* @since 2.3.0 bbPress (r4521)
*
* @return string Path to template file
*/
function bbp_get_reply_move_template() {
$templates = array(
'single-' . bbp_get_reply_post_type() . '-move.php', // Reply move
);
return bbp_get_query_template( 'reply_move', $templates );
}
/**
* Get the topic template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_tag_template() {
$tt_slug = bbp_get_topic_tag_slug();
$tt_id = bbp_get_topic_tag_tax_id();
$templates = array(
'taxonomy-' . $tt_slug . '.php', // Single Topic Tag slug
'taxonomy-' . $tt_id . '.php', // Single Topic Tag ID
);
return bbp_get_query_template( 'topic_tag', $templates );
}
/**
* Get the topic edit template
*
* @since 2.0.0 bbPress (r3311)
*
* @return string Path to template file
*/
function bbp_get_topic_tag_edit_template() {
$tt_slug = bbp_get_topic_tag_slug();
$tt_id = bbp_get_topic_tag_tax_id();
$templates = array(
'taxonomy-' . $tt_slug . '-edit.php', // Single Topic Tag Edit slug
'taxonomy-' . $tt_id . '-edit.php' // Single Topic Tag Edit ID
);
return bbp_get_query_template( 'topic_tag_edit', $templates );
}
/**
* Get the templates to use as the endpoint for bbPress template parts
*
* @since 2.0.0 bbPress (r3311)
* @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack
*
* @return string Path to template file
*/
function bbp_get_theme_compat_templates() {
$templates = array(
'plugin-bbpress.php',
'bbpress.php',
'forums.php',
'forum.php',
'generic.php',
'page.php',
'single.php',
'singular.php',
'index.php'
);
return bbp_get_query_template( 'bbpress', $templates );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,631 @@
<?php
/**
* bbPress Updater
*
* @package bbPress
* @subpackage Core
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* If there is no raw DB version, this is the first installation
*
* @since 2.1.0 bbPress (r3764)
*
* @return bool True if update, False if not
*/
function bbp_is_install() {
return ! bbp_get_db_version_raw();
}
/**
* Compare the bbPress version to the DB version to determine if updating
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if update, False if not
*/
function bbp_is_update() {
$raw = (int) bbp_get_db_version_raw();
$cur = (int) bbp_get_db_version();
$retval = (bool) ( $raw < $cur );
return $retval;
}
/**
* Determine if bbPress is being activated
*
* Note that this function currently is not used in bbPress core and is here
* for third party plugins to use to check for bbPress activation.
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if activating bbPress, false if not
*/
function bbp_is_activation( $basename = '' ) {
global $pagenow;
$bbp = bbpress();
$action = false;
// Bail if not in admin/plugins
if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
return false;
}
if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
$action = $_REQUEST['action'];
} elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
$action = $_REQUEST['action2'];
}
// Bail if not activating
if ( empty( $action ) || ! in_array( $action, array( 'activate', 'activate-selected', true ) ) ) {
return false;
}
// The plugin(s) being activated
if ( $action === 'activate' ) {
$plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
} else {
$plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
}
// Set basename if empty
if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
$basename = $bbp->basename;
}
// Bail if no basename
if ( empty( $basename ) ) {
return false;
}
// Is bbPress being activated?
return in_array( $basename, $plugins, true );
}
/**
* Determine if bbPress is being deactivated
*
* @since 2.0.0 bbPress (r3421)
*
* @return bool True if deactivating bbPress, false if not
*/
function bbp_is_deactivation( $basename = '' ) {
global $pagenow;
$bbp = bbpress();
$action = false;
// Bail if not in admin/plugins
if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
return false;
}
if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
$action = $_REQUEST['action'];
} elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
$action = $_REQUEST['action2'];
}
// Bail if not deactivating
if ( empty( $action ) || ! in_array( $action, array( 'deactivate', 'deactivate-selected' ), true ) ) {
return false;
}
// The plugin(s) being deactivated
if ( $action === 'deactivate' ) {
$plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
} else {
$plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
}
// Set basename if empty
if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
$basename = $bbp->basename;
}
// Bail if no basename
if ( empty( $basename ) ) {
return false;
}
// Is bbPress being deactivated?
return in_array( $basename, $plugins, true );
}
/**
* Update the DB to the latest version
*
* @since 2.0.0 bbPress (r3421)
*/
function bbp_version_bump() {
update_option( '_bbp_db_version', bbp_get_db_version() );
}
/**
* Setup the bbPress updater
*
* @since 2.0.0 bbPress (r3419)
*/
function bbp_setup_updater() {
// Bail if no update needed
if ( ! bbp_is_update() ) {
return;
}
// Call the automated updater
bbp_version_updater();
}
/**
* Runs when a new site is created in a multisite network, and bbPress is active
* on that site (hooked to `bbp_new_site`)
*
* @since 2.6.0 bbPress (r6779)
*/
function bbp_setup_new_site( $site_id = 0 ) {
// Look for initial content
$created = is_multisite()
? get_blog_option( $site_id, '_bbp_flag_initial_content', false )
: get_option( '_bbp_flag_initial_content', false );
// Maybe create the initial content
if ( ! empty( $created ) ) {
bbp_create_initial_content();
// Flag initial content as created
is_multisite()
? update_blog_option( $site_id, '_bbp_flag_initial_content', true )
: update_option( '_bbp_flag_initial_content', true );
}
}
/**
* Create a default forum, topic, and reply
*
* @since 2.1.0 bbPress (r3767)
*
* @param array $args Array of arguments to override default values
*/
function bbp_create_initial_content( $args = array() ) {
// Cannot use bbp_get_current_user_id() during activation process
$user_id = get_current_user_id();
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'forum_author' => $user_id,
'forum_parent' => 0,
'forum_status' => 'publish',
'forum_title' => esc_html__( 'General', 'bbpress' ),
'forum_content' => esc_html__( 'General Discussion', 'bbpress' ),
'topic_author' => $user_id,
'topic_title' => esc_html__( 'Hello World!', 'bbpress' ),
'topic_content' => esc_html__( 'This is the very first topic in these forums.', 'bbpress' ),
'reply_author' => $user_id,
'reply_content' => esc_html__( 'And this is the very first reply.', 'bbpress' ),
), 'create_initial_content' );
// Use the same time for each post
$current_time = time();
$forum_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 80 );
$topic_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 60 );
$reply_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 40 );
// Create the initial forum
$forum_id = bbp_insert_forum( array(
'post_author' => $r['forum_author'],
'post_parent' => $r['forum_parent'],
'post_status' => $r['forum_status'],
'post_title' => $r['forum_title'],
'post_content' => $r['forum_content'],
'post_date' => $forum_time
) );
// Create the initial topic
$topic_id = bbp_insert_topic(
array(
'post_author' => $r['topic_author'],
'post_parent' => $forum_id,
'post_title' => $r['topic_title'],
'post_content' => $r['topic_content'],
'post_date' => $topic_time,
),
array(
'forum_id' => $forum_id
)
);
// Create the initial reply
$reply_id = bbp_insert_reply(
array(
'post_author' => $r['reply_author'],
'post_parent' => $topic_id,
'post_content' => $r['reply_content'],
'post_date' => $reply_time
),
array(
'forum_id' => $forum_id,
'topic_id' => $topic_id
)
);
return array(
'forum_id' => $forum_id,
'topic_id' => $topic_id,
'reply_id' => $reply_id
);
}
/**
* The version updater looks at what the current database version is, and
* runs whatever other code is needed.
*
* This is most-often used when the data schema changes, but should also be used
* to correct issues with bbPress meta-data silently on software update.
*
* @since 2.2.0 bbPress (r4104)
*/
function bbp_version_updater() {
// Get the raw database version
$raw_db_version = (int) bbp_get_db_version_raw();
// Only run updater if previous installation exists
if ( ! empty( $raw_db_version ) ) {
/** 2.0 Branch ********************************************************/
// 2.0, 2.0.1, 2.0.2, 2.0.3
if ( $raw_db_version < 200 ) {
// No changes
}
/** 2.1 Branch ********************************************************/
// 2.1, 2.1.1
if ( $raw_db_version < 211 ) {
/**
* Repair private and hidden forum data
*
* @link https://bbpress.trac.wordpress.org/ticket/1891
*/
bbp_admin_repair_forum_visibility();
}
/** 2.2 Branch ********************************************************/
// 2.2.x
if ( $raw_db_version < 220 ) {
// Remove any old bbPress roles
bbp_remove_roles();
// Remove capabilities
bbp_remove_caps();
}
/** 2.3 Branch ********************************************************/
// 2.3.x
if ( $raw_db_version < 230 ) {
// No changes
}
/** 2.4 Branch ********************************************************/
// 2.4.x
if ( $raw_db_version < 240 ) {
// No changes
}
/** 2.5 Branch ********************************************************/
// 2.5.x
if ( $raw_db_version < 250 ) {
// No changes
}
/** 2.6 Branch ********************************************************/
// Smaller installs run the upgrades directly
if ( ! bbp_is_large_install() ) {
/**
* Upgrade user favorites and subscriptions
*/
if ( $raw_db_version < 261 ) {
bbp_admin_upgrade_user_favorites();
bbp_admin_upgrade_user_topic_subscriptions();
bbp_admin_upgrade_user_forum_subscriptions();
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 262 ) {
bbp_admin_upgrade_user_engagements();
}
/**
* Repair forum hidden reply count
*/
if ( $raw_db_version < 263 ) {
bbp_admin_repair_forum_hidden_reply_count();
}
// Large installs require manual intervention
} else {
/**
* Upgrade user favorites and subscriptions
*/
if ( $raw_db_version < 261 ) {
bbp_add_pending_upgrade( 'bbp-user-favorites-move' );
bbp_add_pending_upgrade( 'bbp-user-topic-subscriptions-move' );
bbp_add_pending_upgrade( 'bbp-user-forum-subscriptions-move' );
// Set strategy to pre-2.6 on large network
update_option( '_bbp_engagements_strategy', 'user' );
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 262 ) {
bbp_add_pending_upgrade( 'bbp-user-topic-engagements-move' );
// Set strategy to pre-2.6 on large network
update_option( '_bbp_engagements_strategy', 'user' );
}
/**
* Upgrade user engagements
*/
if ( $raw_db_version < 263 ) {
bbp_add_pending_upgrade( 'bbp-forum-hidden-replies' );
}
}
}
/** All done! *************************************************************/
// Bump the version
bbp_version_bump();
// Delete rewrite rules to force a flush
bbp_delete_rewrite_rules();
}
/**
* Redirect user to the "What's New" page on activation
*
* @since 2.2.0 bbPress (r4389)
*
* @internal Used internally to redirect bbPress to the about page on activation
*
* @return If network admin or bulk activation
*/
function bbp_add_activation_redirect() {
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
// Add the redirect trigger
update_user_option( get_current_user_id(), '_bbp_activation_redirect', true );
}
/**
* Redirect user to "What's New" page on activation
*
* @since 2.2.0 bbPress (r4389)
*
* @internal Used internally to redirect bbPress to the about page on activation
*
* @return If no transient, or in network admin, or is bulk activation
*/
function bbp_do_activation_redirect() {
// Bail if no redirect trigger
if ( ! get_user_option( '_bbp_activation_redirect' ) ) {
return;
}
// Delete the redirect trigger
delete_user_option( get_current_user_id(), '_bbp_activation_redirect' );
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
// Bail if the current user cannot see the about page
if ( ! current_user_can( 'bbp_about_page' ) ) {
return;
}
// Redirect to bbPress about page
bbp_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
}
/**
* Hooked to the 'bbp_activate' action, this helper function automatically makes
* the current user a Key Master in the forums if they just activated bbPress,
* regardless of the bbp_allow_global_access() setting.
*
* @since 2.4.0 bbPress (r4910)
*
* @internal Used to internally make the current user a keymaster on activation
*
* @return If user can't activate plugins or is already a keymaster
*/
function bbp_make_current_user_keymaster() {
// Catch all, to prevent premature user initialization
if ( ! did_action( 'set_current_user' ) ) {
return;
}
// Bail if not logged in or already a member of this site
if ( ! is_user_logged_in() ) {
return;
}
// Bail if the current user can't activate plugins since previous pageload
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
// Cannot use bbp_get_current_user_id() during activation process
$user_id = get_current_user_id();
// Get the current blog ID, to know if they should be promoted here
$blog_id = get_current_blog_id();
// Bail if user is not actually a member of this site
if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) {
return;
}
// Bail if the current user already has a forum role to prevent
// unexpected role and capability escalation.
if ( bbp_get_user_role( $user_id ) ) {
return;
}
// Make the current user a keymaster
bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
// Reload the current user so caps apply immediately
wp_get_current_user();
}
/** Pending Upgrades **********************************************************/
/**
* Return the number of pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return int
*/
function bbp_get_pending_upgrade_count( $type = '' ) {
return count( (array) bbp_get_pending_upgrades( $type ) );
}
/**
* Return an array of pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return array
*/
function bbp_get_pending_upgrades( $type = '' ) {
// Get the pending upgrades
$retval = (array) get_option( '_bbp_db_pending_upgrades', array() );
// Looking for a specific type?
if ( ! empty( $type ) ) {
$tools = bbp_get_admin_repair_tools( $type );
$plucked = array_keys( wp_list_pluck( $tools, 'type' ) );
$retval = array_intersect( $retval, $plucked );
}
return (array) $retval;
}
/**
* Add an upgrade ID to pending upgrades array
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $upgrade_id
*/
function bbp_add_pending_upgrade( $upgrade_id = '' ) {
// Get the pending upgrades option
$pending = bbp_get_pending_upgrades();
// Maybe add upgrade ID to end of pending array
if ( false === array_search( $upgrade_id, $pending, true ) ) {
array_push( $pending, $upgrade_id );
}
// Update and return
return update_option( '_bbp_db_pending_upgrades', $pending );
}
/**
* Add an upgrade ID to pending upgrades array
*
* @since 2.6.0 bbPress (r6895)
*
* @param string $upgrade_id
*/
function bbp_remove_pending_upgrade( $upgrade_id = '' ) {
// Get the pending upgrades option
$pending = bbp_get_pending_upgrades();
// Look for this upgrade ID
$index = array_search( $upgrade_id, $pending, true );
// Maybe remove upgrade ID from pending array
if ( false !== $index ) {
unset( $pending[ $index ] );
}
// Update and return
return update_option( '_bbp_db_pending_upgrades', $pending );
}
/**
* Delete all pending upgrades
*
* @since 2.6.0 bbPress (r6895)
*/
function bbp_clear_pending_upgrades() {
return delete_option( '_bbp_db_pending_upgrades' );
}
/**
* Maybe append an upgrade count to a string
*
* @since 2.6.0 bbPress (r6896)
*
* @param string $string Text to append count to
* @param string $type Type of pending upgrades (upgrade|repair|empty)
*
* @return string
*/
function bbp_maybe_append_pending_upgrade_count( $string = '', $type = '' ) {
// Look for an upgrade count
$count = bbp_get_pending_upgrade_count( $type );
// Append the count to the string
if ( ! empty( $count ) ) {
$suffix = ' <span class="awaiting-mod count-' . absint( $count ) . '"><span class="pending-count">' . bbp_number_format( $count ) . '</span></span>';
$string = "{$string}{$suffix}";
}
// Return the string, maybe with a count
return $string;
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More