Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17042 | Rev 17045 | 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
    {
17042 ariadna 292
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
293
 
294
 
295
        if (file_exists($remoto)) {
17018 efrain 296
            return $this->getPresignedUrl($remoto);
17002 efrain 297
        } else {
298
            $remoto = $this->config['leaderslinked.images_default.no_image'];
17018 efrain 299
            return $this->getPresignedUrl($remoto);
17002 efrain 300
        }
301
    }
17042 ariadna 302
 
303
 
304
 
305
 
17002 efrain 306
    /**
307
     *
17008 efrain 308
     * @param string $path
17018 efrain 309
     * @param string $code,
17008 efrain 310
     * @param string $filename
17018 efrain 311
     * @param boolean $checkExists
17002 efrain 312
     * @return string
313
     */
17018 efrain 314
    public function getFileFromDisk($path, $code, $filename)
17002 efrain 315
    {
17042 ariadna 316
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
317
 
318
        if (file_exists($current_file)) {
17018 efrain 319
            return $current_file;
17042 ariadna 320
        }
17018 efrain 321
        return;
322
    }
17042 ariadna 323
 
324
 
17018 efrain 325
    /**
326
     *
327
     * @param string $path
328
     * @param string $code,
329
     * @return string
330
     */
331
    public function getDirectoryFromDisk($path, $code)
332
    {
17042 ariadna 333
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code;
334
 
335
        if (file_exists($directory)) {
17018 efrain 336
            return $directory;
337
        }
338
        return;
339
    }
17042 ariadna 340
 
17018 efrain 341
    /**
342
     *
343
     * @param string $path
344
     * @param string $code,
345
     * @param string $filename
346
     * @param boolean $checkExists
347
     * @return string
348
     */
349
    public function getGenericFile($path, $code, $filename, $checkExists = true)
350
    {
17042 ariadna 351
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
17018 efrain 352
 
17042 ariadna 353
 
354
        if ($checkExists) {
355
            if (file_exists($remoto)) {
17018 efrain 356
                return $this->getPresignedUrl($remoto);
357
            } else {
358
                return;
17042 ariadna 359
            }
360
        }
17018 efrain 361
        return $this->getPresignedUrl($remoto);
362
    }
17042 ariadna 363
 
17018 efrain 364
    public function getPathByType($type)
