summaryrefslogtreecommitdiff
path: root/themes/engines/phptemplate/phptemplate.engine
blob: 4e9c065afbaddae80385ed12fee1707e331c461f (plain)
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
<?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();
}