BUG 0000 "Safe upgrade for JavaScript files of the plugins" SOLVED

- Safe upgrade for JavaScript files of the plugins's translations
- Improved programming logic for this issue
- Problem solved, has been added the code necessary for the plugins's translations
* Available from version ProcessMaker-2.5.2-testing.1
This commit is contained in:
Victor Saisa Lopez
2013-06-12 16:58:48 -04:00
parent c15432f92d
commit 34ec53f91c
5 changed files with 66 additions and 97 deletions

View File

@@ -571,6 +571,14 @@ class Bootstrap
*/ */
public function streamFile($file, $download = false, $downloadFileName = '') public function streamFile($file, $download = false, $downloadFileName = '')
{ {
$fileNameIni = $file;
$browserCacheFilesUid = G::browserCacheFilesGetUid();
if ($browserCacheFilesUid != null) {
$file = str_replace(".$browserCacheFilesUid", null, $file);
}
$folderarray = explode('/', $file); $folderarray = explode('/', $file);
$typearray = explode('.', basename($file)); $typearray = explode('.', basename($file));
$typefile = $typearray[count($typearray) - 1]; $typefile = $typearray[count($typearray) - 1];
@@ -578,14 +586,7 @@ class Bootstrap
//trick to generate the translation.language.js file , merging two files //trick to generate the translation.language.js file , merging two files
if (strtolower($typefile) == 'js' && $typearray[0] == 'translation') { if (strtolower($typefile) == 'js' && $typearray[0] == 'translation') {
Bootstrap::sendHeaders($filename, 'text/javascript', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/javascript", $download, $downloadFileName);
if ($typearray[1] != "enterprise" && $typearray[1] != "pmCaseArchive") {
$arrayAux = array($typearray[0], $typearray[1], $typearray[count($typearray) - 1]);
$filename = str_replace(implode(".", $typearray), implode(".", $arrayAux), $filename);
$typearray = $arrayAux;
}
$output = Bootstrap::streamJSTranslationFile($filename, $typearray[count($typearray) - 2]); $output = Bootstrap::streamJSTranslationFile($filename, $typearray[count($typearray) - 2]);
@@ -596,7 +597,7 @@ class Bootstrap
//trick to generate the big css file for ext style . //trick to generate the big css file for ext style .
if (strtolower($typefile) == 'css' && $folderarray[count($folderarray) - 2] == 'css') { if (strtolower($typefile) == 'css' && $folderarray[count($folderarray) - 2] == 'css') {
Bootstrap::sendHeaders($filename, 'text/css', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/css", $download, $downloadFileName);
$output = Bootstrap::streamCSSBigFile($typearray[0]); $output = Bootstrap::streamCSSBigFile($typearray[0]);
echo $output; echo $output;
return; return;
@@ -605,59 +606,59 @@ class Bootstrap
if (file_exists($filename)) { if (file_exists($filename)) {
switch (strtolower($typefile)) { switch (strtolower($typefile)) {
case 'swf': case 'swf':
Bootstrap::sendHeaders($filename, 'application/x-shockwave-flash', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "application/x-shockwave-flash", $download, $downloadFileName);
break; break;
case 'js': case 'js':
Bootstrap::sendHeaders($filename, 'text/javascript', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/javascript", $download, $downloadFileName);
break; break;
case 'htm': case 'htm':
case 'html': case 'html':
Bootstrap::sendHeaders($filename, 'text/html', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/html", $download, $downloadFileName);
break; break;
case 'htc': case 'htc':
Bootstrap::sendHeaders($filename, 'text/plain', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
break; break;
case 'json': case 'json':
Bootstrap::sendHeaders($filename, 'text/plain', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
break; break;
case 'gif': case 'gif':
Bootstrap::sendHeaders($filename, 'image/gif', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "image/gif", $download, $downloadFileName);
break; break;
case 'png': case 'png':
Bootstrap::sendHeaders($filename, 'image/png', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "image/png", $download, $downloadFileName);
break; break;
case 'jpg': case 'jpg':
Bootstrap::sendHeaders($filename, 'image/jpg', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "image/jpg", $download, $downloadFileName);
break; break;
case 'css': case 'css':
Bootstrap::sendHeaders($filename, 'text/css', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/css", $download, $downloadFileName);
break; break;
case 'xml': case 'xml':
Bootstrap::sendHeaders($filename, 'text/xml', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/xml", $download, $downloadFileName);
break; break;
case 'txt': case 'txt':
Bootstrap::sendHeaders($filename, 'text/html', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/html", $download, $downloadFileName);
break; break;
case 'doc': case 'doc':
case 'pdf': case 'pdf':
case 'pm': case 'pm':
case 'po': case 'po':
Bootstrap::sendHeaders($filename, 'application/octet-stream', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "application/octet-stream", $download, $downloadFileName);
break; break;
case 'php': case 'php':
if ($download) { if ($download) {
Bootstrap::sendHeaders($filename, 'text/plain', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
} else { } else {
require_once ($filename); require_once ($filename);
return; return;
} }
break; break;
case 'tar': case 'tar':
Bootstrap::sendHeaders($filename, 'application/x-tar', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "application/x-tar", $download, $downloadFileName);
break; break;
default: default:
//throw new Exception ( "Unknown type of file '$file'. " ); //throw new Exception ( "Unknown type of file '$file'. " );
Bootstrap::sendHeaders($filename, 'application/octet-stream', $download, $downloadFileName); Bootstrap::sendHeaders($fileNameIni, "application/octet-stream", $download, $downloadFileName);
break; break;
} }
} else { } else {
@@ -672,6 +673,7 @@ class Bootstrap
if (substr($filename, -10) == "ext-all.js") { if (substr($filename, -10) == "ext-all.js") {
$filename = PATH_GULLIVER_HOME . 'js/ext/min/ext-all.js'; $filename = PATH_GULLIVER_HOME . 'js/ext/min/ext-all.js';
} }
@readfile($filename); @readfile($filename);
} }

View File

@@ -5080,21 +5080,19 @@ class G
$arrayLibrary = array(); $arrayLibrary = array();
//Translations /js/ext/translation.en.js //Translations /js/ext/translation.en.js
$arrayLibrary["translation"] = ""; //Not use null //Translations /js/ext/translation.xxx.en.js //xxx is an plugin
$arrayLibrary["translation"] = 1; //Not use null
//Translation environment /jscore/labels/en.js //Translation environment /jscore/labels/en.js
$translationEnvFilePath = PATH_DATA . "META-INF" . PATH_SEP . "translations.env"; if (file_exists(PATH_DATA . "META-INF" . PATH_SEP . "translations.env")) {
$arrayData = unserialize(file_get_contents(PATH_DATA . "META-INF" . PATH_SEP . "translations.env"));
if (file_exists($translationEnvFilePath)) {
$arrayData = unserialize(file_get_contents($translationEnvFilePath));
$path = PATH_CORE . "js" . PATH_SEP . "labels" . PATH_SEP;
foreach ($arrayData as $index1 => $value1) { foreach ($arrayData as $index1 => $value1) {
foreach ($value1 as $index2 => $value2) { foreach ($value1 as $index2 => $value2) {
$record = $value2; $record = $value2;
if (file_exists($path . $record["LOCALE"] . ".js")) { if (file_exists(PATH_CORE . "js" . PATH_SEP . "labels" . PATH_SEP . $record["LOCALE"] . ".js")) {
$arrayLibrary[$record["LOCALE"]] = $path; $arrayLibrary[$record["LOCALE"]] = 1;
} }
} }
} }
@@ -5111,7 +5109,7 @@ class G
$lib->build_js_to = $lib->build_js_to . "/"; $lib->build_js_to = $lib->build_js_to . "/";
} }
$arrayLibrary[$lib->name] = PATH_TRUNK . $lib->build_js_to; $arrayLibrary[$lib->name] = 1;
} }
} }
@@ -5120,33 +5118,12 @@ class G
public static function browserCacheFilesSetUid() public static function browserCacheFilesSetUid()
{ {
//Set UID
$uid = G::generateUniqueID(); $uid = G::generateUniqueID();
$arrayData = array(); $arrayData = array();
$arrayData["browser_cache_files_uid"] = $uid; $arrayData["browser_cache_files_uid"] = $uid;
G::update_php_ini(PATH_CONFIG . "env.ini", $arrayData); G::update_php_ini(PATH_CONFIG . "env.ini", $arrayData);
//Set file JavaScript
$arrayLibrary = G::browserCacheFilesGetLibraryJs();
foreach ($arrayLibrary as $index => $value) {
$name = $index;
$path = $value;
if (!empty($path)) {
foreach (glob($path . $name . "*") as $file) {
if (preg_match("/^\.\w{32}\.js$/i", str_replace($path . $name, null, $file))) {
@unlink($file); //Delete old file
}
}
if (file_exists($path . $name . ".js")) {
@copy($path . $name . ".js", $path . $name . "." . $uid . ".js"); //Create new file
}
}
}
} }
public static function browserCacheFilesGetUid() public static function browserCacheFilesGetUid()
@@ -5175,20 +5152,7 @@ class G
$arrayLibrary = G::browserCacheFilesGetLibraryJs(); $arrayLibrary = G::browserCacheFilesGetLibraryJs();
if (isset($arrayLibrary[$index])) { if (isset($arrayLibrary[$index])) {
$path = $arrayLibrary[$index]; $url = str_replace($name, $arrayMatch[1] . "." . $browserCacheFilesUid . ".js", $url);
$sw = 0;
if (!empty($path)) {
if (file_exists($path . $arrayMatch[1] . "." . $browserCacheFilesUid . ".js")) {
$sw = 1;
}
} else {
$sw = 1;
}
if ($sw == 1) {
$url = str_replace($name, $arrayMatch[1] . "." . $browserCacheFilesUid . ".js", $url);
}
} }
} }
} }

View File

@@ -214,11 +214,9 @@ class headPublisher
$head = ''; $head = '';
$head .= '<TITLE>' . $this->title . "</TITLE>\n"; $head .= '<TITLE>' . $this->title . "</TITLE>\n";
$browserCacheFilesUid = G::browserCacheFilesGetUid();
$head = $head . " $head = $head . "
<script type=\"text/javascript\"> <script type=\"text/javascript\">
var BROWSER_CACHE_FILES_UID = \"" . (($browserCacheFilesUid != null && file_exists(PATH_TRUNK . "gulliver" . PATH_SEP . "js" . PATH_SEP . "maborak" . PATH_SEP . "core" . PATH_SEP . "maborak.$browserCacheFilesUid.js"))? $browserCacheFilesUid : null) . "\"; var BROWSER_CACHE_FILES_UID = \"" . G::browserCacheFilesGetUid() . "\";
</script> </script>
"; ";
@@ -310,12 +308,14 @@ class headPublisher
public function includeExtJs() public function includeExtJs()
{ {
$this->clearScripts(); $this->clearScripts();
$head = '';
$head .= " <script type='text/javascript' src='/js/ext/ext-base.js'></script>\n"; $head = "";
$head .= " <script type='text/javascript' src='/js/ext/ext-all.js'></script>\n"; $head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/ext-base.js") . "\"></script>\n";
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/ext-all.js") . "\"></script>\n";
$aux = explode('-', strtolower(SYS_LANG)); $aux = explode('-', strtolower(SYS_LANG));
if (($aux[0] != 'en') && file_exists(PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $aux[0] . '.js')) { if (($aux[0] != 'en') && file_exists(PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $aux[0] . '.js')) {
$head .= " <script type='text/javascript' src='/js/ext/locale/ext-lang-" . $aux[0] . ".js'></script>\n"; $head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/locale/ext-lang-" . $aux[0] . ".js") . "\"></script>\n";
} }
// enabled for particular use // enabled for particular use
@@ -333,7 +333,7 @@ class headPublisher
$head .= $this->getExtJsVariablesScript(); $head .= $this->getExtJsVariablesScript();
$oServerConf = & serverConf::getSingleton(); $oServerConf = & serverConf::getSingleton();
if ($oServerConf->isRtl(SYS_LANG)) { if ($oServerConf->isRtl(SYS_LANG)) {
$head .= " <script type='text/javascript' src='/js/ext/extjs_rtl.js'></script>\n"; $head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/extjs_rtl.js") . "\"></script>\n";
} }
return $head; return $head;
@@ -374,7 +374,7 @@ class headPublisher
$script = ''; $script = '';
if (isset($this->extJsScript) && is_array($this->extJsScript)) { if (isset($this->extJsScript) && is_array($this->extJsScript)) {
foreach ($this->extJsScript as $key => $file) { foreach ($this->extJsScript as $key => $file) {
$script .= " <script type='text/javascript' src='" . $file . ".js'></script>\n"; $script = $script . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($file . ".js") . "\"></script>\n";
} }
} }
return $script; return $script;
@@ -410,7 +410,7 @@ class headPublisher
$script = ''; $script = '';
if (isset($this->extJsLibrary) && is_array($this->extJsLibrary)) { if (isset($this->extJsLibrary) && is_array($this->extJsLibrary)) {
foreach ($this->extJsLibrary as $file) { foreach ($this->extJsLibrary as $file) {
$script .= " <script type='text/javascript' src='/js/ext/" . $file . ".js'></script>\n"; $script = $script . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/" . $file . ".js") . "\"></script>\n";
} }
} }
if (!in_array($this->translationsFile, $this->extJsLibrary)) { if (!in_array($this->translationsFile, $this->extJsLibrary)) {

View File

@@ -138,8 +138,6 @@ try {
$oStep = new Step(); $oStep = new Step();
$sUidGrids = $oStep->lookingforUidGrids( $sPRO_UID, $sDYNAFORM ); $sUidGrids = $oStep->lookingforUidGrids( $sPRO_UID, $sDYNAFORM );
$browserCacheFilesUid = G::browserCacheFilesGetUid();
$template->assign("URL_MABORAK_JS", G::browserCacheFilesUrl("/js/maborak/core/maborak.js")); $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("URL_TRANSLATION_ENV_JS", G::browserCacheFilesUrl("/jscore/labels/" . SYS_LANG . ".js"));
$template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]); $template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);

View File

@@ -72,6 +72,7 @@ function transactionLog($transactionName){
newrelic_name_transaction ($transactionName); newrelic_name_transaction ($transactionName);
} }
} }
// Defining the PATH_SEP constant, he we are defining if the the path separator symbol will be '\\' or '/' // Defining the PATH_SEP constant, he we are defining if the the path separator symbol will be '\\' or '/'
define( 'PATH_SEP', '/' ); define( 'PATH_SEP', '/' );
@@ -316,6 +317,15 @@ if (! defined( 'PATH_C' )) {
define( 'PATH_LANGUAGECONT', PATH_HOME . 'engine/content/languages/' ); define( 'PATH_LANGUAGECONT', PATH_HOME . 'engine/content/languages/' );
} }
//Call Gulliver Classes
Bootstrap::LoadThirdParty("smarty/libs", "Smarty.class");
//Loading the autoloader libraries feature
spl_autoload_register(array("Bootstrap", "autoloadClass"));
Bootstrap::registerClass("G", PATH_GULLIVER . "class.g.php");
Bootstrap::registerClass("System", PATH_HOME . "engine/classes/class.system.php");
// defining Virtual URLs // defining Virtual URLs
$virtualURITable = array (); $virtualURITable = array ();
$virtualURITable['/plugin/(*)'] = 'plugin'; $virtualURITable['/plugin/(*)'] = 'plugin';
@@ -405,6 +415,7 @@ if (Bootstrap::virtualURI( $_SERVER['REQUEST_URI'], $virtualURITable, $realPath
} }
die(); die();
} }
switch ($realPath) { switch ($realPath) {
case 'jsMethod': case 'jsMethod':
Bootstrap::parseURI( getenv( "REQUEST_URI" ) ); Bootstrap::parseURI( getenv( "REQUEST_URI" ) );
@@ -421,6 +432,7 @@ if (Bootstrap::virtualURI( $_SERVER['REQUEST_URI'], $virtualURITable, $realPath
die(); die();
break; break;
default: default:
//Process files loaded with tag head in HTML
if (substr( $realPath, 0, 12 ) == 'rest-service') { if (substr( $realPath, 0, 12 ) == 'rest-service') {
$isRestRequest = true; $isRestRequest = true;
} else { } else {
@@ -435,13 +447,6 @@ if (Bootstrap::virtualURI( $_SERVER['REQUEST_URI'], $virtualURITable, $realPath
} }
} //virtual URI parser } //virtual URI parser
// Call Gulliver Classes
Bootstrap::LoadThirdParty( 'smarty/libs', 'Smarty.class' );
//loading the autoloader libraries feature
spl_autoload_register(array('Bootstrap', 'autoloadClass'));
Bootstrap::registerClass('G', PATH_GULLIVER . "class.g.php");
Bootstrap::registerClass('System', PATH_HOME . "engine/classes/class.system.php");
// the request correspond to valid php page, now parse the URI // the request correspond to valid php page, now parse the URI
Bootstrap::parseURI( getenv( "REQUEST_URI" ), $isRestRequest ); Bootstrap::parseURI( getenv( "REQUEST_URI" ), $isRestRequest );
@@ -870,16 +875,16 @@ if (! defined( 'EXECUTE_BY_CRON' )) {
$noLoginFiles[] = 'appFolderAjax'; $noLoginFiles[] = 'appFolderAjax';
$noLoginFiles[] = 'steps_Ajax'; $noLoginFiles[] = 'steps_Ajax';
$noLoginFiles[] = 'proxyCasesList'; $noLoginFiles[] = 'proxyCasesList';
$noLoginFiles[] = 'casesStartPage_Ajax'; $noLoginFiles[] = 'casesStartPage_Ajax';
$noLoginFiles[] = 'appProxy'; $noLoginFiles[] = 'appProxy';
$noLoginFiles[] = 'cases_Ajax'; $noLoginFiles[] = 'cases_Ajax';
$noLoginFiles[] = 'casesList_Ajax'; $noLoginFiles[] = 'casesList_Ajax';
$noLoginFiles[] = 'proxyReassignCasesList'; $noLoginFiles[] = 'proxyReassignCasesList';
$noLoginFiles[] = 'ajaxListener'; $noLoginFiles[] = 'ajaxListener';
$noLoginFiles[] = 'cases_Step'; $noLoginFiles[] = 'cases_Step';
$noLoginFiles[] = 'cases_ShowOutputDocument'; $noLoginFiles[] = 'cases_ShowOutputDocument';
$noLoginFiles[] = 'cases_ShowDocument'; $noLoginFiles[] = 'cases_ShowDocument';
$noLoginFiles[] = 'cases_CatchExecute'; $noLoginFiles[] = 'cases_CatchExecute';
$noLoginFiles[] = 'cases_SaveData'; $noLoginFiles[] = 'cases_SaveData';
$noLoginFolders[] = 'services'; $noLoginFolders[] = 'services';