Index: inc/core/class.dc.trackback.php
===================================================================
--- inc/core/class.dc.trackback.php	(revision 1674)
+++ inc/core/class.dc.trackback.php	(revision 1684)
@@ -14,7 +14,7 @@
 /**
 @ingroup DC_CORE
-@brief Trackbacks sender and server
-
-Sends and receives trackbacks. Also handles trackbacks auto discovery.
+@brief Trackbacks/Pingbacks sender and server
+
+Sends and receives trackbacks/pingbacks. Also handles trackbacks/pingbacks auto discovery.
 */
 class dcTrackback
@@ -146,4 +146,34 @@
 	}
 	//@}
+	
+	private function addBacklink($post_id, $url, $blog_name, $title, $excerpt, &$comment)
+	{
+		if (empty($blog_name)) {
+			$blog_name = 'Anonymous blog';
+		}
+		
+		$comment =
+		"<!-- TB -->\n".
+		'<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n".
+		'<p>'.$excerpt.'</p>';
+		
+		$cur = $this->core->con->openCursor($this->core->prefix.'comment');
+		$cur->comment_author = (string) $blog_name;
+		$cur->comment_site = (string) $url;
+		$cur->comment_content = (string) $comment;
+		$cur->post_id = $post_id;
+		$cur->comment_trackback = 1;
+		$cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1;
+		$cur->comment_ip = http::realIP();
+		
+		# --BEHAVIOR-- publicBeforeTrackbackCreate
+		$this->core->callBehavior('publicBeforeTrackbackCreate',$cur);
+		if ($cur->post_id) {
+			$comment_id = $this->core->blog->addComment($cur);
+			
+			# --BEHAVIOR-- publicAfterTrackbackCreate
+			$this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id);
+		}
+	}
 	
 	/// @name Receive trackbacks
@@ -216,8 +246,5 @@
 			
 			if (!$charset) {
-				$charset = mb_detect_encoding($title.' '.$excerpt.' '.$blog_name,
-				'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'.
-				'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'.
-				'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15');
+				$charset = self::detectCharset($title.' '.$excerpt.' '.$blog_name);
 			}
 			
@@ -246,32 +273,7 @@
 			$url = trim(html::clean($url));
 			
-			if (!$blog_name) {
-				$blog_name = 'Anonymous blog';
-			}
-			
-			$comment =
-			"<!-- TB -->\n".
-			'<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n".
-			'<p>'.$excerpt.'</p>';
-			
-			$cur = $this->core->con->openCursor($this->core->prefix.'comment');
-			$cur->comment_author = (string) $blog_name;
-			$cur->comment_site = (string) $url;
-			$cur->comment_content = (string) $comment;
-			$cur->post_id = $post_id;
-			$cur->comment_trackback = 1;
-			$cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1;
-			$cur->comment_ip = http::realIP();
-			
 			try
 			{
-				# --BEHAVIOR-- publicBeforeTrackbackCreate
-				$this->core->callBehavior('publicBeforeTrackbackCreate',$cur);
-				if ($cur->post_id) {
-					$comment_id = $this->core->blog->addComment($cur);
-					
-					# --BEHAVIOR-- publicAfterTrackbackCreate
-					$this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id);
-				}
+				$this->addBacklink($post_id, $url, $blog_name, $title, $excerpt, $comment);
 			}
 			catch (Exception $e)
@@ -281,15 +283,4 @@
 			}
 		}
-		
-		
-		$debug_trace =
-		"  <debug>\n".
-		'    <title>'.$title."</title>\n".
-		'    <excerpt>'.$excerpt."</excerpt>\n".
-		'    <url>'.$url."</url>\n".
-		'    <blog_name>'.$blog_name."</blog_name>\n".
-		'    <charset>'.$charset."</charset>\n".
-		'    <comment>'.$comment."</comment>\n".
-		"  </debug>\n";
 		
 		$resp =
@@ -303,5 +294,13 @@
 		
 		if (!empty($_POST['__debug'])) {
-			$resp .= $debug_trace;
+			$resp .= 
+			"  <debug>\n".
+			'    <title>'.$title."</title>\n".
+			'    <excerpt>'.$excerpt."</excerpt>\n".
+			'    <url>'.$url."</url>\n".
+			'    <blog_name>'.$blog_name."</blog_name>\n".
+			'    <charset>'.$charset."</charset>\n".
+			'    <comment>'.$comment."</comment>\n".
+			"  </debug>\n";
 		}
 		
@@ -381,9 +380,10 @@
 			$remote_content = $http->getContent();
 
-			$charset = mb_detect_encoding($remote_content,
-				'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'.
-				'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'.
-				'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15');
-
+			$charset = self::getCharsetFromRequest($http->getHeader('content-type'));
+
+			if (!$charset) {
+				$charset = self::detectCharset($remote_content);
+			}
+			
 			if (strtolower($charset) != 'utf-8') {
 				$remote_content = iconv($charset,'UTF-8',$remote_content);
@@ -416,32 +416,11 @@
 			}
 			if ($excerpt) {
-				$excerpt = '(&#8230;) '.text::cutString(html::escapeHTML($excerpt),255).' (&#8230;)';
+				$excerpt = '(&#8230;) '.text::cutString(html::escapeHTML($excerpt),200).' (&#8230;)';
 			}
 			else {
-				$excerpt = '(??)';
-			}
-
-			$comment =
-			"<!-- TB -->\n".
-			'<p><strong>'.$title."</strong></p>\n".
-			'<p>'.$excerpt.'</p>';
-			
-			$cur = $this->core->con->openCursor($this->core->prefix.'comment');
-			$cur->comment_author = 'Anonymous blog';
-			$cur->comment_site = (string) $from_url;
-			$cur->comment_content = (string) $comment;
-			$cur->post_id = $posts->post_id;
-			$cur->comment_trackback = 1;
-			$cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1;
-			$cur->comment_ip = http::realIP();
-			
-			# --BEHAVIOR-- publicBeforeTrackbackCreate
-			$this->core->callBehavior('publicBeforeTrackbackCreate',$cur);
-			if ($cur->post_id) {
-				$comment_id = $this->core->blog->addComment($cur);
-				
-				# --BEHAVIOR-- publicAfterTrackbackCreate
-				$this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id);
-			}
+				$excerpt = '(&#8230;)';
+			}
+
+			$this->addBacklink($posts->post_id, $from_url, '', $title, $excerpt, $comment);
 		}
 		catch (Exception $e) {
@@ -464,9 +443,12 @@
 	}
 	
-	private static function getCharsetFromRequest()
-	{
-		if (isset($_SERVER['CONTENT_TYPE']))
-		{
-			if (preg_match('|charset=([a-zA-Z0-9-]+)|',$_SERVER['CONTENT_TYPE'],$m)) {
+	private static function getCharsetFromRequest($header = '')
+	{
+		if (!$header && isset($_SERVER['CONTENT_TYPE'])) {
+			$header = $_SERVER['CONTENT_TYPE'];
+		}
+		
+		if ($header) {
+			if (preg_match('|charset=([a-zA-Z0-9-]+)|',$header,$m)) {
 				return $m[1];
 			}
@@ -475,5 +457,13 @@
 		return null;
 	}
-	
+
+	private static function detectCharset($string)
+	{
+		return mb_detect_encoding($remote_content,
+				'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'.
+				'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'.
+				'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15');
+	}
+		
 	/// @name Trackbacks auto discovery
 	//@{
