streams/mod/ratings.php

110 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2015-02-03 23:06:16 +00:00
require_once('include/dir_fns.php');
2015-02-03 23:06:16 +00:00
function ratings_init(&$a) {
if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
return;
}
2015-02-04 06:55:01 +00:00
if(local_channel())
load_contact_links(local_channel());
2015-02-03 23:06:16 +00:00
$dirmode = intval(get_config('system','directory_mode'));
$x = find_upstream_directory($dirmode);
if($x)
$url = $x['url'];
$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(argc() > 1)
$hash = argv(1);
if(! $hash) {
notice('Must supply a channel identififier.');
return;
}
2015-02-03 23:06:16 +00:00
$results = false;
2015-02-16 05:22:05 +00:00
$x = z_fetch_url($url . '/ratingsearch/' . urlencode($hash));
2015-02-03 23:06:16 +00:00
if($x['success'])
$results = json_decode($x['body'],true);
if((! $results) || (! $results['success'])) {
notice('No results.');
return;
}
2015-02-16 05:22:05 +00:00
if(array_key_exists('xchan_hash',$results['target']))
$a->poi = $results['target'];
2015-02-04 06:55:01 +00:00
$friends = array();
$others = array();
if($results['ratings']) {
foreach($results['ratings'] as $n) {
if(is_array($a->contacts) && array_key_exists($n['xchan_hash'],$a->contacts))
2015-02-04 06:55:01 +00:00
$friends[] = $n;
else
$others[] = $n;
}
}
2015-02-16 05:22:05 +00:00
$a->data = array('target' => $results['target'], 'results' => array_merge($friends,$others));
2015-02-16 05:22:05 +00:00
if(! $a->data['results']) {
2015-02-03 23:06:16 +00:00
notice( t('No ratings') . EOL);
}
2015-01-16 03:05:42 +00:00
2015-02-03 23:06:16 +00:00
return;
2015-01-16 03:05:42 +00:00
}
2015-02-03 23:06:16 +00:00
function ratings_content(&$a) {
2015-01-16 03:05:42 +00:00
if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
notice( t('Public access denied.') . EOL);
return;
}
2015-01-16 03:05:42 +00:00
$poco_rating = get_config('system','poco_rating_enable');
// if unset default to enabled
if($poco_rating === false)
$poco_rating = true;
if(! $poco_rating)
return;
2015-02-16 05:22:05 +00:00
$site_target = ((array_key_exists('target',$a->data) && array_key_exists('site_url',$a->data['target'])) ?
'<a href="' . $a->data['target']['site_url'] . '" >' . $a->data['target']['site_url'] . '</a>' : '');
2015-02-16 05:22:05 +00:00
$o = replace_macros(get_markup_template('prep.tpl'),array(
'$header' => t('Ratings'),
'$rating_lbl' => t('Rating: ' ),
2015-02-16 05:22:05 +00:00
'$website' => t('Website: '),
'$site' => $site_target,
'$rating_text_lbl' => t('Description: '),
2015-02-16 05:22:05 +00:00
'$raters' => $a->data['results']
));
return $o;
}