File: SmallPig.pm

package info (click to toggle)
sporum 1.8b1-3.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,108 kB
  • ctags: 676
  • sloc: perl: 14,300; makefile: 52
file content (220 lines) | stat: -rw-r--r-- 6,487 bytes parent folder | download
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package SmallPig;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(@EXPORT_OK);
@EXPORT_OK = qw();

use SmallPigVars qw($config);

use strict;

sub add_br{
  my $body = shift;
  my @body = split('\n', $body);
  return join('<BR>', @body);
}

sub filter_quote{
  my $str = shift;
  $str =~ s/\"/&quot;/g;
  return $str;
}

sub filter_html{
  my $str = shift;
  $str =~ s/</&lt;/g;
  $str =~ s/>/&gt;/g;
  $str = filter_quote($str);
  return $str;
}

sub recover_quote{
  my $str = shift;
  $str =~ s/&quot;/\"/g;
  return $str;
}

sub recover_html{
  my $str = shift;
  $str =~ s/&lt;/</g;
  $str =~ s/&gt;/>/g;
  $str =~ s/&quot;/\"/g;
  return $str;
}

sub format_markup{
    my ($str) = @_;
    # --- format email address
    $str =~ s/\[email\s+([^\]]+)\](.+?)\[\/email\]/<A HREF=mailto:$1>$2<\/A>/gsi;
    $str =~ s/\[email\](.+?)\[\/email\]/<A HREF=mailto:$1>$1<\/A>/gsi;
    # --- format url 
    $str =~ s/\[url\s+([^\]]+)\](.+?)\[\/url\]/<A HREF=$1>$2<\/A>/gsi;
    $str =~ s/\[url\](.+?)\[\/url\]/<A HREF=$1>$1<\/A>/gsi;
    # --- format image
    $str =~ s/\[img\](.+?)\[\/img\]/<IMG SRC=$1 BORDER=0>/gsi;
    # --- format i
    $str =~ s/\[i\](.+?)\[\/i\]/<i>$1<\/i>/gsi;
    # --- format b
    $str =~ s/\[b\](.+?)\[\/b\]/<b>$1<\/b>/gsi;

    
    # --- Emoticons (mod from Marcus J. Ertl, 29.10.1999 --- 
    $str =~ s/\s+x-\(/<IMG SRC=\"$config->{imagesdir}\/smilies\/Mad2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+x\(/<IMG SRC=\"$config->{imagesdir}\/smilies\/Mad.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Happy.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:-\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Happy.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:\(/<IMG SRC=\"$config->{imagesdir}\/smilies\/Sad.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:-\(/<IMG SRC=\"$config->{imagesdir}\/smilies\/Sad.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+;\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Wilk.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+;-\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Wilk.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:P/<IMG SRC=\"$config->{imagesdir}\/smilies\/Tongue.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:-P/<IMG SRC=\"$config->{imagesdir}\/smilies\/Tongue.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+;P/<IMG SRC=\"$config->{imagesdir}\/smilies\/Tongue2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+;-P/<IMG SRC=\"$config->{imagesdir}\/smilies\/Tongue2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:O\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Embrass2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:O/<IMG SRC=\"$config->{imagesdir}\/smilies\/Embrass.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+\^_\^/<IMG SRC=\"$config->{imagesdir}\/smilies\/Sleep.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+\^\^;/<IMG SRC=\"$config->{imagesdir}\/smilies\/Sleep3.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+\^\^/<IMG SRC=\"$config->{imagesdir}\/smilies\/Sleep2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+8-\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Cool2.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+8\)/<IMG SRC=\"$config->{imagesdir}\/smilies\/Cool.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    $str =~ s/\s+:D/<IMG SRC=\"$config->{imagesdir}\/smilies\/TooHappy.gif\" WIDTH=14 HEIGHT=15>/gsi; 
    # --- end of mod 

    return $str;
}

