Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15447 Rev 16287
Línea 9... Línea 9...
9
    public static function getUserIP()
9
    public static function getUserIP()
10
    {
10
    {
11
        $client  = isset($_SERVER['HTTP_CLIENT_IP'])  ? $_SERVER['HTTP_CLIENT_IP'] : '';
11
        $client  = isset($_SERVER['HTTP_CLIENT_IP'])  ? $_SERVER['HTTP_CLIENT_IP'] : '';
12
        $forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
12
        $forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
13
        $remote  = $_SERVER['REMOTE_ADDR'];
13
        $remote  = $_SERVER['REMOTE_ADDR'];
14
        
14
 
15
        if(filter_var($client, FILTER_VALIDATE_IP)) {
15
        if (filter_var($client, FILTER_VALIDATE_IP)) {
16
            $ip = $client;
16
            $ip = $client;
17
        } elseif(filter_var($forward, FILTER_VALIDATE_IP)) {
17
        } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
18
            $ip = $forward;
18
            $ip = $forward;
19
        } else {
19
        } else {
20
            $ip = $remote;
20
            $ip = $remote;
21
        }
21
        }
22
        
22
 
23
        return $ip;
23
        return $ip;
24
    }
24
    }
25
    
25
 
26
   
26
 
27
    /**
27
    /**
28
     * 
28
     * 
29
     * @param string $what
29
     * @param string $what
30
     * @param string $date
30
     * @param string $date
31
     * @return string
31
     * @return string
32
     */
32
     */
33
    public static function convertDate($what, $date) {
33
    public static function convertDate($what, $date)
-
 
34
    {
34
        if ($what == 'wherecond') {
35
        if ($what == 'wherecond') {
35
            return date('Y-m-d', strtotime($date));
36
            return date('Y-m-d', strtotime($date));
36
        }  
-
 
37
        else if ($what == 'display') {
37
        } else if ($what == 'display') {
38
            return date('d M, Y h:i A', strtotime($date));
38
            return date('d M, Y h:i A', strtotime($date));
39
        } 
-
 
40
        else if ($what == 'displayWeb') {
39
        } else if ($what == 'displayWeb') {
41
            return date('d M Y', strtotime($date));
40
            return date('d M Y', strtotime($date));
42
        }
-
 
43
        else if ($what == 'onlyDate') {
41
        } else if ($what == 'onlyDate') {
44
            return date(PHP_DATE_FORMAT, strtotime($date));
42
            return date(PHP_DATE_FORMAT, strtotime($date));
45
        } 
-
 
46
        else if ($what == 'monthYear') {
43
        } else if ($what == 'monthYear') {
47
            return date(PHP_DATE_FORMAT_MONTH_YEAR, strtotime($date));
44
            return date(PHP_DATE_FORMAT_MONTH_YEAR, strtotime($date));
48
        } 
-
 
49
        else if ($what == 'onlyMonth') {
45
        } else if ($what == 'onlyMonth') {
50
            return date(PHP_DATE_FORMAT_MONTH, strtotime($date));
46
            return date(PHP_DATE_FORMAT_MONTH, strtotime($date));
51
        }
-
 
52
        else if ($what == 'gmail') {
47
        } else if ($what == 'gmail') {
53
            return date('D, M d, Y - h:i A', strtotime($date));
48
            return date('D, M d, Y - h:i A', strtotime($date));
54
        } 
-
 
55
        else if ($what == 'onlyDateForCSV') {
49
        } else if ($what == 'onlyDateForCSV') {
56
            return date('M d,Y', strtotime($date));
50
            return date('M d,Y', strtotime($date));
57
        } 
-
 
58
        else {
51
        } else {
59
            return date('Y-m-d', strtotime($date));
52
            return date('Y-m-d', strtotime($date));
60
        }
53
        }
61
    }
54
    }
62
    
55
 
-
 
56
    /**
-
 
57
     * 
-
 
58
     * @return string[]
-
 
59
     */
-
 
60
    public static function getAllTimeZones()
-
 
61
    {
-
 
62
        $timezones =  [];
-
 
63
        $zones = \DateTimeZone::listIdentifiers();
-
 
64
 
-
 
65
        foreach ($zones as $zone) {
-
 
66
            array_push($timezones, $zone);
-
 
67
        }
-
 
68
 
-
 
69
        return $timezones;
-
 
70
    }
-
 
71
 
63
    /**
72
    /**
64
     *
73
     *
65
     * @param string $timestamp
74
     * @param string $timestamp
66
     * @param string $now
75
     * @param string $now
67
     * @return string
76
     * @return string
68
     */
77
     */
69
    public static function timeAgo($timestamp, $now = '')
78
    public static function timeAgo($timestamp, $now = '')
70
    {
79
    {
71
        
80
 
72
        if($now) {
81
        if ($now) {
73
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now);
82
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now);
74
        } else {
83
        } else {
75
            $now = date('Y-m-d H:i:s');
84
            $now = date('Y-m-d H:i:s');
76
            $datetime1 = date_create($now);
85
            $datetime1 = date_create($now);
77
        }
86
        }
78
        $datetime2 = date_create($timestamp);
