Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

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