PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

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