17c8e3e54e01ff48a46dd2f65473094ed674a535
[lhc/web/www.git] / www / plugins / crayons / crayons.js_fonctions.php
1 <?php
2 /**
3 * Crayons
4 * plugin for spip
5 * (c) Fil, toggg 2006-2013
6 * licence GPL
7 *
8 */
9
10 if (!defined('_ECRIRE_INC_VERSION')) {
11 return;
12 }
13
14 //
15 // Les crayons ont leur propre copie du pack de Dean Edwards
16 // pour compatibilite avec SPIP < [9717]
17 //
18 function pack_cQuery($chemin) {
19 if (!$chemin) {
20 return;
21 }
22
23 $flux = spip_file_get_contents($chemin);
24 $flux = str_replace('jQuery', 'cQuery', $flux);
25 $flux = str_replace('cQuery.spip', 'jQuery.spip', $flux);
26
27 // On ne compacte PAS deux fois (c'est inutile et en plus ca bugge)
28 if (!strlen($flux)
29 or _request('debug_crayons') // mode debug des crayons
30 or ($GLOBALS['meta']['auto_compress_js'] == 'oui' // le vieil auto_compress_js
31 and @file_exists(_DIR_RESTREINT.'inc/compacte_js.php'))
32 or !function_exists('test_espace_prive')// ou l'espace prive
33 or test_espace_prive()) {
34 return $flux;
35 }
36
37 include_spip('lib/JavaScriptPacker/class.JavaScriptPacker');
38 $packer = new JavaScriptPacker($flux, 0, true, false);
39
40 // en cas d'echec (?) renvoyer l'original
41 if (strlen($t = $packer->pack())) {
42 return $t;
43 }
44
45 // erreur
46 spip_log('erreur de pack_js');
47 return $flux;
48 }