Changeset 3521:b8a16a351d6d for inc
- Timestamp:
- 01/20/17 14:14:22 (9 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.trackback.php
r3415 r3521 356 356 /** 357 357 Receives a webmention and insert it as a comment of given post. 358 358 359 359 NB: plugin Fair Trackback check source content to find url. 360 360 … … 387 387 388 388 # Create a comment for received webmention 389 // maybe better to try to fetch a title from the source ?... 390 $title = __('A website mention this entry.'); 391 $comment = ''; 392 $excerpt = sprintf('<a href="%s" rel="nofollow">%s</a>',$from_url,$from_url); 389 $remote_content = $this->getRemoteContent($from_url); 390 391 # We want a title... 392 if (!preg_match('!<title>([^<].*?)</title>!mis',$remote_content,$m)) { 393 throw new Exception(__('Where\'s your title?'), 0); 394 } 395 $title = trim(html::clean($m[1])); 396 $title = html::decodeEntities($title); 397 $title = html::escapeHTML($title); 398 $title = text::cutString($title,60); 399 400 preg_match('!<body[^>]*?>(.*)?</body>!msi',$remote_content,$m); 401 $source = $m[1]; 402 $source = preg_replace('![\r\n\s]+!ms',' ',$source); 403 $source = preg_replace( "/<\/*(h\d|p|th|td|li|dt|dd|pre|caption|input|textarea|button)[^>]*>/","\n\n",$source ); 404 $source = strip_tags($source,'<a>'); 405 $source = explode("\n\n",$source); 406 407 $excerpt = ''; 408 foreach ($source as $line) { 409 if (strpos($line, $to_url) !== false) { 410 if (preg_match("!<a[^>]+?".$to_url."[^>]*>([^>]+?)</a>!",$line,$m)) { 411 $excerpt = strip_tags($line); 412 break; 413 } 414 } 415 } 416 if ($excerpt) { 417 $excerpt = '(…) '.text::cutString(html::escapeHTML($excerpt),200).' (…)'; 418 } 419 else { 420 $excerpt = '(…)'; 421 } 422 393 423 $this->addBacklink($post_id,$from_url,'',$title,$excerpt,$comment); 394 424 … … 443 473 { 444 474 if (empty($blog_name)) { 445 $blog_name = 'Anonymous blog'; 475 // Let use title as text link for this backlink 476 $blog_name = ($title ?: 'Anonymous blog'); 446 477 } 447 478 … … 522 553 523 554 /** 524 Retreive local post from a given IRL555 Retreive local post from a given URL 525 556 526 557 @param to_url <b>string</b> Target URL … … 692 723 } 693 724 694 # If we've got a X-Pingback header and it's a valid URL, it will be enough 695 if ($pb_url && filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 696 return $pb_url.'|'.$url; 697 } 698 699 # No X-Pingback header. A link rel=pingback, maybe ? 700 $pattern_pingback = '!<link rel="pingback" href="(.*?)"( /)?>!msi'; 701 702 if (preg_match($pattern_pingback,$page_content,$m)) { 703 $pb_url = $m[1]; 704 if (filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 705 return $pb_url.'|'.$url; 706 } 707 } 708 709 # No pingback ? OK, let's check for a trackback data chunk... 725 # Let's check for an elderly trackback data chunk... 710 726 $pattern_rdf = 711 727 '/<rdf:RDF.*?>.*?'. … … 730 746 } 731 747 748 # No trackback ? OK, let see if we've got a X-Pingback header and it's a valid URL, it will be enough 749 if ($pb_url && filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 750 return $pb_url.'|'.$url; 751 } 752 753 # No X-Pingback header. A link rel=pingback, maybe ? 754 $pattern_pingback = '!<link rel="pingback" href="(.*?)"( /)?>!msi'; 755 756 if (preg_match($pattern_pingback,$page_content,$m)) { 757 $pb_url = $m[1]; 758 if (filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 759 return $pb_url.'|'.$url; 760 } 761 } 762 732 763 # Nothing, let's try webmention. Only support x/html content 733 764 if ($wm_url) { … … 792 823 public static function checkURLs($from_url,$to_url) 793 824 { 794 if (!(filter_var($from_url, 825 if (!(filter_var($from_url,FILTER_VALIDATE_URL) && preg_match('!^https?://!',$from_url))) { 795 826 throw new Exception(__('No valid source URL provided? Try again!'), 0); 796 827 } 797 828 798 if (!(filter_var($to_url, 829 if (!(filter_var($to_url,FILTER_VALIDATE_URL) && preg_match('!^https?://!',$to_url))) { 799 830 throw new Exception(__('No valid target URL provided? Try again!'), 0); 800 831 }
Note: See TracChangeset
for help on using the changeset viewer.