A lot fixes to templates and missing functions added, more rewrites
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!EXT_IS_ACTIVE("theme")) {
39         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "theme");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", __FILE__);
45
46 // Switch to testing mode
47 $THEME_MODE = "test";
48
49 // Import selected theme if not present
50 if (REQUEST_ISSET_POST(('theme'))) {
51         // Check if theme is there
52         if (!THEME_CHECK_EXIST(REQUEST_POST('theme'))) {
53                 // Import theme
54                 $INC = sprintf("theme/%s/theme.php", SQL_ESCAPE(REQUEST_POST('theme')));
55                 if (INCLUDE_READABLE($INC)) {
56                         // Load the theme header file
57                         LOAD_INC($INC);
58
59                         // Register it ith the exchange
60                         SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_themes` (`theme_path`, `theme_active`, `theme_ver`, `theme_name`)
61 VALUES ('%s','N','%s','%s')",
62                                 array(REQUEST_POST('theme'), $THEME_VERSION, $THEME_NAME), __FILE__, __LINE__);
63
64                         // Destroy cache
65                         REBUILD_CACHE("themes", "them");
66
67                         // Prepare message
68                         $msg = ADMIN_THEME_IMPORTED_1.REQUEST_POST('theme').ADMIN_THEME_IMPORTED_2;
69                 } else {
70                         // Include file not found!
71                         $msg = ADMIN_THEME_INC_404_1.REQUEST_POST('theme').ADMIN_THEME_INC_404_2;
72                 }
73         } else {
74                 // Theme already imported
75                 $msg = ADMIN_THEME_ALREADY_1.REQUEST_POST('theme').ADMIN_THEME_ALREADY_2;
76         }
77
78         // Output message
79         LOAD_TEMPLATE("admin_settings_saved", false, $msg);
80 } // END - if
81
82 // Initialize array
83 $THEMES = array(
84         'theme_unix'   => array(), // Unix name from filesystem
85         'theme_name'   => array(), // Title
86         'theme_author' => array(), // Theme author's name
87         'theme_email'  => array(), // Author's email address
88         'theme_url'    => array(), // URL were you can download it from
89         'theme_ver'    => array(), // Version number of theme
90 );
91
92 // Read directory "themes"
93 $handle = opendir(constant('PATH')."theme/") or mxchange_die("Cannot read themes dir!");
94 while ($dir = readdir($handle)) {
95         // Construct absolute theme.php file name
96         $INC = sprintf("theme/%s/theme.php", $dir);
97
98         // Test it...
99         if (($dir != ".") && ($dir != "..") && (INCLUDE_READABLE($INC))) {
100                 // Found a valid directory so let's load it's theme.php file
101                 LOAD_INC($INC);
102
103                 // Add found theme to array
104                 $THEMES['theme_unix'][]   = $dir;
105                 $THEMES['theme_name'][]   = $THEME_NAME;
106                 $THEMES['theme_author'][] = $THEME_AUTHOR;
107                 $THEMES['theme_email'][]  = $THEME_EMAIL;
108                 $THEMES['theme_url'][]    = $THEME_URL;
109                 $THEMES['theme_ver'][]    = $THEME_VERSION;
110         } // END - if
111 } // END - while
112
113 // Close directory
114 closedir($handle);
115
116 // Sort array by Uni* name
117 array_pk_sort($THEMES, array("theme_name"));
118
119 // Generate output lines for the template
120 $OUT = ""; $SW = 2;
121 foreach ($THEMES['theme_unix'] as $key => $unix) {
122         // Already installed is default
123         $FOUND = "<div class=\"admin_note\">{--ADMIN_THEME_ALREADY_INSTALLED--}</div>";
124
125         // Check if current theme is already imported or not
126         if (!THEME_CHECK_EXIST($unix)) {
127                 // Theme not installed
128                 $FOUND = LOAD_TEMPLATE("admin_theme_import_form", true, $unix);
129         } // END - if
130
131         // Prepare content
132         $content = array(
133                 'sw'      => $SW,
134                 'unix'    => $unix,
135                 'name'    => $THEMES['theme_name'][$key],
136                 'email'   => $THEMES['theme_email'][$key],
137                 'author'  => $THEMES['theme_author'][$key],
138                 'link'    => DEREFERER($THEMES['theme_url'][$key]),
139                 'url'     => $THEMES['theme_url'][$key],
140                 'version' => $THEMES['theme_ver'][$key],
141                 'form'    => $FOUND
142         );
143
144         // Add row template
145         $OUT .= LOAD_TEMPLATE("admin_theme_import_row", true, $content);
146
147         // Switch color
148         $SW = 3 - $SW;
149 } // END - foreach
150
151 if (empty($OUT)) {
152         // No themes found???
153         $OUT .= LOAD_TEMPLATE("admin_theme_import_none", true, LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_NO_THEMES_FOUND')));
154 } // END - if
155
156 // Set the generated list
157 define('__THEME_LIST', $OUT);
158
159 // Load template
160 LOAD_TEMPLATE("admin_theme_import");
161
162 //
163 ?>