Proyectos de Subversion LeadersLinked - Services

Rev

Rev 334 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 334 Rev 345
Línea 4... Línea 4...
4
 
4
 
Línea 5... Línea 5...
5
namespace LeadersLinked\Library;
5
namespace LeadersLinked\Library;
6
 
6
 
7
abstract class Functions
-
 
8
{
-
 
9
    /**
-
 
10
     *
-
 
11
     * @param \Laminas\Http\Response $response
-
 
12
     * @param string|array $content
-
 
13
     */
-
 
14
    public static function sendResponseJson($response, $content)
-
 
15
    {
-
 
16
        if(is_array($content)) {
-
 
17
            $content = json_encode($content);
-
 
18
        }
-
 
19
        
-
 
20
        
-
 
21
        $headers = $response->getHeaders();
-
 
22
        $headers->clearHeaders();
-
 
23
        $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
-
 
24
        
-
 
25
        Functions::addCrossSiteToResponse($response);
-
 
26
        
-
 
27
        $response->setStatusCode(200);
-
 
28
        $response->setContent($content); //json_encode($data));
-
 
29
        $response->send();
-
 
30
        exit;    
-
 
31
    
-
 
32
    }
-
 
33
    
-
 
34
    
-
 
35
    /**
-
 
36
     * 
-
 
37
     * @param \Laminas\Http\Response $response
-
 
38
     */
-
 
39
    public static function addCrossSiteToResponse($response)
-
 
40
    {
-
 
41
        $headers = $response->getHeaders();
-
 
42
        $headers->addHeaderLine('Access-Control-Allow-Origin', '*');
-
 
43
        $headers->addHeaderLine('Access-Control-Allow-Headers', '*');
-
 
44
        $headers->addHeaderLine('Access-Control-Allow-Method', 'POST, GET, HEAD, OPTIONS');
-
 
45
        $headers->addHeaderLine('Access-Control-Max-Age', '86400');
-
 
46
    }
7
abstract class Functions
47
    
8
{
48
    public static function utf8_decode($value)
9
    public static function utf8_decode($value)
49
    {
10
    {
Línea 80... Línea 41...
80
    {
41
    {
81
        if(empty($value)) {
42
        if(empty($value)) {
82
            return '';
43
            return '';
83
        }
44
        }
Línea -... Línea 45...
-
 
45
        
-
 
46
        $value = strval($value);
-
 
47
        
Línea 84... Línea 48...
84
        
48
        
85
        
49
        
86
        $noQuotes = in_array(FILTER_FLAG_NO_ENCODE_QUOTES, $flags);
50
        $noQuotes = in_array(FILTER_FLAG_NO_ENCODE_QUOTES, $flags);
Línea 96... Línea 60...
96
        // https://stackoverflow.com/questions/64083440/use-php-htmlentities-to-convert-special-characters-to-their-entity-number-rather
60
        // https://stackoverflow.com/questions/64083440/use-php-htmlentities-to-convert-special-characters-to-their-entity-number-rather
97
        $value = str_replace([""", "'"], [""", "'"], $value);
61
        $value = str_replace([""", "'"], [""", "'"], $value);
Línea 98... Línea 62...
98
        
62
        
99
        // Decode all entities
63
        // Decode all entities
100
        $value = html_entity_decode($value, $optionsDecode);
64
        $value = html_entity_decode($value, $optionsDecode);
101
       
65
        
102
        return trim($value);
66
        return trim($value);
103
       
67
        
Línea -... Línea 68...
-
 
68
    }
104
    }
69
    
-
 
70
    /**
-
 
71
     *
105
    
72
     * @return string
106
    
73
     */
107
    public static function getUserIP()
74
    public static function getUserIP()
108
    {
75
    {
109
        $client  = isset($_SERVER['HTTP_CLIENT_IP'])  ? $_SERVER['HTTP_CLIENT_IP'] : '';
76
        $client  = isset($_SERVER['HTTP_CLIENT_IP'])  ? $_SERVER['HTTP_CLIENT_IP'] : '';
Línea 110... Línea 77...
110
        $forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
77
        $forward = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
111
        $remote  = $_SERVER['REMOTE_ADDR'];
78
        $remote  = $_SERVER['REMOTE_ADDR'];
112
        
79
        
113
        if(filter_var($client, FILTER_VALIDATE_IP)) {
80
        if (filter_var($client, FILTER_VALIDATE_IP)) {
114
            $ip = $client;
81
            $ip = $client;
115
        } elseif(filter_var($forward, FILTER_VALIDATE_IP)) {
82
        } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
116
            $ip = $forward;
83
            $ip = $forward;
Línea 117... Línea 84...
117
        } else {
84
        } else {
118
            $ip = $remote;
85
            $ip = $remote;
Línea 119... Línea 86...
119
        }
86
        }
120
        
87
        
121
        return $ip;
88
        return $ip;
122
    }
89
    }
123
    
90
    
124
   
91
    
125
    /**
92
    /**
126
     * 
93
     *
-
 
94
     * @param string $what
127
     * @param string $what
95
     * @param string $date
128
     * @param string $date
96
     * @return string
129
     * @return string
-
 
130
     */
97
     */
131
    public static function convertDate($what, $date) {
98
    public static function convertDate($what, $date)
132
        if ($what == 'wherecond') {
-
 
133
            return date('Y-m-d', strtotime($date));
99
    {
134
        }  
100
        if ($what == 'wherecond') {
135
        else if ($what == 'display') {
-
 
136
            return date('d M, Y h:i A', strtotime($date));
101
            return date('Y-m-d', strtotime($date));
137
        } 
102
        } else if ($what == 'display') {
138
        else if ($what == 'displayWeb') {
-
 
139
            return date('d M Y', strtotime($date));
103
            return date('d M, Y h:i A', strtotime($date));
140
        }
104
        } else if ($what == 'displayWeb') {
141
        else if ($what == 'onlyDate') {
-
 
142
            return date(PHP_DATE_FORMAT, strtotime($date));
105
            return date('d M Y', strtotime($date));
143
        } 
106
        } else if ($what == 'onlyDate') {
144
        else if ($what == 'monthYear') {
-
 
145
            return date(PHP_DATE_FORMAT_MONTH_YEAR, strtotime($date));
107
            return date(PHP_DATE_FORMAT, strtotime($date));
146
        } 
108
        } else if ($what == 'monthYear') {
147
        else if ($what == 'onlyMonth') {
-
 
148
            return date(PHP_DATE_FORMAT_MONTH, strtotime($date));
109
            return date(PHP_DATE_FORMAT_MONTH_YEAR, strtotime($date));
149
        }
110
        } else if ($what == 'onlyMonth') {
150
        else if ($what == 'gmail') {
-
 
151
            return date('D, M d, Y - h:i A', strtotime($date));
111
            return date(PHP_DATE_FORMAT_MONTH, strtotime($date));
152
        } 
112
        } else if ($what == 'gmail') {
153
        else if ($what == 'onlyDateForCSV') {
113
            return date('D, M d, Y - h:i A', strtotime($date));
154
            return date('M d,Y', strtotime($date));
114
        } else if ($what == 'onlyDateForCSV') {
Línea 155... Línea 115...
155
        } 
115
            return date('M d,Y', strtotime($date));
156
        else {
116
        } else {
-
 
117
            return date('Y-m-d', strtotime($date));
-
 
118
        }
-
 
119
    }
-
 
120
    
-
 
121
    /**
-
 
122
     *
-
 
123
     * @return string[]
-
 
124
     */
-
 
125
    public static function getAllTimeZones()
-
 
126
    {
-
 
127
        $timezones =  [];
-
 
128
        $zones = \DateTimeZone::listIdentifiers();
-
 
129
        
-
 
130
        foreach ($zones as $zone) {
-
 
131
            array_push($timezones, $zone);
-
 
132
        }
157
            return date('Y-m-d', strtotime($date));
133
        
158
        }
134
        return $timezones;
159
    }
135
    }
160
    
136
    
161
    /**
137
    /**
162
     *
138
     *
Línea 163... Línea 139...
163
     * @param string $timestamp
139
     * @param string $timestamp
164
     * @param string $now
140
     * @param string $now
165
     * @return string
141
     * @return string
166
     */
142
     */
167
    public static function timeAgo($timestamp, $now = '')
143
    public static function timeAgo($timestamp, $now = '')
168
    {
144
    {
Línea 196... Línea 172...
196
            $timemsg = $timemsg . '';
172
            $timemsg = $timemsg . '';
197
        }
173
        }
198
        return $timemsg;
174
        return $timemsg;
199
    }
175
    }
Línea -... Línea 176...
-
 
176
    
200
    
177
    /*
201
    public static function geoCodeService($key, $address, $address1, $city, $state, $zip)
178
     public static function timeElapsedString(int $ptime, $now = null)
202
    {
-
 
203
        
-
 
204
        
-
 
205
        
179
     {
206
        $data = [];
-
 
207
        array_push($data, $address);
-
 
208
        array_push($data, $address1);
-
 
209
        array_push($data, $city);
180
     if($now)  {
210
        array_push($data, $state);
-
 
211
        array_push($data, $zip);
181
     $etime = $now - $ptime;
212
            
182
     
213
        $data = array_filter($data, function($value) { return !empty($value); } );
-
 
214
            
-
 
215
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?' . http_build_query(['address' => implode(',', $data), 'key' => $key]);
-
 
216
   
-
 
217
        
183
     } else {
-
 
184
     $etime = time() - $ptime;
218
        echo 'URL : ' . $url . '<br>';
185
     }
219
        
186
     
220
        
187
     
221
        $ch = curl_init();
188
     if ($etime < 1) {
-
 
189
     return 'LABEL_ZERO_SECOND';
222
        curl_setopt($ch, CURLOPT_URL,$url);
190
     }
223
        curl_setopt($ch, CURLOPT_POST, false);
191
     $a = array(365 * 24 * 60 * 60 => 'LABEL_YEAR_SMALL',
224
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
192
     30 * 24 * 60 * 60 => 'LABEL_MONTH_SMALL',
225
        $response  = curl_exec ($ch);
193
     24 * 60 * 60 => 'LABEL_DAY_SMALL',
226
        curl_close ($ch);
-
 
227
        
-
 
228
        
194
     60 * 60 => 'LABEL_HOUR_SMALL',
229
        $response = json_decode($response, true);
-
 
230
 
-
 
231
        $latitude   = isset($response['results'][0]['geometry']['location']['lat']) ? $response['results'][0]['geometry']['location']['lat'] : 0;
-
 
232
        $longitude  = isset($response['results'][0]['geometry']['location']['lng']) ? $response['results'][0]['geometry']['location']['lng'] : 0;
-
 
233
 
-
 
234
        return ['latitude' => $latitude, 'longitude' => $longitude];
-
 
235
    }
-
 
236
    
-
 
237
    /**
-
 
238
     * 
195
     60 => 'LABEL_MINUTE_SMALL',
239
     * @return string[]
196
     1 => 'LABEL_SECOND_SMALL'
240
     */
197
     );
