- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.trackback.php
r1674 r1689 14 14 /** 15 15 @ingroup DC_CORE 16 @brief Trackbacks sender and server17 18 Sends and receives trackbacks . Also handles trackbacks auto discovery.16 @brief Trackbacks/Pingbacks sender and server 17 18 Sends and receives trackbacks/pingbacks. Also handles trackbacks/pingbacks auto discovery. 19 19 */ 20 20 class dcTrackback … … 146 146 } 147 147 //@} 148 149 private function pingAlreadyDone($post_id, $from_url) 150 { 151 $params = array( 152 'post_id' => $post_id, 153 'comment_site' => $from_url, 154 'comment_trackback' => 1, 155 ); 156 157 $rs = $this->core->blog->getComments($params, true); 158 if ($rs && !$rs->isEmpty()) { 159 return ($rs->f(0)); 160 } 161 162 return false; 163 } 164 165 private function addBacklink($post_id, $url, $blog_name, $title, $excerpt, &$comment) 166 { 167 if (empty($blog_name)) { 168 $blog_name = 'Anonymous blog'; 169 } 170 171 $comment = 172 "<!-- TB -->\n". 173 '<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n". 174 '<p>'.$excerpt.'</p>'; 175 176 $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 177 $cur->comment_author = (string) $blog_name; 178 $cur->comment_site = (string) $url; 179 $cur->comment_content = (string) $comment; 180 $cur->post_id = $post_id; 181 $cur->comment_trackback = 1; 182 $cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1; 183 $cur->comment_ip = http::realIP(); 184 185 # --BEHAVIOR-- publicBeforeTrackbackCreate 186 $this->core->callBehavior('publicBeforeTrackbackCreate',$cur); 187 if ($cur->post_id) { 188 $comment_id = $this->core->blog->addComment($cur); 189 190 # --BEHAVIOR-- publicAfterTrackbackCreate 191 $this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id); 192 } 193 } 148 194 149 195 /// @name Receive trackbacks … … 176 222 $charset = ''; 177 223 $comment = ''; 178 224 179 225 $err = false; 180 226 $msg = ''; … … 209 255 $msg = 'Trackbacks are not allowed for this post or weblog.'; 210 256 } 257 258 $url = trim(html::clean($url)); 259 if ($this->pingAlreadyDone($post->post_id, $url)) { 260 $err = true; 261 $msg = 'The trackback has already been registered'; 262 } 211 263 } 212 264 … … 216 268 217 269 if (!$charset) { 218 $charset = mb_detect_encoding($title.' '.$excerpt.' '.$blog_name, 219 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'. 220 'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'. 221 'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15'); 270 $charset = self::detectCharset($title.' '.$excerpt.' '.$blog_name); 222 271 } 223 272 … … 244 293 $blog_name = text::cutString($blog_name,60); 245 294 246 $url = trim(html::clean($url));247 248 if (!$blog_name) {249 $blog_name = 'Anonymous blog';250 }251 252 $comment =253 "<!-- TB -->\n".254 '<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n".255 '<p>'.$excerpt.'</p>';256 257 $cur = $this->core->con->openCursor($this->core->prefix.'comment');258 $cur->comment_author = (string) $blog_name;259 $cur->comment_site = (string) $url;260 $cur->comment_content = (string) $comment;261 $cur->post_id = $post_id;262 $cur->comment_trackback = 1;263 $cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1;264 $cur->comment_ip = http::realIP();265 266 295 try 267 296 { 268 # --BEHAVIOR-- publicBeforeTrackbackCreate 269 $this->core->callBehavior('publicBeforeTrackbackCreate',$cur); 270 if ($cur->post_id) { 271 $comment_id = $this->core->blog->addComment($cur); 272 273 # --BEHAVIOR-- publicAfterTrackbackCreate 274 $this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id); 275 } 297 $this->addBacklink($post_id, $url, $blog_name, $title, $excerpt, $comment); 276 298 } 277 299 catch (Exception $e) … … 281 303 } 282 304 } 283 284 285 $debug_trace =286 " <debug>\n".287 ' <title>'.$title."</title>\n".288 ' <excerpt>'.$excerpt."</excerpt>\n".289 ' <url>'.$url."</url>\n".290 ' <blog_name>'.$blog_name."</blog_name>\n".291 ' <charset>'.$charset."</charset>\n".292 ' <comment>'.$comment."</comment>\n".293 " </debug>\n";294 305 295 306 $resp = … … 303 314 304 315 if (!empty($_POST['__debug'])) { 305 $resp .= $debug_trace; 316 $resp .= 317 " <debug>\n". 318 ' <title>'.$title."</title>\n". 319 ' <excerpt>'.$excerpt."</excerpt>\n". 320 ' <url>'.$url."</url>\n". 321 ' <blog_name>'.$blog_name."</blog_name>\n". 322 ' <charset>'.$charset."</charset>\n". 323 ' <comment>'.$comment."</comment>\n". 324 " </debug>\n"; 306 325 } 307 326 … … 362 381 } 363 382 383 if ($this->pingAlreadyDone($posts->post_id, $from_url)) { 384 throw new Exception(__('Don\'t repeat yourself, please.'), 48); 385 } 386 364 387 # OK. We've found our champion. Time to check the remote part. 365 388 try { … … 381 404 $remote_content = $http->getContent(); 382 405 383 $charset = mb_detect_encoding($remote_content, 384 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'. 385 'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'. 386 'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15'); 387 406 $charset = self::getCharsetFromRequest($http->getHeader('content-type')); 407 408 if (!$charset) { 409 $charset = self::detectCharset($remote_content); 410 } 411 388 412 if (strtolower($charset) != 'utf-8') { 389 413 $remote_content = iconv($charset,'UTF-8',$remote_content); … … 416 440 } 417 441 if ($excerpt) { 418 $excerpt = '(…) '.text::cutString(html::escapeHTML($excerpt),2 55).' (…)';442 $excerpt = '(…) '.text::cutString(html::escapeHTML($excerpt),200).' (…)'; 419 443 } 420 444 else { 421 $excerpt = '(??)'; 422 } 423 424 $comment = 425 "<!-- TB -->\n". 426 '<p><strong>'.$title."</strong></p>\n". 427 '<p>'.$excerpt.'</p>'; 428 429 $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 430 $cur->comment_author = 'Anonymous blog'; 431 $cur->comment_site = (string) $from_url; 432 $cur->comment_content = (string) $comment; 433 $cur->post_id = $posts->post_id; 434 $cur->comment_trackback = 1; 435 $cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1; 436 $cur->comment_ip = http::realIP(); 437 438 # --BEHAVIOR-- publicBeforeTrackbackCreate 439 $this->core->callBehavior('publicBeforeTrackbackCreate',$cur); 440 if ($cur->post_id) { 441 $comment_id = $this->core->blog->addComment($cur); 442 443 # --BEHAVIOR-- publicAfterTrackbackCreate 444 $this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id); 445 } 445 $excerpt = '(…)'; 446 } 447 448 $this->addBacklink($posts->post_id, $from_url, '', $title, $excerpt, $comment); 446 449 } 447 450 catch (Exception $e) { … … 464 467 } 465 468 466 private static function getCharsetFromRequest() 467 { 468 if (isset($_SERVER['CONTENT_TYPE'])) 469 { 470 if (preg_match('|charset=([a-zA-Z0-9-]+)|',$_SERVER['CONTENT_TYPE'],$m)) { 469 private static function getCharsetFromRequest($header = '') 470 { 471 if (!$header && isset($_SERVER['CONTENT_TYPE'])) { 472 $header = $_SERVER['CONTENT_TYPE']; 473 } 474 475 if ($header) { 476 if (preg_match('|charset=([a-zA-Z0-9-]+)|',$header,$m)) { 471 477 return $m[1]; 472 478 } … … 475 481 return null; 476 482 } 477 483 484 private static function detectCharset($string) 485 { 486 return mb_detect_encoding($remote_content, 487 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'. 488 'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'. 489 'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15'); 490 } 491 478 492 /// @name Trackbacks auto discovery 479 493 //@{
Note: See TracChangeset
for help on using the changeset viewer.