minor fixes
This commit is contained in:
parent
daace699a6
commit
2ce4424db7
20 changed files with 674 additions and 621 deletions
|
@ -1,32 +1,41 @@
|
|||
<?php
|
||||
require(__DIR__ . "/test_secret.php");
|
||||
|
||||
function auth($token) {
|
||||
if (is_null($token)) return null;
|
||||
require(__DIR__ . "/test_secret.php");
|
||||
|
||||
global $db;
|
||||
function auth($token)
|
||||
{
|
||||
if (is_null($token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.token WHERE token = ?");
|
||||
$stmt->execute([$token]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) return null;
|
||||
|
||||
$username = $result['username'];
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.auth WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) return null;
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.ban WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) return $username;
|
||||
|
||||
$reason = $result['reason']; ?>
|
||||
global $db;
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.token WHERE token = ?");
|
||||
$stmt->execute([$token]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$username = $result['username'];
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.auth WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.ban WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$result) {
|
||||
return $username;
|
||||
}
|
||||
|
||||
$reason = $result['reason']; ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
@ -35,9 +44,9 @@
|
|||
</body>
|
||||
</html>
|
||||
<?php die();
|
||||
}
|
||||
|
||||
if (array_key_exists('token',$_COOKIE)) {
|
||||
$username = auth($_COOKIE['token']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('token', $_COOKIE)) {
|
||||
$username = auth($_COOKIE['token']);
|
||||
}
|
||||
?>
|
||||
|
|
155
libs/comment.php
155
libs/comment.php
|
@ -1,42 +1,49 @@
|
|||
<?php
|
||||
require(__DIR__ . "/markdown.php");
|
||||
function comments($typer, $idr, $disable = false) {
|
||||
$ref = 1732684297;
|
||||
global $username;
|
||||
global $db;
|
||||
$page = array_key_exists('page',$_GET) ? ($_GET['page']) : 0;
|
||||
$mode = array_key_exists('mode',$_GET) ? ($_GET['mode']) : 'all';
|
||||
if ($username && !$disable) {
|
||||
form("Broadcast your thoughts...", '', array(
|
||||
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => ''),
|
||||
array('key' => '','type' => 'hidden','name' => 'type', 'default' => $typer),
|
||||
array('key' => '','type' => 'hidden','name' => 'id', 'default' => $idr),
|
||||
array('key' => 'Attachments', 'type' => 'file', 'name' => 'file', 'default' => '')
|
||||
),'/api/comment.php');
|
||||
}
|
||||
require(__DIR__ . "/markdown.php");
|
||||
function comments($typer, $idr, $disable = false)
|
||||
{
|
||||
$ref = 1732684297;
|
||||
global $username;
|
||||
global $db;
|
||||
$page = array_key_exists('page', $_GET) ? ($_GET['page']) : 0;
|
||||
$mode = array_key_exists('mode', $_GET) ? ($_GET['mode']) : 'all';
|
||||
if ($username && !$disable) {
|
||||
form("Broadcast your thoughts...", '', array(
|
||||
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => ''),
|
||||
array('key' => '','type' => 'hidden','name' => 'type', 'default' => $typer),
|
||||
array('key' => '','type' => 'hidden','name' => 'id', 'default' => $idr),
|
||||
array('key' => 'Attachments', 'type' => 'file', 'name' => 'file', 'default' => '')
|
||||
), '/api/comment.php');
|
||||
}
|
||||
|
||||
$qs = parse_url($_SERVER['REQUEST_URI']);
|
||||
$qs = parse_url($_SERVER['REQUEST_URI']);
|
||||
|
||||
if (is_null($qs)) $qs = array('query' => '?');
|
||||
$qsq = $qs['query'];
|
||||
if (is_null($qs)) {
|
||||
$qs = array('query' => '?');
|
||||
}
|
||||
$qsq = $qs['query'];
|
||||
|
||||
$qss = array();
|
||||
|
||||
parse_str($qsq,$qss);
|
||||
$qss = array();
|
||||
|
||||
$qss['page'] = $page + 1;
|
||||
$qs_next = http_build_query($qss);
|
||||
$qss['page'] = $page - 1;
|
||||
$qs_prev = http_build_query($qss);
|
||||
$qss['page'] = $page;
|
||||
|
||||
$qss['mode'] = 'all';
|
||||
$qs_1 = http_build_query($qss);
|
||||
parse_str($qsq, $qss);
|
||||
|
||||
$qss['mode'] = 'followers';
|
||||
$qs_2 = http_build_query($qss);
|
||||
?>
|
||||
$qss['page'] = $page + 1;
|
||||
$qs_next = http_build_query($qss);
|
||||
$qss['page'] = $page - 1;
|
||||
$qs_prev = http_build_query($qss);
|
||||
$qss['page'] = $page;
|
||||
|
||||
$qss['mode'] = 'all';
|
||||
$qs_1 = http_build_query($qss);
|
||||
|
||||
$qss['mode'] = 'followers';
|
||||
$qs_2 = http_build_query($qss);
|
||||
?>
|
||||
|
||||
<div>
|
||||
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
|
||||
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
|
||||
</div>
|
||||
<div>
|
||||
<?php if ($page > 0) { ?>
|
||||
<a class="form-button" href="?<?php echo $qs_prev ?>">Previous</a>
|
||||
|
@ -44,60 +51,58 @@
|
|||
<a class="form-button" href="?<?php echo $qs_next ?>">Next</a>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
|
||||
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$posts = array();
|
||||
$posts = array();
|
||||
|
||||
$theId = $idr;
|
||||
$theId = $idr;
|
||||
|
||||
while (true) {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$theId
|
||||
]);
|
||||
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
if (is_null($posts1) || count($posts1) < 1) break;
|
||||
$theId = $posts1[0]['targetid'];
|
||||
$posts = array_merge($posts1,$posts);
|
||||
}
|
||||
while (true) {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
$theId
|
||||
]);
|
||||
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
if (is_null($posts1) || count($posts1) < 1) {
|
||||
break;
|
||||
}
|
||||
$theId = $posts1[0]['targetid'];
|
||||
$posts = array_merge($posts1, $posts);
|
||||
}
|
||||
|
||||
if ($mode == 'all') {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
|
||||
$stmt->execute([
|
||||
$typer,
|
||||
$idr,
|
||||
10,
|
||||
$page * 10
|
||||
]);
|
||||
} else {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? AND username IN (SELECT username FROM main.follow WHERE target = ?) ORDER BY date DESC LIMIT ? OFFSET ?");
|
||||
$stmt->execute([
|
||||
$typer,
|
||||
$idr,
|
||||
$username,
|
||||
10,
|
||||
$page * 10
|
||||
]);
|
||||
}
|
||||
|
||||
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
if ($mode == 'all') {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
|
||||
$stmt->execute([
|
||||
$typer,
|
||||
$idr,
|
||||
10,
|
||||
$page * 10
|
||||
]);
|
||||
} else {
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? AND username IN (SELECT username FROM main.follow WHERE target = ?) ORDER BY date DESC LIMIT ? OFFSET ?");
|
||||
$stmt->execute([
|
||||
$typer,
|
||||
$idr,
|
||||
$username,
|
||||
10,
|
||||
$page * 10
|
||||
]);
|
||||
}
|
||||
|
||||
$edge = count($posts);
|
||||
$posts = array_merge($posts,$posts2);
|
||||
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
?>
|
||||
$edge = count($posts);
|
||||
$posts = array_merge($posts, $posts2);
|
||||
|
||||
?>
|
||||
<meta property="og:title" content="NewBiglyChat" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:url" content="<?php echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ?>" />
|
||||
<meta property="og:description" content="<?php echo htmlspecialchars($posts[$edge - 1]['content']) ?>" />
|
||||
<meta property="og:image" content="https://nbg.dervland.net/img/newlogo.svg" />
|
||||
<?php
|
||||
foreach ($posts as $key => $post) {
|
||||
if ($key == $edge) { ?>
|
||||
foreach ($posts as $key => $post) {
|
||||
if ($key == $edge) { ?>
|
||||
<h2>Replies</h2>
|
||||
<?php } ?>
|
||||
<div class='comment'>
|
||||
|
@ -111,7 +116,7 @@
|
|||
</b></div>
|
||||
<div><b>
|
||||
<a class='link' href='/comment.php?id=<?php echo $post['id'] ?>'>
|
||||
<?php echo date(DATE_RFC2822,$post['date'] + $ref) ?>
|
||||
<?php echo date(DATE_RFC2822, $post['date'] + $ref) ?>
|
||||
</a>
|
||||
</b></div>
|
||||
</div>
|
||||
|
@ -120,5 +125,5 @@
|
|||
<a class="clickie" href="/comment.php?id=<?php echo $post['id']?>"><img class="header-img header-link" src="/img/mail.svg">Replies</a>
|
||||
</div>
|
||||
<?php }
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
function form($title, $form_message, $inputs, $action = '') { ?>
|
||||
function form($title, $form_message, $inputs, $action = '')
|
||||
{ ?>
|
||||
<form class='form' enctype="multipart/form-data" method="POST" action="<?php echo $action ?>">
|
||||
<h1 class="form-heading">
|
||||
<?php echo $title ?>
|
||||
|
@ -8,7 +9,7 @@
|
|||
<?php echo htmlspecialchars($form_message) ?>
|
||||
</span>
|
||||
<?php
|
||||
foreach ($inputs as $kv) { ?>
|
||||
foreach ($inputs as $kv) { ?>
|
||||
<span class='form-key'>
|
||||
<?php echo htmlspecialchars($kv['key']) ?>
|
||||
</span>
|
||||
|
|
|
@ -1,43 +1,44 @@
|
|||
<?php
|
||||
function markdown($text) {
|
||||
$search = array (
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(png|jpg|jpeg|gif))~i',
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(mp3|wav))~i',
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(webm|mp4))~i',
|
||||
//'~(https://studio\.penguinmod\.com/[^\s<?#]*[#]([^\s<]*))~i',
|
||||
//'~(https://studio\.penguinmod\.com/[^\s<?#]*[?#]?([^\s<#]*)[#]?([^\s<]*))~i',
|
||||
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
|
||||
'~(?:@)([^\s]+)(?:\s|$)~i',
|
||||
'~(\[b\])(.*?)(\[\/b\])~i',
|
||||
'~(\[i\])(.*?)(\[\/i\])~i',
|
||||
'~(\[u\])(.*?)(\[\/u\])~i',
|
||||
'~(\[ul\])(.*?)(\[\/ul\])~i',
|
||||
'~(\[li\])(.*?)(\[\/li\])~i',
|
||||
'~(\[h\])(.*?)(\[\/h\])~i',
|
||||
'~(\[url=)(.*?)(\])(.*?)(\[\/url\])~i',
|
||||
'~(\[url\])(.*?)(\[\/url\])~i'
|
||||
);
|
||||
|
||||
$replace = array (
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><img src="$1" class="img"></a>',
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><audio controls src="$1"></a>',
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><video controls class="img"><source src="$1"/></video></a>',
|
||||
//'https://studio.penguinmod.com/?#$2',
|
||||
//'<a class="link" href="$1" target="_blank"><div>$1</div><iframe src="https://studio.penguinmod.com/embed?$2#$3"></iframe></a>',
|
||||
'<a class="link" href="$0" target="_blank">$0</a>',
|
||||
'<a class="link" href="/user.php?id=$1" target="_blank">@$1</a>',
|
||||
'<strong>$2</strong>',
|
||||
'<em>$2</em>',
|
||||
'<u>$2</u>',
|
||||
'<ul>$2</ul>',
|
||||
'<li>$2</li>',
|
||||
'<h2>$2</h2>',
|
||||
'<a class="link" href="$2" target="_blank">$4</a>',
|
||||
'<a class="link" href="$2" target="_blank">$2</a>'
|
||||
);
|
||||
|
||||
$text = preg_replace($search, $replace, $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
function markdown($text)
|
||||
{
|
||||
$search = array(
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(png|jpg|jpeg|gif))~i',
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(mp3|wav))~i',
|
||||
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(webm|mp4))~i',
|
||||
//'~(https://studio\.penguinmod\.com/[^\s<?#]*[#]([^\s<]*))~i',
|
||||
//'~(https://studio\.penguinmod\.com/[^\s<?#]*[?#]?([^\s<#]*)[#]?([^\s<]*))~i',
|
||||
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
|
||||
'~(?:@)([^\s]+)(?:\s|$)~i',
|
||||
'~(\[b\])(.*?)(\[\/b\])~i',
|
||||
'~(\[i\])(.*?)(\[\/i\])~i',
|
||||
'~(\[u\])(.*?)(\[\/u\])~i',
|
||||
'~(\[ul\])(.*?)(\[\/ul\])~i',
|
||||
'~(\[li\])(.*?)(\[\/li\])~i',
|
||||
'~(\[h\])(.*?)(\[\/h\])~i',
|
||||
'~(\[url=)(.*?)(\])(.*?)(\[\/url\])~i',
|
||||
'~(\[url\])(.*?)(\[\/url\])~i'
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><img src="$1" class="img"></a>',
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><audio controls src="$1"></a>',
|
||||
'<a class="link" href="$1" target="_blank"><div>$1</div><video controls class="img"><source src="$1"/></video></a>',
|
||||
//'https://studio.penguinmod.com/?#$2',
|
||||
//'<a class="link" href="$1" target="_blank"><div>$1</div><iframe src="https://studio.penguinmod.com/embed?$2#$3"></iframe></a>',
|
||||
'<a class="link" href="$0" target="_blank">$0</a>',
|
||||
'<a class="link" href="/user.php?id=$1" target="_blank">@$1</a>',
|
||||
'<strong>$2</strong>',
|
||||
'<em>$2</em>',
|
||||
'<u>$2</u>',
|
||||
'<ul>$2</ul>',
|
||||
'<li>$2</li>',
|
||||
'<h2>$2</h2>',
|
||||
'<a class="link" href="$2" target="_blank">$4</a>',
|
||||
'<a class="link" href="$2" target="_blank">$2</a>'
|
||||
);
|
||||
|
||||
$text = preg_replace($search, $replace, $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,43 +1,45 @@
|
|||
<?php
|
||||
require(__DIR__ . "/auth.php");
|
||||
require(__DIR__ . "/auth.php");
|
||||
global $username;
|
||||
function page_header()
|
||||
{
|
||||
global $db;
|
||||
global $username;
|
||||
function page_header() {
|
||||
global $db;
|
||||
global $username;
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
"notification",
|
||||
$username,
|
||||
]);
|
||||
|
||||
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC");
|
||||
$stmt->execute([
|
||||
"notification",
|
||||
$username,
|
||||
]);
|
||||
|
||||
$edge = count($posts2);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>BiglyChat</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1">
|
||||
<link rel="icon" href="/img/bgc.svg">
|
||||
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
$edge = count($posts2);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>BiglyChat</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1">
|
||||
<link rel="icon" href="/img/bgc.svg">
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="/"><img class="header-img header-link" src="/img/bgc.svg">BiglyChat</a>
|
||||
<?php
|
||||
if (isset($username)) { ?>
|
||||
<a href="/user.php?id=<?php echo $username ?>"><img class="header-img header-link" src="/img/home.svg">Home</a>
|
||||
<a href="/notif.php"> <img class="header-img header-link" src="/img/mail.svg"><span>Mail<sub> <?php echo $edge?></sub></span></a>
|
||||
<a href="/logout.php"><img class="header-img header-link" src="/img/logout.svg">Leave</a>
|
||||
<?php } else { ?>
|
||||
<a href="/login.php"><img class="header-img header-link" src="/img/home.svg">Join</a>
|
||||
<?php }
|
||||
?>
|
||||
</div>
|
||||
<?php }
|
||||
function page_footer() { ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php }
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<a href="/"><img class="header-img header-link" src="/img/bgc.svg">BiglyChat</a>
|
||||
<?php if (isset($username)) { ?>
|
||||
<a href="/user.php?id=<?php echo $username ?>"><img class="header-img header-link" src="/pfp/<?php echo $username ?>.png">Wall</a>
|
||||
<a href="/notif.php"> <img class="header-img header-link" src="/img/mail.svg"><span>Mail<sub> <?php echo $edge?></sub></span></a>
|
||||
<a href="/stats.php?username=<?php echo $username ?>"><img class="header-img header-link" src="/img/home.svg">Users</a>
|
||||
<a href="/logout.php"><img class="header-img header-link" src="/img/logout.svg">Leave</a>
|
||||
<?php } else { ?>
|
||||
<a href="/login.php"><img class="header-img header-link" src="/img/home.svg">Join</a>
|
||||
<a href="/stats.php"><img class="header-img header-link" src="/img/home.svg">Users</a>
|
||||
<?php }
|
||||
?>
|
||||
</div>
|
||||
<?php }
|
||||
function page_footer()
|
||||
{ ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php }
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue