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
|
<?php
// $Id$
/**
* @file
* Handles the interface between XTemplate files and the Drupal theme system.
*/
// Initialize the xtemplate engine.
function xtemplate_init($template) {
// We cannot use the theme() or path_to_theme() functions here
if (!class_exists('XTemplate')) {
include_once(dirname(__FILE__) . '/xtemplate.inc');
}
$GLOBALS["xtemplate"] = new StdClass();
$dir = dirname($template->filename);
$GLOBALS['xtemplate']->template = new XTemplate(basename($template->filename), $dir);
$GLOBALS['xtemplate']->template->assign(array('directory' => $dir));
$GLOBALS['xtemplate']->template->SetNullBlock(' '); // '' doesn't work!
}
function xtemplate_templates() {
return system_listing('^xtemplate\.xtmpl$', 'themes', 'filename');
}
function xtemplate_features() {
return array(
'logo',
'toggle_name',
'toggle_search',
'toggle_slogan',
'toggle_mission',
'toggle_primary_links',
'toggle_secondary_links',
'toggle_node_user_picture',
'toggle_comment_user_picture');
}
function xtemplate_node($node, $main = 0, $page = 0) {
global $xtemplate;
$xtemplate->template->assign(array(
"submitted" => theme_get_setting("toggle_node_info_$node->type") ?
t("Submitted by %a on %b.",
array("%a" => format_name($node),
"%b" => format_date($node->created))) : '',
"link" => url("node/$node->nid"),
"title" => $node->title,
"author" => format_name($node),
"date" => format_date($node->created),
"sticky" => ($main && $node->sticky) ? 'sticky' : '',
"content" => ($main && $node->teaser) ? $node->teaser : $node->body));
if ($page == 0) {
$xtemplate->template->parse("node.title");
}
if (theme_get_setting('toggle_node_user_picture') && $picture = theme('user_picture', $node)) {
$xtemplate->template->assign("picture", $picture);
$xtemplate->template->parse("node.picture");
}
if (module_exist("taxonomy") && ($taxonomy = taxonomy_link("taxonomy terms", $node))) {
$xtemplate->template->assign("taxonomy", theme_links($taxonomy));
$xtemplate->template->parse("node.taxonomy");
}
if ($node->links) {
$xtemplate->template->assign("links", theme_links($node->links));
$xtemplate->template->parse("node.links");
}
$xtemplate->template->parse("node");
$output = $xtemplate->template->text("node");
$xtemplate->template->reset("node");
return $output;
}
function xtemplate_comment($comment, $links = 0) {
global $xtemplate;
$xtemplate->template->assign(array (
"new" => t("new"),
"submitted" => t("Submitted by %a on %b.",
array("%a" => format_name($comment),
"%b" => format_date($comment->timestamp))),
"title" => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid"),
"author" => format_name($comment),
"date" => format_date($comment->timestamp),
"content" => $comment->comment
));
if ($comment->new) {
$xtemplate->template->parse("comment.new");
}
if (theme_get_setting('toggle_comment_user_picture') && $picture = theme('user_picture', $comment)) {
$xtemplate->template->assign("picture", $picture);
$xtemplate->template->parse("comment.picture");
}
if ($links) {
$xtemplate->template->assign("links", $links);
$xtemplate->template->parse("comment.links");
}
$xtemplate->template->parse("comment");
$output = $xtemplate->template->text("comment");
$xtemplate->template->reset("comment");
return $output;
}
function xtemplate_page($content) {
global $xtemplate;
$xtemplate->template->assign(array(
"language" => $GLOBALS['locale'],
"head_title" => (drupal_get_title() ? drupal_get_title() ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")),
"head" => drupal_get_html_head(),
"styles" => theme_get_styles(),
"onload_attributes" => theme_onload_attribute(),
"primary_links" => theme_get_setting('primary_links'),
"secondary_links" => theme_get_setting('secondary_links')
));
if ($logo = theme_get_setting('logo')) {
$xtemplate->template->assign('logo', $logo);
$xtemplate->template->parse('header.logo');
}
if (theme_get_setting('toggle_name')) {
$xtemplate->template->assign('site_name', variable_get('site_name', ''));
$xtemplate->template->parse('header.site_name');
}
if (theme_get_setting('toggle_slogan')) {
$xtemplate->template->assign('site_slogan', variable_get('site_slogan', ''));
$xtemplate->template->parse('header.site_slogan');
}
if ($tabs = theme('menu_local_tasks')) {
$xtemplate->template->assign("tabs", $tabs);
$xtemplate->template->parse("header.title.tabs");
}
if ($title = drupal_get_title()) {
$xtemplate->template->assign("title", $title);
$xtemplate->template->assign("breadcrumb", theme("breadcrumb", drupal_get_breadcrumb()));
$xtemplate->template->parse("header.title");
}
if ($help = menu_get_active_help()) {
$xtemplate->template->assign("help", $help);
$xtemplate->template->parse("header.help");
}
if ($message = theme_status_messages()) {
$xtemplate->template->assign("message", $message);
$xtemplate->template->parse("header.message");
}
if (theme_get_setting('toggle_search')) {
$xtemplate->template->assign(array(
//"search" => search_form(),
"search_url" => url("search"),
"search_button_text" => t("Search"),
"search_description" => t("Enter the terms you wish to search for.")
));
$xtemplate->template->parse("header.search_box");
}
// only parse the mission block if we are on the frontpage ...
if ($_GET["q"] == variable_get("site_frontpage", "node") && theme_get_setting('toggle_mission') && ($mission = theme_get_setting('mission'))) {
$xtemplate->template->assign("mission", $mission);
$xtemplate->template->parse("header.mission");
}
if ($blocks = theme("blocks", "left")) {
$xtemplate->template->assign("blocks", $blocks);
$xtemplate->template->parse("header.blocks");
}
$xtemplate->template->parse("header");
$output = $xtemplate->template->text("header");
$output .= "\n<!-- begin content -->\n";
$output .= $content;
$output .= "\n<!-- end content -->\n";
if ($blocks = theme("blocks", "right")) {
$xtemplate->template->assign("blocks", $blocks);
$xtemplate->template->parse("footer.blocks");
}
// only parse the footer block if site_footer is set
if ($footer_message = variable_get("site_footer", FALSE)) {
$xtemplate->template->assign("footer_message", $footer_message);
$xtemplate->template->parse("footer.message");
}
$xtemplate->template->assign("footer", theme_closure());
$xtemplate->template->parse("footer");
$output .= $xtemplate->template->text("footer");
return $output;
}
function xtemplate_block(&$block) {
global $xtemplate;
// create template variables for all block variables (module, delta, region, subject, content, ...)
foreach ($block as $key => $value) {
$xtemplate->template->assign($key == "subject" ? "title" : $key, $value); // TODO: standardize on 'title' (ie. rename all $block["subject"] to "title")
}
$xtemplate->template->parse("block");
$output = $xtemplate->template->text("block");
$xtemplate->template->reset("block");
return $output;
}
function xtemplate_box($title, $content, $region = "main") {
global $xtemplate;
$xtemplate->template->assign(array(
"title" => $title,
"content" => $content));
$xtemplate->template->parse("box");
$output = $xtemplate->template->text("box");
$xtemplate->template->reset("box");
return $output;
}
?>
|