/[webpac2]/trunk/web/browse.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/web/browse.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (hide annotations)
Wed Nov 16 15:33:12 2005 UTC (18 years, 6 months ago) by dpavlin
File size: 7948 byte(s)
 r8900@llin:  dpavlin | 2005-11-16 16:33:30 +0100
 added CSS editor

1 dpavlin 46 #!/usr/bin/perl -w
2    
3 dpavlin 54 use strict;
4    
5 dpavlin 46 use Cwd qw/abs_path/;
6     use CGI::Carp qw(fatalsToBrowser);
7     use CGI::Simple;
8 dpavlin 49 use File::Slurp;
9 dpavlin 54 use Data::Dumper;
10     use Text::Iconv;
11 dpavlin 46
12     use lib '../lib';
13    
14     use WebPAC::DB;
15     use WebPAC::Output::TT;
16    
17     my $abs_path = abs_path($0);
18     $abs_path =~ s#/[^/]*$#/../#;
19    
20     my $db_path = $abs_path . '/db/';
21 dpavlin 67 my $template_file = 'html_ffzg.tt';
22     my $css_file = 'user.css';
23 dpavlin 46
24 dpavlin 54 my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
25     my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
26    
27 dpavlin 46 my $db = new WebPAC::DB(
28     path => $db_path,
29     read_only => 1,
30     debug => 1,
31     );
32    
33     my $out = new WebPAC::Output::TT(
34     include_path => "$abs_path/conf/output/tt",
35     filters => { foo => sub { shift } },
36     );
37    
38     my $q = new CGI::Simple;
39     my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
40    
41     my $rec = $q->param('rec') || 1;
42    
43 dpavlin 54 print $q->header( -charset => 'utf-8' );
44 dpavlin 46
45 dpavlin 67 ##---- some handy subs
46    
47     sub update_file($$) {
48     my ($path, $content) = @_;
49    
50     $content = $iconv_loc->convert( $content ) || die "no content?";
51    
52     sub _conv_js {
53     my $t = shift || return;
54     return $iconv_loc->convert(chr(hex($t)));
55     }
56     $content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
57     $content =~ s/[\n\r]+$//s;
58    
59     write_file($path . '.new', $content) || die "can't save ${path}.new $!";
60     rename $path . '.new', $path || die "can't rename to $path: $!";
61     }
62    
63     sub get_file_in_html($) {
64     my ($path) = @_;
65    
66     die "no path?" unless ($path);
67    
68     my $content = read_file($path) || die "can't read $path: $!";
69     $content = $q->escapeHTML($iconv_utf8->convert($content));
70    
71     return $content;
72     }
73    
74     ##----
75    
76 dpavlin 46 if ($q->path_info =~ m#xml#) {
77    
78     my @ds = $db->load_ds($rec);
79    
80 dpavlin 49 if (@ds && $#ds > 0) {
81 dpavlin 46 print qq{<response>
82 dpavlin 49 <action type='html' target='div_record' errorCode='' errorMessage='' >
83 dpavlin 58 }, $iconv_utf8->convert( $out->apply(
84 dpavlin 67 template => $template_file,
85 dpavlin 46 data => \@ds,
86 dpavlin 58 ) ), qq{
87 dpavlin 46
88 dpavlin 57 </action>
89     <action type='javascript' errorCode='' errorMessage='' >
90 dpavlin 46 <!--
91 dpavlin 49 var el = iwfGetById('div_record_nr');
92 dpavlin 46 if (el) el.innerHTML = '# <b>$rec</b>';
93 dpavlin 49 //iwfShow('div_record');
94     iwfOpacity('div_record', 100);
95 dpavlin 46 //-->
96     </action>
97     </response>
98     };
99     exit;
100     } else {
101 dpavlin 49 print qq{<response>
102     <action type='html' target='div_record' errorCode='' errorMessage='' >
103    
104     <b>Record $rec not found!</b>
105 dpavlin 57 </action>
106     <action type='javascript' errorCode='' errorMessage='' >
107 dpavlin 49 <!--
108     var el = iwfGetById('div_record_nr');
109 dpavlin 59 if (el) el.innerHTML = '<strike>&nbsp;$rec&nbsp;</strike>';
110 dpavlin 49 //-->
111     </action>
112     </response>
113     };
114     exit;
115 dpavlin 46 }
116    
117 dpavlin 49 } elsif ($q->path_info =~ m#template#) {
118    
119 dpavlin 67 my $template_path = $out->{'include_path'} . '/' . $template_file;
120 dpavlin 49
121 dpavlin 54 if ($q->param('save_template')) {
122    
123 dpavlin 67 update_file($template_path, $q->param('tt_template'));
124 dpavlin 58
125 dpavlin 54 print qq{<response>
126 dpavlin 67 <action type='html' target='div_template_status' errorCode='' errorMessage='' >
127     <tt>$template_file</tt> saved
128 dpavlin 54 </action>
129     <action type='js'>
130     <!--
131 dpavlin 67 iwfShow('div_template_status', 1);
132 dpavlin 54 reload_rec();
133 dpavlin 67 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
134 dpavlin 54 -->
135     </action>
136     </response>
137     };
138     exit;
139    
140     }
141    
142 dpavlin 67 my $tmpl = get_file_in_html($template_path);
143 dpavlin 54
144 dpavlin 49 print qq{<response>
145     <action type='html' target='div_template' errorCode='' errorMessage='' >
146 dpavlin 54
147 dpavlin 67 <form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" >
148 dpavlin 54
149     <textarea name="tt_template" cols="80" rows="10" style="display: block;">
150 dpavlin 49 $tmpl
151     </textarea>
152 dpavlin 54
153     <br/>
154     <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
155 dpavlin 61 <!--
156     <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
157     -->
158 dpavlin 67 &nbsp;&nbsp;<span id="div_template_status" style="color: #808080;">idle</span>
159 dpavlin 54
160     <input type='hidden' value='hidden post value' name='hidValue' />
161    
162     </form>
163 dpavlin 49 </action>
164 dpavlin 61 <action type='js'>
165     <!--
166 dpavlin 67 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
167 dpavlin 61 -->
168     </action>
169 dpavlin 49 </response>
170 dpavlin 54 };
171 dpavlin 49
172 dpavlin 54 exit;
173    
174 dpavlin 67 } elsif ($q->path_info =~ m#css#) {
175    
176     my $css_path = $abs_path . '/web/' . $css_file;
177    
178    
179     if ($q->param('save_css')) {
180     update_file($css_path, $q->param('user_css'));
181    
182     print qq{<response>
183     <action type='html' target='div_css_status' errorCode='' errorMessage='' >
184     <tt>$css_file</tt> saved
185     </action>
186     <action type='js'>
187     <!--
188     iwfShow('div_css_status', 1);
189     // switch css
190     css_rnd++;
191     iwfLog('loading user.css?'+css_rnd);
192     iwfGetById('user_css_link').href = 'user.css?'+css_rnd;
193     iwfHideGentlyDelay('div_css_status', 2, 2000, 1);
194     -->
195     </action>
196     </response>
197     };
198     exit;
199    
200     }
201    
202     my $user_css = get_file_in_html($css_path);
203    
204     print qq{<response>
205     <action type='html' target='div_css' errorCode='' errorMessage='' >
206    
207     <form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" >
208    
209     <textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;">
210     $user_css
211     </textarea>
212    
213     <br/>
214     <input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" />
215     &nbsp;&nbsp;<span id="div_css_status" style="color: #808080;">idle</span>
216     </form>
217     </action>
218     <action type='js'>
219     <!--
220     iwfLog('loaded CSS template');
221     -->
222     </action>
223     </response>
224     };
225    
226     exit;
227    
228 dpavlin 46 } else {
229 dpavlin 67 print <<"_END_OF_HEAD_";
230 dpavlin 46 <html>
231     <head>
232     <title>WebPAC simple browse interface</title>
233 dpavlin 67
234     <link id="user_css_link" href="user.css" type="text/css" rel="stylesheet">
235    
236 dpavlin 46 <script type='text/javascript' src='iwf/iwfcore.js'></script>
237     <script type='text/javascript' src='iwf/iwfgui.js'></script>
238     <script type='text/javascript' src='iwf/iwfxml.js'></script>
239     <script type='text/javascript' src='iwf/iwfajax.js'></script>
240 dpavlin 67 <script type='text/javascript' src='iwf/iwconfig.js'></script>
241 dpavlin 46 <script type='text/javascript'>
242    
243     var rec = $rec ;
244     var url = '$self';
245    
246 dpavlin 67 var css_rnd = 0;
247    
248 dpavlin 46 function update_status(text) {
249 dpavlin 49 var el = iwfGetById('div_record_nr');
250 dpavlin 46 if (el) el.innerHTML = text;
251     }
252    
253     function load_rec(nr) {
254 dpavlin 59 if (nr == 1) {
255     iwfHide('a_left_arr', 1);
256     } else {
257     iwfShow('a_left_arr', 1);
258     }
259 dpavlin 46 update_status(nr+'...');
260 dpavlin 49 iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
261     iwfOpacity('div_record', 30);
262 dpavlin 46 }
263    
264     function inc_rec() {
265     rec++;
266     load_rec(rec);
267     return false;
268     }
269    
270     function dec_rec() {
271 dpavlin 59 if (rec > 1) {
272     rec--;
273     load_rec(rec);
274     }
275 dpavlin 46 return false;
276     }
277    
278 dpavlin 47 function reload_rec() {
279     load_rec(rec);
280     return false;
281     }
282    
283 dpavlin 67 function edit_template() {
284     iwfHideGently('div_css', 30, 1);
285     iwfShowGently('div_template', 30, 1);
286     return false;
287     }
288    
289     function edit_css() {
290     iwfHideGently('div_template', 30, 1);
291     iwfShowGently('div_css', 30, 1);
292     return false;
293     }
294    
295 dpavlin 49 function init_page() {
296 dpavlin 67 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
297     iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
298    
299     iwfX('div_css', iwfX('div_template'));
300     iwfY('div_css', iwfY('div_template'));
301    
302     iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
303    
304 dpavlin 49 load_rec(rec);
305 dpavlin 67
306     // load template editor
307 dpavlin 49 iwfRequest( url+'/template/', 'div_template' );
308 dpavlin 67 // load css editor
309     iwfRequest( url+'/css/', 'div_css' );
310 dpavlin 49 }
311    
312 dpavlin 46 </script>
313 dpavlin 67
314 dpavlin 46 </head>
315 dpavlin 49 <body onload="init_page();">
316 dpavlin 46
317 dpavlin 67 <div id="iwfLog">
318     </div>
319    
320 dpavlin 46 db_path = <tt>$db_path</tt><br/>
321 dpavlin 67 template = <tt>$template_file</tt><br/>
322     css = <tt>$css_file</tt>
323 dpavlin 46
324     <div style="background: #e0e0e0; padding: 0.5em; display: block;">
325 dpavlin 59 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>
326 dpavlin 49 <span id="div_record_nr"> none </span>
327 dpavlin 47
328 dpavlin 59 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>
329     <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>
330 dpavlin 67 <a href="#" onClick="iwfShowLog(); return false;">&#9636;</a>
331 dpavlin 54
332 dpavlin 46 </div>
333    
334 dpavlin 67 <div>
335    
336     <div style="display: block;">
337     Editor
338     <a id="a_template" href="#" onClick="return edit_template();">template</a>
339     <a id="a_css" href="#" onClick="return edit_css();">css</a>
340    
341 dpavlin 49 <div id="div_template">
342     <span style="color: #808080;"> no template loaded yet. </span>
343     </div>
344    
345 dpavlin 67 <div id="div_css" style="position: absolute; display: none;">
346     <span style="color: #808080;"> no CSS loaded yet. </span>
347     </div>
348    
349     </div>
350    
351 dpavlin 49 <div id="div_record" style="display: block;">
352 dpavlin 46 <span style="color: #808080;"> no record loaded yet. </span>
353     </div>
354    
355 dpavlin 49
356 dpavlin 46 </body>
357 dpavlin 67 </html>
358     _END_OF_HEAD_
359 dpavlin 46
360 dpavlin 67 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26