Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

[HACK] Show images in the admin area...

Quote Reply
[HACK] Show images in the admin area...
I know there has been a lot of requests for this feature, and I'm not sure if it will be available in the new version of LSQL. I have been doing some work on ImageSQL today, and thought I would take the plunge, and try to show images in the admin area (should work with view/modify/delete).

You need to replace the following in /admin/GT/SQL/Display/HTML.pm;

Code:
$out .= qq! <font $self->{font}><font size=1><i><a href="$url" target=_blank>view</a></i></font></font>!;

(about line 507) ...with...

Code:
$out .= qq! <font $self->{font}><font size=1><i><a href="$url" target=_blank>view</a></i></font><BR><img src="$url"></font>!;

... and the whole routine of sub display_text (in the same file);

Code:
sub display_text {
# ---------------------------------------------------------------
my $self = shift;
my $opts = shift or return $self->error ("BADARGS", "FATAL", "No hash ref passed to form creator display_text");
my $values = shift;
my $def = exists $opts->{def} ? $opts->{def} : return $self->error ("BADARGS", "FATAL", "No type hash passed to view creator display_text (" . (caller())[2] . ")" );
my $val = exists $opts->{value} ? $opts->{value} : (exists $def->{default} ? $def->{default} : '');
my $pval = $val;
defined $val or ($val = '');
_escape(\$val);

# If they are using checkbox/radio/selects then we map form_names => form_values.
if (ref $def->{form_names} and ref $def->{form_values}) {
if (@{$def->{form_names}} and @{$def->{form_values}}) {
my %map = map { $def->{form_names}->[$_] => $def->{form_values}->[$_] } (0 .. $#{$def->{form_names}});
my @keys = split /\Q$INPUT_SEPARATOR\E|\n/, $val;
$val = '';

foreach (@keys) {
$val .= $map{$_} ? $map{$_} : $_;
$val .= "<br>";
}
}
}

if ($def->{form_type} and uc $def->{form_type} eq 'FILE' and not $self->{hide_downloads} and $self->{url}) {
$pval or return $val;

my @parts = split /\./, $opts->{name};
my $name = pop @parts;
my $dbname = shift @parts || $self->{db}->name;
my $prefix = $self->{db}->prefix;
$dbname =~ s,^$prefix,, if ($prefix);
my $colname = $opts->{name}; $colname =~ s,^$dbname\.,,g;

my @pk = $self->{db}->pk(); @pk == 1 or return;
my $url = _reparam_url( $self->{url}, { do => 'download_file', id => $values->{$pk[0]}, cn => $colname, db => $dbname }, [qw( do id cn db )] );
$val .= qq! <font $self->{font}><font size=1><i><a href="$url">download</a></i></font></font>!;

#######

my $DB = new GT::SQL '/path/to/admin/defs';

# get the actual path to where the file is/will be saved...
my $schema = $DB->table('Links')->cols;
my $path = $schema->{$colname}->{'file_save_url'};
$path =~ s,/$,,; # get rid of trailing / at end of $path

# now we have the highest ID, lets get the image stuff for this link.
my $tbl = $DB->table('Links');
my $fh = $tbl->file_info( $colname, $values->{$pk[0]} ); # return a glob reference to the file that you can print <$fh> if you want
my $rel_path = $fh->File_URL;
undef $fh; # explicit close of the filehandle for good measure

$rel_path =~ s|([^\/]+)$|GT::CGI->escape( $1 )|e;

if ($rel_path !~ /(\.gif|\.jpg|\.jpeg|\.bmp)/i) { $rel_path = ''; } else {
$rel_path = qq|<img src="$rel_path">|;
}

########


$url = _reparam_url( $self->{url}, { do => 'view_file', id => $values->{$pk[0]}, cn => $colname, db => $dbname }, [qw( do id cn db )] );
$val .= qq! <font $self->{font}><font size=1><i><a href="$url" target=_blank>view</a></i></font></font><BR>$rel_path!;
}

return $val;
}

NOTE!!!! You need to change the part in green, to the path to your /admin/defs/ folder, otherwise you will get an error!

Please note, this works on my installation... but be safe, and backup the old version first, in case something doesn't go quite right!

And last but not least, enjoy!

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread [HACK] Show images in the admin area... Andy 2168 Mar 15, 2004, 4:15 AM
Thread Re: [Andy] [HACK] Show images in the admin area...
webslicer 2035 Mar 15, 2004, 9:58 AM
Thread Re: [webslicer] [HACK] Show images in the admin area...
Andy 2035 Mar 15, 2004, 10:03 AM
Thread Re: [Andy] [HACK] Show images in the admin area...
webslicer 2059 Mar 15, 2004, 10:23 AM
Thread Re: [webslicer] [HACK] Show images in the admin area...
Andy 2050 Mar 15, 2004, 10:30 AM
Post Re: [Andy] [HACK] Show images in the admin area...
webslicer 2025 Mar 15, 2004, 10:43 AM