aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Widget/Rating.php
blob: f8986ac935d64008c993cf2dc719da69d1960e36 (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
<?php

/**
 *   * Name: Rating
 *   * Description: Deprecated rating tool
 *   * Requires: disabled_for_pdledit_gui
 */

namespace Zotlabs\Widget;

use Zotlabs\Lib\Config;

class Rating {

	function widget($arr) {


		$rating_enabled = Config::Get('system','rating_enabled');
		if(! $rating_enabled) {
			return;
		}

		if($arr['target'])
			$hash = $arr['target'];
		else
			$hash = \App::$poi['xchan_hash'];

		if(! $hash)
			return;

		$url = '';
		$remote = false;

		if(remote_channel() && ! local_channel()) {
			$ob = \App::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;
			}
		}

		$self = false;

		if(local_channel()) {
			$channel = \App::get_channel();

			if($hash == $channel['channel_hash'])
				$self = true;

			head_add_js('ratings.js');
		}


		$o = '<div class="widget">';
		$o .= '<h3>' . t('Rating Tools') . '</h3>';

		if((($remote) || (local_channel())) && (! $self)) {
			if($remote)
				$o .= '<a class="btn btn-block btn-primary btn-sm" href="' . $url . '"><i class="fa fa-pencil"></i> ' . t('Rate Me') . '</a>';
			else
				$o .= '<div class="btn btn-block btn-primary btn-sm" onclick="doRatings(\'' . $hash . '\'); return false;"><i class="fa fa-pencil"></i> ' . t('Rate Me') . '</div>';
		}

		$o .= '<a class="btn btn-block btn-default btn-sm" href="ratings/' . $hash . '"><i class="fa fa-eye"></i> ' . t('View Ratings') . '</a>';
		$o .= '</div>';

		return $o;

	}
}