241
    public static function getAllTimeZones()
-
 
242
    {
198
     $a_plural = array('LABEL_YEAR_SMALL' => 'LABEL_YEARS_SMALL',
243
        $timezones =  [];
199
     'LABEL_MONTH_SMALL' => 'LABEL_MONTHS_SMALL',
244
        $zones = \DateTimeZone::listIdentifiers();
-
 
245
 
200
     'LABEL_DAY_SMALL' => 'LABEL_DAYS_SMALL',
246
        foreach($zones as $zone)
-
 
247
        {
201
     'LABEL_HOUR_SMALL' => 'LABEL_HOURS_SMALL',
248
            array_push($timezones, $zone);
-
 
249
            
-
 
250
        }
-
 
251
        
202
     'LABEL_MINUTE_SMALL' => 'LABEL_MINUTES_SMALL',
252
        return $timezones;
203
     'LABEL_SECOND_SMALL' => 'LABEL_SECONDS_SMALL'
253
    }
204
     );
254
    
-
 
255
    /**
-
 
256
     * 
205
     
257
     * @param string $from_date
206
     foreach ($a as $secs => $str) {
258
     * @param string $from_timezone
207
     $d = $etime / $secs;
259
     * @param string $to_timezone
208
     if ($d >= 1) {
-
 
209
     $r = round($d);
260
     * @return string
210
     return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
261
     */
