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!
Quote Reply
Re: [Andy] [HACK] Show images in the admin area... In reply to
Interesting!

What exactly does this do and how is it used?
I'm not quite visualizing it..

Do you have a screenshot?

I'd think that to justify modifying the underlying code of Links there must be a good reason, so can you tell us more?
Quote Reply
Re: [webslicer] [HACK] Show images in the admin area... In reply to
Well, currently you only get 'view' and 'download' next to the FILE fields. This will actually show you the image with an <img> tag IN THE PAGE ...for example, you would now see;

Code:
Field Name - view download
[ IMG HERE ]
[ ] delete (checkbox)
upload new image here

Not sure if that makes much more sense... its more of a visual thing. Give it a go... if you don't like it , you can change it back :)

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!
Quote Reply
Re: [Andy] [HACK] Show images in the admin area... In reply to
I'm not sure I've got this right... trying to understand how it is used.

It's for users or webmaster?

It's to preview user uploaded images so the webmaster can delete them if not desirable?
Also to check if the image uploaded correctly?

And these images are photo galleries or postcards, etc hooked into Links??

What if they are very large? Does this throw the display off?

and it's NOT to make the admin section prettier?

Thanks.
Quote Reply
Re: [webslicer] [HACK] Show images in the admin area... In reply to
Quote:
It's for users or webmaster?

Webmasters.

Quote:
t's to preview user uploaded images so the webmaster can delete them if not desirable?
Also to check if the image uploaded correctly?

Yeah, pretty much.

Quote:
And these images are photo galleries or postcards, etc hooked into Links??

It will just show images that have been uploaded in SIMPLE or HASHED mode (i.e where you can add an image directly from the admin panel).

Quote:
What if they are very large? Does this throw the display off?

I could hack it so that it shows the thumbnailed image (if you have the Thumb_Images plugin installed), rather than the full sized image.

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!
Quote Reply
Re: [Andy] [HACK] Show images in the admin area... In reply to
Thanks very much for the answers Andy.
I will plan on trying it out!