You are here

protected function NodeResourceFeedModelItem::renderAsNodeFeed in Services 6.3

This function consists entirely of code copy pasted from node_feed() to make the node resource feed model consistent with normal feeds.

Parameters

int $nid: The id of the node that should be rendered

string $item_length: The length of the content to generate: title, teaser or fulltext

Return value

string The text that should be used for the feed item description

1 call to NodeResourceFeedModelItem::renderAsNodeFeed()
NodeResourceFeedModelItem::getDescription in servers/rest_server/includes/node_resource.models.inc
Calls node_build_content to create a teaser

File

servers/rest_server/includes/node_resource.models.inc, line 113
This file will parse a node resource feed And will also provide the necessary manip functions

Class

NodeResourceFeedModelItem

Code

protected function renderAsNodeFeed($nid, $item_length) {

  // Load the specified node:
  $item = node_load($nid);
  $item->build_mode = NODE_BUILD_RSS;
  $item->link = url("node/{$nid}", array(
    'absolute' => TRUE,
  ));
  if ($item_length != 'title') {
    $teaser = $item_length == 'teaser' ? TRUE : FALSE;

    // Filter and prepare node teaser
    if (node_hook($item, 'view')) {
      $item = node_invoke($item, 'view', $teaser, FALSE);
    }
    else {
      $item = node_prepare($item, $teaser);
    }

    // Allow modules to change $node->content before the node is rendered.
    node_invoke_nodeapi($item, 'view', $teaser, FALSE);

    // Set the proper node property, then unset unused $node property so that a
    // bad theme can not open a security hole.
    $content = drupal_render($item->content);
    if ($teaser) {
      $item->teaser = $content;
      unset($item->body);
    }
    else {
      $item->body = $content;
      unset($item->teaser);
    }

    // Allow modules to modify the fully-built node.
    node_invoke_nodeapi($item, 'alter', $teaser, FALSE);
  }

  // Allow modules to add additional item fields and/or modify $item
  $extra = node_invoke_nodeapi($item, 'rss item');
  $extra = array_merge($extra, array(
    array(
      'key' => 'pubDate',
      'value' => gmdate('r', $item->created),
    ),
    array(
      'key' => 'dc:creator',
      'value' => $item->name,
    ),
    array(
      'key' => 'guid',
      'value' => $item->nid . ' at ' . $base_url,
      'attributes' => array(
        'isPermaLink' => 'false',
      ),
    ),
  ));
  foreach ($extra as $element) {
    if (isset($element['namespace'])) {
      $namespaces = array_merge($namespaces, $element['namespace']);
    }
  }

  // Prepare the item description
  switch ($item_length) {
    case 'fulltext':
      $item_text = $item->body;
      break;
    case 'teaser':
      $item_text = $item->teaser;
      if (!empty($item->readmore)) {
        $item_text .= '<p>' . l(t('read more'), 'node/' . $item->nid, array(
          'absolute' => TRUE,
          'attributes' => array(
            'target' => '_blank',
          ),
        )) . '</p>';
      }
      break;
    case 'title':
      $item_text = '';
      break;
  }
  return $item_text;
}