PageRenderTime 43ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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