sub recover_markup{
    my ($str) = @_;
    # --- format email address
    $str =~ s/\[email\](.+?)\[\/email\]/$1/gsi;
    $str =~ s/\[email\s+([^\]]+)\](.+?)\[\/email\]/$2 <$1>/gsi;
    # --- format url 
    $str =~ s/\[url\](.+?)\[\/url\]/$1/gsi;
    $str =~ s/\[url\s+([^\]]+)\](.+?)\[\/url\]/$2 ($1)/gsi;
    # --- format image
    $str =~ s/\[img\](.+?)\[\/img\]//gsi;
    # --- format i
    $str =~ s/\[i\](.+?)\[\/i\]/$1/gsi;
    # --- format b
    $str =~ s/\[b\](.+?)\[\/b\]/$1/gsi;
    return $str;
}

sub url_encode{
  my $words = shift;
  $words =~ s/([^a-zA-Z0-9_.-])/"%".sprintf("%1X", ord($1))/eg;
  return $words;
}

sub get_board_status{
  my $level = shift;
  my $status = "public" unless 63^$level;
  $status = "public protected" unless 62^$level;
  $status = "user public" unless 60^$level;
  $status = "user private" unless 56^$level;
  $status = "user private protected" unless 48^$level;
  $status = "group private" unless 32^$level;
  return $status;
}

sub load_module{
    eval "require $_[0]";
    $_[0]->import(@_[1 .. $#_]);
}

sub get_lang_ptr{
    my ($lang, $type) = @_;
    
    $lang ||= $config->{'lang'};
    
    my $thememod = "Langs::$lang\::$type";

    # --- load the theme module
    load_module($thememod);
    return get_lang();
}

sub get_spmail_config{
    if($config->{'spmail_cgi'} && -d $config->{'spmail_cgi'}){
	unshift(@INC, $config->{'spmail_cgi'});
	
	require SpmailVars;
	SpmailVars->import();

	return get_mconfig();
    }

    return undef;
}

sub get_spmail_lang{
    if($config->{'spmail_cgi'} && -d $config->{'spmail_cgi'}){
	unshift(@INC, $config->{'spmail_cgi'});
	
	require SpmailLang;
	SpmailLang->import();

	return get_mlang();
    }

    return undef;
}

sub send_mail{
  my ($addr, $from, $subject, $content, $replyto, $lang) = @_;

  # --- if there is no recipient address
  return if !$addr;

  require HTML::TreeBuilder;
  require HTML::FormatText;
  
  $content =~ s/\n/<BR>/gi;
  my $html = HTML::TreeBuilder->new();
  $html->parse($content);
  my $formatter = HTML::FormatText->new(leftmargin=>0, 
					rightmargin=>76);
  $content = $formatter->format($html);

  if($config->{'smtpserver'}){
      require Net::SMTP;
      
      my $smtp = Net::SMTP->new($config->{'smtpserver'});
      if(!$smtp){
	  return (0, $@);
      }
      $smtp->mail($from);
      
      $smtp->to($addr);
      $smtp->data();
      $smtp->datasend("Subject: $subject\n");
      $smtp->datasend("To: $addr\n");
      $smtp->datasend("Reply-To: $replyto\n") if $replyto;
      $smtp->datasend("\n");
      $smtp->datasend($content);
      $smtp->dataend();
      $smtp->quit;
  }
  elsif($config->{'sendmail'}){
      local $ENV{PATH};
      unless(open MAIL, "|$config->{'sendmail'} -oi -t"){
	  return (0, "");
      }

      print MAIL "To: ", $addr, "\n";
      print MAIL "From: ", $from, "\n";
      print MAIL "Subject: ", $subject, "\n";
      print MAIL "Reply-To: $replyto\n\n" if $replyto;
      print MAIL "$content";
      close MAIL;
  }
  else{ return (0, $lang->{'no_mail_server'}); }
  
  return (1, "");
}

return 1;