Enhanced pingback/trackback receiving
This commit is contained in:
10
docs/NEWS
10
docs/NEWS
@ -3,6 +3,16 @@
|
|||||||
Version 1.3 ()
|
Version 1.3 ()
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* Pingback/Trackback textfetching: HTML Entities are now converted
|
||||||
|
to characters. Character encoding defaults to UTF-8 but can be
|
||||||
|
configured via $serendipity['pingbackEntityEncoding'] = "UTF-8"
|
||||||
|
in your serendipity_config_local.php (brockhaus)
|
||||||
|
|
||||||
|
* For Pingback it is now possible to define the maximum amount of
|
||||||
|
characters while fetching text of the remote site. Add
|
||||||
|
$serendipity['pingbackFetchPageMaxLenght'] = 200 to your
|
||||||
|
serendipity_config_local.php. (brockhaus)
|
||||||
|
|
||||||
* Add ability to set comments as "pending" again, even when already
|
* Add ability to set comments as "pending" again, even when already
|
||||||
approved in the comment-moderation backend panel.
|
approved in the comment-moderation backend panel.
|
||||||
(garvinhicking)
|
(garvinhicking)
|
||||||
|
@ -320,6 +320,9 @@ function add_trackback ($id, $title, $url, $name, $excerpt) {
|
|||||||
$title = $url;
|
$title = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode HTML Entities
|
||||||
|
$excerpt = trackback_body_strip($excerpt);
|
||||||
|
|
||||||
$comment = array(
|
$comment = array(
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
@ -489,6 +492,17 @@ function fetchPingbackData( &$comment) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max amount of characters fetched from the page doing a pingback:
|
||||||
|
$fetchPageMaxLenght = 200;
|
||||||
|
if (isset($serendipity['pingbackFetchPageMaxLenght'])){
|
||||||
|
$fetchPageMaxLenght = $serendipity['pingbackFetchPageMaxLenght'];
|
||||||
|
}
|
||||||
|
// HTML Entity Encoding
|
||||||
|
$entityEncoding = "UTF-8";
|
||||||
|
if (isset($serendipity['pingbackEntityEncoding'])){
|
||||||
|
$entityEncoding = $serendipity['pingbackEntityEncoding'];
|
||||||
|
}
|
||||||
|
|
||||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||||
$url = $comment['url'];
|
$url = $comment['url'];
|
||||||
|
|
||||||
@ -507,7 +521,7 @@ function fetchPingbackData( &$comment) {
|
|||||||
|
|
||||||
// Get a title
|
// Get a title
|
||||||
if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is',$fContent,$matches)) {
|
if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is',$fContent,$matches)) {
|
||||||
$comment['title'] = strip_tags($matches[1]);
|
$comment['title'] = html_entity_decode(strip_tags($matches[1]),ENT_COMPAT,$entityEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get content from first <p> tag on:
|
// Try to get content from first <p> tag on:
|
||||||
@ -519,16 +533,10 @@ function fetchPingbackData( &$comment) {
|
|||||||
}
|
}
|
||||||
// Get a part of the article
|
// Get a part of the article
|
||||||
if (!empty($body)) {
|
if (!empty($body)) {
|
||||||
$body = strip_tags($body);
|
$body = trackback_body_strip($body);
|
||||||
|
|
||||||
//TODO: Serendipity comes into trouble wit html_entity_decode and "Umlaute"
|
|
||||||
$body = str_replace(array(" "),array(' '),$body);
|
|
||||||
|
|
||||||
// replace whitespace with single space
|
|
||||||
$body = preg_replace('@\s+@s', ' ', $body);
|
|
||||||
|
|
||||||
// truncate the text to 200 chars
|
// truncate the text to 200 chars
|
||||||
$arr = str_split($body, 200);
|
$arr = str_split($body, $fetchPageMaxLenght);
|
||||||
$body = $arr[0];
|
$body = $arr[0];
|
||||||
|
|
||||||
$comment['comment'] = $body . '[..]';
|
$comment['comment'] = $body . '[..]';
|
||||||
@ -539,6 +547,27 @@ function fetchPingbackData( &$comment) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips any unneeded code from trackback / pingback bodies returning pure (UTF8) text.
|
||||||
|
*/
|
||||||
|
function trackback_body_strip( $body ){
|
||||||
|
// replace non brakeable space with normal space:
|
||||||
|
$body = str_replace(' ', ' ', $body);
|
||||||
|
|
||||||
|
// HTML Entity Encoding
|
||||||
|
$entityEncoding = "UTF-8";
|
||||||
|
if (isset($serendipity['pingbackEntityEncoding'])){
|
||||||
|
$entityEncoding = $serendipity['pingbackEntityEncoding'];
|
||||||
|
}
|
||||||
|
// strip html entities and tags.
|
||||||
|
$body = html_entity_decode(strip_tags($body),ENT_COMPAT,$entityEncoding);
|
||||||
|
|
||||||
|
// replace whitespace with single space
|
||||||
|
$body = preg_replace('@\s+@s', ' ', $body);
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an excerpt for a trackback to send
|
* Create an excerpt for a trackback to send
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user