Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodereference_url/README.txt,v
retrieving revision 1.2
diff -u -r1.2 README.txt
--- README.txt	15 Jun 2009 15:03:58 -0000	1.2
+++ README.txt	1 Mar 2010 20:17:29 -0000
@@ -17,11 +17,64 @@
 -------
 Installing the Node Reference URL Widget is simple:
 
-1) Copy the nodereference_url folder to the sites/all/modules folder in your installation.
+1) Copy the nodereference_url folder to the sites/all/modules folder in your
+   installation.
 
-2) Enable the module using Administer -> Modules (/admin/build/modules)
+2) Enable the module using Administer -> Modules (admin/build/modules)
 
 3) Add or edit a CCK Node Reference field from admin/content/node-type/[type]/fields.
+   When configuring the field, use the "Reference from URL" option.
+
+4) Follow on-screen help text to configure your Node Reference URL Widget.
+
+Advanced: Build your own links
+------------------------------
+Normally you can prepopulate a Node Reference URL widget simply by creating a
+link with the following structure:
+
+As HTML:
+<a href="/node/add/story/10">Add a story</a>
+
+Or in PHP code:
+<a href="<?php print url('node/add/story/' . $node->nid); ?>">Add a story</a>
+
+However if using multiple Node Reference fields, you can populate them by
+using a query string instead of embedding the IDs directly in the URL. Assuming
+you had two fields, named "field_ref_a" and "field_ref_b", the URL to
+prepopulate both of them at the same time would look like this:
+
+In HTML:
+<a href="/node/add/story?ref_a=10&ref_b=20">Add a story</a>
+
+Or in PHP code:
+<a href="<?php print url('node/add/story', array('query' => array('ref_a' => $nid1, 'ref_b' => $nid2))); ?>">Add a story</a>
+
+Advanced: Support for non-standard URLs
+---------------------------------------
+By default Node Reference URL Widget will only work with node form paths that
+match the standard Drupal install: "node/add/%type", where %type is a node type
+like "blog" or "story". If you want to use Node Reference URL Widget on
+non-standard URLs, you may do so by informing Node Reference URL Widget of these
+special paths.
+
+To do so, add additional paths to your settings.php with the following code:
+
+$conf['nodereference_url_paths'] = array(
+  'node/add/%type/%nid',
+  'node/%/add/%type/%nid,
+);
+
+Only two tokens are supported:
+%type: The node type that will be created.
+%nid: The node ID that will be referenced.
+
+The % wildcard may be used when including other dynamic IDs.
+
+In the above example, Node Reference URL Widget will work at either
+"node/add/story/2" or "node/1/add/story/2", where "2" is the node ID being
+referenced. Important to note: The first URL will be used in the links that Node
+Reference URL Widget provides. If needing advanced configuration of links, look
+into the Custom Links module: http://drupal.org/project/custom_links.
 
 Support
 -------
@@ -29,4 +82,4 @@
 request or issue in the Node Reference URL Widget queue at
 http://drupal.org/project/issues/nodereference_url. DO NOT POST IN THE FORUMS.
 Posting in the issue queues is a direct line of communication with the module
-authors.
\ No newline at end of file
+authors.
Index: nodereference_url.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodereference_url/nodereference_url.module,v
retrieving revision 1.20
diff -u -r1.20 nodereference_url.module
--- nodereference_url.module	1 Mar 2010 18:50:40 -0000	1.20
+++ nodereference_url.module	1 Mar 2010 20:17:29 -0000
@@ -114,9 +114,17 @@
   if ($referenceable && node_access('create', $field['type_name'])) {
     $link_settings = $field['widget']['node_link'];
     if ((!empty($link_settings['teaser']) && $teaser == TRUE) || (!empty($link_settings['full']) && $teaser == FALSE)) {
+      // Get the first "preferred" path for creating Node Reference links.
+      $link_urls = variable_get('nodereference_url_paths', array('node/add/%type/%nid'));
+
+      // Basic wildcard replacement: %type and %nid.
+      $link_url = $link_urls[0];
+      $link_url = str_replace('%type', str_replace('_', '-', $field['type_name']), $link_url);
+      $link_url = str_replace('%nid', $node->nid, $link_url);
+
       $link = array(
         'title' => t($link_settings['title']),
-        'href' => 'node/add/'. str_replace('_', '-', $field['type_name']) .'/'. $node->nid,
+        'href' => $link_url,
       );
       if (!empty($link_settings['hover_title'])) {
         $link['attributes']['title'] = t($link_settings['hover_title']);
@@ -316,16 +324,43 @@
   $element = array('#tree' => TRUE);
   $field_name = $field['field_name'];
   $field_name_url = preg_replace('/^field_/', '', $field_name);
+  $referenced_nid = NULL;
 
-  // Check for an existing NID or pull it from the URL.
+  // Check for an existing NID.
   if (isset($items[0]['nid']) && is_numeric($items[0]['nid'])) {
     $referenced_nid = $items[0]['nid'];
   }
-  elseif (arg(0) == 'node' && arg(1) == 'add' && isset($_GET[$field_name_url])) {
-    $referenced_nid = is_numeric($_GET[$field_name_url]) ? $_GET[$field_name_url] : NULL;
+  // Check for a reference in the query string.
+  elseif (isset($_GET[$field_name_url]) && is_numeric($_GET[$field_name_url])) {
+    $referenced_nid = $_GET[$field_name_url];
   }
-  elseif (arg(0) == 'node' && arg(1) == 'add') {
-    $referenced_nid = is_numeric(arg(3)) ? arg(3) : NULL;
+  // Pull from the URL.
+  else {
+    $add_urls = variable_get('nodereference_url_paths', array('node/add/%type/%nid'));
+    foreach ($add_urls as $url) {
+      $args = explode('/', $url);
+      foreach ($args as $part => $arg) {
+        $matches = array();
+        // Set the target NID if matching on this part of the URL.
+        if ($arg == '%nid') {
+          $referenced_nid = arg($part);
+        }
+        // Set the target NID based on the field name, allowing for multiple
+        // references in the same URL.
+        elseif ($arg == '%' . $field_name_url) {
+          $referenced_nid = arg($part);
+        }
+        // Skip any other wildcards in the URL.
+        elseif (strpos($arg, '%') === 0) {
+          continue;
+        }
+        // Arguments must line up exactly if they're not a wildcard.
+        elseif (arg($part) != $arg) {
+          $reference_nid = NULL;
+          break;
+        }
+      }
+    }
   }
 
   // Check that the NID is a valid reference.
