aboutsummaryrefslogtreecommitdiffstats
path: root/mod/dirprofile.php
blob: 133089419b5158e4be3a461c9437d698f3742c1d (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php

require_once('include/dir_fns.php');

function dirprofile_init(&$a) {

	if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
		notice( t('Public access denied.') . EOL);
		return;
	}

	$hash = $_REQUEST['hash'];
	if(! $hash)
		return '';

	$o = '';

	$dirmode = intval(get_config('system','directory_mode'));

	if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
		$url = z_root() . '/dirsearch';
	}
	if(! $url) {
		$directory = find_upstream_directory($dirmode);

		if($directory) {
			$url = $directory['url'] . '/dirsearch';
		}
		else {
			$url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
		}
	}
	logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);

	$contacts = array();

	if(local_user()) {
		$x = q("select abook_xchan from abook where abook_channel = %d",
			intval(local_user())
		);
		if($x) {
			foreach($x as $xx)
				$contacts[] = $xx['abook_xchan'];
		}
	}



	if($url) {

		$query = $url . '?f=&hash=' . $hash;

		$x = z_fetch_url($query);
		logger('dirprofile: return from upstream: ' . print_r($x,true), LOGGER_DATA);

		if($x['success']) {
			$t = 0;
			$j = json_decode($x['body'],true);
			if($j) {

				if($j['results']) {

					$entries = array();

					$photo = 'thumb';

					foreach($j['results'] as $rr) {

						$profile_link = chanlink_url($rr['url']);
		
						$pdesc = (($rr['description']) ? $rr['description'] . '<br />' : '');
						$connect_link = ((local_user()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : ''); 		

						if(in_array($rr['hash'],$contacts))
							$connect_link = '';

						$details = '';
						if(strlen($rr['locale']))
							$details .= $rr['locale'];
						if(strlen($rr['region'])) {
							if(strlen($rr['locale']))
								$details .= ', ';
							$details .= $rr['region'];
						}
						if(strlen($rr['country'])) {
							if(strlen($details))
								$details .= ', ';
							$details .= $rr['country'];
						}
						if(strlen($rr['birthday'])) {
							if(($years = age($rr['birthday'],'UTC','')) != 0)
								$details .= '<br />' . t('Age: ') . $years ; 
						}
						if(strlen($rr['gender']))
							$details .= '<br />' . t('Gender: ') . $rr['gender'];

						$page_type = '';

						$profile = $rr;

						if ((x($profile,'locale') == 1)
							|| (x($profile,'region') == 1)
							|| (x($profile,'postcode') == 1)
							|| (x($profile,'country') == 1))
						$location = t('Location:');

						$gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
	
						$marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
		
						$homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);

						$about = ((x($profile,'about') == 1) ?  t('About:') : False);

			

						$entry = replace_macros(get_markup_template('direntry_large.tpl'), array(
							'$id' => ++$t,
							'$profile_link' => $profile_link,
							'$photo' => $rr['photo_l'],
							'$alttext' => $rr['name'] . ' ' . $rr['address'],
							'$name' => $rr['name'],
							'$details' => $pdesc . $details,
							'$profile' => $profile,
							'$location' => $location,
							'$gender'   => $gender,
							'$pdesc'	=> $pdesc,
							'$marital'  => $marital,
							'$homepage' => $homepage,
							'$about' => $about,
							'$conn_label' => t('Connect'),
							'$connect' => $connect_link,
						));


						echo $entry;
						killme();

					}
				}
				else {
					info( t("Not found.") . EOL);
				}
			}
		}
	}




}