-
 
262
    public static function convertDateBetweenTimeZones($from_date, $from_timezone, $to_timezone)
211
     }
263
    {
-
 
264
        $date = new \DateTime($from_date, new \DateTimeZone($from_timezone)); 
-
 
265
        $date->setTimezone(new \DateTimeZone($to_timezone));
-
 
266
        return $date->format('Y-m-d H:i:s');
212
     }
Línea 267... Línea 213...
267
    }
213
     }*/
268
    
214
    
269
    
-
 
270
    /**
-
 
271
     *
-
 
272
     * @param string $from_datetime
-
 
273
     * @param string $from_timezone
-
 
274
     * @param string $to_timezone
-
 
275
     * @return string
-
 
276
     */
-
 
277
    public static function convertDateTimeBetweenTimeZones($from_datetime, $from_timezone, $to_timezone)
-
 
278
    {
-
 
279
        $date = new \DateTime($from_datetime, new \DateTimeZone($from_timezone));
-
 
280
        $date->setTimezone(new \DateTimeZone($to_timezone));
-
 
281
        return $date->format('Y-m-d H:i:s');
-
 
282
    }
-
 
283
 
-
 
284
    
-
 
285
    /*
-
 
286
    public static function timeElapsedString(int $ptime) 
-
 
287
    {
-
 
288
        $etime = time() - $ptime;
-
 
289
        if ($etime < 1) {
-
 
290
            return 'LABEL_ZERO_SECOND';
-
 
291
        }
-
 
292
        $a = array(365 * 24 * 60 * 60 => 'LABEL_YEAR_SMALL',
-
 
293
            30 * 24 * 60 * 60 => 'LABEL_MONTH_SMALL',
-
 
294
            24 * 60 * 60 => 'LABEL_DAY_SMALL',
-
 
295
            60 * 60 => 'LABEL_HOUR_SMALL',
-
 
296
            60 => 'LABEL_MINUTE_SMALL',
-
 
297
            1 => 'LABEL_SECOND_SMALL'
-
 
298
        );
-
 
299
        $a_plural = array('LABEL_YEAR_SMALL' => 'LABEL_YEARS_SMALL',
-
 
300
            'LABEL_MONTH_SMALL' => 'LABEL_MONTHS_SMALL',
-
 
301
            'LABEL_DAY_SMALL' => 'LABEL_DAYS_SMALL',
-
 
302
            'LABEL_HOUR_SMALL' => 'LABEL_HOURS_SMALL',
-
 
303
            'LABEL_MINUTE_SMALL' => 'LABEL_MINUTES_SMALL',
-
 
304
            'LABEL_SECOND_SMALL' => 'LABEL_SECONDS_SMALL'
-
 
305
        );
-
 
306
        
-
 
307
        foreach ($a as $secs => $str) {
-
 
308
            $d = $etime / $secs;
-
 
309
            if ($d >= 1) {
-
 
310
                $r = round($d);
-
 
311
                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
-
 
312
            }
-
 
313
        }
-
 
314
    }*/
-
 
315
    
-
 
316
 
215
    
317
    /**
216
    /**
318
     * 
217
     *
319
     * @param string $date1
218
     * @param string $date1
320
     * @param string $date2
219
     * @param string $date2
321
     * @param string $format
220
     * @param string $format
322
     */
221
     */
323
    public static function getYears(string $date1, string $date2, string $format = 'YearMonth') 
222
    public static function getYears(string $date1, string $date2, string $format = 'YearMonth')
324
    {
223
    {
325
        $date1 = new \DateTime($date1);
224
        $date1 = new \DateTime($date1);
326
        $date2 = new \DateTime($date2);
225
        $date2 = new \DateTime($date2);
327
        $interval = date_diff($date1, $date2);
226
        $interval = date_diff($date1, $date2);
Línea 328... Línea 227...
328
        $months = $interval->m + ($interval->y * 12);
227
        $months = $interval->m + ($interval->y * 12);
329
        return(int) ($months / 12);
228
        return (int) ($months / 12);
330
    }
229
    }
331
    
230
    
332
    /**
231
    /**
333
     * 
232
     *
334
     * @param number $length
233
     * @param number $length
335
     * @param string $seeds
234
     * @param string $seeds
336
     * @return string
235
     * @return string
337
     */
236
     */
