b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/_generic_ping.plugin.php - 218 lines - 5863 bytes - Summary - Text - Print

Description: This file implements the generic_ping_plugin. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   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-2014 by Francois Planque - {@link http://fplanque.com/}
   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 6136 2014-03-08 07:59:48Z manuel $
  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 = '5.0.0';
  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 $group = 'ping';
  56  
  57  
  58      /**
  59       * Init
  60       *
  61       * This gets called after a plugin has been registered/instantiated.
  62       */
  63  	function PluginInit( & $params )
  64      {
  65          $this->name = T_('Generic Ping plugin');
  66          $this->short_desc = T_('Use this plugin to add a generic ping service to your installation.');
  67  
  68          if( $params['is_installed'] )
  69          { // is not set for not-installed Plugins
  70              $this->ping_service_name = $this->Settings->get('ping_service_name');
  71              $this->ping_service_note = $this->Settings->get('ping_service_note');
  72          }
  73      }
  74  
  75  
  76      /**
  77       * Get the settings that the plugin can use.
  78       *
  79       * Those settings are transfered into a Settings member object of the plugin
  80       * and can be edited in the backoffice (Settings / Plugins).
  81       *
  82       * @see Plugin::GetDefaultSettings()
  83       * @see PluginSettings
  84       * @see Plugin::PluginSettingsValidateSet()
  85       * @return array
  86       */
  87  	function GetDefaultSettings()
  88      {
  89          return array(
  90              'ping_service_url' => array(
  91                      'label' => T_('Ping service URL'),
  92                      'defaultvalue' => '',
  93                      'type' => 'text',
  94                      'size' => 50,
  95                      'note' => T_('The URL of the ping service.').' '.sprintf('E.g. &laquo;%s&raquo;', 'rpc.weblogs.com/RPC2 or rpc.foobar.com:8080'),
  96                  ),
  97              'ping_service_extended' => array(
  98                      'label' => T_('Extended ping?'),
  99                      'type' => 'checkbox',
 100                      'defaultvalue' => 0,
 101                      'note' => T_('Use weblogUpdates.extendedPing method instead of weblogUpdates.ping?'),
 102                  ),
 103              'ping_service_name' => array(
 104                      'label' => T_('Ping service name'),
 105                      'defaultvalue' => '',
 106                      'type' => 'text',
 107                      'size' => 25,
 108                      'note' => T_('The name of the ping service, used for displaying only.'),
 109              ),
 110              'ping_service_note' => array(
 111                      'label' => T_('Ping service note'),
 112                      'defaultvalue' => '',
 113                      'type' => 'text',
 114                      'size' => 50,
 115                      'note' => T_('Notes about the ping service, used for displaying only.'),
 116              ),
 117          );
 118      }
 119  
 120  
 121      /**
 122       * Check ping service URL and plugin code.
 123       */
 124  	function BeforeEnable()
 125      {
 126          $ping_service_url = $this->Settings->get('ping_service_url');
 127          if( empty($ping_service_url) )
 128          {
 129              return T_('You must configure a ping service URL before the plugin can be enabled.');
 130          }
 131  
 132          if( empty($this->code) )
 133          {
 134              return T_('The ping plugin needs a non-empty code.');
 135          }
 136  
 137          return true;
 138      }
 139  
 140  
 141      /**
 142       * Check ping service URL.
 143       */
 144  	function PluginSettingsValidateSet( & $params )
 145      {
 146          if( $params['name'] == 'ping_service_url' )
 147          {
 148              if( ! $this->parse_ping_url($params['value']) )
 149              {
 150                  return T_('The ping service URL is invalid.');
 151              }
 152          }
 153      }
 154  
 155  
 156      /**
 157       * Parse a given ping service URL
 158       *
 159       * @return false|array False in case of error, array with keys 'host', 'port', 'path' otherwise
 160       */
 161  	function parse_ping_url( $url )
 162      {
 163          if( ! preg_match( '~^([^/:]+)(:\d+)?(/.*)?$~', $url, $match ) )
 164          {
 165              return false;
 166          }
 167  
 168          $r = array(
 169                  'host' => $match[1],
 170                  'port' => empty($match[2]) ? 80 : $match[2],
 171                  'path' => empty($match[3]) ? '/' : $match[3],
 172              );
 173  
 174          return $r;
 175      }
 176  
 177  
 178      /**
 179       * Send a ping to the configured service.
 180       */
 181  	function ItemSendPing( & $params )
 182      {
 183          global $debug;
 184  
 185          $url = $this->parse_ping_url( $this->Settings->get( 'ping_service_url' ) );
 186  
 187          $Item = $params['Item'];
 188          $item_Blog = $Item->get_Blog();
 189  
 190          $client = new xmlrpc_client( $url['path'], $url['host'], $url['port'] );
 191          $client->debug = ($debug && $params['display']);
 192  
 193          if( $this->Settings->get('ping_service_extended') )
 194          {
 195              $message = new xmlrpcmsg("weblogUpdates.extendedPing", array(
 196                      new xmlrpcval( $item_Blog->get('name') ),
 197                      new xmlrpcval( $item_Blog->get('url') ),
 198                      new xmlrpcval( $Item->get_permanent_url() ),
 199                      new xmlrpcval( $item_Blog->get('atom_url') ),
 200                      // TODO: tags..
 201                      ));
 202          }
 203          else
 204          {
 205              $message = new xmlrpcmsg("weblogUpdates.ping", array(
 206                      new xmlrpcval( $item_Blog->get('name') ),
 207                      new xmlrpcval( $item_Blog->get('url') ) ));
 208          }
 209          $result = $client->send($message);
 210  
 211          $params['xmlrpcresp'] = $result;
 212  
 213          return true;
 214      }
 215  
 216  }
 217  
 218  ?>

title

Description

title

Description

title

Description

title

title

Body