]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/what-theme_import.php
Missing theme extension fixed in theme_edit/theme_import
[mailer.git] / inc / modules / admin / what-theme_import.php
index 3bd1ce95bfe09d98e7d9896e7b1ca5f4ed858223..8d8e5de725bf5bc60a714edd222ed0863588d776 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin()))
-{
+if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
+} elseif (!EXT_IS_ACTIVE("theme")) {
+       ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "theme"));
+       return;
 }
 
 // Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+ADD_DESCR("admin", __FILE__);
 
 // Switch to testing mode
 $THEME_MODE = "test";
 
 // Import selected theme if not present
-if (!empty($_POST['theme']))
-{
-       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' LIMIT 1",
-        array($_POST['theme']), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0)
-       {
+if (!empty($_POST['theme'])) {
+       // Check if theme is there
+       if (!THEME_CHECK_EXIST($_POST['theme'])) {
                // Import theme
-               $file = PATH."theme/".$_POST['theme']."/theme.php";
-               if (file_exists($file))
-               {
+               $file = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($_POST['theme']));
+               if (FILE_READABLE($file)) {
+                       // Load the theme header file
                        include($file);
-                       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_themes (theme_path, theme_active, theme_ver)
-VALUES ('%s', 'N', '%s')",
- array($_POST['theme'], $THEME_VERSION), __FILE__, __LINE__);
+
+                       // Register it ith the exchange
+                       $result = SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_themes` (`theme_path`, `theme_active`, `theme_ver`, `theme_name`)
+VALUES ('%s','N','%s','%s')",
+                               array($_POST['theme'], $THEME_VERSION, $THEME_NAME), __FILE__, __LINE__);
+
+                       // Destroy cache
+                       REBUILD_CACHE("themes", "them");
+
+                       // Prepare message
                        $msg = ADMIN_THEME_IMPORTED_1.$_POST['theme'].ADMIN_THEME_IMPORTED_2;
-               }
-                else
-               {
+               } else {
                        // Include file not found!
                        $msg = ADMIN_THEME_INC_404_1.$_POST['theme'].ADMIN_THEME_INC_404_2;
                }
-       }
-        else
-       {
-               // Free memory
-               SQL_FREERESULT($result);
-
+       } else {
                // Theme already imported
                $msg = ADMIN_THEME_ALREADY_1.$_POST['theme'].ADMIN_THEME_ALREADY_2;
        }
 
        // Output message
        LOAD_TEMPLATE("admin_settings_saved", false, $msg);
-       OUTPUT_HTML("<BR>");
-}
+       OUTPUT_HTML("<br />");
+} // END - if
 
 // Initialize array
 $THEMES = array(
@@ -93,14 +92,12 @@ $THEMES = array(
 
 // Read directory "themes"
 $handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
-while ($dir = readdir($handle))
-{
+while ($dir = readdir($handle)) {
        // Construct absolute theme.php file name
-       $theme = PATH."theme/".$dir."/"."theme.php";
+       $theme = sprintf("%stheme/%s/theme.php", PATH, $dir);
 
        // Test it...
-       if (($dir != ".") && ($dir != "..") && (file_exists($theme)))
-       {
+       if (($dir != ".") && ($dir != "..") && (FILE_READABLE($theme))) {
                // Found a valid directory so let's load it's theme.php file
                include($theme);
 
@@ -111,8 +108,10 @@ while ($dir = readdir($handle))
                $THEMES['theme_email'][]  = $THEME_EMAIL;
                $THEMES['theme_url'][]    = $THEME_URL;
                $THEMES['theme_ver'][]    = $THEME_VERSION;
-       }
-}
+       } // END - if
+} // END - while
+
+// Close directory
 closedir($handle);
 
 // Sort array by Uni* name
@@ -120,21 +119,12 @@ array_pk_sort($THEMES, array("theme_name"));
 
 // Generate output lines for the template
 $OUT = ""; $SW = 2;
-foreach ($THEMES['theme_unix'] as $key=>$unix)
-{
+foreach ($THEMES['theme_unix'] as $key => $unix) {
        // Check if current theme is already imported or not
-       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' LIMIT 1",
-        array($unix), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
-               // Free memory
-               SQL_FREERESULT($result);
-
+       if (THEME_CHECK_EXIST($unix)) {
                // Already installed
                $FOUND = "<FONT class=\"admin_note\">".ADMIN_THEME_ALREADY_INSTALLED."</FONT>";
-       }
-        else
-       {
+       } else {
                // Theme not installed
                $FOUND = "<FORM action=\"".URL."/modules.php?module=admin&amp;what=theme_import\" method=\"POST\">
   <INPUT type=\"submit\" name=\"ok\" class=\"admin_submit\" value=\"".ADMIN_INSTALL_THEME."\">
@@ -157,17 +147,19 @@ foreach ($THEMES['theme_unix'] as $key=>$unix)
     ".$FOUND."
   </TD>
 </TR>\n";
+
+       // Switch color
        $SW = 3 - $SW;
 }
-if (empty($OUT))
-{
-       // No themes found???
+
+if (empty($OUT)) {
+       // No themes found???
        $OUT .= "<TR>
   <TD colspan=\"6\" class=\"bottom2\" height=\"80\">
     ".LOAD_TEMPLATE("admin_settings_saved", true, ADMIN_NO_THEMES_FOUND)."
   </TD>
 </TR>\n";
-}
+} // END - if
 define('__THEME_LIST', $OUT);
 
 // Load template