FrxDrupalNode.inc 1.57 KB
Newer Older
metzlerd's avatar
metzlerd committed
1
<?php
metzlerd's avatar
metzlerd committed
2
3
4
5
/**
 * Implementation of a drupal node load function
 * @author baileys
 */
metzlerd's avatar
metzlerd committed
6
7
class FrxDrupalNode {
  public $access = 'access content';
metzlerd's avatar
metzlerd committed
8
  public $tokens = array('nid', 'vid');
metzlerd's avatar
metzlerd committed
9

metzlerd's avatar
metzlerd committed
10
  public function load($parms = array()) {
11
12
    $nid = isset($parms['nid']) ? $parms['nid'] : 1;
    $vid = isset($parms['vid']) ? $parms['vid'] : NULL;
13
14
15

    // No node ID means don't try and laod a node.
    if (!$nid && !$vid) return '';
16
17
18
    $node = node_load($nid, $vid);
    $return = new SimpleXMLElement('<node/>');
    $lang = isset($node->language) ? $node->language : 'unk';
19
20
    $display = isset($parms['display']) ? $parms['display'] : 'default';
    if ($node) foreach ($node as $key => $val) if ($val) {
21
      if (strpos($key, 'field_') === 0) {
22
23
24
25
26
27
28
29
        //$fields = field_get_items('node', $node, $key);
        $field = field_view_field('node', $node, $key, $display);
        $field['#theme'] = array('forena_inline_field');
        $value  = drupal_render($field);
        $f = $return->addChild($key, $value);
        if (isset($field['#field_type'])) $f['type'] = $field['#field_type'];
        if (isset($field['#field_name'])) $f['name'] = $field['#field_name'];

30
      } else if (is_array($val) && isset($val[$lang])) {
31
        $tmp = $val[$lang][0];
32
33
34
35
        if (isset($tmp['safe_value'])) {
          $return->addChild($key, $tmp['safe_value']);
        } else if (isset($tmp['value'])) {
          $return->addChild($key, $tmp['value']);
36
        }
37
38
      } else if (is_scalar($val)) {
        $return->addChild($key, $val);
metzlerd's avatar
metzlerd committed
39
40
      }
    }
41
    return $return;
metzlerd's avatar
metzlerd committed
42
43
  }
}