/[drupal]/contributions/modules/node_import/import_cck.inc
ViewVC logotype

Contents of /contributions/modules/node_import/import_cck.inc

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


Revision 1.4 - (hide annotations) (download) (as text)
Fri Apr 14 22:08:13 2006 UTC (3 years, 7 months ago) by dado
Branch: MAIN
Changes since 1.3: +5 -7 lines
File MIME type: text/x-php
added installer
improved event importing
fixed nodereference importing
added importing of taxopnomy terms, including inserting new terms when they do not already exist in the vocabulary when desired
1 dado 1.1 <?php
2     /* $Id: import_flexinode.inc,v 1.5 2005/07/01 23:37:02 drumm Exp $ */
3    
4     function content_node_import_types() {
5     $types = array();
6     foreach (_content_types() as $id => $type) {
7     $types[$id] = $type->label;
8     }
9     return $types;
10     }
11    
12     function content_node_import_fields($type) {
13 dado 1.2 $types = (array)_content_types();
14 dado 1.1 if (!isset($types[$type])) return;
15    
16     $content_type = $types[$type];
17     $fields = array();
18    
19     //add the title field
20     $fields['title'] = $content_type->title_label;
21    
22     //add all cck widget fields
23     foreach ($content_type->fields as $field) {
24     $fields[$field['field_name']] = $field['widget']['label'];
25     }
26     return $fields;
27     }
28    
29     function content_node_import_prepare(&$node, $preview = FALSE) {
30     $types = _content_types();
31     if (!isset($types[$node->type])) return;
32     $content_type = $types[$node->type];
33     //add all cck widget fields
34     foreach ($content_type->fields as $field) {
35 dado 1.2 if (strpos($field['widget']['type'], 'nodereference') === 0) {//nodereference node: query nid of the referenced node
36     $referenced_nodes = array();
37 dado 1.4 $sql = "select nid, title from {node} where title sounds like '%s'";
38 dado 1.2 $result = db_query($sql, $node->$field['field_name']);
39     $record_found = db_fetch_object($result);
40    
41     if ($record_found) {
42     if ($field['multiple']) {
43 dado 1.4 $node_field = array(0 => array('nid' => $record_found->nid));
44 dado 1.2 } else {
45 dado 1.4 $node_field = array('nid' => $record_found->nid);
46 dado 1.2 }
47     } else {
48 dado 1.4 $node_field = array();
49 dado 1.2 }
50 dado 1.4 $node->$field['field_name'] = $node_field;
51 dado 1.2
52     } else {//default node types: add value to array w/ key 'value'
53     $thisval = $node->$field['field_name'];
54     $node->$field['field_name'] = array('value' => $thisval);
55     }
56 dado 1.1 }
57     return;
58     }
59     ?>

  ViewVC Help
Powered by ViewVC 1.1.2