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');
7 function dirfind_init(&$a) {
10 notice( t('Permission denied.') . EOL );
14 if(! x($a->page,'aside'))
15 $a->page['aside'] = '';
17 $a->page['aside'] .= findpeople_widget();
19 $a->page['aside'] .= follow_widget();
24 function dirfind_content(&$a, $prefix = "") {
28 $local = get_config('system','poco_local_search');
30 $search = $prefix.notags(trim($_REQUEST['search']));
32 if(strpos($search,'@') === 0)
33 $search = substr($search,1);
35 if(strpos($search,'!') === 0) {
36 $search = substr($search,1);
47 $extra_sql = " AND `community`";
52 $startrec = (($a->pager['page']) * $perpage) - $perpage;
54 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
55 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
56 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
57 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
58 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
59 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
61 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network` , `gcontact`.`keywords`
63 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
64 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
65 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
66 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
67 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
68 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
69 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
70 GROUP BY `gcontact`.`nurl`
71 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
72 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
73 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
74 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
75 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
76 intval($startrec), intval($perpage));
78 $j->total = $count[0]["total"];
79 $j->items_page = $perpage;
80 $j->page = $a->pager['page'];
81 foreach ($results AS $result) {
82 if (poco_alternate_ostatus_url($result["url"]))
85 if ($result["name"] == "") {
86 $urlparts = parse_url($result["url"]);
87 $result["name"] = end(explode("/", $urlparts["path"]));
90 $objresult = new stdClass();
91 $objresult->cid = $result["cid"];
92 $objresult->name = $result["name"];
93 $objresult->url = $result["url"];
94 $objresult->photo = $result["photo"];
95 $objresult->tags = $result["keywords"];
96 $objresult->network = $result["network"];
98 $j->results[] = $objresult;
101 // Add found profiles from the global directory to the local directory
102 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
105 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
107 if(strlen(get_config('system','directory')))
108 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
110 $j = json_decode($x);
114 $a->set_pager_total($j->total);
115 $a->set_pager_itemspage($j->items_page);
118 if(count($j->results)) {
122 foreach($j->results as $jj) {
124 // If We already know this contact then don't show the "connect" button
128 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
131 $photo_menu = contact_photo_menu($contact[0]);
133 $photo_menu = array();
135 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
136 $conntxt = t('Connect');
137 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
138 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
141 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
144 'url' => zrl($jj->url),
145 'itemurl' => $jj->url,
146 'name' => htmlentities($jj->name),
147 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
148 'img_hover' => $jj->tags,
149 'conntxt' => $conntxt,
150 'connlnk' => $connlnk,
151 'photo_menu' => $photo_menu,
152 'network' => network_to_name($jj->network, $jj->url),
158 $tpl = get_markup_template('viewcontact_template.tpl');
160 $o .= replace_macros($tpl,array(
161 'title' => sprintf( t('People Search - %s'), $search),
162 '$contacts' => $entries,
163 '$paginate' => paginate($a),
168 info( t('No matches') . EOL);