Skip to content
Browse files

Initial Google import

git-svn-id: http://phpsyntaxtree.googlecode.com/svn/trunk@2 dd736c32-9719-0410-982d-5f90ca37e7c8
  • Loading branch information...
1 parent 0412ce8 commit 5f0975a6de6cdfa792cb657b8962bcbf0d132f67 int2str committed
Showing with 117,021 additions and 0 deletions.
  1. +12 −0 .htaccess
  2. +16 −0 AUTHORS
  3. +340 −0 COPYING
  4. +63 −0 ChangeLog
  5. +51 −0 README
  6. +160 −0 css/default.css
  7. BIN css/gradient.jpg
  8. +26 −0 css/print.css
  9. +88 −0 dnlgraph.php
  10. +143 −0 index.php
  11. +70 −0 js/autoSubmit.js
  12. +83 −0 js/bracketCount.js
  13. +39 −0 js/hookOnLoad.js
  14. +270 −0 lib/class.template.php
  15. +2 −0 src/.htaccess
  16. +78 −0 src/class.element.php
  17. +175 −0 src/class.elementlist.php
  18. +267 −0 src/class.stringparser.php
  19. +373 −0 src/class.svggraph.php
  20. +414 −0 src/class.treegraph.php
  21. +47 −0 src/counter.php
  22. +35 −0 src/imgutils.php
  23. +83 −0 src/lang.php
  24. +62 −0 src/log.php
  25. +135 −0 src/smoothline.php
  26. +91 −0 stgraph.png
  27. +85 −0 stgraph.svg
  28. +2 −0 tpl/.htaccess
  29. +18 −0 tpl/footer.html
  30. +32 −0 tpl/header.html
  31. +77 −0 tpl/intro.html
  32. +78 −0 tpl/intro.html.de
  33. +75 −0 tpl/intro.html.nl
  34. +67 −0 tpl/main.html
  35. +67 −0 tpl/main.html.de
  36. +67 −0 tpl/main.html.nl
  37. +49 −0 tpl/news.html
  38. +56 −0 tpl/news.html.de
  39. +47 −0 tpl/news.html.nl
  40. +124 −0 ttf/COPYRIGHT.TXT
  41. +11 −0 ttf/README.TXT
  42. +162 −0 ttf/RELEASENOTES.TXT
  43. BIN ttf/Vera.ttf
  44. BIN ttf/VeraBI.ttf
  45. BIN ttf/VeraBd.ttf
  46. BIN ttf/VeraIt.ttf
  47. BIN ttf/VeraMoBI.ttf
  48. BIN ttf/VeraMoBd.ttf
  49. BIN ttf/VeraMoIt.ttf
  50. BIN ttf/VeraMono.ttf
  51. BIN ttf/VeraSe.ttf
  52. BIN ttf/VeraSeBd.ttf
  53. +32 −0 ttf/local.conf
  54. +3 −0 var/.cvsignore
  55. +2 −0 var/.htaccess
  56. +1 −0 var/counter.dat
  57. +91,688 −0 var/lang.log
  58. +21,152 −0 var/phpst.log
  59. +1 −0 var/sample.phrase
  60. +1 −0 var/sample.phrase.de
  61. +1 −0 var/sample.phrase.nl
