public function import($sLanguageFile, $updateXml = true, $updateDB = true, $generateMafe = true) { try { //get labels MichelangeloFE try { $oTranslation = new Translation(); $MichelangeloFE = PATH_HOME . "../workflow/public_html/lib/js"; if (file_exists($MichelangeloFE)) { $labels = self::readLabelsDirectory($MichelangeloFE, true); foreach ($labels as $label) { $oTranslation->addTranslation('LABEL', 'ID_MAFE_' . G::encryptOld($label), 'en', $label); } } } catch (Exception $e) { error_log($e->getMessage()); } G::LoadSystem('i18n_po'); $POFile = new i18n_PO($sLanguageFile); $POFile->readInit(); $POHeaders = $POFile->getHeaders(); /*getting the PO Language definition*/ $langName = $POHeaders['X-Poedit-Language']; //find the lang id $language = new Language(); $langRecord = $language->findByLanName($langName); if (!isset($langRecord['LAN_ID'])) { $langRecord = $language->findById($langName); if (!isset($langRecord['LAN_ID'])) { //if the language doesn't exist abort throw new Exception('The .po file has a invalid X-Poedit-Language definition!'); } } $languageID = $langRecord['LAN_ID']; /*getting the PO Language definition*/ $countryName = $POHeaders['X-Poedit-Country']; if ($countryName != '.') { $isoCountry = new IsoCountry(); $countryRecord = $isoCountry->findByIcName($countryName); if (!isset($countryRecord['IC_UID'])) { //if the language doesn't exist abort throw new Exception('The .po file has a invalid X-Poedit-Country definition!'); } $countryID = $countryRecord['IC_UID']; //define locale $LOCALE = "{$languageID}-{$countryID}"; } else { $LOCALE = $languageID; } $oTranslation = new Translation(); $countItems = 0; $countItemsSuccess = 0; $errorMsg = ''; while ($rowTranslation = $POFile->getTranslation()) { $countItems++; if (!isset($POFile->translatorComments[0]) || !isset($POFile->translatorComments[1]) || !isset($POFile->references[0])) { throw new Exception('The .po file doesn\'t have valid directives for Processmaker!'); } foreach ($POFile->translatorComments as $a => $aux) { $aux = trim($aux); if ($aux == 'TRANSLATION') { $identifier = $aux; } else { $var = explode('/', $aux); if ($var[0] == 'LABEL') { $context = $aux; } if ($var[0] == 'JAVASCRIPT') { $context = $aux; } } if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml\\?)/', $aux, $match)) { $identifier = $aux; } else { if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml$)/', $aux, $match)) { $context = $aux; } } } $reference = $POFile->references[0]; // it is a Sql insert on TRANSLATIONS TAble if ($identifier == 'TRANSLATION') { if ($updateDB) { list($category, $id) = explode('/', $context); $result = $oTranslation->addTranslation($category, $id, $LOCALE, trim(stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr'])))); if ($result['codError'] == 0) { $countItemsSuccess++; } else { $errorMsg .= $id . ': ' . $result['message'] . "\n"; } } } elseif ($updateXml) { $xmlForm = $context; //erik: expresion to prevent and hable correctly dropdown values like -1, -2 etc. preg_match('/^([\\w_]+)\\s-\\s([\\w_]+)\\s*-*\\s*([\\w\\W]*)$/', $reference, $match); if (!file_exists(PATH_XMLFORM . $xmlForm)) { $errorMsg .= 'file doesn\'t exist: ' . PATH_XMLFORM . $xmlForm . "\n"; continue; } if (count($match) < 4) { $near = isset($rowTranslation['msgid']) ? $rowTranslation['msgid'] : (isset($rowTranslation['msgstr']) ? $rowTranslation['msgstr'] : ''); $errorMsg .= "Invalid Translation reference: \"{$reference}\", near -> " . strip_tags($near) . "\n"; continue; } G::LoadSystem('dynaformhandler'); $dynaform = new dynaFormHandler(PATH_XMLFORM . $xmlForm); $fieldName = $match[2]; $codes = explode('-', $reference); if (sizeof($codes) == 2) { //is a normal node $dynaform->addChilds($fieldName, array($LOCALE => stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr'])))); } elseif (sizeof($codes) > 2) { //is a node child for a language node $name = $match[3] == "''" ? '' : $match[3]; $childNode = array(array('name' => 'option', 'value' => $rowTranslation['msgstr'], 'attributes' => array('name' => $name))); $dynaform->addChilds($fieldName, array($LOCALE => null), $childNode); } $countItemsSuccess++; } } $oLanguage = new Language(); $oLanguage->update(array('LAN_ID' => $languageID, 'LAN_ENABLED' => '1')); if ($updateXml) { $trn = new Translation(); $trn->generateFileTranslation($LOCALE); $trn->addTranslationEnvironment($LOCALE, $POHeaders, $countItemsSuccess); } if ($generateMafe) { $trn = new Translation(); $trn->generateFileTranslationMafe(); } //fill the results $results = new stdClass(); $results->recordsCount = $countItems; $results->recordsCountSuccess = $countItemsSuccess; $results->lang = $languageID; $results->headers = $POHeaders; $results->errMsg = $errorMsg; G::auditLog("UploadLanguage", "Language: " . $languageID); return $results; } catch (Exception $oError) { throw $oError; } }
/** * Index Action * * @param string $httpData (opional) */ public function index($httpData) { $proUid = isset($httpData->prj_uid) ? $httpData->prj_uid : ''; $appUid = isset($httpData->app_uid) ? $httpData->app_uid : ''; $proReadOnly = isset($httpData->prj_readonly) ? $httpData->prj_readonly : 'false'; $client = $this->getClientCredentials(); if (isset($httpData->tracker_designer) && $httpData->tracker_designer == 1) { $client["tracker_designer"] = 1; } $authCode = $this->getAuthorizationCode($client); $debug = false; //System::isDebugMode(); $loader = Maveriks\Util\ClassLoader::getInstance(); $loader->add(PATH_TRUNK . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2"); $request = array( 'grant_type' => 'authorization_code', 'code' => $authCode ); $server = array( 'REQUEST_METHOD' => 'POST' ); $headers = array( "PHP_AUTH_USER" => $client['CLIENT_ID'], "PHP_AUTH_PW" => $client['CLIENT_SECRET'], "Content-Type" => "multipart/form-data;", "Authorization" => "Basic " . base64_encode($client['CLIENT_ID'] . ":" . $client['CLIENT_SECRET']) ); $request = new \OAuth2\Request(array(), $request, array(), array(), array(), $server, null, $headers); $oauthServer = new \ProcessMaker\Services\OAuth2\Server(); $response = $oauthServer->postToken($request, true); $clientToken = $response->getParameters(); $clientToken["client_id"] = $client['CLIENT_ID']; $clientToken["client_secret"] = $client['CLIENT_SECRET']; $consolidated = 0; $enterprise = 0; $distribution = 0; /*----------------------------------********---------------------------------*/ $this->setVar('prj_uid', $proUid); $this->setVar('app_uid', $appUid); $this->setVar('consolidated', $consolidated); $this->setVar('enterprise', $enterprise); $this->setVar('prj_readonly', $proReadOnly); $this->setVar('credentials', base64_encode(json_encode($clientToken))); $this->setVar('isDebugMode', $debug); $this->setVar("distribution", $distribution); if ($debug) { if (! file_exists(PATH_HTML . "lib-dev/pmUI/build.cache")) { throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in pmUI project"); } if (! file_exists(PATH_HTML . "lib-dev/mafe/build.cache")) { throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in MichelangeloFE project"); } $mafeFiles = file(PATH_HTML . "lib-dev/mafe/build.cache", FILE_IGNORE_NEW_LINES); $mafeCssFiles = array(); $mafeJsFiles = array(); foreach ($mafeFiles as $file) { if (substr($file, -3) == ".js") { $mafeJsFiles[] = $file; } else { $mafeCssFiles[] = $file; } } $this->setVar('pmuiJsCacheFile', file(PATH_HTML . "lib-dev/pmUI/build.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('pmuiCssCacheFile', file(PATH_HTML . "lib-dev/pmUI/css.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('designerCacheFile', file(PATH_HTML . "lib-dev/mafe/applications.cache", FILE_IGNORE_NEW_LINES)); $this->setVar('mafeJsFiles', $mafeJsFiles); $this->setVar('mafeCssFiles', $mafeCssFiles); } else { $buildhashFile = PATH_HTML . "lib/buildhash"; if (! file_exists($buildhashFile)) { throw new RuntimeException("CSS and JS Files were are not generated!.\nPlease review install process"); } $buildhash = file_get_contents($buildhashFile); $this->setVar('buildhash', $buildhash); } $translationMafe = "/translations/translationsMafe.js"; $this->setVar('translationMafe', $translationMafe); if (!file_exists(PATH_HTML . "translations" . PATH_SEP. 'translationsMafe' . ".js")) { $translation = new Translation(); $translation->generateFileTranslationMafe(); } $this->setVar('sys_skin', SYS_SKIN); $this->setView('designer/index'); $this->render(); }