Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17018 | Rev 17044 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17018 Rev 17042
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
namespace LeadersLinked\Library;
3
namespace LeadersLinked\Library;
Línea 3... Línea 4...
3
 
4
 
4
use LeadersLinked\Model\User;
5
use LeadersLinked\Model\User;
5
use LeadersLinked\Model\UserProfile;
6
use LeadersLinked\Model\UserProfile;
6
use LeadersLinked\Model\Company;
7
use LeadersLinked\Model\Company;
-
 
8
use LeadersLinked\Model\Group;
-
 
9
use LeadersLinked\Model\StorageFile;
Línea 7... Línea 10...
7
use LeadersLinked\Model\Group;
10
use LeadersLinked\Mapper\StorageFileMapper;
8
 
11
 
-
 
12
class Storage
-
 
13
{
-
 
14
    const FILE_TYPE_IMAGE = 'image';
9
class Storage 
15
    const FILE_TYPE_VIDEO = 'video';
-
 
16
    const FILE_TYPE_DOCUMENT = 'document';
10
{
17
 
11
    
18
    const TYPE_DEFAULT = 'default';
12
    const TYPE_CHAT                             = 'chat';
19
    const TYPE_CHAT = 'chat';
13
    const TYPE_GROUP                            = 'group';
20
    const TYPE_GROUP = 'group';
14
    const TYPE_USER                             = 'user';
21
    const TYPE_USER = 'user';
-
 
22
    const TYPE_IMAGE = 'image';
15
    const TYPE_IMAGE                            = 'image';
23
    const TYPE_JOB = 'job';
16
    const TYPE_JOB                              = 'job';
24
    const TYPE_MEDIA = 'media';
17
    const TYPE_COMPANY                          = 'company';
25
    const TYPE_COMPANY = 'company';
18
    const TYPE_FEED                             = 'feed';
26
    const TYPE_FEED = 'feed';
19
    CONST TYPE_POST                             = 'post';
27
    const TYPE_POST = 'post';
20
    const TYPE_MICROLEARNING_TOPIC              = 'topic';
28
    const TYPE_MICROLEARNING_TOPIC = 'topic';
21
    const TYPE_MICROLEARNING_CAPSULE            = 'capsule';
29
    const TYPE_MICROLEARNING_CAPSULE = 'capsule';
22
    const TYPE_MICROLEARNING_SLIDE              = 'slide';
30
    const TYPE_MICROLEARNING_SLIDE = 'slide';
23
    const TYPE_JOB_DESCRIPTION                  = 'jobdesc';
31
    const TYPE_JOB_DESCRIPTION = 'jobdesc';
24
    const TYPE_SELF_EVALUATION                  = 'selfval';
32
    const TYPE_SELF_EVALUATION = 'selfval';
25
    const TYPE_PERFORMANCE_EVALUATION           = 'perfeva';
33
    const TYPE_PERFORMANCE_EVALUATION = 'perfeva';
26
    const TYPE_RECRUITMENT_SELECTION            = 'recrsel';
34
    const TYPE_RECRUITMENT_SELECTION = 'recrsel';
27
    const TYPE_PLANNING_OBJECTIVES_AND_GOALS    = 'plannig';
35
    const TYPE_PLANNING_OBJECTIVES_AND_GOALS = 'plannig';
28
    const TYPE_MESSAGE                          = 'message';
36
    const TYPE_MESSAGE = 'message';
29
    const TYPE_SURVEY                           = 'survey';
37
    const TYPE_SURVEY = 'survey';
30
    const TYPE_NETWORK                          = 'network';
38
    const TYPE_NETWORK = 'network';
31
    const TYPE_DAILY_PULSE                      = 'dailpuls';
39
    const TYPE_DAILY_PULSE = 'dailpuls';
32
    const TYPE_ENGAGEMENT_REWARD                = 'engarewr';
40
    const TYPE_ENGAGEMENT_REWARD = 'engarewr';
33
    const TYPE_KNOWLEDGE_AREA                   = 'knowarea';
41
    const TYPE_KNOWLEDGE_AREA = 'knowarea';
34
    const TYPE_MY_COACH                         = 'mycoach';
42
    const TYPE_MY_COACH = 'mycoach';
35
    const TYPE_HABIT_EMOJI                      = 'habit-emoji';
43
    const TYPE_HABIT_EMOJI = 'habit-emoji';
36
    const TYPE_HABIT_CONTENT                    = 'habit-content';
44
    const TYPE_HABIT_CONTENT = 'habit-content';
37
    
-
 
38
    const BASE_PATH = 'data' . DIRECTORY_SEPARATOR . 'storage';
45
 
39
    
46
    const BASE_PATH = 'data' . DIRECTORY_SEPARATOR . 'storage';
40
    
-
 
41
    /**
47
 
42
     * 
48
    /**
43
     * @var\LeadersLinked\Library\Storage 
49
     * @var \LeadersLinked\Library\Storage 
44
     */
50
     */
45
    private static $_instance;
51
    private static $_instance;
46
    
-
 
47
    /**
52
 
48
     * 
53
    /**
49
     * @var array
54
     * @var array
50
     */
55
     */
51
    private $config;
56
    private $config;
52
    
-
 
53
    /**
57
 
54
     * 
58
    /**
55
     * @var \Laminas\Db\Adapter\AdapterInterface 
59
     * @var \Laminas\Db\Adapter\AdapterInterface 
56
     */
-
 
57
    private $adapter;
-
 
Línea 58... Línea -...
58
    
-
 
59
    
60
     */
-
 
61
    private $adapter;
60
 
62
 
-
 
63
    /**
-
 
64
     * @var string
-
 
65
     */
-
 
66
    private $tempPath;
-
 
67
 
-
 
68
    /**
-
 
69
     * @var string
-
 
70
     */
-
 
71
    private $storagePath;
-
 
72
 
-
 
73
    /**
-
 
74
     * @var array
-
 
75
     */
-
 
76
    private $currentFile;
-
 
77
 
-
 
78
    /**
-
 
79
     * @var array
-
 
80
     */
61
    
81
    private $files;
62
    /**
82
 
63
     * 
83
    /**
64
     * @param array $config
84
     * @param array $config
65
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
85
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
66
     */
86
     */
67
    private function __construct($config, $adapter) 
87
    private function __construct($config, $adapter)
-
 
88
    {
-
 
89
        $this->config = $config;
-
 
90
        $this->adapter = $adapter;
-
 
91
        $this->currentFile = [];
-
 
92
 
-
 
93
        $this->storagePath = self::BASE_PATH;
-
 
94
        if (!file_exists($this->storagePath)) {
-
 
95
            mkdir($this->storagePath, 0775, true);
-
 
96
        }
-
 
97
 
-
 
98
        $this->tempPath = self::BASE_PATH . DIRECTORY_SEPARATOR . 'tmp';
68
    {
99
        if (!file_exists($this->tempPath)) {
69
        $this->config       = $config;
100
            mkdir($this->tempPath, 0775, true);
70
        $this->adapter      = $adapter;
101
        }
71
    }
-
 
72
    
102
    }
73
    /**
103
 
74
     * 
104
    /**
75
     * @param array $config
105
     * @param array $config
76
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
106
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
77
     * @return \LeadersLinked\Library\Storage
107
     * @return \LeadersLinked\Library\Storage
78
     */
108
     */
79
    public static function getInstance($config, $adapter)
109
    public static function getInstance($config, $adapter)
80
    {
110
    {
81
        if(self::$_instance == null) {
111
        if (self::$_instance == null) {
82
            self::$_instance = new Storage($config, $adapter);
112
            self::$_instance = new Storage($config, $adapter);
83
        }
113
        }
84
        
114
 
85
        return self::$_instance;
115
        return self::$_instance;
86
    }
116
    }
87
    
117
 
88
    /**
118
    /**
89
     * 
119
     * 
90
     * @param User $user
120
     * @param User $user
91
     * @return string
121
     * @return string
92
     */
122
     */
93
    public function getUserImage($user)
123
    public function getUserImage($user)
94
    {
124
    {
95
        if($user->image) {
-
 
96
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
-
 
97
            if(file_exists($remoto)) {
-
 
98
                return $this->getPresignedUrl($remoto);
-
 
99
                
-
 
100
            }
-
 
101
        }
-
 
102
        
-
 
103
        $remoto = $this->config['leaderslinked.images_default.user_image'];
-
 
104
        return $this->getPresignedUrl($remoto);
-
 
105
    }
-
 
106
    
-
 
107
    
-
 
108
    /**
-
 
109
     *
-
 
110
     * @param User $user
-
 
111
     * @return string
-
 
112
     */
-
 
113
    public function getUserImageForCodeAndFilename($code, $filename)
-
 
114
    {
-
 
115
        if($filename) {
125
        if ($user->image) {
116
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
-
 
117
            if(file_exists($remoto)) {
126
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
118
                return $this->getPresignedUrl($remoto);
127
            if (file_exists($remoto)) {
119
                
128
                return $this->getPresignedUrl($remoto);
120
            }
129
            }
121
        }
130
        }
122
        
-
 
123
        $remoto = $this->config['leaderslinked.images_default.user_image'];
131
 
-
 
132
        $remoto = $this->config['leaderslinked.images_default.user_image'];
124
        return $this->getPresignedUrl($remoto);
133
        return $this->getPresignedUrl($remoto);
125
        
134
    }
126
    }
135
 
127
    
136
 
128
    /**
137
    /**
129
     *
138
     *
130
     * @param User $user
139
     * @param User $user
131
     * @param UserProfile $userProfile
140
     * @param UserProfile $userProfile
132
     * @return string
141
     * @return string
133
     */
142
     */
134
    public function getUserProfileImage($user, $userProfile)
143
    public function getUserProfileImage($user, $userProfile)
135
    {
144
    {
136
        if($userProfile->image) {
145
        if ($userProfile->image) {
137
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
-
 
138
            if(file_exists($remoto)) {
146
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
139
                return $this->getPresignedUrl($remoto);
147
            if (file_exists($remoto)) {
140
                
148
                return $this->getPresignedUrl($remoto);
141
            }
149
            }
142
        }
150
        }
143
        
-
 
144
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
151
 
145
        return $this->getPresignedUrl($remoto);
152
        $remoto = $this->config['leaderslinked.images_default.user_profile'];
146
        
153
        return $this->getPresignedUrl($remoto);
147
    }
154
    }
148
    
155
 
149
    /**
156
    /**
150
     *
157
     *
151
     * @param User $user
158
     * @param User $user
152
     * @param UserProfile $userProfile
159
     * @param UserProfile $userProfile
153
     * @return string
160
     * @return string
154
     */
161
     */
155
    public function getUserProfileCover($user, $userProfile)
162
    public function getUserProfileCover($user, $userProfile)
156
    {
163
    {
157
        if($userProfile->cover) {
164
        if ($userProfile->cover) {
158
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
-
 
159
            if(file_exists($remoto)) {
165
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
160
                return $this->getPresignedUrl($remoto);
166
            if (file_exists($remoto)) {
161
                
167
                return $this->getPresignedUrl($remoto);
162
            }
168
            }
163
        }
169
        }
164
        
-
 
165
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
170
 
166
        return $this->getPresignedUrl($remoto);
171
        $remoto = $this->config['leaderslinked.images_default.user_cover'];
167
        
172
        return $this->getPresignedUrl($remoto);
168
    }
173
    }
169
    
174
 
170
    /**
175
    /**
171
     *
176
     *
172
     * @param Company $company
177
     * @param Company $company
173
     * @return string
178
     * @return string
174
     */
179
     */
175
    public function getCompanyImage($company)
180
    public function getCompanyImage($company)
176
    {
181
    {
177
        if($company->image) {
182
        if ($company->image) {
178
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
-
 
179
            if(file_exists($remoto)) {
183
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
180
                return $this->getPresignedUrl($remoto);
184
            if (file_exists($remoto)) {
181
                
185
                return $this->getPresignedUrl($remoto);
182
            }
186
            }
183
        }
187
        }
184
        
-
 
185
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
188
 
186
        return $this->getPresignedUrl($remoto);
189
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
187
        
190
        return $this->getPresignedUrl($remoto);
188
    }
191
    }
189
    
192
 
190
    /**
193
    /**
191
     *
194
     *
192
     * @param string $code
195
     * @param string $code
193
     * @param string $filename
196
     * @param string $filename
194
     * @return string
197
     * @return string
195
     */
198
     */
196
    public function getCompanyImageForCodeAndFilename($code, $filename)
199
    public function getCompanyImageForCodeAndFilename($code, $filename)
197
    {
200
    {
198
        if($filename) {
201
        if ($filename) {
199
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
-
 
200
            if(file_exists($remoto)) {
202
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
201
                return $this->getPresignedUrl($remoto);
203
            if (file_exists($remoto)) {
202
                
204
                return $this->getPresignedUrl($remoto);
203
            }
205
            }
204
        }
206
        }
205
        
-
 
206
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
207
 
207
        return $this->getPresignedUrl($remoto);
208
        $remoto = $this->config['leaderslinked.images_default.company_profile'];
208
        
209
        return $this->getPresignedUrl($remoto);
209
    }
210
    }
210
    
211
 
211
    /**
212
    /**
212
     *
213
     *
213
     * @param Company $company
214
     * @param Company $company
214
     * @return string
215
     * @return string
215
     */
216
     */
216
    public function getCompanyCover($company)
217
    public function getCompanyCover($company)
217
    {
218
    {
218
        if($company->cover) {
219
        if ($company->cover) {
219
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
-
 
220
            if(file_exists($remoto)) {
220
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
221
                return $this->getPresignedUrl($remoto);
221
            if (file_exists($remoto)) {
222
                
222
                return $this->getPresignedUrl($remoto);
223
            }
223
            }
224
        }
224
        }
225
        
-
 
226
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
225
 
227
        return $this->getPresignedUrl($remoto);
226
        $remoto = $this->config['leaderslinked.images_default.company_cover'];
228
        
227
        return $this->getPresignedUrl($remoto);
229
    }
228
    }
230
    
229
 
231
    /**
230
    /**
232
     *
231
     *
233
     * @param Group $group
232
     * @param Group $group
234
     * @return string
233
     * @return string
235
     */
234
     */
236
    public function getGroupImage($group)
235
    public function getGroupImage($group)
237
    {
236
    {
238
        if($group->image) {
237
        if ($group->image) {
239
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
-
 
240
            if(file_exists($remoto)) {
238
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
241
                return $this->getPresignedUrl($remoto);
239
            if (file_exists($remoto)) {
242
                
240
                return $this->getPresignedUrl($remoto);
243
            }
241
            }
244
        }
242
        }
245
        
-
 
246
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
243
 
247
        return $this->getPresignedUrl($remoto);
244
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
248
        
245
        return $this->getPresignedUrl($remoto);
249
    }
246
    }
250
    
247
 
251
    /**
248
    /**
252
     *
249
     *
253
     * @param string $code
250
     * @param string $code
254
     * @param string $filename
251
     * @param string $filename
255
     * @return string
252
     * @return string
256
     */
253
     */
257
    public function getGroupImageForCodeAndFilename($code, $filename)
254
    public function getGroupImageForCodeAndFilename($code, $filename)
258
    {
255
    {
259
        if($filename) {
256
        if ($filename) {
260
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
-
 
261
            if(file_exists($remoto)) {
257
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
262
                return $this->getPresignedUrl($remoto);
258
            if (file_exists($remoto)) {
263
                
259
                return $this->getPresignedUrl($remoto);
264
            }
260
            }
265
        }
261
        }
266
        
-
 
267
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
262
 
268
        return $this->getPresignedUrl($remoto);
263
        $remoto = $this->config['leaderslinked.images_default.group_profile'];
269
        
264
        return $this->getPresignedUrl($remoto);
270
    }
265
    }
271
    
266
 
272
    /**
267
    /**
273
     *
268
     *
274
     * @param Group $group
269
     * @param Group $group
275
     * @return string
270
     * @return string
276
     */
271
     */
277
    public function getGroupCover($group)
272
    public function getGroupCover($group)
278
    {
273
    {
279
        if($group->cover) {
274
        if ($group->cover) {
280
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
-
 
281
            if(file_exists($remoto)) {
275
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
282
                return $this->getPresignedUrl($remoto);
276
            if (file_exists($remoto)) {
283
                
277
                return $this->getPresignedUrl($remoto);
284
            }
278
            }
285
        }
279
        }
286
        
-
 
287
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
280
 
288
        return $this->getPresignedUrl($remoto);
281
        $remoto = $this->config['leaderslinked.images_default.group_cover'];
289
        
282
        return $this->getPresignedUrl($remoto);
290
    }
283
    }
291
    
284
 
292
    /**
285
    /**
293
     *
286
     *
294
     * @param Group $group
287
     * @param Group $group
295
     * @return string
288
     * @return string
296
     */
289
     */
297
    public function getGenericImage($path, $code, $filename)
290
    public function getGenericImage($path, $code, $filename)
298
    {
291
    {
299
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
292
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
300
        
293
 
301
  
-
 
302
        if(file_exists($remoto)) {
294
 
303
            return $this->getPresignedUrl($remoto);
295
        if (file_exists($remoto)) {
304
            
296
            return $this->getPresignedUrl($remoto);
305
        } else {
-
 
306
            $remoto = $this->config['leaderslinked.images_default.no_image'];
297
        } else {
307
            return $this->getPresignedUrl($remoto);
298
            $remoto = $this->config['leaderslinked.images_default.no_image'];
308
            
299
            return $this->getPresignedUrl($remoto);
309
        }
300
        }
310
    }
301
    }
311
    
302
 
312
    
303
 
313
    
304
 
314
    
305
 
315
    /**
306
    /**
316
     *
307
     *
317
     * @param string $path
308
     * @param string $path
318
     * @param string $code,
309
     * @param string $code,
319
     * @param string $filename
310
     * @param string $filename
320
     * @param boolean $checkExists
311
     * @param boolean $checkExists
321
     * @return string
312
     * @return string
322
     */
313
     */
323
    public function getFileFromDisk($path, $code, $filename)
314
    public function getFileFromDisk($path, $code, $filename)
324
    {
315
    {
325
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
316
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
326
        
317
 
327
        if(file_exists($current_file)) {
318
        if (file_exists($current_file)) {
328
            return $current_file;
319
            return $current_file;
329
        } 
320
        }
330
        return;
321
        return;
331
    }
322
    }
332
    
323
 
333
    
324
 
334
    /**
325
    /**
335
     *
326
     *
336
     * @param string $path
327
     * @param string $path
337
     * @param string $code,
328
     * @param string $code,
338
     * @return string
329
     * @return string
339
     */
330
     */
340
    public function getDirectoryFromDisk($path, $code)
331
    public function getDirectoryFromDisk($path, $code)
341
    {
332
    {
342
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
333
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code;
343
        
334
 
344
        if(file_exists($directory)) {
335
        if (file_exists($directory)) {
345
            return $directory;
336
            return $directory;
346
        }
337
        }
347
        return;
338
        return;
348
    }
339
    }
349
    
340
 
350
    /**
341
    /**
351
     *
342
     *
352
     * @param string $path
343
     * @param string $path
353
     * @param string $code,
344
     * @param string $code,
354
     * @param string $filename
345
     * @param string $filename
355
     * @param boolean $checkExists
346
     * @param boolean $checkExists
356
     * @return string
347
     * @return string
357
     */
348
     */
358
    public function getGenericFile($path, $code, $filename, $checkExists = true)
349
    public function getGenericFile($path, $code, $filename, $checkExists = true)
Línea 359... Línea 350...
359
    {
350
    {
360
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
351
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
361
        
352
 
362
 
-
 
363
        if($checkExists) {
353
 
364
            if(file_exists($remoto)) {
354
        if ($checkExists) {
365
                return $this->getPresignedUrl($remoto);
355
            if (file_exists($remoto)) {
366
                
356
                return $this->getPresignedUrl($remoto);
367
            } else {
357
            } else {
368
                return;
358
                return;
369
            } 
359
            }
370
        } 
360
        }
371
        return $this->getPresignedUrl($remoto);
361
        return $this->getPresignedUrl($remoto);
372
    }
362
    }
373
    
-
 
374
    public function getPathByType($type)
363
 
375
    {
364
    public function getPathByType($type)
376
        switch($type) 
365
    {
377
        {
366
        switch ($type) {
378
            case TYPE_CHAT : 
367
            case TYPE_CHAT:
379
                return $this->getPathChat();
368
                return $this->getPathChat();
380
                
369
 
381
            case TYPE_GROUP : 
370
            case TYPE_GROUP:
382
                return $this->getPathGroup();
371
                return $this->getPathGroup();
383
                
372
 
384
            case TYPE_USER : 
373
            case TYPE_USER:
385
                return $this->getPathUser();
374
                return $this->getPathUser();
386
                
375
 
387
            case TYPE_IMAGE : 
376
            case TYPE_IMAGE:
388
                return $this->getPathImage();
377
                return $this->getPathImage();
389
                
378
 
390
            case TYPE_JOB : 
379
            case TYPE_JOB:
391
                return $this->getPathJob();
380
                return $this->getPathJob();
392
                
381
 
393
            case TYPE_COMPANY : 
382
            case TYPE_COMPANY:
394
                return $this->getPathCompany();
383
                return $this->getPathCompany();
395
                
384
 
396
            case TYPE_FEED : 
385
            case TYPE_FEED:
397
                return $this->getPathFeed();
386
                return $this->getPathFeed();
398
                
387
 
399
            case TYPE_POST : 
388
            case TYPE_POST:
400
                return $this->getPathPost();
389
                return $this->getPathPost();
401
                
390
 
402
            case TYPE_MICROLEARNING_TOPIC  : 
391
            case TYPE_MICROLEARNING_TOPIC:
403
                return $this->getPathMicrolearningTopic();
392
                return $this->getPathMicrolearningTopic();
404
                
393
 
405
            case TYPE_MICROLEARNING_CAPSULE : 
394
            case TYPE_MICROLEARNING_CAPSULE:
406
                return $this->getPathMicrolearningCapsule();
395
                return $this->getPathMicrolearningCapsule();
407
                
396
 
408
            case TYPE_MICROLEARNING_SLIDE  : 
397
            case TYPE_MICROLEARNING_SLIDE:
409
                return $this->getPathMicrolearningSlide();
398
                return $this->getPathMicrolearningSlide();
410
                
399
 
411
            case TYPE_JOB_DESCRIPTION : 
400
            case TYPE_JOB_DESCRIPTION:
412
                return $this->getPathJobDescription();
401
                return $this->getPathJobDescription();
413
                
402
 
414
            case TYPE_SELF_EVALUATION  : 
403
            case TYPE_SELF_EVALUATION:
415
                return $this->getPathSelfEvaluation();
404
                return $this->getPathSelfEvaluation();
416
                
405
 
417
            case TYPE_PERFORMANCE_EVALUATION  : 
406
            case TYPE_PERFORMANCE_EVALUATION:
418
                return $this->getPathPerformanceEvaluation();
407
                return $this->getPathPerformanceEvaluation();
419
                
408
 
420
            case TYPE_RECRUITMENT_SELECTION  : 
409
            case TYPE_RECRUITMENT_SELECTION:
421
                return $this->getPathRecruitmentSelection();
410
                return $this->getPathRecruitmentSelection();
422
                
411
 
423
            case TYPE_PLANNING_OBJECTIVES_AND_GOALS : 
412
            case TYPE_PLANNING_OBJECTIVES_AND_GOALS:
424
                return $this->getPathPlanningObjectivesAnGoals();
413
                return $this->getPathPlanningObjectivesAnGoals();
425
                
414
 
426
                
415
 
427
            case TYPE_MESSAGE  : 
416
            case TYPE_MESSAGE:
428
                return $this->getPathMessage();
417
                return $this->getPathMessage();
429
                
418
 
430
            case TYPE_SURVEY   : 
419
            case TYPE_SURVEY:
431
                return $this->getPathSurvey();
420
                return $this->getPathSurvey();
432
                
421
 
433
            case TYPE_NETWORK   : 
422
            case TYPE_NETWORK:
434
                return $this->getPathNetwork();
423
                return $this->getPathNetwork();
435
                
424
 
436
            case TYPE_DAILY_PULSE : 
425
            case TYPE_DAILY_PULSE:
437
                return $this->getPathDailyPulse();
426
                return $this->getPathDailyPulse();
438
                
427
 
439
            case TYPE_ENGAGEMENT_REWARD  : 
428
            case TYPE_ENGAGEMENT_REWARD:
440
                return $this->getPathEngagementReward();
429
                return $this->getPathEngagementReward();
441
                
430
 
442
            case TYPE_KNOWLEDGE_AREA : 
431
            case TYPE_KNOWLEDGE_AREA:
443
                return $this->getPathKnowledgeArea();
432
                return $this->getPathKnowledgeArea();
444
                
433
 
445
            case TYPE_MY_COACH : 
434
            case TYPE_MY_COACH:
446
                return $this->getPathMyCoach();
435
                return $this->getPathMyCoach();
447
                
436
 
448
            case TYPE_HABIT_EMOJI  : 
437
            case TYPE_HABIT_EMOJI:
449
                return $this->getPathHabitEmoji();
438
                return $this->getPathHabitEmoji();
450
                
439
 
451
            case TYPE_HABIT_CONTENT : 
440
            case TYPE_HABIT_CONTENT:
452
                return $this->getPathHabitContent();
441
                return $this->getPathHabitContent();
453
                
-
 
454
            default : 
-
 
455
                return DIRECTORY_SEPARATOR;
442
 
456
        }
443
            default:
457
        
444
                return DIRECTORY_SEPARATOR;
458
       
445
        }
459
    }
446
    }
460
    
447
 
461
    /**
448
    /**
462
     *
449
     *
463
     * @param Group $group
450
     * @param Group $group
464
     * @return string
451
     * @return string
465
     */
452
     */
Línea 466... Línea 453...
466
    public function getGenericImageByType($type, $code, $filename)
453
    public function getGenericImageByType($type, $code, $filename)
467
    {
454
    {
468
        $path = $this->getPathByType($type);
-
 
469
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
455
        $path = $this->getPathByType($type);
470
 
456
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
471
        if(file_exists($remoto)) {
457
 
472
            return $this->getPresignedUrl($remoto);
-
 
473
            
458
        if (file_exists($remoto)) {
474
        } else {
459
            return $this->getPresignedUrl($remoto);
475
            $remoto = $this->config['leaderslinked.images_default.no_image'];
460
        } else {
476
            return $this->getPresignedUrl($remoto);
461
            $remoto = $this->config['leaderslinked.images_default.no_image'];
477
            
462
            return $this->getPresignedUrl($remoto);
478
        }
463
        }
479
    }
464
    }
480
    
465
 
Línea 487... Línea 472...
487
     * @return string
472
     * @return string
488
     */
473
     */
489
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
474
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
490
    {
475
    {
491
        $path = $this->getPathByType($type);
476
        $path = $this->getPathByType($type);
492
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
477
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
Línea 493... Línea 478...
493
 
478
 
494
        if($checkExists) {
479
        if ($checkExists) {
495
            if(file_exists($remoto)) {
480
            if (file_exists($remoto)) {
496
                return $this->getPresignedUrl($remoto);
-
 
497
                
481
                return $this->getPresignedUrl($remoto);
498
            } else {
482
            } else {
499
                return;
483
                return;
500
            }
484
            }
501
        }
485
        }
502
        return $this->getPresignedUrl($remoto);
486
        return $this->getPresignedUrl($remoto);
503
    }
487
    }
504
    
488
 
505
    /**
489
    /**
506
     *
490
     *
507
     * @param string $path
491
     * @param string $path
508
     * @param string $code
492
     * @param string $code
509
     * @param string $filename
493
     * @param string $filename
510
     * @return string
494
     * @return string
511
     */
495
     */
512
    public function delete($path, $code, $filename)
496
    public function delete($path, $code, $filename)
513
    {
497
    {
514
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
498
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
515
        return @unlink($remoto);
-
 
516
 
-
 
517
        
499
        return @unlink($remoto);
518
    }
500
    }
519
    
501
 
520
  
502
 
521
    
503
 
522
    /**
504
    /**
523
     *
505
     *
524
     * @return string
506
     * @return string
525
     */
507
     */
526
    public function getPathMedia()
508
    public function getPathMedia()
527
    {
509
    {
528
        return $this->config['leaderslinked.storage.fullpath_media'];
510
        return $this->config['leaderslinked.storage.fullpath_media'];
529
    }
511
    }
530
    
512
 
531
    
513
 
532
    /**
514
    /**
533
     *
515
     *
534
     * @return string
516
     * @return string
535
     */
517
     */
536
    public function getPathHabitEmoji()
518
    public function getPathHabitEmoji()
537
    {
519
    {
538
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
520
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
539
    }
521
    }
540
    
522
 
541
    /**
523
    /**
542
     *
524
     *
543
     * @return string
525
     * @return string
544
     */
526
     */
545
    public function getPathHabitContent()
527
    public function getPathHabitContent()
546
    {
528
    {
547
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
529
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
Línea 548... Línea 530...
548
    }
530
    }
549
 
531
 
550
    
532
 
551
    /**
533
    /**
552
     * 
534
     * 
553
     * @return string
535
     * @return string
554
     */
536
     */
555
    public function getPathGroup()
537
    public function getPathGroup()
556
    {
538
    {
557
        return $this->config['leaderslinked.storage.fullpath_group'];
539
        return $this->config['leaderslinked.storage.fullpath_group'];
558
    }
540
    }
559
    
541
 
560
    /**
542
    /**
561
     *
543
     *
562
     * @return string
544
     * @return string
563
     */
545
     */
564
    public function getPathUser()
546
    public function getPathUser()
565
    {
547
    {
566
        return $this->config['leaderslinked.storage.fullpath_user'];
548
        return $this->config['leaderslinked.storage.fullpath_user'];
567
    }
549
    }
568
    
550
 
569
    /**
551
    /**
570
     *
552
     *
571
     * @return string
553
     * @return string
572
     */
554
     */
573
    public function getPathImage()
555
    public function getPathImage()
574
    {
556
    {
575
        return $this->config['leaderslinked.storage.fullpath_image'];
557
        return $this->config['leaderslinked.storage.fullpath_image'];
576
    }
558
    }
577
    
559
 
578
    /**
560
    /**
579
     *
561
     *
580
     * @return string
562
     * @return string
581
     */
563
     */
582
    public function getPathJob()
564
    public function getPathJob()
583
    {
565
    {
584
        return $this->config['leaderslinked.storage.fullpath_job'];
566
        return $this->config['leaderslinked.storage.fullpath_job'];
585
    }
567
    }
586
    
568
 
587
    /**
569
    /**
588
     *
570
     *
589
     * @return string
571
     * @return string
590
     */
572
     */
591
    public function getPathChat()
573
    public function getPathChat()
592
    {
574
    {
593
        return $this->config['leaderslinked.storage.fullpath_chat'];
575
        return $this->config['leaderslinked.storage.fullpath_chat'];
594
    }
576
    }
595
    
577
 
596
    /**
578
    /**
597
     *
579
     *
598
     * @return string
580
     * @return string
599
     */
581
     */
600
    public function getPathCompany()
582
    public function getPathCompany()
601
    {
583
    {
602
        return $this->config['leaderslinked.storage.fullpath_company'];
584
        return $this->config['leaderslinked.storage.fullpath_company'];
603
    }
585
    }
604
    
586
 
605
    /**
587
    /**
606
     *
588
     *
607
     * @return string
589
     * @return string
608
     */
590
     */
609
    public function getPathFeed()
591
    public function getPathFeed()
610
    {
592
    {
611
        return $this->config['leaderslinked.storage.fullpath_feed'];
593
        return $this->config['leaderslinked.storage.fullpath_feed'];
612
    }
594
    }
613
    
595
 
614
    
596
 
615
    
597
 
616
    /**
598
    /**
617
     *
599
     *
618
     * @return string
600
     * @return string
619
     */
601
     */
620
    public function getPathMessage()
602
    public function getPathMessage()
621
    {
603
    {
622
        return $this->config['leaderslinked.storage.fullpath_message'];
604
        return $this->config['leaderslinked.storage.fullpath_message'];
623
    }
605
    }
624
    
606
 
625
    /**
607
    /**
626
     *
608
     *
627
     * @return string
609
     * @return string
628
     */
610
     */
629
    public function getPathPost()
611
    public function getPathPost()
630
    {
612
    {
631
        return $this->config['leaderslinked.storage.fullpath_post'];
613
        return $this->config['leaderslinked.storage.fullpath_post'];
632
    }
614
    }
633
    
615
 
634
    /**
616
    /**
635
     *
617
     *
636
     * @return string
618
     * @return string
637
     */
619
     */
638
    public function getPathMicrolearningTopic()
620
    public function getPathMicrolearningTopic()
639
    {
621
    {
640
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
622
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
641
    }
623
    }
642
    
624
 
643
    /**
625
    /**
644
     *
626
     *
645
     * @return string
627
     * @return string
646
     */
628
     */
647
    public function getPathMicrolearningCapsule()
629
    public function getPathMicrolearningCapsule()
648
    {
630
    {
649
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
631
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
650
    }
632
    }
651
    
633
 
652
    /**
634
    /**
653
     *
635
     *
654
     * @return string
636
     * @return string
655
     */
637
     */
656
    public function getPathMicrolearningSlide()
638
    public function getPathMicrolearningSlide()
657
    {
639
    {
658
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
640
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
659
    }
641
    }
660
    
642
 
661
    /**
643
    /**
662
     *
644
     *
663
     * @return string
645
     * @return string
664
     */
646
     */
665
    public function getPathJobDescription()
647
    public function getPathJobDescription()
666
    {
648
    {
667
        return $this->config['leaderslinked.storage.fullpath_job_description'];
649
        return $this->config['leaderslinked.storage.fullpath_job_description'];
668
    }
650
    }
669
    
651
 
670
    /**
652
    /**
671
     *
653
     *
672
     * @return string
654
     * @return string
673
     */
655
     */
674
    public function getPathSelfEvaluation()
656
    public function getPathSelfEvaluation()
675
    {
657
    {
676
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
658
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
677
    }
659
    }
678
    
660
 
679
    /**
661
    /**
680
     *
662
     *
681
     * @return string
663
     * @return string
682
     */
664
     */
683
    public function getPathRecruitmentSelection()
665
    public function getPathRecruitmentSelection()
684
    {
666
    {
685
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
667
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
686
    }
668
    }
687
    
669
 
688
    /**
670
    /**
689
     *
671
     *
690
     * @return string
672
     * @return string
691
     */
673
     */
692
    public function getPathPerformanceEvaluation()
674
    public function getPathPerformanceEvaluation()
693
    {
675
    {
694
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
676
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
695
    }
677
    }
696
    
678
 
697
    /**
679
    /**
698
     *
680
     *
699
     * @return string
681
     * @return string
700
     */
682
     */
701
    public function getPathPlanningObjectivesAnGoals()
683
    public function getPathPlanningObjectivesAnGoals()
702
    {
684
    {
703
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
685
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
704
    }
686
    }
705
    
687
 
706
    /**
688
    /**
707
     *
689
     *
708
     * @return string
690
     * @return string
709
     */
691
     */
710
    public function getPathSurvey()
692
    public function getPathSurvey()
711
    {
693
    {
712
        return $this->config['leaderslinked.storage.fullpath_survey'];
694
        return $this->config['leaderslinked.storage.fullpath_survey'];
713
    }
695
    }
714
    
696
 
715
    /**
697
    /**
716
     *
698
     *
717
     * @return string
699
     * @return string
718
     */
700
     */
719
    public function getPathNetwork()
701
    public function getPathNetwork()
720
    {
702
    {
721
        return $this->config['leaderslinked.storage.fullpath_network'];
703
        return $this->config['leaderslinked.storage.fullpath_network'];
722
    }
704
    }
723
    
705
 
724
    /**
706
    /**
725
     *
707
     *
726
     * @return string
708
     * @return string
727
     */
709
     */
728
    public function getPathEngagementReward()
710
    public function getPathEngagementReward()
729
    {
711
    {
730
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
712
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
731
    }
713
    }
732
    
714
 
733
    /**
715
    /**
734
     *
716
     *
735
     * @return string
717
     * @return string
736
     */
718
     */
737
    public function getPathDailyPulse()
719
    public function getPathDailyPulse()
738
    {
720
    {
739
        return $this->config['leaderslinked.storage.fullpath_daily_pulse'];
721
        return $this->config['leaderslinked.storage.fullpath_daily_pulse'];
740
    }
722
    }
741
    
723
 
742
    /**
724
    /**
743
     *
725
     *
744
     * @return string
726
     * @return string
745
     */
727
     */
746
    public function getPathKnowledgeArea()
728
    public function getPathKnowledgeArea()
747
    {
729
    {
748
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
730
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
749
    }
731
    }
750
    
732
 
751
    /**
733
    /**
752
     *
734
     *
753
     * @return string
735
     * @return string
754
     */
736
     */
755
    public function getPathMyCoach()
737
    public function getPathMyCoach()
756
    {
738
    {
757
        return $this->config['leaderslinked.storage.fullpath_my_coach'];
739
        return $this->config['leaderslinked.storage.fullpath_my_coach'];
758
    }
740
    }
759
    
741
 
760
    /**
742
    /**
761
     * 
743
     * 
762
     * @param String $filename
744
     * @param String $filename
763
     * return boolean
745
     * return boolean
764
     */
746
     */
765
    public function objectExist($filename) 
747
    public function objectExist($filename)
766
    {
748
    {
767
        return file_exists($filename);
749
        return file_exists($filename);
768
    }
750
    }
769
    
751
 
770
    /**
752
    /**
771
     * 
753
     * 
772
     * @param string $remote
754
     * @param string $remote
773
     * @param string $local
755
     * @param string $local
774
     * @return boolean
756
     * @return boolean
775
     */
757
     */
776
    public function putObject($remote, $local)
758
    public function putObject($remote, $local)
777
    {
759
    {
778
        
760
 
779
        $dir = dirname($remote);
761
        $dir = dirname($remote);
780
        if(!file_exists($dir)) {
762
        if (!file_exists($dir)) {
781
            @mkdir($dir, 0755, true);
763
            @mkdir($dir, 0755, true);
782
        }
764
        }
783
        
765
 
784
        return @rename($local, $remote);
766
        return @rename($local, $remote);
785
    }
767
    }
786
    
768
 
787
    
769
 
788
    /**
770
    /**
Línea 789... Línea 771...
789
     *
771
     *
790
     * @param string $filename
772
     * @param string $filename
791
 
773
 
792
     * @return boolean
774
     * @return boolean
793
     */
775
     */
794
    public function deleteObject($filename)
776
    public function deleteObject($filename)
795
    {
777
    {
796
        return @unlink($filename);
778
        return @unlink($filename);
797
    }
779
    }
798
    
780
 
799
    
781
 
800
    /**
782
    /**
801
     * 
783
     * 
802
     * @param string $path
784
     * @param string $path
803
     * @param string $code
785
     * @param string $code
804
     * @param string $filename
786
     * @param string $filename
805
     * @return boolean
787
     * @return boolean
806
     */
788
     */
807
    public function deleteFile($path, $code, $filename)
789
    public function deleteFile($path, $code, $filename)
808
    {
790
    {
809
        if($code) {
791
        if ($code) {
810
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
792
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
811
        } else {
793
        } else {
812
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
794
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
813
        }
795
        }
814
        if(file_exists($remoto)) {
796
        if (file_exists($remoto)) {
815
            return @unlink($remoto);
797
            return @unlink($remoto);
816
        } else {
798
        } else {
817
            return true;
799
            return true;
818
        }
800
        }
819
    }
801
    }
820
    
802
 
821
    /**
803
    /**
822
     *
804
     *
823
     * @param string $path
805
     * @param string $path
824
     * @param string $code
806
     * @param string $code
825
     * @return boolean
807
     * @return boolean
826
     */
808
     */
827
    public function deleteDirectory($path, $code)
809
    public function deleteDirectory($path, $code)
828
    {
810
    {
829
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
811
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
830
        if(file_exists($remoto)) {
812
        if (file_exists($remoto)) {
831
            $this->deleteDirectoryRecursive($remoto);
813
            $this->deleteDirectoryRecursive($remoto);
832
            return true;
814
            return true;
833
        } else {
815
        } else {
834
            return true;
816
            return true;
835
        }
817
        }
836
    }
818
    }
837
    
819
 
838
    /**
820
    /**
839
     * 
821
     * 
-
 
822
     * @param string $dir
840
     * @param string $dir
823
     */
841
     */
824
    private function deleteDirectoryRecursive($dir)
842
    private function deleteDirectoryRecursive($dir) {
825
    {
843
        if (is_dir($dir)) {
826
        if (is_dir($dir)) {
844
            $objects = scandir($dir);
827
            $objects = scandir($dir);
845
            foreach ($objects as $object) {
828
            foreach ($objects as $object) {
846
                if ($object != ''.'' && $object != '..') {
829
                if ($object != '' . '' && $object != '..') {
847
                    if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.'/'.$object)) { 
830
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . '/' . $object)) {
848
                        @rmdir($dir. DIRECTORY_SEPARATOR .$object);
831
                        @rmdir($dir . DIRECTORY_SEPARATOR . $object);
849
                    }  else { 
832
                    } else {
850
                        @unlink($dir. DIRECTORY_SEPARATOR .$object);
833
                        @unlink($dir . DIRECTORY_SEPARATOR . $object);
851
                    }
834
                    }
852
                }
835
                }
853
            }
836
            }
854
            @rmdir($dir);
837
            @rmdir($dir);
Línea 855... Línea 838...
855
        }
838
        }
