Skip to content

Commit

Permalink
Item2060:
Browse files Browse the repository at this point in the history
   * removed GETSKINSTYLE in favour of using ADDTOHEAD
   * ajusted css to latest TablePlugin
   * using relative urls where possible 



git-svn-id: http://svn.foswiki.org/trunk/NatSkinPlugin@4916 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Sep 14, 2009
1 parent 931f267 commit 2932933
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 56 deletions.
16 changes: 4 additions & 12 deletions data/System/NatSkinPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="micha" date="1247226122" format="1.1" reprev="1.2" version="1.2"}%
%META:TOPICINFO{author="ProjectContributor" date="1247226122" format="1.1" reprev="1.2" version="1.2"}%
<!--

PLEASE DO NOT EDIT THIS TOPIC
Expand Down Expand Up @@ -57,17 +57,6 @@ The optional =%lt;format>= string may contain the following variables
For example =%<nop>FORMBUTTON{"| $1"}%= will generate a pipe and the formbutton
if possible. See the =edit.nat.tmpl= template file of the !NatSkin.

---+++ GETSKINSTYLE
*Syntax*: =%<nop>GETSKINSTYLE%=

get the current skin style; the priority is
1 urlparam =style=&lt;name>=,
2 value of the session variable =NATSKIN_STYLE= and
3 preference value =SKINSTYLE= set in
(a) the user preferences
(b) the WebPreferences or
(c) %SYSTEMWEB%.DefaultPreferences or %USERSWEB%.SitePreferences

---+++ KNOWNSTYLES
*Syntax*: =%<nop>KNOWNSTYLES%=

