Slimmed down the content section's code, Added images.

Update .htaccess, content.php, and 16 more files...
This commit is contained in:
2022-04-15 02:22:40 +02:00
parent ccf4134cff
commit de7bb68b49
18 changed files with 4426 additions and 156 deletions

View File

@@ -77,7 +77,8 @@ RewriteRule ^lb/(.*)$ /$1 [QSA]
#RewriteRule ^((en|fr|lb)/)?electronics/(iot|experiments)/(.*)$ /content/$1 [QSA]
# Content pages. (Old regex are taken care of by the "content/index.php" page)
RewriteRule ^((en|fr|lb)/)?(blog|programming|electronics)/(.*)$ /content/$1 [QSA]
#RewriteRule ^((en|fr|lb)/)?(blog|programming|electronics|projects)/(.*)$ /content/$1 [QSA]
#RewriteRule ^((en|fr|lb)/)?(content)/(.*)$ /content/$1 [QSA]
# Internal redirections for scanning and exploit attempts.
# These rules are here since they're easier to implement in the .htaccess.

View File

@@ -8,128 +8,64 @@ if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
// Importing required scripts
include_once 'langs.php';
$CONTENT_DEBUG = true;
// TODO: Add /content as raw input of some sort (No auto tags).
// This helper requires PHP 8 or newer !
$SHOW_CONTENT_DEBUG_CARD = true;
// Defining constants and enums.
const CONTENT_NONE = 0;
abstract class ContentType {
const NONE = CONTENT_NONE;
const BLOG = 1;
const PROGRAMMING = 2;
const ELECTRONICS = 3;
}
abstract class ContentDisplayType {
const NONE = CONTENT_NONE;
const NONE = 0;
const SEARCH = 1;
const ARTICLE = 2;
const APPLICATION = 3;
const CONTENT = 2;
}
// Preparing default variables.
$requested_content_type = ContentType::NONE;
$requested_content_display_type = ContentDisplayType::NONE;
$content_has_error = false;
$_content_error_message_key = "error.content.none";
$content_error_message_key = "error.content.none";
$content_error_message = "";
$was_item_requested = false;
$requested_tags = NULL;
$requested_tags = array();
$raw_additional_tags = "";
$filtered_content_index_data = NULL;
// Detecting content type requested.
$content_requested_url_part = l10n_url_switch(NULL);
// Detecting content display type requested.
$content_requested_url_part = explode("?", explode("#", preg_replace("^\/(content)^", "", l10n_url_switch(NULL)))[0])[0];
if(str_starts_with($content_requested_url_part, "/blog/")) {
$requested_content_type = ContentType::BLOG;
} elseif(str_starts_with($content_requested_url_part, "/programming/")) {
$requested_content_type = ContentType::PROGRAMMING;
} elseif(str_starts_with($content_requested_url_part, "/electronics/")) {
$requested_content_type = ContentType::ELECTRONICS;
if(strcmp($content_requested_url_part, "/") == 0) {
$requested_content_display_type = ContentDisplayType::SEARCH;
} else {
// Failed to detect which category of content was requested.
$content_has_error = true;
$_content_error_message_key = "error.content.detect.category";
goto content_end;
$requested_content_display_type = ContentDisplayType::CONTENT;
$content_requested_url_part = ltrim($content_requested_url_part, "/");
}
// 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;
$requested_tags[] = "programming";
if(str_starts_with($content_requested_url_part, "/applications/")) {
$requested_tags[] = "application";
} elseif(str_starts_with($content_requested_url_part, "/tutorials/")) {
$requested_tags[] = "tutorial";
} elseif(str_starts_with($content_requested_url_part, "/tools/")) {
$requested_tags[] = "tool";
} elseif(str_starts_with($content_requested_url_part, "/purebasic/")) {
$requested_tags[] = "purebasic";
} elseif(str_starts_with($content_requested_url_part, "/python/")) {
$requested_tags[] = "python";
} elseif(str_starts_with($content_requested_url_part, "/java/")) {
$requested_tags[] = "java";
} elseif(str_starts_with($content_requested_url_part, "/others/")) {
$requested_tags[] = "miscellaneous";
} elseif(str_starts_with($content_requested_url_part, "/docker/")) {
$requested_tags[] = "docker";
} else {
//$content_has_error = true;
//$_content_error_message_key = "error.content.detect.subtype";
//goto content_end;
}
} elseif($requested_content_type == ContentType::ELECTRONICS) {
// May be changed later if a specific resource is requested and found.
$requested_content_display_type = ContentDisplayType::SEARCH;
$requested_tags[] = "electronic";
if(str_starts_with($content_requested_url_part, "/iot/")) {
$requested_tags[] = "iot";
} elseif(str_starts_with($content_requested_url_part, "/experiments/")) {
$requested_tags[] = "experiment";
} elseif(str_starts_with($content_requested_url_part, "/ham/")) {
$requested_tags[] = "ham";
} else {
//$content_has_error = true;
//$_content_error_message_key = "error.content.detect.subtype";
//goto content_end;
}
}
// Checking for errors preliminarily
if($requested_content_display_type == ContentDisplayType::NONE) {
// Failed to detect what kind of content was requested.
$content_has_error = true;
$_content_error_message_key = "error.content.detect.display";
goto content_end;
}
// TODO: Check with a raw root type if not set
if(count($requested_tags) == 0) {
// Failed to detect the subtype of content requested when not a blog post.
$content_has_error = true;
$_content_error_message_key = "error.content.detect.tags";
goto content_end;
}
$content_requested_url_part = preg_replace("^\/(java|python|purebasic|others|ham|iot|experiments|applications|tutorials|tools)^", "", $content_requested_url_part);
// TODO: Detect specific resource or additional tags and parameters
if($requested_content_display_type == ContentDisplayType::SEARCH) {
// Checking if more tags were given
if(isset($_GET['tags'])) {
$raw_additional_tags = htmlspecialchars($_GET['tags']);
// Checking the length to prevent bad requests
if(strlen($raw_additional_tags) > 256) {
$content_has_error = true;
$content_error_message_key = "error.content.tags.length";
goto content_end;
}
// Extracting the additional tags safely
$raw_additional_tags_exploded = explode(";", $raw_additional_tags);
for($i = 0; $i < count($raw_additional_tags_exploded); $i++) {
if(strlen($raw_additional_tags_exploded[$i]) > 0) {
if(ctype_alnum($raw_additional_tags_exploded[$i])) {
$requested_tags[] = $raw_additional_tags_exploded[$i];
} else {
$content_has_error = true;
$content_error_message_key = "error.content.tags.alphanumeric";
goto content_end;
}
}
}
unset($raw_additional_tags_exploded);
}
// Loading the content index.
$content_json = file_get_contents(realpath($dir_content . "/index.json"));
$content_index_data = json_decode($content_json, true);
@@ -151,23 +87,23 @@ if($requested_content_display_type == ContentDisplayType::SEARCH) {
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";
$content_error_message_key = "error.content.detect.empty";
goto content_end;
}
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
// Attempting to get the requested ID.
}
// TODO: Get relevant data
content_end:
$content_error_message = localize($_content_error_message_key);
$content_error_message = localize($content_error_message_key);
// These function are placed here to prevent the main file from becoming impossible to read.
// These functions are placed here to prevent the main file from becoming impossible to read.
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>&nbsp;&nbsp;'.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>');
echo('<div class="card p-0 mx-0"><div class="px-card py-10 border-bottom px-20"><div class="container-fluid">');
echo('<div class="row"><div class="col-4"><h2 class="card-title font-size-18 m-0">');
echo('<i class="'.$iconClasses.'"></i>&nbsp;&nbsp;'.localize($title).'</h2></div>');
echo('<div class="col-8 text-right font-italic"><h2 class="card-title font-size-18 m-0 text-super-muted">'.$subTitle.'</h2>');
echo('</div></div></div></div>');
}
function endMainCard() {

View File

@@ -23,33 +23,33 @@ if(!isset($SIDEBAR_ID)) {
<?php print(localize("home.title.nav")); ?>
</a>
<div class="sidebar-divider"></div>
<a id="sbl-programming" href="<?php print(l10n_url_abs('/programming/')); ?>" class="sidebar-link sidebar-link-with-icon<?php if($SIDEBAR_ID=="blog"){echo(" active");} ?>">
<a id="sbl-programming" href="<?php print(l10n_url_abs('/content/')); ?>" class="sidebar-link sidebar-link-with-icon<?php if($SIDEBAR_ID=="blog"){echo(" active");} ?>">
<span class="sidebar-icon"><i class="fad fa-briefcase"></i></span>
<?php print(localize("programming.title.projects")); ?>
</a>
<div class="ml-20">
<a id="sbl-projects-apps" href="<?php print(l10n_url_abs('/programming/applications/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-projects-apps" href="<?php print(l10n_url_abs('/content/?tags=application')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fad fa-browser"></i></span>
<?php print(localize("programming.apps.title")); ?>
</a>
<a id="sbl-projects-tutorials" href="<?php print(l10n_url_abs('/programming/tutorials/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-projects-tutorials" href="<?php print(l10n_url_abs('/content/?tags=tutorial')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fad fa-books"></i></span>
<?php print(localize("programming.tutorials.title")); ?>
</a>
<a id="sbl-projects-tools" href="<?php print(l10n_url_abs('/programming/tools/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-projects-tools" href="<?php print(l10n_url_abs('/content/?tags=tool')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fad fa-tools"></i></span>
<?php print(localize("programming.tools.title")); ?>
</a>
<div class="sidebar-divider"></div>
<a id="sbl-purebasic" href="<?php print(l10n_url_abs('/programming/purebasic/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-purebasic" href="<?php print(l10n_url_abs('/content/?tags=purebasic')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fad fa-microchip"></i></span>
<?php print(localize("programming.purebasic.title")); ?>
</a>
<a id="sbl-python" href="<?php print(l10n_url_abs('/programming/python/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-python" href="<?php print(l10n_url_abs('/content/?tags=python')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fab fa-python"></i></span>
<?php print(localize("programming.python.title")); ?>
</a>
<a id="sbl-docker" href="<?php print(l10n_url_abs('/programming/docker/')); ?>" class="sidebar-link sidebar-link-with-icon">
<a id="sbl-docker" href="<?php print(l10n_url_abs('/content/?tags=docker')); ?>" class="sidebar-link sidebar-link-with-icon">
<span class="sidebar-icon"><i class="fab fa-docker"></i></span>
<?php print(localize("programming.docker.title")); ?>
</a>

View File

@@ -102,6 +102,9 @@
"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.tags.length": "The \"tags\" URL parameter is too long.",
"error.content.tags.alphanumeric": "One of the tags given in the \"tags\" URL parameter is not a valid alphanumeric string.",
"error.content.detect.type": "The type of requested content couldn't be determined.",
"content.title.error": "$content.title.error",
"content.title.search": "Projects search",
@@ -224,6 +227,9 @@
"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.tags.length": "Le paramètre d'URL \"tags\" est trop long.",
"error.content.tags.alphanumeric": "Un des tags donné dans le paramètre d'URL \"tags\" n'est pas une chaîne de texte alphanumérique valide.",
"error.content.detect.type": "Le type de contenu désiré n'as pas pu être détecté.",
"content.title.error": "$content.title.error",
"content.title.search": "Recherche de projets",

3
content/.htaccess Normal file
View File

@@ -0,0 +1,3 @@
# Redirecting any URL that starts with "/content" to the root of this folder.
RewriteEngine On
RewriteRule ^(.*) index.php [NC]

View File

@@ -11,7 +11,7 @@
},
"image": "/resources/Azias/imgs/angry-alchool-pussy.png",
"tags": [
"programming", "purebasic"
"test", "programming", "purebasic"
]
},
{
@@ -26,22 +26,22 @@
},
"image": "test.jpg",
"tags": [
"programming", "docker"
"test", "programming", "docker"
]
},
{
"id": "test03",
"id": "lscom-cli",
"title": {
"en": "ListComPort - COM port enumerator",
"fr": "ListComPort - Enumérateur de port COM"
"en": "PB-ListComPort - CLI COM port enumerator",
"fr": "PB-ListComPort - Enumérateur de port COM pour invité de commande"
},
"preamble": {
"en": "A simple cli tool that can list COM ports with their full name easily and cleanly.<br>This tool is intended to replace the tedious task of having to use the <code>mode</code> command, and the <i>Device Manager</i> to find a newly plugged-in device that provides a COM port.",
"en": "A simple tool that can list COM ports with their name, friendly name and device name easily and cleanly.<br>This tool is intended to replace the tedious task of having to use the <code>mode</code> command, and the <i>Device Manager</i> to find a newly plugged-in device that provides a COM port.",
"fr": "..."
},
"image": "/resources/Azias/imgs/lscom-v2-text-01.png",
"image": "/resources/Azias/imgs/lscom-v2-text-01-bkgd-cli.png",
"tags": [
"programming", "docker"
"application", "lscom", "purebasic"
]
}
]

