예제 #1
0
/**
 * Ensures that a javascript cache file exists and if it doesn't, will create
 * the necessary JS Groupings files into the cache directory for consumption.
 *
 * @param array $files The basename of the file to check or an array of names to check
 * @param string $root The directory off which the cache file path lives
 * @param boolean $addPath Adds the path to the cache for this file if true
 * @return string|array The path to the single file specified, or the collection of files specified
 */
function ensureJSCacheFilesExist($files = array(), $root = '.', $addPath = true)
{
    // Create a reasonable default. Using sugar_sidecar since that is what was
    // used in ensureCache as a default
    if (empty($files)) {
        $files = array('sugar_sidecar.min.js');
    }
    // Make this an array to facilitate more than one file check
    if (!is_array($files)) {
        $files = array($files);
    }
    // Prepare the return
    $return = array();
    // Check existence of files to allow building only when necessary
    $cacheExists = true;
    foreach ($files as $f) {
        // Build the path to the file we are looking for
        if ($addPath) {
            $path = "{$root}/" . sugar_cached("include/javascript/{$f}");
        } else {
            $path = "{$root}/{$f}";
        }
        // Keep track of existence
        $cacheExists = $cacheExists && file_exists($path) && is_file($path);
        // Add this file to the return stack
        $return[] = $path;
    }
    // If even one of the files doesn't exist, rebuild
    if (!$cacheExists) {
        // Maintain state as well as possible
        $rd = isset($_REQUEST['root_directory']) ? $_REQUEST['root_directory'] : null;
        // Build the concatenated files
        $_REQUEST['root_directory'] = $root;
        require_once "jssource/minify_utils.php";
        $minifyUtils = new SugarMinifyUtils();
        $minifyUtils->ConcatenateFiles($root);
        // Cleanup the root directory request var if it was found. If it was null
        // this will in effect unset it
        $_REQUEST['root_directory'] = $rd;
    }
    // For a single file check return just that file
    if (count($return) == 1) {
        return $return[0];
    }
    // For multiple file checks return all files
    return $return;
}
예제 #2
0
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 {
    if ($_REQUEST['js_admin_repair'] === 'sidecar') {
        $dir = getcwd();
        chdir('sidecar');
        shell_exec('php -f build.php p');
        chdir($dir);
    } else {
        $_REQUEST['root_directory'] = getcwd();
        require_once 'jssource/minify.php';
        $minifyUtils = new SugarMinifyUtils();
        if ($_REQUEST['js_admin_repair'] == 'replace') {
            //should replace compressed JS with source js
            $minifyUtils->reverseScripts("{$from}/jssource/src_files", "{$from}");
        } elseif ($_REQUEST['js_admin_repair'] == 'mini') {
            //should replace compressed JS with minified version of source js
            $minifyUtils->reverseScripts("{$from}/jssource/src_files", "{$from}");
            $minifyUtils->BackUpAndCompressScriptFiles("{$from}", "", false);
            $minifyUtils->ConcatenateFiles("{$from}");
        } elseif ($_REQUEST['js_admin_repair'] == 'repair') {
            //should compress existing javascript (including changes done) without overwriting original source files
            $minifyUtils->BackUpAndCompressScriptFiles("{$from}", "", false);
            $minifyUtils->ConcatenateFiles("{$from}");
        }
    }
}
//set execution time back to what it was
ini_set('max_execution_time', $tmp_time);
예제 #3
0
    protected function _displayLoginJS()
    {
        global $sugar_config, $timedate;
        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(sugar_cached("include/javascript/sugar_grp1.js"))) {
            $_REQUEST['root_directory'] = ".";
            require_once "jssource/minify_utils.php";
            $minifyUtils = new SugarMinifyUtils();
            $minifyUtils->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');
        if (!is_file(sugar_cached("Expressions/functions_cache.js"))) {
            $GLOBALS['updateSilent'] = true;
            include "include/Expressions/updatecache.php";
        }
        if (inDeveloperMode()) {
            echo getVersionedScript('cache/Expressions/functions_cache_debug.js');
        } else {
            echo getVersionedScript('cache/Expressions/functions_cache.js');
        }
        echo <<<EOQ
        <script>
            if ( typeof(SUGAR) == 'undefined' ) {SUGAR = {}};
            if ( typeof(SUGAR.themes) == 'undefined' ) SUGAR.themes = {};
        </script>
EOQ;
        if (isset($sugar_config['disc_client']) && $sugar_config['disc_client']) {
            echo getVersionedScript('modules/Sync/headersync.js');
        }
    }
예제 #4
0
 }
 $minifyUtils = new SugarMinifyUtils();
 //if second argument is set, then process commands
 if (!empty($argv[2])) {
     if ($argv[2] == '-r') {
         //replace the compressed scripts with the backed up version
         $minifyUtils->reverseScripts("{$from}/jssource/src_files", $from);
     } elseif ($argv[2] == '-m') {
         //replace the scripts, and then minify the scripts again
         $minifyUtils->reverseScripts("{$from}/jssource/src_files", $from);
         $minifyUtils->BackUpAndCompressScriptFiles($from, "", false, true);
     } elseif ($argv[2] == '-c') {
         //replace the scripts, concatenate the files, and then minify the scripts again
         $minifyUtils->reverseScripts("{$from}/jssource/src_files", $from);
         $minifyUtils->BackUpAndCompressScriptFiles($from, "", false, true);
         $minifyUtils->ConcatenateFiles($from, true);
     } elseif ($argv[2] == '-mo') {
         //do not replace the scriptsjust minify the existing scripts again
         $minifyUtils->BackUpAndCompressScriptFiles($from, "", false, true);
     } elseif ($argv[2] == '-co') {
         //concatenate the files only
         $minifyUtils->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";
     }
     $minifyUtils->BackUpAndCompressScriptFiles($from, '', true, true);