Overview

Packages

  • Onion::Controllers
  • Onion::Core
  • Onion::UI
  • Onion::Utils

Classes

  • Arrays
  • Assets
  • Filesystem
  • Image
  • Languages
  • Mail
  • Secure
  • Strings
  • SWF
  • Utils
  • Validate
  • Visitor
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Onion Framework - Práca so súbormi SWF (Adobe Flash)
  5:  *
  6:  * Copyright (c) 2011 Jano Gašpar (http://webstranky.net)
  7:  *
  8:  * @author    Jano Gašpar
  9:  * @copyright Copyright (c) 2011 Jano Gašpar
 10:  * @package   Onion::Utils
 11:  **/
 12: class SWF {
 13:     var $filename = NULL;       // SWF file analyzed
 14:     var $magic = NULL;          // Magic in a SWF file (FWS or CWS)
 15:     var $compressed = FALSE;    // Flag to indicate a compressed file (CWS)
 16:     var $version = 0;           // Flash version
 17:     var $size = 0;              // Uncompressed file size (in bytes)
 18:     var $width = 0;             // Flash movie native width
 19:     var $height = 0;            // Flash movie native height
 20:     var $valid = FALSE;         // Valid SWF file
 21:     var $fps = array();         // Flash movie native frame-rate
 22:     var $frames = 0;            // Flash movie total frames
 23: 
 24:     public function __construct($filename) {
 25:         $this->filename = $filename;
 26:         if (FALSE === $fp = @fopen($filename, 'rb')) {
 27:             return FALSE;
 28:         }
 29: 
 30:         // Read MAGIC FIELD
 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:             // Compression
 39:             if (substr($this->magic, 0, 1) == 'C') {
 40:                 $this->compressed = TRUE;
 41: 
 42:             } else {
 43:                 $this->compressed = FALSE;
 44:             }
 45: 
 46:             // Version
 47:             $this->version = ord(fread($fp, 1));
 48: 
 49:             // Size
 50:             $lg = 0;
 51:             // 4 LSB-MSB
 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:             // RECT... we will 'simulate' a stream from now on... read remaining file
 59:             $buffer = fread($fp,$this->size);
 60:             if ($this->compressed) {
 61:                 // First decompress GZ stream
 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:             // Current byte
 71:             $cbyte &= 7;
 72:             $cbyte <<= 5;
 73: 
 74:             // Current bit (first byte starts off already shifted)
 75:             $cbit   = 2;
 76: 
 77:             // Must get all 4 values in the RECT
 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:                     // We will be needing a new byte if we run out of bits
 94:                     if ($cbit<0) {
 95:                         $cbyte  = ord(substr($buffer,0,1));
 96:                         $buffer = substr($buffer,1);
 97:                         $cbit = 7;
 98:                     }
 99:                 }
100: 
101:                 // O.k. full value stored... calculate
102:                 $c = 1;
103:                 $val = 0;
104: 
105:                 // Reverse string to allow for SUM(2^n*$atom)
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:                     // 2^n
113:                     $c *= 2;
114:                 }
115: 
116:                 // TWIPS to PIXELS
117:                 $val /= 20;
118:                 switch ($vals) {
119:                     case 0:
120:                         // tmp value
121:                         $this->width = $val;
122:                         break;
123: 
124:                     case 1:
125:                         $this->width = $val - $this->width;
126:                         break;
127: 
128:                     case 2:
129:                         // tmp value
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:             // Frame rate
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:             // Frames
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: 
Onion API documentation generated by ApiGen.
Generated using the TokenReflection library.