123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /*
- * Copyright (C) 2021 Echedey López Romero <elr@disroot.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- class Post {
- private string $Id;
- private string $UserId;
- private string $Title;
- private string $Date;
- private string $Image;
- private string $Content;
- private array $Comments;
- public function __construct(string $Id, string $UserId, string $Title, string $Date, string $Image, string $Content, array $Comments) {
- $this->Id = $Id;
- $this->UserId = $UserId;
- $this->Title = $Title;
- $this->Date = $Date;
- $this->Image = $Image;
- $this->Content = $Content;
- $this->Comments = $Comments;
- }
- public function GetId(): string {
- return $this->Id;
- }
- public function GetUserId(): string {
- return $this->Id;
- }
- public function GetTitle(): string {
- return $this->Title;
- }
- public function GetDate(): string {
- return $this->Date;
- }
- public function GetImage(): string {
- return $this->Image;
- }
- public function GetContent(): string {
- return $this->Content;
- }
- public function GetComments(): array {
- return $this->Comments;
- }
- public function SetId(string $Id): void {
- $this->Id = $Id;
- }
- public function SetUserId(string $Id): void {
- $this->Id = $Id;
- }
- public function SetTitle(string $Title): void {
- $this->Title = $Title;
- }
- function SetDate(string $Date): void {
- $this->Date = $Date;
- }
- public function SetImage(string $Image): void {
- $this->Image = $Image;
- }
- public function SetContent(string $Content): void {
- $this->Content = $Content;
- }
- public function SetComments(array $Comments): void {
- $this->Comments = $Comments;
- }
- public function RenderCard(): string {
- $HTML = '';
- $HTML .= '<div>' . PHP_EOL;
- $HTML .= '<strong><a href=".?post=' . $this->Id . '">' . $this->Title . '</a></strong>' . PHP_EOL;
- $HTML .= '<span>' . $this->Date . '</span>' . PHP_EOL;
- $HTML .= '<div>' . PHP_EOL;
- $HTML .= substr($this->Content, 0, 60) . ' ...' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- return $HTML;
- }
- public function RenderComplete(string $UserName, array $UserNamesList, array $CommentsList): string {
- $HTML = '';
- $HTML .= '<div>' . PHP_EOL;
- $HTML .= '<h2>' . $this->Title . '</h2>' . PHP_EOL;
- $HTML .= '<span><a href=".?user=' . $this->UserId . '">' . $UserName . '</a></span>' . PHP_EOL;
- $HTML .= '<span>' . $this->Date . '</span>' . PHP_EOL;
- $HTML .= '<img src="' . $this->Image . '" alt="Post image"/>' . PHP_EOL;
- $HTML .= '<div>' . PHP_EOL;
- $HTML .= $this->Content . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= '<div>' . PHP_EOL;
- $HTML .= '<h3>Comments</h3>' . PHP_EOL;
- if (count($CommentsList) !== 0) {
- for ($Position = 0; $Position < count($CommentsList); $Position++) {
- $Comment = $CommentsList[$Position];
- $UserName = $UserNamesList[$Position];
- $HTML .= $Comment->Render($UserName);
- }
- } else {
- $HTML .= '<span>' . $CommentsList . '</span>'. PHP_EOL;
- }
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- return $HTML;
- }
- }
|