# Copyright 2002-2008 Josh Clark and Global Moxie, LLC. This code cannot be
# redistributed without permission from globalmoxie.com.  For more
# information, consult your Big Medium license.
#
# $Id: Public.pm 3237 2008-08-21 17:11:06Z josh $

package BigMed::App::Web::Public;
use strict;
use warnings;
use utf8;
use Carp;
$Carp::Verbose = 1;
use base qw(BigMed::App::Web);
use BigMed::Prefs;

sub cgiapp_init {
    my $app = shift;
    $app->SUPER::cgiapp_init;
    my $site_id = $app->path_site or return;

    #change Big Medium language lexicon if public site is different
    #language than env('LANGUAGE')
    if ( !BigMed::Prefs->pref_exists('html_htmlhead_lang') ) {
        BigMed::Prefs->register_pref( 'html_htmlhead_lang',
            { default => 'en', edit_type => 'raw_text' } );
    }

    #fetch pref directly instead of via site for faster operation,
    #since we're not using a cached site object
    my $pref = BigMed::Prefs->fetch(
        { site => $site_id, section => 0, name => 'html_htmlhead_lang' } )
        or return;
    my $lang = ($pref->pref_value)[0] or return;
    my $bm_lang = lc substr( $app->env('LANGUAGE'), 0, 2 );
    if ( $lang ne $bm_lang ) {
        my $bm = $app->bigmed;
        $bm->set_env( 'LANGUAGE', $lang );
        my $lang_obj = BigMed::Language->get_handle($lang)->customize_lang();
        $bm->{_lang} = $lang_obj;
    }
    return;
}

1;
__END__

=head1 NAME

BigMed::App::Web::Public - Big Medium application class for run modes
to be displayed to public-site visitors in the language of the public
site.

=head1 DESCRIPTION

BigMed::App::Web::Public is a subclass of BigMed::App::Web. All subclasses
of BigMed::App::Web::Public automatically have the Big Medium language
lexicon updated to the language indicated in the current site's page-header
preferences, overriding the control-panel site language. The current site
is taken from the id provided in C<<$app->path_site()>>.

=head1 AUTHOR & COPYRIGHTS

This module and all Big Medium modules are copyright Josh Clark
and Global Moxie. All rights reserved.

Use of this module and the Big Medium content
management system are governed by Global Moxie's software licenses
and may not be used outside of the terms and conditions outlined
there.

For more information, visit the Global Moxie website at
L<http://globalmoxie.com/>.

Big Medium and Global Moxie are service marks of Global Moxie
and Josh Clark. All rights reserved.

=cut

