Index: technorati.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/technorati/technorati.install,v
retrieving revision 1.1
diff -u -r1.1 technorati.install
--- technorati.install	28 Oct 2006 02:17:35 -0000	1.1
+++ technorati.install	30 Nov 2008 21:11:47 -0000
@@ -1,12 +1,21 @@
 <?php
 // $Id: technorati.install,v 1.1 2006/10/28 02:17:35 kbahey Exp $
 
-// Copyright 2006 http://2bits.com
+/**
+ * @file
+ * Installation and uninstallation code for the technorati module.
+ *
+ * Copyright (c) 2006 http://2bits.com
+ * Copyright (c) 2008 Jan Dittberner <jan@dittberner.info>
+ */
 
+/**
+ * Implementation of hook_install().
+ */
 function technorati_install() {
   switch ($GLOBALS['db_type']) {
     case 'mysqli':
-    case 'mysql':     
+    case 'mysql':
       $result = db_query("
         CREATE TABLE {technorati} (
           nid INT  NOT NULL default '0',
@@ -14,5 +23,40 @@
           PRIMARY KEY nid (nid)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       break;
+    case 'pgsql':
+      $result = db_query("
+        CREATE TABLE {technorati} (
+          nid INT NOT NULL DEFAULT 0 PRIMARY KEY,
+          tags TEXT NOT NULL DEFAULT ''
+        );");
+      break;
+    default:
+      drupal_set_message(t('unsupported database type'), 'error');
+      return;
+  }
+  drupal_set_message(t('technorati module installed.'));
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function technorati_uninstall() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+    case 'pgsql':
+      $result = db_query("DROP TABLE {technorati};");
+      break;
+    default:
+      drupal_set_message(t('unsupported database type'), 'error');
+      return;
+  }
+  // delete variables
+  variable_del('technorati_display_type');
+  variable_del('technorati_unify_tags');
+  variable_del('technorati_sort_tags');
+  variable_del('technorati_hide_notags');
+  foreach (node_get_types() as $node_type => $node_name) {
+    variable_del('technorati_node_type_'. $node_type);
   }
 }
Index: technorati.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/technorati/technorati.module,v
retrieving revision 1.6.2.3
diff -u -r1.6.2.3 technorati.module
--- technorati.module	1 May 2007 19:55:38 -0000	1.6.2.3
+++ technorati.module	30 Nov 2008 21:11:48 -0000
@@ -1,7 +1,17 @@
 <?php
 // $Id: technorati.module,v 1.6.2.3 2007/05/01 19:55:38 kbahey Exp $
 
-// Copyright 2006 http://2bits.com
+/*
+ * @file
+ * Technorati module for Drupal 5.x.
+ *
+ * This module enables Technorati (http://technorati.com) tags for Drupal
+ * node. Tags can be stored in a separate database table or can be taken from
+ * the taxonomy tags.
+ *
+ * Copyright (c) 2006 http://2bits.com
+ * Copyright (c) 2008 Jan Dittberner <jan@dittberner.info>
+ */
 
 define('TECHNORATI_NODE_TYPE',       'technorati_node_type_');
 
@@ -17,6 +27,13 @@
 define('TECHNORATI_DISPLAY_FULL',    2);
 define('TECHNORATI_DISPLAY_BOTH',    3);
 
+define('TECHNORATI_UNIFY_TAGS',      'technorati_unify_tags');
+define('TECHNORATI_SORT_TAGS',       'technorati_sort_tags');
+define('TECHNORATI_HIDE_NOTAGS',     'technorati_hide_notags');
+
+/**
+ * Implementation of hook_help().
+ */
 function technorati_help($section) {
   switch ($section) {
     case 'admin/modules#description':
@@ -24,22 +41,27 @@
   }
 }
 
+/**
+ * Implementation of hook_menu().
+ */
 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
-    );
+  $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;
 }
 
