-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix column length check for negative integer during an insert. * XenForo 2 Module
- Loading branch information
1 parent
3d287da
commit b3d1540
Showing
16 changed files
with
1,842 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
/** | ||
* MyBB 1.8 Merge System | ||
* Copyright 2019 MyBB Group, All Rights Reserved | ||
* | ||
* Website: http://www.mybb.com | ||
* License: http://www.mybb.com/download/merge-system/license/ | ||
*/ | ||
|
||
// Disallow direct access to this file for security reasons | ||
if(!defined("IN_MYBB")) | ||
{ | ||
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); | ||
} | ||
|
||
class XENFORO2_Converter extends Converter | ||
{ | ||
/** | ||
* String of the bulletin board name | ||
* | ||
* @var string | ||
*/ | ||
var $bbname = "Xenforo 2"; | ||
|
||
/** | ||
* String of the plain bulletin board name | ||
* | ||
* @var string | ||
*/ | ||
var $plain_bbname = "Xenforo 2"; | ||
|
||
/** | ||
* Whether or not this module requires the loginconvert.php plugin | ||
* | ||
* @var boolean | ||
*/ | ||
var $requires_loginconvert = true; | ||
|
||
/** | ||
* Array of all of the modules | ||
* | ||
* @var array | ||
*/ | ||
var $modules = array( | ||
"db_configuration" => array("name" => "Database Configuration", "dependencies" => ""), | ||
"import_settings" => array("name" => "Settings", "dependencies" => "db_configuration"), | ||
"import_usergroups" => array("name" => "Usergroups", "dependencies" => "db_configuration"), | ||
"import_users" => array("name" => "Users", "dependencies" => "db_configuration,import_usergroups"), | ||
"import_forums" => array("name" => "Forums", "dependencies" => "db_configuration,import_users"), | ||
"import_moderators" => array("name" => "Moderators", "dependencies" => "db_configuration,import_forums,import_users"), | ||
"import_threads" => array("name" => "Threads", "dependencies" => "db_configuration,import_forums"), | ||
"import_polls" => array("name" => "Polls", "dependencies" => "db_configuration,import_threads"), | ||
"import_pollvotes" => array("name" => "Poll Votes", "dependencies" => "db_configuration,import_polls"), | ||
"import_posts" => array("name" => "Posts", "dependencies" => "db_configuration,import_threads"), | ||
"import_privatemessages" => array("name" => "Private Messages", "dependencies" => "db_configuration,import_users"), | ||
"import_avatars" => array("name" => "Avatars", "dependencies" => "db_configuration,import_users"), | ||
"import_attachments" => array("name" => "Attachments", "dependencies" => "db_configuration,import_posts"), | ||
); | ||
|
||
/** | ||
* The table we check to verify it's "our" database | ||
* | ||
* @var String | ||
*/ | ||
var $check_table = "ip"; | ||
|
||
/** | ||
* The table prefix we suggest to use | ||
* | ||
* @var String | ||
*/ | ||
var $prefix_suggestion = "xf_"; | ||
|
||
/** | ||
* An array of xenforo -> mybb groups | ||
* | ||
* @var array | ||
*/ | ||
var $groups = array( | ||
1 => MYBB_GUESTS, // Guests | ||
2 => MYBB_REGISTERED, // Registered | ||
3 => MYBB_ADMINS, // Administrators | ||
4 => MYBB_MODS, // Moderators | ||
); | ||
|
||
/** | ||
* An array of supported databases | ||
* XenForo only supports MySQL | ||
*/ | ||
var $supported_databases = array("mysql"); | ||
|
||
var $column_length_to_check = array( | ||
"user_group" => array( | ||
"usergroups" => array( | ||
"title" => "title", | ||
"username_css" => "namestyle", | ||
), | ||
), | ||
"user" => array( | ||
"users" => array( | ||
"username" => "username", | ||
"email" => "email", | ||
), | ||
), | ||
"user_profile" => array( | ||
"users" => array( | ||
"website" => "website", | ||
), | ||
), | ||
"thread" => array( | ||
"threads" => array( | ||
"title" => "subject", | ||
), | ||
), | ||
"post" => array( | ||
"posts" => array( | ||
"message" => "message", | ||
), | ||
), | ||
); | ||
|
||
/** | ||
* Get imported thread and cache it during script processing. | ||
*/ | ||
var $cache_threads = array(); | ||
function get_thread($tid) | ||
{ | ||
global $db; | ||
|
||
if(isset($this->cache_threads[$tid])) | ||
{ | ||
return $this->cache_threads[$tid]; | ||
} | ||
|
||
$query = $db->simple_select("threads", "fid,subject,dateline,visible", "tid='{$tid}'", array("limit" => 1)); | ||
$thread = $db->fetch_array($query); | ||
$db->free_result($query); | ||
|
||
$this->cache_threads[$tid] = $thread; | ||
return $this->cache_threads[$tid]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
/** | ||
* MyBB 1.8 Merge System | ||
* Copyright 2019 MyBB Group, All Rights Reserved | ||
* | ||
* Website: http://www.mybb.com | ||
* License: http://www.mybb.com/download/merge-system/license/ | ||
*/ | ||
|
||
// Disallow direct access to this file for security reasons | ||
if(!defined("IN_MYBB")) | ||
{ | ||
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); | ||
} | ||
|
||
class XENFORO2_Converter_Module_Attachments extends Converter_Module_Attachments | ||
{ | ||
var $settings = array( | ||
'friendly_name' => 'attachments', | ||
'progress_column' => 'attachment_id', | ||
'default_per_screen' => 20, | ||
); | ||
|
||
public $path_column = "attachment_id, data_id"; | ||
|
||
public $test_table = "attachment"; | ||
|
||
function get_upload_path() | ||
{ | ||
$query = $this->old_db->simple_select("option", "option_value", "option_id='boardUrl'"); | ||
$uploadspath = $this->old_db->fetch_field($query, "option_value") . "/internal_data/attachments/"; | ||
$this->old_db->free_result($query); | ||
return $uploadspath; | ||
} | ||
|
||
function import() | ||
{ | ||
global $import_session; | ||
|
||
$query = $this->old_db->query("SELECT * | ||
FROM ".OLD_TABLE_PREFIX."attachment a | ||
LEFT JOIN ".OLD_TABLE_PREFIX."attachment_data d ON (d.data_id=a.data_id) | ||
WHERE a.content_type='post' | ||
LIMIT {$this->trackers['start_attachments']}, {$import_session['attachments_per_screen']}"); | ||
while($attachment = $this->old_db->fetch_array($query)) | ||
{ | ||
$this->insert($attachment); | ||
} | ||
} | ||
|
||
function convert_data($data) | ||
{ | ||
global $db; | ||
|
||
$insert_data = array(); | ||
|
||
// Xenforo 2 values | ||
$insert_data['import_aid'] = $data['attachment_id']; | ||
|
||
$ext = get_extension($data['filename']); | ||
$query = $db->simple_select("attachtypes", "mimetype", "extension='{$ext}'"); | ||
$insert_data['filetype'] = $db->fetch_field($query, "mimetype"); | ||
$db->free_result($query); | ||
|
||
// Check if it is it an image | ||
switch(strtolower($insert_data['filetype'])) | ||
{ | ||
case "image/gif": | ||
case "image/jpeg": | ||
case "image/x-jpg": | ||
case "image/x-jpeg": | ||
case "image/pjpeg": | ||
case "image/jpg": | ||
case "image/png": | ||
case "image/x-png": | ||
$is_image = 1; | ||
break; | ||
default: | ||
$is_image = 0; | ||
break; | ||
} | ||
|
||
// Should have thumbnail if it's an image | ||
if($is_image == 1) | ||
{ | ||
$insert_data['thumbnail'] = 'SMALL'; | ||
} | ||
else | ||
{ | ||
$insert_data['thumbnail'] = ''; | ||
} | ||
|
||
$insert_data['uid'] = $this->get_import->uid($data['user_id']); | ||
$insert_data['filename'] = $data['filename']; | ||
$insert_data['filesize'] = $data['file_size']; | ||
$insert_data['downloads'] = $data['view_count']; | ||
|
||
$attach_details = $this->get_import->post_attachment_details($data['content_id']); | ||
|
||
$insert_data['pid'] = $attach_details['pid']; | ||
$insert_data['posthash'] = md5($attach_details['tid'].$attach_details['uid'].random_str()); | ||
|
||
// Build name and check whether it's already in use | ||
$insert_data['attachname'] = "post_".$insert_data['uid']."_".$data['attach_date'].".attach"; | ||
$query = $db->simple_select("attachments", "aid", "attachname='".$db->escape_string($insert_data['attachname'])."'"); | ||
if($db->num_rows($query) > 0) | ||
{ | ||
$insert_data['attachname'] = "post_".$insert_data['uid']."_".$data['attach_date']."_".$data['attachment_id'].".attach"; | ||
} | ||
|
||
return $insert_data; | ||
} | ||
|
||
function generate_raw_filename($attach) | ||
{ | ||
if(!isset($attach['file_hash'])) | ||
{ | ||
$query = $this->old_db->simple_select("attachment_data", "file_hash", "data_id='{$attach['data_id']}'"); | ||
$data = $this->old_db->fetch_array($query); | ||
$this->old_db->free_result($query); | ||
$attach = array_merge($attach, $data); | ||
} | ||
$name = floor($attach['data_id']/1000)."/{$attach['data_id']}-{$attach['file_hash']}.data"; | ||
|
||
return $name; | ||
} | ||
|
||
function fetch_total() | ||
{ | ||
global $import_session; | ||
|
||
// Get number of attachments | ||
if(!isset($import_session['total_attachments'])) | ||
{ | ||
$query = $this->old_db->simple_select("attachment", "COUNT(*) as count", "content_type='post'"); | ||
$import_session['total_attachments'] = $this->old_db->fetch_field($query, 'count'); | ||
$this->old_db->free_result($query); | ||
} | ||
|
||
return $import_session['total_attachments']; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* MyBB 1.8 Merge System | ||
* Copyright 2019 MyBB Group, All Rights Reserved | ||
* | ||
* Website: http://www.mybb.com | ||
* License: http://www.mybb.com/download/merge-system/license/ | ||
*/ | ||
|
||
// Disallow direct access to this file for security reasons | ||
if(!defined("IN_MYBB")) | ||
{ | ||
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); | ||
} | ||
|
||
class XENFORO2_Converter_Module_Avatars extends Converter_Module_Avatars | ||
{ | ||
var $settings = array( | ||
'friendly_name' => 'avatars', | ||
'progress_column' => 'user_id', | ||
'default_per_screen' => 20, | ||
); | ||
|
||
function get_avatar_path() | ||
{ | ||
$query = $this->old_db->simple_select("option", "option_value", "option_id='boardUrl'"); | ||
$uploadspath = $this->old_db->fetch_field($query, "option_value") . "/data/avatars/"; | ||
$this->old_db->free_result($query); | ||
return $uploadspath; | ||
} | ||
|
||
function import() | ||
{ | ||
global $import_session; | ||
|
||
$query = $this->old_db->simple_select("user", "*", "avatar_date > 0 OR gravatar != ''", array('limit_start' => $this->trackers['start_avatars'], 'limit' => $import_session['avatars_per_screen'])); | ||
while($avatar = $this->old_db->fetch_array($query)) | ||
{ | ||
$this->insert($avatar); | ||
} | ||
} | ||
|
||
function convert_data($data) | ||
{ | ||
global $mybb; | ||
|
||
$insert_data = array(); | ||
|
||
// Xenforo 2 values | ||
$insert_data['uid'] = $this->get_import->uid($data['user_id']); | ||
|
||
if(!empty($data['gravatar'])) | ||
{ | ||
$insert_data['avatartype'] = AVATAR_TYPE_GRAVATAR; | ||
$insert_data['avatar'] = $this->get_gravatar_url($data['gravatar']); | ||
|
||
if(!$mybb->settings['maxavatardims']) | ||
{ | ||
$mybb->settings['maxavatardims'] = '100x100'; // Hard limit of 100 if there are no limits | ||
} | ||
|
||
list($maxwidth, $maxheight) = explode("x", my_strtolower($mybb->settings['maxavatardims'])); | ||
$this->dimension = "{$maxheight}|{$maxwidth}"; | ||
} | ||
else | ||
{ | ||
$insert_data['avatar'] = $this->get_upload_avatar_name($insert_data['uid'], $this->generate_raw_filename($data)); | ||
$insert_data['avatartype'] = AVATAR_TYPE_UPLOAD; | ||
$insert_data['avatardimensions'] = "{$data['avatar_height']}|{$data['avatar_width']}"; | ||
} | ||
|
||
return $insert_data; | ||
} | ||
|
||
function fetch_total() | ||
{ | ||
global $import_session; | ||
|
||
// Get number of users with avatar | ||
if(!isset($import_session['total_avatars'])) | ||
{ | ||
$query = $this->old_db->simple_select("user", "COUNT(*) as count", "avatar_date > 0 OR gravatar != ''"); | ||
$import_session['total_avatars'] = $this->old_db->fetch_field($query, 'count'); | ||
$this->old_db->free_result($query); | ||
} | ||
|
||
return $import_session['total_avatars']; | ||
} | ||
|
||
function generate_raw_filename($avatar) | ||
{ | ||
// TODO: or "o/" for original? | ||
return "l/".floor($avatar['user_id']/1000)."/{$avatar['user_id']}.jpg"; | ||
} | ||
} |
Oops, something went wrong.