338
    public static function genrateRandom($length = 8, $seeds = 'alphanum') 
237
    public static function genrateRandom($length = 8, $seeds = 'alphanum')
339
    {
238
    {
340
        $seedings = [
239
        $seedings = [
341
            'alpha' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
240
            'alpha' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
342
            'numeric' => '0123456789',
241
            'numeric' => '0123456789',
343
            'alphanum' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
242
            'alphanum' => 'abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
344
            'hexidec' => '0123456789abcdef',
243
            'hexidec' => '0123456789abcdef',
345
        ];
244
        ];
346
 
245
        
347
        if (isset($seedings[$seeds])) {
246
        if (isset($seedings[$seeds])) {
348
            $seeds = $seedings[$seeds];
-
 
349
        }
-
 
350
        list($usec, $sec) = explode(' ', microtime());
-
 
351
        $seed = (float) $sec + ((float) $usec * 100000);
247
            $seeds = $seedings[$seeds];
352
        
248
        }
353
   
249
        list($usec, $sec) = explode(' ', microtime());
354
        
250
        $seed = (float) $sec + ((float) $usec * 100000);
355
        mt_srand(intval($seed));
251
        mt_srand($seed);
Línea 362... Línea 258...
362
        }
258
        }
363
        return $str;
259
        return $str;
364
    }
260
    }
Línea 365... Línea 261...
365
    
261
    
366
    /**
262
    /**
367
     * 
263
     *
368
     * @param string $date1
264
     * @param string $date1
369
     * @param string $date2
265
     * @param string $date2
370
     * @param string $timeFormat
266
     * @param string $timeFormat
371
     * @param bool $positive
267
     * @param bool $positive
372
     * @return number
268
     * @return number
373
     */
269
     */
374
    public static function getDateDiff(string $date1, string $date2, string $timeFormat = 'sec', bool $positive = false) 
270
    public static function getDateDiff(string $date1, string $date2, string $timeFormat = 'sec', bool $positive = false)
375
    {
-
 
376
 
-
 
377
        
-
 
378
        
271
    {
379
        $dtTime1 = strtotime($date1);
272
        $dtTime1 = strtotime($date1);
380
        $dtTime2 = strtotime($date2);
-
 
381
        
-
 
382
 
273
        $dtTime2 = strtotime($date2);
383
        if ($positive === true) {
274
        if ($positive === true) {
384
            if ($dtTime2 < $dtTime1) {
275
            if ($dtTime2 < $dtTime1) {
385
                $tmp = $dtTime1;
276
                $tmp = $dtTime1;
386
                $dtTime1 = $dtTime2;
277
                $dtTime1 = $dtTime2;
387
                $dtTime2 = $tmp;
278
                $dtTime2 = $tmp;
388
            }
279
            }
389
        }
280
        }
390
        $diff = $dtTime2 - $dtTime1;
-
 
391
        
-
 
392
        /*
-
 
393
        echo 'date1 = ' . $date1 . '<br>';
-
 
394
        echo 'date2 = ' . $date2 . '<br>';
-
 
395
        echo 'dtTime1 = ' . $dtTime1 . '<br>';
-
 
396
        echo 'dtTime2 = ' . $dtTime2 . '<br>';
-
 
397
        echo 'diff = '.  $diff . '<br>';
-
 
398
        exit;
-
 
399
        */
-
 
400
        
281
        $diff = $dtTime2 - $dtTime1;
401
        if ($timeFormat == 'sec') {
282
        if ($timeFormat == 'sec') {
402
            return $diff;
283
            return $diff;
403
        } else if ($timeFormat == 'day') {
284
        } else if ($timeFormat == 'day') {
404
            return $diff / 86400;
285
            return $diff / 86400;
405
        }
286
        }
Línea 406... Línea 287...
406
    }
287
    }
407
    
288
    
408
    
289
    
409
    /**
290
    /**
410
     * 
291
     *
411
     * @param string $date1
292
     * @param string $date1
412
     * @param string $date2
293
     * @param string $date2
413
     * @param string $format
294
     * @param string $format
414
     * @return string
295
     * @return string
415
     */
296
     */
416
    public static function getDifference(string $date1, string $date2, string $format = 'YearMonth') 
297
    public static function getDifference(string $date1, string $date2, string $format = 'YearMonth')
417
    {
298
    {
418
        $difference = '';
299
        $difference = '';
Línea 448... Línea 329...
448
            return trim($difference);
329
            return trim($difference);
449
        }
330
        }
450
    }
331
    }
Línea 451... Línea 332...
451
    
332
    
452
    /**
333
    /**
453
     * 
334
     *
454
     * @param string $source
335
     * @param string $source
455
     * @param string $destination
336
     * @param string $destination
456
     * @param int $quality
337
     * @param int $quality
457
     * @return string
338
     * @return string
458
     */
339
     */
459
    public static function compress(string $source, string $destination, int $quality = null) 
340
    public static function compress(string $source, string $destination, int $quality = null)
460
    {
341
    {
461
        $info = getimagesize($source);
342
        $info = getimagesize($source);
462
        if ($info['mime'] == 'image/jpeg') {
343
        if ($info['mime'] == 'image/jpeg') {
463
            $image = imagecreatefromjpeg($source);
-
 
464
        }
344
            $image = imagecreatefromjpeg($source);
465
        elseif ($info['mime'] == 'image/gif') {
345
        } elseif ($info['mime'] == 'image/gif') {
466
            $image = imagecreatefromgif($source);
-
 
467
        }
346
            $image = imagecreatefromgif($source);
468
        elseif ($info['mime'] == 'image/png') {
347
        } elseif ($info['mime'] == 'image/png') {
469
            $image = imagecreatefrompng($source);
348
            $image = imagecreatefrompng($source);
470
        }
349
        }
471
            
350
        
472
        imagejpeg($image, $destination, $quality);
351
        imagejpeg($image, $destination, $quality);
473
        return $destination;
352
        return $destination;
Línea 474... Línea 353...
474
    }
353
    }
