| 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.19'; | ||
| 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 | # begin content folder to select form | ||
| 729 | sub body_form | ||
| 730 | { | ||
| 731 | my $self = shift; | ||
| 732 | |||
| 733 | my $out; | ||
| 734 | |||
| 735 | my @keys; | ||
| 736 | if (@_) { @keys = "@_"; } | ||
| 737 | |||
| 738 | my ($vars, $vals) = (''); | ||
| 739 | for (@keys) | ||
| 740 | { | ||
| 741 | $vars = $_ if ($_ =~ /^vars/); | ||
| 742 | $vals = $_ if ($_ =~ /^vals/); | ||
| 743 | } | ||
| 744 | |||
| 745 | my @form_vars = split(/\;/, $vars); | ||
| 746 | |||
| 747 | my @form_vals = split(/\;/, $vals); | ||
| 748 | |||
| 749 | # get params for hidden fields if given | ||
| 750 | my @hidden; | ||
| 751 | if ($form_vars[4] and $form_vars[4] =~ /\,/) | ||
| 752 | { | ||
| 753 | @hidden = split(/\,/, $_) if $_; | ||
| 754 | } | ||
| 755 | else | ||
| 756 | { | ||
| 757 | @hidden = ("No", "Vals"); | ||
| 758 | } | ||
| 759 | |||
| 760 | # if SELECT .... | ||
| 761 | |||
| 762 | my $select; | ||
| 763 | |||
| 764 | if ($form_vars[3] and $form_vars[3] =~ /^select/) | ||
| 765 | { | ||
| 766 | # get the params for the form | ||
| 767 | my ($sel_key, $sel_name, $sel_default, $folder_or_file) = split(/\,/, $form_vars[3], 4); | ||
| 768 | $select .= qq{ | ||
| 769 | <label for"$sel_name">$sel_default</label> | ||
| 770 | <div class="form-group"><!--begin select--> | ||
| 771 | <select name="$sel_name"> | ||
| 772 | <option selected value="$sel_default">$sel_default</option> | ||
| 773 | }; | ||
| 774 | |||
| 775 | #now open file/folder to fill "options" | ||
| 776 | if ( -f $folder_or_file ) | ||
| 777 | { | ||
| 778 | # open as file | ||
| 779 | #$select .= qq{none}; | ||
| 780 | } | ||
| 781 | elsif (-d $folder_or_file) | ||
| 782 | { | ||
| 783 | # open as dir and add all files in it to "options" | ||
| 784 | opendir (D, "$folder_or_file") or print "$!"; | ||
| 785 | my @dir = readdir(D); | ||
| 786 | close D; | ||
| 787 | |||
| 788 | for my $file (@dir) | ||
| 789 | { | ||
| 790 | next unless $file =~ /[a-zA-Z0-9]/; | ||
| 791 | # comment if your want subfolders also listed | ||
| 792 | next unless -f "$folder_or_file/$file"; | ||
| 793 | # get rid of . and .. | ||
| 794 | next if $file =~ /^(\.|\.\.)/; | ||
| 795 | # do not add hidden files to the options list | ||
| 796 | next if $file =~ /^\./; | ||
| 797 | #$select .= ' ' x 8 . qq{<option value="$file">$file</option>\n} if $file; # ' ' x 8 = 8 spaces | ||
| 798 | |||
| 799 | # get the size of th file | ||
| 800 | my $size = -s "$folder_or_file/$file"; | ||
| 801 | my $original = $size; | ||
| 802 | $size /= 1024; | ||
| 803 | $size /= 1024; | ||
| 804 | $size = sprintf "%.2f", $size; | ||
| 805 | $select .= qq{\t<option value="$file">$file [$size mb]</option>\n} if $file; # ' ' x 9 #= spaces | ||
| 806 | } | ||
| 807 | } | ||
| 808 | |||
| 809 | $select .= qq{ | ||
| 810 | </select> </div> | ||
| 811 | }; | ||
| 812 | } | ||
| 813 | else | ||
| 814 | { | ||
| 815 | # no select | ||
| 816 | $select .= qq{}; | ||
| 817 | } | ||
| 818 | |||
| 819 | |||
| 820 | $out .= qq{<form action="$form_vars[2]" method="$form_vars[1]">}; | ||
| 821 | |||
| 822 | # add hidden fields/values # from $form_vars[4] | ||
| 823 | for (@hidden) | ||
| 824 | { | ||
| 825 | my ($name, $value) = split(/\-\-\-/, $_, 2) if $_; | ||
| 826 | $out .= qq{<input type="hidden" name="$name" value="$value"/>\n} if $_; | ||
| 827 | } | ||
| 828 | # add select | ||
| 829 | $out .= qq{$select}; | ||
| 830 | $out .= qq{\n<button type="submit" class="btn btn-default">Submit</button>\n</form>\n\n}; | ||
| 831 | |||
| 832 | return qq{$out}; | ||
| 833 | } | ||
| 834 | |||
| 835 | # end body_form | ||
| 836 | |||
| 837 | |||
| 838 | |||
| 839 | sub defaults_begin | ||
| 840 | { | ||
| 841 | my $self = shift; | ||
| 842 | |||
| 843 | my $out; | ||
| 844 | |||
| 845 | $out .= sprintf header(), | ||
| 846 | start_html(), | ||
| 847 | head_title("$_[0]"), | ||
| 848 | head_meta(), | ||
| 849 | head_meta("$_[1]"), | ||
| 850 | head_js_css(), | ||
| 851 | head_js_css("$_[2]"), | ||
| 852 | end_head(), | ||
| 853 | begin_body(), | ||
| 854 | body_topnavbar() | ||
| 855 | ; | ||
| 856 | |||
| 857 | return $out; | ||
| 858 | } | ||
| 859 | |||
| 860 | |||
| 861 | |||
| 862 | sub defaults_end | ||
| 863 | { | ||
| 864 | my $self = shift; | ||
| 865 | |||
| 866 | my $out; | ||
| 867 | |||
| 868 | $out .= sprintf body_js_css(), | ||
| 869 | body_js_css("$_[0]"), | ||
| 870 | end_body(), | ||
| 871 | end_html() | ||
| 872 | ; | ||
| 873 | |||
| 874 | return $out; | ||
| 875 | } | ||
| 876 | |||
| 877 | |||
| 878 | |||
| 879 | # HTML | ||
| 880 | my %HTML; | ||
| 881 | |||
| 882 | %HTML = ( | ||
| 883 | -defaultjquery => qq{\n<!-- -defaultjquery--> | ||
| 884 | |||
| 885 | <!-- jquery--> | ||
| 886 | <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> | ||
| 887 | |||
| 888 | <!--bootstrap--> | ||
| 889 | <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> | ||
| 890 | |||
| 891 | <!--blueimp gallery--> | ||
| 892 | <script src="https://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script> | ||
| 893 | |||
| 894 | <!-- jquery ui --> | ||
| 895 | <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> | ||
| 896 | |||
| 897 | <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> | ||
| 898 | <script type="text/javascript" src="https://www.a1z.us/jquery/bootstrap/fixed-top/ie10-viewport-bug-workaround.js"></script> | ||
| 899 | <script type="text/javascript"> | ||
| 900 | |||
| 901 | // for tabs | ||
| 902 | \$( function() { | ||
| 903 | var tabs = \$( "#tabs" ).tabs(); | ||
| 904 | |||
| 905 | tabs.find( ".ui-tabs-nav" ).sortable({ | ||
| 906 | axis: "x", | ||
| 907 | stop: function() { tabs.tabs( "refresh" ); } | ||
| 908 | }); | ||
| 909 | }); | ||
| 910 | |||
| 911 | // dialog | ||
| 912 | \$(function() { | ||
| 913 | \$( "#dialog" ).dialog({ | ||
| 914 | autoOpen: false, | ||
| 915 | show: { | ||
| 916 | effect: "blind", | ||
| 917 | duration: 1000 | ||
| 918 | }, | ||
| 919 | hide: { | ||
| 920 | effect: "explode", | ||
| 921 | duration: 1000 | ||
| 922 | } | ||
| 923 | }); | ||
| 924 | |||
| 925 | \$( "#opener" ).click(function() { | ||
| 926 | \$( "#dialog" ).dialog( "open" ); | ||
| 927 | }); | ||
| 928 | }); | ||
| 929 | |||
| 930 | \$('#menu').menu(); | ||
| 931 | \$('#accordion').accordion(); | ||
| 932 | \$('#accordion1').accordion(); | ||
| 933 | \$('#accordion2').accordion(); | ||
| 934 | \$('#accordion3').accordion(); | ||
| 935 | \$('accordion617').accordion(); | ||
| 936 | \$('#tabs').tabs(); | ||
| 937 | |||
| 938 | |||
| 939 | </script> | ||
| 940 | }, | ||
| 941 | |||
| 942 | -default_LastItem => qq{}, | ||
| 943 | |||
| 944 | ); | ||
| 945 | |||
| 946 | |||
| 947 | sub html_bootstrap_css | ||
| 948 | { | ||
| 949 | return qq{<!-- Bootstrap/jqueryUI --> | ||
| 950 | <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" type="text/css"> | ||
| 951 | <link href="https://www.a1z.us/jquery/bootstrap/fixed-top/navbar-fixed-top.css" rel="stylesheet"> | ||
| 952 | }; | ||
| 953 | |||
| 954 | } | ||
| 955 | |||
| 956 | |||
| 957 | |||
| 958 | |||
| 959 | sub html_jqueryui_css | ||
| 960 | { | ||
| 961 | # jquery ui theme jquery-ui.css #1.12.0 | ||
| 962 | return qq{<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet">}; | ||
| 963 | } | ||
| 964 | |||
| 965 | |||
| 966 | |||
| 967 | |||
| 968 | sub html_shim_respond | ||
| 969 | { | ||
| 970 | return qq{<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | ||
| 971 | <!--[if lt IE 9]> | ||
| 972 | <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | ||
| 973 | <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | ||
| 974 | <![endif]--> | ||
| 975 | }; | ||
| 976 | |||
| 977 | } | ||
| 978 | |||
| 979 | |||
| 980 | |||
| 981 | sub html_navbar | ||
| 982 | { | ||
| 983 | #my $self = shift; | ||
| 984 | |||
| 985 | #serverName, pageName, menuName, dropDownLinks | ||
| 986 | |||
| 987 | my %in; | ||
| 988 | %in = ( | ||
| 989 | -nbMenuName => "", | ||
| 990 | -nbPageName => "", | ||
| 991 | -nbServer => "", | ||
| 992 | -nbLinks => "blog-support-help-contact-sale", | ||
| 993 | @_, | ||
| 994 | ); | ||
| 995 | |||
| 996 | return qq{<script src="https://www.a1z.us/js/utils/top-nav-bar.js"></script> | ||
| 997 | <!--top nav bar begin--> | ||
| 998 | <script> | ||
| 999 | //<-- | ||
| 1000 | fixed_top_navbar('$in{-nbServer}', '$in{-nbPageName}', '$in{-nbMenuName}', '$in{-nbLinks}'); | ||
| 1001 | //--> | ||
| 1002 | </script> | ||
| 1003 | <!-- top nav bar end--> | ||
| 1004 | }; | ||
| 1005 | |||
| 1006 | } | ||
| 1007 | |||
| 1008 | |||
| 1009 | |||
| 1010 | |||
| 1011 | sub html_bootstrap_js | ||
| 1012 | { | ||
| 1013 | # jquery:3.3.0 ui:1/12/1 | ||
| 1014 | |||
| 1015 | return qq{<!-- Bootstrap/jqueryUI --> | ||
| 1016 | <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js" rel="stylesheet" type="text/css"> | ||
| 1017 | |||
| 1018 | }; | ||
| 1019 | |||
| 1020 | } | ||
| 1021 | |||
| 1022 | sub html_js_css | ||
| 1023 | { | ||
| 1024 | |||
| 1025 | } | ||
| 1026 | |||
| 1027 | sub html_jquery | ||
| 1028 | { | ||
| 1029 | |||
| 1030 | } | ||
| 1031 | |||
| 1032 | |||
| 1033 | |||
| 1034 | sub html_setTitle | ||
| 1035 | { | ||
| 1036 | my $out; | ||
| 1037 | |||
| 1038 | my %in; | ||
| 1039 | |||
| 1040 | %in = ( | ||
| 1041 | ta => qq{}, | ||
| 1042 | tb => qq{}, | ||
| 1043 | tc => qq{}, | ||
| 1044 | @_, | ||
| 1045 | ); | ||
| 1046 | |||
| 1047 | $out .= qq{<script> | ||
| 1048 | <!-- Begin | ||
| 1049 | function setTitle() | ||
| 1050 | { | ||
| 1051 | var a = "$in{ta}"; | ||
| 1052 | var b = "$in{tb}"; | ||
| 1053 | var c = "$in{tc}"; | ||
| 1054 | var t = new Date(); | ||
| 1055 | s = t.getSeconds(); | ||
| 1056 | if (s == 10) { document.title = a;} | ||
| 1057 | else if (s == 20) { document.title = b;} | ||
| 1058 | else if (s == 30) { document.title = c;} | ||
| 1059 | else if (s == 40) { document.title = a;} | ||
| 1060 | else if (s == 50) { document.title = b;} | ||
| 1061 | else if (s == 00) { document.title = c;} | ||
| 1062 | setTimeout("setTitle()", 1000); | ||
| 1063 | } | ||
| 1064 | // End --> | ||
| 1065 | </script> | ||
| 1066 | }; | ||
| 1067 | |||
| 1068 | return $out; | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | |||
| 1072 | |||
| 1073 | |||
| 1074 | sub html_humanejs_css | ||
| 1075 | { | ||
| 1076 | return qq{<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/bigbox.css'> | ||
| 1077 | <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/boldlight.css'> | ||
| 1078 | <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/jackedup.css'> | ||
| 1079 | <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/libnotify.css'> | ||
| 1080 | <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/original.css'> | ||
| 1081 | <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/themes/flatty.min.css'> | ||
| 1082 | <link href='https://fonts.googleapis.com/css?family=Ubuntu&v2' rel='stylesheet' type='text/css'> | ||
| 1083 | <link href='https://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'> | ||
| 1084 | <link href='https://fonts.googleapis.com/css?family=Cabin+Sketch:700&v2' rel='stylesheet' type='text/css'> | ||
| 1085 | }; | ||
| 1086 | |||
| 1087 | } | ||
| 1088 | |||
| 1089 | |||
| 1090 | |||
| 1091 | |||
| 1092 | sub html_bootstrap_bluimp | ||
| 1093 | { | ||
| 1094 | return qq{<!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body --> | ||
| 1095 | <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-use-bootstrap-modal="false"> | ||
| 1096 | <!-- The container for the modal slides --> | ||
| 1097 | <div class="slides"></div> | ||
| 1098 | <!-- Controls for the borderless lightbox --> | ||
| 1099 | <h3 class="title"></h3> | ||
| 1100 | <a class="prev">‹</a> | ||
| 1101 | <a class="next">›</a> | ||
| 1102 | <a class="close">×</a> | ||
| 1103 | <a class="play-pause"></a> | ||
| 1104 | <ol class="indicator"></ol> | ||
| 1105 | <!-- The modal dialog, which will be used to wrap the lightbox content --> | ||
| 1106 | <div class="modal fade"> | ||
| 1107 | <div class="modal-dialog"> | ||
| 1108 | <div class="modal-content"> | ||
| 1109 | <div class="modal-header"> | ||
| 1110 | <button type="button" class="close" aria-hidden="true">×</button> | ||
| 1111 | <h4 class="modal-title"></h4> | ||
| 1112 | </div> | ||
| 1113 | <div class="modal-body next"></div> | ||
| 1114 | <div class="modal-footer"> | ||
| 1115 | <button type="button" class="btn btn-default pull-left prev"> | ||
| 1116 | <i class="glyphicon glyphicon-chevron-left"></i> | ||
| 1117 | Previous | ||
| 1118 | </button> | ||
| 1119 | <button type="button" class="btn btn-primary next"> | ||
| 1120 | Next | ||
| 1121 | <i class="glyphicon glyphicon-chevron-right"></i> | ||
| 1122 | </button> | ||
| 1123 | </div> | ||
| 1124 | </div> | ||
| 1125 | </div> | ||
| 1126 | </div> | ||
| 1127 | </div> | ||
| 1128 | }; | ||
| 1129 | } | ||
| 1130 | # end sub html_bootstrap_bluimp | ||
| 1131 | |||
| 1132 | |||
| 1133 | |||
| 1134 | |||
| 1135 | sub head | ||
| 1136 | { | ||
| 1137 | my $self = shift; | ||
| 1138 | |||
| 1139 | my $out; | ||
| 1140 | |||
| 1141 | my %in = ( | ||
| 1142 | -type => "Content-Type: text/html;charset=utf-8\n\n", | ||
| 1143 | -bootstrap => html_bootstrap_css, | ||
| 1144 | -jqueryui => html_jqueryui_css, | ||
| 1145 | -htmlshim => html_shim_respond, | ||
| 1146 | -humanejs => html_humanejs_css, | ||
| 1147 | -title => "$ENV{SERVER_NAME}", | ||
| 1148 | -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", | ||
| 1149 | -cssCode => "", | ||
| 1150 | -mobilemeta => qq{<meta name="HandheldFriendly" content="true"> | ||
| 1151 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| 1152 | }, | ||
| 1153 | -charsetmeta => qq{<meta charset="utf-8">}, | ||
| 1154 | -usermeta => "", | ||
| 1155 | -titleRotatingText => qq{text1,text2,text3}, | ||
| 1156 | @_, | ||
| 1157 | |||
| 1158 | ); | ||
| 1159 | |||
| 1160 | |||
| 1161 | # rotating title function and text | ||
| 1162 | my $setTitle; | ||
| 1163 | if ( $in{-titleRotatingText} and $in{-titleRotatingText} =~ /\,/ ) | ||
| 1164 | { | ||
| 1165 | my @a; | ||
| 1166 | @a = split(/\,/, $in{-titleRotatingText}, 3); | ||
| 1167 | |||
| 1168 | $setTitle = html_setTitle(ta => "$a[0]", tb => "$a[1]", tc => "$a[2]"); | ||
| 1169 | } | ||
| 1170 | else | ||
| 1171 | { | ||
| 1172 | $setTitle = html_setTitle(ta => "Text01", tb => "text02", tc => "text03"); | ||
| 1173 | } | ||
| 1174 | |||
| 1175 | # css multiple links/files | ||
| 1176 | my $css; my @css; | ||
| 1177 | if ($in{-cssLinks} ) | ||
| 1178 | { | ||
| 1179 | if ( $in{-cssLinks} =~ /\,/ ) | ||
| 1180 | { | ||
| 1181 | @css = split(/\,/, $in{-cssLinks}); | ||
| 1182 | for (@css) | ||
| 1183 | { | ||
| 1184 | if ($_ =~ /\.css$/) | ||
| 1185 | { | ||
| 1186 | $css .= qq{<link type="text/css" rel="stylesheet" href="$_">\n} ; | ||
| 1187 | } | ||
| 1188 | else | ||
| 1189 | { | ||
| 1190 | $css = ''; | ||
| 1191 | } | ||
| 1192 | } | ||
| 1193 | } | ||
| 1194 | } | ||
| 1195 | else | ||
| 1196 | { | ||
| 1197 | $css = qq{}; | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | |||
| 1201 | return qq{$in{-type}<!DOCTYPE html> | ||
| 1202 | <html> | ||
| 1203 | <head> | ||
| 1204 | <title>$in{-title}</title> | ||
| 1205 | $in{-charsetmeta} | ||
| 1206 | $in{-mobilemeta} | ||
| 1207 | $in{-usermeta} | ||
| 1208 | $in{-bootstrap} | ||
| 1209 | $in{-jqueryui} | ||
| 1210 | $in{-htmlshim} | ||
| 1211 | $in{-humanejs} | ||
| 1212 | $css | ||
| 1213 | <style type="text/css"> | ||
| 1214 | $in{-cssCode} | ||
| 1215 | </style> | ||
| 1216 | |||
| 1217 | $setTitle | ||
| 1218 | |||
| 1219 | </head> | ||
| 1220 | }; # thats orderly | ||
| 1221 | |||
| 1222 | } | ||
| 1223 | # end head | ||
| 1224 | |||
| 1225 | |||
| 1226 | |||
| 1227 | sub body | ||
| 1228 | { | ||
| 1229 | my $self = shift; | ||
| 1230 | |||
| 1231 | my $out; | ||
| 1232 | |||
| 1233 | my %in; | ||
| 1234 | |||
| 1235 | %in = ( | ||
| 1236 | -h1 => qq{$ENV{SERVER_NAME}}, | ||
| 1237 | -onload => qq{setTitle();}, | ||
| 1238 | -nbhead => qq{}, | ||
| 1239 | -nbpage => qq{}, | ||
| 1240 | -nbmenu => qq{More}, | ||
| 1241 | -defaultjquery => qq{$HTML{-defaultjquery}}, | ||
| 1242 | -humanejs => qq{<script src="https://cdnjs.cloudflare.com/ajax/libs/humane-js/3.2.2/humane.min.js">}, | ||
| 1243 | -userjquery => qq{}, | ||
| 1244 | -navbar => html_navbar( $in{-nbmenu}, $in{-nbpage}, "", ""), | ||
| 1245 | -content => qq{<div class="content">Content</div>}, | ||
| 1246 | -footer => qq{All rights reserved © $ENV{SERVER_NAME}}, | ||
| 1247 | -bootstrapbluimp => html_bootstrap_bluimp, | ||
| 1248 | -nbLinks => qq{contact-help-feedback}, | ||
| 1249 | @_, | ||
| 1250 | ); | ||
| 1251 | |||
| 1252 | return qq{<body onload="$in{-onload}"> | ||
| 1253 | <div id="main" class="container"> | ||
| 1254 | <!--top nav bar begin--> | ||
| 1255 | <script type="text/javascript" src="https://www.a1z.us/js/utils/top-nav-bar.js"></script> | ||
| 1256 | <script type="text/javascript"> | ||
| 1257 | //<-- | ||
| 1258 | fixed_top_navbar('$in{-nbhead}', '$in{-nbpage}', '$in{-nbmenu}', '$in{-nbLinks}'); | ||
| 1259 | //--> | ||
| 1260 | </script> | ||
| 1261 | |||
| 1262 | $in{-bootstrapbluimp} | ||
| 1263 | |||
| 1264 | $in{-h1} | ||
| 1265 | |||
| 1266 | $in{-content} | ||
| 1267 | |||
| 1268 | $in{-footer} | ||
| 1269 | |||
| 1270 | </div> | ||
| 1271 | |||
| 1272 | $in{-defaultjquery} | ||
| 1273 | |||
| 1274 | $in{-humanejs} | ||
| 1275 | |||
| 1276 | <script type="text/javascript"> | ||
| 1277 | //<!-- | ||
| 1278 | $in{-userjquery} | ||
| 1279 | //--> | ||
| 1280 | </script> | ||
| 1281 | |||
| 1282 | </body> | ||
| 1283 | |||
| 1284 | </html> | ||
| 1285 | |||
| 1286 | }; | ||
| 1287 | |||
| 1288 | } | ||
| 1289 | # end body | ||
| 1290 | |||
| 1291 | |||
| 1292 | sub create_accordion | ||
| 1293 | { | ||
| 1294 | my $out; | ||
| 1295 | |||
| 1296 | my $file = "@_"; | ||
| 1297 | |||
| 1298 | my @data; | ||
| 1299 | |||
| 1300 | if ($file and -e -f $file) | ||
| 1301 | { | ||
| 1302 | $out .= open_file("$file"); | ||
| 1303 | } | ||
| 1304 | else | ||
| 1305 | { | ||
| 1306 | $out .= qq{#55 Unable to open file $file}; | ||
| 1307 | |||
| 1308 | } | ||
| 1309 | |||
| 1310 | return $out; | ||
| 1311 | |||
| 1312 | } | ||
| 1313 | # end create accordion | ||
| 1314 | |||
| 1315 | |||
| 1316 | |||
| 1317 | |||
| 1318 | sub open_file | ||
| 1319 | { | ||
| 1320 | my $self =shift; | ||
| 1321 | |||
| 1322 | # OUTPUT FORMAT OPTIONS: table, accordion, menu, as is; where "as is" is the default | ||
| 1323 | |||
| 1324 | my $file = "$_[0]"; # do not use @_ for a scalar: it puts all together and the file path was wrong. # use $_[n] # use $_ if and only if there will be just one var passed to this sub | ||
| 1325 | |||
| 1326 | my $output_format = "$_[1]"; | ||
| 1327 | |||
| 1328 | my $output_header = "$_[2]"; | ||
| 1329 | |||
| 1330 | my $out; | ||
| 1331 | |||
| 1332 | my @data; | ||
| 1333 | |||
| 1334 | if (open(FILE, "$file") ) | ||
| 1335 | { | ||
| 1336 | #open(FILE, "$file") or $out .= qq{77 $!}; | ||
| 1337 | |||
| 1338 | @data = <FILE>; | ||
| 1339 | |||
| 1340 | $out .= qq{\n<!--begin file output-->\n<div class="file_output">\n}; | ||
| 1341 | |||
| 1342 | # Step 1 | ||
| 1343 | # set the header as per format | ||
| 1344 | if ($output_format eq 'table') | ||
| 1345 | { | ||
| 1346 | $out .= qq{<table class="table table-striped table-bordered table-hover table-condensed table-responsive"> | ||
| 1347 | <thead> | ||
| 1348 | <tr><th colspan="2">$output_header</th></tr> | ||
| 1349 | </thead> | ||
| 1350 | <tbody> | ||
| 1351 | }; | ||
| 1352 | } | ||
| 1353 | elsif ($output_format eq 'accordion') | ||
| 1354 | { | ||
| 1355 | $out .= qq{<h2>$output_header</h2>\n<div id="accordion2" class="accordion"><!--118-->\n}; | ||
| 1356 | } | ||
| 1357 | elsif ($output_format eq 'menu') | ||
| 1358 | { | ||
| 1359 | $out .= qq{<ul class="menu" id="menu">\n<li><a href="/">$output_header</a>\n<ul>}; | ||
| 1360 | } | ||
| 1361 | elsif ($output_format eq 'tabs') | ||
| 1362 | { | ||
| 1363 | # special case for tabs since the data needs to be formatted a little differently | ||
| 1364 | |||
| 1365 | $out .= qq{<h2>$output_header</h2>\n<div id="tabs">\n<ul>\n}; | ||
| 1366 | |||
| 1367 | my $sl = '0'; | ||
| 1368 | |||
| 1369 | foreach my $line (@data) | ||
| 1370 | { | ||
| 1371 | $sl++ if $line; | ||
| 1372 | |||
| 1373 | my ($h1, $div) = (''); | ||
| 1374 | |||
| 1375 | if ($line =~ /\|/) | ||
| 1376 | { | ||
| 1377 | ($h1, $div) = split(/\|/, $line, 2); | ||
| 1378 | } # no (\|) # i.e., do not enclose with brackets. Enclosing was the culprit | ||
| 1379 | elsif ($line =~ /\t+/) { | ||
| 1380 | ($h1, $div) = split(/\t+/, $line, 2); | ||
| 1381 | } | ||
| 1382 | elsif ($line =~ /\s+/) | ||
| 1383 | { | ||
| 1384 | ($h1, $div) = split(/\s+/, $line, 2); | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | # Keep only those items that have '==' in the beginning | ||
| 1388 | |||
| 1389 | if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ ) | ||
| 1390 | { | ||
| 1391 | next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/); | ||
| 1392 | $div =~ s!^\s+==!!g; | ||
| 1393 | $h1 =~ s!^\s+==!!g; | ||
| 1394 | } | ||
| 1395 | else | ||
| 1396 | { | ||
| 1397 | next unless ($h1 =~ /^==/ or $div =~ /^==/); | ||
| 1398 | $div =~ s!^==!!g; | ||
| 1399 | $h1 =~ s!^==!!g; | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | $out .= qq{\t<li><a href="#tabs-$sl">$h1</a></li>\n}; | ||
| 1403 | } | ||
| 1404 | $out .= qq{</ul>\n}; | ||
| 1405 | } | ||
| 1406 | elsif ($output_format eq 'dialog') | ||
| 1407 | { | ||
| 1408 | $out .= qq{<h2>Dialog: <a href="#opener" id="opener" title="Opens the Dialog">$output_header</a></h2> | ||
| 1409 | <div id="dialog">\n}; | ||
| 1410 | } | ||
| 1411 | else | ||
| 1412 | { | ||
| 1413 | $out .= qq{\n<h2>$output_header</h2>\n}; | ||
| 1414 | } | ||
| 1415 | # End Step 1 | ||
| 1416 | |||
| 1417 | # now work on file | ||
| 1418 | |||
| 1419 | my $serial = '0'; | ||
| 1420 | |||
| 1421 | foreach my $line (@data) | ||
| 1422 | { | ||
| 1423 | chomp $line; | ||
| 1424 | |||
| 1425 | $serial++ if $line; | ||
| 1426 | |||
| 1427 | my ($h1, $div) = (''); | ||
| 1428 | |||
| 1429 | if ($line) # make sure no output if line is empty | ||
| 1430 | { | ||
| 1431 | $line =~ s! RN !\r\n!g; | ||
| 1432 | |||
| 1433 | # split the file's lines into usable data according to separator used. | ||
| 1434 | if ($line =~ /\|/) | ||
| 1435 | { | ||
| 1436 | ($h1, $div) = split(/\|/, $line, 2); | ||
| 1437 | } # no (\|) # i.e., no enclosing with brackets. was the culprit | ||
| 1438 | elsif ($line =~ /\t+/) { | ||
| 1439 | ($h1, $div) = split(/\t+/, $line, 2); | ||
| 1440 | } | ||
| 1441 | elsif ($line =~ /\s+/) | ||
| 1442 | { | ||
| 1443 | ($h1, $div) = split(/\s+/, $line, 2); | ||
| 1444 | } | ||
| 1445 | # end split the file's line according to match: 3 options: |, \t+, or \s+ | ||
| 1446 | |||
| 1447 | } | ||
| 1448 | |||
| 1449 | # Step 2 | ||
| 1450 | #Now set the content as per output format | ||
| 1451 | if ($output_format eq 'table') | ||
| 1452 | { | ||
| 1453 | # Keep only those items that have a # in the beginning | ||
| 1454 | |||
| 1455 | if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ ) | ||
| 1456 | { | ||
| 1457 | next unless ($h1 =~ /^\s+#/ or $div =~ /^\s+#/); | ||
| 1458 | $div =~ s!^\s+#!!g; | ||
| 1459 | $h1 =~ s!^\s+#!!g; | ||
| 1460 | } | ||
| 1461 | else | ||
| 1462 | { | ||
| 1463 | next unless ($h1 =~ /^#/ or $div =~ /^#/); | ||
| 1464 | $div =~ s!^#!!g; | ||
| 1465 | $h1 =~ s!^#!!g; | ||
| 1466 | } | ||
| 1467 | $out .= qq{\t<tr><td>$h1</td><td>$div</td></tr>\n}; | ||
| 1468 | } | ||
| 1469 | elsif ($output_format eq 'accordion') | ||
| 1470 | { | ||
| 1471 | # Keep only those items that have -- in the beginning | ||
| 1472 | |||
| 1473 | if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ ) | ||
| 1474 | { | ||
| 1475 | next unless ($h1 =~ /^\s+--/ or $div =~ /^\s+--/); | ||
| 1476 | $div =~ s!^\s+--!!g; | ||
| 1477 | $h1 =~ s!^\s+--!!g; | ||
| 1478 | } | ||
| 1479 | else | ||
| 1480 | { | ||
| 1481 | next unless ($h1 =~ /^--/ or $div =~ /^--/); | ||
| 1482 | $div =~ s!^--!!g; | ||
| 1483 | $h1 =~ s!^--!!g; | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | $out .= qq{\t<h3>$h1</h3>\n\t<div>$div</div>\n} if $line; | ||
| 1487 | } | ||
| 1488 | elsif ($output_format eq 'menu') | ||
| 1489 | { | ||
| 1490 | # the first item will be used as link title and name | ||
| 1491 | # the second item will be used as the actual link | ||
| 1492 | # no extensions added automatically by the script | ||
| 1493 | # an id for each link/li is also provided in case, may be it is not needed | ||
| 1494 | |||
| 1495 | # Remove items with a # in the beginning; Sat Feb 21 18:48:19 2015 | ||
| 1496 | next if ($h1 =~ /^#http/ or $div =~ /^#http/); | ||
| 1497 | |||
| 1498 | # Keep only those items that have a 'http' in the beginning | ||
| 1499 | |||
| 1500 | if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ ) | ||
| 1501 | { | ||
| 1502 | next unless ($h1 =~ /^\s+http/ or $div =~ /^\s+http/); | ||
| 1503 | $div =~ s!^\s+http!!g; | ||
| 1504 | $h1 =~ s!^\s+http!!g; | ||
| 1505 | } | ||
| 1506 | else | ||
| 1507 | { | ||
| 1508 | next unless ($h1 =~ /^http/ or $div =~ /^http/); | ||
| 1509 | $div =~ s!^http!!g; | ||
| 1510 | $h1 =~ s!^http!!g; | ||
| 1511 | } | ||
| 1512 | $out .= qq{\t<li id="li-$serial"><a id="a-$serial" href="$div" title="$h1">$h1</a></li>\n}; | ||
| 1513 | } | ||
| 1514 | elsif ($output_format eq 'tabs') | ||
| 1515 | { | ||
| 1516 | # Keep only those items that have a == in the beginning | ||
| 1517 | |||
| 1518 | if ( $h1 =~ /^\s+/ or $div =~ /^\s+/ ) | ||
| 1519 | { | ||
| 1520 | next unless ($h1 =~ /^\s+==/ or $div =~ /^\s+==/); | ||
| 1521 | $div =~ s!^\s+==!!g; | ||
| 1522 | $h1 =~ s!^\s+==!!g; | ||
| 1523 | } | ||
| 1524 | else | ||
| 1525 | { | ||
| 1526 | next unless ($h1 =~ /^==/ or $div =~ /^==/); | ||
| 1527 | $div =~ s!^==!!g; | ||
| 1528 | $h1 =~ s!^==!!g; | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | $out .= qq{\t<div id="tabs-$serial"><p>$div</p></div>\n}; | ||
| 1532 | } | ||
| 1533 | elsif ($output_format eq 'dialog') | ||
| 1534 | { | ||
| 1535 | # includes everything; So, no filtering. | ||
| 1536 | |||
| 1537 | # But, just remove symbols in both $h1 and $div | ||
| 1538 | $div =~ s!^(==|\#|--)!!g; | ||
| 1539 | $h1 =~ s!^(==|\#|--)!!g; | ||
| 1540 | |||
| 1541 | $out .= qq{<p>$h1</p>\n<p>$div</p>\n}; | ||
| 1542 | } | ||
| 1543 | else | ||
| 1544 | { | ||
| 1545 | $out .= qq{$h1 $div}; # or $line | ||
| 1546 | } | ||
| 1547 | } | ||
| 1548 | |||
| 1549 | # add an extra item at the end of file output | ||
| 1550 | #$out .= qq{\t<h3>Powered by Business Impact Solutions</h3>\n\t<div>bislinks.com, bizImpactSolutions.com - Business Impact Solutions</div>\n}; | ||
| 1551 | |||
| 1552 | # Step 3 | ||
| 1553 | # set the output ending as per format | ||
| 1554 | if ($output_format eq 'table') | ||
| 1555 | { | ||
| 1556 | $out .= qq{\n</tbody>\n</table>\n\n}; | ||
| 1557 | } | ||
| 1558 | elsif ($output_format eq 'accordion') | ||
| 1559 | { | ||
| 1560 | $out .= qq{\n<!--end accordion--></div>\n\n}; | ||
| 1561 | } | ||
| 1562 | elsif ($output_format eq 'menu') | ||
| 1563 | { | ||
| 1564 | $out .= qq{</ul></ul>}; | ||
| 1565 | } | ||
| 1566 | elsif ($output_format eq 'tabs') | ||
| 1567 | { | ||
| 1568 | $out .= qq{</div><!--end tabs-->\n}; | ||
| 1569 | } | ||
| 1570 | elsif ($output_format eq 'dialog') | ||
| 1571 | { | ||
| 1572 | $out .= qq{</div><!--end dialog-->\n}; | ||
| 1573 | } | ||
| 1574 | else | ||
| 1575 | { | ||
| 1576 | $out .= qq{\n\n}; | ||
| 1577 | } | ||
| 1578 | |||
| 1579 | # end file output wrapper | ||
| 1580 | $out .= qq{</div><!--end file output-->\n}; | ||
| 1581 | |||
| 1582 | close FILE; | ||
| 1583 | |||
| 1584 | return $out; | ||
| 1585 | } | ||
| 1586 | else | ||
| 1587 | { | ||
| 1588 | my $out; | ||
| 1589 | |||
| 1590 | @data = <DATA>; | ||
| 1591 | |||
| 1592 | close DATA; | ||
| 1593 | |||
| 1594 | $out .= qq{\n<!--begin accord 112-->\n<div id="accordion1460" class="accordion">\n}; | ||
| 1595 | foreach my $line (@data) | ||
| 1596 | { | ||
| 1597 | chomp $line; | ||
| 1598 | |||
| 1599 | my ($h1, $div) = (''); | ||
| 1600 | |||
| 1601 | ($h1, $div) = split(/\t+/, $line, 2) if $line; | ||
| 1602 | |||
| 1603 | $out .= qq{\t<h3>$h1</h3>\n\t<div>$div</div>\n} if $line; | ||
| 1604 | } | ||
| 1605 | $out .= qq{\t<h3>Powered by</h3>\n\t<div>Perl/CPAN</div>\n}; | ||
| 1606 | |||
| 1607 | $out .= qq{</div>\n<!--end accord-->\n}; | ||
| 1608 | |||
| 1609 | return $out; | ||
| 1610 | } | ||
| 1611 | |||
| 1612 | } | ||
| 1613 | # end open_file | ||
| 1614 | |||
| 1615 | |||
| 1616 | |||
| 1617 | |||
| 1618 | sub edit_file | ||
| 1619 | { | ||
| 1620 | my $self = shift; | ||
| 1621 | |||
| 1622 | my $out; | ||
| 1623 | |||
| 1624 | my %in; | ||
| 1625 | |||
| 1626 | %in = ( | ||
| 1627 | file => "", | ||
| 1628 | error => "", | ||
| 1629 | action => "TemplateAdmin.cgi", | ||
| 1630 | serial => '', | ||
| 1631 | output_type => '', | ||
| 1632 | @_, | ||
| 1633 | ); | ||
| 1634 | |||
| 1635 | if (-e -f "$in{file}") | ||
| 1636 | { | ||
| 1637 | open(FILE, "$in{file}") or $in{error} = "unable to open $in{file}"; | ||
| 1638 | my @file = <FILE>; | ||
| 1639 | close FILE; | ||
| 1640 | |||
| 1641 | $out .= qq{ | ||
| 1642 | <article class="container"> | ||
| 1643 | |||
| 1644 | <form action="$in{action}" method="post"> | ||
| 1645 | <input type="hidden" name="action" value="write"> | ||
| 1646 | }; | ||
| 1647 | |||
| 1648 | for (@file) | ||
| 1649 | { | ||
| 1650 | chomp; | ||
| 1651 | |||
| 1652 | next if $_ =~ /^$/; | ||
| 1653 | |||
| 1654 | $in{serial}++ if $_; | ||
| 1655 | |||
| 1656 | my ( $type, $content ) = split(/\|/, $_, 2); | ||
| 1657 | |||
| 1658 | $type =~ s!\s+$!!g; | ||
| 1659 | |||
| 1660 | my $identifiers = substr "$content", 0, 4; # has to be 4 to cover 'http.' Also, assuming no spaces in the beginning (removed by write_file) | ||
| 1661 | |||
| 1662 | # determine output type | ||
| 1663 | if ( $identifiers =~ /^\#/ ) { $in{output_type} = 'Table'; } | ||
| 1664 | elsif ( $identifiers =~ /^\-/ ) { $in{output_type} = 'Accordion'; } | ||
| 1665 | elsif ( $identifiers =~ /^\=/ ) { $in{output_type} = 'Tabs'; } | ||
| 1666 | elsif ( $identifiers =~ /^http/ ) { $in{output_type} = 'Menu'; } | ||
| 1667 | else { $in{output_type} = 'None'; } | ||
| 1668 | |||
| 1669 | # remove all nonmeta characters for web page display | ||
| 1670 | $identifiers =~ s!(\s+|[a-zA-z0-9])!!g; # removes http also. | ||
| 1671 | |||
| 1672 | $content =~ s!\<!<\;!g; | ||
| 1673 | $content =~ s!\>!>\;!g; | ||
| 1674 | |||
| 1675 | $content =~ s! RN !\r\n!g; # | ||
| 1676 | |||
| 1677 | $out .= qq`<div> | ||
| 1678 | <span class="serial">$in{serial} </span> | ||
| 1679 | <span class="type">$type </span> | ||
| 1680 | <span class="identifiers">$identifiers </span> | ||
| 1681 | <span class="type type-$in{output_type}">Type:$in{output_type} </span> | ||
| 1682 | </div> | ||
| 1683 | <div> | ||
| 1684 | <textarea name="ta-$type" id="ta-$type" rows="5" cols="98%" class="type-$in{output_type}">$type , $content</textarea> | ||
| 1685 | </div> | ||
| 1686 | <br/> | ||
| 1687 | `; | ||
| 1688 | } | ||
| 1689 | |||
| 1690 | $out .= qq{<input type='submit' value="Save"></form></article>}; | ||
| 1691 | |||
| 1692 | |||
| 1693 | return $out; | ||
| 1694 | |||
| 1695 | } | ||
| 1696 | } | ||
| 1697 | |||
| 1698 | |||
| 1699 | |||
| 1700 | sub write_file | ||
| 1701 | { | ||
| 1702 | my $self = shift; | ||
| 1703 | |||
| 1704 | my $out; | ||
| 1705 | |||
| 1706 | my %in; | ||
| 1707 | %in = | ||
| 1708 | ( | ||
| 1709 | file => "", | ||
| 1710 | error => "", | ||
| 1711 | powershell => "C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe ", | ||
| 1712 | @_, | ||
| 1713 | ); | ||
| 1714 | |||
| 1715 | my %vars; | ||
| 1716 | |||
| 1717 | use CGI; | ||
| 1718 | my $q = new CGI; | ||
| 1719 | %vars = $q->Vars(); | ||
| 1720 | |||
| 1721 | my $action = $q->param('action'); | ||
| 1722 | |||
| 1723 | if ( $action eq 'write') | ||
| 1724 | { | ||
| 1725 | |||
| 1726 | if (-e -f "$in{file}") | ||
| 1727 | { | ||
| 1728 | |||
| 1729 | # First, get file content to backup to another file | ||
| 1730 | open(F, "$in{file}") or $in{error} .= "#1565 Unable to open file for reading. '$!' <br/>"; | ||
| 1731 | my @f = <F>; | ||
| 1732 | |||
| 1733 | # save original file content to backup file | ||
| 1734 | open(BAK, ">$in{file},bak.txt") or $in{error} .= "#1570 Unable to create backup file '$in{file},bak.txt' '$!' <br/>"; | ||
| 1735 | for (@f) | ||
| 1736 | { | ||
| 1737 | print BAK qq{$_}; | ||
| 1738 | } | ||
| 1739 | close BAK; | ||
| 1740 | |||
| 1741 | close F; | ||
| 1742 | |||
| 1743 | # recreate file, thereby deleting original content | ||
| 1744 | open(DEL, ">$in{file}") or $in{error} .= "#1579 Unable to recreate file '$in{file}' '$!' <br/>"; | ||
| 1745 | print DEL "File ReCreated"; | ||
| 1746 | close DEL; | ||
| 1747 | |||
| 1748 | my %out; | ||
| 1749 | for (keys %vars) | ||
| 1750 | { | ||
| 1751 | chomp $_; | ||
| 1752 | chomp $vars{$_}; | ||
| 1753 | |||
| 1754 | next if $_ eq 'action'; | ||
| 1755 | my ( $name, $value ) = split(/\,/, $vars{"$_"}, 2); | ||
| 1756 | |||
| 1757 | $name =~ s!(\r\n+|\n+)! RN !g; | ||
| 1758 | $value =~ s!(\r\n+|\n+)! RN !g; | ||
| 1759 | |||
| 1760 | $value =~ s!^\s+!!g; | ||
| 1761 | |||
| 1762 | $out{"$name"} = "$value"; | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | # Insert/Add new content | ||
| 1766 | open(FILE, ">$in{file}") or $in{error} .= "#1582 Error writing to file '$in{file}' '$!' <br/>"; | ||
| 1767 | for (keys %out) | ||
| 1768 | { | ||
| 1769 | print FILE qq{$_\|$out{$_}\n}; | ||
| 1770 | } | ||
| 1771 | close FILE; | ||
| 1772 | |||
| 1773 | |||
| 1774 | if (-e -f "$in{file},bak.txt" and -e -f "$in{file}") | ||
| 1775 | { | ||
| 1776 | return "<div class='success'>Saved</div> <div class='error'>$in{error}</div>"; | ||
| 1777 | } | ||
| 1778 | else | ||
| 1779 | { | ||
| 1780 | return "<div>#1605 Error saving file '$in{file}'</div> <div class='error'>$in{error}</div>"; | ||
| 1781 | } | ||
| 1782 | } | ||
| 1783 | else | ||
| 1784 | { | ||
| 1785 | return "File not found"; | ||
| 1786 | } | ||
| 1787 | } | ||
| 1788 | elsif ( $action eq 'newItem' ) | ||
| 1789 | { | ||
| 1790 | return "$action"; | ||
| 1791 | } | ||
| 1792 | else | ||
| 1793 | { | ||
| 1794 | return '* ' x 10; | ||
| 1795 | } | ||
| 1796 | |||
| 1797 | } | ||
| 1798 | |||
| 1799 | # end write_file | ||
| 1800 | |||
| 1801 | |||
| 1802 | |||
| 1803 | |||
| 1804 | sub display_gallery_thumbnails | ||
| 1805 | { | ||
| 1806 | my $self = shift; | ||
| 1807 | |||
| 1808 | my $out; | ||
| 1809 | |||
| 1810 | my %in; | ||
| 1811 | |||
| 1812 | %in = ( | ||
| 1813 | |||
| 1814 | error => "", | ||
| 1815 | |||
| 1816 | images_dir => "/images/a1z-html5-template/", | ||
| 1817 | thumbs_dir => "/images/a1z-html5-template/thumbs", | ||
| 1818 | |||
| 1819 | images_url => "/images/a1z-html5-template", | ||
| 1820 | thumbs_url => "/thumbs/a1z-html5-template/thumbs", | ||
| 1821 | |||
| 1822 | width => "100", | ||
| 1823 | height => "100", | ||
| 1824 | |||
| 1825 | @_, | ||
| 1826 | ); | ||
| 1827 | |||
| 1828 | if (-e -d "$in{images_dir}" and "$in{thumbs_dir}" ) | ||
| 1829 | { | ||
| 1830 | opendir(TH, "$in{thumbs_dir}") or $in{error} .= qq{<p>$!</p>}; | ||
| 1831 | my @thumbs = readdir(TH); | ||
| 1832 | close TH; | ||
| 1833 | |||
| 1834 | foreach ( @thumbs ) | ||
| 1835 | { | ||
| 1836 | if ( $_ and $_ =~ /(.jpg|.gif|.jpeg|.png|.tiff)$/ ) | ||
| 1837 | { | ||
| 1838 | $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}; | ||
| 1839 | } | ||
| 1840 | } | ||
| 1841 | } | ||
| 1842 | else | ||
| 1843 | { | ||
| 1844 | $in{error} .= qq{<p>Image directory does not exist or is inaccessible. Make sure you provided the correct path.</p>}; | ||
| 1845 | |||
| 1846 | $out = $in{error}; | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | return $out; | ||
| 1850 | } | ||
| 1851 | # end display gallery thumbnails | ||
| 1852 | |||
| 1853 | |||
| 1854 | |||
| 1855 | |||
| 1856 | |||
| 1857 | |||
| 1858 | |||
| 1859 | |||
| 1860 | |||
| 1861 | 1; | ||
| 1862 | |||
| 1863 | __END__ |