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

/trunk/squirrelmail/themes/darkness.php

#
PHP | 134 lines | 97 code | 14 blank | 23 comment | 13 complexity | 2496d7567212e92afb10940df460774e 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-2012 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: darkness.php 14249 2012-01-02 02:09:17Z pdontthink $
  10. * @package squirrelmail
  11. * @subpackage themes
  12. */
  13. // Note: The text distance is actually pre-squared
  14. // Background range is from 24-64, all three colors are the same
  15. // Text range is from 196 to 255
  16. $BackgroundTargetDistance = 12;
  17. $BackgroundAdjust = 1;
  18. $TextTargetDistance = 65536;
  19. $TextAdjust = 0.95;
  20. function IsUnique($Distance, $r, $g, $b, $usedArray)
  21. {
  22. foreach ($usedArray as $data) {
  23. $a = abs($data[0] - $r);
  24. $b = abs($data[1] - $g);
  25. $c = abs($data[2] - $b);
  26. $newDistance = $a * $a + $b * $b + $c * $c;
  27. if ($newDistance < $Distance)
  28. return false;
  29. }
  30. return true;
  31. }
  32. // Extra spiffy page fade if left frame
  33. // Always tremble background
  34. // This might make people go insane. Yes! *Victory dance!*
  35. function Darkness_HeaderPlugin() {
  36. if (defined('PAGE_NAME') && PAGE_NAME=='left_main') {
  37. echo '<meta http-equiv="Page-Enter" content="' .
  38. 'blendTrans(Duration=2.0)" />' . "\n";
  39. }
  40. ?><script type="text/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. $color[3] = '#000000';
  65. $color[4] = '#000000';
  66. $used = array(0);
  67. $targetDistance = $BackgroundTargetDistance;
  68. $Left = array(0, 5, 9, 10, 12);
  69. while (count($Left) > 0) {
  70. // Some background colors
  71. $r = mt_rand(24,64);
  72. $unique = true;
  73. foreach ($used as $col) {
  74. if (abs($r - $col) < $targetDistance)
  75. $unique = false;
  76. }
  77. if ($unique) {
  78. $i = array_shift($Left);
  79. $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
  80. $used[] = $r;
  81. $targetDistance = $BackgroundTargetDistance;
  82. } else {
  83. $targetDistance -= $BackgroundAdjust;
  84. }
  85. }
  86. // Set the error color to some shade of red
  87. $r = mt_rand(196, 255);
  88. $g = mt_rand(144, ($r * .8));
  89. $color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
  90. $used = array(array($r, $g, $g));
  91. // Set normal text colors
  92. $cmin = 196;
  93. $cmax = 255;
  94. foreach (array(6, 8) as $i) {
  95. /** generate random color **/
  96. $r = mt_rand($cmin,$cmax);
  97. $g = mt_rand($cmin,$cmax);
  98. $b = mt_rand($cmin,$cmax);
  99. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  100. $used[] = array($r, $g, $b);
  101. }
  102. $Left = array(1, 7, 11, 13, 14, 15);
  103. $targetDistance = $TextTargetDistance;
  104. while (count($Left) > 0) {
  105. // Text colors -- Try to keep the colors distinct
  106. $cmin = 196;
  107. $cmax = 255;
  108. /** generate random color **/
  109. $r = mt_rand($cmin,$cmax);
  110. $g = mt_rand($cmin,$cmax);
  111. $b = mt_rand($cmin,$cmax);
  112. if (IsUnique($targetDistance, $r, $g, $b, $used)) {
  113. $i = array_shift($Left);
  114. $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
  115. $used[] = array($r, $g, $b);
  116. $targetDistance = $TextTargetDistance;
  117. } else {
  118. $targetDistance *= $TextAdjust;
  119. }
  120. }