View source
<?php
$freelinking['drupalorgnid'] = array(
'indicator' => '/d(rupal)?o(rg)?/',
'callback' => 'freelinking_drupalorgnid_callback',
'tip' => t('Link to a drupal.org node.'),
);
function freelinking_drupalorgnid_callback($target, $plugin) {
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) {
$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;
}
function freelinking_drupalorgnid_settings() {
$form['freelinking_drupalorgnid_http_request'] = array(
'#type' => 'checkbox',
'#title' => t('Get node title'),
'#default_value' => variable_get('freelinking_drupalorgnid_http_request', TRUE),
'#description' => t('Get node title from drupal.org.'),
);
return $form;
}
$freelinking['drupalproject'] = array(
'indicator' => '/d(rupal)?project/',
'translate' => array(
' ' => '_',
),
'replacement' => 'http://drupal.org/project/%1',
'tip' => t('Link to a project on drupal.org by name.'),
);