Exemple #1
0
    /**
     * Called from process(). This method will display the correct javascript.
     */
    protected function _displayJavascript()
    {
        global $locale, $sugar_config, $timedate;
        if ($this->_getOption('show_javascript')) {
            if (!$this->_getOption('show_header')) {
                $langHeader = get_language_header();
                echo <<<EOHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html {$langHeader}>
<head>
EOHTML;
            }
            $js_vars = array("sugar_cache_dir" => "cache/");
            if (isset($this->bean->module_dir)) {
                $js_vars['module_sugar_grp1'] = $this->bean->module_dir;
            }
            if (isset($_REQUEST['action'])) {
                $js_vars['action_sugar_grp1'] = $_REQUEST['action'];
            }
            echo '<script>jscal_today = 1000*' . $timedate->asUserTs($timedate->getNow()) . '; if(typeof app_strings == "undefined") app_strings = new Array();</script>';
            if (!is_file(sugar_cached("include/javascript/sugar_grp1.js")) || !is_file(sugar_cached("include/javascript/sugar_grp1_yui.js")) || !is_file(sugar_cached("include/javascript/sugar_grp1_jquery.js"))) {
                $_REQUEST['root_directory'] = ".";
                require_once "jssource/minify_utils.php";
                ConcatenateFiles(".");
            }
            echo getVersionedScript('cache/include/javascript/sugar_grp1_jquery.js');
            echo getVersionedScript('cache/include/javascript/sugar_grp1_yui.js');
            echo getVersionedScript('cache/include/javascript/sugar_grp1.js');
            echo getVersionedScript('include/javascript/calendar.js');
            // output necessary config js in the top of the page
            $config_js = $this->getSugarConfigJS();
            if (!empty($config_js)) {
                echo "<script>\n" . implode("\n", $config_js) . "</script>\n";
            }
            if (isset($sugar_config['email_sugarclient_listviewmaxselect'])) {
                echo "<script>SUGAR.config.email_sugarclient_listviewmaxselect = {$GLOBALS['sugar_config']['email_sugarclient_listviewmaxselect']};</script>";
            }
            $image_server = defined('TEMPLATE_URL') ? TEMPLATE_URL . '/' : '';
            echo '<script type="text/javascript">SUGAR.themes.image_server="' . $image_server . '";</script>';
            // cn: bug 12274 - create session-stored key to defend against CSRF
            echo '<script type="text/javascript">var name_format = "' . $locale->getLocaleFormatMacro() . '";</script>';
            echo self::getJavascriptValidation();
            if (!is_file(sugar_cached('jsLanguage/') . $GLOBALS['current_language'] . '.js')) {
                require_once 'include/language/jsLanguage.php';
                jsLanguage::createAppStringsCache($GLOBALS['current_language']);
            }
            echo getVersionedScript('cache/jsLanguage/' . $GLOBALS['current_language'] . '.js', $GLOBALS['sugar_config']['js_lang_version']);
            echo $this->_getModLanguageJS();
            if (isset($sugar_config['disc_client']) && $sugar_config['disc_client']) {
                echo getVersionedScript('modules/Sync/headersync.js');
            }
            //echo out the $js_vars variables as javascript variables
            echo "<script type='text/javascript'>\n";
            foreach ($js_vars as $var => $value) {
                echo "var {$var} = '{$value}';\n";
            }
            echo "</script>\n";
        }
    }
