mirror of
https://github.com/friendica/friendica
synced 2025-04-21 14:30:12 +00:00
Split Directory Search as a base for further changes
This commit is contained in:
parent
2520286b1f
commit
5b44fdc202
4 changed files with 106 additions and 69 deletions
104
src/Module/BaseSearchModule.php
Normal file
104
src/Module/BaseSearchModule.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Object\Search\ResultList;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Model;
|
||||
|
||||
/**
|
||||
* Base class for search modules
|
||||
*/
|
||||
abstract class BaseSearchModule extends BaseModule
|
||||
{
|
||||
/**
|
||||
* Prints a human readable search result
|
||||
*
|
||||
* @param ResultList $results
|
||||
* @param Pager $pager
|
||||
* @param string $header
|
||||
*
|
||||
* @return string The result
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
protected static function printResult(ResultList $results, Pager $pager, $header = '')
|
||||
{
|
||||
if (empty($results) || empty($results->getResults())) {
|
||||
info(L10n::t('No matches') . EOL);
|
||||
return '';
|
||||
}
|
||||
|
||||
$a = self::getApp();
|
||||
|
||||
$id = 0;
|
||||
$entries = [];
|
||||
foreach ($results->getResults() as $result) {
|
||||
|
||||
$alt_text = '';
|
||||
$location = '';
|
||||
$about = '';
|
||||
$accountType = '';
|
||||
$photo_menu = [];
|
||||
|
||||
// If We already know this contact then don't show the "connect" button
|
||||
if ($result->getCid() > 0 || $result->getPcid() > 0) {
|
||||
$connLink = "";
|
||||
$connTxt = "";
|
||||
$contact = Model\Contact::getById(
|
||||
($result->getCid() > 0) ? $result->getCid() : $result->getPcid()
|
||||
);
|
||||
|
||||
if (!empty($contact)) {
|
||||
$photo_menu = Model\Contact::photoMenu($contact);
|
||||
$details = Contact::getContactTemplateVars($contact);
|
||||
$alt_text = $details['alt_text'];
|
||||
$location = $contact['location'];
|
||||
$about = $contact['about'];
|
||||
$accountType = Model\Contact::getAccountType($contact);
|
||||
} else {
|
||||
$photo_menu = [];
|
||||
}
|
||||
} else {
|
||||
$connLink = $a->getBaseURL() . '/follow/?url=' . $result->getUrl();
|
||||
$connTxt = L10n::t('Connect');
|
||||
|
||||
$photo_menu['profile'] = [L10n::t("View Profile"), Model\Contact::magicLink($result->getUrl())];
|
||||
$photo_menu['follow'] = [L10n::t("Connect/Follow"), $connLink];
|
||||
}
|
||||
|
||||
$photo = str_replace("http:///photo/", get_server() . "/photo/", $result->getPhoto());
|
||||
|
||||
$entry = [
|
||||
'alt_text' => $alt_text,
|
||||
'url' => Model\Contact::magicLink($result->getUrl()),
|
||||
'itemurl' => $result->getItem(),
|
||||
'name' => $result->getName(),
|
||||
'thumb' => ProxyUtils::proxifyUrl($photo, false, ProxyUtils::SIZE_THUMB),
|
||||
'img_hover' => $result->getTags(),
|
||||
'conntxt' => $connTxt,
|
||||
'connlnk' => $connLink,
|
||||
'photo_menu' => $photo_menu,
|
||||
'details' => $location,
|
||||
'tags' => $result->getTags(),
|
||||
'about' => $about,
|
||||
'account_type' => $accountType,
|
||||
'network' => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
|
||||
'id' => ++$id,
|
||||
];
|
||||
$entries[] = $entry;
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'title' => $header,
|
||||
'$contacts' => $entries,
|
||||
'$paginate' => $pager->renderFull($results->getTotal()),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue