Merge pull request #807 from rabuzarus/20190219_-_frio_support_for_forumdirectory

forumdirectory: use the directory template from friendica core
This commit is contained in:
Hypolite Petovan 2019-02-18 08:01:29 -05:00 committed by GitHub
commit fd1b155120
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 222 deletions

View file

@ -1,67 +0,0 @@
section .forumdirectory-item dl {
height: auto;
overflow: auto;
}
section .forumdirectory-item dt {
float: left;
margin-left: 0px;
text-align: right;
color: #999;
}
section .forumdirectory-item dd {
float: left;
margin-left: 5px;
}
.forumdirectory-profile-wrapper {
float: left;
/*max-height: 178px; */
overflow: hidden;
width: 500px;
margin: 0px 20px;
}
.forumdirectory-copy-wrapper {
float: left;
overflow: hidden;
}
.forumdirectory-item {
float: left;
width: 800px;
/* height: 200px; */
box-shadow: 8px 8px 4px #000;
margin-top: 30px;
border: solid 1px #222;
}
section .forumdirectory-photo-wrapper {
float: left;
height: 200px;
width: 165px;
}
.forumcontact-name {
font-size: 18px;
font-weight: bold;
margin-bottom: -3px;
text-align: left;
}
.page-type {
font-size: 10px;
font-style: italic;
}
.directory-detailscolumn-wrapper {
float: left;
width: 305px;
margin-right: 10px;
}
.directory-profile-wrapper dl {
margin-top: 3px;
margin-bottom: 3px;
}
.directory-profile-title {
font-weight: bold;
margin-bottom: 3px;
font-size: 14px;
}

View file

