[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_event_weblogping.php 1791 2007-07-20 09:20:03Z garvinhicking $ 2 3 require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; 4 5 // Probe for a language include with constants. Still include defines later on, if some constants were missing 6 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 7 if (file_exists($probelang)) { 8 include $probelang; 9 } 10 11 include dirname(__FILE__) . '/lang_en.inc.php'; 12 13 class serendipity_event_weblogping extends serendipity_event 14 { 15 var $services; 16 17 function introspect(&$propbag) 18 { 19 global $serendipity; 20 21 $propbag->add('name', PLUGIN_EVENT_WEBLOGPING_TITLE); 22 $propbag->add('description', PLUGIN_EVENT_WEBLOGPING_DESC); 23 $propbag->add('stackable', false); 24 $propbag->add('author', 'Serendipity Team'); 25 $propbag->add('version', '1.07'); 26 $propbag->add('requirements', array( 27 'serendipity' => '0.8', 28 'smarty' => '2.6.7', 29 'php' => '4.1.0' 30 )); 31 $propbag->add('event_hooks', array( 32 'backend_display' => true, 33 'frontend_display' => true, 34 'backend_insert' => true, 35 'backend_update' => true, 36 'backend_publish' => true, 37 'backend_draft' => true, 38 'external_plugin' => true 39 )); 40 $propbag->add('groups', array('BACKEND_EDITOR')); 41 42 $servicesdb = array(); 43 $servicesdb_file = dirname(__FILE__) . '/servicesdb_' . $serendipity['lang'] . '.inc.php'; 44 if (!file_exists($servicesdb_file)) { 45 $servicesdb_file = dirname(__FILE__) . '/servicesdb_en.inc.php'; 46 } 47 include $servicesdb_file; 48 $this->services =& $servicesdb; 49 50 51 $manual_services = explode(',', $this->get_config('manual_services')); 52 if (is_array($manual_services)) { 53 foreach($manual_services as $ms_index => $ms_name) { 54 if (!empty($ms_name)) { 55 $is_extended = ($ms_name{0} == '*' ? true : false); 56 $ms_name = trim($ms_name, '*'); 57 $ms_parts = explode('/', $ms_name); 58 $ms_host = $ms_parts[0]; 59 unset($ms_party[0]); 60 61 array_shift( $ms_parts); // remove hostname. 62 $this->services[] = array( 63 'name' => $ms_name, 64 'host' => $ms_host, 65 'path' => '/'.implode('/', $ms_parts), 66 'extended' => $is_extended 67 ); 68 } 69 } 70 } 71 72 $conf_array = array(); 73 foreach($this->services AS $key => $service) { 74 $conf_array[] = $service['name']; 75 } 76 77 $conf_array[] = 'manual_services'; 78 79 $propbag->add('configuration', $conf_array); 80 } 81 82 function introspect_config_item($name, &$propbag) 83 { 84 switch($name) { 85 case 'manual_services': 86 $propbag->add('type', 'string'); 87 $propbag->add('name', PLUGIN_EVENT_WEBLOGPING_CUSTOM); 88 $propbag->add('description', PLUGIN_EVENT_WEBLOGPING_CUSTOM_BLAHBLA); 89 $propbag->add('default', ''); 90 break; 91 92 default: 93 $propbag->add('type', 'boolean'); 94 $propbag->add('name', $name); 95 $propbag->add('description', sprintf(PLUGIN_EVENT_WEBLOGPING_PING, $name)); 96 $propbag->add('default', 'false'); 97 } 98 return true; 99 } 100 101 function generate_content(&$title) { 102 $title = PLUGIN_EVENT_WEBLOGPING_TITLE; 103 } 104 105 function event_hook($event, &$bag, &$eventData) { 106 global $serendipity; 107 108 $hooks = &$bag->get('event_hooks'); 109 if (isset($hooks[$event])) { 110 switch($event) { 111 case 'backend_display': 112 ?> 113 <fieldset style="margin: 5px"> 114 <legend><?php echo PLUGIN_EVENT_WEBLOGPING_PING; ?></legend> 115 <?php 116 $noneclick = ''; 117 foreach($this->services AS $index => $service) { 118 // Detect if the current checkbox needs to be saved. We use the field chk_timestamp to see, 119 // if the form has already been submitted and individual changes shall be preserved 120 $selected = (($serendipity['POST']['chk_timestamp'] && $serendipity['POST']['announce_entries_' . $service['name']]) || (!isset($serendipity['POST']['chk_timestamp']) && $this->get_config($service['name']) == 'true') ? 'checked="checked"' : ''); 121 122 $noneclick .= 'document.getElementById(\'serendipity[announce_entries_' . $service['name'] . ']\').checked = false; '; 123 $onclick = ''; 124 if (!empty($service['supersedes'])) { 125 $onclick = 'onclick="'; 126 $supersedes = explode(', ', $service['supersedes']); 127 foreach($supersedes AS $sid => $servicename) { 128 $onclick .= 'document.getElementById(\'serendipity[announce_entries_' . $servicename . ']\').checked = false; '; 129 } 130 $onclick .= '"'; 131 } 132 133 $title = sprintf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING, $service['name']) 134 . (!empty($service['supersedes']) ? ' ' . sprintf(PLUGIN_EVENT_WEBLOGPING_SUPERSEDES, $service['supersedes']) : ''); 135 ?> 136 <input <?php echo $onclick; ?> class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" name="serendipity[announce_entries_<?php echo $service['name']; ?>]" id="serendipity[announce_entries_<?php echo $service['name']; ?>]" value="true" <?php echo $selected; ?> /> 137 <label title="<?php echo $title; ?>" style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_<?php echo $service['name']; ?>]"> <?php echo $service['name']; ?> </label><br /> 138 <?php 139 } 140 ?> 141 <input onclick="<?php echo $noneclick; ?>" class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" value="none" id="serendipity[announce_entries_none]" /> 142 <label title="<?php echo NONE; ?>" style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_none]"> <?php echo NONE; ?> </label><br /> 143 </fieldset> 144 <?php 145 return true; 146 break; 147 148 case 'backend_publish': 149 if (!class_exists('XML_RPC_Base')) { 150 include_once(S9Y_PEAR_PATH . "XML/RPC.php"); 151 } 152 153 // First cycle through list of services to remove superseding services which may have been checked 154 foreach ($this->services as $index => $service) { 155 if (!empty($service['supersedes']) && isset($serendipity['POST']['announce_entries_' . $service['name']])) { 156 $supersedes = explode(', ', $service['supersedes']); 157 foreach($supersedes AS $sid => $servicename) { 158 // A service has been checked that is superseded by another checked meta-service. Remove that service from the list of services to be ping'd 159 unset($serendipity['POST']['announce_entries_' . $servicename]); 160 } 161 } 162 } 163 foreach ($this->services as $index => $service) { 164 if (isset($serendipity['POST']['announce_entries_' . $service['name']]) || (defined('SERENDIPITY_IS_XMLRPC') && serendipity_db_bool($this->get_config($service['name'])))) { 165 if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) { 166 printf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING . '...', $service['host']); 167 } 168 flush(); 169 170 # XXX append $serendipity['indexFile'] to baseURL? 171 $args = array( 172 new XML_RPC_Value( 173 $serendipity['blogTitle'], 174 'string' 175 ), 176 new XML_RPC_Value( 177 $serendipity['baseURL'], 178 'string' 179 ) 180 ); 181 182 if ($service['extended']) { 183 # the checkUrl: for when the main page is not really the main page 184 $args[] = new XML_RPC_Value( 185 '', 186 'string' 187 ); 188 189 # the rssUrl 190 $args[] = new XML_RPC_Value( 191 $serendipity['baseURL'] . 'rss.php?version=2.0', 192 'string' 193 ); 194 } 195 196 $message = new XML_RPC_Message( 197 $service['extended'] ? 'weblogUpdates.extendedPing' : 'weblogUpdates.ping', 198 $args 199 ); 200 201 $client = new XML_RPC_Client( 202 trim($service['path']), 203 trim($service['host']) 204 ); 205 206 # 15 second timeout may not be long enough for weblogs.com 207 $message->createPayload(); 208 $options = array(); 209 serendipity_plugin_api::hook_event('backend_http_request', $options, 'weblogping'); 210 serendipity_request_start(); 211 212 $req = new HTTP_Request("http://".$service['host'].$service['path'], $options); 213 $req->setMethod(HTTP_REQUEST_METHOD_POST); 214 $req->addHeader("Content-Type", "text/xml"); 215 if (strtoupper(LANG_CHARSET) != 'UTF-8') { 216 $payload = utf8_encode($message->payload); 217 } else { 218 $payload = $message->payload; 219 } 220 $req->addRawPostData($payload); 221 $http_result = $req->sendRequest(); 222 $http_response = $req->getResponseBody(); 223 $xmlrpc_result = $message->parseResponse($http_response); 224 if ($xmlrpc_result->faultCode()) { 225 $out = sprintf(PLUGIN_EVENT_WEBLOGPING_SEND_FAILURE . "<br />", htmlspecialchars($xmlrpc_result->faultString())); 226 } else { 227 $out = PLUGIN_EVENT_WEBLOGPING_SEND_SUCCESS . "<br />"; 228 } 229 serendipity_request_end(); 230 231 if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) { 232 echo $out; 233 } 234 } 235 } 236 237 return true; 238 break; 239 240 case 'external_plugin': 241 if ($eventData == 'xmlrpc_ping') { 242 echo "XMLRPC START\n"; 243 @define('SERENDIPITY_IS_XMLRPC', true); 244 @define('SERENDIPITY_XMLRPC_VERBOSE', true); 245 $this->event_hook('backend_publish', $bag, $eventData); 246 echo "XMLRPC DONE\n"; 247 } 248 return true; 249 250 case 'frontend_display': 251 case 'backend_insert': 252 case 'backend_update': 253 case 'backend_draft': 254 default: 255 return false; 256 break; 257 } 258 } else { 259 return false; 260 } 261 } 262 } 263 264 /* vim: set sts=4 ts=4 expandtab : */ 265 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |