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. 39
      public/css/app.css
  8. 31
      public/image.php
  9. 14
      public/index.php
  10. 50
      public/index.phtml
  11. 2
      public/robots.txt

49
README.md

@ -1,5 +1,50 @@
# kvazar-network webapp # kvazar-network webapp
Web-oriented content exploring platform for Kevacoin Blockchain Web-oriented content exploring platform for Kevacoin Blockchain
### demo ### requirements
https://kvazar.ml ```
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', '/');
define('PAGE_LIMIT', 10); define('PAGE_LIMIT', 10);
define('SEF_MODE', false); define('SEF_MODE', false);
define('BASE_URL', 'https://kvazar.today');
define('PAGE_LIMIT', 10);
define('SEF_MODE', true);
define('CACHE_ENABLED', false);
// Database // Database
define('DB_NAME', 'kvazar.dat'); define('DB_NAME', 'kvazar.dat');
define('DB_USERNAME', ''); define('DB_USERNAME', '');

59
crontab/sitemap.php

@ -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 {
private $_spriteZ = 800; 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->_width = $width;
$this->_height = $height; $this->_height = $height;
@ -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); 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) { if ($filter) {
imagefilter($resized, $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(); ob_start();
imagejpeg($resized, null, 100); imagepng($resized);
imagedestroy($resized); imagedestroy($resized);
return ob_get_clean(); return ob_get_clean();
} }

36
library/sqlite.php

@ -16,7 +16,7 @@ class SQLite {
} }
} }
public function getNamespaceName($namehash) { public function getNamespaceValueByNS($ns) {
try { try {
@ -27,13 +27,13 @@ class SQLite {
WHERE `namespace`.`hash` = ? WHERE `namespace`.`hash` = ?
AND `data`.`ns` = "1" AND `data`.`ns` = "1"
AND `data`.`deleted` = "0" -- AND `data`.`deleted` = "0" --
ORDER BY `data`.`blockId` DESC ORDER BY `data`.`blockId` DESC
LIMIT 1'); LIMIT 1');
$query->execute([$namehash]); $query->execute([$ns]);
$result = $query->fetch(); $result = $query->fetch();
@ -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) { public function getData($namehash = false, $txid = false, $search = false, $start = 0, $limit = 10) {
try { try {
@ -65,7 +87,7 @@ class SQLite {
WHERE `data`.`txid` = ? WHERE `data`.`txid` = ?
AND `data`.`ns` = "0" AND `data`.`ns` = "0"
AND `data`.`deleted` = "0" -- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC ORDER BY `block`.`blockId` DESC
@ -88,7 +110,7 @@ class SQLite {
WHERE `namespace`.`hash` = ? WHERE `namespace`.`hash` = ?
AND `data`.`ns` = "0" AND `data`.`ns` = "0"
AND `data`.`deleted` = "0" -- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC ORDER BY `block`.`blockId` DESC
@ -116,7 +138,7 @@ class SQLite {
OR `data`.`txid` LIKE :search) OR `data`.`txid` LIKE :search)
AND `data`.`ns` = "0" AND `data`.`ns` = "0"
AND `data`.`deleted` = "0" -- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC ORDER BY `block`.`blockId` DESC
@ -140,7 +162,7 @@ class SQLite {
JOIN `namespace` ON (`namespace`.`nameSpaceId` = `data`.`nameSpaceId`) JOIN `namespace` ON (`namespace`.`nameSpaceId` = `data`.`nameSpaceId`)
WHERE `data`.`ns` = "0" WHERE `data`.`ns` = "0"
AND `data`.`deleted` = "0" -- AND `data`.`deleted` = "0" --
ORDER BY `block`.`blockId` DESC ORDER BY `block`.`blockId` DESC

39
public/css/app.css

@ -1,8 +1,8 @@
button::-moz-focus-inner { button::-moz-focus-inner {
border: 0; border: 0;
padding: 0; padding: 0;
margin-top:-2px; margin-top:-2px;
margin-bottom: -2px; margin-bottom: -2px;
} }
* { * {
@ -12,12 +12,19 @@ button::-moz-focus-inner {
input, button { input, button {
opacity: 0.8; 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 { body {
color: #E8E8E8; color: #E8E8E8;
background-color: #000; background-color: #18102d;
font-family: Sans-Serif, Arial; font-family: Sans-Serif, Arial;
font-size: 14px; font-size: 14px;
font-weight: normal; font-weight: normal;
@ -88,19 +95,21 @@ img:hover {
} }
.b-g::before { .b-g::before {
content: ""; content: "";
background-image: linear-gradient(to left, #9B94BF, #000); background-image: linear-gradient(to left, #9B94BF, #18102d);
height: 1px; height: 1px;
width: 360px; width: 50%;
display: inline-block; max-width: 360px;
display: inline-block;
} }
.b-g::after { .b-g::after {
content: ""; content: "";
background-image: linear-gradient(to right, #9B94BF, #000); background-image: linear-gradient(to right, #9B94BF, #18102d);
height: 1px; height: 1px;
width: 360px; width: 50%;
display: inline-block; max-width: 360px;
display: inline-block;
} }
.br-50 { .br-50 {

31
public/image.php

@ -1,11 +1,36 @@
<?php <?php
require_once('../config.php');
require_once('../library/icon.php'); require_once('../library/icon.php');
if (isset($_GET['hash'])) { if (isset($_GET['hash'])) {
$icon = new Icon(); $hash = md5($_GET['hash']);
header("Content-Type: image/jpeg"); $width = isset($_GET['width']) ? (int) $_GET['width'] : 60;
echo $icon->generateImageResource(md5($_GET['hash']), 60, 60, false); $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();
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');
require_once('../library/icon.php'); require_once('../library/icon.php');
require_once('../library/sqlite.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; $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; $tx = isset($_GET['tx']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['tx']) : false;
$page = (int) isset($_GET['page']) ? $_GET['page'] : 0; $page = (int) isset($_GET['page']) ? $_GET['page'] : 0;
@ -41,8 +41,18 @@ if ($page > 0) {
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD); $db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
if ($ns) { if ($ns) {
$namespaceValue = $db->getNamespaceName($ns);
$namespaceHash = $ns;
$namespaceValue = $db->getNamespaceValueByNS($ns);
} else if ($tx) {
$namespaceHash = $db->getNamespaceHashByTX($tx);
$namespaceValue = $db->getNamespaceValueByNS($namespaceHash);
} else { } else {
$namespaceHash = false;
$namespaceValue = false; $namespaceValue = false;
} }

50
public/index.phtml

@ -1,24 +1,28 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <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 charset="UTF-8" />
<meta name="description" content="Open Source Content Exploring Platform for Kevacoin Blockchain" /> <meta name="description" content="Open Source Content Exploring Platform for Kevacoin Blockchain" />
<base href="<?php echo BASE_URL; ?>" /> <?php if ($namespaceHash) { ?>
<?php if ($ns) { ?> <link rel="icon" type="image/png" href="/image.php?hash=<?php echo $namespaceHash; ?>&radius=30" />
<?php if ($page) { ?>
<title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | PART <?php echo $page; ?> | KVAZAR</title>
<?php } else { ?>
<title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | KVAZAR</title>
<?php } ?> <?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 } else { ?>
<?php if ($page) { ?> <?php if ($page) { ?>
<title>KVAZAR | PART <?php echo $page; ?></title> <title>KVAZAR | PART <?php echo $page; ?></title>
<?php } else if ($tx) { ?> <meta name="robots" content="noindex,follow" />
<title><?php echo $tx && isset($data[0]['key']) ? $data[0]['key'] : $tx; ?> | KVAZAR</title> <?php } else if ($tx) { ?>
<?php } else { ?> <title><?php echo $tx && isset($data[0]['key']) ? $data[0]['key'] : $tx; ?> | <?php echo ($namespaceValue ? $namespaceValue : ($namespaceHash ? $namespaceHash : false)); ?> | KVAZAR</title>
<title>KVAZAR | Observe Kevacoin Universe</title> <?php } else { ?>
<?php } ?> <title>KVAZAR | TODAY</title>
<?php } ?>
<?php } ?> <?php } ?>
</head> </head>
<body> <body>
@ -29,7 +33,7 @@
</div> </div>
<?php if ($ns) { ?> <?php if ($ns) { ?>
<div class="mx-a mw-560 px-16 pb-16"> <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> </div>
<?php } ?> <?php } ?>
<div class="mb-36 c-1"><?php echo $namespaceValue ? $namespaceValue : 'Observe Kevacoin Universe'; ?></div> <div class="mb-36 c-1"><?php echo $namespaceValue ? $namespaceValue : 'Observe Kevacoin Universe'; ?></div>
@ -44,18 +48,18 @@
<?php if (!$ns) { ?> <?php if (!$ns) { ?>
<div class="mx-a mw-560 mb-16"> <div class="mx-a mw-560 mb-16">
<?php if (SEF_MODE) { ?> <?php if (SEF_MODE) { ?>
<a href="<?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']; ?>" /> <img class="br-50" src="/image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
</a> </a>
<?php } else { ?> <?php } else { ?>
<a href="?ns=<?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']; ?>" /> <img class="br-50" src="/image.php?hash=<?php echo $item['namehash']; ?>" alt="<?php echo $item['namehash']; ?>" />
</a> </a>
<?php } ?> <?php } ?>
</div> </div>
<?php } ?> <?php } ?>
<?php if (!$tx) { ?> <?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 } ?> <?php } ?>
<div class="f-s-16 mb-16 of-a"> <div class="f-s-16 mb-16 of-a">
<?php echo $item['key']; ?> <?php echo $item['key']; ?>
@ -76,20 +80,20 @@
<?php if (!$tx && ($newer !== false || $older !== false)) { ?> <?php if (!$tx && ($newer !== false || $older !== false)) { ?>
<div class="t-center pt-16 pb-27"> <div class="t-center pt-16 pb-27">
<?php if ($newer !== false) { ?> <?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 } ?>
<?php if ($newer !== false && $older !== false) { ?> <?php if ($newer !== false && $older !== false) { ?>
| |
<?php } ?> <?php } ?>
<?php if ($older !== false) { ?> <?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 } ?> <?php } ?>
</div> </div>
<?php } ?> <?php } ?>
<div class="t-center px-16 pb-27"> <div class="t-center px-16 pb-27">
<form name="namespace" action="/" method="GET"> <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" /> <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> </form>
</div> </div>
<div class="t-center px-16 pb-27"> <div class="t-center px-16 pb-27">

2
public/robots.txt

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