diff --git a/public/about/index.php b/public/about/index.php index 02c517b..06791f9 100644 --- a/public/about/index.php +++ b/public/about/index.php @@ -28,7 +28,7 @@ include("$root/analytics/matomo.php");

Author

This website is developped with ♥ by Samuel ORTION, a juvenile Geekus biologicus.

Source code

-

This project is available under the GNU Affero GPL v3 license at https://forge.ortion.xyz/UncleSamulus/chiro-canto.

+

This project is available under the GNU Affero GPL v3 license at https://forge.ortion.xyz/Chiro-Canto/chiro-canto.

diff --git a/public/articles/Article.php b/public/articles/Article.php new file mode 100644 index 0000000..d9575b8 --- /dev/null +++ b/public/articles/Article.php @@ -0,0 +1,122 @@ + PDO::ERRMODE_EXCEPTION + )); +} catch (Exception $e) { + die("Error : ".$e->getMessage()); +} + +class Article +{ + public $id = null; + public $publication_date = null; + public $modification_date = null; + public $title = null; + public $summary = null; + public $content = null; + public $author_id = null; + + 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']; + if ( isset( $data['author_id'] ) ) $this->author_id = $data['author_id']; + } + + public function storeFormValues($params) { + $this->__construct($params); + if (isset($params['publication_date'])) { + $publication_date = explode('-', $params['publication_date']); + if(count($publication_date) == 3) { + list($y, $m, $d) = $publication_date; + $this->publication_date = mktime(0, 0, 0, $m, $d, $y); + } + } + } + + public static function getById($id) + { + global $db; + $req = $db->prepare('SELECT *, UNIX_TIMESTAMP(publication_date) AS publication_date FROM articles WHERE id=:id'); + $req->execute(array( + "id"=>$id + )); + if ($data = $req->fetch()) { + return new Article($data); + } + } + + public static function getList($num = 1000000) { + global $db; + $req = $db->prepare('SELECT *, UNIX_TIMESTAMP(created_on) AS publication_date FROM articles ORDER BY created_on DESC LIMIT 5'); + $req->execute();//array( + // "num_rows"=>$num + // )); + $list = array(); + while ($row = $req->fetch()) { + $article = new Article($row); + $list[] = $article; + } + return $list; + } + + public function insert() { + if (! is_null($this->id)) { + 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->execute(array( + "publication_date"=>$this->publication_date, + "modification_date"=>$this->modification_date, + "title"=>$this->title, + "summary"=>$this->summary, + "content"=>$this->content, + "author_id"=>$this->author_id + )); + $this->id = $db->lastInsertedId(); + } + + public function update() { + if (is_null($this->id)) + { + trigger_error("Article::update(): Attempt to update an Article object that does not have its ID property set.", E_USER_ERROR); + } + global $db; + $req = $db->prepare('UPDATE article SET modification_date=FROM_UNIXTIMESTAMP(:modification_date), title=:title, summary=:summary, content=:content WHERE id=:id'); + $req->execute(array( + "modification_date"=>$this->modification_date, + "title"=>$this->title, + "summary"=>$this->summary, + "content"=>$this->content, + "id"=>$this->id + )); + } + + public function delete() { + if (is_null($this->id)) + { + trigger_error( "Article::delete(): Attempt to delete an Article object that does not have its ID property set.", E_USER_ERROR); + } + global $db; + $req = $db->prepare('DELETE FROM articles WHERE id=:id LIMIT 1'); + $req->execute(array( + "id"=>$this->id + )); + } +} + +?> \ No newline at end of file diff --git a/public/articles/admin.php b/public/articles/admin.php new file mode 100644 index 0000000..16d3465 --- /dev/null +++ b/public/articles/admin.php @@ -0,0 +1,89 @@ +storeFormValues($_POST); + $article->insert(); + header("Location: admin.php?status=saved"); + } elseif (isset($_POST['cancel'])) { + header("Location: admin.php"); + } else { + $results['article'] = new Article; + require("edit.php"); + } +} + +function edit() { + $results = array(); + $results['pageTitle'] = "Edit Article"; + $result['form'] = "edit"; + + if (isset($_POST['save'])) { + if (!$article = Article::getById((int)$_POST['id'])) { + header( "Location: admin.php?error=notFound" ); + return; + } + $article->storeFormValues($_POST); + $article->update(); + header("Location: admin.php?status=saved"); + } elseif (isset($_POST['cancel'])) { + header("Location: admin.php"); + } else { + $results['article'] = Article::getById((int)$_GET['article']); + require("edit.php"); + } +} + +function delete() { + if (!$article = Article::getById((int) $_GET['article'])) { + header("Location: admin.php?error=notFound"); + return; + } + $article->delete(); + header("Location: admin.php?status=deleted"); +} + +function listArticles() { + $results = array(); + $data = Article::getList(); + $results['articles'] = $data['results']; + $results['totalRows'] = $data['totalRows']; + $results['pageTitle'] = "All Articles"; + if (isset($_GET['error'])) { + if ($_GET['error'] == "notFound") { + $results['error'] = "Error: Article not found."; + } + } + if ( isset( $_GET['status'] ) ) { + if ( $_GET['status'] == "saved" ) $results['status'] = "Your changes have been saved."; + if ( $_GET['status'] == "deleted" ) $results['status'] = "Article deleted."; + } + require("list.php"); +} +?> diff --git a/public/articles/archive.php b/public/articles/archive.php new file mode 100644 index 0000000..aad7a8f --- /dev/null +++ b/public/articles/archive.php @@ -0,0 +1,43 @@ + + + + + + + + Explore | Chiro - Canto + + + + + + +

Articles Archive

+ +

Article Archive

+ + + + \ No newline at end of file diff --git a/public/articles/config.php b/public/articles/config.php new file mode 100644 index 0000000..c9da791 --- /dev/null +++ b/public/articles/config.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/public/articles/home.php b/public/articles/home.php new file mode 100644 index 0000000..d9f2039 --- /dev/null +++ b/public/articles/home.php @@ -0,0 +1,25 @@ + +

Articles Home

+ +

Article Archive

\ No newline at end of file diff --git a/public/articles/index.php b/public/articles/index.php new file mode 100644 index 0000000..741581d --- /dev/null +++ b/public/articles/index.php @@ -0,0 +1,73 @@ +title . " | Chiro - Canto"; + require("$root/articles/view.php"); +} + +function home() { + $results = array(); + $data = Article::getList(HOMEPAGE_NUM_ARTICLES); + $results['articles'] = $data['results']; + $results['totalRows'] = $data['totalRows']; + $results['pageTitle'] = "Articles | Chiro - Canto"; + require("home.php"); +} +?> + + + + + + + + Articles | Chiro - Canto + + + + + + +
+ +

Articles

+
+

+
+
+ + + + \ No newline at end of file diff --git a/public/articles/list.php b/public/articles/list.php new file mode 100644 index 0000000..39263ef --- /dev/null +++ b/public/articles/list.php @@ -0,0 +1,49 @@ + + + + + + + + Explore | Chiro - Canto + + + + + + +

All Articles

+ +
+ +
+ + + + + + + + + + + + +
Publication DateArticle
publication_date)?> + title?> +
+

New article

+

Return to Homepage

+ + + + \ No newline at end of file diff --git a/public/articles/view.php b/public/articles/view.php new file mode 100644 index 0000000..c1d83e8 --- /dev/null +++ b/public/articles/view.php @@ -0,0 +1,32 @@ + + + + + + + + Explore | Chiro - Canto + + + + + + +

Article

+

title)?>

+
summary)?>
+
content?>
+

Published on publication_date)?>

+

Return to Homepage

+ + + + \ No newline at end of file