quickfix for bug that caused
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL / OutputControl.php
blobce3c3403d629d0d1cf0f3982874ab8550288143f
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 //
4 // Copyright (c) 2003 Laurent Bedubourg
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
21 //
23 class PHPTAL_OutputControl
25 var $_buffer = "";
26 var $_buffers = array();
27 var $_quoteStyle = ENT_COMPAT;
28 var $_encoding = 'UTF-8';
29 var $_context;
31 function PHPTAL_OutputControl(&$context, $encoding='UTF-8')
33 $this->_context = $context;
34 $this->_encoding = $encoding;
37 function pushBuffer()
39 $this->_buffers[] = $this->_buffer;
40 $this->_buffer = "";
43 function popBuffer()
45 $res = $this->_buffer;
46 $this->_buffer = array_pop($this->_buffers);
47 return $res;
50 function write(&$str)
52 if (is_object($str)) {
53 if (PEAR::isError($str)) {
54 $str = "[". get_class($str) . ": " . $str->message . "]";
55 // $this->_context->cleanError();
56 } else {
57 $str = Types::toString($str);
61 if (defined("PHPTAL_DIRECT_OUTPUT") && count($this->_buffers) == 0) {
62 // echo htmlentities($str);
63 // support for cyrillic strings thanks to Igor E. Poteryaev
64 echo htmlentities($str, $this->_quoteStyle, $this->_encoding);
65 } else {
66 // $this->_buffer .= htmlentities($str);
67 // support for cyrillic strings thanks to Igor E. Poteryaev
68 $this->_buffer .= htmlentities($str, $this->_quoteStyle, $this->_encoding);
72 function writeStructure($str)
74 if (is_object($str)) {
75 if (PEAR::isError($str)) {
76 $str = "[" . $str->message . "]";
77 // $this->_context->cleanError();
78 } else {
79 $str = Types::toString($str);
83 if (defined("PHPTAL_DIRECT_OUTPUT") && count($this->_buffers) == 0) {
84 echo $str;
85 } else {
86 $this->_buffer .= $str;
90 function &toString()
92 return $this->_buffer;