2011-03-22 03:33:06 +01:00
|
|
|
<?php
|
2017-11-15 16:53:16 +01:00
|
|
|
/**
|
|
|
|
* @file mod/match.php
|
|
|
|
*/
|
2018-07-21 15:10:13 +02:00
|
|
|
|
2017-04-30 06:07:00 +02:00
|
|
|
use Friendica\App;
|
2018-10-24 08:15:24 +02:00
|
|
|
use Friendica\Content\Pager;
|
2018-01-15 15:50:06 +01:00
|
|
|
use Friendica\Content\Widget;
|
2017-11-07 03:22:52 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-01-21 19:33:59 +01:00
|
|
|
use Friendica\Core\L10n;
|
2018-10-31 15:35:50 +01:00
|
|
|
use Friendica\Core\Renderer;
|
2017-08-26 08:04:21 +02:00
|
|
|
use Friendica\Core\System;
|
2018-07-21 14:40:21 +02:00
|
|
|
use Friendica\Database\DBA;
|
2017-12-07 15:04:24 +01:00
|
|
|
use Friendica\Model\Contact;
|
2018-01-27 05:24:23 +01:00
|
|
|
use Friendica\Util\Network;
|
2018-07-31 04:06:22 +02:00
|
|
|
use Friendica\Util\Proxy as ProxyUtils;
|
2017-04-30 06:07:00 +02:00
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
require_once 'include/text.php';
|
2011-03-22 03:33:06 +01:00
|
|
|
|
2015-10-17 00:39:50 +02: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 16:53:16 +01:00
|
|
|
* @param App $a App
|
|
|
|
*
|
2015-10-17 00:39:50 +02:00
|
|
|
* @return void|string
|
|
|
|
*/
|
2017-11-15 16:53:16 +01:00
|
|
|
function match_content(App $a)
|
|
|
|
{
|
2011-03-22 05:26:11 +01:00
|
|
|
$o = '';
|
2016-12-20 11:56:34 +01:00
|
|
|
if (! local_user()) {
|
2011-03-22 03:33:06 +01:00
|
|
|
return;
|
2016-12-20 11:56:34 +01:00
|
|
|
}
|
2011-03-22 03:33:06 +01:00
|
|
|
|
2018-01-15 15:50:06 +01:00
|
|
|
$a->page['aside'] .= Widget::findPeople();
|
|
|
|
$a->page['aside'] .= Widget::follow();
|
2015-09-15 22:29:02 +02:00
|
|
|
|
2018-10-19 23:55:11 +02:00
|
|
|
$_SESSION['return_path'] = $a->cmd;
|
2011-12-18 10:44:46 +01:00
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
$r = q(
|
|
|
|
"SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
|
2011-03-22 03:33:06 +01:00
|
|
|
intval(local_user())
|
|
|
|
);
|
2018-07-21 14:46:04 +02:00
|
|
|
if (! DBA::isResult($r)) {
|
2015-09-15 22:29:02 +02:00
|
|
|
return;
|
2016-12-20 10:10:33 +01:00
|
|
|
}
|
2017-11-15 16:53:16 +01:00
|
|
|
if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
|
2018-01-21 19:33:59 +01:00
|
|
|
notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
|
2011-03-22 03:33:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$params = [];
|
2011-03-22 03:33:06 +01:00
|
|
|
$tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
|
2015-08-23 11:05:10 +02:00
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
if ($tags) {
|
2018-10-24 18:03:14 +02:00
|
|
|
$pager = new Pager($a->query_string);
|
2018-10-24 17:42:59 +02:00
|
|
|
|
2011-03-22 03:33:06 +01:00
|
|
|
$params['s'] = $tags;
|
2018-10-24 08:15:24 +02:00
|
|
|
if ($pager->getPage() != 1) {
|
|
|
|
$params['p'] = $pager->getPage();
|
2017-11-15 16:53:16 +01:00
|
|
|
}
|
2015-08-23 11:05:10 +02:00
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
if (strlen(Config::get('system', 'directory'))) {
|
2018-10-10 21:15:26 +02:00
|
|
|
$x = Network::post(get_server().'/msearch', $params)->getBody();
|
2017-11-15 16:53:16 +01:00
|
|
|
} else {
|
2018-10-10 21:15:26 +02:00
|
|
|
$x = Network::post(System::baseUrl() . '/msearch', $params)->getBody();
|
2017-11-15 16:53:16 +01:00
|
|
|
}
|
2011-03-22 03:44:00 +01:00
|
|
|
|
2011-03-22 03:33:06 +01:00
|
|
|
$j = json_decode($x);
|
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
if (count($j->results)) {
|
2018-10-24 18:03:14 +02:00
|
|
|
$pager->setItemsPerPage($j->items_page);
|
|
|
|
|
2015-10-18 17:12:48 +02:00
|
|
|
$id = 0;
|
|
|
|
|
2017-11-15 16:53:16 +01:00
|
|
|
foreach ($j->results as $jj) {
|
2015-09-15 22:29:02 +02:00
|
|
|
$match_nurl = normalise_link($jj->url);
|
2017-11-15 16:53:16 +01:00
|
|
|
$match = q(
|
|
|
|
"SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
|
2015-09-15 22:29:02 +02:00
|
|
|
intval(local_user()),
|
2018-07-21 15:10:13 +02:00
|
|
|
DBA::escape($match_nurl)
|
2017-11-15 16:53:16 +01:00
|
|
|
);
|
2015-10-18 17:12:48 +02:00
|
|
|
|
2015-09-15 22:29:02 +02:00
|
|
|
if (!count($match)) {
|
|
|
|
$jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
|
2017-08-26 09:32:10 +02:00
|
|
|
$connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
|
2018-01-15 14:05:12 +01:00
|
|
|
$photo_menu = [
|
2018-06-02 10:05:06 +02:00
|
|
|
'profile' => [L10n::t("View Profile"), Contact::magicLink($jj->url)],
|
2018-01-22 15:16:25 +01:00
|
|
|
'follow' => [L10n::t("Connect/Follow"), $connlnk]
|
2018-01-15 14:05:12 +01:00
|
|
|
];
|
2015-10-18 17:12:48 +02:00
|
|
|
|
2017-11-19 23:03:39 +01:00
|
|
|
$contact_details = Contact::getDetailsByURL($jj->url, local_user());
|
2015-11-06 00:47:54 +01:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$entry = [
|
2018-06-02 10:05:06 +02:00
|
|
|
'url' => Contact::magicLink($jj->url),
|
2018-08-19 03:52:21 +02:00
|
|
|
'itemurl' => defaults($contact_details, 'addr', $jj->url),
|
2015-10-17 00:39:50 +02:00
|
|
|
'name' => $jj->name,
|
2018-08-19 03:52:21 +02:00
|
|
|
'details' => defaults($contact_details, 'location', ''),
|
|
|
|
'tags' => defaults($contact_details, 'keywords', ''),
|
|
|
|
'about' => defaults($contact_details, 'about', ''),
|
2017-11-19 23:03:39 +01:00
|
|
|
'account_type' => Contact::getAccountType($contact_details),
|
2018-07-31 04:06:22 +02:00
|
|
|
'thumb' => ProxyUtils::proxifyUrl($jj->photo, false, ProxyUtils::SIZE_THUMB),
|
2018-01-22 15:16:25 +01:00
|
|
|
'inttxt' => ' ' . L10n::t('is interested in:'),
|
|
|
|
'conntxt' => L10n::t('Connect'),
|
2015-10-17 00:39:50 +02:00
|
|
|
'connlnk' => $connlnk,
|
2015-10-18 17:12:48 +02:00
|
|
|
'img_hover' => $jj->tags,
|
|
|
|
'photo_menu' => $photo_menu,
|
|
|
|
'id' => ++$id,
|
2018-01-15 14:05:12 +01:00
|
|
|
];
|
2015-10-26 16:15:08 +01:00
|
|
|
$entries[] = $entry;
|
2015-09-15 22:29:02 +02:00
|
|
|
}
|
2011-03-22 03:33:06 +01:00
|
|
|
}
|
2015-10-17 00:39:50 +02:00
|
|
|
|
2018-10-31 15:44:06 +01:00
|
|
|
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
|
2017-11-15 16:53:16 +01:00
|
|
|
|
2018-10-31 15:35:50 +01:00
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
2018-10-24 17:42:59 +02:00
|
|
|
'$title' => L10n::t('Profile Match'),
|
2017-11-15 16:53:16 +01:00
|
|
|
'$contacts' => $entries,
|
2018-10-24 17:42:59 +02:00
|
|
|
'$paginate' => $pager->renderFull($j->total)
|
|
|
|
]);
|
2017-11-15 16:53:16 +01:00
|
|
|
} else {
|
2018-01-22 15:16:25 +01:00
|
|
|
info(L10n::t('No matches') . EOL);
|
2015-09-15 22:29:02 +02:00
|
|
|
}
|
2011-03-22 03:33:06 +01:00
|
|
|
}
|
2011-03-22 05:26:11 +01:00
|
|
|
|
2011-03-22 03:33:06 +01:00
|
|
|
return $o;
|
2011-05-23 11:39:57 +02:00
|
|
|
}
|