A1z-HTML5-Template
view release on metacpan or search on metacpan
lib/A1z/HTML5/Template.pm view on Meta::CPAN
#now open file/folder to fill "options"
if ( -f $folder_or_file )
{
# open as file
#$select .= qq{none};
}
elsif (-d $folder_or_file)
{
# open as dir and add all files in it to "options"
opendir(D, "$folder_or_file") or $select .= qq{<div class="error">$!</div>};
my @DIR = readdir(D);
while ( my $file = <each @DIR> )
{
# only if file contains alphabets, numbers, and dashes
next unless $file =~ /[a-zA-Z0-9\-]/;
# comment if you want subfolders also listed
next unless -f "$folder_or_file/$file";
lib/A1z/HTML5/Template.pm view on Meta::CPAN
sub edit_file
{
my $self = shift;
my $out;
my %in;
%in = (
file => "",
error => "",
action => "TemplateAdmin.cgi",
serial => '',
output_type => '',
@_,
);
if (-e -f "$in{file}")
{
open(FILE, "$in{file}") or $in{error} = "unable to open $in{file}";
my @file = <FILE>;
close FILE;
$out .= qq{
<article class="container">
<form action="$in{action}" method="post">
<input type="hidden" name="action" value="write">
};
lib/A1z/HTML5/Template.pm view on Meta::CPAN
sub write_file
{
my $self = shift;
my $out;
my %in;
%in =
(
file => "",
error => "",
powershell => "C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell.exe ",
@_,
);
my %vars;
use CGI;
my $q = new CGI;
%vars = $q->Vars();
my $action = $q->param('action');
if ( $action eq 'write')
{
if (-e -f "$in{file}")
{
# First, get file content to backup to another file
open(F, "$in{file}") or $in{error} .= "#1565 Unable to open file for reading. '$!' <br/>";
my @f = <F>;
# save original file content to backup file
open(BAK, ">$in{file},bak.txt") or $in{error} .= "#1570 Unable to create backup file '$in{file},bak.txt' '$!' <br/>";
for (@f)
{
print BAK qq{$_};
}
close BAK;
close F;
# recreate file, thereby deleting original content
open(DEL, ">$in{file}") or $in{error} .= "#1579 Unable to recreate file '$in{file}' '$!' <br/>";
print DEL "File ReCreated";
close DEL;
my %out;
for (keys %vars)
{
chomp $_;
chomp $vars{$_};
next if $_ eq 'action';
lib/A1z/HTML5/Template.pm view on Meta::CPAN
$name =~ s!(\r\n+|\n+)! RN !g;
$value =~ s!(\r\n+|\n+)! RN !g;
$value =~ s!^\s+!!g;
$out{"$name"} = "$value";
}
# Insert/Add new content
open(FILE, ">$in{file}") or $in{error} .= "#1582 Error writing to file '$in{file}' '$!' <br/>";
for (keys %out)
{
print FILE qq{$_\|$out{$_}\n};
}
close FILE;
if (-e -f "$in{file},bak.txt" and -e -f "$in{file}")
{
return "<div class='success'>Saved</div> <div class='error'>$in{error}</div>";
}
else
{
return "<div>#1605 Error saving file '$in{file}'</div> <div class='error'>$in{error}</div>";
}
}
else
{
return "File not found";
}
}
elsif ( $action eq 'newItem' )
{
return "$action";
lib/A1z/HTML5/Template.pm view on Meta::CPAN
sub display_gallery_thumbnails
{
my $self = shift;
my $out;
my %in;
%in = (
error => "",
images_dir => "/images/a1z-html5-template/",
thumbs_dir => "/images/a1z-html5-template/thumbs",
images_url => "/images/a1z-html5-template",
thumbs_url => "/thumbs/a1z-html5-template/thumbs",
width => "100",
height => "100",
@_,
);
if (-e -d "$in{images_dir}" and "$in{thumbs_dir}" )
{
opendir(TH, "$in{thumbs_dir}") or $in{error} .= qq{<p>$!</p>};
my @thumbs = readdir(TH);
close TH;
foreach ( @thumbs )
{
if ( $_ and $_ =~ /(.jpg|.gif|.jpeg|.png|.tiff)$/ )
{
$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};
}
}
}
else
{
$in{error} .= qq{<p>Image directory does not exist or is inaccessible. Make sure you provided the correct path.</p>};
$out = $in{error};
}
return $out;
}
# end display gallery thumbnails
( run in 0.489 second using v1.01-cache-2.11-cpan-65fba6d93b7 )