475
    
354
    
476
    /**
355
    /**
477
     * 
356
     *
478
     * @param string $filename
357
     * @param string $filename
479
     * @param string $newfilename
358
     * @param string $newfilename
480
     * @param int $max_width
359
     * @param int $max_width
481
     * @param int $max_height
360
     * @param int $max_height
482
     * @param bool $withSampling
361
     * @param bool $withSampling
483
     * @param array $crop_coords
362
     * @param array $crop_coords
484
     * @return boolean
363
     * @return boolean
485
     */
364
     */
486
    public static function resizeImage(string $filename, string $newfilename = "", int $max_width  = 0, int $max_height = 0, bool $withSampling = true, $crop_coords = array()) 
365
    public static function resizeImage(string $filename, string $newfilename = "", int $max_width  = 0, int $max_height = 0, bool $withSampling = true, $crop_coords = array())
487
    {
366
    {
488
        if (empty($newfilename)) {
367
        if (empty($newfilename)) {
489
            $newfilename = $filename;
368
            $newfilename = $filename;
Línea 541... Línea 420...
541
        
420
        
542
        return $createImageSave;
421
        return $createImageSave;
Línea 543... Línea 422...
543
    }
422
    }
544
    
423
    
545
    /**
424
    /**
546
     * 
425
     *
547
     * @param string $start
426
     * @param string $start
548
     * @param string $end
427
     * @param string $end
549
     * @return array
428
     * @return array
-
 
429
     */
550
     */
430
    public static function getTimeDifference(string $start, string $end)
551
    public static function getTimeDifference(string $start, string $end) {
431
    {
552
        $uts = [
432
        $uts = [
553
            'start' => strtotime($start),
433
            'start' => strtotime($start),
554
            'end' => strtotime($end)
434
            'end' => strtotime($end)
555
        ];   
435
        ];
556
        if ($uts['start'] !== -1 && $uts['end'] !== -1) {
436
        if ($uts['start'] !== -1 && $uts['end'] !== -1) {
557
            if ($uts['end'] >= $uts['start']) {
437
            if ($uts['end'] >= $uts['start']) {
558
                $diff = $uts['end'] - $uts['start'];
438
                $diff = $uts['end'] - $uts['start'];
Línea 580... Línea 460...
580
        }
460
        }
581
        return;
461
        return;
582
    }
462
    }
Línea 583... Línea 463...
583
    
463
    
584
    /**
464
    /**
585
     * 
465
     *
586
     * @param number $length
466
     * @param number $length
587
     * @return string
467
     * @return string
588
     */
468
     */
589
    public static function generatePassword($length = 8) 
469
    public static function generatePassword($length = 8)
590
    {
470
    {
591
        $password = '';
471
        $password = '';
592
        $possible = '2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ';
472
        $possible = '2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ';
593
        $maxlength = strlen($possible);
473
        $maxlength = strlen($possible);
Línea 606... Línea 486...
606
    }
486
    }
Línea 607... Línea 487...
607
    
487
    
608
    
488
    
609
    
489
    
610
    /**
490
    /**
611
     * 
491
     *
612
     * @param string $date
492
     * @param string $date
613
     * @param boolean $time_required
493
     * @param boolean $time_required
614
     * @return string
494
     * @return string
615
     */
495
     */
616
    public static function countRemainingDays(string $date, $time_required = true) 
496
    public static function countRemainingDays(string $date, $time_required = true)
617
    {
497
    {
618
        $datestr = $date;
498
        $datestr = $date;
Línea 627... Línea 507...
627
            return "$days days remaining";
507
            return "$days days remaining";
628
        }
508
        }
629
    }
509
    }
Línea 630... Línea 510...
630
    
510
    
631
    /**
511
    /**
632
     * 
512
     *
633
     * @param string $varPhoto
513
     * @param string $varPhoto
634
     * @param string $uploadDir
514
     * @param string $uploadDir
635
     * @param string $tmp_name
515
     * @param string $tmp_name
636
     * @param array $th_arr
516
     * @param array $th_arr
637
     * @param string $file_nm
517
     * @param string $file_nm
638
     * @param boolean $addExt
518
     * @param boolean $addExt
639
     * @param array $crop_coords
519
     * @param array $crop_coords
640
     * @return string|boolean
520
     * @return string|boolean
641
     */
521
     */
642
    public static function generateThumbnail(string $varPhoto, string $uploadDir, string $tmp_name, $th_arr = array(), $file_nm = '', $addExt = true, $crop_coords = array()) 
522
    public static function generateThumbnail(string $varPhoto, string $uploadDir, string $tmp_name, $th_arr = array(), $file_nm = '', $addExt = true, $crop_coords = array())
643
    {
523
    {
644
        $ext = '.' . strtolower(self::getExt($varPhoto));
524
        $ext = '.' . strtolower(self::getExt($varPhoto));
645
        $tot_th = count($th_arr);
525
        $tot_th = count($th_arr);
646
        if (($ext == ".jpg" || $ext == ".gif" || $ext == ".png" || $ext == ".bmp" || $ext == ".jpeg" || $ext == ".ico")) {
526
        if (($ext == ".jpg" || $ext == ".gif" || $ext == ".png" || $ext == ".bmp" || $ext == ".jpeg" || $ext == ".ico")) {
Línea 665... Línea 545...
665
                        }
545
                        }
666
        } else {
546
        } else {
667
            return false;
547
            return false;
668
        }
548
        }
669
    }
549
    }
