Index: inc/core/class.dc.trackback.php
===================================================================
--- inc/core/class.dc.trackback.php	(revision 1689)
+++ inc/core/class.dc.trackback.php	(revision 2566)
@@ -22,8 +22,8 @@
 	public $core;		///< <b>dcCore</b> dcCore instance
 	public $table;		///< <b>string</b> done pings table name
-	
+
 	/**
 	Object constructor
-	
+
 	@param	core		<b>dcCore</b>		dcCore instance
 	*/
@@ -34,10 +34,10 @@
 		$this->table = $this->core->prefix.'ping';
 	}
-	
+
 	/// @name Send trackbacks
 	//@{
 	/**
 	Get all pings sent for a given post.
-	
+
 	@param	post_id	<b>integer</b>		Post ID
 	@return	<b>record</b>
@@ -48,11 +48,11 @@
 				'FROM '.$this->table.' '.
 				'WHERE post_id = '.(integer) $post_id;
-		
+
 		return $this->con->select($strReq);
 	}
-	
+
 	/**
 	Sends a ping to given <var>$url</var>.
-	
+
 	@param	url			<b>string</b>		URL to ping
 	@param	post_id		<b>integer</b>		Post ID
@@ -66,20 +66,20 @@
 			return false;
 		}
-		
+
 		$post_id = (integer) $post_id;
-		
+
 		# Check for previously done trackback
 		$strReq = 'SELECT post_id, ping_url FROM '.$this->table.' '.
 				'WHERE post_id = '.$post_id.' '.
 				"AND ping_url = '".$this->con->escape($url)."' ";
-		
+
 		$rs = $this->con->select($strReq);
-		
+
 		if (!$rs->isEmpty()) {
 			throw new Exception(sprintf(__('%s has still been pinged'),$url));
 		}
-		
+
 		$ping_parts = explode('|',$url);
-		
+
 		# Let's walk by the trackback way
 		if (count($ping_parts) < 2) {
@@ -91,5 +91,5 @@
 				//,'__debug' => false
 			);
-			
+
 			# Ping
 			try
@@ -103,15 +103,15 @@
 				throw new Exception(__('Unable to ping URL'));
 			}
-			
+
 			$pattern =
 			'|<response>.*<error>(.*)</error>(.*)'.
 			'(<message>(.*)</message>(.*))?'.
 			'</response>|msU';
-			
+
 			if (!preg_match($pattern,$res,$match))
 			{
 				throw new Exception(sprintf(__('%s is not a ping URL'),$url));
 			}
-			
+
 			$ping_error = trim($match[1]);
 			$ping_msg = (!empty($match[4])) ? $match[4] : '';
@@ -126,5 +126,5 @@
 			catch (xmlrpcException $e) {
 				$ping_error = $e->getCode();
-				$ping_msg = $e->getMessage();	
+				$ping_msg = $e->getMessage();
 			}
 			catch (Exception $e) {
@@ -132,5 +132,5 @@
 			}
 		}
-		
+
 		if ($ping_error != '0') {
 			throw new Exception(sprintf(__('%s, ping error:'),$url).' '.$ping_msg);
@@ -141,10 +141,10 @@
 			$cur->ping_url = $url;
 			$cur->ping_dt = date('Y-m-d H:i:s');
-			
+
 			$cur->insert();
 		}
 	}
 	//@}
-	
+
 	private function pingAlreadyDone($post_id, $from_url)
 	{
@@ -154,13 +154,13 @@
 			'comment_trackback' => 1,
 		);
-		
+
 		$rs = $this->core->blog->getComments($params, true);
 		if ($rs && !$rs->isEmpty()) {
 			return ($rs->f(0));
 		}
-		
+
 		return false;
 	}
-	
+
 	private function addBacklink($post_id, $url, $blog_name, $title, $excerpt, &$comment)
 	{
@@ -168,10 +168,10 @@
 			$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;
@@ -182,20 +182,20 @@
 		$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
 	//@{
 	/**
 	Receives a trackback and insert it as a comment of given post.
-	
+
 	@param	post_id		<b>integer</b>		Post ID
 	*/
@@ -213,7 +213,7 @@
 			return;
 		}
-		
+
 		$post_id = (integer) $post_id;
-		
+
 		$title = !empty($_POST['title']) ? $_POST['title'] : '';
 		$excerpt = !empty($_POST['excerpt']) ? $_POST['excerpt'] : '';
