package WebGUI::Style; =head1 LEGAL ------------------------------------------------------------------- WebGUI is Copyright 2001-2004 Plain Black LLC. ------------------------------------------------------------------- Please read the legal notices (docs/legal.txt) and the license (docs/license.txt) that came with this distribution before using this software. ------------------------------------------------------------------- http://www.plainblack.com info@plainblack.com ------------------------------------------------------------------- =cut use strict; use Tie::CPHash; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Template; =head1 NAME Package WebGUI::Style =head1 DESCRIPTION This package contains utility methods for WebGUI's style system. =head1 SYNOPSIS use WebGUI::Style; $template = WebGUI::Style::getTemplate(); $html = WebGUI::Style::process($content); =head1 SUBROUTINES These subroutines are available from this package: =cut #------------------------------------------------------------------- =head2 getTemplate ( [ templateId ] ) Retrieves the template for this style. =over =item templateId The unique identifier for the template to retrieve. Defaults to the style template tied to the current page. =back =cut sub getTemplate { my $templateId = shift || $session{page}{styleId}; return WebGUI::Template::get($templateId,"style"); } #------------------------------------------------------------------- =head2 process ( content [ , templateId ] ) Returns a parsed style with content based upon the current WebGUI session information. =over =item content The content to be parsed into the style. Usually generated by WebGUI::Page::generate(). =item templateId The unique identifier for the template to retrieve. Defaults to the style template tied to the current page. =back =cut sub process { my %var; $var{'body.content'} = shift; my $templateId = shift; if ($session{page}{makePrintable}) { $templateId = $session{page}{printableStyleId}; } elsif ($session{page}{useAdminStyle} ne "" && $session{setting}{useAdminStyle}) { $templateId = $session{setting}{adminStyleId}; } elsif ($session{scratch}{personalStyleId} ne "") { $templateId = $session{scratch}{personalStyleId}; } elsif ($session{page}{useEmptyStyle}) { $templateId = 6; } my $type = lc($session{setting}{siteicon}); $type =~ s/.*\.(.*?)$/$1/; $var{'head.tags'} = ' '.$session{page}{head}{raw}; # generate additional link tags foreach my $url (keys %{$session{page}{head}{link}}) { $var{'head.tags'} .= ' '; if ($session{page}{synopsis}) { $var{'head.tags'} .= ' '; } } return WebGUI::Template::process(getTemplate($templateId),\%var); } 1;