use PAGE_NAME in themes and templates
[squirrelmail.git] / themes / darkness.php
CommitLineData
2824cc54 1<?php
4b4abf93 2
c4309fbd 3/**
c4309fbd 4 * Theme Name: 'Darkness'
5 * Like black?
4b4abf93 6 *
7 * @author Tyler Akins
4b5049de 8 * @copyright &copy; 2001-2007 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
c4309fbd 11 * @package squirrelmail
12 * @subpackage themes
13 */
43fdb2a4 14
c4309fbd 15/**
16 * Load up the usual suspects.. */
a6bc3f3f 17require_once(SM_PATH . 'functions/strings.php');
43fdb2a4 18
8c933a32 19 // Note: The text distance is actually pre-squared
20 // Background range is from 24-64, all three colors are the same
21 // Text range is from 196 to 255
22 $BackgroundTargetDistance = 12;
23 $BackgroundAdjust = 1;
24 $TextTargetDistance = 65536;
25 $TextAdjust = 0.95;
2824cc54 26
27function IsUnique($Distance, $r, $g, $b, $usedArray)
28{
29 foreach ($usedArray as $data) {
30 $a = abs($data[0] - $r);
31 $b = abs($data[1] - $g);
32 $c = abs($data[2] - $b);
33 $newDistance = $a * $a + $b * $b + $c * $c;
34 if ($newDistance < $Distance)
35 return false;
36 }
37 return true;
38}
39
40
41// Extra spiffy page fade if left frame
42// Always tremble background
43// This might make people go insane. Yes! *Victory dance!*
44function Darkness_HeaderPlugin() {
eb548244 45
101068d9 46 if (defined('PAGE_NAME') && PAGE_NAME=='left_main') {
673f9350 47 echo '<meta http-equiv="Page-Enter" content="' .
04fa3c41 48 'blendTrans(Duration=2.0)" />' . "\n";
2824cc54 49 }
eb548244 50
2c92ea9d 51?><script type="text/javascript">
2824cc54 52darkness_color = 0;
53darkness_dir = +1;
eb548244 54darkness_hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
55 'a', 'b', 'c', 'd', 'e', 'f');
2824cc54 56function DarknessTremble() {
57 if (darkness_color >= 32 || darkness_color <= 0)
58 darkness_dir = - darkness_dir;
59 darkness_color += darkness_dir;
60 if (darkness_color < 0)
61 darkness_color = 0;
62 bigDigit = Math.floor(darkness_color / 16);
63 littleDigit = darkness_color - (bigDigit * 16);
64 Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
1681f4d9 65 document.bgColor='#' + Color + Color + Color;
66 setTimeout('DarknessTremble()', 5000);
2824cc54 67}
1681f4d9 68setTimeout('DarknessTremble()', 10000);
2824cc54 69</script>
6fd95361 70<?php
2824cc54 71}
72
73global $squirrelmail_plugin_hooks;
74$squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
75 'Darkness_HeaderPlugin';
76
6c99d1de 77/** seed the random number generator **/
78sq_mt_randomize();
79
80$color[3] = '#000000';
81$color[4] = '#000000';
82$used = array(0);
83$targetDistance = $BackgroundTargetDistance;
84$Left = array(0, 5, 9, 10, 12);
85while (count($Left) > 0) {
86 // Some background colors
87 $r = mt_rand(24,64);
88 $unique = true;
89 foreach ($used as $col) {
90 if (abs($r - $col) < $targetDistance)
eb548244 91 $unique = false;
6c99d1de 92 }
93 if ($unique) {
94 $i = array_shift($Left);
95 $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
96 $used[] = $r;
97 $targetDistance = $BackgroundTargetDistance;
98 } else {
99 $targetDistance -= $BackgroundAdjust;
100 }
101}
2824cc54 102
6c99d1de 103// Set the error color to some shade of red
104$r = mt_rand(196, 255);
105$g = mt_rand(144, ($r * .8));
106$color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
107$used = array(array($r, $g, $g));
108
109// Set normal text colors
110$cmin = 196;
111$cmax = 255;
112foreach (array(6, 8) as $i) {
113 /** generate random color **/
114 $r = mt_rand($cmin,$cmax);
115 $g = mt_rand($cmin,$cmax);
116 $b = mt_rand($cmin,$cmax);
117 $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
118 $used[] = array($r, $g, $b);
119}
2824cc54 120
6c99d1de 121$Left = array(1, 7, 11, 13, 14, 15);
122$targetDistance = $TextTargetDistance;
123while (count($Left) > 0) {
124 // Text colors -- Try to keep the colors distinct
125 $cmin = 196;
126 $cmax = 255;
127
128 /** generate random color **/
129 $r = mt_rand($cmin,$cmax);
130 $g = mt_rand($cmin,$cmax);
131 $b = mt_rand($cmin,$cmax);
132
133 if (IsUnique($targetDistance, $r, $g, $b, $used)) {
134 $i = array_shift($Left);
135 $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
136 $used[] = array($r, $g, $b);
137 $targetDistance = $TextTargetDistance;
138 } else {
139 $targetDistance *= $TextAdjust;
140 }
141}