856
    }
839
    }
857
    
840
 
Línea 864... Línea 847...
864
     * @param string $local_filename
847
     * @param string $local_filename
865
     * @return boolean
848
     * @return boolean
866
     */
849
     */
867
    public function putFile($path, $code, $local_filename)
850
    public function putFile($path, $code, $local_filename)
868
    {
851
    {
869
        if($code) {
852
        if ($code) {
870
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
853
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
871
        } else {
854
        } else {
872
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
855
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
873
        }
856
        }
Línea 874... Línea 857...
874
 
857
 
875
        $dir = dirname($remote);
858
        $dir = dirname($remote);
876
        if(!file_exists($dir)) {
859
        if (!file_exists($dir)) {
877
            @mkdir($dir, 0755, true);
860
            @mkdir($dir, 0755, true);
878
        }
-
 
Línea 879... Línea -...
879
        
-
 
Línea -... Línea 861...
-
 
861
        }
880
 
862
 
881
        return @rename($local_filename, $remote);
863
 
882
 
864
        return @rename($local_filename, $remote);
883
    }
865
    }
884
    
866
 
885
    
867
 
886
    /**
868
    /**
887
     *
869
     *
888
     * @param string $tempfile
870
     * @param string $tempfile
889
     * @param string $path
871
     * @param string $path
890
     * @param string $code
872
     * @param string $code
891
     * @param string $filename
873
     * @param string $filename
892
     * @return boolean
874
     * @return boolean
893
     */
