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

Diff of /contributions/modules/comment_page/comment_page.module

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

revision 1.1, Tue May 1 14:07:10 2007 UTC revision 1.2, Fri Jun 13 20:10:52 2008 UTC
# Line 20  function comment_page_menu($may_cache) { Line 20  function comment_page_menu($may_cache) {
20        'description' => t('Adjust the settings for the comment page module.'),        'description' => t('Adjust the settings for the comment page module.'),
21        'callback' => 'drupal_get_form',        'callback' => 'drupal_get_form',
22        'callback arguments' => array('comment_page_settings'),        'callback arguments' => array('comment_page_settings'),
23        'access' => user_access('admin comments'),        'access' => user_access('administer comments'),
24        'type' => MENU_NORMAL_ITEM,        'type' => MENU_NORMAL_ITEM,
25      );      );
26    }    }
# Line 145  function comment_page_settings() { Line 145  function comment_page_settings() {
145      '#size' => 16,      '#size' => 16,
146    );    );
147    
   // Default words to ignore  
   $ignore_words = 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"  
   );  
   
148    $form['url'] = array(    $form['url'] = array(
149      '#type' => 'fieldset',      '#type' => 'fieldset',
150      '#title' => t('Comment URL settings'),      '#title' => t('Comment URL settings'),
# Line 161  function comment_page_settings() { Line 154  function comment_page_settings() {
154    $form['url']['comment_subject_in_url'] = array(    $form['url']['comment_subject_in_url'] = array(
155      '#type' => 'checkbox',      '#type' => 'checkbox',
156      '#title' => t('Include the comment subject in the page URL.'),      '#title' => t('Include the comment subject in the page URL.'),
157        '#description' => t('This setting is only taken into account if <a href="!url">Pathauto</a> is installed and enabled.', array('!url' => 'http://drupal.org/project/pathauto')),
158      '#default_value' => variable_get('comment_subject_in_url', TRUE),      '#default_value' => variable_get('comment_subject_in_url', TRUE),
159    );    );
   $form['url']['text'] = array(  
     '#value' => '<div>'. t('If Pathauto is enabled, the settings in these fields will default to the Pathauto settings.  However, any changes here will not affect Pathauto URL aliasing.') .'</div>',  
   );  
   $form['url']['comment_page_separator'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Separator'),  
     '#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters.'),  
     '#default_value' => variable_get('comment_page_separator', variable_get('pathauto_separator', '-')),  
     '#size' => 1,  
     '#maxlength' => 1,  
   );  
   $form['url']['comment_page_quotes'] = array(  
     '#type' => 'radios',  
     '#title' => t('Quotation marks'),  
     '#options' => array(t('Remove'), t('Replace by separator')),  
     '#default_value' => variable_get('comment_page_quotes', variable_get('pathauto_quotes', 0)),  
   );  
   $form['url']['comment_page_max_comp_length'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Maximum component length'),  
     '#description' => t('Maximum text length of the comment subject alias. 100 is recommended.'),  
     '#default_value' => variable_get('comment_page_max_comp_length', variable_get('pathauto_max_component_length', 100)),  
     '#size' => 3,  
     '#maxlength' => 3,  
   );  
   $form['url']['comment_page_ignore_words'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Strings to remove'),  
     '#default_value' => variable_get('comment_page_ignore_words', variable_get('pathauto_ignore_words', implode(",", $ignore_words))),  
     '#description' => t('Words to strip out of the URL alias, separated by commas'),  
     '#rows' => 2,  
   );  
160    
161    return system_settings_form($form);    return system_settings_form($form);
162  }  }
# Line 203  function comment_page_settings() { Line 165  function comment_page_settings() {
165   * Display a comment as a page.   * Display a comment as a page.
166   */   */
167  function comment_page_display($comment_id) {  function comment_page_display($comment_id) {
168      // Load up the comment.
169    $comment = _comment_load($comment_id);    $comment = _comment_load($comment_id);
170    
171      // Check to make sure the user can access the node.
172      $node = node_load($comment->nid);
173      if ($node->nid) {
174        if (!node_access('view', $node)) {
175          drupal_access_denied();
176        }
177      }
178      else {
179        drupal_not_found();
180      }
181    
182    if (variable_get('default_comment_subject_on', TRUE) &&    if (variable_get('default_comment_subject_on', TRUE) &&
183        substr($comment->comment, 0, strlen($comment->subject)) == $comment->subject) {        substr($comment->comment, 0, strlen($comment->subject)) == $comment->subject) {
184      $title = variable_get('default_comment_subject_prefix', t('Re:')) .' ';      $title = variable_get('default_comment_subject_prefix', t('Re:')) .' ';
# Line 235  function comment_page_display($comment_i Line 209  function comment_page_display($comment_i
209   * Returns the URL for a comment page.   * Returns the URL for a comment page.
210   */   */
211  function comment_page_url($cid, $subject = NULL) {  function comment_page_url($cid, $subject = NULL) {
212    if (empty($subject) || !variable_get('comment_subject_in_url', TRUE)) {    if (empty($subject) || !variable_get('comment_subject_in_url', TRUE) || !function_exists('pathauto_cleanstring')) {
213      return 'comment/'. $cid;      return 'comment/'. $cid;
214    }    }
215    else {    else {
# Line 245  function comment_page_url($cid, $subject Line 219  function comment_page_url($cid, $subject
219          $subject = substr($subject, strlen($prefix) + 1);          $subject = substr($subject, strlen($prefix) + 1);
220        }        }
221      }      }
222      return 'comment/'. $cid .'/'. comment_page_cleanstring($subject);      return 'comment/'. $cid .'/'. pathauto_cleanstring($subject);
223    }    }
224  }  }
225    
226  /**  /**
  * Clean up a string value provided by a module, resulting in a string  
  * containing only alphanumerics and separators; from Pathauto.  
  */  
 function comment_page_cleanstring($string) {  
   // Default words to ignore  
   $ignore_words = 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"  
   );  
   
   // Replace or drop apostrophes based on user settings  
   $separator = variable_get('comment_page_separator', variable_get('pathauto_separator', '-'));  
   $quotes = variable_get('comment_page_quotes', variable_get('pathauto_quotes', 0));  
   $output = str_replace("'", ($quotes ? $separator : ''), $string);  
   
   // Get rid of words that are on the ignore list  
   $ignore_re = "\b". preg_replace("/,/", "\b|\b", variable_get('comment_page_ignore_words', variable_get('pathauto_ignore_words', $ignore_words))) ."\b";  
   $output = preg_replace("/$ignore_re/ie", "", $output);  
   
   // Preserve alphanumerics, everything else becomes a separator  
   $pattern = '/[^a-zA-Z0-9]+/ ';  
   $output = preg_replace($pattern, $separator, $output);  
   
   // Trim any leading or trailing separators (note the need to  
   // escape the separator if and only if it is not alphanumeric)  
   if ($separator) {  
     if (ctype_alnum($separator)) {  
       $seppattern = $separator;  
     }  
     else {  
       $seppattern = '\\'.$separator;  
     }  
     $output = preg_replace("/^$seppattern+|$seppattern+$/", "", $output);  
   }  
   
   // Enforce the maximum component length  
   $maxlength = min(variable_get('comment_page_max_comp_length', variable_get('pathauto_max_component_length', 100)), 128);  
   $output = drupal_substr($output, 0, $maxlength);  
   
   return $output;  
 }  
   
 /**  
227   * Return the threaded list for display on a comment page.   * Return the threaded list for display on a comment page.
228   */   */
229  function comment_page_thread($comment, $show_node = TRUE) {  function comment_page_thread($comment, $show_node = TRUE) {
# Line 402  function comment_page_thread($comment, $ Line 332  function comment_page_thread($comment, $
332    
333    return $output;    return $output;
334  }  }
335    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2