summaryrefslogtreecommitdiff
path: root/it_text.class
diff options
context:
space:
mode:
authorChristian Schneider2008-05-09 12:35:20 +0000
committerChristian Schneider2008-05-09 12:35:20 +0000
commite158abb0132f50b14327a3ddf69f7f0d75fcc88d (patch)
tree5f3393e6b85012adaccadc6588cd689ff6354524 /it_text.class
parent99a45216ecec35e631f232c6bfc36fdcd7222ffe (diff)
downloaditools-e158abb0132f50b14327a3ddf69f7f0d75fcc88d.tar.gz
itools-e158abb0132f50b14327a3ddf69f7f0d75fcc88d.tar.bz2
itools-e158abb0132f50b14327a3ddf69f7f0d75fcc88d.zip
Code cleanup, adds new parameter phpfiles as side-effect
Diffstat (limited to 'it_text.class')
-rw-r--r--it_text.class22
1 files changed, 11 insertions, 11 deletions
diff --git a/it_text.class b/it_text.class
index c920941..247369d 100644
--- a/it_text.class
+++ b/it_text.class
@@ -35,21 +35,25 @@ class it_text
* @param $p['forcelanguage'] optional language to use instead of user's preferred language
* @param $p['global'] store text object in global it_text for global functions (default: true)
* @param $p['phpfile'] optional texts file(s), default: all texts.php in include path
+ * @param $p['phpfiles'] text files to load in addition to $p['phpfile'] (Note: $p['phpfile'] defaults to all texts.php files in include path)
*/
function it_text($p = array())
{
if (!$p['phpfile'])
{
# Find all texts.php in path (abs path in case we need to save)
- foreach (array_unique(explode(PATH_SEPARATOR, ini_get('include_path'))) as $dir)
+ foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $dir)
if (file_exists($phpfile = "$dir/texts.php"))
- $p['phpfile'][] = $phpfile;
+ $p['phpfiles'][] = $phpfile;
}
- $this->p = ($p += array('global' => true));
+ $this->p = ($p += array(
+ 'global' => true,
+ 'phpfiles' => array_unique(array_merge((array)$p['phpfiles'], (array)$p['phpfile'])),
+ ));
# Read and merge texts from php files if none defined yet
- foreach ((array)$p['phpfile'] as $phpfile)
+ foreach ($p['phpfiles'] as $phpfile)
{
$oldtext = $this->statictext;
if (is_array($ret = include($phpfile)))
@@ -231,15 +235,11 @@ function dump_php()
$result = false;
# Special sorting: natural, but _ is the first entry
- $keys = array_keys($this->statictext);
- natsort($keys);
- foreach ($keys as $key)
- $text[$key] = $this->statictext[$key];
- $this->statictext = array_merge(array('_' => $text['_']), $text);
+ uksort($this->statictext, "strnatcmp");
+ $this->statictext = array_merge(array('_' => $this->statictext['_']), $this->statictext);
$oldmask = umask(002);
- $phpfiles = (array)$this->p['phpfile'];
- if ($f = fopen(count($phpfiles) == 1 ? $phpfiles[0] : null, 'w'))
+ if ((count($this->p['phpfiles']) == 1) && ($f = fopen($this->p['phpfiles'][0], 'w')))
{
$result = (fputs($f, '<?php return ' . strtr(var_export($this->statictext, true), array("=> \n array (" => "=> array(", "array (\n '_'" => "array(\n'_'", "\n ),\n " => "\n),\n", "\n ),\n" => "\n),\n", "\r" => "")) . ";\n?>\n") !== false);
fclose($f);