CODE STYLE class.pluginRegistry.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 12:55:14 -04:00
parent b7b062bdec
commit 7f1d0fad9c

View File

@@ -1,6 +1,8 @@
<?php
/**
* class.pluginRegistry.php
*
* @package workflow.engine.classes
*
* ProcessMaker Open Source Edition
@@ -23,12 +25,13 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
/**
*
* @package workflow.engine.classes
*/
class pluginDetail {
class pluginDetail
{
var $sNamespace;
var $sClassName;
var $sFriendlyName = null;
@@ -44,6 +47,7 @@ class pluginDetail {
/**
* This function is the constructor of the pluginDetail class
*
* @param string $sNamespace
* @param string $sClassName
* @param string $sFilename
@@ -54,7 +58,8 @@ class pluginDetail {
* @param integer $iVersion
* @return void
*/
function __construct( $sNamespace, $sClassName, $sFilename, $sFriendlyName = '', $sPluginFolder ='', $sDescription ='', $sSetupPage ='', $iVersion = 0) {
function __construct ($sNamespace, $sClassName, $sFilename, $sFriendlyName = '', $sPluginFolder = '', $sDescription = '', $sSetupPage = '', $iVersion = 0)
{
$this->sNamespace = $sNamespace;
$this->sClassName = $sClassName;
$this->sFriendlyName = $sFriendlyName;
@@ -70,10 +75,12 @@ class pluginDetail {
}
/**
*
* @package workflow.engine.classes
*/
class PMPluginRegistry {
class PMPluginRegistry
{
private $_aPluginDetails = array ();
private $_aPlugins = array ();
private $_aMenus = array ();
@@ -100,21 +107,26 @@ class PMPluginRegistry {
*/
private $_restServices = array ();
static private $instance = NULL;
private static $instance = NULL;
/**
* This function is the constructor of the PMPluginRegistry class
* param
*
* @return void
*/
public function __construct() {}
public function __construct ()
{
}
/**
* This function is instancing to this class
* param
*
* @return object
*/
function &getSingleton() {
function &getSingleton ()
{
if (self::$instance == NULL) {
self::$instance = new PMPluginRegistry();
}
@@ -124,18 +136,22 @@ class PMPluginRegistry {
/**
* This function generates a storable representation of a value
* param
*
* @return void
*/
function serializeInstance() {
function serializeInstance ()
{
return serialize( self::$instance );
}
/**
* This function takes a single serialized variable and converts it back a code
*
* @param string $serialized
* @return void
*/
function unSerializeInstance( $serialized ) {
function unSerializeInstance ($serialized)
{
if (self::$instance == NULL) {
self::$instance = new PMPluginRegistry();
}
@@ -146,9 +162,9 @@ class PMPluginRegistry {
/**
* Save the current instance to the plugin singleton
*
*/
function save() {
function save ()
{
file_put_contents( PATH_DATA_SITE . 'plugin.singleton', $this->serializeInstance() );
}
@@ -166,15 +182,7 @@ class PMPluginRegistry {
return;
//require_once ( $sFilename );
$plugin = new $sClassName( $sNamespace, $sFilename );
$detail = new pluginDetail (
$sNamespace,
$sClassName,
$sFilename,
$plugin->sFriendlyName,
$plugin->sPluginFolder,
$plugin->sDescription,
$plugin->sSetupPage,
$plugin->iVersion );
$detail = new pluginDetail( $sNamespace, $sClassName, $sFilename, $plugin->sFriendlyName, $plugin->sPluginFolder, $plugin->sDescription, $plugin->sSetupPage, $plugin->iVersion );
if (isset( $plugin->aWorkspaces ))
$detail->aWorkspaces = $plugin->aWorkspaces;
if (isset( $plugin->bPrivate ))
@@ -190,7 +198,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sFilename
*/
function getPluginDetails( $sFilename ) {
function getPluginDetails ($sFilename)
{
foreach ($this->_aPluginDetails as $key => $row) {
if ($sFilename == baseName( $row->sFilename ))
return $row;
@@ -203,7 +212,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sNamespace
*/
function enablePlugin($sNamespace ) {
function enablePlugin ($sNamespace)
{
foreach ($this->_aPluginDetails as $namespace => $detail) {
if ($sNamespace == $namespace) {
$this->registerFolder( $sNamespace, $sNamespace, $detail->sPluginFolder ); //register the default directory, later we can have more
@@ -313,7 +323,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sNamespace
*/
function getStatusPlugin($sNamespace ) {
function getStatusPlugin ($sNamespace)
{
foreach ($this->_aPluginDetails as $namespace => $detail) {
if ($sNamespace == $namespace)
if ($this->_aPluginDetails[$sNamespace]->enabled)
@@ -325,12 +336,14 @@ class PMPluginRegistry {
}
/**
* Install a plugin archive. If pluginName is specified, the archive will
* Install a plugin archive.
* If pluginName is specified, the archive will
* only be installed if it contains this plugin.
*
* @return bool true if enabled, false otherwise
*/
function installPluginArchive($filename, $pluginName) {
function installPluginArchive ($filename, $pluginName)
{
G::LoadThirdParty( "pear/Archive", "Tar" );
$tar = new Archive_Tar( $filename );
@@ -375,6 +388,7 @@ class PMPluginRegistry {
//$pluginIni = $tar->extractInString("$pluginName.ini");
//$pluginConfig = parse_ini_string($pluginIni);
/*
if (!empty($oClass->aDependences)) {
foreach ($oClass->aDependences as $aDependence) {
@@ -450,7 +464,8 @@ class PMPluginRegistry {
}
///////
$this->uninstallPluginWorkspaces(array($sNamespace));
$this->uninstallPluginWorkspaces( array ($sNamespace
) );
///////
break;
@@ -473,6 +488,7 @@ class PMPluginRegistry {
//Here we are loading all plug-ins registered
//The singleton has a list of enabled plug-ins
$pluginRegistry = &PMPluginRegistry::getSingleton();
$pluginRegistry->unSerializeInstance( file_get_contents( $wsPathDataSite . "plugin.singleton" ) );
@@ -496,7 +512,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sNamespace
*/
function installPlugin($sNamespace ) {
function installPlugin ($sNamespace)
{
try {
foreach ($this->_aPluginDetails as $namespace => $detail) {
if ($sNamespace == $namespace) {
@@ -505,14 +522,13 @@ class PMPluginRegistry {
$oPlugin->install();
}
}
}
catch ( Exception $e ) {
} catch (Exception $e) {
global $G_PUBLISH;
$aMessage['MESSAGE'] = $e->getMessage();
$G_PUBLISH = new Publisher;
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
G::RenderPage( 'publish' );
die;
die();
}
}
@@ -524,7 +540,8 @@ class PMPluginRegistry {
* @param unknown_type $sMenuId
* @param unknown_type $sFilename
*/
function registerMenu($sNamespace, $sMenuId, $sFilename ) {
function registerMenu ($sNamespace, $sMenuId, $sFilename)
{
$found = false;
foreach ($this->_aMenus as $row => $detail) {
if ($sMenuId == $detail->sMenuId && $sNamespace == $detail->sNamespace)
@@ -541,7 +558,8 @@ class PMPluginRegistry {
*
* @param unknown_type $className
*/
function registerDashlets($namespace) {
function registerDashlets ($namespace)
{
$found = false;
foreach ($this->_aDashlets as $row => $detail) {
if ($namespace == $detail) {
@@ -559,7 +577,8 @@ class PMPluginRegistry {
* @param unknown_type $sNamespace
* @param unknown_type $sPage
*/
function registerCss($sNamespace, $sCssFile ) {
function registerCss ($sNamespace, $sCssFile)
{
$found = false;
foreach ($this->_aCSSStyleSheets as $row => $detail) {
if ($sCssFile == $detail->sCssFile && $sNamespace == $detail->sNamespace) {
@@ -578,7 +597,8 @@ class PMPluginRegistry {
*
* @return array
*/
function getRegisteredCss() {
function getRegisteredCss ()
{
return $this->_aCSSStyleSheets;
}
@@ -589,7 +609,8 @@ class PMPluginRegistry {
* @param string $coreJsFile
* @param array/string $pluginJsFile
*/
function registerJavascript($sNamespace, $sCoreJsFile, $pluginJsFile) {
function registerJavascript ($sNamespace, $sCoreJsFile, $pluginJsFile)
{
foreach ($this->_aJavascripts as $i => $js) {
if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) {
@@ -627,18 +648,20 @@ class PMPluginRegistry {
*
* @return array
*/
function getRegisteredJavascript() {
function getRegisteredJavascript ()
{
return $this->_aJavascripts;
}
/**
* return all plugin javascripts given a core js file, from all namespaces or a single namespace
*
* @param string $sCoreJsFile
* @param string $sNamespace
* @return array
*/
function getRegisteredJavascriptBy($sCoreJsFile, $sNamespace='') {
function getRegisteredJavascriptBy ($sCoreJsFile, $sNamespace = '')
{
$scripts = array ();
if ($sNamespace == '') {
@@ -657,14 +680,15 @@ class PMPluginRegistry {
return $scripts;
}
/**
* unregister all javascripts from a namespace or a js core file given
*
* @param string $sNamespace
* @param string $sCoreJsFile
* @return array
*/
function unregisterJavascripts($sNamespace, $sCoreJsFile='') {
function unregisterJavascripts ($sNamespace, $sCoreJsFile = '')
{
if ($sCoreJsFile == '') { // if $sCoreJsFile=='' unregister all js from this namespace
foreach ($this->_aJavascripts as $i => $js) {
if ($sNamespace == $js->sNamespace) {
@@ -684,7 +708,6 @@ class PMPluginRegistry {
}
}
/**
* Register a reports class in the singleton
*
@@ -692,7 +715,8 @@ class PMPluginRegistry {
* @param unknown_type $sMenuId
* @param unknown_type $sFilename
*/
function registerReport($sNamespace ) {
function registerReport ($sNamespace)
{
$found = false;
foreach ($this->_aReports as $row => $detail) {
if ($sNamespace == $detail)
@@ -710,7 +734,8 @@ class PMPluginRegistry {
* @param unknown_type $sMenuId
* @param unknown_type $sFilename
*/
function registerPmFunction($sNamespace ) {
function registerPmFunction ($sNamespace)
{
$found = false;
foreach ($this->_aPmFunctions as $row => $detail) {
if ($sNamespace == $detail)
@@ -728,7 +753,8 @@ class PMPluginRegistry {
* @param unknown_type $sRole
* @param unknown_type $sPath
*/
function registerRedirectLogin($sNamespace, $sRole, $sPathMethod ) {
function registerRedirectLogin ($sNamespace, $sRole, $sPathMethod)
{
$found = false;
foreach ($this->_aRedirectLogin as $row => $detail) {
if (($sNamespace == $detail->sNamespace) && ($sRole == $detail->sRoleCode)) //Filters based on Workspace and Role Code
@@ -744,7 +770,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sFolderName
*/
function registerFolder($sNamespace, $sFolderId, $sFolderName ) {
function registerFolder ($sNamespace, $sFolderId, $sFolderName)
{
$found = false;
foreach ($this->_aFolders as $row => $detail)
if ($sFolderId == $detail->sFolderId && $sNamespace == $detail->sNamespace)
@@ -760,7 +787,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sFolderName
*/
function registerStep($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage = '') {
function registerStep ($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage = '')
{
$found = false;
foreach ($this->_aSteps as $row => $detail)
if ($sStepId == $detail->sStepId && $sNamespace == $detail->sNamespace)
@@ -776,7 +804,8 @@ class PMPluginRegistry {
*
* @param unknown_type $sFolderName
*/
function isRegisteredFolder( $sFolderName ) {
function isRegisteredFolder ($sFolderName)
{
foreach ($this->_aFolders as $row => $folder) {
if ($sFolderName == $folder->sFolderName && is_dir( PATH_PLUGINS . $folder->sFolderName )) {
return true;
@@ -792,7 +821,8 @@ class PMPluginRegistry {
*
* @param unknown_type $menuId
*/
function getMenus( $menuId ) {
function getMenus ($menuId)
{
foreach ($this->_aMenus as $row => $detail) {
if ($menuId == $detail->sMenuId && file_exists( $detail->sFilename )) {
include ($detail->sFilename);
@@ -802,17 +832,21 @@ class PMPluginRegistry {
/**
* return all dashlets classes registered
*
* @return array
*/
function getDashlets() {
function getDashlets ()
{
return $this->_aDashlets;
}
/**
* this function returns all reports registered
*
* @return array
*/
function getReports( ) {
function getReports ()
{
return $this->_aReports;
$report = array ();
foreach ($this->_aReports as $row => $detail) {
@@ -826,7 +860,8 @@ class PMPluginRegistry {
* This function returns all pmFunctions registered
* @ array
*/
function getPmFunctions( ) {
function getPmFunctions ()
{
return $this->_aPmFunctions;
$pmf = array ();
foreach ($this->_aPmFunctions as $row => $detail) {
@@ -841,15 +876,18 @@ class PMPluginRegistry {
*
* @return string
*/
function getSteps( ) {
function getSteps ()
{
return $this->_aSteps;
}
/**
* This function returns all redirect registered
*
* @return string
*/
function getRedirectLogins( ) {
function getRedirectLogins ()
{
return $this->_aRedirectLogin;
}
@@ -882,11 +920,11 @@ class PMPluginRegistry {
$methodName = $detail->sTriggerName;
$response = $obj->{$methodName}( $oData );
if (PEAR::isError( $response )) {
print $response->getMessage(); return;
print $response->getMessage();
return;
}
return $response;
}
else
} else
print "error in call method " . $detail->sTriggerName;
}
}
@@ -897,7 +935,8 @@ class PMPluginRegistry {
*
* @param unknown_type $triggerId
*/
function existsTrigger( $triggerId) {
function existsTrigger ($triggerId)
{
$found = false;
foreach ($this->_aTriggers as $row => $detail) {
if ($triggerId == $detail->sTriggerId) {
@@ -920,7 +959,8 @@ class PMPluginRegistry {
* @param unknown_type $triggerId
* @return object
*/
function getTriggerInfo( $triggerId) {
function getTriggerInfo ($triggerId)
{
$found = null;
foreach ($this->_aTriggers as $row => $detail) {
if ($triggerId == $detail->sTriggerId) {
@@ -944,7 +984,8 @@ class PMPluginRegistry {
* @param unknown_type $sMethodFunction
* @return void
*/
function registerTrigger($sNamespace, $sTriggerId, $sTriggerName ) {
function registerTrigger ($sNamespace, $sTriggerId, $sTriggerName)
{
$found = false;
foreach ($this->_aTriggers as $row => $detail) {
if ($sTriggerId == $detail->sTriggerId && $sNamespace == $detail->sNamespace)
@@ -962,7 +1003,8 @@ class PMPluginRegistry {
* @param unknown_type $sNamespace
* @return void
*/
function &getPlugin($sNamespace) {
function &getPlugin ($sNamespace)
{
if (array_key_exists( $sNamespace, $this->_aPlugins )) {
return $this->_aPlugins[$sNamespace];
}
@@ -989,7 +1031,8 @@ class PMPluginRegistry {
* @param unknown_type $filename
* @return void
*/
function setCompanyLogo( $sNamespace, $filename ) {
function setCompanyLogo ($sNamespace, $filename)
{
$found = false;
foreach ($this->_aPluginDetails as $row => $detail) {
if ($sNamespace == $detail->sNamespace)
@@ -1003,7 +1046,8 @@ class PMPluginRegistry {
* @param unknown_type $default
* @return void
*/
function getCompanyLogo( $default ) {
function getCompanyLogo ($default)
{
$sCompanyLogo = $default;
foreach ($this->_aPluginDetails as $row => $detail) {
if (trim( $detail->sCompanyLogo ) != '')
@@ -1018,7 +1062,8 @@ class PMPluginRegistry {
* @param unknown_type $default
* @return void
*/
function setupPlugins() {
function setupPlugins ()
{
try {
$iPlugins = 0;
G::LoadClass( 'serverConfiguration' );
@@ -1029,12 +1074,12 @@ class PMPluginRegistry {
if (! empty( $detail->sFilename ) && file_exists( $detail->sFilename )) {
if (strpos( $detail->sFilename, PATH_SEP ) !== false) {
$aux = explode( PATH_SEP, $detail->sFilename );
}
else {
} else {
$aux = explode( chr( 92 ), $detail->sFilename );
}
$sFilename = PATH_PLUGINS . $aux[count( $aux ) - 1];
if (! file_exists($sFilename) ) continue;
if (! file_exists( $sFilename ))
continue;
require_once $sFilename;
if (class_exists( $detail->sClassName )) {
$oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename );
@@ -1047,14 +1092,13 @@ class PMPluginRegistry {
}
$this->eevalidate();
return $iPlugins;
}
catch ( Exception $e ) {
} catch (Exception $e) {
global $G_PUBLISH;
$aMessage['MESSAGE'] = $e->getMessage();
$G_PUBLISH = new Publisher;
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
G::RenderPage( 'publish' );
die;
die();
}
}
@@ -1067,7 +1111,8 @@ class PMPluginRegistry {
* @param object $oData
* @return object
*/
function executeMethod( $sNamespace, $methodName, $oData ) {
function executeMethod ($sNamespace, $methodName, $oData)
{
$response = null;
try {
$details = $this->_aPluginDetails[$sNamespace];
@@ -1093,8 +1138,7 @@ class PMPluginRegistry {
$response = $obj->{$methodName}( $oData );
}
return $response;
}
catch ( Exception $e ) {
} catch (Exception $e) {
throw ($e);
}
}
@@ -1105,7 +1149,8 @@ class PMPluginRegistry {
* @param string $sNamespace
* @return object
*/
function getFieldsForPageSetup( $sNamespace ) {
function getFieldsForPageSetup ($sNamespace)
{
$oData = NULL;
return $this->executeMethod( $sNamespace, 'getFieldsForPageSetup', $oData );
}
@@ -1116,13 +1161,17 @@ class PMPluginRegistry {
* @param string $sNamespace
* @return void
*/
function updateFieldsForPageSetup( $sNamespace, $oData ) {
function updateFieldsForPageSetup ($sNamespace, $oData)
{
if (! isset( $this->_aPluginDetails[$sNamespace] )) {
throw (new Exception( "The namespace '$sNamespace' doesn't exist in plugins folder." ));
};
}
;
return $this->executeMethod( $sNamespace, 'updateFieldsForPageSetup', $oData );
}
function eevalidate(){
function eevalidate ()
{
$fileL = PATH_DATA_SITE . 'license.dat';
$fileS = PATH_DATA . 'license.dat';
if ((file_exists( $fileL )) || (file_exists( $fileS ))) { //Found a License
@@ -1135,6 +1184,7 @@ class PMPluginRegistry {
}
}
}
/**
* Register a toolbar for dynaform editor in the singleton
*
@@ -1142,7 +1192,8 @@ class PMPluginRegistry {
* @param unknown_type $sToolbarId
* @param unknown_type $sFilename
*/
function registerToolbarFile($sNamespace, $sToolbarId, $sFilename ) {
function registerToolbarFile ($sNamespace, $sToolbarId, $sFilename)
{
$found = false;
foreach ($this->_aToolbarFiles as $row => $detail) {
if ($sToolbarId == $detail->sToolbarId && $sNamespace == $detail->sNamespace)
@@ -1153,23 +1204,26 @@ class PMPluginRegistry {
$this->_aToolbarFiles[] = $toolbarDetail;
}
}
/**
* return all toolbar files related to a sToolbarId
*
* @param unknown_type $sToolbarId (NORMAL, GRID)
*/
function getToolbarOptions( $sToolbarId ) {
function getToolbarOptions ($sToolbarId)
{
foreach ($this->_aToolbarFiles as $row => $detail) {
if ($sToolbarId == $detail->sToolbarId && file_exists( $detail->sFilename )) {
include ($detail->sFilename);
}
}
}
/**
* Register a Case Scheduler Plugin
*
*/
function registerCaseSchedulerPlugin($sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields) {
function registerCaseSchedulerPlugin ($sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields)
{
$found = false;
foreach ($this->_aCaseSchedulerPlugin as $row => $detail)
if ($sActionId == $detail->sActionId && $sNamespace == $detail->sNamespace)
@@ -1179,12 +1233,14 @@ class PMPluginRegistry {
$this->_aCaseSchedulerPlugin[] = new caseSchedulerPlugin( $sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields );
}
}
/**
* This function returns all Case Scheduler Plugins registered
*
* @return string
*/
function getCaseSchedulerPlugins( ) {
function getCaseSchedulerPlugins ()
{
return $this->_aCaseSchedulerPlugin;
}
@@ -1195,7 +1251,8 @@ class PMPluginRegistry {
* @param unknown_type $sPage
*/
function registerTaskExtendedProperty($sNamespace, $sPage, $sName, $sIcon ) {
function registerTaskExtendedProperty ($sNamespace, $sPage, $sName, $sIcon)
{
$found = false;
foreach ($this->_aTaskExtendedProperties as $row => $detail) {
if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) {
@@ -1212,12 +1269,14 @@ class PMPluginRegistry {
/**
* Register a dashboard page for cases in the singleton
*
* @param unknown_type $sNamespace
* @param unknown_type $sPage
* @param unknown_type $sName
* @param unknown_type $sIcon
*/
function registerDashboardPage($sNamespace, $sPage, $sName, $sIcon ) {
function registerDashboardPage ($sNamespace, $sPage, $sName, $sIcon)
{
foreach ($this->_aDashboardPages as $row => $detail) {
if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) {
$detail->sName = $sName;
@@ -1301,7 +1360,8 @@ class PMPluginRegistry {
*
* @return array
*/
function getDashboardPages() {
function getDashboardPages ()
{
return $this->_aDashboardPages;
}
@@ -1310,11 +1370,13 @@ class PMPluginRegistry {
*
* @return array
*/
function getTaskExtendedProperties() {
function getTaskExtendedProperties ()
{
return $this->_aTaskExtendedProperties;
}
function registerDashboard() {
function registerDashboard ()
{
// Dummy function for backwards compatibility
}