--- contextlinks.module	Tue Nov 29 17:49:54 2005
+++ contextlinks.module	Fri Feb 03 22:45:43 2006
@@ -207,8 +207,12 @@
 
 <ul>
   <li>The URL can be relative (some/link), linking to information on
-  the same site, or fully-qualified (http://some.site/), linking to
+  this site, or fully-qualified (http://some.site/), linking to
   information on another site.</li>
+  <li>Alternatively, if a partial external URL (stub) is set in the class,
+   the URL is just the required ending.</li>
+   <li>There is a shortcut entry, where a link to a node on this site can be made
+    by simply entering the node number as the URL.</li>
   <li>The URL can optionally be preceded with a ^ (caret) to force the
   link to open in a new window or a ` (backtick) to force the link to
   open in the current window (if the class defaults to opening in a
@@ -240,7 +244,8 @@
 
       $the_rows[] = array($the_class->name, ($the_class->new_window ? t('Yes') : t('No')), $the_text, _contextlinks_process($the_text));
     }
-
+   $the_text= t('A %shortcut link.', array('%shortcut' => '[?:1 shortcut]'));
+   $the_rows[] = array('Shortcut', '', $the_text, _contextlinks_process($the_text));
     return $the_output . theme('table', $the_header, $the_rows);
   }
   else {
@@ -340,7 +345,7 @@
    * to determine newer/older versions for upgrade and installation
    * purposes.
    */
-  return array('text' => '4.7r1', 'build' => 2005112900);
+  return array('text' => '4.7r2', 'build' => 2006013100);
 } // function _contextlinks_version
 
 /**
@@ -408,7 +413,9 @@
   if ($the_classes[$the_class]) {
     $the_rel = (isset($the_rel) ? $the_rel : $the_classes[$the_class]['rel']);
     $the_rel = ($the_rel ? " rel=\"$the_rel\"" : '');
-    $the_url = (preg_match('!^[a-z]+://!', $the_url) ? $the_url : url($the_url));
+    if(!(preg_match('!^[a-z]+://!', $the_url) || $the_classes[$the_class]['stub'])) {
+      $the_url = url((($the_url==(string)(int)$the_url) ? 'node/'  : '') . $the_url);
+    }
 
     return str_replace(array('%URL', '%TARGET', '%TEXT'), array($the_url, $the_rel, $the_text), $the_classes[$the_class]['markup']);
   }
@@ -429,12 +436,14 @@
     $the_markup .= ($the_markup ? ' ' : '') . $the_matches[2];
   }
 
+    $the_stub='href="'. $the_class->ext_url . '%URL"';
+    
   if (!$the_markup) {
-    $the_markup = '<span class="contextlinks-text"><a href="%URL"%TARGET>%TEXT</a></span>';
+    $the_markup = '<span class="contextlinks-text"><a ' . $the_stub .'%TARGET>%TEXT</a></span>';
   }
   else {
-    $the_text_mark = '<span class="contextlinks-text">' . ($the_class->link_text ? '<a href="%URL"%TARGET>%TEXT</a>' : '%TEXT') . '</span>';
-    $the_markup = $the_matches[1] . '<a href="%URL"%TARGET>' . $the_markup . '</a>' . $the_matches[3];
+    $the_text_mark = '<span class="contextlinks-text">' . ($the_class->link_text ? '<a ' . $the_stub . '%TARGET>%TEXT</a>' : '%TEXT') . '</span>';
+    $the_markup = $the_matches[1] . '<a '. $the_stub . '%TARGET>' . $the_markup . '</a>' . $the_matches[3];
     $the_markup = ($the_class->position ? "$the_text_mark $the_markup" : "$the_markup $the_text_mark");
   }
 
@@ -442,6 +451,7 @@
 
   $the_classes[$the_class->name]['rel'] = ($the_class->new_window ? 'CONTEXTLINKS_NEW_WINDOW' : '');
   $the_classes[$the_class->name]['markup'] = $the_markup;
+  $the_classes[$the_class->name]['stub'] = !empty($the_class->ext_url);
 
   return _contextlinks_callback($in_matches);
 } // function _contextlinks_callback
@@ -479,7 +489,7 @@
  *   A <code>string</code> containing the HTML-formatted form.
  */
 function _contextlinks_admin_form($in_cid = 0) {
-  $the_class = array2object($_POST['edit']);
+  $the_class = (object) $_POST['edit'];
 
   if (intval($in_cid)) {
     $the_class = db_fetch_object(db_query("SELECT cc.* FROM {contextlinks_class} cc WHERE cc.cid = %d", intval($in_cid)));
@@ -526,6 +536,13 @@
     '#title' => t('Link text'),
     '#default_value' => $the_class->link_text,
     '#description' => t('Whether on not this class should make the text of the context link a link also. If neither an image nor a string is specified, this option will be implied.'));
+  $the_form['ext_url'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Ext. URL'),
+    '#default_value' => $the_class->ext_url,
+    '#size' => 70,
+    '#maxlength' => 255,
+    '#description' => t('Optional: Add the starting part of a URL, which the link will be appended to. Use for external sites that are referenced often, such as Drupal.org or Wikipedia. Do not use for your own site unless you require absolute URLs!'));
   $the_form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'));
@@ -558,7 +575,7 @@
  * @param $in_form_values
  *   The form values passed from the form.
  */
-function _contextlinks_admin_form_execute($in_form_id, $in_form_values) {
+function _contextlinks_admin_form_submit($in_form_id, $in_form_values) {
   global $user;
 
   $the_cid = intval($in_form_values['cid']);
@@ -568,25 +585,26 @@
   $the_image = trim($in_form_values['image']);
   $the_string = trim($in_form_values['string']);
   $do_link_text = (($in_form_values['link_text'] || (!$the_image && !$the_string)) ? 1 : 0);
-
+  $the_ext_url = trim($in_form_values['ext_url']);
+  
   if ($the_cid) {
     $the_query = "
 UPDATE {contextlinks_class}
-SET mtime = %d, uid = %d, name = '%s', position = %d, new_window = %d, image = '%s', string = '%s', link_text = %d
+SET mtime = %d, uid = %d, name = '%s', position = %d, new_window = %d, image = '%s', string = '%s', link_text = %d, ext_url = '%s'
 WHERE cid = %d
 ";
 
-    $is_ok = db_query($the_query, time(), $user->uid, $the_name, $the_position, $the_target, $the_image, $the_string, $do_link_text, $the_cid);
+    $is_ok = db_query($the_query, time(), $user->uid, $the_name, $the_position, $the_target, $the_image, $the_string, $do_link_text, $the_ext_url, $the_cid);
   }
   else {
     $the_query = "
 INSERT INTO {contextlinks_class}
-  (cid, ctime, mtime, uid, name, position, new_window, image, string, link_text)
+  (cid, ctime, mtime, uid, name, position, new_window, image, string, link_text, ext_url)
 VALUES
-  (%d, %d, %d, %d, '%s', %d, %d, '%s', '%s', %d)
+  (%d, %d, %d, %d, '%s', %d, %d, '%s', '%s', %d, '%s')
 ";
 
-    $is_ok = db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, $the_name, $the_position, $the_target, $the_image, $the_string, $do_link_text);
+    $is_ok = db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, $the_name, $the_position, $the_target, $the_image, $the_string, $do_link_text, $the_ext_url);
     }
 
   if ($is_ok) {
@@ -596,7 +614,7 @@
   else {
     drupal_set_message(t('Class %name could not be saved.', array('%name' => theme('placeholder', $the_name))), 'error');
   }
-} // _contextlinks_admin_form_execute
+} // _contextlinks_admin_form_submit
 
 /**
  * Deletes a contextlinks class.
@@ -668,7 +686,7 @@
 
   // installed, so show classes
   $the_positions = array(t('before'), t('after'));
-  $the_header = array(array('data' => t('class'), 'field' => 'name', 'sort' => 'asc'), array('data' => t('position'), 'field' => 'position'), array('data' => t('new<br />window'), 'field' => 'new_window'), array('data' => t('image'), 'field' => 'image'), array('data' => t('text'), 'field' => 'string'), array('data' => t('link<br />text'), 'field' => 'link_text'), array('data' => t('operations')));
+  $the_header = array(array('data' => t('class'), 'field' => 'name', 'sort' => 'asc'), array('data' => t('position'), 'field' => 'position'), array('data' => t('new<br />window'), 'field' => 'new_window'), array('data' => t('image'), 'field' => 'image'), array('data' => t('text'), 'field' => 'string'), array('data' => t('link<br />text'), 'field' => 'link_text'), array('data' => t('External Stub'), 'field' => 'ext_url'), array('data' => t('operations')));
   $the_rows = array();
 
   $the_query  = "SELECT cc.* FROM {contextlinks_class} cc";
@@ -677,7 +695,7 @@
   $the_result = db_query($the_query);
 
   while ($the_class = db_fetch_object($the_result)) {
-    $the_rows[] = array($the_class->name, $the_positions[$the_class->position], ($the_class->new_window ? t('Yes') : t('No')), ($the_class->image ? "$the_class->image<br />\n<img src=\"$the_class->image\" alt=\"?\" style=\"width: 1.2em; height: 1.2em;\" />" : ''), $the_class->string, ($the_class->link_text ? t('Yes') : t('No')), l(t('edit'), "admin/contextlinks/edit/$the_class->cid") . ' ' . l(t('delete'), "admin/contextlinks/delete/$the_class->cid"));
+    $the_rows[] = array($the_class->name, $the_positions[$the_class->position], ($the_class->new_window ? t('Yes') : t('No')), ($the_class->image ? "$the_class->image<br />\n<img src=\"$the_class->image\" alt=\"?\" style=\"width: 1.2em; height: 1.2em;\" />" : ''), $the_class->string, ($the_class->link_text ? t('Yes') : t('No')), $the_class->ext_url, l(t('edit'), "admin/contextlinks/edit/$the_class->cid") . ' ' . l(t('delete'), "admin/contextlinks/delete/$the_class->cid"));
   }
 
   return $the_output . theme('table', $the_header, $the_rows);
@@ -713,7 +731,8 @@
   new_window INTEGER(1) NOT NULL,
   image VARCHAR(255) NOT NULL,
   string VARCHAR(255) NOT NULL,
-  link_text INTEGER(1) NOT NULL
+  link_text INTEGER(1) NOT NULL,
+  ext_url VARCHAR(255)
 )
 ';
 
@@ -723,25 +742,26 @@
     else {
       $the_query = "
 INSERT INTO {contextlinks_class}
-  (cid, ctime, mtime, uid, name, position, new_window, image, string, link_text)
+  (cid, ctime, mtime, uid, name, position, new_window, image, string, link_text, ext_url)
 VALUES
-  (%d, %d, %d, %d, '%s', %d, %d, '%s', '%s', %d)
+  (%d, %d, %d, %d, '%s', %d, %d, '%s', '%s', %d, '%s')
 ";
 
       $the_path = drupal_get_path('module', 'contextlinks');
       $the_default = db_next_id('{contextlinks}_cid');
-      db_query($the_query, $the_default, time(), time(), $user->uid, 'link', 1, 0, '', '', 1);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'external', 1, 1, "$the_path/images/external.gif", '', 1);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'info', 1, 0, "$the_path/images/info.gif", '', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'info-text', 1, 0, '', '[info]', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'note', 1, 0, "$the_path/images/note.gif", '', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'note-text', 1, 0, '', '[note]', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'person', 1, 0, "$the_path/images/person.gif", '', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'person-text', 1, 0, '', '[person]', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'question', 1, 0, "$the_path/images/question.gif", '', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'question-text', 1, 0, '', '[?]', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'warning', 1, 0, "$the_path/images/warning.gif", '', 0);
-      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'warning-text', 1, 0, '', '[warning]', 0);
+      db_query($the_query, $the_default, time(), time(), $user->uid, 'link', 1, 0, '', '', 1, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'external', 1, 1, "$the_path/images/external.gif", '', 1, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'info', 1, 0, "$the_path/images/info.gif", '', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'info-text', 1, 0, '', '[info]', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'note', 1, 0, "$the_path/images/note.gif", '', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'note-text', 1, 0, '', '[note]', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'person', 1, 0, "$the_path/images/person.gif", '', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'person-text', 1, 0, '', '[person]', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'question', 1, 0, "$the_path/images/question.gif", '', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'question-text', 1, 0, '', '[?]', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'warning', 1, 0, "$the_path/images/warning.gif", '', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'warning-text', 1, 0, '', '[warning]', 0, '');
+      db_query($the_query, db_next_id('{contextlinks}_cid'), time(), time(), $user->uid, 'wp', 1, 1, '', '[wikipedia]', 0, 'http://en.wikipedia.org/wiki/');
 
       // installed successfully
       variable_set('contextlinks_version', $the_current_ver);
