From e117954197fe0f4598720477973dc2cbfd4016a1 Mon Sep 17 00:00:00 2001 From: Herwin Bozet Date: Thu, 9 Dec 2021 10:54:28 +0100 Subject: [PATCH] Improved the content system Update content.php, strings.json, and 2 more files... --- commons/content.php | 26 ++++++- commons/strings.json | 14 +++- content/index.json | 15 ++++ content/index.php | 164 +++++++++++++++++++++++++------------------ 4 files changed, 146 insertions(+), 73 deletions(-) diff --git a/commons/content.php b/commons/content.php index de21078..7846614 100644 --- a/commons/content.php +++ b/commons/content.php @@ -24,12 +24,14 @@ abstract class ContentDisplayType { // Preparing default variables. $requested_content_type = ContentType::NONE; $requested_content_display_type = ContentDisplayType::NONE; -$requested_tags = array(); $content_has_error = false; $_content_error_message_key = "error.content.none"; $content_error_message = ""; $was_item_requested = false; +$requested_tags = NULL; +$filtered_content_index_data = NULL; + // Detecting content type requested. $content_requested_url_part = l10n_url_switch(NULL); @@ -48,12 +50,14 @@ if(str_starts_with($content_requested_url_part, "/blog/")) { // Detecting what kind of item was requested, parsing additional parameters and loading required data. $content_requested_url_part = preg_replace("^\/(blog|programming|electronics)^", "", $content_requested_url_part); +$requested_tags = array(); if($requested_content_type == ContentType::BLOG) { if(str_starts_with($content_requested_url_part, "/article/")) { $requested_content_display_type = ContentDisplayType::ARTICLE; } else { $requested_content_display_type = ContentDisplayType::SEARCH; } + $requested_tags[] = "blog"; } elseif($requested_content_type == ContentType::PROGRAMMING) { // May be changed later if a specific resource is requested and found. $requested_content_display_type = ContentDisplayType::SEARCH; @@ -148,4 +152,24 @@ if($requested_content_display_type == ContentDisplayType::SEARCH) { content_end: $content_error_message = localize($_content_error_message_key); + +// These function are placed here to prevent the main file from becoming impossible to read. +function printErrorCard($title, $content) { + echo('
'. + '

  '. + $title.'

'. + '

'.$content.'

'); +} + +function startMainCard($iconClasses, $title, $subTitle) { + echo('
'. + '

  '.localize($title).'

'. + '

'.$subTitle.'

'); +} + +function endMainCard() { + echo('
'); +} + ?> diff --git a/commons/strings.json b/commons/strings.json index afa840e..04fd843 100644 --- a/commons/strings.json +++ b/commons/strings.json @@ -60,7 +60,12 @@ "error.content.detect.display": "Failed to detect if you requested the category's search page or a specific one.", "error.content.detect.subtype": "Failed to detect the sub-type of content you requested.", "error.content.detect.tags": "Failed to detect the basic tags for the content you requested.", - "error.content.detect.empty": "No content could be found for the given tags." + "error.content.detect.empty": "No content could be found for the given tags.", + + "content.title.error": "$content.title.error", + "content.title.search": "$content.title.search", + "content.title.article": "$content.title.article", + "content.title.application": "$content.title.application" }, "fr": { "home.title.nav": "Accueil", @@ -122,7 +127,12 @@ "error.content.detect.display": "Impossibilité de détecter si une recherche ou page spécifique était demandée.", "error.content.detect.subtype": "Impossibilité de détecter le sous-type de contenu demandé.", "error.content.detect.tags": "Impossibilité de détecter les tags de base du contenu demandé.", - "error.content.detect.empty": "Aucun contenu en rapport avec les tags choisi n'as été trouvé." + "error.content.detect.empty": "Aucun contenu en rapport avec les tags choisi n'as été trouvé.", + + "content.title.error": "$content.title.error", + "content.title.search": "$content.title.search", + "content.title.article": "$content.title.article", + "content.title.application": "$content.title.application" }, "lb": { "home.title.nav": "Doheem", diff --git a/content/index.json b/content/index.json index 7bd06a6..6eda888 100644 --- a/content/index.json +++ b/content/index.json @@ -13,5 +13,20 @@ "tags": [ "programming", "purebasic" ] + }, + { + "id": "test02", + "title": { + "en": "Test article #2", + "fr": "Article de test #2" + }, + "preamble": { + "en": "This is a test article, please ignore it", + "fr": "Ceci est un article de test, veuillez l'ignorer." + }, + "image": "test.jpg", + "tags": [ + "programming", "purebasic" + ] } ] \ No newline at end of file diff --git a/content/index.php b/content/index.php index f67f267..b2e9c3b 100644 --- a/content/index.php +++ b/content/index.php @@ -1,5 +1,23 @@ @@ -16,76 +34,84 @@ - -
- -
-
- -
- -
-
-
-
-
+ +
+ +
+
+ +
+ +
+
+
+

  Debug

-
-
-

This page is still under construction !

-

REQUEST_URI:

-

$requested_content_type:

-

$requested_content_display_type:

-

$requested_tags: []

-

count($requested_tags):

-

$content_has_error:

-

$_content_error_message_key:

-

localize($_content_error_message_key):

-

$content_error_message:

-

$filtered_content_index_data:

-

$content_requested_url_part:

-
-
- -
-
-
-
-
-

-   error.content.title.generic -

-
-
+
+

This page is still under construction !

+

REQUEST_URI:

+

$requested_content_type:

+

$requested_content_display_type:

+

$requested_tags: []

+

count($requested_tags):

+

$content_has_error:

+

$_content_error_message_key:

+

localize($_content_error_message_key):

+

$content_error_message:

+

$filtered_content_index_data:

+

$content_requested_url_part:

-
-

-
-
- -
-
-
-
-
-

  Email

-
-
-

herwin.bozet@gmail.com

-
-
-
-
-
+ + '); + for($i = 0; $i < count($filtered_content_index_data); $i++) { + if($i > 0) { + echo(''); + } + echo('
'); + echo('

'.$filtered_content_index_data[$i]["title"][$user_language].'

'); + echo('
'); + } + echo('
'); + + echo('
'. + '

'. + 'Card footer here.'. + '

');/**/ + + endMainCard(); + } elseif($requested_content_display_type == ContentDisplayType::ARTICLE) { + startMainCard("fad fa-file-alt", "content.title.article", "subtitle"); + endMainCard(); + } elseif($requested_content_display_type == ContentDisplayType::APPLICATION) { + startMainCard("fad fa-file-alt", "content.title.application", "subtitle"); + endMainCard(); + } + + content_printing_end: + ?> + + + +
-
+
- -
- - + +