summaryrefslogtreecommitdiff
path: root/lib/color.pm
blob: 29474810b9819c4ffb522742e00f43c3588c22cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# COLOR SETTINGS

use RGB;

sub is_color
	{
	my ($plaid) = @_;
	return exists($COLORS{$plaid});
	}

sub color_dropdown
	{
	my ($selected, $quick) = @_;
	$selected = 'plain' if (!defined($selected));
	$quick = '0' if (!defined($quick));
	print qq!<select name="color"!;
	print qq! onchange="this.form.submit();"! if ($quick);
	print qq!>!;
	foreach $c (keys %COLORS)
		{
                print qq!<option value="$c"!;
                print qq! selected! if ($c eq $selected);
		print qq!>$c</option>!;
		}
	print qq!</select>\n!;
	}

sub get_color
	{
	my ($t, $k, $row) = @_;
	print qq!<tt> $t->{id}(color) = $t->{color}, $k->{color} </tt><br> ! if ($DEBUG);

	if (ref($row) eq "HASH")
		{
		my $comments = $row;
		my $color = find_comments_color($row);
		return $color if $color;
		}
	elsif (defined($row) && $row > 0)
		{
		if ($t->{color} && $t->{color} ne "plain")
			{ return $t->{color}; }
		elsif ($k->{color} && $k->{color} ne "plain")
			{ return $k->{color}; }
		elsif (!length($t->{keyword}))
			{ return $BUCKY_UNSORTED_COLOR; }
		else
			{ return $BUCKY_DEFAULT_COLOR; }
		}
	if ($t != -1 && $t->{color})
		{ return $t->{color} if ($t->{color} ne "plain"); }
	if ($k != -1 && $k->{color})
		{ return $k->{color}; }
	return "plain";
	}

sub find_comments_color
	{
	my ($comments) = @_;
	foreach my $comment (values %$comments)
		{
	# if ($message->{'body'} =~ /body bgcolor="?([#0-9a-fA-F]+)/)
		if ($comment->{'comment'}  =~ /(body bgcolor="|background-color: )#?([0-9a-fA-F]+)/)
			{
			print "1" if $DEBUG;
			my $color = $2;
			return "#" . $color;
			}
		}
	return undef;
	}
sub nighttime_quotient
  {
  my $nighttime_quotient = -30;
  my $date = time + get_tz_offset(); # if ($dateoffset == -1);
  my $x;
  my ($m,$h,$d,$n,$y) = (localtime $date)[1..5];
  if ($h < 5 || $h > 23)
    { return $nighttime_quotient; }
  if ($h >= 5 && $h <= 7)
    { $x = 60*60*3 - 60 * ($h - 5) + $m; }
  if ($h >= 21 && $h <= 23)
    { $x = 60 * ($h - 21) + $m; }
  $x /= 60*60*3;
  return $nighttime_quotient * $x;
  }

sub get_color_from_time
  {
  my ($date) = @_;
  $date = time;
  my $offset = get_tz_offset(); # if ($dateoffset == -1);
  $date += $offset;
  my ($m,$h,$d,$n,$y) = (localtime $date)[1..5];
  if (($h == 4 || $h == 16) && $m == 20)
    { $c = "green"; }
  elsif ($h < 5)
    { $c = "purple"; }
  elsif ($h >= 5 && $h < 6)
    { $c = "red"; }
  elsif ($h >= 6 && $h < 9)
    { $c = "orange"; }
  elsif ($h >= 9 && $h < 12)
    { $c = "yellow"; }
  elsif ($h >= 12 && $h < 18)
    { $c = "plain"; }
  elsif ($h >= 18 && $h < 21)
    { $c = "blue"; }
  elsif ($h >= 21)
    { $c = "purple"; }
  else
    { $c = "plain"; }
  return  $c;
  }

1;