Commit | Line | Data |
---|---|---|
7d7400ea JL |
1 | #!/usr/bin/php |
2 | <?php | |
3 | ini_set("include_path", "/etc/diogenes:/usr/share/diogenes/include:/usr/share/php"); | |
4 | require_once("diogenes.common.inc.php"); | |
5 | require_once("diogenes.script.inc.php"); | |
6 | require_once("System.php"); | |
7 | require_once("Barrel.php"); | |
8 | ||
9 | /** Import a single Perl POD file. | |
10 | * | |
11 | * @param $caller | |
12 | * @param $pod | |
13 | * @param $docdir | |
14 | * @param $docbase | |
15 | * @param $template | |
16 | */ | |
17 | function importPod(&$caller, $pod, $docdir, $docbase, $template = '') | |
18 | { | |
19 | global $globals; | |
20 | $barrel =& $caller->barrel; | |
21 | ||
22 | $pid = $barrel->makePath($docdir, $caller); | |
23 | $page = Diogenes_Barrel_Page::fromDb($barrel, $pid); | |
24 | if (!$page->props['PID']) { | |
25 | echo "failed to get Page $pid\n"; | |
26 | exit(1); | |
27 | } | |
28 | ||
29 | # produce HTML from POD | |
30 | $pod = realpath($pod); | |
31 | if (($tmpdir = System::mktemp('-d')) == false) { | |
32 | $this->kill("Error : could not create temporary directory!"); | |
33 | } | |
34 | $content = shell_exec("cd $tmpdir && pod2html --htmlroot=FOODOCBASE --infile=".escapeshellarg($pod)); | |
35 | $content = str_replace('<hr />', '', $content); | |
36 | $content = preg_replace('/FOODOCBASE(.*).html/', "/$docbase$1/", $content); | |
37 | ||
38 | # extract title | |
39 | if (preg_match("/<title>(.*)<\/title>/si", $content, $matches)) | |
40 | { | |
41 | $page->props['title'] = addslashes($matches[1]); | |
42 | if ($template) | |
43 | $page->props['template'] = $template; | |
44 | $page->toDb(0, $caller); | |
45 | } | |
46 | ||
47 | # strip un-needed info | |
48 | $rcs = $caller->getRcs(); | |
49 | $content = $rcs->importHtmlString($content); | |
50 | if (preg_match("/<h1><a name=\"synopsis\">.*/si", $content, $matches)) | |
51 | $content = $matches[0]; | |
52 | ||
53 | $content = str_replace("h1>", "h2>", $content); | |
54 | $rcs->commit($pid,$globals->htmlfile,$content,"automatic import"); | |
55 | } | |
56 | ||
57 | ||
58 | /** Import a set of Perl POD files. | |
59 | * | |
60 | * @param $caller | |
61 | * @param $docarray | |
62 | * @param $docbase | |
63 | * @param $template | |
64 | */ | |
65 | function importPods(&$caller, $docarray, $docbase, $template = '') | |
66 | { | |
67 | foreach ($docarray as $pod => $docdir) | |
68 | { | |
69 | importPod($caller, $pod, $docdir, $docbase, $template); | |
70 | } | |
71 | } | |
72 | ||
73 | ||
74 | /** Print program usage and exit. | |
75 | */ | |
76 | function usage() | |
77 | { | |
78 | echo "Usage : pod2diogenes.php | |
79 | exit(1); | |
80 | } | |
81 | ||
82 | ||
83 | function main() | |
84 | { | |
85 | $alias = "umts_tools"; | |
86 | $script = new Diogenes_Script($alias, "sharky"); | |
87 | $podmap = array(); | |
88 | importPods($script, $docs, "docs", "barrel:pod.tpl"); | |
89 | } | |
90 | ||
91 | main(); | |
92 | ?> |