View
12 .htaccess
@@ -0,0 +1,12 @@
+<Files .htaccess>
+ order allow,deny
+ deny from all
+</Files>
+
+<Files stgraph.png>
+ ForceType application/x-httpd-php
+</Files>
+
+<Files stgraph.svg>
+ ForceType application/x-httpd-php
+</Files>
View
16 AUTHORS
@@ -0,0 +1,16 @@
+DEVELOPERS
+
+Andre Eisenbach <andre@ironcreek.net>
+ Initial coding and maintenance.
+
+Mei Eisenbach <mei@ironcreek.net>
+ Idea and Linguistic support
+
+
+TRANSLATORS
+
+Bart van Bezooijen <b.van.bezooijen@chello.nl>
+ Dutch
+
+Andre Eisenbach <andre@ironcreek.net>
+ German
View
340 COPYING
@@ -0,0 +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.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ <signature of Ty Coon>, 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.
View
63 ChangeLog
@@ -0,0 +1,63 @@
+
+phpSyntaxTree 1.10
+------------------
+
+2005-06-02 int2str <andre@ironcreek.net>
+
+ * README: Added local installation instructions
+
+ * src/class.svggraph.php, src/class.treegraph.php, stgraph.png, stgraph.svg:
+ Fix PHP generated warning messages when allow_call_time_pass_reference is set to 'off'.
+
+ * src/counter.php:
+ Check if file exists before accessing it, to prevent warning messages.
+
+phpSyntaxTree 1.9
+-----------------
+
+2005-03-10 int2str <andre@ironcreek.net>
+
+ * css/default.css, tpl/footer.html, tpl/intro.html, tpl/main.html:
+ Made content area and phrase entry field sizing more dynamic.
+
+2005-03-05 int2str <andre@ironcreek.net>
+
+ * src/class.stringparser.php:
+ Fixed problem where TAB characters would cause empty tree element.
+
+2005-02-27 int2str <andre@ironcreek.net>
+
+ * src/class.treegraph.php:
+ Use the font size as padding for tree elements to fix a bug where the text elements were drawn too close to each other at large font size settings.
+
+ * index.php: Started 1.9 development cycle.
+
+phpSyntaxTree 1.8
+-----------------
+
+2005-01-08 int2str <andre@ironcreek.net>
+
+ * ChangeLog: Fixed email address in ChangeLog
+
+ * tpl/main.html:
+ Fixed bug where Konqueror would constantly reload the phrase form.
+
+ * css/default.css: Cleaned up column style.
+
+2005-01-07 int2str <andre@ironcreek.net>
+
+ * tpl/intro.html: Fixed HTML syntax error.
+
+phpSyntaxTree 1.7
+-----------------
+
+2005-01-06 int2str <sndre@ironcreek.net>
+
+ * tpl/footer.html, tpl/header.html, tpl/intro.html, tpl/main.html, css/default.css, index.php:
+ * Changed Version number handling (now a template variable)
+ * Broke out HTML header and footer into their own respective files to be included from main.html and intro.html
+ * New HTML/CSS layout
+
+ * lib/class.template.php:
+ Pass known values to included sub-templates before parsing them.
+
View
51 README
@@ -0,0 +1,51 @@
+phpSyntaxTree
+=============
+
+phpSyntaxTree is a web application that creates syntax tree graphs
+from phrases entered in labelled bracket notation. phpSyntaxTree
+generated graphs can be used in linguistic homework, assignments
+and other documents.
+
+See the COPYING file for license information.
+
+phpSyntaxTree can be used on the web, without installing any
+software at http://ironcreek.net/phpsyntaxtree .
+
+
+Local Installation
+==================
+
+If you prefer to run phpSyntaxTree locally, or on your own server,
+simply follow the instructions below.
+
+
+Requirements
+------------
+
+- Web server with support for .htaccess overwritable mime types
+ like Apache 1.3/2.0 (http://httpd.apache.org/)
+
+- PHP 4.3+ (PHP 5 not yet tested, but should work) with support
+ for the GD library and TrueType font support (http://php.net)
+
+Installation
+------------
+
+Unpack the archive into a suitable directory on your web server.
+Be sure that the directory is configured to allow configuration
+overwrites using a .htaccess file.
+
+Change the permissions on the phpsyntaxtree/var/ directory to be
+writable by the web server user (ex. apache, nobody, or similar).
+phpSyntaxTree will create a counter.dat and a phpst.log file there
+as well as other temporary files.
+
+
+Support, Questions etc.
+=======================
+
+If you encounter any bugs or problems, please file a bug report
+on the phpSyntaxTree project page:
+http://sourceforge.net/projects/phpsyntaxtree
+
+Or, send email to andre@ironcreek.net
View
160 css/default.css
@@ -0,0 +1,160 @@
+/*
+** phpSyntaxTree - Default stylesheet
+** $Id: default.css,v 1.9 2006/07/21 22:27:32 int2str Exp $
+*/
+
+body {
+ color: black;
+ background-color: #fff;
+ font-family: "Bitsream Vera Sans",Helvetica,Arial,sans-serif;
+ font-size: 0.9em;
+ margin: 0;
+ padding: 0;
+}
+
+#content {
+ width: 90%;
+ padding: 10px;
+ margin-top: 0px;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+#footer {
+ text-align: center;
+ font-size: smaller;
+ padding-top: 10px;
+ color: #777;
+ background-color: #fff;
+ clear: both;
+}
+
+#footer a {
+ color: #777;
+ background-color: #fff;
+ font-weight: bold;
+ border: 0;
+}
+
+#footer a:hover {
+ color: red;
+ background-color: #fff;
+}
+
+#footer img {
+ border: 0;
+}
+
+#phrase {
+ display: none;
+}
+
+#graph {
+ text-align: center;
+}
+
+#graph img {
+ border: 0;
+}
+
+#options {
+ text-align: left;
+}
+
+button {
+ font-weight: bold;
+ font-size: 0.9em;
+ color: black;
+ background-color: #fefefe;
+ padding: 3px 10px;
+ margin-right: 10px;
+}
+
+button:hover {
+ color: #900;
+ background-color: #fff;
+ border: 1px solid #444;
+}
+
+textarea {
+ width: 100%;
+}
+
+fieldset {
+ color: black;
+ background-color: #eee;
+ border: 1px solid #ccc;
+ padding: 5px 10px;
+ margin: 10px 0;
+}
+
+#actions {
+ font-size: 0.8em;
+}
+
+.readonly {
+ border: 0;
+ text-align: center;
+ background-color: transparent;
+}
+
+h1 {
+ background: #335 url("gradient.jpg") bottom left repeat-x;
+ color: white;
+ padding: 15px 10px 5px 10px;
+ font-size: 1.1em;
+ margin: 0px;
+}
+
+h2 {
+ font-size: 1.1em;
+ border-bottom: 1px solid silver;
+ padding: 0 0 5px 0;
+}
+
+h3 {
+ font-size: 1em;
+ margin: 0;
+ padding: 0;
+}
+
+h4 {
+ margin: 0;
+}
+
+p {
+ margin: 5px 0 10px 0;
+}
+
+#intro {
+ width: 49%;
+ float: left;
+ margin: 0;
+ padding-right: 5px;
+}
+
+#news, #about, #usage {
+ font-size: 0.8em;
+}
+
+#news {
+ margin: 0;
+ padding-left: 5px;
+ width: 49%;
+ float: right;
+}
+
+#tip {
+ color: #555;
+ text-align: center;
+ font-style: italic;
+}
+
+textarea {
+ padding: 2px;
+}
+
+textarea, button, select {
+ border: 1px solid #ccc;
+}
+
View
BIN css/gradient.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
26 css/print.css
@@ -0,0 +1,26 @@
+/*
+** phpSyntaxTree - Printing stylesheet
+**
+** The printer stylesheet hides everything but
+** the phrase and the graph.
+**
+** $Id: print.css,v 1.2 2005/08/20 20:52:13 int2str Exp $
+*/
+
+fieldset {
+ border: 0;
+}
+
+h1, #about, #usage, #footer, #form, #options, #news, #tip {
+ display: none;
+}
+
+#phrase {
+ display: block;
+}
+
+#content {
+ text-align: center;
+ border: 0;
+}
+
View
88 dnlgraph.php
@@ -0,0 +1,88 @@
+<?php
+
+// dnlgrapn.php - Generate a downloadable syntax tree
+// Copyright (c) 2003-2005 Andre Eisenbach <andre@ironcreek.net>
+//
+// dnlgraph.php is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: dnlgraph.php,v 1.3 2005/08/25 19:07:18 int2str Exp $
+
+require_once( "src/class.elementlist.php" );
+require_once( "src/class.stringparser.php" );
+require_once( "src/class.treegraph.php" );
+
+// Start session to retrieve graph data
+session_start();
+
+// Read session data
+
+if ( !isset( $_SESSION['data'] ) )
+{
+ printf( "Error: Couldn't retrieve session data." );
+ exit;
+}
+
+$data = $_SESSION['data'];
+
+$color = isset( $_SESSION['color'] ) ? $_SESSION['color'] : 0;
+$triangles = isset( $_SESSION['triangles'] ) ? $_SESSION['triangles'] : FALSE;
+$antialias = isset( $_SESSION['antialias'] ) ? $_SESSION['antialias'] : 0;
+$autosub = isset( $_SESSION['autosub'] ) ? $_SESSION['autosub'] : 0;
+$font = isset( $_SESSION['font'] ) ? $_SESSION['font'] : 'Vera.ttf';
+$fontsize = isset( $_SESSION['fontsize'] ) ? $_SESSION['fontsize'] : 8;
+
+// Validate the phrase and draw the tree
+
+$sp = new CStringParser( $data );
+
+if ($sp->Validate() )
+{
+ // If all is well, go ahead and draw the graph ...
+
+ $sp->Parse();
+
+ if ( $autosub )
+ $sp->AutoSubscript();
+
+ $elist = $sp->GetElementList();
+
+ // Draw the graph into a file
+
+ $tmpfile = tempnam( 'var/', 'stgraph' );
+
+ $fontpath = dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/ttf/';
+
+ $graph = new CTreegraph( $elist
+ , $color, $antialias, $triangles
+ , $fontpath . $font, $fontsize );
+ $graph->Save( $tmpfile );
+
+ $size = filesize( $tmpfile );
+
+ header( "Content-Type: application/octet-stream" );
+ // header( "Content-Type: image/png" );
+ header( "Content-Disposition: attachment; filename=syntax_tree.png" );
+ header( sprintf( "Content-Length: %ld", $size ));
+
+ readfile( $tmpfile );
+
+ unlink( $tmpfile );
+} else {
+ printf( "Error: Phrase could not be parsed correctly." );
+}
+
+?>
View
143 index.php
@@ -0,0 +1,143 @@
+<?php
+
+// phpSyntaxTree - A syntax tree graph generator writtn in PHP.
+// Copyright (c) 2003-2005 Andre Eisenbach <andre@ironcreek.net>
+//
+// 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
+//
+// $Id: index.php,v 1.14 2005/08/22 23:31:16 int2str Exp $
+
+define( 'VERSION', '1.11-CVS' );
+
+define( 'LOG_PHRASE', 0 );
+define( 'LOG_LANG', 1 );
+
+require_once( 'lib/class.template.php' );
+require_once( 'src/counter.php' );
+require_once( 'src/log.php' );
+require_once( 'src/lang.php' );
+
+define( 'HTML_CHECKED', 'checked="checked"' );
+define( 'HTML_UNCHECKED', '' );
+define( 'HTML_SELECTED', 'selected="selected"' );
+
+// Start a session which is used to pass form data
+// to the image generating PHP.
+
+session_start();
+
+$page = NULL;
+
+// Check if a new form was submitted and store
+// the data in session variables accordingly
+
+if( isset( $_POST['data'] ) )
+{
+ // Initialize the main page template
+
+ $page = new CTemplate( GetLocalizedFName( 'tpl/main.html' ));
+
+ $_SESSION['data'] = trim( $_POST['data'] );
+
+ $_SESSION['color'] = ( isset( $_POST['color'] ) ? TRUE : FALSE );
+ $_SESSION['antialias'] = ( isset( $_POST['antialias'] ) ? TRUE : FALSE );
+ $_SESSION['autosub'] = ( isset( $_POST['autosub'] ) ? TRUE : FALSE );
+ $_SESSION['triangles'] = ( isset( $_POST['triangles'] ) ? TRUE : FALSE );
+
+ if ( isset( $_POST['font'] ) )
+ {
+ $font = 'Vera.ttf';
+ switch( $_POST['font'] )
+ {
+ case 'vera_sans':
+ break;
+
+ case 'vera_serif':
+ $font = 'VeraSe.ttf';
+ break;
+
+ default:
+ break;
+ }
+
+ $_SESSION['fontsel'] = $_POST['font'];
+ $_SESSION['font'] = $font;
+ }
+
+ $_SESSION['fontsize'] = isset( $_POST['fontsize'] )
+ ? intval( $_POST['fontsize'] ) : 8;
+
+ // Increment phrase counter (displayed on the bottom of the page)
+ AddCounter();
+
+ // Log phrase
+ if ( LOG_PHRASE )
+ LogPhrase( $_SESSION['data'] );
+
+ // Log language settings, so we get a feeling for
+ // which translations we'll need...
+ if ( LOG_LANG )
+ LogLangSettings();
+} else {
+ // If no phrase was submitted, show
+ // usage information, news, etc. .
+
+ $page = new CTemplate( GetLocalizedFname( 'tpl/intro.html' ));
+}
+
+// If we don't have data from the form or a
+// previous phrase stored in the sessions,
+// load the example data.
+
+if ( !isset( $_SESSION['data'] ) )
+{
+ $_SESSION['data'] = file_get_contents( GetLocalizedFname( "var/sample.phrase" ));
+ $_SESSION['color'] = TRUE;
+ $_SESSION['antialias'] = TRUE;
+ $_SESSION['autosub'] = TRUE;
+ $_SESSION['triangles'] = TRUE;
+ $_SESSION['fontsel'] = "vera_sans";
+ $_SESSION['font'] = "Vera.ttf";
+ $_SESSION['fontsize'] = 8;
+}
+
+// Render the page
+
+$phrase = htmlentities( $_SESSION['data'] );
+
+$img = sprintf( "<img src=\"stgraph.png?%s\" alt=\"\" title=\"%s\"/>", SID, $phrase );
+$graph = sprintf( "<a href=\"dnlgraph.php?%s\">%s</a>", SID, $img );
+
+$fontoption = sprintf( "SELECT_%s", $_SESSION['fontsel'] );
+$sizeoption = sprintf( "SELECT_size_%d", $_SESSION['fontsize'] );
+
+$page->SetValues( array(
+ 'VERSION' => VERSION,
+ 'FORM_ACTION' => sprintf( "?%s", strip_tags( SID )),
+ 'GRAPH' => $graph,
+ 'PHRASE' => $phrase,
+ 'DATA_VAL' => $phrase,
+ 'COLOR_VAL' => $_SESSION['color'] ? HTML_CHECKED : HTML_UNCHECKED,
+ 'ANTIALIAS_VAL' => $_SESSION['antialias'] ? HTML_CHECKED : HTML_UNCHECKED,
+ 'AUTOSUB_VAL' => $_SESSION['autosub'] ? HTML_CHECKED : HTML_UNCHECKED,
+ 'TRIANGLES_VAL' => $_SESSION['triangles'] ? HTML_CHECKED : HTML_UNCHECKED,
+ 'COUNTER' => GetCounter(),
+ $fontoption => HTML_SELECTED,
+ $sizeoption => HTML_SELECTED
+));
+
+$page->Render();
+
+?>
View
70 js/autoSubmit.js
@@ -0,0 +1,70 @@
+// autoSubmit.js - JavaScript helper to force a submit of a form when an option is changed
+// Copyright (c) 2003-2005 Andre Eisenbach <andre@ironcreek.net>
+//
+// autoSubmit.js is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: autoSubmit.js,v 1.3 2005/11/03 23:07:43 int2str Exp $
+
+function autoSubmitHookOnChange( controlName, formId )
+{
+ if ( !document.getElementsByName )
+ return;
+
+ if ( !document.getElementById )
+ return;
+
+ control = document.getElementsByName( controlName )[0];
+ if ( !control ) return;
+
+ myform = document.getElementById( formId );
+ if ( !myform ) return;
+
+ control.onchange = function()
+ {
+ myform.submit();
+ };
+}
+
+function autoSubmitHookOnClick( controlName, formId )
+{
+ if ( !document.getElementsByName )
+ return;
+
+ control = document.getElementsByName( controlName )[0];
+ if ( !control ) return;
+
+ myform = document.getElementById( formId );
+ if ( !myform ) return;
+
+ control.onclick = function()
+ {
+ myform.submit();
+ };
+}
+
+function autoSubmitOnLoad()
+{
+ autoSubmitHookOnChange( 'font', 'phraseform' );
+ autoSubmitHookOnChange( 'fontsize', 'phraseform' );
+
+ autoSubmitHookOnClick( 'color', 'phraseform' );
+ autoSubmitHookOnClick( 'antialias', 'phraseform' );
+ autoSubmitHookOnClick( 'autosub', 'phraseform' );
+ autoSubmitHookOnClick( 'triangles', 'phraseform' );
+}
+
+hookOnLoad( autoSubmitOnLoad );
View
83 js/bracketCount.js
@@ -0,0 +1,83 @@
+// bracketCount.js - JavaScript helper to count open/closed brackets
+// Copyright (c) 2003-2005 Andre Eisenbach <andre@ironcreek.net>
+//
+// bracketCount.js is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: bracketCount.js,v 1.4 2005/11/03 23:07:43 int2str Exp $
+
+function bracketCountOnLoad()
+{
+ if (! document.getElementById )
+ return;
+
+ // Hook the OnKeyUp event for the phrase input area
+
+ data = document.getElementById( 'data' );
+ if ( data )
+ data.onkeyup = bracketCount;
+
+ // Do the bracket count once when the page is first loaded
+
+ bracketCount();
+}
+
+function bracketCount()
+{
+ if ( !document.getElementById )
+ return;
+
+ if ( !document.getElementsByName )
+ return;
+
+ var txtArea = document.getElementById( 'data' );
+ if ( !txtArea ) return;
+
+ var oc = document.getElementsByName( 'opencount' )[0];
+ if ( !oc ) return;
+
+ var cc = document.getElementsByName( 'closedcount' )[0];
+ if ( !oc ) return;
+
+ var btn = document.getElementsByName( 'drawbtn' )[0];
+ if ( !btn ) return;
+
+ var str = txtArea.value;
+ var i = 0;
+
+ var bracketOpen = 0;
+ var bracketClosed = 0;
+
+ for ( i=0; i<str.length; i++ )
+ {
+ if ( str.charAt( i ) == "[" )
+ bracketOpen++;
+
+ if ( str.charAt( i ) == "]" )
+ bracketClosed++;
+ }
+
+ oc.value = bracketOpen;
+ cc.value = bracketClosed;
+
+ if ( (bracketClosed - bracketOpen) == 0 )
+ btn.disabled = false;
+ else
+ btn.disabled = true;
+}
+
+hookOnLoad( bracketCountOnLoad );
+
View
39 js/hookOnLoad.js
@@ -0,0 +1,39 @@
+// hookOnLoad.js - JavaScript helper function to hook up a custom onLoad handler
+// Copyright (c) 2003-2005 Andre Eisenbach <andre@ironcreek.net>
+//
+// hookOnLoad.js is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: hookOnLoad.js,v 1.1 2005/11/03 23:07:43 int2str Exp $
+
+function hookOnLoad( func )
+{
+ if ( typeof( func ) != 'function' )
+ {
+ alert( 'Fatal error: Non-function object passed to hookOnLoad()!' );
+ return;
+ }
+
+ var currOnLoad = window.onload;
+
+ window.onload = function()
+ {
+ func();
+
+ if ( typeof( currOnLoad ) == 'function' )
+ currOnLoad();
+ }
+}
View
270 lib/class.template.php
@@ -0,0 +1,270 @@
+<?php
+
+// CTemplate - Simple templating engine which can be used to build
+// web pages and other text documents based on templates.
+// Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
+//
+// 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
+//
+// $Id: class.template.php,v 1.2 2005/01/06 00:53:51 int2str Exp $
+
+// Example:
+// < ?php // Remove space between "< ?"
+// include( "class.template.php" );
+//
+// $page = new CTemplae( "mypage.html" );
+// $page->SetValues( "GREET", "World" );
+// $page->Render();
+// ? > // Remove space between "? >"
+//
+// Sample template (mypage.html):
+// <html>
+// <body>
+// Hello {GREET}!
+// </body>
+// </html>
+
+class CTemplate
+{
+ // --------------------------------------------------------------------
+ // PUBLIC functions
+ // --------------------------------------------------------------------
+
+ // Constructor - set the template to use.
+ function CTemplate( $tpl_file = "", $debug = FALSE )
+ {
+ $this->_values = array();
+ $this->_blockdata = array();
+ $this->_debug = $debug;
+
+ if ( "" != $tpl_file )
+ {
+ $this->SetTemplate( $tpl_file );
+ }
+ }
+
+ // Set the template and load the file from disc.
+ function SetTemplate( $tpl_file )
+ {
+ if ( !file_exists( $tpl_file ) )
+ {
+ trigger_error( "Template file ($tpl_file) not found.",
+ E_USER_ERROR );
+ return;
+ }
+
+ $this->_tpl_file = $tpl_file;
+
+ // Load the whole template...
+ $this->_template = $this->_getFile( $this->_tpl_file );
+
+ // Parse blocks
+ $this->_parseBlocks();
+ }
+
+ // Assign values to template placeholders
+ function SetMacros( $macros )
+ {
+ foreach( $macros as $key => $value )
+ {
+ $this->_template =
+ str_replace( '{' . $key . '}', $value,
+ $this->_template );
+ }
+ }
+
+ // You can either simply pass an array with
+ // multiple values, or a single value.
+ function SetValues( $parameters, $value = "" )
+ {
+ if ( gettype( $parameters ) == "array" )
+ {
+ $this->_values = array_merge( $this->_values, $parameters );
+ }
+ else
+ {
+ $this->_values[$parameters] = $value;
+ }
+ }
+
+ // Enable PHP parsing for this template
+ function EnablePHP( $enable = TRUE )
+ {
+ $this->_parse_php = $enable;
+ }
+
+ // Add a template block with values
+ function AddBlock( $block, $values )
+ {
+ if ( !isset( $this->_blocks[ $block ] ))
+ return;
+
+ $content = $this->_blocks[ $block ];;
+
+ foreach( $values as $token => $value )
+ {
+ $content = str_replace( '{'.$token.'}', $value, $content );
+ }
+
+ $this->_blockdata[ $block ] .= $content;
+ }
+
+ // Parse the template and substitute placeholders.
+ function Parse()
+ {
+ $content = $this->_template;
+
+ // Mask {{ and }} for later substitution with { and }
+ $content = str_replace( "{{", "_<<<_", $content );
+ $content = str_replace( "}}", "_>>>_", $content );
+
+ // Parse includes
+ $search = "#{INCLUDE}(.*){/INCLUDE}#isU";
+ preg_match_all( $search, $content, $matches, PREG_SET_ORDER );
+
+ foreach( $matches as $match )
+ {
+ $incfile = dirname( $this->_tpl_file ) . DIRECTORY_SEPARATOR . $match[1];
+
+ $t = new CTemplate( $incfile );
+ $t->SetValues( $this->_values );
+
+ $search = sprintf( "#{INCLUDE}%s\{/INCLUDE}#isU", $match[1] );
+ $replace = str_replace( "\$", "\\\$", $t->Parse() );
+
+ $content = preg_replace( $search, $replace, $content );
+ }
+
+ // Replace single fields
+ foreach( $this->_values as $token => $value )
+ {
+ $content = str_replace( '{'.$token.'}', $value, $content );
+ }
+
+ // Replace template blocks
+ foreach( $this->_blockdata as $token => $value )
+ {
+ $content = str_replace( '{BLOCK_'.$token.'}', $value, $content );
+ }
+
+ // Parse PHP
+ if ( $this->_parse_php )
+ {
+ $content = $this->_parsePHP( $content );
+ }
+
+ // Strip empty template placeholders
+ if ( !$this->_debug )
+ {
+ $content = preg_replace( "/{.*}/U", "", $content );
+ }
+
+ // Now convert the {{ and }} replacements back to { and }
+ $content = str_replace( "_<<<_", "{", $content );
+ $content = str_replace( "_>>>_", "}", $content );
+
+ // Return content
+ $this->_content = $content;
+
+ return $this->_content;
+ }
+
+ // Render the parsed template (print).
+ function Render()
+ {
+ if ( empty( $this->_content ) )
+ $this->Parse();
+
+ print( $this->_content );
+ }
+
+ // --------------------------------------------------------------------
+ // PRIVATE functions
+ // --------------------------------------------------------------------
+
+ // The prefix to put before the image in the target HREF anchor.
+ var $_tpl_file = "";
+
+ // The template with placeholders
+ var $_template = "";
+
+ // The parsed page content
+ var $_content = "";
+
+ // The values arrary
+ var $_values;
+
+ // Template blocks
+ var $_blocks;
+
+ // Parsed template blocks
+ var $_blockdata;
+
+ // Parse PHP?
+ var $_parse_php = FALSE;
+
+ // Debug - if set, empty placeholders stay...
+ var $_debug = FALSE;
+
+ // Read file contents
+ function _getFile( $file )
+ {
+ if ( function_exists( "file_get_contents" ) )
+ {
+ return file_get_contents( $file );
+ }
+ else
+ {
+ return implode( '', file( $file ) );
+ }
+
+ return "";
+ }
+
+ // Determine all template blocks
+ function _parseBlocks()
+ {
+ $search = "#{BLOCK (.*)}(.*){\/BLOCK}#isU";
+ $replace = "{BLOCK_\\1}";
+
+ preg_match_all( $search, $this->_template, $matches, PREG_SET_ORDER );
+ $this->_template = preg_replace( $search, $replace, $this->_template );
+
+ foreach( $matches as $match )
+ {
+ $this->_blocks[ trim( $match[1] ) ] = ltrim( $match[2] );
+ $this->_blockdata[ trim( $match[1] ) ] = "";
+ }
+ }
+
+ // Parse PHP
+ function _parsePHP( $content )
+ {
+ $search = "#\{PHP\}(.*)\{\/PHP\}#sU";
+ preg_match_all( $search, $content, $matches, PREG_SET_ORDER );
+
+ foreach( $matches as $match )
+ {
+ $search = sprintf( "{PHP}%s{/PHP}", $match[1] );
+ $replace = eval( $match[1] );
+
+ $content = str_replace( $search, $replace, $content );
+ }
+
+ return $content;
+ }
+}
+
+?>
View
2 src/.htaccess
@@ -0,0 +1,2 @@
+Order deny,allow
+Deny from all
View
78 src/class.element.php
@@ -0,0 +1,78 @@
+<?php
+
+// CElement - Basic tree element class
+// Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
+//
+// CElement is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: class.element.php,v 1.1.1.1 2005/01/05 17:49:14 int2str Exp $
+
+// Note: All variables are 'public' access
+
+define( 'ETYPE_UNDEFINED', 0 );
+define( 'ETYPE_NODE', 1 );
+define( 'ETYPE_LEAF', 2 );
+
+class CElement
+{
+ // Unique element id
+ var $id = 0;
+
+ // Parent element id
+ var $parent = 0;
+
+ // Element type
+ var $type = ETYPE_UNDEFINED;
+
+ // The actual element content
+ var $content;
+
+ // Element level in the tree (0=top etc...)
+ var $level = 0;
+
+ // Width of the element in pixels
+ var $width = 0;
+
+ // Drawing offset
+ var $indent = 0;
+
+ // Constructor
+ function CElement( $id = 0, $parent = 0, $content = NULL, $level = 0, $type = ETYPE_LEAF )
+ {
+ $this->id = $id;
+ $this->parent = $parent;
+ $this->type = $type;
+ $this->content = trim( $content );
+ $this->level = $level;
+ $this->width = 0;
+ $this->indent = 0;
+ }
+
+ // Debug helper function
+ function Dump()
+ {
+ printf( "ID : %d\n", $this->id );
+ printf( "Parent : %d\n", $this->parent );
+ printf( "Level : %d\n", $this->level );
+ printf( "Type : %d\n", $this->type );
+ printf( "Width : %d\n", $this->width );
+ printf( "Indent : %d\n", $this->indent );
+ printf( "Content : %s\n\n", $this->content );
+ }
+}
+
+?>
View
175 src/class.elementlist.php
@@ -0,0 +1,175 @@
+<?php
+
+// CElementList - List of unordered tree elements with defined parent
+// relationships and indentation levels.
+// Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
+//
+// CElementList is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: class.elementlist.php,v 1.1.1.1 2005/01/05 17:49:14 int2str Exp $
+
+require_once( "src/class.element.php" );
+
+class CElementList
+{
+ // +--------------------------------------------------------------------
+ // | PUBLIC functions
+ // +--------------------------------------------------------------------
+
+ function Add( $e )
+ {
+ $this->_elements[] = $e;
+
+ if ( $e->parent != 0 )
+ {
+ $p = $this->GetID( $e->parent );
+ $p->type = ETYPE_NODE;
+ $this->SetID( $p->id, $p );
+ }
+ }
+
+ function GetFirst()
+ {
+ if ( count( $this->_elements ) == 0 )
+ return NULL;
+
+ $this->_iterator = 0;
+
+ return ( $this->_elements[ $this->_iterator ] );
+ }
+
+ function GetNext()
+ {
+ ++$this->_iterator;
+
+ if ( !isset( $this->_elements[ $this->_iterator ] ))
+ return NULL;
+
+ return ( $this->_elements[ $this->_iterator ] );
+ }
+
+ function GetID( $id )
+ {
+ for( $i=0; $i<count( $this->_elements ); $i++ )
+ {
+ if ( $this->_elements[ $i ]->id == $id )
+ return $this->_elements[ $i ];
+ }
+
+ return FALSE;
+ }
+
+ function SetID( $id, $e )
+ {
+ for( $i=0; $i<count( $this->_elements ); $i++ )
+ {
+ if ( $this->_elements[ $i ]->id == $id )
+ {
+ $this->_elements[ $i ] = $e;
+ break;
+ }
+ }
+ }
+
+ function GetElements()
+ {
+ return $this->_elements;
+ }
+
+ function GetChildCount( $id )
+ {
+ return count( $this->GetChildren( $i ) );
+ }
+
+ function GetChildren( $id )
+ {
+ $children = array();
+
+ for( $i=0; $i<count( $this->_elements ); $i++ )
+ {
+ if ( $this->_elements[$i]->parent == $id )
+ {
+ $children[] = $this->_elements[$i]->id;
+ }
+ }
+
+ return $children;
+ }
+
+ function GetElementWidth( $id )
+ {
+ $e = $this->GetID( $id );
+ if ( $e != FALSE )
+ return $e->width;
+
+ return -1;
+ }
+
+ function SetElementWidth( $id, $width )
+ {
+ $e = $this->GetID( $id );
+ if ( $e != FALSE )
+ {
+ $e->width = $width;
+ $this->SetID( $id, $e );
+ }
+ }
+
+ function GetIndent( $id )
+ {
+ $e = $this->GetID( $id );
+ if ( $e != FALSE )
+ return $e->indent;
+
+ return -1;
+ }
+
+ function SetIndent( $id, $indent )
+ {
+ $e = $this->GetID( $id );
+ if ( $e != FALSE )
+ {
+ $e->indent = $indent;
+ $this->SetID( $id, $e );
+ }
+ }
+
+ function GetLevelHeight()
+ {
+ $maxlevel = 0;
+ for( $i=0; $i<count( $this->_elements ); $i++ )
+ {
+ $level = $this->_elements[ $i ]->level;
+ if ( $level > $maxlevel )
+ $maxlevel = $level;
+ }
+
+ return $maxlevel+1;
+ }
+
+ // +--------------------------------------------------------------------
+ // | PRIVATE functions
+ // +--------------------------------------------------------------------
+
+ // The element array
+ var $_elements;
+
+ // Iterator index (used for GetFirst() / GetNext() )
+ var $_iterator = -1;
+}
+
+?>
View
267 src/class.stringparser.php
@@ -0,0 +1,267 @@
+<?php
+
+// CStringParser - Parse a phrase into leafs and nodes and strore
+// the result in an element list (see CElementList)
+// Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
+//
+// CStringParser is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: class.stringparser.php,v 1.3 2005/11/15 17:51:50 int2str Exp $
+
+require_once( "src/class.elementlist.php" );
+require_once( "src/class.element.php" );
+
+function escape_high_ascii( $s )
+{
+ $html = '';
+
+ for( $i = 0; $i < strlen( $s ); ++$i )
+ {
+ $c = $s[$i];
+ if ( ord( $c ) < 127 )
+ $html .= $c;
+ else
+ $html .= sprintf( '&#%d;', ord( $c ) );
+ }
+
+ return $html;
+}
+
+class CStringParser
+{
+ // ----------------------------------------------------------------------
+ // PUBLIC FUNCTIONS
+ // ----------------------------------------------------------------------
+
+ function CStringParser( $s )
+ {
+ // Clean up the data a little to make processing easier
+
+ $s = str_replace( "\t", "", $s );
+ $s = str_replace( " ", " ", $s );
+ $s = str_replace( "] [", "][", $s );
+ $s = str_replace( " [", "[", $s );
+
+ $s = escape_high_ascii( $s );
+
+ // Store it for later...
+
+ $this->data = $s;
+
+ // Initialize internal element list
+
+ $this->elist = new CElementList();
+ }
+
+ function Validate()
+ {
+ if( strlen( $this->data ) < 1 )
+ return FALSE;
+
+ // TODO: Currently the only real validation is that the brackets match up. There's room for improvement here.
+
+ $open = 0;
+
+ for( $i=0; $i<strlen( $this->data ); $i++ )
+ {
+ switch( $this->data[$i] )
+ {
+ case "[": $open++; break;
+ case "]": $open--; break;
+ default: break;
+ }
+ }
+
+ return( $open==0 );
+ }
+
+ function Parse()
+ {
+ $this->makeTree( 0 );
+ }
+
+ function GetElementList()
+ {
+ return $this->elist;
+ }
+
+ function AutoSubscript()
+ {
+ $elements = $this->elist->GetElements();
+ $tmpcnt = array();
+
+ foreach( $elements as $element )
+ {
+ if ( $element->type == ETYPE_NODE )
+ {
+ $count = 1;
+ $content = $element->content;
+
+ if( isset( $this->tncnt[ $content ] ))
+ $count = $this->tncnt[ $content ];
+
+ if ( $count > 1 )
+ {
+ if ( isset( $tmpcnt[ $content ] ) )
+ $tmpcnt[ $content ]++;
+ else
+ $tmpcnt[ $content ] = 1;
+
+ $element->content .= "_" . $tmpcnt[ $content ];
+ }
+ $this->elist->SetID( $element->id, $element );
+ }
+ }
+
+ return $this->tncnt;
+ }
+
+ // ----------------------------------------------------------------------
+ // PRIVATE FUNCTIONS
+ // ----------------------------------------------------------------------
+
+ // Element list pointer
+ var $elist;
+
+ // The input sentence
+ var $data = "";
+
+ // Position in the sentence
+ var $pos = 0;
+
+ // ID for the next element
+ var $id = 1;
+
+ // Level in the diagram
+ var $level = 0;
+
+ // Node type counts
+ var $tncnt;
+
+ function countNode( $name )
+ {
+ $name = trim( $name );
+
+ if ( isset( $this->tncnt[ $name ] ) )
+ $this->tncnt[ $name ] += 1;
+ else
+ $this->tncnt[ $name ] = 1;
+ }
+
+ function getNextToken()
+ {
+ $gottoken = FALSE;
+ $token = "";
+ $i = 0;
+
+ if ( ($this->pos + 1) >= strlen( $this->data ) )
+ return "";
+
+ while( ($this->pos + $i) < strlen( $this->data ) && !$gottoken )
+ {
+ $ch = $this->data[$this->pos + $i];
+
+ switch( $ch )
+ {
+ case "[":
+ if( $i > 0 )
+ $gottoken = TRUE;
+ else
+ $token .= $ch;
+ break;
+
+ case "]":
+ if( $i == 0 )
+ $token .= $ch;
+ $gottoken = TRUE;
+ break;
+
+ case "\n":
+ case "\r":
+ break;
+
+ default:
+ $token .= $ch;
+ break;
+ }
+
+ $i++;
+ }
+
+ if( $i > 1 )
+ $this->pos += $i - 1;
+ else
+ $this->pos++;
+
+ return $token;
+ }
+
+ function makeTree( $parent )
+ {
+ $token = trim( $this->getNextToken() );
+
+ while( $token != "" && $token != "]" )
+ {
+ switch( $token[0] )
+ {
+ case "[":
+ $token = substr( $token, 1, strlen( $token ) - 1 );
+ $spaceat = strpos( $token, " " );
+
+ $newparent = -1;
+
+ if( $spaceat != FALSE )
+ {
+ $parts[0] = substr( $token, 0, $spaceat );
+ $parts[1] = substr( $token, $spaceat, strlen( $token ) - $spaceat );
+
+ $e = new CElement( $this->id++, $parent, $parts[0], $this->level );
+ $this->elist->Add( $e );
+ $newparent = $e->id;
+ $this->countNode( $parts[0] );
+
+ $e = new CElement( $this->id++, $this->id - 2, $parts[1], $this->level + 1 );
+ $this->elist->Add( $e );
+ } else {
+ $e = new CElement( $this->id++, $parent, $token, $this->level );
+ $newparent = $e->id;
+ $this->elist->Add( $e );
+ $this->countNode( $token );
+ }
+
+ $this->level++;
+ $this->makeTree( $newparent );
+ break;
+
+ default:
+ if ( trim( $token ) > "" )
+ {
+ $e = new CElement( $this->id++, $parent, $token, $this->level );
+ $this->elist->Add( $e );
+ $this->countNode( $token );
+ }
+ break;
+ }
+
+ $token = $this->getNextToken();
+ }
+
+ $this->level--;
+ }
+}
+
+?>
View
373 src/class.svggraph.php
@@ -0,0 +1,373 @@
+<?php
+
+// CSVGGraph - Parse an element list into a graphical tree.
+// Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
+//
+// CSVGGraph is part of phpSyntaxTree.
+//
+// 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
+//
+// $Id: class.svggraph.php,v 1.3 2006/07/21 22:27:11 int2str Exp $
+
+require_once( "src/smoothline.php" );
+require_once( "src/imgutils.php" );
+require_once( "src/class.elementlist.php" );
+
+define( 'E_WIDTH', 60 ); // Element width
+define( 'E_PADD', 5 ); // Element height padding
+define( 'V_SPACE', 10 );
+define( 'H_SPACE', 10 );
+define( 'B_SIDE', 5 );
+define( 'B_TOPBOT', 5 );
+
+class CSVGGraph
+{
+ // ----------------------------------------------------------------------
+ // PUBLIC FUNCTIONS
+ // ----------------------------------------------------------------------
+
+ // Constructor
+ function CSVGGraph(
+ &$e_list_ref
+ , $color=TRUE, $antialias=TRUE, $triangles=TRUE
+ , $font="Vera.ttf", $fontsize=10 )
+ {
+ // Store parameters
+
+ $this->e_list = $e_list_ref;
+ $this->font = $font;
+ $this->font_size = $fontsize;
+ $this->antialias = $antialias;
+ $this->triangles = $triangles;
+
+ // Calculate image dimensions
+
+ $this->e_height = $this->font_size + E_PADD*2;
+ $h = $e_list_ref->GetLevelHeight();
+
+ $e = $e_list_ref->GetFirst();
+ $this->CalcElementWidth( $e );
+
+ $w_px = $this->e_list->GetElementWidth( $e->id ) + B_SIDE * 2;
+ $h_px = $h * $this->e_height + ($h-1) * (V_SPACE + $fontsize) + B_TOPBOT * 2;;
+
+ $this->height = $h_px;
+ $this->width = $w_px;
+
+ }
+
+ function Draw()
+ {
+ $this->svgHeader();
+ $this->parseList();
+ $this->svgFooter();
+
+ print( $this->xml );
+ }
+
+ // ----------------------------------------------------------------------
+ // PRIVATE FUNCTIONS
+ // ----------------------------------------------------------------------
+
+ // Image dimensions
+ var $height = 0;
+ var $width = 0;
+
+ // Element dimensions
+ var $e_width = E_WIDTH;
+ var $e_height = 50;
+
+ // Element list
+ var $e_list;
+
+ // Font settings
+ var $font = "Vera.ttf";
+ var $font_size = 10;
+
+ // Options
+ var $antialias = TRUE;
+ var $triangles = TRUE;
+ var $color = TRUE;
+
+ // XML output
+ var $xml = "";
+
+ // Add the element into the tree (draw it)
+ function drawElement( $x, $y, $w, $string, $type )
+ {
+ // Calculate element dimensions and position
+
+ $top = $this->row2Px( $y );
+ $left = $x + B_SIDE;
+ $bottom = $top + $this->e_height;
+ $right = $left + $w;
+
+ // Draw element frame (for debugging)
+
+ if ( isset( $_GET['frame'] ) )
+ {
+ $style = "style=\"fill:rgb(255,255,255); stroke-width: 1; stroke:rgb(0,0,0);\"";
+ $this->xml .= sprintf( "<rect %s x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
+ $style, $left, $top, $right-$left, $bottom-$top );
+ }
+
+ // Select apropriate color
+
+ if ( $this->color )
+ {
+ $col = "blue";
+ if ( ETYPE_LEAF == $type )
+ $col = "red";
+
+ if ( substr( $string, 0, 1 ) == "<"
+ && substr( $string, strlen( $string ) - 1, 1 ) == ">" )
+ $col = "green";
+ } else {
+ $col = "black";
+ }
+
+ // Split the string into the main part and the
+ // subscript part of the element (if any)
+
+ $main = $string;
+ $sub = "";
+
+ $parts = split( "_", $string, 2 );
+ if ( count( $parts ) > 1 )
+ {
+ $main = $parts[0];
+ $sub = str_replace( "_", " ", $parts[1] );
+ }
+
+ // Calculate text size for the main and the
+ // subscript part of the element
+
+ $main_width = ImgGetTxtWidth( $main, $this->font, $this->font_size/2 );
+ $sub_width = ImgGetTxtWidth( $sub, $this->font, $this->font_size/2-2 );
+
+ // Center text in the element
+
+ $txt_width = $main_width + $sub_width;
+ $txt_pos = $left + ($right - $left) / 2 - $txt_width / 2;
+
+ // Draw main text
+
+ $style=sprintf( "style=\"fill: %s; font-size: %dpx;\"", $col, $this->font_size );
+
+ $this->xml .= sprintf( "<text %s x=\"%d\" y=\"%d\">%s</text>\n",
+ $style, $txt_pos, $top+($this->e_height-5), htmlentities( $main ) );
+
+ // Draw subscript text
+
+ if ( strlen( $sub ) > 0 )
+ {
+ $style=sprintf( "style=\"fill: %s; font-size: %dpx;\"", $col, $this->font_size+2 );
+
+ $this->xml .= sprintf( "<text %s x=\"%d\" y=\"%d\">%s</text>\n",
+ $style, $txt_pos+$main_width+1, $top+($this->e_height-2), htmlentities( $sub ));
+ }
+ }
+
+ // Draw a line between child/parent elements
+ function linetoParent( $fromX, $fromY, $fromW, $toX, $toW )
+ {
+ if ( $fromY == 0 )
+ return;
+
+ $fromTop = $this->row2Px( $fromY );
+ $fromLeft = $fromX + $fromW / 2 + B_SIDE;
+
+ $toBot = $this->row2Px( $fromY-1 ) + $this->e_height;
+ $toLeft = $toX + $toW / 2 + B_SIDE;
+
+ $style = "style=\"stroke:rgb(0,0,0);stroke-width:1;\"";
+
+ $this->xml .= sprintf( "<line %s x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
+ $style, $fromLeft, $fromTop, $toLeft, $toBot );
+ }
+
+ // Draw a triangle between child/parent elements
+ function triangletoParent( $fromX, $fromY, $fromW, $toW, $textW )
+ {
+ if ( $fromY == 0 )
+ return;
+
+ $toX = $fromX;
+
+ $fromTop = $this->row2Px( $fromY );
+ $fromCenter = $fromX + $fromW / 2 + B_SIDE;
+
+ $fromLeft1 = $fromCenter + $textW / 2 ;
+ $fromLeft2 = $fromCenter - $textW / 2 ;
+
+ $toBot = $this->row2Px( $fromY-1 ) + $this->e_height;
+ $toLeft = $toX + $toW / 2 + B_SIDE;
+
+ $style = "style=\"fill: white; stroke: black; stroke-width: 1;\"";
+
+ $this->xml .= sprintf( "<polygon %s points=\"%d %d %d %d %d %d\" />\n",
+ $style, $fromLeft1, $fromTop, $toLeft, $toBot, $fromLeft2, $fromTop );
+ }
+
+ // If a node element text is wider than the sum of it's
+ // child elements, then the child elements need to
+ // be resized to even out the space. This function
+ // recurses down the a child tree and sizes the
+ // children appropriately.
+ function fixChildSize( $id, $current, $target )
+ {
+ $e_list = &$this->e_list;
+ $children = $e_list->GetChildren( $id );
+
+ $e_list->SetElementWidth( $id, $target );
+
+ if ( count( $children ) > 0 )
+ {
+ $delta = $target - $current;
+ $target_delta = $delta / count( $children );
+
+ foreach( $children as $child )
+ {
+ $child_width = $e_list->GetElementWidth( $child );
+ $this->fixChildSize( $child, $child_width, $child_width + $target_delta );
+ }
+ }
+ }
+
+ // Calculate the width of the element. If the element is
+ // a node, the calculation will be performed recursively
+ // for all child elements.
+ function calcElementWidth( &$e )
+ {
+ $w = 0;
+ $e_list = &$this->e_list;
+
+ $children = $e_list->GetChildren( $e->id );
+
+ if ( count( $children ) == 0 )
+ {
+ $w = ImgGetTxtWidth( $e->content, $this->font, $this->font_size ) + E_PADD*2;
+ } else {
+ foreach( $children as $child )
+ {
+ $child_e = $e_list->GetID( $child );
+ $w += $this->calcElementWidth( $child_e );
+ }
+
+ $tw = ImgGetTxtWidth( $e->content, $this->font, $this->font_size ) + E_PADD*2;
+ if ( $tw > $w )
+ {
+ $this->fixChildSize( $e->id, $w, $tw );
+ $w = $tw;
+ }
+ }
+
+ $e_list->SetElementWidth( $e->id, $w );
+ return $w;
+ }
+
+ // Parse the elements in the list top to bottom and
+ // draw the elements into the image.
+ // As we it iterate through the levels, the element
+ // indentation is calculated.
+ function parseList()
+ {
+ $e_list = &$this->e_list;
+
+ // Calc element list recursively....
+
+ $e_arr = $e_list->GetElements();
+
+ $h = $e_list->GetLevelHeight();
+
+ for( $i=0; $i<$h; $i++ )
+ {
+ $x = 0;
+
+ for( $j=0; $j<count( $e_arr ); $j++ )
+ {
+ if ( $e_arr[$j]->level == $i )
+ {
+ $cw = $e_list->GetElementWidth( $e_arr[$j]->id );
+ $parent_indent = $e_list->GetIndent( $e_arr[$j]->parent );
+
+ if ( $x < $parent_indent )
+ $x = $parent_indent;
+
+ $e_list->SetIndent( $e_arr[$j]->id, $x );
+
+ $this->drawElement( $x, $i, $cw, $e_arr[$j]->