From a417171bf4b28dc2e0901a3deec723cb779eabe5 Mon Sep 17 00:00:00 2001 From: kgsoft Date: Thu, 7 Dec 2017 13:46:59 +0000 Subject: [PATCH] =?utf8?q?=E6=94=B9=E8=A1=8C=E3=82=B3=E3=83=BC=E3=83=89?= =?utf8?q?=E3=82=92LF=E3=81=AB=E7=B5=B1=E4=B8=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- category.cgi | 78 +- docs/default.css | 248 +++--- docs/gpl.txt | 680 +++++++------- docs/makedoc.sh | 8 +- docs/plugindev.html | 86 +- docs/readme.html | 228 ++--- download.cgi | 146 +-- edit.cgi | 438 ++++----- lib/cgi-lib.pl | 910 +++++++++---------- lib/common.pl | 2472 +++++++++++++++++++++++++-------------------------- lib/jcode.pl | 1560 ++++++++++++++++---------------- lib/mimew.pl | 644 +++++++------- lib/setup.pl | 66 +- plugin/core.pl | 602 ++++++------- release.sh | 136 +-- wiki.cgi | 222 ++--- 16 files changed, 4262 insertions(+), 4262 deletions(-) diff --git a/category.cgi b/category.cgi index 740fafb..5db5f48 100644 --- a/category.cgi +++ b/category.cgi @@ -1,39 +1,39 @@ -#!/usr/bin/perl -################################################################################ -# -# FSWiki Lite - ¥«¥Æ¥´¥ê¤Î°ìÍ÷ -# -################################################################################ -require "./lib/common.pl"; -#=============================================================================== -# ½èÍý¤Î¿¶¤êʬ¤± -#=============================================================================== -&ReadParse(); -if($in{'c'} ne ""){ - &show_category($in{'c'}); - -} else { - &show_all_category(); - -} - -#=============================================================================== -# »ØÄꤵ¤ì¤¿¥«¥Æ¥´¥ê¤òɽ¼¨ -#=============================================================================== -sub show_category { - my $category = shift; - - &print_header("¥«¥Æ¥´¥ê"); - print &Wiki::Plugin::category_list($category); - &print_footer(); -} - -#=============================================================================== -# Á´¤Æ¤Î¥«¥Æ¥´¥ê¤òɽ¼¨ -#=============================================================================== -sub show_all_category { - &print_header("¥«¥Æ¥´¥ê"); - print "

".&Util::escapeHTML($category)."

\n"; - print &Wiki::Plugin::category_list(); - &print_footer(); -} +#!/usr/bin/perl +################################################################################ +# +# FSWiki Lite - ¥«¥Æ¥´¥ê¤Î°ìÍ÷ +# +################################################################################ +require "./lib/common.pl"; +#=============================================================================== +# ½èÍý¤Î¿¶¤êʬ¤± +#=============================================================================== +&ReadParse(); +if($in{'c'} ne ""){ + &show_category($in{'c'}); + +} else { + &show_all_category(); + +} + +#=============================================================================== +# »ØÄꤵ¤ì¤¿¥«¥Æ¥´¥ê¤òɽ¼¨ +#=============================================================================== +sub show_category { + my $category = shift; + + &print_header("¥«¥Æ¥´¥ê"); + print &Wiki::Plugin::category_list($category); + &print_footer(); +} + +#=============================================================================== +# Á´¤Æ¤Î¥«¥Æ¥´¥ê¤òɽ¼¨ +#=============================================================================== +sub show_all_category { + &print_header("¥«¥Æ¥´¥ê"); + print "

".&Util::escapeHTML($category)."

\n"; + print &Wiki::Plugin::category_list(); + &print_footer(); +} diff --git a/docs/default.css b/docs/default.css index df46b9c..756db26 100644 --- a/docs/default.css +++ b/docs/default.css @@ -1,124 +1,124 @@ -body { - background-color: #FFFFFF; - color : #000000; - font-family : Verdana,Arial,Helvetica,sans-serif; -} - -p.adminmenu { - text-align : right; - padding-bottom : 5px; - margin-bottom : 5px; - border-bottom : #000088 1px dotted; - font-size : 80%; - text-indent : 10px; -} - -.footer { - border-top : #000088 1px dotted; - margin-top : 20px; - padding-top : 5px; - text-align : right; - font-size : 80%; - font-style : italic; -} - -hr { - color : #FFFFFF; -} - -pre { - border : #888888 1px solid; - padding : 4px; - margin-left : 40px; -} - -p { - padding-left : 20pt; -} - -strong { - font-weight : normal; -} - -h1 { - background-color : #FFFFFF; - border-bottom : #AABBFF 1px solid; - font-family : Verdana,Arial,Helvetica,sans-serif; - padding-left : 4pt; -} - - -h2 { - background-color : #AABBFF; - font-family : Verdana,Arial,Helvetica,sans-serif; - padding-left : 4pt; -} - -h3 { - border-left : #AABBFF 10px solid; - border-top : #AABBFF 5px solid; - border-right : #AABBFF 1px solid; - border-bottom : #AABBFF 1px solid; - font-family : Verdana,Arial,Helvetica,sans-serif; - font-size : 100%; - padding-left : 4pt; -} - -h4 { - border-left : #AABBFF 10px solid; - padding-left : 4px; - font-family : Verdana,Arial,Helvetica,sans-serif; - padding-left : 4pt; -} - -table { - border : #888888 2px solid; -} - -th { - border : #888888 1px solid; - background-color : #88AAFF; -} - -td { - border : #888888 1px solid; -} - -A:link { - color : #4444FF; - text-decoration : none; -} -A:visited { - color : #4444FF; - text-decoration : none; -} -A:hover { - color : #FF4444; - text-decoration : underline; -} - -div.main { - margin-left: 20%; -} - -div.sidebar { - position : absolute; - top : 0px; - left : 0px; - width : 20%; - font-size : x-small; - padding: 2px 2px 100% 2px; - border-style: solid; - border-color: #CCCCFF; - border-width: 2px; - color : #000000; - background-color: #EEEEFF; -} - -div.comment { - margin-top : 10px; - margin-bottom : 10px; - background-color : DDDDFF; - border : AAAAFF 2px solid; - font-size : 80%; -} +body { + background-color: #FFFFFF; + color : #000000; + font-family : Verdana,Arial,Helvetica,sans-serif; +} + +p.adminmenu { + text-align : right; + padding-bottom : 5px; + margin-bottom : 5px; + border-bottom : #000088 1px dotted; + font-size : 80%; + text-indent : 10px; +} + +.footer { + border-top : #000088 1px dotted; + margin-top : 20px; + padding-top : 5px; + text-align : right; + font-size : 80%; + font-style : italic; +} + +hr { + color : #FFFFFF; +} + +pre { + border : #888888 1px solid; + padding : 4px; + margin-left : 40px; +} + +p { + padding-left : 20pt; +} + +strong { + font-weight : normal; +} + +h1 { + background-color : #FFFFFF; + border-bottom : #AABBFF 1px solid; + font-family : Verdana,Arial,Helvetica,sans-serif; + padding-left : 4pt; +} + + +h2 { + background-color : #AABBFF; + font-family : Verdana,Arial,Helvetica,sans-serif; + padding-left : 4pt; +} + +h3 { + border-left : #AABBFF 10px solid; + border-top : #AABBFF 5px solid; + border-right : #AABBFF 1px solid; + border-bottom : #AABBFF 1px solid; + font-family : Verdana,Arial,Helvetica,sans-serif; + font-size : 100%; + padding-left : 4pt; +} + +h4 { + border-left : #AABBFF 10px solid; + padding-left : 4px; + font-family : Verdana,Arial,Helvetica,sans-serif; + padding-left : 4pt; +} + +table { + border : #888888 2px solid; +} + +th { + border : #888888 1px solid; + background-color : #88AAFF; +} + +td { + border : #888888 1px solid; +} + +A:link { + color : #4444FF; + text-decoration : none; +} +A:visited { + color : #4444FF; + text-decoration : none; +} +A:hover { + color : #FF4444; + text-decoration : underline; +} + +div.main { + margin-left: 20%; +} + +div.sidebar { + position : absolute; + top : 0px; + left : 0px; + width : 20%; + font-size : x-small; + padding: 2px 2px 100% 2px; + border-style: solid; + border-color: #CCCCFF; + border-width: 2px; + color : #000000; + background-color: #EEEEFF; +} + +div.comment { + margin-top : 10px; + margin-bottom : 10px; + background-color : DDDDFF; + border : AAAAFF 2px solid; + font-size : 80%; +} diff --git a/docs/gpl.txt b/docs/gpl.txt index 45645b4..5b6e7c6 100644 --- a/docs/gpl.txt +++ b/docs/gpl.txt @@ -1,340 +1,340 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/docs/makedoc.sh b/docs/makedoc.sh index da61745..b895ad3 100644 --- a/docs/makedoc.sh +++ b/docs/makedoc.sh @@ -1,4 +1,4 @@ -#!/bin/sh -# HTML¥Õ¥¡¥¤¥ë¤ËÊÑ´¹ -perl ../../tools/wiki2html.pl "http://fswiki.poi.jp/wiki.cgi/docs?action=SOURCE&page=FSWikiLite%2Freadme" -css=default.css -title=README > readme.html -perl ../../tools/wiki2html.pl "http://fswiki.poi.jp/wiki.cgi/docs?action=SOURCE&page=FSWikiLite%2F%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%B3%AB%C8%AF" -css=default.css -title=¥×¥é¥°¥¤¥ó³«È¯ > plugindev.html +#!/bin/sh +# HTML¥Õ¥¡¥¤¥ë¤ËÊÑ´¹ +perl ../../tools/wiki2html.pl "http://fswiki.poi.jp/wiki.cgi/docs?action=SOURCE&page=FSWikiLite%2Freadme" -css=default.css -title=README > readme.html +perl ../../tools/wiki2html.pl "http://fswiki.poi.jp/wiki.cgi/docs?action=SOURCE&page=FSWikiLite%2F%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%B3%AB%C8%AF" -css=default.css -title=¥×¥é¥°¥¤¥ó³«È¯ > plugindev.html diff --git a/docs/plugindev.html b/docs/plugindev.html index 8d7e725..89a0f90 100644 --- a/docs/plugindev.html +++ b/docs/plugindev.html @@ -1,43 +1,43 @@ - - - ¥×¥é¥°¥¤¥ó³«È¯ - - - -

¥µ¥Ý¡¼¥È¤¹¤ë¥×¥é¥°¥¤¥ó

-

FSWikiLite¤ÏFSWiki¤È¤Ï°ã¤¤¡¢Wiki¥Ú¡¼¥¸¤Ëµ­½Ò¤·¤Æ»ÈÍѤ¹¤ë¥¿¥¤¥×¤Î¥×¥é¥°¥¤¥ó¡Ê¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤È¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¡Ë¤·¤«¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤»¤ó¡£¤¿¤À¤·¡¢FSWiki¤Ç¥¢¥¯¥·¥ç¥ó¥×¥é¥°¥¤¥ó¤È¸Æ¤Ð¤ì¤Æ¤¤¤ë¤â¤Î¤Ë¤Ä¤¤¤Æ¤ÏÊ̤ÎCGI¥¹¥¯¥ê¥×¥È¤òÍÑ°Õ¤¹¤ë¤³¤È¤ÇÂбþ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡ÊLite¤Îcategory.cgi¤Ê¤É¤¬¤³¤ì¤Ë¤¢¤¿¤ê¤Þ¤¹¡Ë¡£

¥×¥é¥°¥¤¥ó¤Ï¡Á.pl¤È¤¤¤¦Ì¾Á°¤òÉÕ¤±¤Æplugin¥Ç¥£¥ì¥¯¥È¥ê¤ËÇÛÃÖ¤·¤Þ¤¹¡£¤½¤·¤Ælib/setup.pl¤Çrequire¤·¤Þ¤¹¡£¥Ç¥Õ¥©¥ë¥È¤Îsetup.pl¤Ç¤Ïcore.pl¤Î¤ßÆɤ߹þ¤à¤è¤¦ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£

require "./plugin/core.pl";
-

¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó

-

¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ÏWiki::Plugin¥Ñ¥Ã¥±¡¼¥¸¤ÇÄêµÁ¤µ¤ì¤¿Perl´Ø¿ô¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤Ç¤¹¡£´Ø¿ô¤Î°ú¿ô¤Ë¤ÏWiki¥½¡¼¥¹¤Çµ­½Ò¤·¤¿°ú¿ô¤¬¤½¤Î¤Þ¤ÞÅϤµ¤ì¤Þ¤¹¡£´Ø¿ô¤ÏÌá¤êÃͤȤ·¤ÆHTML¤òÊÖ¤¹¤è¤¦¤Ë¼ÂÁõ¤·¤Þ¤¹¡£¤Þ¤¿¡¢¥¹¥¯¥ê¥×¥È¤ÎBEGINÀá¤Ç´Ø¿ô¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤È¤·¤ÆÅÐÏ¿¤·¤Þ¤¹¡£

package Wiki::Plugin;
-BEGIN {
-  $main::I_PLUGIN->{hello} = \&hello;
-}
-sub hello {
-  my $name = shift;
-  if($name eq ''){
-    return "̾Á°¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
-  } else {
-    return "¤³¤ó¤Ë¤Á¤Ï".&Util::escapeHTML($name)."¤µ¤ó";
-  }
-}
-1;
-

¥Ú¡¼¥¸ÊÔ½¸»þ¤Ë°Ê²¼¤Î½ñ¼°¤Ç»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

{{hello ¤¿¤í¤¦}}
-

¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó

-

¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤â¼ÂÁõÊýË¡¤Ï¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ÈƱÍͤǤ¹¡£¥Ö¥í¥Ã¥¯Í×ÁǤò´Þ¤àHTML¤òÊֵѤ¹¤ë¾ì¹ç¤Ë¤Ï¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤È¤·¤Æ¼ÂÁõ¤·¤Þ¤¹¡£BEGINÀá¤Ç¤ÎÅÐÏ¿ÊýË¡¤Î¤ß¤¬°Û¤Ê¤ê¤Þ¤¹¡£

BEGIN {
-  $main::P_PLUGIN->{hello} = \&hello;
-}
-

¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤Ø¤Î¥¢¥¯¥»¥¹

-

¥×¥é¥°¥¤¥óÆâÉô¤«¤é¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤Ë¤Ï%main::in¤È¤¤¤¦ÊÑ¿ô¤òÍøÍѤ·¤Þ¤¹¡£¤³¤ì¤Ïcgi-lib.pl¤Ç¥Ñ¡¼¥¹¤µ¤ì¤¿¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤¬³ÊǼ¤µ¤ì¤¿Ï¢ÁÛÇÛÎó¤Ç¤¹¡£

# ¥Ú¡¼¥¸Ì¾¤ò¼èÆÀ
-my $p = $main::in{'p'};
-

¥×¥é¥°¥¤¥ó¤«¤éÍøÍѲÄǽ¤Ê¥æ¡¼¥Æ¥£¥ê¥Æ¥£

-

¥×¥é¥°¥¤¥óÆâÉô¤Ç¤ÏUtil¥Ñ¥Ã¥±¡¼¥¸¤ËÄêµÁ¤µ¤ì¤¿¥æ¡¼¥Æ¥£¥ê¥Æ¥£´Ø¿ô¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£Util¥Ñ¥Ã¥±¡¼¥¸¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ê´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

- - - - - - - -
´Ø¿ô̾ÀâÌÀ
url_encodeURL¥¨¥ó¥³¡¼¥É¤·¤Þ¤¹¡£
url_decodeURL¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿Ê¸»úÎó¤ò¥Ç¥³¡¼¥É¤·¤Þ¤¹¡£
escapeHTMLHTML¤ò¥¨¥¹¥±¡¼¥×¤·¤Þ¤¹¡£
trimʸ»úÎó¤ÎÁ°¸å¤Î¶õÇò¤ò¼è¤ê½ü¤­¤Þ¤¹¡£
check_numericʸ»úÎ󤬿ôÃͤ«¤É¤¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£
handyphone·ÈÂÓÅÅÏ䫤ɤ¦¤«¤òȽÃǤ·¤Þ¤¹¡£
-

¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È

-

FSWiki¤Ç¥¢¥¯¥·¥ç¥ó¥×¥é¥°¥¤¥ó¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¥×¥é¥°¥¤¥ó¤ÏÊÌÅÓCGI¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë¤³¤È¤ÇÂбþ¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£action¥Ñ¥é¥á¡¼¥¿¤ÎÂå¤ï¤ê¤Ë¤½¤ÎCGI¥¹¥¯¥ê¥×¥È¤ò¸Æ¤Ó½Ð¤¹¤è¤¦¤Ë¤·¤Þ¤¹¡£CGI¥¹¥¯¥ê¥×¥È¤«¤é¤Ïcommon.pl¤ËÄêµÁ¤µ¤ì¤¿´Ø¿ô·²¤ò»ÈÍѤ·¤Æ¥Ú¡¼¥¸¤Î¼èÆÀ¤äÊݸ¤Ê¤É¤ò¹Ô¤¦¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

FSWikiLite¤Ç¤Ï¥Ç¥Õ¥©¥ë¥È¤Çedit.cgi¡Ê¥Ú¡¼¥¸¤ÎÊÔ½¸¡Ë¡¢download.cgi¡ÊźÉÕ¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥É¡Ë¡¢category.cgi¡Ê¥«¥Æ¥´¥êɽ¼¨¡Ë¤È¤¤¤¦£³¤Ä¤Î¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤³¤ì¤é¤ò»²¹Í¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£

- + + + ¥×¥é¥°¥¤¥ó³«È¯ + + + +

¥µ¥Ý¡¼¥È¤¹¤ë¥×¥é¥°¥¤¥ó

+

FSWikiLite¤ÏFSWiki¤È¤Ï°ã¤¤¡¢Wiki¥Ú¡¼¥¸¤Ëµ­½Ò¤·¤Æ»ÈÍѤ¹¤ë¥¿¥¤¥×¤Î¥×¥é¥°¥¤¥ó¡Ê¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤È¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¡Ë¤·¤«¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤»¤ó¡£¤¿¤À¤·¡¢FSWiki¤Ç¥¢¥¯¥·¥ç¥ó¥×¥é¥°¥¤¥ó¤È¸Æ¤Ð¤ì¤Æ¤¤¤ë¤â¤Î¤Ë¤Ä¤¤¤Æ¤ÏÊ̤ÎCGI¥¹¥¯¥ê¥×¥È¤òÍÑ°Õ¤¹¤ë¤³¤È¤ÇÂбþ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡ÊLite¤Îcategory.cgi¤Ê¤É¤¬¤³¤ì¤Ë¤¢¤¿¤ê¤Þ¤¹¡Ë¡£

¥×¥é¥°¥¤¥ó¤Ï¡Á.pl¤È¤¤¤¦Ì¾Á°¤òÉÕ¤±¤Æplugin¥Ç¥£¥ì¥¯¥È¥ê¤ËÇÛÃÖ¤·¤Þ¤¹¡£¤½¤·¤Ælib/setup.pl¤Çrequire¤·¤Þ¤¹¡£¥Ç¥Õ¥©¥ë¥È¤Îsetup.pl¤Ç¤Ïcore.pl¤Î¤ßÆɤ߹þ¤à¤è¤¦ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£

require "./plugin/core.pl";
+

¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó

+

¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ÏWiki::Plugin¥Ñ¥Ã¥±¡¼¥¸¤ÇÄêµÁ¤µ¤ì¤¿Perl´Ø¿ô¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤Ç¤¹¡£´Ø¿ô¤Î°ú¿ô¤Ë¤ÏWiki¥½¡¼¥¹¤Çµ­½Ò¤·¤¿°ú¿ô¤¬¤½¤Î¤Þ¤ÞÅϤµ¤ì¤Þ¤¹¡£´Ø¿ô¤ÏÌá¤êÃͤȤ·¤ÆHTML¤òÊÖ¤¹¤è¤¦¤Ë¼ÂÁõ¤·¤Þ¤¹¡£¤Þ¤¿¡¢¥¹¥¯¥ê¥×¥È¤ÎBEGINÀá¤Ç´Ø¿ô¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤È¤·¤ÆÅÐÏ¿¤·¤Þ¤¹¡£

package Wiki::Plugin;
+BEGIN {
+  $main::I_PLUGIN->{hello} = \&hello;
+}
+sub hello {
+  my $name = shift;
+  if($name eq ''){
+    return "̾Á°¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
+  } else {
+    return "¤³¤ó¤Ë¤Á¤Ï".&Util::escapeHTML($name)."¤µ¤ó";
+  }
+}
+1;
+

¥Ú¡¼¥¸ÊÔ½¸»þ¤Ë°Ê²¼¤Î½ñ¼°¤Ç»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

{{hello ¤¿¤í¤¦}}
+

¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó

+

¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤â¼ÂÁõÊýË¡¤Ï¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ÈƱÍͤǤ¹¡£¥Ö¥í¥Ã¥¯Í×ÁǤò´Þ¤àHTML¤òÊֵѤ¹¤ë¾ì¹ç¤Ë¤Ï¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤È¤·¤Æ¼ÂÁõ¤·¤Þ¤¹¡£BEGINÀá¤Ç¤ÎÅÐÏ¿ÊýË¡¤Î¤ß¤¬°Û¤Ê¤ê¤Þ¤¹¡£

BEGIN {
+  $main::P_PLUGIN->{hello} = \&hello;
+}
+

¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤Ø¤Î¥¢¥¯¥»¥¹

+

¥×¥é¥°¥¤¥óÆâÉô¤«¤é¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤Ë¤Ï%main::in¤È¤¤¤¦ÊÑ¿ô¤òÍøÍѤ·¤Þ¤¹¡£¤³¤ì¤Ïcgi-lib.pl¤Ç¥Ñ¡¼¥¹¤µ¤ì¤¿¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤¬³ÊǼ¤µ¤ì¤¿Ï¢ÁÛÇÛÎó¤Ç¤¹¡£

# ¥Ú¡¼¥¸Ì¾¤ò¼èÆÀ
+my $p = $main::in{'p'};
+

¥×¥é¥°¥¤¥ó¤«¤éÍøÍѲÄǽ¤Ê¥æ¡¼¥Æ¥£¥ê¥Æ¥£

+

¥×¥é¥°¥¤¥óÆâÉô¤Ç¤ÏUtil¥Ñ¥Ã¥±¡¼¥¸¤ËÄêµÁ¤µ¤ì¤¿¥æ¡¼¥Æ¥£¥ê¥Æ¥£´Ø¿ô¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£Util¥Ñ¥Ã¥±¡¼¥¸¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ê´Ø¿ô¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

+ + + + + + + +
´Ø¿ô̾ÀâÌÀ
url_encodeURL¥¨¥ó¥³¡¼¥É¤·¤Þ¤¹¡£
url_decodeURL¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿Ê¸»úÎó¤ò¥Ç¥³¡¼¥É¤·¤Þ¤¹¡£
escapeHTMLHTML¤ò¥¨¥¹¥±¡¼¥×¤·¤Þ¤¹¡£
trimʸ»úÎó¤ÎÁ°¸å¤Î¶õÇò¤ò¼è¤ê½ü¤­¤Þ¤¹¡£
check_numericʸ»úÎ󤬿ôÃͤ«¤É¤¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£
handyphone·ÈÂÓÅÅÏ䫤ɤ¦¤«¤òȽÃǤ·¤Þ¤¹¡£
+

¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È

+

FSWiki¤Ç¥¢¥¯¥·¥ç¥ó¥×¥é¥°¥¤¥ó¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¥×¥é¥°¥¤¥ó¤ÏÊÌÅÓCGI¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë¤³¤È¤ÇÂбþ¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£action¥Ñ¥é¥á¡¼¥¿¤ÎÂå¤ï¤ê¤Ë¤½¤ÎCGI¥¹¥¯¥ê¥×¥È¤ò¸Æ¤Ó½Ð¤¹¤è¤¦¤Ë¤·¤Þ¤¹¡£CGI¥¹¥¯¥ê¥×¥È¤«¤é¤Ïcommon.pl¤ËÄêµÁ¤µ¤ì¤¿´Ø¿ô·²¤ò»ÈÍѤ·¤Æ¥Ú¡¼¥¸¤Î¼èÆÀ¤äÊݸ¤Ê¤É¤ò¹Ô¤¦¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

FSWikiLite¤Ç¤Ï¥Ç¥Õ¥©¥ë¥È¤Çedit.cgi¡Ê¥Ú¡¼¥¸¤ÎÊÔ½¸¡Ë¡¢download.cgi¡ÊźÉÕ¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥É¡Ë¡¢category.cgi¡Ê¥«¥Æ¥´¥êɽ¼¨¡Ë¤È¤¤¤¦£³¤Ä¤Î¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤³¤ì¤é¤ò»²¹Í¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£

+ diff --git a/docs/readme.html b/docs/readme.html index 4f2d41d..9eb397f 100644 --- a/docs/readme.html +++ b/docs/readme.html @@ -1,114 +1,114 @@ - - - README - - - -

FSWikiLite¤È¤Ï¡©

-

FSWikiLite¤Î¸µ¤Ë¤Ê¤Ã¤Æ¤¤¤ëFreeStyleWiki¤ÏPerl¤Ë¤è¤ëmodulable¤ÊWiki¥¯¥í¡¼¥ó¤Ç¤¹¡£¥×¥é¥°¥¤¥ó¤Ë¤è¤Ã¤ÆÍÍ¡¹¤Êµ¡Ç½¤òÄɲ乤뤳¤È¤¬¤Ç¤­¤Þ¤¹¡£¤¿¤À¤·¡¢¹âµ¡Ç½¤Êʬ¡¢Ä̾ï¤ÎCGI¥¹¥¯¥ê¥×¥È¤ÈÈæ³Ó¤¹¤ë¤ÈÆ°ºî¤¬½Å¤¤¤È¤¤¤¦·çÅÀ¤¬¤¢¤ê¤Þ¤·¤¿¡£

FSWikiLite¤ÏFSWiki¤Û¤É¹âµ¡Ç½¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤¬¡¢µ¡Ç½¤ò¸ÂÄꤹ¤ë¤³¤È¤Ç·Ú²÷¤ËÆ°ºî¤·¤Þ¤¹¡£¥×¥é¥°¥¤¥ó¤Ï°ìÉô¤·¤«»ÈÍѤǤ­¤Þ¤»¤ó¤¬¡¢Ê¸Ë¡¤ÏFSWiki¤È´°Á´¸ß´¹¤Ç¤¹¡£¤Þ¤¿¡¢FSWiki¤ÈÈæ¤Ù¤ë¤È¹½Â¤¤¬¥·¥ó¥×¥ë¤Êʬ¡¢ÀßÃÖ¤âÍưפǤ¹¡£

¤½¤Î¾¤ËFSWikiLite¤Ï°Ê²¼¤Î¤è¤¦¤ÊÆÃħ¤¬¤¢¤ê¤Þ¤¹¡£

    -
  • tDiary¤Î¥Æ¡¼¥Þ¤ò»ÈÍѲÄǽ¡£ -
  • -
  • ¥µ¥¤¥É¥Ð¡¼¤ä¥Ø¥Ã¥À¡¢¥Õ¥Ã¥¿¤òɽ¼¨²Äǽ¡£ -
  • -
  • FSWiki¤È¤Ï°Û¤Ê¤ë¥·¥ó¥×¥ë¤Ê¥×¥é¥°¥¤¥óµ¡¹½¤òÈ÷¤¨¤Æ¤¤¤ë¡£ -
  • -
  • .htaccess¤ò»ÈÍѤ¹¤ë¤³¤È¤ÇÊÔ½¸¤ò´ÉÍý¿Í¤Î¤ß¤Ë¸ÂÄꤹ¤ë¤³¤È¤¬²Äǽ¡£ -
  • -
  • ¥Ú¡¼¥¸¤Î¥«¥Æ¥´¥é¥¤¥º¤¬²Äǽ¡£ -
  • -
  • ¥Õ¥¡¥¤¥ë¤ÎźÉÕ¤¬²Äǽ¡£ -
  • -
  • PDFÀ¸À®¡¢¥­¡¼¥ï¡¼¥É¥ê¥ó¥¯¡¢InterWiki¤Ê¤É¤Ï»ÈÍÑÉԲġ£ -
  • -

¥¤¥ó¥¹¥È¡¼¥ë

-

lib/setup.pl¤òÊÔ½¸¤·¡¢³Æ¼«¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£

    -
  • $DATA_DIR - ¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ -
  • -
  • $BACKUP_DIR - ¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ -
  • -
  • $ATTACH_DIR - źÉÕ¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ -
  • -
  • $THEME_URL - ¥Æ¡¼¥Þ¡ÊCSS¡Ë¤Î¾ì½ê¡£ -
  • -
  • $SEND_MAIL - sendmail¤Î¥Ñ¥¹¡£¹¹¿·ÄÌÃΤò¼õ¤±¼è¤ë¾ì¹ç¤ÏÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ -
  • -
  • $ADMIN_MAIL- ´ÉÍý¼Ô¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¡£¹¹¿·ÄÌÃΤò¼õ¤±¼è¤ë¾ì¹ç¤ÏÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ -
  • -
  • $WIKI_NAME - WikiName¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ï1¡¢»ÈÍѤ·¤Ê¤¤¾ì¹ç¤Ï0¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ -
  • -
  • $MAIN_SCRIPT - ¥á¥¤¥ó¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -
  • $EDIT_SCRIPT - ÊÔ½¸ÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -
  • $DOWNLOAD_SCRIPT - źÉÕ¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥ÉÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -
  • $CATEGORY_SCRIPT - ¥«¥Æ¥´¥êɽ¼¨ÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -
  • $SITE_TITLE - ¥µ¥¤¥È̾¡£¼«Í³¤ËÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£ -
  • -
  • $VERSION - FSWikiLite¤Î¥Ð¡¼¥¸¥ç¥ó¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -
  • $SITE_URL - FSWiki¸ø¼°¥µ¥¤¥È¤ÎURL¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ -
  • -

FTP¤Ê¤É¤Ç°Ê²¼¤Î¤è¤¦¤Ë¥Õ¥¡¥¤¥ë¤òÇÛÃÖ¤·¤Þ¤¹¡Ê¥Ç¥Õ¥©¥ë¥È¤ÎÀßÄê¤Î¾ì¹ç¡Ë¡£

-+- wiki.cgi
- |
- +- edit.cgi
- |
- +- category.cgi
- |
- +- download.cgi
- |
- +- /lib ¡Ê¥é¥¤¥Ö¥é¥ê¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
- |   |
- |   +- jcode.pl
- |   |
- |   +- cgi-lib.pl
- |   |
- |   +- setup.pl
- |   |
- |   +- common.pl
- |   |
- |   +- mimew.pl
- |
- +- /plugin ¡Ê¥×¥é¥°¥¤¥ó¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
- |   |
- |   +- core.pl
- |
- +- /data ¡Ê¥Ú¡¼¥¸¥Ç¡¼¥¿¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
- |
- +- /backup ¡Ê¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
- |
- +- /attach¡ÊźÉÕ¥Õ¥¡¥¤¥ë¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
- |
- +-/theme ¡Ê¥Æ¡¼¥Þ¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
-    |
-    +- /default
-        |
-        +- default.css
-

wiki.cgi¡¢edit.cgi¡¢category.cgi¡¢download.cgi¤Î¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó¤òCGI¤È¤·¤Æ¼Â¹Ô²Äǽ¤Ê¤è¤¦¤ËÀßÄꤷ¤Þ¤¹¡£¤Þ¤¿¡¢data¥Ç¥£¥ì¥¯¥È¥ê¡¢backup¥Ç¥£¥ì¥¯¥È¥ê¡¢attach¥Ç¥£¥ì¥¯¥È¥ê¤ÏCGI¤«¤é½ñ¤­¹þ¤ß²Äǽ¤Ê¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó¤ËÀßÄꤷ¤Þ¤¹¡£¤Ê¤ª¡¢¥Ç¥£¥ì¥¯¥È¥ê¹½À®¤Ë´Ø¤·¤Æ¤Ïsetup.pl¤òÊÔ½¸¤¹¤ë¤³¤È¤ÇǤ°Õ¤Î¹½Â¤¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥Æ¡¼¥Þ¤Ë´Ø¤·¤Æ¤Ï¸½ºß¤ÎFSWikiLite¤ÎÇÛÉÛ¥¢¡¼¥«¥¤¥Ö¤Ë¤ÏƱº­¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£FSWiki¤Î¥Ç¥£¥¹¥È¥ê¥Ó¥å¡¼¥·¥ç¥ó¤ä¡¢tDiary¤ÎWeb¥µ¥¤¥È¤è¤ê¤ª¹¥¤ß¤Î¥Æ¡¼¥Þ¤ò¼èÆÀ¤·¤Æ¤¯¤À¤µ¤¤¡£

ÊÔ½¸¤ò´ÉÍý¼Ô¤Ë¸ÂÄꤹ¤ë

-

.htaccess¤ò»È¤Ã¤Æedit.cgi¤Ë¥¢¥¯¥»¥¹À©¸Â¤ò¤«¤±¤Þ¤¹¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¤½¤Î¤¦¤Á¡£

»ÈÍѲÄǽ¤Ê¥×¥é¥°¥¤¥ó

-

recent

-

¹¹¿·Æü»þ½ç¤Ë¥Ú¡¼¥¸Ì¾¤Î°ìÍ÷¤ò½ÐÎϤ·¤Þ¤¹¡£°ú¿ô¤Çɽ¼¨·ï¿ô¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£É½¼¨·ï¿ô¤ò¾Êά¤¹¤ë¤ÈÁ´·ï½ÐÎϤ·¤Þ¤¹¡£

{{recent 10}}
-

recentdays

-

ÆüÉÕ¤´¤È¤Ë¹¹¿·¤µ¤ì¤¿¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨¤·¤Þ¤¹¡£°ú¿ô¤Çɽ¼¨Æü¿ô¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£É½¼¨Æü¿ô¤ò¾Êά¤¹¤ë¤ÈºÇ¿·¤Î£µÆüʬ¤ò½ÐÎϤ·¤Þ¤¹¡£

{{recentdays 10}}
-

lastmodified

-

¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·Æü»þ¤òɽ¼¨¤·¤Þ¤¹¡£

{{lastmodified}}
-

category

-

¥Ú¡¼¥¸¤ò¥«¥Æ¥´¥é¥¤¥º¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¤Ç¤¹¡£°ú¿ô¤Ë¥«¥Æ¥´¥ê̾¤ò»ØÄꤷ¤Þ¤¹¡£

{{category ¥«¥Æ¥´¥ê̾}}
-

category_list

-

