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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
<?php
/**
Theme System - controls the output of Drupal.
The theme system allows for nearly all output of the Drupal system to be
customized by user themes.
@package theme_system
@defgroup theme_system
@{
**/
/* $Id$ */
/**
Returns the theme header.
@param $title (optional) override the page title.
@return a string containing the \a header output.
**/
function theme_header($title = "") {
global $base_url;
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
$output .= "<head>";
$output .= " <title>". $title ? $title : variable_get(site_name, "drupal") ."</title>";
$output .= theme_head($main);
$output .= " <style type=\"text/css\" media=\"all\">";
$output .= " @import url(misc/drupal.css);";
$output .= " </style>";
$output .= " </head>";
$output .= " <body style=\"background-color: #fff; color: #000;\"". theme("onload_attribute"). "\">";
$output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td style=\"vertical-align: top; width: 170px;\">";
$output .= theme("box", t("Navigation"), @implode("<br />", link_page()));
$output .= theme("blocks", "all");
$output .= "</td><td style=\"vertical-align: top;\">";
$output .= theme("breadcrumb", drupal_get_breadcrumb());
$output .= "<h1>" . drupal_get_title() . "</h1>";
if ($help = menu_get_active_help()) {
$output .= "<small>$help</small><hr />";
}
return $output;
}
/**
Returns themed set of links.
@param $links an array of \a links to be themed.
@param $delimiter (optional) \a delimiter used to separate the links.
@return a string containing the \a links output.
**/
function theme_links($links, $delimiter = " | ") {
return implode($delimiter, $links);
}
/**
Returns themed image.
@param $name the \a name of the image file.
@return a string containing the \a image output.
**/
function theme_image($name) {
return "misc/$name";
}
/**
Returns a themed breadcrumb menu.
@param $breadcrumb an array containing the breadcrumb links.
@return a string containing the \a breadcrumb output.
**/
function theme_breadcrumb($breadcrumb) {
return "<div class=\"breadcrumb\">". implode($breadcrumb, " » ") ."</div>";
}
/**
Returns themed node.
The passed $node object provides a all relevant information for displaying a node:
\li \c $node->nid
\li \c $node->type i.e. story, blog, forum.
\li \c $node->title
\li \c $node->created a unix timestamp.
\li \c $node->teaser
\li \c $node->body
\li \c $node->changed a unix timestamp.
\li \c $node->uid the id of the poster.
\li \c $node->username the username of the poster.
@param $node the \a node to be themed.
@param $main
@return a string containing the \a node output.
**/
function theme_node($node, $main) {
if (module_exist("taxonomy")) {
$terms = taxonomy_link("taxonomy terms", $node);
}
$output = "<h2>$node->title</h2> by ". format_name($node);
if (count($terms)) {
$output .= " <small>(". print theme("links", $terms) .")</small><br />";
}
if ($main && $node->teaser) {
$output .= $node->teaser;
}
else {
$output .= $node->body;
}
if ($links = link_node($node, $main)) {
$output .= "<br />[ ". print theme("links", $links) ." ]";
}
$output .= "<hr />";
return $output;
}
function _theme_table_cell($cell, $header = 0) {
if (is_array($cell)) {
$data = $cell["data"];
foreach ($cell as $key => $value) {
if ($key != "data") {
$attributes .= " $key=\"$value\"";
}
}
}
else {
$data = $cell;
}
if ($header) {
$output = "<th$attributes>$data</th>";
}
else {
$output = "<td$attributes>$data</td>";
}
return $output;
}
/**
Returns themed table.
@param $title the form element's title
@param $value the form element's data
@param $description the form element's description or explanation
@return a string contraining the \a node output.
**/
function theme_form_element($title, $value, $description = 0) {
return "<div class=\"form-item\">". ($title ? "<label>$title:</label><br />" : "") . $value . ($description ? "<div class=\"description\">$description</div>" : "") ."</div>\n";
}
/**
Returns themed table.
@param $header
@param $rows
@return a string contraining the \a node output.
**/
function theme_table($header, $rows) {
$output = "<table>\n";
/*
** Emit the table header:
*/
if (is_array($header)) {
$output .= " <tr>";
foreach ($header as $cell) {
if (is_array($cell) && $cell["field"]) {
$cell = tablesort($cell, $header);
}
$output .= _theme_table_cell($cell, 1);
}
$output .= " </tr>\n";
}
/*
** Emit the table rows:
*/
if (is_array($rows)) {
foreach ($rows as $number => $row) {
if ($number % 2 == 1) {
$output .= " <tr class=\"light\">";
}
else {
$output .= " <tr class=\"dark\">";
}
foreach ($row as $cell) {
$output .= _theme_table_cell($cell, 0);
}
$output .= " </tr>\n";
}
}
$output .= "</table>\n";
return $output;
}
/**
Returns themed box.
@param $subject the \a subject of the box.
@param $content the \a content of the box.
@param $region the \a region of the box.
@return a string containing the \a box output.
**/
function theme_box($subject, $content, $region = "main") {
$output = "<h2>$subject</h2><p>$content</p>";
return $output;
}
/**
Returns a themed block.
You can style your blocks by defining .block (all blocks),
.block-<i>module</i> (all blocks of module <i>module</i>),
and \#block-<i>module</i>-<i>delta</i> (specific block of
module <i>module</i> with delta <i>delta</i>) in your
theme's CSS.
@param $block object "indexed with" fields from database table 'blocks' ($block->module, $block->delta, $block->region, ...) and fields returned by <i>module</i>_block("view") ($block->subject, $block->content, ...).
@return a string containing the \a box output.
**/
function theme_block($block) {
$output = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">";
$output .= " <h3>$block->subject</h3>";
$output .= " <div class=\"content\">$block->content</div>";
$output .= "</div>";
return $output;
}
/**
Returns themed page footer.
@return a string containing the \a footer output.
**/
function theme_footer() {
$output = "</td></tr></table>";
$output .= theme_closure();
$output .= "</body></html>";
return $output;
}
/**
Returns themed marker, useful for marking new comments or required form elements.
@return a string containing the \a mark output.
**/
function theme_mark() {
return "<span class=\"marker\">*</span>";
}
/**
Returns themed list of items.
@param $items (optional) an array of the items to be displayed in a list.
@param $title (optional) the title of the list.
@return a string containing the \a list output.
**/
function theme_item_list($items = array(), $title = NULL) {
$output .= "<div class=\"item-list\">";
if (isset($title)) {
$output .= "<h3>$title</h3>";
}
if (isset($items)) {
$output .= "<ul>";
foreach ($items as $item) {
$output .= "<li>$item</li>";
}
$output .= "</ul>";
}
$output .= "</div>";
return $output;
}
/**
Returns themed error message.
@param $message the error message to be themed.
@return a string containing the \a error output.
**/
function theme_error($message) {
return "<div class=\"error\">$message</div>";
}
/**
Execute hook _head which is run at the start of the page, and output should be in the head tags.
@param $main (optional)
@return a string containing the \a error output.
**/
function theme_head($main = 0) {
global $base_url;
$output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
$output .= "<base href=\"$base_url/\" />\n";
$output .= "<style type=\"text/css\">\n";
$output .= "@import url(misc/drupal.css);\n";
$output .= "</style>\n";
$head = module_invoke_all("head", $main);
$output .= implode($head, "\n");
return $output;
}
/**
Execute hook _footer() which is run at the end of the page right
before the </body> tag.
@param $main (optional)
@return a string containing the \a closure output.
**/
function theme_closure($main = 0) {
$footer = module_invoke_all("footer", $main);
return implode($footer, "\n");
}
/**
Call _onload hook in all modules to enable modules to insert javascript
that will get run once the page has been loaded by the browser.
@param $theme_onloads (optional) addition onload directives.
@return a string containing the \a onload output.
**/
function theme_onload_attribute($theme_onloads = array()) {
if (!is_array($theme_onloads)) {
$theme_onloads = array($theme_onloads);
}
// Merge theme onloads (javascript rollovers, image preloads, etc.)
// with module onloads (htmlarea, etc.)
$onloads = array_merge(module_invoke_all("onload"), $theme_onloads);
if (count($onloads)) {
return " onload=\"" . implode("; ", $onloads) . "\"";
}
return "";
}
/**
* Returns themed blocks available for current $user at $region.
*
* @param $region main|left|right
*
* @return a string containing the \a blocks output.
*/
function theme_blocks($region) {
$output = "";
if ($list = module_invoke('block', 'list', $region)) {
foreach ($list as $key => $block) {
// $key == <i>module</i>_<i>delta</i>
$output .= theme('block', $block);
}
}
return $output;
}
/**
Hook Help - returns theme specific help and information.
@param section defines the \a section of the help to be returned.
@return a string containing the help output.
**/
function theme_help($section) {
$ouptout = "";
switch ($section) {
case 'admin/system/themes#description':
$output = t("The base theme");
break;
}
return $output;
}
/**
Provides a list of currently available themes.
@param $refresh
@return an array of the currently available themes.
**/
function list_themes($refresh = 0) {
static $list;
if ($refresh) {
unset($list);
}
if (!$list) {
$list = array();
$result = db_query("SELECT * FROM {system} where type = 'theme' AND status = '1' ORDER BY name");
while ($theme = db_fetch_object($result)) {
if (file_exists($theme->filename)) {
$list[$theme->name] = $theme;
}
}
}
return $list;
}
/**
Initialized the theme system.
@return the name of the currently selected theme.
**/
function init_theme() {
global $user;
$themes = list_themes();
$name = $user->theme ? $user->theme : variable_get("theme_default", 0);
$theme->path = "";
$theme->name = "";
if (is_object($themes[$name])) {
include_once($themes[$name]->filename);
$theme->path = dirname($themes[$name]->filename);
$theme->name = $name;
}
return $theme;
}
/**
Returns the path to the currently selected theme.
@return the path to the the currently selected theme.
**/
function path_to_theme() {
global $theme;
return $theme->path;
}
/**
External interface of the theme system to all other modules, and core files.
All requests for themed functions must go through this function. It examines
the request and routes it to the appropriate theme function. If the current
theme does not implement the requested function, then the base theme function
is called.
Example: \verbatim $header_text = theme("header"); \endverbatim
@return the path to the the currently selected theme.
**/
function theme() {
global $theme;
$args = func_get_args();
$function = array_shift($args);
if (($theme->name != "") && (function_exists($theme->name ."_". $function))) {
return call_user_func_array($theme->name ."_". $function, $args);
}
elseif (function_exists("theme_". $function)){
return call_user_func_array("theme_". $function, $args);
}
}
/** @} End of defgroup theme_system **/
?>
|