/[drupal]/contributions/modules/import_typepad/import_typepad.module
ViewVC logotype

Diff of /contributions/modules/import_typepad/import_typepad.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.7, Sun Jan 7 04:28:02 2007 UTC revision 1.7.4.1, Wed Aug 20 00:39:26 2008 UTC
# Line 4  Line 4 
4   * Based on node_import (the cvs content importer)   * Based on node_import (the cvs content importer)
5   *   *
6   * Nigel Sim <nigel.sim@gmail.com> 2005, 2006   * Nigel Sim <nigel.sim@gmail.com> 2005, 2006
7     * Leigh Morresi <dgtlmoon@gmail.com> 2007, 2008
8   */   */
9    
10  ini_set('auto_detect_line_endings', TRUE);  ini_set('auto_detect_line_endings', TRUE);
# Line 17  function import_typepad_help($section) { Line 18  function import_typepad_help($section) {
18      case 'admin/modules#description':      case 'admin/modules#description':
19        return t('Import nodes from a typepad file.');        return t('Import nodes from a typepad file.');
20      case 'admin/help#import_typepad':      case 'admin/help#import_typepad':
21        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')));
22    }    }
23  }  }
24    
25  function import_typepad_menu($may_cache) {  function import_typepad_menu($may_cache) {
26    $links = array();    $links = array();
27    if ($may_cache) {    if ($may_cache) {
28      $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/content/import_typepad',
29      $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);                       'title' => t('Import Typepad Content'),
30                         'callback' => 'import_typepad_page',
31                         'weight' => 5,
32                         'access' => user_access('import nodes'));
33        $links[] = array('path' => 'admin/content/import_typepad/preview',
34                         'title' => t('type pad'),
35                         'callback' => 'import_typepad_preview',
36                         'weight' => 5,
37                         'access' => user_access('import nodes'),
38                         'type' => MENU_CALLBACK);
39    }    }
40    return $links;    return $links;
41  }  }
# Line 42  function import_typepad_page($form_value Line 52  function import_typepad_page($form_value
52    if ($edit[_WORKING_FILE]) {    if ($edit[_WORKING_FILE]) {
53      $output .= form_item(t('File'), $edit[_WORKING_FILE] .' ('. format_size( filesize($edit[_WORKING_FILE]) ) .')<br />'. form_submit(t('Use a different file')));      $output .= form_item(t('File'), $edit[_WORKING_FILE] .' ('. format_size( filesize($edit[_WORKING_FILE]) ) .')<br />'. form_submit(t('Use a different file')));
54    }    }
   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'));  
   }  
55    
56    // todo add an insert/update option    // todo add an insert/update option
57      $output = drupal_get_form('import_typepad_form_select');
58    
59      return $output;
60    }
61    
62    function import_typepad_form_select(){
63      $form['upload_file'] = array(
64        '#type' => 'file',
65        '#title' => t('Upload Type Pad/Movable Type file'),
66        '#description' => t('The export file you wish to import'));
67      $form['serverside_file'] = array(
68        '#type' => 'textfield',
69        '#title' => t('Server side file'),
70        '#description' => t('The file located on the server you wish to import'));
71    $form['submit'] = array(    $form['submit'] = array(
72      '#type' => 'submit',      '#type' => 'submit',
73      '#value' => t('Step 2'));      '#value' => t('Step 2'));
74    
75    $form['#attributes'] = array('enctype' => 'multipart/form-data');    $form['#attributes'] = array('enctype' => 'multipart/form-data');
   
   $output = drupal_get_form('typepad_step1', $form);  
76    
77    return $output;    return $form;
78  }  }
79    
80  /**  /**
81   * Discover which file we are using, and move it into the appropriate position   * Discover which file we are using, and move it into the appropriate position
82   */   */
83  function typepad_step1_validate($form_id, $form_values){  function import_typepad_form_select_validate($form_id, $form_values){
84    global $user;    global $user;
85    global $base_url;    global $base_url;
86    
# Line 96  function typepad_step1_validate($form_id Line 108  function typepad_step1_validate($form_id
108  /**  /**
109   * If the validation passed then simple redirect to the preview   * If the validation passed then simple redirect to the preview
110   */   */
111  function typepad_step1_submit($form_id, $form_values){  function import_typepad_form_select_submit($form_id, $form_values){
112    return 'admin/node/import_typepad/preview';    return 'admin/content/import_typepad/preview';
113  }  }
114    
115  /**  /**
# Line 106  function typepad_step1_submit($form_id, Line 118  function typepad_step1_submit($form_id,
118   * In due course we'll pass the preview count via the parameters   * In due course we'll pass the preview count via the parameters
119   */   */
120  function import_typepad_preview($previewCount = 10) {  function import_typepad_preview($previewCount = 10) {
   $authors = array();  
   $cats = array();  
121    $output = '';    $output = '';
122      $authors = array();
123    
124    $items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], $previewCount, $authors, $cats, array());    $items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], $previewCount, $authors, $cats, array());
125    
126      // Previews
127      $output .= "<h3>".t("Preview Items To Import")."</h3>".$items;
128      $output .= "<h3>".t("Select Import Options")."</h3>".
129                        drupal_get_form('import_typepad_form_process',$authors,$cats);
130    
   // Refresh preview w/ entry count  
131    
132    // Previews    return $output;
133    $output .= $items;  }
134    
135    function import_typepad_form_process($authors,$cats){
136    // Mappings and import    // Mappings and import
137    // Get user list    // Get user list
138    $users = array();    $users = array();
# Line 127  function import_typepad_preview($preview Line 142  function import_typepad_preview($preview
142      $users[$user->uid] = $user->name;      $users[$user->uid] = $user->name;
143    }    }
144    
145    $import_form["author_title"] = array(    $import_form["author_mappings"] = array(
146      "#type" => "markup",      "#type" => "fieldset",
147      "#value" => t("<span>Author mappings</span>"));      "#title" => t("Author mappings"));
148    
149    foreach ($authors as $author=>$uid){    foreach ($authors as $author=>$uid){
150      $import_form[$author] = array(      $import_form["author_mappings"][$author] = array(
151        "#type" => 'select',        "#type" => 'select',
152        "#title"=> $author,        "#title"=> $author,
153        '#options' => $users);        '#options' => $users);
154    }    }
155    
156    $import_form["taxonomy_title"] = array(    $import_form["taxonomy_mappings"] = array(
157      "#type" => "markup",      "#type" => "fieldset",
158      "#value" => t("<span>Taxonomy mappings</span>"));      "#title" => t("Taxonomy mappings"));
159    
160    foreach ($cats as $cat=>$count){    foreach ($cats as $cat=>$count){
161      $item = _import_typepad_taxonomy_list($cat);      $item = _import_typepad_taxonomy_list($cat);
162      $item['#title'] = "$cat ($count)";      $item['#title'] = "$cat ($count)";
163      $import_form['taxonomy_'.str_replace(' ','_',$cat)] = $item;      $import_form["taxonomy_mappings"]['taxonomy_'.str_replace(' ','_',$cat)] = $item;
164    }    }
165    
166    $import_form["import_warning"] = array (    $import_form["import_warning"] = array (
167      "#type" => "markup",      "#type" => "markup",
168      "#value" => t('<span>Importing may take awhile, do not click \'Import\' more than once. To see progress, look at the <a href="?q=admin/node" target="_new">Administer -> Content</a> page in a new window.</span>')  );      "#value" => t('Importing may take a while, do not click \'Import\' more than once. To see progress, look at the <a href="?=admin/content/node">administer content</a> page in a new window.<br/><br/>'));
169    
170    $import_form['submit'] = array('#type' => 'submit', '#value' => t('Import'));    $import_form['submit'] = array('#type' => 'submit', '#value' => t('Import'));
171    
172    $output .= drupal_get_form('import_typepad_process', $import_form);    return $import_form;
   
   return $output;  
