Renamed function so it might be more understandable
[mailer.git] / inc / modules / admin / what-theme_import.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (!isExtensionActive('theme')) {
47         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('theme'));
48         return;
49 } // END - if
50
51 // Switch to testing mode
52 $GLOBALS['theme_mode'] = 'test';
53
54 // Import selected theme if not present
55 if (isPostRequestParameterSet('theme')) {
56         // Check if theme is there
57         if (!ifThemeExists(postRequestParameter('theme'))) {
58                 // Import theme
59                 $inc = sprintf("theme/%s/theme.php", SQL_ESCAPE(postRequestParameter('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                                         postRequestParameter('theme'),
71                                         $GLOBALS['theme_data']['version'],
72                                         $GLOBALS['theme_data']['name']
73                                 ), __FILE__, __LINE__);
74
75                         // Destroy cache
76                         rebuildCache('themes', 'them');
77
78                         // Prepare message
79                         $message = getMaskedMessage('ADMIN_THEME_IMPORTED', postRequestParameter('theme'));
80                 } else {
81                         // Include file not found!
82                         $message = getMaskedMessage('ADMIN_THEME_INC_404', postRequestParameter('theme'));
83                 }
84         } else {
85                 // Theme already imported
86                 $message = getMaskedMessage('ADMIN_THEME_ALREADY_INSTALLED', postRequestParameter('theme'));
87         }
88
89         // Output message
90         loadTemplate('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_version' => array(), // Version number of theme
101 );
102
103 // Read directory "themes"
104 $includes = getArrayFromDirectory('theme/', '', false, true, array('css', 'images'));
105
106 // Walk through all entries and add it
107 foreach ($includes as $inc) {
108         // Get directory from it
109         $dir = basename(dirname($inc));
110
111         // Load include 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_version'][]    = $GLOBALS['theme_data']['version'];
121 } // END - while
122
123 // Sort array by Uni* name
124 array_pk_sort($THEMES, array('theme_name'));
125
126 // Generate output lines for the template
127 $OUT = '';
128 foreach ($THEMES['theme_unix'] as $key => $unix) {
129         // Already installed is default
130         $formContent = '<div class="notice">' . getMaskedMessage('ADMIN_THEME_ALREADY_INSTALLED', $unix) . '</div>';
131
132         // Check if current theme is already imported or not
133         if (!ifThemeExists($unix)) {
134                 // Theme not installed
135                 $formContent = loadTemplate('admin_import_theme_form', true, $unix);
136         } // END - if
137
138         // Prepare content
139         $content = array(
140                 'unix'          => $unix,
141                 'theme_name'    => $THEMES['theme_name'][$key],
142                 'theme_email'   => $THEMES['theme_email'][$key],
143                 'theme_author'  => $THEMES['theme_author'][$key],
144                 'theme_url'     => $THEMES['theme_url'][$key],
145                 'theme_version' => $THEMES['theme_version'][$key],
146                 'form_content'  => $formContent
147         );
148
149         // Add row template
150         $OUT .= loadTemplate('admin_import_theme_row', true, $content);
151 } // END - foreach
152
153 if (empty($OUT)) {
154         // No themes found???
155         $OUT .= loadTemplate('admin_import_theme_none', true, loadTemplate('admin_settings_saved', true, '{--ADMIN_NO_THEMES_FOUND--}'));
156 } // END - if
157
158 // Load template
159 loadTemplate('admin_import_theme', false, $OUT);
160
161 // [EOF]
162 ?>