author | Dan |
Sun, 27 Jan 2008 23:17:15 -0500 | |
changeset 380 | 73444271fd1c |
parent 345 | 4ccdfeee9a11 |
child 387 | 92664d2efab8 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
322
5f1cd51bf1be
Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents:
166
diff
changeset
|
5 |
* Version 1.0.3 (Dyrad) |
1 | 6 |
* Copyright (C) 2006-2007 Dan Fuhry |
7 |
* jsres.php - the Enano client-side runtime, a.k.a. AJAX on steroids |
|
8 |
* |
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 |
*/ |
|
15 |
||
16 |
if(!isset($_GET['title'])) $_GET['title'] = 'null'; |
|
17 |
require('../common.php'); |
|
18 |
||
19 |
define('ENABLE_COMPRESSION', ''); |
|
20 |
||
21 |
ob_start(); |
|
22 |
header('Content-type: text/javascript'); |
|
23 |
||
24 |
$file = ( isset($_GET['file']) ) ? $_GET['file'] : 'enano-lib-basic.js'; |
|
25 |
||
26 |
if(!preg_match('/^([a-z0-9_-]+)\.js$/i', $file)) |
|
27 |
die('// ERROR: Hacking attempt'); |
|
28 |
||
29 |
$fname = './static/' . $file; |
|
30 |
if ( !file_exists($fname) ) |
|
31 |
die('// ERROR: File not found: ' . $file); |
|
32 |
||
33 |
$everything = file_get_contents($fname); |
|
34 |
||
35 |
$mtime = filemtime($fname); |
|
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
322
diff
changeset
|
36 |
header('Last-Modified: '.enano_date('D, d M Y H:i:s T', $mtime)); |
1 | 37 |
header('Content-disposition: attachment; filename=' . $file); |
38 |
||
39 |
if(defined('ENABLE_COMPRESSION')) |
|
40 |
{ |
|
41 |
echo "/* |
|
42 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
322
5f1cd51bf1be
Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents:
166
diff
changeset
|
43 |
* Version 1.0.3 (Dyrad) |
1 | 44 |
* [Aggressively compressed] Javascript client code |
45 |
* Copyright (C) 2006-2007 Dan Fuhry |
|
36
425261984266
Added "page hint" on search page; deprecated "www." on EnanoCMS.org links
Dan
parents:
21
diff
changeset
|
46 |
* Enano is Free Software, licensed under the GNU General Public License; see http://enanocms.org/ for details. |
1 | 47 |
*/ |
48 |
||
49 |
"; |
|
50 |
||
51 |
$cache_file = ENANO_ROOT . '/cache/jsres-' . $file . '.php'; |
|
52 |
||
53 |
if ( file_exists($cache_file) ) |
|
54 |
{ |
|
55 |
$cached = file_get_contents ( $cache_file ); |
|
56 |
$data = unserialize ( $cached ); |
|
57 |
if ( $data['md5'] == md5 ( $everything ) ) |
|
58 |
{ |
|
59 |
echo "// The code in this file was fetched from cache\n\n"; |
|
60 |
echo $data['code']; |
|
61 |
exit; |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
if ( getConfig('cache_thumbs') == '1' ) |
|
66 |
{ |
|
67 |
$js_compressor = new JavascriptCompressor(); |
|
68 |
$packed = $js_compressor->getPacked($everything); |
|
69 |
$data = Array( |
|
70 |
'md5' => md5 ( $everything ), |
|
71 |
'code' => $packed |
|
72 |
); |
|
73 |
echo "// The code in this file was fetched from the static scripts and compressed (packed code cached)\n\n"; |
|
74 |
echo $packed; |
|
75 |
||
76 |
$fh = @fopen($cache_file, 'w'); |
|
77 |
if (!$fh) |
|
78 |
die('// ERROR: Can\'t open cache file for writing'); |
|
79 |
fwrite($fh, serialize ( $data ) ); |
|
80 |
fclose($fh); |
|
81 |
||
82 |
exit; |
|
83 |
} |
|
84 |
||
85 |
echo "// The code in this file was not compressed because packed-script caching is disabled\n\n"; |
|
86 |
echo $everything; |
|
87 |
||
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
echo "// The code in this file was not compressed because all script compression is disabled\n\n"; |
|
92 |
echo $everything; |
|
93 |
} |
|
94 |
?> |