Development

Changeset 10092

You must first sign up to be able to contribute.

Changeset 10092

Show
Ignore:
Timestamp:
07/03/08 15:46:16 (2 months ago)
Author:
KRavEN
Message:

moving trunk back to 0.1.0 to create tag

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfCombineFilterPlugin/trunk/README

    r6025 r10092  
    7575 
    7676Initial public release. 
    77  
    78 === 2007-08-02 | 0.1.1 beta === 
    79  
    80 Changes by Kiril Angov: 
    81  - Fixes regular expression to match '^/css/' 
    82  - Fixes issues when included files outside of root css and js directories. 
    83  - New: Option to minify the js using JSMin. 
  • plugins/sfCombineFilterPlugin/trunk/lib/sfCombineFilter.class.php

    r6025 r10092  
    33 * This file is part of the sfCombineFilter package. 
    44 * 
    5  * sfCombineFilter.class.php (c) 2007 Scott Meves. 
     5 * sfCombineFilter.class.php (c) 2007 Scott Meves.  
    66 * Combine.php Copyright (c) 2006 by Niels Leenheer 
    77 * 
     
    1212/** 
    1313 * This filter combines requested js and css files into a single request each. 
    14  * 
     14 *  
    1515 * @package      sfCombineFilter 
    1616 * @subpackage   filter 
    1717 * @author       Scott Meves <scott@stereointeractive.com> 
    18  * 
     18 *  
    1919 */ 
    2020class sfCombineFilter extends sfFilter 
    2121{ 
    22  
     22   
    2323  public function execute ($filterChain) 
    2424  { 
    2525    $filterChain->execute(); 
    2626 
     27    sfLoader::loadHelpers('Asset'); 
     28         
    2729    if ($this->getParameter('javascripts', true)) { 
    2830      $this->getCombinedJavascripts(); 
    2931    } 
    30  
     32     
    3133    if ($this->getParameter('stylesheets', true)) { 
    32       $this->getCombinedStylesheets(); 
     34      $this->getCombinedStylesheets();   
    3335    } 
    3436  } 
    35  
     37   
    3638  protected function getCombinedJavascripts() 
    3739  { 
    38     $response = $this->getContext()->getResponse(); 
     40    $response = $this->getContext()->getResponse();     
    3941    $sf_relative_url_root = $this->getContext()->getRequest()->getRelativeUrlRoot(); 
    4042    $root_js_only = $this->getParameter('root_js_only', true); 
    41  
     43     
    4244    $already_seen = array(); 
    4345    $combined_sources = array(); 
    44  
     46     
    4547    foreach (array('first', '', 'last') as $position) 
    4648    { 
     
    5759 
    5860          $already_seen[$file] = 1; 
    59  
     61           
    6062          if (is_array($options) && $this->isAbsolutePath($options)) 
    6163          { 
    6264            continue; 
    6365          } 
    64  
     66           
    6567          $path = _compute_public_path($file, 'js', 'js'); 
    66  
     68                     
    6769          if ((!$root_js_only && !strpos($path, '://')) || ($root_js_only && strpos($path, $sf_relative_url_root.'/js/') === 0)) { 
    68             $combined_sources[] = ($root_js_only ? preg_replace("/^".str_replace('/', '\/', $sf_relative_url_root.'/js/')."/i", '', $path) : $path); 
     70            $combined_sources[] = ($root_js_only ? str_replace($sf_relative_url_root.'/js/', '', $path) : $path); 
    6971            $response->getParameterHolder()->remove($file, 'helper/asset/auto/javascript'.($position ? '/'.$position : '')); 
    7072          } 
     
    7274      } 
    7375    } 
    74  
     76     
    7577    if (count($combined_sources)) { 
    7678      $combined_sources_str = $sf_relative_url_root . '/js/packed/' . implode(',', $combined_sources); 
    7779      $response->addJavascript($combined_sources_str, ''); 
    7880    } 
    79  
     81     
    8082  } 
    81  
     83   
    8284  protected function getCombinedStylesheets() 
    8385  { 
    84     $response = $this->getContext()->getResponse(); 
     86    $response = $this->getContext()->getResponse();     
    8587    $sf_relative_url_root = $this->getContext()->getRequest()->getRelativeUrlRoot(); 
    8688    $root_css_only = $this->getParameter('root_css_only', true); 
    87  
     89         
    8890    $already_seen = array(); 
    8991    $combined_sources = array(); 
    90  
     92     
    9193    foreach (array('first', '', 'last') as $position) 
    9294    { 
     
    103105 
    104106          $already_seen[$file] = 1; 
    105  
     107           
    106108          if (is_array($options) && ($this->isInvalidMediaType($options) || $this->isAbsolutePath($options))) 
    107109          { 
    108110            continue; 
    109111          } 
    110  
     112           
    111113          $path = _compute_public_path($file, 'css', 'css'); 
    112  
     114           
    113115          if ((!$root_css_only && !strpos($path, '://')) || ($root_css_only && strpos($path, $sf_relative_url_root.'/css/') === 0)) { 
    114             $combined_sources[] = (!$root_css_only ? preg_replace("/^".str_replace('/', '\/', $sf_relative_url_root.'/css/')."/i", '', $path) : $path); 
     116            $combined_sources[] = (!$root_css_only ? str_replace($sf_relative_url_root.'/css/', '', $path) : $path); 
    115117            $response->getParameterHolder()->remove($file, 'helper/asset/auto/stylesheet'.($position ? '/'.$position : '')); 
    116118          } 
     
    128130    return isset($options['media']) && !in_array($options['media'], array('', 'all', 'screen')); 
    129131  } 
    130  
     132   
    131133  protected function isAbsolutePath($options) { 
    132134    return isset($options['absolute']) && $options['absolute'] == true; 
  • plugins/sfCombineFilterPlugin/trunk/package.xml

    r6025 r10092  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2007-08-01</date> 
    14  <time>23:50:02</time> 
     13 <date>2007-07-26</date> 
     14 <time>11:34:37</time> 
    1515 <version> 
    16   <release>0.1.1</release> 
    17   <api>0.1.1</api> 
     16  <release>0.1.0</release> 
     17  <api>0.1.0</api> 
    1818 </version> 
    1919 <stability> 
     
    2525 <contents> 
    2626  <dir name="/"> 
    27    <file md5sum="86e7cd2d5f0386b575804ed6332e6940" name="lib/sfCombineFilter.class.php" role="data" /> 
    28    <file md5sum="f3405423799e62528a9ff46a059e1315" name="lib/JSMin.class.php" role="data" /> 
    29    <file md5sum="05c3b05532b187a2a6e173d36f6aee19" name="web/combine.php" role="data" /> 
    30    <file md5sum="d870ba4c56e95678233ea66ec1bc3ea0" name="README" role="data" /> 
     27   <file md5sum="fd27c01a1eaa51a51f254ac518e0af00" name="lib/sfCombineFilter.class.php" role="data" /> 
     28   <file md5sum="0dbc029fd2b17de944edd6865effc420" name="web/combine.php" role="data" /> 
     29   <file md5sum="064987ac72d5a69a474a7fda995d2832" name="README" role="data" /> 
    3130   <file md5sum="5a6e3a01bce673b38277f73dc1a8bab5" name="LICENSE" role="data" /> 
    3231  </dir> 
  • plugins/sfCombineFilterPlugin/trunk/web/combine.php

    r6025 r10092  
    1313 * permit persons to whom the Software is furnished to do so, subject to 
    1414 * the following conditions: 
    15  * 
     15 *  
    1616 * The above copyright notice and this permission notice shall be 
    1717 * included in all copies or substantial portions of the Software. 
     
    2525 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    2626 */ 
    27  
     27  
    2828// Minor modifications by Scott Meves for use with sfCombineFilterPlugin. 
    2929 
    30 define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/../../..')); 
    31 require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    32  
    3330$cache     = true; 
    34 $minify_js = true; 
    35  
    36 $cachedir  = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'cache'; 
    37 $webdir    = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'web'; 
    38 $cssdir    = $webdir.DIRECTORY_SEPARATOR.'css'; 
    39 $jsdir     = $webdir.DIRECTORY_SEPARATOR.'js'; 
     31$cachedir = dirname(__FILE__) . '/../cache'; 
     32$cssdir   = dirname(__FILE__) . '/css'; 
     33$jsdir  = dirname(__FILE__) . '/js'; 
    4034 
    4135// Determine the directory and type we should use 
     
    4539    break; 
    4640  case 'javascript': 
    47     $dir = $jsdir; 
     41    $dir = $jsdir;     
    4842    break; 
    4943  default: 
    5044    header ("HTTP/1.0 503 Not Implemented"); 
    5145    exit; 
    52 
     46}; 
     47 
     48$base = realpath($dir); 
    5349 
    5450$type = $_GET['type']; 
     
    5753  array_shift($elements); 
    5854} 
    59  
    6055// Determine last modification date of the files 
    6156$lastmodified = 0; 
    6257 
    63 $files = array(); 
    6458while (list(,$element) = each($elements)) { 
    65   $path = null; 
    66   if (substr($element, 0, 4) == '/sf/') { 
    67     $path = $sf_symfony_data_dir.DIRECTORY_SEPARATOR.'web'.$element; 
    68   } else if (substr($element, 0, 3) == 'sf/') { 
    69     $path = $sf_symfony_data_dir.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR.$element; 
    70   } else if (0 === strpos($element, '/')) { 
    71     $path = realpath($webdir.$element); 
     59  $path = realpath($element); 
     60  if (0 === strpos($element, '/')) { 
     61    $path = realpath(dirname(__FILE__).$element); 
    7262  } else { 
    73     $path = realpath($dir.DIRECTORY_SEPARATOR.$element); 
     63    $path = realpath($base . '/' . $element); 
    7464  } 
    75  
    76   if (($type == 'javascript' && substr($path, -3) != '.js') || 
     65   
     66  if (($type == 'javascript' && substr($path, -3) != '.js') ||  
    7767    ($type == 'css' && substr($path, -4) != '.css')) { 
    7868    header ("HTTP/1.0 403 Forbidden"); 
    79     exit; 
     69    exit;   
    8070  } 
    8171 
     
    8474    exit; 
    8575  } 
    86  
    87   $files[] = $path; 
     76   
    8877  $lastmodified = max($lastmodified, filemtime($path)); 
    8978} 
     
    9382header ("Etag: \"" . $hash . "\""); 
    9483 
    95 if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && 
    96   stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"') 
     84if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&  
     85  stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"')  
    9786{ 
    9887  // Return visit and no modifications, so do not send anything 
    9988  header ("HTTP/1.0 304 Not Modified"); 
    10089  header ('Content-Length: 0'); 
    101 } 
    102 else 
     90}  
     91else  
    10392{ 
    104  
    10593  // First time visit or files were modified 
    106   if ($cache) 
     94  if ($cache)  
    10795  { 
    10896    // Determine supported compression method 
     
    114102 
    115103    // Check for buggy versions of Internet Explorer 
    116     if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && 
     104    if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') &&  
    117105      preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) { 
    118106      $version = floatval($matches[1]); 
    119  
     107       
    120108      if ($version < 6) 
    121109        $encoding = 'none'; 
    122  
    123       if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) 
     110         
     111      if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1'))  
    124112        $encoding = 'none'; 
    125113    } 
    126  
     114     
    127115    // Try the cache first to see if the combined files were already generated 
    128116 
    129117    $cachefile = 'cache-' . $hash . '.' . $type . ($encoding != 'none' ? '.' . $encoding : ''); 
    130  
     118     
    131119    if (file_exists($cachedir . '/' . $cachefile)) { 
    132120      if ($fp = fopen($cachedir . '/' . $cachefile, 'rb')) { 
     
    135123          header ("Content-Encoding: " . $encoding); 
    136124        } 
    137  
     125       
    138126        header ("Content-Type: text/" . $type); 
    139127        header ("Content-Length: " . filesize($cachedir . '/' . $cachefile)); 
    140  
     128   
    141129        fpassthru($fp); 
    142130        fclose($fp); 
     
    149137  $contents = ''; 
    150138  reset($elements); 
    151   foreach ($files as $path) { 
     139  while (list(,$element) = each($elements)) { 
     140    $path = realpath($element); 
     141    if (0 === strpos($element, '/')) { 
     142      $path = realpath(dirname(__FILE__).$element); 
     143    } else { 
     144      $path = realpath($base . '/' . $element); 
     145    } 
    152146    $contents .= "\n\n" . file_get_contents($path); 
    153147  } 
    154148 
    155   if ($_GET['type'] == 'javascript' && $minify_js) { 
    156     include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'JSMin.class.php'; 
    157     try { 
    158       $contents = JSMin::minify($contents); 
    159     } catch (JSMinException $e) { 
    160       ; 
    161     } 
    162   } 
    163  
    164  
    165149  // Send Content-Type 
    166150  header ("Content-Type: text/" . $type); 
    167  
    168   if (isset($encoding) && $encoding != 'none') 
     151   
     152  if (isset($encoding) && $encoding != 'none')  
    169153  { 
    170154    // Send compressed contents 
     
    174158    header ('Content-Length: ' . strlen($contents)); 
    175159    echo $contents; 
    176   } 
    177   else 
     160  }  
     161  else  
    178162  { 
    179163    // Send regular contents 
     
    184168  // Store cache 
    185169  if ($cache) { 
    186     file_put_contents($cachedir . '/' . $cachefile, $contents); 
     170    if ($fp = fopen($cachedir . '/' . $cachefile, 'wb')) { 
     171      fwrite($fp, $contents); 
     172      fclose($fp); 
     173    } 
    187174  } 
    188175}