/[webpac2]/trunk/web/iwf/php/iwf.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/web/iwf/php/iwf.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide annotations)
Mon Nov 14 16:13:17 2005 UTC (18 years, 6 months ago) by dpavlin
File size: 5755 byte(s)
 r8855@llin:  dpavlin | 2005-11-14 01:49:57 +0100
 added small browser using Interactive Website Framework
 from http://iwf.sourceforge.net

1 dpavlin 46 <?
2     class IWFAction {
3    
4     var $type;
5     var $target;
6     var $code;
7     var $msg;
8     var $content;
9     var $emitted;
10    
11     function IWFAction($type, $target, $content){
12     $this->type = $type;
13     $this->target = $target;
14     $this->emitted = false;
15     $this->content = $content;
16     }
17    
18     function error($code, $msg){
19     $this->code = $code;
20     $this->msg = $msg;
21     $this->content = '';
22     return $this;
23     }
24    
25     function _echoStart($prettyprint){
26     if ($prettyprint){
27     echo "\n\t";
28     }
29     echo "<action type='$this->type'";
30     if ($this->target){
31     echo " target='$this->target'";
32     }
33     if ($this->errorCode){
34     echo " errorCode='$this->code'";
35     }
36     if ($this->message){
37     echo " message='$this->message'";
38     }
39     echo '>';
40     if ($prettyprint){
41     echo "\n\t\t";
42     }
43     // once we echo any part of this object, we must not re-echo it,
44     // so mark this object as emitted.
45     $this->emitted = true;
46     return $this;
47     }
48    
49     function _echoEnd($prettyprint){
50     if ($prettyprint){
51     echo "\n\t";
52     }
53     echo "</action>";
54     return $this;
55     }
56    
57     function emit($echoEnd, $prettyprint){
58     if (!$this->emitted){
59     $this->_echoStart($prettyprint);
60     echo $this->content;
61     }
62     if ($echoEnd){
63     $this->_echoEnd($prettyprint);
64     }
65     return $this;
66     }
67     }
68    
69     class IWFController {
70    
71     var $actions;
72     var $currentAction;
73     var $currentlyEmitting;
74     var $startedEmitting;
75     var $debugging;
76     var $prettyprint;
77    
78     function IWFController(){
79     if ($iwf){
80     alert("Do not create new IWFController objects.\nThe singleton stored in $iwf should be used instead.");
81     return;
82     }
83     $this->actions = array();
84     $this->currentAction = null;
85     $this->currentlyEmitting = '';
86     $this->startedEmitting = false;
87     $this->debugging = false;
88     $this->prettyprint = false;
89     }
90    
91     function debug($on){
92     $this->debugging = $on;
93     if ($on){
94     $this->prettyprint = true;
95     }
96     }
97    
98     function pretty($on){
99     $this->prettyprint = $on;
100     }
101    
102     function startAction($type, $target){
103     // ensure we've emitted everything up until this point...
104     $this->_emit(false);
105     $this->currentAction = new IWFAction($type, $target, '');
106     $this->currentAction->emit(false, $this->prettyprint);
107     $this->currenltyEmitting = $type;
108     return $this->currentAction;
109     }
110    
111     function endAction(){
112     if ($this->currentAction){
113     $this->currentAction->emit(true, $this->prettyprint);
114     $this->currentlyEmitting = '';
115     $this->currentAction = null;
116     } else {
117     echo "called end action when no action was current!";
118     }
119     return null;
120     }
121    
122     function addHtml($html, $target){
123     $act = new IWFAction('html', $target, $html);
124     array_push($this->actions, $act);
125     return $act;
126     }
127    
128     function startHtml($target){
129     return $this->startAction('html', $target);
130     }
131    
132     function endHtml($close){
133     if ($this->currentlyEmitting != 'html'){
134     $this->error(-2163, 'iwf.endHtml() called, but iwf believes it should be emitting ' . $this->currentlyEmitting);
135     } else {
136     $this->endAction();
137     }
138    
139     if ($close){
140     $this->close();
141     }
142     }
143    
144     function error($code, $msg){
145     if ($this->currentAction){
146     $this->currentAction->error($code, $msg);
147     } else {
148     $this->addError($code, $msg);
149     }
150     }
151    
152     function endXml($finished){
153     if ($this->currentlyEmitting != 'html'){
154     $this->error(-2164, 'iwf.endXml() called, but iwf believes it should be emitting ' . $this->currentlyEmitting);
155     } else {
156     $this->endAction();
157     }
158     if (isset($finished) && $finished){
159     $this->close();
160     }
161     }
162    
163     function addJavascript($js){
164     $act = new IWFAction('javascript', '', "<![CDATA[ $js ]]>" );
165     array_push($this->actions, $act);
166     return $act;
167     }
168    
169     function popup($txt){
170     return $this->addJavascript("alert('Server-side IWF popup:\\n$txt')");
171     }
172    
173     function addXml($xml){
174     $act = new IWFAction('xml', '', $xml);
175     array_push($this->actions, $act);
176     return $act;
177     }
178    
179     function startXml(){
180     return $this->startAction('xml', '');
181     }
182    
183     function addError($code, $msg){
184     $act = new IWFAction('','','');
185     $act->error($code, $msg);
186     array_push($this->actions, $act);
187     return $act;
188     }
189    
190     function _emit($emitEnd){
191     if (!$this->startedEmitting){
192     echo "<response";
193     if ($this->debugging){
194     echo " debugging='true'";
195     }
196     if ($this->prettyprint){
197     echo " pretty='true'";
198     }
199     echo ">";
200     $this->startedEmitting = true;
201     }
202    
203     if ($this->currentAction){
204     $this->endAction();
205     }
206    
207     foreach($this->actions as $act){
208     $act->emit(true, $this->prettyprint);
209     }
210    
211     // empty the array, as we've emitted it and cannot go back anymore...
212     $this->actions = array();
213    
214     if ($emitEnd){
215     if ($this->prettyprint){
216     echo "\n";
217     }
218     echo "</response>";
219     }
220     }
221    
222    
223     function close(){
224     $this->_emit(true);
225     $this->debugging = false;
226     }
227    
228     }
229    
230     //function iwfXmlEncode($s){
231     // return str_replace('"', '&quot;', str_replace("'", "&apos;", str_replace('>', '&gt;', str_replace('<', '&lt;', str_replace('&', '&amp;', $s)))));
232     //}
233    
234     //function iwfXmlDecode($s){
235     // return str_replace('&quot;', '"', str_replace('&apos;', "'", str_replace('&gt;', '>', str_replace('&lt;', '<', str_replace('&amp;', '&', $s)))));
236     //}
237    
238     // create a singleton IWF object to use
239     $iwf = new IWFController();
240    
241     $iwfPretty = strtolower(@$_REQUEST['iwfPretty']) == 'true';
242     $iwf->pretty($iwfPretty);
243    
244     // debugging always sets prettyprint to true, so we must set debug last.
245     $iwfDebug = strtolower(@$_REQUEST['iwfDebug']) == 'true';
246     $iwf->debug($iwfDebug);
247    
248    
249    
250     // load the default vars...
251     $iwfMode = strtolower(@$_REQUEST['iwfMode']);
252     $iwfId = @$_REQUEST['iwfId'];
253    
254     $iwfTarget = @$_REQUEST['iwfTarget'];
255    
256     //if (!isset($iwfTarget)){
257     // $iwfTarget = 'iwfContent';
258     //}
259    
260     ?>

  ViewVC Help
Powered by ViewVC 1.1.26