1
0
Fork 0

Merge pull request #6315 from MrPetovan/bug/6309-add-fulltext-index-profile

Rework mod/match and mod/msearch
This commit is contained in:
Michael Vogel 2018-12-27 18:04:06 +01:00 committed by GitHub
commit 94eca77041
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
131 changed files with 508 additions and 762 deletions

View file

@ -14,8 +14,6 @@ use Friendica\Model\Item;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/dba.php';
function acl_content(App $a)
{
if (!local_user()) {

View file

@ -33,10 +33,6 @@ use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
require_once 'include/enotify.php';
require_once 'include/text.php';
require_once 'include/items.php';
/**
* @brief Process send data from the admin panels subpages
*

View file

@ -15,8 +15,6 @@ use Friendica\Module;
use Friendica\Util\Proxy as ProxyUtils;
require_once 'include/dba.php';
function allfriends_content(App $a)
{
$o = '';

View file

@ -8,8 +8,6 @@ use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Util\Security;
require_once 'include/dba.php';
function attach_init(App $a)
{
if ($a->argc != 2) {

View file

@ -11,9 +11,6 @@ use Friendica\Core\System;
use Friendica\Module\Login;
use Friendica\Util\Strings;
require_once 'include/conversation.php';
require_once 'include/items.php';
function bookmarklet_init()
{
$_GET["mode"] = "minimal";

View file

@ -14,8 +14,6 @@ use Friendica\Module;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/dba.php';
function common_content(App $a)
{
$o = '';

View file

@ -93,8 +93,6 @@ function community_content(App $a, $update = 0)
}
}
require_once 'include/conversation.php';
if (!$update) {
$tabs = [];

View file

@ -36,9 +36,6 @@ use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/enotify.php';
require_once 'include/items.php';
function dfrn_confirm_post(App $a, $handsfree = null)
{
$node = null;

View file

@ -16,8 +16,6 @@ use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora;
use Friendica\Util\Strings;
require_once 'include/items.php';
function dfrn_notify_post(App $a) {
Logger::log(__function__, Logger::TRACE);

View file

@ -17,8 +17,6 @@ use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
function dfrn_poll_init(App $a)
{
Login::sessionAuth();

View file

@ -30,8 +30,6 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings;
require_once 'include/enotify.php';
function dfrn_request_init(App $a)
{
if ($a->argc > 1) {

View file

@ -214,8 +214,6 @@ function display_content(App $a, $update = false, $update_uid = 0)
return;
}
require_once 'include/conversation.php';
$o = '';
if ($update) {

View file

@ -22,8 +22,6 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
require_once 'include/items.php';
function events_init(App $a)
{
if (!local_user()) {

View file

@ -12,10 +12,6 @@ use Friendica\Model\Contact;
use Friendica\Protocol\Feed;
use Friendica\Util\Network;
require_once 'boot.php';
require_once 'include/dba.php';
require_once 'include/text.php';
function feedtest_content(App $a)
{
if (!local_user()) {

View file

@ -10,8 +10,6 @@ use Friendica\Core\Renderer;
use Friendica\Model\FileTag;
use Friendica\Util\XML;
require_once 'include/items.php';
function filer_content(App $a)
{
if (! local_user()) {

View file

@ -38,10 +38,6 @@ use Friendica\Util\Emailer;
use Friendica\Util\Security;
use Friendica\Util\Strings;
require_once 'include/enotify.php';
require_once 'include/text.php';
require_once 'include/items.php';
function item_post(App $a) {
if (!local_user() && !remote_user()) {
return 0;
@ -668,7 +664,6 @@ function item_post(App $a) {
// preview mode - prepare the body for display and send it via json
if ($preview) {
require_once 'include/conversation.php';
// We set the datarray ID to -1 because in preview mode the dataray
// doesn't have an ID.
$datarray["id"] = -1;

View file

@ -5,8 +5,6 @@ use Friendica\Core\System;
use Friendica\Model\Item;
use Friendica\Util\Strings;
require_once 'include/items.php';
function like_content(App $a) {
if (!local_user() && !remote_user()) {
return false;

View file

@ -13,10 +13,6 @@ use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
require_once 'boot.php';
require_once 'include/enotify.php';
require_once 'include/text.php';
function lostpass_post(App $a)
{
$loginame = Strings::escapeTags(trim($_POST['login-name']));

View file

@ -10,8 +10,6 @@ use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
require_once "include/text.php";
function manage_post(App $a) {
if (! local_user()) {

View file

@ -12,11 +12,9 @@ use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/text.php';
/**
* @brief Controller for /match.
@ -26,13 +24,12 @@ require_once 'include/text.php';
*
* @param App $a App
*
* @return void|string
* @return string
*/
function match_content(App $a)
{
$o = '';
if (! local_user()) {
return;
if (!local_user()) {
return '';
}
$a->page['aside'] .= Widget::findPeople();
@ -40,91 +37,102 @@ function match_content(App $a)
$_SESSION['return_path'] = $a->cmd;
$r = q(
"SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
intval(local_user())
);
if (! DBA::isResult($r)) {
return;
$profile = Profile::getByUID(local_user());
if (!DBA::isResult($profile)) {
return '';
}
if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
return;
return '';
}
$params = [];
$tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
$tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
if ($tags) {
$pager = new Pager($a->query_string);
$params['s'] = $tags;
$params['n'] = 100;
$params['s'] = $tags;
if ($pager->getPage() != 1) {
$params['p'] = $pager->getPage();
}
if (strlen(Config::get('system', 'directory'))) {
$host = get_server();
} else {
$host = System::baseUrl();
}
if (strlen(Config::get('system', 'directory'))) {
$x = Network::post(get_server().'/msearch', $params)->getBody();
} else {
$x = Network::post(System::baseUrl() . '/msearch', $params)->getBody();
}
$msearch_json = Network::post($host . '/msearch', $params)->getBody();
$j = json_decode($x);
$msearch = json_decode($msearch_json);
if (count($j->results)) {
$pager->setItemsPerPage($j->items_page);
$start = defaults($_GET, 'start', 0);
$entries = [];
$paginate = '';
$id = 0;
if (!empty($msearch->results)) {
for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
$profile = $msearch->results[$i];
foreach ($j->results as $jj) {
$match_nurl = Strings::normaliseLink($jj->url);
$match = q(
"SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
intval(local_user()),
DBA::escape($match_nurl)
);
if (!count($match)) {
$jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
$connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
$photo_menu = [
'profile' => [L10n::t("View Profile"), Contact::magicLink($jj->url)],
'follow' => [L10n::t("Connect/Follow"), $connlnk]
];
$contact_details = Contact::getDetailsByURL($jj->url, local_user());
$entry = [
'url' => Contact::magicLink($jj->url),
'itemurl' => defaults($contact_details, 'addr', $jj->url),
'name' => $jj->name,
'details' => defaults($contact_details, 'location', ''),
'tags' => defaults($contact_details, 'keywords', ''),
'about' => defaults($contact_details, 'about', ''),
'account_type' => Contact::getAccountType($contact_details),
'thumb' => ProxyUtils::proxifyUrl($jj->photo, false, ProxyUtils::SIZE_THUMB),
'inttxt' => ' ' . L10n::t('is interested in:'),
'conntxt' => L10n::t('Connect'),
'connlnk' => $connlnk,
'img_hover' => $jj->tags,
'photo_menu' => $photo_menu,
'id' => ++$id,
];
$entries[] = $entry;
}
// Already known contact
if (Contact::getIdForURL($profile->url, local_user(), true)) {
continue;
}
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
// Workaround for wrong directory photo URL
$profile->photo = str_replace('http:///photo/', get_server() . '/photo/', $profile->photo);
$o .= Renderer::replaceMacros($tpl, [
'$title' => L10n::t('Profile Match'),
'$contacts' => $entries,
'$paginate' => $pager->renderFull($j->total)
]);
} else {
info(L10n::t('No matches') . EOL);
$connlnk = System::baseUrl() . '/follow/?url=' . $profile->url;
$photo_menu = [
'profile' => [L10n::t("View Profile"), Contact::magicLink($profile->url)],
'follow' => [L10n::t("Connect/Follow"), $connlnk]
];
$contact_details = Contact::getDetailsByURL($profile->url, 0);
$entry = [
'url' => Contact::magicLink($profile->url),
'itemurl' => defaults($contact_details, 'addr', $profile->url),
'name' => $profile->name,
'details' => defaults($contact_details, 'location', ''),
'tags' => defaults($contact_details, 'keywords', ''),
'about' => defaults($contact_details, 'about', ''),
'account_type' => Contact::getAccountType($contact_details),
'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
'conntxt' => L10n::t('Connect'),
'connlnk' => $connlnk,
'img_hover' => $profile->tags,
'photo_menu' => $photo_menu,
'id' => $i,
];
$entries[] = $entry;
}
$data = [
'class' => 'pager',
'first' => [
'url' => 'match',
'text' => L10n::t('first'),
'class' => 'previous' . ($start == 0 ? 'disabled' : '')
],
'next' => [
'url' => 'match?start=' . $i,
'text' => L10n::t('next'),
'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
]
];
$tpl = Renderer::getMarkupTemplate('paginate.tpl');
$paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
}
if (empty($entries)) {
info(L10n::t('No matches') . EOL);
}
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
$o = Renderer::replaceMacros($tpl, [
'$title' => L10n::t('Profile Match'),
'$contacts' => $entries,
'$paginate' => $paginate
]);
return $o;
}

View file

@ -21,8 +21,6 @@ use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
require_once 'include/conversation.php';
function message_init(App $a)
{
$tabs = '';

View file

@ -4,45 +4,64 @@ use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBA;
function msearch_post(App $a) {
$perpage = (($_POST['n']) ? $_POST['n'] : 80);
$page = (($_POST['p']) ? intval($_POST['p'] - 1) : 0);
$startrec = (($page+1) * $perpage) - $perpage;
$search = $_POST['s'];
if(! strlen($search))
killme();
$r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ",
DBA::escape($search)
);
if (DBA::isResult($r))
$total = $r[0]['total'];
function msearch_post(App $a)
{
$search = defaults($_POST, 's', '');
$perpage = intval(defaults($_POST, 'n', 80));
$page = intval(defaults($_POST, 'p', 1));
$startrec = ($page - 1) * $perpage;
$total = 0;
$results = [];
$r = q("SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` FROM `user` LEFT JOIN `profile` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') LIMIT %d , %d ",
DBA::escape($search),
intval($startrec),
intval($perpage)
);
if (DBA::isResult($r)) {
foreach($r as $rr)
$results[] = [
'name' => $rr['name'],
'url' => System::baseUrl() . '/profile/' . $rr['nickname'],
'photo' => System::baseUrl() . '/photo/avatar/' . $rr['uid'] . '.jpg',
'tags' => str_replace([',',' '],[' ',' '],$rr['pub_keywords'])
];
if (!strlen($search)) {
$output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
echo json_encode($output);
exit();
}
$output = ['total' => $total, 'items_page' => $perpage, 'page' => $page + 1, 'results' => $results];
$count_stmt = DBA::p(
"SELECT COUNT(*) AS `total`
FROM `profile`
JOIN `user` ON `user`.`uid` = `profile`.`uid`
WHERE `is-default` = 1
AND `user`.`hidewall` = 0
AND MATCH(`pub_keywords`) AGAINST (?)",
$search
);
if (DBA::isResult($count_stmt)) {
$row = DBA::fetch($count_stmt);
$total = $row['total'];
}
DBA::close($count_stmt);
$search_stmt = DBA::p(
"SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid`
FROM `user`
JOIN `profile` ON `user`.`uid` = `profile`.`uid`
WHERE `is-default` = 1
AND `user`.`hidewall` = 0
AND MATCH(`pub_keywords`) AGAINST (?)
LIMIT ?, ?",
$search,
$startrec,
$perpage
);
while($search_result = DBA::fetch($search_stmt)) {
$results[] = [
'name' => $search_result['name'],
'url' => System::baseUrl() . '/profile/' . $search_result['nickname'],
'photo' => System::baseUrl() . '/photo/avatar/' . $search_result['uid'] . '.jpg',
'tags' => str_replace([',', ' '], [' ', ' '], $search_result['pub_keywords'])
];
}
$output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
echo json_encode($output);
killme();
exit();
}

View file

@ -30,9 +30,6 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/conversation.php';
require_once 'include/items.php';
function network_init(App $a)
{
if (!local_user()) {

View file

@ -12,8 +12,6 @@ use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Util\Network;
require_once 'include/dba.php';
function nodeinfo_wellknown(App $a) {
$nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
'href' => System::baseUrl().'/nodeinfo/1.0']]];

View file

@ -34,8 +34,6 @@ function notes_content(App $a, $update = false)
return;
}
require_once 'include/conversation.php';
$o = Profile::getTabs($a, true);
if (!$update) {

View file

@ -15,8 +15,6 @@ use Friendica\Core\Logger;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
require_once 'include/items.php';
function parse_url_content(App $a)
{
$text = null;

View file

@ -34,8 +34,6 @@ use Friendica\Util\Temporal;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
function photos_init(App $a) {
if ($a->argc > 1) {
@ -946,8 +944,6 @@ function photos_content(App $a)
return;
}
require_once 'include/conversation.php';
if (empty($a->data['user'])) {
notice(L10n::t('No photos selected') . EOL);
return;

View file

@ -3,8 +3,6 @@
* @file mod/phpinfo.php
*/
require_once 'boot.php';
function phpinfo_content()
{
if (!is_site_admin()) {

View file

@ -22,8 +22,6 @@ use Friendica\Util\Temporal;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\XML;
require_once 'include/enotify.php';
/**
* @brief Outputs the counts and the lists of various notifications
*

View file

@ -25,8 +25,6 @@ use Friendica\Model\Item;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
function poke_init(App $a)
{
if (!local_user()) {

View file

@ -127,9 +127,6 @@ function profile_content(App $a, $update = 0)
return Login::form();
}
require_once 'include/conversation.php';
require_once 'include/items.php';
$groups = [];
$remote_cid = null;

View file

@ -9,8 +9,6 @@ use Friendica\Protocol\OStatus;
use Friendica\Util\Strings;
use Friendica\Core\System;
require_once 'include/items.php';
function hub_return($valid, $body)
{
if ($valid) {

View file

@ -18,8 +18,6 @@ use Friendica\Model;
use Friendica\Module\Tos;
use Friendica\Util\Strings;
require_once 'include/enotify.php';
function register_post(App $a)
{
BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');

View file

@ -13,8 +13,6 @@ use Friendica\Model\Register;
use Friendica\Model\User;
use Friendica\Module\Login;
require_once 'include/enotify.php';
function user_allow($hash)
{
$a = get_app();

View file

@ -12,8 +12,6 @@ use Friendica\Database\DBA;
use Friendica\Model\User;
use Friendica\Util\Strings;
require_once 'include/enotify.php';
function removeme_post(App $a)
{
if (!local_user()) {

View file

@ -14,8 +14,6 @@ use Friendica\Protocol\Salmon;
use Friendica\Util\Crypto;
use Friendica\Util\Strings;
require_once 'include/items.php';
function salmon_post(App $a, $xml = '') {
if (empty($xml)) {

View file

@ -18,7 +18,6 @@ use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Util\Strings;
require_once 'include/conversation.php';
require_once 'mod/dirfind.php';
function search_saved_searches() {

View file

@ -13,8 +13,6 @@ use Friendica\Util\Security;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
function subthread_content(App $a) {
if (!local_user() && !remote_user()) {

View file

@ -13,8 +13,6 @@ use Friendica\Model\Item;
use Friendica\Util\Strings;
use Friendica\Util\XML;
require_once 'include/items.php';
function tagger_content(App $a) {
if (!local_user() && !remote_user()) {

View file

@ -18,8 +18,6 @@ use Friendica\Model\Profile;
use Friendica\Protocol\DFRN;
use Friendica\Util\Security;
require_once 'include/items.php';
function videos_init(App $a)
{
if ($a->argc > 1) {
@ -195,8 +193,6 @@ function videos_content(App $a)
return;
}
require_once 'include/conversation.php';
if (empty($a->data['user'])) {
notice(L10n::t('No videos selected') . EOL );
return;