2 /************************************************************************
3 * MXChange v0.2.1 Start: 02/12/2004 *
4 * ================ Last change: 11/12/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-theme_import.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Import of new themes *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Importieren von neuen Themes *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43 } elseif (!EXT_IS_ACTIVE('theme')) {
44 addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('theme'));
48 // Add description as navigation point
49 ADD_DESCR('admin', __FILE__);
51 // Switch to testing mode
52 $GLOBALS['theme_mode'] = 'test';
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'))) {
59 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE(REQUEST_POST('theme')));
61 // Is the theme readable?
62 if (isIncludeReadable($INC)) {
63 // Load the theme header file
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')",
70 REQUEST_POST('theme'),
71 $GLOBALS['theme_data']['version'],
72 $GLOBALS['theme_data']['name']
73 ), __FILE__, __LINE__);
76 rebuildCacheFiles('themes', 'them');
79 $message = sprintf(getMessage('ADMIN_THEME_IMPORTED'), REQUEST_POST('theme'));
81 // Include file not found!
82 $message = sprintf(getMessage('ADMIN_THEME_INC_404'), REQUEST_POST('theme'));
85 // Theme already imported
86 $message = sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), REQUEST_POST('theme'));
90 LOAD_TEMPLATE('admin_settings_saved', false, $message);
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
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);
110 if ((!isDirectory($dir)) && (isIncludeReadable($INC))) {
111 // Found a valid directory so let's load it's theme.php file
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'];
127 // Sort array by Uni* name
128 array_pk_sort($THEMES, array('theme_name'));
130 // Generate output lines for the template
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>';
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);
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
156 $OUT .= LOAD_TEMPLATE('admin_theme_import_row', true, $content);
163 // No themes found???
164 $OUT .= LOAD_TEMPLATE('admin_theme_import_none', true, LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_NO_THEMES_FOUND')));
167 // Set the generated list
168 define('__THEME_LIST', $OUT);
171 LOAD_TEMPLATE('admin_theme_import');