diff options
-rw-r--r-- | include/identity.php | 6 | ||||
-rw-r--r-- | include/widgets.php | 38 | ||||
-rw-r--r-- | mod/rate.php | 158 | ||||
-rw-r--r-- | view/css/mod_rate.css | 8 | ||||
-rw-r--r-- | view/pdl/mod_rate.pdl | 3 | ||||
-rw-r--r-- | view/theme/redbasic/css/style.css | 6 | ||||
-rwxr-xr-x | view/tpl/profile_vcard.tpl | 2 | ||||
-rw-r--r-- | view/tpl/rating_form.tpl | 22 |
8 files changed, 228 insertions, 15 deletions
diff --git a/include/identity.php b/include/identity.php index aef6471e5..415e85f2f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -943,10 +943,8 @@ logger('online: ' . $profile['online']); $tpl = get_markup_template('profile_vcard.tpl'); -// This isn't ideal here because it requires local_channel(). -// We need the rating widget to recognise and take you home if you're remote. -// require_once('include/widgets.php'); -// $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( '$profile' => $profile, diff --git a/include/widgets.php b/include/widgets.php index 71407ad3d..7d2aaeb99 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -907,10 +907,6 @@ function widget_random_block($arr) { function widget_rating($arr) { $a = get_app(); - if(! local_channel()) - return; - - $channel = $a->get_channel(); if($arr['target']) $hash = $arr['target']; @@ -920,13 +916,39 @@ function widget_rating($arr) { if(! $hash) return; - if($hash == $channel['channel_hash']) - return; + $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; + } + } - head_add_js('ratings.js'); + if(local_channel()) { + $channel = $a->get_channel(); + + if($hash == $channel['channel_hash']) + return; + + head_add_js('ratings.js'); + + } + + if((! $remote) && (! local_channel())) + return; $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; }
\ No newline at end of file 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 @@ +<?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; + +}
\ No newline at end of file diff --git a/view/css/mod_rate.css b/view/css/mod_rate.css new file mode 100644 index 000000000..58e87b9b4 --- /dev/null +++ b/view/css/mod_rate.css @@ -0,0 +1,8 @@ +#rating-slider { + width: 600px !important; +} + +#rating-text { + width: 400px; + height: 60px; +} diff --git a/view/pdl/mod_rate.pdl b/view/pdl/mod_rate.pdl new file mode 100644 index 000000000..d8f50ad7a --- /dev/null +++ b/view/pdl/mod_rate.pdl @@ -0,0 +1,3 @@ +[region=aside] +[widget=vcard][/widget] +[/region] diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index 32ded75ba..1aa7cc729 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -771,7 +771,7 @@ footer { clear: both; } -div.rateme { +a.rateme, div.rateme { display: block; color: $nav_active_icon_colour; background-color: $nav_bg; @@ -1455,14 +1455,14 @@ div.jGrowl div.jGrowl-notification { width: 90%; } -a.rconnect, div.rateme { +a.rconnect, a.rateme, div.rateme { color: $nav_active_icon_colour; text-decoration: none; font-weight: normal; outline: none; } -a.rconnect:hover, div.rateme:hover { +a.rconnect:hover, a.rateme:hover, div.rateme:hover { color: #0080FF; text-decoration: none; } diff --git a/view/tpl/profile_vcard.tpl b/view/tpl/profile_vcard.tpl index bc093ebb5..cae920c5d 100755 --- a/view/tpl/profile_vcard.tpl +++ b/view/tpl/profile_vcard.tpl @@ -51,6 +51,8 @@ <a href="{{$connect_url}}" class="rconnect"><i class="icon-plus connect-icon"></i> {{$connect}}</a> {{/if}} +{{$rating}} + </div> <div id="vcard-end"></div> diff --git a/view/tpl/rating_form.tpl b/view/tpl/rating_form.tpl new file mode 100644 index 000000000..216bf6ede --- /dev/null +++ b/view/tpl/rating_form.tpl @@ -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>
\ No newline at end of file |