b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/test_plugin/_test.plugin.php - 1025 lines - 29074 bytes - Summary - Text - Print

Description: This file implements the TEST plugin. For the most recent and complete Plugin API documentation see {@link Plugin} in ../inc/plugins/_plugin.class.php.

   1  <?php
   2  /**

   3   * This file implements the TEST plugin.

   4   *

   5   * For the most recent and complete Plugin API documentation

   6   * see {@link Plugin} in ../inc/plugins/_plugin.class.php.

   7   *

   8   * This file is part of the evoCore framework - {@link http://evocore.net/}

   9   * See also {@link http://sourceforge.net/projects/evocms/}.

  10   *

  11   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

  12   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  13   *

  14   * {@internal License choice

  15   * - If you have received this file as part of a package, please find the license.txt file in

  16   *   the same folder or the closest folder above for complete license terms.

  17   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  18   *   then you must choose one of the following licenses before using the file:

  19   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  20   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  21   * }}

  22   *

  23   * {@internal Open Source relicensing agreement:

  24   * Daniel HAHLER grants Francois PLANQUE the right to license

  25   * Daniel HAHLER's contributions to this file and the b2evolution project

  26   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  27   * }}

  28   *

  29   * @package plugins

  30   *

  31   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  32   * @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}

  33   * @author blueyed: Daniel HAHLER

  34   *

  35   * @version $Id: _test.plugin.php 13 2011-10-24 23:42:53Z fplanque $

  36   */
  37  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  38  
  39  
  40  /**

  41   * TEST Plugin

  42   *

  43   * This plugin responds to virtually all possible plugin events :P

  44   *

  45   * @package plugins

  46   */
  47  class test_plugin extends Plugin
  48  {
  49      /**

  50       * Variables below MUST be overriden by plugin implementations,

  51       * either in the subclass declaration or in the subclass constructor.

  52       */
  53      var $name = 'Test';
  54      var $code = 'evo_TEST';
  55      var $priority = 50;
  56      var $version = '5.0.0';
  57      var $author = 'The b2evo Group';
  58      var $help_url = '';  // empty URL defaults to manual wiki

  59  
  60      /*

  61       * These variables MAY be overriden.

  62       */
  63      var $number_of_installs = 1;
  64      var $group = 'test';
  65  
  66  
  67      /**

  68       * Init

  69       *

  70       * This gets called after a plugin has been registered/instantiated.

  71       */
  72  	function PluginInit( & $params )
  73      {
  74          $this->short_desc = 'Test plugin';
  75          $this->long_desc = 'This plugin responds to virtually all possible plugin events :P';
  76  
  77          // Trigger plugin settings instantiation (for testing).

  78          if( $params['is_installed'] )
  79          {
  80              $this->Settings->get('foo');
  81          }
  82      }
  83  
  84  
  85      /**

  86       * Get the settings that the plugin can use.

  87       *

  88       * Those settings are transfered into a Settings member object of the plugin

  89       * and can be edited in the backoffice (Settings / Plugins).

  90       *

  91       * @see Plugin::GetDefaultSettings()

  92       * @see PluginSettings

  93       * @see Plugin::PluginSettingsValidateSet()

  94       * @return array

  95       */
  96  	function GetDefaultSettings( & $params )
  97      {
  98          $r = array(
  99              'click_me' => array(
 100                  'label' => 'Click me!',
 101                  'defaultvalue' => '1',
 102                  'type' => 'checkbox',
 103              ),
 104              'input_me' => array(
 105                  'label' => 'How are you?',
 106                  'defaultvalue' => '',
 107                  'note' => 'Welcome to b2evolution',
 108              ),
 109              'number' => array(
 110                  'label' => 'Number',
 111                  'defaultvalue' => '8',
 112                  'note' => '1-9',
 113                  'valid_range' => array( 'min'=>1, 'max'=>9 ),
 114              ),
 115              'my_select' => array(
 116                  'label' => 'Selector',
 117                  'id' => $this->classname.'_my_select',
 118                  'onchange' => 'document.getElementById("'.$this->classname.'_a_disabled_one").disabled = ( this.value == "sun" );',
 119                  'defaultvalue' => 'one',
 120                  'type' => 'select',
 121                  'options' => array( 'sun' => 'Sunday', 'mon' => 'Monday' ),
 122                  'note' => 'This combo is connected with the next field',
 123              ),
 124              'a_disabled_one' => array(
 125                  'label' => 'This one is disabled',
 126                  'id' => $this->classname.'_a_disabled_one',
 127                  'type' => 'checkbox',
 128                  'defaultvalue' => '1',
 129                  'disabled' => true, // this can be useful if you detect that something cannot be changed. You probably want to add a 'note' then, too.
 130                  'note' => 'Change the above select input to "Monday" to enable it.',
 131              ),
 132              'select_multiple' => array(
 133                  'label' => $this->T_( 'Multiple select' ),
 134                  'type' => 'select',
 135                  'multiple' => true,
 136                  'allow_none' => true,
 137                  'options' => array( 'sci' => $this->T_( 'Scissors' ), 'pap' => $this->T_( 'Paper' ), 'sto' => $this->T_( 'Stone') ),
 138                  'defaultvalue' => array( 'sci', 'sto' ),
 139                  'note' => $this->T_( 'This is a free style Multiple Select. You can choose zero or one or more items' )
 140              ),
 141              /*

 142               * note: The $this->T_( string )function tanslates the string.

 143               * However since it inherits from the class Plugin you will need

 144               * to provide the translation on a per plugin basis. In other

 145               * words: this will not be translated through B2evolution.

 146               */
 147              'blog' => array(
 148                  'label' => 'A blog',
 149                  'type' => 'select_blog',  // TODO: does not scale with 500 blogs
 150                  'allow_none' => true,
 151              ),
 152              'blogs' => array(
 153                  'label' => 'A set of blogs',
 154                  'type' => 'select_blog',    // TODO: BROKEN + does not scale with 500 blogs
 155                  'multiple' => true,
 156                  'allow_none' => true,
 157              ),
 158              'single_user' => array(
 159                  'label' => 'A single user',
 160                  'type' => 'select_user',
 161                  'allow_none' => true,
 162                  'default_value' => 0,
 163                  'note' => 'Allows chosing none or one user'
 164              ),
 165              'sets' => array(
 166                  'type' => 'select_user',
 167                  'label' => 'Multiple users',
 168                  'min_count' => 0,
 169                  'max_count' => 3,
 170                  'multiple' => 'true',
 171                  'allow_none' => true,
 172                  'note' => 'Allows none or one or more than one user (up to three in this example)',
 173                  'entries' => array(
 174                      'user' => array(
 175                          'label' => 'A user',
 176                          'type' => 'select_user',        // TODO: does not scale with 500 users
 177                          'allow_none' => true,
 178                      ),
 179                  ),
 180              ),
 181              'maxlen' => array(
 182                  'label' => 'Max',
 183                  'type' => 'textarea',
 184                  'maxlength' => 10,
 185                  'note' => 'Maximum length is 10 here.',
 186              ),
 187          );
 188  
 189          if( $params['for_editing'] )
 190          { // we're asked for the settings for editing:
 191              if( $this->Settings->get('my_select') == 'mon' )
 192              {
 193                  $r['a_disabled_one']['disabled'] = false;
 194              }
 195          }
 196  
 197          return $r;
 198      }
 199  
 200  
 201      /**

 202       * User settings.

 203       *

 204       * @see Plugin::GetDefaultUserSettings()

 205       * @see PluginUserSettings

 206       * @see Plugin::PluginUserSettingsValidateSet()

 207       * @return array

 208       */
 209  	function GetDefaultUserSettings()
 210      {
 211          return array(
 212                  'echo_random' => array(
 213                      'label' => 'Echo a random number in AdminBeginPayload event',
 214                      'type' => 'checkbox',
 215                      'defaultvalue' => '0',
 216                  ),
 217                  'deactivate' => array(
 218                      'label' => 'Deactivate',
 219                      'type' => 'checkbox',
 220                      'defaultvalue' => '0',
 221                  ),
 222              );
 223      }
 224  
 225  
 226      /**

 227       * We trigger an extra event ourself (which we also provide ourselves).

 228       *

 229       * @return array

 230       */
 231  	function GetExtraEvents()
 232      {
 233          return array(
 234                  // Gets "min" and "max" as params and should return a random number in between:

 235                  'test_plugin_get_random' => 'TEST event that returns a random number.',
 236              );
 237      }
 238  
 239  
 240      /**

 241       * Define a test cron job

 242       */
 243  	function GetCronJobs( & $params )
 244      {
 245          return array(
 246                  array(
 247                      'name' => 'TEST plugin - cron job',
 248                      'ctrl' => 'test_job',
 249                      'params' => array( 'param' => 1 ),
 250                  ),
 251              );
 252      }
 253  
 254  
 255      /**

 256       * Execute/Handle a test/sample cronjob.

 257       */
 258  	function ExecCronJob( & $params )
 259      {
 260          if( $params['ctrl'] == 'test_job' )
 261          {
 262              return array( 'code' => 1, 'message' => 'Test successful.' );
 263          }
 264      }
 265  
 266  
 267      /**

 268       * Deactive the plugin for the current request if the user wants it so.

 269       * @see Plugin::AppendLoginRegisteredUser()

 270       */
 271  	function AppendLoginRegisteredUser()
 272      {
 273          if( $this->UserSettings->get('deactivate') )
 274          {
 275              $this->forget_events();
 276          }
 277      }
 278  
 279  
 280      /**

 281       * Define some dependencies.

 282       *

 283       * @see Plugin::GetDependencies()

 284       * @return array

 285       */
 286  	function GetDependencies()
 287      {
 288          return array(
 289                  'recommends' => array(
 290                      'events_by_one' => array( array('Foo', 'Bar'), array('FooBar', 'BarFoo') ), // a plugin that provides "Foo" and "Bar", and one (may be the same) that provides "FooBar" and "BarFoo"
 291                      'events' => array( 'some_event', 'some_other_event' ),
 292                      'plugins' => array( array( 'some_plugin', '1' ) ), // at least version 1 of some_plugin
 293                  ),
 294  
 295                  'requires' => array(
 296                      // Same syntax as with the 'recommends' class above, but would prevent the plugin from being installed.

 297                  ),
 298              );
 299      }
 300  
 301  
 302      /**

 303       * Gets asked for, if user settings get updated.

 304       *

 305       * We just add a note.

 306       *

 307       * @see Plugin::PluginUserSettingsUpdateAction()

 308       */
 309  	function PluginUserSettingsUpdateAction()
 310      {
 311          if( $this->UserSettings->get('echo_random') )
 312          {
 313              $this->msg( 'TEST plugin: Random numbers have been disabled.' );
 314          }
 315          else
 316          {
 317              $this->msg( 'TEST plugin: Random numbers have been enabled.' );
 318          }
 319  
 320          return true;
 321      }
 322  
 323  
 324      /**

 325       * Event handlers:

 326       */
 327  
 328      /**

 329       * Event handler: Called when ending the admin html head section.

 330       *

 331       * @see Plugin::AdminEndHtmlHead()

 332       * @param array Associative array of parameters

 333       * @return boolean did we do something?

 334       */
 335  	function AdminEndHtmlHead( & $params )
 336      {
 337          echo '<!-- This comment was added by the TEST plugin -->';
 338  
 339          return true;
 340      }
 341  
 342  
 343      /**

 344       * Event handler: Called right after displaying the admin page footer.

 345       *

 346       * @see Plugin::AdminAfterPageFooter()

 347       * @param array Associative array of parameters

 348       * @return boolean did we do something?

 349       */
 350  	function AdminAfterPageFooter( & $params )
 351      {
 352          echo '<p class="footer">This is the TEST plugin responding to the AdminAfterPageFooter event!</p>';
 353  
 354          return true;
 355      }
 356  
 357  
 358      /**

 359       * Event handler: Called when displaying editor toolbars.

 360       *

 361       * @see Plugin::AdminDisplayToolbar()

 362       * @param array Associative array of parameters

 363       * @return boolean did we display a toolbar?

 364       */
 365  	function AdminDisplayToolbar( & $params )
 366      {
 367          echo '<div class="edit_toolbar">This is the TEST Toolbar</div>';
 368  
 369          return true;
 370      }
 371  
 372  
 373      /**

 374       * Event handler: Called when displaying editor buttons (in back-office).

 375       *

 376       * @see Plugin::AdminDisplayEditorButton()

 377       * @param array Associative array of parameters

 378       * @return boolean did we display ?

 379       */
 380  	function AdminDisplayEditorButton( & $params )
 381      {
 382          if( $params['edit_layout'] == 'simple' )
 383          { // this is the "simple" layout, we do nothing
 384              return false;
 385          }
 386          ?>
 387          <input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (AdminDisplayEditorButton)!');" />
 388          <?php
 389          return true;
 390      }
 391  
 392  
 393      /**

 394       * Event handler: Called when displaying editor buttons (in front-office).

 395       *

 396       * @see Plugin::DisplayEditorButton()

 397       * @param array Associative array of parameters

 398       * @return boolean did we display ?

 399       */
 400  	function DisplayEditorButton( & $params )
 401      {
 402          ?>
 403          <input type="button" value="TEST" onclick="alert('Hi! This is the TEST plugin (DisplayEditorButton)!');" />
 404          <?php
 405          return true;
 406      }
 407  
 408  
 409      /**

 410       * @see Plugin::AdminDisplayItemFormFieldset()

 411       */
 412  	function AdminDisplayItemFormFieldset( & $params )
 413      {
 414          $params['Form']->begin_fieldset( 'TEST plugin' );
 415          $params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the AdminDisplayItemFormFieldset event.' );
 416          $params['Form']->end_fieldset( 'Foo' );
 417      }
 418  
 419  
 420      /**

 421       * @see Plugin::DisplayItemFormFieldset()

 422       */
 423  	function DisplayItemFormFieldset( & $params )
 424      {
 425          $params['Form']->begin_fieldset( 'TEST plugin' );
 426          $params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the DisplayItemFormFieldset event.' );
 427          $params['Form']->end_fieldset( 'Foo' );
 428      }
 429  
 430  
 431      /**

 432       * @see Plugin::SkinBeginHtmlHead()

 433       */
 434  	function SkinBeginHtmlHead()
 435      {
 436          require_js( '#jquery#', 'blog' );
 437      }
 438  
 439  
 440      /**

 441       * @see Plugin::AdminBeforeItemEditCreate()

 442       */
 443  	function AdminBeforeItemEditCreate( & $params )
 444      {
 445          $this->msg( 'This is the TEST plugin responding to the AdminBeforeItemEditCreate event.' );
 446      }
 447  
 448  
 449      /**

 450       * @see Plugin::AdminBeforeItemEditUpdate()

 451       */
 452  	function AdminBeforeItemEditUpdate( & $params )
 453      {
 454          $this->msg( 'This is the TEST plugin responding to the AdminBeforeItemEditUpdate event.' );
 455      }
 456  
 457  
 458      /**

 459       * @see Plugin::AdminDisplayCommentFormFieldset()

 460       */
 461  	function AdminDisplayCommentFormFieldset( & $params )
 462      {
 463          $params['Form']->begin_fieldset( 'TEST plugin' );
 464          $params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin responding to the AdminDisplayCommentFormFieldset event.' );
 465          $params['Form']->end_fieldset( 'Foo' );
 466      }
 467  
 468  
 469      /**

 470       * Event handler: Gets invoked in /toolbar.inc.php after the menu structure is built.

 471       *

 472       * @see Plugin::AdminAfterEvobarInit()

 473       */
 474  	function AdminAfterEvobarInit()
 475      {
 476  
 477          // The following is a tiny bit hackish and should probably be abstracted a bit, but just a little bit

 478          // The idea is too let plugins hook pretty much anywhere into the menu structure, including Left AND Right menus.

 479  
 480          global $topleft_Menu;
 481          $topleft_Menu->add_menu_entries( 'tools', array(
 482                  'urls_sep' => array(
 483                          'separator' => true,
 484                      ),
 485                  'urls' => array(
 486                          'text' => 'Test plugin&hellip;',
 487                          'href' => $this->get_tools_tab_url(),
 488                      ),
 489              ) );
 490  
 491      }
 492  
 493  
 494      /**

 495       * Event handler: Gets invoked in /admin.php for every backoffice page after

 496       *                the menu structure is built. You can use the {@link $AdminUI} object

 497       *                to modify it.

 498       *

 499       * This is the hook to register menu entries. See {@link register_menu_entry()}.

 500       *

 501       * @see Plugin::AdminAfterMenuInit()

 502       */
 503  	function AdminAfterMenuInit()
 504      {
 505          $this->register_menu_entry( 'Test tab' );
 506      }
 507  
 508  
 509      /**

 510       * Event handler: Called when handling actions for the "Tools" menu.

 511       *

 512       * Use {@link $Messages} to add Messages for the user.

 513       *

 514       * @see Plugin::AdminToolAction()

 515       */
 516  	function AdminToolAction( $params )
 517      {
 518          global $Messages;
 519  
 520          $Messages->add( 'Hello, This is the AdminToolAction for the TEST plugin.' );
 521      }
 522  
 523  
 524      /**

 525       * Event handler: Called when displaying the block in the "Tools" menu.

 526       *

 527       * @see Plugin::AdminToolPayload()

 528       */
 529  	function AdminToolPayload( $params )
 530      {
 531          echo 'Hello, This is the AdminToolPayload for the TEST plugin.';
 532      }
 533  
 534  
 535      /**

 536       * Event handler: Method that gets invoked when our tab (?tab=plug_ID_X) is selected.

 537       *

 538       * You should catch params (GET/POST) here and do actions (no output!).

 539       * Use {@link $Messages} to add messages for the user.

 540       *

 541       * @see Plugin::AdminTabAction()

 542       */
 543  	function AdminTabAction()
 544      {
 545          global $Plugins;
 546  
 547          $this->text_from_AdminTabAction = '<p>This is text from AdminTabAction for the TEST plugin.</p>'
 548              .'<p>Here is a random number: '
 549              .$Plugins->get_trigger_event_first_return('test_plugin_get_random', array( 'min'=>-1000, 'max'=>1000 )).'</p>';
 550  
 551          if( $this->param_text = param( $this->get_class_id('text') ) )
 552          {
 553              $this->text_from_AdminTabAction .= '<p>You have said: '.$this->param_text.'</p>';
 554          }
 555      }
 556  
 557  
 558      /**

 559       * Event handler: Gets invoked when our tab is selected and should get displayed.

 560       *

 561       * @see Plugin::AdminTabPayload()

 562       */
 563  	function AdminTabPayload()
 564      {
 565          echo 'Hello, this is the AdminTabPayload for the TEST plugin.';
 566  
 567          echo $this->text_from_AdminTabAction;
 568  
 569          // TODO: this is tedious.. should either be a global function (get_admin_Form()) or a plugin helper..

 570          $Form = new Form();
 571          $Form->begin_form();
 572  
 573          $Form->add_crumb( 'plugin_test' );
 574          $Form->hidden_ctrl(); // needed to pass the "ctrl=tools" param

 575          $Form->hiddens_by_key( get_memorized() ); // needed to pass all other memorized params, especially "tab"

 576  
 577          $Form->text_input( $this->get_class_id().'_text', $this->param_text, '20', 'Text' );
 578  
 579          $Form->button_input(); // default "submit" button

 580  
 581          $Form->end_form();
 582      }
 583  
 584  
 585      /**

 586       * Event handler: Gets invoked before the main payload in the backoffice.

 587       *

 588       * @see Plugin::AdminBeginPayload()

 589       */
 590  	function AdminBeginPayload()
 591      {
 592          global $Plugins;
 593  
 594          echo '<div class="panelblock center">TEST plugin: AdminBeginPayload event.</div>';
 595  
 596          if( $this->UserSettings->get('echo_random') )
 597          {
 598              echo '<div class="panelblock center">TEST plugin: A random number requested by user setting: '
 599                      .$Plugins->get_trigger_event_first_return('test_plugin_get_random', array( 'min'=>0, 'max'=>1000 ) ).'</div>';
 600          }
 601      }
 602  
 603  
 604      /**

 605       * Event handler: Called when rendering item/post contents as HTML.

 606       *

 607       * Note: return value is ignored. You have to change $params['data'].

 608       *

 609       * @see Plugin::RenderItemAsHtml()

 610       */
 611  	function RenderItemAsHtml( & $params )
 612      {
 613          $params['data'] = 'TEST['.$params['data'].']TEST';
 614      }
 615  
 616  
 617      /**

 618       * Event handler: Called when rendering item/post contents as XML.

 619       *

 620       * Note: return value is ignored. You have to change $params['data'].

 621       *

 622       * @see Plugin::RenderItemAsXml()

 623       */
 624  	function RenderItemAsXml( & $params )
 625      {
 626          // Do the same as with HTML:

 627          $this->RenderItemAsHtml( $params );
 628      }
 629  
 630  
 631      /**

 632       * Event handler: Called when rendering item/post contents as text.

 633       *

 634       * Note: return value is ignored. You have to change $params['data'].

 635       *

 636       * @see Plugin::RenderItemAsText()

 637       */
 638  	function RenderItemAsText( & $params )
 639      {
 640          // Do nothing.

 641      }
 642  
 643  
 644      /**

 645       * Event handler: Called when displaying item/post contents as HTML.

 646       *

 647       * Note: return value is ignored. You have to change $params['data'].

 648       *

 649       * @see Plugin::DisplayItemAsHtml()

 650       */
 651  	function DisplayItemAsHtml( & $params )
 652      {
 653          $params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsHtml()";
 654      }
 655  
 656  
 657      /**

 658       * Event handler: Called when displaying item/post contents as XML.

 659       *

 660       * Note: return value is ignored. You have to change $params['data'].

 661       *

 662       * @see Plugin::DisplayItemAsXml()

 663       */
 664  	function DisplayItemAsXml( & $params )
 665      {
 666          $params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsXml()";
 667      }
 668  
 669  
 670      /**

 671       * Event handler: Called when displaying item/post contents as text.

 672       *

 673       * Note: return value is ignored. You have to change $params['data'].

 674       *

 675       * @see Plugin::DisplayItemAsText()

 676       */
 677  	function DisplayItemAsText( & $params )
 678      {
 679          $params['data'] = $params['data']."\n<br />-- test_plugin::DisplayItemAsText()";
 680      }
 681  
 682  
 683      /**

 684       * Wrap a to be displayed IP address.

 685       * @see Plugin::FilterIpAddress()

 686       */
 687  	function FilterIpAddress( & $params )
 688      {
 689          $params['data'] = '[[IP:'.$params['data'].' (TEST plugin)]]';
 690      }
 691  
 692  
 693      /**

 694       * Event handler: Called before the plugin is installed.

 695       * @see Plugin::BeforeInstall()

 696       */
 697  	function BeforeInstall()
 698      {
 699          global $Plugins;
 700          $this->msg( 'TEST plugin: BeforeInstall event.' );
 701          return true;
 702      }
 703  
 704  
 705      /**

 706       * Event handler: Called when the plugin has been installed.

 707       * @see Plugin::AfterInstall()

 708       */
 709  	function AfterInstall()
 710      {
 711          $this->msg( 'TEST plugin sucessfully installed. All the hard work we did was adding this message in the AfterInstall event.. ;)' );
 712      }
 713  
 714  
 715      /**

 716       * Event handler: Called before the plugin is going to be un-installed.

 717       * @see Plugin::BeforeUninstall()

 718       */
 719  	function BeforeUninstall()
 720      {
 721          $this->msg( 'TEST plugin sucessfully un-installed. All the hard work we did was adding this message.. ;)' );
 722          return true;
 723      }
 724  
 725  
 726      /**

 727       * Event handler: called when a new user has registered.

 728       * @see Plugin::AfterUserRegistration()

 729       */
 730  	function AfterUserRegistration( $params )
 731      {
 732          $this->msg( 'The TEST plugin welcomes the new user '.$params['User']->dget('login').'!' );
 733      }
 734  
 735  
 736      /**

 737       * Event handler: Called at the end of the "Login" form.

 738       * @see Plugin::DisplayLoginFormFieldset()

 739       */
 740  	function DisplayLoginFormFieldset( & $params )
 741      {
 742          $params['Form']->info_field( 'TEST plugin', 'This is the TEST plugin hooking the DisplayLoginFormFieldset event.' );
 743      }
 744  
 745  
 746      /**

 747       * Event handler: Called when a user tries to login.

 748       * @see Plugin::LoginAttempt()

 749       */
 750  	function LoginAttempt()
 751      {
 752          $this->msg( 'This is the TEST plugin responding to the LoginAttempt event.', 'note' );
 753      }
 754  
 755  
 756      /**

 757       * Event handler: Do we need a raw password in {@link LoginAttempt()}?

 758       * @see Plugin::LoginAttemptNeedsRawPassword()

 759       */
 760  	function LoginAttemptNeedsRawPassword()
 761      {
 762          return false;    // No we don't need raw. (do not implement this method if the answer is no)

 763      }
 764  
 765  
 766      /**

 767       * Automagically login every user as "demouser" who is not logged in and does not

 768       * try to currently.

 769       *

 770       * To enable/test it, change the "if-0" check below to "if( 1 )".

 771       *

 772       * @see Plugin::AlternateAuthentication()

 773       */
 774  	function AlternateAuthentication()
 775      {
 776          if( 0 ) // you should only enable it for test purposes, because it automagically logs every user in as "demouser"!
 777          {
 778              global $Session, $Messages;
 779  
 780              $UserCache = & get_UserCache();
 781              if( $demo_User = & $UserCache->get_by_login('demouser') )
 782              { // demouser exists:
 783                  $Session->set_User( $demo_User );
 784                  $Messages->add( 'Logged in as demouser.', 'success' );
 785                  return true;
 786              }
 787          }
 788      }
 789  
 790  
 791      /**

 792       * @see Plugin::DisplayValidateAccountFormFieldset()

 793       */
 794  	function DisplayValidateAccountFormFieldset( & $params )
 795      {
 796          $params['Form']->info( 'TEST plugin', 'This is the TEST plugin responding to the ValidateAccountFormSent event.' );
 797      }
 798  
 799  
 800      /**

 801       * Gets provided as plugin event (and gets also used internally for demonstration).

 802       *

 803       * @param array Associative array of parameters

 804       *              'min': mininum number

 805       *              'max': maxinum number

 806       * @return integer

 807       */
 808  	function test_plugin_get_random( & $params )
 809      {
 810          return rand( $params['min'], $params['max'] );
 811      }
 812  
 813  
 814      /**

 815       * Return list of custom disp types handled by this plugin

 816       *

 817       * @return array list of disp modes handled by this plugin

 818       */
 819  	function GetHandledDispModes()
 820      {
 821          return array(
 822                  'disp_test', // display our test disp
 823              );
 824      }
 825  
 826  
 827      /**

 828       * Display our custom disp mode(s)

 829       *

 830       * @param mixed array $params

 831       *         disp > display mode requested

 832       *

 833       * @return did we display?

 834       */
 835  	function HandleDispMode( $params )
 836      {
 837          echo '<p>This is the test plugin handling the ['.$params['disp'].'] disp mode.</p>';
 838      }
 839  
 840  
 841      /**

 842       * @see Plugin::BeforeSessionsDelete()

 843       */
 844  	function BeforeSessionsDelete( $params )
 845      {
 846          $this->debug_log('BeforeSessionsDelete: Could have prevented the deletion of all sessions older than ' ).date('Y-m-d H:i:s', $params['cutoff_timestamp' ] );
 847          return;
 848      }
 849  
 850  
 851      /**

 852       * Event handler: Defines blog kinds, their names and description.

 853       * Define blog settings in {@link Plugin::InitCollectionKinds()} method of your plugin.

 854       *

 855       * Note: You can change default blog kinds $params['default_kinds'] (which get passed by reference).

 856       *

 857       * @param array Associative array of parameters

 858       *   - 'kinds': dafault blog kinds (by reference)

 859       * @retun: array

 860       */
 861  	function GetCollectionKinds( & $params )
 862      {
 863          $params['kinds'] = array_merge( $params['kinds'], array(
 864                  'test_kind' => array(
 865                      'name' => 'Just another blog type',
 866                      'desc' => 'This is the TEST plugin handling the GetCollectionKinds event.',
 867                  ),
 868                  'std' => array( // override standard blog settings
 869                      'name' => 'Non-standard blog',
 870                      'desc' => 'Description is changed by TEST plugin.',
 871                  ),
 872              ) );
 873  
 874          return $params['kinds'];
 875      }
 876  
 877  
 878      /**

 879       * Event handler: Defines blog settings by its kind. Use {@link get_collection_kinds()} to return

 880       * an array of available blog kinds and their names.

 881       * Define new blog kinds in {@link Plugin::GetCollectionKinds()} method of your plugin.

 882       *

 883       * Note: You have to change $params['Blog'] (which gets passed by reference).

 884       *

 885       * @param array Associative array of parameters

 886       *   - 'Blog': created Blog (by reference)

 887       *   - 'kind': the kind of created blog (by reference)

 888       */
 889  	function InitCollectionKinds( & $params )
 890      {
 891          // Load blog functions

 892          load_funcs( 'collections/model/_blog.funcs.php' );
 893  
 894          // Get all available blog kinds

 895          $kinds = get_collection_kinds();
 896  
 897          switch( $params['kind'] )
 898          {
 899              case 'std': // override standard blog settings
 900                  $params['Blog']->set( 'name', $kinds[$params['kind']]['name'] );
 901                  break;
 902  
 903              case 'test_kind':
 904                  $params['Blog']->set( 'name', $kinds[$params['kind']]['name'] );
 905                  $params['Blog']->set( 'shortname', 'Test blog' );
 906                  break;
 907          }
 908      }
 909  
 910  
 911      /**

 912       * Event handler: called at the end of {@link DataObject::dbinsert() inserting an object in the database}.

 913       *

 914       * @param array Associative array of parameters

 915       *   - 'Object': the related Object (by reference)

 916       *   - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)

 917       */
 918  	function AfterObjectInsert( & $params )
 919      {
 920          $this->msg( sprintf('This is the TEST plugin responding to the AfterObjectInsert event. You have just created new [%s]', $params['type']), 'note' );
 921      }
 922  
 923  
 924      /**

 925       * Event handler: called at the end of {@link DataObject::dbupdate() updating an object in the database}.

 926       *

 927       * @param array Associative array of parameters

 928       *   - 'Object': the related Object (by reference)

 929       *   - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)

 930       */
 931  	function AfterObjectUpdate( & $params )
 932      {
 933          $this->msg( sprintf('This is the TEST plugin responding to the AfterObjectUpdate event. You have just changed a [%s]', $params['type']), 'note' );
 934      }
 935  
 936  
 937      /**

 938       * Event handler: called at the end of {@link DataObject::dbdelete() deleting an object from the database}.

 939       *

 940       * @param array Associative array of parameters

 941       *   - 'Object': the related Object (by reference)

 942       *   - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)

 943       */
 944  	function AfterObjectDelete( & $params )
 945      {
 946          $this->msg( sprintf('This is the TEST plugin responding to the AfterObjectDelete event. You have just deleted a [%s]', $params['type']), 'note' );
 947      }
 948  
 949  
 950      /**

 951       * Event handler: Called when a MainList object gets created.

 952       *

 953       * Note: you must create your own MainList object here, set filters and query the database, see init_MainList() for detailes.

 954       *

 955       * @param array Associative array of parameters

 956       *   - 'MainList': The "MainList" object (by reference).

 957       *   - 'limit': The number of posts to display

 958       *

 959       * @return boolean True if you've created your own MainList object and queried the database, false otherwise.

 960       */
 961  	function InitMainList( & $params )
 962      {
 963          global $Blog;
 964          global $preview, $disp;
 965          global $postIDlist, $postIDarray, $cat_array;
 966  
 967          $params['MainList'] = new ItemList2( $Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), $params['limit'] ); // COPY (FUNC)

 968  
 969          if( ! $preview )
 970          {
 971              if( $disp == 'page' )
 972              {    // Get pages:
 973                  $params['MainList']->set_default_filters( array(
 974                          'types' => '1000',        // pages
 975                      ) );
 976              }
 977  
 978              if( $disp == 'search' && param('s', 'string') )
 979              {    // Here we allow b2evolution to search in posts and in pages
 980                  $this->msg( 'TEST plugin: InitMainList() method allows us to search in both posts and pages.', 'note' );
 981  
 982                  $params['MainList']->set_default_filters( array(
 983                          'types' => '1,1000',
 984                      ) );
 985              }
 986  
 987              $params['MainList']->load_from_Request( false );
 988  
 989              // Save aggregate setting

 990              $saved_aggregate_state = $Blog->get_setting( 'aggregate_coll_IDs' );
 991  
 992              if( $disp == 'posts' && !empty($params['MainList']->filters['tags']) )
 993              {    // If the MainList if filtered by tag we search for posts in all public blogs
 994                  if( !empty($params['MainList']->filters['tags']) )
 995                  {    // All public blogs
 996                      $BlogCache = & get_BlogCache();
 997                      $Blog->set_setting( 'aggregate_coll_IDs', implode( ',', $BlogCache->load_public() ) );
 998  
 999                      $this->msg( 'TEST plugin: InitMainList() method allows us to display tagged posts from all public blogs.', 'note' );
1000                  }
1001              }
1002  
1003              // Run the query:

1004              $params['MainList']->query();
1005  
1006              // Restore aggregate setting to its original value

1007              $Blog->set_setting( 'aggregate_coll_IDs', $saved_aggregate_state );
1008  
1009              // Old style globals for category.funcs:

1010              $postIDlist = $params['MainList']->get_page_ID_list();
1011              $postIDarray = $params['MainList']->get_page_ID_array();
1012          }
1013          else
1014          {    // We want to preview a single post, we are going to fake a lot of things...
1015              $params['MainList']->preview_from_request();
1016  
1017              // Legacy for the category display

1018              $cat_array = array();
1019          }
1020  
1021          return true; // This is required!

1022      }
1023  }
1024  
1025  ?>

title

Description

title

Description

title

Description

title

title

Body