Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1979 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Library;
6
 
7
abstract class Functions
8
{
9
    public static function getUserIP()
10
    {
11
        $client  = isset($_SERVER['HTTP_CLIENT_IP'])  ? $_SERVER['HTTP_CLIENT_IP'] : '';
12
        $forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
13
        $remote  = $_SERVER['REMOTE_ADDR'];
14
 
15
        if(filter_var($client, FILTER_VALIDATE_IP)) {
16
            $ip = $client;
17
        } elseif(filter_var($forward, FILTER_VALIDATE_IP)) {
18
            $ip = $forward;
19
        } else {
20
            $ip = $remote;
21
        }
22
 
23
        return $ip;
24
    }
25
 
26
 
27
    /**
28
     *
29
     * @param string $what
30
     * @param string $date
31
     * @return string
32
     */
33
    public static function convertDate($what, $date) {
34
        if ($what == 'wherecond') {
35
            return date('Y-m-d', strtotime($date));
36
        }
37
        else if ($what == 'display') {
38
            return date('d M, Y h:i A', strtotime($date));
39
        }
40
        else if ($what == 'displayWeb') {
41
            return date('d M Y', strtotime($date));
42
        }
43
        else if ($what == 'onlyDate') {
44
            return date(PHP_DATE_FORMAT, strtotime($date));
45
        }
46
        else if ($what == 'monthYear') {
47
            return date(PHP_DATE_FORMAT_MONTH_YEAR, strtotime($date));
48
        }
49
        else if ($what == 'onlyMonth') {
50
            return date(PHP_DATE_FORMAT_MONTH, strtotime($date));
51
        }
52
        else if ($what == 'gmail') {
53
            return date('D, M d, Y - h:i A', strtotime($date));
54
        }
55
        else if ($what == 'onlyDateForCSV') {
56
            return date('M d,Y', strtotime($date));
57
        }
58
        else {
59
            return date('Y-m-d', strtotime($date));
60
        }
61
    }
62
 
63
    /**
64
     *
65
     * @param int $ptime
66
     * @return string
67
     */
68
    public static function timeElapsedString(int $ptime)
69
    {
70
        $etime = time() - $ptime;
71
        if ($etime < 1) {
72
            return 'LABEL_ZERO_SECOND';
73
        }
74
        $a = array(365 * 24 * 60 * 60 => 'LABEL_YEAR_SMALL',
75
            30 * 24 * 60 * 60 => 'LABEL_MONTH_SMALL',
76
            24 * 60 * 60 => 'LABEL_DAY_SMALL',
77
            60 * 60 => 'LABEL_HOUR_SMALL',
78
            60 => 'LABEL_MINUTE_SMALL',
79
            1 => 'LABEL_SECOND_SMALL'
80
        );
81
        $a_plural = array('LABEL_YEAR_SMALL' => 'LABEL_YEARS_SMALL',
82
            'LABEL_MONTH_SMALL' => 'LABEL_MONTHS_SMALL',
83
            'LABEL_DAY_SMALL' => 'LABEL_DAYS_SMALL',
84
            'LABEL_HOUR_SMALL' => 'LABEL_HOURS_SMALL',
85
            'LABEL_MINUTE_SMALL' => 'LABEL_MINUTES_SMALL',
86
            'LABEL_SECOND_SMALL' => 'LABEL_SECONDS_SMALL'
87
        );
88
 
89
        foreach ($a as $secs => $str) {
90
            $d = $etime / $secs;
91
            if ($d >= 1) {
92
                $r = round($d);
93
                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
94
            }
95
        }
96
    }
97
 
98
 
99
    /**
100
     *
101
     * @param string $date1
102
     * @param string $date2
103
     * @param string $format
104
     */
105
    public static function getYears(string $date1, string $date2, string $format = 'YearMonth')
106
    {
107
        $date1 = new \DateTime($date1);
108
        $date2 = new \DateTime($date2);
109
        $interval = date_diff($date1, $date2);
110
        $months = $interval->m + ($interval->y * 12);
111
        return(int) ($months / 12);
112
    }
113
 
114
    /**
115
     *
116
     * @param number $length
117
     * @param string $seeds
118
     * @return string
119
     */
120
    public static function genrateRandom($length = 8, $seeds = 'alphanum')
121
    {
122
        $seedings = [
123
            'alpha' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
124
            'numeric' => '0123456789',
125
            'alphanum' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
126
            'hexidec' => '0123456789abcdef',
127
        ];
128
 
129
        if (isset($seedings[$seeds])) {
130
            $seeds = $seedings[$seeds];
131
        }
132
        list($usec, $sec) = explode(' ', microtime());
133
        $seed = (float) $sec + ((float) $usec * 100000);
134
        mt_srand($seed);
135
        $str = '';
136
        $seeds_count = strlen($seeds);
137
        for ($i = 0; $length > $i; $i++) {
138
            $pos = mt_rand(0, $seeds_count - 1);
139
 
140
            $str .= substr($seeds, $pos, $pos + 1);
141
        }
142
        return $str;
143
    }
144
 
145
    /**
146
     *
147
     * @param string $date1
148
     * @param string $date2
149
     * @param string $timeFormat
150
     * @param bool $positive
151
     * @return number
152
     */
153
    public static function getDateDiff(string $date1, string $date2, string $timeFormat = 'sec', bool $positive = false)
154
    {
155
        $dtTime1 = strtotime($date1);
156
        $dtTime2 = strtotime($date2);
157
        if ($positive === true) {
158
            if ($dtTime2 < $dtTime1) {
159
                $tmp = $dtTime1;
160
                $dtTime1 = $dtTime2;
161
                $dtTime2 = $tmp;
162
            }
163
        }
164
        $diff = $dtTime2 - $dtTime1;
165
        if ($timeFormat == 'sec') {
166
            return $diff;
167
        } else if ($timeFormat == 'day') {
168
            return $diff / 86400;
169
        }
170
    }
171
 
172
 
173
    /**
174
     *
175
     * @param string $date1
176
     * @param string $date2
177
     * @param string $format
178
     * @return string
179
     */
180
    public static function getDifference(string $date1, string $date2, string $format = 'YearMonth')
181
    {
182
        $difference = '';
183
        $datetime1 = date_create($date1);
184
        $datetime2 = date_create($date2);
185
        $interval = date_diff($datetime1, $datetime2);
186
        $years = $interval->format('%y');
187
        $months = $interval->format('%m');
188
        $days = $interval->format('%d');
189
        $years_text = $months_text = $days_text = '';
190
        if ($years == 1) {
191
            $years_text = '1 LABEL_YEAR';
192
        } else if ($years > 1) {
193
            $years_text = $years . ' LABEL_YEARS';
194
        }
195
        if ($months == 1) {
196
            $months_text = '1 LABEL_MONTH';
197
        } else if ($months > 1) {
198
            $months_text = $months . ' LABEL_MONTHS';
199
        }
200
        if ($days == 1) {
201
            $days_text = '1 LABEL_DAY';
202
        } else if ($days > 1) {
203
            $days_text = $days . ' LABEL_DAYS';
204
        }
205
        if ($format == 'Year') {
206
            return trim($years_text);
207
        } else if ($format == 'YearMonth') {
208
            $difference = trim($years_text) . ' ' . trim($months_text);
209
            return trim($difference);
210
        } else if ($format == 'YearMonthDay') {
211
            $difference = trim($years_text) . ' ' . trim($months_text) . ' ' . trim($days_text);
212
            return trim($difference);
213
        }
214
    }
215
 
216
    /**
217
     *
218
     * @param string $source
219
     * @param string $destination
220
     * @param int $quality
221
     * @return string
222
     */
223
    public static function compress(string $source, string $destination, int $quality = null)
224
    {
225
        $info = getimagesize($source);
226
        if ($info['mime'] == 'image/jpeg') {
227
            $image = imagecreatefromjpeg($source);
228
        }
229
        elseif ($info['mime'] == 'image/gif') {
230
            $image = imagecreatefromgif($source);
231
        }
232
        elseif ($info['mime'] == 'image/png') {
233
            $image = imagecreatefrompng($source);
234
        }
235
 
236
        imagejpeg($image, $destination, $quality);
237
        return $destination;
238
    }
239
 
240
    /**
241
     *
242
     * @param string $filename
243
     * @param string $newfilename
244
     * @param int $max_width
245
     * @param int $max_height
246
     * @param bool $withSampling
247
     * @param array $crop_coords
248
     * @return boolean
249
     */
250
    public static function resizeImage(string $filename, string $newfilename = "", int $max_width  = 0, int $max_height = 0, bool $withSampling = true, $crop_coords = array())
251
    {
252
        if (empty($newfilename)) {
253
            $newfilename = $filename;
254
        }
255
        $fileExtension = strtolower(self::getExt($filename));
256
        if ($fileExtension == 'jpg' || $fileExtension == 'jpeg') {
257
            $img = imagecreatefromjpeg($filename);
258
        } else if ($fileExtension == 'png') {
259
            $img = imagecreatefrompng($filename);
260
        } else if ($fileExtension == 'gif') {
261
            $img = imagecreatefromgif($filename);
262
        } else {
263
            $img = imagecreatefromjpeg($filename);
264
        }
265
        $width = imageSX($img);
266
        $height = imageSY($img);
267
        $target_width = $max_width;
268
        $target_height = $max_height;
269
        $target_ratio = $target_width / $target_height;
270
        $img_ratio = $width / $height;
271
        if (empty($crop_coords)) {
272
            if ($target_ratio > $img_ratio) {
273
                $new_height = $target_height;
274
                $new_width = $img_ratio * $target_height;
275
            } else {
276
                $new_height = $target_width / $img_ratio;
277
                $new_width = $target_width;
278
            }
279
            if ($new_height > $target_height) {
280
                $new_height = $target_height;
281
            }
282
            if ($new_width > $target_width) {
283
                $new_height = $target_width;
284
            }
285
            $new_img = imagecreatetruecolor($target_width, $target_height);
286
            $white = imagecolorallocate($new_img, 255, 255, 255);
287
            imagecolortransparent($new_img);
288
            imagefilledrectangle($new_img, 0, 0, $target_width - 1, $target_height - 1, $white);
289
            imagecopyresampled($new_img, $img, ($target_width - $new_width) / 2, ($target_height - $new_height) / 2, 0, 0, $new_width, $new_height, $width, $height);
290
        } else {
291
            $new_img = imagecreatetruecolor($target_width, $target_height);
292
            $white = imagecolorallocate($new_img, 255, 255, 255);
293
            imagefilledrectangle($new_img, 0, 0, $target_width - 1, $target_height - 1, $white);
294
            imagecopyresampled($new_img, $img, 0, 0, $crop_coords['x1'], $crop_coords['y1'], $target_width, $target_height, $crop_coords['x2'], $crop_coords['y2']);
295
        }
296
        if ($fileExtension == 'jpg' || $fileExtension == 'jpeg') {
297
            $createImageSave = imagejpeg($new_img, $newfilename);
298
        } else if ($fileExtension == 'png') {
299
            $createImageSave = imagepng($new_img, $newfilename);
300
        } else if ($fileExtension == 'gif') {
301
            $createImageSave = imagegif($new_img, $newfilename);
302
        } else {
303
            $createImageSave = imagejpeg($new_img, $newfilename);
304
        }
305
 
306
        return $createImageSave;
307
    }
308
 
309
    /**
310
     *
311
     * @param string $start
312
     * @param string $end
313
     * @return array
314
     */
315
    public static function getTimeDifference(string $start, string $end) {
316
        $uts = [
317
            'start' => strtotime($start),
318
            'end' => strtotime($end)
319
        ];
320
        if ($uts['start'] !== -1 && $uts['end'] !== -1) {
321
            if ($uts['end'] >= $uts['start']) {
322
                $diff = $uts['end'] - $uts['start'];
323
                if ($days = intval((floor($diff / 86400)))) {
324
                    $diff = $diff % 86400;
325
                }
326
                if ($hours = intval((floor($diff / 3600)))) {
327
                    $diff = $diff % 3600;
328
                }
329
                if ($minutes = intval((floor($diff / 60)))) {
330
                    $diff = $diff % 60;
331
                }
332
                $diff = intval($diff);
333
                return [
334
                    'days' => $days,
335
                    'hours' => $hours,
336
                    'minutes' => $minutes,
337
                    'seconds' => $diff
338
                ];
339
            } else {
340
                trigger_error("Ending date/time is earlier than the start date/time", E_USER_WARNING);
341
            }
342
        } else {
343
            trigger_error("Invalid date/time data detected", E_USER_WARNING);
344
        }
345
        return;
346
    }
347
 
348
    /**
349
     *
350
     * @param number $length
351
     * @return string
352
     */
353
    public static function generatePassword($length = 8)
354
    {
355
        $password = '';
356
        $possible = '2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ';
357
        $maxlength = strlen($possible);
358
        if ($length > $maxlength) {
359
            $length = $maxlength;
360
        }
361
        $i = 0;
362
        while ($i < $length) {
363
            $char = substr($possible, mt_rand(0, $maxlength - 1), 1);
364
            if (!strstr($password, $char)) {
365
                $password .= $char;
366
                $i++;
367
            }
368
        }
369
        return $password;
370
    }
371
 
372
 
373
 
374
    /**
375
     *
376
     * @param string $date
377
     * @param boolean $time_required
378
     * @return string
379
     */
380
    public static function countRemainingDays(string $date, $time_required = true)
381
    {
382
        $datestr = $date;
383
        $date = strtotime($datestr);
384
        $diff = $date - time();
385
        if ($time_required) {
386
            $days = floor($diff / (60 * 60 * 24));
387
            $hours = round(($diff - $days * 60 * 60 * 24) / (60 * 60));
388
            return "$days days $hours hours remaining";
389
        } else {
390
            $days = ceil($diff / (60 * 60 * 24));
391
            return "$days days remaining";
392
        }
393
    }
394
 
395
    /**
396
     *
397
     * @param string $varPhoto
398
     * @param string $uploadDir
399
     * @param string $tmp_name
400
     * @param array $th_arr
401
     * @param string $file_nm
402
     * @param boolean $addExt
403
     * @param array $crop_coords
404
     * @return string|boolean
405
     */
406
    public static function generateThumbnail(string $varPhoto, string $uploadDir, string $tmp_name, $th_arr = array(), $file_nm = '', $addExt = true, $crop_coords = array())
407
    {
408
        $ext = '.' . strtolower(self::getExt($varPhoto));
409
        $tot_th = count($th_arr);
410
        if (($ext == ".jpg" || $ext == ".gif" || $ext == ".png" || $ext == ".bmp" || $ext == ".jpeg" || $ext == ".ico")) {
411
            if (!file_exists($uploadDir)) {
412
                mkdir($uploadDir, 0777);
413
            }
414
            if ($file_nm == '')
415
                $imagename = rand() . time();
416
                else
417
                    $imagename = $file_nm;
418
                    if ($addExt || $file_nm == '')
419
                        $imagename = $imagename . $ext;
420
                        $pathToImages = $uploadDir . $imagename;
421
                        $Photo_Source = copy($tmp_name, $pathToImages);
422
                        if ($Photo_Source) {
423
                            for ($i = 0; $i < $tot_th; $i++) {
424
                                Functions::resizeImage($uploadDir . $imagename, $uploadDir . 'th' . ($i + 1) . '_' . $imagename, $th_arr[$i]['width'], $th_arr[$i]['height'], false, $crop_coords);
425
                            }
426
                            return $imagename;
427
                        } else {
428
                            return false;
429
                        }
430
        } else {
431
            return false;
432
        }
433
    }
434
    /**
435
     *
436
     * @param string $file
437
     * @return mixed
438
     */
439
    public static function getExt(string $file)
440
    {
441
        $path_parts = pathinfo($file);
442
        $ext = $path_parts['extension'];
443
        return $ext;
444
    }
445
 
446
 
447
    /**
448
     *
449
     * @param string $source
450
     * @param string $target_path
451
     * @param string $target_filename
452
     * @param number $target_width
453
     * @param number $target_height
454
     * @return boolean
455
     */
456
    public  static function uploadImage($source, $target_path, $target_filename, $target_width, $target_height )
457
    {
458
        try {
459
            $data = file_get_contents($source);
460
            $img = imagecreatefromstring($data);
461
 
462
            if(!file_exists($target_path)) {
463
                mkdir($target_path, 0755);
464
            }
465
 
466
            if($img) {
467
                list($source_width, $source_height) = getimagesize($source);
468
 
469
                $width_ratio    = $target_width / $source_width;
470
                $height_ratio   = $target_height / $source_height;
471
                if($width_ratio > $height_ratio) {
472
                    $resized_width = $target_width;
473
                    $resized_height = $source_height * $width_ratio;
474
                } else {
475
                    $resized_height = $target_height;
476
                    $resized_width = $source_width * $height_ratio;
477
                }
478
 
479
                $resized_width = round($resized_width);
480
                $resized_height = round($resized_height);
481
 
482
                $offset_width = round(($target_width - $resized_width) / 2);
483
                $offset_height = round(($target_height - $resized_height) / 2);
484
 
485
 
486
                $new_image = imageCreateTrueColor($target_width, $target_height);
487
                imageAlphaBlending($new_image, False);
488
                imageSaveAlpha($new_image, True);
489
                $transparent = imageColorAllocateAlpha($new_image, 0, 0, 0, 127);
490
                imagefill($new_image, 0, 0, $transparent);
491
                imageCopyResampled($new_image, $img , $offset_width, $offset_height, 0, 0, $resized_width, $resized_height, $source_width, $source_height);
492
 
493
 
494
                $target = $target_path . DIRECTORY_SEPARATOR . $target_filename;
495
                if(file_exists($target)) {
496
                    @unlink($target);
497
                }
498
 
499
 
500
                imagepng($new_image, $target);
501
            }
502
 
503
            unlink($source);
504
 
505
            return true;
506
 
507
        }
508
        catch (\Throwable $e)
509
        {
510
            error_log($e->getTraceAsString());
511
            return false;
512
        }
513
    }
514
 
515
 
516
    /**
517
     *
518
     * @param string $source
519
     * @param string $target_path
520
     * @param string $target_filename
521
     * @return boolean
522
     */
523
    public  static function uploadFile($source, $target_path, $target_filename)
524
    {
525
        try {
526
 
527
            $target_filename = self::normalizeString(basename($target_filename));
528
 
529
            $parts = explode('.', $target_filename);
530
            $basename = trim($parts[0]);
531
            if(strlen($basename) > 220) {
532
                $basename = substr($basename, 0, 220);
533
            }
534
            $basename = $basename . '-' . uniqid() . '.' . $parts[1];
535
            $full_filename = $target_path  . DIRECTORY_SEPARATOR . $basename;
536
 
537
 
538
            return move_uploaded_file($source, $full_filename);
539
 
540
        }
541
        catch (\Throwable $e)
542
        {
543
            error_log($e->getTraceAsString());
544
            return false;
545
        }
546
    }
547
 
548
    /**
549
     *
550
     * @param string $path
551
     * @param string $prefix
552
     * @return boolean
553
     */
554
    public static function delete($path, $prefix)
555
    {
556
        try {
557
            if (is_dir($path)){
558
                if ($dh = opendir($path)) {
559
                    while (($file = readdir($dh)) !== false)
560
                    {
561
                        if($file == '.' || $file == '..') {
562
                            continue;
563
                        }
564
 
565
                        if(strpos($file, $prefix) !== false) {
566
                            unlink($path . DIRECTORY_SEPARATOR . $file);
567
                        }
568
                    }
569
                    closedir($dh);
570
                }
571
            }
572
 
573
            return true;
574
 
575
        }
576
        catch (\Throwable $e)
577
        {
578
            error_log($e->getTraceAsString());
579
            return false;
580
        }
581
    }
582
 
583
 
584
    /**
585
     *
586
     * @param string $str
587
     * @return string
588
     */
589
    public static function normalizeString ($str = '')
590
    {
591
        $str = strtolower($str);
592
        $str = trim($str);
593
        $str = strip_tags($str);
594
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
595
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
596
        $str = strtolower($str);
597
        $str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
598
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
599
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
600
        $str = str_replace(' ', '-', $str);
601
        $str = rawurlencode($str);
602
        $str = str_replace('%', '-', $str);
603
        return trim(strtolower($str));
604
    }
605
 
606
 
607
 
608
 
609
    /**
610
     *
611
     * @return string
612
     */
613
    public static function genUUID()
614
    {
615
 
616
        $data = random_bytes(16);
617
        $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
618
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
619
        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
620
    }
621
 
622
 
623
 
624
 
625
 
626
    /**
627
     *
628
     * @param string $dir
629
     */
630
    public static function rmDirRecursive(string $dir)
631
    {
632
        if (is_dir($dir)) {
633
            $objects = scandir($dir);
634
            foreach ($objects as $object)
635
            {
636
                if ($object != '.' && $object != '..') {
637
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
638
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
639
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
640
                    } else {
641
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
642
                    }
643
                }
644
            }
645
            rmdir($dir);
646
        }
647
    }
648
 
649
    /**
650
     *
651
     * @param string $dir
652
     */
653
    public static function deleteFiles(string $dir)
654
    {
655
        if (is_dir($dir)) {
656
            $objects = scandir($dir);
657
            foreach ($objects as $object)
658
            {
659
                if ($object != '.' && $object != '..') {
660
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
661
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
662
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
663
                    } else {
664
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
665
                    }
666
                }
667
            }
668
        }
669
    }
670
 
671
 
672
 
673
    /**
674
     *
675
     * @param string $address
676
     * @return  array
677
     */
678
    public static function reverseGeocode(string $address)
679
    {
680
        $array = [];
681
        $address = str_replace(" ", "+", $address);
682
        $url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false";
683
        $ch = curl_init();
684
        curl_setopt($ch, CURLOPT_URL, $url);
685
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
686
        curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
687
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
688
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
689
        $response = curl_exec($ch);
690
        curl_close($ch);
691
        $json = json_decode($response);
692
        //print_r($json);
693
        foreach ($json->results as $result) {
694
            $address1='';
695
            foreach($result->address_components as $addressPart)
696
            {
697
                if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
698
                    $city = $addressPart->long_name;
699
                }
700
                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)))){
701
                    $state = $addressPart->long_name;
702
                } else if((in_array('postal_code', $addressPart->types))){
703
                    $postal_code = $addressPart->long_name;
704
                } else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
