From 5fb56281d0ab264425e64af2cd9dc98a54bcabba Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Apr 2017 19:57:26 -0400 Subject: [PATCH] Enforce coding standards in include/directory.php --- mod/directory.php | 195 +++++++++++++++++++++++----------------------- 1 file changed, 97 insertions(+), 98 deletions(-) diff --git a/mod/directory.php b/mod/directory.php index 08a1d713..0d30512d 100755 --- a/mod/directory.php +++ b/mod/directory.php @@ -1,123 +1,122 @@ set_pager_itemspage(80); +function directory_init(App $a) +{ + $a->set_pager_itemspage(80); - $a->page['aside'] .= tags_widget(); - $a->page['aside'] .= country_widget(); + $a->page['aside'] .= tags_widget(); + $a->page['aside'] .= country_widget(); } -function directory_content(&$a) { +function directory_content(App $a) +{ + $forums = false; + if ($a->argc == 2 && $a->argv[1] === 'forum') { + $forums = true; + } - $forums = false; - if($a->argc == 2 && $a->argv[1] === 'forum') - $forums = true; + $alpha = false; + if ($_GET['alpha'] == 1) { + $alpha = true; + } - $alpha = false; - if($_GET['alpha'] == 1) - $alpha = true; + $search = ((x($_GET, 'search')) ? notags(trim($_GET['search'])) : ''); + if ($_GET['submit'] === t('Clear')) { + goaway($a->get_baseurl()); + } - $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : ''); + if ($search) { + $alpha = true; + } - if($_GET['submit'] === t('Clear')) { - goaway($a->get_baseurl()); - } + $tpl .= file_get_contents('view/directory_header.tpl'); - if($search) - $alpha = true; + $o .= replace_macros($tpl, array( + '$search' => $search, + '$header' => t('Global Directory'), + '$submit' => t('Find'), + '$clear' => t('Clear'), + '$forum' => $a->get_baseurl() . (($forums) ? '' : '/directory/forum'), + '$toggle' => (($forums) ? t('Show People') : t('Show Community Forums')), + '$alpha' => (($alpha) ? t('Updated order') : t('Alphabetic order')), + '$alink' => (($alpha) ? str_replace('&alpha=1', '', $a->query_string) : $a->query_string . "&alpha=1"), + '$args' => (($forums) ? '/forum' : ''), + '$finding' => (strlen($search) ? '

' . t('Search for: ') . "'" . $search . "'" . '

' : "") + )); - - $tpl .= file_get_contents('view/directory_header.tpl'); - - $o .= replace_macros($tpl, array( - '$search' => $search, - '$header' => t('Global Directory'), - '$submit' => t('Find'), - '$clear' => t('Clear'), - '$forum' => $a->get_baseurl() . (($forums) ? '' : '/directory/forum' ), - '$toggle' => (($forums) ? t('Show People') : t('Show Community Forums')), - '$alpha' => (($alpha) ? t('Updated order') : t('Alphabetic order')), - '$alink' => (($alpha) ? str_replace('&alpha=1','',$a->query_string) : $a->query_string . "&alpha=1"), - '$args' => (($forums) ? '/forum' : ''), - '$finding' => (strlen($search) ? '

' . t('Search for: ') . "'" . $search . "'" . '

' : "") - )); - - if($search) - $search = dbesc($search . '*'); - $sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` ) + if ($search) { + $search = dbesc($search . '*'); + } + $sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` ) AGAINST ('$search' IN BOOLEAN MODE) " : ""); - if($forums) - $sql_extra .= " and comm = 1 "; + if ($forums) { + $sql_extra .= " and comm = 1 "; + } - $sql_extra = str_replace('%','%%',$sql_extra); + $sql_extra = str_replace('%', '%%', $sql_extra); - $r = q("SELECT COUNT(*) AS `total` FROM `profile` WHERE `censored` = 0 $sql_extra "); - if(count($r)) - $a->set_pager_total($r[0]['total']); + $r = q("SELECT COUNT(*) AS `total` FROM `profile` WHERE `censored` = 0 $sql_extra "); + if (count($r)) { + $a->set_pager_total($r[0]['total']); + } - if($alpha) - $order = " order by name asc "; - else - $order = " order by updated desc, id desc "; + if ($alpha) { + $order = " order by name asc "; + } else { + $order = " order by updated desc, id desc "; + } + $r = q("SELECT * FROM `profile` WHERE `censored` = 0 $sql_extra $order LIMIT %d , %d ", + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); - $r = q("SELECT * FROM `profile` WHERE `censored` = 0 $sql_extra $order LIMIT %d , %d ", - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); + if (count($r)) { + $tpl = file_get_contents('view/directory_item.tpl'); - if(count($r)) { + foreach ($r as $rr) { + $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); - $tpl = file_get_contents('view/directory_item.tpl'); + $details = ''; + if (strlen($rr['locality'])) { + $details .= $rr['locality']; + } + if (strlen($rr['region'])) { + if (strlen($rr['locality'])) { + $details .= ', '; + } + $details .= $rr['region']; + } + if (strlen($rr['country-name'])) { + if (strlen($details)) { + $details .= ', '; + } + $details .= $rr['country-name']; + } - foreach($r as $rr) { + $o .= replace_macros($tpl, array( + '$id' => $rr['id'], + '$mod' => '
' . t('Flag this entry') . '
', + '$star' => (($rr['tags']) ? '
' : ''), + '$profile-link' => zrl($rr['homepage']), + '$photo' => $a->get_baseurl() . '/photo/' . $rr['id'], + '$alt-text' => $rr['name'] . ' ' . '(' . $rr['homepage'] . ')', + '$name' => $rr['name'], + '$pclass' => (($rr['comm']) ? ' group' : ''), + '$pgroup' => (($rr['comm']) ? '
' . t('[Public Group]') . '
' : ''), + '$details' => $pdesc . $details + )); + } - $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); + $o .= '
' . PHP_EOL; + $o .= paginate($a); + } else { + notice(t('No matching entries.') . EOL); + } - $details = ''; - if(strlen($rr['locality'])) - $details .= $rr['locality']; - if(strlen($rr['region'])) { - if(strlen($rr['locality'])) - $details .= ', '; - $details .= $rr['region']; - } - if(strlen($rr['country-name'])) { - if(strlen($details)) - $details .= ', '; - $details .= $rr['country-name']; - } - - - $o .= replace_macros($tpl,array( - '$id' => $rr['id'], - '$mod' => '
' . t('Flag this entry') . '
', - '$star' => (($rr['tags']) ? '
' : ''), - '$profile-link' => zrl($rr['homepage']), - '$photo' => $a->get_baseurl() . '/photo/' . $rr['id'], - -// '$photo' => (($rr['photo']) ? $rr['photo'] : $a->get_baseurl() . '/photo/' . $rr['id']), - '$alt-text' => $rr['name'] . ' ' . '(' . $rr['homepage'] . ')', - '$name' => $rr['name'], - '$pclass' => (($rr['comm']) ? ' group' : ''), - '$pgroup' => (($rr['comm']) ? '
' . t('[Public Group]') . '
' : ''), - '$details' => $pdesc . $details - - - - )); - - } - $o .= "
\r\n"; - $o .= paginate($a); - - } - else - notice( t('No matching entries.') . EOL); - - return $o; -} \ No newline at end of file + return $o; +}