| 1 |
<?php |
<?php |
| 2 |
// $Id: invisimail.module,v 1.3.4.5 2009/03/31 22:10:09 crell Exp $ |
// $Id: invisimail.module,v 1.3.4.6 2009/03/31 22:48:38 crell Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 37 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 38 |
); |
); |
| 39 |
} |
} |
| 40 |
|
|
| 41 |
return $items; |
return $items; |
| 42 |
} |
} |
| 43 |
|
|
| 90 |
'#collapsible' => true, '#collapsed' => true |
'#collapsible' => true, '#collapsed' => true |
| 91 |
); |
); |
| 92 |
$form['invisimail_settings'] += _invisimail_settings($format); |
$form['invisimail_settings'] += _invisimail_settings($format); |
| 93 |
|
|
| 94 |
return $form; |
return $form; |
| 95 |
} |
} |
| 96 |
break; |
break; |
| 98 |
} |
} |
| 99 |
|
|
| 100 |
function invisimail($string, $format) { |
function invisimail($string, $format) { |
| 101 |
$pattern = '!(<p>|<li>|<br />|[\s\(])([A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,4})([.,]?)(?=(</p>|</li>|<br />|[\s/)]))!i'; |
$pattern = '!(<p>|<li>|<br />|[\s\(])([A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,4})([.,]?)(?=(</p>|</li>|<br />|[\s/)]))!i'; |
| 102 |
// the callback needs to know what filter we're using |
// the callback needs to know what filter we're using |
| 103 |
// however there's no way to hand off that variable |
// however there's no way to hand off that variable |
| 104 |
// so we'll set a global variable |
// so we'll set a global variable |
| 111 |
$format = $GLOBALS['invisimail_format']; |
$format = $GLOBALS['invisimail_format']; |
| 112 |
$js = variable_get('invisimail_js_'.$format, FALSE); |
$js = variable_get('invisimail_js_'.$format, FALSE); |
| 113 |
$link = variable_get('invisimail_link_'.$format, FALSE); |
$link = variable_get('invisimail_link_'.$format, FALSE); |
| 114 |
|
|
| 115 |
return $matches[1] . invisimail_ascii_encode($matches[2], $js, $link) . $matches[3]; |
return $matches[1] . invisimail_ascii_encode($matches[2], $js, $link) . $matches[3]; |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
/** |
/** |
| 119 |
* This function does the actual encoding. |
* This function does the actual encoding. |
| 120 |
* |
* |
| 121 |
* @param $string |
* @param $string |
| 122 |
* A string which contains only an email addres to be encoded. |
* A string which contains only an email addres to be encoded. |
| 123 |
* @param $js |
* @param $js |
| 124 |
* Optional: A boolean which sets whether Javascript is used for encoding. |
* Optional: A boolean which sets whether Javascript is used for encoding. |
| 125 |
* @param $link |
* @param $link |
| 127 |
* @param $text |
* @param $text |
| 128 |
* Optional: The text to be used for the link. |
* Optional: The text to be used for the link. |
| 129 |
* @return |
* @return |
| 130 |
* An ascii encoded email address. |
* An ascii encoded email address. |
| 131 |
*/ |
*/ |
| 132 |
function invisimail_ascii_encode($string, $js = FALSE, $link = FALSE, $text = NULL) { |
function invisimail_ascii_encode($string, $js = FALSE, $link = FALSE, $text = NULL) { |
| 133 |
|
|
| 134 |
if ($text == NULL) { |
if ($text == NULL) { |
| 135 |
$text = $string; |
$text = $string; |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
if ($js) { |
if ($js) { |
| 139 |
$output = "<script type='text/javascript'><!-- |
$output = "<script type='text/javascript'><!-- |
| 140 |
document.write('"; |
document.write('"; |
| 141 |
} |
} |
| 142 |
|
|
| 143 |
for ($i=0; $i < strlen($string); $i++) { |
for ($i=0; $i < strlen($string); $i++) { |
| 144 |
$char = substr($string, $i, 1); |
$char = substr($string, $i, 1); |
| 145 |
$encode .= '&#'.ord($char).';'; |
$encode .= '&#'.ord($char).';'; |
| 146 |
if ($js) { |
if ($js) { |
| 147 |
if (in_array($char, array('.', '@'))) { |
if (in_array($char, array('.', '@'))) { |
| 148 |
// break strings after ats and dots. |
// break strings after ats and dots. |
| 150 |
} |
} |
| 151 |
} |
} |
| 152 |
} |
} |
| 153 |
|
|
| 154 |
if ($link && !$js) { |
if ($link && !$js) { |
| 155 |
// ascii in this next line is "mailto:" |
// ascii in this next line is "mailto:" |
| 156 |
$output .= "<a href=\"mailto:$encode\">$encode</a>"; |
$output .= "<a href=\"mailto:$encode\">$encode</a>"; |
| 167 |
//--> |
//--> |
| 168 |
</script>"; |
</script>"; |
| 169 |
} |
} |
| 170 |
|
|
| 171 |
return $output; |
return $output; |
| 172 |
} |
} |
| 173 |
|
|
| 199 |
} |
} |
| 200 |
|
|
| 201 |
function theme_invisimail_formatter_invisimail($element) { |
function theme_invisimail_formatter_invisimail($element) { |
| 202 |
|
|
| 203 |
|
// If there's no email address, don't bother trying to encode it. |
| 204 |
|
if ($element['#item']['email'] == '') { |
| 205 |
|
return; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
if (module_exists('invisimail')) { |
if (module_exists('invisimail')) { |
| 209 |
return invisimail_ascii_encode($element['#item']['email'], variable_get('invisimail_js_formatter', FALSE), variable_get('invisimail_link_formatter', FALSE)); |
return invisimail_ascii_encode($element['#item']['email'], variable_get('invisimail_js_formatter', FALSE), variable_get('invisimail_link_formatter', FALSE)); |
| 210 |
} |
} |
| 245 |
'#options' => array(FALSE => t('Do not create links.'), TRUE => t('Automatically create links from email addresses.')), |
'#options' => array(FALSE => t('Do not create links.'), TRUE => t('Automatically create links from email addresses.')), |
| 246 |
'#description' => t('Selecting "Automatically create links" will convert email addresses into a clickable "mailto:" link.'), |
'#description' => t('Selecting "Automatically create links" will convert email addresses into a clickable "mailto:" link.'), |
| 247 |
); |
); |
| 248 |
|
|
| 249 |
return $form; |
return $form; |
| 250 |
} |
} |