b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.9) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _generic_ping.plugin.php

Documentation is available at _generic_ping.plugin.php

  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-2006 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://cvs.sourceforge.net/viewcvs.py/evocms/)
  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.2.2.3 2006/10/30 19:05:58 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, in this case: http://manual.b2evolution.net/Plugins/test_plugin';
  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. &laquo;%s&raquo;''rpc.weblogs.com/RPC2 or rpc.foobar.com:8080'),
  97.                 ),
  98.             'ping_service_name' => array(
  99.                     'label' => T_('Ping service name'),
  100.                     'defaultvalue' => '',
  101.                     'type' => 'text',
  102.                     'size' => 25,
  103.                     'note' => T_('The name of the ping service, used for displaying only.'),
  104.             ),
  105.             'ping_service_note' => array(
  106.                     'label' => T_('Ping service note'),
  107.                     'defaultvalue' => '',
  108.                     'type' => 'text',
  109.                     'size' => 50,
  110.                     'note' => T_('Notes about the ping service, used for displaying only.'),
  111.             ),
  112.         );
  113.     }
  114.  
  115.  
  116.     /**
  117.      * Check ping service URL and plugin code.
  118.      */
  119.     function BeforeEnable()
  120.     {
  121.         $ping_service_url $this->Settings->get('ping_service_url');
  122.         ifempty($ping_service_url) )
  123.         {
  124.             return T_('You must configure a ping service URL before the plugin can be enabled.');
  125.         }
  126.  
  127.         ifempty($this->code) )
  128.         {
  129.             return T_('The ping plugin needs a non-empty code.');
  130.         }
  131.  
  132.         return true;
  133.     }
  134.  
  135.  
  136.     /**
  137.      * Check ping service URL.
  138.      */
  139.     function PluginSettingsValidateSet$params )
  140.     {
  141.         if$params['name'== 'ping_service_url' )
  142.         {
  143.             if$this->parse_ping_url($params['value']) )
  144.             {
  145.                 return T_('The ping service URL is invalid.');
  146.             }
  147.         }
  148.     }
  149.  
  150.  
  151.     /**
  152.      * Parse a given ping service URL
  153.      *
  154.      * @return false|arrayFalse in case of error, array with keys 'host', 'port', 'path' otherwise
  155.      */
  156.     function parse_ping_url$url )
  157.     {
  158.         ifpreg_match'~^([^/:]+)(:\d+)?(/.*)?$~'$url$match ) )
  159.         {
  160.             return false;
  161.         }
  162.  
  163.         $r array(
  164.                 'host' => $match[1],
  165.                 'port' => empty($match[2]80 $match[2],
  166.                 'path' => empty($match[3]'/' $match[3],
  167.             );
  168.  
  169.         return $r;
  170.     }
  171.  
  172.  
  173.     /**
  174.      * Send a ping to the configured service.
  175.      */
  176.     function ItemSendPing$params )
  177.     {
  178.         global $debug;
  179.  
  180.         $url $this->parse_ping_url$this->Settings->get'ping_service_url' ) );
  181.  
  182.         $item_Blog $params['Item']->get_Blog();
  183.  
  184.         $client new xmlrpc_client$url['path']$url['host']$url['port');
  185.         $client->debug ($debug && $params['display']);
  186.  
  187.         $message new xmlrpcmsg("weblogUpdates.ping"array(
  188.                 new xmlrpcval$item_Blog->get('name') ),
  189.                 new xmlrpcval$item_Blog->get('url') ) ));
  190.         $result $client->send($message);
  191.  
  192.         $params['xmlrpcresp'$result;
  193.  
  194.         return true;
  195.     }
  196.  
  197. }
  198.  
  199.  
  200. /*
  201.  * nolog
  202.  */
  203. ?>

Documentation generated on Tue, 18 Dec 2007 19:17:31 +0100 by phpDocumentor 1.4.0