1<?php
2/**
3 * phpfreechat.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
23/**
24 * pfcResponse is used to build each ajax response
25 * Commands stack contains characteres strings with javascript instructions.
26 */
27class pfcResponse
28{
29  var $_commands = array();
30
31  function pfcResponse()
32  {
33  }
34
35  function remove($id)
36  {
37    $this->_commands[] = '$(\''.$id.'\').remove();';
38  }
39
40  function update($id,$data)
41  {
42    $data = preg_replace("/'/","\'",$data);
43    $data = preg_replace("/[\n\r]/","",$data);
44    $data = preg_replace("/\s*</"," <",$data);
45    $data = preg_replace("/>\s*/","> ",$data);
46    $this->_commands[] = '$(\''.$id.'\').update(\''.$data.'\');';
47  }
48
49  function script($js)
50  {
51    $this->_commands[] = $js;
52  }
53
54  function redirect($url)
55  {
56    $this->script('window.location = "'.$url.'";');
57  }
58
59  function getCommandCount()
60  {
61    return count($this->_commands);
62  }
63
64  function getOutput()
65  {
66    return implode("\n",$this->_commands);
67  }
68}
69?>