Skip to content

Instantly share code, notes, and snippets.

@ntwb

ntwb/SocialEngine4.php Secret

Last active Dec 20, 2015
Embed
What would you like to do?
SocialEngine v4.x bbPress Importer
<?php
/**
* Implementation of Social Engine v4.x converter.
*
* @since bbPress (r5057)
* @link Codex Docs http://codex.bbpress.org/import-forums/socialengine
*/
class SocialEngine4 extends BBP_Converter_Base {
/**
* Main Constructor
*
* @uses SocialEngine4::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' => 'forum_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' => 'forum_forums',
'from_fieldname' => 'category_id',
'to_type' => 'forum',
'to_fieldname' => '_bbp_forum_parent_id'
);
// Forum topic count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'topic_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_topic_count'
);
// Forum reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'post_count',
'to_type' => 'forum',
'to_fieldname' => '_bbp_reply_count'
);
// Forum title.
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'title',
'to_type' => 'forum',
'to_fieldname' => 'post_title'
);
// Forum slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'title',
'to_type' => 'forum',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Forum display order (Starts from 1)
// $this->field_map[] = array(
// 'from_tablename' => 'forum_forums',
// 'from_fieldname' => 'order',
// 'to_type' => 'forum',
// 'to_fieldname' => 'menu_order'
// );
// Forum description.
$this->field_map[] = array(
'from_tablename' => 'forum_forums',
'from_fieldname' => 'description',
'to_type' => 'forum',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_null'
);
// Forum 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' => 'forum_topics',
'from_fieldname' => 'topic_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_topic_id'
);
// Topic reply count (Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'post_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic total reply count (Includes unpublished replies, Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'post_count',
'to_type' => 'topic',
'to_fieldname' => '_bbp_total_reply_count',
'callback_method' => 'callback_topic_reply_count'
);
// Topic parent forum id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_forumid'
);
// Topic author.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'user_id',
'to_type' => 'topic',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Topic Author ip (Stored in postmeta)
// $this->field_map[] = array(
// 'from_tablename' => 'forum_topics',
// 'from_fieldname' => 'ipaddress',
// 'join_tablename' => 'threads',
// 'join_type' => 'INNER',
// 'join_expression' => 'USING (tid) WHERE replyto = 0',
// 'to_type' => 'topic',
// 'to_fieldname' => '_bbp_author_ip'
// );
// Topic content.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'description',
'to_type' => 'topic',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Topic title.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_title'
);
// Topic slug (Clean name to avoid conflicts)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'title',
'to_type' => 'topic',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Topic parent forum id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'forum_id',
'to_type' => 'topic',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_forumid'
);
// Topic dates.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'creation_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'creation_date',
'to_type' => 'topic',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'modified_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'modified_date',
'to_type' => 'topic',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'modified_date',
'to_type' => 'topic',
'to_fieldname' => '_bbp_last_active_time',
'callback_method' => 'callback_datetime'
);
// Topic status (Open or Closed, SocialEngine v4.6.0 0=open & 1=closed)
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => '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' => 'forum_posts',
'from_fieldname' => 'post_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' => 'forum_posts',
'from_fieldname' => 'forum_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_forum_id',
'callback_method' => 'callback_topicid_to_forumid'
);
// Reply parent topic id (If no parent, then 0. Stored in postmeta)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'topic_id',
'to_type' => 'reply',
'to_fieldname' => '_bbp_topic_id',
'callback_method' => 'callback_topicid'
);
// Reply author ip (Stored in postmeta)
// $this->field_map[] = array(
// 'from_tablename' => 'forum_posts',
// 'from_fieldname' => 'user_ip_lastactive',
// 'to_type' => 'reply',
// 'to_fieldname' => '__bbp_author_ip'
// );
// Reply author.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'user_id',
'to_type' => 'reply',
'to_fieldname' => 'post_author',
'callback_method' => 'callback_userid'
);
// Reply title.
// Note: We join the 'topics' table because 'posts' table does not have topic titles.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'title',
'join_tablename' => 'forum_posts',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id)',
'to_type' => 'reply',
'to_fieldname' => 'post_title'
);
// Reply slug (Clean name to avoid conflicts)
// Note: We join the 'topics' table because 'posts' table does not have topic titles.
$this->field_map[] = array(
'from_tablename' => 'forum_topics',
'from_fieldname' => 'title',
'join_tablename' => 'forum_posts',
'join_type' => 'INNER',
'join_expression' => 'USING (topic_id)',
'to_type' => 'reply',
'to_fieldname' => 'post_name',
'callback_method' => 'callback_slug'
);
// Reply content.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'body',
'to_type' => 'reply',
'to_fieldname' => 'post_content',
'callback_method' => 'callback_html'
);
// Reply parent topic id (If no parent, then 0)
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'forum_id',
'to_type' => 'reply',
'to_fieldname' => 'post_parent',
'callback_method' => 'callback_topicid'
);
// Reply dates.
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'creation_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'creation_date',
'to_type' => 'reply',
'to_fieldname' => 'post_date_gmt',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'modified_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified',
'callback_method' => 'callback_datetime'
);
$this->field_map[] = array(
'from_tablename' => 'forum_posts',
'from_fieldname' => 'modified_date',
'to_type' => 'reply',
'to_fieldname' => 'post_modified_gmt',
'callback_method' => 'callback_datetime'
);
}
/**
* This method allows us to indicates what is or is not converted for each
* converter.
*/
public function info() {
return '';
}
/**
* This method is to save the salt and password together. That
* way when we authenticate it we can get it out of the database
* as one value. Array values are auto sanitized by WordPress.
*/
public function callback_savepass($field, $row) {
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 v4.6.0 numeric's to WordPress's strings.
*
* @param int $status SocialEngine v4.6.0 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 v4.6.0 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
You can’t perform that action at this time.