diff --git a/sql/0-initdatabase.sql b/sql/0-initdatabase.sql new file mode 100644 index 0000000..78c97e3 --- /dev/null +++ b/sql/0-initdatabase.sql @@ -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; diff --git a/src/common/article.php b/src/common/article.php new file mode 100644 index 0000000..fe6cee0 --- /dev/null +++ b/src/common/article.php @@ -0,0 +1,44 @@ +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); + } + +} +?> diff --git a/src/common/git.php b/src/common/git.php index ca31a3a..898e2d1 100644 --- a/src/common/git.php +++ b/src/common/git.php @@ -1,52 +1,60 @@ giteaToken = $token; } - curl_close($curl); + public function getResumeReleases() : String { + $curl = curl_init(); + 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); - return $result; + $result = curl_exec($curl); + if(!$result){ + header('HTTP/1.1 500 Internal Server Error'); + die(); + } -} + curl_close($curl); -function getRecentProjects() { - $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_RETURNTRANSFER, 1); + return $result; - $result = curl_exec($curl); - if(!$result){ - header('HTTP/1.1 500 Internal Server Error'); - die(); } - curl_close($curl); - //now we need to parse out the results into a nice array containing the - //most recent items + public function getRecentProjects() : array { + $curl = curl_init(); + 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); - $parsed = json_decode($result, true); + $result = curl_exec($curl); + if(!$result){ + header('HTTP/1.1 500 Internal Server Error'); + die(); + } - $ret = array(); + curl_close($curl); + //now we need to parse out the results into a nice array containing the + //most recent items + + $parsed = json_decode($result, true); + + $ret = array(); + + foreach($parsed as $item){ + array_push($ret, $item); + } + + usort($ret, "datecmp"); + return $ret; - foreach($parsed as $item){ - array_push($ret, $item); } - usort($ret, "datecmp"); - return $ret; - } function datecmp($lhs, $rhs) { return $lhs["updated_at"] < $rhs["updated_at"]; } - - ?> diff --git a/src/common/header.php b/src/common/header.php index 27974dd..9c667a5 100644 --- a/src/common/header.php +++ b/src/common/header.php @@ -2,7 +2,7 @@