directory.php - code beautification (PSR)

This commit is contained in:
rabuzarus 2018-03-03 14:40:16 +01:00
parent 2efd4ba780
commit c78572bf47

View file

@ -12,12 +12,12 @@ use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
function directory_init(App $a) { function directory_init(App $a)
{
$a->set_pager_itemspage(60); $a->set_pager_itemspage(60);
if(local_user()) { if (local_user()) {
$a->page['aside'] .= Widget::findPeople(); $a->page['aside'] .= Widget::findPeople();
$a->page['aside'] .= Widget::follow(); $a->page['aside'] .= Widget::follow();
} else { } else {
unset($_SESSION['theme']); unset($_SESSION['theme']);
@ -25,16 +25,20 @@ function directory_init(App $a) {
} }
} }
function directory_post(App $a) { function directory_post(App $a)
if(x($_POST,'search')) {
if (x($_POST, 'search')) {
$a->data['search'] = $_POST['search']; $a->data['search'] = $_POST['search'];
}
} }
function directory_content(App $a) { function directory_content(App $a)
{
require_once("mod/proxy.php"); require_once("mod/proxy.php");
if((Config::get('system','block_public')) && (! local_user()) && (! remote_user()) || if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
(Config::get('system','block_local_dir')) && (! local_user()) && (! remote_user())) { || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
) {
notice(L10n::t('Public access denied.') . EOL); notice(L10n::t('Public access denied.') . EOL);
return; return;
} }
@ -42,18 +46,19 @@ function directory_content(App $a) {
$o = ''; $o = '';
Nav::setSelected('directory'); Nav::setSelected('directory');
if(x($a->data,'search')) if (x($a->data, 'search')) {
$search = notags(trim($a->data['search'])); $search = notags(trim($a->data['search']));
else } else {
$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
$gdirpath = '';
$dirurl = Config::get('system','directory');
if(strlen($dirurl)) {
$gdirpath = Profile::zrl($dirurl,true);
} }
if($search) { $gdirpath = '';
$dirurl = Config::get('system', 'directory');
if (strlen($dirurl)) {
$gdirpath = Profile::zrl($dirurl, true);
}
if ($search) {
$search = dbesc($search); $search = dbesc($search);
$sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
@ -73,35 +78,35 @@ function directory_content(App $a) {
(`profile`.`prv_keywords` LIKE '%$search%'))"; (`profile`.`prv_keywords` LIKE '%$search%'))";
} }
$publish = ((Config::get('system','publish_all')) ? '' : " AND `publish` = 1 " ); $publish = ((Config::get('system', 'publish_all')) ? '' : " AND `publish` = 1 " );
$r = q("SELECT COUNT(*) AS `total` FROM `profile` $total = q("SELECT COUNT(*) AS `total` FROM `profile`
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra "); WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra "
if (DBM::is_result($r)) );
$a->set_pager_total($r[0]['total']); if (DBM::is_result($total)) {
$a->set_pager_total($total[0]['total']);
}
$order = " ORDER BY `name` ASC "; $order = " ORDER BY `name` ASC ";
$limit = intval($a->pager['start']).",".intval($a->pager['itemspage']); $limit = intval($a->pager['start'])."," . intval($a->pager['itemspage']);
$r = dba::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, $r = dba::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
`contact`.`addr`, `contact`.`url` AS profile_url FROM `profile` `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit); WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit
);
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
if (in_array('small', $a->argv)) { if (in_array('small', $a->argv)) {
$photo = 'thumb'; $photo = 'thumb';
} } else {
else {
$photo = 'photo'; $photo = 'photo';
} }
while ($rr = dba::fetch($r)) { while ($rr = dba::fetch($r)) {
$itemurl= ''; $itemurl= '';
$itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']); $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
@ -111,16 +116,19 @@ function directory_content(App $a) {
$pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : ''); $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
$details = ''; $details = '';
if(strlen($rr['locality'])) if (strlen($rr['locality'])) {
$details .= $rr['locality']; $details .= $rr['locality'];
if(strlen($rr['region'])) { }
if(strlen($rr['locality'])) if (strlen($rr['region'])) {
if (strlen($rr['locality'])) {
$details .= ', '; $details .= ', ';
}
$details .= $rr['region']; $details .= $rr['region'];
} }
if(strlen($rr['country-name'])) { if (strlen($rr['country-name'])) {
if(strlen($details)) if (strlen($details)) {
$details .= ', '; $details .= ', ';
}
$details .= $rr['country-name']; $details .= $rr['country-name'];
} }
// if(strlen($rr['dob'])) { // if(strlen($rr['dob'])) {
@ -132,20 +140,19 @@ function directory_content(App $a) {
$profile = $rr; $profile = $rr;
if((x($profile,'address') == 1) if ((x($profile, 'address') == 1)
|| (x($profile,'locality') == 1) || (x($profile, 'locality') == 1)
|| (x($profile,'region') == 1) || (x($profile, 'region') == 1)
|| (x($profile,'postal-code') == 1) || (x($profile, 'postal-code') == 1)
|| (x($profile,'country-name') == 1)) || (x($profile, 'country-name') == 1)
$location = L10n::t('Location:'); ) {
$location = L10n::t('Location:');
}
$gender = ((x($profile,'gender') == 1) ? L10n::t('Gender:') : False); $gender = ((x($profile, 'gender') == 1) ? L10n::t('Gender:') : false);
$marital = ((x($profile, 'marital') == 1) ? L10n::t('Status:') : false);
$marital = ((x($profile,'marital') == 1) ? L10n::t('Status:') : False); $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
$about = ((x($profile, 'about') == 1) ? L10n::t('About:') : false);
$homepage = ((x($profile,'homepage') == 1) ? L10n::t('Homepage:') : False);
$about = ((x($profile,'about') == 1) ? L10n::t('About:') : False);
$location_e = $location; $location_e = $location;
@ -154,23 +161,23 @@ function directory_content(App $a) {
]; ];
$entry = [ $entry = [
'id' => $rr['id'], 'id' => $rr['id'],
'url' => $profile_link, 'url' => $profile_link,
'itemurl' => $itemurl, 'itemurl' => $itemurl,
'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB), 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
'img_hover' => $rr['name'], 'img_hover' => $rr['name'],
'name' => $rr['name'], 'name' => $rr['name'],
'details' => $details, 'details' => $details,
'account_type' => Contact::getAccountType($rr), 'account_type' => Contact::getAccountType($rr),
'profile' => $profile, 'profile' => $profile,
'location' => $location_e, 'location' => $location_e,
'tags' => $rr['pub_keywords'], 'tags' => $rr['pub_keywords'],
'gender' => $gender, 'gender' => $gender,
'pdesc' => $pdesc, 'pdesc' => $pdesc,
'marital' => $marital, 'marital' => $marital,
'homepage' => $homepage, 'homepage' => $homepage,
'about' => $about, 'about' => $about,
'photo_menu' => $photo_menu, 'photo_menu' => $photo_menu,
]; ];
@ -192,16 +199,16 @@ function directory_content(App $a) {
$tpl = get_markup_template('directory_header.tpl'); $tpl = get_markup_template('directory_header.tpl');
$o .= replace_macros($tpl, [ $o .= replace_macros($tpl, [
'$search' => $search, '$search' => $search,
'$globaldir' => L10n::t('Global Directory'), '$globaldir' => L10n::t('Global Directory'),
'$gdirpath' => $gdirpath, '$gdirpath' => $gdirpath,
'$desc' => L10n::t('Find on this site'), '$desc' => L10n::t('Find on this site'),
'$contacts' => $entries, '$contacts' => $entries,
'$finding' => L10n::t('Results for:'), '$finding' => L10n::t('Results for:'),
'$findterm' => (strlen($search) ? $search : ""), '$findterm' => (strlen($search) ? $search : ""),
'$title' => L10n::t('Site Directory'), '$title' => L10n::t('Site Directory'),
'$submit' => L10n::t('Find'), '$submit' => L10n::t('Find'),
'$paginate' => paginate($a), '$paginate' => paginate($a),
]); ]);
} else { } else {
info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL); info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);