drupal/themes/engines/phptemplate/phptemplate.engine

78 lines
2.1 KiB
Plaintext

<?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";
}
}
/**
* Implementation of hook_theme to tell Drupal what templates the engine
* and the current theme use. The $existing argument will contain hooks
* pre-defined by Drupal so that we can use that information if
* we need to.
*/
function phptemplate_theme($existing, $type, $theme, $path) {
$templates = array();
// Check for template overrides.
$files = drupal_system_listing('\.tpl\.php$', $path, 'name', 0);
foreach ($files as $template => $file) {
// chop off the .tpl
$template = substr($template, 0, -4);
if (isset($existing[$template])) {
$templates[$template] = array(
'file' => $template,
'path' => dirname($file->filename),
);
}
}
// Check for function overrides.
foreach ($existing as $hook => $info) {
if (function_exists($theme .'_'. $hook)) {
$templates[$hook] = array(
'function' => $theme .'_'. $hook,
);
}
else if (function_exists('phptemplate_'. $hook)) {
$templates[$hook] = array(
'function' => 'phptemplate_'. $hook,
);
}
}
return $templates;
}
/**
* Adds additional helper variables to all templates.
*
* Counts how many times certain hooks have been called. Sidebar left / right are special cases.
*
* @param $variables
* A series of key-value value pairs.
* @param $hook
* The name of the theme function being executed.
*/
function phptemplate_engine_preprocess(&$variables, $hook) {
static $count = array();
// Create variables so anything which is themed can be zebra striped automatically.
$count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
$variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
$variables['id'] = $count[$hook]++;
// Tell all templates where they are located.
$variables['directory'] = path_to_theme();
$variables['is_front'] = drupal_is_front_page();
}