87
        $datetime2 = date_create($timestamp);
79
        
88
 
80
        $diff = date_diff($datetime1, $datetime2);
89
        $diff = date_diff($datetime1, $datetime2);
81
        $timemsg = '';
90
        $timemsg = '';
82
        if ($diff->y > 0) {
91
        if ($diff->y > 0) {
83
            $timemsg = $diff->y . ' año' . ($diff->y > 1 ? "s" : '');
92
            $timemsg = $diff->y . ' año' . ($diff->y > 1 ? "s" : '');
84
        } else if ($diff->m > 0) {
93
        } else if ($diff->m > 0) {
Línea 97... Línea 106...
97
        } else {
106
        } else {
98
            $timemsg = $timemsg . '';
107
            $timemsg = $timemsg . '';
99
        }
108
        }
100
        return $timemsg;
109
        return $timemsg;
101
    }
110
    }
102
    
111
 
103
    /*
112
    /*
104
    public static function timeElapsedString(int $ptime, $now = null) 
113
    public static function timeElapsedString(int $ptime, $now = null) 
105
    {
114
    {
106
        if($now)  {
115
        if($now)  {
107
            $etime = $now - $ptime;
116
            $etime = $now - $ptime;
Línea 135... Línea 144...
135
                $r = round($d);
144
                $r = round($d);
136
                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
145
                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
137
            }
146
            }
138
        }
147
        }
139
    }*/
148
    }*/
140
    
149
 
Línea 141... Línea 150...
141
 
150
 
142
    /**
151
    /**
143
     * 
152
     * 
144
     * @param string $date1
153
     * @param string $date1
145
     * @param string $date2
154
     * @param string $date2
146
     * @param string $format
155
     * @param string $format
147
     */
156
     */
148
    public static function getYears(string $date1, string $date2, string $format = 'YearMonth') 
157
    public static function getYears(string $date1, string $date2, string $format = 'YearMonth')
149
    {
158
    {
150
        $date1 = new \DateTime($date1);
159
        $date1 = new \DateTime($date1);
151
        $date2 = new \DateTime($date2);
160
        $date2 = new \DateTime($date2);
152
        $interval = date_diff($date1, $date2);
161
        $interval = date_diff($date1, $date2);
153
        $months = $interval->m + ($interval->y * 12);
162
        $months = $interval->m + ($interval->y * 12);
154
        return(int) ($months / 12);
163
        return (int) ($months / 12);
155
    }
164
    }
156
    
165
 
157
    /**
166
    /**
158
     * 
167
     * 
159
     * @param number $length
168
     * @param number $length
160
     * @param string $seeds
169
     * @param string $seeds
161
     * @return string
170
     * @return string
162
     */
171
     */
163
    public static function genrateRandom($length = 8, $seeds = 'alphanum') 
172
    public static function genrateRandom($length = 8, $seeds = 'alphanum')
