Prestashop 1.6 - Mettre jquery.min.js sur le cdn de Google

Nous allons créer un override Controller.php dans /override/classes/controller et y mettre ce code.

<?php

    abstract class Controller extends ControllerCore
    {

        /*** All other previous overrides here ***/

        /**
         * Use Google's CDN to host jQuery
         * @param string  $version  Version of jQuery to include
         * @param string  $folder   Not used in this override
         * @param boolean $minifier Use minified version?
         */
        public function addJquery($version = null, $folder = null, $minifier = true) {

        $this->addJS(Media::getJSPath(Tools::getCurrentUrlProtocolPrefix() . 'ajax.googleapis.com/ajax/libs/jquery/' . ($version ? $version : _PS_JQUERY_VERSION_) . '/jquery'.($minifier ? '.min.js' : '.js')));
		$this->addJS(Media::getJqueryPath($minifier));

        }
    }

Nous créons l'override de Media.php que nous placons dans /override/classes

<?php

    class Media extends MediaCore

    {
   
	public static function cccJS($js_files)
	{
		//inits
		$compressed_js_files_not_found = array();
		$js_files_infos = array();
		$js_files_date = 0;
		$compressed_js_filename = '';
		$js_external_files = array();
		$protocol_link = Tools::getCurrentUrlProtocolPrefix();
		$cache_path = _PS_THEME_DIR_.'cache/';

		// get js files infos
		foreach ($js_files as $filename)
		{
			if (Validate::isAbsoluteUrl($filename))
				$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']);

				if (!@filemtime($info['path']))
					$infos['path'] = _PS_CORE_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);
		$version = (int)Configuration::get('PS_CCCJS_VERSION');
		$compressed_js_path = $cache_path.'v_'.$version.'_'.$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)
		{
			if ($compressed_js_file_date)
				Configuration::updateValue('PS_CCCJS_VERSION', ++$version);

			$compressed_js_path = $cache_path.'v_'.$version.'_'.$compressed_js_filename.'.js';
			$content = '';
			foreach ($js_files_infos as $file_infos)
			{
				if (file_exists($file_infos['path']))
				{
					$tmp_content = file_get_contents($file_infos['path']);
					if (preg_match('@\.(min|pack)\.[^/]+$@', $file_infos['path'], $matches))
						$content .= preg_replace('/\/\/@\ssourceMappingURL\=[_a-zA-Z0-9-.]+\.'.$matches[1].'\.map\s+/', '', $tmp_content);
					else
						$content .= Media::packJS($tmp_content);
				}
				else
					$compressed_js_files_not_found[] = $file_infos['path'];
			}

			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
		if (strpos($compressed_js_path, _PS_ROOT_DIR_) !== false)
			$url = str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $compressed_js_path);

		if (strpos($compressed_js_path, _PS_CORE_DIR_) !== false)
			$url = str_replace(_PS_CORE_DIR_.'/', __PS_BASE_URI__, $compressed_js_path);

        return array_merge($js_external_files,array($protocol_link.Tools::getMediaServer($url).$url));
	}
}

Commentaires


Notice: Undefined index: customer_avatar in /home/tangence/public_html/cache/smarty/compile/0c/23/4a/0c234a9ea2459e7dbf9533a4ca298d269dd2f2e8.file.productcomments.tpl.php on line 56
le 12/06/2015 19:03:53

Oui, il a été développé pour !


Notice: Undefined index: customer_avatar in /home/tangence/public_html/cache/smarty/compile/0c/23/4a/0c234a9ea2459e7dbf9533a4ca298d269dd2f2e8.file.productcomments.tpl.php on line 56
le 07/06/2015 18:20:02

Bonjour,
Est-ce ce script fonctionne bien sous 1.6.0.9 ?
Cordialement
Pascal