Beispiel #1
0
/**
 * Handler for HOOK_PRE_RENDER
 * 
 * Checks if there are minified files present as sets up ScavixWDF to use them.
 * Do not call this directly!
 * @param mixed $args Do not call!
 * @return void
 */
function minify_pre_render_handler($args)
{
    if (count($args) > 0) {
        if (minify_forbidden($args[0])) {
            return;
        }
    }
    $target_base_name = cfg_get('minify', 'target_path');
    system_ensure_path_ending($target_base_name, true);
    $target_base_name .= cfg_get('minify', 'base_name');
    $base_uri = cfg_get('minify', 'url');
    use_minified_file($target_base_name, 'js', $base_uri);
    use_minified_file($target_base_name, 'css', $base_uri);
}
Beispiel #2
0
/**
 * Initializes the translation essential.
 * 
 * @return void
 */
function translation_init()
{
    global $CONFIG;
    $GLOBALS['__unknown_constants'] = array();
    $GLOBALS['__translate_functions'] = array();
    if (!isset($CONFIG['translation']['data_path'])) {
        //log_warn('Please define $CONFIG["translation"]["data_path"]');
        $CONFIG['translation']['data_path'] = __DIR__ . '/UNDEFINED/';
    }
    if (isset($CONFIG['translation']['sync']['provider']) && $CONFIG['translation']['sync']['provider']) {
        if (!isset($CONFIG['translation']['sync']['datasource'])) {
            $CONFIG['translation']['sync']['datasource'] = 'internal';
        }
        $CONFIG['class_path']['system'][] = __DIR__ . '/translation/';
        $CONFIG['class_path']['system'][] = __DIR__ . '/translation/' . strtolower($CONFIG['translation']['sync']['provider']) . '/';
    } else {
        $CONFIG['translation']['sync']['datasource'] = false;
    }
    if (!isset($CONFIG['translation']['searchpatterns'])) {
        $CONFIG['translation']['searchpatterns'] = array();
    }
    if (!isset($CONFIG['translation']['minlangtransrate'])) {
        $CONFIG['translation']['minlangtransrate'] = 0.75;
    }
    if (!isset($CONFIG['localization']['default_language'])) {
        $CONFIG['localization']['default_language'] = "en";
    }
    if (!isset($CONFIG['translation']['detect_ci_callback'])) {
        $CONFIG['translation']['detect_ci_callback'] = false;
    }
    if (!isset($CONFIG['translation']['default_strings'])) {
        $CONFIG['translation']['default_strings'] = array();
    }
    $CONFIG['translation']['searchpatterns'] = array_merge($CONFIG['translation']['searchpatterns'], array("WINDOW_", "TITLE_", "BTN_", "TXT_", "ERR_"));
    // build reg pattern once:
    $reg = array();
    foreach ($CONFIG['translation']['searchpatterns'] as $pat) {
        $reg[] = '(' . $pat . '[a-zA-Z0-9_-]+)(\\[[^\\]]+\\])*';
    }
    $reg = "/" . implode("|", $reg) . "/";
    $GLOBALS['__translate_regpattern'] = $reg;
    $GLOBALS['translation']['data'] = array();
    system_ensure_path_ending($CONFIG['translation']['data_path']);
}
 /**
  * @attribute[RequestParam('submitter','bool',false)]
  * @attribute[RequestParam('skip_minify','bool',false)]
  * @attribute[RequestParam('random_nc','bool',false)]
  */
 function Start($submitter, $skip_minify, $random_nc)
 {
     global $CONFIG;
     if (!$submitter) {
         $this->_contentdiv->content("<h1>Select what to minify</h1>");
         $form = $this->_contentdiv->content(new Form());
         $form->AddHidden('submitter', '1');
         $form->AddCheckbox('skip_minify', 'Skip minify (only collect and combine)<br/>');
         $form->AddCheckbox('random_nc', 'Generate random name (instead of app version)<br/>');
         $form->AddSubmit('Go');
         return;
     }
     $this->_contentdiv->content("<h1>Minify DONE</h1>");
     $parts = array_diff($CONFIG['class_path']['order'], array('system', 'model', 'content'));
     $paths = array();
     foreach ($parts as $part) {
         $paths = array_merge($paths, $CONFIG['class_path'][$part]);
     }
     sort($paths);
     $root_paths = array();
     foreach ($paths as $i => $cp) {
         $root = true;
         for ($j = 0; $j < $i && $root; $j++) {
             if (starts_with($cp, $paths[$j])) {
                 $root = false;
             }
         }
         if ($root) {
             $root_paths[] = $cp;
         }
     }
     if ($skip_minify) {
         $GLOBALS['nominify'] = '1';
     }
     $target_path = cfg_get('minify', 'target_path');
     system_ensure_path_ending($target_path, true);
     $target = $target_path . cfg_get('minify', 'base_name');
     minify_all($root_paths, $target, $random_nc ? md5(time()) : getAppVersion('nc'));
 }
/**
 * Lists all files of a directory recursively.
 * 
 * Note that default pattern in *.* thus only listing files with a dot in the name.
 * If you change that to '*' everything will be returned.
 * We use *.* a common filter for all files (yes, we know that this is wrong).
 * @param string $directory Directory name
 * @param string $pattern Filename pattern
 * @return array Listing of all files
 */
function system_glob_rec($directory = '', $pattern = '*.*')
{
    system_ensure_path_ending($directory);
    $paths = system_glob($directory . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
    $files = system_glob($directory . $pattern);
    foreach ($paths as $path) {
        $files = array_merge($files, system_glob_rec($path, $pattern));
    }
    return $files;
}