Add-DAO #14

Merged
tyler merged 3 commits from Add-DAO into master 2022-12-23 21:16:01 +00:00
7 changed files with 158 additions and 40 deletions

28
sql/0-initdatabase.sql Normal file
View File

@ -0,0 +1,28 @@
-- 22-12-22
-- Init the database
START TRANSACTION;
CREATE DATABASE [IF NOT EXISTS] site;
USE site;
CREATE TABLE post(
ID INT AUTO_INCREMENT PRIMARY KEY,
author VARCHAR(32) NOT NULL,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
title VARCHAR(64) NOT NULL,
);
CREATE TABLE tag(
ID INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(32)
);
CREATE TABLE post_tag(
tag_id INT NOT NULL,
post_id INT NOT NULL,
FOREIGN KEY (tag_id) REFERENCES tag(ID) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES post(ID) ON DELETE CASCADE
);
COMMIT;

44
src/common/article.php Normal file
View File

@ -0,0 +1,44 @@
<?php
class Article {
private $client;
// Factory constructors
public static function makeNewClient() : Article {
$host = getenv("MYSQL_HOST");
$db = getenv("MYSQL_DB");
$user = getenv("MYSQL_USER");
$pass = getenv("MYSQL_PASS");
$host = "127.0.0.1";
$db = "site";
$user = "root";
$pass = "password";
return new Article($host, $db, $user, $pass);
}
public static function makeNewClientWithSpecs(String $host,
String $db, String $user, String $pass) : Article {
return new Article($host, $db, $user, $pass);
}
private function __construct(String $host, String $db, String $user, String $pass){
$this->client = mysqli_connect($host, $user, $pass, $db);
}
public function getAllPosts() {
$result = mysqli_query($this->client, 'SELECT * FROM post');
return mysqli_fetch_all($result);
}
public function getMostRecentPosts($limit){
$result = mysqli_query($this->client, 'SELECT * FROM post ORDER BY created DESC LIMIT ' . $limit);
return mysqli_fetch_all($result);
}
public function getPostData($postId) {
$result = mysqli_query($this->client, 'SELECT * FROM post WHERE ID = ' . $postId);
return mysqli_fetch_all($result);
}
}
?>

View File

@ -1,7 +1,15 @@
<?php <?php
function getResumeReleases() {
class Gitea {
private $giteaToken;
public function __construct(String $token) {
$this->giteaToken = $token;
}
public function getResumeReleases() : String {
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . getenv("GITEA_TOKEN")); curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . $this->giteaToken);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
@ -16,9 +24,9 @@ function getResumeReleases() {
} }
function getRecentProjects() { public function getRecentProjects() : array {
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . getenv("GITEA_TOKEN")); curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . $this->giteaToken);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); $result = curl_exec($curl);
@ -44,9 +52,9 @@ function getRecentProjects() {
} }
}
function datecmp($lhs, $rhs) { function datecmp($lhs, $rhs) {
return $lhs["updated_at"] < $rhs["updated_at"]; return $lhs["updated_at"] < $rhs["updated_at"];
} }
?> ?>

View File

@ -2,7 +2,7 @@
<link rel="stylesheet" href="/common/header.css"> <link rel="stylesheet" href="/common/header.css">
<nav class="navbar sticky"> <nav class="navbar sticky">
<a href="/">Home</a> <a href="/">Home</a>
<a href="/resume.php">Resume</a> <a href="/resume">Resume</a>
<a href="https://git.clortox.com">Git</a> <a href="https://git.clortox.com">Git</a>
<a href="/utilities/">Utilities</a> <a href="/utilities/">Utilities</a>
<a href="https://wiki.clortox.com">Wiki</a> <a href="https://wiki.clortox.com">Wiki</a>

View File

@ -31,7 +31,7 @@
text-decoration: none; text-decoration: none;
} }
.git-clickable-div { .list-clickable-div {
display: block; display: block;
width: calc(100% - 10px - 3px); width: calc(100% - 10px - 3px);
height: auto; height: auto;
@ -42,16 +42,31 @@
background-color: rgba(0,0,0,0.4); background-color: rgba(0,0,0,0.4);
margin: 5px; margin: 5px;
} }
.git-clickable-div p {
.list-clickable-div p {
margin: 15px 5px; margin: 15px 5px;
} }
.git-clickable-div:hover { .list-clickable-div:hover {
text-decoration: underline 0.15em rgba(255,255,255,1); text-decoration: underline 0.15em rgba(255,255,255,1);
background-color: rgba(0,0,0,0.85); background-color: rgba(0,0,0,0.85);
} }
.clickable-header {
display: block;
text-decoration-color: rgba(255,255,255,0) !important;
}
.clickable-header h3 {
text-decoration: underline 0.15em rgba(255,255,255,0) !important;
transition: 300ms;
}
.clickable-header h3:hover {
text-decoration: underline 0.15em rgba(255,255,255,1);
}
.single-column { .single-column {
grid-template-columns: 1fr !important; grid-template-columns: 1fr !important;
} }
@ -84,6 +99,7 @@
.index-column { .index-column {
display: grid; display: grid;
grid-template-rows: 10em 1fr; grid-template-rows: 10em 1fr;
width: calc(100% - 3em);
} }

View File

@ -3,6 +3,7 @@
<head> <head>
<?php include 'common/include.php' ?> <?php include 'common/include.php' ?>
<?php include 'common/git.php' ?> <?php include 'common/git.php' ?>
<?php include 'common/article.php' ?>
<title>Tyler Perkins - Home</title> <title>Tyler Perkins - Home</title>
<link rel="stylesheet" href="index.css"> <link rel="stylesheet" href="index.css">
@ -32,7 +33,8 @@
<h3>Projects</h3> <h3>Projects</h3>
<div> <div>
<?php <?php
$result = getRecentProjects(); $giteaClient = new Gitea(getenv("GITEA_TOKEN"));
$result = $giteaClient->getRecentProjects();
array_splice($result, 6, -1); array_splice($result, 6, -1);
foreach($result as $item){ foreach($result as $item){
if($item["private"]) if($item["private"])
@ -44,7 +46,7 @@
$description = $item["description"]; $description = $item["description"];
//build out the html //build out the html
echo '<a class="git-clickable-div" href="' . $url . '">'; echo '<a class="list-clickable-div" href="' . $url . '">';
echo '<p>' . $name . ' - ' . $description . '</p>'; echo '<p>' . $name . ' - ' . $description . '</p>';
echo '</a>'; echo '</a>';
} }
@ -53,7 +55,25 @@
</div> </div>
<div class="index-column"> <div class="index-column">
<h3>Articles</h3> <h3>Articles</h3>
<p>To be implemented</p> <div>
<?php
$articleClient = Article::makeNewClient();
$posts = $articleClient->getMostRecentPosts(5);
foreach($posts as $post){
if($post == null)
continue;
$id = $post[0];
$author = $post[1];
$title = $post[3];
echo '<a class="list-clickable-div" href="/posts/?id=' . $id . '">';
echo '<p>(' . $author . ') ' . $title . '</p>';
echo '</a>';
}
?>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,8 +1,10 @@
<?php <?php
include 'common/git.php'; include '../common/git.php';
$parsed = json_decode(getResumeReleases(), true); $giteaClient = new Gitea(getenv('GITEA_TOKEN'));
$parsed = json_decode($giteaClient->getResumeReleases(), true);
$url = $parsed[0]["assets"][0]["browser_download_url"]; $url = $parsed[0]["assets"][0]["browser_download_url"];
if(!$url){ if(!$url){