PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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