File Coverage

blib/lib/A1z/HTML5/Template.pm
Criterion Covered Total %
statement 53 482 11.0
branch 4 250 1.6
condition 1 126 0.7
subroutine 16 41 39.0
pod 32 36 88.8
total 106 935 11.3


line stmt bran cond sub pod time code
1             package A1z::HTML5::Template;
2 2     2   113945 use strict;
  2         13  
  2         48  
3 2     2   9 use warnings;
  2         3  
  2         99  
4 2     2   11 use vars qw($NAME);
  2         3  
  2         234  
5              
6             # ABSTRACT: Fast and Easy Web Apps
7              
8 1     1 0 638 sub NAME { my $self = shift; $NAME = "Fast and Easy Web Apps"; return $NAME; }
  1         3  
  1         3  
9              
10             our $VERSION = '0.22';
11              
12 2     2   740 use parent qw(Exporter);
  2         449  
  2         9  
13             require Exporter;
14             our @ISA = ("Exporter");
15              
16             our @EXPORT_OK = qw(header start_html head_title head_meta head_js_css end_head begin_body body_js_css body_topnavbar
17             body_accordion end_body end_html head body
18             );
19              
20              
21              
22             sub new {
23 1     1 1 67 my $class = shift;
24 1         4 my $self = bless { @_ }, $class;
25 1         3 return $self;
26             }
27              
28              
29             sub math1
30             {
31 0     0 1 0 my $self = shift;
32            
33 0         0 my ($num1, $num2) = @_;
34            
35 0 0       0 if ($num1 eq '') { $num1 = '2'; }
  0         0  
36 0 0       0 if ($num2 eq '') { $num2 = '4'; }
  0         0  
37            
38 0         0 my $out;
39            
40 0         0 my $m = $num1 * $num2;
41 0         0 my $a = $num1 + $num2;
42 0         0 my $s = $num1 - $num2;
43 0         0 my $s1 = $num2 - $num1;
44 0         0 my $d = $num1 / $num2;
45 0         0 my $d1 = $num2 / $num1;
46            
47 0         0 $out .= qq{
48            
49            
50            
Multiplication
51            
52            
53             $num1
54             x
55             $num2
56             \=
57             $m
58            
59            
60            
Addition
61            
$num1 \+ $num2 \= $a
62            
63            
Subtraction
64            
$num1 \- $num2 \= $s
65            
$num2 \- $num1 \= $s1
66            
67            
Division
68            
$num1 \/ $num2 \= $d
69            
$num2 \/ $num1 \= $d1
70            
71            
72            
73             };
74              
75 0         0 return qq{\n$out\n};
76             }
77              
78              
79              
80             # begin timestable
81             sub timestable
82             {
83 0     0 1 0 my $self = shift;
84            
85 0         0 my ($num1) = @_;
86            
87 0 0       0 if ( $num1 eq '' ) { $num1 = '2'; }
  0         0  
88            
89 0         0 my $out;
90            
91 0         0 $out .= qq{}; } if ($_);
92            
93 0         0 for ('1'..'20')
94             {
95 0 0       0 $out .= qq{
$num1 x $_ = } . $num1 * $_ . qq{
96             }
97 0         0 $out .= qq{
};
98            
99 0         0 return $out;
100             }
101             # end timestable
102              
103              
104              
105             # begin header
106             sub header
107             {
108 0     0 1 0 my $self = shift;
109            
110 0         0 my @keys;
111 0 0       0 if (@_) { @keys = @_; }
  0         0  
112            
113 0         0 my $args = scalar(@keys);
114            
115 0         0 my ($key, $key1) = @_;
116            
117 0         0 my %out;
118            
119 0 0 0     0 if ($ARGV and $ARGV > 0 and scalar(@keys) > 0)
      0        
120             {
121 0 0 0     0 if ($key eq 'utf8')
    0          
122             {
123 0         0 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
124            
125             }
126             elsif (!defined $key or $key eq '')
127             {
128 0         0 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
129             }
130             else
131             {
132 0         0 $out{"$key"} = qq{Content-Type: text/html;charset=utf-8\n\n};
133             }
134             }
135             else
136             {
137 0         0 return qq{Content-Type: text/html;charset=utf-8\n\n};
138             }
139            
140             }
141             # end header
142              
143              
144              
145             # begin start html 01
146             sub start_html
147             {
148 0     0 1 0 my $self = shift;
149            
150 0         0 my @keys;
151 0 0       0 if (@_) { @keys = @_; }
  0         0  
152            
153 0         0 my $args = scalar @keys;
154            
155 0         0 my ($key, $key1) = @_;
156            
157 0         0 my %out;
158            
159 0 0 0     0 if ($args and $args >= 0)
160             {
161             # have your own custom header, backwards compatibility
162            
163 0         0 my $out;
164            
165 0         0 $out .= qq{@_ };
166            
167 0         0 return $out;
168            
169             }
170             else
171             {
172 0         0 my $out;
173            
174 0         0 $out .= qq{\n\n};
175 0         0 $out .= qq{\n};
176            
177 0         0 return $out;
178            
179             }
180             }
181             # end start_html
182              
183              
184              
185              
186             sub body_js_css
187             {
188 0     0 1 0 my $self = shift;
189            
190 0         0 my $key = "@_";
191            
192 0         0 my @keys;
193 0 0       0 if (@_) { @keys = @_; }
  0         0  
194            
195 0         0 my $args = scalar (@keys);
196            
197 0         0 my $out;
198            
199 0         0 $out .= qq^
200            
201            
202            
203            
204            
205              
206            
207            
208              
209            
247            
248             ^;
249            
250            
251 0 0       0 if ( $args )
252             {
253            
254 0 0       0 if ( $args >= 0)
255             {
256 0         0 my $return;
257            
258 0         0 for (@keys )
259             {
260 0         0 chomp;
261 0 0       0 if ($_ =~ /.js$/)
    0          
262             {
263 0         0 $return .= qq{\n};
264             }
265             elsif ($_ =~ /.css$/)
266             {
267 0         0 $return .= qq{\n};
268             }
269             else
270             {
271             # do nothing
272             }
273             }
274            
275 0         0 return qq{$return}; #
276             }
277             else
278             {
279 0         0 return qq{$out};
280             }
281            
282             }
283             else
284             {
285 0         0 return qq{$out}; #
286             }
287            
288             }
289              
290              
291              
292              
293              
294             # start end_html
295             sub end_html
296             {
297 0     0 1 0 my $self = shift;
298            
299 0         0 my @keys;
300 0 0       0 if (@_) { @keys = @_; }
  0         0  
301            
302 0         0 my ($key, $key1) = @_;
303            
304 0         0 my $out;
305            
306 0         0 $out .= qq{\n\n};
307            
308 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
309             {
310 0         0 return qq{@_};
311             }
312             else
313             {
314 0         0 return $out;
315             }
316             }
317             # end end_html
318              
319              
320              
321              
322             # start head title 02
323             sub head_title
324             {
325 0     0 1 0 my $self = shift;
326            
327 0         0 my $key = "@_";
328            
329 0         0 my @keys;
330 0 0       0 if (@_) { @keys = @_; }
  0         0  
331            
332 0         0 my $out;
333            
334 0         0 $out .= qq{};
335            
336 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
337             {
338            
339 0 0       0 if ($key)
340             {
341 0         0 return qq{@_\n};
342             }
343             else
344             {
345 0         0 return qq{Template\n};
346             }
347            
348             }
349             else
350             {
351 0         0 return qq{Package Html5\n}; # this works but does not ask the user
352             }
353            
354             }
355             # end head title
356              
357              
358              
359              
360             # begin head meta 03
361             sub head_meta
362             {
363 0     0 1 0 my $self = shift;
364            
365 0         0 my $key = "@_";
366            
367 0         0 my @keys;
368 0 0       0 if (@_) { @keys = @_; }
  0         0  
369            
370 0         0 my $args = scalar @keys;
371            
372 0         0 my $out;
373            
374 0         0 $out .= qq{
375            
376            
377            
378            
379             };
380            
381 0 0       0 if ($args)
382             {
383            
384 0 0       0 if ($args >= 0)
385             {
386 0         0 my $return;
387            
388 0         0 for (@keys )
389             {
390 0         0 chomp;
391            
392 0         0 my ( $meta_name, $meta_cont) = split(/---/, $_, 2);
393            
394 0         0 $return .= qq{\n};
395             }
396            
397 0         0 return qq{$return};
398             }
399             else
400             {
401 0         0 $out .= qq{};
402             # add default meta if user has not called one of his own
403 0         0 return qq{$out};
404             }
405            
406             }
407             else
408             {
409 0         0 return qq{$out}; # this works but does not ask the user
410             }
411            
412             }
413             # end head meta 03
414              
415              
416              
417              
418             # begin body top nav bar
419             sub body_topnavbar
420             {
421 0     0 1 0 my $self = shift;
422            
423 0         0 my %in;
424            
425 0         0 %in = (
426             file => "https://www.a1z.us/js/utils/top-nav-bar.js",
427             name => "Menu",
428             @_,
429             );
430            
431 0         0 my $out;
432            
433 0         0 $out .= qq{
434            
435            
438            
439             };
440            
441 0         0 return qq{$out\n}; # this works but does not ask the user
442            
443             }
444             # end body top nav bar
445              
446              
447              
448              
449             sub head_js_css
450             {
451 0     0 1 0 my $self = shift;
452            
453 0         0 my $key = "@_";
454            
455 0         0 my @keys;
456 0 0       0 if (@_) { @keys = @_; }
  0         0  
457            
458 0         0 my $args = scalar (@keys);
459            
460 0         0 my $out;
461            
462 0         0 $out .= qq{
463            
464            
465              
466            
467            
468            
469              
470            
471              
472            
476              
477             };
478            
479 0 0       0 if ($args)
480             {
481            
482 0 0       0 if ($args >= 0)
483             {
484 0         0 my $return;
485            
486 0         0 for (@keys)
487             {
488 0         0 chomp;
489 0 0       0 if ($_ =~ /.js$/)
    0          
490             {
491 0         0 $return .= qq{ \n \n};
492             }
493             elsif ($_ =~ /.css$/)
494             {
495 0         0 $return .= qq{ \n \n};
496             }
497             else
498             {
499             # do nothing
500 0         0 return qq{@keys\n};
501             }
502             }
503            
504 0         0 return qq{$return\n};
505             }
506             else
507             {
508 0         0 return qq{$out\n};
509             }
510            
511             }
512             else
513             {
514 0         0 return qq{$out\n}; # this works but does not ask the user
515             }
516            
517             }
518             # end head js css
519              
520              
521              
522              
523             # begin end head
524             sub end_head
525             {
526 0     0 1 0 my $self = shift;
527            
528 0         0 my $key = "@_";
529            
530 0         0 my @keys;
531 0 0       0 if (@_) { @keys = @_; }
  0         0  
532            
533 0         0 my $out;
534            
535 0         0 $out .= qq{};
536            
537 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
538             {
539            
540 0 0       0 if (@_)
541             {
542 0         0 return qq{@_\n};
543             }
544             else
545             {
546 0         0 return qq{$out\n};
547             }
548            
549             }
550             else
551             {
552 0         0 return qq{$out\n}; # this works but does not ask the user
553             }
554             }
555             # end end head
556              
557              
558              
559             # begin begin body
560             sub begin_body
561             {
562 0     0 1 0 my $self = shift;
563            
564 0         0 my $key = "@_";
565            
566 0         0 my @keys;
567 0 0       0 if (@_) { @keys = @_; }
  0         0  
568            
569 0         0 my $out;
570            
571 0         0 $out .= qq{};
572            
573 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
574             {
575            
576 0 0       0 if (@_)
577             {
578 0         0 return qq{@_\n};
579             }
580             else
581             {
582 0         0 return qq{$out\n};
583             }
584            
585             }
586             else
587             {
588 0         0 return qq{$out\n}; # this works but does not ask the user
589             }
590             }
591             # end begin body
592              
593              
594              
595             # begin accordion or rather file content. Need to change name of this method
596             sub body_accordion
597             {
598 0     0 1 0 my $self = shift;
599            
600 0         0 my $key = "@_";
601            
602 0         0 my @keys;
603 0 0       0 if (@_) { @keys = @_; }
  0         0  
604            
605 0         0 my $out;
606            
607 0         0 $out .= qq{
608            
609            

Who is it for

610            
For those who know/uderstand Perl/HTML/jQuery
611            

What about a bigger number?

612            
Sure. Use the custom form to get the times table for a number greater than 30?
613            

How about any number/range?

614            
Yes, of course! Once again, use the custom form bearing the heading "Or enter your own"
615            

Can I customize it for own use?

616            
In that case, you need to purchase the software and/or order a customization
617            
618              
619            
620              
621             };
622            
623 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
624             {
625            
626 0 0       0 if (@_)
627             {
628 0         0 return qq{\n@_\n};
629             }
630             else
631             {
632 0         0 return qq{\n$out\n};
633             }
634            
635             }
636             else
637             {
638 0         0 return qq{\n$out\n}; #
639             }
640             }
641             # end accordion
642              
643              
644              
645              
646             sub body_article
647             {
648 0     0 1 0 my $self = shift;
649            
650 0         0 my $out;
651            
652             my %in;
653 0         0 %in =
654             (
655             content => "",
656             type => "article",
657             header => "Content Header",
658             @_,
659             );
660            
661 0 0 0     0 if ( !defined $in{content} or $in{content} eq '' )
662             {
663 0         0 return qq{
664             No Content
665             };
666             }
667             else
668             {
669 0         0 return qq{

$in{header}

670             $in{content}
671            
672             };
673             }
674             }
675              
676              
677              
678              
679             # begin begin body
680             sub end_body
681             {
682 0     0 1 0 my $self = shift;
683            
684 0         0 my $key = "@_";
685            
686 0         0 my @keys;
687 0 0       0 if (@_) { @keys = @_; }
  0         0  
688            
689 0         0 my $out;
690            
691 0         0 $out .= qq{\n\n};
692            
693 0 0 0     0 if ($ARGV and $ARGV > 0 or scalar(@keys) > 0)
      0        
694             {
695            
696 0 0       0 if (@_)
697             {
698 0         0 return qq{@_\n};
699             }
700             else
701             {
702 0         0 return qq{$out\n};
703             }
704            
705             }
706             else
707             {
708 0         0 return qq{$out\n}; # this works but does not ask the user
709             }
710             }
711             # end end body
712              
713              
714              
715              
716              
717             # begin content folder to select form
718             sub body_form
719             {
720 0     0 1 0 my $self = shift;
721            
722 0         0 my $out;
723            
724             my @keys;
725 0 0       0 if (@_) { @keys = @_; }
  0         0  
726            
727 0         0 my ($vars, $vals) = ('');
728 0         0 for (@keys)
729             {
730 0 0       0 $vars = $_ if ($_ =~ /^vars/);
731              
732             # $vals not used
733 0 0       0 $vals = $_ if ($_ =~ /^vals/);
734             }
735            
736 0         0 my @form_vars = split(/\;/, $vars);
737            
738 0         0 my @form_vals = split(/\;/, $vals);
739            
740             # get params for hidden fields if given
741 0         0 my @hidden;
742 0 0 0     0 if ($form_vars[4] and $form_vars[4] =~ /\,/)
743             {
744 0         0 @hidden = split(/\,/, $form_vars[4]);
745             }
746             else
747             {
748 0         0 @hidden = ("No", "Vals");
749             }
750            
751             # if SELECT ....
752            
753 0         0 my $select;
754            
755 0 0 0     0 if ($form_vars[3] and $form_vars[3] =~ /^select/)
756             {
757             # get the params for the form
758             # select,
759 0         0 my ($sel_key, $sel_name, $sel_default, $folder_or_file, $selectLabelText) = split(/\,/, $form_vars[3], 5);
760              
761 0         0 $select .= qq{
762            
763            
764             \t
765             \t\t
766             };
767            
768             #now open file/folder to fill "options"
769 0 0       0 if ( -f $folder_or_file )
    0          
770             {
771             # open as file
772             #$select .= qq{none};
773             }
774             elsif (-d $folder_or_file)
775             {
776             # open as dir and add all files in it to "options"
777 0 0       0 opendir(D, "$folder_or_file") or $select .= qq{
$!
};
778 0         0 my @DIR = readdir(D);
779            
780 0         0 while ( my $file = )
781             {
782             # only if file contains alphabets, numbers, and dashes
783 0 0       0 next unless $file =~ /[a-zA-Z0-9\-]/;
784              
785             # comment if you want subfolders also listed
786 0 0       0 next unless -f "$folder_or_file/$file";
787              
788             # get rid of . and ..
789 0 0       0 next if $file =~ /^(\.|\.\.)/;
790              
791             # do not add hidden files to the options list
792 0 0       0 next if $file =~ /^\./;
793            
794             # get the size of th file
795 0         0 my $size = -s "$folder_or_file/$file";
796 0         0 my $original = $size;
797 0         0 $size /= 1024;
798             #$size /= 1024;
799 0         0 $size = sprintf "%.2f", $size;
800 0 0       0 $select .= qq{\n\t\t\t} if $file;
801             }
802              
803 0         0 close D;
804             }
805              
806 0         0 $select .= qq{\n\t\t\n\t\n};
807             }
808             else
809             {
810             # no select
811 0         0 $select .= qq{};
812             }
813            
814            
815 0         0 $out .= qq{
};
816            
817             # add hidden fields/values # from $form_vars[4]
818 0         0 for (@hidden)
819             {
820 0 0       0 my ($name, $value) = split(/\-\-\-/, $_, 2) if $_;
821 0 0       0 $out .= qq{\n\t} if $_;
822             }
823             # add select
824 0         0 $out .= qq{$select};
825 0         0 $out .= qq{\n\t\n\n};
826            
827 0         0 return qq{
$out
};
828             }
829              
830             # end body_form
831              
832              
833              
834             sub defaults_begin
835             {
836 0     0 1 0 my $self = shift;
837            
838 0         0 my $out;
839            
840 0         0 $out .= sprintf header(),
841             start_html(),
842             head_title("$_[0]"),
843             head_meta(),
844             head_meta("$_[1]"),
845             head_js_css(),
846             head_js_css("$_[2]"),
847             end_head(),
848             begin_body(),
849             body_topnavbar()
850             ;
851            
852 0         0 return $out;
853             }
854              
855              
856              
857             sub defaults_end
858             {
859 0     0 1 0 my $self = shift;
860            
861 0         0 my $out;
862            
863 0         0 $out .= sprintf body_js_css(),
864             body_js_css("$_[0]"),
865             end_body(),
866             end_html()
867             ;
868            
869 0         0 return $out;
870             }
871              
872              
873              
874             # HTML
875             my %HTML;
876              
877             %HTML = (
878             -defaultjquery => qq{\n
879              
880            
881            
882              
883            
884            
885              
886            
887            
888              
889            
890            
891              
892            
893            
894            
935             },
936            
937             -default_LastItem => qq{},
938            
939             );
940              
941              
942             sub html_bootstrap_css
943             {
944 1     1 1 4 return qq{
945            
946            
947             };
948            
949             }
950              
951              
952              
953              
954             sub html_jqueryui_css
955             {
956             # jquery ui theme jquery-ui.css #1.12.0
957 1     1 1 3 return qq{};
958             }
959              
960              
961              
962              
963             sub html_shim_respond
964             {
965 1     1 1 2 return qq{
966            
970             };
971              
972             }
973              
974              
975              
976             sub html_navbar
977             {
978             #my $self = shift;
979              
980             #serverName, pageName, menuName, dropDownLinks
981            
982 1     1 1 2 my %in;
983 1         26 %in = (
984             -nbMenuName => "",
985             -nbPageName => "",
986             -nbServer => "",
987             -nbLinks => "blog-support-help-contact-sale",
988             @_,
989             );
990            
991 1         11 return qq{
992            
993            
998            
999             };
1000              
1001             }
1002              
1003              
1004            
1005              
1006             sub html_bootstrap_js
1007             {
1008             # jquery:3.3.0 ui:1/12/1
1009              
1010 0     0 1 0 return qq{
1011            
1012              
1013             };
1014              
1015             }
1016              
1017             sub html_js_css
1018       0 0   {
1019            
1020             }
1021              
1022             sub html_jquery
1023       0 0   {
1024            
1025             }
1026              
1027              
1028              
1029             sub html_setTitle
1030             {
1031 1     1 1 2 my $out;
1032              
1033             my %in;
1034            
1035 1         5 %in = (
1036             ta => qq{},
1037             tb => qq{},
1038             tc => qq{},
1039             @_,
1040             );
1041              
1042 1         5 $out .= qq{
1061             };
1062              
1063 1         3 return $out;
1064             }
1065              
1066              
1067              
1068              
1069             sub html_humanejs_css
1070             {
1071 1     1 1 10 return qq{
1072            
1073            
1074            
1075            
1076            
1077            
1078            
1079            
1080             };
1081              
1082             }
1083              
1084              
1085              
1086              
1087             sub html_bootstrap_bluimp
1088             {
1089 1     1 1 8 return qq{
1090            
1091            
1092            
1093            
1094            

1095            
1096            
1097             ×
1098            
1099            
    1100            
    1101            
    1102            
    1103            
    1104            
    1105            
    1106            
    1107            
    1108            
    1109            
    1110            
    1111            
    1112             Previous
    1113            
    1114            
    1115             Next
    1116            
    1117            
    1118            
    1119            
    1120            
    1121            
    1122            
    1123             };
    1124             }
    1125             # end sub html_bootstrap_bluimp
    1126              
    1127              
    1128              
    1129              
    1130             sub head
    1131             {
    1132 1     1 1 3 my $self = shift;
    1133            
    1134 1         1 my $out;
    1135            
    1136 1         6 my %in = (
    1137             -type => "Content-Type: text/html;charset=utf-8\n\n",
    1138             -bootstrap => html_bootstrap_css,
    1139             -jqueryui => html_jqueryui_css,
    1140             -htmlshim => html_shim_respond,
    1141             -humanejs => html_humanejs_css,
    1142             -title => "A1Z .us",
    1143             -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",
    1144             -cssCode => "",
    1145             -mobilemeta => qq{
    1146            
    1147             },
    1148             -charsetmeta => qq{},
    1149             -usermeta => "",
    1150             -titleRotatingText => qq{text1,text2,text3},
    1151             @_,
    1152            
    1153             );
    1154              
    1155              
    1156             # rotating title function and text
    1157 1         11 my $setTitle;
    1158 1 50 33     12 if ( $in{-titleRotatingText} and $in{-titleRotatingText} =~ /\,/ )
    1159             {
    1160 1         2 my @a;
    1161 1         4 @a = split(/\,/, $in{-titleRotatingText}, 3);
    1162              
    1163 1         4 $setTitle = html_setTitle(ta => "$a[0]", tb => "$a[1]", tc => "$a[2]");
    1164             }
    1165             else
    1166             {
    1167 0         0 $setTitle = html_setTitle(ta => "Text01", tb => "text02", tc => "text03");
    1168             }
    1169              
    1170             # css multiple links/files
    1171 1         2 my $css; my @css;
    1172 1 50       3 if ($in{-cssLinks} )
    1173             {
    1174 1 50       4 if ( $in{-cssLinks} =~ /\,/ )
    1175             {
    1176 1         3 @css = split(/\,/, $in{-cssLinks});
    1177 1         2 for (@css)
    1178             {
    1179 3 50       9 if ($_ =~ /\.css$/)
    1180             {
    1181 3         7 $css .= qq{\n} ;
    1182             }
    1183             else
    1184             {
    1185 0         0 $css = '';
    1186             }
    1187             }
    1188             }
    1189             }
    1190             else
    1191             {
    1192 0         0 $css = qq{};
    1193             }
    1194              
    1195              
    1196 1         27 return qq{$in{-type}
    1197            
    1198            
    1199             $in{-title}
    1200             $in{-charsetmeta}
    1201             $in{-mobilemeta}
    1202             $in{-usermeta}
    1203             $in{-bootstrap}
    1204             $in{-jqueryui}
    1205             $in{-htmlshim}
    1206             $in{-humanejs}
    1207             $css
    1208            
    1211              
    1212             $setTitle
    1213              
    1214            
    1215             }; # thats orderly
    1216              
    1217             }
    1218             # end head
    1219              
    1220              
    1221              
    1222             sub body
    1223             {
    1224 1     1 1 3 my $self = shift;
    1225            
    1226 1         2 my $out;
    1227            
    1228             my %in;
    1229            
    1230             %in = (
    1231             -h1 => qq{A1Z .us},
    1232             -onload => qq{setTitle();},
    1233             -nbhead => qq{},
    1234             -nbpage => qq{},
    1235             -nbmenu => qq{More},
    1236             -defaultjquery => qq{$HTML{-defaultjquery}},
    1237             -humanejs => qq{
    1251            
    1256              
    1257             $in{-bootstrapbluimp}
    1258              
    1259             $in{-h1}
    1260              
    1261             $in{-content}
    1262            
    1263             $in{-footer}
    1264              
    1265            
    1266              
    1267             $in{-defaultjquery}
    1268              
    1269             $in{-humanejs}
    1270            
    1271            
    1276              
    1277            
    1278            
    1279            
    1280            
    1281             };
    1282              
    1283             }
    1284             # end body
    1285              
    1286              
    1287              
    1288              
    1289              
    1290             sub open_file
    1291             {
    1292 0     0 0   my $self =shift;
    1293              
    1294              
    1295              
    1296 0           my %in;
    1297 0           %in =
    1298             (
    1299             file => "",
    1300            
    1301             output_header => "",
    1302              
    1303             output_format => "",
    1304              
    1305             @_,
    1306             );
    1307              
    1308 0   0       my $file = "$in{file}" || "$_[0]";
    1309            
    1310 0   0       my $output_format = "$in{output_format}" || "$_[1]";
    1311            
    1312 0   0       my $output_header = "$in{output_header}" || "$_[2]";
    1313            
    1314 0           my $out;
    1315              
    1316             my $div4tabs;
    1317            
    1318 0           my @data;
    1319            
    1320 0 0         if (-e -f "$file")
    1321             {
    1322              
    1323 0 0         open(FILE, "$file") or die "$!";
    1324              
    1325 0           $out .= qq{\n\n
    \n};
    1326            
    1327             # Step 1
    1328             # set the header as per format
    1329 0 0         if ($output_format eq 'table')
        0          
        0          
        0          
        0          
    1330             {
    1331 0           $out .= qq{\n}; \n
    1332            
    1333            
    $output_header
    1334            
    1335            
    1336             };
    1337             }
    1338             elsif ($output_format eq 'accordion')
    1339             {
    1340 0           $out .= qq{

    $output_header

    \n
    \n};
    1341             }
    1342             elsif ($output_format eq 'menu')
    1343             {
    1344 0           $out .= qq{
    1345             }
    1346             elsif ($output_format eq 'tabs')
    1347             {
    1348             # special case for tabs since the data needs to be formatted a little differently
    1349            
    1350 0           $out .= qq{

    $output_header

    \n
    \n
      \n};
    1351            
    1352 0           my $sl = '0';
    1353            
    1354 0           while ( my $line = )
    1355             {
    1356 0 0         $sl++ if $line;
    1357            
    1358 0           my ($h1, $div) = ('');
    1359            
    1360 0 0         if ($line =~ /\|/)
        0          
        0          
    1361             {
    1362 0           ($h1, $div) = split(/\|/, $line, 2);
    1363             } # no (\|) # i.e., do not enclose with brackets
    1364             elsif ($line =~ /\t+/) {
    1365 0           ($h1, $div) = split(/\t+/, $line, 2);
    1366             }
    1367             elsif ($line =~ /\s+/)
    1368             {
    1369 0           ($h1, $div) = split(/\s+/, $line, 2);
    1370             }
    1371            
    1372             # Keep only those items that have '==' in the beginning
    1373              
    1374 0 0 0       if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
    1375             {
    1376 0 0 0       next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/);
    1377 0           $div =~ s!^\s+==!!g;
    1378 0           $h1 =~ s!^\s+==!!g;
    1379             }
    1380             else
    1381             {
    1382 0 0 0       next unless ($h1 =~ /^==/ or $div =~ /^==/);
    1383 0           $div =~ s!^==!!g;
    1384 0           $h1 =~ s!^==!!g;
    1385             }
    1386            
    1387 0           $out .= qq{\t
  1. $h1
  2. \n};
    1388              
    1389 0           $div4tabs .= qq{
    $div
    };
    1390             }
    1391 0           $out .= qq{\n};
    1392              
    1393 0           $out .= $div4tabs;
    1394              
    1395 0           close FILE;
    1396             }
    1397             elsif ($output_format eq 'dialog')
    1398             {
    1399 0           $out .= qq{

    Dialog: $output_header

    1400            
    \n};
    1401             }
    1402             else
    1403             {
    1404 0           $out .= qq{\n

    $output_header

    \n};
    1405             }
    1406             # End Step 1
    1407            
    1408             # now work on file
    1409            
    1410 0           my $serial = '0';
    1411            
    1412 0           while ( my $line = )
    1413             {
    1414 0           chomp $line;
    1415            
    1416 0 0         $serial++ if $line;
    1417            
    1418 0           my ($h1, $div) = ('');
    1419            
    1420 0 0         if ($line) # make sure no output if line is empty
    1421             {
    1422 0           $line =~ s! RN !\r\n!g;
    1423            
    1424             # split the file's lines into usable data according to separator used.
    1425 0 0         if ($line =~ /\|/)
        0          
        0          
    1426             {
    1427 0           ($h1, $div) = split(/\|/, $line, 2);
    1428             } # no (\|) # i.e., no enclosing with brackets. was the culprit
    1429             elsif ($line =~ /\t+/) {
    1430 0           ($h1, $div) = split(/\t+/, $line, 2);
    1431             }
    1432             elsif ($line =~ /\s+/)
    1433             {
    1434 0           ($h1, $div) = split(/\s+/, $line, 2);
    1435             }
    1436             # end split the file's line according to match: 3 options: |, \t+, or \s+
    1437              
    1438             }
    1439            
    1440             # Step 2
    1441             #Now set the content as per output format
    1442 0 0         if ($output_format eq 'table')
        0          
        0          
        0          
        0          
    1443             {
    1444             # Keep only those items that have a # in the beginning
    1445            
    1446 0 0 0       if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
    1447             {
    1448 0 0 0       next unless ($h1 =~ /^\s+#/ or $div =~ /^\s+#/);
    1449 0           $div =~ s!^\s+#!!g;
    1450 0           $h1 =~ s!^\s+#!!g;
    1451             }
    1452             else
    1453             {
    1454 0 0 0       next unless ($h1 =~ /^#/ or $div =~ /^#/);
    1455 0           $div =~ s!^#!!g;
    1456 0           $h1 =~ s!^#!!g;
    1457             }
    1458 0           $out .= qq{\t
    $h1$div
    1459             }
    1460             elsif ($output_format eq 'accordion')
    1461             {
    1462             # Keep only those items that have -- in the beginning
    1463            
    1464 0 0 0       if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
    1465             {
    1466 0 0 0       next unless ($h1 =~ /^\s+--/ or $div =~ /^\s+--/);
    1467 0           $div =~ s!^\s+--!!g;
    1468 0           $h1 =~ s!^\s+--!!g;
    1469             }
    1470             else
    1471             {
    1472 0 0 0       next unless ($h1 =~ /^--/ or $div =~ /^--/);
    1473 0           $div =~ s!^--!!g;
    1474 0           $h1 =~ s!^--!!g;
    1475             }
    1476            
    1477 0 0         $out .= qq{\t

    $h1

    \n\t
    $div
    \n} if $line;
    1478             }
    1479             elsif ($output_format eq 'menu')
    1480             {
    1481             # the first item will be used as link title and name
    1482             # the second item will be used as the actual link
    1483             # no extensions added automatically by the script
    1484             # an id for each link/li is also provided in case, may be it is not needed
    1485            
    1486             # Remove items with a # in the beginning; Sat Feb 21 18:48:19 2015
    1487 0 0 0       next if ($h1 =~ /^#http/ or $div =~ /^#http/);
    1488            
    1489             # Keep only those items that have a 'http' in the beginning
    1490            
    1491 0 0 0       if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
    1492             {
    1493 0 0 0       next unless ($h1 =~ /^\s+http/ or $div =~ /^\s+http/);
    1494             #$div =~ s!^\s+http!!g;
    1495             #$h1 =~ s!^\s+http!!g;
    1496             }
    1497             else
    1498             {
    1499 0 0 0       next unless ($h1 =~ /^http/ or $div =~ /^http/);
    1500             #$div =~ s!^http!!g;
    1501             #$h1 =~ s!^http!!g;
    1502             }
    1503 0           $out .= qq{\t
  3. $h1
  4. \n};
    1504             }
    1505             elsif ($output_format eq 'tabs')
    1506             {
    1507             # Keep only those items that have a == in the beginning
    1508            
    1509 0 0 0       if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ )
    1510             {
    1511 0 0 0       next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/);
    1512 0           $div =~ s!^\s+==!!g;
    1513 0           $h1 =~ s!^\s+==!!g;
    1514             }
    1515             else
    1516             {
    1517 0 0 0       next unless ($h1 =~ /^==/ or $div =~ /^==/);
    1518 0           $div =~ s!^==!!g;
    1519 0           $h1 =~ s!^==!!g;
    1520             }
    1521            
    1522             # Mismatching fragment identifier. See 1797.
    1523             # $div not available here as is not open here.
    1524 0           $out .= qq{\t

    $div

    \n};
    1525            
    1526             }
    1527             elsif ($output_format eq 'dialog')
    1528             {
    1529             # includes everything; So, no filtering.
    1530            
    1531             # But, just remove symbols in both $h1 and $div
    1532 0           $div =~ s!^(==|\#|--)!!g;
    1533 0           $h1 =~ s!^(==|\#|--)!!g;
    1534            
    1535 0           $out .= qq{\t\t

    $h1

    \n\t\t
    $div
    \n};
    1536             }
    1537             else
    1538             {
    1539 0           $out .= qq{$h1 $div}; # or $line
    1540             }
    1541             }
    1542            
    1543             # add an extra item at the end of file output
    1544            
    1545             # Step 3
    1546             # set the output ending as per format
    1547 0 0         if ($output_format eq 'table')
        0          
        0          
        0          
        0          
    1548             {
    1549 0           $out .= qq{\n
    \n\n};
    1550             }
    1551             elsif ($output_format eq 'accordion')
    1552             {
    1553 0           $out .= qq{\n\n\n};
    1554             }
    1555             elsif ($output_format eq 'menu')
    1556             {
    1557 0           $out .= qq{};
    1558             }
    1559             elsif ($output_format eq 'tabs')
    1560             {
    1561 0           $out .= qq{\n};
    1562             }
    1563             elsif ($output_format eq 'dialog')
    1564             {
    1565 0           $out .= qq{\n};
    1566             }
    1567             else
    1568             {
    1569 0           $out .= qq{\n\n};
    1570             }
    1571            
    1572             # end file output wrapper
    1573 0           $out .= qq{\n};
    1574            
    1575 0           return $out;
    1576             }
    1577             else
    1578             {
    1579 0           my $out;
    1580              
    1581            
    1582            
    1583 0           $out .= qq{\n\n
    \n};
    1584 0           while ( my $line = )
    1585             {
    1586 0           chomp $line;
    1587            
    1588 0           my ($h1, $div) = ('');
    1589            
    1590 0 0         ($h1, $div) = split(/\t+/, $line, 2) if $line;
    1591            
    1592 0 0         $out .= qq{\t

    $h1

    \n\t
    $div
    \n} if $line;
    1593             }
    1594 0           $out .= qq{\t

    Powered by

    \n\t
    Perl/CPAN
    \n};
    1595            
    1596 0           $out .= qq{\n\n};
    1597            
    1598 0           return $out;
    1599             }
    1600              
    1601 0           close FILE;
    1602            
    1603             }
    1604             # end open_file
    1605              
    1606              
    1607              
    1608              
    1609             sub edit_file
    1610             {
    1611 0     0 1   my $self = shift;
    1612            
    1613 0           my $out;
    1614            
    1615             my %in;
    1616            
    1617 0           %in = (
    1618             file => "",
    1619             error => "",
    1620             action => "TemplateAdmin.cgi",
    1621             serial => '',
    1622             output_type => '',
    1623             @_,
    1624             );
    1625            
    1626 0 0         if (-e -f "$in{file}")
    1627             {
    1628 0 0         open(FILE, "$in{file}") or $in{error} = "unable to open $in{file}";
    1629 0           my @file = ;
    1630 0           close FILE;
    1631            
    1632 0           $out .= qq{
    1633            
    1634            
    1635            
    1636            
    1637             };
    1638            
    1639 0           for (@file)
    1640             {
    1641 0           chomp;
    1642            
    1643 0 0         next if $_ =~ /^$/;
    1644            
    1645 0 0         $in{serial}++ if $_;
    1646            
    1647 0           my ( $type, $content ) = split(/\|/, $_, 2);
    1648            
    1649 0           $type =~ s!\s+$!!g;
    1650            
    1651 0           my $identifiers = substr "$content", 0, 4; # has to be 4 to cover 'http.' Also, assuming no spaces in the beginning (removed by write_file)
    1652            
    1653             # determine output type
    1654 0 0         if ( $identifiers =~ /^\#/ ) { $in{output_type} = 'Table'; }
      0 0          
        0          
        0          
    1655 0           elsif ( $identifiers =~ /^\-/ ) { $in{output_type} = 'Accordion'; }
    1656 0           elsif ( $identifiers =~ /^\=/ ) { $in{output_type} = 'Tabs'; }
    1657 0           elsif ( $identifiers =~ /^http/ ) { $in{output_type} = 'Menu'; }
    1658 0           else { $in{output_type} = 'None'; }
    1659            
    1660             # remove all nonmeta characters for web page display
    1661 0           $identifiers =~ s!(\s+|[a-zA-z0-9])!!g; # removes http also.
    1662            
    1663 0           $content =~ s!\
    1664 0           $content =~ s!\>!>\;!g;
    1665            
    1666 0           $content =~ s! RN !\r\n!g; #
    1667            
    1668 0           $out .= qq`
    1669             $in{serial}
    1670             $type
    1671             $identifiers
    1672             Type:$in{output_type}
    1673            
    1674            
    1675            
    1676            
    1677            
    1678             `;
    1679             }
    1680            
    1681 0           $out .= qq{};
    1682            
    1683            
    1684 0           return $out;
    1685            
    1686             }
    1687             }
    1688              
    1689              
    1690              
    1691             sub write_file
    1692             {
    1693 0     0 1   my $self = shift;
    1694            
    1695 0           my $out;
    1696            
    1697             my %in;
    1698 0           %in =
    1699             (
    1700             file => "",
    1701             error => "",
    1702             powershell => "C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe ",
    1703             @_,
    1704             );
    1705            
    1706 0           my %vars;
    1707            
    1708 2     2   13362 use CGI;
      2         54904  
      2         11  
    1709 0           my $q = new CGI;
    1710 0           %vars = $q->Vars();
    1711            
    1712 0           my $action = $q->param('action');
    1713            
    1714 0 0         if ( $action eq 'write')
        0          
    1715             {
    1716              
    1717 0 0         if (-e -f "$in{file}")
    1718             {
    1719            
    1720             # First, get file content to backup to another file
    1721 0 0         open(F, "$in{file}") or $in{error} .= "#1565 Unable to open file for reading. '$!'
    ";
    1722 0           my @f = ;
    1723            
    1724             # save original file content to backup file
    1725 0 0         open(BAK, ">$in{file},bak.txt") or $in{error} .= "#1570 Unable to create backup file '$in{file},bak.txt' '$!'
    ";
    1726 0           for (@f)
    1727             {
    1728 0           print BAK qq{$_};
    1729             }
    1730 0           close BAK;
    1731            
    1732 0           close F;
    1733            
    1734             # recreate file, thereby deleting original content
    1735 0 0         open(DEL, ">$in{file}") or $in{error} .= "#1579 Unable to recreate file '$in{file}' '$!'
    ";
    1736 0           print DEL "File ReCreated";
    1737 0           close DEL;
    1738            
    1739 0           my %out;
    1740 0           for (keys %vars)
    1741             {
    1742 0           chomp $_;
    1743 0           chomp $vars{$_};
    1744            
    1745 0 0         next if $_ eq 'action';
    1746 0           my ( $name, $value ) = split(/\,/, $vars{"$_"}, 2);
    1747            
    1748 0           $name =~ s!(\r\n+|\n+)! RN !g;
    1749 0           $value =~ s!(\r\n+|\n+)! RN !g;
    1750            
    1751 0           $value =~ s!^\s+!!g;
    1752            
    1753 0           $out{"$name"} = "$value";
    1754             }
    1755            
    1756             # Insert/Add new content
    1757 0 0         open(FILE, ">$in{file}") or $in{error} .= "#1582 Error writing to file '$in{file}' '$!'
    ";
    1758 0           for (keys %out)
    1759             {
    1760 0           print FILE qq{$_\|$out{$_}\n};
    1761             }
    1762 0           close FILE;
    1763            
    1764            
    1765 0 0 0       if (-e -f "$in{file},bak.txt" and -e -f "$in{file}")
    1766             {
    1767 0           return "
    Saved
    $in{error}
    ";
    1768             }
    1769             else
    1770             {
    1771 0           return "
    #1605 Error saving file '$in{file}'
    $in{error}
    ";
    1772             }
    1773             }
    1774             else
    1775             {
    1776 0           return "File not found";
    1777             }
    1778             }
    1779             elsif ( $action eq 'newItem' )
    1780             {
    1781 0           return "$action";
    1782             }
    1783             else
    1784             {
    1785 0           return '* ' x 10;
    1786             }
    1787            
    1788             }
    1789              
    1790             # end write_file
    1791              
    1792              
    1793              
    1794              
    1795             sub display_gallery_thumbnails
    1796             {
    1797 0     0 1   my $self = shift;
    1798              
    1799 0           my $out;
    1800              
    1801             my %in;
    1802              
    1803 0           %in = (
    1804            
    1805             error => "",
    1806              
    1807             images_dir => "/images/a1z-html5-template/",
    1808             thumbs_dir => "/images/a1z-html5-template/thumbs",
    1809            
    1810             images_url => "/images/a1z-html5-template",
    1811             thumbs_url => "/thumbs/a1z-html5-template/thumbs",
    1812              
    1813             width => "100",
    1814             height => "100",
    1815              
    1816             @_,
    1817             );
    1818              
    1819 0 0 0       if (-e -d "$in{images_dir}" and "$in{thumbs_dir}" )
    1820             {
    1821 0 0         opendir(TH, "$in{thumbs_dir}") or $in{error} .= qq{

    $!

    };
    1822 0           my @thumbs = readdir(TH);
    1823 0           close TH;
    1824              
    1825 0           foreach ( @thumbs )
    1826             {
    1827 0 0 0       if ( $_ and $_ =~ /(.jpg|.gif|.jpeg|.png|.tiff)$/ )
    1828             {
    1829 0           $out .= qq{\n Image $_ \n};
    1830             }
    1831             }
    1832             }
    1833             else
    1834             {
    1835 0           $in{error} .= qq{

    Image directory does not exist or is inaccessible. Make sure you provided the correct path.

    };
    1836              
    1837 0           $out = $in{error};
    1838             }
    1839              
    1840 0           return $out;
    1841             }
    1842             # end display gallery thumbnails
    1843              
    1844              
    1845              
    1846              
    1847              
    1848              
    1849              
    1850              
    1851              
    1852             1;
    1853              
    1854             __END__