/[drupal]/contributions/modules/invisimail/invisimail.module
ViewVC logotype

Diff of /contributions/modules/invisimail/invisimail.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3.4.6, Tue Mar 31 22:48:38 2009 UTC revision 1.3.4.7, Thu Jun 18 21:25:01 2009 UTC
# Line 1  Line 1 
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
# Line 37  function invisimail_menu() { Line 37  function invisimail_menu() {
37        'type' => MENU_NORMAL_ITEM,        'type' => MENU_NORMAL_ITEM,
38      );      );
39    }    }
40    
41    return $items;    return $items;
42  }  }
43    
# Line 90  function invisimail_filter($op, $delta = Line 90  function invisimail_filter($op, $delta =
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;
# Line 98  function invisimail_filter($op, $delta = Line 98  function invisimail_filter($op, $delta =
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
# Line 111  function invisimail_callback($matches) { Line 111  function invisimail_callback($matches) {
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
# Line 127  function invisimail_callback($matches) { Line 127  function invisimail_callback($matches) {
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.
# Line 149  function invisimail_ascii_encode($string Line 150  function invisimail_ascii_encode($string
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=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;$encode\">$encode</a>";      $output .= "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;$encode\">$encode</a>";
# Line 166  function invisimail_ascii_encode($string Line 167  function invisimail_ascii_encode($string
167      //-->      //-->
168      </script>";      </script>";
169    }    }
170    
171    return $output;    return $output;
172  }  }
173    
# Line 198  function invisimail_theme() { Line 199  function invisimail_theme() {
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    }    }
# Line 238  function _invisimail_settings($format) { Line 245  function _invisimail_settings($format) {
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  }  }

Legend:
Removed from v.1.3.4.6  
changed lines
  Added in v.1.3.4.7

  ViewVC Help
Powered by ViewVC 1.1.2