365
    {
17042 ariadna 366
        switch ($type) {
17044 ariadna 367
            case self::TYPE_DEFAULT:
368
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'default';
369
                break;
17042 ariadna 370
 
17044 ariadna 371
            case self::TYPE_CHAT:
372
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'chat';
373
                break;
17042 ariadna 374
 
17044 ariadna 375
            case self::TYPE_GROUP:
376
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'group';
377
                break;
17042 ariadna 378
 
17044 ariadna 379
            case self::TYPE_USER:
380
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'user';
381
                break;
17042 ariadna 382
 
17044 ariadna 383
            case self::TYPE_IMAGE:
384
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'image';
385
                break;
17042 ariadna 386
 
17044 ariadna 387
            case self::TYPE_JOB:
388
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job';
389
                break;
17042 ariadna 390
 
17044 ariadna 391
            case self::TYPE_COMPANY:
392
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'company';
393
                break;
17042 ariadna 394
 
17044 ariadna 395
            case self::TYPE_FEED:
396
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'feed';
397
                break;
17042 ariadna 398
 
17044 ariadna 399
            case self::TYPE_MEDIA:
400
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'media';
401
                break;
17042 ariadna 402
 
17044 ariadna 403
            case self::TYPE_POST:
404
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'post';
405
                break;
17042 ariadna 406
 
17044 ariadna 407
            case self::TYPE_MICROLEARNING_TOPIC:
408
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'topic';
409
                break;
17042 ariadna 410
 
17044 ariadna 411
            case self::TYPE_MICROLEARNING_CAPSULE:
412
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'capsule';
413
                break;
17042 ariadna 414
 
17044 ariadna 415
            case self::TYPE_MICROLEARNING_SLIDE:
416
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'slide';
417
                break;
17042 ariadna 418
 
17044 ariadna 419
            case self::TYPE_JOB_DESCRIPTION:
420
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job-description';
421
                break;
17042 ariadna 422
 
17044 ariadna 423
            case self::TYPE_SELF_EVALUATION:
424
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'self-evaluation';
425
                break;
17042 ariadna 426
 
17044 ariadna 427
            case self::TYPE_PERFORMANCE_EVALUATION:
428
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'performance-evaluation';
429
                break;
17042 ariadna 430
 
17044 ariadna 431
            case self::TYPE_RECRUITMENT_SELECTION:
432
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'recruitment-selection';
433
                break;
17042 ariadna 434
 
17044 ariadna 435
            case self::TYPE_PLANNING_OBJECTIVES_AND_GOALS:
436
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'planning-objectives-and-goals';
437
                break;
17042 ariadna 438
 
17044 ariadna 439
            case self::TYPE_MESSAGE:
440
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'message';
441
                break;
17042 ariadna 442
 
17044 ariadna 443
            case self::TYPE_SURVEY:
444
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'survey';
445
                break;
17042 ariadna 446
 
17044 ariadna 447
            case self::TYPE_NETWORK:
448
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'network';
449
                break;
17042 ariadna 450
 
17044 ariadna 451
            case self::TYPE_DAILY_PULSE:
452
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'daily-pulse';
453
                break;
17042 ariadna 454
 
17044 ariadna 455
            case self::TYPE_ENGAGEMENT_REWARD:
456
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'engagement-reward';
457
                break;
17042 ariadna 458
 
17044 ariadna 459
            case self::TYPE_KNOWLEDGE_AREA:
460
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'knowledge-area';
461
                break;
17042 ariadna 462
 
17044 ariadna 463
            case self::TYPE_MY_COACH:
464
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'my-coach';
465
                break;
17042 ariadna 466
 
17044 ariadna 467
            case self::TYPE_HABIT_EMOJI:
468
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'habit' . DIRECTORY_SEPARATOR . 'emoji';
469
                break;
17042 ariadna 470
 
17044 ariadna 471
            case self::TYPE_HABIT_CONTENT:
472
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'habit' . DIRECTORY_SEPARATOR . 'content';
473
                break;
474
 
17042 ariadna 475
            default:
17044 ariadna 476
                $path = $this->storagePath;
477
                break;
17018 efrain 478
        }
17044 ariadna 479
 
480
        if (! file_exists($path)) {
481
            mkdir($path, 0775, true);
482
        }
483
 
484
        return $path;
17018 efrain 485
    }
17042 ariadna 486
 
17018 efrain 487
    /**
488
     *
489
     * @param Group $group
490
     * @return string
491
     */
492
    public function getGenericImageByType($type, $code, $filename)
493
    {
494
        $path = $this->getPathByType($type);
17042 ariadna 495
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
17018 efrain 496
 
17042 ariadna 497
        if (file_exists($remoto)) {
17018 efrain 498
            return $this->getPresignedUrl($remoto);
17002 efrain 499
        } else {
17018 efrain 500
            $remoto = $this->config['leaderslinked.images_default.no_image'];
501
            return $this->getPresignedUrl($remoto);
17002 efrain 502
        }
503
    }
17042 ariadna 504
 
17018 efrain 505
    /**
506
     *
507
     * @param string $type
508
     * @param string $code,
509
     * @param string $filename
510
     * @param boolean $checkExists
511
     * @return string
512
     */
513
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
514
    {
515
        $path = $this->getPathByType($type);
17042 ariadna 516
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
17018 efrain 517
 
17042 ariadna 518
        if ($checkExists) {
519
            if (file_exists($remoto)) {
17018 efrain 520
                return $this->getPresignedUrl($remoto);
521
            } else {
522
                return;
523
            }
524
        }
525
        return $this->getPresignedUrl($remoto);
526
    }
17042 ariadna 527
 
