You are here

function featured_content_get_cck_nids in Featured Content 6

Same name and namespace in other branches
  1. 6.2 featured_content.module \featured_content_get_cck_nids()
  2. 7.2 featured_content.module \featured_content_get_cck_nids()
  3. 7 featured_content.module \featured_content_get_cck_nids()

Get CCK node nids.

1 call to featured_content_get_cck_nids()
featured_content_view in ./featured_content.module
Provides 'view' info for hook_block().

File

./featured_content.module, line 396
Featured Content module for created related & featured content blocks.

Code

function featured_content_get_cck_nids($data) {
  $nids = array();
  $node = _featured_content_load_node();
  if ($node->nid) {
    $cck_fields = content_fields();
    if (!empty($cck_fields)) {
      foreach ($cck_fields as $field_name => $field_data) {
        if ($data['fields'][$field_name]) {
          $cck_field = $node->{$field_name};
          if ($field_data['type'] == 'text') {

            // parse the text field
            $cck_text = trim($cck_field[0]['value']);
            if ($cck_text) {
              $tmp = array();
              if (preg_match('/,/', $cck_text, $matches)) {
                $tmp = explode(',', $cck_text);
              }
              else {
                $tmp = explode("\r\n", $cck_text);
              }
              if (!empty($tmp)) {
                foreach ($tmp as $nid) {
                  $nid = trim($nid);
                  if (!is_numeric($nid)) {
                    $path = drupal_lookup_path('source', $nid);
                    if (!empty($path)) {
                      $nid = $path;
                    }
                    $matches = array();
                    if (preg_match('/node\\/([0-9]+)/', $nid, $matches)) {
                      $nid = $matches[1];
                    }
                  }
                  if (is_numeric($nid) && $nid > 0) {
                    $nids[$nid] = $nid;
                  }
                }
              }
            }
          }
          elseif ($field_data['type'] == 'nodereference') {
            if (is_array($cck_field)) {
              foreach ($cck_field as $node_refs) {
                if ($node_refs['nid']) {
                  $nids[$node_refs['nid']] = $node_refs['nid'];
                }
              }
            }
          }
          elseif ($field_data['type'] == 'userreference') {
            $uids = array();
            if (is_array($cck_field)) {
              foreach ($cck_field as $user_refs) {
                if ($user_refs['uid']) {
                  $uids[] = $user_refs['uid'];
                }
              }
            }
            if (!empty($uids)) {
              $results = db_query('SELECT nid FROM {node} WHERE uid in (' . db_placeholders($uids, 'int') . ') AND status <> 0', $uids);
              while ($row = db_fetch_object($results)) {
                if (is_numeric($row->nid) && $row->nid > 0) {
                  $nids[$row->nid] = $row->nid;
                }
              }
            }
          }
        }
      }
    }
  }
  return $nids;
}