Instantly share code, notes, and snippets.
ntwb/SocialEngine3.php Secret
Created Aug 8, 2013
SocialEngine v3.x bbPress Importer
<?php | |
/** | |
* Implementation of Social Engine v3.x converter. | |
* | |
* @since bbPress (r5xxx) | |
* @link Codex Docs http://codex.bbpress.org/import-forums/socialengine | |
*/ | |
class SocialEngine3 extends BBP_Converter_Base { | |
/** | |
* Main Constructor | |
* | |
* @uses SocialEngine3::setup_globals() | |
*/ | |
function __construct() { | |
parent::__construct(); | |
$this->setup_globals(); | |
} | |
/** | |
* Sets up the field mappings | |
*/ | |
public function setup_globals() { | |
/** Forum Section ***************************************************** */ | |
// Forum id (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forums', | |
'from_fieldname' => 'forum_id', | |
'to_type' => 'forum', | |
'to_fieldname' => '_bbp_forum_id' | |
); | |
// Forum parent id (If no parent, then 0, Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forums', | |
'from_fieldname' => 'forum_forumcat_id', | |
'to_type' => 'forum', | |
'to_fieldname' => '_bbp_forum_parent_id' | |
); | |
// Forum topic count (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forums', | |
'from_fieldname' => 'forum_totaltopics', | |
'to_type' => 'forum', | |
'to_fieldname' => '_bbp_topic_count' | |
); | |
// Forum reply count (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forums', | |
'from_fieldname' => 'forum_totalreplies', | |
'to_type' => 'forum', | |
'to_fieldname' => '_bbp_reply_count' | |
); | |
// Forum title. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_languagevars', | |
'from_fieldname' => 'languagevar_value', | |
'join_tablename' => 'se_forums', | |
'join_type' => 'LEFT', | |
'join_expression' => 'on se_forums.forum_title = se_languagevars.languagevar_id', | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_title' | |
); | |
// Forum slug (Clean name to avoid conflicts) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_languagevars', | |
'from_fieldname' => 'languagevar_value', | |
'join_tablename' => 'se_forums', | |
'join_type' => 'LEFT', | |
'join_expression' => 'on se_forums.forum_title = se_languagevars.languagevar_id', | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_name', | |
'callback_method' => 'callback_slug' | |
); | |
// Forum description. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_languagevars', | |
'from_fieldname' => 'languagevar_value', | |
'join_tablename' => 'se_forums', | |
'join_type' => 'LEFT', | |
'join_expression' => 'ON se_forums.forum_desc = se_languagevars.languagevar_id', | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_content', | |
'callback_method' => 'callback_null' | |
); | |
// Forum display order (Starts from 1) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forums', | |
'from_fieldname' => 'forum_order', | |
'to_type' => 'forum', | |
'to_fieldname' => 'menu_order' | |
); | |
// Forum dates. | |
$this->field_map[] = array( | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_date', | |
'default' => date('Y-m-d H:i:s') | |
); | |
$this->field_map[] = array( | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_date_gmt', | |
'default' => date('Y-m-d H:i:s') | |
); | |
$this->field_map[] = array( | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_modified', | |
'default' => date('Y-m-d H:i:s') | |
); | |
$this->field_map[] = array( | |
'to_type' => 'forum', | |
'to_fieldname' => 'post_modified_gmt', | |
'default' => date('Y-m-d H:i:s') | |
); | |
/** Topic Section ***************************************************** */ | |
// Topic id (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_id', | |
'to_type' => 'topic', | |
'to_fieldname' => '_bbp_topic_id' | |
); | |
// Topic reply count (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_totalreplies', | |
'to_type' => 'topic', | |
'to_fieldname' => '_bbp_reply_count', | |
'callback_method' => 'callback_topic_reply_count' | |
); | |
// Topic total reply count (Includes unpublished replies, Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_totalreplies', | |
'to_type' => 'topic', | |
'to_fieldname' => '_bbp_total_reply_count', | |
'callback_method' => 'callback_topic_reply_count' | |
); | |
// Topic parent forum id (If no parent, then 0. Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_forum_id', | |
'to_type' => 'topic', | |
'to_fieldname' => '_bbp_forum_id', | |
'callback_method' => 'callback_forumid' | |
); | |
// Topic author. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_creatoruser_id', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_author', | |
'callback_method' => 'callback_userid' | |
); | |
// Topic title. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_subject', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_title' | |
); | |
// Topic slug (Clean name to avoid conflicts) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_subject', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_name', | |
'callback_method' => 'callback_slug' | |
); | |
// Topic content. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_body', | |
'join_tablename' => 'se_forumtopics', | |
'join_type' => 'INNER', | |
'join_expression' => 'ON se_forumtopics.forumtopic_excerpt = se_forumposts.forumpost_excerpt', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_content', | |
'callback_method' => 'callback_html' | |
); | |
// Topic parent forum id (If no parent, then 0) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_forum_id', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_parent', | |
'callback_method' => 'callback_forumid' | |
); | |
// Topic dates. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_date', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_date', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_date', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_date_gmt', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_date', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_modified', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_date', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_modified_gmt', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_date', | |
'to_type' => 'topic', | |
'to_fieldname' => '_bbp_last_active_time', | |
'callback_method' => 'callback_datetime' | |
); | |
// Topic status (Open or Closed, SocialEngine v3.x 0=open & 1=closed) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_closed', | |
'to_type' => 'topic', | |
'to_fieldname' => 'post_status', | |
'callback_method' => 'callback_topic_status' | |
); | |
/** Reply Section ***************************************************** */ | |
// Reply id (Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_id', | |
'to_type' => 'reply', | |
'to_fieldname' => '_bbp_post_id' | |
); | |
// Reply parent forum id (If no parent, then 0. Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_forum_id', | |
'join_tablename' => 'se_forumposts', | |
'join_type' => 'INNER', | |
'join_expression' => 'ON se_forumtopics.forumtopic_id = se_forumposts.forumpost_forumtopic_id WHERE se_forumposts.forumpost_excerpt != se_forumtopics.forumtopic_excerpt', | |
'to_type' => 'reply', | |
'to_fieldname' => '_bbp_forum_id', | |
'callback_method' => 'callback_topicid_to_forumid' | |
); | |
// Reply parent topic id (If no parent, then 0. Stored in postmeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_forumtopic_id', | |
'to_type' => 'reply', | |
'to_fieldname' => '_bbp_topic_id', | |
'callback_method' => 'callback_topicid' | |
); | |
// Reply author ip (Stored in postmeta) | |
// Reply author. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_authoruser_id', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_author', | |
'callback_method' => 'callback_userid' | |
); | |
// Reply title. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_subject', | |
'join_tablename' => 'se_forumposts', | |
'join_type' => 'INNER', | |
'join_expression' => 'ON se_forumtopics.forumtopic_id = se_forumposts.forumpost_forumtopic_id WHERE se_forumposts.forumpost_excerpt != se_forumtopics.forumtopic_excerpt', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_title' | |
); | |
// Reply slug (Clean name to avoid conflicts) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumtopics', | |
'from_fieldname' => 'forumtopic_subject', | |
'join_tablename' => 'se_forumposts', | |
'join_type' => 'INNER', | |
'join_expression' => 'ON se_forumtopics.forumtopic_id = se_forumposts.forumpost_forumtopic_id WHERE se_forumposts.forumpost_excerpt != se_forumtopics.forumtopic_excerpt', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_name', | |
'callback_method' => 'callback_slug' | |
); | |
// Reply content. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_body', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_content', | |
'callback_method' => 'callback_html' | |
); | |
// Reply parent topic id (If no parent, then 0) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_forumtopic_id', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_parent', | |
'callback_method' => 'callback_topicid' | |
); | |
// Reply dates. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_date', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_date', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_date', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_date_gmt', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_date', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_modified', | |
'callback_method' => 'callback_datetime' | |
); | |
$this->field_map[] = array( | |
'from_tablename' => 'se_forumposts', | |
'from_fieldname' => 'forumpost_date', | |
'to_type' => 'reply', | |
'to_fieldname' => 'post_modified_gmt', | |
'callback_method' => 'callback_datetime' | |
); | |
/** User Section ******************************************************/ | |
// Store old User id (Stored in usermeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_id', | |
'to_type' => 'user', | |
'to_fieldname' => '_bbp_user_id' | |
); | |
// Store old User password (Stored in usermeta serialized with salt) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_password', | |
'to_type' => 'user', | |
'to_fieldname' => '_bbp_password', | |
'callback_method' => 'callback_savepass' | |
); | |
// Store old User Salt (This is only used for the SELECT row info for the above password save) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_code', | |
'to_type' => 'user', | |
'to_fieldname' => '' | |
); | |
// User password verify class (Stored in usermeta for verifying password) | |
$this->field_map[] = array( | |
'to_type' => 'se_users', | |
'to_fieldname' => '_bbp_class', | |
'default' => 'SocialEngine3' | |
); | |
// User name. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_username', | |
'to_type' => 'user', | |
'to_fieldname' => 'user_login' | |
); | |
// User nice name. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_username', | |
'to_type' => 'user', | |
'to_fieldname' => 'user_nicename' | |
); | |
// User email. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_email', | |
'to_type' => 'user', | |
'to_fieldname' => 'user_email' | |
); | |
// User registered. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_signupdate', | |
'to_type' => 'user', | |
'to_fieldname' => 'user_registered', | |
'callback_method' => 'callback_datetime' | |
); | |
// User display name. | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_displayname', | |
'to_type' => 'user', | |
'to_fieldname' => 'display_name' | |
); | |
// User first name (Stored in usermeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_fname', | |
'to_type' => 'user', | |
'to_fieldname' => 'first_name' | |
); | |
// User last name (Stored in usermeta) | |
$this->field_map[] = array( | |
'from_tablename' => 'se_users', | |
'from_fieldname' => 'user_lname', | |
'to_type' => 'user', | |
'to_fieldname' => 'last_name' | |
); | |
} | |
/** | |
* This method allows us to indicates what is or is not converted for each | |
* converter. | |
*/ | |
public function info() { | |
return ''; | |
} | |
/** | |
* This method is to save the salt and password together. That | |
* way when we authenticate it we can get it out of the database | |
* as one value. Array values are auto sanitized by WordPress. | |
*/ | |
public function callback_savepass($field, $row) { | |
return false; | |
} | |
/** | |
* This method is to take the pass out of the database and compare | |
* to a pass the user has typed in. | |
*/ | |
public function authenticate_pass($password, $serialized_pass) { | |
return false; | |
} | |
/** | |
* Translate the post status from SocialEngine v3.x numeric's to WordPress's strings. | |
* | |
* @param int $status SocialEngine v3.x numeric topic status | |
* @return string WordPress safe | |
*/ | |
public function callback_topic_status( $status = 0 ) { | |
switch ( $status ) { | |
case 1 : | |
$status = 'closed'; | |
break; | |
case 0 : | |
default : | |
$status = 'publish'; | |
break; | |
} | |
return $status; | |
} | |
/** | |
* Verify the topic/reply count. | |
* | |
* @param int $count SocialEngine v3.x topic/reply counts | |
* @return string WordPress safe | |
*/ | |
public function callback_topic_reply_count( $count = 1 ) { | |
$count = absint( (int) $count - 1 ); | |
return $count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment