PageRenderTime 63ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/console/libs/tasks/extract.php

https://github.com/samanz/cakecart
PHP | 683 lines | 457 code | 46 blank | 180 comment | 129 complexity | a763b6cc900f93eaddc91a1b4b74e0d6 MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id: extract.php 7296 2008-06-27 09:09:03Z gwoo $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc.
  12. * 1785 E. Sahara Avenue, Suite 490-204
  13. * Las Vegas, Nevada 89104
  14. *
  15. * Licensed under The MIT License
  16. * Redistributions of files must retain the above copyright notice.
  17. *
  18. * @filesource
  19. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
  20. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21. * @package cake
  22. * @subpackage cake.cake.console.libs
  23. * @since CakePHP(tm) v 1.2.0.5012
  24. * @version $Revision: 7296 $
  25. * @modifiedby $LastChangedBy: gwoo $
  26. * @lastmodified $Date: 2008-06-27 02:09:03 -0700 (Fri, 27 Jun 2008) $
  27. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  28. */
  29. /**
  30. * Only used when -debug option
  31. */
  32. ob_start();
  33. $singularReturn = __('Singular string return __()', true);
  34. $singularEcho = __('Singular string echo __()');
  35. $pluralReturn = __n('% apple in the bowl (plural string return __n())', '% apples in the blowl (plural string 2 return __n())', 3, true);
  36. $pluralEcho = __n('% apple in the bowl (plural string 2 echo __n())', '% apples in the blowl (plural string 2 echo __n()', 3);
  37. $singularDomainReturn = __d('controllers', 'Singular string domain lookup return __d()', true);
  38. $singularDomainEcho = __d('controllers', 'Singular string domain lookup echo __d()');
  39. $pluralDomainReturn = __dn('controllers', '% pears in the bowl (plural string domain lookup return __dn())', '% pears in the blowl (plural string domain lookup return __dn())', 3, true);
  40. $pluralDomainEcho = __dn('controllers', '% pears in the bowl (plural string domain lookup echo __dn())', '% pears in the blowl (plural string domain lookup echo __dn())', 3);
  41. $singularDomainCategoryReturn = __dc('controllers', 'Singular string domain and category lookup return __dc()', 5, true);
  42. $singularDomainCategoryEcho = __dc('controllers', 'Singular string domain and category lookup echo __dc()', 5);
  43. $pluralDomainCategoryReturn = __dcn('controllers', '% apple in the bowl (plural string 1 domain and category lookup return __dcn())', '% apples in the blowl (plural string 2 domain and category lookup return __dcn())', 3, 5, true);
  44. $pluralDomainCategoryEcho = __dcn('controllers', '% apple in the bowl (plural string 1 domain and category lookup echo __dcn())', '% apples in the blowl (plural string 2 domain and category lookup echo __dcn())', 3, 5);
  45. $categoryReturn = __c('Category string lookup line return __c()', 5, true);
  46. $categoryEcho = __c('Category string lookup line echo __c()', 5);
  47. ob_end_clean();
  48. /**
  49. * Language string extractor
  50. *
  51. * @package cake
  52. * @subpackage cake.cake.console.libs
  53. */
  54. class ExtractTask extends Shell{
  55. /**
  56. * Path to use when looking for strings
  57. *
  58. * @var string
  59. * @access public
  60. */
  61. var $path = null;
  62. /**
  63. * Files from where to extract
  64. *
  65. * @var array
  66. * @access public
  67. */
  68. var $files = array();
  69. /**
  70. * Filename where to deposit translations
  71. *
  72. * @var string
  73. * @access private
  74. */
  75. var $__filename = 'default';
  76. /**
  77. * True if all strings should be merged into one file
  78. *
  79. * @var boolean
  80. * @access private
  81. */
  82. var $__oneFile = true;
  83. /**
  84. * Current file being processed
  85. *
  86. * @var string
  87. * @access private
  88. */
  89. var $__file = null;
  90. /**
  91. * Extracted tokens
  92. *
  93. * @var array
  94. * @access private
  95. */
  96. var $__tokens = array();
  97. /**
  98. * Extracted strings
  99. *
  100. * @var array
  101. * @access private
  102. */
  103. var $__strings = array();
  104. /**
  105. * History of file versions
  106. *
  107. * @var array
  108. * @access private
  109. */
  110. var $__fileVersions = array();
  111. /**
  112. * Destination path
  113. *
  114. * @var string
  115. * @access private
  116. */
  117. var $__output = null;
  118. /**
  119. * Execution method always used for tasks
  120. *
  121. * @access public
  122. */
  123. function execute() {
  124. if (isset($this->params['files']) && !is_array($this->params['files'])) {
  125. $this->files = explode(',', $this->params['files']);
  126. }
  127. if (isset($this->params['path'])) {
  128. $this->path = $this->params['path'];
  129. } else {
  130. $response = '';
  131. while ($response == '') {
  132. $response = $this->in("What is the full path you would like to extract?\nExample: " . $this->params['root'] . DS . "myapp\n[Q]uit", null, 'Q');
  133. if (strtoupper($response) === 'Q') {
  134. $this->out('Extract Aborted');
  135. $this->_stop();
  136. }
  137. }
  138. if (is_dir($response)) {
  139. $this->path = $response;
  140. } else {
  141. $this->err('The directory path you supplied was not found. Please try again.');
  142. $this->execute();
  143. }
  144. }
  145. if (isset($this->params['debug'])) {
  146. $this->path = ROOT;
  147. $this->files = array(__FILE__);
  148. }
  149. if (isset($this->params['output'])) {
  150. $this->__output = $this->params['output'];
  151. } else {
  152. $response = '';
  153. while ($response == '') {
  154. $response = $this->in("What is the full path you would like to output?\nExample: " . $this->path . DS . "locale\n[Q]uit", null, $this->path . DS . "locale");
  155. if (strtoupper($response) === 'Q') {
  156. $this->out('Extract Aborted');
  157. $this->_stop();
  158. }
  159. }
  160. if (is_dir($response)) {
  161. $this->__output = $response . DS;
  162. } else {
  163. $this->err('The directory path you supplied was not found. Please try again.');
  164. $this->execute();
  165. }
  166. }
  167. if (empty($this->files)) {
  168. $this->files = $this->__searchDirectory();
  169. }
  170. $this->__extract();
  171. }
  172. /**
  173. * Extract text
  174. *
  175. * @access private
  176. */
  177. function __extract() {
  178. $this->out('');
  179. $this->out('');
  180. $this->out(__('Extracting...', true));
  181. $this->hr();
  182. $this->out(__('Path: ', true). $this->path);
  183. $this->out(__('Output Directory: ', true). $this->__output);
  184. $this->hr();
  185. $response = '';
  186. $filename = '';
  187. while ($response == '') {
  188. $response = $this->in(__('Would you like to merge all translations into one file?', true), array('y','n'), 'y');
  189. if (strtolower($response) == 'n') {
  190. $this->__oneFile = false;
  191. } else {
  192. while ($filename == '') {
  193. $filename = $this->in(__('What should we name this file?', true), null, $this->__filename);
  194. if ($filename == '') {
  195. $this->out(__('The filesname you supplied was empty. Please try again.', true));
  196. }
  197. }
  198. $this->__filename = $filename;
  199. }
  200. }
  201. $this->__extractTokens();
  202. }
  203. /**
  204. * Show help options
  205. *
  206. * @access public
  207. */
  208. function help() {
  209. $this->out(__('CakePHP Language String Extraction:', true));
  210. $this->hr();
  211. $this->out(__('The Extract script generates .pot file(s) with translations', true));
  212. $this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true));
  213. $this->out(__('By default -app is ROOT/app', true));
  214. $this->hr();
  215. $this->out(__('usage: cake i18n extract [command] [path...]', true));
  216. $this->out('');
  217. $this->out(__('commands:', true));
  218. $this->out(__(' -app [path...]: directory where your application is located', true));
  219. $this->out(__(' -root [path...]: path to install', true));
  220. $this->out(__(' -core [path...]: path to cake directory', true));
  221. $this->out(__(' -path [path...]: Full path to directory to extract strings', true));
  222. $this->out(__(' -output [path...]: Full path to output directory', true));
  223. $this->out(__(' -files: [comma separated list of files, full path to file is needed]', true));
  224. $this->out(__(' cake i18n extract help: Shows this help message.', true));
  225. $this->out(__(' -debug: Perform self test.', true));
  226. $this->out('');
  227. }
  228. /**
  229. * Extract tokens out of all files to be processed
  230. *
  231. * @access private
  232. */
  233. function __extractTokens() {
  234. foreach ($this->files as $file) {
  235. $this->__file = $file;
  236. $this->out(sprintf(__('Processing %s...', true), $file));
  237. $code = file_get_contents($file);
  238. $this->__findVersion($code, $file);
  239. $allTokens = token_get_all($code);
  240. $this->__tokens = array();
  241. $lineNumber = 1;
  242. foreach ($allTokens as $token) {
  243. if ((!is_array($token)) || (($token[0] != T_WHITESPACE) && ($token[0] != T_INLINE_HTML))) {
  244. if (is_array($token)) {
  245. $token[] = $lineNumber;
  246. }
  247. $this->__tokens[] = $token;
  248. }
  249. if (is_array($token)) {
  250. $lineNumber += count(split("\n", $token[1])) - 1;
  251. } else {
  252. $lineNumber += count(split("\n", $token)) - 1;
  253. }
  254. }
  255. unset($allTokens);
  256. $this->basic();
  257. $this->basic('__c');
  258. $this->extended();
  259. $this->extended('__dc', 2);
  260. $this->extended('__n', 0, true);
  261. $this->extended('__dn', 2, true);
  262. $this->extended('__dcn', 4, true);
  263. }
  264. $this->__buildFiles();
  265. $this->__writeFiles();
  266. $this->out('Done.');
  267. }
  268. /**
  269. * Will parse __(), __c() functions
  270. *
  271. * @param string $functionName Function name that indicates translatable string (e.g: '__')
  272. * @access public
  273. */
  274. function basic($functionName = '__') {
  275. $count = 0;
  276. $tokenCount = count($this->__tokens);
  277. while (($tokenCount - $count) > 3) {
  278. list($countToken, $parenthesis, $middle, $right) = array($this->__tokens[$count], $this->__tokens[$count + 1], $this->__tokens[$count + 2], $this->__tokens[$count + 3]);
  279. if (!is_array($countToken)) {
  280. $count++;
  281. continue;
  282. }
  283. list($type, $string, $line) = $countToken;
  284. if (($type == T_STRING) && ($string == $functionName) && ($parenthesis == '(')) {
  285. if (in_array($right, array(')', ','))
  286. && (is_array($middle) && ($middle[0] == T_CONSTANT_ENCAPSED_STRING))) {
  287. if ($this->__oneFile === true) {
  288. $this->__strings[$this->__formatString($middle[1])][$this->__file][] = $line;
  289. } else {
  290. $this->__strings[$this->__file][$this->__formatString($middle[1])][] = $line;
  291. }
  292. } else {
  293. $this->__markerError($this->__file, $line, $functionName, $count);
  294. }
  295. }
  296. $count++;
  297. }
  298. }
  299. /**
  300. * Will parse __d(), __dc(), __n(), __dn(), __dcn()
  301. *
  302. * @param string $functionName Function name that indicates translatable string (e.g: '__')
  303. * @param integer $shift Number of parameters to shift to find translateable string
  304. * @param boolean $plural Set to true if function supports plural format, false otherwise
  305. * @access public
  306. */
  307. function extended($functionName = '__d', $shift = 0, $plural = false) {
  308. $count = 0;
  309. $tokenCount = count($this->__tokens);
  310. while (($tokenCount - $count) > 7) {
  311. list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]);
  312. if (!is_array($countToken)) {
  313. $count++;
  314. continue;
  315. }
  316. list($type, $string, $line) = $countToken;
  317. if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis == '(')) {
  318. $position = $count;
  319. $depth = 0;
  320. while ($depth == 0) {
  321. if ($this->__tokens[$position] == '(') {
  322. $depth++;
  323. } elseif ($this->__tokens[$position] == ')') {
  324. $depth--;
  325. }
  326. $position++;
  327. }
  328. if ($plural) {
  329. $end = $position + $shift + 7;
  330. if ($this->__tokens[$position + $shift + 5] === ')') {
  331. $end = $position + $shift + 5;
  332. }
  333. if (empty($shift)) {
  334. list($singular, $firstComma, $plural, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$end]);
  335. $condition = ($seoncdComma == ',');
  336. } else {
  337. list($domain, $firstComma, $singular, $seoncdComma, $plural, $comma3, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $this->__tokens[$position + 3], $this->__tokens[$position + 4], $this->__tokens[$position + 5], $this->__tokens[$end]);
  338. $condition = ($comma3 == ',');
  339. }
  340. $condition = $condition &&
  341. (is_array($singular) && ($singular[0] == T_CONSTANT_ENCAPSED_STRING)) &&
  342. (is_array($plural) && ($plural[0] == T_CONSTANT_ENCAPSED_STRING));
  343. } else {
  344. if ($this->__tokens[$position + $shift + 5] === ')') {
  345. $comma = $this->__tokens[$position + $shift + 3];
  346. $end = $position + $shift + 5;
  347. } else {
  348. $comma = null;
  349. $end = $position + $shift + 3;
  350. }
  351. list($domain, $firstComma, $text, $seoncdComma, $endParenthesis) = array($this->__tokens[$position], $this->__tokens[$position + 1], $this->__tokens[$position + 2], $comma, $this->__tokens[$end]);
  352. $condition = ($seoncdComma == ',' || $seoncdComma === null) &&
  353. (is_array($domain) && ($domain[0] == T_CONSTANT_ENCAPSED_STRING)) &&
  354. (is_array($text) && ($text[0] == T_CONSTANT_ENCAPSED_STRING));
  355. }
  356. if (($endParenthesis == ')') && $condition) {
  357. if ($this->__oneFile === true) {
  358. if ($plural) {
  359. $this->__strings[$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][$this->__file][] = $line;
  360. } else {
  361. $this->__strings[$this->__formatString($text[1])][$this->__file][] = $line;
  362. }
  363. } else {
  364. if ($plural) {
  365. $this->__strings[$this->__file][$this->__formatString($singular[1]) . "\0" . $this->__formatString($plural[1])][] = $line;
  366. } else {
  367. $this->__strings[$this->__file][$this->__formatString($text[1])][] = $line;
  368. }
  369. }
  370. } else {
  371. $this->__markerError($this->__file, $line, $functionName, $count);
  372. }
  373. }
  374. $count++;
  375. }
  376. }
  377. /**
  378. * Build the translate template file contents out of obtained strings
  379. *
  380. * @access private
  381. */
  382. function __buildFiles() {
  383. foreach ($this->__strings as $str => $fileInfo) {
  384. $output = '';
  385. $occured = $fileList = array();
  386. if ($this->__oneFile === true) {
  387. foreach ($fileInfo as $file => $lines) {
  388. $occured[] = "$file:" . join(';', $lines);
  389. if (isset($this->__fileVersions[$file])) {
  390. $fileList[] = $this->__fileVersions[$file];
  391. }
  392. }
  393. $occurances = join("\n#: ", $occured);
  394. $occurances = str_replace($this->path, '', $occurances);
  395. $output = "#: $occurances\n";
  396. $filename = $this->__filename;
  397. if (strpos($str, "\0") === false) {
  398. $output .= "msgid \"$str\"\n";
  399. $output .= "msgstr \"\"\n";
  400. } else {
  401. list($singular, $plural) = explode("\0", $str);
  402. $output .= "msgid \"$singular\"\n";
  403. $output .= "msgid_plural \"$plural\"\n";
  404. $output .= "msgstr[0] \"\"\n";
  405. $output .= "msgstr[1] \"\"\n";
  406. }
  407. $output .= "\n";
  408. } else {
  409. foreach ($fileInfo as $file => $lines) {
  410. $filename = $str;
  411. $occured = array("$str:" . join(';', $lines));
  412. if (isset($this->__fileVersions[$str])) {
  413. $fileList[] = $this->__fileVersions[$str];
  414. }
  415. $occurances = join("\n#: ", $occured);
  416. $occurances = str_replace($this->path, '', $occurances);
  417. $output .= "#: $occurances\n";
  418. if (strpos($file, "\0") === false) {
  419. $output .= "msgid \"$file\"\n";
  420. $output .= "msgstr \"\"\n";
  421. } else {
  422. list($singular, $plural) = explode("\0", $file);
  423. $output .= "msgid \"$singular\"\n";
  424. $output .= "msgid_plural \"$plural\"\n";
  425. $output .= "msgstr[0] \"\"\n";
  426. $output .= "msgstr[1] \"\"\n";
  427. }
  428. $output .= "\n";
  429. }
  430. }
  431. $this->__store($filename, $output, $fileList);
  432. }
  433. }
  434. /**
  435. * Prepare a file to be stored
  436. *
  437. * @param string $file Filename
  438. * @param string $input What to store
  439. * @param array $fileList File list
  440. * @param integer $get Set to 1 to get files to store, false to set
  441. * @return mixed If $get == 1, files to store, otherwise void
  442. * @access private
  443. */
  444. function __store($file = 0, $input = 0, $fileList = array(), $get = 0) {
  445. static $storage = array();
  446. if (!$get) {
  447. if (isset($storage[$file])) {
  448. $storage[$file][1] = array_unique(array_merge($storage[$file][1], $fileList));
  449. $storage[$file][] = $input;
  450. } else {
  451. $storage[$file] = array();
  452. $storage[$file][0] = $this->__writeHeader();
  453. $storage[$file][1] = $fileList;
  454. $storage[$file][2] = $input;
  455. }
  456. } else {
  457. return $storage;
  458. }
  459. }
  460. /**
  461. * Write the files that need to be stored
  462. *
  463. * @access private
  464. */
  465. function __writeFiles() {
  466. $output = $this->__store(0, 0, array(), 1);
  467. $output = $this->__mergeFiles($output);
  468. foreach ($output as $file => $content) {
  469. $tmp = str_replace(array($this->path, '.php','.ctp','.thtml', '.inc','.tpl' ), '', $file);
  470. $tmp = str_replace(DS, '.', $tmp);
  471. $file = str_replace('.', '-', $tmp) .'.pot';
  472. $fileList = $content[1];
  473. unset($content[1]);
  474. $fileList = str_replace(array($this->path), '', $fileList);
  475. if (count($fileList) > 1) {
  476. $fileList = "Generated from files:\n# " . join("\n# ", $fileList);
  477. } elseif (count($fileList) == 1) {
  478. $fileList = 'Generated from file: ' . join('', $fileList);
  479. } else {
  480. $fileList = 'No version information was available in the source files.';
  481. }
  482. if (is_file($this->__output . $file)) {
  483. $response = '';
  484. while ($response == '') {
  485. $response = $this->in("\n\nError: ".$file . ' already exists in this location. Overwrite?', array('y','n', 'q'), 'n');
  486. if (strtoupper($response) === 'Q') {
  487. $this->out('Extract Aborted');
  488. $this->_stop();
  489. } elseif (strtoupper($response) === 'N') {
  490. $response = '';
  491. while ($response == '') {
  492. $response = $this->in("What would you like to name this file?\nExample: new_" . $file, null, "new_" . $file);
  493. $file = $response;
  494. }
  495. }
  496. }
  497. }
  498. $fp = fopen($this->__output . $file, 'w');
  499. fwrite($fp, str_replace('--VERSIONS--', $fileList, join('', $content)));
  500. fclose($fp);
  501. }
  502. }
  503. /**
  504. * Merge output files
  505. *
  506. * @param array $output Output to merge
  507. * @return array Merged output
  508. * @access private
  509. */
  510. function __mergeFiles($output) {
  511. foreach ($output as $file => $content) {
  512. if (count($content) <= 1 && $file != $this->__filename) {
  513. @$output[$this->__filename][1] = array_unique(array_merge($output[$this->__filename][1], $content[1]));
  514. if (!isset($output[$this->__filename][0])) {
  515. $output[$this->__filename][0] = $content[0];
  516. }
  517. unset($content[0]);
  518. unset($content[1]);
  519. foreach ($content as $msgid) {
  520. $output[$this->__filename][] = $msgid;
  521. }
  522. unset($output[$file]);
  523. }
  524. }
  525. return $output;
  526. }
  527. /**
  528. * Build the translation template header
  529. *
  530. * @return string Translation template header
  531. * @access private
  532. */
  533. function __writeHeader() {
  534. $output = "# LANGUAGE translation of CakePHP Application\n";
  535. $output .= "# Copyright YEAR NAME <EMAIL@ADDRESS>\n";
  536. $output .= "# --VERSIONS--\n";
  537. $output .= "#\n";
  538. $output .= "#, fuzzy\n";
  539. $output .= "msgid \"\"\n";
  540. $output .= "msgstr \"\"\n";
  541. $output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
  542. $output .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
  543. $output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
  544. $output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
  545. $output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
  546. $output .= "\"MIME-Version: 1.0\\n\"\n";
  547. $output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
  548. $output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
  549. $output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n";
  550. return $output;
  551. }
  552. /**
  553. * Find the version number of a file looking for SVN commands
  554. *
  555. * @param string $code Source code of file
  556. * @param string $file File
  557. * @access private
  558. */
  559. function __findVersion($code, $file) {
  560. $header = '$Id' . ':';
  561. if (preg_match('/\\' . $header . ' [\\w.]* ([\\d]*)/', $code, $versionInfo)) {
  562. $version = str_replace(ROOT, '', 'Revision: ' . $versionInfo[1] . ' ' .$file);
  563. $this->__fileVersions[$file] = $version;
  564. }
  565. }
  566. /**
  567. * Format a string to be added as a translateable string
  568. *
  569. * @param string $string String to format
  570. * @return string Formatted string
  571. * @access private
  572. */
  573. function __formatString($string) {
  574. $quote = substr($string, 0, 1);
  575. $string = substr($string, 1, -1);
  576. if ($quote == '"') {
  577. $string = stripcslashes($string);
  578. } else {
  579. $string = strtr($string, array("\\'" => "'", "\\\\" => "\\"));
  580. }
  581. return addcslashes($string, "\0..\37\\\"");
  582. }
  583. /**
  584. * Indicate an invalid marker on a processed file
  585. *
  586. * @param string $file File where invalid marker resides
  587. * @param integer $line Line number
  588. * @param string $marker Marker found
  589. * @param integer $count Count
  590. * @access private
  591. */
  592. function __markerError($file, $line, $marker, $count) {
  593. $this->out("Invalid marker content in $file:$line\n* $marker(", true);
  594. $count += 2;
  595. $tokenCount = count($this->__tokens);
  596. $parenthesis = 1;
  597. while ((($tokenCount - $count) > 0) && $parenthesis) {
  598. if (is_array($this->__tokens[$count])) {
  599. $this->out($this->__tokens[$count][1], false);
  600. } else {
  601. $this->out($this->__tokens[$count], false);
  602. if ($this->__tokens[$count] == '(') {
  603. $parenthesis++;
  604. }
  605. if ($this->__tokens[$count] == ')') {
  606. $parenthesis--;
  607. }
  608. }
  609. $count++;
  610. }
  611. $this->out("\n", true);
  612. }
  613. /**
  614. * Search the specified path for files that may contain translateable strings
  615. *
  616. * @param string $path Path (or set to null to use current)
  617. * @return array Files
  618. * @access private
  619. */
  620. function __searchDirectory($path = null) {
  621. if ($path === null) {
  622. $path = $this->path .DS;
  623. }
  624. $files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE);
  625. $dirs = glob("$path*", GLOB_ONLYDIR);
  626. foreach ($dirs as $dir) {
  627. if (!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) {
  628. $files = array_merge($files, $this->__searchDirectory("$dir" . DS));
  629. if (($id = array_search($dir . DS . 'extract.php', $files)) !== FALSE) {
  630. unset($files[$id]);
  631. }
  632. }
  633. }
  634. return $files;
  635. }
  636. }
  637. ?>