Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5848 | Ir a la última revisión | | Ultima modificación | Ver Log |

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