upload
This commit is contained in:
commit
a54152fcc0
18 changed files with 658 additions and 0 deletions
133
common.php
Executable file
133
common.php
Executable file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
$db = new SQLite3(constant("dbfile"), SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
$db->enableExceptions(true);
|
||||
$db->query('CREATE TABLE IF NOT EXISTS "sites" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"name" VARCHAR NOT NULL,
|
||||
"url" VARCHAR NOT NULL,
|
||||
"summary" VARCHAR NOT NULL,
|
||||
"category" VARCHAR NOT NULL,
|
||||
"time" DATETIME NOT NULL,
|
||||
"nsfw" INTEGER NOT NULL
|
||||
)');
|
||||
function submitSite($name, $url, $summary, $category) {
|
||||
global $db;
|
||||
$stm = $db->prepare('INSERT INTO "sites" ("name", "url", "summary", "category", "time", "nsfw") VALUES (?,?,?,?,?,?)');
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$nsfw = 0;
|
||||
$stm->bindParam(1, $name);
|
||||
$stm->bindParam(2, $url);
|
||||
$stm->bindParam(3, $summary);
|
||||
$stm->bindParam(4, $category);
|
||||
$stm->bindParam(5, $date);
|
||||
$stm->bindParam(6, $nsfw);
|
||||
return $stm->execute();
|
||||
}
|
||||
function getRowCount($cat=null) {
|
||||
global $db;
|
||||
if ($cat) {
|
||||
$stm = $db->prepare('SELECT COUNT(*) as count FROM "sites" WHERE "category" = ? ;');
|
||||
$stm->bindParam(1, $cat);
|
||||
$results = $stm->execute();
|
||||
} else {
|
||||
$stm = $db->prepare('SELECT COUNT(*) as count FROM "sites";');
|
||||
$results = $stm->execute();
|
||||
}
|
||||
$row = $results->fetchArray();
|
||||
return intval($row['count']);
|
||||
}
|
||||
function getRandom() {
|
||||
global $db;
|
||||
$results = $db->query('SELECT * FROM "sites" ORDER BY RANDOM() LIMIT 1;');
|
||||
$row = $results->fetchArray();
|
||||
return $row['url'];
|
||||
}
|
||||
function renderPage($page=1, $cat) {
|
||||
global $db;
|
||||
global $manage;
|
||||
$no = ($page-1) * 15;
|
||||
if ($cat) {
|
||||
$stm = $db->prepare('SELECT * FROM "sites" WHERE "category" = ? ORDER BY "time" DESC LIMIT 15 OFFSET ? ;');
|
||||
$stm->bindParam(1, $cat);
|
||||
$stm->bindParam(2, $no);
|
||||
$results = $stm->execute();
|
||||
} else {
|
||||
$stm = $db->prepare('SELECT * FROM "sites" ORDER BY "time" DESC LIMIT 15 OFFSET ? ;');
|
||||
$stm->bindParam(1, $no);
|
||||
$results = $stm->execute();
|
||||
}
|
||||
while ($row = $results->fetchArray()) {
|
||||
if ($row["nsfw"]) {
|
||||
echo("<tr class='nsfw'>");
|
||||
} else {
|
||||
echo("<tr>");
|
||||
}
|
||||
for ($i=1; $i < 5; $i++) {
|
||||
echo("<td>");
|
||||
if ($i == 1) {
|
||||
if ($manage) {
|
||||
echo ("<p>[<a href='manage.php?delete=" . $row["id"] . "&manage=" . $_GET["manage"] . "'>Delete</a>]");
|
||||
echo (" [<a href='manage.php?nsfw=" . $row["id"] . "&manage=" . $_GET["manage"] . "'>+ NSFW</a>]");
|
||||
echo (" [<a href='manage.php?unnsfw=" . $row["id"] . "&manage=" . $_GET["manage"] . "'>- NSFW</a>]");
|
||||
echo (" [<a href='manage.php?blacklist=" . $row["id"] . "&manage=" . $_GET["manage"] . "'>Blacklist</a>]</p>");
|
||||
}
|
||||
$url = parse_url($row[$i + 1]);
|
||||
if ($url['scheme'] == 'https' || $url['scheme'] == 'http') {
|
||||
echo('<img src="https://icons.duckduckgo.com/ip3/' . $url['host'] . '.ico" class="siteicon"> ');
|
||||
} else {
|
||||
echo("(" . $url['scheme'] . ")");
|
||||
}
|
||||
echo(' <a href="' . $row[$i+1] . '">' . $row[$i] . '</a> ');
|
||||
if ($row["nsfw"]) {
|
||||
echo("<small>(NSFW)</small>");
|
||||
}
|
||||
} elseif ($i ==2) {
|
||||
echo($row[$i+1]);
|
||||
} elseif ($i ==3) {
|
||||
$name = constant("categories")[$row[$i + 1]];
|
||||
echo("<a href='?cat=" . $row[$i+1] . "' rel='noreferrer'>" . $name . "</a>");
|
||||
} else {
|
||||
echo($row[$i+1]);
|
||||
}
|
||||
echo("</td>");
|
||||
}
|
||||
echo("</tr>");
|
||||
}
|
||||
}
|
||||
# manage stuff
|
||||
function deleteSite($id) {
|
||||
global $db;
|
||||
$stm = $db->prepare('DELETE FROM "sites" WHERE id = ?;');
|
||||
$stm->bindParam(1, $id);
|
||||
return $stm->execute();
|
||||
}
|
||||
function markSiteNSFW($id, $nsfw) {
|
||||
global $db;
|
||||
$stm = $db->prepare('UPDATE "sites" SET nsfw = ? WHERE id = ?;');
|
||||
$stm->bindParam(1, $nsfw);
|
||||
$stm->bindParam(2, $id);
|
||||
return $stm->execute();
|
||||
}
|
||||
|
||||
if (isset($_GET["manage"])) {
|
||||
$fh = fopen('secrets/password.secret','r');
|
||||
if (!$fh) {
|
||||
$manage = false;
|
||||
} else {
|
||||
while ($hash = fgets($fh)) {
|
||||
if (password_verify($_GET["manage"], $hash)) {
|
||||
$manage = true;
|
||||
} else {
|
||||
$manage = false;
|
||||
}
|
||||
}
|
||||
fclose($fh);
|
||||
}
|
||||
} else {
|
||||
$manage = false;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue