| 1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 16768 |
efrain |
7 |
|
| 1 |
www |
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\Mvc\I18n\Translator;
|
|
|
11 |
|
|
|
12 |
use Laminas\Authentication\AuthenticationService;
|
|
|
13 |
use LeadersLinked\Library\Functions;
|
|
|
14 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
15 |
use LeadersLinked\Mapper\UserProfileMapper;
|
|
|
16 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
17 |
use LeadersLinked\Mapper\GroupMapper;
|
|
|
18 |
use LeadersLinked\Mapper\JobMapper;
|
|
|
19 |
use LeadersLinked\Mapper\ChatUserMapper;
|
|
|
20 |
use LeadersLinked\Mapper\ChatGroupMapper;
|
|
|
21 |
|
|
|
22 |
class StorageController extends AbstractActionController
|
|
|
23 |
{
|
|
|
24 |
/**
|
|
|
25 |
*
|
| 16769 |
efrain |
26 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
| 1 |
www |
27 |
*/
|
|
|
28 |
private $adapter;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
*
|
| 16769 |
efrain |
32 |
* @var \LeadersLinked\Cache\CacheInterface
|
| 1 |
www |
33 |
*/
|
| 16769 |
efrain |
34 |
private $cache;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var \Laminas\Log\LoggerInterface
|
|
|
40 |
*/
|
| 1 |
www |
41 |
private $logger;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
*/
|
|
|
47 |
private $config;
|
|
|
48 |
|
| 16769 |
efrain |
49 |
|
| 1 |
www |
50 |
/**
|
|
|
51 |
*
|
| 16769 |
efrain |
52 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
53 |
*/
|
|
|
54 |
private $translator;
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
60 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
61 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
| 1 |
www |
62 |
* @param array $config
|
| 16769 |
efrain |
63 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
| 1 |
www |
64 |
*/
|
| 16769 |
efrain |
65 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
| 1 |
www |
66 |
{
|
| 16769 |
efrain |
67 |
$this->adapter = $adapter;
|
|
|
68 |
$this->cache = $cache;
|
|
|
69 |
$this->logger = $logger;
|
|
|
70 |
$this->config = $config;
|
|
|
71 |
$this->translator = $translator;
|
| 1 |
www |
72 |
}
|
|
|
73 |
|
|
|
74 |
public function downloadAction()
|
|
|
75 |
{
|
|
|
76 |
|
|
|
77 |
|
| 8544 |
efrain |
78 |
|
| 1 |
www |
79 |
// Get the file name from GET variable.
|
|
|
80 |
$code = $this->params()->fromRoute('code', '');
|
| 8537 |
efrain |
81 |
$code2 = $this->params()->fromRoute('code2', '');
|
| 1 |
www |
82 |
$fileName = $this->params()->fromRoute('filename', '');
|
|
|
83 |
$type = $this->params()->fromRoute('type', 'user');
|
|
|
84 |
|
|
|
85 |
|
| 8551 |
efrain |
86 |
|
| 1 |
www |
87 |
|
|
|
88 |
$no_image = $this->config['leaderslinked.images_default.no_image'];
|
|
|
89 |
$path = '';
|
|
|
90 |
switch($type)
|
|
|
91 |
{
|
|
|
92 |
case 'user' :
|
|
|
93 |
$no_image = $this->config['leaderslinked.images_default.user_image'];
|
|
|
94 |
$path = $this->config['leaderslinked.fullpath.user'];
|
|
|
95 |
break;
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
case 'user-profile' :
|
|
|
99 |
$no_image = $this->config['leaderslinked.images_default.user_profile'];
|
|
|
100 |
$path = $this->config['leaderslinked.fullpath.user'];
|
|
|
101 |
break;
|
|
|
102 |
|
|
|
103 |
case 'user-cover' :
|
|
|
104 |
$no_image = $this->config['leaderslinked.images_default.user_cover'];
|
|
|
105 |
$path = $this->config['leaderslinked.fullpath.user'];
|
|
|
106 |
break;
|
|
|
107 |
|
|
|
108 |
case 'company' :
|
|
|
109 |
$no_image = $this->config['leaderslinked.images_default.company_profile'];
|
|
|
110 |
$path = $this->config['leaderslinked.fullpath.company'];
|
|
|
111 |
break;
|
|
|
112 |
|
|
|
113 |
case 'company-cover' :
|
|
|
114 |
$no_image = $this->config['leaderslinked.images_default.company_cover'];
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
$path = $this->config['leaderslinked.fullpath.company'];
|
|
|
118 |
break;
|
|
|
119 |
|
|
|
120 |
case 'group' :
|
|
|
121 |
$no_image = $this->config['leaderslinked.images_default.group_profile'];
|
|
|
122 |
$path = $this->config['leaderslinked.fullpath.group'];
|
|
|
123 |
break;
|
|
|
124 |
|
|
|
125 |
case 'group-cover' :
|
|
|
126 |
$no_image = $this->config['leaderslinked.images_default.group_cover'];
|
|
|
127 |
$path = $this->config['leaderslinked.fullpath.group'];
|
|
|
128 |
break;
|
|
|
129 |
|
|
|
130 |
case 'job' :
|
|
|
131 |
$path = $this->config['leaderslinked.fullpath.job'];
|
|
|
132 |
break;
|
|
|
133 |
|
|
|
134 |
case 'chat' :
|
|
|
135 |
$path = $this->config['leaderslinked.fullpath.chat'];
|
|
|
136 |
break;
|
|
|
137 |
|
|
|
138 |
case 'feed' :
|
|
|
139 |
$path = $this->config['leaderslinked.fullpath.feed'];
|
|
|
140 |
break;
|
|
|
141 |
|
|
|
142 |
case 'post' :
|
|
|
143 |
$path = $this->config['leaderslinked.fullpath.post'];
|
|
|
144 |
break;
|
|
|
145 |
|
|
|
146 |
case 'message' :
|
|
|
147 |
$path = $this->config['leaderslinked.fullpath.message'];
|
|
|
148 |
break;
|
|
|
149 |
|
|
|
150 |
case 'microlearning-topic' :
|
|
|
151 |
$path = $this->config['leaderslinked.fullpath.microlearning_topic'];
|
|
|
152 |
break;
|
|
|
153 |
|
|
|
154 |
case 'microlearning-capsule' :
|
|
|
155 |
$path = $this->config['leaderslinked.fullpath.microlearning_capsule'];
|
|
|
156 |
break;
|
|
|
157 |
|
|
|
158 |
case 'microlearning-slide' :
|
|
|
159 |
$path = $this->config['leaderslinked.fullpath.microlearning_slide'];
|
|
|
160 |
break;
|
| 1590 |
eleazar |
161 |
|
| 8537 |
efrain |
162 |
case 'recruitment-selection' :
|
| 1590 |
eleazar |
163 |
$path = $this->config['leaderslinked.fullpath.recruitment_selection'];
|
|
|
164 |
break;
|
| 1 |
www |
165 |
|
| 15540 |
efrain |
166 |
case 'daily-pulse' :
|
|
|
167 |
$path = $this->config['leaderslinked.fullpath.daily_pulse'] ;
|
|
|
168 |
break;
|
|
|
169 |
|
| 15542 |
efrain |
170 |
case 'engagement-reward' :
|
|
|
171 |
$path = $this->config['leaderslinked.fullpath.engagement_reward'] ;
|
|
|
172 |
break;
|
|
|
173 |
|
| 1 |
www |
174 |
default :
|
|
|
175 |
$path = $this->config['leaderslinked.fullpath.image'];
|
|
|
176 |
break;
|
|
|
177 |
|
|
|
178 |
}
|
|
|
179 |
if($code && $fileName) {
|
| 8537 |
efrain |
180 |
|
|
|
181 |
if (empty($code2)) {
|
|
|
182 |
$request_fullpath = $path . $code . DIRECTORY_SEPARATOR . $fileName;
|
|
|
183 |
} else {
|
|
|
184 |
$request_fullpath = $path . $code . DIRECTORY_SEPARATOR. $code2. DIRECTORY_SEPARATOR . $fileName;
|
|
|
185 |
}
|
|
|
186 |
|
| 8543 |
efrain |
187 |
|
| 16766 |
efrain |
188 |
// echo $request_fullpath; exit;
|
|
|
189 |
|
|
|
190 |
|
| 1 |
www |
191 |
} else {
|
|
|
192 |
$request_fullpath = $no_image;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
if(empty($fileName)) {
|
|
|
196 |
$extensions = explode('.',$request_fullpath);
|
|
|
197 |
$extension = strtolower(trim($extensions[count($extensions)-1]));
|
|
|
198 |
if ($extension=='jpg' || $extension=='jpeg' || $extension=='gif' || $extension == 'png') {
|
|
|
199 |
$request_fullpath = $no_image;
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
| 16766 |
efrain |
204 |
|
| 1 |
www |
205 |
|
|
|
206 |
|
|
|
207 |
if(file_exists($request_fullpath)) {
|
|
|
208 |
|
|
|
209 |
// Try to open file
|
|
|
210 |
if (!is_readable($request_fullpath)) {
|
|
|
211 |
return $this->getResponse()->setStatusCode(500);
|
|
|
212 |
}
|
| 16766 |
efrain |
213 |
} else {
|
|
|
214 |
$request_fullpath = $no_image;
|
|
|
215 |
}
|
| 1 |
www |
216 |
|
|
|
217 |
// Get file size in bytes.
|
|
|
218 |
$fileSize = filesize($request_fullpath);
|
|
|
219 |
|
|
|
220 |
// Get MIME type of the file.
|
|
|
221 |
$mimeType = mime_content_type($request_fullpath);
|
|
|
222 |
if($mimeType===false) {
|
|
|
223 |
$mimeType = 'application/octet-stream';
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
$fileContent = file_get_contents($request_fullpath);
|
|
|
227 |
|
|
|
228 |
$response = $this->getResponse();
|
|
|
229 |
$headers = $response->getHeaders();
|
|
|
230 |
$headers->addHeaderLine('Content-type: ' . $mimeType);
|
|
|
231 |
$headers->addHeaderLine('Content-length: ' . $fileSize);
|
|
|
232 |
|
|
|
233 |
if($fileContent!==false) {
|
|
|
234 |
$response->setContent($fileContent);
|
| 16766 |
efrain |
235 |
return $this->getResponse();
|
| 1 |
www |
236 |
} else {
|
|
|
237 |
$this->getResponse()->setStatusCode(500);
|
|
|
238 |
return;
|
|
|
239 |
}
|
| 16766 |
efrain |
240 |
|
| 1 |
www |
241 |
|
| 16766 |
efrain |
242 |
|
| 1 |
www |
243 |
}
|
|
|
244 |
|
|
|
245 |
}
|