PLUGINS.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Plugins
  2. =======
  3. GNU social supports a simple but
  4. powerful plugin architecture. Important events in the code are named,
  5. like 'StartNoticeSave', and other software can register interest
  6. in those events. When the events happen, the other software is called
  7. and has a choice of accepting or rejecting the events.
  8. In the simplest case, you can add a function to config.php and use the
  9. Event::addHandler() function to hook an event:
  10. function AddGoogleLink($action)
  11. {
  12. $action->menuItem('http://www.google.com/', _('Google'), _('Search engine'));
  13. return true;
  14. }
  15. Event::addHandler('EndPrimaryNav', 'AddGoogleLink');
  16. This adds a menu item to the end of the main navigation menu. You can
  17. see the list of existing events, and parameters that handlers must
  18. implement, in EVENTS.txt.
  19. The Plugin class in lib/plugin.php makes it easier to write more
  20. complex plugins. Sub-classes can just create methods named
  21. 'onEventName', where 'EventName' is the name of the event (case
  22. matters!). These methods will be automatically registered as event
  23. handlers by the Plugin constructor (which you must call from your own
  24. class's constructor).
  25. Several example plugins are included in the plugins/ directory. You
  26. can enable a plugin with the following line in config.php:
  27. addPlugin('Example', array('param1' => 'value1',
  28. 'param2' => 'value2'));
  29. This will look for and load files named 'ExamplePlugin.php' or
  30. 'Example/ExamplePlugin.php' either in the plugins/ directory (for
  31. plugins that ship with GNU social) or in the local/ directory (for
  32. plugins you write yourself or that you get from somewhere else) or
  33. local/plugins/.
  34. Plugins are documented in their own directories.