aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/notifier.php14
-rw-r--r--include/ratenotif.php124
-rw-r--r--include/zot.php39
-rw-r--r--mod/connedit.php21
-rw-r--r--mod/directory.php4
-rw-r--r--mod/dirsearch.php17
-rw-r--r--mod/prate.php20
-rw-r--r--mod/prep.php4
-rwxr-xr-xview/tpl/direntry.tpl8
9 files changed, 209 insertions, 42 deletions
diff --git a/include/notifier.php b/include/notifier.php
index edb2f1946..fe6ac33c0 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -297,15 +297,6 @@ function notifier_run($argv, $argc){
$private = false;
$packet_type = 'purge';
}
- elseif($cmd === 'rating') {
- $r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1",
- intval($item_id)
- );
- if($r) {
- logger('rating message: ' . print_r($r[0],true));
- return;
- }
- }
else {
// Normal items
@@ -483,11 +474,6 @@ function notifier_run($argv, $argc){
// Now we have collected recipients (except for external mentions, FIXME)
// Let's reduce this to a set of hubs.
-
- // for public posts always include our own hub
-// this shouldn't be needed any more. collect_recipients should take care of it.
-// $sql_extra = (($private) ? "" : " or hubloc_url = '" . dbesc(z_root()) . "' ");
-
logger('notifier: hub choice: ' . intval($relay_to_owner) . ' ' . intval($private) . ' ' . $cmd, LOGGER_DEBUG);
if($relay_to_owner && (! $private) && ($cmd !== 'relay')) {
diff --git a/include/ratenotif.php b/include/ratenotif.php
new file mode 100644
index 000000000..4fa0077a6
--- /dev/null
+++ b/include/ratenotif.php
@@ -0,0 +1,124 @@
+<?php
+
+require_once('include/cli_startup.php');
+require_once('include/zot.php');
+require_once('include/queue_fn.php');
+
+
+function ratenotif_run($argv, $argc){
+
+ cli_startup();
+
+ $a = get_app();
+
+ require_once("session.php");
+ require_once("datetime.php");
+ require_once('include/items.php');
+ require_once('include/Contact.php');
+
+ if($argc < 3)
+ return;
+
+
+ logger('ratenotif: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
+
+ $cmd = $argv[1];
+
+ $item_id = $argv[2];
+
+
+ if($cmd === 'rating') {
+ $r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1",
+ intval($item_id)
+ );
+ if(! $r) {
+ logger('rating not found');
+ return;
+ }
+
+ $encoded_item = array(
+ 'type' => 'rating',
+ 'encoding' => 'zot',
+ 'target' => $r[0]['xlink_link'],
+ 'rating' => intval($r[0]['xlink_rating']),
+ 'rating_text' => $r[0]['xlink_rating_text'],
+ 'signature' => $r[0]['xlink_sig'],
+ 'edited' => $r[0]['xlink_updated']
+ );
+ }
+
+ $channel = channelx_by_hash($r[0]['xlink_xchan']);
+ if(! $channel) {
+ logger('no channel');
+ return;
+ }
+
+
+ $primary = get_directory_primary();
+
+ if(! $primary)
+ return;
+
+
+ $interval = ((get_config('system','delivery_interval') !== false)
+ ? intval(get_config('system','delivery_interval')) : 2 );
+
+ $deliveries_per_process = intval(get_config('system','delivery_batch_count'));
+
+ if($deliveries_per_process <= 0)
+ $deliveries_per_process = 1;
+
+ $deliver = array();
+
+ $x = z_fetch_url($primary . '/regdir');
+ if($x['success']) {
+ $j = json_decode($x['body'],true);
+ if($j && $j['success'] && is_array($j['directories'])) {
+
+ foreach($j['directories'] as $h) {
+// if($h == z_root())
+// continue;
+
+ $hash = random_string();
+ $n = zot_build_packet($channel,'notify',null,null,$hash);
+
+ q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
+ dbesc($hash),
+ intval($channel['channel_account_id']),
+ intval($channel['channel_id']),
+ dbesc('zot'),
+ dbesc($h . '/post'),
+ intval(1),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($n),
+ dbesc(json_encode($encoded_item))
+ );
+ }
+ $deliver[] = $hash;
+
+ if(count($deliver) >= $deliveries_per_process) {
+ proc_run('php','include/deliver.php',$deliver);
+ $deliver = array();
+ if($interval)
+ @time_sleep_until(microtime(true) + (float) $interval);
+ }
+
+
+ // catch any stragglers
+
+ if(count($deliver)) {
+ proc_run('php','include/deliver.php',$deliver);
+ }
+ }
+ }
+
+ logger('ratenotif: complete.');
+ return;
+
+}
+
+if (array_search(__file__,get_included_files())===0){
+ ratenotif_run($argv,$argc);
+ killme();
+}
diff --git a/include/zot.php b/include/zot.php
index 04b6806c2..1e9577dc6 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -1108,7 +1108,8 @@ function zot_import($arr, $sender_url) {
if(array_key_exists('message',$i) && array_key_exists('type',$i['message']) && $i['message']['type'] === 'rating') {
// rating messages are processed only by directory servers
logger('Rating received: ' . print_r($arr,true), LOGGER_DATA);
- $result = process_rating_delivery($i['notify']['sender'],$arr);
+ $result = process_rating_delivery($i['notify']['sender'],$i['message']);
+ continue;
}
if(array_key_exists('recipients',$i['notify']) && count($i['notify']['recipients'])) {
@@ -1813,34 +1814,52 @@ function process_mail_delivery($sender,$arr,$deliveries) {
function process_rating_delivery($sender,$arr) {
- $dirmode = intval(get_config('system','directory_mode'));
- if($dirmode == DIRECTORY_MODE_NORMAL)
- return;
+ logger('process_rating_delivery: ' . print_r($arr,true));
if(! $arr['target'])
return;
- $r = q("select * from xlink where xlink_xchan = '%s' and xlink_target = '%s' limit 1",
+ $z = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1",
+ dbesc($sender['hash'])
+ );
+
+
+ if((! $z) || (! rsa_verify($arr['target'] . '.' . $arr['rating'] . '.' . $arr['rating_text'], base64url_decode($arr['signature']),$z[0]['xchan_pubkey']))) {
+ logger('failed to verify rating');
+ return;
+ }
+
+ $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
dbesc($sender['hash']),
dbesc($arr['target'])
- );
+ );
+
if($r) {
- $x = q("update xlink set xlink_rating = %d, xlink_rating_text = '%s', xlink_updated = '%s' where xlink_id = %d",
+ if($r[0]['xlink_updated'] >= $arr['edited']) {
+ logger('rating message duplicate');
+ return;
+ }
+
+ $x = q("update xlink set xlink_rating = %d, xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s' where xlink_id = %d",
intval($arr['rating']),
- intval($arr['rating_text']),
+ dbesc($arr['rating_text']),
+ dbesc($arr['signature']),
dbesc(datetime_convert()),
intval($r[0]['xlink_id'])
);
+ logger('rating updated');
}
else {
- $x = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_updated, xlink_static )
+ $x = 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($sender['hash']),
dbesc($arr['target']),
intval($arr['rating']),
- intval($arr['rating_text']),
+ dbesc($arr['rating_text']),
+ dbesc($arr['signature']),
dbesc(datetime_convert())
);
+ logger('rating created');
}
return;
}
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)
diff --git a/view/tpl/direntry.tpl b/view/tpl/direntry.tpl
index 6ba86a085..450bddd95 100755
--- a/view/tpl/direntry.tpl
+++ b/view/tpl/direntry.tpl
@@ -15,9 +15,9 @@
<div class='contact-info'>
<div class="contact-name" id="directory-name-{{$entry.id}}" ><a href='{{$entry.profile_link}}' >{{$entry.name}}</a>{{if $entry.online}} <i class="icon-asterisk online-now" title="{{$entry.online}}"></i>{{/if}}</div>
-{{if $entry.rateme}}
-<div id="dir-rating-wrapper-{{$entry.id}}" style="float:right; width: 20%;">
-62 ratings<br />
+{{*if $entry.rateme*}}
+<div id="dir-rating-wrapper-{{$entry.id}}" style="float:right; width: 20%;">{{if $entry.total_ratings}}<a href="prep/{{$entry.hash}}">
+{{$entry.total_ratings}}</a>{{/if}}<br />
<div id="dir-rating-slider-{{$entry.id}}" class="dir-slider" style="height: 32px; margin-right:10px;">
<input id="dir-rating-range-{{$entry.id}}" type="text" value="0" name="fake-rating-{{$entry.id}}" style="display: none;">
</div>
@@ -26,7 +26,7 @@
<script>
$("#dir-rating-range-{{$entry.id}}").jRange({ from: -10, to: 10, step: 1, width:'100%', showLabels: false, showScale: true, scale : [ '-10','-5','0','5','10' ], onstatechange: function(v) { $("#contact-rating-mirror").val(v); } });
</script>
-{{/if}}
+{{*/if*}}
{{if $entry.public_forum}}
<div class="contact-forum">
{{$entry.forum_label}} @{{$entry.nickname}}+