mirror of
https://github.com/kvazar-network/webapp.git
synced 2025-02-03 10:46:04 +00:00
implement optional trends block
This commit is contained in:
parent
38c860f0fa
commit
a0eba92cc7
@ -10,6 +10,11 @@ define('BASE_URL', 'https://kvazar.today/');
|
||||
define('PAGE_LIMIT', 10);
|
||||
define('CACHE_ENABLED', false);
|
||||
|
||||
define('TRENDS_ENABLED', false); // alpha
|
||||
define('TRENDS_SECONDS_OFFSET', 2592000);
|
||||
define('TRENDS_MIN_LENGHT', 4);
|
||||
define('TRENDS_LIMIT', 40);
|
||||
|
||||
// Database
|
||||
define('DB_NAME', '../kvazar.sqlite');
|
||||
define('DB_USERNAME', '');
|
||||
|
@ -231,4 +231,38 @@ class SQLite {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTrends(int $offset = 0) {
|
||||
|
||||
try {
|
||||
|
||||
$query = $this->_db->prepare('SELECT `block`.`blockId` AS `block`,
|
||||
`namespace`.`hash` AS `namehash`,
|
||||
`data`.`time` AS `time`,
|
||||
`data`.`key` AS `key`,
|
||||
`data`.`value` AS `value`,
|
||||
`data`.`txid` AS `txid`
|
||||
|
||||
FROM `data`
|
||||
JOIN `block` ON (`block`.`blockId` = `data`.`blockId`)
|
||||
JOIN `namespace` ON (`namespace`.`nameSpaceId` = `data`.`nameSpaceId`)
|
||||
|
||||
WHERE `data`.`ns` = "0"
|
||||
AND `data`.`time` >= ' . (int) $offset . '
|
||||
-- AND `data`.`deleted` = "0" --
|
||||
|
||||
ORDER BY `block`.`blockId` DESC');
|
||||
|
||||
$query->execute();
|
||||
|
||||
$result = $query->fetchAll();
|
||||
|
||||
return $result ? $result : [];
|
||||
|
||||
} catch(PDOException $e) {
|
||||
|
||||
trigger_error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,48 @@ if ($ns) {
|
||||
$namespaceValue = false;
|
||||
}
|
||||
|
||||
$trends = [];
|
||||
|
||||
if (TRENDS_ENABLED) {
|
||||
|
||||
foreach ($db->getTrends(time() - TRENDS_SECONDS_OFFSET) as $value) {
|
||||
|
||||
foreach ((array) explode(' ', strip_tags(html_entity_decode(nl2br(trim($value['key']))))) as $trend) {
|
||||
|
||||
if (strlen($trend) >= TRENDS_MIN_LENGHT) {
|
||||
|
||||
$trend = strtolower($trend);
|
||||
|
||||
if (isset($trends[$trend])) {
|
||||
$trends[$trend]++;
|
||||
} else {
|
||||
$trends[$trend] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) explode(' ', strip_tags(html_entity_decode(nl2br(trim($value['value']))))) as $trend) {
|
||||
|
||||
if (strlen($trend) >= TRENDS_MIN_LENGHT) {
|
||||
|
||||
$trend = strtolower($trend);
|
||||
|
||||
if (isset($trends[$trend])) {
|
||||
$trends[$trend]++;
|
||||
} else {
|
||||
$trends[$trend] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arsort($trends);
|
||||
|
||||
$trends = array_slice($trends, 0, TRENDS_LIMIT);
|
||||
|
||||
$trends = array_flip($trends);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($db->getData($ns, $tx, $query, $limit, PAGE_LIMIT) as $value) {
|
||||
$data[] = [
|
||||
|
@ -44,6 +44,18 @@
|
||||
<div class="t-center px-16 pb-36">
|
||||
<div class="b-g"></div>
|
||||
</div>
|
||||
<?php if ($trends && !$ns && !$tx && !$page && !$q) { ?>
|
||||
<div class="t-center px-16">
|
||||
<div class="mx-a mw-560 px-16">
|
||||
<?php foreach ($trends as $trend) { ?>
|
||||
#<a href="<?php echo BASE_URL; ?>?q=<?php echo $trend; ?>"><?php echo $trend; ?></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="t-center px-16 py-27">
|
||||
<div class="b-g"></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php foreach ($data as $item) { ?>
|
||||
<div class="t-center px-16">
|
||||
<div class="mx-a mw-560 px-16">
|
||||
|
Loading…
x
Reference in New Issue
Block a user