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