From 3c547de4488307df5e9027363ad830aa0a84d049 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Fri, 20 Jun 2008 13:01:58 -0500 Subject: [PATCH] refactor C4::Auth::get_template_and_user for readability I'd like to add another template parameter to geta_template_and user, but found it diffiult due to unreadability. I stanadardized the whitespace in a portion of get_template_and_user, alphabetized the parameters, finding a duplicate in one spot, and then extracted the common template parameters that are set the same regardless of template type. Signed-off-by: Joshua Ferraro --- C4/Auth.pm | 168 +++++++++++++++++++++++++---------------------------- 1 file changed, 80 insertions(+), 88 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 9a3480968a..de55f120ff 100755 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -247,41 +247,44 @@ sub get_template_and_user { } + # these template parameters are set the same regardless of $in->{'type'} + $template->param( + "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1, + GoogleJackets => C4::Context->preference("GoogleJackets"), + KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"), + LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"), + LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"), + LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu", + TagsEnabled => C4::Context->preference("TagsEnabled"), + hide_marc => C4::Context->preference("hide_marc"), + 'item-level_itypes' => C4::Context->preference('item-level_itypes'), + patronimages => C4::Context->preference("patronimages"), + singleBranchMode => C4::Context->preference("singleBranchMode"), + ); + if ( $in->{'type'} eq "intranet" ) { $template->param( - intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), - intranetuserjs => C4::Context->preference("intranetuserjs"), - TemplateEncoding => C4::Context->preference("TemplateEncoding"), - AmazonContent => C4::Context->preference("AmazonContent"), - LibraryName => C4::Context->preference("LibraryName"), - LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"), - LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"), - LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"), - LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu", - AutoLocation => C4::Context->preference("AutoLocation"), - hide_marc => C4::Context->preference("hide_marc"), - patronimages => C4::Context->preference("patronimages"), + AmazonContent => C4::Context->preference("AmazonContent"), + AmazonSimilarItems => C4::Context->preference("AmazonSimilarItems"), + AutoLocation => C4::Context->preference("AutoLocation"), "BiblioDefaultView".C4::Context->preference("IntranetBiblioDefaultView") => 1, - advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), - suggestion => C4::Context->preference("suggestion"), - virtualshelves => C4::Context->preference("virtualshelves"), - LibraryName => C4::Context->preference("LibraryName"), - KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"), - IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), - IndependantBranches => C4::Context->preference("IndependantBranches"), - CircAutocompl => C4::Context->preference("CircAutocompl"), - FRBRizeEditions => C4::Context->preference("FRBRizeEditions"), - AmazonSimilarItems => C4::Context->preference("AmazonSimilarItems"), - 'item-level_itypes' => C4::Context->preference('item-level_itypes'), - canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), - intranetreadinghistory => C4::Context->preference("intranetreadinghistory"), - noItemTypeImages => C4::Context->preference("noItemTypeImages"), - singleBranchMode => C4::Context->preference("singleBranchMode"), - TagsEnabled => C4::Context->preference("TagsEnabled"), - GoogleJackets => C4::Context->preference("GoogleJackets"), - AuthorisedValueImages => C4::Context->preference("AuthorisedValueImages"), + CircAutocompl => C4::Context->preference("CircAutocompl"), + FRBRizeEditions => C4::Context->preference("FRBRizeEditions"), + IndependantBranches => C4::Context->preference("IndependantBranches"), + IntranetNav => C4::Context->preference("IntranetNav"), + IntranetmainUserblock => C4::Context->preference("IntranetmainUserblock"), + LibraryName => C4::Context->preference("LibraryName"), + LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"), + TemplateEncoding => C4::Context->preference("TemplateEncoding"), + advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), + canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), + intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + intranetreadinghistory => C4::Context->preference("intranetreadinghistory"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + intranetuserjs => C4::Context->preference("intranetuserjs"), + noItemTypeImages => C4::Context->preference("noItemTypeImages"), + suggestion => C4::Context->preference("suggestion"), + virtualshelves => C4::Context->preference("virtualshelves"), ); } else { @@ -289,62 +292,51 @@ sub get_template_and_user { my $LibraryNameTitle = C4::Context->preference("LibraryName"); $LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi; $LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg; - $template->param( - KohaAdminEmailAddress => "" . C4::Context->preference("KohaAdminEmailAddress"), - AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), - suggestion => "" . C4::Context->preference("suggestion"), - OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), - virtualshelves => "" . C4::Context->preference("virtualshelves"), - OpacNav => "" . C4::Context->preference("OpacNav"), - opacheader => "" . C4::Context->preference("opacheader"), - opaccredits => "" . C4::Context->preference("opaccredits"), - opacsmallimage => "" . C4::Context->preference("opacsmallimage"), - opaclargeimage => "" . C4::Context->preference("opaclargeimage"), - opaclayoutstylesheet => "". C4::Context->preference("opaclayoutstylesheet"), - opaccolorstylesheet => "". C4::Context->preference("opaccolorstylesheet"), - OPACUserCSS => "". C4::Context->preference("OPACUserCSS"), - opaclanguagesdisplay => "". C4::Context->preference("opaclanguagesdisplay"), - opacuserlogin => "" . C4::Context->preference("opacuserlogin"), - OpacMainUserBlock => "" . C4::Context->preference("OpacMainUserBlock"), - OPACURLOpenInNewWindow => "" . C4::Context->preference("OPACURLOpenInNewWindow"), - opacbookbag => "" . C4::Context->preference("opacbookbag"), - TemplateEncoding => "". C4::Context->preference("TemplateEncoding"), - AmazonContent => "" . C4::Context->preference("AmazonContent"), - OPACShelfBrowser => "". C4::Context->preference("OPACShelfBrowser"), - OPACAmazonSimilarItems => "" . C4::Context->preference("OPACAmazonSimilarItems"), - LibraryName => "" . C4::Context->preference("LibraryName"), - LibraryNameTitle => "" . $LibraryNameTitle, - LoginBranchcode => (C4::Context->userenv?C4::Context->userenv->{"branch"}:"insecure"), - LoginBranchname => C4::Context->userenv?C4::Context->userenv->{"branchname"}:"", - LoginFirstname => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"), - LoginSurname => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu", - OpacPasswordChange => C4::Context->preference("OpacPasswordChange"), - opacreadinghistory => C4::Context->preference("opacreadinghistory"), - opacuserjs => C4::Context->preference("opacuserjs"), - OpacCloud => C4::Context->preference("OpacCloud"), - OpacTopissue => C4::Context->preference("OpacTopissue"), - OpacAuthorities => C4::Context->preference("OpacAuthorities"), - OpacBrowser => C4::Context->preference("OpacBrowser"), - RequestOnOpac => C4::Context->preference("RequestOnOpac"), - OPACItemHolds => C4::Context->preference("OPACItemHolds"), - reviewson => C4::Context->preference("reviewson"), - hide_marc => C4::Context->preference("hide_marc"), - patronimages => C4::Context->preference("patronimages"), - hidelostitems => C4::Context->preference("hidelostitems"), - mylibraryfirst => C4::Context->preference("SearchMyLibraryFirst"), - "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1, - OPACFRBRizeEditions => C4::Context->preference("OPACFRBRizeEditions"), - 'item-level_itypes' => C4::Context->preference('item-level_itypes'), - 'Version' => C4::Context->preference('Version'), - singleBranchMode => C4::Context->preference("singleBranchMode"), - XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"), - XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"), - TagsEnabled => C4::Context->preference("TagsEnabled"), - GoogleJackets => C4::Context->preference("GoogleJackets"), - AuthorisedValueImages => C4::Context->preference("AuthorisedValueImages"), - OPACBaseURL=> ($in->{'query'}->https() ? "https://" : "http://") . - $ENV{'SERVER_NAME'} . - ($ENV{'SERVER_PORT'} eq ($in->{'query'}->https() ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"), + $template->param( + AmazonContent => "" . C4::Context->preference("AmazonContent"), + AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), + AuthorisedValueImages => C4::Context->preference("AuthorisedValueImages"), + LibraryName => "" . C4::Context->preference("LibraryName"), + LibraryNameTitle => "" . $LibraryNameTitle, + LoginBranchname => C4::Context->userenv?C4::Context->userenv->{"branchname"}:"", + OPACAmazonSimilarItems => "" . C4::Context->preference("OPACAmazonSimilarItems"), + OPACFRBRizeEditions => C4::Context->preference("OPACFRBRizeEditions"), + OPACItemHolds => C4::Context->preference("OPACItemHolds"), + OPACShelfBrowser => "". C4::Context->preference("OPACShelfBrowser"), + OPACURLOpenInNewWindow => "" . C4::Context->preference("OPACURLOpenInNewWindow"), + OPACUserCSS => "". C4::Context->preference("OPACUserCSS"), + OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), + OpacAuthorities => C4::Context->preference("OpacAuthorities"), + OPACBaseURL => ($in->{'query'}->https() ? "https://" : "http://") . + $ENV{'SERVER_NAME'} . + ($ENV{'SERVER_PORT'} eq ($in->{'query'}->https() ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"), + OpacBrowser => C4::Context->preference("OpacBrowser"), + OpacCloud => C4::Context->preference("OpacCloud"), + OpacMainUserBlock => "" . C4::Context->preference("OpacMainUserBlock"), + OpacNav => "" . C4::Context->preference("OpacNav"), + OpacPasswordChange => C4::Context->preference("OpacPasswordChange"), + OpacTopissue => C4::Context->preference("OpacTopissue"), + RequestOnOpac => C4::Context->preference("RequestOnOpac"), + TemplateEncoding => "". C4::Context->preference("TemplateEncoding"), + 'Version' => C4::Context->preference('Version'), + XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"), + XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"), + hidelostitems => C4::Context->preference("hidelostitems"), + mylibraryfirst => C4::Context->preference("SearchMyLibraryFirst"), + opacbookbag => "" . C4::Context->preference("opacbookbag"), + opaccolorstylesheet => "". C4::Context->preference("opaccolorstylesheet"), + opaccredits => "" . C4::Context->preference("opaccredits"), + opacheader => "" . C4::Context->preference("opacheader"), + opaclanguagesdisplay => "". C4::Context->preference("opaclanguagesdisplay"), + opaclargeimage => "" . C4::Context->preference("opaclargeimage"), + opaclayoutstylesheet => "". C4::Context->preference("opaclayoutstylesheet"), + opacreadinghistory => C4::Context->preference("opacreadinghistory"), + opacsmallimage => "" . C4::Context->preference("opacsmallimage"), + opacuserjs => C4::Context->preference("opacuserjs"), + opacuserlogin => "" . C4::Context->preference("opacuserlogin"), + reviewson => C4::Context->preference("reviewson"), + suggestion => "" . C4::Context->preference("suggestion"), + virtualshelves => "" . C4::Context->preference("virtualshelves"), ); } $template->param(listloop=>[{shelfname=>"Freelist", shelfnumber=>110}]); -- 2.20.1