? signature.install
Index: signature.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signature/signature.info,v
retrieving revision 1.1
diff -u -p -r1.1 signature.info
--- signature.info	10 Mar 2007 17:44:43 -0000	1.1
+++ signature.info	30 Oct 2007 10:44:25 -0000
@@ -1,3 +1,8 @@
 ; $Id: signature.info,v 1.1 2007/03/10 17:44:43 zertox Exp $
 name = Signature
 description = Manages users signatures.
+
+; Information added by drupal.org packaging script on 2007-03-11
+version = "5.x-1.x-dev"
+project = "signature"
+
Index: signature.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signature/signature.module,v
retrieving revision 1.1
diff -u -p -r1.1 signature.module
--- signature.module	10 Mar 2007 17:44:43 -0000	1.1
+++ signature.module	30 Oct 2007 10:44:25 -0000
@@ -1,134 +1,175 @@
-<?php
-// signature.module v1.1 for Drupal 5.0; author - ultraBoy@drupal.org;
-
-function signature_help($section='') {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t('Manages users\' signatures.');
-  };
-}
-
-
-function signature_perm() {
-  return array('administer signature');
-}
-
-function signature_menu($may_cache) {
-	$items = array();
-	$items[] = array(
-    'path' => 'admin/settings/signature',
-    'title' => t('signature'),
-    'description' => t('Manages users\' signatures.'),
-    'callback' => 'drupal_get_form',
-    'callback arguments' => array('signature_admin_settings'),
-    'access' => user_access('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM, // optional
-   );
-	return $items;
-}
-function signature_admin_settings() {
-  $form['signature'] = array(
-    '#type' => 'fieldset',
-    '#description' => t('Show signatures with nodes and comments for: '),
-  );
-
-  foreach(node_get_types('names') as $type => $name) {
-    $form['signature']['signature_show_for_'.$type] = array(
-      '#type' => 'checkbox',
-      '#title' => $name,
-      '#return_value' => 1,
-      '#default_value' => variable_get('signature_show_for_'.$type, '0'),
-    );
-  }
-
-  $form['signature']['signature_template'] = array (
-    '#type' => 'textarea',
-    '#title' => 'Template for signatures:',
-    '#default_value' => variable_get('signature_template', "__________________________\n<br />%s"),
-    '#description' => '<strong>%s</strong> will be replaced with user\'s actual signature. Please note, all html tags will be filtered out.',
-  );
-
-   return system_settings_form($form);
-}
-
-function signature_form_alter($form_id, &$form) {
-//if signatures are disabled for all content types, hiding signature field in user profile settings 
-  if ($form_id == 'user_edit') {
-    $enabled = false;
-    foreach(node_get_types('names') as $type => $name) {
-      if (variable_get('signature_show_for_'.$type, '0')) {
-        $enabled = true;
-        break;
-      }
-    }
-    if (!$enabled) {
-      unset($form['comment_settings']);
-    }
-  }
-
-//cleaning signature in comment/reply
-  if ($form_id == 'comment_form') {
-    global $user;
-    if ($form['comment_filter']['comment']['#default_value'] == $user->signature ) {
-      $form['comment_filter']['comment']['#default_value'] = '';      
-  	}
-  }
-}
-
-
-function signature_nodeapi(&$node, $op, $teaser, $page) {
-  if (variable_get('signature_show_for_'.$node->type, '0')) {
-    switch ($op) {
-	
-      case 'load':
-        global $signature_node_type;
-        $signature_node_type = $node->type;
-        
-		$node->signature = db_result(db_query('SELECT signature FROM {users} WHERE uid = %d', $node->uid));
-        $node->body = $node->body . theme('signature', $node->signature);
-	      break;
-
-//	    case 'view':
-//	      $node->body = $node->body . theme('signature', $node->signature);
-//	      break;
-
-      case 'prepare':
-        $themed_signature = theme('signature', $node->signature);
-        if (substr($node->body, - strlen($themed_signature)) == $themed_signature) {
-          $node->body = substr($node->body, 0, strlen($node->body) - strlen($themed_signature));
-        }
-        break;
-	  }
-  }
-}
-
-
-function signature_comment(&$comment, $op) {
-//  $node_type = db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $comment->nid));
-  global $signature_node_type;
-  
-  if ($op == 'view' && variable_get('signature_show_for_'.$signature_node_type, '0')) {
-    static $cache;
-    if (!isset($cache)) {
-      $result = db_query('SELECT u.uid, u.signature FROM {comments} c
-                            INNER JOIN {users} u ON c.uid = u.uid
-                            WHERE c.nid = %d AND c.status = 0 AND NOT(u.signature = "")
-                            GROUP BY u.uid', $comment->nid);
-      $cache = array();
-      while($row = db_fetch_object($result)) {
-        $cache[$row->uid] = $row->signature;
-      }
-    }
-    
-    if (isset($cache[$comment->uid])) {
-      $comment->comment .= theme('signature', $cache[$comment->uid]);
-    }
-  }
-}
-
-
-function theme_signature($signature) {
-  return sprintf("\n" . variable_get('signature_template', "__________________________\n<br />%s"), check_markup($signature));
-}
-
-?>
\ No newline at end of file
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_help()
+ */
+function signature_help($section='') {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Manages users\' signatures.');
+  };
+}
+
+/**
+ * Implementation of hook_perm()
+ */
+function signature_perm() {
+  return array('administer signature');
+}
+
+/**
+ * Implementation of hook_menu()
+ */
+function signature_menu($may_cache) {
+	$items = array();
+	$items[] = array(
+    'path' => 'admin/settings/signature',
+    'title' => t('Signature'),
+    'description' => t('Manages users\' signatures.'),
+    'callback' => 'drupal_get_form',
+    'callback arguments' => array('signature_admin_settings'),
+    'access' => user_access('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM, // optional
+   );
+	return $items;
+}
+
+/**
+ * Admin settings form
+ */
+function signature_admin_settings() {
+  $form['signature'] = array(
+    '#type' => 'fieldset',
+    '#description' => t('Show signatures with nodes and comments for: '),
+  );
+
+  foreach(node_get_types('names') as $type => $name) {
+    $form['signature']['signature_show_for_'.$type] = array(
+      '#type' => 'checkbox',
+      '#title' => $name,
+      '#return_value' => 1,
+      '#default_value' => variable_get('signature_show_for_'.$type, '0'),
+    );
+  }
+
+  $form['signature']['signature_template'] = array (
+    '#type' => 'textarea',
+    '#title' => 'Template for signatures:',
+    '#default_value' => variable_get('signature_template', "__________________________\n<p>%s</p>"),
+    '#description' => '<strong>%s</strong> will be replaced with user\'s actual signature.',
+  );
+
+  $form['signature']['filter'] = filter_form(variable_get('signature_format', FILTER_FORMAT_DEFAULT));
+
+  return system_settings_form($form);
+}
+
+/**
+ * Admin settings form submit
+ */
+function signature_admin_settings_submit($form_id, $form_values) {
+  foreach($form_values as $form_value_key => $form_value_value) {
+    if (substr($form_value_key, 0, strlen('signature_show_for_')) == 'signature_show_for_') {
+      variable_set($form_value_key, $form_value_value);
+    }
+  }
+  variable_set('signature_template', $form_values['signature_template']);
+  variable_set('signature_format', $form_values['format']);
+}
+
+/**
+ * Implementation of hook_form_alter()
+ */
+function signature_form_alter($form_id, &$form) {
+  // if signatures are disabled for all content types, hide signature field in user profile settings 
+  if ($form_id == 'user_edit') {
+    $enabled = false;
+    foreach(node_get_types('names') as $type => $name) {
+      if (variable_get('signature_show_for_'. $type, '0')) {
+        $enabled = true;
+        break;
+      }
+    }
+    if (!$enabled) {
+      unset($form['comment_settings']);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_user()
+ */
+function signature_user($op, &$edit, &$account, $category = NULL) {
+  if ($op == 'submit' && $category == 'account') {
+    // Re-route the user signature to this modules signature table
+    db_query('UPDATE {users_signature} SET signature=\'%s\' WHERE uid=%d', array($edit['signature'], $account->uid));
+    unset($edit['signature']);
+  }
+  else if ($op == 'load') {
+    static $signature;
+    // We keep this in memory because load is called several times
+    if (!isset($signature)) {
+      $signature = db_result(db_query('SELECT signature FROM {users_signature} WHERE uid=%d', $account->uid));
+    }
+    $account->signature = $signature;
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi()
+ */
+function signature_nodeapi(&$node, $op, $teaser, $page) {
+  if (variable_get('signature_show_for_'.$node->type, '0')) {
+		$node->signature = db_result(db_query('SELECT signature FROM {users_signature} WHERE uid = %d', $node->uid));
+    switch ($op) {
+	    case 'view':
+        // Add signature to node body text
+	      $node->content['body']['#value'] = $node->content['body']['#value'] . theme('signature', $node->signature);
+	      break;
+	  }
+  }
+}
+
+/**
+ * Implementation of hook_comment()
+ */
+function signature_comment(&$comment, $op) {
+  static $node_type;
+
+  if (!isset($node_type)) {
+    $node_type = db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $comment->nid));
+  }
+  
+  if ($op == 'view' && variable_get('signature_show_for_'. $node_type, '0')) {
+    static $cache;
+    if (!isset($cache)) {
+      $result = db_query('SELECT u.uid, u.signature FROM {comments} c
+                            INNER JOIN {users_signature} u ON c.uid = u.uid
+                            WHERE c.nid = %d AND c.status = 0 AND NOT(u.signature = "")
+                            GROUP BY u.uid', $comment->nid);
+      $cache = array();
+      while($row = db_fetch_object($result)) {
+        $cache[$row->uid] = $row->signature;
+      }
+    }
+    
+    if (isset($cache[$comment->uid])) {
+      $comment->comment .= theme('signature', $cache[$comment->uid]);
+    }
+  }
+}
+
+/**
+ * Format user signature
+ *
+ * @ingroup themeable
+ */
+function theme_signature($signature) {
+  $format = variable_get('signature_format', FILTER_FORMAT_DEFAULT);
+  $template = variable_get('signature_template', "__________________________\n<p>%s</p>");
+  $sig_temp = check_markup($signature, $format);
+  $sig_temp = trim(sprintf("\n". $template, $sig_temp));
+
+  return '<div class="signature">'. $sig_temp .'</div>';
+}