17002 efrain 528
    /**
529
     *
17008 efrain 530
     * @param string $path
531
     * @param string $code
532
     * @param string $filename
17002 efrain 533
     * @return string
534
     */
17008 efrain 535
    public function delete($path, $code, $filename)
536
    {
17042 ariadna 537
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
17018 efrain 538
        return @unlink($remoto);
17042 ariadna 539
    }
17018 efrain 540
 
17042 ariadna 541
 
542
 
17008 efrain 543
    /**
544
     *
545
     * @return string
546
     */
17002 efrain 547
    public function getPathMedia()
548
    {
17018 efrain 549
        return $this->config['leaderslinked.storage.fullpath_media'];
17002 efrain 550
    }
17042 ariadna 551
 
552
 
17002 efrain 553
    /**
17018 efrain 554
     *
555
     * @return string
556
     */
557
    public function getPathHabitEmoji()
558
    {
559
        return $this->config['leaderslinked.storage.fullpath_habit_emoji'];
560
    }
17042 ariadna 561
 
17018 efrain 562
    /**
563
     *
564
     * @return string
565
     */
566
    public function getPathHabitContent()
567
    {
568
        return $this->config['leaderslinked.storage.fullpath_habit_content'];
569
    }
570
 
17042 ariadna 571
 
17018 efrain 572
    /**
17002 efrain 573
     *
574
     * @return string
575
     */
576
    public function getPathGroup()
577
    {
17018 efrain 578
        return $this->config['leaderslinked.storage.fullpath_group'];
17002 efrain 579
    }
17042 ariadna 580
 
17002 efrain 581
    /**
582
     *
583
     * @return string
584
     */
585
    public function getPathUser()
586
    {
17018 efrain 587
        return $this->config['leaderslinked.storage.fullpath_user'];
17002 efrain 588
    }
17042 ariadna 589
 
17002 efrain 590
    /**
591
     *
592
     * @return string
593
     */
594
    public function getPathImage()
595
    {
17018 efrain 596
        return $this->config['leaderslinked.storage.fullpath_image'];
17002 efrain 597
    }
17042 ariadna 598
 
17002 efrain 599
    /**
600
     *
601
     * @return string
602
     */
603
    public function getPathJob()
604
    {
17018 efrain 605
        return $this->config['leaderslinked.storage.fullpath_job'];
17002 efrain 606
    }
17042 ariadna 607
 
17002 efrain 608
    /**
609
     *
610
     * @return string
611
     */
17018 efrain 612
    public function getPathChat()
613
    {
614
        return $this->config['leaderslinked.storage.fullpath_chat'];
615
    }
17042 ariadna 616
 
17018 efrain 617
    /**
618
     *
619
     * @return string
620
     */
17002 efrain 621
    public function getPathCompany()
622
    {
17018 efrain 623
        return $this->config['leaderslinked.storage.fullpath_company'];
17002 efrain 624
    }
17042 ariadna 625
 
17002 efrain 626
    /**
627
     *
628
     * @return string
629
     */
630
    public function getPathFeed()
631
    {
17018 efrain 632
        return $this->config['leaderslinked.storage.fullpath_feed'];
17002 efrain 633
    }
17042 ariadna 634
 
635
 
636
 
17002 efrain 637
    /**
638
     *
639
     * @return string
640
     */
17018 efrain 641
    public function getPathMessage()
642
    {
643
        return $this->config['leaderslinked.storage.fullpath_message'];
644
    }
17042 ariadna 645
 
17018 efrain 646
    /**
647
     *
648
     * @return string
649
     */
17002 efrain 650
    public function getPathPost()
651
    {
17018 efrain 652
        return $this->config['leaderslinked.storage.fullpath_post'];
17002 efrain 653
    }
17042 ariadna 654
 
17002 efrain 655
    /**
656
     *
657
     * @return string
658
     */
659
    public function getPathMicrolearningTopic()
660
    {
17018 efrain 661
        return $this->config['leaderslinked.storage.fullpath_microlearning_topic'];
17002 efrain 662
    }
17042 ariadna 663
 
