Changeset 1684:b7294dd181ee
- Timestamp:
- 09/01/13 18:00:42 (10 years ago)
- Branch:
- default
- Children:
- 1685:8d8ae6da4e22, 1687:1b2c41ca89a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.trackback.php
r1674 r1684 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 addBacklink($post_id, $url, $blog_name, $title, $excerpt, &$comment) 150 { 151 if (empty($blog_name)) { 152 $blog_name = 'Anonymous blog'; 153 } 154 155 $comment = 156 "<!-- TB -->\n". 157 '<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n". 158 '<p>'.$excerpt.'</p>'; 159 160 $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 161 $cur->comment_author = (string) $blog_name; 162 $cur->comment_site = (string) $url; 163 $cur->comment_content = (string) $comment; 164 $cur->post_id = $post_id; 165 $cur->comment_trackback = 1; 166 $cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1; 167 $cur->comment_ip = http::realIP(); 168 169 # --BEHAVIOR-- publicBeforeTrackbackCreate 170 $this->core->callBehavior('publicBeforeTrackbackCreate',$cur); 171 if ($cur->post_id) { 172 $comment_id = $this->core->blog->addComment($cur); 173 174 # --BEHAVIOR-- publicAfterTrackbackCreate 175 $this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id); 176 } 177 } 148 178 149 179 /// @name Receive trackbacks … … 216 246 217 247 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'); 248 $charset = self::detectCharset($title.' '.$excerpt.' '.$blog_name); 222 249 } 223 250 … … 246 273 $url = trim(html::clean($url)); 247 274 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 275 try 267 276 { 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 } 277 $this->addBacklink($post_id, $url, $blog_name, $title, $excerpt, $comment); 276 278 } 277 279 catch (Exception $e) … … 281 283 } 282 284 } 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 285 295 286 $resp = … … 303 294 304 295 if (!empty($_POST['__debug'])) { 305 $resp .= $debug_trace; 296 $resp .= 297 " <debug>\n". 298 ' <title>'.$title."</title>\n". 299 ' <excerpt>'.$excerpt."</excerpt>\n". 300 ' <url>'.$url."</url>\n". 301 ' <blog_name>'.$blog_name."</blog_name>\n". 302 ' <charset>'.$charset."</charset>\n". 303 ' <comment>'.$comment."</comment>\n". 304 " </debug>\n"; 306 305 } 307 306 … … 381 380 $remote_content = $http->getContent(); 382 381 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 382 $charset = self::getCharsetFromRequest($http->getHeader('content-type')); 383 384 if (!$charset) { 385 $charset = self::detectCharset($remote_content); 386 } 387 388 388 if (strtolower($charset) != 'utf-8') { 389 389 $remote_content = iconv($charset,'UTF-8',$remote_content); … … 416 416 } 417 417 if ($excerpt) { 418 $excerpt = '(…) '.text::cutString(html::escapeHTML($excerpt),2 55).' (…)';418 $excerpt = '(…) '.text::cutString(html::escapeHTML($excerpt),200).' (…)'; 419 419 } 420 420 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 } 421 $excerpt = '(…)'; 422 } 423 424 $this->addBacklink($posts->post_id, $from_url, '', $title, $excerpt, $comment); 446 425 } 447 426 catch (Exception $e) { … … 464 443 } 465 444 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)) { 445 private static function getCharsetFromRequest($header = '') 446 { 447 if (!$header && isset($_SERVER['CONTENT_TYPE'])) { 448 $header = $_SERVER['CONTENT_TYPE']; 449 } 450 451 if ($header) { 452 if (preg_match('|charset=([a-zA-Z0-9-]+)|',$header,$m)) { 471 453 return $m[1]; 472 454 } … … 475 457 return null; 476 458 } 477 459 460 private static function detectCharset($string) 461 { 462 return mb_detect_encoding($remote_content, 463 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,'. 464 'ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,'. 465 'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15'); 466 } 467 478 468 /// @name Trackbacks auto discovery 479 469 //@{
Note: See TracChangeset
for help on using the changeset viewer.