<?php
// $Id: $


/**
 * Plugin declaration function - returns a plugin definition array that
 * describes the content type.
 */
function panels_node_links_panels_content_types() {
  $items['node_links'] = array(
    'title' => t('Node links'),
    'content_types' => 'panels_admin_content_types_node_links',
    'single' => TRUE,
    'render callback' => 'panels_content_node_links',
    'add callback' => 'panels_admin_edit_node_links',
    'edit callback' => 'panels_admin_edit_node_links',
    'title callback' => 'panels_admin_title_node_links',
  );
  return $items;
}

function panels_content_node_links($subtype, $conf, $panel_args, $context) {
  $node = isset($context->data) ? drupal_clone($context->data) : NULL;
  $block = new stdClass();
  $block->module = 'node';
  $block->delta  = $node->nid;

  $block->subject = t('Links');
  $block->content = panels_node_links_render($node, $conf);

  return $block;
}

/**
 * Return all content types available.
 */
function panels_admin_content_types_node_links() {
  return array(
    'links' => array(
      'title' => t('Node links'),
      'icon' => 'icon_node.png',
      'path' => panels_get_path('content_types/node'),
      'description' => t('The links of the referenced node.'),
      'required context' => new panels_required_context(t('Node'), 'node'),
      'category' => array(t('Node context'), -9),
    ),
  );
}

function panels_admin_edit_node_links($id, $parents, $conf = array()) {
  $form = array();
  return $form;
}

function panels_admin_title_node_links($subtype, $conf, $context) {
  return t('"@s" links', array('@s' => $context->identifier));
}

function panels_node_links_render($node, $conf) {
  $links = module_invoke_all('link', 'node', $node, $node->teaser);

  foreach (module_implements('link_alter') as $module) {
    $function = $module .'_link_alter';
    $function($node, $links);
  }

  return theme('links', $links);
}