PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/develop/create_variable_overview.php

http://github.com/phpbb/phpbb3
PHP | 545 lines | 464 code | 45 blank | 36 comment | 27 complexity | 89254d71bddae0b49533cbb3a8f6a88f MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * This script generates an index of some template vars and their use within the templates.
  15. * It writes down all language variables used by various templates.
  16. */
  17. //
  18. // Security message:
  19. //
  20. // This script is potentially dangerous.
  21. // Remove or comment the next line (die(".... ) to enable this script.
  22. // Do NOT FORGET to either remove this script or disable it after you have used it.
  23. //
  24. die("Please read the first lines of this script for instructions on how to enable it");
  25. $directory = '../styles/subSilver/template/';
  26. $ext = 'html';
  27. $store_dir = '../store/';
  28. $phpfiles_directories = array('../', '../includes/', '../includes/acm/', '../includes/auth/', '../includes/mcp/', '../includes/ucp/');
  29. // Template Files beginning with this names are merged together
  30. $merge = array('gcp', 'login', 'mcp', 'memberlist', 'posting', 'ucp');
  31. if (!is_writable($store_dir))
  32. {
  33. die("Directory $store_dir is not writable!");
  34. }
  35. $contents = implode('', file('../adm/subSilver.css', filesize('../adm/subSilver.css')));
  36. $fp = fopen($store_dir . 'subSilver.css', 'w');
  37. fwrite($fp, $contents);
  38. fclose($fp);
  39. $html_skeleton = '
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <link rel="stylesheet" href="subSilver.css" type="text/css">
  44. <style type="text/css">
  45. <!--
  46. th { background-image: url(\'cellpic3.gif\') }
  47. td.cat { background-image: url(\'cellpic1.gif\') }
  48. //-->
  49. </style>
  50. <title>{FILENAME}</title>
  51. </head>
  52. <body>
  53. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  54. <tr>
  55. <td><img src="header_left.jpg" width="200" height="60" alt="phpBB Logo" title="phpBB Logo" border="0"/></td>
  56. <td width="100%" background="header_bg.jpg" height="60" align="right" nowrap="nowrap"><span class="maintitle">File {FILENAME}</span> &nbsp; &nbsp; &nbsp;</td>
  57. </tr>
  58. </table>
  59. <table width="95%" cellspacing="0" cellpadding="0" border="0" align="center">
  60. <tr>
  61. <td><br clear="all" />
  62. ';
  63. $html_skeleton .= '<br><a href="./index.html" class="gen">Back to Contents</a><br><br>';
  64. $html_skeleton .= '<br><a href="#lang" class="gen">Language Variables</a> :: <a href="#includes" class="gen">Includes</a> :: <a href="#cond" class="gen">Conditionals</a><br><a href="#remain" class="gen">Remaining Vars</a> :: <a href="#usedby" class="gen">phpBB File Usage</a> :: <a href="#ref" class="gen">References</a>';
  65. $html_skeleton .= '<br><br><a name="lang"></a><b>Language Variables</b><br><br>{LANGUAGE_VARIABLES}';
  66. $html_skeleton .= '<br><br><a name="includes"></a><b>Included Files</b><br><br>{INCLUDES}';
  67. $html_skeleton .= '<br><br><a name="cond"></a><b>Used Conditionals</b><br><br>{CONDITIONALS}';
  68. $html_skeleton .= '<br><br><a name="remain"></a><b>Remaining Vars used</b><br><br>{REMAINING_VARS}';
  69. $html_skeleton .= '<br><br><a name="usedby"></a><b>This Template File is used by the following phpBB Files</b><br><br>{USED_BY}';
  70. $html_skeleton .= '<br><br><a name="ref"></a><b>References: </b>{SEE_FILES}';
  71. //$html_skeleton .= "</body>\n</html>\n";
  72. $html_skeleton .= '
  73. <br><br>
  74. <div class="copyright" align="center">Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited</div>
  75. <br clear="all" /></td>
  76. </tr>
  77. </table>
  78. </body>
  79. </html>
  80. ';
  81. // Open Language File
  82. include('../language/en/lang_main.php');
  83. include('../language/en/lang_admin.php');
  84. $files_to_parse = $php_files = array();
  85. $dhandler = opendir($directory);
  86. if (!$dhandler)
  87. {
  88. die("Unable to open $directory");
  89. }
  90. $num = 0;
  91. while ($file = readdir($dhandler))
  92. {
  93. if (is_file($directory . $file) && preg_match('#\.' . $ext . '$#i', $file))
  94. {
  95. $files_to_parse[$num]['filename'] = $directory . $file;
  96. $files_to_parse[$num]['single_filename'] = $file;
  97. $files_to_parse[$num]['destfile'] = str_replace(".{$ext}", '', $file) . '_' . $num . '.html';
  98. $file_to_destfile[$file] = $files_to_parse[$num]['destfile'];
  99. $num++;
  100. }
  101. }
  102. closedir($dhandler);
  103. $num = 0;
  104. foreach ($phpfiles_directories as $directory)
  105. {
  106. $dhandler = opendir($directory);
  107. if (!$dhandler)
  108. {
  109. die("Unable to open $directory");
  110. }
  111. while ($file = readdir($dhandler))
  112. {
  113. if (is_file($directory . $file) && preg_match('#\.php$#i', $file))
  114. {
  115. $php_files[$num]['filename'] = $directory . $file;
  116. $php_files[$num]['single_filename'] = $file;
  117. $num++;
  118. }
  119. }
  120. closedir($dhandler);
  121. }
  122. $php_files_includes = $lang_references = array();
  123. //$php_files_includes['viewtopic_attach_body.html'][0] = filename
  124. echo '<br>Parsing PHP Files';
  125. // Parse PHP Files and get our filenames
  126. foreach ($php_files as $file_num => $data)
  127. {
  128. echo '.';
  129. flush();
  130. $contents = implode('', file($data['filename'], filesize($data['filename'])));
  131. $html_files = array();
  132. preg_match_all('#([a-zA-Z0-9\-_]*?)\.' . $ext . '#s', $contents, $html_files);
  133. $html_files = array_unique($html_files[1]);
  134. foreach ($html_files as $html_file)
  135. {
  136. $html_file = trim($html_file);
  137. if ($html_file != '')
  138. {
  139. $php_files_includes[$html_file . '.' . $ext][] = $data['filename'];
  140. }
  141. }
  142. }
  143. echo '<br>Parsing HTML Files';
  144. foreach ($files_to_parse as $file_num => $data)
  145. {
  146. echo '.';
  147. flush();
  148. $contents = implode('', file($data['filename'], filesize($data['filename'])));
  149. // Language Variables -> [0]:tpl [1]:lang
  150. $lang_vars = array();
  151. preg_match_all('#{L_([a-z0-9\-_]*?)\}#is', $contents, $lang_vars);
  152. $contents = preg_replace('#{L_([a-z0-9\-_]*?)\}#is', '', $contents);
  153. $lang_vars[0] = array_unique($lang_vars[0]);
  154. $lang_vars[1] = array_unique($lang_vars[1]);
  155. // Includes
  156. $includes = array();
  157. preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#s', $contents, $includes);
  158. $contents = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', '', $contents);
  159. $includes = $includes[1];
  160. $includes = array_unique($includes);
  161. // IF Conditions
  162. $switches = array();
  163. preg_match_all('#<!-- [IF]|[ELSEIF] ([a-zA-Z0-9\-_\.]+?) (.*?)?[ ]?-->#', $contents, $switches);
  164. $contents = preg_replace('#<!-- [IF]|[ELSEIF] ([a-zA-Z0-9\-_]) (.*?)?[ ]?-->#s', '', $contents);
  165. $switches[0] = array_unique($switches[1]); // No resorting please
  166. $switches[1] = $switches[2];
  167. unset($switches[2]);
  168. // Remaining Vars
  169. $remaining_vars = array();
  170. preg_match_all('#{([a-z0-9\-_\.]*?)\}#is', $contents, $remaining_vars);
  171. $contents = preg_replace('#{([a-z0-9\-_]*?)\}#is', '', $contents);
  172. $remaining_vars = array_unique($remaining_vars[1]);
  173. sort($remaining_vars, SORT_STRING);
  174. // Now build the filename specific site
  175. $fp = fopen($store_dir . $data['destfile'], 'w');
  176. $html_data = $html_skeleton;
  177. $html_data = str_replace('{FILENAME}', $data['single_filename'], $html_data);
  178. // Write up the Language Variables
  179. if (count($lang_vars[0]))
  180. {
  181. $lang_data = '<ul>';
  182. for ($num = 0; $num <= count($lang_vars[0]); $num++)
  183. {
  184. $var = $lang_vars[0][$num];
  185. if ($var != '')
  186. {
  187. $_var = str_replace(array('{', '}'), array('', ''), $var);
  188. $lang_references[$_var][] = $data['single_filename'];
  189. $lang_data .= '<li>' . $var . '<br>' . "\n" . ((isset($lang[$_var])) ? htmlspecialchars(str_replace("\\'", "'", $lang[$_var])) : '<span style="color:red">No Language Variable available</span>') . '<br></li><br>' . "\n";
  190. }
  191. }
  192. $lang_data .= '</ul>';
  193. }
  194. else
  195. {
  196. $lang_data = '<b>NONE</b><br>' . "\n";
  197. }
  198. $html_data = str_replace('{LANGUAGE_VARIABLES}', $lang_data, $html_data);
  199. // Write up the Includes
  200. echo '.';
  201. flush();
  202. if (count($includes))
  203. {
  204. $includes_data = '<ul>';
  205. $see_files = '';
  206. for ($num = 0; $num <= count($includes); $num++)
  207. {
  208. $var = $includes[$num];
  209. if ($var != '')
  210. {
  211. $includes_data .= '<li><a href="./' . $file_to_destfile[$var] . '" class="gen">' . $var . '</a></li><br>' . "\n";
  212. $see_files .= ($see_files != '') ? ' :: ' : '';
  213. $see_files .= '<a href="./' . $file_to_destfile[$var] . '" class="gen">' . $var . '</a>';
  214. }
  215. }
  216. $includes_data .= '</ul>';
  217. }
  218. else
  219. {
  220. $includes_data = '<b>NONE</b><br>' . "\n";
  221. $see_files = '<b>NONE</b>';
  222. }
  223. $html_data = str_replace('{INCLUDES}', $includes_data, $html_data);
  224. $html_data = str_replace('{SEE_FILES}', $see_files, $html_data);
  225. // Write up Conditionals
  226. echo '.';
  227. flush();
  228. if (count($switches[0]))
  229. {
  230. $conditionals = '<ul>';
  231. for ($num = 0; $num <= count($switches[0]); $num++)
  232. {
  233. $var = trim($switches[0][$num]);
  234. if ($var != '')
  235. {
  236. if ($var == 'not')
  237. {
  238. $conditionals .= '<li>' . trim($switches[1][$num]) . '<br><b>Negation</b><br>' . "\n";
  239. $block_var = explode('.', trim($switches[1][$num]));
  240. unset($block_var[0]);
  241. }
  242. else
  243. {
  244. $conditionals .= '<li>' . $var . ((trim($switches[1][$num]) != '') ? '<br>' . "\n" . '<i>Compared with</i> -&gt; <b>' . trim($switches[1][$num]) . '</b>' : '') . '<br>' . "\n";
  245. $block_var = explode('.', $var);
  246. unset($block_var[count($block_var)-1]);
  247. }
  248. if (count($block_var))
  249. {
  250. for ($_num = count($block_var)-1; $_num >= 0; $_num--)
  251. {
  252. $conditionals .= ($_num == count($block_var)-1) ? '<i>Element of Block</i> -&gt; <b>' . $block_var[$_num] . '</b><br>' . "\n" : '<i>...which is an element of</i> -&gt; <b>' . $block_var[$_num] . '</b><br>' . "\n";
  253. }
  254. }
  255. $conditionals .= '<br></li>' . "\n";
  256. }
  257. }
  258. $conditionals .= '</ul>';
  259. }
  260. else
  261. {
  262. $conditionals = '<b>NONE</b><br>' . "\n";
  263. }
  264. $html_data = str_replace('{CONDITIONALS}', $conditionals, $html_data);
  265. // Write up Remaining Vars
  266. echo '.';
  267. flush();
  268. if (count($remaining_vars))
  269. {
  270. $remaining = '<ul>';
  271. for ($num = 0; $num <= count($remaining_vars); $num++)
  272. {
  273. $var = trim($remaining_vars[$num]);
  274. if ($var != '')
  275. {
  276. $remaining .= '<li>' . $var . '<br>' . "\n";
  277. $block_var = explode('.', $var);
  278. unset($block_var[count($block_var)-1]);
  279. if (count($block_var))
  280. {
  281. for ($_num = count($block_var)-1; $_num >= 0; $_num--)
  282. {
  283. $remaining .= ($_num == count($block_var)-1) ? '<i>Element of Block</i> -&gt; <b>' . $block_var[$_num] . '</b><br>' . "\n" : '<i>...which is an element of</i> -&gt; <b>' . $block_var[$_num] . '</b><br>' . "\n";
  284. }
  285. }
  286. $remaining .= '<br></li>' . "\n";
  287. }
  288. }
  289. $remaining .= '</ul>';
  290. }
  291. else
  292. {
  293. $remaining = '<b>NONE</b><br>' . "\n";
  294. }
  295. $html_data = str_replace('{REMAINING_VARS}', $remaining, $html_data);
  296. if (isset($php_files_includes[$data['single_filename']]) && count($php_files_includes[$data['single_filename']]))
  297. {
  298. $usedby = '<ul>';
  299. foreach ($php_files_includes[$data['single_filename']] as $php_filename)
  300. {
  301. $usedby .= '<li>' . str_replace('../', '', $php_filename) . '</li>';
  302. }
  303. $usedby .= '</ul>';
  304. }
  305. else
  306. {
  307. $usedby = '<b>NONE</b><br>' . "\n";
  308. }
  309. $html_data = str_replace('{USED_BY}', $usedby, $html_data);
  310. fwrite($fp, $html_data);
  311. fclose($fp);
  312. }
  313. echo '<br>Store Files';
  314. $fp = fopen($store_dir . 'index.html', 'w');
  315. $html_data = '
  316. <!DOCTYPE html>
  317. <html>
  318. <head>
  319. <link rel="stylesheet" href="subSilver.css" type="text/css">
  320. <style type="text/css">
  321. <!--
  322. th { background-image: url(\'cellpic3.gif\') }
  323. td.cat { background-image: url(\'cellpic1.gif\') }
  324. //-->
  325. </style>
  326. <title>Contents</title>
  327. </head>
  328. <body>
  329. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  330. <tr>
  331. <td><img src="header_left.jpg" width="200" height="60" alt="phpBB Logo" title="phpBB Logo" border="0"/></td>
  332. <td width="100%" background="header_bg.jpg" height="60" align="right" nowrap="nowrap"><span class="maintitle">Available Template Files</span> &nbsp; &nbsp; &nbsp;</td>
  333. </tr>
  334. </table>
  335. <table width="95%" cellspacing="0" cellpadding="0" border="0" align="center">
  336. <tr>
  337. <td><br clear="all" />
  338. <br>This Style Document is 100% auto-generated... no human interaction included. :D<br>
  339. <h2>phpBB 2.2 Template</h2>
  340. <br>
  341. <ol>
  342. ';
  343. sort($files_to_parse);
  344. foreach ($files_to_parse as $file_num => $data)
  345. {
  346. echo '.';
  347. flush();
  348. $var = $data['single_filename'];
  349. $html_data .= '<li><a href="./' . $file_to_destfile[$var] . '" class="gen">' . $var . '</a></li><br>' . "\n";
  350. }
  351. $html_data .= '<br><li><a href="./lang_index.html" class="gen">Appendix A: Language Variable Index</a></li><br>';
  352. $html_data .= '
  353. </ol><br><br>
  354. <div class="copyright" align="center">Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited</div>
  355. <br clear="all" /></td>
  356. </tr>
  357. </table>
  358. </body>
  359. </html>
  360. ';
  361. fwrite($fp, $html_data);
  362. fclose($fp);
  363. // Not only write down all language files, place them into a specific array, named by the template file
  364. // All Language vars assigned to more than one template will be placed into a common file
  365. $entry = array();
  366. $common_fp = fopen($store_dir . 'lang_common.php', 'w');
  367. fwrite($common_fp, "<?php\n\n \$lang = array(\n");
  368. $fp = fopen($store_dir . 'lang_index.html', 'w');
  369. $html_data = '
  370. <!DOCTYPE html>
  371. <html>
  372. <head>
  373. <link rel="stylesheet" href="subSilver.css" type="text/css">
  374. <style type="text/css">
  375. <!--
  376. th { background-image: url(\'cellpic3.gif\') }
  377. td.cat { background-image: url(\'cellpic1.gif\') }
  378. //-->
  379. </style>
  380. <title>Appendix A :: Language Variable Index</title>
  381. </head>
  382. <body>
  383. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  384. <tr>
  385. <td><img src="header_left.jpg" width="200" height="60" alt="phpBB Logo" title="phpBB Logo" border="0"/></td>
  386. <td width="100%" background="header_bg.jpg" height="60" align="right" nowrap="nowrap"><span class="maintitle">Language Variable Index</span> &nbsp; &nbsp; &nbsp;</td>
  387. </tr>
  388. </table>
  389. <table width="95%" cellspacing="0" cellpadding="0" border="0" align="center">
  390. <tr>
  391. <td><br clear="all" />
  392. <br><a href="./index.html" class="gen">Back to Contents</a><br><br>
  393. <br>
  394. ';
  395. echo '<br>Write Language Files';
  396. asort($lang_references);
  397. ksort($lang_references);
  398. $_index = '';
  399. $old_char = '';
  400. foreach ($lang_references as $lang_var => $filenames)
  401. {
  402. $var = preg_replace('#^L_(.*?)#', '\1', $lang_var);
  403. $char = $var{0};
  404. if ($old_char != $char)
  405. {
  406. $old_char = $char;
  407. $_index .= ($_index != '') ? ' :: ' : '';
  408. $_index .= '<a href="#' . $char . '" class="gen"><b>' . $char . '</b></a>';
  409. }
  410. }
  411. $html_data .= $_index . '<br><br><br>';
  412. $old_char = '';
  413. foreach ($lang_references as $lang_var => $filenames)
  414. {
  415. echo '.';
  416. flush();
  417. $var = preg_replace('#^L_(.*?)#', '\1', $lang_var);
  418. $char = $var{0};
  419. if ($old_char != $char)
  420. {
  421. $old_char = $char;
  422. $html_data .= '<br><hr><br><a name="' . $char . '"></a><h2>Letter ' . $char . '</h2><br><br>';
  423. }
  424. $html_data .= '<b>' . $lang_var . '</b><ul>';
  425. if (count($filenames) != 1)
  426. {
  427. fwrite($common_fp, (($entry['common']) ? ",\n" : '') . "\t'$var' => '" . $lang[$var] . "'");
  428. $entry['common'] = true;
  429. }
  430. else if (count($filenames) == 1)
  431. {
  432. // Merge logical - hardcoded
  433. $fname = (preg_match('#^(' . implode('|', $merge) . ')#', $filenames[0], $match)) ? $match[0] . '.php' : str_replace($ext, 'php', $filenames[0]);
  434. if (!$lang_fp[$fname])
  435. {
  436. $lang_fp[$fname] = fopen($store_dir . 'lang_' . $fname, 'w');
  437. fwrite($lang_fp[$fname], "<?php\n\n\$lang = array(\n");
  438. $entry[$fname] = false;
  439. }
  440. fwrite($lang_fp[$fname], (($entry[$fname]) ? ",\n" : '') . "\t'$var' => '" . $lang[$var] . "'");
  441. $entry[$fname] = true;
  442. }
  443. foreach ($filenames as $f_name)
  444. {
  445. $var = trim($f_name);
  446. $html_data .= '<li><a href="./' . $file_to_destfile[$var] . '" class="gen">' . $var . '</a></li><br>' . "\n";
  447. }
  448. $html_data .= '</ul><br><br>';
  449. }
  450. fwrite($common_fp, ")\n);\n?>");
  451. fclose($common_fp);
  452. foreach ($lang_fp as $filepointer)
  453. {
  454. fwrite($filepointer, ")\n);\n?>");
  455. fclose($filepointer);
  456. }
  457. $html_data .= '
  458. <br><br>
  459. <div class="copyright" align="center">Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited</div>
  460. <br clear="all" /></td>
  461. </tr>
  462. </table>
  463. </body>
  464. </html>
  465. ';
  466. fwrite($fp, $html_data);
  467. fclose($fp);
  468. echo '<br>Finished!';
  469. flush();