@@ -222,8 +222,8 @@
 		$charset = '';
 		$comment = '';
-				
+
 		$err = false;
 		$msg = '';
-		
+
 		if ($this->core->blog === null)
 		{
@@ -240,9 +240,9 @@
 			$msg = 'Blog name is required.';
 		}
-		
+
 		if (!$err)
 		{
 			$post = $this->core->blog->getPosts(array('post_id'=>$post_id,'post_type'=>''));
-			
+
 			if ($post->isEmpty())
 			{
@@ -262,13 +262,13 @@
 			}
 		}
-		
+
 		if (!$err)
 		{
 			$charset = self::getCharsetFromRequest();
-			
+
 			if (!$charset) {
 				$charset = self::detectCharset($title.' '.$excerpt.' '.$blog_name);
 			}
-			
+
 			if (strtolower($charset) != 'utf-8') {
 				$title = iconv($charset,'UTF-8',$title);
@@ -276,21 +276,21 @@
 				$blog_name = iconv($charset,'UTF-8',$blog_name);
 			}
-			
+
 			$title = trim(html::clean($title));
 			$title = html::decodeEntities($title);
 			$title = html::escapeHTML($title);
 			$title = text::cutString($title,60);
-			
+
 			$excerpt = trim(html::clean($excerpt));
 			$excerpt = html::decodeEntities($excerpt);
 			$excerpt = preg_replace('/\s+/ms',' ',$excerpt);
-			$excerpt = text::cutString($excerpt,252); 
+			$excerpt = text::cutString($excerpt,252);
 			$excerpt = html::escapeHTML($excerpt).'...';
-			
+
 			$blog_name = trim(html::clean($blog_name));
 			$blog_name = html::decodeEntities($blog_name);
 			$blog_name = html::escapeHTML($blog_name);
 			$blog_name = text::cutString($blog_name,60);
-			
+
 			try
 			{
@@ -303,16 +303,16 @@
 			}
 		}
-		
+
 		$resp =
 		'<?xml version="1.0" encoding="utf-8"?>'."\n".
 		"<response>\n".
 		'  <error>'.(integer) $err."</error>\n";
-		
+
 		if ($msg) {
 			$resp .= '  <message>'.$msg."</message>\n";
 		}
-		
+
 		if (!empty($_POST['__debug'])) {
-			$resp .= 
+			$resp .=
 			"  <debug>\n".
 			'    <title>'.$title."</title>\n".
@@ -324,5 +324,5 @@
 			"  </debug>\n";
 		}
-		
+
 		echo	$resp."</response>";
 	}
