digg_ajax.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. *
  4. * 文档digg处理ajax文件
  5. *
  6. * @version $Id: digg_ajax.php 2 13:00 2011/11/25 tianya $
  7. * @package DedeCMS.Plus
  8. * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. require_once(dirname(__FILE__)."/../include/common.inc.php");
  13. $action = isset($action) ? trim($action) : '';
  14. $id = empty($id)? 0 : intval(preg_replace("/[^\d]/",'', $id));
  15. helper('cache');
  16. if($id < 1)
  17. {
  18. exit();
  19. }
  20. $maintable = '#@__archives';
  21. $prefix = 'diggCache';
  22. $key = 'aid-'.$id;
  23. $row = GetCache($prefix, $key);
  24. if(!is_array($row) || $cfg_digg_update==0)
  25. {
  26. $row = $dsql->GetOne("SELECT goodpost,badpost,scores FROM `$maintable` WHERE id='$id' ");
  27. if($cfg_digg_update == 0)
  28. {
  29. if($action == 'good')
  30. {
  31. $row['goodpost'] = $row['goodpost'] + 1;
  32. $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=".time()." WHERE id='$id'");
  33. }
  34. else if($action=='bad')
  35. {
  36. $row['badpost'] = $row['badpost'] + 1;
  37. $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET scores = scores - {$cfg_caicai_sub},badpost=badpost+1,lastpost=".time()." WHERE id='$id'");
  38. }
  39. DelCache($prefix, $key);
  40. }
  41. SetCache($prefix, $key, $row, 0);
  42. } else {
  43. if($action == 'good')
  44. {
  45. $row['goodpost'] = $row['goodpost'] + 1;
  46. $row['scores'] = $row['scores'] + $cfg_caicai_sub;
  47. if($row['goodpost'] % $cfg_digg_update == 0)
  48. {
  49. $add_caicai_sub = $cfg_digg_update * $cfg_caicai_sub;
  50. $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET scores = scores + {$add_caicai_sub},goodpost=goodpost+{$cfg_digg_update} WHERE id='$id'");
  51. DelCache($prefix, $key);
  52. }
  53. } else if($action == 'bad')
  54. {
  55. $row['badpost'] = $row['badpost'] + 1;
  56. $row['scores'] = $row['scores'] - $cfg_caicai_sub;
  57. if($row['badpost'] % $cfg_digg_update == 0)
  58. {
  59. $add_caicai_sub = $cfg_digg_update * $cfg_caicai_sub;
  60. $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET scores = scores - {$add_caicai_sub},badpost=badpost+{$cfg_digg_update} WHERE id='$id'");
  61. DelCache($prefix, $key);
  62. }
  63. }
  64. SetCache($prefix, $key, $row, 0);
  65. }
  66. $digg = '';
  67. if(!is_array($row)) exit();
  68. if($row['goodpost'] + $row['badpost'] == 0)
  69. {
  70. $row['goodper'] = $row['badper'] = 0;
  71. }
  72. else
  73. {
  74. $row['goodper'] = number_format($row['goodpost'] / ($row['goodpost'] + $row['badpost']), 3) * 100;
  75. $row['badper'] = 100 - $row['goodper'];
  76. }
  77. if(empty($formurl)) $formurl = '';
  78. if($formurl=='caicai')
  79. {
  80. if($action == 'good') $digg = $row['goodpost'];
  81. if($action == 'bad') $digg = $row['badpost'];
  82. }
  83. else
  84. {
  85. $row['goodper'] = trim(sprintf("%4.2f", $row['goodper']));
  86. $row['badper'] = trim(sprintf("%4.2f", $row['badper']));
  87. $digg = '<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';" onclick="postDigg(\'good\','.$id.')">
  88. <div class="digg_act">顶一下</div>
  89. <div class="digg_num">('.$row['goodpost'].')</div>
  90. <div class="digg_percent">
  91. <div class="digg_percent_bar"><span style="width:'.$row['goodper'].'%"></span></div>
  92. <div class="digg_percent_num">'.$row['goodper'].'%</div>
  93. </div>
  94. </div>
  95. <div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition=\'right bottom\';" onmouseout="this.style.backgroundPosition=\'right top\';" onclick="postDigg(\'bad\','.$id.')">
  96. <div class="digg_act">踩一下</div>
  97. <div class="digg_num">('.$row['badpost'].')</div>
  98. <div class="digg_percent">
  99. <div class="digg_percent_bar"><span style="width:'.$row['badper'].'%"></span></div>
  100. <div class="digg_percent_num">'.$row['badper'].'%</div>
  101. </div>
  102. </div>';
  103. }
  104. AjaxHead();
  105. echo $digg;
  106. exit();