New naming convention applied to many functions, see #118 for details
[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__, sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), '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                 if (isIncludeReadable($INC)) {
61                         // Load the theme header file
62                         loadInclude($INC);
63
64                         // Register it ith the exchange
65                         SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_themes` (`theme_path`,`theme_active`,`theme_ver`,`theme_name`)
66 VALUES ('%s','N','%s','%s')",
67                                 array(REQUEST_POST('theme'), $GLOBALS['theme_data']['version'], $GLOBALS['theme_data']['name']), __FILE__, __LINE__);
68
69                         // Destroy cache
70                         rebuildCacheFiles("themes", "them");
71
72                         // Prepare message
73                         $msg = sprintf(getMessage('ADMIN_THEME_IMPORTED'), REQUEST_POST('theme'));
74                 } else {
75                         // Include file not found!
76                         $msg = sprintf(getMessage('ADMIN_THEME_INC_404'), REQUEST_POST('theme'));
77                 }
78         } else {
79                 // Theme already imported
80                 $msg = sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), REQUEST_POST('theme'));
81         }
82
83         // Output message
84         LOAD_TEMPLATE('admin_settings_saved', false, $msg);
85 } // END - if
86
87 // Initialize array
88 $THEMES = array(
89         'theme_unix'   => array(), // Unix name from filesystem
90         'theme_name'   => array(), // Title
91         'theme_author' => array(), // Theme author's name
92         'theme_email'  => array(), // Author's email address
93         'theme_url'    => array(), // URL were you can download it from
94         'theme_ver'    => array(), // Version number of theme
95 );
96
97 // Read directory "themes"
98 $handle = opendir(constant('PATH')."theme/") or app_die(__FILE__, __LINE__, "Cannot read themes dir!");
99 while ($dir = readdir($handle)) {
100         // Construct absolute theme.php file name
101         $INC = sprintf("theme/%s/theme.php", $dir);
102
103         // Test it...
104         if ((!isDirectory($dir)) && (isIncludeReadable($INC))) {
105                 // Found a valid directory so let's load it's theme.php file
106                 loadInclude($INC);
107
108                 // Add found theme to array
109                 $THEMES['theme_unix'][]   = $dir;
110                 $THEMES['theme_name'][]   = $GLOBALS['theme_data']['name'];
111                 $THEMES['theme_author'][] = $GLOBALS['theme_data']['author'];
112                 $THEMES['theme_email'][]  = $GLOBALS['theme_data']['email'];
113                 $THEMES['theme_url'][]    = $GLOBALS['theme_data']['url'];
114                 $THEMES['theme_ver'][]    = $GLOBALS['theme_data']['version'];
115         } // END - if
116 } // END - while
117
118 // Close directory
119 closedir($handle);
120
121 // Sort array by Uni* name
122 array_pk_sort($THEMES, array("theme_name"));
123
124 // Generate output lines for the template
125 $OUT = ''; $SW = 2;
126 foreach ($THEMES['theme_unix'] as $key => $unix) {
127         // Already installed is default
128         $FOUND = "<div class=\"admin_note\">{--ADMIN_THEME_ALREADY_INSTALLED--}</div>";
129
130         // Check if current theme is already imported or not
131         if (!ifThemeExists($unix)) {
132                 // Theme not installed
133                 $FOUND = LOAD_TEMPLATE("admin_theme_import_form", true, $unix);
134         } // END - if
135
136         // Prepare content
137         $content = array(
138                 'sw'      => $SW,
139                 'unix'    => $unix,
140                 'name'    => $THEMES['theme_name'][$key],
141                 'email'   => $THEMES['theme_email'][$key],
142                 'author'  => $THEMES['theme_author'][$key],
143                 'link'    => DEREFERER($THEMES['theme_url'][$key]),
144                 'url'     => $THEMES['theme_url'][$key],
145                 'version' => $THEMES['theme_ver'][$key],
146                 'form'    => $FOUND
147         );
148
149         // Add row template
150         $OUT .= LOAD_TEMPLATE("admin_theme_import_row", true, $content);
151
152         // Switch color
153         $SW = 3 - $SW;
154 } // END - foreach
155
156 if (empty($OUT)) {
157         // No themes found???
158         $OUT .= LOAD_TEMPLATE("admin_theme_import_none", true, LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_NO_THEMES_FOUND')));
159 } // END - if
160
161 // Set the generated list
162 define('__THEME_LIST', $OUT);
163
164 // Load template
165 LOAD_TEMPLATE("admin_theme_import");
166
167 //
168 ?>