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