-
 
550
    
-
 
551
    
-
 
552
    
-
 
553
    
-
 
554
    
-
 
555
    
-
 
556
    
-
 
557
    
-
 
558
    
-
 
559
    /**
-
 
560
     *
-
 
561
     * @param string $dir
-
 
562
     */
-
 
563
    public static function rmDirRecursive(string $dir)
-
 
564
    {
-
 
565
        if (is_dir($dir)) {
-
 
566
            $objects = scandir($dir);
-
 
567
            foreach ($objects as $object) {
-
 
568
                if ($object != '.' && $object != '..') {
-
 
569
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
-
 
570
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
-
 
571
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
-
 
572
                    } else {
-
 
573
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
-
 
574
                    }
-
 
575
                }
-
 
576
            }
-
 
577
            rmdir($dir);
-
 
578
        }
-
 
579
    }
-
 
580
    
-
 
581
    /**
-
 
582
     *
-
 
583
     * @param string $dir
-
 
584
     */
-
 
585
    public static function deleteFiles(string $dir)
-
 
586
    {
-
 
587
        if (is_dir($dir)) {
-
 
588
            $objects = scandir($dir);
-
 
589
            foreach ($objects as $object) {
-
 
590
                if ($object != '.' && $object != '..') {
-
 
591
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
-
 
592
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
-
 
593
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
-
 
594
                    } else {
-
 
595
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
-
 
596
                    }
-
 
597
                }
-
 
598
            }
-
 
599
        }
-
 
600
    }
-
 
601
    
-
 
602
    
-
 
603
    
-
 
604
    /**
-
 
605
     *
-
 
606
     * @param string $address
-
 
607
     * @return  array
-
 
608
     */
-
 
609
    public static function reverseGeocode(string $address)
-
 
610
    {
-
 
611
        $array = [];
-
 
612
        $address = str_replace(" ", "+", $address);
-
 
613
        $url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false";
-
 
614
        $ch = curl_init();
-
 
615
        curl_setopt($ch, CURLOPT_URL, $url);
-
 
616
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
 
617
        curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
-
 
618
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-
 
619
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-
 
620
        $response = curl_exec($ch);
-
 
621
        curl_close($ch);
-
 
622
        $json = json_decode($response);
-
 
623
        
-
 
624
        foreach ($json->results as $result) {
-
 
625
            $address1 = '';
-
 
626
            foreach ($result->address_components as $addressPart) {
-
 
627
                if ((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
-
 
628
                    $city = $addressPart->long_name;
-
 
629
                } 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)))) {
-
 
630
                    $state = $addressPart->long_name;
-
 
631
                } else if ((in_array('postal_code', $addressPart->types))) {
-
 
632
                    $postal_code = $addressPart->long_name;
-
 
633
                } else if ((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
-
 
634
                    $country = $addressPart->long_name;
-
 
635
                } else {
-
 
636
                    $address1 .= $addressPart->long_name . ', ';
-
 
637
                }
-
 
638
            }
-
 
639
            if (($city != '') && ($state != '') && ($country != '')) {
-
 
640
                $address = $city . ', ' . $state . ', ' . $country;
-
 
641
            } else if (($city != '') && ($state != '')) {
-
 
642
                $address = $city . ', ' . $state;
-
 
643
            } else if (($state != '') && ($country != '')) {
-
 
644
                $address = $state . ', ' . $country;
-
 
645
            } else if ($country != '') {
-
 
646
                $address = $country;
-
 
647
            }
-
 
648
            
-
 
649
            $address1 = trim($address1, ',');
-
 
650
            $array['country'] = $country;
-
 
651
            $array['state'] = $state;
-
 
652
            $array['city'] = $city;
-
 
653
            $array['address'] = $address1;
-
 
654
            $array['postal_code'] = $postal_code;
-
 
655
        }
-
 
656
        $array['status'] = $json->status;
-
 
657
        $array['lat'] = $json->results[0]->geometry->location->lat;
-
 
658
        $array['long'] = $json->results[0]->geometry->location->lng;
-
 
659
        return $array;
-
 
660
    }
-
 
661
    
-
 
662
    
-
 
663
    
-
 
664
    /**
-
 
665
     *
-
 
666
     * @param number $number
-
 
667
     * @param number $significance
-
 
668
     * @return number|boolean
-
 
669
     */
-
 
670
    public static function ceiling($number, $significance = 1)
-
 
671
    {
-
 
672
        return (is_numeric($number) && is_numeric($significance)) ? (ceil($number / $significance) * $significance) : 0;
-
 
673
    }
-
 
674
    
-
 
675
    
-
 
676
    /**
-
 
677
     *
-
 
678
     * @param \Laminas\Http\Response $response
-
 
679
     * @param string|array $content
-
 
680
     */
-
 
681
    public static function sendResponseJson($response, $content)
-
 
682
    {
-
 
683
        if(is_array($content)) {
-
 
684
            $content = json_encode($content);
-
 
685
        }
-
 
686
        
-
 
687
        
-
 
688
        $headers = $response->getHeaders();
-
 
689
        $headers->clearHeaders();
-
 
690
        $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
-
 
691
        
-
 
692
        Functions::addCrossSiteToResponse($response);
-
 
693
        
-
 
694
        $response->setStatusCode(200);
-
 
695
        $response->setContent($content); //json_encode($data));
-
 
696
        $response->send();
-
 
697
        exit;    
-
 
698
    
-
 
699
    }
