Skip to content

Commit

Permalink
feature 1514: improvement, impossible to delete a theme that is required
Browse files Browse the repository at this point in the history
by another installed theme.

git-svn-id: http://piwigo.org/svn/trunk@5258 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Mar 22, 2010
1 parent cf9af7d commit 15499d5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
32 changes: 32 additions & 0 deletions admin/include/themes.class.php
Expand Up @@ -140,6 +140,19 @@ function perform_action($action, $theme_id)
// nothing to do here
break;
}

$children = $this->get_children_themes($theme_id);
if (count($children) > 0)
{
array_push(
$errors,
sprintf(
l10n('Impossible to delete this theme. Other themes depends on it: %s'),
implode(', ', $children)
)
);
break;
}

if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id))
{
Expand All @@ -155,6 +168,21 @@ function perform_action($action, $theme_id)
return $errors;
}

function get_children_themes($theme_id)
{
$children = array();

foreach ($this->fs_themes as $test_child)
{
if (isset($test_child['parent']) and $test_child['parent'] == $theme_id)
{
array_push($children, $test_child['name']);
}
}

return $children;
}

function set_default_theme($theme_id)
{
// first we need to know which users are using the current default theme
Expand Down Expand Up @@ -267,6 +295,10 @@ function get_fs_themes()
list( , $extension) = explode('extension_view.php?eid=', $theme['uri']);
if (is_numeric($extension)) $theme['extension'] = $extension;
}
if (preg_match('/["\']parent["\'][^"\']+["\']([^"\']+)["\']/', $theme_data, $val))
{
$theme['parent'] = $val[1];
}

// screenshot
$screenshot_path = $path.'/screenshot.png';
Expand Down
2 changes: 1 addition & 1 deletion admin/themes/default/template/footer.tpl
Expand Up @@ -45,7 +45,7 @@
{literal}
<script type='text/javascript'>
$(function() {
$('#pwgHead A, #footer A, .themeActions A').tipTip({
$('#pwgHead A, #footer A, .themeActions A, .themeActions SPAN').tipTip({
'delay' : 0,
'fadeIn' : 200,
'fadeOut' : 200,
Expand Down
15 changes: 12 additions & 3 deletions admin/themes/default/template/themes_installed.tpl
Expand Up @@ -4,7 +4,8 @@

<div id="themesContent">

<h3>Active Themes</h3>
<fieldset>
<legend>Active Themes</legend>
{if isset($active_themes)}
<div class="themeBoxes">
{foreach from=$active_themes item=theme}
Expand All @@ -21,22 +22,30 @@
{/foreach}
</div> <!-- themeBoxes -->
{/if}
</fieldset>

{if isset($inactive_themes)}
<h3>Inactive Themes</h3>
<fieldset>
<legend>Inactive Themes</legend>
<div class="themeBoxes">
{foreach from=$inactive_themes item=theme}
<div class="themeBox">
<div class="themeName">{$theme.name}</div>
<div class="themeShot"><img src="{$theme.screenshot}"></div>
<div class="themeActions">
<a href="{$activate_baseurl}{$theme.id}" title="{'Make this theme available to users'|@translate}">{'Activate'|@translate}</a>
| <a href="{$delete_baseurl}{$theme.id}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'Delete this theme'|@translate}">{'Delete'|@translate}</a>
|
{if $theme.deletable}
<a href="{$delete_baseurl}{$theme.id}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" title="{'Delete this theme'|@translate}">{'Delete'|@translate}</a>
{else}
<span title="{$theme.delete_tooltip}">{'Delete'|@translate}</span>
{/if}
</div>

</div>
{/foreach}
</div> <!-- themeBoxes -->
</fieldset>
{/if}

</div> <!-- themesContent -->
18 changes: 17 additions & 1 deletion admin/themes_installed.php
Expand Up @@ -68,7 +68,7 @@
$active_themes = array();
$inactive_themes = array();

foreach($themes->fs_themes as $theme_id => $fs_theme)
foreach ($themes->fs_themes as $theme_id => $fs_theme)
{
if ($theme_id == 'default')
{
Expand All @@ -89,6 +89,22 @@
}
else
{
$children = $themes->get_children_themes($theme_id);

if (count($children) > 0)
{
$fs_theme['deletable'] = false;

$fs_theme['delete_tooltip'] = sprintf(
l10n('Impossible to delete this theme. Other themes depends on it: %s'),
implode(', ', $children)
);
}
else
{
$fs_theme['deletable'] = true;
}

array_push($inactive_themes, $fs_theme);
}
}
Expand Down

0 comments on commit 15499d5

Please sign in to comment.