Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17045 | Rev 17048 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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