source: trunk/admin/themes_installed.php @ 23259

Last change on this file since 23259 was 23259, checked in by mistic100, 11 years ago

feature:2884 Display "i" tooltip on themes
+ simplify layout (like plugins_installed)

File size: 5.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
30
31$base_url = get_root_url().'admin.php?page='.$page['page'];
32
33$themes = new themes();
34
35// +-----------------------------------------------------------------------+
36// |                          perform actions                              |
37// +-----------------------------------------------------------------------+
38
39if (isset($_GET['action']) and isset($_GET['theme']))
40{
41  $page['errors'] = $themes->perform_action($_GET['action'], $_GET['theme']);
42
43  if (empty($page['errors']))
44  {
45    if ($_GET['action'] == 'activate' or $_GET['action'] == 'deactivate')
46    {
47      $template->delete_compiled_templates();
48    }
49    redirect($base_url);
50  }
51}
52
53// +-----------------------------------------------------------------------+
54// |                     start template output                             |
55// +-----------------------------------------------------------------------+
56
57$themes->sort_fs_themes();
58
59$default_theme = get_default_theme();
60
61$db_themes = $themes->get_db_themes();
62$db_theme_ids = array();
63foreach ($db_themes as $db_theme)
64{
65  array_push($db_theme_ids, $db_theme['id']);
66}
67
68$tpl_themes = array();
69
70foreach ($themes->fs_themes as $theme_id => $fs_theme)
71{
72  if ($theme_id == 'default')
73  {
74    continue;
75  }
76 
77  $tpl_theme = array(
78    'ID' => $theme_id,
79    'NAME' => $fs_theme['name'],
80    'VISIT_URL' => $fs_theme['uri'],
81    'VERSION' => $fs_theme['version'],
82    'DESC' => $fs_theme['description'],
83    'AUTHOR' => $fs_theme['author'],
84    'AUTHOR_URL' => @$fs_theme['author uri'],
85    'PARENT' => @$fs_theme['parent'],
86    'SCREENSHOT' => $fs_theme['screenshot'],
87    'IS_MOBILE' => $fs_theme['mobile'],
88    'ADMIN_URI' => @$fs_theme['admin_uri'],
89    );
90
91  if (in_array($theme_id, $db_theme_ids))
92  {
93    $tpl_theme['STATE'] = 'active';
94    $tpl_theme['DEACTIVABLE'] = true;
95
96    if (count($db_theme_ids) <= 1)
97    {
98      $tpl_theme['DEACTIVABLE'] = false;
99      $tpl_theme['DEACTIVATE_TOOLTIP'] = l10n('Impossible to deactivate this theme, you need at least one theme.');
100    }
101   
102    $tpl_theme['IS_DEFAULT'] = ($theme_id == $default_theme);
103  }
104  else
105  {
106    $tpl_theme['STATE'] = 'inactive';
107   
108    // is the theme "activable" ?
109    if (isset($fs_theme['activable']) and !$fs_theme['activable'])
110    {
111      $tpl_theme['ACTIVABLE'] = false;
112      $tpl_theme['ACTIVABLE_TOOLTIP'] = l10n('This theme was not designed to be directly activated');
113    }
114    else
115    {
116      $tpl_theme['ACTIVABLE'] = true;
117    }
118
119    $missing_parent = $themes->missing_parent_theme($theme_id);
120    if (isset($missing_parent))
121    {
122      $tpl_theme['ACTIVABLE'] = false;
123
124      $tpl_theme['ACTIVABLE_TOOLTIP'] = sprintf(
125        l10n('Impossible to activate this theme, the parent theme is missing: %s'),
126        $missing_parent
127        );
128    }
129
130    // is the theme "deletable" ?
131    $children = $themes->get_children_themes($theme_id);
132
133    $tpl_theme['DELETABLE'] = true;
134
135    if (count($children) > 0)
136    {
137      $tpl_theme['DELETABLE'] = false;
138
139      $tpl_theme['DELETE_TOOLTIP'] = sprintf(
140        l10n('Impossible to delete this theme. Other themes depends on it: %s'),
141        implode(', ', $children)
142        );
143    }
144  }
145 
146  array_push($tpl_themes, $tpl_theme);
147}
148
149// sort themes by state then by name
150function cmp($a, $b)
151{ 
152  $s = array('active' => 0, 'inactive' => 1);
153 
154  if (@$a['IS_DEFAULT']) return -1;
155  if (@$b['IS_DEFAULT']) return 1;
156 
157  if($a['STATE'] == $b['STATE'])
158    return strcasecmp($a['NAME'], $b['NAME']); 
159  else
160    return $s[$a['STATE']] >= $s[$b['STATE']]; 
161}
162usort($tpl_themes, 'cmp');
163
164$template->assign(
165    array(
166      'activate_baseurl' => $base_url.'&amp;action=activate&amp;theme=',
167      'deactivate_baseurl' => $base_url.'&amp;action=deactivate&amp;theme=',
168      'set_default_baseurl' => $base_url.'&amp;action=set_default&amp;theme=',
169      'delete_baseurl' => $base_url.'&amp;action=delete&amp;theme=',
170
171      'tpl_themes' => $tpl_themes,
172    )
173  );
174
175
176$template->set_filenames(array('themes' => 'themes_installed.tpl'));
177$template->assign_var_from_handle('ADMIN_CONTENT', 'themes');
178?>
Note: See TracBrowser for help on using the repository browser.