random.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Name: Random Theme Every Login
  4. * Date: December 24, 2001
  5. * Comment: Guess what this does!
  6. *
  7. * @author Tyler Akins
  8. * @copyright &copy; 2000-2007 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @subpackage themes
  13. */
  14. /** Prevent direct script loading */
  15. if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
  16. (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
  17. die();
  18. }
  19. /** load required functions */
  20. include_once(SM_PATH . 'functions/global.php');
  21. include_once(SM_PATH . 'functions/strings.php');
  22. /** Initialize the random number generator */
  23. sq_mt_randomize();
  24. global $theme;
  25. if (!sqsession_is_registered('random_theme_good_theme')) {
  26. $good_themes = array();
  27. foreach ($theme as $data) {
  28. if (substr($data['PATH'], -18) != '/themes/random.php') {
  29. $good_themes[] = $data['PATH'];
  30. }
  31. }
  32. if (count($good_themes) == 0) {
  33. $good_themes[] = '../themes/default.php';
  34. }
  35. $which = mt_rand(0, count($good_themes));
  36. $random_theme_good_theme = $good_themes[$which];
  37. // remove current sm_path from theme name
  38. $path=preg_quote(SM_PATH,'/');
  39. $random_theme_good_theme=preg_replace("/^$path/",'',$random_theme_good_theme);
  40. // store it in session
  41. sqsession_register($random_theme_good_theme, 'random_theme_good_theme');
  42. } else {
  43. // get random theme stored in session
  44. sqgetGlobalVar('random_theme_good_theme',$random_theme_good_theme);
  45. }
  46. @include_once (SM_PATH . $random_theme_good_theme);