¥«¥Æ¥´¥ê¤´¤È¤Î¥Ú¡¼¥¸°ìÍ÷¤òɽ¼¨¤·¤Þ¤¹¡£

{{category_list}}
-

°ú¿ô¤È¤·¤Æɽ¼¨¤¹¤ë¥«¥Æ¥´¥ê¤ò»ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

{{category_list ¥«¥Æ¥´¥ê̾}}
-

ref

-

źÉÕ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤ò½ÐÎϤ¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref ¥Õ¥¡¥¤¥ë̾}}
-

ref_image

-

źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref_image ¥Õ¥¡¥¤¥ë̾}}
-

ref_text

-

źÉÕ¥Õ¥¡¥¤¥ë¤òÀ°·ÁºÑ¥Æ¥­¥¹¥È¤È¤·¤Æɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref_text ¥Õ¥¡¥¤¥ë̾}}
-

outline

-

¥Ú¡¼¥¸¤Î¥¢¥¦¥È¥é¥¤¥ó¤òɽ¼¨¤·¤Þ¤¹¡£¸«½Ð¤·¤¬¥Ä¥ê¡¼·Á¼°¤Çɽ¼¨¤µ¤ì¡¢¥¯¥ê¥Ã¥¯¤¹¤ë¤È¤½¤Î¸«½Ð¤·¤Ë¥¸¥ã¥ó¥×¤·¤Þ¤¹¡£Header¤Ê¤É¤ËÆþ¤ì¤Æ¤ª¤¯¤ÈÊØÍø¤Ç¤¹¡£

{{outline}}
-

search

-

¸¡º÷¥Õ¥©¡¼¥à¤òɽ¼¨¤·¤Þ¤¹¡£¥µ¥¤¥É¥Ð¡¼¤Ê¤É¤ËÆþ¤ì¤Æ¤ª¤¯¤ÈÊØÍø¤Ç¤¹¡£

{{search}}
-

¥é¥¤¥»¥ó¥¹

-

FSWikiLite¤ÏGNUL GPL¥é¥¤¥»¥ó¥¹¤Ë´ð¤Å¤¤¤Æ²þÊÑ¡¢ºÆÇÛÉÛ¤¬²Äǽ¤Ç¤¹¡£

ºîÀ®¼Ô

-

Naoki Takezoe <mailto:takezoe@aa.bb-east.ne.jp>

- + + + README + + + +

FSWikiLite¤È¤Ï¡©

+

FSWikiLite¤Î¸µ¤Ë¤Ê¤Ã¤Æ¤¤¤ëFreeStyleWiki¤ÏPerl¤Ë¤è¤ëmodulable¤ÊWiki¥¯¥í¡¼¥ó¤Ç¤¹¡£¥×¥é¥°¥¤¥ó¤Ë¤è¤Ã¤ÆÍÍ¡¹¤Êµ¡Ç½¤òÄɲ乤뤳¤È¤¬¤Ç¤­¤Þ¤¹¡£¤¿¤À¤·¡¢¹âµ¡Ç½¤Êʬ¡¢Ä̾ï¤ÎCGI¥¹¥¯¥ê¥×¥È¤ÈÈæ³Ó¤¹¤ë¤ÈÆ°ºî¤¬½Å¤¤¤È¤¤¤¦·çÅÀ¤¬¤¢¤ê¤Þ¤·¤¿¡£

FSWikiLite¤ÏFSWiki¤Û¤É¹âµ¡Ç½¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤¬¡¢µ¡Ç½¤ò¸ÂÄꤹ¤ë¤³¤È¤Ç·Ú²÷¤ËÆ°ºî¤·¤Þ¤¹¡£¥×¥é¥°¥¤¥ó¤Ï°ìÉô¤·¤«»ÈÍѤǤ­¤Þ¤»¤ó¤¬¡¢Ê¸Ë¡¤ÏFSWiki¤È´°Á´¸ß´¹¤Ç¤¹¡£¤Þ¤¿¡¢FSWiki¤ÈÈæ¤Ù¤ë¤È¹½Â¤¤¬¥·¥ó¥×¥ë¤Êʬ¡¢ÀßÃÖ¤âÍưפǤ¹¡£

¤½¤Î¾¤ËFSWikiLite¤Ï°Ê²¼¤Î¤è¤¦¤ÊÆÃħ¤¬¤¢¤ê¤Þ¤¹¡£

    +
  • tDiary¤Î¥Æ¡¼¥Þ¤ò»ÈÍѲÄǽ¡£ +
  • +
  • ¥µ¥¤¥É¥Ð¡¼¤ä¥Ø¥Ã¥À¡¢¥Õ¥Ã¥¿¤òɽ¼¨²Äǽ¡£ +
  • +
  • FSWiki¤È¤Ï°Û¤Ê¤ë¥·¥ó¥×¥ë¤Ê¥×¥é¥°¥¤¥óµ¡¹½¤òÈ÷¤¨¤Æ¤¤¤ë¡£ +
  • +
  • .htaccess¤ò»ÈÍѤ¹¤ë¤³¤È¤ÇÊÔ½¸¤ò´ÉÍý¿Í¤Î¤ß¤Ë¸ÂÄꤹ¤ë¤³¤È¤¬²Äǽ¡£ +
  • +
  • ¥Ú¡¼¥¸¤Î¥«¥Æ¥´¥é¥¤¥º¤¬²Äǽ¡£ +
  • +
  • ¥Õ¥¡¥¤¥ë¤ÎźÉÕ¤¬²Äǽ¡£ +
  • +
  • PDFÀ¸À®¡¢¥­¡¼¥ï¡¼¥É¥ê¥ó¥¯¡¢InterWiki¤Ê¤É¤Ï»ÈÍÑÉԲġ£ +
  • +

¥¤¥ó¥¹¥È¡¼¥ë

+

lib/setup.pl¤òÊÔ½¸¤·¡¢³Æ¼«¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£

    +
  • $DATA_DIR - ¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ +
  • +
  • $BACKUP_DIR - ¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ +
  • +
  • $ATTACH_DIR - źÉÕ¥Õ¥¡¥¤¥ë¤Î³ÊǼ¾ì½ê¡£ +
  • +
  • $THEME_URL - ¥Æ¡¼¥Þ¡ÊCSS¡Ë¤Î¾ì½ê¡£ +
  • +
  • $SEND_MAIL - sendmail¤Î¥Ñ¥¹¡£¹¹¿·ÄÌÃΤò¼õ¤±¼è¤ë¾ì¹ç¤ÏÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ +
  • +
  • $ADMIN_MAIL- ´ÉÍý¼Ô¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¡£¹¹¿·ÄÌÃΤò¼õ¤±¼è¤ë¾ì¹ç¤ÏÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ +
  • +
  • $WIKI_NAME - WikiName¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ï1¡¢»ÈÍѤ·¤Ê¤¤¾ì¹ç¤Ï0¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ +
  • +
  • $MAIN_SCRIPT - ¥á¥¤¥ó¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +
  • $EDIT_SCRIPT - ÊÔ½¸ÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +
  • $DOWNLOAD_SCRIPT - źÉÕ¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥ÉÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +
  • $CATEGORY_SCRIPT - ¥«¥Æ¥´¥êɽ¼¨ÍÑ¥¹¥¯¥ê¥×¥È¤Î¥Õ¥¡¥¤¥ë̾¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +
  • $SITE_TITLE - ¥µ¥¤¥È̾¡£¼«Í³¤ËÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£ +
  • +
  • $VERSION - FSWikiLite¤Î¥Ð¡¼¥¸¥ç¥ó¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +
  • $SITE_URL - FSWiki¸ø¼°¥µ¥¤¥È¤ÎURL¡£Êѹ¹¤·¤Ê¤¯¤Æ¤â¤¤¤¤¤Ç¤¹¡£ +
  • +

FTP¤Ê¤É¤Ç°Ê²¼¤Î¤è¤¦¤Ë¥Õ¥¡¥¤¥ë¤òÇÛÃÖ¤·¤Þ¤¹¡Ê¥Ç¥Õ¥©¥ë¥È¤ÎÀßÄê¤Î¾ì¹ç¡Ë¡£

-+- wiki.cgi
+ |
+ +- edit.cgi
+ |
+ +- category.cgi
+ |
+ +- download.cgi
+ |
+ +- /lib ¡Ê¥é¥¤¥Ö¥é¥ê¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
+ |   |
+ |   +- jcode.pl
+ |   |
+ |   +- cgi-lib.pl
+ |   |
+ |   +- setup.pl
+ |   |
+ |   +- common.pl
+ |   |
+ |   +- mimew.pl
+ |
+ +- /plugin ¡Ê¥×¥é¥°¥¤¥ó¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
+ |   |
+ |   +- core.pl
+ |
+ +- /data ¡Ê¥Ú¡¼¥¸¥Ç¡¼¥¿¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
+ |
+ +- /backup ¡Ê¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
+ |
+ +- /attach¡ÊźÉÕ¥Õ¥¡¥¤¥ë¤¬½ÐÎϤµ¤ì¤Þ¤¹¡Ë
+ |
+ +-/theme ¡Ê¥Æ¡¼¥Þ¤òÇÛÃÖ¤·¤Þ¤¹¡Ë
+    |
+    +- /default
+        |
+        +- default.css
+

wiki.cgi¡¢edit.cgi¡¢category.cgi¡¢download.cgi¤Î¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó¤òCGI¤È¤·¤Æ¼Â¹Ô²Äǽ¤Ê¤è¤¦¤ËÀßÄꤷ¤Þ¤¹¡£¤Þ¤¿¡¢data¥Ç¥£¥ì¥¯¥È¥ê¡¢backup¥Ç¥£¥ì¥¯¥È¥ê¡¢attach¥Ç¥£¥ì¥¯¥È¥ê¤ÏCGI¤«¤é½ñ¤­¹þ¤ß²Äǽ¤Ê¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó¤ËÀßÄꤷ¤Þ¤¹¡£¤Ê¤ª¡¢¥Ç¥£¥ì¥¯¥È¥ê¹½À®¤Ë´Ø¤·¤Æ¤Ïsetup.pl¤òÊÔ½¸¤¹¤ë¤³¤È¤ÇǤ°Õ¤Î¹½Â¤¤ËÊѹ¹¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥Æ¡¼¥Þ¤Ë´Ø¤·¤Æ¤Ï¸½ºß¤ÎFSWikiLite¤ÎÇÛÉÛ¥¢¡¼¥«¥¤¥Ö¤Ë¤ÏƱº­¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£FSWiki¤Î¥Ç¥£¥¹¥È¥ê¥Ó¥å¡¼¥·¥ç¥ó¤ä¡¢tDiary¤ÎWeb¥µ¥¤¥È¤è¤ê¤ª¹¥¤ß¤Î¥Æ¡¼¥Þ¤ò¼èÆÀ¤·¤Æ¤¯¤À¤µ¤¤¡£

ÊÔ½¸¤ò´ÉÍý¼Ô¤Ë¸ÂÄꤹ¤ë

+

.htaccess¤ò»È¤Ã¤Æedit.cgi¤Ë¥¢¥¯¥»¥¹À©¸Â¤ò¤«¤±¤Þ¤¹¡£¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¤½¤Î¤¦¤Á¡£

»ÈÍѲÄǽ¤Ê¥×¥é¥°¥¤¥ó

+

recent

+

¹¹¿·Æü»þ½ç¤Ë¥Ú¡¼¥¸Ì¾¤Î°ìÍ÷¤ò½ÐÎϤ·¤Þ¤¹¡£°ú¿ô¤Çɽ¼¨·ï¿ô¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£É½¼¨·ï¿ô¤ò¾Êά¤¹¤ë¤ÈÁ´·ï½ÐÎϤ·¤Þ¤¹¡£

{{recent 10}}
+

recentdays

+

ÆüÉÕ¤´¤È¤Ë¹¹¿·¤µ¤ì¤¿¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨¤·¤Þ¤¹¡£°ú¿ô¤Çɽ¼¨Æü¿ô¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£É½¼¨Æü¿ô¤ò¾Êά¤¹¤ë¤ÈºÇ¿·¤Î£µÆüʬ¤ò½ÐÎϤ·¤Þ¤¹¡£

{{recentdays 10}}
+

lastmodified

+

¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·Æü»þ¤òɽ¼¨¤·¤Þ¤¹¡£

{{lastmodified}}
+

category

+

¥Ú¡¼¥¸¤ò¥«¥Æ¥´¥é¥¤¥º¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¤Ç¤¹¡£°ú¿ô¤Ë¥«¥Æ¥´¥ê̾¤ò»ØÄꤷ¤Þ¤¹¡£

{{category ¥«¥Æ¥´¥ê̾}}
+

category_list

+

¥«¥Æ¥´¥ê¤´¤È¤Î¥Ú¡¼¥¸°ìÍ÷¤òɽ¼¨¤·¤Þ¤¹¡£

{{category_list}}
+

°ú¿ô¤È¤·¤Æɽ¼¨¤¹¤ë¥«¥Æ¥´¥ê¤ò»ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

{{category_list ¥«¥Æ¥´¥ê̾}}
+

ref

+

źÉÕ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤ò½ÐÎϤ¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref ¥Õ¥¡¥¤¥ë̾}}
+

ref_image

+

źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref_image ¥Õ¥¡¥¤¥ë̾}}
+

ref_text

+

źÉÕ¥Õ¥¡¥¤¥ë¤òÀ°·ÁºÑ¥Æ¥­¥¹¥È¤È¤·¤Æɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

{{ref_text ¥Õ¥¡¥¤¥ë̾}}
+

outline

+

¥Ú¡¼¥¸¤Î¥¢¥¦¥È¥é¥¤¥ó¤òɽ¼¨¤·¤Þ¤¹¡£¸«½Ð¤·¤¬¥Ä¥ê¡¼·Á¼°¤Çɽ¼¨¤µ¤ì¡¢¥¯¥ê¥Ã¥¯¤¹¤ë¤È¤½¤Î¸«½Ð¤·¤Ë¥¸¥ã¥ó¥×¤·¤Þ¤¹¡£Header¤Ê¤É¤ËÆþ¤ì¤Æ¤ª¤¯¤ÈÊØÍø¤Ç¤¹¡£

{{outline}}
+

search

+

¸¡º÷¥Õ¥©¡¼¥à¤òɽ¼¨¤·¤Þ¤¹¡£¥µ¥¤¥É¥Ð¡¼¤Ê¤É¤ËÆþ¤ì¤Æ¤ª¤¯¤ÈÊØÍø¤Ç¤¹¡£

{{search}}
+

¥é¥¤¥»¥ó¥¹

+

FSWikiLite¤ÏGNUL GPL¥é¥¤¥»¥ó¥¹¤Ë´ð¤Å¤¤¤Æ²þÊÑ¡¢ºÆÇÛÉÛ¤¬²Äǽ¤Ç¤¹¡£

ºîÀ®¼Ô

+

Naoki Takezoe <mailto:takezoe@aa.bb-east.ne.jp>

+ diff --git a/download.cgi b/download.cgi index 5729e87..c1a3caa 100644 --- a/download.cgi +++ b/download.cgi @@ -1,73 +1,73 @@ -#!/usr/bin/perl -################################################################################ -# -# FSWiki Lite - źÉÕ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤¿¤á¤ÎCGI¥¹¥¯¥ê¥×¥È -# -################################################################################ -require "./lib/common.pl"; -#============================================================================== -# ¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë -#============================================================================== -&ReadParse(); -my $page = $in{"p"}; -my $file = $in{"f"}; - -#============================================================================== -# ¥¨¥é¡¼¥Á¥§¥Ã¥¯ -#============================================================================== -if($page eq ""){ - &Util::error("¥Ú¡¼¥¸¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); -} -if($file eq ""){ - &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); -} -#============================================================================== -# ¥À¥¦¥ó¥í¡¼¥É -#============================================================================== -my $filename = sprintf("$main::ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file)); -unless(-e $filename){ - &Util::error("»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¸ºß¤·¤Þ¤»¤ó¡£"); -} - -my $contenttype = &get_mime_type($file); -my $ua = $ENV{"HTTP_USER_AGENT"}; -my $disposition = ($contenttype =~ /^image\// && $ua !~ /MSIE/ ? "inline" : "attachment"); - -&jcode::convert(\$file,'sjis'); - -print "Content-Type: $contenttype\n"; -print "Content-Disposition: $disposition;filename=\"$file\"\n\n"; -open(DATA,$filename); -binmode(DATA); -while(){ - print $_; -} -close(DATA); - - -#============================================================================== -# MIME¥¿¥¤¥×¤ò¼èÆÀ¤·¤Þ¤¹ -#============================================================================== -sub get_mime_type { - my $file = shift; - my $type = lc(substr($file,rindex($file,"."))); - my $ctype; - - if ($type eq ".gif" ){ $ctype = "image/gif"; } - elsif($type eq ".txt" ){ $ctype = "text/plain"; } - elsif($type eq ".rb" ){ $ctype = "text/plain"; } - elsif($type eq ".pl" ){ $ctype = "text/plain"; } - elsif($type eq ".java"){ $ctype = "text/plain"; } -# elsif($type eq ".html"){ $ctype = "text/html"; } -# elsif($type eq ".htm" ){ $ctype = "text/html"; } - elsif($type eq ".css" ){ $ctype = "text/css"; } - elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; } - elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; } - elsif($type eq ".png" ){ $ctype = "image/png"; } - elsif($type eq ".bmp" ){ $ctype = "image/bmp"; } - elsif($type eq ".doc" ){ $ctype = "application/msword"; } - elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; } - else { $ctype = "application/octet-stream"; } - - return $ctype; -} +#!/usr/bin/perl +################################################################################ +# +# FSWiki Lite - źÉÕ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤¿¤á¤ÎCGI¥¹¥¯¥ê¥×¥È +# +################################################################################ +require "./lib/common.pl"; +#============================================================================== +# ¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë +#============================================================================== +&ReadParse(); +my $page = $in{"p"}; +my $file = $in{"f"}; + +#============================================================================== +# ¥¨¥é¡¼¥Á¥§¥Ã¥¯ +#============================================================================== +if($page eq ""){ + &Util::error("¥Ú¡¼¥¸¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); +} +if($file eq ""){ + &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); +} +#============================================================================== +# ¥À¥¦¥ó¥í¡¼¥É +#============================================================================== +my $filename = sprintf("$main::ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file)); +unless(-e $filename){ + &Util::error("»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¸ºß¤·¤Þ¤»¤ó¡£"); +} + +my $contenttype = &get_mime_type($file); +my $ua = $ENV{"HTTP_USER_AGENT"}; +my $disposition = ($contenttype =~ /^image\// && $ua !~ /MSIE/ ? "inline" : "attachment"); + +&jcode::convert(\$file,'sjis'); + +print "Content-Type: $contenttype\n"; +print "Content-Disposition: $disposition;filename=\"$file\"\n\n"; +open(DATA,$filename); +binmode(DATA); +while(){ + print $_; +} +close(DATA); + + +#============================================================================== +# MIME¥¿¥¤¥×¤ò¼èÆÀ¤·¤Þ¤¹ +#============================================================================== +sub get_mime_type { + my $file = shift; + my $type = lc(substr($file,rindex($file,"."))); + my $ctype; + + if ($type eq ".gif" ){ $ctype = "image/gif"; } + elsif($type eq ".txt" ){ $ctype = "text/plain"; } + elsif($type eq ".rb" ){ $ctype = "text/plain"; } + elsif($type eq ".pl" ){ $ctype = "text/plain"; } + elsif($type eq ".java"){ $ctype = "text/plain"; } +# elsif($type eq ".html"){ $ctype = "text/html"; } +# elsif($type eq ".htm" ){ $ctype = "text/html"; } + elsif($type eq ".css" ){ $ctype = "text/css"; } + elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; } + elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; } + elsif($type eq ".png" ){ $ctype = "image/png"; } + elsif($type eq ".bmp" ){ $ctype = "image/bmp"; } + elsif($type eq ".doc" ){ $ctype = "application/msword"; } + elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; } + else { $ctype = "application/octet-stream"; } + + return $ctype; +} diff --git a/edit.cgi b/edit.cgi index c421b26..136b78d 100644 --- a/edit.cgi +++ b/edit.cgi @@ -1,219 +1,219 @@ -#!/usr/bin/perl -################################################################################ -# -# FSWiki Lite - ¥Ú¡¼¥¸ºîÀ®¡¢ÊÔ½¸ÍÑ¥¹¥¯¥ê¥×¥È -# -################################################################################ -require "./lib/common.pl"; -#=============================================================================== -# ½èÍý¤Î¿¶¤êʬ¤± -#=============================================================================== -&ReadParse(); -if($in{"p"} eq ""){ - $in{"p"} = "FrontPage"; -} - -if($in{"p"}=~ /[\|:\[\]]/){ - &Util::error("¥Ú¡¼¥¸Ì¾¤Ë»ÈÍѤǤ­¤Ê¤¤Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£"); -} - -if($in{"a"} eq "edit"){ - &edit_page(); - -} elsif($in{"a"} eq "new"){ - &new_page(); - -} elsif($in{"a"} eq "save"){ - &save_page(); - -} elsif($in{"a"} eq "attach"){ - &attach_file(); - -} elsif($in{"a"} eq "delconf"){ - &attach_delete_confirm(); - -} elsif($in{"a"} eq "delete"){ - &attach_delete(); - -} else { - redirect("FrontPage"); -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤ÎÊÔ½¸ -#------------------------------------------------------------------------------- -sub edit_page { - my $source = shift; - my $page = $in{"p"}; - my $preview = 0; - my $time = $in{"t"}; - - if($source ne ""){ - $preview = 1; - } elsif(&Wiki::exists_page($page)){ - $source = &Wiki::get_page($page); - $time = &Wiki::get_last_modified($page); - } - - &print_header($in{"p"}."¤ÎÊÔ½¸"); - - if($preview==1){ - print &Wiki::process_wiki($source); - } - - print "
\n"; - print "
\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print "
\n"; - - opendir(DIR, $main::ATTACH_DIR); - my ($attachentry, @attachfiles); - while($attachentry = readdir(DIR)){ - my $type = rindex($attachentry,&Util::url_encode($page)."."); - if($type eq 0){ - push(@attachfiles, "$main::ATTACH_DIR/$attachentry"); - } - } - closedir(DIR); - foreach my $attach (@attachfiles){ - $attach =~ /^\Q$main::ATTACH_DIR\E\/(.+)\.(.+)$/; - my $pagename = $1; - my $filename = $2; - print &Wiki::Plugin::ref(&Util::url_decode($filename)); - printf ("[ºï½ü]\n",$pagename,$filename); - } - - print "
\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print "
\n"; - - &print_footer(); -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤ÎºîÀ® -#------------------------------------------------------------------------------- -sub new_page { - &print_header("¥Ú¡¼¥¸¤ÎºîÀ®"); - print "
\n"; - print " \n"; - print " \n"; - print " \n"; - print "
\n"; - &print_footer(); -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤ÎÊݸ -#------------------------------------------------------------------------------- -sub save_page { - my $page = $in{"p"}; - my $source = $in{"source"}; - - if($in{"preview"} ne ""){ - &edit_page($source); - - } else { - # ¥Ú¡¼¥¸¤Îºï½ü - if($source eq ""){ - # ¹¹¿·¤Î½ÅÊ£¥Á¥§¥Ã¥¯ - if(&Wiki::exists_page($page)){ - if($in{"t"} != &Wiki::get_last_modified($page)){ - &Util::error("¤³¤Î¥Ú¡¼¥¸¤Ï´û¤Ë¹¹¿·¤µ¤ì¤Æ¤¤¤Þ¤¹¡£"); - } else { - &Wiki::remove_page($page); - } - } - &redirect("FrontPage"); - - # ¥Ú¡¼¥¸¤ÎºîÀ®¤Þ¤¿¤Ï¹¹¿· - } else { - # ¹¹¿·¤Î½ÅÊ£¥Á¥§¥Ã¥¯ - if(&Wiki::exists_page($page)){ - if($in{"t"} != &Wiki::get_last_modified($page)){ - &Util::error("¤³¤Î¥Ú¡¼¥¸¤Ï´û¤Ë¹¹¿·¤µ¤ì¤Æ¤¤¤Þ¤¹¡£"); - } - } - &Wiki::save_page($page,$source); - &redirect($page); - } - } -} - -#------------------------------------------------------------------------------- -# ¥Õ¥¡¥¤¥ë¤ÎźÉÕ -#------------------------------------------------------------------------------- -sub attach_file { - my $page = $in{"p"}; - my $file = $in{"f"}; # ¥Õ¥¡¥¤¥ëÆâÍƤò¼èÆÀ - my $name = $incfn{"f"}; # ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ - - if($file eq ""){ - &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); - } - - if($name eq ""){ - return; - } - - $name =~ s/\\/\//g; # ¥Ñ¥¹¶èÀÚ¤êʸ»ú¤ò/¤ËÊÑ´¹ - $name = substr($name,rindex($name,"/")+1); # ¥Õ¥¡¥¤¥ë̾¤Î¤ß¤ò¼èÆÀ - - my $filename = sprintf("%s/%s.%s",$main::ATTACH_DIR,&Util::url_encode($page),&Util::url_encode($name)); - open(DATA,">$filename"); - binmode(DATA); - print DATA $file; - close(DATA); - - &redirectURL("$EDIT_SCRIPT?a=edit&p=".&Util::url_encode($page)); -} - -#------------------------------------------------------------------------------- -# źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü³Îǧ -#------------------------------------------------------------------------------- -sub attach_delete_confirm { - my $page = $in{"p"}; - my $file = $in{"f"}; - - if($file eq ""){ - &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); - } - - &print_header("źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü"); - printf ("

%s¤«¤é". - "%s¤òºï½ü¤·¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©

\n", - &Util::url_encode($page),&Util::escapeHTML($page), - &Util::url_encode($page),&Util::url_encode($file),&Util::escapeHTML($file)); - - print "
\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print "
\n"; - &print_footer(); -} - -#------------------------------------------------------------------------------- -# źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü -#------------------------------------------------------------------------------- -sub attach_delete { - my $page = $in{"p"}; - my $file = $in{"f"}; - - if($file eq ""){ - &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); - } - - my $filename = sprintf("$ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file)); - unlink($filename); - - &redirectURL("$EDIT_SCRIPT?a=edit&p=".&Util::url_encode($page)); -} +#!/usr/bin/perl +################################################################################ +# +# FSWiki Lite - ¥Ú¡¼¥¸ºîÀ®¡¢ÊÔ½¸ÍÑ¥¹¥¯¥ê¥×¥È +# +################################################################################ +require "./lib/common.pl"; +#=============================================================================== +# ½èÍý¤Î¿¶¤êʬ¤± +#=============================================================================== +&ReadParse(); +if($in{"p"} eq ""){ + $in{"p"} = "FrontPage"; +} + +if($in{"p"}=~ /[\|:\[\]]/){ + &Util::error("¥Ú¡¼¥¸Ì¾¤Ë»ÈÍѤǤ­¤Ê¤¤Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£"); +} + +if($in{"a"} eq "edit"){ + &edit_page(); + +} elsif($in{"a"} eq "new"){ + &new_page(); + +} elsif($in{"a"} eq "save"){ + &save_page(); + +} elsif($in{"a"} eq "attach"){ + &attach_file(); + +} elsif($in{"a"} eq "delconf"){ + &attach_delete_confirm(); + +} elsif($in{"a"} eq "delete"){ + &attach_delete(); + +} else { + redirect("FrontPage"); +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤ÎÊÔ½¸ +#------------------------------------------------------------------------------- +sub edit_page { + my $source = shift; + my $page = $in{"p"}; + my $preview = 0; + my $time = $in{"t"}; + + if($source ne ""){ + $preview = 1; + } elsif(&Wiki::exists_page($page)){ + $source = &Wiki::get_page($page); + $time = &Wiki::get_last_modified($page); + } + + &print_header($in{"p"}."¤ÎÊÔ½¸"); + + if($preview==1){ + print &Wiki::process_wiki($source); + } + + print "
\n"; + print "
\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print "
\n"; + + opendir(DIR, $main::ATTACH_DIR); + my ($attachentry, @attachfiles); + while($attachentry = readdir(DIR)){ + my $type = rindex($attachentry,&Util::url_encode($page)."."); + if($type eq 0){ + push(@attachfiles, "$main::ATTACH_DIR/$attachentry"); + } + } + closedir(DIR); + foreach my $attach (@attachfiles){ + $attach =~ /^\Q$main::ATTACH_DIR\E\/(.+)\.(.+)$/; + my $pagename = $1; + my $filename = $2; + print &Wiki::Plugin::ref(&Util::url_decode($filename)); + printf ("[ºï½ü]\n",$pagename,$filename); + } + + print "
\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print "
\n"; + + &print_footer(); +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤ÎºîÀ® +#------------------------------------------------------------------------------- +sub new_page { + &print_header("¥Ú¡¼¥¸¤ÎºîÀ®"); + print "
\n"; + print " \n"; + print " \n"; + print " \n"; + print "
\n"; + &print_footer(); +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤ÎÊݸ +#------------------------------------------------------------------------------- +sub save_page { + my $page = $in{"p"}; + my $source = $in{"source"}; + + if($in{"preview"} ne ""){ + &edit_page($source); + + } else { + # ¥Ú¡¼¥¸¤Îºï½ü + if($source eq ""){ + # ¹¹¿·¤Î½ÅÊ£¥Á¥§¥Ã¥¯ + if(&Wiki::exists_page($page)){ + if($in{"t"} != &Wiki::get_last_modified($page)){ + &Util::error("¤³¤Î¥Ú¡¼¥¸¤Ï´û¤Ë¹¹¿·¤µ¤ì¤Æ¤¤¤Þ¤¹¡£"); + } else { + &Wiki::remove_page($page); + } + } + &redirect("FrontPage"); + + # ¥Ú¡¼¥¸¤ÎºîÀ®¤Þ¤¿¤Ï¹¹¿· + } else { + # ¹¹¿·¤Î½ÅÊ£¥Á¥§¥Ã¥¯ + if(&Wiki::exists_page($page)){ + if($in{"t"} != &Wiki::get_last_modified($page)){ + &Util::error("¤³¤Î¥Ú¡¼¥¸¤Ï´û¤Ë¹¹¿·¤µ¤ì¤Æ¤¤¤Þ¤¹¡£"); + } + } + &Wiki::save_page($page,$source); + &redirect($page); + } + } +} + +#------------------------------------------------------------------------------- +# ¥Õ¥¡¥¤¥ë¤ÎźÉÕ +#------------------------------------------------------------------------------- +sub attach_file { + my $page = $in{"p"}; + my $file = $in{"f"}; # ¥Õ¥¡¥¤¥ëÆâÍƤò¼èÆÀ + my $name = $incfn{"f"}; # ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ + + if($file eq ""){ + &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); + } + + if($name eq ""){ + return; + } + + $name =~ s/\\/\//g; # ¥Ñ¥¹¶èÀÚ¤êʸ»ú¤ò/¤ËÊÑ´¹ + $name = substr($name,rindex($name,"/")+1); # ¥Õ¥¡¥¤¥ë̾¤Î¤ß¤ò¼èÆÀ + + my $filename = sprintf("%s/%s.%s",$main::ATTACH_DIR,&Util::url_encode($page),&Util::url_encode($name)); + open(DATA,">$filename"); + binmode(DATA); + print DATA $file; + close(DATA); + + &redirectURL("$EDIT_SCRIPT?a=edit&p=".&Util::url_encode($page)); +} + +#------------------------------------------------------------------------------- +# źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü³Îǧ +#------------------------------------------------------------------------------- +sub attach_delete_confirm { + my $page = $in{"p"}; + my $file = $in{"f"}; + + if($file eq ""){ + &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); + } + + &print_header("źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü"); + printf ("

%s¤«¤é". + "%s¤òºï½ü¤·¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©

