2015-08-02 04:47:45 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Variables
|
|
|
|
// ============================================================================
|
2023-07-15 15:58:33 +02:00
|
|
|
$themePlugin = getPlugin($site->theme()); // Returns plugin object or False
|
2015-08-02 04:47:45 +02:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
function buildThemes()
|
|
|
|
{
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2016-01-16 15:01:29 +01:00
|
|
|
|
|
|
|
$themes = array();
|
|
|
|
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
|
|
|
|
|
2023-07-15 15:58:33 +02:00
|
|
|
foreach ($themesPaths as $themePath) {
|
2016-01-16 15:01:29 +01:00
|
|
|
// Check if the theme is translated.
|
2023-07-15 15:58:33 +02:00
|
|
|
$languageFilename = $themePath . DS . 'languages' . DS . $site->language() . '.json';
|
|
|
|
if (!Sanitize::pathFile($languageFilename)) {
|
|
|
|
$languageFilename = $themePath . DS . 'languages' . DS . DEFAULT_LANGUAGE_FILE;
|
2016-01-16 15:01:29 +01:00
|
|
|
}
|
|
|
|
|
2023-07-15 15:58:33 +02:00
|
|
|
if (Sanitize::pathFile($languageFilename)) {
|
2016-01-16 15:01:29 +01:00
|
|
|
$database = file_get_contents($languageFilename);
|
|
|
|
$database = json_decode($database, true);
|
2023-07-15 15:58:33 +02:00
|
|
|
if (empty($database)) {
|
|
|
|
Log::set('99.themes.php' . LOG_SEP . 'Language file error on theme ' . $themePath);
|
2016-01-19 03:34:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
$database = $database['theme-data'];
|
|
|
|
|
|
|
|
$database['dirname'] = basename($themePath);
|
2015-08-02 04:47:45 +02:00
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
// --- Metadata ---
|
2023-07-15 15:58:33 +02:00
|
|
|
$filenameMetadata = $themePath . DS . 'metadata.json';
|
2015-08-02 04:47:45 +02:00
|
|
|
|
2023-07-15 15:58:33 +02:00
|
|
|
if (Sanitize::pathFile($filenameMetadata)) {
|
2016-01-16 15:01:29 +01:00
|
|
|
$metadataString = file_get_contents($filenameMetadata);
|
|
|
|
$metadata = json_decode($metadataString, true);
|
|
|
|
|
2016-08-10 01:46:56 +02:00
|
|
|
$database['compatible'] = false;
|
2023-07-15 15:58:33 +02:00
|
|
|
if (!empty($metadata['compatible'])) {
|
2017-05-30 19:18:18 +02:00
|
|
|
$bluditRoot = explode('.', BLUDIT_VERSION);
|
|
|
|
$compatible = explode(',', $metadata['compatible']);
|
2023-07-15 15:58:33 +02:00
|
|
|
foreach ($compatible as $version) {
|
2017-05-30 19:18:18 +02:00
|
|
|
$root = explode('.', $version);
|
2023-07-15 15:58:33 +02:00
|
|
|
if ($root[0] == $bluditRoot[0] && $root[1] == $bluditRoot[1]) {
|
2017-05-30 19:18:18 +02:00
|
|
|
$database['compatible'] = true;
|
|
|
|
}
|
2016-06-21 03:06:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-16 15:01:29 +01:00
|
|
|
|
2016-08-10 01:46:56 +02:00
|
|
|
$database = $database + $metadata;
|
|
|
|
array_push($themes, $database);
|
2016-01-16 15:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $themes;
|
2015-11-29 00:21:04 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
// ============================================================================
|
|
|
|
// Main
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// Load the language file
|
2023-07-15 15:58:33 +02:00
|
|
|
$languageFilename = THEME_DIR . 'languages' . DS . $site->language() . '.json';
|
|
|
|
if (!Sanitize::pathFile($languageFilename)) {
|
|
|
|
$languageFilename = THEME_DIR . 'languages' . DS . DEFAULT_LANGUAGE_FILE;
|
2015-08-02 04:47:45 +02:00
|
|
|
}
|
|
|
|
|
2023-07-15 15:58:33 +02:00
|
|
|
if (Sanitize::pathFile($languageFilename)) {
|
2016-01-16 15:01:29 +01:00
|
|
|
$database = file_get_contents($languageFilename);
|
|
|
|
$database = json_decode($database, true);
|
2015-08-02 04:47:45 +02:00
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
// Remote the name and description.
|
|
|
|
unset($database['theme-data']);
|
2015-08-02 04:47:45 +02:00
|
|
|
|
2016-01-16 15:01:29 +01:00
|
|
|
// Load words from the theme language
|
2023-07-15 15:58:33 +02:00
|
|
|
if (!empty($database)) {
|
2018-08-05 17:54:20 +02:00
|
|
|
$L->add($database);
|
2016-01-16 15:01:29 +01:00
|
|
|
}
|
2023-07-15 15:58:33 +02:00
|
|
|
}
|