Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 346 Rev 546
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
namespace LeadersLinked\Library;
3
namespace LeadersLinked\Library;
Línea 3... Línea 4...
3
 
4
 
4
use LeadersLinked\Model\User;
5
use LeadersLinked\Model\User;
5
use LeadersLinked\Model\UserProfile;
6
use LeadersLinked\Model\UserProfile;
Línea 102... Línea 103...
102
    /**
103
    /**
103
     *
104
     *
104
     * @var array
105
     * @var array
105
     */
106
     */
106
    private $currentFile;
107
    private $currentFile;
107
    
108
 
108
    
109
 
109
    /**
110
    /**
110
     * 
111
     * 
111
     * @var array
112
     * @var array
112
     */
113
     */
113
    private $files;
114
    private $files;
Línea 280... Línea 281...
280
     *
281
     *
281
     * @param array $filename
282
     * @param array $filename
282
     */
283
     */
283
    public function setCurrentFilename($filename)
284
    public function setCurrentFilename($filename)
284
    {
285
    {
285
        if(empty($this->files)) {
286
        if (empty($this->files)) {
286
            if (isset($_FILES[$filename]) && empty($_FILES[$filename]['error'])) {
287
            if (isset($_FILES[$filename]) && empty($_FILES[$filename]['error'])) {
287
                $this->currentFile = $_FILES[$filename];
288
                $this->currentFile = $_FILES[$filename];
288
            } else {
289
            } else {
289
                $this->currentFile = [];
290
                $this->currentFile = [];
290
            }
291
            }
291
        } else {
292
        } else {
292
            if (isset($this->files[$filename]) && empty($this->files[$filename]['error'])) {
293
            if (isset($this->files[$filename]) && empty($this->files[$filename]['error'])) {
293
                $this->currentFile = $this->files[$filename];
294
                $this->currentFile = $this->files[$filename];
294
            } else {
295
            } else {
295
                $this->currentFile = [];
296
                $this->currentFile = [];
296
                
-
 
297
            }
297
            }
298
        }
298
        }
299
        
299
 
300
        return !empty($this->currentFile);
300
        return !empty($this->currentFile);
301
    }
301
    }
302
    
302
 
303
    /**
303
    /**
304
     * 
304
     * 
305
     * @return boolean
305
     * @return boolean
306
     */
306
     */
307
    public function hasFile()
307
    public function hasFile()
308
    {
308
    {
309
        return !empty($this->currentFile);
309
        return !empty($this->currentFile);
310
    }
310
    }
311
    
311
 
312
    /**
312
    /**
313
     * 
313
     * 
314
     * @param array $files
314
     * @param array $files
315
     */
315
     */
316
    public function setFiles($files)
316
    public function setFiles($files)
Línea 485... Línea 485...
485
     * @return string
485
     * @return string
486
     */
486
     */
487
    public function getGroupImage($group)
487
    public function getGroupImage($group)
