Refactored commons/content.php for tools page

Update composer.php, config.php, and 7 more files...
This commit is contained in:
2023-05-25 07:09:39 +02:00
parent ee90a3745d
commit e6e00ad02f
9 changed files with 241 additions and 162 deletions

View File

@@ -5,14 +5,27 @@ $start_time = microtime(true);
set_include_path('../');
include_once 'commons/config.php';
include_once 'commons/langs.php';
// Preparing the content
include_once 'commons/content.php';
include_once 'commons/composer.php';
$contentManager = getContentManager($config_dir_content);
$content = NULL;
if(!$contentManager->hasError && $contentManager->displayType == ContentDisplayType::CONTENT) {
$content = load_content_by_file_path($contentManager->contentFilepath);
if(is_null($content)) {
$contentManager->hasError = true;
$contentManager->errorMessageKey = "content.error.message.cannot.load";
}
}
$content_error_message = localize($contentManager->errorMessageKey);
// Checking if an error occurred while loading data and parsing the URL.
// And if not, enabling special features.
$content_error_code = 200;
if ($content_has_error) {
if($contentManager->hasError) {
// TODO: Add condition for the lack of data for an item.
if (is_null($filtered_content_index_data)) {
if(is_null($contentManager->rootIndexEntries)) {
// Failed to get a display type or to extract types.
header("HTTP/1.1 400 Bad Request");
$content_error_code = 400;
@@ -34,12 +47,12 @@ if ($content_has_error) {
include 'commons/DOM/head.php';
// Preparing values for the head's tags.
if ($content_has_error) {
if ($contentManager->hasError) {
$content_head_title = localize("content.error.head.title");
$content_head_description = $content_error_message;
$content_head_og_title = localize("content.error.og.title");
$content_head_og_description = $content_error_message;
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
} elseif($contentManager->displayType == ContentDisplayType::CONTENT) {
$content_head_title =
localize("content.item.head.title.prefix") .
$content->get_head_title() .
@@ -50,7 +63,7 @@ if ($content_has_error) {
$content->get_head_title() .
localize("content.item.og.title.suffix");
$content_head_og_description = $content->get_head_description();
} elseif($requested_content_display_type == ContentDisplayType::SEARCH) {
} elseif($contentManager->displayType == ContentDisplayType::SEARCH) {
$content_head_title = localize("content.search.head.title");
$content_head_description = localize("content.search.head.description");;
$content_head_og_title = localize("content.search.og.title");;
@@ -79,17 +92,17 @@ include 'commons/DOM/body-2.php';
<header class="w-full p-m pl-s">
<h1 class="t-size-17 t-w-500">
<?php
if($content_has_error) {
if($contentManager->hasError) {
echo('<i class="fad fa-exclamation-triangle t-size-16 mr-s t-muted"></i>');
echo(localize("content.header.base"));
echo('<span class="mx-s t-size-15">❱</span>');
echo(localize("content.error.header"));
} elseif($requested_content_display_type == ContentDisplayType::SEARCH) {
} elseif($contentManager->displayType == ContentDisplayType::SEARCH) {
echo('<i class="fad fa-briefcase t-size-16 mr-s t-muted"></i>');
echo(localize("content.header.base"));
echo('<span class="mx-s t-size-15">❱</span>');
echo(localize("content.search.header"));
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
} elseif($contentManager->displayType == ContentDisplayType::CONTENT) {
echo('<i class="fad fa-briefcase t-size-16 mr-s t-muted"></i>');
echo(localize("content.header.base"));
echo('<span class="mx-s t-size-15">❱</span>');
@@ -104,9 +117,9 @@ include 'commons/DOM/body-2.php';
<?php
// Checking if an error occurred.
if($content_error_code != 200) {
if($requested_content_display_type == ContentDisplayType::SEARCH) {
if($contentManager->displayType == ContentDisplayType::SEARCH) {
printMainHeader(localize("content.error.heading.main.search"), "fad fa-exclamation-triangle");
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
} elseif($contentManager->displayType == ContentDisplayType::CONTENT) {
printMainHeader(localize("content.error.heading.main.content"), "fad fa-exclamation-triangle");
} else {
printMainHeader(localize("content.error.heading.main.fallback"), "fad fa-exclamation-triangle");
@@ -117,52 +130,54 @@ include 'commons/DOM/body-2.php';
goto content_printing_end;
}
if($requested_content_display_type == ContentDisplayType::SEARCH) {
if($contentManager->displayType == ContentDisplayType::SEARCH) {
// We are handling a content search with at least one result.
// Making the header with the amount of results.
printMainHeader(
count($filtered_content_index_data) > 1 ?
count($contentManager->rootIndexEntries) > 1 ?
localize("content.search.heading.main.multiple") :
localize("content.search.heading.main.single"),
"fad fa-file-search",
count($filtered_content_index_data) . " " . (
count($filtered_content_index_data) > 1 ?
count($contentManager->rootIndexEntries) . " " . (
count($contentManager->rootIndexEntries) > 1 ?
localize("content.search.count.multiple") :
localize("content.search.count.single")));
// Printing the entry for each piece of relevant content.
for($iContent = 0; $iContent < count($filtered_content_index_data); $iContent++) {
$current_content = $filtered_content_index_data[$iContent];
if($iContent > 0) {
echo('<hr class="subtle">');
}
$doPrintRuler = false;
foreach($contentManager->rootIndexEntries as $current_content) {
/** @var ContentIndexEntry $current_content */
if($doPrintRuler) {
echo('<hr class="subtle">');
} else {
$doPrintRuler = true;
}
echo('<div class="p-s">');
echo('<a class="casper-link" href="'.l10n_url_abs("/content/".$current_content["id"]).'">');
echo('<a class="casper-link" href="'.l10n_url_abs("/content/".$current_content->id).'">');
echo('<div class="content-search-entry">');
echo('<img class="content-search-image mr-s r-l" src="' . $current_content["image"] . '">');
echo('<h3 class="mb-xs">' . $current_content["title"][$user_language] . '</h3>');
echo('<p>' . $current_content["preamble"][$user_language] . '</p>');
echo('<img class="content-search-image mr-s r-l" src="' . $current_content->image . '">');
echo('<h3 class="mb-xs">' . $current_content->title[$user_language] . '</h3>');
echo('<p>' . $current_content->preamble[$user_language] . '</p>');
echo('</div>');
echo('</a>');
echo('<p class="mt-xs"><i class="fad fa-tags t-size-8"></i>');
for($iContentTag = 0; $iContentTag < count($current_content["tags"]); $iContentTag++) {
echo('<a href="' . l10n_url_abs("/content/?tags=".$current_content["tags"][$iContentTag]) .
'" class="ml-xs">#' . $current_content["tags"][$iContentTag] . '</a>');
foreach($current_content->tags as $current_content_tag) {
echo('<a href="' . l10n_url_abs("/content/?tags=".$current_content_tag) .
'" class="ml-xs">#' . $current_content_tag . '</a>');
}
echo('</p>');
echo('</div>');
}
// TODO: Print the tags used in the search and others that may be available.
} elseif($requested_content_display_type == ContentDisplayType::CONTENT) {
} elseif($contentManager->displayType == ContentDisplayType::CONTENT) {
// Printing the content
echo($content->get_html());
}