PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

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