remote rating and addition of rate-me to channel profile sidebar
This commit is contained in:
parent
48a145a8ed
commit
561bab4ece
@ -943,10 +943,8 @@ logger('online: ' . $profile['online']);
|
|||||||
|
|
||||||
$tpl = get_markup_template('profile_vcard.tpl');
|
$tpl = get_markup_template('profile_vcard.tpl');
|
||||||
|
|
||||||
// This isn't ideal here because it requires local_channel().
|
require_once('include/widgets.php');
|
||||||
// We need the rating widget to recognise and take you home if you're remote.
|
$z = widget_rating(array('target' => $profile['channel_hash']));
|
||||||
// require_once('include/widgets.php');
|
|
||||||
// $z = widget_rating(array('target' => $profile['channel_hash']));
|
|
||||||
|
|
||||||
$o .= replace_macros($tpl, array(
|
$o .= replace_macros($tpl, array(
|
||||||
'$profile' => $profile,
|
'$profile' => $profile,
|
||||||
|
@ -907,10 +907,6 @@ function widget_random_block($arr) {
|
|||||||
|
|
||||||
function widget_rating($arr) {
|
function widget_rating($arr) {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
if(! local_channel())
|
|
||||||
return;
|
|
||||||
|
|
||||||
$channel = $a->get_channel();
|
|
||||||
|
|
||||||
if($arr['target'])
|
if($arr['target'])
|
||||||
$hash = $arr['target'];
|
$hash = $arr['target'];
|
||||||
@ -920,13 +916,39 @@ function widget_rating($arr) {
|
|||||||
if(! $hash)
|
if(! $hash)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if($hash == $channel['channel_hash'])
|
$url = '';
|
||||||
|
$remote = false;
|
||||||
|
|
||||||
|
if(remote_channel() && ! local_channel()) {
|
||||||
|
$ob = $a->get_observer();
|
||||||
|
if($ob && $ob['xchan_url']) {
|
||||||
|
$p = parse_url($ob['xchan_url']);
|
||||||
|
if($p) {
|
||||||
|
$url = $p['scheme'] . '://' . $p['host'] . (($p['port']) ? ':' . $p['port'] : '');
|
||||||
|
$url .= '/rate?f=&target=' . urlencode($hash);
|
||||||
|
}
|
||||||
|
$remote = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(local_channel()) {
|
||||||
|
$channel = $a->get_channel();
|
||||||
|
|
||||||
|
if($hash == $channel['channel_hash'])
|
||||||
|
return;
|
||||||
|
|
||||||
|
head_add_js('ratings.js');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if((! $remote) && (! local_channel()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
head_add_js('ratings.js');
|
|
||||||
|
|
||||||
$o = '<div class="widget rateme">';
|
$o = '<div class="widget rateme">';
|
||||||
$o .= '<div class="rateme fakelink" onclick="doRatings(\'' . $hash . '\'); return false;"><i class="icon-pencil"></i> ' . t('Rate Me') . '</div></div>';
|
if($remote)
|
||||||
|
$o .= '<a class="rateme" href="' . $url . '"><i class="icon-pencil"></i> ' . t('Rate Me') . '</a></div>';
|
||||||
|
else
|
||||||
|
$o .= '<div class="rateme fakelink" onclick="doRatings(\'' . $hash . '\'); return false;"><i class="icon-pencil"></i> ' . t('Rate Me') . '</div></div>';
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}
|
}
|
158
mod/rate.php
Normal file
158
mod/rate.php
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function rate_init(&$a) {
|
||||||
|
|
||||||
|
if(! local_channel())
|
||||||
|
return;
|
||||||
|
|
||||||
|
$channel = $a->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;
|
||||||
|
|
||||||
|
}
|
8
view/css/mod_rate.css
Normal file
8
view/css/mod_rate.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#rating-slider {
|
||||||
|
width: 600px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#rating-text {
|
||||||
|
width: 400px;
|
||||||
|
height: 60px;
|
||||||
|
}
|
3
view/pdl/mod_rate.pdl
Normal file
3
view/pdl/mod_rate.pdl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[region=aside]
|
||||||
|
[widget=vcard][/widget]
|
||||||
|
[/region]
|
@ -771,7 +771,7 @@ footer {
|
|||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.rateme {
|
a.rateme, div.rateme {
|
||||||
display: block;
|
display: block;
|
||||||
color: $nav_active_icon_colour;
|
color: $nav_active_icon_colour;
|
||||||
background-color: $nav_bg;
|
background-color: $nav_bg;
|
||||||
@ -1455,14 +1455,14 @@ div.jGrowl div.jGrowl-notification {
|
|||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.rconnect, div.rateme {
|
a.rconnect, a.rateme, div.rateme {
|
||||||
color: $nav_active_icon_colour;
|
color: $nav_active_icon_colour;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.rconnect:hover, div.rateme:hover {
|
a.rconnect:hover, a.rateme:hover, div.rateme:hover {
|
||||||
color: #0080FF;
|
color: #0080FF;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
<a href="{{$connect_url}}" class="rconnect"><i class="icon-plus connect-icon"></i> {{$connect}}</a>
|
<a href="{{$connect_url}}" class="rconnect"><i class="icon-plus connect-icon"></i> {{$connect}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{$rating}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="vcard-end"></div>
|
<div id="vcard-end"></div>
|
||||||
|
|
||||||
|
22
view/tpl/rating_form.tpl
Normal file
22
view/tpl/rating_form.tpl
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<h3>{{$header}}</h3>
|
||||||
|
|
||||||
|
<div class="rating-target-name">{{$tgt_name}}</div>
|
||||||
|
|
||||||
|
<h3>{{$lbl_rating}}</h3>
|
||||||
|
|
||||||
|
<form action="rate" method="post">
|
||||||
|
|
||||||
|
{{$rating}}
|
||||||
|
|
||||||
|
<input type="hidden" name="execute" value="1" />
|
||||||
|
<input type="hidden" name="target" value="{{$target}}" />
|
||||||
|
|
||||||
|
<input id="contact-rating-mirror" type="hidden" name="rating" value="{{$rating_val}}" />
|
||||||
|
<h3 class="abook-rating-text-desc">{{$lbl_rating_txt}}</h3>
|
||||||
|
<textarea name="rating_text" id="rating-text" >{{$rating_txt}}</textarea>
|
||||||
|
|
||||||
|
<div class="clear"></div>
|
||||||
|
|
||||||
|
<input class="contact-edit-submit" type="submit" name="done" value="{{$submit}}" />
|
||||||
|
|
||||||
|
</form>
|
Reference in New Issue
Block a user