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");
This website is developped with ♥ by Samuel ORTION, a juvenile Geekus biologicus.
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.
+ + +summary)?>
+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 @@ + + + +
+ + + +
+ + + +
+ +