From 398211cd50da447b3dec643ddb6017602cd71473 Mon Sep 17 00:00:00 2001
From: unknown <Mehul.Parmar@LTPPUN022276513.corp.mphasis.com>
Date: Mon, 28 Apr 2014 19:47:38 +0530
Subject: [PATCH 1/1] Requires Login Patch

---
 link.module | 156 ++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 100 insertions(+), 56 deletions(-)

diff --git a/link.module b/link.module
index aad69e8..b358b17 100644
--- a/link.module
+++ b/link.module
@@ -211,6 +211,20 @@ function link_field_instance_settings_form($field, $instance) {
     '#field_suffix' => '"',
     '#size' => 20,
   );
+  $form['requireslogin'] = array(
+    '#title' => t("Requires Login"),
+    '#type' => 'checkbox',
+    '#weight' => -10,
+    '#default_value' => isset($instance['settings']['requireslogin']) && ($instance['settings']['requireslogin'] !== '') ? $instance['settings']['requireslogin'] : FALSE,
+  );
+  $form['requireslogin_text'] = array(
+    '#title' => t("Requires Login Text"),
+    '#type' => 'textfield',
+    '#weight' => -9,
+  	'#default_value' => isset($instance['settings']['requireslogin_text']) && ($instance['settings']['requireslogin_text'] !== '') ? $instance['settings']['requireslogin_text'] : t("Requires Login"),
+  );
+  
+  
   return $form;
 }
 
@@ -691,6 +705,9 @@ function link_theme() {
     'link_formatter_link_separate' => array(
       'variables' => array('element' => NULL, 'field' => NULL),
     ),
+    'link_formatter_link_requireslogin' => array(
+       'variables' => array('element' => NULL, 'field' => NULL),
+    ),
     'link_field' => array(
       'render element' => 'element',
     ),
@@ -881,6 +898,11 @@ function link_field_formatter_info() {
       'field types' => array('link_field'),
       'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
+    'link_requireslogin' => array(
+      'label' => t('Shows login requirement indication'),
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+    ),
   );
 }
 
