-
Notifications
You must be signed in to change notification settings - Fork 0
/
phd
executable file
·129 lines (103 loc) · 3.71 KB
/
phd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/local/zend/bin/php
<?php
namespace phpdotnet\phd;
/* $Id: render.php 310453 2011-04-24 09:58:39Z bjori $ */
// /usr/local/zend/share/pear gets replaced by pear with the install dir. use __DIR__ when
// running from SVN
define("__INSTALLDIR__", __DIR__ . "/tools");
require __INSTALLDIR__ . '/phpdotnet/phd/Autoloader.php';
require __INSTALLDIR__ . '/phpdotnet/phd/functions.php';
spl_autoload_register(array(__NAMESPACE__ . "\\Autoloader", "autoload"));
$conf = array();
if (file_exists("phd.config.php")) {
$conf = include "phd.config.php";
Config::init($conf);
v("Loaded config from existing file", VERBOSE_MESSAGES);
} else {
// need to init regardless so we get package-dirs from the include-path
Config::init(array());
}
Options_Parser::getopt();
/* If no docbook file was passed, die */
if (!is_dir(Config::xml_root()) || !is_file(Config::xml_file())) {
trigger_error("No Docbook file given. Specify it on the command line with --docbook.", E_USER_ERROR);
}
if (!file_exists(Config::output_dir())) {
v("Creating output directory..", VERBOSE_MESSAGES);
if (!mkdir(Config::output_dir(), 0777, True)) {
v("Can't create output directory : %s", Config::output_dir(), E_USER_ERROR);
}
} elseif (!is_dir(Config::output_dir())) {
v("Output directory is not a file?", E_USER_ERROR);
}
// This needs to be moved. Preferably into the PHP package.
if (!$conf) {
Config::init(array(
"lang_dir" => __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR
. "phd" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR
. "langs" . DIRECTORY_SEPARATOR,
"phpweb_version_filename" => Config::xml_root() . DIRECTORY_SEPARATOR . 'version.xml',
"phpweb_acronym_filename" => Config::xml_root() . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'acronyms.xml',
));
}
if (Config::saveconfig()) {
v("Writing the config file", VERBOSE_MESSAGES);
file_put_contents("phd.config.php", "<?php\nreturn " . var_export(Config::getAllFiltered(), 1) . ";");
}
if (Config::quit()) {
exit(0);
}
function make_reader() {
//Partial Rendering
$idlist = Config::render_ids() + Config::skip_ids();
if (!empty($idlist)) {
v("Running partial build", VERBOSE_RENDER_STYLE);
$reader = new Reader_Partial();
} else {
v("Running full build", VERBOSE_RENDER_STYLE);
$reader = new Reader();
}
return $reader;
}
$render = new Render();
$reader = make_reader();
// Set reader LIBXML options
$readerOpts = 0;
if (Config::process_xincludes()) {
$readerOpts |= LIBXML_XINCLUDE;
}
// Indexing
if (Index::requireIndexing()) {
v("Indexing...", VERBOSE_INDEXING);
// Create indexer
$format = $render->attach(new Index);
$reader->open(Config::xml_file(), NULL, $readerOpts);
$render->execute($reader);
$render->detach($format);
v("Indexing done", VERBOSE_INDEXING);
} else {
v("Skipping indexing", VERBOSE_INDEXING);
}
foreach((array)Config::package() as $package) {
$factory = Format_Factory::createFactory($package);
// Default to all output formats specified by the package
if (count(Config::output_format()) == 0) {
Config::set_output_format((array)$factory->getOutputFormats());
}
// Register the formats
foreach (Config::output_format() as $format) {
$render->attach($factory->createFormat($format));
}
}
// Render formats
$reader = make_reader();
$reader->open(Config::xml_file(), NULL, $readerOpts);
foreach($render as $format) {
$format->notify(Render::VERBOSE, true);
}
$render->execute($reader);
v("Finished rendering", VERBOSE_FORMAT_RENDERING);
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/