aboutsummaryrefslogtreecommitdiffstats
path: root/mod/directory.php
blob: efdbe9fa28c28adb4e0d1785fd085b5ef852accf (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php

require_once('include/dir_fns.php');


function directory_init(&$a) {
	$a->set_pager_itemspage(60);

}

function directory_aside(&$a) {

	if(local_user()) {
		require_once('include/contact_widgets.php');
		$a->set_widget('find_people',findpeople_widget());
	}
}


function directory_content(&$a) {

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

	$o = '';
	nav_set_selected('directory');

	if(x($_POST,'search'))
		$search = notags(trim($_POST['search']));
	else
		$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');


	$tpl = get_markup_template('directory_header.tpl');


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

//	if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
//		$localdir = true;
//		return;
//	}

// FIXME
$localdir = true;


	if(! $localdir) {
		$directory = find_upstream_directory($dirmode);

		if($directory) {
			$url = $directory['url'];
		}
		else {
			$url = DIRECTORY_FALLBACK_MASTER . '/post';
		}
	}



	if($localdir) {
		if($search)
			$search = dbesc($search);
		$sql_extra = ((strlen($search)) ? " AND MATCH ( xchan_name, xchan_addr, xprof_desc, xprof_locale, xprof_region, xprof_country, xprof_gdner, xprof_marital, tags ) AGAINST ('$search' IN BOOLEAN MODE) " : "");


		$r = q("SELECT COUNT(xchan_hash) AS `total`, group_concat(xtag_term separator ', ') as tags FROM xchan left join xprof  on xchan_hash = xprof_hash left join xtag on xtag_hash = xchan_hash $sql_extra group by xchan_hash");
		if($r)
			$a->set_pager_total($r[0]['total']);

		$order = " ORDER BY `xchan_name` ASC "; 


		$r = q("SELECT xchan.*, xprof.*, group_concat(xtag_term separator ', ') as tags from xchan left join xprof on xchan_hash = xprof_hash left join xtag on xtag_hash = xchan_hash $sql_extra group by xchan_hash $order LIMIT %d , %d ",
			intval($a->pager['start']),
			intval($a->pager['itemspage'])
		);


		if($r) {

			$entries = array();

			$photo = 'thumb';

			foreach($r as $rr) {

				$profile_link = chanlink_hash($rr['xchan_hash']);
		
				$pdesc = (($rr['xprof_desc']) ? $rr['xprof_desc'] . '<br />' : '');

				$details = '';
				if(strlen($rr['xprof_locale']))
					$details .= $rr['xprof_locale'];
				if(strlen($rr['xprof_region'])) {
					if(strlen($rr['xprof_locale']))
						$details .= ', ';
					$details .= $rr['xprof_region'];
				}
				if(strlen($rr['xprof_country'])) {
					if(strlen($details))
						$details .= ', ';
					$details .= $rr['xprof_country'];
				}
				if(strlen($rr['xprof_dob'])) {
					if(($years = age($rr['xprof_dob'],'UTC','')) != 0)
						$details .= '<br />' . t('Age: ') . $years ; 
				}
				if(strlen($rr['xprof_gender']))
					$details .= '<br />' . t('Gender: ') . $rr['xprof_gender'];

				$page_type = '';

				$profile = $rr;

				if ((x($profile,'xprof_locale') == 1)
					|| (x($profile,'xprof_region') == 1)
					|| (x($profile,'xprof_postcode') == 1)
					|| (x($profile,'xprof_country') == 1))
				$location = t('Location:');

				$gender = ((x($profile,'xprof_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);
			
				$t = 0;

				$entry = array(
					'id' => ++$t,
					'profile_link' => $profile_link,
					'photo' => $rr[xchan_photo_m],
					'alttext' => $rr['xchan_name'],
					'name' => $rr['xchan_name'],
					'details' => $pdesc . $details,
					'profile' => $profile,
					'location' => $location,
					'gender'   => $gender,
					'pdesc'	=> $pdesc,
					'marital'  => $marital,
					'homepage' => $homepage,
					'about' => $about,

				);

				$arr = array('contact' => $rr, 'entry' => $entry);

				call_hooks('directory_item', $arr);
			
				unset($profile);
				unset($location);

				$entries[] = $entry;

			}

			logger('entries: ' . print_r($entries,true));

			$o .= replace_macros($tpl, array(
				'$search' => $search,
				'$desc' => t('Find'),
				'$finddsc' => t('Finding:'),
				'$safetxt' => htmlspecialchars($search,ENT_QUOTES,'UTF-8'),
				'$entries' => $entries,
				'$dirlbl' => t('Directory'),
				'$submit' => t('Find')
			));


			$o .= paginate($a);

		}

	else
		info( t("No entries (some entries may be hidden).") . EOL);

	}

	return $o;
}