PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/source/plugin/cloudstat/cloudstat.class.php

https://github.com/jinbo51/DiscuzX
PHP | 314 lines | 257 code | 51 blank | 6 comment | 51 complexity | 6691665a25315dbdaf6b44ae3e394e4c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cloudstat.class.php 33237 2013-05-08 06:16:23Z jeffjzhang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class plugin_cloudstat {
  12. var $discuzParams = array();
  13. var $extraParams = array();
  14. function common() {
  15. global $_G;
  16. if($_G['inajax']) {
  17. return;
  18. }
  19. $_G['setting']['statcode'] = $this->_makejs() . $_G['setting']['statcode'];
  20. }
  21. function global_cpnav_extra1() {
  22. $js = '<script type="text/javascript">var _speedMark = new Date();</script>';
  23. return $js;
  24. }
  25. function _makejs() {
  26. global $_G;
  27. $dzjs = $this->_makedzjs();
  28. $return = '';
  29. if(!$_G['inajax']) {
  30. $return = '&nbsp;&nbsp;<span id="tcss"></span><script type="text/javascript" src="http://tcss.qq.com/ping.js?v=1'.VERHASH.'" charset="utf-8"></script>';
  31. }
  32. $return .= '<script type="text/javascript" reload="1">pgvMain('.$dzjs.');</script>';
  33. return $return;
  34. }
  35. function _makedzjs() {
  36. global $_G, $mod;
  37. $this->discuzParams['r2'] = $_G['setting']['my_siteid'];
  38. $this->discuzParams['ui'] = $_G['uid'] ? $_G['uid'] : 0;
  39. if($_G['uid'] && ($_G['member']['regdate'] < ($_G['timestamp'] - $_G['timestamp'] % 86400))) {
  40. $this->discuzParams['ty'] = 2;
  41. }
  42. $this->discuzParams['rt'] = $_G['basescript'];
  43. if($mod) {
  44. $this->discuzParams['md'] = $mod;
  45. }
  46. if($_G['fid']) {
  47. $this->discuzParams['fi'] = $_G['fid'];
  48. }
  49. if($_G['tid']) {
  50. $this->discuzParams['ti'] = $_G['tid'];
  51. }
  52. if($_G['page']) {
  53. $this->discuzParams['pn'] = $_G['page'];
  54. } else {
  55. $this->discuzParams['pn'] = 1;
  56. }
  57. $qq = intval(getcookie('stats_qc_reg'));
  58. dsetcookie('stats_qc_reg');
  59. $qq .= $_G['uid']?'1':'0';
  60. $qclogin = intval(getcookie('stats_qc_login'));
  61. if(($_G['uid'] && $_G['member']['conisbind']) || $qclogin == 4) {
  62. $qq .= $qclogin?$qclogin:1;
  63. dsetcookie('stats_qc_login');
  64. } else {
  65. $qq .= '0';
  66. }
  67. $this->discuzParams['qq'] = $qq;
  68. $cloudstatpost = getcookie('cloudstatpost');
  69. dsetcookie('cloudstatpost');
  70. $cloudstatpost = explode('D', $cloudstatpost);
  71. if($cloudstatpost[0] == 'thread') {
  72. $this->discuzParams['nt'] = 1;
  73. $this->discuzParams['ui'] = $cloudstatpost[1];
  74. $this->discuzParams['fi'] = $cloudstatpost[2];
  75. $this->discuzParams['ti'] = $cloudstatpost[3];
  76. $subject = $_G['forum_thread']['subject'];
  77. $charset = $_G['charset'];
  78. if(empty($charset)) {
  79. foreach ($_G['config']['db'] as $key => $cfg) {
  80. if ($cfg['dbcharset']) {
  81. $charset = $cfg['dbcharset'];
  82. break;
  83. }
  84. }
  85. }
  86. if('GBK' != strtoupper($charset) && !empty($charset)) {
  87. $subject = diconv($subject, $charset, 'GBK');
  88. }
  89. $this->extraParams[] = "tn=" . urlencode($subject);
  90. } elseif($cloudstatpost[0] == 'post') {
  91. $this->discuzParams['nt'] = 2;
  92. $this->discuzParams['ui'] = $cloudstatpost[1];
  93. $this->discuzParams['fi'] = $cloudstatpost[2];
  94. $this->discuzParams['ti'] = $cloudstatpost[3];
  95. $this->discuzParams['pi'] = $cloudstatpost[4];
  96. }
  97. $cloudstaticon = isset($_G['setting']['cloud_staticon']) ? intval($_G['setting']['cloud_staticon']) : 1;
  98. if ($cloudstaticon && !$_G['inajax']) {
  99. if ($cloudstaticon > 4 && $cloudstaticon < 9) {
  100. $cloudstaticon = 1;
  101. } elseif ($cloudstaticon < 5) {
  102. $cloudstaticon += 10;
  103. }
  104. $this->discuzParams['logo'] = $cloudstaticon;
  105. }
  106. return $this->_response_format(array(
  107. 'discuzParams' => $this->discuzParams,
  108. 'extraParams' => implode(';', $this->extraParams)
  109. ));
  110. }
  111. function _response_format($result) {
  112. if(function_exists('json_encode')) {
  113. $json = json_encode($result);
  114. } else {
  115. $json = $this->_array2json($result);
  116. }
  117. return $json;
  118. }
  119. function _array2json($array) {
  120. $piece = array();
  121. foreach ($array as $k => $v) {
  122. $piece[] = $k . ':' . $this->_php2json($v);
  123. }
  124. if ($piece) {
  125. $json = '{' . implode(',', $piece) . '}';
  126. } else {
  127. $json = '[]';
  128. }
  129. return $json;
  130. }
  131. function _php2json($value) {
  132. if (is_array($value)) {
  133. return $this->_array2json($value);
  134. }
  135. if (is_string($value)) {
  136. $value = str_replace(array("\n", "\t"), array(), $value);
  137. $value = addslashes($value);
  138. return '"'.$value.'"';
  139. }
  140. if (is_bool($value)) {
  141. return $value ? 'true' : 'false';
  142. }
  143. if (is_null($value)) {
  144. return 'null';
  145. }
  146. return $value;
  147. }
  148. function _post_cloudstat_message($param) {
  149. global $_G;
  150. $param = $param['param'];
  151. if(in_array($param[0], array('post_newthread_succeed', 'post_newthread_mod_succeed'))) {
  152. dsetcookie('cloudstatpost', 'threadD'.$_G['uid'].'D'.$param[2]['fid'].'D'.$param[2]['tid'], 86400);
  153. } elseif(in_array($param[0], array('post_reply_succeed', 'post_reply_mod_succeed'))) {
  154. dsetcookie('cloudstatpost', 'postD'.$_G['uid'].'D'.$param[2]['fid'].'D'.$param[2]['tid'].'D'.$param[2]['pid'], 86400);
  155. }
  156. }
  157. function _viewthread_postbottom_output() {
  158. global $_G;
  159. $cloudstatjs = array();
  160. if($_G['inajax'] && !empty($_GET['viewpid'])) {
  161. $cloudstatjs[] = $this->_makejs();
  162. }
  163. return $cloudstatjs;
  164. }
  165. }
  166. class plugin_cloudstat_forum extends plugin_cloudstat {
  167. function post_cloudstat_message($param) {
  168. return $this->_post_cloudstat_message($param);
  169. }
  170. function viewthread_postbottom_output() {
  171. return $this->_viewthread_postbottom_output();
  172. }
  173. }
  174. class plugin_cloudstat_group extends plugin_cloudstat {
  175. function post_cloudstat_message($param) {
  176. return $this->_post_cloudstat_message($param);
  177. }
  178. function viewthread_postbottom_output() {
  179. return $this->_viewthread_postbottom_output();
  180. }
  181. }
  182. class mobileplugin_cloudstat_forum extends plugin_cloudstat {
  183. function post_cloudstat_message($param) {
  184. return $this->_post_cloudstat_message($param);
  185. }
  186. }
  187. class mobileplugin_cloudstat extends plugin_cloudstat {
  188. function global_footer_mobile() {
  189. return $this->_noscript();
  190. }
  191. function _noscript() {
  192. global $_G;
  193. $this->_makedzjs();
  194. $uri = $_SERVER['REQUEST_URI'];
  195. if ($uri) {
  196. $urlInfo = parse_url($uri);
  197. $this->discuzParams['url'] = $urlInfo['path'];
  198. $this->discuzParams['arg'] = urlencode($urlInfo['query']);
  199. } else {
  200. $this->discuzParams['url'] = '/';
  201. $this->discuzParams['arg'] = '-';
  202. }
  203. $this->discuzParams['tz'] = sprintf('%0d', -($_G['timenow']['offset']));
  204. $siteUrl = parse_url($_G['siteurl']);
  205. $this->discuzParams['dm'] = $siteUrl['host'];
  206. $pvi = getcookie('pvi');
  207. if (!$pvi) {
  208. $pvi = mt_rand(1, 0x7fffffff) % 10000000000;
  209. dsetcookie('pvi', $pvi, 2145888000);
  210. }
  211. $this->discuzParams['pvi'] = $pvi;
  212. $si = getcookie('si');
  213. if (!$si) {
  214. $si = 's' . (mt_rand(1, 0x7fffffff) % 10000000000);
  215. dsetcookie('si', $si);
  216. }
  217. $this->discuzParams['si'] = $si;
  218. $cloudstatpost = getcookie('cloudstatpost');
  219. dsetcookie('cloudstatpost');
  220. $cloudstatpost = explode('D', $cloudstatpost);
  221. if($cloudstatpost[0] == 'thread') {
  222. $this->discuzParams['nt'] = 1;
  223. $this->discuzParams['ui'] = $cloudstatpost[1];
  224. $this->discuzParams['fi'] = $cloudstatpost[2];
  225. $this->discuzParams['ti'] = $cloudstatpost[3];
  226. $subject = $_G['forum_thread']['subject'];
  227. $charset = $_G['charset'];
  228. if(empty($charset)) {
  229. foreach ($_G['config']['db'] as $key => $cfg) {
  230. if ($cfg['dbcharset']) {
  231. $charset = $cfg['dbcharset'];
  232. break;
  233. }
  234. }
  235. }
  236. if('GBK' != strtoupper($charset) && !empty($charset)) {
  237. $subject = diconv($subject, $charset, 'GBK');
  238. }
  239. $this->extraParams[] = "tn=" . urlencode($subject);
  240. } elseif($cloudstatpost[0] == 'post') {
  241. $this->discuzParams['nt'] = 2;
  242. $this->discuzParams['ui'] = $cloudstatpost[1];
  243. $this->discuzParams['fi'] = $cloudstatpost[2];
  244. $this->discuzParams['ti'] = $cloudstatpost[3];
  245. $this->discuzParams['pi'] = $cloudstatpost[4];
  246. }
  247. $ref = $_SERVER['HTTP_REFERER'];
  248. if ($ref) {
  249. $refInfo = parse_url($ref);
  250. $this->discuzParams['rdm'] = $refInfo['host'];
  251. $this->discuzParams['rarg'] = urlencode($refInfo['query']);
  252. $this->discuzParams['rurl'] = $refInfo['path'];
  253. }
  254. $this->extraParams[] = 'mt=0';
  255. $this->discuzParams['rnd'] = mt_rand(1, 0x7fffffff);
  256. $query = '';
  257. foreach ($this->discuzParams as $key => $val) {
  258. $query .= "$key=$val&";
  259. }
  260. $pingd = 'http://pingtcss.qq.com/pingd?' . $query . 'ext=' . implode(';', $this->extraParams);
  261. return '<img src="' . $pingd . '" height="1" width="1" style="float:right" noerror="true" />';
  262. }
  263. }