705
                    $country = $addressPart->long_name;
706
                } else {
707
                    $address1 .= $addressPart->long_name.', ';
708
                }
709
            }
710
            if(($city != '') && ($state != '') && ($country != '')) {
711
                $address = $city.', '.$state.', '.$country;
712
            } else if(($city != '') && ($state != '')) {
713
                $address = $city.', '.$state;
714
            } else if(($state != '') && ($country != '')) {
715
                $address = $state.', '.$country;
716
            } else if($country != '') {
717
                $address = $country;
718
            }
719
 
720
            $address1=trim($address1, ',');
721
            $array['country']=$country;
722
            $array['state']=$state;
723
            $array['city']=$city;
724
            $array['address']=$address1;
725
            $array['postal_code']=$postal_code;
726
        }
727
        $array['status']=$json->status;
728
        $array['lat'] = $json->results[0]->geometry->location->lat;
729
        $array['long'] = $json->results[0]->geometry->location->lng;
730
        return $array;
731
    }
732
 
733
 
734
 
735
    /**
736
     *
737
     * @param number $number
738
     * @param number $significance
739
     * @return number|boolean
740
     */
741
    public static function ceiling($number, $significance = 1)
742
    {
743
        return ( is_numeric($number) && is_numeric($significance) ) ? (ceil($number / $significance) * $significance) : 0;
744
    }
745
 
746
 
747
 
748
 
749
 
750
 
751
}