# ==================================================================
# Gossamer Forum - Advanced web community
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# Revision : $Id: GUI.pm,v 1.6 2002/10/30 01:37:06 jagerman Exp $
#
# Copyright (c) 2001 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================
#
# Handles sections of template code that would make templates slow and overly
# complex.
#
package GForum::GUI;
# ==================================================================
use strict;
use vars qw/%GUI $ERROR/;
use GT::Base qw/$PERSIST/;
use GForum qw/:user :forum $CFG $IN/;
use GForum::Template;
%GUI = (
post_display_options => <<'END_OF_CODE',
my %input = @_;
my (%link_pos, $j);
if ($input{order}) {
for (split /\s*,\s*/, $input{order}) {
if (/^(edit|delete|cant_post|reply|quote)$/) {
$link_pos{$1} = $j++;
}
}
}
for (qw/edit delete quote reply/) {
$input{$_} ||= ucfirst;
$link_pos{$_} ||= $j++;
}
$input{cant_post} ||= "Can't Post";
$link_pos{cant_post} ||= $j++;
$input{a_attribs} ||= ""; $input{a_attribs} = " $input{a_attribs}" if $input{a_attribs};
$input{separator} ||= " | ";
$input{'gforum.cgi'} ||= "gforum.cgi";
my $tags = GForum::Template->tags;
my $hidden_query = ${$tags->{hidden_query} || \''};
$hidden_query = ";" . $hidden_query if $hidden_query;
my $return = '';
unless ($tags->{preview} or $tags->{deleteview} or $tags->{hide_post_menu} or $tags->{post_deleted}) {
if (!$tags->{post_locked} or $tags->{user_perm_moderator}) {
my @pieces;
if ($tags->{user_perm_edit} or $tags->{user_perm_moderator}) {
$pieces[$link_pos{edit}] = qq|$input{edit}|;
}
if (not $tags->{post_deleted} and ($tags->{user_perm_delete} or $tags->{user_perm_moderator})) {
$pieces[$link_pos{delete}] = qq|$input{delete}|;
}
if ($tags->{user_forum_permission} < FORUM_PERM_REPLY) {
$pieces[$link_pos{cant_post}] = $input{cant_post};
}
else {
$pieces[$link_pos{quote}] = qq|$input{quote}|
if $tags->{forum_style} % 2; # The forum allows markup
$pieces[$link_pos{reply}] = qq|$input{reply}|;
}
$return .= join $input{separator}, grep $_, @pieces;
}
else {
$return .= ' ';
}
}
elsif ($tags->{post_deleted} and $tags->{user_perm_moderator}) {
$return .= qq|$input{delete}|;
}
return \$return;
END_OF_CODE
paging => <<'END_OF_CODE',
my %input = @_;
my $tags = GForum::Template->tags;
$input{first} ||= q|
|;
$input{first_grey} ||= q|
|;
$input{prev} ||= q|
|;
$input{prev_grey} ||= q|
|;
$input{next} ||= q|
|;
$input{next_grey} ||= q|
|;
$input{last} ||= q|
|;
$input{last_grey} ||= q|
|;
$input{view_all} ||= q|View All|;
$input{pages} ||= 9;
$input{'...'} ||= '...';
$input{'first_...'} ||= 1;
$input{'last_...'} ||= 1;
$input{before_page} ||= q||;
$input{after_page} ||= q||;
$input{before_current} ||= q||;
$input{after_current} ||= q||;
$input{'gforum.cgi'} ||= 'gforum.cgi';
for (keys %input) {
$input{$_} =~ s/\$image_url/$tags->{image_url}/g;
}
my $hidden_query = ${$tags->{hidden_query} || \''};
return '' if $tags->{this_do} eq 'post_view_flat' and $tags->{mh} == -1; # In a flat view with no mh, there is no paging.
require GForum::Utils;
my $paging = GForum::Utils::paging(@$tags{qw/num_page_items mh this_page/}, @input{qw/pages last_.../});
($paging, my ($top_page, $ddd)) = @$paging{'paging', 'top_page', 'dotdotdot'};
my $return = '';
my $link = sub {
my ($page, $disp) = @_;
$return .= qq|$disp\n|;
};
unless ($top_page == 1) {
if ($tags->{this_page} == 1) {
$return .= $input{first_grey} . "\n";
$return .= $input{prev_grey} . "\n";
}
else {
$link->(1, $input{first});
$link->($tags->{this_page} - 1, $input{prev});
}
if (@$paging and $paging->[0]->{page_num} > 1 and $input{'first_...'}) {
$link->(1, qq|$input{before_page}1$input{after_page}|);
$return .= "$input{before_page}$input{'...'}" . ($input{after_page} || " ") if $paging->[0]->{page_num} > 2;
}
for (@$paging) {
if ($_->{is_current_page}) {
$return .= qq|$input{before_current}$_->{page_num}$input{after_current}\n|;
}
else {
$link->($_->{page_num}, qq|$input{before_page}$_->{page_num}$input{after_page}|);
}
}
if ($ddd) {
$return .= "$input{before_page}$input{'...'}" . ($input{after_page} || " ");
$link->($top_page, "$input{before_page}$top_page$input{after_page}");
}
if ($tags->{this_page} >= $top_page) {
$return .= $input{next_grey} . "\n";
$return .= $input{last_grey} . "\n";
}
else {
$link->($tags->{this_page} + 1, $input{next});
$link->($top_page, $input{last});
}
if ($tags->{this_do} eq 'post_view_flat') {
$return .= qq| $input{view_all}\n|;
}
}
return \$return;
END_OF_CODE
);
sub draw {
my %input = @_;
return unless $input{draw};
return unless exists $GUI{$input{draw}};
my $ok = (ref $GUI{$input{draw}} eq 'CODE' or _compile($input{draw}));
return "Unable to compile \$GForum::GUI::GUI{$input{draw}}: $ERROR" if not $ok;
my $return = GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins/GForum', "gui_$input{draw}", $GUI{$input{draw}}, %input);
$return = $GUI{$input{draw}}->(%input);
$return;
}
sub _compile {
my $c = shift;
$ERROR = undef;
return 1 if ref $GUI{$c} eq 'CODE'; # Already compiled
local $@;
$GUI{$c} = eval qq|sub {\n$GUI{$c}\n}|;
$ERROR = $@ if $@;
return if $ERROR; # Uh oh - couldn't compile
return 1;
}
if ($PERSIST) {
for (keys %GUI) {
_compile($_);
}
}
1;