/
Component.php
105 lines (91 loc) · 3.21 KB
/
Component.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
class Kwc_Basic_DownloadTag_Component extends Kwc_Basic_LinkTag_Abstract_Component
implements Kwf_Media_Output_IsValidInterface, Kwf_Media_Output_ClearCacheInterface
{
public static function getSettings($param = null)
{
$ret = array_merge(parent::getSettings($param), array(
'ownModel' => 'Kwc_Basic_DownloadTag_Model',
'componentName' => trlKwfStatic('Download'),
'componentIcon' => 'folder_link',
'hasPopup' => true,
'openType' => null, //wenn hasPopup auf false
));
$ret['dataClass'] = 'Kwc_Basic_DownloadTag_Data';
$ret['assetsAdmin']['dep'][] = 'KwfFormFile';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Basic/DownloadTag/Panel.js';
$ret['apiContent'] = 'Kwc_Basic_DownloadTag_ApiContent';
$ret['apiContentType'] = 'download';
$ret['throwHasContentChangedOnRowColumnsUpdate'] = 'kwf_upload_id';
return $ret;
}
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$row = $this->_getRow();
$filename = $row->filename != '' ? $row->filename : 'unnamed';
$ret['filesize'] = $this->getFilesize();
$ret['url'] = $this->getDownloadUrl();
$ret['filename'] = $filename;
return $ret;
}
public function hasContent()
{
$row = $this->getFileRow();
if ($row && $row->kwf_upload_id) {
return true;
}
return false;
}
public function getDownloadUrl()
{
return $this->getData()->url;
}
public function getFilesize()
{
$fRow = $this->getFileRow()->getParentRow('File');
if (!$fRow) return null;
return $fRow->getFileSize();
}
public function getFileRow()
{
return $this->_getRow();
}
public static function isValidMediaOutput($id, $type, $className)
{
return Kwf_Media_Output_Component::isValid($id);
}
public static function getMediaOutput($id, $type, $className)
{
$c = Kwf_Component_Data_Root::getInstance()->getComponentById($id, array('ignoreVisible'=>true));
if (!$c) return null;
$row = $c->getComponent()->getRow();
$fileRow = $row->getParentRow('File');
if (!$fileRow) {
return null;
} else {
$file = $fileRow->getFileSource();
$mimeType = $fileRow->mime_type;
}
if (!$file || !file_exists($file)) {
return null;
}
$filename = $row->filename != '' ? $row->filename : 'unnamed';
$filename .= '.'.$fileRow->extension;
$ret = array(
'file' => $file,
'mimeType' => $mimeType,
'noindex' => !!$row->rel_noindex
);
if ($row->content_disposition === 'attachment') {
$ret['downloadFilename'] = $filename;
} else if ($row->content_disposition === 'inline') {
$ret['filename'] = $filename;
}
return $ret;
}
public static function canCacheBeDeleted($id)
{
return !Kwf_Component_Data_Root::getInstance()->getComponentById($id, array('ignoreVisible' => true));
}
}