Source for file _functions_pingback.php
Documentation is available at _functions_pingback.php
* Pingback support functions
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
* @author This file built upon code from original b2 - http://cafelog.com/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
* original code by Mort (http://mort.mine.nu:8080)
* {@internal pingback(-)}}
global $b2_version, $debug, $ItemCache;
echo
"<div class=\"panelinfo\">\n";
echo
'<h3>', T_('Sending pingbacks...'), '</h3>', "\n";
if( $display ) echo
'<p>', T_('No pingback to be done.'), '</p>', "\n";
$gunk =
'/#~:.?+=&%@!\-';
$any =
$ltrs.
$gunk.
$punc;
$pingback_str_dquote =
'rel="pingback"';
$pingback_str_squote =
'rel=\'pingback\'';
$x_pingback_str =
'x-pingback: ';
$pingback_href_original_pos =
27;
$Item =
$ItemCache->get_by_ID( $post_ID );
$content =
'<a href="'.
$post_url.
'">'.
$post_title.
'</a>'.
$post_url;
// Parsing the post, external links (if any) are stored in the $post_links array
// This regexp comes straigth from phpfreaks.com
// http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php
// preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
// fplanque: \b is for word boundary
// trailing x is to ignore whitespace
// we need to simplify and allow ; in the URL
preg_match_all("{\b http:// [0-9A-Za-z:/_~+\-%.?&=;]+}x", $content, $post_links_temp);
// Walking thru the links array
// first we get rid of links pointing to sites, not to specific files
// http://dummy-weblog.org
// http://dummy-weblog.org/
// http://dummy-weblog.org/post.php
// We don't wanna ping first and second types, even if they have a valid <link/>
foreach($post_links_temp[0] as $link_test)
//echo "testing: $link_test <br />";
if( $test['scheme'] ==
'http' )
if (isset
($test['query']))
$post_links[] =
$link_test;
elseif(($test['path'] !=
'/') &&
($test['path'] !=
''))
$post_links[] =
$link_test;
foreach ($post_links as $pagelinkedto)
if( $display ) echo
'<p>', T_('Processing:'), ' ', $pagelinkedto, "<br />\n";
if (!isset
($bits['host'])) {
if( $display ) echo
T_('Couldn\'t find a hostname for:'),' ',$pagelinkedto, "<br />\n";
debug_fwrite($log, T_('Couldn\'t find a hostname for:').
' '.
$pagelinkedto.
"\n\n");
$path = isset
($bits['path']) ?
$bits['path'] :
'';
if (isset
($bits['query'])) {
$path .=
'?'.
$bits['query'];
$port = isset
($bits['port']) ?
$bits['port'] :
80;
// Try to connect to the server at $host
if( $display ) echo
T_('Connect to server at:'), ' ',$host;
$fp =
fsockopen($host, $port, $errno, $errstr, 30);
if( $display ) echo
T_('Couldn\'t open a connection to:'), ' ', $pagelinkedto, "<br />\n";
debug_fwrite($log, T_('Couldn\'t open a connection to:').
' '.
$host.
"\n\n");
$request =
"GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: b2evolution/$b2_version PHP/" .
phpversion() .
"\r\n\r\n";
// Start receiving headers and content
$found_pingback_server =
0;
$line =
fgets($fp, 4096);
// echo "line (".strlen($line)."): [",htmlspecialchars($line),"] <br />\n";
if (trim($line) ==
'') // ligne blanche = fin des headers
$pingback_link_offset_dquote =
0;
$pingback_link_offset_squote =
0;
$x_pingback_header_offset =
0;
$contents .=
trim($line).
"\n";
// localise rel="'pingback"' :
$pingback_link_offset_dquote =
strpos($contents, $pingback_str_dquote);
$pingback_link_offset_squote =
strpos($contents, $pingback_str_squote);
$headers .=
trim($line).
"\n";
if ($x_pingback_header_offset)
{ // on a trouvé dans les headers
preg_match('#x-pingback: (.+)#is', $headers, $matches);
$pingback_server_url =
trim($matches[1]);
echo
T_('Pingback server found from X-Pingback header:'), ' ', $pingback_server_url, "<br />\n";
debug_fwrite($log, T_('Pingback server found from X-Pingback header:').
' '.
$pingback_server_url.
"\n");
$found_pingback_server =
1;
if( $pingback_link_offset_dquote ||
$pingback_link_offset_squote )
{ // on a trouvé dans les données
$quote =
($pingback_link_offset_dquote) ?
'"' :
'\'';
$pingback_link_offset =
($quote==
'"') ?
$pingback_link_offset_dquote :
$pingback_link_offset_squote;
$pingback_href_pos =
strpos($contents, 'href=', $pingback_link_offset);
$pingback_href_start =
$pingback_href_pos+
6;
$pingback_href_end =
strpos($contents, $quote, $pingback_href_start);
$pingback_server_url_len =
$pingback_href_end-
$pingback_href_start;
$pingback_server_url =
substr($contents, $pingback_href_start, $pingback_server_url_len);
echo
T_('Pingback server found from Pingback <link /> tag:'), ' ', $pingback_server_url, "<br />\n";
debug_fwrite($log, T_('Pingback server found from Pingback <link /> tag:').
' '.
$pingback_server_url.
"\n");
$found_pingback_server =
1;
if(!$found_pingback_server)
if( $display ) echo
T_('Pingback server not found in headers and content'), "<br />\n";
debug_fwrite($log, T_('Pingback server not found in headers and content').
"\n\n*************************\n\n");
elseif( empty($pingback_server_url) )
if( $display ) echo
T_('Pingback server URL is empty (may be an internal PHP fgets error)'), "<br />\n";
debug_fwrite($log, T_('Pingback server URL is empty (may be an internal PHP fgets error)').
"\n\n*************************\n\n");
$parsed_url =
parse_url( $pingback_server_url );
$port = isset
($parsed_url['port']) ?
$parsed_url['port'] :
80;
$method =
'pingback.ping';
if( $display ) echo
T_('Page Linked To:'), " $pagelinkedto<br />\n";
if( $display ) echo
T_('Page Linked From:'), " $pagelinkedfrom<br />\n";
$client =
new xmlrpc_client( $parsed_url['path'], $parsed_url['host'], $port);
$client->setDebug( $debug );
printf( T_('Pinging %s...').
"<br />\n", $host );
$result =
$client->send($message);
if( $display ) echo
"</p>\n";
if( $display ) echo
"<p>", T_('Pingbacks done.'), "<p>\n";
if( $display ) echo
"</div>\n";
* @deprecated deprecated by {@link Item::feedback_link()}
if( $zero ==
'#' ) $zero =
T_('Pingback (0)');
if( $one ==
'#' ) $one =
T_('Pingback (1)');
if( $more ==
'#' ) $more =
T_('Pingbacks (%d)');
global $id, $tablecomments, $tb, $querycount, $cache_pingbacknumber, $use_cache;
} elseif ($number ==
1) {
* Displays link to the pingback page
* @deprecated deprecated by {@link Item::feedback_link()}
if( ($file ==
'') ||
($file ==
'/') )
{ // include comments // fplanque: added
{ // include trackback // fplanque: added
echo
'&pb=1#pingbacks';
* @deprecated deprecated by {@link Item::feedback_link()}
global $blog, $id, $b2pingbackpopupfile, $b2commentsjavascript;
if ($b2commentsjavascript) {
echo
'" onclick="b2open(this.href); return false"';
// if comments_popup_script() is not in the template, display simple comment link
echo
' class="'.
$CSSclass.
'"';
/***** // Pingback tags *****/