Cheetah
ChLang.php
Go to the documentation of this file.
1 <?php
2 
8 // language compiling class
9 
10 class ChLang
11 {
12  var $_sLang = 'en';
13  var $_sSkin = 'default';
14  var $_iVisualProcessing = true;
15 
16  function __construct ($sLang, $sSkin)
17  {
18  $this->_sLang = $sLang;
19  $this->_sSkin = preg_replace ('#_\w{2}$#', '', $sSkin);
20  }
21 
22  function setVisualProcessing ($i)
23  {
24  $this->_iVisualProcessing = $i;
25  }
26 
27  function compile ()
28  {
29  $ret = $this->_copyFromOrig ();
30 
31  $this->_cleanJsCache ();
32 
33  return $ret;
34  }
35 
36  function _cleanJsCache ()
37  {
38  global $gConf;
39 
40  if (isset($gConf['dir']['cache'])) {
41  $d = dir($gConf['dir']['cache']);
42 
43  while (FALSE !== ($entry = $d->read())) {
44  if ($entry == '.' || $entry == '..') {
45  continue;
46  }
47 
48  @unlink ($gConf['dir']['cache'] . $entry);
49  }
50 
51  }
52  }
53 
54  function _copyFromOrig ()
55  {
56  global $gConf;
57 
58  // copy base
59  if (!$this->_fullCopy ($gConf['dir']['layouts'] . 'base', $gConf['dir']['layouts'] . 'base_' . $this->_sLang))
60  return false;
61 
62  // copy skins
63  $sDirSkin = $gConf['dir']['layouts'] . $this->_sSkin;
64  if (!$this->_fullCopy ($sDirSkin, $sDirSkin . '_' . $this->_sLang))
65  return false;
66 
67  // copy classes
68  $sDirClasses = preg_replace ('#classes/\w{2}/$#', 'classes/', $gConf['dir']['classes']);
69  if (!$this->_fullCopy ($sDirClasses, $sDirClasses . $this->_sLang, false))
70  return false;
71 
72  // copy javascripts
73  $sDirJs = preg_replace ('#js/\w{2}/$#', 'js/', $gConf['dir']['js']);
74  if (!$this->_fullCopy ($sDirJs, $sDirJs . $this->_sLang, false))
75  return false;
76 
77  return true;
78  }
79 
80  function _replaceVars ($sFilePath)
81  {
82  $s = $this->_fileGetContents ($sFilePath);
83 
84  $sExt = substr($sFilePath, -4);
85 
86  if ('.xsl' == $sExt || '.php' == $sExt || '.js' == substr($sFilePath, -3)) {
87  $this->_replaceLangs ($s);
88  }
89 
90  if ('.xsl' == $sExt || '.php' == $sExt || '.css' == $sExt) {
91  $this->_replacePatches ($s);
92  }
93 
94  if ('loader.php' == substr($sFilePath, -10)) {
95  $s = str_replace ("'..'","'../..'", $s);
96  }
97 
98  $this->_filePutContents ($sFilePath, $s);
99 
100  if ($this->_iVisualProcessing)
101  echo ".";
102  }
103 
104  function _replacePatches (&$s)
105  {
106  $s = str_replace (
107  array(
108  'base/',
109  $this->_sSkin . '/'
110  ),
111  array(
112  'base_' . $this->_sLang . '/',
113  $this->_sSkin . '_' . $this->_sLang . '/'
114  ),
115  $s);
116  }
117 
118  function _langReplaceHandler ($m)
119  {
120  return getLangString($m[1], $this->_sLang);
121  }
122 
123  function _replaceLangs (&$s)
124  {
125  $s = preg_replace_callback ('#\[L\[(.*?)\]\]#', array($this, '_langReplaceHandler'), $s);
126  }
127 
128  function _fullCopy ($source, $target, $recursively = true)
129  {
130  if (is_dir($source)) {
131  @mkdir($target, 0777);
132  @chmod($target, 0777);
133 
134  $d = dir($source);
135 
136  while (FALSE !== ($entry = $d->read())) {
137  if ($entry == '.' || $entry == '..') {
138  continue;
139  }
140 
141  $Entry = $source . '/' . $entry;
142  if (is_dir($Entry)) {
143  if ($recursively) {
144  if (!$this->_fullCopy($Entry, $target . '/' . $entry))
145  return false;
146  }
147  } else {
148  if (!copy($Entry, $target . '/' . $entry))
149  return false;
150  @chmod($target . '/' . $entry, 0666);
151  $this->_replaceVars ($target . '/' . $entry);
152  }
153  }
154 
155  $d->close();
156  } else {
157  if (!copy($source, $target))
158  return false;
159  @chmod($target, 0666);
160  $this->_replaceVars ($target);
161  }
162 
163  return true;
164  }
165 
166  function _fileGetContents ($sFilePath)
167  {
168  return file_get_contents ($sFilePath);
169  }
170 
171  function _filePutContents ($sFilePath, $s)
172  {
173  $f = fopen ($sFilePath, 'w');
174  if (!$f) return false;
175  fwrite ($f, $s);
176  fclose($f);
177  return true;
178  }
179 }
180 
181 ?>
ChLang\setVisualProcessing
setVisualProcessing($i)
Definition: ChLang.php:22
$f
global $f
Definition: callback.php:13
getLangString
getLangString($s, $sLang='')
Definition: lang.php:12
$ret
$ret
Definition: index.php:39
ChLang\_langReplaceHandler
_langReplaceHandler($m)
Definition: ChLang.php:118
php
$sExt
$sExt
Definition: get_file.php:14
ChLang\compile
compile()
Definition: ChLang.php:27
ChLang\_filePutContents
_filePutContents($sFilePath, $s)
Definition: ChLang.php:171
copy
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy
Definition: license.txt:50
ChLang\__construct
__construct($sLang, $sSkin)
Definition: ChLang.php:16
ChLang\_fileGetContents
_fileGetContents($sFilePath)
Definition: ChLang.php:166
ChLang\_replaceVars
_replaceVars($sFilePath)
Definition: ChLang.php:80
ChLang
Definition: ChLang.php:11
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChLang\_replacePatches
_replacePatches(&$s)
Definition: ChLang.php:104
ChLang\_replaceLangs
_replaceLangs(&$s)
Definition: ChLang.php:123
ChLang\_cleanJsCache
_cleanJsCache()
Definition: ChLang.php:36
ChLang\$_sSkin
$_sSkin
Definition: ChLang.php:13
$s
$s
Definition: embed.php:13
ChLang\_copyFromOrig
_copyFromOrig()
Definition: ChLang.php:54
ChLang\$_iVisualProcessing
$_iVisualProcessing
Definition: ChLang.php:14
$sSkin
$sSkin
Definition: actions.inc.php:18
$gConf
global $gConf
Definition: header.inc.php:8
ChLang\_fullCopy
_fullCopy($source, $target, $recursively=true)
Definition: ChLang.php:128
ChLang\$_sLang
$_sLang
Definition: ChLang.php:12