aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2015-02-03 18:35:54 -0800
committerfriendica <info@friendica.com>2015-02-03 18:35:54 -0800
commit86771547e6d04d046d3beeabb8e4486a59a7fcc6 (patch)
treeccb63ad0dd92eda830e94295a5111b046d1ecc24
parent17ffe122b309610208d769f0e2b41f53fcf9d254 (diff)
downloadvolse-hubzilla-86771547e6d04d046d3beeabb8e4486a59a7fcc6.tar.gz
volse-hubzilla-86771547e6d04d046d3beeabb8e4486a59a7fcc6.tar.bz2
volse-hubzilla-86771547e6d04d046d3beeabb8e4486a59a7fcc6.zip
finish off the sync functions
-rw-r--r--include/dir_fns.php43
-rw-r--r--mod/dirsearch.php5
2 files changed, 46 insertions, 2 deletions
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 6d06fddd1..8c0161ff1 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -216,6 +216,49 @@ function sync_directories($dirmode) {
);
}
}
+ if(count($j['ratings'])) {
+ foreach($j['ratings'] as $rr) {
+ $x = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1",
+ dbesc($rr['channel']),
+ dbesc($rr['target'])
+ );
+ if($x && $x[0]['xlink_updated'] >= $rr['edited'])
+ continue;
+ $y = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1",
+ dbesc($rr['channel'])
+ );
+ if(! $y) {
+ logger('key unavailable on this site for ' . $rr['channel']);
+ continue;
+ }
+ if(! rsa_verify($rr['target'] . '.' . $rr['rating'] . '.' . $rr['rating_text'], base64url_decode($rr['signature']),$y[0]['xchan_pubkey'])) {
+ logger('failed to verify rating');
+ continue;
+ }
+
+ if($x) {
+ $z = q("update xlink set xlink_rating = %d, xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s' where xlink_id = %d",
+ intval($rr['rating']),
+ dbesc($rr['rating_text']),
+ dbesc($rr['signature']),
+ dbesc(datetime_convert()),
+ intval($x[0]['xlink_id'])
+ );
+ logger('rating updated');
+ }
+ else {
+ $z = 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', 1 ) ",
+ dbesc($rr['channel']),
+ dbesc($rr['target']),
+ intval($rr['rating']),
+ dbesc($rr['rating_text']),
+ dbesc($rr['signature']),
+ dbesc(datetime_convert())
+ );
+ logger('rating created');
+ }
+ }
+ }
}
}
diff --git a/mod/dirsearch.php b/mod/dirsearch.php
index 69b7e2eac..5a0a7cee8 100644
--- a/mod/dirsearch.php
+++ b/mod/dirsearch.php
@@ -213,11 +213,12 @@ function dirsearch_content(&$a) {
dbesc($sync)
);
if($r) {
- $spkt['rating'] = array();
+ $spkt['ratings'] = array();
foreach($r as $rr) {
- $spkt['rating'][] = array(
+ $spkt['ratings'][] = array(
'type' => 'rating',
'encoding' => 'zot',
+ 'channel' => $rr['xlink_xchan'],
'target' => $rr['xlink_link'],
'rating' => intval($rr['xlink_rating']),
'rating_text' => $rr['xlink_rating_text'],