| 1 |
<?php |
| 2 |
|
| 3 |
function acym_fileGetContent($url, $timeout = 10) |
| 4 |
{ |
| 5 |
if (strpos($url, '_custom.ini') !== false && !file_exists($url)) { |
| 6 |
return ''; |
| 7 |
} |
| 8 |
|
| 9 |
ob_start(); |
| 10 |
$data = ''; |
| 11 |
|
| 12 |
$allowUrlFopen = ini_get('allow_url_fopen'); |
| 13 |
|
| 14 |
if (function_exists('file_get_contents') && (!empty($allowUrlFopen) || strpos($url, 'http') !== 0)) { |
| 15 |
if (!empty($timeout)) { |
| 16 |
ini_set('default_socket_timeout', $timeout); |
| 17 |
} |
| 18 |
$streamContext = stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]); |
| 19 |
$data = file_get_contents($url, false, $streamContext); |
| 20 |
} |
| 21 |
|
| 22 |
if (empty($data) && strpos($url, 'http') === 0 && class_exists('WP_Http') && method_exists('WP_Http', 'request')) { |
| 23 |
$args = ['timeout' => $timeout]; |
| 24 |
$request = new WP_Http(); |
| 25 |
$data = $request->request($url, $args); |
| 26 |
$data = (empty($data) || !is_array($data) || empty($data['body'])) ? '' : $data['body']; |
| 27 |
} |
| 28 |
|
| 29 |
if (empty($data) && function_exists('fopen') && function_exists('stream_get_contents')) { |
| 30 |
$handle = fopen($url, 'r'); |
| 31 |
if (!empty($handle)) { |
| 32 |
if (!empty($timeout)) { |
| 33 |
stream_set_timeout($handle, $timeout); |
| 34 |
} |
| 35 |
$data = stream_get_contents($handle); |
| 36 |
} |
| 37 |
} |
| 38 |
$warnings = ob_get_clean(); |
| 39 |
|
| 40 |
if (acym_isDebug()) { |
| 41 |
echo $warnings; |
| 42 |
} |
| 43 |
|
| 44 |
return $data; |
| 45 |
} |
| 46 |
|
| 47 |
function acym_extractArchive($archive, $destination) |
| 48 |
{ |
| 49 |
if (substr($archive, strlen($archive) - 4) !== '.zip') { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
WP_Filesystem(); |
| 54 |
|
| 55 |
return true === unzip_file($archive, $destination); |
| 56 |
} |
| 57 |
|