--- modules/technorati/technorati.module	2007-04-28 21:48:10.000000000 +0000
+++ modules/technorati/technoratiNew.module	2007-04-28 22:21:56.000000000 +0000
@@ -1,256 +1,277 @@
-<?php
-// $Id: technorati.module,v 1.6.2.2 2007/04/13 19:35:35 kbahey Exp $
-
-// Copyright 2006 http://2bits.com
-
-define('TECHNORATI_NODE_TYPE',       'technorati_node_type_');
-
-define('TECHNORATI_MODE_NONE',       0);
-define('TECHNORATI_MODE_MANUAL',     1);
-define('TECHNORATI_MODE_TAXONOMY',   2);
-define('TECHNORATI_MODE_BOTH',       3);
-
-define('TECHNORATI_DISPLAY_TYPE',    'technorati_display_type');
-
-define('TECHNORATI_DISPLAY_NONE',    0);
-define('TECHNORATI_DISPLAY_TEASER',  1);
-define('TECHNORATI_DISPLAY_FULL',    2);
-define('TECHNORATI_DISPLAY_BOTH',    3);
-
-function technorati_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t('Enables Technorati tags for selected content types, and pings Technorati when new content is created.');
-  }
-}
-
-function technorati_menu($may_cache) {
-  $items = array();
-
-    $items[] = array(
-      'path' => 'admin/settings/technorati',
-      'title' => t('Technorati'),
-      'description' => t('technorati settings.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('technorati_admin_settings'),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM, // optional
-    );
-  return $items;
-}
-
-
-function technorati_admin_settings() {
-  if (!module_exists('ping')) {
-    drupal_set_message(t('This module requires that the %pingmodule be enabled',
-      array('%pingmodule' => l('ping module', 'admin/modules'))), 'error');
-      return;
-  }
-
-  $display_options = array(
-    TECHNORATI_DISPLAY_NONE    => t('None'),
-    TECHNORATI_DISPLAY_TEASER  => t('Teaser view'),
-    TECHNORATI_DISPLAY_FULL    => t('Full page view'),
-    TECHNORATI_DISPLAY_BOTH    => t('Both'),
-  );
-
-  $node_options = array(
-    TECHNORATI_MODE_NONE     => t('None'),
-    TECHNORATI_MODE_MANUAL   => t('Manual entry'),
-    TECHNORATI_MODE_TAXONOMY => t('Drupal categories'),
-    TECHNORATI_MODE_BOTH     => t('Both'),
-  );
-
-  $form[TECHNORATI_DISPLAY_TYPE] = array(
-    '#type'          => 'select',
-    '#title'         => t('How to display the technorati tags'),
-    '#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),
-    '#options'       => $display_options,
-    '#description' => t('Select how to display the tags.<ul><li>None: means that the module will not display the tags. The theme can use the $node->technorati object to display the tags anywhere.</li><li>Teaser: means that the tags will only be displayed when the node is in teaser view.</li><li>Full page: means that the tags will only be displayed when the node is in full page view.</li><li>Both: means the tags will be displayed in both teaser and full view.</li></ul>'),
-  );
-
-  $form['types'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Content types'),
-    '#collapsible' => TRUE,
-    '#description' => t('Select the type of tags to use for each content type.<ul><li>None: means do not do any Technorati tags for this content type.</li><li>Manual entry: means that the tags have to be entered manually for each node.</li><li>Drupal categories: means that the terms the node belong to will be used as Technorati tags.</li><li>Both: means a combination of manual entries and categories.</li></ul>'),
-  );
-
-  foreach(node_get_types() as $node_type => $node_name) {
-    $type = TECHNORATI_NODE_TYPE . $node_type;
-    $form['types'][$type] = array(
-      '#type'          => 'select',
-      '#title'         => $node_type,
-      '#default_value' => variable_get($type, TECHNORATI_MODE_NONE),
-      '#options'       => $node_options,
-    );
-  }
-
- return system_settings_form($form);
-}
-
-function technorati_form_alter($form_id, &$form) {
-  if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {
-    // Get the node type we are processing
-    $node_type = $matches[1];
-
-    // Check what the technorati mode for that node type
-    $mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);
-    switch($mode) {
-      case TECHNORATI_MODE_NONE:
-      case TECHNORATI_MODE_TAXONOMY:
-        // No need to do anything in the node form
-        return;
-
-      case TECHNORATI_MODE_MANUAL:
-      case TECHNORATI_MODE_BOTH:
-        // We need to inject the texfield for technorati tags in the form
-        $tags = '';
-        // Load the node and get the technorati tags, if present
-        if ($nid = $form['nid']['#value']) {
-          $node = node_load($nid);
-          if (is_array($node->technorati_tags)) {
-            $tags = implode(',', $node->technorati_tags);
-          }
-        }
-
-        $form['technorati'] = array(
-          '#type'        => 'fieldset',
-          '#title'       => t('Technorati'),
-          '#collapsible' => TRUE,
-          '#collapsed'   => TRUE,
-        );
-
-        $form['technorati']['technorati_tags'] = array(
-          '#type'          => 'textfield',
-          '#title'         => t('Technorati tags'),
-          '#default_value' => $tags,
-          '#size'          => 80,
-          '#maxlength'     => 120,
-          '#description'   => t('Enter your Technorati tags, separated by commas.'),
-        );
-    }
-  }
-}
-
-function technorati_nodeapi(&$node, $op, $teaser, $page) {
-  $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
-  switch($mode) {
-    case TECHNORATI_MODE_NONE:
-    case TECHNORATI_MODE_TAXONOMY:
-      // No need to do anything in the node form
-      return;
-  }
-
-  switch ($op) {
-    case 'insert':
-      db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
-        $node->nid, serialize(explode(',', $node->technorati_tags)));
-      break;
-
-    case 'update':
-      db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
-      db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
-        $node->nid, serialize(explode(',', $node->technorati_tags)));
-      break;
-
-    case 'delete':
-      db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
-      break;
-
-    case 'load':
-      $result = db_query('SELECT tags FROM {technorati} WHERE nid = %d', $node->nid);
-      $tags = unserialize(db_result($result));
-      if ($tags) {
-        return array('technorati_tags' => $tags);
-      }
-      break;
-
-    case 'view':
-      $technorati = array (
-        '#value' => theme('technorati_tags', _technorati_process_tags($node)),
-        '#weight' => 10,
-        );
-      $mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);
-      switch($mode) {
-        case TECHNORATI_DISPLAY_NONE:
-          // No inline display. Theme will handle it all.
-          break;
-        case TECHNORATI_DISPLAY_TEASER:
-          // Teaser view only
-	  if ($teaser) {
-            $node->content['technorati'] = $technorati;
-          }
-          break;
-        case TECHNORATI_DISPLAY_FULL:
-          // Full page view only
-	  if (!$teaser) {
-	    $node->content['technorati'] = $technorati;
-          }
-          break;
-        case TECHNORATI_DISPLAY_BOTH:
-          // Teaser and full page view 
-	  $node->content['technorati'] = $technorati;
-          break;
-      }
-      break;
-  }
-}
-
-function theme_technorati_tags($tags) {
-  $path = base_path() . drupal_get_path('module', 'technorati') . '/technobubble.gif';
-  $output = '<div class="technorati_tags">';
-  $output .= '<img src="' . $path . '"/>';
-  $output .= '<strong>' . t('Technorati Tags: ') . '</strong>';
-  $output .= implode(' ', $tags);
-  $output .= '</div>';
-  //$output .= '<script type="text/javascript" src="http://technorati.com/embed/CODE.js"></script>';
-  return $output; 
-}
-
-function _technorati_process_tags($node) {
-  $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
-  switch($mode) {
-    case TECHNORATI_MODE_MANUAL:
-      return _technorati_manual($node);
-
-    case TECHNORATI_MODE_TAXONOMY:
-      return _technorati_taxonomy($node);
-
-    case TECHNORATI_MODE_BOTH:
-      return array_merge(_technorati_taxonomy($node),  _technorati_manual($node));
-  }
-}
-
-function _technorati_manual($node) {
-  $links = array();
-  if (is_array($node->technorati_tags)) {
-    foreach($node->technorati_tags as $tag) {
-      $links[] = _technorati_link($tag);
-    }
-  }
-  return $links;
-}
-
-function _technorati_taxonomy($node) {
-  $links = array();
-  $terms = taxonomy_node_get_terms($node->nid);
-  foreach ($terms as $term) {
-    $links[] = _technorati_link($term->name);
-  }
-  return $links;
-}
-
-function _technorati_link($tag) {
-  return '<a href="http://technorati.com/tag/' . check_plain($tag) . '" rel="tag">' . check_plain($tag) . '</a>';
-}
-
-function technorati_ping($name = '', $url = '') {
-  $result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
-  if ($result) {
-    watchdog("directory ping", t('Successfully notified technorati.com site.'), WATCHDOG_NOTICE);
-  }
-  else {
-    watchdog('directory ping', t('Failed to notify technorati.com site.'), WATCHDOG_WARNING);
-  }
-}
+<?php
+// $Id: technorati.module,v 1.6.2.2 2007/04/13 19:35:35 kbahey Exp $
+
+// Copyright 2006 http://2bits.com
+
+define('TECHNORATI_NODE_TYPE',       'technorati_node_type_');
+
+define('TECHNORATI_MODE_NONE',       0);
+define('TECHNORATI_MODE_MANUAL',     1);
+define('TECHNORATI_MODE_TAXONOMY',   2);
+define('TECHNORATI_MODE_BOTH',       3);
+
+define('TECHNORATI_DISPLAY_TYPE',    'technorati_display_type');
+
+define('TECHNORATI_DISPLAY_NONE',    0);
+define('TECHNORATI_DISPLAY_TEASER',  1);
+define('TECHNORATI_DISPLAY_FULL',    2);
+define('TECHNORATI_DISPLAY_BOTH',    3);
+
+function technorati_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Enables Technorati tags for selected content types, and pings Technorati when new content is created.');
+  }
+}
+
+function technorati_menu($may_cache) {
+  $items = array();
+
+    $items[] = array(
+      'path' => 'admin/settings/technorati',
+      'title' => t('Technorati'),
+      'description' => t('technorati settings.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('technorati_admin_settings'),
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM, // optional
+    );
+  return $items;
+}
+
+
+function technorati_admin_settings() {
+  if (!module_exists('ping')) {
+    drupal_set_message(t('This module requires that the %pingmodule be enabled',
+      array('%pingmodule' => l('ping module', 'admin/modules'))), 'error');
+      return;
+  }
+
+  $display_options = array(
+    TECHNORATI_DISPLAY_NONE    => t('None'),
+    TECHNORATI_DISPLAY_TEASER  => t('Teaser view'),
+    TECHNORATI_DISPLAY_FULL    => t('Full page view'),
+    TECHNORATI_DISPLAY_BOTH    => t('Both'),
+  );
+
+  $node_options = array(
+    TECHNORATI_MODE_NONE     => t('None'),
+    TECHNORATI_MODE_MANUAL   => t('Manual entry'),
+    TECHNORATI_MODE_TAXONOMY => t('Drupal categories'),
+    TECHNORATI_MODE_BOTH     => t('Both'),
+  );
+
+  $form[TECHNORATI_DISPLAY_TYPE] = array(
+    '#type'          => 'select',
+    '#title'         => t('How to display the technorati tags'),
+    '#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),
+    '#options'       => $display_options,
+    '#description' => t('Select how to display the tags.<ul><li>None: means that the module will not display the tags. The theme can use the $node->technorati object to display the tags anywhere.</li><li>Teaser: means that the tags will only be displayed when the node is in teaser view.</li><li>Full page: means that the tags will only be displayed when the node is in full page view.</li><li>Both: means the tags will be displayed in both teaser and full view.</li></ul>'),
+  );
+
+  $form['types'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Content types'),
+    '#collapsible' => TRUE,
+    '#description' => t('Select the type of tags to use for each content type.<ul><li>None: means do not do any Technorati tags for this content type.</li><li>Manual entry: means that the tags have to be entered manually for each node.</li><li>Drupal categories: means that the terms the node belong to will be used as Technorati tags.</li><li>Both: means a combination of manual entries and categories.</li></ul>'),
+  );
+
+  foreach(node_get_types() as $node_type => $node_name) {
+    $type = TECHNORATI_NODE_TYPE . $node_type;
+    $form['types'][$type] = array(
+      '#type'          => 'select',
+      '#title'         => $node_type,
+      '#default_value' => variable_get($type, TECHNORATI_MODE_NONE),
+      '#options'       => $node_options,
+    );
+  }
+
+ return system_settings_form($form);
+}
+
+function technorati_form_alter($form_id, &$form) {
+  if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {
+    // Get the node type we are processing
+    $node_type = $matches[1];
+
+    // Check what the technorati mode for that node type
+    $mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);
+    switch($mode) {
+      case TECHNORATI_MODE_NONE:
+      case TECHNORATI_MODE_TAXONOMY:
+        // No need to do anything in the node form
+        return;
+
+      case TECHNORATI_MODE_MANUAL:
+      case TECHNORATI_MODE_BOTH:
+        // We need to inject the texfield for technorati tags in the form
+        $tags = '';
+        // Load the node and get the technorati tags, if present
+        if ($nid = $form['nid']['#value']) {
+          $node = node_load($nid);
+          if (is_array($node->technorati_tags)) {
+            $tags = implode(',', $node->technorati_tags);
+          }
+        }
+
+        $form['technorati'] = array(
+          '#type'        => 'fieldset',
+          '#title'       => t('Technorati'),
+          '#collapsible' => TRUE,
+          '#collapsed'   => TRUE,
+        );
+
+        $form['technorati']['technorati_tags'] = array(
+          '#type'          => 'textfield',
+          '#title'         => t('Technorati tags'),
+          '#default_value' => $tags,
+          '#size'          => 80,
+          '#maxlength'     => 120,
+          '#description'   => t('Enter your Technorati tags, separated by commas.'),
+        );
+    }
+  }
+}
+
+function technorati_nodeapi(&$node, $op, $teaser, $page) {
+  $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
+  switch($mode) {
+    case TECHNORATI_MODE_NONE:
+    case TECHNORATI_MODE_TAXONOMY:
+      // No need to do anything in the node form
+      return;
+  }
+
+  switch ($op) {
+    case 'insert':
+      db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
+        $node->nid, serialize(explode(',', $node->technorati_tags)));
+      break;
+
+    case 'update':
+      db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
+      db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
+        $node->nid, serialize(explode(',', $node->technorati_tags)));
+      break;
+
+    case 'delete':
+      db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
+      break;
+
+    case 'load':
+      $result = db_query('SELECT tags FROM {technorati} WHERE nid = %d', $node->nid);
+      $tags = unserialize(db_result($result));
+      if ($tags) {
+        return array('technorati_tags' => $tags);
+      }
+      break;
+
+    case 'view':
+      $technorati = array (
+        '#value' => theme('technorati_tags', _technorati_process_tags($node)),
+        '#weight' => 10,
+        );
+      $mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);
+      switch($mode) {
+        case TECHNORATI_DISPLAY_NONE:
+          // No inline display. Theme will handle it all.
+          break;
+        case TECHNORATI_DISPLAY_TEASER:
+          // Teaser view only
+	  if ($teaser) {
+            $node->content['technorati'] = $technorati;
+          }
+          break;
+        case TECHNORATI_DISPLAY_FULL:
+          // Full page view only
+	  if (!$teaser) {
+	    $node->content['technorati'] = $technorati;
+          }
+          break;
+        case TECHNORATI_DISPLAY_BOTH:
+          // Teaser and full page view 
+	  $node->content['technorati'] = $technorati;
+          break;
+      }
+      break;
+  }
+}
+
+function theme_technorati_tags($tags) {
+  $path = base_path() . drupal_get_path('module', 'technorati') . '/technobubble.gif';
+  $output = '<div class="technorati_tags">';
+  $output .= '<img src="' . $path . '"/>';
+  $output .= '<strong>' . t('Technorati Tags: ') . '</strong>';
+  $output .= implode(' ', $tags);
+  $output .= '</div>';
+  //$output .= '<script type="text/javascript" src="http://technorati.com/embed/CODE.js"></script>';
+  return $output; 
+}
+
+function _technorati_process_tags($node) {
+  $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
+  switch($mode) {
+    case TECHNORATI_MODE_MANUAL:
+      return _technorati_manual($node);
+
+    case TECHNORATI_MODE_TAXONOMY:
+      return _technorati_taxonomy($node);
+
+    case TECHNORATI_MODE_BOTH:
+      return array_merge(_technorati_taxonomy($node),  _technorati_manual($node));
+  }
+}
+
+function _technorati_manual($node) {
+  $links = array();
+  if (is_array($node->technorati_tags)) {
+    foreach($node->technorati_tags as $tag) {
+      $links[] = _technorati_link($tag);
+    }
+  }
+  return $links;
+}
+
+function _technorati_taxonomy($node) {
+  $links = array();
+  $terms = taxonomy_node_get_terms($node->nid);
+  foreach ($terms as $term) {
+    $links[] = _technorati_link($term->name);
+  }
+  return $links;
+}
+
+function _technorati_link($tag) {
+  // Patch by Ron D. Fredericks (RDF), April 22, 2007	
+  // http://www.embeddedcomponents.com/blogs/
+  // a) remove whitespace between tags;
+  // b) format the n words making up multi-word tags
+  //     with (n-1) "+" symbols.
+  $tag = check_plain($tag);
+  $tag = str_replace("+", " ", $tag);
+  $tag = _technorati_wsstrip($tag);
+  return '<a href="http://technorati.com/tag/' . 
+          str_replace(" ", "+", $tag) . 
+           '" rel="tag">' . $tag . '</a>';
+}
+
+function technorati_ping($name = '', $url = '') {
+  $result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
+  if ($result) {
+    watchdog("directory ping", t('Successfully notified technorati.com site.'), WATCHDOG_NOTICE);
+  }
+  else {
+    watchdog('directory ping', t('Failed to notify technorati.com site.'), WATCHDOG_WARNING);
+  }
+}
+
+function _technorati_wsstrip($str) {
+// Whitespace strip algorithm:
+//   a) Delete all whitespace from left and/or right of tags,
+//   b) Reduce multiple whitespace in between elements of tags 
+//      to a single whitespace.
+// Reference: 
+//   daggillies's comment on http://www.php.net/trim 
+  $str=ereg_replace (' +', ' ', trim($str));
+  return ereg_replace("[\r\t\n]","",$str);	
+}
