--- import_typepad.module 2007-01-06 23:28:02.000000000 -0500
+++ import_typepad.module 2007-03-30 12:07:42.000000000 -0400
@@ -17,15 +17,24 @@ function import_typepad_help($section) {
case 'admin/modules#description':
return t('Import nodes from a typepad file.');
case 'admin/help#import_typepad':
- return t(' ', array('%admin-node-import_typepad' => url('admin/node/import_typepad'), '%admin-access-permission' => url('admin/access/permission')));
+ return t(' ', array('%admin-node-import_typepad' => url('admin/content/import_typepad'), '%admin-access-permission' => url('admin/access/permission')));
}
}
function import_typepad_menu($may_cache) {
$links = array();
if ($may_cache) {
- $links[] = array('path' => 'admin/node/import_typepad', 'title' => t('type pad'), 'callback' => 'import_typepad_page', 'weight' => 5, 'access' => user_access('import nodes'));
- $links[] = array('path' => 'admin/node/import_typepad/preview', 'title' => t('type pad'), 'callback' => 'import_typepad_preview', 'weight' => 5, 'access' => user_access('import nodes'), 'type' => MENU_CALLBACK);
+ $links[] = array('path' => 'admin/content/import_typepad',
+ 'title' => t('Import Typepad Content'),
+ 'callback' => 'import_typepad_page',
+ 'weight' => 5,
+ 'access' => user_access('import nodes'));
+ $links[] = array('path' => 'admin/content/import_typepad/preview',
+ 'title' => t('type pad'),
+ 'callback' => 'import_typepad_preview',
+ 'weight' => 5,
+ 'access' => user_access('import nodes'),
+ 'type' => MENU_CALLBACK);
}
return $links;
}
@@ -42,33 +51,35 @@ function import_typepad_page($form_value
if ($edit[_WORKING_FILE]) {
$output .= form_item(t('File'), $edit[_WORKING_FILE] .' ('. format_size( filesize($edit[_WORKING_FILE]) ) .')
'. form_submit(t('Use a different file')));
}
- else {
- $form['upload_file'] = array(
- '#type' => 'file',
- '#title' => t('Upload Type Pad/Movable Type file'),
- '#description' => t('The export file you wish to import'));
- $form['serverside_file'] = array(
- '#type' => 'textfield',
- '#title' => t('Server side file'),
- '#description' => t('The file located on the server you wish to import'));
- }
// todo add an insert/update option
+ $output = drupal_get_form('import_typepad_form_select');
+
+ return $output;
+}
+
+function import_typepad_form_select(){
+ $form['upload_file'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload Type Pad/Movable Type file'),
+ '#description' => t('The export file you wish to import'));
+ $form['serverside_file'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Server side file'),
+ '#description' => t('The file located on the server you wish to import'));
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Step 2'));
$form['#attributes'] = array('enctype' => 'multipart/form-data');
-
- $output = drupal_get_form('typepad_step1', $form);
- return $output;
+ return $form;
}
/**
* Discover which file we are using, and move it into the appropriate position
*/
-function typepad_step1_validate($form_id, $form_values){
+function import_typepad_form_select_validate($form_id, $form_values){
global $user;
global $base_url;
@@ -96,8 +107,8 @@ function typepad_step1_validate($form_id
/**
* If the validation passed then simple redirect to the preview
*/
-function typepad_step1_submit($form_id, $form_values){
- return 'admin/node/import_typepad/preview';
+function import_typepad_form_select_submit($form_id, $form_values){
+ return 'admin/content/import_typepad/preview';
}
/**
@@ -106,18 +117,21 @@ function typepad_step1_submit($form_id,
* In due course we'll pass the preview count via the parameters
*/
function import_typepad_preview($previewCount = 10) {
- $authors = array();
- $cats = array();
$output = '';
-
+ $authors = array();
+
$items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], $previewCount, $authors, $cats, array());
+ // Previews
+ $output .= "
".t("Preview Items To Import")."
".$items;
+ $output .= "".t("Select Import Options")."
".
+ drupal_get_form('import_typepad_form_process',$authors,$cats);
- // Refresh preview w/ entry count
- // Previews
- $output .= $items;
+ return $output;
+}
+function import_typepad_form_process($authors,$cats){
// Mappings and import
// Get user list
$users = array();
@@ -127,35 +141,34 @@ function import_typepad_preview($preview
$users[$user->uid] = $user->name;
}
- $import_form["author_title"] = array(
- "#type" => "markup",
- "#value" => t("Author mappings"));
+ $import_form["author_mappings"] = array(
+ "#type" => "fieldset",
+ "#title" => t("Author mappings"));
+
foreach ($authors as $author=>$uid){
- $import_form[$author] = array(
+ $import_form["author_mappings"][$author] = array(
"#type" => 'select',
"#title"=> $author,
'#options' => $users);
}
- $import_form["taxonomy_title"] = array(
- "#type" => "markup",
- "#value" => t("Taxonomy mappings"));
+ $import_form["taxonomy_mappings"] = array(
+ "#type" => "fieldset",
+ "#title" => t("Taxonomy mappings"));
foreach ($cats as $cat=>$count){
$item = _import_typepad_taxonomy_list($cat);
$item['#title'] = "$cat ($count)";
- $import_form['taxonomy_'.str_replace(' ','_',$cat)] = $item;
+ $import_form["taxonomy_mappings"]['taxonomy_'.str_replace(' ','_',$cat)] = $item;
}
$import_form["import_warning"] = array (
"#type" => "markup",
- "#value" => t('Importing may take awhile, do not click \'Import\' more than once. To see progress, look at the Administer -> Content page in a new window.') );
+ "#value" => t('Importing may take a while, do not click \'Import\' more than once. To see progress, look at the administer content page in a new window.
'));
$import_form['submit'] = array('#type' => 'submit', '#value' => t('Import'));
- $output .= drupal_get_form('import_typepad_process', $import_form);
-
- return $output;
+ return $import_form;
}
/**
@@ -165,15 +178,15 @@ function import_typepad_preview($preview
function _import_typepad_taxonomy_list($name){
if (user_access('access content')) {
$default = '';
- $vocabs = taxonomy_get_vocabularies('blog');
- $items = array();
+ $vocabs = taxonomy_get_vocabularies();
+ $items = array(0=>t("(none)"));
foreach ($vocabs as $vocab) {
$tree = taxonomy_get_tree($vocab->vid);
foreach ($tree as $term) {
- $items[$term->tid] = _taxonomy_depth($term->depth) .' '.$term->name;
- if ($name == $term->name){
- $default = $term->tid;
- }
+ $items[$term->tid] = $vocab->name." | ".$term->name;
+ if ($name == $term->name){
+ $default = $term->tid;
+ }
}
}
return array(
@@ -186,7 +199,7 @@ function _import_typepad_taxonomy_list($
/**
* Simply run the import, passing the form in for the taxonomy and author maps
*/
-function import_typepad_process_submit($formid, $form_elements){
+function import_typepad_form_process_submit($formid, $form_elements){
$cats = array(); // unused
$items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], 0, $form_elements, $cats, $form_elements);
if ( variable_get(_FILE_TYPE, null) == 'UPLOAD'){
@@ -194,7 +207,7 @@ function import_typepad_process_submit($
}
variable_del(_WORKING_FILE);
variable_del(_FILE_TYPE);
- return 'admin/node/import_typepad';
+ return 'admin/content/import_typepad';
}
/**
@@ -266,7 +279,7 @@ function _import_typepad_errors_validate
*
* @return preview
*/
-function _import_typepad_get_nodes($path, $type, $preview, &$authors, &$cats, $taxonomy) {
+function _import_typepad_get_nodes($path, $type, $preview, &$authors, &$cats, $taxonomy, $type="blog") {
$handle = fopen($path, 'r');
if ($handle == null)
return false;
@@ -345,7 +358,7 @@ function _import_typepad_get_nodes($path
// Start new blog
$blogCats = array();
$currentBlog = new StdClass();
- $currentBlog->type = 'blog';
+ $currentBlog->type = $type;
$currentBlog->author = trim( substr($line, strpos($line,"AUTHOR:") + strlen("AUTHOR:")) );
// We generate a hash for the author name which can be used in HTML forms
$authorHash = 'author_map_'.str_replace(" ","_",$currentBlog->author);
@@ -488,7 +501,7 @@ function _import_typepad_save($currentBl
// Type pad doesn't have threaded comments, or subject lines, so we have to improvise them
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')",
$cid, $currentBlog->nid, 0/*pid*/, 0, "re: ".$currentBlog->title, $comment->comment, 1/*format*/, $comment->hostname, $comment->timestamp, 0/*status*/, 0/*score*/, ''/*$users*/, $thread, $comment->name, $comment->mail, $comment->homepage);
- _comment_update_node_statistics($nid);
+// _comment_update_node_statistics($nid);
}
}
}