1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250:
<?php
class ThemesManager
{
private static $error = null;
public static function get_installed_themes_map()
{
$themes = array();
foreach (ThemesConfig::load()->get_themes() as $theme) {
$themes[$theme->get_id()] = $theme;
}
ksort($themes);
return $themes;
}
public static function get_installed_themes_map_sorted_by_localized_name()
{
$themes = self::get_installed_themes_map();
try {
usort($themes, array(__CLASS__, 'callback_sort_themes_by_name'));
} catch (IOException $ex) {
}
return $themes;
}
public static function get_activated_themes_map()
{
$activated_themes = array();
foreach (ThemesConfig::load()->get_themes() as $theme) {
if ($theme->is_activated()) {
$activated_themes[$theme->get_id()] = $theme;
}
}
ksort($activated_themes);
return $activated_themes;
}
public static function get_activated_themes_map_sorted_by_localized_name()
{
$themes = self::get_activated_themes_map();
try {
usort($themes, array(__CLASS__, 'callback_sort_themes_by_name'));
} catch (IOException $ex) {
}
return $themes;
}
public static function get_activated_and_authorized_themes_map()
{
$themes = array();
foreach (ThemesConfig::load()->get_themes() as $theme) {
if ($theme->is_activated() && $theme->check_auth()) {
$themes[$theme->get_id()] = $theme;
}
}
ksort($themes);
return $themes;
}
public static function get_activated_and_authorized_themes_map_sorted_by_localized_name()
{
$themes = self::get_activated_and_authorized_themes_map();
try {
usort($themes, array(__CLASS__, 'callback_sort_themes_by_name'));
} catch (IOException $ex) {
}
return $themes;
}
public static function callback_sort_themes_by_name(Theme $theme1, Theme $theme2)
{
if (TextHelper::strtolower($theme1->get_configuration()->get_name()) > TextHelper::strtolower($theme2->get_configuration()->get_name()))
{
return 1;
}
return -1;
}
public static function get_default_theme()
{
return UserAccountsConfig::load()->get_default_theme();
}
public static function get_theme($theme_id)
{
return ThemesConfig::load()->get_theme($theme_id);
}
public static function get_theme_existed($theme_id)
{
if (ThemesConfig::load()->get_theme($theme_id) !== null)
{
return true;
}
return false;
}
public static function install($theme_id, $authorizations = array(), $enable_theme = true)
{
if (!file_exists(PATH_TO_ROOT . '/templates/' . $theme_id . '/config.ini'))
{
self::$error = LangLoader::get_message('misfit.phpboost', 'status-messages-common');
$folder = new Folder(PATH_TO_ROOT . '/templates/' . $theme_id);
$folder->delete();
}
else if (!empty($theme_id) && !self::get_theme_existed($theme_id))
{
$theme = new Theme($theme_id, $authorizations, $enable_theme);
$configuration = $theme->get_configuration();
$theme->set_columns_disabled($configuration->get_columns_disabled());
$phpboost_version = GeneralConfig::load()->get_phpboost_major_version();
if (version_compare($phpboost_version, $configuration->get_compatibility(), '>'))
{
self::$error = LangLoader::get_message('misfit.phpboost', 'status-messages-common');
}
else
{
ThemesConfig::load()->add_theme($theme);
ThemesConfig::save();
}
}
else
{
self::$error = LangLoader::get_message('element.already_exists', 'status-messages-common');
}
}
public static function uninstall($theme_id, $drop_files = false)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$default_theme = self::get_default_theme();
if (self::get_theme($theme_id)->get_id() !== $default_theme)
{
PersistenceContext::get_querier()->update(DB_TABLE_MEMBER, array('theme' => $default_theme),
'WHERE theme=:old_theme', array('old_theme' => $theme_id
));
ThemesConfig::load()->remove_theme_by_id($theme_id);
ThemesConfig::save();
if ($drop_files)
{
$folder = new Folder(PATH_TO_ROOT . '/templates/' . $theme_id);
$folder->delete();
}
AppContext::get_cache_service()->clear_css_cache();
}
}
}
public static function change_visibility($theme_id, $visibility)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$theme = ThemesConfig::load()->get_theme($theme_id);
$theme->set_activated($visibility);
ThemesConfig::load()->update($theme);
ThemesConfig::save();
}
}
public static function change_authorizations($theme_id, Array $authorizations)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$theme = ThemesConfig::load()->get_theme($theme_id);
$theme->set_authorizations($authorizations);
ThemesConfig::load()->update($theme);
ThemesConfig::save();
}
}
public static function change_informations($theme_id, $visibility, Array $authorizations = array(), $columns_disabled = null)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$theme = ThemesConfig::load()->get_theme($theme_id);
$theme->set_activated($visibility);
if (!empty($authorizations))
{
$theme->set_authorizations($authorizations);
}
if ($columns_disabled !== null)
{
$theme->set_columns_disabled($columns_disabled);
}
ThemesConfig::load()->update($theme);
ThemesConfig::save();
}
}
public static function change_columns_disabled($theme_id, ColumnsDisabled $columns_disabled)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$theme = ThemesConfig::load()->get_theme($theme_id);
$theme->set_columns_disabled($columns_disabled);
ThemesConfig::load()->update($theme);
ThemesConfig::save();
}
}
public static function change_customize_interface($theme_id, CustomizeInterface $customize_interface)
{
if (!empty($theme_id) && self::get_theme_existed($theme_id))
{
$theme = ThemesConfig::load()->get_theme($theme_id);
$theme->set_customize_interface($customize_interface);
ThemesConfig::load()->update($theme);
ThemesConfig::save();
}
}
public static function get_error()
{
return self::$error;
}
}
?>