onclickfun.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. //信息统计
  3. function InfoOnclick($classid,$id){
  4. global $empire,$dbtbpre,$public_r;
  5. if(!$classid||!$id)
  6. {
  7. return '';
  8. }
  9. $var='ecookieinforecord';
  10. $val=$classid.'-'.$id;
  11. if(!eCheckOnclickCookie($var,$val))
  12. {
  13. return '';
  14. }
  15. $r=$empire->fetch1("select tbname,tid from {$dbtbpre}enewsclass where classid='$classid'");
  16. if(empty($r[tbname]))
  17. {
  18. return '';
  19. }
  20. if($public_r['onclicktype']==0)
  21. {
  22. $empire->query("update {$dbtbpre}ecms_".$r[tbname]." set onclick=onclick+1 where id='$id'");
  23. }
  24. elseif($public_r['onclicktype']==1)
  25. {
  26. $filename=ECMS_PATH.'e/data/filecache/onclick/ocinfo'.$r[tid].'.log';
  27. eAddUpdateOnclick($id,$filename);
  28. eDoUpdateOnclick($dbtbpre.'ecms_'.$r[tbname],'id','onclick',$filename);
  29. }
  30. }
  31. //栏目统计
  32. function ClassOnclick($classid){
  33. global $empire,$dbtbpre,$public_r;
  34. if(!$classid)
  35. {
  36. return '';
  37. }
  38. $var='ecookieclassrecord';
  39. $val=$classid;
  40. if(!eCheckOnclickCookie($var,$val))
  41. {
  42. return '';
  43. }
  44. if($public_r['onclicktype']==0)
  45. {
  46. $empire->query("update {$dbtbpre}enewsclass set onclick=onclick+1 where classid='$classid'");
  47. }
  48. elseif($public_r['onclicktype']==1)
  49. {
  50. $filename=ECMS_PATH.'e/data/filecache/onclick/occlass.log';
  51. eAddUpdateOnclick($classid,$filename);
  52. eDoUpdateOnclick($dbtbpre.'enewsclass','classid','onclick',$filename);
  53. }
  54. }
  55. //专题统计
  56. function ZtOnclick($ztid){
  57. global $empire,$dbtbpre,$public_r;
  58. if(!$ztid)
  59. {
  60. return '';
  61. }
  62. $var='ecookieztrecord';
  63. $val=$ztid;
  64. if(!eCheckOnclickCookie($var,$val))
  65. {
  66. return '';
  67. }
  68. if($public_r['onclicktype']==0)
  69. {
  70. $empire->query("update {$dbtbpre}enewszt set onclick=onclick+1 where ztid='$ztid'");
  71. }
  72. elseif($public_r['onclicktype']==1)
  73. {
  74. $filename=ECMS_PATH.'e/data/filecache/onclick/oczt.log';
  75. eAddUpdateOnclick($ztid,$filename);
  76. eDoUpdateOnclick($dbtbpre.'enewszt','ztid','onclick',$filename);
  77. }
  78. }
  79. //加入点击缓存
  80. function eAddUpdateOnclick($id,$filename){
  81. if(@$fp=fopen($filename,'a'))
  82. {
  83. fwrite($fp,"$id\n");
  84. fclose($fp);
  85. }
  86. }
  87. //更新点击缓存
  88. function eDoUpdateOnclick($table,$idf,$onclickf,$filename){
  89. global $empire,$dbtbpre,$public_r;
  90. if(!file_exists($filename))
  91. {
  92. return '';
  93. }
  94. if(filesize($filename)>=$public_r['onclickfilesize']*1024||time()-filectime($filename)>=$public_r['onclickfiletime']*60)
  95. {
  96. $lr=$ocr=array();
  97. if(@$lr=file($filename))
  98. {
  99. if(!@unlink($filename))
  100. {
  101. if($fp=@fopen($filename,'w'))
  102. {
  103. fwrite($fp,'');
  104. fclose($fp);
  105. }
  106. }
  107. $lr=array_count_values($lr);
  108. foreach($lr as $id => $oc)
  109. {
  110. $ocr[$oc].=($id>0)?','.intval($id):'';
  111. }
  112. foreach($ocr as $oc => $ids)
  113. {
  114. $empire->query("UPDATE LOW_PRIORITY $table SET $onclickf=$onclickf+'$oc' WHERE $idf IN (0$ids)");
  115. }
  116. }
  117. }
  118. }
  119. //COOKIE点击验证
  120. function eCheckOnclickCookie($var,$val){
  121. $doupdate=1;
  122. $onclickrecord=getcvar($var);
  123. if(strstr($onclickrecord,','.$val.','))
  124. {
  125. $doupdate=0;
  126. }
  127. else
  128. {
  129. $newval=empty($onclickrecord)?','.$val.',':$onclickrecord.$val.',';
  130. esetcookie($var,$newval);
  131. }
  132. if(empty($_COOKIE))
  133. {
  134. $doupdate=0;
  135. }
  136. return $doupdate;
  137. }
  138. ?>