/**
     * Enable the plugin in the singleton
     *
     * @param unknown_type $sNamespace
     */
    public 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
                $this->_aPluginDetails[$sNamespace]->enabled = true;
                if (class_exists($detail->sClassName)) {
                    $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename );
                } else {
                    $oPlugin = $detail;
                }
                $this->_aPlugins[$detail->sNamespace] = $oPlugin;
                if (method_exists( $oPlugin, 'enable' )) {
                    $oPlugin->enable();
                }

                /*
                 * 1. register <plugin-dir>/src directory for autoloading
                 * 2. verify if rest service is enabled
                 * 3. register rest service directory
                 */
                $pluginSrcDir = PATH_PLUGINS . $detail->sNamespace . PATH_SEP . 'src';

                if (is_dir($pluginSrcDir)) {
                    //Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir);
                    $loader = \Maveriks\Util\ClassLoader::getInstance();
                    $loader->add($pluginSrcDir);
                }

                if (array_key_exists($detail->sNamespace, $this->_restServiceEnabled)
                    && $this->_restServiceEnabled[$detail->sNamespace] == true
                ) {

                    $oPlugin->registerRestService();
                }

                return true;
            }
        }
        throw new Exception( "Unable to enable plugin '$sNamespace' (plugin not found)" );
    }
