-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp7.x.php
More file actions
520 lines (489 loc) · 15.6 KB
/
php7.x.php
File metadata and controls
520 lines (489 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<?php
/**
* PHP7 DEPRECATED FUNCTION SUPPORT
*
* @description This file fix removed functionality from PHP7 and add them back on the new way
* You just need to add this PHP file at the top of your enthire project and will
* work nice for you.
* @url https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
* @version 1.0.0
**/
if (version_compare(PHP_VERSION, '7.0.0', '>='))
{
/**
* @name eregi_replace
* @description eregi_replace — Replace regular expression case insensitive (PHP 5)
* @url http://php.adamharvey.name/manual/en/function.eregi-replace.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('eregi_replace')):
function eregi_replace ($pattern , $replacement , $string )
{
return preg_replace((preg_match('~^(.*?)i$~', $pattern) ? $pattern : $pattern.'i'), $replacement, $string);
}
endif;
/**
* @name ereg_replace
* @description ereg_replace — Replace regular expression (PHP 5)
* @url http://php.adamharvey.name/manual/en/function.eregi-replace.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('ereg_replace')):
function ereg_replace ($pattern , $replacement , $string )
{
return preg_replace($pattern, $replacement, $string);
}
endif;
/**
* @name split
* @description split — Split string into array by regular expression (PHP 4, PHP 5)
* @url http://php.net/manual/en/function.split.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('split')):
function split($pattern, $string, $limit = -1, $flags = 0)
{
if(@preg_match($pattern, NULL) === false){
if($limit === -1) $limit = PHP_INT_MAX;
return explode( $pattern , $string, $limit);
} else {
return preg_split( $pattern , $string, $limit, $flags);
}
}
endif;
/**
* @name call_user_method
* @description call_user_method — Call a user method on an specific object (PHP 4, PHP 5)
* @url http://php.net/manual/en/function.call-user-method.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('call_user_method')):
function call_user_method($method_name, &$obj, $parameter)
{
$numargs = func_num_args();
if ($numargs > 3) {
$arg_list = func_get_args();
unset($arg_list[0]);
unset($arg_list[1]);
unset($arg_list[2]);
call_user_func(array($obj, $method_name), $parameter, $arg_list);
} else {
call_user_func(array($obj, $method_name), $parameter);
}
}
endif;
/**
* @name call_user_method_array
* @description call_user_method_array — Call a user method given with an array of parameters (PHP 4 >= 4.0.5, PHP 5)
* @url http://php.net/manual/en/function.call-user-method-array.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('call_user_method_array')):
function call_user_method_array($method_name, &$obj, $params)
{
call_user_func_array(array($obj, $method_name), $params);
}
endif;
}
if (version_compare(PHP_VERSION, '7.2.0', '>='))
{
/**
* @name call_user_method_array
* @description call_user_method_array — Call a user method given with an array of parameters (PHP 4 >= 4.0.1, PHP 5, PHP 7) (eval() must be anabled)
* @url http://php.net/manual/en/function.create-function.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('create_function')):
function create_function($args, $code)
{
if(function_exists('eval'))
{
return eval("function ( {$args} ) { {$code} }");
}
return false;
}
endif;
}
if (version_compare(PHP_VERSION, '7.3.0', '>='))
{
/**
* @name FILTER_FLAG_SCHEME_REQUIRED
* @description Requires the URL to contain a scheme part. Used with: FILTER_VALIDATE_URL
* @url http://php.net/manual/en/filter.filters.flags.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!defined('FILTER_FLAG_SCHEME_REQUIRED'))
{
define('FILTER_FLAG_SCHEME_REQUIRED',65536);
}
/**
* @name FILTER_FLAG_HOST_REQUIRED
* @description Requires the URL to contain a host part. Used with: FILTER_VALIDATE_URL
* @url http://php.net/manual/en/filter.filters.flags.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!defined('FILTER_FLAG_HOST_REQUIRED'))
{
define('FILTER_FLAG_HOST_REQUIRED',131072);
}
/**
* @name image2wbmp
* @description image2wbmp — Output image to browser or file
* @url http://php.net/manual/en/function.image2wbmp.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('image2wbmp'))
{
function image2wbmp($image, $to=NULL, $foreground=0){
return imagewbmp($image, $to, $foreground);
}
}
}
if (version_compare(PHP_VERSION, '7.4.0', '>='))
{
/**
* @name get_magic_quotes_gpc
* @description get_magic_quotes_gpc — Gets the current configuration setting of magic_quotes_gpc
* @url https://www.php.net/manual/en/function.get-magic-quotes-gpc.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('get_magic_quotes_gpc'))
{
function get_magic_quotes_gpc() {
if(function_exists('ini_get')) {
return ini_get('magic_quotes_gpc');
}
return false;
}
}
/**
* @name money_format
* @description money_format — Formats a number as a currency string
* @url https://www.php.net/manual/en/function.money-format.php
* @author Nageen Nayak <https://stackoverflow.com/users/3996624/nageen-nayak>
**/
if(!function_exists('money_format'))
{
function money_format($format, $number) {
if (setlocale(LC_MONETARY, 0) == 'C') {
return number_format($number, 2);
}
$locale = localeconv();
$regex = '/^'. // Inicio da Expressao
'%'. // Caractere %
'(?:'. // Inicio das Flags opcionais
'\=([\w\040])'. // Flag =f
'|'.
'([\^])'. // Flag ^
'|'.
'(\+|\()'. // Flag + ou (
'|'.
'(!)'. // Flag !
'|'.
'(-)'. // Flag -
')*'. // Fim das flags opcionais
'(?:([\d]+)?)'. // W Largura de campos
'(?:#([\d]+))?'. // #n Precisao esquerda
'(?:\.([\d]+))?'. // .p Precisao direita
'([in%])'. // Caractere de conversao
'$/'; // Fim da Expressao
if (!preg_match($regex, $format, $matches)) {
trigger_error('Invalid format: '.$format, E_USER_WARNING);
return $number;
}
$options = array(
'preenchimento' => ($matches[1] !== '') ? $matches[1] : ' ',
'nao_agrupar' => ($matches[2] == '^'),
'usar_sinal' => ($matches[3] == '+'),
'usar_parenteses' => ($matches[3] == '('),
'ignorar_simbolo' => ($matches[4] == '!'),
'alinhamento_esq' => ($matches[5] == '-'),
'largura_campo' => ($matches[6] !== '') ? (int)$matches[6] : 0,
'precisao_esq' => ($matches[7] !== '') ? (int)$matches[7] : false,
'precisao_dir' => ($matches[8] !== '') ? (int)$matches[8] : $locale['int_frac_digits'],
'conversao' => $matches[9]
);
if ($options['usar_sinal'] && $locale['n_sign_posn'] == 0) {
$locale['n_sign_posn'] = 1;
} elseif ($options['usar_parenteses']) {
$locale['n_sign_posn'] = 0;
}
if ($options['precisao_dir']) {
$locale['frac_digits'] = $options['precisao_dir'];
}
if ($options['nao_agrupar']) {
$locale['mon_thousands_sep'] = '';
}
$tipo_sinal = $number >= 0 ? 'p' : 'n';
if ($options['ignorar_simbolo']) {
$simbolo = '';
} else {
$simbolo = $options['conversao'] == 'n' ? $locale['currency_symbol']
: $locale['int_curr_symbol'];
}
$numero = number_format(abs($number), $locale['frac_digits'], $locale['mon_decimal_point'], $locale['mon_thousands_sep']);
$sinal = $number >= 0 ? $locale['positive_sign'] : $locale['negative_sign'];
$simbolo_antes = $locale[$tipo_sinal.'_cs_precedes'];
$espaco1 = $locale[$tipo_sinal.'_sep_by_space'] == 1 ? ' ' : '';
$espaco2 = $locale[$tipo_sinal.'_sep_by_space'] == 2 ? ' ' : '';
$formatted = '';
switch ($locale[$tipo_sinal.'_sign_posn']) {
case 0:
if ($simbolo_antes) {
$formatted = '('.$simbolo.$espaco1.$numero.')';
} else {
$formatted = '('.$numero.$espaco1.$simbolo.')';
}
break;
case 1:
if ($simbolo_antes) {
$formatted = $sinal.$espaco2.$simbolo.$espaco1.$numero;
} else {
$formatted = $sinal.$numero.$espaco1.$simbolo;
}
break;
case 2:
if ($simbolo_antes) {
$formatted = $simbolo.$espaco1.$numero.$sinal;
} else {
$formatted = $numero.$espaco1.$simbolo.$espaco2.$sinal;
}
break;
case 3:
if ($simbolo_antes) {
$formatted = $sinal.$espaco2.$simbolo.$espaco1.$numero;
} else {
$formatted = $numero.$espaco1.$sinal.$espaco2.$simbolo;
}
break;
case 4:
if ($simbolo_antes) {
$formatted = $simbolo.$espaco2.$sinal.$espaco1.$numero;
} else {
$formatted = $numero.$espaco1.$simbolo.$espaco2.$sinal;
}
break;
}
if ($options['largura_campo'] > 0 && strlen($formatted) < $options['largura_campo']) {
$alinhamento = $options['alinhamento_esq'] ? STR_PAD_RIGHT : STR_PAD_LEFT;
$formatted = str_pad($formatted, $options['largura_campo'], $options['preenchimento'], $alinhamento);
}
return $formatted;
}
}
/**
* @name array_key_exists
* @description array_key_exists — Checks if the given key or index exists in the array
* @url https://www.php.net/manual/en/function.array-key-exists.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('array_key_exists'))
{
function array_key_exists($key, $array){
return is_array($array) ? isset($array[$key]) : (is_object($array) ? method_exists($array, $key) : false);
}
}
/**
* @name is_real
* @description Alias of is_float()
* @url https://www.php.net/manual/en/function.is-real.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('is_real'))
{
function is_real($var){
return is_float($var);
}
}
}
if (version_compare(PHP_VERSION, '7.3.0', '<')):
/**
* @name array_key_first
* @description array_key_first — Gets the first key of an array
* @url https://www.php.net/manual/en/function.array-key-first.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('array_key_first')) :
function array_key_first( $array ) {
if(is_array($array) && !empty($array))
{
reset($array);
if($key = key($array)) {
$array = NULL;
return $key;
}
}
return NULL;
}
endif;
/**
* @name array_key_last
* @description array_key_last — Gets the last key of an array
* @url https://www.php.net/manual/en/function.array-key-last.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('array_key_last')) :
function array_key_last( $array ) {
if(is_array($array) && !empty($array))
{
end($array);
if($key = key($array)) {
$array = NULL;
return $key;
}
}
return NULL;
}
endif;
endif;
/**
* @name is_a
* @description is_a — Checks if the object is of this class or has this class as one of its parents
* @info On the some PHP versions this function not exists. On that case we must return it back
* @url https://www.php.net/manual/en/function.is-a.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
if(!function_exists('is_a'))
{
function is_a($object, $class_name, $allow_string = false)
{
if($allow_string === false)
return ($object instanceof $class_name);
else
return is_subclass_of($object, $class_name, true);
}
}
/**
* @name Return missing constants
* @description This will give some older PHP versions constants that missing.
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
// Return WEBP constant
if(!defined('IMAGETYPE_WEBP')) {
define('IMAGETYPE_WEBP', 18);
}
// Return ICO constant
if(!defined('IMAGETYPE_ICO')) {
define('IMAGETYPE_ICO', 17);
}
// Fix missing PHP SESSION constant PHP_SESSION_NONE (this is bug on the some Nginx servers)
if (!defined('PHP_SESSION_NONE')) {
define('PHP_SESSION_NONE', -1);
}
/**
* @name MySQL
* @description Let's bring MySQL deprecated support on new way
* @url http://php.net/manual/en/book.mysql.php
* @author Ivijan-Stefan Stipic <infinitumform@gmail.com>
**/
$php7x_mysql_connect = NULL;
if(!function_exists('mysql_connect'))
{
function mysql_connect($server, $user, $password){
global $php7x_mysql_connect;
$php7x_mysql_connect = mysqli_connect($server, $user, $password);
return $php7x_mysql_connect;
}
}
if(!function_exists('mysql_select_db'))
{
function mysql_select_db($db){
global $php7x_mysql_connect;
return mysqli_select_db($php7x_mysql_connect, $db);
}
}
if(!function_exists('mysql_query'))
{
function mysql_query($query){
global $php7x_mysql_connect;
return mysqli_query($php7x_mysql_connect, $query);
}
}
if(!function_exists('mysql_fetch_object'))
{
function mysql_fetch_object($result){
return mysqli_fetch_object($result);
}
}
if(!function_exists('mysql_fetch_array'))
{
function mysql_fetch_array($result){
return mysqli_fetch_array($result);
}
}
if(!function_exists('mysql_fetch_row'))
{
function mysql_fetch_row($result){
return mysqli_fetch_row($result);
}
}
if(!function_exists('mysql_num_rows'))
{
function mysql_num_rows($result){
return mysqli_num_rows($result);
}
}
if(!function_exists('mysql_set_charset'))
{
function mysql_set_charset($charset){
global $php7x_mysql_connect;
return mysqli_set_charset($php7x_mysql_connect, $charset);
}
}
if(!function_exists('mysql_real_escape_string'))
{
function mysql_real_escape_string($string){
global $php7x_mysql_connect;
return mysqli_real_escape_string($php7x_mysql_connect, $string);
}
}
if(!function_exists('mysql_insert_id'))
{
function mysql_insert_id() {
global $php7x_mysql_connect;
return mysqli_insert_id($php7x_mysql_connect);
}
}
if(!function_exists('mysql_data_seek'))
{
function mysql_data_seek($db_query, $row_number=0) {
return mysqli_data_seek($db_query, $row_number);
}
}
if(!function_exists('mysql_fetch_field'))
{
function mysql_fetch_field($results) {
return mysqli_fetch_field($results);
}
}
if(!function_exists('mysql_free_result'))
{
function mysql_free_result($results) {
return mysqli_free_result($results);
}
}
if(!function_exists('mysql_affected_rows'))
{
function mysql_affected_rows() {
global $php7x_mysql_connect;
return mysqli_affected_rows($php7x_mysql_connect);
}
}
if(!function_exists('mysql_get_server_info'))
{
function mysql_get_server_info() {
global $php7x_mysql_connect;
return mysqli_get_server_info($php7x_mysql_connect);
}
}
if(!function_exists('mysql_close'))
{
function mysql_close($connect) {
if(!$connect) {
global $php7x_mysql_connect;
$connect = $php7x_mysql_connect;
}
return mysqli_close($connect);
}
}