[geeklog-cvs] geeklog-1.3/system lib-pingback.php,NONE,1.1 lib-plugins.php,1.54,1.55
dhaun at iowaoutdoors.org
dhaun at iowaoutdoors.org
Fri Jan 28 05:04:16 EST 2005
Update of /var/cvs/geeklog-1.3/system
In directory www:/tmp/cvs-serv14362/system
Modified Files:
lib-plugins.php
Added Files:
lib-pingback.php
Log Message:
Added preliminary support for Pingbacks (receiving pingbacks works; sending pingbacks hasn't been hooked up yet).
--- NEW FILE: lib-pingback.php ---
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.3 |
// +---------------------------------------------------------------------------+
// | lib-pingback.php |
// | |
// | Functions needed to handle pingbacks. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2005 by the following authors: |
// | |
// | Author: Dirk Haun - dirk AT haun-online DOT de |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
// $Id: lib-pingback.php,v 1.1 2005/01/28 10:04:14 dhaun Exp $
if (eregi ('lib-trackback.php', $_SERVER['PHP_SELF'])) {
die ('This file can not be used on its own.');
}
// PEAR class to handle XML-RPC
require_once ('XML/RPC.php');
/**
* Get the HEAD response for a URL
*
* @param string $targeturl URL to get the HEAD from
* @return string the HEAD response as one string or false
*
*/
function PNB_getHead ($targeturl)
{
$target = parse_url ($targeturl);
if (!empty ($target['query'])) {
$target['query'] = '?' . $target['query'];
}
if (empty ($target['port']) || !is_numeric ($target['port'])) {
$target['port'] = 80;
}
$sock = fsockopen ($target['host'], $target['port']);
if (!is_resource ($sock)) {
COM_errorLog ('Pingback: Could not connect to ' . $targeturl);
return false;
}
fputs ($sock, 'HEAD ' . $target['path'] . " HTTP/1.1\n");
fputs ($sock, 'Host: ' . $target['host'] . "\n");
fputs ($sock, "Connection: close\n\n");
$res = '';
while (!feof ($sock)) {
$res .= fgets ($sock, 128);
}
fclose($sock);
return $res;
}
/**
* Get the Pingback URL for a given URL
*
* Note: Only checks for the 'X-Pingback:' header.
*
* @param string $url URL to get the Pingback URL for
* @return string Pingback URL or empty string
*
*/
function PNB_getPingbackUrl ($url)
{
$retval = '';
$head = PNB_getHead ($url);
if (!empty ($head)) {
$header = explode ("\n", $head);
foreach ($header as $h) {
$parts = explode (' ', $h);
if (strcasecmp ($parts[0], 'X-Pingback:') == 0) {
$retval = trim ($parts[1]);
break;
}
}
}
// if we don't get the URL from the header, we could now try to read
// the page and extract it from a <link rel="pingback"> tag, but use
// of those is discouraged anyway ...
return $retval;
}
/**
* Send a Pingback
*
* @param string $sourceURI URL of an entry on our site
* @param string $targetURI an entry on someone else's site
* @return string empty string on success or error message
*
*/
function PNB_sendPingback ($sourceURI, $targetURI)
{
$retval = '';
$pingback = PNB_getPingbackUrl ($targetURI);
if (empty ($pingback)) {
return 'No pingback URL found.';
}
$parts = parse_url ($pingback);
if (empty ($parts['port'])) {
if (strcasecmp ($parts['scheme'], 'https') == 0) {
$parts['port'] = 443;
} else {
$parts['port'] = 80;
}
}
$client = new XML_RPC_Client ($parts['path'], $parts['host'], $parts['port']);
//$client->setDebug (1);
$msg = new XML_RPC_Message ('pingback.ping',
array (new XML_RPC_Value ($sourceURI, 'string'),
new XML_RPC_Value ($targetURI, 'string')));
$response = $client->send ($msg, 0, $parts['scheme']);
if ($response == 0) {
$retval = $client->errstring;
} else if ($response->faultCode () != 0) {
$retval = $response->faultString ();
}
return $retval;
}
?>
Index: lib-plugins.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/system/lib-plugins.php,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** lib-plugins.php 28 Jan 2005 04:49:10 -0000 1.54
--- lib-plugins.php 28 Jan 2005 10:04:14 -0000 1.55
***************
*** 233,237 ****
* @return mixed false for failure, HTML string (redirect?) for success
*/
! function PLG_commentDelete($type, $cid, $id) {
$args[1] = $cid;
$args[2] = $id;
--- 233,238 ----
* @return mixed false for failure, HTML string (redirect?) for success
*/
! function PLG_commentDelete($type, $cid, $id)
! {
$args[1] = $cid;
$args[2] = $id;
***************
*** 252,256 ****
* @return mixed false for failure, HTML string (redirect?) for success
*/
! function PLG_commentSave($type, $title, $comment, $id, $pid, $postmode) {
$args[1] = $title;
$args[2] = $comment;
--- 253,258 ----
* @return mixed false for failure, HTML string (redirect?) for success
*/
! function PLG_commentSave($type, $title, $comment, $id, $pid, $postmode)
! {
$args[1] = $title;
$args[2] = $comment;
***************
*** 276,280 ****
* @return mixed results of calling the plugin_displaycomment_ function
*/
! function PLG_displayComment($type, $id, $cid, $title, $order, $format, $page, $view) {
$args[1] = $id;
$args[2] = $cid;
--- 278,283 ----
* @return mixed results of calling the plugin_displaycomment_ function
*/
! function PLG_displayComment($type, $id, $cid, $title, $order, $format, $page, $view)
! {
$args[1] = $id;
$args[2] = $cid;
***************
*** 529,532 ****
--- 532,536 ----
{
$args[1] = $id;
+
return PLG_callFunctionForOnePlugin('plugin_moderationapprove_' . $type, $args);
}
***************
*** 545,548 ****
--- 549,553 ----
{
$args[1] = $id;
+
return PLG_callFunctionForOnePlugin('plugin_moderationdelete_' . $type, $args);
}
***************
*** 560,563 ****
--- 565,569 ----
{
$args[1] = $A;
+
return PLG_callFunctionForOnePlugin('plugin_savesubmission_' . $type, $args);
}
***************
*** 1283,1289 ****
function PLG_handleTrackbackComment ($type, $id, $operation)
{
$function = 'plugin_handletrackbackcomment_' . $type;
! return PLG_callFunctionForOnePlugin ($function, $id, $operation);
}
--- 1289,1324 ----
function PLG_handleTrackbackComment ($type, $id, $operation)
{
+ $args[1] = $id;
+ $args[2] = $operation;
+
$function = 'plugin_handletrackbackcomment_' . $type;
! return PLG_callFunctionForOnePlugin ($function, $args);
! }
!
! /**
! * Ask plugin if it accepts a pingback for the item at URL $targetURI
! *
! * Pingback only sends the URL of the item it's pinging. Geeklog has determined
! * that the URL belongs to a plugin and is now asking that plugin if it will
! * accept pingbacks for it. The plugin is expected to return a unique ID for
! * the entry if it accepts the ping or an empty string to reject it.
! *
! * Note: This API function is subject to change ...
! *
! * @param string $type plugin type
! * @param string $sourceURI URL the ping came from (FYI only)
! * @param string $targetURI URL being pinged
! * @return string ID of the pinged item or empty string = rejected
! *
! */
! function PLG_acceptPingback ($type, $sourceURI, $targetURI)
! {
! $args[1] = $sourceURI;
! $args[2] = $targetURI;
!
! $function = 'plugin_acceptpingback_' . $type;
!
! return PLG_callFunctionForOnePlugin ($function, $args);
}
More information about the geeklog-cvs
mailing list