Example #2
0
 /**
  * Set value in WE_DATA
  *
  * @param string $webEntryUid Unique id of Web Entry
  *
  * return void
  */
 public function setWeData($webEntryUid)
 {
     try {
         //Verify data
         $this->throwExceptionIfNotExistsWebEntry($webEntryUid, $this->arrayFieldNameForException["webEntryUid"]);
         //Set variables
         $arrayWebEntryData = $this->getWebEntry($webEntryUid, true);
         $processUid = $arrayWebEntryData["PRO_UID"];
         $taskUid = $arrayWebEntryData["TAS_UID"];
         $dynaFormUid = $arrayWebEntryData["DYN_UID"];
         $webEntryMethod = $arrayWebEntryData["WE_METHOD"];
         $webEntryInputDocumentAccess = $arrayWebEntryData["WE_INPUT_DOCUMENT_ACCESS"];
         $webEntryData = "";
         $wsRoundRobin = 0;
         //0, 1 //0 - Cyclical Assignment
         $pathDataPublicProcess = PATH_DATA_PUBLIC . $processUid;
         //Delete previous files
         if (trim($arrayWebEntryData["WE_DATA"]) != "") {
             $fileName = str_replace(".php", "", trim($arrayWebEntryData["WE_DATA"]));
             $file = $pathDataPublicProcess . PATH_SEP . $fileName . ".php";
             if (is_file($file) && file_exists($file)) {
                 unlink($file);
                 unlink($pathDataPublicProcess . PATH_SEP . $fileName . "Post.php");
             }
         }
         //Create files
         \G::mk_dir($pathDataPublicProcess, 0777);
         $http = \G::is_https() ? "https://" : "http://";
         switch ($webEntryMethod) {
             case "WS":
                 require_once PATH_RBAC . "model" . PATH_SEP . "RbacUsers.php";
                 $user = new \RbacUsers();
                 $arrayUserData = $user->load($arrayWebEntryData["USR_UID"]);
                 $usrUsername = $arrayUserData["USR_USERNAME"];
                 $usrPassword = $arrayUserData["USR_PASSWORD"];
                 $dynaForm = new \Dynaform();
                 $arrayDynaFormData = $dynaForm->Load($arrayWebEntryData["DYN_UID"]);
                 //Creating sys.info;
                 $sitePublicPath = "";
                 if (file_exists($sitePublicPath . "")) {
                 }
                 //Creating the first file
                 $weTitle = $this->sanitizeFilename($arrayWebEntryData["WE_TITLE"]);
                 $fileName = $weTitle;
                 $fileContent = "<?php\n";
                 $fileContent .= "global \$_DBArray;\n";
                 $fileContent .= "if (!isset(\$_DBArray)) {\n";
                 $fileContent .= "  \$_DBArray = array();\n";
                 $fileContent .= "}\n";
                 $fileContent .= "\$_SESSION[\"PROCESS\"] = \"" . $processUid . "\";\n";
                 $fileContent .= "\$_SESSION[\"CURRENT_DYN_UID\"] = \"" . $dynaFormUid . "\";\n";
                 $fileContent .= "\$G_PUBLISH = new Publisher();\n";
                 $fileContent .= "G::LoadClass(\"pmDynaform\");\n";
                 $fileContent .= "\$a = new pmDynaform(array(\"CURRENT_DYNAFORM\" => \"" . $arrayWebEntryData["DYN_UID"] . "\"));\n";
                 $fileContent .= "if (\$a->isResponsive()) {";
                 $fileContent .= "  \$a->printWebEntry(\"" . $fileName . "Post.php\");";
                 $fileContent .= "} else {";
                 $fileContent .= "  \$G_PUBLISH->AddContent(\"dynaform\", \"xmlform\", \"" . $processUid . PATH_SEP . $dynaFormUid . "\", \"\", array(), \"" . $fileName . "Post.php\");\n";
                 $fileContent .= "  G::RenderPage(\"publish\", \"blank\");";
                 $fileContent .= "}";
                 file_put_contents($pathDataPublicProcess . PATH_SEP . $fileName . ".php", $fileContent);
                 //Creating the second file, the  post file who receive the post form.
                 $pluginTpl = PATH_TPL . "processes" . PATH_SEP . "webentryPost.tpl";
                 $template = new \TemplatePower($pluginTpl);
                 $template->prepare();
                 $template->assign("wsdlUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/wsdl2");
                 $template->assign("wsUploadUrl", $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/upload");
                 $template->assign("processUid", $processUid);
                 $template->assign("dynaformUid", $dynaFormUid);
                 $template->assign("taskUid", $taskUid);
                 $template->assign("wsUser", $usrUsername);
                 $template->assign("wsPass", \Bootstrap::getPasswordHashType() . ':' . $usrPassword);
                 $template->assign("wsRoundRobin", $wsRoundRobin);
                 if ($webEntryInputDocumentAccess == 0) {
                     //Restricted to process permissions
                     $template->assign("USR_VAR", "\$cInfo = ws_getCaseInfo(\$caseId);\n\t  \$USR_UID = \$cInfo->currentUsers->userId;");
                 } else {
                     //No Restriction
                     $template->assign("USR_VAR", "\$USR_UID = -1;");
                 }
                 $template->assign("dynaform", $arrayDynaFormData["DYN_TITLE"]);
                 $template->assign("timestamp", date("l jS \\of F Y h:i:s A"));
                 $template->assign("ws", SYS_SYS);
                 $template->assign("version", \System::getVersion());
                 $fileName = $pathDataPublicProcess . PATH_SEP . $weTitle . "Post.php";
                 file_put_contents($fileName, $template->getOutputContent());
                 //Creating the third file, only if this wsClient.php file doesn't exist.
                 $fileName = $pathDataPublicProcess . PATH_SEP . "wsClient.php";
                 $pluginTpl = PATH_CORE . "templates" . PATH_SEP . "processes" . PATH_SEP . "wsClient.php";
                 if (file_exists($fileName)) {
                     if (filesize($fileName) != filesize($pluginTpl)) {
                         copy($fileName, $pathDataPublicProcess . PATH_SEP . "wsClient.php.bak");
                         unlink($fileName);
                         $template = new \TemplatePower($pluginTpl);
                         $template->prepare();
                         file_put_contents($fileName, $template->getOutputContent());
                     }
                 } else {
                     $template = new \TemplatePower($pluginTpl);
                     $template->prepare();
                     file_put_contents($fileName, $template->getOutputContent());
                 }
                 //Event
                 $task = new \Task();
                 $arrayTaskData = $task->load($arrayWebEntryData["TAS_UID"]);
                 $weEventUid = $task->getStartingEvent();
                 if ($weEventUid != "") {
                     $event = new \Event();
                     $arrayEventData = array();
                     $arrayEventData["EVN_UID"] = $weEventUid;
                     $arrayEventData["EVN_RELATED_TO"] = "MULTIPLE";
                     $arrayEventData["EVN_ACTION"] = $dynaFormUid;
                     $arrayEventData["EVN_CONDITIONS"] = $usrUsername;
                     $result = $event->update($arrayEventData);
                 }
                 //WE_DATA
                 $webEntryData = $weTitle . ".php";
                 break;
             case "HTML":
                 global $G_FORM;
                 if (!class_exists("Smarty")) {
                     $loader = \Maveriks\Util\ClassLoader::getInstance();
                     $loader->addClass("Smarty", PATH_THIRDPARTY . "smarty" . PATH_SEP . "libs" . PATH_SEP . "Smarty.class.php");
                 }
                 $G_FORM = new \Form($processUid . "/" . $dynaFormUid, PATH_DYNAFORM, SYS_LANG, false);
                 $G_FORM->action = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/services/cases_StartExternal.php";
                 $scriptCode = "";
                 $scriptCode = $G_FORM->render(PATH_TPL . "xmlform" . ".html", $scriptCode);
                 $scriptCode = str_replace("/controls/", $http . $_SERVER["HTTP_HOST"] . "/controls/", $scriptCode);
                 $scriptCode = str_replace("/js/maborak/core/images/", $http . $_SERVER["HTTP_HOST"] . "/js/maborak/core/images/", $scriptCode);
                 //Render the template
                 $pluginTpl = PATH_TPL . "processes" . PATH_SEP . "webentry.tpl";
                 $template = new \TemplatePower($pluginTpl);
                 $template->prepare();
                 $step = new \Step();
                 $sUidGrids = $step->lookingforUidGrids($processUid, $dynaFormUid);
                 $template->assign("URL_MABORAK_JS", \G::browserCacheFilesUrl("/js/maborak/core/maborak.js"));
                 $template->assign("URL_TRANSLATION_ENV_JS", \G::browserCacheFilesUrl("/jscore/labels/" . SYS_LANG . ".js"));
                 $template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);
                 $template->assign("sysSys", SYS_SYS);
                 $template->assign("sysLang", SYS_LANG);
                 $template->assign("sysSkin", SYS_SKIN);
                 $template->assign("processUid", $processUid);
                 $template->assign("dynaformUid", $dynaFormUid);
                 $template->assign("taskUid", $taskUid);
                 $template->assign("dynFileName", $processUid . "/" . $dynaFormUid);
                 $template->assign("formId", $G_FORM->id);
                 $template->assign("scriptCode", $scriptCode);
                 if (sizeof($sUidGrids) > 0) {
                     foreach ($sUidGrids as $k => $v) {
                         $template->newBlock("grid_uids");
                         $template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);
                         $template->assign("gridFileName", $processUid . "/" . $v);
                     }
                 }
                 //WE_DATA
                 $html = str_replace("</body>", "</form></body>", str_replace("</form>", "", $template->getOutputContent()));
                 $webEntryData = $html;
                 break;
         }
         //Update
         //Update where
         $criteriaWhere = new \Criteria("workflow");
         $criteriaWhere->add(\WebEntryPeer::WE_UID, $webEntryUid);
         //Update set
         $criteriaSet = new \Criteria("workflow");
         $criteriaSet->add(\WebEntryPeer::WE_DATA, $webEntryData);
         \BasePeer::doUpdate($criteriaWhere, $criteriaSet, \Propel::getConnection("workflow"));
     } catch (\Exception $e) {
         throw $e;
     }
 }
