ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HFile_ueconv.php
Go to the documentation of this file.
1 <?php
2 $BEAUT_PATH = realpath(".") . "/Services/COPage/syntax_highlight/php";
3 if (!isset($BEAUT_PATH)) {
4  return;
5 }
6 require "$BEAUT_PATH/Beautifier/HFile.php";
7 
8 //######## Configuration Conversion functions
9 
10 // Function to go through an Ultraedit-style configuration file and convert to a PHP include
11 
12 function HFile_print_php_file($tofile = 1)
13 {
14  global $indent, $unindent, $stringchars, $config, $keywords, $delimiters, $lang_name;
15  global $linecommenton, $blockcommenton, $blockcommentoff;
16  global $perl, $nocase, $notrim;
17  if ($tofile) {
18  print "<?php\n";
19  } else {
20  print "&lt;?\n";
21  }
22  print "######################################\n";
23  print "# Beautifier Highlighting Configuration File \n";
24  print "# $lang_name\n";
25  print "######################################\n";
26  print "# Flags\n\n";
27  dump_var($nocase, "\$nocase ");
28  dump_var($notrim, "\$notrim ");
29  dump_var($perl, "\$perl ");
30  print "\n# Colours\n\n";
31  $used_categories = get_categories();
32  dump_colours($used_categories);
33  dump_var("blue", "\$quotecolour ");
34  dump_var("green", "\$blockcommentcolour");
35  dump_var("green", "\$linecommentcolour ");
36  print "\n# Indent Strings\n\n";
37  dump_array($indent, "\$indent ");
38  dump_array($unindent, "\$unindent ");
39  print "\n# String characters and delimiters\n\n";
40  dump_array($stringchars, "\$stringchars ");
41  dump_array($delimiters, "\$delimiters ");
42  dump_var($escchar, "\$escchar ");
43  print "\n# Comment settings\n\n";
44  dump_var($linecommenton, "\$linecommenton ");
45  dump_var($blockcommenton, "\$blockcommenton ");
46  dump_var($blockcommentoff, "\$blockcommentoff ");
47  print "\n# Keywords (keyword mapping to colour number)\n\n";
48  dump_hash($keywords, "\$keywords ");
49  print "\n# Special extensions\n";
50  dump_linkscripts($used_categories);
51  if ($tofile) {
52  print "\n?>";
53  } else {
54  print "\n?&gt;";
55  }
56 }
57 
58 function get_categories()
59 {
60  global $keywords;
61  $usedcats = array();
62 
63  foreach (array_keys($keywords) as $k) {
64  $cat = $keywords[$k];
65  if (!in_array($cat, $usedcats)) {
66  array_push($usedcats, $cat);
67  }
68  }
69  return $usedcats;
70 }
71 
72 function dump_linkscripts($cats)
73 {
74  print "
75 // Each category can specify a PHP function that returns an altered
76 // version of the keyword.
77  # This link is then placed in a <a href=\"...\">foo</a>; structure around keyword 'foo' - which is
78  \n\n";
79 
80  $linkhash = array();
81 
82  foreach ($cats as $c) {
83  $linkhash{$c} = "donothing";
84  }
85 
86  dump_hash($linkhash, "\$linkscripts ");
87  print "\n# DoNothing link function\n\n";
88  print "function donothing(\$keywordin)\n{\n return \$keywordin;\n}\n";
89 }
90 
91 function dump_colours($cats)
92 {
93  global $colours;
94 
95  $usedcols = array();
96  foreach ($cats as $c) {
97  array_push($usedcols, $colours[$c-1]);
98  }
99  dump_array($usedcols, "\$colours ");
100 }
101 
102 function dump_var($variable, $name)
103 {
104  print $name . " = \"" . addslashes($variable) . "\";\n";
105 }
106 
107 function dump_array($array, $name)
108 {
109  $first = 1;
110  print $name . " = array(";
111  foreach ($array as $a) {
112  if (!$first) {
113  print ", ";
114  } else {
115  $first = 0;
116  }
117  print "\"" . addslashes($a) . "\"";
118  }
119  print ");\n";
120 }
121 
122 function dump_hash($hash, $name)
123 {
124  $first = 1;
125  print $name . " = array(";
126  foreach (array_keys($hash) as $k) {
127  if (!$first) {
128  print ", ";
129  } else {
130  $first = 0;
131  }
132  print "\n \"" . addslashes($k) . "\"";
133  print " => \"" . addslashes($hash[$k]) . "\"";
134  }
135  print ");\n";
136 }
137 
138 ?>
139 <html><title>Configuration Converter</title><body>
140 <h1>Important Note</h1>
141 <p>This script should <b>not</b> be run on a public server. It is possible to access files other than syntax highlight files (by entering /etc/passwd, for example). Although this should not display anything useful, it is still possible that important data may be extractable. As such, only run this script <b>locally</b> (it should not be necessary to run it on a public server, anyway).</p>
142 <form action="HFileconv.php">Please specify a syntax file to convert:<br />
143 <input type="text" width="64" size="64" name="file" value="<?php print $file; ?>" /><br />
144 Save to:<br />
145 <input type="text" width="64" size="64" name="fileout" value="<?php print stripslashes($fileout); ?>" /><br />
146 <input type="submit" /></form><hr />
147 <pre>
148 <?php
149 if (isset($fileout) && $fileout == "") {
150  unset($fileout);
151 }
152 if (isset($file) && file_exists($file)) {
153  HFile_parse_file($file);
154  ob_start();
155  HFile_print_php_file(isset($fileout));
156  $out = ob_get_contents();
157  if (isset($fileout)) {
158  $fd = fopen($fileout, "w");
159  fputs($fd, $out);
160  fclose($fd);
161  }
162  ob_end_flush();
163 }
164 ?>
165 </pre>
166 </body></html>
167 
168 
169 
File written to
Add some data
print $file
HFile_print_php_file($tofile=1)
Sum of both Ranges is
Definition: 03formulas.php:77
dump_colours($cats)
convert($file)
Definition: HFile_conv.php:151
dump_array($array, $name)
dump_hash($hash, $name)
dump_var($variable, $name)
if($format !==null) $name
Definition: metadata.php:146
Reload workbook from saved file
Create styles array
The data for the language used.
get_categories()
html()
Done writing files
$BEAUT_PATH
Definition: HFile_ueconv.php:2
dump_linkscripts($cats)
Set page orientation and size
Definition: 04printing.php:77