xtemplate.engine

  1. drupal
    1. 4.6 themes/engines/xtemplate/xtemplate.engine

Handles the interface between XTemplate files and the Drupal theme system.

Functions & methods

NameDescription
xtemplate_block
xtemplate_box
xtemplate_comment
xtemplate_features
xtemplate_init
xtemplate_node
xtemplate_page
xtemplate_templates

File

themes/engines/xtemplate/xtemplate.engine
View source
  1. // $Id$
  2. /**
  3. * @file
  4. * Handles the interface between XTemplate files and the Drupal theme system.
  5. */
  6. // Initialize the xtemplate engine.
  7. function xtemplate_init($template) {
  8. // We cannot use the theme() or path_to_theme() functions here
  9. if (!class_exists('XTemplate')) {
  10. include_once(dirname(__FILE__) . '/xtemplate.inc');
  11. }
  12. $GLOBALS["xtemplate"] = new StdClass();
  13. $dir = dirname($template->filename);
  14. $GLOBALS['xtemplate']->template = new XTemplate(basename($template->filename), $dir);
  15. $GLOBALS['xtemplate']->template->assign(array('directory' => $dir));
  16. $GLOBALS['xtemplate']->template->SetNullBlock(' '); // '' doesn't work!
  17. }
  18. function xtemplate_templates() {
  19. return system_listing('^xtemplate\.xtmpl$', 'themes', 'filename');
  20. }
  21. function xtemplate_features() {
  22. return array(
  23. 'logo',
  24. 'toggle_name',
  25. 'toggle_search',
  26. 'toggle_slogan',
  27. 'toggle_mission',
  28. 'toggle_primary_links',
  29. 'toggle_secondary_links',
  30. 'toggle_node_user_picture',
  31. 'toggle_comment_user_picture');
  32. }
  33. function xtemplate_node($node, $main = 0, $page = 0) {
  34. global $xtemplate;
  35. $xtemplate->template->assign(array(
  36. "submitted" => theme_get_setting("toggle_node_info_$node->type") ?
  37. t("Submitted by %a on %b.",
  38. array("%a" => format_name($node),
  39. "%b" => format_date($node->created))) : '',
  40. "link" => url("node/$node->nid"),
  41. "title" => check_plain($node->title),
  42. "author" => format_name($node),
  43. "date" => format_date($node->created),
  44. "sticky" => ($main && $node->sticky) ? 'sticky' : '',
  45. "content" => ($main && $node->teaser) ? $node->teaser : $node->body));
  46. if ($page == 0) {
  47. $xtemplate->template->parse("node.title");
  48. }
  49. if (theme_get_setting('toggle_node_user_picture') && $picture = theme('user_picture', $node)) {
  50. $xtemplate->template->assign("picture", $picture);
  51. $xtemplate->template->parse("node.picture");
  52. }
  53. if (module_exist("taxonomy") && ($taxonomy = taxonomy_link("taxonomy terms", $node))) {
  54. $xtemplate->template->assign("taxonomy", theme_links($taxonomy));
  55. $xtemplate->template->parse("node.taxonomy");
  56. }
  57. if ($node->links) {
  58. $xtemplate->template->assign("links", theme_links($node->links));
  59. $xtemplate->template->parse("node.links");
  60. }
  61. $xtemplate->template->parse("node");
  62. $output = $xtemplate->template->text("node");
  63. $xtemplate->template->reset("node");
  64. return $output;
  65. }
  66. function xtemplate_comment($comment, $links = 0) {
  67. global $xtemplate;
  68. $xtemplate->template->assign(array (
  69. "new" => t("new"),
  70. "submitted" => t("Submitted by %a on %b.",
  71. array("%a" => format_name($comment),
  72. "%b" => format_date($comment->timestamp))),
  73. "title" => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid"),
  74. "author" => format_name($comment),
  75. "date" => format_date($comment->timestamp),
  76. "content" => $comment->comment
  77. ));
  78. if ($comment->new) {
  79. $xtemplate->template->parse("comment.new");
  80. }
  81. if (theme_get_setting('toggle_comment_user_picture') && $picture = theme('user_picture', $comment)) {
  82. $xtemplate->template->assign("picture", $picture);
  83. $xtemplate->template->parse("comment.picture");
  84. }
  85. if ($links) {
  86. $xtemplate->template->assign("links", $links);
  87. $xtemplate->template->parse("comment.links");
  88. }
  89. $xtemplate->template->parse("comment");
  90. $output = $xtemplate->template->text("comment");
  91. $xtemplate->template->reset("comment");
  92. return $output;
  93. }
  94. function xtemplate_page($content) {
  95. global $xtemplate;
  96. // Construct page title
  97. if (drupal_get_title()) {
  98. $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'drupal'));
  99. }
  100. else {
  101. $head_title = array(variable_get('site_name', 'drupal'));
  102. if (variable_get('site_slogan', '')) {
  103. $head_title[] = variable_get('site_slogan', '');
  104. }
  105. }
  106. $xtemplate->template->assign(array(
  107. "language" => $GLOBALS['locale'],
  108. "head_title" => implode(' | ', $head_title),
  109. "head" => drupal_get_html_head(),
  110. "styles" => theme_get_styles(),
  111. "onload_attributes" => theme_onload_attribute(),
  112. "primary_links" => theme_get_setting('primary_links'),
  113. "secondary_links" => theme_get_setting('secondary_links')
  114. ));
  115. if ($logo = theme_get_setting('logo')) {
  116. $xtemplate->template->assign('logo', $logo);
  117. $xtemplate->template->parse('header.logo');
  118. }
  119. if (theme_get_setting('toggle_name')) {
  120. $xtemplate->template->assign('site_name', variable_get('site_name', ''));
  121. $xtemplate->template->parse('header.site_name');
  122. }
  123. if (theme_get_setting('toggle_slogan')) {
  124. $xtemplate->template->assign('site_slogan', variable_get('site_slogan', ''));
  125. $xtemplate->template->parse('header.site_slogan');
  126. }
  127. if ($tabs = theme('menu_local_tasks')) {
  128. $xtemplate->template->assign("tabs", $tabs);
  129. $xtemplate->template->parse("header.title.tabs");
  130. }
  131. if ($title = drupal_get_title()) {
  132. $xtemplate->template->assign("title", $title);
  133. $xtemplate->template->assign("breadcrumb", theme("breadcrumb", drupal_get_breadcrumb()));
  134. $xtemplate->template->parse("header.title");
  135. }
  136. if ($help = menu_get_active_help()) {
  137. $xtemplate->template->assign("help", $help);
  138. $xtemplate->template->parse("header.help");
  139. }
  140. if ($message = theme_status_messages()) {
  141. $xtemplate->template->assign("message", $message);
  142. $xtemplate->template->parse("header.message");
  143. }
  144. if (theme_get_setting('toggle_search')) {
  145. $xtemplate->template->assign(array(
  146. //"search" => search_form(),
  147. "search_url" => url("search"),
  148. "search_button_text" => t("Search"),
  149. "search_description" => t("Enter the terms you wish to search for."),
  150. "form_token" => form_token()
  151. ));
  152. $xtemplate->template->parse("header.search_box");
  153. }
  154. // only parse the mission block if we are on the frontpage ...
  155. if ($_GET["q"] == variable_get("site_frontpage", "node") && theme_get_setting('toggle_mission') && ($mission = theme_get_setting('mission'))) {
  156. $xtemplate->template->assign("mission", filter_xss($mission));
  157. $xtemplate->template->parse("header.mission");
  158. }
  159. if ($blocks = theme("blocks", "left")) {
  160. $xtemplate->template->assign("blocks", $blocks);
  161. $xtemplate->template->parse("header.blocks");
  162. }
  163. $xtemplate->template->parse("header");
  164. $output = $xtemplate->template->text("header");
  165. $output .= "\n<!-- begin content -->\n";
  166. $output .= $content;
  167. $output .= "\n<!-- end content -->\n";
  168. if ($blocks = theme("blocks", "right")) {
  169. $xtemplate->template->assign("blocks", $blocks);
  170. $xtemplate->template->parse("footer.blocks");
  171. }
  172. // only parse the footer block if site_footer is set
  173. if ($footer_message = variable_get("site_footer", FALSE)) {
  174. $xtemplate->template->assign("footer_message", $footer_message);
  175. $xtemplate->template->parse("footer.message");
  176. }
  177. $xtemplate->template->assign("footer", theme_closure());
  178. $xtemplate->template->parse("footer");
  179. $output .= $xtemplate->template->text("footer");
  180. return $output;
  181. }
  182. function xtemplate_block(&$block) {
  183. global $xtemplate;
  184. // create template variables for all block variables (module, delta, region, subject, content, ...)
  185. foreach ($block as $key => $value) {
  186. $xtemplate->template->assign($key == "subject" ? "title" : $key, $value); // TODO: standardize on 'title' (ie. rename all $block["subject"] to "title")
  187. }
  188. $xtemplate->template->parse("block");
  189. $output = $xtemplate->template->text("block");
  190. $xtemplate->template->reset("block");
  191. return $output;
  192. }
  193. function xtemplate_box($title, $content, $region = "main") {
  194. global $xtemplate;
  195. $xtemplate->template->assign(array(
  196. "title" => $title,
  197. "content" => $content));
  198. $xtemplate->template->parse("box");
  199. $output = $xtemplate->template->text("box");
  200. $xtemplate->template->reset("box");
  201. return $output;
  202. }
Login or register to post comments