2 require_once('include/contact_widgets.php');
3 require_once('include/socgraph.php');
4 require_once('include/Contact.php');
6 function dirfind_init(&$a) {
9 notice( t('Permission denied.') . EOL );
13 if(! x($a->page,'aside'))
14 $a->page['aside'] = '';
16 $a->page['aside'] .= follow_widget();
18 $a->page['aside'] .= findpeople_widget();
23 function dirfind_content(&$a, $prefix = "") {
27 $local = get_config('system','poco_local_search');
29 $search = $prefix.notags(trim($_REQUEST['search']));
31 if(strpos($search,'@') === 0)
32 $search = substr($search,1);
34 if(strpos($search,'!') === 0) {
35 $search = substr($search,1);
46 $extra_sql = " AND `community`";
51 $startrec = (($a->pager['page']) * $perpage) - $perpage;
53 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
54 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
55 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
56 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
57 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
58 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
60 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
62 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
63 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
64 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
65 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
66 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
67 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
68 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
69 GROUP BY `gcontact`.`nurl`
70 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
71 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
72 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
73 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
74 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
75 intval($startrec), intval($perpage));
77 $j->total = $count[0]["total"];
78 $j->items_page = $perpage;
79 $j->page = $a->pager['page'];
80 foreach ($results AS $result) {
81 if (poco_alternate_ostatus_url($result["url"]))
84 if ($result["name"] == "") {
85 $urlparts = parse_url($result["url"]);
86 $result["name"] = end(explode("/", $urlparts["path"]));
89 $objresult = new stdClass();
90 $objresult->cid = $result["cid"];
91 $objresult->name = $result["name"];
92 $objresult->url = $result["url"];
93 $objresult->photo = $result["photo"];
94 $objresult->tags = $result["keywords"];
96 $j->results[] = $objresult;
99 // Add found profiles from the global directory to the local directory
100 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
103 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
105 if(strlen(get_config('system','directory')))
106 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
108 $j = json_decode($x);
112 $a->set_pager_total($j->total);
113 $a->set_pager_itemspage($j->items_page);
116 if(count($j->results)) {
120 foreach($j->results as $jj) {
122 // If We already know this contact then don't show the "connect" button
126 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
129 $photo_menu = contact_photo_menu($contact[0]);
131 $photo_menu = array();
133 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
134 $conntxt = t('Connect');
135 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
136 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
139 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
142 'url' => zrl($jj->url),
143 'name' => htmlentities($jj->name),
144 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
145 'img_hover' => $jj->tags,
146 'conntxt' => $conntxt,
147 'connlnk' => $connlnk,
148 'photo_menu' => $photo_menu,
154 $tpl = get_markup_template('viewcontact_template.tpl');
156 $o .= replace_macros($tpl,array(
157 'title' => sprintf( t('People Search - %s'), $search),
158 '$contacts' => $entries,
159 '$paginate' => paginate($a),
164 info( t('No matches') . EOL);