getMessage(); } if (empty($error)) { if ($tpl_file) { if (!file_exists($tpl_file)) { $tpl_file = dirname(__FILE__) . '/templates/' . $tpl_file; if (!file_exists($tpl_file)) { throw new Exception('[ERROR] template not found', 1); } } if ($tpl_file) { } $content = preg_replace('!\{content\}!', $content, file_get_contents($tpl_file)); } // Перекодируем контент в нужную кодировку, если необходимо if (isset($params['codepage_out'])) { $content = iconv(isset($params['codepage_in']) ? $params['codepage_in'] : 'utf-8', $params['codepage_out'], $content); } // Сохраним в кеше, если в этом есть необходимость if ($cache_time) { $cache = array( 'timeout' => time() + $cache_time, 'content' => $content, ); file_put_contents($cache_filename, serialize($cache)); } return $content; } return $error; } else { return $cache['content']; } } private static function get($url, $params) { if (function_exists('curl_init')) { $ch = curl_init($url); if (isset($params['auth'])) { curl_setopt($ch, CURLOPT_USERPWD, $params['auth']); } curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, isset($params['timeout']) ? $params['timeout'] : 20); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (isset($params['post']) && is_array($params['post'])) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params['post'])); } $content = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { throw new Exception('[ERROR] ' . $error, 1); } } else { $content = ''; try { $f = fopen($url, 'r'); stream_set_timeout($f, isset($params['timeout']) ? $params['timeout'] : 20); while($tmp = fread($f, 1024)) { $content .= $tmp; } } catch (Exception $e) { throw $e; } } return $content; } } ?>