]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/docgen.php
[SCRIPTS] Make them work in v2 by setting PUBLICDIR
[quix0rs-gnu-social.git] / scripts / docgen.php
1 #!/usr/bin/env php
2 <?php
3
4 $shortoptions = '';
5 $longoptions = array('plugin=');
6
7
8 $helptext = <<<ENDOFHELP
9 Build HTML documentation from doc comments in source.
10
11 Usage: docgen.php [options] output-directory
12 Options:
13
14   --plugin=...     build docs for given plugin instead of core
15
16
17 ENDOFHELP;
18
19 define('INSTALLDIR', dirname(__DIR__));
20 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
21 set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path());
22
23 $pattern = "*.php *.inc";
24 $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
25 $plugin = false;
26
27 require_once INSTALLDIR . '/vendor/autoload.php';
28 $parser = new Console_Getopt();
29 $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
30 if (PEAR::isError($result)) {
31     print $result->getMessage() . "\n";
32     exit(1);
33 }
34 list($options, $args) = $result;
35
36 foreach ($options as $option) {
37     $arg = $option[0];
38     if ($arg == '--plugin') {
39         $plugin = $options[1];
40     } else if ($arg == 'h' || $arg == '--help') {
41         print $helptext;
42         exit(0);
43     }
44 }
45
46 if (isset($args[0])) {
47     $outdir = $args[0];
48     if (!is_dir($outdir)) {
49         echo "Output directory $outdir is not a directory.\n";
50         exit(1);
51     }
52 } else {
53     print $helptext;
54     exit(1);
55 }
56
57 if ($plugin) {
58     $exclude = "*/extlib/*";
59     $indir = INSTALLDIR . "/plugins/" . $plugin;
60     if (!is_dir($indir)) {
61         $indir = INSTALLDIR . "/plugins";
62         $filename = "{$plugin}Plugin.php";
63         if (!file_exists("$indir/$filename")) {
64             echo "Can't find plugin $plugin.\n";
65             exit(1);
66         } else {
67             $pattern = $filename;
68         }
69     }
70 } else {
71     $indir = INSTALLDIR;
72 }
73
74 function getVersion()
75 {
76     // define('GNUSOCIAL_VERSION', '0.9.1');
77     $source = file_get_contents(INSTALLDIR . '/lib/common.php');
78     if (preg_match('/^\s*define\s*\(\s*[\'"]GNUSOCIAL_VERSION[\'"]\s*,\s*[\'"](.*)[\'"]\s*\)\s*;/m', $source, $matches)) {
79         return $matches[1];
80     }
81     return 'unknown';
82 }
83
84
85 $replacements = array(
86     '%%version%%' => getVersion(),
87     '%%indir%%' => $indir,
88     '%%pattern%%' => $pattern,
89     '%%outdir%%' => $outdir,
90     '%%htmlout%%' => $outdir,
91     '%%exclude%%' => $exclude,
92 );
93
94 var_dump($replacements);
95
96 $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl');
97 $template = strtr($template, $replacements);
98
99 $templateFile = tempnam(sys_get_temp_dir(), 'statusnet-doxygen');
100 file_put_contents($templateFile, $template);
101
102 $cmd = "doxygen " . escapeshellarg($templateFile);
103
104 $retval = 0;
105 passthru($cmd, $retval);
106
107 if ($retval == 0) {
108     echo "Done!\n";
109     unlink($templateFile);
110     exit(0);
111 } else {
112     echo "Failed! Doxygen config left in $templateFile\n";
113     exit($retval);
114 }
115