| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Implementation of Drupal v7.x Forum converter. |
|---|
| 5 | * |
|---|
| 6 | * @since bbPress (r5057) |
|---|
| 7 | * @link Codex Docs http://codex.bbpress.org/import-forums/drupal |
|---|
| 8 | */ |
|---|
| 9 | class Drupal7 extends BBP_Converter_Base { |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * Main Constructor |
|---|
| 13 | * |
|---|
| 14 | * @uses Drupal7::setup_globals() |
|---|
| 15 | */ |
|---|
| 16 | function __construct() { |
|---|
| 17 | parent::__construct(); |
|---|
| 18 | $this->setup_globals(); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Sets up the field mappings |
|---|
| 23 | */ |
|---|
| 24 | public function setup_globals() { |
|---|
| 25 | |
|---|
| 26 | /** Forum Section *****************************************************/ |
|---|
| 27 | |
|---|
| 28 | // Forum id (Stored in postmeta) |
|---|
| 29 | $this->field_map[] = array( |
|---|
| 30 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 31 | 'from_fieldname' => 'tid', |
|---|
| 32 | 'to_type' => 'forum', |
|---|
| 33 | 'to_fieldname' => '_bbp_forum_id' |
|---|
| 34 | ); |
|---|
| 35 | |
|---|
| 36 | // Forum parent id (If no parent, then 0, Stored in postmeta) |
|---|
| 37 | $this->field_map[] = array( |
|---|
| 38 | 'from_tablename' => 'taxonomy_term_hierarchy', |
|---|
| 39 | 'from_fieldname' => 'parent', |
|---|
| 40 | 'join_tablename' => 'taxonomy_term_data', |
|---|
| 41 | 'join_type' => 'INNER', |
|---|
| 42 | 'join_expression' => 'USING (tid)', |
|---|
| 43 | 'from_expression' => 'LEFT JOIN taxonomy_vocabulary AS taxonomy_vocabulary USING (vid) WHERE module = "forum"', |
|---|
| 44 | 'to_type' => 'forum', |
|---|
| 45 | 'to_fieldname' => '_bbp_forum_parent_id' |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | // Forum title. |
|---|
| 49 | $this->field_map[] = array( |
|---|
| 50 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 51 | 'from_fieldname' => 'name', |
|---|
| 52 | 'to_type' => 'forum', |
|---|
| 53 | 'to_fieldname' => 'post_title' |
|---|
| 54 | ); |
|---|
| 55 | |
|---|
| 56 | // Forum slug (Clean name to avoid conflicts) |
|---|
| 57 | $this->field_map[] = array( |
|---|
| 58 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 59 | 'from_fieldname' => 'name', |
|---|
| 60 | 'to_type' => 'forum', |
|---|
| 61 | 'to_fieldname' => 'post_name', |
|---|
| 62 | 'callback_method' => 'callback_slug' |
|---|
| 63 | ); |
|---|
| 64 | |
|---|
| 65 | // Forum description. |
|---|
| 66 | $this->field_map[] = array( |
|---|
| 67 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 68 | 'from_fieldname' => 'description', |
|---|
| 69 | 'to_type' => 'forum', |
|---|
| 70 | 'to_fieldname' => 'post_content', |
|---|
| 71 | 'callback_method' => 'callback_null' |
|---|
| 72 | ); |
|---|
| 73 | |
|---|
| 74 | // Forum display order (Starts from 1) |
|---|
| 75 | $this->field_map[] = array( |
|---|
| 76 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 77 | 'from_fieldname' => 'weight', |
|---|
| 78 | 'to_type' => 'forum', |
|---|
| 79 | 'to_fieldname' => 'menu_order' |
|---|
| 80 | ); |
|---|
| 81 | |
|---|
| 82 | // Forum dates. |
|---|
| 83 | $this->field_map[] = array( |
|---|
| 84 | 'to_type' => 'forum', |
|---|
| 85 | 'to_fieldname' => 'post_date', |
|---|
| 86 | 'default' => date('Y-m-d H:i:s') |
|---|
| 87 | ); |
|---|
| 88 | $this->field_map[] = array( |
|---|
| 89 | 'to_type' => 'forum', |
|---|
| 90 | 'to_fieldname' => 'post_date_gmt', |
|---|
| 91 | 'default' => date('Y-m-d H:i:s') |
|---|
| 92 | ); |
|---|
| 93 | $this->field_map[] = array( |
|---|
| 94 | 'to_type' => 'forum', |
|---|
| 95 | 'to_fieldname' => 'post_modified', |
|---|
| 96 | 'default' => date('Y-m-d H:i:s') |
|---|
| 97 | ); |
|---|
| 98 | $this->field_map[] = array( |
|---|
| 99 | 'to_type' => 'forum', |
|---|
| 100 | 'to_fieldname' => 'post_modified_gmt', |
|---|
| 101 | 'default' => date('Y-m-d H:i:s') |
|---|
| 102 | ); |
|---|
| 103 | |
|---|
| 104 | /** Topic Section *****************************************************/ |
|---|
| 105 | |
|---|
| 106 | // Topic id (Stored in postmeta) |
|---|
| 107 | $this->field_map[] = array( |
|---|
| 108 | 'from_tablename' => 'forum_index', |
|---|
| 109 | 'from_fieldname' => 'nid', |
|---|
| 110 | 'to_type' => 'topic', |
|---|
| 111 | 'to_fieldname' => '_bbp_topic_id' |
|---|
| 112 | ); |
|---|
| 113 | |
|---|
| 114 | // Topic reply count (Stored in postmeta) |
|---|
| 115 | $this->field_map[] = array( |
|---|
| 116 | 'from_tablename' => 'forum_index', |
|---|
| 117 | 'from_fieldname' => 'comment_count', |
|---|
| 118 | 'to_type' => 'topic', |
|---|
| 119 | 'to_fieldname' => '_bbp_reply_count', |
|---|
| 120 | 'callback_method' => 'callback_topic_reply_count' |
|---|
| 121 | ); |
|---|
| 122 | |
|---|
| 123 | // Topic total reply count (Includes unpublished replies, Stored in postmeta) |
|---|
| 124 | $this->field_map[] = array( |
|---|
| 125 | 'from_tablename' => 'forum_index', |
|---|
| 126 | 'from_fieldname' => 'comment_count', |
|---|
| 127 | 'to_type' => 'topic', |
|---|
| 128 | 'to_fieldname' => '_bbp_total_reply_count', |
|---|
| 129 | 'callback_method' => 'callback_topic_reply_count' |
|---|
| 130 | ); |
|---|
| 131 | |
|---|
| 132 | // Topic parent forum id (If no parent, then 0. Stored in postmeta) |
|---|
| 133 | $this->field_map[] = array( |
|---|
| 134 | 'from_tablename' => 'forum_index', |
|---|
| 135 | 'from_fieldname' => 'tid', |
|---|
| 136 | 'to_type' => 'topic', |
|---|
| 137 | 'to_fieldname' => '_bbp_forum_id', |
|---|
| 138 | 'callback_method' => 'callback_forumid' |
|---|
| 139 | ); |
|---|
| 140 | |
|---|
| 141 | // Topic author. |
|---|
| 142 | // Note: We join the 'node' table because 'forum_index' table does not include author id. |
|---|
| 143 | $this->field_map[] = array( |
|---|
| 144 | 'from_tablename' => 'node', |
|---|
| 145 | 'from_fieldname' => 'uid', |
|---|
| 146 | 'join_tablename' => 'forum_index', |
|---|
| 147 | 'join_type' => 'INNER', |
|---|
| 148 | 'join_expression' => 'ON node.nid = forum_index.nid', |
|---|
| 149 | 'to_type' => 'topic', |
|---|
| 150 | 'to_fieldname' => 'post_author', |
|---|
| 151 | 'callback_method' => 'callback_userid' |
|---|
| 152 | ); |
|---|
| 153 | |
|---|
| 154 | // Topic content. |
|---|
| 155 | // Note: We join the 'field_data_body' table because 'node' or 'forum_index' table does not include topic content. |
|---|
| 156 | $this->field_map[] = array( |
|---|
| 157 | 'from_tablename' => 'field_data_body', |
|---|
| 158 | 'from_fieldname' => 'body_value', |
|---|
| 159 | 'join_tablename' => 'node', |
|---|
| 160 | 'join_type' => 'INNER', |
|---|
| 161 | 'join_expression' => 'ON field_data_body.revision_id = node.vid', |
|---|
| 162 | 'to_type' => 'topic', |
|---|
| 163 | 'to_fieldname' => 'post_content', |
|---|
| 164 | 'callback_method' => 'callback_html' |
|---|
| 165 | ); |
|---|
| 166 | |
|---|
| 167 | // Topic title. |
|---|
| 168 | $this->field_map[] = array( |
|---|
| 169 | 'from_tablename' => 'forum_index', |
|---|
| 170 | 'from_fieldname' => 'title', |
|---|
| 171 | 'to_type' => 'topic', |
|---|
| 172 | 'to_fieldname' => 'post_title' |
|---|
| 173 | ); |
|---|
| 174 | |
|---|
| 175 | // Topic slug (Clean name to avoid conflicts) |
|---|
| 176 | $this->field_map[] = array( |
|---|
| 177 | 'from_tablename' => 'forum_index', |
|---|
| 178 | 'from_fieldname' => 'title', |
|---|
| 179 | 'to_type' => 'topic', |
|---|
| 180 | 'to_fieldname' => 'post_name', |
|---|
| 181 | 'callback_method' => 'callback_slug' |
|---|
| 182 | ); |
|---|
| 183 | |
|---|
| 184 | // Topic parent forum id (If no parent, then 0) |
|---|
| 185 | $this->field_map[] = array( |
|---|
| 186 | 'from_tablename' => 'forum_index', |
|---|
| 187 | 'from_fieldname' => 'tid', |
|---|
| 188 | 'to_type' => 'topic', |
|---|
| 189 | 'to_fieldname' => 'post_parent', |
|---|
| 190 | 'callback_method' => 'callback_forumid' |
|---|
| 191 | ); |
|---|
| 192 | |
|---|
| 193 | // Topic dates. |
|---|
| 194 | $this->field_map[] = array( |
|---|
| 195 | 'from_tablename' => 'forum_index', |
|---|
| 196 | 'from_fieldname' => 'created', |
|---|
| 197 | 'to_type' => 'topic', |
|---|
| 198 | 'to_fieldname' => 'post_date', |
|---|
| 199 | 'callback_method' => 'callback_datetime' |
|---|
| 200 | ); |
|---|
| 201 | $this->field_map[] = array( |
|---|
| 202 | 'from_tablename' => 'forum_index', |
|---|
| 203 | 'from_fieldname' => 'created', |
|---|
| 204 | 'to_type' => 'topic', |
|---|
| 205 | 'to_fieldname' => 'post_date_gmt', |
|---|
| 206 | 'callback_method' => 'callback_datetime' |
|---|
| 207 | ); |
|---|
| 208 | $this->field_map[] = array( |
|---|
| 209 | 'from_tablename' => 'forum_index', |
|---|
| 210 | 'from_fieldname' => 'last_comment_timestamp', |
|---|
| 211 | 'to_type' => 'topic', |
|---|
| 212 | 'to_fieldname' => 'post_modified', |
|---|
| 213 | 'callback_method' => 'callback_datetime' |
|---|
| 214 | ); |
|---|
| 215 | $this->field_map[] = array( |
|---|
| 216 | 'from_tablename' => 'forum_index', |
|---|
| 217 | 'from_fieldname' => 'last_comment_timestamp', |
|---|
| 218 | 'to_type' => 'topic', |
|---|
| 219 | 'to_fieldname' => 'post_modified_gmt', |
|---|
| 220 | 'callback_method' => 'callback_datetime' |
|---|
| 221 | ); |
|---|
| 222 | $this->field_map[] = array( |
|---|
| 223 | 'from_tablename' => 'forum_index', |
|---|
| 224 | 'from_fieldname' => 'last_comment_timestamp', |
|---|
| 225 | 'to_type' => 'topic', |
|---|
| 226 | 'to_fieldname' => '_bbp_last_active_time', |
|---|
| 227 | 'callback_method' => 'callback_datetime' |
|---|
| 228 | ); |
|---|
| 229 | |
|---|
| 230 | // Topic status (Drupal v7.x Comments Enabled no = 0, closed = 1 & open = 2) |
|---|
| 231 | $this->field_map[] = array( |
|---|
| 232 | 'from_tablename' => 'node', |
|---|
| 233 | 'from_fieldname' => 'comment', |
|---|
| 234 | 'join_tablename' => 'forum_index', |
|---|
| 235 | 'join_type' => 'INNER', |
|---|
| 236 | 'join_expression' => 'ON node.nid = forum_index.nid', |
|---|
| 237 | 'to_type' => 'topic', |
|---|
| 238 | 'to_fieldname' => 'post_status', |
|---|
| 239 | 'callback_method' => 'callback_topic_status' |
|---|
| 240 | ); |
|---|
| 241 | |
|---|
| 242 | /** Tags Section ******************************************************/ |
|---|
| 243 | |
|---|
| 244 | // Topic id. |
|---|
| 245 | $this->field_map[] = array( |
|---|
| 246 | 'from_tablename' => 'field_data_field_tags', |
|---|
| 247 | 'from_fieldname' => 'entity_id', |
|---|
| 248 | 'to_type' => 'tags', |
|---|
| 249 | 'to_fieldname' => 'objectid', |
|---|
| 250 | 'callback_method' => 'callback_topicid' |
|---|
| 251 | ); |
|---|
| 252 | |
|---|
| 253 | // Taxonomy ID. |
|---|
| 254 | $this->field_map[] = array( |
|---|
| 255 | 'from_tablename' => 'field_data_field_tags', |
|---|
| 256 | 'from_fieldname' => 'field_tags_tid', |
|---|
| 257 | 'to_type' => 'tags', |
|---|
| 258 | 'to_fieldname' => 'taxonomy' |
|---|
| 259 | ); |
|---|
| 260 | |
|---|
| 261 | // Term name. |
|---|
| 262 | $this->field_map[] = array( |
|---|
| 263 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 264 | 'from_fieldname' => 'name', |
|---|
| 265 | 'join_tablename' => 'field_data_field_tags', |
|---|
| 266 | 'join_type' => 'INNER', |
|---|
| 267 | 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid', |
|---|
| 268 | 'to_type' => 'tags', |
|---|
| 269 | 'to_fieldname' => 'name' |
|---|
| 270 | ); |
|---|
| 271 | |
|---|
| 272 | /* Pending: 'Topic-Tag' Descriptions & Slugs with bbPress Importer |
|---|
| 273 | /* Pending: http://bbpress.trac.wordpress.org/ticket/2399 |
|---|
| 274 | |
|---|
| 275 | // Term slug. |
|---|
| 276 | $this->field_map[] = array( |
|---|
| 277 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 278 | 'from_fieldname' => 'description', |
|---|
| 279 | 'join_tablename' => 'field_data_field_tags', |
|---|
| 280 | 'join_type' => 'INNER', |
|---|
| 281 | 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid', |
|---|
| 282 | 'to_type' => 'tags', |
|---|
| 283 | 'to_fieldname' => 'slug' |
|---|
| 284 | ); |
|---|
| 285 | |
|---|
| 286 | // Term description. |
|---|
| 287 | $this->field_map[] = array( |
|---|
| 288 | 'from_tablename' => 'taxonomy_term_data', |
|---|
| 289 | 'from_fieldname' => 'description', |
|---|
| 290 | 'join_tablename' => 'field_data_field_tags', |
|---|
| 291 | 'join_type' => 'INNER', |
|---|
| 292 | 'join_expression' => 'ON field_tags_tid = taxonomy_term_data.tid', |
|---|
| 293 | 'to_type' => 'tags', |
|---|
| 294 | 'to_fieldname' => 'description' |
|---|
| 295 | ); |
|---|
| 296 | */ |
|---|
| 297 | |
|---|
| 298 | /** Reply Section *****************************************************/ |
|---|
| 299 | |
|---|
| 300 | // Reply id (Stored in postmeta) |
|---|
| 301 | $this->field_map[] = array( |
|---|
| 302 | 'from_tablename' => 'comment', |
|---|
| 303 | 'from_fieldname' => 'cid', |
|---|
| 304 | 'to_type' => 'reply', |
|---|
| 305 | 'to_fieldname' => '_bbp_post_id' |
|---|
| 306 | ); |
|---|
| 307 | |
|---|
| 308 | // Reply parent forum id (If no parent, then 0. Stored in postmeta) |
|---|
| 309 | // Note: We join the 'forum' table because 'comment' table does not include parent forum id. |
|---|
| 310 | $this->field_map[] = array( |
|---|
| 311 | 'from_tablename' => 'forum', |
|---|
| 312 | 'from_fieldname' => 'tid', |
|---|
| 313 | 'join_tablename' => 'comment', |
|---|
| 314 | 'join_type' => 'INNER', |
|---|
| 315 | 'join_expression' => 'ON forum.nid = comment.nid', |
|---|
| 316 | 'to_type' => 'reply', |
|---|
| 317 | 'to_fieldname' => '_bbp_forum_id', |
|---|
| 318 | 'callback_method' => 'callback_topicid_to_forumid' |
|---|
| 319 | ); |
|---|
| 320 | |
|---|
| 321 | // Reply parent topic id (If no parent, then 0. Stored in postmeta) |
|---|
| 322 | $this->field_map[] = array( |
|---|
| 323 | 'from_tablename' => 'comment', |
|---|
| 324 | 'from_fieldname' => 'nid', |
|---|
| 325 | 'to_type' => 'reply', |
|---|
| 326 | 'to_fieldname' => '_bbp_topic_id', |
|---|
| 327 | 'callback_method' => 'callback_topicid' |
|---|
| 328 | ); |
|---|
| 329 | |
|---|
| 330 | // Reply parent reply id (If no parent, then 0. Stored in postmeta) |
|---|
| 331 | $this->field_map[] = array( |
|---|
| 332 | 'from_tablename' => 'comment', |
|---|
| 333 | 'from_fieldname' => 'pid', |
|---|
| 334 | 'to_type' => 'reply', |
|---|
| 335 | 'to_fieldname' => '_bbp_reply_to' |
|---|
| 336 | ); |
|---|
| 337 | |
|---|
| 338 | // Reply author ip (Stored in postmeta) |
|---|
| 339 | $this->field_map[] = array( |
|---|
| 340 | 'from_tablename' => 'comment', |
|---|
| 341 | 'from_fieldname' => 'hostname', |
|---|
| 342 | 'to_type' => 'reply', |
|---|
| 343 | 'to_fieldname' => '_bbp_author_ip' |
|---|
| 344 | ); |
|---|
| 345 | |
|---|
| 346 | // Reply author. |
|---|
| 347 | $this->field_map[] = array( |
|---|
| 348 | 'from_tablename' => 'comment', |
|---|
| 349 | 'from_fieldname' => 'uid', |
|---|
| 350 | 'to_type' => 'reply', |
|---|
| 351 | 'to_fieldname' => 'post_author', |
|---|
| 352 | 'callback_method' => 'callback_userid' |
|---|
| 353 | ); |
|---|
| 354 | |
|---|
| 355 | // Reply title. |
|---|
| 356 | $this->field_map[] = array( |
|---|
| 357 | 'from_tablename' => 'comment', |
|---|
| 358 | 'from_fieldname' => 'subject', |
|---|
| 359 | 'to_type' => 'reply', |
|---|
| 360 | 'to_fieldname' => 'post_title' |
|---|
| 361 | ); |
|---|
| 362 | |
|---|
| 363 | // Reply slug (Clean name to avoid conflicts) |
|---|
| 364 | $this->field_map[] = array( |
|---|
| 365 | 'from_tablename' => 'comment', |
|---|
| 366 | 'from_fieldname' => 'subject', |
|---|
| 367 | 'to_type' => 'reply', |
|---|
| 368 | 'to_fieldname' => 'post_name', |
|---|
| 369 | 'callback_method' => 'callback_slug' |
|---|
| 370 | ); |
|---|
| 371 | |
|---|
| 372 | // Reply content. |
|---|
| 373 | // Note: We join the 'field_data_comment_body' table because 'comment' table does not include reply content. |
|---|
| 374 | $this->field_map[] = array( |
|---|
| 375 | 'from_tablename' => 'field_data_comment_body', |
|---|
| 376 | 'from_fieldname' => 'comment_body_value', |
|---|
| 377 | 'join_tablename' => 'comment', |
|---|
| 378 | 'join_type' => 'INNER', |
|---|
| 379 | 'join_expression' => 'ON field_data_comment_body.entity_id = comment.cid', |
|---|
| 380 | 'to_type' => 'reply', |
|---|
| 381 | 'to_fieldname' => 'post_content', |
|---|
| 382 | 'callback_method' => 'callback_html' |
|---|
| 383 | ); |
|---|
| 384 | |
|---|
| 385 | // Reply parent topic id (If no parent, then 0) |
|---|
| 386 | $this->field_map[] = array( |
|---|
| 387 | 'from_tablename' => 'comment', |
|---|
| 388 | 'from_fieldname' => 'nid', |
|---|
| 389 | 'to_type' => 'reply', |
|---|
| 390 | 'to_fieldname' => 'post_parent', |
|---|
| 391 | 'callback_method' => 'callback_topicid' |
|---|
| 392 | ); |
|---|
| 393 | |
|---|
| 394 | // Reply dates. |
|---|
| 395 | $this->field_map[] = array( |
|---|
| 396 | 'from_tablename' => 'comment', |
|---|
| 397 | 'from_fieldname' => 'created', |
|---|
| 398 | 'to_type' => 'reply', |
|---|
| 399 | 'to_fieldname' => 'post_date', |
|---|
| 400 | 'callback_method' => 'callback_datetime' |
|---|
| 401 | ); |
|---|
| 402 | $this->field_map[] = array( |
|---|
| 403 | 'from_tablename' => 'comment', |
|---|
| 404 | 'from_fieldname' => 'created', |
|---|
| 405 | 'to_type' => 'reply', |
|---|
| 406 | 'to_fieldname' => 'post_date_gmt', |
|---|
| 407 | 'callback_method' => 'callback_datetime' |
|---|
| 408 | ); |
|---|
| 409 | $this->field_map[] = array( |
|---|
| 410 | 'from_tablename' => 'comment', |
|---|
| 411 | 'from_fieldname' => 'changed', |
|---|
| 412 | 'to_type' => 'reply', |
|---|
| 413 | 'to_fieldname' => 'post_modified', |
|---|
| 414 | 'callback_method' => 'callback_datetime' |
|---|
| 415 | ); |
|---|
| 416 | $this->field_map[] = array( |
|---|
| 417 | 'from_tablename' => 'comment', |
|---|
| 418 | 'from_fieldname' => 'changed', |
|---|
| 419 | 'to_type' => 'reply', |
|---|
| 420 | 'to_fieldname' => 'post_modified_gmt', |
|---|
| 421 | 'callback_method' => 'callback_datetime' |
|---|
| 422 | ); |
|---|
| 423 | |
|---|
| 424 | /** User Section ******************************************************/ |
|---|
| 425 | |
|---|
| 426 | // Store old User id (Stored in usermeta) |
|---|
| 427 | $this->field_map[] = array( |
|---|
| 428 | 'from_tablename' => 'users', |
|---|
| 429 | 'from_fieldname' => 'uid', |
|---|
| 430 | 'to_type' => 'user', |
|---|
| 431 | 'to_fieldname' => '_bbp_user_id' |
|---|
| 432 | ); |
|---|
| 433 | |
|---|
| 434 | // Store old User password (Stored in usermeta serialized with salt) |
|---|
| 435 | $this->field_map[] = array( |
|---|
| 436 | 'from_tablename' => 'users', |
|---|
| 437 | 'from_fieldname' => 'pass', |
|---|
| 438 | 'to_type' => 'user', |
|---|
| 439 | 'to_fieldname' => '_bbp_password' |
|---|
| 440 | // 'callback_method' => 'callback_savepass' |
|---|
| 441 | ); |
|---|
| 442 | |
|---|
| 443 | // Store old User Salt (This is only used for the SELECT row info for the above password save) |
|---|
| 444 | $this->field_map[] = array( |
|---|
| 445 | 'from_tablename' => 'users', |
|---|
| 446 | 'from_fieldname' => 'pass', |
|---|
| 447 | 'to_type' => 'user', |
|---|
| 448 | 'to_fieldname' => '' |
|---|
| 449 | ); |
|---|
| 450 | |
|---|
| 451 | // User password verify class (Stored in usermeta for verifying password) |
|---|
| 452 | $this->field_map[] = array( |
|---|
| 453 | 'to_type' => 'users', |
|---|
| 454 | 'to_fieldname' => '_bbp_class', |
|---|
| 455 | 'default' => 'Drupal7' |
|---|
| 456 | ); |
|---|
| 457 | |
|---|
| 458 | // User name. |
|---|
| 459 | $this->field_map[] = array( |
|---|
| 460 | 'from_tablename' => 'users', |
|---|
| 461 | 'from_fieldname' => 'name', |
|---|
| 462 | 'to_type' => 'user', |
|---|
| 463 | 'to_fieldname' => 'user_login' |
|---|
| 464 | ); |
|---|
| 465 | |
|---|
| 466 | // User nice name. |
|---|
| 467 | $this->field_map[] = array( |
|---|
| 468 | 'from_tablename' => 'users', |
|---|
| 469 | 'from_fieldname' => 'name', |
|---|
| 470 | 'to_type' => 'user', |
|---|
| 471 | 'to_fieldname' => 'user_nicename' |
|---|
| 472 | ); |
|---|
| 473 | |
|---|
| 474 | // User email. |
|---|
| 475 | $this->field_map[] = array( |
|---|
| 476 | 'from_tablename' => 'users', |
|---|
| 477 | 'from_fieldname' => 'mail', |
|---|
| 478 | 'to_type' => 'user', |
|---|
| 479 | 'to_fieldname' => 'user_email' |
|---|
| 480 | ); |
|---|
| 481 | |
|---|
| 482 | // User registered. |
|---|
| 483 | $this->field_map[] = array( |
|---|
| 484 | 'from_tablename' => 'users', |
|---|
| 485 | 'from_fieldname' => 'created', |
|---|
| 486 | 'to_type' => 'user', |
|---|
| 487 | 'to_fieldname' => 'user_registered', |
|---|
| 488 | 'callback_method' => 'callback_datetime' |
|---|
| 489 | ); |
|---|
| 490 | |
|---|
| 491 | // Store Signature (Stored in usermeta) |
|---|
| 492 | $this->field_map[] = array( |
|---|
| 493 | 'from_tablename' => 'users', |
|---|
| 494 | 'from_fieldname' => 'signature', |
|---|
| 495 | 'to_fieldname' => '_bbp_drupal7_user_sig', |
|---|
| 496 | 'to_type' => 'user', |
|---|
| 497 | 'callback_method' => 'callback_html' |
|---|
| 498 | ); |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | /** |
|---|
| 502 | * This method allows us to indicates what is or is not converted for each |
|---|
| 503 | * converter. |
|---|
| 504 | */ |
|---|
| 505 | public function info() |
|---|
| 506 | { |
|---|
| 507 | return ''; |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | /** |
|---|
| 511 | * This method is to save the salt and password together. That |
|---|
| 512 | * way when we authenticate it we can get it out of the database |
|---|
| 513 | * as one value. Array values are auto sanitized by WordPress. |
|---|
| 514 | */ |
|---|
| 515 | public function callback_savepass( $field, $row ) |
|---|
| 516 | { |
|---|
| 517 | $pass_array = array( 'hash' => $field, 'salt' => $row['salt'] ); |
|---|
| 518 | return $pass_array; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | /** |
|---|
| 522 | * This method is to take the pass out of the database and compare |
|---|
| 523 | * to a pass the user has typed in. |
|---|
| 524 | */ |
|---|
| 525 | public function authenticate_pass( $password, $serialized_pass ) |
|---|
| 526 | { |
|---|
| 527 | $pass_array = unserialize( $serialized_pass ); |
|---|
| 528 | return ( $pass_array['hash'] == md5( md5( $password ). $pass_array['salt'] ) ); |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | /** |
|---|
| 532 | * Translate the post status from Drupal v7.x numeric's to WordPress's strings. |
|---|
| 533 | * |
|---|
| 534 | * @param int $status Drupal v7.x numeric topic status |
|---|
| 535 | * @return string WordPress safe |
|---|
| 536 | */ |
|---|
| 537 | public function callback_topic_status( $status = 2 ) { |
|---|
| 538 | switch ( $status ) { |
|---|
| 539 | case 1 : |
|---|
| 540 | $status = 'closed'; |
|---|
| 541 | break; |
|---|
| 542 | |
|---|
| 543 | case 2 : |
|---|
| 544 | default : |
|---|
| 545 | $status = 'publish'; |
|---|
| 546 | break; |
|---|
| 547 | } |
|---|
| 548 | return $status; |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | /** |
|---|
| 552 | * Verify the topic/reply count. |
|---|
| 553 | * |
|---|
| 554 | * @param int $count Drupal v7.x topic/reply counts |
|---|
| 555 | * @return string WordPress safe |
|---|
| 556 | */ |
|---|
| 557 | public function callback_topic_reply_count( $count = 1 ) { |
|---|
| 558 | $count = absint( (int) $count - 1 ); |
|---|
| 559 | return $count; |
|---|
| 560 | } |
|---|
| 561 | } |
|---|