array( 'Command line options' => 'command.compiler', 'Configurable options' => 'options.compiler', ), 'Compiled Program' => array( 'Command line options' => 'command.compiled', 'Configurable options' => 'options.compiled', 'Administrative commands' => 'command.admin_server', 'Server Status' => 'server.status', 'Server Statistics' => 'server.stats', ), 'Debugger' => array( 'Getting Started' => 'debugger.start', 'All Commands' => 'debugger.cmds', 'Command A-Z' => 'debugger.refs', ), 'HTTP Server' => array( 'Rewrite Rules' => 'server.rewrite_rules', 'SSL Setup' => 'server.ssl', ), 'Inconsistencies' => array( 'PHP vs. HipHop' => 'inconsistencies', 'HipHop Compiler vs. Interpreter' => 'inconsistencies.hphpi', ), 'New Features' => array( 'New functions' => 'extension.new_functions', 'yield and generator' => 'extension.yield', 'Richer type hints' => 'extension.type_hints', 'Parallel execution' => 'threading', 'Server documents' => 'server.documents', 'RPC server' => 'server.rpc_server', 'Xbox server' => 'server.xbox_server', 'Dangling server' => 'server.dangling_server', ), 'Foreign Function Interfaces' => array( 'C++' => 'ffi.c++', 'Java' => 'ffi.java', 'Python' => 'ffi.python', ), 'Debugging' => array( 'Server' => 'debug.server', 'CPU Profiling' => 'debug.profile', 'Memory leak detection' => 'debug.leak', 'Mutex contention' => 'debug.mutex', 'Useful gdb commands' => 'debug.gdb', 'Useful Linux commands' => 'debug.linux', ), 'Development' => array( 'Coding guidelines' => 'coding_guideline', 'Type system' => 'runtime.type_system', 'Memory model' => 'runtime.memory_model', 'Writing new extensions' => 'extension.development', 'Useful commands' => 'command.project', ), 'References' => array( 'Configuration file format' => 'hdf', ), ); /////////////////////////////////////////////////////////////////////////////// // main echo ""; $file = 'coding_guideline'; if (isset($_GET['file'])) $file = $_GET['file']; $title = find_topics($topics, $file); echo ''.htmlspecialchars($title ? $title : 'Invalid topic').''; echo ''; echo '
'; format_index($topics, $file); echo ''; if (!$title) { echo 'Topic does not exist.'; } else { $doc = file_get_contents(realpath(dirname(__FILE__))."/$file"); if (preg_match('/^debugger\./', $file)) { echo format_debugger_doc($doc); } else { echo format_document($doc); } } echo '
'; /////////////////////////////////////////////////////////////////////////////// // helpers function find_topics(&$topics, $file) { $title = ''; $found_files = array(); exec('find . -type f', $found_files); $files = array(); foreach ($found_files as $f) { $f = substr($f, 2); // skipping "./" if (!preg_match('/(~|Makefile|index\.php|style\.css|www\.pid)/', $f)) { if ($f == $file) { $title = $f; } $files[$f] = $f; } } $allowed = isset($files[$file]); foreach ($topics as $topic => $group) { foreach ($group as $name => $f) { if ($f == $file) { $title = "$topic: $name"; } unset($files[$f]); } } if (!empty($files)) { $topics['New Topics'] = $files; } return $title; } function format_index($topics, $file) { echo ''; echo ''; echo ''; foreach ($topics as $topic => $group) { echo ""; foreach ($group as $name => $f) { echo ''; } } echo '
HipHopDoc
 
"; echo "$topic
'; $class = $f == $file ? 'current_file' : 'file'; echo "$name"; echo '
'; } function format_document($doc) { $doc = preg_replace('/<(?!\/?(b|h2|i)[ >])/', '<', $doc); // unsupported tags $doc = preg_replace('/\n= (.*?)\n/', "

\\1

\n", $doc); // h3 headers $doc = preg_replace('/\n([0-9]+\. )(.*?)\n/', "

\\1\\2

\n", $doc); // 1. 2. 3. $doc = preg_replace('/\n(\([0-9]+\) )(.*?)\n/', "\n\\1\\2\n", $doc); // (1) (2) (3) $doc = preg_replace('/((?:\n- [^\n]*(?:\n [^\n]+)*)+)/', "\n\n", $doc); // lists $doc = preg_replace('/\n- /', "\n
  • ", $doc); // list items $doc = preg_replace('/((?:\n( |\t)[^\n]*)+)/', "\n
    \\1
    \n", $doc); // code blocks $doc = preg_replace('/(
  • [^\n]*)\n
    (.*?)<\/pre>/s',
                          "\\1 \\2", $doc);            // fix list item's 2nd lines
    
      $doc = preg_replace('/\n([^ \t]+): (.*)/',
                          "
    \\1: ". "\\2", $doc); // item: details $doc = preg_replace('/\n\n/', '

    ', $doc); // paragraphs $doc = preg_replace('/\[\[[ \n]*(.*?)[ \n]*\|[ \n]*(.*?)[ \n]*\]\]/s', '\\2',$doc); // links // copyright notice $doc .= '

     
    '; return $doc; } function format_debugger_doc($doc) { $doc = preg_replace('/ *(?:\xe2\x94\x80|\-){5,}(.*) '. '(?:\xe2\x94\x80|\-){5,}/', '

    $1

    ', $doc); $doc = preg_replace("/('\[.*?')/", '$1', $doc); $doc = preg_replace("/(\{.*?\})/", '$1', $doc); return format_document($doc); }