View File

@@ -5,11 +5,6 @@ include_once 'config.php';
include_once 'langs.php';
include_once 'content.php';
// Safety check for the constants
/*if(!defined('CONTENT_DEBUG')) {
$CONTENT_DEBUG = false;
}/**/
// Checking if an error occurred while loading data and parsing the URL.
$content_error_code = 200;
if($content_has_error) {
@@ -27,8 +22,6 @@ if($content_has_error) {
$content_error_code = 500;
}
}
// TODO: Check if it went well, else 503 or something like - Done above ?. - What is this shit supposed to mean ?!?
?>
<!DOCTYPE html>
<html lang="<?php echo($user_language); ?>">
@@ -57,7 +50,7 @@ if($content_has_error) {
</div>
<div class="content mx-auto w-lg-p90">
<?php
if($CONTENT_DEBUG) {
if($SHOW_CONTENT_DEBUG_CARD) {
echo('<div class="card p-0 mx-0">
<div class="px-card py-10 border-bottom px-20">
<div class="container-fluid">
@@ -69,14 +62,14 @@ if($content_has_error) {
<div class="px-card py-20 bg-light-lm rounded-bottom px-20 bg-very-dark title-bkgd">
<!--<h3 class="m-0 mb-5 font-size-20 text-center font-weight-semi-bold">This page is still under construction !</h3>-->');
echo('<p class="m-0 mb-5">REQUEST_URI: '.$_SERVER['REQUEST_URI'].'</p>');
echo('<p class="m-0 mb-5">$requested_content_type: '.$requested_content_type.'</p>');
echo('<p class="m-0 mb-5">$requested_content_display_type: '.$requested_content_display_type.'</p>');
echo('<p class="m-0 mb-5">$requested_tags: ['.implode(", ", $requested_tags).']</p>');
echo('<p class="m-0 mb-5">count($requested_tags): '.count($requested_tags).'</p>');
echo('<p class="m-0 mb-5">$content_has_error: '.$content_has_error.'</p>');
echo('<p class="m-0 mb-5">$_content_error_message_key: '.$_content_error_message_key.'</p>');
echo('<p class="m-0 mb-5">localize($_content_error_message_key): '.localize($_content_error_message_key).'</p>');
echo('<p class="m-0 mb-5">$content_error_message_key: '.$content_error_message_key.'</p>');
echo('<p class="m-0 mb-5">localize($content_error_message_key): '.localize($content_error_message_key).'</p>');
echo('<p class="m-0 mb-5">$content_error_message: '.$content_error_message.'</p>');
echo('<p class="m-0 mb-5">$raw_additional_tags: '.$raw_additional_tags.'</p>');
echo('<p class="m-0 mb-5">$filtered_content_index_data: ');
print_r($filtered_content_index_data);
echo('</p>');
@@ -117,7 +110,7 @@ if($content_has_error) {
// https://css-tricks.com/float-an-element-to-the-bottom-corner/
echo('<div class="content-presentation-container">');
echo('<a href="#"><div>');
echo('<a href="'.l10n_url_abs("/content/".$filtered_content_index_data[$i]["id"]).'"><div>');
echo('<div class="content-search-image-container">');
echo('<img class="content-search-image" src="'.$filtered_content_index_data[$i]["image"].'">');
echo('</div>');
@@ -135,10 +128,8 @@ if($content_has_error) {
echo('<a href="#" class="content-tag">#'.$filtered_content_index_data[$i]["tags"][$j].'</a>');
}
echo('</div>');
// TODO: Add button to view article !
echo('</div>');
echo('</div>');
}
echo('</div>');
@@ -147,11 +138,8 @@ if($content_has_error) {
'Card footer here.'.
'</p></div>');
endMainCard();
} elseif($requested_content_display_type == ContentDisplayType::ARTICLE) {
startMainCard("fad fa-file-alt", localize("content.title.article"), "subtitle");
endMainCard();
} elseif($requested_content_display_type == ContentDisplayType::APPLICATION) {
startMainCard("fad fa-file-alt", localize("content.title.application"), "subtitle");
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
startMainCard("fad fa-file-alt", localize("content.title.content"), "subtitle");
endMainCard();
}

View File

@@ -0,0 +1,9 @@
{
"title": {
"en": "PB-ListComPort - CLI COM port enumerator",
"fr": "PB-ListComPort - Enumérateur de port COM pour invité de commande"
},
"tags": [
"programming", "lscom"
]
}

View File

@@ -111,14 +111,25 @@ hr, hr.dark-mde, hr.subtle {
margin-bottom: 5px;
}
/* Content search */
@media (max-width: 992px) {
:root {
--content-search-image-size: 96px;
}
}
@media (min-width: 993px) {
:root {
--content-search-image-size: 128px;
}
}
div.content-presentation-container {
margin-bottom: 10px;
min-height: 128px;
min-height: var(--content-search-image-size);
display: flex;
}
div.content-presentation-container > a {
width: 100%;
min-height: 128px;
min-height: var(--content-search-image-size);
text-align: justify;
color: var(--dm-card-text-color);
}
@@ -130,14 +141,14 @@ div.content-search-image-container {
background: var(--dm-card-bg-color) url("/resources/Azias/imgs/3px-tile-0.2.png") repeat fixed center center;
box-shadow: inset 0 0 25px 1px rgba(255,255,255,0.05);
border-radius: 8px;
width: 128px;
height: 128px;
width: var(--content-search-image-size);
height: var(--content-search-image-size);
margin-right: 10px;
float: left;
}
img.content-search-image {
max-width: 128px;
max-height: 128px;
max-width: var(--content-search-image-size);
max-height: var(--content-search-image-size);
border-radius: 8px;
box-shadow: 0 0 5px 1px rgba(0,0,0,0.3);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB