00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class MediaView extends View {
00030
00031
00032
00033
00034
00035 var $mimeType = array('ai' => 'application/postscript', 'bcpio' => 'application/x-bcpio', 'bin' => 'application/octet-stream',
00036 'ccad' => 'application/clariscad', 'cdf' => 'application/x-netcdf', 'class' => 'application/octet-stream',
00037 'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'csh' => 'application/x-csh',
00038 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dms' => 'application/octet-stream',
00039 'doc' => 'application/msword', 'drw' => 'application/drafting', 'dvi' => 'application/x-dvi',
00040 'dwg' => 'application/acad', 'dxf' => 'application/dxf', 'dxr' => 'application/x-director',
00041 'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset',
00042 'flv' => 'video/x-flv', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'hdf' => 'application/x-hdf',
00043 'hqx' => 'application/mac-binhex40', 'ips' => 'application/x-ipscript', 'ipx' => 'application/x-ipix',
00044 'js' => 'application/x-javascript', 'latex' => 'application/x-latex', 'lha' => 'application/octet-stream',
00045 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream', 'man' => 'application/x-troff-man',
00046 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif', 'ms' => 'application/x-troff-ms',
00047 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf',
00048 'pgn' => 'application/x-chess-pgn', 'pot' => 'application/mspowerpoint', 'pps' => 'application/mspowerpoint',
00049 'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'pre' => 'application/x-freelance',
00050 'prt' => 'application/pro_eng', 'ps' => 'application/postscript', 'roff' => 'application/x-troff',
00051 'scm' => 'application/x-lotusscreencam', 'set' => 'application/set', 'sh' => 'application/x-sh',
00052 'shar' => 'application/x-shar', 'sit' => 'application/x-stuffit', 'skd' => 'application/x-koan',
00053 'skm' => 'application/x-koan', 'skp' => 'application/x-koan', 'skt' => 'application/x-koan',
00054 'smi' => 'application/smil', 'smil' => 'application/smil', 'sol' => 'application/solids',
00055 'spl' => 'application/x-futuresplash', 'src' => 'application/x-wais-source', 'step' => 'application/STEP',
00056 'stl' => 'application/SLA', 'stp' => 'application/STEP', 'sv4cpio' => 'application/x-sv4cpio',
00057 'sv4crc' => 'application/x-sv4crc', 'swf' => 'application/x-shockwave-flash', 't' => 'application/x-troff',
00058 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex',
00059 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tr' => 'application/x-troff',
00060 'tsp' => 'application/dsptype', 'unv' => 'application/i-deas', 'ustar' => 'application/x-ustar',
00061 'vcd' => 'application/x-cdlink', 'vda' => 'application/vda', 'xlc' => 'application/vnd.ms-excel',
00062 'xll' => 'application/vnd.ms-excel', 'xlm' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel',
00063 'xlw' => 'application/vnd.ms-excel', 'zip' => 'application/zip', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff',
00064 'aiff' => 'audio/x-aiff', 'au' => 'audio/basic', 'kar' => 'audio/midi', 'mid' => 'audio/midi',
00065 'midi' => 'audio/midi', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpga' => 'audio/mpeg',
00066 'ra' => 'audio/x-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio',
00067 'rpm' => 'audio/x-pn-realaudio-plugin', 'snd' => 'audio/basic', 'tsi' => 'audio/TSP-audio', 'wav' => 'audio/x-wav',
00068 'asc' => 'text/plain', 'c' => 'text/plain', 'cc' => 'text/plain', 'css' => 'text/css', 'etx' => 'text/x-setext',
00069 'f' => 'text/plain', 'f90' => 'text/plain', 'h' => 'text/plain', 'hh' => 'text/plain', 'htm' => 'text/html',
00070 'html' => 'text/html', 'm' => 'text/plain', 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', 'sgm' => 'text/sgml',
00071 'sgml' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'tpl' => 'text/template', 'txt' => 'text/plain',
00072 'xml' => 'text/xml', 'avi' => 'video/x-msvideo', 'fli' => 'video/x-fli', 'mov' => 'video/quicktime',
00073 'movie' => 'video/x-sgi-movie', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg',
00074 'qt' => 'video/quicktime', 'viv' => 'video/vnd.vivo', 'vivo' => 'video/vnd.vivo', 'gif' => 'image/gif',
00075 'ief' => 'image/ief', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg',
00076 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'png' => 'image/png',
00077 'pnm' => 'image/x-portable-anymap', 'ppm' => 'image/x-portable-pixmap', 'ras' => 'image/cmu-raster',
00078 'rgb' => 'image/x-rgb', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'xbm' => 'image/x-xbitmap',
00079 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'ice' => 'x-conference/x-cooltalk',
00080 'iges' => 'model/iges', 'igs' => 'model/iges', 'mesh' => 'model/mesh', 'msh' => 'model/mesh',
00081 'silo' => 'model/mesh', 'vrml' => 'model/vrml', 'wrl' => 'model/vrml',
00082 'mime' => 'www/mime', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-pdb');
00083
00084
00085
00086
00087
00088
00089 function __construct(&$controller) {
00090 parent::__construct($controller);
00091 }
00092
00093
00094
00095
00096
00097
00098 function render() {
00099 $name = null;
00100 $download = null;
00101 $extension = null;
00102 $id = null;
00103 $modified = null;
00104 $path = null;
00105 $size = null;
00106 extract($this->viewVars, EXTR_OVERWRITE);
00107
00108 if ($size) {
00109 $id = $id . "_$size";
00110 }
00111 $path = APP . $path . $id;
00112
00113 if (is_null($name)) {
00114 $name = $id;
00115 }
00116
00117 if (file_exists($path) && isset($extension) && array_key_exists($extension, $this->mimeType) && connection_status() == 0) {
00118 $chunkSize = 1 * (1024 * 8);
00119 $buffer = '';
00120 $fileSize = @filesize($path);
00121 $handle = fopen($path, 'rb');
00122
00123 if ($handle === false) {
00124 return false;
00125 }
00126 if (isset($modified) && !empty($modified)) {
00127 $modified = gmdate('D, d M Y H:i:s', strtotime($modified, time())) . ' GMT';
00128 } else {
00129 $modified = gmdate('D, d M Y H:i:s').' GMT';
00130 }
00131
00132 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
00133 header("Last-Modified: $modified");
00134
00135 if ($download) {
00136 $contentType = 'application/octet-stream';
00137 $agent = env('HTTP_USER_AGENT');
00138
00139 if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
00140 $contentType = 'application/octetstream';
00141 }
00142
00143 header('Content-Type: ' . $contentType);
00144 header("Content-Disposition: attachment; filename=\"" . $name . '.' . $extension . "\";");
00145 header("Expires: 0");
00146 header('Accept-Ranges: bytes');
00147 header("Cache-Control: private", false);
00148 header("Pragma: private");
00149
00150 $httpRange = env('HTTP_RANGE');
00151
00152 if (isset($httpRange)) {
00153 list ($toss, $range) = explode("=", $httpRange);
00154 str_replace($range, "-", $range);
00155
00156 $size = $fileSize - 1;
00157 $length = $fileSize - $range;
00158
00159 header("HTTP/1.1 206 Partial Content");
00160 header("Content-Length: $length");
00161 header("Content-Range: bytes $range$size/$fileSize");
00162 fseek($handle, $range);
00163 } else {
00164 header("Content-Length: " . $fileSize);
00165 }
00166 } else {
00167 header("Content-Type: " . $this->mimeType[$extension]);
00168 header("Content-Length: " . $fileSize);
00169 }
00170 @ob_end_clean();
00171
00172 while (!feof($handle) && connection_status() == 0) {
00173 set_time_limit(0);
00174 $buffer = fread($handle, $chunkSize);
00175 echo $buffer;
00176 @flush();
00177 @ob_flush();
00178 }
00179 fclose($handle);
00180 return((connection_status() == 0) && !connection_aborted());
00181 }
00182 return false;
00183 }
00184 }
00185 ?>