\n", + &Util::url_encode($page),&Util::escapeHTML($page), + &Util::url_encode($page),&Util::url_encode($file),&Util::escapeHTML($file)); + + print "
\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print "
\n"; + &print_footer(); +} + +#------------------------------------------------------------------------------- +# źÉÕ¥Õ¥¡¥¤¥ë¤Îºï½ü +#------------------------------------------------------------------------------- +sub attach_delete { + my $page = $in{"p"}; + my $file = $in{"f"}; + + if($file eq ""){ + &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); + } + + my $filename = sprintf("$ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file)); + unlink($filename); + + &redirectURL("$EDIT_SCRIPT?a=edit&p=".&Util::url_encode($page)); +} diff --git a/lib/cgi-lib.pl b/lib/cgi-lib.pl index 72c7ba1..6475a26 100644 --- a/lib/cgi-lib.pl +++ b/lib/cgi-lib.pl @@ -1,456 +1,456 @@ -# Perl Routines to Manipulate CGI input -# S.E.Brenner@bioc.cam.ac.uk -# $Id: cgi-lib.pl,v 1.2 2004/05/24 14:35:08 takezoe Exp $ -# -# Copyright (c) 1996 Steven E. Brenner -# Unpublished work. -# Permission granted to use and modify this library so long as the -# copyright above is maintained, modifications are documented, and -# credit is given for any use of the library. -# -# Thanks are due to many people for reporting bugs and suggestions -# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen, -# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews - -# For more information, see: -# http://www.bio.cam.ac.uk/cgi-lib/ - -$cgi_lib'version = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); - - -# Parameters affecting cgi-lib behavior -# User-configurable parameters affecting file upload. -$cgi_lib'maxdata = 131072; # maximum bytes to accept via POST - 2^17 -$cgi_lib'writefiles = 0; # directory to which to write files, or - # 0 if files should not be written -$cgi_lib'filepre = "cgi-lib"; # Prefix of file names, in directory above - -# Do not change the following parameters unless you have special reasons -$cgi_lib'bufsize = 8192; # default buffer size when reading multipart -$cgi_lib'maxbound = 100; # maximum boundary length to be encounterd -$cgi_lib'headerout = 0; # indicates whether the header has been printed - - -# ReadParse -# Reads in GET or POST data, converts it to unescaped text, and puts -# key/value pairs in %in, using "\0" to separate multiple selections - -# Returns >0 if there was input, 0 if there was no input -# undef indicates some failure. - -# Now that cgi scripts can be put in the normal file space, it is useful -# to combine both the form and the script in one place. If no parameters -# are given (i.e., ReadParse returns FALSE), then a form could be output. - -# If a reference to a hash is given, then the data will be stored in that -# hash, but the data from $in and @in will become inaccessable. -# If a variable-glob (e.g., *cgi_input) is the first parameter to ReadParse, -# information is stored there, rather than in $in, @in, and %in. -# Second, third, and fourth parameters fill associative arrays analagous to -# %in with data relevant to file uploads. - -# If no method is given, the script will process both command-line arguments -# of the form: name=value and any text that is in $ENV{'QUERY_STRING'} -# This is intended to aid debugging and may be changed in future releases - -sub ReadParse { - local (*in) = shift if @_; # CGI input - local (*incfn, # Client's filename (may not be provided) - *inct, # Client's content-type (may not be provided) - *insfn) = @_; # Server's filename (for spooled files) - local ($len, $type, $meth, $errflag, $cmdflag, $perlwarn, $got); - - # Disable warnings as this code deliberately uses local and environment - # variables which are preset to undef (i.e., not explicitly initialized) - $perlwarn = $^W; - $^W = 0; - - binmode(STDIN); # we need these for DOS-based systems - binmode(STDOUT); # and they shouldn't hurt anything else - binmode(STDERR); - - # Get several useful env variables - $type = $ENV{'CONTENT_TYPE'}; - $len = $ENV{'CONTENT_LENGTH'}; - $meth = $ENV{'REQUEST_METHOD'}; - - if ($len > $cgi_lib'maxdata) { #' - &CgiDie("cgi-lib.pl: Request to receive too much data: $len bytes\n"); - } - - if (!defined $meth || $meth eq '' || $meth eq 'GET' || $meth eq 'HEAD' || - $type eq 'application/x-www-form-urlencoded') { - local ($key, $val, $i); - - # Read in text - if (!defined $meth || $meth eq '') { - $in = $ENV{'QUERY_STRING'}; - $cmdflag = 1; # also use command-line options - } elsif($meth eq 'GET' || $meth eq 'HEAD') { - $in = $ENV{'QUERY_STRING'}; - } elsif ($meth eq 'POST') { - if (($got = read(STDIN, $in, $len) != $len)) - {$errflag="Short Read: wanted $len, got $got\n";}; - } else { - &CgiDie("cgi-lib.pl: Unknown request method: $meth\n"); - } - - @in = split(/[&;]/,$in); - push(@in, @ARGV) if $cmdflag; # add command-line parameters - - foreach $i (0 .. $#in) { - # Convert plus to space - $in[$i] =~ s/\+/ /g; - - # Split into key and value. - ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. - - # Convert %XX from hex numbers to alphanumeric - $key =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; - $val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; - - # Associate key and value - $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator - $in{$key} .= $val; - } - - } elsif ($ENV{'CONTENT_TYPE'} =~ m#^multipart/form-data#) { - # for efficiency, compile multipart code only if needed -$errflag = !(eval <<'END_MULTIPART'); - - local ($buf, $boundary, $head, @heads, $cd, $ct, $fname, $ctype, $blen); - local ($bpos, $lpos, $left, $amt, $fn, $ser); - local ($bufsize, $maxbound, $writefiles) = - ($cgi_lib'bufsize, $cgi_lib'maxbound, $cgi_lib'writefiles); - - - # The following lines exist solely to eliminate spurious warning messages - $buf = ''; - - ($boundary) = $type =~ /boundary="([^"]+)"/; #"; # find boundary - ($boundary) = $type =~ /boundary=(\S+)/ unless $boundary; - &CgiDie ("Boundary not provided: probably a bug in your server") - unless $boundary; - $boundary = "--" . $boundary; - $blen = length ($boundary); - - if ($ENV{'REQUEST_METHOD'} ne 'POST') { - &CgiDie("Invalid request method for multipart/form-data: $meth\n"); - } - - if ($writefiles) { - local($me); - stat ($writefiles); - $writefiles = "/tmp" unless -d _ && -r _ && -w _; - # ($me) = $0 =~ m#([^/]*)$#; - $writefiles .= "/$cgi_lib'filepre"; - } - - # read in the data and split into parts: - # put headers in @in and data in %in - # General algorithm: - # There are two dividers: the border and the '\r\n\r\n' between - # header and body. Iterate between searching for these - # Retain a buffer of size(bufsize+maxbound); the latter part is - # to ensure that dividers don't get lost by wrapping between two bufs - # Look for a divider in the current batch. If not found, then - # save all of bufsize, move the maxbound extra buffer to the front of - # the buffer, and read in a new bufsize bytes. If a divider is found, - # save everything up to the divider. Then empty the buffer of everything - # up to the end of the divider. Refill buffer to bufsize+maxbound - # Note slightly odd organization. Code before BODY: really goes with - # code following HEAD:, but is put first to 'pre-fill' buffers. BODY: - # is placed before HEAD: because we first need to discard any 'preface,' - # which would be analagous to a body without a preceeding head. - - $left = $len; - PART: # find each part of the multi-part while reading data - while (1) { - die $@ if $errflag; - - $amt = ($left > $bufsize+$maxbound-length($buf) - ? $bufsize+$maxbound-length($buf): $left); - $errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt); - die "Short Read: wanted $amt, got $got\n" if $errflag; - $left -= $amt; - - $in{$name} .= "\0" if defined $in{$name}; - $in{$name} .= $fn if $fn; - - $name=~/([-\w]+)/; # This allows $insfn{$name} to be untainted - if (defined $1) { - $insfn{$1} .= "\0" if defined $insfn{$1}; - $insfn{$1} .= $fn if $fn; - } - - BODY: - while (($bpos = index($buf, $boundary)) == -1) { - die $@ if $errflag; - if ($name) { # if no $name, then it's the prologue -- discard - if ($fn) { print FILE substr($buf, 0, $bufsize); } - else { $in{$name} .= substr($buf, 0, $bufsize); } - } - $buf = substr($buf, $bufsize); - $amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf); - $errflag = (($got = read(STDIN, $buf, $amt, $maxbound)) != $amt); - die "Short Read: wanted $amt, got $got\n" if $errflag; - $left -= $amt; - } - if (defined $name) { # if no $name, then it's the prologue -- discard - if ($fn) { print FILE substr($buf, 0, $bpos-2); } - else { $in {$name} .= substr($buf, 0, $bpos-2); } # kill last \r\n - } - close (FILE); - last PART if substr($buf, $bpos + $blen, 4) eq "--\r\n"; - substr($buf, 0, $bpos+$blen+2) = ''; - $amt = ($left > $bufsize+$maxbound-length($buf) - ? $bufsize+$maxbound-length($buf) : $left); - $errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt); - die "Short Read: wanted $amt, got $got\n" if $errflag; - $left -= $amt; - - - undef $head; undef $fn; - HEAD: - while (($lpos = index($buf, "\r\n\r\n")) == -1) { - die $@ if $errflag; - $head .= substr($buf, 0, $bufsize); - $buf = substr($buf, $bufsize); - $amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf); - $errflag = (($got = read(STDIN, $buf, $amt, $maxbound)) != $amt); - die "Short Read: wanted $amt, got $got\n" if $errflag; - $left -= $amt; - } - $head .= substr($buf, 0, $lpos+2); - push (@in, $head); - @heads = split("\r\n", $head); - ($cd) = grep (/^\s*Content-Disposition:/i, @heads); - ($ct) = grep (/^\s*Content-Type:/i, @heads); - - ($name) = $cd =~ /\bname="([^"]+)"/i; #"; - ($name) = $cd =~ /\bname=([^\s:;]+)/i unless defined $name; - - ($fname) = $cd =~ /\bfilename="([^"]*)"/i; #"; # filename can be null-str - ($fname) = $cd =~ /\bfilename=([^\s:;]+)/i unless defined $fname; - $incfn{$name} .= (defined $in{$name} ? "\0" : "") . - (defined $fname ? $fname : ""); - - ($ctype) = $ct =~ /^\s*Content-type:\s*"([^"]+)"/i; #"; - ($ctype) = $ct =~ /^\s*Content-Type:\s*([^\s:;]+)/i unless defined $ctype; - $inct{$name} .= (defined $in{$name} ? "\0" : "") . $ctype; - - if ($writefiles && defined $fname) { - $ser++; - $fn = $writefiles . ".$$.$ser"; - open (FILE, ">$fn") || &CgiDie("Couldn't open $fn\n"); - binmode (FILE); # write files accurately - } - substr($buf, 0, $lpos+4) = ''; - undef $fname; - undef $ctype; - } - -1; -END_MULTIPART - if ($errflag) { - local ($errmsg, $value); - $errmsg = $@ || $errflag; - foreach $value (values %insfn) { - unlink(split("\0",$value)); - } - &CgiDie($errmsg); - } else { - # everything's ok. - } - } else { - &CgiDie("cgi-lib.pl: Unknown Content-type: $ENV{'CONTENT_TYPE'}\n"); - } - - # no-ops to avoid warnings - $insfn = $insfn; - $incfn = $incfn; - $inct = $inct; - - $^W = $perlwarn; - - return ($errflag ? undef : scalar(@in)); -} - - -# PrintHeader -# Returns the magic line which tells WWW that we're an HTML document - -sub PrintHeader { - return "Content-type: text/html\n\n"; -} - - -# HtmlTop -# Returns the of a document and the beginning of the body -# with the title and a body

header as specified by the parameter - -sub HtmlTop -{ - local ($title) = @_; - - return < - -$title - - -

$title

-END_OF_TEXT -} - - -# HtmlBot -# Returns the , codes for the bottom of every HTML page - -sub HtmlBot -{ - return "\n\n"; -} - - -# SplitParam -# Splits a multi-valued parameter into a list of the constituent parameters - -sub SplitParam -{ - local ($param) = @_; - local (@params) = split ("\0", $param); - return (wantarray ? @params : $params[0]); -} - - -# MethGet -# Return true if this cgi call was using the GET request, false otherwise - -sub MethGet { - return (defined $ENV{'REQUEST_METHOD'} && $ENV{'REQUEST_METHOD'} eq "GET"); -} - - -# MethPost -# Return true if this cgi call was using the POST request, false otherwise - -sub MethPost { - return (defined $ENV{'REQUEST_METHOD'} && $ENV{'REQUEST_METHOD'} eq "POST"); -} - - -# MyBaseUrl -# Returns the base URL to the script (i.e., no extra path or query string) -sub MyBaseUrl { - local ($ret, $perlwarn); - $perlwarn = $^W; $^W = 0; - $ret = 'http://' . $ENV{'SERVER_NAME'} . - ($ENV{'SERVER_PORT'} != 80 ? ":$ENV{'SERVER_PORT'}" : '') . - $ENV{'SCRIPT_NAME'}; - $^W = $perlwarn; - return $ret; -} - - -# MyFullUrl -# Returns the full URL to the script (i.e., with extra path or query string) -sub MyFullUrl { - local ($ret, $perlwarn); - $perlwarn = $^W; $^W = 0; - $ret = 'http://' . $ENV{'SERVER_NAME'} . - ($ENV{'SERVER_PORT'} != 80 ? ":$ENV{'SERVER_PORT'}" : '') . - $ENV{'SCRIPT_NAME'} . $ENV{'PATH_INFO'} . - (length ($ENV{'QUERY_STRING'}) ? "?$ENV{'QUERY_STRING'}" : ''); - $^W = $perlwarn; - return $ret; -} - - -# MyURL -# Returns the base URL to the script (i.e., no extra path or query string) -# This is obsolete and will be removed in later versions -sub MyURL { - return &MyBaseUrl; -} - - -# CgiError -# Prints out an error message which which containes appropriate headers, -# markup, etcetera. -# Parameters: -# If no parameters, gives a generic error message -# Otherwise, the first parameter will be the title and the rest will -# be given as different paragraphs of the body - -sub CgiError { - local (@msg) = @_; - local ($i,$name); - - if (!@msg) { - $name = &MyFullUrl; - @msg = ("Error: script $name encountered fatal error\n"); - }; - - if (!$cgi_lib'headerout) { #') - print &PrintHeader; - print "\n\n$msg[0]\n\n\n"; - } - print "

$msg[0]

\n"; - foreach $i (1 .. $#msg) { - print "

$msg[$i]

\n"; - } - - $cgi_lib'headerout++; -} - - -# CgiDie -# Identical to CgiError, but also quits with the passed error message. - -sub CgiDie { - local (@msg) = @_; - &CgiError (@msg); - die @msg; -} - - -# PrintVariables -# Nicely formats variables. Three calling options: -# A non-null associative array - prints the items in that array -# A type-glob - prints the items in the associated assoc array -# nothing - defaults to use %in -# Typical use: &PrintVariables() - -sub PrintVariables { - local (*in) = @_ if @_ == 1; - local (%in) = @_ if @_ > 1; - local ($out, $key, $output); - - $output = "\n
\n"; - foreach $key (sort keys(%in)) { - foreach (split("\0", $in{$key})) { - ($out = $_) =~ s/\n/
\n/g; - $output .= "
$key\n
:$out:
\n"; - } - } - $output .= "
\n"; - - return $output; -} - -# PrintEnv -# Nicely formats all environment variables and returns HTML string -sub PrintEnv { - &PrintVariables(*ENV); -} - - -# The following lines exist only to avoid warning messages -$cgi_lib'writefiles = $cgi_lib'writefiles; -$cgi_lib'bufsize = $cgi_lib'bufsize ; -$cgi_lib'maxbound = $cgi_lib'maxbound; -$cgi_lib'version = $cgi_lib'version; -$cgi_lib'filepre = $cgi_lib'filepre; - +# Perl Routines to Manipulate CGI input +# S.E.Brenner@bioc.cam.ac.uk +# $Id: cgi-lib.pl,v 1.2 2004/05/24 14:35:08 takezoe Exp $ +# +# Copyright (c) 1996 Steven E. Brenner +# Unpublished work. +# Permission granted to use and modify this library so long as the +# copyright above is maintained, modifications are documented, and +# credit is given for any use of the library. +# +# Thanks are due to many people for reporting bugs and suggestions +# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen, +# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews + +# For more information, see: +# http://www.bio.cam.ac.uk/cgi-lib/ + +$cgi_lib'version = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); + + +# Parameters affecting cgi-lib behavior +# User-configurable parameters affecting file upload. +$cgi_lib'maxdata = 131072; # maximum bytes to accept via POST - 2^17 +$cgi_lib'writefiles = 0; # directory to which to write files, or + # 0 if files should not be written +$cgi_lib'filepre = "cgi-lib"; # Prefix of file names, in directory above + +# Do not change the following parameters unless you have special reasons +$cgi_lib'bufsize = 8192; # default buffer size when reading multipart +$cgi_lib'maxbound = 100; # maximum boundary length to be encounterd +$cgi_lib'headerout = 0; # indicates whether the header has been printed + + +# ReadParse +# Reads in GET or POST data, converts it to unescaped text, and puts +# key/value pairs in %in, using "\0" to separate multiple selections + +# Returns >0 if there was input, 0 if there was no input +# undef indicates some failure. + +# Now that cgi scripts can be put in the normal file space, it is useful +# to combine both the form and the script in one place. If no parameters +# are given (i.e., ReadParse returns FALSE), then a form could be output. + +# If a reference to a hash is given, then the data will be stored in that +# hash, but the data from $in and @in will become inaccessable. +# If a variable-glob (e.g., *cgi_input) is the first parameter to ReadParse, +# information is stored there, rather than in $in, @in, and %in. +# Second, third, and fourth parameters fill associative arrays analagous to +# %in with data relevant to file uploads. + +# If no method is given, the script will process both command-line arguments +# of the form: name=value and any text that is in $ENV{'QUERY_STRING'} +# This is intended to aid debugging and may be changed in future releases + +sub ReadParse { + local (*in) = shift if @_; # CGI input + local (*incfn, # Client's filename (may not be provided) + *inct, # Client's content-type (may not be provided) + *insfn) = @_; # Server's filename (for spooled files) + local ($len, $type, $meth, $errflag, $cmdflag, $perlwarn, $got); + + # Disable warnings as this code deliberately uses local and environment + # variables which are preset to undef (i.e., not explicitly initialized) + $perlwarn = $^W; + $^W = 0; + + binmode(STDIN); # we need these for DOS-based systems + binmode(STDOUT); # and they shouldn't hurt anything else + binmode(STDERR); + + # Get several useful env variables + $type = $ENV{'CONTENT_TYPE'}; + $len = $ENV{'CONTENT_LENGTH'}; + $meth = $ENV{'REQUEST_METHOD'}; + + if ($len > $cgi_lib'maxdata) { #' + &CgiDie("cgi-lib.pl: Request to receive too much data: $len bytes\n"); + } + + if (!defined $meth || $meth eq '' || $meth eq 'GET' || $meth eq 'HEAD' || + $type eq 'application/x-www-form-urlencoded') { + local ($key, $val, $i); + + # Read in text + if (!defined $meth || $meth eq '') { + $in = $ENV{'QUERY_STRING'}; + $cmdflag = 1; # also use command-line options + } elsif($meth eq 'GET' || $meth eq 'HEAD') { + $in = $ENV{'QUERY_STRING'}; + } elsif ($meth eq 'POST') { + if (($got = read(STDIN, $in, $len) != $len)) + {$errflag="Short Read: wanted $len, got $got\n";}; + } else { + &CgiDie("cgi-lib.pl: Unknown request method: $meth\n"); + } + + @in = split(/[&;]/,$in); + push(@in, @ARGV) if $cmdflag; # add command-line parameters + + foreach $i (0 .. $#in) { + # Convert plus to space + $in[$i] =~ s/\+/ /g; + + # Split into key and value. + ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. + + # Convert %XX from hex numbers to alphanumeric + $key =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; + $val =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; + + # Associate key and value + $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator + $in{$key} .= $val; + } + + } elsif ($ENV{'CONTENT_TYPE'} =~ m#^multipart/form-data#) { + # for efficiency, compile multipart code only if needed +$errflag = !(eval <<'END_MULTIPART'); + + local ($buf, $boundary, $head, @heads, $cd, $ct, $fname, $ctype, $blen); + local ($bpos, $lpos, $left, $amt, $fn, $ser); + local ($bufsize, $maxbound, $writefiles) = + ($cgi_lib'bufsize, $cgi_lib'maxbound, $cgi_lib'writefiles); + + + # The following lines exist solely to eliminate spurious warning messages + $buf = ''; + + ($boundary) = $type =~ /boundary="([^"]+)"/; #"; # find boundary + ($boundary) = $type =~ /boundary=(\S+)/ unless $boundary; + &CgiDie ("Boundary not provided: probably a bug in your server") + unless $boundary; + $boundary = "--" . $boundary; + $blen = length ($boundary); + + if ($ENV{'REQUEST_METHOD'} ne 'POST') { + &CgiDie("Invalid request method for multipart/form-data: $meth\n"); + } + + if ($writefiles) { + local($me); + stat ($writefiles); + $writefiles = "/tmp" unless -d _ && -r _ && -w _; + # ($me) = $0 =~ m#([^/]*)$#; + $writefiles .= "/$cgi_lib'filepre"; + } + + # read in the data and split into parts: + # put headers in @in and data in %in + # General algorithm: + # There are two dividers: the border and the '\r\n\r\n' between + # header and body. Iterate between searching for these + # Retain a buffer of size(bufsize+maxbound); the latter part is + # to ensure that dividers don't get lost by wrapping between two bufs + # Look for a divider in the current batch. If not found, then + # save all of bufsize, move the maxbound extra buffer to the front of + # the buffer, and read in a new bufsize bytes. If a divider is found, + # save everything up to the divider. Then empty the buffer of everything + # up to the end of the divider. Refill buffer to bufsize+maxbound + # Note slightly odd organization. Code before BODY: really goes with + # code following HEAD:, but is put first to 'pre-fill' buffers. BODY: + # is placed before HEAD: because we first need to discard any 'preface,' + # which would be analagous to a body without a preceeding head. + + $left = $len; + PART: # find each part of the multi-part while reading data + while (1) { + die $@ if $errflag; + + $amt = ($left > $bufsize+$maxbound-length($buf) + ? $bufsize+$maxbound-length($buf): $left); + $errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt); + die "Short Read: wanted $amt, got $got\n" if $errflag; + $left -= $amt; + + $in{$name} .= "\0" if defined $in{$name}; + $in{$name} .= $fn if $fn; + + $name=~/([-\w]+)/; # This allows $insfn{$name} to be untainted + if (defined $1) { + $insfn{$1} .= "\0" if defined $insfn{$1}; + $insfn{$1} .= $fn if $fn; + } + + BODY: + while (($bpos = index($buf, $boundary)) == -1) { + die $@ if $errflag; + if ($name) { # if no $name, then it's the prologue -- discard + if ($fn) { print FILE substr($buf, 0, $bufsize); } + else { $in{$name} .= substr($buf, 0, $bufsize); } + } + $buf = substr($buf, $bufsize); + $amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf); + $errflag = (($got = read(STDIN, $buf, $amt, $maxbound)) != $amt); + die "Short Read: wanted $amt, got $got\n" if $errflag; + $left -= $amt; + } + if (defined $name) { # if no $name, then it's the prologue -- discard + if ($fn) { print FILE substr($buf, 0, $bpos-2); } + else { $in {$name} .= substr($buf, 0, $bpos-2); } # kill last \r\n + } + close (FILE); + last PART if substr($buf, $bpos + $blen, 4) eq "--\r\n"; + substr($buf, 0, $bpos+$blen+2) = ''; + $amt = ($left > $bufsize+$maxbound-length($buf) + ? $bufsize+$maxbound-length($buf) : $left); + $errflag = (($got = read(STDIN, $buf, $amt, length($buf))) != $amt); + die "Short Read: wanted $amt, got $got\n" if $errflag; + $left -= $amt; + + + undef $head; undef $fn; + HEAD: + while (($lpos = index($buf, "\r\n\r\n")) == -1) { + die $@ if $errflag; + $head .= substr($buf, 0, $bufsize); + $buf = substr($buf, $bufsize); + $amt = ($left > $bufsize ? $bufsize : $left); #$maxbound==length($buf); + $errflag = (($got = read(STDIN, $buf, $amt, $maxbound)) != $amt); + die "Short Read: wanted $amt, got $got\n" if $errflag; + $left -= $amt; + } + $head .= substr($buf, 0, $lpos+2); + push (@in, $head); + @heads = split("\r\n", $head); + ($cd) = grep (/^\s*Content-Disposition:/i, @heads); + ($ct) = grep (/^\s*Content-Type:/i, @heads); + + ($name) = $cd =~ /\bname="([^"]+)"/i; #"; + ($name) = $cd =~ /\bname=([^\s:;]+)/i unless defined $name; + + ($fname) = $cd =~ /\bfilename="([^"]*)"/i; #"; # filename can be null-str + ($fname) = $cd =~ /\bfilename=([^\s:;]+)/i unless defined $fname; + $incfn{$name} .= (defined $in{$name} ? "\0" : "") . + (defined $fname ? $fname : ""); + + ($ctype) = $ct =~ /^\s*Content-type:\s*"([^"]+)"/i; #"; + ($ctype) = $ct =~ /^\s*Content-Type:\s*([^\s:;]+)/i unless defined $ctype; + $inct{$name} .= (defined $in{$name} ? "\0" : "") . $ctype; + + if ($writefiles && defined $fname) { + $ser++; + $fn = $writefiles . ".$$.$ser"; + open (FILE, ">$fn") || &CgiDie("Couldn't open $fn\n"); + binmode (FILE); # write files accurately + } + substr($buf, 0, $lpos+4) = ''; + undef $fname; + undef $ctype; + } + +1; +END_MULTIPART + if ($errflag) { + local ($errmsg, $value); + $errmsg = $@ || $errflag; + foreach $value (values %insfn) { + unlink(split("\0",$value)); + } + &CgiDie($errmsg); + } else { + # everything's ok. + } + } else { + &CgiDie("cgi-lib.pl: Unknown Content-type: $ENV{'CONTENT_TYPE'}\n"); + } + + # no-ops to avoid warnings + $insfn = $insfn; + $incfn = $incfn; + $inct = $inct; + + $^W = $perlwarn; + + return ($errflag ? undef : scalar(@in)); +} + + +# PrintHeader +# Returns the magic line which tells WWW that we're an HTML document + +sub PrintHeader { + return "Content-type: text/html\n\n"; +} + + +# HtmlTop +# Returns the of a document and the beginning of the body +# with the title and a body

header as specified by the parameter + +sub HtmlTop +{ + local ($title) = @_; + + return < + +$title + + +

$title

+END_OF_TEXT +} + + +# HtmlBot +# Returns the , codes for the bottom of every HTML page + +sub HtmlBot +{ + return "\n\n"; +} + + +# SplitParam +# Splits a multi-valued parameter into a list of the constituent parameters + +sub SplitParam +{ + local ($param) = @_; + local (@params) = split ("\0", $param); + return (wantarray ? @params : $params[0]); +} + + +# MethGet +# Return true if this cgi call was using the GET request, false otherwise + +sub MethGet { + return (defined $ENV{'REQUEST_METHOD'} && $ENV{'REQUEST_METHOD'} eq "GET"); +} + + +# MethPost +# Return true if this cgi call was using the POST request, false otherwise + +sub MethPost { + return (defined $ENV{'REQUEST_METHOD'} && $ENV{'REQUEST_METHOD'} eq "POST"); +} + + +# MyBaseUrl +# Returns the base URL to the script (i.e., no extra path or query string) +sub MyBaseUrl { + local ($ret, $perlwarn); + $perlwarn = $^W; $^W = 0; + $ret = 'http://' . $ENV{'SERVER_NAME'} . + ($ENV{'SERVER_PORT'} != 80 ? ":$ENV{'SERVER_PORT'}" : '') . + $ENV{'SCRIPT_NAME'}; + $^W = $perlwarn; + return $ret; +} + + +# MyFullUrl +# Returns the full URL to the script (i.e., with extra path or query string) +sub MyFullUrl { + local ($ret, $perlwarn); + $perlwarn = $^W; $^W = 0; + $ret = 'http://' . $ENV{'SERVER_NAME'} . + ($ENV{'SERVER_PORT'} != 80 ? ":$ENV{'SERVER_PORT'}" : '') . + $ENV{'SCRIPT_NAME'} . $ENV{'PATH_INFO'} . + (length ($ENV{'QUERY_STRING'}) ? "?$ENV{'QUERY_STRING'}" : ''); + $^W = $perlwarn; + return $ret; +} + + +# MyURL +# Returns the base URL to the script (i.e., no extra path or query string) +# This is obsolete and will be removed in later versions +sub MyURL { + return &MyBaseUrl; +} + + +# CgiError +# Prints out an error message which which containes appropriate headers, +# markup, etcetera. +# Parameters: +# If no parameters, gives a generic error message +# Otherwise, the first parameter will be the title and the rest will +# be given as different paragraphs of the body + +sub CgiError { + local (@msg) = @_; + local ($i,$name); + + if (!@msg) { + $name = &MyFullUrl; + @msg = ("Error: script $name encountered fatal error\n"); + }; + + if (!$cgi_lib'headerout) { #') + print &PrintHeader; + print "\n\n$msg[0]\n\n\n"; + } + print "

$msg[0]

\n"; + foreach $i (1 .. $#msg) { + print "

$msg[$i]

\n"; + } + + $cgi_lib'headerout++; +} + + +# CgiDie +# Identical to CgiError, but also quits with the passed error message. + +sub CgiDie { + local (@msg) = @_; + &CgiError (@msg); + die @msg; +} + + +# PrintVariables +# Nicely formats variables. Three calling options: +# A non-null associative array - prints the items in that array +# A type-glob - prints the items in the associated assoc array +# nothing - defaults to use %in +# Typical use: &PrintVariables() + +sub PrintVariables { + local (*in) = @_ if @_ == 1; + local (%in) = @_ if @_ > 1; + local ($out, $key, $output); + + $output = "\n
\n"; + foreach $key (sort keys(%in)) { + foreach (split("\0", $in{$key})) { + ($out = $_) =~ s/\n/
\n/g; + $output .= "
$key\n
:$out:
\n"; + } + } + $output .= "
\n"; + + return $output; +} + +# PrintEnv +# Nicely formats all environment variables and returns HTML string +sub PrintEnv { + &PrintVariables(*ENV); +} + + +# The following lines exist only to avoid warning messages +$cgi_lib'writefiles = $cgi_lib'writefiles; +$cgi_lib'bufsize = $cgi_lib'bufsize ; +$cgi_lib'maxbound = $cgi_lib'maxbound; +$cgi_lib'version = $cgi_lib'version; +$cgi_lib'filepre = $cgi_lib'filepre; + 1; #return true \ No newline at end of file diff --git a/lib/common.pl b/lib/common.pl index 2e64cfa..4ea9d2a 100644 --- a/lib/common.pl +++ b/lib/common.pl @@ -1,1236 +1,1236 @@ -################################################################################ -# -# FSWikiLite ¶¦ÄÌ´Ø¿ô¥Õ¥¡¥¤¥ë -# -################################################################################ -require "./lib/cgi-lib.pl"; -require "./lib/jcode.pl"; -require "./lib/mimew.pl"; -require "./lib/setup.pl"; -#------------------------------------------------------------------------------- -# °ú¿ô¤ÇÅϤ·¤¿¥Ú¡¼¥¸¤ËÁ«°Ü -#------------------------------------------------------------------------------- -sub redirect { - my $page = shift; - my $url = "$MAIN_SCRIPT?p=".&Util::url_encode($page); - &redirectURL($url); -} - -#------------------------------------------------------------------------------- -# °ú¿ô¤ÇÅϤ·¤¿URL¤ËÁ«°Ü -#------------------------------------------------------------------------------- -sub redirectURL { - my $url = shift; - - print "Content-Type: text/html;charset=EUC-JP\n"; - print "Pragma: no-cache\n"; - print "Cache-Control: no-cache\n\n"; - print "\n"; - print " \n"; - print " moving...\n"; - print " \n"; - print " \n"; - print " \n"; - print " Wait or Click Here!!\n"; - print " \n"; - print "\n"; - - exit; -} - -#------------------------------------------------------------------------------- -# ¥Ø¥Ã¥À¤òɽ¼¨ -#------------------------------------------------------------------------------- -sub print_header { - my $title = shift; - my $show = shift; - - print "Content-Type: text/html;charset=EUC-JP\n"; - print "Pragma: no-cache\n"; - print "Cache-Control: no-cache\n\n"; - print "\n"; - print "\n"; - print "".&Util::escapeHTML($title)." - $SITE_TITLE\n"; - print "\n"; - print "\n"; - print "\n"; - - print "
\n"; - print " \n"; - print " FrontPage\n"; - print " ¿·µ¬\n"; - if($show==1){ - print " ÊÔ½¸\n"; - } - print " ¸¡º÷\n"; - print " °ìÍ÷\n"; - print " ¥Ø¥ë¥×\n"; - print " \n"; - print "
\n"; - - print "

".&Util::escapeHTML($title)."

\n"; - if(&Wiki::exists_page("Menu")){ - print "
\n"; - } - -} - -#------------------------------------------------------------------------------- -# ¥Õ¥Ã¥¿¤òɽ¼¨ -#------------------------------------------------------------------------------- -sub print_footer { - if(&Wiki::exists_page("Menu")){ - print "
\n"; - print "
\n"; - print &Wiki::process_wiki(&Wiki::get_page("Menu")); - print "
\n"; - } - print "\n"; - print "\n"; -} - -############################################################################### -# -# Wiki´ØÏ¢¤Î´Ø¿ô¤òÄ󶡤¹¤ë¥Ñ¥Ã¥±¡¼¥¸ -# -############################################################################### -package Wiki; -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤ò¼èÆÀ -#------------------------------------------------------------------------------- -sub get_page { - my $page = &Util::url_encode(shift); - - open(DATA,"$main::DATA_DIR/$page.wiki") or &Util::error("$main::DATA_DIR/$page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); - my $content = ""; - while(){ - $content .= $_; - } - close(DATA); - - return $content; -} -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤òÊݸ -#------------------------------------------------------------------------------- -sub save_page { - my $page = shift; - my $source = shift; - - $page = &Util::trim($page); - $source =~ s/\r\n/\n/g; - $source =~ s/\r/\n/g; - - my $enc_page = &Util::url_encode($page); - my $action = 'MODIFY'; - unless(-e "$main::DATA_DIR/$enc_page.wiki"){ - $action = 'CREATE'; - } - - # ¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤òºîÀ® - if(-e "$main::DATA_DIR/$enc_page.wiki"){ - open(BACKUP,">$main::BACKUP_DIR/$enc_page.bak") or &Util::error("$main::BACKUP_DIR/$enc_page.bak¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); - open(DATA ,"$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); - while(){ - print BACKUP $_; - } - close(DATA); - close(BACKUP); - } - - # ÆþÎÏÆâÍƤòÊݸ - open(DATA,">$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); - print DATA $source; - close(DATA); - - &send_mail($action,$page); -} -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤òºï½ü -#------------------------------------------------------------------------------- -sub remove_page { - my $page = shift; - my $enc_page = &Util::url_encode($page); - unlink("$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); - - &send_mail('DELETE',$page); -} -#------------------------------------------------------------------------------- -# ¥á¡¼¥ëÁ÷¿® -#------------------------------------------------------------------------------- -sub send_mail { - my $action = shift; - my $page = shift; - my $enc_page = &Util::url_encode($page); - - if($main::ADMIN_MAIL eq "" || $main::SEND_MAIL eq ""){ - return; - } - - my $subject = ""; - if($action eq 'CREATE'){ - $subject = "[FSWikiLite]$page¤¬ºîÀ®¤µ¤ì¤Þ¤·¤¿"; - - } elsif($action eq 'MODIFY'){ - $subject = "[FSWikiLite]$page¤¬¹¹¿·¤µ¤ì¤Þ¤·¤¿"; - - } elsif($action eq 'DELETE'){ - $subject = "[FSWikiLite]$page¤¬ºï½ü¤µ¤ì¤Þ¤·¤¿"; - } - - # MIME¥¨¥ó¥³¡¼¥É - $subject = &main::mimeencode($subject); - - my $head = "Subject: $subject\n". - "From: $main::ADMIN_MAIL\n". - "Content-Transfer-Encoding: 7bit\n". - "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n". - "Reply-To: $main::ADMIN_MAIL\n". - "\n"; - - my $body = "IP:".$ENV{'REMOTE_ADDR'}."\n". - "UA:".$ENV{'HTTP_USER_AGENT'}."\n"; - - if($action eq 'MODIFY' || $action eq 'DELETE'){ - if(-e "$main::BACKUP_DIR/$enc_page.bak"){ - $body .= "°Ê²¼¤ÏÊѹ¹Á°¤Î¥½¡¼¥¹¤Ç¤¹¡£\n". - "-----------------------------------------------------\n"; - open(BACKUP,"$main::BACKUP_DIR/$enc_page.bak"); - while(my $line = ){ - $body .= $line; - } - close(BACKUP); - } - } - - # ʸ»ú¥³¡¼¥É¤ÎÊÑ´¹(jcode.pl¤ò»ÈÍѤ¹¤ë) - &jcode::convert(\$body,'jis'); - - open(MAIL,"| $main::SEND_MAIL $main::ADMIN_MAIL"); - print MAIL $head; - print MAIL $body; - close(MAIL); -} -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤Î°ìÍ÷¤ò¼èÆÀ -#------------------------------------------------------------------------------- -sub get_page_list { - opendir(DIR, $main::DATA_DIR); - my ($fileentry, @files); - while($fileentry = readdir(DIR)){ - my $type = substr($fileentry,rindex($fileentry,".")); - if($type eq ".wiki"){ - push(@files, "$main::DATA_DIR/$fileentry"); - } - } - closedir(DIR); - - my @pages; - foreach my $entry (@files){ - my @stat = stat($entry); - my $time = $stat[9]; - - $entry = substr($entry,length($main::DATA_DIR)+1); - $entry =~ /(.+?)\.wiki/; - my $page = &Util::url_decode($1); - push(@pages,{NAME=>$page,TIME=>$time}); - } - - @pages = sort { $b->{TIME}<=>$a->{TIME} } @pages; - return @pages; -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤Î¹¹¿·Æü»þ¤ò¼èÆÀ -#------------------------------------------------------------------------------- -sub get_last_modified { - my $page = shift; - if(&exists_page($page)){ - my $file = sprintf("%s/%s.wiki",$main::DATA_DIR,&Util::url_encode($page)); - my @stat = stat($file); - return $stat[9]; - } else { - return undef; - } -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤¬Â¸ºß¤¹¤ë¤«¤É¤¦¤« -#------------------------------------------------------------------------------- -sub exists_page { - my $page = &Util::url_encode(shift); - if(-e "$main::DATA_DIR/$page.wiki"){ - return 1; - } else { - return 0; - } -} - -#------------------------------------------------------------------------------- -# Wiki¥½¡¼¥¹¤òÅϤ·¤ÆHTML¤ò¼èÆÀ¤·¤Þ¤¹ -#------------------------------------------------------------------------------- -sub process_wiki { - my $source = shift; - my $main = shift; - my $parser = HTMLParser->new($main); - $parser->parse($source); - - return $parser->{html}; -} - -############################################################################### -# -# HTML¥Ñ¡¼¥µ -# -############################################################################### -package HTMLParser; -#============================================================================== -# ¥³¥ó¥¹¥È¥é¥¯¥¿ -#============================================================================== -sub new { - my $class = shift; - my $mainflg = shift; - my $self = {}; - - if(!defined($mainflg) || $mainflg eq ""){ $mainflg = 0; } - - $self->{html} = ""; - $self->{pre} = ""; - $self->{quote} = ""; - $self->{table} = 0; - $self->{level} = 0; - $self->{para} = 0; - $self->{p_cnt} = 0; - $self->{explan} = 0; - $self->{main} = $mainflg; - return bless $self,$class; -} - -#=============================================================================== -# ¥Ñ¡¼¥¹ -#=============================================================================== -sub parse { - my $self = shift; - my $source = shift; - - $source =~ s/\r//g; - my @lines = split(/\n/,$source); - - foreach my $line (@lines){ - chomp $line; - - # Ê£¿ô¹Ô¤ÎÀâÌÀ - $self->multi_explanation($line); - - my $word1 = substr($line,0,1); - my $word2 = substr($line,0,2); - my $word3 = substr($line,0,3); - - # ¶õ¹Ô - if($line eq ""){ - $self->l_paragraph(); - next; - } - - # ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó - if($line =~ /^{{((.|\s)+?)}}$/){ - my $plugin = &Util::parse_plugin($1); - my $class = $main::P_PLUGIN->{$plugin->{command}}; - if(defined($class)){ - $self->l_plugin($plugin); - } else { - my @obj = $self->parse_line($line); - $self->l_text(\@obj); - } - next; - } - - # PRE - if($word1 eq " " || $word1 eq "\t"){ - $self->l_verbatim($line); - - # ¸«½Ð¤· - } elsif($word3 eq "!!!"){ - my @obj = $self->parse_line(substr($line,3)); - $self->l_headline(1,\@obj); - - } elsif($word2 eq "!!"){ - my @obj = $self->parse_line(substr($line,2)); - $self->l_headline(2,\@obj); - - } elsif($word1 eq "!"){ - my @obj = $self->parse_line(substr($line,1)); - $self->l_headline(3,\@obj); - - # ¹àÌÜ - } elsif($word3 eq "***"){ - my @obj = $self->parse_line(substr($line,3)); - $self->l_list(3,\@obj); - - } elsif($word2 eq "**"){ - my @obj = $self->parse_line(substr($line,2)); - $self->l_list(2,\@obj); - - } elsif($word1 eq "*"){ - my @obj = $self->parse_line(substr($line,1)); - $self->l_list(1,\@obj); - - # ÈÖ¹æÉÕ¤­¹àÌÜ - } elsif($word3 eq "+++"){ - my @obj = $self->parse_line(substr($line,3)); - $self->l_numlist(3,\@obj); - - } elsif($word2 eq "++"){ - my @obj = $self->parse_line(substr($line,2)); - $self->l_numlist(2,\@obj); - - } elsif($word1 eq "+"){ - my @obj = $self->parse_line(substr($line,1)); - $self->l_numlist(1,\@obj); - - # ¿åÊ¿Àþ - } elsif($line eq "----"){ - $self->l_line(); - - # °úÍÑ - } elsif($word2 eq '""'){ - my @obj = $self->parse_line(substr($line,2)); - $self->l_quotation(\@obj); - - # ÀâÌÀ - } elsif(index($line,":")==0 && index($line,":",1)!=-1){ - if(index($line,":::")==0){ - $self->{dd} .= substr($line,3); - next; - } - if(index($line,"::")==0){ - if($self->{dt} ne "" || $self->{dd} ne ""){ - $self->multi_explanation; - } - $self->{dt} = substr($line,2); - $self->{dl_flag} = 1; - next; - } - my $dt = substr($line,1,index($line,":",1)-1); - my $dd = substr($line,index($line,":",1)+1); - my @obj1 = $self->parse_line($dt); - my @obj2 = $self->parse_line($dd); - $self->l_explanation(\@obj1,\@obj2); - - # ¥Æ¡¼¥Ö¥ë - } elsif($word1 eq ","){ - if($line =~ /,$/){ - $line .= " "; - } - my @spl = map {/^"(.*)"$/ ? scalar($_ = $1, s/\"\"/\"/g, $_) : $_} - ($line =~ /,\s*(\"[^\"]*(?:\"\"[^\"]*)*\"|[^,]*)/g); - my @array; - foreach my $value (@spl){ - my @cell = $self->parse_line($value); - push @array,\@cell; - } - $self->l_table(\@array); - - # ¥³¥á¥ó¥È - } elsif($word2 eq "//"){ - - # ²¿¤â¤Ê¤¤¹Ô - } else { - my @obj = $self->parse_line($line); - $self->l_text(\@obj); - } - } - - # Ê£¿ô¹Ô¤ÎÀâÌÀ - $self->multi_explanation; - - $self->end_parse; -} - -#=============================================================================== -# Ê£¿ô¹Ô¤ÎÀâÌÀ -#=============================================================================== -sub multi_explanation { - my $self = shift; - my $line = shift; - if($self->{dl_flag}==1 && (index($line,":")!=0 || !defined($line))){ - my @obj1 = $self->parse_line($self->{dt}); - my @obj2 = $self->parse_line($self->{dd}); - $self->l_explanation(\@obj1,\@obj2); - $self->{dl_flag} = 0; - $self->{dt} = ""; - $self->{dd} = ""; - } -} - -#=============================================================================== -# £±¹Ôʬ¤ò¥Ñ¡¼¥¹ -#=============================================================================== -sub parse_line { - my $self = shift; - my $source = shift; - my @array = (); - - # ¥×¥é¥°¥¤¥ó - if($source =~ /{{((.|\s)+?)}}/){ - my $pre = $`; - my $post = $'; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - my $plugin = &Util::parse_plugin($1); - my $class = $main::I_PLUGIN->{$plugin->{command}}; - if(defined($class)){ - push @array,$self->plugin($plugin); - } else { - push @array,$self->text("{{$1}}"); - } - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # ¥Ü¡¼¥ë¥É¡¢¥¤¥¿¥ê¥Ã¥¯¡¢¼è¤ê¾Ã¤·Àþ¡¢²¼Àþ - } elsif($source =~ /((''')|('')|(==)|(__))(.+?)(\1)/){ - my $pre = $`; - my $post = $'; - my $type = $1; - my $label = $6; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - if($type eq "'''"){ - push @array,$self->bold($label); - } elsif($type eq "__"){ - push @array,$self->underline($label); - } elsif($type eq "''"){ - push @array,$self->italic($label); - } elsif($type eq "=="){ - push @array,$self->denialline($label); - } - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # ¥Ú¡¼¥¸ÊÌ̾¥ê¥ó¥¯ - } elsif($source =~ /\[\[([^\[]+?)\|(.+?)\]\]/){ - my $pre = $`; - my $post = $'; - my $label = $1; - my $page = $2; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - push @array,$self->wiki_anchor($page,$label); - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # URLÊÌ̾¥ê¥ó¥¯ - } elsif($source =~ /\[([^\[]+?)\|((http|https|ftp|mailto):[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*)\]/ - || $source =~ /\[([^\[]+?)\|(file:[^\[\]]*)\]/ - || $source =~ /\[([^\[]+?)\|((\/|\.\/|\.\.\/)+[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*)\]/){ - my $pre = $`; - my $post = $'; - my $label = $1; - my $url = $2; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ - push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; - } else { - push @array,$self->url_anchor($url,$label); - } - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # URL¥ê¥ó¥¯ - } elsif($source =~ /(http|https|ftp|mailto):[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*/ - || $source =~ /\[([^\[]+?)\|(file:[^\[\]]*)\]/){ - my $pre = $`; - my $post = $'; - my $url = $&; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ - push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; - } else { - push @array,$self->url_anchor($url); - } - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # ¥Ú¡¼¥¸¥ê¥ó¥¯ - } elsif($source =~ /\[\[([^\|]+?)\]\]/){ - my $pre = $`; - my $post = $'; - my $page = $1; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - push @array,$self->wiki_anchor($page); - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # Ǥ°Õ¤ÎURL¥ê¥ó¥¯ - } elsif($source =~ /\[([^\[]+?)\|(.+?)\]/){ - my $pre = $`; - my $post = $'; - my $label = $1; - my $url = $2; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ - push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; - } else { - push @array,$self->url_anchor($url,$label); - } - if($post ne ""){ push(@array,$self->parse_line($post)); } - - # WikiName - } elsif($main::WIKI_NAME==1 && $source =~ /[A-Z]+?[a-z]+?([A-Z]+?[a-z]+)+/){ - my $pre = $`; - my $post = $'; - my $page = $&; - if($pre ne ""){ push(@array,$self->parse_line($pre)); } - push @array,$self->wiki_anchor($page); - if($post ne ""){ push(@array,$self->parse_line($post)); } - - } else { - push @array,$self->text($source); - } - - return @array; -} - -#============================================================================== -# ¥ê¥¹¥È -#============================================================================== -sub l_list { - my $self = shift; - my $level = shift; - my $obj = shift; - - if($self->{para}==1){ - $self->{html} .= "

