# ------------------------------------------
# FIND -------------------------------------
$this->addCallback(
'mt.publishPost',
'this:mt_publishPost',
array('boolean','string','string','string'),
'changes the status of the current article to published'
);
# ADD AFTER
$this->addCallback(
'pingback.ping',
'this:pingback_ping',
array('boolean', 'string', 'string'),
'pingback server'
);
# ------------------------------------------
# FIND -------------------------------------
# MediaObjects
# ADD BEFORE
# Pingback
function pingback_ping($params) {
list($pagelinkedfrom, $pagelinkedto) = $params;
$pagelinkedfrom = doSlash($pagelinkedfrom);
$pagelinkedto = doSlash($pagelinkedto);
$title = '';
$pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom);
$pagelinkedto = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedto);
// Check IP
$ip = $_SERVER['REMOTE_ADDR'];
$checkBan = fetch('ip', 'txp_discuss_ipban', 'ip', $ip);
if (!empty($checkBan))
return new IXR_Error(49, gTxt('you_have_been_banned'));
$blacklisted = is_blacklisted($ip);
if ($blacklisted)
return new IXR_Error(49, gTxt('your_ip_is_blacklisted_by').' '.$blacklisted);
// Check URI
$pos1 = strpos($pagelinkedto, str_replace(array('http://www', 'http://', 'https:/www', 'https://'), '', hu));
if (!$pos1)
return new IXR_Error(0, 'Is there no link to us?');
include_plugin('bat_trackback_lib');
$post_ID = (int) url_to_postid($pagelinkedto);
if (!$post_ID)
return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
$post = safe_row('*', 'textpattern', "ID='$post_ID'");
if (!$post)
return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
if ($post_ID == @url_to_postid($pagelinkedfrom))
return new IXR_Error(0, 'The source URI and the target URI cannot both point to the same resource.');
$dupe = getRow("SELECT * FROM ".PFX."txp_trackback WHERE parentid='$post_ID' AND url='$pagelinkedfrom'");
if($dupe)
return new IXR_Error(48, 'The pingback has already been registered.');
sleep(1);
$linea = wp_remote_fopen($pagelinkedfrom);
if (!$linea)
return new IXR_Error(16, 'The source URI does not exist.');
$linea = str_replace(']*>/", "\n\n", $linea);
preg_match('|
([^<]*?)|is', $linea, $matchtitle);
$title = $matchtitle[1];
if (empty($title))
return new IXR_Error(32, 'We cannot find a title on that page.');
$linea = strip_tags($linea, '');
$p = explode("\n\n", $linea);
$sem_regexp_pb = "/(\\/|\\\|\*|\?|\+|\.|\^|\\$|\(|\)|\[|\]|\||\{|\})/";
$sem_regexp_fix = "\\\\$1";
$link = preg_replace($sem_regexp_pb, $sem_regexp_fix, $pagelinkedfrom);
$finished = false;
foreach($p as $para) {
if ($finished)
continue;
if (strstr($para, $pagelinkedto)) {
$context = preg_replace( "/.*]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para );
$excerpt = strip_tags( $para );
$excerpt = trim( $excerpt );
$use = preg_quote( $context );
$excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt);
$finished = true;
}
}
if (empty($context))
return new IXR_Error(17, 'The source URI does not contain a link to the target URI, and so cannot be used as a source.');
$pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedfrom);
$context = '[...] '.wp_specialchars($excerpt).' [...]';
$original_pagelinkedfrom = $pagelinkedfrom;
$pagelinkedfrom = doSlash($pagelinkedfrom);
$original_title = $title;
$parentid = $post_ID;
$url = $pagelinkedfrom;
$excerpt = $context;
$type = 'pingback';
$trackbackdata = compact('parentid', 'title', 'excerpt', 'url', 'type', 'ip');
require_once txpath.'/lib/constants.php';
require_once txpath.'/publish/taghandlers.php';
$updated = bat_new_trackback($trackbackdata);
if ($updated)
return "Pingback from $pagelinkedfrom to $pagelinkedto registered. Keep the web talking! :-)";
else
return new IXR_Error(320603, 'unable to log.');
}
# ------------------------------------------
# FIND -------------------------------------
?>
# ADD BEFORE
// Functions from Wordpress http://wordpress.org
function wp_remote_fopen($uri) {
if (ini_get('allow_url_fopen')) {
$fp = fopen($uri, 'r');
if (!$fp)
return false;
$linea = '';
while($remote_read = fread($fp, 4096))
$linea .= $remote_read;
fclose($fp);
return $linea;
} elseif (function_exists('curl_init')) {
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $uri);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($handle, CURLOPT_RETURNTRASFER, 1);
$buffer = curl_exec($handle);
curl_close($handle);
return $buffer;
} else {
return false;
}
}
function wp_specialchars($text) {
$text = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/', '&$1', $text);
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
return $text;
}