| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.3 | 6 // +---------------------------------------------------------------------------+ 7 // | lib-pingback.php | 8 // | | 9 // | Functions needed to handle pingbacks. | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2005 by the following authors: | 12 // | | 13 // | Author: Dirk Haun - dirk AT haun-online DOT de | 14 // +---------------------------------------------------------------------------+ 15 // | | 16 // | This program is free software; you can redistribute it and/or | 17 // | modify it under the terms of the GNU General Public License | 18 // | as published by the Free Software Foundation; either version 2 | 19 // | of the License, or (at your option) any later version. | 20 // | | 21 // | This program is distributed in the hope that it will be useful, | 22 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 // | GNU General Public License for more details. | 25 // | | 26 // | You should have received a copy of the GNU General Public License | 27 // | along with this program; if not, write to the Free Software Foundation, | 28 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 29 // | | 30 // +---------------------------------------------------------------------------+ 31 // 32 // $Id: lib-pingback.php,v 1.7 2006/06/15 18:26:45 dhaun Exp $ 33 34 if (strpos ($_SERVER['PHP_SELF'], 'lib-pingback.php') !== false) { 35 die ('This file can not be used on its own!'); 36 } 37 38 // PEAR class to handle XML-RPC 39 require_once ('XML/RPC.php'); 40 41 /** 42 * Get the Pingback URL for a given URL 43 * 44 * Note: Only checks for the 'X-Pingback:' header. 45 * 46 * @param string $url URL to get the Pingback URL for 47 * @return string Pingback URL or empty string 48 * 49 */ 50 function PNB_getPingbackUrl ($url) 51 { 52 require_once ('HTTP/Request.php'); 53 54 $retval = ''; 55 56 $req =& new HTTP_Request ($url); 57 $req->setMethod (HTTP_REQUEST_METHOD_HEAD); 58 $req->addHeader ('User-Agent', 'GeekLog/' . VERSION); 59 60 $response = $req->sendRequest (); 61 if (PEAR::isError ($response)) { 62 COM_errorLog ('Pingback: ' . $response->getMessage()); 63 return false; 64 } else { 65 $retval = $req->getResponseHeader ('X-Pingback'); 66 } 67 68 return $retval; 69 } 70 71 /** 72 * Send a Pingback 73 * 74 * @param string $sourceURI URL of an entry on our site 75 * @param string $targetURI an entry on someone else's site 76 * @return string empty string on success or error message 77 * 78 */ 79 function PNB_sendPingback ($sourceURI, $targetURI) 80 { 81 global $LANG_TRB; 82 83 $retval = ''; 84 85 $pingback = PNB_getPingbackUrl ($targetURI); 86 if (empty ($pingback)) { 87 return $LANG_TRB['no_pingback_url']; 88 } 89 90 $parts = parse_url ($pingback); 91 if (empty ($parts['port'])) { 92 if (strcasecmp ($parts['scheme'], 'https') == 0) { 93 $parts['port'] = 443; 94 } else { 95 $parts['port'] = 80; 96 } 97 } 98 $client = new XML_RPC_Client ($parts['path'], $parts['host'], $parts['port']); 99 //$client->setDebug (1); 100 101 $msg = new XML_RPC_Message ('pingback.ping', 102 array (new XML_RPC_Value ($sourceURI, 'string'), 103 new XML_RPC_Value ($targetURI, 'string'))); 104 105 $response = $client->send ($msg, 0, $parts['scheme']); 106 if ($response == 0) { 107 $retval = $client->errstring; 108 } else if ($response->faultCode () != 0) { 109 $retval = $response->faultString (); 110 } 111 112 return $retval; 113 } 114 115 /** 116 * Send a standard ping to a weblog directory service 117 * 118 * The "classic" ping, originally invented for weblogs.com 119 * 120 * @param string $url URL to ping 121 * @param string $blogname name of our site 122 * @param string $blogurl URL of our site 123 * @param string $changedurl URL of the changed / new entry 124 * @return string empty string on success of error message 125 * 126 */ 127 function PNB_sendPing ($url, $blogname, $blogurl, $changedurl) 128 { 129 $parts = parse_url ($url); 130 if (empty ($parts['port'])) { 131 if (strcasecmp ($parts['scheme'], 'https') == 0) { 132 $parts['port'] = 443; 133 } else { 134 $parts['port'] = 80; 135 } 136 } 137 $client = new XML_RPC_Client ($parts['path'], $parts['host'], $parts['port']); 138 //$client->setDebug (1); 139 140 $msg = new XML_RPC_Message ('weblogUpdates.ping', 141 array (new XML_RPC_Value ($blogname, 'string'), 142 new XML_RPC_Value ($blogurl, 'string'), 143 new XML_RPC_Value ($changedurl, 'string'))); 144 145 $response = $client->send ($msg, 0, $parts['scheme']); 146 if ($response == 0) { 147 $retval = $client->errstring; 148 } else if ($response->faultCode () != 0) { 149 $retval = $response->faultString (); 150 } 151 152 return $retval; 153 } 154 155 /** 156 * Send an extended ping to a weblog directory service 157 * 158 * Supported e.g. by blo.gs 159 * 160 * @param string $url URL to ping 161 * @param string $blogname name of our site 162 * @param string $blogurl URL of our site 163 * @param string $changedurl URL of the changed / new entry 164 * @param string $feedurl URL of a feed for our site 165 * @return string empty string on success of error message 166 * 167 */ 168 function PNB_sendExtendedPing ($url, $blogname, $blogurl, $changedurl, $feedurl) 169 { 170 $parts = parse_url ($url); 171 if (empty ($parts['port'])) { 172 if (strcasecmp ($parts['scheme'], 'https') == 0) { 173 $parts['port'] = 443; 174 } else { 175 $parts['port'] = 80; 176 } 177 } 178 $client = new XML_RPC_Client ($parts['path'], $parts['host'], $parts['port']); 179 //$client->setDebug (1); 180 181 $msg = new XML_RPC_Message ('weblogUpdates.extendedPing', 182 array (new XML_RPC_Value ($blogname, 'string'), 183 new XML_RPC_Value ($blogurl, 'string'), 184 new XML_RPC_Value ($changedurl, 'string'), 185 new XML_RPC_Value ($feedurl, 'string'))); 186 187 $response = $client->send ($msg, 0, $parts['scheme']); 188 if ($response == 0) { 189 $retval = $client->errstring; 190 } else if ($response->faultCode () != 0) { 191 $retval = $response->faultString (); 192 } 193 194 return $retval; 195 } 196 197 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|