PageRenderTime 18ms CodeModel.GetById 5ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/webmail-release-1_4_22/themes/darkness.php

#
PHP | 140 lines | 99 code | 15 blank | 26 comment | 13 complexity | 22ca8cf26c1a4b7e5e7b3a8e67d726b7 MD5 | raw file
  1<?php
  2
  3/**
  4 * Theme Name:   'Darkness'
  5 * Like black?
  6 *
  7 * @author Tyler Akins
  8 * @copyright 2001-2011 The SquirrelMail Project Team
  9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 10 * @version $Id: darkness.php 14084 2011-01-06 02:44:03Z pdontthink $
 11 * @package squirrelmail
 12 * @subpackage themes
 13 */
 14
 15/**
 16 * Load up the usual suspects.. */
 17require_once(SM_PATH . 'functions/strings.php');
 18
 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;
 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() {
 45   if (defined('PAGE_NAME') && PAGE_NAME=='left_main') {
 46      echo '<meta http-equiv="Page-Enter" content="' .
 47         'blendTrans(Duration=2.0)" />' . "\n";
 48   }
 49
 50?><script type="text/javascript">
 51darkness_color = 0;
 52darkness_dir = +1;
 53darkness_hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 54   'a', 'b', 'c', 'd', 'e', 'f');
 55function DarknessTremble() {
 56   if (darkness_color >= 32 || darkness_color <= 0)
 57      darkness_dir = - darkness_dir;
 58   darkness_color += darkness_dir;
 59   if (darkness_color < 0)
 60      darkness_color = 0;
 61   bigDigit = Math.floor(darkness_color / 16);
 62   littleDigit = darkness_color - (bigDigit * 16);
 63   Color = darkness_hex[bigDigit] + darkness_hex[littleDigit];
 64   document.bgColor='#' + Color + Color + Color;
 65   setTimeout('DarknessTremble()', 5000);
 66}
 67setTimeout('DarknessTremble()', 10000);
 68</script>
 69<?php
 70}
 71
 72global $squirrelmail_plugin_hooks;
 73$squirrelmail_plugin_hooks['generic_header']['theme_darkness'] =
 74    'Darkness_HeaderPlugin';
 75
 76/** seed the random number generator **/
 77sq_mt_randomize();
 78
 79$color[3] = '#000000';
 80$color[4] = '#000000';
 81$used = array(0);
 82$targetDistance = $BackgroundTargetDistance;
 83$Left = array(0, 5, 9, 10, 12);
 84while (count($Left) > 0) {
 85    // Some background colors
 86    $r = mt_rand(24,64);
 87    $unique = true;
 88    foreach ($used as $col) {
 89        if (abs($r - $col) < $targetDistance)
 90            $unique = false;
 91    }
 92    if ($unique) {
 93        $i = array_shift($Left);
 94        $color[$i] = sprintf('#%02X%02X%02X',$r,$r, $r);
 95        $used[] = $r;
 96        $targetDistance = $BackgroundTargetDistance;
 97    } else {
 98        $targetDistance -= $BackgroundAdjust;
 99    }
100}
101
102// Set the error color to some shade of red
103$r = mt_rand(196, 255);
104$g = mt_rand(144, ($r * .8));
105$color[2] = sprintf('#%02X%02X%02X', $r, $g, $g);
106$used = array(array($r, $g, $g));
107
108// Set normal text colors
109$cmin = 196;
110$cmax = 255;
111foreach (array(6, 8) as $i) {
112    /** generate random color **/
113    $r = mt_rand($cmin,$cmax);
114    $g = mt_rand($cmin,$cmax);
115    $b = mt_rand($cmin,$cmax);
116    $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
117    $used[] = array($r, $g, $b);
118}
119
120$Left = array(1, 7, 11, 13, 14, 15);
121$targetDistance = $TextTargetDistance;
122while (count($Left) > 0) {
123    // Text colors -- Try to keep the colors distinct
124    $cmin = 196;
125    $cmax = 255;
126
127    /** generate random color **/
128    $r = mt_rand($cmin,$cmax);
129    $g = mt_rand($cmin,$cmax);
130    $b = mt_rand($cmin,$cmax);
131
132    if (IsUnique($targetDistance, $r, $g, $b, $used)) {
133        $i = array_shift($Left);
134        $color[$i] = sprintf('#%02X%02X%02X',$r,$g,$b);
135        $used[] = array($r, $g, $b);
136        $targetDistance = $TextTargetDistance;
137    } else {
138        $targetDistance *= $TextAdjust;
139    }
140}