lib.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. if ( ! defined('BASE_PATH')) exit('No direct script access allowed');
  3. /**
  4. * 公共函数
  5. * */
  6. class lib{
  7. /**
  8. * 检查环境
  9. **/
  10. public static function check(){
  11. }
  12. /**
  13. * 是否为URL
  14. **/
  15. public static function is_url($url){
  16. }
  17. //抓取
  18. public static function fetch_url($url){
  19. switch(RUN_ENV){
  20. case 'SAE': //使用SAE FetchURL服务
  21. $f = new SaeFetchurl();
  22. if(STATIC_HOST){
  23. $f->setHeader('Host',STATIC_HOST);
  24. }
  25. $content = $f->fetch($url);
  26. return $content;
  27. break;
  28. case 'BAE':
  29. case 'LOCAL':
  30. default:
  31. if(function_exists('curl_init')){
  32. //BAE或普通平台下可使用curl
  33. $ch = curl_init();
  34. curl_setopt($ch, CURLOPT_URL, $url);
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  37. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  38. if(!ini_get('safe_mode')){
  39. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  40. }
  41. if(STATIC_HOST){
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, 'Host: '.STATIC_HOST);
  43. }
  44. return curl_exec($ch);
  45. }else{
  46. //否则使用file_get_contents
  47. if(STATIC_HOST){
  48. $opt=array('http'=>array('header'=>'Host: '.STATIC_HOST));
  49. $context=stream_context_create($opt);
  50. return file_get_contents($url,false,$context);
  51. }else{
  52. return file_get_contents($url);
  53. }
  54. }
  55. }
  56. }
  57. }