rm trailing white space
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL / OutputControl.php
blobcb118f92e155085e1d47ee8cea3fb36a297b6472
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 // **** hacked to htmlspecialchars() to avoid messing with text.
69 // **** PHP prior to 4.3.7 contains bugs that mess up Greek.
70 // **** removed encoding parameter, this messed up titles in older versions of php
71 // **** we deal with encoding in Language.php
72 $this->_buffer .= htmlspecialchars($str, $this->_quoteStyle);
76 function writeStructure($str)
78 if (is_object($str)) {
79 if (PEAR::isError($str)) {
80 $str = "[" . $str->message . "]";
81 // $this->_context->cleanError();
82 } else {
83 $str = Types::toString($str);
87 if (defined("PHPTAL_DIRECT_OUTPUT") && count($this->_buffers) == 0) {
88 echo $str;
89 } else {
90 $this->_buffer .= $str;
94 function &toString()
96 return $this->_buffer;