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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
<?php
require_once $ROOT . '/themes/pear/pearchunkedhtml.php';
class pearchm extends pearchunkedhtml {
const DEFAULT_FONT = "Arial,10,0";
const DEFAULT_TITLE = "PEAR Manual";
// Array to manual code -> HTML Help Code conversion
// Code list: http://www.helpware.net/htmlhelp/hh_info.htm
// Charset list: http://www.microsoft.com/globaldev/nlsweb/default.asp
// Language code: http://www.unicode.org/unicode/onlinedat/languages.html
// MIME preferred charset list: http://www.iana.org/assignments/character-sets
// Font list: http://www.microsoft.com/office/ork/xp/three/inte03.htm
private $LANGUAGES = array(
"hk" => array(
"langcode" => "0xc04 Hong Kong Cantonese",
"preferred_charset" => "CP950",
"mime_charset_name" => "Big5",
"preferred_font" => "MingLiu,10,0"
),
"tw" => array(
"langcode" => "0x404 Traditional Chinese",
"preferred_charset" => "CP950",
"mime_charset_name" => "Big5",
"preferred_font" => "MingLiu,10,0"
),
"cs" => array(
"langcode" => "0x405 Czech",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT,
),
"da" => array(
"langcode" => "0x406 Danish",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "PEAR Manualen"
),
"de" => array(
"langcode" => "0x407 German (Germany)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "PEAR Handbuch",
),
"el" => array(
"langcode" => "0x408 Greek",
"preferred_charset" => "Windows-1253",
"mime_charset_name" => "Windows-1253",
"preferred_font" => self::DEFAULT_FONT
),
"en" => array(
"langcode" => "0x809 English (United Kingdom)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "PEAR Manual",
),
"es" => array(
"langcode" => "0xc0a Spanish (International Sort)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT
),
"fr" => array(
"langcode" => "0x40c French (France)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "Manuel de PEAR"
),
"fi" => array(
"langcode" => "0x40b Finnish",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT
),
"he" => array(
"langcode" => "0x40d Hebrew",
"preferred_charset" => "Windows-1255",
"mime_charset_name" => "Windows-1255",
"preferred_font" => self::DEFAULT_FONT
),
"hu" => array(
"langcode" => "0x40e Hungarian",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT
),
"it" => array(
"langcode" => "0x410 Italian (Italy)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "Manuale PEAR",
),
"ja" => array(
"langcode" => "0x411 Japanese",
"preferred_charset" => "CP932",
"mime_charset_name" => "csWindows31J",
"preferred_font" => "MS PGothic,10,0"
),
"kr" => array(
"langcode" => "0x412 Korean",
"preferred_charset" => "CP949",
"mime_charset_name" => "EUC-KR",
"preferred_font" => "Gulim,10,0"
),
"nl" => array(
"langcode" => "0x413 Dutch (Netherlands)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT
),
"no" => array(
"langcode" => "0x414 Norwegian (Bokmal)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT
),
"pl" => array(
"langcode" => "0x415 Polish",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT
),
"pt_BR" => array(
"langcode" => "0x416 Portuguese (Brazil)",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT,
"title" => "Manual do PEAR",
),
"ro" => array(
"langcode" => "0x418 Romanian",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT
),
"ru" => array(
"langcode" => "0x419 Russian",
"preferred_charset" => "Windows-1251",
"mime_charset_name" => "Windows-1251",
"preferred_font" => self::DEFAULT_FONT
),
"sk" => array(
"langcode" => "0x41b Slovak",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT
),
"sl" => array(
"langcode" => "0x424 Slovenian",
"preferred_charset" => "Windows-1250",
"mime_charset_name" => "Windows-1250",
"preferred_font" => self::DEFAULT_FONT
),
"sv" => array(
"langcode" => "0x41d Swedish",
"preferred_charset" => "Windows-1252",
"mime_charset_name" => "Windows-1252",
"preferred_font" => self::DEFAULT_FONT
),
"zh" => array(
"langcode" => "0x804 Simplified Chinese",
"preferred_charset" => "CP936",
"mime_charset_name" => "gb2312",
"preferred_font" => "simsun,10,0"
)
);
// HTML Help Workshop project file
protected $hhpStream;
// CHM Table of contents
protected $hhcStream;
protected $currentTocDepth = 0;
protected $lastContent = null;
protected $toc;
// CHM Index Map
protected $hhkStream;
// Project files Output directory
protected $chmdir;
public function __construct(array $IDs, $ext = "html", $dir = "chm") {
parent::__construct($IDs, $ext);
$this->chmdir = $GLOBALS['OPTIONS']['output_dir'] . $dir . DIRECTORY_SEPARATOR;
if(!file_exists($this->chmdir) || is_file($this->chmdir))
mkdir($this->chmdir) or die("Can't create the CHM project directory");
$this->outputdir = $GLOBALS['OPTIONS']['output_dir'] . $dir . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
if(!file_exists($this->outputdir) || is_file($this->outputdir))
mkdir($this->outputdir) or die("Can't create the cache directory");
$lang = $GLOBALS['OPTIONS']['language'];
$this->hhpStream = fopen($this->chmdir . "pear_manual_{$lang}.hhp", "w");
$this->hhcStream = fopen($this->chmdir . "pear_manual_{$lang}.hhc", "w");
$this->hhkStream = fopen($this->chmdir . "pear_manual_{$lang}.hhk", "w");
foreach(array("reset-fonts", "style", "manual") as $name) {
if (!file_exists($this->outputdir . "$name.css")) {
file_put_contents($this->outputdir . "$name.css", $this->fetchStylesheet($name));
}
}
self::headerChm();
}
public function __destruct() {
self::footerChm();
fclose($this->hhpStream);
fclose($this->hhcStream);
fclose($this->hhkStream);
parent::__destruct();
}
protected function appendChm($name, $ref, $isChunk, $hasChild) {
switch ($isChunk) {
case PhDReader::OPEN_CHUNK :
$this->currentTocDepth++;
fwrite($this->hhpStream, "{$ref}\n");
fwrite($this->hhcStream, "{$this->offset(1)}<li><object type=\"text/sitemap\">\n" .
"{$this->offset(3)}<param name=\"Name\" value=\"" . htmlentities($name) . "\">\n" .
"{$this->offset(3)}<param name=\"Local\" value=\"{$ref}\">\n" .
"{$this->offset(2)}</object>\n");
if ($hasChild) fwrite($this->hhcStream, "{$this->offset(2)}<ul>\n");
fwrite($this->hhkStream, " <li><object type=\"text/sitemap\">\n" .
" <param name=\"Local\" value=\"{$ref}\">\n" .
" <param name=\"Name\" value=\"" . htmlentities(self::cleanIndexName($name)) . "\">\n" .
" </object>\n </li>\n");
break;
case PhDReader::CLOSE_CHUNK :
if ($hasChild) {
fwrite($this->hhcStream, "{$this->offset(2)}</ul>\n");
}
$this->currentTocDepth--;
break;
}
}
/**
* Clean up the index name.
* Newlines and double spaces don't look that good in some chm viewer apps.
*
* @param string $value Value to fix
*
* @return string Fixed/cleaned value
*/
protected static function cleanIndexName($value)
{
return str_replace(
array("\n", "\r", ' '),
array('', '', ' '),
$value
);
}
protected function headerChm() {
$lang = $GLOBALS['OPTIONS']['language'];
fwrite($this->hhpStream, '[OPTIONS]
Compatibility=1.1 or later
Compiled file=pear_manual_' . $lang . '.chm
Contents file=pear_manual_' . $lang . '.hhc
Index file=pear_manual_' . $lang . '.hhk
Default Window=doc
Default topic=res\index.html
Display compile progress=Yes
Full-text search=Yes
Language=' . $this->LANGUAGES[$lang]["langcode"] . '
Title=' . ($this->LANGUAGES[$lang]["title"] ? $this->LANGUAGES[$lang]["title"] : self::DEFAULT_TITLE) . '
Default Font=' . ($this->LANGUAGES[$lang]["preferred_font"] ? $this->LANGUAGES[$lang]["preferred_font"] : self::DEFAULT_FONT). '
[WINDOWS]
doc="' . ($this->LANGUAGES[$lang]["title"] ? $this->LANGUAGES[$lang]["title"] : self::DEFAULT_TITLE) . '","pear_manual_' . $lang . '.hhc","pear_manual_' . $lang . '.hhk","res\index.html","res\index.html",,,,,0x23520,,0x386e,,,,,,,,0
[FILES]
res\reset-fonts.css
res\style.css
res\manual.css
');
fwrite($this->hhcStream, '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta name="generator" content="PhD">
<!-- Sitemap 1.0 -->
</head>
<body>
<object type="text/site properties">
<param name="Window Styles" value="0x800227">
</object>
<ul>
');
fwrite($this->hhkStream, '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta name="generator" content="PhD">
<!-- Sitemap 1.0 -->
</head>
<body>
<object type="text/site properties">
<param name="Window Styles" value="0x800227">
</object>
<ul>
');
}
protected function footerChm() {
fwrite($this->hhcStream, " </ul>\n" .
" </body>\n" .
"</html>\n");
fwrite($this->hhkStream, " </ul>\n" .
" </body>\n" .
"</html>\n");
}
public function appendData($data, $isChunk) {
if ($this->lastContent)
$this->appendChm($this->lastContent["name"], $this->lastContent["reference"],
$isChunk, $this->lastContent["hasChild"]);
$this->lastContent = null;
return parent::appendData($data, $isChunk);
}
public function format_chunk($open, $name, $attrs, $props) {
$this->collectContent($attrs);
return parent::format_chunk($open, $name, $attrs, $props);
}
public function format_container_chunk($open, $name, $attrs, $props) {
$this->collectContent($attrs);
return parent::format_container_chunk($open, $name, $attrs, $props);
}
public function format_root_chunk($open, $name, $attrs, $props) {
$this->collectContent($attrs);
return parent::format_root_chunk($open, $name, $attrs, $props);
}
/**
* Generate the HTML header.
* Uses parent::header() and adds some additional stylesheets.
*
* @param string $id Page ID
*
* @return string Header HTML
*/
public function header($id)
{
$header = parent::header($id);
// Add CSS link to <head>
$header = preg_replace('#( *)</head>#',
'$1 <link media="all" rel="stylesheet" type="text/css" href="reset-fonts.css"/>
$1 <link media="all" rel="stylesheet" type="text/css" href="style.css"/>
$1 <link media="all" rel="stylesheet" type="text/css" href="manual.css"/>
$1</head>',
$header
);
return $header;
}
private function collectContent($attrs) {
if (isset($attrs[PhDReader::XMLNS_XML]["id"])) {
$id = $attrs[PhDReader::XMLNS_XML]["id"];
$this->lastContent = array(
"name" => PhDHelper::getDescription($id),
"reference" => "res\\" .
(PhDHelper::getFilename($id) ? PhDHelper::getFilename($id) : $id) . "." . $this->ext,
"hasChild" => (count(PhDHelper::getChildren($id)) > 0)
);
}
}
private function fetchStylesheet($name) {
$stylesheet = file_get_contents("http://pear.php.net/css/$name.css");
if ($stylesheet) return $stylesheet;
else {
v("Stylesheet $name not fetched. Uses default rendering style.", E_USER_WARNING);
return "";
}
}
private function offset($offset) {
$spaces = "";
for ($i = 0; $i < $offset + 2 * $this->currentTocDepth; $i++)
$spaces .= " ";
return $spaces;
}
}
|