MimeView Class Reference
[Mime]
A content view of any mime type, not only text/html. More...
Public Member Functions |
|
__construct ($template, $page_data) | |
Contructor takes a name and the page data.
|
|
display_file ($file) | |
Send given File to the browser. |
|
Public Attributes |
|
const | EXPIRES = 'expires' |
const | MIMETYPE = 'mimetype' |
Protected Member Functions |
|
render_postprocess (&$rendered_content, $policy) | |
Called after content is rendered, always.
|
|
should_cache () | |
Always returns false. |
Detailed Description
A content view of any mime type, not only text/html.
Assign 'data' and MimeView::MIMETYPE to the created view like this:
$imagedata = file_get_contents('my/image.png'); $view = ViewFactory::create_view(ViewFactoryMime::MIME, 'mime/view', $page_data); $view->assign('data', $imagedata); $view->assign(MimeView::MIMETYPE, 'image/png'); $view->render();
For convenience, the same can be achieved using display_file():
$view = ViewFactory::create_view(ViewFactoryMime::MIME, 'mime/view', $page_data); $view->display_file('my/image.png'); $view->render();
Mime views are normally cached, like any other content. When using a mime view, the according route therefor should disable server side caching, but enable it at client side. The simplest way to fullfill this is to use the MimeCacheManager.
Not caching on client side may lead to trouble in IE 6 when downloading data with SSL encryption.
Definition at line 34 of file mimeview.cls.php.
Constructor & Destructor Documentation
MimeView::__construct | ( | $ | template, | |
$ | page_data | |||
) |
Contructor takes a name and the page data.
Reimplemented from ContentViewBase.
Definition at line 41 of file mimeview.cls.php.
00041 { 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 }
Member Function Documentation
MimeView::display_file | ( | $ | file | ) |
Send given File to the browser.
- Parameters:
-
string $file Path to file
Definition at line 97 of file mimeview.cls.php.
00097 { 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 // Detect mime type 00105 $mime_type = 'application/octect-stream'; 00106 if (function_exists('finfo_open')) { 00107 $handle = finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension 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 // No MAGIC functions enabled, do a primitiv lookup based upon file ending 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 }
MimeView::render_postprocess | ( | &$ | rendered_content, | |
$ | policy | |||
) | [protected] |
Called after content is rendered, always.
- Parameters:
-
mixed $rendered_content The content rendered $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Reimplemented from ViewBase.
Definition at line 64 of file mimeview.cls.php.
00064 { 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 // GR: Disabled, since this is too generic. Left to app to handle 00071 //if (RequestInfo::current()->is_ssl()) { 00072 // Common::header('Cache-Control', 'maxage=3600', true); //Fix for IE in SSL 00073 //} 00074 00075 if (strpos($mimetype, 'charset') === false) { 00076 $mimetype .= '; charset=' . GyroLocale::get_charset(); 00077 } 00078 GyroHeaders::set('Content-Type', $mimetype, true); 00079 00080 // Expires Header 00081 $ex = $this->retrieve(self::EXPIRES); 00082 if ($ex) { 00083 if ($ex < 10 * GyroDate::ONE_YEAR) { 00084 // $ex is a duration 00085 $ex = time() + $ex; 00086 } 00087 $this->page_data->get_cache_manager()->set_expiration_datetime($ex); 00088 } 00089 } 00090 }
MimeView::should_cache | ( | ) | [protected] |
Always returns false.
- Returns:
- bool
Reimplemented from ViewBase.
Definition at line 53 of file mimeview.cls.php.
Member Data Documentation
const MimeView::EXPIRES = 'expires' |
Definition at line 36 of file mimeview.cls.php.
const MimeView::MIMETYPE = 'mimetype' |
Definition at line 35 of file mimeview.cls.php.
The documentation for this class was generated from the following file:
- gyro/modules/mime/view/base/mimeview.cls.php