Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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