2011-03-22 02:33:06 +00:00
|
|
|
<?php
|
2017-11-15 15:53:16 +00:00
|
|
|
/**
|
|
|
|
* @file mod/match.php
|
|
|
|
*/
|
2017-04-30 04:07:00 +00:00
|
|
|
use Friendica\App;
|
2018-01-15 14:50:06 +00:00
|
|
|
use Friendica\Content\Widget;
|
2017-11-07 02:22:52 +00:00
|
|
|
use Friendica\Core\Config;
|
2017-08-26 06:04:21 +00:00
|
|
|
use Friendica\Core\System;
|
2017-11-08 03:57:46 +00:00
|
|
|
use Friendica\Database\DBM;
|
2017-12-07 14:04:24 +00:00
|
|
|
use Friendica\Model\Contact;
|
2018-01-15 02:22:39 +00:00
|
|
|
use Friendica\Model\Profile;
|
2017-04-30 04:07:00 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
require_once 'include/text.php';
|
|
|
|
require_once 'mod/proxy.php';
|
2011-03-22 02:33:06 +00:00
|
|
|
|
2015-10-16 22:39:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Controller for /match.
|
|
|
|
*
|
|
|
|
* It takes keywords from your profile and queries the directory server for
|
|
|
|
* matching keywords from other profiles.
|
|
|
|
*
|
2017-11-15 15:53:16 +00:00
|
|
|
* @param App $a App
|
|
|
|
*
|
2015-10-16 22:39:50 +00:00
|
|
|
* @return void|string
|
|
|
|
*/
|
2017-11-15 15:53:16 +00:00
|
|
|
function match_content(App $a)
|
|
|
|
{
|
2011-03-22 04:26:11 +00:00
|
|
|
$o = '';
|
2016-12-20 10:56:34 +00:00
|
|
|
if (! local_user()) {
|
2011-03-22 02:33:06 +00:00
|
|
|
return;
|
2016-12-20 10:56:34 +00:00
|
|
|
}
|
2011-03-22 02:33:06 +00:00
|
|
|
|
2018-01-15 14:50:06 +00:00
|
|
|
$a->page['aside'] .= Widget::findPeople();
|
|
|
|
$a->page['aside'] .= Widget::follow();
|
2015-09-15 20:29:02 +00:00
|
|
|
|
2017-08-26 07:32:10 +00:00
|
|
|
$_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
|
2011-12-18 09:44:46 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
$r = q(
|
|
|
|
"SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
|
2011-03-22 02:33:06 +00:00
|
|
|
intval(local_user())
|
|
|
|
);
|
2017-11-08 03:57:46 +00:00
|
|
|
if (! DBM::is_result($r)) {
|
2015-09-15 20:29:02 +00:00
|
|
|
return;
|
2016-12-20 09:10:33 +00:00
|
|
|
}
|
2017-11-15 15:53:16 +00:00
|
|
|
if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
|
|
|
|
notice(t('No keywords to match. Please add keywords to your default profile.') . EOL);
|
2011-03-22 02:33:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
$params = [];
|
2011-03-22 02:33:06 +00:00
|
|
|
$tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
|
2015-08-23 09:05:10 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
if ($tags) {
|
2011-03-22 02:33:06 +00:00
|
|
|
$params['s'] = $tags;
|
2017-11-15 15:53:16 +00:00
|
|
|
if ($a->pager['page'] != 1) {
|
2011-03-22 04:26:11 +00:00
|
|
|
$params['p'] = $a->pager['page'];
|
2017-11-15 15:53:16 +00:00
|
|
|
}
|
2015-08-23 09:05:10 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
if (strlen(Config::get('system', 'directory'))) {
|
2015-08-23 09:05:10 +00:00
|
|
|
$x = post_url(get_server().'/msearch', $params);
|
2017-11-15 15:53:16 +00:00
|
|
|
} else {
|
2017-08-26 07:32:10 +00:00
|
|
|
$x = post_url(System::baseUrl() . '/msearch', $params);
|
2017-11-15 15:53:16 +00:00
|
|
|
}
|
2011-03-22 02:44:00 +00:00
|
|
|
|
2011-03-22 02:33:06 +00:00
|
|
|
$j = json_decode($x);
|
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
if ($j->total) {
|
2011-03-22 04:26:11 +00:00
|
|
|
$a->set_pager_total($j->total);
|
|
|
|
$a->set_pager_itemspage($j->items_page);
|
|
|
|
}
|
2011-03-22 02:44:00 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
if (count($j->results)) {
|
2015-10-18 15:12:48 +00:00
|
|
|
$id = 0;
|
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
foreach ($j->results as $jj) {
|
2015-09-15 20:29:02 +00:00
|
|
|
$match_nurl = normalise_link($jj->url);
|
2017-11-15 15:53:16 +00:00
|
|
|
$match = q(
|
|
|
|
"SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
|
2015-09-15 20:29:02 +00:00
|
|
|
intval(local_user()),
|
2017-11-15 15:53:16 +00:00
|
|
|
dbesc($match_nurl)
|
|
|
|
);
|
2015-10-18 15:12:48 +00:00
|
|
|
|
2015-09-15 20:29:02 +00:00
|
|
|
if (!count($match)) {
|
|
|
|
$jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
|
2017-08-26 07:32:10 +00:00
|
|
|
$connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
|
2018-01-15 13:05:12 +00:00
|
|
|
$photo_menu = [
|
|
|
|
'profile' => [t("View Profile"), Profile::zrl($jj->url)],
|
|
|
|
'follow' => [t("Connect/Follow"), $connlnk]
|
|
|
|
];
|
2015-10-18 15:12:48 +00:00
|
|
|
|
2017-11-19 22:03:39 +00:00
|
|
|
$contact_details = Contact::getDetailsByURL($jj->url, local_user());
|
2015-11-05 23:47:54 +00:00
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
$entry = [
|
2018-01-15 02:22:39 +00:00
|
|
|
'url' => Profile::zrl($jj->url),
|
2015-11-05 23:47:54 +00:00
|
|
|
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url),
|
2015-10-16 22:39:50 +00:00
|
|
|
'name' => $jj->name,
|
2015-11-05 23:47:54 +00:00
|
|
|
'details' => $contact_details['location'],
|
|
|
|
'tags' => $contact_details['keywords'],
|
|
|
|
'about' => $contact_details['about'],
|
2017-11-19 22:03:39 +00:00
|
|
|
'account_type' => Contact::getAccountType($contact_details),
|
2015-10-18 15:12:48 +00:00
|
|
|
'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
|
2015-10-16 22:39:50 +00:00
|
|
|
'inttxt' => ' ' . t('is interested in:'),
|
|
|
|
'conntxt' => t('Connect'),
|
|
|
|
'connlnk' => $connlnk,
|
2015-10-18 15:12:48 +00:00
|
|
|
'img_hover' => $jj->tags,
|
|
|
|
'photo_menu' => $photo_menu,
|
|
|
|
'id' => ++$id,
|
2018-01-15 13:05:12 +00:00
|
|
|
];
|
2015-10-26 15:15:08 +00:00
|
|
|
$entries[] = $entry;
|
2015-09-15 20:29:02 +00:00
|
|
|
}
|
2011-03-22 02:33:06 +00:00
|
|
|
}
|
2015-10-16 22:39:50 +00:00
|
|
|
|
2017-11-15 15:53:16 +00:00
|
|
|
$tpl = get_markup_template('viewcontact_template.tpl');
|
|
|
|
|
|
|
|
$o .= replace_macros(
|
|
|
|
$tpl,
|
2018-01-15 13:05:12 +00:00
|
|
|
[
|
2017-11-15 15:53:16 +00:00
|
|
|
'$title' => t('Profile Match'),
|
|
|
|
'$contacts' => $entries,
|
2018-01-15 13:05:12 +00:00
|
|
|
'$paginate' => paginate($a)]
|
2017-11-15 15:53:16 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
info(t('No matches') . EOL);
|
2015-09-15 20:29:02 +00:00
|
|
|
}
|
2011-03-22 02:33:06 +00:00
|
|
|
}
|
2011-03-22 04:26:11 +00:00
|
|
|
|
2011-03-22 02:33:06 +00:00
|
|
|
return $o;
|
2011-05-23 09:39:57 +00:00
|
|
|
}
|