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");
9 /** Import a single Perl POD file.
17 function importPod(&$caller, $pod, $docdir, $docbase, $template = '')
20 $barrel =& $caller->barrel;
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";
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!");
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);
39 if (preg_match("/<title>(.*)<\/title>/si", $content, $matches))
41 $page->props['title'] = addslashes($matches[1]);
43 $page->props['template'] = $template;
44 $page->toDb(0, $caller);
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];
53 $content = str_replace("h1>", "h2>", $content);
54 $rcs->commit($pid,$globals->htmlfile,$content,"automatic import");
58 /** Import a set of Perl POD files.
65 function importPods(&$caller, $docarray, $docbase, $template = '')
67 foreach ($docarray as $pod => $docdir)
69 importPod($caller, $pod, $docdir, $docbase, $template);
74 /** Print program usage and exit.
78 echo "Usage: pod2diogenes [options] barrel podmap\n\n";
80 echo " -b<docbase> the base URL for Perl docs (default: '')\n";
81 echo " -h display help message\n";
82 echo " -t<template> set page template to <template>\n";
83 echo " -u<user> make commits as <user> (default : current user)\n";
88 /** Parse a podmap file.
90 function parsePodmap($mapfile)
92 if (!($fp = fopen($mapfile, "r")))
94 echo "could not open '$mapfile'\n";
98 while ($line = fgets($fp))
100 $bits = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
101 $podmap[$bits[0]] = $bits[1];
115 $user = get_current_user();
119 $opts = Console_GetOpt::getopt($argv, "b:hu:t:");
120 if ( PEAR::isError($opts) ) {
121 echo $opts->getMessage();
126 foreach ( $opts as $opt) {
143 if (sizeof($argv) != 2)
145 list($alias, $mapfile) = $argv;
147 // parse the podmap file
148 if (!($podmap = parsePodmap($mapfile)))
150 echo "failed to parse '$mapfile'\n";
154 // perform the actual work
155 $script = new Diogenes_Script($alias, $user);
156 importPods($script, $podmap, $docbase, $template);