488
    {
488
    {
489
        if ($group->image) {
489
        if ($group->image) {
490
            $remoto = $this->composePathToFilename(self::TYPE_COMPANY, $group->uuid, $group->image);
490
            $remoto = $this->composePathToFilename(self::TYPE_GROUP, $group->uuid, $group->image);
491
            if (file_exists($remoto)) {
491
            if (file_exists($remoto)) {
492
                return $this->getPresignedUrl($remoto);
492
                return $this->getPresignedUrl($remoto);
493
            }
493
            }
494
        }
494
        }
Línea 540... Línea 540...
540
     * @return string
540
     * @return string
541
     */
541
     */
542
    public function getGenericImage($path, $code, $filename)
542
    public function getGenericImage($path, $code, $filename)
543
    {
543
    {
544
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
544
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
545
        
545
 
546
        
546
 
547
     
547
 
548
        
548
 
Línea 549... Línea 549...
549
 
549
 
550
        if (file_exists($remoto)) {
550
        if (file_exists($remoto)) {
551
            
551
 
552
            if($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
552
            if ($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
553
                
553
 
554
                error_log('getGenericImage = ' . $remoto);
554
                error_log('getGenericImage = ' . $remoto);
555
            }
555
            }
556
            
556
 
557
            return $this->getPresignedUrl($remoto);
557
            return $this->getPresignedUrl($remoto);
Línea 558... Línea 558...
558
        }
558
        }
559
 
559
 
Línea 569... Línea 569...
569
     * @return string
569
     * @return string
570
     */
570
     */
571
    public function getGenericFile($path, $code, $filename)
571
    public function getGenericFile($path, $code, $filename)
572
    {
572
    {
573
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
573
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
574
        
574
 
575
       
575
 
576
        
576
 
577
        if (file_exists($remoto)) {
577
        if (file_exists($remoto)) {
578
            if($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
578
            if ($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
579
                
579
 
580
                error_log('getGenericFile = ' . $remoto);
580
                error_log('getGenericFile = ' . $remoto);
581
            }
581
            }
582
            
582
 
583
            
583
 
584
            return $this->getPresignedUrl($remoto);
584
            return $this->getPresignedUrl($remoto);
585
        }
585
        }
586
        return;
586
        return;
587
    }
587
    }
588
    
588
 
589
    public function getPathDefault()
589
    public function getPathDefault()
590
    {
590
    {
591
        return $this->getPathByType(self::TYPE_DEFAULT);
591
        return $this->getPathByType(self::TYPE_DEFAULT);
592
    }
592
    }
593
    
593
 
594
    public function getPathChat()
594
    public function getPathChat()
595
    {
595
    {
596
        return $this->getPathByType(self::TYPE_CHAT);
596
        return $this->getPathByType(self::TYPE_CHAT);
597
    }
597
    }
598
    
598
 
599
    public function getPathGroup()
599
    public function getPathGroup()
600
    {
600
    {
601
        return $this->getPathByType(self::TYPE_GROUP);
601
        return $this->getPathByType(self::TYPE_GROUP);
602
    }
602
    }
603
    
603
 
604
    public function getPathUser()
604
    public function getPathUser()
605
    {
605
    {
606
        return $this->getPathByType(self::TYPE_USER);
606
        return $this->getPathByType(self::TYPE_USER);
607
    }
607
    }
608
    
608
 
609
    public function getPathImage()
609
    public function getPathImage()
610
    {
610
    {
611
        return $this->getPathByType(self::TYPE_IMAGE);
611
        return $this->getPathByType(self::TYPE_IMAGE);
612
    }
612
    }
613
    
613
 
614
    public function getPathJob()
614
    public function getPathJob()
615
    {
615
    {
616
        return $this->getPathByType(self::TYPE_JOB);
616
        return $this->getPathByType(self::TYPE_JOB);
617
    }
617
    }
618
    
618
 
619
    public function getPathCompany()
619
    public function getPathCompany()
620
    {
620
    {
621
        return $this->getPathByType(self::TYPE_COMPANY);
621
        return $this->getPathByType(self::TYPE_COMPANY);
622
    }
622
    }
623
    
623
 
624
    
624
 
625
    public function getPathFeed()
625
    public function getPathFeed()
626
    {
626
    {
627
        return $this->getPathByType(self::TYPE_FEED);
627
        return $this->getPathByType(self::TYPE_FEED);
628
    }
628
    }
629
    
629
 
630
    public function getPathMedia()
630
    public function getPathMedia()
631
    {
631
    {
632
        return $this->getPathByType(self::TYPE_MEDIA);
632
        return $this->getPathByType(self::TYPE_MEDIA);
633
    }
633
    }
634
    
634
 
635
    public function getPathPost()
635
    public function getPathPost()
636
    {
636
    {
637
        return $this->getPathByType(self::TYPE_POST);
637
        return $this->getPathByType(self::TYPE_POST);
638
    }
638
    }
639
    
639
 
640
    
640
 
641
    public function getPathMicrolearningTopic()
641
    public function getPathMicrolearningTopic()
642
    {
642
    {
643
        return $this->getPathByType(self::TYPE_MICROLEARNING_TOPIC);
643
        return $this->getPathByType(self::TYPE_MICROLEARNING_TOPIC);
644
    }
644
    }
645
    
645
 
646
    public function getPathMicrolearningCapsule()
646
    public function getPathMicrolearningCapsule()
647
    {
647
    {
648
        return $this->getPathByType(self::TYPE_MICROLEARNING_CAPSULE);
648
        return $this->getPathByType(self::TYPE_MICROLEARNING_CAPSULE);
649
    }
649
    }
650
    
650
 
651
    public function getPathMicrolearningSlide()
651
    public function getPathMicrolearningSlide()
652
    {
652
    {
653
        return $this->getPathByType(self::TYPE_MICROLEARNING_SLIDE);
653
        return $this->getPathByType(self::TYPE_MICROLEARNING_SLIDE);
654
    }
654
    }
655
    
655
 
656
    public function getPathJobDescription()
656
    public function getPathJobDescription()
657
    {
657
    {
658
        return $this->getPathByType(self::TYPE_JOB_DESCRIPTION);
658
        return $this->getPathByType(self::TYPE_JOB_DESCRIPTION);
659
    }
659
    }
660
    
660
 
661
    public function getPathSelfEvaluation()
661
    public function getPathSelfEvaluation()
662
    {
662
    {
663
        return $this->getPathByType(self::TYPE_SELF_EVALUATION);
663
        return $this->getPathByType(self::TYPE_SELF_EVALUATION);
664
    }
664
    }
665
    
665
 
666
    public function getPathPerformanceEvaluation()
666
    public function getPathPerformanceEvaluation()
667
    {
667
    {
668
        return $this->getPathByType(self::TYPE_PERFORMANCE_EVALUATION);
668
        return $this->getPathByType(self::TYPE_PERFORMANCE_EVALUATION);
669
    }
669
    }
670
    
670
 
671
    
671
 
672
    public function getPathRecruitmentSelection()
672
    public function getPathRecruitmentSelection()
673
    {
673
    {
674
        return $this->getPathByType(self::TYPE_RECRUITMENT_SELECTION);
674
        return $this->getPathByType(self::TYPE_RECRUITMENT_SELECTION);
675
    }
675
    }
676
    
676
 
677
    
677
 
678
    public function getPathPlanningObjectivesAndGoals()
678
    public function getPathPlanningObjectivesAndGoals()
679
    {
679
    {
680
        return $this->getPathByType(self::TYPE_PLANNING_OBJECTIVES_AND_GOALS);
680
        return $this->getPathByType(self::TYPE_PLANNING_OBJECTIVES_AND_GOALS);
681
    }
681
    }
682
    
682
 
683
    public function getPathMessage()
683
    public function getPathMessage()
684
    {
684
    {
685
        return $this->getPathByType(self::TYPE_MESSAGE);
685
        return $this->getPathByType(self::TYPE_MESSAGE);
686
    }
686
    }
687
    
687
 
688
    
688
 
689
    public function getPathSurvey()
689
    public function getPathSurvey()
690
    {
690
    {
691
        return $this->getPathByType(self::TYPE_SURVEY);
691
        return $this->getPathByType(self::TYPE_SURVEY);
692
    }
692
    }
693
    
693
 
694
    
694
 
695
    public function getPathNetwork()
695
    public function getPathNetwork()
696
    {
696
    {
697
        return $this->getPathByType(self::TYPE_NETWORK);
697
        return $this->getPathByType(self::TYPE_NETWORK);
698
    }
698
    }
699
    
699
 
700
    
700
 
701
    public function getPathDailyPulse()
701
    public function getPathDailyPulse()
702
    {
702
    {
703
        return $this->getPathByType(self::TYPE_DAILY_PULSE);
703
        return $this->getPathByType(self::TYPE_DAILY_PULSE);
704
    }
704
    }
Línea 705... Línea 705...
705
 
705
 
706
    
706
 
707
    public function getPathEngagementReward()
707
    public function getPathEngagementReward()
708
    {
708
    {
709
        return $this->getPathByType(self::TYPE_ENGAGEMENT_REWARD);
709
        return $this->getPathByType(self::TYPE_ENGAGEMENT_REWARD);
710
    }
710
    }
711
    
711
 
712
    public function getPathKnowledgeArea()
712
    public function getPathKnowledgeArea()
713
    {
713
    {
714
        return $this->getPathByType(self::TYPE_KNOWLEDGE_AREA);
714
        return $this->getPathByType(self::TYPE_KNOWLEDGE_AREA);
715
    }
715
    }
716
    
716
 
717
    public function getPathMyCoach()
717
    public function getPathMyCoach()
718
    {
718
    {
719
        return $this->getPathByType(self::TYPE_MY_COACH);
719
        return $this->getPathByType(self::TYPE_MY_COACH);
720
    }
720
    }
721
    
721
 
722
    public function getPathHabitEmoji()
722
    public function getPathHabitEmoji()
723
    {
723
    {
724
        return $this->getPathByType(self::TYPE_HABIT_EMOJI);
724
        return $this->getPathByType(self::TYPE_HABIT_EMOJI);
Línea 861... Línea 861...
861
     * @return string
861
     * @return string
862
     */
862
     */
863
    public function deleteFile($path, $code, $filename)
863
    public function deleteFile($path, $code, $filename)
864
    {
864
    {
865
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
865
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
866
        if(file_exists($filename)) {
866
        if (file_exists($filename)) {
867
            return @unlink($remoto);
867
            return @unlink($remoto);
868
        } else {
868
        } else {
869
            return true;
869
            return true;
870
        }
870
        }
871
    }
871
    }
Línea 944... Línea 944...
944
     */
944
     */
945
    public function copyFile($source_file, $target_file)
945
    public function copyFile($source_file, $target_file)
946
    {
946
    {
947
        return @copy($source_file, $target_file);
947
        return @copy($source_file, $target_file);
948
    }
948
    }
949
    
949
 
950
    
950
 
951
    /**
951
    /**
952
     *
952
     *
953
     * @param string $url
953
     * @param string $url
954
     * @return string
954
     * @return string
955
     */
955
     */
956
    public function getPresignedUrl($url)
956
    public function getPresignedUrl($url)
957
    {
957
    {
958
        
958
 
959
       
959
 
960
        if(strpos($url, 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') !== false) {
960
        if (strpos($url, 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') !== false) {
961
            $show = true;
961
            $show = true;
962
        } else {
962
        } else {
963
            $show = false;
963
            $show = false;
964
        } 
964
        }
965
        
965
 
966
        
966
 
967
        if($show) {
967
        if ($show) {
968
            error_log('getPresignedUrl : ' . $url);
968
            error_log('getPresignedUrl : ' . $url);
969
        }
969
        }
970
        
970
 
971
        $code = hash('sha256', $url);
971
        $code = hash('sha256', $url);
972
        
972
 
973
        if($show) {
973
        if ($show) {
974
            error_log('getPresignedUrl CODE : ' . $code);
974
            error_log('getPresignedUrl CODE : ' . $code);
975
        }
975
        }
Línea 976... Línea 976...
976
 
976
 
977
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
977
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
Línea 980... Línea 980...
980
            $storageFile = new \LeadersLinked\Model\StorageFile();
980
            $storageFile = new \LeadersLinked\Model\StorageFile();
981
            $storageFile->code = $code;
981
            $storageFile->code = $code;
982
            $storageFile->path = $url;
982
            $storageFile->path = $url;
983
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
983
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
Línea 984... Línea 984...
984
 
984
 
985
        
985
 
986
            
986
 
987
            $storageFileMapper->insert($storageFile);
987
            $storageFileMapper->insert($storageFile);
Línea 988... Línea 988...
988
        }
988
        }
989
 
989
 
990
        
990
 
991
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
991
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
992
        if($show) {
992
        if ($show) {
993
            error_log('URL : ' .  $url);
993
            error_log('URL : ' .  $url);
994
        }
994
        }
995
        
995
 
Línea 996... Línea 996...
996
        return $url;
996
        return $url;
997
    }
997
    }
Línea 1072... Línea 1072...
1072
            return $ext;
1072
            return $ext;
1073
        } else {
1073
        } else {
1074
            return;
1074
            return;
1075
        }
1075
        }
1076
    }
1076
    }
1077
    
1077
 
1078
    /**
1078
    /**
1079
     *
1079
     *
1080
     * @param string $source
1080
     * @param string $source
1081
     * @param string $target_filename
1081
     * @param string $target_filename
1082
     * @param number $target_width
1082
     * @param number $target_width
Línea 1085... Línea 1085...
1085
     */
1085
     */
1086
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1086
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1087
    {
1087
    {
Línea 1088... Línea 1088...
1088
 
1088
 
1089
        try {
1089
        try {
1090
            
1090
 
1091
            $data = file_get_contents($source_filename);
1091
            $data = file_get_contents($source_filename);
1092
            $img = imagecreatefromstring($data);
1092
            $img = imagecreatefromstring($data);
1093
            
1093
 
1094
            
1094
 
1095
            if($img) {
1095
            if ($img) {
1096
                list($source_width, $source_height) = getimagesize($source_filename);
1096
                list($source_width, $source_height) = getimagesize($source_filename);
1097
                
1097
 
1098
                
1098
 
1099
                $width_ratio = $target_width / $source_width;
1099
                $width_ratio = $target_width / $source_width;
1100
                $height_ratio = $target_height / $source_height;
1100
                $height_ratio = $target_height / $source_height;
1101
                
1101
 
1102
                if($width_ratio > $height_ratio) {
1102
                if ($width_ratio > $height_ratio) {
1103
                    $resized_width = $target_width;
1103
                    $resized_width = $target_width;
1104
                    $resized_height = $source_height * $width_ratio;
1104
                    $resized_height = $source_height * $width_ratio;
1105
                } else {
1105
                } else {
1106
                    $resized_height = $target_height;
1106
                    $resized_height = $target_height;
1107
                    $resized_width = $source_width * $height_ratio;
1107
                    $resized_width = $source_width * $height_ratio;
1108
                }
1108
                }
1109
                
1109
 
1110
                
1110
 
1111
                
1111
 
1112
                $resized_width = round($resized_width);
1112
                $resized_width = round($resized_width);
1113
                $resized_height = round($resized_height);
1113
                $resized_height = round($resized_height);
1114
                
1114
 
1115
                $new_image = imageCreateTrueColor($target_width, $target_height);
1115
                $new_image = imageCreateTrueColor($target_width, $target_height);
1116
                imageAlphaBlending($new_image, False);
1116
                imageAlphaBlending($new_image, False);
1117
                imageSaveAlpha($new_image, True);
1117
                imageSaveAlpha($new_image, True);
1118
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1118
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1119
                imagefill($new_image, 0, 0, $transparent);
1119
                imagefill($new_image, 0, 0, $transparent);
1120
                imageCopyResampled($new_image, $img , 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1120
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1121
                
1121
 
1122
          
1122
 
1123
                imagepng($new_image, $target_filename);
1123
                imagepng($new_image, $target_filename);
1124
                
1124
 
1125
                @unlink($source_filename);
1125
                @unlink($source_filename);
1126
                return true;
-
 
1127
                
1126
                return true;
1128
            }
1127
            }
1129
            
1128
 
1130
            @unlink($source_filename);
1129
            @unlink($source_filename);
1131
            return false;
-
 
1132
            
1130
            return false;
1133
        } catch (\Throwable $e) {
1131
        } catch (\Throwable $e) {
1134
            error_log( $e->getTraceAsString() );
1132
            error_log($e->getTraceAsString());
1135
            
1133
 
1136
            @unlink($source_filename);
1134
            @unlink($source_filename);
1137
            return false;
-
 
1138
            
1135
            return false;
1139
        }
-
 
1140
 
1136
        }
1141
    }
1137
    }
1142
    
1138
 
1143
    
1139
 
1144
    /**
1140
    /**
1145
     *
1141
     *
1146
     * @param string $source
1142
     * @param string $source
1147
     * @param string $target_filename
1143
     * @param string $target_filename
Línea 1152... Línea 1148...
1152
     */
1148
     */
1153
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
1149
    public function uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)
1154
    {
1150
    {
Línea 1155... Línea 1151...
1155
 
1151
 
1156
        try {
1152
        try {
1157
            
1153
 
1158
            $data = file_get_contents($source_filename);
1154
            $data = file_get_contents($source_filename);
1159
            $img = imagecreatefromstring($data);
1155
            $img = imagecreatefromstring($data);
1160
            
1156
 
1161
            
1157
 
1162
            if($img) {
1158
            if ($img) {
1163
                list($source_width, $source_height) = getimagesize($source_filename);
1159
                list($source_width, $source_height) = getimagesize($source_filename);
1164
                
1160
 
1165
                $width_ratio = $target_width / $source_width;
1161
                $width_ratio = $target_width / $source_width;
1166
                $height_ratio = $target_height / $source_height;
1162
                $height_ratio = $target_height / $source_height;
1167
                if($width_ratio > $height_ratio) {
1163
                if ($width_ratio > $height_ratio) {
1168
                    $resized_width = $target_width;
1164
                    $resized_width = $target_width;
1169
                    $resized_height = $source_height * $width_ratio;
1165
                    $resized_height = $source_height * $width_ratio;
1170
                } else {
1166
                } else {
1171
                    $resized_height = $target_height;
1167
                    $resized_height = $target_height;
1172
                    $resized_width = $source_width * $height_ratio;
1168
                    $resized_width = $source_width * $height_ratio;
1173
                }
1169
                }
1174
                
1170
 
1175
                
1171
 
1176
                
1172
 
1177
                $resized_width = round($resized_width);
1173
                $resized_width = round($resized_width);
1178
                $resized_height = round($resized_height);
1174
                $resized_height = round($resized_height);
1179
                
1175
 
1180
                $offset_width = round(($target_width - $resized_width) / 2);
1176
                $offset_width = round(($target_width - $resized_width) / 2);
1181
                $offset_height = round(($target_height - $resized_height) / 2);
1177
                $offset_height = round(($target_height - $resized_height) / 2);
1182
                
1178
 
1183
                
1179
 
1184
                $new_image = imageCreateTrueColor($target_width, $target_height);
1180
                $new_image = imageCreateTrueColor($target_width, $target_height);
1185
                imageAlphaBlending($new_image, False);
1181
                imageAlphaBlending($new_image, False);
1186
                imageSaveAlpha($new_image, True);
1182
                imageSaveAlpha($new_image, True);
1187
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1183
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1188
                imagefill($new_image, 0, 0, $transparent);
1184
                imagefill($new_image, 0, 0, $transparent);
1189
                imageCopyResampled($new_image, $img , $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1185
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
1190
                
1186
 
1191
                imagepng($new_image, $target_filename);
1187
                imagepng($new_image, $target_filename);
1192
                
1188
 
1193
                @unlink($source_filename);
1189
                @unlink($source_filename);
1194
                return true;
-
 
1195
                
1190
                return true;
1196
            } 
1191
            }
1197
            
1192
 
1198
            @unlink($source_filename);
1193
            @unlink($source_filename);
1199
            return false;
-
 
1200
            
-
 
1201
        }
1194
            return false;
1202
        catch (\Throwable $e)
-
 
1203
        {
1195
        } catch (\Throwable $e) {
1204
            error_log( $e->getTraceAsString() );
1196
            error_log($e->getTraceAsString());
1205
            
1197
 
1206
            @unlink($source_filename);
1198
            @unlink($source_filename);
1207
            return false;
-
 
1208
            
1199
            return false;
1209
        }
-
 
1210
    
1200
        }
1211
    }
1201
    }
1212
    
1202
 
1213
    /**
1203
    /**
1214
     *
1204
     *
1215
     * @param string $source
1205
     * @param string $source
1216
     * @param string $target_filename
1206
     * @param string $target_filename
Línea 1219... Línea 1209...
1219
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
1209
    public function uploadImageWithOutChangeSize($source_filename, $target_filename)
1220
    {
1210
    {
Línea 1221... Línea 1211...
1221
 
1211
 
1222
        try {
1212
        try {
1223
            $data = file_get_contents($source_filename);
1213
            $data = file_get_contents($source_filename);
1224
            
1214
 
1225
            
1215
 
1226
            $img = imagecreatefromstring($data);
1216
            $img = imagecreatefromstring($data);
1227
            
1217
 
1228
            if($img) {
1218
            if ($img) {
1229
                list($source_width, $source_height) = getimagesize($source_filename);
1219
                list($source_width, $source_height) = getimagesize($source_filename);
1230
    
1220
 
1231
                $new_image = imageCreateTrueColor($source_width, $source_height);
1221
                $new_image = imageCreateTrueColor($source_width, $source_height);
1232
                imageAlphaBlending($new_image, False);
1222
                imageAlphaBlending($new_image, False);
1233
                imageSaveAlpha($new_image, True);
1223
                imageSaveAlpha($new_image, True);
1234
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1224
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
1235
                imagefill($new_image, 0, 0, $transparent);
1225
                imagefill($new_image, 0, 0, $transparent);
1236
                imageCopyResampled($new_image, $img , 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
1226
                imageCopyResampled($new_image, $img, 0, 0, 0, 0, $source_width, $source_height, $source_width, $source_height);
1237
                
1227
 
1238
                
1228
 
1239
                imagepng($new_image, $target_filename);
1229
                imagepng($new_image, $target_filename);
1240
                
1230
 
1241
                @unlink($source_filename);
1231
                @unlink($source_filename);
1242
                return true;
-
 
1243
                
1232
                return true;
1244
            } 
1233
            }
1245
            
1234
 
1246
            @unlink($source_filename);
1235
            @unlink($source_filename);
1247
            return false;
-
 
1248
            
1236
            return false;
1249
        } catch (\Throwable $e) {
1237
        } catch (\Throwable $e) {
1250
            error_log( $e->getTraceAsString() );
1238
            error_log($e->getTraceAsString());
1251
            
1239
 
1252
            @unlink($source_filename);
1240
            @unlink($source_filename);
1253
            return false;
-
 
1254
            
1241
            return false;
1255
        }
-
 
1256
        
-
 
1257
        
1242
        }
1258
    }
1243
    }
1259
    
1244
 
1260
    public static function extractPosterFromVideo($source_filename, $target_filename)
1245
    public static function extractPosterFromVideo($source_filename, $target_filename)
1261
    {
1246
    {
1262
        
1247
 
1263
        try {
1248
        try {
1264
            $cmd        = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $source_filename";
1249
            $cmd        = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration  $source_filename";
1265
            $response   = trim(shell_exec($cmd));
1250
            $response   = trim(shell_exec($cmd));
1266
            
1251
 
1267
            $source_duration = 0;
1252
            $source_duration = 0;
1268
            $lines = explode("\n", $response);
1253
            $lines = explode("\n", $response);
1269
            foreach ($lines as $line) {
1254
            foreach ($lines as $line) {
1270
                $line = trim(strtolower($line));
1255
                $line = trim(strtolower($line));
1271
                if (strpos($line, 'duration') !== false) {
1256
                if (strpos($line, 'duration') !== false) {
1272
                    $values = explode('=', $line);
1257
                    $values = explode('=', $line);
1273
                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
1258
                    $source_duration = intval(str_replace($values[1], '#', ''), 10);
1274
                }
1259
                }
1275
            }
1260
            }
1276
            
1261
 
1277
            
1262
 
1278
            if ($source_duration == 0) {
1263
            if ($source_duration == 0) {
1279
                $second_extract = '00:00:02';
1264
                $second_extract = '00:00:02';
1280
            } else {
1265
            } else {
1281
                if ($source_duration > 10) {
1266
                if ($source_duration > 10) {
1282
                    $second_extract = '00:00:10';
1267
                    $second_extract = '00:00:10';
1283
                } else {
1268
                } else {
1284
                    $second_extract = '00:00:02';
1269
                    $second_extract = '00:00:02';
1285
                }
1270
                }
1286
            }
1271
            }
1287
            
1272
 
1288
            $cmd = "/usr/bin/ffmpeg -y -i $source_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $target_filename";
1273
            $cmd = "/usr/bin/ffmpeg -y -i $source_filename  -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y  $target_filename";
1289
            exec($cmd);
1274
            exec($cmd);
1290
            
1275
 
1291
            return true;
-
 
1292
            
-
 
1293
        }
1276
            return true;
1294
        catch (\Throwable $e)
-
 
1295
        {
1277
        } catch (\Throwable $e) {
1296
            error_log( $e->getTraceAsString() );
1278
            error_log($e->getTraceAsString());
1297
            
1279
 
1298
            return false;
-
 
1299
            
1280
            return false;
1300
        }
-
 
1301
        
-
 
1302
        
1281
        }
Línea 1303... Línea 1282...
1303
    }
1282
    }
1304
 
1283
 
1305
    /**
1284
    /**
Línea 1332... Línea 1311...
1332
            '---',
1311
            '---',
1333
            '--'
1312
            '--'
1334
        ], '-', $str);
1313
        ], '-', $str);
1335
        return trim(strtolower($str));
1314
        return trim(strtolower($str));
1336
    }
1315
    }
1337
}
-
 
1338
1316
}
-
 
1317