misc.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: misc.php 1127 2011-12-14 04:24:58Z svn_project_zhangjie $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. define('UC_ARRAY_SEP_1', 'UC_ARRAY_SEP_1');
  9. define('UC_ARRAY_SEP_2', 'UC_ARRAY_SEP_2');
  10. class miscmodel {
  11. var $db;
  12. var $base;
  13. function __construct(&$base) {
  14. $this->miscmodel($base);
  15. }
  16. function miscmodel(&$base) {
  17. $this->base = $base;
  18. $this->db = $base->db;
  19. }
  20. function get_apps($col = '*', $where = '') {
  21. $arr = $this->db->fetch_all("SELECT $col FROM ".UC_DBTABLEPRE."applications".($where ? ' WHERE '.$where : ''));
  22. return $arr;
  23. }
  24. function delete_apps($appids) {
  25. }
  26. function update_app($appid, $name, $url, $authkey, $charset, $dbcharset) {
  27. }
  28. function alter_app_table($appid, $operation = 'ADD') {
  29. }
  30. function get_host_by_url($url) {
  31. }
  32. function check_url($url) {
  33. }
  34. function check_ip($url) {
  35. }
  36. function test_api($url, $ip = '') {
  37. }
  38. function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {
  39. $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
  40. if($__times__ > 2) {
  41. return '';
  42. }
  43. $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
  44. return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype);
  45. }
  46. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {
  47. $return = '';
  48. $matches = parse_url($url);
  49. $scheme = $matches['scheme'];
  50. $host = $matches['host'];
  51. $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  52. $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80);
  53. if($post) {
  54. $out = "POST $path HTTP/1.0\r\n";
  55. $header = "Accept: */*\r\n";
  56. $header .= "Accept-Language: zh-cn\r\n";
  57. $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n")));
  58. $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
  59. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  60. $header .= "Host: $host:$port\r\n";
  61. $header .= 'Content-Length: '.strlen($post)."\r\n";
  62. $header .= "Connection: Close\r\n";
  63. $header .= "Cache-Control: no-cache\r\n";
  64. $header .= "Cookie: $cookie\r\n\r\n";
  65. $out .= $header.$post;
  66. } else {
  67. $out = "GET $path HTTP/1.0\r\n";
  68. $header = "Accept: */*\r\n";
  69. $header .= "Accept-Language: zh-cn\r\n";
  70. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  71. $header .= "Host: $host:$port\r\n";
  72. $header .= "Connection: Close\r\n";
  73. $header .= "Cookie: $cookie\r\n\r\n";
  74. $out .= $header;
  75. }
  76. $fpflag = 0;
  77. if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) {
  78. $context = array(
  79. 'http' => array(
  80. 'method' => $post ? 'POST' : 'GET',
  81. 'header' => $header,
  82. 'content' => $post,
  83. 'timeout' => $timeout,
  84. ),
  85. );
  86. $context = stream_context_create($context);
  87. $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context);
  88. $fpflag = 1;
  89. }
  90. if(!$fp) {
  91. return '';
  92. } else {
  93. stream_set_blocking($fp, $block);
  94. stream_set_timeout($fp, $timeout);
  95. @fwrite($fp, $out);
  96. $status = stream_get_meta_data($fp);
  97. if(!$status['timed_out']) {
  98. while (!feof($fp) && !$fpflag) {
  99. if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  100. break;
  101. }
  102. }
  103. $stop = false;
  104. while(!feof($fp) && !$stop) {
  105. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  106. $return .= $data;
  107. if($limit) {
  108. $limit -= strlen($data);
  109. $stop = $limit <= 0;
  110. }
  111. }
  112. }
  113. @fclose($fp);
  114. return $return;
  115. }
  116. }
  117. function array2string($arr) {
  118. $s = $sep = '';
  119. if($arr && is_array($arr)) {
  120. foreach($arr as $k => $v) {
  121. $s .= $sep.addslashes($k).UC_ARRAY_SEP_1.$v;
  122. $sep = UC_ARRAY_SEP_2;
  123. }
  124. }
  125. return $s;
  126. }
  127. function string2array($s) {
  128. $arr = explode(UC_ARRAY_SEP_2, $s);
  129. $arr2 = array();
  130. foreach($arr as $k => $v) {
  131. list($key, $val) = explode(UC_ARRAY_SEP_1, $v);
  132. $arr2[$key] = $val;
  133. }
  134. return $arr2;
  135. }
  136. }
  137. ?>