}
$form['display'] = array(
- '#tree' => true,
+ '#tree' => TRUE,
);
$form['display']['url_cutoff'] = array(
'#type' => 'textfield',
'user' => t('Allow the user to choose'),
);
$form['attributes'] = array(
- '#tree' => true,
+ '#tree' => TRUE,
);
$form['attributes']['target'] = array(
'#type' => 'radios',
case 'validate':
$optional_field_found = FALSE;
- foreach($items as $delta => $value) {
- _link_validate($items[$delta],$delta, $field, $node, $optional_field_found);
+ foreach ($items as $delta => $value) {
+ _link_validate($items[$delta], $delta, $field, $node, $optional_field_found);
}
if ($field['url'] == 'optional' && $field['title'] == 'optional' && $field['required'] && !$optional_field_found) {
break;
case 'presave':
- foreach($items as $delta => $value) {
+ foreach ($items as $delta => $value) {
_link_process($items[$delta], $delta, $field, $node);
}
break;
if ($item['url'] && !(isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'] && !$field['required'])) {
// Validate the link.
if (link_validate_url(trim($item['url'])) == FALSE) {
- form_set_error($field['field_name'] .']['. $delta. '][url', t('Not a valid URL.'));
+ form_set_error($field['field_name'] .']['. $delta .'][url', t('Not a valid URL.'));
}
// Require a title for the link if necessary.
if ($field['title'] == 'required' && strlen(trim($item['title'])) == 0) {
- form_set_error($field['field_name'] .']['. $delta. '][title', t('Titles are required for all links.'));
+ form_set_error($field['field_name'] .']['. $delta .'][title', t('Titles are required for all links.'));
}
}
// Require a link if we have a title.
if ($field['url'] !== 'optional' && strlen($item['title']) > 0 && strlen(trim($item['url'])) == 0) {
- form_set_error($field['field_name'] .']['. $delta. '][url', t('You cannot enter a title without a link url.'));
+ form_set_error($field['field_name'] .']['. $delta .'][url', t('You cannot enter a title without a link url.'));
}
// In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link.
if ($field['url'] == 'optional' && $field['title'] == 'optional' && (strlen(trim($item['url'])) != 0 || strlen(trim($item['title'])) != 0)) {
// Create a shortened URL for display.
$display_url = $type == LINK_EMAIL ? str_replace('mailto:', '', $url) : url($url, array('query' => isset($item['query']) ? $item['query'] : NULL, 'fragment' => isset($item['fragment']) ? $item['fragment'] : NULL, 'absolute' => TRUE));
if ($field['display']['url_cutoff'] && strlen($display_url) > $field['display']['url_cutoff']) {
- $display_url = substr($display_url, 0, $field['display']['url_cutoff']) . "...";
+ $display_url = substr($display_url, 0, $field['display']['url_cutoff']) ."...";
}
$item['display_url'] = $display_url;
// Add attributes defined at the widget level
$attributes = array();
if (!empty($item['attributes']) && is_array($item['attributes'])) {
- foreach($item['attributes'] as $attribute => $attbvalue) {
+ foreach ($item['attributes'] as $attribute => $attbvalue) {
if (isset($item['attributes'][$attribute]) && $field['attributes'][$attribute] == 'user') {
$attributes[$attribute] = $attbvalue;
}
}
// Add attributes defined at the field level
if (is_array($field['attributes'])) {
- foreach($field['attributes'] as $attribute => $attbvalue) {
+ foreach ($field['attributes'] as $attribute => $attbvalue) {
if (!empty($attbvalue) && $attbvalue != 'default' && $attbvalue != 'user') {
$attributes[$attribute] = $attbvalue;
}
$element['url']['#title'] = $element['#title'] .' '. $element['url']['#title'];
$element['title']['#title'] = $element['#title'] .' '. $element['title']['#title'];
}
- elseif($element['url']) {
+ elseif ($element['url']) {
$element['url']['#title'] = $element['#title'];
}
}
$output = '';
$output .= '<div class="link-field-subrow clear-block">';
if (isset($element['title'])) {
- $output .= '<div class="link-field-title link-field-column">' . theme('textfield', $element['title']) . '</div>';
+ $output .= '<div class="link-field-title link-field-column">'. theme('textfield', $element['title']) .'</div>';
}
- $output .= '<div class="link-field-url' . (isset($element['title']) ? ' link-field-column' : '') . '">' . theme('textfield', $element['url']) . '</div>';
+ $output .= '<div class="link-field-url'. (isset($element['title']) ? ' link-field-column' : '') .'">'. theme('textfield', $element['url']) .'</div>';
$output .= '</div>';
if (!empty($element['attributes']['target'])) {
- $output .= '<div class="link-attributes">' . theme('checkbox', $element['attributes']['target']) . '</div>';
+ $output .= '<div class="link-attributes">'. theme('checkbox', $element['attributes']['target']) .'</div>';
}
return $output;
}
function link_views_api() {
return array(
'api' => 2,
- 'path' => drupal_get_path('module', 'link') . '/views',
+ 'path' => drupal_get_path('module', 'link') .'/views',
);
}
if ($type == LINK_EXTERNAL) {
// Check if there is no protocol specified.
- $protocol_match = preg_match("/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i",$url);
+ $protocol_match = preg_match("/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i", $url);
if (empty($protocol_match)) {
// But should there be? Add an automatic http:// if it starts with a domain name.
- $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)('. LINK_DOMAINS .'|[a-z]{2}))/i',$url);
+ $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)('. LINK_DOMAINS .'|[a-z]{2}))/i', $url);
if (!empty($domain_match)) {
- $url = $protocol."://".$url;
+ $url = $protocol ."://". $url;
}
}
}
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
- $protocol = '((' . implode("|", $allowed_protocols) . '):\/\/)';
+ $protocol = '(('. implode("|", $allowed_protocols) .'):\/\/)';
$authentication = '([a-z0-9]+(:[a-z0-9]+)?@)';
$domain = '(([a-z0-9]([a-z0-9\-_\[\]])*)(\.(([a-z0-9\-_\[\]])+\.)*('. LINK_DOMAINS .'|[a-z]{2}))?)';
$ipv4 = '([0-9]{1,3}(\.[0-9]{1,3}){3})';
$port = '(:([0-9]{1,5}))';
// Pattern specific to eternal links.
- $external_pattern = '/^' . $protocol . '?' . $authentication . '?' . '(' . $domain . '|' . $ipv4 . '|' . $ipv6 . ' |localhost)' . $port . '?';
+ $external_pattern = '/^'. $protocol .'?'. $authentication .'?('. $domain .'|'. $ipv4 .'|'. $ipv6 .' |localhost)'. $port .'?';
// Pattern specific to internal links.
$internal_pattern = "/^([a-z0-9_\-+\[\]]+)";
$anchor = "(#[a-z0-9_\-\.~+%=&,$'():;*@\[\]]*)";
// The rest of the path for a standard URL.
- $end = $directories . '?' . $query . '?' . $anchor . '?' . '$/i';
+ $end = $directories .'?'. $query .'?'. $anchor .'?'.'$/i';
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'\[\]]+';
- $email_pattern = '/^mailto:' . $user . '@' . '(' . $domain . '|' . $ipv4 .'|'. $ipv6 . '|localhost)' . $query . '?$/';
+ $email_pattern = '/^mailto:'. $user .'@'.'('. $domain .'|'. $ipv4 .'|'. $ipv6 .'|localhost)'. $query .'?$/';
if (strpos($text, '<front>') === 0) {
return LINK_FRONT;
<?php
+// $Id$
+/**
+ * @file
+ * Contains functions handling views integration.
+ */
/**
* Implementation of hook_views_handlers().
function link_views_handlers() {
return array(
'info' => array(
- 'path' => drupal_get_path('module', 'link') . '/views',
+ 'path' => drupal_get_path('module', 'link') .'/views',
),
'handlers' => array(
'link_views_handler_argument_target' => array(
// Build out additional views data for the link "title" field.
$data[$table_alias][$field['field_name'] .'_title'] = array(
'group' => t('Content'),
- 'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) . ' ('. $field['field_name'] .')',
+ 'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'argument' => array(
'field' => $db_info['columns']['title']['column'],
// TODO: Add a protocol argument.
$data[$table_alias][$field['field_name'] .'_protocol'] = array(
'group' => t('Content'),
- 'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) . ' ('. $field['field_name'] .')',
+ 'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'filter' => array(
'field' => $db_info['columns']['url']['column'],
// TODO: Add a target filter.
$data[$table_alias][$field['field_name'] .'_target'] = array(
'group' => t('Content'),
- 'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) . ' ('. $field['field_name'] .')',
+ 'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'help' => $data[$table_alias][$field['field_name'] .'_url']['help'],
'argument' => array(
'field' => $db_info['columns']['attributes']['column'],
- 'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) . ' ('. $field['field_name'] .')',
+ 'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
'tablename' => $db_info['table'],
'handler' => 'link_views_handler_argument_target',
'additional fields' => array(),