| 1 |
#!/usr/bin/php
|
| 2 |
<?php
|
| 3 |
if (!isset($_SERVER['argv'][1])) {
|
| 4 |
print "Usage: php quanta-doc-generate.php [path to drupal]\nYou should run this in the quanta doc dir, or move the result into there. (~/.kde/share/apps/quanta/doc/) The drupal.xml can be moved into your kate syntax dir (~/.kde/share/apps/katepart/syntax/)"; exit;
|
| 5 |
}
|
| 6 |
$api = rtrim($_SERVER['argv'][1], '/');
|
| 7 |
$files = '/^[^.]*\.(inc|module|php|theme)$/';
|
| 8 |
|
| 9 |
function recurse($dir) {
|
| 10 |
global $api, $files;
|
| 11 |
static $all_functions;
|
| 12 |
|
| 13 |
$handle = opendir($dir);
|
| 14 |
while ($file = readdir($handle)) {
|
| 15 |
$path = $dir .'/'. $file;
|
| 16 |
if (is_dir($path) && $file[0] != '.') {
|
| 17 |
recurse($path);
|
| 18 |
}
|
| 19 |
if (preg_match($files, $file)) {
|
| 20 |
$functions = parse($path);
|
| 21 |
$all_functions = array_merge($all_functions, $functions);
|
| 22 |
}
|
| 23 |
}
|
| 24 |
closedir($handle);
|
| 25 |
return $all_functions;
|
| 26 |
}
|
| 27 |
|
| 28 |
function parse($file) {
|
| 29 |
$data = file_get_contents($file);
|
| 30 |
preg_match_all('/function ([A-Za-z0-9_]+)(\([^{]+)/', $data, $matches, PREG_SET_ORDER);
|
| 31 |
foreach ($matches as $func) {
|
| 32 |
$snippet = snippet($func);
|
| 33 |
$f = fopen('./function.'. $func[1] .'.html', 'w+');
|
| 34 |
fwrite($f, $snippet);
|
| 35 |
fclose($f);
|
| 36 |
$functions[$func[1]] = $func;
|
| 37 |
}
|
| 38 |
return $functions;
|
| 39 |
}
|
| 40 |
|
| 41 |
function argument($matches) {
|
| 42 |
$GLOBALS['argument']++;
|
| 43 |
return '${'. $GLOBALS['argument'] .':\\$'. $matches[1] .'}';
|
| 44 |
}
|
| 45 |
|
| 46 |
function snippet($func) {
|
| 47 |
$guid = '';
|
| 48 |
for ($i = 0; $i < 8; ++$i) {
|
| 49 |
$guid .= base_convert(rand(0, 15), 10, 16);
|
| 50 |
}
|
| 51 |
$guid .= '-';
|
| 52 |
for ($i = 0; $i < 4; ++$i) {
|
| 53 |
$guid .= base_convert(rand(0, 15), 10, 16);
|
| 54 |
}
|
| 55 |
$guid .= '-';
|
| 56 |
for ($i = 0; $i < 4; ++$i) {
|
| 57 |
$guid .= base_convert(rand(0, 15), 10, 16);
|
| 58 |
}
|
| 59 |
$guid .= '-';
|
| 60 |
for ($i = 0; $i < 4; ++$i) {
|
| 61 |
$guid .= base_convert(rand(0, 15), 10, 16);
|
| 62 |
}
|
| 63 |
$guid .= '-';
|
| 64 |
for ($i = 0; $i < 12; ++$i) {
|
| 65 |
$guid .= base_convert(rand(0, 15), 10, 16);
|
| 66 |
}
|
| 67 |
$guid = strtoupper($guid);
|
| 68 |
|
| 69 |
$GLOBALS['argument'] = 0;
|
| 70 |
$func[2] = htmlspecialchars(trim(preg_replace_callback('/\$([a-zA-Z0-9_]+)/', 'argument', $func[2])));
|
| 71 |
|
| 72 |
$template = <<<DOC
|
| 73 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
| 74 |
|
| 75 |
<html>
|
| 76 |
<head>
|
| 77 |
<meta name="generator" content=
|
| 78 |
"HTML Tidy for Linux/x86 (vers 12 April 2005), see www.w3.org">
|
| 79 |
|
| 80 |
<title>$func[1]</title>
|
| 81 |
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7">
|
| 82 |
<meta http-equiv="Content-type" content="text/html; charset=us-ascii">
|
| 83 |
</head>
|
| 84 |
|
| 85 |
<body class="refentry">
|
| 86 |
<h1>$func[1]</h1>
|
| 87 |
|
| 88 |
<div class="refnamediv">
|
| 89 |
<p></p><!--TODO: (Drupal version), summary of Doxygen here.-->
|
| 90 |
</div>
|
| 91 |
|
| 92 |
<div class="refsect1">
|
| 93 |
<h2>Description</h2>
|
| 94 |
dunno <b class="methodname">$func[1]</b> $func[2] <br>
|
| 95 |
<!--TODO: full Doxygen here. including examples -->
|
| 96 |
</div>
|
| 97 |
</body>
|
| 98 |
</html>
|
| 99 |
DOC;
|
| 100 |
return $template;
|
| 101 |
}
|
| 102 |
|
| 103 |
function write_docrc($functions) {
|
| 104 |
foreach ($functions as $name => $function) {
|
| 105 |
$list[] = "$name=function.$name.html";
|
| 106 |
}
|
| 107 |
$list = implode("\n",$list);
|
| 108 |
$string = implode(',', array_keys($functions));
|
| 109 |
|
| 110 |
$bundle = <<<DOC
|
| 111 |
#######################################################
|
| 112 |
# This file maintained by Drupal community (drupal.org)
|
| 113 |
# Generated by the quanta doc generator, developed and
|
| 114 |
# maintaind by B� Kessels (webschuur.com) for Sympal (sympal.nl)
|
| 115 |
# This file is for Quanta+
|
| 116 |
#####################################################
|
| 117 |
# KDE Config File
|
| 118 |
[Tree]
|
| 119 |
Doc dir=drupal
|
| 120 |
Name=Drupal
|
| 121 |
Top Element=Drupal documentation
|
| 122 |
Drupal documentation=#Function Reference
|
| 123 |
|
| 124 |
Function Reference=$string
|
| 125 |
|
| 126 |
# All the functions
|
| 127 |
$list
|
| 128 |
|
| 129 |
# Keywords for context help
|
| 130 |
[Context]
|
| 131 |
ContextList=$string
|
| 132 |
$list
|
| 133 |
|
| 134 |
#The end.... :)
|
| 135 |
DOC;
|
| 136 |
|
| 137 |
$f = fopen('drupal.docrc', 'w+');
|
| 138 |
fwrite($f, $bundle);
|
| 139 |
fclose($f);
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* This works. But only kindof.
|
| 144 |
* The problem lies in the complexity of PHP:
|
| 145 |
* Since it is an embedded scripting language, we need to include all sorts and flavours of language highligting.
|
| 146 |
* Wich basically means that it is not just parsing a list into an XML file, but it means we need to parse a lot of other files, parts of files etc. into it.
|
| 147 |
* Too hard for now.
|
| 148 |
*/
|
| 149 |
function write_syntax_file($functions) {
|
| 150 |
//More info on the method here http://kate.kde.org/doc/hlhowto.php
|
| 151 |
foreach ($functions as $name => $function) {
|
| 152 |
$list[] = " <item>$name</item>";
|
| 153 |
}
|
| 154 |
$list = implode("\n", $list);
|
| 155 |
|
| 156 |
//first we parse the PHP.xml file.
|
| 157 |
if ($php_file = file('/usr/share/apps/katepart/syntax/php.xml')) {
|
| 158 |
foreach ($php_file as $line) {
|
| 159 |
if(strstr($line, '<item>')) {
|
| 160 |
//here we should include all the existing items.
|
| 161 |
}
|
| 162 |
}
|
| 163 |
}
|
| 164 |
else {
|
| 165 |
print "PHP syntax could not be found";
|
| 166 |
}
|
| 167 |
|
| 168 |
$bundle = <<<DOC
|
| 169 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 170 |
<!DOCTYPE language SYSTEM "language.dtd">
|
| 171 |
<language name="PHP/PHP" version="1.22" kateversion="2.4" section="Scripts" extensions="" priority="5" mimetype="" hidden="true">
|
| 172 |
<highlighting>
|
| 173 |
<list name="functions">
|
| 174 |
$list
|
| 175 |
</list>
|
| 176 |
</highlighting>
|
| 177 |
DOC;
|
| 178 |
|
| 179 |
$f = fopen('drupal.xml', 'w+');
|
| 180 |
fwrite($f, $bundle);
|
| 181 |
fclose($f);
|
| 182 |
}
|
| 183 |
|
| 184 |
/**
|
| 185 |
* This is where the magic takes place.
|
| 186 |
* LEVIATUM QUANTERIA DRUPALERIUS
|
| 187 |
*/
|
| 188 |
if (!is_dir('drupal')) {
|
| 189 |
mkdir('drupal');
|
| 190 |
}
|
| 191 |
chdir('drupal');
|
| 192 |
$functions = recurse($api);
|
| 193 |
chdir('..');
|
| 194 |
write_docrc($functions);
|
| 195 |
?>
|