Example #3
0
    define('PATH_TRUNK', $pathTrunk);

    define('PATH_OUTTRUNK', $pathOutTrunk);



    require_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php');

    require_once PATH_TRUNK . "framework/src/Maveriks/Util/ClassLoader.php";



    //Class Loader - /ProcessMaker/BusinessModel

    $classLoader = \Maveriks\Util\ClassLoader::getInstance();

    $classLoader->add(PATH_TRUNK . "framework" . PATH_SEP . "src" . PATH_SEP, "Maveriks");

    $classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP, "ProcessMaker");

    $classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP);



    //Add vendors to autoloader

    //$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "luracast" . PATH_SEP . "restler" . PATH_SEP . "vendor", "Luracast");

    //$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "bshaffer" . PATH_SEP . "oauth2-server-php" . PATH_SEP . "src" . PATH_SEP, "OAuth2");
 /**
  * create a new instance of local $rest Restler object
  */
 protected function initRest($uri, $version, $multipart = false)
 {
     require_once $this->rootDir . "/framework/src/Maveriks/Extension/Restler/UploadFormat.php";
     // $servicesDir contains directory where Services Classes are allocated
     $servicesDir = $this->workflowDir . 'engine' . DS . 'src' . DS . 'ProcessMaker' . DS . 'Services' . DS;
     // $apiDir - contains directory to scan classes and add them to Restler
     $apiDir = $servicesDir . 'Api' . DS;
     // $apiIniFile - contains file name of api ini configuration
     $apiIniFile = $servicesDir . DS . 'api.ini';
     // $authenticationClass - contains the class name that validate the authentication for Restler
     $authenticationClass = 'ProcessMaker\\Services\\OAuth2\\Server';
     // $pmOauthClientId - contains PM Local OAuth Id (Web Designer)
     $pmOauthClientId = 'x-pm-local-client';
     /*
      * Load Api ini file for Rest Service
      */
     $config = array();
     if (file_exists($apiIniFile)) {
         $cachedConfig = $this->workspaceCacheDir . "api-config.php";
         // verify if config cache file exists, is array and the last modification date is the same when cache was created.
         if (!file_exists($cachedConfig) || !is_array($config = (include $cachedConfig)) || $config["_chk"] != filemtime($apiIniFile)) {
             $config = Util\Common::parseIniFile($apiIniFile);
             $config["_chk"] = filemtime($apiIniFile);
             if (!is_dir(dirname($cachedConfig))) {
                 Util\Common::mk_dir(dirname($cachedConfig));
             }
             file_put_contents($cachedConfig, "<?php return " . var_export($config, true) . ";");
             Util\Logger::log("Configuration cache was loaded and cached to: {$cachedConfig}");
         } else {
             Util\Logger::log("Loading Api Configuration from: {$cachedConfig}");
         }
     }
     // Setting current workspace to Api class
     Services\Api::setWorkspace(SYS_SYS);
     $cacheDir = defined("PATH_C") ? PATH_C : sys_get_temp_dir();
     $sysConfig = \System::getSystemConfiguration();
     \Luracast\Restler\Defaults::$cacheDirectory = $cacheDir;
     $productionMode = (bool) (!(isset($sysConfig["service_api_debug"]) && $sysConfig["service_api_debug"]));
     Util\Logger::log("Serving API mode: " . ($productionMode ? "production" : "development"));
     // create a new Restler instance
     //$rest = new \Luracast\Restler\Restler();
     $this->rest = new \Maveriks\Extension\Restler($productionMode);
     // setting flag for multipart to Restler
     $this->rest->setFlagMultipart($multipart);
     // setting api version to Restler
     $this->rest->setAPIVersion($version);
     // adding $authenticationClass to Restler
     $this->rest->addAuthenticationClass($authenticationClass, '');
     // Setting database connection source
     list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
     $port = empty($port) ? '' : ";port={$port}";
     Services\OAuth2\Server::setDatabaseSource(DB_USER, DB_PASS, DB_ADAPTER . ":host={$host};dbname=" . DB_NAME . $port);
     if (DB_NAME != DB_RBAC_NAME) {
         //it's PM < 3
         list($host, $port) = strpos(DB_RBAC_HOST, ':') !== false ? explode(':', DB_RBAC_HOST) : array(DB_RBAC_HOST, '');
         $port = empty($port) ? '' : ";port={$port}";
         Services\OAuth2\Server::setDatabaseSourceRBAC(DB_RBAC_USER, DB_RBAC_PASS, DB_ADAPTER . ":host={$host};dbname=" . DB_RBAC_NAME . $port);
     }
     // Setting default OAuth Client id, for local PM Web Designer
     Services\OAuth2\Server::setPmClientId($pmOauthClientId);
     $this->rest->setOverridingFormats('JsonFormat', 'UploadFormat');
     // scan all api directory to find api classes
     $classesList = Util\Common::rglob($apiDir . "/*");
     foreach ($classesList as $classFile) {
         if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') {
             $relClassPath = str_replace('.php', '', str_replace($servicesDir, '', $classFile));
             $namespace = '\\ProcessMaker\\Services\\' . str_replace(DS, '\\', $relClassPath);
             $namespace = strpos($namespace, "//") === false ? $namespace : str_replace("//", '', $namespace);
             //if (! class_exists($namespace)) {
             require_once $classFile;
             //}
             $this->rest->addAPIClass($namespace);
         }
     }
     // adding aliases for Restler
     if (array_key_exists('alias', $config)) {
         foreach ($config['alias'] as $alias => $aliasData) {
             if (is_array($aliasData)) {
                 foreach ($aliasData as $label => $namespace) {
                     $namespace = '\\' . ltrim($namespace, '\\');
                     $this->rest->addAPIClass($namespace, $alias);
                 }
             }
         }
     }
     //
     // Register API Plugins classes
     $isPluginRequest = strpos($uri, '/plugin-') !== false ? true : false;
     if ($isPluginRequest) {
         $tmp = explode('/', $uri);
         array_shift($tmp);
         $tmp = array_shift($tmp);
         $tmp = explode('-', $tmp);
         $pluginName = $tmp[1];
         $uri = str_replace('plugin-' . $pluginName, strtolower($pluginName), $uri);
     }
     // hook to get rest api classes from plugins
     if (class_exists('PMPluginRegistry') && file_exists(PATH_DATA_SITE . 'plugin.singleton')) {
         $pluginRegistry = \PMPluginRegistry::loadSingleton(PATH_DATA_SITE . 'plugin.singleton');
         $plugins = $pluginRegistry->getRegisteredRestServices();
         if (!empty($plugins)) {
             foreach ($plugins as $pluginName => $plugin) {
                 $pluginSourceDir = PATH_PLUGINS . $pluginName . DIRECTORY_SEPARATOR . 'src';
                 $loader = \Maveriks\Util\ClassLoader::getInstance();
                 $loader->add($pluginSourceDir);
                 foreach ($plugin as $class) {
                     if (class_exists($class['namespace'])) {
                         $this->rest->addAPIClass($class['namespace'], strtolower($pluginName));
                     }
                 }
             }
         }
     }
     Services\OAuth2\Server::setWorkspace(SYS_SYS);
     $this->rest->addAPIClass('\\ProcessMaker\\Services\\OAuth2\\Server', 'oauth2');
     return $uri;
 }