About
'; + $output .= '' . 'The link provides a standard custom content field for links. Links can be easily added to any content types and profiles and include advanced validating and different ways of storing internal or external links and URLs. It also supports additional link text title, site wide tokens for titles and title attributes, target attributes, css class attribution, static repeating values, input conversion, and many more.' . '
'; + $output .= '' . 'Requirements / Dependencies' . '
'; + $output .= '' . 'Fields API is provided already by core [no dependencies].' . '
'; + $output .= 'Configuration
'; + $output .= '' . 'Configuration is only slightly more complicated than a text field. Link text titles for URLs can be made required, set as instead of URL, optional (default), or left out entirely. If no link text title is provided, the trimmed version of the complete URL will be displayed. The target attribute should be set to "_blank", "top", or left out completely (checkboxes provide info). The rel=nofollow attribute prevents the link from being followed by certain search engines.' . '
'; + return $output; + } +} + /** * Implements hook_field_info(). */ @@ -98,6 +112,7 @@ function link_field_instance_settings_form($field, $instance) { 'optional' => t('Optional Title'), 'required' => t('Required Title'), 'value' => t('Static Title'), + 'select' => t('Selected Title'), 'none' => t('No Title'), ); @@ -111,9 +126,26 @@ function link_field_instance_settings_form($field, $instance) { $form['title_value'] = array( '#type' => 'textfield', - '#title' => t('Static title'), + '#title' => t('Static or default title'), '#default_value' => isset($instance['settings']['title_value']) ? $instance['settings']['title_value'] : '', - '#description' => t('This title will always be used if “Static Title” is selected above.'), + '#description' => t('This title will 1) always be used if "Static Title" is selected above, or 2) used if "Optional title" is selected above and no title is entered when creating content.'), + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][title]"]' => array('value' => 'value'), + ), + ), + ); + + $form['title_allowed_values'] = array( + '#type' => 'textarea', + '#title' => t('Title allowed values'), + '#default_value' => isset($instance['settings']['title_allowed_values']) ? $instance['settings']['title_allowed_values'] : '', + '#description' => t('When using "Selected Title", you can allow users to select the title from a limited set of values (eg. Home, Office, Other). Enter here all possible values that title can take, one value per line.'), + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][title]"]' => array('value' => 'select'), + ), + ), ); $form['title_label_use_field_label'] = array( @@ -181,7 +213,7 @@ function link_field_instance_settings_form($field, $instance) { $form['attributes']['rel'] = array( '#type' => 'textfield', '#title' => t('Rel Attribute'), - '#description' => t('When output, this link will have this rel attribute. The most common usage is rel="nofollow" which prevents some search engines from spidering entered links.'), + '#description' => t('When output, this link will have this rel attribute. The most common usage is rel="nofollow" which prevents some search engines from spidering entered links.'), '#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], '#field_prefix' => 'rel = "', '#field_suffix' => '"', @@ -218,7 +250,7 @@ function link_field_instance_settings_form($field, $instance) { $form['attributes']['title'] = array( '#title' => t("Default link 'title' Attribute"), '#type' => 'textfield', - '#description' => t('When output, links will use this "title" attribute if the user does not provide one and when different from the link text. Read WCAG 1.0 Guidelines for links comformances. Tokens values will be evaluated.'), + '#description' => t('When output, links will use this "title" attribute if the user does not provide one and when different from the link text. Read WCAG 1.0 Guidelines for links comformances. Tokens values will be evaluated.'), '#default_value' => empty($instance['settings']['attributes']['title']) ? '' : $instance['settings']['attributes']['title'], '#field_prefix' => 'title = "', '#field_suffix' => '"', @@ -228,11 +260,17 @@ function link_field_instance_settings_form($field, $instance) { } /** + * Form validate. + * * #element_validate handler for link_field_instance_settings_form(). */ function link_field_settings_form_validate($element, &$form_state, $complete_form) { if ($form_state['values']['instance']['settings']['title'] === 'value' && empty($form_state['values']['instance']['settings']['title_value'])) { - form_set_error('title_value', t('A default title must be provided if the title is a static value.')); + form_set_error('instance][settings][title_value', t('A default title must be provided if the title is a static value.')); + } + if ($form_state['values']['instance']['settings']['title'] === 'select' + && empty($form_state['values']['instance']['settings']['title_allowed_values'])) { + form_set_error('instance][settings][title_allowed_values', t('You must enter one or more allowed values for link Title, the title is a selected value.')); } if (!empty($form_state['values']['instance']['settings']['display']['url_cutoff']) && !is_numeric($form_state['values']['instance']['settings']['display']['url_cutoff'])) { form_set_error('display', t('URL Display Cutoff value must be numeric.')); @@ -277,6 +315,16 @@ function link_field_validate($entity_type, $entity, $field, $instance, $langcode } } + foreach ($items as $delta => $value) { + if (isset($value['attributes']) && is_string($value['attributes'])) { + $errors[$field['field_name']][$langcode][$delta][] = array( + 'error' => 'link_required', + 'message' => t('String values are not acceptable for attributes.'), + 'error_element' => array('url' => TRUE, 'title' => FALSE), + ); + } + } + if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] && !$optional_field_found) { $errors[$field['field_name']][$langcode][0][] = array( 'error' => 'link_required', @@ -343,10 +391,10 @@ function link_field_widget_form(&$form, &$form_state, $field, $instance, $langco * Implements hook_field_widget_error(). */ function link_field_widget_error($element, $error, $form, &$form_state) { - if ($error['error_element']['title']) { + if (!empty($error['error_element']['title'])) { form_error($element['title'], $error['message']); } - elseif ($error['error_element']['url']) { + elseif (!empty($error['error_element']['url'])) { form_error($element['url'], $error['message']); } } @@ -372,23 +420,21 @@ function _link_load($field, $item, $instance) { /** * Prepares the item attributes and url for storage. * - * @param $item - * Link field values. - * - * @param $delta - * The sequence number for current values. - * - * @param $field - * The field structure array. - * - * @param $entity - * Entity object. - * - * @param $instance - * The instance structure for $field on $entity's bundle. + * @param array $item + * Link field values. + * @param array $delta + * The sequence number for current values. + * @param array $field + * The field structure array. + * @param object $entity + * Entity object. + * @param array $instance + * The instance structure for $field on $entity's bundle. * + * @codingStandardsIgnoreStart */ function _link_process(&$item, $delta, $field, $entity, $instance) { + // @codingStandardsIgnoreEnd // Trim whitespace from URL. if (!empty($item['url'])) { $item['url'] = trim($item['url']); @@ -447,9 +493,10 @@ function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, & '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. + // 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)) { + && (strlen(trim($item['url'])) !== 0 || strlen(trim($item['title'])) !== 0)) { $optional_field_found = TRUE; } // Require entire field. @@ -465,16 +512,19 @@ function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, & /** * Clean up user-entered values for a link field according to field settings. * - * @param array $item + * @param array $item * A single link item, usually containing url, title, and attributes. - * @param int $delta + * @param int $delta * The delta value if this field is one of multiple fields. - * @param array $field + * @param array $field * The CCK field definition. - * @param object $entity + * @param object $entity * The entity containing this link. + * + * @codingStandardsIgnoreStart */ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { + // @codingStandardsIgnoreEnd // Don't try to process empty links. if (empty($item['url']) && empty($item['title'])) { return; @@ -488,7 +538,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { $entity_info = entity_get_info($entity_type); $property_id = $entity_info['entity keys']['id']; $entity_token_type = isset($entity_info['token type']) ? $entity_info['token type'] : ( - $entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type + $entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type ); if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) { $text_tokens = token_scan($item['url']); @@ -516,10 +566,11 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { 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' => !empty($instance['settings']['absolute_url']), - 'html' => TRUE, + 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, ) ); } @@ -551,15 +602,20 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { } } // Use the title defined by the user at the widget level. - elseif (isset($item['title'])) { + elseif (drupal_strlen(trim($item['title']))) { $title = $item['title']; } + // Use the static title if a user-defined title is optional and a static title + // has been defined. + elseif ($instance['settings']['title'] == 'optional' && drupal_strlen(trim($instance['settings']['title_value']))) { + $title = $instance['settings']['title_value']; + } else { $title = ''; } // Replace title tokens. - if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) { + if ($title && $instance['settings']['enable_tokens']) { $text_tokens = token_scan($title); if (!empty($text_tokens)) { // Load the entity if necessary for entities in views. @@ -572,10 +628,25 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { } $title = token_replace($title, array($entity_token_type => $entity_loaded)); } - $title = filter_xss($title, array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); + } + if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) { + $title = filter_xss($title, array( + 'b', + 'br', + 'code', + 'em', + 'i', + 'img', + 'span', + 'strong', + 'sub', + 'sup', + 'tt', + 'u', + )); $item['html'] = TRUE; } - $item['title'] = empty($title) ? $item['display_url'] : $title; + $item['title'] = empty($title) && $title !== '0' ? $item['display_url'] : $title; if (!isset($item['attributes'])) { $item['attributes'] = array(); @@ -622,7 +693,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { // Handle "title" link attribute. if (!empty($item['attributes']['title']) && module_exists('token')) { $text_tokens = token_scan($item['attributes']['title']); - if (!empty($text_tokens)) { + if (!empty($text_tokens)) { // Load the entity (necessary for entities in views). if (isset($entity->{$property_id})) { $entity_loaded = entity_load($entity_type, array($entity->{$property_id})); @@ -633,7 +704,20 @@ 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')); + $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'])) { @@ -685,7 +769,8 @@ function _link_parse_url($url) { * Replaces the PHP parse_str() function. * * Because parse_str replaces the following characters in query parameters name - * in order to maintain compatibility with deprecated register_globals directive: + * in order to maintain compatibility with deprecated register_globals + * directive: * * - chr(32) ( ) (space) * - chr(46) (.) (dot) @@ -732,7 +817,14 @@ function link_theme() { 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_domain' => array( - 'variables' => array('element' => NULL, 'display' => NULL, 'field' => NULL), + 'variables' => array( + 'element' => NULL, + 'display' => NULL, + 'field' => NULL, + ), + ), + 'link_formatter_link_no_protocol' => array( + 'variables' => array('element' => NULL, 'field' => NULL), ), 'link_formatter_link_title_plain' => array( 'variables' => array('element' => NULL, 'field' => NULL), @@ -819,7 +911,8 @@ function _link_default_attributes() { * Build the form element. When creating a form using FAPI #process, * note that $element['#value'] is already set. * - * The $fields array is in $complete_form['#field_info'][$element['#field_name']]. + * The $fields array is in + * $complete_form['#field_info'][$element['#field_name']]. */ function link_field_process($element, $form_state, $complete_form) { $instance = field_widget_instance($element, $form_state); @@ -831,7 +924,7 @@ function link_field_process($element, $form_state, $complete_form) { '#required' => ($element['#delta'] == 0 && $settings['url'] !== 'optional') ? $element['#required'] : FALSE, '#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL, ); - if ($settings['title'] !== 'none' && $settings['title'] !== 'value') { + if (in_array($settings['title'], array('optional', 'required'))) { // 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. @@ -843,15 +936,31 @@ function link_field_process($element, $form_state, $complete_form) { $title_label = t('Title'); } + // Default value. + $title_maxlength = 128; + if (!empty($settings['title_maxlength'])) { + $title_maxlength = $settings['title_maxlength']; + } + $element['title'] = array( '#type' => 'textfield', - '#maxlength' => $settings['title_maxlength'], + '#maxlength' => $title_maxlength, '#title' => $title_label, - '#description' => t('The link title is limited to @maxlength characters maximum.', array('@maxlength' => $settings['title_maxlength'])), + '#description' => t('The link title is limited to @maxlength characters maximum.', array('@maxlength' => $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, ); } + elseif ($settings['title'] == 'select') { + $options = drupal_map_assoc(array_filter(explode("\n", str_replace("\r", "\n", trim($settings['title_allowed_values']))))); + $element['title'] = array( + '#type' => 'select', + '#title' => t('Title'), + '#description' => t('Select the a title for this link.'), + '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL, + '#options' => $options, + ); + } // Initialize field attributes as an array if it is not an array yet. if (!is_array($settings['attributes'])) { @@ -888,7 +997,8 @@ function link_field_process($element, $form_state, $complete_form) { } // If the title field is available or there are field accepts multiple values - // then allow the individual field items display the required asterisk if needed. + // then allow the individual field items display the required asterisk if + // needed. if (isset($element['title']) || isset($element['_weight'])) { // To prevent an extra required indicator, disable the required flag on the // base element since all the sub-fields are already required if desired. @@ -941,6 +1051,11 @@ function link_field_formatter_info() { 'strip_www' => FALSE, ), ), + 'link_no_protocol' => array( + 'label' => t('URL with the protocol removed'), + 'field types' => array('link_field'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), 'link_short' => array( 'label' => t('Short, as link with title "Link"'), 'field types' => array('link_field'), @@ -980,8 +1095,9 @@ function link_field_formatter_settings_form($field, $instance, $view_mode, $form * Implements hook_field_formatter_settings_summary(). */ function link_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; - $settings = $display['settings']; + if ($display['type'] == 'link_domain') { if ($display['settings']['strip_www']) { return t('Strip www. from domain'); @@ -1026,7 +1142,7 @@ function theme_link_formatter_link_default($vars) { } // If only a title, display the title. elseif (!empty($vars['element']['title'])) { - return $link_options['html'] ? $vars['element']['title'] : check_plain($vars['element']['title']); + return !empty($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); @@ -1078,11 +1194,27 @@ function theme_link_formatter_link_domain($vars) { return $vars['element']['url'] ? l($domain, $vars['element']['url'], $link_options) : ''; } +/** + * Formats a link without the http:// or https://. + */ +function theme_link_formatter_link_no_protocol($vars) { + $link_options = $vars['element']; + unset($link_options['title']); + unset($link_options['url']); + // We drop any scheme of the url. + $scheme = parse_url($vars['element']['url']); + $search = '/' . preg_quote($scheme['scheme'] . '://', '/') . '/'; + $replace = ''; + $display_url = preg_replace($search, $replace, $vars['element']['url'], 1); + + return $vars['element']['url'] ? l($display_url, $vars['element']['url'], $link_options) : ''; +} + /** * Formats a link's title as plain text. */ function theme_link_formatter_link_title_plain($vars) { - return empty($vars['element']['title']) ? '' : check_plain($vars['element']['title']); + return empty($vars['element']['title']) ? '' : check_plain(decode_entities($vars['element']['title'])); } /** @@ -1142,7 +1274,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(). + * @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') { @@ -1157,7 +1290,8 @@ function link_token_list($type = 'all') { /** * Implements hook_token_values(). * - * @TODO: hook_token_values no longer exists - this should change to hook_tokens(). + * @TODO: hook_token_values no longer exists - this should change to + * hook_tokens(). */ function link_token_values($type, $object = NULL) { if ($type === 'field') { @@ -1185,12 +1319,12 @@ function link_views_api() { * Forms a valid URL if possible from an entered address. * * Trims whitespace and automatically adds an http:// to addresses without a - * protocol specified + * 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 + * The protocol to be prepended to the url if one is not specified. */ function link_cleanup_url($url, $protocol = 'http') { $url = trim($url); @@ -1200,9 +1334,10 @@ function link_cleanup_url($url, $protocol = 'http') { // Check if there is no protocol specified. $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. - $LINK_DOMAINS = _link_domains(); - $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z]{2}))/i', $url); + // But should there be? Add an automatic http:// if it starts with a + // domain name. + $link_domains = _link_domains(); + $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)(' . $link_domains . '|[a-z]{2}))/i', $url); if (!empty($domain_match)) { $url = $protocol . "://" . $url; } @@ -1215,16 +1350,17 @@ function link_cleanup_url($url, $protocol = 'http') { /** * Validates a URL. * - * @param $text + * @param string $text * Url to be validated. - * - * @param $langcode + * @param string $langcode * An optional language code to look up the path in. * - * @return boolean + * @return bool * True if a valid link, FALSE otherwise. */ function link_validate_url($text, $langcode = NULL) { + + $text = _link_clean_relative($text); $text = link_cleanup_url($text); $type = link_url_type($text); @@ -1253,6 +1389,31 @@ function link_validate_url($text, $langcode = NULL) { return $flag; } +/** + * Cleaner of relatives urls. + * + * @param string $url + * The url to clean up the relative protocol. + */ +function _link_clean_relative($url) { + $check = substr($url, 0, 2); + if (isset($_SERVER['HTTPS']) && + ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || + isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && + $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { + $protocol = 'https://'; + } + else { + $protocol = 'http://'; + } + + if ($check == '//') { + $url = str_replace('//', $protocol, $url); + } + + return $url; +} + /** * Type check a URL. * @@ -1261,103 +1422,134 @@ function link_validate_url($text, $langcode = NULL) { * * @param string $text * Url to be checked. - * + * * @return mixed * Returns boolean FALSE if the URL is not valid. On success, returns one of * the LINK_(linktype) constants. */ function link_url_type($text) { // @TODO Complete letters. - $LINK_ICHARS_DOMAIN = (string) html_entity_decode(implode("", array( - "æ", // æ - "Æ", // Æ + // @codingStandardsIgnoreStart + $link_ichars_domain = (string) html_entity_decode(implode("", array( + "¿", // ¿ "À", // À - "à", // à "Á", // Á - "á", // á "Â", //  - "â", // â - "å", // å - "Å", // Å - "ä", // ä + "Ã", // à "Ä", // Ä + "Å", // Å + "Æ", // Æ "Ç", // Ç - "ç", // ç - "Ð", // Ð - "ð", // ð "È", // È - "è", // è "É", // É - "é", // é "Ê", // Ê - "ê", // ê "Ë", // Ë - "ë", // ë + "Ì", // Ì + "Í", // Í "Î", // Î - "î", // î "Ï", // Ï - "ï", // ï - "ø", // ø - "Ø", // Ø - "ö", // ö - "Ö", // Ö + "Ð", // Ð + "Ñ", // Ñ + "Ò", // Ò + "Ó", // Ó "Ô", // Ô - "ô", // ô "Õ", // Õ + "Ö", // Ö + // × + "Ø", // Ø + "Ù", // Ù + "Ú", // Ú + "Û", // Û + "Ü", // Ü + "Ý", // Ý + "Þ", // Þ + // ß (see LINK_ICHARS) + "à", // à + "á", // á + "â", // â + "ã", // ã + "ä", // ä + "å", // å + "æ", // æ + "ç", // ç + "è", // è + "é", // é + "ê", // ê + "ë", // ë + "ì", // ì + "í", // í + "î", // î + "ï", // ï + "ð", // ð + "ñ", // ñ + "ò", // ò + "ó", // ó + "ô", // ô "õ", // õ + "ö", // ö + // ÷ + "ø", // ø + "ù", // ù + "ú", // ú + "û", // û + "ü", // ü + "ý", // ý + "þ", // þ + "ÿ", // ÿ "Œ", // Œ "œ", // œ - "ü", // ü - "Ü", // Ü - "Ù", // Ù - "ù", // ù - "Û", // Û - "û", // û "Ÿ", // Ÿ - "ÿ", // ÿ - "Ñ", // Ñ - "ñ", // ñ - "þ", // þ - "Þ", // Þ - "ý", // ý - "Ý", // Ý - "¿", // ¿ )), ENT_QUOTES, 'UTF-8'); + // @codingStandardsIgnoreEnd - $LINK_ICHARS = $LINK_ICHARS_DOMAIN . (string) html_entity_decode(implode("", array( - "ß", // ß - )), ENT_QUOTES, 'UTF-8'); - $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal')); - $LINK_DOMAINS = _link_domains(); + $link_ichars = $link_ichars_domain . (string) html_entity_decode(implode("", array( + // ß. + "ß", + )), ENT_QUOTES, 'UTF-8'); + $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}))?)'; + $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}))?)'; $ipv4 = '(?:[0-9]{1,3}(\.[0-9]{1,3}){3})'; $ipv6 = '(?:[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})'; $port = '(?::([0-9]{1,5}))'; - // Pattern specific to external links. $external_pattern = '/^' . $protocol . '?' . $authentication . '?(' . $domain . '|' . $ipv4 . '|' . $ipv6 . ' |localhost)' . $port . '?'; // Pattern specific to internal links. - $internal_pattern = "/^(?:[a-z0-9" . $LINK_ICHARS . "_\-+\[\] ]+)"; - $internal_pattern_file = "/^(?:[a-z0-9" . $LINK_ICHARS . "_\-+\[\]\. \/\(\)][a-z0-9" . $LINK_ICHARS . "_\-+\[\]\. \(\)][a-z0-9" . $LINK_ICHARS . "_\-+\[\]\. \/\(\)]+)$/i"; + $internal_pattern = "/^(?:[a-z0-9" . $link_ichars . "_\-+\[\] ]+)"; + $internal_pattern_file = "/^(?:[a-z0-9" . $link_ichars . "_\-+\[\]\. \/\(\)][a-z0-9" . $link_ichars . "_\-+\[\]\. \(\)][a-z0-9" . $link_ichars . "_\-+\[\]\. \/\(\)]+)$/i"; - $directories = "(?:\/[a-z0-9" . $LINK_ICHARS . "_\-\.~+%=&,$'#!():;*@\[\]]*)*"; + $directories = "(?:\/[a-z0-9" . $link_ichars . "_\-\.~+%=&,$'#!():;*@\[\]]*)*"; // Yes, four backslashes == a single backslash. - $query = "(?:\/?\?([?a-z0-9" . $LINK_ICHARS . "+_|\-\.~\/\\\\%=&,$'!():;*@\[\]{} ]*))"; - $anchor = "(?:#[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. + // @codingStandardsIgnoreLine $end = $directories . '?' . $query . '?' . $anchor . '?' . '$/i'; $message_id = '[^@].*@' . $domain; $newsgroup_name = '(?:[0-9a-z+-]*\.)*[0-9a-z+-]*'; $news_pattern = '/^news:(' . $newsgroup_name . '|' . $message_id . ')$/i'; - $user = '[a-zA-Z0-9' . $LINK_ICHARS . '_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'\[\]]+'; + $user = '[a-zA-Z0-9' . $link_ichars . '_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'\[\]]+'; $email_pattern = '/^mailto:' . $user . '@' . '(?:' . $domain . '|' . $ipv4 . '|' . $ipv6 . '|localhost)' . $query . '?$/'; if (strpos($text, '' . print_r($token_url_tests, TRUE) . '');
-
+ // @codingStandardsIgnoreLine
+ // $this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');.
foreach ($token_url_tests as &$input) {
$this->drupalGet('node/add/page');
-
+
$edit = array(
'title' => $input['label'],
$field_name . '[und][0][title]' => $input['label'],
@@ -73,34 +79,37 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
$input['url'] = $url;
}
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
-
+
foreach ($token_url_tests as $index => $input2) {
$node = node_load($index);
$this->assertNotEqual(NULL, $node, "Do we have a node?");
$this->assertEqual($node->nid, $index, "Test that we have a node.");
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
$assert_data = token_replace($token_name,
- array('node' => $node));
+ array('node' => $node));
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
}
}
-
+
/**
- * Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens.
+ * Field Token Node Viewed.
+ *
+ * Creates a link field, fills it, then uses a loaded and node_view'd node to
+ * test tokens.
*/
- function testFieldTokenNodeViewed() {
- // create field
+ public function testFieldTokenNodeViewed() {
+ // Create field.
$settings = array(
'instance[settings][enable_tokens]' => 0,
);
$field_name = $this->createLinkField('page',
- $settings);
+ $settings);
- // create page form
+ // Create page form.
$this->drupalGet('node/add/page');
- //$field_name = 'field_' . $name;
+ // $field_name = 'field_' . $name;.
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -122,11 +131,12 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
'label' => $this->randomName(),
),
);
- //$this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');
+ //@codingStandardsIgnoreLine
+ // $this->assert('pass', '' . print_r($token_url_tests, TRUE) . '');.
foreach ($token_url_tests as &$input) {
$this->drupalGet('node/add/page');
-
+
$edit = array(
'title' => $input['label'],
$field_name . '[und][0][title]' => $input['label'],
@@ -137,19 +147,18 @@ class LinkEntityTokenTest extends LinkBaseTestClass {
$input['url'] = $url;
}
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
-
+
foreach ($token_url_tests as $index => $input2) {
$node = node_load($index);
- $node_array = node_view($node, 'full');
$this->assertNotEqual(NULL, $node, "Do we have a node?");
$this->assertEqual($node->nid, $index, "Test that we have a node.");
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
$assert_data = token_replace($token_name,
- array('node' => $node));
+ array('node' => $node));
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
}
}
-
-}
\ No newline at end of file
+
+}
diff --git a/sites/all/modules/contrib/fields/link/tests/link.test b/sites/all/modules/contrib/fields/link/tests/link.test
index 962197f2..dd9adb49 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.test
@@ -5,10 +5,15 @@
* Link base test file - contains common functions for testing links.
*/
+/**
+ * Base Test Class.
+ */
class LinkBaseTestClass extends DrupalWebTestCase {
+
protected $permissions = array(
'access content',
'administer content types',
+ 'administer fields',
'administer nodes',
'administer filters',
'access comments',
@@ -17,17 +22,23 @@ class LinkBaseTestClass extends DrupalWebTestCase {
'create page content',
);
- function setUp() {
+ /**
+ * Setup.
+ */
+ public function setUp() {
$modules = func_get_args();
$modules = (isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules);
$modules[] = 'field_ui';
$modules[] = 'link';
parent::setUp($modules);
-
+
$this->web_user = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->web_user);
}
+ /**
+ * Create Link Field.
+ */
protected function createLinkField($node_type = 'page', $settings = array()) {
$name = strtolower($this->randomName());
$edit = array(
@@ -48,4 +59,5 @@ class LinkBaseTestClass extends DrupalWebTestCase {
return $field_name;
}
+
}
diff --git a/sites/all/modules/contrib/fields/link/tests/link.token.test b/sites/all/modules/contrib/fields/link/tests/link.token.test
index 617260e6..edbb1df5 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.token.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.token.test
@@ -6,10 +6,13 @@
*/
/**
- * Testing that tokens can be used in link titles
+ * Testing that tokens can be used in link titles.
*/
class LinkTokenTest extends LinkBaseTestClass {
+ /**
+ * Get Info.
+ */
public static function getInfo() {
return array(
'name' => 'Link tokens - browser test',
@@ -19,34 +22,38 @@ class LinkTokenTest extends LinkBaseTestClass {
);
}
- function setUp($modules = array()) {
+ /**
+ * Setup.
+ */
+ public function setUp($modules = array()) {
parent::setUp(array('token'));
}
/**
* Creates a link field with a required title enabled for user-entered tokens.
+ *
* Creates a node with a token in the link title and checks the value.
*/
- function testUserTokenLinkCreate() {
- // create field
+ public function testUserTokenLinkCreate() {
+ // Create field.
$settings = array(
'instance[settings][enable_tokens]' => 1,
);
$field_name = $this->createLinkField('page',
- $settings);
+ $settings);
- // create page form
+ // Create page form.
$this->drupalGet('node/add/page');
- //$field_name = 'field_' . $name;
+ // $field_name = 'field_' . $name;.
$this->assertField($field_name . '[und][0][title]', 'Title found');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
- 'href' => 'http://example.com/' . $this->randomName(),
- 'label' => $this->randomName(),
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
);
- //$this->drupalLogin($this->web_user);
+ // $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -57,36 +64,37 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'] . ' page', $input['href']));
}
-
/**
* Creates a link field with a static title and an admin-entered token.
+ *
* Creates a node with a link and checks the title value.
*/
- function testStaticTokenLinkCreate() {
+ public function testStaticTokenLinkCreate() {
- // create field
+ // Create field.
$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
+ // Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
- 'href' => 'http://example.com/' . $this->randomName()
+ 'href' => 'http://example.com/' . $this->randomName(),
);
- //$this->drupalLogin($this->web_user);
+ // $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -97,7 +105,7 @@ class LinkTokenTest extends LinkBaseTestClass {
$url = $this->getUrl();
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
@@ -106,30 +114,32 @@ class LinkTokenTest extends LinkBaseTestClass {
/**
* Creates a link field with a static title and an admin-entered token.
+ *
* Creates a node with a link and checks the title value.
*
* Basically, I want to make sure the [title-raw] token works, because it's a
* token that changes from node to node, where [type]'s always going to be the
* same.
*/
- function testStaticTokenLinkCreate2() {
+ public function testStaticTokenLinkCreate2() {
- // create field
+ // Create field.
$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
+ // Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
- 'href' => 'http://example.com/' . $this->randomName()
+ 'href' => 'http://example.com/' . $this->randomName(),
);
- //$this->drupalLogin($this->web_user);
+ // $this->drupalLogin($this->web_user);.
$this->drupalGet('node/add/page');
$edit = array(
@@ -140,27 +150,32 @@ class LinkTokenTest extends LinkBaseTestClass {
$url = $this->getUrl();
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($name . ' ' . $name, $input['href']));
}
- // This test doesn't seem to actually work, due to lack of 'title' in url.
- function _test_Link_With_Title_Attribute_token_url_form() {
- /* $this->loginWithPermissions($this->permissions);
+ /**
+ * This test doesn't seem to actually work, due to lack of 'title' in url.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function _test_Link_With_Title_Attribute_token_url_form() {
+ // @codingStandardsIgnoreEnd
+ /* $this->loginWithPermissions($this->permissions);
$this->acquireContentTypes(1);
$field_settings = array(
- 'type' => 'link',
- 'widget_type' => 'link',
- 'type_name' => $this->content_types[0]->name,
- 'attributes' => array(
- 'class' => '',
- 'target' => 'default',
- 'rel' => 'nofollow',
- 'title' => '',
- ),
+ 'type' => 'link',
+ 'widget_type' => 'link',
+ 'type_name' => $this->content_types[0]->name,
+ 'attributes' => array(
+ 'class' => '',
+ 'target' => 'default',
+ 'rel' => 'nofollow',
+ 'title' => '',
+ ),
);
$field = $this->createField($field_settings, 0);
@@ -170,10 +185,10 @@ class LinkTokenTest extends LinkBaseTestClass {
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-url]',
- 'enable_tokens' => TRUE);
-
+ 'enable_tokens' => TRUE);
+ // @codingStandardsIgnoreLine
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
- $edit, t('Save field settings'));
+ $edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));*/
$name = $this->randomName();
$settings = array(
@@ -183,12 +198,9 @@ class LinkTokenTest extends LinkBaseTestClass {
$field_name = $this->createLinkField('page', $settings);
// So, having saved this field_name, let's see if it works...
- //$this->acquireNodes(1);
-
- //$node = node_load($this->nodes[0]->nid);
-
- //$this->drupalGet('node/'. $this->nodes[0]->nid);
-
+ // $this->acquireNodes(1);
+ // $node = node_load($this->nodes[0]->nid);
+ // $this->drupalGet('node/'. $this->nodes[0]->nid);.
$edit = array();
$test_link_url = 'http://www.example.com/test';
$edit[$field_name . '[und][0][url]'] = $test_link_url;
@@ -200,23 +212,28 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
// Make sure we get a new version!
- //$node = node_load($this->nodes[0]->nid, NULL, TRUE);
+ // $node = node_load($this->nodes[0]->nid, NULL, TRUE);.
$this->assertText(t('Basic page @title has been updated.',
- array('@title' => $name)));
+ array('@title' => $name)));
- //$this->drupalGet('node/'. $node->nid);
+ // $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->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.'));
- //$this->fail($this->content);
+ // $this->fail($this->content);.
}
/**
+ * Link With Title Attribute token title form.
+ *
* If the title of the link is set to the title attribute, then the title
* attribute isn't supposed to show.
+ *
+ * @codingStandardsIgnoreStart
*/
- function _test_Link_With_Title_Attribute_token_title_form() {
+ public function _test_Link_With_Title_Attribute_token_title_form() {
+ // @codingStandardsIgnoreEnd
$this->loginWithPermissions($this->permissions);
$this->acquireContentTypes(1);
$field_settings = array(
@@ -233,21 +250,20 @@ class LinkTokenTest extends LinkBaseTestClass {
$field = $this->createField($field_settings, 0);
$field_name = $field['field_name'];
- $field_db_info = content_database_info($field);
$url_type = str_replace('_', '-', $this->content_types[0]->type);
- $edit = array('attributes[title]' => '[' . $field_name . '-title]',
- 'enable_tokens' => TRUE);
+ $edit = array(
+ 'attributes[title]' => '[' . $field_name . '-title]',
+ 'enable_tokens' => TRUE,
+ );
$this->drupalPost('admin/content/node-type/' . $url_type . '/fields/' . $field['field_name'],
- $edit, t('Save field settings'));
+ $edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
// So, having saved this field_name, let's see if it works...
$this->acquireNodes(1);
- $node = node_load($this->nodes[0]->nid);
-
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
@@ -260,24 +276,35 @@ class LinkTokenTest extends LinkBaseTestClass {
// Make sure we get a new version!
$node = node_load($this->nodes[0]->nid, NULL, TRUE);
$this->assertText(t('@type @title has been updated.',
- array('@title' => $node->title,
- '@type' => $this->content_types[0]->name)));
+ array(
+ '@title' => $node->title,
+ '@type' => $this->content_types[0]->name,
+ )));
$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->fail($this->content);
+ // $this->fail($this->content);.
}
/**
- * Trying to set the url to contain a token.
+ * Trying to set the url to contain a token.
+ *
+ * @codingStandardsIgnoreStart
*/
- function _testUserTokenLinkCreateInURL() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ public function _testUserTokenLinkCreateInURL() {
+ //@codingStandardsIgnoreEnd
+
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'access content',
+ 'create page content',
+ ));
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
@@ -288,20 +315,21 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => 1,
+ ), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
- // create page form
+ // Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField($field_name . '[0][title]', 'Title found');
$this->assertField($field_name . '[0][url]', 'URL found');
$input = array(
- 'href' => 'http://example.com/' . $this->randomName(),
- 'label' => $this->randomName(),
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
);
$this->drupalLogin($this->web_user);
@@ -315,22 +343,31 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw(l($input['label'], $input['href'] . '/page'));
- //$this->fail($this->content);
+ // $this->fail($this->content);.
}
/**
- * Trying to set the url to contain a token.
+ * Trying to set the url to contain a token.
+ *
+ * @codingStandardsIgnoreStart
*/
- function _testUserTokenLinkCreateInURL2() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ public function _testUserTokenLinkCreateInURL2() {
+ // @codingStandardsIgnoreEnd
+
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'access content',
+ 'create page content',
+ ));
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$edit = array(
'_add_new_field[label]' => $name,
@@ -341,20 +378,21 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => 1,
+ ), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
- // create page form
+ // Create page form.
$this->drupalGet('node/add/page');
$field_name = 'field_' . $name;
$this->assertField($field_name . '[0][title]', 'Title found');
$this->assertField($field_name . '[0][url]', 'URL found');
$input = array(
- 'href' => 'http://example.com/' . $this->randomName(),
- 'label' => $this->randomName(),
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
);
$this->drupalLogin($this->web_user);
@@ -368,22 +406,34 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
- // change to anonymous user
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$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.
+ * CRUD Title Only Title No Link.
+ *
+ * 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.
+ *
+ * @codingStandardsIgnoreStart
*/
- function testCRUDTitleOnlyTitleNoLink2() {
- $this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ public function testCRUDTitleOnlyTitleNoLink2() {
+ //@codingStandardsIgnoreEnd
+
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'access content',
+ 'create page content',
+ ));
+
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$field_name = 'field_' . $name;
$edit = array(
@@ -401,8 +451,8 @@ class LinkTokenTest extends LinkBaseTestClass {
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
-
- // create page form
+
+ // Create page form.
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
@@ -419,13 +469,12 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
-
- // change to anonymous user
+
+ // Change to anonymous user.
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This & That');
}
-
-
+
}
diff --git a/sites/all/modules/contrib/fields/link/tests/link.validate.test b/sites/all/modules/contrib/fields/link/tests/link.validate.test
index a9ac116c..addd7d37 100644
--- a/sites/all/modules/contrib/fields/link/tests/link.validate.test
+++ b/sites/all/modules/contrib/fields/link/tests/link.validate.test
@@ -5,8 +5,14 @@
* Tests that exercise the validation functions in the link module.
*/
+/**
+ * Validate Test Case.
+ */
class LinkValidateTestCase extends LinkBaseTestClass {
+ /**
+ * Create Link.
+ */
protected function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
@@ -17,8 +23,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
/**
* Takes a url, and sees if it can validate that the url is valid.
+ *
+ * @codingStandardsIgnoreStart
*/
protected function link_test_validate_url($url) {
+ // @codingStandardsIgnoreEnd
$field_name = $this->createLinkField();
@@ -26,11 +35,11 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$settings = array(
'title' => $label,
$field_name => array(
- LANGUAGE_NONE=> array(
+ LANGUAGE_NONE => array(
array(
'title' => $label,
'url' => $url,
- )
+ ),
),
),
);
@@ -41,10 +50,17 @@ class LinkValidateTestCase extends LinkBaseTestClass {
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
}
+
}
+/**
+ * Class for Validate Test.
+ */
class LinkValidateTest extends LinkValidateTestCase {
+ /**
+ * Get Info.
+ */
public static function getInfo() {
return array(
'name' => 'Link Validation Tests',
@@ -53,23 +69,35 @@ class LinkValidateTest extends LinkValidateTestCase {
);
}
- function test_link_validate_basic_url() {
+ /**
+ * Validate basic URL.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_validate_basic_url() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.example.com');
}
/**
* Test if we're stopped from posting a bad url on default validation.
+ *
+ * @codingStandardsIgnoreStart
*/
- function test_link_validate_bad_url_validate_default() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
+ public function test_link_validate_bad_url_validate_default() {
+ // @codingStandardsIgnoreEnd
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'administer nodes',
+ 'administer filters',
+ 'access content',
+ 'create page content',
+ 'access administration pages',
+ ));
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -86,35 +114,43 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
- // create page form
+ // 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');
-
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText(t('The value @value provided for @field is not a valid URL.', array('@value' => 'edik:naw', '@field' => $name)));
+ $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
+ '@value' => 'edik:naw',
+ '@field' => $name,
+ )));
}
/**
* Test if we're stopped from posting a bad url with validation on.
+ *
+ * @codingStandardsIgnoreStart
*/
- function test_link_validate_bad_url_validate_on() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
+ public function test_link_validate_bad_url_validate_on() {
+ // @codingStandardsIgnoreEnd
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'administer nodes',
+ 'administer filters',
+ 'access content',
+ 'create page content',
+ 'access administration pages',
+ ));
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -131,36 +167,44 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
- // create page form
+ // 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');
-
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText(t('The value @value provided for @field is not a valid URL.', array('@field' => $name, '@value' => 'edik:naw')));
+ $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
+ '@field' => $name,
+ '@value' => 'edik:naw',
+ )));
}
/**
* Test if we can post a bad url if the validation is expressly turned off.
+ *
+ * @codingStandardsIgnoreStart
*/
- function test_link_validate_bad_url_validate_off() {
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'administer filters',
- 'access content',
- 'create page content',
- 'access administration pages'));
+ public function test_link_validate_bad_url_validate_off() {
+ // @codingStandardsIgnoreEnd
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'administer nodes',
+ 'administer filters',
+ 'access content',
+ 'create page content',
+ 'access administration pages',
+ ));
$this->drupalLogin($this->web_user);
- // create field
+ // Create field.
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
@@ -172,6 +216,7 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings'));
+ // @codingStandardsIgnoreLine
/*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject();
$this->fail(''. print_r($instance_details, TRUE) .'
');
$this->fail(''. print_r(unserialize($instance_details->data), TRUE) .'
');*/
@@ -181,51 +226,62 @@ class LinkValidateTest extends LinkValidateTestCase {
node_types_rebuild();
menu_rebuild();
- // create page form
+ // 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');
-
$edit = array(
'title' => 'Simple Title',
$field_name . '[und][0][url]' => 'edik:naw',
);
$this->drupalPost(NULL, $edit, t('Save'));
- $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => 'edik:naw')));
+ $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
+ '%field' => $name,
+ '%value' => 'edik:naw',
+ )));
}
/**
- * Test if a bad url can sneak through un-filtered if we play with the validation...
+ * Validate switching between validation status.
+ *
+ * Test if a bad url can sneak through un-filtered if we play with the
+ * validation...
+ *
+ * @codingStandardsIgnoreStart
*/
- function x_test_link_validate_switching_between_validation_status() {
+ public function x_test_link_validate_switching_between_validation_status() {
+ // @codingStandardsIgnoreEnd
$this->acquireContentTypes(1);
- $this->web_user = $this->drupalCreateUser(array('administer content types',
- 'administer nodes',
- 'access administration pages',
- 'access content',
- 'create ' . $this->content_types[0]->type . ' content',
- 'edit any ' . $this->content_types[0]->type . ' content'));
+ $this->web_user = $this->drupalCreateUser(array(
+ 'administer content types',
+ 'administer fields',
+ 'administer nodes',
+ 'access administration pages',
+ 'access 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',
'type_name' => $this->content_types[0]->name,
- 'attributes' => array(), // <-- This is needed or we have an error
+ // <-- This is needed or we have an error.
+ 'attributes' => array(),
'validate_url' => 0,
);
$field = $this->createField($field_settings, 0);
- //$this->fail(''. print_r($field, TRUE) .'
');
- $field_db_info = content_database_info($field);
$this->acquireNodes(2);
- $node = node_load($this->nodes[0]->nid);
-
$this->drupalGet('node/' . $this->nodes[0]->nid);
$edit = array();
@@ -235,8 +291,12 @@ class LinkValidateTest extends LinkValidateTestCase {
$edit[$field['field_name'] . '[0][title]'] = $title;
$this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
- //$this->pass($this->content);
- $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array('%field' => $name, '%value' => trim($url))));
+ // $this->pass($this->content);.
+ // @codingStandardsIgnoreLine
+ $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);
@@ -248,8 +308,9 @@ class LinkValidateTest extends LinkValidateTestCase {
// Turn the array validation back _on_.
$edit = array('validate_url' => TRUE);
$node_type_link = str_replace('_', '-', $node->type);
- //$this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
- //$this->fail($this->content);
+ // @codingStandardsIgnoreLine
+ // $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->drupalGet('node/' . $node->nid);
@@ -257,17 +318,26 @@ class LinkValidateTest extends LinkValidateTestCase {
// url() function. But we should have a test that makes sure it continues
// to work.
$this->assertNoRaw($url, 'Make sure Javascript does not display.');
- //$this->fail($this->content);
-
+ // $this->fail($this->content);.
}
- // Validate that '' is a valid url.
- function test_link_front_url() {
+ /**
+ * Validate that '' is a valid url.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_front_url() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('');
}
- // Validate that an internal url would be accepted.
- function test_link_internal_url() {
+ /**
+ * Validate that an internal url would be accepted.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_internal_url() {
+ // @codingStandardsIgnoreEnd
// Create the content first.
$node = $this->drupalCreateNode();
@@ -277,22 +347,46 @@ class LinkValidateTest extends LinkValidateTestCase {
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
}
- // Validate a simple mailto.
- function test_link_mailto() {
+ /**
+ * Validate a simple mailto.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_mailto() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('mailto:jcfiala@gmail.com');
}
- function test_link_external_https() {
+ /**
+ * Check link external https.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_external_https() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('https://www.example.com/');
}
- function test_link_ftp() {
+ /**
+ * Check link FTP.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_ftp() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('ftp://www.example.com/');
}
+
}
+/**
+ * Validate Test News.
+ */
class LinkValidateTestNews extends LinkValidateTestCase {
+ /**
+ * Get Info.
+ */
public static function getInfo() {
return array(
'name' => 'Link News Validation Tests',
@@ -301,18 +395,36 @@ class LinkValidateTestNews extends LinkValidateTestCase {
);
}
- // Validate a news link to a message group
- function test_link_news() {
+ /**
+ * Validate a news link to a message group.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_news() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('news:comp.infosystems.www.misc');
}
- // Validate a news link to a message id. Said ID copied off of google groups.
- function test_link_news_message() {
+ /**
+ * Validate a news link to a message id. Said ID copied off of google groups.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_link_news_message() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
}
+
}
+/**
+ * Validate Specific URL.
+ */
class LinkValidateSpecificURL extends LinkValidateTestCase {
+
+ /**
+ * Get Info.
+ */
public static function getInfo() {
return array(
'name' => 'Link Specific URL Validation Tests',
@@ -321,24 +433,53 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
);
}
- // Lets throw in a lot of umlouts for testing!
- function test_umlout_url() {
+ /**
+ * Lets throw in a lot of umlouts for testing!
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_umlout_url() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://üÜü.exämple.com/nöde');
}
- function test_umlout_mailto() {
+ /**
+ * Check umlout mailto.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_umlout_mailto() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('mailto:Üser@exÅmple.com');
}
- function test_german_b_url() {
+ /**
+ * Check german b in url.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_german_b_url() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.test.com/ßstuff');
}
- function test_special_n_url() {
+ /**
+ * Check Special in url.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_special_n_url() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.testÑñ.com/');
}
- function test_curly_brackets_in_query() {
+ /**
+ * Curly Brackets in query.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function test_curly_brackets_in_query() {
+ // @codingStandardsIgnoreEnd
$this->link_test_validate_url('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
}
@@ -346,8 +487,11 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
* Here, we're testing that a very long url is stored properly in the db.
*
* Basically, trying to test http://drupal.org/node/376818
+ *
+ * @codingStandardsIgnoreStart
*/
- function testLinkURLFieldIsBig() {
+ public function testLinkURLFieldIsBig() {
+ // @codingStandardsIgnoreEnd
$long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
$this->link_test_validate_url($long_url);
}
@@ -355,12 +499,18 @@ class LinkValidateSpecificURL extends LinkValidateTestCase {
}
/**
- * A series of tests of links, only going against the link_validate_url function in link.module.
+ * Validate Url Light.
+ *
+ * A series of tests of links, only going against the link_validate_url function
+ * in link.module.
*
* Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
*/
class LinkValidateUrlLight extends DrupalWebTestCase {
+ /**
+ * Get Info.
+ */
public static function getInfo() {
return array(
'name' => 'Link Light Validation Tests',
@@ -368,72 +518,107 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'group' => 'Link',
);
}
-
- function setUp() {
+
+ /**
+ * Setup.
+ */
+ public function setUp() {
parent::setUp('link');
}
/**
- * Translates the LINK type constants to english for display and debugging of tests
+ * Name Link Type.
+ *
+ * Translates the LINK type constants to english for display and debugging of
+ * tests.
+ *
+ * @codingStandardsIgnoreStart
*/
- function name_Link_Type($type) {
+ public function name_Link_Type($type) {
+ // @codingStandardsIgnoreEnd
switch ($type) {
case LINK_FRONT:
return "Front";
+
case LINK_EMAIL:
return "Email";
+
case LINK_NEWS:
return "Newsgroup";
+
case LINK_INTERNAL:
return "Internal Link";
+
case LINK_EXTERNAL:
return "External Link";
+
case FALSE:
return "Invalid Link";
+
default:
return "Bad Value:" . $type;
}
}
- // Make sure that a link labeled works.
- function testValidateFrontLink() {
+ /**
+ * Make sure that a link labeled works.
+ */
+ public function testValidateFrontLink() {
$valid = link_validate_url('');
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
}
- function testValidateEmailLink() {
+ /**
+ * Validate Email Link.
+ */
+ public function testValidateEmailLink() {
$valid = link_validate_url('mailto:bob@example.com');
$this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
}
- function testValidateEmailLinkBad() {
+ /**
+ * Validate Email Link Bad.
+ */
+ public function testValidateEmailLinkBad() {
$valid = link_validate_url(':bob@example.com');
$this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
}
- function testValidateNewsgroupLink() {
+ /**
+ * Validate Newsgroup Link.
+ */
+ public function testValidateNewsgroupLink() {
$valid = link_validate_url('news:comp.infosystems.www.misc');
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
}
- function testValidateNewsArticleLink() {
+ /**
+ * Validate News Article Link.
+ */
+ public function testValidateNewsArticleLink() {
$valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
}
- function testValidateBadNewsgroupLink() {
+ /**
+ * Validate Bad Newsgroup Link.
+ */
+ public function testValidateBadNewsgroupLink() {
$valid = link_validate_url('news:comp.bad_name.misc');
$this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
}
- function testValidateInternalLinks() {
+ /**
+ * Validate Internal Links.
+ */
+ public function testValidateInternalLinks() {
$tempfile = drupal_tempnam('public://files', 'test');
$links = array(
'rss.xml',
file_uri_target($tempfile),
drupal_realpath($tempfile),
);
-
+
foreach ($links as $link) {
$type = link_url_type($link);
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
@@ -442,7 +627,10 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
}
}
- function testValidateExternalLinks() {
+ /**
+ * Validate External Links.
+ */
+ public function testValidateExternalLinks() {
$links = array(
'http://localhost:8080/',
'www.example.com',
@@ -458,7 +646,7 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'www.test-site.com',
'http://example.com/index.php?q=node/123',
'http://example.com/?first_name=Joe Bob&last_name=Smith',
- // Anchors
+ // Anchors.
'http://www.example.com/index.php#test',
'http://www.example.com/index.php#this@that.',
'http://www.example.com/index.php#',
@@ -466,8 +654,22 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
'http://www.example.com/blah/#this@that?',
);
+
// Test all of the protocols.
- $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
+ $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';
@@ -478,25 +680,28 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
$valid = link_validate_url($link);
$this->assertTrue($valid, 'Test ' . $link . ' is 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.");
+ // 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.");.
}
- // Test if we can make a tld valid:
- variable_set('link_extra_domains', array('frog'));
- $valid = link_validate_url('http://www.example.frog');
- $this->assertEqual(LINK_EXTERNAL, $valid, "Testing that http://www.example.frog is a valid external link if we've added 'frog' to the list of valid domains.");
}
- function testInvalidExternalLinks() {
+ /**
+ * Check Invalid External Links.
+ */
+ public function testInvalidExternalLinks() {
$links = array(
'http://www.ex ample.com/',
- 'http://25.0.0/', // bad ip!
+ // Bad ip!
+ 'http://25.0.0/',
'http://4827.0.0.2/',
- '//www.example.com/',
- 'http://www.testß.com/', // ß not allowed in domain names!
- 'http://www.example.frog/', // Bad TLD
- //'http://www.-fudge.com/', // domains can't have sections starting with a dash.
+ // ß not allowed in domain names!
+ 'http://www.testß.com/',
+ // Bad TLD.
+ 'http://.www.foo.bar./',
+ // Domains can't have sections starting with a dash.
+ // 'http://www.-fudge.com/',
'http://example.com/index.php?page=this\that',
'example@example.com',
);
@@ -505,4 +710,5 @@ class LinkValidateUrlLight extends DrupalWebTestCase {
$this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
}
}
+
}
diff --git a/sites/all/modules/contrib/fields/link/views/link.views.inc b/sites/all/modules/contrib/fields/link/views/link.views.inc
index 27d5182f..8c080ad1 100644
--- a/sites/all/modules/contrib/fields/link/views/link.views.inc
+++ b/sites/all/modules/contrib/fields/link/views/link.views.inc
@@ -1,4 +1,7 @@
default_actions();
$form['title'] = array(
@@ -52,7 +58,7 @@ class link_views_handler_argument_target extends views_handler_argument {
$form['wildcard'] = array(
'#prefix' => '',
- // prefix and no suffix means these two items will be grouped together.
+ // Prefix and no suffix means these two items will be grouped together.
'#type' => 'textfield',
'#title' => t('Wildcard'),
'#size' => 20,
@@ -125,8 +131,8 @@ class link_views_handler_argument_target extends views_handler_argument {
asort($validate_types);
$form['validate_type']['#options'] = $validate_types;
- // Show this gadget if *anything* but 'none' is selected
+ // Show this gadget if *anything* but 'none' is selected.
$form['validate_fail'] = array(
'#type' => 'select',
'#title' => t('Action to take if argument does not validate'),
@@ -140,10 +146,11 @@ class link_views_handler_argument_target extends views_handler_argument {
*
* The argument sent may be found at $this->argument.
*/
- function query($group_by = FALSE) {
+ public function query($group_by = FALSE) {
$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)));
}
+
}
diff --git a/sites/all/modules/contrib/fields/link/views/link_views_handler_filter_protocol.inc b/sites/all/modules/contrib/fields/link/views/link_views_handler_filter_protocol.inc
index a020b4e0..ae00c17e 100644
--- a/sites/all/modules/contrib/fields/link/views/link_views_handler_filter_protocol.inc
+++ b/sites/all/modules/contrib/fields/link/views/link_views_handler_filter_protocol.inc
@@ -7,22 +7,30 @@
/**
* Filter handler for limiting a view to URLs of a certain protocol.
+ *
+ * @codingStandardsIgnoreStart
*/
class link_views_handler_filter_protocol extends views_handler_filter_string {
+
/**
* Set defaults for the filter options.
+ *
+ * @codingStandardsIgnoreEnd
*/
- function options(&$options) {
- parent::options($options);
+ function option_definition() {
+ $options = parent::option_definition();
+
$options['operator'] = 'OR';
$options['value'] = 'http';
$options['case'] = 0;
+
+ return $options;
}
/**
* Define the operators supported for protocols.
*/
- function operators() {
+ public function operators() {
$operators = array(
'OR' => array(
'title' => t('Is one of'),
@@ -35,7 +43,13 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
return $operators;
}
- function options_form(&$form, &$form_state) {
+ /**
+ * Options form.
+ *
+ * @codingStandardsIgnoreStart
+ */
+ public function options_form(&$form, &$form_state) {
+ //@codingStandardsIgnoreEnd
parent::options_form($form, $form_state);
$form['case'] = array(
'#type' => 'value',
@@ -45,8 +59,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Provide a select list to choose the desired protocols.
+ *
+ * @codingStandardsIgnoreStart
*/
- function value_form(&$form, &$form_state) {
+ public function value_form(&$form, &$form_state) {
+ // @codingStandardsIgnoreEnd
// We have to make some choices when creating this as an exposed
// filter form. For example, if the operator is locked and thus
// not rendered, we can't render dependencies; instead we only
@@ -61,7 +78,19 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
'#type' => 'select',
'#title' => t('Protocol'),
'#default_value' => $this->value,
- '#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'))),
+ '#options' => drupal_map_assoc(variable_get('filter_allowed_protocols', array(
+ 'http',
+ 'https',
+ 'ftp',
+ 'news',
+ 'nntp',
+ 'telnet',
+ 'mailto',
+ 'irc',
+ 'ssh',
+ 'sftp',
+ 'webcal',
+ ))),
'#multiple' => 1,
'#size' => 4,
'#description' => t('The protocols displayed here are those globally available. You may add more protocols by modifying the filter_allowed_protocols variable in your installation.'),
@@ -71,8 +100,11 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
/**
* Filter down the query to include only the selected protocols.
+ *
+ * @codingStandardsIgnoreStart
*/
- function op_protocol($field, $upper) {
+ public function op_protocol($field, $upper) {
+ // @codingStandardsIgnoreEnd
$db_type = db_driver();
$protocols = $this->value;
@@ -82,20 +114,25 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
// Simple case, the URL begins with the specified protocol.
$condition = $field . ' LIKE \'' . $protocol . '%\'';
- // More complex case, no protocol specified but is automatically cleaned up
- // by link_cleanup_url(). RegEx is required for this search operation.
+ // More complex case, no protocol specified but is automatically cleaned
+ // up by link_cleanup_url(). RegEx is required for this search operation.
if ($protocol == 'http') {
- $LINK_DOMAINS = _link_domains();
+ $link_domains = _link_domains();
if ($db_type == 'pgsql') {
- // 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.
+ // 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.
+ // @codingStandardsIgnoreLine
// 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.
+ // mySQL requires backslashes to be double (triple?) escaped within
+ // character classes.
+ // @codingStandardsIgnoreLine
// 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]))' . '\'';
}
}
@@ -104,4 +141,5 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
$this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions));
}
+
}