misc.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 1182 2014-11-17 08:57:52Z andyzheng $
  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. {
  12. var $db;
  13. var $base;
  14. function __construct(&$base)
  15. {
  16. $this->miscmodel($base);
  17. }
  18. function miscmodel(&$base)
  19. {
  20. $this->base = $base;
  21. $this->db = $base->db;
  22. }
  23. function get_apps($col = '*', $where = '')
  24. {
  25. $arr = $this->db->fetch_all("SELECT $col FROM " . UC_DBTABLEPRE . "applications" . ($where ? ' WHERE ' . $where : ''));
  26. return $arr;
  27. }
  28. function delete_apps($appids)
  29. {
  30. }
  31. function update_app($appid, $name, $url, $authkey, $charset, $dbcharset)
  32. {
  33. }
  34. function alter_app_table($appid, $operation = 'ADD')
  35. {
  36. }
  37. function get_host_by_url($url)
  38. {
  39. }
  40. function check_url($url)
  41. {
  42. }
  43. function check_ip($url)
  44. {
  45. }
  46. function test_api($url, $ip = '')
  47. {
  48. }
  49. function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE')
  50. {
  51. $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
  52. if ($__times__ > 2)
  53. {
  54. return '';
  55. }
  56. $url .= (strpos($url, '?') === FALSE ? '?' : '&') . "__times__=$__times__";
  57. return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype);
  58. }
  59. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE')
  60. {
  61. $return = '';
  62. $matches = parse_url($url);
  63. $scheme = $matches['scheme'];
  64. $host = $matches['host'];
  65. $path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
  66. $port = !empty($matches['port']) ? $matches['port'] : 80;
  67. if ($post)
  68. {
  69. $out = "POST $path HTTP/1.0\r\n";
  70. $header = "Accept: */*\r\n";
  71. $header .= "Accept-Language: zh-cn\r\n";
  72. $boundary = $encodetype == 'URLENCODE' ? '' : ';' . substr($post, 0, trim(strpos($post, "\n")));
  73. $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
  74. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  75. $header .= "Host: $host:$port\r\n";
  76. $header .= 'Content-Length: ' . strlen($post) . "\r\n";
  77. $header .= "Connection: Close\r\n";
  78. $header .= "Cache-Control: no-cache\r\n";
  79. $header .= "Cookie: $cookie\r\n\r\n";
  80. $out .= $header . $post;
  81. }
  82. else
  83. {
  84. $out = "GET $path HTTP/1.0\r\n";
  85. $header = "Accept: */*\r\n";
  86. $header .= "Accept-Language: zh-cn\r\n";
  87. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  88. $header .= "Host: $host:$port\r\n";
  89. $header .= "Connection: Close\r\n";
  90. $header .= "Cookie: $cookie\r\n\r\n";
  91. $out .= $header;
  92. }
  93. $fpflag = 0;
  94. if (!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout))
  95. {
  96. $context = array(
  97. 'http' => array(
  98. 'method' => $post ? 'POST' : 'GET',
  99. 'header' => $header,
  100. 'content' => $post,
  101. 'timeout' => $timeout,
  102. ),
  103. );
  104. $context = stream_context_create($context);
  105. $fp = @fopen($scheme . '://' . ($ip ? $ip : $host) . ':' . $port . $path, 'b', false, $context);
  106. $fpflag = 1;
  107. }
  108. if (!$fp)
  109. {
  110. return '';
  111. }
  112. else
  113. {
  114. stream_set_blocking($fp, $block);
  115. stream_set_timeout($fp, $timeout);
  116. @fwrite($fp, $out);
  117. $status = stream_get_meta_data($fp);
  118. if (!$status['timed_out'])
  119. {
  120. while (!feof($fp) && !$fpflag)
  121. {
  122. if (($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n"))
  123. {
  124. break;
  125. }
  126. }
  127. $stop = false;
  128. while (!feof($fp) && !$stop)
  129. {
  130. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  131. $return .= $data;
  132. if ($limit)
  133. {
  134. $limit -= strlen($data);
  135. $stop = $limit <= 0;
  136. }
  137. }
  138. }
  139. @fclose($fp);
  140. return $return;
  141. }
  142. }
  143. function array2string($arr)
  144. {
  145. $s = $sep = '';
  146. if ($arr && is_array($arr))
  147. {
  148. foreach ($arr as $k => $v)
  149. {
  150. $s .= $sep . addslashes($k) . UC_ARRAY_SEP_1 . $v;
  151. $sep = UC_ARRAY_SEP_2;
  152. }
  153. }
  154. return $s;
  155. }
  156. function string2array($s)
  157. {
  158. $arr = explode(UC_ARRAY_SEP_2, $s);
  159. $arr2 = array();
  160. foreach ($arr as $k => $v)
  161. {
  162. list($key, $val) = explode(UC_ARRAY_SEP_1, $v);
  163. $arr2[$key] = $val;
  164. }
  165. return $arr2;
  166. }
  167. }