PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/source/class/discuz/discuz_session_close.php

https://github.com/kuaileshike/upload
PHP | 186 lines | 148 code | 32 blank | 6 comment | 23 complexity | fab55c63bd3a07a003e083faa1536998 MD5 | raw file
  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: discuz_session_close.php 28628 2012-03-06 09:33:10Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class discuz_session_close {
  12. private $onlinehold;
  13. private $oltimestamp;
  14. public $sid = null;
  15. public $var;
  16. public $isnew = false;
  17. protected $newguest = array('sid' => 0, 'ip1' => 0, 'ip2' => 0, 'ip3' => 0, 'ip4' => 0,
  18. 'uid' => 0, 'username' => '', 'groupid' => 7, 'invisible' => 0, 'action' => 0,
  19. 'lastactivity' => 0, 'fid' => 0, 'tid' => 0, 'lastolupdate' => 0);
  20. protected $table;
  21. public function __construct($sid = '', $ip = '', $uid = 0) {
  22. $this->old = array('sid' => $sid, 'ip' => $ip, 'uid' => $uid);
  23. $this->var = $this->newguest;
  24. $this->onlinehold = getglobal('setting/onlinehold');
  25. $this->oltimestamp = TIMESTAMP - $this->onlinehold;
  26. $this->table = C::t('common_member_status');
  27. if(!empty($ip)) {
  28. $this->init($sid, $ip, $uid);
  29. }
  30. }
  31. public function set($key, $value) {
  32. if(isset($this->newguest[$key])) {
  33. $this->var[$key] = $value;
  34. } elseif ($key == 'ip') {
  35. $ips = explode('.', $value);
  36. $this->set('ip1', $ips[0]);
  37. $this->set('ip2', $ips[1]);
  38. $this->set('ip3', $ips[2]);
  39. $this->set('ip4', $ips[3]);
  40. }
  41. }
  42. public function get($key) {
  43. if(isset($this->newguest[$key])) {
  44. return $this->var[$key];
  45. } elseif ($key == 'ip') {
  46. return $this->get('ip1').'.'.$this->get('ip2').'.'.$this->get('ip3').'.'.$this->get('ip4');
  47. }
  48. }
  49. public function init($sid, $ip, $uid) {
  50. if(($uid = intval($uid)) > 0) {
  51. $this->var = $this->newguest;
  52. $this->set('sid', 0);
  53. $this->set('uid', $uid);
  54. $this->set('username', getglobal('member/username'));
  55. $this->set('groupid', getglobal('member/groupid'));
  56. $this->set('ip', $ip);
  57. if(($ulastactivity = getglobal('cookie/ulastactivity'))) {
  58. list($lastactivity, $invisible) = explode('|', $ulastactivity);
  59. $lastactivity = intval($lastactivity);
  60. $invisible = intval($invisible);
  61. }
  62. if(!$lastactivity) {
  63. $lastactivity = getuserprofile('lastactivity');
  64. $invisible = getuserprofile('invisible');
  65. dsetcookie('ulastactivity', $lastactivity.'|'.$invisible, 31536000);
  66. }
  67. if($this->oltimestamp >= $lastactivity) {
  68. $this->isnew = true;
  69. }
  70. $this->set('invisible', $invisible);
  71. $this->set('lastactivity', $lastactivity);
  72. $this->sid = 0;
  73. }
  74. }
  75. public function create($ip, $uid) {
  76. return $this->var;
  77. }
  78. public function delete() {
  79. return true;
  80. }
  81. public function update() {
  82. return true;
  83. }
  84. public function count($type = 0) {
  85. loadcache('onlinecount');
  86. $onlinecount = getglobal('cache/onlinecount');
  87. if($onlinecount && $onlinecount['dateline'] > TIMESTAMP - 600) {
  88. $count = $onlinecount['count'];
  89. } else {
  90. $count = $this->table->count_by_lastactivity_invisible($this->oltimestamp);
  91. savecache('onlinecount', array('count' => $count, 'dateline' => TIMESTAMP));
  92. }
  93. if($type == 1) {
  94. return $count;
  95. }
  96. if(!($multiple = getglobal('setting/onlineguestsmultiple'))) $multiple = 11;
  97. $add = mt_rand(0, $multiple);
  98. if($type == 2) {
  99. return intval($count * $multiple) + $add - $count;
  100. } else {
  101. return intval($count * $multiple) + $add;
  102. }
  103. }
  104. public function fetch_member($ismember = 0, $invisible = 0, $start = 0, $limit = 0) {
  105. return $this->table->fetch_all_by_lastactivity_invisible($this->oltimestamp, $invisible, $start, $limit);
  106. }
  107. public function count_invisible($type = 1) {
  108. return $this->table->count_by_lastactivity_invisible($this->oltimestamp, $type);
  109. }
  110. public function update_by_ipban($ip1, $ip2, $ip3, $ip4) {
  111. return false;
  112. }
  113. public function update_max_rows($max_rows) {
  114. return false;
  115. }
  116. public function clear() {
  117. return false;
  118. }
  119. public function count_by_fid($fid) {
  120. return 0;
  121. }
  122. public function fetch_all_by_fid($fid, $limit) {
  123. return array();
  124. }
  125. public function fetch_by_uid($uid) {
  126. if(($member = $this->table->fetch($uid)) && $member['lastactivity'] >= $this->oltimestamp) {
  127. return $member;
  128. }
  129. return array();
  130. }
  131. public function fetch_all_by_uid($uids, $start = 0, $limit = 0) {
  132. return $this->table->fetch_all_onlines($uids, $this->oltimestamp, $start, $limit);
  133. }
  134. public function update_by_uid($uid, $data) {
  135. return false;
  136. }
  137. public function count_by_ip($ip) {
  138. return 0;
  139. }
  140. public function fetch_all_by_ip($ip, $start = 0, $limit = 0) {
  141. return array();
  142. }
  143. public function updatesession() {
  144. static $updated = false;
  145. if(!$updated && $this->isnew) {
  146. global $_G;
  147. C::t('common_member_status')->update($_G['uid'], array('lastip' => $_G['clientip'], 'lastactivity' => TIMESTAMP, 'lastvisit' => TIMESTAMP));
  148. dsetcookie('ulastactivity', TIMESTAMP.'|'.getuserprofile('invisible'), 31536000);
  149. $updated = true;
  150. }
  151. return $updated;
  152. }
  153. }
  154. ?>