aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Ratings.php
blob: 055b16ca342d704bcbfc3976fbf85bac50da65f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Zotlabs\Module;

require_once('include/dir_fns.php');


class Ratings extends \Zotlabs\Web\Controller {

	function init() {
	
		if(observer_prohibited()) {
			return;
		}
	
		if(local_channel())
			load_contact_links(local_channel());
	
		$dirmode = intval(get_config('system','directory_mode'));
	
		$x = find_upstream_directory($dirmode);
		if($x)
			$url = $x['url'];
	
		$rating_enabled = get_config('system','rating_enabled');
	
		if(! $rating_enabled)
			return;
	
		if(argc() > 1)
			$hash = argv(1);
	
		if(! $hash) {
			notice('Must supply a channel identififier.');
			return;
		}
	
		$results = false;
	
		$x = z_fetch_url($url . '/ratingsearch/' . urlencode($hash));
	
	
		if($x['success'])
			$results = json_decode($x['body'],true);
	
	
		if((! $results) || (! $results['success'])) {
	
			notice('No results.');
			return;
		} 
	
		if(array_key_exists('xchan_hash',$results['target']))
			\App::$poi = $results['target'];
		
		$friends = array();
		$others = array();
	
		if($results['ratings']) {
			foreach($results['ratings'] as $n) {
				if(is_array(\App::$contacts) && array_key_exists($n['xchan_hash'],\App::$contacts))
					$friends[] = $n;
				else
					$others[] = $n;
			}
		}
	
		\App::$data = array('target' => $results['target'], 'results' => array_merge($friends,$others));
	
		if(! \App::$data['results']) {
			notice( t('No ratings') . EOL);
		}
	
		return;
	}
	
	
	
	
	
	function get() {
	
		if(observer_prohibited()) {
			notice( t('Public access denied.') . EOL);
			return;
		}
	
		$rating_enabled = get_config('system','rating_enabled');
	
		if(! $rating_enabled)
			return;
	
		$site_target = ((array_key_exists('target',\App::$data) && array_key_exists('site_url',\App::$data['target'])) ?
			'<a href="' . \App::$data['target']['site_url'] . '" >' . \App::$data['target']['site_url'] . '</a>' : '');
	
	
		$o = replace_macros(get_markup_template('prep.tpl'),array(
			'$header' => t('Ratings'),
			'$rating_lbl' => t('Rating: ' ),
			'$website' => t('Website: '),
			'$site' => $site_target,
			'$rating_text_lbl' => t('Description: '),
			'$raters' => \App::$data['results']
		));
	
		return $o;
	}
	
				
}