Created
November 19, 2013 19:19
-
-
Save MissAllSunday/7550934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_all_themes($enable_only = false) | |
{ | |
global $modSettings, $context, $smcFunc; | |
// Make our known themes a little easier to work with. | |
$knownThemes = !empty($modSettings['knownThemes']) ? explode(',',$modSettings['knownThemes']) : array(); | |
// All of them or just the enable ones? each will have a pretty different query. | |
if ($enable_only) | |
$query = ' | |
SELECT th.value, th.variable, th2.id_theme, th2.variable, th2.value | |
FROM {db_prefix}themes AS th | |
INNER JOIN {db_prefix}themes AS th2 ON (th2.id_theme = th.id_theme | |
AND th2.variable IN ({string:theme_dir}, {string:theme_url}, {string:images_url}, {string:name}, {string:theme_layers}, {string:theme_templates}, {string:version}, {string:install_for}, {string:based_on}, {string:enable})) | |
WHERE th.variable = {string:enable} | |
AND th.value = 1 | |
OR th.id_theme = 1'; | |
else | |
$query = ' | |
SELECT id_theme, variable, value | |
FROM {db_prefix}themes | |
WHERE variable IN ({string:theme_dir}, {string:theme_url}, {string:images_url}, {string:name}, {string:theme_layers}, {string:theme_templates}, {string:version}, {string:install_for}, {string:based_on}, {string:enable}) | |
AND id_member = {int:no_member}'; | |
// Perform the query as requested. | |
$request = $smcFunc['db_query']('', $query, | |
array( | |
'no_member' => 0, | |
'theme_dir' => 'theme_dir', | |
'images_url' => 'images_url', | |
'theme_url' => 'theme_url', | |
'name' => 'name', | |
'theme_layers' => 'theme_layers', | |
'theme_templates' => 'theme_templates', | |
'version' => 'version', | |
'install_for' => 'install_for', | |
'based_on' => 'based_on', | |
'enable' => 'enable', | |
) | |
); | |
$context['themes'] = array(); | |
while ($row = $smcFunc['db_fetch_assoc']($request)) | |
{ | |
$context['themes'][$row['id_theme']]['id'] = (int) $row['id_theme']; | |
// Fix the path and tell if its a valid one. | |
if ($row['variable'] == 'theme_dir') | |
{ | |
$context['themes'][$row['id_theme']][$row['variable']] = realpath($row['value']); | |
$context['themes'][$row['id_theme']]['valid_path'] = file_exists(realpath($row['value'])) && is_dir(realpath($row['value'])); | |
} | |
$context['themes'][$row['id_theme']]['known'] = in_array($row['id_theme'], $knownThemes); | |
$context['themes'][$row['id_theme']][$row['variable']] = $row['value']; | |
} | |
$smcFunc['db_free_result']($request); | |
return $context['themes']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment