Improved the content system
Update content.php, strings.json, and 2 more files...
This commit is contained in:
@@ -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('<div class="card p-0 mx-0"><div class="px-card py-10 border-bottom px-20"><div class="container-fluid">'.
|
||||
'<div class="row"><h2 class="card-title font-size-18 m-0"><i class="fad fa-exclamation-triangle"></i> '.
|
||||
$title.'</h2></div></div></div><div class="px-card py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-20">'.
|
||||
'<h3 class="m-0 font-size-20 text-center font-weight-semi-bold">'.$content.'</h3></div></div>');
|
||||
}
|
||||
|
||||
function startMainCard($iconClasses, $title, $subTitle) {
|
||||
echo('<div class="card p-0 mx-0"><div class="px-card py-10 border-bottom px-20"><div class="container-fluid">'.
|
||||
'<div class="row"><div class="col-4"><h2 class="card-title font-size-18 m-0"><i class="'.$iconClasses.
|
||||
'"></i> '.localize($title).'</h2></div><div class="col-8 text-right font-italic">'.
|
||||
'<h2 class="card-title font-size-18 m-0 text-super-muted">'.$subTitle.'</h2></div></div></div></div>');
|
||||
}
|
||||
|
||||
function endMainCard() {
|
||||
echo('</div>');
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -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",
|
||||
|
@@ -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"
|
||||
]
|
||||
}
|
||||
]
|
@@ -1,5 +1,23 @@
|
||||
<?php set_include_path('../commons/'); include 'config.php'; include 'langs.php'; include 'content.php'?>
|
||||
<?php
|
||||
// Checking if an error occured while loading data and parsing the URL.
|
||||
$content_error_code = 200;
|
||||
if($content_has_error) {
|
||||
if(is_null($requested_tags)) {
|
||||
// Failed to parse URL and detect a default category.
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
$content_error_code = 400;
|
||||
} elseif(is_null($filtered_content_index_data)) {
|
||||
// Failed to get a display type or to extract types.
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
$content_error_code = 400;
|
||||
} else {
|
||||
//Other error. (No article, ...)
|
||||
header("HTTP/1.1 500 Internal Server Error");
|
||||
$content_error_code = 500;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check if it went well, else 503 or something like that.
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@@ -33,12 +51,10 @@
|
||||
<div class="px-card py-10 border-bottom px-20">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h2 class="card-title font-size-18 m-0"><i class="fad fa-debug"></i> Debug</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-card py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-20">
|
||||
<h3 class="m-0 mb-5 font-size-20 text-center font-weight-semi-bold">This page is still under construction !</h3>
|
||||
<p class="m-0 mb-5">REQUEST_URI: <?php echo($_SERVER['REQUEST_URI']); ?></p>
|
||||
@@ -55,37 +71,47 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-0 mx-0">
|
||||
<div class="px-card py-10 border-bottom px-20">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h2 class="card-title font-size-18 m-0">
|
||||
<i class="fad fa-exclamation-triangle"></i> error.content.title.generic
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-card py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-20">
|
||||
<h3 class="m-0 font-size-20 text-center font-weight-semi-bold"><?php echo($content_error_message); ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if($content_error_code != 200) {
|
||||
printErrorCard('error.content.title.generic', $content_error_message);
|
||||
goto content_printing_end;
|
||||
}
|
||||
|
||||
<div class="card p-0 mx-0 d-none">
|
||||
<div class="px-card py-10 border-bottom px-20">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h2 class="card-title font-size-18 m-0"><i class="fad fa-envelope-square"></i> Email</h2>
|
||||
</div>
|
||||
<div class="col-8 text-right font-italic">
|
||||
<h2 class="card-title font-size-18 m-0 text-super-muted">herwin.bozet@gmail.com</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-card py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-20">
|
||||
// Printing the containers
|
||||
if($requested_content_display_type == ContentDisplayType::SEARCH) {
|
||||
startMainCard("fad fa-file-alt", "content.title.search", "subtitle");
|
||||
echo('<div class="py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-0">');
|
||||
for($i = 0; $i < count($filtered_content_index_data); $i++) {
|
||||
if($i > 0) {
|
||||
echo('<div class="sidebar-divider m-20 mx-0"></div>');
|
||||
}
|
||||
echo('<div class="content m-0 mx-20">');
|
||||
echo('<h3 class="font-size-14 font-weight-semi-bold m-0">'.$filtered_content_index_data[$i]["title"][$user_language].'</h3>');
|
||||
echo('</div>');
|
||||
}
|
||||
echo('</div>');
|
||||
|
||||
echo('<div class="px-card py-10 bg-light-lm bg-dark-dm rounded-bottom border-top">'.
|
||||
'<p class="font-size-12 m-0">'.
|
||||
'Card footer here.'.
|
||||
'</p></div>');/**/
|
||||
|
||||
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:
|
||||
?>
|
||||
|
||||
<!--
|
||||
-->
|
||||
|
||||
<!--<div class="px-card py-20 bg-light-lm bg-very-dark-dm rounded-bottom px-20">
|
||||
<form action="mailto:herwin.bozet@gmail.com?subject=Website%20contact%20form%20message" method="post" class="w-full">
|
||||
<div class="form-group">
|
||||
<label for="name">Sender's Name</label>
|
||||
@@ -98,9 +124,7 @@
|
||||
<input class="btn btn-primary mr-10" type="submit" value="Submit">
|
||||
<input class="btn btn-secondary" type="reset" value="Reset">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user