Expand Down Expand Up @@ -240,6 +229,9 @@ See NatSkin#Installation_Instructions
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 14 Sep 2009: | removed GETSKINSTYLE in favour of using ADDTOHEAD; \
ajusted css to latest !TablePlugin; \
using relative urls where possible |
| 20 Aug 2009: | added support to switch javascript parmeters via templating; \
using relative urls as much as possible; \
be more robust when selecting unknown themes; \
Expand Down
92 changes: 48 additions & 44 deletions lib/Foswiki/Plugins/NatSkinPlugin.pm
Expand Up @@ -49,7 +49,7 @@ $ENDWW = qr/$|(?=[\s\,\.\;\:\!\?\)])/m;
$emailRegex = qr/([a-z0-9!+$%&'*+-\/=?^_`{|}~.]+)\@([a-z0-9\-]+)([a-z0-9\-\.]*)/i;

$VERSION = '$Rev$';
$RELEASE = '3.93';
$RELEASE = '3.94';
$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'Theming engine for NatSkin';

Expand All @@ -76,7 +76,6 @@ sub initPlugin {

# register tags
Foswiki::Func::registerTagHandler('GETSKINSTATE', \&renderGetSkinState);
Foswiki::Func::registerTagHandler('GETSKINSTYLE', \&renderGetSkinStyle);
Foswiki::Func::registerTagHandler('WEBLINK', \&renderWebLink);
Foswiki::Func::registerTagHandler('USERACTIONS', \&renderUserActions);
Foswiki::Func::registerTagHandler('NATWEBLOGO', \&renderNatWebLogo);
Expand All @@ -94,36 +93,16 @@ sub initPlugin {
Foswiki::Func::registerTagHandler('CURREV', \&renderCurRevision);
Foswiki::Func::registerTagHandler('NATMAXREV', \&renderMaxRevision);

my $skin = Foswiki::Func::getSkin();
if ($skin =~ /\bnat\b/) {
Foswiki::Func::setPreferencesValue('FOSWIKI_STYLE_URL', '%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseStyle.css');
Foswiki::Func::setPreferencesValue('FOSWIKI_COLORS_URL', '%NATSTYLEURL%');

Foswiki::Func::addToHEAD('NATSKIN', <<'HERE', 'NATSKIN::OPTS, JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::SUPERFISH');
<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/JavascriptFiles/foswikilib.js"></script>
<script type="text/javascript" src="%PUBURL%/%SYSTEMWEB%/NatSkin/natskin.js"></script>
HERE

}

# preference values
$useEmailObfuscator = $Foswiki::cfg{NatSkin}{ObfuscateEmails};

$doneInitSkinState = 0;

# don't initialize the following two to keep them in memory using perl accelerators
#$doneInitKnownStyles = 0;
#$lastStylePath = '';

%emailCollection = (); # collected email addrs
$nrEmails = 0; # number of collected addrs
%maxRevs = (); # cache for getMaxRevision()
%seenWebComponent = (); # used to prevent deep recursion
$request = Foswiki::Func::getCgiQuery();

# get skin state from session
initKnownStyles();
initSkinState();
my $skin = Foswiki::Func::getSkin();

if ($useEmailObfuscator) {
my $isScripted = Foswiki::Func::getContext()->{'command_line'}?1:0;
Expand All @@ -142,7 +121,29 @@ HERE
}
#writeDebug("useEmailObfuscator=$useEmailObfuscator");

#writeDebug("done doInit");
my $doRefresh = $request->param('refresh') || ''; # refresh internal caches
$doRefresh = ($doRefresh eq 'on')?1:0;
if ($doRefresh) {
$doneInitKnownStyles = 0;
$lastStylePath = '';
}

# get skin state from session
initKnownStyles();
initSkinState();

if ($skin =~ /\bnat\b/) {
Foswiki::Func::setPreferencesValue('FOSWIKI_STYLE_URL', '%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseStyle.css');
Foswiki::Func::setPreferencesValue('FOSWIKI_COLORS_URL', '%NATSTYLEURL%');

Foswiki::Func::addToHEAD('NATSKIN::JS', <<'HERE', 'NATSKIN, NATSKIN::OPTS, JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::SUPERFISH');
<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/JavascriptFiles/foswikilib.js"></script>
<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/NatSkin/natskin.js"></script>
HERE

Foswiki::Func::addToHEAD('NATSKIN', "\n".getSkinStyle(), 'TABLEPLUGIN_default');
}

return 1;
}
###############################################################################
Expand Down Expand Up @@ -331,13 +332,9 @@ sub initSkinState {
$theStyle = $request->param('style') || $request->param('skinstyle') || '';

my $theReset = $request->param('resetstyle') || ''; # get back to site defaults
my $theRefresh = $request->param('refresh') || ''; # refresh internal caches
$theRefresh = ($theRefresh eq 'on')?1:0;
$theReset = ($theReset eq 'on')?1:0;

#writeDebug("theReset=$theReset, theRefresh=$theRefresh");

if ($theRefresh || $theReset || $theStyle eq 'reset') {
if ($theReset || $theStyle eq 'reset') {
# clear the style cache
$doneInitKnownStyles = 0;
$lastStylePath = '';
Expand Down Expand Up @@ -431,7 +428,7 @@ sub initSkinState {
$skinState{'style'} = $firstStyle if $state == 1;
}

$skinState{'style'} = $theStyle;
$skinState{'style'} = $theStyle; ## SMELL: seems to override cycle styles
my $themeRecord = getThemeRecord($theStyle);
#writeDebug("theStyle=$theStyle");

Expand Down Expand Up @@ -608,6 +605,9 @@ sub initSkinState {
$skin = "$prefix,$skin" unless $skin =~ /\b$prefix\b/;
}

# auto-add natedit
$skin = "natedit,$skin" unless $skin =~ /\b(natedit)\b/;

#writeDebug("setting skin to $skin");

# store session prefs
Expand Down Expand Up @@ -797,7 +797,7 @@ sub getThemeRecord {
}

###############################################################################
sub renderGetSkinStyle {
sub getSkinStyle {

my $theStyle;
$theStyle = $skinState{'style'} || 'off';
Expand All @@ -820,33 +820,33 @@ sub renderGetSkinStyle {
#writeDebug("knownStyle=".join(',', sort keys %knownStyles));

$text = <<"HERE";
<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/NatSkin/print.css' type='text/css' media='print' />
<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseStyle.css' type='text/css' media='all' />
<link rel='stylesheet' href='$themeRecord->{styles}{$theStyle}' type='text/css' media='all' />
<link rel=\"stylesheet\" href=\"%PUBURLPATH%/%SYSTEMWEB%/NatSkin/print.css\" type=\"text/css\" media=\"print\" />
<link rel=\"stylesheet\" href=\"%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseStyle.css\" type=\"text/css\" media=\"all\" />
<link rel=\"stylesheet\" href=\"$themeRecord->{styles}{$theStyle}\" type=\"text/css\" media=\"all\" />
HERE

if ($skinState{'border'} eq 'on' && $themeRecord->{borders}{$theStyle}) {
$text .= <<"HERE";
<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseBorder.css' type='text/css' media='all' />
<link rel='stylesheet' href='$themeRecord->{borders}{$theStyle}' type='text/css' media='all' />
<link rel=\"stylesheet\" href=\"%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseBorder.css\" type=\"text/css\" media=\"all\" />
<link rel=\"stylesheet\" href=\"$themeRecord->{borders}{$theStyle}\" type=\"text/css\" media=\"all\" />
HERE
} elsif ($skinState{'border'} eq 'thin' && $themeRecord->{thins}{$theStyle}) {
$text .= <<"HERE";
<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseThin.css' type='text/css' media='all' />
<link rel='stylesheet' href='$themeRecord->{thins}{$theStyle}' type='text/css' media='all' />
<link rel=\"stylesheet\" href=\"%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseThin.css\" type=\"text/css\" media=\"all\" />
<link rel=\"stylesheet\" href=\"$themeRecord->{thins}{$theStyle}\" type=\"text/css\" media=\"all\" />
HERE
}

if ($skinState{'buttons'} eq 'on' && $themeRecord->{buttons}{$theStyle}) {
$text .= <<"HERE";
<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseButtons.css' type='text/css' media='all' />
<link rel='stylesheet' href='$themeRecord->{buttons}{$theStyle}' type='text/css' media='all' />
<link rel=\"stylesheet\" href=\"%PUBURLPATH%/%SYSTEMWEB%/NatSkin/BaseButtons.css\" type=\"text/css\" media=\"all\" />
<link rel=\"stylesheet\" href=\"$themeRecord->{buttons}{$theStyle}\" type=\"text/css\" media=\"all\" />
HERE
}

if ($theVariation && $themeRecord->{variations}{$theVariation}) {
$text .= <<"HERE";
<link rel='stylesheet' href='$themeRecord->{variations}{$theVariation}' type='text/css' media='all' />
<link rel=\"stylesheet\" href=\"$themeRecord->{variations}{$theVariation}\" type=\"text/css\" media=\"all\" />
HERE
}

Expand Down Expand Up @@ -1128,7 +1128,9 @@ sub renderUserActions {
$pdfString = Foswiki::Func::expandTemplate('PDF_ACTION_RESTRICTED');
} else {
my $url;
if (Foswiki::Func::getContext()->{GenPDFPrincePluginEnabled}) {
my $context = Foswiki::Func::getContext();
if ($context->{GenPDFPrincePluginEnabled} ||
$context->{GenPDFWebkitPluginEnabled}) {
$url = $session->getScriptUrl(0, 'view', $baseWeb, $baseTopic,
'contenttype'=>'application/pdf');
} else {
Expand Down Expand Up @@ -1598,7 +1600,7 @@ sub renderNatWebLogo {
my $url = Foswiki::Func::getPreferencesValue('NATWEBLOGOURL') ||
Foswiki::Func::getPreferencesValue('WEBLOGOURL') ||
Foswiki::Func::getPreferencesValue('WIKILOGOURL') ||
Foswiki::Func::getPreferencesValue('%SCRIPTURL{"view"}%/%USERSWEB%/%HOMETOPIC%');
Foswiki::Func::getPreferencesValue('%SCRIPTURLPATH{"view"}%/%USERSWEB%/%HOMETOPIC%');

my $variation = lc $skinState{variation};
my $style = lc $skinState{style};
Expand Down Expand Up @@ -1633,7 +1635,9 @@ sub renderNatWebLogo {

#############################################################################
sub renderNatStyleUrl {
return Foswiki::Func::getPubUrlPath.'/'.$knownStyles{$skinState{style}};
my $theStyle = lc($skinState{'style'});
my $themeRecord = getThemeRecord($theStyle);
return $themeRecord->{styles}{$theStyle};
}

###############################################################################
Expand Down

0 comments on commit 2932933

Please sign in to comment.