-
 
700
    
-
 
701
    
-
 
702
    /**
-
 
703
     * 
-
 
704
     * @param \Laminas\Http\Response $response
-
 
705
     */
-
 
706
    public static function addCrossSiteToResponse($response)
-
 
707
    {
-
 
708
        $headers = $response->getHeaders();
-
 
709
        $headers->addHeaderLine('Access-Control-Allow-Origin', '*');
-
 
710
        $headers->addHeaderLine('Access-Control-Allow-Headers', '*');
-
 
711
        $headers->addHeaderLine('Access-Control-Allow-Method', 'POST, GET, HEAD, OPTIONS');
-
 
712
        $headers->addHeaderLine('Access-Control-Max-Age', '86400');
-
 
713
    }
-
 
714
    
-
 
715
 
-
 
716
    public static function geoCodeService($key, $address, $address1, $city, $state, $zip)
-
 
717
    {
-
 
718
        
-
 
719
        
-
 
720
        
-
 
721
        $data = [];
-
 
722
        array_push($data, $address);
-
 
723
        array_push($data, $address1);
-
 
724
        array_push($data, $city);
-
 
725
        array_push($data, $state);
-
 
726
        array_push($data, $zip);
-
 
727
            
-
 
728
        $data = array_filter($data, function($value) { return !empty($value); } );
-
 
729
            
-
 
730
        $url = 'https://maps.googleapis.com/maps/api/geocode/json?' . http_build_query(['address' => implode(',', $data), 'key' => $key]);
-
 
731
   
-
 
732
        
-
 
733
        echo 'URL : ' . $url . '<br>';
-
 
734
        
-
 
735
        
-
 
736
        $ch = curl_init();
-
 
737
        curl_setopt($ch, CURLOPT_URL,$url);
-
 
738
        curl_setopt($ch, CURLOPT_POST, false);
-
 
739
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
740
        $response  = curl_exec ($ch);
-
 
741
        curl_close ($ch);
-
 
742
        
-
 
743
        
-
 
744
        $response = json_decode($response, true);
-
 
745
 
-
 
746
        $latitude   = isset($response['results'][0]['geometry']['location']['lat']) ? $response['results'][0]['geometry']['location']['lat'] : 0;
-
 
747
        $longitude  = isset($response['results'][0]['geometry']['location']['lng']) ? $response['results'][0]['geometry']['location']['lng'] : 0;
-
 
748
 
-
 
749
        return ['latitude' => $latitude, 'longitude' => $longitude];
-
 
750
    }
-
 
751
    
-
 
752
 
-
 
753
    /**
-
 
754
     * 
-
 
755
     * @param string $from_date
-
 
756
     * @param string $from_timezone
-
 
757
     * @param string $to_timezone
-
 
758
     * @return string
-
 
759
     */
-
 
760
    public static function convertDateBetweenTimeZones($from_date, $from_timezone, $to_timezone)
-
 
761
    {
-
 
762
        $date = new \DateTime($from_date, new \DateTimeZone($from_timezone)); 
-
 
763
        $date->setTimezone(new \DateTimeZone($to_timezone));
-
 
764
        return $date->format('Y-m-d H:i:s');
-
 
765
    }
-
 
766
    
-
 
767
    
-
 
768
    /**
-
 
769
     *
-
 
770
     * @param string $from_datetime
-
 
771
     * @param string $from_timezone
-
 
772
     * @param string $to_timezone
-
 
773
     * @return string
-
 
774
     */
-
 
775
    public static function convertDateTimeBetweenTimeZones($from_datetime, $from_timezone, $to_timezone)
-
 
776
    {
-
 
777
        $date = new \DateTime($from_datetime, new \DateTimeZone($from_timezone));
-
 
778
        $date->setTimezone(new \DateTimeZone($to_timezone));
-
 
779
        return $date->format('Y-m-d H:i:s');
-
 
780
    }
-
 
781
 
-
 
782
    
-
 
783
    /*
-
 
784
    public static function timeElapsedString(int $ptime) 
-
 
785
    {
-
 
786
        $etime = time() - $ptime;
-
 
787
        if ($etime < 1) {
-
 
788
            return 'LABEL_ZERO_SECOND';
-
 
789
        }
-
 
790
        $a = array(365 * 24 * 60 * 60 => 'LABEL_YEAR_SMALL',
-
 
791
            30 * 24 * 60 * 60 => 'LABEL_MONTH_SMALL',
-
 
792
            24 * 60 * 60 => 'LABEL_DAY_SMALL',
-
 
793
            60 * 60 => 'LABEL_HOUR_SMALL',
-
 
794
            60 => 'LABEL_MINUTE_SMALL',
-
 
795
            1 => 'LABEL_SECOND_SMALL'
-
 
796
        );
-
 
797
        $a_plural = array('LABEL_YEAR_SMALL' => 'LABEL_YEARS_SMALL',
-
 
798
            'LABEL_MONTH_SMALL' => 'LABEL_MONTHS_SMALL',
-
 
799
            'LABEL_DAY_SMALL' => 'LABEL_DAYS_SMALL',
-
 
800
            'LABEL_HOUR_SMALL' => 'LABEL_HOURS_SMALL',
-
 
801
            'LABEL_MINUTE_SMALL' => 'LABEL_MINUTES_SMALL',
-
 
802
            'LABEL_SECOND_SMALL' => 'LABEL_SECONDS_SMALL'
-
 
803
        );
-
 
804
        
-
 
805
        foreach ($a as $secs => $str) {
-
 
806
            $d = $etime / $secs;
-
 
807
            if ($d >= 1) {
-
 
808
                $r = round($d);
-
 
809
                return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str);
-
 
810
            }
-
 
811
        }
-
 
812
    }*/