\n"; - $self->{para} = 0; - } - - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - my $html = join("",@$obj); - my $plus = 1; - - if($level < $self->{level}){ $plus = -1; } - if($level==$self->{level}){ - $self->{html} .= "\n"; - } - while($level != $self->{level}){ - if($plus==1){ - $self->{html} .= "
    \n"; - push(@{$self->{close_list}},"
\n"); - } else { - $self->{html} .= "\n"; - $self->{html} .= pop(@{$self->{close_list}}); - } - $self->{level} += $plus; - } - - $self->{html} .= "
  • ".$html; -} - -#============================================================================== -# ÈÖ¹æÉÕ¤­¥ê¥¹¥È -#============================================================================== -sub l_numlist { - my $self = shift; - my $level = shift; - my $obj = shift; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } - - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - my $html = join("",@$obj); - my $plus = 1; - - if($level < $self->{level}){ $plus = -1; } - if($level==$self->{level}){ - $self->{html} .= "
  • \n"; - } - while($level != $self->{level}){ - if($plus==1){ - $self->{html} .= "
      \n"; - push(@{$self->{close_list}},"
    \n"); - } else { - $self->{html} .= "\n"; - $self->{html} .= pop(@{$self->{close_list}}); - } - $self->{level} += $plus; - } - $self->{html} .= "
  • ".$html; -} - -#============================================================================== -# ¥ê¥¹¥È¤Î½ªÎ» -#============================================================================== -sub end_list { - my $self = shift; - if ($self->{level}!=0) { - $self->{html} .= "
  • \n"; - while($self->{level}!=0){ - $self->{html} .= pop(@{$self->{close_list}}); - $self->{level} += -1; - } - } -} - -#============================================================================== -# ¥Ø¥Ã¥É¥é¥¤¥ó -#============================================================================== -sub l_headline { - my $self = shift; - my $level = shift; - my $obj = shift; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - my $html = join("",@$obj); - - if(!$self->{main}){ - $self->{html} .= "".$html."\n"; - } else { - if($level==2){ - $self->{html} .= "{p_cnt}."\">". - "_".$html."\n"; - } else { - $self->{html} .= "". - "{p_cnt}."\">".$html."". - "\n"; - } - } - $self->{p_cnt}++; -} - -#============================================================================== -# ¿åÊ¿Àþ -#============================================================================== -sub l_line { - my $self = shift; - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - $self->{html} .= "
    \n"; -} - -#============================================================================== -# ÃÊÍî¶èÀÚ¤ê -#============================================================================== -sub l_paragraph { - my $self = shift; - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } -} - -#============================================================================== -# À°·ÁºÑ¥Æ¥­¥¹¥È -#============================================================================== -sub l_verbatim { - my $self = shift; - my $text = shift; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } - - $self->end_list; - $self->end_table; - $self->end_quote; - $self->end_explan; - - $self->{pre} .= Util::escapeHTML($text)."\n"; -} - -sub end_verbatim { - my $self = shift; - if($self->{pre} ne ""){ - $self->{html} .= "
    ".$self->{pre}."
    "; - $self->{pre} = ""; - } -} - -#============================================================================== -# ¥Æ¡¼¥Ö¥ë -#============================================================================== -sub l_table { - my $self = shift; - my $row = shift; - $self->end_list; - $self->end_verbatim; - $self->end_quote; - $self->end_explan; - - if($self->{table}==0){ - $self->{table}=1; - $self->{html} .= "\n"; - $self->{html} .= "\n"; - foreach(@$row){ - my $html = join("",@$_); - $self->{html} .= "\n"; - } - $self->{html} .= "\n"; - } else { - $self->{table}=2; - $self->{html} .= "\n"; - foreach(@$row){ - my $html = join("",@$_); - $self->{html} .= "\n"; - } - $self->{html} .= "\n"; - } -} - -sub end_table { - my $self = shift; - if($self->{table}!=0){ - $self->{table} = 0; - $self->{html} .= "
    ".$html."
    ".$html."
    \n"; - } -} - -#============================================================================== -# ¥Ñ¡¼¥¹½ªÎ»»þ¤Î½èÍý -#============================================================================== -sub end_parse { - my $self = shift; - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } -} - -#============================================================================== -# ¹Ô½ñ¼°¤Ë³ºÅö¤·¤Ê¤¤¹Ô -#============================================================================== -sub l_text { - my $self = shift; - my $obj = shift; - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - my $html = join("",@$obj); - - if($self->{para}==0){ - $self->{html} .= "

    "; - $self->{para} = 1; - } - $self->{html} .= $html; -} - -#============================================================================== -# °úÍÑ -#============================================================================== -sub l_quotation { - my $self = shift; - my $obj = shift; - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_explan; - my $html = join("",@$obj); - $self->{quote} .= "

    ".$html."

    \n"; -} - -sub end_quote { - my $self = shift; - if($self->{quote} ne ""){ - $self->{html} .= "
    ".$self->{quote}."
    \n"; - $self->{quote} = ""; - } -} - -#============================================================================== -# ÀâÌÀ -#============================================================================== -sub l_explanation { - my $self = shift; - my $obj1 = shift; - my $obj2 = shift; - - if($self->{para}==1){ - $self->{html} .= "

    "; - $self->{para} = 0; - } - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - - if($self->{explan}==0){ - $self->{explan}=1; - $self->{html} .= "
    \n"; - } - - my $html1 = join("",@$obj1); - my $html2 = join("",@$obj2); - - $self->{html} .= "
    ".$html1."
    \n
    ".$html2."
    \n"; -} - -sub end_explan { - my $self = shift; - if($self->{explan}!=0){ - $self->{explan} = 0; - $self->{html} .= "
    \n"; - } -} - -#============================================================================== -# ¥Ü¡¼¥ë¥É -#============================================================================== -sub bold { - my $self = shift; - my $text = shift; - return "".join("",$self->parse_line($text)).""; -} - -#============================================================================== -# ¥¤¥¿¥ê¥Ã¥¯ -#============================================================================== -sub italic { - my $self = shift; - my $text = shift; - return "".join("",$self->parse_line($text)).""; -} - -#============================================================================== -# ²¼Àþ -#============================================================================== -sub underline { - my $self = shift; - my $text = shift; - return "".join("",$self->parse_line($text)).""; -} - -#============================================================================== -# ÂǤÁ¾Ã¤·Àþ -#============================================================================== -sub denialline { - my $self = shift; - my $text = shift; - return "".join("",$self->parse_line($text)).""; -} - -#============================================================================== -# URL¥¢¥ó¥« -#============================================================================== -sub url_anchor { - my $self = shift; - my $url = shift; - my $name = shift; - - if($name eq ""){ - $name = $url; - } - - if($url eq $name && $url=~/\.(gif|jpg|jpeg|bmp|png)$/i){ - return ""; - } else { - return "".Util::escapeHTML($name).""; - } -} - -#============================================================================== -# Wiki¥Ú¡¼¥¸¤Ø¤Î¥¢¥ó¥« -#============================================================================== -sub wiki_anchor { - my $self = shift; - my $page = shift; - my $name = shift; - - if(!defined($name) || $name eq ""){ - $name = $page; - } - - if(&Wiki::exists_page($page)){ - return "". - &Util::escapeHTML($name).""; - } else { - return "".&Util::escapeHTML($name)."". - "?"; - } -} - -#============================================================================== -# ¤¿¤À¤Î¥Æ¥­¥¹¥È -#============================================================================== -sub text { - my $self = shift; - my $text = shift; - return &Util::escapeHTML($text); -} - -#============================================================================== -# ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó -#============================================================================== -sub plugin { - my $self = shift; - my $plugin = shift; - - my $func_ref = $main::I_PLUGIN->{$plugin->{command}}; - my $result = &$func_ref(@{$plugin->{args}}); - if(defined($result) && $result ne ""){ - return ($result); - } - - return undef; -} - -#============================================================================== -# ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó -#============================================================================== -sub l_plugin { - my $self = shift; - my $plugin = shift; - - if($self->{para}==1){ - $self->{html} .= "

    \n"; - $self->{para} = 0; - } - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - my $func_ref = $main::P_PLUGIN->{$plugin->{command}}; - my $result = &$func_ref(@{$plugin->{args}}); - if(defined($result) && $result ne ""){ - $self->{html} .= $result; - } -} - -#============================================================================== -# ¥¤¥á¡¼¥¸ -#============================================================================== -sub l_image { - my $self = shift; - my $page = shift; - my $file = shift; - my $wiki = $self->{wiki}; - - if($self->{para}==1){ - $self->{html} .= "

    "; - $self->{para} = 0; - } - - $self->end_list; - $self->end_verbatim; - $self->end_table; - $self->end_quote; - $self->end_explan; - - $self->{html} .= "config('script_name')."?action=ATTACH&". - "page=".&Util::url_encode($page)."&file=".&Util::url_encode($file)."\">"; -} - - -################################################################################ -# -# ¥æ¡¼¥Æ¥£¥ê¥Æ¥£´Ø¿ô¤òÄ󶡤¹¤ë¥Ñ¥Ã¥±¡¼¥¸ -# -################################################################################ -package Util; -#=============================================================================== -# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤òURL¥¨¥ó¥³¡¼¥É¤·¤ÆÊÖ¤·¤Þ¤¹¡£ -#=============================================================================== -sub url_encode { - my $retstr = shift; - $retstr =~ s/([^ 0-9A-Za-z])/sprintf("%%%.2X", ord($1))/eg; - $retstr =~ tr/ /+/; - return $retstr; -} - -#=============================================================================== -# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤òURL¥Ç¥³¡¼¥É¤·¤ÆÊÖ¤·¤Þ¤¹¡£ -#=============================================================================== -sub url_decode{ - my $retstr = shift; - $retstr =~ tr/+/ /; - $retstr =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; - return $retstr; -} - -#=============================================================================== -# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤ÎHTML¥¿¥°¤ò¥¨¥¹¥±¡¼¥×¤·¤ÆÊÖ¤·¤Þ¤¹¡£ -#=============================================================================== -sub escapeHTML { - my($retstr) = shift; - my %table = ( - '&' => '&', - '"' => '"', - '<' => '<', - '>' => '>', - ); - $retstr =~ s/([&\"<>])/$table{$1}/go; - return $retstr; -} - - -#=============================================================================== -# ÆüÉÕ¤ò¥Õ¥©¡¼¥Þ¥Ã¥È¤·¤Þ¤¹¡£ -#=============================================================================== -sub format_date { - my $t = shift; - my ($sec, $min, $hour, $mday, $mon, $year) = localtime($t); - return sprintf("%04dǯ%02d·î%02dÆü %02d»þ%02dʬ%02dÉÃ", - $year+1900,$mon+1,$mday,$hour,$min,$sec); -} - -#=============================================================================== -# ʸ»úÎó¤Îξü¤Î¶õÇò¤òÀÚ¤êÍî¤È¤·¤Þ¤¹¡£ -#=============================================================================== -sub trim { - my $text = shift; - if(!defined($text)){ - return ""; - } - $text =~ s/^(?:\s)+//o; - $text =~ s/(?:\s)+$//o; - return $text; -} - - -#=============================================================================== -# ¥¿¥°¤òºï½ü¤·¤Æʸ»úÎó¤Î¤ß¤ò¼èÆÀ¤·¤Þ¤¹¡£ -#=============================================================================== -sub delete_tag { - my $text = shift; - $text =~ s/<(.|\s)+?>//g; - return $text; -} - -#=============================================================================== -# ¿ôÃͤ«¤É¤¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ -#=============================================================================== -sub check_numeric { - my $text = shift; - if($text =~ /^[0-9]+$/){ - return 1; - } else { - return 0; - } -} - -#=============================================================================== -# ¥¨¥é¡¼¤òÄÌÃÎ -#=============================================================================== -sub error { - my $error = shift; - - print "Content-Type: text/html;charset=EUC-JP\n\n"; - print "\n"; - print "¥¨¥é¡¼ - FSWikiLite\n"; - print "\n"; - print "

    ¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿

    \n"; - print "
    \n";
    -	print &Util::escapeHTML($error);
    -	print "
    \n"; - print "\n"; - - exit; -} - -#=============================================================================== -# ·ÈÂÓÅÅÏ䫤ɤ¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ -#=============================================================================== -sub handyphone { - my $ua = $ENV{'HTTP_USER_AGENT'}; - if(!defined($ua)){ - return 0; - } - if($ua=~/^DoCoMo\// || $ua=~ /^J-PHONE\// || $ua=~ /UP\.Browser/){ - return 1; - } else { - return 0; - } -} - -#=============================================================================== -# ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ò¥Ñ¡¼¥¹¤·¤Æ¥³¥Þ¥ó¥É¤È°ú¿ô¤Ëʬ³ä -#=============================================================================== -sub parse_plugin { - my $text = shift; - my ($cmd,@args_tmp) = split(/ /,$text); - my $args_txt = &Util::trim(join(" ",@args_tmp)); - - my @ret_args; - my $tmp = ""; - my $escape = 0; - my $quote = 0; - - for(my $i=0;$i"¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤Î¹½Ê¸¤¬ÉÔÀµ¤Ç¤¹¡£"}; - } else { - $tmp .= $c; - } - } - - if($tmp ne ""){ - push(@ret_args,$tmp); - } - - return {command=>$cmd,args=>\@ret_args}; -} - -1; +################################################################################ +# +# FSWikiLite ¶¦ÄÌ´Ø¿ô¥Õ¥¡¥¤¥ë +# +################################################################################ +require "./lib/cgi-lib.pl"; +require "./lib/jcode.pl"; +require "./lib/mimew.pl"; +require "./lib/setup.pl"; +#------------------------------------------------------------------------------- +# °ú¿ô¤ÇÅϤ·¤¿¥Ú¡¼¥¸¤ËÁ«°Ü +#------------------------------------------------------------------------------- +sub redirect { + my $page = shift; + my $url = "$MAIN_SCRIPT?p=".&Util::url_encode($page); + &redirectURL($url); +} + +#------------------------------------------------------------------------------- +# °ú¿ô¤ÇÅϤ·¤¿URL¤ËÁ«°Ü +#------------------------------------------------------------------------------- +sub redirectURL { + my $url = shift; + + print "Content-Type: text/html;charset=EUC-JP\n"; + print "Pragma: no-cache\n"; + print "Cache-Control: no-cache\n\n"; + print "\n"; + print " \n"; + print " moving...\n"; + print " \n"; + print " \n"; + print " \n"; + print " Wait or Click Here!!\n"; + print " \n"; + print "\n"; + + exit; +} + +#------------------------------------------------------------------------------- +# ¥Ø¥Ã¥À¤òɽ¼¨ +#------------------------------------------------------------------------------- +sub print_header { + my $title = shift; + my $show = shift; + + print "Content-Type: text/html;charset=EUC-JP\n"; + print "Pragma: no-cache\n"; + print "Cache-Control: no-cache\n\n"; + print "\n"; + print "\n"; + print "".&Util::escapeHTML($title)." - $SITE_TITLE\n"; + print "\n"; + print "\n"; + print "\n"; + + print "
    \n"; + print " \n"; + print " FrontPage\n"; + print " ¿·µ¬\n"; + if($show==1){ + print " ÊÔ½¸\n"; + } + print " ¸¡º÷\n"; + print " °ìÍ÷\n"; + print " ¥Ø¥ë¥×\n"; + print " \n"; + print "
    \n"; + + print "

    ".&Util::escapeHTML($title)."

    \n"; + if(&Wiki::exists_page("Menu")){ + print "
    \n"; + } + +} + +#------------------------------------------------------------------------------- +# ¥Õ¥Ã¥¿¤òɽ¼¨ +#------------------------------------------------------------------------------- +sub print_footer { + if(&Wiki::exists_page("Menu")){ + print "
    \n"; + print "
    \n"; + print &Wiki::process_wiki(&Wiki::get_page("Menu")); + print "
    \n"; + } + print "\n"; + print "\n"; +} + +############################################################################### +# +# Wiki´ØÏ¢¤Î´Ø¿ô¤òÄ󶡤¹¤ë¥Ñ¥Ã¥±¡¼¥¸ +# +############################################################################### +package Wiki; +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤ò¼èÆÀ +#------------------------------------------------------------------------------- +sub get_page { + my $page = &Util::url_encode(shift); + + open(DATA,"$main::DATA_DIR/$page.wiki") or &Util::error("$main::DATA_DIR/$page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); + my $content = ""; + while(){ + $content .= $_; + } + close(DATA); + + return $content; +} +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤òÊݸ +#------------------------------------------------------------------------------- +sub save_page { + my $page = shift; + my $source = shift; + + $page = &Util::trim($page); + $source =~ s/\r\n/\n/g; + $source =~ s/\r/\n/g; + + my $enc_page = &Util::url_encode($page); + my $action = 'MODIFY'; + unless(-e "$main::DATA_DIR/$enc_page.wiki"){ + $action = 'CREATE'; + } + + # ¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤òºîÀ® + if(-e "$main::DATA_DIR/$enc_page.wiki"){ + open(BACKUP,">$main::BACKUP_DIR/$enc_page.bak") or &Util::error("$main::BACKUP_DIR/$enc_page.bak¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); + open(DATA ,"$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); + while(){ + print BACKUP $_; + } + close(DATA); + close(BACKUP); + } + + # ÆþÎÏÆâÍƤòÊݸ + open(DATA,">$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Î¥ª¡¼¥×¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); + print DATA $source; + close(DATA); + + &send_mail($action,$page); +} +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤òºï½ü +#------------------------------------------------------------------------------- +sub remove_page { + my $page = shift; + my $enc_page = &Util::url_encode($page); + unlink("$main::DATA_DIR/$enc_page.wiki") or &Util::error("$main::DATA_DIR/$enc_page.wiki¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); + + &send_mail('DELETE',$page); +} +#------------------------------------------------------------------------------- +# ¥á¡¼¥ëÁ÷¿® +#------------------------------------------------------------------------------- +sub send_mail { + my $action = shift; + my $page = shift; + my $enc_page = &Util::url_encode($page); + + if($main::ADMIN_MAIL eq "" || $main::SEND_MAIL eq ""){ + return; + } + + my $subject = ""; + if($action eq 'CREATE'){ + $subject = "[FSWikiLite]$page¤¬ºîÀ®¤µ¤ì¤Þ¤·¤¿"; + + } elsif($action eq 'MODIFY'){ + $subject = "[FSWikiLite]$page¤¬¹¹¿·¤µ¤ì¤Þ¤·¤¿"; + + } elsif($action eq 'DELETE'){ + $subject = "[FSWikiLite]$page¤¬ºï½ü¤µ¤ì¤Þ¤·¤¿"; + } + + # MIME¥¨¥ó¥³¡¼¥É + $subject = &main::mimeencode($subject); + + my $head = "Subject: $subject\n". + "From: $main::ADMIN_MAIL\n". + "Content-Transfer-Encoding: 7bit\n". + "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n". + "Reply-To: $main::ADMIN_MAIL\n". + "\n"; + + my $body = "IP:".$ENV{'REMOTE_ADDR'}."\n". + "UA:".$ENV{'HTTP_USER_AGENT'}."\n"; + + if($action eq 'MODIFY' || $action eq 'DELETE'){ + if(-e "$main::BACKUP_DIR/$enc_page.bak"){ + $body .= "°Ê²¼¤ÏÊѹ¹Á°¤Î¥½¡¼¥¹¤Ç¤¹¡£\n". + "-----------------------------------------------------\n"; + open(BACKUP,"$main::BACKUP_DIR/$enc_page.bak"); + while(my $line = ){ + $body .= $line; + } + close(BACKUP); + } + } + + # ʸ»ú¥³¡¼¥É¤ÎÊÑ´¹(jcode.pl¤ò»ÈÍѤ¹¤ë) + &jcode::convert(\$body,'jis'); + + open(MAIL,"| $main::SEND_MAIL $main::ADMIN_MAIL"); + print MAIL $head; + print MAIL $body; + close(MAIL); +} +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤Î°ìÍ÷¤ò¼èÆÀ +#------------------------------------------------------------------------------- +sub get_page_list { + opendir(DIR, $main::DATA_DIR); + my ($fileentry, @files); + while($fileentry = readdir(DIR)){ + my $type = substr($fileentry,rindex($fileentry,".")); + if($type eq ".wiki"){ + push(@files, "$main::DATA_DIR/$fileentry"); + } + } + closedir(DIR); + + my @pages; + foreach my $entry (@files){ + my @stat = stat($entry); + my $time = $stat[9]; + + $entry = substr($entry,length($main::DATA_DIR)+1); + $entry =~ /(.+?)\.wiki/; + my $page = &Util::url_decode($1); + push(@pages,{NAME=>$page,TIME=>$time}); + } + + @pages = sort { $b->{TIME}<=>$a->{TIME} } @pages; + return @pages; +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤Î¹¹¿·Æü»þ¤ò¼èÆÀ +#------------------------------------------------------------------------------- +sub get_last_modified { + my $page = shift; + if(&exists_page($page)){ + my $file = sprintf("%s/%s.wiki",$main::DATA_DIR,&Util::url_encode($page)); + my @stat = stat($file); + return $stat[9]; + } else { + return undef; + } +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤¬Â¸ºß¤¹¤ë¤«¤É¤¦¤« +#------------------------------------------------------------------------------- +sub exists_page { + my $page = &Util::url_encode(shift); + if(-e "$main::DATA_DIR/$page.wiki"){ + return 1; + } else { + return 0; + } +} + +#------------------------------------------------------------------------------- +# Wiki¥½¡¼¥¹¤òÅϤ·¤ÆHTML¤ò¼èÆÀ¤·¤Þ¤¹ +#------------------------------------------------------------------------------- +sub process_wiki { + my $source = shift; + my $main = shift; + my $parser = HTMLParser->new($main); + $parser->parse($source); + + return $parser->{html}; +} + +############################################################################### +# +# HTML¥Ñ¡¼¥µ +# +############################################################################### +package HTMLParser; +#============================================================================== +# ¥³¥ó¥¹¥È¥é¥¯¥¿ +#============================================================================== +sub new { + my $class = shift; + my $mainflg = shift; + my $self = {}; + + if(!defined($mainflg) || $mainflg eq ""){ $mainflg = 0; } + + $self->{html} = ""; + $self->{pre} = ""; + $self->{quote} = ""; + $self->{table} = 0; + $self->{level} = 0; + $self->{para} = 0; + $self->{p_cnt} = 0; + $self->{explan} = 0; + $self->{main} = $mainflg; + return bless $self,$class; +} + +#=============================================================================== +# ¥Ñ¡¼¥¹ +#=============================================================================== +sub parse { + my $self = shift; + my $source = shift; + + $source =~ s/\r//g; + my @lines = split(/\n/,$source); + + foreach my $line (@lines){ + chomp $line; + + # Ê£¿ô¹Ô¤ÎÀâÌÀ + $self->multi_explanation($line); + + my $word1 = substr($line,0,1); + my $word2 = substr($line,0,2); + my $word3 = substr($line,0,3); + + # ¶õ¹Ô + if($line eq ""){ + $self->l_paragraph(); + next; + } + + # ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó + if($line =~ /^{{((.|\s)+?)}}$/){ + my $plugin = &Util::parse_plugin($1); + my $class = $main::P_PLUGIN->{$plugin->{command}}; + if(defined($class)){ + $self->l_plugin($plugin); + } else { + my @obj = $self->parse_line($line); + $self->l_text(\@obj); + } + next; + } + + # PRE + if($word1 eq " " || $word1 eq "\t"){ + $self->l_verbatim($line); + + # ¸«½Ð¤· + } elsif($word3 eq "!!!"){ + my @obj = $self->parse_line(substr($line,3)); + $self->l_headline(1,\@obj); + + } elsif($word2 eq "!!"){ + my @obj = $self->parse_line(substr($line,2)); + $self->l_headline(2,\@obj); + + } elsif($word1 eq "!"){ + my @obj = $self->parse_line(substr($line,1)); + $self->l_headline(3,\@obj); + + # ¹àÌÜ + } elsif($word3 eq "***"){ + my @obj = $self->parse_line(substr($line,3)); + $self->l_list(3,\@obj); + + } elsif($word2 eq "**"){ + my @obj = $self->parse_line(substr($line,2)); + $self->l_list(2,\@obj); + + } elsif($word1 eq "*"){ + my @obj = $self->parse_line(substr($line,1)); + $self->l_list(1,\@obj); + + # ÈÖ¹æÉÕ¤­¹àÌÜ + } elsif($word3 eq "+++"){ + my @obj = $self->parse_line(substr($line,3)); + $self->l_numlist(3,\@obj); + + } elsif($word2 eq "++"){ + my @obj = $self->parse_line(substr($line,2)); + $self->l_numlist(2,\@obj); + + } elsif($word1 eq "+"){ + my @obj = $self->parse_line(substr($line,1)); + $self->l_numlist(1,\@obj); + + # ¿åÊ¿Àþ + } elsif($line eq "----"){ + $self->l_line(); + + # °úÍÑ + } elsif($word2 eq '""'){ + my @obj = $self->parse_line(substr($line,2)); + $self->l_quotation(\@obj); + + # ÀâÌÀ + } elsif(index($line,":")==0 && index($line,":",1)!=-1){ + if(index($line,":::")==0){ + $self->{dd} .= substr($line,3); + next; + } + if(index($line,"::")==0){ + if($self->{dt} ne "" || $self->{dd} ne ""){ + $self->multi_explanation; + } + $self->{dt} = substr($line,2); + $self->{dl_flag} = 1; + next; + } + my $dt = substr($line,1,index($line,":",1)-1); + my $dd = substr($line,index($line,":",1)+1); + my @obj1 = $self->parse_line($dt); + my @obj2 = $self->parse_line($dd); + $self->l_explanation(\@obj1,\@obj2); + + # ¥Æ¡¼¥Ö¥ë + } elsif($word1 eq ","){ + if($line =~ /,$/){ + $line .= " "; + } + my @spl = map {/^"(.*)"$/ ? scalar($_ = $1, s/\"\"/\"/g, $_) : $_} + ($line =~ /,\s*(\"[^\"]*(?:\"\"[^\"]*)*\"|[^,]*)/g); + my @array; + foreach my $value (@spl){ + my @cell = $self->parse_line($value); + push @array,\@cell; + } + $self->l_table(\@array); + + # ¥³¥á¥ó¥È + } elsif($word2 eq "//"){ + + # ²¿¤â¤Ê¤¤¹Ô + } else { + my @obj = $self->parse_line($line); + $self->l_text(\@obj); + } + } + + # Ê£¿ô¹Ô¤ÎÀâÌÀ + $self->multi_explanation; + + $self->end_parse; +} + +#=============================================================================== +# Ê£¿ô¹Ô¤ÎÀâÌÀ +#=============================================================================== +sub multi_explanation { + my $self = shift; + my $line = shift; + if($self->{dl_flag}==1 && (index($line,":")!=0 || !defined($line))){ + my @obj1 = $self->parse_line($self->{dt}); + my @obj2 = $self->parse_line($self->{dd}); + $self->l_explanation(\@obj1,\@obj2); + $self->{dl_flag} = 0; + $self->{dt} = ""; + $self->{dd} = ""; + } +} + +#=============================================================================== +# £±¹Ôʬ¤ò¥Ñ¡¼¥¹ +#=============================================================================== +sub parse_line { + my $self = shift; + my $source = shift; + my @array = (); + + # ¥×¥é¥°¥¤¥ó + if($source =~ /{{((.|\s)+?)}}/){ + my $pre = $`; + my $post = $'; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + my $plugin = &Util::parse_plugin($1); + my $class = $main::I_PLUGIN->{$plugin->{command}}; + if(defined($class)){ + push @array,$self->plugin($plugin); + } else { + push @array,$self->text("{{$1}}"); + } + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # ¥Ü¡¼¥ë¥É¡¢¥¤¥¿¥ê¥Ã¥¯¡¢¼è¤ê¾Ã¤·Àþ¡¢²¼Àþ + } elsif($source =~ /((''')|('')|(==)|(__))(.+?)(\1)/){ + my $pre = $`; + my $post = $'; + my $type = $1; + my $label = $6; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + if($type eq "'''"){ + push @array,$self->bold($label); + } elsif($type eq "__"){ + push @array,$self->underline($label); + } elsif($type eq "''"){ + push @array,$self->italic($label); + } elsif($type eq "=="){ + push @array,$self->denialline($label); + } + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # ¥Ú¡¼¥¸ÊÌ̾¥ê¥ó¥¯ + } elsif($source =~ /\[\[([^\[]+?)\|(.+?)\]\]/){ + my $pre = $`; + my $post = $'; + my $label = $1; + my $page = $2; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + push @array,$self->wiki_anchor($page,$label); + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # URLÊÌ̾¥ê¥ó¥¯ + } elsif($source =~ /\[([^\[]+?)\|((http|https|ftp|mailto):[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*)\]/ + || $source =~ /\[([^\[]+?)\|(file:[^\[\]]*)\]/ + || $source =~ /\[([^\[]+?)\|((\/|\.\/|\.\.\/)+[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*)\]/){ + my $pre = $`; + my $post = $'; + my $label = $1; + my $url = $2; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ + push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; + } else { + push @array,$self->url_anchor($url,$label); + } + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # URL¥ê¥ó¥¯ + } elsif($source =~ /(http|https|ftp|mailto):[a-zA-Z0-9\.,%~^_+\-%\/\?\(\)!\$&=:;\*#\@']*/ + || $source =~ /\[([^\[]+?)\|(file:[^\[\]]*)\]/){ + my $pre = $`; + my $post = $'; + my $url = $&; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ + push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; + } else { + push @array,$self->url_anchor($url); + } + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # ¥Ú¡¼¥¸¥ê¥ó¥¯ + } elsif($source =~ /\[\[([^\|]+?)\]\]/){ + my $pre = $`; + my $post = $'; + my $page = $1; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + push @array,$self->wiki_anchor($page); + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # Ǥ°Õ¤ÎURL¥ê¥ó¥¯ + } elsif($source =~ /\[([^\[]+?)\|(.+?)\]/){ + my $pre = $`; + my $post = $'; + my $label = $1; + my $url = $2; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + if(index($url,'"') >= 0 || index($url,'><') >= 0 || index($url, 'javascript:') >= 0){ + push @array,"ÉÔÀµ¤Ê¥ê¥ó¥¯¤Ç¤¹¡£"; + } else { + push @array,$self->url_anchor($url,$label); + } + if($post ne ""){ push(@array,$self->parse_line($post)); } + + # WikiName + } elsif($main::WIKI_NAME==1 && $source =~ /[A-Z]+?[a-z]+?([A-Z]+?[a-z]+)+/){ + my $pre = $`; + my $post = $'; + my $page = $&; + if($pre ne ""){ push(@array,$self->parse_line($pre)); } + push @array,$self->wiki_anchor($page); + if($post ne ""){ push(@array,$self->parse_line($post)); } + + } else { + push @array,$self->text($source); + } + + return @array; +} + +#============================================================================== +# ¥ê¥¹¥È +#============================================================================== +sub l_list { + my $self = shift; + my $level = shift; + my $obj = shift; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } + + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + my $html = join("",@$obj); + my $plus = 1; + + if($level < $self->{level}){ $plus = -1; } + if($level==$self->{level}){ + $self->{html} .= "\n"; + } + while($level != $self->{level}){ + if($plus==1){ + $self->{html} .= "
      \n"; + push(@{$self->{close_list}},"
    \n"); + } else { + $self->{html} .= "\n"; + $self->{html} .= pop(@{$self->{close_list}}); + } + $self->{level} += $plus; + } + + $self->{html} .= "
  • ".$html; +} + +#============================================================================== +# ÈÖ¹æÉÕ¤­¥ê¥¹¥È +#============================================================================== +sub l_numlist { + my $self = shift; + my $level = shift; + my $obj = shift; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } + + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + my $html = join("",@$obj); + my $plus = 1; + + if($level < $self->{level}){ $plus = -1; } + if($level==$self->{level}){ + $self->{html} .= "
  • \n"; + } + while($level != $self->{level}){ + if($plus==1){ + $self->{html} .= "
      \n"; + push(@{$self->{close_list}},"
    \n"); + } else { + $self->{html} .= "\n"; + $self->{html} .= pop(@{$self->{close_list}}); + } + $self->{level} += $plus; + } + $self->{html} .= "
  • ".$html; +} + +#============================================================================== +# ¥ê¥¹¥È¤Î½ªÎ» +#============================================================================== +sub end_list { + my $self = shift; + if ($self->{level}!=0) { + $self->{html} .= "
  • \n"; + while($self->{level}!=0){ + $self->{html} .= pop(@{$self->{close_list}}); + $self->{level} += -1; + } + } +} + +#============================================================================== +# ¥Ø¥Ã¥É¥é¥¤¥ó +#============================================================================== +sub l_headline { + my $self = shift; + my $level = shift; + my $obj = shift; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + my $html = join("",@$obj); + + if(!$self->{main}){ + $self->{html} .= "".$html."\n"; + } else { + if($level==2){ + $self->{html} .= "{p_cnt}."\">". + "_".$html."\n"; + } else { + $self->{html} .= "". + "{p_cnt}."\">".$html."". + "\n"; + } + } + $self->{p_cnt}++; +} + +#============================================================================== +# ¿åÊ¿Àþ +#============================================================================== +sub l_line { + my $self = shift; + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + $self->{html} .= "
    \n"; +} + +#============================================================================== +# ÃÊÍî¶èÀÚ¤ê +#============================================================================== +sub l_paragraph { + my $self = shift; + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } +} + +#============================================================================== +# À°·ÁºÑ¥Æ¥­¥¹¥È +#============================================================================== +sub l_verbatim { + my $self = shift; + my $text = shift; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } + + $self->end_list; + $self->end_table; + $self->end_quote; + $self->end_explan; + + $self->{pre} .= Util::escapeHTML($text)."\n"; +} + +sub end_verbatim { + my $self = shift; + if($self->{pre} ne ""){ + $self->{html} .= "
    ".$self->{pre}."
    "; + $self->{pre} = ""; + } +} + +#============================================================================== +# ¥Æ¡¼¥Ö¥ë +#============================================================================== +sub l_table { + my $self = shift; + my $row = shift; + $self->end_list; + $self->end_verbatim; + $self->end_quote; + $self->end_explan; + + if($self->{table}==0){ + $self->{table}=1; + $self->{html} .= "\n"; + $self->{html} .= "\n"; + foreach(@$row){ + my $html = join("",@$_); + $self->{html} .= "\n"; + } + $self->{html} .= "\n"; + } else { + $self->{table}=2; + $self->{html} .= "\n"; + foreach(@$row){ + my $html = join("",@$_); + $self->{html} .= "\n"; + } + $self->{html} .= "\n"; + } +} + +sub end_table { + my $self = shift; + if($self->{table}!=0){ + $self->{table} = 0; + $self->{html} .= "
    ".$html."
    ".$html."
    \n"; + } +} + +#============================================================================== +# ¥Ñ¡¼¥¹½ªÎ»»þ¤Î½èÍý +#============================================================================== +sub end_parse { + my $self = shift; + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } +} + +#============================================================================== +# ¹Ô½ñ¼°¤Ë³ºÅö¤·¤Ê¤¤¹Ô +#============================================================================== +sub l_text { + my $self = shift; + my $obj = shift; + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + my $html = join("",@$obj); + + if($self->{para}==0){ + $self->{html} .= "

    "; + $self->{para} = 1; + } + $self->{html} .= $html; +} + +#============================================================================== +# °úÍÑ +#============================================================================== +sub l_quotation { + my $self = shift; + my $obj = shift; + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_explan; + my $html = join("",@$obj); + $self->{quote} .= "

    ".$html."

    \n"; +} + +sub end_quote { + my $self = shift; + if($self->{quote} ne ""){ + $self->{html} .= "
    ".$self->{quote}."
    \n"; + $self->{quote} = ""; + } +} + +#============================================================================== +# ÀâÌÀ +#============================================================================== +sub l_explanation { + my $self = shift; + my $obj1 = shift; + my $obj2 = shift; + + if($self->{para}==1){ + $self->{html} .= "

    "; + $self->{para} = 0; + } + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + + if($self->{explan}==0){ + $self->{explan}=1; + $self->{html} .= "
    \n"; + } + + my $html1 = join("",@$obj1); + my $html2 = join("",@$obj2); + + $self->{html} .= "
    ".$html1."
    \n
    ".$html2."
    \n"; +} + +sub end_explan { + my $self = shift; + if($self->{explan}!=0){ + $self->{explan} = 0; + $self->{html} .= "
    \n"; + } +} + +#============================================================================== +# ¥Ü¡¼¥ë¥É +#============================================================================== +sub bold { + my $self = shift; + my $text = shift; + return "".join("",$self->parse_line($text)).""; +} + +#============================================================================== +# ¥¤¥¿¥ê¥Ã¥¯ +#============================================================================== +sub italic { + my $self = shift; + my $text = shift; + return "".join("",$self->parse_line($text)).""; +} + +#============================================================================== +# ²¼Àþ +#============================================================================== +sub underline { + my $self = shift; + my $text = shift; + return "".join("",$self->parse_line($text)).""; +} + +#============================================================================== +# ÂǤÁ¾Ã¤·Àþ +#============================================================================== +sub denialline { + my $self = shift; + my $text = shift; + return "".join("",$self->parse_line($text)).""; +} + +#============================================================================== +# URL¥¢¥ó¥« +#============================================================================== +sub url_anchor { + my $self = shift; + my $url = shift; + my $name = shift; + + if($name eq ""){ + $name = $url; + } + + if($url eq $name && $url=~/\.(gif|jpg|jpeg|bmp|png)$/i){ + return ""; + } else { + return "".Util::escapeHTML($name).""; + } +} + +#============================================================================== +# Wiki¥Ú¡¼¥¸¤Ø¤Î¥¢¥ó¥« +#============================================================================== +sub wiki_anchor { + my $self = shift; + my $page = shift; + my $name = shift; + + if(!defined($name) || $name eq ""){ + $name = $page; + } + + if(&Wiki::exists_page($page)){ + return "". + &Util::escapeHTML($name).""; + } else { + return "".&Util::escapeHTML($name)."". + "?"; + } +} + +#============================================================================== +# ¤¿¤À¤Î¥Æ¥­¥¹¥È +#============================================================================== +sub text { + my $self = shift; + my $text = shift; + return &Util::escapeHTML($text); +} + +#============================================================================== +# ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó +#============================================================================== +sub plugin { + my $self = shift; + my $plugin = shift; + + my $func_ref = $main::I_PLUGIN->{$plugin->{command}}; + my $result = &$func_ref(@{$plugin->{args}}); + if(defined($result) && $result ne ""){ + return ($result); + } + + return undef; +} + +#============================================================================== +# ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó +#============================================================================== +sub l_plugin { + my $self = shift; + my $plugin = shift; + + if($self->{para}==1){ + $self->{html} .= "

    \n"; + $self->{para} = 0; + } + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + my $func_ref = $main::P_PLUGIN->{$plugin->{command}}; + my $result = &$func_ref(@{$plugin->{args}}); + if(defined($result) && $result ne ""){ + $self->{html} .= $result; + } +} + +#============================================================================== +# ¥¤¥á¡¼¥¸ +#============================================================================== +sub l_image { + my $self = shift; + my $page = shift; + my $file = shift; + my $wiki = $self->{wiki}; + + if($self->{para}==1){ + $self->{html} .= "

    "; + $self->{para} = 0; + } + + $self->end_list; + $self->end_verbatim; + $self->end_table; + $self->end_quote; + $self->end_explan; + + $self->{html} .= "config('script_name')."?action=ATTACH&". + "page=".&Util::url_encode($page)."&file=".&Util::url_encode($file)."\">"; +} + + +################################################################################ +# +# ¥æ¡¼¥Æ¥£¥ê¥Æ¥£´Ø¿ô¤òÄ󶡤¹¤ë¥Ñ¥Ã¥±¡¼¥¸ +# +################################################################################ +package Util; +#=============================================================================== +# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤òURL¥¨¥ó¥³¡¼¥É¤·¤ÆÊÖ¤·¤Þ¤¹¡£ +#=============================================================================== +sub url_encode { + my $retstr = shift; + $retstr =~ s/([^ 0-9A-Za-z])/sprintf("%%%.2X", ord($1))/eg; + $retstr =~ tr/ /+/; + return $retstr; +} + +#=============================================================================== +# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤òURL¥Ç¥³¡¼¥É¤·¤ÆÊÖ¤·¤Þ¤¹¡£ +#=============================================================================== +sub url_decode{ + my $retstr = shift; + $retstr =~ tr/+/ /; + $retstr =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge; + return $retstr; +} + +#=============================================================================== +# °ú¿ô¤ÇÅϤµ¤ì¤¿Ê¸»úÎó¤ÎHTML¥¿¥°¤ò¥¨¥¹¥±¡¼¥×¤·¤ÆÊÖ¤·¤Þ¤¹¡£ +#=============================================================================== +sub escapeHTML { + my($retstr) = shift; + my %table = ( + '&' => '&', + '"' => '"', + '<' => '<', + '>' => '>', + ); + $retstr =~ s/([&\"<>])/$table{$1}/go; + return $retstr; +} + + +#=============================================================================== +# ÆüÉÕ¤ò¥Õ¥©¡¼¥Þ¥Ã¥È¤·¤Þ¤¹¡£ +#=============================================================================== +sub format_date { + my $t = shift; + my ($sec, $min, $hour, $mday, $mon, $year) = localtime($t); + return sprintf("%04dǯ%02d·î%02dÆü %02d»þ%02dʬ%02dÉÃ", + $year+1900,$mon+1,$mday,$hour,$min,$sec); +} + +#=============================================================================== +# ʸ»úÎó¤Îξü¤Î¶õÇò¤òÀÚ¤êÍî¤È¤·¤Þ¤¹¡£ +#=============================================================================== +sub trim { + my $text = shift; + if(!defined($text)){ + return ""; + } + $text =~ s/^(?:\s)+//o; + $text =~ s/(?:\s)+$//o; + return $text; +} + + +#=============================================================================== +# ¥¿¥°¤òºï½ü¤·¤Æʸ»úÎó¤Î¤ß¤ò¼èÆÀ¤·¤Þ¤¹¡£ +#=============================================================================== +sub delete_tag { + my $text = shift; + $text =~ s/<(.|\s)+?>//g; + return $text; +} + +#=============================================================================== +# ¿ôÃͤ«¤É¤¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ +#=============================================================================== +sub check_numeric { + my $text = shift; + if($text =~ /^[0-9]+$/){ + return 1; + } else { + return 0; + } +} + +#=============================================================================== +# ¥¨¥é¡¼¤òÄÌÃÎ +#=============================================================================== +sub error { + my $error = shift; + + print "Content-Type: text/html;charset=EUC-JP\n\n"; + print "\n"; + print "¥¨¥é¡¼ - FSWikiLite\n"; + print "\n"; + print "

    ¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿

    \n"; + print "
    \n";
    +	print &Util::escapeHTML($error);
    +	print "
    \n"; + print "\n"; + + exit; +} + +#=============================================================================== +# ·ÈÂÓÅÅÏ䫤ɤ¦¤«¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ +#=============================================================================== +sub handyphone { + my $ua = $ENV{'HTTP_USER_AGENT'}; + if(!defined($ua)){ + return 0; + } + if($ua=~/^DoCoMo\// || $ua=~ /^J-PHONE\// || $ua=~ /UP\.Browser/){ + return 1; + } else { + return 0; + } +} + +#=============================================================================== +# ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤ò¥Ñ¡¼¥¹¤·¤Æ¥³¥Þ¥ó¥É¤È°ú¿ô¤Ëʬ³ä +#=============================================================================== +sub parse_plugin { + my $text = shift; + my ($cmd,@args_tmp) = split(/ /,$text); + my $args_txt = &Util::trim(join(" ",@args_tmp)); + + my @ret_args; + my $tmp = ""; + my $escape = 0; + my $quote = 0; + + for(my $i=0;$i"¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤Î¹½Ê¸¤¬ÉÔÀµ¤Ç¤¹¡£"}; + } else { + $tmp .= $c; + } + } + + if($tmp ne ""){ + push(@ret_args,$tmp); + } + + return {command=>$cmd,args=>\@ret_args}; +} + +1; diff --git a/lib/jcode.pl b/lib/jcode.pl index 8af2ac9..828032a 100644 --- a/lib/jcode.pl +++ b/lib/jcode.pl @@ -1,780 +1,780 @@ -package jcode; -;###################################################################### -;# -;# jcode.pl: Perl library for Japanese character code conversion -;# -;# Copyright (c) 1995-1999 Kazumasa Utashiro -;# Internet Initiative Japan Inc. -;# 3-13 Kanda Nishiki-cho, Chiyoda-ku, Tokyo 101-0054, Japan -;# -;# Copyright (c) 1992,1993,1994 Kazumasa Utashiro -;# Software Research Associates, Inc. -;# -;# Use and redistribution for ANY PURPOSE are granted as long as all -;# copyright notices are retained. Redistribution with modification -;# is allowed provided that you make your modified version obviously -;# distinguishable from the original one. THIS SOFTWARE IS PROVIDED -;# BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES ARE -;# DISCLAIMED. -;# -;# Original version was developed under the name of srekcah@sra.co.jp -;# February 1992 and it was called kconv.pl at the beginning. This -;# address was a pen name for group of individuals and it is no longer -;# valid. -;# -;# The latest version is available here: -;# -;# ftp://ftp.iij.ad.jp/pub/IIJ/dist/utashiro/perl/ -;# -;; $rcsid = q$Id: jcode.pl,v 1.1 2003/09/18 15:35:28 takezoe Exp $; -;# -;###################################################################### -;# -;# PERL4 INTERFACE: -;# -;# &jcode'getcode(*line) -;# Return 'jis', 'sjis', 'euc' or undef according to -;# Japanese character code in $line. Return 'binary' if -;# the data has non-character code. -;# -;# When evaluated in array context, it returns a list -;# contains two items. First value is the number of -;# characters which matched to the expected code, and -;# second value is the code name. It is useful if and -;# only if the number is not 0 and the code is undef; -;# that case means it couldn't tell 'euc' or 'sjis' -;# because the evaluation score was exactly same. This -;# interface is too tricky, though. -;# -;# Code detection between euc and sjis is very difficult -;# or sometimes impossible or even lead to wrong result -;# when it includes JIS X0201 KANA characters. So JIS -;# X0201 KANA is ignored for automatic code detection. -;# -;# &jcode'convert(*line, $ocode [, $icode [, $option]]) -;# Convert the contents of $line to the specified -;# Japanese code given in the second argument $ocode. -;# $ocode can be any of "jis", "sjis" or "euc", or use -;# "noconv" when you don't want the code conversion. -;# Input code is recognized automatically from the line -;# itself when $icode is not supplied (JIS X0201 KANA is -;# ignored in code detection. See the above descripton -;# of &getcode). $icode also can be specified, but -;# xxx2yyy routine is more efficient when both codes are -;# known. -;# -;# It returns the code of input string in scalar context, -;# and a list of pointer of convert subroutine and the -;# input code in array context. -;# -;# Japanese character code JIS X0201, X0208, X0212 and -;# ASCII code are supported. X0212 characters can not be -;# represented in SJIS and they will be replased by -;# "geta" character when converted to SJIS. -;# -;# See next paragraph for $option parameter. -;# -;# &jcode'xxx2yyy(*line [, $option]) -;# Convert the Japanese code from xxx to yyy. String xxx -;# and yyy are any convination from "jis", "euc" or -;# "sjis". They return *approximate* number of converted -;# bytes. So return value 0 means the line was not -;# converted at all. -;# -;# Optional parameter $option is used to specify optional -;# conversion method. String "z" is for JIS X0201 KANA -;# to X0208 KANA, and "h" is for reverse. -;# -;# $jcode'convf{'xxx', 'yyy'} -;# The value of this associative array is pointer to the -;# subroutine jcode'xxx2yyy(). -;# -;# &jcode'to($ocode, $line [, $icode [, $option]]) -;# &jcode'jis($line [, $icode [, $option]]) -;# &jcode'euc($line [, $icode [, $option]]) -;# &jcode'sjis($line [, $icode [, $option]]) -;# These functions are prepared for easy use of -;# call/return-by-value interface. You can use these -;# funcitons in s///e operation or any other place for -;# convenience. -;# -;# &jcode'jis_inout($in, $out) -;# Set or inquire JIS start and end sequences. Default -;# is "ESC-$-B" and "ESC-(-B". If you supplied only one -;# character, "ESC-$" or "ESC-(" is prepended for each -;# character respectively. Acutually "ESC-(-B" is not a -;# sequence to end JIS code but a sequence to start ASCII -;# code set. So `in' and `out' are somewhat misleading. -;# -;# &jcode'get_inout($string) -;# Get JIS start and end sequences from $string. -;# -;# &jcode'cache() -;# &jcode'nocache() -;# &jcode'flush() -;# Usually, converted character is cached in memory to -;# avoid same calculations have to be done many times. -;# To disable this caching, call &jcode'nocache(). It -;# can be revived by &jcode'cache() and cache is flushed -;# by calling &jcode'flush(). &cache() and &nocache() -;# functions return previous caching state. -;# -;# --------------------------------------------------------------- -;# -;# &jcode'h2z_xxx(*line) -;# JIS X0201 KANA (so-called Hankaku-KANA) to X0208 KANA -;# (Zenkaku-KANA) code conversion routine. String xxx is -;# any of "jis", "sjis" and "euc". From the difficulty -;# of recognizing code set from 1-byte KATAKANA string, -;# automatic code recognition is not supported. -;# -;# &jcode'z2h_xxx(*line) -;# X0208 to X0201 KANA code conversion routine. String -;# xxx is any of "jis", "sjis" and "euc". -;# -;# $jcode'z2hf{'xxx'} -;# $jcode'h2zf{'xxx'} -;# These are pointer to the corresponding function just -;# as $jcode'convf. -;# -;# --------------------------------------------------------------- -;# -;# &jcode'tr(*line, $from, $to [, $option]) -;# &jcode'tr emulates tr operator for 2 byte code. Only 'd' -;# is interpreted as an option. -;# -;# Range operator like `A-Z' for 2 byte code is partially -;# supported. Code must be JIS or EUC, and first byte -;# have to be same on first and last character. -;# -;# CAUTION: Handling range operator is a kind of trick -;# and it is not perfect. So if you need to transfer `-' -;# character, please be sure to put it at the beginning -;# or the end of $from and $to strings. -;# -;# &jcode'trans($line, $from, $to [, $option) -;# Same as &jcode'tr but accept string and return string -;# after translation. -;# -;# --------------------------------------------------------------- -;# -;# &jcode'init() -;# Initialize the variables used in this package. You -;# don't have to call this when using jocde.pl by `do' or -;# `require' interface. Call it first if you embedded -;# the jcode.pl at the end of your script. -;# -;###################################################################### -;# -;# PERL5 INTERFACE: -;# -;# Current jcode.pl is written in Perl 4 but it is possible to use -;# from Perl 5 using `references'. Fully perl5 capable version is -;# future issue. -;# -;# Since lexical variable is not a subject of typeglob, *string style -;# call doesn't work if the variable is declared as `my'. Same thing -;# happens to special variable $_ if the perl is compiled to use -;# thread capability. So using reference is generally recommented to -;# avoid the mysterious error. -;# -;# jcode::getcode(\$line) -;# jcode::convert(\$line, $ocode [, $icode [, $option]]) -;# jcode::xxx2yyy(\$line [, $option]) -;# &{$jcode::convf{'xxx', 'yyy'}}(\$line) -;# jcode::to($ocode, $line [, $icode [, $option]]) -;# jcode::jis($line [, $icode [, $option]]) -;# jcode::euc($line [, $icode [, $option]]) -;# jcode::sjis($line [, $icode [, $option]]) -;# jcode::jis_inout($in, $out) -;# jcode::get_inout($string) -;# jcode::cache() -;# jcode::nocache() -;# jcode::flush() -;# jcode::h2z_xxx(\$line) -;# jcode::z2h_xxx(\$line) -;# &{$jcode::z2hf{'xxx'}}(\$line) -;# &{$jcode::h2zf{'xxx'}}(\$line) -;# jcode::tr(\$line, $from, $to [, $option]) -;# jcode::trans($line, $from, $to [, $option) -;# jcode::init() -;# -;###################################################################### -;# -;# SAMPLES -;# -;# Convert any Kanji code to JIS and print each line with code name. -;# -;# while (defined($s = <>)) { -;# $code = &jcode'convert(*s, 'jis'); -;# print $code, "\t", $s; -;# } -;# -;# Convert all lines to JIS according to the first recognized line. -;# -;# while (defined($s = <>)) { -;# print, next unless $s =~ /[\033\200-\377]/; -;# (*f, $icode) = &jcode'convert(*s, 'jis'); -;# print; -;# defined(&f) || next; -;# while (<>) { &f(*s); print; } -;# last; -;# } -;# -;# The safest way of JIS conversion. -;# -;# while (defined($s = <>)) { -;# ($matched, $icode) = &jcode'getcode(*s); -;# if (@buf == 0 && $matched == 0) { -;# print $s; -;# next; -;# } -;# push(@buf, $s); -;# next unless $icode; -;# while (defined($s = shift(@buf))) { -;# &jcode'convert(*s, 'jis', $icode); -;# print $s; -;# } -;# while (defined($s = <>)) { -;# &jcode'convert(*s, 'jis', $icode); -;# print $s; -;# } -;# last; -;# } -;# print @buf if @buf; -;# -;###################################################################### - -;# -;# Call initialize function if it is not called yet. This may sound -;# strange but it makes easy to embed the jcode.pl at the end of -;# script. Call &jcode'init at the beginning of the script in that -;# case. -;# -&init unless defined $version; - -;# -;# Initialize variables. -;# -sub init { - $version = $rcsid =~ /,v ([\d.]+)/ ? $1 : 'unkown'; - - $re_bin = '[\000-\006\177\377]'; - - $re_jis0208_1978 = '\e\$\@'; - $re_jis0208_1983 = '\e\$B'; - $re_jis0208_1990 = '\e&\@\e\$B'; - $re_jis0208 = "$re_jis0208_1978|$re_jis0208_1983|$re_jis0208_1990"; - $re_jis0212 = '\e\$\(D'; - $re_jp = "$re_jis0208|$re_jis0212"; - $re_asc = '\e\([BJ]'; - $re_kana = '\e\(I'; - - $esc_0208 = "\e\$B"; - $esc_0212 = "\e\$(D"; - $esc_asc = "\e(B"; - $esc_kana = "\e(I"; - - $re_sjis_c = '[\201-\237\340-\374][\100-\176\200-\374]'; - $re_sjis_kana = '[\241-\337]'; - - $re_euc_c = '[\241-\376][\241-\376]'; - $re_euc_kana = '\216[\241-\337]'; - $re_euc_0212 = '\217[\241-\376][\241-\376]'; - - # Use `geta' for undefined character code - $undef_sjis = "\x81\xac"; - - $cache = 1; - - # X0201 -> X0208 KANA conversion table. Looks weird? Not that - # much. This is simply JIS text without escape sequences. - ($h2z_high = $h2z = <<'__TABLE_END__') =~ tr/\041-\176/\241-\376/; -! !# $ !" % !& " !V # !W -^ !+ _ !, 0 !< -' %! ( %# ) %% * %' + %) -, %c - %e . %g / %C -1 %" 2 %$ 3 %& 4 %( 5 %* -6 %+ 7 %- 8 %/ 9 %1 : %3 -6^ %, 7^ %. 8^ %0 9^ %2 :^ %4 -; %5 < %7 = %9 > %; ? %= -;^ %6 <^ %8 =^ %: >^ %< ?^ %> -@ %? A %A B %D C %F D %H -@^ %@ A^ %B B^ %E C^ %G D^ %I -E %J F %K G %L H %M I %N -J %O K %R L %U M %X N %[ -J^ %P K^ %S L^ %V M^ %Y N^ %\ -J_ %Q K_ %T L_ %W M_ %Z N_ %] -O %^ P %_ Q %` R %a S %b -T %d U %f V %h -W %i X %j Y %k Z %l [ %m -\ %o ] %s & %r 3^ %t -__TABLE_END__ - %h2z = split(/\s+/, $h2z . $h2z_high); - %z2h = reverse %h2z; - - $convf{'jis' , 'jis' } = *jis2jis; - $convf{'jis' , 'sjis'} = *jis2sjis; - $convf{'jis' , 'euc' } = *jis2euc; - $convf{'euc' , 'jis' } = *euc2jis; - $convf{'euc' , 'sjis'} = *euc2sjis; - $convf{'euc' , 'euc' } = *euc2euc; - $convf{'sjis' , 'jis' } = *sjis2jis; - $convf{'sjis' , 'sjis'} = *sjis2sjis; - $convf{'sjis' , 'euc' } = *sjis2euc; - $h2zf{'jis' } = *h2z_jis; - $z2hf{'jis' } = *z2h_jis; - $h2zf{'euc' } = *h2z_euc; - $z2hf{'euc' } = *z2h_euc; - $h2zf{'sjis'} = *h2z_sjis; - $z2hf{'sjis'} = *z2h_sjis; -} - -;# -;# Set escape sequences which should be put before and after Japanese -;# (JIS X0208) string. -;# -sub jis_inout { - $esc_0208 = shift || $esc_0208; - $esc_0208 = "\e\$$esc_0208" if length($esc_0208) == 1; - $esc_asc = shift || $esc_asc; - $esc_asc = "\e\($esc_asc" if length($esc_asc) == 1; - ($esc_0208, $esc_asc); -} - -;# -;# Get JIS in and out sequences from the string. -;# -sub get_inout { - local($esc_0208, $esc_asc); - $_[$[] =~ /($re_jis0208)/o && ($esc_0208 = $1); - $_[$[] =~ /($re_asc)/o && ($esc_asc = $1); - ($esc_0208, $esc_asc); -} - -;# -;# Recognize character code. -;# -sub getcode { - local(*s) = @_; - local($matched, $code); - - if ($s !~ /[\e\200-\377]/) { # not Japanese - $matched = 0; - $code = undef; - } # 'jis' - elsif ($s =~ /$re_jp|$re_asc|$re_kana/o) { - $matched = 1; - $code = 'jis'; - } - elsif ($s =~ /$re_bin/o) { # 'binary' - $matched = 0; - $code = 'binary'; - } - else { # should be 'euc' or 'sjis' - local($sjis, $euc) = (0, 0); - - while ($s =~ /(($re_sjis_c)+)/go) { - $sjis += length($1); - } - while ($s =~ /(($re_euc_c|$re_euc_kana|$re_euc_0212)+)/go) { - $euc += length($1); - } - $matched = &max($sjis, $euc); - $code = ('euc', undef, 'sjis')[($sjis<=>$euc) + $[ + 1]; - } - wantarray ? ($matched, $code) : $code; -} -sub max { $_[ $[ + ($_[ $[ ] < $_[ $[ + 1 ]) ]; } - -;# -;# Convert any code to specified code. -;# -sub convert { - local(*s, $ocode, $icode, $opt) = @_; - return (undef, undef) unless $icode = $icode || &getcode(*s); - return (undef, $icode) if $icode eq 'binary'; - $ocode = 'jis' unless $ocode; - $ocode = $icode if $ocode eq 'noconv'; - local(*f) = $convf{$icode, $ocode}; - &f(*s, $opt); - wantarray ? (*f, $icode) : $icode; -} - -;# -;# Easy return-by-value interfaces. -;# -sub jis { &to('jis', @_); } -sub euc { &to('euc', @_); } -sub sjis { &to('sjis', @_); } -sub to { - local($ocode, $s, $icode, $opt) = @_; - &convert(*s, $ocode, $icode, $opt); - $s; -} -sub what { - local($s) = @_; - &getcode(*s); -} -sub trans { - local($s) = shift; - &tr(*s, @_); - $s; -} - -;# -;# SJIS to JIS -;# -sub sjis2jis { - local(*s, $opt, $n) = @_; - &sjis2sjis(*s, $opt) if $opt; - $s =~ s/(($re_sjis_c|$re_sjis_kana)+)/&_sjis2jis($1) . $esc_asc/geo; - $n; -} -sub _sjis2jis { - local($s) = shift; - $s =~ s/(($re_sjis_c)+|($re_sjis_kana)+)/&__sjis2jis($1)/geo; - $s; -} -sub __sjis2jis { - local($s) = shift; - if ($s =~ /^$re_sjis_kana/o) { - $n += $s =~ tr/\241-\337/\041-\137/; - $esc_kana . $s; - } else { - $n += $s =~ s/($re_sjis_c)/$s2e{$1}||&s2e($1)/geo; - $s =~ tr/\241-\376/\041-\176/; - $esc_0208 . $s; - } -} - -;# -;# EUC to JIS -;# -sub euc2jis { - local(*s, $opt, $n) = @_; - &euc2euc(*s, $opt) if $opt; - $s =~ s/(($re_euc_c|$re_euc_kana|$re_euc_0212)+)/ - &_euc2jis($1) . $esc_asc - /geo; - $n; -} -sub _euc2jis { - local($s) = shift; - $s =~ s/(($re_euc_c)+|($re_euc_kana)+|($re_euc_0212)+)/&__euc2jis($1)/geo; - $s; -} -sub __euc2jis { - local($s) = shift; - local($esc); - - if ($s =~ tr/\216//d) { - $esc = $esc_kana; - } elsif ($s =~ tr/\217//d) { - $esc = $esc_0212; - } else { - $esc = $esc_0208; - } - - $n += $s =~ tr/\241-\376/\041-\176/; - $esc . $s; -} - -;# -;# JIS to EUC -;# -sub jis2euc { - local(*s, $opt, $n) = @_; - $s =~ s/($re_jp|$re_asc|$re_kana)([^\e]*)/&_jis2euc($1,$2)/geo; - &euc2euc(*s, $opt) if $opt; - $n; -} -sub _jis2euc { - local($esc, $s) = @_; - if ($esc !~ /^$re_asc/o) { - $n += $s =~ tr/\041-\176/\241-\376/; - if ($esc =~ /^$re_kana/o) { - $s =~ s/([\241-\337])/\216$1/g; - } - elsif ($esc =~ /^$re_jis0212/o) { - $s =~ s/([\241-\376][\241-\376])/\217$1/g; - } - } - $s; -} - -;# -;# JIS to SJIS -;# -sub jis2sjis { - local(*s, $opt, $n) = @_; - &jis2jis(*s, $opt) if $opt; - $s =~ s/($re_jp|$re_asc|$re_kana)([^\e]*)/&_jis2sjis($1,$2)/geo; - $n; -} -sub _jis2sjis { - local($esc, $s) = @_; - if ($esc =~ /^$re_jis0212/o) { - $s =~ s/../$undef_sjis/g; - $n = length; - } - elsif ($esc !~ /^$re_asc/o) { - $n += $s =~ tr/\041-\176/\241-\376/; - if ($esc =~ /^$re_jp/o) { - $s =~ s/($re_euc_c)/$e2s{$1}||&e2s($1)/geo; - } - } - $s; -} - -;# -;# SJIS to EUC -;# -sub sjis2euc { - local(*s, $opt,$n) = @_; - $n = $s =~ s/($re_sjis_c|$re_sjis_kana)/$s2e{$1}||&s2e($1)/geo; - &euc2euc(*s, $opt) if $opt; - $n; -} -sub s2e { - local($c1, $c2, $code); - ($c1, $c2) = unpack('CC', $code = shift); - - if (0xa1 <= $c1 && $c1 <= 0xdf) { - $c2 = $c1; - $c1 = 0x8e; - } elsif (0x9f <= $c2) { - $c1 = $c1 * 2 - ($c1 >= 0xe0 ? 0xe0 : 0x60); - $c2 += 2; - } else { - $c1 = $c1 * 2 - ($c1 >= 0xe0 ? 0xe1 : 0x61); - $c2 += 0x60 + ($c2 < 0x7f); - } - if ($cache) { - $s2e{$code} = pack('CC', $c1, $c2); - } else { - pack('CC', $c1, $c2); - } -} - -;# -;# EUC to SJIS -;# -sub euc2sjis { - local(*s, $opt,$n) = @_; - &euc2euc(*s, $opt) if $opt; - $n = $s =~ s/($re_euc_c|$re_euc_kana|$re_euc_0212)/$e2s{$1}||&e2s($1)/geo; -} -sub e2s { - local($c1, $c2, $code); - ($c1, $c2) = unpack('CC', $code = shift); - - if ($c1 == 0x8e) { # SS2 - return substr($code, 1, 1); - } elsif ($c1 == 0x8f) { # SS3 - return $undef_sjis; - } elsif ($c1 % 2) { - $c1 = ($c1>>1) + ($c1 < 0xdf ? 0x31 : 0x71); - $c2 -= 0x60 + ($c2 < 0xe0); - } else { - $c1 = ($c1>>1) + ($c1 < 0xdf ? 0x30 : 0x70); - $c2 -= 2; - } - if ($cache) { - $e2s{$code} = pack('CC', $c1, $c2); - } else { - pack('CC', $c1, $c2); - } -} - -;# -;# JIS to JIS, SJIS to SJIS, EUC to EUC -;# -sub jis2jis { - local(*s, $opt) = @_; - $s =~ s/$re_jis0208/$esc_0208/go; - $s =~ s/$re_asc/$esc_asc/go; - &h2z_jis(*s) if $opt =~ /z/; - &z2h_jis(*s) if $opt =~ /h/; -} -sub sjis2sjis { - local(*s, $opt) = @_; - &h2z_sjis(*s) if $opt =~ /z/; - &z2h_sjis(*s) if $opt =~ /h/; -} -sub euc2euc { - local(*s, $opt) = @_; - &h2z_euc(*s) if $opt =~ /z/; - &z2h_euc(*s) if $opt =~ /h/; -} - -;# -;# Cache control functions -;# -sub cache { - ($cache, $cache = 1)[$[]; -} -sub nocache { - ($cache, $cache = 0)[$[]; -} -sub flushcache { - undef %e2s; - undef %s2e; -} - -;# -;# X0201 -> X0208 KANA conversion routine -;# -sub h2z_jis { - local(*s, $n) = @_; - if ($s =~ s/$re_kana([^\e]*)/$esc_0208 . &_h2z_jis($1)/geo) { - 1 while $s =~ s/(($re_jis0208)[^\e]*)($re_jis0208)/$1/o; - } - $n; -} -sub _h2z_jis { - local($s) = @_; - $n += $s =~ s/([\41-\137]([\136\137])?)/$h2z{$1}/g; - $s; -} - -sub h2z_euc { - local(*s) = @_; - $s =~ s/\216([\241-\337])(\216([\336\337]))?/$h2z{"$1$3"}/g; -} - -sub h2z_sjis { - local(*s, $n) = @_; - $s =~ s/(($re_sjis_c)+)|(([\241-\337])([\336\337])?)/ - $1 || ($n++, $e2s{$h2z{$3}} || &e2s($h2z{$3})) - /geo; - $n; -} - -;# -;# X0208 -> X0201 KANA conversion routine -;# -sub z2h_jis { - local(*s, $n) = @_; - $s =~ s/($re_jis0208)([^\e]+)/&_z2h_jis($2)/geo; - $n; -} -sub _z2h_jis { - local($s) = @_; - $s =~ s/((\%[!-~]|![\#\"&VW+,<])+|([^!%][!-~]|![^\#\"&VW+,<])+)/ - &__z2h_jis($1) - /ge; - $s; -} -sub __z2h_jis { - local($s) = @_; - return $esc_0208 . $s unless /^%/ || $s =~ /^![\#\"&VW+,<]/; - $n += length($s) / 2; - $s =~ s/(..)/$z2h{$1}/g; - $esc_kana . $s; -} - -sub z2h_euc { - local(*s, $n) = @_; - &init_z2h_euc unless defined %z2h_euc; - $s =~ s/($re_euc_c|$re_euc_kana)/ - $z2h_euc{$1} ? ($n++, $z2h_euc{$1}) : $1 - /geo; - $n; -} - -sub z2h_sjis { - local(*s, $n) = @_; - &init_z2h_sjis unless defined %z2h_sjis; - $s =~ s/($re_sjis_c)/$z2h_sjis{$1} ? ($n++, $z2h_sjis{$1}) : $1/geo; - $n; -} - -;# -;# Initializing JIS X0208 to X0201 KANA table for EUC and SJIS. This -;# can be done in &init but it's not worth doing. Similarly, -;# precalculated table is not worth to occupy the file space and -;# reduce the readability. The author personnaly discourages to use -;# X0201 Kana character in the any situation. -;# -sub init_z2h_euc { - local($k, $s); - while (($k, $s) = each %z2h) { - $s =~ s/([\241-\337])/\216$1/g && ($z2h_euc{$k} = $s); - } -} -sub init_z2h_sjis { - local($s, $v); - while (($s, $v) = each %z2h) { - $s =~ /[\200-\377]/ && ($z2h_sjis{&e2s($s)} = $v); - } -} - -;# -;# TR function for 2-byte code -;# -sub tr { - # $prev_from, $prev_to, %table are persistent variables - local(*s, $from, $to, $opt) = @_; - local(@from, @to); - local($jis, $n) = (0, 0); - - $jis++, &jis2euc(*s) if $s =~ /$re_jp|$re_asc|$re_kana/o; - $jis++ if $to =~ /$re_jp|$re_asc|$re_kana/o; - - if (!defined($prev_from) || $from ne $prev_from || $to ne $prev_to) { - ($prev_from, $prev_to) = ($from, $to); - undef %table; - &_maketable; - } - - $s =~ s/([\200-\377][\000-\377]|[\000-\377])/ - defined($table{$1}) && ++$n ? $table{$1} : $1 - /ge; - - &euc2jis(*s) if $jis; - - $n; -} - -sub _maketable { - local($ascii) = '(\\\\[\\-\\\\]|[\0-\133\135-\177])'; - - &jis2euc(*to) if $to =~ /$re_jp|$re_asc|$re_kana/o; - &jis2euc(*from) if $from =~ /$re_jp|$re_asc|$re_kana/o; - - grep(s/(([\200-\377])[\200-\377]-\2[\200-\377])/&_expnd2($1)/ge, - $from, $to); - grep(s/($ascii-$ascii)/&_expnd1($1)/geo, - $from, $to); - - @to = $to =~ /[\200-\377][\000-\377]|[\000-\377]/g; - @from = $from =~ /[\200-\377][\000-\377]|[\000-\377]/g; - push(@to, ($opt =~ /d/ ? '' : $to[$#to]) x (@from - @to)) if @to < @from; - @table{@from} = @to; -} - -sub _expnd1 { - local($s) = @_; - $s =~ s/\\(.)/$1/g; - local($c1, $c2) = unpack('CxC', $s); - if ($c1 <= $c2) { - for ($s = ''; $c1 <= $c2; $c1++) { - $s .= pack('C', $c1); - } - } - $s; -} - -sub _expnd2 { - local($s) = @_; - local($c1, $c2, $c3, $c4) = unpack('CCxCC', $s); - if ($c1 == $c3 && $c2 <= $c4) { - for ($s = ''; $c2 <= $c4; $c2++) { - $s .= pack('CC', $c1, $c2); - } - } - $s; -} - -1; +package jcode; +;###################################################################### +;# +;# jcode.pl: Perl library for Japanese character code conversion +;# +;# Copyright (c) 1995-1999 Kazumasa Utashiro +;# Internet Initiative Japan Inc. +;# 3-13 Kanda Nishiki-cho, Chiyoda-ku, Tokyo 101-0054, Japan +;# +;# Copyright (c) 1992,1993,1994 Kazumasa Utashiro +;# Software Research Associates, Inc. +;# +;# Use and redistribution for ANY PURPOSE are granted as long as all +;# copyright notices are retained. Redistribution with modification +;# is allowed provided that you make your modified version obviously +;# distinguishable from the original one. THIS SOFTWARE IS PROVIDED +;# BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES ARE +;# DISCLAIMED. +;# +;# Original version was developed under the name of srekcah@sra.co.jp +;# February 1992 and it was called kconv.pl at the beginning. This +;# address was a pen name for group of individuals and it is no longer +;# valid. +;# +;# The latest version is available here: +;# +;# ftp://ftp.iij.ad.jp/pub/IIJ/dist/utashiro/perl/ +;# +;; $rcsid = q$Id: jcode.pl,v 1.1 2003/09/18 15:35:28 takezoe Exp $; +;# +;###################################################################### +;# +;# PERL4 INTERFACE: +;# +;# &jcode'getcode(*line) +;# Return 'jis', 'sjis', 'euc' or undef according to +;# Japanese character code in $line. Return 'binary' if +;# the data has non-character code. +;# +;# When evaluated in array context, it returns a list +;# contains two items. First value is the number of +;# characters which matched to the expected code, and +;# second value is the code name. It is useful if and +;# only if the number is not 0 and the code is undef; +;# that case means it couldn't tell 'euc' or 'sjis' +;# because the evaluation score was exactly same. This +;# interface is too tricky, though. +;# +;# Code detection between euc and sjis is very difficult +;# or sometimes impossible or even lead to wrong result +;# when it includes JIS X0201 KANA characters. So JIS +;# X0201 KANA is ignored for automatic code detection. +;# +;# &jcode'convert(*line, $ocode [, $icode [, $option]]) +;# Convert the contents of $line to the specified +;# Japanese code given in the second argument $ocode. +;# $ocode can be any of "jis", "sjis" or "euc", or use +;# "noconv" when you don't want the code conversion. +;# Input code is recognized automatically from the line +;# itself when $icode is not supplied (JIS X0201 KANA is +;# ignored in code detection. See the above descripton +;# of &getcode). $icode also can be specified, but +;# xxx2yyy routine is more efficient when both codes are +;# known. +;# +;# It returns the code of input string in scalar context, +;# and a list of pointer of convert subroutine and the +;# input code in array context. +;# +;# Japanese character code JIS X0201, X0208, X0212 and +;# ASCII code are supported. X0212 characters can not be +;# represented in SJIS and they will be replased by +;# "geta" character when converted to SJIS. +;# +;# See next paragraph for $option parameter. +;# +;# &jcode'xxx2yyy(*line [, $option]) +;# Convert the Japanese code from xxx to yyy. String xxx +;# and yyy are any convination from "jis", "euc" or +;# "sjis". They return *approximate* number of converted +;# bytes. So return value 0 means the line was not +;# converted at all. +;# +;# Optional parameter $option is used to specify optional +;# conversion method. String "z" is for JIS X0201 KANA +;# to X0208 KANA, and "h" is for reverse. +;# +;# $jcode'convf{'xxx', 'yyy'} +;# The value of this associative array is pointer to the +;# subroutine jcode'xxx2yyy(). +;# +;# &jcode'to($ocode, $line [, $icode [, $option]]) +;# &jcode'jis($line [, $icode [, $option]]) +;# &jcode'euc($line [, $icode [, $option]]) +;# &jcode'sjis($line [, $icode [, $option]]) +;# These functions are prepared for easy use of +;# call/return-by-value interface. You can use these +;# funcitons in s///e operation or any other place for +;# convenience. +;# +;# &jcode'jis_inout($in, $out) +;# Set or inquire JIS start and end sequences. Default +;# is "ESC-$-B" and "ESC-(-B". If you supplied only one +;# character, "ESC-$" or "ESC-(" is prepended for each +;# character respectively. Acutually "ESC-(-B" is not a +;# sequence to end JIS code but a sequence to start ASCII +;# code set. So `in' and `out' are somewhat misleading. +;# +;# &jcode'get_inout($string) +;# Get JIS start and end sequences from $string. +;# +;# &jcode'cache() +;# &jcode'nocache() +;# &jcode'flush() +;# Usually, converted character is cached in memory to +;# avoid same calculations have to be done many times. +;# To disable this caching, call &jcode'nocache(). It +;# can be revived by &jcode'cache() and cache is flushed +;# by calling &jcode'flush(). &cache() and &nocache() +;# functions return previous caching state. +;# +;# --------------------------------------------------------------- +;# +;# &jcode'h2z_xxx(*line) +;# JIS X0201 KANA (so-called Hankaku-KANA) to X0208 KANA +;# (Zenkaku-KANA) code conversion routine. String xxx is +;# any of "jis", "sjis" and "euc". From the difficulty +;# of recognizing code set from 1-byte KATAKANA string, +;# automatic code recognition is not supported. +;# +;# &jcode'z2h_xxx(*line) +;# X0208 to X0201 KANA code conversion routine. String +;# xxx is any of "jis", "sjis" and "euc". +;# +;# $jcode'z2hf{'xxx'} +;# $jcode'h2zf{'xxx'} +;# These are pointer to the corresponding function just +;# as $jcode'convf. +;# +;# --------------------------------------------------------------- +;# +;# &jcode'tr(*line, $from, $to [, $option]) +;# &jcode'tr emulates tr operator for 2 byte code. Only 'd' +;# is interpreted as an option. +;# +;# Range operator like `A-Z' for 2 byte code is partially +;# supported. Code must be JIS or EUC, and first byte +;# have to be same on first and last character. +;# +;# CAUTION: Handling range operator is a kind of trick +;# and it is not perfect. So if you need to transfer `-' +;# character, please be sure to put it at the beginning +;# or the end of $from and $to strings. +;# +;# &jcode'trans($line, $from, $to [, $option) +;# Same as &jcode'tr but accept string and return string +;# after translation. +;# +;# --------------------------------------------------------------- +;# +;# &jcode'init() +;# Initialize the variables used in this package. You +;# don't have to call this when using jocde.pl by `do' or +;# `require' interface. Call it first if you embedded +;# the jcode.pl at the end of your script. +;# +;###################################################################### +;# +;# PERL5 INTERFACE: +;# +;# Current jcode.pl is written in Perl 4 but it is possible to use +;# from Perl 5 using `references'. Fully perl5 capable version is +;# future issue. +;# +;# Since lexical variable is not a subject of typeglob, *string style +;# call doesn't work if the variable is declared as `my'. Same thing +;# happens to special variable $_ if the perl is compiled to use +;# thread capability. So using reference is generally recommented to +;# avoid the mysterious error. +;# +;# jcode::getcode(\$line) +;# jcode::convert(\$line, $ocode [, $icode [, $option]]) +;# jcode::xxx2yyy(\$line [, $option]) +;# &{$jcode::convf{'xxx', 'yyy'}}(\$line) +;# jcode::to($ocode, $line [, $icode [, $option]]) +;# jcode::jis($line [, $icode [, $option]]) +;# jcode::euc($line [, $icode [, $option]]) +;# jcode::sjis($line [, $icode [, $option]]) +;# jcode::jis_inout($in, $out) +;# jcode::get_inout($string) +;# jcode::cache() +;# jcode::nocache() +;# jcode::flush() +;# jcode::h2z_xxx(\$line) +;# jcode::z2h_xxx(\$line) +;# &{$jcode::z2hf{'xxx'}}(\$line) +;# &{$jcode::h2zf{'xxx'}}(\$line) +;# jcode::tr(\$line, $from, $to [, $option]) +;# jcode::trans($line, $from, $to [, $option) +;# jcode::init() +;# +;###################################################################### +;# +;# SAMPLES +;# +;# Convert any Kanji code to JIS and print each line with code name. +;# +;# while (defined($s = <>)) { +;# $code = &jcode'convert(*s, 'jis'); +;# print $code, "\t", $s; +;# } +;# +;# Convert all lines to JIS according to the first recognized line. +;# +;# while (defined($s = <>)) { +;# print, next unless $s =~ /[\033\200-\377]/; +;# (*f, $icode) = &jcode'convert(*s, 'jis'); +;# print; +;# defined(&f) || next; +;# while (<>) { &f(*s); print; } +;# last; +;# } +;# +;# The safest way of JIS conversion. +;# +;# while (defined($s = <>)) { +;# ($matched, $icode) = &jcode'getcode(*s); +;# if (@buf == 0 && $matched == 0) { +;# print $s; +;# next; +;# } +;# push(@buf, $s); +;# next unless $icode; +;# while (defined($s = shift(@buf))) { +;# &jcode'convert(*s, 'jis', $icode); +;# print $s; +;# } +;# while (defined($s = <>)) { +;# &jcode'convert(*s, 'jis', $icode); +;# print $s; +;# } +;# last; +;# } +;# print @buf if @buf; +;# +;###################################################################### + +;# +;# Call initialize function if it is not called yet. This may sound +;# strange but it makes easy to embed the jcode.pl at the end of +;# script. Call &jcode'init at the beginning of the script in that +;# case. +;# +&init unless defined $version; + +;# +;# Initialize variables. +;# +sub init { + $version = $rcsid =~ /,v ([\d.]+)/ ? $1 : 'unkown'; + + $re_bin = '[\000-\006\177\377]'; + + $re_jis0208_1978 = '\e\$\@'; + $re_jis0208_1983 = '\e\$B'; + $re_jis0208_1990 = '\e&\@\e\$B'; + $re_jis0208 = "$re_jis0208_1978|$re_jis0208_1983|$re_jis0208_1990"; + $re_jis0212 = '\e\$\(D'; + $re_jp = "$re_jis0208|$re_jis0212"; + $re_asc = '\e\([BJ]'; + $re_kana = '\e\(I'; + + $esc_0208 = "\e\$B"; + $esc_0212 = "\e\$(D"; + $esc_asc = "\e(B"; + $esc_kana = "\e(I"; + + $re_sjis_c = '[\201-\237\340-\374][\100-\176\200-\374]'; + $re_sjis_kana = '[\241-\337]'; + + $re_euc_c = '[\241-\376][\241-\376]'; + $re_euc_kana = '\216[\241-\337]'; + $re_euc_0212 = '\217[\241-\376][\241-\376]'; + + # Use `geta' for undefined character code + $undef_sjis = "\x81\xac"; + + $cache = 1; + + # X0201 -> X0208 KANA conversion table. Looks weird? Not that + # much. This is simply JIS text without escape sequences. + ($h2z_high = $h2z = <<'__TABLE_END__') =~ tr/\041-\176/\241-\376/; +! !# $ !" % !& " !V # !W +^ !+ _ !, 0 !< +' %! ( %# ) %% * %' + %) +, %c - %e . %g / %C +1 %" 2 %$ 3 %& 4 %( 5 %* +6 %+ 7 %- 8 %/ 9 %1 : %3 +6^ %, 7^ %. 8^ %0 9^ %2 :^ %4 +; %5 < %7 = %9 > %; ? %= +;^ %6 <^ %8 =^ %: >^ %< ?^ %> +@ %? A %A B %D C %F D %H +@^ %@ A^ %B B^ %E C^ %G D^ %I +E %J F %K G %L H %M I %N +J %O K %R L %U M %X N %[ +J^ %P K^ %S L^ %V M^ %Y N^ %\ +J_ %Q K_ %T L_ %W M_ %Z N_ %] +O %^ P %_ Q %` R %a S %b +T %d U %f V %h +W %i X %j Y %k Z %l [ %m +\ %o ] %s & %r 3^ %t +__TABLE_END__ + %h2z = split(/\s+/, $h2z . $h2z_high); + %z2h = reverse %h2z; + + $convf{'jis' , 'jis' } = *jis2jis; + $convf{'jis' , 'sjis'} = *jis2sjis; + $convf{'jis' , 'euc' } = *jis2euc; + $convf{'euc' , 'jis' } = *euc2jis; + $convf{'euc' , 'sjis'} = *euc2sjis; + $convf{'euc' , 'euc' } = *euc2euc; + $convf{'sjis' , 'jis' } = *sjis2jis; + $convf{'sjis' , 'sjis'} = *sjis2sjis; + $convf{'sjis' , 'euc' } = *sjis2euc; + $h2zf{'jis' } = *h2z_jis; + $z2hf{'jis' } = *z2h_jis; + $h2zf{'euc' } = *h2z_euc; + $z2hf{'euc' } = *z2h_euc; + $h2zf{'sjis'} = *h2z_sjis; + $z2hf{'sjis'} = *z2h_sjis; +} + +;# +;# Set escape sequences which should be put before and after Japanese +;# (JIS X0208) string. +;# +sub jis_inout { + $esc_0208 = shift || $esc_0208; + $esc_0208 = "\e\$$esc_0208" if length($esc_0208) == 1; + $esc_asc = shift || $esc_asc; + $esc_asc = "\e\($esc_asc" if length($esc_asc) == 1; + ($esc_0208, $esc_asc); +} + +;# +;# Get JIS in and out sequences from the string. +;# +sub get_inout { + local($esc_0208, $esc_asc); + $_[$[] =~ /($re_jis0208)/o && ($esc_0208 = $1); + $_[$[] =~ /($re_asc)/o && ($esc_asc = $1); + ($esc_0208, $esc_asc); +} + +;# +;# Recognize character code. +;# +sub getcode { + local(*s) = @_; + local($matched, $code); + + if ($s !~ /[\e\200-\377]/) { # not Japanese + $matched = 0; + $code = undef; + } # 'jis' + elsif ($s =~ /$re_jp|$re_asc|$re_kana/o) { + $matched = 1; + $code = 'jis'; + } + elsif ($s =~ /$re_bin/o) { # 'binary' + $matched = 0; + $code = 'binary'; + } + else { # should be 'euc' or 'sjis' + local($sjis, $euc) = (0, 0); + + while ($s =~ /(($re_sjis_c)+)/go) { + $sjis += length($1); + } + while ($s =~ /(($re_euc_c|$re_euc_kana|$re_euc_0212)+)/go) { + $euc += length($1); + } + $matched = &max($sjis, $euc); + $code = ('euc', undef, 'sjis')[($sjis<=>$euc) + $[ + 1]; + } + wantarray ? ($matched, $code) : $code; +} +sub max { $_[ $[ + ($_[ $[ ] < $_[ $[ + 1 ]) ]; } + +;# +;# Convert any code to specified code. +;# +sub convert { + local(*s, $ocode, $icode, $opt) = @_; + return (undef, undef) unless $icode = $icode || &getcode(*s); + return (undef, $icode) if $icode eq 'binary'; + $ocode = 'jis' unless $ocode; + $ocode = $icode if $ocode eq 'noconv'; + local(*f) = $convf{$icode, $ocode}; + &f(*s, $opt); + wantarray ? (*f, $icode) : $icode; +} + +;# +;# Easy return-by-value interfaces. +;# +sub jis { &to('jis', @_); } +sub euc { &to('euc', @_); } +sub sjis { &to('sjis', @_); } +sub to { + local($ocode, $s, $icode, $opt) = @_; + &convert(*s, $ocode, $icode, $opt); + $s; +} +sub what { + local($s) = @_; + &getcode(*s); +} +sub trans { + local($s) = shift; + &tr(*s, @_); + $s; +} + +;# +;# SJIS to JIS +;# +sub sjis2jis { + local(*s, $opt, $n) = @_; + &sjis2sjis(*s, $opt) if $opt; + $s =~ s/(($re_sjis_c|$re_sjis_kana)+)/&_sjis2jis($1) . $esc_asc/geo; + $n; +} +sub _sjis2jis { + local($s) = shift; + $s =~ s/(($re_sjis_c)+|($re_sjis_kana)+)/&__sjis2jis($1)/geo; + $s; +} +sub __sjis2jis { + local($s) = shift; + if ($s =~ /^$re_sjis_kana/o) { + $n += $s =~ tr/\241-\337/\041-\137/; + $esc_kana . $s; + } else { + $n += $s =~ s/($re_sjis_c)/$s2e{$1}||&s2e($1)/geo; + $s =~ tr/\241-\376/\041-\176/; + $esc_0208 . $s; + } +} + +;# +;# EUC to JIS +;# +sub euc2jis { + local(*s, $opt, $n) = @_; + &euc2euc(*s, $opt) if $opt; + $s =~ s/(($re_euc_c|$re_euc_kana|$re_euc_0212)+)/ + &_euc2jis($1) . $esc_asc + /geo; + $n; +} +sub _euc2jis { + local($s) = shift; + $s =~ s/(($re_euc_c)+|($re_euc_kana)+|($re_euc_0212)+)/&__euc2jis($1)/geo; + $s; +} +sub __euc2jis { + local($s) = shift; + local($esc); + + if ($s =~ tr/\216//d) { + $esc = $esc_kana; + } elsif ($s =~ tr/\217//d) { + $esc = $esc_0212; + } else { + $esc = $esc_0208; + } + + $n += $s =~ tr/\241-\376/\041-\176/; + $esc . $s; +} + +;# +;# JIS to EUC +;# +sub jis2euc { + local(*s, $opt, $n) = @_; + $s =~ s/($re_jp|$re_asc|$re_kana)([^\e]*)/&_jis2euc($1,$2)/geo; + &euc2euc(*s, $opt) if $opt; + $n; +} +sub _jis2euc { + local($esc, $s) = @_; + if ($esc !~ /^$re_asc/o) { + $n += $s =~ tr/\041-\176/\241-\376/; + if ($esc =~ /^$re_kana/o) { + $s =~ s/([\241-\337])/\216$1/g; + } + elsif ($esc =~ /^$re_jis0212/o) { + $s =~ s/([\241-\376][\241-\376])/\217$1/g; + } + } + $s; +} + +;# +;# JIS to SJIS +;# +sub jis2sjis { + local(*s, $opt, $n) = @_; + &jis2jis(*s, $opt) if $opt; + $s =~ s/($re_jp|$re_asc|$re_kana)([^\e]*)/&_jis2sjis($1,$2)/geo; + $n; +} +sub _jis2sjis { + local($esc, $s) = @_; + if ($esc =~ /^$re_jis0212/o) { + $s =~ s/../$undef_sjis/g; + $n = length; + } + elsif ($esc !~ /^$re_asc/o) { + $n += $s =~ tr/\041-\176/\241-\376/; + if ($esc =~ /^$re_jp/o) { + $s =~ s/($re_euc_c)/$e2s{$1}||&e2s($1)/geo; + } + } + $s; +} + +;# +;# SJIS to EUC +;# +sub sjis2euc { + local(*s, $opt,$n) = @_; + $n = $s =~ s/($re_sjis_c|$re_sjis_kana)/$s2e{$1}||&s2e($1)/geo; + &euc2euc(*s, $opt) if $opt; + $n; +} +sub s2e { + local($c1, $c2, $code); + ($c1, $c2) = unpack('CC', $code = shift); + + if (0xa1 <= $c1 && $c1 <= 0xdf) { + $c2 = $c1; + $c1 = 0x8e; + } elsif (0x9f <= $c2) { + $c1 = $c1 * 2 - ($c1 >= 0xe0 ? 0xe0 : 0x60); + $c2 += 2; + } else { + $c1 = $c1 * 2 - ($c1 >= 0xe0 ? 0xe1 : 0x61); + $c2 += 0x60 + ($c2 < 0x7f); + } + if ($cache) { + $s2e{$code} = pack('CC', $c1, $c2); + } else { + pack('CC', $c1, $c2); + } +} + +;# +;# EUC to SJIS +;# +sub euc2sjis { + local(*s, $opt,$n) = @_; + &euc2euc(*s, $opt) if $opt; + $n = $s =~ s/($re_euc_c|$re_euc_kana|$re_euc_0212)/$e2s{$1}||&e2s($1)/geo; +} +sub e2s { + local($c1, $c2, $code); + ($c1, $c2) = unpack('CC', $code = shift); + + if ($c1 == 0x8e) { # SS2 + return substr($code, 1, 1); + } elsif ($c1 == 0x8f) { # SS3 + return $undef_sjis; + } elsif ($c1 % 2) { + $c1 = ($c1>>1) + ($c1 < 0xdf ? 0x31 : 0x71); + $c2 -= 0x60 + ($c2 < 0xe0); + } else { + $c1 = ($c1>>1) + ($c1 < 0xdf ? 0x30 : 0x70); + $c2 -= 2; + } + if ($cache) { + $e2s{$code} = pack('CC', $c1, $c2); + } else { + pack('CC', $c1, $c2); + } +} + +;# +;# JIS to JIS, SJIS to SJIS, EUC to EUC +;# +sub jis2jis { + local(*s, $opt) = @_; + $s =~ s/$re_jis0208/$esc_0208/go; + $s =~ s/$re_asc/$esc_asc/go; + &h2z_jis(*s) if $opt =~ /z/; + &z2h_jis(*s) if $opt =~ /h/; +} +sub sjis2sjis { + local(*s, $opt) = @_; + &h2z_sjis(*s) if $opt =~ /z/; + &z2h_sjis(*s) if $opt =~ /h/; +} +sub euc2euc { + local(*s, $opt) = @_; + &h2z_euc(*s) if $opt =~ /z/; + &z2h_euc(*s) if $opt =~ /h/; +} + +;# +;# Cache control functions +;# +sub cache { + ($cache, $cache = 1)[$[]; +} +sub nocache { + ($cache, $cache = 0)[$[]; +} +sub flushcache { + undef %e2s; + undef %s2e; +} + +;# +;# X0201 -> X0208 KANA conversion routine +;# +sub h2z_jis { + local(*s, $n) = @_; + if ($s =~ s/$re_kana([^\e]*)/$esc_0208 . &_h2z_jis($1)/geo) { + 1 while $s =~ s/(($re_jis0208)[^\e]*)($re_jis0208)/$1/o; + } + $n; +} +sub _h2z_jis { + local($s) = @_; + $n += $s =~ s/([\41-\137]([\136\137])?)/$h2z{$1}/g; + $s; +} + +sub h2z_euc { + local(*s) = @_; + $s =~ s/\216([\241-\337])(\216([\336\337]))?/$h2z{"$1$3"}/g; +} + +sub h2z_sjis { + local(*s, $n) = @_; + $s =~ s/(($re_sjis_c)+)|(([\241-\337])([\336\337])?)/ + $1 || ($n++, $e2s{$h2z{$3}} || &e2s($h2z{$3})) + /geo; + $n; +} + +;# +;# X0208 -> X0201 KANA conversion routine +;# +sub z2h_jis { + local(*s, $n) = @_; + $s =~ s/($re_jis0208)([^\e]+)/&_z2h_jis($2)/geo; + $n; +} +sub _z2h_jis { + local($s) = @_; + $s =~ s/((\%[!-~]|![\#\"&VW+,<])+|([^!%][!-~]|![^\#\"&VW+,<])+)/ + &__z2h_jis($1) + /ge; + $s; +} +sub __z2h_jis { + local($s) = @_; + return $esc_0208 . $s unless /^%/ || $s =~ /^![\#\"&VW+,<]/; + $n += length($s) / 2; + $s =~ s/(..)/$z2h{$1}/g; + $esc_kana . $s; +} + +sub z2h_euc { + local(*s, $n) = @_; + &init_z2h_euc unless defined %z2h_euc; + $s =~ s/($re_euc_c|$re_euc_kana)/ + $z2h_euc{$1} ? ($n++, $z2h_euc{$1}) : $1 + /geo; + $n; +} + +sub z2h_sjis { + local(*s, $n) = @_; + &init_z2h_sjis unless defined %z2h_sjis; + $s =~ s/($re_sjis_c)/$z2h_sjis{$1} ? ($n++, $z2h_sjis{$1}) : $1/geo; + $n; +} + +;# +;# Initializing JIS X0208 to X0201 KANA table for EUC and SJIS. This +;# can be done in &init but it's not worth doing. Similarly, +;# precalculated table is not worth to occupy the file space and +;# reduce the readability. The author personnaly discourages to use +;# X0201 Kana character in the any situation. +;# +sub init_z2h_euc { + local($k, $s); + while (($k, $s) = each %z2h) { + $s =~ s/([\241-\337])/\216$1/g && ($z2h_euc{$k} = $s); + } +} +sub init_z2h_sjis { + local($s, $v); + while (($s, $v) = each %z2h) { + $s =~ /[\200-\377]/ && ($z2h_sjis{&e2s($s)} = $v); + } +} + +;# +;# TR function for 2-byte code +;# +sub tr { + # $prev_from, $prev_to, %table are persistent variables + local(*s, $from, $to, $opt) = @_; + local(@from, @to); + local($jis, $n) = (0, 0); + + $jis++, &jis2euc(*s) if $s =~ /$re_jp|$re_asc|$re_kana/o; + $jis++ if $to =~ /$re_jp|$re_asc|$re_kana/o; + + if (!defined($prev_from) || $from ne $prev_from || $to ne $prev_to) { + ($prev_from, $prev_to) = ($from, $to); + undef %table; + &_maketable; + } + + $s =~ s/([\200-\377][\000-\377]|[\000-\377])/ + defined($table{$1}) && ++$n ? $table{$1} : $1 + /ge; + + &euc2jis(*s) if $jis; + + $n; +} + +sub _maketable { + local($ascii) = '(\\\\[\\-\\\\]|[\0-\133\135-\177])'; + + &jis2euc(*to) if $to =~ /$re_jp|$re_asc|$re_kana/o; + &jis2euc(*from) if $from =~ /$re_jp|$re_asc|$re_kana/o; + + grep(s/(([\200-\377])[\200-\377]-\2[\200-\377])/&_expnd2($1)/ge, + $from, $to); + grep(s/($ascii-$ascii)/&_expnd1($1)/geo, + $from, $to); + + @to = $to =~ /[\200-\377][\000-\377]|[\000-\377]/g; + @from = $from =~ /[\200-\377][\000-\377]|[\000-\377]/g; + push(@to, ($opt =~ /d/ ? '' : $to[$#to]) x (@from - @to)) if @to < @from; + @table{@from} = @to; +} + +sub _expnd1 { + local($s) = @_; + $s =~ s/\\(.)/$1/g; + local($c1, $c2) = unpack('CxC', $s); + if ($c1 <= $c2) { + for ($s = ''; $c1 <= $c2; $c1++) { + $s .= pack('C', $c1); + } + } + $s; +} + +sub _expnd2 { + local($s) = @_; + local($c1, $c2, $c3, $c4) = unpack('CCxCC', $s); + if ($c1 == $c3 && $c2 <= $c4) { + for ($s = ''; $c2 <= $c4; $c2++) { + $s .= pack('CC', $c1, $c2); + } + } + $s; +} + +1; diff --git a/lib/mimew.pl b/lib/mimew.pl index 6c79451..ee4b40d 100644 --- a/lib/mimew.pl +++ b/lib/mimew.pl @@ -1,322 +1,322 @@ -package MIME; -# Copyright (C) 1993-94,1997 Noboru Ikuta -# -# mimew.pl: MIME encoder library Ver.2.02 (1997/12/30) - -$main'mimew_version = "2.02"; - -# $B%$%s%9%H!<%k(B : @INC $B$N%G%#%l%/%H%j!JDL>o$O(B /usr/local/lib/perl$B!K$K%3%T!<(B -# $B$7$F2<$5$$!#(B -# -# $B;HMQNc(B1 : require 'mimew.pl'; -# $from = "From: $B@8ED(B $B>:(B "; -# print &mimeencode($from); -# -# $B;HMQNc(B2 : # UNIX$B$G(BBase64$B%(%s%3!<%I$9$k>l9g(B -# require 'mimew.pl'; -# undef $/; -# $body = <>; -# print &bodyencode($body); -# print &benflush; -# -# &bodyencode($data,$coding): -# $B%G!<%?$r(BBase64$B7A<0$^$?$O(BQuoted-Printable$B7A<0$G%(%s%3!<%I$9$k!#(B -# $BBh(B2$B%Q%i%a!<%?$K(B"qp"$B$^$?$O(B"b64"$B$r;XDj$9$k$3$H$K$h$j%3!<%G%#%s%07A<0(B -# $B$r;X<($9$k$3$H$,$G$-$k!#Bh(B2$B%Q%i%a!<%?$r>JN,$9$k$H(BBase64$B7A<0$G%(%s(B -# $B%3!<%I$9$k!#(B -# Base64$B7A<0$N%(%s%3!<%I$N>l9g$O!"(B$foldcol*3/4 $B%P%$%HC10L$GJQ49$9$k(B -# $B$N$G!"EO$5$l$?%G!<%?$N$&$AH>C<$JItJ,$O%P%C%U%!$KJ]B8$5$ll9g$O!"9TC10L$GJQ49$9$k$?$a!"(B -# $B%G!<%?$N:G8e$K2~9TJ8;z$,L5$$>l9g!":G8e$N2~9TJ8;z$N8e$m$N%G!<%?$O(B -# $B%P%C%U%!$KJ]B8$5$l!"$l(BBase64 -# $B7A<0$^$?$O(BQuoted-Printable$B7A<0$N%(%s%3!<%I$r;XDj$9$k$3$H$,$G$-$k!#(B -# $BBh(B1$B%Q%i%a!<%?$K2?$b;XDj$7$J$1$l$P(BBase64$B7A<0$G%(%s%3!<%I$5$l$k!#(B -# Base64$B$N%(%s%3!<%I$N>l9g!"(B&bodyencode$B$,=hM}$7;D$7$?%G!<%?$r=hM}$7(B -# pad$BJ8;z$r=PNO$9$k!#(BQuoted-Printable$B$N>l9g!"9TC10L$G$J$/%V%m%C%/C1(B -# $B0L$G(B&bodyencode$B$r8F$V>l9g!"(B&bodyencode$B$,=hM}$7;D$7$?%G!<%?$,$b$7(B -# $B%P%C%U%!$K;D$C$F$$$l$P$=$l$r=hM}$9$k!#(B -# $B0l$D$N%G!<%?$r(B(1$B2s$^$?$O2?2s$+$KJ,$1$F(B)&bodyencode$B$7$?8e$KI,$:(B1$B2s(B -# $B8F$VI,MW$,$"$k!#(B -# -# &mimeencode($text): -# $BBh(B1$B%Q%i%a!<%?$,F|K\8lJ8;zNs$r4^$s$G$$$l$P!"$=$NItJ,$r(BISO-2022-JP$B$K(B -# $BJQ49$7$?$"$H!"(BMIME encoded-word(RFC2047$B;2>H(B)$B$KJQ49$9$k!#I,MW$K1~$8(B -# $B$F(Bencoded-word$B$NJ,3d$H(Bencoded-word$B$NA08e$G$N9TJ,3d$r9T$&!#(B -# -# $BJ8;z%3!<%I$N<+F0H=Dj$O!"F10l9T$K(BShiftJIS$B$H(BEUC$B$,:.:_$7$F$$$k>l9g$r(B -# $B=|$$$F4A;z%3!<%I$N:.:_$K$bBP1~$7$F$$$k!#(BShiftJIS$B$+(BEUC$B$+$I$&$7$F$b(B -# $BH=CG$G$-$J$$$H$-$O(B$often_use_kanji$B$K@_Dj$5$l$F$$$k%3!<%I$HH=Dj$9$k!#(B -# ISO-2022-JP$B$N%(%9%1!<%W%7!<%1%s%9$O(B$jis_in$B$H(B$jis_out$B$K@_Dj$9$k$3$H(B -# $B$K$h$jJQ992DG=$G$"$k!#(B - -$often_use_kanji = 'EUC'; # or 'SJIS' - -$jis_in = "\x1b\$B"; # ESC-$-B ( or ESC-$-@ ) -$jis_out = "\x1b\(B"; # ESC-(-B ( or ESC-(-J ) - -# $BG[I[>r7o(B : $BCx:n8"$OJ|4~$7$^$;$s$,!"G[I[!&2~JQ$O<+M3$H$7$^$9!#2~JQ$7$F(B -# $BG[I[$9$k>l9g$O!"%*%j%8%J%k$H0[$J$k$3$H$rL@5-$7!"%*%j%8%J%k(B -# $B$N%P!<%8%g%s%J%s%P!<$K2~JQHG%P!<%8%g%s%J%s%P!<$rIU2C$7$?7A(B -# $BNc$($P(B Ver.2.02-XXXXX $B$N$h$&$J%P!<%8%g%s%J%s%P!<$rIU$1$F2<(B -# $B$5$$!#$J$*!"(BCopyright$BI=<($OJQ99$7$J$$$G$/$@$5$$!#(B -# -# $BCm0U(B : &mimeencode$B$r(Bjperl1.X($B$N(B2$B%P%$%HJ8;zBP1~%b!<%I(B)$B$G;HMQ$9$k$H!"(BSJIS -# $B$H(BEUC$B$r$&$^$/(B7bit JIS(ISO-2022-JP)$B$KJQ49$G$-$^$;$s!#(B -# $BF~NO$K4^$^$l$kJ8;z$,(B7bit JIS(ISO-2022-JP)$B$H(BASCII$B$N$_$G$"$k$3$H(B -# $B$,J]>Z$5$l$F$$$k>l9g$r=|$-!"I,$:(Boriginal$B$N1Q8lHG$N(Bperl$B!J$^$?$O(B -# jperl1.4$B0J>e$r(B -Llatin $B%*%W%7%g%sIU$-!K$GF0$+$7$F$/$@$5$$!#(B -# $B$J$*!"(BPerl5$BBP1~$N(Bjperl$B$O;n$7$?$3$H$,$J$$$N$G$I$N$h$&$JF0:n$K$J$k(B -# $B$+$o$+$j$^$;$s!#(B -# -# $B;2>H(B : RFC1468, RFC2045, RFC2047 - -## MIME base64 $B%"%k%U%!%Y%C%H%F!<%V%k!J(BRFC2045$B$h$j!K(B -%mime = ( -"000000", "A", "000001", "B", "000010", "C", "000011", "D", -"000100", "E", "000101", "F", "000110", "G", "000111", "H", -"001000", "I", "001001", "J", "001010", "K", "001011", "L", -"001100", "M", "001101", "N", "001110", "O", "001111", "P", -"010000", "Q", "010001", "R", "010010", "S", "010011", "T", -"010100", "U", "010101", "V", "010110", "W", "010111", "X", -"011000", "Y", "011001", "Z", "011010", "a", "011011", "b", -"011100", "c", "011101", "d", "011110", "e", "011111", "f", -"100000", "g", "100001", "h", "100010", "i", "100011", "j", -"100100", "k", "100101", "l", "100110", "m", "100111", "n", -"101000", "o", "101001", "p", "101010", "q", "101011", "r", -"101100", "s", "101101", "t", "101110", "u", "101111", "v", -"110000", "w", "110001", "x", "110010", "y", "110011", "z", -"110100", "0", "110101", "1", "110110", "2", "110111", "3", -"111000", "4", "111001", "5", "111010", "6", "111011", "7", -"111100", "8", "111101", "9", "111110", "+", "111111", "/", -); - -## JIS$B%3!<%I(B(byte$B?t(B)$B"*(Bencoded-word $B$NJ8;z?tBP1~(B -%mimelen = ( - 8,30, 10,34, 12,34, 14,38, 16,42, -18,42, 20,46, 22,50, 24,50, 26,54, -28,58, 30,58, 32,62, 34,66, 36,66, -38,70, 40,74, 42,74, -); - -## $B%X%C%@%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B -$limit=74; ## $B!vCm0U!v(B $limit$B$r(B75$B$h$jBg$-$$?t;z$K@_Dj$7$F$O$$$1$J$$!#(B - -## $B%\%G%#(Bbase64$B%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B -$foldcol=72; ## $B!vCm0U!v(B $foldcol$B$O(B76$B0J2<$N(B4$B$NG\?t$K@_Dj$9$k$3$H!#(B - -## $B%\%G%#(BQuoted-Printable$B%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B -$qfoldcol=75; ## $B!vCm0U!v(B $foldcol$B$O(B76$B0J2<$K@_Dj$9$k$3$H!#(B - -## null bit$B$NA^F~$H(B pad$BJ8;z$NA^F~$N$?$a$N%F!<%V%k(B -@zero = ( "", "00000", "0000", "000", "00", "0" ); -@pad = ( "", "===", "==", "=" ); - -## ASCII, 7bit JIS, Shift-JIS $B5Z$S(B EUC $B$N3F!9$K%^%C%A$9$k%Q%?!<%s(B -$match_ascii = '\x1b\([BHJ]([\t\x20-\x7e]*)'; -$match_jis = '\x1b\$[@B](([\x21-\x7e]{2})*)'; -$match_sjis = '([\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc])+'; -$match_euc = '([\xa1-\xfe]{2})+'; - -## MIME Part 2(charset=`ISO-2022-JP',encoding=`B') $B$N(B head $B$H(B tail -$mime_head = '=?ISO-2022-JP?B?'; -$mime_tail = '?='; - -## &bodyencode $B$,;H$&=hM};D$7%G!<%?MQ%P%C%U%!(B -$benbuf = ""; - -## &bodyencode $B$N=hM}C10L!J%P%$%H!K(B -$bensize = int($foldcol/4)*3; - -## &mimeencode interface ## -sub main'mimeencode { - local($_) = @_; - s/$match_jis/$jis_in$1/go; - s/$match_ascii/$jis_out$1/go; - $kanji = &checkkanji; - s/$match_sjis/&s2j($&)/geo if ($kanji eq 'SJIS'); - s/$match_euc/&e2j($&)/geo if ($kanji eq 'EUC'); - s/(\x1b[\$\(][BHJ@])+/$1/g; - 1 while s/(\x1b\$[B@][\x21-\x7e]+)\x1b\$[B@]/$1/; - 1 while s/$match_jis/&mimeencode($&,$`,$')/eo; - s/$match_ascii/$1/go; - $_; -} - -## &bodyencode interface ## -sub main'bodyencode { - local($_,$coding) = @_; - if (!defined($coding) || $coding eq "" || $coding eq "b64"){ - $_ = $benbuf . $_; - local($cut) = int((length)/$bensize)*$bensize; - $benbuf = substr($_, $cut+$[); - $_ = substr($_, $[, $cut); - $_ = &base64encode($_); - s/.{$foldcol}/$&\n/g; - }elsif ($coding eq "qp"){ - # $benbuf $B$,6u$G$J$1$l$P%G!<%?$N:G=i$KDI2C$9$k(B - $_ = $benbuf . $_; - - # $B2~9TJ8;z$r@55,2=$9$k(B - s/\r\n/\n/g; - s/\r/\n/g; - - # $B%G!<%?$r9TC10L$KJ,3d$9$k(B($B:G8e$N2~9TJ8;z0J9_$r(B $benbuf $B$KJ]B8$9$k(B) - @line = split(/\n/,$_,-1); - $benbuf = pop(@line); - - local($result) = ""; - foreach (@line){ - $_ = &qpencode($_); - $result .= $_ . "\n"; - } - $_ = $result; - } - $_; -} - -## &benflush interface ## -sub main'benflush { - local($coding) = @_; - local($ret) = ""; - if ((!defined($coding) || $coding eq "" || $coding eq "b64") - && $benbuf ne ""){ - $ret = &base64encode($benbuf) . "\n"; - $benbuf = ""; - }elsif ($coding eq "qp" && $benbuf ne ""){ - $ret = &qpencode($benbuf) . "\n"; - $benbuf = ""; - } - $ret; -} - -## MIME $B%X%C%@%(%s%3!<%G%#%s%0(B -sub mimeencode { - local($_, $befor, $after) = @_; - local($back, $forw, $blen, $len, $flen, $str); - $befor = substr($befor, rindex($befor, "\n")+1); - $after = substr($after, 0, index($after, "\n")-$[); - $back = " " unless ($befor eq "" - || $befor =~ /[ \t\(]$/); - $forw = " " unless ($after =~ /^\x1b\([BHJ]$/ - || $after =~ /^\x1b\([BHJ][ \t\)]/); - $blen = length($befor); - $flen = length($forw)+length($&)-3 if ($after =~ /^$match_ascii/o); - $len = length($_); - return "" if ($len <= 3); - if ($len > 39 || $blen + $mimelen{$len+3} > $limit){ - if ($limit-$blen < 30){ - $len = 0; - }else{ - $len = int(($limit-$blen-26)/4)*2+3; - } - if ($len >= 5){ - $str = substr($_, 0, $len).$jis_out; - $str = &base64encode($str); - $str = $mime_head.$str.$mime_tail; - $back.$str."\n ".$jis_in.substr($_, $len); - }else{ - "\n ".$_; - } - }else{ - $_ .= $jis_out; - $_ = &base64encode($_); - $_ = $back.$mime_head.$_.$mime_tail; - if ($blen + (length) + $flen > $limit){ - $_."\n "; - }else{ - $_.$forw; - } - } -} - -## MIME base64 $B%(%s%3!<%G%#%s%0(B -sub base64encode { - local($_) = @_; - $_ = unpack("B".((length)<<3), $_); - $_ .= $zero[(length)%6]; - s/.{6}/$mime{$&}/go; - $_.$pad[(length)%4]; -} - -## Quoted-Printable $B%(%s%3!<%G%#%s%0(B -sub qpencode { - local($_) = @_; - - # `=' $BJ8;z$r(B16$B?JI=8=$KJQ49$9$k(B - s/=/=3D/g; - - # $B9TKv$N%?%V$H%9%Z!<%9$r(B16$B?JI=8=$KJQ49$9$k(B - s/\t$/=09/; - s/ $/=20/; - - # $B0u;z2DG=J8;z(B(`!'$B!A(B`~')$B0J30$NJ8;z$r(B16$B?JI=8=$KJQ49$9$k(B - s/([^!-~ \t])/&qphex($1)/ge; - - # 1$B9T$,(B$qfoldcol$BJ8;z0J2<$K$J$k$h$&$K%=%U%H2~9T$r$$$l$k(B - local($folded, $line) = ""; - while (length($_) > $qfoldcol){ - $line = substr($_, 0, $qfoldcol-1); - if ($line =~ /=$/){ - $line = substr($_, 0, $qfoldcol-2); - $_ = substr($_, $qfoldcol-2); - }elsif ($line =~ /=[0-9A-Fa-f]$/){ - $line = substr($_, 0, $qfoldcol-3); - $_ = substr($_, $qfoldcol-3); - }else{ - $_ = substr($_, $qfoldcol-1); - } - $folded .= $line . "=\n"; - } - $folded . $_; -} - -sub qphex { - local($_) = @_; - $_ = '=' . unpack("H2", $_); - tr/a-f/A-F/; - $_; -} - -## Shift-JIS $B$H(B EUC $B$N$I$A$i$N4A;z%3!<%I$,4^$^$l$k$+$r%A%'%C%/(B -sub checkkanji { - local($sjis,$euc); - $sjis += length($&) while(/$match_sjis/go); - $euc += length($&) while(/$match_euc/go); - return 'NONE' if ($sjis == 0 && $euc == 0); - return 'SJIS' if ($sjis > $euc); - return 'EUC' if ($sjis < $euc); - $often_use_kanji; -} - -## EUC $B$r(B 7bit JIS $B$KJQ49(B -sub e2j { - local($_) = @_; - tr/\xa1-\xfe/\x21-\x7e/; - $jis_in.$_.$jis_out; -} - -## Shift-JIS $B$r(B 7bit JIS $B$KJQ49(B -sub s2j { - local($string); - local(@ch) = split(//, $_[0]); - while(($j1,$j2)=unpack("CC",shift(@ch).shift(@ch))){ - if ($j2 > 0x9e){ - $j1 = (($j1>0x9f ? $j1-0xb1 : $j1-0x71)<<1)+2; - $j2 -= 0x7e; - } - else{ - $j1 = (($j1>0x9f ? $j1-0xb1 : $j1-0x71)<<1)+1; - $j2 -= ($j2>0x7e ? 0x20 : 0x1f); - } - $string .= pack("CC", $j1, $j2); - } - $jis_in.$string.$jis_out; -} -1; +package MIME; +# Copyright (C) 1993-94,1997 Noboru Ikuta +# +# mimew.pl: MIME encoder library Ver.2.02 (1997/12/30) + +$main'mimew_version = "2.02"; + +# $B%$%s%9%H!<%k(B : @INC $B$N%G%#%l%/%H%j!JDL>o$O(B /usr/local/lib/perl$B!K$K%3%T!<(B +# $B$7$F2<$5$$!#(B +# +# $B;HMQNc(B1 : require 'mimew.pl'; +# $from = "From: $B@8ED(B $B>:(B "; +# print &mimeencode($from); +# +# $B;HMQNc(B2 : # UNIX$B$G(BBase64$B%(%s%3!<%I$9$k>l9g(B +# require 'mimew.pl'; +# undef $/; +# $body = <>; +# print &bodyencode($body); +# print &benflush; +# +# &bodyencode($data,$coding): +# $B%G!<%?$r(BBase64$B7A<0$^$?$O(BQuoted-Printable$B7A<0$G%(%s%3!<%I$9$k!#(B +# $BBh(B2$B%Q%i%a!<%?$K(B"qp"$B$^$?$O(B"b64"$B$r;XDj$9$k$3$H$K$h$j%3!<%G%#%s%07A<0(B +# $B$r;X<($9$k$3$H$,$G$-$k!#Bh(B2$B%Q%i%a!<%?$r>JN,$9$k$H(BBase64$B7A<0$G%(%s(B +# $B%3!<%I$9$k!#(B +# Base64$B7A<0$N%(%s%3!<%I$N>l9g$O!"(B$foldcol*3/4 $B%P%$%HC10L$GJQ49$9$k(B +# $B$N$G!"EO$5$l$?%G!<%?$N$&$AH>C<$JItJ,$O%P%C%U%!$KJ]B8$5$ll9g$O!"9TC10L$GJQ49$9$k$?$a!"(B +# $B%G!<%?$N:G8e$K2~9TJ8;z$,L5$$>l9g!":G8e$N2~9TJ8;z$N8e$m$N%G!<%?$O(B +# $B%P%C%U%!$KJ]B8$5$l!"$l(BBase64 +# $B7A<0$^$?$O(BQuoted-Printable$B7A<0$N%(%s%3!<%I$r;XDj$9$k$3$H$,$G$-$k!#(B +# $BBh(B1$B%Q%i%a!<%?$K2?$b;XDj$7$J$1$l$P(BBase64$B7A<0$G%(%s%3!<%I$5$l$k!#(B +# Base64$B$N%(%s%3!<%I$N>l9g!"(B&bodyencode$B$,=hM}$7;D$7$?%G!<%?$r=hM}$7(B +# pad$BJ8;z$r=PNO$9$k!#(BQuoted-Printable$B$N>l9g!"9TC10L$G$J$/%V%m%C%/C1(B +# $B0L$G(B&bodyencode$B$r8F$V>l9g!"(B&bodyencode$B$,=hM}$7;D$7$?%G!<%?$,$b$7(B +# $B%P%C%U%!$K;D$C$F$$$l$P$=$l$r=hM}$9$k!#(B +# $B0l$D$N%G!<%?$r(B(1$B2s$^$?$O2?2s$+$KJ,$1$F(B)&bodyencode$B$7$?8e$KI,$:(B1$B2s(B +# $B8F$VI,MW$,$"$k!#(B +# +# &mimeencode($text): +# $BBh(B1$B%Q%i%a!<%?$,F|K\8lJ8;zNs$r4^$s$G$$$l$P!"$=$NItJ,$r(BISO-2022-JP$B$K(B +# $BJQ49$7$?$"$H!"(BMIME encoded-word(RFC2047$B;2>H(B)$B$KJQ49$9$k!#I,MW$K1~$8(B +# $B$F(Bencoded-word$B$NJ,3d$H(Bencoded-word$B$NA08e$G$N9TJ,3d$r9T$&!#(B +# +# $BJ8;z%3!<%I$N<+F0H=Dj$O!"F10l9T$K(BShiftJIS$B$H(BEUC$B$,:.:_$7$F$$$k>l9g$r(B +# $B=|$$$F4A;z%3!<%I$N:.:_$K$bBP1~$7$F$$$k!#(BShiftJIS$B$+(BEUC$B$+$I$&$7$F$b(B +# $BH=CG$G$-$J$$$H$-$O(B$often_use_kanji$B$K@_Dj$5$l$F$$$k%3!<%I$HH=Dj$9$k!#(B +# ISO-2022-JP$B$N%(%9%1!<%W%7!<%1%s%9$O(B$jis_in$B$H(B$jis_out$B$K@_Dj$9$k$3$H(B +# $B$K$h$jJQ992DG=$G$"$k!#(B + +$often_use_kanji = 'EUC'; # or 'SJIS' + +$jis_in = "\x1b\$B"; # ESC-$-B ( or ESC-$-@ ) +$jis_out = "\x1b\(B"; # ESC-(-B ( or ESC-(-J ) + +# $BG[I[>r7o(B : $BCx:n8"$OJ|4~$7$^$;$s$,!"G[I[!&2~JQ$O<+M3$H$7$^$9!#2~JQ$7$F(B +# $BG[I[$9$k>l9g$O!"%*%j%8%J%k$H0[$J$k$3$H$rL@5-$7!"%*%j%8%J%k(B +# $B$N%P!<%8%g%s%J%s%P!<$K2~JQHG%P!<%8%g%s%J%s%P!<$rIU2C$7$?7A(B +# $BNc$($P(B Ver.2.02-XXXXX $B$N$h$&$J%P!<%8%g%s%J%s%P!<$rIU$1$F2<(B +# $B$5$$!#$J$*!"(BCopyright$BI=<($OJQ99$7$J$$$G$/$@$5$$!#(B +# +# $BCm0U(B : &mimeencode$B$r(Bjperl1.X($B$N(B2$B%P%$%HJ8;zBP1~%b!<%I(B)$B$G;HMQ$9$k$H!"(BSJIS +# $B$H(BEUC$B$r$&$^$/(B7bit JIS(ISO-2022-JP)$B$KJQ49$G$-$^$;$s!#(B +# $BF~NO$K4^$^$l$kJ8;z$,(B7bit JIS(ISO-2022-JP)$B$H(BASCII$B$N$_$G$"$k$3$H(B +# $B$,J]>Z$5$l$F$$$k>l9g$r=|$-!"I,$:(Boriginal$B$N1Q8lHG$N(Bperl$B!J$^$?$O(B +# jperl1.4$B0J>e$r(B -Llatin $B%*%W%7%g%sIU$-!K$GF0$+$7$F$/$@$5$$!#(B +# $B$J$*!"(BPerl5$BBP1~$N(Bjperl$B$O;n$7$?$3$H$,$J$$$N$G$I$N$h$&$JF0:n$K$J$k(B +# $B$+$o$+$j$^$;$s!#(B +# +# $B;2>H(B : RFC1468, RFC2045, RFC2047 + +## MIME base64 $B%"%k%U%!%Y%C%H%F!<%V%k!J(BRFC2045$B$h$j!K(B +%mime = ( +"000000", "A", "000001", "B", "000010", "C", "000011", "D", +"000100", "E", "000101", "F", "000110", "G", "000111", "H", +"001000", "I", "001001", "J", "001010", "K", "001011", "L", +"001100", "M", "001101", "N", "001110", "O", "001111", "P", +"010000", "Q", "010001", "R", "010010", "S", "010011", "T", +"010100", "U", "010101", "V", "010110", "W", "010111", "X", +"011000", "Y", "011001", "Z", "011010", "a", "011011", "b", +"011100", "c", "011101", "d", "011110", "e", "011111", "f", +"100000", "g", "100001", "h", "100010", "i", "100011", "j", +"100100", "k", "100101", "l", "100110", "m", "100111", "n", +"101000", "o", "101001", "p", "101010", "q", "101011", "r", +"101100", "s", "101101", "t", "101110", "u", "101111", "v", +"110000", "w", "110001", "x", "110010", "y", "110011", "z", +"110100", "0", "110101", "1", "110110", "2", "110111", "3", +"111000", "4", "111001", "5", "111010", "6", "111011", "7", +"111100", "8", "111101", "9", "111110", "+", "111111", "/", +); + +## JIS$B%3!<%I(B(byte$B?t(B)$B"*(Bencoded-word $B$NJ8;z?tBP1~(B +%mimelen = ( + 8,30, 10,34, 12,34, 14,38, 16,42, +18,42, 20,46, 22,50, 24,50, 26,54, +28,58, 30,58, 32,62, 34,66, 36,66, +38,70, 40,74, 42,74, +); + +## $B%X%C%@%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B +$limit=74; ## $B!vCm0U!v(B $limit$B$r(B75$B$h$jBg$-$$?t;z$K@_Dj$7$F$O$$$1$J$$!#(B + +## $B%\%G%#(Bbase64$B%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B +$foldcol=72; ## $B!vCm0U!v(B $foldcol$B$O(B76$B0J2<$N(B4$B$NG\?t$K@_Dj$9$k$3$H!#(B + +## $B%\%G%#(BQuoted-Printable$B%(%s%3!<%I;~$N9T$ND9$5$N@)8B(B +$qfoldcol=75; ## $B!vCm0U!v(B $foldcol$B$O(B76$B0J2<$K@_Dj$9$k$3$H!#(B + +## null bit$B$NA^F~$H(B pad$BJ8;z$NA^F~$N$?$a$N%F!<%V%k(B +@zero = ( "", "00000", "0000", "000", "00", "0" ); +@pad = ( "", "===", "==", "=" ); + +## ASCII, 7bit JIS, Shift-JIS $B5Z$S(B EUC $B$N3F!9$K%^%C%A$9$k%Q%?!<%s(B +$match_ascii = '\x1b\([BHJ]([\t\x20-\x7e]*)'; +$match_jis = '\x1b\$[@B](([\x21-\x7e]{2})*)'; +$match_sjis = '([\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc])+'; +$match_euc = '([\xa1-\xfe]{2})+'; + +## MIME Part 2(charset=`ISO-2022-JP',encoding=`B') $B$N(B head $B$H(B tail +$mime_head = '=?ISO-2022-JP?B?'; +$mime_tail = '?='; + +## &bodyencode $B$,;H$&=hM};D$7%G!<%?MQ%P%C%U%!(B +$benbuf = ""; + +## &bodyencode $B$N=hM}C10L!J%P%$%H!K(B +$bensize = int($foldcol/4)*3; + +## &mimeencode interface ## +sub main'mimeencode { + local($_) = @_; + s/$match_jis/$jis_in$1/go; + s/$match_ascii/$jis_out$1/go; + $kanji = &checkkanji; + s/$match_sjis/&s2j($&)/geo if ($kanji eq 'SJIS'); + s/$match_euc/&e2j($&)/geo if ($kanji eq 'EUC'); + s/(\x1b[\$\(][BHJ@])+/$1/g; + 1 while s/(\x1b\$[B@][\x21-\x7e]+)\x1b\$[B@]/$1/; + 1 while s/$match_jis/&mimeencode($&,$`,$')/eo; + s/$match_ascii/$1/go; + $_; +} + +## &bodyencode interface ## +sub main'bodyencode { + local($_,$coding) = @_; + if (!defined($coding) || $coding eq "" || $coding eq "b64"){ + $_ = $benbuf . $_; + local($cut) = int((length)/$bensize)*$bensize; + $benbuf = substr($_, $cut+$[); + $_ = substr($_, $[, $cut); + $_ = &base64encode($_); + s/.{$foldcol}/$&\n/g; + }elsif ($coding eq "qp"){ + # $benbuf $B$,6u$G$J$1$l$P%G!<%?$N:G=i$KDI2C$9$k(B + $_ = $benbuf . $_; + + # $B2~9TJ8;z$r@55,2=$9$k(B + s/\r\n/\n/g; + s/\r/\n/g; + + # $B%G!<%?$r9TC10L$KJ,3d$9$k(B($B:G8e$N2~9TJ8;z0J9_$r(B $benbuf $B$KJ]B8$9$k(B) + @line = split(/\n/,$_,-1); + $benbuf = pop(@line); + + local($result) = ""; + foreach (@line){ + $_ = &qpencode($_); + $result .= $_ . "\n"; + } + $_ = $result; + } + $_; +} + +## &benflush interface ## +sub main'benflush { + local($coding) = @_; + local($ret) = ""; + if ((!defined($coding) || $coding eq "" || $coding eq "b64") + && $benbuf ne ""){ + $ret = &base64encode($benbuf) . "\n"; + $benbuf = ""; + }elsif ($coding eq "qp" && $benbuf ne ""){ + $ret = &qpencode($benbuf) . "\n"; + $benbuf = ""; + } + $ret; +} + +## MIME $B%X%C%@%(%s%3!<%G%#%s%0(B +sub mimeencode { + local($_, $befor, $after) = @_; + local($back, $forw, $blen, $len, $flen, $str); + $befor = substr($befor, rindex($befor, "\n")+1); + $after = substr($after, 0, index($after, "\n")-$[); + $back = " " unless ($befor eq "" + || $befor =~ /[ \t\(]$/); + $forw = " " unless ($after =~ /^\x1b\([BHJ]$/ + || $after =~ /^\x1b\([BHJ][ \t\)]/); + $blen = length($befor); + $flen = length($forw)+length($&)-3 if ($after =~ /^$match_ascii/o); + $len = length($_); + return "" if ($len <= 3); + if ($len > 39 || $blen + $mimelen{$len+3} > $limit){ + if ($limit-$blen < 30){ + $len = 0; + }else{ + $len = int(($limit-$blen-26)/4)*2+3; + } + if ($len >= 5){ + $str = substr($_, 0, $len).$jis_out; + $str = &base64encode($str); + $str = $mime_head.$str.$mime_tail; + $back.$str."\n ".$jis_in.substr($_, $len); + }else{ + "\n ".$_; + } + }else{ + $_ .= $jis_out; + $_ = &base64encode($_); + $_ = $back.$mime_head.$_.$mime_tail; + if ($blen + (length) + $flen > $limit){ + $_."\n "; + }else{ + $_.$forw; + } + } +} + +## MIME base64 $B%(%s%3!<%G%#%s%0(B +sub base64encode { + local($_) = @_; + $_ = unpack("B".((length)<<3), $_); + $_ .= $zero[(length)%6]; + s/.{6}/$mime{$&}/go; + $_.$pad[(length)%4]; +} + +## Quoted-Printable $B%(%s%3!<%G%#%s%0(B +sub qpencode { + local($_) = @_; + + # `=' $BJ8;z$r(B16$B?JI=8=$KJQ49$9$k(B + s/=/=3D/g; + + # $B9TKv$N%?%V$H%9%Z!<%9$r(B16$B?JI=8=$KJQ49$9$k(B + s/\t$/=09/; + s/ $/=20/; + + # $B0u;z2DG=J8;z(B(`!'$B!A(B`~')$B0J30$NJ8;z$r(B16$B?JI=8=$KJQ49$9$k(B + s/([^!-~ \t])/&qphex($1)/ge; + + # 1$B9T$,(B$qfoldcol$BJ8;z0J2<$K$J$k$h$&$K%=%U%H2~9T$r$$$l$k(B + local($folded, $line) = ""; + while (length($_) > $qfoldcol){ + $line = substr($_, 0, $qfoldcol-1); + if ($line =~ /=$/){ + $line = substr($_, 0, $qfoldcol-2); + $_ = substr($_, $qfoldcol-2); + }elsif ($line =~ /=[0-9A-Fa-f]$/){ + $line = substr($_, 0, $qfoldcol-3); + $_ = substr($_, $qfoldcol-3); + }else{ + $_ = substr($_, $qfoldcol-1); + } + $folded .= $line . "=\n"; + } + $folded . $_; +} + +sub qphex { + local($_) = @_; + $_ = '=' . unpack("H2", $_); + tr/a-f/A-F/; + $_; +} + +## Shift-JIS $B$H(B EUC $B$N$I$A$i$N4A;z%3!<%I$,4^$^$l$k$+$r%A%'%C%/(B +sub checkkanji { + local($sjis,$euc); + $sjis += length($&) while(/$match_sjis/go); + $euc += length($&) while(/$match_euc/go); + return 'NONE' if ($sjis == 0 && $euc == 0); + return 'SJIS' if ($sjis > $euc); + return 'EUC' if ($sjis < $euc); + $often_use_kanji; +} + +## EUC $B$r(B 7bit JIS $B$KJQ49(B +sub e2j { + local($_) = @_; + tr/\xa1-\xfe/\x21-\x7e/; + $jis_in.$_.$jis_out; +} + +## Shift-JIS $B$r(B 7bit JIS $B$KJQ49(B +sub s2j { + local($string); + local(@ch) = split(//, $_[0]); + while(($j1,$j2)=unpack("CC",shift(@ch).shift(@ch))){ + if ($j2 > 0x9e){ + $j1 = (($j1>0x9f ? $j1-0xb1 : $j1-0x71)<<1)+2; + $j2 -= 0x7e; + } + else{ + $j1 = (($j1>0x9f ? $j1-0xb1 : $j1-0x71)<<1)+1; + $j2 -= ($j2>0x7e ? 0x20 : 0x1f); + } + $string .= pack("CC", $j1, $j2); + } + $jis_in.$string.$jis_out; +} +1; diff --git a/lib/setup.pl b/lib/setup.pl index 3f312fd..e9a93b9 100644 --- a/lib/setup.pl +++ b/lib/setup.pl @@ -1,33 +1,33 @@ -################################################################################ -# -# ÀßÄê¥Õ¥¡¥¤¥ë -# -################################################################################ -#=============================================================================== -# ½é´üÀßÄê -#=============================================================================== -$DATA_DIR = './data'; -$BACKUP_DIR = './backup'; -$ATTACH_DIR = './attach'; -$THEME_URL = './theme/default/default.css'; -$ADMIN_MAIL = ''; -$SEND_MAIL = ''; -$WIKI_NAME = 0; -$MAIN_SCRIPT = 'wiki.cgi'; -$EDIT_SCRIPT = 'edit.cgi'; -$CATEGORY_SCRIPT = 'category.cgi'; -$DOWNLOAD_SCRIPT = 'download.cgi'; -$SITE_TITLE = 'FSWikiLite'; - -#=============================================================================== -# ¥×¥í¥À¥¯¥È¾ðÊó -#=============================================================================== -$VERSION = '0.0.12'; -$SITE_URL = 'http://fswiki.poi.jp/'; - -#=============================================================================== -# ¥×¥é¥°¥¤¥ó¤ÎÀßÄê -#=============================================================================== -require "./plugin/core.pl"; - -1; +################################################################################ +# +# ÀßÄê¥Õ¥¡¥¤¥ë +# +################################################################################ +#=============================================================================== +# ½é´üÀßÄê +#=============================================================================== +$DATA_DIR = './data'; +$BACKUP_DIR = './backup'; +$ATTACH_DIR = './attach'; +$THEME_URL = './theme/default/default.css'; +$ADMIN_MAIL = ''; +$SEND_MAIL = ''; +$WIKI_NAME = 0; +$MAIN_SCRIPT = 'wiki.cgi'; +$EDIT_SCRIPT = 'edit.cgi'; +$CATEGORY_SCRIPT = 'category.cgi'; +$DOWNLOAD_SCRIPT = 'download.cgi'; +$SITE_TITLE = 'FSWikiLite'; + +#=============================================================================== +# ¥×¥í¥À¥¯¥È¾ðÊó +#=============================================================================== +$VERSION = '0.0.12'; +$SITE_URL = 'http://fswiki.osdn.jp/cgi-bin/wiki.cgi'; + +#=============================================================================== +# ¥×¥é¥°¥¤¥ó¤ÎÀßÄê +#=============================================================================== +require "./plugin/core.pl"; + +1; diff --git a/plugin/core.pl b/plugin/core.pl index e146012..5206f68 100644 --- a/plugin/core.pl +++ b/plugin/core.pl @@ -1,301 +1,301 @@ -################################################################################ -# -# ¥³¥¢¥×¥é¥°¥¤¥ó¤Î¼ÂÁõ -# -################################################################################ -package Wiki::Plugin; - -BEGIN { - # ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤Î¥¨¥ó¥È¥ê - $main::P_PLUGIN->{recent} = \&Wiki::Plugin::recent; - $main::P_PLUGIN->{recentdays} = \&Wiki::Plugin::recentdays; - $main::P_PLUGIN->{category_list} = \&Wiki::Plugin::category_list; - $main::P_PLUGIN->{ref_image} = \&Wiki::Plugin::ref_image; - $main::P_PLUGIN->{ref_text} = \&Wiki::Plugin::ref_text; - $main::P_PLUGIN->{outline} = \&Wiki::Plugin::outline; - $main::P_PLUGIN->{search} = \&Wiki::Plugin::search; - - # ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤Î¥¨¥ó¥È¥ê - $main::I_PLUGIN->{category} = \&Wiki::Plugin::category; - $main::I_PLUGIN->{lastmodified} = \&Wiki::Plugin::lastmodified; - $main::I_PLUGIN->{ref} = \&Wiki::Plugin::ref; -} - -#============================================================================== -# ¥Ú¡¼¥¸¤Î°ìÍ÷¤ò¹¹¿·Æü»þ½ç¤Ëɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ -#============================================================================== -sub recent { - my $max = shift; - $max = 0 if($max eq ""); - my $buf = ""; - - my @pages = &Wiki::get_page_list(); - my $count = 0; - - $buf .= "\n"; - - return $buf; -} - -#============================================================================== -# ÆüÉÕ¤´¤È¤Ë¹¹¿·¤µ¤ì¤¿¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ -#============================================================================== -sub recentdays { - my $max = shift; - $max = 5 if($max eq ""); - my $buf = ""; - - my @pages = &Wiki::get_page_list(); - my $count = 0; - - my $last_year = 0; - my $last_mon = 0; - my $last_day = 0; - - foreach my $page (@pages){ - my ($sec, $min, $hour, $day, $mon, $year) = localtime($page->{TIME}); - - $year += 1900; - $mon += 1; - - if($last_year!=$year || $last_mon!=$mon || $last_day!=$day){ - - $count++; - last if($count == $max+1); - - $last_year = $year; - $last_mon = $mon; - $last_day = $day; - - $buf .= "\n" if($buf ne ""); - $buf .= sprintf("%04d/%02d/%02d\n",$year,$mon,$day); - $buf .= "\n"; - } - - return $buf; -} - -#============================================================================== -# ¥Ú¡¼¥¸¤ò¥«¥Æ¥´¥é¥¤¥º¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ -#============================================================================== -sub category { - my $category = shift; - if($category eq ""){ - return "¥«¥Æ¥´¥ê¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; - } else { - return "[". - "¥«¥Æ¥´¥ê:".&Util::escapeHTML($category)."]"; - } -} - -#============================================================================= -# ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·Æü»þ¤òɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ -#============================================================================= -sub lastmodified { - my $page = $main::in{"p"}; - if(&Wiki::exists_page($page)){ - return "ºÇ½ª¹¹¿·»þ´Ö¡§".&Util::format_date(&Wiki::get_last_modified($page)); - } else { - return undef; - } -} - -#============================================================================= -# ¥«¥Æ¥´¥ê¤´¤È¤Î¥Ú¡¼¥¸°ìÍ÷¤òɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ -#============================================================================= -sub category_list { - my $category = shift; - my $buf = ""; - - # »ØÄꤵ¤ì¤¿¥«¥Æ¥´¥ê¤òɽ¼¨ - if($category ne ""){ - my @pages = &Wiki::get_page_list(); - $buf .= "

    ".&Util::escapeHTML($category)."

    \n"; - $buf .= "
      \n"; - #foreach my $page (sort(@pages)){ - foreach my $page (sort {$a->{NAME} cmp $b->{NAME}} @pages){ - my $source = &Wiki::get_page($page->{NAME}); - foreach my $line (split(/\n/,$source)){ - # ¥³¥á¥ó¥È¤«À°·ÁºÑ¥Æ¥­¥¹¥È¤Î¾ì¹ç¤ÏÈô¤Ð¤¹ - next if($line =~ /^(\t| |\/\/)/); - - # ¥«¥Æ¥´¥ê¤Ë¥Þ¥Ã¥Á¤·¤¿¤é¥ê¥¹¥Æ¥£¥ó¥° - if($line =~ /{{category\s+$category}}/){ - $buf .= "
    • {NAME})."\">". - &Util::escapeHTML($page->{NAME})."
    • "; - last; - } - } - } - $buf .= "
    \n"; - - # Á´¤Æ¤Î¥«¥Æ¥´¥ê¤òɽ¼¨ - } else { - my $category = {}; - my @pages = &Wiki::get_page_list(); - - foreach my $page (@pages){ - my $source = &Wiki::get_page($page->{NAME}); - foreach my $line (split(/\n/,$source)){ - # ¥³¥á¥ó¥È¤«À°·ÁºÑ¥Æ¥­¥¹¥È¤Î¾ì¹ç¤ÏÈô¤Ð¤¹ - next if($line =~ /^(\t| |\/\/)/); - - # ¥«¥Æ¥´¥ê¤Ë¥Þ¥Ã¥Á¤·¤¿¤é¥ê¥¹¥Æ¥£¥ó¥° - while($line =~ /{{category\s+(.+?)}}/g){ - $category->{$1}->{$page->{NAME}} = 1; - } - } - } - - foreach my $name (sort(keys(%$category))){ - $buf .= "

    ".&Util::escapeHTML($name)."

    \n"; - $buf .= "\n"; - } - } - return $buf; -} - -#============================================================================= -# źÉÕ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ -#============================================================================= -sub ref { - my $page = $main::in{"p"}; - my $file = shift; - - if($file eq ""){ - return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; - } - - my $filename = sprintf("$main::ATTACH_DIR/%s.%s", - &Util::url_encode($page),&Util::url_encode($file)); - unless(-e $filename){ - return "¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£"; - } - - return sprintf("%s", - &Util::url_encode($page),&Util::url_encode($file),$file); -} - -#============================================================================= -# źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ -#============================================================================= -sub ref_image { - my $page = $main::in{"p"}; - my $file = shift; - - if($file eq ""){ - return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; - } - - my $filename = sprintf("$main::ATTACH_DIR/%s.%s", - &Util::url_encode($page),&Util::url_encode($file)); - unless(-e $filename){ - return "

    ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£

    \n"; - } - - return sprintf("
    ", - &Util::url_encode($page),&Util::url_encode($file)); -} - -#============================================================================= -# źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ -#============================================================================= -sub ref_text { - my $page = $main::in{"p"}; - my $file = shift; - - if($file eq ""){ - return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; - } - - my $filename = sprintf("$main::ATTACH_DIR/%s.%s", - &Util::url_encode($page),&Util::url_encode($file)); - unless(-e $filename){ - return "

    ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£

    \n"; - } - - my $text = ""; - open(DATA,$filename); - while(){ - $text .= $_; - } - close(DATA); - - # ²þ¹Ô¥³¡¼¥É¤òÊÑ´¹ - $text =~ s/\r\n/\n/g; - $text =~ s/\r/\n/g; - # ʸ»ú¥³¡¼¥É¤òÊÑ´¹ - &jcode::convert(\$text,"euc"); - - # pre¥¿¥°¤ò¤Ä¤±¤ÆÊÖµÑ - return "
    ".&Util::escapeHTML($text)."
    \n"; -} - -#============================================================================= -# ¥¢¥¦¥È¥é¥¤¥ó¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó -# ½ÐÎϤµ¤ì¤ëHTML¤Ï¤Á¤ç¤Ã¤È¼êÈ´¤­¤Ç¤¹¡Ä -#============================================================================= -sub outline { - my $page = $main::in{'p'}; - my $source = &Wiki::get_page($page); - my $level = 0; - my $count = 0; - my $buf = ""; - foreach my $line (split(/\n/,$source)){ - if($line=~/^(!{1,3})(.+)$/){ - my $find_level = 4 - length($1); - - while($level < $find_level){ - $buf .= "
      \n"; - $level++; - } - - while($level > $find_level){ - $buf .= "
    \n"; - $level--; - } - my $section = &Util::delete_tag(&Wiki::process_wiki($2)); - - $buf .= "
  • $section
  • \n"; - $count++; - } - } - while($level > 0){ - $buf .= "\n"; - $level--; - } - return $buf; -} - -#============================================================================= -# ¸¡º÷¥Õ¥©¡¼¥à¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó -#============================================================================= -sub search { - return "
    \n". - " ¥­¡¼¥ï¡¼¥É \n". - " \n". - " \n". - "
    \n"; -} - -1; +################################################################################ +# +# ¥³¥¢¥×¥é¥°¥¤¥ó¤Î¼ÂÁõ +# +################################################################################ +package Wiki::Plugin; + +BEGIN { + # ¥Ñ¥é¥°¥é¥Õ¥×¥é¥°¥¤¥ó¤Î¥¨¥ó¥È¥ê + $main::P_PLUGIN->{recent} = \&Wiki::Plugin::recent; + $main::P_PLUGIN->{recentdays} = \&Wiki::Plugin::recentdays; + $main::P_PLUGIN->{category_list} = \&Wiki::Plugin::category_list; + $main::P_PLUGIN->{ref_image} = \&Wiki::Plugin::ref_image; + $main::P_PLUGIN->{ref_text} = \&Wiki::Plugin::ref_text; + $main::P_PLUGIN->{outline} = \&Wiki::Plugin::outline; + $main::P_PLUGIN->{search} = \&Wiki::Plugin::search; + + # ¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤Î¥¨¥ó¥È¥ê + $main::I_PLUGIN->{category} = \&Wiki::Plugin::category; + $main::I_PLUGIN->{lastmodified} = \&Wiki::Plugin::lastmodified; + $main::I_PLUGIN->{ref} = \&Wiki::Plugin::ref; +} + +#============================================================================== +# ¥Ú¡¼¥¸¤Î°ìÍ÷¤ò¹¹¿·Æü»þ½ç¤Ëɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ +#============================================================================== +sub recent { + my $max = shift; + $max = 0 if($max eq ""); + my $buf = ""; + + my @pages = &Wiki::get_page_list(); + my $count = 0; + + $buf .= "\n"; + + return $buf; +} + +#============================================================================== +# ÆüÉÕ¤´¤È¤Ë¹¹¿·¤µ¤ì¤¿¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ +#============================================================================== +sub recentdays { + my $max = shift; + $max = 5 if($max eq ""); + my $buf = ""; + + my @pages = &Wiki::get_page_list(); + my $count = 0; + + my $last_year = 0; + my $last_mon = 0; + my $last_day = 0; + + foreach my $page (@pages){ + my ($sec, $min, $hour, $day, $mon, $year) = localtime($page->{TIME}); + + $year += 1900; + $mon += 1; + + if($last_year!=$year || $last_mon!=$mon || $last_day!=$day){ + + $count++; + last if($count == $max+1); + + $last_year = $year; + $last_mon = $mon; + $last_day = $day; + + $buf .= "\n" if($buf ne ""); + $buf .= sprintf("%04d/%02d/%02d\n",$year,$mon,$day); + $buf .= "\n"; + } + + return $buf; +} + +#============================================================================== +# ¥Ú¡¼¥¸¤ò¥«¥Æ¥´¥é¥¤¥º¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ +#============================================================================== +sub category { + my $category = shift; + if($category eq ""){ + return "¥«¥Æ¥´¥ê¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; + } else { + return "[". + "¥«¥Æ¥´¥ê:".&Util::escapeHTML($category)."]"; + } +} + +#============================================================================= +# ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·Æü»þ¤òɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ +#============================================================================= +sub lastmodified { + my $page = $main::in{"p"}; + if(&Wiki::exists_page($page)){ + return "ºÇ½ª¹¹¿·»þ´Ö¡§".&Util::format_date(&Wiki::get_last_modified($page)); + } else { + return undef; + } +} + +#============================================================================= +# ¥«¥Æ¥´¥ê¤´¤È¤Î¥Ú¡¼¥¸°ìÍ÷¤òɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó¡£ +#============================================================================= +sub category_list { + my $category = shift; + my $buf = ""; + + # »ØÄꤵ¤ì¤¿¥«¥Æ¥´¥ê¤òɽ¼¨ + if($category ne ""){ + my @pages = &Wiki::get_page_list(); + $buf .= "

    ".&Util::escapeHTML($category)."

    \n"; + $buf .= "
      \n"; + #foreach my $page (sort(@pages)){ + foreach my $page (sort {$a->{NAME} cmp $b->{NAME}} @pages){ + my $source = &Wiki::get_page($page->{NAME}); + foreach my $line (split(/\n/,$source)){ + # ¥³¥á¥ó¥È¤«À°·ÁºÑ¥Æ¥­¥¹¥È¤Î¾ì¹ç¤ÏÈô¤Ð¤¹ + next if($line =~ /^(\t| |\/\/)/); + + # ¥«¥Æ¥´¥ê¤Ë¥Þ¥Ã¥Á¤·¤¿¤é¥ê¥¹¥Æ¥£¥ó¥° + if($line =~ /{{category\s+$category}}/){ + $buf .= "
    • {NAME})."\">". + &Util::escapeHTML($page->{NAME})."
    • "; + last; + } + } + } + $buf .= "
    \n"; + + # Á´¤Æ¤Î¥«¥Æ¥´¥ê¤òɽ¼¨ + } else { + my $category = {}; + my @pages = &Wiki::get_page_list(); + + foreach my $page (@pages){ + my $source = &Wiki::get_page($page->{NAME}); + foreach my $line (split(/\n/,$source)){ + # ¥³¥á¥ó¥È¤«À°·ÁºÑ¥Æ¥­¥¹¥È¤Î¾ì¹ç¤ÏÈô¤Ð¤¹ + next if($line =~ /^(\t| |\/\/)/); + + # ¥«¥Æ¥´¥ê¤Ë¥Þ¥Ã¥Á¤·¤¿¤é¥ê¥¹¥Æ¥£¥ó¥° + while($line =~ /{{category\s+(.+?)}}/g){ + $category->{$1}->{$page->{NAME}} = 1; + } + } + } + + foreach my $name (sort(keys(%$category))){ + $buf .= "

    ".&Util::escapeHTML($name)."

    \n"; + $buf .= "\n"; + } + } + return $buf; +} + +#============================================================================= +# źÉÕ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ +#============================================================================= +sub ref { + my $page = $main::in{"p"}; + my $file = shift; + + if($file eq ""){ + return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; + } + + my $filename = sprintf("$main::ATTACH_DIR/%s.%s", + &Util::url_encode($page),&Util::url_encode($file)); + unless(-e $filename){ + return "¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£"; + } + + return sprintf("%s", + &Util::url_encode($page),&Util::url_encode($file),$file); +} + +#============================================================================= +# źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ +#============================================================================= +sub ref_image { + my $page = $main::in{"p"}; + my $file = shift; + + if($file eq ""){ + return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; + } + + my $filename = sprintf("$main::ATTACH_DIR/%s.%s", + &Util::url_encode($page),&Util::url_encode($file)); + unless(-e $filename){ + return "

    ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£

    \n"; + } + + return sprintf("
    ", + &Util::url_encode($page),&Util::url_encode($file)); +} + +#============================================================================= +# źÉÕ¥Õ¥¡¥¤¥ë¤ò²èÁü¤È¤·¤Æɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¡£ +#============================================================================= +sub ref_text { + my $page = $main::in{"p"}; + my $file = shift; + + if($file eq ""){ + return "¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"; + } + + my $filename = sprintf("$main::ATTACH_DIR/%s.%s", + &Util::url_encode($page),&Util::url_encode($file)); + unless(-e $filename){ + return "

    ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£

    \n"; + } + + my $text = ""; + open(DATA,$filename); + while(){ + $text .= $_; + } + close(DATA); + + # ²þ¹Ô¥³¡¼¥É¤òÊÑ´¹ + $text =~ s/\r\n/\n/g; + $text =~ s/\r/\n/g; + # ʸ»ú¥³¡¼¥É¤òÊÑ´¹ + &jcode::convert(\$text,"euc"); + + # pre¥¿¥°¤ò¤Ä¤±¤ÆÊÖµÑ + return "
    ".&Util::escapeHTML($text)."
    \n"; +} + +#============================================================================= +# ¥¢¥¦¥È¥é¥¤¥ó¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó +# ½ÐÎϤµ¤ì¤ëHTML¤Ï¤Á¤ç¤Ã¤È¼êÈ´¤­¤Ç¤¹¡Ä +#============================================================================= +sub outline { + my $page = $main::in{'p'}; + my $source = &Wiki::get_page($page); + my $level = 0; + my $count = 0; + my $buf = ""; + foreach my $line (split(/\n/,$source)){ + if($line=~/^(!{1,3})(.+)$/){ + my $find_level = 4 - length($1); + + while($level < $find_level){ + $buf .= "
      \n"; + $level++; + } + + while($level > $find_level){ + $buf .= "
    \n"; + $level--; + } + my $section = &Util::delete_tag(&Wiki::process_wiki($2)); + + $buf .= "
  • $section
  • \n"; + $count++; + } + } + while($level > 0){ + $buf .= "\n"; + $level--; + } + return $buf; +} + +#============================================================================= +# ¸¡º÷¥Õ¥©¡¼¥à¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó +#============================================================================= +sub search { + return "
    \n". + " ¥­¡¼¥ï¡¼¥É \n". + " \n". + " \n". + "
    \n"; +} + +1; diff --git a/release.sh b/release.sh index 5e2e509..8c4ff85 100644 --- a/release.sh +++ b/release.sh @@ -1,68 +1,68 @@ -#!/bin/sh -########################################################################## -# -# FSWikiLite¥ê¥ê¡¼¥¹ÍÑ¥·¥§¥ë¥¹¥¯¥ê¥×¥È -# -########################################################################## -#========================================================================= -# °ú¿ô¤Î¥Á¥§¥Ã¥¯ -#========================================================================= -if [ $# -lt 1 ] -then - echo "./release.sh version" - exit 1 -fi - -#========================================================================= -# ¥Ð¡¼¥¸¥ç¥ó¾ðÊó -#========================================================================= -VERSION=$1 -RELEASE="fswiki_lite_$VERSION" - -#========================================================================= -# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤¬¤¢¤ë¾ì¹ç¤Ïºï½ü -#========================================================================= -if [ -e $RELEASE ]; then - echo "delete temp directory..." - rm -rf $RELEASE -fi - -#========================================================================= -# zip¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¾ì¹ç¤Ïºï½ü -#========================================================================= -if [ -e $RELEASE.zip ]; then - echo "delete zip file..." - rm -f $RELEASE.zip -fi - -#========================================================================= -# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤ÎºîÀ® -#========================================================================= -echo "create temp directory..." -mkdir $RELEASE - -#========================================================================= -# ¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼ -#========================================================================= -echo "copy to temp directory..." -cp ./*.cgi $RELEASE -cp -r ./docs $RELEASE -cp -r ./lib $RELEASE -cp -r ./plugin $RELEASE - -#========================================================================= -# zip¥Õ¥¡¥¤¥ë¤ÎºîÀ® -#========================================================================= -echo "create zip file..." -find ./$RELEASE \! -path '*/CVS*' -exec zip $RELEASE.zip {} \; - -#========================================================================= -# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤òºï½ü -#========================================================================= -echo "remove temp directory..." -rm -rf $RELEASE - -#========================================================================= -# ½ªÎ» -#========================================================================= -echo "complete." +#!/bin/sh +########################################################################## +# +# FSWikiLite¥ê¥ê¡¼¥¹ÍÑ¥·¥§¥ë¥¹¥¯¥ê¥×¥È +# +########################################################################## +#========================================================================= +# °ú¿ô¤Î¥Á¥§¥Ã¥¯ +#========================================================================= +if [ $# -lt 1 ] +then + echo "./release.sh version" + exit 1 +fi + +#========================================================================= +# ¥Ð¡¼¥¸¥ç¥ó¾ðÊó +#========================================================================= +VERSION=$1 +RELEASE="fswiki_lite_$VERSION" + +#========================================================================= +# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤¬¤¢¤ë¾ì¹ç¤Ïºï½ü +#========================================================================= +if [ -e $RELEASE ]; then + echo "delete temp directory..." + rm -rf $RELEASE +fi + +#========================================================================= +# zip¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¾ì¹ç¤Ïºï½ü +#========================================================================= +if [ -e $RELEASE.zip ]; then + echo "delete zip file..." + rm -f $RELEASE.zip +fi + +#========================================================================= +# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤ÎºîÀ® +#========================================================================= +echo "create temp directory..." +mkdir $RELEASE + +#========================================================================= +# ¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼ +#========================================================================= +echo "copy to temp directory..." +cp ./*.cgi $RELEASE +cp -r ./docs $RELEASE +cp -r ./lib $RELEASE +cp -r ./plugin $RELEASE + +#========================================================================= +# zip¥Õ¥¡¥¤¥ë¤ÎºîÀ® +#========================================================================= +echo "create zip file..." +find ./$RELEASE \! -path '*/CVS*' -exec zip $RELEASE.zip {} \; + +#========================================================================= +# ¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤òºï½ü +#========================================================================= +echo "remove temp directory..." +rm -rf $RELEASE + +#========================================================================= +# ½ªÎ» +#========================================================================= +echo "complete." diff --git a/wiki.cgi b/wiki.cgi index be8dae8..3bffab1 100644 --- a/wiki.cgi +++ b/wiki.cgi @@ -1,111 +1,111 @@ -#!/usr/bin/perl -################################################################################ -# -# FSWiki Lite -# -################################################################################ -require "./lib/common.pl"; -#=============================================================================== -# ½èÍý¤Î¿¶¤êʬ¤± -#=============================================================================== -&ReadParse(); -if($in{"p"} eq ""){ - $in{"p"} = "FrontPage"; -} - -if($in{"a"} eq "list"){ - &list_page(); - -} elsif($in{"a"} eq "search"){ - &search_page(); - -} else { - &show_page(); - -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤Î°ìÍ÷ -#------------------------------------------------------------------------------- -sub list_page { - my @pages = &Wiki::get_page_list(); - - &print_header("°ìÍ÷"); - print "\n"; - &print_footer(); -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤òɽ¼¨ -#------------------------------------------------------------------------------- -sub show_page { - - unless(&Wiki::exists_page($in{"p"})){ - undef %in; - $in{"a"} = "edit"; - require $EDIT_SCRIPT; - return; - } - - my $source = &Wiki::get_page($in{"p"}); - my $html = &Wiki::process_wiki($source,1); - - &print_header($in{"p"},1); - - if(&Wiki::exists_page("Header")){ - print "
    \n"; - print &Wiki::process_wiki(&Wiki::get_page("Header")); - print "
    \n"; - } - - print "
    \n"; - print $html; - print "
    \n"; - - if(&Wiki::exists_page("Footer")){ - print "
    \n"; - print &Wiki::process_wiki(&Wiki::get_page("Footer")); - print "
    \n"; - } - - &print_footer(); -} - -#------------------------------------------------------------------------------- -# ¥Ú¡¼¥¸¤Î¸¡º÷ -#------------------------------------------------------------------------------- -sub search_page { - - &print_header("¸¡º÷"); - print "
    \n"; - print " ¥­¡¼¥ï¡¼¥É \n"; - print " \n"; - print " \n"; - print "
    \n"; - - if($in{'w'} ne ""){ - my @pages = &Wiki::get_page_list(); - my $find = 0; - print "
      \n"; - foreach my $page (@pages){ - my $source = $page->{NAME}."\n".&Wiki::get_page($page->{NAME}); - if(index($source,$in{'w'})!=-1){ - print "
    • {NAME})."\">".&Util::escapeHTML($page->{NAME})."
    • \n"; - $find = 1; - } - } - if($find==0){ - print "
    • ³ºÅö¤¹¤ë¥Ú¡¼¥¸¤Ï¸ºß¤·¤Þ¤»¤ó¡£
    • \n"; - } - print "
    \n"; - } - - &print_footer(); -} - +#!/usr/bin/perl +################################################################################ +# +# FSWiki Lite +# +################################################################################ +require "./lib/common.pl"; +#=============================================================================== +# ½èÍý¤Î¿¶¤êʬ¤± +#=============================================================================== +&ReadParse(); +if($in{"p"} eq ""){ + $in{"p"} = "FrontPage"; +} + +if($in{"a"} eq "list"){ + &list_page(); + +} elsif($in{"a"} eq "search"){ + &search_page(); + +} else { + &show_page(); + +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤Î°ìÍ÷ +#------------------------------------------------------------------------------- +sub list_page { + my @pages = &Wiki::get_page_list(); + + &print_header("°ìÍ÷"); + print "\n"; + &print_footer(); +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤òɽ¼¨ +#------------------------------------------------------------------------------- +sub show_page { + + unless(&Wiki::exists_page($in{"p"})){ + undef %in; + $in{"a"} = "edit"; + require $EDIT_SCRIPT; + return; + } + + my $source = &Wiki::get_page($in{"p"}); + my $html = &Wiki::process_wiki($source,1); + + &print_header($in{"p"},1); + + if(&Wiki::exists_page("Header")){ + print "
    \n"; + print &Wiki::process_wiki(&Wiki::get_page("Header")); + print "
    \n"; + } + + print "
    \n"; + print $html; + print "
    \n"; + + if(&Wiki::exists_page("Footer")){ + print "
    \n"; + print &Wiki::process_wiki(&Wiki::get_page("Footer")); + print "
    \n"; + } + + &print_footer(); +} + +#------------------------------------------------------------------------------- +# ¥Ú¡¼¥¸¤Î¸¡º÷ +#------------------------------------------------------------------------------- +sub search_page { + + &print_header("¸¡º÷"); + print "
    \n"; + print " ¥­¡¼¥ï¡¼¥É \n"; + print " \n"; + print " \n"; + print "
    \n"; + + if($in{'w'} ne ""){ + my @pages = &Wiki::get_page_list(); + my $find = 0; + print "
      \n"; + foreach my $page (@pages){ + my $source = $page->{NAME}."\n".&Wiki::get_page($page->{NAME}); + if(index($source,$in{'w'})!=-1){ + print "
    • {NAME})."\">".&Util::escapeHTML($page->{NAME})."
    • \n"; + $find = 1; + } + } + if($find==0){ + print "
    • ³ºÅö¤¹¤ë¥Ú¡¼¥¸¤Ï¸ºß¤·¤Þ¤»¤ó¡£
    • \n"; + } + print "
    \n"; + } + + &print_footer(); +} + -- 2.11.0