2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
4 require_once('include/Contact.php');
5 require_once('include/contact_selectors.php');
6 require_once('mod/contacts.php');
8 function dirfind_init(&$a) {
11 notice( t('Permission denied.') . EOL );
15 if(! x($a->page,'aside'))
16 $a->page['aside'] = '';
18 $a->page['aside'] .= findpeople_widget();
20 $a->page['aside'] .= follow_widget();
25 function dirfind_content(&$a, $prefix = "") {
29 $local = get_config('system','poco_local_search');
31 $search = $prefix.notags(trim($_REQUEST['search']));
33 if(strpos($search,'@') === 0)
34 $search = substr($search,1);
36 if(strpos($search,'!') === 0) {
37 $search = substr($search,1);
48 $extra_sql = " AND `community`";
53 $startrec = (($a->pager['page']) * $perpage) - $perpage;
55 if (get_config('system','diaspora_enabled'))
56 $diaspora = NETWORK_DIASPORA;
58 $diaspora = NETWORK_DFRN;
60 if (!get_config('system','ostatus_disabled'))
61 $ostatus = NETWORK_OSTATUS;
63 $ostatus = NETWORK_DFRN;
65 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
66 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
67 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
68 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
69 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
70 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
72 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
74 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
75 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
76 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
77 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
78 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
79 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
80 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
81 GROUP BY `gcontact`.`nurl`
82 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
83 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
84 dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
85 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
86 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
87 intval($startrec), intval($perpage));
89 $j->total = $count[0]["total"];
90 $j->items_page = $perpage;
91 $j->page = $a->pager['page'];
92 foreach ($results AS $result) {
93 if (poco_alternate_ostatus_url($result["url"]))
96 if ($result["name"] == "") {
97 $urlparts = parse_url($result["url"]);
98 $result["name"] = end(explode("/", $urlparts["path"]));
101 $objresult = new stdClass();
102 $objresult->cid = $result["cid"];
103 $objresult->name = $result["name"];
104 $objresult->addr = $result["addr"];
105 $objresult->url = $result["url"];
106 $objresult->photo = $result["photo"];
107 $objresult->tags = $result["keywords"];
108 $objresult->network = $result["network"];
110 $j->results[] = $objresult;
113 // Add found profiles from the global directory to the local directory
114 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
117 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
119 if(strlen(get_config('system','directory')))
120 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
122 $j = json_decode($x);
126 $a->set_pager_total($j->total);
127 $a->set_pager_itemspage($j->items_page);
130 if(count($j->results)) {
134 foreach($j->results as $jj) {
138 $contact_details = get_contact_details_by_url($jj->url, local_user());
140 $itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
142 // If We already know this contact then don't show the "connect" button
146 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
149 $photo_menu = contact_photo_menu($contact[0]);
150 $details = _contact_detail_for_template($contact[0]);
151 $alt_text = $details['alt_text'];
153 $photo_menu = array();
155 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
156 $conntxt = t('Connect');
157 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
158 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
161 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
164 'alt_text' => $alt_text,
165 'url' => zrl($jj->url),
166 'itemurl' => $itemurl,
167 'name' => htmlentities($jj->name),
168 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
169 'img_hover' => $jj->tags,
170 'conntxt' => $conntxt,
171 'connlnk' => $connlnk,
172 'photo_menu' => $photo_menu,
173 'details' => $contact_details['location'],
174 'tags' => $contact_details['keywords'],
175 'about' => $contact_details['about'],
176 'network' => network_to_name($jj->network, $jj->url),
182 $tpl = get_markup_template('viewcontact_template.tpl');
184 $o .= replace_macros($tpl,array(
185 'title' => sprintf( t('People Search - %s'), $search),
186 '$contacts' => $entries,
187 '$paginate' => paginate($a),
192 info( t('No matches') . EOL);