♻️ improve content file listing

This commit is contained in:
DrMaxNix 2024-02-19 19:12:32 +01:00
parent 368690888a
commit 936402ade6
1 changed files with 43 additions and 7 deletions

View File

@ -363,13 +363,11 @@
/**
* HELPER: Read one content file.
* HELPER: List all available content files.
*
* @param string $name Name of the content file to read.
*
* @return array Content file data.
* @return array List of content file names.
*/
private static function content_file_read(string $name): array {
private static function content_file_list(): array {
// GET AVAILABLE CONTENT FILES //
$indir = scandir("./newsletter/content");
$content_file_list = [];
@ -379,13 +377,51 @@
$path = "./newsletter/content/" . $one_element;
if(!is_file($path)) continue;
// check extension
if(substr($one_element, strlen($one_element) - strlen(".data.php")) !== ".data.php") continue;
// check file name format
if(!preg_match("/\d{4}-\d{2}-\d{2}(-[a-z0-9]+)+\.data\.php/", $one_element)) continue;
// add to list
$content_file_list[] = $one_element;
}
// return list
return $content_file_list;
}
/**
* HELPER: List all available content names.
*
* @return array List of content names.
*/
public static function content_list(): array {
// get available content files
$content_file_list = self::content_file_list();
// remove file extension
$content_name_list = [];
foreach($content_file_list as $one_content_file){
$content_name_list[] = substr($one_content_file, 0, strlen($one_content_file) - strlen(".data.php"));
}
// return list
return $content_name_list;
}
/**
* HELPER: Read one content file.
*
* @param string $name Name of the content file to read.
*
* @return array Content file data.
*/
private static function content_file_read(string $name): array {
// GET AVAILABLE CONTENT FILES //
$content_file_list = self::content_file_list();
// PARSE FILE //
// build content file name