Index: phpbbforum.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phpbbforum/phpbbforum.module,v
retrieving revision 1.24
diff -u -r1.24 phpbbforum.module
--- phpbbforum.module	16 May 2008 16:52:58 -0000	1.24
+++ phpbbforum.module	15 Jun 2008 00:02:32 -0000
@@ -1715,14 +1715,34 @@
             $sync_data = false;
         else
           $val = $account->signature;
+          
+        $aVal = _phpbbforum_convert_sig ($val, '', 'phpbb');
+        
+        if ($aVal !== false && $sync === PHPBB_SYNC_TO_PHPBB && isset ($aVal['user_sig']))            
+          $val = $aVal['user_sig'];
+
         $valphpbb = $phpbb_user->data['user_sig'];
+        $valphpbb_converted = _phpbbforum_convert_sig ($valphpbb, $phpbb_user->data['user_sig_bbcode_uid'], 'drupal');
+        
+        if ($valphpbb_converted !== false)
+          $valphpbb = $valphpbb_converted;
+        
         if ($sync_data && $val != $valphpbb) {
-          if ($sync == PHPBB_SYNC_TO_PHPBB)
-            $data += array('user_sig' => $val);
-          else
+
+          if ($sync == PHPBB_SYNC_TO_PHPBB) {
+            
+            if (is_array ($aVal) && isset ($aVal['user_sig']))
+               $data += $aVal;
+             else
+               $data += array('user_sig' => $val);
+
+          } else
             $data += array('signature' => $valphpbb);
+            
         }
+
       }
+      
     }
     // avatars
     if (variable_get('user_pictures', 0) && variable_get('phpbbforum_sync_avatar', 1)) {
@@ -2450,6 +2470,50 @@
 
 }
 
+
+function _phpbbforum_convert_sig ($sSignature, $uid = '', $mode = 'phpbb') {
+  
+  global $phpbb_root_path;
+  global $phpEx;
+  
+  if (empty ($phpEx))
+    $phpEx = 'php';
+
+  include_once($phpbb_root_path . 'includes/message_parser.php');
+
+  $message_parser = new parse_message($sSignature);
+
+  switch ($mode) {
+    case 'phpbb':
+      // Allowing Quote BBCode
+    	$message_parser->parse(true, true, true);
+    
+    	if (sizeof($message_parser->warn_msg)) {
+    	  $sWarning = implode('<br />', t($message_parser->warn_msg)); 
+    		$error[] = $sWarning;
+    	  drupal_set_message ($sWarning);
+    	}
+    	
+    	if (!sizeof($error)) {
+        $aSigInfos = array(
+        	'user_sig'					=> (string) $message_parser->message,
+        	'user_sig_bbcode_uid'		=> (string) $message_parser->bbcode_uid,
+        	'user_sig_bbcode_bitfield'	=> $message_parser->bbcode_bitfield
+        );
+        
+       return $aSigInfos;
+    	}
+    	return false;
+    case 'drupal':
+      decode_message($sSignature, $uid);
+      $sSignature = str_replace(array('&#58;', '&#46;'), array(':', '.'), $sSignature);
+      return $sSignature;
+      break;
+      
+  }
+
+}
+
 if (PHPBB_DRUPAL_MODULE_VERSION == 5) {
   function phpbbforum_auth($login, $passwd, $server = FALSE) {
     if (empty($passwd))
