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 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
56 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
57 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
58 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
59 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
60 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
62 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network` , `gcontact`.`keywords`
64 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
65 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
66 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
67 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
68 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
69 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
70 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
71 GROUP BY `gcontact`.`nurl`
72 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
73 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
74 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
75 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
76 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
77 intval($startrec), intval($perpage));
79 $j->total = $count[0]["total"];
80 $j->items_page = $perpage;
81 $j->page = $a->pager['page'];
82 foreach ($results AS $result) {
83 if (poco_alternate_ostatus_url($result["url"]))
86 if ($result["name"] == "") {
87 $urlparts = parse_url($result["url"]);
88 $result["name"] = end(explode("/", $urlparts["path"]));
91 $objresult = new stdClass();
92 $objresult->cid = $result["cid"];
93 $objresult->name = $result["name"];
94 $objresult->url = $result["url"];
95 $objresult->photo = $result["photo"];
96 $objresult->tags = $result["keywords"];
97 $objresult->network = $result["network"];
99 $j->results[] = $objresult;
102 // Add found profiles from the global directory to the local directory
103 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
106 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
108 if(strlen(get_config('system','directory')))
109 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
111 $j = json_decode($x);
115 $a->set_pager_total($j->total);
116 $a->set_pager_itemspage($j->items_page);
119 if(count($j->results)) {
123 foreach($j->results as $jj) {
129 // If We already know this contact then don't show the "connect" button
133 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
136 $photo_menu = contact_photo_menu($contact[0]);
137 $details = _contact_detail_for_template($contact[0]);
138 $alt_text = $details['alt_text'];
140 $photo_menu = array();
142 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
143 $conntxt = t('Connect');
144 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
145 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
148 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
151 'alt_text' => $alt_text,
152 'url' => zrl($jj->url),
153 'itemurl' => $itemurl,
154 'name' => htmlentities($jj->name),
155 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
156 'img_hover' => $jj->tags,
157 'conntxt' => $conntxt,
158 'connlnk' => $connlnk,
159 'photo_menu' => $photo_menu,
160 'network' => network_to_name($jj->network, $jj->url),
166 $tpl = get_markup_template('viewcontact_template.tpl');
168 $o .= replace_macros($tpl,array(
169 'title' => sprintf( t('People Search - %s'), $search),
170 '$contacts' => $entries,
171 '$paginate' => paginate($a),
176 info( t('No matches') . EOL);