Beispiele > Einfaches Widget

Datei: plugins/example.hellowidget.php

Quellcode
Darstellung:
  1. <?php
  2. /**
  3.  * Plugin example: Hello widget
  4.  *
  5.  */
  6. class HelloWidgetExample extends BMPlugin 
  7. {
  8.    function HelloWidgetExample()
  9.    {
  10.       $this->name             'Hello widget example';
  11.       $this->author           'B1G Software';
  12.       $this->web              'http://www.b1g.de';
  13.       $this->mail             'info@b1g.de';
  14.       $this->version          '1.1';
  15.       $this->designedfor         '7.2.0';
  16.       $this->type             BMPLUGIN_WIDGET;
  17.       
  18.       $this->widgetTitle         'Hello!';
  19.       $this->widgetTemplate      'hello.widget.tpl';
  20.       $this->widgetIcon       'widget_welcome.png';
  21.       $this->widgetPrefs         true;
  22.       $this->widgetPrefsWidth    320;
  23.       $this->widgetPrefsHeight   100;
  24.    }
  25.    
  26.    function isWidgetSuitable($for)
  27.    {
  28.       return($for == BMWIDGET_START);
  29.    }
  30.    
  31.    function renderWidget()
  32.    {
  33.       global $tpl$userRow$thisUser;
  34.       
  35.       $tpl->assign('hello_fullname'$userRow['vorname'] . ' ' $userRow['nachname']);
  36.       $tpl->assign('hello_testSetting'$thisUser->GetPref('helloWidget.testSetting'));
  37.    }
  38.  
  39.    function renderWidgetPrefs()
  40.    {
  41.       global $tpl$thisUser;
  42.  
  43.       if(isset($_POST['save']))
  44.       {
  45.          $thisUser->SetPref('helloWidget.testSetting', isset($_POST['testSetting']));
  46.          $this->_closeWidgetPrefs(true);
  47.       }
  48.       else
  49.       {
  50.          $tpl->assign('testSetting'$thisUser->GetPref('helloWidget.testSetting'));
  51.          $tpl->display($this->_templatePath('hello.widget.prefs.tpl'));
  52.       }
  53.    }
  54. }
  55.  
  56. /**
  57.  * register plugin
  58.  */
  59. $plugins->registerPlugin('HelloWidgetExample');
  60. ?>