17002 efrain 664
    /**
665
     *
666
     * @return string
667
     */
668
    public function getPathMicrolearningCapsule()
669
    {
17018 efrain 670
        return $this->config['leaderslinked.storage.fullpath_microlearning_capsule'];
17002 efrain 671
    }
17042 ariadna 672
 
17002 efrain 673
    /**
674
     *
675
     * @return string
676
     */
677
    public function getPathMicrolearningSlide()
678
    {
17018 efrain 679
        return $this->config['leaderslinked.storage.fullpath_microlearning_slide'];
17002 efrain 680
    }
17042 ariadna 681
 
17002 efrain 682
    /**
683
     *
684
     * @return string
685
     */
686
    public function getPathJobDescription()
687
    {
17018 efrain 688
        return $this->config['leaderslinked.storage.fullpath_job_description'];
17002 efrain 689
    }
17042 ariadna 690
 
17002 efrain 691
    /**
692
     *
693
     * @return string
694
     */
17018 efrain 695
    public function getPathSelfEvaluation()
17002 efrain 696
    {
17018 efrain 697
        return $this->config['leaderslinked.storage.fullpath_self_evaluation'];
17002 efrain 698
    }
17042 ariadna 699
 
17002 efrain 700
    /**
701
     *
702
     * @return string
703
     */
704
    public function getPathRecruitmentSelection()
705
    {
17018 efrain 706
        return $this->config['leaderslinked.storage.fullpath_recruitment_selection'];
17002 efrain 707
    }
17042 ariadna 708
 
17002 efrain 709
    /**
710
     *
711
     * @return string
712
     */
713
    public function getPathPerformanceEvaluation()
714
    {
17018 efrain 715
        return $this->config['leaderslinked.storage.fullpath_performance_evaluation'];
17002 efrain 716
    }
17042 ariadna 717
 
17002 efrain 718
    /**
719
     *
720
     * @return string
721
     */
722
    public function getPathPlanningObjectivesAnGoals()
723
    {
17018 efrain 724
        return $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'];
17002 efrain 725
    }
17042 ariadna 726
 
17002 efrain 727
    /**
728
     *
729
     * @return string
730
     */
731
    public function getPathSurvey()
732
    {
17018 efrain 733
        return $this->config['leaderslinked.storage.fullpath_survey'];
17002 efrain 734
    }
17042 ariadna 735
 
17002 efrain 736
    /**
737
     *
738
     * @return string
739
     */
740
    public function getPathNetwork()
741
    {
17018 efrain 742
        return $this->config['leaderslinked.storage.fullpath_network'];
17002 efrain 743
    }
17042 ariadna 744
 
17002 efrain 745
    /**
746
     *
747
     * @return string
748
     */
749
    public function getPathEngagementReward()
750
    {
17018 efrain 751
        return $this->config['leaderslinked.storage.fullpath_engagement_reward'];
17002 efrain 752
    }
17042 ariadna 753
 
17002 efrain 754
    public function getPathDailyPulse()
755
    {
17044 ariadna 756
        return $this->getPathByType(self::TYPE_DAILY_PULSE);
17002 efrain 757
    }
17042 ariadna 758
 
17002 efrain 759
    /**
760
     *
761
     * @return string
762
     */
763
    public function getPathKnowledgeArea()
764
    {
17018 efrain 765
        return $this->config['leaderslinked.storage.fullpath_knowledge_area'];
17002 efrain 766
    }
17042 ariadna 767
 
17002 efrain 768
    /**
769
     *
770
     * @return string
771
     */
772
    public function getPathMyCoach()
773
    {
17018 efrain 774
        return $this->config['leaderslinked.storage.fullpath_my_coach'];
17002 efrain 775
    }
17042 ariadna 776
 
17002 efrain 777
    /**
778
     *
779
     * @param String $filename
780
     * return boolean
781
     */
17042 ariadna 782
    public function objectExist($filename)
17002 efrain 783
    {
17018 efrain 784
        return file_exists($filename);
17002 efrain 785
    }
