Ignore:
Timestamp:
Dec 17, 2010, 7:33:16 AM (13 years ago)
Author:
rvelices
Message:

combined css and js are minified

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/template.class.php

    r8162 r8170  
    399399              $content[]=
    400400                  '<script type="text/javascript" src="'
    401                   . Template::make_script_src($script)
     401                  . self::make_script_src($script)
    402402                  .'"></script>';
    403403          }
     
    996996  }
    997997
    998         private static function do_combine($scripts, $load_mode)
    999         {
    1000                 global $conf;
    1001                 if (count($scripts)<2 or !$conf['template_combine_files'])
    1002                         return $scripts;
    1003                 $combiner = new FileCombiner('js');
    1004                 foreach ($scripts as $script)
    1005                 {
    1006                         if ($script->is_remote()) fatal_error("NOT IMPLEMENTED");// TODO - we cannot combine remote scripts
    1007                         $combiner->add( $script->path, $script->version );
    1008                 }
    1009                 if ( $combiner->combine( $out_file, $out_version) )
    1010                 {
    1011                         return array( 'combi' => new Script($load_mode, 'combi', $out_file, $out_version, array() ) );
    1012                 }
    1013                 return null;
    1014         }
    1015        
    1016         // checks that if B depends on A, then B->load_mode >= A->load_mode in order to respect execution order
     998  private static function do_combine($scripts, $load_mode)
     999  {
     1000    global $conf;
     1001    if (count($scripts)<2 or !$conf['template_combine_files'])
     1002      return $scripts;
     1003    $combiner = new FileCombiner('js');
     1004    foreach ($scripts as $script)
     1005    {
     1006      if ($script->is_remote()) fatal_error("NOT IMPLEMENTED");// TODO - we cannot combine remote scripts
     1007      $combiner->add( $script->path, $script->version );
     1008    }
     1009    if ( $combiner->combine( $out_file, $out_version) )
     1010    {
     1011      return array( 'combi' => new Script($load_mode, 'combi', $out_file, $out_version, array() ) );
     1012    }
     1013    return null;
     1014  }
     1015 
     1016  // checks that if B depends on A, then B->load_mode >= A->load_mode in order to respect execution order
    10171017  private static function check_load_dep($scripts)
    10181018  {
    1019                 global $conf;
     1019    global $conf;
    10201020    do
    10211021    {
     
    10621062  }
    10631063
    1064   private function compute_script_topological_order($script_id)
     1064  private function compute_script_topological_order($script_id, $recursion_limiter=0)
    10651065  {
    10661066    if (!isset($this->registered_scripts[$script_id]))
     
    10691069      return 0;
    10701070    }
     1071    $recursion_limiter<5 or fatal_error("combined script circular dependency");
    10711072    $script = & $this->registered_scripts[$script_id];
    10721073    if (isset($script->extra['order']))
     
    10761077    $max = 0;
    10771078    foreach( $script->precedents as $precedent)
    1078       $max = max($max, $this->compute_script_topological_order($precedent) );
     1079      $max = max($max, $this->compute_script_topological_order($precedent, $recursion_limiter+1) );
    10791080    $max++;
    10801081    return ($script->extra['order'] = $max);
     
    12091210    if (strpos($file, '.min')===false and strpos($file, '.packed')===false )
    12101211    {
    1211       //TODO minify javascript with some php lib from www...
     1212      require_once(PHPWG_ROOT_PATH.'include/jsmin.class.php');
     1213      try { $js = JSMin::minify($js); } catch(Exception $e) {}
    12121214    }
    12131215    return $js;
     
    12151217 
    12161218  private static function process_css($file)
     1219  {
     1220    $css = self::process_css_rec($file);
     1221    require_once(PHPWG_ROOT_PATH.'include/cssmin.class.php');
     1222    $css = CssMin::minify($css, array('emulate-css3-variables'=>false));
     1223    return $css;
     1224  }
     1225 
     1226  private static function process_css_rec($file)
    12171227  {
    12181228    static $PATTERN = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#";
     
    12401250      {
    12411251        $search[] = $match[0];
    1242         $replace[] = self::process_css(dirname($file) . "/$match[1]");
     1252        $replace[] = self::process_css_rec(dirname($file) . "/$match[1]");
    12431253      }
    12441254      $css = str_replace($search, $replace, $css);
Note: See TracChangeset for help on using the changeset viewer.