@@ -333,5 +333,5 @@
 	/**
 	Receives a pingback and insert it as a comment of given post.
-	
+
 	@param	from_url		<b>string</b>		Source URL
 	@param	to_url			<b>string</b>		Target URL
@@ -341,11 +341,11 @@
 		$reg = '!^'.preg_quote($this->core->blog->url).'(.*)!';
 		$type = $args = $next = '';
-		
+
 		# Are you dumb?
 		if (!preg_match($reg, $to_url, $m)) {
 			throw new Exception(__('Any chance you ping one of my contents? No? Really?'), 0);
 		}
-		
-		# Does the targeted URL look like a registered post type? 
+
+		# Does the targeted URL look like a registered post type?
 		$url_part = $m[1];
 		$p_type = '';
@@ -359,5 +359,5 @@
 			}
 		}
-		
+
 		if (empty($p_type)) {
 			throw new Exception(__('Sorry but you can not ping this type of content.'), 33);
@@ -370,10 +370,10 @@
 		);
 		$posts = $this->core->blog->getPosts($params);
-		
-		# Missed! 
+
+		# Missed!
 		if ($posts->isEmpty()) {
 			throw new Exception(__('Oops. Kinda "not found" stuff. Please check the target URL twice.'), 33);
 		}
-		
+
 		# Nice try. But, sorry, no.
 		if (!$posts->trackbacksActive()) {
@@ -384,9 +384,9 @@
 			throw new Exception(__('Don\'t repeat yourself, please.'), 48);
 		}
-		
+
 		# OK. We've found our champion. Time to check the remote part.
 		try {
 			$http = self::initHttp($from_url, $from_path);
-			
+
 			# First round : just to be sure the ping comes from an acceptable resource type.
 			$http->setHeadersOnly(true);
@@ -398,5 +398,5 @@
 				throw new Exception(__('Your source URL does not look like a supported content type. Sorry. Bye, bye!'), 0);
 			}
-			
+
 			# Second round : let's go fetch and parse the remote content
 			$http->setHeadersOnly(false);
@@ -409,9 +409,9 @@
 				$charset = self::detectCharset($remote_content);
 			}
-			
+
 			if (strtolower($charset) != 'utf-8') {
 				$remote_content = iconv($charset,'UTF-8',$remote_content);
 			}
-			
+
 			# We want a title...
 			if (!preg_match('!<title>([^<].*?)</title>!mis', $remote_content, $m)) {
@@ -422,5 +422,5 @@
 			$title = html::escapeHTML($title);
 			$title = text::cutString($title,60);
-			
+
 			preg_match('!<body[^>]*?>(.*)?</body>!msi', $remote_content, $m);
 			$source = $m[1];
@@ -429,5 +429,5 @@
 			$source = strip_tags($source, '<a>');
 			$source = explode("\n\n",$source);
-			
+
 			$excerpt = '';
 			foreach ($source as $line) {
@@ -451,9 +451,9 @@
 			throw new Exception(__('Sorry, an internal problem has occured.'), 0);
 		}
-		
+
 		return __('Thanks, mate. It was a pleasure.');
 	}
 	//@}
-	
+
 	private static function initHttp($url,&$path)
 	{
@@ -463,8 +463,8 @@
 		$client->useGzip(false);
 		$client->setPersistReferers(false);
-		
+
 		return $client;
 	}
-	
+
 	private static function getCharsetFromRequest($header = '')
 	{
@@ -472,5 +472,5 @@
 			$header = $_SERVER['CONTENT_TYPE'];
 		}
-		
+
 		if ($header) {
 			if (preg_match('|charset=([a-zA-Z0-9-]+)|',$header,$m)) {
@@ -478,5 +478,5 @@
 			}
 		}
-		
+
 		return null;
 	}
@@ -489,5 +489,5 @@
 				'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15');
 	}
-		
+
 	/// @name Trackbacks auto discovery
 	//@{
@@ -495,5 +495,5 @@
 	Returns an array containing all discovered trackbacks URLs in
 	<var>$text</var>.
-	
+
 	@param	text		<b>string</b>		Input text
 	@return	<b>array</b>
@@ -502,5 +502,5 @@
 	{
 		$res = array();
-		
+
 		foreach ($this->getTextLinks($text) as $link)
 		{
@@ -509,13 +509,13 @@
 			}
 		}
-		
+
 		return $res;
 	}
 	//@}
-	
+
 	private function getTextLinks($text)
 	{
 		$res = array();
-		
+
 		# href attribute on "a" tags
 		if (preg_match_all('/<a ([^>]+)>/ms', $text, $match, PREG_SET_ORDER))
@@ -529,5 +529,5 @@
 		}
 		unset($match);
-		
+
 		# cite attributes on "blockquote" and "q" tags
 		if (preg_match_all('/<(blockquote|q) ([^>]+)>/ms', $text, $match, PREG_SET_ORDER))
@@ -540,8 +540,8 @@
 			}
 		}
-		
+
 		return array_keys($res);
 	}
-	
+
 	private function getPingURL($url)
 	{
@@ -549,5 +549,5 @@
 			$url = http::getHost().$url;
 		}
-		
+
 		try
 		{
@@ -561,13 +561,13 @@
 			return false;
 		}
-		
+
 		# If we've got a X-Pingback header and it's a valid URL, it will be enough
 		if ($pb_url && filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) {
 			return $pb_url.'|'.$url;
 		}
-		
+
 		# No X-Pingback header. A link rel=pingback, maybe ?
 		$pattern_pingback = '!<link rel="pingback" href="(.*?)"( /)?>!msi';
-		
+
 		if (preg_match($pattern_pingback,$page_content,$m)) {
 			$pb_url = $m[1];
@@ -583,10 +583,10 @@
 		'.*?<\/rdf:RDF>'.
 		'/msi';
-		
+
 		preg_match_all($pattern_rdf,$page_content,$rdf_all,PREG_SET_ORDER);
-		
+
 		$url_path = parse_url($url, PHP_URL_PATH);
 		$sanitized_url = str_replace($url_path, html::sanitizeURL($url_path), $url);
-		
+
 		for ($i=0; $i<count($rdf_all); $i++)
 		{
@@ -599,7 +599,6 @@
 			}
 		}
-		
+
 		return null;
 	}
 }
-?>
