073cb7421f8ba66c3a5d6c5f2d5d8532c3cb00f7
[squirrelmail.git] / themes / darkness.php
1 <?php
2 /** Author: Tyler Akins
3 Theme Name: "Darkness"
4
5 Like black?
6
7 **/
8
9
10 require_once('../functions/strings.php');
11
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
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
33
34 // Extra spiffy page fade if left frame
35 // Always tremble background
36 // This might make people go insane. Yes! *Victory dance!*
37 function Darkness_HeaderPlugin() {
38 global $PHP_SELF, $Darkness_Transition;
39
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
45 ?><script language=javascript>
46 darkness_color = 0;
47 darkness_dir = +1;
48 darkness_hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
49 "A", "B", "C", "D", "E", "F");
50 function DarknessTremble() {
51 if (darkness_color >= 32 || darkness_color <= 0)
52 darkness_dir = - darkness_dir;
53 darkness_color += darkness_dir;
54 if (darkness_color < 0)
55 darkness_color = 0;
56 bigDigit = Math.floor(darkness_color / 16);
57 littleDigit = darkness_color - (bigDigit * 16);
58 Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
59 document.bgColor="#" + Color + Color + Color;
60 setTimeout("DarknessTremble()", 5000);
61 }
62 setTimeout("DarknessTremble()", 10000);
63 </script>
64 <?PHP
65 }
66
67 global $squirrelmail_plugin_hooks;
68 $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
69 'Darkness_HeaderPlugin';
70
71 /** seed the random number generator **/
72 sq_mt_randomize();
73
74 $color[3] = "#000000";
75 $color[4] = "#000000";
76 $used = array(0);
77 $targetDistance = $BackgroundTargetDistance;
78 $Left = array(0, 5, 9, 10, 12);
79 while (count($Left) > 0) {
80 // Some background colors
81 $r = mt_rand(24,64);
82 $unique = true;
83 foreach ($used as $col) {
84 if (abs($r - $col) < $targetDistance)
85 $unique = false;
86 }
87 if ($unique) {
88 $i = array_shift($Left);
89 $color[$i] = sprintf("#%02X%02X%02X",$r,$r, $r);
90 $used[] = $r;
91 $targetDistance = $BackgroundTargetDistance;
92 } else {
93 $targetDistance -= $BackgroundAdjust;
94 }
95 }
96
97 // Set the error color to some shade of red
98 $r = mt_rand(196, 255);
99 $g = mt_rand(144, ($r * .8));
100 $color[2] = sprintf("#%02X%02X%02X", $r, $g, $g);
101 $used = array(array($r, $g, $g));
102
103 // Set normal text colors
104 $cmin = 196;
105 $cmax = 255;
106 foreach (array(6, 8) as $i) {
107 /** generate random color **/
108 $r = mt_rand($cmin,$cmax);
109 $g = mt_rand($cmin,$cmax);
110 $b = mt_rand($cmin,$cmax);
111 $color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
112 $used[] = array($r, $g, $b);
113 }
114
115 $Left = array(1, 7, 11, 13, 14, 15);
116 $targetDistance = $TextTargetDistance;
117 while (count($Left) > 0) {
118 // Text colors -- Try to keep the colors distinct
119 $cmin = 196;
120 $cmax = 255;
121
122 /** generate random color **/
123 $r = mt_rand($cmin,$cmax);
124 $g = mt_rand($cmin,$cmax);
125 $b = mt_rand($cmin,$cmax);
126
127 if (IsUnique($targetDistance, $r, $g, $b, $used)) {
128 $i = array_shift($Left);
129 $color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
130 $used[] = array($r, $g, $b);
131 $targetDistance = $TextTargetDistance;
132 } else {
133 $targetDistance *= $TextAdjust;
134 }
135 }
136
137
138 /** Reference from doc/themes.txt
139
140 b 0: Title Bar at the top of the page header
141 f 1: <not currently used>
142 f 2: Error messages, usually red
143 b 3: Left folder list background color
144 b 4: Normal background color
145 b 5: Header of the message index [From, Date, Subject]
146 f 6: Normal text on the left folder list
147 f 7: Links in the right frame, Folders with subfolders in left frame
148 f 8: Normal text [usually black]
149 b 9: Darker version of #0
150 b 10: Darker version of #9
151 f 11: Special folders color [Inbox, Trash, Sent]
152 b 12: Alternate color for message list [alters between 4 and this one]
153 f 13: Color for single-quoted text ("> text") when reading (default: #800000)
154 f 14: Color for text with more than one quote (default: #FF0000)
155
156 **/
157
158 ?>