From 8ef32e183df3c690048a4edf5f01e1343cd57d34 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Fri, 6 Mar 2020 09:37:56 +0100 Subject: [PATCH] Coded the basics for the blog --- assets/lang/en.php | 5 +++++ assets/lang/fr.php | 5 +++++ config/main.php | 9 ++++++++ index.php | 53 ++++++++++++++++++++++++++++++---------------- lib/articles.php | 41 +++++++++++++++++++++++++++++++++++ lib/db.php | 10 +++++++++ lib/users.php | 30 ++++++++++++++++++++++++++ test.php | 2 ++ views/article.php | 17 +++++++++++++++ views/index.php | 10 +++++++++ views/write.php | 30 ++++++++++++++++++++++++++ 11 files changed, 194 insertions(+), 18 deletions(-) create mode 100755 assets/lang/en.php create mode 100755 assets/lang/fr.php create mode 100755 config/main.php create mode 100644 lib/articles.php create mode 100755 lib/db.php create mode 100644 lib/users.php create mode 100644 test.php create mode 100644 views/article.php create mode 100755 views/index.php create mode 100644 views/write.php diff --git a/assets/lang/en.php b/assets/lang/en.php new file mode 100755 index 0000000..39f2ee8 --- /dev/null +++ b/assets/lang/en.php @@ -0,0 +1,5 @@ + 'Home menu' +); +?> diff --git a/assets/lang/fr.php b/assets/lang/fr.php new file mode 100755 index 0000000..cc6ec21 --- /dev/null +++ b/assets/lang/fr.php @@ -0,0 +1,5 @@ + 'Menu principal' +); +?> diff --git a/config/main.php b/config/main.php new file mode 100755 index 0000000..77c7ac3 --- /dev/null +++ b/config/main.php @@ -0,0 +1,9 @@ + 'My blog', + 'description' => 'Welcome on my wonderful blog', + 'dbHost' => 'localhost', + 'dbUser' => 'usr', + 'dbPasswd' => 'JFZZxF+^}U:SZ<7EE=n!_(gQs', + 'dbName' => 'blog' +); diff --git a/index.php b/index.php index 6fdbfe9..3090cb6 100644 --- a/index.php +++ b/index.php @@ -1,27 +1,44 @@ + - L'étudiant auto-hébergé + <?php echo $config["title"]; ?> -

L'étudiant auto-hébergé - Blog

-

Vous pouvez trouver ici mes billets de blog sur mon quotidien en tant qu'étudiant auto-hébergé.

-
-
-

Nom de l'article

-

Description

-
-
-
-

Nom de l'article

-

Description

-
-
-
-

Nom de l'article

-

Description

-
+

+

+
+ diff --git a/lib/articles.php b/lib/articles.php new file mode 100644 index 0000000..994f9de --- /dev/null +++ b/lib/articles.php @@ -0,0 +1,41 @@ +prepare("SELECT * FROM articles"); + + if($req->execute(array())){ + $list = array(); + + while($data = $req->fetch()) + $list[] = $data; + }else + $list = NULL; + + return $list; +} + +function newArticle($title, $description, $author, $content){ + require("lib/db.php"); + + $req = $db->prepare("INSERT INTO articles (title, description, author, date, content) VALUES (?, ?, ?, NOW(), ?)"); + + if($req->execute(array($title, $description, $author, $content))){ + return true; + } + + return false; +} + +function getArticle($ID){ + require("lib/db.php"); + + $req = $db->prepare("SELECT * FROM articles WHERE ID = ?"); + + if($req->execute(array($ID))){ + if($data = $req->fetch()) + return $data; + } + + return false; +} diff --git a/lib/db.php b/lib/db.php new file mode 100755 index 0000000..aaf0185 --- /dev/null +++ b/lib/db.php @@ -0,0 +1,10 @@ +getMessage() . "
"; + die(); +} +?> diff --git a/lib/users.php b/lib/users.php new file mode 100644 index 0000000..255974f --- /dev/null +++ b/lib/users.php @@ -0,0 +1,30 @@ +prepare("SELECT ID, password FROM users WHERE name = ?"); + if($req->execute(array($login))){ + $data = $req->fetch(); + + if(password_verify($password, $data['password'])){ + return $data['ID']; + }else{ + return NULL; + } + }else{ + return NULL; + } +} + +function getUserName($id){ + require('lib/db.php'); + + $req = $db->prepare("SELECT name FROM users WHERE ID = ?"); + if($req->execute(array($id))){ + $data = $req->fetch(); + + return $data["name"]; + }else{ + return NULL; + } +} diff --git a/test.php b/test.php new file mode 100644 index 0000000..c36d125 --- /dev/null +++ b/test.php @@ -0,0 +1,2 @@ +".$article["title"]."
".$article["content"]."
written by ".$authorName." on ".$article["date"].""; + }else{ + $content = "Article ID is empty"; + } +}else{ + $content = "No article ID set"; +} diff --git a/views/index.php b/views/index.php new file mode 100755 index 0000000..2fefa4b --- /dev/null +++ b/views/index.php @@ -0,0 +1,10 @@ +

".$article["title"]."

".$article["description"]."


"; +} +?> diff --git a/views/write.php b/views/write.php new file mode 100644 index 0000000..8900e6d --- /dev/null +++ b/views/write.php @@ -0,0 +1,30 @@ + + +
+ +
+ +
+ +
+ +
+ + ";