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

/tags/webmail-release-1_4_22/themes/darkness.php

#
PHP | 140 lines | 99 code | 15 blank | 26 comment | 13 complexity | 22ca8cf26c1a4b7e5e7b3a8e67d726b7 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 2001-2011 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: darkness.php 14084 2011-01-06 02:44:03Z pdontthink $
  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. if (defined('PAGE_NAME') && PAGE_NAME=='left_main') {
  40. echo '<meta http-equiv="Page-Enter" content="' .
  41. 'blendTrans(Duration=2.0)" />' . "\n";
  42. }
  43. ?><script type="text/javascript">
  44. darkness_color = 0;
  45. darkness_dir = +1;
  46. darkness_hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  47. 'a', 'b', 'c', 'd', 'e', 'f');
  48. function DarknessTremble() {
  49. if (darkness_color >= 32 || darkness_color <= 0)
  50. darkness_dir = - darkness_dir;
  51. darkness_color += darkness_dir;
  52. if (darkness_color < 0)
  53. darkness_color = 0;
  54. bigDigit = Math.floor(darkness_color / 16);
  55. littleDigit = darkness_color - (bigDigit * 16);
  56. Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
  57. document.bgColor='#' + Color + Color + Color;
  58. setTimeout('DarknessTremble()', 5000);
  59. }
  60. setTimeout('DarknessTremble()', 10000);
  61. </script>
  62. <?php
  63. }
  64. global $squirrelmail_plugin_hooks;
  65. $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
  66. 'Darkness_HeaderPlugin';
  67. /** seed the random number generator **/
  68. sq_mt_randomize();
  69. $color[3] = '#000000';
  70. $color[4] = '#000000';
  71. $used = array(0);
  72. $targetDistance = $BackgroundTargetDistance;
  73. $Left = array(0, 5, 9, 10, 12);
  74. while (count($Left) > 0) {
  75. // Some background colors
  76. $r = mt_rand(24,64);
  77. $unique = true;
  78. foreach ($used as $col) {
  79. if (abs($r - $col) < $targetDistance)
  80. $unique = false;
  81. }
  82. if ($unique) {
  83. $i = array_shift($Left);
  84. $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
  85. $used[] = $r;
  86. $targetDistance = $BackgroundTargetDistance;
  87. } else {
  88. $targetDistance -= $BackgroundAdjust;
  89. }
  90. }
  91. // Set the error color to some shade of red
  92. $r = mt_rand(196, 255);
  93. $g = mt_rand(144, ($r * .8));
  94. $color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
  95. $used = array(array($r, $g, $g));
  96. // Set normal text colors
  97. $cmin = 196;
  98. $cmax = 255;
  99. foreach (array(6, 8) as $i) {
  100. /** generate random color **/
  101. $r = mt_rand($cmin,$cmax);
  102. $g = mt_rand($cmin,$cmax);
  103. $b = mt_rand($cmin,$cmax);
  104. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  105. $used[] = array($r, $g, $b);
  106. }
  107. $Left = array(1, 7, 11, 13, 14, 15);
  108. $targetDistance = $TextTargetDistance;
  109. while (count($Left) > 0) {
  110. // Text colors -- Try to keep the colors distinct
  111. $cmin = 196;
  112. $cmax = 255;
  113. /** generate random color **/
  114. $r = mt_rand($cmin,$cmax);
  115. $g = mt_rand($cmin,$cmax);
  116. $b = mt_rand($cmin,$cmax);
  117. if (IsUnique($targetDistance, $r, $g, $b, $used)) {
  118. $i = array_shift($Left);
  119. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  120. $used[] = array($r, $g, $b);
  121. $targetDistance = $TextTargetDistance;
  122. } else {
  123. $targetDistance *= $TextAdjust;
  124. }
  125. }