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
00030
00031
00032
00033
00034 class MimeView extends ContentViewBase {
00035 const MIMETYPE = 'mimetype';
00036 const EXPIRES = 'expires';
00037
00038
00039
00040
00041 public function __construct($template, $page_data) {
00042 parent::__construct($template, $page_data);
00043 $page_data->page_template = 'emptypage';
00044 $this->assign(self::MIMETYPE, 'application/octet-stream');
00045 $this->assign(self::EXPIRES, 0);
00046 }
00047
00048
00049
00050
00051
00052
00053 protected function should_cache() {
00054 return false;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 protected function render_postprocess(&$rendered_content, $policy) {
00065 parent::render_postprocess($rendered_content, $policy);
00066
00067 if (!Common::flag_is_set($policy, self::CONTENT_ONLY)) {
00068 $mimetype = $this->retrieve(self::MIMETYPE);
00069
00070
00071
00072
00073
00074
00075 if (strpos($mimetype, 'charset') === false) {
00076 $mimetype .= '; charset=' . GyroLocale::get_charset();
00077 }
00078 GyroHeaders::set('Content-Type', $mimetype, true);
00079
00080
00081 $ex = $this->retrieve(self::EXPIRES);
00082 if ($ex) {
00083 if ($ex < 10 * GyroDate::ONE_YEAR) {
00084
00085 $ex = time() + $ex;
00086 }
00087 $this->page_data->get_cache_manager()->set_expiration_datetime($ex);
00088 }
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097 public function display_file($file) {
00098 if (file_exists($file)) {
00099 $modification = filemtime($file);
00100 if ($modification) {
00101 $this->page_data->get_cache_manager()->set_creation_datetime($modification);
00102 }
00103
00104
00105 $mime_type = 'application/octect-stream';
00106 if (function_exists('finfo_open')) {
00107 $handle = finfo_open(FILEINFO_MIME);
00108 $mime_type = finfo_file($handle, $file);
00109 finfo_close($handle);
00110 }
00111 else if (function_exists('mime_content_type')) {
00112 $mime_type = mime_content_type($file);
00113 }
00114 else {
00115 $path_info = pathinfo($file);
00116 $path_ext = $path_info['extension'];
00117
00118 $types = array(
00119 'gif' => 'image/gif',
00120 'png' => 'image/png',
00121 'jpg' => 'image/jpeg',
00122 );
00123 foreach($types as $extension => $type) {
00124 if ($path_ext === $extension) {
00125 $mime_type = $type;
00126 break;
00127 }
00128 }
00129 }
00130 $this->assign(self::MIMETYPE, $mime_type);
00131
00132 $this->assign('data', file_get_contents($file));
00133 }
00134 }
00135 }