/[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.10 - (show annotations) (download) (as text)
Fri May 19 07:38:14 2006 UTC (3 years, 6 months ago) by robrechtj
Branch: MAIN
Changes since 1.9: +2 -1 lines
File MIME type: text/x-php
another try to get $Id$ to work...
1 <?php
2 /* $Id$ */
3
4 /**
5 * Implementation of hook_node_import_types().
6 */
7 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 /**
16 * Implementation of hook_node_import_fields().
17 */
18 function content_node_import_fields($type) {
19 $types = (array)_content_types();
20 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 /**
36 * Implementation of hook_node_import_prepare().
37 */
38 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
43 //add all cck widget fields
44 foreach ($content_type->fields as $field) {
45 if (strpos($field['widget']['type'], 'nodereference') === 0) {//nodereference node: query nid of the referenced node
46 $referenced_nodes = array();
47 $sql = "SELECT nid, title FROM {node} WHERE title SOUNDS LIKE '%s'";
48 $result = db_query($sql, $node->$field['field_name']);
49 $record_found = db_fetch_object($result);
50 if ($record_found) {
51 $node_field = array(0 => array('nid' => $record_found->nid));
52 } else {
53 $node_field = array();
54 }
55 $node->$field['field_name'] = $node_field;
56 } else {//default node types: add value to array w/ key 'value'
57 $thisval = $node->$field['field_name'];
58 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 }
64 }
65 return;
66 }
67 ?>

  ViewVC Help
Powered by ViewVC 1.1.2