3 * sac-a-push - Obj/transports.phh
5 * Copyright (C) 2012 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
27 * Values: Y: works, N: not works, @: continuous download,
28 * D: continuous download after first reload
32 * Iframe| IW | FF | Ch | Op | Ko | IE
33 * ------+----+----+----+----+----+----
34 * Lnx | D | | @ | | @ | x
35 * Win | x | D | @ | @ | | D
39 * XHR | IW | FF | Ch | Op | Ko | IE
40 * ------+----+----+----+----+----+----
41 * Lnx | Y | | ^D | | Y | x
42 * Win | x | Y | Y | | | N
46 * HtmlFl| IW | FF | Ch | Op | Ko | IE
47 * ------+----+----+----+----+----+----
49 * Win | x | N | N | | | Y* (* seems delay between click and load of a new page)
56 class Transport_template {
58 function Transport_template() {
61 function init($enc, &$header_out, $init_string, $base, $step)
65 static function fini($init_string, $base, $blockerr)
69 function chunk($step, $cont)
76 function Transport_xhr() {
79 function init($enc, &$header_out, $init_string, $base, $step)
81 $ret = sprintf("@BEGIN@ /* %s */ @END@", $init_string);
83 $header_out['Content-Encoding'] = $enc;
84 $header_out['Cache-Control'] = 'no-cache, must-revalidate'; // HTTP/1.1
85 $header_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // Date in the past
86 $header_out['Content-type'] = 'application/xml; charset="utf-8"';
91 static function fini($init_string, $base, $blockerr)
96 function chunk($step, $cont)
98 return ("@BEGIN@".$cont."@END@");
102 class Transport_iframe {
104 function Transport_iframe() {
107 function init($enc, &$header_out, $init_string, $base, $step)
112 $header_out['Content-Encoding'] = $enc;
113 $header_out['Cache-Control'] = 'no-cache, must-revalidate'; // HTTP/1.1
114 $header_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // Date in the past
115 $header_out['Content-type'] = 'text/html; charset="utf-8"';
117 $ret .= sprintf("<html>
119 <script type=\"text/javascript\" src=\"%scommons.js\"></script>
120 <script type=\"text/javascript\" src=\"%sxynt-streaming-ifra.js\"></script>
121 <script type=\"text/javascript\">
122 var xynt_streaming = \"ready\";", $base, $base);
124 $ret .= sprintf("last_clean = %d;\n", ($step-1));
126 window.onload = function () { try { if (xynt_streaming != \"ready\") { xynt_streaming.transp.stopped = true; } } catch(e) { /* console.log(\"catcha\"); */ } };
130 $ret .= sprintf("<!-- \n%s -->\n", $init_string);
135 static function fini($init_string, $base, $blockerr)
138 $ret .= sprintf("<html>
140 <script type=\"text/javascript\" src=\"%scommons.js\"></script>
141 <script type=\"text/javascript\" src=\"%sxynt-streaming-ifra.js\"></script>
142 <script type=\"text/javascript\">
143 var xynt_streaming = \"ready\";", $base, $base);
145 window.onload = function () { try { if (xynt_streaming != \"ready\") { xynt_streaming.reload(); } } catch(e) { /* console.log(\"catcha\"); */ } };
149 $ret .= sprintf("<!-- \n%s -->\n", $init_string);
150 $ret .= sprintf("<script id='hs%d' type='text/javascript'><!--
153 </script>", 0, escpush($blockerr) );
157 function chunk($step, $cont)
160 return sprintf("<script id='hs%d' type='text/javascript'><!--
161 push(null);\n// -->\n</script>", $step);
164 return sprintf("<script id='hs%d' type='text/javascript'><!--
165 push(\"%s\");\n// -->\n</script>", $step, escpush($cont) );
170 class Transport_htmlfile extends Transport_iframe {
178 static function create($transp)
180 if ($transp == 'xhr') {
181 return new Transport_xhr();
183 else if ($transp == 'htmlfile') {
184 return new Transport_htmlfile();
187 return new Transport_iframe();