# NOTE -- This file is generated by running make-js-interfaces.pl package mozilla; use strict; use vars qw/@ISA $standardheader/; $standardheader = < == Released under the GNU GPL --> EOF if(defined $::config->{javascript_domain}) { $standardheader .= "\n"; } use default; @ISA = qw/default/; my %colours = ( '00' => '#FFFFFF', '01' => '#000000', '02' => '#0000FF', '03' => '#008000', '04' => '#FF0000', '05' => '#800000', '06' => '#800080', '07' => '#FF6600', '08' => '#FFFF00', '09' => '#00FF00', '10' => '#008080', '11' => '#00FFFF', '12' => '#0000FF', '13' => '#FF00FF', '14' => '#808080', '15' => '#C0C0C0'); my %options = ( timestamp => { type => 'toggle', info => 'Display a timestamp next to each message', img => 'time.gif' }, font => { type => 'select', options => [qw/serif sans-serif fantasy cursive monospace/, 'Arial Black', 'Comic Sans MS', 'Fixedsys', 'Tahoma', 'Verdana'], info => 'The font that messages are displayed in', img => 'font.gif' }, shownick => { type => 'toggle', info => 'Show your nickname next to the text entry box', img => 'entry.gif' }, smilies => { type => 'toggle', info => 'Convert smilies into pictures', img => 'smile.gif' }, scrollback => { type => 'toggle', info => 'Store all scrollback data (uses more memory)', img => 'scrollback.gif', }, 'actsound' => { type => "toggle", info => "Play a sound when activity directed at you occurs", img => 'actsound.gif', }, 'joinsound' => { type => "toggle", info => "Play a sound when some one joins a channel", img => 'joinsound.gif', }, ); my(%output_status, %output_none, %output_active); sub new { my($class,$event, $timer, $config, $icookies) = @_; my $self = bless {}, $class; tie %$self, 'IRC::UniqueHash'; if(defined $config->{javascript_domain}) { _out("document.domain = " . _escapejs($config->{javascript_domain}) . ";"); } my $tmp=''; for(keys %$icookies) { $tmp .= "$_: " . _escapejs($icookies->{$_}) . ', '; } $tmp =~ s/, $//; _out('document.onreadystatechange = function() { if(this.readyState == "complete") parent.disconnected(); }'); _out('parent.options = { ' . $tmp . '};'); $event->add('user add', code => \&useradd); $event->add('user del', code => \&userdel); $event->add('user change nick', code => \&usernick); $event->add('user change', code => \&usermode); $event->add('user self', code => \&mynick); $event->add('user 005', code => sub { _func_out('prefix',$_[1])}); $event->add('user connected', code => sub { _out('parent.connected = 1;') }); $self->add('Status', 0); _func_out('witemnospeak', 'Status'); _func_out('fontset', $icookies->{font}) if exists $icookies->{font}; _func_out('enable_sounds') if ((exists $icookies->{actsound} || exists $icookies->{joinsound}) && ($icookies->{actsound} || $icookies->{joinsound})); if(exists $::config->{'output status'}) { @output_status{split /,\s*/, $::config->{'output status'}} = 1; } if(exists $::config->{'output none'}) { @output_none{split /,\s*/, $::config->{'output none'}} = 1; } if(exists $::config->{'output active'}) { @output_active{split /,\s*/, $::config->{'output active'}} = 1; } return $self; } sub end { _out('parent.connected = 0;'); } sub _out { unless(print "\r\n") { $::needtodie++; } } sub _func_out { my($func,@rest) = @_; @rest = map(ref $_ eq 'ARRAY' ? _outputarray($_) : _escapejs($_), @rest); if($func eq 'witemaddtext') { return 'parent.' . $func . '(' . _jsp(@rest) . ');'; } _out('parent.' . $func . '(' . _jsp(@rest) . ');'); } sub _escapejs { my $in = shift; return "''" unless defined $in; $in =~ s/\\/\\\\/g; $in =~ s/'/\\'/g; $in =~ s/<\/script/<\\\/\\script/g; if(defined $_[0]) { return "$_[0]$in$_[0]"; } return '\'' . $in . '\''; } sub _escapehtml { my $in = shift; return "''" unless defined $in; $in =~ s//>/g; $in =~ s/"/"/g; return $in; } # XXX: switch this to use a proper JSON library one day.. sub _jsp { return join(', ', @_); } sub _outputarray { my $array = shift; return '[' . _jsp(map(_escapejs($_), @$array)) . ']'; } sub _outputhash { my $hash = shift; return '{' . _jsp(map(_escapejs($_) . ":" . _escapejs($hash->{$_}), keys %$hash)) . '}'; } sub useradd { my($event, $nicks, $channel) = @_; _func_out('channeladdusers', $channel, $nicks); } sub userdel { my($event, $nick, $channels) = @_; _func_out('channelsdeluser', $channels, $nick); } sub usernick { my($event,$old,$new,$channels) = @_; _func_out('channelsusernick', $old, $new); } sub usermode { my($event,$nick, $channel, $action, $type) = @_; _func_out('channelusermode', $channel, $nick, $action, $type); } sub mynick { my($event, $nick) = @_; _func_out('mynick', $nick); } sub exists { return 1 if defined &{__PACKAGE__ . '::' . $_[1]}; } sub query { return 1; } sub style { my($self, $cgi, $config) = @_; my $style = $cgi->{style} || 'default'; $cgi->{style} =~ s/[^a-z]//gi; open(STYLE, "; close(STYLE); } sub makeline { my($self, $info, $html) = @_; my $target = defined $info->{target} ? $info->{target} : 'Status'; if(ref $target eq 'ARRAY') { my %tmp = %$info; my $text = ''; for(@$target) { $tmp{target} = $_; $text .= $self->makeline(\%tmp, $html) . "\r\n"; } return $text; } my $out = ""; if(not exists $self->{$target}) { if(defined $info && ref $info && exists $info->{create} && $info->{create}) { $self->add($target, $info->{type} eq 'join' ? 1 : 0); }elsif($target ne '-all') { $target = 'Status'; } }elsif($info->{type} eq 'join') { $out = "parent.joinsound();"; } $info->{type} =~ s/^(\w+ \w+) .*/$1/; return if exists $output_none{$info->{type}}; $target = "Status" if exists $output_status{$info->{type}}; $target = "-active" if exists $output_active{$info->{type}}; if($info->{style}) { $html = "{style}\">$html"; } return $out . _func_out('witemaddtext', $target, $html . '
', $info->{activity} || 0, 0); } sub lines { my($self, @lines) = @_; _out(join("\r\n", @lines)."\r\nparent.witemredraw();"); print "\r\n"; } sub header { my($self, $cgi, $config, $fg, $bg) = @_; _func_out('maincolor', $fg, $bg); } sub error { my($self,$message) = @_; $self->lines($self->makeline({ target => 'Status'}, $message)); _func_out('disconnected'); } sub add { my($self,$add,$channel) = @_; return if not defined $add; $self->{$add}++; _func_out('witemadd', $add, $channel); _func_out('witemchg', $add) if $channel; } sub del { my($self, $del) = @_; return if not defined $del; _func_out('witemdel', $del); return if not exists $self->{$del}; delete($self->{$del}); } sub clear { my($self, $window) = @_; _func_out('witemclear', $window); } sub active { my($self, $window) = @_; _func_out('witemchg', $window); } sub smilie { # js runs in fmain. (XXX: doesn't actually work?) return '' . $_[2] . ''; } sub link { shift; # object return "$_[1]"; } sub frameset { my($self, $scriptname, $config, $random, $out, $interface, $style) = @_; if($config->{balance_servers}) { my @balance_servers = split /,\s*/, $config->{balance_servers}; $scriptname = $balance_servers[rand @balance_servers] . "/$scriptname"; } print < CGI:IRC - Loading This interface requires a browser that supports frames and javascript. EOF } sub blank { return ''; } sub ctcpping { my($self, $nick, $params) = @_; _func_out('sendcmd',"/ctcpreply $nick PING $params"); 1; } sub ping { 1; } sub sendping { _func_out('sendcmd',"/noop"); } sub help { my($self,$config) = @_; my %helpmap = ( "russian" => ".ru" ); my $extra = $helpmap{$::formatname} || ""; open(HELP, "<" . $::help_path . "help$extra.html") or do { _func_out('doinfowin', '-Help', "Help file not found!"); return; }; eval { local $SIG{__DIE__}; binmode HELP, ':utf8'; }; local $/; my $help = ; close HELP; $help =~ s/[\n\r]/ /g; _func_out('doinfowin', '-Help', $help); } sub setoption { my($self, $name, $value) = @_; _func_out('setoption', $name, $value); $self->options({}, {}, $main::config) } sub options { my($self, $cgi, $irc, $config) = @_; $config = $irc unless ref $config; my $ioptions = $main::ioptions; my $out = "CGI:IRC Options

Options

These options affect the appearence of CGI:IRC, they will stay between sessions provided cookies are turned on.
"; for my $option(sort keys %options) { my $o = $options{$option}; my $value = defined $ioptions->{$option} ? $ioptions->{$option} : ''; $out .= ""; } $out .= "
" . (exists $o->{img} ? ""; if($o->{type} eq 'toggle') { $out .= ""; }elsif($o->{type} eq 'select') { $out .= ""; }else{ $out .= ""; } $out .= "
close "; $out =~ s/\n//g; _func_out('doinfowin', '-Options', $out); } sub say { my($self) = @_; return 'ok'; } sub reconnect { my($self, $url, $text) = @_; return "$text"; } sub fwindowlist { my($self, $cgi, $config) = @_; my $string; for(keys %$cgi) { next if $_ eq 'item'; $string .= main::cgi_encode($_) . '=' . main::cgi_encode($cgi->{$_}).'&'; } $string =~ s/\&$//; print $standardheader; print q~
EOF } sub fmain { my($self, $cgi, $config) = @_; # evil. sub regexp_parse { my $have_entities = eval { require HTML::Entities; }; my $string = shift; $string =~ s/(? EOF if($::config->{smilies_popup}) { my $smilies = ::parse_config($::config->{smilies}); my %smilies; for(keys %$smilies) { $smilies{regexp_parse($_)} = $smilies->{$_}; } $smilies = _outputhash(\%smilies); $config->{smilies_perrow} = 5 unless exists $config->{smilies_perrow}; print < var swin; function smilies() { if(!swin) { swin = document.createElement("table"); swin.className = "main-smilies"; var smilies = $smilies; var c = 0, tr; for(var i in smilies) { if((c++ % $config->{smilies_perrow}) == 0) { tr = document.createElement("tr"); swin.appendChild(tr); } var cont = document.createElement("td"); cont.width = "@{[int(100 / $config->{smilies_perrow})]}%"; var p = document.createElement("img"); p.title = i; p.src = "$config->{image_path}/" + smilies[i] + ".gif"; cont.appendChild(p); cont.onclick = function() { parent.fform.append(this.firstChild.title + " "); this.parentNode.parentNode.style.display = 'none'; } tr.appendChild(cont); } document.body.appendChild(swin); } swin.style.display = ''; } EOF } print <
EOF } sub fuserlist { my($self, $cgi, $config) = @_; print <
No channel
EOF } sub fform { my($self, $cgi, $config) = @_; print <
EOF if($ENV{HTTP_USER_AGENT} !~ /Mac_PowerPC/ && (!exists $config->{disable_format_input} || !$config->{disable_format_input})) { print < EOF if(exists $config->{smilies_popup} && $config->{smilies_popup}) { print ':)'; } print < EOF for(sort {$a <=> $b} keys %colours) { print "\n"; } print < EOF } print < EOF } 1;