Overview

Create a front-end UI hooks system, ala WordPress and Drupal.

Issues

How to include custom css? javascript? images?

Lazy loading versus always loading? (requires perf testing)

What if there is required configuration?

Limiting the hooking depth?

Localization?

Current Progress

Created simple class for hooking into events. Where to allow user plugins?

Hook Locations

Locations in blue have been implemented. This is an idea list.

  • Special Pages (SPECIAL_PAGE)
    • Enables creating new special pages
    • hook($pageName, &$pageTitle, &$html)
      • SPECIAL_POPULAR_PAGES, SPECIAL_TAGS, SPECIAL_SITEMAP
  • Rss Feed Creation
  • Diff Viewer
  • Comment Parser (askismet support)
  • Navigation pane
  • Title parsing (MAIN_PROCESS_TITLE)
    • (mdc redirects, sitemap.xml)
      • Allows title to be rewritten or handled specially before the app can handle them
      • hook(&$Request, &$Title)
  • Image Gallery
  • File Listing
  • Editor loading (EDITOR_LOAD)
    • Allows different editors based on content type
    • Still needs some work to allow the plugins more control
  • Editor saving (PAGE_SAVE)
    • Gets article object with all information about the page after saving.
    • hook($Article)
  • User Logout  (MAIN_LOGOUT, MAIN_LOGOUT_COMPLETE)
    • Allows the user to be processed before and after logout
    • hook($User)

 

Creating A Hook

When creating a hook the developer needs to control the objects/primitives that get passed to the plugin. Below outlines the possible ways.

Objects by value
DekiPlugin::executeHook(Hooks::XXX, array(clone $Object));
Objects by reference
DekiPlugin::executeHook(Hooks::XXX, array($Object));
Primitives by value
DekiPlugin::executeHook(Hooks::XXX, array($string));
Primitives by reference
DekiPlugin::executeHook(Hooks::XXX, array(&$string));

 

Notes from an email

I changed how the return values affect plugin execution. Before the
return values were boolean, now they are integer codes.

By default you do not have to return anything.  However if you want to
enforce additional functionality then the return codes are required.


Examples:

When this executes additional plugins will also be called, however, the
default handler, if any, may not be executed.

<?php myPluginFunction() { // does something } ?>


This is the same as above. Default return value.
<?php myPluginFunction() { return DekiPlugin::HANDLED; } ?>


After this plugin is called, no additional plugins for the hook will be
executed.
<?php myPluginFunction() { return DekiPlugin::HANDLED_HALT; } ?>


When unhandled is returned, the point in the code where the hook is
called can see if any plugins actually did anything.  If the unhandled
code is returned then any default actions can check for this code and
perform default actions.
<?php myPluginFunction() { return DekiPlugin::UNHANDLED; } ?>


There is a fourth status code UNREGISTERED which is returned if no
plugins are registered with a hook.
<?php
  $result = DekiPlugin::executeHook(XXX, array());

  if ($result == DekiPlugin::UNHANDLED || $result == DekiPlugin::UNREGISTERED) { // default actions }
?>


With this new return format, we should have more granular control over
how the plugins are executed. 

 

Tag page
You must login to post a comment.