misc.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 1059 2011-03-01 07:25:09Z monkey $
  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. //private
  29. function alter_app_table($appid, $operation = 'ADD') {
  30. }
  31. function get_host_by_url($url) {
  32. }
  33. function check_url($url) {
  34. }
  35. function check_ip($url) {
  36. }
  37. function test_api($url, $ip = '') {
  38. }
  39. function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {
  40. $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
  41. if($__times__ > 2) {
  42. return '';
  43. }
  44. $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
  45. return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype);
  46. }
  47. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') {
  48. //error_log("[uc_client]\r\nurl: $url\r\npost: $post\r\n\r\n", 3, 'c:/log/php_fopen.txt');
  49. $return = '';
  50. $matches = parse_url($url);
  51. $host = $matches['host'];
  52. $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  53. $port = !empty($matches['port']) ? $matches['port'] : 80;
  54. if($post) {
  55. $out = "POST $path HTTP/1.0\r\n";
  56. $out .= "Accept: */*\r\n";
  57. //$out .= "Referer: $boardurl\r\n";
  58. $out .= "Accept-Language: zh-cn\r\n";
  59. $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n")));
  60. $out .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
  61. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  62. $out .= "Host: $host\r\n";
  63. $out .= 'Content-Length: '.strlen($post)."\r\n";
  64. $out .= "Connection: Close\r\n";
  65. $out .= "Cache-Control: no-cache\r\n";
  66. $out .= "Cookie: $cookie\r\n\r\n";
  67. $out .= $post;
  68. } else {
  69. $out = "GET $path HTTP/1.0\r\n";
  70. $out .= "Accept: */*\r\n";
  71. //$out .= "Referer: $boardurl\r\n";
  72. $out .= "Accept-Language: zh-cn\r\n";
  73. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  74. $out .= "Host: $host\r\n";
  75. $out .= "Connection: Close\r\n";
  76. $out .= "Cookie: $cookie\r\n\r\n";
  77. }
  78. if(function_exists('fsockopen')) {
  79. $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
  80. } elseif (function_exists('pfsockopen')) {
  81. $fp = @pfsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
  82. } else {
  83. $fp = false;
  84. }
  85. if(!$fp) {
  86. return '';
  87. } else {
  88. stream_set_blocking($fp, $block);
  89. stream_set_timeout($fp, $timeout);
  90. @fwrite($fp, $out);
  91. $status = stream_get_meta_data($fp);
  92. if(!$status['timed_out']) {
  93. while (!feof($fp)) {
  94. if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  95. break;
  96. }
  97. }
  98. $stop = false;
  99. while(!feof($fp) && !$stop) {
  100. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  101. $return .= $data;
  102. if($limit) {
  103. $limit -= strlen($data);
  104. $stop = $limit <= 0;
  105. }
  106. }
  107. }
  108. @fclose($fp);
  109. return $return;
  110. }
  111. }
  112. function array2string($arr) {
  113. $s = $sep = '';
  114. if($arr && is_array($arr)) {
  115. foreach($arr as $k => $v) {
  116. $s .= $sep.$k.UC_ARRAY_SEP_1.$v;
  117. $sep = UC_ARRAY_SEP_2;
  118. }
  119. }
  120. return $s;
  121. }
  122. function string2array($s) {
  123. $arr = explode(UC_ARRAY_SEP_2, $s);
  124. $arr2 = array();
  125. foreach($arr as $k => $v) {
  126. list($key, $val) = explode(UC_ARRAY_SEP_1, $v);
  127. $arr2[$key] = $val;
  128. }
  129. return $arr2;
  130. }
  131. }
  132. ?>