| 1 | <?php
|
|---|
| 2 | /*-----------------------------------------------------------
|
|---|
| 3 | $Id:$
|
|---|
| 4 |
|
|---|
| 5 | modified eCommerce Shopsoftware
|
|---|
| 6 | http://www.modified-shop.org
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 2009 - 2013 [www.modified-shop.org]
|
|---|
| 9 | -----------------------------------------------------------
|
|---|
| 10 | based on: (c) 2003 - 2006 XT-Commerce (general.js.php)
|
|---|
| 11 | -----------------------------------------------------------
|
|---|
| 12 | Released under the GNU General Public License
|
|---|
| 13 | -----------------------------------------------------------
|
|---|
| 14 | */
|
|---|
| 15 | define('DIR_TMPL_JS', 'templates/'.CURRENT_TEMPLATE. '/javascript/');
|
|---|
| 16 | // this javascriptfile get includes at the TOP of every template page in shop
|
|---|
| 17 | // you can add your template specific js scripts here
|
|---|
| 18 |
|
|---|
| 19 | $js_app_plain = DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/javascript/app.js';
|
|---|
| 20 | $js_app_min = DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/javascript/app.min.js';
|
|---|
| 21 |
|
|---|
| 22 | function compress_javascript($js_plain, $js_min, $js_filename = 'jquery.js', $js_filename_min = 'jquery.min.js'){
|
|---|
| 23 | // function should be moved to /includes/somefilename.php
|
|---|
| 24 | require_once(DIR_FS_EXTERNAL.'jsmin/min-js.php');
|
|---|
| 25 |
|
|---|
| 26 | $js_file = $js_filename;
|
|---|
| 27 |
|
|---|
| 28 | if (($js_content = file_get_contents($js_plain)) !== false) {
|
|---|
| 29 |
|
|---|
| 30 | $jSqueeze = new JSqueeze();
|
|---|
| 31 | $js_content = $jSqueeze->squeeze($js_content, true, false);
|
|---|
| 32 | try {
|
|---|
| 33 | if (file_put_contents($js_min, $js_content, LOCK_EX) !== false) {
|
|---|
| 34 | $js_file = $js_filename_min;
|
|---|
| 35 | }
|
|---|
| 36 | } catch (Exception $e) {
|
|---|
| 37 | trigger_error('func compress_javascript', $e->getMessage());
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | return $js_file;
|
|---|
| 41 |
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | function auto_compress_javascript($js_plain, $js_min, $js_filename = 'jquery.js', $js_filename_min = 'jquery.min.js'){
|
|---|
| 46 |
|
|---|
| 47 | $fs_file = $fs_filename;
|
|---|
| 48 |
|
|---|
| 49 | //TODO sql: INSERT INTO `configuration` (`configuration_id`, `configuration_key`, `configuration_value`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES (NULL, 'COMPRESS_JAVASCRIPT', 'true', '14', '5', '2016-02-26 00:00:00', '2016-02-26 00:00:00', NULL, 'xtc_cfg_select_option(array(''true'', ''false''),');
|
|---|
| 50 |
|
|---|
| 51 | if (COMPRESS_JAVASCRIPT == 'true') {
|
|---|
| 52 | //require_once(DIR_FS_EXTERNAL.'compactor/compactor.php');
|
|---|
| 53 | if (file_exists($js_min)){
|
|---|
| 54 | if (filemtime($js_plain) > filemtime($js_min)) {
|
|---|
| 55 | compress_javascript($js_plain, $js_min, $js_filename, $js_filename_min);
|
|---|
| 56 | } else {
|
|---|
| 57 | //stylesheet.css is older than stylesheet.min.css => nothing to do
|
|---|
| 58 | $js_file = $js_filename_min;
|
|---|
| 59 | }
|
|---|
| 60 | } else{
|
|---|
| 61 | // stylesheet.min.css does not exist => create
|
|---|
| 62 | compress_javascript($js_plain, $js_min, $js_filename, $js_filename_min);
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | return $js_file;
|
|---|
| 67 |
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | $js_file = auto_compress_javascript($js_app_plain,$js_app_min, 'app.js', 'app.min.js');
|
|---|
| 71 |
|
|---|
| 72 | ?>
|
|---|
| 73 | <script src="<?php echo DIR_WS_BASE.DIR_TMPL_JS.$js_file; ?>" type="text/javascript"></script>
|
|---|
| 74 |
|
|---|