164
    {
173
    {
165
        $seedings = [
174
        $seedings = [
166
            'alpha' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
175
            'alpha' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
167
            'numeric' => '0123456789',
176
            'numeric' => '0123456789',
Línea 177... Línea 186...
177
        mt_srand($seed);
186
        mt_srand($seed);
178
        $str = '';
187
        $str = '';
179
        $seeds_count = strlen($seeds);
188
        $seeds_count = strlen($seeds);
180
        for ($i = 0; $length > $i; $i++) {
189
        for ($i = 0; $length > $i; $i++) {
181
            $pos = mt_rand(0, $seeds_count - 1);
190
            $pos = mt_rand(0, $seeds_count - 1);
182
            
191
 
183
            $str .= substr($seeds, $pos, $pos + 1);
192
            $str .= substr($seeds, $pos, $pos + 1);
184
        }
193
        }
185
        return $str;
194
        return $str;
186
    }
195
    }
187
    
196
 
188
    /**
197
    /**
189
     * 
198
     * 
190
     * @param string $date1
199
     * @param string $date1
191
     * @param string $date2
200
     * @param string $date2
192
     * @param string $timeFormat
201
     * @param string $timeFormat
193
     * @param bool $positive
202
     * @param bool $positive
194
     * @return number
203
     * @return number
195
     */
204
     */
196
    public static function getDateDiff(string $date1, string $date2, string $timeFormat = 'sec', bool $positive = false) 
205
    public static function getDateDiff(string $date1, string $date2, string $timeFormat = 'sec', bool $positive = false)
197
    {
206
    {
198
        $dtTime1 = strtotime($date1);
207
        $dtTime1 = strtotime($date1);
199
        $dtTime2 = strtotime($date2);
208
        $dtTime2 = strtotime($date2);
200
        if ($positive === true) {
209
        if ($positive === true) {
201
            if ($dtTime2 < $dtTime1) {
210
            if ($dtTime2 < $dtTime1) {
Línea 209... Línea 218...
209
            return $diff;
218
            return $diff;
210
        } else if ($timeFormat == 'day') {
219
        } else if ($timeFormat == 'day') {
211
            return $diff / 86400;
220
            return $diff / 86400;
212
        }
221
        }
213
    }
222
    }
214
    
223
 
215
    
224
 
216
    /**
225
    /**
217
     * 
226
     * 
218
     * @param string $date1
227
     * @param string $date1
219
     * @param string $date2
228
     * @param string $date2
220
     * @param string $format
229
     * @param string $format
221
     * @return string
230
     * @return string
222
     */
231
     */
223
    public static function getDifference(string $date1, string $date2, string $format = 'YearMonth') 
232
    public static function getDifference(string $date1, string $date2, string $format = 'YearMonth')
224
    {
233
    {
225
        $difference = '';
234
        $difference = '';
226
        $datetime1 = date_create($date1);
235
        $datetime1 = date_create($date1);
227
        $datetime2 = date_create($date2);
236
        $datetime2 = date_create($date2);
228
        $interval = date_diff($datetime1, $datetime2);
237
        $interval = date_diff($datetime1, $datetime2);
Línea 253... Línea 262...
253
        } else if ($format == 'YearMonthDay') {
262
        } else if ($format == 'YearMonthDay') {
254
            $difference = trim($years_text) . ' ' . trim($months_text) . ' ' . trim($days_text);
263
            $difference = trim($years_text) . ' ' . trim($months_text) . ' ' . trim($days_text);
255
            return trim($difference);
264
            return trim($difference);
256
        }
265
        }
257
    }
266
    }
258
    
267
 
259
    /**
268
    /**
260
     * 
269
     * 
261
     * @param string $source
270
     * @param string $source
262
     * @param string $destination
271
     * @param string $destination
263
     * @param int $quality
272
     * @param int $quality
264
     * @return string
273
     * @return string
265
     */
274
     */
266
    public static function compress(string $source, string $destination, int $quality = null) 
275
    public static function compress(string $source, string $destination, int $quality = null)
267
    {
276
    {
268
        $info = getimagesize($source);
277
        $info = getimagesize($source);
269
        if ($info['mime'] == 'image/jpeg') {
278
        if ($info['mime'] == 'image/jpeg') {
270
            $image = imagecreatefromjpeg($source);
279
            $image = imagecreatefromjpeg($source);
271
        }
-
 
272
        elseif ($info['mime'] == 'image/gif') {
280
        } elseif ($info['mime'] == 'image/gif') {
273
            $image = imagecreatefromgif($source);
281
            $image = imagecreatefromgif($source);
274
        }
-
 
275
        elseif ($info['mime'] == 'image/png') {
282
        } elseif ($info['mime'] == 'image/png') {
276
            $image = imagecreatefrompng($source);
283
            $image = imagecreatefrompng($source);
277
        }
284
        }
278
            
285
 
279
        imagejpeg($image, $destination, $quality);
286
        imagejpeg($image, $destination, $quality);
280
        return $destination;
287
        return $destination;
281
    }
288
    }
282
    
289
 
283
    /**
290
    /**
284
     * 
291
     * 
285
     * @param string $filename
292
     * @param string $filename
286
     * @param string $newfilename
293
     * @param string $newfilename
287
     * @param int $max_width
294
     * @param int $max_width
288
     * @param int $max_height
295
     * @param int $max_height
289
     * @param bool $withSampling
296
     * @param bool $withSampling
290
     * @param array $crop_coords
297
     * @param array $crop_coords
291
     * @return boolean
298
     * @return boolean
292
     */
299
     */
293
    public static function resizeImage(string $filename, string $newfilename = "", int $max_width  = 0, int $max_height = 0, bool $withSampling = true, $crop_coords = array()) 
300
    public static function resizeImage(string $filename, string $newfilename = "", int $max_width  = 0, int $max_height = 0, bool $withSampling = true, $crop_coords = array())
294
    {
301
    {
295
        if (empty($newfilename)) {
302
        if (empty($newfilename)) {
296
            $newfilename = $filename;
303
            $newfilename = $filename;
297
        }
304
        }
298
        $fileExtension = strtolower(self::getExt($filename));
305
        $fileExtension = strtolower(self::getExt($filename));
Línea 343... Línea 350...
343
        } else if ($fileExtension == 'gif') {
350
        } else if ($fileExtension == 'gif') {
344
            $createImageSave = imagegif($new_img, $newfilename);
351
            $createImageSave = imagegif($new_img, $newfilename);
345
        } else {
352
        } else {
346
            $createImageSave = imagejpeg($new_img, $newfilename);
353
            $createImageSave = imagejpeg($new_img, $newfilename);
347
        }
354
        }
348
        
355
 
349
        return $createImageSave;
356
        return $createImageSave;
350
    }
357
    }
351
    
358
 
352
    /**
359
    /**
353
     * 
360
     * 
354
     * @param string $start
361
     * @param string $start
355
     * @param string $end
362
     * @param string $end
356
     * @return array
363
     * @return array
357
     */
364
     */
