/[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.11 - (hide annotations) (download) (as text)
Fri May 19 15:11:31 2006 UTC (3 years, 6 months ago) by robrechtj
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +0 -0 lines
File MIME type: text/x-php
FILE REMOVED
#53044 : renamed import_cck.inc to import_content.inc
1 dado 1.1 <?php
2 robrechtj 1.10 /* $Id$ */
3 dado 1.1
4 robrechtj 1.8 /**
5     * Implementation of hook_node_import_types().
6     */
7 dado 1.1 function content_node_import_types() {
8     $types = array();
9     foreach (_content_types() as $id => $type) {
10     $types[$id] = $type->label;
11     }
12     return $types;
13     }
14    
15 robrechtj 1.8 /**
16     * Implementation of hook_node_import_fields().
17     */
18 dado 1.1 function content_node_import_fields($type) {
19 dado 1.2 $types = (array)_content_types();
20 dado 1.1 if (!isset($types[$type])) return;
21    
22     $content_type = $types[$type];
23     $fields = array();
24    
25     //add the title field
26     $fields['title'] = $content_type->title_label;
27    
28     //add all cck widget fields
29     foreach ($content_type->fields as $field) {
30     $fields[$field['field_name']] = $field['widget']['label'];
31     }
32     return $fields;
33     }
34    
35 robrechtj 1.8 /**
36     * Implementation of hook_node_import_prepare().
37     */
38 dado 1.1 function content_node_import_prepare(&$node, $preview = FALSE) {
39     $types = _content_types();
40     if (!isset($types[$node->type])) return;
41     $content_type = $types[$node->type];
42 robrechtj 1.8
43 dado 1.1 //add all cck widget fields
44     foreach ($content_type->fields as $field) {
45 dado 1.2 if (strpos($field['widget']['type'], 'nodereference') === 0) {//nodereference node: query nid of the referenced node
46     $referenced_nodes = array();
47 robrechtj 1.8 $sql = "SELECT nid, title FROM {node} WHERE title SOUNDS LIKE '%s'";
48 dado 1.2 $result = db_query($sql, $node->$field['field_name']);
49 dado 1.7 $record_found = db_fetch_object($result);
50 dado 1.2 if ($record_found) {
51 dado 1.7 $node_field = array(0 => array('nid' => $record_found->nid));
52 dado 1.2 } else {
53 dado 1.4 $node_field = array();
54 dado 1.2 }
55 dado 1.4 $node->$field['field_name'] = $node_field;
56 dado 1.2 } else {//default node types: add value to array w/ key 'value'
57     $thisval = $node->$field['field_name'];
58 dado 1.5 if ($field['widget']['type'] == 'weburl') {
59     $node->$field['field_name'] = array('value' => $thisval);
60     } else {
61     $node->$field['field_name'] = array(0 => array('value' => $thisval));
62     }
63 dado 1.2 }
64 dado 1.1 }
65     return;
66     }
67 robrechtj 1.10 ?>

  ViewVC Help
Powered by ViewVC 1.1.2