bludit/bl-kernel/boot/rules/99.themes.php

95 lines
2.6 KiB
PHP

<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
// ============================================================================
// Functions
// ============================================================================
function buildThemes()
{
global $Site;
$themes = array();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach($themesPaths as $themePath)
{
// Check if the theme is translated.
$languageFilename = $themePath.DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = $themePath.DS.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
if(empty($database)) {
Log::set('99.themes.php'.LOG_SEP.'JSON Error on theme '.$themePath);
break;
}
$database = $database['theme-data'];
$database['dirname'] = basename($themePath);
// --- Metadata ---
$filenameMetadata = $themePath.DS.'metadata.json';
if( Sanitize::pathFile($filenameMetadata) )
{
$metadataString = file_get_contents($filenameMetadata);
$metadata = json_decode($metadataString, true);
if(empty($metadata)) {
Log::set('99.themes.php'.LOG_SEP.'JSON Error on theme '.$themePath);
break;
}
// Check if the theme is compatible
if(empty($metadata['compatible'])) {
Log::set('99.themes.php'.LOG_SEP.'Metadata error, field compatible invalid '.$themePath);
break;
}
$explode = explode(',', $metadata['compatible']);
if(!in_array(BLUDIT_VERSION, $explode)) {
Log::set('99.themes.php'.LOG_SEP.'Theme incompatible '.$themePath);
break;
}
// Theme data
$database = $database + $metadata;
array_push($themes, $database);
}
}
}
return $themes;
}
// ============================================================================
// Main
// ============================================================================
// Load the language file
$languageFilename = PATH_THEME.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = PATH_THEME.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
// Remote the name and description.
unset($database['theme-data']);
// Load words from the theme language
if(!empty($database)) {
$Language->add($database);
}
}