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);
41 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
42 '$title' => sprintf( t('People Search - %s'), $search)
50 $extra_sql = " AND `community`";
55 $startrec = (($a->pager['page']) * $perpage) - $perpage;
57 $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
58 (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
59 `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
60 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
61 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
62 dbesc(escape_tags($search)), dbesc(escape_tags($search)));
64 $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
66 LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
67 AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
68 AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
69 WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
70 ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
71 (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
72 `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
73 GROUP BY `gcontact`.`nurl`
74 ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
75 intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
76 dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
77 dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
78 dbesc(escape_tags($search)), dbesc(escape_tags($search)),
79 intval($startrec), intval($perpage));
81 $j->total = $count[0]["total"];
82 $j->items_page = $perpage;
83 $j->page = $a->pager['page'];
84 foreach ($results AS $result) {
85 if (poco_alternate_ostatus_url($result["url"]))
88 if ($result["name"] == "") {
89 $urlparts = parse_url($result["url"]);
90 $result["name"] = end(explode("/", $urlparts["path"]));
93 $objresult = new stdClass();
94 $objresult->cid = $result["cid"];
95 $objresult->name = $result["name"];
96 $objresult->url = $result["url"];
97 $objresult->photo = $result["photo"];
98 $objresult->tags = $result["keywords"];
100 $j->results[] = $objresult;
103 // Add found profiles from the global directory to the local directory
104 proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
107 $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
109 if(strlen(get_config('system','directory')))
110 $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
112 $j = json_decode($x);
116 $a->set_pager_total($j->total);
117 $a->set_pager_itemspage($j->items_page);
120 if(count($j->results)) {
124 $tpl = get_markup_template('match.tpl');
125 foreach($j->results as $jj) {
127 // If We already know this contact then don't show the "connect" button
131 $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
134 $photo_menu = contact_photo_menu($contact[0]);
136 $photo_menu = array();
138 $connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
139 $conntxt = t('Connect');
140 $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
141 $photo_menu[] = array(t("Connect/Follow"), $connlnk);
144 $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
146 $o .= replace_macros($tpl,array(
147 '$url' => zrl($jj->url),
148 '$name' => htmlentities($jj->name),
149 '$photo' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
150 '$tags' => $jj->tags,
151 '$conntxt' => $conntxt,
152 '$connlnk' => $connlnk,
153 '$photo_menu' => $photo_menu,
159 info( t('No matches') . EOL);
164 $o .= '<div class="clear"></div>';