is missing
[mailer.git] / inc / modules / admin / what-theme_import.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/12/2004 *
4  * ================                             Last change: 11/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-theme_import.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Import of new themes                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Importieren von neuen Themes                     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (!isExtensionActive('theme')) {
48         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('theme'));
49         return;
50 } // END - if
51
52 // Switch to testing mode
53 $GLOBALS['theme_mode'] = 'test';
54
55 // Import selected theme if not present
56 if (isPostRequestElementSet('theme')) {
57         // Check if theme is there
58         if (!ifThemeExists(postRequestElement('theme'))) {
59                 // Import theme
60                 $inc = sprintf("theme/%s/theme.php", SQL_ESCAPE(postRequestElement('theme')));
61
62                 // Is the theme readable?
63                 if (isIncludeReadable($inc)) {
64                         // Load the theme header file
65                         loadInclude($inc);
66
67                         // Register it ith the exchange
68                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_themes` (`theme_path`,`theme_active`,`theme_ver`,`theme_name`)
69 VALUES ('%s','N','%s','%s')",
70                                 array(
71                                         postRequestElement('theme'),
72                                         $GLOBALS['theme_data']['version'],
73                                         $GLOBALS['theme_data']['name']
74                                 ), __FILE__, __LINE__);
75
76                         // Destroy cache
77                         rebuildCacheFile('themes', 'them');
78
79                         // Prepare message
80                         $message = sprintf(getMessage('ADMIN_THEME_IMPORTED'), postRequestElement('theme'));
81                 } else {
82                         // Include file not found!
83                         $message = sprintf(getMessage('ADMIN_THEME_INC_404'), postRequestElement('theme'));
84                 }
85         } else {
86                 // Theme already imported
87                 $message = sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), postRequestElement('theme'));
88         }
89
90         // Output message
91         loadTemplate('admin_settings_saved', false, $message);
92 } // END - if
93
94 // Initialize array
95 $THEMES = array(
96         'theme_unix'   => array(), // Unix name from filesystem
97         'theme_name'   => array(), // Title
98         'theme_author' => array(), // Theme author's name
99         'theme_email'  => array(), // Author's email address
100         'theme_url'    => array(), // URL were you can download it from
101         'theme_ver'    => array(), // Version number of theme
102 );
103
104 // Read directory "themes"
105 $includes = getArrayFromDirectory('theme/', '', false, true, array('css', 'images'));
106
107 // Walk through all entries and add it
108 foreach ($includes as $inc) {
109         // Get directory from it
110         $dir = basename(dirname($inc));
111
112         // Load include file
113         loadInclude($inc);
114
115         // Add found theme to array
116         $THEMES['theme_unix'][]   = $dir;
117         $THEMES['theme_name'][]   = $GLOBALS['theme_data']['name'];
118         $THEMES['theme_author'][] = $GLOBALS['theme_data']['author'];
119         $THEMES['theme_email'][]  = $GLOBALS['theme_data']['email'];
120         $THEMES['theme_url'][]    = $GLOBALS['theme_data']['url'];
121         $THEMES['theme_ver'][]    = $GLOBALS['theme_data']['version'];
122 } // END - while
123
124 // Sort array by Uni* name
125 array_pk_sort($THEMES, array('theme_name'));
126
127 // Generate output lines for the template
128 $OUT = ''; $SW = 2;
129 foreach ($THEMES['theme_unix'] as $key => $unix) {
130         // Already installed is default
131         $formContent = '<div class="admin_note">' . sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), $unix) . '</div>';
132
133         // Check if current theme is already imported or not
134         if (!ifThemeExists($unix)) {
135                 // Theme not installed
136                 $formContent = loadTemplate('admin_theme_import_form', true, $unix);
137         } // END - if
138
139         // Prepare content
140         $content = array(
141                 'sw'      => $SW,
142                 'unix'    => $unix,
143                 'name'    => $THEMES['theme_name'][$key],
144                 'email'   => $THEMES['theme_email'][$key],
145                 'author'  => $THEMES['theme_author'][$key],
146                 'link'    => generateDerefererUrl($THEMES['theme_url'][$key]),
147                 'url'     => $THEMES['theme_url'][$key],
148                 'version' => $THEMES['theme_ver'][$key],
149                 'form'    => $formContent
150         );
151
152         // Add row template
153         $OUT .= loadTemplate('admin_theme_import_row', true, $content);
154
155         // Switch color
156         $SW = 3 - $SW;
157 } // END - foreach
158
159 if (empty($OUT)) {
160         // No themes found???
161         $OUT .= loadTemplate('admin_theme_import_none', true, loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_THEMES_FOUND')));
162 } // END - if
163
164 // Load template
165 loadTemplate('admin_theme_import', false, $OUT);
166
167 // [EOF]
168 ?>