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')));
60 if (isIncludeReadable($INC)) {
61 // Load the theme header file
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__);
70 rebuildCacheFiles("themes", "them");
73 $msg = sprintf(getMessage('ADMIN_THEME_IMPORTED'), REQUEST_POST('theme'));
75 // Include file not found!
76 $msg = sprintf(getMessage('ADMIN_THEME_INC_404'), REQUEST_POST('theme'));
79 // Theme already imported
80 $msg = sprintf(getMessage('ADMIN_THEME_ALREADY_INSTALLED'), REQUEST_POST('theme'));
84 LOAD_TEMPLATE('admin_settings_saved', false, $msg);
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
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);
104 if ((!isDirectory($dir)) && (isIncludeReadable($INC))) {
105 // Found a valid directory so let's load it's theme.php file
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'];
121 // Sort array by Uni* name
122 array_pk_sort($THEMES, array("theme_name"));
124 // Generate output lines for the template
126 foreach ($THEMES['theme_unix'] as $key => $unix) {
127 // Already installed is default
128 $FOUND = "<div class=\"admin_note\">{--ADMIN_THEME_ALREADY_INSTALLED--}</div>";
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);
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],
150 $OUT .= LOAD_TEMPLATE("admin_theme_import_row", true, $content);
157 // No themes found???
158 $OUT .= LOAD_TEMPLATE("admin_theme_import_none", true, LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_NO_THEMES_FOUND')));
161 // Set the generated list
162 define('__THEME_LIST', $OUT);
165 LOAD_TEMPLATE("admin_theme_import");