1<?php
2/**
3 * pfctemplate.class.php
4 *
5 * Copyright � 2006 Stephane Gully <stephane.gully@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, 51 Franklin St, Fifth Floor,
20 * Boston, MA  02110-1301  USA
21 */
22
23require_once dirname(__FILE__)."/pfci18n.class.php";
24
25/**
26 * pfcTemplate is used to display chat templates (html and javascript)
27 * @author Stephane Gully <stephane.gully@gmail.com>
28 */
29class pfcTemplate
30{
31  var $tpl_filename;
32  var $vars;
33
34  function pfcTemplate($tpl_filename = "")
35  {
36    $this->tpl_filename = $tpl_filename;
37  }
38
39  function setTemplate($tpl_filename)
40  {
41    $this->tpl_filename = $tpl_filename;
42  }
43
44  function getOutput()
45  {
46    ob_start();
47    if (!file_exists($this->tpl_filename))
48      die(_pfc("%s template could not be found", $this->tpl_filename));
49    // assign defined vars to this template
50    foreach( $this->vars as $v_name => $v_val )
51      $$v_name = $v_val;
52    // execute the template
53    include($this->tpl_filename);
54    $result = ob_get_contents();
55    ob_end_clean();
56    return $result;
57  }
58
59  function assignObject(&$obj, $name = "c")
60  {
61    $vars = get_object_vars($obj);
62    foreach( $vars as $v_name => $v_val )
63      $this->vars[$v_name] = $v_val;
64    $this->vars[$name] =& $obj; // assigne also the whole object
65  }
66}
67
68?>