| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * BuddyPress Group Forums (bbPress 1.1) Converter |
| | 5 | * - Default WordPress Install with shared database tables |
| | 6 | * - BuddyPress 1.6.x _bp_* |
| | 7 | * - bbPress 1.x _bb_* |
| | 8 | * |
| | 9 | * @since bbPress (rXXXX) |
| | 10 | * @link Codex Docs https://codex.bbpress.org/import-forums/bbpress-1-x-buddypress-group-forums |
| | 11 | */ |
| | 12 | class BuddyPressLegacy extends BBP_Converter_Base { |
| | 13 | |
| | 14 | /** |
| | 15 | * Main constructor |
| | 16 | * |
| | 17 | * @uses BuddyPress::setup_globals() |
| | 18 | */ |
| | 19 | function __construct() { |
| | 20 | parent::__construct(); |
| | 21 | $this->setup_globals(); |
| | 22 | } |
| | 23 | |
| | 24 | /** |
| | 25 | * Sets up the field mappings |
| | 26 | */ |
| | 27 | public function setup_globals() { |
| | 28 | |
| | 29 | /** Forum Section *****************************************************/ |
| | 30 | |
| | 31 | // Old forum id (Stored in postmeta) |
| | 32 | $this->field_map[] = array( |
| | 33 | 'from_tablename' => 'bb_forums', |
| | 34 | 'from_fieldname' => 'forum_id', |
| | 35 | 'to_type' => 'forum', |
| | 36 | 'to_fieldname' => '_bbp_old_forum_id' |
| | 37 | ); |
| | 38 | |
| | 39 | // Forum parent id (If no parent, then 0. Stored in postmeta) |
| | 40 | $this->field_map[] = array( |
| | 41 | 'from_tablename' => 'bb_forums', |
| | 42 | 'from_fieldname' => 'forum_parent', |
| | 43 | 'to_type' => 'forum', |
| | 44 | 'to_fieldname' => '_bbp_old_forum_parent_id' |
| | 45 | ); |
| | 46 | |
| | 47 | // Forum topic count (Stored in postmeta) |
| | 48 | $this->field_map[] = array( |
| | 49 | 'from_tablename' => 'bb_forums', |
| | 50 | 'from_fieldname' => 'topics', |
| | 51 | 'to_type' => 'forum', |
| | 52 | 'to_fieldname' => '_bbp_topic_count' |
| | 53 | ); |
| | 54 | |
| | 55 | // Forum reply count (Stored in postmeta) |
| | 56 | $this->field_map[] = array( |
| | 57 | 'from_tablename' => 'bb_forums', |
| | 58 | 'from_fieldname' => 'posts', |
| | 59 | 'to_type' => 'forum', |
| | 60 | 'to_fieldname' => '_bbp_reply_count' |
| | 61 | ); |
| | 62 | |
| | 63 | // Forum total topic count (Stored in postmeta) |
| | 64 | $this->field_map[] = array( |
| | 65 | 'from_tablename' => 'bb_forums', |
| | 66 | 'from_fieldname' => 'topics', |
| | 67 | 'to_type' => 'forum', |
| | 68 | 'to_fieldname' => '_bbp_total_topic_count' |
| | 69 | ); |
| | 70 | |
| | 71 | // Forum total reply count (Stored in postmeta) |
| | 72 | $this->field_map[] = array( |
| | 73 | 'from_tablename' => 'bb_forums', |
| | 74 | 'from_fieldname' => 'posts', |
| | 75 | 'to_type' => 'forum', |
| | 76 | 'to_fieldname' => '_bbp_total_reply_count' |
| | 77 | ); |
| | 78 | |
| | 79 | // Forum title. |
| | 80 | $this->field_map[] = array( |
| | 81 | 'from_tablename' => 'bb_forums', |
| | 82 | 'from_fieldname' => 'forum_name', |
| | 83 | 'to_type' => 'forum', |
| | 84 | 'to_fieldname' => 'post_title' |
| | 85 | ); |
| | 86 | |
| | 87 | // Forum slug (Clean name to avoid confilcts) |
| | 88 | $this->field_map[] = array( |
| | 89 | 'from_tablename' => 'bb_forums', |
| | 90 | 'from_fieldname' => 'forum_slug', |
| | 91 | 'to_type' => 'forum', |
| | 92 | 'to_fieldname' => 'post_name', |
| | 93 | 'callback_method' => 'callback_slug' |
| | 94 | ); |
| | 95 | |
| | 96 | // Forum description. |
| | 97 | $this->field_map[] = array( |
| | 98 | 'from_tablename' => 'bb_forums', |
| | 99 | 'from_fieldname' => 'forum_desc', |
| | 100 | 'to_type' => 'forum', |
| | 101 | 'to_fieldname' => 'post_content', |
| | 102 | 'callback_method' => 'callback_null' |
| | 103 | ); |
| | 104 | |
| | 105 | // Forum display order (Starts from 1) |
| | 106 | $this->field_map[] = array( |
| | 107 | 'from_tablename' => 'bb_forums', |
| | 108 | 'from_fieldname' => 'forum_order', |
| | 109 | 'to_type' => 'forum', |
| | 110 | 'to_fieldname' => 'menu_order' |
| | 111 | ); |
| | 112 | |
| | 113 | // Forum visibily |
| | 114 | $this->field_map[] = array( |
| | 115 | 'from_tablename' => 'bp_groups_groupmeta', |
| | 116 | 'from_fieldname' => 'group_id', |
| | 117 | 'join_tablename' => 'bb_forums', |
| | 118 | 'join_type' => 'LEFT', |
| | 119 | 'join_expression' => 'ON bp_groups_groupmeta.meta_value = bb_forums.forum_id AND bp_groups_groupmeta.meta_key = "forum_id"', |
| | 120 | 'to_type' => 'forum', |
| | 121 | 'to_fieldname' => 'post_status', |
| | 122 | 'callback_method' => 'callback_group_id' |
| | 123 | ); |
| | 124 | |
| | 125 | // Forum type (bbPress v1.x Forum > 0 or Category = 0, Stored in postmeta) |
| | 126 | $this->field_map[] = array( |
| | 127 | 'from_tablename' => 'bb_meta', |
| | 128 | 'from_fieldname' => 'meta_value', |
| | 129 | 'join_tablename' => 'bb_forums', |
| | 130 | 'join_type' => 'LEFT', |
| | 131 | 'join_expression' => 'ON bb_meta.object_id = bb_forums.forum_id AND bb_meta.meta_key = "forum_is_category"', |
| | 132 | 'to_type' => 'forum', |
| | 133 | 'to_fieldname' => '_bbp_forum_type', |
| | 134 | 'callback_method' => 'callback_forum_type' |
| | 135 | ); |
| | 136 | |
| | 137 | // Forum status (Set a default value 'open', Stored in postmeta) |
| | 138 | $this->field_map[] = array( |
| | 139 | 'to_type' => 'forum', |
| | 140 | 'to_fieldname' => '_bbp_status', |
| | 141 | 'default' => 'open' |
| | 142 | ); |
| | 143 | |
| | 144 | // Forum dates. |
| | 145 | $this->field_map[] = array( |
| | 146 | 'to_type' => 'forum', |
| | 147 | 'to_fieldname' => 'post_date', |
| | 148 | 'default' => date('Y-m-d H:i:s') |
| | 149 | ); |
| | 150 | $this->field_map[] = array( |
| | 151 | 'to_type' => 'forum', |
| | 152 | 'to_fieldname' => 'post_date_gmt', |
| | 153 | 'default' => date('Y-m-d H:i:s') |
| | 154 | ); |
| | 155 | $this->field_map[] = array( |
| | 156 | 'to_type' => 'forum', |
| | 157 | 'to_fieldname' => 'post_modified', |
| | 158 | 'default' => date('Y-m-d H:i:s') |
| | 159 | ); |
| | 160 | $this->field_map[] = array( |
| | 161 | 'to_type' => 'forum', |
| | 162 | 'to_fieldname' => 'post_modified_gmt', |
| | 163 | 'default' => date('Y-m-d H:i:s') |
| | 164 | ); |
| | 165 | |
| | 166 | /** Forum Subscriptions Section ***************************************/ |
| | 167 | |
| | 168 | /** |
| | 169 | * bbPress 1.x Forums do not support forum subscriptions |
| | 170 | */ |
| | 171 | |
| | 172 | /** Topic Section *****************************************************/ |
| | 173 | |
| | 174 | // Old topic id (Stored in postmeta) |
| | 175 | $this->field_map[] = array( |
| | 176 | 'from_tablename' => 'bb_topics', |
| | 177 | 'from_fieldname' => 'topic_id', |
| | 178 | 'to_type' => 'topic', |
| | 179 | 'to_fieldname' => '_bbp_old_topic_id' |
| | 180 | ); |
| | 181 | |
| | 182 | // Topic reply count (Stored in postmeta) |
| | 183 | $this->field_map[] = array( |
| | 184 | 'from_tablename' => 'bb_topics', |
| | 185 | 'from_fieldname' => 'topic_posts', |
| | 186 | 'to_type' => 'topic', |
| | 187 | 'to_fieldname' => '_bbp_reply_count', |
| | 188 | 'callback_method' => 'callback_topic_reply_count' |
| | 189 | ); |
| | 190 | |
| | 191 | // Topic total reply count (Includes unpublished replies, Stored in postmeta) |
| | 192 | $this->field_map[] = array( |
| | 193 | 'from_tablename' => 'bb_topics', |
| | 194 | 'from_fieldname' => 'topic_posts', |
| | 195 | 'to_type' => 'topic', |
| | 196 | 'to_fieldname' => '_bbp_total_reply_count', |
| | 197 | 'callback_method' => 'callback_topic_reply_count' |
| | 198 | ); |
| | 199 | |
| | 200 | // Topic parent forum id (If no parent, then 0. Stored in postmeta) |
| | 201 | $this->field_map[] = array( |
| | 202 | 'from_tablename' => 'bb_topics', |
| | 203 | 'from_fieldname' => 'forum_id', |
| | 204 | 'to_type' => 'topic', |
| | 205 | 'to_fieldname' => '_bbp_forum_id', |
| | 206 | 'callback_method' => 'callback_forumid' |
| | 207 | ); |
| | 208 | |
| | 209 | // Topic author. |
| | 210 | $this->field_map[] = array( |
| | 211 | 'from_tablename' => 'bb_topics', |
| | 212 | 'from_fieldname' => 'topic_poster', |
| | 213 | 'to_type' => 'topic', |
| | 214 | 'to_fieldname' => 'post_author', |
| | 215 | 'callback_method' => 'callback_userid' |
| | 216 | ); |
| | 217 | |
| | 218 | // Topic title. |
| | 219 | $this->field_map[] = array( |
| | 220 | 'from_tablename' => 'bb_topics', |
| | 221 | 'from_fieldname' => 'topic_title', |
| | 222 | 'to_type' => 'topic', |
| | 223 | 'to_fieldname' => 'post_title' |
| | 224 | ); |
| | 225 | |
| | 226 | // Topic slug (Clean name to avoid conflicts) |
| | 227 | $this->field_map[] = array( |
| | 228 | 'from_tablename' => 'bb_topics', |
| | 229 | 'from_fieldname' => 'topic_slug', |
| | 230 | 'to_type' => 'topic', |
| | 231 | 'to_fieldname' => 'post_name', |
| | 232 | 'callback_method' => 'callback_slug' |
| | 233 | ); |
| | 234 | |
| | 235 | // Topic content. |
| | 236 | // Note: We join the 'posts' table because 'topics' table does not include content. |
| | 237 | $this->field_map[] = array( |
| | 238 | 'from_tablename' => 'bb_posts', |
| | 239 | 'from_fieldname' => 'post_text', |
| | 240 | 'join_tablename' => 'bb_topics', |
| | 241 | 'join_type' => 'INNER', |
| | 242 | 'join_expression' => 'USING (topic_id) WHERE bb_posts.post_position IN (0,1)', |
| | 243 | 'to_type' => 'topic', |
| | 244 | 'to_fieldname' => 'post_content', |
| | 245 | 'callback_method' => 'callback_html' |
| | 246 | ); |
| | 247 | |
| | 248 | // Topic status (Spam, Trash or Publish, bbPress v1.x publish = 0, trash = 1 & spam = 2) |
| | 249 | $this->field_map[] = array( |
| | 250 | 'from_tablename' => 'bb_posts', |
| | 251 | 'from_fieldname' => 'post_status', |
| | 252 | 'join_tablename' => 'bb_topics', |
| | 253 | 'join_type' => 'INNER', |
| | 254 | 'join_expression' => 'USING (topic_id) WHERE bb_posts.post_position IN (0,1)', |
| | 255 | 'to_type' => 'topic', |
| | 256 | 'to_fieldname' => 'post_status', |
| | 257 | 'callback_method' => 'callback_status' |
| | 258 | ); |
| | 259 | |
| | 260 | // Topic status (Publish or Closed to new replies) |
| | 261 | $this->field_map[] = array( |
| | 262 | 'from_tablename' => 'bb_topics', |
| | 263 | 'from_fieldname' => 'topic_open', |
| | 264 | 'to_type' => 'topic', |
| | 265 | 'to_fieldname' => '_bbp_old_closed_status_id', |
| | 266 | 'callback_method' => 'callback_topic_status' |
| | 267 | ); |
| | 268 | |
| | 269 | // Topic author ip (Stored in postmeta) |
| | 270 | // Note: We join the 'posts' table because 'topics' table does not include author ip. |
| | 271 | $this->field_map[] = array( |
| | 272 | 'from_tablename' => 'bb_posts', |
| | 273 | 'from_fieldname' => 'poster_ip', |
| | 274 | 'join_tablename' => 'bb_topics', |
| | 275 | 'join_type' => 'INNER', |
| | 276 | 'join_expression' => 'USING (topic_id) WHERE bb_posts.post_position IN (0,1)', |
| | 277 | 'to_type' => 'topic', |
| | 278 | 'to_fieldname' => '_bbp_author_ip' |
| | 279 | ); |
| | 280 | |
| | 281 | // Topic parent forum id (If no parent, then 0) |
| | 282 | $this->field_map[] = array( |
| | 283 | 'from_tablename' => 'bb_topics', |
| | 284 | 'from_fieldname' => 'forum_id', |
| | 285 | 'to_type' => 'topic', |
| | 286 | 'to_fieldname' => 'post_parent', |
| | 287 | 'callback_method' => 'callback_forumid' |
| | 288 | ); |
| | 289 | |
| | 290 | // Sticky status (Stored in postmeta) |
| | 291 | $this->field_map[] = array( |
| | 292 | 'from_tablename' => 'bb_topics', |
| | 293 | 'from_fieldname' => 'topic_sticky', |
| | 294 | 'to_type' => 'topic', |
| | 295 | 'to_fieldname' => '_bbp_old_sticky_status_id', |
| | 296 | 'callback_method' => 'callback_sticky_status' |
| | 297 | ); |
| | 298 | |
| | 299 | // Topic dates. |
| | 300 | $this->field_map[] = array( |
| | 301 | 'from_tablename' => 'bb_topics', |
| | 302 | 'from_fieldname' => 'topic_start_time', |
| | 303 | 'to_type' => 'topic', |
| | 304 | 'to_fieldname' => 'post_date' |
| | 305 | ); |
| | 306 | $this->field_map[] = array( |
| | 307 | 'from_tablename' => 'bb_topics', |
| | 308 | 'from_fieldname' => 'topic_start_time', |
| | 309 | 'to_type' => 'topic', |
| | 310 | 'to_fieldname' => 'post_date_gmt' |
| | 311 | ); |
| | 312 | $this->field_map[] = array( |
| | 313 | 'from_tablename' => 'bb_topics', |
| | 314 | 'from_fieldname' => 'topic_time', |
| | 315 | 'to_type' => 'topic', |
| | 316 | 'to_fieldname' => 'post_modified' |
| | 317 | ); |
| | 318 | $this->field_map[] = array( |
| | 319 | 'from_tablename' => 'bb_topics', |
| | 320 | 'from_fieldname' => 'topic_time', |
| | 321 | 'to_type' => 'topic', |
| | 322 | 'to_fieldname' => 'post_modified_gmt' |
| | 323 | ); |
| | 324 | $this->field_map[] = array( |
| | 325 | 'from_tablename' => 'bb_topics', |
| | 326 | 'from_fieldname' => 'topic_time', |
| | 327 | 'to_type' => 'topic', |
| | 328 | 'to_fieldname' => '_bbp_last_active_time' |
| | 329 | ); |
| | 330 | |
| | 331 | /** Tags Section ******************************************************/ |
| | 332 | |
| | 333 | // Topic id. |
| | 334 | $this->field_map[] = array( |
| | 335 | 'from_tablename' => 'bb_term_relationships', |
| | 336 | 'from_fieldname' => 'object_id', |
| | 337 | 'to_type' => 'tags', |
| | 338 | 'to_fieldname' => 'objectid', |
| | 339 | 'callback_method' => 'callback_topicid' |
| | 340 | ); |
| | 341 | |
| | 342 | // Taxonomy ID. |
| | 343 | $this->field_map[] = array( |
| | 344 | 'from_tablename' => 'bb_term_taxonomy', |
| | 345 | 'from_fieldname' => 'term_taxonomy_id', |
| | 346 | 'join_tablename' => 'bb_term_relationships', |
| | 347 | 'join_type' => 'INNER', |
| | 348 | 'join_expression' => 'USING (term_taxonomy_id)', |
| | 349 | 'to_type' => 'tags', |
| | 350 | 'to_fieldname' => 'taxonomy' |
| | 351 | ); |
| | 352 | |
| | 353 | // Term description. |
| | 354 | $this->field_map[] = array( |
| | 355 | 'from_tablename' => 'bb_term_taxonomy', |
| | 356 | 'from_fieldname' => 'description', |
| | 357 | 'join_tablename' => 'bb_term_relationships', |
| | 358 | 'join_type' => 'INNER', |
| | 359 | 'join_expression' => 'USING (term_taxonomy_id)', |
| | 360 | 'to_type' => 'tags', |
| | 361 | 'to_fieldname' => 'description', |
| | 362 | 'callback_method' => 'callback_html' |
| | 363 | ); |
| | 364 | |
| | 365 | // Term text. |
| | 366 | $this->field_map[] = array( |
| | 367 | 'from_tablename' => 'bb_terms', |
| | 368 | 'from_fieldname' => 'name', |
| | 369 | 'join_tablename' => 'bb_term_taxonomy', |
| | 370 | 'join_type' => 'INNER', |
| | 371 | 'join_expression' => 'USING (term_id) WHERE bb_term_taxonomy.taxonomy = "bb_topic_tag"', |
| | 372 | 'to_type' => 'tags', |
| | 373 | 'to_fieldname' => 'name' |
| | 374 | ); |
| | 375 | |
| | 376 | // Term slug. |
| | 377 | $this->field_map[] = array( |
| | 378 | 'from_tablename' => 'bb_terms', |
| | 379 | 'from_fieldname' => 'slug', |
| | 380 | 'join_tablename' => 'bb_term_taxonomy', |
| | 381 | 'join_type' => 'INNER', |
| | 382 | 'join_expression' => 'USING (term_id) WHERE bb_term_taxonomy.taxonomy = "bb_topic_tag"', |
| | 383 | 'to_type' => 'tags', |
| | 384 | 'to_fieldname' => 'slug', |
| | 385 | 'callback_method' => 'callback_slug' |
| | 386 | ); |
| | 387 | |
| | 388 | /** Topic Subscriptions Section ***************************************/ |
| | 389 | |
| | 390 | // Subscribed user ID (Stored in usermeta) |
| | 391 | $this->field_map[] = array( |
| | 392 | 'from_tablename' => 'bb_term_relationships', |
| | 393 | 'from_fieldname' => 'user_id', |
| | 394 | 'to_type' => 'topic_subscriptions', |
| | 395 | 'to_fieldname' => 'user_id', |
| | 396 | 'callback_method' => 'callback_userid' |
| | 397 | ); |
| | 398 | |
| | 399 | // Join the 'term_taxonomy' table to link 'terms' 'term_relationships' tables |
| | 400 | $this->field_map[] = array( |
| | 401 | 'from_tablename' => 'bb_term_taxonomy', |
| | 402 | 'from_fieldname' => 'term_taxonomy_id', |
| | 403 | 'join_tablename' => 'bb_term_relationships', |
| | 404 | 'join_type' => 'INNER', |
| | 405 | 'join_expression' => 'USING (term_taxonomy_id)', |
| | 406 | 'to_type' => 'topic_subscriptions' |
| | 407 | ); |
| | 408 | |
| | 409 | // Subscribed topic ID (Stored in usermeta) |
| | 410 | $this->field_map[] = array( |
| | 411 | 'from_tablename' => 'bb_terms', |
| | 412 | 'from_fieldname' => 'name', |
| | 413 | 'join_tablename' => 'bb_term_taxonomy', |
| | 414 | 'join_type' => 'INNER', |
| | 415 | 'join_expression' => 'USING (term_id) WHERE bb_term_taxonomy.taxonomy = "bb_subscribe"', |
| | 416 | 'to_type' => 'topic_subscriptions', |
| | 417 | 'to_fieldname' => '_bbp_subscriptions', |
| | 418 | 'callback_method' => 'callback_topic_subscriptions' |
| | 419 | ); |
| | 420 | |
| | 421 | /** Favorites Section *************************************************/ |
| | 422 | |
| | 423 | // Favorited topic ID (Stored in usermeta) |
| | 424 | $this->field_map[] = array( |
| | 425 | 'from_tablename' => 'usermeta', |
| | 426 | 'from_fieldname' => 'meta_value', |
| | 427 | 'from_expression' => 'WHERE usermeta.meta_key = "bb_favorites"', |
| | 428 | 'to_type' => 'favorites', |
| | 429 | 'to_fieldname' => '_bbp_favorites' |
| | 430 | ); |
| | 431 | |
| | 432 | // Favorited user ID (Stored in usermeta) |
| | 433 | $this->field_map[] = array( |
| | 434 | 'from_tablename' => 'usermeta', |
| | 435 | 'from_fieldname' => 'user_id', |
| | 436 | 'from_expression' => 'WHERE usermeta.meta_key = "bb_favorites"', |
| | 437 | 'to_type' => 'favorites', |
| | 438 | 'to_fieldname' => 'user_id', |
| | 439 | 'callback_method' => 'callback_userid' |
| | 440 | ); |
| | 441 | |
| | 442 | /** Reply Section *****************************************************/ |
| | 443 | |
| | 444 | // Old reply id (Stored in postmeta) |
| | 445 | $this->field_map[] = array( |
| | 446 | 'from_tablename' => 'bb_posts', |
| | 447 | 'from_fieldname' => 'post_id', |
| | 448 | 'to_type' => 'reply', |
| | 449 | 'to_fieldname' => '_bbp_old_reply_id' |
| | 450 | ); |
| | 451 | |
| | 452 | // Reply parent topic id (If no parent, then 0. Stored in postmeta) |
| | 453 | // Note: We join the 'topics' table to limit the replies section to only import replies |
| | 454 | $this->field_map[] = array( |
| | 455 | 'from_tablename' => 'bb_topics', |
| | 456 | 'from_fieldname' => 'topic_id', |
| | 457 | 'join_tablename' => 'bb_posts', |
| | 458 | 'join_type' => 'INNER', |
| | 459 | 'join_expression' => 'USING (topic_id) WHERE bb_posts.post_position NOT IN (0,1)', |
| | 460 | 'to_type' => 'reply', |
| | 461 | 'to_fieldname' => '_bbp_topic_id', |
| | 462 | 'callback_method' => 'callback_topicid' |
| | 463 | ); |
| | 464 | |
| | 465 | // Reply parent forum id (If no parent, then 0. Stored in postmeta) |
| | 466 | $this->field_map[] = array( |
| | 467 | 'from_tablename' => 'bb_posts', |
| | 468 | 'from_fieldname' => 'forum_id', |
| | 469 | 'to_type' => 'reply', |
| | 470 | 'to_fieldname' => '_bbp_forum_id', |
| | 471 | 'callback_method' => 'callback_forumid' |
| | 472 | ); |
| | 473 | |
| | 474 | // Reply author ip (Stored in postmeta) |
| | 475 | $this->field_map[] = array( |
| | 476 | 'from_tablename' => 'bb_posts', |
| | 477 | 'from_fieldname' => 'poster_ip', |
| | 478 | 'to_type' => 'reply', |
| | 479 | 'to_fieldname' => '_bbp_author_ip' |
| | 480 | ); |
| | 481 | |
| | 482 | // Reply author. |
| | 483 | $this->field_map[] = array( |
| | 484 | 'from_tablename' => 'bb_posts', |
| | 485 | 'from_fieldname' => 'poster_id', |
| | 486 | 'to_type' => 'reply', |
| | 487 | 'to_fieldname' => 'post_author', |
| | 488 | 'callback_method' => 'callback_userid' |
| | 489 | ); |
| | 490 | |
| | 491 | // Reply status (Spam, Trash or Publish, bbPress v1.x publish = 0, trash = 1 & spam = 2) |
| | 492 | $this->field_map[] = array( |
| | 493 | 'from_tablename' => 'bb_posts', |
| | 494 | 'from_fieldname' => 'post_status', |
| | 495 | 'to_type' => 'reply', |
| | 496 | 'to_fieldname' => 'post_status', |
| | 497 | 'callback_method' => 'callback_status' |
| | 498 | ); |
| | 499 | |
| | 500 | // Reply content. |
| | 501 | $this->field_map[] = array( |
| | 502 | 'from_tablename' => 'bb_posts', |
| | 503 | 'from_fieldname' => 'post_text', |
| | 504 | 'to_type' => 'reply', |
| | 505 | 'to_fieldname' => 'post_content', |
| | 506 | 'callback_method' => 'callback_html' |
| | 507 | ); |
| | 508 | |
| | 509 | // Reply order. |
| | 510 | $this->field_map[] = array( |
| | 511 | 'from_tablename' => 'bb_posts', |
| | 512 | 'from_fieldname' => 'post_position', |
| | 513 | 'to_type' => 'reply', |
| | 514 | 'to_fieldname' => 'menu_order' |
| | 515 | ); |
| | 516 | |
| | 517 | // Reply parent topic id (If no parent, then 0) |
| | 518 | $this->field_map[] = array( |
| | 519 | 'from_tablename' => 'bb_posts', |
| | 520 | 'from_fieldname' => 'topic_id', |
| | 521 | 'to_type' => 'reply', |
| | 522 | 'to_fieldname' => 'post_parent', |
| | 523 | 'callback_method' => 'callback_topicid' |
| | 524 | ); |
| | 525 | |
| | 526 | // Reply dates. |
| | 527 | $this->field_map[] = array( |
| | 528 | 'from_tablename' => 'bb_posts', |
| | 529 | 'from_fieldname' => 'post_time', |
| | 530 | 'to_type' => 'reply', |
| | 531 | 'to_fieldname' => 'post_date' |
| | 532 | ); |
| | 533 | $this->field_map[] = array( |
| | 534 | 'from_tablename' => 'bb_posts', |
| | 535 | 'from_fieldname' => 'post_time', |
| | 536 | 'to_type' => 'reply', |
| | 537 | 'to_fieldname' => 'post_date_gmt' |
| | 538 | ); |
| | 539 | $this->field_map[] = array( |
| | 540 | 'from_tablename' => 'bb_posts', |
| | 541 | 'from_fieldname' => 'post_time', |
| | 542 | 'to_type' => 'reply', |
| | 543 | 'to_fieldname' => 'post_modified' |
| | 544 | ); |
| | 545 | $this->field_map[] = array( |
| | 546 | 'from_tablename' => 'bb_posts', |
| | 547 | 'from_fieldname' => 'post_time', |
| | 548 | 'to_type' => 'reply', |
| | 549 | 'to_fieldname' => 'post_modified_gmt' |
| | 550 | ); |
| | 551 | |
| | 552 | /** User Section ******************************************************/ |
| | 553 | |
| | 554 | // Store old user id (Stored in usermeta) |
| | 555 | $this->field_map[] = array( |
| | 556 | 'from_tablename' => 'users', |
| | 557 | 'from_fieldname' => 'ID', |
| | 558 | 'to_type' => 'user', |
| | 559 | 'to_fieldname' => '_bbp_old_user_id' |
| | 560 | ); |
| | 561 | |
| | 562 | // Store old user password (Stored in usermeta) |
| | 563 | $this->field_map[] = array( |
| | 564 | 'from_tablename' => 'users', |
| | 565 | 'from_fieldname' => 'user_pass', |
| | 566 | 'to_type' => 'user', |
| | 567 | 'to_fieldname' => '_bbp_password' |
| | 568 | ); |
| | 569 | |
| | 570 | // User name. |
| | 571 | $this->field_map[] = array( |
| | 572 | 'from_tablename' => 'users', |
| | 573 | 'from_fieldname' => 'user_login', |
| | 574 | 'to_type' => 'user', |
| | 575 | 'to_fieldname' => 'user_login' |
| | 576 | ); |
| | 577 | |
| | 578 | // User nice name. |
| | 579 | $this->field_map[] = array( |
| | 580 | 'from_tablename' => 'users', |
| | 581 | 'from_fieldname' => 'user_nicename', |
| | 582 | 'to_type' => 'user', |
| | 583 | 'to_fieldname' => 'user_nicename' |
| | 584 | ); |
| | 585 | |
| | 586 | // User email. |
| | 587 | $this->field_map[] = array( |
| | 588 | 'from_tablename' => 'users', |
| | 589 | 'from_fieldname' => 'user_email', |
| | 590 | 'to_type' => 'user', |
| | 591 | 'to_fieldname' => 'user_email' |
| | 592 | ); |
| | 593 | |
| | 594 | // User homepage. |
| | 595 | $this->field_map[] = array( |
| | 596 | 'from_tablename' => 'users', |
| | 597 | 'from_fieldname' => 'user_url', |
| | 598 | 'to_type' => 'user', |
| | 599 | 'to_fieldname' => 'user_url' |
| | 600 | ); |
| | 601 | |
| | 602 | // User registered. |
| | 603 | $this->field_map[] = array( |
| | 604 | 'from_tablename' => 'users', |
| | 605 | 'from_fieldname' => 'user_registered', |
| | 606 | 'to_type' => 'user', |
| | 607 | 'to_fieldname' => 'user_registered' |
| | 608 | ); |
| | 609 | |
| | 610 | // User status. |
| | 611 | $this->field_map[] = array( |
| | 612 | 'from_tablename' => 'users', |
| | 613 | 'from_fieldname' => 'user_status', |
| | 614 | 'to_type' => 'user', |
| | 615 | 'to_fieldname' => 'user_status' |
| | 616 | ); |
| | 617 | |
| | 618 | // User display name. |
| | 619 | $this->field_map[] = array( |
| | 620 | 'from_tablename' => 'users', |
| | 621 | 'from_fieldname' => 'display_name', |
| | 622 | 'to_type' => 'user', |
| | 623 | 'to_fieldname' => 'display_name' |
| | 624 | ); |
| | 625 | } |
| | 626 | |
| | 627 | /** |
| | 628 | * This method allows us to indicates what is or is not converted for each |
| | 629 | * converter. |
| | 630 | */ |
| | 631 | public function info() { |
| | 632 | return ''; |
| | 633 | } |
| | 634 | |
| | 635 | /** |
| | 636 | * Translate the post status from bbPress 1's numeric's to WordPress's |
| | 637 | * strings. |
| | 638 | * |
| | 639 | * @param int $status bbPress 1.x numeric post status |
| | 640 | * @return string WordPress safe |
| | 641 | */ |
| | 642 | public function callback_status( $status = 0 ) { |
| | 643 | switch ( $status ) { |
| | 644 | case 2 : |
| | 645 | $status = 'spam'; // bbp_get_spam_status_id() |
| | 646 | break; |
| | 647 | |
| | 648 | case 1 : |
| | 649 | $status = 'trash'; // bbp_get_trash_status_id() |
| | 650 | break; |
| | 651 | |
| | 652 | case 0 : |
| | 653 | default : |
| | 654 | $status = 'publish'; // bbp_get_public_status_id() |
| | 655 | break; |
| | 656 | } |
| | 657 | return $status; |
| | 658 | } |
| | 659 | |
| | 660 | /** |
| | 661 | * Translate the forum type from bbPress 1.x numeric's to WordPress's strings. |
| | 662 | * |
| | 663 | * @param int $status bbPress 1.x numeric forum type |
| | 664 | * @return string WordPress safe |
| | 665 | */ |
| | 666 | public function callback_forum_type( $status = 0 ) { |
| | 667 | if ( $status == 1 ) { |
| | 668 | $status = 'category'; |
| | 669 | } else { |
| | 670 | $status = 'forum'; |
| | 671 | } |
| | 672 | return $status; |
| | 673 | } |
| | 674 | |
| | 675 | /** |
| | 676 | * Translate the topic status from bbPress 1's numeric's to WordPress's |
| | 677 | * strings. |
| | 678 | * |
| | 679 | * @param int $topic_status bbPress 1.x numeric status |
| | 680 | * @return string WordPress safe |
| | 681 | */ |
| | 682 | public function callback_topic_status( $topic_status = 1 ) { |
| | 683 | switch ( $topic_status ) { |
| | 684 | case 0 : |
| | 685 | $topic_status = 'closed'; // bbp_get_closed_status_id() |
| | 686 | break; |
| | 687 | |
| | 688 | case 1 : |
| | 689 | default : |
| | 690 | $topic_status = 'publish'; // bbp_get_public_status_id() |
| | 691 | break; |
| | 692 | } |
| | 693 | return $topic_status; |
| | 694 | } |
| | 695 | |
| | 696 | /** |
| | 697 | * Translate the topic sticky status type from bbPress 1.x numeric's to WordPress's strings. |
| | 698 | * |
| | 699 | * @param int $status bbPress 1.x numeric forum type |
| | 700 | * @return string WordPress safe |
| | 701 | */ |
| | 702 | public function callback_sticky_status( $status = 0 ) { |
| | 703 | switch ( $status ) { |
| | 704 | case 2 : |
| | 705 | $status = 'super-sticky'; // bbPress Super Sticky 'topic_sticky = 2' |
| | 706 | break; |
| | 707 | |
| | 708 | case 1 : |
| | 709 | $status = 'sticky'; // bbPress Sticky 'topic_sticky = 1' |
| | 710 | break; |
| | 711 | |
| | 712 | case 0 : |
| | 713 | default : |
| | 714 | $status = 'normal'; // bbPress Normal Topic 'topic_sticky = 0' |
| | 715 | break; |
| | 716 | } |
| | 717 | return $status; |
| | 718 | } |
| | 719 | |
| | 720 | /** |
| | 721 | * Verify the topic reply count. |
| | 722 | * |
| | 723 | * @param int $count bbPress 1.x topic and reply counts |
| | 724 | * @return string WordPress safe |
| | 725 | */ |
| | 726 | public function callback_topic_reply_count( $count = 1 ) { |
| | 727 | $count = absint( (int) $count - 1 ); |
| | 728 | return $count; |
| | 729 | } |
| | 730 | |
| | 731 | /** |
| | 732 | * This method is to save the salt and password together. That |
| | 733 | * way when we authenticate it we can get it out of the database |
| | 734 | * as one value. Array values are auto sanitized by WordPress. |
| | 735 | */ |
| | 736 | public function callback_savepass( $field, $row ) { |
| | 737 | return false; |
| | 738 | } |
| | 739 | |
| | 740 | /** |
| | 741 | * This method is to take the pass out of the database and compare |
| | 742 | * to a pass the user has typed in. |
| | 743 | */ |
| | 744 | public function authenticate_pass( $password, $serialized_pass ) { |
| | 745 | return false; |
| | 746 | } |
| | 747 | |
| | 748 | /** |
| | 749 | * This callback strips `topic-` from topic subscriptions taxonomy |
| | 750 | * |
| | 751 | * @since (r5572) |
| | 752 | * |
| | 753 | * @param string $field Topic ID |
| | 754 | * @return integer WordPress safe |
| | 755 | */ |
| | 756 | protected function callback_topic_subscriptions( $field ) { |
| | 757 | |
| | 758 | // Replace 'topic-' with '' so that only the original topic ID remains |
| | 759 | $field = absint( (int) preg_replace( '/(topic-)(\d+)/', '$2', $field ) ); |
| | 760 | return $field; |
| | 761 | } |
| | 762 | |
| | 763 | /** |
| | 764 | * Takes the passed group id and queries for the group status. From there, we |
| | 765 | * conform it to bbPress standards. |
| | 766 | * |
| | 767 | * @since (rXXXX) |
| | 768 | * |
| | 769 | * @param string $field Group id. |
| | 770 | * @return string Group forum status. |
| | 771 | */ |
| | 772 | protected function callback_group_id( $field ) { |
| | 773 | |
| | 774 | // Use the provided group id to get the group status |
| | 775 | $status = (string) $this->wpdb->get_var( $this->wpdb->prepare( 'SELECT status FROM ' . $this->wpdb->prefix . 'bp_groups WHERE id = %d LIMIT 1', $field ) ); |
| | 776 | |
| | 777 | // Conform the BP status to our use |
| | 778 | switch ( $status ) { |
| | 779 | case 'private' : |
| | 780 | $status = bbp_get_private_status_id(); |
| | 781 | break; |
| | 782 | |
| | 783 | case 'hidden' : |
| | 784 | $status = bbp_get_hidden_status_id(); |
| | 785 | break; |
| | 786 | |
| | 787 | case '' : |
| | 788 | $status = bbp_get_orphan_status_id(); |
| | 789 | break; |
| | 790 | |
| | 791 | default : |
| | 792 | $status = bbp_get_public_status_id(); |
| | 793 | break; |
| | 794 | } |
| | 795 | |
| | 796 | return $status; |
| | 797 | } |
| | 798 | |
| | 799 | /** |
| | 800 | * This callback: |
| | 801 | * |
| | 802 | * - turns off smiley parsing |
| | 803 | * - processes any custom parser.php attributes |
| | 804 | * - decodes necessary HTML entities |
| | 805 | */ |
| | 806 | protected function callback_html( $field ) { |
| | 807 | require_once( bbpress()->admin->admin_dir . 'parser.php' ); |
| | 808 | $bbcode = BBCode::getInstance(); |
| | 809 | $bbcode->enable_smileys = false; |
| | 810 | $bbcode->smiley_regex = false; |
| | 811 | return html_entity_decode( $bbcode->Parse( $field ) ); |
| | 812 | } |
| | 813 | } |