Commit 28189ac72d2e3a1f1157189b44cb67ad24c87cf2

Authored by Neil Blakey-Milner
1 parent 525653e7

Univeral access to actions - looks them up by name and calls their

dispatcher.  Makes it easy for plugins to register actions without
installing files in the KnowledgeTree code itself, nor exposing their
code for direct access.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3933 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 60 additions and 0 deletions
action.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once('config/dmsDefaults.php');
  4 +require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php');
  5 +require_once(KT_LIB_DIR . '/dispatcher.inc.php');
  6 +
  7 +/*
  8 + * Using KTStandardDispatcher for errorPage, overriding handleOutput as
  9 + * the document action dispatcher will handle that.
  10 + */
  11 +
  12 +/**
  13 + * Dispatcher for action.php/actionname
  14 + *
  15 + * This dispatcher looks up the action from the Action Registry, and
  16 + * then chains onto that action's dispatcher.
  17 + */
  18 +class KTActionDispatcher extends KTStandardDispatcher {
  19 + /**
  20 + * Default dispatch
  21 + *
  22 + * Find the action, and then use its dispatcher. Error out nicely
  23 + * if we aren't so lucky.
  24 + */
  25 + function do_main() {
  26 + $this->error = false;
  27 + $action = KTUtil::arrayGet($_SERVER, 'PATH_INFO');
  28 + $action = trim($action);
  29 + $action = trim($action, "/");
  30 + if (empty($action)) {
  31 + $this->error = true;
  32 + $this->errorPage("No action given");
  33 + }
  34 + $oRegistry =& KTActionRegistry::getSingleton();
  35 + $aActionInfo = $oRegistry->getActionByNsname($action);
  36 + if (empty($aActionInfo)) {
  37 + $this->error = true;
  38 + $this->errorPage("No such action exists in KnowledgeTree");
  39 + }
  40 + $oAction = new $aActionInfo[0];
  41 + $oAction->dispatch();
  42 + }
  43 +
  44 + /**
  45 + * Handle output from this dispatcher.
  46 + *
  47 + * If there's an error in _this_ dispatcher, use the standard
  48 + * surroundings. If not, don't put anything around the output - the
  49 + * chained dispatcher will take care of that.
  50 + */
  51 + function handleOutput ($data) {
  52 + if ($this->error) {
  53 + parent::handleOutput($data);
  54 + } else {
  55 + print $data;
  56 + }
  57 + }
  58 +}
  59 +$d = new KTActionDispatcher();
  60 +$d->dispatch();