diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 72c8c195..ad69ae39 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1667,3 +1667,130 @@ function mod_debug_antispam() { mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args); } +function mod_themes_list() { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + if(!is_dir($config['dir']['themes'])) + error(_('Themes directory doesn\'t exist!')); + if(!$dir = opendir($config['dir']['themes'])) + error(_('Cannot open themes directory; check permissions.')); + + $query = query('SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error()); + $themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN); + + // Scan directory for themes + $themes = array(); + while ($file = readdir($dir)) { + if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) { + $themes[$file] = loadThemeConfig($file); + } + } + closedir($dir); + + mod_page(_('Manage themes'), 'mod/themes.html', array( + 'themes' => $themes, + 'themes_in_use' => $themes_in_use, + )); +} + +function mod_theme_configure($theme_name) { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + if(!$theme = loadThemeConfig($theme_name)) { + error($config['error']['invalidtheme']); + } + + if(isset($_POST['install'])) { + // Check if everything is submitted + foreach($theme['config'] as &$conf) { + if(!isset($_POST[$conf['name']]) && $conf['type'] != 'checkbox') + error(sprintf($config['error']['required'], $c['title'])); + } + + // Clear previous settings + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + + foreach($theme['config'] as &$conf) { + $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, :name, :value)"); + $query->bindValue(':theme', $theme_name); + $query->bindValue(':name', $conf['name']); + $query->bindValue(':value', $_POST[$conf['name']]); + $query->execute() or error(db_error($query)); + } + + $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, NULL, NULL)"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + + $result = true; + $message = false; + if(isset($theme['install_callback'])) { + $ret = $theme['install_callback'](themeSettings($theme_name)); + if($ret && !empty($ret)) { + if(is_array($ret) && count($ret) == 2) { + $result = $ret[0]; + $message = $ret[1]; + } + } + } + + if(!$result) { + // Install failed + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + } + + // Build themes + rebuildThemes('all'); + + mod_page(sprintf(_($result ? 'Installed theme: %s' : 'Installation failed: %s'), $theme['name']), 'mod/theme_installed.html', array( + 'theme_name' => $theme_name, + 'theme' => $theme, + 'result' => $result, + 'message' => $message, + )); + } + + $settings = themeSettings($theme_name); + + mod_page(sprintf(_('Configuring theme: %s'), $theme['name']), 'mod/theme_config.html', array( + 'theme_name' => $theme_name, + 'theme' => $theme, + 'settings' => $settings, + )); +} + +function mod_theme_uninstall($theme_name) { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + + header('Location: ?/themes', true, $config['redirect_http']); +} + +function mod_theme_rebuild($theme_name) { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + rebuildTheme($theme_name, 'all'); + + mod_page(sprintf(_('Rebuilt theme: %s'), $theme_name), 'mod/theme_rebuilt.html', array( + 'theme_name' => $theme_name, + )); +} diff --git a/mod.php b/mod.php index 5fa040ee..52f340d2 100644 --- a/mod.php +++ b/mod.php @@ -65,6 +65,11 @@ $pages = array( '/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread '/(\w+)/move/(\d+)' => 'move', // move thread + '/themes' => 'themes_list', // manage themes + '/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme + '/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme + '/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme + '/config' => 'config', // config editor // these pages aren't listed in the dashboard without $config['debug'] diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 47a25390..30742dc1 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -10,7 +10,6 @@ {% if board.subtitle %} — {{ board.subtitle|e }} {% endif %} - {% if mod|hasPermission(config.mod.manageboards) %} [{% trans 'edit' %}] {% endif %} @@ -78,39 +77,30 @@ {% if reports > 0 %}{% endif %} {% endif %} - {% if mod|hasPermission(config.mod.view_banlist) %}
  • {% trans 'Ban list' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.manageusers) %}
  • {% trans 'Manage users' %}
  • {% elseif mod|hasPermission(config.mod.change_password) %}
  • {% trans 'Change password' %}
  • {% endif %} - + {% if mod|hasPermission(config.mod.themes) %} +
  • {% trans 'Manage themes' %}
  • + {% endif %} {% if mod|hasPermission(config.mod.modlog) %}
  • {% trans 'Moderation log' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.rebuild) %}
  • {% trans 'Rebuild' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.show_config) %}
  • {% trans 'Configuration' %}
  • {% endif %} + -{% if mod|hasPermission(config.mod.themes) %} -
    - {% trans 'Themes' %} - - {# TODO #} -
    -{% endif %} -
    {% trans 'Search' %} diff --git a/templates/mod/theme_config.html b/templates/mod/theme_config.html new file mode 100644 index 00000000..2dbb8397 --- /dev/null +++ b/templates/mod/theme_config.html @@ -0,0 +1,27 @@ +
    + {% if not config %} +

    (No configuration required.)

    + {% else %} + + {% for conf in theme.config %} + + + + + {% endfor %} +
    {{ conf.title }} + + {% if conf.comment %} + {{ conf.comment }} + {% endif %} +
    + {% endif %} +

    + +

    +
    diff --git a/templates/mod/theme_installed.html b/templates/mod/theme_installed.html new file mode 100644 index 00000000..e6beec10 --- /dev/null +++ b/templates/mod/theme_installed.html @@ -0,0 +1,9 @@ +{% if message %} +
    {{ message }}
    +{% endif %} + +{% if result %} +

    {% trans 'Successfully installed and built theme.' %}

    +{% endif %} + +

    {% trans 'Go back to themes' %}.

    diff --git a/templates/mod/theme_rebuilt.html b/templates/mod/theme_rebuilt.html new file mode 100644 index 00000000..b366e7a6 --- /dev/null +++ b/templates/mod/theme_rebuilt.html @@ -0,0 +1,2 @@ +

    {{ 'Successfully rebuilt the %s theme.'|trans|sprintf(theme_name) }}

    +

    {% trans 'Go back to themes' %}.

    diff --git a/templates/mod/themes.html b/templates/mod/themes.html new file mode 100644 index 00000000..b596826d --- /dev/null +++ b/templates/mod/themes.html @@ -0,0 +1,40 @@ +{% if themes|count == 0 %} +

    ({% trans 'There are no themes available.' %})

    +{% else %} + + {% for theme_name, theme in themes %} + + + + + + + + + + + + + + + + + + + + + + + {% endfor %} +
    {% trans 'Name' %}{{ theme.name }}
    {% trans 'Version' %}{{ theme.version }}
    {% trans 'Description' %}{{ theme.description }}
    {% trans 'Thumbnail' %} + +
    {% trans 'Actions' %}

    +{% endif %}