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

Diff of /contributions/modules/urlify/urlify.module

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

revision 1.4.2.1, Sat Jan 13 23:21:40 2007 UTC revision 1.4.2.2, Sat Sep 29 06:23:39 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: urlify.module,v 1.4 2006/11/01 04:57:47 canen Exp $  // $Id: urlify.module,v 1.4.2.1 2007/01/13 23:21:40 canen Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 51  function urlify_menu($may_cache) { Line 51  function urlify_menu($may_cache) {
51        'type' => MENU_LOCAL_TASK);        'type' => MENU_LOCAL_TASK);
52    }    }
53    else if (_urlify_insert_js()){    else if (_urlify_insert_js()){
54      drupal_set_html_head(urlify_head());      $default_remove_list = array(
55          "a", "an", "as", "at", "before", "but", "by", "for", "from",
56          "is", "in", "into", "like", "of", "off", "on", "onto", "per",
57          "since", "than", "the", "this", "that", "to", "up", "via",
58          "with"
59        );
60    
61        $remove_list = preg_replace("/(\w+)/e","\"'$1'\"", variable_get('urlify_strings_to_ignore', implode(',', $default_remove_list)));
62    
63        drupal_add_js(array('urlify' => array('remove_list' => $remove_list)), 'setting');
64        drupal_add_js(drupal_get_path('module', 'urlify') . '/urlify.js');
65    }    }
66    
67    return $items;    return $items;
# Line 73  function urlify_settings() { Line 83  function urlify_settings() {
83      '#type' => 'textarea',      '#type' => 'textarea',
84      '#title' => t('Strings to remove from generated URL'),      '#title' => t('Strings to remove from generated URL'),
85      '#default_value' => variable_get('urlify_strings_to_ignore', implode(',', $strings_to_ignore)),      '#default_value' => variable_get('urlify_strings_to_ignore', implode(',', $strings_to_ignore)),
86      '#description' => t('A list of words(strings) to remove from generated url separated by commas.')      '#description' => t('A list of words (strings) to remove from generated url, separated by commas.')
87      );      );
88    
89    $form['urlify_max_characters'] = array(    $form['urlify_max_characters'] = array(
# Line 88  function urlify_settings() { Line 98  function urlify_settings() {
98  }  }
99    
100  /**  /**
101   * Implementation of hook_form_alter()   * Decide if the javascript should be inserted.
102   */   *
103  function urlify_head() {   * Only insert on node/add/nodetype and node/$nid/edit pages.
   $default_remove_list = array(  
     "a", "an", "as", "at", "before", "but", "by", "for", "from",  
     "is", "in", "into", "like", "of", "off", "on", "onto", "per",  
     "since", "than", "the", "this", "that", "to", "up", "via",  
     "with"  
   );  
   
   $remove_list = preg_replace("/(\w+)/e","\"'$1'\"", variable_get('urlify_strings_to_ignore', implode(',', $default_remove_list)));  
   $output = <<<EOF  
 <script type="text/javascript">  
 function URLify(s, num_chars) {  
   // changes, e.g., "Petty theft" to "petty_theft"  
   // remove all these words from the string before urlifying  
   removelist = [$remove_list];  
   r = new RegExp('\\\b(' + removelist.join('|') + ')\\\b', 'gi');  
   s = s.replace(r, '');  
   s = s.replace(/[^-A-Z0-9\s]/gi, '');  // remove unneeded chars  
   s = s.replace(/^\s+|\s+$/g, '');      // trim leading/trailing spaces  
   s = s.replace(/[-\s]+/g, '-');        // convert spaces to hyphens  
   s = s.toLowerCase();                  // convert to lowercase  
   return s.substring(0, num_chars);     // trim to first num_chars chars  
 }  
 </script>  
 EOF;  
   return $output;  
 }  
   
 /**  
  * Decide if the javascript should be inserted. Only insert on  
  * node/add/nodetype and node/$nid/edit pages  
104   */   */
105  function _urlify_insert_js() {  function _urlify_insert_js() {
106    if ((arg(0) == 'node' && ((arg(1) == 'add' && arg(2)) ||    if ((arg(0) == 'node' && ((arg(1) == 'add' && arg(2)) || arg(2) == 'edit'))) {
        arg(2) == 'edit'))) {  
107      return TRUE;      return TRUE;
108    }    }
109    else {    else {

Legend:
Removed from v.1.4.2.1  
changed lines
  Added in v.1.4.2.2

  ViewVC Help
Powered by ViewVC 1.1.2