1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-29 01:34:31 +01:00
This commit is contained in:
Michael Save 2012-08-13 00:18:13 +10:00
parent 4f83915413
commit 69d9abc8f7
7 changed files with 214 additions and 14 deletions

View File

@ -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,
));
}

View File

@ -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']

View File

@ -10,7 +10,6 @@
{% if board.subtitle %}
<small>&mdash; {{ board.subtitle|e }}</small>
{% endif %}
{% if mod|hasPermission(config.mod.manageboards) %}
<a href="?/edit/{{ board.uri }}"><small>[{% trans 'edit' %}]</small></a>
{% endif %}
@ -78,39 +77,30 @@
{% if reports > 0 %}</strong>{% endif %}
</li>
{% endif %}
{% if mod|hasPermission(config.mod.view_banlist) %}
<li><a href="?/bans">{% trans 'Ban list' %}</a></li>
{% endif %}
{% if mod|hasPermission(config.mod.manageusers) %}
<li><a href="?/users">{% trans 'Manage users' %}</a></li>
{% elseif mod|hasPermission(config.mod.change_password) %}
<li><a href="?/users/{{ mod.id }}">{% trans 'Change password' %}</a></li>
{% endif %}
{% if mod|hasPermission(config.mod.themes) %}
<li><a href="?/themes">{% trans 'Manage themes' %}</a></li>
{% endif %}
{% if mod|hasPermission(config.mod.modlog) %}
<li><a href="?/log">{% trans 'Moderation log' %}</a></li>
{% endif %}
{% if mod|hasPermission(config.mod.rebuild) %}
<li><a href="?/rebuild">{% trans 'Rebuild' %}</a></li>
{% endif %}
{% if mod|hasPermission(config.mod.show_config) %}
<li><a href="?/config">{% trans 'Configuration' %}</a></li>
{% endif %}
</ul>
</fieldset>
{% if mod|hasPermission(config.mod.themes) %}
<fieldset>
<legend>{% trans 'Themes' %}</legend>
{# TODO #}
</fieldset>
{% endif %}
<fieldset>
<legend>{% trans 'Search' %}</legend>

View File

@ -0,0 +1,27 @@
<form action="" method="post">
{% if not config %}
<p style="text-align:center" class="unimportant">(No configuration required.)</p>
{% else %}
<table>
{% for conf in theme.config %}
<tr>
<th>{{ conf.title }}</th>
<td>
<input type="text" name="{{ conf.name }}"
{% if settings[conf.name] %}value="{{ settings[conf.name] }}"{% else %}{% if conf.default %}value="{{ conf.default }}"{% endif %}{% endif %}
{% if conf.size %}
size="{{ conf.size }}"
{% endif %}
/>
{% if conf.comment %}
<span class="unimportant">{{ conf.comment }}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}
<p style="text-align:center">
<input name="install" type="submit" value="{% trans 'Install theme' %}" />
</p>
</form>

View File

@ -0,0 +1,9 @@
{% if message %}
<div style="border:1px dashed maroon;padding:20px;margin:auto;max-width:800px">{{ message }}</div>
{% endif %}
{% if result %}
<p style="text-align:center">{% trans 'Successfully installed and built theme.' %}</p>
{% endif %}
<p style="text-align:center"><a href="?/themes">{% trans 'Go back to themes' %}</a>.</p>

View File

@ -0,0 +1,2 @@
<p style="text-align:center">{{ 'Successfully rebuilt the <strong>%s</strong> theme.'|trans|sprintf(theme_name) }}</p>
<p style="text-align:center"><a href="?/themes">{% trans 'Go back to themes' %}</a>.</p>

40
templates/mod/themes.html Normal file
View File

@ -0,0 +1,40 @@
{% if themes|count == 0 %}
<p style="text-align:center" class="unimportant">({% trans 'There are no themes available.' %})</p>
{% else %}
<table class="modlog">
{% for theme_name, theme in themes %}
<tr>
<th class="minimal">{% trans 'Name' %}</th>
<td>{{ theme.name }}</td>
</tr>
<tr>
<th class="minimal">{% trans 'Version' %}</th>
<td>{{ theme.version }}</td>
</tr>
<tr>
<th class="minimal">{% trans 'Description' %}</th>
<td>{{ theme.description }}</td>
</tr>
<tr>
<th class="minimal">{% trans 'Thumbnail' %}</th>
<td>
<img style="float:none;margin:4px{% if theme_name in themes_in_use %};border:2px solid red;padding:4px{% endif %}" src="{{ config.dir.themes_uri }}/{{ theme_name }}/thumb.png" />
</td>
</tr>
<tr>
<th class="minimal">{% trans 'Actions' %}</th>
<td><ul style="padding:0 20px">
<li><a title=" {% trans 'Use theme' %}" href="?/themes/{{ theme_name }}">
{% if theme_name in themes_in_use %}{% trans 'Reconfigure' %}{% else %}{% trans 'Install' %}{% endif %}
</a></li>
{% if theme_name in themes_in_use %}
<li><a href="?/themes/{{ theme_name }}/rebuild">{% trans 'Rebuild' %}</a></li>
<li><a href="?/themes/{{ theme_name }}/uninstall" onclick="return confirm('Are you sure you want to uninstall this theme?');">{% trans 'Uninstall' %}</a></li>
{% endif %}
</ul></td>
</tr>
<tr style="height:40px"><td colspan="2"><hr/></td></tr>
</tr>
{% endfor %}
</table>
{% endif %}