code cleanup

This commit is contained in:
2021-04-02 21:58:06 +02:00
parent 4a52ab2fd7
commit eea0aeacc6
67 changed files with 472 additions and 425 deletions

View File

@@ -11,16 +11,16 @@ class EmptyHead extends Head {
protected function initSources() {
}
protected function initMetas() {
protected function initMetas(): array {
return array(
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "";
}
}

View File

@@ -24,9 +24,9 @@ abstract class Head extends View {
}
protected abstract function initSources();
protected abstract function initMetas();
protected abstract function initRawFields();
protected abstract function initTitle();
protected abstract function initMetas(): array;
protected abstract function initRawFields(): array;
protected abstract function initTitle(): string;
protected function init() {
$this->keywords = array();

View File

@@ -3,14 +3,15 @@
namespace Elements;
abstract class SimpleBody extends Body {
public function __construct($document) {
parent::__construct($document);
}
public function getCode() {
public function getCode(): string {
$content = $this->getContent();
return parent::getCode() . "<body>$content</body>";
}
protected abstract function getContent();
protected abstract function getContent(): string;
}

View File

@@ -7,23 +7,25 @@ abstract class View extends StaticView {
private Document $document;
private bool $loadView;
protected bool $searchable;
protected string $reference;
protected string $title;
protected array $langModules;
public function __construct(Document $document, $loadView = true) {
public function __construct(Document $document, bool $loadView = true) {
$this->document = $document;
$this->searchable = false;
$this->reference = "";
$this->title = "Untitled View";
$this->langModules = array();
$this->loadView = $loadView;
}
public function getTitle() { return $this->title; }
public function getDocument() { return $this->document; }
public function isSearchable() { return $this->searchable; }
public function getReference() { return $this->reference; }
public function getTitle(): string { return $this->title; }
public function getDocument(): Document { return $this->document; }
public function isSearchable(): bool { return $this->searchable; }
public function getSiteName(): string {
// what a chain lol
return $this->getDocument()->getUser()->getConfiguration()->getSettings()->getSiteName();
}
protected function load(string $viewClass) : string {
try {
@@ -50,7 +52,7 @@ abstract class View extends StaticView {
// Virtual Methods
public function loadView() { }
public function getCode() {
public function getCode(): string {
// Load translations
$this->loadLanguageModules();
@@ -64,33 +66,33 @@ abstract class View extends StaticView {
}
// UI Functions
private function createList($items, $tag) {
private function createList($items, $tag): string {
if(count($items) === 0)
return "<$tag></$tag>";
else
return "<$tag><li>" . implode("</li><li>", $items) . "</li></$tag>";
}
public function createOrderedList($items=array()) {
public function createOrderedList($items=array()): string {
return $this->createList($items, "ol");
}
public function createUnorderedList($items=array()) {
public function createUnorderedList($items=array()): string {
return $this->createList($items, "ul");
}
protected function createLink($link, $title=null, $classes="") {
protected function createLink($link, $title=null, $classes=""): string {
if(is_null($title)) $title=$link;
if(!empty($classes)) $classes = " class=\"$classes\"";
return "<a href=\"$link\"$classes>$title</a>";
}
protected function createExternalLink($link, $title=null) {
protected function createExternalLink($link, $title=null): string {
if(is_null($title)) $title=$link;
return "<a href=\"$link\" target=\"_blank\" class=\"external\">$title</a>";
}
protected function createIcon($icon, $type = "fas", $classes = "") {
protected function createIcon($icon, $type = "fas", $classes = ""): string {
$iconClass = "$type fa-$icon";
if($icon === "spinner" || $icon === "circle-notch")
@@ -102,39 +104,39 @@ abstract class View extends StaticView {
return "<i class=\"$iconClass\" ></i>";
}
protected function createErrorText($text, $id="", $hidden=false) {
protected function createErrorText($text, $id="", $hidden=false): string {
return $this->createStatusText("danger", $text, $id, $hidden);
}
protected function createWarningText($text, $id="", $hidden=false) {
protected function createWarningText($text, $id="", $hidden=false): string {
return $this->createStatusText("warning", $text, $id, $hidden);
}
protected function createSuccessText($text, $id="", $hidden=false) {
protected function createSuccessText($text, $id="", $hidden=false): string {
return $this->createStatusText("success", $text, $id, $hidden);
}
protected function createSecondaryText($text, $id="", $hidden=false) {
protected function createSecondaryText($text, $id="", $hidden=false): string {
return $this->createStatusText("secondary", $text, $id, $hidden);
}
protected function createInfoText($text, $id="", $hidden=false) {
protected function createInfoText($text, $id="", $hidden=false): string {
return $this->createStatusText("info", $text, $id, $hidden);
}
protected function createStatusText($type, $text, $id="", $hidden=false, $classes="") {
protected function createStatusText($type, $text, $id="", $hidden=false, $classes=""): string {
if(strlen($id) > 0) $id = " id=\"$id\"";
if($hidden) $classes .= " hidden";
if(strlen($classes) > 0) $classes = " $classes";
return "<div class=\"alert alert-$type$hidden$classes\" role=\"alert\"$id>$text</div>";
}
protected function createBadge($type, $text) {
protected function createBadge($type, $text): string {
$text = htmlspecialchars($text);
return "<span class=\"badge badge-$type\">$text</span>";
}
protected function createJumbotron(string $content, bool $fluid=false, $class="") {
protected function createJumbotron(string $content, bool $fluid=false, $class=""): string {
$jumbotronClass = "jumbotron" . ($fluid ? "-fluid" : "");
if (!empty($class)) $jumbotronClass .= " $class";
@@ -148,12 +150,12 @@ abstract class View extends StaticView {
</div>";
}
public function createSimpleParagraph(string $content, string $class="") {
public function createSimpleParagraph(string $content, string $class=""): string {
if($class) $class = " class=\"$class\"";
return "<p$class>$content</p>";
}
public function createParagraph($title, $id, $content) {
public function createParagraph($title, $id, $content): string {
$id = replaceCssSelector($id);
$iconId = urlencode("$id-icon");
return "
@@ -166,7 +168,7 @@ abstract class View extends StaticView {
</div>";
}
protected function createBootstrapTable($data, string $classes="") {
protected function createBootstrapTable($data, string $classes=""): string {
$classes = empty($classes) ? "" : " $classes";
$code = "<div class=\"container$classes\">";
foreach($data as $row) {