-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAmslib_Resource.php
executable file
·199 lines (171 loc) · 5.33 KB
/
Amslib_Resource.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/*******************************************************************************
* Copyright (c) {15/03/2008} {Christopher Thomas}
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Contributors/Author:
* {Christopher Thomas} - Creator - [email protected]
*
*******************************************************************************/
/**
* class: Amslib_Resource
*
* group: core
*
* file: Amslib_Resource.php
*
* description: todo, write description
*
* todo: write documentation
*/
class Amslib_Resource
{
static protected $stylesheet = array("__common"=>array());
static protected $javascript = array("__common"=>array());
static protected $default_position = "__common";
static protected function validatePosition($position=NULL)
{
return is_string($position) && strlen($position)
? $position
: self::$default_position;
}
/**
* method: addStylesheet
*
* todo: write documentation
*/
static public function addStylesheet($id,$file,$conditional=NULL,$media=NULL,$position=NULL)
{
$position = self::validatePosition($position);
if(!isset(self::$stylesheet[$position])) self::$stylesheet[$position] = array();
$p = &self::$stylesheet[$position];
if($id && $file){
$media = $media ? "media='$media'" : "";
$p[$id] = "<link rel='stylesheet' type='text/css' href='$file' $media />";
if(is_string($conditional) && strlen($conditional)){
$p[$id] = "<!--[$conditional]>{$p[$id]}<![endif]-->";
}
}
unset($p); // release the reference (prevents problems with loops)
}
/**
* method: getStylesheet
*
* todo: write documentation
*/
static public function getStylesheet($position=NULL)
{
$position = self::validatePosition($position);
if(isset(self::$stylesheet[$position])){
return implode("\n",self::$stylesheet[$position]);
}
Amslib_Debug::log(
"the requested position to obtain the stylesheets from was not valid",
$position,
array_keys(self::$stylesheet)
);
return "";
}
/**
* method: removeStylesheet
*
* todo: write documentation
*/
static public function removeStylesheet($id,$position=NULL)
{
$position = self::validatePosition($position);
if(!isset(self::$stylesheet[$position])){
Amslib_Debug::log("position requested to remove stylesheet from is not exist");
}else if(!isset(self::$stylesheet[$position][$id])){
Amslib_Debug::log("index requested to remove from stylesheet array is not valid");
}else{
unset(self::$stylesheet[$position][$id]);
}
}
/**
* method: addJavascript
*
* todo: write documentation
*/
static public function addJavascript($id,$file,$conditional=NULL,$position=NULL)
{
$position = self::validatePosition($position);
if(!isset(self::$javascript[$position])) self::$javascript[$position] = array();
$p = &self::$javascript[$position];
if($id && $file){
$p[$id] = "<script type='text/javascript' src='$file'></script>";
if(is_string($conditional) && strlen($conditional)){
$p[$id] = "<!--[$conditional]>{$p[$id]}<![endif]-->";
}
}
unset($p); // release the reference (prevents problems with loops)
}
/**
* method: getJavascript
*
* todo: write documentation
*/
static public function getJavascript($position=NULL)
{
$position = self::validatePosition($position);
if(isset(self::$javascript[$position])){
return implode("\n",self::$javascript[$position]);
}
Amslib_Debug::log(
"the requested position to obtain the javascripts from was not valid",
$position,
array_keys(self::$javascript)
);
return "";
}
/**
* method: removeJavascript
*
* todo: write documentation
*/
static public function removeJavascript($id,$position=NULL)
{
$position = self::validatePosition($position);
if(!isset(self::$javascript[$position])){
Amslib_Debug::log("position requested to remove javascript from is not valid");
}else if(!isset(self::$javascript[$position][$id])){
Amslib_Debug::log("index requested to remove from javascript array is not valid");
}else{
unset(self::$javascript[$position][$id]);
}
}
/**
* method: addFont
*
* todo: write documentation
*/
static public function addFont($id,$font,$conditional=NULL,$position)
{
$position = self::validatePosition($position);
self::addStylesheet($id,"http://fonts.googleapis.com/css?$font",$conditional,NULL,$position);
}
/**
* method: removeFont
*
* todo: write documentation
*/
static public function removeFont($id,$position=NULL)
{
self::removeStylesheet($id,$position);
}
// DEPRECATED GOOGLE FONT METHODS
static public function addGoogleFont($id,$font,$conditional=NULL){ self::addFont($id,$font,$conditional); }
static public function removeGoogleFont($id){ self::removeFont($id);}
}