Index: phpbb2drupal.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phpbb2drupal/phpbb2drupal.module,v
retrieving revision 1.34
diff -u -p -r1.34 phpbb2drupal.module
--- phpbb2drupal.module 18 Nov 2006 01:54:02 -0000 1.34
+++ phpbb2drupal.module 18 Nov 2006 06:36:42 -0000
@@ -4,13 +4,10 @@
*
****************************************************/
-/****************************************************
- *
+/**
* Implementation of hook_menu()
- *
-****************************************************/
+ */
function phpbb2drupal_menu($may_cache) {
- global $user;
$items = array();
if (!$may_cache) {
@@ -19,96 +16,84 @@ function phpbb2drupal_menu($may_cache) {
'title' => t('phpBB to Drupal'),
'access' => user_access('migrate phpBB'),
'callback' => 'phpbb2drupal_main',
- 'type'=> MENU_NORMAL_ITEM
+ 'type'=> MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/phpbb2drupal/postconfiguration',
'title' => t('Post Migration Configuration'),
'access' => user_access('migrate phpBB'),
'callback' => 'phpbb2drupal_postconfiguration',
- 'type'=> MENU_NORMAL_ITEM
+ 'type'=> MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/phpbb2drupal/cleanup',
'title' => t('Cleanup'),
'access' => user_access('migrate phpBB'),
'callback' => 'phpbb2drupal_cleanup',
- 'type'=> MENU_CALLBACK
+ 'type'=> MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/phpbb2drupal/migrate',
'title' => t('Execute Migration'),
'access' => user_access('migrate phpBB'),
'callback' => 'phpbb2drupal_migrate',
- 'type'=> MENU_CALLBACK
+ 'type'=> MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/phpbb2drupal/reset',
'title' => t('Reset phpBB2 database URL'),
'access' => user_access('migrate phpBB'),
'callback' => 'phpbb2drupal_reset',
- 'type'=> MENU_CALLBACK
+ 'type'=> MENU_CALLBACK,
);
}
return $items;
}
-/****************************************************
- *
+/**
* Implementation of hook_perm()
- *
-****************************************************/
+ */
function phpbb2drupal_perm() {
- return array ('migrate phpBB');
+ return array('migrate phpBB');
}
-/****************************************************
- *
+/**
* Implementation of hook_help()
- *
-****************************************************/
-function phpbb2drupal_help( $section='') {
+ */
+function phpbb2drupal_help($section = '') {
$output = '';
switch ($section) {
- case "admin/modules#description":
- $output = t("Migrate your phpBB data into a Drupal forum.");
+ case 'admin/modules#description':
+ $output = t('Migrate your phpBB data into a Drupal forum.');
break;
}
return $output;
}
-/****************************************************
- *
+/**
* Callback admin/phpbb2drupal/reset
- *
-****************************************************/
+ */
function phpbb2drupal_reset() {
global $db_url;
- variable_set ("phpbb2drupal_db_url", $db_url);
- variable_set ("phpbb2drupal_ready", 0);
+ variable_set('phpbb2drupal_db_url', $db_url);
+ variable_set('phpbb2drupal_ready', 0);
return '
'. t('The phpBB2 database URL has been reset. You may now go back to the configuration page.',
array('%configlink' => url('admin/settings/phpbb2drupal'))) .'
';
}
-/****************************************************
- *
+/**
* Callback admin/phpbb2drupal/cleanup
- *
-****************************************************/
+ */
function phpbb2drupal_cleanup() {
return phpbb2drupal_import_cleanup() . ''. t('Drupal database cleaned.') .'
';
}
-/****************************************************
- *
+/**
* Callback admin/phpbb2drupal/postconfiguration
- *
-****************************************************/
+ */
function phpbb2drupal_postconfiguration() {
- $output ='';
-
// Private forums.
- $output .= ''. t('Private forums') .'
';
+ $output = ''. t('Private forums') .'
';
$output .= ''. t('Setup the private forums as explained in the documentation') .'
';
// Redirection from old URL:
@@ -120,7 +105,8 @@ function phpbb2drupal_postconfiguration(
if ($bbcode) {
$output .= ''. t('Remove BBcode module') .'
';
$output .= ''. t("The bbcode has been cleaned from the posts. You shouldn't need the bbcode module anymore. You can disable it.") .'
';
- } else {
+ }
+ else {
$output .= ''. t('Configure BBcode module') .'
';
$output .= ''. t('Most probably, there are many phpBB forum postings formatted in BBcode. During the import procedure, the BBcode has been cleaned so that it can work with the Drupal bbcode.module. Please install and configure the BBcode module so that the forum topics display properly. See the BBcode module documentation for details.') .'
';
}
@@ -129,66 +115,59 @@ function phpbb2drupal_postconfiguration(
$output .= ''. t('Avatars') .'
';
$output .= t('Manually copy the avatars from the phpbb2/images/avatars/ directory to the drupal/files/pictures/ directory.
Also, in admin > settings > users, you need to enable picture support.
- Finally, in admin > themes > configure, you need to allow "User Picture in posts/comments".
');
- $output .='';
+ Finally, in admin > themes > configure, you need to allow "User Picture in posts/comments"
');
+
return $output;
}
-/****************************************************
- *
+/**
* Callback admin/phpbb2drupal
- *
-****************************************************/
+ */
function phpbb2drupal_main() {
- $output ='';
-
- $output .='- ';
+ $output = '
- ';
$output .= t('You may want to check the documentation before starting.');
- $output .='
';
- $output .='- ';
- $output .=l(t('Configure the migration'), 'admin/settings/phpbb2drupal');
- $output .='
';
- $output .='- ';
- $output .=l(t('Execute the migration'), 'admin/phpbb2drupal/migrate');
- $output .='
';
- $output .='- ';
- $output .=l(t('Post migration configuration'), 'admin/phpbb2drupal/postconfiguration');
- $output .='
';
- $output .='- ';
+ $output .= '
';
+ $output .= '- ';
+ $output .= l(t('Configure the migration'), 'admin/settings/phpbb2drupal');
+ $output .= '
';
+ $output .= '- ';
+ $output .= l(t('Execute the migration'), 'admin/phpbb2drupal/migrate');
+ $output .= '
';
+ $output .= '- ';
+ $output .= l(t('Post migration configuration'), 'admin/phpbb2drupal/postconfiguration');
+ $output .= '
';
+ $output .= '- ';
$output .= t('Cleanup (Accessing this link will delete all the saved phpbb2drupal settings and temporary tables: click only when you\'re done with all the above.)', array('%cleanuplink' => url('admin/phpbb2drupal/cleanup')));
$output .= '
';
$output .= '- '. t('If your data migration has proceeded smoothly, please post a "thank you" note in this forum topic at drupal.org.');
- $output .='
';
- $output .='
';
+ $output .= ' ';
+ $output .= '
';
// process will die() if the link to the phpBB2 database is wrong:
- $output .=''. t('If the phpBB2 data is in another data base, but you made a mistake while setting up the data base url, you may be unable to access the setting page due to some limitations of the core of Drupal. Click here to reset the database url.',
+ $output .= '
'. t('If the phpBB2 data is in another data base, but you made a mistake while setting up the data base url, you may be unable to access the setting page due to some limitations of the core of Drupal. Click here to reset the database url.',
array('%reseturl' => url('admin/phpbb2drupal/reset'))) .'
';
- $output .='';
- $output .='';
- $output .='';
return $output;
}
-/****************************************************
- *
+
+/**
* Set database connection for phpBB
*
- * return 1 if can connect to phpbb database.
+ * @return
+ * 1 if can connect to phpbb database.
*
* BEWARE: if you test using db_connect and the connection
* fails, the process will die() which is a bit too much since we only
* want to test. Therefore, the test part of the code is not used, now.
- *
-****************************************************/
+ */
function _phpbb2drupal_db_connect($test= 0) {
global $db_url;
$same = variable_get('phpbb2drupal_same_db', 1);
if (!$same) {
$db_url2['phpbb'] = variable_get('phpbb2drupal_db_url', $db_url);
$db_url2['default'] = $db_url;
- $GLOBALS["db_url"] =& $db_url2;
- if ($test){
+ $GLOBALS['db_url'] =& $db_url2;
+ if ($test) {
if (!db_connect($db_url2['phpbb'])) {
return 0;
}
@@ -198,11 +177,9 @@ function _phpbb2drupal_db_connect($test=
}
-/****************************************************
- *
+/**
* Callback admin/phpbb2drupal/configure
- *
-****************************************************/
+ */
function phpbb2drupal_settings() {
global $conf ;
global $db_url;
@@ -213,11 +190,11 @@ function phpbb2drupal_settings() {
$ready_for_migration = 1;
// Checking that the migration has been tested on a copy first.
- $form['test'] = array (
+ $form['test'] = array(
'#type' => 'fieldset',
'#title' => t('Test on copy first'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$output = '';
@@ -243,17 +220,17 @@ function phpbb2drupal_settings() {
);
// Input format settings
- $form['input'] = array (
+ $form['input'] = array(
'#type' => 'fieldset',
'#title' => t('Input Format settings'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$output = ''. t('Select which input format should the imported messages be set:', array('%link' => url('admin/filters'))) .'
';
$form['input']['intro'] = array('#value' => $output);
$output = '';
- $input_formats = array (0 => t('not set yet'));
+ $input_formats = array(0 => t('not set yet'));
$sql = 'SELECT format, name FROM {filter_formats}';
$result = db_query($sql);
while ($format = db_fetch_array($result)) {
@@ -275,11 +252,11 @@ function phpbb2drupal_settings() {
// BBcode settings
- $form['bbcode'] = array (
+ $form['bbcode'] = array(
'#type' => 'fieldset',
'#title' => t('BBcode settings'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$output = t('pbpBB2 posts are often formatted in BBcode. During the import process, BBcode can be handled in two diffent ways:
@@ -309,15 +286,16 @@ function phpbb2drupal_settings() {
You first need to enable the bbcode module', array('%adminmodules' => url('admin/modules')));
$output .= '';
}
- $sql ='SELECT * FROM {filters} WHERE module = \'bbcode\' AND format = %d';
- $result = db_query ($sql, $input_format);
+ $sql = 'SELECT * FROM {filters} WHERE module = \'bbcode\' AND format = %d';
+ $result = db_query($sql, $input_format);
if (!db_num_rows($result)) {
$form['bbcode']['#collapsed']= FALSE;
$output .= ''. t('You need to enable bbcode in the selected input format THEN click on configure to see bbcode options', array('%formatenable' => $link_input_format_enable, '%formatconfigure' => $link_input_format_configure)) .'
';
}
$output .= ''. t('For best results, all four BBcode configure options should be disabled.', array('%bbcodeconfig' => url('admin/filters/'. $input_format .'/configure'))) .'
';
- } else {
+ }
+ else {
if ($result7['result'] == 0) {
$form['bbcode']['#collapsed']= FALSE;
$output .= ''. t('The bbcode module is only recommanded. You may enable the bbcode module after having installed it.', array('%adminmodules' => url('admin/modules'))) .'
';
@@ -331,11 +309,11 @@ function phpbb2drupal_settings() {
// Drupal Modules settings
- $form['modules'] = array (
+ $form['modules'] = array(
'#type' => 'fieldset',
'#title' => t('Drupal modules'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$output = '';
$result1 = _phpbb2drupal_check_module('forum');
@@ -352,7 +330,7 @@ function phpbb2drupal_settings() {
$output .= $result6['html'];
$output .= '
';
- if ($result1['result'] == 0 OR $result2['result'] == 0 OR $result3['result'] == 0 OR $result4['result'] == 0 OR $result5['result'] == 0 OR $result6['result'] == 0 ) {
+ if ($result1['result'] == 0 || $result2['result'] == 0 || $result3['result'] == 0 || $result4['result'] == 0 || $result5['result'] == 0 || $result6['result'] == 0) {
$ready_for_migration = 0;
$form['modules']['#collapsed']= FALSE;
$output .= '';
@@ -363,11 +341,11 @@ function phpbb2drupal_settings() {
$output = '';
// Where is phpbb2?
- $form['phpbb2'] = array (
+ $form['phpbb2'] = array(
'#type' => 'fieldset',
'#title' => t('Location of phpBB2 data'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$form['phpbb2']['phpbb2drupal_same_db'] = array(
'#type' => 'checkbox',
@@ -378,7 +356,7 @@ function phpbb2drupal_settings() {
);
if (variable_get('phpbb2drupal_same_db', 1) != 1) {
$url = variable_get('phpbb2drupal_db_url', $db_url);
- if ( $url == $db_url) {
+ if ($url == $db_url) {
$output = '
'. t('Set the address of the phpBB database according to the following format:
mysql://phpbb_username:phpbb_password@localhost/phpbb_database
') .'';
$ready_for_migration = 0;
$form['phpbb2']['#collapsed']= FALSE;
@@ -393,8 +371,9 @@ function phpbb2drupal_settings() {
'#description' => '',
);
}
- $output = t('Note that due to a limitation within Drupal core, we cannot import messages from one database type to another database type. E.g, we cannot import phpBB for a myqsl DB, to a postgresql DB. You need to import the data into the same type of database first (import all the phpBB data, as is, from mysql to postgresql.
-If both phpBB and Drupal are on postgresql, see this issue.
');
+
+ $output = t('Note that due to a limitation within Drupal core, we cannot import messages from one database type to another database type. E.g, we cannot import phpBB for a myqsl DB, to a postgresql DB. You need to import the data into the same type of database first (import all the phpBB data, as is, from mysql to postgresql.
+ If both phpBB and Drupal are on postgresql, see this issue.
');
$form['phpbb2']['note'] = array('#value' => $output);
// phpBB2 table prefix
@@ -409,7 +388,7 @@ function phpbb2drupal_settings() {
);
$pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$tables = array($pre.'categories', $pre.'forums', $pre.'posts', $pre.'posts_text', $pre.'topics', $pre.'users');
- $result = _phpbb2drupal_check_tables ($tables, 'phpbb', 0);
+ $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
$output .= $result['html'];
if ($result['result'] != 1) {
@@ -417,18 +396,18 @@ function phpbb2drupal_settings() {
$form['phpbb2']['#collapsed']= FALSE;
$output .= '';
$output .= t("Some tables couldn't be found. Please correct the errors so that the phpBB2 tables can be accessed.");
- $output .= "";
+ $output .= '';
}
$form['phpbb2']['result'] = array('#value' => $output);
// Misc.
- $form['misc'] = array (
+ $form['misc'] = array(
'#type' => 'fieldset',
'#title' => t('Misc. settings'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
// Time limit
@@ -454,11 +433,11 @@ function phpbb2drupal_settings() {
);
// USERS settings
- $form['users'] = array (
+ $form['users'] = array(
'#type' => 'fieldset',
'#title' => t('User import'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
// User to map admin user too
$drupal_admin = user_load(array('uid' => 1));
@@ -483,8 +462,8 @@ function phpbb2drupal_settings() {
$form['polls'] = array(
'#type' => 'fieldset',
'#title' => t('Polls import'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$form['polls']['phpbb2drupal_import_polls'] = array(
'#type' => 'checkbox',
@@ -500,9 +479,9 @@ function phpbb2drupal_settings() {
if ($result['result'] != 1) {
$ready_for_migration = 0;
$form['polls']['#collapsed'] = FALSE;
- $output .= "";
+ $output .= '';
$output .= t('Please enable the poll module.') ;
- $output .= "";
+ $output .= '';
}
$form['polls']['info'] = array('#value' => $output);
}
@@ -510,11 +489,11 @@ function phpbb2drupal_settings() {
//Attachements
$output ='';
- $form['attachements'] = array (
+ $form['attachements'] = array(
'#type' => 'fieldset',
'#title' => t('Attachements import'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$form['attachements']['phpbb2drupal_import_attachments'] = array(
'#type' => 'checkbox',
@@ -524,49 +503,47 @@ function phpbb2drupal_settings() {
'#description' => '',
);
if (variable_get('phpbb2drupal_import_attachments', 0) == 1) {
-
- // Comment attachments module
- $result = _phpbb2drupal_check_module('comment_upload');
- $output .= $result['html'];
- if ($result['result'] != 1) {
- $ready_for_migration = 0;
- $form['attachements']['#collapsed']= FALSE;
- $output .= "";
- $output .= t('The comment_upload.module is not enabled. You can go to the module Home Page to download it. After having installed it, go to the admin/module page to enable it', array('%adminmodules' => url('admin/modules')));
- $output .= "";
- }
+ // Comment attachments module
+ $result = _phpbb2drupal_check_module('comment_upload');
+ $output .= $result['html'];
+ if ($result['result'] != 1) {
+ $ready_for_migration = 0;
+ $form['attachements']['#collapsed']= FALSE;
+ $output .= '';
+ $output .= t('The comment_upload.module is not enabled. You can go to the module Home Page to download it. After having installed it, go to the admin/module page to enable it', array('%adminmodules' => url('admin/modules')));
+ $output .= '';
+ }
- //comment_files tables.
- $result = _phpbb2drupal_check_tables (array('comment_files'));
- $output .= $result['html'];
- if ($result['result'] != 1) {
- $ready_for_migration = 0;
- $form['attachements']['#collapsed']= FALSE;
- $output .= '';
- $output .= t("The comment_files table couldn't be found. Please make sure you have properly installed the comment_upload.mysql on your Drupal database.");
- $output .= "
";
- }
- $form['attachements']['info'] = array('#value' => $output);
- $output = '';
-
+ //comment_files tables.
+ $result = _phpbb2drupal_check_tables(array('comment_files'));
+ $output .= $result['html'];
+ if ($result['result'] != 1) {
+ $ready_for_migration = 0;
+ $form['attachements']['#collapsed']= FALSE;
+ $output .= '';
+ $output .= t("The comment_files table couldn't be found. Please make sure you have properly installed the comment_upload.mysql on your Drupal database.");
+ $output .= '
';
+ }
+ $form['attachements']['info'] = array('#value' => $output);
+ $output = '';
}
// Encoding
$form['encoding'] = array(
'#type' => 'fieldset',
'#title' => 'Encoding setting',
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
//DEBUG http://php.net/extension_loaded
if (!extension_loaded('mbstring') && variable_get('phpbb2drupal_encode', '1')) {
$ready_for_migration = 0;
$form['encoding']['#collapsed']= FALSE;
- $output .= "";
+ $output .= '
';
$output .= t("The php mbstring module is not installed on this server: the posts' encoding cannot be changed during the migration.");
- $output .= "
";
+ $output .= '';
}
$encodings = array(
@@ -655,11 +632,11 @@ function phpbb2drupal_settings() {
// Private messages
$output = '';
- $form['pm'] = array (
+ $form['pm'] = array(
'#type' => 'fieldset',
'#title' => t('Private Messages'),
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
$form['pm']['phpbb2drupal_import_pm'] = array(
'#type' => 'checkbox',
@@ -679,29 +656,29 @@ function phpbb2drupal_settings() {
$form['pm']['#collapsed']= FALSE;
$output .= '';
$output .= t('The private message module is not enabled. You can go to the module Home Page to download it. After having installed it, go to the admin/module page to enable it.', array('%adminmodules' => url('admin/modules')));
- $output .= "
";
+ $output .= '';
}
$pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$tables = array($pre.'privmsgs', $pre.'privmsgs_text');
- $result = _phpbb2drupal_check_tables ($tables, 'phpbb', 0);
+ $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
$output .= $result['html'];
if ($result['result'] != 1) {
$ready_for_migration = 0;
$form['pm']['#collapsed']= FALSE;
$output .= '';
$output .= t("Couldn't find the phpBB privatemsg tables.");
- $output .= "
";
+ $output .= '';
}
//private messages tables.
- $result = _phpbb2drupal_check_tables (array('privatemsg', 'privatemsg_folder', 'privatemsg_archive'));
+ $result = _phpbb2drupal_check_tables(array('privatemsg', 'privatemsg_folder', 'privatemsg_archive'));
$output .= $result['html'];
if ($result['result'] != 1) {
$ready_for_migration = 0;
$form['pm']['#collapsed']= FALSE;
$output .= '';
$output .= t("Some tables couldn't be found. Please make sure you have properly installed the privatemsg.mysql on your Drupal data base.");
- $output .= "
";
+ $output .= '';
}
$form['pm']['info'] = array('#value' => $output);
@@ -709,59 +686,58 @@ function phpbb2drupal_settings() {
$output ='';
// Are we ready for migration?
- $form['migration'] = array (
+ $form['migration'] = array(
'#type' => 'fieldset',
'#title' => 'Migration',
- '#collapsible' => 'TRUE',
- '#collapsed' => 'TRUE',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
);
- variable_set ('phpbb2drupal_ready', $ready_for_migration);
+ variable_set('phpbb2drupal_ready', $ready_for_migration);
if ($ready_for_migration) {
$form['migration']['#collapsed']= FALSE;
$output .= ''. t('Check again all the settings above, and if everything is ok, you can now proceed with the migration', array('%migratelink' => url('admin/phpbb2drupal/migrate'))) .'
';
- } else {
+ }
+ else {
$output = ''. t('You are not ready for the migration yet. Check the settings above.') .'
';
}
- $form['migration']['info'] = array('#value'=>$output);
+ $form['migration']['info'] = array('#value' => $output);
return $form;
}
-/****************************************************
- *
+/**
* Check if the module is enabled.
- * Returns array:
- * $out['html'] = formatted html.
- * $out['result'] = boolean.
- *
-****************************************************/
+ *
+ * @return array
+ * $out['html'] = formatted html.
+ * $out['result'] = boolean.
+ */
function _phpbb2drupal_check_module($module) {
- $out['html'] = "";
- $query = "SELECT status FROM {system}
- WHERE status = 1 AND type = 'module' AND name = '%s'";
- $result = db_query ($query, $module);
+ $out['html'] = '';
+ $query = "SELECT status FROM {system} WHERE status = 1 AND type = 'module' AND name = '%s'";
+ $result = db_query($query, $module);
$result = db_num_rows($result);
$out['result'] = $result;
- if ($result == 1 ) {
+ if ($result == 1) {
$out['html'] .= '- '. t('Module %module is enabled. OK!', array('%module' => $module)) .'
';
- } else {
+ }
+ else {
$out['html'] .= '- '. t('Module %module is disabled.', array('%module' => $module)) .'
';
}
- $out['html'] .= "
";
+ $out['html'] .= '
';
return $out;
}
-/****************************************************
- *
+/**
* Check if the sql tables are installed.
- * Returns array:
- * $out['html'] = formatted html.
- * $out['result'] = boolean.
- *
-****************************************************/
-function _phpbb2drupal_check_tables( $tables = array(), $db = 'default' , $prefix=1) {
+ *
+ * @return array
+ * $out['html'] = formatted html.
+ * $out['result'] = boolean.
+ */
+function _phpbb2drupal_check_tables( $tables = array(), $db = 'default' , $prefix = 1) {
_phpbb2drupal_db_connect() ;
db_set_active($db);
@@ -775,10 +751,10 @@ function _phpbb2drupal_check_tables( $ta
$query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE '%s'";
}
else {
- $query = 'SHOW TABLES LIKE "%s"';
+ $query = "SHOW TABLES LIKE '%s'";
}
- $result = db_query ($query, $table);
- $result = db_num_rows ($result);
+ $result = db_query($query, $table);
+ $result = db_num_rows($result);
if ($result) {
$out['html'] .= ''. t('Table %table: OK!', array('%table' => $table)) .'';
}
@@ -795,7 +771,7 @@ function _phpbb2drupal_check_tables( $ta
function phpbb2drupal_migrate() {
- if (!variable_get ('phpbb2drupal_ready', 0)) {
+ if (!variable_get('phpbb2drupal_ready', 0)) {
return ''. t('You cannot migrate the data now. Please complete the setup first', array('%settings' => url('admin/settings/phpbb2drupal'))) .'
';
}
@@ -816,7 +792,7 @@ function phpbb2drupal_migrate() {
'posts' => t('Import Posts'),
);
- if (variable_get('phpbb2drupal_import_pm',0)) {
+ if (variable_get('phpbb2drupal_import_pm', 0)) {
$PHPBB2DRUPAL_FUNCTIONS['pm'] = t('Import Private Messages');
}
$PHPBB2DRUPAL_FUNCTIONS['url'] = t('Transform URLs');
@@ -843,62 +819,69 @@ function phpbb2drupal_migrate_submit($fo
switch ($form_values['import']) {
case 'users':
phpbb2drupal_import_users();
- if(!variable_get('phpbb2drupal_import_user_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_user_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'users';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'categories';
}
break;
case 'categories':
phpbb2drupal_import_categories();
- if(!variable_get('phpbb2drupal_import_category_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_category_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'categories';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'topics';
}
break;
case 'topics':
phpbb2drupal_import_topics();
- if(!variable_get('phpbb2drupal_import_topic_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_topic_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'topics';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'polls';
}
break;
case 'polls':
phpbb2drupal_import_polls();
- if(!variable_get('phpbb2drupal_import_poll_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_poll_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'polls';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'posts';
}
break;
case 'posts':
phpbb2drupal_import_posts();
- if(!variable_get('phpbb2drupal_import_post_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_post_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'posts';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'pm';
}
break;
case 'pm':
phpbb2drupal_import_pm();
- if(!variable_get('phpbb2drupal_import_pm_successful', 0)) {
+ if (!variable_get('phpbb2drupal_import_pm_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'pm';
- } else {
+ }
+ else {
$_SESSION['phpbb2drupal_selected'] = 'url';
}
break;
case 'url':
phpbb2drupal_replace_url();
- if(!variable_get('phpbb2drupal_replace_url_successful', 0)) {
+ if (!variable_get('phpbb2drupal_replace_url_successful', 0)) {
$_SESSION['phpbb2drupal_selected'] = 'url';
- } else {
+ }
+ else {
drupal_set_message('Congratulations. Import Finished');
drupal_set_message('Please visit the ' . l('Post migration configuration', 'admin/phpbb2drupal/postconfiguration'). ' page');
unset($_SESSION['phpbb2drupal_selected']);
@@ -914,27 +897,28 @@ function phpbb2drupal_migrate_submit($fo
* Private Message Import Functions
*/
function phpbb2drupal_import_pm() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$format = variable_get('phpbb2drupal_input_format', 0);
- if(variable_get('phpbb2drupal_import_pm_successful', 0) == 1) return;
+ if (variable_get('phpbb2drupal_import_pm_successful', 0) == 1) {
+ return;
+ }
db_set_active('phpbb');
- $query = "SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid, p.privmsgs_subject,pt.privmsgs_text, pt.privmsgs_bbcode_uid ,p.privmsgs_date,
+ $query = "SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid, p.privmsgs_subject, pt.privmsgs_text, pt.privmsgs_bbcode_uid, p.privmsgs_date,
CASE WHEN p.privmsgs_type = 1 THEN 1
WHEN p.privmsgs_type = 5 THEN 1
ELSE 0
END as newmsg,
- p.privmsgs_ip,0,0,0
+ p.privmsgs_ip, 0, 0, 0
FROM %sprivmsgs p
- LEFT JOIN %sprivmsgs_text AS pt ON p.privmsgs_id=pt.privmsgs_text_id";
+ LEFT JOIN %sprivmsgs_text AS pt ON p.privmsgs_id = pt.privmsgs_text_id";
$messages = db_query($query, $pre, $pre);
db_set_active('default');
- while($pm = db_fetch_object($messages)) {
- $query = "SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d";
- $from_result = db_query ($query, $pm->privmsgs_from_userid);
+ while ($pm = db_fetch_object($messages)) {
+ $query = 'SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d';
+ $from_result = db_query($query, $pm->privmsgs_from_userid);
$from = db_result($from_result);
- $query = "SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d";
- $to_result = db_query ($query, $pm->privmsgs_to_userid);
+ $to_result = db_query($query, $pm->privmsgs_to_userid);
$to = db_result($to_result);
// don't import private messages from or to users who are not imported.
if ($from and $to) {
@@ -945,9 +929,9 @@ function phpbb2drupal_import_pm() {
$pm->privmsgs_text = _phpbb2drupal_replace_links($pm->privmsgs_text);
$pm->privmsgs_subject = _phpbb2drupal_text_encode($pm->privmsgs_subject);
- $query = "INSERT INTO {privatemsg} ( id, author, recipient,subject,message,timestamp,newmsg,hostname,folder,author_del,recipient_del, format )
+ $query = "INSERT INTO {privatemsg} ( id, author, recipient, subject, message, timestamp, newmsg, hostname, folder, author_del, recipient_del, format )
VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', 0, 0, 0 , %d)";
- $result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject,0,64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip,0,255), $format);
+ $result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject, 0, 64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip, 0, 255), $format);
}
}
variable_set('phpbb2drupal_import_pm_successful', 1);
@@ -958,92 +942,92 @@ function phpbb2drupal_import_pm() {
* User Import Functions
*/
function phpbb2drupal_import_users() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
// check if the user database has been successfully imported
db_set_active('default');
- if(variable_get('phpbb2drupal_import_user_successful', 0)) {
+ if (variable_get('phpbb2drupal_import_user_successful', 0)) {
drupal_set_message(t('Users already imported successfully'));
return;
}
- if(variable_get('phpbb2drupal_import_user_started', 0) == 0) {
+ if (variable_get('phpbb2drupal_import_user_started', 0) == 0) {
// create temporary tables
db_set_active('default');
// create profile fields for icq, aim, msn...etc
- $querybase = "INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES ";
+ $querybase = 'INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES ';
- $query = $querybase . "('YIM','user_yim','','Contact','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('YIM', 'user_yim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('AIM','user_aim','','Contact','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('AIM', 'user_aim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('icq','user_icq','','Contact','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('icq', 'user_icq', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('Website','user_website','','Contact','','url',0,0,1,2,'')";
+ $query = $querybase . "('Website', 'user_website', '', 'Contact', '', 'url', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('Location','user_from','','Personal','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('Location', 'user_from', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('Occupation','user_occ','','Personal','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('Occupation', 'user_occ', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
- $query = $querybase . "('Interests','user_interests','','Personal','','textfield',0,0,1,2,'')";
+ $query = $querybase . "('Interests', 'user_interests', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
db_query($query);
variable_set('phpbb2drupal_import_user_started', 1);
}
db_set_active('default');
- $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user','')));
- db_query("INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)", $drupal_admin->uid);
+ $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+ db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
$files_path = variable_get('file_directory_path', 'files');
$pictures_path = variable_get('user_picture_path', 'pictures');
// Insert the users into drupal
db_set_active('phpbb');
- $user_ids = db_query("SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id", $pre);
+ $user_ids = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre);
$user_count = db_num_rows($user_ids);
- if(!$user_count) {
+ if (!$user_count) {
drupal_set_message(t('There were no users found: Aborting script'), 'error');
return t('There were no users found: Aborting script.');
}
- drupal_set_message(t("Found %user_count users: Beginning Import", array('%user_count' => $user_count + 1)));
+ drupal_set_message(t('Found %user_count users: Beginning Import', array('%user_count' => $user_count + 1)));
- $import_spammers = variable_get('phpbb2drupal_import_spammers',1);
+ $import_spammers = variable_get('phpbb2drupal_import_spammers', 1);
- while($result = db_fetch_object($user_ids)) {
+ while ($result = db_fetch_object($user_ids)) {
db_set_active('phpbb');
- $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d',$pre, $result->user_id));
+ $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id));
// Make sure the user is not on the banlist
/* db_set_active('phpbb');
$banned = db_result(db_query("SELECT COUNT(*) FROM {banlist} WHERE ban_userid = %d", $user->user_id));
- if($banned) {
+ if ($banned) {
db_set_active('phpbb');
continue;
}*/
// If we don't want to import users who have never posted, break this while loop here.
- if ($import_spammers == 1 OR $user->user_posts != 0 ) {
+ if ($import_spammers == 1 || $user->user_posts != 0 ) {
// Make sure the user is has not already been imported
db_set_active('default');
- $count = db_result(db_query("SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d", $user->user_id));
- if($count > 0) {
+ $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $user->user_id));
+ if ($count > 0) {
$user->user_active = 0;
}
- $user->user_aim = strtr($user->user_aim, array("+" => ' ')); # PHPBB stores spaces as +, replace with ' '
- $user->user_yim = strtr($user->user_yim, array("+" => ' '));
+ $user->user_aim = strtr($user->user_aim, array('+' => ' ')); # PHPBB stores spaces as +, replace with ' '
+ $user->user_yim = strtr($user->user_yim, array('+' => ' '));
$user->user_timezone = $user->user_timezone * 60 * 60; # Drupal stores timezones in seconds
// remove the bbcode_uid from post_text
@@ -1053,15 +1037,15 @@ function phpbb2drupal_import_users() {
// drupal doesn't have pre-defined avatars. if we were to import it
// then multiple people would share the same avatar image and if one user
// were to changes their avatar then it would change it for everybody else.
- if($user->user_avatar_type > 1) {
+ if ($user->user_avatar_type > 1) {
$user->user_avatar = '';
}
- $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : '';
+ $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : '';
// remove the :bbcode_uid from signature
$signature = preg_replace("/:$post->bbcode_uid/", '', $user->user_sig);
- $signature = _phpbb2drupal_strip_bbcode ($signature);
+ $signature = _phpbb2drupal_strip_bbcode($signature);
$signature = _phpbb2drupal_text_encode($signature);
if (variable_get('phpbb2drupal_regdate_us_english', 0)) {
$user_regdate = strtotime($user->user_regdate);
@@ -1071,15 +1055,15 @@ function phpbb2drupal_import_users() {
}
$data = array(
- 'name' => substr($user->username,0,60),
- 'pass' => substr($user->user_password,0,32),
- 'mail' => substr($user->user_email,0,64),
- 'signature' => substr($signature,0,255),
+ 'name' => substr($user->username, 0, 60),
+ 'pass' => substr($user->user_password, 0, 32),
+ 'mail' => substr($user->user_email, 0, 64),
+ 'signature' => substr($signature, 0, 255),
'created' => $user_regdate,
'status' => $user->user_active,
'timezone' => $user->user_timezone,
'picture' => $user->user_avatar,
- 'init' => substr($user->user_email,0,64),
+ 'init' => substr($user->user_email, 0, 64),
'roles' => array(0 => 2), # Authenticated User
'user_website' => $user->user_website,
'user_from' => $user->user_from,
@@ -1090,7 +1074,7 @@ function phpbb2drupal_import_users() {
'user_occ' => $user->user_occ,
'user_interests' => $user->user_interest
);
- if (variable_get('phpbb2drupal_import_pm', 0)){
+ if (variable_get('phpbb2drupal_import_pm', 0)) {
$data['privatemsg_allow'] = 1;
}
@@ -1111,27 +1095,25 @@ function phpbb2drupal_import_users() {
db_set_active('default');
variable_set('phpbb2drupal_import_user_successful', '1');
- $count = db_result(db_query("SELECT COUNT(*) FROM {phpbb2drupal_temp_user}"));
+ $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user}'));
drupal_set_message(t('Successfully Imported %count Users', array('%count' => $count)));
}
/**
- *
* Create Forum Containers and Forums
- *
*/
function phpbb2drupal_import_categories() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
// check if the forum database has been successfully imported
db_set_active('default');
- if(variable_get('phpbb2drupal_import_category_successful', 0)) {
+ if (variable_get('phpbb2drupal_import_category_successful', 0)) {
drupal_set_message(t('Categories already imported successfully'));
return;
}
// forum mapping temporary tables
- if(variable_get('phpbb2drupal_import_category_started', 0) == 0) {
+ if (variable_get('phpbb2drupal_import_category_started', 0) == 0) {
db_set_active('default');
//db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}');
//db_query("CREATE TABLE {phpbb2drupal_temp_forum} ( forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL, tid integer UNSIGNED DEFAULT '0' NOT NULL, KEY forum_id (forum_id))");
@@ -1151,13 +1133,13 @@ function phpbb2drupal_import_categories(
$forum_count = 0;
- while($category_result = db_fetch_array($category_results)) {
+ while ($category_result = db_fetch_array($category_results)) {
$cat_id = $category_result['cat_id'];
$forums_results = db_query('SELECT * FROM %sforums WHERE cat_id = %d', $pre, $cat_id);
$forum_count += db_num_rows($forums_results);
$phpbb2_forums = array(); # reinitialize the temp var not to include it multiple times
- while($forum_result = db_fetch_object($forums_results)) {
+ while ($forum_result = db_fetch_object($forums_results)) {
//$phpbb2_categories[$category_result->cat_id]['forums'][] = $forums_result;
$phpbb2_forums[$forum_result->forum_id] = $forum_result;
}
@@ -1172,7 +1154,7 @@ function phpbb2drupal_import_categories(
// Insert the Containers
$container_order = -10;
- foreach($phpbb2_categories as $container) {
+ foreach ($phpbb2_categories as $container) {
$edit = array(
'name' => $container['cat_title'],
'vid' => $forum_vid,
@@ -1190,9 +1172,9 @@ function phpbb2drupal_import_categories(
// Insert the Forums
$forum_order = -10;
- foreach($container['forums'] as $forum) {
+ foreach ($container['forums'] as $forum) {
// Make sure the forum/term is has not already been imported
- if(!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum->forum_id))) {
+ if (!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum->forum_id))) {
$forum_edit = array(
'name' => $forum->forum_name,
'vid' => $forum_vid,
@@ -1209,7 +1191,7 @@ function phpbb2drupal_import_categories(
$tid = $forum_edit['tid'];
db_set_active('default');
- db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)',$forum->forum_id, $tid);
+ db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)', $forum->forum_id, $tid);
}
}
@@ -1225,23 +1207,21 @@ function phpbb2drupal_import_categories(
}
/**
- *
* Imports PHPBB topics to Drupal equivalent forum nodes
- *
*/
function phpbb2drupal_import_topics() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
$input_format = variable_get('phpbb2drupal_input_format', 0);
// check if the post database has been successfully imported
db_set_active('default');
- if(variable_get('phpbb2drupal_import_topic_successful', 0)) {
+ if (variable_get('phpbb2drupal_import_topic_successful', 0)) {
drupal_set_message(t('Topics already imported successfully'));
return;
}
- if(!variable_get('phpbb2drupal_import_topic_started', 0)) {
+ if (!variable_get('phpbb2drupal_import_topic_started', 0)) {
db_set_active('default');
//db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}');
//db_query("CREATE TABLE {phpbb2drupal_temp_topic} ( topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, nid integer UNSIGNED DEFAULT '0' NOT NULL, KEY topic_id (topic_id))");
@@ -1260,12 +1240,12 @@ function phpbb2drupal_import_topics() {
// Import the topics into drupal
$counter = 0;
db_set_active('phpbb');
- while($result = db_fetch_object($topic_ids)) {
+ while ($result = db_fetch_object($topic_ids)) {
// check if this topic has been imported already just to be sure
db_set_active('default');
$count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $result->topic_id));
- if($count > 0) {
+ if ($count > 0) {
#print "Topic $result->topic_id has already been imported
";
#flush();
db_set_active('phpbb');
@@ -1289,9 +1269,10 @@ function phpbb2drupal_import_topics() {
AND t.topic_id = %d',$pre, $pre, $pre, $result->topic_id);
// check if the topic is a valid topic. if not, continue on
- if(db_num_rows($query)) {
+ if (db_num_rows($query)) {
$topic = db_fetch_object($query);
- } else {
+ }
+ else {
drupal_set_message(t('Could not find post details of topic: %topic_id', array('%topic_id' => $result->topic_id)));
continue;
}
@@ -1300,27 +1281,31 @@ function phpbb2drupal_import_topics() {
$uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
$tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
- if($topic->topic_poster == 2) { // is the admin
- $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user','')));
+ if ($topic->topic_poster == 2) { // is the admin
+ $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
$uid = $user->uid;
- } elseif($topic->topic_poster == -1) {
+ }
+ else if ($topic->topic_poster == -1) {
$uid = 0;
}
- if($topic->topic_type == 1) {
+ if ($topic->topic_type == 1) {
$sticky = 1; // sticky
$promote = 0;
- } elseif ($topic->topic_type == 2) {
+ }
+ else if ($topic->topic_type == 2) {
$sticky = 1;
$promote = 0; // display on the front page, i.e. promote
- } else {
+ }
+ else {
$sticky = 0;
$promote = 0;
}
if ($topic->topic_status == 1) { // LOCKED
$comment = 1; // read-only
- } else { // UNLOCKED & WATCH NOTIFIED
+ }
+ else { // UNLOCKED & WATCH NOTIFIED
$comment = 2; // read-write
}
@@ -1349,14 +1334,15 @@ function phpbb2drupal_import_topics() {
);
$node['title'] = _phpbb2drupal_text_encode($node['title']);
- if($topic->topic_status == 2) {
+ if ($topic->topic_status == 2) {
db_set_active('phpbb');
- $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d',$pre, $topic->topic_moved_id));
+ $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
db_set_active('default');
$moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
$node['tid'] = $moved_tid; // which forum it used to be part of
- } else {
+ }
+ else {
$node['tid'] = $tid;
}
@@ -1366,13 +1352,13 @@ function phpbb2drupal_import_topics() {
node_save($node);
taxonomy_node_save($node->nid, array($tid));
- if(!$node->nid) {
+ if (!$node->nid) {
drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
}
// Handle attachments
- if($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
- if($topic->topic_attachment == 1) {
+ if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
+ if ($topic->topic_attachment == 1) {
db_set_active('default');
$file_path = variable_get('file_directory_path', 'files');
@@ -1385,10 +1371,10 @@ function phpbb2drupal_import_topics() {
WHERE p.topic_id = %d
ORDER BY a.attach_id', $pre, $pre, $pre, $topic->topic_id);
- while($file = db_fetch_object($files)) {
+ while ($file = db_fetch_object($files)) {
db_set_active('default');
$fid = db_next_id('{files}_fid');
- db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, $node->nid, substr($file->real_filename0,255), substr("$file_path/$file->physical_filename",0,255), substr($file->mimetype,0,255), $file->filesize);
+ db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, $node->nid, substr($file->real_filename0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
db_set_active('phpbb');
}
}
@@ -1398,7 +1384,7 @@ function phpbb2drupal_import_topics() {
db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
db_set_active('phpbb');
- } // while($result = db_fetch_object($topic_ids))
+ } // while ($result = db_fetch_object($topic_ids))
db_set_active('default');
// set the topic import successful flag in the variable table
@@ -1412,17 +1398,17 @@ function phpbb2drupal_import_topics() {
* Imports phpBB polls into drupal
*/
function phpbb2drupal_import_polls() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$input_format = variable_get('phpbb2drupal_input_format', 0);
db_set_active('default');
// check if the poll database has been successfully imported
- if(variable_get('phpbb2drupal_import_polls_successful', 0)) {
+ if (variable_get('phpbb2drupal_import_polls_successful', 0)) {
drupal_set_message(t('Polls already imported successfully'));
return;
}
- if(!variable_get('phpbb2drupal_import_polls_started', 0)) {
+ if (!variable_get('phpbb2drupal_import_polls_started', 0)) {
variable_set('phpbb2drupal_import_poll_started', 1);
}
@@ -1433,12 +1419,12 @@ function phpbb2drupal_import_polls() {
drupal_set_message(t('Found %poll_count polls: Beginning Import', array('%poll_count' => $topic_count)));
// insert into polls
- while($topic = db_fetch_object($topics)) {
+ while ($topic = db_fetch_object($topics)) {
// check if this topic has been imported already just to be sure
db_set_active('default');
- $count = db_result(db_query("SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d", $topic->topic_id));
- if($count > 0) {
+ $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $topic->topic_id));
+ if ($count > 0) {
drupal_set_message(t('Poll %topic_id has already been imported', array('%topic_id' => $result->topic_id)));
db_set_active('phpbb');
continue;
@@ -1448,9 +1434,10 @@ function phpbb2drupal_import_polls() {
db_set_active('phpbb');
$query = db_query('SELECT * FROM %svote_desc vd WHERE topic_id = %d ORDER BY vote_id', $pre, $topic->topic_id);
- if(db_num_rows($query)) {
+ if (db_num_rows($query)) {
$poll = db_fetch_object($query);
- } else {
+ }
+ else {
drupal_set_message(t('Could not find details of poll: %topic_id', array('%topic_id' => $topic->topic_id)));
continue;
}
@@ -1458,15 +1445,16 @@ function phpbb2drupal_import_polls() {
// get vote results
$query = db_query('SELECT * FROM %svote_results WHERE vote_id = %d ORDER BY vote_option_id', $pre, $poll->vote_id);
- if(db_num_rows($query)) {
+ if (db_num_rows($query)) {
$choice = array();
- while($result = db_fetch_object($query)) {
+ while ($result = db_fetch_object($query)) {
$choice[] = array(
'chtext' => _phpbb2drupal_text_encode($result->vote_option_text),
'chvotes' => _phpbb2drupal_text_encode($result->vote_result),
);
}
- } else {
+ }
+ else {
drupal_set_message(t('Could not find vote_results details of poll: %vote_id', array('%vote_id' => $poll->vote_id)));
continue;
}
@@ -1475,27 +1463,31 @@ function phpbb2drupal_import_polls() {
$uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
$tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
- if($topic->topic_poster == 2) { // is the admin
- $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user','')));
+ if ($topic->topic_poster == 2) { // is the admin
+ $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
$uid = $user->uid;
- } elseif($topic->topic_poster == -1) {
+ }
+ else if ($topic->topic_poster == -1) {
$uid = 0;
}
- if($topic->topic_type == 1) {
+ if ($topic->topic_type == 1) {
$sticky = 1; // sticky
$promote = 0;
- } elseif ($topic->topic_type == 2) {
+ }
+ else if ($topic->topic_type == 2) {
$sticky = 0;
$promote = 1; // display on the front page, i.e. promote
- } else {
+ }
+ else {
$sticky = 0;
$promote = 0;
}
if ($topic->topic_status == 1) { // LOCKED
$comment = 1; // read-only
- } else { // UNLOCKED & WATCH NOTIFIED
+ }
+ else { // UNLOCKED & WATCH NOTIFIED
$comment = 2; // read-write
}
@@ -1519,20 +1511,21 @@ function phpbb2drupal_import_polls() {
// handle moved nodes
- if($topic->topic_status == 2) {
+ if ($topic->topic_status == 2) {
db_set_active('phpbb');
- $forum_id = db_result(db_query("SELECT forum_id FROM %stopics WHERE topic_id = %d", $pre, $topic->topic_moved_id));
+ $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
db_set_active('default');
- $moved_tid = db_result(db_query("SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d", $forum_id));
+ $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
$node['tid'] = $moved_tid; // which forum it used to be part of
- } else {
+ }
+ else {
$node['tid'] = $tid;
}
// Add poll node information
$node['runtime'] = $poll->vote_length;
- $node['active'] = (time() > ($poll->start+$poll->length)) ? 0 : 1;
+ $node['active'] = (time() > ($poll->start + $poll->length)) ? 0 : 1;
$node['choice'] = $choice;
$node = (object)$node; // node_save requires an object form
@@ -1541,8 +1534,8 @@ function phpbb2drupal_import_polls() {
node_save($node);
taxonomy_node_save($node->nid, array($tid));
- if(!$node->nid) {
- drupal_set_message("Failed importing $topic->topic_id");
+ if (!$node->nid) {
+ drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
}
@@ -1551,9 +1544,9 @@ function phpbb2drupal_import_polls() {
$query = db_query('SELECT vote_user_id FROM %svote_voters WHERE vote_id = %d ORDER BY vote_id', $pre, $poll->vote_id);
// manually update the poll table to store the uid of those who voted
- if(db_num_rows($query)) {
+ if (db_num_rows($query)) {
db_set_active('phpbb');
- while($result = db_fetch_object($query)) {
+ while ($result = db_fetch_object($query)) {
db_set_active('default');
$uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $result->vote_user_id));
$result = db_query('INSERT INTO {poll_votes} (nid, uid, hostname) VALUES (%d, %d, \'NA\')', $node->nid, $uid);
@@ -1577,22 +1570,20 @@ function phpbb2drupal_import_polls() {
}
/**
- *
* PHPBB Posts --> Drupal Comments
- *
*/
function phpbb2drupal_import_posts() {
- $pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
$PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
db_set_active('default');
// check if the post database has been successfully imported
- if(variable_get('phpbb2drupal_import_post_successful', 0)) {
+ if (variable_get('phpbb2drupal_import_post_successful', 0)) {
drupal_set_message(t('Posts already imported successfully'));
return;
}
- if(!variable_get('phpbb2drupal_import_post_started', 0)) {
+ if (!variable_get('phpbb2drupal_import_post_started', 0)) {
db_set_active('default');
//db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_post}');
/*db_query("CREATE TABLE {phpbb2drupal_temp_post} (
@@ -1617,22 +1608,23 @@ function phpbb2drupal_import_posts() {
$errors = 0;
$loops = 0;
// Import the posts into drupal
- while($obj = db_fetch_object($topic_ids)) {
+ while ($obj = db_fetch_object($topic_ids)) {
$loops++;
// skip first post if the post is not a poll
// stupid phpbb... make the way you store topics consistent for crying out loud
db_set_active('phpbb');
- if($obj->topic_vote == 0) {
+ if ($obj->topic_vote == 0) {
$post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d AND post_id <> %d ORDER BY post_id',
$pre, $obj->topic_id, $obj->topic_first_post_id);
- } else {
+ }
+ else {
$post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d ORDER BY post_id', $pre, $obj->topic_id);
}
unset($obj);
- while($result = db_fetch_object($post_ids)) {
+ while ($result = db_fetch_object($post_ids)) {
$loops++;
db_set_active('phpbb');
@@ -1644,9 +1636,10 @@ function phpbb2drupal_import_posts() {
$pre, $pre, $result->post_id);
// make sure the post is valid
- if(db_num_rows($query)) {
+ if (db_num_rows($query)) {
$post = db_fetch_object($query);
- } else {
+ }
+ else {
$errors++;
drupal_set_message(t("Couldn't find post text for %post_id", array('%post_id' => $result->post_id)));
continue;
@@ -1654,8 +1647,8 @@ function phpbb2drupal_import_posts() {
// skip if the post has already been imported
db_set_active('default');
- $count = db_result(db_query("SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d", $post->post_id));
- if($count > 0) {
+ $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post->post_id));
+ if ($count > 0) {
$errors++;
drupal_set_message(t('Post %post_id was already inserted', array('%post_id' => $post->post_id)));
db_set_active('phpbb');
@@ -1663,18 +1656,19 @@ function phpbb2drupal_import_posts() {
}
db_set_active('default');
- $uid = db_result(db_query("SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d", $post->poster_id));
- $pid = db_result(db_query("SELECT MAX(pid) FROM {comments} WHERE nid = %d", $nid));
+ $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $post->poster_id));
+ $pid = db_result(db_query('SELECT MAX(pid) FROM {comments} WHERE nid = %d', $nid));
// get the node ID. The title may be useful further down if the comment doesn't have its own title.
- $node = (db_fetch_object(db_query("SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid WHERE topic_id = %d", $post->topic_id)));
+ $node = (db_fetch_object(db_query('SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid WHERE topic_id = %d', $post->topic_id)));
$nid = $node->nid;
$pid = (is_null($pid)) ? 0 : $pid;
- if($post->poster_id == 2) { // is the admin
- $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user','')));
+ if ($post->poster_id == 2) { // is the admin
+ $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
$uid = $user->uid;
- } elseif($post->poster_id == -1) { // anonymous
+ }
+ else if ($post->poster_id == -1) { // anonymous
$uid = 0;
}
@@ -1682,7 +1676,7 @@ function phpbb2drupal_import_posts() {
// remove the :bbcode_uid from post_text
$post->post_text = preg_replace("/:$post->bbcode_uid/", '', $post->post_text);
- $post->post_text = _phpbb2drupal_strip_bbcode ($post->post_text);
+ $post->post_text = _phpbb2drupal_strip_bbcode($post->post_text);
$post->post_text = _phpbb2drupal_text_encode($post->post_text);
$post->post_subject = _phpbb2drupal_text_encode($post->post_subject);
@@ -1705,14 +1699,14 @@ function phpbb2drupal_import_posts() {
db_set_active('default');
$cid = phpbb2drupal_comment_save($comment);
- if(!$cid) {
+ if (!$cid) {
$errors++;
drupal_set_message(t('Failed importing %post_id', array('%post_id' => $post->post_id)));
}
// Handle attachments
- if($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
- if($post->post_attachment == 1) {
+ if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
+ if ($post->post_attachment == 1) {
db_set_active('default');
$file_path = variable_get('file_directory_path', 'files');
@@ -1720,10 +1714,10 @@ function phpbb2drupal_import_posts() {
$files = db_query('SELECT * FROM %sattachments a INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id WHERE a.post_id = %d',
$pre, $pre, $post->post_id);
- while($file = db_fetch_object($files)) {
+ while ($file = db_fetch_object($files)) {
db_set_active('default');
$fid = db_next_id('{files}_fid');
- db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, 0, substr($file->real_filename,0,255), substr("$file_path/$file->physical_filename",0,255), substr($file->mimetype,0,255), $file->filesize);
+ db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, 0, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
db_query('INSERT INTO {comment_files} (cid, fid) VALUES (%d, %d)', $cid, $fid);
db_set_active('phpbb');
}
@@ -1741,92 +1735,88 @@ function phpbb2drupal_import_posts() {
db_set_active('default');
variable_set('phpbb2drupal_import_post_successful', '1');
drupal_set_message(t('Successfully Imported %imported posts', array('%imported' => $imported)));
- drupal_set_message(t('"The were %loops loops executed', array('%loops' => $loops)));
+ drupal_set_message(t('The were %loops loops executed', array('%loops' => $loops)));
drupal_set_message(t('There %errors errors while importing posts', array('%errors' => $errors)));
}
/**
- *
* Clean UP
- *
*/
function phpbb2drupal_import_cleanup() {
-$pre = variable_get('phpbb2drupal_table_prefix','phpbb_');
+ $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-#
-# Update Drupal sequence
-#
- db_set_active('default');
- $term_data_tid = db_result(db_query("SELECT MAX(tid) FROM {term_data}"));
- $comments_cid = db_result(db_query("SELECT MAX(cid) FROM {comments}"));
- $node_nid = db_result(db_query("SELECT MAX(nid) FROM {node}"));
- $users_uid = db_result(db_query("SELECT MAX(uid) FROM {users}"));
-
- db_query("DELETE FROM {sequences} WHERE name='term_data_tid'");
- db_query("DELETE FROM {sequences} WHERE name='comments_cid'");
- db_query("DELETE FROM {sequences} WHERE name='node_nid'");
- db_query("DELETE FROM {sequences} WHERE name='users_uid'");
-
- db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', $term_data_tid)");
- db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', $comments_cid)");
- db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', $node_nid)");
- db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', $users_uid)");
-
- if(variable_get('phpbb2drupal_import_attachments', 0)) {
- $files_fid = db_result(db_query("SELECT MAX(fid) FROM {files}"));
- if (!$files_fid ) { //may be NULL
- $files_fid = 0;
- }
- db_query("DELETE FROM {sequences} WHERE name='files_fid'");
- db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', $files_fid)");
+ #
+ # Update Drupal sequence
+ #
+ db_set_active('default');
+ $term_data_tid = db_result(db_query('SELECT MAX(tid) FROM {term_data}'));
+ $comments_cid = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
+ $node_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
+ $users_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
+
+ db_query("DELETE FROM {sequences} WHERE name='term_data_tid'");
+ db_query("DELETE FROM {sequences} WHERE name='comments_cid'");
+ db_query("DELETE FROM {sequences} WHERE name='node_nid'");
+ db_query("DELETE FROM {sequences} WHERE name='users_uid'");
+
+ db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', '%s')", $term_data_tid);
+ db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', '%s')", $comments_cid);
+ db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', '%s')", $node_nid);
+ db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', '%s')", $users_uid);
+
+ if (variable_get('phpbb2drupal_import_attachments', 0)) {
+ $files_fid = db_result(db_query('SELECT MAX(fid) FROM {files}'));
+ if (!$files_fid) { //may be NULL
+ $files_fid = 0;
}
-
- // don't DROP: the data is used for redirects from old forum.
- #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_user}");
- #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}");
- #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}");
- #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_post}");
-
- variable_del('phpbb2drupal_import_user_successful');
- variable_del('phpbb2drupal_import_user_started');
- variable_del('phpbb2drupal_import_category_successful');
- variable_del('phpbb2drupal_replace_url_successful');
- variable_del('phpbb2drupal_import_category_started');
- variable_del('phpbb2drupal_import_topic_successful');
- variable_del('phpbb2drupal_import_topic_started');
- variable_del('phpbb2drupal_import_post_successful');
- variable_del('phpbb2drupal_import_post_started');
- variable_del('phpbb2drupal_ready');
- variable_del('phpbb2drupal_regdate_us_english');
- variable_del('phpbb2drupal_input_format');
- variable_del('phpbb2drupal_db_url');
- variable_del('phpbb2drupal_tested');
- variable_del('phpbb2drupal_same_db');
- variable_del('phpbb2drupal_table_prefix');
- variable_del('phpbb2drupal_time_limit');
- variable_del('phpbb2drupal_import_spammers');
- variable_del('phpbb2drupal_import_attachments');
- variable_del('phpbb2drupal_import_polls');
- variable_del('phpbb2drupal_import_pm');
- variable_del('phpbb2drupal_import_poll_started');
- variable_del('phpbb2drupal_import_poll_successful');
- variable_del('phpbb2drupal_import_pm_successful');
- variable_del('phpbb2drupal_admin_user');
- variable_del('phpbb2drupal_encode');
- variable_del('phpbb2drupal_encoding_phpbb');
- variable_del('phpbb2drupal_encoding_drupal');
+ db_query("DELETE FROM {sequences} WHERE name='files_fid'");
+ db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', '%s')", $files_fid);
+ }
+
+ // don't DROP: the data is used for redirects from old forum.
+ #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_user}");
+ #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}");
+ #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}");
+ #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_post}");
+
+ variable_del('phpbb2drupal_import_user_successful');
+ variable_del('phpbb2drupal_import_user_started');
+ variable_del('phpbb2drupal_import_category_successful');
+ variable_del('phpbb2drupal_replace_url_successful');
+ variable_del('phpbb2drupal_import_category_started');
+ variable_del('phpbb2drupal_import_topic_successful');
+ variable_del('phpbb2drupal_import_topic_started');
+ variable_del('phpbb2drupal_import_post_successful');
+ variable_del('phpbb2drupal_import_post_started');
+ variable_del('phpbb2drupal_ready');
+ variable_del('phpbb2drupal_regdate_us_english');
+ variable_del('phpbb2drupal_input_format');
+ variable_del('phpbb2drupal_db_url');
+ variable_del('phpbb2drupal_tested');
+ variable_del('phpbb2drupal_same_db');
+ variable_del('phpbb2drupal_table_prefix');
+ variable_del('phpbb2drupal_time_limit');
+ variable_del('phpbb2drupal_import_spammers');
+ variable_del('phpbb2drupal_import_attachments');
+ variable_del('phpbb2drupal_import_polls');
+ variable_del('phpbb2drupal_import_pm');
+ variable_del('phpbb2drupal_import_poll_started');
+ variable_del('phpbb2drupal_import_poll_successful');
+ variable_del('phpbb2drupal_import_pm_successful');
+ variable_del('phpbb2drupal_admin_user');
+ variable_del('phpbb2drupal_encode');
+ variable_del('phpbb2drupal_encoding_phpbb');
+ variable_del('phpbb2drupal_encoding_drupal');
- db_query('DELETE FROM {cache}');
+ db_query('DELETE FROM {cache}');
}
/**
- *
* Helper Functions
- *
*/
function phpbb2drupal_user_save($phpBB_user, $category = array()) {
- if(!($user = user_load(array('name' => $phpBB_user['name'])))) {
+ if (!($user = user_load(array('name' => $phpBB_user['name'])))) {
$account = new StdClass();
$account->uid = FALSE;
$user = user_save($account, $phpBB_user);
@@ -1835,7 +1825,7 @@ function phpbb2drupal_user_save($phpBB_u
$user = user_save($user, array('created' => $phpBB_user['created']));
// Update the password: just import the md5() hash straight into Drupal without
// passing through the Drupal function user_save() which would re-hash the hash.
- $result = db_query('UPDATE {users} SET pass = \'%s\' WHERE uid = %d', $phpBB_user['pass'], $user->uid);
+ $result = db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $phpBB_user['pass'], $user->uid);
}
$phpBB_user['uid'] = $user->uid;
@@ -1846,7 +1836,6 @@ function phpbb2drupal_user_save($phpBB_u
}
function phpbb2drupal_profile_save_profile(&$edit, &$user, $category) {
-
$result = db_query('SELECT fid, name, type, category, weight FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
while ($field = db_fetch_object($result)) {
@@ -1856,128 +1845,135 @@ function phpbb2drupal_profile_save_profi
db_query('DELETE FROM {profile_values} WHERE fid = %d AND uid = %d', $field->fid, $user->uid);
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]);
// Mark field as handled (prevents saving to user->data).
- $edit[$field->name] = null;
+ $edit[$field->name] = NULL;
}
}
function phpbb2drupal_comment_save($edit) {
- db_set_active('default');
- // Here we are building the thread field. See the comment
- // in comment_render().
- if ($edit['pid'] == 0) {
- // This is a comment with no parent comment (depth 0): we start
- // by retrieving the maximum thread level.
- $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
-
- // Strip the "/" from the end of the thread.
- $max = rtrim($max, '/');
-
- // Next, we increase this value by one. Note that we can't
- // use 1, 2, 3, ... 9, 10, 11 because we order by string and
- // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
- // 92, 93, ... instead. Ugly but fast.
- $decimals = (string) substr($max, 0, strlen($max) - 1);
- $units = substr($max, -1, 1);
- if ($units) {
- $units++;
- }
- else {
- $units = 1;
- }
-
- if ($units == 10) {
- $units = '90';
- }
-
- // Finally, build the thread field for this new comment.
- $thread = $decimals . $units .'/';
+ db_set_active('default');
+ // Here we are building the thread field. See the comment
+ // in comment_render().
+ if ($edit['pid'] == 0) {
+ // This is a comment with no parent comment (depth 0): we start
+ // by retrieving the maximum thread level.
+ $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
+
+ // Strip the "/" from the end of the thread.
+ $max = rtrim($max, '/');
+
+ // Next, we increase this value by one. Note that we can't
+ // use 1, 2, 3, ... 9, 10, 11 because we order by string and
+ // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
+ // 92, 93, ... instead. Ugly but fast.
+ $decimals = (string) substr($max, 0, strlen($max) - 1);
+ $units = substr($max, -1, 1);
+ if ($units) {
+ $units++;
}
else {
- // This is comment with a parent comment: we increase
- // the part of the thread value at the proper depth.
+ $units = 1;
+ }
- // Get the parent comment:
- $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid']));
+ if ($units == 10) {
+ $units = '90';
+ }
- // Strip the "/" from the end of the parent thread.
- $parent->thread = (string) rtrim((string) $parent->thread, '/');
+ // Finally, build the thread field for this new comment.
+ $thread = $decimals . $units .'/';
+ }
+ else {
+ // This is comment with a parent comment: we increase
+ // the part of the thread value at the proper depth.
- // Get the max value in _this_ thread.
- $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
+ // Get the parent comment:
+ $parent = db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $edit['pid']));
- if ($max == '') {
- // First child of this parent.
- $thread = $parent->thread .'.1/';
- }
- else {
- // Strip the "/" at the end of the thread.
- $max = rtrim($max, '/');
+ // Strip the "/" from the end of the parent thread.
+ $parent->thread = (string) rtrim((string) $parent->thread, '/');
- // We need to get the value at the correct depth.
- $parts = explode('.', $max);
- $parent_depth = count(explode('.', $parent->thread));
- $last = $parts[$parent_depth];
+ // Get the max value in _this_ thread.
+ $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
- // Next, we increase this value by one. Note that we can't
- // use 1, 2, 3, ... 9, 10, 11 because we order by string and
- // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
- // 92, 93, ... instead. Ugly but fast.
- $decimals = (string)substr($last, 0, strlen($last) - 1);
- $units = substr($last, -1, 1);
- $units++;
- if ($units == 10) {
- $units = '90';
- }
-
- // Finally, build the thread field for this new comment.
- $thread = $parent->thread .'.'. $decimals . $units .'/';
- }
+ if ($max == '') {
+ // First child of this parent.
+ $thread = $parent->thread .'.1/';
}
+ else {
+ // Strip the "/" at the end of the thread.
+ $max = rtrim($max, '/');
+
+ // We need to get the value at the correct depth.
+ $parts = explode('.', $max);
+ $parent_depth = count(explode('.', $parent->thread));
+ $last = $parts[$parent_depth];
+
+ // Next, we increase this value by one. Note that we can't
+ // use 1, 2, 3, ... 9, 10, 11 because we order by string and
+ // 10 would be right after 1. We use 1, 2, 3, ..., 9, 91,
+ // 92, 93, ... instead. Ugly but fast.
+ $decimals = (string)substr($last, 0, strlen($last) - 1);
+ $units = substr($last, -1, 1);
+ $units++;
+ if ($units == 10) {
+ $units = '90';
+ }
+
+ // Finally, build the thread field for this new comment.
+ $thread = $parent->thread .'.'. $decimals . $units .'/';
+ }
+ }
- $edit['cid'] = db_next_id('{comments}_cid');
+ $edit['cid'] = db_next_id('{comments}_cid');
- $status = 0; // 1 - not published, 0 - published
- $format = variable_get('phpbb2drupal_input_format', 0);
- $score = 0; // 0 default value, comments get higher score depending on the author's roles
- $users = serialize(array(0 => 1)); // default value for everybody!!
+ $status = 0; // 1 - not published, 0 - published
+ $format = variable_get('phpbb2drupal_input_format', 0);
+ $score = 0; // 0 default value, comments get higher score depending on the author's roles
+ $users = serialize(array(0 => 1)); // default value for everybody!!
- db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], substr($edit['subject'],0,64), $edit['comment'], $format, substr($edit['hostname'],0,128), $edit['timestamp'], $status, $score, $users, substr($thread,0,255), substr($edit['name'],0,60), substr($edit['mail'],0,64), substr($edit['homepage'],0,255));
+ db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], substr($edit['subject'], 0, 64), $edit['comment'], $format, substr($edit['hostname'], 0, 128), $edit['timestamp'], $status, $score, $users, substr($thread, 0, 255), substr($edit['name'], 0, 60), substr($edit['mail'], 0, 64), substr($edit['homepage'], 0, 255));
- _comment_update_node_statistics($edit['nid']);
+ _comment_update_node_statistics($edit['nid']);
- return $edit['cid'];
+ return $edit['cid'];
}
-// function for inserting polls into drupal
+/**
+ * function for inserting polls into drupal
+ */
function phpbb2_drupal_poll_insert($node) {
if (!variable_get('phpbb2drupal_import_polls', 0)) {
return 1;
}
- if (!user_access('administer nodes')) {
- // Make sure all votes are 0 initially
- foreach ($node->choice as $i => $choice) {
- $node->choice[$i]['chvotes'] = 0;
- }
- $node->active = 1;
+
+ if (!user_access('administer nodes')) {
+ // Make sure all votes are 0 initially
+ foreach ($node->choice as $i => $choice) {
+ $node->choice[$i]['chvotes'] = 0;
}
+ $node->active = 1;
+ }
- db_query("INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active);
+ db_query('INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)', $node->nid, $node->runtime, $node->active);
- foreach ($node->choice as $choice) {
- if ($choice['chtext'] != '') {
- db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, substr($choice['chtext'],0,128), $choice['chvotes'], $i++);
- }
+ foreach ($node->choice as $choice) {
+ if ($choice['chtext'] != '') {
+ db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, substr($choice['chtext'], 0, 128), $choice['chvotes'], $i++);
}
+ }
}
-// PHPBB function for decoding the user ip
+/**
+ * PHPBB function for decoding the user ip
+ */
function phpbb2drupal_decode_ip($int_ip) {
$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}
-//If requested, strips all bbcode from text.
-function _phpbb2drupal_strip_bbcode ($text) {
+/**
+ * If requested, strips all bbcode from text.
+ */
+function _phpbb2drupal_strip_bbcode($text) {
if (variable_get('phpbb2drupal_bbcode', 0)) {
$input_format = variable_get('phpbb2drupal_input_format', 0);
$text = bbcode_filter('process', 0 , $input_format, $text);
@@ -1986,9 +1982,11 @@ function _phpbb2drupal_strip_bbcode ($te
}
-// function to properly encode strings.
-function _phpbb2drupal_text_encode ($text) {
- if(!variable_get('phpbb2drupal_encode', 0)) {
+/**
+ * function to properly encode strings.
+ */
+function _phpbb2drupal_text_encode($text) {
+ if (!variable_get('phpbb2drupal_encode', 0)) {
return $text;
}
$text = mb_convert_encoding($text, variable_get('phpbb2drupal_encoding_drupal', 'utf-8'), variable_get('phpbb2drupal_encoding_phpbb', 'iso-8859-1'));
@@ -1998,38 +1996,45 @@ function _phpbb2drupal_text_encode ($tex
// grep replace functions.
function _phpbb2drupal_replace_links_topic($matches) {
- //print_r ($matches);
+ //print_r($matches);
$result = db_result(db_query('SELECT nid FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $matches[1]));
$link = 'node/'. $result . $matches[2];
return $link;
}
+
function _phpbb2drupal_replace_links_post($matches) {
- //print_r ($matches);
+ //print_r($matches);
$result = db_fetch_object(db_query('SELECT c.cid, c.nid FROM {phpbb2drupal_temp_post} p JOIN {comments} c ON c.cid = p.cid WHERE post_id = %d', $matches[1]));
$link = 'node/'. $result->nid . '#comment-' . $result->cid . $matches[3];
return $link;
}
+
function _phpbb2drupal_replace_links_forum($matches) {
- //print_r ($matches);
+ //print_r($matches);
$result = db_fetch_object(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $matches[1]));
$link = 'forum/'. $result->tid . $matches[2] ;
return $link;
}
-// function replace all types of links.
+/**
+ * Replace all types of links.
+ */
function _phpbb2drupal_replace_links($html) {
- $html = preg_replace_callback("{forum/viewtopic.php\?p=(\d+)#(\d+)[^\"|'|>|<|\s]*([\"|'|>|<|\s|\\|"])}i", "_phpbb2drupal_replace_links_post", $html);
- $html = preg_replace_callback("{forum/viewtopic.php\?t=(\d+)[^\"|'|>|<|\s]*([\"|'|>|<|\s|\\|"])}i", "_phpbb2drupal_replace_links_topic", $html);
- $html = preg_replace_callback("{forum/viewforum.php\?f=(\d+)[^\"|'|>|<|\s]*([\"|'|>|<|\s|\\|"])}i", "_phpbb2drupal_replace_links_forum", $html);
- $html = preg_replace("{forum/index.php[^\"|'|>|\s]*([\"|'|<|>|\s|\\|"])}i", "forum$1", $html);
+ $html = preg_replace_callback('{forum/viewtopic.php\?p=(\d+)#(\d+)[^"|\'|>|<|\s]*(["|\'|>|<|\s|\\|"])}i', '_phpbb2drupal_replace_links_post', $html);
+ $html = preg_replace_callback('{forum/viewtopic.php\?t=(\d+)[^"|\'|>|<|\s]*(["|\'|>|<|\s|\\|"])}i', '_phpbb2drupal_replace_links_topic', $html);
+ $html = preg_replace_callback('{forum/viewforum.php\?f=(\d+)[^"|\'|>|<|\s]*(["|\'|>|<|\s|\\|"])}i', '_phpbb2drupal_replace_links_forum', $html);
+ // TODO look at removing $1. it looks like dead code.
+ $html = preg_replace('{forum/index.php[^"|\'|>|\s]*(["|\'|<|>|\s|\\|"])}i', "forum$1", $html);
// You can use the line below to test locally the url's when you are testing:
//$html = preg_replace("{www.reuniting.info}i", "127.0.0.1/drupal", $html);
return $html;
}
-// Replace URLs to old phpBB forum to new Drupal forum
+/**
+ * Replace URLs to old phpBB forum to new Drupal forum
+ */
function phpbb2drupal_replace_url() {
db_set_active('default');
@@ -2040,14 +2045,14 @@ function phpbb2drupal_replace_url() {
while ($node = db_fetch_object($result)) {
$node->body = _phpbb2drupal_replace_links($node->body);
$node->teaser = _phpbb2drupal_replace_links($node->teaser);
- db_query('UPDATE {node_revisions} SET body= \'%s\', teaser = \'%s\' WHERE nid = %d', $node->body, $node->teaser, $node->nid);
+ db_query("UPDATE {node_revisions} SET body= '%s', teaser = '%s' WHERE nid = %d", $node->body, $node->teaser, $node->nid);
}
// transform comments:
$result = db_query('SELECT c.cid, c.comment FROM {phpbb2drupal_temp_post} AS p LEFT JOIN {comments} AS c ON p.cid = c.cid');
while ($comment = db_fetch_object($result)) {
$comment->comment = _phpbb2drupal_replace_links($comment->comment);
- db_query('UPDATE {comments} SET comment= \'%s\' WHERE cid = %d', $comment->comment, $comment->cid);
+ db_query("UPDATE {comments} SET comment= '%s' WHERE cid = %d", $comment->comment, $comment->cid);
}
variable_set('phpbb2drupal_replace_url_successful', '1');