Exemple #2
0
    if (!empty($argv[2])) {
        if ($argv[2] == '-r') {
            //replace the compressed scripts with the backed up version
            reverseScripts("{$from}/jssource/src_files", "{$from}");
        } elseif ($argv[2] == '-m') {
            //replace the scripts, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", "{$from}");
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
        } elseif ($argv[2] == '-c') {
            //replace the scripts, concatenate the files, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", "{$from}");
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
            ConcatenateFiles("{$from}", true);
        } elseif ($argv[2] == '-mo') {
            //do not replace the scriptsjust minify the existing scripts again
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
        } elseif ($argv[2] == '-co') {
            //concatenate the files only
            ConcatenateFiles("{$from}", true);
        } elseif ($argv[2] == '-?') {
            die("\n    Usage : minify <root path> [[-r]|[-m]|[-c]]\n    \n    <root path> = path of directory to process.  Should be root of sugar instance.   \n     -r  = replace javascript of root with scripts from backed up jssource/src_files directory   \n     -m  = same as r, only the script is minified and then copied   \n     -c  = same as m, only the concatenated files are processed again.\n     -co = concatenates only the js files that are to be concatenated.  Main use is for development when files that make up a concatenated file have been modified.\n     -mo = minifies only the existing js files.  Will not use source files and will not back up scripts.  Main use is for development, when changes have been made to working javascript and you wish to recompress your scripts.\n            \n    *** note that options are mutually exclusive.  You would use -r OR -m OR -c          \n    \n    examples: say your patch is located in 'c:/sugar'\n    You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:\n        minify 'c:/sugar'                                \n            \n    You wish to have backed up jssource files replace your current javascript files:\n        minify 'c:/sugar' -r                                \n            \n    You wish to have backed up jssource files minified, and replace your current javascript files:\n        minify 'c:/sugar' -m                               \n            \n    You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:\n        minify 'c:/sugar' -c                               \n                                        ");
        }
    } else {
        //default is to concatenate the files, then back up and compress them
        if (empty($from)) {
            echo "directory root to process was not specified";
        }
        BackUpAndCompressScriptFiles("{$from}", '', true, true);
        ConcatenateFiles("{$from}", true);
    }
}
Exemple #3
0
    /**
     * Called from process(). This method will display the correct javascript.
     */
    protected function _displayJavascript()
    {
        global $locale, $sugar_config, $timedate;
        if ($this->_getOption('show_javascript')) {
            if (!$this->_getOption('show_header')) {
                echo <<<EOHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
EOHTML;
            }
            echo "<script>var sugar_cache_dir = '{$GLOBALS['sugar_config']['cache_dir']}';</script>";
            echo "<script>var sugar_upload_dir = '{$GLOBALS['sugar_config']['upload_dir']}';</script>";
            if (isset($this->bean->module_dir)) {
                echo "<script>var module_sugar_grp1 = '{$this->bean->module_dir}';</script>";
            }
            if (isset($_REQUEST['action'])) {
                echo "<script>var action_sugar_grp1 = '{$_REQUEST['action']}';</script>";
            }
            echo '<script>jscal_today = ' . 1000 * $timedate->asUserTs($timedate->getNow()) . '; if(typeof app_strings == "undefined") app_strings = new Array();</script>';
            if (!is_file("include/javascript/sugar_grp1.js") || !is_file("include/javascript/sugar_grp1_yui.js")) {
                $_REQUEST['root_directory'] = ".";
                require_once "jssource/minify_utils.php";
                ConcatenateFiles(".");
            }
            echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1_yui.js') . '"></script>';
            echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1.js') . '"></script>';
            echo '<script type="text/javascript" src="' . getJSPath('include/javascript/calendar.js') . '"></script>';
            if (isset($sugar_config['quicksearch_querydelay'])) {
                echo "<script>SUGAR.config.quicksearch_querydelay = {$GLOBALS['sugar_config']['quicksearch_querydelay']};</script>";
            }
            // cn: bug 12274 - prepare secret guid for asynchronous calls
            if (!isset($_SESSION['asynchronous_key']) || empty($_SESSION['asynchronous_key'])) {
                $_SESSION['asynchronous_key'] = create_guid();
            }
            $image_server = defined('TEMPLATE_URL') ? TEMPLATE_URL . '/' : '';
            echo '<script type="text/javascript">var asynchronous_key = "' . $_SESSION['asynchronous_key'] . '";SUGAR.themes.image_server="' . $image_server . '";</script>';
            // cn: bug 12274 - create session-stored key to defend against CSRF
            echo '<script type="text/javascript"> var name_format = "' . $locale->getLocaleFormatMacro() . '";</script>';
            echo self::getJavascriptValidation();
            if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $GLOBALS['current_language'] . '.js')) {
                require_once 'include/language/jsLanguage.php';
                jsLanguage::createAppStringsCache($GLOBALS['current_language']);
            }
            echo '<script type="text/javascript" src="' . $GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $GLOBALS['current_language'] . '.js?s=' . $GLOBALS['js_version_key'] . '&c=' . $GLOBALS['sugar_config']['js_custom_version'] . '&j=' . $GLOBALS['sugar_config']['js_lang_version'] . '"></script>';
            if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $this->module . '/' . $GLOBALS['current_language'] . '.js')) {
                require_once 'include/language/jsLanguage.php';
                jsLanguage::createModuleStringsCache($this->module, $GLOBALS['current_language']);
            }
            echo '<script type="text/javascript" src="' . $GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $this->module . '/' . $GLOBALS['current_language'] . '.js?s=' . $GLOBALS['js_version_key'] . '&c=' . $GLOBALS['sugar_config']['js_custom_version'] . '&j=' . $GLOBALS['sugar_config']['js_lang_version'] . '"></script>';
            if (isset($sugar_config['disc_client']) && $sugar_config['disc_client']) {
                echo '<script type="text/javascript" src="' . getJSPath('modules/Sync/headersync.js') . '"></script>';
            }
            echo '<script src="' . getJSPath('include/javascript/yui3/build/yui/yui-min.js') . '" type="text/javascript"></script>';
        }
        if (isset($_REQUEST['popup']) && !empty($_REQUEST['popup'])) {
            // cn: bug 12274 - add security metadata envelope for async calls in popups
            echo '<script type="text/javascript">var asynchronous_key = "' . $_SESSION['asynchronous_key'] . '";</script>';
            // cn: bug 12274 - create session-stored key to defend against CSRF
        }
    }