875
     */
894
    public function moveAndPutFile($tempfile, $path, $code, $filename)
876
    public function moveAndPutFile($tempfile, $path, $code, $filename)
895
    {
877
    {
896
        if($code) {
878
        if ($code) {
897
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
879
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
898
        } else {
880
        } else {
Línea 899... Línea 881...
899
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
881
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
900
        }
882
        }
901
        
883
 
902
 
884
 
903
        $dir = dirname($target_file);
885
        $dir = dirname($target_file);
904
        if(!file_exists($dir)) {
886
        if (!file_exists($dir)) {
905
            @mkdir($dir, 0755, true);
887
            @mkdir($dir, 0755, true);
906
        }
888
        }
907
 
889
 
908
        return move_uploaded_file($tempfile, $target_file);
890
        return move_uploaded_file($tempfile, $target_file);
909
    }
891
    }
910
    
892
 
911
    /**
893
    /**
912
     *
894
     *
913
     * @return string
895
     * @return string
914
     */
896
     */
915
    public function getStoagePath()
897
    public function getStoagePath()
916
    {
898
    {
917
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
899
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
918
    }
900
    }
919
    
901
 
920
    /**
902
    /**
-
 
903
     * 
921
     * 
904
     * @return string
922
     * @return string
905
     */
923
     */
906
    public function getTempPath()
924
    public function getTempPath() {
907
    {
925
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
908
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
926
        if(!file_exists($interal_path)) {
909
        if (!file_exists($interal_path)) {
927
            mkdir($interal_path, 0775);
-
 
928
        }
910
            mkdir($interal_path, 0775);
929
        
911
        }
930
        return $interal_path;
912
 
931
        
913
        return $interal_path;
932
    }
914
    }
933
    
915
 
934
    /**
916
    /**
935
     * 
917
     * 
936
     * @param string $url
918
     * @param string $url
937
     * @return string
-
 
Línea -... Línea 919...
-
 
919
     * @return string
938
     */
920
     */
939
    public function getPresignedUrl($url)
921
    public function getPresignedUrl($url)
940
    {
922
    {
941
        
923
 
942
 
924
 
943
        
925
 
944
        $code = hash('sha256', $url);
926
        $code = hash('sha256', $url);
945
        
927
 
946
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
928
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
947
        $storageFile = $storageFileMapper->fetchOneByCode($code);
929
        $storageFile = $storageFileMapper->fetchOneByCode($code);
948
        if(!$storageFile) {
930
        if (!$storageFile) {
949
            $storageFile = new \LeadersLinked\Model\StorageFile();
931
            $storageFile = new \LeadersLinked\Model\StorageFile();
950
            $storageFile->code = $code;
932
            $storageFile->code = $code;
951
            $storageFile->path = $url;
933
            $storageFile->path = $url;
952
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
-
 
953
            
934
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
954
            
935
 
955
            
936
 
956
            $storageFileMapper->insert($storageFile);
937
 
Línea 957... Línea 938...
957
            
938
            $storageFileMapper->insert($storageFile);
Línea 973... Línea 954...
973
        print_r($_SERVER);
954
        print_r($_SERVER);
Línea 974... Línea 955...
974
        
955
        
975
        
956
        
976
        $hostname = trim(str_replace('http://', 'https://', $hostname));
957
        $hostname = trim(str_replace('http://', 'https://', $hostname));
977
        */
958
        */
978
        
959
 
979
        
960
 
980
        
961
 
981
        
962
 
982
 
963
 
983
      
964
 
984
       
965
 
985
        
-
 
986
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
966
 
987
        
-
 
988
    }
-
 
989
    
-
 
990
   
-
 
991
    
-
 
992
    
-
 
993
    
-
 
994
    
-
 
995
    
967
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
-
 
968
    }
-
 
969
 
-
 
970
    /**
-
 
971
     * Creates a new GD image resource with transparency settings for PNG.
-
 
972
     * @param int $width The width of the new image.
-
 
973
     * @param int $height The height of the new image.
-
 
974
     * @return \GdImage|false The image resource or false on failure.
-
 
975
     */
-
 
976
    private function _createImageCanvas($width, $height)
-
 
977
    {
-
 
978
        $new_image = imageCreateTrueColor($width, $height);
-
 
979
        if ($new_image === false) {
-
 
980
            error_log("_createImageCanvas: imageCreateTrueColor failed for dimensions {$width}x{$height}.");
-
 
981
            return false;
-
 
982
        }
-
 
983
        imageAlphaBlending($new_image, False);
-
 
984
        imageSaveAlpha($new_image, True);
-
 
985
        $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
-
 
986
        if ($transparent === false) {
-
 
987
            error_log("_createImageCanvas: imageColorAllocateAlpha failed.");
-
 
988
            imagedestroy($new_image);
-
 
989
            return false;
-
 
990
        }
-
 
991
        imagefill($new_image, 0, 0, $transparent);
-
 
992
        return $new_image;
-
 
993
    }
-
 
994
 
-
 
995
    /**
-
 
996
     * Saves a GD image resource as PNG, unlinks source, and cleans up image resource.
-
 
997
     * @param \GdImage $imageResource The GD image resource to save.
-
 
998
     * @param string $targetFilename The path to save the PNG file to.
-
 
999
     * @param string $sourceFilenameToUnlink The path to the source file to unlink.
-
 
1000
     * @return bool True on success, false on failure.
-
 
1001
     */
-
 
1002
    private function _savePngAndCleanup($imageResource, $targetFilename, $sourceFilenameToUnlink)
-
 
1003
    {
-
 
1004
        $save_success = imagepng($imageResource, $targetFilename);
-
 
1005
        imagedestroy($imageResource); // Clean up the image resource
-
 
1006
 
-
 
1007
        if ($save_success) {
-
 
1008
            if ($sourceFilenameToUnlink && file_exists($sourceFilenameToUnlink)) {
-
 
1009
                unlink($sourceFilenameToUnlink);
-
 
1010
            }
-
 
1011
            return true;
-
 
1012
        } else {
-
 
1013
            error_log("_savePngAndCleanup: imagepng failed to save image to {$targetFilename}.");
-
 
1014
            return false;
-
 
1015
        }
-
 
1016
    }
-
 
1017
 
-
 
1018
    /**
-
 
1019
     * @param string $source_filename
-
 
1020
     * @param string $target_filename
-
 
1021
     * @param int $target_width
-
 
1022
     * @param int $target_height
-
 
1023
     * @return boolean
-
 
1024
     */
-
 
1025
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
-
 
1026
    {
-
 
1027
        try {
-
 
1028
            $data = file_get_contents($source_filename);
-
 
1029
            $img = imagecreatefromstring($data);
-
 
1030
 
-
 
1031
            if ($img) {
-
 
1032
                list($source_width, $source_height) = getimagesize($source_filename);
-
 
1033
 
-
 
1034
                $width_ratio = $target_width / $source_width;
-
 
1035
                $height_ratio = $target_height / $source_height;
-
 
1036
 
-
 
1037
                if ($width_ratio > $height_ratio) {
-
 
1038
                    $resized_width = $target_width;
-
 
1039
                    $resized_height = $source_height * $width_ratio;
-
 
1040
                } else {
-
 
1041
                    $resized_height = $target_height;
-
 
1042
                    $resized_width = $source_width * $height_ratio;
-
 
1043
                }
-
 
1044
 
-
 
1045
                $resized_width = round($resized_width);
-
 
1046
                $resized_height = round($resized_height);
-
 
1047
 
-
 
1048
                $new_image = $this->_createImageCanvas($target_width, $target_height);
-
 
1049
                if ($new_image === false) {
-
 
1050
                    imagedestroy($img);
-
 
1051
                    unlink($source_filename);
-
 
1052
                    return false;
-
 
1053
                }
-
 
1054
 
-
 
1055
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
-
 
1056
                imagedestroy($img);
-
 
1057
 
-
 
1058
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
-
 
1059
            }
-
 
1060
 
-
 
1061
            unlink($source_filename);
-
 
1062
            return false;
-
 
1063
        } catch (\Throwable $e) {
-
 
1064
            error_log($e->getTraceAsString());
-
 
1065
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
-
 
1066
                imagedestroy($img);
-
 
1067
            }
-
 
1068
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
-
 
1069
                imagedestroy($new_image);
-
 
1070
            }
-
 
1071
            if (isset($source_filename) && file_exists($source_filename)) {
-
 
1072
                unlink($source_filename);
-
 
1073
            }
-
 
1074
            return false;
-
 
1075
        }
-
 
1076
    }
-
 
1077
 
-
 
1078
    /**
-
 
1079
     * @param string $source_filename
-
 
1080
     * @param string $target_filename
-
 
1081
     * @param int $target_width
-
 
1082
     * @param int $target_height
-
 
1083
     * @return boolean
-
 
1084
     */
-
 
1085
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
-
 
1086
    {
-
 
1087
        try {
-
 
1088
            $data = file_get_contents($source_filename);
-
 
1089
            $img = imagecreatefromstring($data);
-
 
1090
 
-
 
1091
            if ($img) {
-
 
1092
                list($source_width, $source_height) = getimagesize($source_filename);
-
 
1093
 
-
 
1094
                $width_ratio = $target_width / $source_width;
-
 
1095
                $height_ratio = $target_height / $source_height;
-
 
1096
                if ($width_ratio > $height_ratio) {
-
 
1097
                    $resized_width = $target_width;
-
 
1098
                    $resized_height = $source_height * $width_ratio;
-
 
1099
                } else {
-
 
1100
                    $resized_height = $target_height;
-
 
1101
                    $resized_width = $source_width * $height_ratio;
-
 
1102
                }
-
 
1103
 
-
 
1104
                $resized_width = round($resized_width);
-
 
1105
                $resized_height = round($resized_height);
-
 
1106
 
-
 
1107
                $offset_width = round(($target_width - $resized_width) / 2);
-
 
1108
                $offset_height = round(($target_height - $resized_height) / 2);
-
 
1109
 
-
 
1110
                $new_image = $this->_createImageCanvas($target_width, $target_height);
-
 
1111
                if ($new_image === false) {
-
 
1112
                    imagedestroy($img);
-
 
1113
                    unlink($source_filename);
-
 
1114
                    return false;
-
 
1115
                }
-
 
1116
 
-
 
1117
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
-
 
1118
                imagedestroy($img);
-
 
1119
 
-
 
1120
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
-
 
1121
            }
-
 
1122
 
-
 
1123
            unlink($source_filename);
-
 
1124
            return false;
-
 
1125
        } catch (\Throwable $e) {
-
 
1126
            error_log($e->getTraceAsString());
-
 
1127
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
-
 
1128
                imagedestroy($img);
-
 
1129
            }
-
 
1130
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
-
 
1131
                imagedestroy($new_image);
-
 
1132
            }
-
 
1133
            if (isset($source_filename) && file_exists($source_filename)) {
-
 
1134
                unlink($source_filename);
-
 
1135
            }
-
 
1136
            return false;
-
 
1137
        }
-
 
1138
    }
-
 
1139
 
-
 
1140
    /**
-
 
1141
     * @param string $source_filename
-
 
1142
     * @param string $target_filename
-
 
1143
     * @return boolean
-
 
1144
     */
-
 
1145
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
-
 
1146
    {
-
 
1147
        try {
-
 
1148
            $data = file_get_contents($source_filename);
-
 
1149
            $img = imagecreatefromstring($data);
-
 
1150
 
-
 
1151
            if ($img) {
-
 
1152
                list($source_width, $source_height) = getimagesize($source_filename);
-
 
1153
 
-
 
1154
                $new_image = $this->_createImageCanvas($source_width, $source_height);
-
 
1155
                if ($new_image === false) {
-
 
1156
                    imagedestroy($img);
-
 
1157
                    unlink($source_filename);
-
 
1158
                    return false;
-
 
1159
                }
-
 
1160
 
-
 
1161
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
-
 
1162
                imagedestroy($img);
-
 
1163
 
-
 
1164
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
-
 
1165
            }
-
 
1166
 
-
 
1167
            unlink($source_filename);
-
 
1168
            return false;
-
 
1169
        } catch (\Throwable $e) {
-
 
1170
            error_log($e->getTraceAsString());
-
 
1171
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
-
 
1172
                imagedestroy($img);
-
 
1173
            }
-
 
1174
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
-
 
1175
                imagedestroy($new_image);
-
 
1176
            }