-
 
813
    
-
 
814
 
-
 
815
    
-
 
816
  
-
 
817
   
670
    /**
818
    /**
671
     * 
819
     * 
672
     * @param string $file
820
     * @param string $file
673
     * @return mixed
821
     * @return mixed
674
     */
822
     */
Línea 860... Línea 1008...
860
        $str = rawurlencode($str);
1008
        $str = rawurlencode($str);
861
        $str = str_replace('%', '-', $str);
1009
        $str = str_replace('%', '-', $str);
862
        $str = str_replace(['-----', '----', '---', '--'], '-', $str);
1010
        $str = str_replace(['-----', '----', '---', '--'], '-', $str);
863
        return trim(strtolower($str));
1011
        return trim(strtolower($str));
864
    }
1012
    }
-
 
1013
    
865
   
1014
 
Línea 866... Línea 1015...
866
    
1015
    
867
    
1016
    
868
    /**
1017
    /**
Línea 879... Línea 1028...
879
    }
1028
    }
Línea 880... Línea -...
880
 
-
 
881
   
-
 
882
 
-
 
883
 
-
 
884
 
-
 
885
    /**
-
 
886
     * 
-
 
887
     * @param string $dir
-
 
888
     */
-
 
889
    public static function rmDirRecursive(string $dir) 
-
 
890
    {
-
 
891
        if (is_dir($dir)) {
-
 
892
            $objects = scandir($dir);
-
 
893
            foreach ($objects as $object) 
-
 
894
            {
-
 
895
                if ($object != '.' && $object != '..') {
-
 
896
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
-
 
897
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
-
 
898
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
-
 
899
                    } else {
-
 
900
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
-
 
901
                    }
-
 
902
                }
-
 
Línea 903... Línea -...
903
            }
-
 
904
            rmdir($dir);
-
 
905
        }
-
 
906
    }
-
 
907
    
-
 
908
    /**
1029
 
909
     *
-
 
910
     * @param string $dir
-
 
911
     */
-
 
912
    public static function deleteFiles(string $dir)
-
 
913
    {
-
 
914
        if (is_dir($dir)) {
-
 
915
            $objects = scandir($dir);
-
 
916
            foreach ($objects as $object)
-
 
917
            {
-
 
918
                if ($object != '.' && $object != '..') {
-
 
919
                    if (is_dir($dir . DIRECTORY_SEPARATOR . $object)) {
-
 
920
                        self::rmDirRecursive($dir . DIRECTORY_SEPARATOR . $object);
-
 
921
                        rrmdir($dir . DIRECTORY_SEPARATOR . $object);
-
 
922
                    } else {
-
 
923
                        unlink($dir . DIRECTORY_SEPARATOR . $object);
-
 
Línea 924... Línea -...
924
                    }
-
 
925
                }
-
 
926
            }
-
 
927
        }
-
 
928
    }
-
 
929
    
-
 
930
 
-
 
931
 
-
 
932
    /**
-
 
933
     * 
-
 
934
     * @param string $address
-
 
935
     * @return  array
-
 
936
     */
-
 
937
    public static function reverseGeocode(string $address)
-
 
938
    {
-
 
939
        $array = [];
-
 
940
        $address = str_replace(" ", "+", $address);
-
 
941
        $url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false";
-
 
942
        $ch = curl_init();
-
 
943
        curl_setopt($ch, CURLOPT_URL, $url);
-
 
944
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
 
945
        curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
-
 
946
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-
 
947
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-
 
948
        $response = curl_exec($ch);
-
 
949
        curl_close($ch);
-
 
950
        $json = json_decode($response);
-
 
951
 
-
 
952
        foreach ($json->results as $result) {
-
 
953
            $address1='';
-
 
954
            foreach($result->address_components as $addressPart) 
-
 
955
            {
-
 
956
                if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
-
 
957
                    $city = $addressPart->long_name;
-
 
958
                }
-
 
959
                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)))){
-
 
960
                    $state = $addressPart->long_name;
-
 
961
                } else if((in_array('postal_code', $addressPart->types))){
-
 
962
                    $postal_code = $addressPart->long_name;
-
 
963
                } else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
-
 
964
                    $country = $addressPart->long_name;
-
 
965
                } else {
-
 
966
                    $address1 .= $addressPart->long_name.', ';
-
 
967
                }
-
 
968
            }
-
 
969
            if(($city != '') && ($state != '') && ($country != '')) {
-
 
970
                $address = $city.', '.$state.', '.$country;
-
 
971
            } else if(($city != '') && ($state != '')) {
-
 
972
                $address = $city.', '.$state;
-
 
973
            } else if(($state != '') && ($country != '')) {
-
 
974
                $address = $state.', '.$country;
-
 
975
            } else if($country != '') {
-
 
976
                $address = $country;
-
 
977
            }
-
 
978
            
-
 
979
            $address1=trim($address1, ',');
-
 
980
            $array['country']=$country;
-
 
981
            $array['state']=$state;
-
 
982
            $array['city']=$city;
-
 
983
            $array['address']=$address1;
-
 
984
            $array['postal_code']=$postal_code;
1030
   
Línea 985... Línea -...
985
        }
-
 
986
        $array['status']=$json->status;
-
 
987
        $array['lat'] = $json->results[0]->geometry->location->lat;
-
 
988
        $array['long'] = $json->results[0]->geometry->location->lng;
-
 
989
        return $array;
-
 
990
    }
-
 
991
    
-
 
992
 
-
 
993
 
-
 
994
    /**
-