Added content JSON structure parser base, Added images, Added Glider.js, Fixed typos

Update .gitignore, content.php, and 21 more files...
This commit is contained in:
2022-04-15 20:17:28 +02:00
parent e2adc41bad
commit 01ceb1b89b
23 changed files with 1221 additions and 101 deletions

View File

@@ -11,12 +11,14 @@ include_once 'langs.php';
// This helper requires PHP 8 or newer !
$SHOW_CONTENT_DEBUG_CARD = false;
$PRINT_CONTENT_DEBUG_INFO_TEXT_ELEMENTS = true;
$PRINT_CONTENT_DEBUG_ERROR_TEXT_ELEMENTS = true;
// Defining constants and enums.
abstract class ContentDisplayType {
const NONE = 0;
const SEARCH = 1;
const CONTENT = 2;
const CONTENT = 2;
}
// Preparing default variables.
@@ -130,4 +132,211 @@ function endMainCard() {
echo('</div>');
}
function getContentItemText(array $contentNode, bool $italicOnError = true, bool $returnMissingAsEmpty = false) : string {
global $user_language, $default_language;
if(array_key_exists("key", $contentNode)) {
return localize($contentNode["key"]);
} elseif(array_key_exists($user_language, $contentNode)) {
return $contentNode[$user_language];
} elseif(array_key_exists($default_language, $contentNode)) {
return $contentNode[$default_language];
} else {
if($returnMissingAsEmpty) {
return "";
}
if($italicOnError) {
return '<i>'.localize("error.content.data.no.title").'</i>';
} else {
return localize("error.content.data.no.title");
}
}
}
function printInfoTextElement(string $text) : void {
global $PRINT_CONTENT_DEBUG_INFO_TEXT_ELEMENTS;
if($PRINT_CONTENT_DEBUG_INFO_TEXT_ELEMENTS) {
echo('<h3 class="m-0 font-size-20 text-primary font-weight-semi-bold">'.$text.'</h3>');
}
}
function printErrorTextElement(string $text) : void {
global $PRINT_CONTENT_DEBUG_ERROR_TEXT_ELEMENTS;
if($PRINT_CONTENT_DEBUG_ERROR_TEXT_ELEMENTS) {
echo('<h3 class="m-0 font-size-20 text-center text-danger font-weight-semi-bold">'.$text.'</h3>');
}
}
function createElementNode(mixed $elementNode) : void {
// Checking if we actually have a JSON object.
if(!is_array($elementNode)) {
echo('<p>Not array node !</p>');
return;
}
if(!array_key_exists("type", $elementNode)) {
echo('<p>No "type" member found in node !</p>');
return;
}
switch($elementNode["type"]) {
case "table":
//printInfoTextElement('table item type');
// Reading and processing the modifiers
$_modNoOuterPadding = false;
$_modStriped = false;
$_modHover = false;
$_modInnerBordered = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($elementNode["modifiers"]); $i++) {
//printInfoTextElement('&gt;&gt; Modifier: '.$elementNode["modifiers"][$i]);
switch($elementNode["modifiers"][$i]) {
case "no-outer-padding":
// Removes the rounding on the external edges.
$_modNoOuterPadding = true;
break;
case "striped":
// Removes the internal padding and adds 0.01em to the top to prevent gaps from margins.
$_modStriped = true;
break;
case "hover":
// Removes the standard top margin.
$_modHover = true;
break;
case "inner-bordered":
// Removes the standard top margin.
$_modInnerBordered = true;
break;
}
}
}
// Preparing table
echo('<table class="table'.($_modNoOuterPadding?" table-no-outer-padding":"").($_modStriped?" table-striped":"").
($_modHover?" table-hover":"").($_modInnerBordered?" table-inner-bordered":"").'">');
// Creating "thead"
if(array_key_exists("head", $elementNode)) {
echo('<thead><tr>');
for ($iTableHead = 0; $iTableHead < count($elementNode["head"]); $iTableHead++) {
echo('<th>');
if(array_key_exists("parts", $elementNode["head"][$iTableHead])) {
for ($iPart = 0; $iPart < count($elementNode["head"][$iTableHead]["parts"]); $iPart++) {
createElementNode($elementNode["head"][$iTableHead]["parts"][$iPart]);
}
} else {
echo(getContentItemText($elementNode["head"][$iTableHead], false, true));
}
echo('</th>');
}
echo('</tr></thead>');
}
// Creating "tbody"
if(array_key_exists("body", $elementNode)) {
echo('<tbody>');
for ($iTableBodyRow = 0; $iTableBodyRow < count($elementNode["body"]); $iTableBodyRow++) {
echo('<tr>');
for ($iTableBodyCell = 0; $iTableBodyCell < count($elementNode["body"][$iTableBodyRow]); $iTableBodyCell++) {
$_cellColSpan = 1;
$_cellRowSpan = 1;
if(array_key_exists("colspan", $elementNode["body"][$iTableBodyRow][$iTableBodyCell])) {
$_cellColSpan = $elementNode["body"][$iTableBodyRow][$iTableBodyCell]["colspan"];
}
if(array_key_exists("rowspan", $elementNode["body"][$iTableBodyRow][$iTableBodyCell])) {
$_cellRowSpan = $elementNode["body"][$iTableBodyRow][$iTableBodyCell]["rowspan"];
}
echo('<td'.($_cellColSpan>1?' colspan="'.$_cellColSpan.'"':'').($_cellRowSpan>1?' rowspan="'.$_cellRowSpan.'"':'').'>');
if(array_key_exists("parts", $elementNode["body"][$iTableBodyRow][$iTableBodyCell])) {
for ($iPart = 0; $iPart < count($elementNode["body"][$iTableBodyRow][$iTableBodyCell]["parts"]); $iPart++) {
createElementNode($elementNode["body"][$iTableBodyRow][$iTableBodyCell]["parts"][$iPart]);
}
} else {
echo(getContentItemText($elementNode["body"][$iTableBodyRow][$iTableBodyCell], false, true));
}
echo('</td>');
}
echo('</tr>');
}
echo('</tbody>');
}
// Ending table
echo('</table>');
break;
case "collapse":
//printInfoTextElement('collapse item type');
// Preparing some stuff
$_title = '<i>'.localize("error.content.data.no.title").'</i>';
$_subtitle = '';
if(array_key_exists("title", $elementNode)) {
$_title = getContentItemText($elementNode["title"], true, true);
}
if(array_key_exists("subtitle", $elementNode)) {
$_subtitle = getContentItemText($elementNode["subtitle"], true, true);
}
//printInfoTextElement('&gt; title: "'.$_title);
//printInfoTextElement('&gt; subtitle: "'.$_subtitle);
// Reading and processing the modifiers
$_modNoRounding = false;
$_modNoContentPadding = false;
$_modNoTopMargin = false;
$_modIsClosed = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($elementNode["modifiers"]); $i++) {
//printInfoTextElement('&gt;&gt; Modifier: '.$elementNode["modifiers"][$i]);
switch($elementNode["modifiers"][$i]) {
case "no-rounding":
// Removes the rounding on the external edges.
$_modNoRounding = true;
break;
case "no-padding-content":
// Removes the internal padding and adds 0.01em to the top to prevent gaps from margins.
$_modNoContentPadding = true;
break;
case "no-top-margin":
// Removes the standard top margin.
$_modNoTopMargin = true;
break;
case "closed":
// Close the collapse by default.
$_modIsClosed = true;
break;
}
}
}
// Starting the collapse
echo('<details class="collapse-panel w-full'.($_modNoTopMargin?"":" mt-20").'" '.($_modIsClosed?"closed":"open").'>');
echo('<summary class="collapse-header p-10 px-15 text-truncate without-arrow'.($_modNoRounding?" rounded-0":"").' border-left-0 border-right-0">');
echo('<h4 class="font-size-16 m-0 align-middle no-select"><i class="fad fa-angle-down hidden-collapse-open font-size-24"></i>');
echo('<i class="fad fa-angle-up hidden-collapse-closed font-size-24"></i>');
echo('<span class="font-weight-semi-bold align-top">&nbsp;&nbsp;'.$_title.'<span class="ml-20 text-muted">'.$_subtitle.'</span></span>');
echo('</h4></summary><div class="collapse-content'.($_modNoContentPadding?" p-0 py-01":"").($_modNoRounding?" rounded-0":"").' border-0 border-bottom">');
// Rendering sub-elements
if(array_key_exists("parts", $elementNode)) {
//printInfoTextElement('&gt; Processing sub-parts');
for ($i = 0; $i < count($elementNode["parts"]); $i++) {
createElementNode($elementNode["parts"][$i]);
}
//printInfoTextElement('&gt; Done processing sub-parts');
} else {
printErrorTextElement(localize("error.content.data.no.subpart"));
}
// Ending the collapse
echo('</div></details>');
//printInfoTextElement('end of collapse');
break;
default:
printErrorTextElement(sprintf(localize("error.content.data.part.unknown"), $elementNode["type"]));
break;
}
}
?>

