DirectConnect/pslib/psweb.pm untested

filter: Statementstmt 0.0% 0 / 1153 Branchbran 0.0% 0 / 550 Conditioncond 0.0% 0 / 928 MC/DCmcdc 0.0% 0 / 551 Subroutinesub 0.0% 0 / 36 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 3243 CC 276 SCAR 100.1
CC
276
Cov
0%
config_init
36290.0
gotopage
702.0
part
240.0
CRAP 22250.3
1 #!/usr/bin/perl
2 #$Id: psweb.pm 4843 2013-08-14 12:17:58Z pro $ $URL: svn://svn.setun.net/search/trunk/lib/psweb.pm $
3  
4 =copyright
5 PRO-search web shared library
6 Copyright (C) 2003-2011 Oleg Alexeenkov http://pro.setun.net/search/ proler@gmail.com
7  
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12  
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17  
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 =cut
21  
22 #print "Content-type: text/html\n\n" if defined($ENV{'SERVER_PORT'}); # for web dev debug
23 package #no cpan
24 psweb;
25 use strict;
26 our $VERSION = ( split( ' ', '$Revision: 4843 $' ) )[1];
27 #use locale;
28 use Encode;
29 use utf8;
30 #use open qw(:utf8 :std);
31 #use encoding "utf8", STDOUT => "utf8", STDIN => "utf8", STDERR => "utf8";
32 #use encoding 'utf-8';
33 #use open ':utf8';
34 use Data::Dumper; #dev only
35 $Data::Dumper::Sortkeys = $Data::Dumper::Useqq = $Data::Dumper::Indent = 1;
36 use vars qw(@ISA @EXPORT @EXPORT_OK);
37 use lib::abs qw(./);
38 use psmisc qw(:all);
39 require Exporter;
40 @ISA = qw(Exporter);
41 @EXPORT = qw(
42 mylink
43 out_bold
44 destroy_html
45 get_param_hash
46 get_param_str
47 get_param_url_str
48 grab_begin
49 grab_end
50 nameid
51 part
52 gotopage
53 fromto
54 cache_file
55 cache_file_js
56 cache_file_css
57 is_img
58 %work %config %stat %static $param
59 );
60 use Socket;
61 #use Time::HiRes qw(time);
62 no warnings qw(uninitialized);
63 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
64 our ( %config, %work, %stat, %static, $param, );
65 #*config=\%::config;
66 #*psweb::stat = *main::stat;
67 #*psweb::work = *main::work;
68 *stat = *main::stat;
69 *work = *main::work;
70 *config = *main::config;
71 *param = *main::param;
72 sub BEGIN { $static{'script_start'} = psmisc::timer(); }
73  
74 sub config_init {
75 return if $static{'lib_init_psweb'}{ $ENV{'SCRIPT_FILENAME'} }++;
76 #my ($param) = @_;
77 psmisc::conf(
78 sub {
79 #warn "psweb::config_init;";
80 #my ($param) = @_; # print "confonce($param);"; #,%$param ;
81 $config{'root_url'} ||= $ENV{'SCRIPT_NAME'} if $ENV{'REQUEST_URI'} =~ /^\Q$ENV{'SCRIPT_NAME'}/;
82 $config{'root_dir'} ||= $1 if $ENV{'SCRIPT_NAME'} =~ m{^(.*/)([^/]+)?};
83 my $script = $2;
84 $config{'root_url'} ||= $config{'root_dir'};
85 $config{'root_url'} ||= './';
86 $config{'css_url'} ||= $config{'root_dir'};
87 $config{'js_url'} ||= $config{'root_dir'};
88 $config{'img_url'} ||= $config{'root_dir'};
89 $config{'rewrite'} = $ENV{'REQUEST_URI'};
90 $config{'rewrite'} =~ s/^$config{'root_dir'}(?:$script)?//;
91 $config{'rewrite'} =~ s/\?.*//;
92 $config{'rewrite'} = decode_url( $config{'rewrite'} );
93 $config{'result'} ||= $config{'rewrite'} || grep { defined( $param->{$_} ) } @{ $config{'user_param_founded'} };
94 $config{'gotopage_bb'} ||= 5; #gotopage buttons before current
95 $config{'gotopage_ba'} ||= 5; # --//-- after --//--
96 $config{'jscript_open'} ||= qq{<script type="text/javascript" language="JavaScript">/*<![CDATA[*/};
97 $config{'jscript_close'} ||= "/*]]>*/</script>";
98 $config{'lang_default'} ||= ''; # empty = autodetect, en or ru or...
99 #$config{'lng_default_auto'} ||= 'en'; # if autodetect fail
100 $config{'lng'}{'en'}{'language-code'} ||= 'en';
101 #$config{'lng'}{'en'}{'codepages'} ||= [qw(utf-8 iso-8859-1)];
102 $config{'lng'}{'ru'}{'language-code'} ||= 'ru';
103 $config{'config_sets'} ||= [qw(mode style)];
104 $config{'config_user'} ||= [ @{ $config{'config_sets'} }, qw(lang specify on_page css css_add ) ]; #codepage
105 $config{'lng'}{''}{'darr'} ||= '&darr;';
106 $config{'lng'}{''}{'uarr'} ||= '&uarr;';
107 $config{'lng'}{''}{'>'} ||= '&gt;';
108 $config{'lng'}{''}{'<'} ||= '&lt;';
109 $config{'lng'}{''}{'cp1251'} ||= 'WINDOWS-1251';
110 $config{'lng'}{''}{'ctrl-prev'} ||= '(Ctrl &#8592;)';
111 $config{'lng'}{''}{'ctrl-next'} ||= '(Ctrl &#8594;)';
112 $config{'lng'}{''}{'thislink'} ||= '.';
113 $config{'sel_sep'} ||= ' ';
114 $config{'foot_stat_sep'} ||= ' :: ';
115 $config{'http-header-default'} ||= "http-header: text/plain\n\n"; #'text/html'
116 $config{'post_init_every'}{'psweb'} = sub {
117 my ($param) = @_;
118 if ( $config{'param_cookie'} ) {
119 local %_;
120 @_{ @{ $config{'param_cookie'} || [] } } = (1) x @{ $config{'param_cookie'} || [] };
121 delete $param->{$_} for grep { !$_{$_} } keys %{ get_params_one( undef, split( /;\s*/, $ENV{'HTTP_COOKIE'} ) ) };
122 }
123 %$param = ( %{ $param || {} }, %{ $config{'force_param'} || {} } );
124 $param->{ $config{'param_trans'}{$_} } = $param->{$_} for ( grep $config{'param_trans'}{$_}, keys %$param );
125 $config{'view'} ||= ( $param->{'view'} || ( defined( $ENV{'SERVER_PORT'} ) ? 'html' : 'text' ) );
126 if ( $param->{'json'} and psmisc::use_try 'JSON' ) {
127 $config{'view'} = 'json';
128 my $j = {};
129 eval { $j = JSON->new->decode( $param->{'json'} ) || {} }; #allow_nonref->
130 #warn Dumper $j;
131 $param->{$_} = $j->{$_} for keys %$j;
132 }
133 for ( split( /\s*,\s*/, $ENV{'HTTP_ACCEPT_LANGUAGE'} ) ) {
134 $_ = lc;
135 s/\;.*$//;
136 $work{'lang'} ||= $_, last if $config{'lng'}{$_};
137 $work{'lang'} ||= $_, last if s/-(\w+)$// and ( $config{'lng'}{$_} or $config{'lng'}{$1} );
138 }
139 if ( !$work{'lang'} or $work{'lang'} eq 'en' ) {
140 $ENV{'HTTP_USER_AGENT'} =~ /\(([^)]+)\)/;
141 for ( split '; ', $1 ) {
142 $_ = lc;
143 $work{'lang'} = $_, last if exists $config{'lng'}{$_} and $config{'lng'}{$_};
144 }
145 }
146 $work{$_} = ( $param->{$_} || $config{$_} || $work{$_} ) for @{ $config{'config_sets'} };
147 #TODO recurse hash copy
148 %config = ( %config, %{ $config{ $work{$_} } || {} } ) for @{ $config{'config_sets'} };
149 $work{$_} = ( length( $param->{$_} ) ? $param->{$_} : ( $config{$_} or $work{$_} ) ) for @{ $config{'config_user'} };
150 $work{$_} = $param->{$_} for grep { defined( $param->{$_} ) } @{ $config{'param_config'} };
151 $work{'lang'} = undef if $work{'lang'} and !exists $config{'lng'}{ $work{'lang'} };
152 $work{'lang'} ||= $config{'lang_default'};
153 $config{'lng'}{'ru'}{'codepages'} ||= [ keys %{ $config{'trans'} } ];
154 my %c = ( map { $_ => 1 } @{ $config{'lng'}{ $work{'lang'} }{'codepages'} || [] } );
155 $work{'codepage'} = 'utf-8';
156 #binmode( STDOUT, ':utf8' );
157 #binmode( STDIN, ':utf8' );
158  
159 =old
160 for ( map { lc } split( /\s*,\s*/, $ENV{'HTTP_ACCEPT_CHARSET'} ) ) {
161 s/\;.*$//;
162 $_ = psmisc::cp_normalize( $_ || next );
163 $work{'codepage'} ||= $_, last if $c{$_};
164 }
165 $work{'codepage'} = undef if $work{'codepage'} and !Encode::find_encoding( $work{'codepage'} );
166 $work{'codepage'} ||=
167 $config{'lng'}{ $work{'lang'} }{'codepage_default'}
168 || $config{'codepage_default'}
169 || $config{'codepage'};
170 $work{'codepage'} = psmisc::cp_normalize( $work{'codepage'} );
171 $config{'rewrite'} = cp_trans( 'utf-8', $work{'codepage'}, $config{'rewrite'} );
172 =cut
173  
174 $config{'lng'}{'en'}{'specify'} ||= 'more options';
175 }
176 },
177 1001
178 );
179 psmisc::conf(
180 sub {
181 #warn Dumper __FILE__, __LINE__, $param;
182 $config{'internet_bots'} //=
183 join( '|', qw(bot crawler spider checker worm ping heritrix perl yandex rambler NG/ Yahoo mail\.ru facebook) )
184 ; #Gigabot googlebot msnbot Gokubot
185 $config{'client_bot'} //= 1
186 if ( $ENV{'HTTP_USER_AGENT'} =~ /$config{'internet_bots'}/i )
187 or $param->{'testbot'}
188 or ( $ENV{'SERVER_PORT'} and !$ENV{'HTTP_USER_AGENT'} );
189 $config{'client_no_high_priority'} = 1 if $ENV{'HTTP_USER_AGENT'} =~ /Mediapartners-Google/i;
190 #warn "bot:", $config{'client_bot'}, Dumper $param;
191 $config{'out'}{'html'}{'result-flush'} ||= sub {
192 my ($param) = @_;
193 print $config{'jscript_open'}, qq{sort_res()}, $config{'jscript_close'};
194 };
195 $config{'out'}{''}{'search'} ||= sub {
196 my ( $param, $table, $where ) = @_;
197 #print( 'dev', 'SEARCHSS', $where, 'lim=', $static{'db'}->{'limit'} );
198 part( 'similar-query', $param, $table ) if $param->{'q'};
199 #printlog( 'dev', 'search001' , Dumper($param));
200 $static{'db'}->user_params($param);
201 #$static{'db'}->dump_cp();
202 my $tim = time();
203 #printlog( 'dev', 'tim0', $stat{'found_time'} ,time() , $tim);
204 $static{'db'}->count( $param, $table ) if $static{'db'}->{'page'} eq 'rnd';
205 $stat{'found_time'} += time() - $tim;
206 #printlog( 'dev', 'tim1', $stat{'found_time'} ,time() , $tim);
207 #printlog( 'dev', 'search01', $static{'db'}->{'limit_offset'}, $static{'db'}->{'page'} );
208 my $err;
209 #printlog( 'dev', 'search00', $where, 'lim=', $static{'db'}->{'limit'} );
210 #$where ||= $static{'db'}->where( $param, undef, $table );
211 $where ||= $static{'db'}->can_select( $param, $table );
212 if ( $where and $static{'db'}->{'limit'} > 0 ) {
213 #printlog( 'dev', 'search0', $where, 'lim=', $static{'db'}->{'limit'} );
214  
215 =was
216 if ( $static{'db'}->{'limit'} > 0 ) {
217 #printlog( 'dev', 'search1', $where , $param->{'codepage'} ,$static{'db'}->{'cp_in'});
218 psmisc::flush();
219 #++$err if $static{'db'}->prepare( $static{'db'}->select_body( scalar cp_trans( $param->{'codepage'} ,$static{'db'}->{'codepage'}, $where ), $param, $table ) ) > 0;
220 ++$err if $static{'db'}->prepare( $static{'db'}->select_body( $where , $param, $table ) ) > 0;
221 #printlog( 'dev', 'serr=', $err, $static{'db'}->{'sth'}, $static{'db'}->{'actual'}, $static{'db'}->{'limit'} );
222 }
223 if ( !$err and $static{'db'}->{'sth'} and $static{'db'}->{'actual'} > 0 and $static{'db'}->{'limit'} > 0 ) {
224 #printlo
225 my $row = $static{'db'}->{'sth'}->fetchrow_hashref();
226 part( 'result_head', $param, $table, $row, { 'no_cont' => 1 } );
227 #while ( my $row = $static{'db'}->{'sth'}->fetchrow_hashref ) {
228 while ($row) {
229 part( 'result_string_pre', $param, $table, $row, { 'no_cont' => 1 } );
230 part( 'result_string', $param, $table, $row, { 'no_cont' => 1 } );
231 ++$stat{'results'};
232 part( 'result_string_post', $param, $table, $row, { 'no_cont' => 1 } );
233 $row = $static{'db'}->{'sth'}->fetchrow_hashref;
234 }
235 $static{'db'}->count( $param, $table );
236 part( 'result_foot', $param, $table, undef, { 'no_cont' => 1 } );
237 }
238 $static{'db'}->count( $param, $table );
239 #$static{'db'}->count( $param, $table );
240 part( 'result_error', $param, $table ) if $err;
241 =cut
242  
243 psmisc::flush();
244 #if ( $static{'db'}->{'limit'} > 0 ) {
245 #printlog( 'dev', 'search1', $where , $param->{'codepage'} ,$static{'db'}->{'cp_in'});
246 #++$err if $static{'db'}->prepare( $static{'db'}->select_body( scalar cp_trans( $param->{'codepage'} ,$static{'db'}->{'codepage'}, $where ), $param, $table ) ) > 0;
247 #++$err if $static{'db'}->prepare( $static{'db'}->select_body( $where , $param, $table ) ) > 0;
248 #printlog( 'dev', 'serr=', $err, $static{'db'}->{'sth'}, $static{'db'}->{'actual'}, $static{'db'}->{'limit'} );
249 #}
250 #if ( !$err and $static{'db'}->{'sth'} and $static{'db'}->{'actual'} > 0 and $static{'db'}->{'limit'} > 0 ) {
251 #printlo
252 #my $row = $static{'db'}->{'sth'}->fetchrow_hashref();
253 my $n;
254 my $tim = time();
255 #printlog( 'dev', 'searchr0000', Dumper $param);
256 my $line = sub (@) {
257 for my $row (@_) {
258 #utf8::decode $_ for values %$row;
259 #printlog( 'dev', 'searchr0', Dumper $row );
260 #$stat{'found_time'} ||= time() - $work{'start_time'};
261 $stat{'found_time'} += time() - $tim unless $n;
262 #printlog( 'dev', 'tim2', $stat{'found_time'} ,time() , $tim);
263 part( 'result_head', $param, $table, $row, { 'no_cont' => 1 } ) unless $n++;
264 #while ( my $row = $static{'db'}->{'sth'}->fetchrow_hashref ) {
265 #while ($row) {
266 part( 'result_string_pre', $param, $table, $row, { 'no_cont' => 1 } );
267 part( 'result_string', $param, $table, $row, { 'no_cont' => 1 } );
268 ++$stat{'results'};
269 part( 'result_string_post', $param, $table, $row, { 'no_cont' => 1 } );
270 #$row = $static{'db'}->{'sth'}->fetchrow_hashref;
271 #printlog( 'dev', 'searchr1', $row);
272 }
273 };
274 #my $sort = sub { print $config{'jscript_open'}, qq{sort_res()}, $config{'jscript_close'}; };
275 for my $row (
276 $static{'db'}->select(
277 $table, $param, {
278 row => $line,
279 #flush => sub { part( 'result-flush', $param ); psmisc::flush() }
280 flush => sub {
281 #$sort->();
282 part( 'result-flush', $param );
283 psmisc::flush();
284 },
285 }
286 )
287 )
288 {
289 $line->($row);
290 }
291 $err += $static{'db'}->err();
292 #printlog( 'dev', 'search err', $static{'db'}->err());
293 $static{'db'}->count( $param, $table );
294 $err += $static{'db'}->err();
295 #$sort->();
296 part( 'result-flush', $param );
297 part( 'result_foot', $param, $table, undef, { 'no_cont' => 1 } );
298 #}
299 #$static{'db'}->count( $param, $table );
300 #$static{'db'}->count( $param, $table );
301 part( 'result_error', $param, $table, $err ) if $err;
302 }
303 #$stat{'found_time'} ||= time() - $work{'start_time'};
304 part( 'result-report', $param ) unless $err;
305 };
306 $config{'out'}{''}{'main_or_search'} ||= sub {
307 my ( $param, $table ) = @_;
308 my ($param_num);
309 #my $wparam = {%$param};
310 #print "PCP1[$work{'codepage'}, $config{'cp_int'}]($wparam->{path})", Dumper $wparam;
311 #cp_trans_hash( $work{'codepage'}, $config{'cp_int'}, $wparam );
312 #print "PCP2[$work{'codepage'}, $config{'cp_int'}]($wparam->{path})";
313 #my $where = $static{'db'}->where( $param, $param_num, $table );
314 my $where = $static{'db'}->can_select( $param, $table );
315 psmisc::printall( \$config{'html_result_bef'}, $param ) if $where;
316 #$work{'start_time'} ||= time();
317 #printlog( 'dev', 'PRE-SERACH', Dumper $where, $param, $table , "($config{'use_sphinx'} and $param->{'q'})");
318 if ( (
319 ( $where and ( $static{'db'}->where( \%{ $config{'force_param'} }, $param_num, $table ) ne $where ) )
320 or ( $param->{ 'count_f' . $param_num } and !$config{'force_param'}{ 'count_f' . $param_num } )
321 or ( $param->{ 'count_size' . $param_num } and !$config{'force_param'}{ 'count_size' . $param_num } )
322 or ( $static{'db'}{'use_sphinx'} and $param->{'q'} )
323 )
324 )
325 {
326 part( 'search', $param, $table, $where );
327 } else {
328 part( 'main', $param, $table );
329 }
330 };
331 $config{'out'}{'html'}{'header'} ||= sub {
332 my ( $param, $table ) = @_;
333 part( 'loading', $param ) if ( $config{'ajax'} );
334 part( 'pre-search-form', $param, $table );
335 part( 'search-form', $param, $table );
336 #print '<br/><br/>', lang('starting downloading'), ' <a href="', $param->{'go'}, '">', $param->{'go'}, '</a><br/>',
337 #lang('if download does not start you can try other locations'), '<br/><br/>'
338 #if $param->{'go'};
339 };
340 $config{'out'}{'html'}{'search-form'} ||= sub {
341 my ( $gparam, $table ) = @_;
342 my $param = {%$gparam};
343 #print "PCP[$work{'codepage'}, $config{'cp_int'}]", Dumper $param;
344 cp_trans_hash( $work{'codepage'}, $config{'cp_int'}, $param );
345 print $config{'jscript_open'}, 'function disable_form(obj) {',
346 map( 'repl(\'' . $_ . '\', \'disabled\', \'true\');', @{ $config{'user_param_disable'} } ),
347 'if (!gid(\'search_prev\').checked)',
348 join( ',', map { 'repl(\'' . $_ . '0\',\'value\',\'\')' . $config{'js_debug'} } @{ $config{'user_param_founded'} } ),
349 ';',
350 'for(i = 0; i < obj.length; ++i) { if (!obj[i].value || obj[i].className==\'input-help\') obj[i].disabled=true;}',
351 '}',
352 #'for(i in obj) { if (!obj[i].value || obj[i].className==\'input-help\') obj[i].disabled=true;}', '}',
353 'function enable_form(obj) {',
354 'for(i = 0; i < obj.length; ++i) if (!obj[i].value || obj[i].className==\'input-help\') obj[i].disabled=false;', '}',
355 #'for(i in obj) if (\'value\' in obj[i] &&(!obj[i].value || obj[i].className==\'input-help\')&& \'disabled\' in obj[i]) obj[i].disabled=false;', '}',
356 $config{'jscript_close'};
357 print ' <form method="', $config{'form_method'}, '" action="', $config{'root_url'},
358 '" id="searchform" ' . $config{'js_debug'} . 'onsubmit="disable_form(this);',
359 ( $config{'ajax'} ? 'dosubmit(); return false;' : '' ),
360 '" ' . $config{'js_debug'} . 'onmouseover="enable_form(this);" ',
361 #(!$config{'no_ajax'} ? ' onchange="alert(100);dosubmit();" ' : ''),
362 #(!$config{'no_ajax'} ? ' onkeypress="disable_form(this);dosubmit();enable_form(this);" _onchange="disable_form(this);dosubmit();enable_form(this);" ' : ''),
363 '>';
364 part( 'search-form-input', $param, $table );
365 print $config{'jscript_open'}, qq@
366 var obj=gid('searchform');
367 for(i in obj){
368 //if(!obj[i]||!obj[i].addEventListener)continue;
369 //obj[i].addEventListener('change',function(e){var el=gid('page');if(el.value>1)el.value=1;},false);
370 setup_event(obj[i], 'change', function(e){var el=gid('page');if(el.value>1)el.value=1;});
371 }
372 @, $config{'jscript_close'};
373 print '</form>',
374 #$config{'jscript_open'}, qq@form_strip_setup('searchform');@, $config{'jscript_close'},
375 ;
376 };
377 $config{'out'}{'html'}{'http-header'} ||= "Content-type: text/html\n\n";
378 $config{'out'}{'html'}{'form-i-search'} ||= sub {
379 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
380 print '', (
381 defined($paramnum)
382 ? (
383 '<select name="glueg',
384 $paramnum,
385 '" dir="ltr" >',
386 '<option value="">',
387 lang('and'),
388 '</option>',
389 '<option value="or" ',
390 ( $param->{ 'glueg' . $valuenum } eq 'or' ? 'selected="selected"' : '' ),
391 '>',
392 lang('or'),
393 '</option>', (
394 $config{'enable_xor_query'}
395 ? (
396 '<option value="xor" ',
397 ( $param->{ 'glueg' . $valuenum } eq 'xor' ? 'selected="selected"' : '' ),
398 '>', lang('xor'), '</option>',
399 )
400 : ()
401 ),
402 '</select> '
403 )
404 : psmisc::printall( $config{'i-search_bef'} )
405 ),
406 '<input type="text" ', nameid( 'q' . $paramnum ), ' size="',
407 ( ( !$paramnum and $config{'main_q_length'} )
408 ? $config{'main_q_length'}
409 : check_int( length( $param->{ 'q' . $valuenum } ), 20, 30, 20 ) ), '" maxlength="160" ',
410 value( $param->{ 'q' . $valuenum } ),
411 #'" maxlength="160" value="', to_quot($param->{'q'.$valuenum}, '"'),
412 #'" />', $config{'form-i-search-input_right'};
413 #(!$config{'no_ajax'} ? ' onchange="dosubmit();" ' : ''),
414 #(!$config{'no_ajax'} ? ' onkeypress="dosubmit();" ' : ''),
415 '/>', $config{'form-i-search-input_bef'};
416 print '<input ',
417 ( !$config{'ajax'}
418 ? 'type="submit"'
419 : 'type="button" ' . $config{'js_debug'} . 'onclick="disable_form(gid(\'searchform\'));dosubmit(); return false;"' ),
420 ' value="'
421 #. 'onclick="dosubmit(); return false;"' ), ' value="'
422 . lang('search'), '"/> ' unless ( defined($paramnum) );
423 };
424 $config{'out'}{'html'}{'form-reset'} ||= sub {
425 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
426 print $config{'sel_sep'},
427 mylink( lang('reset'), undef, { 'onclick' => 'gid(\'searchform\').reset(); return false;', 'href' => '#' }, {} );
428 };
429 $config{'out'}{'html'}{'form-clear'} ||= sub {
430 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
431 print $config{'sel_sep'}, mylink(
432 lang('clear'),
433 undef, {
434 'onclick' => 'var obj = gid(\'searchform\');'
435 . 'for(i = 0; i < obj.length; ++i) { if (obj[i].value && (obj[i].className!=\'input-help\' && obj[i].type!=\'submit\' && obj[i].type!=\'button\')) obj[i].value=\'\';}; return false;',
436 #. 'for(i in obj) { if (obj[i].value && (obj[i].className!=\'input-help\' && obj[i].type!=\'submit\' && obj[i].type!=\'button\')) obj[i].value=\'\';}; return false;',
437 'href' => '#',
438 'class' => 'a',
439 },
440 { 'tag' => 'span', },
441 );
442 };
443 $config{'out'}{'html'}{'form-link-hide-specify'} ||= sub {
444 #my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
445 print '<span class="a" ' . $config{'js_debug'} . 'onclick="hide_adv();return false;">', lang('hide'), '</span>';
446 };
447 $config{'out'}{'html'}{'form-link-specify'} ||= sub {
448 #my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
449 print '<span class="a" ' . $config{'js_debug'} . 'onclick="show_adv();return false;">', lang('specify'), '</span>';
450 };
451 $config{'out'}{'html'}{'form-link-specify-hide'} ||= sub {
452 my ( $param, $table, $fparam ) = @_;
453 #print "lspc1:";
454 part(
455 'form-link-hide-specify', $param, $table, undef, #$param, $table, undef,
456 #{ 'cont_param' => ' id="form-link-hide-specify" style="display:none;" ' },
457 { 'cont_param' => ' style="display:none;" ' },
458 #$work{'paramnum'}, $work{'valuenum'}
459 ) unless $config{'no_hide'};
460 #print "lspcss";
461 part(
462 'form-link-specify', #undef,undef,undef, #$param, $table, undef, undef,
463 #{ 'cont_param' => ' id="form-link-specify" ' },
464 #$work{'paramnum'}, $work{'valuenum'}
465 ) unless $config{'no_hide'};
466 #print "lspc2";
467 };
468 $config{'out'}{'html'}{'form-links'} ||= sub {
469 my ( $param, $table ) = @_;
470 #print "ZZZ";
471 print $config{'form-link-bef'}, mylink( lang('..'), undef, undef, { 'base' => $_ } ), $config{'form-link-aft'},
472 $config{'sel_sep'}
473 if !$config{'no_form-links-up'} and ( ( $_ = $config{'root_url'} ) =~ s|^(\w+://[^/]+)/.+$|$1| );
474 print $config{'form-link-bef'}, mylink( lang('main') ), $config{'form-link-aft'}, $config{'sel_sep'}
475 if !$config{'no_form-links-main'}; #and ( $config{'ajax'} or ( $config{'result'} || $param->{'show'} ) );
476 print $config{'form-link-bef'}, mylink( lang('stats'), { 'show' => 'stat' } ), $config{'form-link-aft'},
477 $config{'sel_sep'}
478 unless $config{'no_form-links-stat'};
479 print $config{'form-link-bef'}, mylink( lang('add'), { 'show' => 'add' } ), $config{'form-link-aft'}, $config{'sel_sep'}
480 if $config{'allow_add'} and ( !$config{'web_adder_mask'} xor $config{'client_ip'} =~ $config{'web_adder_mask'} );
481 };
482 $config{'out'}{'html'}{'form-adjust'} ||= sub {
483 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
484 part( 'form-adjust-win', $param, $table, undef, { 'cont_param' => ' style="display:none;" ' }, $paramnum, $valuenum );
485 $config{'form-adjust-no-move'} //= 0;
486 print $config{'form-link-bef'},
487 qq{<span class="a" }
488 . $config{'js_debug'}
489 . qq{onclick="menu_toggle(this, gid(\'form-adjust-win\'), -20, 5, $config{'form-adjust-no-move'} );">},
490 lang('adjust'), '</span>', $config{'form-link-aft'};
491 };
492 $config{'out'}{'html'}{'form-adjust-win-config'} ||= sub {
493 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
494 print lang($_), ' <input type="checkbox" ', nameid($_), ' ' . $config{'js_debug'} . 'onclick="cookie_checkbox(this);" ',
495 ( ( $config{$_} ) ? 'checked="checked"' : '' ), '/><br/>'
496 for @{ $config{'param_config'} || [] };
497 };
498 $config{'out'}{'html'}{'form-adjust-win'} ||= sub {
499 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
500 print q{<div class="results">};
501 print lang('show results'),
502 '<select name="on_page" dir="ltr" '
503 . $config{'js_debug'}
504 . 'onchange="createCookie(\'on_page\', value);"><option value=""></option>',
505 map( (
506 '<option value="',
507 $_, '" ', ( $param->{'on_page'} == $_ ? 'selected="selected"' : '' ),
508 '>', lang($_), '</option>'
509 ),
510 ( 10, 20, 50, 100 ) ),
511 '</select></div>';
512 print q{<div class="spacify">};
513 print lang('specify'),
514 '<select name="on_page" dir="ltr" '
515 . $config{'js_debug'}
516 . 'onchange="createCookie(\'specify\', value); if(value==\'on\') allow_show_adv_auto = 1,show_adv(); if(value==\'off\') allow_show_adv_auto = 0, hide_adv();if(value==\'auto\') allow_show_adv_auto = 1;"><option value=""></option>',
517 map( (
518 '<option value="',
519 $_, '" ', ( ( $work{'specify'} eq $_ ) ? 'selected="selected"' : '' ),
520 '>', lang($_), '</option>'
521 ),
522 qw(auto on off) ),
523 '</select></div>';
524 print q{<div class="images">};
525 psmisc::printu lang('show images'), ' <select dir="ltr" id="img" name="img" title="', lang('max in bytes or all'),
526 '" ' . $config{'js_debug'} . 'onchange="createCookie(\'img\', value);" >', '<option value="">', lang('no'),
527 '</option>',
528 map(
529 ( '<option value="', $_, '" ', ( ( $work{'img'} eq $_ ) ? 'selected="selected"' : '' ), '>', lang($_), '</option>' ),
530 @{ $config{'img_show_sizes'} } ),
531 '</select></div>'
532 unless $config{'no_player'};
533 #print ' Будут показаны картинки с размером, не превышающий указанный, если all - то все картинки. Целесообразно использовать с галочкой online' if $param->{'help'};
534 part( 'form-adjust-win-config', $param, $table, undef, undef, $paramnum, $valuenum );
535 print '<div><span class="a apply" ' . $config{'js_debug'} . 'onclick="window.location.reload(false);">', lang('apply'),
536 '</span></div>';
537 print '<div><span class="a reset" ' . $config{'js_debug'} . 'onclick="',
538 map( "eraseCookie('$_');", @{ $config{'param_cookie'} } ), 'window.location.reload(false);">', lang('reset'),
539 '</span></div>';
540 print '<div><span class="a close" ' . $config{'js_debug'} . 'onclick="menu_hide();return false;">', lang('hide'),
541 '</span></div>';
542 };
543 $config{'out'}{'html'}{'form-in-founded'} ||= sub {
544 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
545 print $config{'sel_sep_head'}, lang('in found'), ' <input type="checkbox" id="search_prev" name="search_prev" ',
546 ( $config{'client_ie'} ? 'onclick' : 'onchange' ), '="', # IE SUKA MUST DIE
547 'toggleview(\'tr_hidden_prev\');',
548 map( 'if (checked &amp;&amp; gid(\''
549 . $_
550 . '\').value== \''
551 . destroy_quotes( $param->{$_} )
552 . '\') gid(\''
553 . $_
554 . '\').value=\'\';',
555 grep $param->{$_},
556 @{ $config{'user_param_founded'} } ),
557 map( 'if (!checked &amp;&amp; (gid(\''
558 . $_
559 #map( 'if (!checked && (gid(\'' . $_
560 . '\').value== \'\' || gid(\''
561 . $_
562 . '\').className==\'input-help\')) gid(\''
563 . $_
564 . '\').value=\''
565 . destroy_quotes( $param->{$_} )
566 . '\', gid(\''
567 . $_
568 . '\').className=\'input-normal\';', grep $param->{$_}, @{ $config{'user_param_founded'} } ),
569 '"/> ';
570 };
571 $config{'out'}{'html'}{'form-accurate'} ||= sub {
572 my ( $param, $table, $fparam, $cparam, $paramnum, $valuenum ) = @_;
573 if (
574 grep {
575 ( $config{'sql'}{'table'}{$table}{$_}{'fulltext'} and $config{'sql'}{'table'}{$table}{$_}{'stem'} )
576 or ( $config{'sql'}{'table_param'}{$table}{'stemmed_index'} and !$config{'use_sphinx'} )
577 } keys %{ $config{'sql'}{'table'}{$table} }
578 )
579 {
580 print $config{'sel_sep_head'};
581 my $link = 1 if $config{'result'} and $param->{ 'q' . $valuenum };
582 print '<a href="#" onclick="gid(\'accurate' . $paramnum . '\').checked=\'',
583 ( $param->{ 'accurate' . $valuenum } ? '' : 'checked' ), '\'; dosubmit(); return false;">',
584 if $link;
585 print lang('accurate');
586 print '</a>' if $link;
587 psmisc::printu ' <input type="checkbox" ', nameid( 'accurate' . $work{'paramnum'} ), ' ',
588 ( ( $param->{ 'accurate' . $valuenum } eq 'on' ) ? 'checked="checked"' : '' ), '/>';
589 return 1;
590 }
591 print '<input type="hidden" ', nameid( 'accurate' . $work{'paramnum'} ), '/>';
592 return 0;
593 };
594 $config{'out'}{'html'}{'one-query'} ||= sub {
595 my ( $param, $table, $fparam ) = @_;
596 local $param->{'help'} = 0 if defined $work{'paramnum'};
597 my $questions = 0;
598 map { ++$questions; } grep defined( $param->{ $_ . $work{'valuenum'} } ), @{ $config{'user_param_founded'} };
599 return
600 if ( $work{'paramnum'} )
601 and ( $work{'paramnum'} > 100 or ( $work{'paramnum'} > $param->{'complex'} and !$questions ) );
602 local $config{'sel_sep'} = ' ' . lang( $param->{ 'gluel' . $work{'valuenum'} } ) . ' '
603 if $param->{ 'gluel' . $work{'valuenum'} };
604 #print "P$work{'paramnum'};V$work{'valuenum'};";
605 psmisc::printall( $config{ 'html_header-' . $work{'paramnum'} . '-bef' }, $param, $table, $fparam );
606 print '<div class="header-', ( ( defined $work{'paramnum'} or defined $work{'valuenum'} ) ? 'extended"' : '1"' ),
607 ( $work{'paramnum'} eq 0 ? ' ' . nameid('tr_hidden_prev') . ' style="display:none;" ' : '' ), '>';
608 part( 'form-i-search', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
609 unless ( defined( $work{'paramnum'} ) ) {
610 part( 'form-accurate', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
611 if ( $config{'allow_search_in_founded'}
612 and $questions
613 and ( !$config{'use_sphinx'} or !$param->{ 'q' . $work{'valuenum'} } ) )
614 {
615 part( 'form-in-founded', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
616 } else {
617 print '<input type="hidden" ', nameid('search_prev'), '/>';
618 }
619 part( 'form-online', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} ) if !$config{'no_online'};
620 unless ( $config{'no_index'}
621 or $config{'ignore_index'}
622 or $config{'table_param'}{$table}{'no_index'}
623 or $config{'table_param'}{$table}{'ignore_index'} )
624 {
625 #print'Искать только на доступных в данный момент ресурсах.' if $param->{'help'}; # print'</tr><tr>' if $param->{'help'};
626 part( 'form-help', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
627 part( 'form-link-specify-hide', $param, $table, ) unless $config{'one-query-no-link-specify'};
628 }
629 }
630 unless ( defined( $work{'paramnum'} ) ) {
631 print '</div>';
632 psmisc::printall( $config{'html_header-1-aft'}, $param, $table, $fparam );
633 print '<div class="header-2" id="tr_adv" ', ( $config{'no_hide'} ? '' : 'style="display:none;">' );
634 } else {
635 print $config{'sel_sep'};
636 }
637 print qq{<div class="path">};
638 my $name;
639 for (
640 sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} } grep {
641 !$config{ 'no_' . $_ }
642 and $config{'sql'}{'table'}{$table}{$_}{'nav_field'}
643 and !$config{'sql'}{'table'}{$table}{$_}{'nav_hide'}
644 } keys %{ $config{'sql'}{'table'}{$table} }
645 )
646 {
647 my $value = $param->{ $_ . $work{'valuenum'} };
648 $name = lang( $_ . '_symb' );
649 #($param->{ $_ . $work{'valuenum'} } ? () : lang( $_ . '_symb_alt' )),
650 ( $name eq $_ . '_symb' ? ( $name = lang($_) ) : () ),
651 print( $name , ( $value ? () : $config{'lng'}{''}{ $_ . '_symb_alt' } ), ),
652 ( ( $param->{'expert'} or $param->{ $_ . '_mode' . $work{'valuenum'} } )
653 ? select_mode( $param, $work{'paramnum'}, $work{'valuenum'} )
654 : 0 );
655 print(
656 '<input class="input" style="display:none" type="text" id="',
657 $_,
658 $work{'paramnum'},
659 '" name="',
660 $_,
661 $work{'paramnum'},
662 '" title="',
663 lang($_),
664 '" placeholder="',
665 lang($_),
666 '" size="',
667 psmisc::check_int( length($value), 5, 25 ),
668 '" ',
669 value($value),
670 '/>',
671 qq{<span class="a input},
672 ( length $value ? ' filled' : '' ),
673 qq{" onclick="var w = this.offsetWidth;hide_id(this);show_id('$_$work{'paramnum'}');if (w)gid('$_$work{'paramnum'}')/*.clientWidth*/.style.width=w+'px';" title="},
674 lang($_),
675 qq{">},
676 ( destroy_html( $param->{ $_ . $work{'valuenum'} } ) // lang($_) ),
677 qq{</span>},
678 )
679 #(
680 #( defined( $param->{ $_ . $work{'valuenum'} } ) and ( length( $param->{ $_ . $work{'valuenum'} } ) > 5 ) )
681 #? length( $param->{ $_ . $work{'valuenum'} } )
682 #: '5'
683 #),
684 }
685 print qq{</div><div class="sorter">};
686 print( $config{'sel_sep'} ), select_mode( $param, $work{'paramnum'}, $work{'valuenum'} ), print(
687 '<input type="text" id="', $_, $work{'paramnum'}, '" name="', $_, $work{'paramnum'}, '" size="5" ',
688 #( defined( $param->{ $_ . $work{'valuenum'} } ) ? value($param->{ $_ . $work{'valuenum'} }) : '' ), '/> ' )
689 value( $param->{ $_ . $work{'valuenum'} } ), '/> '
690 )
691 for (
692 sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} } grep {
693 !$config{ 'no_' . $_ }
694 and $config{'sql'}{'table'}{$table}{$_}{'nav_num_field'}
695 and !$config{'sql'}{'table'}{$table}{$_}{'nav_hide'}
696 } keys %{ $config{'sql'}{'table'}{$table} }
697 );
698 print $config{'sel_sep'}, '<select id="search_days_mode', $work{'paramnum'}, '" name="search_days_mode',
699 $work{'paramnum'}, '" dir="ltr">', '<option value="">', lang('days'), '</option>', '<option value="g" ',
700 ( $param->{ 'search_days_mode' . $work{'valuenum'} } =~ /[g>]/i ? 'selected="selected"' : '' ), '>', lang('<'),
701 '</option>', '<option value="l" ',
702 ( $param->{ 'search_days_mode' . $work{'valuenum'} } =~ /[l<]/i ? 'selected="selected"' : '' ), '>', lang('>'),
703 '</option>', '</select><input type="text" id="search_days', $work{'paramnum'}, '" name="search_days',
704 $work{'paramnum'}, '" size="3" '
705 #. (
706 #defined( $param->{ 'search_days' . $work{'valuenum'} } )
707 #? value($param->{ 'search_days' . $work{'valuenum'} })
708 #: ''
709 #),
710 , value( $param->{ 'search_days' . $work{'valuenum'} } ), '/> '
711 if !$config{'no_search_days'} and $config{'sql'}{'table'}{$table}{'time'};
712 if ( $param->{'expert'} or defined( $param->{ 'gluel' . $work{'valuenum'} } ) ) {
713 print ' <select id="gluel', $work{'paramnum'}, '" name="gluel', $work{'paramnum'}, '" dir="ltr" >',
714 '<option value="">', lang('and'), '</option>', '<option value="or" ',
715 ( $param->{ 'gluel' . $work{'valuenum'} } eq 'or' ? 'selected="selected"' : '' ), '>', lang('or'), '</option>',
716 (
717 $config{'enable_xor_query'}
718 ? (
719 '<option value="xor" ',
720 ( $param->{ 'glueg' . $work{'valuenum'} } eq 'xor' ? 'selected="selected"' : '' ),
721 '>', lang('xor'), '</option>',
722 )
723 : ()
724 ),
725 '</select> ';
726 } else {
727 print '<input type="hidden" id="gluel', $work{'paramnum'}, '" name="gluel', $work{'paramnum'}, '"/>';
728 }
729 print $config{'sel_sep'}, '<select ', nameid( 'order' . $work{'paramnum'} ), ' dir="ltr"><option value="">',
730 lang('sort'), '</option>';
731 print '<option value="', $_, '" ', ( $param->{ 'order' . $work{'valuenum'} } eq $_ ? 'selected="selected"' : '' ), '>',
732 lang($_), '</option>'
733 for sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} } grep {
734 ( $config{'sql'}{'table'}{$table}{$_}{'sort'} or !$config{'sql'}{'table'}{$table}{$_}{'no_order'} )
735 and !$config{'sql'}{'table'}{$table}{$_}{'hide'}
736 } keys %{ $config{'sql'}{'table'}{$table} };
737 psmisc::printu '</select> ', lang('reverse'), ' <input type="checkbox" ', nameid( 'order_mode' . $work{'paramnum'} ),
738 ' ', ( ( $param->{ 'order_mode' . $work{'valuenum'} } ) ? 'checked="checked"' : '' ), '/>';
739 print qq{</div><div class="checks">};
740 unless ( defined( $work{'paramnum'} ) ) {
741 print $config{'sel_sep'}, '&sum;', lang('files'), '<input type="checkbox" id="count_f" name="count_f" ',
742 ( ( $param->{'count_f'} eq 'on' ) ? 'checked="checked"' : '' ), ' /> ', $config{'sel_sep'}
743 unless $config{'no_count_f'};
744 psmisc::printu ' &sum;', lang($_), ' <input type="checkbox" id="count_', $_, '" name="count_', $_, '" ',
745 ( ( $param->{ 'count_' . $_ } eq 'on' ) ? 'checked="checked"' : '' ), ' />', $config{'sel_sep'}
746 for grep { !$config{ 'no_count_' . $_ } and $config{'sql'}{'table'}{$table}{$_}{'allow_count'} }
747 sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} }
748 keys %{ $config{'sql'}{'table'}{$table} };
749 psmisc::printu lang('page'), ': <input type="text" id="page" name="page" size="2" ', value( $param->{'page'} ),
750 '/> ';
751 #(или "rnd")
752 #print ' Показать данную страницу, если rnd - то случайную' if $param->{'help'};
753 print $config{'sel_sep'}, '<select id="distinct" name="distinct" dir="ltr" ><option value="">', lang('distinct'),
754 '</option>',
755 map( {
756 '<option value="'
757 . $_ . '" '
758 . ( $param->{'distinct'} eq $_ ? 'selected="selected"' : '' ) . '>'
759 . lang($_)
760 . '</option>'
761 } sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} }
762 grep { $config{'sql'}{'table'}{$table}{$_}{'sort'} or $config{'sql'}{'table'}{$table}{$_}{'index'} }
763 keys %{ $config{'sql'}{'table'}{$table} } ),
764 '</select>'
765 unless $config{'no_distinct'};
766 part( 'form-reset', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
767 part( 'form-clear', $param, $table, undef, undef, $work{'paramnum'}, $work{'valuenum'} );
768 }
769 print $config{'sel_sep'},
770 mylink( lang('thislink'), { get_param_hash($param), 'form' => 1 },
771 undef, { 'destroy' => $config{'destroy_link_view'} } )
772 if !$config{'no_thislink'} and $fparam->{'hide_link'};
773 print '</div >' if defined( $work{'paramnum'} );
774 unless ( $config{'no_js'} ) {
775  
776 =no js placeholder
777 print $config{'jscript_open'},
778 #'if(document.getElementById) {',
779 (
780 map {
781 #'var ph' . $_ . $work{'paramnum'} . ' = new InputPlaceholder (document.getElementById (\'' . $_ . $work{'paramnum'},
782 'var ph' . $_ . $work{'paramnum'} . ' = new InputPlaceholder (gid(\'' . $_ . $work{'paramnum'},
783 '\'), \'' . lang($_) . '\', \'\', \'input-help\');',
784 #"\n",
785 #'gid(\'' . $_ . $work{'paramnum'}, '\').addEventListener(\'change\', function (e) {alert(se);gid(\'page\').value = 1;}, false);'
786 } grep {
787 $config{'sql'}{'table'}{$table}{$_}{'nav_field'}
788 } keys %{ $config{'sql'}{'table'}{$table} }
789 ),
790 #"}",
791 $config{'jscript_close'} if !$config{'no_placeholder'} and $config{'input_help'} > $work{'paramnum'};
792 =cut
793  
794 if ( $work{'specify'} eq 'off' ) {
795 print $config{'jscript_open'}, "allow_show_adv_auto = 0;", $config{'jscript_close'};
796 } else {
797 print $config{'jscript_open'}, "show_adv(", ( $work{'specify'} eq 'auto' ), ");", $config{'jscript_close'}
798 if (
799 !defined( $work{'paramnum'} )
800 and (
801 $work{'specify'} eq 'on'
802 or ( (
803 @_ = (
804 grep( $param->{$_},
805 grep( $config{'sql'}{'table'}{$table}{$_}{'nav_field'}, keys %{ $config{'sql'}{'table'}{$table} } ),
806 @{ $config{'param_advanced'} } ),
807 grep defined( $param->{$_} ),
808 @{ $config{'param_advanced_num'} }
809 )
810 )
811 and !(
812 $config{'no_index'}
813 or $config{'ignore_index'}
814 or $config{'table_param'}{$table}{'no_index'}
815 or $config{'table_param'}{$table}{'ignore_index'}
816 )
817 )
818 )
819 );
820 }
821 }
822 print "</div>";
823 ++$work{'one'}{$_} for grep {
824 $work{'paramnum'} ne 0
825 and !( $param->{'q'} and $static{'db'}->{'disable_slow'} )
826 and $param->{ $_ . $work{'valuenum'} }
827 and $param->{ $_ . $work{'valuenum'} } !~ /((^|\s)!)|[*]/
828 } keys %{ $config{'sql'}{'table'}{$table} };
829 $work{'paramnum'} += ( defined( $work{'paramnum'} ) ? 1 : 0 );
830 $work{'valuenum'} = $work{'paramnum'} - ( $param->{'search_prev'} ? 1 : 0 );
831 --$work{'valuenum'} if $work{'paramnum'} eq 0 and !$param->{'search_prev'};
832 $work{'valuenum'} = undef if $work{'valuenum'} < 0;
833 part( 'one-query', $param, $table, undef, { 'no_cont' => 1 } ) unless $config{'no_second_query'};
834 };
835 $config{'out'}{'html'}{'head'} ||= sub {
836 my ( $param, $table ) = @_;
837 print #'<?xml version="1.0"?>',
838 #'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
839 #'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
840 #'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">',
841 '<!DOCTYPE html><html><head>';
842 #'<html xmlns="http://www.w3.org/1999/xhtml" lang="' . lang('language-code') . '" xml:lang="' . lang('language-code') . '">';
843 #print '<head>';
844 #print map { '<META HTTP-EQUIV="Set-Cookie" CONTENT="' . $_ . '=' . encode_url($param->{$_}) . '; EXPIRES=Friday,31-Dec-15 23:59:59 GMT;"/>' } grep $param->{$_}, @{ $config{'user_param_save'} } ;# if $param->{'param_save'} # DOMAIN=domain_name; PATH=path; SECURE
845 part( 'head-head', $param, $table, undef, { 'no_cont' => 1 } ); #
846 print '<meta http-equiv="Content-Type" content="text/html; charset=', lang( $work{'codepage'} ), '"/>',
847 '<meta http-equiv="Content-Language" content="', lang('language-code'), '"/>', '<meta name="language" content="',
848 lang('language-code'), '"/>';
849 print '<meta http-equiv="refresh" content="', $config{'redirect_sleep'}, '; URL=', encode_url_link( $param->{'go'} ),
850 '">'
851 if $param->{'go'};
852 print "<title>";
853 psmisc::printall( $config{'title'} );
854 print( ( $param->{'q'} ? destroy_html(" : $param->{'q'}") : '' ), '</title>' );
855 psmisc::printall( \$config{'html_head'}, $param );
856  
857 =old
858 print '<link rel="stylesheet" media="screen" title="', $config{'style'}, '" href="', $config{'css_url'}, $config{'css_list'}{$config{'style'}}, '" type="text/css"/>';
859 print '<link rel="stylesheet" media="screen" title="', $config{'style'}, '" href="', $config{'css_url'}, $config{'css_list_add'}{$config{'style'}}, '" type="text/css"/>' if $config{'css_list_add'}{$config{'style'}};
860 print '<link rel="alternate stylesheet" media="screen" title="', $_, '" href="', $config{'css_url'}, $config{'css_list'}{$_}, '" type="text/css"/>' ,
861 ($config{'css_list_add'}{$_} ? ('<link rel="alternate stylesheet" media="screen" title="', $_, '" href="', $config{'css_url'}, $config{'css_list_add'}{$_}, '" type="text/css"/>') : ())
862 for grep {$_ ne $config{'style'}} keys %{ $config{'css_list'} };
863 =cut
864  
865 cache_file_css( {
866 'pre_url' => '<link rel="stylesheet" media="screen" type="text/css" title="' . $work{'style'} . '" href="',
867 'pre_cached' => '<style rel="stylesheet" media="screen" type="text/css" title="' . $work{'style'} . "\" >",
868 },
869 $config{'css'},
870 $config{'css_add'}
871 );
872  
873 =temp disabled
874 cache_file_css({'pre_url'=> '<link rel="alternate stylesheet" media="screen" title="' . $_ . '" type="text/css" href="',
875 'pre_cached'=> '<style rel="alternate stylesheet" media="screen" type="text/css" title="' . $_ . "\" >", #<!--\n
876 #}, $config{'css_list'}{$_}, $config{'css_list_add'}{$_}
877 #) for grep {$_ ne $config{'style'}} keys %{ $config{'css_list'} };
878 }, $config{$_}{'css'}, $config{$_}{'css_add'}
879 ) for grep {$_ ne $work{'style'}} @{ $config{'styles'} };
880 =cut
881  
882 print '<link rel="alternate" type="application/rss+xml" title="RSS version" href="',
883 get_param_url_str( $param, ['view'] ), '&amp;view=rss2"/>'
884 if !$config{'destroy_link_view'}
885 and $param->{'order'}
886 and $config{'out'}{'rss2'}{'result_string'};
887 #<link rel="first" title="Первая страница" href="/">
888 #<link rel="prev" title="Предыдущая страница" href="/">
889 unless ( $config{'no_js'} ) {
890 print $config{'jscript_open'};
891 sub js_quote { return $_[0] =~ /^\d+$/ ? $_[0] : "'$_[0]'" }
892 print map { "var $_=" . js_quote( $config{$_} or 0 ) . ";" } grep { $_ } @{ $config{'js_config'} || [] };
893 print map { "var $_=" . js_quote( $work{$_} or 0 ) . ";" } grep { $_ } @{ $config{'js_work'} || [] };
894 print map { "var lang_$_='" . lang($_) . "';" } grep { $_ } @{ $config{'js_lang'} } unless $config{'no_img'};
895 print $config{'jscript_close'};
896 cache_file_js( undef, @{ $config{'js_list'} || [] } );
897 }
898 print '</head><body ' . $config{'html_body_params'} . '>';
899 $work{'param_str'} = get_param_url_str( $param, $config{'skip_from_link'} );
900 };
901 $config{'out'}{'html'}{'loading'} ||= sub { };
902 $config{'out'}{'html'}{'lang-select'} ||= sub {
903 my ($param) = @_;
904 if ( scalar keys %{ $config{'lng'} || {} } > 1 ) {
905 print lang('lang'), ': ' if !$config{'no_select_describe'};
906 print "<ul>";
907 for my $lang ( sort grep { $_ } keys %{ $config{'lng'} } ) {
908 print "<li>",
909 mylink(
910 lang($lang),
911 { get_param_hash($param), 'lang' => $lang },
912 {
913 'title' => lang('lang') . ' ' . lang($lang),
914 'class' => 'lang' . ( $lang eq $work{'lang'} ? ' selected' : '' ),
915 'onclick' => qq{createCookie('lang', '$lang');window.location.reload(false);},
916 ( $lang eq $work{'lang'} ) ? ( 'href' => undef ) : ()
917 },
918 { 'destroy' => $config{'destroy_link_lang'} }
919 ),
920 "</li>";
921 #print "N&f;<a class=\"lang\" ";
922 #my $notcurlng;
923 #print 'href="#"' if $notcurlng = $lang ne $work{'lang'};
924 #print ' ' . $config{'js_debug'} . 'onclick="createCookie(\'lang\', \'', $lang,'\');window.location.reload(false);">', lang($lang), '</a>';
925 }
926 print "</ul>";
927 }
928 };
929 $config{'out'}{'html'}{'cp-select'} ||= sub {
930 my ( $param, $table ) = @_;
931 local @_ = ();
932 if (
933 scalar( $config{'lng'}{ $work{'lang'} }{'codepages'} ? @{ $config{'lng'}{ $work{'lang'} }{'codepages'} } : @_ ) > 1 )
934 {
935 print "("; #. $work{'codepage'};
936 print lang('cp'), ': ' if !$config{'no_select_describe'};
937 print join ' ', map {
938 "<a class=\"codepage\" "
939 . ( $_ ne $work{'codepage'} ? "href=\"#\" " : ' ' ) . ' '
940 . $config{'js_debug'}
941 . 'onclick="createCookie(\'codepage\', \''
942 . $_
943 . '\');window.location.reload(false);"'
944 . ">", $_, "</a>"
945 } sort ( $config{'lng'}{ $work{'lang'} }{'codepages'} ? @{ $config{'lng'}{ $work{'lang'} }{'codepages'} } : @_ );
946 print ")";
947 }
948 };
949 $config{'out'}{'html'}{'mode-select'} ||= sub {
950 my ( $param, $table ) = @_;
951 if ( scalar @{ $config{'modes'} || [] } > 1 ) {
952 print lang('mode'), ': ' if !$config{'no_select_describe'};
953 #print ' <a ', ( $_ ne $work{'mode'} ? ' href="#" ' : ' ' ),
954 # ' ' . $config{'js_debug'} . 'onclick="createCookie(\'mode\', \'', $_, '\');',
955 # 'window.location.reload(false);" title="', lang('mode'), ' ', $_, '">', lang($_), '</a>'
956 # for sort @{ $config{'modes'} };
957 print ' ',
958 mylink(
959 lang($_),
960 { get_param_hash($param), 'mode' => $_ },
961 {
962 'title' => lang('mode') . " $_",
963 'onclick' => qq{createCookie('mode', '$_');window.location.reload(false);},
964 ( $_ eq $work{'mode'} ) ? ( 'href' => undef ) : ()
965 },
966 { 'destroy' => $config{'destroy_link_mode'} }
967 ) for sort @{ $config{'modes'} };
968 }
969 };
970 $config{'out'}{'html'}{'style-select'} ||= sub {
971 my ( $param, $table ) = @_;
972 if ( scalar @{ $config{'styles'} || [] } > 1 ) {
973 print lang('style'), ': ' if !$config{'no_select_describe'};
974 print ' <span class="a" ', (
975 $work{'style'} ne $_
976 ? (
977 'href="#" ' . $config{'js_debug'} . 'onclick="createCookie(\'style\', \'',
978 $_,
979 '\');'
980 . (
981 ( $config{'style_change_reload'} or $config{$_}{'style_change_reload'} )
982 ? 'window.location.reload(false);'
983 : ( 'setActiveStyleSheet(\'', $_, '\');' )
984 )
985 . '" '
986 )
987 : ''
988 ),
989 'title="', lang('style'), ' ', $_, '">', lang($_), '</span>'
990 for $work{'style'}, sort grep { !$config{$_}{'hide'} and $_ ne $work{'style'} } @{ $config{'styles'} };
991 }
992 };
993 $config{'out'}{'html'}{'view-select'} ||= sub {
994 my ( $param, $table ) = @_;
995 part( 'lang-select', $param, $table );
996 part( 'cp-select', $param, $table );
997 part( 'style-select', $param, $table );
998 part( 'mode-select', $param, $table );
999 };
1000 $config{'out'}{'html'}{'search-form-input'} ||= sub {
1001 my ( $param, $table ) = @_;
1002 print '<input type="hidden" name="', $_, '" ', value( $param->{$_} ), ' />'
1003 for ( @{ $config{'user_param_hidden'} }, @{ $config{'user_param_save_hidden'} }, qw(distinct live live_mode) );
1004 part( 'one-query', $param, $table, { 'hide_link' => 1 } );
1005 print '</div>'; # opened in one-query, advanced search - hidden
1006 };
1007 $config{'out'}{'html'}{'pre-search-form'} ||= sub {
1008 my ( $param, $table ) = @_;
1009 #print "z";
1010 part( 'form-links', $param, $table );
1011 part( 'form-adjust', $param, $table );
1012 part( 'view-select', $param, $table );
1013 };
1014 $config{'out'}{'html'}{'similar-query'} ||= sub {
1015 my ( $param, $table, $fparam ) = @_;
1016 local $_ = $param->{'q'};
1017 s/\s*\S+:\S+\s*//g;
1018 return unless $_;
1019 #printlog( "WH:", $static{'db'}->where( { %$param, 'query' => $param->{'q'}, 'query_mode' => '!' }, undef, $config{'sql_tquerystat'} ));
1020 local $param->{'page'} = undef;
1021 local $param->{'q'} = scalar cp_trans( $work{'codepage'}, $config{'cp_db'}, $param->{'q'}, );
1022 local $work{'query'} = {};
1023 local $work{'word'} = {};
1024 #printlog('dev', "qstat", Dumper($param));
1025 part(
1026 'query',
1027 { %$param, 'order' => '', },
1028 $config{'sql_tquerystat'}, {
1029 'where' => $static{'db'}->where( {
1030 %$param,
1031 'query' => $param->{'q'},
1032 #'query' => scalar cp_trans( $work{'codepage'}, $config{'cp_db'}, $param->{'q'}, ),
1033 'query_mode' => '!'
1034 },
1035 undef,
1036 $config{'sql_tquerystat'}
1037 ),
1038 'no_desc' => 1,
1039 'desc' => lang('similar requests') . ': '
1040 }
1041 );
1042 };
1043 $config{'out'}{'html'}{'result_error'} ||= sub {
1044 my ( $param, $table, $error ) = @_;
1045 print ucfirst lang('sorry');
1046 if ( $error eq 'timeout' ) { print ', ', lang('the database is busy right now'); }
1047 else { print ', ', lang('database error'); }
1048 print '. <a href="javascript:location.reload()">', lang('reload the page'), '</a>, ',
1049 lang('change your query or try again later'), '.';
1050 };
1051 $config{'out'}{'html'}{'result_head'} ||= sub {
1052 my ( $param, $table, $row ) = @_;
1053 psmisc::printall( \$config{'html_result_header_top'}, $param ) unless $param->{'no_result_header'};
1054 $work{'n'} = $static{'db'}->{'limit_offset'};
1055 print '<table class="result-table" ';
1056 psmisc::printall( \$config{'html_result-table_param'}, $param );
1057 print '>';
1058 return if $param->{'no_result_header'};
1059 if ( $config{'one_string'} and keys %{ $work{'one'} } ) {
1060 local $work{'n'} = -1;
1061 my (%string) = (%$param);
1062 delete $string{$_} for grep ( ( $work{'one'}{$_} != 1 ), keys %string );
1063 $string{'full'} = join_url( \%string );
1064 local $work{'one'} = ();
1065 local $config{'allow_vote'} = 0;
1066 local $config{'no_dir_word'} = 1;
1067 local $config{'allow_pinger'} = 0;
1068 local $config{'no_rel_path_link'} = 0;
1069 part( 'result_string_pre', $param, $table, \%string, { 'no_cont' => 1 } );
1070 part( 'result_string', $param, $table, \%string, { 'no_cont' => 1 } );
1071 part( 'result_string_post', $param, $table, \%string, { 'no_cont' => 1 } );
1072 }
1073 print '<tr class="result-head"><td>N</td>';
1074 if ( $param->{'distinct'} ) { print '<td>', $param->{'distinct'}, '</td>'; }
1075 else {
1076 #print "HI";
1077 my %ord_param_hash = get_param_hash( $param, ( 'order', 'order_mode', 'page' ) ) unless $config{'destroy_link_sort'};
1078 #for my $rown ( sort keys %{ $config{'sql'}{'table'}{$table} } ) {
1079 for my $rown ( sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} }
1080 grep { $config{'sql'}{'table'}{$table}{$_} and !$config{'sql'}{'table'}{$table}{$_}{'hide'} } keys %$row )
1081 {
1082 print '<td>';
1083 #print "zz";
1084 psweb::sorter( $param, { 'order' => $rown }, \%ord_param_hash );
1085 print '</td>';
1086 }
1087 print '</tr>';
1088 }
1089 };
1090 $config{'out'}{'html'}{'result_string'} ||= sub {
1091 my ( $param, $table, $row ) = @_;
1092 $row->{'n'} = ++$work{'n'};
1093 print "<tr><td>$row->{'n'}</td>";
1094 for my $rown ( sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} }
1095 grep { $config{'sql'}{'table'}{$table}{$_} and !$config{'sql'}{'table'}{$table}{$_}{'hide'} } keys %$row )
1096 {
1097 print '<td>';
1098 $config{'sql'}{'table'}{$table}{$rown}{'show'}
1099 ? psmisc::printall( $config{'sql'}{'table'}{$table}{$rown}{'show'}, $row->{$rown} )
1100 : print mylink(
1101 $row->{$rown}, {
1102 $rown => $row->{$rown},
1103 #'size_mode' => 'e'
1104 }, {
1105 #'title' => "$row->{'size'} bytes",
1106 ( $row->{$rown} == $param->{$rown} ? ( 'class' => 'hilight1' ) : () ),
1107 #( $row->{'files'} ? ( 'href' => undef ) : () )
1108 },
1109 #{ 'destroy' => $config{'destroy_link_size'}, }
1110 ) if $row->{$rown};
1111 print '</td>';
1112 }
1113 #print "<td>[$row->{'stem'}]</td>";
1114 print "</tr>";
1115 #local $row->{'size'} = undef if $row->{'size'} ==1;
1116 #print "<tr><td colspan='20'>";
1117 $work{'head'}{$_} += ( $row->{$_} =~ /^\s*\d+\s*$/ ? $row->{$_} : ( $row->{$_} =~ /\S/ ? 1 : 0 ) ),
1118 #print("$_ = $work{'head'}{$_};")
1119 for
1120 grep { ( $config{'sql'}{'table'}{$table}{$_}{'row'} or !$config{'sql'}{'table'}{$table}{$_}{'hide'} ) and $row->{$_} }
1121 keys %{ $config{'sql'}{'table'}{$table} };
1122 #print "</td></tr>";
1123 };
1124 $config{'out'}{'html'}{'result_foot'} ||= sub {
1125 my ( $param, $table ) = @_;
1126 print '</table>';
1127 part( 'result_foot_hide', $param, $table );
1128 };
1129 $config{'out'}{'html'}{'result_foot_hide'} ||= sub {
1130 my ( $param, $table ) = @_;
1131 print $config{'jscript_open'};
1132 print 'toggleview(\'head_', $_, '\');' for grep {
1133 ( $config{'sql'}{'table'}{$table}{$_}{'row'} or !$config{'sql'}{'table'}{$table}{$_}{'hide'} )
1134 and ( !$work{'head'}{$_} or $work{'n'} < 1 )
1135 } keys %{ $config{'sql'}{'table'}{$table} };
1136 print $config{'jscript_close'};
1137 };
1138 $config{'out'}{'html'}{'result-report'} ||= sub {
1139 my ( $param, $table ) = @_;
1140 print lang('found'), ' '
1141 if $stat{'found_time'} > 0
1142 or $static{'db'}->{'founded'} > 0
1143 or $static{'db'}->{'stat'}{'found'}{'size'} > 0
1144 or !$stat{'results'};
1145 print " $static{'db'}->{'founded'} ", lang('files'), ' ' if $static{'db'}->{'founded'} > 0 or !$stat{'results'};
1146 psmisc::printu " $stat{'found'}{'size'} ", lang('bytes'),
1147 ( $static{'db'}->{'stat'}{'found'}{'size'} > 1000
1148 ? ' (' . psmisc::human( 'size', $static{'db'}->{'stat'}{'found'}{'size'} ) . ')'
1149 : ' ' )
1150 if $static{'db'}->{'stat'}{'found'}{'size'} > 0;
1151 psmisc::printu ' ', lang('in'), ' ', psmisc::human( 'time_period', $stat{'found_time'} ), ' '
1152 if $stat{'found_time'} > 0;
1153 print ', ', lang('showed'), ' ',
1154 ( $static{'db'}->{'dbirows'} ? $static{'db'}->{'limit_offset'} + 1 : $static{'db'}->{'limit_offset'} ) . '-'
1155 . ( $static{'db'}->{'founded'} > $static{'db'}->{'limit_offset'} + $static{'db'}->{'limit'}
1156 ? $static{'db'}->{'limit_offset'} + $static{'db'}->{'limit'}
1157 : ( $static{'db'}->{'founded'} or $static{'db'}->{'limit_offset'} + $static{'db'}->{'dbirows'} ) )
1158 . ( $static{'db'}->{'page'}
1159 ? ' (' . lang('page') . " $static{'db'}->{'page'} " . lang('from') . " $static{'db'}->{'page_last'})"
1160 : '' )
1161 if $static{'db'}->{'page_last'} > 1;
1162 print '<br/>';
1163 #printlog('d', Dumper($param));
1164 part(
1165 'gotopage',
1166 $param, $table, {
1167 'current' => $static{'db'}->{'page'},
1168 'total' => $static{'db'}->{'founded'},
1169 'actual' => $static{'db'}->{'dbirows'},
1170 'size' => $static{'db'}->{'limit'},
1171 'last' => $static{'db'}->{'page_last'},
1172 'total_max' => $static{'db'}->{'founded_max'},
1173 }
1174 );
1175 part( 'viewas', $param, $table ) if $static{'db'}->{'founded'};
1176 if ( ( $static{'db'}->{'dbirows'} > 0 or $static{'db'}->{'founded'} > 0 ) and $static{'db'}->{'limit'} > 0 ) {
1177 print $config{'jscript_open'}, q{toggleview('form-in-founded');}, $config{'jscript_close'} if $param->{'page'} <= 1;
1178 } else {
1179 psmisc::printall( \$config{'no_results_insert'}, $param );
1180 }
1181 };
1182 $config{'out'}{'html'}{'gotopage'} ||= sub {
1183 my ( $param, $table, $fparam ) = @_;
1184 #printlog('dev' , "gtp", Dumper($fparam));
1185 my $gotopage = gotopage($fparam); #$param,
1186 #printlog('dev' , "gtp", gotopage($fparam), Dumper($fparam));
1187 return unless keys %$gotopage;
1188 #print "GOOO";
1189 print lang('goto page') . ' ';
1190 my %param_hash = get_param_hash( $param, 'page' );
1191 #printlog('d', Dumper($param,\%param_hash));
1192 print ' ',
1193 mylink(
1194 lang('ctrl-prev') . ' ' . lang('prev'),
1195 { %param_hash, ( $_ == 1 ? () : 'page' => $_ ) },
1196 { 'id' => 'prev_page', 'title' => $gotopage->{'prev'}->{$_} },
1197 { 'destroy' => $config{'destroy_link_page'} }
1198 ),
1199 ' '
1200 for sort { $a <=> $b } keys %{ $gotopage->{'prev'} };
1201 print ' ', mylink(
1202 $_,
1203 { %param_hash, ( $_ == 1 ? () : 'page' => $_ ) },
1204 { 'title' => $gotopage->{'big'}->{$_}, ( $fparam->{'current'} == $_ ? ( 'href' => undef ) : () ) },
1205 {
1206 'destroy' => $config{'destroy_link_page'},
1207 #( $fparam->{'current'} == $_ ? ( 'href' => 'NO' ) : () )
1208 }
1209 ),
1210 ' ' for sort {
1211 $a <=> $b
1212 } keys %{ $gotopage->{'big'} };
1213 print ' ',
1214 mylink(
1215 $_,
1216 { %param_hash, 'page' => $_ },
1217 { 'class' => 'unknownlink', 'title' => $gotopage->{'small'}->{$_} },
1218 { 'destroy' => $config{'destroy_link_page'}, }
1219 ),
1220 ' '
1221 for sort { $a <=> $b } keys %{ $gotopage->{'small'} };
1222 print ' ',
1223 mylink(
1224 lang('next') . ' ' . lang('ctrl-next'),
1225 { %param_hash, 'page' => $_ },
1226 { 'id' => 'next_page', 'title' => $gotopage->{'next'}->{$_} },
1227 { 'destroy' => $config{'destroy_link_page'}, }
1228 ),
1229 ' '
1230 for sort { $a <=> $b } keys %{ $gotopage->{'next'} };
1231 };
1232 $config{'out'}{'html'}{'viewas'} ||= sub {
1233 my ( $param, $table ) = @_;
1234 print '[';
1235 #printlog('vi', $config{'view'}, $param->{'view'});
1236 print ' ', mylink(
1237 lang($_), { get_param_hash( $param, 'view' ), 'view' => $_ }, undef,
1238 #{ 'destroy' => $config{'destroy_link_view'}, ( ( $_ ne 'html' and $config{'view'} ne $_ ) ? () : ( 'href' => 'NO' ) ) } ),
1239 { 'destroy' => $config{'destroy_link_view'} || ( ( $_ ne 'html' and $config{'view'} ne $_ ) ? ('') : ('YES') ) }
1240 ),
1241 ' '
1242 for ( sort grep { $_ and !$config{'out'}{$_}{'hide'} } keys %{ $config{'out'} } );
1243 print ']';
1244 };
1245 $config{'out'}{'html'}{'stat'} ||= sub {
1246 my ($param) = @_;
1247 part( 'main-topquery', $param, undef, { 'no_split' => 1, 'no_result_header' => 1, 'no_gotopage' => 1 } )
1248 if $config{'allow_query_stat'};
1249 part( 'main-stat', $param );
1250 part( 'main-top-stat', $param, undef, { 'no_gotopage' => 1 } );
1251 };
1252 $config{'out'}{'html'}{'main'} ||= sub {
1253 my ( $param, $table, ) = @_;
1254 part( 'stat', $param );
1255 part( 'examples', $param, $table );
1256 };
1257 $config{'out'}{'html'}{'main-top-stat'} ||= sub {
1258 my ( $param, $table, $fparam ) = @_;
1259 part( 'top', $param, undef, $fparam );
1260 };
1261 #$config{'out'}{'html'}{'footer-stat'} ||= sub {
1262 $config{'html_footer_stat_bef'} //= '<!-- ';
1263 $config{'html_footer_stat_aft'} //= ' -->';
1264 $config{'out'}{'html'}{'footer_stat'} ||= sub {
1265 my ($param) = @_;
1266 print $config{'foot_stat_sep'};
1267 print '[', psmisc::human( 'date_time', ), ']', $config{'foot_stat_sep'};
1268 print 'this page generated in ', ( psmisc::human( 'time_period', $work{'page_start'}->() ) or '0s' ),
1269 $config{'foot_stat_sep'}
1270 if $work{'page_start'};
1271 print 'with ', ( $static{'db'}->queries() || 0 ), ' queries (',
1272 psmisc::human( 'time_period', $static{'db'}->{'queries_time'} ), ')',, $config{'foot_stat_sep'}, ' perl ',
1273 psmisc::human( 'time_period', $work{'page_start'}->() - $static{'db'}->{'queries_time'} ), $config{'foot_stat_sep'}
1274 if $static{'db'}
1275 and $static{'db'}->queries()
1276 and $work{'page_start'};
1277 print 'MP:', $$, ' SP:', $static{'runs'}, ' UP:',
1278 ( psmisc::human( 'time_period', $static{'script_start'}->() ) or '0s' ), $config{'foot_stat_sep'}
1279 if $ENV{'MOD_PERL'} || $ENV{'FCGI_ROLE'};
1280 print $work{'counter'}{'total'}, ' hits [', $work{'counter'}{'pday'}, ':', $work{'counter'}{'day'}, ']',
1281 $config{'foot_stat_sep'}
1282 if $work{'counter'}{'total'};
1283 };
1284 $config{'out'}{'html'}{'footer'} ||= sub {
1285 my ($param) = @_;
1286 part( 'footer_stat', $param, undef, undef, { 'no_cont' => 1 } );
1287 psmisc::printu '    ';
1288 };
1289 $config{'out'}{'html'}{'item_info'} ||= sub {
1290 my ($row) = @_;
1291 local @_ = (
1292 !$config{'no_query_count'} && $$row{'top'} ? $$row{'top'} : (),
1293 !$config{'no_query_dl'} && $$row{'dl'} ? $$row{'dl'} : (),
1294 !$config{'no_query_time'} && $$row{'last'} ? psmisc::human( 'time_period', time() - $$row{'last'} ) : (),
1295 !$config{'no_query_ip'} && $$row{'lastip'} ? $$row{'lastip'} : ()
1296 );
1297 print '[', join( ',', @_ ), '] ' if @_;
1298 };
1299 for my $stat (qw(word query)) {
1300 #$config{'out'}{'html'}{'string'}{$stat} ||= sub {
1301 $config{'out'}{'html'}{ 'string_' . $stat } ||= sub {
1302 #my ( $row, $param ) = @_;
1303 my ( $param, undef, $row, ) = @_;
1304 #cp_trans_row($row);
1305 #printlog( "zzz",Dumper($row));
1306 print mylink(
1307 psmisc::human( 'string_long', $$row{$stat}, 30 ),
1308 { 'q' => $$row{$stat} },
1309 undef, { 'destroy' => $config{'destroy_link_top'} }
1310 ),
1311 ' ';
1312 part( 'item_info', $row, undef, undef, { 'no_cont' => 1 } );
1313 #print ' (', ( $param->{'order'} eq 'top' ? ( $$row{'top'} ) : () ),
1314 #( $param->{'order'} eq 'last' ? ( psmisc::human( 'time_period', time() - $$row{'last'} ) ) : () ), ')'
1315 #if $param->{'order'};
1316 #print ' ';
1317 };
1318 }
1319 #$config{'out'}{'html'}{'string'}{'file'} ||= sub {
1320 $config{'out'}{'html'}{'string_file'} ||= sub {
1321 #my ( $row, $param ) = @_;
1322 my ( $param, undef, $row, ) = @_;
1323 my %url = split_url( $$row{'file'} );
1324 #print "========",join':',%$row;
1325 #print "====", $work{'codepage'}, $$row{'cp'}||hconfig( 'cp_res', $url{'host'}, $url{'prot'} );
1326  
1327 =direct links
1328 print $config{'redirector'}->( {
1329 #'go' => scalar psmisc::cp_trans($work{'codepage'}, $$row{'cp'} || hconfig( 'cp_res', $url{'host'}, $url{'prot'} ), $$row{'file'}),
1330 'go' => scalar psmisc::encode_safe( $$row{'cp'} || hconfig( 'cp_res', $url{'host'}, $url{'prot'} ), $$row{'file'} ),
1331 'actname' => part( 'result_string_img', undef, undef, { 'ext' => $url{'ext'}, size => 1 }, { 'no_cont' => 1 } )
1332 . join_url( {
1333 'name' => psmisc::human( 'string_long', $url{'name'}, 25 ),
1334 'ext' => psmisc::human( 'string_long', $url{'ext'}, 5 )
1335 }
1336 )
1337 }
1338 );
1339 =cut
1340  
1341 print mylink(
1342 part( 'result_string_img', undef, undef, { 'ext' => $url{'ext'}, size => 1 }, { 'no_cont' => 1 } )
1343 . join_url( {
1344 'name' => psmisc::human( 'string_long', $url{'name'}, 25 ),
1345 'ext' => psmisc::human( 'string_long', $url{'ext'}, 5 )
1346 }
1347 ), #{%url, 'prot'=>undef, 'host'=>undef, 'user'=>undef, 'pass'=>undef, 'path'=>undef}
1348 #{'q'=> $$row{'file'} ,}
1349 { 'name' => $url{'name'}, 'ext' => $url{'ext'}, },
1350 undef,
1351 { 'destroy' => $config{'destroy_link_file'} },
1352 );
1353 part( 'item_info', $row, undef, undef, { 'no_cont' => 1 } );
1354 #item_info($row);
1355 #print '', ( ( $config{'show_query_ip'} and $$row{'lastip'} ) ? '[' . $$row{'lastip'} . ']' : '' );
1356 #print ' (', ( $param->{'order'} eq 'dl' ? ( $$row{'dl'} ) : () ),
1357 #( $param->{'order'} eq 'last' ? ( psmisc::human( 'time_period', time() - $$row{'last'} ) ) : () ), ')'
1358 #if $param->{'order'};
1359 #print ' ';
1360 };
1361 for my $stat (qw(file word query)) {
1362 $config{'out'}{'html'}{$stat} ||= sub {
1363 my ( $param, $table, $fparam ) = @_;
1364 $table = $config{ 'sql_t' . $stat . 'stat' };
1365 #printlog( 'dev', "fwq: $stat, $table;" , Dumper($param));
1366 #$param->{'on_page'} =
1367 $static{'db'}->user_params($param);
1368 local $static{'db'}->{'limit'} = check_int( $param->{'results'}, 1, $config{'top_query_max'}, $config{'top_query'} );
1369 $param->{'order'} = 'top' unless defined $param->{'order'};
1370 $param->{'order_mode'} = '!' unless defined $param->{'order_mode'};
1371 local $static{'db'}->{'disable_slow'} = 0; #!
1372 #? local $config{'sql'}{'database'} = ref $config{'sql_base_up'} eq 'HASH' ? $config{'sql_base_up'}{'database'} : $config{'sql_base_up'};
1373 local $config{'allow_null_count'} = 1;
1374 $static{'db'}->count( $param, $table ),
1375 $stat{'top_founded_max'} = max( $stat{'top_founded_max'}, $stat{'found'}{'files'} ),
1376 $stat{'top_pages_max'} = max( $stat{'top_pages_max'}, $static{'db'}->{'page_last'} )
1377 unless $fparam->{'no_gotopage'};
1378 #printlog( 'dev', 'fwq0' );
1379 my $top = $static{'db'}->query( $static{'db'}->select_body( $fparam->{'where'}, $param, $table ) )
1380 #my $top = $static{'db'}->select( $static{'db'}->select_body( $fparam->{'where'}, $param, $table ) )
1381 if $static{'db'}->{'limit'};
1382 #$param->{'on_page'};
1383 #printlog( 'dev', 'fwq1', $top );
1384 if ( $static{'db'}->{'limit'} and $top and scalar @$top >= 1 and keys %{ $top->[0] } ) {
1385 print $fparam->{'desc'};
1386 print lang( $stat . ' ' . $param->{'order'} ) unless $fparam->{'no_desc'};
1387 print ' (', mylink( '100', { 'show' => 'topquery', 'results' => '100' } ), ')' if $fparam->{'link_100'};
1388 print ':', ( $fparam->{'no_split'} ? ' ' : '<br/>' ) unless $fparam->{'no_desc'};
1389 #$config{'out'}{'html'}{'string'}{$stat}->( $_, $param ) for (@$top);
1390 #$config{'out'}{'html'}{'string_'.$stat}->( $param,$_, ) for (@$top);
1391 part( 'string_' . $stat, $param, undef, $_, { 'no_cont' => 1 } ) for (@$top);
1392 }
1393 };
1394 }
1395 for my $stat (qw(queries dls)) {
1396 $config{'out'}{'html'}{$stat} ||= sub {
1397 my ( $param, $table, $fparam ) = @_;
1398 return unless @{ $work{$stat} };
1399 print lang( 'my ' . $stat ), ': ';
1400 my $output = $stat eq 'dls' ? 'file' : 'query';
1401 #$config{'out'}{'html'}{'string_'.$output}->( { %$param, 'order' => undef }, { $output => $_ }, )
1402 part( 'string_' . $output, { %$param, 'order' => undef }, undef, { $output => $_ }, { 'no_cont' => 1 } )
1403 for ( @{ $work{$stat} } );
1404 print ' [<a href="#" ' . $config{'js_debug'} . 'onclick="createCookie(\'', $stat, '\', \'\');hide_id(\'', $stat,
1405 '\');', $stat, '_cleared = 1; return false;">', lang('clear'), '</a>] ';
1406 };
1407 }
1408 $config{'out'}{'html'}{'main-topquery'} ||= sub {
1409 my ( $param, $table, $fparam ) = @_;
1410 print( ucfirst( lang('queries') ), ' 10 (', mylink( '100', { 'show' => 'topquery', 'results' => '100' } ), ') :' );
1411 part( 'topquery', $param, undef, $fparam ) if $config{'allow_query_stat'};
1412 };
1413 $config{'out'}{'html'}{'topquery'} ||= sub {
1414 my ( $paramorig, $table, $fparam ) = @_;
1415 my $param = {%$paramorig};
1416 #printlog('dev', 'topq', $paramorig, $table, $fparam);
1417 $fparam->{'no_gotopage'} = 1 unless $config{'topquery_gotopages'};
1418 psmisc::printall( \$config{'html_result_header_top'}, $param, $fparam ) if !$fparam->{'no_result_header'};
1419 my $delim = ( $fparam->{'no_split'} ? '' : '<br/>' );
1420 #print $delim;
1421 #part( 'word', $param, $table, $fparam );
1422 print $delim;
1423 part( 'query', $param, $table, $fparam );
1424 if ( $config{'allow_topfiles'} ) {
1425 print $delim;
1426 $param->{'order'} = 'dl';
1427 part( 'file', $param, $table, $fparam );
1428 }
1429 psmisc::printall $config{'html_topquery_split'};
1430 {
1431 $param->{'order'} = 'last';
1432 $param->{'count_f'} = 'on' unless $fparam->{'no_gotopage'};
1433 part( 'query', $param, $table, $fparam );
1434 delete $param->{'order'};
1435 }
1436 if ( $config{'allow_topfiles'} ) {
1437 print $delim;
1438 $param->{'order'} = 'last';
1439 part( 'file', $param, $table, $fparam );
1440 }
1441 for my $q (qw(queries dls)) {
1442 print $delim;
1443 part( $q, $param, $table, $fparam, { 'cont_param' => 'id="' . $q . '"' } );
1444 }
1445 part(
1446 'gotopage',
1447 $paramorig,
1448 undef, {
1449 'current' => $param->{'page'},
1450 'buttonsb' => $config{'topquery_gotopages'},
1451 'buttonsa' => $config{'topquery_gotopages'},
1452 'total' => $stat{'top_founded_max'},
1453 'actual' => $static{'db'}->{'limit'},
1454 'size' => $static{'db'}->{'limit'},
1455 'last' => $stat{'top_pages_max'}
1456 }
1457 ) unless $fparam->{'no_gotopage'};
1458 };
1459 $config{'out'}{'html'}{'presets'} ||= sub {
1460 my ($param) = @_;
1461 for my $sets ( sort keys %{ $config{'preset'} } ) {
1462 print lang($sets), ":<br/>";
1463 for my $preset ( sort { $config{'preset'}{$sets}{$a}{'order'} <=> $config{'preset'}{$sets}{$b}{'order'} }
1464 keys %{ $config{'preset'}{$sets} } )
1465 {
1466 psmisc::printu ' ', mylink( $preset, { 'q' => ':' . $preset } ), ":\t ";
1467 print join ' & ',
1468 map { "$_=$config{'preset'}{$sets}{$preset}{'set'}{$_}" } sort keys %{ $config{'preset'}{$sets}{$preset}{'set'} };
1469 print '<br/>';
1470 }
1471 }
1472 };
1473 $config{'out'}{'html'}{'empty'} ||= sub { };
1474 $config{'out'}{'m3u'}{'http-header'} =
1475 "Content-type: audio/x-mpegurl\n" . "Content-Disposition:attachment; filename=searchlist.m3u\n\n";
1476 $config{'out'}{'m3u'}{'head'} ||= sub {
1477 $work{'m3u_limit_max'} = $static{'db'}->{'limit_max'};
1478 $static{'db'}->{'limit_max'} = $config{'maxplaylist'};
1479 $work{'m3u_web_max_search_time'} = $config{'web_max_search_time'};
1480 $config{'web_max_search_time'} = 600;
1481 print "#EXTM3U\n";
1482 psmisc::flush();
1483 };
1484 $config{'out'}{'m3u'}{'foot'} ||= sub {
1485 $static{'db'}->{'limit_max'} = $work{'m3u_limit_max'};
1486 $config{'web_max_search_time'} = $work{'m3u_web_max_search_time'};
1487 };
1488 $config{'out'}{'text'}{'head'} ||= sub { print "#Result\n"; };
1489 $config{'out'}{'text'}{'size'} ||= sub {
1490 my ( $param, $table, $row ) = @_;
1491 psmisc::printu psmisc::human( 'size', $row->{'size'}, ' ' );
1492 };
1493 $config{'out'}{'text'}{'time'} ||= sub {
1494 my ( $param, $table, $row ) = @_;
1495 psmisc::printu psmisc::human( 'time_period', int(time) - $row->{'time'} );
1496 };
1497 for my $field (qw(desc full tiger)) {
1498 $config{'out'}{'text'}{$field} ||= sub {
1499 my ( $param, $table, $row ) = @_;
1500 print $row->{$field};
1501 };
1502 }
1503 $config{'out'}{'text'}{'result_string'} ||= sub {
1504 my ( $param, $table, $row ) = @_;
1505 $row->{'n'} = ++$work{'n'};
1506 print $row->{'n'};
1507 for my $rown ( sort { $config{'sql'}{'table'}{$table}{$b}{'order'} <=> $config{'sql'}{'table'}{$table}{$a}{'order'} }
1508 grep { $config{'sql'}{'table'}{$table}{$_} and !$config{'sql'}{'table'}{$table}{$_}{'hide'} } keys %$row )
1509 {
1510 print "\t", $row->{$rown};
1511 }
1512 print "\n";
1513 };
1514 $config{'out'}{'rss2'}{'http-header'} = "Content-type: application/rss+xml\n\n";
1515 $config{'out'}{'rss2'}{'head'} ||= sub {
1516 my ( $param, $table ) = @_;
1517 $work{'param_str'} = get_param_url_str( $param, $config{'skip_from_link'} );
1518 $work{'rssn'} = $work{'n'} = $static{'db'}->{'limit_offset'};
1519 print '<?xml version="1.0" encoding="', lang( $work{'codepage'} ), '" ?>';
1520 #print '<?xml-stylesheet type="text/css" href="', $config{'root_url'}, $config{'css'}, '" ?>' if $config{'css'};
1521 print '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">', '<channel>';
1522 print '<title>', $config{'title'}, '</title>' if $config{'title'};
1523 print '<link>', $config{'root_url'}, '</link>' if $config{'root_url'};
1524 print '<description>', $config{'rss2_description'}, '</description>' if $config{'rss2_description'};
1525 print '<language>', lang('language-code'), '</language>';
1526 };
1527 $config{'out'}{'rss2'}{'result_string'} ||= sub {
1528 my ( $param, $table, $row ) = @_;
1529 #printlog('dev', 'rss2RS');
1530 print '<item>';
1531 #"\n<link>", get_param_url_str( $param, ['view'] ), '#n', ( ++$work{'rssn'} ), '</link>';
1532 #'<description>';
1533 #my $buffer;
1534 #$buffer .= '<table>';
1535 #print 'ITEMS:[' ,join',',%$row;
1536 unless ( $row->{'description'} ) {
1537 grab_begin( \$row->{'description'} );
1538 print '<![CDATA[<table>';
1539 {
1540 local $config{'view'} = 'html';
1541 #local $config{'view_from'} = 'rss2';
1542 local $config{'allow_vote'} = 0;
1543 local $config{'no_plus_minus'} = 1;
1544 local $config{'no_play'} = 1;
1545 #print('dev', 'call parsRS', "\n");
1546 part( 'result_string', $param, undef, $row, { 'no_cont' => 1 } );
1547 }
1548 #print('dev', 'buf=[',$buffer,"]\n");
1549 print '</table>]]>';
1550 grab_end();
1551 }
1552 #$buffer .= '</table>';
1553 #html_chars( \$buffer );
1554 #print $buffer;
1555 #print '</description>';
1556 my $unique = $row->{ $config{'rss2_guid'} || 'full' };
1557 #print "UNIQ1[$unique:$config{'rss2_guid'}]";#, join',',%$row;
1558 html_chars( \$unique );
1559 $row->{'guid'} ||= $unique;
1560 #print "UNIQ[$unique]";#, join',',%$row;
1561 $row->{'pubDate'} ||= psmisc::human( 'rfc822_date_time', $row->{'time'} );
1562 $row->{'link'} ||= get_param_url_str( $param, ['view'] ), '#n', ( ++$work{'rssn'} );
1563 print '<', $_, '>', $row->{$_}, '</', $_, ">\n"
1564 for grep { $row->{$_} } qw(title description author category comments guid pubDate link);
1565 #'<pubDate>', , '</pubDate>',
1566 #"<guid></guid>"
1567 print "</item>\n";
1568 };
1569 $config{'out'}{'rss2'}{'footer'} ||= sub { print '</channel></rss>'; };
1570 $config{'out'}{'xml'}{'http-header'} = "Content-type: application/xml\n\n";
1571 $config{'out'}{'xml'}{'head'} ||= sub {
1572 $work{'rssn'} = $work{'n'} = $static{'db'}->{'limit_offset'};
1573 print '<?xml version="1.0" encoding="', lang( $work{'codepage'} ), "\" ?>\n<search>\n";
1574 };
1575 $config{'out'}{'xml'}{'footer'} ||= sub { print '</search>'; };
1576 $config{'out'}{'html'}{'ajax'} ||= sub {
1577 my ( $param, $table ) = @_;
1578 return unless ( $config{'ajax'} and $param->{'JsHttpRequest'} );
1579 eval "
1580 use lib \$$config{'root_path'}.'./';
1581 use JsHttpRequest;
1582 ";
1583 local $config{'log_all'} = 't.log';
1584 local $config{'log_screen'} = '0';
1585 my $jsr = JsHttpRequest->new(
1586 'params' => $param,
1587 'func' => sub {
1588 my $buffer;
1589 my @needupdate = ( 'search', 'show' );
1590 for my $as (@needupdate) {
1591 my $part = $as;
1592 $_[1]->{$as} = ' ', next if $part eq 'show' and !$param->{'show'};
1593 $part = $param->{'show'} if $part eq 'show';
1594 $_[1]->{$as} = ' ', next if $part eq 'search' and ( $param->{'show'} or $param->{'form'} );
1595 $buffer = '';
1596 grab_begin($buffer);
1597 part( $part, $param, $table, undef, { 'no_cont' => 1 } );
1598 grab_end();
1599 $_[1]->{$as} = $buffer;
1600 printlog( 'dbg', 'JSRET', $part, $as, $buffer );
1601 }
1602 }
1603 );
1604 print $jsr->{'header'};
1605 print $jsr->{'jscode'};
1606 printlog( 'dbg', "<br\n><br\n><h1>param:</h1><br\n><br\n>" );
1607 for ( sort keys %$param ) { printlog( 'dbg', "$_ = [$param->{$_}]<br\n>" ); }
1608 exit;
1609 };
1610 $config{'out'}{'json'}{'http-header'} = "Content-type: application/json\n\n";
1611 $config{'out'}{'json'}{'footer'} ||= sub {
1612 my ( $param, ) = @_;
1613 return print +($param->{'callback'} ? $param->{'callback'} . '(':'') ,${ psmisc::json_encode($param->{__result} || {}) }, ($param->{'callback'} ? ');' : '');
1614 };
1615 $config{'out'}{'json'}{'result_string'} ||= sub {
1616 my ( $param, $table, $row ) = @_;
1617 #print 'string',Dumper \@_;
1618 push @{ $param->{__result}{'rows'} ||= [] }, $row;
1619 };
1620 $config{'out'}{''}{'run'} ||= sub {
1621 my ( $param, $table ) = @_;
1622 return if $config{'out'}{ $config{'view'} }{'disabled'};
1623 part( 'ajax', $param, $table, undef, { 'no_cont' => 1 } );
1624 print( $config{'out'}{ $config{'view'} }{'http-header'} || $config{'http-header-default'} )
1625 if !$config{'out'}{ $config{'view'} }{'no-http-header'}
1626 and ( $config{'force-http-header'} or defined( $ENV{'SERVER_PORT'} ) );
1627 #printlog('dev', '1part', 'nofunc', $config{'view'}, $config{'out'}{'html'}{'cattest'}, 'runw:',@_, $config{'view'});
1628 part( 'head', $param, $table, undef, { 'no_cont' => 1 } );
1629 part( 'header', $param, $table ) unless $config{'no_auto_header'};
1630 #printlog('dev', 'show', $param->{'show'});
1631 part( $param->{'show'}, $param, $table );
1632 part( 'show', $param, $table );
1633 alarmed( $config{'web_max_search_time'}, sub { part( 'main_or_search', $param, $table ); } )
1634 if !$param->{'show'} and !$param->{'form'};
1635 part( 'result_error', $param, $table, 'timeout' ) if $@;
1636 part( 'footer', $param, $table ) unless $config{'no_auto_footer'};
1637 alarmed(
1638 $config{'web_max_finish_time'},
1639 sub {
1640 part( 'foot', $param, $table, undef, { 'no_cont' => 1 } );
1641 redirect_update( $param, $table ) if $param->{'go'};
1642 update_query_stat() if $stat{'results'} and !$work{'fulltext_fail'};
1643 #printlog('dev', 'alarmed upstat end ');
1644 }
1645 );
1646 #printlog('dev', 'the end');
1647 };
1648 }
1649 );
1650 }
1651 #BEGIN { config_init(); }
1652 config_init($param);
1653  
1654 sub mylink {
1655 my ( $body, $param, $params, $lparam, ) = @_;
1656 #printlog('dev', 'mylink', $body, %{$param or {}}, %{$params or {}}, %{$lparam or {}}) ;
1657 #printlog(Dumper([$body, $param, $params, $lparam]));
1658 $config{'mylink_bef_bef'}->( \( $body, $param, $params, $lparam, ) ) if ref $config{'mylink_bef_bef'} eq 'CODE';
1659 local %_ = (
1660 'glue' => '&amp;',
1661 'delim' => '?',
1662 'tag' => 'a',
1663 'href' => 'href',
1664 'body' => ( length($body) ? $body : 'link' ),
1665 'base' => $config{'root_url'} || $config{'root_dir'} || './',
1666 'param_add' => $work{'uparam'},
1667 %{ $lparam || {} },
1668 );
1669 $params ||= {};
1670 $config{$_}->( \( $body, $param, $params ), \%_, ) for grep { ref $config{$_} eq 'CODE' } (qw(mylink_bef mylink_rewrite));
1671 local $config{'ajax'} = 0 if ( $_{'base'} ne $config{'root_url'} ) or ( $param->{'view'} and ( $param->{'view'} ne 'html' ) );
1672 my %modes =
1673 #map {s/(\d*)$//;$_ => $param->{$_.'_mode'.$1} }
1674 map { s/_mode(\d*)$//; $_ . $1 => $param->{ $_ . '_mode' . $1 } }
1675 #grep { s/_mode(\d*)$/$1/ and $param->{$_.'_mode'.$1}=~ /^\W+$/}
1676 #grep { /^(.+)_mode(\d*)$/ and $param->{$1.'_mode'.$1}=~ /^\W+$/}
1677 grep { /_mode\d*$/ and $param->{$_} =~ /^\W+$/ } keys %$param;
1678 #printlog('dev', Dumper(\%modes));
1679 local @_ = sort grep { length($_) and length( $param->{$_} ) and !( /^(.+)_mode(\d*)$/ and $modes{ $1 . $2 } ) } keys %$param;
1680 if ( !$config{'ajax'} ) {
1681 if ( !$_{'destroy'} ) {
1682 $params->{'href'} //=
1683 $_{'base'}
1684 . ( ( @_ or $_{'param_add'} ) ? $_{'delim'} : '' )
1685 . join( $_{'glue'}, map { encode_url($_) . $modes{$_} . '=' . encode_url( $param->{$_} ) } @_ )
1686 . $_{'param_add'}
1687 unless exists $params->{'href'};
1688 }
1689 } else {
1690 $params->{'href'} //= '#';
1691 $params->{'onclick'} ||= 'dosubmit({' . join( ',', map { "'$_':'$param->{$_}'" } @_ ) . '});return false;';
1692 }
1693 local $_ = join '', '<', $_{'tag'}, ' ',
1694 #print("[$_ = $params->{$_}] "),
1695 join( ' ', map { $_ . '="' . $params->{$_} . '"' } sort grep { defined $params->{$_} } keys %$params ), '>', $_{'body'},
1696 '</', $_{'tag'}, '>';
1697 $config{'mylink_aft'}->( \$_ ) if ref $config{'mylink_aft'} eq 'CODE';
1698 return $_;
1699 }
1700  
1701 sub out_bold {
1702 my ( $string, $what, @whata ) = @_;
1703 #printlog "OB:",utf8::is_utf8($string)," out_bold($string, $what, @whata);", Dumper $string;
1704 return $string if !( ( length $what or @whata ) and length $string );
1705 my $mask = (
1706 join '|',
1707 map { s/(\W)/\\$1/g; $_ } grep { length $_ } sort { length($b) <=> length($a) } @whata,
1708 ( $what =~ s/^\s*\"(.+)\"\s*$/$1/ ? ($what) : split( /\s+|\W+|_+/, $what ) )
1709 ) or return $string;
1710 #print " obmask=$mask; ";
1711 #!return $string if $string =~ /[\xD0\xD1]/; #dont break utf
1712 $string =~ s{($mask)}{ length $1 ? qq{<span class="hilight1">$1</span>} : ''}gie;
1713 return $string;
1714 }
1715  
1716 sub destroy_html {
1717 my ($string) = @_;
1718 #? &->&amp; "->&quot;
1719 $string =~ s/</&lt;/g;
1720 $string =~ s/>/&gt;/g;
1721 $string =~ s/\\\\n/<br\/>/g;
1722 return $string;
1723 }
1724  
1725 sub destroy_quotes {
1726 my ($string) = @_;
1727 $string =~ s/"/&quot;/g; #" mc colorer bug '
1728 $string =~ s/'/&#39;/g;
1729 return $string;
1730 }
1731  
1732 =c
1733 sub to_quot { #v0c0
1734 local ($_) = @_;
1735 s/\"/&quot;/g;
1736 return $_;
1737 }
1738 =cut
1739  
1740 sub value {
1741 return unless defined $_[0];
1742 return
1743 ' value="'
1744 . ( $_[0] ? destroy_quotes( cp_trans( $config{'cp_int'}, $work{'codepage'}, $_[0] ), $_[1] || '"' ) : '' ) . '" ';
1745 }
1746  
1747 sub get_param_hash {
1748 my ( $param, @skip ) = @_;
1749 push @skip, @{ $config{'param_cookie'} || [] };
1750 my (%ret);
1751 GPSL1: for my $par ( sort keys %$param ) {
1752 next unless ( $par and $param->{$par} ne '' );
1753 for my $sk (@skip) { next GPSL1 if $sk eq $par; }
1754 $ret{$par} = $param->{$par};
1755 }
1756 return %ret;
1757 }
1758  
1759 sub get_param_str { #future? remove
1760 my ( $param, $skip, $glue, $mask ) = @_;
1761 $glue ||= '&amp;';
1762 $skip ||= [];
1763 push @$skip, @{ $config{'param_cookie'} || [] };
1764 my ( $string, $tmp );
1765 GPSL1: for my $par ( sort keys %$param ) {
1766 next unless ( $par and $param->{$par} ne '' );
1767 for my $sk (@$skip) { next GPSL1 if $sk eq $par; }
1768 $tmp = encode_url( $param->{$par}, $mask );
1769 $string .= $par . '=' . $tmp . $glue;
1770 }
1771 $string =~ s/$glue$//g;
1772 #print "[$glue, $string]";
1773 return $string;
1774 }
1775  
1776 sub get_param_url_str {
1777 my $gps = get_param_str(@_);
1778 return $config{'root_url'} . ( $gps ? '?' . $gps : '' );
1779 }
1780 {
1781 #no strict; #strange error with open(STDOUT, [ ActiveState Perl v5.6.1 build 631]
1782 #local *OLDSTDOUT;
1783 #local *STDOUT;
1784 #our (OLDSTDOUT, STDOUT);
1785 sub grab_begin { #(\$) #v1
1786 open( OLDSTDOUT, '>&', STDOUT ); #local *
1787 close(STDOUT); # or return;
1788 open( STDOUT, '>>', $_[0] ); # or return
1789 }
1790  
1791 sub grab_end { #v1
1792 close(STDOUT); # or return;
1793 open( STDOUT, '>&', OLDSTDOUT ); # or return; #local *
1794 }
1795 }
1796 sub nameid { return qq{ name="$_[0]" id="$_[0]" }; }
1797  
1798 sub part {
1799 #printlog('', 'part:',$config{'view'},@_);
1800 my ($part) = shift;
1801 #my ( $param, $table, $part_param, $cont_param, $paramnum, $valuenum ) = @_;
1802 my ( $param, $table, $part_param, $cont_param ) = @_;
1803 my $func =
1804 $config{'out'}{ $config{'view'} }{$part}
1805 || $config{'out'}{''}{$part}
1806 || $config{ $config{'view'} . '_' . $part }
1807 || $config{ '_' . $part };
1808 #printlog('', 'view:',$config{'view'} , 'func',$func, 'param', %$param);
1809 #printlog('dev', 'part', 'nofunc', $config{'view'}, $config{'out'}{'html'}{'cattest'}, 'runw:',@_) if (!$part or $param->{ 'no_' . $part } or $config{ 'no_' . $part } or !$func) and $cont_param ne 'NODIV' ;
1810 $cont_param ||= {};
1811 #print "COPAR[$part]:", %$cont_param if $part eq 'search';
1812 #sub check_opt {
1813 #my ( $part, $param, $cont_param, $opt ) = @_;
1814 my $check_opt = sub {
1815 my ($opt) = @_;
1816 #print "CO","[$part]:$opt=",$param->{$part.'_'.$opt} ,'or', $config{$part.'_'.$opt} ,'or', $config{$config{'view'} . '_' .$part.'_'.$opt} ,'or', $cont_param->{$opt};
1817 return $param->{ $opt . '_' . $part } || $work{ $opt . '_' . $part } || $config{ $opt . '_' . $part } || $cont_param->{$opt}
1818 if $opt eq 'no';
1819 return defined $config{ $part . '_' . $opt } ? $config{ $part . '_' . $opt } : $config{ $opt . '_def' }
1820 if $config{ $opt . '_def' };
1821 return
1822 $param->{ $part . '_' . $opt }
1823 || $work{ $part . '_' . $opt }
1824 || $config{ $part . '_' . $opt }
1825 || $work{ $config{'view'} . '_' . $part . '_' . $opt }
1826 || $config{ $config{'view'} . '_' . $part . '_' . $opt }
1827 || $cont_param->{$opt};
1828 };
1829 return if !$part or !$func or $check_opt->('no');
1830 #my $cont = ($cont_param->{'cont'} or ( $part =~ /^form-/ ? 'span' : 'div' ));
1831 #print "[1]";
1832 my $cont = $check_opt->('tag') || ( $part =~ /^form-/ ? 'span' : 'div' );
1833 #printlog('trace',"<br/>part:$part:"),
1834 #print "[2]";
1835 print "\n<!-- $part BEGIN $cont [$config{'view'}] no_cont=", $check_opt->('no_cont'), " -->\n"
1836 if $param->{'debug'} eq 'on' #' ',Dumper(@_),
1837 #;#
1838 and !$check_opt->('no_cont');
1839 $work{'part_stack'}{$part} = ++$work{'part_stack_current'};
1840 #psmisc::printall( \$config{ $config{'view'} . '_' . $part . '_bef_bef' }, @_ );
1841 #print "P1";
1842 psmisc::printall( $check_opt->('bef_bef'), psmisc::is_code( $check_opt->('bef_bef') ) ? @_ : () );
1843 #print "P2";
1844 #return if $config{ 'no_' . $part } or !$func;
1845 #print "[3]";
1846 return if !$part or !$func or $check_opt->('no');
1847 #print "[4]";
1848 if ( $config{'view'} eq 'html' and !$check_opt->('no_cont') ) {
1849 print '<', $cont, ( $check_opt->('no_class') ? () : ( ' class="', $cont_param->{'class'} || $part, '" ' ) ),
1850 ( $check_opt->('no_nameid') ? () : ( nameid($part) ) ), $cont_param->{'cont_param'}, ' ';
1851 #psmisc::printall( \$config{ $config{'view'} . '_' . $part . '_param' }, @_ );
1852 psmisc::printall( $check_opt->('param'), @_ );
1853 print '>';
1854 }
1855 psmisc::printall( $check_opt->('bef'), @_ );
1856 #psmisc::printall( \$config{ $config{'view'} . '_' . $part . '_bef' }, @_ );
1857 #$func->( $param, $table, $part_param, $paramnum, $valuenum );
1858 #print "[5fu $func]";
1859 #$func->(@_) if ref $func eq 'CODE';
1860 psmisc::printall( $func, @_ );
1861 psmisc::printall( $check_opt->('aft'), psmisc::is_code( $check_opt->('aft') ) ? @_ : () );
1862 #psmisc::printall( \$config{ $config{'view'} . '_' . $part . '_aft' }, @_ );
1863 print "</$cont>" if $config{'view'} eq 'html' and !$check_opt->('no_cont');
1864 psmisc::printall( $check_opt->('aft_aft'), @_ );
1865 #psmisc::printall( \$config{ $config{'view'} . '_' . $part . '_aft_aft' }, @_ );
1866 --$work{'part_stack_current'};
1867 delete $work{'part_stack'}{$part};
1868 print "\n<!-- $part END -->\n" if $param->{'debug'} eq 'on' and !$check_opt->('no_cont');
1869 }
1870 #changed!
1871 #founded_files founded -> total
1872 #onpage limit -> size
1873 #dbirows -> actual
1874 #maxpage -> last
1875 sub gotopage { # $Id: psweb.pm 4843 2013-08-14 12:17:58Z pro $ $URL: svn://svn.setun.net/search/trunk/lib/psweb.pm $
1876 my ($fparam) = @_; #$param,
1877 my (%ret);
1878 #$fparam->{'total'} : total results, usually COUNT(*) as total
1879 #-----------size -- : size of one page in rows (LIMIT x,size)
1880 #current : current page number
1881 #actual : usually $DBI::rows, if total unknown
1882 #last : last page number (auto calculated from total/size if 0)
1883 #total_max = 1000 : maximum db results
1884 #printlog('dmp', 'gotopage start:', Dumper($fparam));
1885 $fparam->{'size'} = 100 unless defined $fparam->{'size'};
1886 return {} unless $fparam->{'size'};
1887 $fparam->{'actual'} = $fparam->{'size'} unless defined $fparam->{'actual'};
1888 $fparam->{'current'} ||= 1;
1889 $fparam->{'last'} ||=
1890 $fparam->{'size'} < 1
1891 ? undef
1892 : ( int( $fparam->{'total'} / ( $fparam->{'size'} || 1 ) ) + ( $fparam->{'total'} % ( $fparam->{'size'} || 1 ) ? 1 : 0 ) );
1893 $fparam->{'buttonsb'} ||= $config{'gotopage_bb'} || 5; #before
1894 $fparam->{'buttonsa'} ||= $config{'gotopage_ba'} || 5; #after
1895 $fparam->{'align'} = 1 unless defined $fparam->{'align'};
1896 $fparam->{'jumpten'} = 1 unless defined $fparam->{'jumpten'};
1897 $fparam->{'power'} = 2 unless defined $fparam->{'power'};
1898 my $fromto = sub {
1899 my ($n) = @_;
1900 return (
1901 ( ( ( $n - 1 ) * $fparam->{'size'} ) + 1 ) . '-'
1902 . (
1903 ( $fparam->{'total'} and ( $fparam->{'total'} < $n * $fparam->{'size'} ) ) ? $fparam->{'total'} : $n * $fparam->{'size'}
1904 )
1905 );
1906 };
1907 my $align = sub {
1908 my $a = int(shift);
1909 my $len = shift || $fparam->{'align'};
1910 substr( $a, $len, length($a) - $len ) = '0' x ( length($a) - $len ) if $len > 0 and length($a) > $len;
1911 return $a;
1912 };
1913 #printlog('dmp', 'gotopage calc:'," <br\n/>" .Dumper($fparam) . "<br\n/>");
1914 my $next = $fparam->{'actual'} >= $fparam->{'size'};
1915 if ( ( !$fparam->{'total'} and $fparam->{'actual'} > 0 )
1916 or $fparam->{'total'} >= $fparam->{'size'}
1917 or $fparam->{'current'} > 1 )
1918 {
1919 $ret{'prev'}{ $fparam->{'current'} - 1 } = $fromto->( $fparam->{'current'} - 1 ) if $fparam->{'current'} > 1;
1920 for my $n ( ( $fparam->{'current'} > $fparam->{'buttonsb'} ? $fparam->{'current'} - $fparam->{'buttonsb'} : 2 )
1921 .. $fparam->{'current'} + ( $next ? $fparam->{'buttonsa'} : 0 ) )
1922 {
1923 last if $fparam->{'total'} and $n > $fparam->{'last'};
1924 last if $fparam->{'total_max'} and $n * $fparam->{'size'} > $fparam->{'total_max'};
1925 ( ( !$fparam->{'total'} and $n > $fparam->{'current'} + 1 ) ? ( \%{ $ret{'small'} } ) : ( \%{ $ret{'big'} } ) )->{$n} =
1926 $fromto->($n);
1927 }
1928 if ( $fparam->{'jumpten'} ) {
1929 $fparam->{'jumpfrom'} ||= '1' . ( 0 x ( length( $fparam->{'current'} - $fparam->{'buttonsb'} ) - 1 ) );
1930 $fparam->{'jumpto'} ||= '1' . ( 0 x length( $fparam->{'current'} + $fparam->{'buttonsa'} ) );
1931 $ret{'big'}{$_} = $fromto->($_)
1932 for grep { !$fparam->{'last'} or $_ <= $fparam->{'last'} }
1933 map { '1' . ( 0 x $_ ) } 1 .. length( $fparam->{'current'} ) - 1;
1934 if ($next) {
1935 $ret{'big'}{$_} = $fromto->($_)
1936 for map { '1' . ( 0 x $_ ) } length( $fparam->{'current'} ) .. length( $fparam->{'last'} ) - 1;
1937 }
1938 }
1939 $fparam->{'jumpfrom'} ||= 1;
1940 $fparam->{'jumpto'} ||= $fparam->{'last'};
1941 #$fparam->{'jumpto'} = psmisc::min( $fparam->{'jumpto'}, $fparam->{'last'} );
1942 $fparam->{'jumpto'} = $fparam->{'last'} if $fparam->{'last'} < $fparam->{'jumpto'};
1943 if ( $fparam->{'power'} > 1 ) {
1944 my ($n);
1945 $n = $fparam->{'current'} - $fparam->{'buttonsb'} * $fparam->{'power'};
1946 for (
1947 $_ = $fparam->{'buttonsb'} ;
1948 $fparam->{'jumpfrom'} >= 1 and $n > $fparam->{'jumpfrom'} and $n < $fparam->{'last'} ;
1949 $n -= ( $_ *= $fparam->{'power'} )
1950 )
1951 {
1952 $ret{'big'}{ $align->($n) } = $fromto->( $align->($n) );
1953 }
1954 $n = $fparam->{'current'} + $fparam->{'buttonsa'} * $fparam->{'power'};
1955 for ( $_ = $fparam->{'buttonsa'} ; $next and $n < $fparam->{'jumpto'} ; $n += ( $_ *= $fparam->{'power'} ) ) {
1956 $ret{'big'}{ $align->($n) } = $fromto->( $align->($n) );
1957 }
1958 }
1959 $ret{'big'}{ $fparam->{'last'} } = $fromto->( $fparam->{'last'} ) if $fparam->{'last'} > 1 and $next;
1960 $ret{'big'}{1} ||= $fromto->(1)
1961 if ( $fparam->{'last'} > 1 or !$fparam->{'total'} )
1962 and $fparam->{'actual'} >= $fparam->{'size'};
1963 $ret{'next'}{ $fparam->{'current'} + 1 } = $fromto->( $fparam->{'current'} + 1 )
1964 if $next and !$fparam->{'last'}
1965 or $fparam->{'current'} < $fparam->{'last'};
1966 }
1967 #printlog('dmp', 'gotopage ret:', Dumper(\%ret));
1968 return wantarray ? ( sort { $a <=> $b } keys %{ $ret{'big'} }, keys %{ $ret{'small'} } ) : \%ret;
1969 }
1970  
1971 sub cache_file {
1972 my $fparam = ( shift or {} );
1973 for my $file ( grep $_, @_ ) {
1974 if ( $fparam->{'cache'} and !$fparam->{'url'} ) {
1975 my $full = $config{'root_path'} . $file;
1976 if (
1977 !defined $static{'cache'}{$full} and open( CFH, '<',
1978 #$ENV{'PROSEARCH_PATH'}
1979 $full
1980 )
1981 )
1982 {
1983 local $/;
1984 $static{'cache'}{$full} = cp_trans( $config{'cp_cache'}, $config{'cp_int'}, <CFH> );
1985 close(CFH);
1986 #print "cache readed($file, $full) = ",length $static{'cache'}{$full},";\n";
1987 }
1988 #print "cache print($file, $full);\n";
1989 print $fparam->{'pre_cached'}, cp_trans( $config{'cp_int'}, $work{'codepage'}, $static{'cache'}{$full} ),
1990 $fparam->{'post_cached'};
1991 } else {
1992 print $fparam->{'pre_url'}, ( $file =~ m{^\w+://} ? () : $fparam->{'url'} ), $file, $fparam->{'post_url'};
1993 }
1994 }
1995 }
1996  
1997 sub cache_file_js {
1998 my $fparam = ( shift or {} );
1999 cache_file( {
2000 'cache' => $config{'cache_js'},
2001 'url' => $config{'js_url'},
2002 'pre_cached' => $config{'jscript_open'},
2003 'post_cached' => $config{'jscript_close'},
2004 'pre_url' => '<script type="text/javascript" language="JavaScript" src="',
2005 'post_url' => "\">\n</script>",
2006 %$fparam,
2007 },
2008 @_
2009 );
2010 }
2011  
2012 sub cache_file_css {
2013 my $fparam = shift || {};
2014 cache_file( {
2015 'cache' => $config{'cache_css'},
2016 'url' => $config{'css_url'},
2017 'pre_cached' => "<style type=\"text/css\" media=\"screen\" rel=\"stylesheet\">",
2018 'post_cached' => "</style>",
2019 'pre_url' => '<link rel="stylesheet" media="screen" type="text/css" href="',
2020 'post_url' => '"/>',
2021 %$fparam,
2022 },
2023 @_
2024 );
2025 }
2026  
2027 sub is_img {
2028 #printlog('devw', '0is_img', "F[$_[0]]", defined( $static{'is_img'}{ $_[0] } ), $static{'is_img'}{ $_[0] }, "external[$config{'img_external'}{$_[0]}] url=$config{'img_url'} path=$config{'img_path'}");
2029 return undef unless length $_[0];
2030 return $static{'is_img'}{ $_[0] } if defined( $static{'is_img'}{ $_[0] } );
2031 local $_ = $_[0];
2032 $_ = $config{'img_trans'}{$_} if defined $config{'img_trans'}{$_};
2033 #printlog('devw', '1is_img=', $_[0]),
2034 return $static{'is_img'}{$_} = $_[0] if $_[0] =~ m|^\w+://|;
2035 #printlog('devw', '2is_img=', $config{'img_url'} .$config{'img_path'}. $_ . '.' . $config{'img_ext'}),
2036 return $static{'is_img'}{$_} = $config{'img_url'} . $config{'img_path'} . $_ . '.' . $config{'img_ext'}
2037 if $config{'img_url'} =~ m{^\w+://} and ( $config{'img_external'}{$_} or -e $config{'root_path'} . $_[0] );
2038 #printlog('devw', '3is_img=', !!-e $config{'root_path'} . $config{'img_path'} . $_ . '.' . $config{'img_ext'} ? $config{'img_url'} . $_ . '.' . $config{'img_ext'} : '', $config{'img_path'} . $_ . '.' . $config{'img_ext'}),
2039 return $static{'is_img'}{$_} = $_[0] if $_[0] =~ m|/| and !!-e $config{'root_path'} . $_[0];
2040 #return $static{'is_img'}{$_} = !!-e if $config{'img_url'} =~ m|^\w+://| and ;
2041 #my $r =
2042 return $static{'is_img'}{$_} =
2043 !!-e $config{'root_path'} . $config{'img_path'} . $_ . '.' . $config{'img_ext'}
2044 ? $config{'img_url'} . $config{'img_path'} . $_ . '.' . $config{'img_ext'}
2045 : '';
2046 #printlog('devw', '4is_img=', $_[0], $config{'root_path'} . $config{'img_path'} . $_ . '.' . $config{'img_ext'}, $config{'img_url'} . $config{'img_path'}.$_ . '.' . $config{'img_ext'}, );
2047 #return $r;
2048 }
2049  
2050 sub select_mode {
2051 my ( $param, $paramnum, $valuenum ) = @_;
2052 print '<select name="', $_, '_mode', $paramnum, '" dir="ltr" >', '<option value="">', lang($_), '</option>',
2053 '<option value="=" ', ( $param->{ $_ . '_mode' . $valuenum } =~ /[e=]/i ? 'selected="selected"' : '' ), '>', lang('='),
2054 '</option>', '<option value="!" ', ( $param->{ $_ . '_mode' . $valuenum } =~ /[n!]/i ? 'selected="selected"' : '' ), '>',
2055 lang('!'), '</option>', '<option value=">" ',
2056 ( $param->{ $_ . '_mode' . $valuenum } =~ /[g>]/i ? 'selected="selected"' : '' ), '>', lang('>'), '</option>',
2057 '<option value="<" ', ( $param->{ $_ . '_mode' . $valuenum } =~ /[l<]/i ? 'selected="selected"' : '' ), '>', lang('<'),
2058 '</option>', '<option value="~" ', ( $param->{ $_ . '_mode' . $valuenum } =~ /[r~]/i ? 'selected="selected"' : '' ), '>',
2059 lang('~'), '</option>', '<option value="@" ',
2060 ( $param->{ $_ . '_mode' . $valuenum } =~ /[s@]/i ? 'selected="selected"' : '' ), '>', lang('@'), '</option>', '</select>';
2061 }
2062  
2063 =dep
2064 sub cp_trans_row {
2065 my ($row) = @_;
2066 return cp_trans_hash( $config{'cp_db'}, $work{'codepage'}, $row );
2067 }
2068 =cut
2069  
2070 sub update_query_stat {
2071 return if !$config{'allow_query_stat'} or $config{'client_bot'};
2072 #printlog( 'dev', 'update_query_stat' , $work{'codepage'}, $config{'cp_db'}, keys %{ $work{'word'} }, keys %{ $work{'query'} }, Dumper \%work);
2073 print $config{'jscript_open'}, 'createCookie(\'queries\', \'',
2074 ( join '||', map { encode_url($_) } grep { $_ } ( keys %{ $work{'query'} }, @{ $work{'queries'} } )[ 0 .. 10 ], ), '\');',
2075 $config{'jscript_close'}
2076 if $config{'view'} eq 'html' and keys %{ $work{'query'} };
2077 psmisc::flush();
2078 local $config{'sql'}{'database'} = $config{'sql_base_wup'};
2079 #local $static{'db'}->{'cp_in'} = $config{'cp_db'};
2080 delete $work{'word'} if $config{'no_word'};
2081 for my $word ( grep { $_ =~ /\w/ } keys %{ $work{'word'} } ) {
2082 #map {scalar cp_trans( $self->{'cp_in'}, $self->{'codepage'}, $_ )}
2083 $_->update(
2084 $config{'sql_twordstat'},
2085 ['word'], {
2086 #'word' => $word,
2087 'word' => scalar cp_trans( $work{'codepage'}, $config{'cp_db'}, $word ),
2088 'lastip' => $config{'client_ip'},
2089 'last' => int( time() )
2090 },
2091 '',
2092 '',
2093 ", " . $_->rquote('top') . " = " . $_->rquote('top') . "+" . $_->quote(1)
2094 ) for $static{'dbs_up_all'} ? @{ $static{'dbs_up_all'} } : $static{'db'};
2095 }
2096 #$static{'db'}->dump_cp();
2097 #printlog( 'dev', 'update_query_stat' , $work{'codepage'}, $config{'cp_db'}, keys %{ $work{'word'} }, keys %{ $work{'query'} });
2098 for my $query ( grep $_ =~ /\w/, keys %{ $work{'query'} } ) {
2099 #printlog( 'dev', 'query', $query, utf8::is_utf8($query) );
2100 #$query =~ s/\W+/ /g , $query =~ s/(^\s+)|(\s+$)//g if $config{'cp_db'} ne 'utf-8';
2101 $_->update(
2102 $config{'sql_tquerystat'},
2103 ['query'], {
2104 #'query' => $query, #scalar cp_trans( $work{'zcodepage'}, $config{'cp_db'}, $query ),
2105 'query' => scalar cp_trans( $work{'codepage'}, $config{'cp_db'}, $query ),
2106 'lastip' => $config{'client_ip'},
2107 'last' => int( time() )
2108 },
2109 '',
2110 '',
2111 #", `top` = `top`+'1'"
2112 ", " . $_->rquote('top') . " = " . $_->rquote('top') . "+" . $_->quote(1)
2113 ) for $static{'dbs_up_all'} ? @{ $static{'dbs_up_all'} } : $static{'db'};
2114 }
2115 }
2116  
2117 sub sorter {
2118 my ( $param, $fparam, $oph ) = @_;
2119 $fparam->{'id'} ||= $fparam->{'order'};
2120 $fparam->{'lang'} ||= $fparam->{'order'};
2121 #print "hi", Dumper(( $param, $fparam, $oph ));
2122 print '<span id="head_', $fparam->{'id'}, '">';
2123 psmisc::printu mylink(
2124 lang( $fparam->{'lang'} ), {
2125 %$oph,
2126 'order' => $fparam->{'order'},
2127 ( ( $param->{'order'} eq $fparam->{'order'} and $param->{'order_mode'} ) ? () : ( 'order_mode' => '!' ) ),
2128 },
2129 undef,
2130 { 'destroy' => $config{'destroy_link_sort'} }
2131 ),
2132 ' '
2133 unless $fparam->{'no_lang'};
2134 psmisc::printu mylink(
2135 lang('darr'),
2136 { %$oph, 'order' => $fparam->{'order'}, },
2137 undef, {
2138 'destroy' => $config{'destroy_link_sort'}
2139 || ( ( $param->{'order'} eq $fparam->{'order'} and !$param->{'order_mode'} ) ? ('NO') : () ),
2140 #( ( $param->{'order'} eq $fparam->{'order'} and !$param->{'order_mode'} ) ? ( 'href' => 'NO' ) : () ), 'destroy' => $config{'destroy_link_sort'}
2141 },
2142 ),
2143 ' '
2144 unless $fparam->{'no_down'};
2145 print mylink(
2146 lang('uarr'),
2147 { %$oph, 'order' => $fparam->{'order'}, 'order_mode' => '!' },
2148 undef, {
2149 #( ( $param->{'order'} eq $fparam->{'order'} and $param->{'order_mode'} ) ? ( 'href' => 'NO' ) : () ), 'destroy' => $config{'destroy_link_sort'}
2150 'destroy' => $config{'destroy_link_sort'}
2151 || ( ( $param->{'order'} eq $fparam->{'order'} and $param->{'order_mode'} ) ? ('NO') : () ),
2152 },
2153 ),
2154 unless $fparam->{'no_up'};
2155 print $config{'sel_sep'} unless $fparam->{'no_sep'};
2156 print '</span> ';
2157 }
2158  
2159 sub date_period {
2160 #return;
2161 my ( $time, $name ) = @_;
2162 #print '[',@_,']';
2163 print mylink(
2164 psmisc::human( 'time_period', int( time() ) + $config{'timediff'} - $time ) || 0,
2165 undef, {
2166 'title' => lang( $name, undef, undef, ' ' ) . psmisc::human( 'date_time', $time - $config{'timediff'} ),
2167 'href' => undef,
2168 },
2169 ) if $time;
2170 }
2171  
2172 sub next_user {
2173 #my $self = shift;
2174 #$self->{'queries'} = $self->{'queries_time'} = $self->{'errors_chain'} = $self->{'errors'} = $self->{'connect_tried'} = 0;
2175 delete $stat{$_} for qw (found files found_time onpage results top_founded_max top_pages_max);
2176 #$self->{ 'on_user' . $_ }->($self) for grep { ref $self->{ 'on_user' . $_ } eq 'CODE' } ( '', 1 .. 5 );
2177 #$self->{ 'on_user' }->($self) for grep { ref $self->{ 'on_user' } eq 'CODE'}('');
2178 #$self->log('dev', 'nup');
2179 #found
2180 }
2181 1;