streams/mod/prate.php

78 lines
1.6 KiB
PHP
Raw Normal View History

2015-01-29 08:28:02 +00:00
<?php
function prate_post(&$a) {
2015-02-03 00:54:55 +00:00
2015-01-29 08:28:02 +00:00
if(! local_channel())
return;
$channel = $a->get_channel();
2015-02-03 00:54:55 +00:00
$target = trim($_REQUEST['target']);
2015-01-29 08:28:02 +00:00
if(! $target)
return;
if($target === $channel['channel_hash'])
return;
$rating = intval($_POST['rating']);
if($rating < (-10))
$rating = (-10);
if($rating > 10)
$rating = 10;
2015-02-03 00:54:55 +00:00
$rating_text = trim(escape_tags($_REQUEST['rating_text']));
$signed = $target . '.' . $rating . '.' . $rating_text;
$sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey']));
2015-01-29 08:28:02 +00:00
2015-02-03 01:58:51 +00:00
$z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
2015-01-29 08:28:02 +00:00
dbesc($channel['channel_hash']),
dbesc($target)
);
if($z) {
$record = $z[0]['xlink_id'];
2015-02-03 00:54:55 +00:00
$w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'
2015-01-29 08:28:02 +00:00
where xlink_id = %d",
intval($rating),
dbesc($rating_text),
2015-02-03 00:54:55 +00:00
dbesc($sig),
2015-01-29 08:28:02 +00:00
dbesc(datetime_convert()),
intval($record)
);
}
else {
2015-02-03 00:54:55 +00:00
$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 ) ",
2015-01-29 08:28:02 +00:00
dbesc($channel['channel_hash']),
dbesc($target),
intval($rating),
dbesc($rating_text),
2015-02-03 00:54:55 +00:00
dbesc($sig),
2015-01-29 08:28:02 +00:00
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) {
2015-02-03 04:13:07 +00:00
proc_run('php','include/ratenotif.php','rating',$record);
2015-01-29 08:28:02 +00:00
}
return;
}