File: Preview.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 (215 lines) | stat: -rw-r--r-- 5,460 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
package Templates::Preview;

use SmallPigVars qw($config);
use Templates::CommentsNC;

use strict;
use vars qw(@ISA $template);

@ISA = qw(Templates::CommentsNC);

my $lang;

sub new{
  my ($class, $spcgi, $spdb, $fid, $caution) = @_;

  $template = Templates::CommentsNC->new($spcgi, $spdb);

  $template->{'STATE'} = $spcgi->{'STATE'};
  $template->{'spdb'} = $spdb || SPDB->new;
  
  $template->{'caution'} = $caution;
  $template->{'fid'} = $fid;
  
  bless $template, $class;

  $template->initialize();
  
  return $template;
}

#########################################################################
# --- Sun Dec 19 23:06:10 PST 1999
# ---
sub initialize{
  my ($template) = @_;

  my $pagefiles = {};
  $pagefiles->{'default'} = "default.temp";
  
  $template->{'pagefiles'} = $pagefiles;

  my $pagesubs = {};
  $pagesubs->{'default'} = \&whole;
  
  $template->{'pagesubs'} = $pagesubs;
  
  $lang = $template->{'lang'};
}

#########################################################################
# --- pagesubs
# ---
sub whole{
  my $STATE = $template->{'STATE'};
  my $fid = $template->{'fid'};
  my ($display, $userstatus, 
      $sid, $cid, $uid, $body, $html, $markup, $prev_op,
      , $fids) = 
      map { $STATE->{$_} } 
  qw(display userstatus 
     sid cid uid body html markup prev_op
     fids);

  # --- set files info
  $fid .= "#" if $fid && $fids;
  my $fids = $template->{'fids'} = $fid.$fids;
  $template->_set_files_info($fids);

  print qq|<FORM METHOD="post" ACTION="$config->{'cgidir'}/comments.cgi" ENCTYPE="multipart/form-data">|;

  $template->print_standard_index();
  
  # --- if caution
  if($template->{'caution'}){
      $template->print_caution_msg("", $template->{'caution'});
      $template->print_space();
  }

  $template->print_preview($fids); 
  $template->print_space();
  $template->print_new_comment_form();
  $template->print_file_att();
  $template->print_bottom_bar();
  
  $prev_op .= "#" if $prev_op;
  print qq|<INPUT type="hidden" name="prev_op" value="$prev_op|."preview\">";

  print qq|<INPUT type="hidden" name="sid" value="$sid">|;

  print qq|<INPUT type="hidden" name="fids" value="$fids">|;

  print qq|<INPUT type="hidden" name="cid" value="$cid">|;
  print qq|<INPUT type="hidden" name="uid" value="$uid">|;
  print qq|<INPUT type="hidden" name="html" value="$html">|;
  print qq|<INPUT type="hidden" name="markup" value="$markup">|;
  
  print "</form>";
}

sub print_preview{
  my ($template, $fids) = @_;
  my ($STATE, $spdb) = map{ $template->{$_} } qw(STATE spdb);
  my $theme = $template->{'theme'};
  
  my ($subject, $bodytext, $name, $email, $sid, $uid, $sig) = 
      map{ $STATE->{$_} } 
  qw(subject body poster posteremail sid uid sig);  

  $subject = $template->filter_html($subject);

  my $user_info;
  
  if($uid == 0){
      $user_info = ($name)?"$name(anon)":"anon"; 
  }
  else{
      $user_info = $name;
  }
  
  my $parent = $lang->{'parent'};
  
  my $reply = $lang->{'reply_post'};

  my $edit_post = "$lang->{'edit_post'}";

  # --- filter html and add <BR>
  my ($html, $markup) = $template->allow_html_markup($sid);
  $bodytext = $template->recover_quote($bodytext);
  $bodytext = $template->filter_html($bodytext) unless $html;
  $bodytext .= "\n\n$sig";
  $bodytext = $template->add_br($bodytext);
  $bodytext = $template->format_markup($bodytext) if $markup;

  my $time = $spdb->db_date("$config->{date_format}");

  my ($files);
  if($fids){
      my $where = join(" OR fid= ", split "#", $fids);       
      $where = "fid=$where";
				      
      ($files) = $spdb->db_select_many_new(1, "fname, fsize, fdesc, date", 
					   "FileAttach", $where);
  }

  my $files_info;

  if($files){
      
      while (my ($fname, $fsize, $fdesc, $date) = $files->fetchrow_array){
	  $date =~ s/\s+/-/g;
	  my $fnameurl;
	  ($fnameurl = $fname) =~ s/(\s+|\\)/-/g;
	  my $fnameurl = qq|<a href="$config->{'file_url'}/$date-$fnameurl">$fname</a>|;
	  $files_info .= "$fnameurl $fsize $lang->{'bytes'} $fdesc<BR>";
      }

      $spdb->db_handler_done($files);
  }

  $spdb->db_handler_done($files);

  $files_info = 
      "<HR align=left width=\"30%\"><B>$lang->{'file_attach2'}:</B><BR>$files_info" if $files_info;

  my $width;
  $width = $theme->{'intblwidth'};

  $template->print_block_start("","","",$width);

  my $content = qq^
      <tr bgcolor="$theme->{'dhdrcolor'}">
	  <td class=bheader1nb>
	      \&nbsp <b>$lang->{'subject'}:</b> $subject 
	  </td>
     </tr>
     <tr bgcolor="$theme->{'lhdrcolor'}">
	 <td class=bheader1nb>
	     &nbsp; &nbsp; $lang->{'posted_by'}: $user_info $lang->{'on'} $time &nbsp; &nbsp; &nbsp; &nbsp; [ $reply | $edit_post | $parent ]
	 </td>
     </tr>
     <tr>
	 <td>
	     <table border=0 cellspacing=0 cellpadding=10 width="100%" bgcolor=$theme->{'boxbgcolor'}>
		 <tr>
		     <td align="left" valign="top">
			 $bodytext<BR>$files_info
		     </td>
		 </tr>
	     </table>
	</td>
     </tr>
	 
	 </td>
	     </tr>
	 ^;
  print "<!--comment-->$content";

  $template->print_block_end();
}

sub print_bottom_bar{
  my ($self) = @_;
  my ($buttons, $ret);

  $buttons = qq|<INPUT TYPE="submit" name="op" value=$lang->{'Submit'}><INPUT TYPE="submit" name="op" value=$lang->{'Preview'}><INPUT TYPE="submit" name="op" value=$lang->{'AttachFile'}>|;

  $template->SUPER::print_block_start();  
  print qq|<tr width="100%"><td><FONT SIZE="1">$buttons</FONT></td></tr>|;
  $template->SUPER::print_block_end();
}

return 1;