Updated ContentManager and related enums
Update .htaccess, manager.php, and 3 more files...
This commit is contained in:
@@ -33,6 +33,11 @@ AddType application/wasm .wasm
|
||||
AddType video/x-matroska .mkv
|
||||
AddType text/css .css
|
||||
|
||||
# Special case for Plik
|
||||
<Files ~ "\.css?$">
|
||||
Header set Content-Type "text/css; charset=utf-8"
|
||||
</Files>
|
||||
|
||||
|
||||
# Correcting some default options for security and language/content redirection.
|
||||
# FollowSymlinks is also on since it's required for "mod_rewrite" and the server is jailed/containerized.
|
||||
|
@@ -9,9 +9,14 @@ if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
|
||||
include_once 'commons/langs.php';
|
||||
|
||||
enum EContentDisplayType {
|
||||
const NONE = 0;
|
||||
const SEARCH = 1;
|
||||
const DISPLAY = 2;
|
||||
/** No display type have or could be determined. */
|
||||
case NONE;
|
||||
|
||||
/** The content index should be shown */
|
||||
case SEARCH;
|
||||
|
||||
/** The page for a specific piece of content should be shown */
|
||||
case DISPLAY;
|
||||
}
|
||||
|
||||
class ContentIndexEntry {
|
||||
@@ -47,7 +52,7 @@ class ContentIndexEntry {
|
||||
}
|
||||
|
||||
class ContentManager {
|
||||
public ContentDisplayType|int $displayType;
|
||||
public EContentDisplayType $displayType;
|
||||
public bool $hasError;
|
||||
public string $errorMessageKey;
|
||||
public ?string $requestedId;
|
||||
@@ -87,7 +92,7 @@ class ContentManager {
|
||||
// Doing some dark magic whose inner workings are lost to times...
|
||||
$requestedUrlPart = explode(
|
||||
"?",
|
||||
explode("#", preg_replace("^\/(content|tools)^", "", $requestedUrl))[0]
|
||||
explode("#", preg_replace("^/(content|tools)^", "", $requestedUrl))[0]
|
||||
)[0];
|
||||
|
||||
if(strcmp($requestedUrlPart, "/") == 0) {
|
||||
@@ -177,7 +182,7 @@ class ContentManager {
|
||||
/**
|
||||
* If currently in a "EContentDisplayType::DISPLAY" context, we prepare the path to the content definition.
|
||||
* This definition must be loaded afterward depending on the content's type. (content, tool, article, ...)
|
||||
* @param string $rootIndexFilepath
|
||||
* @param string $contentRootPath
|
||||
* @return void
|
||||
*/
|
||||
function prepareContentFilePath(string $contentRootPath): void {
|
||||
@@ -189,7 +194,7 @@ class ContentManager {
|
||||
}
|
||||
|
||||
// Preparing and checking the content's info index file.
|
||||
$this->contentFilepath = get_content_file_path($contentRootPath, $this->requestedId);
|
||||
$this->contentFilepath = ContentManager::getContentFilePath($contentRootPath, $this->requestedId);
|
||||
|
||||
if(empty($this->contentFilepath)) {
|
||||
// File doesn't exist !
|
||||
@@ -197,29 +202,32 @@ class ContentManager {
|
||||
$this->errorMessageKey = "content.error.message.data.not.exist";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Common utilities
|
||||
function get_content_file_path(string $contentRootPath, string $contentId): ?string {
|
||||
if(ctype_alnum(str_replace("-", "", $contentId))) {
|
||||
return realpath($contentRootPath . "/items/" . $contentId . ".json");
|
||||
|
||||
/**
|
||||
* Returns the path to the main JSON file for a desired piece of content.
|
||||
* @param string $contentRootPath
|
||||
* @param string $contentId
|
||||
* @return string|null
|
||||
*/
|
||||
private static function getContentFilePath(string $contentRootPath, string $contentId): ?string {
|
||||
if(ctype_alnum(str_replace("-", "", $contentId))) {
|
||||
return realpath($contentRootPath . "/items/" . $contentId . ".json");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a ContentManager for the current page.
|
||||
* @param string $contentRootPath Root path for the relevant content ("<webRoot>/content", "<webRoot>/tools", ...)
|
||||
* @return ContentManager
|
||||
*/
|
||||
public static function createContentManager(string $contentRootPath): ContentManager {
|
||||
return new ContentManager(
|
||||
$contentRootPath,
|
||||
l10n_url_switch(NULL),
|
||||
isset($_GET['tags']) ? htmlspecialchars($_GET['tags']) : NULL
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Functions for use in pages
|
||||
|
||||
/**
|
||||
* Prepares a ContentManager for the current page.
|
||||
* @param string $contentRootPath Root path for the relevant content ("<webRoot>/content", "<webRoot>/tools", ...)
|
||||
* @return ContentManager
|
||||
*/
|
||||
function getContentManager(string $contentRootPath): ContentManager {
|
||||
return new ContentManager(
|
||||
$contentRootPath,
|
||||
l10n_url_switch(NULL),
|
||||
isset($_GET['tags']) ? htmlspecialchars($_GET['tags']) : NULL
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@@ -9,7 +9,7 @@ include_once 'commons/langs.php';
|
||||
// Preparing the content
|
||||
include_once 'commons/content/manager.php';
|
||||
include_once 'commons/content/composer.php';
|
||||
$contentManager = getContentManager($config_dir_content);
|
||||
$contentManager = ContentManager::createContentManager($config_dir_content);
|
||||
$content = NULL;
|
||||
if(!$contentManager->hasError && $contentManager->displayType == EContentDisplayType::DISPLAY) {
|
||||
$content = load_content_by_file_path($contentManager->contentFilepath);
|
||||
|
@@ -39,10 +39,10 @@ include 'commons/DOM/sidebar.php';
|
||||
<?php
|
||||
// Loading the "index.json" file for later use in the showcase.
|
||||
include_once 'commons/config.php';
|
||||
include_once 'commons/content.php';
|
||||
$contentManager = getContentManager($config_dir_content);
|
||||
include_once 'commons/content/manager.php';
|
||||
$contentManager = ContentManager::createContentManager($config_dir_content);
|
||||
$content = NULL;
|
||||
if(!$contentManager->hasError && $contentManager->displayType == ContentDisplayType::CONTENT) {
|
||||
if(!$contentManager->hasError && $contentManager->displayType == EContentDisplayType::DISPLAY) {
|
||||
$content = load_content_by_file_path($contentManager->contentFilepath);
|
||||
if(is_null($content)) {
|
||||
$contentManager->hasError = true;
|
||||
|
@@ -8,7 +8,7 @@ include_once 'commons/langs.php';
|
||||
|
||||
// Preparing the content manager to get the page's context.
|
||||
include_once 'commons/content/manager.php';
|
||||
$contentManager = getContentManager($config_dir_tools);
|
||||
$contentManager = ContentManager::createContentManager($config_dir_tools);
|
||||
|
||||
// Attempting to load the tool's data if relevant.
|
||||
// If loaded, we can assume the standardized index wasn't loaded by "$contentManager".
|
||||
|
Reference in New Issue
Block a user