From 125ebfeb0cca25a34a54fc57908d2afa93b96f44 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 16:54:55 -0800 Subject: add signatures --- mod/prate.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'mod') diff --git a/mod/prate.php b/mod/prate.php index 28703d414..9c46d205a 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,7 +21,12 @@ 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", dbesc($channel['channel_hash']), @@ -28,20 +34,22 @@ function prate_post(&$a) { ); 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", -- cgit v1.2.3 From fb6deb113b718e18bf1e5031ec868b53acf93c1e Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 17:32:54 -0800 Subject: improved directory registration - honour standalones and do the right thing --- mod/regdir.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'mod') diff --git a/mod/regdir.php b/mod/regdir.php index c00187978..eecc99ca5 100644 --- a/mod/regdir.php +++ b/mod/regdir.php @@ -47,9 +47,14 @@ function regdir_init(&$a) { json_return_and_die($result); } else { - $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s'", - dbesc(get_directory_realm()) - ); + if($dirmode == DIRECTORY_MODE_STANDALONE) { + $r = array(array('site_url' => z_root())); + } + else { + $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s'", + dbesc(get_directory_realm()) + ); + } if($r) { $result['success'] = true; $result['directories'] = array(); -- cgit v1.2.3 From fa710106e5f97744e43a61a7e9ef5a1b993261ee Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 17:58:51 -0800 Subject: sign the ratings, fix the bugs --- mod/connedit.php | 17 +++++++++++++---- mod/prate.php | 2 +- mod/prep.php | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'mod') diff --git a/mod/connedit.php b/mod/connedit.php index 8c0212afe..93cf1b09a 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -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 = $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($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", @@ -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/prate.php b/mod/prate.php index 9c46d205a..00de8b6fc 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -28,7 +28,7 @@ function prate_post(&$a) { $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) ); diff --git a/mod/prep.php b/mod/prep.php index 896717826..9d21b0409 100644 --- a/mod/prep.php +++ b/mod/prep.php @@ -54,7 +54,7 @@ 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", + $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['xchan_hash']) ); -- cgit v1.2.3 From 1807db6cb0cc297aff32750b371a4e2e6539ad31 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 20:13:07 -0800 Subject: send rating information to directories --- mod/connedit.php | 6 +++--- mod/prate.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'mod') diff --git a/mod/connedit.php b/mod/connedit.php index 93cf1b09a..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; @@ -132,7 +132,7 @@ function connedit_post(&$a) { if(! $is_self) { - $signed = $target . '.' . $rating . '.' . $rating_text; + $signed = $orig_record[0]['abook_xchan'] . '.' . $rating . '.' . $rating_text; $sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey'])); @@ -170,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); } } diff --git a/mod/prate.php b/mod/prate.php index 00de8b6fc..30de97927 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -60,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", -- cgit v1.2.3 From 77379029f566fc759651fdaa01f5bfaf2ad9db28 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 21:07:46 -0800 Subject: add ratings to the directory sync arrays --- mod/dirsearch.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mod') 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 { -- cgit v1.2.3 From 6067274b51cfec0d14ad4a68675d07a2e6a39387 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Feb 2015 23:58:44 -0800 Subject: start to tie ratings to the directory page --- mod/directory.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mod') 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, -- cgit v1.2.3 From 4362aa4c26f4a5931cacacb182a750c2273f7d59 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 11:18:00 -0800 Subject: for now punt if have no poi, but we should get it from the server --- mod/prep.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/prep.php b/mod/prep.php index 9d21b0409..950b602c9 100644 --- a/mod/prep.php +++ b/mod/prep.php @@ -55,7 +55,7 @@ function prep_content(&$a) { return; $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['xchan_hash']) + dbesc(($a->poi) ? $a->poi['xchan_hash'] : argv(1)) ); if(! $r) -- cgit v1.2.3 From df632c423252a19b41d3502412135309063b85fa Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 15:06:16 -0800 Subject: run ratingsearch on the server --- mod/prep.php | 75 -------------------------------------------------- mod/ratings.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mod/ratingsearch.php | 58 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 75 deletions(-) delete mode 100644 mod/prep.php create mode 100644 mod/ratings.php create mode 100644 mod/ratingsearch.php (limited to 'mod') diff --git a/mod/prep.php b/mod/prep.php deleted file mode 100644 index 950b602c9..000000000 --- a/mod/prep.php +++ /dev/null @@ -1,75 +0,0 @@ - 1) - $hash = argv(1); - - if(! $hash) { - notice('Must supply a channel identififier.'); - return; - } - - if(strpos($hash,'@')) { - $r = q("select * from hubloc where hubloc_addr = '%s' limit 1", - dbesc($hash) - ); - if($r) - $hash = $r[0]['hubloc_hash']; - } - - $p = q("select * from xchan where xchan_hash like '%s'", - dbesc($hash . '%') - ); - - if($p) - $a->poi = $p[0]; - -} - - - - - -function prep_content(&$a) { - - - $poco_rating = get_config('system','poco_rating_enable'); - // if unset default to enabled - if($poco_rating === false) - $poco_rating = true; - - if(! $poco_rating) - return; - - 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 and xlink_static = 1", - dbesc(($a->poi) ? $a->poi['xchan_hash'] : argv(1)) - ); - - if(! $r) - notice( t('No ratings available') . EOL); - - - $o = replace_macros(get_markup_template('prep.tpl'),array( - '$header' => t('Ratings'), - '$rating_lbl' => t('Rating: ' ), - '$rating_text_lbl' => t('Description: '), - '$raters' => $r - )); - - return $o; -} - - \ No newline at end of file diff --git a/mod/ratings.php b/mod/ratings.php new file mode 100644 index 000000000..fe7cca6e1 --- /dev/null +++ b/mod/ratings.php @@ -0,0 +1,78 @@ + 1) + $hash = argv(1); + + if(! $hash) { + notice('Must supply a channel identififier.'); + return; + } + + $results = false; + + $x = z_fetch_url($url . '/ratingsearch/' . $hash); + + + if($x['success']) + $results = json_decode($x['body'],true); + + + if((! $results) || (! $results['success'])) { + + notice('No results.'); + return; + } + + $a->poi = $results['target']; + $a->data = $results['ratings']; + + if(! $a->data) { + notice( t('No ratings') . EOL); + } + + return; +} + + + + + +function ratings_content(&$a) { + + $poco_rating = get_config('system','poco_rating_enable'); + // if unset default to enabled + if($poco_rating === false) + $poco_rating = true; + + if(! $poco_rating) + return; + + $o = replace_macros(get_markup_template('prep.tpl'),array( + '$header' => t('Ratings'), + '$rating_lbl' => t('Rating: ' ), + '$rating_text_lbl' => t('Description: '), + '$raters' => $a->data + )); + + return $o; +} + + \ No newline at end of file diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php new file mode 100644 index 000000000..9a537bf97 --- /dev/null +++ b/mod/ratingsearch.php @@ -0,0 +1,58 @@ + false); + + $dirmode = intval(get_config('system','directory_mode')); + + if($dirmode == DIRECTORY_MODE_NORMAL) { + $ret['message'] = 'This site is not a directory server.'; + json_return_and_die($ret); + } + + if(argc() > 1) + $hash = argv(1); + + if(! $hash) { + $ret['message'] = 'No channel identifier'; + json_return_and_die($ret); + } + + if(strpos($hash,'@')) { + $r = q("select * from hubloc where hubloc_addr = '%s' limit 1", + dbesc($hash) + ); + if($r) + $hash = $r[0]['hubloc_hash']; + } + + $p = q("select * from xchan where xchan_hash like '%s'", + dbesc($hash . '%') + ); + + if($p) + $ret['target'] = $p[0]; + else { + $ret['message'] = 'channel not found'; + json_return_and_die($ret); + } + + $ret['success'] = true; + + $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash + where xlink_link = '%s' and xlink_rating != 0 and xlink_static = 1", + dbesc($p[0]['xchan_hash']) + ); + + if($r) { + $ret['ratings'] = $r; + } + else + $ret['ratings'] = array(); + + json_return_and_die($ret); + +} + -- cgit v1.2.3 From 36b756e4cde4f45993a1941eb6b8a71bb348c6e4 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 15:16:03 -0800 Subject: honour block public setting - especially for standalones --- mod/dirsearch.php | 10 +++++++++- mod/ratings.php | 9 +++++++++ mod/ratingsearch.php | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/dirsearch.php b/mod/dirsearch.php index 0f4dde976..fcd72e9eb 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -12,7 +12,6 @@ function dirsearch_content(&$a) { $ret = array('success' => false); - // If you've got a public directory server, you probably shouldn't block public access $dirmode = intval(get_config('system','directory_mode')); @@ -22,6 +21,15 @@ function dirsearch_content(&$a) { json_return_and_die($ret); } + + // If you've got a public directory server, you probably shouldn't block public access + + if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + $ret['message'] = 'permission denied'; + json_return_and_die($ret); + } + + if(argc() > 1 && argv(1) === 'sites') { $ret = list_public_sites(); json_return_and_die($ret); diff --git a/mod/ratings.php b/mod/ratings.php index fe7cca6e1..4b94f0e52 100644 --- a/mod/ratings.php +++ b/mod/ratings.php @@ -4,6 +4,10 @@ require_once('include/dir_fns.php'); function ratings_init(&$a) { + if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + return; + } + $dirmode = intval(get_config('system','directory_mode')); $x = find_upstream_directory($dirmode); @@ -57,6 +61,11 @@ function ratings_init(&$a) { function ratings_content(&$a) { + if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + notice( t('Public access denied.') . EOL); + return; + } + $poco_rating = get_config('system','poco_rating_enable'); // if unset default to enabled if($poco_rating === false) diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php index 9a537bf97..558b459eb 100644 --- a/mod/ratingsearch.php +++ b/mod/ratingsearch.php @@ -12,6 +12,12 @@ function ratingsearch_init(&$a) { json_return_and_die($ret); } + if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + $ret['message'] = 'permission denied'; + json_return_and_die($ret); + } + + if(argc() > 1) $hash = argv(1); -- cgit v1.2.3 From c417a43338087de82bd1c067c479320a923fe619 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 15:50:12 -0800 Subject: styling for the directory page when it comes to ratings --- mod/directory.php | 2 ++ mod/dirsearch.php | 9 --------- mod/ratingsearch.php | 6 ------ 3 files changed, 2 insertions(+), 15 deletions(-) (limited to 'mod') diff --git a/mod/directory.php b/mod/directory.php index 7f9283ba4..d9316ef67 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -192,6 +192,8 @@ function directory_content(&$a) { if($rr['total_ratings']) $total_ratings = sprintf( tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']); + else + $total_ratings = ''; $profile = $rr; diff --git a/mod/dirsearch.php b/mod/dirsearch.php index fcd72e9eb..69b7e2eac 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -21,15 +21,6 @@ function dirsearch_content(&$a) { json_return_and_die($ret); } - - // If you've got a public directory server, you probably shouldn't block public access - - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { - $ret['message'] = 'permission denied'; - json_return_and_die($ret); - } - - if(argc() > 1 && argv(1) === 'sites') { $ret = list_public_sites(); json_return_and_die($ret); diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php index 558b459eb..9a537bf97 100644 --- a/mod/ratingsearch.php +++ b/mod/ratingsearch.php @@ -12,12 +12,6 @@ function ratingsearch_init(&$a) { json_return_and_die($ret); } - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { - $ret['message'] = 'permission denied'; - json_return_and_die($ret); - } - - if(argc() > 1) $hash = argv(1); -- cgit v1.2.3 From 5cb2f55dbbe715219dd18c60345e341ed478a753 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 16:52:09 -0800 Subject: rating form work --- mod/prate.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mod') diff --git a/mod/prate.php b/mod/prate.php index 30de97927..25d279a5b 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -3,6 +3,11 @@ function prate_post(&$a) { +logger('request: ' . print_r($_REQUEST,true)); +return; + + + if(! local_channel()) return; -- cgit v1.2.3 From 17ffe122b309610208d769f0e2b41f53fcf9d254 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 18:10:55 -0800 Subject: ratings - mopping up, most everything but directory sync implemented --- mod/connedit.php | 30 ++++++++++++++++++++++-------- mod/directory.php | 2 ++ mod/prate.php | 27 --------------------------- 3 files changed, 24 insertions(+), 35 deletions(-) (limited to 'mod') diff --git a/mod/connedit.php b/mod/connedit.php index 79c7e6a4f..58366da6d 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -180,13 +180,11 @@ function connedit_post(&$a) { } - $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_rating = %d, abook_rating_text = '%s', abook_flags = %d + $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d where abook_id = %d AND abook_channel = %d", dbesc($profile_id), intval($abook_my_perms), intval($closeness), - intval($rating), - dbesc($rating_text), intval($abook_flags), intval($contact_id), intval(local_channel()) @@ -324,6 +322,7 @@ function connedit_content(&$a) { return login(); } + $channel = $a->get_channel(); $my_perms = get_channel_default_perms(local_channel()); $role = get_pconfig(local_channel(),'system','permissions_role'); if($role) { @@ -572,6 +571,21 @@ function connedit_content(&$a) { )); } + $rating_val = 0; + $rating_text = ''; + +dbg(1); + $xl = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", + dbesc($channel['channel_hash']), + dbesc($contact['xchan_hash']) + ); +dbg(0); + if($xl) { + $rating_val = intval($xl[0]['xlink_rating']); + $rating_text = $xl[0]['xlink_rating_text']; + } + + $poco_rating = get_config('system','poco_rating_enable'); // if unset default to enabled @@ -581,7 +595,7 @@ function connedit_content(&$a) { if($poco_rating) { $rating = replace_macros(get_markup_template('rating_slider.tpl'),array( '$min' => -10, - '$val' => (($contact['abook_rating']) ? $contact['abook_rating'] : 0), + '$val' => $rating_val )); } else { @@ -621,11 +635,11 @@ function connedit_content(&$a) { '$viewprof' => t('View Profile'), '$clickme' => t('Click to open/close'), '$lbl_slider' => t('Slide to adjust your degree of friendship'), - '$lbl_rating' => t('Rating (this information may be public)'), - '$lbl_rating_txt' => t('Optionally explain your rating (this information may be public)'), - '$rating_txt' => $contact['abook_rating_text'], + '$lbl_rating' => t('Rating (this information is public)'), + '$lbl_rating_txt' => t('Optionally explain your rating (this information is public)'), + '$rating_txt' => $rating_text, '$rating' => $rating, - '$rating_val' => $contact['abook_rating'], + '$rating_val' => $rating_val, '$slide' => $slide, '$tabs' => $t, '$tab_str' => $tab_str, diff --git a/mod/directory.php b/mod/directory.php index d9316ef67..40ca93af9 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -261,6 +261,8 @@ function directory_content(&$a) { 'location' => $location, 'gender' => $gender, 'total_ratings' => $total_ratings, + 'viewrate' => true, + 'canrate' => ((local_channel()) ? true : false), 'pdesc' => $pdesc, 'marital' => $marital, 'homepage' => $homepage, diff --git a/mod/prate.php b/mod/prate.php index 25d279a5b..62f188891 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -3,11 +3,6 @@ function prate_post(&$a) { -logger('request: ' . print_r($_REQUEST,true)); -return; - - - if(! local_channel()) return; @@ -68,28 +63,6 @@ return; 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; } -- cgit v1.2.3 From 86771547e6d04d046d3beeabb8e4486a59a7fcc6 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 18:35:54 -0800 Subject: finish off the sync functions --- mod/dirsearch.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mod') 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'], -- cgit v1.2.3 From 4ead2cd79d3c7e5c29a11785a3ceefef6d3ba93f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 21:19:29 -0800 Subject: final cleanup on ratings feature --- mod/prate.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/prate.php b/mod/prate.php index 62f188891..b89d16f42 100644 --- a/mod/prate.php +++ b/mod/prate.php @@ -1,5 +1,26 @@ get_channel(); + + $target = argv(1); + if(! $target) + return; + + $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", + dbesc($channel['channel_hash']), + dbesc($target) + ); + if($r) + json_return_and_die(array('rating' => $r[0]['xlink_rating'],'rating_text' => $r[0]['xlink_rating_text'])); + killme(); +} function prate_post(&$a) { @@ -63,7 +84,7 @@ function prate_post(&$a) { proc_run('php','include/ratenotif.php','rating',$record); } - return; + json_return_and_die(array('result' => true));; } @@ -75,3 +96,4 @@ function prate_post(&$a) { + -- cgit v1.2.3 From 0cc29af6d0c305efa35fbe3b0c7bc314f21b4166 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 22:55:01 -0800 Subject: order ratings friends first --- mod/ratings.php | 18 +++++++++++++++++- mod/ratingsearch.php | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'mod') diff --git a/mod/ratings.php b/mod/ratings.php index 4b94f0e52..66392fe2b 100644 --- a/mod/ratings.php +++ b/mod/ratings.php @@ -8,6 +8,9 @@ function ratings_init(&$a) { return; } + if(local_channel()) + load_contact_links(local_channel()); + $dirmode = intval(get_config('system','directory_mode')); $x = find_upstream_directory($dirmode); @@ -46,7 +49,20 @@ function ratings_init(&$a) { } $a->poi = $results['target']; - $a->data = $results['ratings']; + + $friends = array(); + $others = array(); + + if($results['ratings']) { + foreach($results['ratings'] as $n) { + if(array_key_exists($n['xchan_hash'],$a->contacts)) + $friends[] = $n; + else + $others[] = $n; + } + } + + $a->data = array_merge($friends,$others); if(! $a->data) { notice( t('No ratings') . EOL); diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php index 9a537bf97..ec2db570b 100644 --- a/mod/ratingsearch.php +++ b/mod/ratingsearch.php @@ -42,7 +42,7 @@ function ratingsearch_init(&$a) { $ret['success'] = true; $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash - where xlink_link = '%s' and xlink_rating != 0 and xlink_static = 1", + where xlink_link = '%s' and xlink_rating != 0 and xlink_static = 1 order by xchan_name asc", dbesc($p[0]['xchan_hash']) ); -- cgit v1.2.3 From 127bf82187c266c2202fd33003e60b5061778cd7 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 23:30:07 -0800 Subject: probably enough for now - couldn't get the censorship filter in today, I think that's the only bit missing. --- mod/directory.php | 1 + mod/ratings.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/directory.php b/mod/directory.php index 40ca93af9..f19b1142e 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -277,6 +277,7 @@ function directory_content(&$a) { 'keywords' => $out, 'ignlink' => $suggest ? $a->get_baseurl() . '/directory?ignore=' . $rr['hash'] : '', 'ignore_label' => "Don't suggest", + 'safe' => $safe_mode ); $arr = array('contact' => $rr, 'entry' => $entry); diff --git a/mod/ratings.php b/mod/ratings.php index 66392fe2b..fe7865778 100644 --- a/mod/ratings.php +++ b/mod/ratings.php @@ -55,7 +55,7 @@ function ratings_init(&$a) { if($results['ratings']) { foreach($results['ratings'] as $n) { - if(array_key_exists($n['xchan_hash'],$a->contacts)) + if(is_array($a->contacts) && array_key_exists($n['xchan_hash'],$a->contacts)) $friends[] = $n; else $others[] = $n; -- cgit v1.2.3 From 0357180164d9805ded2d00157d74b4b42b9d1055 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 23:33:06 -0800 Subject: remove extra debugging --- mod/connedit.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mod') diff --git a/mod/connedit.php b/mod/connedit.php index 58366da6d..2c4c0cef8 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -574,12 +574,11 @@ function connedit_content(&$a) { $rating_val = 0; $rating_text = ''; -dbg(1); $xl = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", dbesc($channel['channel_hash']), dbesc($contact['xchan_hash']) ); -dbg(0); + if($xl) { $rating_val = intval($xl[0]['xlink_rating']); $rating_text = $xl[0]['xlink_rating_text']; -- cgit v1.2.3 From 1ceb0a7fbab5957ae077ef4867266314c612f8ea Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 3 Feb 2015 23:36:37 -0800 Subject: hide channel address in directory from hovertip if not logged into the matrix --- mod/directory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/directory.php b/mod/directory.php index f19b1142e..329e255cf 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -252,7 +252,7 @@ function directory_content(&$a) { 'public_forum' => $rr['public_forum'], 'photo' => $rr['photo'], 'hash' => $rr['hash'], - 'alttext' => $rr['name'] . ' ' . $rr['address'], + 'alttext' => $rr['name'] . ((local_channel() || remote_channel()) ? ' ' . $rr['address'] : ''), 'name' => $rr['name'], 'details' => $pdesc . $details, 'profile' => $profile, -- cgit v1.2.3 From 561bab4ece9fa5844a0cb00f3cbd75e0855b2796 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 4 Feb 2015 17:32:29 -0800 Subject: remote rating and addition of rate-me to channel profile sidebar --- mod/rate.php | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 mod/rate.php (limited to 'mod') diff --git a/mod/rate.php b/mod/rate.php new file mode 100644 index 000000000..694b88ddd --- /dev/null +++ b/mod/rate.php @@ -0,0 +1,158 @@ +get_channel(); + + $target = $_REQUEST['target']; + if(! $target) + return; + + $a->data['target'] = $target; + + if($target) { + $r = q("SELECT * FROM xchan where xchan_hash like '%s' LIMIT 1", + dbesc($target) + ); + if($r) { + $a->poi = $r[0]; + } + } + + + return; + +} + + +function rate_post(&$a) { + + if(! local_channel()) + return; + + if(! $a->data['target']) + return; + + if(! $_REQUEST['execute']) + return; + + $channel = $a->get_channel(); + + $rating = intval($_POST['rating']); + if($rating < (-10)) + $rating = (-10); + if($rating > 10) + $rating = 10; + + $rating_text = trim(escape_tags($_REQUEST['rating_text'])); + + $signed = $a->data['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($a->data['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($a->data['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($a->data['target']) + ); + if($z) + $record = $z[0]['xlink_id']; + } + + if($record) { + proc_run('php','include/ratenotif.php','rating',$record); + } + +} + + + +function rate_content(&$a) { + + if(! local_channel()) { + notice( t('Permission denied.') . EOL); + return; + } + +// if(! $a->data['target']) { +// notice( t('No recipients.') . EOL); +// return; +// } + + $poco_rating = get_config('system','poco_rating_enable'); + if((! $poco_rating) && ($poco_rating !== false)) { + notice('Ratings are disabled on this site.'); + return; + } + + $channel = $a->get_channel(); + + $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", + dbesc($channel['channel_hash']), + dbesc($a->data['target']) + ); + if($r) + $a->data['xlink'] = $r[0]; + + $rating_val = $r[0]['xlink_rating']; + $rating_text = $r[0]['xlink_rating_text']; + + + // if unset default to enabled + if($poco_rating === false) + $poco_rating = true; + + if($poco_rating) { + $rating = replace_macros(get_markup_template('rating_slider.tpl'),array( + '$min' => -10, + '$val' => $rating_val + )); + } + else { + $rating = false; + } + + $o = replace_macros(get_markup_template('rating_form.tpl'),array( + '$header' => t('Rating'), + 'target' => $a->data['target'], + '$tgt_name' => (($a->poi && $a->poi['xchan_name']) ? $a->poi['xchan_name'] : sprintf( t('Remote Channel [%s] (not yet known on this site)'), substr($a->data['target'],0,16))), + '$lbl_rating' => t('Rating (this information is public)'), + '$lbl_rating_txt' => t('Optionally explain your rating (this information is public)'), + '$rating_txt' => $rating_text, + '$rating' => $rating, + '$rating_val' => $rating_val, + '$slide' => $slide, + '$submit' => t('Submit') + )); + + return $o; + +} \ No newline at end of file -- cgit v1.2.3