Some fixes:
[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 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://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         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Switch to testing mode
47 $GLOBALS['theme_mode'] = 'test';
48
49 // Import selected theme if not present
50 if (isPostRequestElementSet('theme')) {
51         // Check if theme is there
52         if (!ifThemeExists(postRequestElement('theme'))) {
53                 // Import theme
54                 $inc = sprintf("theme/%s/theme.php", sqlEscapeString(postRequestElement('theme')));
55
56                 // Is the theme readable?
57                 if (isIncludeReadable($inc)) {
58                         // Load the theme header file
59                         loadInclude($inc);
60
61                         // Register it ith the exchange
62                         sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_themes` (`theme_path`, `theme_active`, `theme_ver`, `theme_name`)
63 VALUES ('%s','N','%s','%s')",
64                                 array(
65                                         postRequestElement('theme'),
66                                         $GLOBALS['theme_data']['version'],
67                                         $GLOBALS['theme_data']['name']
68                                 ), __FILE__, __LINE__);
69
70                         // Destroy cache
71                         rebuildCache('themes', 'themes');
72
73                         // Prepare message
74                         $message = '{%message,ADMIN_THEME_IMPORTED=' . postRequestElement('theme') . '%}';
75                 } else {
76                         // Include file not found
77                         $message = '{%message,ADMIN_THEME_INC_404=' . postRequestElement('theme') . '%}';
78                 }
79         } else {
80                 // Theme already imported
81                 $message = '{%message,ADMIN_THEME_ALREADY_INSTALLED=' . postRequestElement('theme') . '%}';
82         }
83
84         // Output message
85         displayMessage($message);
86 } // END - if
87
88 // Initialize array
89 $themes = array(
90         'theme_unix'    => array(), // Unix name from filesystem
91         'theme_name'    => array(), // Title
92         'theme_author'  => array(), // Theme author's name
93         'theme_email'   => array(), // Author's email address
94         'theme_url'     => array(), // URL were you can download it from
95         'theme_version' => array(), // Version number of theme
96 );
97
98 // Read directory "themes"
99 $includes = getArrayFromDirectory('theme/', '', FALSE, TRUE, array('css', 'images'));
100
101 // Walk through all entries and add it
102 foreach ($includes as $inc) {
103         // Get directory from it
104         $dir = basename(dirname($inc));
105
106         // Load include file
107         loadInclude($inc);
108
109         // Add found theme to array
110         array_push($themes['theme_unix']   , $dir);
111         array_push($themes['theme_name']   , $GLOBALS['theme_data']['name']);
112         array_push($themes['theme_author'] , $GLOBALS['theme_data']['author']);
113         array_push($themes['theme_email']  , $GLOBALS['theme_data']['email']);
114         array_push($themes['theme_url']    , $GLOBALS['theme_data']['url']);
115         array_push($themes['theme_version'], $GLOBALS['theme_data']['version']);
116 } // END - while
117
118 // Sort array by Uni* name
119 array_pk_sort($themes, array('theme_name'));
120
121 // Generate output lines for the template
122 $OUT = '';
123 foreach ($themes['theme_unix'] as $key => $unix) {
124         // Already installed is default
125         $formContent = '<div class="notice">{%message,ADMIN_THEME_ALREADY_INSTALLED=' . $unix . '%}</div>';
126
127         // Check if current theme is already imported or not
128         if (!ifThemeExists($unix)) {
129                 // Theme not installed
130                 $formContent = loadTemplate('admin_import_theme_form', TRUE, $unix);
131         } // END - if
132
133         // Prepare content
134         $content = array(
135                 'unix'          => $unix,
136                 'theme_name'    => $themes['theme_name'][$key],
137                 'theme_email'   => $themes['theme_email'][$key],
138                 'theme_author'  => $themes['theme_author'][$key],
139                 'theme_url'     => $themes['theme_url'][$key],
140                 'theme_version' => $themes['theme_version'][$key],
141                 'form_content'  => $formContent
142         );
143
144         // Add row template
145         $OUT .= loadTemplate('admin_import_theme_row', TRUE, $content);
146 } // END - foreach
147
148 if (empty($OUT)) {
149         // No themes found???
150         $OUT .= loadTemplate('admin_import_theme_none', TRUE, displayMessage('{--ADMIN_NO_THEMES_FOUND--}', TRUE));
151 } // END - if
152
153 // Load template
154 loadTemplate('admin_import_theme', FALSE, $OUT);
155
156 // [EOF]
157 ?>