View File

@@ -106,8 +106,12 @@
"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.",
"error.content.id.alphanumeric": "The requested resource's ID isn't valid.",
"error.content.data.not.exist": "The requested resource's doesn't have an associated item file.",
"error.content.data.not.exist": "The requested content doesn't have an internal item file.",
"error.content.data.no.title": "No title found !",
"error.content.data.no.tags": "No tags found !",
"error.content.data.no.parts": "No content parts were found for this content !",
"error.content.data.no.subpart": "No sub-element were found for this element !",
"error.content.data.part.unknown": "Unknown element: \"%s\" !",
"content.title.error": "Error",
"content.title.content": "Content",
@@ -118,6 +122,18 @@
"content.search.count.single": "result",
"content.search.count.multiple": "results",
"content.commons.version.current": "Current version",
"content.commons.version.previous.single": "Previous version",
"content.commons.version.previous.multiple": "Previous versions",
"content.commons.version.old.single": "Old version",
"content.commons.version.old.multiple": "Old versions",
"content.commons.cpu": "CPU Architecture",
"content.commons.cpu.x64": "x64",
"content.commons.cpu.x86": "x86",
"content.commons.lang": "Language",
"content.commons.download.single": "Download",
"content.commons.download.multiple": "Downloads",
"about.biography.title": "Who am I ?",
"about.philosophy.title": "Projects philosophy",
"about.skills.title": "Skills",
@@ -235,8 +251,12 @@
"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é.",
"error.content.id.alphanumeric": "L'ID de la ressource demandée n'est pas valide.",
"error.content.data.not.exist": "La ressource demandée n'a pas de fichier de données associé.",
"error.content.data.not.exist": "Le contenu demandée n'a pas de fichier de données interne associé.",
"error.content.data.no.title": "Aucun titre trouvé !",
"error.content.data.no.tags": "Aucun tag trouvé !",
"error.content.data.no.parts": "Aucun élément à présenter n'a été trouvé !",
"error.content.data.no.subpart": "Aucun sous-élément n'a été trouvé pour cet élément !",
"error.content.data.part.unknown": "Élément inconnu: \"%s\" !",
"content.title.error": "Erreur de contenu",
"content.title.content": "Content",
@@ -247,6 +267,18 @@
"content.search.count.single": "résultat",
"content.search.count.multiple": "résultats",
"content.commons.version.current": "Version actuelle",
"content.commons.version.previous.single": "Version précédente",
"content.commons.version.previous.multiple": "Versions précédentes",
"content.commons.version.old.single": "Ancienne version",
"content.commons.version.old.multiple": "Anciennes versions",
"content.commons.cpu": "Architecture de CPU",
"content.commons.cpu.x64": "x64",
"content.commons.cpu.x86": "x86",
"content.commons.lang": "Langue",
"content.commons.download.single": "Téléchargement",
"content.commons.download.multiple": "Téléchargements",
"about.biography.title": "Qui suis-je ?",
"about.philosophy.title": "Philosophie des projets",
"about.skills.title": "Compétences",