diff --git a/lib/actions/actionregistry.inc.php b/lib/actions/actionregistry.inc.php new file mode 100644 index 0000000..c13c6d9 --- /dev/null +++ b/lib/actions/actionregistry.inc.php @@ -0,0 +1,24 @@ +actions[$slot] = KTUtil::arrayGet($this->actions, $slot, array()); + $this->actions[$slot][$nsname] = array($name, $path); + } + + function getActions($slot) { + return $this->actions[$slot]; + } +} + +?> diff --git a/lib/actions/documentaction.inc.php b/lib/actions/documentaction.inc.php new file mode 100644 index 0000000..25dce55 --- /dev/null +++ b/lib/actions/documentaction.inc.php @@ -0,0 +1,108 @@ +oDocument = $oDocument; + $this->oUser = $oUser; + } + + function _show() { + if (is_null($this->_sShowPermission)) { + return true; + } + $oPermission =& KTPermission::getByName($this->_sShowPermission); + if (PEAR::isError($oPermission)) { + return true; + } + return KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument); + } + + function _disable() { + if ($this->_bDisabled === true) { + return true; + } + if (is_null($this->_sDisablePermission)) { + return false; + } + $oPermission =& KTPermission::getByName($this->_sDisablePermission); + if (PEAR::isError($oPermission)) { + return false; + } + $bResult = KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument); + if ($bResult === false) { + $this->_sDisabledText = "Insufficient privileges"; + } + return !$bResult; + } + + function getURL() { + return sprintf("/plugin.php/%s?fDocumentID=%d", $this->sName, $this->oDocument->getID()); + } + + function getInfo() { + if ($this->_show() === false) { + return null; + } + + $aInfo = array( + 'disabled' => $this->_disable(), + 'description' => $this->sDescription, + 'name' => $this->sDisplayName, + 'url' => generateLink($this->getURL(), ""), + 'disabled_text' => $this->_sDisabledText, + ); + return $this->customiseInfo($aInfo); + } + + function customiseInfo($aInfo) { + return $aInfo; + } +} + +class KTDocumentActionUtil { + function getDocumentActions() { + $oRegistry =& KTActionRegistry::getSingleton(); + return $oRegistry->getActions('documentaction'); + } + function &getDocumentActionsForDocument($oDocument, $oUser) { + $aObjects = array(); + foreach (KTDocumentActionUtil::getDocumentActions() as $aAction) { + list($sClassName, $sPath) = $aAction; + if (!empty($sPath)) { + // require_once(KT_DIR . + // Or something... + } + $aObjects[] =& new $sClassName($oDocument, $oUser); + } + return $aObjects; + } +} + +class KTBuiltInDocumentAction extends KTDocumentAction { + var $sBuildInAction; + function getURL() { + return sprintf("/control.php?action=%s&fDocumentID=%d", $this->sBuiltInAction, $this->oDocument->getID()); + } +} + +class KTBuiltInDocumentActionSingle extends KTBuiltInDocumentAction { + function getURL() { + return sprintf("/control.php?action=%s&fDocumentIDs[]=%d&fReturnDocumentID=%d", $this->sBuiltInAction, $this->oDocument->getID(), $this->oDocument->getID()); + } +} + +/* require_once(KT_DIR . '/plugins/ktcore/documentaction.inc.php'); */ + +?>