r394: Add access keys to the checkboxes
[bugdar.git] / docs / lang_registry_replacer.php
1 <?php
2
3 // replaces lang::r() with lang::p() calls
4 // $Id$
5
6 chdir('./../');
7 require_once('./global.php');
8
9 function fetch_listing($path, $basepath = '', $unset = 1)
10 {
11 static $filelist;
12
13 if ($unset)
14 {
15 $filelist = array();
16 }
17
18 if (substr($path, (strlen($path) - 1), 1) != '/')
19 {
20 $path .= '/';
21 }
22
23 if ($handle = opendir($path))
24 {
25 while (($file = readdir($handle)) !== false)
26 {
27 if (substr($file, 0, 1) != '.' AND $file != 'CVS')
28 {
29 if (is_dir($path . $file))
30 {
31 $filelist["$basepath"][] = "$file/";
32 fetch_listing("$path$file", "$basepath$file/", 0);
33 }
34 else
35 {
36 $filelist["$basepath"][] = $file;
37 }
38 }
39 }
40 closedir($handle);
41 }
42 return $filelist;
43 }
44
45 function fetch_flat_listing($filelist)
46 {
47 foreach ($filelist AS $basepath => $files)
48 {
49 foreach ($files AS $file)
50 {
51 if (preg_match('#\.php$#', $file))
52 {
53 $flatlist[] = "./$basepath$file";
54 }
55 }
56 }
57 return $flatlist;
58 }
59
60 // ###################################################################
61 // ###################################################################
62
63 $listing = fetch_flat_listing(fetch_listing(getcwd()));
64
65 $phrases = $db->query("SELECT * FROM phrase WHERE md5");
66 while ($phrase = $db->fetch_array($phrases))
67 {
68 $replace["$phrase[md5]"] = $phrase['varname'];
69 }
70
71 foreach ($listing AS $filename)
72 {
73 $file = file_get_contents($filename);
74
75 preg_match_all("#lang::r\('(.*?)'\)#", $file, $matches);
76 foreach ($matches[0] AS $matchid => $match)
77 {
78 $mdstring = md5($matches[1]["$matchid"]);
79 if ($replace["$mdstring"])
80 {
81 $file = str_replace($match, 'lang::p(\'' . $replace["$mdstring"] . '\')', $file);
82 }
83 }
84
85 if ($h = fopen($filename, 'w'))
86 {
87 fwrite($h, $file);
88 }
89 fclose($h);
90 }
91
92 ?>