diff options
Diffstat (limited to 'mod')
-rw-r--r-- | mod/connedit.php | 21 | ||||
-rw-r--r-- | mod/directory.php | 4 | ||||
-rw-r--r-- | mod/dirsearch.php | 17 | ||||
-rw-r--r-- | mod/prate.php | 20 | ||||
-rw-r--r-- | mod/prep.php | 4 |
5 files changed, 52 insertions, 14 deletions
diff --git a/mod/connedit.php b/mod/connedit.php index 8c0212afe..79c7e6a4f 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -117,7 +117,7 @@ function connedit_post(&$a) { if($rating > 10) $rating = 10; - $rating_text = escape_tags($_REQUEST['rating_text']); + $rating_text = trim(escape_tags($_REQUEST['rating_text'])); $abook_my_perms = 0; @@ -131,26 +131,35 @@ function connedit_post(&$a) { $new_friend = false; if(! $is_self) { - $z = q("select * from xlink where xlink_xchan = '%s' and xlink_xlink = '%s' and xlink_static = 1 limit 1", + + $signed = $orig_record[0]['abook_xchan'] . '.' . $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($orig_record[0]['abook_xchan']) ); + + if($z) { $record = $z[0]['xlink_id']; - $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_updated = '%s' + $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_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', 1 ) ", + $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($orig_record[0]['abook_xchan']), 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", @@ -161,7 +170,7 @@ function connedit_post(&$a) { $record = $z[0]['xlink_id']; } if($record) { - proc_run('php','include/notifier.php','rating',$record); + proc_run('php','include/ratenotif.php','rating',$record); } } @@ -564,7 +573,7 @@ function connedit_content(&$a) { } $poco_rating = get_config('system','poco_rating_enable'); - $poco_rating = 0; + // if unset default to enabled if($poco_rating === false) $poco_rating = true; diff --git a/mod/directory.php b/mod/directory.php index 21940d57b..7f9283ba4 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -190,6 +190,9 @@ function directory_content(&$a) { $page_type = ''; + if($rr['total_ratings']) + $total_ratings = sprintf( tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']); + $profile = $rr; if ((x($profile,'locale') == 1) @@ -255,6 +258,7 @@ function directory_content(&$a) { 'nickname' => substr($rr['address'],0,strpos($rr['address'],'@')), 'location' => $location, 'gender' => $gender, + 'total_ratings' => $total_ratings, 'pdesc' => $pdesc, 'marital' => $marital, 'homepage' => $homepage, diff --git a/mod/dirsearch.php b/mod/dirsearch.php index 52a3d02cf..0f4dde976 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -210,6 +210,23 @@ function dirsearch_content(&$a) { ); } } + $r = q("select * from xlink where xlink_static = 1 and xlink_updated >= '%s' ", + dbesc($sync) + ); + if($r) { + $spkt['rating'] = array(); + foreach($r as $rr) { + $spkt['rating'][] = array( + 'type' => 'rating', + 'encoding' => 'zot', + 'target' => $rr['xlink_link'], + 'rating' => intval($rr['xlink_rating']), + 'rating_text' => $rr['xlink_rating_text'], + 'signature' => $rr['xlink_sig'], + 'edited' => $rr['xlink_updated'] + ); + } + } json_return_and_die($spkt); } else { diff --git a/mod/prate.php b/mod/prate.php index 28703d414..30de97927 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -2,12 +2,13 @@ function prate_post(&$a) { + if(! local_channel()) return; $channel = $a->get_channel(); - $target = $_REQUEST['target']; + $target = trim($_REQUEST['target']); if(! $target) return; @@ -20,28 +21,35 @@ function prate_post(&$a) { if($rating > 10) $rating = 10; - $rating_text = escape_tags($_REQUEST['rating_text']); + $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_xlink = '%s' and xlink_static = 1 limit 1", + $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_updated = '%s' + $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_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', 1 ) ", + $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", @@ -52,7 +60,7 @@ function prate_post(&$a) { $record = $z[0]['xlink_id']; } if($record) { - proc_run('php','include/notifier.php','rating',$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", diff --git a/mod/prep.php b/mod/prep.php index 896717826..950b602c9 100644 --- a/mod/prep.php +++ b/mod/prep.php @@ -54,8 +54,8 @@ function prep_content(&$a) { if(! $a->poi) return; - $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash where xlink_link like '%s' and xlink_rating != 0", - dbesc($a->poi['xchan_hash']) + $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash where xlink_link like '%s' and xlink_rating != 0 and xlink_static = 1", + dbesc(($a->poi) ? $a->poi['xchan_hash'] : argv(1)) ); if(! $r) |