173  }  }
174    
175  /**  /**
# Line 165  function import_typepad_preview($preview Line 179  function import_typepad_preview($preview
179  function _import_typepad_taxonomy_list($name){  function _import_typepad_taxonomy_list($name){
180    if (user_access('access content')) {    if (user_access('access content')) {
181      $default = '';      $default = '';
182      $vocabs = taxonomy_get_vocabularies('blog');      $vocabs = taxonomy_get_vocabularies();
183      $items = array();      $items = array(0=>t("(none)"));
184      foreach ($vocabs as $vocab) {      foreach ($vocabs as $vocab) {
185        $tree = taxonomy_get_tree($vocab->vid);        $tree = taxonomy_get_tree($vocab->vid);
186        foreach ($tree as $term) {        foreach ($tree as $term) {
187          $items[$term->tid] = _taxonomy_depth($term->depth) .' '.$term->name;          $items[$term->tid] = $vocab->name." | ".$term->name;
188          if ($name == $term->name){          if ($name == $term->name){
189            $default = $term->tid;                  $default = $term->tid;
190          }          }
191        }        }
192      }      }
193      return array(      return array(
# Line 186  function _import_typepad_taxonomy_list($ Line 200  function _import_typepad_taxonomy_list($
200  /**  /**
201   * Simply run the import, passing the form in for the taxonomy and author maps   * Simply run the import, passing the form in for the taxonomy and author maps
202   */   */
203  function import_typepad_process_submit($formid, $form_elements){  function import_typepad_form_process_submit($formid, $form_elements){
204    $cats = array(); // unused    $cats = array(); // unused
205    $items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], 0, $form_elements, $cats, $form_elements);    $items = _import_typepad_get_nodes( variable_get(_WORKING_FILE, null), $edit['type'], 0, $form_elements, $cats, $form_elements);
206    if ( variable_get(_FILE_TYPE, null) == 'UPLOAD'){    if ( variable_get(_FILE_TYPE, null) == 'UPLOAD'){
# Line 194  function import_typepad_process_submit($ Line 208  function import_typepad_process_submit($
208    }    }
209    variable_del(_WORKING_FILE);    variable_del(_WORKING_FILE);
210    variable_del(_FILE_TYPE);    variable_del(_FILE_TYPE);
211    return 'admin/node/import_typepad';    return 'admin/content/import_typepad';
212  }  }
213    
214  /**  /**
# Line 266  function _import_typepad_errors_validate Line 280  function _import_typepad_errors_validate
280   *   *
281   * @return preview   * @return preview
282   */   */
283  function _import_typepad_get_nodes($path, $type, $preview, &$authors, &$cats, $taxonomy) {  function _import_typepad_get_nodes($path, $type, $preview, &$authors, &$cats, $taxonomy, $type="blog") {
284    $handle = fopen($path, 'r');    $handle = fopen($path, 'r');
285    if ($handle == null)    if ($handle == null)
286      return false;      return false;
# Line 345  function _import_typepad_get_nodes($path Line 359  function _import_typepad_get_nodes($path
359            // Start new blog            // Start new blog
360            $blogCats = array();            $blogCats = array();
361            $currentBlog = new StdClass();            $currentBlog = new StdClass();
362            $currentBlog->type = 'blog';            $currentBlog->type = $type;
363            $currentBlog->author = trim( substr($line, strpos($line,"AUTHOR:") + strlen("AUTHOR:")) );            $currentBlog->author = trim( substr($line, strpos($line,"AUTHOR:") + strlen("AUTHOR:")) );
364            // We generate a hash for the author name which can be used in HTML forms            // We generate a hash for the author name which can be used in HTML forms
365            $authorHash = 'author_map_'.str_replace(" ","_",$currentBlog->author);            $authorHash = 'author_map_'.str_replace(" ","_",$currentBlog->author);
# Line 381  function _import_typepad_get_nodes($path Line 395  function _import_typepad_get_nodes($path
395          } else if ($state == 2){          } else if ($state == 2){
396            //echo "<!-- $name $val $sep -->\n";            //echo "<!-- $name $val $sep -->\n";
397            if (strlen($name) > 0 && array_key_exists($name, $mapping)){            if (strlen($name) > 0 && array_key_exists($name, $mapping)){
398              $currentBlog->comments[count($currentBlog->comments)-1]->$mapping[$name] = $value;              $currentBlog->comments[count($currentBlog->comments)-1]->$mapping[$name] = trim($value);
399            } else {            } else {
400              $currentBlog->comments[count($currentBlog->comments)-1]->comment .= $rawLine;              $currentBlog->comments[count($currentBlog->comments)-1]->comment .= trim($rawLine);
401            }            }
402          } else if ($state == 3){          } else if ($state == 3){
403                  // Do nothing (Skip)                  // Do nothing (Skip)
# Line 425  function _import_typepad_get_nodes($path Line 439  function _import_typepad_get_nodes($path
439    }    }
440    */    */
441    if ($success) {    if ($success) {
442      drupal_set_message(t('Successfully imported %count.', array('%count' => format_plural($success, '1 node', '%count nodes'))));      drupal_set_message(t('Successfully imported %count.', array('%count' => $success . format_plural($success, ' node', ' nodes'))));
443    }    }
444    
445    return $output;    return $output;
# Line 488  function _import_typepad_save($currentBl Line 502  function _import_typepad_save($currentBl
502      // Type pad doesn't have threaded comments, or subject lines, so we have to improvise them      // Type pad doesn't have threaded comments, or subject lines, so we have to improvise them
503          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')",          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')",
504            $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);            $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);
505          _comment_update_node_statistics($nid);  //      _comment_update_node_statistics($nid);
506    }    }
507  }  }
508  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.7.4.1

  ViewVC Help
Powered by ViewVC 1.1.2