2005-05-04 18:12:18 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Handles integration of templates written in pure php with the Drupal theme system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function phptemplate_init($template) {
|
|
|
|
$file = dirname($template->filename) . '/template.php';
|
|
|
|
if (file_exists($file)) {
|
|
|
|
include_once($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function phptemplate_templates($directory = 'themes') {
|
|
|
|
return system_listing('^page\.tpl\.php$', $directory, 'filename');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a template engine call.
|
|
|
|
*
|
|
|
|
* Each call to the template engine has two parts. Namely preparing
|
|
|
|
* the variables, and then doing something with them.
|
|
|
|
*
|
|
|
|
* The first step is done by all template engines / themes, the second
|
|
|
|
* step is dependent on the engine used.
|
|
|
|
*
|
|
|
|
* @param $hook
|
|
|
|
* The name of the theme function being executed.
|
|
|
|
* @param $variables
|
|
|
|
* A sequential array of variables passed to the theme function.
|
|
|
|
* @param $file
|
|
|
|
* A suggested template file to use. If the file is not found, the default $hook.tpl.php will be used.
|
|
|
|
* @return
|
|
|
|
* The HTML generated by the template system.
|
|
|
|
*/
|
|
|
|
function _phptemplate_callback($hook, $variables = array(), $file = null) {
|
|
|
|
|
|
|
|
$variables = array_merge($variables, _phptemplate_default_variables($hook, $variables));
|
|
|
|
|
|
|
|
// Allow specified variables to be overridden
|
|
|
|
if (function_exists('_phptemplate_variables')) {
|
|
|
|
$variables = array_merge($variables, _phptemplate_variables($hook, $variables));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($variables['template_file']) {
|
|
|
|
$file = $variables['template_file'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (function_exists('_phptemplate_' . $hook)) {
|
|
|
|
return call_user_func('_phptemplate_' . $hook, $variables, $file);
|
|
|
|
}
|
|
|
|
elseif (function_exists('_phptemplate_default')) {
|
|
|
|
return call_user_func('_phptemplate_default', $hook, $variables, $file);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds additional helper variables to all templates.
|
|
|
|
*
|
|
|
|
* Counts how many times certain hooks have been called. Sidebar left / right are special cases.
|
|
|
|
*
|
|
|
|
* @param $hook
|
|
|
|
* The name of the theme function being executed.
|
|
|
|
* @param $variables
|
|
|
|
* A sequential array of variables passed to the theme function.
|
|
|
|
*/
|
|
|
|
function _phptemplate_default_variables($hook, $variables) {
|
|
|
|
static $count = array();
|
|
|
|
$count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
|
|
|
|
$variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
|
|
|
|
$variables['id'] = $count[$hook]++;
|
|
|
|
|
|
|
|
global $sidebar_indicator;
|
|
|
|
if ($hook == 'block') {
|
|
|
|
$count['block_counter'][$sidebar_indicator] = is_int($count['block_counter'][$sidebar_indicator]) ? $count['block_counter'][$sidebar_indicator] : 1;
|
|
|
|
$variables['block_zebra'] = ($count['block_counter'][$sidebar_indicator] % 2) ? 'odd' : 'even';
|
|
|
|
$variables['block_id'] = $count['block_counter'][$sidebar_indicator]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell all templates where they are located.
|
|
|
|
$variables['directory'] = path_to_theme();
|
|
|
|
|
|
|
|
if (drupal_get_path_alias($_GET['q']) == variable_get('site_frontpage', 'node')) {
|
|
|
|
$variables['is_front'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $variables;
|
|
|
|
}
|
|
|
|
|
|
|
|
function phptemplate_features() {
|
|
|
|
return array(
|
2005-07-30 17:13:48 +00:00
|
|
|
'logo',
|
|
|
|
'toggle_comment_user_picture',
|
|
|
|
'toggle_favicon',
|
|
|
|
'toggle_mission',
|
|
|
|
'toggle_name',
|
|
|
|
'toggle_node_user_picture',
|
|
|
|
'toggle_primary_links',
|
|
|
|
'toggle_search',
|
|
|
|
'toggle_secondary_links',
|
|
|
|
'toggle_slogan'
|
|
|
|
);
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the values passed to the theme_page function to be passed
|
|
|
|
* into a pluggable template engine.
|
|
|
|
*/
|
|
|
|
function phptemplate_page($content) {
|
|
|
|
/* Set title and breadcrumb to declared values */
|
|
|
|
|
|
|
|
if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
|
|
|
|
$mission = theme_get_setting('mission');
|
|
|
|
$frontpage = true;
|
|
|
|
}
|
|
|
|
|
2005-05-25 06:03:18 +00:00
|
|
|
/* Add favicon */
|
|
|
|
if (theme_get_setting('toggle_favicon')) {
|
|
|
|
drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
|
|
|
|
}
|
|
|
|
|
2005-05-04 18:12:18 +00:00
|
|
|
/**
|
|
|
|
* Populate sidebars.
|
|
|
|
*/
|
2005-07-17 19:52:10 +00:00
|
|
|
$layout = 'none';
|
2005-05-04 18:12:18 +00:00
|
|
|
global $sidebar_indicator;
|
|
|
|
/**
|
|
|
|
* Sidebar_indicator tells the block counting code to count sidebars seperately.
|
|
|
|
*/
|
|
|
|
$sidebar_indicator = 'left';
|
2005-07-17 19:52:10 +00:00
|
|
|
$sidebar_left = theme('blocks', 'left');
|
|
|
|
if ($sidebar_left != '') {
|
|
|
|
$layout = 'left';
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sidebar_indicator = 'right';
|
2005-07-17 19:52:10 +00:00
|
|
|
$sidebar_right = theme('blocks', 'right');
|
|
|
|
if ($sidebar_right != '') {
|
|
|
|
$layout = ($layout == 'left') ? 'both' : 'right';
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
$sidebar_indicator = null;
|
|
|
|
|
2005-07-25 06:59:37 +00:00
|
|
|
// Construct page title
|
|
|
|
if (drupal_get_title()) {
|
|
|
|
$head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'drupal'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$head_title = array(variable_get('site_name', 'drupal'));
|
|
|
|
if (variable_get('site_slogan', '')) {
|
|
|
|
$head_title[] = variable_get('site_slogan', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-04 18:12:18 +00:00
|
|
|
$variables = array(
|
2005-07-30 17:13:48 +00:00
|
|
|
'breadcrumb' => theme('breadcrumb', drupal_get_breadcrumb()),
|
|
|
|
'closure' => theme('closure'),
|
|
|
|
'content' => '<!-- begin content -->' . $content . '<!-- end content -->',
|
|
|
|
'footer_message' => variable_get('site_footer', FALSE),
|
|
|
|
'head' => drupal_get_html_head(),
|
2005-07-25 06:59:37 +00:00
|
|
|
'head_title' => implode(' | ', $head_title),
|
2005-07-30 17:13:48 +00:00
|
|
|
'help' => theme('help'),
|
2005-05-04 18:12:18 +00:00
|
|
|
'language' => $GLOBALS['locale'],
|
2005-07-30 17:13:48 +00:00
|
|
|
'layout' => $layout,
|
2005-05-04 18:12:18 +00:00
|
|
|
'logo' => theme_get_setting('logo'),
|
2005-07-30 17:13:48 +00:00
|
|
|
'messages' => theme('status_messages'),
|
|
|
|
'mission' => $mission,
|
|
|
|
'onload_attributes' => theme('onload_attribute'),
|
|
|
|
'primary_links' => theme_get_setting('primary_links'),
|
2005-05-04 18:12:18 +00:00
|
|
|
'site_name' => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''),
|
|
|
|
'site_slogan' => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''),
|
|
|
|
'search_box' => theme_get_setting('toggle_search'),
|
|
|
|
'search_button_text' => t('search'),
|
|
|
|
'search_description' => t('Enter the terms you wish to search for.'),
|
2005-07-30 17:13:48 +00:00
|
|
|
'search_url' => url('search'),
|
2005-05-05 07:35:58 +00:00
|
|
|
'secondary_links' => theme_get_setting('secondary_links'),
|
2005-05-04 18:12:18 +00:00
|
|
|
'sidebar_left' => $sidebar_left,
|
|
|
|
'sidebar_right' => $sidebar_right,
|
2005-07-30 17:13:48 +00:00
|
|
|
'styles' => theme_get_styles(),
|
|
|
|
'tabs' => theme('menu_local_tasks'),
|
|
|
|
'title' => drupal_get_title()
|
2005-05-04 18:12:18 +00:00
|
|
|
);
|
|
|
|
if ((arg(0) == 'node') && is_int(arg(1))) {
|
2005-07-17 19:19:55 +00:00
|
|
|
$variables['node'] = node_load(arg(1));
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _phptemplate_callback('page', $variables);
|
|
|
|
}
|
|
|
|
|
2005-07-17 19:52:10 +00:00
|
|
|
/*
|
2005-05-04 18:12:18 +00:00
|
|
|
* Prepare the values passed to the theme_node function to be passed
|
|
|
|
* into a pluggable template engine.
|
|
|
|
*/
|
2005-08-10 20:55:59 +00:00
|
|
|
function phptemplate_node($node, $teaser = 0, $page = 0) {
|
2005-05-04 18:12:18 +00:00
|
|
|
if (module_exist('taxonomy')) {
|
|
|
|
$taxonomy = taxonomy_link('taxonomy terms', $node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$taxonomy = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$variables = array(
|
2005-08-10 20:55:59 +00:00
|
|
|
'content' => ($teaser && $node->teaser) ? $node->teaser : $node->body,
|
2005-07-30 17:13:48 +00:00
|
|
|
'date' => format_date($node->created),
|
|
|
|
'links' => $node->links ? theme('links', $node->links) : '',
|
2005-08-01 05:14:05 +00:00
|
|
|
'name' => theme('username', $node),
|
2005-07-30 17:13:48 +00:00
|
|
|
'node' => $node, // we pass the actual node to allow more customization
|
|
|
|
'node_url' => url('node/'. $node->nid),
|
|
|
|
'page' => $page,
|
|
|
|
'taxonomy' => $taxonomy,
|
2005-08-10 20:55:59 +00:00
|
|
|
'teaser' => $teaser,
|
2005-07-30 17:13:48 +00:00
|
|
|
'terms' => theme('links', $taxonomy),
|
|
|
|
'title' => check_plain($node->title)
|
|
|
|
);
|
2005-05-04 18:12:18 +00:00
|
|
|
|
2005-07-17 19:52:10 +00:00
|
|
|
// Flatten the node object's member fields.
|
|
|
|
$variables = array_merge(object2array($node), $variables);
|
|
|
|
|
2005-05-04 18:12:18 +00:00
|
|
|
// Display info only on certain node types.
|
|
|
|
if (theme_get_setting('toggle_node_info_' . $node->type)) {
|
2005-08-01 05:14:05 +00:00
|
|
|
$variables['submitted'] = t('Submitted by %a on %b.', array('%a' => theme('username', $node), '%b' => format_date($node->created)));
|
2005-05-23 20:24:52 +00:00
|
|
|
$variables['picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '';
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _phptemplate_callback('node', $variables, 'node-' . $node->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the values passed to the theme_comment function to be passed
|
|
|
|
* into a pluggable template engine.
|
|
|
|
*/
|
|
|
|
function phptemplate_comment($comment, $links = 0) {
|
|
|
|
return _phptemplate_callback('comment', array(
|
2005-08-01 05:14:05 +00:00
|
|
|
'author' => theme('username', $comment),
|
2005-05-04 18:12:18 +00:00
|
|
|
'comment' => $comment,
|
|
|
|
'content' => $comment->comment,
|
2005-07-30 17:13:48 +00:00
|
|
|
'date' => format_date($comment->timestamp),
|
|
|
|
'links' => $links,
|
|
|
|
'new' => $comment->new ? t('new') : '',
|
|
|
|
'picture' => theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : '',
|
|
|
|
'submitted' => t('Submitted by %a on %b.',
|
2005-08-01 05:14:05 +00:00
|
|
|
array('%a' => theme('username', $comment),
|
2005-07-30 20:54:02 +00:00
|
|
|
'%b' => format_date($comment->timestamp))),
|
2005-07-30 17:13:48 +00:00
|
|
|
'title' => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid")
|
2005-05-04 18:12:18 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the values passed to the theme_block function to be passed
|
|
|
|
* into a pluggable template engine.
|
|
|
|
*/
|
|
|
|
function phptemplate_block($block) {
|
|
|
|
return _phptemplate_callback('block', array('block' => $block));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the values passed to the theme_box function to be passed
|
|
|
|
* into a pluggable template engine.
|
|
|
|
*/
|
|
|
|
function phptemplate_box($title, $content, $region = 'main') {
|
|
|
|
return _phptemplate_callback('box', array(
|
|
|
|
'content' => $content,
|
2005-07-30 17:13:48 +00:00
|
|
|
'region' => $region,
|
|
|
|
'title' => $title
|
2005-05-04 18:12:18 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default callback for PHPTemplate.
|
|
|
|
*
|
|
|
|
* Load a template file, and pass the variable array to it.
|
|
|
|
* If the suggested file is not found, PHPTemplate will attempt to use
|
|
|
|
* a $hook.tpl.php file in the template directory, and failing that a
|
|
|
|
* $hook.tpl.php in the PHPTemplate directory.
|
|
|
|
*
|
|
|
|
* @param $hook
|
|
|
|
* The name of the theme function being executed.
|
|
|
|
* @param $variables
|
|
|
|
* A sequential array of variables passed to the theme function.
|
|
|
|
* @param $file
|
|
|
|
* A suggested template file to use.
|
|
|
|
*/
|
|
|
|
function _phptemplate_default($hook, $variables, $file = null) {
|
|
|
|
if ($file && file_exists(path_to_theme() . "/$file.tpl.php")) {
|
|
|
|
$file = path_to_theme() . "/$file.tpl.php";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (file_exists(path_to_theme() . "/$hook.tpl.php")) {
|
|
|
|
$file = path_to_theme() . "/$hook.tpl.php";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (in_array($hook, array('node', 'block', 'box', 'comment'))) {
|
|
|
|
$file = "themes/engines/phptemplate/$hook.tpl.php";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$variables['hook'] = $hook;
|
|
|
|
watchdog('error', 'PHPTemplate was instructed to override the ' . $hook . ' theme function, but no valid template file was found.');
|
2005-07-17 19:52:10 +00:00
|
|
|
$file = 'themes/engines/phptemplate/default.tpl.php';
|
2005-05-04 18:12:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file) {
|
2005-07-30 17:13:48 +00:00
|
|
|
extract($variables); // Extract the vars to local namespace
|
2005-05-04 18:12:18 +00:00
|
|
|
ob_start(); // Start output buffering
|
|
|
|
include($file); // Include the file
|
|
|
|
$contents = ob_get_contents(); // Get the contents of the buffer
|
|
|
|
ob_end_clean(); // End buffering and discard
|
|
|
|
return $contents; // Return the contents
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|