forked from Eric-Brison/dynacase-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.php
56 lines (50 loc) · 1.68 KB
/
pack.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
* pack js or css files
* @author Anakeen
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
* @package FDL
*/
/**
*/
include_once ("config/sessionHandler.php");
function setHeaderCache($type)
{
$mime = "text/plain";
if ($type == 'css') {
$mime = 'text/css';
} elseif ($type == 'js') {
$mime = 'text/javascript';
}
ini_set('session.cache_limiter', 'none');
$duration = 24 * 3600;
header("Cache-Control: private, max-age=$duration"); // use cache client (one day) for speed optimsation
header("Expires: " . gmdate("D, d M Y H:i:s T\n", time() + $duration)); // for mozilla
header("Pragma: none"); // HTTP 1.0
header("Content-Disposition: inline;");
header("Content-type: $mime");
}
function exitError($text)
{
header('HTTP/1.0 503 ' . $text);
exit;
}
$cookName = 'dcpsession'; // see Session::PARAMNAME .. not included here to be independant
if (!isset($_COOKIE[$cookName])) exitError('Not connected');
$sessid = $_COOKIE[$cookName];
if (!isset($_GET["pack"])) exitError('No pack set');
if (!isset($_GET["type"])) exitError('No type set');
if ($_GET["type"] != "js" && $_GET["type"] != "css") exitError('No compatible type');
$packName = $_GET["pack"];
$type = $_GET["type"];
session_id($sessid);
session_start();
if (!isset($_SESSION['RSPACK_' . $packName])) exitError('No pack reference found');
$packDef = $_SESSION['RSPACK_' . $packName];
setHeaderCache($type);
foreach ($packDef as $fileRef) {
$path = $fileRef["ref"];
printf("\n/*include : %s */\n", $path);
if (!file_exists($path)) exitError(sprintf('File %s not found', $path));
print file_get_contents($path);
}