Browse Source

Merge 'master' branch changes to 'sqlite'

pull/8/head
ghost 2 years ago
parent
commit
0bb720f7ce
  1. 49
      README.md
  2. 0
      cache/index.html
  3. 5
      config-default.php
  4. 59
      crontab/sitemap.php
  5. 21
      library/icon.php
  6. 36
      library/sqlite.php
  7. 21
      public/css/app.css
  8. 29
      public/image.php
  9. 14
      public/index.php
  10. 30
      public/index.phtml
  11. 2
      public/robots.txt

49
README.md

@ -1,5 +1,50 @@ @@ -1,5 +1,50 @@
# kvazar-network webapp
Web-oriented content exploring platform for Kevacoin Blockchain
### demo
https://kvazar.ml
### requirements
```
php-7.4
php-curl
php-mbstring
php-mysql
php-sqlite
php-pdo
php-bcmath
php-gd
```
#### database
https://github.com/kvazar-network/database
##### MySQL
https://github.com/kvazar-network/webapp/tree/master
##### SQLite
https://github.com/kvazar-network/webapp/tree/sqlite
#### crontab
```
0 0 * * * /path-to/php /path-to/crontab/sitemap.php > /dev/null 2>&1
```
### nginx sef_mode example
```
location / {
try_files $uri $uri/ =404 @sef;
}
location @sef {
rewrite ^(/.*)$ /?$1 last;
}
```
### examples
#### web
https://kvazar.today
#### yggdrasil
[http://[203:7693:ae20:18a6:7689:cb63:c53d:43c6]](http://[203:7693:ae20:18a6:7689:cb63:c53d:43c6])

0
cache/index.html vendored

5
config-default.php

@ -10,6 +10,11 @@ define('BASE_URL', '/'); @@ -10,6 +10,11 @@ define('BASE_URL', '/');
define('PAGE_LIMIT', 10);
define('SEF_MODE', false);
define('BASE_URL', 'https://kvazar.today');
define('PAGE_LIMIT', 10);
define('SEF_MODE', true);
define('CACHE_ENABLED', false);
// Database
define('DB_NAME', 'kvazar.dat');
define('DB_USERNAME', '');

59
crontab/sitemap.php

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
<?php
require_once(dirname(__FILE__) . '/../config.php');
require_once(dirname(__FILE__) . '/../library/mysql.php');
$db = new MySQL();
// Generate url sets
$transaction = '<?xml version="1.0" encoding="UTF-8"?>';
$transaction .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
$namespace = '<?xml version="1.0" encoding="UTF-8"?>';
$namespace .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
$namespaces = [];
$transactions = [];
foreach ($db->getData(false, false, false, 0, 1000000) as $value) {
if (!in_array($value['namehash'], $namespaces)) {
$namespace .= '<loc>' . BASE_URL . '/' . $value['namehash'] . '</loc>';
}
if (!in_array($value['namehash'], $transactions)) {
$transaction .= '<loc>' . BASE_URL . '/' . $value['txid'] . '</loc>';
}
$namespaces[] = $value['namehash'];
$transactions[] = $value['txid'];
}
$namespace .= '</urlset>';
$transaction .= '</urlset>';
$handle = fopen(dirname(__FILE__) . '/../public/sitemap.transaction.xml', 'w');
fwrite($handle, $transaction);
fclose($handle);
$handle = fopen(dirname(__FILE__) . '/../public/sitemap.namespace.xml', 'w');
fwrite($handle, $namespace);
fclose($handle);
// Sitemap
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$sitemap .= ' <sitemap>';
$sitemap .= ' <loc>' . BASE_URL . '/sitemap.namespace.xml</loc>';
$sitemap .= ' </sitemap>';
$sitemap .= ' <sitemap>';
$sitemap .= ' <loc>' . BASE_URL . '/sitemap.transaction.xml</loc>';
$sitemap .= ' </sitemap>';
$sitemap .= '</sitemapindex>';
$handle = fopen(dirname(__FILE__) . '/../public/sitemap.xml', 'w');
fwrite($handle, $sitemap);
fclose($handle);

21
library/icon.php

@ -10,7 +10,7 @@ final class Icon { @@ -10,7 +10,7 @@ final class Icon {
private $_spriteZ = 800;
public function generateImageResource($hash, $width, $height, $filter = false) {
public function generateImageResource($hash, $width, $height, $filter = false, $radius = 0) {
$this->_width = $width;
$this->_height = $height;
@ -74,14 +74,27 @@ final class Icon { @@ -74,14 +74,27 @@ final class Icon {
imagecopyresampled($resized, $identicon, 0, 0, (imagesx($identicon) - $this->_spriteZ * 3) / 2, (imagesx($identicon) - $this->_spriteZ * 3) / 2, $this->_width, $this->_height, $this->_spriteZ * 3, $this->_spriteZ * 3);
imagecolortransparent($resized, $bg);
if ($filter) {
imagefilter($resized, $filter);
}
if ($radius) {
imagearc($resized, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $bg);
imagefilltoborder($resized, 0, 0, $bg, $bg);
imagearc($resized, $this->_width-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $bg);
imagefilltoborder($resized, $this->_width-1, 0, $bg, $bg);
imagearc($resized, $radius-1, $this->_height-$radius, $radius*2, $radius*2, 90, 180, $bg);
imagefilltoborder($resized, 0, $this->_height-1, $bg, $bg);
imagearc($resized, $this->_width-$radius, $this->_height-$radius, $radius*2, $radius*2, 0, 90, $bg);
imagefilltoborder($resized, $this->_width-1, $this->_height-1, $bg, $bg);
imagecolortransparent($resized, $bg);
}
ob_start();
imagejpeg($resized, null, 100);
imagepng($resized);
imagedestroy($resized);
return ob_get_clean();
}

36
library/sqlite.php

@ -16,7 +16,7 @@ class SQLite { @@ -16,7 +16,7 @@ class SQLite {
}
}
public function getNamespaceName($namehash) {
public function getNamespaceValueByNS($ns) {
try {
@ -27,13 +27,13 @@ class SQLite { @@ -27,13 +27,13 @@ class SQLite {
WHERE `namespace`.`hash` = ?
AND `data`.`ns` = "1"
AND `data`.`deleted` = "0"
-- AND `data`.`deleted` = "0" --
ORDER BY `data`.`blockId` DESC
LIMIT 1');
$query->execute([$namehash]);
$query->execute([$ns]);
$result = $query->fetch();
@ -46,6 +46,28 @@ class SQLite { @@ -46,6 +46,28 @@ class SQLite {
}
}
public function getNamespaceHashByTX($txid) {
try {
$query = $this->_db->prepare('SELECT `namespace`.`hash`
FROM `namespace`
JOIN `data` ON (`data`.`nameSpaceId` = `namespace`.`nameSpaceId`)
WHERE `data`.`txid` = ?');
$query->execute([$txid]);
return $query->rowCount() ? $query->fetch()['hash'] : [];
} catch(PDOException $e) {
trigger_error($e->getMessage());
return false;
}
}
public function getData($namehash = false, $txid = false, $search = false, $start = 0, $limit = 10) {
try {
@ -65,7 +87,7 @@ class SQLite { @@ -65,7 +87,7 @@ class SQLite {
WHERE `data`.`txid` = ?
AND `data`.`ns` = "0"
AND `data`.`deleted` = "0"
-- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC
@ -88,7 +110,7 @@ class SQLite { @@ -88,7 +110,7 @@ class SQLite {
WHERE `namespace`.`hash` = ?
AND `data`.`ns` = "0"
AND `data`.`deleted` = "0"
-- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC
@ -116,7 +138,7 @@ class SQLite { @@ -116,7 +138,7 @@ class SQLite {
OR `data`.`txid` LIKE :search)
AND `data`.`ns` = "0"
AND `data`.`deleted` = "0"
-- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC
@ -140,7 +162,7 @@ class SQLite { @@ -140,7 +162,7 @@ class SQLite {
JOIN `namespace` ON (`namespace`.`nameSpaceId` = `data`.`nameSpaceId`)
WHERE `data`.`ns` = "0"
AND `data`.`deleted` = "0"
-- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC

21
public/css/app.css

@ -12,12 +12,19 @@ button::-moz-focus-inner { @@ -12,12 +12,19 @@ button::-moz-focus-inner {
input, button {
opacity: 0.8;
color: #5A526C;
color: #18102d;
background: #BFBACC;
border: 0;
border-radius: 3px;
height: 18px;
line-height: 18px;
outline: none;
text-align: center;
}
body {
color: #E8E8E8;
background-color: #000;
background-color: #18102d;
font-family: Sans-Serif, Arial;
font-size: 14px;
font-weight: normal;
@ -89,17 +96,19 @@ img:hover { @@ -89,17 +96,19 @@ img:hover {
.b-g::before {
content: "";
background-image: linear-gradient(to left, #9B94BF, #000);
background-image: linear-gradient(to left, #9B94BF, #18102d);
height: 1px;
width: 360px;
width: 50%;
max-width: 360px;
display: inline-block;
}
.b-g::after {
content: "";
background-image: linear-gradient(to right, #9B94BF, #000);
background-image: linear-gradient(to right, #9B94BF, #18102d);
height: 1px;
width: 360px;
width: 50%;
max-width: 360px;
display: inline-block;
}

29
public/image.php

@ -1,11 +1,36 @@ @@ -1,11 +1,36 @@
<?php
require_once('../config.php');
require_once('../library/icon.php');
if (isset($_GET['hash'])) {
$hash = md5($_GET['hash']);
$width = isset($_GET['width']) ? (int) $_GET['width'] : 60;
$height = isset($_GET['height']) ? (int) $_GET['height'] : 60;
$radius = isset($_GET['radius']) ? (int) $_GET['radius'] : 0;
header("Content-Type: image/png");
if (CACHE_ENABLED) {
$filename = dirname(__FILE__) . '/../cache/' . $hash . '.png';
if (!file_exists($filename)) {
$icon = new Icon();
header("Content-Type: image/jpeg");
echo $icon->generateImageResource(md5($_GET['hash']), 60, 60, false);
file_put_contents($filename, $icon->generateImageResource($hash, $width, $height, false, $radius));
}
echo file_get_contents($filename);
} else {
$icon = new Icon();
echo $icon->generateImageResource($hash, $width, $height, false, $radius);
}
}

14
public/index.php

@ -4,7 +4,7 @@ require_once('../config.php'); @@ -4,7 +4,7 @@ require_once('../config.php');
require_once('../library/icon.php');
require_once('../library/sqlite.php');
$query = isset($_GET['q']) ? $_GET['q'] : false;
$query = isset($_GET['q']) ? preg_replace('/[\W\D\S]+/', '', $_GET['q']) : false;
$ns = isset($_GET['ns']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['ns']) : false;
$tx = isset($_GET['tx']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['tx']) : false;
$page = (int) isset($_GET['page']) ? $_GET['page'] : 0;
@ -41,8 +41,18 @@ if ($page > 0) { @@ -41,8 +41,18 @@ if ($page > 0) {
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
if ($ns) {
$namespaceValue = $db->getNamespaceName($ns);
$namespaceHash = $ns;
$namespaceValue = $db->getNamespaceValueByNS($ns);
} else if ($tx) {
$namespaceHash = $db->getNamespaceHashByTX($tx);
$namespaceValue = $db->getNamespaceValueByNS($namespaceHash);
} else {
$namespaceHash = false;
$namespaceValue = false;
}

30
public/index.phtml

@ -1,23 +1,27 @@ @@ -1,23 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/app.css" />
<link rel="stylesheet" type="text/css" href="/css/app.css?v=4" />
<meta charset="UTF-8" />
<meta name="description" content="Open Source Content Exploring Platform for Kevacoin Blockchain" />
<base href="<?php echo BASE_URL; ?>" />
<?php if ($namespaceHash) { ?>
<link rel="icon" type="image/png" href="/image.php?hash=<?php echo $namespaceHash; ?>&radius=30" />
<?php } ?>
<?php if ($ns) { ?>
<?php if ($page) { ?>
<title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | PART <?php echo $page; ?> | KVAZAR</title>
<meta name="robots" content="noindex,follow" />
<?php } else { ?>
<title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | KVAZAR</title>
<?php } ?>
<?php } else { ?>
<?php if ($page) { ?>
<title>KVAZAR | PART <?php echo $page; ?></title>
<meta name="robots" content="noindex,follow" />
<?php } else if ($tx) { ?>
<title><?php echo $tx && isset($data[0]['key']) ? $data[0]['key'] : $tx; ?> | KVAZAR</title>
<title><?php echo $tx && isset($data[0]['key']) ? $data[0]['key'] : $tx; ?> | <?php echo ($namespaceValue ? $namespaceValue : ($namespaceHash ? $namespaceHash : false)); ?> | KVAZAR</title>
<?php } else { ?>
<title>KVAZAR | Observe Kevacoin Universe</title>
<title>KVAZAR | TODAY</title>
<?php } ?>
<?php } ?>
</head>
@ -29,7 +33,7 @@ @@ -29,7 +33,7 @@
</div>
<?php if ($ns) { ?>
<div class="mx-a mw-560 px-16 pb-16">
<img class="br-50 shine" src="image.php?hash=<?php echo $ns; ?>" alt="<?php echo $ns; ?>" />
<img class="br-50 shine" src="/image.php?hash=<?php echo $ns; ?>" alt="<?php echo $ns; ?>" />
</div>
<?php } ?>
<div class="mb-36 c-1"><?php echo $namespaceValue ? $namespaceValue : 'Observe Kevacoin Universe'; ?></div>
@ -44,18 +48,18 @@ @@ -44,18 +48,18 @@
<?php if (!$ns) { ?>
<div class="mx-a mw-560 mb-16">
<?php if (SEF_MODE) { ?>
<a href="<?php echo $item['namehash']; ?>">
<img class="br-50" src="image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
<a href="/<?php echo $item['namehash']; ?>">
<img class="br-50" src="/image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
</a>
<?php } else { ?>
<a href="?ns=<?php echo $item['namehash']; ?>">
<img class="br-50" src="image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
<a href="/?ns=<?php echo $item['namehash']; ?>">
<img class="br-50" src="/image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
</a>
<?php } ?>
</div>
<?php } ?>
<?php if (!$tx) { ?>
<a class="d-block" href="<?php echo (SEF_MODE ? $item['txid'] : '?tx=' . $item['txid']); ?>">
<a class="d-block" href="/<?php echo (SEF_MODE ? $item['txid'] : '?tx=' . $item['txid']); ?>">
<?php } ?>
<div class="f-s-16 mb-16 of-a">
<?php echo $item['key']; ?>
@ -76,20 +80,20 @@ @@ -76,20 +80,20 @@
<?php if (!$tx && ($newer !== false || $older !== false)) { ?>
<div class="t-center pt-16 pb-27">
<?php if ($newer !== false) { ?>
<a href="<?php echo $newer; ?>">newer</a>
<a href="/<?php echo $newer; ?>"<?php echo $newer ? ' rel="nofollow"' : false; ?>>newer</a>
<?php } ?>
<?php if ($newer !== false && $older !== false) { ?>
|
<?php } ?>
<?php if ($older !== false) { ?>
<a href="<?php echo $older; ?>">older</a>
<a href="/<?php echo $older; ?>"<?php echo $older ? ' rel="nofollow"' : false; ?>>older</a>
<?php } ?>
</div>
<?php } ?>
<div class="t-center px-16 pb-27">
<form name="namespace" action="/" method="GET">
<input class="p-8" type="text" name="q" value="<?php echo ($query ? $query : ''); ?>" placeholder="key, value, block, ns, txid" autocomplete="off" />
<button class="p-8 cursor-pointer" type="submit">Search</button>
<!--<button class="p-8 cursor-pointer" type="submit">Search</button>-->
</form>
</div>
<div class="t-center px-16 pb-27">

2
public/robots.txt

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
User-Agent: *
Sitemap: https://kvazar.today/sitemap.xml
Loading…
Cancel
Save