17042 ariadna 786
 
17002 efrain 787
    /**
788
     *
17018 efrain 789
     * @param string $remote
17002 efrain 790
     * @param string $local
791
     * @return boolean
792
     */
793
    public function putObject($remote, $local)
794
    {
17042 ariadna 795
 
17018 efrain 796
        $dir = dirname($remote);
17042 ariadna 797
        if (!file_exists($dir)) {
17018 efrain 798
            @mkdir($dir, 0755, true);
799
        }
17042 ariadna 800
 
17018 efrain 801
        return @rename($local, $remote);
17002 efrain 802
    }
17042 ariadna 803
 
804
 
17002 efrain 805
    /**
806
     *
807
     * @param string $filename
808
 
809
     * @return boolean
810
     */
811
    public function deleteObject($filename)
812
    {
17018 efrain 813
        return @unlink($filename);
17002 efrain 814
    }
17042 ariadna 815
 
816
 
17002 efrain 817
    /**
818
     *
819
     * @param string $path
820
     * @param string $code
821
     * @param string $filename
822
     * @return boolean
823
     */
824
    public function deleteFile($path, $code, $filename)
825
    {
17042 ariadna 826
        if ($code) {
827
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
17002 efrain 828
        } else {
17018 efrain 829
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
17002 efrain 830
        }
17042 ariadna 831
        if (file_exists($remoto)) {
17018 efrain 832
            return @unlink($remoto);
17002 efrain 833
        } else {
834
            return true;
835
        }
836
    }
17042 ariadna 837
 
17002 efrain 838
    /**
839
     *
840
     * @param string $path
841
     * @param string $code
842
     * @return boolean
843
     */
17018 efrain 844
    public function deleteDirectory($path, $code)
17002 efrain 845
    {
17018 efrain 846
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
17042 ariadna 847
        if (file_exists($remoto)) {
17018 efrain 848
            $this->deleteDirectoryRecursive($remoto);
849
            return true;
850
        } else {
851
            return true;
852
        }
853
    }
17042 ariadna 854
 
17018 efrain 855
    /**
856
     *
857
     * @param string $dir
858
     */
17042 ariadna 859
    private function deleteDirectoryRecursive($dir)
860
    {
17018 efrain 861
        if (is_dir($dir)) {
862
            $objects = scandir($dir);
863
            foreach ($objects as $object) {
17042 ariadna 864
                if ($object != '' . '' && $object != '..') {
865
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . '/' . $object)) {
866
                        @rmdir($dir . DIRECTORY_SEPARATOR . $object);
867
                    } else {
868
                        @unlink($dir . DIRECTORY_SEPARATOR . $object);
17018 efrain 869
                    }
870
                }
871
            }
872
            @rmdir($dir);
873
        }
874
    }
875
 
876
 
17042 ariadna 877
 
17018 efrain 878
    /**
879
     *
880
     * @param string $path
881
     * @param string $code
882
     * @param string $local_filename
883
     * @return boolean
884
     */
885
    public function putFile($path, $code, $local_filename)
886
    {
17042 ariadna 887
        if ($code) {
17018 efrain 888
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
17002 efrain 889
        } else {
17018 efrain 890
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
17002 efrain 891
        }
17018 efrain 892
 
893
        $dir = dirname($remote);
17042 ariadna 894
        if (!file_exists($dir)) {
17018 efrain 895
            @mkdir($dir, 0755, true);
896
        }
17002 efrain 897
 
17042 ariadna 898
 
17018 efrain 899
        return @rename($local_filename, $remote);
17042 ariadna 900
    }
17018 efrain 901
 
17042 ariadna 902
 
17002 efrain 903
    /**
904
     *
17018 efrain 905
     * @param string $tempfile
17002 efrain 906
     * @param string $path
907
     * @param string $code
908
     * @param string $filename
909
     * @return boolean
910
     */
17018 efrain 911
    public function moveAndPutFile($tempfile, $path, $code, $filename)
