| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
function acym_getAllHeaders(): array |
| 5 |
{ |
| 6 |
if (function_exists('getallheaders')) { |
| 7 |
return getallheaders(); |
| 8 |
} |
| 9 |
|
| 10 |
$headers = []; |
| 11 |
|
| 12 |
foreach ($_SERVER as $name => $value) { |
| 13 |
if (substr($name, 0, 5) === 'HTTP_') { |
| 14 |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
| 15 |
} else { |
| 16 |
$headers[$name] = $value; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
return $headers; |
| 21 |
} |
| 22 |
|
| 23 |
function acym_getHeader(string $headerName): string |
| 24 |
{ |
| 25 |
$allHeaders = acym_getAllHeaders(); |
| 26 |
|
| 27 |
if (!empty($allHeaders[$headerName])) { |
| 28 |
return $allHeaders[$headerName]; |
| 29 |
} |
| 30 |
|
| 31 |
return ''; |
| 32 |
} |
| 33 |
|
| 34 |
function acym_isAjax(): bool |
| 35 |
{ |
| 36 |
$allHeaders = acym_getAllHeaders(); |
| 37 |
|
| 38 |
if (!empty($allHeaders['Accept'])) { |
| 39 |
$headerAccept = $allHeaders['Accept']; |
| 40 |
} elseif (!empty($allHeaders['accept'])) { |
| 41 |
$headerAccept = $allHeaders['accept']; |
| 42 |
} else { |
| 43 |
$headerAccept = ''; |
| 44 |
} |
| 45 |
|
| 46 |
return strpos($headerAccept, 'application/json') !== false; |
| 47 |
} |
| 48 |
|