Added content filtering, Removed old files
Update strings.json, blog-listing.php, and 5 more files...
This commit is contained in:
@@ -4,4 +4,5 @@ $host = "nibblepoker.lu";
|
|||||||
$host_uri = "https://nibblepoker.lu";
|
$host_uri = "https://nibblepoker.lu";
|
||||||
$dir_commons = dirname(__FILE__);
|
$dir_commons = dirname(__FILE__);
|
||||||
$dir_root = realpath($dir_commons . "/../");
|
$dir_root = realpath($dir_commons . "/../");
|
||||||
|
$dir_content = realpath($dir_commons . "/../" . "content/");
|
||||||
?>
|
?>
|
@@ -2,6 +2,8 @@
|
|||||||
<?php
|
<?php
|
||||||
// TODO: Include lang once
|
// TODO: Include lang once
|
||||||
|
|
||||||
|
// TODO: Add /content as raw input of some sort (No auto tags).
|
||||||
|
|
||||||
// This helper requires PHP 8 or newer !
|
// This helper requires PHP 8 or newer !
|
||||||
|
|
||||||
// Defining constants and enums.
|
// Defining constants and enums.
|
||||||
@@ -74,9 +76,9 @@ if($requested_content_type == ContentType::BLOG) {
|
|||||||
} elseif(str_starts_with($content_requested_url_part, "/docker/")) {
|
} elseif(str_starts_with($content_requested_url_part, "/docker/")) {
|
||||||
$requested_tags[] = "docker";
|
$requested_tags[] = "docker";
|
||||||
} else {
|
} else {
|
||||||
$content_has_error = true;
|
//$content_has_error = true;
|
||||||
$_content_error_message_key = "error.content.detect.subtype";
|
//$_content_error_message_key = "error.content.detect.subtype";
|
||||||
goto content_end;
|
//goto content_end;
|
||||||
}
|
}
|
||||||
} elseif($requested_content_type == ContentType::ELECTRONICS) {
|
} elseif($requested_content_type == ContentType::ELECTRONICS) {
|
||||||
// May be changed later if a specific resource is requested and found.
|
// May be changed later if a specific resource is requested and found.
|
||||||
@@ -90,9 +92,9 @@ if($requested_content_type == ContentType::BLOG) {
|
|||||||
} elseif(str_starts_with($content_requested_url_part, "/ham/")) {
|
} elseif(str_starts_with($content_requested_url_part, "/ham/")) {
|
||||||
$requested_tags[] = "ham";
|
$requested_tags[] = "ham";
|
||||||
} else {
|
} else {
|
||||||
$content_has_error = true;
|
//$content_has_error = true;
|
||||||
$_content_error_message_key = "error.content.detect.subtype";
|
//$_content_error_message_key = "error.content.detect.subtype";
|
||||||
goto content_end;
|
//goto content_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +113,37 @@ if(count($requested_tags) == 0) {
|
|||||||
}
|
}
|
||||||
$content_requested_url_part = preg_replace("^\/(java|python|purebasic|others|ham|iot|experiments|applications|tutorials|tools)^", "", $content_requested_url_part);
|
$content_requested_url_part = preg_replace("^\/(java|python|purebasic|others|ham|iot|experiments|applications|tutorials|tools)^", "", $content_requested_url_part);
|
||||||
|
|
||||||
// TODO: detect specific resource and parameters, and load data.
|
// TODO: Detect specific resource or additional tags and parameters
|
||||||
|
|
||||||
|
if($requested_content_display_type == ContentDisplayType::SEARCH) {
|
||||||
|
// Loading the content index.
|
||||||
|
$content_json = file_get_contents(realpath($dir_content . "/index.json"));
|
||||||
|
$content_index_data = json_decode($content_json, true);
|
||||||
|
unset($content_json);
|
||||||
|
|
||||||
|
// Filtering out unwanted entries.
|
||||||
|
$filtered_content_index_data = array();
|
||||||
|
for($i = 0; $i < count($content_index_data); $i++) {
|
||||||
|
if(count(array_intersect($content_index_data[$i]["tags"], $requested_tags)) == count($requested_tags)) {
|
||||||
|
$filtered_content_index_data[] = $content_index_data[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleaning some variables.
|
||||||
|
unset($content_index_data);
|
||||||
|
unset($content_json);
|
||||||
|
|
||||||
|
// Checking if we found content for the user.
|
||||||
|
if(count($filtered_content_index_data) == 0) {
|
||||||
|
// No relevant article/page were found for the given tags.
|
||||||
|
$content_has_error = true;
|
||||||
|
$_content_error_message_key = "error.content.detect.empty";
|
||||||
|
goto content_end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Get relevant data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
content_end:
|
content_end:
|
||||||
$content_error_message = localize($_content_error_message_key);
|
$content_error_message = localize($_content_error_message_key);
|
||||||
|
@@ -58,7 +58,8 @@
|
|||||||
"error.content.detect.category": "Failed to detect which category of content you requested.",
|
"error.content.detect.category": "Failed to detect which category of content you requested.",
|
||||||
"error.content.detect.display": "Failed to detect if you requested the category's search page or a specific one.",
|
"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.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.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."
|
||||||
},
|
},
|
||||||
"fr": {
|
"fr": {
|
||||||
"home.title.nav": "Accueil",
|
"home.title.nav": "Accueil",
|
||||||
@@ -118,7 +119,8 @@
|
|||||||
"error.content.detect.category": "Impossibilité de détecter la catégorie de contenu demandée.",
|
"error.content.detect.category": "Impossibilité de détecter la catégorie de contenu demandée.",
|
||||||
"error.content.detect.display": "Impossibilité de détecter si une recherche ou page spécifique était demandée.",
|
"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.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.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é."
|
||||||
},
|
},
|
||||||
"lb": {
|
"lb": {
|
||||||
"home.title.nav": "Doheem",
|
"home.title.nav": "Doheem",
|
||||||
|
@@ -1,113 +0,0 @@
|
|||||||
<?php if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) { header('HTTP/1.1 403 Forbidden'); die(); } ?>
|
|
||||||
<div class="content"><?php
|
|
||||||
|
|
||||||
function handleError($errorMessage) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function printBlogPreviewCard($id, $title, $previewPreface, $previewText, $previewImageUrl, $previewImageAlt, $tags, $faIcon) {
|
|
||||||
echo('<div class="card p-0 mx-0"><div class="px-card py-10 border-bottom px-20"><h2 class="card-title font-size-18 m-0 d-inline-block">
|
|
||||||
<span class="text-left"><i class="'.$faIcon.'"></i> '.$title.'</span><span class="text-right"></span></h2></div>');
|
|
||||||
|
|
||||||
echo('<div class="d-flex"><div class="w-100 h-100 m-10 align-self-center"><div class="w-100 h-100 rounded d-flex align-items-center justify-content-center" style="background-color: #5352ed;">
|
|
||||||
<img src="'.$previewImageUrl.'" class="d-block w-100 h-100 rounded" loading="lazy" alt="'.$previewImageAlt.'"></div></div><div class="flex-grow-1 overflow-y-hidden d-flex align-items-center position-relative h-120">
|
|
||||||
<div class="p-10 w-full m-auto">');
|
|
||||||
|
|
||||||
if(!empty($previewPreface)) {
|
|
||||||
echo('<p class="font-size-10 text-dark-lm text-light-dm m-0 mb-5 text-truncate font-weight-medium">'.$previewPreface.'</p>');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($previewText)) {
|
|
||||||
echo('<p class="font-size-12 mt-5 mb-0">'.$previewText.'<br><span class="text-primary text-smoothing-auto-dm d-inline-block">Click here <i class="fa fa-angle-right" aria-hidden="true"></i></span></p>');
|
|
||||||
} else {
|
|
||||||
echo('<p class="font-size-12 mt-5 mb-0"><span class="text-primary text-smoothing-auto-dm d-inline-block">Click here <i class="fa fa-angle-right" aria-hidden="true"></i></span></p>');
|
|
||||||
}
|
|
||||||
|
|
||||||
echo('</div><div class="sponsor-section-card-scroll-block"></div></div></div>');
|
|
||||||
|
|
||||||
echo('<div class="px-card py-10 bg-light-lm bg-very-dark-dm rounded-bottom px-20"><p class="font-size-12 m-0"><i class="fad fa-tags"></i>');
|
|
||||||
foreach($tags as &$tagValue) {
|
|
||||||
echo(' <a href="?c=t&t='.$tagValue.'">#'.$tagValue.'</a>');
|
|
||||||
}
|
|
||||||
echo('</p></div></div>');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Defining globals and constants */
|
|
||||||
const BLOG_ACTION_NONE = "n";
|
|
||||||
const BLOG_ACTION_SEARCH_TAGS = "t";
|
|
||||||
const BLOG_ACTION_SEARCH_AUTHOR = "a";
|
|
||||||
const BLOG_ACTION_SEARCH_DATE = "d";
|
|
||||||
//const BLOG_ACTION_ERROR_SEARCH_TYPE_INVALID = "e";
|
|
||||||
|
|
||||||
const BLOG_PARAM_ACTION = "c";
|
|
||||||
const BLOG_PARAM_ARTICLE_PER_PAGE = "c";
|
|
||||||
const BLOG_PARAM_PAGE = "p";
|
|
||||||
const BLOG_PARAM_SEARCH_PARAM = "s";
|
|
||||||
|
|
||||||
$blog_action = BLOG_ACTION_NONE;
|
|
||||||
$blog_search_parameter = "";
|
|
||||||
$current_page = 0;
|
|
||||||
$article_per_page = 10;
|
|
||||||
|
|
||||||
/* Parsing and verifying arguments */
|
|
||||||
if(count($_GET) > 0) {
|
|
||||||
if(array_key_exists(BLOG_PARAM_ACTION, $_GET)) {
|
|
||||||
$blog_action = $_GET[BLOG_PARAM_ACTION];
|
|
||||||
}
|
|
||||||
if(array_key_exists(BLOG_PARAM_ARTICLE_PER_PAGE, $_GET)) {
|
|
||||||
$article_per_page = $_GET[BLOG_PARAM_ARTICLE_PER_PAGE];
|
|
||||||
}
|
|
||||||
if(array_key_exists(BLOG_PARAM_PAGE, $_GET)) {
|
|
||||||
$current_page = $_GET[BLOG_PARAM_PAGE];
|
|
||||||
}
|
|
||||||
if(array_key_exists(BLOG_PARAM_SEARCH_PARAM, $_GET)) {
|
|
||||||
$blog_search_parameter = $_GET[BLOG_PARAM_SEARCH_PARAM];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!($blog_action == BLOG_ACTION_NONE || $blog_action == BLOG_ACTION_SEARCH_TAGS ||
|
|
||||||
$blog_action == BLOG_ACTION_SEARCH_AUTHOR || $blog_action == BLOG_ACTION_SEARCH_DATE)) {
|
|
||||||
$blog_action = BLOG_ACTION_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!is_numeric($article_per_page)) {
|
|
||||||
$article_per_page = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!is_numeric($current_page)) {
|
|
||||||
$current_page = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loading blog entries */
|
|
||||||
$jsonArticles = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$jsonArticles = file_get_contents("articles.json");
|
|
||||||
$jsonArticles = json_decode($jsonArticles, true);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
|
||||||
$jsonArticles = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($jsonArticles == null) {
|
|
||||||
exit("An error occured during the JSON parsing process...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Printing the articles... */
|
|
||||||
$currentArticleId = 0;
|
|
||||||
$articlesLeft = $article_per_page;
|
|
||||||
|
|
||||||
//TODO: Max value is not right or checked yet !
|
|
||||||
for($currentArticleId = ($article_per_page * $current_page); $currentArticleId < count($jsonArticles); $currentArticleId++) {
|
|
||||||
//echo($jsonArticles[$currentArticleId]["id"]."<br>");
|
|
||||||
printBlogPreviewCard(
|
|
||||||
$jsonArticles[$currentArticleId]["id"],
|
|
||||||
$jsonArticles[$currentArticleId]["title"],
|
|
||||||
$jsonArticles[$currentArticleId]["preview"]["preface"],
|
|
||||||
$jsonArticles[$currentArticleId]["preview"]["text"],
|
|
||||||
$jsonArticles[$currentArticleId]["preview"]["image"],
|
|
||||||
$jsonArticles[$currentArticleId]["preview"]["imageAlt"],
|
|
||||||
$jsonArticles[$currentArticleId]["tags"],
|
|
||||||
$jsonArticles[$currentArticleId]["preview"]["icon"]);
|
|
||||||
}
|
|
||||||
?></div>
|
|
17
content/index.json
Normal file
17
content/index.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "test01",
|
||||||
|
"title": {
|
||||||
|
"en": "Test article",
|
||||||
|
"fr": "Article de test"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
@@ -18,10 +18,12 @@
|
|||||||
<p>$requested_content_type: <?php echo($requested_content_type); ?></p>
|
<p>$requested_content_type: <?php echo($requested_content_type); ?></p>
|
||||||
<p>$requested_content_display_type: <?php echo($requested_content_display_type); ?></p>
|
<p>$requested_content_display_type: <?php echo($requested_content_display_type); ?></p>
|
||||||
<p>$requested_tags: [<?php echo(implode(", ", $requested_tags)); ?>]</p>
|
<p>$requested_tags: [<?php echo(implode(", ", $requested_tags)); ?>]</p>
|
||||||
|
<p>count($requested_tags): <?php echo(count($requested_tags)); ?></p>
|
||||||
<p>$content_has_error: <?php echo($content_has_error); ?></p>
|
<p>$content_has_error: <?php echo($content_has_error); ?></p>
|
||||||
<p>$_content_error_message_key: <?php echo($_content_error_message_key); ?></p>
|
<p>$_content_error_message_key: <?php echo($_content_error_message_key); ?></p>
|
||||||
<p>localize($_content_error_message_key): <?php echo(localize($_content_error_message_key)); ?></p>
|
<p>localize($_content_error_message_key): <?php echo(localize($_content_error_message_key)); ?></p>
|
||||||
<p>$content_error_message: <?php echo($content_error_message); ?></p>
|
<p>$content_error_message: <?php echo($content_error_message); ?></p>
|
||||||
|
<p>$filtered_content_index_data: <?php print_r($filtered_content_index_data); ?></p>
|
||||||
<p>$content_requested_url_part: <?php echo($content_requested_url_part); ?></p>
|
<p>$content_requested_url_part: <?php echo($content_requested_url_part); ?></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
3
content/items/test01.json
Normal file
3
content/items/test01.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user