-
+/**
+ * Form definition for technorati module settings.
+ */
 function technorati_admin_settings() {
   if (!module_exists('ping')) {
     drupal_set_message(t('This module requires that the %pingmodule be enabled',
@@ -61,7 +83,12 @@
     TECHNORATI_MODE_BOTH     => t('Both'),
   );
 
-  $form[TECHNORATI_DISPLAY_TYPE] = array(
+  $form['display'] = array(
+    '#type'          => 'fieldset',
+    '#title'         => t('Technorati tag display settings'),
+  );
+
+  $form['display'][TECHNORATI_DISPLAY_TYPE] = array(
     '#type'          => 'select',
     '#title'         => t('How to display the technorati tags'),
     '#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),
@@ -69,6 +96,27 @@
     '#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['display'][TECHNORATI_UNIFY_TAGS] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Unify technorati tags'),
+    '#default_value' => variable_get(TECHNORATI_UNIFY_TAGS, 0),
+    '#description'   => t('Use this option if you want to have only one occurrence of each choosen tag.'),
+  );
+
+  $form['display'][TECHNORATI_SORT_TAGS] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Sort technorati tags'),
+    '#default_value' => variable_get(TECHNORATI_SORT_TAGS, 0),
+    '#description'   => t('Sort the tags when displaying Technorati links.'),
+  );
+
+  $form['display'][TECHNORATI_HIDE_NOTAGS] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Hide technorati display if empty'),
+    '#default_value' => variable_get(TECHNORATI_HIDE_NOTAGS, 0),
+    '#description'   => t('Hide the display of the Technorati icon and the Technorati Tags label, if there are no tags assigned to a node.'),
+  );
+
   $form['types'] = array(
     '#type' => 'fieldset',
     '#title' => t('Content types'),
@@ -76,7 +124,7 @@
     '#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) {
+  foreach (node_get_types() as $node_type => $node_name) {
     $type = TECHNORATI_NODE_TYPE . $node_type;
     $form['types'][$type] = array(
       '#type'          => 'select',
@@ -86,9 +134,12 @@
     );
   }
 
- return system_settings_form($form);
+  return system_settings_form($form);
 }
 
+/**
+ * Implementation of hook_form_alter().
+ */
 function technorati_form_alter($form_id, &$form) {
   if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {
     // Get the node type we are processing
@@ -96,7 +147,7 @@
 
     // Check what the technorati mode for that node type
     $mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);
-    switch($mode) {
+    switch ($mode) {
       case TECHNORATI_MODE_NONE:
       case TECHNORATI_MODE_TAXONOMY:
         // No need to do anything in the node form
@@ -133,9 +184,12 @@
   }
 }
 
-function technorati_nodeapi(&$node, $op, $teaser, $page) {
+/**
+ * Implementation of hook_nodeapi().
+ */
+function technorati_nodeapi(&$node, $op, $a3, $a4) {
   $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
-  switch($mode) {
+  switch ($mode) {
     case TECHNORATI_MODE_NONE:
     case TECHNORATI_MODE_TAXONOMY:
       // No need to do anything in the node form
@@ -167,71 +221,104 @@
       break;
 
     case 'view':
-      $technorati = array (
+      $technorati = array(
         '#value' => theme('technorati_tags', _technorati_process_tags($node)),
         '#weight' => 10,
-        );
+      );
       $mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);
-      switch($mode) {
+      switch ($mode) {
         case TECHNORATI_DISPLAY_NONE:
           // No inline display. Theme will handle it all.
           break;
         case TECHNORATI_DISPLAY_TEASER:
           // Teaser view only
-	  if ($teaser) {
+          if ($a3) {
             $node->content['technorati'] = $technorati;
           }
           break;
         case TECHNORATI_DISPLAY_FULL:
           // Full page view only
-	  if (!$teaser) {
-	    $node->content['technorati'] = $technorati;
+          if (!$a3) {
+            $node->content['technorati'] = $technorati;
           }
           break;
         case TECHNORATI_DISPLAY_BOTH:
-          // Teaser and full page view 
-	  $node->content['technorati'] = $technorati;
+          // Teaser and full page view
+          $node->content['technorati'] = $technorati;
           break;
       }
       break;
   }
 }
 
+/**
+ * Theme function for registered theme 'technorati_tags'.
+ */
 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>';
+  if (empty($tags) && variable_get(TECHNORATI_HIDE_NOTAGS, 0)) {
+    return '';
+  }
+  $path = base_path() . drupal_get_path('module', 'technorati') .'/technobubble.gif';
+
+  $output  = '<div class="technorati_tags">';
+  $output .= '<img alt="'. t('Technorati Tags:') .'" 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; 
+  return $output;
 }
 
+/**
+ * This function is called by technorati_nodeapi() with $op 'view' and
+ * processes the tags in a node type and technorati mode specific way.
+ */
 function _technorati_process_tags($node) {
   $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
-  switch($mode) {
+  switch ($mode) {
     case TECHNORATI_MODE_MANUAL:
-      return _technorati_manual($node);
-
+      $tags = _technorati_manual($node);
+      break;
     case TECHNORATI_MODE_TAXONOMY:
-      return _technorati_taxonomy($node);
-
+      $tags = _technorati_taxonomy($node);
+      break;
     case TECHNORATI_MODE_BOTH:
-      return array_merge(_technorati_taxonomy($node),  _technorati_manual($node));
+      $tags = array_merge(_technorati_taxonomy($node),  _technorati_manual($node));
+      break;
+    default:
+      return;
   }
+  if (variable_get(TECHNORATI_UNIFY_TAGS, 0)) {
+    $tags = array_unique($tags);
+  }
+  if (variable_get(TECHNORATI_SORT_TAGS, 0)) {
+    natcasesort($tags);
+  }
+  return $tags;
 }
 
+/**
+ * This function handles the manually assigned technorati tags of a node. It
+ * is called by _technorati_process_tags() for the technorati modes 'manual'
+ * and 'both'.
+ */
 function _technorati_manual($node) {
   $links = array();
   if (is_array($node->technorati_tags)) {
-    foreach($node->technorati_tags as $tag) {
-      $links[] = _technorati_link($tag);
+    foreach ($node->technorati_tags as $tag) {
+      if (!empty($tag)) {
+        $links[] = _technorati_link($tag);
+      }
     }
   }
   return $links;
 }
 
+/**
+ * This function handles the taxonomy tags of a node and creates technorati
+ * links from them. It is called by _technorati_process_tags() for the
+ * technorati modes 'taxonomy' and 'both'.
+ */
 function _technorati_taxonomy($node) {
   $links = array();
   $terms = taxonomy_node_get_terms($node->nid);
@@ -241,6 +328,10 @@
   return $links;
 }
 
+/**
+ * Calls the Technorati ping service at http://rpc.technorati.com/rpc/ping and
+ * notifies changes to the given URL.
+ */
 function technorati_ping($name = '', $url = '') {
   $result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
   if ($result) {
@@ -268,7 +359,7 @@
 
 /**
  * Strip whitespace from left and/or right of tags, and reduce multiples
- * to just one
+ * to just one.
  *
  * Reference: daggillies's comment on http://www.php.net/trim
  */
