? forum_separation_118676.patch
? use_of_raw_docs_and_warning.patch
Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.44.4.40
diff -u -p -r1.44.4.40 pathauto.module
--- pathauto.module	23 Oct 2007 00:04:41 -0000	1.44.4.40
+++ pathauto.module	24 Oct 2007 18:07:51 -0000
@@ -18,7 +18,10 @@ function pathauto_help($section) {
                   for feeds will have '/feed' added to the end. You should enter a value that is the length of the dst
                   column minus the length of any strings that might get added to the end of the URL. The length of 
                   strings that might get added to the end of your URLs depends on which modules you have enabled and 
-                  on your Pathauto settings. The recommended and default value is 100.</p>");
+                  on your Pathauto settings. The recommended and default value is 100.</p>
+                  <p><strong>Raw Tokens</strong> In Pathauto it is appropriate to use the -raw form of tokens.  Paths are sent through a filtering
+                  system which ensures that raw user content is filtered.  Failure to use -raw tokens can cause problems
+                  with the Pathauto punctuation filtering system.</p>");
       return $output;
   }
 }
@@ -132,9 +135,10 @@ function pathauto_admin_settings() {
     '#description' => t('Maximum number of objects of a given type which should be aliased during a a bulk update. The default is 50 and the recommended number depends on the speed of your server.  If bulk updates "time out" or result in a "white screen" then reduce the number.'));
 
   $actions = array(
-               t('Do nothing. Leave the old alias intact.'),
-               t('Create a new alias. Leave the existing alias functioning.'),
-               t('Create a new alias. Delete the old alias.'));
+    t('Do nothing. Leave the old alias intact.'),
+    t('Create a new alias. Leave the existing alias functioning.'),
+    t('Create a new alias. Delete the old alias.'));
+
   if (function_exists('path_redirect_save')) {
     $actions[] = t('Create a new alias. Redirect from old alias.');
   }
