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