Add PHPDocs generated by ChatGPT,
add additional clarification to some functions, add addNewsComment function and API, currently untested and not implemented in the client, fix a bunch of stuff that PHPStorm pointed out
This commit is contained in:
63
lib/page.php
63
lib/page.php
@@ -1,16 +1,37 @@
|
||||
<?php
|
||||
require_once "lib/dynamic_style.php";
|
||||
require_once "lib/script_data.php";
|
||||
function renderDynamicPage($page_file): array
|
||||
/**
|
||||
* Loads and returns the result of a PHP file.
|
||||
* This function is typically used to process dynamic content of a page.
|
||||
* It simply scopes an external file into a function to prevent variable conflicts.
|
||||
*
|
||||
* @param string $page_file The file path to the dynamic page.
|
||||
* @return array Returns the array of data generated by including the PHP file.
|
||||
*/
|
||||
function renderDynamicPage(string $page_file): array
|
||||
{
|
||||
return require $page_file;
|
||||
}
|
||||
|
||||
function removeHtmlComments($content = '') :string {
|
||||
/**
|
||||
* Removes all HTML comments from the provided content string.
|
||||
*
|
||||
* @param string $content The HTML content from which to remove comments.
|
||||
* @return string The content without any HTML comments.
|
||||
*/
|
||||
function removeHtmlComments(string $content = '') :string {
|
||||
return preg_replace('/<!--(.|\s)*?-->/', '', $content);
|
||||
}
|
||||
|
||||
function parsePageTag($input): array
|
||||
/**
|
||||
* Parses custom `<page>` tags from the given input string and extracts parameters.
|
||||
* Returns the input string with `<page>` tags removed and a list of parameters.
|
||||
*
|
||||
* @param string $input The input HTML or text containing `<page>` tags.
|
||||
* @return array Returns an associative array with 'parameters' (parsed from the tag)
|
||||
* and 'output' (the modified input string with `<page>` tags removed).
|
||||
*/
|
||||
function parsePageTag(string $input): array
|
||||
{
|
||||
// Define the pattern for the tag
|
||||
$pattern = '/<page\s+([^>]+)><\/page>/i';
|
||||
@@ -34,8 +55,15 @@ function parsePageTag($input): array
|
||||
// If no match is found, return the original input
|
||||
return ['parameters' => [], 'output' => $input];
|
||||
}
|
||||
|
||||
function renderPage($page_name = null, $site_name = null): array
|
||||
/**
|
||||
* Renders a page based on specified page and site names, handling dynamic and static content,
|
||||
* permissions, and error pages.
|
||||
*
|
||||
* @param string|null $page_name The name of the page to render. If null, uses default from request.
|
||||
* @param string|null $site_name The name of the site to render. If null, uses default from request.
|
||||
* @return array Returns an associative array containing the rendered page content, page name, site name, and page title.
|
||||
*/
|
||||
function renderPage(string $page_name = null, string $site_name = null): array
|
||||
{
|
||||
global $routerConfig;
|
||||
global $routerRequest;
|
||||
@@ -138,8 +166,16 @@ function renderPage($page_name = null, $site_name = null): array
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
function getPage($site_name_in = null, $page_name_in = null): string
|
||||
/**
|
||||
* Compiles a complete web page by injecting dynamic elements into a template skeleton,
|
||||
* including headers, footers, and SEO tags.
|
||||
* It is used when not going to a page by AJAX to initialize everything.
|
||||
*
|
||||
* @param string|null $site_name_in The site name to be used; defaults from global configuration if null.
|
||||
* @param string|null $page_name_in The page name to be used; defaults from global configuration if null.
|
||||
* @return string The complete HTML content of the web page ready for display.
|
||||
*/
|
||||
function getPage(string $site_name_in = null, string $page_name_in = null): string
|
||||
{
|
||||
$page_tmp = renderPage($page_name_in, $site_name_in);
|
||||
|
||||
@@ -223,8 +259,15 @@ function getPage($site_name_in = null, $page_name_in = null): string
|
||||
}
|
||||
return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out);
|
||||
}
|
||||
|
||||
function getPageEndpoint($page_name, $site_name) :array
|
||||
/**
|
||||
* Provides an API interface to get page details including content and meta-information for routing purposes.
|
||||
* This is what enables the page to never refresh.
|
||||
*
|
||||
* @param string $page_name The name of the page.
|
||||
* @param string $site_name The name of the site.
|
||||
* @return array Returns an array with status, page content, location URL, and title for the requested page.
|
||||
*/
|
||||
function getPageEndpoint(string $page_name, string $site_name) :array
|
||||
{
|
||||
$page_location = "/" . $site_name . "/" . $page_name;
|
||||
$page_tmp = renderPage($page_name, $site_name);
|
||||
|
Reference in New Issue
Block a user