1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class SWF {
13: var $filename = NULL;
14: var $magic = NULL;
15: var $compressed = FALSE;
16: var $version = 0;
17: var $size = 0;
18: var $width = 0;
19: var $height = 0;
20: var $valid = FALSE;
21: var $fps = array();
22: var $frames = 0;
23:
24: public function __construct($filename) {
25: $this->filename = $filename;
26: if (FALSE === $fp = @fopen($filename, 'rb')) {
27: return FALSE;
28: }
29:
30:
31: $this->magic = fread($fp, 3);
32: if ($this->magic <> 'FWS'
33: AND $this->magic <> 'CWS') {
34:
35: $this->valid = FALSE;
36:
37: } else {
38:
39: if (substr($this->magic, 0, 1) == 'C') {
40: $this->compressed = TRUE;
41:
42: } else {
43: $this->compressed = FALSE;
44: }
45:
46:
47: $this->version = ord(fread($fp, 1));
48:
49:
50: $lg = 0;
51:
52: for ($i=0;$i<4;$i++) {
53: $t = ord(fread($fp, 1));
54: $lg += ($t<<(8*$i));
55: }
56: $this->size = $lg;
57:
58:
59: $buffer = fread($fp,$this->size);
60: if ($this->compressed) {
61:
62: $buffer = gzuncompress($buffer,$this->size);
63: }
64: $b = ord(substr($buffer,0,1));
65: $buffer = substr($buffer,1);
66: $cbyte = $b;
67: $bits = $b>>3;
68:
69: $cval = '';
70:
71: $cbyte &= 7;
72: $cbyte <<= 5;
73:
74:
75: $cbit = 2;
76:
77:
78: for ($vals = 0; $vals < 4; $vals++) {
79: $bitcount = 0;
80: while ($bitcount < $bits) {
81: if ($cbyte & 128) {
82: $cval .= '1';
83:
84: } else {
85: $cval .= '0';
86: }
87:
88: $cbyte <<= 1;
89: $cbyte &= 255;
90: $cbit--;
91: $bitcount++;
92:
93:
94: if ($cbit<0) {
95: $cbyte = ord(substr($buffer,0,1));
96: $buffer = substr($buffer,1);
97: $cbit = 7;
98: }
99: }
100:
101:
102: $c = 1;
103: $val = 0;
104:
105:
106: $tval = strrev($cval);
107: for ($n=0; $n < strlen($tval); $n++) {
108: $atom = substr($tval,$n,1);
109: if ($atom == '1') {
110: $val += $c;
111: }
112:
113: $c *= 2;
114: }
115:
116:
117: $val /= 20;
118: switch ($vals) {
119: case 0:
120:
121: $this->width = $val;
122: break;
123:
124: case 1:
125: $this->width = $val - $this->width;
126: break;
127:
128: case 2:
129:
130: $this->height = $val;
131: break;
132:
133: case 3:
134: $this->height = $val - $this->height;
135: break;
136: }
137:
138: $cval = '';
139: }
140:
141:
142: $this->fps = Array();
143: for ($i = 0; $i < 2; $i++) {
144: $t = ord(substr($buffer, 0, 1));
145: $buffer = substr($buffer, 1);
146: $this->fps[] = $t;
147: }
148:
149:
150: $this->frames = 0;
151: for ($i=0; $i < 2; $i++) {
152: $t = ord(substr($buffer,0,1));
153: $buffer = substr($buffer,1);
154: $this->frames += ($t<<(8*$i));
155: }
156:
157: fclose($fp);
158: $this->valid = 1;
159: }
160:
161: return $this->valid;
162: }
163:
164: function html($url = '', $width = NULL, $height = NULL) {
165: if ($this->valid == FALSE) {
166: return FALSE;
167: }
168:
169: if ($width === NULL) {
170: $width = $this->width;
171: }
172:
173: if ($height === NULL) {
174: $height = $this->height;
175: }
176:
177: if (empty($url) == FALSE) {
178: $url = trim($url, '/').'/';
179: }
180: $url .= $this->filename;
181:
182: $eol = chr(10);
183:
184: $html = '<!--[if !IE]> -->'.$eol;
185: $html .= '<object type="application/x-shockwave-flash"'.$eol;
186: $html .= 'data="'.$url.'" width="'.$width.'" height="'.$height.'">'.$eol;
187: $html .= '<!-- <![endif]-->'.$eol.$eol;
188:
189: $html .= '<!--[if IE]>'.$eol;
190: $html .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.$eol;
191: $html .= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"'.$eol;
192: $html .= 'width="'.$width.'" height="'.$height.'">'.$eol;
193: $html .= '<param name="movie" value="'.$url.'" />'.$eol;
194: $html .= '<!--><!--###-->'.$eol;
195: $html .= '<param name="loop" value="true" />'.$eol;
196: $html .= '<param name="menu" value="false" />'.$eol.$eol;
197:
198: $html .= '<p>This is <b>alternative</b> content.</p>'.$eol;
199: $html .= '</object>'.$eol;
200: $html .= '<!-- <![endif]-->'.$eol.$eol;
201:
202: return $html;
203: }
204: }
205: