non security modules update

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 16:32:07 +02:00
parent 6a8d30db08
commit 37fbabab56
466 changed files with 32690 additions and 9652 deletions

View File

@@ -0,0 +1,17 @@
<?php
/**
* @file
* Provide diff field functions for the Email module.
*/
/**
* Diff field callback for parsing email fields comparative values.
*/
function email_field_diff_view($items, $context) {
$diff_items = array();
foreach ($items as $delta => $item) {
$diff_items[$delta] = $item['email'];
}
return $diff_items;
}

View File

@@ -5,9 +5,9 @@ package = Fields
files[] = email.migrate.inc
; Information added by drupal.org packaging script on 2012-08-29
version = "7.x-1.2"
; Information added by Drupal.org packaging script on 2014-04-10
version = "7.x-1.3"
core = "7.x"
project = "email"
datestamp = "1346254131"
datestamp = "1397134155"

View File

@@ -10,7 +10,7 @@ class MigrateEmailFieldHandler extends MigrateFieldHandler {
$this->registerTypes(array('email'));
}
public function prepare(stdClass $entity, array $field_info, array $instance, array $values) {
public function prepare($entity, array $field_info, array $instance, array $values) {
// Setup the Field API array for saving.
$arguments = (isset($values['arguments'])) ? $values['arguments']: array();
$language = $this->getFieldLanguage($entity, $field_info, $arguments);

View File

@@ -1,5 +1,9 @@
<?php
/**
* @file
* Module file for the email module, which creates a email address field.
*/
/**
* Implements hook_field_info().
@@ -20,7 +24,10 @@ function email_field_info() {
* Implements hook_migrate_api().
*/
function email_migrate_api() {
return array('api' => 2);
return array(
'api' => 2,
'field handlers' => array('MigrateEmailFieldHandler'),
);
}
/**
@@ -198,7 +205,7 @@ function email_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('email_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
@@ -433,7 +440,7 @@ function email_mail_page_form_submit($form, &$form_state) {
// Log the operation:
flood_register_event('email');
watchdog('mail', t('%name-from sent an e-mail at %form.', array('%name-from' => $form_state['values']['name'], '%form' => url($_GET['q'], array('absolute' => TRUE)))));
watchdog('mail', '%name-from sent an e-mail at %form.', array('%name-from' => $form_state['values']['name'], '%form' => url($_GET['q'], array('absolute' => TRUE))));
drupal_set_message(t('Your message has been sent.'));
$form_state['redirect'] = $path;
@@ -447,7 +454,7 @@ function email_mail($key, &$message, $params) {
switch ($key) {
case 'contact':
// Compose the body:
$message['body'][] = t('@name sent a message using the contact form at @url.', array('@name' => $params['name'], '@url' => $params['url']), array('langcode' =>$language->language));
$message['body'][] = t('@name sent a message using the contact form at @url.', array('@name' => $params['name'], '@url' => $params['url']), array('langcode' => $language->language));
$message['body'][] = $params['message'];
$message['subject'] = "";

View File

@@ -0,0 +1,8 @@
.link-field-column {
float: right;
}
.link-field-column.link-field-url .form-text {
direction: ltr;
text-align: left;
}

View File

@@ -21,9 +21,12 @@ function link_devel_generate($object, $field, $instance, $bundle) {
* Callback for hook_devel_generate().
*/
function _link_devel_generate($object, $field, $instance, $bundle) {
return array(
$link = array(
'url' => url('<front>', array('absolute' => TRUE)),
'title' => devel_create_greeking(mt_rand(1, 3), TRUE),
'attributes' => _link_default_attributes(),
);
if ($instance['settings']['title'] != 'none') {
$link['title'] = devel_create_greeking(mt_rand(1, 3), TRUE);
}
return $link;
}

View File

@@ -18,9 +18,9 @@ files[] = tests/link.validate.test
files[] = views/link_views_handler_argument_target.inc
files[] = views/link_views_handler_filter_protocol.inc
; Information added by drupal.org packaging script on 2013-02-09
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2014-10-21
version = "7.x-1.3"
core = "7.x"
project = "link"
datestamp = "1360444361"
datestamp = "1413924830"

View File

@@ -97,7 +97,12 @@ class MigrateLinkFieldHandler extends MigrateFieldHandler {
}
}
if (isset($arguments['attributes'])) {
$item['attributes'] = $arguments['attributes'];
if (is_array($arguments['attributes']) && isset($arguments['attributes'][$delta])) {
$item['attributes'] = $arguments['attributes'][$delta];
}
else {
$item['attributes'] = $arguments['attributes'];
}
}
$item['url'] = $value;
$return[$language][$delta] = $item;

View File

@@ -10,7 +10,7 @@ define('LINK_INTERNAL', 'internal');
define('LINK_FRONT', 'front');
define('LINK_EMAIL', 'email');
define('LINK_NEWS', 'news');
define('LINK_DOMAINS', 'aero|arpa|asia|biz|com|cat|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobi|local');
define('LINK_DOMAINS', 'aero|arpa|asia|biz|build|com|cat|ceo|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|post|pro|tel|travel|mobi|local|xxx');
define('LINK_TARGET_DEFAULT', 'default');
define('LINK_TARGET_NEW_WINDOW', '_blank');
@@ -46,12 +46,14 @@ function link_field_info() {
'url' => 0,
'title' => 'optional',
'title_value' => '',
'title_label_use_field_label' => FALSE,
'title_maxlength' => 128,
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'validate_url' => 1,
'absolute_url' => 1,
),
'default_widget' => 'link_field',
'default_formatter' => 'link_default',
@@ -70,6 +72,13 @@ function link_field_instance_settings_form($field, $instance) {
'#element_validate' => array('link_field_settings_form_validate'),
);
$form['absolute_url'] = array(
'#type' => 'checkbox',
'#title' => t('Absolute URL'),
'#default_value' => isset($instance['settings']['absolute_url']) && ($instance['settings']['absolute_url'] !== '') ? $instance['settings']['absolute_url'] : TRUE,
'#description' => t('If checked, the URL will always render as an absolute URL.'),
);
$form['validate_url'] = array(
'#type' => 'checkbox',
'#title' => t('Validate URL'),
@@ -107,6 +116,13 @@ function link_field_instance_settings_form($field, $instance) {
'#description' => t('This title will always be used if &ldquo;Static Title&rdquo; is selected above.'),
);
$form['title_label_use_field_label'] = array(
'#type' => 'checkbox',
'#title' => t('Use field label as the label for the title field'),
'#default_value' => isset($instance['settings']['title_label_use_field_label']) ? $instance['settings']['title_label_use_field_label'] : FALSE,
'#description' => t('If this is checked the field label will be hidden.'),
);
$form['title_maxlength'] = array(
'#type' => 'textfield',
'#title' => t('Max length of title field'),
@@ -117,28 +133,22 @@ function link_field_instance_settings_form($field, $instance) {
);
if (module_exists('token')) {
// Add token module replacements fields
$form['tokens'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Placeholder tokens'),
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
);
$entity_info = entity_get_info($instance['entity_type']);
$form['tokens']['help'] = array(
'#theme' => 'token_tree',
'#token_types' => array($entity_info['token type']),
'#global_types' => TRUE,
'#click_insert' => TRUE,
);
// Add token module replacements fields.
$form['enable_tokens'] = array(
'#type' => 'checkbox',
'#title' => t('Allow user-entered tokens'),
'#default_value' => isset($instance['settings']['enable_tokens']) ? $instance['settings']['enable_tokens'] : 1,
'#description' => t('Checking will allow users to enter tokens in URLs and Titles on the entity edit form. This does not affect the field settings on this page.'),
);
$entity_info = entity_get_info($instance['entity_type']);
$form['tokens_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array($entity_info['token type']),
'#global_types' => TRUE,
'#click_insert' => TRUE,
'#dialog' => TRUE,
);
}
$form['display'] = array(
@@ -189,6 +199,11 @@ function link_field_instance_settings_form($field, $instance) {
'#description' => t('Turn on/off if rel attribute should be removed automatically, if user given link is internal/external'),
'#options' => $rel_remove_options,
);
$form['attributes']['configurable_class'] = array(
'#title' => t("Allow the user to enter a custom link class per link"),
'#type' => 'checkbox',
'#default_value' => empty($instance['settings']['attributes']['configurable_class']) ? '' : $instance['settings']['attributes']['configurable_class'],
);
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
@@ -258,12 +273,16 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode
$optional_field_found = FALSE;
if ($instance['settings']['validate_url'] !== 0 || is_null($instance['settings']['validate_url']) || !isset($instance['settings']['validate_url'])) {
foreach ($items as $delta => $value) {
_link_validate($items[$delta], $delta, $field, $entity, $instance, $langcode, $optional_field_found);
_link_validate($items[$delta], $delta, $field, $entity, $instance, $langcode, $optional_field_found, $errors);
}
}
if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] && !$optional_field_found) {
form_set_error($field['field_name'] . '][' . $langcode . '][0][title', t('At least one title or URL must be entered.'));
$errors[$field['field_name']][$langcode][0][] = array(
'error' => 'link_required',
'message' => t('At least one title or URL must be entered.'),
'error_element' => array('url' => FALSE, 'title' => TRUE),
);
}
}
@@ -320,6 +339,18 @@ function link_field_widget_form(&$form, &$form_state, $field, $instance, $langco
return $element;
}
/**
* Implements hook_field_widget_error().
*/
function link_field_widget_error($element, $error, $form, &$form_state) {
if ($error['error_element']['title']) {
form_error($element['title'], $error['message']);
}
elseif ($error['error_element']['url']) {
form_error($element['url'], $error['message']);
}
}
/**
* Unpacks the item attributes for use.
*/
@@ -341,9 +372,11 @@ function _link_load($field, $item, $instance) {
/**
* Prepares the item attributes and url for storage.
*/
function _link_process(&$item, $delta = 0, $field, $entity) {
function _link_process(&$item, $delta, $field, $entity) {
// Trim whitespace from URL.
$item['url'] = trim($item['url']);
if (!empty($item['url'])) {
$item['url'] = trim($item['url']);
}
// If no attributes are set then make sure $item['attributes'] is an empty
// array, so $field['attributes'] can override it.
@@ -367,41 +400,61 @@ function _link_process(&$item, $delta = 0, $field, $entity) {
/**
* Validates that the link field has been entered properly.
*/
function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found) {
function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found, &$errors) {
if ($item['url'] && !(isset($instance['default_value'][$delta]['url']) && $item['url'] === $instance['default_value'][$delta]['url'] && !$instance['required'])) {
// Validate the link.
if (link_validate_url(trim($item['url'])) == FALSE) {
form_set_error($field['field_name'] . '][' . $langcode . '][' . $delta . '][url', t('The value provided for %field is not a valid URL.', array('%field' => $instance['label'])));
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'link_required',
'message' => t('The value %value provided for %field is not a valid URL.', array(
'%value' => trim($item['url']),
'%field' => $instance['label'],
)),
'error_element' => array('url' => TRUE, 'title' => FALSE),
);
}
// Require a title for the link if necessary.
if ($instance['settings']['title'] == 'required' && strlen(trim($item['title'])) == 0) {
form_set_error($field['field_name'] . '][' . $langcode . '][' . $delta . '][title', t('Titles are required for all links.'));
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'link_required',
'message' => t('Titles are required for all links.'),
'error_element' => array('url' => FALSE, 'title' => TRUE),
);
}
}
// Require a link if we have a title.
if ($instance['settings']['url'] !== 'optional' && strlen(isset($item['title']) ? $item['title'] : NULL) > 0 && strlen(trim($item['url'])) == 0) {
form_set_error($field['field_name'] . '][' . $langcode . '][' . $delta . '][url', t('You cannot enter a title without a link url.'));
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'link_required',
'message' => t('You cannot enter a title without a link url.'),
'error_element' => array('url' => TRUE, 'title' => FALSE),
);
}
// In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link.
if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && (strlen(trim($item['url'])) !== 0 || strlen(trim($item['title'])) !== 0)) {
if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional'
&& (strlen(trim($item['url'])) !== 0 || strlen(trim($item['title'])) !== 0)) {
$optional_field_found = TRUE;
}
// Require entire field
// Require entire field.
if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] == 1 && !$optional_field_found && isset($instance['id'])) {
form_set_error($instance['field_name'] . '][' . $langcode . '][0][title', t('At least one title or URL must be entered.'));
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'link_required',
'message' => t('At least one title or URL must be entered.'),
'error_element' => array('url' => FALSE, 'title' => TRUE),
);
}
}
/**
* Clean up user-entered values for a link field according to field settings.
*
* @param $item
* @param array $item
* A single link item, usually containing url, title, and attributes.
* @param $delta
* @param int $delta
* The delta value if this field is one of multiple fields.
* @param $field
* @param array $field
* The CCK field definition.
* @param $entity
* @param object $entity
* The entity containing this link.
*/
function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
@@ -409,6 +462,9 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
if (empty($item['url']) && empty($item['title'])) {
return;
}
if (empty($item['html'])) {
$item['html'] = FALSE;
}
// Replace URL tokens.
$entity_type = $instance['entity_type'];
@@ -439,19 +495,13 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$url = link_cleanup_url($item['url']);
$url_parts = _link_parse_url($url);
// We can't check_plain('<front>') because it'll break.
if ($type != LINK_FRONT) {
$url_parts['url'] = check_plain($url_parts['url']);
}
if (!empty($url_parts['url'])) {
$item['url'] = url($url_parts['url'],
array(
'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL,
'absolute' => TRUE,
'html' => TRUE,
)
$item['url'] = $url_parts['url'];
$item += array(
'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL,
'absolute' => !empty($instance['settings']['absolute_url']),
'html' => TRUE,
);
}
@@ -464,7 +514,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
array(
'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL,
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL,
'absolute' => TRUE,
'absolute' => !empty($instance['settings']['absolute_url']),
)
);
}
@@ -489,7 +539,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$title = '';
}
// Replace tokens.
// Replace title tokens.
if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) {
// Load the entity if necessary for entities in views.
if (isset($entity->{$property_id})) {
@@ -511,7 +561,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Unserialize attributtes array if it has not been unserialized yet.
if (!is_array($item['attributes'])) {
$item['attributes'] = (array)unserialize($item['attributes']);
$item['attributes'] = (array) unserialize($item['attributes']);
}
// Add default attributes.
@@ -560,6 +610,16 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
$item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
}
// Handle attribute classes.
if (!empty($item['attributes']['class'])) {
$classes = explode(' ', $item['attributes']['class']);
foreach ($classes as &$class) {
$class = drupal_html_class($class);
}
$item['attributes']['class'] = implode(' ', $classes);
}
unset($item['attributes']['configurable_class']);
// Remove title attribute if it's equal to link text.
if (isset($item['attributes']['title']) && $item['attributes']['title'] == $item['title']) {
unset($item['attributes']['title']);
@@ -568,15 +628,6 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Remove empty attributes.
$item['attributes'] = array_filter($item['attributes']);
// Sets title to trimmed url if one exists
// @todo: Obsolete?
/*if(!empty($item['display_url']) && empty($item['title'])) {
$item['title'] = $item['display_url'];
}
elseif(!isset($item['title'])) {
$item['title'] = $item['url'];
}*/
}
/**
@@ -585,7 +636,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
* @param string $url
* URL to parse.
*
* @return Array
* @return array
* Array of url pieces - only 'url', 'query', and 'fragment'.
*/
function _link_parse_url($url) {
@@ -598,51 +649,77 @@ function _link_parse_url($url) {
// Separate out the query string, if any.
if (strpos($url, '?') !== FALSE) {
$query = substr($url, strpos($url, '?') + 1);
parse_str($query, $query_array);
// See http://drupal.org/node/1710578
foreach ($query_array as $key=> &$value) {
if ($value === '' && FALSE === strpos($query, $key . '=')) {
$value = NULL;
}
}
$url_parts['query'] = $query_array;
$url_parts['query'] = _link_parse_str($query);
$url = substr($url, 0, strpos($url, '?'));
}
$url_parts['url'] = $url;
return $url_parts;
}
/**
* Replaces the PHP parse_str() function.
*
* Because parse_str replaces the following characters in query parameters name
* in order to maintain compability with deprecated register_globals directive:
*
* - chr(32) ( ) (space)
* - chr(46) (.) (dot)
* - chr(91) ([) (open square bracket)
* - chr(128) - chr(159) (various)
*
* @param string $query
* Query to parse.
*
* @return array
* Array of query parameters.
*
* @see http://php.net/manual/en/language.variables.external.php#81080
*/
function _link_parse_str($query) {
$query_array = array();
$pairs = explode('&', $query);
foreach ($pairs as $pair) {
$name_value = explode('=', $pair, 2);
$name = urldecode($name_value[0]);
$value = isset($name_value[1]) ? urldecode($name_value[1]) : NULL;
$query_array[$name] = $value;
}
return $query_array;
}
/**
* Implements hook_theme().
*/
function link_theme() {
return array(
'link_formatter_link_default' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_plain' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_absolute' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_domain' => array(
'variables' => array('element' => NULL, 'display' => NULL),
'variables' => array('element' => NULL, 'display' => NULL, 'field' => NULL),
),
'link_formatter_link_title_plain' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_url' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_short' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_label' => array(
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_formatter_link_separate' => array(
'variables' => array('element' => NULL),
'variables' => array('element' => NULL, 'field' => NULL),
),
'link_field' => array(
'render element' => 'element',
@@ -668,7 +745,7 @@ function theme_link_field($vars) {
if (isset($element['title'])) {
$output .= '<div class="link-field-title link-field-column">' . drupal_render($element['title']) . '</div>';
}
$output .= '<div class="link-field-url' . (isset($element['title']) ? ' link-field-column' : '') . '">'. drupal_render($element['url']) . '</div>';
$output .= '<div class="link-field-url' . (isset($element['title']) ? ' link-field-column' : '') . '">' . drupal_render($element['url']) . '</div>';
$output .= '</div>';
if (!empty($element['attributes']['target'])) {
$output .= '<div class="link-attributes">' . drupal_render($element['attributes']['target']) . '</div>';
@@ -676,6 +753,10 @@ function theme_link_field($vars) {
if (!empty($element['attributes']['title'])) {
$output .= '<div class="link-attributes">' . drupal_render($element['attributes']['title']) . '</div>';
}
if (!empty($element['attributes']['class'])) {
$output .= '<div class="link-attributes">' . drupal_render($element['attributes']['class']) . '</div>';
}
$output .= drupal_render_children($element);
return $output;
}
@@ -723,10 +804,21 @@ function link_field_process($element, $form_state, $complete_form) {
'#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
);
if ($settings['title'] !== 'none' && $settings['title'] !== 'value') {
// Figure out the label of the title field.
if (!empty($settings['title_label_use_field_label'])) {
// Use the element label as the title field label.
$title_label = $element['#title'];
// Hide the field label because there is no need for the duplicate labels.
$element['#title_display'] = 'invisible';
}
else {
$title_label = t('Title');
}
$element['title'] = array(
'#type' => 'textfield',
'#maxlength' => $settings['title_maxlength'],
'#title' => t('Title'),
'#title' => $title_label,
'#description' => t('The link title is limited to @maxlength characters maximum.', array('@maxlength' => $settings['title_maxlength'])),
'#required' => ($settings['title'] == 'required' && (($element['#delta'] == 0 && $element['#required']) || !empty($element['#value']['url']))) ? TRUE : FALSE,
'#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
@@ -757,6 +849,15 @@ function link_field_process($element, $form_state, $complete_form) {
'#field_suffix' => '"',
);
}
if (!empty($settings['attributes']['configurable_class']) && $settings['attributes']['configurable_class'] == 1) {
$element['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Custom link class'),
'#default_value' => isset($attributes['class']) ? $attributes['class'] : '',
'#field_prefix' => 'class = "',
'#field_suffix' => '"',
);
}
// If the title field is avaliable or there are field accepts multiple values
// then allow the individual field items display the required asterisk if needed.
@@ -886,14 +987,13 @@ function theme_link_formatter_link_default($vars) {
if (isset($link_options['attributes']['class'])) {
$link_options['attributes']['class'] = array($link_options['attributes']['class']);
}
// Display a normal link if both title and URL are available.
if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], $link_options);
}
// If only a title, display the title.
elseif (!empty($vars['element']['title'])) {
return check_plain($vars['element']['title']);
return $link_options['html'] ? $vars['element']['title'] : check_plain($vars['element']['title']);
}
elseif (!empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], $link_options);
@@ -916,7 +1016,7 @@ function theme_link_formatter_link_plain($vars) {
}
/**
* Formats a link as an absolute URL
* Formats a link as an absolute URL.
*/
function theme_link_formatter_link_absolute($vars) {
$absolute = array('absolute' => TRUE);
@@ -985,10 +1085,8 @@ function theme_link_formatter_link_separate($vars) {
unset($link_options['url']);
$title = empty($vars['element']['title']) ? '' : check_plain($vars['element']['title']);
/**
* @TODO static html markup looks not very elegant
* needs smarter output solution and an optional title/url seperator
*/
// @TODO static html markup looks not very elegant
// needs smarter output solution and an optional title/url seperator
$url_parts = _link_parse_url($vars['element']['url']);
$output = '';
$output .= '<div class="link-item ' . $class . '">';
@@ -1002,6 +1100,8 @@ function theme_link_formatter_link_separate($vars) {
/**
* Implements hook_token_list().
*
* @TODO: hook_token_list no longer exists - this should change to hook_token_info().
*/
function link_token_list($type = 'all') {
if ($type === 'field' || $type === 'all') {
@@ -1013,6 +1113,11 @@ function link_token_list($type = 'all') {
}
}
/**
* Implements hook_token_values().
*
* @TODO: hook_token_values no longer exists - this should change to hook_tokens().
*/
function link_token_values($type, $object = NULL) {
if ($type === 'field') {
$item = $object[0];
@@ -1042,6 +1147,7 @@ function link_views_api() {
* protocol specified
*
* @param string $url
* The url entered by the user.
* @param string $protocol
* The protocol to be prepended to the url if one is not specified
*/
@@ -1072,6 +1178,7 @@ function link_cleanup_url($url, $protocol = 'http') {
* addresses following the RFC 2368 standard for mailto address formation.
*
* @param string $text
* Url to be validated.
*
* @return mixed
* Returns boolean FALSE if the URL is not valid. On success, returns one of
@@ -1141,7 +1248,7 @@ function link_validate_url($text) {
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
$LINK_DOMAINS = _link_domains();
// Starting a parenthesis group with (?: means that it is grouped, but is not captured
// Starting a parenthesis group with (?: means that it is grouped, but is not captured.
$protocol = '((?:' . implode("|", $allowed_protocols) . '):\/\/)';
$authentication = "(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;=" . $LINK_ICHARS . "]|%[0-9a-f]{2})+(?::(?:[\w" . $LINK_ICHARS . "\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})*)?)?@)";
$domain = '(?:(?:[a-z0-9' . $LINK_ICHARS_DOMAIN . ']([a-z0-9' . $LINK_ICHARS_DOMAIN . '\-_\[\]])*)(\.(([a-z0-9' . $LINK_ICHARS_DOMAIN . '\-_\[\]])+\.)*(' . $LINK_DOMAINS . '|[a-z]{2}))?)';
@@ -1158,7 +1265,7 @@ function link_validate_url($text) {
$directories = "(?:\/[a-z0-9" . $LINK_ICHARS . "_\-\.~+%=&,$'#!():;*@\[\]]*)*";
// Yes, four backslashes == a single backslash.
$query = "(?:\/?\?([?a-z0-9" . $LINK_ICHARS . "+_|\-\.~\/\\\\%=&,$'():;*@\[\]{} ]*))";
$query = "(?:\/?\?([?a-z0-9" . $LINK_ICHARS . "+_|\-\.~\/\\\\%=&,$'!():;*@\[\]{} ]*))";
$anchor = "(?:#[a-z0-9" . $LINK_ICHARS . "_\-\.~+%=&,$'():;*@\[\]\/\?]*)";
// The rest of the path for a standard URL.
@@ -1169,7 +1276,7 @@ function link_validate_url($text) {
$news_pattern = '/^news:(' . $newsgroup_name . '|' . $message_id . ')$/i';
$user = '[a-zA-Z0-9' . $LINK_ICHARS . '_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'\[\]]+';
$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;
@@ -1251,7 +1358,7 @@ function link_field_settings_form() {
/**
* Additional callback to adapt the property info of link fields.
*
* @see entity_metadata_field_entity_property_info().
* @see entity_metadata_field_entity_property_info()
*/
function link_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
@@ -1295,16 +1402,27 @@ function link_field_item_property_info() {
'label' => t('The URL of the link.'),
'setter callback' => 'entity_property_verbatim_set',
);
$properties['attributes'] = array(
'type' => 'struct',
'label' => t('The attributes of the link.'),
'setter callback' => 'entity_property_verbatim_set',
'getter callback' => 'link_attribute_property_get',
);
return $properties;
}
/**
* Entity property info getter callback for link attributes.
*/
function link_attribute_property_get($data, array $options, $name, $type, $info) {
return isset($data[$name]) ? array_filter($data[$name]) : array();
}
/**
* Implements hook_field_update_instance().
*/
function link_field_update_instance($instance, $prior_instance) {
if (function_exists('i18n_string_update')
&& isset($prior_instance['settings']['title_value']) && isset($instance['settings']['title_value'])
&& $prior_instance['settings']['title_value'] != $instance['settings']['title_value']) {
if (function_exists('i18n_string_update') && $instance['widget']['type'] == 'link_field' && $prior_instance['settings']['title_value'] != $instance['settings']['title_value']) {
$i18n_string_name = "field:{$instance['field_name']}:{$instance['bundle']}:title_value";
i18n_string_update($i18n_string_name, $instance['settings']['title_value']);
}
@@ -1314,9 +1432,10 @@ function link_field_update_instance($instance, $prior_instance) {
* Implements hook_i18n_string_list_TEXTGROUP_alter().
*/
function link_i18n_string_list_field_alter(&$strings, $type = NULL, $object = NULL) {
if ($type == 'field_instance' && $object && $object['widget']['type'] == 'link_field') {
if (isset($object['settings']['title_value'])) {
$strings['field'][$object['field_name']][$object['bundle']]['title_value']['string'] = $object['settings']['title_value'];
}
if ($type != 'field_instance' || !is_array($object) || !isset($object['widget']['type'])) {
return;
}
if ($object['widget']['type'] == 'link_field' && isset($object['settings']['title_value'])) {
$strings['field'][$object['field_name']][$object['bundle']]['title_value']['string'] = $object['settings']['title_value'];
}
}

View File

@@ -46,8 +46,8 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
protected function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
$this->zebra++;
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
$cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
$this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is',
$cssFieldLocator = 'field-' . str_replace('_', '-', $field_name);
$this->assertPattern('@<div class="field field-type-link ' . $cssFieldLocator . '".*<div class="field-item ' . $zebra_string . '">\s*' . $link_value . '\s*</div>@is',
$message,
$group);
}
@@ -66,7 +66,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// Create the content type.
$this->clickLink(t('Add content type'));
$edit = array (
$edit = array(
'name' => $content_type_friendly,
'type' => $content_type_machine,
);
@@ -76,8 +76,8 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
$single_field_name = 'field_'. $single_field_name_machine;
$edit = array (
$single_field_name = 'field_' . $single_field_name_machine;
$edit = array(
'fields[_add_new_field][label]' => $single_field_name_friendly,
'fields[_add_new_field][field_name]' => $single_field_name_machine,
'fields[_add_new_field][type]' => 'link_field',
@@ -112,19 +112,19 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->drupalLogin($this->web_user);
// Go to page.
$this->drupalGet('node/add/'. $content_type_machine);
$this->drupalGet('node/add/' . $content_type_machine);
// Add a node.
$edit = array(
'title' => $title,
'field_'. $single_field_name_machine. '[und][0][title]' => 'Link',
'field_'. $single_field_name_machine. '[und][0][url]' => 'http://www.drupal.org/',
'field_' . $single_field_name_machine . '[und][0][title]' => 'Link',
'field_' . $single_field_name_machine . '[und][0][url]' => 'http://www.drupal.org/',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
$this->drupalGet('node/add/'. $content_type_machine);
$this->drupalGet('node/add/' . $content_type_machine);
// Create a node:
$edit = array(
@@ -143,7 +143,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
protected function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) {
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/fields');
$edit = array (
$edit = array(
'fields[_add_new_field][label]' => $single_field_name_friendly,
'fields[_add_new_field][field_name]' => $single_field_name_machine,
'fields[_add_new_field][type]' => 'link_field',
@@ -180,7 +180,7 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
}
protected function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') {
$this->drupalGet('node/add/'. $content_type_machine);
$this->drupalGet('node/add/' . $content_type_machine);
if (!$node_title) {
$node_title = $this->randomName(20);
@@ -219,10 +219,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -270,10 +270,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_url',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -320,10 +320,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_short',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -371,10 +371,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_label',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -422,10 +422,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_separate',
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -474,10 +474,10 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
// Okay, now we want to make sure this display is changed:
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
$this->drupalGet('admin/structure/types/manage/' . $content_type_machine . '/display');
$edit = array(
'fields[field_'. $single_field_name_machine .'][label]' => 'above',
'fields[field_'. $single_field_name_machine .'][type]' => 'link_title_plain',
'fields[field_' . $single_field_name_machine . '][label]' => 'above',
'fields[field_' . $single_field_name_machine . '][type]' => 'link_title_plain',
);
$this->drupalPost(NULL, $edit, t('Save'));

View File

@@ -37,18 +37,17 @@ class LinkContentCrudTest extends DrupalWebTestCase {
// Create the content type.
$this->clickLink(t('Add content type'));
$edit = array (
$edit = array(
'name' => $content_type_friendly,
'type' => $content_type_machine,
);
$this->drupalPost(NULL, $edit, t('Save and add fields'));
$this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
//$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
$edit = array (
$edit = array(
'fields[_add_new_field][label]' => $single_field_name_friendly,
'fields[_add_new_field][field_name]' => $single_field_name_machine,
'fields[_add_new_field][type]' => 'link_field',
@@ -69,14 +68,5 @@ class LinkContentCrudTest extends DrupalWebTestCase {
menu_rebuild();
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
/*$table_schema = drupal_get_schema();
$this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
// Check the schema - the values should be in the per-type table.
$this->assertSchemaMatchesTables(array(
'per_type' => array(
$this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
),
));*/
}
}

View File

@@ -76,8 +76,8 @@ class LinkUITest extends DrupalWebTestcase {
//$this->drupalGet('node/add');
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$input_test_cases = array(
array(
@@ -104,26 +104,32 @@ class LinkUITest extends DrupalWebTestcase {
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
),
array(
array(
'href' => 'http://example.com/' . $this->randomName(),
'label' => $this->randomName() . '\' onmouseover="alert(\'hi\')',
'msg' => 'js label',
'type' => self::LINK_INPUT_TYPE_BAD_TITLE
),
array(
array(
'href' => 'javascript:alert("http://example.com/' . $this->randomName() . '")',
'label' => $this->randomName(),
'msg' => 'js url',
'type' => self::LINK_INPUT_TYPE_BAD_URL
),
array(
'href' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
'label' => 'http://ecs-es.kelkoo.es/ctl/go/sitesearchGo?.ts=1338833010331&.sig=qP9GXeEFH6syBzwmzYkxmsvp1EI-',
'msg' => 'Url with . in querystring',
'type' => self::LINK_INPUT_TYPE_GOOD,
),
);
$test_case = array(
'href' => 'www.example.com/'. $this->randomName(),
'href' => 'www.example.com/' . $this->randomName(),
'label' => $this->randomName(),
'msg' => 'Link found',
'type' => self::LINK_INPUT_TYPE_GOOD,
);
$test_case['expected_href'] = 'http://'. $test_case['href'];
$test_case['expected_href'] = 'http://' . $test_case['href'];
$input_test_cases[] = $test_case;
foreach ($input_test_cases as $input) {
@@ -137,17 +143,17 @@ class LinkUITest extends DrupalWebTestcase {
);
$this->drupalPost(NULL, $edit, t('Save'));
if ($input['type'] == self::LINK_INPUT_TYPE_BAD_URL) {
$this->assertRaw(t('The value provided for %field is not a valid URL.', array('%field' => $name)), 'Not a valid URL: ' . $input['href']);
$this->assertRaw(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($input['href']))), 'Not a valid URL: ' . $input['href']);
continue;
}
else {
$this->assertRaw(t(' has been created.',
$this->assertRaw(' ' . t('has been created.',
array('@type' => 'Basic Page', '%title' => $edit['title'])),
'Page created: ' . $input['href']);
}
$url = $this->getUrl();
// change to anonym user
// change to Anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
@@ -156,12 +162,11 @@ class LinkUITest extends DrupalWebTestcase {
// us and let us know it's broken.
$this->assertFalse(libxml_use_internal_errors(TRUE));
if (isset($input['expected_href'])) {
$path = '//a[@href="'. $input['expected_href'] .'" and text()="'. $input['label'] .'"]';
$path = '//a[@href="' . $input['expected_href'] . '" and text()="' . $input['label'] . '"]';
}
else {
$path = '//a[@href="'. $input['href'] .'" and text()="'. $input['label'] .'"]';
$path = '//a[@href="' . $input['href'] . '" and text()="' . $input['label'] . '"]';
}
//$this->pass(htmlentities($path));
$elements = $this->xpath($path);
libxml_use_internal_errors(FALSE);
$this->assertIdentical(isset($elements[0]), $input['type'] == self::LINK_INPUT_TYPE_GOOD, $input['msg']);
@@ -179,7 +184,7 @@ class LinkUITest extends DrupalWebTestcase {
// create field
$name = strtolower($this->randomName());
$field_name = 'field_'. $name;
$field_name = 'field_' . $name;
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
@@ -190,7 +195,7 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => '<strong>'. $name .'</strong>'), t('Save settings'));
'instance[settings][title_value]' => '<strong>' . $name . '</strong>'), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
@@ -215,7 +220,57 @@ class LinkUITest extends DrupalWebTestcase {
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
$this->assertRaw(l('<strong>' . $name . '</strong>', $input['href'], array('html' => TRUE)));
}
/**
* Testing that if you have the title but no url, the title is not sanitized twice.
*/
function testCRUDTitleOnlyTitleNoLink() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][url]' => 1,
), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => '',
);
$edit = array(
'title' => $name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
}
/**
@@ -242,25 +297,19 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
//_content_type_info(TRUE);
//$fields = content_fields();
//$field = $fields['field_'. $name];
//$field = field_info_field('field_'. $name);
_field_info_collate_fields(TRUE);
$instances = field_info_instances('node', 'page');
//$this->debug($instances);
//$this->assert('debug', '<pre>'. print_r($instances, TRUE) .'</pre>', 'Debug');
$instance = $instances['field_'. $name];
//$this->assertTrue(1 === $instance['validate_url'], 'Make sure validation is on.');
$instance = $instances['field_' . $name];
$this->assertFalse($instance['required'], 'Make sure field is not required.');
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.');
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
//$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
}
}

View File

@@ -36,8 +36,8 @@ class LinkBaseTestClass extends DrupalWebTestCase {
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$field_name = 'field_'. $name;
$this->drupalPost('admin/structure/types/manage/'. $node_type .'/fields', $edit, t('Save'));
$field_name = 'field_' . $name;
$this->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, $settings, t('Save settings'));

View File

@@ -75,7 +75,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:content-type:machine-name]');
'instance[settings][title_value]' => $name . ' [node:content-type:machine-name]');
$field_name = $this->createLinkField('page', $settings);
// create page form
@@ -118,7 +118,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$name = $this->randomName();
$settings = array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $name .' [node:title]');
'instance[settings][title_value]' => $name . ' [node:title]');
$field_name = $this->createLinkField('page', $settings);
// create page form
@@ -144,7 +144,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($name .' '. $name, $input['href']));
$this->assertRaw(l($name . ' ' . $name, $input['href']));
}
// This test doesn't seem to actually work, due to lack of 'title' in url.
@@ -191,9 +191,9 @@ class LinkTokenTest extends LinkBaseTestClass {
$edit = array();
$test_link_url = 'http://www.example.com/test';
$edit[$field_name .'[und][0][url]'] = $test_link_url;
$title = 'title_'. $this->randomName(20);
$edit[$field_name .'[und][0][title]'] = $title;
$edit[$field_name . '[und][0][url]'] = $test_link_url;
$title = 'title_' . $this->randomName(20);
$edit[$field_name . '[und][0][title]'] = $title;
$edit['title'] = $name;
$this->drupalGet('node/add/page');
@@ -206,8 +206,8 @@ class LinkTokenTest extends LinkBaseTestClass {
//$this->drupalGet('node/'. $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?");
$this->assertNoRaw(' title="['. $field_name .'-url]"');
$this->assertRaw(' title="' . $test_link_url . '"', "Do we show the link url as the title attribute?");
$this->assertNoRaw(' title="[' . $field_name . '-url]"');
$this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
//$this->fail($this->content);
}
@@ -236,10 +236,10 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_db_info = content_database_info($field);
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-title]',
$edit = array('attributes[title]' => '[' . $field_name . '-title]',
'enable_tokens' => TRUE);
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'],
$edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
@@ -248,14 +248,14 @@ class LinkTokenTest extends LinkBaseTestClass {
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/'. $this->nodes[0]->nid);
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
$title = 'title_'. $this->randomName(20);
$edit[$field['field_name'] .'[0][title]'] = $title;
$edit[$field['field_name'] . '[0][url]'] = 'http://www.example.com/test';
$title = 'title_' . $this->randomName(20);
$edit[$field['field_name'] . '[0][title]'] = $title;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
@@ -263,10 +263,10 @@ class LinkTokenTest extends LinkBaseTestClass {
array('@title' => $node->title,
'@type' => $this->content_types[0]->name)));
$this->drupalGet('node/'. $node->nid);
$this->drupalGet('node/' . $node->nid);
$this->assertText($title, 'Make sure the link title/text shows');
$this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?");
$this->assertNoRaw(' title="['. $field_name .'-title]"');
$this->assertNoRaw(' title="' . $title . '"', "We should not show the link title as the title attribute?");
$this->assertNoRaw(' title="[' . $field_name . '-title]"');
//$this->fail($this->content);
}
@@ -319,7 +319,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/page'));
$this->assertRaw(l($input['label'], $input['href'] . '/page'));
//$this->fail($this->content);
}
@@ -372,6 +372,58 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] .'/'. $this->web_user->uid));
$this->assertRaw(l($input['label'], $input['href'] . '/' . $this->web_user->uid));
}
/**
* Test that if you have a title and no url on a field which does not have tokens enabled,
* that the title is sanitized once.
*/
function testCRUDTitleOnlyTitleNoLink2() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][url]' => 1,
'instance[settings][enable_tokens]' => 0,
), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => '',
);
$edit = array(
'title' => $name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
}
}

View File

@@ -34,7 +34,7 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$field_name . '[und][0][url]' => $url,
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t(' has been created.'), 'Node created');
$this->assertRaw(' has been created.', 'Node created');
$nid = 1; //$matches[1];
@@ -90,17 +90,17 @@ class LinkValidateTest extends LinkValidateTestCase {
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('The value provided for @field is not a valid URL.', array('@field' => $name)));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array('@value' => 'edik:naw', '@field' => $name)));
}
/**
@@ -135,17 +135,17 @@ class LinkValidateTest extends LinkValidateTestCase {
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('The value provided for @field is not a valid URL.', array('@field' => $name)));
$this->assertText(t('The value @value provided for @field is not a valid URL.', array('@field' => $name, '@value' => 'edik:naw')));
}
@@ -185,17 +185,17 @@ class LinkValidateTest extends LinkValidateTestCase {
// create page form
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField('edit-field-'. $name .'-und-0-title', 'Title found');
$this->assertField('edit-field-'. $name .'-und-0-url', 'URL found');
$this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
$this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
$edit = array(
'title' => 'Simple Title',
$field_name .'[und][0][url]' => 'edik:naw',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertNoText(t('The value provided for @field is not a valid URL.', array('@field' => $name)));
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => 'edik:naw')));
}
/**
@@ -207,10 +207,10 @@ class LinkValidateTest extends LinkValidateTestCase {
'administer nodes',
'access administration pages',
'access content',
'create '. $this->content_types[0]->type .' content',
'edit any '. $this->content_types[0]->type .' content'));
'create ' . $this->content_types[0]->type . ' content',
'edit any ' . $this->content_types[0]->type . ' content'));
$this->drupalLogin($this->web_user);
variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote'));
variable_set('node_options_' . $this->content_types[0]->name, array('status', 'promote'));
$field_settings = array(
'type' => 'link',
'widget_type' => 'link',
@@ -227,23 +227,23 @@ class LinkValidateTest extends LinkValidateTestCase {
$node = node_load($this->nodes[0]->nid);
$this->drupalGet('node/'. $this->nodes[0]->nid);
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
$title = $this->randomName();
$url = 'javascript:alert("http://example.com/' . $this->randomName() . '")';
$edit[$field['field_name'] .'[0][url]'] = $url;
$edit[$field['field_name'] .'[0][title]'] = $title;
$edit[$field['field_name'] . '[0][url]'] = $url;
$edit[$field['field_name'] . '[0][title]'] = $title;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
//$this->pass($this->content);
$this->assertNoText(t('The value provided for %field is not a valid URL.', array('%field' => $name)));
$this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($url))));
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertEqual($url, $node->{$field['field_name']}[0]['url']);
$this->drupalGet('node/'. $node->nid);
$this->drupalGet('node/' . $node->nid);
$this->assertNoRaw($url, 'Make sure Javascript does not display.');
// Turn the array validation back _on_.
@@ -251,9 +251,9 @@ class LinkValidateTest extends LinkValidateTestCase {
$node_type_link = str_replace('_', '-', $node->type);
//$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
//$this->fail($this->content);
$this->drupalPost('admin/content/node-type/'. $node_type_link .'/fields/'. $field['field_name'], $edit, t('Save field settings'));
$this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings'));
$this->drupalGet('node/'. $node->nid);
$this->drupalGet('node/' . $node->nid);
// This actually works because the display_url goes through the core
// url() function. But we should have a test that makes sure it continues
// to work.
@@ -382,7 +382,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
case FALSE:
return "Invalid Link";
default:
return "Bad Value:". $type;
return "Bad Value:" . $type;
}
}
@@ -460,12 +460,12 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
foreach ($allowed_protocols as $protocol) {
if ($protocol !== 'news' && $protocol !== 'mailto') {
$links[] = $protocol .'://www.example.com';
$links[] = $protocol . '://www.example.com';
}
}
foreach ($links as $link) {
$valid = link_validate_url($link);
$this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that '. $link .' is a valid external link.');
$this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
// The following two lines are commented out and only used for comparisons.
//$valid2 = valid_url($link, TRUE);
//$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
@@ -488,7 +488,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
);
foreach ($links as $link) {
$valid = link_validate_url($link);
$this->assertEqual(FALSE, $valid, 'Testing that '. $link .' is not a valid link.');
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
}
}

View File

@@ -144,6 +144,6 @@ class link_views_handler_argument_target extends views_handler_argument {
$this->ensure_my_table();
// Because attributes are stored serialized, our only option is to also
// serialize the data we're searching for and use LIKE to find similar data.
$this->query->add_where(0, $this->table_alias . '.' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
$this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
}
}

View File

@@ -90,12 +90,12 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
// PostGreSQL code has NOT been tested. Please report any problems to the link issue queue.
// pgSQL requires all slashes to be double escaped in regular expressions.
// See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
$condition .= ' OR ' . $field .' ~* \''.'^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
$condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
}
else {
// mySQL requires backslashes to be double (triple?) escaped within character classes.
// See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp
$condition .= ' OR ' . $field . ' REGEXP \''.'^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
$condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
}
}