PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_2_3/squirrelmail/themes/darkness.php

#
PHP | 158 lines | 101 code | 19 blank | 38 comment | 13 complexity | 0840be929517c47e225306d991907a62 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /** Author: Tyler Akins
  3. Theme Name: "Darkness"
  4. Like black?
  5. **/
  6. include_once('../functions/strings.php');
  7. // Note: The text distance is actually pre-squared
  8. // Background range is from 24-64, all three colors are the same
  9. // Text range is from 196 to 255
  10. $BackgroundTargetDistance = 12;
  11. $BackgroundAdjust = 1;
  12. $TextTargetDistance = 65536;
  13. $TextAdjust = 0.95;
  14. function IsUnique($Distance, $r, $g, $b, $usedArray)
  15. {
  16. foreach ($usedArray as $data) {
  17. $a = abs($data[0] - $r);
  18. $b = abs($data[1] - $g);
  19. $c = abs($data[2] - $b);
  20. $newDistance = $a * $a + $b * $b + $c * $c;
  21. if ($newDistance < $Distance)
  22. return false;
  23. }
  24. return true;
  25. }
  26. // Extra spiffy page fade if left frame
  27. // Always tremble background
  28. // This might make people go insane. Yes! *Victory dance!*
  29. function Darkness_HeaderPlugin() {
  30. global $PHP_SELF, $Darkness_Transition;
  31. if (substr($PHP_SELF, -18) == "/src/left_main.php") {
  32. echo '<meta http-equiv="Page-Enter" content="' .
  33. 'blendTrans(Duration=2.0)">' . "\n";
  34. }
  35. ?><script language=javascript>
  36. darkness_color = 0;
  37. darkness_dir = +1;
  38. darkness_hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
  39. "A", "B", "C", "D", "E", "F");
  40. function DarknessTremble() {
  41. if (darkness_color >= 32 || darkness_color <= 0)
  42. darkness_dir = - darkness_dir;
  43. darkness_color += darkness_dir;
  44. if (darkness_color < 0)
  45. darkness_color = 0;
  46. bigDigit = Math.floor(darkness_color / 16);
  47. littleDigit = darkness_color - (bigDigit * 16);
  48. Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
  49. document.bgColor="#" + Color + Color + Color;
  50. setTimeout("DarknessTremble()", 5000);
  51. }
  52. setTimeout("DarknessTremble()", 10000);
  53. </script>
  54. <?PHP
  55. }
  56. global $squirrelmail_plugin_hooks;
  57. $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
  58. 'Darkness_HeaderPlugin';
  59. /** seed the random number generator **/
  60. sq_mt_randomize();
  61. $color[3] = "#000000";
  62. $color[4] = "#000000";
  63. $used = array(0);
  64. $targetDistance = $BackgroundTargetDistance;
  65. $Left = array(0, 5, 9, 10, 12);
  66. while (count($Left) > 0) {
  67. // Some background colors
  68. $r = mt_rand(24,64);
  69. $unique = true;
  70. foreach ($used as $col) {
  71. if (abs($r - $col) < $targetDistance)
  72. $unique = false;
  73. }
  74. if ($unique) {
  75. $i = array_shift($Left);
  76. $color[$i] = sprintf("#%02X%02X%02X",$r,$r, $r);
  77. $used[] = $r;
  78. $targetDistance = $BackgroundTargetDistance;
  79. } else {
  80. $targetDistance -= $BackgroundAdjust;
  81. }
  82. }
  83. // Set the error color to some shade of red
  84. $r = mt_rand(196, 255);
  85. $g = mt_rand(144, ($r * .8));
  86. $color[2] = sprintf("#%02X%02X%02X", $r, $g, $g);
  87. $used = array(array($r, $g, $g));
  88. // Set normal text colors
  89. $cmin = 196;
  90. $cmax = 255;
  91. foreach (array(6, 8) as $i) {
  92. /** generate random color **/
  93. $r = mt_rand($cmin,$cmax);
  94. $g = mt_rand($cmin,$cmax);
  95. $b = mt_rand($cmin,$cmax);
  96. $color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
  97. $used[] = array($r, $g, $b);
  98. }
  99. $Left = array(1, 7, 11, 13, 14, 15);
  100. $targetDistance = $TextTargetDistance;
  101. while (count($Left) > 0) {
  102. // Text colors -- Try to keep the colors distinct
  103. $cmin = 196;
  104. $cmax = 255;
  105. /** generate random color **/
  106. $r = mt_rand($cmin,$cmax);
  107. $g = mt_rand($cmin,$cmax);
  108. $b = mt_rand($cmin,$cmax);
  109. if (IsUnique($targetDistance, $r, $g, $b, $used)) {
  110. $i = array_shift($Left);
  111. $color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
  112. $used[] = array($r, $g, $b);
  113. $targetDistance = $TextTargetDistance;
  114. } else {
  115. $targetDistance *= $TextAdjust;
  116. }
  117. }
  118. /** Reference from doc/themes.txt
  119. b 0: Title Bar at the top of the page header
  120. f 1: <not currently used>
  121. f 2: Error messages, usually red
  122. b 3: Left folder list background color
  123. b 4: Normal background color
  124. b 5: Header of the message index [From, Date, Subject]
  125. f 6: Normal text on the left folder list
  126. f 7: Links in the right frame, Folders with subfolders in left frame
  127. f 8: Normal text [usually black]
  128. b 9: Darker version of #0
  129. b 10: Darker version of #9
  130. f 11: Special folders color [Inbox, Trash, Sent]
  131. b 12: Alternate color for message list [alters between 4 and this one]
  132. f 13: Color for single-quoted text ("> text") when reading (default: #800000)
  133. f 14: Color for text with more than one quote (default: #FF0000)
  134. **/
  135. ?>