--- import_typepad.module 2007-01-07 15:28:02.000000000 +1100 +++ import_typepad.module.mine 2007-10-26 14:04:45.000000000 +1000 @@ -11,6 +11,7 @@ define('_WORKING_FILE', 'import_typepad_workingfile'); define('_IMPORT_TYPEPAD', 'import_typepad'); define('_ACTION_DELETE_FILE', 'Delete file from server'); +define('_CTYPE','import_typepad,content_type'); function import_typepad_help($section) { switch ($section) { @@ -116,7 +117,7 @@ // Refresh preview w/ entry count // Previews - $output .= $items; + // $output .= $items; // Mappings and import // Get user list @@ -137,6 +138,19 @@ '#options' => $users); } + // get available types including CCK + $types["blog"] = "blog"; + $result = db_query('SELECT type_name FROM {node_type};'); + while ($type = db_fetch_object($result)) { + $types[$type->type_name] = $type->type_name; + } + + $import_form["type"] = array( + "#type" => 'select', + "#title"=> t('Content type to map to'), + '#options' => $types); + + $import_form["taxonomy_title"] = array( "#type" => "markup", "#value" => t("Taxonomy mappings")); @@ -165,7 +179,7 @@ function _import_typepad_taxonomy_list($name){ if (user_access('access content')) { $default = ''; - $vocabs = taxonomy_get_vocabularies('blog'); + $vocabs = taxonomy_get_vocabularies(); $items = array(); foreach ($vocabs as $vocab) { $tree = taxonomy_get_tree($vocab->vid); @@ -188,7 +202,10 @@ */ function import_typepad_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); + + variable_set(_CTYPE, $form_elements['type']); + + $items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null),$form_elements['type'], 0, $form_elements, $cats, $form_elements); if ( variable_get(_FILE_TYPE, null) == 'UPLOAD'){ unlink( variable_get(_WORKING_FILE, null) ); } @@ -266,11 +283,12 @@ * * @return preview */ -function _import_typepad_get_nodes($path, $type, $preview, &$authors, &$cats, $taxonomy) { +function _import_typepad_get_nodes($path, $type='blog', $preview, &$authors, &$cats, $taxonomy) { $handle = fopen($path, 'r'); if ($handle == null) return false; + // this is the way the original author seemed todo things $success = 0; $run = true; @@ -278,6 +296,7 @@ $state = 0; // 0-unknown, 1-blog, 2-comment, 3-skip, 4-blog body, 5-blog excerpt $previewCount = 0; $blogCats = array(); + $saveBlogs = array(); $mapping = array('TITLE:'=>'title', 'ALLOW COMMENTS:'=>'comment', 'EMAIL:'=>'mail', 'IP:'=>'hostname', 'URL:'=>'homepage'); @@ -334,18 +353,24 @@ foreach ($blogCats as $id=>$val){ $c[] = $taxonomy['taxonomy_'.str_replace(' ','_',$val)]; } - _import_typepad_save($currentBlog, $c); + // put these into an array for reversing later + // drupal wants the oldest entries in the database first + // due to its thread sorting methods + $blog['c']=$c; + $blog['currentBlog']=$currentBlog; + $saveBlogs[]=$blog; + $success++; } else if ($previewCount < $preview){ $output .= node_view($currentBlog); $previewCount++; } } - + if(!$type) $type='blog'; // 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); @@ -358,7 +383,7 @@ $currentBlog->comments = array(); } else if ($state == 2) { - $currentBlog->comments[count($currentBlog->comments)-1]->name = substr($line, strlen("AUTHOR:")); + $currentBlog->comments[count($currentBlog->comments)-1]->name = ltrim(substr($line, strlen("AUTHOR:"))); } else { echo "