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);
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;
}
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
// Sanitizing the requested ID.
if(!ctype_alnum(str_replace("-", "", $content_requested_url_part))) {
$content_has_error = true;
$content_error_message_key = "error.content.id.alphanumeric";
goto content_end;
}
// Loading the content's data.
$content_file_path = realpath($dir_content . "/items/".$content_requested_url_part.".json");
if($content_file_path) {
// FIXME: Handle JSON errors cleanly
$content_json = file_get_contents($content_file_path);
$requested_item_data = json_decode($content_json, true);
unset($content_json);
} else {
$content_has_error = true;
$content_error_message_key = "error.content.data.not.exist";
goto content_end;
}
unset($content_file_path);
}
content_end:
$content_error_message = localize($content_error_message_key);
// These functions are placed here to prevent the main file from becoming impossible to read.
function startMainCard($iconClasses, $title, $subTitle) {
echo('
');
echo('
'.localize($title));
echo(''.$subTitle.'
');
echo('');
}
function endMainCard() {
echo('
');
}
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 ''.localize("error.content.data.no.title").'';
} 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(''.$text.'
');
}
}
function printErrorTextElement(string $text) : void {
global $PRINT_CONTENT_DEBUG_ERROR_TEXT_ELEMENTS;
if($PRINT_CONTENT_DEBUG_ERROR_TEXT_ELEMENTS) {
echo(''.$text.'
');
}
}
function processStandardContentSubNode(mixed $elementNode) : void {
if(array_key_exists("content", $elementNode)) {
if (array_key_exists("parts", $elementNode["content"])) {
for ($iPart = 0; $iPart < count($elementNode["content"]["parts"]); $iPart++) {
createElementNode($elementNode["content"]["parts"][$iPart]);
}
} else {
echo(getContentItemText($elementNode["content"], false, true));
}
}
}
function createElementNode(mixed $elementNode) : void {
// Checking if we actually have a JSON object.
if(!is_array($elementNode)) {
echo('Not array node !
');
return;
}
if(!array_key_exists("type", $elementNode)) {
echo('No "type" member found in node !
');
return;
}
switch($elementNode["type"]) {
case "spacer":
// Defining the font size.
$_spacerSize = 1;
if(array_key_exists("size", $elementNode)) {
$_spacerSize = $elementNode["size"];
}
// Adding element.
echo('');
break;
case "h1":
case "h2":
case "h3":
// Defining the font size.
$_headingFontSize = ($elementNode["type"] == "h3" ? '18' : (($elementNode["type"] == "h2" ? '20' : '22')));
// Opening heading.
echo('<'.$elementNode["type"].' class="font-weight-semi-bold font-size-'.$_headingFontSize.' m-0">');
// Adding content.
processStandardContentSubNode($elementNode);
// Closing heading.
echo(''.$elementNode["type"].'>');
break;
case "paragraph":
// Parsing properties.
$_indentLevel = 0;
if(array_key_exists("indent", $elementNode)) {
$_indentLevel = $elementNode["indent"];
}
// Opening paragraph.
echo('');
// Adding content.
processStandardContentSubNode($elementNode);
// Closing paragraph.
echo('
');
break;
case "code":
// Parsing properties.
$_indentLevel = 0;
if(array_key_exists("indent", $elementNode)) {
$_indentLevel = $elementNode["indent"];
}
// Reading and processing the modifiers.
$_modNoTopMargin = false;
$_modFullWidth = false;
$_modHorizontalScroll = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($elementNode["modifiers"]); $i++) {
switch($elementNode["modifiers"][$i]) {
case "no-top-margin":
$_modNoTopMargin = true;
break;
case "full-width":
$_modFullWidth = true;
break;
case "horizontal-scroll":
$_modHorizontalScroll = true;
break;
}
}
}
// Opening code element.
echo('');
// Adding code lines.
if (array_key_exists("code", $elementNode)) {
for ($iCodeLine = 0; $iCodeLine < count($elementNode["code"]); $iCodeLine++) {
echo(htmlspecialchars($elementNode["code"][$iCodeLine]).'
');
}
}
// Closing code element.
echo('
');
break;
case "container":
// Grabbing the global padding.
$_containerPadding = "10";
if(array_key_exists("padding", $elementNode)) {
$_containerPadding = $elementNode["padding"];
}
// Reading and processing the modifiers.
$_modNoTopMargin = false;
$_modNoTopPadding = false;
$_modNoBottomPadding = false;
$_modNoSizePadding = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($elementNode["modifiers"]); $i++) {
switch($elementNode["modifiers"][$i]) {
case "no-top-margin":
$_modNoTopMargin = true;
break;
case "no-top-padding":
$_modNoTopPadding = true;
break;
case "no-bottom-padding":
$_modNoBottomPadding = true;
break;
case "no-side-padding":
$_modNoSizePadding = true;
break;
}
}
}
// Opening container.
echo('');
// Adding content.
processStandardContentSubNode($elementNode);
// Closing container.
echo('
');
break;
case "button":
// Reading and processing the modifiers.
$_modRawStyle = false;
$_modThinStyle = false;
$_modThickStyle = false;
$_modRoundShape = false;
$_modCircleShape = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($elementNode["modifiers"]); $i++) {
switch($elementNode["modifiers"][$i]) {
case "raw":
$_modRawStyle = true;
break;
case "thin":
$_modThinStyle = true;
break;
case "thick":
$_modThickStyle = true;
break;
case "rounded":
$_modRoundShape = true;
break;
case "circle":
$_modCircleShape = true;
break;
}
}
}
// Adding link if needed.
if(array_key_exists("link", $elementNode)) {
echo('');
}
// Opening button.
echo('');
if(array_key_exists("link", $elementNode)) {
echo('');
}
break;
case "table":
// 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++) {
switch($elementNode["modifiers"][$i]) {
case "no-outer-padding":
$_modNoOuterPadding = true;
break;
case "striped":
$_modStriped = true;
break;
case "hover":
$_modHover = true;
break;
case "inner-bordered":
$_modInnerBordered = true;
break;
}
}
}
// Preparing table.
echo('');
// Creating "thead".
if(array_key_exists("head", $elementNode)) {
echo('');
for ($iTableHead = 0; $iTableHead < count($elementNode["head"]); $iTableHead++) {
echo('');
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(' | ');
}
echo('
');
}
// Creating "tbody".
if(array_key_exists("body", $elementNode)) {
echo('');
for ($iTableBodyRow = 0; $iTableBodyRow < count($elementNode["body"]); $iTableBodyRow++) {
echo('');
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('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(' | ');
}
echo('
');
}
echo('');
}
// Ending table.
echo('
');
break;
case "collapse":
// Preparing some stuff.
$_title = ''.localize("error.content.data.no.title").'';
$_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);
}
// Reading and processing the modifiers.
$_modNoRounding = false;
$_modNoContentPadding = false;
$_modNoTopMargin = false;
$_modIsClosed = false;
$_modHorizontalScroll = false;
if(array_key_exists("modifiers", $elementNode)) {
for ($i = 0; $i < count($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;
case "horizontal-scroll":
$_modHorizontalScroll = true;
break;
}
}
}
// Starting the collapse.
echo('');
echo('');
// Rendering sub-elements.
if(array_key_exists("parts", $elementNode)) {
for ($i = 0; $i < count($elementNode["parts"]); $i++) {
createElementNode($elementNode["parts"][$i]);
}
} else {
printErrorTextElement(localize("error.content.data.no.subpart"));
}
// Ending the collapse.
echo('
');
break;
default:
printErrorTextElement(sprintf(localize("error.content.data.part.unknown"), $elementNode["type"]));
break;
}
}
?>