| @@ -1,315 +1,471 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Implementation of Invision Power Board converter. | |
| 4 | + * bbPress Invision Converter | |
| 5 | + * | |
| 6 | + * @package bbPress | |
| 7 | + * @subpackage Converters | |
| 5 | 8 | */ |
| 6 | -class Invision extends BBP_Converter_Base | |
| 7 | -{ | |
| 8 | - function __construct() | |
| 9 | - { | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Implementation of Invision Power Board v3.x converter. | |
| 12 | + * | |
| 13 | + * @since 2.3.0 bbPress (r4713) | |
| 14 | + * | |
| 15 | + * @link Codex Docs https://codex.bbpress.org/import-forums/invision | |
| 16 | + */ | |
| 17 | +class Invision extends BBP_Converter_Base { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * Main Constructor | |
| 21 | + * | |
| 22 | + */ | |
| 23 | + public function __construct() { | |
| 10 | 24 | parent::__construct(); |
| 11 | - $this->setup_globals(); | |
| 12 | 25 | } |
| 13 | 26 | |
| 14 | - public function setup_globals() | |
| 15 | - { | |
| 16 | - /** Forum Section ******************************************************/ | |
| 27 | + /** | |
| 28 | + * Sets up the field mappings | |
| 29 | + */ | |
| 30 | + public function setup_globals() { | |
| 17 | 31 | |
| 18 | - // Forum id. Stored in postmeta. | |
| 32 | + // Setup smiley URL & path | |
| 33 | + $this->bbcode_parser_properties = array( | |
| 34 | + 'smiley_url' => false, | |
| 35 | + 'smiley_dir' => false | |
| 36 | + ); | |
| 37 | + | |
| 38 | + /** Forum Section *****************************************************/ | |
| 39 | + | |
| 40 | + // Old forum id (Stored in postmeta) | |
| 19 | 41 | $this->field_map[] = array( |
| 20 | - 'from_tablename' => 'forums', 'from_fieldname' => 'id', | |
| 21 | - 'to_type' => 'forum', 'to_fieldname' => '_bbp_forum_id' | |
| 42 | + 'from_tablename' => 'forums', | |
| 43 | + 'from_fieldname' => 'id', | |
| 44 | + 'to_type' => 'forum', | |
| 45 | + 'to_fieldname' => '_bbp_old_forum_id' | |
| 22 | 46 | ); |
| 23 | - | |
| 24 | - // Forum parent id. If no parent, than 0. Stored in postmeta. | |
| 47 | + | |
| 48 | + // Forum parent id (If no parent, then 0, Stored in postmeta) | |
| 25 | 49 | $this->field_map[] = array( |
| 26 | - 'from_tablename' => 'forums', 'from_fieldname' => 'parent_id', | |
| 27 | - 'to_type' => 'forum', 'to_fieldname' => '_bbp_parent_id' | |
| 50 | + 'from_tablename' => 'forums', | |
| 51 | + 'from_fieldname' => 'parent_id', | |
| 52 | + 'to_type' => 'forum', | |
| 53 | + 'to_fieldname' => '_bbp_old_forum_parent_id' | |
| 28 | 54 | ); |
| 29 | - | |
| 55 | + | |
| 56 | + // Forum topic count (Stored in postmeta) | |
| 57 | + $this->field_map[] = array( | |
| 58 | + 'from_tablename' => 'forums', | |
| 59 | + 'from_fieldname' => 'topics', | |
| 60 | + 'to_type' => 'forum', | |
| 61 | + 'to_fieldname' => '_bbp_topic_count' | |
| 62 | + ); | |
| 63 | + | |
| 64 | + // Forum reply count (Stored in postmeta) | |
| 65 | + $this->field_map[] = array( | |
| 66 | + 'from_tablename' => 'forums', | |
| 67 | + 'from_fieldname' => 'posts', | |
| 68 | + 'to_type' => 'forum', | |
| 69 | + 'to_fieldname' => '_bbp_reply_count' | |
| 70 | + ); | |
| 71 | + | |
| 72 | + // Forum total topic count (Stored in postmeta) | |
| 73 | + $this->field_map[] = array( | |
| 74 | + 'from_tablename' => 'forums', | |
| 75 | + 'from_fieldname' => 'topics', | |
| 76 | + 'to_type' => 'forum', | |
| 77 | + 'to_fieldname' => '_bbp_total_topic_count' | |
| 78 | + ); | |
| 79 | + | |
| 80 | + // Forum total reply count (Stored in postmeta) | |
| 81 | + $this->field_map[] = array( | |
| 82 | + 'from_tablename' => 'forums', | |
| 83 | + 'from_fieldname' => 'posts', | |
| 84 | + 'to_type' => 'forum', | |
| 85 | + 'to_fieldname' => '_bbp_total_reply_count' | |
| 86 | + ); | |
| 87 | + | |
| 30 | 88 | // Forum title. |
| 31 | 89 | $this->field_map[] = array( |
| 32 | - 'from_tablename' => 'forums', 'from_fieldname' => 'name', | |
| 33 | - 'to_type' => 'forum', 'to_fieldname' => 'post_title' | |
| 90 | + 'from_tablename' => 'forums', | |
| 91 | + 'from_fieldname' => 'name', | |
| 92 | + 'to_type' => 'forum', | |
| 93 | + 'to_fieldname' => 'post_title' | |
| 34 | 94 | ); |
| 35 | - | |
| 36 | - // Forum slug. Clean name. | |
| 95 | + | |
| 96 | + // Forum slug (Clean name to avoid confilcts) | |
| 37 | 97 | $this->field_map[] = array( |
| 38 | - 'from_tablename' => 'forums', 'from_fieldname' => 'name', | |
| 39 | - 'to_type' => 'forum', 'to_fieldname' => 'post_name', | |
| 98 | + 'from_tablename' => 'forums', | |
| 99 | + 'from_fieldname' => 'name_seo', | |
| 100 | + 'to_type' => 'forum', | |
| 101 | + 'to_fieldname' => 'post_name', | |
| 40 | 102 | 'callback_method' => 'callback_slug' |
| 41 | 103 | ); |
| 42 | - | |
| 104 | + | |
| 43 | 105 | // Forum description. |
| 44 | 106 | $this->field_map[] = array( |
| 45 | - 'from_tablename' => 'forums', 'from_fieldname' => 'description', | |
| 46 | - 'to_type' => 'forum', 'to_fieldname' => 'post_content', | |
| 107 | + 'from_tablename' => 'forums', | |
| 108 | + 'from_fieldname' => 'description', | |
| 109 | + 'to_type' => 'forum', | |
| 110 | + 'to_fieldname' => 'post_content', | |
| 47 | 111 | 'callback_method' => 'callback_null' |
| 48 | 112 | ); |
| 49 | - | |
| 50 | - // Forum display order. Starts from 1. | |
| 113 | + | |
| 114 | + // Forum display order (Starts from 1) | |
| 51 | 115 | $this->field_map[] = array( |
| 52 | - 'from_tablename' => 'forums', 'from_fieldname' => 'position', | |
| 53 | - 'to_type' => 'forum', 'to_fieldname' => 'menu_order' | |
| 116 | + 'from_tablename' => 'forums', | |
| 117 | + 'from_fieldname' => 'position', | |
| 118 | + 'to_type' => 'forum', | |
| 119 | + 'to_fieldname' => 'menu_order' | |
| 54 | 120 | ); |
| 55 | - | |
| 56 | - // Forum date update. | |
| 121 | + | |
| 122 | + // Forum type (Forum = 0 or Category = -1, Stored in postmeta) | |
| 57 | 123 | $this->field_map[] = array( |
| 58 | - 'to_type' => 'forum', 'to_fieldname' => 'post_date', | |
| 59 | - 'default' => date('Y-m-d H:i:s') | |
| 124 | + 'from_tablename' => 'forums', | |
| 125 | + 'from_fieldname' => 'parent_id', | |
| 126 | + 'to_type' => 'forum', | |
| 127 | + 'to_fieldname' => '_bbp_forum_type', | |
| 128 | + 'callback_method' => 'callback_forum_type' | |
| 60 | 129 | ); |
| 130 | + | |
| 131 | + // Forum status (Set a default value 'open', Stored in postmeta) | |
| 61 | 132 | $this->field_map[] = array( |
| 62 | - 'to_type' => 'forum', 'to_fieldname' => 'post_date_gmt', | |
| 63 | - 'default' => date('Y-m-d H:i:s') | |
| 133 | + 'to_type' => 'forum', | |
| 134 | + 'to_fieldname' => '_bbp_status', | |
| 135 | + 'default' => 'open' | |
| 64 | 136 | ); |
| 137 | + | |
| 138 | + // Forum dates. | |
| 65 | 139 | $this->field_map[] = array( |
| 66 | - 'to_type' => 'forum', 'to_fieldname' => 'post_modified', | |
| 67 | - 'default' => date('Y-m-d H:i:s') | |
| 140 | + 'to_type' => 'forum', | |
| 141 | + 'to_fieldname' => 'post_date', | |
| 142 | + 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 68 | 143 | ); |
| 69 | 144 | $this->field_map[] = array( |
| 70 | - 'to_type' => 'forum', 'to_fieldname' => 'post_modified_gmt', | |
| 71 | - 'default' => date('Y-m-d H:i:s') | |
| 145 | + 'to_type' => 'forum', | |
| 146 | + 'to_fieldname' => 'post_date_gmt', | |
| 147 | + 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 72 | 148 | ); |
| 149 | + $this->field_map[] = array( | |
| 150 | + 'to_type' => 'forum', | |
| 151 | + 'to_fieldname' => 'post_modified', | |
| 152 | + 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 153 | + ); | |
| 154 | + $this->field_map[] = array( | |
| 155 | + 'to_type' => 'forum', | |
| 156 | + 'to_fieldname' => 'post_modified_gmt', | |
| 157 | + 'default' => date( 'Y-m-d H:i:s' ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 158 | + ); | |
| 73 | 159 | |
| 74 | - /** Topic Section ******************************************************/ | |
| 160 | + /** Topic Section *****************************************************/ | |
| 75 | 161 | |
| 76 | - // Topic id. Stored in postmeta. | |
| 162 | + // Old topic id (Stored in postmeta) | |
| 77 | 163 | $this->field_map[] = array( |
| 78 | - 'from_tablename' => 'topics', 'from_fieldname' => 'tid', | |
| 79 | - 'to_type' => 'topic', 'to_fieldname' => '_bbp_topic_id' | |
| 164 | + 'from_tablename' => 'topics', | |
| 165 | + 'from_fieldname' => 'tid', | |
| 166 | + 'to_type' => 'topic', | |
| 167 | + 'to_fieldname' => '_bbp_old_topic_id' | |
| 80 | 168 | ); |
| 81 | - | |
| 82 | - // Forum id. Stored in postmeta. | |
| 169 | + | |
| 170 | + // Topic reply count (Stored in postmeta) | |
| 83 | 171 | $this->field_map[] = array( |
| 84 | - 'from_tablename' => 'topics', 'from_fieldname' => 'forum_id', | |
| 85 | - 'to_type' => 'topic', 'to_fieldname' => '_bbp_forum_id', | |
| 172 | + 'from_tablename' => 'topics', | |
| 173 | + 'from_fieldname' => 'posts', | |
| 174 | + 'to_type' => 'topic', | |
| 175 | + 'to_fieldname' => '_bbp_reply_count', | |
| 176 | + 'callback_method' => 'callback_topic_reply_count' | |
| 177 | + ); | |
| 178 | + | |
| 179 | + // Topic parent forum id (If no parent, then 0. Stored in postmeta) | |
| 180 | + $this->field_map[] = array( | |
| 181 | + 'from_tablename' => 'topics', | |
| 182 | + 'from_fieldname' => 'forum_id', | |
| 183 | + 'to_type' => 'topic', | |
| 184 | + 'to_fieldname' => '_bbp_forum_id', | |
| 86 | 185 | 'callback_method' => 'callback_forumid' |
| 87 | 186 | ); |
| 88 | - | |
| 187 | + | |
| 89 | 188 | // Topic author. |
| 90 | 189 | $this->field_map[] = array( |
| 91 | - 'from_tablename' => 'topics', 'from_fieldname' => 'starter_id', | |
| 92 | - 'to_type' => 'topic', 'to_fieldname' => 'post_author', | |
| 190 | + 'from_tablename' => 'topics', | |
| 191 | + 'from_fieldname' => 'starter_id', | |
| 192 | + 'to_type' => 'topic', | |
| 193 | + 'to_fieldname' => 'post_author', | |
| 93 | 194 | 'callback_method' => 'callback_userid' |
| 94 | 195 | ); |
| 95 | - | |
| 196 | + | |
| 96 | 197 | // Topic content. |
| 198 | + // Note: We join the posts table because topics do not have content. | |
| 97 | 199 | $this->field_map[] = array( |
| 98 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post', | |
| 99 | - 'join_tablename' => 'topics', 'join_type' => 'INNER', 'join_expression' => 'ON(topics.tid = posts.topic_id) WHERE posts.new_topic = 1', | |
| 100 | - 'to_type' => 'topic', 'to_fieldname' => 'post_content', | |
| 200 | + 'from_tablename' => 'posts', | |
| 201 | + 'from_fieldname' => 'post', | |
| 202 | + 'join_tablename' => 'topics', | |
| 203 | + 'join_type' => 'INNER', | |
| 204 | + 'join_expression' => 'ON(topics.tid = posts.topic_id) WHERE posts.new_topic = 1', | |
| 205 | + 'to_type' => 'topic', | |
| 206 | + 'to_fieldname' => 'post_content', | |
| 101 | 207 | 'callback_method' => 'callback_html' |
| 102 | - ); | |
| 103 | - | |
| 208 | + ); | |
| 209 | + | |
| 104 | 210 | // Topic title. |
| 105 | 211 | $this->field_map[] = array( |
| 106 | - 'from_tablename' => 'topics', 'from_fieldname' => 'title', | |
| 107 | - 'to_type' => 'topic', 'to_fieldname' => 'post_title' | |
| 212 | + 'from_tablename' => 'topics', | |
| 213 | + 'from_fieldname' => 'title', | |
| 214 | + 'to_type' => 'topic', | |
| 215 | + 'to_fieldname' => 'post_title' | |
| 108 | 216 | ); |
| 109 | - | |
| 110 | - // Topic slug. Clean name. | |
| 217 | + | |
| 218 | + // Topic slug (Clean name to avoid conflicts) | |
| 111 | 219 | $this->field_map[] = array( |
| 112 | - 'from_tablename' => 'topics', 'from_fieldname' => 'title', | |
| 113 | - 'to_type' => 'topic', 'to_fieldname' => 'post_name', | |
| 220 | + 'from_tablename' => 'topics', | |
| 221 | + 'from_fieldname' => 'title', | |
| 222 | + 'to_type' => 'topic', | |
| 223 | + 'to_fieldname' => 'post_name', | |
| 114 | 224 | 'callback_method' => 'callback_slug' |
| 115 | 225 | ); |
| 116 | - | |
| 117 | - // Forum id. If no parent, than 0. | |
| 226 | + | |
| 227 | + // Topic parent forum id (If no parent, then 0) | |
| 118 | 228 | $this->field_map[] = array( |
| 119 | - 'from_tablename' => 'topics', 'from_fieldname' => 'forum_id', | |
| 120 | - 'to_type' => 'topic', 'to_fieldname' => 'post_parent', | |
| 229 | + 'from_tablename' => 'topics', | |
| 230 | + 'from_fieldname' => 'forum_id', | |
| 231 | + 'to_type' => 'topic', | |
| 232 | + 'to_fieldname' => 'post_parent', | |
| 121 | 233 | 'callback_method' => 'callback_forumid' |
| 122 | 234 | ); |
| 123 | 235 | |
| 124 | - // Topic date update. | |
| 236 | + // Sticky status (Stored in postmeta) | |
| 125 | 237 | $this->field_map[] = array( |
| 126 | - 'from_tablename' => 'topics', 'from_fieldname' => 'start_date', | |
| 127 | - 'to_type' => 'topic', 'to_fieldname' => 'post_date', | |
| 238 | + 'from_tablename' => 'topics', | |
| 239 | + 'from_fieldname' => 'pinned', | |
| 240 | + 'to_type' => 'topic', | |
| 241 | + 'to_fieldname' => '_bbp_old_sticky_status_id', | |
| 242 | + 'callback_method' => 'callback_sticky_status' | |
| 243 | + ); | |
| 244 | + | |
| 245 | + // Topic dates. | |
| 246 | + $this->field_map[] = array( | |
| 247 | + 'from_tablename' => 'topics', | |
| 248 | + 'from_fieldname' => 'start_date', | |
| 249 | + 'to_type' => 'topic', | |
| 250 | + 'to_fieldname' => 'post_date', | |
| 128 | 251 | 'callback_method' => 'callback_datetime' |
| 129 | 252 | ); |
| 130 | 253 | $this->field_map[] = array( |
| 131 | - 'from_tablename' => 'topics', 'from_fieldname' => 'start_date', | |
| 132 | - 'to_type' => 'topic', 'to_fieldname' => 'post_date_gmt', | |
| 254 | + 'from_tablename' => 'topics', | |
| 255 | + 'from_fieldname' => 'start_date', | |
| 256 | + 'to_type' => 'topic', | |
| 257 | + 'to_fieldname' => 'post_date_gmt', | |
| 133 | 258 | 'callback_method' => 'callback_datetime' |
| 134 | 259 | ); |
| 135 | 260 | $this->field_map[] = array( |
| 136 | - 'from_tablename' => 'topics', 'from_fieldname' => 'last_post', | |
| 137 | - 'to_type' => 'topic', 'to_fieldname' => 'post_modified', | |
| 261 | + 'from_tablename' => 'topics', | |
| 262 | + 'from_fieldname' => 'last_post', | |
| 263 | + 'to_type' => 'topic', | |
| 264 | + 'to_fieldname' => 'post_modified', | |
| 138 | 265 | 'callback_method' => 'callback_datetime' |
| 139 | 266 | ); |
| 140 | 267 | $this->field_map[] = array( |
| 141 | - 'from_tablename' => 'topics', 'from_fieldname' => 'last_post', | |
| 142 | - 'to_type' => 'topic', 'to_fieldname' => 'post_modified_gmt', | |
| 268 | + 'from_tablename' => 'topics', | |
| 269 | + 'from_fieldname' => 'last_post', | |
| 270 | + 'to_type' => 'topic', | |
| 271 | + 'to_fieldname' => 'post_modified_gmt', | |
| 143 | 272 | 'callback_method' => 'callback_datetime' |
| 144 | 273 | ); |
| 274 | + $this->field_map[] = array( | |
| 275 | + 'from_tablename' => 'topics', | |
| 276 | + 'from_fieldname' => 'last_post', | |
| 277 | + 'to_type' => 'topic', | |
| 278 | + 'to_fieldname' => '_bbp_last_active_time', | |
| 279 | + 'callback_method' => 'callback_datetime' | |
| 280 | + ); | |
| 145 | 281 | |
| 146 | 282 | /** Tags Section ******************************************************/ |
| 147 | - | |
| 283 | + | |
| 148 | 284 | // Topic id. |
| 149 | 285 | $this->field_map[] = array( |
| 150 | - 'from_tablename' => 'core_tags', 'from_fieldname' => 'tag_meta_id', | |
| 151 | - 'to_type' => 'tags', 'to_fieldname' => 'objectid', | |
| 286 | + 'from_tablename' => 'core_tags', | |
| 287 | + 'from_fieldname' => 'tag_meta_id', | |
| 288 | + 'to_type' => 'tags', | |
| 289 | + 'to_fieldname' => 'objectid', | |
| 152 | 290 | 'callback_method' => 'callback_topicid' |
| 153 | 291 | ); |
| 154 | - | |
| 155 | - // Tags text. | |
| 292 | + | |
| 293 | + // Term text. | |
| 156 | 294 | $this->field_map[] = array( |
| 157 | - 'from_tablename' => 'core_tags', 'from_fieldname' => 'tag_text', | |
| 158 | - 'to_type' => 'tags', 'to_fieldname' => 'name' | |
| 159 | - ); | |
| 160 | - | |
| 161 | - /** Post Section ******************************************************/ | |
| 295 | + 'from_tablename' => 'core_tags', | |
| 296 | + 'from_fieldname' => 'tag_text', | |
| 297 | + 'to_type' => 'tags', | |
| 298 | + 'to_fieldname' => 'name' | |
| 299 | + ); | |
| 162 | 300 | |
| 163 | - // Post id. Stores in postmeta. | |
| 301 | + /** Reply Section *****************************************************/ | |
| 302 | + | |
| 303 | + // Old reply id (Stored in postmeta) | |
| 164 | 304 | $this->field_map[] = array( |
| 165 | - 'from_tablename' => 'posts', 'from_fieldname' => 'pid', 'from_expression' => 'WHERE posts.new_topic = 0', | |
| 166 | - 'to_type' => 'reply', 'to_fieldname' => '_bbp_post_id' | |
| 305 | + 'from_tablename' => 'posts', | |
| 306 | + 'from_fieldname' => 'pid', | |
| 307 | + 'to_type' => 'reply', | |
| 308 | + 'to_fieldname' => '_bbp_old_reply_id' | |
| 167 | 309 | ); |
| 168 | - | |
| 169 | - // Forum id. Stores in postmeta. | |
| 310 | + | |
| 311 | + // Reply parent forum id (If no parent, then 0. Stored in postmeta) | |
| 170 | 312 | $this->field_map[] = array( |
| 171 | - 'from_tablename' => 'posts', 'from_fieldname' => 'topic_id', | |
| 172 | - 'to_type' => 'reply', 'to_fieldname' => '_bbp_forum_id', | |
| 313 | + 'from_tablename' => 'posts', | |
| 314 | + 'from_fieldname' => 'topic_id', | |
| 315 | + 'to_type' => 'reply', | |
| 316 | + 'to_fieldname' => '_bbp_forum_id', | |
| 173 | 317 | 'callback_method' => 'callback_topicid_to_forumid' |
| 174 | 318 | ); |
| 175 | - | |
| 176 | - // Topic id. Stores in postmeta. | |
| 319 | + | |
| 320 | + // Reply parent topic id (If no parent, then 0. Stored in postmeta) | |
| 177 | 321 | $this->field_map[] = array( |
| 178 | - 'from_tablename' => 'posts', 'from_fieldname' => 'topic_id', | |
| 179 | - 'to_type' => 'reply', 'to_fieldname' => '_bbp_topic_id', | |
| 322 | + 'from_tablename' => 'posts', | |
| 323 | + 'from_fieldname' => 'topic_id', | |
| 324 | + 'to_type' => 'reply', | |
| 325 | + 'to_fieldname' => '_bbp_topic_id', | |
| 180 | 326 | 'callback_method' => 'callback_topicid' |
| 181 | 327 | ); |
| 182 | - | |
| 183 | - // Author ip. | |
| 328 | + | |
| 329 | + // Reply author ip (Stored in postmeta) | |
| 184 | 330 | $this->field_map[] = array( |
| 185 | - 'from_tablename' => 'posts', 'from_fieldname' => 'ip_address', | |
| 186 | - 'to_type' => 'reply', 'to_fieldname' => '__bbp_author_ip' | |
| 187 | - ); | |
| 188 | - | |
| 189 | - // Post author. | |
| 331 | + 'from_tablename' => 'posts', | |
| 332 | + 'from_fieldname' => 'ip_address', | |
| 333 | + 'to_type' => 'reply', | |
| 334 | + 'to_fieldname' => '_bbp_author_ip' | |
| 335 | + ); | |
| 336 | + | |
| 337 | + // Reply author. | |
| 190 | 338 | $this->field_map[] = array( |
| 191 | - 'from_tablename' => 'posts', 'from_fieldname' => 'author_id', | |
| 192 | - 'to_type' => 'reply', 'to_fieldname' => 'post_author', | |
| 339 | + 'from_tablename' => 'posts', | |
| 340 | + 'from_fieldname' => 'author_id', | |
| 341 | + 'to_type' => 'reply', | |
| 342 | + 'to_fieldname' => 'post_author', | |
| 193 | 343 | 'callback_method' => 'callback_userid' |
| 194 | 344 | ); |
| 195 | - | |
| 196 | - // Topic title. | |
| 345 | + | |
| 346 | + // Reply content. | |
| 197 | 347 | $this->field_map[] = array( |
| 198 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post_title', | |
| 199 | - 'to_type' => 'reply', 'to_fieldname' => 'post_title' | |
| 200 | - ); | |
| 201 | - | |
| 202 | - // Topic slug. Clean name. | |
| 203 | - $this->field_map[] = array( | |
| 204 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post_title', | |
| 205 | - 'to_type' => 'reply', 'to_fieldname' => 'post_name', | |
| 206 | - 'callback_method' => 'callback_slug' | |
| 207 | - ); | |
| 208 | - | |
| 209 | - // Post content. | |
| 210 | - $this->field_map[] = array( | |
| 211 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post', | |
| 212 | - 'to_type' => 'reply', 'to_fieldname' => 'post_content', | |
| 348 | + 'from_tablename' => 'posts', | |
| 349 | + 'from_fieldname' => 'post', | |
| 350 | + 'to_type' => 'reply', | |
| 351 | + 'to_fieldname' => 'post_content', | |
| 213 | 352 | 'callback_method' => 'callback_html' |
| 214 | 353 | ); |
| 215 | - | |
| 216 | - // Topic id. If no parent, than 0. | |
| 354 | + | |
| 355 | + // Reply parent topic id (If no parent, then 0) | |
| 217 | 356 | $this->field_map[] = array( |
| 218 | - 'from_tablename' => 'posts', 'from_fieldname' => 'topic_id', | |
| 219 | - 'to_type' => 'reply', 'to_fieldname' => 'post_parent', | |
| 357 | + 'from_tablename' => 'posts', | |
| 358 | + 'from_fieldname' => 'topic_id', | |
| 359 | + 'to_type' => 'reply', | |
| 360 | + 'to_fieldname' => 'post_parent', | |
| 220 | 361 | 'callback_method' => 'callback_topicid' |
| 221 | 362 | ); |
| 222 | 363 | |
| 223 | - // Topic date update. | |
| 364 | + // Reply dates. | |
| 224 | 365 | $this->field_map[] = array( |
| 225 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post_date', | |
| 226 | - 'to_type' => 'reply', 'to_fieldname' => 'post_date', | |
| 366 | + 'from_tablename' => 'posts', | |
| 367 | + 'from_fieldname' => 'post_date', | |
| 368 | + 'to_type' => 'reply', | |
| 369 | + 'to_fieldname' => 'post_date', | |
| 227 | 370 | 'callback_method' => 'callback_datetime' |
| 228 | 371 | ); |
| 229 | 372 | $this->field_map[] = array( |
| 230 | - 'from_tablename' => 'posts', 'from_fieldname' => 'post_date', | |
| 231 | - 'to_type' => 'reply', 'to_fieldname' => 'post_date_gmt', | |
| 373 | + 'from_tablename' => 'posts', | |
| 374 | + 'from_fieldname' => 'post_date', | |
| 375 | + 'to_type' => 'reply', | |
| 376 | + 'to_fieldname' => 'post_date_gmt', | |
| 232 | 377 | 'callback_method' => 'callback_datetime' |
| 233 | 378 | ); |
| 234 | 379 | $this->field_map[] = array( |
| 235 | - 'from_tablename' => 'posts', 'from_fieldname' => 'edit_time', | |
| 236 | - 'to_type' => 'reply', 'to_fieldname' => 'post_modified', | |
| 380 | + 'from_tablename' => 'posts', | |
| 381 | + 'from_fieldname' => 'edit_time', | |
| 382 | + 'to_type' => 'reply', | |
| 383 | + 'to_fieldname' => 'post_modified', | |
| 237 | 384 | 'callback_method' => 'callback_datetime' |
| 238 | 385 | ); |
| 239 | 386 | $this->field_map[] = array( |
| 240 | - 'from_tablename' => 'posts', 'from_fieldname' => 'edit_time', | |
| 241 | - 'to_type' => 'reply', 'to_fieldname' => 'post_modified_gmt', | |
| 387 | + 'from_tablename' => 'posts', | |
| 388 | + 'from_fieldname' => 'edit_time', | |
| 389 | + 'to_type' => 'reply', | |
| 390 | + 'to_fieldname' => 'post_modified_gmt', | |
| 242 | 391 | 'callback_method' => 'callback_datetime' |
| 243 | 392 | ); |
| 244 | 393 | |
| 245 | 394 | /** User Section ******************************************************/ |
| 246 | 395 | |
| 247 | - // Store old User id. Stores in usermeta. | |
| 396 | + // Store old user id (Stored in usermeta) | |
| 248 | 397 | $this->field_map[] = array( |
| 249 | - 'from_tablename' => 'members', 'from_fieldname' => 'member_id', | |
| 250 | - 'to_type' => 'user', 'to_fieldname' => '_bbp_user_id' | |
| 398 | + 'from_tablename' => 'members', | |
| 399 | + 'from_fieldname' => 'member_id', | |
| 400 | + 'to_type' => 'user', | |
| 401 | + 'to_fieldname' => '_bbp_old_user_id' | |
| 251 | 402 | ); |
| 252 | - | |
| 253 | - // Store old User password. Stores in usermeta serialized with salt. | |
| 403 | + | |
| 404 | + // Store old user password (Stored in usermeta serialized with salt) | |
| 254 | 405 | $this->field_map[] = array( |
| 255 | - 'from_tablename' => 'members', 'from_fieldname' => 'members_pass_hash', | |
| 256 | - 'to_type' => 'user', 'to_fieldname' => '_bbp_password', | |
| 406 | + 'from_tablename' => 'members', | |
| 407 | + 'from_fieldname' => 'members_pass_hash', | |
| 408 | + 'to_type' => 'user', | |
| 409 | + 'to_fieldname' => '_bbp_password', | |
| 257 | 410 | 'callback_method' => 'callback_savepass' |
| 258 | 411 | ); |
| 259 | 412 | |
| 260 | - // Store old User Salt. This is only used for the SELECT row info for the above password save | |
| 413 | + // Store old user salt (This is only used for the SELECT row info for the above password save) | |
| 261 | 414 | $this->field_map[] = array( |
| 262 | - 'from_tablename' => 'members', 'from_fieldname' => 'members_pass_salt', | |
| 263 | - 'to_type' => 'user', 'to_fieldname' => '' | |
| 415 | + 'from_tablename' => 'members', | |
| 416 | + 'from_fieldname' => 'members_pass_salt', | |
| 417 | + 'to_type' => 'user', | |
| 418 | + 'to_fieldname' => '' | |
| 264 | 419 | ); |
| 265 | - | |
| 266 | - // User password verify class. Stores in usermeta for verifying password. | |
| 420 | + | |
| 421 | + // User password verify class (Stored in usermeta for verifying password) | |
| 267 | 422 | $this->field_map[] = array( |
| 268 | - 'to_type' => 'user', 'to_fieldname' => '_bbp_class', | |
| 423 | + 'to_type' => 'user', | |
| 424 | + 'to_fieldname' => '_bbp_class', | |
| 269 | 425 | 'default' => 'Invision' |
| 270 | 426 | ); |
| 271 | - | |
| 427 | + | |
| 272 | 428 | // User name. |
| 273 | 429 | $this->field_map[] = array( |
| 274 | - 'from_tablename' => 'members', 'from_fieldname' => 'name', | |
| 275 | - 'to_type' => 'user', 'to_fieldname' => 'user_login' | |
| 430 | + 'from_tablename' => 'members', | |
| 431 | + 'from_fieldname' => 'name', | |
| 432 | + 'to_type' => 'user', | |
| 433 | + 'to_fieldname' => 'user_login' | |
| 276 | 434 | ); |
| 277 | - | |
| 435 | + | |
| 436 | + // User nice name. | |
| 437 | + $this->field_map[] = array( | |
| 438 | + 'from_tablename' => 'members', | |
| 439 | + 'from_fieldname' => 'name', | |
| 440 | + 'to_type' => 'user', | |
| 441 | + 'to_fieldname' => 'user_nicename' | |
| 442 | + ); | |
| 443 | + | |
| 278 | 444 | // User email. |
| 279 | 445 | $this->field_map[] = array( |
| 280 | - 'from_tablename' => 'members', 'from_fieldname' => 'email', | |
| 281 | - 'to_type' => 'user', 'to_fieldname' => 'user_email' | |
| 446 | + 'from_tablename' => 'members', | |
| 447 | + 'from_fieldname' => 'email', | |
| 448 | + 'to_type' => 'user', | |
| 449 | + 'to_fieldname' => 'user_email' | |
| 282 | 450 | ); |
| 283 | - | |
| 451 | + | |
| 284 | 452 | // User registered. |
| 285 | 453 | $this->field_map[] = array( |
| 286 | - 'from_tablename' => 'members', 'from_fieldname' => 'joined', | |
| 287 | - 'to_type' => 'user', 'to_fieldname' => 'user_registered', | |
| 454 | + 'from_tablename' => 'members', | |
| 455 | + 'from_fieldname' => 'joined', | |
| 456 | + 'to_type' => 'user', | |
| 457 | + 'to_fieldname' => 'user_registered', | |
| 288 | 458 | 'callback_method' => 'callback_datetime' |
| 289 | 459 | ); |
| 290 | - | |
| 291 | -/* | |
| 292 | - * Table pfields_content AND pfields_data | |
| 293 | - // User homepage. | |
| 460 | + | |
| 461 | + // User display name. | |
| 294 | 462 | $this->field_map[] = array( |
| 295 | - 'from_tablename' => 'members', 'from_fieldname' => 'homepage', | |
| 296 | - 'to_type' => 'user', 'to_fieldname' => 'user_url' | |
| 297 | - ); | |
| 298 | - | |
| 299 | - // User aim. | |
| 300 | - $this->field_map[] = array( | |
| 301 | - 'from_tablename' => 'members', 'from_fieldname' => 'aim', | |
| 302 | - 'to_type' => 'user', 'to_fieldname' => 'aim' | |
| 463 | + 'from_tablename' => 'members', | |
| 464 | + 'from_fieldname' => 'members_display_name', | |
| 465 | + 'to_type' => 'user', | |
| 466 | + 'to_fieldname' => 'display_name' | |
| 303 | 467 | ); |
| 304 | - | |
| 305 | - // User yahoo. | |
| 306 | - $this->field_map[] = array( | |
| 307 | - 'from_tablename' => 'members', 'from_fieldname' => 'yahoo', | |
| 308 | - 'to_type' => 'user', 'to_fieldname' => 'yim' | |
| 309 | - ); | |
| 310 | -*/ | |
| 311 | - | |
| 312 | 468 | } |
| 313 | 469 | |
| 314 | 470 | /** |
| 315 | 471 | * This method allows us to indicates what is or is not converted for each |
| @@ -314,22 +470,68 @@ | ||
| 314 | 470 | /** |
| 315 | 471 | * This method allows us to indicates what is or is not converted for each |
| 316 | 472 | * converter. |
| 317 | 473 | */ |
| 318 | - public function info() | |
| 319 | - { | |
| 474 | + public function info() { | |
| 320 | 475 | return ''; |
| 321 | 476 | } |
| 322 | 477 | |
| 323 | 478 | /** |
| 479 | + * Translate the forum type from Invision numerics to WordPress's strings. | |
| 480 | + * | |
| 481 | + * @param int $status Invision numeric forum type | |
| 482 | + * @return string WordPress safe | |
| 483 | + */ | |
| 484 | + public function callback_forum_type( $status = 0 ) { | |
| 485 | + if ( -1 === (int) $status ) { | |
| 486 | + $status = 'category'; | |
| 487 | + } else { | |
| 488 | + $status = 'forum'; | |
| 489 | + } | |
| 490 | + return $status; | |
| 491 | + } | |
| 492 | + | |
| 493 | + /** | |
| 494 | + * Translate the topic sticky status type from Invision numerics to WordPress's strings. | |
| 495 | + * | |
| 496 | + * @param int $status Invision numeric forum type | |
| 497 | + * @return string WordPress safe | |
| 498 | + */ | |
| 499 | + public function callback_sticky_status( $status = 0 ) { | |
| 500 | + switch ( $status ) { | |
| 501 | + case 1 : | |
| 502 | + $status = 'sticky'; // Invision Pinned Topic 'pinned = 1' | |
| 503 | + break; | |
| 504 | + | |
| 505 | + case 0 : | |
| 506 | + default : | |
| 507 | + $status = 'normal'; // Invision Normal Topic 'pinned = 0' | |
| 508 | + break; | |
| 509 | + } | |
| 510 | + return $status; | |
| 511 | + } | |
| 512 | + | |
| 513 | + /** | |
| 514 | + * Verify the topic reply count. | |
| 515 | + * | |
| 516 | + * @param int $count Invision reply count | |
| 517 | + * @return string WordPress safe | |
| 518 | + */ | |
| 519 | + public function callback_topic_reply_count( $count = 1 ) { | |
| 520 | + $count = absint( (int) $count - 1 ); | |
| 521 | + return $count; | |
| 522 | + } | |
| 523 | + | |
| 524 | + /** | |
| 324 | 525 | * This method is to save the salt and password together. That |
| 325 | 526 | * way when we authenticate it we can get it out of the database |
| 326 | - * as one value. Array values are auto sanitized by wordpress. | |
| 527 | + * as one value. Array values are auto sanitized by WordPress. | |
| 327 | 528 | */ |
| 328 | - public function callback_savepass( $field, $row ) | |
| 329 | - { | |
| 330 | - $pass_array = array( 'hash' => $field, 'salt' => $row['members_pass_salt'] ); | |
| 331 | - return $pass_array; | |
| 529 | + public function callback_savepass( $field, $row ) { | |
| 530 | + return array( | |
| 531 | + 'hash' => $field, | |
| 532 | + 'salt' => $row['members_pass_salt'] | |
| 533 | + ); | |
| 332 | 534 | } |
| 333 | 535 | |
| 334 | 536 | /** |
| 335 | 537 | * This method is to take the pass out of the database and compare |
| @@ -334,30 +536,124 @@ | ||
| 334 | 536 | /** |
| 335 | 537 | * This method is to take the pass out of the database and compare |
| 336 | 538 | * to a pass the user has typed in. |
| 337 | 539 | */ |
| 338 | - public function authenticate_pass( $password, $serialized_pass ) | |
| 339 | - { | |
| 340 | - $pass_array = unserialize( $serialized_pass ); | |
| 341 | - return ( $pass_array['hash'] == md5( md5( $pass_array['salt'] ) . md5( $this->to_char( $password ) ) ) ); | |
| 540 | + public function authenticate_pass( $password, $serialized_pass ) { | |
| 541 | + | |
| 542 | + // Unserialize the password, with safeguards | |
| 543 | + $pass_array = unserialize( | |
| 544 | + $serialized_pass, | |
| 545 | + array( | |
| 546 | + 'allowed_classes' => false, | |
| 547 | + 'max_depth' => 1 | |
| 548 | + ) | |
| 549 | + ); | |
| 550 | + | |
| 551 | + // Bail if missing values | |
| 552 | + if ( ! is_array( $pass_array ) || ! isset( $pass_array['hash'], $pass_array['salt'] ) ) { | |
| 553 | + return false; | |
| 554 | + } | |
| 555 | + | |
| 556 | + // Return comparison | |
| 557 | + return hash_equals( | |
| 558 | + $pass_array['hash'], | |
| 559 | + md5( md5( $pass_array['salt'] ) . md5( $this->to_char( $password ) ) ) | |
| 560 | + ); | |
| 342 | 561 | } |
| 343 | 562 | |
| 344 | - public function to_char( $input ) | |
| 345 | - { | |
| 346 | - $output = ""; | |
| 347 | - for( $i = 0; $i < strlen( $input ); $i++ ) | |
| 348 | - { | |
| 349 | - $j = ord( $input{$i} ); | |
| 350 | - if( ( $j >= 65 && $j <= 90 ) | |
| 563 | + private function to_char( $input ) { | |
| 564 | + $output = ''; | |
| 565 | + $length = strlen( $input ); | |
| 566 | + for ( $i = 0; $i < $length; $i++ ) { | |
| 567 | + $j = ord( $input[ $i ] ); | |
| 568 | + if ( ( $j >= 65 && $j <= 90 ) | |
| 351 | 569 | || ( $j >= 97 && $j <= 122 ) |
| 352 | - || ( $j >= 48 && $j <= 57 ) ) | |
| 353 | - { | |
| 354 | - $output .= $input{$i}; | |
| 570 | + || ( $j >= 48 && $j <= 57 ) ) { | |
| 571 | + $output .= $input[ $i ]; | |
| 572 | + } else { | |
| 573 | + $output .= '&#' . ord( $input[ $i ] ) . ';'; | |
| 355 | 574 | } |
| 356 | - else | |
| 357 | - { | |
| 358 | - $output .= "&#" . ord( $input{$i} ) . ";"; | |
| 359 | - } | |
| 360 | 575 | } |
| 361 | 576 | return $output; |
| 577 | + } | |
| 578 | + | |
| 579 | + /** | |
| 580 | + * This callback processes any custom BBCodes with parser.php | |
| 581 | + */ | |
| 582 | + protected function callback_html( $field ) { | |
| 583 | + | |
| 584 | + // Strips Invision custom HTML first from $field before parsing $field to parser.php | |
| 585 | + $invision_markup = $field; | |
| 586 | + $invision_markup = html_entity_decode( $invision_markup ); | |
| 587 | + | |
| 588 | + // Replace '[html]' with '<pre><code>' | |
| 589 | + $invision_markup = preg_replace( '/\[html\]/', '<pre><code>', $invision_markup ); | |
| 590 | + // Replace '[/html]' with '</code></pre>' | |
| 591 | + $invision_markup = preg_replace( '/\[\/html\]/', '</code></pre>', $invision_markup ); | |
| 592 | + // Replace '[sql]' with '<pre><code>' | |
| 593 | + $invision_markup = preg_replace( '/\[sql\]/', '<pre><code>', $invision_markup ); | |
| 594 | + // Replace '[/sql]' with '</code></pre>' | |
| 595 | + $invision_markup = preg_replace( '/\[\/sql\]/', '</code></pre>', $invision_markup ); | |
| 596 | + // Replace '[php]' with '<pre><code>' | |
| 597 | + $invision_markup = preg_replace( '/\[php\]/', '<pre><code>', $invision_markup ); | |
| 598 | + // Replace '[/php]' with '</code></pre>' | |
| 599 | + $invision_markup = preg_replace( '/\[\/php\]/', '</code></pre>', $invision_markup ); | |
| 600 | + // Replace '[xml]' with '<pre><code>' | |
| 601 | + $invision_markup = preg_replace( '/\[xml\]/', '<pre><code>', $invision_markup ); | |
| 602 | + // Replace '[/xml]' with '</code></pre>' | |
| 603 | + $invision_markup = preg_replace( '/\[\/xml\]/', '</code></pre>', $invision_markup ); | |
| 604 | + // Replace '[CODE]' with '<pre><code>' | |
| 605 | + $invision_markup = preg_replace( '/\[CODE\]/', '<pre><code>', $invision_markup ); | |
| 606 | + // Replace '[/CODE]' with '</code></pre>' | |
| 607 | + $invision_markup = preg_replace( '/\[\/CODE\]/', '</code></pre>', $invision_markup ); | |
| 608 | + | |
| 609 | + // Replace '[quote:XXXXXXX]' with '<blockquote>' | |
| 610 | + $invision_markup = preg_replace( '/\[quote:(.*?)\]/', '<blockquote>', $invision_markup ); | |
| 611 | + // Replace '[quote="$1"]' with '<em>@$1 wrote:</em><blockquote>' | |
| 612 | + $invision_markup = preg_replace( '/\[quote="(.*?)":(.*?)\]/', '<em>@$1 wrote:</em><blockquote>', $invision_markup ); | |
| 613 | + // Replace '[/quote:XXXXXXX]' with '</blockquote>' | |
| 614 | + $invision_markup = preg_replace( '/\[\/quote:(.*?)\]/', '</blockquote>', $invision_markup ); | |
| 615 | + | |
| 616 | + // Replace '[twitter]$1[/twitter]' with '<a href="https://twitter.com/$1">@$1</a>" | |
| 617 | + $invision_markup = preg_replace( '/\[twitter\](.*?)\[\/twitter\]/', '<a href="https://twitter.com/$1">@$1</a>', $invision_markup ); | |
| 618 | + | |
| 619 | + // Replace '[member='username']' with '@username" | |
| 620 | + $invision_markup = preg_replace( '/\[member=\'(.*?)\'\]/', '@$1 ', $invision_markup ); | |
| 621 | + | |
| 622 | + // Replace '[media]' with '' | |
| 623 | + $invision_markup = preg_replace( '/\[media\]/', '', $invision_markup ); | |
| 624 | + // Replace '[/media]' with '' | |
| 625 | + $invision_markup = preg_replace( '/\[\/media\]/', '', $invision_markup ); | |
| 626 | + | |
| 627 | + // Replace '[list:XXXXXXX]' with '<ul>' | |
| 628 | + $invision_markup = preg_replace( '/\[list\]/', '<ul>', $invision_markup ); | |
| 629 | + // Replace '[list=1:XXXXXXX]' with '<ul>' | |
| 630 | + $invision_markup = preg_replace( '/\[list=1\]/', '<ul>', $invision_markup ); | |
| 631 | + // Replace '[*:XXXXXXX]' with '<li>' | |
| 632 | + $invision_markup = preg_replace( '/\[\*\](.*?)\<br \/\>/', '<li>$1</li>', $invision_markup ); | |
| 633 | + // Replace '[/list:u:XXXXXXX]' with '</ul>' | |
| 634 | + $invision_markup = preg_replace( '/\[\/list\]/', '</ul>', $invision_markup ); | |
| 635 | + | |
| 636 | + // Replace '[hr]' with '<hr>" | |
| 637 | + $invision_markup = preg_replace( '/\[hr\]/', '<hr>', $invision_markup ); | |
| 638 | + | |
| 639 | + // Replace '[font=XXXXXXX]' with '' | |
| 640 | + $invision_markup = preg_replace( '/\[font=(.*?)\]/', '', $invision_markup ); | |
| 641 | + // Replace '[/font]' with '' | |
| 642 | + $invision_markup = preg_replace( '/\[\/font\]/', '', $invision_markup ); | |
| 643 | + | |
| 644 | + // Replace any Invision smilies from path '/sp-resources/forum-smileys/sf-smily.gif' with the equivelant WordPress Smilie | |
| 645 | + $invision_markup = preg_replace( '/\<img src=(.*?)EMO\_DIR(.*?)bbc_emoticon(.*?)alt=\'(.*?)\' \/\>/', '$4', $invision_markup ); | |
| 646 | + $invision_markup = preg_replace( '/\:angry\:/', ':mad:', $invision_markup ); | |
| 647 | + $invision_markup = preg_replace( '/\:mellow\:/', ':neutral:', $invision_markup ); | |
| 648 | + $invision_markup = preg_replace( '/\:blink\:/', ':eek:', $invision_markup ); | |
| 649 | + $invision_markup = preg_replace( '/B\)/', ':cool:', $invision_markup ); | |
| 650 | + $invision_markup = preg_replace( '/\:rolleyes\:/', ':roll:', $invision_markup ); | |
| 651 | + $invision_markup = preg_replace( '/\:unsure\:/', ':???:', $invision_markup ); | |
| 652 | + | |
| 653 | + // Now that Invision custom HTML has been stripped put the cleaned HTML back in $field | |
| 654 | + $field = $invision_markup; | |
| 655 | + | |
| 656 | + // Parse out any bbCodes in $field with the BBCode 'parser.php' | |
| 657 | + return parent::callback_html( $field ); | |
| 362 | 658 | } |
| 363 | 659 | } |