-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresource.php
More file actions
100 lines (99 loc) · 3.85 KB
/
resource.php
File metadata and controls
100 lines (99 loc) · 3.85 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/******************************************************
* Protolus : Render + Data
******************************************************
* @created 09/09/09
* @author Abbey Hawk Sparrow
* @name root index
******************************************************
* This script provides an entry point for all URLS to
* map to a panel, redirection, or to location failure
* It also performs all needed App initialization
* todo: replace this header block with YAML
******************************************************/
require('./Protolus/bootstrap.php');
$resources = explode('-', WebApplication::getGet('resources'));
//echo('minify: '.WebApplication::getGet('minify')); exit();
if(WebApplication::getGet('minify')){
$minString = '.min';
}
$v = WebApplication::getGet('version');
$fileName = '/tmp/ResourceCache/'.WebApplication::getGet('resources').$minString.'.'.WebApplication::getGet('type');
$componentConfName = '/tmp/ResourceCache/'.WebApplication::getGet('resources').$minString.'.'.WebApplication::getGet('type');
if(!file_exists(dirname($fileName))) mkdir(dirname($fileName));
$mostRecentTime = 0;
foreach($resources as $resourceName){
$time = filemtime('Resources/'.$resourceName.'/component.json');
if($mostRecentTime < $time) $mostRecentTime = $time;
}
$rootDir = getcwd();
if(file_exists($fileName) && filemtime($fileName) > $mostRecentTime){
echo(file_get_contents($fileName));
exit();
}else{
chdir('min/lib');
require('min/utils.php');
require('Minify.php');
require('JSMin.php');
require('Minify/CSS.php');
require_once('Minify/CSS/Compressor.php');
//Minify_CSS::minify('');
//chdir('../..');
$items = array();
$code = '';
$allItems = array();
foreach($resources as $resourceName){
chdir('../..');
$resource = new ResourceBundle($resourceName, Formats::loadFile('Resources/'.$resourceName.'/component.json', 'json'));
chdir('min/lib');
$items = $resource->resourceItems(true, true);
//print_r($resources); print_r($items); exit();
foreach($items as $index=>$item){
switch(strtolower(WebApplication::getGet('type'))){
case 'js' :
if(strtolower(substr($item, -3)) != '.js') unset($items[$index]);
break;
case 'css' :
//echo('Style: '.strtolower(substr($item, -4))); exit();
if(strtolower(substr($item, -4)) != '.css') unset($items[$index]);
break;
}
}
$allItems = array_merge($allItems, $items);
}
//file_put_contents($fileName, $code);
}
//chdir('../..');
//echo($rootDir); exit();
$mapper = function($string) { global $rootDir; return $rootDir.$string; };
$allItems = array_map($mapper, $allItems);
//print_r($resources); print_r($allItems); exit();
if(count($allItems) == 0){
echo('');
exit();
}
//*
switch(strtolower(WebApplication::getGet('type'))){
case 'js' :
WebApplication::addHeader("Content-type: text/javascript");
break;
case 'css' :
WebApplication::addHeader("Content-type: text/css");
break;
}//*/
if(strtolower(WebApplication::getGet('minify')) == 'true'){
Minify::setCache('/tmp/ResourceCache');
Minify::serve('Files', array(
'files' => $allItems,
'maxAge' => 86400
));//*/
}else{
$res = '';
foreach($allItems as $item){
$res .= file_get_contents($item).';';
}
echo($res);
}
//echo($code);*/
exit();
?>