358
    public static function getTimeDifference(string $start, string $end) {
365
    public static function getTimeDifference(string $start, string $end)
-
 
366
    {
359
        $uts = [
367
        $uts = [
360
            'start' => strtotime($start),
368
            'start' => strtotime($start),
361
            'end' => strtotime($end)
369
            'end' => strtotime($end)
362
        ];   
370
        ];
363
        if ($uts['start'] !== -1 && $uts['end'] !== -1) {
371
        if ($uts['start'] !== -1 && $uts['end'] !== -1) {
364
            if ($uts['end'] >= $uts['start']) {
372
            if ($uts['end'] >= $uts['start']) {
365
                $diff = $uts['end'] - $uts['start'];
373
                $diff = $uts['end'] - $uts['start'];
366
                if ($days = intval((floor($diff / 86400)))) {
374
                if ($days = intval((floor($diff / 86400)))) {
367
                    $diff = $diff % 86400;
375
                    $diff = $diff % 86400;
Línea 385... Línea 393...
385
        } else {
393
        } else {
386
            trigger_error("Invalid date/time data detected", E_USER_WARNING);
394
            trigger_error("Invalid date/time data detected", E_USER_WARNING);
387
        }
395
        }
388
        return;
396
        return;
389
    }
397
    }
390
    
398
 
391
    /**
399
    /**
392
     * 
400
     * 
393
     * @param number $length
401
     * @param number $length
394
     * @return string
402
     * @return string
395
     */
403
     */
396
    public static function generatePassword($length = 8) 
404
    public static function generatePassword($length = 8)
397
    {
405
    {
398
        $password = '';
406
        $password = '';
399
        $possible = '2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ';
407
        $possible = '2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ';
400
        $maxlength = strlen($possible);
408
        $maxlength = strlen($possible);
401
        if ($length > $maxlength) {
409
        if ($length > $maxlength) {
Línea 409... Línea 417...
409
                $i++;
417
                $i++;
410
            }
418
            }
411
        }
419
        }
412
        return $password;
420
        return $password;
413
    }
421
    }
414
    
422
 
415
    
423
 
416
    
424
 
417
    /**
425
    /**
418
     * 
426
     * 
419
     * @param string $date
427
     * @param string $date
420
     * @param boolean $time_required
428
     * @param boolean $time_required
421
     * @return string
429
     * @return string
422
     */
430
     */
423
    public static function countRemainingDays(string $date, $time_required = true) 
431
    public static function countRemainingDays(string $date, $time_required = true)
424
    {
432
    {
425
        $datestr = $date;
433
        $datestr = $date;
426
        $date = strtotime($datestr);
434
        $date = strtotime($datestr);
427
        $diff = $date - time();
435
        $diff = $date - time();
428
        if ($time_required) {
436
        if ($time_required) {
Línea 432... Línea 440...
432
        } else {
440
        } else {
433
            $days = ceil($diff / (60 * 60 * 24));
441
            $days = ceil($diff / (60 * 60 * 24));
434
            return "$days days remaining";
442
            return "$days days remaining";
435
        }
443
        }
436
    }
444
    }
437
    
445
 
438
    /**
446
    /**
439
     * 
447
     * 
440
     * @param string $varPhoto
448
     * @param string $varPhoto
441
     * @param string $uploadDir
449
     * @param string $uploadDir
442
     * @param string $tmp_name
450
     * @param string $tmp_name
Línea 444... Línea 452...
444
     * @param string $file_nm
452
     * @param string $file_nm
445
     * @param boolean $addExt
453
     * @param boolean $addExt
446
     * @param array $crop_coords
454
     * @param array $crop_coords
447
     * @return string|boolean
455
     * @return string|boolean
448
     */
456
     */
449
    public static function generateThumbnail(string $varPhoto, string $uploadDir, string $tmp_name, $th_arr = array(), $file_nm = '', $addExt = true, $crop_coords = array()) 
457
    public static function generateThumbnail(string $varPhoto, string $uploadDir, string $tmp_name, $th_arr = array(), $file_nm = '', $addExt = true, $crop_coords = array())
450
    {
458
    {
451
        $ext = '.' . strtolower(self::getExt($varPhoto));
459
        $ext = '.' . strtolower(self::getExt($varPhoto));
452
        $tot_th = count($th_arr);
460
        $tot_th = count($th_arr);
453
        if (($ext == ".jpg" || $ext == ".gif" || $ext == ".png" || $ext == ".bmp" || $ext == ".jpeg" || $ext == ".ico")) {
461
        if (($ext == ".jpg" || $ext == ".gif" || $ext == ".png" || $ext == ".bmp" || $ext == ".jpeg" || $ext == ".ico")) {
454
            if (!file_exists($uploadDir)) {
462
            if (!file_exists($uploadDir)) {
455
                mkdir($uploadDir, 0777);
463
                mkdir($uploadDir, 0777);
456
            }
464
            }
457
            if ($file_nm == '')
465
            if ($file_nm == '')
458
                $imagename = rand() . time();
466
                $imagename = rand() . time();
459
                else
467
            else
460
                    $imagename = $file_nm;
468
                $imagename = $file_nm;
461
                    if ($addExt || $file_nm == '')
469
            if ($addExt || $file_nm == '')
462
                        $imagename = $imagename . $ext;
470
                $imagename = $imagename . $ext;
463
                        $pathToImages = $uploadDir . $imagename;
471
            $pathToImages = $uploadDir . $imagename;
464
                        $Photo_Source = copy($tmp_name, $pathToImages);
472
            $Photo_Source = copy($tmp_name, $pathToImages);
465
                        if ($Photo_Source) {
473
            if ($Photo_Source) {
466
                            for ($i = 0; $i < $tot_th; $i++) {
474
                for ($i = 0; $i < $tot_th; $i++) {
467
                                Functions::resizeImage($uploadDir . $imagename, $uploadDir . 'th' . ($i + 1) . '_' . $imagename, $th_arr[$i]['width'], $th_arr[$i]['height'], false, $crop_coords);
475
                    Functions::resizeImage($uploadDir . $imagename, $uploadDir . 'th' . ($i + 1) . '_' . $imagename, $th_arr[$i]['width'], $th_arr[$i]['height'], false, $crop_coords);
468
                            }
476
                }
469
                            return $imagename;
477
                return $imagename;
470
                        } else {
478
            } else {
471
                            return false;
479
                return false;
472
                        }
480
            }
473
        } else {
481
        } else {
474
            return false;
482
            return false;
475
        }
483
        }
476
    }
484
    }
477
    /**
485
    /**
Línea 483... Línea 491...
483
    {
491
    {
484
        $path_parts = pathinfo($file);
492
        $path_parts = pathinfo($file);
485
        $ext = $path_parts['extension'];
493
        $ext = $path_parts['extension'];
486
        return $ext;
494
        return $ext;
487
    }
495
    }
488
    
496
 
489
    
497
 
490
    /**
498
    /**
491
     *
499
     *
492
     * @param string $source
500
     * @param string $source
493
     * @param string $target_path
501
     * @param string $target_path
494
     * @param string $target_filename
502
     * @param string $target_filename
495
     * @param number $target_width
503
     * @param number $target_width
496
     * @param number $target_height
504
     * @param number $target_height
497
     * @return boolean
505
     * @return boolean
498
     */
506
     */
499
    public  static function uploadImage($source, $target_path, $target_filename, $target_width, $target_height )
507
    public  static function uploadImage($source, $target_path, $target_filename, $target_width, $target_height)
500
    {
508
    {
501
        try {
509
        try {
502
            
510
 
503
            $target_width = intval($target_width, 10);
511
            $target_width = intval($target_width, 10);
504
            $target_height = intval($target_height, 10);
512
            $target_height = intval($target_height, 10);
505
            
513
 
506
            $data = file_get_contents($source);
514
            $data = file_get_contents($source);
507
            $img = imagecreatefromstring($data);
515
            $img = imagecreatefromstring($data);
508
            
516
 
509
            if(!file_exists($target_path)) {
517
            if (!file_exists($target_path)) {
510
                mkdir($target_path, 0755);
518
                mkdir($target_path, 0755);
511
            }
519
            }
512
            
520
 
513
            if($img) {
521
            if ($img) {
514
                list($source_width, $source_height) = getimagesize($source);
522
                list($source_width, $source_height) = getimagesize($source);
515
                
523
 
516
                $width_ratio    = $target_width / $source_width;
524
                $width_ratio    = $target_width / $source_width;
517
                $height_ratio   = $target_height / $source_height;
525
                $height_ratio   = $target_height / $source_height;
518
                if($width_ratio > $height_ratio) {
526
                if ($width_ratio > $height_ratio) {
519
                    $resized_width = $target_width;
527
                    $resized_width = $target_width;
520
                    $resized_height = $source_height * $width_ratio;
528
                    $resized_height = $source_height * $width_ratio;
521
                } else {
529
                } else {
522
                    $resized_height = $target_height;
530
                    $resized_height = $target_height;
523
                    $resized_width = $source_width * $height_ratio;
531
                    $resized_width = $source_width * $height_ratio;
524
                }
532
                }
525
                
533
 
526
                $resized_width = intval(round($resized_width), 10);
534
                $resized_width = intval(round($resized_width), 10);
527
                $resized_height = intval(round($resized_height), 10);
535
                $resized_height = intval(round($resized_height), 10);
528
                
536
 
529
                $offset_width = intval(round(($target_width - $resized_width) / 2), 10);
537
                $offset_width = intval(round(($target_width - $resized_width) / 2), 10);
530
                $offset_height = intval(round(($target_height - $resized_height) / 2), 10);
538
                $offset_height = intval(round(($target_height - $resized_height) / 2), 10);
531
                
539
 
532
                
540
 
533
                $new_image = imageCreateTrueColor($target_width, $target_height);
541
                $new_image = imageCreateTrueColor($target_width, $target_height);
534
                imageAlphaBlending($new_image, False);
542
                imageAlphaBlending($new_image, False);
535
                imageSaveAlpha($new_image, True);
543
                imageSaveAlpha($new_image, True);
536
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
544
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
537
                imagefill($new_image, 0, 0, $transparent);
545
                imagefill($new_image, 0, 0, $transparent);
538
                imageCopyResampled($new_image, $img , $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
546
                imageCopyResampled($new_image, $img, $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
539
                
547
 
540
                
548
 
541
                $target = $target_path . DIRECTORY_SEPARATOR . $target_filename;
549
                $target = $target_path . DIRECTORY_SEPARATOR . $target_filename;
542
                if(file_exists($target)) {
550
                if (file_exists($target)) {
543
                    @unlink($target);
551
                    @unlink($target);
544
                }
552
                }
545
                
553
 
546
                
554
 
547
                imagepng($new_image, $target);
555
                imagepng($new_image, $target);
548
            }
556
            }
549
            
557
 
550
            unlink($source);
558
            unlink($source);
551
            
559
 
552
            return true;
560
            return true;
553
            
-
 
554
        }
-
 
555
        catch (\Throwable $e)
561
        } catch (\Throwable $e) {
556
        {
-
 
Línea 557... Línea 562...
557
 
562
 
558
            error_log($e->getTraceAsString());
563
            error_log($e->getTraceAsString());
559
            return false;
564
            return false;
560
        }
565
        }
561
    }
566
    }
562
    
567
 
563
    
568
 
564
    /**
569
    /**
565
     * 
570
     * 
566
     * @param string $source
571
     * @param string $source
567
     * @param string $target_path
572
     * @param string $target_path
568
     * @param string $target_filename
573
     * @param string $target_filename
569
     * @return boolean
574
     * @return boolean
570
     */
575
     */
571
    public  static function uploadFile($source, $target_path, $target_filename)
576
    public  static function uploadFile($source, $target_path, $target_filename)
572
    {
577
    {
573
        try {
578
        try {
574
            
579
 
575
            $target_filename = self::normalizeString(basename($target_filename));
580
            $target_filename = self::normalizeString(basename($target_filename));
576
            
581
 
577
            $parts = explode('.', $target_filename);
582
            $parts = explode('.', $target_filename);
578
            $basename = trim($parts[0]);
583
            $basename = trim($parts[0]);
579
            if(strlen($basename) > 220) {
584
            if (strlen($basename) > 220) {
580
                $basename = substr($basename, 0, 220);
585
                $basename = substr($basename, 0, 220);
581
            }
586
            }
582
            $basename = $basename . '-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
587
            $basename = $basename . '-' . uniqid() . '.' . $parts[count($parts) - 1];
583
            $full_filename = $target_path  . DIRECTORY_SEPARATOR . $basename;
588
            $full_filename = $target_path  . DIRECTORY_SEPARATOR . $basename;
584
            
589
 
585
            
590
 
586
            return move_uploaded_file($source, $full_filename);
-
 
587
            
-
 
588
        }
591
            return move_uploaded_file($source, $full_filename);
589
        catch (\Throwable $e)
-
 
590
        {
592
        } catch (\Throwable $e) {
591
            error_log($e->getTraceAsString());
593
            error_log($e->getTraceAsString());
592
            return false;
594
            return false;
593
        }
595
        }
594
    }
596
    }
595
    
597
 
596
    /**
598
    /**
597
     *
599
     *
598
     * @param string $path
600
     * @param string $path
599
     * @param string $prefix
601
     * @param string $prefix
600
     * @return boolean
602
     * @return boolean
601
     */
603
     */
602
    public static function delete($path, $prefix)
604
    public static function delete($path, $prefix)
603
    {
605
    {
604
        try {
606
        try {
605
            if (is_dir($path)){
607
            if (is_dir($path)) {
606
                if ($dh = opendir($path)) {
608
                if ($dh = opendir($path)) {
607
                    while (($file = readdir($dh)) !== false)
-
 
608
                    {
609
                    while (($file = readdir($dh)) !== false) {
609
                        if($file == '.' || $file == '..') {
610
                        if ($file == '.' || $file == '..') {
610
                            continue;
611
                            continue;
611
                        }
612
                        }
612
                        
613
 
613
                        if(strpos($file, $prefix) !== false) {
614
                        if (strpos($file, $prefix) !== false) {
614
                            unlink($path . DIRECTORY_SEPARATOR . $file);
615
                            unlink($path . DIRECTORY_SEPARATOR . $file);
615
                        }
616
                        }
616
                    }
617
                    }
617
                    closedir($dh);
618
                    closedir($dh);
618
                }
619
                }
619
            }
620
            }
620
            
621
 
621
            return true;
-
 
622
            
-
 
623
        }
622
            return true;
624
        catch (\Throwable $e)
-
 
625
        {
623
        } catch (\Throwable $e) {
626
            error_log($e->getTraceAsString());
624
            error_log($e->getTraceAsString());
627
            return false;
625
            return false;
628
        }
626
        }
629
    }
627
    }
630
    
628
 
631
    
629
 
632
    /**
630
    /**
633
     *
631
     *
634
     * @param string $path
632
     * @param string $path
635
     * @param string $filename
633
     * @param string $filename
636
     * @return boolean
634
     * @return boolean
637
     */
635
     */
638
    public static function deleteFilename($path, $filename)
636
    public static function deleteFilename($path, $filename)
639
    {
637
    {
640
        try {
638
        try {
641
            if (is_dir($path)){
639
            if (is_dir($path)) {
642
                if ($dh = opendir($path)) {
640
                if ($dh = opendir($path)) {
643
                    while (($file = readdir($dh)) !== false)
-
 
644
                    {
641
                    while (($file = readdir($dh)) !== false) {
645
                        if($file == '.' || $file == '..') {
642
                        if ($file == '.' || $file == '..') {
646
                            continue;
643
                            continue;
647
                        }
644
                        }
648
                        
645
 
649
                        if($file == $filename) {
646
                        if ($file == $filename) {
650
                            unlink($path . DIRECTORY_SEPARATOR . $file);
647
                            unlink($path . DIRECTORY_SEPARATOR . $file);
651
                        }
648
                        }
652
                    }
649
                    }
653
                    closedir($dh);
650
                    closedir($dh);
654
                }
651
                }
655
            }
652
            }
656
            
653
 
657
            return true;
-
 
658
            
-
 
659
        }
654
            return true;
660
        catch (\Throwable $e)
-
 
661
        {
655
        } catch (\Throwable $e) {
662
            error_log($e->getTraceAsString());
656
            error_log($e->getTraceAsString());
663
            return false;
657
            return false;
664
        }
658
        }
665
    }
659
    }
666
    
660
 
667
    
661
 
668
    /**
662
    /**
669
     *
663
     *
670
     * @param string $str
664
     * @param string $str
671
     * @return string
665
     * @return string
672
     */
666
     */
673
    public static function normalizeString ($str = '')
667
    public static function normalizeString($str = '')
674
    {
668
    {
675
        $str = strtolower($str);
669
        $str = strtolower($str);
676
        $str = trim($str);
670
        $str = trim($str);
677
        $str = strip_tags($str);
671
        $str = strip_tags($str);
678
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
672
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
679
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
673
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
680
        $str = strtolower($str);
674
        $str = strtolower($str);
681
        $str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
675
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
682
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
676
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
683
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
677
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
684
        $str = str_replace(' ', '-', $str);
678
        $str = str_replace(' ', '-', $str);
685
        $str = rawurlencode($str);
679
        $str = rawurlencode($str);
686
        $str = str_replace('%', '-', $str);
680
        $str = str_replace('%', '-', $str);
687
        return trim(strtolower($str));
681
        return trim(strtolower($str));
688
    }
682
    }
689
    
683
 
690
    public static function normalizeStringFilename($str = '')
684
    public static function normalizeStringFilename($str = '')
691
    {
685
    {
692
        $basename  = substr($str, 0, strrpos($str, '.'));
686
        $basename  = substr($str, 0, strrpos($str, '.'));
693
        $basename  = str_replace('.', '-', $basename);
687
        $basename  = str_replace('.', '-', $basename);
694
        
688
 
695
        $extension  = substr($str, strrpos($str, '.'));
689
        $extension  = substr($str, strrpos($str, '.'));
696
        
690
 
697
        $str = $basename . $extension;
691
        $str = $basename . $extension;
698
        
692
 
699
        $str = strip_tags($str);
693
        $str = strip_tags($str);
700
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
694
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
701
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
695
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
702
        $str = strtolower($str);
696
        $str = strtolower($str);
703
        $str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
697
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
704
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
698
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
705
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
699
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
706
        $str = str_replace(' ', '-', $str);
700
        $str = str_replace(' ', '-', $str);
707
        $str = rawurlencode($str);
701
        $str = rawurlencode($str);
708
        $str = str_replace('%', '-', $str);
702
        $str = str_replace('%', '-', $str);
709
        $str = str_replace(['-----', '----', '---', '--'], '-', $str);
703
        $str = str_replace(['-----', '----', '---', '--'], '-', $str);
710
        return trim(strtolower($str));
704
        return trim(strtolower($str));
Línea 711... Línea 705...
711
    }
705
    }
712
 
706
 
713
   
707
 
714
    
708
 
715
    
709
 
716
    /**
710
    /**
717
     *
711
     *
718
     * @return string
712
     * @return string
719
     */
713
     */
720
    public static function genUUID()
714
    public static function genUUID()
721
    {
715
    {
722
        
716
 
723
        $data = random_bytes(16);
717
        $data = random_bytes(16);
724
        $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
718
        $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
725
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
719
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
Línea 726... Línea 720...
726
        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
720
        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
Línea 727... Línea 721...
727
    }
721
    }
728
 
722
 
729
   
723
 
730
 
724
 
731
 
725
 
732
 
726
 
733
    /**
727
    /**
734
     * 
728
     * 
735
     * @param string $dir
729
     * @param string $dir
736
     */
-
 
737
    public static function rmDirRecursive(string $dir) 
730
     */
738
    {
731
    public static function rmDirRecursive(string $dir)
739
        if (is_dir($dir)) {
732
    {
740
            $objects = scandir($dir);
733
        if (is_dir($dir)) {
741
            foreach ($objects as $object) 
734
            $objects = scandir($dir);
Línea 750... Línea 743...
750
                }
743
                }
751
            }
744
            }
752
            rmdir($dir);
745
            rmdir($dir);
753
        }
746
        }
754
    }
747
    }
