Do not ignore filtered result in php_filter_validate_url
[hiphop-php.git] / hphp / doc / index.php
blobe082ef68eaf7030776fb0a0b58c04dbc95dcf45e
1 <?php
2 $topics =
3 array(
4 'Compiler' => array(
5 'Command line options' => 'command.compiler',
6 'Configurable options' => 'options.compiler',
7 ),
8 'Compiled Program' => array(
9 'Command line options' => 'command.compiled',
10 'Configurable options' => 'options.compiled',
11 'Administrative commands' => 'command.admin_server',
12 'Server Status' => 'server.status',
13 'Server Statistics' => 'server.stats',
15 'Debugger' => array(
16 'Getting Started' => 'debugger.start',
17 'All Commands' => 'debugger.cmds',
18 'Command A-Z' => 'debugger.refs',
20 'HTTP Server' => array(
21 'Rewrite Rules' => 'server.rewrite_rules',
22 'SSL Setup' => 'server.ssl',
24 'Inconsistencies' => array(
25 'PHP vs. HipHop' => 'inconsistencies',
26 'HipHop Compiler vs. Interpreter' => 'inconsistencies.hphpi',
28 'New Features' => array(
29 'New functions' => 'extension.new_functions',
30 'yield and generator' => 'extension.yield',
31 'Richer type hints' => 'extension.type_hints',
32 'Parallel execution' => 'threading',
33 'Server documents' => 'server.documents',
34 'RPC server' => 'server.rpc_server',
35 'Xbox server' => 'server.xbox_server',
36 'Dangling server' => 'server.dangling_server',
38 'Foreign Function Interfaces' => array(
39 'C++' => 'ffi.c++',
40 'Java' => 'ffi.java',
41 'Python' => 'ffi.python',
43 'Debugging' => array(
44 'Server' => 'debug.server',
45 'CPU Profiling' => 'debug.profile',
46 'Memory leak detection' => 'debug.leak',
47 'Mutex contention' => 'debug.mutex',
48 'Useful gdb commands' => 'debug.gdb',
49 'Useful Linux commands' => 'debug.linux',
51 'Development' => array(
52 'Coding guidelines' => 'coding_guideline',
53 'Type system' => 'runtime.type_system',
54 'Memory model' => 'runtime.memory_model',
55 'Writing new extensions' => 'extension.development',
56 'Useful commands' => 'command.project',
58 'References' => array(
59 'Configuration file format' => 'hdf',
63 ///////////////////////////////////////////////////////////////////////////////
64 // main
66 echo "<link type='text/css' rel='stylesheet' href='style.css' />";
68 $file = 'coding_guideline';
69 if (isset($_GET['file'])) $file = $_GET['file'];
70 $title = find_topics($topics, $file);
72 echo '<title>'.htmlspecialchars($title ? $title : 'Invalid topic').'</title>';
73 echo '<table cellpadding=0 cellspacing=0 border=0>';
74 echo '<tr><td valign=top width=200>';
75 format_index($topics, $file);
76 echo '</td><td valign=top bgcolor=white width=640>';
77 if (!$title) {
78 echo 'Topic does not exist.';
79 } else {
80 $doc = file_get_contents(realpath(dirname(__FILE__))."/$file");
81 if (preg_match('/^debugger\./', $file)) {
82 echo format_debugger_doc($doc);
83 } else {
84 echo format_document($doc);
87 echo '</td></tr></table>';
89 ///////////////////////////////////////////////////////////////////////////////
90 // helpers
92 function find_topics(&$topics, $file) {
93 $title = '';
95 $found_files = array();
96 exec('find . -type f', $found_files);
98 $files = array();
99 foreach ($found_files as $f) {
100 $f = substr($f, 2); // skipping "./"
101 if (!preg_match('/(~|Makefile|index\.php|style\.css|www\.pid)/', $f)) {
102 if ($f == $file) {
103 $title = $f;
105 $files[$f] = $f;
109 $allowed = isset($files[$file]);
111 foreach ($topics as $topic => $group) {
112 foreach ($group as $name => $f) {
113 if ($f == $file) {
114 $title = "$topic: $name";
116 unset($files[$f]);
119 if (!empty($files)) {
120 $topics['New Topics'] = $files;
123 return $title;
126 function format_index($topics, $file) {
127 echo '<table cellpadding=1 cellspacing=3 border=1 bgcolor=white>';
128 echo '<tr><td colspan=2 class="hphp">HipHopDoc</td></tr>';
129 echo '<tr><td colspan=2>&nbsp;</td></tr>';
130 foreach ($topics as $topic => $group) {
131 echo "<tr><td colspan=2 class='topic'>";
132 echo "<nobr>$topic</nobr></a></td></tr>";
134 foreach ($group as $name => $f) {
135 echo '<tr><td width=5></td><td><nobr>';
136 $class = $f == $file ? 'current_file' : 'file';
137 echo "<span class='$class'><a href='index.php?file=".
138 urlencode($f)."'>$name</a></span>";
139 echo '</nobr></td></tr>';
142 echo '</table>';
145 function format_document($doc) {
146 $doc = preg_replace('/<(?!\/?(b|h2|i)[ >])/',
147 '&lt;', $doc); // unsupported tags
148 $doc = preg_replace('/\n= (.*?)\n/',
149 "<h3>\\1</h3>\n", $doc); // h3 headers
150 $doc = preg_replace('/\n([0-9]+\. )(.*?)\n/',
151 "<h3>\\1\\2</h3>\n", $doc); // 1. 2. 3.
152 $doc = preg_replace('/\n(\([0-9]+\) )(.*?)\n/',
153 "\n\\1<u>\\2</u>\n", $doc); // (1) (2) (3)
154 $doc = preg_replace('/((?:\n- [^\n]*(?:\n [^\n]+)*)+)/',
155 "\n<ul>\\1</ul>\n", $doc); // lists
156 $doc = preg_replace('/\n- /', "\n<li>", $doc); // list items
157 $doc = preg_replace('/((?:\n( |\t)[^\n]*)+)/',
158 "\n<pre>\\1</pre>\n", $doc); // code blocks
159 $doc = preg_replace('/(<li>[^\n]*)\n<pre>(.*?)<\/pre>/s',
160 "\\1 \\2", $doc); // fix list item's 2nd lines
162 $doc = preg_replace('/\n([^ \t]+): (.*)/',
163 "<br><b class=item_header>\\1</b>: ".
164 "<span class=item_details>\\2</span>",
165 $doc); // item: details
167 $doc = preg_replace('/\n\n/', '<p>', $doc); // paragraphs
168 $doc = preg_replace('/\[\[[ \n]*(.*?)[ \n]*\|[ \n]*(.*?)[ \n]*\]\]/s',
169 '<a href="\\1">\\2</a>',$doc); // links
171 // copyright notice
172 $doc .= '<p>&nbsp;<table width="100%"><tr><td class="footer" align=right>'.
173 'Facebook &copy; 2009</td></tr></table>';
174 return $doc;
177 function format_debugger_doc($doc) {
178 $doc = preg_replace('/ *(?:\xe2\x94\x80|\-){5,}(.*) '.
179 '(?:\xe2\x94\x80|\-){5,}/',
180 '<h2>$1</h2>', $doc);
181 $doc = preg_replace("/('\[.*?')/", '<b>$1</b>', $doc);
182 $doc = preg_replace("/(\{.*?\})/", '<i>$1</i>', $doc);
183 return format_document($doc);