17002 efrain 912
    {
17042 ariadna 913
        if ($code) {
17018 efrain 914
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
17002 efrain 915
        } else {
17018 efrain 916
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
17002 efrain 917
        }
17018 efrain 918
 
17042 ariadna 919
 
17018 efrain 920
        $dir = dirname($target_file);
17042 ariadna 921
        if (!file_exists($dir)) {
17018 efrain 922
            @mkdir($dir, 0755, true);
923
        }
17042 ariadna 924
 
17018 efrain 925
        return move_uploaded_file($tempfile, $target_file);
926
    }
17042 ariadna 927
 
17018 efrain 928
    /**
929
     *
930
     * @return string
931
     */
932
    public function getStoagePath()
933
    {
934
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
935
    }
17042 ariadna 936
 
17018 efrain 937
    /**
938
     *
939
     * @return string
940
     */
17042 ariadna 941
    public function getTempPath()
942
    {
17018 efrain 943
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
17042 ariadna 944
        if (!file_exists($interal_path)) {
17018 efrain 945
            mkdir($interal_path, 0775);
946
        }
17042 ariadna 947
 
17018 efrain 948
        return $interal_path;
17002 efrain 949
    }
17042 ariadna 950
 
17002 efrain 951
    /**
952
     *
17018 efrain 953
     * @param string $url
17002 efrain 954
     * @return string
955
     */
17018 efrain 956
    public function getPresignedUrl($url)
17002 efrain 957
    {
17018 efrain 958
 
17042 ariadna 959
 
960
 
17018 efrain 961
        $code = hash('sha256', $url);
17042 ariadna 962
 
17018 efrain 963
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
964
        $storageFile = $storageFileMapper->fetchOneByCode($code);
17042 ariadna 965
        if (!$storageFile) {
17018 efrain 966
            $storageFile = new \LeadersLinked\Model\StorageFile();
967
            $storageFile->code = $code;
968
            $storageFile->path = $url;
969
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
17042 ariadna 970
 
971
 
972
 
17018 efrain 973
            $storageFileMapper->insert($storageFile);
974
        }
17042 ariadna 975
 
17018 efrain 976
        /*
977
        $hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
978
 
979
        if(empty($hostname)) {
980
 
981
            $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
982
 
983
            if(empty($hostname)) {
984
                $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
985
 
986
            }
987
        }
988
 
989
        print_r($_SERVER);
990
 
991
 
992
        $hostname = trim(str_replace('http://', 'https://', $hostname));
993
        */
17042 ariadna 994
 
995
 
996
 
997
 
998
 
999
 
1000
 
1001
 
17018 efrain 1002
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
17002 efrain 1003
    }
17042 ariadna 1004
 
1005
    /**
1006
     * Creates a new GD image resource with transparency settings for PNG.
1007
     * @param int $width The width of the new image.
1008
     * @param int $height The height of the new image.
1009
     * @return \GdImage|false The image resource or false on failure.
1010
     */
1011
    private function _createImageCanvas($width, $height)
1012
    {
1013
        $new_image = imageCreateTrueColor($width, $height);
1014
        if ($new_image === false) {
1015
            error_log("_createImageCanvas: imageCreateTrueColor failed for dimensions {$width}x{$height}.");
1016
            return false;
1017
        }
1018
        imageAlphaBlending($new_image, False);
1019
        imageSaveAlpha($new_image, True);
1020
        $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1021
        if ($transparent === false) {
1022
            error_log("_createImageCanvas: imageColorAllocateAlpha failed.");
1023
            imagedestroy($new_image);
1024
            return false;
1025
        }
1026
        imagefill($new_image, 0, 0, $transparent);
1027
        return $new_image;
1028
    }
1029
 
1030
    /**
1031
     * Saves a GD image resource as PNG, unlinks source, and cleans up image resource.
1032
     * @param \GdImage $imageResource The GD image resource to save.
1033
     * @param string $targetFilename The path to save the PNG file to.
1034
     * @param string $sourceFilenameToUnlink The path to the source file to unlink.
1035
     * @return bool True on success, false on failure.
1036
     */
1037
    private function _savePngAndCleanup($imageResource, $targetFilename, $sourceFilenameToUnlink)
1038
    {
1039
        $save_success = imagepng($imageResource, $targetFilename);
1040
        imagedestroy($imageResource); // Clean up the image resource
1041
 
1042
        if ($save_success) {
1043
            if ($sourceFilenameToUnlink && file_exists($sourceFilenameToUnlink)) {
1044
                unlink($sourceFilenameToUnlink);
1045
            }
1046
            return true;
1047
        } else {
1048
            error_log("_savePngAndCleanup: imagepng failed to save image to {$targetFilename}.");
1049
            return false;
1050
        }
1051
    }
1052
 
1053
    /**
1054
     * @param string $source_filename
1055
     * @param string $target_filename
1056
     * @param int $target_width
1057
     * @param int $target_height
1058
     * @return boolean
1059
     */
1060
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1061
    {
1062
        try {
1063
            $data = file_get_contents($source_filename);
1064
            $img = imagecreatefromstring($data);
1065
 
1066
            if ($img) {
1067
                list($source_width, $source_height) = getimagesize($source_filename);
1068
 
1069
                $width_ratio = $target_width / $source_width;
1070
                $height_ratio = $target_height / $source_height;
1071
 
1072
                if ($width_ratio > $height_ratio) {
1073
                    $resized_width = $target_width;
1074
                    $resized_height = $source_height * $width_ratio;
1075
                } else {
1076
                    $resized_height = $target_height;
1077
                    $resized_width = $source_width * $height_ratio;
1078
                }
1079
 
1080
                $resized_width = round($resized_width);
1081
                $resized_height = round($resized_height);
1082
 
1083
                $new_image = $this->_createImageCanvas($target_width, $target_height);
1084
                if ($new_image === false) {
1085
                    imagedestroy($img);
1086
                    unlink($source_filename);
1087
                    return false;
1088
                }
1089
 
1090
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1091
                imagedestroy($img);
1092
 
1093
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
1094
            }
1095
 
1096
            unlink($source_filename);
1097
            return false;
1098
        } catch (\Throwable $e) {
1099
            error_log($e->getTraceAsString());
1100
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1101
                imagedestroy($img);
1102
            }
1103
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1104
                imagedestroy($new_image);
1105
            }
1106
            if (isset($source_filename) && file_exists($source_filename)) {
1107
                unlink($source_filename);
1108
            }
1109
            return false;
1110
        }
1111
    }
1112
 
1113
    /**
1114
     * @param string $source_filename
1115
     * @param string $target_filename
1116
     * @param int $target_width
1117
     * @param int $target_height
1118
     * @return boolean
1119
     */
1120
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
1121
    {
1122
        try {
1123
            $data = file_get_contents($source_filename);
1124
            $img = imagecreatefromstring($data);
1125
 
1126
            if ($img) {
1127
                list($source_width, $source_height) = getimagesize($source_filename);
1128
 
1129
                $width_ratio = $target_width / $source_width;
1130
                $height_ratio = $target_height / $source_height;
1131
                if ($width_ratio > $height_ratio) {
1132
                    $resized_width = $target_width;
1133
                    $resized_height = $source_height * $width_ratio;
1134
                } else {
1135
                    $resized_height = $target_height;
1136
                    $resized_width = $source_width * $height_ratio;
1137
                }
1138
 
1139
                $resized_width = round($resized_width);
1140
                $resized_height = round($resized_height);
1141
 
1142
                $offset_width = round(($target_width - $resized_width) / 2);
1143
                $offset_height = round(($target_height - $resized_height) / 2);
1144
 
1145
                $new_image = $this->_createImageCanvas($target_width, $target_height);
1146
                if ($new_image === false) {
1147
                    imagedestroy($img);
1148
                    unlink($source_filename);
1149
                    return false;
1150
                }
1151
 
1152
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1153
                imagedestroy($img);
1154
 
1155
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
1156
            }
1157
 
1158
            unlink($source_filename);
1159
            return false;
1160
        } catch (\Throwable $e) {
1161
            error_log($e->getTraceAsString());
1162
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1163
                imagedestroy($img);
1164
            }
1165
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1166
                imagedestroy($new_image);
1167
            }
1168
            if (isset($source_filename) && file_exists($source_filename)) {
1169
                unlink($source_filename);
1170
            }
1171
            return false;
1172
        }
1173
    }
1174
 
1175
    /**
1176
     * @param string $source_filename
1177
     * @param string $target_filename
1178
     * @return boolean
1179
     */
1180
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
1181
    {
1182
        try {
1183
            $data = file_get_contents($source_filename);
1184
            $img = imagecreatefromstring($data);
1185
 
1186
            if ($img) {
1187
                list($source_width, $source_height) = getimagesize($source_filename);
1188
 
1189
                $new_image = $this->_createImageCanvas($source_width, $source_height);
1190
                if ($new_image === false) {
1191
                    imagedestroy($img);
1192
                    unlink($source_filename);
1193
                    return false;
1194
                }
1195
 
1196
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
1197
                imagedestroy($img);
1198
 
1199
                return $this->_savePngAndCleanup($new_image, $target_filename, $source_filename);
1200
            }
1201
 
1202
            unlink($source_filename);
1203
            return false;
1204
        } catch (\Throwable $e) {
1205
            error_log($e->getTraceAsString());
1206
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1207
                imagedestroy($img);
1208
            }
1209
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1210
                imagedestroy($new_image);
1211
            }
1212
            if (isset($source_filename) && file_exists($source_filename)) {
1213
                unlink($source_filename);
1214
            }
1215
            return false;
1216
        }
1217
    }
1218
 
1219
    /**
1220
     * @param string $source_filename
1221
     * @param string $target_filename
1222
     * @return boolean
1223
     */
1224
    public static function extractPosterFromVideo($source_filename, $target_filename)
1225
    {
1226
        try {
1227
            $cmd = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $source_filename";
1228
            $response = trim(shell_exec($cmd));
1229
 
1230
            $source_duration = 0;
1231
            $lines = explode("\n", $response);
1232
            foreach ($lines as $line) {
1233
                $line = trim(strtolower($line));
1234
                if (strpos($line, 'duration') !== false) {
1235
                    $values = explode('=', $line);
1236
                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
1237
                }
1238
            }
1239
 
1240
            if ($source_duration == 0) {
1241
                $second_extract = '00:00:02';
1242
            } else {
1243
                if ($source_duration > 10) {
1244
                    $second_extract = '00:00:10';
1245
                } else {
1246
                    $second_extract = '00:00:02';
1247
                }
1248
            }
1249
 
1250
            $cmd = "/usr/bin/ffmpeg -y -i $source_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $target_filename";
1251
            exec($cmd);
1252
 
1253
            return true;
1254
        } catch (\Throwable $e) {
1255
            error_log($e->getTraceAsString());
1256
            return false;
1257
        }
1258
    }
1259
 
1260
    /**
1261
     * @param string $str
1262
     * @return string
1263
     */
1264
    public function normalizeStringFilename($str = '')
1265
    {
1266
        $basename = substr($str, 0, strrpos($str, '.'));
1267
        $basename = str_replace('.', '-', $basename);
1268
 
1269
        $extension = substr($str, strrpos($str, '.'));
1270
 
1271
        $str = $basename . $extension;
1272
 
1273
        $str = strip_tags($str);
1274
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
1275
        $str = preg_replace('/[\#\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
1276
        $str = strtolower($str);
1277
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
1278
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
1279
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
1280
        $str = str_replace(' ', '-', $str);
1281
        $str = rawurlencode($str);
1282
        $str = str_replace('%', '-', $str);
1283
        $str = str_replace([
1284
            '-----',
1285
            '----',
1286
            '---',
1287
            '--'
1288
        ], '-', $str);
1289
        return trim(strtolower($str));
1290
    }
1291
}