755
    
748
 
756
    /**
749
    /**
757
     *
750
     *
758
     * @param string $dir
751
     * @param string $dir
759
     */
752
     */
760
    public static function deleteFiles(string $dir)
753
    public static function deleteFiles(string $dir)
761
    {
754
    {
762
        if (is_dir($dir)) {
755
        if (is_dir($dir)) {
763
            $objects = scandir($dir);
756
            $objects = scandir($dir);
764
            foreach ($objects as $object)
757
            foreach ($objects as $object) {
765
            {
-
 
766
                if ($object != '.' && $object != '..') {
758
                if ($object != '.' && $object != '..') {
767
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
759
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
768
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
760
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
769
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
761
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
770
                    } else {
762
                    } else {
Línea 772... Línea 764...
772
                    }
764
                    }
773
                }
765
                }
774
            }
766
            }
775
        }
767
        }
776
    }
768
    }
777
    
769
 
Línea 778... Línea 770...
778
 
770
 
779
 
771
 
780
    /**
772
    /**
Línea 796... Línea 788...
796
        $response = curl_exec($ch);
788
        $response = curl_exec($ch);
797
        curl_close($ch);
789
        curl_close($ch);
798
        $json = json_decode($response);
790
        $json = json_decode($response);
799
        //print_r($json);
791
        //print_r($json);
800
        foreach ($json->results as $result) {
792
        foreach ($json->results as $result) {
801
            $address1='';
793
            $address1 = '';
802
            foreach($result->address_components as $addressPart) 
794
            foreach ($result->address_components as $addressPart) {
803
            {
-
 
804
                if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
795
                if ((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
805
                    $city = $addressPart->long_name;
796
                    $city = $addressPart->long_name;
806
                }
-
 
807
                else if((in_array('administrative_area_level_1', $addressPart->types)  && (in_array('political', $addressPart->types))) || (in_array('administrative_area_level_2', $addressPart->types) && (in_array('political', $addressPart->types)))){
797
                } else if ((in_array('administrative_area_level_1', $addressPart->types)  && (in_array('political', $addressPart->types))) || (in_array('administrative_area_level_2', $addressPart->types) && (in_array('political', $addressPart->types)))) {
808
                    $state = $addressPart->long_name;
798
                    $state = $addressPart->long_name;
809
                } else if((in_array('postal_code', $addressPart->types))){
799
                } else if ((in_array('postal_code', $addressPart->types))) {
810
                    $postal_code = $addressPart->long_name;
800
                    $postal_code = $addressPart->long_name;
811
                } else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
801
                } else if ((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
812
                    $country = $addressPart->long_name;
802
                    $country = $addressPart->long_name;
813
                } else {
803
                } else {
814
                    $address1 .= $addressPart->long_name.', ';
804
                    $address1 .= $addressPart->long_name . ', ';
815
                }
805
                }
816
            }
806
            }
817
            if(($city != '') && ($state != '') && ($country != '')) {
807
            if (($city != '') && ($state != '') && ($country != '')) {
818
                $address = $city.', '.$state.', '.$country;
808
                $address = $city . ', ' . $state . ', ' . $country;
819
            } else if(($city != '') && ($state != '')) {
809
            } else if (($city != '') && ($state != '')) {
820
                $address = $city.', '.$state;
810
                $address = $city . ', ' . $state;
821
            } else if(($state != '') && ($country != '')) {
811
            } else if (($state != '') && ($country != '')) {
822
                $address = $state.', '.$country;
812
                $address = $state . ', ' . $country;
823
            } else if($country != '') {
813
            } else if ($country != '') {
824
                $address = $country;
814
                $address = $country;
825
            }
815
            }
826
            
816
 
827
            $address1=trim($address1, ',');
817
            $address1 = trim($address1, ',');
828
            $array['country']=$country;
818
            $array['country'] = $country;
829
            $array['state']=$state;
819
            $array['state'] = $state;
830
            $array['city']=$city;
820
            $array['city'] = $city;
831
            $array['address']=$address1;
821
            $array['address'] = $address1;
832
            $array['postal_code']=$postal_code;
822
            $array['postal_code'] = $postal_code;
833
        }
823
        }
834
        $array['status']=$json->status;
824
        $array['status'] = $json->status;
835
        $array['lat'] = $json->results[0]->geometry->location->lat;
825
        $array['lat'] = $json->results[0]->geometry->location->lat;
836
        $array['long'] = $json->results[0]->geometry->location->lng;
826
        $array['long'] = $json->results[0]->geometry->location->lng;
837
        return $array;
827
        return $array;
838
    }
828
    }
839
    
829
 
Línea 840... Línea 830...
840
 
830
 
841
 
831
 
842
    /**
832
    /**
843
     * 
833
     * 
844
     * @param number $number
834
     * @param number $number
845
     * @param number $significance
835
     * @param number $significance
846
     * @return number|boolean
836
     * @return number|boolean
847
     */
837
     */
848
    public static function ceiling($number, $significance = 1) 
838
    public static function ceiling($number, $significance = 1)
849
    {
839
    {
850
        return ( is_numeric($number) && is_numeric($significance) ) ? (ceil($number / $significance) * $significance) : 0;
-
 
851
    }
-
 
852
 
-
 
853
    
-
 
854
 
-
 
855
 
-
 
856
    
-
 
857
    
840
        return (is_numeric($number) && is_numeric($significance)) ? (ceil($number / $significance) * $significance) : 0;
-
 
841
    }