You are here

function freelinking_drupalorgnid_callback in Freelinking 6.3

1 string reference to 'freelinking_drupalorgnid_callback'
freelinking_dev.inc in plugins/freelinking_dev.inc

File

plugins/freelinking_dev.inc, line 18

Code

function freelinking_drupalorgnid_callback($target, $plugin) {

  // resolve nid to a node title
  if (!is_numeric($target['dest'])) {
    return array(
      'failover' => 'error',
      'message' => t('Invalid Node ID !nid', array(
        '!nid' => $target['dest'],
      )),
    );
  }
  $url = 'http://drupal.org/node/' . $target['dest'];
  if (!$target['text'] && variable_get('freelinking_drupalorgnid_http_request', TRUE)) {
    $result = drupal_http_request($url, array(), 'GET');
    if (isset($result->data)) {
      $found_title = preg_match('/<h1.*>(.*)<\\/h1>/', $result->data, $matches);
      if ($found_title) {

        // regex worked to scarf title of page
        $replacement = array(
          'Drupal.org: "' . check_plain($matches[1]) . '"',
          check_url($url),
        );
      }
    }
  }
  elseif ($target['text']) {
    $replacement = array(
      $target['text'],
      $url,
    );
  }
  if (empty($replacement)) {
    $replacement = array(
      'Drupal.org Node: ' . $target['dest'],
      $url,
    );
  }
  return $replacement;
}