blib/lib/A1z/HTML5/Template.pm untested

filter: Statementstmt 0.0% 0 / 506 Branchbran 0.0% 0 / 234 Conditioncond 0.0% 0 / 145 Subroutinesub 0.0% 0 / 42 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 963 CC 118 SCAR 64.3
CC
118
Cov
0%
open_file
2070.0
body_form
240.0
edit_file
72.0
CRAP 623.3
1 use strict;
2 use warnings;
3 package A1z::HTML5::Template;
4  
5 use vars qw(%ENV);
6  
7 # ABSTRACT: Fast/easy Web Apps in Perl
8  
9  
10 sub NAME { my $self = shift; my $NAME; $NAME = "Fast and Easy Web Apps"; return $NAME; }
11  
12 our $VERSION = '0.20';
13  
14  
15  
16 use parent qw(Exporter);
17 require Exporter;
18 our @ISA = ("Exporter");
19  
20 our @EXPORT_OK = qw(header start_html head_title head_meta head_js_css end_head begin_body body_js_css body_topnavbar
21 body_accordion end_body end_html
22 );
23  
24  
25  
26 sub new {
27 my $class = shift;
28 my $self = bless { @_ }, $class;
29 return $self;
30 }
31  
32  
33 sub math1
34 {
35 my $self = shift;
36
37 my ($num1, $num2) = @_;
38
39 if ($num1 eq '') { $num1 = '2'; }
40 if ($num2 eq '') { $num2 = '4'; }
41
42 my $out;
43
44 my $m = $num1 * $num2;
45 my $a = $num1 + $num2;
46 my $s = $num1 - $num2;
47 my $s1 = $num2 - $num1;
48 my $d = $num1 / $num2;
49 my $d1 = $num2 / $num1;
50
51 $out .= qq{<div class="math">
52 <table class="table table-responsive table-bordered table-condensed table-hover">
53
54 <thead><tr><td colspan="6">Multiplication</td></tr></thead>
55 <tr>
56 <td></td>
57 <td>$num1</td>
58 <td>x</td>
59 <td>$num2</td>
60 <td>\=</td>
61 <td>$m</td>
62 </tr>
63
64 <thead><tr><td colspan="6">Addition</td></tr></thead>
65 <tr> <td></td> <td>$num1 </td> <td>\+</td> <td> $num2</td> <td> \=</td> <td> $a</td> </tr>
66
67 <thead><tr><td colspan="6">Subtraction</td></tr></thead>
68 <tr> <td></td> <td>$num1</td> <td> \-</td> <td> $num2</td> <td> \=</td> <td> $s</td> </tr>
69 <tr> <td></td> <td>$num2</td> <td> \-</td> <td> $num1</td> <td> \=</td> <td> $s1</td> </tr>
70
71 <thead><tr><td colspan="6">Division</td></tr></thead>
72 <tr> <td></td> <td>$num1</td> <td> \/</td> <td> $num2</td> <td> \=</td> <td> $d </td></tr>
73 <tr> <td></td> <td>$num2</td> <td> \/</td> <td> $num1</td> <td> \=</td> <td> $d1</td> </tr>
74
75 </table>
76 </div>
77 };
78  
79 return qq{\n$out\n};
80 }
81  
82  
83  
84 # begin timestable
85 sub timestable
86 {
87 my $self = shift;
88
89 my ($num1) = @_;
90
91 if ( $num1 eq '' ) { $num1 = '2'; }
92
93 my $out;
94
95 $out .= qq{<table class="table table-bordered table-condensed table-striped table-hover table-responsive">};
96
97 for ('1'..'20')
98 {
99 $out .= qq{<tr> <td>$num1</td> <td>x</td> <td>$_</td> <td>=</td> <td>} . $num1 * $_ . qq{</td></tr>} if ($_);
100 }
101 $out .= qq{</table>};
102
103 return $out;
104 }
105 # end timestable
106  
107  
108  
109 # begin header
110 sub header
111 {
112 my $self = shift;
113
114 # my %in = (
115 # -type => "Content-Type: text/html",
116 # -char => "charset=utf-8\n\n",
117 # @_,
118
119 # );
120
121 my @keys;
122 if (@_) { @keys = @_; }
123
124 my $args = scalar(@keys);
125
126 my ($key, $key1) = @_;
127
128 my %out;
129
130 if ($ARGV and $ARGV > 0 and scalar(@keys) > 0)
131 {
132 if ($key eq 'utf8')
133 {
134 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
135
136 }
137 elsif (!defined $key or $key eq '')
138 {
139 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
140 }
141 else
142 {
143 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
144 }
145 }
146 else
147 {
148 return qq{Content-Type: text/html;charset=utf-8\n\n};
149 }
150
151 }
152 # end header
153  
154  
155  
156 # begin start html 01
157 sub start_html
158 {
159 my $self = shift;
160
161 my @keys;
162 if (@_) { @keys = @_; }
163
164 my $args = scalar @keys;
165
166 my ($key, $key1) = @_;
167
168 my %out;
169
170 if ($args and $args >= 0)
171 {
172 # have your own custom header, backwards compatibility
173
174 my $out;
175
176 $out .= qq{@_ };
177
178 return $out;
179
180 }
181 else
182 {
183 my $out;
184
185 $out .= qq{<!DOCTYPE html>\n<html>\n};
186 $out .= qq{<head>\n};
187
188 return $out;
189
190 }
191 }
192 # end start_html
193  
194  
195  
196  
197 sub body_js_css
198 {
199 my $self = shift;
200
201 my $key = "@_";
202
203 my @keys;
204 if (@_) { @keys = @_; }
205
206 my $args = scalar (@keys);
207
208 my $out;
209
210 $out .= qq^
211 <!--jquery-->
212 <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
213 <!--bootstrap/jQueryUI-->
214 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
215 <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
216  
217 <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
218 <script type="text/javascript" src="https://www.a1z.us/jquery/bootstrap/fixed-top/ie10-viewport-bug-workaround.js"></script>
219  
220 <script type="text/javascript">
221
222 // for tabs
223 \$( function() {
224 var tabs = \$("#tabs").tabs();
225 tabs.find( ".ui-tabs-nav" ).sortable({
226 axis: "x",
227 stop: function() { tabs.tabs( "refresh" ); }
228 });
229 });
230
231 // dialog
232 \$( function() {
233 \$( "#dialog" ).dialog({
234 autoOpen: false,
235 show: {
236 effect: "blind",
237 duration: 1000
238 },
239 hide: {
240 effect: "explode",
241 duration: 1000
242 }
243 });
244
245 \$( "#opener" ).click(function() {
246 \$( "#dialog" ).dialog( "open" );
247 });
248 });
249
250 \$('#menu').menu();
251 \$('#accordion').accordion();
252 \$('#accordion1').accordion();
253 \$('#accordion2').accordion();
254 \$('#accordion3').accordion();
255 \$('#tabs').tabs();
256
257 </script>
258
259 ^;
260
261
262 if ( $args )
263 {
264
265 if ( $args >= 0)
266 {
267 my $return;
268
269 for (@keys )
270 {
271 chomp;
272 if ($_ =~ /.js$/)
273 {
274 $return .= qq{<script type="text/javascript" src="$_"></script>\n};
275 }
276 elsif ($_ =~ /.css$/)
277 {
278 $return .= qq{<link href="$_" rel="stylesheet" style="text/css">\n};
279 }
280 else
281 {
282 # do nothing
283 #return qq{<!--213--> @keys\n};
284 }
285 }
286
287 return qq{$return}; #
288 }
289 else
290 {
291 return qq{$out};
292 }
293
294 }
295 else
296 {
297 return qq{<!--229 noParams-->$out}; #
298 }
299
300 }
301  
302  
303  
304  
305  
306 # start end_html
307 sub end_html
308 {
309 my $self = shift;
310
311 my @keys;
312 if (@_) { @keys = @_; }
313
314 my ($key, $key1) = @_;
315
316 my $out;
317
318 $out .= qq{</html>\n\n};
319
320 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
321 {
322 return qq{@_};
323 }
324 else
325 {
326 return $out;
327 }
328 }
329 # end end_html
330  
331  
332  
333  
334 # start head title 02
335 sub head_title
336 {
337 my $self = shift;
338
339 my $key = "@_";
340
341 my @keys;
342 if (@_) { @keys = @_; }
343
344 my $out;
345
346 $out .= qq{};
347
348 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
349 {
350
351 if ($key)
352 {
353 return qq{<title>@_</title>\n};
354 }
355 else
356 {
357 return qq{<title>Template</title>\n};
358 }
359
360 }
361 else
362 {
363 return qq{<title>Package Html5</title>\n}; # this works but does not ask the user
364 }
365
366 }
367 # end head title
368  
369  
370  
371  
372 # begin head meta 03
373 sub head_meta
374 {
375 my $self = shift;
376
377 my $key = "@_";
378
379 my @keys;
380 if (@_) { @keys = @_; }
381
382 my $args = scalar @keys;
383
384 my $out;
385
386 $out .= qq{<meta charset="utf-8">
387 <meta lang="en">
388 <meta http-equiv="X-UA-Compatible" content="IE=edge">
389 <meta name="HandheldFriendly" content="true">
390 <meta name="viewport" content="width=device-width, initial-scale=1">
391 };
392
393 if ($args)
394 {
395
396 if ($args >= 0)
397 {
398 my $return;
399
400 for (@keys )
401 {
402 chomp;
403
404 my ( $meta_name, $meta_cont) = split(/---/, $_, 2);
405
406 $return .= qq{<meta name="$meta_name" content="$meta_cont">\n};
407 }
408
409 return qq{$return<!--360-->};
410 }
411 else
412 {
413 $out .= qq{<meta name="description" content="HTML5 by Business Impact Solutions - bislinks.com"/><!--364-->};
414 # add default meta if user has not called one of his own
415 return qq{$out};
416 }
417
418 }
419 else
420 {
421 return qq{$out}; # this works but does not ask the user
422 }
423
424 }
425 # end head meta 03
426  
427  
428  
429  
430 # begin body top nav bar
431 sub body_topnavbar
432 {
433 my $self = shift;
434
435 my %in;
436
437 %in = (
438 file => "https://www.a1z.us/js/utils/top-nav-bar.js",
439 name => "Menu",
440 @_,
441 );
442
443 my $out;
444
445 $out .= qq{<!--top nav bar begin-->
446 <script src="$in{file}"></script>
447 <script>
448 fixed_top_navbar('', '', '$in{name}', '', '');
449 </script>
450 <!-- top nav bar end-->
451 };
452
453 return qq{$out\n}; # this works but does not ask the user
454
455 }
456 # end body top nav bar
457  
458  
459  
460  
461 sub head_js_css
462 {
463 my $self = shift;
464
465 my $key = "@_";
466
467 my @keys;
468 if (@_) { @keys = @_; }
469
470 my $args = scalar (@keys);
471
472 my $out;
473
474 $out .= qq{
475
476 <!-- Bootstrap/jqueryUI -->
477  
478 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" type="text/css">
479 <link href="https://www.a1z.us/jquery/bootstrap/fixed-top/navbar-fixed-top.css" rel="stylesheet">
480 <link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet">
481  
482 <!--HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries-->
483  
484 <!--[if lt IE 9]>
485 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
486 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
487 <![endif]-->
488  
489 };
490
491 if ($args)
492 {
493
494 if ($args >= 0)
495 {
496 my $return;
497
498 for (@keys)
499 {
500 chomp;
501 if ($_ =~ /.js$/)
502 {
503 $return .= qq{<!--442--> \n<script type="text/javascript" src="$_"></script> \n};
504 }
505 elsif ($_ =~ /.css$/)
506 {
507 $return .= qq{<!--446--> \n<link href="$_" rel="stylesheet" style="text/css"> \n};
508 }
509 else
510 {
511 # do nothing
512 return qq{@keys<!--469-->\n};
513 }
514 }
515
516 return qq{$return<!--473 jQ-->\n};
517 }
518 else
519 {
520 return qq{$out\n};
521 }
522
523 }
524 else
525 {
526 return qq{$out\n}; # this works but does not ask the user
527 }
528
529 }
530 # end head js css
531  
532  
533  
534  
535 # begin end head
536 sub end_head
537 {
538 my $self = shift;
539
540 my $key = "@_";
541
542 my @keys;
543 if (@_) { @keys = @_; }
544
545 my $out;
546
547 $out .= qq{</head>};
548
549 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
550 {
551
552 if (@_)
553 {
554 return qq{@_\n};
555 }
556 else
557 {
558 return qq{$out\n};
559 }
560
561 }
562 else
563 {
564 return qq{$out\n}; # this works but does not ask the user
565 }
566 }
567 # end end head
568  
569  
570  
571 # begin begin body
572 sub begin_body
573 {
574 my $self = shift;
575
576 my $key = "@_";
577
578 my @keys;
579 if (@_) { @keys = @_; }
580
581 my $out;
582
583 $out .= qq{<body>};
584
585 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
586 {
587
588 if (@_)
589 {
590 return qq{@_\n};
591 }
592 else
593 {
594 return qq{$out\n};
595 }
596
597 }
598 else
599 {
600 return qq{$out\n}; # this works but does not ask the user
601 }
602 }
603 # end begin body
604  
605  
606  
607 # begin accordion or rather file content. Need to change name of this method
608 sub body_accordion
609 {
610 my $self = shift;
611
612 my $key = "@_";
613
614 my @keys;
615 if (@_) { @keys = @_; }
616
617 my $out;
618
619 $out .= qq{<!--begin Content-->
620 <div id="accordion617" class="accordion">
621 <h3>Who is it for</h3>
622 <div>For those who know/uderstand Perl/HTML/jQuery</div>
623 <h3>What about a bigger number?</h3>
624 <div>Sure. Use the custom form to get the times table for a number greater than 30?</div>
625 <h3>How about any number/range?</h3>
626 <div>Yes, of course! Once again, use the custom form bearing the heading "Or enter your own"</div>
627 <h3>Can I customize it for own use?</h3>
628 <div>In that case, you need to purchase the software and/or order a customization</div>
629 </div>
630  
631 <!--end Content-->
632  
633 };
634
635 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
636 {
637
638 if (@_)
639 {
640 return qq{\n@_\n};
641 }
642 else
643 {
644 return qq{\n$out\n};
645 }
646
647 }
648 else
649 {
650 return qq{\n$out\n}; #
651 }
652 }
653 # end accordion
654  
655  
656  
657  
658 sub body_article
659 {
660 my $self = shift;
661
662 my $out;
663
664 my %in;
665 %in =
666 (
667 content => "",
668 type => "article",
669 header => "Content Header",
670 @_,
671 );
672
673 if ( !defined $in{content} or $in{content} eq '' )
674 {
675 return qq{
676 No Content
677 };
678 }
679 else
680 {
681 return qq{<article class="container"><h2>$in{header}</h2>
682 $in{content}
683 </article>
684 };
685 }
686 }
687  
688  
689  
690  
691 # begin begin body
692 sub end_body
693 {
694 my $self = shift;
695
696 my $key = "@_";
697
698 my @keys;
699 if (@_) { @keys = @_; }
700
701 my $out;
702
703 $out .= qq{\n</body>\n};
704
705 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
706 {
707
708 if (@_)
709 {
710 return qq{@_\n};
711 }
712 else
713 {
714 return qq{$out\n};
715 }
716
717 }
718 else
719 {
720 return qq{$out\n}; # this works but does not ask the user
721 }
722 }
723 # end end body
724  
725  
726  
727  
728  
729 # begin content folder to select form
730 sub body_form
731 {
732 my $self = shift;
733
734 my $out;
735
736 my @keys;
737 if (@_) { @keys = @_; }
738
739 my ($vars, $vals) = ('');
740 for (@keys)
741 {
742 $vars = $_ if ($_ =~ /^vars/);
743  
744 # $vals not used
745 $vals = $_ if ($_ =~ /^vals/);
746 }
747
748 my @form_vars = split(/\;/, $vars);
749
750 my @form_vals = split(/\;/, $vals);
751
752 # get params for hidden fields if given
753 my @hidden;
754 if ($form_vars[4] and $form_vars[4] =~ /\,/)
755 {
756 @hidden = split(/\,/, $form_vars[4]);
757 }
758 else
759 {
760 @hidden = ("No", "Vals");
761 }
762
763 # if SELECT ....
764
765 my $select;
766
767 if ($form_vars[3] and $form_vars[3] =~ /^select/)
768 {
769 # get the params for the form
770 # select,
771 my ($sel_key, $sel_name, $sel_default, $folder_or_file, $selectLabelText) = split(/\,/, $form_vars[3], 5);
772  
773 $select .= qq{
774 <label for="$sel_name">$selectLabelText</label>
775 <div class="form-group"><!--begin select-->
776 \t<select name="$sel_name">
777 \t\t<option selected value="$sel_default">$sel_default</option>
778 };
779
780 #now open file/folder to fill "options"
781 if ( -f $folder_or_file )
782 {
783 # open as file
784 #$select .= qq{none};
785 }
786 elsif (-d $folder_or_file)
787 {
788 # open as dir and add all files in it to "options"
789 opendir(D, "$folder_or_file") or $select .= qq{<div class="error">$!</div>};
790 my @DIR = readdir(D);
791
792 while ( my $file = <each @DIR> )
793 {
794 # only if file contains alphabets, numbers, and dashes
795 next unless $file =~ /[a-zA-Z0-9\-]/;
796  
797 # comment if you want subfolders also listed
798 next unless -f "$folder_or_file/$file";
799  
800 # get rid of . and ..
801 next if $file =~ /^(\.|\.\.)/;
802  
803 # do not add hidden files to the options list
804 next if $file =~ /^\./;
805
806 # get the size of th file
807 my $size = -s "$folder_or_file/$file";
808 my $original = $size;
809 $size /= 1024;
810 #$size /= 1024;
811 $size = sprintf "%.2f", $size;
812 $select .= qq{\n\t\t\t<option value="$file">$file [$size kb]</option>} if $file;
813 }
814  
815 close D;
816 }
817  
818 $select .= qq{\n\t\t</select>\n\t</div>\n};
819 }
820 else
821 {
822 # no select
823 $select .= qq{};
824 }
825
826
827 $out .= qq{<form action="$form_vars[2]" method="$form_vars[1]">};
828
829 # add hidden fields/values # from $form_vars[4]
830 for (@hidden)
831 {
832 my ($name, $value) = split(/\-\-\-/, $_, 2) if $_;
833 $out .= qq{\n\t<input type="hidden" name="$name" value="$value"/>} if $_;
834 }
835 # add select
836 $out .= qq{$select};
837 $out .= qq{\n\t<button type="submit" class="btn btn-default">Submit</button>\n</form>\n};
838
839 return qq{<div class="body_form">$out</div>};
840 }
841  
842 # end body_form
843  
844  
845  
846 sub defaults_begin
847 {
848 my $self = shift;
849
850 my $out;
851
852 $out .= sprintf header(),
853 start_html(),
854 head_title("$_[0]"),
855 head_meta(),
856 head_meta("$_[1]"),
857 head_js_css(),
858 head_js_css("$_[2]"),
859 end_head(),
860 begin_body(),
861 body_topnavbar()
862 ;
863
864 return $out;
865 }
866  
867  
868  
869 sub defaults_end
870 {
871 my $self = shift;
872
873 my $out;
874
875 $out .= sprintf body_js_css(),
876 body_js_css("$_[0]"),
877 end_body(),
878 end_html()
879 ;
880
881 return $out;
882 }
883  
884  
885  
886 # HTML
887 my %HTML;
888  
889 %HTML = (
890 -defaultjquery => qq{\n<!-- -defaultjquery-->
891  
892 <!-- jquery-->
893 <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
894  
895 <!--bootstrap-->
896 <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
897  
898 <!--blueimp gallery-->
899 <script src="https://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
900  
901 <!-- jquery ui -->
902 <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
903  
904 <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
905 <script type="text/javascript" src="https://www.a1z.us/jquery/bootstrap/fixed-top/ie10-viewport-bug-workaround.js"></script>
906 <script type="text/javascript">
907
908 // for tabs
909 \$( function() {
910 var tabs = \$( "#tabs" ).tabs();
911
912 tabs.find( ".ui-tabs-nav" ).sortable({
913 axis: "x",
914 stop: function() { tabs.tabs( "refresh" ); }
915 });
916 });
917
918 // dialog
919 \$(function() {
920 \$( "#dialog" ).dialog({
921 autoOpen: false,
922 show: {
923 effect: "blind",
924 duration: 1000
925 },
926 hide: {
927 effect: "explode",
928 duration: 1000
929 }
930 });
931
932 \$( "#opener" ).click(function() {
933 \$( "#dialog" ).dialog( "open" );
934 });
935 });
936
937 \$('#menu').menu();
938 \$('#accordion').accordion();
939 \$('#accordion1').accordion();
940 \$('#accordion2').accordion();
941 \$('#accordion3').accordion();
942 \$('accordion617').accordion();
943 \$('#tabs').tabs();
944  
945
946 </script>
947 },
948
949 -default_LastItem => qq{},
950
951 );
952  
953  
954 sub html_bootstrap_css
955 {
956 return qq{<!-- Bootstrap/jqueryUI -->
957 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" type="text/css">
958 <link href="https://www.a1z.us/jquery/bootstrap/fixed-top/navbar-fixed-top.css" rel="stylesheet">
959 };
960
961 }
962  
963  
964  
965  
966 sub html_jqueryui_css
967 {
968 # jquery ui theme jquery-ui.css #1.12.0
969 return qq{<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet">};
970 }
971  
972  
973  
974  
975 sub html_shim_respond
976 {
977 return qq{<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
978 <!--[if lt IE 9]>
979 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
980 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
981 <![endif]-->
982 };
983  
984 }
985  
986  
987  
988 sub html_navbar
989 {
990 #my $self = shift;
991  
992 #serverName, pageName, menuName, dropDownLinks
993
994 my %in;
995 %in = (
996 -nbMenuName => "",
997 -nbPageName => "",
998 -nbServer => "",
999 -nbLinks => "blog-support-help-contact-sale",
1000 @_,
1001 );
1002
1003 return qq{<script src="https://www.a1z.us/js/utils/top-nav-bar.js"></script>
1004 <!--top nav bar begin-->
1005 <script>
1006 //<--
1007 fixed_top_navbar('$in{-nbServer}', '$in{-nbPageName}', '$in{-nbMenuName}', '$in{-nbLinks}');
1008 //-->
1009 </script>
1010 <!-- top nav bar end-->
1011 };
1012  
1013 }
1014  
1015  
1016
1017  
1018 sub html_bootstrap_js
1019 {
1020 # jquery:3.3.0 ui:1/12/1
1021  
1022 return qq{<!-- Bootstrap/jqueryUI -->
1023 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js" rel="stylesheet" type="text/css">
1024  
1025 };
1026  
1027 }
1028  
1029 sub html_js_css
1030 {
1031
1032 }
1033  
1034 sub html_jquery
1035 {
1036
1037 }
1038  
1039  
1040  
1041 sub html_setTitle
1042 {
1043 my $out;
1044  
1045 my %in;
1046
1047 %in = (
1048 ta => qq{},
1049 tb => qq{},
1050 tc => qq{},
1051 @_,
1052 );
1053  
1054 $out .= qq{<script>
1055 <!-- Begin
1056 function setTitle()
1057 {
1058 var a = "$in{ta}";
1059 var b = "$in{tb}";
1060 var c = "$in{tc}";
1061 var t = new Date();
1062 s = t.getSeconds();
1063 if (s == 10) { document.title = a;}
1064 else if (s == 20) { document.title = b;}
1065 else if (s == 30) { document.title = c;}
1066 else if (s == 40) { document.title = a;}
1067 else if (s == 50) { document.title = b;}
1068 else if (s == 00) { document.title = c;}
1069 setTimeout("setTitle()", 1000);
1070 }
1071 // End -->
1072 </script>
1073 };
1074  
1075 return $out;
1076 }
1077  
1078  
1079  
1080  
1081 sub html_humanejs_css
1082 {
1083 return qq{<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/bigbox.css'>
1084 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/boldlight.css'>
1085 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/jackedup.css'>
1086 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/libnotify.css'>
1087 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/original.css'>
1088 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/flatty.min.css'>
1089 <link href='https://fonts.googleapis.com/css?family=Ubuntu&v2' rel='stylesheet' type='text/css'>
1090 <link href='https://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
1091 <link href='https://fonts.googleapis.com/css?family=Cabin+Sketch:700&v2' rel='stylesheet' type='text/css'>
1092 };
1093  
1094 }
1095  
1096  
1097  
1098  
1099 sub html_bootstrap_bluimp
1100 {
1101 return qq{<!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body -->
1102 <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-use-bootstrap-modal="false">
1103 <!-- The container for the modal slides -->
1104 <div class="slides"></div>
1105 <!-- Controls for the borderless lightbox -->
1106 <h3 class="title"></h3>
1107 <a class="prev">‹</a>
1108 <a class="next">›</a>
1109 <a class="close">×</a>
1110 <a class="play-pause"></a>
1111 <ol class="indicator"></ol>
1112 <!-- The modal dialog, which will be used to wrap the lightbox content -->
1113 <div class="modal fade">
1114 <div class="modal-dialog">
1115 <div class="modal-content">
1116 <div class="modal-header">
1117 <button type="button" class="close" aria-hidden="true">&times;</button>
1118 <h4 class="modal-title"></h4>
1119 </div>
1120 <div class="modal-body next"></div>
1121 <div class="modal-footer">
1122 <button type="button" class="btn btn-default pull-left prev">
1123 <i class="glyphicon glyphicon-chevron-left"></i>
1124 Previous
1125 </button>
1126 <button type="button" class="btn btn-primary next">
1127 Next
1128 <i class="glyphicon glyphicon-chevron-right"></i>
1129 </button>
1130 </div>
1131 </div>
1132 </div>
1133 </div>
1134 </div>
1135 };
1136 }
1137 # end sub html_bootstrap_bluimp
1138  
1139  
1140  
1141  
1142 sub head
1143 {
1144 my $self = shift;
1145
1146 my $out;
1147
1148 my %in = (
1149 -type => "Content-Type: text/html;charset=utf-8\n\n",
1150 -bootstrap => html_bootstrap_css,
1151 -jqueryui => html_jqueryui_css,
1152 -htmlshim => html_shim_respond,
1153 -humanejs => html_humanejs_css,
1154 -title => "$ENV{SERVER_NAME}",
1155 -cssLinks => "https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css,https://blueimp.github.io/Gallery/css/blueimp-gallery.min.css,https://www.a1z.us/A1z/HTML5/Template.css",
1156 -cssCode => "",
1157 -mobilemeta => qq{<meta name="HandheldFriendly" content="true">
1158 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1159 },
1160 -charsetmeta => qq{<meta charset="utf-8">},
1161 -usermeta => "",
1162 -titleRotatingText => qq{text1,text2,text3},
1163 @_,
1164
1165 );
1166  
1167  
1168 # rotating title function and text
1169 my $setTitle;
1170 if ( $in{-titleRotatingText} and $in{-titleRotatingText} =~ /\,/ )
1171 {
1172 my @a;
1173 @a = split(/\,/, $in{-titleRotatingText}, 3);
1174  
1175 $setTitle = html_setTitle(ta => "$a[0]", tb => "$a[1]", tc => "$a[2]");
1176 }
1177 else
1178 {
1179 $setTitle = html_setTitle(ta => "Text01", tb => "text02", tc => "text03");
1180 }
1181  
1182 # css multiple links/files
1183 my $css; my @css;
1184 if ($in{-cssLinks} )
1185 {
1186 if ( $in{-cssLinks} =~ /\,/ )
1187 {
1188 @css = split(/\,/, $in{-cssLinks});
1189 for (@css)
1190 {
1191 if ($_ =~ /\.css$/)
1192 {
1193 $css .= qq{<link type="text/css" rel="stylesheet" href="$_">\n} ;
1194 }
1195 else
1196 {
1197 $css = '';
1198 }
1199 }
1200 }
1201 }
1202 else
1203 {
1204 $css = qq{};
1205 }
1206  
1207  
1208 return qq{$in{-type}<!DOCTYPE html>
1209 <html>
1210 <head>
1211 <title>$in{-title}</title>
1212 $in{-charsetmeta}
1213 $in{-mobilemeta}
1214 $in{-usermeta}
1215 $in{-bootstrap}
1216 $in{-jqueryui}
1217 $in{-htmlshim}
1218 $in{-humanejs}
1219 $css
1220 <style type="text/css">
1221 $in{-cssCode}
1222 </style>
1223  
1224 $setTitle
1225  
1226 </head>
1227 }; # thats orderly
1228  
1229 }
1230 # end head
1231  
1232  
1233  
1234 sub body
1235 {
1236 my $self = shift;
1237
1238 my $out;
1239
1240 my %in;
1241
1242 %in = (
1243 -h1 => qq{$ENV{SERVER_NAME}},
1244 -onload => qq{setTitle();},
1245 -nbhead => qq{},
1246 -nbpage => qq{},
1247 -nbmenu => qq{More},
1248 -defaultjquery => qq{$HTML{-defaultjquery}},
1249 -humanejs => qq{<script src="https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/humane.min.js">},
1250 -userjquery => qq{},
1251 -navbar => html_navbar( $in{-nbmenu}, $in{-nbpage}, "", ""),
1252 -content => qq{<div class="content">Content</div>},
1253 -footer => qq{All rights reserved &copy; $ENV{SERVER_NAME}},
1254 -bootstrapbluimp => html_bootstrap_bluimp,
1255 -nbLinks => qq{contact-help-feedback},
1256 @_,
1257 );
1258
1259 return qq{<body onload="$in{-onload}">
1260 <div id="main" class="container">
1261 <!--top nav bar begin-->
1262 <script type="text/javascript" src="https://www.a1z.us/js/utils/top-nav-bar.js"></script>
1263 <script type="text/javascript">
1264 //<--
1265 fixed_top_navbar('$in{-nbhead}', '$in{-nbpage}', '$in{-nbmenu}', '$in{-nbLinks}');
1266 //-->
1267 </script>
1268  
1269 $in{-bootstrapbluimp}
1270  
1271 $in{-h1}
1272  
1273 $in{-content}
1274
1275 $in{-footer}
1276  
1277 </div>
1278  
1279 $in{-defaultjquery}
1280  
1281 $in{-humanejs}
1282
1283 <script type="text/javascript">
1284 //<!--
1285 $in{-userjquery}
1286 //-->
1287 </script>
1288  
1289 </body>
1290
1291 </html>
1292
1293 };
1294  
1295 }
1296 # end body
1297  
1298  
1299  
1300  
1301  
1302 sub open_file
1303 {
1304 my $self =shift;
1305  
1306  
1307  
1308 my %in;
1309 %in =
1310 (
1311 file => "",
1312
1313 output_header => "",
1314  
1315 output_format => "",
1316  
1317 @_,
1318 );
1319  
1320 my $file = "$in{file}" || "$_[0]";
1321
1322 my $output_format = "$in{output_format}" || "$_[1]";
1323
1324 my $output_header = "$in{output_header}" || "$_[2]";
1325
1326 my $out;
1327  
1328 my $div4tabs;
1329
1330 my @data;
1331
1332 if (-e -f "$file")
1333 {
1334  
1335 open(FILE, "$file") or die "$!";
1336  
1337 $out .= qq{\n<!--begin file output-->\n<div class="file_output">\n};
1338
1339 # Step 1
1340 # set the header as per format
1341 if ($output_format eq 'table')
1342 {
1343 $out .= qq{<table class="table table-striped table-bordered table-hover table-condensed table-responsive">
1344 <thead>
1345 <tr><th colspan="2">$output_header</th></tr>
1346 </thead>
1347 <tbody>
1348 };
1349 }
1350 elsif ($output_format eq 'accordion')
1351 {
1352 $out .= qq{<h2>$output_header</h2>\n<div id="accordion2" class="accordion"><!--118-->\n};
1353 }
1354 elsif ($output_format eq 'menu')
1355 {
1356 $out .= qq{<ul class="menu" id="menu">\n<li><a href="/">$output_header</a>\n<ul>};
1357 }
1358 elsif ($output_format eq 'tabs')
1359 {
1360 # special case for tabs since the data needs to be formatted a little differently
1361
1362 $out .= qq{<h2>$output_header</h2>\n<div id="tabs">\n<ul>\n};
1363
1364 my $sl = '0';
1365
1366 while ( my $line = <FILE>)
1367 {
1368 $sl++ if $line;
1369
1370 my ($h1, $div) = ('');
1371
1372 if ($line =~ /\|/)
1373 {
1374 ($h1, $div) = split(/\|/, $line, 2);
1375 } # no (\|) # i.e., do not enclose with brackets
1376 elsif ($line =~ /\t+/) {
1377 ($h1, $div) = split(/\t+/, $line, 2);
1378 }
1379 elsif ($line =~ /\s+/)
1380 {
1381 ($h1, $div) = split(/\s+/, $line, 2);
1382 }
1383
1384 # Keep only those items that have '==' in the beginning
1385  
1386 if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
1387 {
1388 next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/);
1389 $div =~ s!^\s+==!!g;
1390 $h1 =~ s!^\s+==!!g;
1391 }
1392 else
1393 {
1394 next unless ($h1 =~ /^==/ or $div =~ /^==/);
1395 $div =~ s!^==!!g;
1396 $h1 =~ s!^==!!g;
1397 }
1398
1399 $out .= qq{\t<li><a href="#tabs-$sl">$h1</a></li>\n};
1400  
1401 $div4tabs .= qq{<div id="tabs-$sl">$div</div>};
1402 }
1403 $out .= qq{</ul>\n};
1404  
1405 $out .= $div4tabs;
1406  
1407 close FILE;
1408 }
1409 elsif ($output_format eq 'dialog')
1410 {
1411 $out .= qq{<h2>Dialog: <a href="#opener" id="opener" title="Opens the Dialog">$output_header</a></h2>
1412 <div id="dialog">\n};
1413 }
1414 else
1415 {
1416 $out .= qq{\n<h2>$output_header</h2>\n};
1417 }
1418 # End Step 1
1419
1420 # now work on file
1421
1422 my $serial = '0';
1423
1424 while ( my $line = <FILE> )
1425 {
1426 chomp $line;
1427
1428 $serial++ if $line;
1429
1430 my ($h1, $div) = ('');
1431
1432 if ($line) # make sure no output if line is empty
1433 {
1434 $line =~ s! RN !\r\n!g;
1435
1436 # split the file's lines into usable data according to separator used.
1437 if ($line =~ /\|/)
1438 {
1439 ($h1, $div) = split(/\|/, $line, 2);
1440 } # no (\|) # i.e., no enclosing with brackets. was the culprit
1441 elsif ($line =~ /\t+/) {
1442 ($h1, $div) = split(/\t+/, $line, 2);
1443 }
1444 elsif ($line =~ /\s+/)
1445 {
1446 ($h1, $div) = split(/\s+/, $line, 2);
1447 }
1448 # end split the file's line according to match: 3 options: |, \t+, or \s+
1449  
1450 }
1451
1452 # Step 2
1453 #Now set the content as per output format
1454 if ($output_format eq 'table')
1455 {
1456 # Keep only those items that have a # in the beginning
1457
1458 if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
1459 {
1460 next unless ($h1 =~ /^\s+#/ or $div =~ /^\s+#/);
1461 $div =~ s!^\s+#!!g;
1462 $h1 =~ s!^\s+#!!g;
1463 }
1464 else
1465 {
1466 next unless ($h1 =~ /^#/ or $div =~ /^#/);
1467 $div =~ s!^#!!g;
1468 $h1 =~ s!^#!!g;
1469 }
1470 $out .= qq{\t<tr><td>$h1</td><td>$div</td></tr>\n};
1471 }
1472 elsif ($output_format eq 'accordion')
1473 {
1474 # Keep only those items that have -- in the beginning
1475
1476 if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
1477 {
1478 next unless ($h1 =~ /^\s+--/ or $div =~ /^\s+--/);
1479 $div =~ s!^\s+--!!g;
1480 $h1 =~ s!^\s+--!!g;
1481 }
1482 else
1483 {
1484 next unless ($h1 =~ /^--/ or $div =~ /^--/);
1485 $div =~ s!^--!!g;
1486 $h1 =~ s!^--!!g;
1487 }
1488
1489 $out .= qq{\t<h3>$h1</h3>\n\t<div>$div</div>\n} if $line;
1490 }
1491 elsif ($output_format eq 'menu')
1492 {
1493 # the first item will be used as link title and name
1494 # the second item will be used as the actual link
1495 # no extensions added automatically by the script
1496 # an id for each link/li is also provided in case, may be it is not needed
1497
1498 # Remove items with a # in the beginning; Sat Feb 21 18:48:19 2015
1499 next if ($h1 =~ /^#http/ or $div =~ /^#http/);
1500
1501 # Keep only those items that have a 'http' in the beginning
1502
1503 if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
1504 {
1505 next unless ($h1 =~ /^\s+http/ or $div =~ /^\s+http/);
1506 #$div =~ s!^\s+http!!g;
1507 #$h1 =~ s!^\s+http!!g;
1508 }
1509 else
1510 {
1511 next unless ($h1 =~ /^http/ or $div =~ /^http/);
1512 #$div =~ s!^http!!g;
1513 #$h1 =~ s!^http!!g;
1514 }
1515 $out .= qq{\t<li id="li-$serial"><a id="a-$serial" href="$div" title="$h1">$h1</a></li>\n};
1516 }
1517 elsif ($output_format eq 'tabs')
1518 {
1519 # Keep only those items that have a == in the beginning
1520
1521 if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
1522 {
1523 next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/);
1524 $div =~ s!^\s+==!!g;
1525 $h1 =~ s!^\s+==!!g;
1526 }
1527 else
1528 {
1529 next unless ($h1 =~ /^==/ or $div =~ /^==/);
1530 $div =~ s!^==!!g;
1531 $h1 =~ s!^==!!g;
1532 }
1533
1534 # Mismatching fragment identifier. See 1797.
1535 # $div not available here as <FILE> is not open here.
1536 $out .= qq{\t<div id="tabs-$serial"><p>$div</p></div>\n};
1537
1538 }
1539 elsif ($output_format eq 'dialog')
1540 {
1541 # includes everything; So, no filtering.
1542
1543 # But, just remove symbols in both $h1 and $div
1544 $div =~ s!^(==|\#|--)!!g;
1545 $h1 =~ s!^(==|\#|--)!!g;
1546
1547 $out .= qq{\t\t<h4 class="dialog-header">$h1</h4>\n\t\t<div class="dialog-content">$div <hr/></div>\n};
1548 }
1549 else
1550 {
1551 $out .= qq{$h1 $div}; # or $line
1552 }
1553 }
1554
1555 # add an extra item at the end of file output
1556 #$out .= qq{\t<h3>Powered by Business Impact Solutions</h3>\n\t<div>bislinks.com, bizImpactSolutions.com - Business Impact Solutions</div>\n};
1557
1558 # Step 3
1559 # set the output ending as per format
1560 if ($output_format eq 'table')
1561 {
1562 $out .= qq{\n</tbody>\n</table>\n\n};
1563 }
1564 elsif ($output_format eq 'accordion')
1565 {
1566 $out .= qq{\n<!--end accordion--></div>\n\n};
1567 }
1568 elsif ($output_format eq 'menu')
1569 {
1570 $out .= qq{</ul></ul>};
1571 }
1572 elsif ($output_format eq 'tabs')
1573 {
1574 $out .= qq{</div><!--end tabs-->\n};
1575 }
1576 elsif ($output_format eq 'dialog')
1577 {
1578 $out .= qq{</div><!--end dialog-->\n};
1579 }
1580 else
1581 {
1582 $out .= qq{\n\n};
1583 }
1584
1585 # end file output wrapper
1586 $out .= qq{</div><!--end file output-->\n};
1587
1588 return $out;
1589 }
1590 else
1591 {
1592 my $out;
1593  
1594
1595
1596 $out .= qq{\n<!--begin accord 112-->\n<div id="accordion1460" class="accordion">\n};
1597 while ( my $line = <FILE> )
1598 {
1599 chomp $line;
1600
1601 my ($h1, $div) = ('');
1602
1603 ($h1, $div) = split(/\t+/, $line, 2) if $line;
1604
1605 $out .= qq{\t<h3>$h1</h3>\n\t<div>$div</div>\n} if $line;
1606 }
1607 $out .= qq{\t<h3>Powered by</h3>\n\t<div>Perl/CPAN</div>\n};
1608
1609 $out .= qq{</div>\n<!--end accord-->\n};
1610
1611 return $out;
1612 }
1613  
1614 close FILE;
1615
1616 }
1617 # end open_file
1618  
1619  
1620  
1621  
1622 sub edit_file
1623 {
1624 my $self = shift;
1625
1626 my $out;
1627
1628 my %in;
1629
1630 %in = (
1631 file => "",
1632 error => "",
1633 action => "TemplateAdmin.cgi",
1634 serial => '',
1635 output_type => '',
1636 @_,
1637 );
1638
1639 if (-e -f "$in{file}")
1640 {
1641 open(FILE, "$in{file}") or $in{error} = "unable to open $in{file}";
1642 my @file = <FILE>;
1643 close FILE;
1644
1645 $out .= qq{
1646 <article class="container">
1647
1648 <form action="$in{action}" method="post">
1649 <input type="hidden" name="action" value="write">
1650 };
1651
1652 for (@file)
1653 {
1654 chomp;
1655
1656 next if $_ =~ /^$/;
1657
1658 $in{serial}++ if $_;
1659
1660 my ( $type, $content ) = split(/\|/, $_, 2);
1661
1662 $type =~ s!\s+$!!g;
1663
1664 my $identifiers = substr "$content", 0, 4; # has to be 4 to cover 'http.' Also, assuming no spaces in the beginning (removed by write_file)
1665
1666 # determine output type
1667 if ( $identifiers =~ /^\#/ ) { $in{output_type} = 'Table'; }
1668 elsif ( $identifiers =~ /^\-/ ) { $in{output_type} = 'Accordion'; }
1669 elsif ( $identifiers =~ /^\=/ ) { $in{output_type} = 'Tabs'; }
1670 elsif ( $identifiers =~ /^http/ ) { $in{output_type} = 'Menu'; }
1671 else { $in{output_type} = 'None'; }
1672
1673 # remove all nonmeta characters for web page display
1674 $identifiers =~ s!(\s+|[a-zA-z0-9])!!g; # removes http also.
1675
1676 $content =~ s!\<!&lt\;!g;
1677 $content =~ s!\>!&gt\;!g;
1678
1679 $content =~ s! RN !\r\n!g; # &#13;&#10;
1680
1681 $out .= qq`<div>
1682 <span class="serial">$in{serial} </span>
1683 <span class="type">$type </span>
1684 <span class="identifiers">$identifiers </span>
1685 <span class="type type-$in{output_type}">Type:$in{output_type} </span>
1686 </div>
1687 <div>
1688 <textarea name="ta-$type" id="ta-$type" rows="5" cols="98%" class="type-$in{output_type}">$type , $content</textarea>
1689 </div>
1690 <br/>
1691 `;
1692 }
1693
1694 $out .= qq{<input type='submit' value="Save"></form></article>};
1695
1696
1697 return $out;
1698
1699 }
1700 }
1701  
1702  
1703  
1704 sub write_file
1705 {
1706 my $self = shift;
1707
1708 my $out;
1709
1710 my %in;
1711 %in =
1712 (
1713 file => "",
1714 error => "",
1715 powershell => "C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe ",
1716 @_,
1717 );
1718
1719 my %vars;
1720
1721 use CGI;
1722 my $q = new CGI;
1723 %vars = $q->Vars();
1724
1725 my $action = $q->param('action');
1726
1727 if ( $action eq 'write')
1728 {
1729  
1730 if (-e -f "$in{file}")
1731 {
1732
1733 # First, get file content to backup to another file
1734 open(F, "$in{file}") or $in{error} .= "#1565 Unable to open file for reading. '$!' <br/>";
1735 my @f = <F>;
1736
1737 # save original file content to backup file
1738 open(BAK, ">$in{file},bak.txt") or $in{error} .= "#1570 Unable to create backup file '$in{file},bak.txt' '$!' <br/>";
1739 for (@f)
1740 {
1741 print BAK qq{$_};
1742 }
1743 close BAK;
1744
1745 close F;
1746
1747 # recreate file, thereby deleting original content
1748 open(DEL, ">$in{file}") or $in{error} .= "#1579 Unable to recreate file '$in{file}' '$!' <br/>";
1749 print DEL "File ReCreated";
1750 close DEL;
1751
1752 my %out;
1753 for (keys %vars)
1754 {
1755 chomp $_;
1756 chomp $vars{$_};
1757
1758 next if $_ eq 'action';
1759 my ( $name, $value ) = split(/\,/, $vars{"$_"}, 2);
1760
1761 $name =~ s!(\r\n+|\n+)! RN !g;
1762 $value =~ s!(\r\n+|\n+)! RN !g;
1763
1764 $value =~ s!^\s+!!g;
1765
1766 $out{"$name"} = "$value";
1767 }
1768
1769 # Insert/Add new content
1770 open(FILE, ">$in{file}") or $in{error} .= "#1582 Error writing to file '$in{file}' '$!' <br/>";
1771 for (keys %out)
1772 {
1773 print FILE qq{$_\|$out{$_}\n};
1774 }
1775 close FILE;
1776
1777
1778 if (-e -f "$in{file},bak.txt" and -e -f "$in{file}")
1779 {
1780 return "<div class='success'>Saved</div> <div class='error'>$in{error}</div>";
1781 }
1782 else
1783 {
1784 return "<div>#1605 Error saving file '$in{file}'</div> <div class='error'>$in{error}</div>";
1785 }
1786 }
1787 else
1788 {
1789 return "File not found";
1790 }
1791 }
1792 elsif ( $action eq 'newItem' )
1793 {
1794 return "$action";
1795 }
1796 else
1797 {
1798 return '* ' x 10;
1799 }
1800
1801 }
1802  
1803 # end write_file
1804  
1805  
1806  
1807  
1808 sub display_gallery_thumbnails
1809 {
1810 my $self = shift;
1811  
1812 my $out;
1813  
1814 my %in;
1815  
1816 %in = (
1817
1818 error => "",
1819  
1820 images_dir => "/images/a1z-html5-template/",
1821 thumbs_dir => "/images/a1z-html5-template/thumbs",
1822
1823 images_url => "/images/a1z-html5-template",
1824 thumbs_url => "/thumbs/a1z-html5-template/thumbs",
1825  
1826 width => "100",
1827 height => "100",
1828  
1829 @_,
1830 );
1831  
1832 if (-e -d "$in{images_dir}" and "$in{thumbs_dir}" )
1833 {
1834 opendir(TH, "$in{thumbs_dir}") or $in{error} .= qq{<p>$!</p>};
1835 my @thumbs = readdir(TH);
1836 close TH;
1837  
1838 foreach ( @thumbs )
1839 {
1840 if ( $_ and $_ =~ /(.jpg|.gif|.jpeg|.png|.tiff)$/ )
1841 {
1842 $out .= qq{\n<a href="$in{images_url}/$_" title="$_" data-gallery> <img src="$in{thumbs_url}/$_" alt="Image $_" width="$in{width}" height="$in{height}"> </a> \n};
1843 }
1844 }
1845 }
1846 else
1847 {
1848 $in{error} .= qq{<p>Image directory does not exist or is inaccessible. Make sure you provided the correct path.</p>};
1849  
1850 $out = $in{error};
1851 }
1852  
1853 return $out;
1854 }
1855 # end display gallery thumbnails
1856  
1857  
1858  
1859  
1860  
1861  
1862  
1863  
1864  
1865 1;
1866  
1867 __END__