A lot code rewritten:
[mailer.git] / inc / modules / member / what-themes.php
index fe74c42d26aba336d4cd9a3e52887cb3e66af62e..f7381e612ba3d4b036de2d4fa3e20cf64db44b18 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 03/20/2005 *
- * ================                             Last change: 03/20/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 03/20/2005 *
+ * ===================                          Last change: 03/20/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-themes.php                                  *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Design-Auswahl fuer Mitglieder                   *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
- elseif (!IS_LOGGED_IN())
-{
-       LOAD_URL(URL."/modules.php?module=index");
+if (!defined('__SECURITY')) {
+       die();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR("member", basename(__FILE__));
+addMenuDescription('member', __FILE__);
 
-if (!empty($_POST['member_theme']))
-{
+if ((!isExtensionActive('theme')) && (!isAdmin())) {
+       loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('theme'));
+       return;
+} // END - if
+
+if (isPostRequestParameterSet('member_theme')) {
        // Save theme to member's profile
-       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET curr_theme='%s' WHERE userid=%d LIMIT 1",
-         array($_POST['member_theme'], $GLOBALS['userid']), __FILE__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `curr_theme`='%s' WHERE `userid`=%s LIMIT 1",
+               array(postRequestParameter('member_theme'), getMemberId()), __FILE__, __LINE__);
 
        // Set new theme for guests
-       $NewTheme = $_POST['member_theme'];
+       $newTheme = SQL_ESCAPE(postRequestParameter('member_theme'));
 
        // Change to new theme
-       @setcookie("mxchange_theme", $NewTheme, (time() + 60*60*24*365), COOKIE_PATH);
-       $_COOKIE['mxchange_theme'] = $NewTheme;
+       setTheme($newTheme);
 
        // Theme saved!
-       LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_THEME_SAVED);
-}
+       loadTemplate('admin_settings_saved', false, '{--MEMBER_THEME_SAVED--}');
+} // END - if
 
 // Initialize array
 $THEMES = array(
-       'theme_unix'   => array(), // Unix name from filesystem
-       'theme_name'   => array(), // Title
-       'theme_author' => array(), // Theme author's name
-       'theme_email'  => array(), // Author's email address
-       'theme_url'    => array(), // URL were you can download it from
-       'theme_ver'    => array(), // Version number of theme
+       'theme_unix'    => array(), // Unix name from filesystem
+       'theme_name'    => array(), // Title
+       'theme_author'  => array(), // Theme author's name
+       'theme_email'   => array(), // Author's email address
+       'theme_url'     => array(), // URL were you can download it from
+       'theme_version' => array(), // Version number of theme
 );
 
 // Read directory "themes"
-$handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
-while ($dir = readdir($handle))
-{
-       // Construct absolute theme.php file name
-       $theme = PATH."theme/".$dir."/"."theme.php";
+$includes = getArrayFromDirectory('theme/', '', false, true, array('css', 'images'));
 
-       // Test it...
-       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
-        array($dir), __FILE__, __LINE__);
-
-       if (($dir != ".") && ($dir != "..") && (file_exists($theme)) && (is_readable($theme)) && (SQL_NUMROWS($result) == 1))
-       {
-               // Free memory
-               SQL_FREERESULT($result);
+// Walk through all entries and add it
+foreach ($includes as $inc) {
+       // Get directory from it
+       $dir = basename(dirname($inc));
 
+       // Is the theme active, then include it
+       if (isThemeActive($dir)) {
                // Found a valid directory so let's load it's theme.php file
-               include($theme);
+               loadInclude($inc);
 
                // Add found theme to array
-               $THEMES['theme_unix'][]   = $dir;
-               $THEMES['theme_name'][]   = $THEME_NAME;
-               $THEMES['theme_author'][] = $THEME_AUTHOR;
-               $THEMES['theme_email'][]  = $THEME_EMAIL;
-               $THEMES['theme_url'][]    = $THEME_URL;
-               $THEMES['theme_ver'][]    = $THEME_VERSION;
-       }
-}
-closedir($handle);
+               $THEMES['theme_unix'][]    = $dir;
+               $THEMES['theme_name'][]    = $GLOBALS['theme_data']['name'];
+               $THEMES['theme_author'][]  = $GLOBALS['theme_data']['author'];
+               $THEMES['theme_email'][]   = $GLOBALS['theme_data']['email'];
+               $THEMES['theme_url'][]     = $GLOBALS['theme_data']['url'];
+               $THEMES['theme_version'][] = $GLOBALS['theme_data']['version'];
+       } // END - if
+} // END - while
+
+// Remove last theme data
+unset($GLOBALS['theme_data']);
 
 // Sort array by Uni* name
-array_pk_sort($THEMES, array("theme_name"));
+array_pk_sort($THEMES, array('theme_name'));
 
 // Generate output lines for the template
-$OUT = ""; $SW = 2;
-foreach ($THEMES['theme_unix'] as $key=>$unix)
-{
-       $default = "";
-       if ($_COOKIE['mxchange_theme'] == $unix) $default = " checked selected";
+$OUT = '';
+foreach ($THEMES['theme_unix'] as $key => $unix) {
+       $default = '';
+       if (getCurrentTheme() == $unix) $default = ' selected="selected"';
 
        // Add row
-       $OUT .= "<TR>
-  <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">
-    <INPUT type=\"radio\" name=\"member_theme\" class=\"member_normal\" value=\"".$unix."\"".$default.">
-  </TD>
-  <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</TD>
-  <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
-    <A href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</A>
-  </TD>
-  <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
-    <A href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</A>
-  </TD>
-  <TD class=\"switch_sw".$SW." bottom2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</TD>
-</TR>\n";
-       $SW = 3 - $SW;
-}
-if (empty($OUT))
-{
-       // No themes found???
-       $OUT = "<TR>
-  <TD colspan=\"5\" class=\"bottom2\" height=\"80\">
-    ".LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_THEMES_FOUND)."
-  </TD>
-</TR>\n";
-}
-define('__THEME_LIST', $OUT);
+       // @TODO Move this code into a template
+       $OUT .= "<tr>
+  <td class=\"{%template,ColorSwitch%} bottom right\" align=\"center\" height=\"30\">
+    <input type=\"radio\" name=\"member_theme\" class=\"member_normal\" value=\"".$unix."\"".$default." />
+  </td>
+  <td class=\"{%template,ColorSwitch%} bottom right\" align=\"center\">".$THEMES['theme_name'][$key]."</td>
+  <td class=\"{%template,ColorSwitch%} bottom right\" align=\"center\">
+    <a href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")'.'\">".$THEMES['theme_author'][$key]."</a>
+  </td>
+  <td class=\"{%template,ColorSwitch%} bottom right\" align=\"center\">
+    <a href=\"".generateDerefererUrl($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</a>
+  </td>
+  <td class=\"{%template,ColorSwitch%} bottom\" align=\"center\">v".$THEMES['theme_version'][$key]."</td>
+</tr>\n";
+} // END - foreach
+
+if (empty($OUT)) {
+       // No themes found???
+       $OUT = '<tr>
+  <td colspan="5" class="bottom" height="80">
+    ' . loadTemplate('admin_settings_saved', true, '{--MEMBER_NO_THEMES_FOUND--}') . '
+  </td>
+</tr>';
+} // END - if
 
 // Load template
-LOAD_TEMPLATE("member_themes");
+loadTemplate('member_themes', false, $OUT);
 
-//
+// [EOF]
 ?>