forked from pointybeard-archives/content_type_mappings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.driver.php
67 lines (52 loc) · 1.79 KB
/
extension.driver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
Final Class extension_Content_Type_Mappings extends Extension{
public function about(){
return array('name' => 'Content Type Mappings',
'version' => '1.0',
'release-date' => '2009-04-30',
'author' => array('name' => 'Symphony Team',
'website' => 'http://www.symphony21.com',
'email' => '[email protected]')
);
}
public function install(){
$initial_mappings = array(
'xml' => 'text/xml; charset=utf-8',
'text' => 'text/plain; charset=utf-8'
);
foreach($initial_mappings as $type => $content_type){
$this->_Parent->Configuration->set($type, $content_type, 'content-type-mappings');
}
$this->_Parent->saveConfig();
}
public function uninstall(){
$this->_Parent->Configuration->remove('content-type-mappings');
$this->_Parent->saveConfig();
}
public function resolveType($type){
return $this->_Parent->Configuration->get(strtolower($type), 'content-type-mappings');
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/frontend/',
'delegate' => 'FrontendOutputPostGenerate',
'callback' => 'setContentType'
),
);
}
public function setContentType(array $context=NULL){
$page_data = Frontend::Page()->pageData();
if(!isset($page_data['type']) || !is_array($page_data['type']) || empty($page_data['type'])) return;
foreach($page_data['type'] as $type){
$content_type = $this->resolveType($type);
if(!is_null($content_type)){
header('Content-Type:' . $content_type, true);
}
if(substr($type, 0, 1) == "." ){
$FileName = $page_data['handle'];
header('Content-Disposition: attachment; filename=' . $FileName . $type);
}
}
}
}