[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the generic_ping_plugin. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}. 10 * 11 * {@internal License choice 12 * - If you have received this file as part of a package, please find the license.txt file in 13 * the same folder or the closest folder above for complete license terms. 14 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 15 * then you must choose one of the following licenses before using the file: 16 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 17 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 18 * }} 19 * 20 * {@internal Open Source relicensing agreement: 21 * Daniel HAHLER grants Francois PLANQUE the right to license 22 * Daniel HAHLER's contributions to this file and the b2evolution project 23 * under any OSI approved OSS license (http://www.opensource.org/licenses/). 24 * }} 25 * 26 * @package plugins 27 * 28 * @author blueyed: Daniel HAHLER 29 * 30 * @version $Id: _generic_ping.plugin.php,v 1.7 2007/06/16 20:23:21 blueyed Exp $ 31 */ 32 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 33 34 35 /** 36 * Generic Ping Plugin 37 * 38 * @package plugins 39 */ 40 class generic_ping_plugin extends Plugin 41 { 42 /** 43 * Variables below MUST be overriden by plugin implementations, 44 * either in the subclass declaration or in the subclass constructor. 45 */ 46 var $code = ''; 47 var $priority = 50; 48 var $version = '1.9-dev'; 49 var $author = 'The b2evo Group'; 50 var $help_url = ''; // empty URL defaults to manual wiki 51 52 /* 53 * These variables MAY be overriden. 54 */ 55 var $apply_rendering = 'never'; 56 var $group = 'ping'; 57 58 59 /** 60 * Init 61 * 62 * This gets called after a plugin has been registered/instantiated. 63 */ 64 function PluginInit( & $params ) 65 { 66 $this->name = T_('Generic Ping plugin'); 67 $this->short_desc = T_('Use this plugin to add a generic ping service to your installation.'); 68 69 if( $params['is_installed'] ) 70 { // is not set for not-installed Plugins 71 $this->ping_service_name = $this->Settings->get('ping_service_name'); 72 $this->ping_service_note = $this->Settings->get('ping_service_note'); 73 } 74 } 75 76 77 /** 78 * Get the settings that the plugin can use. 79 * 80 * Those settings are transfered into a Settings member object of the plugin 81 * and can be edited in the backoffice (Settings / Plugins). 82 * 83 * @see Plugin::GetDefaultSettings() 84 * @see PluginSettings 85 * @see Plugin::PluginSettingsValidateSet() 86 * @return array 87 */ 88 function GetDefaultSettings() 89 { 90 return array( 91 'ping_service_url' => array( 92 'label' => T_('Ping service URL'), 93 'defaultvalue' => '', 94 'type' => 'text', 95 'size' => 50, 96 'note' => T_('The URL of the ping service.').' '.sprintf('E.g. «%s»', 'rpc.weblogs.com/RPC2 or rpc.foobar.com:8080'), 97 ), 98 'ping_service_extended' => array( 99 'label' => T_('Extended ping?'), 100 'type' => 'checkbox', 101 'defaultvalue' => 0, 102 'note' => T_('Use weblogUpdates.extendedPing method instead of weblogUpdates.ping?'), 103 ), 104 'ping_service_name' => array( 105 'label' => T_('Ping service name'), 106 'defaultvalue' => '', 107 'type' => 'text', 108 'size' => 25, 109 'note' => T_('The name of the ping service, used for displaying only.'), 110 ), 111 'ping_service_note' => array( 112 'label' => T_('Ping service note'), 113 'defaultvalue' => '', 114 'type' => 'text', 115 'size' => 50, 116 'note' => T_('Notes about the ping service, used for displaying only.'), 117 ), 118 ); 119 } 120 121 122 /** 123 * Check ping service URL and plugin code. 124 */ 125 function BeforeEnable() 126 { 127 $ping_service_url = $this->Settings->get('ping_service_url'); 128 if( empty($ping_service_url) ) 129 { 130 return T_('You must configure a ping service URL before the plugin can be enabled.'); 131 } 132 133 if( empty($this->code) ) 134 { 135 return T_('The ping plugin needs a non-empty code.'); 136 } 137 138 return true; 139 } 140 141 142 /** 143 * Check ping service URL. 144 */ 145 function PluginSettingsValidateSet( & $params ) 146 { 147 if( $params['name'] == 'ping_service_url' ) 148 { 149 if( ! $this->parse_ping_url($params['value']) ) 150 { 151 return T_('The ping service URL is invalid.'); 152 } 153 } 154 } 155 156 157 /** 158 * Parse a given ping service URL 159 * 160 * @return false|array False in case of error, array with keys 'host', 'port', 'path' otherwise 161 */ 162 function parse_ping_url( $url ) 163 { 164 if( ! preg_match( '~^([^/:]+)(:\d+)?(/.*)?$~', $url, $match ) ) 165 { 166 return false; 167 } 168 169 $r = array( 170 'host' => $match[1], 171 'port' => empty($match[2]) ? 80 : $match[2], 172 'path' => empty($match[3]) ? '/' : $match[3], 173 ); 174 175 return $r; 176 } 177 178 179 /** 180 * Send a ping to the configured service. 181 */ 182 function ItemSendPing( & $params ) 183 { 184 global $debug; 185 186 $url = $this->parse_ping_url( $this->Settings->get( 'ping_service_url' ) ); 187 188 $Item = $params['Item']; 189 $item_Blog = $Item->get_Blog(); 190 191 $client = new xmlrpc_client( $url['path'], $url['host'], $url['port'] ); 192 $client->debug = ($debug && $params['display']); 193 194 if( $this->Settings->get('ping_service_extended') ) 195 { 196 $message = new xmlrpcmsg("weblogUpdates.extendedPing", array( 197 new xmlrpcval( $item_Blog->get('name') ), 198 new xmlrpcval( $item_Blog->get('url') ), 199 new xmlrpcval( $Item->get_permanent_url() ), 200 new xmlrpcval( $item_Blog->get('atom_url') ), 201 // TODO: tags.. 202 )); 203 } 204 else 205 { 206 $message = new xmlrpcmsg("weblogUpdates.ping", array( 207 new xmlrpcval( $item_Blog->get('name') ), 208 new xmlrpcval( $item_Blog->get('url') ) )); 209 } 210 $result = $client->send($message); 211 212 $params['xmlrpcresp'] = $result; 213 214 return true; 215 } 216 217 } 218 219 220 /* 221 * $Log: _generic_ping.plugin.php,v $ 222 * Revision 1.7 2007/06/16 20:23:21 blueyed 223 * Added "ping_service_extended" setting to use weblogUpdates.extendedPing 224 * 225 * Revision 1.6 2007/04/26 00:11:04 fplanque 226 * (c) 2007 227 * 228 * Revision 1.5 2007/01/20 23:48:10 blueyed 229 * Changed plugin default URL to manual.b2evolution.net/classname_plugin 230 * 231 * Revision 1.4 2006/11/24 18:27:27 blueyed 232 * Fixed link to b2evo CVS browsing interface in file docblocks 233 * 234 * Revision 1.3 2006/10/30 19:00:37 blueyed 235 * Lazy-loading of Plugin (User)Settings for PHP5 through overloading 236 * 237 * Revision 1.2 2006/10/11 17:21:09 blueyed 238 * Fixes 239 * 240 * Revision 1.1 2006/10/05 01:19:11 blueyed 241 * Initial import of generic ping plugin. 242 * 243 */ 244 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |