Proyectos de Subversion LeadersLinked - Backend

Rev

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