[+] Classes : added new class Media => It contains all the method related to media like CSS, JS
[+] Classes : added new method Media::addJquery(), Media::addJqueryUI(), Media::addJqueryPlugin() [~] Deprecated : All method related to CCC has been moved in class Media git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8926 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -879,15 +879,17 @@ class AdminControllerCore extends Controller
|
||||
$this->addCSS(__PS_BASE_URI__.str_replace(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR,'', _PS_ADMIN_DIR_).'/themes/default/admin.css', 'all');
|
||||
if ($this->context->language->is_rtl)
|
||||
$this->addCSS(_THEME_CSS_DIR_.'rtl.css');
|
||||
|
||||
$this->addJquery();
|
||||
$this->addjQueryPlugin(array('cluetip', 'hoverIntent'));
|
||||
|
||||
$this->addJS(_PS_JS_DIR_.'jquery/jquery-1.4.4.min.js');
|
||||
$this->addJS(_PS_JS_DIR_.'jquery/jquery.hoverIntent.minified.js');
|
||||
$this->addJS(_PS_JS_DIR_.'jquery/jquery.cluetip.js');
|
||||
$this->addJS(_PS_JS_DIR_.'admin.js');
|
||||
$this->addJS(_PS_JS_DIR_.'toggle.js');
|
||||
$this->addJS(_PS_JS_DIR_.'tools.js');
|
||||
$this->addJS(_PS_JS_DIR_.'ajax.js');
|
||||
$this->addJS(_PS_JS_DIR_.'notifications.js');
|
||||
$this->addJS(array(
|
||||
_PS_JS_DIR_.'admin.js',
|
||||
_PS_JS_DIR_.'toggle.js',
|
||||
_PS_JS_DIR_.'tools.js',
|
||||
_PS_JS_DIR_.'ajax.js',
|
||||
_PS_JS_DIR_.'notifications.js')
|
||||
);
|
||||
}
|
||||
|
||||
public static function translate($string, $class, $addslashes = FALSE, $htmlentities = TRUE)
|
||||
|
||||
+67
-36
@@ -173,24 +173,19 @@ abstract class ControllerCore
|
||||
public function addCSS($css_uri, $css_media_type = 'all')
|
||||
{
|
||||
if (is_array($css_uri))
|
||||
{
|
||||
foreach ($css_uri as $file => $media_type)
|
||||
self::addCSS($file, $media_type);
|
||||
return true;
|
||||
}
|
||||
foreach($css_uri as $css_file => $media)
|
||||
{
|
||||
if (is_string($css_file))
|
||||
{
|
||||
if ($css_path = Media::getCSSPath($css_file, $media))
|
||||
$this->css_files = array_merge($css_path, $this->css_files);
|
||||
}
|
||||
else if ($css_path = Media::getCSSPath($media, $css_media_type))
|
||||
$this->css_files = array_merge($css_path, $this->css_files);
|
||||
}
|
||||
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($css_uri);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
|
||||
// check if css files exists
|
||||
if (!file_exists($file_uri))
|
||||
return true;
|
||||
|
||||
// adding file to the big array...
|
||||
$this->css_files[$css_uri] = $css_media_type;
|
||||
|
||||
return true;
|
||||
else if ($css_path = Media::getCSSPath($css_uri, $css_media_type))
|
||||
$this->css_files = array_merge($css_path, $this->css_files);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,26 +197,62 @@ abstract class ControllerCore
|
||||
public function addJS($js_uri)
|
||||
{
|
||||
if (is_array($js_uri))
|
||||
foreach($js_uri as $js_file)
|
||||
if ($js_path = Media::getJSPath($js_file))
|
||||
$this->js_files[] = $js_path;
|
||||
else if ($js_path = Media::getJSPath($js_uri))
|
||||
$this->js_files[] = $js_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new javascript file in page header.
|
||||
*
|
||||
* @param mixed $js_uri
|
||||
* @return void
|
||||
*/
|
||||
public function addJquery($version = null, $folder = null, $minifier = true)
|
||||
{
|
||||
$this->addJS(Media::getJqueryPath($version, $folder, $minifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new javascript file in page header.
|
||||
*
|
||||
* @param mixed $js_uri
|
||||
* @return void
|
||||
*/
|
||||
public function addJqueryUI($component)
|
||||
{
|
||||
if (is_array($component))
|
||||
foreach($component as $ui)
|
||||
$ui_path = Media::getJqueryUIPath($ui);
|
||||
else
|
||||
$ui_path = Media::getJqueryUIPath($component);
|
||||
$this->addJS($ui_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new javascript file in page header.
|
||||
*
|
||||
* @param mixed $js_uri
|
||||
* @return void
|
||||
*/
|
||||
public function addJqueryPlugin($name)
|
||||
{
|
||||
$plugin_path = array();
|
||||
if (is_array($name))
|
||||
{
|
||||
foreach ($js_uri as $file)
|
||||
self::addJS($file);
|
||||
return true;
|
||||
foreach($name as $plugin)
|
||||
{
|
||||
$plugin_path = Media::getJqueryPluginPath($plugin);
|
||||
$this->addJS($plugin_path['js']);
|
||||
$this->addCSS($plugin_path['css']);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($js_uri, $this->js_files))
|
||||
return true;
|
||||
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($js_uri);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
|
||||
// check if js files exists
|
||||
if (!preg_match('/^http(s?):\/\//i', $file_uri) && !file_exists($file_uri))
|
||||
return true;
|
||||
|
||||
// adding file to the big array...
|
||||
$this->js_files[] = $js_uri;
|
||||
|
||||
return true;
|
||||
else
|
||||
$plugin_path = Media::getJqueryPluginPath($name);
|
||||
|
||||
$this->addCSS($plugin_path['css']);
|
||||
$this->addJS($plugin_path['js']);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -498,15 +498,16 @@ class FrontControllerCore extends Controller
|
||||
public function setMedia()
|
||||
{
|
||||
$this->addCSS(_THEME_CSS_DIR_.'global.css', 'all');
|
||||
$this->addJS(array(_PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js', _PS_JS_DIR_.'tools.js'));
|
||||
$this->addjquery();
|
||||
$this->addjqueryPlugin('easing');
|
||||
$this->addJS(_PS_JS_DIR_.'tools.js');
|
||||
|
||||
if (Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
{
|
||||
$this->addJS(array(
|
||||
_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js',
|
||||
_PS_JS_DIR_.'jquery/jquery.fancybox-1.3.4.js',
|
||||
_PS_JS_DIR_.'hookLiveEdit.js')
|
||||
);
|
||||
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css');
|
||||
$this->addJqueryUI('ui.sortable');
|
||||
$this->addjqueryPlugin('fancybox');
|
||||
$this->addJS(_PS_JS_DIR_.'hookLiveEdit.js');
|
||||
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css', 'all'); //TODO
|
||||
}
|
||||
if ($this->context->language->is_rtl)
|
||||
$this->addCSS(_THEME_CSS_DIR_.'rtl.css');
|
||||
@@ -538,13 +539,11 @@ class FrontControllerCore extends Controller
|
||||
{
|
||||
// CSS compressor management
|
||||
if (Configuration::get('PS_CSS_THEME_CACHE'))
|
||||
$this->css_files = Tools::cccCSS($this->css_files);
|
||||
|
||||
$this->css_files = Media::cccCSS($this->css_files);
|
||||
//JS compressor management
|
||||
if (Configuration::get('PS_JS_THEME_CACHE'))
|
||||
$this->js_files = Tools::cccJs($this->js_files);
|
||||
$this->js_files = Media::cccJs($this->js_files);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('css_files', $this->css_files);
|
||||
$this->context->smarty->assign('js_files', array_unique($this->js_files));
|
||||
}
|
||||
|
||||
+21
-11
@@ -31,9 +31,6 @@
|
||||
|
||||
class HelperCore
|
||||
{
|
||||
public static $translationsKeysForAdminCategorieTree = array(
|
||||
'Home', 'selected', 'selecteds', 'Collapse All', 'Expand All', 'Check All', 'Uncheck All'
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -65,19 +62,32 @@ class HelperCore
|
||||
* @param type $input_name name of input
|
||||
* @return string
|
||||
*/
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false)
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false)
|
||||
{
|
||||
if (!$use_radio)
|
||||
$input_name = $input_name.'[]';
|
||||
|
||||
$html = '
|
||||
<script src="../js/jquery/treeview/jquery.treeview.js" type="text/javascript"></script>
|
||||
<script src="../js/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script>
|
||||
<script src="../js/jquery/treeview/jquery.treeview.edit.js" type="text/javascript"></script>
|
||||
<script src="../js/admin-categories-tree.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'/jquery/treeview/jquery.treeview.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'/jquery/treeview/jquery.treeview.edit.js" type="text/javascript"></script>
|
||||
<script src="'._PS_JS_DIR_.'/admin-categories-tree.js" type="text/javascript"></script>'.
|
||||
($use_search ? '<script type="text/javascript" src="'._PS_JS_DIR_.'jquery/jquery.autocomplete.js"></script>' : '' ).'
|
||||
<script type="text/javascript">
|
||||
var inputName = "'.$input_name.'";
|
||||
';
|
||||
var inputName = "'.$input_name.'";';
|
||||
if ($use_search)
|
||||
{
|
||||
|
||||
$html .= '
|
||||
$(\'document\').ready( function() {
|
||||
var dataCat = '. Tools::jsonEncode(array(array('name' => 'toto'), array('name' => 'titi'), array('name' => 'tutu'))).';
|
||||
$(\'input[name="search_cat"]\').autocomplete(dataCat);
|
||||
//$(\'input[name="search_cat"]\').result(function(event, data, formatted) {
|
||||
//alert(\'toto\');
|
||||
//});
|
||||
});
|
||||
';
|
||||
}
|
||||
if (sizeof($selected_cat) > 0)
|
||||
{
|
||||
if (isset($selected_cat[0]))
|
||||
@@ -102,7 +112,7 @@ class HelperCore
|
||||
'.(!$use_radio ? '
|
||||
- <a href="#" id="check_all" >'.$trads['Check All'].'</a>
|
||||
- <a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>
|
||||
' : '').'
|
||||
' : '').($use_search ? '<span style="margin-left:20px">'.$trads['search'].' : <form method="post" id="filternameForm"><input type="text" name="search_cat" id="search_cat"></form></span>' : '').'
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
Executable
+503
@@ -0,0 +1,503 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7521 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class MediaCore
|
||||
{
|
||||
public static $jquery_ui_dependencies = array(
|
||||
'ui.core' => array('fileName' => 'jquery.ui.core.min.js', 'dependencies' => array(), 'theme' => false),
|
||||
'ui.widget' => array('fileName' => 'jquery.ui.widget.min.js', 'dependencies' => array(), 'theme' => false),
|
||||
'ui.mouse' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => false),
|
||||
'ui.position' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array(), 'theme' => false),
|
||||
'ui.draggable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => false),
|
||||
'ui.droppable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('uicore', 'ui.widget', 'ui.mouse', 'ui.draggable'), 'theme' => false),
|
||||
'ui.resizable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
|
||||
'ui.selectable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
|
||||
'ui.sortable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => false),
|
||||
'ui.accordion' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
|
||||
'ui.autocomplete' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.position'), 'theme' => true),
|
||||
'ui.button' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
|
||||
'ui.dialog' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.position'), 'theme' => true),
|
||||
'ui.slider' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true),
|
||||
'ui.tabs' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
|
||||
'ui.datepicker' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core'), 'theme' => true),
|
||||
'ui.progressbar' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true),
|
||||
'effects.core' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array(), 'theme' => false),
|
||||
'effects.blind' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.bounce' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.clip' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.drop' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.explode' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.fade' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.fold' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.highlight' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.pulsate' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.scale' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.shake' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.slide' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.transfer' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'))
|
||||
);
|
||||
|
||||
public static function minifyHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
//set an alphabetical order for args
|
||||
$html_content = preg_replace_callback(
|
||||
'/(<[a-zA-Z0-9]+)((\s?[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']\s?)*)>/'
|
||||
,array('Media', 'minifyHTMLpregCallback')
|
||||
,$html_content);
|
||||
|
||||
require_once(_PS_TOOL_DIR_.'minify_html/minify_html.class.php');
|
||||
$html_content = str_replace(chr(194) . chr(160), ' ', $html_content);
|
||||
$html_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'));
|
||||
|
||||
if (Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION'))
|
||||
{
|
||||
//$html_content = preg_replace('/"([^\>\s"]*)"/i', '$1', $html_content);//FIXME create a js bug
|
||||
$html_content = preg_replace('/<!DOCTYPE \w[^\>]*dtd\">/is', '', $html_content);
|
||||
$html_content = preg_replace('/\s\>/is', '>', $html_content);
|
||||
$html_content = str_replace('</li>', '', $html_content);
|
||||
$html_content = str_replace('</dt>', '', $html_content);
|
||||
$html_content = str_replace('</dd>', '', $html_content);
|
||||
$html_content = str_replace('</head>', '', $html_content);
|
||||
$html_content = str_replace('<head>', '', $html_content);
|
||||
$html_content = str_replace('</html>', '', $html_content);
|
||||
$html_content = str_replace('</body>', '', $html_content);
|
||||
//$html_content = str_replace('</p>', '', $html_content);//FIXME doesnt work...
|
||||
$html_content = str_replace("</option>\n", '', $html_content);//TODO with bellow
|
||||
$html_content = str_replace('</option>', '', $html_content);
|
||||
$html_content = str_replace('<script type=text/javascript>', '<script>', $html_content);//Do a better expreg
|
||||
$html_content = str_replace("<script>\n", '<script>', $html_content);//Do a better expreg
|
||||
}
|
||||
|
||||
return $html_content;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function minifyHTMLpregCallback($preg_matches)
|
||||
{
|
||||
$args = array();
|
||||
preg_match_all('/[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']/is', $preg_matches[2], $args);
|
||||
$args = $args[0];
|
||||
sort($args);
|
||||
$output = $preg_matches[1].' '.implode(' ', $args).'>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function packJSinHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
$htmlContentCopy = $html_content;
|
||||
$html_content = preg_replace_callback(
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)(<\\/script>)\\s*/i'
|
||||
,array('Media', 'packJSinHTMLpregCallback')
|
||||
,$html_content);
|
||||
|
||||
// If the string is too big preg_replace return an error
|
||||
// In this case, we don't compress the content
|
||||
if( preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR ) {
|
||||
error_log('ERROR: PREG_BACKTRACK_LIMIT_ERROR in function packJSinHTML');
|
||||
return $htmlContentCopy;
|
||||
}
|
||||
return $html_content;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function packJSinHTMLpregCallback($preg_matches)
|
||||
{
|
||||
$preg_matches[1] = $preg_matches[1].'/* <![CDATA[ */';
|
||||
$preg_matches[2] = self::packJS($preg_matches[2]);
|
||||
$preg_matches[count($preg_matches)-1] = '/* ]]> */'.$preg_matches[count($preg_matches)-1];
|
||||
unset($preg_matches[0]);
|
||||
$output = implode('', $preg_matches);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public static function packJS($js_content)
|
||||
{
|
||||
if (strlen($js_content) > 0)
|
||||
{
|
||||
require_once(_PS_TOOL_DIR_.'js_minify/jsmin.php');
|
||||
return JSMin::minify($js_content);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function minifyCSS($css_content, $fileuri = false)
|
||||
{
|
||||
global $current_css_file;
|
||||
|
||||
$current_css_file = $fileuri;
|
||||
if (strlen($css_content) > 0)
|
||||
{
|
||||
$css_content = preg_replace('#/\*.*?\*/#s', '', $css_content);
|
||||
$css_content = preg_replace_callback('#url\((?:\'|")?([^\)\'"]*)(?:\'|")?\)#s',array('Media', 'replaceByAbsoluteURL'), $css_content);
|
||||
|
||||
$css_content = preg_replace('#\s+#',' ',$css_content);
|
||||
$css_content = str_replace("\t", '', $css_content);
|
||||
$css_content = str_replace("\n", '', $css_content);
|
||||
//$css_content = str_replace('}', "}\n", $css_content);
|
||||
|
||||
$css_content = str_replace('; ', ';', $css_content);
|
||||
$css_content = str_replace(': ', ':', $css_content);
|
||||
$css_content = str_replace(' {', '{', $css_content);
|
||||
$css_content = str_replace('{ ', '{', $css_content);
|
||||
$css_content = str_replace(', ', ',', $css_content);
|
||||
$css_content = str_replace('} ', '}', $css_content);
|
||||
$css_content = str_replace(' }', '}', $css_content);
|
||||
$css_content = str_replace(';}', '}', $css_content);
|
||||
$css_content = str_replace(':0px', ':0', $css_content);
|
||||
$css_content = str_replace(' 0px', ' 0', $css_content);
|
||||
$css_content = str_replace(':0em', ':0', $css_content);
|
||||
$css_content = str_replace(' 0em', ' 0', $css_content);
|
||||
$css_content = str_replace(':0pt', ':0', $css_content);
|
||||
$css_content = str_replace(' 0pt', ' 0', $css_content);
|
||||
$css_content = str_replace(':0%', ':0', $css_content);
|
||||
$css_content = str_replace(' 0%', ' 0', $css_content);
|
||||
|
||||
return trim($css_content);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* addJS return javascript path
|
||||
*
|
||||
* @param mixed $js_uri
|
||||
* @return string
|
||||
*/
|
||||
public static function getJSPath($js_uri)
|
||||
{
|
||||
if (is_array($js_uri) OR is_null($js_uri))
|
||||
return false;
|
||||
$url_data = parse_url($js_uri);
|
||||
if (!array_key_exists('host', $url_data))
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']); // remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
else
|
||||
$file_uri = $js_uri;
|
||||
// check if js files exists
|
||||
|
||||
if (!preg_match('/^http(s?):\/\//i', $file_uri) && !file_exists($file_uri))
|
||||
return false;
|
||||
|
||||
// adding file to the big array...;
|
||||
return $js_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* addCSS return stylesheet path.
|
||||
*
|
||||
* @param mixed $css_uri
|
||||
* @param string $css_media_type
|
||||
* @return string
|
||||
*/
|
||||
public static function getCSSPath($css_uri, $css_media_type = 'all')
|
||||
{
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($css_uri);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
// check if css files exists
|
||||
if (!file_exists($file_uri))
|
||||
return false;
|
||||
|
||||
// adding file to the big array...
|
||||
if (is_array($css_uri))
|
||||
return $css_uri;
|
||||
return array($css_uri => $css_media_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* return jquery path.
|
||||
*
|
||||
* @param mixed $version
|
||||
* @return string
|
||||
*/
|
||||
public static function getJqueryPath($version = null, $folder = null, $minifier = true)
|
||||
{
|
||||
$addNoConflict = false;
|
||||
if (is_null($version))
|
||||
$version = _PS_JQUERY_VERSION_; //set default version
|
||||
else if (preg_match('/^([0-9]+\.)+[0-9]$/Ui', $version))
|
||||
$addNoConflict = true;
|
||||
else
|
||||
return false;
|
||||
|
||||
if (is_null($folder))
|
||||
$folder = _PS_JS_DIR_.'jquery/'; //set default folder
|
||||
//check if file exist
|
||||
$file = $folder.'jquery-'.$version.($minifier ? '.min.js' : '.js');
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($file);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
// check if js files exists, if not try to load query from ajax.googleapis.com
|
||||
|
||||
if (file_exists($file_uri))
|
||||
return self::getJSPath($file);
|
||||
else
|
||||
return self::getJSPath(Tools::getCurrentUrlProtocolPrefix().'ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery'.($minifier ? '.min.js' : '.js'));
|
||||
if ($addNoConflict)
|
||||
return self::getJSPath(_PS_JS_DIR_.'jquery/jquery.noConflict.php?version='.$version);
|
||||
}
|
||||
|
||||
/**
|
||||
* return jqueryUI component path.
|
||||
*
|
||||
* @param mixed $component
|
||||
* @return string
|
||||
*/
|
||||
public static function getJqueryUIPath($component, $theme = 'base', $check_dependencies = true)
|
||||
{
|
||||
$ui_path = array('js' => array(), 'css' => array());
|
||||
$folder = _PS_JS_DIR_.'jquery/ui/';
|
||||
$file = 'jquery.'.$component.'.min.js';
|
||||
$url_data = parse_url($folder.$file);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
$ui_tmp = array();
|
||||
if ($check_dependencies && array_key_exists($component, self::$jquery_ui_dependencies))
|
||||
foreach(self::$jquery_ui_dependencies[$component]['dependencies'] as $dependency)
|
||||
$ui_tmp[] = self::getJqueryUIPath($dependency, $theme, false);
|
||||
|
||||
if (file_exists($file_uri))
|
||||
{
|
||||
if (!empty($ui_tmp))
|
||||
{
|
||||
$ui_tmp[] = self::getJSPath($folder.$file);
|
||||
return $ui_tmp;
|
||||
}
|
||||
else
|
||||
return self::getJSPath($folder.$file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return jquery plugin path.
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return void
|
||||
*/
|
||||
public static function getJqueryPluginPath($name)
|
||||
{
|
||||
$plugin_path = array('js' => array(), 'css' => array());
|
||||
$folder = _PS_JS_DIR_.'jquery/plugins/';
|
||||
$file = 'jquery.'.$name.'.js';
|
||||
$url_data = parse_url($folder);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
if (file_exists($file_uri.$file))
|
||||
$plugin_path['js'] = self::getJSPath($folder.$file);
|
||||
else if (file_exists($file_uri.$name.'/'.$file))
|
||||
$plugin_path['js'] = self::getJSPath($folder.$name.'/'.$file);
|
||||
else
|
||||
return false;
|
||||
$plugin_path['css'] = self::getJqueryPluginCSSPath($name);
|
||||
return $plugin_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* return jquery plugin css path if exist.
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return void
|
||||
*/
|
||||
public static function getJqueryPluginCSSPath($name)
|
||||
{
|
||||
$plugin_path = array('js' => array(), 'css' => array());
|
||||
$folder = _PS_JS_DIR_.'jquery/plugins/';
|
||||
$file = 'jquery.'.$name.'.css';
|
||||
$url_data = parse_url($folder);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
if (file_exists($file_uri.$file))
|
||||
return self::getCSSPath($folder.$file);
|
||||
else if (file_exists($file_uri.$name.'/'.$file))
|
||||
return self::getCSSPath($folder.$name.'/'.$file);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine Compress and Cache CSS (ccc) calls
|
||||
*
|
||||
* @param array css_files
|
||||
* @return array processed css_files
|
||||
*/
|
||||
public static function cccCss($css_files)
|
||||
{
|
||||
//inits
|
||||
$css_files_by_media = array();
|
||||
$compressed_css_files = array();
|
||||
$compressed_css_files_not_found = array();
|
||||
$compressed_css_files_infos = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// group css files by media
|
||||
foreach ($css_files as $filename => $media)
|
||||
{
|
||||
if (!array_key_exists($media, $css_files_by_media))
|
||||
$css_files_by_media[$media] = array();
|
||||
|
||||
$infos = array();
|
||||
$infos['uri'] = $filename;
|
||||
$url_data = parse_url($filename);
|
||||
$infos['path'] = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$css_files_by_media[$media]['files'][] = $infos;
|
||||
if (!array_key_exists('date', $css_files_by_media[$media]))
|
||||
$css_files_by_media[$media]['date'] = 0;
|
||||
$css_files_by_media[$media]['date'] = max(
|
||||
file_exists($infos['path']) ? filemtime($infos['path']) : 0,
|
||||
$css_files_by_media[$media]['date']
|
||||
);
|
||||
|
||||
if (!array_key_exists($media, $compressed_css_files_infos))
|
||||
$compressed_css_files_infos[$media] = array('key' => '');
|
||||
$compressed_css_files_infos[$media]['key'] .= $filename;
|
||||
}
|
||||
|
||||
// get compressed css file infos
|
||||
foreach ($compressed_css_files_infos as $media => &$info)
|
||||
{
|
||||
$key = md5($info['key'].$protocolLink);
|
||||
$filename = _PS_THEME_DIR_.'cache/'.$key.'_'.$media.'.css';
|
||||
$info = array(
|
||||
'key' => $key,
|
||||
'date' => file_exists($filename) ? filemtime($filename) : 0
|
||||
);
|
||||
}
|
||||
// aggregate and compress css files content, write new caches files
|
||||
foreach ($css_files_by_media as $media => $media_infos)
|
||||
{
|
||||
$cache_filename = _PS_THEME_DIR_.'cache/'.$compressed_css_files_infos[$media]['key'].'_'.$media.'.css';
|
||||
if ($media_infos['date'] > $compressed_css_files_infos[$media]['date'])
|
||||
{
|
||||
$compressed_css_files[$media] = '';
|
||||
foreach ($media_infos['files'] as $file_infos)
|
||||
{
|
||||
if (file_exists($file_infos['path']))
|
||||
$compressed_css_files[$media] .= self::minifyCSS(file_get_contents($file_infos['path']), $file_infos['uri']);
|
||||
else
|
||||
$compressed_css_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
if (!empty($compressed_css_files_not_found))
|
||||
$content = '/* WARNING ! file(s) not found : "'.
|
||||
implode(',', $compressed_css_files_not_found).
|
||||
'" */'."\n".$compressed_css_files[$media];
|
||||
else
|
||||
$content = $compressed_css_files[$media];
|
||||
file_put_contents($cache_filename, $content);
|
||||
chmod($cache_filename, 0777);
|
||||
}
|
||||
$compressed_css_files[$media] = $cache_filename;
|
||||
}
|
||||
|
||||
// rebuild the original css_files array
|
||||
$css_files = array();
|
||||
foreach ($compressed_css_files as $media => $filename)
|
||||
{
|
||||
$url = str_replace(_PS_THEME_DIR_, _THEMES_DIR_._THEME_NAME_.'/', $filename);
|
||||
$css_files[$protocolLink.Tools::getMediaServer($url).$url] = $media;
|
||||
}
|
||||
return $css_files;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combine Compress and Cache (ccc) JS calls
|
||||
*
|
||||
* @param array js_files
|
||||
* @return array processed js_files
|
||||
*/
|
||||
public static function cccJS($js_files)
|
||||
{
|
||||
//inits
|
||||
$compressed_js_files_not_found = array();
|
||||
$js_files_infos = array();
|
||||
$js_files_date = 0;
|
||||
$compressed_js_file_date = 0;
|
||||
$compressed_js_filename = '';
|
||||
$js_external_files = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// get js files infos
|
||||
foreach ($js_files as $filename)
|
||||
{
|
||||
$expr = explode(':', $filename);
|
||||
|
||||
if ($expr[0] == 'http')
|
||||
$js_external_files[] = $filename;
|
||||
else
|
||||
{
|
||||
$infos = array();
|
||||
$infos['uri'] = $filename;
|
||||
$url_data = parse_url($filename);
|
||||
$infos['path'] =_PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$js_files_infos[] = $infos;
|
||||
|
||||
$js_files_date = max(
|
||||
file_exists($infos['path']) ? filemtime($infos['path']) : 0,
|
||||
$js_files_date
|
||||
);
|
||||
$compressed_js_filename .= $filename;
|
||||
}
|
||||
}
|
||||
|
||||
// get compressed js file infos
|
||||
$compressed_js_filename = md5($compressed_js_filename);
|
||||
|
||||
$compressed_js_path = _PS_THEME_DIR_.'cache/'.$compressed_js_filename.'.js';
|
||||
$compressed_js_file_date = file_exists($compressed_js_path) ? filemtime($compressed_js_path) : 0;
|
||||
|
||||
// aggregate and compress js files content, write new caches files
|
||||
if ($js_files_date > $compressed_js_file_date)
|
||||
{
|
||||
$content = '';
|
||||
foreach ($js_files_infos as $file_infos)
|
||||
{
|
||||
if (file_exists($file_infos['path']))
|
||||
$content .= file_get_contents($file_infos['path']).';';
|
||||
else
|
||||
$compressed_js_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
$content = self::packJS($content);
|
||||
|
||||
if (!empty($compressed_js_files_not_found))
|
||||
$content = '/* WARNING ! file(s) not found : "'.
|
||||
implode(',', $compressed_js_files_not_found).
|
||||
'" */'."\n".$content;
|
||||
|
||||
file_put_contents($compressed_js_path, $content);
|
||||
chmod($compressed_js_path, 0777);
|
||||
}
|
||||
|
||||
// rebuild the original js_files array
|
||||
$url = str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $compressed_js_path);
|
||||
|
||||
return array_merge(array($protocolLink.Tools::getMediaServer($url).$url), $js_external_files);
|
||||
}
|
||||
|
||||
}
|
||||
+47
-256
@@ -1206,43 +1206,15 @@ class ToolsCore
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyHTML()
|
||||
*/
|
||||
|
||||
public static function minifyHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
//set an alphabetical order for args
|
||||
$html_content = preg_replace_callback(
|
||||
'/(<[a-zA-Z0-9]+)((\s?[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']\s?)*)>/'
|
||||
,array('Tools', 'minifyHTMLpregCallback')
|
||||
,$html_content);
|
||||
|
||||
require_once(_PS_TOOL_DIR_.'minify_html/minify_html.class.php');
|
||||
$html_content = str_replace(chr(194) . chr(160), ' ', $html_content);
|
||||
$html_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'));
|
||||
|
||||
if (Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION'))
|
||||
{
|
||||
//$html_content = preg_replace('/"([^\>\s"]*)"/i', '$1', $html_content);//FIXME create a js bug
|
||||
$html_content = preg_replace('/<!DOCTYPE \w[^\>]*dtd\">/is', '', $html_content);
|
||||
$html_content = preg_replace('/\s\>/is', '>', $html_content);
|
||||
$html_content = str_replace('</li>', '', $html_content);
|
||||
$html_content = str_replace('</dt>', '', $html_content);
|
||||
$html_content = str_replace('</dd>', '', $html_content);
|
||||
$html_content = str_replace('</head>', '', $html_content);
|
||||
$html_content = str_replace('<head>', '', $html_content);
|
||||
$html_content = str_replace('</html>', '', $html_content);
|
||||
$html_content = str_replace('</body>', '', $html_content);
|
||||
//$html_content = str_replace('</p>', '', $html_content);//FIXME doesnt work...
|
||||
$html_content = str_replace("</option>\n", '', $html_content);//TODO with bellow
|
||||
$html_content = str_replace('</option>', '', $html_content);
|
||||
$html_content = str_replace('<script type=text/javascript>', '<script>', $html_content);//Do a better expreg
|
||||
$html_content = str_replace("<script>\n", '<script>', $html_content);//Do a better expreg
|
||||
}
|
||||
|
||||
return $html_content;
|
||||
}
|
||||
return false;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::minifyHTML($html_content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1265,56 +1237,41 @@ class ToolsCore
|
||||
$b = hexdec(substr($hex, 4, 2));
|
||||
return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyHTMLpregCallback()
|
||||
*/
|
||||
public static function minifyHTMLpregCallback($preg_matches)
|
||||
{
|
||||
$args = array();
|
||||
preg_match_all('/[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']/is', $preg_matches[2], $args);
|
||||
$args = $args[0];
|
||||
sort($args);
|
||||
$output = $preg_matches[1].' '.implode(' ', $args).'>';
|
||||
return $output;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::minifyHTMLpregCallback($preg_matches);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::packJSinHTML()
|
||||
*/
|
||||
public static function packJSinHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
$htmlContentCopy = $html_content;
|
||||
$html_content = preg_replace_callback(
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)(<\\/script>)\\s*/i'
|
||||
,array('Tools', 'packJSinHTMLpregCallback')
|
||||
,$html_content);
|
||||
|
||||
// If the string is too big preg_replace return an error
|
||||
// In this case, we don't compress the content
|
||||
if( preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR ) {
|
||||
error_log('ERROR: PREG_BACKTRACK_LIMIT_ERROR in function packJSinHTML');
|
||||
return $htmlContentCopy;
|
||||
}
|
||||
return $html_content;
|
||||
}
|
||||
return false;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::packJSinHTML($html_content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::packJSinHTMLpregCallback()
|
||||
*/
|
||||
public static function packJSinHTMLpregCallback($preg_matches)
|
||||
{
|
||||
$preg_matches[1] = $preg_matches[1].'/* <![CDATA[ */';
|
||||
$preg_matches[2] = self::packJS($preg_matches[2]);
|
||||
$preg_matches[count($preg_matches)-1] = '/* ]]> */'.$preg_matches[count($preg_matches)-1];
|
||||
unset($preg_matches[0]);
|
||||
$output = implode('', $preg_matches);
|
||||
return $output;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::packJSinHTMLpregCallback($preg_matches);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::packJS()
|
||||
*/
|
||||
public static function packJS($js_content)
|
||||
{
|
||||
if (strlen($js_content) > 0)
|
||||
{
|
||||
require_once(_PS_TOOL_DIR_.'js_minify/jsmin.php');
|
||||
return JSMin::minify($js_content);
|
||||
}
|
||||
return false;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::packJS($js_content);
|
||||
}
|
||||
|
||||
|
||||
@@ -1328,42 +1285,14 @@ class ToolsCore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyCSS()
|
||||
*/
|
||||
public static function minifyCSS($css_content, $fileuri = false)
|
||||
{
|
||||
global $current_css_file;
|
||||
|
||||
$current_css_file = $fileuri;
|
||||
if (strlen($css_content) > 0)
|
||||
{
|
||||
$css_content = preg_replace('#/\*.*?\*/#s', '', $css_content);
|
||||
$css_content = preg_replace_callback('#url\((?:\'|")?([^\)\'"]*)(?:\'|")?\)#s',array('Tools', 'replaceByAbsoluteURL'), $css_content);
|
||||
|
||||
$css_content = preg_replace('#\s+#',' ',$css_content);
|
||||
$css_content = str_replace("\t", '', $css_content);
|
||||
$css_content = str_replace("\n", '', $css_content);
|
||||
//$css_content = str_replace('}', "}\n", $css_content);
|
||||
|
||||
$css_content = str_replace('; ', ';', $css_content);
|
||||
$css_content = str_replace(': ', ':', $css_content);
|
||||
$css_content = str_replace(' {', '{', $css_content);
|
||||
$css_content = str_replace('{ ', '{', $css_content);
|
||||
$css_content = str_replace(', ', ',', $css_content);
|
||||
$css_content = str_replace('} ', '}', $css_content);
|
||||
$css_content = str_replace(' }', '}', $css_content);
|
||||
$css_content = str_replace(';}', '}', $css_content);
|
||||
$css_content = str_replace(':0px', ':0', $css_content);
|
||||
$css_content = str_replace(' 0px', ' 0', $css_content);
|
||||
$css_content = str_replace(':0em', ':0', $css_content);
|
||||
$css_content = str_replace(' 0em', ' 0', $css_content);
|
||||
$css_content = str_replace(':0pt', ':0', $css_content);
|
||||
$css_content = str_replace(' 0pt', ' 0', $css_content);
|
||||
$css_content = str_replace(':0%', ':0', $css_content);
|
||||
$css_content = str_replace(' 0%', ' 0', $css_content);
|
||||
|
||||
return trim($css_content);
|
||||
}
|
||||
return false;
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::minifyCSS($css_content, $fileuri);
|
||||
}
|
||||
|
||||
public static function replaceByAbsoluteURL($matches)
|
||||
@@ -1410,163 +1339,26 @@ class ToolsCore
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine Compress and Cache CSS (ccc) calls
|
||||
*
|
||||
* @param array css_files
|
||||
* @return array processed css_files
|
||||
* @deprecated as of 1.5 use Media::cccCss()
|
||||
*/
|
||||
public static function cccCss($css_files) {
|
||||
//inits
|
||||
$css_files_by_media = array();
|
||||
$compressed_css_files = array();
|
||||
$compressed_css_files_not_found = array();
|
||||
$compressed_css_files_infos = array();
|
||||
$protocolLink = self::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// group css files by media
|
||||
foreach ($css_files as $filename => $media)
|
||||
{
|
||||
if (!array_key_exists($media, $css_files_by_media))
|
||||
$css_files_by_media[$media] = array();
|
||||
|
||||
$infos = array();
|
||||
$infos['uri'] = $filename;
|
||||
$url_data = parse_url($filename);
|
||||
$infos['path'] = _PS_ROOT_DIR_.self::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$css_files_by_media[$media]['files'][] = $infos;
|
||||
if (!array_key_exists('date', $css_files_by_media[$media]))
|
||||
$css_files_by_media[$media]['date'] = 0;
|
||||
$css_files_by_media[$media]['date'] = max(
|
||||
file_exists($infos['path']) ? filemtime($infos['path']) : 0,
|
||||
$css_files_by_media[$media]['date']
|
||||
);
|
||||
|
||||
if (!array_key_exists($media, $compressed_css_files_infos))
|
||||
$compressed_css_files_infos[$media] = array('key' => '');
|
||||
$compressed_css_files_infos[$media]['key'] .= $filename;
|
||||
}
|
||||
|
||||
// get compressed css file infos
|
||||
foreach ($compressed_css_files_infos as $media => &$info)
|
||||
{
|
||||
$key = md5($info['key'].$protocolLink);
|
||||
$filename = _PS_THEME_DIR_.'cache/'.$key.'_'.$media.'.css';
|
||||
$info = array(
|
||||
'key' => $key,
|
||||
'date' => file_exists($filename) ? filemtime($filename) : 0
|
||||
);
|
||||
}
|
||||
// aggregate and compress css files content, write new caches files
|
||||
foreach ($css_files_by_media as $media => $media_infos)
|
||||
{
|
||||
$cache_filename = _PS_THEME_DIR_.'cache/'.$compressed_css_files_infos[$media]['key'].'_'.$media.'.css';
|
||||
if ($media_infos['date'] > $compressed_css_files_infos[$media]['date'])
|
||||
{
|
||||
$compressed_css_files[$media] = '';
|
||||
foreach ($media_infos['files'] as $file_infos)
|
||||
{
|
||||
if (file_exists($file_infos['path']))
|
||||
$compressed_css_files[$media] .= self::minifyCSS(file_get_contents($file_infos['path']), $file_infos['uri']);
|
||||
else
|
||||
$compressed_css_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
if (!empty($compressed_css_files_not_found))
|
||||
$content = '/* WARNING ! file(s) not found : "'.
|
||||
implode(',', $compressed_css_files_not_found).
|
||||
'" */'."\n".$compressed_css_files[$media];
|
||||
else
|
||||
$content = $compressed_css_files[$media];
|
||||
file_put_contents($cache_filename, $content);
|
||||
chmod($cache_filename, 0777);
|
||||
}
|
||||
$compressed_css_files[$media] = $cache_filename;
|
||||
}
|
||||
|
||||
// rebuild the original css_files array
|
||||
$css_files = array();
|
||||
foreach ($compressed_css_files as $media => $filename)
|
||||
{
|
||||
$url = str_replace(_PS_THEME_DIR_, _THEMES_DIR_._THEME_NAME_.'/', $filename);
|
||||
$css_files[$protocolLink.self::getMediaServer($url).$url] = $media;
|
||||
}
|
||||
return $css_files;
|
||||
public static function cccCss($css_files)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::cccCss($css_files);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combine Compress and Cache (ccc) JS calls
|
||||
*
|
||||
* @param array js_files
|
||||
* @return array processed js_files
|
||||
* @deprecated as of 1.5 use Media::cccJS()
|
||||
*/
|
||||
public static function cccJS($js_files) {
|
||||
//inits
|
||||
$compressed_js_files_not_found = array();
|
||||
$js_files_infos = array();
|
||||
$js_files_date = 0;
|
||||
$compressed_js_file_date = 0;
|
||||
$compressed_js_filename = '';
|
||||
$js_external_files = array();
|
||||
$protocolLink = self::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// get js files infos
|
||||
foreach ($js_files as $filename)
|
||||
{
|
||||
$expr = explode(':', $filename);
|
||||
|
||||
if ($expr[0] == 'http')
|
||||
$js_external_files[] = $filename;
|
||||
else
|
||||
{
|
||||
$infos = array();
|
||||
$infos['uri'] = $filename;
|
||||
$url_data = parse_url($filename);
|
||||
$infos['path'] =_PS_ROOT_DIR_.self::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$js_files_infos[] = $infos;
|
||||
|
||||
$js_files_date = max(
|
||||
file_exists($infos['path']) ? filemtime($infos['path']) : 0,
|
||||
$js_files_date
|
||||
);
|
||||
$compressed_js_filename .= $filename;
|
||||
}
|
||||
}
|
||||
|
||||
// get compressed js file infos
|
||||
$compressed_js_filename = md5($compressed_js_filename);
|
||||
|
||||
$compressed_js_path = _PS_THEME_DIR_.'cache/'.$compressed_js_filename.'.js';
|
||||
$compressed_js_file_date = file_exists($compressed_js_path) ? filemtime($compressed_js_path) : 0;
|
||||
|
||||
// aggregate and compress js files content, write new caches files
|
||||
if ($js_files_date > $compressed_js_file_date)
|
||||
{
|
||||
$content = '';
|
||||
foreach ($js_files_infos as $file_infos)
|
||||
{
|
||||
if (file_exists($file_infos['path']))
|
||||
$content .= file_get_contents($file_infos['path']).';';
|
||||
else
|
||||
$compressed_js_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
$content = self::packJS($content);
|
||||
|
||||
if (!empty($compressed_js_files_not_found))
|
||||
$content = '/* WARNING ! file(s) not found : "'.
|
||||
implode(',', $compressed_js_files_not_found).
|
||||
'" */'."\n".$content;
|
||||
|
||||
file_put_contents($compressed_js_path, $content);
|
||||
chmod($compressed_js_path, 0777);
|
||||
}
|
||||
|
||||
// rebuild the original js_files array
|
||||
$url = str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $compressed_js_path);
|
||||
|
||||
return array_merge(array($protocolLink.Tools::getMediaServer($url).$url), $js_external_files);
|
||||
public static function cccJS($js_files)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::cccJS($css_files);
|
||||
}
|
||||
|
||||
private static $_cache_nb_media_servers = null;
|
||||
|
||||
public static function getMediaServer($filename)
|
||||
{
|
||||
if (self::$_cache_nb_media_servers === null)
|
||||
@@ -1770,7 +1562,6 @@ FileETag INode MTime Size
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
$callee = next($backtrace);
|
||||
|
||||
if ($message)
|
||||
trigger_error($message, E_USER_WARNING);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user