forked from ucla-oarc-mobile/mwf
/
css.php
executable file
·119 lines (98 loc) · 3.13 KB
/
css.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* This file is responsible for dynamically loading CSS for the client based on
* user agent. This script outputs CSS and thus can be directly included via
* <link>.
*
* This file should be included on all pages that use the mobile framework.
*
* @package core
* @subpackage css
*
* @author ebollens
* @copyright Copyright (c) 2010-11 UC Regents
* @license http://mwf.ucla.edu/license
* @version 20110901
*
* @uses Classification
* @uses CSS
* @uses CSSMin
* @uses Path
* @uses Path_Validator
*/
/**
* Include necessary libraries.
*/
require_once(dirname(__FILE__).'/lib/classification.class.php');
require_once(dirname(__FILE__).'/lib/config.class.php');
require_once(dirname(__FILE__).'/lib/cssmin.class.php');
require_once(dirname(__FILE__).'/lib/path.class.php');
require_once(dirname(__FILE__).'/lib/path_validator.class.php');
/**
* Defines the file to be parsed as a CSS file.
*/
header('Content-Type: text/css');
if(!Classification::init())
{
header("Cache-Control: max-age=0");
}
else
{
/**
* @todo what do we do with caching here?
*/
}
?>/** Mobile Web Framework | http://mwf.ucla.edu */
<?php
/**
* Get custom CSS classes from {'css':'custom'} config variable.
*
* @link /config/css.php
*/
$custom = Config::get('css', 'custom');
if(!$custom)
$custom = array();
elseif(!is_array($custom))
$custom = array($custom);
/**
* Load all basic.css stylesheets under the default and custom directories.
*/
require_once(dirname(__FILE__).'/css/default/basic.css');
foreach($custom as $dir)
if(file_exists(dirname(__FILE__).'/css/'.$dir.'/basic.css'))
include_once(dirname(__FILE__).'/css/'.$dir.'/basic.css');
/**
* Load all standard.css stylesheets under the default and custom directories.
*/
if(Classification::is_standard())
{
require_once(dirname(__FILE__).'/css/default/standard.css');
foreach($custom as $dir)
if(file_exists(dirname(__FILE__).'/css/'.$dir.'/standard.css'))
include_once(dirname(__FILE__).'/css/'.$dir.'/standard.css');
}
/**
* Load all full.css stylesheets under the default and custom directories.
*/
if(Classification::is_full())
{
require_once(dirname(__FILE__).'/css/default/full.css');
foreach($custom as $dir)
if(file_exists(dirname(__FILE__).'/css/'.$dir.'/full.css'))
include_once(dirname(__FILE__).'/css/'.$dir.'/full.css');
}
/**
* Load custom CSS files (minified) based on user agent.
*/
if(isset($_GET['basic']))
foreach(explode(' ', $_GET['basic']) as $file)
if(Path_Validator::is_safe($file, 'css') && $contents = Path::get_contents($file))
echo ' ' . CSSMin::minify($contents);
if(Classification::is_standard() && isset($_GET['standard']))
foreach(explode(' ', $_GET['standard']) as $file)
if(Path_Validator::is_safe($file, 'css') && $contents = Path::get_contents($file))
echo ' ' . CSSMin::minify($contents);
if(Classification::is_full() && isset($_GET['full']))
foreach(explode(' ', $_GET['full']) as $file)
if(Path_Validator::is_safe($file, 'css') && $contents = Path::get_contents($file))
echo ' ' . CSSMin::minify($contents);