$from = getcwd();
if (isset($_REQUEST['root_directory']) && !empty($_REQUEST['root_directory'])) {
    $from = $_REQUEST['root_directory'];
}
//this script can take a while, change max execution time to 10 mins
$tmp_time = ini_get('max_execution_time');
ini_set('max_execution_time', '600');
//figure out which commands to call.
if ($_REQUEST['js_admin_repair'] == 'concat') {
    //concatenate mode, call the files that will concatenate javascript group files
    $_REQUEST['js_rebuild_concat'] = 'rebuild';
    require_once 'jssource/minify.php';
} else {
    $_REQUEST['root_directory'] = getcwd();
    require_once 'jssource/minify.php';
    if ($_REQUEST['js_admin_repair'] == 'replace') {
        //should replace compressed JS with source js
        reverseScripts("{$from}/jssource/src_files", "{$from}");
    } elseif ($_REQUEST['js_admin_repair'] == 'mini') {
        //should replace compressed JS with minified version of source js
        reverseScripts("{$from}/jssource/src_files", "{$from}");
        BackUpAndCompressScriptFiles("{$from}", "", false);
        ConcatenateFiles("{$from}");
    } elseif ($_REQUEST['js_admin_repair'] == 'repair') {
        //should compress existing javascript (including changes done) without overwriting original source files
        BackUpAndCompressScriptFiles("{$from}", "", false);
        ConcatenateFiles("{$from}");
    }
}
//set execution time back to what it was
ini_set('max_execution_time', $tmp_time);
    if (!empty($argv[2])) {
        if ($argv[2] == '-r') {
            //replace the compressed scripts with the backed up version
            reverseScripts("{$from}/jssource/src_files", $from);
        } elseif ($argv[2] == '-m') {
            //replace the scripts, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", $from);
            BackUpAndCompressScriptFiles($from, "", false, true);
        } elseif ($argv[2] == '-c') {
            //replace the scripts, concatenate the files, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", $from);
            BackUpAndCompressScriptFiles($from, "", false, true);
            ConcatenateFiles($from, true);
        } elseif ($argv[2] == '-mo') {
            //do not replace the scriptsjust minify the existing scripts again
            BackUpAndCompressScriptFiles($from, "", false, true);
        } elseif ($argv[2] == '-co') {
            //concatenate the files only
            ConcatenateFiles($from, true);
        } elseif ($argv[2] == '-?') {
            die("\n    Usage : minify <root path> [[-r]|[-m]|[-c]]\n\n    <root path> = path of directory to process.  Should be root of sugar instance.\n     -r  = replace javascript of root with scripts from backed up jssource/src_files directory\n     -m  = same as r, only the script is minified and then copied\n     -c  = same as m, only the concatenated files are processed again.\n     -co = concatenates only the js files that are to be concatenated.  Main use is for development when files that make up a concatenated file have been modified.\n     -mo = minifies only the existing js files.  Will not use source files and will not back up scripts.  Main use is for development, when changes have been made to working javascript and you wish to recompress your scripts.\n\n    *** note that options are mutually exclusive.  You would use -r OR -m OR -c\n\n    examples: say your patch is located in 'c:/sugar'\n    You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:\n        minify 'c:/sugar'\n\n    You wish to have backed up jssource files replace your current javascript files:\n        minify 'c:/sugar' -r\n\n    You wish to have backed up jssource files minified, and replace your current javascript files:\n        minify 'c:/sugar' -m\n\n    You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:\n        minify 'c:/sugar' -c\n                                        ");
        }
    } else {
        //default is to concatenate the files, then back up and compress them
        if (empty($from)) {
            echo "directory root to process was not specified";
        }
        BackUpAndCompressScriptFiles($from, '', true, true);
        ConcatenateFiles($from, true);
    }
}