@ -2,7 +2,7 @@
/** /**
* Name: Forum Directory * Name: Forum Directory
* Description: Add a directory of forums hosted on your server, with verbose descriptions. * Description: Add a directory of forums hosted on your server, with verbose descriptions.
* Version: 1.0 * Version: 1.1
* Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer> * Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
*/ */
@ -13,6 +13,7 @@ use Friendica\Content\Widget;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Profile; use Friendica\Model\Profile;
@ -20,6 +21,8 @@ use Friendica\Model\User;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
include_once 'mod/directory.php';
function forumdirectory_install() function forumdirectory_install()
{ {
Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu'); Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
@ -42,8 +45,6 @@ function forumdirectory_app_menu(App $a, array &$b)
function forumdirectory_init(App $a) function forumdirectory_init(App $a)
{ {
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/forumdirectory/forumdirectory.css" media="all" />';
if (local_user()) { if (local_user()) {
$a->page['aside'] .= Widget::findPeople(); $a->page['aside'] .= Widget::findPeople();
} else { } else {
@ -66,6 +67,8 @@ function forumdirectory_content(App $a)
} }
$o = ''; $o = '';
$entries = [];
Nav::setSelected('directory'); Nav::setSelected('directory');
if (!empty($a->data['search'])) { if (!empty($a->data['search'])) {
@ -74,52 +77,55 @@ function forumdirectory_content(App $a)
$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
} }
$tpl = Renderer::getMarkupTemplate('directory_header.tpl'); $gdirpath = '';
$dirurl = Config::get('system', 'directory');
$globaldir = ''; if (strlen($dirurl)) {
$gdirpath = Config::get('system', 'directory'); $gdirpath = Profile::zrl($dirurl, true);
if (strlen($gdirpath)) {
$globaldir = '<ul><li><div id="global-directory-link"><a href="'
. Profile::zrl($gdirpath, true) . '">' . L10n::t('Global Directory') . '</a></div></li></ul>';
} }
$admin = '';
$o .= Renderer::replaceMacros($tpl, [
'$search' => $search,
'$globaldir' => $globaldir,
'$desc' => L10n::t('Find on this site'),
'$admin' => $admin,
'$finding' => (strlen($search) ? '<h4>' . L10n::t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
'$sitedir' => L10n::t('Site Directory'),
'$submit' => L10n::t('Find')
]);
$sql_extra = ''; $sql_extra = '';
if (strlen($search)) { if (strlen($search)) {
$sql_extra = " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`," $search = DBA::escape($search);
. "`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` )"
. " AGAINST ('" . DBA::escape($search) . "' IN BOOLEAN MODE) "; $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
(`user`.`nickname` LIKE '%$search%') OR
(`profile`.`pdesc` LIKE '%$search%') OR
(`profile`.`locality` LIKE '%$search%') OR
(`profile`.`region` LIKE '%$search%') OR
(`profile`.`country-name` LIKE '%$search%') OR
(`profile`.`gender` LIKE '%$search%') OR
(`profile`.`marital` LIKE '%$search%') OR
(`profile`.`sexual` LIKE '%$search%') OR
(`profile`.`about` LIKE '%$search%') OR
(`profile`.`romance` LIKE '%$search%') OR
(`profile`.`work` LIKE '%$search%') OR
(`profile`.`education` LIKE '%$search%') OR
(`profile`.`pub_keywords` LIKE '%$search%') OR
(`profile`.`prv_keywords` LIKE '%$search%'))";
} }
$publish = Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 "; $publish = Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ";
$total = 0; $total = 0;
$r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`" $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
. " WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra "); LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
if (DBA::isResult($r)) { WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` `user`.`page-flags` = 2 $sql_extra");
$total = $r[0]['total']; if (DBA::isResult($cnt)) {
$total = $cnt['total'];
} }
$pager = new Pager($a->query_string, 60); $pager = new Pager($a->query_string, 60);
$order = " ORDER BY `name` ASC "; $order = " ORDER BY `name` ASC ";
$r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`" $limit = $pager->getStart()."," . $pager->getItemsPerPage();
. " FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish"
. " AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra $order LIMIT %d , %d ", $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
$pager->getStart(), `contact`.`addr`, `contact`.`url` AS `profile_url` FROM `profile`
$pager->getItemsPerPage() LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = 2 AND `contact`.`self`
$sql_extra $order LIMIT $limit"
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -129,89 +135,28 @@ function forumdirectory_content(App $a)
$photo = 'photo'; $photo = 'photo';
} }
foreach ($r as $rr) { while ($rr = DBA::fetch($r)) {
$profile_link = $a->getBaseURL() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); $entries[] = format_directory_entry($rr, $photo);
$pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
$details = '';
if (strlen($rr['locality'])) {
$details .= $rr['locality'];
} }
DBA::close($r);
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'];
}
if (strlen($rr['dob']) && ($years = Temporal::getAgeByTimezone($rr['dob'], $rr['timezone'], '')) != 0) {
$details .= '<br />' . L10n::t('Age: ') . $years;
}
if (strlen($rr['gender'])) {
$details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
}
switch ($rr['page-flags']) {
case User::PAGE_FLAGS_NORMAL : $page_type = "Personal Profile"; break;
case User::PAGE_FLAGS_SOAPBOX : $page_type = "Fan Page" ; break;
case User::PAGE_FLAGS_COMMUNITY: $page_type = "Community Forum" ; break;
case User::PAGE_FLAGS_FREELOVE : $page_type = "Open Forum" ; break;
case User::PAGE_FLAGS_PRVGROUP : $page_type = "Private Group" ; break;
}
$profile = $rr;
$location = '';
if (!empty($profile['address'])
|| !empty($profile['locality'])
|| !empty($profile['region'])
|| !empty($profile['postal-code'])
|| !empty($profile['country-name'])
) {
$location = L10n::t('Location:');
}
$gender = !empty($profile['gender']) ? L10n::t('Gender:') : false;
$marital = !empty($profile['marital']) ? L10n::t('Status:') : false;
$homepage = !empty($profile['homepage']) ? L10n::t('Homepage:') : false;
$about = !empty($profile['about']) ? L10n::t('About:') : false;
$tpl = Renderer::getMarkupTemplate('forumdirectory_item.tpl', 'addon/forumdirectory/');
$entry = Renderer::replaceMacros($tpl, [
'$id' => $rr['id'],
'$profile_link' => $profile_link,
'$photo' => $rr[$photo],
'$alt_text' => $rr['name'],
'$name' => $rr['name'],
'$details' => $pdesc . $details,
'$page_type' => $page_type,
'$profile' => $profile,
'$location' => $location,
'$gender' => $gender,
'$pdesc' => $pdesc,
'$marital' => $marital,
'$homepage' => $homepage,
'$about' => $about,
]);
$o .= $entry;
}
$o .= "<div class=\"directory-end\" ></div>\r\n";
$o .= $pager->renderFull($total);
} 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);
} }
$tpl = Renderer::getMarkupTemplate('directory_header.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$search' => $search,
'$globaldir' => L10n::t('Global Directory'),
'$gdirpath' => $gdirpath,
'$desc' => L10n::t('Find on this site'),
'$contacts' => $entries,
'$finding' => L10n::t('Results for:'),
'$findterm' => (strlen($search) ? $search : ""),
'$title' => L10n::t('Forum Directory'),
'$search_mod' => 'forumdirectory',
'$submit' => L10n::t('Find'),
'$paginate' => $pager->renderFull($total),
]);
return $o; return $o;
} }

View file

@ -1,42 +0,0 @@
<div class="forumdirectory-item" id="forumdirectory-item-{{$id}}" >
<div class="forumdirectory-photo-wrapper" id="forumdirectory-photo-wrapper-{{$id}}" >
<div class="forumdirectory-photo" id="forumdirectory-photo-{{$id}}" >
<a href="{{$profile_link}}" class="forumdirectory-profile-link" id="forumdirectory-profile-link-{{$id}}" >
<img class="forumdirectory-photo-img photo" src="{{$photo}}" alt="{{$alt_text}}" title="{{$alt_text}}" />
</a>
</div>
</div>
<div class="forumdirectory-profile-wrapper" id="forumdirectory-profile-wrapper-{{$id}}" >
<div class="contact-name" id="forumdirectory-name-{{$id}}">{{$name}}</div>
<div class="page-type">{{$page_type}}</div>
{{if $pdesc}}<div class="forumdirectory-profile-title">{{$profile.pdesc}}</div>{{/if}}
<div class="forumdirectory-detailcolumns-wrapper" id="forumdirectory-detailcolumns-wrapper-{{$id}}">
<div class="forumdirectory-detailscolumn-wrapper" id="forumdirectory-detailscolumn1-wrapper-{{$id}}">
{{if $location}}
<dl class="location"><dt class="location-label">{{$location}}</dt>
<dd class="adr">
{{if $profile.address}}<div class="street-address">{{$profile.address}}</div>{{/if}}
<span class="city-state-zip">
{{if $profile.locality}}<span class="locality">{{$profile.locality}}</span>, {{/if}}
{{if $profile.region}}<span class="region">{{$profile.region}}</span>{{/if}}
{{if $profile['postal-code']}}<span class="postal-code">{{$profile['postal-code']}}</span>{{/if}}
</span>
{{if $profile['country-name']}}<span class="country-name">{{$profile['country-name']}}</span>{{/if}}
</dd>
</dl>
{{/if}}
{{if $gender}}<dl class="mf"><dt class="gender-label">{{$gender}}</dt> <dd class="x-gender">{{$profile.gender}}</dd></dl>{{/if}}
</div>
<div class="forumdirectory-detailscolumn-wrapper" id="forumdirectory-detailscolumn2-wrapper-{{$id}}">
{{if $marital}}<dl class="marital"><dt class="marital-label"><span class="heart">&hearts;</span>{{$marital}}</dt><dd class="marital-text">{{$profile.marital}}</dd></dl>{{/if}}
{{if $homepage}}<dl class="homepage"><dt class="homepage-label">{{$homepage}}</dt><dd class="homepage-url"><a href="{{$profile.homepage}}" target="_blank">{{$profile.homepage}}</a></dd></dl>{{/if}}
</div>
</div>
<div class="forumdirectory-copy-wrapper" id="forumdirectory-copy-wrapper-{{$id}}" >
{{if $about}}<dl class="forumdirectory-copy"><dt class="forumdirectory-copy-label">{{$about}}</dt><dd class="forumdirectory-copy-data">{{$profile.about nofilter}}</dd></dl>{{/if}}
</div>
</div>
</div>