mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
now the files entites are generated dynamically
This commit is contained in:
@@ -3,6 +3,9 @@ dnl $Id$
|
||||
dnl autoconf initialisation
|
||||
AC_INIT()
|
||||
WORKDIR=`pwd`
|
||||
SRCDIR=$srcdir
|
||||
AC_SUBST(SRCDIR)
|
||||
|
||||
AC_SUBST(WORKDIR)
|
||||
|
||||
dnl debug output
|
||||
@@ -217,7 +220,6 @@ AC_SUBST(CATALOG)
|
||||
|
||||
dnl }}}
|
||||
|
||||
|
||||
dnl {{{ language specific stuff
|
||||
|
||||
AC_MSG_CHECKING(for language)
|
||||
@@ -297,4 +299,21 @@ done
|
||||
AC_OUTPUT($OUTFILES)
|
||||
dnl }}}
|
||||
|
||||
dnl {{{ generate entity mapping file, missing entities and IDs
|
||||
|
||||
dnl if we have PHP use it for all of these things
|
||||
if test $PHP != "no"
|
||||
then
|
||||
|
||||
dnl create entity mapping file
|
||||
$PHP -c $INIPATH -q ./scripts/file-entities.php
|
||||
|
||||
else
|
||||
|
||||
echo ERROR: configure process cannot continue, PHP is not found
|
||||
|
||||
fi
|
||||
|
||||
dnl }}}
|
||||
|
||||
dnl }}}
|
||||
|
@@ -19,30 +19,9 @@
|
||||
|
||||
%global.entities;
|
||||
|
||||
<!ENTITY bookinfo SYSTEM "@LANG@/bookinfo.xml">
|
||||
<!ENTITY preface SYSTEM "@LANG@/preface.xml">
|
||||
<!ENTITY getting.started SYSTEM "@LANG@/getting-started.xml">
|
||||
<!ENTITY % file.entities SYSTEM "entities/file-entities.ent">
|
||||
|
||||
<!ENTITY language.basic.syntax SYSTEM "@LANG@/designers/language-basic-syntax.xml">
|
||||
<!ENTITY language.variables SYSTEM "@LANG@/designers/language-variables.xml">
|
||||
<!ENTITY language.modifiers SYSTEM "@LANG@/designers/language-modifiers.xml">
|
||||
<!ENTITY language.combining.modifiers SYSTEM "@LANG@/designers/language-combining-modifiers.xml">
|
||||
<!ENTITY language.builtin.functions SYSTEM "@LANG@/designers/language-builtin-functions.xml">
|
||||
<!ENTITY language.custom.functions SYSTEM "@LANG@/designers/language-custom-functions.xml">
|
||||
<!ENTITY config.files SYSTEM "@LANG@/designers/config-files.xml">
|
||||
<!ENTITY chapter.debugging.console SYSTEM "@LANG@/designers/chapter-debugging-console.xml">
|
||||
|
||||
<!ENTITY smarty.constants SYSTEM "@LANG@/programmers/smarty-constants.xml">
|
||||
<!ENTITY api.variables SYSTEM "@LANG@/programmers/api-variables.xml">
|
||||
<!ENTITY api.functions SYSTEM "@LANG@/programmers/api-functions.xml">
|
||||
<!ENTITY caching SYSTEM "@LANG@/programmers/caching.xml">
|
||||
<!ENTITY advanced.features SYSTEM "@LANG@/programmers/advanced-features.xml">
|
||||
<!ENTITY plugins SYSTEM "@LANG@/programmers/plugins.xml">
|
||||
|
||||
<!ENTITY troubleshooting SYSTEM "@LANG@/appendixes/troubleshooting.xml">
|
||||
<!ENTITY tips SYSTEM "@LANG@/appendixes/tips.xml">
|
||||
<!ENTITY resources SYSTEM "@LANG@/appendixes/resources.xml">
|
||||
<!ENTITY bugs SYSTEM "@LANG@/appendixes/bugs.xml">
|
||||
%file.entities;
|
||||
|
||||
]>
|
||||
|
||||
@@ -52,37 +31,37 @@
|
||||
|
||||
&bookinfo;
|
||||
&preface;
|
||||
&getting.started;
|
||||
&getting-started;
|
||||
|
||||
<part id="smarty.for.designers">
|
||||
<title>&SMARTYDesigners;</title>
|
||||
|
||||
&language.basic.syntax;
|
||||
&language.variables;
|
||||
&language.modifiers;
|
||||
&language.combining.modifiers;
|
||||
&language.builtin.functions;
|
||||
&language.custom.functions;
|
||||
&config.files;
|
||||
&chapter.debugging.console;
|
||||
&designers.language-basic-syntax;
|
||||
&designers.language-variables;
|
||||
&designers.language-modifiers;
|
||||
&designers.language-combining-modifiers;
|
||||
&designers.language-builtin-functions;
|
||||
&designers.language-custom-functions;
|
||||
&designers.config-files;
|
||||
&designers.chapter-debugging-console;
|
||||
</part>
|
||||
|
||||
<part id="smarty.for.programmers">
|
||||
<title>&SMARTYProgrammers;</title>
|
||||
|
||||
&smarty.constants;
|
||||
&api.variables;
|
||||
&api.functions;
|
||||
&caching;
|
||||
&advanced.features;
|
||||
&plugins;
|
||||
&programmers.smarty-constants;
|
||||
&programmers.api-variables;
|
||||
&programmers.api-functions;
|
||||
&programmers.caching;
|
||||
&programmers.advanced-features;
|
||||
&programmers.plugins;
|
||||
</part>
|
||||
|
||||
<part id="appendixes">
|
||||
<title>&Appendixes;</title>
|
||||
&troubleshooting;
|
||||
&tips;
|
||||
&resources;
|
||||
&bugs;
|
||||
&appendixes.troubleshooting;
|
||||
&appendixes.tips;
|
||||
&appendixes.resources;
|
||||
&appendixes.bugs;
|
||||
</part>
|
||||
</book>
|
||||
|
314
docs/scripts/file-entities.php.in
Normal file
314
docs/scripts/file-entities.php.in
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2004 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.0 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| 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 world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Hartmut Holzgraefe <hholzgra@php.net> |
|
||||
| Gabor Hojtsy <goba@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Create smarty/docs/entities/file-entities.ent with respect
|
||||
* to all the specialities needed:
|
||||
*
|
||||
* . CHM only appendix integration
|
||||
* . Translated language files with English ones as fallbacks
|
||||
*
|
||||
* Also take in account, that if XSLT style sheets are used,
|
||||
* special file:/// prefixed path values are needed.
|
||||
*
|
||||
*/
|
||||
|
||||
// Always flush output
|
||||
ob_implicit_flush();
|
||||
// This script runs for a long time
|
||||
set_time_limit(0);
|
||||
|
||||
// ......:ARGUMENT PARSING:.....................................................
|
||||
|
||||
// when php complied on cygwin, the working path have to be /cygdrive..
|
||||
// the below preg_replace have to be done only using binary php complied on MSVC.
|
||||
// let's find if php was complied by cygwin:
|
||||
$cygwin_complied = eregi("CYGWIN",php_uname()) ? true : false;
|
||||
|
||||
// The output directory, which we need to parse for windows specific
|
||||
// things, and correct all problems is needed.
|
||||
// Also use absolute path to have meaningful error messages
|
||||
$out_dir = abs_path(strip_cygdrive("@WORKDIR@"));
|
||||
|
||||
// this path if used for saving the ent file:
|
||||
$script_out_dir = $cygwin_complied ? "@WORKDIR@" : $out_dir;
|
||||
|
||||
// The source directory is passed in the 5th argument counting from backwards.
|
||||
$srcdir = abs_path("@SRCDIR@");
|
||||
|
||||
// The translation dir is passed as the 6th argument, counting
|
||||
// from the end of the argument list
|
||||
$trans_dir = "$srcdir/@LANG@";
|
||||
|
||||
// The original directory is in the base directory, and named "en"
|
||||
$orig_dir = "$srcdir/en";
|
||||
|
||||
// ......:ENTITY CREATION:......................................................
|
||||
|
||||
// Put all the file entitites info $entities
|
||||
$entities = array();
|
||||
file_entities($orig_dir, $trans_dir, $orig_dir, $entities);
|
||||
|
||||
// Open file for appending and write out all entitities
|
||||
$fp = fopen("$script_out_dir/entities/file-entities.ent", "w");
|
||||
if (!$fp) {
|
||||
die("ERROR: Failed to open $script_out_dir/entities/file-entities.ent for writing\n");
|
||||
}
|
||||
|
||||
echo "\ncreating entities/file-entities.ent...\n";
|
||||
|
||||
// File header
|
||||
fputs($fp, "<!-- DON'T TOUCH - AUTOGENERATED BY file-entities.php -->\n\n");
|
||||
|
||||
|
||||
// Write out all other entities
|
||||
foreach ($entities as $entity) {
|
||||
fputs($fp, $entity);
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
// Here is the end of the code
|
||||
exit;
|
||||
|
||||
// ......:FUNCTION DECLARATIONS:................................................
|
||||
|
||||
/**
|
||||
* Generate absolute path from a relative path, taking accout
|
||||
* the current wokring directory.
|
||||
*
|
||||
* @param string $path Relative path
|
||||
* @return string Absolute path generated
|
||||
*/
|
||||
function abs_path($path) {
|
||||
|
||||
// This is already an absolute path (begins with / or a drive letter)
|
||||
if (preg_match("!^(/|\\w:)!", $path)) { return $path; }
|
||||
|
||||
// Get directory parts
|
||||
|
||||
$absdir = str_replace("\\", "/", getcwd());
|
||||
$absdirs = explode("/", preg_replace("!/scripts$!", "", $absdir));
|
||||
$dirs = explode("/", $path);
|
||||
|
||||
// Generate array representation of absolute path
|
||||
foreach ($dirs as $dir) {
|
||||
if (empty($dir) or $dir == ".") continue;
|
||||
else if ($dir == "..") array_pop($absdirs);
|
||||
else array_push($absdirs, $dir);
|
||||
}
|
||||
|
||||
// Return with string
|
||||
return join("/", $absdirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create file entities, and put them into the array passed as the
|
||||
* last argument (passed by reference).
|
||||
*
|
||||
* @param string $work_dir English files' directory
|
||||
* @param string $trans_dir Translation's directory
|
||||
* @param string $orig_dir Original directory
|
||||
* @param array $entities Entities string array
|
||||
* @return boolean Success signal
|
||||
*/
|
||||
function file_entities($work_dir, $trans_dir, $orig_dir, &$entities) {
|
||||
|
||||
// Skip the function directory not under "reference". That
|
||||
// folder is only kept for backward compatibility and only
|
||||
// in the English version of the docs.
|
||||
if (strpos($work_dir, "functions") && !preg_match("!reference/.*/functions!", $work_dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute translated version's path
|
||||
$trans_path = str_replace($orig_dir, $trans_dir, $work_dir);
|
||||
|
||||
// Try to open English working directory
|
||||
$dh = opendir($work_dir);
|
||||
if (!$dh) { return FALSE; }
|
||||
|
||||
// If the working directory is a reference functions directory
|
||||
if (preg_match("!/reference/.*/functions$!", $work_dir)) {
|
||||
|
||||
// Start new functions file with empty entity set
|
||||
$function_entities = array();
|
||||
$functions_file = "$work_dir.xml";
|
||||
|
||||
// Get relative file path to original directory, and form an entity
|
||||
$functions_file_entity = str_replace("$orig_dir/", "", $work_dir);
|
||||
$functions_file_entity = fname2entname($functions_file_entity);
|
||||
$entities[] = entstr($functions_file_entity, $functions_file);
|
||||
}
|
||||
|
||||
// While we can read that directory
|
||||
while (($file = readdir($dh)) !== FALSE) {
|
||||
|
||||
// If file name begins with . skip it
|
||||
if ($file{0} == ".") { continue; }
|
||||
|
||||
// If we found a directory, and it's name is not
|
||||
// CVS, recursively go into it, and generate entities
|
||||
if (is_dir($work_dir . "/" . $file)) {
|
||||
if ($file == "CVS") { continue; }
|
||||
file_entities($work_dir . "/" . $file, $trans_dir, $orig_dir, $entities);
|
||||
}
|
||||
|
||||
// If the file name ends in ".xml"
|
||||
if (preg_match("!\\.xml$!", $file)) {
|
||||
|
||||
// Get relative file name and get entity name for it
|
||||
$name = str_replace(
|
||||
"$orig_dir/",
|
||||
"",
|
||||
$work_dir . "/" . preg_replace("!\\.xml$!", "", $file)
|
||||
);
|
||||
$name = fname2entname($name);
|
||||
|
||||
// If this is a functions directory, collect it into
|
||||
// the special $function_entities array
|
||||
if (isset($function_entities)) {
|
||||
$function_entities[] = "&$name;";
|
||||
}
|
||||
|
||||
// Special treatment for function reference entities if splitted version available
|
||||
if (strstr($work_dir,"/functions")) {
|
||||
$splitfile = str_replace(".xml", "/reference.xml", $file);
|
||||
$splitpath = str_replace("/functions", "/reference", $trans_path) . "/" . $splitfile;
|
||||
if (file_exists($splitpath)) {
|
||||
$entities[] = entstr($name, $splitpath);
|
||||
continue;
|
||||
}
|
||||
$splitpath = str_replace("/functions", "/reference", $trans_path) . "/" . $splitfile;
|
||||
if (file_exists($splitpath)) {
|
||||
$entities[] = entstr($name, $splitpath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a translated file, use it, otherwise fall back to English
|
||||
if (file_exists("$trans_path/$file")) {
|
||||
$path = "$trans_path/$file";
|
||||
} else {
|
||||
$path = "$work_dir/$file";
|
||||
}
|
||||
|
||||
// Append to entities array
|
||||
$entities[] = entstr($name, $path);
|
||||
|
||||
} // end of "if xml file"
|
||||
} // end of readdir loop
|
||||
|
||||
// Close directory
|
||||
closedir($dh);
|
||||
|
||||
// If we created a function entities list, write it out
|
||||
if (isset($function_entities)) {
|
||||
|
||||
// Sort by name
|
||||
sort($function_entities);
|
||||
|
||||
// Write out all entities with newlines
|
||||
$fp = fopen($functions_file, "w");
|
||||
foreach ($function_entities as $entity) {
|
||||
fputs($fp, "$entity\n");
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
// Find all files available in the translation but not in the original English tree
|
||||
if ($orig_dir != $trans_dir && file_exists($trans_path) && is_dir($trans_path)) {
|
||||
|
||||
// Open translation path
|
||||
$dh = @opendir($trans_path);
|
||||
|
||||
if ($dh) {
|
||||
|
||||
while (($file = readdir($dh)) !== FALSE) {
|
||||
if ($file{0} =="." || $file == "CVS") { continue; }
|
||||
if (is_dir($trans_path."/".$file)) { continue; }
|
||||
|
||||
// If this is an XML file
|
||||
if (preg_match("!\\.xml$!",$file)) {
|
||||
|
||||
// Generate relative file path and entity name out of it
|
||||
$name = str_replace(
|
||||
"$orig_dir/",
|
||||
"",
|
||||
$work_dir . "/" . preg_replace("!\\.xml$!", "", $file)
|
||||
);
|
||||
$name = fname2entname($name);
|
||||
|
||||
// If the file found is not in the English dir, append to entities list
|
||||
if (!file_exists("$work_dir/$file")) {
|
||||
$path = "$trans_path/$file";
|
||||
$entities[] = entstr($name, $path);
|
||||
}
|
||||
|
||||
} // if this is an XML file end
|
||||
|
||||
} // readdir iteration end
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
} // end of funciton file_entities()
|
||||
|
||||
/**
|
||||
* Convert a file name (with path) to an entity name.
|
||||
*
|
||||
* Converts: _ => - and / => .
|
||||
*
|
||||
* @param string $fname File name
|
||||
* @return string Entity name
|
||||
*/
|
||||
function fname2entname($fname)
|
||||
{
|
||||
return str_replace("_", "-", str_replace("/", ".", $fname));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return entity string with the given entityname and filename.
|
||||
*
|
||||
* @param string $entname Entity name
|
||||
* @param string $filename Name of file
|
||||
* @return string Entity declaration string
|
||||
*/
|
||||
function entstr($entname, $filename)
|
||||
{
|
||||
// If we have no file, than this is not a system entity
|
||||
if ($filename == "") {
|
||||
return sprintf("<!ENTITY %-40s ''>\n", $entname);
|
||||
} else {
|
||||
return sprintf("<!ENTITY %-40s SYSTEM '%s'>\n", $entname, strip_cygdrive($filename));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return windows style path for cygwin.
|
||||
*
|
||||
* @param string $path Orginal path
|
||||
*/
|
||||
function strip_cygdrive($path){
|
||||
return preg_replace("!^/cygdrive/(\\w)/!", "\\1:/", $path);
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user