summaryrefslogtreecommitdiff
path: root/lib/color.pm
diff options
context:
space:
mode:
authorJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
committerJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
commite9192b3d42660a5781101df4357d276318151e8a (patch)
tree059eb6ace6147cf9559af74ed1ab5e221c80e280 /lib/color.pm
parent79670053c7247d3a49b607960efd284e93f057e5 (diff)
cgi-bin & lib
Diffstat (limited to 'lib/color.pm')
-rw-r--r--lib/color.pm117
1 files changed, 117 insertions, 0 deletions
diff --git a/lib/color.pm b/lib/color.pm
new file mode 100644
index 0000000..2947481
--- /dev/null
+++ b/lib/color.pm
@@ -0,0 +1,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;