Ignore:
Timestamp:
Nov 18, 2013, 6:01:11 AM (11 years ago)
Author:
rvelices
Message:

bug 2963: Ability to create css/js smarty templates - fixes rare cases + code simplifications

File:
1 edited

Legend:

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

    r25506 r25544  
    10471047  {
    10481048    uasort($this->registered_css, array('CssLoader', 'cmp_by_order'));
    1049     return self::do_combine($this->registered_css);
     1049    $combiner = new FileCombiner('css', $this->registered_css);
     1050    return $combiner->combine();
    10501051  }
    10511052 
     
    10531054  {
    10541055    return $a->order - $b->order;
    1055   }
    1056  
    1057   private static function do_combine($files)
    1058   {
    1059     $combiner = new FileCombiner('css');
    1060     foreach ($files as $css)
    1061     {
    1062       $combiner->add( $css);
    1063     }
    1064     return $combiner->combine();
    10651056  }
    10661057 
     
    12531244  private static function do_combine($scripts, $load_mode)
    12541245  {
    1255     $combiner = new FileCombiner('js');
    1256     foreach ($scripts as $script)
    1257     {
    1258       $combiner->add( $script);
    1259     }
     1246    $combiner = new FileCombiner('js', $scripts);
    12601247    return $combiner->combine();
    12611248  }
     
    13781365  private $type; // js or css
    13791366  private $is_css;
    1380   private $combinables = array();
    1381 
    1382   function FileCombiner($type)
     1367  private $combinables;
     1368
     1369  function FileCombiner($type, $combinables)
    13831370  {
    13841371    $this->type = $type;
    13851372    $this->is_css = $type=='css';
     1373    $this->combinables = $combinables;
    13861374  }
    13871375
     
    13971385  }
    13981386
    1399   function add($combinable)
    1400   {
    1401     $this->combinables[] = $combinable;
     1387  function add($combinables)
     1388  {
     1389    foreach($combinables as $combinable)
     1390      $this->combinables[] = $combinable;
    14021391  }
    14031392
     
    14141403    $result = array();
    14151404    $pending = array();
    1416     $key = $this->is_css ? array(get_absolute_root_url(false)): array(); //because for css we modify bg url
     1405    $ini_key = $this->is_css ? array(get_absolute_root_url(false)): array(); //because for css we modify bg url;
     1406    $key = $ini_key;
    14171407
    14181408    foreach ($this->combinables as $combinable)
    14191409    {
    1420       if ($conf['template_combine_files'] && !$combinable->is_remote())
    1421       {
    1422         $key[] = $combinable->path;
    1423         $key[] = $combinable->version;
    1424         if ($conf['template_compile_check'])
    1425           $key[] = filemtime( PHPWG_ROOT_PATH . $combinable->path );
    1426         $pending[] = $combinable;
    1427       }
    1428       else
     1410      if ($combinable->is_remote())
    14291411      {
    14301412        $this->flush_pending($result, $pending, $key, $force);
    1431         $key = $this->is_css ? array(get_absolute_root_url(false)): array(); //because for css we modify bg url
    1432         if ($combinable->is_remote())
    1433           $result[] = $combinable;
    1434         else
    1435           $pending = array($combinable);
    1436       }
     1413        $key = $ini_key;
     1414        $result[] = $combinable;
     1415        continue;
     1416      }
     1417      elseif (!$conf['template_combine_files'])
     1418      {
     1419        $this->flush_pending($result, $pending, $key, $force);
     1420        $key = $ini_key;
     1421      }
     1422
     1423      $key[] = $combinable->path;
     1424      $key[] = $combinable->version;
     1425      if ($conf['template_compile_check'])
     1426        $key[] = filemtime( PHPWG_ROOT_PATH . $combinable->path );
     1427      $pending[] = $combinable;
    14371428    }
    14381429    $this->flush_pending($result, $pending, $key, $force);
Note: See TracChangeset for help on using the changeset viewer.