PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_4_10a/themes/darkness.php

#
PHP | 142 lines | 100 code | 16 blank | 26 comment | 13 complexity | 59ee7adbea43b07f7b71a22a6692f8bf MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * Theme Name: 'Darkness'
  4. * Like black?
  5. *
  6. * @author Tyler Akins
  7. * @copyright &copy; 2001-2007 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: darkness.php 12304 2007-03-04 02:26:48Z jervfors $
  10. * @package squirrelmail
  11. * @subpackage themes
  12. */
  13. /**
  14. * Load up the usual suspects.. */
  15. require_once(SM_PATH . 'functions/strings.php');
  16. // Note: The text distance is actually pre-squared
  17. // Background range is from 24-64, all three colors are the same
  18. // Text range is from 196 to 255
  19. $BackgroundTargetDistance = 12;
  20. $BackgroundAdjust = 1;
  21. $TextTargetDistance = 65536;
  22. $TextAdjust = 0.95;
  23. function IsUnique($Distance, $r, $g, $b, $usedArray)
  24. {
  25. foreach ($usedArray as $data) {
  26. $a = abs($data[0] - $r);
  27. $b = abs($data[1] - $g);
  28. $c = abs($data[2] - $b);
  29. $newDistance = $a * $a + $b * $b + $c * $c;
  30. if ($newDistance < $Distance)
  31. return false;
  32. }
  33. return true;
  34. }
  35. // Extra spiffy page fade if left frame
  36. // Always tremble background
  37. // This might make people go insane. Yes! *Victory dance!*
  38. function Darkness_HeaderPlugin() {
  39. global $PHP_SELF;
  40. if (substr($PHP_SELF, -18) == '/src/left_main.php') {
  41. echo '<meta http-equiv="Page-Enter" content="' .
  42. 'blendTrans(Duration=2.0)" />' . "\n";
  43. }
  44. ?><script language="javascript">
  45. darkness_color = 0;
  46. darkness_dir = +1;
  47. darkness_hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  48. 'a', 'b', 'c', 'd', 'e', 'f');
  49. function DarknessTremble() {
  50. if (darkness_color >= 32 || darkness_color <= 0)
  51. darkness_dir = - darkness_dir;
  52. darkness_color += darkness_dir;
  53. if (darkness_color < 0)
  54. darkness_color = 0;
  55. bigDigit = Math.floor(darkness_color / 16);
  56. littleDigit = darkness_color - (bigDigit * 16);
  57. Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
  58. document.bgColor='#' + Color + Color + Color;
  59. setTimeout('DarknessTremble()', 5000);
  60. }
  61. setTimeout('DarknessTremble()', 10000);
  62. </script>
  63. <?php
  64. }
  65. global $squirrelmail_plugin_hooks;
  66. $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
  67. 'Darkness_HeaderPlugin';
  68. /** seed the random number generator **/
  69. sq_mt_randomize();
  70. $color[3] = '#000000';
  71. $color[4] = '#000000';
  72. $used = array(0);
  73. $targetDistance = $BackgroundTargetDistance;
  74. $Left = array(0, 5, 9, 10, 12);
  75. while (count($Left) > 0) {
  76. // Some background colors
  77. $r = mt_rand(24,64);
  78. $unique = true;
  79. foreach ($used as $col) {
  80. if (abs($r - $col) < $targetDistance)
  81. $unique = false;
  82. }
  83. if ($unique) {
  84. $i = array_shift($Left);
  85. $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
  86. $used[] = $r;
  87. $targetDistance = $BackgroundTargetDistance;
  88. } else {
  89. $targetDistance -= $BackgroundAdjust;
  90. }
  91. }
  92. // Set the error color to some shade of red
  93. $r = mt_rand(196, 255);
  94. $g = mt_rand(144, ($r * .8));
  95. $color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
  96. $used = array(array($r, $g, $g));
  97. // Set normal text colors
  98. $cmin = 196;
  99. $cmax = 255;
  100. foreach (array(6, 8) as $i) {
  101. /** generate random color **/
  102. $r = mt_rand($cmin,$cmax);
  103. $g = mt_rand($cmin,$cmax);
  104. $b = mt_rand($cmin,$cmax);
  105. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  106. $used[] = array($r, $g, $b);
  107. }
  108. $Left = array(1, 7, 11, 13, 14, 15);
  109. $targetDistance = $TextTargetDistance;
  110. while (count($Left) > 0) {
  111. // Text colors -- Try to keep the colors distinct
  112. $cmin = 196;
  113. $cmax = 255;
  114. /** generate random color **/
  115. $r = mt_rand($cmin,$cmax);
  116. $g = mt_rand($cmin,$cmax);
  117. $b = mt_rand($cmin,$cmax);
  118. if (IsUnique($targetDistance, $r, $g, $b, $used)) {
  119. $i = array_shift($Left);
  120. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  121. $used[] = array($r, $g, $b);
  122. $targetDistance = $TextTargetDistance;
  123. } else {
  124. $targetDistance *= $TextAdjust;
  125. }
  126. }