/[drupal]/contributions/theme-engines/phptal/phptal.engine
ViewVC logotype

Contents of /contributions/theme-engines/phptal/phptal.engine

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Mon Aug 27 09:12:56 2007 UTC (2 years, 3 months ago) by olav
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.9: +56 -54 lines
File MIME type: text/x-php
First port to 6.x
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Handles integration of templates written in PHPtal with the Drupal theme system.
7 */
8
9 function phptal_init($template) {
10 $file = dirname($template->filename) . '/template.php';
11 if (file_exists($file)) {
12 include_once "./$file";
13 }
14 }
15
16 /**
17 * Implementation of hook_theme to tell Drupal what templates the engine
18 * and the current theme use. The $existing argument will contain hooks
19 * pre-defined by Drupal so that we can use that information if
20 * we need to.
21 */
22 function phptal_theme($existing, $type, $theme, $path) {
23 $templates = drupal_find_theme_functions($existing, array('phptal', $theme));
24 $templates += drupal_find_theme_templates($existing, '.tal', $path);
25 return $templates;
26 }
27
28 /**
29 * Adds additional helper variables to all templates.
30 *
31 * Counts how many times certain hooks have been called. Sidebar left / right are special cases.
32 *
33 * @param $variables
34 * A series of key-value value pairs.
35 * @param $hook
36 * The name of the theme function being executed.
37 */
38 function phptal_engine_preprocess(&$variables, $hook) {
39 global $user;
40 static $count = array();
41
42 // Create variables so anything which is themed can be zebra striped automatically.
43 $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
44 $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
45 $variables['id'] = $count[$hook]++;
46
47 // Tell all templates where they are located.
48 $variables['directory'] = path_to_theme();
49 $variables['is_front'] = drupal_is_front_page();
50 // Tell all templates by which kind of user they're viewed.
51 $variables['logged_in'] = ($user->uid > 0);
52 $variables['is_admin'] = user_access('access administration pages');
53 }
54
55 /**
56 */
57 function phptal_render_template($template_file, $variables) {
58 global $theme_engine;
59
60 require_once 'PHPTAL.php';
61
62 $phptal = new PHPTAL($template_file);
63 foreach ($variables as $k=>$v) {
64 $phptal->$k = $v;
65 }
66
67 try {
68 return html_entity_decode($phptal->execute());
69 }
70 catch (Exception $e) {
71 watchdog('error', '%engine.engine, %file: %message.', array(
72 '%engine' => $theme_engine, '%file' => $template_file,
73 '%message' => $e->getMessage()));
74 error_log("[phptal] $template_file: " . $e->getMessage());
75 }
76 }
77
78 /**
79 */
80 function phptal_extension() {
81 return '.tal';
82 }

  ViewVC Help
Powered by ViewVC 1.1.2