@@ -922,7 +944,7 @@ function link_field_formatter_settings_summary($field, $instance, $view_mode) {
  * Implements hook_field_formatter_view().
  */
 function link_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
-  $elements = array();
+	$elements = array();
   foreach ($items as $delta => $item) {
     $elements[$delta] = array(
       '#theme' => 'link_formatter_' . $display['type'],
@@ -1057,7 +1079,29 @@ function theme_link_formatter_link_separate($vars) {
   $output .= '</div>';
   return $output;
 }
-
+function theme_link_formatter_link_requireslogin($vars) {
+	$link_options = $vars['element'];
+	$link_title_suffix = (!empty($vars['field']['settings']['requireslogin_text'])) ?
+	   $vars['field']['settings']['requireslogin_text'] : t("Requires Login");
+	$link_title = $vars['element']['title'] . $link_title_suffix;
+	unset($link_options['title']);
+	unset($link_options['url']);
+	
+	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($link_title, $vars['element']['url'], $link_options);
+	}
+	// If only a title, display the title.
+	elseif (!empty($vars['element']['title'])) {
+		return $link_options['html'] ? $link_title : check_plain($link_title);
+	}
+	elseif (!empty($vars['element']['url'])) {
+		return l($link_title, $vars['element']['url'], $link_options);
+	}
+}
 /**
  * Implements hook_token_list().
  */
@@ -1138,63 +1182,63 @@ function link_cleanup_url($url, $protocol = 'http') {
 function link_validate_url($text) {
   // @TODO Complete letters.
   $LINK_ICHARS_DOMAIN = (string) html_entity_decode(implode("", array(
-    "&#x00E6;", // æ
-    "&#x00C6;", // Æ
-    "&#x00C0;", // À
-    "&#x00E0;", // à
-    "&#x00C1;", // Á
-    "&#x00E1;", // á
-    "&#x00C2;", // Â
-    "&#x00E2;", // â
-    "&#x00E5;", // å
-    "&#x00C5;", // Å
-    "&#x00E4;", // ä
-    "&#x00C4;", // Ä
-    "&#x00C7;", // Ç
-    "&#x00E7;", // ç
-    "&#x00D0;", // Ð
-    "&#x00F0;", // ð
-    "&#x00C8;", // È
-    "&#x00E8;", // è
-    "&#x00C9;", // É
-    "&#x00E9;", // é
-    "&#x00CA;", // Ê
-    "&#x00EA;", // ê
-    "&#x00CB;", // Ë
-    "&#x00EB;", // ë
-    "&#x00CE;", // Î
-    "&#x00EE;", // î
-    "&#x00CF;", // Ï
-    "&#x00EF;", // ï
-    "&#x00F8;", // ø
-    "&#x00D8;", // Ø
-    "&#x00F6;", // ö
-    "&#x00D6;", // Ö
-    "&#x00D4;", // Ô
-    "&#x00F4;", // ô
-    "&#x00D5;", // Õ
-    "&#x00F5;", // õ
-    "&#x0152;", // Œ
-    "&#x0153;", // œ
-    "&#x00FC;", // ü
-    "&#x00DC;", // Ü
-    "&#x00D9;", // Ù
-    "&#x00F9;", // ù
-    "&#x00DB;", // Û
-    "&#x00FB;", // û
-    "&#x0178;", // Ÿ
-    "&#x00FF;", // ÿ
-    "&#x00D1;", // Ñ
-    "&#x00F1;", // ñ
-    "&#x00FE;", // þ
-    "&#x00DE;", // Þ
-    "&#x00FD;", // ý
-    "&#x00DD;", // Ý
-    "&#x00BF;", // ¿
+    "&#x00E6;", // Ã¦
+    "&#x00C6;", // Ã†
+    "&#x00C0;", // Ã€
+    "&#x00E0;", // Ã 
+    "&#x00C1;", // Ã�
+    "&#x00E1;", // Ã¡
+    "&#x00C2;", // Ã‚
+    "&#x00E2;", // Ã¢
+    "&#x00E5;", // Ã¥
+    "&#x00C5;", // Ã…
+    "&#x00E4;", // Ã¤
+    "&#x00C4;", // Ã„
+    "&#x00C7;", // Ã‡
+    "&#x00E7;", // Ã§
+    "&#x00D0;", // Ã�
+    "&#x00F0;", // Ã°
+    "&#x00C8;", // Ãˆ
+    "&#x00E8;", // Ã¨
+    "&#x00C9;", // Ã‰
+    "&#x00E9;", // Ã©
+    "&#x00CA;", // ÃŠ
+    "&#x00EA;", // Ãª
+    "&#x00CB;", // Ã‹
+    "&#x00EB;", // Ã«
+    "&#x00CE;", // ÃŽ
+    "&#x00EE;", // Ã®
+    "&#x00CF;", // Ã�
+    "&#x00EF;", // Ã¯
+    "&#x00F8;", // Ã¸
+    "&#x00D8;", // Ã˜
+    "&#x00F6;", // Ã¶
+    "&#x00D6;", // Ã–
+    "&#x00D4;", // Ã”
+    "&#x00F4;", // Ã´
+    "&#x00D5;", // Ã•
+    "&#x00F5;", // Ãµ
+    "&#x0152;", // Å’
+    "&#x0153;", // Å“
+    "&#x00FC;", // Ã¼
+    "&#x00DC;", // Ãœ
+    "&#x00D9;", // Ã™
+    "&#x00F9;", // Ã¹
+    "&#x00DB;", // Ã›
+    "&#x00FB;", // Ã»
+    "&#x0178;", // Å¸
+    "&#x00FF;", // Ã¿
+    "&#x00D1;", // Ã‘
+    "&#x00F1;", // Ã±
+    "&#x00FE;", // Ã¾
+    "&#x00DE;", // Ãž
+    "&#x00FD;", // Ã½
+    "&#x00DD;", // Ã�
+    "&#x00BF;", // Â¿
   )), ENT_QUOTES, 'UTF-8');
 
   $LINK_ICHARS = $LINK_ICHARS_DOMAIN . (string) html_entity_decode(implode("", array(
-    "&#x00DF;", // ß
+    "&#x00DF;", // ÃŸ
   )), 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();
-- 
1.9.2.msysgit.0

