b5a13b47db55ef8498ac815690cdd63b11b64856
[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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!EXT_IS_ACTIVE('theme')) {
44         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('theme'));
45         return;
46 }
47
48 // Add description as navigation point
49 ADD_DESCR('admin', __FILE__);
50
51 // Switch to testing mode
52 $GLOBALS['theme_mode'] = 'test';
53
54 // Import selected theme if not present
55 if (REQUEST_ISSET_POST('theme')) {
56         // Check if theme is there
57         if (!ifThemeExists(REQUEST_POST('theme'))) {
58                 // Import theme
59                 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE(REQUEST_POST('theme')));
60
61                 // Is the theme readable?
62                 if (isIncludeReadable($INC)) {
63                         // Load the theme header file
64                         loadInclude($INC);
65
66                         // Register it ith the exchange
67                         SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_themes` (`theme_path`,`theme_active`,`theme_ver`,`theme_name`)
68 VALUES ('%s','N','%s','%s')",
69                                 array(
70                                         REQUEST_POST('theme'),
71                                         $GLOBALS['theme_data']['version'],
72                                         $GLOBALS['theme_data']['name']
73                                 ), __FILE__, __LINE__);
74
75                         // Destroy cache
76                         rebuildCacheFiles('themes', 'them');
77
78                         // Prepare message
79                         $message = sprintf(getMessage('ADMIN_THEME_IMPORTED'), REQUEST_POST('theme'));
80                 } else {
81                         // Include file not found!
82                         $message = sprintf(getMessage('ADMIN_THEME_INC_404'), REQUEST_POST('theme'));
83                 }
84         } else {
85                 // Theme already imported
86                 $message = sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), REQUEST_POST('theme'));
87         }
88
89         // Output message
90         LOAD_TEMPLATE('admin_settings_saved', false, $message);
91 } // END - if
92
93 // Initialize array
94 $THEMES = array(
95         'theme_unix'   => array(), // Unix name from filesystem
96         'theme_name'   => array(), // Title
97         'theme_author' => array(), // Theme author's name
98         'theme_email'  => array(), // Author's email address
99         'theme_url'    => array(), // URL were you can download it from
100         'theme_ver'    => array(), // Version number of theme
101 );
102
103 // Read directory "themes"
104 $handle = opendir(constant('PATH') . 'theme/') or app_die(__FILE__, __LINE__, 'Cannot read themes dir!');
105 while ($dir = readdir($handle)) {
106         // Construct absolute theme.php file name
107         $INC = sprintf("theme/%s/theme.php", $dir);
108
109         // Test it...
110         if ((!isDirectory($dir)) && (isIncludeReadable($INC))) {
111                 // Found a valid directory so let's load it's theme.php file
112                 loadInclude($INC);
113
114                 // Add found theme to array
115                 $THEMES['theme_unix'][]   = $dir;
116                 $THEMES['theme_name'][]   = $GLOBALS['theme_data']['name'];
117                 $THEMES['theme_author'][] = $GLOBALS['theme_data']['author'];
118                 $THEMES['theme_email'][]  = $GLOBALS['theme_data']['email'];
119                 $THEMES['theme_url'][]    = $GLOBALS['theme_data']['url'];
120                 $THEMES['theme_ver'][]    = $GLOBALS['theme_data']['version'];
121         } // END - if
122 } // END - while
123
124 // Close directory
125 closedir($handle);
126
127 // Sort array by Uni* name
128 array_pk_sort($THEMES, array('theme_name'));
129
130 // Generate output lines for the template
131 $OUT = ''; $SW = 2;
132 foreach ($THEMES['theme_unix'] as $key => $unix) {
133         // Already installed is default
134         $formContent = '<div class="admin_note">' . sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), $unix) . '</div>';
135
136         // Check if current theme is already imported or not
137         if (!ifThemeExists($unix)) {
138                 // Theme not installed
139                 $formContent = LOAD_TEMPLATE('admin_theme_import_form', true, $unix);
140         } // END - if
141
142         // Prepare content
143         $content = array(
144                 'sw'      => $SW,
145                 'unix'    => $unix,
146                 'name'    => $THEMES['theme_name'][$key],
147                 'email'   => $THEMES['theme_email'][$key],
148                 'author'  => $THEMES['theme_author'][$key],
149                 'link'    => DEREFERER($THEMES['theme_url'][$key]),
150                 'url'     => $THEMES['theme_url'][$key],
151                 'version' => $THEMES['theme_ver'][$key],
152                 'form'    => $formContent
153         );
154
155         // Add row template
156         $OUT .= LOAD_TEMPLATE('admin_theme_import_row', true, $content);
157
158         // Switch color
159         $SW = 3 - $SW;
160 } // END - foreach
161
162 if (empty($OUT)) {
163         // No themes found???
164         $OUT .= LOAD_TEMPLATE('admin_theme_import_none', true, LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_NO_THEMES_FOUND')));
165 } // END - if
166
167 // Set the generated list
168 define('__THEME_LIST', $OUT);
169
170 // Load template
171 LOAD_TEMPLATE('admin_theme_import');
172
173 //
174 ?>