Index: joomla.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/joomla/joomla.info,v
retrieving revision 1.11
diff -u -p -r1.11 joomla.info
--- joomla.info 16 Jul 2008 04:01:11 -0000 1.11
+++ joomla.info 9 Jun 2009 08:39:39 -0000
@@ -1,7 +1,6 @@
; $Id: joomla.info,v 1.11 2008/07/16 04:01:11 thenicespider Exp $
name = Joomla
-description = "This module used for import Joomla to Drupal."
-package = Merdeka
-version = "5.x-2.1"
-project = "drupal"
-
+description = "This module is used for importing Joomla content into Drupal."
+dependencies[] = profile
+dependencies[] = taxonomy
+core = 6.x
Index: joomla.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/joomla/joomla.module,v
retrieving revision 1.14
diff -u -p -r1.14 joomla.module
--- joomla.module 17 Jul 2008 11:37:22 -0000 1.14
+++ joomla.module 9 Jun 2009 08:39:41 -0000
@@ -9,8 +9,8 @@
/**
* Implementation of hook_help().
*/
-function joomla_help($section) {
- switch ($section) {
+function joomla_help($path, $arg) {
+ switch ($path) {
case 'admin/help#joomla':
$output = "The joomla module used for migrate Joomla to Drupal.";
return $output;
@@ -30,24 +30,38 @@ function joomla_perm() {
* Menu callback. Prints a listing of active nodes on the site.
*/
-function joomla_menu($may_cache) {
+function joomla_menu() {
$items = array();
- $items[] = array(
- 'path' => 'joomla/import/'.arg(2),
- 'title' => t('Joomla'),
- 'callback' => 'joomla_import',
- 'callback arguments' => array(arg(2)),
- 'access' => user_access('administer joomla'),
+ $items['joomla/import/user'] = array(
+ 'title' => 'Joomla user import',
+ 'page callback' => 'joomla_import',
+ 'page arguments' => array('user'),
+ 'access arguments' => array('administer joomla'),
'type' => MENU_CALLBACK
);
- $items[] = array(
- 'path' => 'admin/settings/joomla',
+ $items['joomla/import/section'] = array(
+ 'title' => 'Joomla section import',
+ 'page callback' => 'joomla_import',
+ 'page arguments' => array('section'),
+ 'access arguments' => array('administer joomla'),
+ 'type' => MENU_CALLBACK
+ );
+
+ $items['joomla/import/content'] = array(
+ 'title' => 'Joomla content import',
+ 'page callback' => 'joomla_import',
+ 'page arguments' => array('content'),
+ 'access arguments' => array('administer joomla'),
+ 'type' => MENU_CALLBACK
+ );
+
+ $items['admin/settings/joomla'] = array(
'title' => 'Joomla to Drupal',
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('joomla_admin_settings'),
- 'access' => user_access('administer joomla'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('joomla_admin_settings'),
+ 'access arguments' => array('administer joomla'),
'description' => 'Migrate Joomla to Drupal.'
);
@@ -187,11 +201,9 @@ function joomla_import($import_type) {
return $output;
}
- //Add Realname to Profile
- $results_realname = db_query("SELECT name FROM {profile_fields} WHERE name='profile_realname'");
- if (!db_num_rows($results_realname)) {
- db_query(" INSERT INTO {profile_fields} (title,name,type,weight) VALUES "
- ." ('Real Name','profile_realname','textfield','0')");
+ //Add Realname to Profile
+ if(db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE name='profile_realname'")) == 0) {
+ db_query(" INSERT INTO {profile_fields} (title,name,type,weight) VALUES ('Real Name','profile_realname','textfield','0')");
}
$results_fid = db_query("SELECT fid from {profile_fields} WHERE name='profile_realname'");
$data_fid = db_fetch_object($results_fid);
@@ -199,10 +211,9 @@ function joomla_import($import_type) {
//Check Users
- $sql_text = " SELECT * FROM $table_user ORDER BY id";
$i = 0;
- $results_user = db_query($sql_text);
+ $results_user = db_query("SELECT * FROM %s ORDER BY id", $table_user);
while ( $data = db_fetch_object($results_user) ) {
$i++;
@@ -214,12 +225,12 @@ function joomla_import($import_type) {
$registerdate = strtotime($data->registerDate);
$lastvisitdate = strtotime($data->lastvisitDate);
- $results_check_user = db_query("SELECT uid,name FROM {users} WHERE name='$username'");
+ $results_check_user = db_query("SELECT uid,name FROM {users} WHERE name='%s'", $username);
$data_user = db_fetch_object($results_check_user);
$uid = $data_user->uid;
$rec_status = 'Exist';
- if (!db_num_rows($results_check_user)) {
+ if (!$data_user) {
$rec_status = 'New';
$sql_uid = " SELECT uid FROM {users} ORDER BY uid DESC LIMIT 1";
@@ -227,21 +238,16 @@ function joomla_import($import_type) {
$data_last_uid = db_fetch_object($results_last_uid);
$last_uid = $data_last_uid->uid;
$new_uid = $data_last_uid->uid + 1;
- //this is redundancy but need if the process not completed!
- update_sequences() ;
- $sql_insert = " INSERT INTO {users} (uid,name,mail,status,created,access,language,timezone) "
- ." values ('$new_uid','$username','$email','$status','$registerdate','$lastvisitdate','en',0)";
- db_query($sql_insert);
+ db_query("INSERT INTO {users} (uid,name,mail,status,created,access,language,timezone) values (%d,'%s','%s',%d,%d,%d,'en',0)", $new_uid, $username, $email, $status, $registerdate, $lastvisitdate);
}
//Check and Update Realname
- $results_profile_values = db_query("SELECT * FROM {profile_values} WHERE fid='$fid' AND uid='$uid'");
- if (!db_num_rows($results_profile_values)) {
- db_query("INSERT INTO {profile_values} (fid,uid,value) VALUES ('$fid','$uid','$realname')");
+ $results_profile_values = db_query("SELECT COUNT(*) FROM {profile_values} WHERE fid=%d AND uid=%d", $fid, $uid);
+ if (db_result($results_profile_values) == 0) {
+ db_query("INSERT INTO {profile_values} (fid,uid,value) VALUES (%d,%d,'%s')", $fid, $uid, $realname);
}
- update_sequences();
//delay
if ($i % $joomla_delay_row ==0 ) {sleep($joomla_delay_sec);}
@@ -262,76 +268,51 @@ function joomla_import($import_type) {
$output = "";
$output .= "
Import Joomla Sections and Categories
";
- $results_joomla_sec = db_query("SELECT * FROM $joomla_database.".$joomla_prefix."sections");
-
- $sql_text = "SELECT * FROM $joomla_database.".$joomla_prefix."sections";
- $results_joomla_sec = db_query($sql_text);
+ $results_joomla_sec = db_query("SELECT * FROM %s.%ssections", $joomla_database, $joomla_prefix);
$i = 1;
//Joomla Sections to Drupal
while ( $data = db_fetch_object($results_joomla_sec) ) {
$i++;
- //Required if process not completed!
- update_sequences();
//Get data
$sec_id = $data->id;
$sec_title = addslashes($data->title);
$sec_name = addslashes($data->name);
- $sql_check = "SELECT name FROM {vocabulary} WHERE name='$sec_title'";
- $results_check = db_query($sql_check);
+ $results_check = db_query("SELECT COUNT(*) FROM {vocabulary} WHERE name='%s'", $sec_title);
$rec_status = 'Exist';
//Insert Sections
- if (!db_num_rows($results_check)) {
+ if (db_result($results_check) == 0) {
$rec_status = 'New';
- $sql_insert = " INSERT INTO {vocabulary} (name,description,hierarchy,weight) "
- ." values ('$sec_title','$sec_name',1,0)";
- db_query($sql_insert);
+ db_query("INSERT INTO {vocabulary} (name,description,hierarchy,weight) values ('%s','%s',1,0)", $sec_title, $sec_name);
}
//Take Vocabulary ID
- $sql_vid = "SELECT vid FROM {vocabulary} WHERE name='$sec_title'";
- $results_vid = db_query($sql_vid);
- $data_vid = db_fetch_object($results_vid);
- $vid = $data_vid->vid;
+ $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE name='%s'", $sec_title));
//Retrieve and Insert categories
- $sql_cat = " SELECT id,title,name,section FROM $joomla_database.".$joomla_prefix."categories "
- ." WHERE section='$sec_id'";
- $results_cat = db_query($sql_cat);
+ $results_cat = db_query("SELECT id,title,name,section FROM %s.%scategories WHERE section='%s'", $joomla_database, $joomla_prefix, $sec_id);
while ( $data_cat = db_fetch_object($results_cat) ) {
$cat_id = $data_cat->id;
$cat_title = addslashes($data_cat->title);
$cat_name = addslashes($data_cat->name);
- //Check if cat exist on certain section
- $sql_check_cat = "SELECT name FROM {term_data} WHERE name='$cat_title' AND vid='$vid'";
- $results_check_cat = db_query($sql_check_cat);
-
- if (!db_num_rows($results_check_cat)) {
- $sql_insert_cat = " INSERT INTO {term_data} (vid,name,description,weight) "
- ." values ('$vid','$cat_title','$cat_name',0)";
- db_query($sql_insert_cat);
+ //Check if cat exist on certain section
+ if (db_result(db_query("SELECT COUNT(*) FROM {term_data} WHERE name='%s' AND vid=%d", $cat_title, $vid)) == 0) {
+ db_query("INSERT INTO {term_data} (vid,name,description,weight) values (%d,'%s','%s',0)", $vid, $cat_title, $cat_name);
- //Take Term ID
- $sql_tid = "SELECT tid FROM {term_data} WHERE vid='$vid' AND name='$cat_title'";
- $results_tid = db_query($sql_tid);
- $data_tid = db_fetch_object($results_tid);
- $tid = $data_tid->tid;
+ //Take Term ID
+ $tid = db_result(db_query("SELECT tid FROM {term_data} WHERE vid=%d AND name='%s'", $vid, $cat_title));
- $sql_insert_hierarchy = " INSERT INTO {term_hierarchy} (tid,parent) "
- ." values ('$tid','0')";
- db_query($sql_insert_hierarchy);
+ db_query("INSERT INTO {term_hierarchy} (tid,parent) values (%d,'0')", $tid);
}
}
- //Update id
- update_sequences();
if ($i % $joomla_delay_row ==0 ) {sleep($joomla_delay_sec);}
}
return "Total imported Sections: ". $i;
@@ -345,27 +326,24 @@ function joomla_import($import_type) {
$input_format = $joomla_input_format + 1;
- $sql_text = " SELECT * FROM $table_content";
- $results_joomla = db_query($sql_text);
+ $results_joomla = db_query("SELECT * FROM %s", $table_content);
$i = 1;
$images = array();
while ( $data_joomla = db_fetch_object($results_joomla) ) {
$i++;
- //Required if process not completed!
- update_sequences();
//Check if content title already exists
$joomla_nid = $data_joomla->id;
$joomla_title = $data_joomla->title;
//Get Username
$joomla_uid = $data_joomla->created_by;
- $results_user = db_query(" SELECT * FROM $table_user WHERE id='$joomla_uid' ");
- $data_user = db_fetch_object($results_user);
+ $results_user = db_query(" SELECT * FROM %s WHERE id = %d", $table_user, $joomla_uid);
+ $data_user = db_fetch_object($results_user);
$joomla_name = $data_user->username;
//Get Drupal uid
- $results_get_uid = db_query("SELECT uid from {users} WHERE name= '$joomla_name'");
+ $results_get_uid = db_query("SELECT uid from {users} WHERE name= '%s'", $joomla_name);
$data_get_uid = db_fetch_object($results_get_uid);
$drupal_uid = $data_get_uid->uid;
@@ -397,110 +375,55 @@ function joomla_import($import_type) {
$joomla_body = addslashes($joomla_body);
//Check Frontpage
- $sql_check_fp = " SELECT content_id FROM $joomla_database.".$joomla_prefix."content_frontpage "
- ." WHERE content_id='$joomla_nid'";
- $results_check_fp = db_query($sql_check_fp);
+ $results_check_fp = db_query("SELECT COUNT(*) FROM %s.%scontent_frontpage WHERE content_id='%d'", $joomla_database, $joomla_prefix, $joomla_nid);
- if (db_num_rows($results_check_fp)) { $joomla_promote = 1; }
- else { $joomla_promote = 0;}
+ if (db_result($results_check_fp) > 0) {
+ $joomla_promote = 1;
+ }
+ else {
+ $joomla_promote = 0;
+ }
//Check content/node exists
$rec_status = 'Ignore';
- $results_check_content = db_query("SELECT title FROM {node} WHERE title='$joomla_title'");
+ $results_check_content = db_query("SELECT COUNT(*) FROM {node} WHERE title='%s'", $joomla_title);
- if (!db_num_rows($results_check_content)) {
+ if (db_result($results_check_content) == 0) {
$rec_status = 'Insert';
//get last nid
$results_last_id = db_query("SELECT nid AS id from {node} ORDER BY nid DESC LIMIT 1");
$data_last_id = db_fetch_object($results_last_id);
$last_nid = $data_last_id->id +1;
- $sql_insert_content = " INSERT INTO {node} "
- ."(nid,vid,type,title,uid,status, "
- ." created,changed,comment,promote,moderate,sticky) "
- ." values ($last_nid,$last_nid,'$joomla_type','$joomla_title','$drupal_uid',"
- ." '$joomla_status',"
- ." '$joomla_created','$joomla_changed','$joomla_comment','$joomla_promote', "
- ." '$joomla_moderate','$joomla_sticky')";
- db_query($sql_insert_content);
+ db_query("INSERT INTO {node} (nid,vid,type,title,uid,status,created,changed,comment,promote,moderate,sticky) values (%d,%d,'%s','%s',%d,%d,%d,%d,%d,%d,%d,%d)", $last_nid, $last_nid, $joomla_type, $joomla_title, $drupal_uid, $joomla_status, $joomla_created, $joomla_changed, $joomla_comment, $joomla_promote, $joomla_moderate, $joomla_sticky);
//Intro and Body
- $sql_insert_rev = " INSERT INTO {node_revisions} "
- ."(nid,vid,uid,title,body,teaser,timestamp,format) "
- ." values ('$last_nid','$last_nid','$drupal_uid','$joomla_title','$joomla_body', "
- ." '$joomla_teaser',"
- ." '$joomla_changed','$input_format')";
- db_query($sql_insert_rev);
+ db_query( " INSERT INTO {node_revisions} (nid,vid,uid,title,body,teaser,timestamp,format) values (%d,%d,%d,'%s','%s','%s',%d,%d)", $last_nid, $last_nid, $drupal_uid, $joomla_title, $joomla_body, $joomla_teaser, $joomla_changed, $input_format);
$rows[] = array(
$i++,
$joomla_nid."/".$last_nid, l(t("$joomla_title"),"node/$last_nid"), $rec_status
);
} else {
$rec_status = 'Ignore duplicate items.';
- $results_last_id = db_query("SELECT nid AS id from {node} WHERE title='$joomla_title' ");
+ $results_last_id = db_query("SELECT nid AS id from {node} WHERE title='%s'", $joomla_title);
$data_last_id = db_fetch_object($results_last_id);
$last_nid = $data_last_id->id;
if ($joomla_update_duplicate) {
$rec_status = 'Update';
- $sql_update_content = " UPDATE {node} "
- ." SET type='$joomla_type', uid='$drupal_uid', status='$joomla_status', "
- ." created='$joomla_created', changed='$joomla_changed', promote='$joomla_promote' "
- ." WHERE nid='$last_nid'";
- db_query($sql_update_content);
+ db_query("UPDATE {node} SET type='%s', uid=%d, status=%d, created=%d, changed=%d, promote=%d WHERE nid=%d", $joomla_type, $drupal_uid, $joomla_status, $joomla_created, $joomla_changed, $joomla_promote, $last_nid) ;
//Intro and Body
- $sql_update_rev = " UPDATE {node_revisions} "
- ." SET uid='$drupal_uid', "
- ." body='$joomla_body', teaser='$joomla_teaser',timestamp='$joomla_changed', "
- ." format='$input_format' "
- ." WHERE nid='$last_nid'";
-
- db_query($sql_update_rev);
- }
+ db_query("UPDATE {node_revisions} SET uid=%d, body='%s', teaser='%s',timestamp=%d, format=%d WHERE nid=%d", $drupal_uid, $joomla_body, $joomla_teaser, $joomla_changed, $input_format, $last_nid);
}
+ }
if ($i % $joomla_delay_row ==0 ) {sleep($joomla_delay_sec);}
}
- //Update id
- update_sequences();
return "Total imported Contents: $i. Action: $rec_status";
break;
}
-
- return NULL;
-}
-
-function update_sequences() {
- $results_last_id = db_query("SELECT nid AS id from {node} ORDER BY nid DESC LIMIT 1");
- $data_last_id = db_fetch_object($results_last_id);
- $last_id = $data_last_id->id;
- if (trim($last_id) <> '') {
- db_query("UPDATE {sequences} SET id='$last_id' WHERE name='node_nid' ");
- db_query("UPDATE {sequences} SET id='$last_id' WHERE name='node_revisions_vid' ");
- }
-
- $results_last_id = db_query("SELECT uid AS id FROM {users} ORDER BY uid DESC LIMIT 1");
- $data_last_id = db_fetch_object($results_last_id);
- $last_id = $data_last_id->id;
- if (trim($last_id) <> '') {
- db_query("UPDATE {sequences} SET id='$last_id' WHERE name='users_uid' ");
- }
-
- $results_last_id = db_query("SELECT vid AS last_id from {vocabulary} ORDER BY vid DESC LIMIT 1");
- $data_last_id = db_fetch_object($results_last_id);
- $last_id = $data_last_id->last_id;
- if (trim($last_id) <> '') {
- db_query("UPDATE {sequences} SET id='$last_id' WHERE name='vocabulary_vid' ");
- }
-
- $results_last_id = db_query("SELECT tid AS last_id from {term_data} ORDER BY tid DESC LIMIT 1");
- $data_last_id = db_fetch_object($results_last_id);
- $last_id = $data_last_id->last_id;
- if (trim($last_id) <> '') {
- db_query("UPDATE {sequences} SET id='$last_id' WHERE name='term_data_tid' ");
- }
}
function replace_mos_image($images_source,$text_source) {