package SSS; #======================================================================= # *************************************************************** # * CGI-SSS(Style Sheets Selector:Three S) Ver.1.1.4 * # *************************************************************** # original made by SHIMODA "Piro" Hiroshi # http://white.sakura.ne.jp/~piro/ #======================================================================= # Tutorial (“ú–{Oe‚A‚I�a–3‚Í120?s–Ú‚­‚ç‚c‚©‚ç�a‚É‚ ‚e‚Ü‚·) #======================================================================= # # This is a package for Perl4 or later. # # ***STEP1: Create the config file # # At first, you have to make a Perl-script like folloing, as # "SSSinit.pl". Put the file into the directory same to this file. # ---------------------- start---------------------- # # # define styles # &SSS'addStyle("style1", "/~piro/style1.css", "screen"); # &SSS'addStyle("style2", "/~piro/style2.css\n/~piro/style2sub.css", "screen"); # # Options are "Title", "Path" and "Media". # # You can use multiple styleseets in a line, like the second sample above. # # (then you have to split each sheet by "\n") # # The first style ("style1" in the sample) is the default style. # # If the title is "" (nullstring), the style will be a permanent # # stylesheet. # # # Label for "No Style" item # $SSS'noStyleLabel = 'No Style'; # # # the path for cookie whith stores the selected style. # $SSS'targetRoot = '/~piro/'; # # # If you use this script for webpages made by XHTML, set "1". # # If not, "0". Default is "0". # $SSS'outputAsXHTML = 1; # # # If you set "1", stylesheets not selected are output as alternate # # stylesheets. Default is "0". # $SSS'shouldLinkAlternateStyleSheets = 1; # # MSIE loads all of alternate stylesheets so I recommend you to use "0". # # # misc. # $SSS'formLabel = 'SelectStyle:'; # label of the form # $SSS'formAccessKey = 'S'; # accesskey for the form # $SSS'applyLabel = 'Go!'; # label of the button # $SSS'applyAccessKey = 'G'; # accesskey for the button # # 1; # this line is required! # ---------------------- end------------------------ # # # ***STEP2: Embed into the header section # # Make a new CGI script as "header.cgi", and call it by SSI in webpages. # ---------------------- start---------------------- # #!/usr/local/bin/perl # # You will change this line by your environment. # # require "./SSS.pl"; # load package # require "./SSSinit.pl"; # load config file # # &SSS'initLinks(); # &SSS'writeLinks(); # # Note: If you hand "1" as the argument, this function doesn't print # # Content-type info of the HTTP header. # # > &SSS'writeLinks(1); # # ---------------------- end------------------------ # To call this from webpages, embed a line like following, to the head # section (...) of weblages: # > # > ... # > # > ... # > # # # ***STEP3: Embed the form to switch styles # # Make a new CGI script as "form.cgi" and call by SSI in weblages. # ---------------------- start------------------------ # #!/usr/local/bin/perl # # You will change this line by your environment. # # require "./SSS.pl"; # require "./SSSinit.pl"; # # &SSS'initForm(); # &SSS'writeForm(); # # Note: If you hand "1" as the argument, this function doesn't print # # Content-type info of the HTTP header. # # > &SSS'writeForm(1); # # ---------------------- end-------------------------- # To call this from webpages, embed a line like following, to the body # section (...) of weblages: # > # > ... # > # > ... # > # # # ***Appendix: Tips # # You can switch style by options in the URL, like: # > http://foo.bar.com/webpage.html?SSSStyle=style1 # When you make a switching menu by simple HTML, this feature will help you. # # Without my agreement, you can use, customize, and re-distribute this. # You don't have to mail to me, link to my website, and write my name. # There is no restriction and requirement. # #======================================================================= # Žg‚c•u #======================================================================= # # SSS.js‚IPerl”A�B # fpfbfP�[fW‚E‚I‚A�APerl4^E?~‚IŽA?sŠÂ‹«‚a•K—v‚A‚·�B # # # �!�Ý’eftf@fCf‹‚I?i�¬ # # ‚Ü‚¸�A^E‰o‚I‚a‚¤‚E“a—e‚IPerlfXfNfŠfvfg‚??i�¬‚µ‚Ü‚·�B # ftf@fCf‹–1‚Í‚E‚n‚A‚a‚c‚c‚A‚·‚a�ASSS.pl‚A“—‚¶fffBfOfNfgfŠ‚É # ’u‚c‚Ä‚¨‚­‚A‰1‚©‚A•Ö—~‚A‚µ‚a‚¤�B # ‚±‚±‚A‚Í—á‚A‚µ‚Ä�uSSSinit.pl�v‚A‚c‚¤–1‘O‚A�Ý’eftf@fCf‹‚??i�¬ # ‚·‚é‚a‚I‚A‰1’e‚µ‚Ü‚·�B # ---------------------- start---------------------- # # # fXf^fCf‹‚I’e‹` # &SSS'addStyle("style1", "/~piro/style1.css", "screen"); # &SSS'addStyle("style2", "/~piro/style2.css", "screen"); # # ^o�”‚Í�ufXf^fCf‹–1�v�ufV�[fg‚IfpfX�v�u‘Ήžf�fffBfA�v‚I?‡�B # # fpfX‚Í�u\n�v‹a�O‚e‚A•!�”Žw’e‰Â”\�Af�fffBfA‚ÍfJf“f}‹a�O‚e‚A�B # # �i^e”Ô?A?‰‚IfXf^fCf‹‚affftfHf‹fg‚IfXf^fCf‹�i?‰‚ß‚Äfy�[fW‚? # # ŠJ‚c‚1‚A‚«‚É�A?‰Šú?ó‘Ô‚A‘I‘?‚3‚e‚Ä‚c‚éfXf^fCf‹�j‚É‚E‚e‚Ü‚·�j # # fXf^fCf‹–1‚??E—a‚·‚é‚A�A‰i‘±fXf^fCf‹‚É‚E‚e‚Ü‚·�B # # ‚E‚¨�A‘a4^o�”‚A‚µ‚Ä0^EŠO‚I’l�i1‚E‚Ç�j‚?“n‚·‚A�A‚»‚IfXf^fCf‹‚Í # # �O‚e‘Ö‚¦ftfH�[f€‚I^e——‚É•\ަ‚3‚e‚E‚­‚E‚e‚Ü‚·�i‰B‚µfXf^fCf‹�j�B # # # �ufXf^fCf‹–3‚µ�v‚I•\ަ–1�iffftfHf‹fg‚Í�uNo Style�v�j # $SSS'noStyleLabel = 'No Style'; # # # fXf^fCf‹‘I‘??î•n‚ICookie‚I•U‘¶—pfpfX�iffftfHf‹fg‚Í‚»‚Ify�[fW‚IfpfX�j # $SSS'targetRoot = '/~piro/'; # # # XHTML‚Ify�[fW‚ɑ΂µ‚ÄŽg—p‚·‚é?e?‡‚Í�u1�v�AHTML‚A‚Í�u0�v # # �iffftfHf‹fg‚Í�u0�v�j # $SSS'outputAsXHTML = 1; # # # ‘I‘?‚3‚e‚E‚©‚Á‚1fV�[fg‚?‘a‘ÖfXf^fCf‹fV�[fg‚A‚µ‚ÄfŠf“fN‚·‚é # # ?e?‡‚Í�u1�v�A‚µ‚E‚c?e?‡‚Í�u0�v�iffftfHf‹fg‚Í�u0�v�j # $SSS'shouldLinkAlternateStyleSheets = 1; # # IE‚A‚Í‘a‘ÖfXf^fCf‹fV�[fg‚Ü‚A‘S•”“Ç‚Ý?ž‚n‚A‚µ‚Ü‚¤‚I‚A�A # # �u0�v‚É‚µ‚Ä‚¨‚©‚E‚c‚Afy�[fW‚I“Ç‚Ý?ž‚Ý‚a’x‚­‚E‚邱‚A‚a‚ ‚e‚Ü‚· # # # �O‚e‘Ö‚¦ftfH�[f€‚I�Ý’e # $SSS'formLabel = 'SelectStyle:'; # fŠfXfg‚If‰fxf‹ # $SSS'formAccessKey = 'S'; # fŠfXfg‚IfAfNfZfXfL�[ # $SSS'applyLabel = 'Go!'; # ŽA?sf{f^f“‚If‰fxf‹ # $SSS'applyAccessKey = 'G'; # ŽA?sf{f^f“‚IfAfNfZfXfL�[ # # 1; # –Y‚e‚E‚c‚a‚¤‚É�I # ---------------------- end------------------------ # # # �!head‚Ö‚I–„‚ß?ž‚Ý # # ^E‰o‚I‚a‚¤‚E“a—e‚ICGIfXfNfŠfvfg‚??i�¬‚µ�A�`‚I’†‚A # SSI‚AŽA?s‚µ‚ĉo‚3‚c�B‚±‚±‚A‚͉1‚É�uheader.cgi�v‚A‚µ‚Ü‚·�B # ---------------------- start---------------------- # #!/usr/local/bin/perl # # �i�aPerl‚IfpfX‚͊‹«‚É?‡‚í‚1‚ĉo‚3‚c�j # # require "./SSS.pl"; # fpfbfP�[fW‚I“Ç‚Ý?ž‚Ý # require "./SSSinit.pl"; # �Ý’eftf@fCf‹‚I“Ç‚Ý?ž‚Ý # # # �Ý’e‚?‚a‚A‚É?‰Šú‰» # &SSS'initLinks(); # # # fXf^fCf‹fV�[fg‚IfŠf“fN‚??o—Í # &SSS'writeLinks(); # # �¦‘1‚ICGIfXfNfŠfvfg‚©‚çOÄ‚N?o‚·?e?‡‚Í�A^o�”�u1�v‚?‚‚—‚é‚A # # HTTPfwfbf_‚IContent-type‚??o—Í‚µ‚Ü‚1‚n # # &SSS'writeLinks(1); # # ---------------------- end------------------------ # # # �!�O‚e‘Ö‚¦ftfH�[f€‚I–„‚ß?ž‚Ý # # ^E‰o‚I‚a‚¤‚EfXfNfŠfvfg‚?SSI‚AŽA?s‚·‚é‚A�A‚»‚I‰Ó?Š‚É # fXf^fCf‹�O‚e‘Ö‚¦‚I‚1‚ß‚IftfH�[f€‚a•\ަ‚3‚e‚Ü‚·�B # fXfNfŠfvfg–1‚Í�A‚±‚±‚A‚͉1‚É�uform.cgi�v‚A‚µ‚Ü‚·�B # ---------------------- start------------------------ # #!/usr/local/bin/perl # # �i�aPerl‚IfpfX‚͊‹«‚É?‡‚í‚1‚ĉo‚3‚c�j # # require "./SSS.pl"; # fpfbfP�[fW‚I“Ç‚Ý?ž‚Ý # require "./SSSinit.pl"; # �Ý’eftf@fCf‹‚I“Ç‚Ý?ž‚Ý # # # �Ý’e‚?‚a‚A‚É?‰Šú‰» # &SSS'initForm(); # # # ftfH�[f€‚??o—Í # &SSS'writeForm(); # # �¦‘1‚ICGIfXfNfŠfvfg‚©‚çOÄ‚N?o‚·?e?‡‚Í�A^o�”�u1�v‚?‚‚—‚é‚A # # HTTPfwfbf_‚IContent-type‚??o—Í‚µ‚Ü‚1‚n # # &SSS'writeForm(1); # # ---------------------- end-------------------------- # # # �!•Ö—~‚EŽg‚c•u # # &SSS'initLinks();‚IŽA?sOa‚Í�A$SSS'styleSheetsLinks‚É # &SSS'writeLinks();‚A?o—Í‚·‚é“a—e‚aŠi”[‚3‚e‚Ü‚·�B # ‚Ü‚1�A&SSS'initForm();‚IŽA?sOa‚Í�A$SSS'form‚É&SSS'writeForm();‚A # ?o—Í‚·‚éftfH�[f€‚aŠi”[‚3‚e‚Ü‚·�BOfަ”‚E‚Ç‚ICGIfXfNfŠfvfg‚A‘g‚Ý # ?‡‚í‚1‚ÄŽg‚¤Žž‚E‚ǂɗ~—p‚A‚«‚Ü‚·�B # # ‚±‚IfXfNfŠfvfg‚?Žg—p‚µ‚Ä‚c‚éfy�[fW‚?�u?SSSStyle=fXf^fCf‹–1�v # ‚A‚c‚¤^o�”‚?Žw’e‚µ‚ēǂÝ?ž‚?‚A�A‹­�§“I‚É‚»‚IfXf^fCf‹‚?“K—p‚µ‚Ü‚·�B # ftfH�[f€‚?Žg‚킸‚ÉfXf^fCf‹�O‚e‘Ö‚¦‚??s‚c‚1‚c?e?‡‚â�A‚±‚IfXfNfŠfvfg‚A # ’n‹Y‚3‚e‚éftfH�[f€‚a‹C‚É“ü‚ç‚E‚c?e?‡‚E‚ǂɗ~—p‚A‚«‚Ü‚·�B # #======================================================================= # # •â‘«�B # ‘1‚IfTfCfg‚AŽg‚í‚e‚é?e?‡‚E‚Ç�A‚¤‚?‚Ö‚IfŠf“fN‚a’~?iO •\ަ‚a‰ü•I‚a # ?Ä”z•z‚a‘S‚ÄŽ©—R‚A‚µ‚Ü‚·�B # #======================================================================= # —š—?�F # 2003/3/1 Ver.1.0 JavaScript‚©‚çPerl‚Ö^Ú�A # 2003/3/1 Ver.1.1 ftfH�[f€‚I?‰Šú‰»•u–@‚?•I?X # 2003/3/3 Ver.1.1.1 HTML‚If~fX‚??C�3 # 2003/3/9 Ver.1.1.2 fŠf“fN‚I?o—Í‚??C�3 # 2003/3/21 Ver.1.1.3 f^fCfgf‹‚I‚E‚cfXf^fCf‹fV�[fg‚?‰i‘±fXf^fCf‹fV�[fg # ‚A‚µ‚Ä?o—Í‚·‚é‚a‚¤‚É‚µ‚1 # 2003/4/29 Ver.1.1.4 fXf^fCf‹‚?�O‚e‘Ö‚¦fŠfXfg‚©‚ç‰B‚·�Ý’e‚?’ljÁ #======================================================================= #======================================================================= # fwfbf_—p $noStyleLabel = 'No Style'; $targetRoot = ''; $outputAsXHTML = 0; $shouldLinkAlternateStyleSheets = 0; $selected = ''; $selectedIndex = 1; $styleSheetsLinks = ''; @stylesID = (''); %stylesNum = ('', 0); @stylesPath = (''); @stylesMedia = ('all'); @stylesHidden = (0); $mSlashForXHTML = ''; #----------------------------------------------------------------------- # ?‰Šú‰» #----------------------------------------------------------------------- sub initLinks { $stylesID[0] = $noStyleLabel; $stylesNum{$noStyleLabel} = 0; if ($outputAsXHTML != 0) { $mSlashForXHTML = ' /'; } &get_cookies(); &decode_input(); &getSelectedStyle(); &makeStyleSheetsLinks(); } #----------------------------------------------------------------------- # fŠf“fN‚I?o—Í # [0] = f‚�[fh 0:SSI—p 1:fXfNfŠfvfg“aOÄ‚N?o‚µ�iContent-type‚??o—Í‚µ‚E‚c�j #----------------------------------------------------------------------- sub writeLinks { local ($stored_selected); if ($_[0] != 1) { print "Content-type: text/html\n\n"; if ($FORM{'SSSStyle'} ne '') { $stored_selected = $FORM{'SSSStyle'}; } else { $stored_selected = $COOKIES{'SSSSelectedStyle'}; } if ($stored_selected ne '') { &put_cookie('SSSSelectedStyle', $selected, 30, $targetRoot, 1); } } print "$styleSheetsLinks\n"; &debugDump(); } #----------------------------------------------------------------------- # ‘I‘?‚3‚e‚1fXf^fCf‹‚?“3‚é #----------------------------------------------------------------------- sub getSelectedStyle { local ($stored_selected); if ($FORM{'SSSStyle'} ne '') { $stored_selected = $FORM{'SSSStyle'}; } else { $stored_selected = $COOKIES{'SSSSelectedStyle'}; } if ( $stored_selected eq '' || ( $stored_selected ne $stylesID[0] && $stylesNum{$stored_selected} eq '' ) ) { $selected = $stylesID[1]; $selectedIndex = 1; } else { $selected = $stored_selected; $selectedIndex = $stylesNum{$stored_selected}; } if ($ENV{'DOCUMENT_URI'} ne '') { if ($stored_selected ne '') { &put_cookie('SSSSelectedStyle', $selected, 30, $targetRoot); } } } #----------------------------------------------------------------------- # fXf^fCf‹fV�[fg‚Ö‚IfŠf“fN‚?�¶�¬ #----------------------------------------------------------------------- sub makeStyleSheetsLinks { local ($name, $ii, @links, @work, $work); $ii = 0; foreach $name (@stylesID) { if ($name eq '') { @work = split(/\n/, $stylesPath[$ii]); foreach $work (@work) { push(@links, ""); } } elsif ($ii == $selectedIndex) { @work = split(/\n/, $stylesPath[$ii]); foreach $work (@work) { push(@links, ""); } } elsif ($shouldLinkAlternateStyleSheets != 0) { @work = split(/\n/, $stylesPath[$ii]); foreach $work (@work) { push(@links, ""); } } $ii++; } $styleSheetsLinks = join("\n", @links); } #----------------------------------------------------------------------- # fXf^fCf‹’e‹` # [0] = –1‘O # [1] = fV�[fg‚IURI�i\n‹a�O‚e‚A•!�”Žw’e‰Â�j # [2] = f�fffBfA # [3] = fŠfXfg‚©‚ç‰B‚·‚©‚Ç‚¤‚©�i0‚E‚ç‰B‚3‚E‚c�A‚»‚e^EŠO‚E‚ç‰B‚·�j #----------------------------------------------------------------------- sub addStyle { local ($ii); $ii = $#stylesID + 1; $stylesNum{$_[0]} = $ii; $stylesID[$ii] = $_[0]; $stylesPath[$ii] = $_[1]; if ($_[2] eq '') { $stylesMedia[$ii] = 'all'; } else { $stylesMedia[$ii] = $_[2]; } if ($_[3] eq '') { $stylesHidden[$ii] = 0; } else { $stylesHidden[$ii] = 1; } } #======================================================================= # ftfH�[f€—p $formLabel = ''; $formAccessKey = ''; $applyLabel = ''; $applyAccessKey = ''; @stylesLabel = (''); @stylesGroup = (''); $form = ''; sub initForm { local ($ii, $max, @stylesLabel, @stylesGroup, $id, $options, @option, @work, $work); $stylesID[0] = $noStyleLabel; $stylesNum{$noStyleLabel} = 0; &get_cookies(); &decode_input(); # fhf?fbfvf_fEf“fŠfXfg‚?�¶�¬ $ii = 0; foreach $id (@stylesID) { if ($id =~ /\@/) { $_ = $id; s/@.*$//; $stylesLabel[$ii] = $_; $_ = $id; s/^[^@]*@//; $stylesGroup[$ii] = $_; } else { $stylesLabel[$ii] = $id; $stylesGroup[$ii] = ''; } $ii++; } &getSelectedStyle(1); $max = $#stylesID; @option = (''); @work = (''); for ($ii = 1; $ii < $max; $ii++) { $id = $stylesID[$ii]; if ($id eq $selected) { $work = ' selected="selected"'; } else { $work = ''; } if ($id ne '' && $stylesHidden[$ii] != 1) { push(@work, ""); } if ($ii == $max-1 || $stylesGroup[$ii] ne $stylesGroup[$ii+1]) { $work = join("\n", @work); if ($stylesGroup[$ii] ne '') { $work = "\n$work\n"; } push(@option, $work); @work = (''); } } push(@option, ""); $options = join("\n", @option); if ($outputAsXHTML != 0) { $mSlashForXHTML = ' /'; } $form = <<________________________HTML_DATA________________________;
________________________HTML_DATA________________________ } # [0] = f‚�[fh 0:SSI—p 1:fXfNfŠfvfg“aOÄ‚N?o‚µ�iContent-type‚??o—Í‚µ‚E‚c�j sub writeForm { if ($_[0] != 1) { print "Content-type: text/html\n\n"; } print $form; &debugDump(); } #======================================================================= # Cookie‚¨‚a‚NftfH�[f€’l‚I?^—?�ipicoBBS‚a‚e“]—p�j #----------------------------------------------------------------------- # fNfbfL�[Ža“3 #----------------------------------------------------------------------- sub get_cookies { local ($work, $name, $value); for $work (split(/; */, $ENV{'HTTP_COOKIE'})) { ($name, $value) = split(/=/, $work); $value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg; $COOKIES{$name} = $value; } } #----------------------------------------------------------------------- # fNfbfL�[?o—Í # [0] = –1‘O # [1] = ’l # [2] = ŠúOA # [3] = fpfX # [4] = f‚�[fh 0:HTTPfwfbf_ 0^EŠO:METAf^fO #----------------------------------------------------------------------- sub put_cookie { local($str, $limit, $value, $path); $COOKIES{$_[0]} = $_[1]; $value = $_[1]; $value =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; $limit = gmtime(time + (86400 * $_[2])); $limit =~ s/^(...) (...) (..) (........) (....).*/$1, $3-$2-$5 $4 GMT\;/; if ($_[3] ne '') { $path = " path=$_[3];"; } else { $path = ''; } if ($_[4] == 0) { print "Set-Cookie: $_[0]=$value; expires=$limit$path\n"; } else { print "\n"; } } #----------------------------------------------------------------------- # ftfH�[f€’l‚IfffR�[fh #----------------------------------------------------------------------- sub decode_input { local ($query_string, $work, @work, $name, $value); if ($ENV{'REQUEST_METHOD'} eq "POST") { # read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); $query_string = ''; } else { $query_string = $ENV{'QUERY_STRING'}; } @work = split(/&/, $query_string); foreach $work (@work) { ($name, $value) = split(/=/, $work); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; # &jcode'convert(*value, "euc"); $FORM{$name} = $value; } } sub debugDump { print "\n"; } 1;