From 353db5a8cb4bb14bf791e0ccb205eb26a1583806 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Mon, 5 Apr 2021 15:37:12 +0200 Subject: [PATCH] Added Blog (Articles) minimal CMS --- public/articles/Article.php | 38 +- public/articles/admin.php | 7 +- public/articles/archive.php | 56 +- public/articles/edit.php | 42 + public/articles/home.php | 11 +- public/articles/index.php | 26 +- public/articles/list.php | 72 +- public/articles/view.php | 38 +- public/database/.~lock.TAXREF14.0_ORTHO.csv# | 1 + public/database/TAXREF14.0_ORTHO.csv | 2124 ++++++++++++++++++ public/forum/categories.php | 2 +- public/forum/topics/scripts/editor.js | 60 + public/forum/topics/sendreply.php | 2 +- public/forum/topics/topics.php | 28 +- public/media/icons/cite.svg | 65 + public/media/icons/code.svg | 67 + public/media/icons/dslr.png | Bin 0 -> 15977 bytes public/src/dump_taxref_into_database.php | 33 +- public/styles/style.css | 19 +- public/upload/metadata.php | 6 +- 20 files changed, 2518 insertions(+), 179 deletions(-) create mode 100644 public/articles/edit.php create mode 100644 public/database/.~lock.TAXREF14.0_ORTHO.csv# create mode 100644 public/database/TAXREF14.0_ORTHO.csv create mode 100644 public/forum/topics/scripts/editor.js create mode 100644 public/media/icons/cite.svg create mode 100644 public/media/icons/code.svg create mode 100644 public/media/icons/dslr.png diff --git a/public/articles/Article.php b/public/articles/Article.php index d9575b8..a4e46ff 100644 --- a/public/articles/Article.php +++ b/public/articles/Article.php @@ -1,9 +1,9 @@ id = (int) $data['id']; - if ( isset( $data['publication_date'] ) ) $this->publication_date = (int) $data['publication_date']; - if ( isset( $data['modification_date'] ) ) $this->modification_date = (int) $data['modification_date']; - if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title'] ); - if ( isset( $data['summary'] ) ) $this->summary = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['summary'] ); - if ( isset( $data['content'] ) ) $this->content = $data['content']; - if ( isset( $data['author_id'] ) ) $this->author_id = $data['author_id']; + public function __construct($data=array()) { + if (isset($data['id'])) $this->id = (int) $data['id']; + if (isset($data['publication_date'])) $this->publication_date = (int) $data['publication_date']; + if (isset($data['modification_date'])) $this->modification_date = (int) $data['modification_date']; + if (isset($data['title'])) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title'] ); + if (isset($data['summary'])) $this->summary = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['summary'] ); + if (isset($data['content'])) $this->content = $data['content']; + global $db; + $req = $db->prepare('SELECT id FROM authors WHERE username=:username'); + $req->execute(array( + "username"=>$_SESSION['username'] + )); + if ($data = $req->fetch()) { + if (isset($data['id'])) + $this->author_id = $data['id']; + } } public function storeFormValues($params) { @@ -50,7 +58,7 @@ class Article public static function getById($id) { global $db; - $req = $db->prepare('SELECT *, UNIX_TIMESTAMP(publication_date) AS publication_date FROM articles WHERE id=:id'); + $req = $db->prepare('SELECT *, UNIX_TIMESTAMP(created_on) AS publication_date FROM articles WHERE id=:id'); $req->execute(array( "id"=>$id )); @@ -69,6 +77,7 @@ class Article while ($row = $req->fetch()) { $article = new Article($row); $list[] = $article; + // print_r($article); } return $list; } @@ -78,16 +87,15 @@ class Article trigger_error("Article::insert(): Attempt to insert an Article object that already has its ID property set (to $this->id).", E_USER_ERROR); } global $db; - $req = $db->prepare('INSERT INTO articles (publication_date, modification_date, title, summary, content) VALUES (FROM_UNIXTIME(:publication_date), FROM_UNIXTIME(:modification_date), :title, :summary, :content, :author_id'); + $req = $db->prepare('INSERT INTO articles (created_on, modified_on, title, summary, content, article_by) VALUES (FROM_UNIXTIME(:created_on), FROM_UNIXTIME(:modified_on), :title, :summary, :content, :article_by)'); $req->execute(array( - "publication_date"=>$this->publication_date, - "modification_date"=>$this->modification_date, + "created_on"=>$this->publication_date, + "modified_on"=>$this->modification_date, "title"=>$this->title, "summary"=>$this->summary, "content"=>$this->content, - "author_id"=>$this->author_id + "article_by"=>$this->author_id )); - $this->id = $db->lastInsertedId(); } public function update() { diff --git a/public/articles/admin.php b/public/articles/admin.php index 16d3465..a83b349 100644 --- a/public/articles/admin.php +++ b/public/articles/admin.php @@ -8,7 +8,7 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : ""; if ($username == "") { $_SESSION['error_msg'] = "You need to be logged in as administrator to perform these tasks."; - header("Location: $root/auth/login"); + header("Location: /auth/login"); } switch ($action) { @@ -72,8 +72,9 @@ function delete() { function listArticles() { $results = array(); $data = Article::getList(); - $results['articles'] = $data['results']; - $results['totalRows'] = $data['totalRows']; + // print_r($data); + $results['articles'][] = $data[0]; + // $results['totalRows'] = $data['totalRows']; $results['pageTitle'] = "All Articles"; if (isset($_GET['error'])) { if ($_GET['error'] == "notFound") { diff --git a/public/articles/archive.php b/public/articles/archive.php index aad7a8f..53299f3 100644 --- a/public/articles/archive.php +++ b/public/articles/archive.php @@ -1,43 +1,17 @@ +

Articles Archive

+ +

Article Archive

diff --git a/public/articles/edit.php b/public/articles/edit.php new file mode 100644 index 0000000..0af6c8e --- /dev/null +++ b/public/articles/edit.php @@ -0,0 +1,42 @@ + + + + + + + + Articles | Chiro - Canto + + + + + + +
+

Articles

+
+

Create an article

+
+ + + + + + + +
+ +
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/public/articles/home.php b/public/articles/home.php index d9f2039..f6dcb1c 100644 --- a/public/articles/home.php +++ b/public/articles/home.php @@ -1,21 +1,14 @@ -

Articles Home