Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 333 Rev 334
Línea 33... Línea 33...
33
    const TYPE_KNOWLEDGE_AREA                   = 'knowarea';
33
    const TYPE_KNOWLEDGE_AREA                   = 'knowarea';
34
    const TYPE_MY_COACH                         = 'mycoach';
34
    const TYPE_MY_COACH                         = 'mycoach';
35
    const TYPE_HABIT_EMOJI                      = 'habit-emoji';
35
    const TYPE_HABIT_EMOJI                      = 'habit-emoji';
36
    const TYPE_HABIT_CONTENT                    = 'habit-content';
36
    const TYPE_HABIT_CONTENT                    = 'habit-content';
Línea 37... Línea 37...
37
    
37
    
Línea 38... Línea 38...
38
    const BASE_PATH = 'data/storage';
38
    const BASE_PATH = 'data' . DIRECTORY_SEPARATOR . 'storage';
39
    
39
    
40
    
40
    
Línea 91... Línea 91...
91
     * @return string
91
     * @return string
92
     */
92
     */
93
    public function getUserImage($user)
93
    public function getUserImage($user)
94
    {
94
    {
95
        if($user->image) {
95
        if($user->image) {
96
            $remoto = self::BASE_PATH . '/' .$this->getPathUser() . '/' . $user->uuid . '/' .  $user->image;
96
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $user->image;
97
            if(file_exists($remoto)) {
97
            if(file_exists($remoto)) {
98
                return $this->getPresignedUrl($remoto);
98
                return $this->getPresignedUrl($remoto);
Línea 99... Línea 99...
99
                
99
                
100
            }
100
            }
Línea 111... Línea 111...
111
     * @return string
111
     * @return string
112
     */
112
     */
113
    public function getUserImageForCodeAndFilename($code, $filename)
113
    public function getUserImageForCodeAndFilename($code, $filename)
114
    {
114
    {
115
        if($filename) {
115
        if($filename) {
116
            $remoto = self::BASE_PATH . '/' .$this->getPathUser() . '/' . $code . '/' .  $filename;
116
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
117
            if(file_exists($remoto)) {
117
            if(file_exists($remoto)) {
118
                return $this->getPresignedUrl($remoto);
118
                return $this->getPresignedUrl($remoto);
Línea 119... Línea 119...
119
                
119
                
120
            }
120
            }
Línea 132... Línea 132...
132
     * @return string
132
     * @return string
133
     */
133
     */
134
    public function getUserProfileImage($user, $userProfile)
134
    public function getUserProfileImage($user, $userProfile)
135
    {
135
    {
136
        if($userProfile->image) {
136
        if($userProfile->image) {
137
            $remoto = self::BASE_PATH . '/' .$this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->image;
137
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->image;
138
            if(file_exists($remoto)) {
138
            if(file_exists($remoto)) {
139
                return $this->getPresignedUrl($remoto);
139
                return $this->getPresignedUrl($remoto);
Línea 140... Línea 140...
140
                
140
                
141
            }
141
            }
Línea 153... Línea 153...
153
     * @return string
153
     * @return string
154
     */
154
     */
155
    public function getUserProfileCover($user, $userProfile)
155
    public function getUserProfileCover($user, $userProfile)
156
    {
156
    {
157
        if($userProfile->cover) {
157
        if($userProfile->cover) {
158
            $remoto = self::BASE_PATH . '/' .$this->getPathUser() . '/' . $user->uuid . '/' .  $userProfile->cover;
158
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathUser() . DIRECTORY_SEPARATOR . $user->uuid . DIRECTORY_SEPARATOR . $userProfile->cover;
159
            if(file_exists($remoto)) {
159
            if(file_exists($remoto)) {
160
                return $this->getPresignedUrl($remoto);
160
                return $this->getPresignedUrl($remoto);
Línea 161... Línea 161...
161
                
161
                
162
            }
162
            }
Línea 173... Línea 173...
173
     * @return string
173
     * @return string
174
     */
174
     */
175
    public function getCompanyImage($company)
175
    public function getCompanyImage($company)
176
    {
176
    {
177
        if($company->image) {
177
        if($company->image) {
178
            $remoto = self::BASE_PATH . '/' .$this->getPathCompany() . '/' . $company->uuid . '/' .  $company->image;
178
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->image;
179
            if(file_exists($remoto)) {
179
            if(file_exists($remoto)) {
180
                return $this->getPresignedUrl($remoto);
180
                return $this->getPresignedUrl($remoto);
Línea 181... Línea 181...
181
                
181
                
182
            }
182
            }
Línea 194... Línea 194...
194
     * @return string
194
     * @return string
195
     */
195
     */
196
    public function getCompanyImageForCodeAndFilename($code, $filename)
196
    public function getCompanyImageForCodeAndFilename($code, $filename)
197
    {
197
    {
198
        if($filename) {
198
        if($filename) {
199
            $remoto = self::BASE_PATH . '/' .$this->getPathCompany() . '/' . $code . '/' .  $filename;
199
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
200
            if(file_exists($remoto)) {
200
            if(file_exists($remoto)) {
201
                return $this->getPresignedUrl($remoto);
201
                return $this->getPresignedUrl($remoto);
Línea 202... Línea 202...
202
                
202
                
203
            }
203
            }
Línea 214... Línea 214...
214
     * @return string
214
     * @return string
215
     */
215
     */
216
    public function getCompanyCover($company)
216
    public function getCompanyCover($company)
217
    {
217
    {
218
        if($company->cover) {
218
        if($company->cover) {
219
            $remoto = self::BASE_PATH . '/' .$this->getPathCompany() . '/' . $company->uuid . '/' .  $company->cover;
219
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathCompany() . DIRECTORY_SEPARATOR . $company->uuid . DIRECTORY_SEPARATOR . $company->cover;
220
            if(file_exists($remoto)) {
220
            if(file_exists($remoto)) {
221
                return $this->getPresignedUrl($remoto);
221
                return $this->getPresignedUrl($remoto);
Línea 222... Línea 222...
222
                
222
                
223
            }
223
            }
Línea 234... Línea 234...
234
     * @return string
234
     * @return string
235
     */
235
     */
236
    public function getGroupImage($group)
236
    public function getGroupImage($group)
237
    {
237
    {
238
        if($group->image) {
238
        if($group->image) {
239
            $remoto = self::BASE_PATH . '/' .$this->getPathGroup() . '/' . $group->uuid . '/' .  $group->image;
239
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR . $group->image;
240
            if(file_exists($remoto)) {
240
            if(file_exists($remoto)) {
241
                return $this->getPresignedUrl($remoto);
241
                return $this->getPresignedUrl($remoto);
Línea 242... Línea 242...
242
                
242
                
243
            }
243
            }
Línea 255... Línea 255...
255
     * @return string
255
     * @return string
256
     */
256
     */
257
    public function getGroupImageForCodeAndFilename($code, $filename)
257
    public function getGroupImageForCodeAndFilename($code, $filename)
258
    {
258
    {
259
        if($filename) {
259
        if($filename) {
260
            $remoto = self::BASE_PATH . '/' .$this->getPathGroup() . '/' . $code . '/' .  $filename;
260
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR .  $filename;
261
            if(file_exists($remoto)) {
261
            if(file_exists($remoto)) {
262
                return $this->getPresignedUrl($remoto);
262
                return $this->getPresignedUrl($remoto);
Línea 263... Línea 263...
263
                
263
                
264
            }
264
            }
Línea 275... Línea 275...
275
     * @return string
275
     * @return string
276
     */
276
     */
277
    public function getGroupCover($group)
277
    public function getGroupCover($group)
278
    {
278
    {
279
        if($group->cover) {
279
        if($group->cover) {
280
            $remoto = self::BASE_PATH . '/' .$this->getPathGroup() . '/' . $group->uuid . '/' .  $group->cover;
280
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$this->getPathGroup() . DIRECTORY_SEPARATOR . $group->uuid . DIRECTORY_SEPARATOR .  $group->cover;
281
            if(file_exists($remoto)) {
281
            if(file_exists($remoto)) {
282
                return $this->getPresignedUrl($remoto);
282
                return $this->getPresignedUrl($remoto);
Línea 283... Línea 283...
283
                
283
                
284
            }
284
            }
Línea 294... Línea 294...
294
     * @param Group $group
294
     * @param Group $group
295
     * @return string
295
     * @return string
296
     */
296
     */
297
    public function getGenericImage($path, $code, $filename)
297
    public function getGenericImage($path, $code, $filename)
298
    {
298
    {
299
        $remoto = self::BASE_PATH . '/' .$path . '/' . $code. '/' .  $filename;
299
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
Línea 300... Línea 300...
300
        
300
        
301
  
301
  
Línea 315... Línea 315...
315
     * @param string $code,
315
     * @param string $code,
316
     * @param string $filename
316
     * @param string $filename
317
     * @param boolean $checkExists
317
     * @param boolean $checkExists
318
     * @return string
318
     * @return string
319
     */
319
     */
-
 
320
    public function checkDirectory($path, $code)
-
 
321
    {
-
 
322
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
-
 
323
        
-
 
324
 
-
 
325
        if(file_exists( $directory)) {
-
 
326
            return true; 
-
 
327
        } else {
-
 
328
            return @mkdir($directory, 0755, true);  
-
 
329
        }
-
 
330
        
-
 
331
    }
-
 
332
    
-
 
333
    
-
 
334
    /**
-
 
335
     *
-
 
336
     * @param string $path
-
 
337
     * @param string $code,
-
 
338
     * @param string $filename
-
 
339
     * @return string
-
 
340
     */
-
 
341
    public function getFileFromDisk($path, $code, $filename)
-
 
342
    {
-
 
343
        $current_file = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
-
 
344
        
-
 
345
        if(file_exists($current_file)) {
-
 
346
            return $current_file;
-
 
347
        } 
-
 
348
        return;
-
 
349
    }
-
 
350
    
-
 
351
    /**
-
 
352
     *
-
 
353
     * @param string $path
-
 
354
     * @param string $code,
-
 
355
     * @return string
-
 
356
     */
-
 
357
    public function getDirectoryFromDisk($path, $code)
-
 
358
    {
-
 
359
        $directory = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code;
-
 
360
        
-
 
361
        if(file_exists($directory)) {
-
 
362
            return $directory;
-
 
363
        }
-
 
364
        return;
-
 
365
    }
-
 
366
    
-
 
367
    
-
 
368
 
-
 
369
    
-
 
370
    /**
-
 
371
     *
-
 
372
     * @param string $path
-
 
373
     * @param string $code,
-
 
374
     * @param string $filename
-
 
375
     * @param boolean $checkExists
-
 
376
     * @return string
-
 
377
     */
320
    public function getGenericFile($path, $code, $filename, $checkExists = true)
378
    public function getGenericFile($path, $code, $filename, $checkExists = true)
321
    {
379
    {
322
        $remoto = self::BASE_PATH . '/' .$path . '/' . $code. '/' .  $filename;
380
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
Línea 323... Línea 381...
323
        
381
        
324
 
382
 
325
        if($checkExists) {
383
        if($checkExists) {
Línea 412... Línea 470...
412
                
470
                
413
            case TYPE_HABIT_CONTENT : 
471
            case TYPE_HABIT_CONTENT : 
Línea 414... Línea 472...
414
                return $this->getPathHabitContent();
472
                return $this->getPathHabitContent();
415
                
473
                
416
            default : 
474
            default : 
Línea 417... Línea 475...
417
                return '/';
475
                return DIRECTORY_SEPARATOR;
Línea 426... Línea 484...
426
     * @return string
484
     * @return string
427
     */
485
     */
428
    public function getGenericImageByType($type, $code, $filename)
486
    public function getGenericImageByType($type, $code, $filename)
429
    {
487
    {
430
        $path = $this->getPathByType($type);
488
        $path = $this->getPathByType($type);
431
        $remoto = self::BASE_PATH . '/' .$path . '/' . $code. '/' .  $filename;
489
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
Línea 432... Línea 490...
432
 
490
 
433
        if(file_exists($remoto)) {
491
        if(file_exists($remoto)) {
Línea 434... Línea 492...
434
            return $this->getPresignedUrl($remoto);
492
            return $this->getPresignedUrl($remoto);
Línea 449... Línea 507...
449
     * @return string
507
     * @return string
450
     */
508
     */
451
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
509
    public function getGenericFileByType($type, $code, $filename, $checkExists = true)
452
    {
510
    {
453
        $path = $this->getPathByType($type);
511
        $path = $this->getPathByType($type);
454
        $remoto = self::BASE_PATH . '/' .$path . '/' . $code. '/' .  $filename;
512
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
Línea 455... Línea 513...
455
 
513
 
456
        if($checkExists) {
514
        if($checkExists) {
457
            if(file_exists($remoto)) {
515
            if(file_exists($remoto)) {
Línea 471... Línea 529...
471
     * @param string $filename
529
     * @param string $filename
472
     * @return string
530
     * @return string
473
     */
531
     */
474
    public function delete($path, $code, $filename)
532
    public function delete($path, $code, $filename)
475
    {
533
    {
476
        $remoto = self::BASE_PATH . '/' .$path . '/' . $code. '/' .  $filename;
534
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .$path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
477
        return @unlink($remoto);
535
        return @unlink($remoto);
Línea 478... Línea 536...
478
 
536
 
Línea 735... Línea 793...
735
     * @param string $local
793
     * @param string $local
736
     * @return boolean
794
     * @return boolean
737
     */
795
     */
738
    public function putObject($remote, $local)
796
    public function putObject($remote, $local)
739
    {
797
    {
-
 
798
        
-
 
799
        $dir = dirname($remote);
-
 
800
        if(!file_exists($dir)) {
-
 
801
            @mkdir($dir, 0755, true);
-
 
802
        }
-
 
803
        
740
        return @rename($local, $remote);
804
        return @rename($local, $remote);
741
    }
805
    }
Línea 742... Línea 806...
742
    
806
    
Línea 761... Línea 825...
761
     * @return boolean
825
     * @return boolean
762
     */
826
     */
763
    public function deleteFile($path, $code, $filename)
827
    public function deleteFile($path, $code, $filename)
764
    {
828
    {
765
        if($code) {
829
        if($code) {
766
            $remoto = $path . '/' . $code. '/' .  $filename;
830
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code. DIRECTORY_SEPARATOR .  $filename;
767
        } else {
831
        } else {
768
            $remoto = $path . '/' .  $filename;
832
            $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $filename;
769
        }
833
        }
770
        if(file_exists($remoto)) {
834
        if(file_exists($remoto)) {
771
            return @unlink($remoto);
835
            return @unlink($remoto);
772
        } else {
836
        } else {
773
            return true;
837
            return true;
Línea 780... Línea 844...
780
     * @param string $code
844
     * @param string $code
781
     * @return boolean
845
     * @return boolean
782
     */
846
     */
783
    public function deleteDirectory($path, $code)
847
    public function deleteDirectory($path, $code)
784
    {
848
    {
785
        $remoto = $path . '/' . $code;
849
        $remoto = self::BASE_PATH . DIRECTORY_SEPARATOR .  $path . DIRECTORY_SEPARATOR . $code;
786
        if(file_exists($remoto)) {
850
        if(file_exists($remoto)) {
-
 
851
            $this->deleteDirectoryRecursive($remoto);
787
            return @unlink($remoto);
852
            return true;
788
        } else {
853
        } else {
789
            return true;
854
            return true;
790
        }
855
        }
791
    }
856
    }
Línea -... Línea 857...
-
 
857
    
-
 
858
    /**
-
 
859
     *
-
 
860
     * @param string $dir
-
 
861
     */
-
 
862
    private function deleteDirectoryRecursive($dir) {
-
 
863
        if (is_dir($dir)) {
-
 
864
            $objects = scandir($dir);
-
 
865
            foreach ($objects as $object) {
-
 
866
                if ($object != ''.'' && $object != '..') {
-
 
867
                    if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.'/'.$object)) {
-
 
868
                        @rmdir($dir. DIRECTORY_SEPARATOR .$object);
-
 
869
                    }  else {
-
 
870
                        @unlink($dir. DIRECTORY_SEPARATOR .$object);
-
 
871
                    }
-
 
872
                }
-
 
873
            }
-
 
874
            @rmdir($dir);
-
 
875
        }
-
 
876
    }
Línea 792... Línea 877...
792
    
877
    
793
 
878
 
794
 
879
 
Línea 800... Línea 885...
800
     * @return boolean
885
     * @return boolean
801
     */
886
     */
802
    public function putFile($path, $code, $local_filename)
887
    public function putFile($path, $code, $local_filename)
803
    {
888
    {
804
        if($code) {
889
        if($code) {
805
            $remote = $path . '/' . $code . '/' . basename($local_filename);
890
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR .  $code . DIRECTORY_SEPARATOR . basename($local_filename);
806
        } else {
891
        } else {
807
            $remote = $path. '/' . basename($local_filename);
892
            $remote = self::BASE_PATH . DIRECTORY_SEPARATOR . $path  . DIRECTORY_SEPARATOR .  basename($local_filename);
-
 
893
        }
-
 
894
 
-
 
895
        $dir = dirname($remote);
-
 
896
        if(!file_exists($dir)) {
-
 
897
            @mkdir($dir, 0755, true);
808
        }
898
        }
Línea 809... Línea 899...
809
        
899
        
Línea 810... Línea 900...
810
 
900
 
Línea 811... Línea 901...
811
        return @rename($local_filename, $remote);
901
        return @rename($local_filename, $remote);
812
 
902
 
-
 
903
    }
813
    }
904
    
814
    
905
    
815
    
-
 
816
    /**
906
    /**
817
     *
907
     *
818
     * @param string $path
908
     * @param string $tempfile
819
     * @param string $code
909
     * @param string $path
820
     * @param string $tempfile
910
     * @param string $code
821
     * @param string $filename
911
     * @param string $filename
822
     * @return boolean
912
     * @return boolean
823
     */
913
     */
-
 
914
    public function moveAndPutFile($tempfile, $path, $code, $filename)
-
 
915
    {
-
 
916
        if($code) {
-
 
917
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
-
 
918
        } else {
-
 
919
            $target_file = self::BASE_PATH . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $filename;
824
    public function moveAndPutFile($path, $code, $tempfile, $filename)
920
        }
825
    {
921
        
Línea 826... Línea 922...
826
        if($code) {
922
 
827
            $targetfile = $path . '/' . $code;
923
        $dir = dirname($target_file);
Línea 828... Línea 924...
828
        } else {
924
        if(!file_exists($dir)) {
829
            $targetfile = $path . '/' . $filename;
925
            @mkdir($dir, 0755, true);
830
        }
926
        }
831
 
927
 
832
        return move_uploaded_file($tempfile, $targetfile);
928
        return move_uploaded_file($tempfile, $target_file);
833
    }
929
    }
834
    
930
    
835
    /**
931
    /**
Línea 836... Línea 932...
836
     *
932
     *
837
     * @return string
933
     * @return string
-
 
934
     */
-
 
935
    public function getStoagePath()
-
 
936
    {
-
 
937
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
-
 
938
    }
-
 
939
    
-
 
940
    /**
-
 
941
     * 
-
 
942
     * @return string
-
 
943
     */
-
 
944
    public function getTempPath() {
-
 
945
        $interal_path   = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
-
 
946
        if(!file_exists($interal_path)) {
-
 
947
            mkdir($interal_path, 0775);
838
     */
948
        }
839
    public function getTempPath()
949
        
840
    {
950
        return $interal_path;
841
        return 'data' . DIRECTORY_SEPARATOR . 'storage';
951
        
842
    }
952
    }
Línea 895... Línea 1005...
895
        
1005
        
Línea 896... Línea 1006...
896
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
1006
        return 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
Línea -... Línea 1007...
-
 
1007