/[drupal]/contributions/modules/color_soc08/color.misc.inc
ViewVC logotype

Contents of /contributions/modules/color_soc08/color.misc.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Aug 22 10:21:56 2008 UTC (15 months ago) by skiquel
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +188 -4 lines
File MIME type: text/x-php
head commit
1 <?php
2 // $Id: color.misc.inc,v 1.5.2.3 2008/08/20 16:45:41 skiquel Exp $
3 /**
4 * @file
5 * Misc functions.
6 */
7
8 /**
9 * Tests individual theme color.module support
10 *
11 * @param $theme
12 * String of theme name
13 */
14 function color_compatible($theme) {
15 static $static;
16
17 $path = drupal_get_path('theme', $theme);
18 $file = $path .'/color/color.inc';
19 if ($path && file_exists($file)) {
20 $static[$theme] = TRUE;
21 }
22 else {
23 $static[$theme] = FALSE;
24 }
25
26 return $static[$theme];
27 }
28
29 /**
30 * Return a list of colorable themes
31 *
32 * @return
33 * Array of themes that support color.module
34 */
35 function color_list_colorable_themes() {
36 $lthemes = list_themes();
37 foreach ($lthemes as $theme) {
38 if (color_compatible($theme->name)) {
39 $themes[] = $theme->name;
40 }
41 }
42 return $themes;
43 }
44
45 /**
46 * Recursively remove directly and file contents at location by directory
47 *
48 * @param $directory
49 * String of directory path
50 * @param $theme
51 * Optional string for theme name
52 */
53 function color_rm_dir($directory, $theme = NULL) {
54 if (is_dir($directory)) {
55 $directory = (substr($directory, -1) != "/") ? $directory."/" : $directory;
56 $open_dir = opendir($directory);
57
58 while ($file = readdir($open_dir)) {
59 if (!in_array($file, array(".", "..")) && (!$theme || ($theme && strstr($directory.$file, $theme)))) {
60 if (!is_dir($directory.$file))
61 @unlink($directory.$file);
62 else
63 color_rm_dir($directory.$file, $theme);
64 }
65 }
66 closedir($open_dir);
67 @rmdir($directory);
68 }
69 }
70
71 /**
72 * Normalize theme names
73 *
74 * @param $string
75 * String to normalize
76 * @return
77 * Normalizing string.
78 */
79 function color_normalize($string) {
80 $string = preg_replace('~[^a-z0-9._]+~', '-', drupal_strtolower($string));
81 return $string;
82 }
83
84 /**
85 * Check the color.inc file for theme
86 *
87 * @param $info
88 * Array of theme info from color.inc. Usually taken from color_get_theme_info($theme, 'inc')
89 * @return
90 * TRUE if theme validates. FALSE if not. Also output drupal error/status messages.
91 */
92 function color_validate($info) {
93 $validated = TRUE;
94 $theme = $info['theme'];
95
96 // Is 'options' set?
97 if (isset($info['engine'])) {
98 // Are any of the two engine options set?
99 if ((array_key_exists('shift', $info['engine']) === FALSE) && (array_key_exists('tag', $info['engine']) === FALSE)) {
100 drupal_set_message("(".$theme.") info[engine]: missing 'shift' and/or 'tag' option.", 'error');
101 $validated = FALSE;
102 }
103
104
105 // Catch common color.inc error. Not referencing 'shift' mode when base/link/text option stated.
106 if (isset($info['engine']['shift']) && array_search('base', $info['engine']['shift']) !== FALSE && array_search('base-only', $info['engine']['shift']) !== FALSE) {
107 drupal_set_message("(".$theme.") info[engine][shift]: missing 'base' or 'base-only' option");
108 }
109 }
110 else {
111 drupal_set_message("(".$theme.") info[engine]: missing.", 'error');
112 $validated = FALSE;
113 }
114
115 if (isset($info['fields'])) {
116 $fieldcount = count($info['fields']);
117 }
118 else {
119 drupal_set_message("(".$theme.") info[fields]: missing.", 'error');
120 $validated = FALSE;
121 }
122
123 if (isset($info['img'])) {
124 if (isset($info['blend_target'])) {
125 if (strlen($info['blend_target']) != 7) {
126 drupal_set_message("(".$theme.") info[blend_target]: (".$info['blend_target'].") is not a valid full hex (i.e. #ffffff).", 'error');
127 $validated = FALSE;
128 }
129 }
130 else {
131 drupal_set_message("(".$theme.") info[blend_target]: missing.", 'error');
132 $validated = FALSE;
133 }
134 }
135
136 if (isset($info['default_scheme'])) {
137 if (array_search($info['default_scheme'], array_keys($info['schemes'])) === FALSE) {
138 $validated = FALSE;
139 drupal_set_message("(".$theme.") info[default_scheme] (".$info['default_scheme']."): does not match a scheme name.", 'error');
140 }
141 }
142 else {
143 drupal_set_message("(".$theme.") info[default_scheme]: missing.", 'error');
144 $validated = FALSE;
145 }
146
147 if (isset($info['engine']['shift']) && (array_search('base', $info['engine']['shift']) !== FALSE || array_search('base-only', $info['engine']['shift']) !== FALSE)) {
148 if (isset($info['reference_scheme'])) {
149 if (array_search($info['reference_scheme'], array_keys($info['schemes'])) === FALSE) {
150 $validated = FALSE;
151 drupal_set_message("(".$theme.") info[reference_scheme] (".$info['reference_scheme']."): does not match a scheme name", 'error');
152 }
153 }
154 else {
155 drupal_set_message("(".$theme.") info[reference_scheme]: missing.", 'error');
156 $validated = FALSE;
157 }
158 }
159
160 if (isset($info['schemes'])) {
161 if (isset($info['engine']['shift']) && array_search('base-only', $info['engine']['shift']) === FALSE) {
162 foreach ($info['schemes'] as $key => $v) {
163 $commas = count($v);
164 foreach ($v as $num => $hex) {
165 if (!isset($hex) || empty($hex)) {
166 drupal_set_message("(".$theme.") info[schemes][{$key}]: missing color field {$num} is missing. (Color scheme fields error)", 'error');
167 drupal_set_message("(".$theme.") (Color scheme fields error): It is possible a comma may be misplaced, leaving the colors out of order.", 'warning', FALSE);
168 $validated = FALSE;
169
170 }
171 elseif (strlen($hex) != 7) {
172 drupal_set_message("(".$theme.") info[schemes][{$key}]: color field {$num} ({$hex}) is not a full hex (i.e. #ffffff).", 'error');
173 $validated = FALSE;
174 }
175 }
176 }
177 }
178 }
179 elseif (!isset($info['schemes'])) {
180 drupal_set_message("(".$theme.") info[schemes]: missing.", 'error');
181 $validated = FALSE;
182 }
183 else {
184
185 }
186
187 if (isset($info['css'])) {
188 foreach ($info['css'] as $val) {
189 // Check for file
190 if (!isset($val)) {
191 $validated = FALSE;
192 drupal_set_message("(".$theme.") info[css][{$val}]: No File provided for image!", 'error');
193 }
194 else {
195 $path = drupal_get_path('theme', $theme) .'/';
196 $file = $path . $val;
197 if ($path && !file_exists($file)) {
198 $validated = FALSE;
199 drupal_set_message("(".$theme.") info[css][{$val}]: File ({$file}) does not exist.", 'error');
200 }
201 }
202 }
203 }
204
205 if (isset($info['img'])) {
206 // Move through $info['img'] array
207 foreach ($info['img'] as $key => $val) {
208
209 // Check for file
210 if (!isset($val['file'])) {
211 $validated = FALSE;
212 drupal_set_message("(".$theme.") info[img][{$key}][file] - No File provided for image!", 'error');
213 }
214 else {
215 $path = drupal_get_path('theme', $theme) .'/';
216 $file = $path . $val['file'];
217 if ($path && !file_exists($file)) {
218 $validated = FALSE;
219 drupal_set_message("(".$theme.") info[img][{$key}][file] - File does not exist.", 'error');
220 }
221 }
222
223 // Fill
224 if (isset($val['fill'])) {
225 foreach ($val['fill'] as $fill) {
226 // Possible feature: check dimensions
227 if (array_search($fill[4], $info['fields']) === FALSE) {
228 $validated = FALSE;
229 drupal_set_message("(".$theme.") Missing fill color.", 'error');
230 }
231 }
232 }
233
234 // Gradient
235 if (isset($val['gradient'])) {
236 foreach ($val['gradient'] as $gradient) {
237 // Possible feature: check dimensions
238 if (array_search($gradient[4], $info['fields']) === FALSE) {
239 $validated = FALSE;
240 drupal_set_message("(".$theme.") Missing the top color field.", 'error');
241 }
242 if (array_search($gradient[5], $info['fields']) === FALSE) {
243 $validated = FALSE;
244 drupal_set_message("(".$theme.") Missing the bottom color field", 'error');
245 }
246 }
247 }
248 }
249 }
250 return $validated;
251 }

  ViewVC Help
Powered by ViewVC 1.1.2