]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-theme_import.php
871e94ac4239c64cd73aaac178cb87c7cbeb2ceb
[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(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "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 (!empty($_POST['theme'])) {
51         // Check if theme is there
52         if (!THEME_CHECK_EXIST($_POST['theme'])) {
53                 // Import theme
54                 $file = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($_POST['theme']));
55                 if (FILE_READABLE($file)) {
56                         // Load the theme header file
57                         include($file);
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($_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.$_POST['theme'].ADMIN_THEME_IMPORTED_2;
69                 } else {
70                         // Include file not found!
71                         $msg = ADMIN_THEME_INC_404_1.$_POST['theme'].ADMIN_THEME_INC_404_2;
72                 }
73         } else {
74                 // Theme already imported
75                 $msg = ADMIN_THEME_ALREADY_1.$_POST['theme'].ADMIN_THEME_ALREADY_2;
76         }
77
78         // Output message
79         LOAD_TEMPLATE("admin_settings_saved", false, $msg);
80         OUTPUT_HTML("<br />");
81 } // END - if
82
83 // Initialize array
84 $THEMES = array(
85         'theme_unix'   => array(), // Unix name from filesystem
86         'theme_name'   => array(), // Title
87         'theme_author' => array(), // Theme author's name
88         'theme_email'  => array(), // Author's email address
89         'theme_url'    => array(), // URL were you can download it from
90         'theme_ver'    => array(), // Version number of theme
91 );
92
93 // Read directory "themes"
94 $handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
95 while ($dir = readdir($handle)) {
96         // Construct absolute theme.php file name
97         $theme = sprintf("%stheme/%s/theme.php", PATH, $dir);
98
99         // Test it...
100         if (($dir != ".") && ($dir != "..") && (FILE_READABLE($theme))) {
101                 // Found a valid directory so let's load it's theme.php file
102                 include($theme);
103
104                 // Add found theme to array
105                 $THEMES['theme_unix'][]   = $dir;
106                 $THEMES['theme_name'][]   = $THEME_NAME;
107                 $THEMES['theme_author'][] = $THEME_AUTHOR;
108                 $THEMES['theme_email'][]  = $THEME_EMAIL;
109                 $THEMES['theme_url'][]    = $THEME_URL;
110                 $THEMES['theme_ver'][]    = $THEME_VERSION;
111         } // END - if
112 } // END - while
113
114 // Close directory
115 closedir($handle);
116
117 // Sort array by Uni* name
118 array_pk_sort($THEMES, array("theme_name"));
119
120 // Generate output lines for the template
121 $OUT = ""; $SW = 2;
122 foreach ($THEMES['theme_unix'] as $key => $unix) {
123         // Check if current theme is already imported or not
124         if (THEME_CHECK_EXIST($unix)) {
125                 // Already installed
126                 $FOUND = "<FONT class=\"admin_note\">".ADMIN_THEME_ALREADY_INSTALLED."</FONT>";
127         } else {
128                 // Theme not installed
129                 $FOUND = "<FORM action=\"".URL."/modules.php?module=admin&amp;what=theme_import\" method=\"POST\">
130   <INPUT type=\"submit\" name=\"ok\" class=\"admin_submit\" value=\"".ADMIN_INSTALL_THEME."\">
131   <INPUT type=\"hidden\" name=\"theme\" value=\"".$unix."\">
132 </FORM>";
133         }
134
135         // Add row
136         $OUT .= "<TR>
137   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">".$unix."</TD>
138   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</TD>
139   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
140     <A href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</A>
141   </TD>
142   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
143     <A href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</A>
144   </TD>
145   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</TD>
146   <TD class=\"switch_sw".$SW." bottom2\" align=\"center\">
147     ".$FOUND."
148   </TD>
149 </TR>\n";
150
151         // Switch color
152         $SW = 3 - $SW;
153 }
154
155 if (empty($OUT)) {
156         // No themes found???
157         $OUT .= "<TR>
158   <TD colspan=\"6\" class=\"bottom2\" height=\"80\">
159     ".LOAD_TEMPLATE("admin_settings_saved", true, ADMIN_NO_THEMES_FOUND)."
160   </TD>
161 </TR>\n";
162 } // END - if
163 define('__THEME_LIST', $OUT);
164
165 // Load template
166 LOAD_TEMPLATE("admin_theme_import");
167
168 //
169 ?>