@@ -206,9 +210,18 @@ function pathauto_admin_settings() {
 
     // Prompt for the default pattern for this module
     $variable = 'pathauto_'. $module .'_pattern';
+    $description = '';
+    if (!count($_POST)) {
+      $error = _pathauto_check_pattern(variable_get($variable, $patterndefault), $settings->token_type);
+    }
+    if ($error) {
+      $form[$module]['#collapsed'] = FALSE;
+      $description = t('NOTE: This field contains potentially incorrect patterns.');
+    }
     $form[$module][$variable] = array('#type' => 'textfield',
       '#title' => $patterndescr,
       '#default_value' => variable_get($variable, $patterndefault),
+      '#description' => $description,
       '#size' => 65, '#maxlength' => 128);
 
     // If the module supports a set of specialized patterns, set
@@ -231,7 +244,7 @@ function pathauto_admin_settings() {
       $doc .= '<dd>'. $description .'</dd>';
     }
     $doc .= "</dl>\n";
-    $form[$module][$variable]["#description"] = $doc;
+    $form[$module][$variable]["#description"] .= $doc;
 
     // If the module supports bulk updates, offer the update action here
     if ($settings->bulkname) {
@@ -278,6 +291,51 @@ function pathauto_admin_settings() {
   return system_settings_form($form);
 }
 
+/**
+ *  Helper function to see if they are using all -raw tokens available
+ *  Returns a status flag if there is an error or not
+ */
+function _pathauto_check_pattern($pattern, $type) {
+  // Hold items we've warned about so we only warn once per token
+  static $warned;
+  $return = FALSE;
+
+  // Build up a set of all tokens in a format that's easy to search
+  $all_tokens = array();
+  $tokens = token_get_list($type);
+  foreach ($tokens as $actual_tokens) {
+    foreach (array_keys($actual_tokens) as $token) {
+      $all_tokens[$token] = $token;
+    }
+  }
+
+  // Now, search the pattern and evaluate its contents.
+  $matches = array();
+  if (preg_match_all('/\[[a-zA-z_\-]+\]/i', $pattern, $matches)) {
+    // Loop over each found token.
+    foreach ($matches[0] as $id => $token) {
+      $token = str_replace('[', '', str_replace(']', '', $token));
+      // Check if the token is even valid in this context.
+      if (!array_key_exists($token, $all_tokens)) {
+        drupal_set_message(t('You are using the token [%token] which is not valid within the scope of tokens where you are using it.', array('%token' => $token)), 'error');
+        $return = TRUE;
+      }
+      // Check if there is a raw companion that they should be using.
+      elseif (!preg_match('/\-raw/i', $token)) {
+        $raw_token = $token .'-raw';
+        if (array_key_exists($raw_token, $all_tokens)) {
+          if (!isset($warned) || !array_key_exists($token, $warned)) {
+            drupal_set_message(t('You are using the token [%token] which has a -raw companion available [%raw_token].  For Pathauto patterns you should use the -raw version of tokens unless you really know what you are doing.  See the <a href="@pathauto-help">Pathauto help</a> for more details.', array('%token' => $token, '%raw_token' => $raw_token, '@pathauto-help' => url('admin/help/pathauto'))), 'error');
+            $warned[$token] = $token;
+            $return = TRUE;
+          }
+        }
+      }
+    }
+  }
+  return $return;
+}
+
 function pathauto_admin_settings_validate($form_id, $form_values) {
   // Validate that the separator is not set to be removed per http://drupal.org/node/184119
   // This isn't really all that bad so warn, but still allow them to save the value.
Index: pathauto_node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_node.inc,v
retrieving revision 1.29.4.19
diff -u -p -r1.29.4.19 pathauto_node.inc
--- pathauto_node.inc	21 Oct 2007 15:12:33 -0000	1.29.4.19
+++ pathauto_node.inc	24 Oct 2007 18:07:51 -0000
@@ -9,6 +9,7 @@ function node_pathauto($op) {
     case 'settings':
       $settings = array();
       $settings['module'] = 'node';
+      $settings['token_type'] = 'node';
       $settings['groupheader'] = t('Node path settings');
       $settings['patterndescr'] = t('Default path pattern (applies to all node types with blank patterns below)');
       $settings['patterndefault'] = t('content/[title-raw]');
Index: pathauto_taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_taxonomy.inc,v
retrieving revision 1.20.4.14
diff -u -p -r1.20.4.14 pathauto_taxonomy.inc
--- pathauto_taxonomy.inc	21 Oct 2007 17:45:53 -0000	1.20.4.14
+++ pathauto_taxonomy.inc	24 Oct 2007 18:07:51 -0000
@@ -10,6 +10,7 @@ function taxonomy_pathauto($op) {
     case 'settings':
       $settings = array();
       $settings['module'] = 'taxonomy';
+      $settings['token_type'] = 'taxonomy';
       $settings['groupheader'] = t('Category path settings');
       $settings['patterndescr'] = t('Default path pattern (applies to all vocabularies with blank patterns below)');
       $settings['patterndefault'] = t('category/[vocab-raw]/[catpath-raw]');
Index: pathauto_user.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_user.inc,v
retrieving revision 1.17.4.12
diff -u -p -r1.17.4.12 pathauto_user.inc
--- pathauto_user.inc	16 Oct 2007 14:31:55 -0000	1.17.4.12
+++ pathauto_user.inc	24 Oct 2007 18:07:51 -0000
@@ -9,6 +9,7 @@ function user_pathauto($op) {
     case 'settings':
       $settings = array();
       $settings['module'] = 'user';
+      $settings['token_type'] = 'user';
       $settings['groupheader'] = t('User path settings');
       $settings['patterndescr'] = t('Pattern for user account page paths');
       $settings['patterndefault'] = t('users/[user-raw]');
@@ -37,6 +38,7 @@ function blog_pathauto($op) {
     case 'settings':
       $settings = array();
       $settings['module'] = 'blog';
+      $settings['token_type'] = 'user';
       $settings['groupheader'] = t('Blog path settings');
       $settings['patterndescr'] = t('Pattern for blog page paths');
       $settings['patterndefault'] = t('blogs/[user-raw]');
@@ -61,6 +63,7 @@ function tracker_pathauto($op) {
     case 'settings':
       $settings = array();
       $settings['module'] = 'tracker';
+      $settings['token_type'] = 'user';
       $settings['groupheader'] = t('User-tracker path settings');
       $settings['patterndescr'] = t('Pattern for user-tracker page paths');
       $settings['patterndefault'] = t('users/[user]/track');
