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