| 1 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
| 59 |
efrain |
10 |
use LeadersLinked\Library\Functions;
|
| 1 |
efrain |
11 |
|
|
|
12 |
|
|
|
13 |
class StorageNetworkController extends AbstractActionController
|
|
|
14 |
{
|
|
|
15 |
/**
|
|
|
16 |
*
|
|
|
17 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
18 |
*/
|
|
|
19 |
private $adapter;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
*
|
|
|
23 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
24 |
*/
|
|
|
25 |
private $cache;
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
*
|
|
|
30 |
* @var \Laminas\Log\LoggerInterface
|
|
|
31 |
*/
|
|
|
32 |
private $logger;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
* @var array
|
|
|
37 |
*/
|
|
|
38 |
private $config;
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
*
|
|
|
43 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
44 |
*/
|
|
|
45 |
private $translator;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
51 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
52 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
|
|
53 |
* @param array $config
|
|
|
54 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
55 |
*/
|
|
|
56 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
57 |
{
|
|
|
58 |
$this->adapter = $adapter;
|
|
|
59 |
$this->cache = $cache;
|
|
|
60 |
$this->logger = $logger;
|
|
|
61 |
$this->config = $config;
|
|
|
62 |
$this->translator = $translator;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public function downloadAction()
|
|
|
66 |
{
|
|
|
67 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
68 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
$path = $this->config['leaderslinked.fullpath.network'];
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
$type = $this->params()->fromRoute('type', 'logo');
|
|
|
75 |
if($type == 'favico') {
|
|
|
76 |
$filename = 'favico.png';
|
|
|
77 |
} else if($type == 'navbar') {
|
|
|
78 |
$filename = 'navbar.png';
|
|
|
79 |
} else if($type == 'moodle') {
|
|
|
80 |
$filename = 'moodle.png';
|
|
|
81 |
} else {
|
|
|
82 |
$filename = 'logo.png';
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
$request_fullpath = $path . $currentNetwork->uuid . DIRECTORY_SEPARATOR . $filename;
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
if(!file_exists($request_fullpath)) {
|
|
|
90 |
$request_fullpath = $this->config['leaderslinked.images_default.no_image'];
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
if(file_exists($request_fullpath)) {
|
|
|
95 |
if (!is_readable($request_fullpath)) {
|
|
|
96 |
return $this->getResponse()->setStatusCode(500);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
$fileSize = filesize($request_fullpath);
|
|
|
100 |
|
|
|
101 |
$mimeType = mime_content_type($request_fullpath);
|
|
|
102 |
if($mimeType===false) {
|
|
|
103 |
$mimeType = 'application/octet-stream';
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$fileContent = file_get_contents($request_fullpath);
|
|
|
107 |
|
|
|
108 |
$response = $this->getResponse();
|
| 59 |
efrain |
109 |
Functions::addCrossSiteToResponse($response);
|
|
|
110 |
|
| 1 |
efrain |
111 |
$headers = $response->getHeaders();
|
|
|
112 |
$headers->addHeaderLine('Content-type: ' . $mimeType);
|
|
|
113 |
$headers->addHeaderLine('Content-length: ' . $fileSize);
|
|
|
114 |
|
|
|
115 |
if($fileContent!==false) {
|
|
|
116 |
$response->setContent($fileContent);
|
|
|
117 |
} else {
|
|
|
118 |
$this->getResponse()->setStatusCode(500);
|
|
|
119 |
return;
|
|
|
120 |
}
|
|
|
121 |
} else {
|
|
|
122 |
return $this->getResponse()->setStatusCode(404);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
return $this->getResponse();
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
}
|