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

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

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

revision 1.9, Tue Feb 20 21:32:28 2007 UTC revision 1.10, Mon Aug 27 09:12:56 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: phptal.engine,v 1.8 2007/02/01 21:38:11 olav Exp $  // $Id$
3    
4  /**  /**
5   * @file   * @file
6   * Handles integration of templates written in PHPTAL   * Handles integration of templates written in PHPtal with the Drupal theme system.
  * with the Drupal theme system.  
7   */   */
8    
 // phptal implements allmost any of its magic through calls to phptemplate.engine  
 require_once('themes/engines/phptemplate/phptemplate.engine');  
   
9  function phptal_init($template) {  function phptal_init($template) {
10    return phptemplate_init($template);    $file = dirname($template->filename) . '/template.php';
11  }    if (file_exists($file)) {
12        include_once "./$file";
13  function phptal_templates($directory = 'themes') {    }
   return drupal_system_listing('^page\.tal$', $directory, 'filename');  
 }  
   
 function phptal_regions() {  
   return phptemplate_regions();  
 }  
   
 function _phptal_default($hook, $variables, $suggestions) {  
   return _phptemplate_default($hook, $variables, $suggestions, $extension = '.tal');  
 }  
   
 function phptal_features() {  
   return phptemplate_features();  
 }  
   
 function phptal_page($content, $show_blocks = TRUE) {  
   return phptemplate_page($content, $show_blocks);  
 }  
   
 function phptal_node($node, $teaser = 0, $page = 0) {  
   return phptemplate_node($node, $teaser, $page);  
 }  
   
 function phptal_comment($comment, $links = 0) {  
   return phptemplate_comment($comment, $links);  
14  }  }
15    
16  function phptal_block($block) {  /**
17    return phptemplate_block($block);   * 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  function phptal_box($title, $content, $region = 'main') {  /**
29    return phptemplate_box($title, $content, $region);   * 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  function _phptal_render($file, $variables) {  /**
56    global $theme_engine;   */
57    global $theme_key;  function phptal_render_template($template_file, $variables) {
58      global $theme_engine;
59    
60    require_once 'PHPTAL.php';    require_once 'PHPTAL.php';
61    
62    //D error_log("[TAL] engine=$theme_engine key=$theme_key file=$file");    $phptal = new PHPTAL($template_file);
   
   $phptal = new PHPTAL($file);  
63    foreach ($variables as $k=>$v) {    foreach ($variables as $k=>$v) {
64      $phptal->$k = $v;      $phptal->$k = $v;
65    }    }
66    
   ob_start();  
   var_dump($variables);  
   $debug_vars = ob_get_contents();  
   ob_end_clean();  
   $phptal->debug = $debug_vars;  
   
67    try {    try {
68      return html_entity_decode($phptal->execute());      return html_entity_decode($phptal->execute());
69    }    }
70    catch (Exception $e) {    catch (Exception $e) {
71      watchdog('error', t('%engine.engine, %file: %message.', array('%engine' => $theme_engine, '%file' => $file,      watchdog('error', '%engine.engine, %file: %message.', array(
72   '%message' => $e->getMessage())));        '%engine' => $theme_engine, '%file' => $template_file,
73      error_log("[phptal] $file: " . $e->getMessage());        '%message' => $e->getMessage()));
74        error_log("[phptal] $template_file: " . $e->getMessage());
75    }    }
76  }  }
77    
78    /**
79     */
80    function phptal_extension() {
81      return '.tal';
82    }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.2