Fixes for minor bugs pointed out by Tyler Akins.
[squirrelmail.git] / themes / darkness.php
CommitLineData
2824cc54 1<?php
2 /** Author: Tyler Akins
1681f4d9 3 Theme Name: 'Darkness'
2824cc54 4
5 Like black?
6
7 **/
8
43fdb2a4 9
46d38f78 10require_once('../functions/strings.php');
43fdb2a4 11
8c933a32 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;
2824cc54 19
20function 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!*
37function Darkness_HeaderPlugin() {
38 global $PHP_SELF, $Darkness_Transition;
39
1681f4d9 40 if (substr($PHP_SELF, -18) == '/src/left_main.php') {
673f9350 41 echo '<meta http-equiv="Page-Enter" content="' .
42 'blendTrans(Duration=2.0)">' . '\n';
2824cc54 43 }
44
45?><script language=javascript>
46darkness_color = 0;
47darkness_dir = +1;
1681f4d9 48darkness_hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
49 'A', 'B', 'C', 'D', 'E', 'F');
2824cc54 50function 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];
1681f4d9 59 document.bgColor='#' + Color + Color + Color;
60 setTimeout('DarknessTremble()', 5000);
2824cc54 61}
1681f4d9 62setTimeout('DarknessTremble()', 10000);
2824cc54 63</script>
64<?PHP
65}
66
67global $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
1681f4d9 74 $color[3] = '#000000';
75 $color[4] = '#000000';
8c933a32 76 $used = array(0);
77 $targetDistance = $BackgroundTargetDistance;
2824cc54 78 $Left = array(0, 5, 9, 10, 12);
79 while (count($Left) > 0) {
80 // Some background colors
8c933a32 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) {
2824cc54 88 $i = array_shift($Left);
1681f4d9 89 $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
8c933a32 90 $used[] = $r;
91 $targetDistance = $BackgroundTargetDistance;
2824cc54 92 } else {
8c933a32 93 $targetDistance -= $BackgroundAdjust;
2824cc54 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));
1681f4d9 100 $color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
2824cc54 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);
1681f4d9 111 $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
2824cc54 112 $used[] = array($r, $g, $b);
113 }
114
ecf5c1bd 115 $Left = array(1, 7, 11, 13, 14, 15);
8c933a32 116 $targetDistance = $TextTargetDistance;
2824cc54 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);
1681f4d9 129 $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
2824cc54 130 $used[] = array($r, $g, $b);
8c933a32 131 $targetDistance = $TextTargetDistance;
2824cc54 132 } else {
8c933a32 133 $targetDistance *= $TextAdjust;
2824cc54 134 }
135 }
136
137
138/** Reference from doc/themes.txt
139
140b 0: Title Bar at the top of the page header
141f 1: <not currently used>
142f 2: Error messages, usually red
143b 3: Left folder list background color
144b 4: Normal background color
145b 5: Header of the message index [From, Date, Subject]
146f 6: Normal text on the left folder list
147f 7: Links in the right frame, Folders with subfolders in left frame
148f 8: Normal text [usually black]
149b 9: Darker version of #0
150b 10: Darker version of #9
151f 11: Special folders color [Inbox, Trash, Sent]
152b 12: Alternate color for message list [alters between 4 and this one]
1681f4d9 153f 13: Color for single-quoted text ('> text') when reading (default: #800000)
2824cc54 154f 14: Color for text with more than one quote (default: #FF0000)
155
156**/
157
158?>