preparation release
This commit is contained in:
commit
f5e3a62ee8
196 changed files with 64314 additions and 0 deletions
11
AUTHORS
Normal file
11
AUTHORS
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
N:Johann Dréo
|
||||
P:nojhan
|
||||
E:nojhan@gmail.com
|
||||
D:2007-11
|
||||
C:Code initial, mainteneur
|
||||
|
||||
N:Simon Leblanc
|
||||
P:Simon
|
||||
E:contact@leblanc-simon.eu
|
||||
D:2007-12
|
||||
C:Patch internationalisation
|
||||
340
COPYING
Normal file
340
COPYING
Normal file
|
|
@ -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.
|
||||
798
HTML/Template/Flexy.php
Normal file
798
HTML/Template/Flexy.php
Normal file
|
|
@ -0,0 +1,798 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// | Original Author: Wolfram Kriesing <wolfram@kriesing.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
/**
|
||||
* @package HTML_Template_Flexy
|
||||
*/
|
||||
// prevent disaster when used with xdebug!
|
||||
@ini_set('xdebug.max_nesting_level', 1000);
|
||||
|
||||
/*
|
||||
* Global variable - used to store active options when compiling a template.
|
||||
*/
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY'] = array();
|
||||
|
||||
// ERRORS:
|
||||
|
||||
define('HTML_TEMPLATE_FLEXY_ERROR_SYNTAX',-1); // syntax error in template.
|
||||
define('HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS',-2); // bad arguments to methods.
|
||||
define('HTML_TEMPLATE_FLEXY_ERROR_FILE',-2); // file access problem
|
||||
|
||||
define('HTML_TEMPLATE_FLEXY_ERROR_RETURN',1); // RETURN ERRORS
|
||||
define('HTML_TEMPLATE_FLEXY_ERROR_DIE',8); // FATAL DEATH
|
||||
/**
|
||||
* A Flexible Template engine - based on simpletemplate
|
||||
*
|
||||
* @abstract Long Description
|
||||
* Have a look at the package description for details.
|
||||
*
|
||||
* usage:
|
||||
* $template = new HTML_Template_Flexy($options);
|
||||
* $template->compiler('/name/of/template.html');
|
||||
* $data =new StdClass
|
||||
* $data->text = 'xxxx';
|
||||
* $template->outputObject($data,$elements)
|
||||
*
|
||||
* Notes:
|
||||
* $options can be blank if so, it is read from
|
||||
* PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
*
|
||||
* the first argument to outputObject is an object (which could even be an
|
||||
* associateve array cast to an object) - I normally send it the controller class.
|
||||
* the seconde argument '$elements' is an array of HTML_Template_Flexy_Elements
|
||||
* eg. array('name'=> new HTML_Template_Flexy_Element('',array('value'=>'fred blogs'));
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @version $Id: Flexy.php,v 1.96 2005/12/20 01:45:06 alan_k Exp $
|
||||
*/
|
||||
class HTML_Template_Flexy
|
||||
{
|
||||
|
||||
/*
|
||||
* @var array $options the options for initializing the template class
|
||||
*/
|
||||
var $options = array(
|
||||
'compileDir' => '', // where do you want to write to.. (defaults to session.save_path)
|
||||
'templateDir' => '', // where are your templates
|
||||
|
||||
// where the template comes from. ------------------------------------------
|
||||
'multiSource' => false, // Allow same template to exist in multiple places
|
||||
// So you can have user themes....
|
||||
'templateDirOrder' => '', // set to 'reverse' to assume that first template
|
||||
|
||||
|
||||
'debug' => false, // prints a few messages
|
||||
|
||||
|
||||
// compiling conditions ------------------------------------------
|
||||
'compiler' => 'Flexy', // which compiler to use. (Flexy,Regex, Raw,Xipe)
|
||||
'forceCompile' => false, // only suggested for debugging
|
||||
|
||||
// regex Compiler ------------------------------------------
|
||||
'filters' => array(), // used by regex compiler.
|
||||
|
||||
// standard Compiler ------------------------------------------
|
||||
'nonHTML' => false, // dont parse HTML tags (eg. email templates)
|
||||
'allowPHP' => false, // allow PHP in template (use true=allow, 'delete' = remove it.)
|
||||
|
||||
'flexyIgnore' => 0, // turn on/off the tag to element code
|
||||
'numberFormat' => ",2,'.',','", // default number format {xxx:n} format = eg. 1,200.00
|
||||
|
||||
'url_rewrite' => '', // url rewriting ability:
|
||||
// eg. "images/:test1/images/,js/:test1/js"
|
||||
// changes href="images/xxx" to href="test1/images/xxx"
|
||||
// and src="js/xxx.js" to src="test1/js/xxx.js"
|
||||
|
||||
'compileToString' => false, // should the compiler return a string
|
||||
// rather than writing to a file.
|
||||
'privates' => false, // allow access to _variables (eg. suido privates
|
||||
'globals' => false, // allow access to _GET/_POST/_REQUEST/GLOBALS/_COOKIES/_SESSION
|
||||
|
||||
'globalfunctions' => false, // allow GLOBALS.date(#d/m/Y#) to have access to all PHP's methods
|
||||
// warning dont use unless you trust the template authors
|
||||
// exec() becomes exposed.
|
||||
|
||||
// get text/transalation suppport ------------------------------------------
|
||||
// (flexy compiler only)
|
||||
'locale' => 'en', // works with gettext or File_Gettext
|
||||
'textdomain' => '', // for gettext emulation with File_Gettext
|
||||
// eg. 'messages' (or you can use the template name.
|
||||
'textdomainDir' => '', // eg. /var/www/site.com/locale
|
||||
// so the french po file is:
|
||||
// /var/www/site.com/local/fr/LC_MESSAGE/{textdomain}.po
|
||||
|
||||
'Translation2' => false, // to make Translation2 a provider.
|
||||
// rather than gettext.
|
||||
// set to:
|
||||
// 'Translation2' => array(
|
||||
// 'driver' => 'dataobjectsimple',
|
||||
// 'options' => array()
|
||||
// );
|
||||
// or the slower way..
|
||||
// = as it requires loading the code..
|
||||
//
|
||||
// 'Translation2' => new Translation2('dataobjectsimple','')
|
||||
|
||||
|
||||
'charset' => 'ISO-8859-1', // charset used with htmlspecialchars to render data.
|
||||
// experimental
|
||||
|
||||
// output options ------------------------------------------
|
||||
'strict' => false, // All elements in the template must be defined -
|
||||
// makes php E_NOTICE warnings appear when outputing template.
|
||||
|
||||
'fatalError' => HTML_TEMPLATE_FLEXY_ERROR_DIE, // default behavior is to die on errors in template.
|
||||
|
||||
'plugins' => array(), // load classes to be made available via the plugin method
|
||||
// eg. = array('Savant') - loads the Savant methods.
|
||||
// = array('MyClass_Plugins' => 'MyClass/Plugins.php')
|
||||
// Class, and where to include it from..
|
||||
);
|
||||
/**
|
||||
* The compiled template filename (Full path)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $compiledTemplate;
|
||||
/**
|
||||
* The source template filename (Full path)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
var $currentTemplate;
|
||||
|
||||
/**
|
||||
* The getTextStrings Filename
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $getTextStringsFile;
|
||||
/**
|
||||
* The serialized elements array file.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $elementsFile;
|
||||
|
||||
|
||||
/**
|
||||
* Array of HTML_elements which is displayed on the template
|
||||
*
|
||||
* Technically it's private (eg. only the template uses it..)
|
||||
*
|
||||
*
|
||||
* @var array of HTML_Template_Flexy_Elements
|
||||
* @access private
|
||||
*/
|
||||
var $elements = array();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Initializes the Template engine, for each instance, accepts options or
|
||||
* reads from PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
*
|
||||
* @access public
|
||||
* @param array $options (Optional)
|
||||
*/
|
||||
|
||||
function HTML_Template_Flexy( $options=array() )
|
||||
{
|
||||
|
||||
$baseoptions = array();
|
||||
if (class_exists('PEAR')) {
|
||||
$baseoptions = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
}
|
||||
if ($baseoptions ) {
|
||||
foreach( $baseoptions as $key=>$aOption) {
|
||||
$this->options[$key] = $aOption;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $options as $key=>$aOption) {
|
||||
$this->options[$key] = $aOption;
|
||||
}
|
||||
|
||||
$filters = $this->options['filters'];
|
||||
if (is_string($filters)) {
|
||||
$this->options['filters']= explode(',',$filters);
|
||||
}
|
||||
|
||||
if (is_string($this->options['templateDir'])) {
|
||||
$this->options['templateDir'] = explode(PATH_SEPARATOR,$this->options['templateDir'] );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* compile the template
|
||||
*
|
||||
* @access public
|
||||
* @version 01/12/03
|
||||
* @author Wolfram Kriesing <wolfram@kriesing.de>
|
||||
* @param string $file relative to the 'templateDir' which you set when calling the constructor
|
||||
* @return boolean true on success. (or string, if compileToString) PEAR_Error on failure..
|
||||
*/
|
||||
function compile( $file )
|
||||
{
|
||||
if (!$file) {
|
||||
return $this->raiseError('HTML_Template_Flexy::compile no file selected',
|
||||
HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if (!@$this->options['locale']) {
|
||||
$this->options['locale']='en';
|
||||
}
|
||||
|
||||
|
||||
//Remove the slash if there is one in front, just to be safe.
|
||||
$file = ltrim($file,DIRECTORY_SEPARATOR);
|
||||
|
||||
|
||||
if (strpos($file,'#')) {
|
||||
list($file,$this->options['output.block']) = explode('#', $file);
|
||||
}
|
||||
|
||||
$parts = array();
|
||||
$tmplDirUsed = false;
|
||||
|
||||
// PART A mulitlanguage support: ( part B is gettext support in the engine..)
|
||||
// - user created language version of template.
|
||||
// - compile('abcdef.html') will check for compile('abcdef.en.html')
|
||||
// (eg. when locale=en)
|
||||
|
||||
$this->currentTemplate = false;
|
||||
|
||||
if (preg_match('/(.*)(\.[a-z]+)$/i',$file,$parts)) {
|
||||
$newfile = $parts[1].'.'.$this->options['locale'] .$parts[2];
|
||||
foreach ($this->options['templateDir'] as $tmplDir) {
|
||||
if (@!file_exists($tmplDir . DIRECTORY_SEPARATOR .$newfile)) {
|
||||
continue;
|
||||
}
|
||||
$file = $newfile;
|
||||
$this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR .$newfile;
|
||||
$tmplDirUsed = $tmplDir;
|
||||
}
|
||||
}
|
||||
|
||||
// look in all the posible locations for the template directory..
|
||||
if ($this->currentTemplate === false) {
|
||||
$dirs = array_unique($this->options['templateDir']);
|
||||
if ($this->options['templateDirOrder'] == 'reverse') {
|
||||
$dirs = array_reverse($dirs);
|
||||
}
|
||||
foreach ($dirs as $tmplDir) {
|
||||
if (!@file_exists($tmplDir . DIRECTORY_SEPARATOR . $file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!$this->options['multiSource'] && ($this->currentTemplate !== false)) {
|
||||
return $this->raiseError("You have more than one template Named {$file} in your paths, found in both".
|
||||
"<BR>{$this->currentTemplate }<BR>{$tmplDir}" . DIRECTORY_SEPARATOR . $file,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS , HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
|
||||
}
|
||||
|
||||
$this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR . $file;
|
||||
$tmplDirUsed = $tmplDir;
|
||||
}
|
||||
}
|
||||
if ($this->currentTemplate === false) {
|
||||
// check if the compile dir has been created
|
||||
return $this->raiseError("Could not find Template {$file} in any of the directories<br>" .
|
||||
implode("<BR>",$this->options['templateDir']) ,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
|
||||
// Savant compatible compiler
|
||||
|
||||
if ($this->options['compiler'] == 'Raw') {
|
||||
$this->compiledTemplate = $this->currentTemplate;
|
||||
$this->debug("Using Raw Compiler");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// now for the compile target
|
||||
|
||||
//If you are working with mulitple source folders and $options['multiSource'] is set
|
||||
//the template folder will be:
|
||||
// compiled_tempaltes/{templatedir_basename}_{md5_of_dir}/
|
||||
|
||||
|
||||
$compileSuffix = ((count($this->options['templateDir']) > 1) && $this->options['multiSource']) ?
|
||||
DIRECTORY_SEPARATOR .basename($tmplDirUsed) . '_' .md5($tmplDirUsed) : '';
|
||||
|
||||
|
||||
$compileDest = @$this->options['compileDir'];
|
||||
|
||||
$isTmp = false;
|
||||
// Use a default compile directory if one has not been set.
|
||||
if (!@$compileDest) {
|
||||
// Use session.save_path + 'compiled_templates_' + md5(of sourcedir)
|
||||
$compileDest = ini_get('session.save_path') . DIRECTORY_SEPARATOR . 'flexy_compiled_templates';
|
||||
if (!file_exists($compileDest)) {
|
||||
require_once 'System.php';
|
||||
System::mkdir(array('-p',$compileDest));
|
||||
}
|
||||
$isTmp = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// we generally just keep the directory structure as the application uses it,
|
||||
// so we dont get into conflict with names
|
||||
// if we have multi sources we do md5 the basedir..
|
||||
|
||||
|
||||
$base = $compileDest . $compileSuffix . DIRECTORY_SEPARATOR .$file;
|
||||
$fullFile = $this->compiledTemplate = $base .'.'.$this->options['locale'].'.php';
|
||||
$this->getTextStringsFile = $base .'.gettext.serial';
|
||||
$this->elementsFile = $base .'.elements.serial';
|
||||
if (isset($this->options['output.block'])) {
|
||||
$this->compiledTemplate .= '#'.$this->options['output.block'];
|
||||
}
|
||||
|
||||
$recompile = false;
|
||||
|
||||
$isuptodate = file_exists($this->compiledTemplate) ?
|
||||
(filemtime($this->currentTemplate) == filemtime( $this->compiledTemplate)) : 0;
|
||||
|
||||
if( @$this->options['forceCompile'] || !$isuptodate ) {
|
||||
$recompile = true;
|
||||
} else {
|
||||
$this->debug("File looks like it is uptodate.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if( !@is_dir($compileDest) || !is_writeable($compileDest)) {
|
||||
require_once 'System.php';
|
||||
|
||||
System::mkdir(array('-p',$compileDest));
|
||||
}
|
||||
if( !@is_dir($compileDest) || !is_writeable($compileDest)) {
|
||||
return $this->raiseError( "can not write to 'compileDir', which is <b>'$compileDest'</b><br>".
|
||||
"Please give write and enter-rights to it",
|
||||
HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if (!file_exists(dirname($this->compiledTemplate))) {
|
||||
require_once 'System.php';
|
||||
System::mkdir(array('-p','-m', 0770, dirname($this->compiledTemplate)));
|
||||
}
|
||||
|
||||
// Compile the template in $file.
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler.php';
|
||||
$compiler = HTML_Template_Flexy_Compiler::factory($this->options);
|
||||
$ret = $compiler->compile($this);
|
||||
if (is_a($ret,'PEAR_Error')) {
|
||||
return $this->raiseError('HTML_Template_Flexy fatal error:' .$ret->message,
|
||||
$ret->code, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
return $ret;
|
||||
|
||||
//return $this->$method();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* compiles all templates
|
||||
* Used for offline batch compilation (eg. if your server doesn't have write access to the filesystem).
|
||||
*
|
||||
* @access public
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
*
|
||||
*/
|
||||
function compileAll($dir = '',$regex='/.html$/')
|
||||
{
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler.php';
|
||||
$c = new HTML_Template_Flexy_Compiler;
|
||||
$c->compileAll($this,$dir,$regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs an object as $t
|
||||
*
|
||||
* for example the using simpletags the object's variable $t->test
|
||||
* would map to {test}
|
||||
*
|
||||
* @version 01/12/14
|
||||
* @access public
|
||||
* @author Alan Knowles
|
||||
* @param object to output
|
||||
* @param array HTML_Template_Flexy_Elements (or any object that implements toHtml())
|
||||
* @return none
|
||||
*/
|
||||
|
||||
|
||||
function outputObject(&$t,$elements=array())
|
||||
{
|
||||
if (!is_array($elements)) {
|
||||
return $this->raiseError(
|
||||
'second Argument to HTML_Template_Flexy::outputObject() was an '.gettype($elements) . ', not an array',
|
||||
HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS ,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
if (@$this->options['debug']) {
|
||||
echo "output $this->compiledTemplate<BR>";
|
||||
}
|
||||
|
||||
// this may disappear later it's a Backwards Compatibility fudge to try
|
||||
// and deal with the first stupid design decision to not use a second argument
|
||||
// to the method.
|
||||
|
||||
if (count($this->elements) && !count($elements)) {
|
||||
$elements = $this->elements;
|
||||
}
|
||||
// end depreciated code
|
||||
|
||||
|
||||
$this->elements = $this->getElements();
|
||||
|
||||
// Overlay values from $elements to $this->elements (which is created from the template)
|
||||
// Remove keys with no corresponding value.
|
||||
foreach($elements as $k=>$v) {
|
||||
// Remove key-value pair from $this->elements if hasn't a value in $elements.
|
||||
if (!$v) {
|
||||
unset($this->elements[$k]);
|
||||
}
|
||||
// Add key-value pair to $this->$elements if it's not there already.
|
||||
if (!isset($this->elements[$k])) {
|
||||
$this->elements[$k] = $v;
|
||||
continue;
|
||||
}
|
||||
// Call the clever element merger - that understands form values and
|
||||
// how to display them...
|
||||
$this->elements[$k] = $this->mergeElement($this->elements[$k] ,$v);
|
||||
}
|
||||
//echo '<PRE>'; print_r(array($elements,$this->elements));
|
||||
|
||||
|
||||
// we use PHP's error handler to hide errors in the template.
|
||||
// use $options['strict'] - if you want to force declaration of
|
||||
// all variables in the template
|
||||
|
||||
|
||||
$_error_reporting = false;
|
||||
if (!$this->options['strict']) {
|
||||
$_error_reporting = error_reporting(E_ALL ^ E_NOTICE);
|
||||
}
|
||||
if (!is_readable($this->compiledTemplate)) {
|
||||
return $this->raiseError( "Could not open the template: <b>'{$this->compiledTemplate}'</b><BR>".
|
||||
"Please check the file permissions on the directory and file ",
|
||||
HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
// are we using the assign api!
|
||||
|
||||
if (isset($this->assign)) {
|
||||
if (!$t) {
|
||||
$t = (object) $this->assign->variables;
|
||||
}
|
||||
extract($this->assign->variables);
|
||||
foreach(array_keys($this->assign->references) as $_k) {
|
||||
$$_k = &$this->assign->references[$_k];
|
||||
}
|
||||
}
|
||||
// used by Flexy Elements etc..
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['options'] = $this->options;
|
||||
|
||||
include($this->compiledTemplate);
|
||||
|
||||
// Return the error handler to its previous state.
|
||||
|
||||
if ($_error_reporting !== false) {
|
||||
error_reporting($_error_reporting);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Outputs an object as $t, buffers the result and returns it.
|
||||
*
|
||||
* See outputObject($t) for more details.
|
||||
*
|
||||
* @version 01/12/14
|
||||
* @access public
|
||||
* @author Alan Knowles
|
||||
* @param object object to output as $t
|
||||
* @return string - result
|
||||
*/
|
||||
function bufferedOutputObject(&$t,$elements=array())
|
||||
{
|
||||
ob_start();
|
||||
$this->outputObject($t,$elements);
|
||||
$data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* static version which does new, compile and output all in one go.
|
||||
*
|
||||
* See outputObject($t) for more details.
|
||||
*
|
||||
* @version 01/12/14
|
||||
* @access public
|
||||
* @author Alan Knowles
|
||||
* @param object object to output as $t
|
||||
* @param filename of template
|
||||
* @return string - result
|
||||
*/
|
||||
function &staticQuickTemplate($file,&$t)
|
||||
{
|
||||
$template = new HTML_Template_Flexy;
|
||||
$template->compile($file);
|
||||
$template->outputObject($t);
|
||||
}
|
||||
|
||||
/**
|
||||
* if debugging is on, print the debug info to the screen
|
||||
*
|
||||
* @access public
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
* @param string $string output to display
|
||||
* @return none
|
||||
*/
|
||||
function debug($string)
|
||||
{
|
||||
|
||||
if (is_a($this,'HTML_Template_Flexy')) {
|
||||
if (!$this->options['debug']) {
|
||||
return;
|
||||
}
|
||||
} else if (!@$GLOBALS['_HTML_TEMPLATE_FLEXY']['debug']) {
|
||||
return;
|
||||
}
|
||||
echo "<PRE><B>FLEXY DEBUG:</B> $string</PRE>";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A general Utility method that merges HTML_Template_Flexy_Elements
|
||||
* Static method - no native debug avaiable..
|
||||
*
|
||||
* @param HTML_Template_Flexy_Element $original (eg. from getElements())
|
||||
* @param HTML_Template_Flexy_Element $new (with data to replace/merge)
|
||||
* @return HTML_Template_Flexy_Element the combined/merged data.
|
||||
* @static
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function mergeElement($original,$new)
|
||||
{
|
||||
|
||||
// no original - return new
|
||||
if (!$original) {
|
||||
return $new;
|
||||
}
|
||||
// no new - return original
|
||||
if (!$new) {
|
||||
return $original;
|
||||
}
|
||||
// If the properties of $original differ from those of $new and
|
||||
// they are set on $new, set them to $new's. Otherwise leave them
|
||||
// as they are.
|
||||
|
||||
if ($new->tag && ($new->tag != $original->tag)) {
|
||||
$original->tag = $new->tag;
|
||||
}
|
||||
|
||||
if ($new->override !== false) {
|
||||
$original->override = $new->override;
|
||||
}
|
||||
|
||||
if (count($new->children)) {
|
||||
//echo "<PRE> COPY CHILDREN"; print_r($from->children);
|
||||
$original->children = $new->children;
|
||||
}
|
||||
|
||||
if (is_array($new->attributes)) {
|
||||
|
||||
foreach ($new->attributes as $key => $value) {
|
||||
$original->attributes[$key] = $value;
|
||||
}
|
||||
}
|
||||
// originals never have prefixes or suffixes..
|
||||
$original->prefix = $new->prefix;
|
||||
$original->suffix = $new->suffix;
|
||||
|
||||
if ($new->value !== null) {
|
||||
$original->setValue($new->value);
|
||||
}
|
||||
|
||||
return $original;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an array of elements from the template
|
||||
*
|
||||
* All <form> elements (eg. <input><textarea) etc.) and anything marked as
|
||||
* dynamic (eg. flexy:dynamic="yes") are converted in to elements
|
||||
* (simliar to XML_Tree_Node)
|
||||
* you can use this to build the default $elements array that is used by
|
||||
* outputObject() - or just create them and they will be overlayed when you
|
||||
* run outputObject()
|
||||
*
|
||||
*
|
||||
* @return array of HTML_Template_Flexy_Element sDescription
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function getElements() {
|
||||
|
||||
if ($this->elementsFile && file_exists($this->elementsFile)) {
|
||||
require_once 'HTML/Template/Flexy/Element.php';
|
||||
return unserialize(file_get_contents($this->elementsFile));
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lazy loading of PEAR, and the error handler..
|
||||
* This should load HTML_Template_Flexy_Error really..
|
||||
*
|
||||
* @param string message
|
||||
* @param int error type.
|
||||
* @param int an equivalant to pear error return|die etc.
|
||||
*
|
||||
* @return object pear error.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function raiseError($message, $type = null, $fatal = HTML_TEMPLATE_FLEXY_ERROR_RETURN )
|
||||
{
|
||||
HTML_Template_Flexy::debug("<B>HTML_Template_Flexy::raiseError</B>$message");
|
||||
require_once 'PEAR.php';
|
||||
if (is_a($this,'HTML_Template_Flexy') && ($fatal == HTML_TEMPLATE_FLEXY_ERROR_DIE)) {
|
||||
// rewrite DIE!
|
||||
return PEAR::raiseError($message, $type, $this->options['fatalError']);
|
||||
}
|
||||
if (isset($GLOBALS['_HTML_TEMPLATE_FLEXY']['fatalError']) && ($fatal == HTML_TEMPLATE_FLEXY_ERROR_DIE)) {
|
||||
|
||||
return PEAR::raiseError($message, $type,$GLOBALS['_HTML_TEMPLATE_FLEXY']['fatalError']);
|
||||
}
|
||||
return PEAR::raiseError($message, $type, $fatal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Assign API -
|
||||
*
|
||||
* read the docs on HTML_Template_Flexy_Assign::assign()
|
||||
*
|
||||
* @param varargs ....
|
||||
*
|
||||
*
|
||||
* @return mixed PEAR_Error or true?
|
||||
* @access public
|
||||
* @see HTML_Template_Flexy_Assign::assign()
|
||||
* @status alpha
|
||||
*/
|
||||
|
||||
function setData() {
|
||||
require_once 'HTML/Template/Flexy/Assign.php';
|
||||
// load assigner..
|
||||
if (!isset($this->assign)) {
|
||||
$this->assign = new HTML_Template_Flexy_Assign;
|
||||
}
|
||||
return $this->assign->assign(func_get_args());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Assign API - by Reference
|
||||
*
|
||||
* read the docs on HTML_Template_Flexy_Assign::assign()
|
||||
*
|
||||
* @param key string
|
||||
* @param value mixed
|
||||
*
|
||||
* @return mixed PEAR_Error or true?
|
||||
* @access public
|
||||
* @see HTML_Template_Flexy_Assign::assign()
|
||||
* @status alpha
|
||||
*/
|
||||
|
||||
function setDataByRef($k,&$v) {
|
||||
require_once 'HTML/Template/Flexy/Assign.php';
|
||||
// load assigner..
|
||||
if (!isset($this->assign)) {
|
||||
$this->assign = new HTML_Template_Flexy_Assign;
|
||||
}
|
||||
$this->assign->assignRef($k,$v);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Plugin (used by templates as $this->plugin(...) or {this.plugin(#...#,#....#)}
|
||||
*
|
||||
* read the docs on HTML_Template_Flexy_Plugin()
|
||||
*
|
||||
* @param varargs ....
|
||||
*
|
||||
* @return mixed PEAR_Error or true?
|
||||
* @access public
|
||||
* @see HTML_Template_Flexy_Plugin
|
||||
* @status alpha
|
||||
*/
|
||||
function plugin() {
|
||||
require_once 'HTML/Template/Flexy/Plugin.php';
|
||||
// load pluginManager.
|
||||
if (!isset($this->plugin)) {
|
||||
$this->plugin = new HTML_Template_Flexy_Plugin;
|
||||
$this->plugin->flexy = &$this;
|
||||
}
|
||||
return $this->plugin->call(func_get_args());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* output / display ? - outputs an object, without copy by references..
|
||||
*
|
||||
* @param optional mixed object to output
|
||||
*
|
||||
* @return mixed PEAR_Error or true?
|
||||
* @access public
|
||||
* @see HTML_Template_Flexy::ouptutObject
|
||||
* @status alpha
|
||||
*/
|
||||
function output($object = false)
|
||||
{
|
||||
return $this->outputObject($object);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* render the template with data..
|
||||
*
|
||||
* @param optional mixed object to output
|
||||
*
|
||||
* @return mixed PEAR_Error or true?
|
||||
* @access public
|
||||
* @see HTML_Template_Flexy::ouptutObject
|
||||
* @status alpha
|
||||
*/
|
||||
function toString($object = false)
|
||||
{
|
||||
return $this->bufferedOutputObject($object);
|
||||
}
|
||||
|
||||
}
|
||||
204
HTML/Template/Flexy/Assign.php
Normal file
204
HTML/Template/Flexy/Assign.php
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: nobody <nobody@localhost> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Assign.php,v 1.5 2004/06/03 03:25:11 alan_k Exp $
|
||||
//
|
||||
// Provider for Assign API ( Eg. $flexy->assign(...) )
|
||||
//
|
||||
|
||||
define('HTML_TEMPLATE_FLEXY_ASSIGN_ERROR_INVALIDARGS', -100);
|
||||
|
||||
class HTML_Template_Flexy_Assign {
|
||||
|
||||
/**
|
||||
* The variables stored in the Assigner
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $variables = array();
|
||||
/**
|
||||
* The references stored in the Assigner
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $references = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Assigns a token-name and value to $this->_token_vars for use in a
|
||||
* template.
|
||||
*
|
||||
* There are three valid ways to assign values to a template.
|
||||
*
|
||||
* Form 1: $args[0] is a string and $args[1] is mixed. This means
|
||||
* $args[0] is a token name and $args[1] is the token value (which
|
||||
* allows objects, arrays, strings, numbers, or anything else).
|
||||
* $args[1] can be null, which means the corresponding token value in
|
||||
* the template will also be null.
|
||||
*
|
||||
* Form 2: $args[0] is an array and $args[1] is not set. Assign a
|
||||
* series of tokens where the key is the token name, and the value is
|
||||
* token value.
|
||||
*
|
||||
* Form 3: $args[0] is an object and $args[1] is not set. Assigns
|
||||
* copies of all object variables (properties) to tokens; the token
|
||||
* name and value is a copy of each object property and value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array|object $args[0] This param can be a string, an
|
||||
* array, or an object. If $args[0] is a string, it is the name of a
|
||||
* variable in the template. If $args[0] is an array, it must be an
|
||||
* associative array of key-value pairs where the key is a variable
|
||||
* name in the template and the value is the value for that variable
|
||||
* in the template. If $args[0] is an object, copies of its
|
||||
* properties will be assigned to the template.
|
||||
*
|
||||
* @param mixed $args[1] If $args[0] is an array or object, $args[1]
|
||||
* should not be set. Otherwise, a copy of $args[1] is assigned to a
|
||||
* template variable named after $args[0].
|
||||
*
|
||||
* @return bool|PEAR_Error Boolean true if all assignments were
|
||||
* committed, or a PEAR_Error object if there was an error.
|
||||
*
|
||||
* @throws SAVANT_ERROR_ASSIGN Unknown reason for error, probably
|
||||
* because you passed $args[1] when $args[0] is an array or object.
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
* @see assignRef()
|
||||
*
|
||||
* @see assignObject()
|
||||
*
|
||||
*/
|
||||
|
||||
function assign($args)
|
||||
{
|
||||
// in Form 1, $args[0] is a string name and $args[1] is mixed.
|
||||
// in Form 2, $args[0] is an associative array.
|
||||
// in Form 3, $args[0] is an object.
|
||||
|
||||
$count = count($args);
|
||||
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Now we assign variable copies.
|
||||
//
|
||||
|
||||
// form 1 (string name and mixed value)
|
||||
// don't check isset() on $args[1] becuase a 'null' is not set,
|
||||
// and we might want to pass a null.
|
||||
if (is_string($args[0]) && $count > 1) {
|
||||
if (isset($this->references[$args[0]])) {
|
||||
unset($this->references[$args[0]]);
|
||||
}
|
||||
// keep a copy in the token vars array
|
||||
$this->variables[$args[0]] = $args[1];
|
||||
|
||||
// done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// form 2 (assoc array)
|
||||
if (is_array($args[0]) && $count == 1) {
|
||||
|
||||
foreach ($args[0] as $key=>$val) {
|
||||
$this->assign($key, $val);
|
||||
}
|
||||
|
||||
// done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// form 3 (object props)
|
||||
if (is_object($args[0]) && $count == 1) {
|
||||
|
||||
// get the object properties
|
||||
$data = get_object_vars($args[0]);
|
||||
foreach ($data as $key=>$val) {
|
||||
$this->assign($key, $val);
|
||||
}
|
||||
|
||||
// done!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Final error catch. We should not have gotten to this point.
|
||||
//
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"invalid type sent to assign, ". print_r($args,true),
|
||||
HTML_TEMPLATE_FLEXY_ASSIGN_ERROR_INVALIDARGS
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Assign a token by reference. This allows you change variable
|
||||
* values within the template and have those changes reflected back
|
||||
* at the calling logic script. Works as with form 2 of assign().
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $name The template token-name for the reference.
|
||||
*
|
||||
* @param mixed &$ref The variable passed by-reference.
|
||||
*
|
||||
* @return bool|PEAR_Error Boolean true on success, or a PEAR_Error
|
||||
* on failure.
|
||||
*
|
||||
* @throws SAVANT_ERROR_ASSIGN_REF Unknown reason for error.
|
||||
*
|
||||
* @see assign()
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
* @see assignObject()
|
||||
*
|
||||
*/
|
||||
|
||||
function assignRef($name, &$ref)
|
||||
{
|
||||
// look for the proper case: name and variable
|
||||
if (is_string($name) && isset($ref)) {
|
||||
if (isset($this->variables[$name])) {
|
||||
unset($this->variables[$name]);
|
||||
}
|
||||
//
|
||||
// assign the token as a reference
|
||||
$this->references[$name] =& $ref;
|
||||
|
||||
// done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// final error catch
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"invalid type sent to assignRef, ". print_r($name,true),
|
||||
HTML_TEMPLATE_FLEXY_ASSIGN_ERROR_INVALIDARGS
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
161
HTML/Template/Flexy/Compiler.php
Normal file
161
HTML/Template/Flexy/Compiler.php
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Compiler.php,v 1.7 2004/07/08 04:56:30 alan_k Exp $
|
||||
//
|
||||
// Base Compiler Class (Interface)
|
||||
//
|
||||
|
||||
/**
|
||||
* Compiler Globals go here..
|
||||
* public (to it's children)
|
||||
*
|
||||
* @var array
|
||||
* @access public (to it's children)
|
||||
*/
|
||||
|
||||
$GLOBAL['_HTML_TEMPLATE_FLEXY_COMPILER'] = array();
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler {
|
||||
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $options;
|
||||
|
||||
/**
|
||||
* Factory constructor
|
||||
*
|
||||
* @param array options only ['compiler'] is used directly
|
||||
*
|
||||
* @return object The Compiler Object
|
||||
* @access public
|
||||
*/
|
||||
function factory($options)
|
||||
{
|
||||
if (empty($options['compiler'])) {
|
||||
$options['compiler'] = 'Flexy';
|
||||
}
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler/'.ucfirst( $options['compiler'] ) .'.php';
|
||||
$class = 'HTML_Template_Flexy_Compiler_'.$options['compiler'];
|
||||
$ret = new $class;
|
||||
$ret->options = $options;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The compile method.
|
||||
*
|
||||
* @param object HTML_Template_Flexy that is requesting the compile
|
||||
* @return object HTML_Template_Flexy
|
||||
* @return string to compile (if not using a file as the source)
|
||||
* @access public
|
||||
*/
|
||||
function compile(&$flexy,$string = false)
|
||||
{
|
||||
echo "No compiler implemented!";
|
||||
}
|
||||
|
||||
/**
|
||||
* Append HTML to compiled ouput
|
||||
* These are hooks for passing data to other processes
|
||||
*
|
||||
* @param string to append to compiled
|
||||
*
|
||||
* @return string to be output
|
||||
* @access public
|
||||
*/
|
||||
function appendHtml($string)
|
||||
{
|
||||
|
||||
return $string;
|
||||
}
|
||||
/**
|
||||
* Append PHP Code to compiled ouput
|
||||
* These are hooks for passing data to other processes
|
||||
*
|
||||
* @param string PHP code to append to compiled
|
||||
*
|
||||
* @return string to be output
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function appendPhp($string)
|
||||
{
|
||||
|
||||
return '<?php '.$string.'?>';
|
||||
}
|
||||
/**
|
||||
* Compile All templates in the
|
||||
* These are hooks for passing data to other processes
|
||||
*
|
||||
* @param string PHP code to append to compiled
|
||||
*
|
||||
* @return string to be output
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function compileAll(&$flexy, $dir = '',$regex='/.html$/')
|
||||
{
|
||||
$this->flexy = &$flexy;
|
||||
$this->compileDir($dir,$regex);
|
||||
}
|
||||
|
||||
|
||||
function compileDir($dir = '',$regex='/.html$/')
|
||||
{
|
||||
|
||||
|
||||
foreach ($this->flexy->options['templateDir'] as $base) {
|
||||
if (!file_exists($base . DIRECTORY_SEPARATOR . $dir)) {
|
||||
continue;
|
||||
}
|
||||
$dh = opendir($base . DIRECTORY_SEPARATOR . $dir);
|
||||
while (($name = readdir($dh)) !== false) {
|
||||
if (!$name) { // empty!?
|
||||
continue;
|
||||
}
|
||||
if ($name{0} == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($base . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $name)) {
|
||||
$this->compileDir($dir . DIRECTORY_SEPARATOR . $name,$regex);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match($regex,$name)) {
|
||||
continue;
|
||||
}
|
||||
//echo "Compiling $dir". DIRECTORY_SEPARATOR . "$name \n";
|
||||
$this->flexy->compile($dir . DIRECTORY_SEPARATOR . $name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
985
HTML/Template/Flexy/Compiler/Flexy.php
Normal file
985
HTML/Template/Flexy/Compiler/Flexy.php
Normal file
|
|
@ -0,0 +1,985 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Flexy.php,v 1.20 2005/10/25 02:21:16 alan_k Exp $
|
||||
//
|
||||
// Base Compiler Class
|
||||
// Standard 'Original Flavour' Flexy compiler
|
||||
|
||||
// this does the main conversion, (eg. for {vars and methods})
|
||||
// it relays into Compiler/Tag & Compiler/Flexy for tags and namespace handling.
|
||||
|
||||
|
||||
|
||||
|
||||
require_once 'HTML/Template/Flexy/Tokenizer.php';
|
||||
require_once 'HTML/Template/Flexy/Token.php';
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Flexy extends HTML_Template_Flexy_Compiler {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The current template (Full path)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $currentTemplate;
|
||||
/**
|
||||
* The compile method.
|
||||
*
|
||||
* @params object HTML_Template_Flexy
|
||||
* @params string|false string to compile of false to use a file.
|
||||
* @return string filename of template
|
||||
* @access public
|
||||
*/
|
||||
function compile(&$flexy, $string=false)
|
||||
{
|
||||
// read the entire file into one variable
|
||||
|
||||
// note this should be moved to new HTML_Template_Flexy_Token
|
||||
// and that can then manage all the tokens in one place..
|
||||
global $_HTML_TEMPLATE_FLEXY_COMPILER;
|
||||
|
||||
$this->currentTemplate = $flexy->currentTemplate;
|
||||
|
||||
|
||||
$gettextStrings = &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
|
||||
$gettextStrings = array(); // reset it.
|
||||
|
||||
if (@$this->options['debug']) {
|
||||
echo "compiling template $flexy->currentTemplate<BR>";
|
||||
|
||||
}
|
||||
|
||||
// reset the elements.
|
||||
$flexy->_elements = array();
|
||||
|
||||
// replace this with a singleton??
|
||||
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'] = $this->options;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'] = array();
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'] = $flexy->currentTemplate;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] = '';
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['compiledTemplate']= $flexy->compiledTemplate;
|
||||
|
||||
|
||||
// initialize Translation 2, and
|
||||
$this->initializeTranslator();
|
||||
|
||||
|
||||
// load the template!
|
||||
$data = $string;
|
||||
$res = false;
|
||||
if ($string === false) {
|
||||
$data = file_get_contents($flexy->currentTemplate);
|
||||
}
|
||||
|
||||
// PRE PROCESS {_(.....)} translation markers.
|
||||
if (strpos($data, '{_(') !== false) {
|
||||
$data = $this->preProcessTranslation($data);
|
||||
}
|
||||
|
||||
// Tree generation!!!
|
||||
|
||||
|
||||
|
||||
if (!$this->options['forceCompile'] && isset($_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)])) {
|
||||
$res = $_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)];
|
||||
} else {
|
||||
|
||||
|
||||
$tokenizer = new HTML_Template_Flexy_Tokenizer($data);
|
||||
$tokenizer->fileName = $flexy->currentTemplate;
|
||||
|
||||
|
||||
|
||||
//$tokenizer->debug=1;
|
||||
$tokenizer->options['ignore_html'] = $this->options['nonHTML'];
|
||||
|
||||
|
||||
require_once 'HTML/Template/Flexy/Token.php';
|
||||
$res = HTML_Template_Flexy_Token::buildTokens($tokenizer);
|
||||
if (is_a($res, 'PEAR_Error')) {
|
||||
return $res;
|
||||
}
|
||||
$_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)] = $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// technically we shouldnt get here as we dont cache errors..
|
||||
if (is_a($res, 'PEAR_Error')) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
// turn tokens into Template..
|
||||
|
||||
$data = $res->compile($this);
|
||||
|
||||
if (is_a($data, 'PEAR_Error')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] . $data;
|
||||
|
||||
if ( $flexy->options['debug'] > 1) {
|
||||
echo "<B>Result: </B><PRE>".htmlspecialchars($data)."</PRE><BR>\n";
|
||||
}
|
||||
|
||||
if ($this->options['nonHTML']) {
|
||||
$data = str_replace("?>\n", "?>\n\n", $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// at this point we are into writing stuff...
|
||||
if ($flexy->options['compileToString']) {
|
||||
if ( $flexy->options['debug']) {
|
||||
echo "<B>Returning string:<BR>\n";
|
||||
}
|
||||
|
||||
$flexy->elements = $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// error checking?
|
||||
$file = $flexy->compiledTemplate;
|
||||
if (isset($flexy->options['output.block'])) {
|
||||
list($file, $part) = explode('#', $file);
|
||||
}
|
||||
|
||||
if( ($cfp = fopen($file, 'w')) ) {
|
||||
if ($flexy->options['debug']) {
|
||||
echo "<B>Writing: </B>$file<BR>\n";
|
||||
}
|
||||
fwrite($cfp, $data);
|
||||
fclose($cfp);
|
||||
|
||||
chmod($file, 0775);
|
||||
// make the timestamp of the two items match.
|
||||
clearstatcache();
|
||||
touch($file, filemtime($flexy->currentTemplate));
|
||||
if ($file != $flexy->compiledTemplate) {
|
||||
chmod($flexy->compiledTemplate, 0775);
|
||||
// make the timestamp of the two items match.
|
||||
clearstatcache();
|
||||
touch($flexy->compiledTemplate, filemtime($flexy->currentTemplate));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::failed to write to '.$flexy->compiledTemplate,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
// gettext strings
|
||||
|
||||
if (file_exists($flexy->getTextStringsFile)) {
|
||||
unlink($flexy->getTextStringsFile);
|
||||
}
|
||||
|
||||
if($gettextStrings && ($cfp = fopen( $flexy->getTextStringsFile, 'w') ) ) {
|
||||
|
||||
fwrite($cfp, serialize(array_unique($gettextStrings)));
|
||||
fclose($cfp);
|
||||
chmod($flexy->getTextStringsFile, 0664);
|
||||
}
|
||||
|
||||
// elements
|
||||
if (file_exists($flexy->elementsFile)) {
|
||||
unlink($flexy->elementsFile);
|
||||
}
|
||||
|
||||
if( $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'] &&
|
||||
($cfp = fopen( $flexy->elementsFile, 'w') ) ) {
|
||||
fwrite($cfp, serialize( $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']));
|
||||
fclose($cfp);
|
||||
chmod($flexy->elementsFile, 0664);
|
||||
// now clear it.
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initilalize the translation methods.
|
||||
*
|
||||
* Loads Translation2 if required.
|
||||
*
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function initializeTranslator() {
|
||||
|
||||
if (is_array($this->options['Translation2'])) {
|
||||
require_once 'Translation2.php';
|
||||
$this->options['Translation2'] = &Translation2::factory(
|
||||
$this->options['Translation2']['driver'],
|
||||
isset($this->options['Translation2']['options']) ? $this->options['Translation2']['options'] : array(),
|
||||
isset($this->options['Translation2']['params']) ? $this->options['Translation2']['params'] : array()
|
||||
);
|
||||
}
|
||||
|
||||
if (is_a($this->options['Translation2'], 'Translation2')) {
|
||||
$this->options['Translation2']->setLang($this->options['locale']);
|
||||
// fixme - needs to be more specific to which template to use..
|
||||
foreach ($this->options['templateDir'] as $tt) {
|
||||
$n = basename($this->currentTemplate);
|
||||
if (substr($this->currentTemplate, 0, strlen($tt)) == $tt) {
|
||||
$n = substr($this->currentTemplate, strlen($tt)+1);
|
||||
}
|
||||
//echo $n;
|
||||
}
|
||||
$this->options['Translation2']->setPageID($n);
|
||||
} else {
|
||||
setlocale(LC_ALL, $this->options['locale']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* do the early tranlsation of {_(......)_} text
|
||||
*
|
||||
*
|
||||
* @param input string
|
||||
* @return output string
|
||||
* @access public
|
||||
*/
|
||||
function preProcessTranslation($data) {
|
||||
global $_HTML_TEMPLATE_FLEXY_COMPILER;
|
||||
$matches = array();
|
||||
$lmatches = explode ('{_(', $data);
|
||||
array_shift($lmatches);
|
||||
// shift the first..
|
||||
foreach ($lmatches as $k) {
|
||||
if (false === strpos($k, ')_}')) {
|
||||
continue;
|
||||
}
|
||||
$x = explode(')_}', $k);
|
||||
$matches[] = $x[0];
|
||||
}
|
||||
|
||||
|
||||
//echo '<PRE>';print_r($matches);
|
||||
// we may need to do some house cleaning here...
|
||||
$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'] = $matches;
|
||||
|
||||
|
||||
// replace them now..
|
||||
// ** leaving in the tag (which should be ignored by the parser..
|
||||
// we then get rid of the tags during the toString method in this class.
|
||||
foreach($matches as $v) {
|
||||
$data = str_replace('{_('.$v.')_}', '{_('.$this->translateString($v).')_}', $data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Flag indicating compiler is inside {_( .... )_} block, and should not
|
||||
* add to the gettextstrings array.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $inGetTextBlock = false;
|
||||
|
||||
/**
|
||||
* This is the base toString Method, it relays into toString{TokenName}
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_*
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toString($element)
|
||||
{
|
||||
static $len = 26; // strlen('HTML_Template_Flexy_Token_');
|
||||
if ($this->options['debug'] > 1) {
|
||||
$x = $element;
|
||||
unset($x->children);
|
||||
//echo htmlspecialchars(print_r($x,true))."<BR>\n";
|
||||
}
|
||||
if ($element->token == 'GetTextStart') {
|
||||
$this->inGetTextBlock = true;
|
||||
return '';
|
||||
}
|
||||
if ($element->token == 'GetTextEnd') {
|
||||
$this->inGetTextBlock = false;
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$class = get_class($element);
|
||||
if (strlen($class) >= $len) {
|
||||
$type = substr($class, $len);
|
||||
return $this->{'toString'.$type}($element);
|
||||
}
|
||||
|
||||
$ret = $element->value;
|
||||
$add = $element->compileChildren($this);
|
||||
if (is_a($add, 'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
|
||||
if ($element->close) {
|
||||
$add = $element->close->compile($this);
|
||||
if (is_a($add, 'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Else toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Else
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringElse($element)
|
||||
{
|
||||
// pushpull states to make sure we are in an area.. - should really check to see
|
||||
// if the state it is pulling is a if...
|
||||
if ($element->pullState() === false) {
|
||||
return $this->appendHTML(
|
||||
"<font color=\"red\">Unmatched {else:} on line: {$element->line}</font>"
|
||||
);
|
||||
}
|
||||
$element->pushState();
|
||||
return $this->appendPhp("} else {");
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_End toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Else
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringEnd($element)
|
||||
{
|
||||
// pushpull states to make sure we are in an area.. - should really check to see
|
||||
// if the state it is pulling is a if...
|
||||
if ($element->pullState() === false) {
|
||||
return $this->appendHTML(
|
||||
"<font color=\"red\">Unmatched {end:} on line: {$element->line}</font>"
|
||||
);
|
||||
}
|
||||
|
||||
return $this->appendPhp("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_EndTag toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_EndTag
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function toStringEndTag($element)
|
||||
{
|
||||
return $this->toStringTag($element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Foreach toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Foreach
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringForeach($element)
|
||||
{
|
||||
|
||||
$loopon = $element->toVar($element->loopOn);
|
||||
if (is_a($loopon, 'PEAR_Error')) {
|
||||
return $loopon;
|
||||
}
|
||||
|
||||
$ret = 'if ($this->options[\'strict\'] || ('.
|
||||
'is_array('. $loopon. ') || ' .
|
||||
'is_object(' . $loopon . '))) ' .
|
||||
'foreach(' . $loopon . " ";
|
||||
|
||||
$ret .= "as \${$element->key}";
|
||||
|
||||
if ($element->value) {
|
||||
$ret .= " => \${$element->value}";
|
||||
}
|
||||
$ret .= ") {";
|
||||
|
||||
$element->pushState();
|
||||
$element->pushVar($element->key);
|
||||
$element->pushVar($element->value);
|
||||
return $this->appendPhp($ret);
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_If toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_If
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringIf($element)
|
||||
{
|
||||
|
||||
$var = $element->toVar($element->condition);
|
||||
if (is_a($var, 'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
$ret = "if (".$element->isNegative . $var .") {";
|
||||
$element->pushState();
|
||||
return $this->appendPhp($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Modifier Wrapper
|
||||
*
|
||||
* converts :h, :u, :r , .....
|
||||
* @param object HTML_Template_Flexy_Token_Method|Var
|
||||
*
|
||||
* @return array prefix,suffix
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function getModifierWrapper($element)
|
||||
{
|
||||
$prefix = 'echo ';
|
||||
|
||||
$suffix = '';
|
||||
$modifier = strlen(trim($element->modifier)) ? $element->modifier : ' ';
|
||||
|
||||
switch ($modifier) {
|
||||
case 'h':
|
||||
break;
|
||||
case 'u':
|
||||
$prefix = 'echo urlencode(';
|
||||
$suffix = ')';
|
||||
break;
|
||||
case 'r':
|
||||
$prefix = 'echo \'<pre>\'; echo htmlspecialchars(print_r(';
|
||||
$suffix = ',true)); echo \'</pre>\';';
|
||||
break;
|
||||
case 'n':
|
||||
// blank or value..
|
||||
$numberformat = @$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'];
|
||||
$prefix = 'echo number_format(';
|
||||
$suffix = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'] . ')';
|
||||
break;
|
||||
case 'b': // nl2br + htmlspecialchars
|
||||
$prefix = 'echo nl2br(htmlspecialchars(';
|
||||
|
||||
// add language ?
|
||||
$suffix = '))';
|
||||
break;
|
||||
case 'e':
|
||||
$prefix = 'echo htmlentities(';
|
||||
// add language ?
|
||||
$suffix = ')';
|
||||
break;
|
||||
case ' ':
|
||||
$prefix = 'echo htmlspecialchars(';
|
||||
// add language ?
|
||||
$suffix = ')';
|
||||
break;
|
||||
default:
|
||||
$prefix = 'echo $this->plugin("'.trim($element->modifier) .'",';
|
||||
$suffix = ')';
|
||||
|
||||
|
||||
}
|
||||
|
||||
return array($prefix, $suffix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Var toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Method
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringVar($element)
|
||||
{
|
||||
// ignore modifier at present!!
|
||||
|
||||
$var = $element->toVar($element->value);
|
||||
if (is_a($var, 'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
list($prefix, $suffix) = $this->getModifierWrapper($element);
|
||||
return $this->appendPhp( $prefix . $var . $suffix .';');
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Method toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Method
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringMethod($element)
|
||||
{
|
||||
|
||||
|
||||
// set up the modifier at present!!
|
||||
|
||||
list($prefix, $suffix) = $this->getModifierWrapper($element);
|
||||
|
||||
// add the '!' to if
|
||||
|
||||
if ($element->isConditional) {
|
||||
$prefix = 'if ('.$element->isNegative;
|
||||
$element->pushState();
|
||||
$suffix = ')';
|
||||
}
|
||||
|
||||
|
||||
// check that method exists..
|
||||
// if (method_exists($object,'method');
|
||||
$bits = explode('.', $element->method);
|
||||
$method = array_pop($bits);
|
||||
|
||||
$object = implode('.', $bits);
|
||||
|
||||
$var = $element->toVar($object);
|
||||
if (is_a($var, 'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
if (($object == 'GLOBALS') &&
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globalfunctions']) {
|
||||
// we should check if they something weird like: GLOBALS.xxxx[sdf](....)
|
||||
$var = $method;
|
||||
} else {
|
||||
$prefix = 'if ($this->options[\'strict\'] || (isset('.$var.
|
||||
') && method_exists('.$var .", '{$method}'))) " . $prefix;
|
||||
$var = $element->toVar($element->method);
|
||||
}
|
||||
|
||||
|
||||
if (is_a($var, 'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
$ret = $prefix;
|
||||
$ret .= $var . "(";
|
||||
$s =0;
|
||||
|
||||
|
||||
|
||||
foreach($element->args as $a) {
|
||||
|
||||
if ($s) {
|
||||
$ret .= ",";
|
||||
}
|
||||
$s =1;
|
||||
if ($a{0} == '#') {
|
||||
if (is_numeric(substr($a, 1, -1))) {
|
||||
$ret .= substr($a, 1, -1);
|
||||
} else {
|
||||
$ret .= '"'. addslashes(substr($a, 1, -1)) . '"';
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$var = $element->toVar($a);
|
||||
if (is_a($var, 'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
$ret .= $var;
|
||||
|
||||
}
|
||||
$ret .= ")" . $suffix;
|
||||
|
||||
if ($element->isConditional) {
|
||||
$ret .= ' { ';
|
||||
} else {
|
||||
$ret .= ";";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->appendPhp($ret);
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Processing toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Processing
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringProcessing($element)
|
||||
{
|
||||
// if it's XML then quote it..
|
||||
if (strtoupper(substr($element->value, 2, 3)) == 'XML') {
|
||||
return $this->appendPhp("echo '" . str_replace("'", "\\"."'", $element->value) . "';");
|
||||
}
|
||||
// otherwise it's PHP code - so echo it..
|
||||
return $element->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Text toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Text
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function toStringText($element)
|
||||
{
|
||||
|
||||
// first get rid of stuff thats not translated etc.
|
||||
// empty strings => output.
|
||||
// comments -> just output
|
||||
// our special tags -> output..
|
||||
|
||||
if (!strlen(trim($element->value) )) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
// dont add comments to translation lists.
|
||||
|
||||
if (substr($element->value, 0, 4) == '<!--') {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
// ignore anything wrapped with {_( .... )_}
|
||||
if ($this->inGetTextBlock) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
|
||||
|
||||
if (!$element->isWord()) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
|
||||
// grab the white space at start and end (and keep it!
|
||||
|
||||
$value = ltrim($element->value);
|
||||
$front = substr($element->value, 0, -strlen($value));
|
||||
$value = rtrim($element->value);
|
||||
$rear = substr($element->value, strlen($value));
|
||||
$value = trim($element->value);
|
||||
|
||||
|
||||
// convert to escaped chars.. (limited..)
|
||||
//$value = strtr($value,$cleanArray);
|
||||
|
||||
$this->addStringToGettext($value);
|
||||
$value = $this->translateString($value);
|
||||
// its a simple word!
|
||||
return $this->appendHtml($front . $value . $rear);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Cdata toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Cdata ?
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function toStringCdata($element)
|
||||
{
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* addStringToGettext
|
||||
*
|
||||
* Adds a string to the gettext array.
|
||||
*
|
||||
* @param mixed preferably.. string to store
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function addStringToGettext($string)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if (!is_string($string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('/[a-z]+/i', $string)) {
|
||||
return;
|
||||
}
|
||||
$string = trim($string);
|
||||
|
||||
if (substr($string, 0, 4) == '<!--') {
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_COMPILER']['gettextStrings'][] = $string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translateString - a gettextWrapper
|
||||
*
|
||||
* tries to do gettext or falls back on File_Gettext
|
||||
* This has !!!NO!!! error handling - if it fails you just get english..
|
||||
* no questions asked!!!
|
||||
*
|
||||
* @param string string to translate
|
||||
*
|
||||
* @return string translated string..
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function translateString($string)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (is_a($this->options['Translation2'], 'Translation2')) {
|
||||
$result = $this->options['Translation2']->get($string);
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
// note this stuff may have been broken by removing the \n replacement code
|
||||
// since i dont have a test for it... it may remain broken..
|
||||
// use Translation2 - it has gettext backend support
|
||||
// and should sort out the mess that \n etc. entail.
|
||||
|
||||
|
||||
$prefix = basename($GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']).':';
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":TRANSLATING $string<BR>\n";
|
||||
}
|
||||
|
||||
if (function_exists('gettext') && !$this->options['textdomain']) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":USING GETTEXT?<BR>";
|
||||
}
|
||||
$t = gettext($string);
|
||||
|
||||
if ($t != $string) {
|
||||
return $t;
|
||||
}
|
||||
$tt = gettext($prefix.$string);
|
||||
if ($tt != $prefix.$string) {
|
||||
return $tt;
|
||||
}
|
||||
// give up it's not translated anywhere...
|
||||
return $string;
|
||||
|
||||
}
|
||||
if (!$this->options['textdomain'] || !$this->options['textdomainDir']) {
|
||||
// text domain is not set..
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":MISSING textdomain settings<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
$pofile = $this->options['textdomainDir'] .
|
||||
'/' . $this->options['locale'] .
|
||||
'/LC_MESSAGES/' . $this->options['textdomain'] . '.po';
|
||||
|
||||
|
||||
// did we try to load it already..
|
||||
if (@$GLOBALS['_'.__CLASS__]['PO'][$pofile] === false) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD failed (Cached):<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
if (!@$GLOBALS['_'.__CLASS__]['PO'][$pofile]) {
|
||||
// default - cant load it..
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile] = false;
|
||||
if (!file_exists($pofile)) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD failed: {$pofile}<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
if (!@include_once 'File/Gettext.php') {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD no File_gettext:<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile] = File_Gettext::factory('PO', $pofile);
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile]->load();
|
||||
//echo '<PRE>'.htmlspecialchars(print_r($GLOBALS['_'.__CLASS__]['PO'][$pofile]->strings,true));
|
||||
|
||||
}
|
||||
$po = &$GLOBALS['_'.__CLASS__]['PO'][$pofile];
|
||||
// we should have it loaded now...
|
||||
// this is odd - data is a bit messed up with CR's
|
||||
$string = str_replace('\n', "\n", $string);
|
||||
|
||||
if (isset($po->strings[$prefix.$string])) {
|
||||
return $po->strings[$prefix.$string];
|
||||
}
|
||||
|
||||
if (!isset($po->strings[$string])) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":no match:<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":MATCHED: {$po->strings[$string]}<BR>";
|
||||
}
|
||||
|
||||
// finally we have a match!!!
|
||||
return $po->strings[$string];
|
||||
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Tag toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Tag
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringTag($element) {
|
||||
|
||||
$original = $element->getAttribute('ALT');
|
||||
if (($element->tag == 'IMG') && is_string($original) && strlen($original)) {
|
||||
$this->addStringToGettext($original);
|
||||
$quote = $element->ucAttributes['ALT']{0};
|
||||
$element->ucAttributes['ALT'] = $quote . $this->translateString($original). $quote;
|
||||
}
|
||||
$original = $element->getAttribute('TITLE');
|
||||
if (($element->tag == 'A') && is_string($original) && strlen($original)) {
|
||||
$this->addStringToGettext($original);
|
||||
$quote = $element->ucAttributes['TITLE']{0};
|
||||
$element->ucAttributes['TITLE'] = $quote . $this->translateString($original). $quote;
|
||||
}
|
||||
|
||||
|
||||
if (strpos($element->tag, ':') === false) {
|
||||
$namespace = 'Tag';
|
||||
} else {
|
||||
$bits = explode(':', $element->tag);
|
||||
$namespace = $bits[0];
|
||||
}
|
||||
if ($namespace{0} == '/') {
|
||||
$namespace = substr($namespace, 1);
|
||||
}
|
||||
if (empty($this->tagHandlers[$namespace])) {
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler/Flexy/Tag.php';
|
||||
$this->tagHandlers[$namespace] = &HTML_Template_Flexy_Compiler_Flexy_Tag::factory($namespace, $this);
|
||||
if (!$this->tagHandlers[$namespace] ) {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::failed to create Namespace Handler '.$namespace .
|
||||
' in file ' . $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'],
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
|
||||
}
|
||||
return $this->tagHandlers[$namespace]->toString($element);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
222
HTML/Template/Flexy/Compiler/Flexy/Flexy.php
Normal file
222
HTML/Template/Flexy/Compiler/Flexy/Flexy.php
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akkbhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Flexy.php,v 1.6 2005/01/22 06:32:20 alan_k Exp $
|
||||
//
|
||||
// Handler code for the <flexy: namespace
|
||||
//
|
||||
|
||||
/**
|
||||
* the <flexy:XXXX namespace
|
||||
*
|
||||
*
|
||||
* at present it handles
|
||||
* <flexy:toJavascript flexy:prefix="Javascript_prefix" javscriptName="PHPvar" .....>
|
||||
* <flexy:include src="xxx.htm">
|
||||
*
|
||||
*
|
||||
*
|
||||
* @version $Id: Flexy.php,v 1.6 2005/01/22 06:32:20 alan_k Exp $
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Flexy_Flexy {
|
||||
|
||||
|
||||
/**
|
||||
* Parent Compiler for
|
||||
*
|
||||
* @var object HTML_Template_Flexy_Compiler
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $compiler;
|
||||
|
||||
|
||||
/**
|
||||
* The current element to parse..
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $element;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* toString - display tag, attributes, postfix and any code in attributes.
|
||||
* Relays into namspace::method to get results..
|
||||
*
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
function toString($element)
|
||||
{
|
||||
|
||||
list($namespace,$method) = explode(':',$element->oTag);
|
||||
if (!strlen($method)) {
|
||||
return '';
|
||||
}
|
||||
// things we dont handle...
|
||||
if (!method_exists($this,$method.'ToString')) {
|
||||
return '';
|
||||
}
|
||||
return $this->{$method.'ToString'}($element);
|
||||
|
||||
}
|
||||
/**
|
||||
* toJavascript handler
|
||||
* <flexy:toJavascript flexy:prefix="some_prefix_" javascriptval="php.val" ....>
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
|
||||
function toJavascriptToString($element)
|
||||
{
|
||||
$ret = $this->compiler->appendPhp( "require_once 'HTML/Javascript/Convert.php';");
|
||||
$ret .= $this->compiler->appendHTML("\n<script type='text/javascript'>\n");
|
||||
$prefix = ''. $element->getAttribute('FLEXY:PREFIX');
|
||||
|
||||
|
||||
foreach ($element->attributes as $k=>$v) {
|
||||
// skip directives..
|
||||
if (strpos($k,':')) {
|
||||
continue;
|
||||
}
|
||||
if ($k == '/') {
|
||||
continue;
|
||||
}
|
||||
$v = substr($v,1,-1);
|
||||
$ret .= $this->compiler->appendPhp(
|
||||
'$__tmp = HTML_Javascript_Convert::convertVar('.$element->toVar($v) .',\''.$prefix . $k.'\',true);'.
|
||||
'echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;');
|
||||
$ret .= $this->compiler->appendHTML("\n");
|
||||
}
|
||||
$ret .= $this->compiler->appendHTML("</script>");
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* include handler
|
||||
* <flexy:include src="test.html">
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
function includeToString($element)
|
||||
{
|
||||
// this is disabled by default...
|
||||
// we ignore modifier pre/suffix
|
||||
|
||||
|
||||
|
||||
|
||||
$arg = $element->getAttribute('SRC');
|
||||
if (!$arg) {
|
||||
return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename</B>");
|
||||
}
|
||||
// ideally it would be nice to embed the results of one template into another.
|
||||
// however that would involve some complex test which would have to stat
|
||||
// the child templates anyway..
|
||||
// compile the child template....
|
||||
// output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
|
||||
return $this->compiler->appendPHP( "\n".
|
||||
"\$x = new HTML_Template_Flexy(\$this->options);\n".
|
||||
"\$x->compile('{$arg}');\n".
|
||||
"\$_t = function_exists('clone') ? clone(\$t) : \$t;\n".
|
||||
"foreach(get_defined_vars() as \$k=>\$v) {\n" .
|
||||
" if (\$k != 't') { \$_t->\$k = \$v; }\n" .
|
||||
"}\n" .
|
||||
"\$x->outputObject(\$_t, \$this->elements);\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert flexy tokens to HTML_Template_Flexy_Elements.
|
||||
*
|
||||
* @param object token to convert into a element.
|
||||
* @return object HTML_Template_Flexy_Element
|
||||
* @access public
|
||||
*/
|
||||
function toElement($element)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for User defined functions in templates..
|
||||
* <flexy:function name="xxxxx">.... </flexy:block> // equivilant to function xxxxx() {
|
||||
* <flexy:function call="{xxxxx}">.... </flexy:block> // equivilant to function {$xxxxx}() {
|
||||
* <flexy:function call="xxxxx">.... </flexy:block> // equivilant to function {$xxxxx}() {
|
||||
*
|
||||
* This will not handle nested blocks initially!! (and may cause even more problems with
|
||||
* if /foreach stuff..!!
|
||||
*
|
||||
* @param object token to convert into a element.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function functionToString($element)
|
||||
{
|
||||
|
||||
if ($arg = $element->getAttribute('NAME')) {
|
||||
// this is a really kludgy way of doing this!!!
|
||||
// hopefully the new Template Package will have a sweeter method..
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] .=
|
||||
$this->compiler->appendPHP(
|
||||
"\nfunction _html_template_flexy_compiler_flexy_flexy_{$arg}(\$t,\$this) {\n").
|
||||
$element->compileChildren($this->compiler) .
|
||||
$this->compiler->appendPHP( "\n}\n");
|
||||
|
||||
return '';
|
||||
}
|
||||
if (!isset($element->ucAttributes['CALL'])) {
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
' tag flexy:function needs an argument call or name'.
|
||||
" Error on Line {$element->line} <{$element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
// call is a stirng : nice and simple..
|
||||
if (is_string($element->ucAttributes['CALL'])) {
|
||||
$arg = $element->getAttribute('CALL');
|
||||
return $this->compiler->appendPHP(
|
||||
"if (function_exists('_html_template_flexy_compiler_flexy_flexy_{$arg}')) " .
|
||||
" _html_template_flexy_compiler_flexy_flexy_{$arg}(\$t,\$this);");
|
||||
}
|
||||
|
||||
// we make a big assumption here.. - it should really be error checked..
|
||||
// that the {xxx} element is item 1 in the list...
|
||||
$e=$element->ucAttributes['CALL'][1];
|
||||
$add = $e->toVar($e->value);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
return $this->compiler->appendPHP(
|
||||
"if (function_exists('_html_template_flexy_compiler_flexy_flexy_'.{$add})) ".
|
||||
"call_user_func_array('_html_template_flexy_compiler_flexy_flexy_'.{$add},array(\$t,\$this));");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
1176
HTML/Template/Flexy/Compiler/Flexy/Tag.php
Normal file
1176
HTML/Template/Flexy/Compiler/Flexy/Tag.php
Normal file
File diff suppressed because it is too large
Load diff
98
HTML/Template/Flexy/Compiler/Regex.php
Normal file
98
HTML/Template/Flexy/Compiler/Regex.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex {
|
||||
|
||||
/**
|
||||
* The main flexy engine
|
||||
*
|
||||
* @var object HTML_Template_Flexy
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $flexy;
|
||||
/**
|
||||
* classicParse - the older regex based code generator.
|
||||
* here all the replacing, filtering and writing of the compiled file is done
|
||||
* well this is not much work, but still its in here :-)
|
||||
*
|
||||
* @access private
|
||||
* @version 01/12/03
|
||||
* @author Wolfram Kriesing <wolfram@kriesing.de>
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
* @return boolean (basically true all the time here)
|
||||
*/
|
||||
function compile(&$flexy)
|
||||
{
|
||||
$this->flexy = &$flexy;
|
||||
// read the entire file into one variable
|
||||
$fileContent = file_get_contents($flexy->currentTemplate);
|
||||
|
||||
// apply pre filter
|
||||
$fileContent = $this->applyFilters( $fileContent , "/^pre_/i" );
|
||||
$fileContent = $this->applyFilters( $fileContent , "/^(pre_|post_)/i",TRUE);
|
||||
$fileContent = $this->applyFilters( $fileContent , "/^post_/i" );
|
||||
// write the compiled template into the compiledTemplate-File
|
||||
if( ($cfp = fopen( $flexy->compiledTemplate , 'w' )) ) {
|
||||
fwrite($cfp,$fileContent);
|
||||
fclose($cfp);
|
||||
@chmod($flexy->compiledTemplate,0775);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* actually it will only be used to apply the pre and post filters
|
||||
*
|
||||
* @access public
|
||||
* @version 01/12/10
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
* @param string $input the string to filter
|
||||
* @param array $prefix the subset of methods to use.
|
||||
* @return string the filtered string
|
||||
*/
|
||||
function applyFilters( $input , $prefix = "",$negate=FALSE)
|
||||
{
|
||||
$this->flexy->debug("APPLY FILTER $prefix<BR>");
|
||||
$filters = $this->options['filters'];
|
||||
$this->flexy->debug(serialize($filters)."<BR>");
|
||||
foreach($filters as $filtername) {
|
||||
$class = "HTML_Template_Flexy_Compiler_Regex_{$filtername}";
|
||||
require_once("HTML/Template/Flexy/Compiler/Regex/{$filtername}.php");
|
||||
|
||||
if (!class_exists($class)) {
|
||||
return HTML_Template_Flexy::raiseError("Failed to load filter $filter",null,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if (!@$this->filter_objects[$class]) {
|
||||
$this->filter_objects[$class] = new $class;
|
||||
$this->filter_objects[$class]->_set_engine($this);
|
||||
}
|
||||
$filter = &$this->filter_objects[$class];
|
||||
$methods = get_class_methods($class);
|
||||
$this->flexy->debug("METHODS:");
|
||||
$this->flexy->debug(serialize($methods)."<BR>");
|
||||
foreach($methods as $method) {
|
||||
if ($method{0} == "_") {
|
||||
continue; // private
|
||||
}
|
||||
if ($method == $class) {
|
||||
continue; // constructor
|
||||
}
|
||||
$this->flexy->debug("TEST: $negate $prefix : $method");
|
||||
if ($negate && preg_match($prefix,$method)) {
|
||||
continue;
|
||||
}
|
||||
if (!$negate && !preg_match($prefix,$method)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->flexy->debug("APPLYING $filtername $method<BR>");
|
||||
$input = $filter->$method($input);
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
81
HTML/Template/Flexy/Compiler/Regex/BodyOnly.php
Normal file
81
HTML/Template/Flexy/Compiler/Regex/BodyOnly.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* The html Body only filter
|
||||
*
|
||||
* @abstract
|
||||
* a Simple filter to remove the everything thats not in the body!
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_BodyOnly
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _set_engine(&$engine)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Strip everything before and including the BODY tag
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function strip_body_head ($input)
|
||||
{
|
||||
if (!preg_match("/^(.*)<body/si", $input)) {
|
||||
return $input;
|
||||
}
|
||||
$input = preg_replace("/^(.*)<body/si", "",$input);
|
||||
$input = preg_replace("/^([^>]*)>/si", "",$input);
|
||||
return $input;
|
||||
}
|
||||
/**
|
||||
* Strip everything after and including the end BODY tag
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
function strip_body_foot ($input)
|
||||
{
|
||||
if (!preg_match("/<\/body>.*/si", $input)) {
|
||||
return $input;
|
||||
}
|
||||
$input = preg_replace("/<\/body>.*/si", "",$input);
|
||||
return $input;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
57
HTML/Template/Flexy/Compiler/Regex/Mail.php
Normal file
57
HTML/Template/Flexy/Compiler/Regex/Mail.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* The Mail filter template (sorts out cr removal in php)
|
||||
*
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_Mail {
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
function _set_engine(&$engine)
|
||||
{
|
||||
}
|
||||
/*
|
||||
* add an extra cr to the end php tag, so it show correctly in Emails
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function post_fix_php_cr ($input)
|
||||
{
|
||||
$input = str_replace("?>\n","?>\n\n",$input);
|
||||
return str_replace("?>\r\n","?>\r\n\r\n",$input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
74
HTML/Template/Flexy/Compiler/Regex/Math.php
Normal file
74
HTML/Template/Flexy/Compiler/Regex/Math.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* A Math Filter
|
||||
*
|
||||
* enable simple maths to be done in the template
|
||||
*
|
||||
* TODO: add an {if:t.xxx%2} type syntax..
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_Math {
|
||||
/*
|
||||
* @var string $start the start tag for the template (escaped for regex)
|
||||
*/
|
||||
var $start = '\{';
|
||||
/*
|
||||
* @var string $stop the stopt tag for the template (escaped for regex)
|
||||
*/
|
||||
var $stop = '\}'; //ending template tag
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
function _set_engine(&$engine) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* allow simple add multiply, divide and subtraction
|
||||
*
|
||||
* eg.
|
||||
* {(12+t.somevar)*2} maps to =(12+$t->somevar)*2
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
function variables ($input) {
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([0-9\(\)+*\/-]*)([a-z0-9]+)([0-9\(\)+*\/-]*)".$this->stop."/ie",
|
||||
"'<?=\\1($'.str_replace('.','->','\\2').')\\3?>'",
|
||||
$input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
59
HTML/Template/Flexy/Compiler/Regex/Php.php
Normal file
59
HTML/Template/Flexy/Compiler/Regex/Php.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Remove PHP tags and replace them with echo '< ? '
|
||||
*
|
||||
* should be the first filter if you use it
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Compiler_Regex_Php
|
||||
{
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
function _set_engine(&$engine)
|
||||
{
|
||||
}
|
||||
/*
|
||||
* replace the php tags
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
function pre_strip_php ($input)
|
||||
{
|
||||
$input = str_replace("<?","__{<__?}__",$input);
|
||||
$input = str_replace("?>","<?php echo '?'.'>'; ?>",$input);
|
||||
return str_replace("__{<__?}__","<?php echo '<'.'>'; ?>",$input);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
50
HTML/Template/Flexy/Compiler/Regex/RtfSimpleTags.php
Normal file
50
HTML/Template/Flexy/Compiler/Regex/RtfSimpleTags.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* The rtf SimpleTags filter
|
||||
*
|
||||
* really an extension of simple tags with \\\{ and \\\\} as the tag delimiters
|
||||
* can parse an RTF template and generate a file.
|
||||
*
|
||||
* usually best used with callback ouput buffering to reduce memory loads.
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
require_once "HTML/Template/Flexy/Filter/SimpleTags.php";
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_RtfSimpleTags extends HTML_Template_Flexy_Compiler_Regex_simpletags
|
||||
{
|
||||
/*
|
||||
* @var string $start the start tag for the template (escaped for regex)
|
||||
*/
|
||||
var $start = '\\\{';
|
||||
/*
|
||||
* @var string $stop the stopt tag for the template (escaped for regex)
|
||||
*/
|
||||
var $stop= '\\\}';
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
391
HTML/Template/Flexy/Compiler/Regex/SimpleTags.php
Normal file
391
HTML/Template/Flexy/Compiler/Regex/SimpleTags.php
Normal file
|
|
@ -0,0 +1,391 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* The Standard Tag filter
|
||||
*
|
||||
* @abstract
|
||||
* does all the clever stuff...
|
||||
*
|
||||
* Security Notes:
|
||||
* Templates should not originate from untrusted sources,
|
||||
* - the method(#.....#) could be regarded as insecure.
|
||||
* - there is no attempt to protect your from <script / <?php in templates.
|
||||
*
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_SimpleTags
|
||||
{
|
||||
/*
|
||||
* @var object HTML_Template_Flexy the main engine
|
||||
*/
|
||||
var $engine; // the engine (with options)
|
||||
/*
|
||||
* @var string $start the start tag for the template (escaped for regex)
|
||||
*/
|
||||
var $start = '\{';
|
||||
|
||||
/*
|
||||
* @var string $stop the stopt tag for the template (escaped for regex)
|
||||
*/
|
||||
var $stop = '\}';
|
||||
/*
|
||||
* @var string $error show/hide the PHP error messages on/off in templates
|
||||
*/
|
||||
var $error = "@"; // change to blank to debug errors.
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
function _set_engine(&$engine) {
|
||||
$this->engine = &$engine;
|
||||
if ($this->engine->options['debug']) {
|
||||
$this->error = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Standard Variable replacement
|
||||
*
|
||||
*
|
||||
* Maps variables
|
||||
* {i.xyz} maps to <?php echo htmlspecialchars($i->xyz)?>
|
||||
* {i.xyz:h} maps to <?php echo $i->xyz?>
|
||||
* {i.xyz:u} maps to <?php echo urlencode($i->xyz)?>
|
||||
* {i.xyz:ru} maps to <?php echo rawurlencode($i->xyz)?>
|
||||
*
|
||||
* {i.xyz:r} maps to <PRE><?php echo print_r($i->xyz)?></PRE>
|
||||
* {i.xyz:n} maps to <?php echo nl2br(htmlspecialchars($i->xyz))?>
|
||||
*
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function variables ($input) {
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'",
|
||||
$input);
|
||||
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+):h".$this->stop."/ie",
|
||||
"'<?php echo ".$this->error."$'.str_replace('.','->','\\1').'?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+):u".$this->stop."/ie",
|
||||
"'<?php echo urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+):ru".$this->stop."/ie",
|
||||
"'<?php echo rawurlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+):r".$this->stop."/ie",
|
||||
"'<PRE><?php echo print_r($'.str_replace('.','->','\\1').')?></PRE>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+):n".$this->stop."/ie",
|
||||
"'<?php echo nl2br(htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'))?>'",
|
||||
$input);
|
||||
return $input;
|
||||
|
||||
}
|
||||
/**
|
||||
* Urlencoded Variable replacement
|
||||
*
|
||||
* Often when you use a WYSISYG editor, it replaces { in
|
||||
* the href="{somevar}" with the urlencoded version, this bit fixes it.
|
||||
*
|
||||
* Maps variables
|
||||
* %??i.xyz%?? maps to <?php echo htmlspecialchars($i->xyz)?>
|
||||
* %??i.xyz:h%?? maps to <?php echo $i->xyz?>
|
||||
* %??i.xyz:u%?? maps to <?php echo urlencode($i->xyz)?>
|
||||
* %??i.xyz:ru%?? maps to <?php echo urlencode($i->xyz)?>
|
||||
* THIS IS PROBABLY THE ONE TO USE!
|
||||
*
|
||||
* %??i.xyz:uu%?? maps to <?php echo urlencode(urlencode($i->xyz))?>
|
||||
*
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function urlencoded_variables ($input) {
|
||||
$input = preg_replace(
|
||||
"/".urlencode(stripslashes($this->start))."([a-z0-9_.]+)".urlencode(stripslashes($this->stop))."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'",
|
||||
$input);
|
||||
|
||||
|
||||
$input = preg_replace(
|
||||
"/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):h".urlencode(stripslashes($this->stop))."/ie",
|
||||
"'<?php echo ".$this->error."$'.str_replace('.','->','\\1').'?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):u".urlencode(stripslashes($this->stop))."/ie",
|
||||
"'<?php echo urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):uu".urlencode(stripslashes($this->stop))."/ie",
|
||||
"'<?php echo urlencode(urlencode(".$this->error."$'.str_replace('.','->','\\1').'))?>'",
|
||||
$input);
|
||||
return $input;
|
||||
}
|
||||
/**
|
||||
* Calling Methods
|
||||
*
|
||||
* This allows you to call methods of your application
|
||||
*
|
||||
* Maps Methods
|
||||
* {t.xxxx_xxxx()} maps to <?php echo htmlspecialchars($t->xxxx_xxxx())?>
|
||||
* {t.xxxx_xxxx():h} maps to <?php echo $t->xxxx_xxxx()?>
|
||||
*
|
||||
* {t.xxxx_xxxx(sssss.dddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($ssss->dddd))?>
|
||||
* {t.xxxx_xxxx(sssss.dddd):h} maps to <?php echo $t->xxxx_xxxx($ssss->dddd)?>
|
||||
* {t.xxxx_xxxx(sssss.dddd):s} maps to <?php highlight_string($t->xxxx_xxxx($ssss->dddd))?>
|
||||
*
|
||||
* {t.xxxx_xxxx(#XXXXX#)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx('XXXXXX'))?>
|
||||
* {t.xxxx_xxxx(#XXXXX#):h} maps to <?php echo $t->xxxx_xxxx('XXXXXX')?>
|
||||
*
|
||||
* {t.xxxx_xxxx(sss.ddd,sss.ddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($sss->ddd,$sss->ddd))?>
|
||||
* {t.xxxx_xxxx(#aaaa#,sss.ddd)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx("aaaa",$sss->ddd))?>
|
||||
* {t.xxxx_xxxx(sss.ddd,#aaaa#)} maps to <?php echo htmlspecialchars($t->xxxx_xxxx($sss->ddd,"aaaa"))?>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function methods($input) {
|
||||
|
||||
/* no vars */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'())?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(\):h".$this->stop."/ie",
|
||||
"'<?php echo ".$this->error."$'.str_replace('.','->','\\1').'()?>'",
|
||||
$input);
|
||||
/* single vars */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '))?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):h".$this->stop."/ie",
|
||||
"'<?php echo ".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ')?>'",
|
||||
$input);
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):s".$this->stop."/ie",
|
||||
"'<?php highlight_string($'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '));?>'",
|
||||
$input);
|
||||
/* double vars */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),([a-z0-9_.]+)\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',$' . str_replace('.','->','\\3') . '))?>'",
|
||||
$input);
|
||||
/* double vars:: # #'d ,var */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#,([a-z0-9_.]+)\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\',$' . str_replace('.','->','\\3') . '))?>'",
|
||||
$input);
|
||||
/* double vars:: var , # #'d */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),\#([^\#]+)\#\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',\''. str_replace(\"'\",\"\\\'\",'\\3') . '\'))?>'",
|
||||
$input);
|
||||
|
||||
/*strings or integers */
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\)".$this->stop."/ie",
|
||||
"'<?php echo htmlspecialchars(\$'.str_replace('.','->','\\1') . '(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\'))?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\):h".$this->stop."/ie",
|
||||
"'<?php echo ".$this->error."$'.str_replace('.','->','\\1').'(\"' . str_replace(\"'\",\"\\\'\",'\\2') . '\")?>'",
|
||||
$input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
/**
|
||||
* Looping
|
||||
*
|
||||
* This allows you to do loops on variables (eg. nested/ repeated blocks!)
|
||||
*
|
||||
* Maps Methods
|
||||
* {foreach:t.xyz,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $zzz) { ?>
|
||||
* {foreach:t.xyz,xxx,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $xxx=>$zzz) { ?>
|
||||
* {end:} maps to <?php }?>
|
||||
* {else:} maps to <?php }else{?>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function looping($input) {
|
||||
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie",
|
||||
"'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . ') { ?>'",
|
||||
$input);
|
||||
$input = preg_replace(
|
||||
"/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie",
|
||||
"'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . '=>$' . str_replace('.','->','\\3') .') { ?>'",
|
||||
$input);
|
||||
|
||||
$input = str_replace(stripslashes($this->start)."else:".stripslashes($this->stop),'<?php }else{?>', $input);
|
||||
$input = str_replace(stripslashes($this->start)."end:".stripslashes($this->stop),'<?php }?>', $input);
|
||||
return $input;
|
||||
}
|
||||
/**
|
||||
* Conditional inclusion
|
||||
*
|
||||
* This allows you to do conditional inclusion (eg. blocks!)
|
||||
*
|
||||
* Maps conditions
|
||||
*
|
||||
* {if:t.xxxx} => <?php if ($t->xxxx) { ?>
|
||||
* {if:t.x_xxx()} => <?php if ($t->x_xxx()) { ?>
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function conditionals($input) {
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."if:([a-z0-9_.]+)".$this->stop."/ie",
|
||||
"'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') { ?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."if:([a-z0-9_.]+)\(\)".$this->stop."/ie",
|
||||
"'<?php if (".$this->error."$' . str_replace('.','->','\\1') . '()) { ?>'",
|
||||
$input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
/**
|
||||
* sub template inclusion
|
||||
*
|
||||
* This allows you to do include other files (either flat or generated templates.).
|
||||
*
|
||||
* {include:t.abcdef} maps to <?php
|
||||
* if($t->abcdef && file_exists($compileDir . "/". $t->abcdef . "en.php"))
|
||||
* include($compileDir . "/". $t->abcdef . ".en.php");
|
||||
* ?>
|
||||
*
|
||||
* include abcdef.en.php (Eg. hard coded compiled template
|
||||
* {include:#abcdef#} => <?php
|
||||
* if(file_exists($compileDir . "/abcdef.en.php"))
|
||||
* include($compileDir . "/abcdef.en.php");
|
||||
* ?>
|
||||
*
|
||||
* include raw
|
||||
* {t_include:#abcdef.html#} => <?php
|
||||
* if(file_exists($templateDir . "/abcdef.html"))
|
||||
* include($compileDir . "/abcdef.html");
|
||||
* ?>
|
||||
* Compile and include
|
||||
* {q_include:#abcdef.html#} => <?php
|
||||
* HTML_Template_Flexy::staticQuickTemplate('abcedef.html',$t);
|
||||
* ?>
|
||||
*
|
||||
*
|
||||
* @param string $input the template
|
||||
* @return string the result of the filtering
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function include_template($input) {
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."include:([a-z0-9_.]+)".$this->stop."/ie",
|
||||
"'<?php
|
||||
if ((".$this->error."$' . str_replace('.','->','\\1') . ') &&
|
||||
file_exists(\"" . $this->engine->options['compileDir'] .
|
||||
"/\{$' . str_replace('.','->','\\1') . '}.en.php\"))
|
||||
include(\"" . $this->engine->options['compileDir'] .
|
||||
"/\{$' . str_replace('.','->','\\1') . '}.en.php\");?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."include:#([a-z0-9_.]+)#".$this->stop."/ie",
|
||||
"'<?php if (file_exists(\"" . $this->engine->options['compileDir'] . "/\\1.en.php\")) include(\"" .
|
||||
$this->engine->options['compileDir'] . "/\\1.en.php\");?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."t_include:#([a-z0-9_.]+)#".$this->stop."/ie",
|
||||
"'<?php if (file_exists(\"" . $this->engine->options['templateDir'] .
|
||||
"/\\1\")) include(\"" . $this->engine->options['templateDir'] . "/\\1\");?>'",
|
||||
$input);
|
||||
|
||||
$input = preg_replace(
|
||||
"/".$this->start."q_include:#([a-z0-9_.]+)#".$this->stop."/ie",
|
||||
"'<?php HTML_Template_Flexy::staticQuickTemplate(\"\\1\",\$t); ?>'",
|
||||
$input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
58
HTML/Template/Flexy/Compiler/Regex/Xml.php
Normal file
58
HTML/Template/Flexy/Compiler/Regex/Xml.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Replace XML tags with echo '<' .'?xml';
|
||||
*
|
||||
|
||||
* @package HTML_Template_Flexy
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Regex_Xml
|
||||
{
|
||||
/**
|
||||
* Standard Set Engine
|
||||
*
|
||||
*
|
||||
* @param object HTML_Template_Flexy the main engine
|
||||
* @access private
|
||||
*/
|
||||
function _set_engine(&$engine)
|
||||
{
|
||||
}
|
||||
/*
|
||||
* replace the xml tags
|
||||
*
|
||||
* @param string The template
|
||||
* @access public
|
||||
*/
|
||||
function pre_replace_xml ($input)
|
||||
{
|
||||
$input = str_replace("?>","<?php echo '?'.'>'; ?>\n",$input);
|
||||
$input = str_replace("<?xml","<?php echo '<'.'?xml'; ?>",$input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
335
HTML/Template/Flexy/Compiler/SmartyConvertor.php
Normal file
335
HTML/Template/Flexy/Compiler/SmartyConvertor.php
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: SmartyConvertor.php,v 1.3 2004/07/03 03:46:43 alan_k Exp $
|
||||
//
|
||||
// Smarty Conversion compiler
|
||||
// takes a smarty template, and converts it to a flexy one.
|
||||
// then does a standard flexy compile.
|
||||
//
|
||||
// anything that is not supported gets changed to HTML comments
|
||||
|
||||
/* Usage:
|
||||
a simple script: 'convertsmarty.php'
|
||||
|
||||
#!/usr/bin/php
|
||||
$file = $_SERVER['argv'][1];
|
||||
$x = new HTML_Template_Flexy(array(
|
||||
'compileDir' => dirname(__FILE__) , // where do you want to write to..
|
||||
'templateDir' => $dir , // where are your templates
|
||||
'locale' => 'en', // works with gettext
|
||||
'forceCompile' => true, // only suggested for debugging
|
||||
'debug' => false, // prints a few errors
|
||||
'nonHTML' => false, // dont parse HTML tags (eg. email templates)
|
||||
'allowPHP' => false, // allow PHP in template
|
||||
'compiler' => 'SmartyConvertor', // which compiler to use.
|
||||
'compileToString' => true, // returns the converted template (rather than actually
|
||||
// converting to PHP.
|
||||
'filters' => array(), // used by regex compiler..
|
||||
'numberFormat' => ",2,'.',','", // default number format = eg. 1,200.00 ( {xxx:n} )
|
||||
'flexyIgnore' => 0 // turn on/off the tag to element code
|
||||
));
|
||||
|
||||
echo $x->compile(basename($file));
|
||||
|
||||
then run it at the command line:
|
||||
php convertsmarty.php /path/to/a/smarty/template.tpl > /path/to/the/flexy/templates.html
|
||||
*/
|
||||
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler.php';
|
||||
|
||||
/**
|
||||
* The Smarty Converter implementation.
|
||||
* designed primarily to be used as above, to convert from one to another.
|
||||
* however it could be used inline to convert simple smarty templates into
|
||||
* flexy ones - then compile them on the fly.
|
||||
*
|
||||
* @version $Id: SmartyConvertor.php,v 1.3 2004/07/03 03:46:43 alan_k Exp $
|
||||
*/
|
||||
class HTML_Template_Flexy_Compiler_SmartyConvertor extends HTML_Template_Flexy_Compiler {
|
||||
|
||||
/**
|
||||
* compile implementation
|
||||
*
|
||||
* see HTML_Template_Flexy_Compiler::compile()
|
||||
*
|
||||
* @param object The core flexy object.
|
||||
* @param string optionally a string to compile.
|
||||
*
|
||||
* @return true | string string when compiling to String.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function compile(&$flexy,$string=false)
|
||||
{
|
||||
$data = $string;
|
||||
if ($string === false) {
|
||||
$data = file_get_contents($flexy->currentTemplate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$data = $this->convertToFlexy($data);
|
||||
|
||||
if ($flexy->options['compileToString']) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler/Standard.php';
|
||||
$flexyCompiler = new HTML_Template_Flexy_Compiler_Standard;
|
||||
$flexyCompiler->compile($flexy,$data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The core work of parsing a smarty template and converting it into flexy.
|
||||
*
|
||||
* @param string the contents of the smarty template
|
||||
*
|
||||
* @return string the flexy version of the template.
|
||||
* @access public|private
|
||||
* @see see also methods.....
|
||||
*/
|
||||
function convertToFlexy($data)
|
||||
{
|
||||
|
||||
$leftq = preg_quote('{', '!');
|
||||
$rightq = preg_quote('}', '!');
|
||||
|
||||
preg_match_all("!" . $leftq . "\s*(.*?)\s*" . $rightq . "!s", $data, $matches);
|
||||
$tags = $matches[1];
|
||||
// find all the tags/text...
|
||||
$text = preg_split("!" . $leftq . ".*?" . $rightq . "!s", $data);
|
||||
|
||||
$max_text = count($text);
|
||||
$max_tags = count($tags);
|
||||
|
||||
for ($i = 0 ; $i < $max_tags ; $i++) {
|
||||
$compiled_tags[] = $this->_compileTag($tags[$i]);
|
||||
}
|
||||
// error handling for closing tags.
|
||||
|
||||
|
||||
$data = '';
|
||||
for ($i = 0; $i < $max_tags; $i++) {
|
||||
$data .= $text[$i].$compiled_tags[$i];
|
||||
}
|
||||
$data .= $text[$i];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* stack for conditional and closers.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $stack = array(
|
||||
'if' => 0,
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* compile a smarty { tag } into a flexy one.
|
||||
*
|
||||
* @param string the tag
|
||||
*
|
||||
* @return string the converted version
|
||||
* @access private
|
||||
*/
|
||||
function _compileTag($str)
|
||||
{
|
||||
// skip comments
|
||||
if (($str{0} == '*') && (substr($str,-1,1) == '*')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
switch($str{0}) {
|
||||
case '$':
|
||||
// its a var
|
||||
return $this->_convertVar($str);
|
||||
case '#':
|
||||
// its a config var
|
||||
return $this->_convertConfigVar($str);
|
||||
case '%':
|
||||
// wtf does this do
|
||||
return "<!-- what is this? $str -->";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// this is where it gets messy
|
||||
// this is very slow - but what the hell
|
||||
// - its only done once
|
||||
// - its alot more readable than a long regext.
|
||||
// - it doesnt infringe on copyright...
|
||||
switch(true) {
|
||||
case (preg_match('/^config_load\s/', $str)):
|
||||
// convert to $t->TemplateConfigLoad()
|
||||
$args = $this->convertAttributesToKeyVal(substr($str,strpos( $str,' ')));
|
||||
return '{plugin(#smartyConfigLoad#,#'.$args['file'].'#,#'.$args['section'].'#)}';
|
||||
|
||||
case (preg_match('/^include\s/', $str)):
|
||||
// convert to $t->TemplateConfigLoad()
|
||||
$args = $this->convertAttributesToKeyVal(substr($str,strpos( $str,' ')));
|
||||
|
||||
return '{plugin(#smartyInclude#,#'.$args['file'].'#)}';
|
||||
|
||||
case ($str == 'ldelim'):
|
||||
return '{';
|
||||
case ($str == 'rdelim'):
|
||||
return '}';
|
||||
|
||||
|
||||
case (preg_match('/^if \$(\S+)$/', $str,$matches)):
|
||||
case (preg_match('/^if \$(\S+)\seq\s""$/', $str,$matches)):
|
||||
// simple if variable..
|
||||
// convert to : {if:sssssss}
|
||||
$this->stack['if']++;
|
||||
$var = $this->_convertVar('$'.$matches[1]);
|
||||
return '{if:'.substr($var,1);
|
||||
|
||||
case (preg_match('/^if #(\S+)#$/', $str,$matches)):
|
||||
case (preg_match('/^if #(\S+)#\sne\s""$/', $str,$matches)):
|
||||
// simple if variable..
|
||||
// convert to : {if:sssssss}
|
||||
$this->stack['if']++;
|
||||
$var = $this->_convertConfigVar('#'.$matches[1].'#');
|
||||
return '{if:'.substr($var,1);
|
||||
|
||||
// negative matches
|
||||
case (preg_match('/^if\s!\s\$(\S+)$/', $str,$matches)):
|
||||
case (preg_match('/^if \$(\S+)\seq\s""$/', $str,$matches)):
|
||||
// simple if variable..
|
||||
// convert to : {if:sssssss}
|
||||
$this->stack['if']++;
|
||||
$var = $this->_convertVar('$'.$matches[1]);
|
||||
return '{if:!'.substr($var,1);
|
||||
|
||||
case ($str == 'else'):
|
||||
if (!$this->stack['if']) {
|
||||
break;
|
||||
}
|
||||
return '{else:}';
|
||||
|
||||
|
||||
case ($str == '/if'):
|
||||
if (!$this->stack['if']) {
|
||||
break;
|
||||
}
|
||||
$this->stack['if']--;
|
||||
return '{end:}';
|
||||
|
||||
|
||||
}
|
||||
|
||||
return "<!-- UNSUPPORTED TAG: $str FOUND -->";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a smarty var into a flexy one.
|
||||
*
|
||||
* @param string the inside of the smart tag
|
||||
*
|
||||
* @return string a flexy version of it.
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _convertVar($str)
|
||||
{
|
||||
// look for modfiers first.
|
||||
$mods = explode('|', $str);
|
||||
$var = array_shift($mods);
|
||||
$var = substr($var,1); // strip $
|
||||
|
||||
// various formats :
|
||||
// aaaa.bbbb.cccc => aaaa[bbbb][cccc]
|
||||
// aaaa[bbbb] => aaa[bbbb]
|
||||
// aaaa->bbbb => aaaa.bbbb
|
||||
|
||||
$bits = explode('.',$var);
|
||||
$var = array_shift($bits);
|
||||
foreach($bits as $k) {
|
||||
$var.= '['.$k .']';
|
||||
}
|
||||
$bits = explode('->',$var);
|
||||
$var = implode('.',$bits);
|
||||
$mods = implode('|',$mods);
|
||||
|
||||
if (strlen($mods)) {
|
||||
return '{plugin(#smartyModifiers#,'.$var.',#'.$mods.'#):h}';
|
||||
}
|
||||
return '{'.$var .'}' . $mods;
|
||||
}
|
||||
/**
|
||||
* convert a smarty key="value" string into a key value array
|
||||
* cheap and cheerfull - doesnt handle spaces inside the strings...
|
||||
*
|
||||
* @param string the key value part of the tag..
|
||||
*
|
||||
* @return array key value array
|
||||
* @access private
|
||||
*/
|
||||
function convertAttributesToKeyVal($str)
|
||||
{
|
||||
$atts = explode(' ', $str);
|
||||
$ret = array();
|
||||
foreach($atts as $bit) {
|
||||
$bits = explode('=',$bit);
|
||||
// loose stuff!!!
|
||||
if (count($bits) != 2) {
|
||||
continue;
|
||||
}
|
||||
$ret[$bits[0]] = ($bits[1]{0} == '"') ? substr($bits[1],1,-1) : $bits[1];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* convert a smarty config var into a flexy one.
|
||||
*
|
||||
* @param string the inside of the smart tag
|
||||
*
|
||||
* @return string a flexy version of it.
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _convertConfigVar($str)
|
||||
{
|
||||
$mods = explode('|', $str);
|
||||
$var = array_shift($mods);
|
||||
$var = substr($var,1,-1); // strip #'s
|
||||
$mods = implode('|',$mods);
|
||||
if (strlen($mods)) {
|
||||
$mods = "<!-- UNSUPPORTED MODIFIERS: $mods -->";
|
||||
}
|
||||
return '{configVars.'.$var .'}' . $mods;
|
||||
}
|
||||
}
|
||||
910
HTML/Template/Flexy/Compiler/Standard.php
Normal file
910
HTML/Template/Flexy/Compiler/Standard.php
Normal file
|
|
@ -0,0 +1,910 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Standard.php,v 1.43 2005/02/08 05:35:27 alan_k Exp $
|
||||
//
|
||||
// Base Compiler Class
|
||||
// Standard 'Original Flavour' Flexy compiler
|
||||
|
||||
/*------------------------------------------------------------------------------------------
|
||||
NOTICE:
|
||||
THIS COMPILER IS DEPRECIATED
|
||||
USE THE FLEXY COMPILER
|
||||
|
||||
The Flexy Compiler should be Compatible
|
||||
|
||||
------------------------------------------------------------------------------------------*/
|
||||
|
||||
require_once 'HTML/Template/Flexy/Tokenizer.php';
|
||||
require_once 'HTML/Template/Flexy/Token.php';
|
||||
|
||||
// cache for po files..
|
||||
$GLOBALS['_html_template_flexy_compiler_standard']['PO'] = array();
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Standard extends HTML_Template_Flexy_Compiler
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The compile method.
|
||||
*
|
||||
* @params object HTML_Template_Flexy
|
||||
* @params string|false string to compile of false to use a file.
|
||||
* @return string filename of template
|
||||
* @access public
|
||||
*/
|
||||
function compile(&$flexy,$string=false)
|
||||
{
|
||||
// read the entire file into one variable
|
||||
|
||||
// note this should be moved to new HTML_Template_Flexy_Token
|
||||
// and that can then manage all the tokens in one place..
|
||||
global $_HTML_TEMPLATE_FLEXY_COMPILER;
|
||||
|
||||
$gettextStrings = &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
|
||||
$gettextStrings = array(); // reset it.
|
||||
|
||||
if (@$this->options['debug']) {
|
||||
echo "compiling template $flexy->currentTemplate<BR>";
|
||||
|
||||
}
|
||||
|
||||
// reset the elements.
|
||||
$flexy->_elements = array();
|
||||
|
||||
// replace this with a singleton??
|
||||
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'] = $this->options;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'] = array();
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'] = $flexy->currentTemplate;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] = '';
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['compiledTemplate'] = $flexy->compiledTemplate;
|
||||
|
||||
if (is_array($this->options['Translation2'])) {
|
||||
require_once 'Translation2.php';
|
||||
$this->options['Translation2'] = new Translation2(
|
||||
$this->options['Translation2']['driver'],
|
||||
@$this->options['Translation2']['options']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (is_a($this->options['Translation2'],'Translation2')) {
|
||||
$this->options['Translation2']->setLang($this->options['locale']);
|
||||
// fixme - needs to be more specific to which template to use..
|
||||
foreach ($this->options['templateDir'] as $tt) {
|
||||
$n = basename($flexy->currentTemplate);
|
||||
if (substr($flexy->currentTemplate,0,strlen($tt)) == $tt) {
|
||||
$n = substr($flexy->currentTemplate,strlen($tt)+1);
|
||||
}
|
||||
//echo $n;
|
||||
}
|
||||
$this->options['Translation2']->setPageID($n);
|
||||
} else {
|
||||
setlocale(LC_ALL, $this->options['locale']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$data = $string;
|
||||
$res = false;
|
||||
if ($string === false) {
|
||||
$data = file_get_contents($flexy->currentTemplate);
|
||||
}
|
||||
|
||||
// PRE PROCESS {_(.....)} translation markers.
|
||||
$got_gettext_markup = false;
|
||||
|
||||
|
||||
|
||||
if (strpos($data,'{_(') !== false) {
|
||||
$matches = array();
|
||||
$lmatches = explode ('{_(', $data);
|
||||
array_shift($lmatches);
|
||||
// shift the first..
|
||||
foreach ($lmatches as $k) {
|
||||
if (false === strpos($k,')_}')) {
|
||||
continue;
|
||||
}
|
||||
$x = explode(')_}',$k);
|
||||
$matches[] = $x[0];
|
||||
}
|
||||
|
||||
|
||||
//echo '<PRE>';print_r($matches);
|
||||
// we may need to do some house cleaning here...
|
||||
$gettextStrings = $matches;
|
||||
$got_gettext_markup = true;
|
||||
|
||||
|
||||
// replace them now..
|
||||
// ** leaving in the tag (which should be ignored by the parser..
|
||||
// we then get rid of the tags during the toString method in this class.
|
||||
foreach($matches as $v) {
|
||||
$data = str_replace('{_('.$v.')_}', '{_('.$this->translateString($v).')_}',$data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)])) {
|
||||
$res = $_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)];
|
||||
} else {
|
||||
|
||||
|
||||
$tokenizer = new HTML_Template_Flexy_Tokenizer($data);
|
||||
$tokenizer->fileName = $flexy->currentTemplate;
|
||||
|
||||
|
||||
//$tokenizer->debug=1;
|
||||
$tokenizer->options['ignore_html'] = $this->options['nonHTML'];
|
||||
$tokenizer->options['ignore_php'] = !$this->options['allowPHP'];
|
||||
|
||||
$res = HTML_Template_Flexy_Token::buildTokens($tokenizer);
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)] = $res;
|
||||
|
||||
}
|
||||
|
||||
if (is_a($res,'PEAR_Error')) {
|
||||
return $res;
|
||||
}
|
||||
// turn tokens into Template..
|
||||
|
||||
$data = $res->compile($this);
|
||||
|
||||
if (is_a($data,'PEAR_Error')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] . $data;
|
||||
|
||||
if ( @$this->options['debug']) {
|
||||
echo "<B>Result: </B><PRE>".htmlspecialchars($data)."</PRE><BR>";
|
||||
|
||||
}
|
||||
|
||||
if ($this->options['nonHTML']) {
|
||||
$data = str_replace("?>\n","?>\n\n",$data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// at this point we are into writing stuff...
|
||||
if ($this->options['compileToString']) {
|
||||
$flexy->elements = $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// error checking?
|
||||
$file = $flexy->compiledTemplate;
|
||||
if (isset($flexy->options['output.block'])) {
|
||||
list($file,$part) = explode('#',$file );
|
||||
}
|
||||
|
||||
if( ($cfp = fopen( $file , 'w' )) ) {
|
||||
if (@$this->options['debug']) {
|
||||
echo "<B>Writing: </B>".htmlspecialchars($data)."<BR>";
|
||||
|
||||
}
|
||||
fwrite($cfp,$data);
|
||||
fclose($cfp);
|
||||
|
||||
chmod($file,0775);
|
||||
// make the timestamp of the two items match.
|
||||
clearstatcache();
|
||||
touch($file, filemtime($flexy->currentTemplate));
|
||||
if ($file != $flexy->compiledTemplate) {
|
||||
chmod($flexy->compiledTemplate,0775);
|
||||
// make the timestamp of the two items match.
|
||||
clearstatcache();
|
||||
touch($flexy->compiledTemplate, filemtime($flexy->currentTemplate));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::failed to write to '.$flexy->compiledTemplate,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_FILE ,HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
// gettext strings
|
||||
if (file_exists($flexy->getTextStringsFile)) {
|
||||
unlink($flexy->getTextStringsFile);
|
||||
}
|
||||
|
||||
if($gettextStrings && ($cfp = fopen( $flexy->getTextStringsFile, 'w') ) ) {
|
||||
|
||||
fwrite($cfp,serialize(array_unique($gettextStrings)));
|
||||
fclose($cfp);
|
||||
}
|
||||
|
||||
// elements
|
||||
if (file_exists($flexy->elementsFile)) {
|
||||
unlink($flexy->elementsFile);
|
||||
}
|
||||
|
||||
if( $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'] &&
|
||||
($cfp = fopen( $flexy->elementsFile, 'w') ) ) {
|
||||
fwrite($cfp,serialize( $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']));
|
||||
fclose($cfp);
|
||||
// now clear it.
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag indicating compiler is inside {_( .... )_} block, and should not
|
||||
* add to the gettextstrings array.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $inGetTextBlock = false;
|
||||
|
||||
/**
|
||||
* This is the base toString Method, it relays into toString{TokenName}
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_*
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toString($element)
|
||||
{
|
||||
static $len = 26; // strlen('HTML_Template_Flexy_Token_');
|
||||
if ($this->options['debug']) {
|
||||
$x = $element;
|
||||
unset($x->children);
|
||||
echo htmlspecialchars(print_r($x,true))."<BR>\n";
|
||||
}
|
||||
if ($element->token == 'GetTextStart') {
|
||||
$this->inGetTextBlock = true;
|
||||
return '';
|
||||
}
|
||||
if ($element->token == 'GetTextEnd') {
|
||||
$this->inGetTextBlock = false;
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$class = get_class($element);
|
||||
if (strlen($class) >= $len) {
|
||||
$type = substr($class,$len);
|
||||
return $this->{'toString'.$type}($element);
|
||||
}
|
||||
|
||||
$ret = $element->value;
|
||||
$add = $element->compileChildren($this);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
|
||||
if ($element->close) {
|
||||
$add = $element->close->compile($this);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Else toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Else
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringElse($element)
|
||||
{
|
||||
// pushpull states to make sure we are in an area.. - should really check to see
|
||||
// if the state it is pulling is a if...
|
||||
if ($element->pullState() === false) {
|
||||
return $this->appendHTML(
|
||||
"<font color=\"red\">Unmatched {else:} on line: {$element->line}</font>"
|
||||
);
|
||||
}
|
||||
$element->pushState();
|
||||
return $this->appendPhp("} else {");
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_End toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Else
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringEnd($element)
|
||||
{
|
||||
// pushpull states to make sure we are in an area.. - should really check to see
|
||||
// if the state it is pulling is a if...
|
||||
if ($element->pullState() === false) {
|
||||
return $this->appendHTML(
|
||||
"<font color=\"red\">Unmatched {end:} on line: {$element->line}</font>"
|
||||
);
|
||||
}
|
||||
|
||||
return $this->appendPhp("}");
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_EndTag toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_EndTag
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function toStringEndTag($element)
|
||||
{
|
||||
return $this->toStringTag($element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Foreach toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Foreach
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringForeach($element)
|
||||
{
|
||||
|
||||
$loopon = $element->toVar($element->loopOn);
|
||||
if (is_a($loopon,'PEAR_Error')) {
|
||||
return $loopon;
|
||||
}
|
||||
|
||||
$ret = 'if ($this->options[\'strict\'] || ('.
|
||||
'is_array('. $loopon. ') || ' .
|
||||
'is_object(' . $loopon . '))) ' .
|
||||
'foreach(' . $loopon . " ";
|
||||
|
||||
$ret .= "as \${$element->key}";
|
||||
|
||||
if ($element->value) {
|
||||
$ret .= " => \${$element->value}";
|
||||
}
|
||||
$ret .= ") {";
|
||||
|
||||
$element->pushState();
|
||||
$element->pushVar($element->key);
|
||||
$element->pushVar($element->value);
|
||||
return $this->appendPhp($ret);
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_If toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_If
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringIf($element)
|
||||
{
|
||||
|
||||
$var = $element->toVar($element->condition);
|
||||
if (is_a($var,'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
$ret = "if (".$element->isNegative . $var .") {";
|
||||
$element->pushState();
|
||||
return $this->appendPhp($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Modifier Wrapper
|
||||
*
|
||||
* converts :h, :u, :r , .....
|
||||
* @param object HTML_Template_Flexy_Token_Method|Var
|
||||
*
|
||||
* @return array prefix,suffix
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function getModifierWrapper($element)
|
||||
{
|
||||
$prefix = 'echo ';
|
||||
|
||||
$suffix = '';
|
||||
$modifier = strlen(trim($element->modifier)) ? $element->modifier : ' ';
|
||||
|
||||
switch ($modifier{0}) {
|
||||
case 'h':
|
||||
break;
|
||||
case 'u':
|
||||
$prefix = 'echo urlencode(';
|
||||
$suffix = ')';
|
||||
break;
|
||||
case 'r':
|
||||
$prefix = 'echo \'<pre>\'; echo htmlspecialchars(print_r(';
|
||||
$suffix = ',true)); echo \'</pre>\';';
|
||||
break;
|
||||
case 'n':
|
||||
// blank or value..
|
||||
$numberformat = @$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'];
|
||||
$prefix = 'echo number_format(';
|
||||
$suffix = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'] . ')';
|
||||
break;
|
||||
case 'b': // nl2br + htmlspecialchars
|
||||
$prefix = 'echo nl2br(htmlspecialchars(';
|
||||
|
||||
// add language ?
|
||||
$suffix = '))';
|
||||
break;
|
||||
case ' ':
|
||||
$prefix = 'echo htmlspecialchars(';
|
||||
// add language ?
|
||||
$suffix = ')';
|
||||
break;
|
||||
default:
|
||||
$prefix = 'echo $this->plugin("'.trim($element->modifier) .'",';
|
||||
$suffix = ')';
|
||||
|
||||
|
||||
}
|
||||
|
||||
return array($prefix,$suffix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Var toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Method
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringVar($element)
|
||||
{
|
||||
// ignore modifier at present!!
|
||||
|
||||
$var = $element->toVar($element->value);
|
||||
if (is_a($var,'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
list($prefix,$suffix) = $this->getModifierWrapper($element);
|
||||
return $this->appendPhp( $prefix . $var . $suffix .';');
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Method toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Method
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringMethod($element)
|
||||
{
|
||||
|
||||
|
||||
// set up the modifier at present!!
|
||||
list($prefix,$suffix) = $this->getModifierWrapper($element);
|
||||
|
||||
// add the '!' to if
|
||||
|
||||
if ($element->isConditional) {
|
||||
$prefix = 'if ('.$element->isNegative;
|
||||
$element->pushState();
|
||||
$suffix = ')';
|
||||
}
|
||||
|
||||
|
||||
// check that method exists..
|
||||
// if (method_exists($object,'method');
|
||||
$bits = explode('.',$element->method);
|
||||
$method = array_pop($bits);
|
||||
|
||||
$object = implode('.',$bits);
|
||||
|
||||
$var = $element->toVar($object);
|
||||
if (is_a($var,'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
if (($object == 'GLOBALS') &&
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globalfunctions']) {
|
||||
// we should check if they something weird like: GLOBALS.xxxx[sdf](....)
|
||||
$var = $method;
|
||||
} else {
|
||||
$prefix = 'if ($this->options[\'strict\'] || (isset('.$var.
|
||||
') && method_exists('.$var .",'{$method}'))) " . $prefix;
|
||||
$var = $element->toVar($element->method);
|
||||
}
|
||||
|
||||
|
||||
if (is_a($var,'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
$ret = $prefix;
|
||||
$ret .= $var . "(";
|
||||
$s =0;
|
||||
|
||||
|
||||
|
||||
foreach($element->args as $a) {
|
||||
|
||||
if ($s) {
|
||||
$ret .= ",";
|
||||
}
|
||||
$s =1;
|
||||
if ($a{0} == '#') {
|
||||
$ret .= '"'. addslashes(substr($a,1,-1)) . '"';
|
||||
continue;
|
||||
}
|
||||
|
||||
$var = $element->toVar($a);
|
||||
if (is_a($var,'PEAR_Error')) {
|
||||
return $var;
|
||||
}
|
||||
$ret .= $var;
|
||||
|
||||
}
|
||||
$ret .= ")" . $suffix;
|
||||
|
||||
if ($element->isConditional) {
|
||||
$ret .= ' { ';
|
||||
} else {
|
||||
$ret .= ";";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->appendPhp($ret);
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Processing toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Processing
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
function toStringProcessing($element)
|
||||
{
|
||||
// if it's XML then quote it..
|
||||
if (strtoupper(substr($element->value,2,3)) == 'XML') {
|
||||
return $this->appendPhp("echo '" . str_replace("'","\\"."'", $element->value) . "';");
|
||||
}
|
||||
// otherwise it's PHP code - so echo it..
|
||||
return $element->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Text toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Text
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function toStringText($element)
|
||||
{
|
||||
|
||||
// first get rid of stuff thats not translated etc.
|
||||
// empty strings => output.
|
||||
// comments -> just output
|
||||
// our special tags -> output..
|
||||
|
||||
if (!strlen(trim($element->value) )) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
// dont add comments to translation lists.
|
||||
|
||||
if (substr($element->value,0,4) == '<!--') {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
// ignore anything wrapped with {_( .... )_}
|
||||
if ($this->inGetTextBlock) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
|
||||
// argTokens is built before the tag matching (it combined
|
||||
// flexy tags into %s, into the string,
|
||||
// and made a list of tokens in argTokens.
|
||||
|
||||
if (!count($element->argTokens) && !$element->isWord()) {
|
||||
return $this->appendHtml($element->value);
|
||||
}
|
||||
|
||||
// grab the white space at start and end (and keep it!
|
||||
|
||||
$value = ltrim($element->value);
|
||||
$front = substr($element->value,0,-strlen($value));
|
||||
$value = rtrim($element->value);
|
||||
$rear = substr($element->value,strlen($value));
|
||||
$value = trim($element->value);
|
||||
|
||||
|
||||
// convert to escaped chars.. (limited..)
|
||||
//$value = strtr($value,$cleanArray);
|
||||
|
||||
$this->addStringToGettext($value);
|
||||
$value = $this->translateString($value);
|
||||
// its a simple word!
|
||||
if (!count($element->argTokens)) {
|
||||
return $this->appendHtml($front . $value . $rear);
|
||||
}
|
||||
|
||||
|
||||
// there are subtokens..
|
||||
// print_r($element->argTokens );
|
||||
$args = array();
|
||||
// these should only be text or vars..
|
||||
|
||||
foreach($element->argTokens as $i=>$token) {
|
||||
$args[] = $token->compile($this);
|
||||
}
|
||||
|
||||
// we break up the translated string, and put the compiled tags
|
||||
// in between the values here.
|
||||
|
||||
$bits = explode('%s',$value);
|
||||
$ret = $front;
|
||||
|
||||
foreach($bits as $i=>$v) {
|
||||
$ret .= $v . @$args[$i];
|
||||
}
|
||||
|
||||
return $ret . $rear;
|
||||
|
||||
}
|
||||
/**
|
||||
* addStringToGettext
|
||||
*
|
||||
* Adds a string to the gettext array.
|
||||
*
|
||||
* @param mixed preferably.. string to store
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function addStringToGettext($string)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if (!is_string($string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('/[a-z]+/i', $string)) {
|
||||
return;
|
||||
}
|
||||
$string = trim($string);
|
||||
|
||||
if (substr($string,0,4) == '<!--') {
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_COMPILER']['gettextStrings'][] = $string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translateString - a gettextWrapper
|
||||
*
|
||||
* tries to do gettext or falls back on File_Gettext
|
||||
* This has !!!NO!!! error handling - if it fails you just get english..
|
||||
* no questions asked!!!
|
||||
*
|
||||
* @param string string to translate
|
||||
*
|
||||
* @return string translated string..
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function translateString($string)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (is_a($this->options['Translation2'],'Translation2')) {
|
||||
$result = $this->options['Translation2']->get($string);
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
// note this stuff may have been broken by removing the \n replacement code
|
||||
// since i dont have a test for it... it may remain broken..
|
||||
// use Translation2 - it has gettext backend support
|
||||
// and should sort out the mess that \n etc. entail.
|
||||
|
||||
|
||||
$prefix = basename($GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']).':';
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":TRANSLATING $string<BR>";
|
||||
}
|
||||
if (function_exists('gettext') && !$this->options['textdomain']) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":USING GETTEXT?<BR>";
|
||||
}
|
||||
$t = gettext($string);
|
||||
if ($t != $string) {
|
||||
return $t;
|
||||
}
|
||||
$tt = gettext($prefix.$string);
|
||||
if ($tt != $prefix.$string) {
|
||||
return $tt;
|
||||
}
|
||||
// give up it's not translated anywhere...
|
||||
return $t;
|
||||
|
||||
}
|
||||
if (!$this->options['textdomain'] || !$this->options['textdomainDir']) {
|
||||
// text domain is not set..
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":MISSING textdomain settings<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
$pofile = $this->options['textdomainDir'] .
|
||||
'/' . $this->options['locale'] .
|
||||
'/LC_MESSAGES/' . $this->options['textdomain'] . '.po';
|
||||
|
||||
|
||||
// did we try to load it already..
|
||||
if (@$GLOBALS['_'.__CLASS__]['PO'][$pofile] === false) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD failed (Cached):<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
if (!@$GLOBALS['_'.__CLASS__]['PO'][$pofile]) {
|
||||
// default - cant load it..
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile] = false;
|
||||
if (!file_exists($pofile)) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD failed: {$pofile}<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
if (!@include_once 'File/Gettext.php') {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":LOAD no File_gettext:<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile] = File_Gettext::factory('PO',$pofile);
|
||||
$GLOBALS['_'.__CLASS__]['PO'][$pofile]->load();
|
||||
//echo '<PRE>'.htmlspecialchars(print_r($GLOBALS['_'.__CLASS__]['PO'][$pofile]->strings,true));
|
||||
|
||||
}
|
||||
$po = &$GLOBALS['_'.__CLASS__]['PO'][$pofile];
|
||||
// we should have it loaded now...
|
||||
// this is odd - data is a bit messed up with CR's
|
||||
$string = str_replace('\n',"\n",$string);
|
||||
|
||||
if (isset($po->strings[$prefix.$string])) {
|
||||
return $po->strings[$prefix.$string];
|
||||
}
|
||||
|
||||
if (!isset($po->strings[$string])) {
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":no match:<BR>";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
if (@$this->options['debug']) {
|
||||
echo __CLASS__.":MATCHED: {$po->strings[$string]}<BR>";
|
||||
}
|
||||
|
||||
// finally we have a match!!!
|
||||
return $po->strings[$string];
|
||||
|
||||
}
|
||||
/**
|
||||
* HTML_Template_Flexy_Token_Tag toString
|
||||
*
|
||||
* @param object HTML_Template_Flexy_Token_Tag
|
||||
*
|
||||
* @return string string to build a template
|
||||
* @access public
|
||||
* @see toString*
|
||||
*/
|
||||
|
||||
function toStringTag($element) {
|
||||
if (strpos($element->tag,':') === false) {
|
||||
$namespace = 'Tag';
|
||||
} else {
|
||||
$bits = explode(':',$element->tag);
|
||||
$namespace = $bits[0];
|
||||
}
|
||||
if ($namespace{0} == '/') {
|
||||
$namespace = substr($namespace,1);
|
||||
}
|
||||
if (empty($this->tagHandlers[$namespace])) {
|
||||
|
||||
require_once 'HTML/Template/Flexy/Compiler/Standard/Tag.php';
|
||||
$this->tagHandlers[$namespace] = &HTML_Template_Flexy_Compiler_Standard_Tag::factory($namespace,$this);
|
||||
if (!$this->tagHandlers[$namespace] ) {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::failed to create Namespace Handler '.$namespace .
|
||||
' in file ' . $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'],
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
|
||||
}
|
||||
return $this->tagHandlers[$namespace]->toString($element);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
218
HTML/Template/Flexy/Compiler/Standard/Flexy.php
Normal file
218
HTML/Template/Flexy/Compiler/Standard/Flexy.php
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akkbhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Flexy.php,v 1.15 2004/06/24 06:12:06 alan_k Exp $
|
||||
//
|
||||
// Handler code for the <flexy: namespace
|
||||
//
|
||||
|
||||
/**
|
||||
* the <flexy:XXXX namespace
|
||||
*
|
||||
*
|
||||
* at present it handles
|
||||
* <flexy:toJavascript flexy:prefix="Javascript_prefix" javscriptName="PHPvar" .....>
|
||||
* <flexy:include src="xxx.htm">
|
||||
*
|
||||
*
|
||||
*
|
||||
* @version $Id: Flexy.php,v 1.15 2004/06/24 06:12:06 alan_k Exp $
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Standard_Flexy {
|
||||
|
||||
|
||||
/**
|
||||
* Parent Compiler for
|
||||
*
|
||||
* @var object HTML_Template_Flexy_Compiler
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $compiler;
|
||||
|
||||
|
||||
/**
|
||||
* The current element to parse..
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $element;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* toString - display tag, attributes, postfix and any code in attributes.
|
||||
* Relays into namspace::method to get results..
|
||||
*
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
function toString($element)
|
||||
{
|
||||
|
||||
list($namespace,$method) = explode(':',$element->oTag);
|
||||
if (!strlen($method)) {
|
||||
return '';
|
||||
}
|
||||
// things we dont handle...
|
||||
if (!method_exists($this,$method.'ToString')) {
|
||||
return '';
|
||||
}
|
||||
return $this->{$method.'ToString'}($element);
|
||||
|
||||
}
|
||||
/**
|
||||
* toJavascript handler
|
||||
* <flexy:toJavascript flexy:prefix="some_prefix_" javascriptval="php.val" ....>
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
|
||||
function toJavascriptToString($element)
|
||||
{
|
||||
$ret = $this->compiler->appendPhp( "require_once 'HTML/Javascript/Convert.php';");
|
||||
$ret .= $this->compiler->appendHTML("\n<script type='text/javascript'>\n");
|
||||
$prefix = ''. $element->getAttribute('FLEXY:PREFIX');
|
||||
|
||||
|
||||
foreach ($element->attributes as $k=>$v) {
|
||||
// skip directives..
|
||||
if (strpos($k,':')) {
|
||||
continue;
|
||||
}
|
||||
if ($k == '/') {
|
||||
continue;
|
||||
}
|
||||
$v = substr($v,1,-1);
|
||||
$ret .= $this->compiler->appendPhp(
|
||||
'$__tmp = HTML_Javascript_Convert::convertVar('.$element->toVar($v) .',\''.$prefix . $k.'\',true);'.
|
||||
'echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;');
|
||||
$ret .= $this->compiler->appendHTML("\n");
|
||||
}
|
||||
$ret .= $this->compiler->appendHTML("</script>");
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* include handler
|
||||
* <flexy:include src="test.html">
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
function includeToString($element)
|
||||
{
|
||||
// this is disabled by default...
|
||||
// we ignore modifier pre/suffix
|
||||
|
||||
|
||||
|
||||
|
||||
$arg = $element->getAttribute('SRC');
|
||||
if (!$arg) {
|
||||
return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename</B>");
|
||||
}
|
||||
// ideally it would be nice to embed the results of one template into another.
|
||||
// however that would involve some complex test which would have to stat
|
||||
// the child templates anyway..
|
||||
// compile the child template....
|
||||
// output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
|
||||
return $this->compiler->appendPHP( "\n".
|
||||
"\$x = new HTML_Template_Flexy(\$this->options);\n".
|
||||
"\$x->compile('{$arg}');\n".
|
||||
"\$x->outputObject(\$t);\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert flexy tokens to HTML_Template_Flexy_Elements.
|
||||
*
|
||||
* @param object token to convert into a element.
|
||||
* @return object HTML_Template_Flexy_Element
|
||||
* @access public
|
||||
*/
|
||||
function toElement($element)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for User defined functions in templates..
|
||||
* <flexy:function name="xxxxx">.... </flexy:block> // equivilant to function xxxxx() {
|
||||
* <flexy:function call="{xxxxx}">.... </flexy:block> // equivilant to function {$xxxxx}() {
|
||||
* <flexy:function call="xxxxx">.... </flexy:block> // equivilant to function {$xxxxx}() {
|
||||
*
|
||||
* This will not handle nested blocks initially!! (and may cause even more problems with
|
||||
* if /foreach stuff..!!
|
||||
*
|
||||
* @param object token to convert into a element.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function functionToString($element)
|
||||
{
|
||||
|
||||
if ($arg = $element->getAttribute('NAME')) {
|
||||
// this is a really kludgy way of doing this!!!
|
||||
// hopefully the new Template Package will have a sweeter method..
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] .=
|
||||
$this->compiler->appendPHP(
|
||||
"\nfunction _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this) {\n").
|
||||
$element->compileChildren($this->compiler) .
|
||||
$this->compiler->appendPHP( "\n}\n");
|
||||
|
||||
return '';
|
||||
}
|
||||
if (!isset($element->ucAttributes['CALL'])) {
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
' tag flexy:function needs an argument call or name'.
|
||||
" Error on Line {$element->line} <{$element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
// call is a stirng : nice and simple..
|
||||
if (is_string($element->ucAttributes['CALL'])) {
|
||||
$arg = $element->getAttribute('CALL');
|
||||
return $this->compiler->appendPHP(
|
||||
"if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$arg})) " .
|
||||
" _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this);");
|
||||
}
|
||||
|
||||
// we make a big assumption here.. - it should really be error checked..
|
||||
// that the {xxx} element is item 1 in the list...
|
||||
$e=$element->ucAttributes['CALL'][1];
|
||||
$add = $e->toVar($e->value);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
return $this->compiler->appendPHP(
|
||||
"if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$add})) ".
|
||||
"call_user_func_array('_html_template_flexy_compiler_standard_flexy_'.{$add},array(\$t,\$this));");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
893
HTML/Template/Flexy/Compiler/Standard/Tag.php
Normal file
893
HTML/Template/Flexy/Compiler/Standard/Tag.php
Normal file
|
|
@ -0,0 +1,893 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Tag.php,v 1.50 2004/07/29 04:26:24 alan_k Exp $
|
||||
/* FC/BC compatibility with php5 */
|
||||
if ( (substr(phpversion(),0,1) < 5) && !function_exists('clone')) {
|
||||
eval('function clone($t) { return $t; }');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiler That deals with standard HTML Tag output.
|
||||
* Since it's pretty complex it has it's own class.
|
||||
* I guess this class should deal with the main namespace
|
||||
* and the parent (standard compiler can redirect other namespaces to other classes.
|
||||
*
|
||||
* one instance of these exists for each namespace.
|
||||
*
|
||||
*
|
||||
* @version $Id: Tag.php,v 1.50 2004/07/29 04:26:24 alan_k Exp $
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Compiler_Standard_Tag {
|
||||
|
||||
|
||||
/**
|
||||
* Parent Compiler for
|
||||
*
|
||||
* @var object HTML_Template_Flexy_Compiler
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $compiler;
|
||||
|
||||
/**
|
||||
*
|
||||
* Factory method to create Tag Handlers
|
||||
*
|
||||
* $type = namespace eg. <flexy:toJavascript loads Flexy.php
|
||||
* the default is this... (eg. Tag)
|
||||
*
|
||||
*
|
||||
* @param string Namespace handler for element.
|
||||
* @param object HTML_Template_Flexy_Compiler
|
||||
*
|
||||
*
|
||||
* @return object tag compiler
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function &factory($type,&$compiler) {
|
||||
if (!$type) {
|
||||
$type = 'Tag';
|
||||
}
|
||||
// if we dont have a handler - just use the basic handler.
|
||||
if (!file_exists(dirname(__FILE__) . '/'. ucfirst(strtolower($type)) . '.php')) {
|
||||
$type = 'Tag';
|
||||
}
|
||||
|
||||
include_once 'HTML/Template/Flexy/Compiler/Standard/' . ucfirst(strtolower($type)) . '.php';
|
||||
|
||||
$class = 'HTML_Template_Flexy_Compiler_Standard_' . $type;
|
||||
if (!class_exists($class)) {
|
||||
return false;
|
||||
}
|
||||
$ret = new $class;
|
||||
$ret->compiler = &$compiler;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The current element to parse..
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $element;
|
||||
|
||||
/**
|
||||
* Flag to indicate has attribute flexy:foreach (so you cant mix it with flexy:if!)
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $hasForeach = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* toString - display tag, attributes, postfix and any code in attributes.
|
||||
* Note first thing it does is call any parseTag Method that exists..
|
||||
*
|
||||
*
|
||||
* @see parent::toString()
|
||||
*/
|
||||
function toString($element)
|
||||
{
|
||||
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
global $_HTML_TEMPLATE_FLEXY;
|
||||
|
||||
// store the element in a variable
|
||||
$this->element = $element;
|
||||
// echo "toString: Line {$this->element->line} <{$this->element->tag}>\n";
|
||||
|
||||
// if the FLEXYSTARTCHILDREN flag was set, only do children
|
||||
// normally set in BODY tag.
|
||||
// this will probably be superseeded by the Class compiler.
|
||||
|
||||
if (isset($element->ucAttributes['FLEXY:STARTCHILDREN'])) {
|
||||
|
||||
return $element->compileChildren($this->compiler);
|
||||
}
|
||||
|
||||
$flexyignore = $this->parseAttributeIgnore();
|
||||
|
||||
// rewriting should be done with a tag.../flag.
|
||||
|
||||
$this->reWriteURL("HREF");
|
||||
$this->reWriteURL("SRC");
|
||||
|
||||
// handle elements
|
||||
if (($ret =$this->_parseTags()) !== false) {
|
||||
return $ret;
|
||||
}
|
||||
// these add to the close tag..
|
||||
|
||||
$ret = $this->parseAttributeForeach();
|
||||
$ret .= $this->parseAttributeIf();
|
||||
|
||||
// spit ou the tag and attributes.
|
||||
|
||||
if ($element->oTag{0} == '?') {
|
||||
$ret .= '<?php echo "<"; ?>';
|
||||
} else {
|
||||
$ret .= "<";
|
||||
}
|
||||
$ret .= $element->oTag;
|
||||
|
||||
foreach ($element->attributes as $k=>$v) {
|
||||
// if it's a flexy tag ignore it.
|
||||
|
||||
|
||||
if (strtoupper($k) == 'FLEXY:RAW') {
|
||||
if (!is_array($v) || !isset($v[1]) || !is_object($v[1])) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
'flexy:raw only accepts a variable or method call as an argument, eg.'.
|
||||
' flexy:raw="{somevalue}" you provided something else.' .
|
||||
" Error on Line {$this->element->line} <{$this->element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
$add = $v[1]->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= ' ' . $add;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (strtoupper(substr($k,0,6)) == 'FLEXY:') {
|
||||
continue;
|
||||
}
|
||||
// true == an attribute without a ="xxx"
|
||||
if ($v === true) {
|
||||
$ret .= " $k";
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it's a string just dump it.
|
||||
if (is_string($v)) {
|
||||
$ret .= " {$k}={$v}";
|
||||
continue;
|
||||
}
|
||||
|
||||
// normally the value is an array of string, however
|
||||
// if it is an object - then it's a conditional key.
|
||||
// eg. if (something) echo ' SELECTED';
|
||||
// the object is responsible for adding it's space..
|
||||
|
||||
if (is_object($v)) {
|
||||
$add = $v->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
|
||||
$ret .= $add;
|
||||
continue;
|
||||
}
|
||||
|
||||
// otherwise its a key="sometext{andsomevars}"
|
||||
|
||||
$ret .= " {$k}=";
|
||||
|
||||
foreach($v as $item) {
|
||||
if (is_string($item)) {
|
||||
$ret .= $item;
|
||||
continue;
|
||||
}
|
||||
$add = $item->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
}
|
||||
$ret .= ">";
|
||||
|
||||
// post stuff this is probably in the wrong place...
|
||||
|
||||
if ($element->postfix) {
|
||||
foreach ($element->postfix as $e) {
|
||||
$add = $e->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
} else if ($this->element->postfix) { // if postfixed by self..
|
||||
foreach ($this->element->postfix as $e) {
|
||||
$add = $e->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
|
||||
$ret .= $add;
|
||||
}
|
||||
}
|
||||
// dump contents of script raw - to prevent gettext additions..
|
||||
// print_r($element);
|
||||
if ($element->tag == 'SCRIPT') {
|
||||
foreach($element->children as $c) {
|
||||
//print_R($c);
|
||||
if (!$c) {
|
||||
continue;
|
||||
}
|
||||
if ($c->token == 'Text') {
|
||||
$ret .= $c->value;
|
||||
continue;
|
||||
}
|
||||
// techically we shouldnt have anything else inside of script tags.
|
||||
// as the tokeinzer is supposted to ignore it..
|
||||
}
|
||||
} else {
|
||||
$add = $element->compileChildren($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// output the closing tag.
|
||||
|
||||
if ($element->close) {
|
||||
$add = $element->close->compile($this->compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
|
||||
// reset flexyignore
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = $flexyignore;
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block']) &&
|
||||
($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block'] == $element->getAttribute('ID'))) {
|
||||
|
||||
// echo $_HTML_TEMPLATE_FLEXY['compiledTemplate'];
|
||||
|
||||
$fh = fopen($_HTML_TEMPLATE_FLEXY['compiledTemplate'],'w');
|
||||
fwrite($fh,$ret);
|
||||
fclose($fh);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* Reads an flexy:foreach attribute -
|
||||
*
|
||||
*
|
||||
* @return string to add to output.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseAttributeIgnore()
|
||||
{
|
||||
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
$flexyignore = $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'];
|
||||
|
||||
if ($this->element->getAttribute('FLEXY:IGNORE') !== false) {
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = true;
|
||||
$this->element->clearAttribute('FLEXY:IGNORE');
|
||||
}
|
||||
return $flexyignore;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an flexy:foreach attribute -
|
||||
*
|
||||
*
|
||||
* @return string to add to output.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseAttributeForeach()
|
||||
{
|
||||
$foreach = $this->element->getAttribute('FLEXY:FOREACH');
|
||||
if ($foreach === false) {
|
||||
return '';
|
||||
}
|
||||
//var_dump($foreach);
|
||||
|
||||
$this->element->hasForeach = true;
|
||||
// create a foreach element to wrap this with.
|
||||
|
||||
$foreachObj = $this->element->factory('Foreach',
|
||||
explode(',',$foreach),
|
||||
$this->element->line);
|
||||
// failed = probably not enough variables..
|
||||
|
||||
|
||||
if ($foreachObj === false) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"Missing Arguments: An flexy:foreach attribute was foundon Line {$this->element->line}
|
||||
in tag <{$this->element->tag} flexy:foreach="$foreach" .....><BR>
|
||||
the syntax is <sometag flexy:foreach="onarray,withvariable[,withanothervar] ><BR>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// does it have a closetag?
|
||||
if (!$this->element->close) {
|
||||
|
||||
if ($this->element->getAttribute('/') === false) {
|
||||
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"A flexy:foreach attribute was found in <{$this->element->name} tag without a corresponding </{$this->element->tag}
|
||||
tag on Line {$this->element->line} <{$this->element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
// it's an xhtml tag!
|
||||
$this->element->postfix = array($this->element->factory("End", '', $this->element->line));
|
||||
} else {
|
||||
$this->element->close->postfix = array($this->element->factory("End", '', $this->element->line));
|
||||
}
|
||||
|
||||
$this->element->clearAttribute('FLEXY:FOREACH');
|
||||
return $foreachObj->compile($this->compiler);
|
||||
}
|
||||
/**
|
||||
* Reads an flexy:if attribute -
|
||||
*
|
||||
*
|
||||
* @return string to add to output.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseAttributeIf()
|
||||
{
|
||||
// dont use the together, if is depreciated..
|
||||
$if = $this->element->getAttribute('FLEXY:IF');
|
||||
|
||||
if ($if === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (isset($this->element->hasForeach)) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"You may not use FOREACH and IF tags in the same tag on Line {$this->element->line} <{$this->element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
// allow if="!somevar"
|
||||
$ifnegative = '';
|
||||
|
||||
if ($if{0} == '!') {
|
||||
$ifnegative = '!';
|
||||
$if = substr($if,1);
|
||||
}
|
||||
// if="xxxxx"
|
||||
// if="xxxx.xxxx()" - should create a method prefixed with 'if:'
|
||||
// these checks should really be in the if/method class..!!!
|
||||
|
||||
|
||||
|
||||
if (!preg_match('/^[_A-Z][A-Z0-9_]*(\[[0-9]+\])?((\[|%5B)[A-Z0-9_]+(\]|%5D))*'.
|
||||
'(\.[_A-Z][A-Z0-9_]*((\[|%5B)[A-Z0-9_]+(\]|%5D))*)*(\\([^)]*\))?$/i',$if)) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"IF tags only accept simple object.variable or object.method() values on
|
||||
Line {$this->element->line} <{$this->element->tag}>
|
||||
{$if}",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if (substr($if,-1) == ')') {
|
||||
// grab args..
|
||||
$args = substr($if,strpos($if,'(')+1,-1);
|
||||
// simple explode ...
|
||||
|
||||
$args = strlen(trim($args)) ? explode(',',$args) : array();
|
||||
//print_R($args);
|
||||
|
||||
// this is nasty... - we need to check for quotes = eg. # at beg. & end..
|
||||
$args_clean = array();
|
||||
for ($i=0; $i<count($args); $i++) {
|
||||
if ($args[$i]{0} != '#') {
|
||||
$args_clean[] = $args[$i];
|
||||
continue;
|
||||
}
|
||||
// single # - so , must be inside..
|
||||
if ((strlen($args[$i]) > 1) && ($args[$i]{strlen($args[$i])-1}=='#')) {
|
||||
$args_clean[] = $args[$i];
|
||||
continue;
|
||||
}
|
||||
|
||||
$args[$i] .=',' . $args[$i+1];
|
||||
// remove args+1..
|
||||
array_splice($args,$i+1,1);
|
||||
$i--;
|
||||
// reparse..
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ifObj = $this->element->factory('Method',
|
||||
array('if:'.$ifnegative.substr($if,0,strpos($if,'(')), $args_clean),
|
||||
$this->element->line);
|
||||
} else {
|
||||
$ifObj = $this->element->factory('If', $ifnegative.$if, $this->element->line);
|
||||
}
|
||||
|
||||
// does it have a closetag? - you must have one - so you will have to hack in <span flexy:if=..><img></span> on tags
|
||||
// that do not have close tags - it's done this way to try and avoid mistakes.
|
||||
|
||||
|
||||
if (!$this->element->close) {
|
||||
//echo "<PRE>";print_R($this->element);
|
||||
|
||||
if ($this->element->getAttribute('/') !== false) {
|
||||
$this->element->postfix = array($this->element->factory("End",'', $this->element->line));
|
||||
} else {
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"An flexy:if attribute was found in <{$this->element->name} tag without a corresponding </{$this->element->name}
|
||||
tag on Line {$this->element->line} <{$this->element->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->element->close->postfix = array($this->element->factory("End",'', $this->element->line));
|
||||
}
|
||||
$this->element->clearAttribute('FLEXY:IF');
|
||||
return $ifObj->compile($this->compiler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads Tags - and relays to parseTagXXXXXXX
|
||||
*
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access private
|
||||
*/
|
||||
|
||||
|
||||
function _parseTags()
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
// doesnt really need strtolower etc. as php functions are not case sensitive!
|
||||
|
||||
if ($this->element->getAttribute('FLEXY:DYNAMIC')) {
|
||||
return $this->compiler->appendPhp(
|
||||
$this->getElementPhp( $this->element->getAttribute('ID') )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if ($this->element->getAttribute('FLEXY:IGNOREONLY') !== false) {
|
||||
return false;
|
||||
}
|
||||
if ($_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore']) {
|
||||
return false;
|
||||
}
|
||||
$tag = $this->element->tag;
|
||||
if (strpos($tag,':') !== false) {
|
||||
$bits = explode(':',$tag);
|
||||
$tag = $bits[1];
|
||||
}
|
||||
|
||||
$method = 'parseTag'.$tag;
|
||||
if (!method_exists($this,$method)) {
|
||||
return false;
|
||||
}
|
||||
// do any of the attributes use flexy data...
|
||||
foreach ($this->element->attributes as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//echo "call $method" . serialize($this->element->attributes). "\n";
|
||||
|
||||
return $this->$method();
|
||||
// allow the parse methods to return output.
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* produces the code for dynamic elements
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function getElementPhp($id,$mergeWithName=false) {
|
||||
|
||||
global $_HTML_TEMPLATE_FLEXY;
|
||||
static $tmpId=0;
|
||||
if (!$id) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} <{$this->element->tag}>: " .
|
||||
" Dynamic tags require an ID value",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
// dont mix and match..
|
||||
if (($this->element->getAttribute('FLEXY:IF') !== false) ||
|
||||
($this->element->getAttribute('FLEXY:FOREACH') !== false) )
|
||||
{
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} <{$this->element->tag}>: " .
|
||||
" You can not mix flexy:if= or flexy:foreach= with dynamic form elements " .
|
||||
" (turn off tag to element code with flexyIgnore=0, use flexy:ignore="yes" in the tag" .
|
||||
" or put the conditional outside in a span tag",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if ((strtolower($this->element->getAttribute('type')) == 'checkbox' ) &&
|
||||
(substr($this->element->getAttribute('name'),-2) == '[]')) {
|
||||
if ($this->element->getAttribute('id') === false) {
|
||||
$id = 'tmpId'. (++$tmpId);
|
||||
$this->element->attributes['id'] = $id;
|
||||
$this->element->ucAttributes['ID'] = $id;
|
||||
}
|
||||
$mergeWithName = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY['elements'][$id])) {
|
||||
// echo "<PRE>";print_r($this);print_r($_HTML_TEMPLATE_FLEXY['elements']);echo "</PRE>";
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} in Tag <{$this->element->tag}>:<BR> " .
|
||||
"The Dynamic tag Name '$id' has already been used previously by tag <{$_HTML_TEMPLATE_FLEXY['elements'][$id]->tag}>",
|
||||
null,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
// this is for a case where you can use a sprintf as the name, and overlay it with a variable element..
|
||||
$_HTML_TEMPLATE_FLEXY['elements'][$id] = $this->toElement($this->element);
|
||||
|
||||
if ($var = $this->element->getAttribute('FLEXY:NAMEUSES')) {
|
||||
|
||||
$var = 'sprintf(\''.$id .'\','.$this->element->toVar($var) .')';
|
||||
return
|
||||
'if (!isset($this->elements['.$var.'])) $this->elements['.$var.']= $this->elements[\''.$id.'\'];
|
||||
$this->elements['.$var.'] = $this->mergeElement($this->elements[\''.$id.'\'],$this->elements['.$var.']);
|
||||
$this->elements['.$var.']->attributes[\'name\'] = '.$var. ';
|
||||
echo $this->elements['.$var.']->toHtml();';
|
||||
} elseif ($mergeWithName) {
|
||||
$name = $this->element->getAttribute('NAME');
|
||||
return
|
||||
'$element = $this->elements[\''.$id.'\'];
|
||||
$element = $this->mergeElement($element,$this->elements[\''.$name.'\']);
|
||||
echo $element->toHtml();';
|
||||
|
||||
|
||||
} else {
|
||||
return 'echo $this->elements[\''.$id.'\']->toHtml();';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Script tag - check if PHP is allowed.
|
||||
*
|
||||
* @return false|PEAR_Error
|
||||
* @access public
|
||||
*/
|
||||
function parseTagScript() {
|
||||
|
||||
|
||||
$lang = $this->element->getAttribute('LANGUAGE');
|
||||
if (!$lang) {
|
||||
return false;
|
||||
}
|
||||
$lang = strtoupper($lang);
|
||||
|
||||
if ($GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($lang == "PHP") {
|
||||
|
||||
return HTML_Template_Flexy::raiseError('PHP code found in script',
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,HTML_TEMPLATE_FLEXY_ERROR_RETURN
|
||||
);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
/**
|
||||
* Reads an Input tag - build a element object for it
|
||||
*
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function parseTagInput()
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY;
|
||||
|
||||
if (in_array(strtoupper($this->element->getAttribute('TYPE')), array('SUBMIT','BUTTON','INPUT',''))) {
|
||||
$this->compiler->addStringToGettext($this->element->getAttribute('VALUE'));
|
||||
}
|
||||
// form elements : format:
|
||||
//value - fill out as PHP CODE
|
||||
|
||||
// as a general rule, this uses name, rather than ID except on
|
||||
// radio
|
||||
$mergeWithName = false;
|
||||
$id = $this->element->getAttribute('NAME');
|
||||
// checkboxes need more work.. - at the momemnt assume one with the same value...
|
||||
if (in_array(strtoupper($this->element->getAttribute('TYPE')), array('RADIO'))) {
|
||||
|
||||
if (!isset($_HTML_TEMPLATE_FLEXY['elements'][$id])) {
|
||||
// register it.. - so we dont overwrite it...
|
||||
$_HTML_TEMPLATE_FLEXY['elements'][$id] = false;
|
||||
} else if ($_HTML_TEMPLATE_FLEXY['elements'][$id] != false) {
|
||||
|
||||
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
"Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} ".
|
||||
"in Tag <{$this->element->tag}>:<BR>".
|
||||
"The Dynamic tag Name '$id' has already been used previously by ".
|
||||
"tag <{$_HTML_TEMPLATE_FLEXY['elements'][$id]->tag}>",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE
|
||||
);
|
||||
}
|
||||
|
||||
$id = $this->element->getAttribute('ID');
|
||||
if (!$id) {
|
||||
return HTML_Template_Flexy::raiseError("Error in {$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} <{$this->element->tag}>:
|
||||
Radio Input's require an ID tag..",
|
||||
null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
$mergeWithName = true;
|
||||
|
||||
}
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
return $this->compiler->appendPhp($this->getElementPhp( $id,$mergeWithName));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a TextArea tag - build a element object for it
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseTagTextArea()
|
||||
{
|
||||
|
||||
return $this->compiler->appendPhp(
|
||||
$this->getElementPhp( $this->element->getAttribute('NAME')));
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Deal with Selects - build a element object for it (unless flexyignore is set)
|
||||
*
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseTagSelect()
|
||||
{
|
||||
return $this->compiler->appendPhp(
|
||||
$this->getElementPhp( $this->element->getAttribute('NAME')));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reads an Form tag - and set up the element object header etc.
|
||||
*
|
||||
* @return string | false = html output or ignore (just output the tag)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function parseTagForm()
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY;
|
||||
$copy = clone($this->element);
|
||||
$copy->children = array();
|
||||
$id = $this->element->getAttribute('NAME');
|
||||
if (!$id) {
|
||||
$id = 'form';
|
||||
}
|
||||
|
||||
// this adds the element to the elements array.
|
||||
$old = clone($this->element);
|
||||
$this->element = $copy;
|
||||
$this->getElementPhp($id);
|
||||
$this->element= $old;
|
||||
|
||||
|
||||
return
|
||||
$this->compiler->appendPhp('echo $this->elements[\''.$id.'\']->toHtmlnoClose();') .
|
||||
$this->element->compileChildren($this->compiler) .
|
||||
$this->compiler->appendHtml( "</{$copy->oTag}>");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* reWriteURL - can using the config option 'url_rewrite'
|
||||
* format "from:to,from:to"
|
||||
* only handle left rewrite.
|
||||
* so
|
||||
* "/images:/myroot/images"
|
||||
* would change
|
||||
* /images/xyz.gif to /myroot/images/xyz.gif
|
||||
* /images/stylesheet/imagestyles.css to /myroot/images/stylesheet/imagestyles.css
|
||||
* note /imagestyles did not get altered.
|
||||
* will only work on strings (forget about doing /images/{someimage}
|
||||
*
|
||||
*
|
||||
* @param string attribute to rewrite
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function reWriteURL($which)
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY;
|
||||
|
||||
|
||||
if (!is_string($original = $this->element->getAttribute($which))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($original == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bits = explode(",",$_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite']);
|
||||
$new = $original;
|
||||
|
||||
foreach ($bits as $bit) {
|
||||
if (!strlen(trim($bit))) {
|
||||
continue;
|
||||
}
|
||||
$parts = explode (':', $bit);
|
||||
if (!isset($parts[1])) {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy: url_rewrite syntax incorrect'.
|
||||
print_r(array($bits,$bits),true),null,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
$new = preg_replace('#^'.$parts[0].'#',$parts[1], $new);
|
||||
}
|
||||
|
||||
|
||||
if ($original == $new) {
|
||||
return;
|
||||
}
|
||||
$this->element->ucAttributes[$which] = '"'. $new . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert flexy tokens to HTML_Template_Flexy_Elements.
|
||||
*
|
||||
* @param object token to convert into a element.
|
||||
* @return object HTML_Template_Flexy_Element
|
||||
* @access public
|
||||
*/
|
||||
function toElement($element) {
|
||||
require_once 'HTML/Template/Flexy/Element.php';
|
||||
$ret = new HTML_Template_Flexy_Element;
|
||||
|
||||
if (strtolower(get_class($element)) != 'html_template_flexy_token_tag') {
|
||||
$this->compiler->addStringToGettext($element->value);
|
||||
return $element->value;
|
||||
}
|
||||
|
||||
|
||||
$ret->tag = strtolower($element->tag);
|
||||
|
||||
$ats = $element->getAttributes();
|
||||
|
||||
if (isset($element->attributes['flexy:xhtml'])) {
|
||||
$ats['flexy:xhtml'] = true;
|
||||
}
|
||||
|
||||
foreach(array_keys($ats) as $a) {
|
||||
$ret->attributes[$a] = $this->unHtmlEntities($ats[$a]);
|
||||
}
|
||||
//print_r($ats);
|
||||
if (!$element->children) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// children - normally to deal with <element>
|
||||
|
||||
//print_r($this->children);
|
||||
foreach(array_keys($element->children) as $i) {
|
||||
// not quite sure why this happens - but it does.
|
||||
if (!is_object($element->children[$i])) {
|
||||
continue;
|
||||
}
|
||||
$ret->children[] = $this->toElement($element->children[$i]);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* do the reverse of htmlspecialchars on an attribute..
|
||||
*
|
||||
* copied from get-html-translation-table man page
|
||||
*
|
||||
* @param mixed from attribute values
|
||||
*
|
||||
* @return string return
|
||||
* @access public
|
||||
* @see see also methods.....
|
||||
*/
|
||||
|
||||
function unHtmlEntities ($in)
|
||||
{
|
||||
if (!is_string($in)) {
|
||||
return $in;
|
||||
}
|
||||
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
|
||||
$trans_tbl = array_flip ($trans_tbl);
|
||||
$ret = strtr ($in, $trans_tbl);
|
||||
return preg_replace('/&#(\d+);/me', "chr('\\1')",$ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
615
HTML/Template/Flexy/Element.php
Normal file
615
HTML/Template/Flexy/Element.php
Normal file
|
|
@ -0,0 +1,615 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com> |
|
||||
// | Based on HTML_Common by: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Element.php,v 1.46 2005/12/20 01:45:06 alan_k Exp $
|
||||
|
||||
/**
|
||||
* Lightweight HTML Element builder and render
|
||||
*
|
||||
* This differs from HTML_Common in the following ways:
|
||||
*
|
||||
* $element->attributes is Public
|
||||
* $element->override if set to anything other than false, renders the value rather than
|
||||
* the defined element
|
||||
*
|
||||
* $element->children is a recursvable child array which is rendered by toHTML
|
||||
* $element->toHtml() is implemented
|
||||
* $element->toHtmlNoClose() renders only the first tag and children (designed for <form
|
||||
* No support for tab offsets, comments ...
|
||||
*
|
||||
* Full support for Select, and common Form elements using
|
||||
* setValue()
|
||||
* setOptions()
|
||||
*
|
||||
* overlay support with SetFrom - base + inherited..
|
||||
*
|
||||
* attributes array values:
|
||||
* key="value" // standard key="value" in output
|
||||
* key = true // outputs just key.
|
||||
*
|
||||
* children can be
|
||||
* another HTML_Element
|
||||
* or string (raw text)
|
||||
*
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @version 1.6
|
||||
* @since PHP 4.0.3pl1
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_Template_Flexy_Element {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tag that this Element represents.
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tag = '';
|
||||
/**
|
||||
* Associative array of table attributes
|
||||
* Note Special values:
|
||||
* true == only display the key
|
||||
* false == remove
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $attributes = array();
|
||||
|
||||
/**
|
||||
* Sequence array of children
|
||||
* children that are strings are assumed to be text
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* override the tag.
|
||||
* if this is set to anything other than false, it will be output
|
||||
* rather than the tags+children
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $override = false;
|
||||
/**
|
||||
* prefix the tag.
|
||||
* this is output by toHtml as a prefix to the tag (can be used for require tags)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $prefix = '';
|
||||
/**
|
||||
* suffix the tag.
|
||||
* this is output by toHtml as a suffix to the tag (can be used for error messages)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $suffix = '';
|
||||
|
||||
/**
|
||||
* a value for delayed merging into live objects
|
||||
* if you set this on an element, it is merged by setValue, at merge time.
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $value = null;
|
||||
/**
|
||||
* Class constructor
|
||||
* @param mixed $attributes Associative array of table tag attributes
|
||||
* or HTML attributes name="value" pairs
|
||||
* @access public
|
||||
*/
|
||||
function HTML_Template_Flexy_Element($tag='', $attributes=null)
|
||||
{
|
||||
|
||||
$this->tag = strtolower($tag);
|
||||
if (false !== strpos($tag, ':')) {
|
||||
$bits = explode(':',$this->tag);
|
||||
$this->tag = $bits[0] . ':'.strtolower($bits[1]);
|
||||
}
|
||||
|
||||
$this->setAttributes($attributes);
|
||||
} // end constructor
|
||||
|
||||
|
||||
/**
|
||||
* Returns an HTML formatted attribute string
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function attributesToHTML()
|
||||
{
|
||||
$strAttr = '';
|
||||
$xhtmlclose = '';
|
||||
$charset = empty($GLOBALS['HTML_Template_Flexy']['options']['charset']) ? 'ISO-8859-1' : $GLOBALS['HTML_Template_Flexy']['options']['charset'];
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
|
||||
// you shouldn't do this, but It shouldnt barf when you do..
|
||||
if (is_array($value) || is_object($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($key == 'flexy:xhtml') {
|
||||
continue;
|
||||
}
|
||||
if ($value === false) {
|
||||
continue;
|
||||
}
|
||||
if ($value === true) {
|
||||
// this is not xhtml compatible..
|
||||
if ($key == '/') {
|
||||
$xhtmlclose = ' /';
|
||||
continue;
|
||||
}
|
||||
if (isset($this->attributes['flexy:xhtml'])) {
|
||||
$strAttr .= " {$key}=\"{$key}\"";
|
||||
} else {
|
||||
$strAttr .= ' ' . $key;
|
||||
}
|
||||
} else {
|
||||
// dont replace & with &
|
||||
if ($this->tag == 'textbox') { // XUL linefeed fix.
|
||||
$value = str_replace("\n", ' ', htmlspecialchars($value,ENT_COMPAT,$charset));
|
||||
} else {
|
||||
$value = str_replace('&nbsp;',' ',htmlspecialchars($value,ENT_COMPAT,$charset));
|
||||
}
|
||||
$strAttr .= ' ' . $key . '="' . $value . '"';
|
||||
}
|
||||
|
||||
}
|
||||
$strAttr .= $xhtmlclose;
|
||||
return $strAttr;
|
||||
} // end func _getAttrString
|
||||
|
||||
/**
|
||||
* Static Method to get key/value array from attributes.
|
||||
* Returns a valid atrributes array from either a string or array
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access private
|
||||
*/
|
||||
function parseAttributes($attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
$ret = array();
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$ret[strtolower($value)] = true;
|
||||
} else {
|
||||
$ret[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
|
||||
} elseif (is_string($attributes)) {
|
||||
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
|
||||
if (preg_match_all($preg, $attributes, $regs)) {
|
||||
for ($counter=0; $counter<count($regs[1]); $counter++) {
|
||||
$name = $regs[1][$counter];
|
||||
$check = $regs[0][$counter];
|
||||
$value = $regs[7][$counter];
|
||||
if (trim($name) == trim($check)) {
|
||||
$arrAttr[strtolower(trim($name))] = strtolower(trim($name));
|
||||
} else {
|
||||
if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
$arrAttr[strtolower(trim($name))] = trim($value);
|
||||
}
|
||||
}
|
||||
return $arrAttr;
|
||||
}
|
||||
}
|
||||
} // end func _parseAttributes
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Utility function to set values from common tag types.
|
||||
* @param HTML_Element $from override settings from another element.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setValue($value) {
|
||||
// store the value in all situations
|
||||
$this->value = $value;
|
||||
$tag = strtolower($this->tag);
|
||||
if (strpos($tag,':') !== false) {
|
||||
$bits = explode(':',$tag);
|
||||
$tag = $bits[1];
|
||||
}
|
||||
switch ($tag) {
|
||||
case 'input':
|
||||
switch (isset($this->attributes['type']) ? strtolower($this->attributes['type']) : '') {
|
||||
case 'checkbox':
|
||||
if (isset($this->attributes['checked'])) {
|
||||
unset($this->attributes['checked']);
|
||||
}
|
||||
// if value is nto set, it doesnt make any difference what you set ?
|
||||
if (!isset($this->attributes['value'])) {
|
||||
return;
|
||||
}
|
||||
//print_r($this); echo "SET TO "; serialize($value);
|
||||
if (isset($this->attributes['name']) && (substr($this->attributes['name'],-2) == '[]')) {
|
||||
if (is_array($value) &&
|
||||
in_array((string) $this->attributes['value'],$value)
|
||||
) {
|
||||
$this->attributes['checked'] = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ($this->attributes['value'] == $value) {
|
||||
$this->attributes['checked'] = true;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
case 'radio':
|
||||
if (isset($this->attributes['checked'])) {
|
||||
unset($this->attributes['checked']);
|
||||
}
|
||||
// if we dont have values associated yet, store it..
|
||||
if (!isset($this->attributes['value'])) {
|
||||
$this->value = $value;
|
||||
return;
|
||||
}
|
||||
if ($this->attributes['value'] == $value) {
|
||||
$this->attributes['checked'] = true;
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
// no other input accepts array as a value.
|
||||
if (is_array($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->attributes['value'] = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
case 'select':
|
||||
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
// its setting the default value..
|
||||
|
||||
foreach($this->children as $i=>$child) {
|
||||
|
||||
if (is_string($child)) {
|
||||
continue;
|
||||
}
|
||||
if ($child->tag == 'optgroup') {
|
||||
foreach($this->children[$i]->children as $ii=>$child) {
|
||||
|
||||
// does the value exist and match..
|
||||
if (isset($child->attributes['value'])
|
||||
&& in_array((string) $child->attributes['value'], $value))
|
||||
{
|
||||
$this->children[$i]->children[$ii]->attributes['selected'] =
|
||||
isset($this->attributes['flexy:xhtml']) ? 'selected' : true;
|
||||
continue;
|
||||
}
|
||||
if (isset($child->attributes['value']) &&
|
||||
isset($this->children[$i]->children[$ii]->attributes['selected']))
|
||||
{
|
||||
unset($this->children[$i]->children[$ii]->attributes['selected']);
|
||||
continue;
|
||||
}
|
||||
// value doesnt exst..
|
||||
|
||||
if (isset($this->children[$i]->children[$ii]->attributes['selected'])) {
|
||||
unset($this->children[$i]->children[$ii]->attributes['selected']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// standard option value...
|
||||
//echo "testing {$child->attributes['value']} against ". print_r($value,true)."\n";
|
||||
// does the value exist and match..
|
||||
|
||||
if (isset($child->attributes['value'])
|
||||
&& in_array((string) $child->attributes['value'], $value))
|
||||
{
|
||||
|
||||
|
||||
$this->children[$i]->attributes['selected'] =
|
||||
isset($this->attributes['flexy:xhtml']) ? 'selected' : true;;
|
||||
continue;
|
||||
}
|
||||
// no value attribute try and use the contents.
|
||||
if (!isset($child->attributes['value'])
|
||||
&& is_string($child->children[0])
|
||||
&& in_array((string) $child->children[0], $value))
|
||||
{
|
||||
|
||||
$this->children[$i]->attributes['selected'] =
|
||||
isset($this->attributes['flexy:xhtml']) ? 'selected' : true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($child->attributes['value']) &&
|
||||
isset($this->children[$i]->attributes['selected']))
|
||||
{
|
||||
//echo "clearing selected\n";
|
||||
unset($this->children[$i]->attributes['selected']);
|
||||
continue;
|
||||
}
|
||||
// value doesnt exst..
|
||||
|
||||
if (isset($this->children[$i]->attributes['selected'])) {
|
||||
//echo "clearing selected\n";
|
||||
unset($this->children[$i]->attributes['selected']);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return;
|
||||
case 'textarea':
|
||||
$charset = empty($GLOBALS['HTML_Template_Flexy']['options']['charset']) ? 'ISO-8859-1' : $GLOBALS['HTML_Template_Flexy']['options']['charset'];
|
||||
$this->children = array(htmlspecialchars($value,ENT_COMPAT,$charset));
|
||||
return;
|
||||
case '': // dummy objects.
|
||||
$this->value = $value;
|
||||
return;
|
||||
|
||||
// XUL elements
|
||||
case 'menulist':
|
||||
case 'textbox':
|
||||
case 'checkbox':
|
||||
require_once 'HTML/Template/Flexy/Element/Xul.php';
|
||||
HTML_Template_Flexy_Element_Xul::setValue($this,$value);
|
||||
return ;
|
||||
|
||||
default:
|
||||
if (is_array($value)) {
|
||||
return;
|
||||
}
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Utility function equivilant to HTML_Select - loadArray **
|
||||
* but using
|
||||
* key=>value maps
|
||||
* <option value="key">Value</option>
|
||||
* Key=key (eg. both the same) maps to
|
||||
* <option>key</option>
|
||||
* and label = array(key=>value) maps to
|
||||
* <optgroup label="label"> <option value="key">value</option></optgroup>
|
||||
*
|
||||
* $element->setOptions(array('a'=>'xxx','b'=>'yyy'));
|
||||
* or
|
||||
* $element->setOptions(array('a','b','c','d'),true);
|
||||
*
|
||||
*
|
||||
*.
|
||||
* @param HTML_Element $from override settings from another element.
|
||||
* @param HTML_Element $noValue ignore the key part of the array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setOptions($array,$noValue=false) {
|
||||
if (!is_array($array)) {
|
||||
$this->children = array();
|
||||
return;
|
||||
}
|
||||
|
||||
$charset = empty($GLOBALS['HTML_Template_Flexy']['options']['charset']) ? 'ISO-8859-1' : $GLOBALS['HTML_Template_Flexy']['options']['charset'];
|
||||
|
||||
$tag = strtolower($this->tag);
|
||||
$namespace = '';
|
||||
if (false !== strpos($this->tag, ':')) {
|
||||
|
||||
$bits = explode(':',$this->tag);
|
||||
$namespace = $bits[0] . ':';
|
||||
$tag = strtolower($bits[1]);
|
||||
|
||||
}
|
||||
// if we have specified a xultag!!?
|
||||
if (strlen($tag) && ($tag != 'select')) {
|
||||
require_once 'HTML/Template/Flexy/Element/Xul.php';
|
||||
return HTML_Template_Flexy_Element_Xul::setOptions($this,$array,$noValue);
|
||||
}
|
||||
|
||||
foreach($array as $k=>$v) {
|
||||
if (is_array($v)) { // optgroup
|
||||
$child = new HTML_Template_Flexy_Element($namespace . 'optgroup',array('label'=>$k));
|
||||
foreach($v as $kk=>$vv) {
|
||||
$atts=array();
|
||||
if (($kk !== $vv) && !$noValue) {
|
||||
$atts = array('value'=>$kk);
|
||||
} else {
|
||||
$atts = array('value'=>$vv);
|
||||
}
|
||||
$add = new HTML_Template_Flexy_Element($namespace . 'option',$atts);
|
||||
$add->children = array(htmlspecialchars($vv,ENT_COMPAT,$charset));
|
||||
$child->children[] = $add;
|
||||
}
|
||||
$this->children[] = $child;
|
||||
continue;
|
||||
}
|
||||
$atts=array();
|
||||
if (($k !== $v) && !$noValue) {
|
||||
$atts = array('value'=>$k);
|
||||
} else {
|
||||
$atts = array('value'=>$v);
|
||||
}
|
||||
$add = new HTML_Template_Flexy_Element($namespace . 'option',$atts);
|
||||
$add->children = array(htmlspecialchars($v,ENT_COMPAT,$charset));
|
||||
$this->children[] = $add;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Sets the HTML attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setAttributes($attributes)
|
||||
{
|
||||
$attrs= $this->parseAttributes($attributes);
|
||||
if (!is_array($attrs)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($attrs as $key => $value) {
|
||||
$this->attributes[$key] = $value;
|
||||
}
|
||||
} // end func updateAttributes
|
||||
|
||||
/**
|
||||
* Removes an attributes
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function removeAttributes($attrs)
|
||||
{
|
||||
if (is_string($attrs)) {
|
||||
$attrs = array($attrs);
|
||||
}
|
||||
foreach ($attrs as $attr) {
|
||||
if (isset($this->attributes[strtolower($attr)])) {
|
||||
$this->attributes[strtolower($attr)] = false;
|
||||
}
|
||||
}
|
||||
} //end func removeAttribute
|
||||
|
||||
|
||||
/**
|
||||
* Output HTML and children
|
||||
*
|
||||
* @access public
|
||||
* @param object $overlay = merge data from object.
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtml($overlay=false)
|
||||
{
|
||||
|
||||
//echo "BEFORE<PRE>";print_R($this);
|
||||
$ret = $this;
|
||||
if ($overlay !== false) {
|
||||
$ret = HTML_Template_Flexy::mergeElement($this,$overlay);
|
||||
}
|
||||
|
||||
if ($ret->override !== false) {
|
||||
return $ret->override;
|
||||
}
|
||||
$prefix = $ret->prefix;
|
||||
if (is_object($prefix)) {
|
||||
$prefix = $prefix->toHtml();
|
||||
}
|
||||
$suffix = $ret->suffix;
|
||||
if (is_object($suffix)) {
|
||||
$suffix = $suffix->toHtml();
|
||||
}
|
||||
//echo "AFTER<PRE>";print_R($ret);
|
||||
|
||||
$tag = $this->tag;
|
||||
if (strpos($tag,':') !== false) {
|
||||
$bits = explode(':',$tag);
|
||||
$tag = $bits[1];
|
||||
}
|
||||
// tags that never should have closers
|
||||
$close = "</{$ret->tag}>";
|
||||
if (in_array(strtoupper($tag),array("INPUT","IMG"))) {
|
||||
$close = '';
|
||||
}
|
||||
if (isset($this->attributes['/'])) {
|
||||
$close = '';
|
||||
}
|
||||
|
||||
$close .= $suffix ;
|
||||
|
||||
return "{$prefix}<{$ret->tag}".$ret->attributesToHTML() . '>'.$ret->childrenToHTML() .$close;
|
||||
|
||||
|
||||
} // end func toHtml
|
||||
|
||||
|
||||
/**
|
||||
* Output Open Tag and any children and not Child tag (designed for use with <form + hidden elements>
|
||||
*
|
||||
* @access public
|
||||
* @param object $overlay = merge data from object.
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtmlnoClose($overlay=false)
|
||||
{
|
||||
$ret = $this;
|
||||
if ($ret->override !== false) {
|
||||
return $ret->override;
|
||||
}
|
||||
if ($overlay !== false) {
|
||||
$ret = HTML_Template_Flexy::mergeElement($this,$overlay);
|
||||
}
|
||||
|
||||
|
||||
return "<{$ret->tag}".$ret->attributesToHTML() . '>' . $ret->childrenToHTML();
|
||||
|
||||
|
||||
} // end func toHtml
|
||||
|
||||
|
||||
/**
|
||||
* Output HTML and children
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function childrenToHtml()
|
||||
{
|
||||
$ret = '';
|
||||
foreach($this->children as $child) {
|
||||
if (!is_object($child)) {
|
||||
$ret .= $child;
|
||||
continue;
|
||||
}
|
||||
|
||||
$ret .= $child->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
} // end func toHtml
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end class HTML_Template_Flexy_Element
|
||||
175
HTML/Template/Flexy/Element/Xul.php
Normal file
175
HTML/Template/Flexy/Element/Xul.php
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Xul.php,v 1.6 2005/11/09 08:29:13 alan_k Exp $
|
||||
|
||||
/**
|
||||
* Extension HTML Element builder and render to provide features for Xul
|
||||
*
|
||||
* All methods are static, and expect the first argument to be a HTML_Template_Flexy_Element
|
||||
*
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
*/
|
||||
class HTML_Template_Flexy_Element_Xul {
|
||||
|
||||
|
||||
/**
|
||||
* Utility function to set values for common tag types.
|
||||
* @param HTML_Template_Flexy_Element $element override settings from another element.
|
||||
* @param mixed $value value to use.
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setValue(&$element,$value) {
|
||||
// store the value in all situations
|
||||
$element->value = $value;
|
||||
$tag = $element->tag;
|
||||
if (strpos($tag,':') !== false) {
|
||||
$bits = explode(':',$tag);
|
||||
$tag = $bits[1];
|
||||
}
|
||||
switch ($tag) {
|
||||
case 'menulist':
|
||||
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
// is the first childa menupopup
|
||||
if (!isset($element->children[0])) {
|
||||
$element->children[0] = HTML_Template_Flexy_Element('menupopup');
|
||||
}
|
||||
if (!is_a($element->children[0],'HTML_Template_Flexy_Element')) {
|
||||
// oh sh*t big problem!
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
__CLASS__ . '::setValue expected a Flexy Element as the child of a menuitem but got something else! '.
|
||||
print_r($element,true),
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
|
||||
// its setting the default value..
|
||||
// if the children havent been built we dont really care?
|
||||
// it will be done at the merge stage anyway..
|
||||
|
||||
foreach(array_keys($element->children[0]->children) as $i) {
|
||||
$child = &$element->children[0]->children[$i];
|
||||
|
||||
if (is_string($child)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// standard option value...
|
||||
//echo "testing {$child->attributes['value']} against ". print_r($value,true)."\n";
|
||||
// does the value exist and match..
|
||||
|
||||
if (isset($child->attributes['value'])
|
||||
&& in_array((string) $child->attributes['value'], $value))
|
||||
{
|
||||
// echo "MATCH!\n";
|
||||
$child->attributes['selected'] = 'true';
|
||||
continue;
|
||||
}
|
||||
|
||||
// otherwise..
|
||||
$child->attributes['selected'] = 'false';
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case 'textbox':
|
||||
$this->attributes['value'] = $value;
|
||||
return;
|
||||
|
||||
case 'checkbox':
|
||||
if (!isset($this->attributes['value'])) {
|
||||
return; // should be an error condition really...
|
||||
}
|
||||
$this->attributes['checked'] = ($value == $this->attributes['value']) ? 'true' : 'false';
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Utility function equivilant to HTML_Select - loadArray ** For xul:menulist.
|
||||
* but using
|
||||
* key=>value maps
|
||||
* <option value="key">Value</option>
|
||||
* Key=key (eg. both the same) maps to
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param HTML_Element $from override settings from another element.
|
||||
* @param HTML_Element $noValue ignore the key part of the array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setOptions(&$element, $array,$noValue=false) {
|
||||
if (!is_array($array)) {
|
||||
$element->children = array();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$tag = '';
|
||||
$namespace = '';
|
||||
if (false !== strpos($element->tag, ':')) {
|
||||
|
||||
$bits = explode(':',$element->tag);
|
||||
$namespace = $bits[0] . ':';
|
||||
$tag = strtolower($bits[1]);
|
||||
|
||||
}
|
||||
if (!isset($element->children[0])) {
|
||||
$element->children[0] = new HTML_Template_Flexy_Element('menupopup');
|
||||
}
|
||||
if (!is_a($element->children[0],'HTML_Template_Flexy_Element')) {
|
||||
// oh sh*t big problem!
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
__CLASS__ . '::setValue expected a menupopup as the child of a menuitem?',
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
|
||||
HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
foreach($array as $k=>$v) {
|
||||
|
||||
$atts=array();
|
||||
if (($k !== $v) && !$noValue) {
|
||||
$atts = array('value'=>$k);
|
||||
} else {
|
||||
$atts = array('value'=>$v);
|
||||
}
|
||||
$atts['label'] = htmlspecialchars($v);
|
||||
$atts['/'] = true;
|
||||
$add = new HTML_Template_Flexy_Element($namespace . 'menuitem',$atts);
|
||||
$element->children[0]->children[] = $add;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // end class HTML_Template_Flexy_Element
|
||||
194
HTML/Template/Flexy/Factory.php
Normal file
194
HTML/Template/Flexy/Factory.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: nobody <nobody@localhost> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Factory.php,v 1.9 2005/05/14 03:06:00 alan_k Exp $
|
||||
//
|
||||
// Factory tools for managing groups of HTML_Elements
|
||||
//
|
||||
|
||||
require_once 'HTML/Template/Flexy/Element.php';
|
||||
|
||||
class HTML_Template_Flexy_Factory {
|
||||
|
||||
|
||||
/**
|
||||
* fromArray - builds a set of elements from a key=>value array (eg. DO->toArray())
|
||||
* the second parameter is an optional HTML_Element array to merge it into.
|
||||
*
|
||||
*
|
||||
* @param array key(tag name) => value
|
||||
* @param optional array key(tag name) => HTML_Element
|
||||
*
|
||||
* @return array Array of HTML_Elements
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function fromArray($ar,$ret=array())
|
||||
{
|
||||
|
||||
foreach($ar as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
$ret = HTML_Template_Flexy_Factory::fromArrayPrefixed($k,$v,$ret);
|
||||
}
|
||||
|
||||
|
||||
if (!isset($ret[$k])) {
|
||||
$ret[$k] = new HTML_Template_Flexy_Element();
|
||||
}
|
||||
$ret[$k]->setValue($v);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* fromArrayPrefixed - takes a multi dimensional array, and builds the 'xxx[sss][xx]' => value
|
||||
*
|
||||
* @param array key(tag name) => value
|
||||
* @param array key(tag name) => value
|
||||
* @param optional array key(tag name) => HTML_Element
|
||||
*
|
||||
* @return array Array of HTML_Elements
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function fromArrayPrefixed($prefix, $ar,$ret=array())
|
||||
{
|
||||
|
||||
foreach($ar as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
$ret = HTML_Template_Flexy_Factory::fromArrayPrefixed($prefix.'['.$k.']',$v,$ret);
|
||||
if (!isset($ret[$prefix.'['.$k.'][]'])) {
|
||||
$ret[$prefix.'['.$k.'][]'] = new HTML_Template_Flexy_Element();
|
||||
}
|
||||
$ret[$prefix.'['.$k.'][]']->setValue($v);
|
||||
}
|
||||
|
||||
if (!isset($ret[$prefix.'['.$k.']'])) {
|
||||
$ret[$prefix.'['.$k.']'] = new HTML_Template_Flexy_Element();
|
||||
}
|
||||
$ret[$prefix.'['.$k.']']->setValue($v);
|
||||
|
||||
|
||||
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setErrors - sets the suffix of an element to a value..
|
||||
*
|
||||
* HTML_Element_Factory::setErrors($elements,array('name','not long enough'));
|
||||
*
|
||||
* @depreciated - this is really outside the scope of Factory - it should be
|
||||
* seperated into a rendering toolkit of some kind.
|
||||
|
||||
* @param array of HTML_Element's
|
||||
* @param array key(tag name) => error
|
||||
* @param string sprintf error format..
|
||||
*
|
||||
* @return array Array of HTML_Elements
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function &setErrors(&$ret,$set,$format='<span class="error">%s</span>')
|
||||
{
|
||||
if (empty($ret) || !is_array($ret)) {
|
||||
$ret = array();
|
||||
}
|
||||
// check what you send this.. !!!
|
||||
if (!is_array($set)) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
'invalid arguments "$set" (should be an array) sent to HTML_Template_Flexy_Factory::setErrors',
|
||||
0, HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
foreach($set as $k=>$v) {
|
||||
if (!$v) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($ret[$k])) {
|
||||
$ret[$k] = new HTML_Template_Flexy_Element;
|
||||
}
|
||||
$ret[$k]->suffix .= sprintf($format,$v);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setRequired - sets the prefix of an element to a value..
|
||||
*
|
||||
* HTML_Element_Factory::setRequired($elements,array('name',true));
|
||||
*
|
||||
* @depreciated - this is really outside the scope of Factory - it should be
|
||||
* seperated into a rendering toolkit
|
||||
*
|
||||
* @param array of HTML_Element's
|
||||
* @param array key(tag name) => error
|
||||
* @param string sprintf error format..
|
||||
*
|
||||
*
|
||||
* @return array Array of HTML_Elements
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function &setRequired(&$ret,$set,$format='<span class="required">*</span>')
|
||||
{
|
||||
|
||||
|
||||
if (empty($ret) || !is_array($ret)) {
|
||||
$ret = array();
|
||||
}
|
||||
foreach($set as $k=>$v) {
|
||||
if (!$v) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($ret[$k])) {
|
||||
$ret[$k] = new HTML_Template_Flexy_Element();
|
||||
}
|
||||
$ret[$k]->prefix .= sprintf($format,$v);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* freeze - freeze's an element. - just copies the value to the override.
|
||||
* this probably needs more thought.. - it would probably need to merge
|
||||
* the full tag info with types, to be usefull..
|
||||
*
|
||||
* $ar = HTML_Element_Factory::freeze($ar);
|
||||
*
|
||||
* @depreciated - this is really outside the scope of Factory - it should be
|
||||
* seperated into a rendering toolkit
|
||||
*
|
||||
*
|
||||
* @param array (return by referencekey(tag name) => HTML_Element
|
||||
*
|
||||
* @return array Array of HTML_Elements
|
||||
* @access public
|
||||
*/
|
||||
function freeze(&$array) {
|
||||
|
||||
foreach($array as $k=>$v) {
|
||||
$array[$k]->override = $array[$k]->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
117
HTML/Template/Flexy/Plugin.php
Normal file
117
HTML/Template/Flexy/Plugin.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: nobody <nobody@localhost> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Plugin.php,v 1.10 2005/05/14 03:44:26 alan_k Exp $
|
||||
//
|
||||
// Plugin API provides support for < ? = $this->plugin(".....",.....); ? >
|
||||
// or {this.plugin(#xxxxx#,#xxxx#):h}
|
||||
//
|
||||
// BASICALLY THIS IS SAVANT'S PLUGIN PROVIDER.
|
||||
// @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Plugin {
|
||||
|
||||
/**
|
||||
* reference to main engine..
|
||||
*
|
||||
* @var object HTML_Template_Flexy
|
||||
* @access public
|
||||
*/
|
||||
var $flexy; // reference to flexy.
|
||||
var $pluginCache = array(); // store of instanced plugins..
|
||||
|
||||
/**
|
||||
* Call a Plugin method.
|
||||
*
|
||||
* Look up in all the plugins to see if the method exists, if it does, call it.
|
||||
*
|
||||
*
|
||||
* @param array name of method, arguments.
|
||||
*
|
||||
*
|
||||
* @return string hopefully
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function call($args)
|
||||
{
|
||||
|
||||
|
||||
$method = $args[0];
|
||||
// attempt to load the plugin on-the-fly
|
||||
$class = $this->_loadPlugins($method);
|
||||
|
||||
if (is_a($class,'PEAR_Error')) {
|
||||
//echo $class->toString();
|
||||
return $class->toString();
|
||||
}
|
||||
|
||||
|
||||
// first argument is always the plugin name; shift the first
|
||||
// argument off the front of the array and reduce the number of
|
||||
// array elements.
|
||||
array_shift($args);
|
||||
|
||||
return call_user_func_array(array(&$this->plugins[$class],$method), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugins, and lookup which one provides the required method
|
||||
*
|
||||
*
|
||||
* @param string Name
|
||||
*
|
||||
* @return string|PEAR_Error the class that provides it.
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _loadPlugins($name)
|
||||
{
|
||||
// name can be:
|
||||
// ahref = maps to {class_prefix}_ahref::ahref
|
||||
$this->plugins = array();
|
||||
if (empty($this->plugins)) {
|
||||
|
||||
foreach ($this->flexy->options['plugins'] as $cname=>$file) {
|
||||
if (!is_int($cname)) {
|
||||
include_once $file;
|
||||
$this->plugins[$cname] = new $cname;
|
||||
$this->plugins[$cname]->flexy = &$this->flexy;
|
||||
continue;
|
||||
}
|
||||
$cname = $file;
|
||||
require_once 'HTML/Template/Flexy/Plugin/'. $cname . '.php';
|
||||
$class = "HTML_Template_Flexy_Plugin_{$cname}";
|
||||
$this->plugins[$class] = new $class;
|
||||
$this->plugins[$class]->flexy = &$this->flexy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->plugins as $class=>$o) {
|
||||
//echo "checking :". get_class($o). ":: $name\n";
|
||||
if (method_exists($o,$name)) {
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
return HTML_Template_Flexy::raiseError("could not find plugin with method: '$name'");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
756
HTML/Template/Flexy/Plugin/Savant.php
Normal file
756
HTML/Template/Flexy/Plugin/Savant.php
Normal file
|
|
@ -0,0 +1,756 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Plugin_Savant {
|
||||
/**
|
||||
* Output an HTML <a href="">...</a> tag.
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $href The URL for the resulting <a href="">...</a> tag.
|
||||
*
|
||||
* @param string $text The text surrounded by the <a>...</a> tag set.
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the <a>
|
||||
* opening tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function ahref($href, $text, $extra = null)
|
||||
{
|
||||
$output = '<a href="' . $href . '"';
|
||||
|
||||
if (! is_null($extra)) {
|
||||
$output .= ' ' . $extra;
|
||||
}
|
||||
|
||||
$output .= '>' . $text . '</a>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a single checkbox <input> element.
|
||||
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $name The HTML "name=" value for the checkbox.
|
||||
*
|
||||
* @param mixed $value The value of the checkbox if checked.
|
||||
*
|
||||
* @param mixed $selected Check $value against this; if they match,
|
||||
* mark the checkbox as checked.
|
||||
*
|
||||
* @param string $set_unchecked If null, this will add no HTML to the
|
||||
* output. However, if set to any non-null value, the value will be
|
||||
* added as a hidden element before the checkbox so that if the
|
||||
* checkbox is unchecked, the hidden value will be returned instead
|
||||
* of the checked value.
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the
|
||||
* checkbox element.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function checkbox(
|
||||
$name,
|
||||
$value,
|
||||
$selected = null,
|
||||
$set_unchecked = null,
|
||||
$extra = null)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
if (! is_null($set_unchecked)) {
|
||||
// this sets the unchecked value of the checkbox.
|
||||
$html .= "<input type=\"hidden\" ";
|
||||
$html .= "name=\"$name\" ";
|
||||
$html .= "value=\"$set_unchecked\" />\n";
|
||||
}
|
||||
|
||||
$html .= "<input type=\"checkbox\" ";
|
||||
$html .= "name=\"$name\" ";
|
||||
$html .= "value=\"$value\"";
|
||||
|
||||
if ($value == $selected) {
|
||||
$html .= " checked=\"checked\"";
|
||||
}
|
||||
|
||||
$html .= " $extra />";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a set of checkbox <input>s.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $name The HTML "name=" value of all the checkbox
|
||||
* <input>s. The name will get [] appended to it to make it an array
|
||||
* when returned to the server.
|
||||
*
|
||||
* @param array $options An array of key-value pairs where the key is
|
||||
* the checkbox value and the value is the checkbox label.
|
||||
*
|
||||
* @param string $set_unchecked If null, this will add no HTML to the
|
||||
* output. However, if set to any non-null value, the value will be
|
||||
* added as a hidden element before every checkbox so that if the
|
||||
* checkbox is unchecked, the hidden value will be returned instead
|
||||
* of the checked value.
|
||||
*
|
||||
* @param string $sep The HTML text to place between every checkbox
|
||||
* in the set.
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the
|
||||
* checkbox element.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function checkboxes(
|
||||
|
||||
$name,
|
||||
$options,
|
||||
$selected = array(),
|
||||
$set_unchecked = null,
|
||||
$sep = "<br />\n",
|
||||
$extra = null)
|
||||
{
|
||||
// force $selected to be an array. this allows multi-checks to
|
||||
// have multiple checked boxes.
|
||||
settype($selected, 'array');
|
||||
|
||||
// the text to be returned
|
||||
$html = '';
|
||||
|
||||
if (is_array($options)) {
|
||||
|
||||
// an iteration counter. we use this to track which array
|
||||
// elements are checked and which are unchecked.
|
||||
$i = 0;
|
||||
|
||||
foreach ($options as $value => $label) {
|
||||
|
||||
if (! is_null($set_unchecked)) {
|
||||
// this sets the unchecked value of the checkbox.
|
||||
$html .= "<input type=\"hidden\" ";
|
||||
$html .= "name=\"{$name}[$i]\" ";
|
||||
$html .= "value=\"$set_unchecked\" />\n";
|
||||
}
|
||||
|
||||
|
||||
$html .= "<input type=\"checkbox\" ";
|
||||
$html .= "name=\"{$name}[$i]\" ";
|
||||
$html .= "value=\"$value\"";
|
||||
|
||||
if (in_array($value, $selected)) {
|
||||
$html .= " checked=\"checked\"";
|
||||
}
|
||||
|
||||
if (! is_null($extra)) {
|
||||
$html .= " $extra";
|
||||
}
|
||||
|
||||
$html .= " />$label$sep";
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Cycle through a series of values based on an iteration number,
|
||||
* with optional group repetition.
|
||||
*
|
||||
* For example, if you have three values in a cycle (a, b, c) the iteration
|
||||
* returns look like this:
|
||||
*
|
||||
* 0 => a
|
||||
* 1 => b
|
||||
* 2 => c
|
||||
* 3 => a
|
||||
* 4 => b
|
||||
* 5 => c
|
||||
*
|
||||
* If you repeat each cycle value (a,b,c) 2 times on the iterations,
|
||||
* the returns look like this:
|
||||
*
|
||||
* 0 => a
|
||||
* 1 => a
|
||||
* 2 => b
|
||||
* 3 => b
|
||||
* 4 => c
|
||||
* 5 => c
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param int $iteration The iteration number for the cycle.
|
||||
*
|
||||
* @param array $values The values to cycle through.
|
||||
*
|
||||
* @param int $repeat The number of times to repeat a cycle value.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function cycle($iteration, $values = null, $repeat = 1)
|
||||
{
|
||||
settype($values, 'array');
|
||||
|
||||
// prevent divide-by-zero errors
|
||||
if ($repeat == 0) {
|
||||
$repeat = 1;
|
||||
}
|
||||
|
||||
return $values[($iteration / $repeat) % count($values)];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a formatted date using strftime() conventions.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $datestring Any date-time string suitable for
|
||||
* strtotime().
|
||||
*
|
||||
* @param string $format The strftime() formatting string.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function dateformat($datestring, $format = false)
|
||||
{
|
||||
if ($format === false) {
|
||||
$format = isset($this->flexy->options['plugin.dateformat']) ?
|
||||
$this->flexy->options['plugin.dateformat'] : '%d %b %Y';
|
||||
}
|
||||
if (trim($datestring) == '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$date = strtotime($datestring);
|
||||
if ($date > 1) {
|
||||
return strftime($format, $date);
|
||||
}
|
||||
require_once 'Date.php';
|
||||
$date = new Date($date);
|
||||
return $date->format($format);
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Output a formatted number using number_format
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param string $datestring Any date-time string suitable for
|
||||
* strtotime().
|
||||
*
|
||||
* @param string $format The strftime() formatting string.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function numberformat($number, $dec=false,$point=false,$thousands=false)
|
||||
{
|
||||
if (!strlen(trim($number))) {
|
||||
return;
|
||||
}
|
||||
// numberformat int decimals, string dec_point, string thousands_sep
|
||||
$dec = ($dec !== false) ? $dec : (
|
||||
isset($this->flexy->options['plugin.numberformat.decimals']) ?
|
||||
$this->flexy->options['plugin.numberformat.decimals'] : 2
|
||||
);
|
||||
$point = ($point !== false) ? $point : (
|
||||
isset($this->flexy->options['plugin.numberformat.point']) ?
|
||||
$this->flexy->options['plugin.numberformat.point'] : '.');
|
||||
$thousands = ($thousands !== false) ? $thousands : (
|
||||
isset($this->flexy->options['plugin.numberformat.thousands']) ?
|
||||
$this->flexy->options['plugin.numberformat.thousands'] : ',');
|
||||
|
||||
|
||||
return number_format($number,$dec,$point,$thousands);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output an <image ... /> tag.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $src The image source as a relative or absolute HREF.
|
||||
*
|
||||
* @param string $link Providing a link will make the image clickable,
|
||||
* leading to the URL indicated by $link; defaults to null.
|
||||
*
|
||||
* @param string $alt Alternative descriptive text for the image;
|
||||
* defaults to the filename of the image.
|
||||
*
|
||||
* @param int $border The border width for the image; defaults to zero.
|
||||
*
|
||||
* @param int $width The displayed image width in pixels; defaults to
|
||||
* the width of the image.
|
||||
*
|
||||
* @param int $height The displayed image height in pixels; defaults to
|
||||
* the height of the image.
|
||||
*
|
||||
*/
|
||||
|
||||
function image(
|
||||
$src,
|
||||
$alt = null,
|
||||
$border = 0,
|
||||
$width = null,
|
||||
$height = null)
|
||||
{
|
||||
$size = '';
|
||||
|
||||
// build the alt tag
|
||||
if (is_null($alt)) {
|
||||
$alt = basename($src);
|
||||
}
|
||||
|
||||
$alt = ' alt="' . htmlentities($alt) . '"';
|
||||
|
||||
// build the border tag
|
||||
$border = ' border="' . htmlentities($border) . '"';
|
||||
|
||||
// get the width and height of the image
|
||||
if (is_null($width) && is_null($height)) {
|
||||
|
||||
if (substr(strtolower($src), 0, 7) == 'http://' ||
|
||||
substr(strtolower($src), 0, 8) == 'https://') {
|
||||
|
||||
// the image is not on the local filesystem
|
||||
$root = '';
|
||||
|
||||
} else {
|
||||
|
||||
// we need to set a base root path so we can find images on the
|
||||
// local file system
|
||||
$root = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
|
||||
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] . '/'
|
||||
: '';
|
||||
}
|
||||
|
||||
$info = @getimagesize($root . $src);
|
||||
|
||||
$width = (is_null($width)) ? $info[0] : $width;
|
||||
$height = (is_null($height)) ? $info[1] : $height;
|
||||
|
||||
unset($info);
|
||||
}
|
||||
|
||||
// build the width tag
|
||||
if ($width > 0) {
|
||||
$size .= ' width="' . htmlentities($width) . '"';
|
||||
}
|
||||
|
||||
// build the height tag
|
||||
if ($height > 0) {
|
||||
$size .= ' height="' . htmlentities($height) . '"';
|
||||
}
|
||||
|
||||
// done!
|
||||
return '<img src="' . $src . '"' .
|
||||
$alt .
|
||||
$border .
|
||||
$size .
|
||||
' />';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a single <input> element.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $type The HTML "type=" value (e.g., 'text',
|
||||
* 'hidden', 'password').
|
||||
*
|
||||
* @param string $name The HTML "name=" value.
|
||||
*
|
||||
* @param mixed $value The initial value of the input element.
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the
|
||||
* checkbox element.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function input($type, $name, $value = '', $extra = '')
|
||||
{
|
||||
$output = "<input type=\"$type\" name=\"$name\" ";
|
||||
$output .= "value=\"$value\" $extra />";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a <script></script> link to a JavaScript file.
|
||||
*
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $href The HREF leading to the JavaScript source
|
||||
* file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function javascript($href)
|
||||
{
|
||||
return '<script language="javascript" type="text/javascript" src="' .
|
||||
$href . '"></script>';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a value using echo after processing with optional modifier
|
||||
* functions.
|
||||
*
|
||||
* Allows you to pass a space-separated list of value-manipulation
|
||||
* functions so that the value is "massaged" before output. For
|
||||
* example, if you want to strip slashes, force to lower case, and
|
||||
* convert to HTML entities (as for an input text box), you might do
|
||||
* this:
|
||||
*
|
||||
* $this->modify($value, 'stripslashes strtolower htmlentities');
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $value The value to be printed.
|
||||
*
|
||||
* @param string $functions A space-separated list of
|
||||
* single-parameter functions to be applied to the $value before
|
||||
* printing.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function modify($value, $functions = null)
|
||||
{
|
||||
// is there a space-delimited function list?
|
||||
if (is_string($functions)) {
|
||||
|
||||
// yes. split into an array of the
|
||||
// functions to be called.
|
||||
$list = explode(' ', $functions);
|
||||
|
||||
// loop through the function list and
|
||||
// apply to the output in sequence.
|
||||
foreach ($list as $func) {
|
||||
if (!function_exists($func)) {
|
||||
continue;
|
||||
}
|
||||
// extend this..
|
||||
if (!in_array($func, array('htmlspecialchars','nl2br','urlencode'))) {
|
||||
continue;
|
||||
}
|
||||
$value = $func($value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a series of HTML <option>s based on an associative array
|
||||
* where the key is the option value and the value is the option
|
||||
* label. You can pass a "selected" value as well to tell the
|
||||
* function which option value(s) should be marked as seleted.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array $options An associative array of key-value pairs; the
|
||||
* key is the option value, the value is the option lable.
|
||||
*
|
||||
* @param mixed $selected A string or array that matches one or more
|
||||
* option values, to tell the function what options should be marked
|
||||
* as selected. Defaults to an empty array.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function options( $options, $selected = array(), $extra = null)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
// force $selected to be an array. this allows multi-selects to
|
||||
// have multiple selected options.
|
||||
settype($selected, 'array');
|
||||
|
||||
// is $options an array?
|
||||
if (is_array($options)) {
|
||||
|
||||
// loop through the options array
|
||||
foreach ($options as $value => $label) {
|
||||
|
||||
$html .= '<option value="' . $value . '"';
|
||||
$html .= ' label="' . $label . '"';
|
||||
|
||||
if (in_array($value, $selected)) {
|
||||
$html .= ' selected="selected"';
|
||||
}
|
||||
|
||||
if (! is_null($extra)) {
|
||||
$html .= ' ' . $extra;
|
||||
}
|
||||
|
||||
$html .= ">$label</option>\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a set of radio <input>s with the same name.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $name The HTML "name=" value of all the radio <input>s.
|
||||
*
|
||||
* @param array $options An array of key-value pairs where the key is the
|
||||
* radio button value and the value is the radio button label.
|
||||
*
|
||||
* $options = array (
|
||||
* 0 => 'zero',
|
||||
* 1 => 'one',
|
||||
* 2 => 'two'
|
||||
* );
|
||||
*
|
||||
* @param string $checked A comparison string; if any of the $option
|
||||
* element values and $checked are the same, that radio button will
|
||||
* be marked as "checked" (otherwise not).
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the
|
||||
* <input /> element.
|
||||
*
|
||||
* @param string $sep The HTML text to place between every radio
|
||||
* button in the set.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
function radios(
|
||||
$name,
|
||||
$options,
|
||||
$checked = null,
|
||||
$set_unchecked = null,
|
||||
$sep = "<br />\n",
|
||||
$extra = null)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
if (is_array($options)) {
|
||||
|
||||
if (! is_null($set_unchecked)) {
|
||||
// this sets the unchecked value of the
|
||||
// radio button set.
|
||||
$html .= "<input type=\"hidden\" ";
|
||||
$html .= "name=\"$name\" ";
|
||||
$html .= "value=\"$set_unchecked\" />\n";
|
||||
}
|
||||
|
||||
foreach ($options as $value => $label) {
|
||||
$html .= "<input type=\"radio\" ";
|
||||
$html .= "name=\"$name\" ";
|
||||
$html .= "value=\"$value\"";
|
||||
|
||||
if ($value == $checked) {
|
||||
$html .= " checked=\"checked\"";
|
||||
}
|
||||
$html .= " $extra />$label$sep";
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a <link ... /> to a CSS stylesheet.
|
||||
*
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $href The HREF leading to the stylesheet file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function stylesheet($href)
|
||||
{
|
||||
return '<link rel="stylesheet" type="text/css" href="' .
|
||||
$href . '" />';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Output a single <textarea> element.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @package Savant
|
||||
*
|
||||
* @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $name The HTML "name=" value.
|
||||
*
|
||||
* @param string $text The initial value of the textarea element.
|
||||
*
|
||||
* @param int $tall How many rows tall should the area be?
|
||||
*
|
||||
* @param mixed $wide The many columns wide should the area be?
|
||||
*
|
||||
* @param string $extra Any "extra" HTML code to place within the
|
||||
* checkbox element.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
|
||||
function textarea($name, $text, $tall = 24, $wide = 80, $extra = '')
|
||||
{
|
||||
$output = "<textarea name=\"$name\" rows=\"$tall\" ";
|
||||
$output .= "cols=\"$wide\" $extra>$text</textarea>";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
179
HTML/Template/Flexy/SmartyAPI.php
Normal file
179
HTML/Template/Flexy/SmartyAPI.php
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: SmartyAPI.php,v 1.2 2004/04/03 12:08:57 alan_k Exp $
|
||||
//
|
||||
// Description this class emulates the Smarty API to attempt to enable
|
||||
// upgrading to flexy. (eg. for use with flexy templates (that have been
|
||||
// converted using the SmartyConverter Compiler.
|
||||
//
|
||||
// I've no idea how complete this will end up being..
|
||||
//
|
||||
// Technically Smarty is LGPL - so theortically no code in here should
|
||||
// use the copy & paste the original smarty code....
|
||||
//
|
||||
|
||||
// to use as a full emulator :
|
||||
// try
|
||||
// class Smarty extends HTML_Template_Flexy_SmartyAPI {
|
||||
// function Smarty() { parent::construct(); }
|
||||
// }
|
||||
|
||||
|
||||
// not implemented:
|
||||
/*
|
||||
append_by_ref
|
||||
append
|
||||
register_function / unregister_function
|
||||
register_object / register_object
|
||||
register_block / unregister_block
|
||||
register_compiler_function / unregister_compiler_function
|
||||
register_modifier / unregister_modifier
|
||||
register_resource / unregister_resource
|
||||
register_prefilter / unregister_prefilter
|
||||
register_postfilter / unregister_postfilter
|
||||
register_outputfilter / unregister_outputfilter
|
||||
load_filter
|
||||
clear_cache
|
||||
clear_all_cache
|
||||
is_cached
|
||||
template_exists
|
||||
get_template_vars
|
||||
get_config_vars
|
||||
trigger_error
|
||||
|
||||
fetch
|
||||
get_registered_object
|
||||
config_load
|
||||
clear_config
|
||||
_* (all the privates)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty API emulator for Flexy
|
||||
* - designed to make transitions simpler
|
||||
* - provides only basic support for variables
|
||||
* - uses flexy templates (that have been converted previosly with the converor)
|
||||
*
|
||||
* @version $Id: SmartyAPI.php,v 1.2 2004/04/03 12:08:57 alan_k Exp $
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_SmartyAPI {
|
||||
|
||||
/**
|
||||
* where the data for the template gets stored.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $vars = array();
|
||||
|
||||
/**
|
||||
* Standard Variable assignment
|
||||
*
|
||||
* @param string|array element name to assign value or assoc. array
|
||||
* @param mixed value of element.
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function assign($k,$v)
|
||||
{
|
||||
if (is_array($k)) {
|
||||
$this->vars = $k + $this->vars;
|
||||
return;
|
||||
}
|
||||
$this->vars[$k] = $v;
|
||||
}
|
||||
/**
|
||||
* Standard Variable assignment (by reference)
|
||||
*
|
||||
* @param string element name to assign value
|
||||
* @param mixed value of element.
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function assign_by_ref($k, &$v)
|
||||
{
|
||||
$this->vars[$k] = &$v;
|
||||
}
|
||||
/**
|
||||
* Unset a variable assignment
|
||||
*
|
||||
* @param string element name to remove
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function clear_assign($k)
|
||||
{
|
||||
if (is_array($k)) {
|
||||
foreach ($k as $kk) {
|
||||
$this->clear_assign($kk);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->vars[$k])) {
|
||||
unset($this->vars[$k]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unset all variables
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function clear_all_assign()
|
||||
{
|
||||
$this->vars = array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* output a template (optionally with flexy object & element.)
|
||||
*
|
||||
* @param string name of flexy template.
|
||||
* @param object object as per HTML_Template_Flexy:outputObject
|
||||
* @param array elements array as per HTML_Template_Flexy:outputObject
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function display($templatename,$object=null,$elements=array())
|
||||
{
|
||||
// some standard stuff available to a smarty template..
|
||||
$this->vars['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'];
|
||||
|
||||
|
||||
$o = PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
|
||||
require_once 'HTML/Template/Flexy.php';
|
||||
$t = new HTML_Template_Flexy;
|
||||
$t->compile($templatename);
|
||||
$object = ($object !== null) ? $object : new StdClass;
|
||||
|
||||
foreach($this->vars as $k=>$v) {
|
||||
$object->$k = $v;
|
||||
}
|
||||
$t->outputObject($object,$elements);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
116
HTML/Template/Flexy/Test.php
Normal file
116
HTML/Template/Flexy/Test.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: nobody <nobody@localhost> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Test.php,v 1.11 2003/10/10 09:27:32 alan_k Exp $
|
||||
//
|
||||
// This is a temporary file - it includes some of the
|
||||
// Code that will have to go in the Engine eventually..
|
||||
// Used to test parsing and generation.
|
||||
//
|
||||
|
||||
//ini_set('include_path', ini_get('include_path').realpath(dirname(__FILE__) . '/../../..'));
|
||||
require_once 'Gtk/VarDump.php';
|
||||
require_once 'Console/Getopt.php';
|
||||
require_once 'HTML/Template/Flexy.php';
|
||||
require_once 'HTML/Template/Flexy/Compiler.php';
|
||||
|
||||
// this is the main runable...
|
||||
|
||||
class HTML_Template_Flexy_Test {
|
||||
|
||||
|
||||
function HTML_Template_Flexy_Test () {
|
||||
// for testing!
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'] = array(
|
||||
'compileDir' => dirname(__FILE__),
|
||||
'locale' => 'en',
|
||||
|
||||
|
||||
);
|
||||
|
||||
$this->parseArgs();
|
||||
$this->parse();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function parseArgs() {
|
||||
// mapp of keys to values..
|
||||
|
||||
|
||||
$args = Console_Getopt::ReadPHPArgV();
|
||||
$vals = Console_Getopt::getopt($args,'');
|
||||
//print_r($vals);
|
||||
$files = $vals[1];
|
||||
|
||||
if (!$files) {
|
||||
$this->error(0,"No Files supplied");
|
||||
}
|
||||
|
||||
foreach($files as $file) {
|
||||
$realpath = realpath($file);
|
||||
if (!$realpath) {
|
||||
$this->error(0,"File $path Does not exist");
|
||||
}
|
||||
$this->files[] = $realpath;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var $files; // array of files to compile
|
||||
var $quickform;
|
||||
|
||||
function parse() {
|
||||
foreach($this->files as $file) {
|
||||
$flexy = new HTML_Template_Flexy(array(
|
||||
'compileToString'=>true,
|
||||
'valid_functions' => 'include'
|
||||
));
|
||||
$compiler = HTML_Template_Flexy_Compiler::factory($flexy->options);
|
||||
$result = $compiler->compile($flexy,file_get_contents($file));
|
||||
echo $result;
|
||||
print_r(array_unique($GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['gettextStrings']));
|
||||
print_r($flexy->elements);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function error($id,$msg) {
|
||||
echo "ERROR $id : $msg\n";
|
||||
exit(255);
|
||||
}
|
||||
|
||||
function debug($id,$msg) {
|
||||
echo "Debug Message ($id) : $msg\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
new HTML_Template_Flexy_Test;
|
||||
?>
|
||||
610
HTML/Template/Flexy/Token.php
Normal file
610
HTML/Template/Flexy/Token.php
Normal file
|
|
@ -0,0 +1,610 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Token.php,v 1.51 2005/05/14 03:44:26 alan_k Exp $
|
||||
//
|
||||
// This is the master Token file for The New Token driver Engine.
|
||||
// All the Token output, and building routines are in here.
|
||||
//
|
||||
// Note overriden methods are not documented unless they differ majorly from
|
||||
// The parent.
|
||||
//
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['base'] = 0;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'] = array();
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeForm'] = '';
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['tokens'] = array();
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['gettextStrings'] = array();
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeFormId'] = 0;
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['flexyIgnore'] = false;
|
||||
/**
|
||||
* Base Class for all Tokens.
|
||||
*
|
||||
* @abstract Provides the static Create Method, and default toString() methods
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Token {
|
||||
|
||||
/**
|
||||
* the token type (Depreciated when we have classes for all tokens
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $token;
|
||||
/**
|
||||
* the default value (normally a string)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $value;
|
||||
/**
|
||||
* the line the token is from
|
||||
*
|
||||
* @var int
|
||||
* @access public
|
||||
*/
|
||||
var $line;
|
||||
/**
|
||||
* the character Position
|
||||
*
|
||||
* @var int
|
||||
* @access public
|
||||
*/
|
||||
var $charPos;
|
||||
|
||||
|
||||
/**
|
||||
* factory a Token
|
||||
*
|
||||
* Standard factory method.. - with object vars.
|
||||
* ?? rename me to factory?
|
||||
* @param string Token type
|
||||
* @param mixed Initialization settings for token
|
||||
* @param int line that the token is defined.
|
||||
*
|
||||
*
|
||||
* @return object Created Object
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function factory($token,$value,$line,$charPos=0) {
|
||||
// try not to reload the same class to often
|
||||
static $loaded = array();
|
||||
|
||||
|
||||
$c = 'HTML_Template_Flexy_Token_'.$token;
|
||||
|
||||
if (!class_exists($c) && !isset($loaded[$token])) {
|
||||
// make sure parse errors are picked up - no @ here..
|
||||
if (file_exists(dirname(__FILE__)."/Token/{$token}.php")) {
|
||||
require_once 'HTML/Template/Flexy/Token/'.$token.'.php';
|
||||
}
|
||||
$loaded[$token] = true;
|
||||
}
|
||||
|
||||
$t = new HTML_Template_Flexy_Token;
|
||||
|
||||
if (class_exists($c)) {
|
||||
$t = new $c;
|
||||
}
|
||||
$t->token = $token;
|
||||
$t->charPos = $charPos;
|
||||
|
||||
if ($t->setValue($value) === false) {
|
||||
// kick back error conditions..
|
||||
return false;
|
||||
}
|
||||
$t->line = $line;
|
||||
|
||||
return $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard Value iterpretor
|
||||
*
|
||||
* @param mixed value recieved from factory method
|
||||
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setValue($value) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* compile to String (vistor method) replaces toString
|
||||
*
|
||||
* @return string HTML
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function compile(&$compiler) {
|
||||
return $compiler->toString($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* compile children (visitor approach).
|
||||
*
|
||||
* @return string HTML
|
||||
* @access public
|
||||
*/
|
||||
function compileChildren( &$compiler) {
|
||||
|
||||
if (!$this->children) {
|
||||
return '';
|
||||
}
|
||||
if ($this->ignoreChildren) {
|
||||
return;
|
||||
}
|
||||
$ret = '';
|
||||
//echo "output $this->id";
|
||||
//new Gtk_VarDump($this);
|
||||
foreach ($this->children as $child) {
|
||||
if (!$child) {
|
||||
continue;
|
||||
}
|
||||
$add = $child->compile($compiler);
|
||||
if (is_a($add,'PEAR_Error')) {
|
||||
return $add;
|
||||
}
|
||||
$ret .= $add;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ======================================================= */
|
||||
/* Token Managmenet = parse and store all the tokens in
|
||||
* an associative array and tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Run a Tokenizer and Store its results
|
||||
* It should build a DOM Tree of the HTML
|
||||
*
|
||||
* @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc.
|
||||
*
|
||||
* @access public
|
||||
* @return base token (really a dummy token, which contains the tree)
|
||||
* @static
|
||||
*/
|
||||
|
||||
function buildTokens($tokenizer)
|
||||
{
|
||||
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
// first record is a filler - to stick all the children on !
|
||||
// reset my globals..
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['base'] = 0;
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['statevars'] = array();
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['state'] = 0;
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = false;
|
||||
if (@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['flexyIgnore']) {
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = true;
|
||||
}
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['activeFormId'] = 0;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] = '';
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = array(new HTML_Template_Flexy_Token);
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->id =0;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['gettextStrings'] = array();
|
||||
$i=1;
|
||||
|
||||
|
||||
// initialize state - this trys to make sure that
|
||||
// you dont do to many elses etc.
|
||||
|
||||
//echo "RUNNING TOKENIZER";
|
||||
// step one just tokenize it.
|
||||
while ($t = $tokenizer->yylex()) {
|
||||
|
||||
if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) {
|
||||
//echo "ERROR";
|
||||
|
||||
//print_r($tokenizer);
|
||||
$err = "<PRE>" . $tokenizer->error . "\n" .
|
||||
htmlspecialchars(substr($tokenizer->yy_buffer,0,$tokenizer->yy_buffer_end)) .
|
||||
"<font color='red'>". htmlspecialchars(substr($tokenizer->yy_buffer,$tokenizer->yy_buffer_end,100)) .
|
||||
".......</font></PRE>";
|
||||
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::Syntax error in ".
|
||||
"Template line:'. $tokenizer->yyline .
|
||||
$err
|
||||
, HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) {
|
||||
continue;
|
||||
}
|
||||
if ( $tokenizer->value->token == 'Php' ) {
|
||||
if (!$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP']) {
|
||||
return HTML_Template_Flexy::raiseError('PHP code found in script (Token)',
|
||||
HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,HTML_TEMPLATE_FLEXY_ERROR_RETURN
|
||||
);
|
||||
}
|
||||
|
||||
if ($GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP'] === 'delete') {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
$i++;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = $tokenizer->value;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $i;
|
||||
|
||||
// this whole children thing needs rethinking
|
||||
// - I think the body of the page should be wrapped: ..
|
||||
// ?php if (!$this->bodyOnly) { .. <HTML> .... <BODY....> ?php } ?
|
||||
//
|
||||
// old values alias to new ones..
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTART'])) {
|
||||
unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTART']);
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START'] = true;
|
||||
}
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTARTCHILDREN'])) {
|
||||
unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTARTCHILDREN']);
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:STARTCHILDREN'] = true;
|
||||
}
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START'])) {
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['base'] = $i;
|
||||
unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START']);
|
||||
}
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:STARTCHILDREN'])) {
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['base'] = $i;
|
||||
}
|
||||
|
||||
|
||||
//print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]);
|
||||
|
||||
}
|
||||
//echo "BUILT TOKENS";
|
||||
|
||||
$res = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'];
|
||||
|
||||
// DEBUG DUMPTING : foreach($res as $k) { $k->dump(); }
|
||||
|
||||
|
||||
$stack = array();
|
||||
$total = $i +1;
|
||||
|
||||
// merge strings and entities - blanking out empty text.
|
||||
|
||||
|
||||
for($i=1;$i<$total;$i++) {
|
||||
if (!isset($res[$i]) || !is_a($res[$i],'HTML_Template_Flexy_Token_Text')) {
|
||||
continue;
|
||||
}
|
||||
$first = $i;
|
||||
$i++;
|
||||
while ($i<$total && is_a($res[$i],'HTML_Template_Flexy_Token_Text')) {
|
||||
if (isset($res[$i])) {
|
||||
$res[$first]->value .= $res[$i]->value;
|
||||
$res[$i]->value = '';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// connect open and close tags.
|
||||
|
||||
// this is done by having a stack for each of the tag types..
|
||||
// then removing it when it finds the closing one
|
||||
// eg.
|
||||
// <a href=""><img src=""></a>
|
||||
// ends up with a stack for <a>'s and a stack for <img>'s
|
||||
//
|
||||
//
|
||||
//
|
||||
//echo '<PRE>' . htmlspecialchars(print_R($res,true));//exit;
|
||||
//echo '<PRE>';
|
||||
for($i=1;$i<$total;$i++) {
|
||||
|
||||
if (empty($res[$i]->tag)) {
|
||||
continue;
|
||||
}
|
||||
//echo "Checking TAG $i {$res[$i]->tag}\n";
|
||||
if ($res[$i]->tag{0} == '/') { // it's a close tag..
|
||||
//echo "GOT END TAG: {$res[$i]->tag}\n";
|
||||
$tag = strtoupper(substr($res[$i]->tag,1));
|
||||
if (!count($stack)) {
|
||||
continue;
|
||||
}
|
||||
$ssc = count($stack) - 1;
|
||||
/* go up the stack trying to find a match */
|
||||
for($s = $ssc; $s > -1; $s--) {
|
||||
if (!isset($stack[$s])) {
|
||||
echo "MISSED STACK? $s<BR><PRE>";print_r($stack);exit;
|
||||
}
|
||||
if (!isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$s]])) {
|
||||
echo "STACKED BAD OFFSET : {$stack[$s]}<BR><PRE>";print_r($stack);exit;
|
||||
}
|
||||
$tok = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$s]];
|
||||
if (strtoupper($tok->tag) == $tag) {
|
||||
// got the matching closer..
|
||||
// echo "MATCH: {$i}:{$tok->tag}({$tok->line}) to {$stack[$s]}:$tag<BR>";
|
||||
$tok->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i];
|
||||
|
||||
array_splice($stack,$s);
|
||||
//print_R($stack);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$stack[] = $i;
|
||||
// tag with no closer (or unmatched in stack..)
|
||||
}
|
||||
|
||||
|
||||
// create a dummy close for the end
|
||||
$i = $total;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = new HTML_Template_Flexy_Token;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $total;
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$total];
|
||||
|
||||
// now is it possible to connect children...
|
||||
// now we need to GLOBALIZE!! -
|
||||
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = $res;
|
||||
|
||||
HTML_Template_Flexy_Token::buildChildren(0);
|
||||
//new Gtk_VarDump($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]);
|
||||
//echo '<PRE>';print_R($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$_HTML_TEMPLATE_FLEXY_TOKEN['base']] );
|
||||
return $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$_HTML_TEMPLATE_FLEXY_TOKEN['base']];
|
||||
}
|
||||
/**
|
||||
* Matching closing tag for a Token
|
||||
*
|
||||
* @var object|none optional closing tag
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
var $close;
|
||||
|
||||
/**
|
||||
* array of children to each object.
|
||||
*
|
||||
* @var array
|
||||
* @access public|private
|
||||
*/
|
||||
|
||||
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* Build the child array for each element.
|
||||
* RECURSIVE FUNCTION!!!!
|
||||
* @param int id of node to add children to.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function buildChildren($id)
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
$base = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$id];
|
||||
$base->children = array();
|
||||
$start = $base->id +1;
|
||||
$end = $base->close->id;
|
||||
|
||||
for ($i=$start; $i<$end; $i++) {
|
||||
//echo "{$base->id}:{$base->tag} ADDING {$i}{$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->tag}<BR>";
|
||||
//if ($base->id == 1176) {
|
||||
// echo "<PRE>";print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]);
|
||||
// }
|
||||
|
||||
$base->children[] = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i];
|
||||
|
||||
if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]) &&
|
||||
is_object($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close)) {
|
||||
|
||||
// if the close id is greater than my id - ignore it! -
|
||||
if ($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id > $end) {
|
||||
continue;
|
||||
}
|
||||
HTML_Template_Flexy_Token::buildChildren($i);
|
||||
$i = $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Flag to ignore children - Used to block output for select/text area etc.
|
||||
* may not be required as I moved the Tag parsing into the toString ph
|
||||
*
|
||||
* @var boolean ingore children
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
var $ignoreChildren = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/* ======================================================== */
|
||||
/* variable STATE management
|
||||
*
|
||||
* raw variables are assumed to be $this->, unless defined by foreach..
|
||||
* it also monitors syntax - eg. end without an if/foreach etc.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* tell the generator you are entering a block
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function pushState()
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['state']++;
|
||||
$s = $_HTML_TEMPLATE_FLEXY_TOKEN['state'];
|
||||
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars
|
||||
}
|
||||
/**
|
||||
* tell the generator you are entering a block
|
||||
*
|
||||
* @return boolean parse error - out of bounds
|
||||
* @access public
|
||||
*/
|
||||
function pullState()
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
$s = $_HTML_TEMPLATE_FLEXY_TOKEN['state'];
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['state']--;
|
||||
if ($s<0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* get the real variable name formated x.y.z => $this->x->y->z
|
||||
* if a variable is in the stack it return $x->y->z
|
||||
*
|
||||
* @return string PHP variable
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function toVar($s) {
|
||||
// wrap [] with quotes.
|
||||
$s = str_replace('[',"['",$s);
|
||||
$s = str_replace('%5b',"['",$s);
|
||||
$s = str_replace('%5B',"['",$s);
|
||||
$s = str_replace(']',"']",$s);
|
||||
$s = str_replace('%5d',"']",$s);
|
||||
$s = str_replace('%5D',"']",$s);
|
||||
// strip the quotes if it's only numbers..
|
||||
$s = preg_replace("/'([-]?[0-9]+)'/", "\\1",$s);
|
||||
|
||||
$parts = explode(".",$s);
|
||||
|
||||
|
||||
$ret = $this->findVar($parts[0]);
|
||||
if (is_a($ret,'PEAR_Error')) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
array_shift($parts);
|
||||
|
||||
if (!count($parts)) {
|
||||
return $ret;
|
||||
}
|
||||
foreach($parts as $p) {
|
||||
$ret .= "->{$p}";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* do the stack lookup on the variable
|
||||
* this relates to flexy
|
||||
* t relates to the object being parsed.
|
||||
*
|
||||
* @return string PHP variable
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function findVar($string)
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
|
||||
if (!$string || $string == 't') {
|
||||
return '$t';
|
||||
}
|
||||
if ($string == 'this') {
|
||||
return '$this';
|
||||
}
|
||||
// accept global access on some string
|
||||
if (@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globals'] &&
|
||||
preg_match('/^(_POST|_GET|_REQUEST|_SESSION|_COOKIE|GLOBALS)\[/',$string)) {
|
||||
return '$'.$string;
|
||||
}
|
||||
if (!@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['privates'] &&
|
||||
($string{0} == '_')) {
|
||||
return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::Attempt to access private variable:'.
|
||||
" on line {$this->line} of {$GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']}".
|
||||
", Use options[privates] to allow this."
|
||||
, HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,HTML_TEMPLATE_FLEXY_ERROR_RETURN);
|
||||
}
|
||||
|
||||
$lookup = $string;
|
||||
if ($p = strpos($string,'[')) {
|
||||
$lookup = substr($string,0,$p);
|
||||
}
|
||||
|
||||
|
||||
for ($s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; $s > 0; $s--) {
|
||||
if (in_array($lookup , $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s])) {
|
||||
return '$'.$string;
|
||||
}
|
||||
}
|
||||
return '$t->'.$string;
|
||||
}
|
||||
/**
|
||||
* add a variable to the stack.
|
||||
*
|
||||
* @param string PHP variable
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function pushVar($string)
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
$s = $_HTML_TEMPLATE_FLEXY_TOKEN['state'];
|
||||
$_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s][] = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* dump to text ATM
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function dump() {
|
||||
echo "{$this->token}/" . (isset($this->tag) ? "<{$this->tag}>" : '') . ": {$this->value}\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
35
HTML/Template/Flexy/Token/Else.php
Normal file
35
HTML/Template/Flexy/Token/Else.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Else.php,v 1.3 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle Else
|
||||
*
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Token_Else extends HTML_Template_Flexy_Token {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
33
HTML/Template/Flexy/Token/End.php
Normal file
33
HTML/Template/Flexy/Token/End.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: End.php,v 1.3 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle End statements (eg. close brakets)
|
||||
*
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Token_End extends HTML_Template_Flexy_Token {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
35
HTML/Template/Flexy/Token/EndTag.php
Normal file
35
HTML/Template/Flexy/Token/EndTag.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: EndTag.php,v 1.2 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* The closing HTML Tag = eg. /Table or /Body etc.
|
||||
*
|
||||
* @abstract
|
||||
* This just extends the generic HTML tag
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'HTML/Template/Flexy/Token/Tag.php';
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Token_EndTag extends HTML_Template_Flexy_Token_Tag { }
|
||||
|
||||
|
||||
72
HTML/Template/Flexy/Token/Foreach.php
Normal file
72
HTML/Template/Flexy/Token/Foreach.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Foreach.php,v 1.3 2004/04/03 03:44:58 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle foreach statements
|
||||
*
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Token_Foreach extends HTML_Template_Flexy_Token {
|
||||
|
||||
/**
|
||||
* variable to loop on.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $loopOn = '';
|
||||
/**
|
||||
* key value
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $key = '';
|
||||
/**
|
||||
* optional value (in key=>value pair)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $value = '';
|
||||
|
||||
/**
|
||||
* Setvalue - a array of all three (last one optional)
|
||||
* @see parent::setValue()
|
||||
*/
|
||||
|
||||
function setValue($value) {
|
||||
$this->loopOn=$value[0];
|
||||
if (!isset($value[1]) || !strlen(trim($value[1]))) {
|
||||
// error condition.
|
||||
return false;
|
||||
}
|
||||
$this->key=$value[1];
|
||||
$this->value=@$value[2];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
62
HTML/Template/Flexy/Token/If.php
Normal file
62
HTML/Template/Flexy/Token/If.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: If.php,v 1.5 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle If statements
|
||||
*
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Token_If extends HTML_Template_Flexy_Token{
|
||||
/**
|
||||
* Condition for the if statement.
|
||||
* @var string // a variable
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $condition;
|
||||
/**
|
||||
* if the statement is negative = eg. !somevar..
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
var $isNegative = '';
|
||||
|
||||
/**
|
||||
* Setvalue - a string
|
||||
* @see parent::setValue()
|
||||
*/
|
||||
function setValue($value) {
|
||||
//var_dump($value);
|
||||
if (strlen($value) && $value{0} == '!') {
|
||||
$this->isNegative = '!';
|
||||
$value = substr($value,1);
|
||||
}
|
||||
$this->condition=$value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
95
HTML/Template/Flexy/Token/Method.php
Normal file
95
HTML/Template/Flexy/Token/Method.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Method.php,v 1.14 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
/**
|
||||
* Class to handle method calls
|
||||
* *
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Token_Method extends HTML_Template_Flexy_Token {
|
||||
/**
|
||||
* variable modifier (h = raw, u = urlencode, none = htmlspecialchars)
|
||||
* TODO
|
||||
* @var char
|
||||
* @access public
|
||||
*/
|
||||
var $modifier;
|
||||
/**
|
||||
* Method name
|
||||
*
|
||||
* @var char
|
||||
* @access public
|
||||
*/
|
||||
var $method;
|
||||
/**
|
||||
* is it in if statement with a method?
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $isConditional;
|
||||
/**
|
||||
* if the statement is negative = eg. !somevar..
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $isNegative = '';
|
||||
|
||||
/**
|
||||
* arguments, either variables or literals eg. #xxxxx yyyy#
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $args= array();
|
||||
/**
|
||||
* setvalue - at present array method, args (need to add modifier)
|
||||
* @see parent::setValue()
|
||||
*/
|
||||
|
||||
function setValue($value) {
|
||||
// var_dump($value);
|
||||
$method = $value[0];
|
||||
if (substr($value[0],0,3) == 'if:') {
|
||||
$this->isConditional = true;
|
||||
if ($value[0]{3} == '!') {
|
||||
$this->isNegative = '!';
|
||||
$method = substr($value[0],4);
|
||||
} else {
|
||||
$method = substr($value[0],3);
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($method,":")) {
|
||||
list($method,$this->modifier) = explode(':',$method);
|
||||
}
|
||||
$this->method = $method;
|
||||
|
||||
$this->args = $value[1];
|
||||
// modifier TODO!
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
34
HTML/Template/Flexy/Token/Processing.php
Normal file
34
HTML/Template/Flexy/Token/Processing.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Processing.php,v 1.3 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle Processing Directives = <?xml or <?php
|
||||
*
|
||||
*
|
||||
*/
|
||||
class HTML_Template_Flexy_Token_Processing extends HTML_Template_Flexy_Token {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
212
HTML/Template/Flexy/Token/Tag.php
Normal file
212
HTML/Template/Flexy/Token/Tag.php
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Tag.php,v 1.49 2004/08/16 09:12:23 alan_k Exp $
|
||||
|
||||
|
||||
$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN_TAG']['activeSelect'] = false;
|
||||
require_once 'HTML/Template/Flexy/Element.php';
|
||||
/**
|
||||
* A standard HTML Tag = eg. Table/Body etc.
|
||||
*
|
||||
* @abstract
|
||||
* This is the generic HTML tag
|
||||
* a simple one will have some attributes and a name.
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token {
|
||||
|
||||
/**
|
||||
* HTML Tag: eg. Body or /Body - uppercase
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $tag = '';
|
||||
/**
|
||||
* HTML Tag: (original case)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $oTag = '';
|
||||
/**
|
||||
* Associative array of attributes. (original case)
|
||||
*
|
||||
* key is the left, value is the right..
|
||||
* note:
|
||||
* values are raw (eg. include "")
|
||||
* valuse can be
|
||||
* text = standard
|
||||
* array (a parsed value with flexy tags in)
|
||||
* object (normally some PHP code that generates the key as well..)
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $attributes = array();
|
||||
|
||||
/**
|
||||
* Associative array of attributes ucase to Original Case for attributes..
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $ucAttributes = array();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* postfix tokens
|
||||
* used to add code to end of tags "<xxxx>here....children .. <close tag>"
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $postfix = '';
|
||||
/**
|
||||
* prefix tokens
|
||||
* used to add code to beginning of tags TODO "here<xxxx>....children .. <close tag>"
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $prefix = '';
|
||||
|
||||
|
||||
/**
|
||||
* Alias to closing tag (built externally).
|
||||
* used to add < ? } ? > code to dynamic tags.
|
||||
* @var object alias
|
||||
* @access public
|
||||
*/
|
||||
var $close; // alias to closing tag.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Setvalue - gets name, attribute as an array
|
||||
* @see parent::setValue()
|
||||
*/
|
||||
|
||||
function setValue($value)
|
||||
{
|
||||
global $_HTML_TEMPLATE_FLEXY_TOKEN;
|
||||
$this->tag = strtoupper($value[0]);
|
||||
$this->oTag = $value[0];
|
||||
if (isset($value[1])) {
|
||||
$this->attributes = $value[1];
|
||||
}
|
||||
|
||||
foreach(array_keys($this->attributes) as $k) {
|
||||
$this->ucAttributes[strtoupper($k)] =& $this->attributes[$k];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* getAttribute = reads an attribute value and strips the quotes
|
||||
*
|
||||
* TODO
|
||||
* does not handle values with flexytags in them
|
||||
*
|
||||
* @return string (
|
||||
* @access public
|
||||
*/
|
||||
function getAttribute($key) {
|
||||
// all attribute keys are stored Upper Case,
|
||||
// however just to make sure we have not done a typo :)
|
||||
$key = strtoupper($key);
|
||||
//echo "looking for $key\n";
|
||||
//var_dump($this->attributes);
|
||||
|
||||
// this is weird case isset() returns false on this being null!
|
||||
|
||||
if (@$this->ucAttributes[$key] === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isset($this->ucAttributes[$key])) {
|
||||
return false;
|
||||
}
|
||||
// general assumption - none of the tools can do much with dynamic
|
||||
// attributes - eg. stuff with flexy tags in it.
|
||||
if (!is_string($this->ucAttributes[$key])) {
|
||||
return false;
|
||||
}
|
||||
$v = $this->ucAttributes[$key];
|
||||
|
||||
// unlikely :)
|
||||
if ($v=='') {
|
||||
return $v;
|
||||
}
|
||||
|
||||
switch($v{0}) {
|
||||
case "\"":
|
||||
case "'":
|
||||
return substr($v,1,-1);
|
||||
default:
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getAttributes = returns all the attributes key/value without quotes
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* @access string
|
||||
*/
|
||||
|
||||
function getAttributes() {
|
||||
$ret = array();
|
||||
foreach($this->attributes as $k=>$v) {
|
||||
if (substr(strtoupper($k),0,6) == 'FLEXY:') {
|
||||
continue;
|
||||
}
|
||||
$ret[$k] = $this->getAttribute($k);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* clearAttributes = removes an attribute from the object.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* @access string
|
||||
*/
|
||||
function clearAttribute($string) {
|
||||
if (isset($this->attributes[$string])) {
|
||||
unset($this->attributes[$string]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
54
HTML/Template/Flexy/Token/Text.php
Normal file
54
HTML/Template/Flexy/Token/Text.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Text.php,v 1.12 2004/12/22 02:22:03 alan_k Exp $
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Class that represents a text string node.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Token_Text extends HTML_Template_Flexy_Token {
|
||||
|
||||
|
||||
/**
|
||||
* Simple check to see if this piece of text is a word
|
||||
* so that gettext and the merging tricks dont try
|
||||
* - merge white space with a flexy tag
|
||||
* - gettext doesnt translate etc.
|
||||
*
|
||||
* @return boolean true if this is a word
|
||||
* @access public
|
||||
*/
|
||||
function isWord() {
|
||||
if (!strlen(trim($this->value))) {
|
||||
return false;
|
||||
}
|
||||
if (preg_match('/^\&[a-z0-9]+;$/i',trim($this->value))) {
|
||||
return false;
|
||||
}
|
||||
return preg_match('/[a-z]/i',$this->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
53
HTML/Template/Flexy/Token/Var.php
Normal file
53
HTML/Template/Flexy/Token/Var.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Var.php,v 1.7 2003/12/10 02:36:26 alan_k Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* Class to handle variable output
|
||||
* *
|
||||
*
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Token_Var extends HTML_Template_Flexy_Token {
|
||||
|
||||
/**
|
||||
* variable modifier (h = raw, u = urlencode, none = htmlspecialchars)
|
||||
*
|
||||
* @var char
|
||||
* @access public
|
||||
*/
|
||||
var $modifier;
|
||||
/**
|
||||
* Setvalue - at present raw text.. - needs sorting out..
|
||||
* @see parent::setValue()
|
||||
*/
|
||||
function setValue($value) {
|
||||
// comes in as raw {xxxx}, {xxxx:h} or {xxx.yyyy:h}
|
||||
|
||||
if (strpos($value,":")) {
|
||||
list($value,$this->modifier) = explode(':',$value);
|
||||
}
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
4333
HTML/Template/Flexy/Tokenizer.php
Normal file
4333
HTML/Template/Flexy/Tokenizer.php
Normal file
File diff suppressed because it is too large
Load diff
472
HTML/Template/Flexy/Translator.php
Normal file
472
HTML/Template/Flexy/Translator.php
Normal file
|
|
@ -0,0 +1,472 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: nobody <nobody@localhost> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Translator.php,v 1.8 2006/01/09 03:05:01 alan_k Exp $
|
||||
//
|
||||
// Controller Type Class providing translation faciliites
|
||||
//
|
||||
|
||||
/*
|
||||
|
||||
usage :
|
||||
|
||||
$t = new HTML_Template_Flexy_Translator(array(
|
||||
'baseLang' => 'en',
|
||||
'targetLangs' => array('es','fr','zh'),
|
||||
'appURL' => '/admin/translate.php',
|
||||
|
||||
));
|
||||
$t->process(isset($_GET ? $_GET : array(),isset($_POST ? $_POST : array()); // read data.. etc.
|
||||
// you can replace this pretty easily with your own templates..
|
||||
$t->outputDefautTemplate();
|
||||
|
||||
*/
|
||||
|
||||
class HTML_Template_Flexy_Translator {
|
||||
|
||||
/**
|
||||
* Options for Translator tool.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $options = array(
|
||||
'baseLang' => 'en', // the language the templates are in.
|
||||
'targetLangs' => array('fr'), // the language the templates are being translated to.
|
||||
'templateDir' => '', // these are read from global config if not set.
|
||||
'compileDir' => '',
|
||||
'url_rewrite' => '', // for image rewriting.. -- needs better thinking through!
|
||||
'appURL' => '', // url to translation too : eg. /admin/translator.php
|
||||
'Translation2' => array(
|
||||
'driver' => 'dataobjectsimple',
|
||||
'options' => 'translations'
|
||||
),
|
||||
|
||||
);
|
||||
/**
|
||||
* app URL (copied from above)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $appURL;
|
||||
var $languages = array();
|
||||
/**
|
||||
* Array of templates and the words found in each one.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $words= array();
|
||||
/**
|
||||
* Array of objects with name, md5's, has it been set, the translation etc.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $status = array();
|
||||
/**
|
||||
* The current language
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $translate = ''; // language being displayed /edited.
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* Just set options (no checking done)
|
||||
*
|
||||
*
|
||||
* @param array see options array in file.
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function HTML_Template_Flexy_Translator($options= array()) {
|
||||
foreach($options as $k=>$v) {
|
||||
$this->options[$k] = $v;
|
||||
}
|
||||
if (!in_array($this->options['baseLang'], $this->options['targetLangs'])) {
|
||||
$this->options['targetLangs'][] = $this->options['baseLang'];
|
||||
}
|
||||
$o = PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
if (!strlen($this->options['templateDir'])) {
|
||||
$this->options['templateDir'] = $o['templateDir'];
|
||||
}
|
||||
if (!strlen($this->options['compileDir'])) {
|
||||
$this->options['compileDir'] = $o['compileDir'];
|
||||
}
|
||||
if (!strlen($this->options['url_rewrite'])) {
|
||||
$this->options['url_rewrite'] = $o['url_rewrite'];
|
||||
}
|
||||
if (empty($this->options['Translation2'])) {
|
||||
$this->options['Translation2'] = $o['Translation2'];
|
||||
}
|
||||
$this->appURL = $this->options['appURL'];
|
||||
$this->languages = $this->options['targetLangs'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* process the input
|
||||
*
|
||||
*
|
||||
* @param array $_GET; (translate = en)
|
||||
* @param array $_POST; (translate = en, en[{md5}] = translation)
|
||||
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
|
||||
function process($get,$post) {
|
||||
//DB_DataObject::debugLevel(1);
|
||||
|
||||
$displayLang = isset($get['translate']) ? $get['translate'] :
|
||||
(isset($post['translate']) ? $post['translate'] : false);
|
||||
|
||||
if ($displayLang === false) {
|
||||
return;
|
||||
}
|
||||
require_once 'Translation2/Admin.php';
|
||||
|
||||
$driver = $this->options['Translation2']['driver'];
|
||||
$options = $this->options['Translation2']['options'];
|
||||
$usingGT = ($driver == 'gettext');
|
||||
$usingDO = ($driver == 'dataobjectsimple');
|
||||
$trd = &Translation2_Admin::factory($driver, $options);
|
||||
|
||||
|
||||
|
||||
//$trd->setDecoratedLang('en');
|
||||
foreach($this->options['targetLangs'] as $l) {
|
||||
$trd->addLang(array(
|
||||
'lang_id' => $l
|
||||
));
|
||||
}
|
||||
|
||||
// back to parent if no language selected..
|
||||
|
||||
if (!in_array($displayLang, $this->options['targetLangs'] )) {
|
||||
require_once 'PEAR.php';
|
||||
return PEAR::raiseError('Unknown Language :' .$displayLang);
|
||||
}
|
||||
|
||||
$this->translate = $displayLang;
|
||||
|
||||
|
||||
if (isset($post['_apply'])) {
|
||||
$this->clearTemplateCache($displayLang);
|
||||
|
||||
}
|
||||
$t = explode(' ',microtime()); $start= $t[0] + $t[1];
|
||||
|
||||
require_once 'Translation2.php';
|
||||
$tr = &Translation2::factory($driver, $options);
|
||||
$tr->setLang($displayLang);
|
||||
|
||||
if (!$usingDO) {
|
||||
$suggestions = &Translation2::factory($driver, $options);
|
||||
$suggestions->setLang($displayLang);
|
||||
}
|
||||
|
||||
$this->compileAll();
|
||||
|
||||
//$tr->setPageID('test.html');
|
||||
// delete them after we have compiled them!!
|
||||
if (isset($post['_apply'])) {
|
||||
$this->clearTemplateCache($displayLang);
|
||||
}
|
||||
//DB_DataObject::debugLevel(1);
|
||||
$this->loadTranslations();
|
||||
$this->loadTranslations($displayLang);
|
||||
if ($usingDO) {
|
||||
$this->loadTranslations();
|
||||
$this->loadTranslations($displayLang);
|
||||
}
|
||||
|
||||
$all = array();
|
||||
|
||||
if ($usingGT) {
|
||||
$trd->storage->begin();
|
||||
}
|
||||
$displayLangClean = str_replace('.', '_', $displayLang);
|
||||
|
||||
foreach($this->words as $page=>$words) {
|
||||
$status[$page] = array();
|
||||
$tr->setPageID($page);
|
||||
// pages....
|
||||
if (isset($post['_clear']) && !PEAR::isError($p = $trd->getPage($page, $displayLang))) {
|
||||
$diff = array_diff(array_keys($p), $words);
|
||||
if (count($diff)) {
|
||||
foreach ($diff as $string) {
|
||||
$trd->remove($string, $page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($words as $word) {
|
||||
|
||||
if (!strlen(trim($word))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$md5 = md5($page.':'.$word);
|
||||
|
||||
$value = $usingDO ? $this->getTranslation($page,$word,$displayLang) : $tr->get($word);
|
||||
|
||||
// we posted something..
|
||||
if (isset($post[$displayLangClean][$md5])) {
|
||||
// eak we shouldnt really deal with magic_quotes!!!
|
||||
$nval = str_replace("\r\n", "\n", get_magic_quotes_gpc() ? stripslashes($post[$_displayLang][$md5]) : $post[$_displayLang][$md5]);
|
||||
|
||||
if ($value != $nval) {
|
||||
$trd->add($word,$page,array($displayLang=>$nval));
|
||||
$value = $nval;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value == '') {
|
||||
// try the old gettext...
|
||||
if (isset($old[addslashes($word)])) {
|
||||
$trd->add($word,$page,array($displayLang=>$old[addslashes($word)]));
|
||||
$value = $old[addslashes($word)];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$add = new StdClass;
|
||||
|
||||
$add->from = $word;
|
||||
$add->to = $value;
|
||||
if (!$add->to || ($add->from == $add->to)) {
|
||||
$add->untranslated = true;
|
||||
|
||||
if ($usingDO) {
|
||||
$add->suggest = implode(', ', $this->getSuggestions($word, $displayLang));
|
||||
} else {
|
||||
$suggest = $suggestions->get($word);
|
||||
if ($suggest && ($suggest != $word)) {
|
||||
$add->suggest = $suggest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$add->md5 = $md5;
|
||||
// show big or small text entry..
|
||||
$add->short = (bool) (strlen($add->from) < 30 && strstr($add->from, "\n") === false);
|
||||
|
||||
$status[$page][] = $add;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ($usingGT) {
|
||||
$trd->storage->commit();
|
||||
}
|
||||
$t = explode(' ',microtime()); $total= $t[0] + $t[1] - $start;
|
||||
//printf("Built All in %0.2fs<BR>",$total);
|
||||
$this->status = $status;
|
||||
|
||||
|
||||
|
||||
}
|
||||
var $translations = array();
|
||||
var $translationMap = array();
|
||||
|
||||
/**
|
||||
* LoadTranslations - load all the translations from the database
|
||||
* into $this->translations[{lang}][{id}] = $translation;
|
||||
*
|
||||
*
|
||||
* @param string Language
|
||||
* @access public
|
||||
*/
|
||||
function loadTranslations ($lang= false) {
|
||||
$d = DB_DataObject::factory('translations');
|
||||
$d->lang = ($lang == false) ? '-' : $lang;
|
||||
$d->find();
|
||||
$this->translations[$d->lang] = array();
|
||||
while ($d->fetch()) {
|
||||
$this->translations[$d->lang][$d->string_id] = $d->translation;
|
||||
if ($lang == false) {
|
||||
$this->translationMap[$d->page][$d->translation] = $d->string_id;
|
||||
}
|
||||
// suggestions:?
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getSuggestions($string,$lang) {
|
||||
$ids = array();
|
||||
//echo '<PRE>';print_r($this->translationMap);
|
||||
foreach($this->translationMap as $page=>$map) {
|
||||
if (isset($map[$string])) {
|
||||
$ids[] = $map[$string];
|
||||
}
|
||||
}
|
||||
//echo '<PRE>';print_r(array($string,$lang,$ids,$this->translations[$lang]));
|
||||
|
||||
//exit;
|
||||
if (!$ids) {
|
||||
return array();
|
||||
}
|
||||
$ret = array();
|
||||
foreach($ids as $id) {
|
||||
if (isset($this->translations[$lang][$id])) {
|
||||
$ret[] = $this->translations[$lang][$id];
|
||||
}
|
||||
}
|
||||
// echo '<PRE>';print_r($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getTranslation($page,$word,$lang)
|
||||
{
|
||||
|
||||
if (!isset($this->translationMap[$page][$word])) {
|
||||
//echo "No string id for $page : $word\n";
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->translations[$lang][$this->translationMap[$page][$word]])) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return $this->translations[$lang][$this->translationMap[$page][$word]];
|
||||
}
|
||||
/**
|
||||
* compile all the templates in a specified folder.
|
||||
*
|
||||
*
|
||||
* @param string subdirectory of templateDir or empty
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function compileAll($d='') {
|
||||
set_time_limit(0); // this could take quite a while!!!
|
||||
|
||||
$words = array();
|
||||
$dname = $d ? $this->options['templateDir'] .'/'.$d : $this->options['templateDir'];
|
||||
//echo "Open $dname<BR>";
|
||||
$dh = opendir( $dname);
|
||||
require_once 'HTML/Template/Flexy.php';
|
||||
$o = $this->options;
|
||||
$o['fatalError'] = PEAR_ERROR_RETURN;
|
||||
$o['locale'] = 'en';
|
||||
while (($name = readdir($dh)) !== false) {
|
||||
$fname = $d ? $d .'/'. $name : $name;
|
||||
|
||||
if ($name{0} == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($this->options['templateDir'] . '/'. $fname)) {
|
||||
$this->compileAll($fname);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!preg_match('/\.html$/',$name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oo = $o;// $oo['debug'] = 1;
|
||||
$x = new HTML_Template_Flexy( $oo );
|
||||
$r = $x->compile($fname);
|
||||
|
||||
//printf(" %0.3fs : $fname<BR>", $time);
|
||||
if (is_a($r,'PEAR_Error')) {
|
||||
echo "compile failed on $fname<BR>";
|
||||
echo $r->toString();
|
||||
continue;
|
||||
}
|
||||
$this->words[$fname] = file_exists($x->getTextStringsFile) ?
|
||||
unserialize(file_get_contents($x->getTextStringsFile)) :
|
||||
array();
|
||||
}
|
||||
//echo '<PRE>';print_R($words);exit;
|
||||
|
||||
ksort($this->words);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete all the compiled templates in a specified language
|
||||
*
|
||||
*
|
||||
* @param string language
|
||||
* @param string subdirectory of templateDir or empty
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function clearTemplateCache($lang='en',$d = '') {
|
||||
|
||||
$dname = $d ? $this->options['templateDir'] .'/'.$d : $this->options['templateDir'];
|
||||
|
||||
$dh = opendir($dname);
|
||||
while (($name = readdir($dh)) !== false) {
|
||||
$fname = $d ? $d .'/'. $name : $name;
|
||||
|
||||
if ($name{0} == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($this->options['templateDir'] . '/'. $fname)) {
|
||||
$this->clearTemplateCache($lang,$fname);
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/\.html$/',$name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = "{$this->options['compileDir']}/{$fname}.{$lang}.php";
|
||||
|
||||
if (file_exists($file)) {
|
||||
// echo "DELETE $file?";
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
clearstatcache();
|
||||
}
|
||||
/**
|
||||
* output the default template with the editing facilities.
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
function outputDefaultTemplate() {
|
||||
$o = array(
|
||||
'compileDir' => ini_get('session.save_path') . '/HTML_Template_Flexy_Translate',
|
||||
'templateDir' => dirname(__FILE__).'/templates'
|
||||
);
|
||||
$x = new HTML_Template_Flexy( $o );
|
||||
$x->compile('translator.html');
|
||||
$x->outputObject($this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
333
HTML/Template/Flexy/Tree.php
Normal file
333
HTML/Template/Flexy/Tree.php
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alan Knowles <alan@akbkhome.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Tree.php,v 1.5 2005/01/31 06:57:44 alan_k Exp $
|
||||
//
|
||||
// The Html Tree Component of Flexy
|
||||
// Designed to be used on it's own
|
||||
//
|
||||
//
|
||||
//
|
||||
// The concept:
|
||||
// - it builds a big tokens[] array :
|
||||
// - filters "Text with {placeholders}" into sprintf formated strings.
|
||||
// - matches closers to openers eg. token[4]->close = &token[5];
|
||||
// - it aliases the tokens into token[0] as children as a tree
|
||||
// - locates the base of the file. (flexy:startchildren.
|
||||
// returns a nice tree..
|
||||
|
||||
|
||||
class HTML_Template_Flexy_Tree {
|
||||
|
||||
/**
|
||||
* Options for Tree:
|
||||
* 'ignore' => dont change {xxxX} into placeholders?
|
||||
* 'filename' => filename of file being parsed. (for error messages.)
|
||||
* 'ignore_html' => return <html> elements as strings.
|
||||
* 'ignore_php' => DELETE/DESTROY any php code in the original template.
|
||||
*/
|
||||
|
||||
var $options = array(
|
||||
'ignore' => false, // was flexyIgnore
|
||||
'filename' => false,
|
||||
'ignore_html' => false,
|
||||
'ignore_php' => true,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Array of all tokens (eg. nodes / text / tags etc. )
|
||||
* All nodes have ID's
|
||||
*
|
||||
* eg.
|
||||
* <b>some text</b>
|
||||
* [0] => Token_Tag::
|
||||
* tagname = '<b>'
|
||||
* children = array( &tag[1] );
|
||||
close = &tag[2];
|
||||
* [1] => Token_Text::'some test'
|
||||
* [2] => Token_Tag::
|
||||
* tagname = '</b>';
|
||||
*
|
||||
*
|
||||
* under normal situations, the tree is built into node[0], the remaining nodes are referenced by alias.
|
||||
* if caching is used (the nodes > 0 will not exist, and everything will just be a child of node 0.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $tokens = array();
|
||||
var $strings = array();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run a Tokenizer and Store its results and return the tree.
|
||||
* It should build a DOM Tree of the HTML
|
||||
*
|
||||
* @param string $data data to parse.
|
||||
* @param array $options see options array.
|
||||
*
|
||||
* @access public
|
||||
* @return base token (really a dummy token, which contains the tree)
|
||||
* @static
|
||||
*/
|
||||
|
||||
function construct($data,$options=array())
|
||||
{
|
||||
|
||||
// local caching!
|
||||
$md5 = md5($data);
|
||||
if (isset($GLOBALS[__CLASS__]['cache'][$md5])) {
|
||||
return $GLOBALS[__CLASS__]['cache'][$md5];
|
||||
}
|
||||
|
||||
$t = new HTML_Template_Flexy_Tree;
|
||||
$t->options = $t->options + $options;
|
||||
require_once 'HTML/Template/Flexy/Token.php';
|
||||
$t->tokens = array(new HTML_Template_Flexy_Token);
|
||||
$t->tokens[0]->id =0;
|
||||
|
||||
// process
|
||||
if (is_a($r = $t->tokenize($data),'PEAR_Error')) {
|
||||
return $r;
|
||||
}
|
||||
|
||||
$t->matchClosers();
|
||||
$t->buildChildren(0);
|
||||
//new Gtk_VarDump($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]);
|
||||
|
||||
$GLOBALS[__CLASS__]['cache'][$md5] = $t->returnStart();
|
||||
return $GLOBALS[__CLASS__]['cache'][$md5];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The core tokenizing part - runs the tokenizer on the data,
|
||||
* and stores the results in $this->tokens[]
|
||||
*
|
||||
* @param string Data to tokenize
|
||||
*
|
||||
* @return none | PEAR::Error
|
||||
* @access public|private
|
||||
* @see see also methods.....
|
||||
*/
|
||||
|
||||
|
||||
function tokenize($data) {
|
||||
require_once 'HTML/Template/Flexy/Tokenizer.php';
|
||||
$tokenizer = &HTML_Template_Flexy_Tokenizer::construct($data,$this->options);
|
||||
|
||||
// initialize state - this trys to make sure that
|
||||
// you dont do to many elses etc.
|
||||
|
||||
//echo "RUNNING TOKENIZER";
|
||||
// step one just tokenize it.
|
||||
$i=1;
|
||||
while ($t = $tokenizer->yylex()) {
|
||||
|
||||
if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) {
|
||||
return HTML_Template_Flexy::raiseError(
|
||||
array(
|
||||
"HTML_Template_Flexy_Tree::Syntax error in File: %s (Line %s)\n".
|
||||
"Tokenizer Error: %s\n".
|
||||
"Context:\n\n%s\n\n >>>>>> %s\n",
|
||||
$this->options['filename'], $tokenizer->yyline ,
|
||||
$tokenizer->error,
|
||||
htmlspecialchars(substr($tokenizer->yy_buffer,0,$tokenizer->yy_buffer_end)),
|
||||
htmlspecialchars(substr($tokenizer->yy_buffer,$tokenizer->yy_buffer_end,100))
|
||||
)
|
||||
,HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,HTML_TEMPLATE_FLEXY_ERROR_DIE);
|
||||
}
|
||||
|
||||
if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) {
|
||||
continue;
|
||||
}
|
||||
if ($t->token == 'Php') {
|
||||
continue;
|
||||
}
|
||||
$i++;
|
||||
$this->tokens[$i] = $tokenizer->value;
|
||||
$this->tokens[$i]->id = $i;
|
||||
|
||||
|
||||
|
||||
//print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]);
|
||||
|
||||
}
|
||||
//echo "BUILT TOKENS";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Match the opening and closing tags eg. </B> is the closer of <B>
|
||||
*
|
||||
* aliases the ->close to the tokens[{closeid}] element
|
||||
*
|
||||
* @return none
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function matchClosers()
|
||||
{
|
||||
$res = &$this->tokens;
|
||||
$total = count($this->tokens);
|
||||
// connect open and close tags.
|
||||
|
||||
// this is done by having a stack for each of the tag types..
|
||||
// then removing it when it finds the closing one
|
||||
// eg.
|
||||
// <a href=""><img src=""></a>
|
||||
// ends up with a stack for <a>'s and a stack for <img>'s
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
for($i=1;$i<$total;$i++) {
|
||||
//echo "Checking TAG $i\n";
|
||||
if (!isset($res[$i]->tag)) {
|
||||
continue;
|
||||
}
|
||||
$tag = strtoupper($res[$i]->tag);
|
||||
if ($tag{0} != '/') { // it's not a close tag..
|
||||
|
||||
|
||||
if (!isset($stack[$tag])) {
|
||||
$npos = $stack[$tag]['pos'] = 0;
|
||||
} else {
|
||||
$npos = ++$stack[$tag]['pos'];
|
||||
}
|
||||
$stack[$tag][$npos] = $i;
|
||||
continue;
|
||||
}
|
||||
|
||||
//echo "GOT END TAG: {$res[$i]->tag}\n";
|
||||
$tag = substr($tag,1);
|
||||
if (!isset($stack[$tag]['pos'])) {
|
||||
continue; // unmatched
|
||||
}
|
||||
|
||||
$npos = $stack[$tag]['pos'];
|
||||
if (!isset($stack[$tag][$npos])) {
|
||||
// stack is empty!!!
|
||||
continue;
|
||||
}
|
||||
// alias closer to opener..
|
||||
$this->tokens[$stack[$tag][$npos]]->close = &$this->tokens[$i];
|
||||
$stack[$tag]['pos']--;
|
||||
// take it off the stack so no one else uses it!!!
|
||||
unset($stack[$tag][$npos]);
|
||||
if ($stack[$tag]['pos'] < 0) {
|
||||
// too many closes - just ignore it..
|
||||
$stack[$tag]['pos'] = 0;
|
||||
}
|
||||
continue;
|
||||
|
||||
// new entry on stack..
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// create a dummy close for the end
|
||||
$i = $total;
|
||||
$this->tokens[$i] = new HTML_Template_Flexy_Token;
|
||||
$this->tokens[$i]->id = $total;
|
||||
$this->tokens[0]->close = &$this->tokens[$i];
|
||||
|
||||
// now is it possible to connect children...
|
||||
// now we need to GLOBALIZE!! -
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the child array for each element.
|
||||
* RECURSIVE FUNCTION!!!!
|
||||
*
|
||||
* does not move tokens, just aliases the child nodes into the token array.
|
||||
*
|
||||
* @param int id of node to add children to.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function buildChildren($id)
|
||||
{
|
||||
|
||||
|
||||
$base = &$this->tokens[$id];
|
||||
$base->children = array();
|
||||
$start = $base->id +1;
|
||||
$end = $base->close->id;
|
||||
|
||||
for ($i=$start; $i<$end; $i++) {
|
||||
//echo "{$base->id}:{$base->tag} ADDING {$i}{$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->tag}<BR>";
|
||||
//if ($base->id == 1176) {
|
||||
// echo "<PRE>";print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]);
|
||||
// }
|
||||
$base->children[] = &$this->tokens[$i];
|
||||
if (isset($this->tokens[$i]->close)) {
|
||||
|
||||
// if the close id is greater than my id - ignore it! -
|
||||
if ($this->tokens[$i]->close->id > $end) {
|
||||
continue;
|
||||
}
|
||||
$this->buildChildren($i);
|
||||
$i = $this->tokens[$i]->close->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Locates Flexy:startchildren etc. if it is used.
|
||||
* and returns the base of the tree. (eg. otherwise token[0].
|
||||
*
|
||||
* @return HTML_Template_Flexy_Token (base of tree.)
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function returnStart() {
|
||||
|
||||
foreach(array_keys($this->tokens) as $i) {
|
||||
switch(true) {
|
||||
case isset($this->tokens[$i]->ucAttributes['FLEXYSTART']):
|
||||
case isset($this->tokens[$i]->ucAttributes['FLEXY:START']):
|
||||
$this->tokens[$i]->removeAttribute('FLEXY:START');
|
||||
$this->tokens[$i]->removeAttribute('FLEXYSTART');
|
||||
return $this->tokens[$i];
|
||||
case isset($this->tokens[$i]->ucAttributes['FLEXYSTARTCHILDREN']):
|
||||
case isset($this->tokens[$i]->ucAttributes['FLEXY:STARTCHILDREN']):
|
||||
$this->tokens[0]->children = $this->tokens[$i]->children;
|
||||
return $this->tokens[0];
|
||||
}
|
||||
}
|
||||
return $this->tokens[0];
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
53
HTML/Template/Flexy/compileAll.php
Normal file
53
HTML/Template/Flexy/compileAll.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: compileAll.php,v 1.3 2003/08/01 08:50:27 alan_k Exp $
|
||||
//
|
||||
|
||||
@include 'HTML/Template/Flexy.php';
|
||||
if (!class_exists('HTML_Template_Flexy')) {
|
||||
ini_set('include_path',dirname(__FILE__).'/../../../');
|
||||
include 'HTML/Template/Flexy.php';
|
||||
}
|
||||
require_once 'PEAR.php';
|
||||
|
||||
if (!ini_get('register_argc_argv')) {
|
||||
PEAR::raiseError("\nERROR: You must turn register_argc_argv On in you php.ini file for this to work\neg.\n\nregister_argc_argv = On\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!@$_SERVER['argv'][1]) {
|
||||
PEAR::raiseError("\nERROR: compileAll.php usage:\n\nC:\php\pear\HTML\Template\Flexy\compileAll.php example.ini\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$config = parse_ini_file($_SERVER['argv'][1], true);
|
||||
|
||||
$options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
$options = $config['HTML_Template_Flexy'];
|
||||
|
||||
if (!$options) {
|
||||
PEAR::raiseError("\nERROR: could not read ini file\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
//DB_DataObject::debugLevel(5);
|
||||
$flexy= new HTML_Template_Flexy;
|
||||
$flexy->compileAll();
|
||||
?>
|
||||
36
HTML/Template/Flexy/example.ini
Normal file
36
HTML/Template/Flexy/example.ini
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
;
|
||||
; To use config file with HTML_Template_Flexy
|
||||
; $config = parse_ini_file('example.ini',TRUE)
|
||||
; $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
|
||||
; $options = $config['HTML_Template_Flexy'];
|
||||
;
|
||||
[HTML_Template_Flexy]
|
||||
|
||||
compileDir = /home/me/Projects/myapplication/compiled_templates
|
||||
; where the compiled templates go.
|
||||
|
||||
templateDir = /home/me/Projects/myapplication/templates
|
||||
; where the original templates are.
|
||||
|
||||
;templateDir = /home/me/Projects/myapplication/english;/home/me/Projects/myapplication/spanish
|
||||
; or use multiple paths..
|
||||
|
||||
forceCompile = 0
|
||||
; force compile template every time...
|
||||
|
||||
filters = Php,SimpleTags,BodyOnly
|
||||
; Order of Classes to use as filters.
|
||||
|
||||
|
||||
;url_rewrite = "/images/:/php_sharpsite/images/"
|
||||
; rewrite src and href urls from /images/ to /php_sharpsite/images/
|
||||
|
||||
;url_rewrite = "/abc/:/xyz/,/bbb/:/zzz/"
|
||||
; rewrite src and href urls from /abc/ to /xyz/ and /bbb/ to /zzz/
|
||||
; not it is only on the left of the url (not anywhere inside it)
|
||||
|
||||
|
||||
;flexyIgnore = 0
|
||||
; this turns of the transformation of HTML form elements into
|
||||
; HTML_Template_Flexy_Element's, either globally, or you
|
||||
; can use it in a constructor to turn it off per template.
|
||||
270
HTML/Template/Flexy/templates/translator.html
Normal file
270
HTML/Template/Flexy/templates/translator.html
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
|
||||
|
||||
|
||||
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="css/arms.css">
|
||||
<title>register2</title>
|
||||
</head><body flexy:startchildren="yes">
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
function xbDetectBrowser()
|
||||
{
|
||||
var oldOnError = window.onerror;
|
||||
var element = null;
|
||||
|
||||
window.onerror = null;
|
||||
|
||||
// work around bug in xpcdom Mozilla 0.9.1
|
||||
window.saveNavigator = window.navigator;
|
||||
|
||||
navigator.OS = '';
|
||||
navigator.version = parseFloat(navigator.appVersion);
|
||||
navigator.org = '';
|
||||
navigator.family = '';
|
||||
|
||||
var platform;
|
||||
if (typeof(window.navigator.platform) != 'undefined') {
|
||||
platform = window.navigator.platform.toLowerCase();
|
||||
if (platform.indexOf('win') != -1) {
|
||||
navigator.OS = 'win';
|
||||
} else if (platform.indexOf('mac') != -1) {
|
||||
navigator.OS = 'mac';
|
||||
} else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1) {
|
||||
navigator.OS = 'nix';
|
||||
}
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var ua = window.navigator.userAgent.toLowerCase();
|
||||
if (ua.indexOf('opera') != -1) {
|
||||
i = ua.indexOf('opera');
|
||||
navigator.family = 'opera';
|
||||
navigator.org = 'opera';
|
||||
navigator.version = parseFloat('0' + ua.substr(i+6), 10);
|
||||
} else if ((i = ua.indexOf('msie')) != -1) {
|
||||
navigator.org = 'microsoft';
|
||||
navigator.version = parseFloat('0' + ua.substr(i+5), 10);
|
||||
|
||||
if (navigator.version < 4) {
|
||||
navigator.family = 'ie3';
|
||||
} else {
|
||||
navigator.family = 'ie4'
|
||||
}
|
||||
} else if (ua.indexOf('gecko') != -1) {
|
||||
navigator.family = 'gecko';
|
||||
var rvStart = navigator.userAgent.indexOf('rv:') + 3;
|
||||
var rvEnd = navigator.userAgent.indexOf(')', rvStart);
|
||||
var rv = navigator.userAgent.substring(rvStart, rvEnd);
|
||||
var decIndex = rv.indexOf('.');
|
||||
if (decIndex != -1) {
|
||||
rv = rv.replace(/\./g, '')
|
||||
rv = rv.substring(0, decIndex-1) + '.' + rv.substr(decIndex)
|
||||
}
|
||||
navigator.version = parseFloat(rv);
|
||||
|
||||
if (ua.indexOf('netscape') != -1) {
|
||||
navigator.org = 'netscape';
|
||||
} else if (ua.indexOf('compuserve') != -1) {
|
||||
navigator.org = 'compuserve';
|
||||
} else {
|
||||
navigator.org = 'mozilla';
|
||||
}
|
||||
} else if ((ua.indexOf('mozilla') !=-1) &&
|
||||
(ua.indexOf('spoofer')==-1) &&
|
||||
(ua.indexOf('compatible') == -1) &&
|
||||
(ua.indexOf('opera')==-1) &&
|
||||
(ua.indexOf('webtv')==-1) &&
|
||||
(ua.indexOf('hotjava')==-1)) {
|
||||
var is_major = parseFloat(navigator.appVersion);
|
||||
|
||||
if (is_major < 4) {
|
||||
navigator.version = is_major;
|
||||
} else {
|
||||
i = ua.lastIndexOf('/')
|
||||
navigator.version = parseFloat('0' + ua.substr(i+1), 10);
|
||||
}
|
||||
navigator.org = 'netscape';
|
||||
navigator.family = 'nn' + parseInt(navigator.appVersion);
|
||||
} else if ((i = ua.indexOf('aol')) != -1 ) {
|
||||
// aol
|
||||
navigator.family = 'aol';
|
||||
navigator.org = 'aol';
|
||||
navigator.version = parseFloat('0' + ua.substr(i+4), 10);
|
||||
} else if ((i = ua.indexOf('hotjava')) != -1 ) {
|
||||
// hotjava
|
||||
navigator.family = 'hotjava';
|
||||
navigator.org = 'sun';
|
||||
navigator.version = parseFloat(navigator.appVersion);
|
||||
}
|
||||
|
||||
window.onerror = oldOnError;
|
||||
}
|
||||
|
||||
xbDetectBrowser();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getTableNodeName(Node){
|
||||
return "pane" + Node;
|
||||
}
|
||||
|
||||
|
||||
function showNode(Node){
|
||||
|
||||
switch(navigator.family){
|
||||
case 'nn4':
|
||||
// Nav 4.x code fork...
|
||||
var oTable = document.layers[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'ie4':
|
||||
// IE 4/5 code fork...
|
||||
var oTable = document.all[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'gecko':
|
||||
// Standards Compliant code fork...
|
||||
var oTable = document.getElementById(getTableNodeName(Node));
|
||||
break;
|
||||
|
||||
}
|
||||
oTable.style.display = "block";
|
||||
}
|
||||
|
||||
function hideNode(Node){
|
||||
switch(navigator.family){
|
||||
case 'nn4':
|
||||
// Nav 4.x code fork...
|
||||
var oTable = document.layers[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'ie4':
|
||||
// IE 4/5 code fork...
|
||||
var oTable = document.all[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'gecko':
|
||||
// Standards Compliant code fork...
|
||||
var oTable = document.getElementById(getTableNodeName(Node));
|
||||
break;
|
||||
|
||||
}
|
||||
oTable.style.display = "none";
|
||||
}
|
||||
function toggleNodeVisibility(Node){
|
||||
if (nodeIsVisible(Node)){
|
||||
hideNode(Node);
|
||||
}else{
|
||||
showNode(Node);
|
||||
}
|
||||
}
|
||||
function nodeIsVisible(Node){
|
||||
switch(navigator.family){
|
||||
case 'nn4':
|
||||
// Nav 4.x code fork...
|
||||
var oTable = document.layers[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'ie4':
|
||||
// IE 4/5 code fork...
|
||||
var oTable = document.all[getTableNodeName(Node)];
|
||||
break;
|
||||
|
||||
case 'gecko':
|
||||
// Standards Compliant code fork...
|
||||
var oTable = document.getElementById(getTableNodeName(Node));
|
||||
break;
|
||||
|
||||
}
|
||||
return (oTable && oTable.style.display == "block");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Select a Language To Translate To : {foreach:languages,lang}
|
||||
<a href="{appURL}?translate={lang}">{lang}</a>
|
||||
{end:}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<form method="post" flexy:ignoreonly="yes" action="{appURL}" flexy:if="translate">
|
||||
<input name="translate" value="{translate}" type="hidden" flexy:ignoreonly="yes">
|
||||
|
||||
<h1>Language : {translate}
|
||||
<input flexy:ignoreonly="yes" value="save" name="_submit" type="submit">
|
||||
or
|
||||
<input flexy:ignoreonly="yes" value="Save And Make Live" name="_apply" type="submit">
|
||||
or
|
||||
<input flexy:ignoreonly="yes" value="Save And Clear Un-used Translations" name="_clear" type="submit">
|
||||
</h1>
|
||||
|
||||
|
||||
{foreach:status,page,items}
|
||||
|
||||
<table border="0" cellspacing="2" cellpadding="2" width="600" align="center">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td bgcolor="#cccccc" colspan="2" rowspan="1" valign="top" width="600">
|
||||
<a class="property" href="javascript:toggleNodeVisibility('{page}');">+
|
||||
Page:<b>{page} (in {translate})</b></a><br>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<span id="pane{page}" style="display: none;">
|
||||
<table width="100%" border="0" cellspacing="2" cellpadding="2" width="600" align="center">
|
||||
|
||||
<tr flexy:foreach="items,item">
|
||||
|
||||
<td bgcolor="#eeeeee" vaslign="top" width="300">
|
||||
<a name="{item.md5}">
|
||||
{if:item.untranslated}
|
||||
<font color="#ff0000">{item.from}</font>
|
||||
{else:}{item.from}
|
||||
{end:}
|
||||
<br>
|
||||
<i>{item.suggest}</i><br>
|
||||
</a>
|
||||
</td>
|
||||
<td bgcolor="#ffffff" valign="top" width="300">
|
||||
<a href="#%7Bitem.md5%7D" flexy:if="item.already">See here</a>
|
||||
<span flexy:if="!item.already">
|
||||
<span flexy:if="item.short"><input
|
||||
flexy:ignoreonly="yes" value="{item.to}" name="{translate}[{item.md5}]" size="40"></span>
|
||||
<textarea cols="40" rows="5" flexy:if="!item.short" flexy:ignore="yes" name="{translate}[{item.md5}]" size="40">{item.to}</textarea>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</span>
|
||||
{end:}
|
||||
<br>
|
||||
|
||||
<br>
|
||||
<!-- InstanceEndEditable --><br>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
32
HTML/Template/tests/smarty/smartytest.php
Normal file
32
HTML/Template/tests/smarty/smartytest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/* Mini test suite */
|
||||
require_once 'HTML/Template/Flexy.php';
|
||||
//print_r($_SERVER['argv']);
|
||||
|
||||
if (!isset($_SERVER['argv'][1])) {
|
||||
$files = array(dirname(__FILE__) . '/index.tpl');
|
||||
} else {
|
||||
$files =$_SERVER['argv'];
|
||||
array_shift($files);
|
||||
}
|
||||
//print_r($files);
|
||||
foreach($files as $file) {
|
||||
$dir = dirname($file);
|
||||
$x = new HTML_Template_Flexy(array(
|
||||
'compileDir' => dirname(__FILE__) , // where do you want to write to..
|
||||
'templateDir' => $dir , // where are your templates
|
||||
'locale' => 'en', // works with gettext
|
||||
'forceCompile' => true, // only suggested for debugging
|
||||
'debug' => false, // prints a few errors
|
||||
'nonHTML' => false, // dont parse HTML tags (eg. email templates)
|
||||
'allowPHP' => false, // allow PHP in template
|
||||
'compiler' => 'SmartyConvertor', // which compiler to use.
|
||||
'compileToString' => true, // returns the converted template (rather than actually
|
||||
// converting to PHP.
|
||||
'filters' => array(), // used by regex compiler..
|
||||
'numberFormat' => ",2,'.',','", // default number format = eg. 1,200.00 ( {xxx:n} )
|
||||
'flexyIgnore' => 0 // turn on/off the tag to element code
|
||||
));
|
||||
|
||||
echo $x->compile(basename($file));
|
||||
}
|
||||
11
HTML/Template/tests/templates/blocks.html
Normal file
11
HTML/Template/tests/templates/blocks.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<span id="block1">
|
||||
This is block 1
|
||||
</span>
|
||||
|
||||
<span id="block2">
|
||||
This is block 2
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
|
||||
122
HTML/Template/tests/templates/bug_2959.html
Normal file
122
HTML/Template/tests/templates/bug_2959.html
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
-------------------------
|
||||
Dear Administrator,
|
||||
|
||||
-- Automatically Generated Email from XXXXXXXXXX --
|
||||
{if:hasmessage}
|
||||
|
||||
*NOTE*: {message:h}.
|
||||
{end:}
|
||||
|
||||
O R D E R A W A I T I N G A U T H O R I S A T I O N
|
||||
_________________________________________________________________
|
||||
|
||||
ORDER:
|
||||
|
||||
ID: {order.h}
|
||||
|
||||
*Edit*: http://{host}/admin/sales/orders/edit?id={order}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
CUSTOMER DETAILS:
|
||||
|
||||
Name: {customer.firstname:h} {customer.lastname:h}
|
||||
|
||||
Email: mailto:{customer.email:h}
|
||||
|
||||
*Edit*: http://{host}/admin/sales/customers/edit?id={customer.id}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
SHIPPING TO:
|
||||
|
||||
*{deliveryname:h}*
|
||||
{deliveryaddress:h}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
XXXXXXXXXXXXXXXXXXX:
|
||||
|
||||
*{post.transactionstatus:h}*
|
||||
|
||||
{if:post.dubious}
|
||||
*WARNING*! - This may not be a bona fide order! - *WARNING*!
|
||||
|
||||
*Reason*: {post.dubiousreason:h}
|
||||
|
||||
/Contact tech support/ before proceeding with this order!
|
||||
|
||||
{end:}
|
||||
Total (currency?): {post.total:h}
|
||||
|
||||
Client ID (XXXXXXXX): {post.clientid:h}
|
||||
|
||||
Order ID: {post.oid:h}
|
||||
|
||||
Charge type: {post.chargetype:h}
|
||||
|
||||
Timestamp (from XXXXXXXX): {post.datetime:h}
|
||||
|
||||
VbV Status: {post.ecistatus:h}
|
||||
|
||||
https://XXXXX.XXXXXXXX.XXXXXX.com/XXXXX/XXXXXXX/XXXXXx
|
||||
_________________________________________________________________
|
||||
|
||||
{foreach:orderlines,i,o}
|
||||
{if:i}
|
||||
|
||||
- - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
{end:}
|
||||
*PRODUCT*:{o.productname:h}
|
||||
|
||||
({o.producttypename:h})
|
||||
|
||||
*Edit*: http://{host}/admin/catalog/products/edit?id={o.product:u}
|
||||
|
||||
FABRIC: {o.fabricname:h}
|
||||
|
||||
SIZE: {o.sizename:h}
|
||||
|
||||
Eurostop: {o.altid:h}
|
||||
|
||||
QUANTITY: {o.quantity:h}
|
||||
|
||||
Price ea: {o.eachprice:h}
|
||||
|
||||
Tax each: {o.eachtax:h}
|
||||
|
||||
Sub-total: {o.totalinctax:h}
|
||||
{if:o.isgift}
|
||||
|
||||
*GIFT MESSAGE* FOR THIS ITEM:
|
||||
{o.giftmessage}{end:}{end:}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
Item total (ex tax): {totals.itemstotal:h}
|
||||
|
||||
Item taxes: {totals.itemstax:h}
|
||||
|
||||
Shipping:
|
||||
{totals.shippingcharges:h}
|
||||
|
||||
Tax on shipping: {totals.shippingtax:h}
|
||||
|
||||
*GRAND TOTAL*: {totals.grandtotal:h}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
{totals.itemsdiscountinfo:h}
|
||||
|
||||
{totals.itemstaxinfo:h}
|
||||
|
||||
{totals.shippinginfo:h}
|
||||
|
||||
{totals.shippingtaxinfo:h}
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
blah blah
|
||||
|
||||
--------------------------
|
||||
46
HTML/Template/tests/templates/conditions.html
Normal file
46
HTML/Template/tests/templates/conditions.html
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
|
||||
<H2>Conditions</H2>
|
||||
<p>a condition {if:condition} hello {else:} world {end:}</p>
|
||||
<p>a negative condition {if:!condition} hello {else:} world {end:}</p>
|
||||
<p>a conditional method {if:condition()} hello {else:} world {end:}</p>
|
||||
<p>a negative conditional method {if:!condition()} hello {else:} world {end:}</p>
|
||||
|
||||
|
||||
<span flexy:if="test">test</span>
|
||||
<span flexy:if="test()">test</span>
|
||||
<span flexy:if="test(#aaa bbb#,ccc,#asdfasdf asdf #)">test</span>
|
||||
|
||||
|
||||
|
||||
<H2>Notices and errros</H2>
|
||||
|
||||
|
||||
<table flexy:if="notices" class="tablenotice" width="70%" align="center">
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="tdheadernotice" height="20" width="526">Thanks</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tdbodynotice" height="33">
|
||||
<p flexy:if="notices[ok]">Submitted data is ok</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table flexy:if="errors" class="tablewarning" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="tdheaderwarning" height="20" width="526">Sorry</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tdbodywarning">
|
||||
|
||||
<li flexy:if="errors[lastname]">Please fill in your last name</li>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
8
HTML/Template/tests/templates/error_foreach.html
Normal file
8
HTML/Template/tests/templates/error_foreach.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
|
||||
<!-- Bugs: 739
|
||||
<td flexy:foreach="xxxx">xxx</td>
|
||||
{foreach:xxxx} {end:}
|
||||
-->
|
||||
|
||||
40
HTML/Template/tests/templates/flexy_tojavascript.html
Normal file
40
HTML/Template/tests/templates/flexy_tojavascript.html
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
|
||||
|
||||
<flexy:toJavascript
|
||||
flexy:prefix="test_abc_"
|
||||
abcg="xyz"
|
||||
abcd="xyz"
|
||||
srcXxx="xyz"
|
||||
>
|
||||
<script type="text/javascript">
|
||||
|
||||
var test_abc_abcg = '123';
|
||||
var test_abc_abcd = '123';
|
||||
var test_abc_srcXxx = '123';
|
||||
|
||||
</script>
|
||||
|
||||
</flexy:toJavascript>
|
||||
|
||||
|
||||
|
||||
|
||||
<flexy:toJavascript abcg="xyz">
|
||||
<script type="text/javascript">
|
||||
var xyz = '123';
|
||||
</script>
|
||||
</flexy:toJavascript>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
<p>Example of flexy:toJavascript with default values.</p>
|
||||
</body></html>
|
||||
107
HTML/Template/tests/templates/forms.html
Normal file
107
HTML/Template/tests/templates/forms.html
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
|
||||
<h2>Form Not Parsed</h2>
|
||||
|
||||
<form name="test" flexy:ignore>
|
||||
<input name=test123>
|
||||
<select name="aaa">
|
||||
<option>bb</option>
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<h2>Parsed</h2>
|
||||
|
||||
|
||||
<form name="test">
|
||||
Input<input name=test123>
|
||||
Checkbox <input name=test123a id=test123ab type='checkbox' checked>
|
||||
Hidden <input name=test123ab type='hidden' value='123'>
|
||||
<textarea name="fred">some text</textarea>
|
||||
<select name="aaa1">
|
||||
<option>aa</option>
|
||||
<option selected>bb</option>
|
||||
<option>cc</option>
|
||||
</select>
|
||||
<select name="aaa2" flexy:ignore>
|
||||
<option>aa</option>
|
||||
<option selected>bb</option>
|
||||
<option>cc</option>
|
||||
|
||||
</select>
|
||||
<select name="aaa3">
|
||||
<option>aa</option>
|
||||
<option selected>bb</option>
|
||||
<option>cc</option>
|
||||
|
||||
</select>
|
||||
|
||||
<!-- bug 5267 -->
|
||||
<input id="opt_1" type="checkbox" name="opt[]" value="1" />
|
||||
<label for="opt_1">option 1</label>
|
||||
<input id="opt_2" type="checkbox" name="opt[]" value="2" />
|
||||
<label for="opt_3">option 2</label>
|
||||
<input id="opt_3" type="checkbox" name="opt[]" value="3" />
|
||||
<label for="opt_3">option 3</label>
|
||||
|
||||
|
||||
|
||||
|
||||
<select name="List">
|
||||
<option value="2000">2000</option>
|
||||
<option value="2001">2001</option>
|
||||
<option value="2002">2002</option>
|
||||
</select>
|
||||
<input type="submit" name="_submit[4]" value="Next >>">
|
||||
<input type="submit" name="_submit[5]" value="Next >>">
|
||||
|
||||
<input type="file" name="testupload">
|
||||
|
||||
#bug bug6058
|
||||
|
||||
<br /><input type="radio" name="payment_1_type" id="1" value="cc" />
|
||||
Credit card
|
||||
<br /><input type="radio" name="payment_1_type" id="2" value="cq" />
|
||||
Cheque
|
||||
|
||||
<br /><input type="radio" name="payment_2_type" id="3" value="cc" />
|
||||
Credit card
|
||||
<br /><input type="radio" name="payment_2_type" id="4" value="cq" />
|
||||
Cheque
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
<img name="picture" id="picture" flexy:dynamic>
|
||||
|
||||
<h2>Bug 1120:</h2>
|
||||
<form action="test">
|
||||
<input name="testing" value="test">
|
||||
<input type="submit" value="x" name="_submit[2]">
|
||||
</form>
|
||||
|
||||
<form action="{someurl}">
|
||||
<input name="testing2" value="{somevalue}">
|
||||
<input type="submit" name="_submit[1]">
|
||||
</form>
|
||||
|
||||
<H2> Bug 1275 XHTML output </H2>
|
||||
<input type="checkbox" name="testingxhtml" flexy:xhtml="true" checked>
|
||||
<select name="xhtmllisttest" flexy:xhtml="true">
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<H2> Bug 4005 Checkboxes </H2>
|
||||
<input type="checkbox" name="testingcheckbox" value="123">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<form name="test_mix" action="{someurl}">
|
||||
<input name="testing5" value="{somevalue}">
|
||||
<input type="submit" name="_submit[3]">
|
||||
</form>
|
||||
17
HTML/Template/tests/templates/function.html
Normal file
17
HTML/Template/tests/templates/function.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
<H1>Example of function block definitions</H1>
|
||||
|
||||
|
||||
<table flexy:if="false">
|
||||
<tr><td>
|
||||
<flexy:function name="test1">this is the contents of test1</flexy:function>
|
||||
</td></tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr><td>
|
||||
<flexy:function call="test1"></flexy:function>
|
||||
<flexy:function call="{a_value}"></flexy:function>
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
26
HTML/Template/tests/templates/globals.html
Normal file
26
HTML/Template/tests/templates/globals.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
<H2>GLOBALS:</H2>
|
||||
{_SESSION[hello]} <BR>
|
||||
{_GET[fred]} <BR>
|
||||
{GLOBALS[abc]} <BR>
|
||||
|
||||
|
||||
<H2>Privates:</H2>
|
||||
{_somemethod()} <BR>
|
||||
{_somevar} <BR>
|
||||
|
||||
|
||||
|
||||
<H2>Global methods </H2>
|
||||
|
||||
{GLOBALS.date(#d/m/y#)} <BR>
|
||||
|
||||
{if:GLOBALS.is_array(test)} <BR>
|
||||
{end:} <BR>
|
||||
<BR>
|
||||
|
||||
{foreach:atest,k,v} <BR>
|
||||
{if:GLOBALS.is_array(v)} <BR>
|
||||
{end:} <BR>
|
||||
{end:} <BR>
|
||||
|
||||
22
HTML/Template/tests/templates/image_view.html
Normal file
22
HTML/Template/tests/templates/image_view.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
|
||||
|
||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>image_view.html</title></head>
|
||||
|
||||
<body flexy:startchildren="yes">
|
||||
|
||||
<table cellpadding="2" cellspacing="2" border="0" bgcolor="black" style="text-align: left; width: 100%;">
|
||||
|
||||
<tbody>
|
||||
<tr flexy:foreach="images,row">
|
||||
<td flexy:foreach="row,col" align="center" valign="middle"
|
||||
background="{rootURL}/FlexyWiki/templates/negative.jpg"><a
|
||||
href="%7Bcol.link%7D"><img
|
||||
border="0" height="{col.info[1]}" width="{col.info[0]}" src="%7Bcol.url%7D"></a><br>
|
||||
<font color="white">[{col.name}] {col.size}Mb</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</body></html>
|
||||
13
HTML/Template/tests/templates/include.html
Normal file
13
HTML/Template/tests/templates/include.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<body>
|
||||
|
||||
the variable is {foo}
|
||||
|
||||
<table>
|
||||
<tr flexy:foreach="range,key,value">
|
||||
<flexy:include src="include_block.html" />
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
78
HTML/Template/tests/templates/javascript.html
Normal file
78
HTML/Template/tests/templates/javascript.html
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<script src='somefile/{js_file}'></script>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<script language="javascript">
|
||||
|
||||
// some sample javascript that might cause problemss
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
//<!--
|
||||
|
||||
function CheckDuplicates2 (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-->
|
||||
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
// and now just commented out stuff.. that may cause problems
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
-->
|
||||
<script type="application/x-javascript" src="js/common.js"></script>
|
||||
<script type="application/x-javascript" src="../searchjs.php"></script>
|
||||
<script type="application/x-javascript" src="js/catctrl.js"></script>
|
||||
<script type="application/x-javascript">
|
||||
function productAddApply() {
|
||||
req = new phpRequest(URI_CONTROL + "/New/product");
|
||||
req.add("product_category", get_value("listProdCat"));
|
||||
req.add("item_category", get_value("listItemCat"));
|
||||
req.add("item_subcategory", get_value("listItemSubCat"));
|
||||
req.add("supplier_id", get_value("listSupplier"));
|
||||
req.add("supplier_model_numb", get_value("txtSupModelNo"));
|
||||
req.add("article", get_value("txtArtDescr"));
|
||||
req.add("material", get_value("txtMaterial"));
|
||||
req.add("color", get_value("txtColor"));
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
59
HTML/Template/tests/templates/looping.html
Normal file
59
HTML/Template/tests/templates/looping.html
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
|
||||
<h2>Looping</h2>
|
||||
|
||||
|
||||
<p>a loop {foreach:loop,a} {a} {end:}</p>
|
||||
<p>a loop with 2 vars {foreach:loop,a,b}
|
||||
{a} ,
|
||||
{b}
|
||||
{end:}</p>
|
||||
|
||||
Bug #84
|
||||
{foreach:list,i}
|
||||
{method(i)}
|
||||
{end:}
|
||||
|
||||
{foreach:list,i,j}
|
||||
{i}:{j}
|
||||
{end:}
|
||||
|
||||
<table>
|
||||
<tr flexy:foreach="xyz,abcd,def">
|
||||
<td>{abcd}, {test(def)}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
<tr flexy:foreach="loop,a,b">
|
||||
<td>{a}</td>
|
||||
<td>{b}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a" or the tr using a highlight class.</h2>
|
||||
<table width="100%" border="0">
|
||||
<tr flexy:foreach="loop,a" class="{a.hightlight}">
|
||||
<td>a is</td>
|
||||
<td flexy:if="a.showtext">{a.text}</td>
|
||||
<td flexy:if="!a.showtext">{a.price:n}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
<tr flexy:foreach="loop,a,b">
|
||||
<td flexy:foreach="b,c,d">{d}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Looping in CDATA</h2>
|
||||
Dont forget that php strips line breaks!
|
||||
<![CDATA[
|
||||
{foreach:list,i,j}
|
||||
{i}:{j}
|
||||
|
||||
{end:}
|
||||
]]>
|
||||
69
HTML/Template/tests/templates/methods.html
Normal file
69
HTML/Template/tests/templates/methods.html
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
<h2>Methods</H2>
|
||||
<p>Calling a method {a.helloWorld()}</p>
|
||||
<p>or {includeBody():h}</P>
|
||||
<img src="%7bgetImageDir()%7D/someimage.jpg">
|
||||
<img src="%7bgetImageDir():h%7D/someimage.jpg">
|
||||
<img src="%7bgetImageDir():u%7D/someimage.jpg">
|
||||
|
||||
<img src="%7bgetImageDir()}/someimage.jpg">
|
||||
<img src="{getImageDir()%7D/someimage.jpg">
|
||||
|
||||
|
||||
|
||||
<span class="{t.getBgnd(valueArr[isConfigurable])}"></span>
|
||||
|
||||
|
||||
|
||||
<h2>Full Method testing</h2>
|
||||
|
||||
{abc(abc,def,hij)}
|
||||
{abc(abc,#def#,#hij#)}
|
||||
|
||||
{abc(abc,def,#hij#)}
|
||||
{abc(#abc#,def,hij)}
|
||||
|
||||
{abc(abc,def,hij):h}
|
||||
{abc(abc,#def#,#hij#):h}
|
||||
{abc(abc,def,#hij#):h}
|
||||
{abc(#abc#,def,hij):h}
|
||||
|
||||
|
||||
{abc(abc,def,hij):u}
|
||||
{abc(abc,#def#,#hij#):u}
|
||||
{abc(abc,def,#hij#):u}
|
||||
{abc(#abc#,def,hij):u}
|
||||
|
||||
{abc(123,def,hij)}
|
||||
{abc(abc,#123#,123):u}
|
||||
{abc(abc,def,123)}
|
||||
{abc(#abc#,123,hij):u}
|
||||
|
||||
|
||||
<h2>Real life method testing </h2>
|
||||
Invoice number: {t.getelem(t.invoice,#number#)} Place:
|
||||
{t.getelem(t.invoice,#place#)} Date: {t.getelem(t.invoice,#date#)} Payment:
|
||||
{t.getelem(t.invoice,#payment#)} Payment date:
|
||||
{t.getelem(t.invoice,#payment_date#)} Seller: Name 1:
|
||||
{t.getelem(t.seller,#name1#)} Name 2: {t.getelem(t.seller,#name2#)} NIP:
|
||||
{t.getelem(t.seller,#nip#)} Street: {t.getelem(t.seller,#street#)} City:
|
||||
{t.getelem(t.seller,#code#)} {t.getelem(t.seller,#city#)} Buyer: Name 1:
|
||||
{t.getelem(t.buyer,#name1#)} Name 2: {t.getelem(t.buyer,#name2#)} NIP:
|
||||
{t.getelem(t.buyer,#nip#)} Street: {t.getelem(t.buyer,#street#)} City:
|
||||
{t.getelem(t.buyer,#code#)} {t.getelem(t.buyer,#city#)}
|
||||
# Name {if:t.show_pkwiu} PKWIU{end:} Count Netto VAT Brutto
|
||||
{foreach:t.positions,position} {t.getelem(position,#nr#)}
|
||||
{t.getelem(position,#name#)} {if:t.show_pkwiu}
|
||||
{t.getelem(position,#pkwiu#)}{end:} {t.getelem(position,#count#)}
|
||||
{t.getelem(position,#netto#)} {t.getelem(position,#vat#)}
|
||||
{t.getelem(position,#brutto#)}
|
||||
{end:} {if:t.edit_positions} # Name {if:t.show_pkwiu} PKWIU{end:} Count
|
||||
{if:t.getelem(position,#netto_mode#)} Netto{else:} {end:} VAT
|
||||
{if:t.getelem(position,#netto_mode#)} {else:} Brutto{end:}
|
||||
{foreach:t.edit_positions,k,position} {t.getelem(position,#nr#)}
|
||||
{if:t.show_pkwiu} {end:} {if:t.getelem(position,#netto_mode#)} {else:}
|
||||
{end:} {if:t.getelem(position,#netto_mode#)} {else:} {end:}
|
||||
{end:} {end:} #
|
||||
{foreach:t.sum,sum} {t.getelem(sum,#nr#)} {t.getelem(sum,#netto#)}
|
||||
{t.getelem(sum,#vat#)} {t.getelem(sum,#brutto#)}
|
||||
{end:}
|
||||
68
HTML/Template/tests/templates/namespaces.html
Normal file
68
HTML/Template/tests/templates/namespaces.html
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="images/css/test.css" type="text/css"?>
|
||||
|
||||
<window id="wndUserResults"
|
||||
title="User Search Results"
|
||||
persist="screenX screenY width height"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<tree id="userSearchResults" flex="1" height="300" enableColumnDrag="true" ondblclick="parent.parent.userEditPopup();">
|
||||
<treecols>
|
||||
<treecol flex="2" id="trcName" label="Name" primary="true" persist="width ordinal hidden"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol flex="1" id="trcGroupName" label="Group Name" persist="width ordinal hidden"/>
|
||||
</treecols>
|
||||
<treechildren>
|
||||
<treeitem flexy:foreach="sresult,id,data">
|
||||
<treerow>
|
||||
<treecell label="{data.name}"/>
|
||||
<treecell label="{data.group_name}"/>
|
||||
<treecell label="{data.user_id}"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</tree>
|
||||
<html:form name="test">
|
||||
<html:input name="test2">
|
||||
<html:table>
|
||||
<html:tr>
|
||||
<html:td>
|
||||
<label style="text-align: left;" control="listItemSubCat" value="Item Subcategory"/>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
</html:table>
|
||||
</html:form>
|
||||
<html:select name="atest">
|
||||
<html:option flexy:foreach="categories,data" value="{data.value}"
|
||||
onselect="parent.onSelect_ProdCat();">{data.name}</html:option>
|
||||
</html:select>
|
||||
<!-- example of how to make the above work correctly.. -->
|
||||
<html:select name="atest" flexy:ignore="yes">
|
||||
<html:option flexy:foreach="categories,data" value="{data.value}"
|
||||
onselect="parent.onSelect_ProdCat();">{data.name}</html:option>
|
||||
</html:select>
|
||||
|
||||
<!-- test toElement -->
|
||||
<menulist id="supplier_id">
|
||||
<menupopup>
|
||||
<menuitem id="itemSubCatAll" label="-- Select --" value="0"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
<!-- test using flexy stuff -->
|
||||
<menulist id="supplier_id2">
|
||||
<menupopup>
|
||||
<menuitem flexy:foreach="x,y" id="itemSubCatAll" label="{y.name}" value="{y.value}"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
<!-- test args on menupopup -->
|
||||
<menulist id="product_category">
|
||||
<menupopup onpopuphiding="cTree.categorySelect(this.parentNode.value,1);">
|
||||
<menuitem id="prodCatAll" label="-- All --" value="0" />
|
||||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
</window>
|
||||
14
HTML/Template/tests/templates/plugin_modifiers.html
Normal file
14
HTML/Template/tests/templates/plugin_modifiers.html
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<H1>Testing Plugin Modifiers</H1>
|
||||
|
||||
|
||||
{datetest:dateformat}
|
||||
|
||||
{numbertest:numberformat}
|
||||
|
||||
|
||||
Bug #3946 - inside raw!
|
||||
|
||||
<input type="checkbox" name="useTextarea3" flexy:ignore="yes"
|
||||
flexy:raw="{person.useTextarea():checked}">
|
||||
|
||||
|
||||
12
HTML/Template/tests/templates/raw_php.html
Normal file
12
HTML/Template/tests/templates/raw_php.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
<? for($i=0;$i<10;$i++) { ?>
|
||||
number: <?=$i?>
|
||||
<?php } ?>
|
||||
|
||||
<script language="php">
|
||||
|
||||
for($i=0;$i<10;$i++) {
|
||||
|
||||
echo "hello world\n";
|
||||
}
|
||||
</script>
|
||||
25
HTML/Template/tests/templates/raw_text.html
Normal file
25
HTML/Template/tests/templates/raw_text.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<h2>Example Template for HTML_Template_Flexy</h2>
|
||||
|
||||
a full string example ~!@#$%^&*() |": ?\][;'/.,=-_+ ~` abcd....
|
||||
asfasfdas
|
||||
|
||||
|
||||
|
||||
<h2>Bugs: 809 Comments:</h2>
|
||||
|
||||
|
||||
<!--- this is a comment with alot of stuff.. --# ---->
|
||||
|
||||
<!-- this is a comment with alot of stuff.. --# -- -->
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
31
HTML/Template/tests/templates/style.html
Normal file
31
HTML/Template/tests/templates/style.html
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="print"
|
||||
|
||||
href="{ROOT_CSS}/print.css">
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="screen"
|
||||
|
||||
href="{ROOT_CSS}/compatible.css">
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
|
||||
<!--
|
||||
|
||||
@import url({ROOT_CSS}/main.css);
|
||||
|
||||
.tdbodywarningCopy {
|
||||
background-color: #eecccc;
|
||||
FONT-FAMILY: arial, geneva, helvetica, sans-serif;
|
||||
font-size : 10px;
|
||||
COLOR: #000000;
|
||||
padding: 0px;
|
||||
border: 0px dashed #000000;
|
||||
}
|
||||
|
||||
-->
|
||||
|
||||
</style>
|
||||
39
HTML/Template/tests/templates/variables.html
Normal file
39
HTML/Template/tests/templates/variables.html
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<p>Example Template for HTML_Template_Flexy</p>
|
||||
|
||||
<h2>Variables</H2>
|
||||
|
||||
<p>Standard variables
|
||||
{hello}
|
||||
{world:h}
|
||||
{test:u}
|
||||
{object.var}
|
||||
{array[0]}
|
||||
{array[entry]}
|
||||
{multi[array][0]}
|
||||
{object.var[array][1]}
|
||||
{object.var[array][1]:r}
|
||||
{object.var[array][1]:h}
|
||||
{object.var[array][-1]:h}
|
||||
{object[array].with[objects]}
|
||||
Long string with NL2BR + HTMLSPECIALCHARS
|
||||
{longstring:b}
|
||||
|
||||
Everything: {t:r}
|
||||
an Object: {object:r}
|
||||
|
||||
|
||||
<img src="%7bgetImageDir%7D/someimage.jpg">
|
||||
<img src="%7bgetImageDir:h%7D/someimage.jpg">
|
||||
<img src="%7bgetImageDir:u%7D/someimage.jpg">
|
||||
|
||||
<img src="%7bgetImageDir}/someimage.jpg">
|
||||
<img src="{getImageDir%7D/someimage.jpg">
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
39
HTML/Template/tests/test_blocks.html.phpt
Normal file
39
HTML/Template/tests/test_blocks.html.phpt
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
Template Test: blocks.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('blocks.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling blocks.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: blocks.html===
|
||||
<span id="block1">
|
||||
This is block 1
|
||||
</span>
|
||||
|
||||
<span id="block2">
|
||||
This is block 2
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
===With data file: blocks.html===
|
||||
<span id="block1">
|
||||
This is block 1
|
||||
</span>
|
||||
|
||||
<span id="block2">
|
||||
This is block 2
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
197
HTML/Template/tests/test_bug_2959.html.phpt
Normal file
197
HTML/Template/tests/test_bug_2959.html.phpt
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
--TEST--
|
||||
Template Test: bug_2959.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('bug_2959.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling bug_2959.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: bug_2959.html===
|
||||
-------------------------
|
||||
Dear Administrator,
|
||||
|
||||
-- Automatically Generated Email from XXXXXXXXXX --
|
||||
<?php if ($t->hasmessage) {?>
|
||||
|
||||
*NOTE*: <?php echo $t->message;?>.
|
||||
<?php }?>
|
||||
|
||||
O R D E R A W A I T I N G A U T H O R I S A T I O N
|
||||
_________________________________________________________________
|
||||
|
||||
ORDER:
|
||||
|
||||
ID: <?php echo htmlspecialchars($t->order->h);?>
|
||||
|
||||
*Edit*: http://<?php echo htmlspecialchars($t->host);?>/admin/sales/orders/edit?id=<?php echo htmlspecialchars($t->order);?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
CUSTOMER DETAILS:
|
||||
|
||||
Name: <?php echo $t->customer->firstname;?> <?php echo $t->customer->lastname;?>
|
||||
|
||||
Email: mailto:<?php echo $t->customer->email;?>
|
||||
|
||||
*Edit*: http://<?php echo htmlspecialchars($t->host);?>/admin/sales/customers/edit?id=<?php echo htmlspecialchars($t->customer->id);?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
SHIPPING TO:
|
||||
|
||||
*<?php echo $t->deliveryname;?>*
|
||||
<?php echo $t->deliveryaddress;?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
XXXXXXXXXXXXXXXXXXX:
|
||||
|
||||
*<?php echo $t->post->transactionstatus;?>*
|
||||
|
||||
<?php if ($t->post->dubious) {?>
|
||||
*WARNING*! - This may not be a bona fide order! - *WARNING*!
|
||||
|
||||
*Reason*: <?php echo $t->post->dubiousreason;?>
|
||||
|
||||
/Contact tech support/ before proceeding with this order!
|
||||
|
||||
<?php }?>
|
||||
Total (currency?): <?php echo $t->post->total;?>
|
||||
|
||||
Client ID (XXXXXXXX): <?php echo $t->post->clientid;?>
|
||||
|
||||
Order ID: <?php echo $t->post->oid;?>
|
||||
|
||||
Charge type: <?php echo $t->post->chargetype;?>
|
||||
|
||||
Timestamp (from XXXXXXXX): <?php echo $t->post->datetime;?>
|
||||
|
||||
VbV Status: <?php echo $t->post->ecistatus;?>
|
||||
|
||||
https://XXXXX.XXXXXXXX.XXXXXX.com/XXXXX/XXXXXXX/XXXXXx
|
||||
_________________________________________________________________
|
||||
|
||||
<?php if ($this->options['strict'] || (is_array($t->orderlines) || is_object($t->orderlines))) foreach($t->orderlines as $i => $o) {?>
|
||||
<?php if ($i) {?>
|
||||
|
||||
- - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
<?php }?>
|
||||
*PRODUCT*:<?php echo $o->productname;?>
|
||||
|
||||
(<?php echo $o->producttypename;?>)
|
||||
|
||||
*Edit*: http://<?php echo htmlspecialchars($t->host);?>/admin/catalog/products/edit?id=<?php echo urlencode($o->product);?>
|
||||
|
||||
FABRIC: <?php echo $o->fabricname;?>
|
||||
|
||||
SIZE: <?php echo $o->sizename;?>
|
||||
|
||||
Eurostop: <?php echo $o->altid;?>
|
||||
|
||||
QUANTITY: <?php echo $o->quantity;?>
|
||||
|
||||
Price ea: <?php echo $o->eachprice;?>
|
||||
|
||||
Tax each: <?php echo $o->eachtax;?>
|
||||
|
||||
Sub-total: <?php echo $o->totalinctax;?>
|
||||
<?php if ($o->isgift) {?>
|
||||
|
||||
*GIFT MESSAGE* FOR THIS ITEM:
|
||||
<?php echo htmlspecialchars($o->giftmessage);?><?php }?><?php }?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
Item total (ex tax): <?php echo $t->totals->itemstotal;?>
|
||||
|
||||
Item taxes: <?php echo $t->totals->itemstax;?>
|
||||
|
||||
Shipping:
|
||||
<?php echo $t->totals->shippingcharges;?>
|
||||
|
||||
Tax on shipping: <?php echo $t->totals->shippingtax;?>
|
||||
|
||||
*GRAND TOTAL*: <?php echo $t->totals->grandtotal;?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
<?php echo $t->totals->itemsdiscountinfo;?>
|
||||
|
||||
<?php echo $t->totals->itemstaxinfo;?>
|
||||
|
||||
<?php echo $t->totals->shippinginfo;?>
|
||||
|
||||
<?php echo $t->totals->shippingtaxinfo;?>
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
blah blah
|
||||
|
||||
--------------------------
|
||||
|
||||
===With data file: bug_2959.html===
|
||||
-------------------------
|
||||
Dear Administrator,
|
||||
|
||||
-- Automatically Generated Email from XXXXXXXXXX --
|
||||
|
||||
O R D E R A W A I T I N G A U T H O R I S A T I O N
|
||||
_________________________________________________________________
|
||||
|
||||
ORDER:
|
||||
|
||||
ID:
|
||||
*Edit*: http:///admin/sales/orders/edit?id=
|
||||
_________________________________________________________________
|
||||
|
||||
CUSTOMER DETAILS:
|
||||
|
||||
Name:
|
||||
Email: mailto:
|
||||
*Edit*: http:///admin/sales/customers/edit?id=
|
||||
_________________________________________________________________
|
||||
|
||||
SHIPPING TO:
|
||||
|
||||
**
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
XXXXXXXXXXXXXXXXXXX:
|
||||
|
||||
**
|
||||
|
||||
Total (currency?):
|
||||
Client ID (XXXXXXXX):
|
||||
Order ID:
|
||||
Charge type:
|
||||
Timestamp (from XXXXXXXX):
|
||||
VbV Status:
|
||||
https://XXXXX.XXXXXXXX.XXXXXX.com/XXXXX/XXXXXXX/XXXXXx
|
||||
_________________________________________________________________
|
||||
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
Item total (ex tax):
|
||||
Item taxes:
|
||||
Shipping:
|
||||
|
||||
Tax on shipping:
|
||||
*GRAND TOTAL*:
|
||||
_________________________________________________________________
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_________________________________________________________________
|
||||
|
||||
blah blah
|
||||
|
||||
--------------------------
|
||||
75
HTML/Template/tests/test_conditions.html.phpt
Normal file
75
HTML/Template/tests/test_conditions.html.phpt
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
--TEST--
|
||||
Template Test: conditions.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('conditions.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling conditions.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: conditions.html===
|
||||
|
||||
|
||||
<H2>Conditions</H2>
|
||||
<p>a condition <?php if ($t->condition) {?> hello <?php } else {?> world <?php }?></p>
|
||||
<p>a negative condition <?php if (!$t->condition) {?> hello <?php } else {?> world <?php }?></p>
|
||||
<p>a conditional method <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'condition'))) if ($t->condition()) { ?> hello <?php } else {?> world <?php }?></p>
|
||||
<p>a negative conditional method <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'condition'))) if (!$t->condition()) { ?> hello <?php } else {?> world <?php }?></p>
|
||||
|
||||
|
||||
<?php if ($t->test) {?><span>test</span><?php }?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'test'))) if ($t->test()) { ?><span>test</span><?php }?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'test'))) if ($t->test("aaa bbb",$t->ccc,"asdfasdf asdf ")) { ?><span>test</span><?php }?>
|
||||
|
||||
|
||||
|
||||
<H2>Notices and errros</H2>
|
||||
|
||||
|
||||
<?php if ($t->notices) {?><table class="tablenotice" width="70%" align="center">
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="tdheadernotice" height="20" width="526">Thanks</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tdbodynotice" height="33">
|
||||
<?php if ($t->notices['ok']) {?><p>Submitted data is ok</p><?php }?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><?php }?>
|
||||
|
||||
<?php if ($t->errors) {?><table class="tablewarning" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="tdheaderwarning" height="20" width="526">Sorry</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tdbodywarning">
|
||||
|
||||
<?php if ($t->errors['lastname']) {?><li>Please fill in your last name</li><?php }?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><?php }?>
|
||||
|
||||
|
||||
===With data file: conditions.html===
|
||||
|
||||
|
||||
<H2>Conditions</H2>
|
||||
<p>a condition world </p>
|
||||
<p>a negative condition hello </p>
|
||||
<p>a conditional method </p>
|
||||
<p>a negative conditional method </p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<H2>Notices and errros</H2>
|
||||
31
HTML/Template/tests/test_error_foreach.html.phpt
Normal file
31
HTML/Template/tests/test_error_foreach.html.phpt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
--TEST--
|
||||
Template Test: error_foreach.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('error_foreach.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling error_foreach.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: error_foreach.html===
|
||||
|
||||
|
||||
|
||||
<!-- Bugs: 739
|
||||
<td flexy:foreach="xxxx">xxx</td>
|
||||
{foreach:xxxx} {end:}
|
||||
-->
|
||||
|
||||
|
||||
|
||||
===With data file: error_foreach.html===
|
||||
|
||||
|
||||
|
||||
<!-- Bugs: 739
|
||||
<td flexy:foreach="xxxx">xxx</td>
|
||||
{foreach:xxxx} {end:}
|
||||
-->
|
||||
73
HTML/Template/tests/test_flexy_tojavascript.html.phpt
Normal file
73
HTML/Template/tests/test_flexy_tojavascript.html.phpt
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
--TEST--
|
||||
Template Test: flexy_tojavascript.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('flexy_tojavascript.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling flexy_tojavascript.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: flexy_tojavascript.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
|
||||
|
||||
<?php require_once 'HTML/Javascript/Convert.php';?>
|
||||
<script type='text/javascript'>
|
||||
<?php $__tmp = HTML_Javascript_Convert::convertVar($t->xyz,'test_abc_abcg',true);echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;?>
|
||||
<?php $__tmp = HTML_Javascript_Convert::convertVar($t->xyz,'test_abc_abcd',true);echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;?>
|
||||
<?php $__tmp = HTML_Javascript_Convert::convertVar($t->xyz,'test_abc_srcXxx',true);echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;?>
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php require_once 'HTML/Javascript/Convert.php';?>
|
||||
<script type='text/javascript'>
|
||||
<?php $__tmp = HTML_Javascript_Convert::convertVar($t->xyz,'abcg',true);echo (is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;?>
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
<p>Example of flexy:toJavascript with default values.</p>
|
||||
</body></html>
|
||||
|
||||
===With data file: flexy_tojavascript.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
test_abc_abcg = null;
|
||||
test_abc_abcd = null;
|
||||
test_abc_srcXxx = null;
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
abcg = null;
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
<p>Example of flexy:toJavascript with default values.</p>
|
||||
</body></html>
|
||||
1040
HTML/Template/tests/test_forms.html.phpt
Normal file
1040
HTML/Template/tests/test_forms.html.phpt
Normal file
File diff suppressed because it is too large
Load diff
43
HTML/Template/tests/test_function.html.phpt
Normal file
43
HTML/Template/tests/test_function.html.phpt
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Template Test: function.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('function.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling function.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: function.html===
|
||||
<?php
|
||||
function _html_template_flexy_compiler_flexy_flexy_test1($t,$this) {
|
||||
?>this is the contents of test1<?php
|
||||
}
|
||||
?>
|
||||
<H1>Example of function block definitions</H1>
|
||||
|
||||
|
||||
<?php if ($t->false) {?><table>
|
||||
<tr><td>
|
||||
|
||||
</td></tr>
|
||||
</table><?php }?>
|
||||
<table>
|
||||
<tr><td>
|
||||
<?php if (function_exists('_html_template_flexy_compiler_flexy_flexy_test1')) _html_template_flexy_compiler_flexy_flexy_test1($t,$this);?>
|
||||
<?php if (function_exists('_html_template_flexy_compiler_flexy_flexy_'.$t->a_value)) call_user_func_array('_html_template_flexy_compiler_flexy_flexy_'.$t->a_value,array($t,$this));?>
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
===With data file: function.html===
|
||||
<H1>Example of function block definitions</H1>
|
||||
|
||||
|
||||
<table>
|
||||
<tr><td>
|
||||
this is the contents of test1 </td></tr>
|
||||
</table>
|
||||
12
HTML/Template/tests/test_globals.html.phpt
Normal file
12
HTML/Template/tests/test_globals.html.phpt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
--TEST--
|
||||
Template Test: globals.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('globals.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling globals.html===
|
||||
|
||||
===Compile failure==
|
||||
[pear_error: message="HTML_Template_Flexy fatal error:HTML_Template_Flexy::Attempt to access private variable: on line %d of %s, Use options[privates] to allow this." code=-1 mode=return level=notice prefix="" info=""]
|
||||
37
HTML/Template/tests/test_image_view.html.phpt
Normal file
37
HTML/Template/tests/test_image_view.html.phpt
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
--TEST--
|
||||
Template Test: image_view.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('image_view.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling image_view.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: image_view.html===
|
||||
|
||||
|
||||
<table cellpadding="2" cellspacing="2" border="0" bgcolor="black" style="text-align: left; width: 100%;">
|
||||
|
||||
<tbody>
|
||||
<?php if ($this->options['strict'] || (is_array($t->images) || is_object($t->images))) foreach($t->images as $row) {?><tr>
|
||||
<?php if ($this->options['strict'] || (is_array($row) || is_object($row))) foreach($row as $col) {?><td align="center" valign="middle" background="<?php echo htmlspecialchars($t->rootURL);?>/FlexyWiki/templates/negative.jpg"><a href="<?php echo htmlspecialchars($col->link);?>"><img border="0" height="<?php echo htmlspecialchars($col->info[1]);?>" width="<?php echo htmlspecialchars($col->info[0]);?>" src="<?php echo htmlspecialchars($col->url);?>"></a><br>
|
||||
<font color="white">[<?php echo htmlspecialchars($col->name);?>] <?php echo htmlspecialchars($col->size);?>Mb</font>
|
||||
</td><?php }?>
|
||||
</tr><?php }?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
===With data file: image_view.html===
|
||||
|
||||
|
||||
<table cellpadding="2" cellspacing="2" border="0" bgcolor="black" style="text-align: left; width: 100%;">
|
||||
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
107
HTML/Template/tests/test_include.html.phpt
Normal file
107
HTML/Template/tests/test_include.html.phpt
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
--TEST--
|
||||
Template Test: include.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
require_once 'HTML/Template/Flexy/Factory.php';
|
||||
|
||||
|
||||
compilefile('include.html',
|
||||
array(
|
||||
'range' => range('a', 'z'),
|
||||
'foo' => 'bar',
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling include.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: include.html===
|
||||
<html>
|
||||
<body>
|
||||
|
||||
the variable is <?php echo htmlspecialchars($t->foo);?>
|
||||
|
||||
<table>
|
||||
<?php if ($this->options['strict'] || (is_array($t->range) || is_object($t->range))) foreach($t->range as $key => $value) {?><tr>
|
||||
<?php
|
||||
$x = new HTML_Template_Flexy($this->options);
|
||||
$x->compile('include_block.html');
|
||||
$_t = function_exists('clone') ? clone($t) : $t;
|
||||
foreach(get_defined_vars() as $k=>$v) {
|
||||
if ($k != 't') { $_t->$k = $v; }
|
||||
}
|
||||
$x->outputObject($_t, $this->elements);
|
||||
?>
|
||||
</tr><?php }?>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
===With data file: include.html===
|
||||
<html>
|
||||
<body>
|
||||
|
||||
the variable is bar
|
||||
<table>
|
||||
<tr>
|
||||
<td width="60">0</td>
|
||||
<td><a href="#foo">a</a></td> </tr><tr>
|
||||
<td width="60">1</td>
|
||||
<td><a href="#foo">b</a></td> </tr><tr>
|
||||
<td width="60">2</td>
|
||||
<td><a href="#foo">c</a></td> </tr><tr>
|
||||
<td width="60">3</td>
|
||||
<td><a href="#foo">d</a></td> </tr><tr>
|
||||
<td width="60">4</td>
|
||||
<td><a href="#foo">e</a></td> </tr><tr>
|
||||
<td width="60">5</td>
|
||||
<td><a href="#foo">f</a></td> </tr><tr>
|
||||
<td width="60">6</td>
|
||||
<td><a href="#foo">g</a></td> </tr><tr>
|
||||
<td width="60">7</td>
|
||||
<td><a href="#foo">h</a></td> </tr><tr>
|
||||
<td width="60">8</td>
|
||||
<td><a href="#foo">i</a></td> </tr><tr>
|
||||
<td width="60">9</td>
|
||||
<td><a href="#foo">j</a></td> </tr><tr>
|
||||
<td width="60">10</td>
|
||||
<td><a href="#foo">k</a></td> </tr><tr>
|
||||
<td width="60">11</td>
|
||||
<td><a href="#foo">l</a></td> </tr><tr>
|
||||
<td width="60">12</td>
|
||||
<td><a href="#foo">m</a></td> </tr><tr>
|
||||
<td width="60">13</td>
|
||||
<td><a href="#foo">n</a></td> </tr><tr>
|
||||
<td width="60">14</td>
|
||||
<td><a href="#foo">o</a></td> </tr><tr>
|
||||
<td width="60">15</td>
|
||||
<td><a href="#foo">p</a></td> </tr><tr>
|
||||
<td width="60">16</td>
|
||||
<td><a href="#foo">q</a></td> </tr><tr>
|
||||
<td width="60">17</td>
|
||||
<td><a href="#foo">r</a></td> </tr><tr>
|
||||
<td width="60">18</td>
|
||||
<td><a href="#foo">s</a></td> </tr><tr>
|
||||
<td width="60">19</td>
|
||||
<td><a href="#foo">t</a></td> </tr><tr>
|
||||
<td width="60">20</td>
|
||||
<td><a href="#foo">u</a></td> </tr><tr>
|
||||
<td width="60">21</td>
|
||||
<td><a href="#foo">v</a></td> </tr><tr>
|
||||
<td width="60">22</td>
|
||||
<td><a href="#foo">w</a></td> </tr><tr>
|
||||
<td width="60">23</td>
|
||||
<td><a href="#foo">x</a></td> </tr><tr>
|
||||
<td width="60">24</td>
|
||||
<td><a href="#foo">y</a></td> </tr><tr>
|
||||
<td width="60">25</td>
|
||||
<td><a href="#foo">z</a></td> </tr> </table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
171
HTML/Template/tests/test_javascript.html.phpt
Normal file
171
HTML/Template/tests/test_javascript.html.phpt
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
--TEST--
|
||||
Template Test: javascript.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('javascript.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling javascript.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: javascript.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<script src='somefile/<?php echo htmlspecialchars($t->js_file);?>'></script>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<script language="javascript">
|
||||
|
||||
// some sample javascript that might cause problemss
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
//<!--
|
||||
|
||||
function CheckDuplicates2 (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-->
|
||||
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
// and now just commented out stuff.. that may cause problems
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
-->
|
||||
<script type="application/x-javascript" src="js/common.js"></script>
|
||||
<script type="application/x-javascript" src="../searchjs.php"></script>
|
||||
<script type="application/x-javascript" src="js/catctrl.js"></script>
|
||||
<script type="application/x-javascript">
|
||||
function productAddApply() {
|
||||
req = new phpRequest(URI_CONTROL + "/New/product");
|
||||
req.add("product_category", get_value("listProdCat"));
|
||||
req.add("item_category", get_value("listItemCat"));
|
||||
req.add("item_subcategory", get_value("listItemSubCat"));
|
||||
req.add("supplier_id", get_value("listSupplier"));
|
||||
req.add("supplier_model_numb", get_value("txtSupModelNo"));
|
||||
req.add("article", get_value("txtArtDescr"));
|
||||
req.add("material", get_value("txtMaterial"));
|
||||
req.add("color", get_value("txtColor"));
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
===With data file: javascript.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<script src='somefile/'></script>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<script language="javascript">
|
||||
|
||||
// some sample javascript that might cause problemss
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
//<!--
|
||||
|
||||
function CheckDuplicates2 (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-->
|
||||
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
// and now just commented out stuff.. that may cause problems
|
||||
|
||||
function CheckDuplicates (AddListContainer, RemoveListContainer) {
|
||||
var AddList = eval('document.main_form.'+AddListContainer);
|
||||
var RemoveList = eval('document.main_form.'+RemoveListContainer);
|
||||
var TempAddList = AddList.value;
|
||||
var TempRemoveList = RemoveList.value;
|
||||
if (TempAddList>''&&TempRemoveList>'') {
|
||||
TempAddList = TempAddList.substring(0,TempAddList.length-1);
|
||||
}
|
||||
}
|
||||
|
||||
-->
|
||||
<script type="application/x-javascript" src="js/common.js"></script>
|
||||
<script type="application/x-javascript" src="../searchjs.php"></script>
|
||||
<script type="application/x-javascript" src="js/catctrl.js"></script>
|
||||
<script type="application/x-javascript">
|
||||
function productAddApply() {
|
||||
req = new phpRequest(URI_CONTROL + "/New/product");
|
||||
req.add("product_category", get_value("listProdCat"));
|
||||
req.add("item_category", get_value("listItemCat"));
|
||||
req.add("item_subcategory", get_value("listItemSubCat"));
|
||||
req.add("supplier_id", get_value("listSupplier"));
|
||||
req.add("supplier_model_numb", get_value("txtSupModelNo"));
|
||||
req.add("article", get_value("txtArtDescr"));
|
||||
req.add("material", get_value("txtMaterial"));
|
||||
req.add("color", get_value("txtColor"));
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
109
HTML/Template/tests/test_looping.html.phpt
Normal file
109
HTML/Template/tests/test_looping.html.phpt
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
--TEST--
|
||||
Template Test: looping.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('looping.html',array('list'=>array(1,2,3,4)));
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling looping.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: looping.html===
|
||||
|
||||
|
||||
<h2>Looping</h2>
|
||||
|
||||
|
||||
<p>a loop <?php if ($this->options['strict'] || (is_array($t->loop) || is_object($t->loop))) foreach($t->loop as $a) {?> <?php echo htmlspecialchars($a);?> <?php }?></p>
|
||||
<p>a loop with 2 vars <?php if ($this->options['strict'] || (is_array($t->loop) || is_object($t->loop))) foreach($t->loop as $a => $b) {?>
|
||||
<?php echo htmlspecialchars($a);?> ,
|
||||
<?php echo htmlspecialchars($b);?>
|
||||
<?php }?></p>
|
||||
|
||||
Bug #84
|
||||
<?php if ($this->options['strict'] || (is_array($t->list) || is_object($t->list))) foreach($t->list as $i) {?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'method'))) echo htmlspecialchars($t->method($i));?>
|
||||
<?php }?>
|
||||
|
||||
<?php if ($this->options['strict'] || (is_array($t->list) || is_object($t->list))) foreach($t->list as $i => $j) {?>
|
||||
<?php echo htmlspecialchars($i);?>:<?php echo htmlspecialchars($j);?>
|
||||
<?php }?>
|
||||
|
||||
<table>
|
||||
<?php if ($this->options['strict'] || (is_array($t->xyz) || is_object($t->xyz))) foreach($t->xyz as $abcd => $def) {?><tr>
|
||||
<td><?php echo htmlspecialchars($abcd);?>, <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'test'))) echo htmlspecialchars($t->test($def));?></td>
|
||||
</tr><?php }?>
|
||||
</table>
|
||||
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
<?php if ($this->options['strict'] || (is_array($t->loop) || is_object($t->loop))) foreach($t->loop as $a => $b) {?><tr>
|
||||
<td><?php echo htmlspecialchars($a);?></td>
|
||||
<td><?php echo htmlspecialchars($b);?></td>
|
||||
</tr><?php }?>
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a" or the tr using a highlight class.</h2>
|
||||
<table width="100%" border="0">
|
||||
<?php if ($this->options['strict'] || (is_array($t->loop) || is_object($t->loop))) foreach($t->loop as $a) {?><tr class="<?php echo htmlspecialchars($a->hightlight);?>">
|
||||
<td>a is</td>
|
||||
<?php if ($a->showtext) {?><td><?php echo htmlspecialchars($a->text);?></td><?php }?>
|
||||
<?php if (!$a->showtext) {?><td><?php echo number_format($a->price,2,'.',',');?></td><?php }?>
|
||||
</tr><?php }?>
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
<?php if ($this->options['strict'] || (is_array($t->loop) || is_object($t->loop))) foreach($t->loop as $a => $b) {?><tr>
|
||||
<?php if ($this->options['strict'] || (is_array($b) || is_object($b))) foreach($b as $c => $d) {?><td><?php echo htmlspecialchars($d);?></td><?php }?>
|
||||
</tr><?php }?>
|
||||
</table>
|
||||
|
||||
<h2>Looping in CDATA</h2>
|
||||
Dont forget that php strips line breaks!
|
||||
<![CDATA[
|
||||
<?php if ($this->options['strict'] || (is_array($t->list) || is_object($t->list))) foreach($t->list as $i => $j) {?>
|
||||
<?php echo htmlspecialchars($i);?>:<?php echo htmlspecialchars($j);?>
|
||||
|
||||
<?php }?>
|
||||
]]>
|
||||
|
||||
===With data file: looping.html===
|
||||
|
||||
|
||||
<h2>Looping</h2>
|
||||
|
||||
|
||||
<p>a loop </p>
|
||||
<p>a loop with 2 vars </p>
|
||||
|
||||
Bug #84
|
||||
|
||||
0:1 1:2 2:3 3:4
|
||||
<table>
|
||||
</table>
|
||||
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a" or the tr using a highlight class.</h2>
|
||||
<table width="100%" border="0">
|
||||
</table>
|
||||
|
||||
<h2>HTML tags example using foreach="loop,a,b" or the tr</h2>
|
||||
<table width="100%" border="0">
|
||||
</table>
|
||||
|
||||
<h2>Looping in CDATA</h2>
|
||||
Dont forget that php strips line breaks!
|
||||
<![CDATA[
|
||||
0:1
|
||||
1:2
|
||||
2:3
|
||||
3:4
|
||||
]]>
|
||||
123
HTML/Template/tests/test_methods.html.phpt
Normal file
123
HTML/Template/tests/test_methods.html.phpt
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
--TEST--
|
||||
Template Test: methods.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('methods.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling methods.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: methods.html===
|
||||
|
||||
<h2>Methods</H2>
|
||||
<p>Calling a method <?php if ($this->options['strict'] || (isset($t->a) && method_exists($t->a,'helloWorld'))) echo htmlspecialchars($t->a->helloWorld());?></p>
|
||||
<p>or <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'includeBody'))) echo $t->includeBody();?></P>
|
||||
<img src="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getImageDir'))) echo htmlspecialchars($t->getImageDir());?>/someimage.jpg">
|
||||
<img src="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getImageDir'))) echo $t->getImageDir();?>/someimage.jpg">
|
||||
<img src="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getImageDir'))) echo urlencode($t->getImageDir());?>/someimage.jpg">
|
||||
|
||||
<img src="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getImageDir'))) echo htmlspecialchars($t->getImageDir());?>/someimage.jpg">
|
||||
<img src="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getImageDir'))) echo htmlspecialchars($t->getImageDir());?>/someimage.jpg">
|
||||
|
||||
|
||||
|
||||
<span class="<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getBgnd'))) echo htmlspecialchars($t->getBgnd($t->valueArr['isConfigurable']));?>"></span>
|
||||
|
||||
|
||||
|
||||
<h2>Full Method testing</h2>
|
||||
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc($t->abc,$t->def,$t->hij));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc($t->abc,"def","hij"));?>
|
||||
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc($t->abc,$t->def,"hij"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc("abc",$t->def,$t->hij));?>
|
||||
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo $t->abc($t->abc,$t->def,$t->hij);?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo $t->abc($t->abc,"def","hij");?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo $t->abc($t->abc,$t->def,"hij");?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo $t->abc("abc",$t->def,$t->hij);?>
|
||||
|
||||
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc($t->abc,$t->def,$t->hij));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc($t->abc,"def","hij"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc($t->abc,$t->def,"hij"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc("abc",$t->def,$t->hij));?>
|
||||
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc(123,$t->def,$t->hij));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc($t->abc,123,123));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo htmlspecialchars($t->abc($t->abc,$t->def,123));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'abc'))) echo urlencode($t->abc("abc",123,$t->hij));?>
|
||||
|
||||
|
||||
<h2>Real life method testing </h2>
|
||||
Invoice number: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->invoice,"number"));?> Place:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->invoice,"place"));?> Date: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->invoice,"date"));?> Payment:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->invoice,"payment"));?> Payment date:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->invoice,"payment_date"));?> Seller: Name 1:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"name1"));?> Name 2: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"name2"));?> NIP:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"nip"));?> Street: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"street"));?> City:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"code"));?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->seller,"city"));?> Buyer: Name 1:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"name1"));?> Name 2: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"name2"));?> NIP:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"nip"));?> Street: <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"street"));?> City:
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"code"));?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($t->buyer,"city"));?>
|
||||
# Name <?php if ($t->show_pkwiu) {?> PKWIU<?php }?> Count Netto VAT Brutto
|
||||
<?php if ($this->options['strict'] || (is_array($t->positions) || is_object($t->positions))) foreach($t->positions as $position) {?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"nr"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"name"));?> <?php if ($t->show_pkwiu) {?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"pkwiu"));?><?php }?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"count"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"netto"));?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"vat"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"brutto"));?>
|
||||
<?php }?> <?php if ($t->edit_positions) {?> # Name <?php if ($t->show_pkwiu) {?> PKWIU<?php }?> Count
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) if ($t->getelem($t->position,"netto_mode")) { ?> Netto<?php } else {?> <?php }?> VAT
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) if ($t->getelem($t->position,"netto_mode")) { ?> <?php } else {?> Brutto<?php }?>
|
||||
<?php if ($this->options['strict'] || (is_array($t->edit_positions) || is_object($t->edit_positions))) foreach($t->edit_positions as $k => $position) {?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($position,"nr"));?>
|
||||
<?php if ($t->show_pkwiu) {?> <?php }?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) if ($t->getelem($position,"netto_mode")) { ?> <?php } else {?>
|
||||
<?php }?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) if ($t->getelem($position,"netto_mode")) { ?> <?php } else {?> <?php }?>
|
||||
<?php }?> <?php }?> #
|
||||
<?php if ($this->options['strict'] || (is_array($t->sum) || is_object($t->sum))) foreach($t->sum as $sum) {?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($sum,"nr"));?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($sum,"netto"));?>
|
||||
<?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($sum,"vat"));?> <?php if ($this->options['strict'] || (isset($t) && method_exists($t,'getelem'))) echo htmlspecialchars($t->getelem($sum,"brutto"));?>
|
||||
<?php }?>
|
||||
|
||||
|
||||
===With data file: methods.html===
|
||||
|
||||
<h2>Methods</H2>
|
||||
<p>Calling a method </p>
|
||||
<p>or </P>
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
|
||||
|
||||
|
||||
<span class=""></span>
|
||||
|
||||
|
||||
|
||||
<h2>Full Method testing</h2>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2>Real life method testing </h2>
|
||||
Invoice number: Place:
|
||||
Date: Payment:
|
||||
Payment date:
|
||||
Seller: Name 1:
|
||||
Name 2: NIP:
|
||||
Street: City:
|
||||
Buyer: Name 1:
|
||||
Name 2: NIP:
|
||||
Street: City:
|
||||
# Name Count Netto VAT Brutto
|
||||
#
|
||||
121
HTML/Template/tests/test_namespaces.html.phpt
Normal file
121
HTML/Template/tests/test_namespaces.html.phpt
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
--TEST--
|
||||
Template Test: namespaces.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('namespaces.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling namespaces.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: namespaces.html===
|
||||
<?php echo "<"; ?>?xml version="1.0" ?>
|
||||
<?php echo "<"; ?>?xml-stylesheet href="chrome://global/skin/" type="text/css" ?>
|
||||
<?php echo "<"; ?>?xml-stylesheet href="/myproject/images/css/test.css" type="text/css" ?>
|
||||
|
||||
<window id="wndUserResults" title="User Search Results" persist="screenX screenY width height" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<tree id="userSearchResults" flex="1" height="300" enableColumnDrag="true" ondblclick="parent.parent.userEditPopup();">
|
||||
<treecols>
|
||||
<treecol flex="2" id="trcName" label="Name" primary="true" persist="width ordinal hidden" />
|
||||
<splitter class="tree-splitter" />
|
||||
<treecol flex="1" id="trcGroupName" label="Group Name" persist="width ordinal hidden" />
|
||||
</treecols>
|
||||
<treechildren>
|
||||
<?php if ($this->options['strict'] || (is_array($t->sresult) || is_object($t->sresult))) foreach($t->sresult as $id => $data) {?><treeitem>
|
||||
<treerow>
|
||||
<treecell label="<?php echo htmlspecialchars($data->name);?>" />
|
||||
<treecell label="<?php echo htmlspecialchars($data->group_name);?>" />
|
||||
<treecell label="<?php echo htmlspecialchars($data->user_id);?>" />
|
||||
</treerow>
|
||||
</treeitem><?php }?>
|
||||
</treechildren>
|
||||
</tree>
|
||||
<?php echo $this->elements['test']->toHtmlnoClose();?>
|
||||
<?php echo $this->elements['test2']->toHtml();?>
|
||||
<html:table>
|
||||
<html:tr>
|
||||
<html:td>
|
||||
<label style="text-align: left;" control="listItemSubCat" value="Item Subcategory" />
|
||||
</html:td>
|
||||
</html:tr>
|
||||
</html:table>
|
||||
</html:form>
|
||||
<?php $_attributes_used = array();
|
||||
echo $this->elements['atest']->toHtml();
|
||||
if (isset($_attributes_used)) { foreach($_attributes_used as $_a) {
|
||||
unset($this->elements['atest']->attributes[$_a]);
|
||||
}}
|
||||
?>
|
||||
<!-- example of how to make the above work correctly.. -->
|
||||
<html:select name="atest">
|
||||
<?php if ($this->options['strict'] || (is_array($t->categories) || is_object($t->categories))) foreach($t->categories as $data) {?><html:option value="<?php echo htmlspecialchars($data->value);?>" onselect="parent.onSelect_ProdCat();"><?php echo htmlspecialchars($data->name);?></html:option><?php }?>
|
||||
</html:select>
|
||||
|
||||
<!-- test toElement -->
|
||||
<?php echo $this->elements['supplier_id']->toHtml();?>
|
||||
|
||||
<!-- test using flexy stuff -->
|
||||
<menulist id="supplier_id2">
|
||||
<menupopup>
|
||||
<?php if ($this->options['strict'] || (is_array($t->x) || is_object($t->x))) foreach($t->x as $y) {?><menuitem id="itemSubCatAll" label="<?php echo htmlspecialchars($y->name);?>" value="<?php echo htmlspecialchars($y->value);?>" /><?php }?>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
<!-- test args on menupopup -->
|
||||
<?php echo $this->elements['product_category']->toHtml();?>
|
||||
|
||||
</window>
|
||||
|
||||
|
||||
===With data file: namespaces.html===
|
||||
<?xml version="1.0" ?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css" ?>
|
||||
<?xml-stylesheet href="/myproject/images/css/test.css" type="text/css" ?>
|
||||
|
||||
<window id="wndUserResults" title="User Search Results" persist="screenX screenY width height" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<tree id="userSearchResults" flex="1" height="300" enableColumnDrag="true" ondblclick="parent.parent.userEditPopup();">
|
||||
<treecols>
|
||||
<treecol flex="2" id="trcName" label="Name" primary="true" persist="width ordinal hidden" />
|
||||
<splitter class="tree-splitter" />
|
||||
<treecol flex="1" id="trcGroupName" label="Group Name" persist="width ordinal hidden" />
|
||||
</treecols>
|
||||
<treechildren>
|
||||
</treechildren>
|
||||
</tree>
|
||||
<html:form name="test"> <html:input name="test2"> <html:table>
|
||||
<html:tr>
|
||||
<html:td>
|
||||
<label style="text-align: left;" control="listItemSubCat" value="Item Subcategory" />
|
||||
</html:td>
|
||||
</html:tr>
|
||||
</html:table>
|
||||
</html:form>
|
||||
<html:select name="atest">
|
||||
<html:option onselect="parent.onSelect_ProdCat();">data.name</html:option>
|
||||
</html:select> <!-- example of how to make the above work correctly.. -->
|
||||
<html:select name="atest">
|
||||
</html:select>
|
||||
|
||||
<!-- test toElement -->
|
||||
<menulist id="supplier_id">
|
||||
<menupopup>
|
||||
<menuitem id="itemSubCatAll" label="-- Select --" value="0" />
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<!-- test using flexy stuff -->
|
||||
<menulist id="supplier_id2">
|
||||
<menupopup>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
<!-- test args on menupopup -->
|
||||
<menulist id="product_category">
|
||||
<menupopup onpopuphiding="cTree.categorySelect(this.parentNode.value,1);">
|
||||
<menuitem id="prodCatAll" label="-- All --" value="0" />
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</window>
|
||||
56
HTML/Template/tests/test_plugin_modifiers.html.phpt
Normal file
56
HTML/Template/tests/test_plugin_modifiers.html.phpt
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
--TEST--
|
||||
Template Test: plugin_modifiers.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('plugin_modifiers.html',
|
||||
array(
|
||||
'numbertest' => 10000.123,
|
||||
'datetest' => '2004-01-12'
|
||||
),
|
||||
array('plugins'=>array('Savant'))
|
||||
);
|
||||
|
||||
compilefile('flexy_raw_with_element.html',
|
||||
array( ),
|
||||
array( )
|
||||
|
||||
);
|
||||
--EXPECTF--
|
||||
<<<<<<< test_plugin_modifiers.html.phpt
|
||||
=======
|
||||
===Compiling plugin_modifiers.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: plugin_modifiers.html===
|
||||
<H1>Testing Plugin Modifiers</H1>
|
||||
|
||||
|
||||
<?php echo $this->plugin("dateformat",$t->datetest);?>
|
||||
|
||||
<?php echo $this->plugin("numberformat",$t->numbertest);?>
|
||||
|
||||
|
||||
Bug #3946 - inside raw!
|
||||
|
||||
<input type="checkbox" name="useTextarea3" <?php if ($this->options['strict'] || (isset($t->person) && method_exists($t->person,'useTextarea'))) echo $this->plugin("checked",$t->person->useTextarea());?>>
|
||||
|
||||
|
||||
|
||||
===With data file: plugin_modifiers.html===
|
||||
<H1>Testing Plugin Modifiers</H1>
|
||||
|
||||
|
||||
12 Jan 2004
|
||||
10,000.12
|
||||
|
||||
Bug #3946 - inside raw!
|
||||
|
||||
<input type="checkbox" name="useTextarea3" >
|
||||
|
||||
|
||||
|
||||
===Compiling flexy_raw_with_element.html===
|
||||
|
||||
Error:/var/svn_live/pear/HTML_Template_Flexy/tests/templates/flexy_raw_with_element.html on Line 5 in Tag <INPUT>:<BR>Flexy:raw can only be used with flexy:ignore, to prevent conversion of html elements to flexy elements>>>>>>> 1.3
|
||||
68
HTML/Template/tests/test_raw_php.html.phpt
Normal file
68
HTML/Template/tests/test_raw_php.html.phpt
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
--TEST--
|
||||
Template Test: raw_php.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('raw_php.html');
|
||||
compilefile('raw_php.html',array(), array('allowPHP'=>true));
|
||||
compilefile('raw_php.html',array(), array('allowPHP'=>'delete'));
|
||||
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling raw_php.html===
|
||||
|
||||
===Compile failure==
|
||||
[pear_error: message="HTML_Template_Flexy fatal error:PHP code found in script (Token)" code=-1 mode=return level=notice prefix="" info=""]
|
||||
|
||||
|
||||
===Compiling raw_php.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: raw_php.html===
|
||||
|
||||
<? for($i=0;$i<10;$i++) { ?>
|
||||
number: <?=$i?>
|
||||
<?php } ?>
|
||||
|
||||
<script language="php">
|
||||
|
||||
for($i=0;$i<10;$i++) {
|
||||
|
||||
echo "hello world\n";
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
===With data file: raw_php.html===
|
||||
|
||||
number: 0number: 1number: 2number: 3number: 4number: 5number: 6number: 7number: 8number: 9
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
hello world
|
||||
|
||||
|
||||
===Compiling raw_php.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: raw_php.html===
|
||||
|
||||
|
||||
number:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
===With data file: raw_php.html===
|
||||
|
||||
|
||||
number:
|
||||
64
HTML/Template/tests/test_raw_text.html.phpt
Normal file
64
HTML/Template/tests/test_raw_text.html.phpt
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
--TEST--
|
||||
Template Test: raw_text.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('raw_text.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling raw_text.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: raw_text.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<h2>Example Template for HTML_Template_Flexy</h2>
|
||||
|
||||
a full string example ~!@#$%^&*() |": ?\][;'/.,=-_+ ~` abcd....
|
||||
asfasfdas
|
||||
|
||||
|
||||
|
||||
<h2>Bugs: 809 Comments:</h2>
|
||||
|
||||
|
||||
<!--- this is a comment with alot of stuff.. --# ---->
|
||||
|
||||
<!-- this is a comment with alot of stuff.. --# -- -->
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
===With data file: raw_text.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<h2>Example Template for HTML_Template_Flexy</h2>
|
||||
|
||||
a full string example ~!@#$%^&*() |": ?\][;'/.,=-_+ ~` abcd....
|
||||
asfasfdas
|
||||
|
||||
|
||||
|
||||
<h2>Bugs: 809 Comments:</h2>
|
||||
|
||||
|
||||
<!--- this is a comment with alot of stuff.. --# ---->
|
||||
|
||||
<!-- this is a comment with alot of stuff.. --# -- -->
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
69
HTML/Template/tests/test_style.html.phpt
Normal file
69
HTML/Template/tests/test_style.html.phpt
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
--TEST--
|
||||
Template Test: style.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('style.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling style.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: style.html===
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="print" href="<?php echo htmlspecialchars($t->ROOT_CSS);?>/print.css">
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo htmlspecialchars($t->ROOT_CSS);?>/compatible.css">
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
|
||||
<!--
|
||||
|
||||
@import url(<?php echo htmlspecialchars($t->ROOT_CSS);?>/main.css);
|
||||
|
||||
.tdbodywarningCopy {
|
||||
background-color: #eecccc;
|
||||
FONT-FAMILY: arial, geneva, helvetica, sans-serif;
|
||||
font-size : 10px;
|
||||
COLOR: #000000;
|
||||
padding: 0px;
|
||||
border: 0px dashed #000000;
|
||||
}
|
||||
|
||||
-->
|
||||
|
||||
</style>
|
||||
|
||||
===With data file: style.html===
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="print" href="/print.css">
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="/compatible.css">
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
|
||||
<!--
|
||||
|
||||
@import url(/main.css);
|
||||
|
||||
.tdbodywarningCopy {
|
||||
background-color: #eecccc;
|
||||
FONT-FAMILY: arial, geneva, helvetica, sans-serif;
|
||||
font-size : 10px;
|
||||
COLOR: #000000;
|
||||
padding: 0px;
|
||||
border: 0px dashed #000000;
|
||||
}
|
||||
|
||||
-->
|
||||
|
||||
</style>
|
||||
83
HTML/Template/tests/test_variables.html.phpt
Normal file
83
HTML/Template/tests/test_variables.html.phpt
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
--TEST--
|
||||
Template Test: variables.html
|
||||
--FILE--
|
||||
<?php
|
||||
require_once 'testsuite.php';
|
||||
compilefile('variables.html');
|
||||
|
||||
--EXPECTF--
|
||||
===Compiling variables.html===
|
||||
|
||||
|
||||
|
||||
===Compiled file: variables.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<p>Example Template for HTML_Template_Flexy</p>
|
||||
|
||||
<h2>Variables</H2>
|
||||
|
||||
<p>Standard variables
|
||||
<?php echo htmlspecialchars($t->hello);?>
|
||||
<?php echo $t->world;?>
|
||||
<?php echo urlencode($t->test);?>
|
||||
<?php echo htmlspecialchars($t->object->var);?>
|
||||
<?php echo htmlspecialchars($t->array[0]);?>
|
||||
<?php echo htmlspecialchars($t->array['entry']);?>
|
||||
<?php echo htmlspecialchars($t->multi['array'][0]);?>
|
||||
<?php echo htmlspecialchars($t->object->var['array'][1]);?>
|
||||
<?php echo '<pre>'; echo htmlspecialchars(print_r($t->object->var['array'][1],true)); echo '</pre>';;?>
|
||||
<?php echo $t->object->var['array'][1];?>
|
||||
<?php echo $t->object->var['array'][-1];?>
|
||||
<?php echo htmlspecialchars($t->object['array']->with['objects']);?>
|
||||
Long string with NL2BR + HTMLSPECIALCHARS
|
||||
<?php echo nl2br(htmlspecialchars($t->longstring));?>
|
||||
|
||||
Everything: <?php echo '<pre>'; echo htmlspecialchars(print_r($t,true)); echo '</pre>';;?>
|
||||
an Object: <?php echo '<pre>'; echo htmlspecialchars(print_r($t->object,true)); echo '</pre>';;?>
|
||||
|
||||
|
||||
<img src="<?php echo htmlspecialchars($t->getImageDir);?>/someimage.jpg">
|
||||
<img src="<?php echo $t->getImageDir;?>/someimage.jpg">
|
||||
<img src="<?php echo urlencode($t->getImageDir);?>/someimage.jpg">
|
||||
|
||||
<img src="<?php echo htmlspecialchars($t->getImageDir);?>/someimage.jpg">
|
||||
<img src="<?php echo htmlspecialchars($t->getImageDir);?>/someimage.jpg">
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
===With data file: variables.html===
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled Document</title>
|
||||
|
||||
<body>
|
||||
<p>Example Template for HTML_Template_Flexy</p>
|
||||
|
||||
<h2>Variables</H2>
|
||||
|
||||
<p>Standard variables
|
||||
|
||||
<pre></pre>Long string with NL2BR + HTMLSPECIALCHARS
|
||||
|
||||
Everything: <pre>stdClass Object
|
||||
(
|
||||
)
|
||||
</pre>an Object: <pre></pre>
|
||||
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
|
||||
<img src="/someimage.jpg">
|
||||
<img src="/someimage.jpg">
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
13
INSTALL
Normal file
13
INSTALL
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Configuration nécessaire:
|
||||
* serveur web avec support PHP
|
||||
|
||||
Installation:
|
||||
* copier les fichiers dans le répertoire souhaité
|
||||
* éditez le fichier configuration.php
|
||||
* donnez les droits en écritures pour tous au répertoire "cache/"
|
||||
|
||||
Utilisation:
|
||||
* Chaque strip est représenté par un fichier SVG et son export en PNG.
|
||||
* Pour un bon fonctionnement (affichage du titre, date, commentaires, etc.) chaque fichier SVG doit contenir des métadonnées au format RDF (dans Inkscape, Fichier > métadonnées).
|
||||
* Déposez ces deux fichiers dans le répertoire "strips/"
|
||||
|
||||
223
PEAR/Autoloader.php
Normal file
223
PEAR/Autoloader.php
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
<?php
|
||||
/**
|
||||
* Class auto-loader
|
||||
*
|
||||
* PHP versions 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Autoloader.php,v 1.13 2006/01/06 04:47:36 cellog Exp $
|
||||
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
|
||||
* @since File available since Release 0.1
|
||||
* @deprecated File deprecated in Release 1.4.0a1
|
||||
*/
|
||||
|
||||
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
|
||||
if (!extension_loaded("overload")) {
|
||||
// die hard without ext/overload
|
||||
die("Rebuild PHP with the `overload' extension to use PEAR_Autoloader");
|
||||
}
|
||||
|
||||
/**
|
||||
* Include for PEAR_Error and PEAR classes
|
||||
*/
|
||||
require_once "PEAR.php";
|
||||
|
||||
/**
|
||||
* This class is for objects where you want to separate the code for
|
||||
* some methods into separate classes. This is useful if you have a
|
||||
* class with not-frequently-used methods that contain lots of code
|
||||
* that you would like to avoid always parsing.
|
||||
*
|
||||
* The PEAR_Autoloader class provides autoloading and aggregation.
|
||||
* The autoloading lets you set up in which classes the separated
|
||||
* methods are found. Aggregation is the technique used to import new
|
||||
* methods, an instance of each class providing separated methods is
|
||||
* stored and called every time the aggregated method is called.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
|
||||
* @since File available since Release 0.1
|
||||
* @deprecated File deprecated in Release 1.4.0a1
|
||||
*/
|
||||
class PEAR_Autoloader extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Map of methods and classes where they are defined
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $_autoload_map = array();
|
||||
|
||||
/**
|
||||
* Map of methods and aggregate objects
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $_method_map = array();
|
||||
|
||||
// }}}
|
||||
// {{{ addAutoload()
|
||||
|
||||
/**
|
||||
* Add one or more autoload entries.
|
||||
*
|
||||
* @param string $method which method to autoload
|
||||
*
|
||||
* @param string $classname (optional) which class to find the method in.
|
||||
* If the $method parameter is an array, this
|
||||
* parameter may be omitted (and will be ignored
|
||||
* if not), and the $method parameter will be
|
||||
* treated as an associative array with method
|
||||
* names as keys and class names as values.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function addAutoload($method, $classname = null)
|
||||
{
|
||||
if (is_array($method)) {
|
||||
array_walk($method, create_function('$a,&$b', '$b = strtolower($b);'));
|
||||
$this->_autoload_map = array_merge($this->_autoload_map, $method);
|
||||
} else {
|
||||
$this->_autoload_map[strtolower($method)] = $classname;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ removeAutoload()
|
||||
|
||||
/**
|
||||
* Remove an autoload entry.
|
||||
*
|
||||
* @param string $method which method to remove the autoload entry for
|
||||
*
|
||||
* @return bool TRUE if an entry was removed, FALSE if not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function removeAutoload($method)
|
||||
{
|
||||
$method = strtolower($method);
|
||||
$ok = isset($this->_autoload_map[$method]);
|
||||
unset($this->_autoload_map[$method]);
|
||||
return $ok;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ addAggregateObject()
|
||||
|
||||
/**
|
||||
* Add an aggregate object to this object. If the specified class
|
||||
* is not defined, loading it will be attempted following PEAR's
|
||||
* file naming scheme. All the methods in the class will be
|
||||
* aggregated, except private ones (name starting with an
|
||||
* underscore) and constructors.
|
||||
*
|
||||
* @param string $classname what class to instantiate for the object.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function addAggregateObject($classname)
|
||||
{
|
||||
$classname = strtolower($classname);
|
||||
if (!class_exists($classname)) {
|
||||
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
|
||||
include_once $include_file;
|
||||
}
|
||||
$obj =& new $classname;
|
||||
$methods = get_class_methods($classname);
|
||||
foreach ($methods as $method) {
|
||||
// don't import priviate methods and constructors
|
||||
if ($method{0} != '_' && $method != $classname) {
|
||||
$this->_method_map[$method] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ removeAggregateObject()
|
||||
|
||||
/**
|
||||
* Remove an aggregate object.
|
||||
*
|
||||
* @param string $classname the class of the object to remove
|
||||
*
|
||||
* @return bool TRUE if an object was removed, FALSE if not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function removeAggregateObject($classname)
|
||||
{
|
||||
$ok = false;
|
||||
$classname = strtolower($classname);
|
||||
reset($this->_method_map);
|
||||
while (list($method, $obj) = each($this->_method_map)) {
|
||||
if (is_a($obj, $classname)) {
|
||||
unset($this->_method_map[$method]);
|
||||
$ok = true;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ __call()
|
||||
|
||||
/**
|
||||
* Overloaded object call handler, called each time an
|
||||
* undefined/aggregated method is invoked. This method repeats
|
||||
* the call in the right aggregate object and passes on the return
|
||||
* value.
|
||||
*
|
||||
* @param string $method which method that was called
|
||||
*
|
||||
* @param string $args An array of the parameters passed in the
|
||||
* original call
|
||||
*
|
||||
* @return mixed The return value from the aggregated method, or a PEAR
|
||||
* error if the called method was unknown.
|
||||
*/
|
||||
function __call($method, $args, &$retval)
|
||||
{
|
||||
$method = strtolower($method);
|
||||
if (empty($this->_method_map[$method]) && isset($this->_autoload_map[$method])) {
|
||||
$this->addAggregateObject($this->_autoload_map[$method]);
|
||||
}
|
||||
if (isset($this->_method_map[$method])) {
|
||||
$retval = call_user_func_array(array($this->_method_map[$method], $method), $args);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
overload("PEAR_Autoloader");
|
||||
|
||||
?>
|
||||
461
PEAR/Builder.php
Normal file
461
PEAR/Builder.php
Normal file
|
|
@ -0,0 +1,461 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Builder for building PHP extensions (PECL packages)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Builder.php,v 1.29 2006/03/05 21:09:18 cellog Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* Needed for extending PEAR_Builder
|
||||
*/
|
||||
require_once 'PEAR/Common.php';
|
||||
require_once 'PEAR/PackageFile.php';
|
||||
/**
|
||||
* Class to handle building (compiling) extensions.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since PHP 4.0.2
|
||||
* @see http://pear.php.net/manual/en/core.ppm.pear-builder.php
|
||||
*/
|
||||
class PEAR_Builder extends PEAR_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $php_api_version = 0;
|
||||
var $zend_module_api_no = 0;
|
||||
var $zend_extension_api_no = 0;
|
||||
|
||||
var $extensions_built = array();
|
||||
|
||||
var $current_callback = null;
|
||||
|
||||
// used for msdev builds
|
||||
var $_lastline = null;
|
||||
var $_firstline = null;
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Builder constructor.
|
||||
*
|
||||
* @param object $ui user interface object (instance of PEAR_Frontend_*)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Builder(&$ui)
|
||||
{
|
||||
parent::PEAR_Common();
|
||||
$this->setFrontendObject($ui);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ _build_win32()
|
||||
|
||||
/**
|
||||
* Build an extension from source on windows.
|
||||
* requires msdev
|
||||
*/
|
||||
function _build_win32($descfile, $callback = null)
|
||||
{
|
||||
if (is_object($descfile)) {
|
||||
$pkg = $descfile;
|
||||
} else {
|
||||
$pf = &new PEAR_PackageFile($this->config, $this->debug);
|
||||
$pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
|
||||
if (PEAR::isError($pkg)) {
|
||||
return $pkg;
|
||||
}
|
||||
}
|
||||
$dir = dirname($pkg->getArchiveFile());
|
||||
$old_cwd = getcwd();
|
||||
|
||||
if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
|
||||
return $this->raiseError("could not chdir to $dir");
|
||||
}
|
||||
$this->log(2, "building in $dir");
|
||||
|
||||
$dsp = $pkg->getPackage().'.dsp';
|
||||
if (!file_exists("$dir/$dsp")) {
|
||||
return $this->raiseError("The DSP $dsp does not exist.");
|
||||
}
|
||||
// XXX TODO: make release build type configurable
|
||||
$command = 'msdev '.$dsp.' /MAKE "'.$info['package']. ' - Release"';
|
||||
|
||||
$this->current_callback = $callback;
|
||||
$err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
|
||||
// figure out the build platform and type
|
||||
$platform = 'Win32';
|
||||
$buildtype = 'Release';
|
||||
if (preg_match('/.*?'.$pkg->getPackage().'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
|
||||
$platform = $matches[1];
|
||||
$buildtype = $matches[2];
|
||||
}
|
||||
|
||||
if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/',$this->_lastline,$matches)) {
|
||||
if ($matches[2]) {
|
||||
// there were errors in the build
|
||||
return $this->raiseError("There were errors during compilation.");
|
||||
}
|
||||
$out = $matches[1];
|
||||
} else {
|
||||
return $this->raiseError("Did not understand the completion status returned from msdev.exe.");
|
||||
}
|
||||
|
||||
// msdev doesn't tell us the output directory :/
|
||||
// open the dsp, find /out and use that directory
|
||||
$dsptext = join(file($dsp),'');
|
||||
|
||||
// this regex depends on the build platform and type having been
|
||||
// correctly identified above.
|
||||
$regex ='/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
|
||||
$pkg->getPackage().'\s-\s'.
|
||||
$platform.'\s'.
|
||||
$buildtype.'").*?'.
|
||||
'\/out:"(.*?)"/is';
|
||||
|
||||
if ($dsptext && preg_match($regex,$dsptext,$matches)) {
|
||||
// what we get back is a relative path to the output file itself.
|
||||
$outfile = realpath($matches[2]);
|
||||
} else {
|
||||
return $this->raiseError("Could not retrieve output information from $dsp.");
|
||||
}
|
||||
// realpath returns false if the file doesn't exist
|
||||
if ($outfile && copy($outfile, "$dir/$out")) {
|
||||
$outfile = "$dir/$out";
|
||||
}
|
||||
|
||||
$built_files[] = array(
|
||||
'file' => "$outfile",
|
||||
'php_api' => $this->php_api_version,
|
||||
'zend_mod_api' => $this->zend_module_api_no,
|
||||
'zend_ext_api' => $this->zend_extension_api_no,
|
||||
);
|
||||
|
||||
return $built_files;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ msdevCallback()
|
||||
function msdevCallback($what, $data)
|
||||
{
|
||||
if (!$this->_firstline)
|
||||
$this->_firstline = $data;
|
||||
$this->_lastline = $data;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _harventInstDir
|
||||
/**
|
||||
* @param string
|
||||
* @param string
|
||||
* @param array
|
||||
* @access private
|
||||
*/
|
||||
function _harvestInstDir($dest_prefix, $dirname, &$built_files)
|
||||
{
|
||||
$d = opendir($dirname);
|
||||
if (!$d)
|
||||
return false;
|
||||
|
||||
$ret = true;
|
||||
while (($ent = readdir($d)) !== false) {
|
||||
if ($ent{0} == '.')
|
||||
continue;
|
||||
|
||||
$full = $dirname . DIRECTORY_SEPARATOR . $ent;
|
||||
if (is_dir($full)) {
|
||||
if (!$this->_harvestInstDir(
|
||||
$dest_prefix . DIRECTORY_SEPARATOR . $ent,
|
||||
$full, $built_files)) {
|
||||
$ret = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
|
||||
$built_files[] = array(
|
||||
'file' => $full,
|
||||
'dest' => $dest,
|
||||
'php_api' => $this->php_api_version,
|
||||
'zend_mod_api' => $this->zend_module_api_no,
|
||||
'zend_ext_api' => $this->zend_extension_api_no,
|
||||
);
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ build()
|
||||
|
||||
/**
|
||||
* Build an extension from source. Runs "phpize" in the source
|
||||
* directory, but compiles in a temporary directory
|
||||
* (/var/tmp/pear-build-USER/PACKAGE-VERSION).
|
||||
*
|
||||
* @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
|
||||
* a PEAR_PackageFile object
|
||||
*
|
||||
* @param mixed $callback callback function used to report output,
|
||||
* see PEAR_Builder::_runCommand for details
|
||||
*
|
||||
* @return array an array of associative arrays with built files,
|
||||
* format:
|
||||
* array( array( 'file' => '/path/to/ext.so',
|
||||
* 'php_api' => YYYYMMDD,
|
||||
* 'zend_mod_api' => YYYYMMDD,
|
||||
* 'zend_ext_api' => YYYYMMDD ),
|
||||
* ... )
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PEAR_Builder::_runCommand
|
||||
*/
|
||||
function build($descfile, $callback = null)
|
||||
{
|
||||
if (PEAR_OS == "Windows") {
|
||||
return $this->_build_win32($descfile,$callback);
|
||||
}
|
||||
if (PEAR_OS != 'Unix') {
|
||||
return $this->raiseError("building extensions not supported on this platform");
|
||||
}
|
||||
if (is_object($descfile)) {
|
||||
$pkg = $descfile;
|
||||
$descfile = $pkg->getPackageFile();
|
||||
} else {
|
||||
$pf = &new PEAR_PackageFile($this->config);
|
||||
$pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
|
||||
if (PEAR::isError($pkg)) {
|
||||
return $pkg;
|
||||
}
|
||||
}
|
||||
$dir = dirname($descfile);
|
||||
$old_cwd = getcwd();
|
||||
if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
|
||||
return $this->raiseError("could not chdir to $dir");
|
||||
}
|
||||
$vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
|
||||
if (is_dir($vdir)) {
|
||||
chdir($vdir);
|
||||
}
|
||||
$dir = getcwd();
|
||||
$this->log(2, "building in $dir");
|
||||
$this->current_callback = $callback;
|
||||
putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
|
||||
$err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
if (!$err) {
|
||||
return $this->raiseError("`phpize' failed");
|
||||
}
|
||||
|
||||
// {{{ start of interactive part
|
||||
$configure_command = "$dir/configure";
|
||||
$configure_options = $pkg->getConfigureOptions();
|
||||
if ($configure_options) {
|
||||
foreach ($configure_options as $o) {
|
||||
$default = array_key_exists($o['default']) ? $o['default'] : null;
|
||||
list($r) = $this->ui->userDialog('build',
|
||||
array($o['prompt']),
|
||||
array('text'),
|
||||
array($default));
|
||||
if (substr($o['name'], 0, 5) == 'with-' &&
|
||||
($r == 'yes' || $r == 'autodetect')) {
|
||||
$configure_command .= " --$o[name]";
|
||||
} else {
|
||||
$configure_command .= " --$o[name]=".trim($r);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}} end of interactive part
|
||||
|
||||
// FIXME make configurable
|
||||
if(!$user=getenv('USER')){
|
||||
$user='defaultuser';
|
||||
}
|
||||
$build_basedir = "/var/tmp/pear-build-$user";
|
||||
$build_dir = "$build_basedir/$vdir";
|
||||
$inst_dir = "$build_basedir/install-$vdir";
|
||||
$this->log(1, "building in $build_dir");
|
||||
if (is_dir($build_dir)) {
|
||||
System::rm(array('-rf', $build_dir));
|
||||
}
|
||||
if (!System::mkDir(array('-p', $build_dir))) {
|
||||
return $this->raiseError("could not create build dir: $build_dir");
|
||||
}
|
||||
$this->addTempFile($build_dir);
|
||||
if (!System::mkDir(array('-p', $inst_dir))) {
|
||||
return $this->raiseError("could not create temporary install dir: $inst_dir");
|
||||
}
|
||||
$this->addTempFile($inst_dir);
|
||||
|
||||
if (getenv('MAKE')) {
|
||||
$make_command = getenv('MAKE');
|
||||
} else {
|
||||
$make_command = 'make';
|
||||
}
|
||||
$to_run = array(
|
||||
$configure_command,
|
||||
$make_command,
|
||||
"$make_command INSTALL_ROOT=\"$inst_dir\" install",
|
||||
"find \"$inst_dir\" -ls"
|
||||
);
|
||||
if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
|
||||
return $this->raiseError("could not chdir to $build_dir");
|
||||
}
|
||||
putenv('PHP_PEAR_VERSION=1.5.0a1');
|
||||
foreach ($to_run as $cmd) {
|
||||
$err = $this->_runCommand($cmd, $callback);
|
||||
if (PEAR::isError($err)) {
|
||||
chdir($old_cwd);
|
||||
return $err;
|
||||
}
|
||||
if (!$err) {
|
||||
chdir($old_cwd);
|
||||
return $this->raiseError("`$cmd' failed");
|
||||
}
|
||||
}
|
||||
if (!($dp = opendir("modules"))) {
|
||||
chdir($old_cwd);
|
||||
return $this->raiseError("no `modules' directory found");
|
||||
}
|
||||
$built_files = array();
|
||||
$prefix = exec("php-config --prefix");
|
||||
$this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
|
||||
chdir($old_cwd);
|
||||
return $built_files;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ phpizeCallback()
|
||||
|
||||
/**
|
||||
* Message callback function used when running the "phpize"
|
||||
* program. Extracts the API numbers used. Ignores other message
|
||||
* types than "cmdoutput".
|
||||
*
|
||||
* @param string $what the type of message
|
||||
* @param mixed $data the message
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function phpizeCallback($what, $data)
|
||||
{
|
||||
if ($what != 'cmdoutput') {
|
||||
return;
|
||||
}
|
||||
$this->log(1, rtrim($data));
|
||||
if (preg_match('/You should update your .aclocal.m4/', $data)) {
|
||||
return;
|
||||
}
|
||||
$matches = array();
|
||||
if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
|
||||
$member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
|
||||
$apino = (int)$matches[2];
|
||||
if (isset($this->$member)) {
|
||||
$this->$member = $apino;
|
||||
//$msg = sprintf("%-22s : %d", $matches[1], $apino);
|
||||
//$this->log(1, $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _runCommand()
|
||||
|
||||
/**
|
||||
* Run an external command, using a message callback to report
|
||||
* output. The command will be run through popen and output is
|
||||
* reported for every line with a "cmdoutput" message with the
|
||||
* line string, including newlines, as payload.
|
||||
*
|
||||
* @param string $command the command to run
|
||||
*
|
||||
* @param mixed $callback (optional) function to use as message
|
||||
* callback
|
||||
*
|
||||
* @return bool whether the command was successful (exit code 0
|
||||
* means success, any other means failure)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _runCommand($command, $callback = null)
|
||||
{
|
||||
$this->log(1, "running: $command");
|
||||
$pp = popen("$command 2>&1", "r");
|
||||
if (!$pp) {
|
||||
return $this->raiseError("failed to run `$command'");
|
||||
}
|
||||
if ($callback && $callback[0]->debug == 1) {
|
||||
$olddbg = $callback[0]->debug;
|
||||
$callback[0]->debug = 2;
|
||||
}
|
||||
|
||||
while ($line = fgets($pp, 1024)) {
|
||||
if ($callback) {
|
||||
call_user_func($callback, 'cmdoutput', $line);
|
||||
} else {
|
||||
$this->log(2, rtrim($line));
|
||||
}
|
||||
}
|
||||
if ($callback && isset($olddbg)) {
|
||||
$callback[0]->debug = $olddbg;
|
||||
}
|
||||
if (is_resource($pp)) {
|
||||
$exitcode = pclose($pp);
|
||||
} else {
|
||||
$exitcode = -1;
|
||||
}
|
||||
return ($exitcode == 0);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ log()
|
||||
|
||||
function log($level, $msg)
|
||||
{
|
||||
if ($this->current_callback) {
|
||||
if ($this->debug >= $level) {
|
||||
call_user_func($this->current_callback, 'output', $msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return PEAR_Common::log($level, $msg);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
1613
PEAR/ChannelFile.php
Normal file
1613
PEAR/ChannelFile.php
Normal file
File diff suppressed because it is too large
Load diff
73
PEAR/ChannelFile/Parser.php
Normal file
73
PEAR/ChannelFile/Parser.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_ChannelFile_Parser for parsing channel.xml
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Parser.php,v 1.4 2006/01/06 04:47:36 cellog Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.4.0a1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base xml parser class
|
||||
*/
|
||||
require_once 'PEAR/XMLParser.php';
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
/**
|
||||
* Parser for channel.xml
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.4.0a1
|
||||
*/
|
||||
class PEAR_ChannelFile_Parser extends PEAR_XMLParser
|
||||
{
|
||||
var $_config;
|
||||
var $_logger;
|
||||
var $_registry;
|
||||
|
||||
function setConfig(&$c)
|
||||
{
|
||||
$this->_config = &$c;
|
||||
$this->_registry = &$c->getRegistry();
|
||||
}
|
||||
|
||||
function setLogger(&$l)
|
||||
{
|
||||
$this->_logger = &$l;
|
||||
}
|
||||
|
||||
function parse($data, $file)
|
||||
{
|
||||
if (PEAR::isError($err = parent::parse($data, $file))) {
|
||||
return $err;
|
||||
}
|
||||
$ret = new PEAR_ChannelFile;
|
||||
$ret->setConfig($this->_config);
|
||||
if (isset($this->_logger)) {
|
||||
$ret->setLogger($this->_logger);
|
||||
}
|
||||
$ret->fromArray($this->_unserializedData);
|
||||
// make sure the filelist is in the easy to read format needed
|
||||
$ret->flattenFilelist();
|
||||
$ret->setPackagefile($file, $archive);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
410
PEAR/Command.php
Normal file
410
PEAR/Command.php
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Command, command pattern class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Command.php,v 1.37 2006/06/09 00:17:50 pajoye Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* Needed for error handling
|
||||
*/
|
||||
require_once 'PEAR.php';
|
||||
require_once 'PEAR/Frontend.php';
|
||||
require_once 'PEAR/XMLParser.php';
|
||||
|
||||
/**
|
||||
* List of commands and what classes they are implemented in.
|
||||
* @var array command => implementing class
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
|
||||
/**
|
||||
* List of shortcuts to common commands.
|
||||
* @var array shortcut => command
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_shortcuts'] = array();
|
||||
|
||||
/**
|
||||
* Array of command objects
|
||||
* @var array class => object
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_objects'] = array();
|
||||
|
||||
/**
|
||||
* PEAR command class, a simple factory class for administrative
|
||||
* commands.
|
||||
*
|
||||
* How to implement command classes:
|
||||
*
|
||||
* - The class must be called PEAR_Command_Nnn, installed in the
|
||||
* "PEAR/Common" subdir, with a method called getCommands() that
|
||||
* returns an array of the commands implemented by the class (see
|
||||
* PEAR/Command/Install.php for an example).
|
||||
*
|
||||
* - The class must implement a run() function that is called with three
|
||||
* params:
|
||||
*
|
||||
* (string) command name
|
||||
* (array) assoc array with options, freely defined by each
|
||||
* command, for example:
|
||||
* array('force' => true)
|
||||
* (array) list of the other parameters
|
||||
*
|
||||
* The run() function returns a PEAR_CommandResponse object. Use
|
||||
* these methods to get information:
|
||||
*
|
||||
* int getStatus() Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
|
||||
* *_PARTIAL means that you need to issue at least
|
||||
* one more command to complete the operation
|
||||
* (used for example for validation steps).
|
||||
*
|
||||
* string getMessage() Returns a message for the user. Remember,
|
||||
* no HTML or other interface-specific markup.
|
||||
*
|
||||
* If something unexpected happens, run() returns a PEAR error.
|
||||
*
|
||||
* - DON'T OUTPUT ANYTHING! Return text for output instead.
|
||||
*
|
||||
* - DON'T USE HTML! The text you return will be used from both Gtk,
|
||||
* web and command-line interfaces, so for now, keep everything to
|
||||
* plain text.
|
||||
*
|
||||
* - DON'T USE EXIT OR DIE! Always use pear errors. From static
|
||||
* classes do PEAR::raiseError(), from other classes do
|
||||
* $this->raiseError().
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
class PEAR_Command
|
||||
{
|
||||
// {{{ factory()
|
||||
|
||||
/**
|
||||
* Get the right object for executing a command.
|
||||
*
|
||||
* @param string $command The name of the command
|
||||
* @param object $config Instance of PEAR_Config object
|
||||
*
|
||||
* @return object the command object or a PEAR error
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function &factory($command, &$config)
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
|
||||
$command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
|
||||
}
|
||||
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
|
||||
$a = PEAR::raiseError("unknown command `$command'");
|
||||
return $a;
|
||||
}
|
||||
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
|
||||
if (!class_exists($class)) {
|
||||
require_once $GLOBALS['_PEAR_Command_objects'][$class];
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
$a = PEAR::raiseError("unknown command `$command'");
|
||||
return $a;
|
||||
}
|
||||
$ui =& PEAR_Command::getFrontendObject();
|
||||
$obj = &new $class($ui, $config);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ & getObject()
|
||||
function &getObject($command)
|
||||
{
|
||||
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
|
||||
if (!class_exists($class)) {
|
||||
require_once $GLOBALS['_PEAR_Command_objects'][$class];
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
return PEAR::raiseError("unknown command `$command'");
|
||||
}
|
||||
$ui =& PEAR_Command::getFrontendObject();
|
||||
$config = &PEAR_Config::singleton();
|
||||
$obj = &new $class($ui, $config);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ & getFrontendObject()
|
||||
|
||||
/**
|
||||
* Get instance of frontend object.
|
||||
*
|
||||
* @return object|PEAR_Error
|
||||
* @static
|
||||
*/
|
||||
function &getFrontendObject()
|
||||
{
|
||||
$a = &PEAR_Frontend::singleton();
|
||||
return $a;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ & setFrontendClass()
|
||||
|
||||
/**
|
||||
* Load current frontend class.
|
||||
*
|
||||
* @param string $uiclass Name of class implementing the frontend
|
||||
*
|
||||
* @return object the frontend object, or a PEAR error
|
||||
* @static
|
||||
*/
|
||||
function &setFrontendClass($uiclass)
|
||||
{
|
||||
$a = &PEAR_Frontend::setFrontendClass($uiclass);
|
||||
return $a;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setFrontendType()
|
||||
|
||||
/**
|
||||
* Set current frontend.
|
||||
*
|
||||
* @param string $uitype Name of the frontend type (for example "CLI")
|
||||
*
|
||||
* @return object the frontend object, or a PEAR error
|
||||
* @static
|
||||
*/
|
||||
function setFrontendType($uitype)
|
||||
{
|
||||
$uiclass = 'PEAR_Frontend_' . $uitype;
|
||||
return PEAR_Command::setFrontendClass($uiclass);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ registerCommands()
|
||||
|
||||
/**
|
||||
* Scan through the Command directory looking for classes
|
||||
* and see what commands they implement.
|
||||
*
|
||||
* @param bool (optional) if FALSE (default), the new list of
|
||||
* commands should replace the current one. If TRUE,
|
||||
* new entries will be merged with old.
|
||||
*
|
||||
* @param string (optional) where (what directory) to look for
|
||||
* classes, defaults to the Command subdirectory of
|
||||
* the directory from where this file (__FILE__) is
|
||||
* included.
|
||||
*
|
||||
* @return bool TRUE on success, a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function registerCommands($merge = false, $dir = null)
|
||||
{
|
||||
$parser = new PEAR_XMLParser;
|
||||
if ($dir === null) {
|
||||
$dir = dirname(__FILE__) . '/Command';
|
||||
}
|
||||
if (!is_dir($dir)) {
|
||||
return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory");
|
||||
}
|
||||
$dp = @opendir($dir);
|
||||
if (empty($dp)) {
|
||||
return PEAR::raiseError("registerCommands: opendir($dir) failed");
|
||||
}
|
||||
if (!$merge) {
|
||||
$GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
}
|
||||
while ($entry = readdir($dp)) {
|
||||
if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
|
||||
continue;
|
||||
}
|
||||
$class = "PEAR_Command_".substr($entry, 0, -4);
|
||||
$file = "$dir/$entry";
|
||||
$parser->parse(file_get_contents($file));
|
||||
$implements = $parser->getData();
|
||||
// List of commands
|
||||
if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
|
||||
$GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . substr($entry, 0, -4) .
|
||||
'.php';
|
||||
}
|
||||
foreach ($implements as $command => $desc) {
|
||||
if ($command == 'attribs') {
|
||||
continue;
|
||||
}
|
||||
if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
|
||||
return PEAR::raiseError('Command "' . $command . '" already registered in ' .
|
||||
'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
|
||||
}
|
||||
$GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
|
||||
$GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary'];
|
||||
if (isset($desc['shortcut'])) {
|
||||
$shortcut = $desc['shortcut'];
|
||||
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) {
|
||||
return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' .
|
||||
'registered to command "' . $command . '" in class "' .
|
||||
$GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
|
||||
}
|
||||
$GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
|
||||
}
|
||||
if (isset($desc['options']) && $desc['options']) {
|
||||
foreach ($desc['options'] as $oname => $option) {
|
||||
if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) {
|
||||
return PEAR::raiseError('Option "' . $oname . '" short option "' .
|
||||
$option['shortopt'] . '" must be ' .
|
||||
'only 1 character in Command "' . $command . '" in class "' .
|
||||
$class . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ksort($GLOBALS['_PEAR_Command_shortcuts']);
|
||||
ksort($GLOBALS['_PEAR_Command_commandlist']);
|
||||
@closedir($dp);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getCommands()
|
||||
|
||||
/**
|
||||
* Get the list of currently supported commands, and what
|
||||
* classes implement them.
|
||||
*
|
||||
* @return array command => implementing class
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function getCommands()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_commandlist'];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getShortcuts()
|
||||
|
||||
/**
|
||||
* Get the list of command shortcuts.
|
||||
*
|
||||
* @return array shortcut => command
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function getShortcuts()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_shortcuts'];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getGetoptArgs()
|
||||
|
||||
/**
|
||||
* Compiles arguments for getopt.
|
||||
*
|
||||
* @param string $command command to get optstring for
|
||||
* @param string $short_args (reference) short getopt format
|
||||
* @param array $long_args (reference) long getopt format
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function getGetoptArgs($command, &$short_args, &$long_args)
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
|
||||
$command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
|
||||
}
|
||||
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
|
||||
return null;
|
||||
}
|
||||
$obj = &PEAR_Command::getObject($command);
|
||||
return $obj->getGetoptArgs($command, $short_args, $long_args);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getDescription()
|
||||
|
||||
/**
|
||||
* Get description for a command.
|
||||
*
|
||||
* @param string $command Name of the command
|
||||
*
|
||||
* @return string command description
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function getDescription($command)
|
||||
{
|
||||
if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
|
||||
return null;
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_commanddesc'][$command];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getHelp()
|
||||
|
||||
/**
|
||||
* Get help for command.
|
||||
*
|
||||
* @param string $command Name of the command to return help for
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function getHelp($command)
|
||||
{
|
||||
$cmds = PEAR_Command::getCommands();
|
||||
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
|
||||
$command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
|
||||
}
|
||||
if (isset($cmds[$command])) {
|
||||
$obj = &PEAR_Command::getObject($command);
|
||||
return $obj->getHelp($command);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
186
PEAR/Command/Auth.php
Normal file
186
PEAR/Command/Auth.php
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Command_Auth (login, logout commands)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Auth.php,v 1.24 2006/03/05 21:23:21 cellog Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class
|
||||
*/
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
require_once 'PEAR/Config.php';
|
||||
|
||||
/**
|
||||
* PEAR commands for login/logout
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
class PEAR_Command_Auth extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $commands = array(
|
||||
'login' => array(
|
||||
'summary' => 'Connects and authenticates to remote server',
|
||||
'shortcut' => 'li',
|
||||
'function' => 'doLogin',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Log in to the remote server. To use remote functions in the installer
|
||||
that require any kind of privileges, you need to log in first. The
|
||||
username and password you enter here will be stored in your per-user
|
||||
PEAR configuration (~/.pearrc on Unix-like systems). After logging
|
||||
in, your username and password will be sent along in subsequent
|
||||
operations on the remote server.',
|
||||
),
|
||||
'logout' => array(
|
||||
'summary' => 'Logs out from the remote server',
|
||||
'shortcut' => 'lo',
|
||||
'function' => 'doLogout',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
Logs out from the remote server. This command does not actually
|
||||
connect to the remote server, it only deletes the stored username and
|
||||
password from your user configuration.',
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Auth constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Auth(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ doLogin()
|
||||
|
||||
/**
|
||||
* Execute the 'login' command.
|
||||
*
|
||||
* @param string $command command name
|
||||
*
|
||||
* @param array $options option_name => value
|
||||
*
|
||||
* @param array $params list of additional parameters
|
||||
*
|
||||
* @return bool TRUE on success or
|
||||
* a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function doLogin($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
$channel = $this->config->get('default_channel');
|
||||
$chan = $reg->getChannel($channel);
|
||||
if (PEAR::isError($chan)) {
|
||||
return $this->raiseError($chan);
|
||||
}
|
||||
$server = $this->config->get('preferred_mirror');
|
||||
$remote = &$this->config->getRemote();
|
||||
$username = $this->config->get('username');
|
||||
if (empty($username)) {
|
||||
$username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
|
||||
}
|
||||
$this->ui->outputData("Logging in to $server.", $command);
|
||||
|
||||
list($username, $password) = $this->ui->userDialog(
|
||||
$command,
|
||||
array('Username', 'Password'),
|
||||
array('text', 'password'),
|
||||
array($username, '')
|
||||
);
|
||||
$username = trim($username);
|
||||
$password = trim($password);
|
||||
|
||||
$this->config->set('username', $username);
|
||||
$this->config->set('password', $password);
|
||||
|
||||
if ($chan->supportsREST()) {
|
||||
$ok = true;
|
||||
} else {
|
||||
$remote->expectError(401);
|
||||
$ok = $remote->call('logintest');
|
||||
$remote->popExpect();
|
||||
}
|
||||
if ($ok === true) {
|
||||
$this->ui->outputData("Logged in.", $command);
|
||||
$this->config->store();
|
||||
} else {
|
||||
return $this->raiseError("Login failed!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doLogout()
|
||||
|
||||
/**
|
||||
* Execute the 'logout' command.
|
||||
*
|
||||
* @param string $command command name
|
||||
*
|
||||
* @param array $options option_name => value
|
||||
*
|
||||
* @param array $params list of additional parameters
|
||||
*
|
||||
* @return bool TRUE on success or
|
||||
* a PEAR error on failure
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function doLogout($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
$channel = $this->config->get('default_channel');
|
||||
$chan = $reg->getChannel($channel);
|
||||
if (PEAR::isError($chan)) {
|
||||
return $this->raiseError($chan);
|
||||
}
|
||||
$server = $this->config->get('preferred_mirror');
|
||||
$this->ui->outputData("Logging out from $server.", $command);
|
||||
$this->config->remove('username');
|
||||
$this->config->remove('password');
|
||||
$this->config->store();
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
25
PEAR/Command/Auth.xml
Normal file
25
PEAR/Command/Auth.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<commands version="1.0">
|
||||
<login>
|
||||
<summary>Connects and authenticates to remote server</summary>
|
||||
<shortcut>li</shortcut>
|
||||
<function>doLogin</function>
|
||||
<options />
|
||||
<doc>
|
||||
Log in to the remote server. To use remote functions in the installer
|
||||
that require any kind of privileges, you need to log in first. The
|
||||
username and password you enter here will be stored in your per-user
|
||||
PEAR configuration (~/.pearrc on Unix-like systems). After logging
|
||||
in, your username and password will be sent along in subsequent
|
||||
operations on the remote server.</doc>
|
||||
</login>
|
||||
<logout>
|
||||
<summary>Logs out from the remote server</summary>
|
||||
<shortcut>lo</shortcut>
|
||||
<function>doLogout</function>
|
||||
<options />
|
||||
<doc>
|
||||
Logs out from the remote server. This command does not actually
|
||||
connect to the remote server, it only deletes the stored username and
|
||||
password from your user configuration.</doc>
|
||||
</logout>
|
||||
</commands>
|
||||
104
PEAR/Command/Build.php
Normal file
104
PEAR/Command/Build.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Command_Auth (build command)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Build.php,v 1.13 2006/01/06 04:47:36 cellog Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class
|
||||
*/
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
|
||||
/**
|
||||
* PEAR commands for building extensions.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
class PEAR_Command_Build extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $commands = array(
|
||||
'build' => array(
|
||||
'summary' => 'Build an Extension From C Source',
|
||||
'function' => 'doBuild',
|
||||
'shortcut' => 'b',
|
||||
'options' => array(),
|
||||
'doc' => '[package.xml]
|
||||
Builds one or more extensions contained in a package.'
|
||||
),
|
||||
);
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Build constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Build(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ doBuild()
|
||||
|
||||
function doBuild($command, $options, $params)
|
||||
{
|
||||
require_once 'PEAR/Builder.php';
|
||||
if (sizeof($params) < 1) {
|
||||
$params[0] = 'package.xml';
|
||||
}
|
||||
$builder = &new PEAR_Builder($this->ui);
|
||||
$this->debug = $this->config->get('verbose');
|
||||
$err = $builder->build($params[0], array(&$this, 'buildCallback'));
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ buildCallback()
|
||||
|
||||
function buildCallback($what, $data)
|
||||
{
|
||||
if (($what == 'cmdoutput' && $this->debug > 1) ||
|
||||
($what == 'output' && $this->debug > 0)) {
|
||||
$this->ui->outputData(rtrim($data), 'build');
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
10
PEAR/Command/Build.xml
Normal file
10
PEAR/Command/Build.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<commands version="1.0">
|
||||
<build>
|
||||
<summary>Build an Extension From C Source</summary>
|
||||
<function>doBuild</function>
|
||||
<shortcut>b</shortcut>
|
||||
<options />
|
||||
<doc>[package.xml]
|
||||
Builds one or more extensions contained in a package.</doc>
|
||||
</build>
|
||||
</commands>
|
||||
785
PEAR/Command/Channels.php
Normal file
785
PEAR/Command/Channels.php
Normal file
|
|
@ -0,0 +1,785 @@
|
|||
<?php
|
||||
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
/**
|
||||
* PEAR_Command_Channels (list-channels, update-channels, channel-delete, channel-add,
|
||||
* channel-update, channel-info, channel-alias, channel-discover commands)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Channels.php,v 1.46 2006/07/17 18:19:25 pajoye Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.4.0a1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class
|
||||
*/
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
|
||||
/**
|
||||
* PEAR commands for managing channels.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.4.0a1
|
||||
*/
|
||||
class PEAR_Command_Channels extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $commands = array(
|
||||
'list-channels' => array(
|
||||
'summary' => 'List Available Channels',
|
||||
'function' => 'doList',
|
||||
'shortcut' => 'lc',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
List all available channels for installation.
|
||||
',
|
||||
),
|
||||
'update-channels' => array(
|
||||
'summary' => 'Update the Channel List',
|
||||
'function' => 'doUpdateAll',
|
||||
'shortcut' => 'uc',
|
||||
'options' => array(),
|
||||
'doc' => '
|
||||
List all installed packages in all channels.
|
||||
'
|
||||
),
|
||||
'channel-delete' => array(
|
||||
'summary' => 'Remove a Channel From the List',
|
||||
'function' => 'doDelete',
|
||||
'shortcut' => 'cde',
|
||||
'options' => array(),
|
||||
'doc' => '<channel name>
|
||||
Delete a channel from the registry. You may not
|
||||
remove any channel that has installed packages.
|
||||
'
|
||||
),
|
||||
'channel-add' => array(
|
||||
'summary' => 'Add a Channel',
|
||||
'function' => 'doAdd',
|
||||
'shortcut' => 'ca',
|
||||
'options' => array(),
|
||||
'doc' => '<channel.xml>
|
||||
Add a private channel to the channel list. Note that all
|
||||
public channels should be synced using "update-channels".
|
||||
Parameter may be either a local file or remote URL to a
|
||||
channel.xml.
|
||||
'
|
||||
),
|
||||
'channel-update' => array(
|
||||
'summary' => 'Update an Existing Channel',
|
||||
'function' => 'doUpdate',
|
||||
'shortcut' => 'cu',
|
||||
'options' => array(
|
||||
'force' => array(
|
||||
'shortopt' => 'f',
|
||||
'doc' => 'will force download of new channel.xml if an existing channel name is used',
|
||||
),
|
||||
'channel' => array(
|
||||
'shortopt' => 'c',
|
||||
'arg' => 'CHANNEL',
|
||||
'doc' => 'will force download of new channel.xml if an existing channel name is used',
|
||||
),
|
||||
),
|
||||
'doc' => '[<channel.xml>|<channel name>]
|
||||
Update a channel in the channel list directly. Note that all
|
||||
public channels can be synced using "update-channels".
|
||||
Parameter may be a local or remote channel.xml, or the name of
|
||||
an existing channel.
|
||||
'
|
||||
),
|
||||
'channel-info' => array(
|
||||
'summary' => 'Retrieve Information on a Channel',
|
||||
'function' => 'doInfo',
|
||||
'shortcut' => 'ci',
|
||||
'options' => array(),
|
||||
'doc' => '<package>
|
||||
List the files in an installed package.
|
||||
'
|
||||
),
|
||||
'channel-alias' => array(
|
||||
'summary' => 'Specify an alias to a channel name',
|
||||
'function' => 'doAlias',
|
||||
'shortcut' => 'cha',
|
||||
'options' => array(),
|
||||
'doc' => '<channel> <alias>
|
||||
Specify a specific alias to use for a channel name.
|
||||
The alias may not be an existing channel name or
|
||||
alias.
|
||||
'
|
||||
),
|
||||
'channel-discover' => array(
|
||||
'summary' => 'Initialize a Channel from its server',
|
||||
'function' => 'doDiscover',
|
||||
'shortcut' => 'di',
|
||||
'options' => array(),
|
||||
'doc' => '[<channel.xml>|<channel name>]
|
||||
Initialize a Channel from its server and creates the local channel.xml.
|
||||
'
|
||||
),
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Registry constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Channels(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ doList()
|
||||
|
||||
function _sortChannels($a, $b)
|
||||
{
|
||||
return strnatcasecmp($a->getName(), $b->getName());
|
||||
}
|
||||
|
||||
function doList($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
$registered = $reg->getChannels();
|
||||
usort($registered, array(&$this, '_sortchannels'));
|
||||
$i = $j = 0;
|
||||
$data = array(
|
||||
'caption' => 'Registered Channels:',
|
||||
'border' => true,
|
||||
'headline' => array('Channel', 'Summary')
|
||||
);
|
||||
foreach ($registered as $channel) {
|
||||
$data['data'][] = array($channel->getName(),
|
||||
$channel->getSummary());
|
||||
}
|
||||
if (count($registered)==0) {
|
||||
$data = '(no registered channels)';
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doUpdateAll($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
$savechannel = $this->config->get('default_channel');
|
||||
if (isset($options['channel'])) {
|
||||
if (!$reg->channelExists($options['channel'])) {
|
||||
return $this->raiseError('Unknown channel "' . $options['channel'] . '"');
|
||||
}
|
||||
$this->config->set('default_channel', $options['channel']);
|
||||
} else {
|
||||
$this->config->set('default_channel', 'pear.php.net');
|
||||
}
|
||||
$remote = &$this->config->getRemote();
|
||||
$channels = $remote->call('channel.listAll');
|
||||
if (PEAR::isError($channels)) {
|
||||
$this->config->set('default_channel', $savechannel);
|
||||
return $channels;
|
||||
}
|
||||
if (!is_array($channels) || isset($channels['faultCode'])) {
|
||||
$this->config->set('default_channel', $savechannel);
|
||||
return $this->raiseError("Incorrect channel listing returned from channel '$chan'");
|
||||
}
|
||||
if (!count($channels)) {
|
||||
$data = 'no updates available';
|
||||
}
|
||||
$dl = &$this->getDownloader();
|
||||
if (!class_exists('System')) {
|
||||
require_once 'System.php';
|
||||
}
|
||||
$tmpdir = System::mktemp(array('-d'));
|
||||
foreach ($channels as $channel) {
|
||||
$channel = $channel[0];
|
||||
$save = $channel;
|
||||
if ($reg->channelExists($channel, true)) {
|
||||
$this->ui->outputData("Updating channel \"$channel\"", $command);
|
||||
$test = $reg->getChannel($channel, true);
|
||||
if (PEAR::isError($test)) {
|
||||
$this->ui->outputData("Channel '$channel' is corrupt in registry!", $command);
|
||||
$lastmodified = false;
|
||||
} else {
|
||||
$lastmodified = $test->lastModified();
|
||||
|
||||
}
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$contents = $dl->downloadHttp('http://' . $test->getName() . '/channel.xml',
|
||||
$this->ui, $tmpdir, null, $lastmodified);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($contents)) {
|
||||
$this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
|
||||
$test->getName() . '"', $command);
|
||||
continue;
|
||||
}
|
||||
if (!$contents) {
|
||||
$this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
|
||||
continue;
|
||||
}
|
||||
list($contents, $lastmodified) = $contents;
|
||||
$info = implode('', file($contents));
|
||||
if (!$info) {
|
||||
$this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
|
||||
continue;
|
||||
}
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$channelinfo = new PEAR_ChannelFile;
|
||||
$channelinfo->fromXmlString($info);
|
||||
if ($channelinfo->getErrors()) {
|
||||
$this->ui->outputData("Downloaded channel data from channel \"$channel\" " .
|
||||
'is corrupt, skipping', $command);
|
||||
continue;
|
||||
}
|
||||
$channel = $channelinfo;
|
||||
if ($channel->getName() != $save) {
|
||||
$this->ui->outputData('ERROR: Security risk - downloaded channel ' .
|
||||
'definition file for channel "'
|
||||
. $channel->getName() . ' from channel "' . $save .
|
||||
'". To use anyway, use channel-update', $command);
|
||||
continue;
|
||||
}
|
||||
$reg->updateChannel($channel, $lastmodified);
|
||||
} else {
|
||||
if ($reg->isAlias($channel)) {
|
||||
$temp = &$reg->getChannel($channel);
|
||||
if (PEAR::isError($temp)) {
|
||||
return $this->raiseError($temp);
|
||||
}
|
||||
$temp->setAlias($temp->getName(), true); // set the alias to the channel name
|
||||
if ($reg->channelExists($temp->getName())) {
|
||||
$this->ui->outputData('ERROR: existing channel "' . $temp->getName() .
|
||||
'" is aliased to "' . $channel . '" already and cannot be ' .
|
||||
're-aliased to "' . $temp->getName() . '" because a channel with ' .
|
||||
'that name or alias already exists! Please re-alias and try ' .
|
||||
'again.', $command);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$this->ui->outputData("Adding new channel \"$channel\"", $command);
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$contents = $dl->downloadHttp('http://' . $channel . '/channel.xml',
|
||||
$this->ui, $tmpdir, null, false);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($contents)) {
|
||||
$this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
|
||||
$channel . '"', $command);
|
||||
continue;
|
||||
}
|
||||
list($contents, $lastmodified) = $contents;
|
||||
$info = implode('', file($contents));
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$channelinfo = new PEAR_Channelfile;
|
||||
$channelinfo->fromXmlString($info);
|
||||
if ($channelinfo->getErrors()) {
|
||||
$this->ui->outputData("Downloaded channel data from channel \"$channel\"" .
|
||||
' is corrupt, skipping', $command);
|
||||
continue;
|
||||
}
|
||||
$channel = $channelinfo;
|
||||
if ($channel->getName() != $save) {
|
||||
$this->ui->outputData('ERROR: Security risk - downloaded channel ' .
|
||||
'definition file for channel "'
|
||||
. $channel->getName() . '" from channel "' . $save .
|
||||
'". To use anyway, use channel-update', $command);
|
||||
continue;
|
||||
}
|
||||
$reg->addChannel($channel, $lastmodified);
|
||||
}
|
||||
}
|
||||
$this->config->set('default_channel', $savechannel);
|
||||
$this->ui->outputData('update-channels complete', $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doInfo($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("No channel specified");
|
||||
}
|
||||
$reg = &$this->config->getRegistry();
|
||||
$channel = strtolower($params[0]);
|
||||
if ($reg->channelExists($channel)) {
|
||||
$chan = $reg->getChannel($channel);
|
||||
if (PEAR::isError($chan)) {
|
||||
return $this->raiseError($chan);
|
||||
}
|
||||
} else {
|
||||
if (strpos($channel, '://')) {
|
||||
$downloader = &$this->getDownloader();
|
||||
if (!class_exists('System')) {
|
||||
require_once 'System.php';
|
||||
}
|
||||
$tmpdir = System::mktemp(array('-d'));
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($loc)) {
|
||||
return $this->raiseError('Cannot open "' . $channel . '"');
|
||||
} else {
|
||||
$contents = implode('', file($loc));
|
||||
}
|
||||
} else {
|
||||
if (file_exists($params[0])) {
|
||||
$fp = fopen($params[0], 'r');
|
||||
if (!$fp) {
|
||||
return $this->raiseError('Cannot open "' . $params[0] . '"');
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError('Unknown channel "' . $channel . '"');
|
||||
}
|
||||
$contents = '';
|
||||
while (!feof($fp)) {
|
||||
$contents .= fread($fp, 1024);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$chan = new PEAR_ChannelFile;
|
||||
$chan->fromXmlString($contents);
|
||||
$chan->validate();
|
||||
if ($errs = $chan->getErrors(true)) {
|
||||
foreach ($errs as $err) {
|
||||
$this->ui->outputData($err['level'] . ': ' . $err['message']);
|
||||
}
|
||||
return $this->raiseError('Channel file "' . $params[0] . '" is not valid');
|
||||
}
|
||||
}
|
||||
if ($chan) {
|
||||
$channel = $chan->getName();
|
||||
$caption = 'Channel ' . $channel . ' Information:';
|
||||
$data1 = array(
|
||||
'caption' => $caption,
|
||||
'border' => true);
|
||||
$data1['data']['server'] = array('Name and Server', $chan->getName());
|
||||
if ($chan->getAlias() != $chan->getName()) {
|
||||
$data1['data']['alias'] = array('Alias', $chan->getAlias());
|
||||
}
|
||||
$data1['data']['summary'] = array('Summary', $chan->getSummary());
|
||||
$validate = $chan->getValidationPackage();
|
||||
$data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
|
||||
$data1['data']['vpackageversion'] =
|
||||
array('Validation Package Version', $validate['attribs']['version']);
|
||||
$d = array();
|
||||
$d['main'] = $data1;
|
||||
|
||||
$data['data'] = array();
|
||||
$data['caption'] = 'Server Capabilities';
|
||||
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
|
||||
$capabilities = $chan->getFunctions('xmlrpc');
|
||||
$soaps = $chan->getFunctions('soap');
|
||||
if ($capabilities || $soaps || $chan->supportsREST()) {
|
||||
if ($capabilities) {
|
||||
if (!isset($capabilities[0])) {
|
||||
$capabilities = array($capabilities);
|
||||
}
|
||||
foreach ($capabilities as $protocol) {
|
||||
$data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
if ($soaps) {
|
||||
if (!isset($soaps[0])) {
|
||||
$soaps = array($soaps);
|
||||
}
|
||||
foreach ($soaps as $protocol) {
|
||||
$data['data'][] = array('soap', $protocol['attribs']['version'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
if ($chan->supportsREST()) {
|
||||
$funcs = $chan->getFunctions('rest');
|
||||
if (!isset($funcs[0])) {
|
||||
$funcs = array($funcs);
|
||||
}
|
||||
foreach ($funcs as $protocol) {
|
||||
$data['data'][] = array('rest', $protocol['attribs']['type'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data['data'][] = array('No supported protocols');
|
||||
}
|
||||
$d['protocols'] = $data;
|
||||
$data['data'] = array();
|
||||
$mirrors = $chan->getMirrors();
|
||||
if ($mirrors) {
|
||||
$data['caption'] = 'Channel ' . $channel . ' Mirrors:';
|
||||
unset($data['headline']);
|
||||
foreach ($mirrors as $mirror) {
|
||||
$data['data'][] = array($mirror['attribs']['host']);
|
||||
$d['mirrors'] = $data;
|
||||
}
|
||||
foreach ($mirrors as $mirror) {
|
||||
$data['data'] = array();
|
||||
$data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
|
||||
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
|
||||
$capabilities = $chan->getFunctions('xmlrpc', $mirror['attribs']['host']);
|
||||
$soaps = $chan->getFunctions('soap', $mirror['attribs']['host']);
|
||||
if ($capabilities || $soaps || $chan->supportsREST($mirror['attribs']['host'])) {
|
||||
if ($capabilities) {
|
||||
if (!isset($capabilities[0])) {
|
||||
$capabilities = array($capabilities);
|
||||
}
|
||||
foreach ($capabilities as $protocol) {
|
||||
$data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
if ($soaps) {
|
||||
if (!isset($soaps[0])) {
|
||||
$soaps = array($soaps);
|
||||
}
|
||||
foreach ($soaps as $protocol) {
|
||||
$data['data'][] = array('soap', $protocol['attribs']['version'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
if ($chan->supportsREST($mirror['attribs']['host'])) {
|
||||
$funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
|
||||
if (!isset($funcs[0])) {
|
||||
$funcs = array($funcs);
|
||||
}
|
||||
foreach ($funcs as $protocol) {
|
||||
$data['data'][] = array('rest', $protocol['attribs']['type'],
|
||||
$protocol['_content']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data['data'][] = array('No supported protocols');
|
||||
}
|
||||
$d['mirrorprotocols'] = $data;
|
||||
}
|
||||
}
|
||||
$this->ui->outputData($d, 'channel-info');
|
||||
} else {
|
||||
return $this->raiseError('Serious error: Channel "' . $params[0] .
|
||||
'" has a corrupted registry entry');
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function doDelete($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError('channel-delete: no channel specified');
|
||||
}
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (!$reg->channelExists($params[0])) {
|
||||
return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');
|
||||
}
|
||||
$channel = $reg->channelName($params[0]);
|
||||
if ($channel == 'pear.php.net') {
|
||||
return $this->raiseError('Cannot delete the pear.php.net channel');
|
||||
}
|
||||
if ($channel == 'pecl.php.net') {
|
||||
return $this->raiseError('Cannot delete the pecl.php.net channel');
|
||||
}
|
||||
if ($channel == '__uri') {
|
||||
return $this->raiseError('Cannot delete the __uri pseudo-channel');
|
||||
}
|
||||
if (PEAR::isError($err = $reg->listPackages($channel))) {
|
||||
return $err;
|
||||
}
|
||||
if (count($err)) {
|
||||
return $this->raiseError('Channel "' . $channel .
|
||||
'" has installed packages, cannot delete');
|
||||
}
|
||||
if (!$reg->deleteChannel($channel)) {
|
||||
return $this->raiseError('Channel "' . $channel . '" deletion failed');
|
||||
} else {
|
||||
$this->config->deleteChannel($channel);
|
||||
$this->ui->outputData('Channel "' . $channel . '" deleted', $command);
|
||||
}
|
||||
}
|
||||
|
||||
function doAdd($command, $options, $params)
|
||||
{
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError('channel-add: no channel file specified');
|
||||
}
|
||||
if (strpos($params[0], '://')) {
|
||||
$downloader = &$this->getDownloader();
|
||||
if (!class_exists('System')) {
|
||||
require_once 'System.php';
|
||||
}
|
||||
$tmpdir = System::mktemp(array('-d'));
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($loc)) {
|
||||
return $this->raiseError('channel-add: Cannot open "' . $params[0] . '"');
|
||||
} else {
|
||||
list($loc, $lastmodified) = $loc;
|
||||
$contents = implode('', file($loc));
|
||||
}
|
||||
} else {
|
||||
$lastmodified = $fp = false;
|
||||
if (file_exists($params[0])) {
|
||||
$fp = fopen($params[0], 'r');
|
||||
}
|
||||
if (!$fp) {
|
||||
return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');
|
||||
}
|
||||
$contents = '';
|
||||
while (!feof($fp)) {
|
||||
$contents .= fread($fp, 1024);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$channel = new PEAR_ChannelFile;
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $channel->fromXmlString($contents);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (!$result) {
|
||||
$exit = false;
|
||||
if (count($errors = $channel->getErrors(true))) {
|
||||
foreach ($errors as $error) {
|
||||
$this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
|
||||
if (!$exit) {
|
||||
$exit = $error['level'] == 'error' ? true : false;
|
||||
}
|
||||
}
|
||||
if ($exit) {
|
||||
return $this->raiseError('channel-add: invalid channel.xml file');
|
||||
}
|
||||
}
|
||||
}
|
||||
$reg = &$this->config->getRegistry();
|
||||
if ($reg->channelExists($channel->getName())) {
|
||||
return $this->raiseError('channel-add: Channel "' . $channel->getName() .
|
||||
'" exists, use channel-update to update entry');
|
||||
}
|
||||
$ret = $reg->addChannel($channel, $lastmodified);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
if (!$ret) {
|
||||
return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .
|
||||
'" to registry failed');
|
||||
}
|
||||
$this->config->setChannels($reg->listChannels());
|
||||
$this->config->writeConfigFile();
|
||||
$this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);
|
||||
}
|
||||
|
||||
function doUpdate($command, $options, $params)
|
||||
{
|
||||
if (!class_exists('System')) {
|
||||
require_once 'System.php';
|
||||
}
|
||||
$tmpdir = System::mktemp(array('-d'));
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("No channel file specified");
|
||||
}
|
||||
$lastmodified = false;
|
||||
if ((!file_exists($params[0]) || is_dir($params[0]))
|
||||
&& $reg->channelExists(strtolower($params[0]))) {
|
||||
$c = $reg->getChannel(strtolower($params[0]));
|
||||
if (PEAR::isError($c)) {
|
||||
return $this->raiseError($c);
|
||||
}
|
||||
$this->ui->outputData('Retrieving channel.xml from remote server');
|
||||
$dl = &$this->getDownloader(array());
|
||||
// if force is specified, use a timestamp of "1" to force retrieval
|
||||
$lastmodified = isset($options['force']) ? false : $c->lastModified();
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml',
|
||||
$this->ui, $tmpdir, null, $lastmodified);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($contents)) {
|
||||
return $this->raiseError('Cannot retrieve channel.xml for channel "' .
|
||||
$c->getName() . '"');
|
||||
}
|
||||
list($contents, $lastmodified) = $contents;
|
||||
if (!$contents) {
|
||||
$this->ui->outputData("Channel $params[0] channel.xml is up to date");
|
||||
return;
|
||||
}
|
||||
$contents = implode('', file($contents));
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$channel = new PEAR_ChannelFile;
|
||||
$channel->fromXmlString($contents);
|
||||
if (!$channel->getErrors()) {
|
||||
// security check: is the downloaded file for the channel we got it from?
|
||||
if (strtolower($channel->getName()) != strtolower($c->getName())) {
|
||||
if (isset($options['force'])) {
|
||||
$this->ui->log(0, 'WARNING: downloaded channel definition file' .
|
||||
' for channel "' . $channel->getName() . '" from channel "' .
|
||||
strtolower($c->getName()) . '"');
|
||||
} else {
|
||||
return $this->raiseError('ERROR: downloaded channel definition file' .
|
||||
' for channel "' . $channel->getName() . '" from channel "' .
|
||||
strtolower($c->getName()) . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (strpos($params[0], '://')) {
|
||||
$dl = &$this->getDownloader();
|
||||
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$loc = $dl->downloadHttp($params[0],
|
||||
$this->ui, $tmpdir, null, $lastmodified);
|
||||
PEAR::staticPopErrorHandling();
|
||||
if (PEAR::isError($loc)) {
|
||||
return $this->raiseError("Cannot open " . $params[0]);
|
||||
} else {
|
||||
list($loc, $lastmodified) = $loc;
|
||||
$contents = implode('', file($loc));
|
||||
}
|
||||
} else {
|
||||
$fp = false;
|
||||
if (file_exists($params[0])) {
|
||||
$fp = fopen($params[0], 'r');
|
||||
}
|
||||
if (!$fp) {
|
||||
return $this->raiseError("Cannot open " . $params[0]);
|
||||
}
|
||||
$contents = '';
|
||||
while (!feof($fp)) {
|
||||
$contents .= fread($fp, 1024);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
if (!class_exists('PEAR_ChannelFile')) {
|
||||
require_once 'PEAR/ChannelFile.php';
|
||||
}
|
||||
$channel = new PEAR_ChannelFile;
|
||||
$channel->fromXmlString($contents);
|
||||
}
|
||||
$exit = false;
|
||||
if (count($errors = $channel->getErrors(true))) {
|
||||
foreach ($errors as $error) {
|
||||
$this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
|
||||
if (!$exit) {
|
||||
$exit = $error['level'] == 'error' ? true : false;
|
||||
}
|
||||
}
|
||||
if ($exit) {
|
||||
return $this->raiseError('Invalid channel.xml file');
|
||||
}
|
||||
}
|
||||
if (!$reg->channelExists($channel->getName())) {
|
||||
return $this->raiseError('Error: Channel "' . $channel->getName() .
|
||||
'" does not exist, use channel-add to add an entry');
|
||||
}
|
||||
$ret = $reg->updateChannel($channel, $lastmodified);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
if (!$ret) {
|
||||
return $this->raiseError('Updating Channel "' . $channel->getName() .
|
||||
'" in registry failed');
|
||||
}
|
||||
$this->config->setChannels($reg->listChannels());
|
||||
$this->config->writeConfigFile();
|
||||
$this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
|
||||
}
|
||||
|
||||
function &getDownloader()
|
||||
{
|
||||
if (!class_exists('PEAR_Downloader')) {
|
||||
require_once 'PEAR/Downloader.php';
|
||||
}
|
||||
$a = new PEAR_Downloader($this->ui, array(), $this->config);
|
||||
return $a;
|
||||
}
|
||||
|
||||
function doAlias($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (sizeof($params) == 1) {
|
||||
return $this->raiseError('No channel alias specified');
|
||||
}
|
||||
if (sizeof($params) != 2) {
|
||||
return $this->raiseError(
|
||||
'Invalid format, correct is: channel-alias channel alias');
|
||||
}
|
||||
if (!$reg->channelExists($params[0], true)) {
|
||||
if ($reg->isAlias($params[0])) {
|
||||
$extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .
|
||||
strtolower($params[1]) . '")';
|
||||
} else {
|
||||
$extra = '';
|
||||
}
|
||||
return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);
|
||||
}
|
||||
if ($reg->isAlias($params[1])) {
|
||||
return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .
|
||||
'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');
|
||||
}
|
||||
$chan = &$reg->getChannel($params[0]);
|
||||
if (PEAR::isError($chan)) {
|
||||
return $this->raiseError('Corrupt registry? Error retrieving channel "' . $params[0] .
|
||||
'" information (' . $chan->getMessage() . ')');
|
||||
}
|
||||
// make it a local alias
|
||||
if (!$chan->setAlias(strtolower($params[1]), true)) {
|
||||
return $this->raiseError('Alias "' . strtolower($params[1]) .
|
||||
'" is not a valid channel alias');
|
||||
}
|
||||
$reg->updateChannel($chan);
|
||||
$this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .
|
||||
strtolower($params[1]) . '"');
|
||||
}
|
||||
|
||||
function doDiscover($command, $options, $params)
|
||||
{
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (sizeof($params) != 1) {
|
||||
return $this->raiseError("No channel server specified");
|
||||
}
|
||||
if ($reg->channelExists($params[0])) {
|
||||
if ($reg->isAlias($params[0])) {
|
||||
return $this->raiseError("A channel alias named \"$params[0]\" " .
|
||||
'already exists, aliasing channel "' . $reg->channelName($params[0])
|
||||
. '"');
|
||||
} else {
|
||||
return $this->raiseError("Channel \"$params[0]\" is already initialized");
|
||||
}
|
||||
}
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$err = $this->doAdd($command, $options, array('http://' . $params[0] . '/channel.xml'));
|
||||
$this->popErrorHandling();
|
||||
if (PEAR::isError($err)) {
|
||||
return $this->raiseError("Discovery of channel \"$params[0]\" failed (" .
|
||||
$err->getMessage() . ')');
|
||||
}
|
||||
$this->ui->outputData("Discovery of channel \"$params[0]\" succeeded", $command);
|
||||
}
|
||||
}
|
||||
?>
|
||||
93
PEAR/Command/Channels.xml
Normal file
93
PEAR/Command/Channels.xml
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<commands version="1.0">
|
||||
<list-channels>
|
||||
<summary>List Available Channels</summary>
|
||||
<function>doList</function>
|
||||
<shortcut>lc</shortcut>
|
||||
<options />
|
||||
<doc>
|
||||
List all available channels for installation.
|
||||
</doc>
|
||||
</list-channels>
|
||||
<update-channels>
|
||||
<summary>Update the Channel List</summary>
|
||||
<function>doUpdateAll</function>
|
||||
<shortcut>uc</shortcut>
|
||||
<options />
|
||||
<doc>
|
||||
List all installed packages in all channels.
|
||||
</doc>
|
||||
</update-channels>
|
||||
<channel-delete>
|
||||
<summary>Remove a Channel From the List</summary>
|
||||
<function>doDelete</function>
|
||||
<shortcut>cde</shortcut>
|
||||
<options />
|
||||
<doc><channel name>
|
||||
Delete a channel from the registry. You may not
|
||||
remove any channel that has installed packages.
|
||||
</doc>
|
||||
</channel-delete>
|
||||
<channel-add>
|
||||
<summary>Add a Channel</summary>
|
||||
<function>doAdd</function>
|
||||
<shortcut>ca</shortcut>
|
||||
<options />
|
||||
<doc><channel.xml>
|
||||
Add a private channel to the channel list. Note that all
|
||||
public channels should be synced using "update-channels".
|
||||
Parameter may be either a local file or remote URL to a
|
||||
channel.xml.
|
||||
</doc>
|
||||
</channel-add>
|
||||
<channel-update>
|
||||
<summary>Update an Existing Channel</summary>
|
||||
<function>doUpdate</function>
|
||||
<shortcut>cu</shortcut>
|
||||
<options>
|
||||
<force>
|
||||
<shortopt>f</shortopt>
|
||||
<doc>will force download of new channel.xml if an existing channel name is used</doc>
|
||||
</force>
|
||||
<channel>
|
||||
<shortopt>c</shortopt>
|
||||
<arg>CHANNEL</arg>
|
||||
<doc>will force download of new channel.xml if an existing channel name is used</doc>
|
||||
</channel>
|
||||
</options>
|
||||
<doc>[<channel.xml>|<channel name>]
|
||||
Update a channel in the channel list directly. Note that all
|
||||
public channels can be synced using "update-channels".
|
||||
Parameter may be a local or remote channel.xml, or the name of
|
||||
an existing channel.
|
||||
</doc>
|
||||
</channel-update>
|
||||
<channel-info>
|
||||
<summary>Retrieve Information on a Channel</summary>
|
||||
<function>doInfo</function>
|
||||
<shortcut>ci</shortcut>
|
||||
<options />
|
||||
<doc><package>
|
||||
List the files in an installed package.
|
||||
</doc>
|
||||
</channel-info>
|
||||
<channel-alias>
|
||||
<summary>Specify an alias to a channel name</summary>
|
||||
<function>doAlias</function>
|
||||
<shortcut>cha</shortcut>
|
||||
<options />
|
||||
<doc><channel> <alias>
|
||||
Specify a specific alias to use for a channel name.
|
||||
The alias may not be an existing channel name or
|
||||
alias.
|
||||
</doc>
|
||||
</channel-alias>
|
||||
<channel-discover>
|
||||
<summary>Initialize a Channel from its server</summary>
|
||||
<function>doDiscover</function>
|
||||
<shortcut>di</shortcut>
|
||||
<options />
|
||||
<doc>[<channel.xml>|<channel name>]
|
||||
Initialize a Channel from its server and create the local channel.xml.
|
||||
</doc>
|
||||
</channel-discover>
|
||||
</commands>
|
||||
291
PEAR/Command/Common.php
Normal file
291
PEAR/Command/Common.php
Normal file
|
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Command_Common base class
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Common.php,v 1.35 2006/06/08 22:25:18 pajoye Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class
|
||||
*/
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* PEAR commands base class
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
class PEAR_Command_Common extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* PEAR_Config object used to pass user system and configuration
|
||||
* on when executing commands
|
||||
*
|
||||
* @var PEAR_Config
|
||||
*/
|
||||
var $config;
|
||||
/**
|
||||
* @var PEAR_Registry
|
||||
* @access protected
|
||||
*/
|
||||
var $_registry;
|
||||
|
||||
/**
|
||||
* User Interface object, for all interaction with the user.
|
||||
* @var object
|
||||
*/
|
||||
var $ui;
|
||||
|
||||
var $_deps_rel_trans = array(
|
||||
'lt' => '<',
|
||||
'le' => '<=',
|
||||
'eq' => '=',
|
||||
'ne' => '!=',
|
||||
'gt' => '>',
|
||||
'ge' => '>=',
|
||||
'has' => '=='
|
||||
);
|
||||
|
||||
var $_deps_type_trans = array(
|
||||
'pkg' => 'package',
|
||||
'ext' => 'extension',
|
||||
'php' => 'PHP',
|
||||
'prog' => 'external program',
|
||||
'ldlib' => 'external library for linking',
|
||||
'rtlib' => 'external runtime library',
|
||||
'os' => 'operating system',
|
||||
'websrv' => 'web server',
|
||||
'sapi' => 'SAPI backend'
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Common constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Common(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR();
|
||||
$this->config = &$config;
|
||||
$this->ui = &$ui;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ getCommands()
|
||||
|
||||
/**
|
||||
* Return a list of all the commands defined by this class.
|
||||
* @return array list of commands
|
||||
* @access public
|
||||
*/
|
||||
function getCommands()
|
||||
{
|
||||
$ret = array();
|
||||
foreach (array_keys($this->commands) as $command) {
|
||||
$ret[$command] = $this->commands[$command]['summary'];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getShortcuts()
|
||||
|
||||
/**
|
||||
* Return a list of all the command shortcuts defined by this class.
|
||||
* @return array shortcut => command
|
||||
* @access public
|
||||
*/
|
||||
function getShortcuts()
|
||||
{
|
||||
$ret = array();
|
||||
foreach (array_keys($this->commands) as $command) {
|
||||
if (isset($this->commands[$command]['shortcut'])) {
|
||||
$ret[$this->commands[$command]['shortcut']] = $command;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOptions()
|
||||
|
||||
function getOptions($command)
|
||||
{
|
||||
$shortcuts = $this->getShortcuts();
|
||||
if (isset($shortcuts[$command])) {
|
||||
$command = $shortcuts[$command];
|
||||
}
|
||||
if (isset($this->commands[$command]) &&
|
||||
isset($this->commands[$command]['options'])) {
|
||||
return $this->commands[$command]['options'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getGetoptArgs()
|
||||
|
||||
function getGetoptArgs($command, &$short_args, &$long_args)
|
||||
{
|
||||
$short_args = "";
|
||||
$long_args = array();
|
||||
if (empty($this->commands[$command]) || empty($this->commands[$command]['options'])) {
|
||||
return;
|
||||
}
|
||||
reset($this->commands[$command]['options']);
|
||||
while (list($option, $info) = each($this->commands[$command]['options'])) {
|
||||
$larg = $sarg = '';
|
||||
if (isset($info['arg'])) {
|
||||
if ($info['arg']{0} == '(') {
|
||||
$larg = '==';
|
||||
$sarg = '::';
|
||||
$arg = substr($info['arg'], 1, -1);
|
||||
} else {
|
||||
$larg = '=';
|
||||
$sarg = ':';
|
||||
$arg = $info['arg'];
|
||||
}
|
||||
}
|
||||
if (isset($info['shortopt'])) {
|
||||
$short_args .= $info['shortopt'] . $sarg;
|
||||
}
|
||||
$long_args[] = $option . $larg;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getHelp()
|
||||
/**
|
||||
* Returns the help message for the given command
|
||||
*
|
||||
* @param string $command The command
|
||||
* @return mixed A fail string if the command does not have help or
|
||||
* a two elements array containing [0]=>help string,
|
||||
* [1]=> help string for the accepted cmd args
|
||||
*/
|
||||
function getHelp($command)
|
||||
{
|
||||
$config = &PEAR_Config::singleton();
|
||||
if (!isset($this->commands[$command])) {
|
||||
return "No such command \"$command\"";
|
||||
}
|
||||
$help = null;
|
||||
if (isset($this->commands[$command]['doc'])) {
|
||||
$help = $this->commands[$command]['doc'];
|
||||
}
|
||||
if (empty($help)) {
|
||||
// XXX (cox) Fallback to summary if there is no doc (show both?)
|
||||
if (!isset($this->commands[$command]['summary'])) {
|
||||
return "No help for command \"$command\"";
|
||||
}
|
||||
$help = $this->commands[$command]['summary'];
|
||||
}
|
||||
if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
|
||||
foreach($matches[0] as $k => $v) {
|
||||
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
|
||||
}
|
||||
}
|
||||
return array($help, $this->getHelpArgs($command));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getHelpArgs()
|
||||
/**
|
||||
* Returns the help for the accepted arguments of a command
|
||||
*
|
||||
* @param string $command
|
||||
* @return string The help string
|
||||
*/
|
||||
function getHelpArgs($command)
|
||||
{
|
||||
if (isset($this->commands[$command]['options']) &&
|
||||
count($this->commands[$command]['options']))
|
||||
{
|
||||
$help = "Options:\n";
|
||||
foreach ($this->commands[$command]['options'] as $k => $v) {
|
||||
if (isset($v['arg'])) {
|
||||
if ($v['arg'][0] == '(') {
|
||||
$arg = substr($v['arg'], 1, -1);
|
||||
$sapp = " [$arg]";
|
||||
$lapp = "[=$arg]";
|
||||
} else {
|
||||
$sapp = " $v[arg]";
|
||||
$lapp = "=$v[arg]";
|
||||
}
|
||||
} else {
|
||||
$sapp = $lapp = "";
|
||||
}
|
||||
if (isset($v['shortopt'])) {
|
||||
$s = $v['shortopt'];
|
||||
$help .= " -$s$sapp, --$k$lapp\n";
|
||||
} else {
|
||||
$help .= " --$k$lapp\n";
|
||||
}
|
||||
$p = " ";
|
||||
$doc = rtrim(str_replace("\n", "\n$p", $v['doc']));
|
||||
$help .= " $doc\n";
|
||||
}
|
||||
return $help;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ run()
|
||||
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
if (empty($this->commands[$command]['function'])) {
|
||||
// look for shortcuts
|
||||
foreach (array_keys($this->commands) as $cmd) {
|
||||
if (isset($this->commands[$cmd]['shortcut']) && $this->commands[$cmd]['shortcut'] == $command) {
|
||||
if (empty($this->commands[$cmd]['function'])) {
|
||||
return $this->raiseError("unknown command `$command'");
|
||||
} else {
|
||||
$func = $this->commands[$cmd]['function'];
|
||||
}
|
||||
$command = $cmd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$func = $this->commands[$command]['function'];
|
||||
}
|
||||
return $this->$func($command, $options, $params);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
418
PEAR/Command/Config.php
Normal file
418
PEAR/Command/Config.php
Normal file
|
|
@ -0,0 +1,418 @@
|
|||
<?php
|
||||
/**
|
||||
* PEAR_Command_Config (config-show, config-get, config-set, config-help, config-create commands)
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Config.php,v 1.52 2006/03/05 21:32:47 cellog Exp $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* base class
|
||||
*/
|
||||
require_once 'PEAR/Command/Common.php';
|
||||
|
||||
/**
|
||||
* PEAR commands for managing configuration data.
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.5.0a1
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 0.1
|
||||
*/
|
||||
class PEAR_Command_Config extends PEAR_Command_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $commands = array(
|
||||
'config-show' => array(
|
||||
'summary' => 'Show All Settings',
|
||||
'function' => 'doConfigShow',
|
||||
'shortcut' => 'csh',
|
||||
'options' => array(
|
||||
'channel' => array(
|
||||
'shortopt' => 'c',
|
||||
'doc' => 'show configuration variables for another channel',
|
||||
'arg' => 'CHAN',
|
||||
),
|
||||
),
|
||||
'doc' => '[layer]
|
||||
Displays all configuration values. An optional argument
|
||||
may be used to tell which configuration layer to display. Valid
|
||||
configuration layers are "user", "system" and "default". To display
|
||||
configurations for different channels, set the default_channel
|
||||
configuration variable and run config-show again.
|
||||
',
|
||||
),
|
||||
'config-get' => array(
|
||||
'summary' => 'Show One Setting',
|
||||
'function' => 'doConfigGet',
|
||||
'shortcut' => 'cg',
|
||||
'options' => array(
|
||||
'channel' => array(
|
||||
'shortopt' => 'c',
|
||||
'doc' => 'show configuration variables for another channel',
|
||||
'arg' => 'CHAN',
|
||||
),
|
||||
),
|
||||
'doc' => '<parameter> [layer]
|
||||
Displays the value of one configuration parameter. The
|
||||
first argument is the name of the parameter, an optional second argument
|
||||
may be used to tell which configuration layer to look in. Valid configuration
|
||||
layers are "user", "system" and "default". If no layer is specified, a value
|
||||
will be picked from the first layer that defines the parameter, in the order
|
||||
just specified. The configuration value will be retrieved for the channel
|
||||
specified by the default_channel configuration variable.
|
||||
',
|
||||
),
|
||||
'config-set' => array(
|
||||
'summary' => 'Change Setting',
|
||||
'function' => 'doConfigSet',
|
||||
'shortcut' => 'cs',
|
||||
'options' => array(
|
||||
'channel' => array(
|
||||
'shortopt' => 'c',
|
||||
'doc' => 'show configuration variables for another channel',
|
||||
'arg' => 'CHAN',
|
||||
),
|
||||
),
|
||||
'doc' => '<parameter> <value> [layer]
|
||||
Sets the value of one configuration parameter. The first argument is
|
||||
the name of the parameter, the second argument is the new value. Some
|
||||
parameters are subject to validation, and the command will fail with
|
||||
an error message if the new value does not make sense. An optional
|
||||
third argument may be used to specify in which layer to set the
|
||||
configuration parameter. The default layer is "user". The
|
||||
configuration value will be set for the current channel, which
|
||||
is controlled by the default_channel configuration variable.
|
||||
',
|
||||
),
|
||||
'config-help' => array(
|
||||
'summary' => 'Show Information About Setting',
|
||||
'function' => 'doConfigHelp',
|
||||
'shortcut' => 'ch',
|
||||
'options' => array(),
|
||||
'doc' => '[parameter]
|
||||
Displays help for a configuration parameter. Without arguments it
|
||||
displays help for all configuration parameters.
|
||||
',
|
||||
),
|
||||
'config-create' => array(
|
||||
'summary' => 'Create a Default configuration file',
|
||||
'function' => 'doConfigCreate',
|
||||
'shortcut' => 'coc',
|
||||
'options' => array(
|
||||
'windows' => array(
|
||||
'shortopt' => 'w',
|
||||
'doc' => 'create a config file for a windows install',
|
||||
),
|
||||
),
|
||||
'doc' => '<root path> <filename>
|
||||
Create a default configuration file with all directory configuration
|
||||
variables set to subdirectories of <root path>, and save it as <filename>.
|
||||
This is useful especially for creating a configuration file for a remote
|
||||
PEAR installation (using the --remoteconfig option of install, upgrade,
|
||||
and uninstall).
|
||||
',
|
||||
),
|
||||
);
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* PEAR_Command_Config constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PEAR_Command_Config(&$ui, &$config)
|
||||
{
|
||||
parent::PEAR_Command_Common($ui, $config);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ doConfigShow()
|
||||
|
||||
function doConfigShow($command, $options, $params)
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$layer = isset($params[0]) ? $params[0] : NULL;
|
||||
} else {
|
||||
$layer = NULL;
|
||||
}
|
||||
|
||||
// $params[0] -> the layer
|
||||
if ($error = $this->_checkLayer($layer)) {
|
||||
return $this->raiseError("config-show:$error");
|
||||
}
|
||||
$keys = $this->config->getKeys();
|
||||
sort($keys);
|
||||
$channel = isset($options['channel']) ? $options['channel'] :
|
||||
$this->config->get('default_channel');
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (!$reg->channelExists($channel)) {
|
||||
return $this->raiseError('Channel "' . $channel . '" does not exist');
|
||||
}
|
||||
$data = array('caption' => 'Configuration (channel ' . $channel . '):');
|
||||
foreach ($keys as $key) {
|
||||
$type = $this->config->getType($key);
|
||||
$value = $this->config->get($key, $layer, $channel);
|
||||
if ($type == 'password' && $value) {
|
||||
$value = '********';
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = 'false';
|
||||
} elseif ($value === true) {
|
||||
$value = 'true';
|
||||
}
|
||||
$data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
|
||||
}
|
||||
foreach ($this->config->getLayers() as $layer) {
|
||||
$data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer));
|
||||
}
|
||||
|
||||
$this->ui->outputData($data, $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doConfigGet()
|
||||
|
||||
function doConfigGet($command, $options, $params)
|
||||
{
|
||||
if (!is_array($params)) {
|
||||
$args_cnt = 0;
|
||||
} else {
|
||||
$args_cnt = count($params);
|
||||
}
|
||||
|
||||
switch ($args_cnt) {
|
||||
case 1:
|
||||
$config_key = $params[0];
|
||||
$layer = NULL;
|
||||
break;
|
||||
case 2:
|
||||
$config_key = $params[0];
|
||||
$layer = $params[1];
|
||||
if ($error = $this->_checkLayer($layer)) {
|
||||
return $this->raiseError("config-get:$error");
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
return $this->raiseError("config-get expects 1 or 2 parameters");
|
||||
}
|
||||
|
||||
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
|
||||
$reg = &$this->config->getRegistry();
|
||||
|
||||
if (!$reg->channelExists($channel)) {
|
||||
return $this->raiseError('Channel "' . $channel . '" does not exist');
|
||||
}
|
||||
|
||||
$this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doConfigSet()
|
||||
|
||||
function doConfigSet($command, $options, $params)
|
||||
{
|
||||
// $param[0] -> a parameter to set
|
||||
// $param[1] -> the value for the parameter
|
||||
// $param[2] -> the layer
|
||||
$failmsg = '';
|
||||
if (sizeof($params) < 2 || sizeof($params) > 3) {
|
||||
$failmsg .= "config-set expects 2 or 3 parameters";
|
||||
return PEAR::raiseError($failmsg);
|
||||
}
|
||||
if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) {
|
||||
$failmsg .= $error;
|
||||
return PEAR::raiseError("config-set:$failmsg");
|
||||
}
|
||||
$channel = isset($options['channel']) ? $options['channel'] :
|
||||
$this->config->get('default_channel');
|
||||
$reg = &$this->config->getRegistry();
|
||||
if (!$reg->channelExists($channel)) {
|
||||
return $this->raiseError('Channel "' . $channel . '" does not exist');
|
||||
}
|
||||
if ($params[0] == 'default_channel') {
|
||||
if (!$reg->channelExists($params[1])) {
|
||||
return $this->raiseError('Channel "' . $params[1] . '" does not exist');
|
||||
}
|
||||
}
|
||||
if (count($params) == 2) {
|
||||
array_push($params, 'user');
|
||||
$layer = 'user';
|
||||
} else {
|
||||
$layer = $params[2];
|
||||
}
|
||||
array_push($params, $channel);
|
||||
if (!call_user_func_array(array(&$this->config, 'set'), $params))
|
||||
{
|
||||
array_pop($params);
|
||||
$failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel";
|
||||
} else {
|
||||
$this->config->store($layer);
|
||||
}
|
||||
if ($failmsg) {
|
||||
return $this->raiseError($failmsg);
|
||||
}
|
||||
$this->ui->outputData('config-set succeeded', $command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doConfigHelp()
|
||||
|
||||
function doConfigHelp($command, $options, $params)
|
||||
{
|
||||
if (empty($params)) {
|
||||
$params = $this->config->getKeys();
|
||||
}
|
||||
$data['caption'] = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
|
||||
$data['headline'] = array('Name', 'Type', 'Description');
|
||||
$data['border'] = true;
|
||||
foreach ($params as $name) {
|
||||
$type = $this->config->getType($name);
|
||||
$docs = $this->config->getDocs($name);
|
||||
if ($type == 'set') {
|
||||
$docs = rtrim($docs) . "\nValid set: " .
|
||||
implode(' ', $this->config->getSetValues($name));
|
||||
}
|
||||
$data['data'][] = array($name, $type, $docs);
|
||||
}
|
||||
$this->ui->outputData($data, $command);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ doConfigCreate()
|
||||
|
||||
function doConfigCreate($command, $options, $params)
|
||||
{
|
||||
if (count($params) != 2) {
|
||||
return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
|
||||
'filename to save as');
|
||||
}
|
||||
$root = $params[0];
|
||||
// Clean up the DIRECTORY_SEPARATOR mess
|
||||
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
|
||||
$root = preg_replace(array('!\\\\+!', '!/+!', "!$ds2+!"),
|
||||
array('/', '/', '/'),
|
||||
$root);
|
||||
if ($root{0} != '/') {
|
||||
if (isset($options['windows'])) {
|
||||
if (!preg_match('/^[A-Za-z]:/', $root)) {
|
||||
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
|
||||
'with "\\" or "C:\\", was: "' . $root . '"');
|
||||
}
|
||||
} else {
|
||||
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
|
||||
'with "/", was: "' . $root . '"');
|
||||
}
|
||||
}
|
||||
$windows = isset($options['windows']);
|
||||
if ($windows) {
|
||||
$root = str_replace('/', '\\', $root);
|
||||
}
|
||||
if (!file_exists($params[1])) {
|
||||
if (!@touch($params[1])) {
|
||||
return PEAR::raiseError('Could not create "' . $params[1] . '"');
|
||||
}
|
||||
}
|
||||
$params[1] = realpath($params[1]);
|
||||
$config = &new PEAR_Config($params[1], '#no#system#config#', false, false);
|
||||
if ($root{strlen($root) - 1} == '/') {
|
||||
$root = substr($root, 0, strlen($root) - 1);
|
||||
}
|
||||
$config->noRegistry();
|
||||
$config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user');
|
||||
$config->set('data_dir', $windows ? "$root\\pear\\data" : "$root/pear/data");
|
||||
$config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext");
|
||||
$config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs");
|
||||
$config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests");
|
||||
$config->set('cache_dir', $windows ? "$root\\pear\\cache" : "$root/pear/cache");
|
||||
$config->set('bin_dir', $windows ? "$root\\pear" : "$root/pear");
|
||||
$config->writeConfigFile();
|
||||
$this->_showConfig($config);
|
||||
$this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"',
|
||||
$command);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function _showConfig(&$config)
|
||||
{
|
||||
$params = array('user');
|
||||
$keys = $config->getKeys();
|
||||
sort($keys);
|
||||
$channel = 'pear.php.net';
|
||||
$data = array('caption' => 'Configuration (channel ' . $channel . '):');
|
||||
foreach ($keys as $key) {
|
||||
$type = $config->getType($key);
|
||||
$value = $config->get($key, 'user', $channel);
|
||||
if ($type == 'password' && $value) {
|
||||
$value = '********';
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = 'false';
|
||||
} elseif ($value === true) {
|
||||
$value = 'true';
|
||||
}
|
||||
$data['data'][$config->getGroup($key)][] =
|
||||
array($config->getPrompt($key) , $key, $value);
|
||||
}
|
||||
foreach ($config->getLayers() as $layer) {
|
||||
$data['data']['Config Files'][] =
|
||||
array(ucfirst($layer) . ' Configuration File', 'Filename' ,
|
||||
$config->getConfFile($layer));
|
||||
}
|
||||
|
||||
$this->ui->outputData($data, 'config-show');
|
||||
return true;
|
||||
}
|
||||
// {{{ _checkLayer()
|
||||
|
||||
/**
|
||||
* Checks if a layer is defined or not
|
||||
*
|
||||
* @param string $layer The layer to search for
|
||||
* @return mixed False on no error or the error message
|
||||
*/
|
||||
function _checkLayer($layer = null)
|
||||
{
|
||||
if (!empty($layer) && $layer != 'default') {
|
||||
$layers = $this->config->getLayers();
|
||||
if (!in_array($layer, $layers)) {
|
||||
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
92
PEAR/Command/Config.xml
Normal file
92
PEAR/Command/Config.xml
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<commands version="1.0">
|
||||
<config-show>
|
||||
<summary>Show All Settings</summary>
|
||||
<function>doConfigShow</function>
|
||||
<shortcut>csh</shortcut>
|
||||
<options>
|
||||
<channel>
|
||||
<shortopt>c</shortopt>
|
||||
<doc>show configuration variables for another channel</doc>
|
||||
<arg>CHAN</arg>
|
||||
</channel>
|
||||
</options>
|
||||
<doc>[layer]
|
||||
Displays all configuration values. An optional argument
|
||||
may be used to tell which configuration layer to display. Valid
|
||||
configuration layers are "user", "system" and "default". To display
|
||||
configurations for different channels, set the default_channel
|
||||
configuration variable and run config-show again.
|
||||
</doc>
|
||||
</config-show>
|
||||
<config-get>
|
||||
<summary>Show One Setting</summary>
|
||||
<function>doConfigGet</function>
|
||||
<shortcut>cg</shortcut>
|
||||
<options>
|
||||
<channel>
|
||||
<shortopt>c</shortopt>
|
||||
<doc>show configuration variables for another channel</doc>
|
||||
<arg>CHAN</arg>
|
||||
</channel>
|
||||
</options>
|
||||
<doc><parameter> [layer]
|
||||
Displays the value of one configuration parameter. The
|
||||
first argument is the name of the parameter, an optional second argument
|
||||
may be used to tell which configuration layer to look in. Valid configuration
|
||||
layers are "user", "system" and "default". If no layer is specified, a value
|
||||
will be picked from the first layer that defines the parameter, in the order
|
||||
just specified. The configuration value will be retrieved for the channel
|
||||
specified by the default_channel configuration variable.
|
||||
</doc>
|
||||
</config-get>
|
||||
<config-set>
|
||||
<summary>Change Setting</summary>
|
||||
<function>doConfigSet</function>
|
||||
<shortcut>cs</shortcut>
|
||||
<options>
|
||||
<channel>
|
||||
<shortopt>c</shortopt>
|
||||
<doc>show configuration variables for another channel</doc>
|
||||
<arg>CHAN</arg>
|
||||
</channel>
|
||||
</options>
|
||||
<doc><parameter> <value> [layer]
|
||||
Sets the value of one configuration parameter. The first argument is
|
||||
the name of the parameter, the second argument is the new value. Some
|
||||
parameters are subject to validation, and the command will fail with
|
||||
an error message if the new value does not make sense. An optional
|
||||
third argument may be used to specify in which layer to set the
|
||||
configuration parameter. The default layer is "user". The
|
||||
configuration value will be set for the current channel, which
|
||||
is controlled by the default_channel configuration variable.
|
||||
</doc>
|
||||
</config-set>
|
||||
<config-help>
|
||||
<summary>Show Information About Setting</summary>
|
||||
<function>doConfigHelp</function>
|
||||
<shortcut>ch</shortcut>
|
||||
<options />
|
||||
<doc>[parameter]
|
||||
Displays help for a configuration parameter. Without arguments it
|
||||
displays help for all configuration parameters.
|
||||
</doc>
|
||||
</config-help>
|
||||
<config-create>
|
||||
<summary>Create a Default configuration file</summary>
|
||||
<function>doConfigCreate</function>
|
||||
<shortcut>coc</shortcut>
|
||||
<options>
|
||||
<windows>
|
||||
<shortopt>w</shortopt>
|
||||
<doc>create a config file for a windows install</doc>
|
||||
</windows>
|
||||
</options>
|
||||
<doc><root path> <filename>
|
||||
Create a default configuration file with all directory configuration
|
||||
variables set to subdirectories of <root path>, and save it as <filename>.
|
||||
This is useful especially for creating a configuration file for a remote
|
||||
PEAR installation (using the --remoteconfig option of install, upgrade,
|
||||
and uninstall).
|
||||
</doc>
|
||||
</config-create>
|
||||
</commands>
|
||||
1038
PEAR/Command/Install.php
Normal file
1038
PEAR/Command/Install.php
Normal file
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue