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
|
<?php
function prate_post(&$a) {
logger('request: ' . print_r($_REQUEST,true));
return;
if(! local_channel())
return;
$channel = $a->get_channel();
$target = trim($_REQUEST['target']);
if(! $target)
return;
if($target === $channel['channel_hash'])
return;
$rating = intval($_POST['rating']);
if($rating < (-10))
$rating = (-10);
if($rating > 10)
$rating = 10;
$rating_text = trim(escape_tags($_REQUEST['rating_text']));
$signed = $target . '.' . $rating . '.' . $rating_text;
$sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey']));
$z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
dbesc($channel['channel_hash']),
dbesc($target)
);
if($z) {
$record = $z[0]['xlink_id'];
$w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'
where xlink_id = %d",
intval($rating),
dbesc($rating_text),
dbesc($sig),
dbesc(datetime_convert()),
intval($record)
);
}
else {
$w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_sig, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', '%s', 1 ) ",
dbesc($channel['channel_hash']),
dbesc($target),
intval($rating),
dbesc($rating_text),
dbesc($sig),
dbesc(datetime_convert())
);
$z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
dbesc($channel['channel_hash']),
dbesc($orig_record[0]['abook_xchan'])
);
if($z)
$record = $z[0]['xlink_id'];
}
if($record) {
proc_run('php','include/ratenotif.php','rating',$record);
}
$x = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($target),
intval($local_channel())
);
if($x) {
$w = q("update abook set abook_rating = %d, abook_rating_text = '%s' where abook_xchan = '%s' and abook_channel = %d",
intval($rating),
dbesc($rating_text),
dbesc($target),
intval(local_channel())
);
$x = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($target),
intval($local_channel())
);
if($x) {
unset($x[0]['abook_id']);
unset($x[0]['abook_account']);
unset($x[0]['abook_channel']);
build_sync_packet(0, array('abook' => array($x[0])));
}
}
return;
}
|