-
 
1177
            if (isset($source_filename) && file_exists($source_filename)) {
-
 
1178
                unlink($source_filename);
-
 
1179
            }
-
 
1180
            return false;
-
 
1181
        }
-
 
1182
    }
-
 
1183
 
-
 
1184
    /**
-
 
1185
     * @param string $source_filename
-
 
1186
     * @param string $target_filename
-
 
1187
     * @return boolean
-
 
1188
     */
-
 
1189
    public static function extractPosterFromVideo($source_filename, $target_filename)
-
 
1190
    {
-
 
1191
        try {
-
 
1192
            $cmd = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $source_filename";
-
 
1193
            $response = trim(shell_exec($cmd));
-
 
1194
 
-
 
1195
            $source_duration = 0;
-
 
1196
            $lines = explode("\n", $response);
-
 
1197
            foreach ($lines as $line) {
-
 
1198
                $line = trim(strtolower($line));
-
 
1199
                if (strpos($line, 'duration') !== false) {
-
 
1200
                    $values = explode('=', $line);
-
 
1201
                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
-
 
1202
                }
-
 
1203
            }
-
 
1204
 
-
 
1205
            if ($source_duration == 0) {
-
 
1206
                $second_extract = '00:00:02';
-
 
1207
            } else {
-
 
1208
                if ($source_duration > 10) {
-
 
1209
                    $second_extract = '00:00:10';
-
 
1210
                } else {
-
 
1211
                    $second_extract = '00:00:02';
-
 
1212
                }
-
 
1213
            }
-
 
1214
 
-
 
1215
            $cmd = "/usr/bin/ffmpeg -y -i $source_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $target_filename";
-
 
1216
            exec($cmd);
-
 
1217
 
-
 
1218
            return true;
-
 
1219
        } catch (\Throwable $e) {
-
 
1220
            error_log($e->getTraceAsString());
-
 
1221
            return false;
-
 
1222
        }
-
 
1223
    }
-
 
1224
 
-
 
1225
    /**
-
 
1226
     * @param string $str
-
 
1227
     * @return string
-
 
1228
     */
-
 
1229
    public function normalizeStringFilename($str = '')
-
 
1230
    {
-
 
1231
        $basename = substr($str, 0, strrpos($str, '.'));
-
 
1232
        $basename = str_replace('.', '-', $basename);
-
 
1233
 
-
 
1234
        $extension = substr($str, strrpos($str, '.'));
-
 
1235
 
-
 
1236
        $str = $basename . $extension;
-
 
1237
 
-
 
1238
        $str = strip_tags($str);
-
 
1239
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
-
 
1240
        $str = preg_replace('/[\#\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
-
 
1241
        $str = strtolower($str);
-
 
1242
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
-
 
1243
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
-
 
1244
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
-
 
1245
        $str = str_replace(' ', '-', $str);
-
 
1246
        $str = rawurlencode($str);
-
 
1247
        $str = str_replace('%', '-', $str);
-
 
1248
        $str = str_replace([
-
 
1249
            '-----',
-
 
1250
            '----',
-
 
1251
            '---',
-
 
1252
            '--'
-
 
1253
        ], '-', $str);
-
 
1254
        return trim(strtolower($str));
-
 
1255
    }