Merge pull request #38 from MrPetovan/task/fix-country-widget

Fix country widget + search + tags
This commit is contained in:
Michael Vogel 2018-01-17 20:23:47 +01:00 committed by GitHub
commit 7701347cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 58 deletions

View File

@ -39,6 +39,9 @@ function run_submit($url)
`updated` = '%s'
WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($profile_id)
);
$r = q("DELETE FROM `tag` WHERE `nurl` = '%s'",
dbesc($r[0]['nurl'])
);
}
//Remove duplicates.
@ -185,16 +188,10 @@ function run_submit($url)
$t = substr($t, 0, 254);
if (strlen($t)) {
$r = q("SELECT `id` FROM `tag` WHERE `term` = '%s' and `nurl` = '%s' LIMIT 1",
$r = q("INSERT INTO `tag` (`term`, `nurl`) VALUES ('%s', '%s') ",
dbesc($t),
dbesc($nurl)
);
if (!count($r)) {
$r = q("INSERT INTO `tag` (`term`, `nurl`) VALUES ('%s', '%s') ",
dbesc($t),
dbesc($nurl)
);
}
}
}
}

View File

@ -1,6 +1,8 @@
<?php
function tags_widget()
use Friendica\Directory\App;
function tags_widget(App $a)
{
$o = '';
@ -10,29 +12,30 @@ function tags_widget()
$o .= '<h3>' . t('Trending Interests') . '</h3>';
$o .= '<ul>';
foreach ($r as $rr) {
$o .= '<li><a href="search?query=' . $rr['term'] . '" >' . $rr['term'] . '</a> (' . $rr['total'] . ')</li>';
$o .= '<li><a href="' . $a->get_baseurl() . '/search?query=' . $rr['term'] . '" >' . $rr['term'] . '</a> (' . $rr['total'] . ')</li>';
}
$o .= '</ul></div>';
}
return $o;
}
function country_widget()
function country_widget(App $a)
{
$o = '';
$r = q("SELECT `country-name`, COUNT(`country-name`) AS `total`"
. " FROM `profile`"
. " WHERE `country-name` != ''"
. " GROUP BY `country-name`"
. " ORDER BY COUNT(`country-name`) DESC"
. " LIMIT 20");
$r = q("SELECT `country-name`, COUNT(`country-name`) AS `total`
FROM `profile`
WHERE `country-name` != ''
AND `available`
GROUP BY `country-name`
ORDER BY COUNT(`country-name`) DESC
LIMIT 20");
if (count($r)) {
$o .= '<div class="widget">';
$o .= '<h3>' . t('Locations') . '</h3>';
$o .= '<ul>';
foreach ($r as $rr) {
$o .= '<li><a href="search?query=' . $rr['country-name'] . '" >' . $rr['country-name'] . '</a> (' . $rr['total'] . ')</li>';
$o .= '<li><a href="' . $a->get_baseurl() . '/search?query=' . $rr['country-name'] . '" >' . $rr['country-name'] . '</a> (' . $rr['total'] . ')</li>';
}
$o .= '</ul></div>';
}

View File

@ -22,7 +22,7 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
$a->init_pagehead();
$a->page['aside'] = '<div id="logo"><img src="images/friendica-32.png" alt="friendica logo" /> <a href="http://friendica.com">Friendica</a></div><div id="slogan">Your friends. Your web.</div>';
$a->page['aside'] = '';
session_start();

View File

@ -11,8 +11,8 @@ function directory_init(App $a)
{
$a->set_pager_itemspage(30);
$a->page['aside'] .= tags_widget();
$a->page['aside'] .= country_widget();
$a->page['aside'] .= tags_widget($a);
$a->page['aside'] .= country_widget($a);
}
function directory_content(App $a)
@ -82,6 +82,7 @@ function directory_content(App $a)
$view->addHelper('filterForumsUrl', SearchHelper::get('filterForumsUrl'));
$view->output(array(
'aside' => $a->page['aside'],
'total' => number_format($total),
'results' => $r,
'filter' => $filter,

View File

@ -5,6 +5,16 @@ use Friendica\Directory\Rendering\View;
use Friendica\Directory\Helper\Search as SearchHelper;
use Friendica\Directory\Helper\Profile as ProfileHelper;
require_once 'include/widget.php';
function search_init(App $a)
{
$a->set_pager_itemspage(30);
$a->page['aside'] .= tags_widget($a);
$a->page['aside'] .= country_widget($a);
}
function search_content(App $a)
{
//Filters
@ -89,6 +99,7 @@ function search_content(App $a)
$view->addHelper('filterForumsUrl', SearchHelper::get('filterForumsUrl'));
$view->output(array(
'aside' => $a->page['aside'],
'total' => number_format($total),
'results' => $r,
'filter' => $filter,

View File

@ -1,33 +1,32 @@
<div class="sub-menu-outer">
<div class="sub-menu-inner search-options">
<a class="option <?php echo empty($filter) ? 'active' : '' ?>" href="<?php echo $this->filterAllUrl(''); ?>">All</a>
<a class="option <?php echo $filter == 'people' ? 'active' : '' ?>" href="<?php echo $this->filterPeopleUrl(''); ?>">People</a>
<a class="option <?php echo $filter == 'forums' ? 'active' : '' ?>" href="<?php echo $this->filterForumsUrl(''); ?>">Forums</a>
</div>
<div class="sub-menu-inner search-options">
<a class="option <?php echo empty($filter) ? 'active' : '' ?>" href="<?php echo $this->filterAllUrl(''); ?>">All</a>
<a class="option <?php echo $filter == 'people' ? 'active' : '' ?>" href="<?php echo $this->filterPeopleUrl(''); ?>">People</a>
<a class="option <?php echo $filter == 'forums' ? 'active' : '' ?>" href="<?php echo $this->filterForumsUrl(''); ?>">Forums</a>
</div>
</div>
<div class="directory-results">
<aside>
<?php echo tags_widget() ?>
<?php echo country_widget() ?>
</aside>
<section>
<div class="profiles">
<?php if (count($results)): ?>
<aside>
<?php echo $aside ?>
</aside>
<section>
<div class="profiles">
<?php if (count($results)): ?>
<?php
foreach ($results as $profile) {
echo $this->view('_profile', array('profile' => $profile));
}
?>
<?php
foreach ($results as $profile) {
echo $this->view('_profile', ['profile' => $profile]);
}
?>
<?php else: ?>
<?php else: ?>
<h3>There were no results</h3>
<h3>There were no results</h3>
<?php endif ?>
<?php endif ?>
</div>
<?php echo $this->paginate();?>
</section>
</div>
<?php echo $this->paginate(); ?>
</section>
</div>

View File

@ -6,24 +6,27 @@
</div>
</div>
<div class="search-results">
<h3>Results for "<?php echo $query; ?>" (<?php echo $total; ?>)</h3>
<div class="profiles">
<?php if (count($results)): ?>
<?php
<div class="directory-results">
<aside>
<?php echo $aside ?>
</aside>
<section>
<h3>Results for "<?php echo $query; ?>" (<?php echo $total; ?>)</h3>
<div class="profiles">
<?php if (count($results)): ?>
<?php
foreach ($results as $profile) {
echo $this->view('_profile', array('profile' => $profile));
}
?>
echo $this->view('_profile', ['profile' => $profile]);
}
?>
<?php else: ?>
<?php else: ?>
<h3>There were no results</h3>
<h3>There were no results</h3>
<?php endif ?>
</div>
<?php echo $this->paginate();?>
<?php endif ?>
</div>
<?php echo $this->paginate(); ?>
</section>
</div>