function checkAndConvertJsScripts($jsFileNames) { $fileExtension = 'js'; $jsScriptInstances = array(); foreach ($jsFileNames as $jsFileName) { // TODO Handle absolute inclusions (...) like in checkAndConvertCssStyles $jsScript = new Vtiger_JsScript_Model(); // external javascript source file handling if (strpos($jsFileName, 'http://') === 0 || strpos($jsFileName, 'https://') === 0) { $jsScriptInstances[$jsFileName] = $jsScript->set('src', $jsFileName); continue; } $completeFilePath = Vtiger_Loader::resolveNameToPath($jsFileName, $fileExtension); $minFilePath = str_replace('.js', '.min.js', $completeFilePath); if (Vtiger_Functions::getMinimizationOptions($fileExtension) && file_exists($minFilePath)) { $minjsFileName = str_replace('.js', '.min.js', $jsFileName); if (strpos($minjsFileName, '~') === 0) { $minjsFileName = ltrim(ltrim($minjsFileName, '~'), '/'); } else { $minjsFileName = str_replace('.', '/', $jsFileName) . '.' . $fileExtension; } $jsScriptInstances[$jsFileName] = $jsScript->set('src', $minjsFileName); } else { if (file_exists($completeFilePath)) { if (strpos($jsFileName, '~') === 0) { $filePath = ltrim(ltrim($jsFileName, '~'), '/'); } else { $filePath = str_replace('.', '/', $jsFileName) . '.' . $fileExtension; } $jsScriptInstances[$jsFileName] = $jsScript->set('src', $filePath); } else { if (Vtiger_Functions::getMinimizationOptions($fileExtension)) { $fallBackFilePath = Vtiger_Loader::resolveNameToPath(Vtiger_JavaScript::getBaseJavaScriptPath() . '/' . $jsFileName . $min, 'js'); if (file_exists($fallBackFilePath)) { $filePath = str_replace('.', '/', $jsFileName) . $min . '.js'; $jsScriptInstances[$jsFileName] = $jsScript->set('src', Vtiger_JavaScript::getFilePath($filePath)); } } $fallBackFilePath = Vtiger_Loader::resolveNameToPath(Vtiger_JavaScript::getBaseJavaScriptPath() . '/' . $jsFileName, 'js'); if (file_exists($fallBackFilePath)) { $filePath = str_replace('.', '/', $jsFileName) . '.js'; $jsScriptInstances[$jsFileName] = $jsScript->set('src', Vtiger_JavaScript::getFilePath($filePath)); } } } } return $jsScriptInstances; }
function checkAndConvertJsScripts($jsFileNames) { $fileExtension = 'js'; $jsScriptInstances = array(); foreach ($jsFileNames as $jsFileName) { // TODO Handle absolute inclusions (~/...) like in checkAndConvertCssStyles $jsScript = new Vtiger_JsScript_Model(); // external javascript source file handling if (strpos($jsFileName, 'http://') === 0 || strpos($jsFileName, 'https://') === 0) { $jsScriptInstances[$jsFileName] = $jsScript->set('src', $jsFileName); continue; } $completeFilePath = Vtiger_Loader::resolveNameToPath($jsFileName, $fileExtension); if (file_exists($completeFilePath)) { if (strpos($jsFileName, '~') === 0) { $filePath = ltrim(ltrim($jsFileName, '~'), '/'); // if ~~ (reference is outside vtiger6 folder) if (substr_count($jsFileName, "~") == 2) { $filePath = "../" . $filePath; } } else { $filePath = str_replace('.', '/', $jsFileName) . '.' . $fileExtension; } $jsScriptInstances[$jsFileName] = $jsScript->set('src', $filePath); } else { $fallBackFilePath = Vtiger_Loader::resolveNameToPath(Vtiger_JavaScript::getBaseJavaScriptPath() . '/' . $jsFileName, 'js'); if (file_exists($fallBackFilePath)) { $filePath = str_replace('.', '/', $jsFileName) . '.js'; $jsScriptInstances[$jsFileName] = $jsScript->set('src', Vtiger_JavaScript::getFilePath($filePath)); } } } return $jsScriptInstances; }
function checkAndConvertJsScripts($jsFileNames) { $fileExtension = 'js'; $jsScriptInstances = array(); foreach ($jsFileNames as $jsFileName) { $jsScript = new Vtiger_JsScript_Model(); // external javascript source file handling if (strpos($jsFileName, 'http://') === 0 || strpos($jsFileName, 'https://') === 0) { $jsScriptInstances[$jsFileName] = $jsScript->set('src', $jsFileName); continue; } $completeFilePath = Vtiger_Loader::resolveNameToPath($jsFileName, $fileExtension); if (file_exists($completeFilePath)) { if (strpos($jsFileName, '~') === 0) { $filePath = ltrim(ltrim($jsFileName, '~'), '/'); } else { $filePath = str_replace('.', '/', $jsFileName) . '.' . $fileExtension; } $jsScriptInstances[$jsFileName] = $jsScript->set('src', $filePath); } else { $fallBackFilePath = Vtiger_Loader::resolveNameToPath(Vtiger_JavaScript::getBaseJavaScriptPath() . '/' . $jsFileName, 'js'); if (file_exists($fallBackFilePath)) { $filePath = str_replace('.', '/', $jsFileName) . '.js'; $jsScriptInstances[$jsFileName] = $jsScript->set('src', Vtiger_JavaScript::getFilePath($filePath)); } } } return $jsScriptInstances; }