';
}
}
/* Functions from PhDThemeXhtml */
/**
* Called after the constructor finished.
* This is needed since themes set their outputdir and outputfile
* in the constructor. That file/dir is used for mediamanager.
* That means we cannot instantiate and complete the manager in our
* constructor centrally.
*
* Each theme needs its own media manager, since the manager contains
* the output path.
*
* @return void
*/
public function postConstruct() {
$this->mediamanager = new MediaManager(Config::xml_root());
$outputdir = $this->getOutputDir();
if (isset($outputdir) && $outputdir) {
$this->mediamanager->output_dir = $outputdir;
} else {
$this->mediamanager->output_dir = Config::output_dir() . '/' . strtolower($this->getFormatName()) . '-data/';
$this->mediamanager->relative_ref_path = basename($this->mediamanager->output_dir) . '/';
}
}
/* Functions from XHTMLPhDFormat */
/**
* Closes a para tag when we are already in a paragraph.
*
* @return string HTML code
*
* @see $openPara
* @see restorePara()
*/
public function escapePara() {
if (!$this->openPara) {
return '';
}
if (!isset($this->escapedPara[$this->openPara])) {
$this->escapedPara[$this->openPara] = 1;
return '';
} else {
++$this->escapedPara[$this->openPara];
return '';
}
}
/**
* Opens a para tag again when we escaped one before.
*
* @return string HTML code
*
* @see $openPara
* @see escapePara()
*/
public function restorePara() {
if (!$this->openPara || !isset($this->escapedPara[$this->openPara])) {
return '';
}
if ($this->escapedPara[$this->openPara] == 1) {
unset($this->escapedPara[$this->openPara]);
return '
';
} else {
--$this->escapedPara[$this->openPara];
return '';
}
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Format/Factory.php 0000644 00000004541 11767147641 0014032 0 ustar 00 pversion;
}
public final function setPackageVersion($version) {
$this->pversion = $version;
}
public final function getOutputFormats() {
return array_keys($this->formats);
}
public final function registerOutputFormats($formats) {
$this->formats = $formats;
}
public final function getOptionsHandler() {
return $this->optionsHandler;
}
public final function registerOptionsHandler(Options_Interface $optionsHandler) {
$this->optionsHandler = $optionsHandler;
}
protected final function setPackageName($name) {
if (!is_string($name)) {
throw new \Exception("Package names must be strings..");
}
$this->packageName = $name;
}
public final function getPackageName() {
return $this->packageName;
}
public final function createFormat($format) {
if (isset($this->formats[$format]) && $this->formats[$format]) {
$classname = __NAMESPACE__ . "\\" . $this->formats[$format];
$obj = new $classname();
if (!($obj instanceof Format)) {
throw new \Exception("All Formats must inherit Format");
}
return $obj;
}
trigger_error("This format is not supported by this package", E_USER_ERROR);
}
public static final function createFactory($package) {
static $factories = array();
if (!is_string($package)) {
throw new \Exception("Package name must be string..");
}
if (!isset($factories[$package])) {
$classname = __NAMESPACE__ . "\\Package_" . $package . "_Factory";
$factory = new $classname();
if (!($factory instanceof Format_Factory)) {
throw new \Exception("All Factories must inherit Format_Factory");
}
$factories[$package] = $factory;
}
return $factories[$package];
}
public final function __toString() {
return $this->getPackageName();
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Options/Handler.php 0000644 00000036646 11767147641 0014216 0 ustar 00 'f:', // The format to render (xhtml, pdf...)
'noindex' => 'I', // Do not re-index
'forceindex' => 'r', // Force re-indexing under all circumstances
'notoc' => 't', // Do not re-create TOC
'docbook:' => 'd:', // The Docbook XML file to render from (.manual.xml)
'output:' => 'o:', // The output directory
'outputfilename:' => 'F:', // The output filename (only useful for bightml/bigpdf)
'partial:' => 'p:', // The ID to render (optionally ignoring its children)
'skip:' => 's:', // The ID to skip (optionally skipping its children too)
'verbose:' => 'v::', // Adjust the verbosity level
'list' => 'l', // List supported packages/formats
'lang::' => 'L:', // Language hint (used by the CHM)
'color:' => 'c:', // Use color output if possible
'highlighter:' => 'g:', // Class used as source code highlighter
'version' => 'V', // Print out version information
'help' => 'h', // Print out help
'package:' => 'P:', // The package of formats
'css:' => 'C:', // External CSS
'xinclude' => 'x', // Automatically process xinclude directives
'ext:' => 'e:', // The file-format extension to use, including the dot
'saveconfig::' => 'S::', // Save the generated config ?
'quit' => 'Q', // Do not run the render. Use with -S to just save the config.
'memoryindex' => 'M', // Use sqlite in memory rather then file
'packagedir' => 'k:', // Include path for external packages
);
}
public function option_M($k, $v)
{
$this->option_memoryindex($k, $v);
}
public function option_memoryindex($k, $v)
{
Config::set_memoryindex(true);
}
public function option_f($k, $v)
{
if ($k == "f") {
return $this->option_format($k, $v);
} else {
return $this->option_outputfilename($k, $v);
}
}
public function option_format($k, $v)
{
$formats = array();
foreach((array)$v as $i => $val) {
if (!in_array($val, $formats)) {
$formats[] = $val;
}
}
Config::set_output_format($formats);
}
public function option_e($k, $v)
{
$this->option_ext($k, $v);
}
public function option_ext($k, $v)
{
$bool = self::boolval($v);
if ($bool === false) {
// `--ext=false` means no extension will be used
$v = "";
Config::setExt($v);
} elseif ($bool === null) {
// `--ext=true` means use the default extension,
// `--ext=".foo"` means use ".foo" as the extension
Config::setExt($v);
}
}
public function option_g($k, $v)
{
$this->option_highlighter($k, $v);
}
public function option_highlighter($k, $v)
{
Config::setHighlighter($v);
}
public function option_i($k, $v)
{
$this->option_noindex($k, 'true');
}
public function option_noindex($k, $v)
{
Config::set_no_index(true);
}
public function option_r($k, $v)
{
$this->option_forceindex($k, 'true');
}
public function option_forceindex($k, $v)
{
Config::set_force_index(true);
}
public function option_t($k, $v)
{
$this->option_notoc($k, 'true');
}
public function option_notoc($k, $v)
{
Config::set_no_toc(true);
}
public function option_d($k, $v)
{
$this->option_docbook($k, $v);
}
public function option_docbook($k, $v)
{
if (is_array($v)) {
trigger_error("Can only parse one file at a time", E_USER_ERROR);
}
if (!file_exists($v) || is_dir($v) || !is_readable($v)) {
trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR);
}
Config::set_xml_root(dirname($v));
Config::set_xml_file($v);
}
public function option_o($k, $v)
{
$this->option_output($k, $v);
}
public function option_output($k, $v)
{
if (is_array($v)) {
trigger_error("Only a single output location can be supplied", E_USER_ERROR);
}
if (!is_dir($v)) {
mkdir($v, 0777, true);
}
if (!is_dir($v) || !is_readable($v)) {
trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR);
}
$v = (substr($v, strlen($v) - strlen(DIRECTORY_SEPARATOR)) == DIRECTORY_SEPARATOR) ? $v : ($v . DIRECTORY_SEPARATOR);
Config::set_output_dir($v);
}
public function option_outputfilename($k, $v)
{
if (is_array($v)) {
trigger_error("Only a single output location can be supplied", E_USER_ERROR);
}
$file = basename($v);
Config::set_output_filename($file);
}
public function option_p($k, $v)
{
if ($k == "P") {
return $this->option_package($k, $v);
}
$this->option_partial($k, $v);
}
public function option_partial($k, $v)
{
$render_ids = Config::render_ids();
foreach((array)$v as $i => $val) {
$recursive = true;
if (strpos($val, "=") !== false) {
list($val, $recursive) = explode("=", $val);
if (!is_numeric($recursive) && defined($recursive)) {
$recursive = constant($recursive);
}
$recursive = (bool) $recursive;
}
$render_ids[$val] = $recursive;
}
Config::set_render_ids($render_ids);
}
public function option_package($k, $v) {
foreach((array)$v as $package) {
if (!in_array($package, Config::getSupportedPackages())) {
$supported = implode(', ', Config::getSupportedPackages());
trigger_error("Invalid Package (Tried: '$package' Supported: '$supported')", E_USER_ERROR);
}
}
Config::set_package($v);
}
public function option_q($k, $v)
{
$this->option_quit($k, $v);
}
public function option_quit($k, $v)
{
Config::set_quit(true);
}
public function option_s($k, $v)
{
if ($k == "S") {
return $this->option_saveconfig($k, $v);
}
$this->option_skip($k, $v);
}
public function option_skip($k, $v)
{
$skip_ids = Config::skip_ids();
foreach((array)$v as $i => $val) {
$recursive = true;
if (strpos($val, "=") !== false) {
list($val, $recursive) = explode("=", $val);
if (!is_numeric($recursive) && defined($recursive)) {
$recursive = constant($recursive);
}
$recursive = (bool) $recursive;
}
$skip_ids[$val] = $recursive;
}
Config::set_skip_ids($skip_ids);
}
public function option_saveconfig($k, $v)
{
if (is_array($v)) {
trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR);
}
// No arguments passed, default to 'true'
if (is_bool($v)) {
$v = "true";
}
$val = self::boolval($v);
if (is_bool($val)) {
Config::set_saveconfig($v);
} else {
trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR);
}
}
public function option_v($k, $v)
{
if ($k[0] === 'V') {
$this->option_version($k, $v);
return;
}
$this->option_verbose($k, $v);
}
public function option_verbose($k, $v)
{
static $verbose = 0;
foreach((array)$v as $i => $val) {
foreach(explode("|", $val) as $const) {
if (defined($const)) {
$verbose |= (int)constant($const);
} elseif (is_numeric($const)) {
$verbose |= (int)$const;
} elseif (empty($const)) {
$verbose = max($verbose, 1);
$verbose <<= 1;
} else {
trigger_error("Unknown option passed to --$k, '$const'", E_USER_ERROR);
}
}
}
Config::set_verbose($verbose);
error_reporting($GLOBALS['olderrrep'] | $verbose);
}
public function option_l($k, $v)
{
if ($k == "L") {
return $this->option_lang($k, $v);
}
$this->option_list($k, $v);
}
public function option_list($k, $v)
{
$packageList = Config::getSupportedPackages();
echo "Supported packages:\n";
foreach ($packageList as $package) {
$formats = Format_Factory::createFactory($package)->getOutputFormats();
echo "\t" . $package . "\n\t\t" . implode("\n\t\t", $formats) . "\n";
}
exit(0);
}
public function option_lang($k, $v)
{
Config::set_language($v);
}
public function option_c($k, $v)
{
if ($k == "C") {
return $this->option_css($k, $v);
}
$this->option_color($k, $v);
}
public function option_color($k, $v)
{
if (is_array($v)) {
trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR);
}
$val = self::boolval($v);
if (is_bool($val)) {
Config::setColor_output($val);
} else {
trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR);
}
}
public function option_css($k, $v) {
$styles = array();
foreach((array)$v as $key => $val) {
if (!in_array($val, $styles)) {
$styles[] = $val;
}
}
Config::set_css($styles);
}
public function option_k($k, $v)
{
$this->option_packagedir($k, $v);
}
public function option_packagedir($k, $v)
{
$packages = Config::package_dirs();
foreach((array)$v as $key => $val) {
if ($path = realpath($val)) {
if (!in_array($path, $packages)) {
$packages[] = $path;
}
} else {
v('Invalid path: %s', $val, E_USER_WARNING);
}
}
Config::set_package_dirs($packages);
}
public function option_x($k, $v)
{
$this->option_xinclude($k, 'true');
}
public function option_xinclude($k, $v)
{
Config::set_process_xincludes(true);
}
/**
* Prints out the current PhD and PHP version.
* Exits directly.
*
* @return void
*/
public function option_version($k, $v)
{
$color = Config::phd_info_color();
$output = Config::phd_info_output();
fprintf($output, "%s\n", term_color('PhD Version: ' . Config::VERSION, $color));
$packageList = Config::getSupportedPackages();
foreach ($packageList as $package) {
$version = Format_Factory::createFactory($package)->getPackageVersion();
fprintf($output, "\t%s: %s\n", term_color($package, $color), term_color($version, $color));
}
fprintf($output, "%s\n", term_color('PHP Version: ' . phpversion(), $color));
fprintf($output, "%s\n", term_color(Config::copyright(), $color));
exit(0);
}
public function option_h($k, $v)
{
$this->option_help($k, $v);
}
public function option_help($k, $v)
{
echo "PhD version: " .Config::VERSION;
echo "\n" . Config::copyright() . "\n
-v
--verbose Adjusts the verbosity level
-f
--format The build format to use
-P
--package The package to use
-I
--noindex Do not index before rendering but load from cache
(default: false)
-M
--memoryindex Do not save indexing into a file, store it in memory.
(default: false)
-r
--forceindex Force re-indexing under all circumstances
(default: false)
-t
--notoc Do not rewrite TOC before rendering but load from
cache (default: false)
-d
--docbook The Docbook file to render from
-x
--xinclude Process XML Inclusions (XInclude)
(default: false)
-p
--partial The ID to render, optionally skipping its children
chunks (default to true; render children)
-s
--skip The ID to skip, optionally skipping its children
chunks (default to true; skip children)
-l
--list Print out the supported packages and formats
-o
--output The output directory (default: .)
-F filename
--outputfilename filename Filename to use when writing standalone formats
(default: -.)
-L
--lang The language of the source file (used by the CHM
theme). (default: en)
-c
--color Enable color output when output is to a terminal
(default: " . (Config::color_output() ? 'true' : 'false') . ")
-C
--css Link for an external CSS file.
-g
--highlighter Use custom source code highlighting php class
-V
--version Print the PhD version information
-h
--help This help
-e
--ext The alternative filename extension to use,
including the dot. Use 'false' for no extension.
-S
--saveconfig Save the generated config (default: false).
-Q
--quit Don't run the build. Use with --saveconfig to
just save the config.
-k
--packagedir Use an external package directory.
Most options can be passed multiple times for greater effect.
";
exit(0);
}
/**
* Makes a string into a boolean (i.e. on/off, yes/no, ..)
*
* Returns boolean true/false on success, null on failure
*
* @param string $val
* @return bool
*/
public static function boolval($val) {
if (!is_string($val)) {
return null;
}
switch ($val) {
case "on":
case "yes":
case "true":
case "1":
return true;
break;
case "off":
case "no":
case "false":
case "0":
return false;
break;
default:
return null;
}
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Options/Interface.php 0000644 00000000251 11767147641 0014520 0 ustar 00 defaultHandler = new Options_Handler();
$this->packageHandlers = $this->loadPackageHandlers();
}
public static function instance() {
static $instance = null;
if ($instance == null) {
$instance = new self();
}
return $instance;
}
private function loadPackageHandlers() {
$packageList = Config::getSupportedPackages();
$list = array();
foreach ($packageList as $package) {
if ($handler = Format_Factory::createFactory($package)->getOptionsHandler()) {
$list[strtolower($package)] = $handler;
}
}
return $list;
}
public function handlerForOption($option) {
if (method_exists($this->defaultHandler, "option_{$option}")) {
return array($this->defaultHandler, "option_{$option}");
}
$opt = explode('-', $option);
$package = strtolower($opt[0]);
if (isset($this->packageHandlers[$package])) {
if (method_exists($this->packageHandlers[$package], "option_{$opt[1]}")) {
return array($this->packageHandlers[$package], "option_{$opt[1]}");
}
}
return NULL;
}
public function getLongOptions() {
$defaultOptions = array_keys($this->defaultHandler->optionList());
$packageOptions = array();
foreach ($this->packageHandlers as $package => $handler) {
foreach ($handler->optionList() as $opt) {
$packageOptions[] = $package . '-' . $opt;
}
}
return array_merge($defaultOptions, $packageOptions);
}
public function getShortOptions() {
return implode('', array_values($this->defaultHandler->optionList()));
}
/**
* Checks if all options passed are valid.
*
* Fix Bug #54217 - Warn about nonexisting parameters
*/
private function checkOptions() {
$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
$short = str_split(str_replace(':', '', $this->getShortOptions()));
$long = array();
foreach ($this->getLongOptions() as $opt) {
$long[] = str_replace(':', '', $opt);
}
for ($i=1; $i < $argc; $i++) {
if (substr($argv[$i], 0, 2) == '--') {
if (!in_array(substr($argv[$i], 2), $long)) {
trigger_error('Invalid long option ' . $argv[$i], E_USER_ERROR);
}
} elseif (substr($argv[$i], 0, 1) == '-') {
if (!in_array(substr($argv[$i], 1), $short)) {
trigger_error('Invalid short option ' . $argv[$i], E_USER_ERROR);
}
}
}
}
public static function getopt() {
$self = self::instance();
//validate options
$self->checkOptions();
$args = getopt($self->getShortOptions(), $self->getLongOptions());
if ($args === false) {
trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR);
}
foreach ($args as $k => $v) {
$handler = $self->handlerForOption($k);
if (is_callable($handler)) {
call_user_func($handler, $k, $v);
} else {
var_dump($k, $v);
trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR);
}
}
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Reader/Partial.php 0000644 00000011064 11767147641 0013767 0 ustar 00 partial = $render_ids;
} else {
$this->partial[$render_ids] = 1;
}
$skip_ids = Config::skip_ids();
if ($skip_ids !== NULL) {
if (is_array($skip_ids)) {
$this->skip = $skip_ids;
} else {
$this->skip[$skip_ids] = 1;
}
}
} else {
throw new \Exception("Didn't get any IDs to seek");
}
$parents = array();
if (file_exists(Config::output_dir() . "index.sqlite")) {
$sqlite = new \SQLite3(Config::output_dir() . "index.sqlite");
// Fetch all ancestors of the ids we should render
foreach($render_ids as $p => $v) {
do {
$id = $sqlite->escapeString($p);
$row = $sqlite->query("SELECT parent_id FROM ids WHERE docbook_id = '$id'")->fetchArray(SQLITE3_ASSOC);
if ($row["parent_id"]) {
$parents[] = $p = $row["parent_id"];
continue;
}
break;
} while(1);
}
}
$this->parents = $parents;
}
public function read() {
static $seeked = 0;
static $currently_reading = false;
static $currently_skipping = false;
static $arrayPartial = array();
static $arraySkip = array();
$ignore = false;
while($ret = parent::read()) {
$id = $this->getAttributeNs("id", self::XMLNS_XML);
$currentPartial = end($arrayPartial);
$currentSkip = end($arraySkip);
if (isset($this->partial[$id])) {
if ($currentPartial == $id) {
v("%s done", $id, VERBOSE_PARTIAL_READING);
unset($this->partial[$id]);
--$seeked;
$currently_reading = false;
array_pop($arrayPartial);
} else {
v("Starting %s...", $id, VERBOSE_PARTIAL_READING);
$currently_reading = $id;
++$seeked;
$arrayPartial[] = $id;
}
return $ret;
} elseif (isset($this->skip[$id])) {
if ($currentSkip == $id) {
v("%s done", $id, VERBOSE_PARTIAL_READING);
unset($this->skip[$id]);
$currently_skipping = false;
$ignore = false;
array_pop($arraySkip);
} else {
v("Skipping %s...", $id, VERBOSE_PARTIAL_READING);
$currently_skipping = $id;
$ignore = true;
$arraySkip[] = $id;
}
} elseif ($currently_skipping && $this->skip[$currently_skipping]) {
if ($currentSkip == $id) {
v("Skipping child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
} else {
v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
}
$ignore = true;
} elseif ($currently_reading && $this->partial[$currently_reading]) {
if ($currentPartial == $id) {
v("Rendering child of %s, %s", $currently_reading, $id, VERBOSE_PARTIAL_CHILD_READING);
} else {
v("%s done", $id, VERBOSE_PARTIAL_CHILD_READING);
}
return $ret;
} elseif (empty($this->partial)) {
return false;
} else {
// If we are used by the indexer then we have no clue about the
// parents :)
if ($id && $this->parents) {
// If this id isn't one of our ancestors we can jump
// completely over it
if (!in_array($id, $this->parents)) {
parent::next();
}
}
$ignore = true;
}
}
return $ret;
}
}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/PI/DBHTMLHandler.php 0000644 00000010434 11767147641 0013751 0 ustar 00 "",
"bgcolor" => "",
"cellpadding" => "",
"cellspacing" => "",
"class" => "",
"dir" => "",
"filename" => "",
"funcsynopsis-style" => "",
"img.src.path" => "",
"label-width" => "",
"linenumbering.everyNth" => "",
"linenumbering.separator" => "",
"linenumbering.width" => "",
"list-presentation" => "",
"list-width" => "",
"row-height" => "",
"start" => "",
"stop-chunking" => "",
"table-summary" => "",
"table-width" => "",
"term-presentation" => "",
"term-separator" => "",
"term-width" => "",
"toc" => "",
//Attributes for "",
"padding" => "",
);
public function __construct($format) {
parent::__construct($format);
}
public function parse($target, $data) {
$pattern = "/(?[\w]+[\w\-\.]*)[\s]*=[\s]*\"(?[^\"]*)\"/";
preg_match_all($pattern, $data, $matches);
for ($i = 0; $i < count($matches["attr"]); $i++) {
$attr = trim($matches["attr"][$i]);
$value = trim($matches["value"][$i]);
$this->setAttribute($attr, $value);
}
//Hack for stop-chunking
if ($data == "stop-chunking") {
$this->setAttribute("stop-chunking", true);
}
//Parse parseDBTimestamp();
$this->setAttribute("padding", "");
$this->setAttribute("format", "");
}
}
public function setAttribute($attr, $value) {
if (isset($this->attrs[$attr])) {
$this->attrs[$attr] = $value;
}
}
public function getAttribute($attr) {
return isset($this->attrs[$attr]) ? $this->attrs[$attr] : false;
}
/**
* Function to parse dbtimestamp processing instructions
* Reference: http://www.sagehill.net/docbookxsl/Datetime.html
*/
public function parseDBTimestamp() {
// Array to parse formats from dbtimestamp to date()
$parseArray = array(
"a" => "D", // Day abbreviation
"A" => "l", // Day name
"b" => "M", // Month abbreviation
"c" => "c", // ISO date and time
"B" => "F", // Month name
"d" => "d", // Day in month
"H" => "H", // Hour in day
"j" => "z", // Day in year
"m" => "m", // Month in year
"M" => "i", // Minute in hour
"S" => "s", // Second in minute
"U" => "W", // Week in year
"w" => "w", // Day in week
"x" => "Y-m-dP", // ISO date
"X" => "H:i:sP", // ISO time
"Y" => "Y", // Year
);
if ($this->getAttribute("padding") == "0") {
$parseArray["d"] = "j";
$parseArray["H"] = "G";
$parseArray["m"] = "n";
}
$format = $this->getAttribute("format");
if (!$format) {
return $this->format->appendData(date('c'));
}
$dateFormat = "";
$len = strlen($format);
for ($i = 0; $i < $len; $i++) {
$dateFormat .= isset($parseArray[$format[$i]])
? $parseArray[$format[$i]]
: $format[$i];
}
return $this->format->appendData(date($dateFormat));
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/PI/PHPDOCHandler.php 0000644 00000016054 11767147641 0013760 0 ustar 00 [\w]+[\w\-\.]*)[\s]*=[\s]*\"(?[^\"]*)\"/";
preg_match($pattern, $data, $matches);
switch($matches["attr"]) {
case "print-version-for":
// FIXME: Figureout a way to detect the current language (for unknownversion)
if (!$this->format instanceof Index) {
return $this->format->autogenVersionInfo($matches["value"], "en");
}
return;
case "generate-index-for":
if ($this->format instanceof Index) {
return;
}
switch($matches["value"]) {
case "function":
case "refentry":
$tmp = $this->format->getRefs();
$ret = "";
$refs = array();
$info = array();
foreach($tmp as $id) {
$filename = $this->format->createLink($id, $desc);
$refs[$filename] = $desc;
$info[$filename] = array($this->format->getLongDescription($id, $islong), $islong);
}
natcasesort($refs);
// Nav bar to jump directly to a character
$chars = array_count_values(array_map(function($ref){ return strtolower($ref[0]); }, $refs));
$ret = '
";
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Autoloader.php 0000644 00000001714 11767147641 0013271 0 ustar 00 array(),
'chunk_extra' => array(
'legalnotice' => true,
'phpdoc:exception' => true,
),
'no_index' => false,
'force_index' => false,
'no_toc' => false,
'xml_root' => '.',
'xml_file' => './.manual.xml',
'lang_dir' => './',
'language' => 'en',
'fallback_language' => 'en',
'verbose' => VERBOSE_DEFAULT,
'date_format' => 'H:i:s',
'render_ids' => array(
),
'skip_ids' => array(
),
'color_output' => true,
'output_dir' => './output/',
'output_filename' => '',
'intermediate_output_dir' => '.',
'php_error_output' => STDERR,
'php_error_color' => '01;31', // Red
'user_error_output' => STDERR,
'user_error_color' => '01;33', // Yellow
'phd_info_output' => STDOUT,
'phd_info_color' => '01;32', // Green
'phd_warning_output' => STDOUT,
'phd_warning_color' => '01;35', // Magenta
'highlighter' => 'phpdotnet\\phd\\Highlighter',
'package' => array(
'Generic',
),
'css' => array(),
'process_xincludes' => false,
'ext' => null,
'package_dirs' => array(__INSTALLDIR__),
'saveconfig' => false,
'quit' => false,
'indexcache' => '',
'memoryindex' => '',
);
private static $optionArray = null;
public static function init(array $a) {
// Override any defaults due to operating system constraints
// and copy defaults to working optionArray
if ($newInit = is_null(self::$optionArray)) {
// By default, Windows does not support colors on the console.
// ANSICON by Jason Hood (http://adoxa.110mb.com/ansicon/index.html)
// can be used to provide colors at the console on Windows.
// Color output can still be enabled via the command line parameters --color
if('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
self::$optionArrayDefault['color_output'] = false;
}
self::$optionArray = self::$optionArrayDefault;
}
// now merge other options
self::$optionArray = array_merge(self::$optionArray, (array)$a);
if ($newInit) {
// Always set saveconfig to false for a new initialization, even after restoring
// a save configuration. This allows additional options to be added at the
// command line without them being automatically saved.
self::$optionArray['saveconfig'] = false;
// As well as the quit option.
self::$optionArray['quit'] = false;
// Set the error reporting level to the restored level.
error_reporting($GLOBALS['olderrrep'] | self::$optionArray['verbose']);
}
}
public static function getAllFiltered() {
$retval = self::$optionArray;
return self::exportable($retval);
}
public static function exportable($val) {
foreach($val as $k => &$opt) {
if (is_array($opt)) {
$opt = self::exportable($opt);
continue;
}
if (is_resource($opt)) {
unset($val[$k]);
}
}
return $val;
}
/**
* Maps static function calls to config option setter/getters.
*
* To set an option, call "Config::setOptionname($value)".
* To retrieve an option, call "Config::optionname()".
*
* It is also possible, but deprecated, to call
* "Config::set_optionname($value)".
*
* @param string $name Name of called function
* @param array $params Array of function parameters
*
* @return mixed Config value that was requested or set.
*/
public static function __callStatic($name, $params)
{
$name = strtolower($name); // FC if this becomes case-sensitive
if (strncmp($name, 'set', 3) === 0) {
$name = substr($name, 3);
if ($name[0] === '_') {
$name = substr($name, 1);
}
if (strlen($name) < 1 || count($params) !== 1) { // assert
trigger_error('Misuse of config option setter', E_USER_ERROR);
}
self::$optionArray[$name] = $params[0];
// no return, intentional
}
return isset(self::$optionArray[$name])
? self::$optionArray[$name]
: NULL;
}
public static function getSupportedPackages() {
$packageList = array();
foreach(Config::package_dirs() as $dir) {
foreach (glob($dir . "/phpdotnet/phd/Package/*", GLOB_ONLYDIR) as $item) {
$baseitem = basename($item);
if ($baseitem[0] != '.') {
$packageList[] = $baseitem;
}
}
}
return $packageList;
}
public static function setColor_output($color_output)
{
// Disable colored output if the terminal doesn't support colors
if ($color_output && function_exists('posix_isatty')) {
if (!posix_isatty(Config::phd_info_output())) {
Config::setPhd_info_color(false);
}
if (!posix_isatty(Config::phd_warning_output())) {
Config::setPhd_warning_color(false);
}
if (!posix_isatty(Config::php_error_output())) {
Config::setPhd_error_color(false);
}
if (!posix_isatty(Config::user_error_output())) {
Config::setUser_error_color(false);
}
}
self::$optionArray['color_output'] = $color_output;
}
public static function set_color_output($color_output)
{
trigger_error('Use setColor_output()', E_USER_DEPRECATED);
}
public static function copyright() {
return sprintf('Copyright(c) 2007-%s The PHP Documentation Group', date('Y'));
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Format.php 0000644 00000046772 11767147641 0012437 0 ustar 00 sqlite = $sqlite;
$this->sortIDs();
}
}
abstract public function transformFromMap($open, $tag, $name, $attrs, $props);
abstract public function UNDEF($open, $name, $attrs, $props);
abstract public function TEXT($value);
abstract public function CDATA($value);
/**
* Create link to chunk.
*
* @param string $for Chunk ID
* @param string &$desc Description of link, to be filled if neccessary
* @param integer $type Format of description, Format::SDESC or
* Format::LDESC
*
* @return string Relative or absolute URI to access $for
*/
abstract public function createLink(
$for, &$desc = null, $type = Format::SDESC
);
abstract public function appendData($data);
/**
* Called by Format::notify()
*
* Possible events:
* - Render::STANDALONE
* Always called with true as value from Render::attach()
*
*
* - Render::INIT
* Called from Render::execute() when rendering
* is being started. Value is always true
*
* - Render::FINALIZE (from Render::execute())
* Called from Render::execute() when there is
* nothing more to read in the XML file.
*
* - Render::VERBOSE
* Called if the user specified the --verbose option
* as commandline parameter. Called in render.php
*
* - Render::CHUNK
* Called when a new chunk is opened or closed.
* Value is either Render::OPEN or Render::CLOSE
*
* @param integer $event Event flag (see Render class)
* @param mixed $val Additional value flag. Depends
* on $event type
*
* @return void
*/
abstract public function update($event, $value = null);
public final function parsePI($target, $data) {
if (isset($this->pihandlers[$target])) {
return $this->pihandlers[$target]->parse($target, $data);
}
}
public final function registerPIHandlers($pihandlers) {
foreach ($pihandlers as $target => $classname) {
$class = __NAMESPACE__ . "\\" . $classname;
$this->pihandlers[$target] = new $class($this);
}
}
public function getPIHandler($target) {
return $this->pihandlers[$target];
}
public function sortIDs() {
$this->sqlite->createAggregate("indexes", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 9);
$this->sqlite->createAggregate("children", array($this, "SQLiteChildren"), array($this, "SQLiteFinal"), 2);
$this->sqlite->createAggregate("refname", array($this, "SQLiteRefname"), array($this, "SQLiteFinal"), 2);
$this->sqlite->createAggregate("varname", array($this, "SQLiteVarname"), array($this, "SQLiteFinal"), 2);
$this->sqlite->createAggregate("classname", array($this, "SQLiteClassname"), array($this, "SQLiteFinal"), 2);
$this->sqlite->createAggregate("example", array($this, "SQLiteExample"), array($this, "SQLiteFinal"), 1);
$this->sqlite->query('SELECT indexes(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next, chunk) FROM ids');
$this->sqlite->query('SELECT children(docbook_id, parent_id) FROM ids WHERE chunk != 0');
$this->sqlite->query('SELECT refname(docbook_id, sdesc) FROM ids WHERE element=\'refentry\'');
$this->sqlite->query('SELECT varname(docbook_id, sdesc) FROM ids WHERE element=\'phpdoc:varentry\'');
$this->sqlite->query('SELECT classname(docbook_id, sdesc) FROM ids WHERE element=\'phpdoc:exceptionref\' OR element=\'phpdoc:classref\'');
$this->sqlite->query('SELECT example(docbook_id) FROM ids WHERE element=\'example\' OR element=\'informalexample\'');
}
public function SQLiteIndex(&$context, $index, $id, $filename, $parent, $sdesc, $ldesc, $element, $previous, $next, $chunk) {
$this->indexes[$id] = array(
"docbook_id" => $id,
"filename" => $filename,
"parent_id" => $parent,
"sdesc" => $sdesc,
"ldesc" => $ldesc,
"element" => $element,
"previous" => $previous,
"next" => $next,
"chunk" => $chunk,
);
}
public function SQLiteChildren(&$context, $index, $id, $parent)
{
if (!isset($this->children[$parent])
|| !is_array($this->children[$parent])
) {
$this->children[$parent] = array();
}
$this->children[$parent][] = $id;
}
public function SQLiteRefname(&$context, $index, $id, $sdesc) {
$ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), html_entity_decode($sdesc, ENT_QUOTES, 'UTF-8')));
$this->refs[$ref] = $id;
}
public function SQLiteVarname(&$context, $index, $id, $sdesc) {
$this->vars[$sdesc] = $id;
}
public function SQLiteClassname(&$context, $index, $id, $sdesc) {
$this->classes[strtolower($sdesc)] = $id;
}
public function SQLiteExample(&$context, $index, $id) {
$this->examples[] = $id;
}
public static function SQLiteFinal(&$context) {
return $context;
}
/**
* Calls update().
*
* @param integer $event Event flag. See Render class for constants
* like Render::INIT and Render::CHUNK
* @param mixed $val Value; depends on $event flag
*
* @return void
*/
final public function notify($event, $val = null)
{
$this->update($event, $val);
}
public function setTitle($title) {
$this->title = $title;
}
public function getTitle() {
return $this->title;
}
/**
* Set file extension used when chunking and writing
* out files.
*
* @param string $ext File extension without dot
*
* @return void
*
* @see getExt()
*/
public function setExt($ext)
{
$this->ext = $ext;
}
/**
* Returns file extension without
* leading dot.
*
* @return string File extension.
*
* @see setExt()
*/
public function getExt() {
return $this->ext;
}
public function setOutputDir($outputdir) {
$this->outputdir = $outputdir;
}
public function getOutputDir() {
return $this->outputdir;
}
public function setChunked($chunked) {
$this->chunked = $chunked;
}
public function isChunked() {
return $this->chunked;
}
public function setFileStream($stream) {
$this->fp = $stream;
}
public function getFileStream() {
return $this->fp;
}
public function pushFileStream($stream) {
$this->fp[] = $stream;
}
public function popFileStream() {
return array_pop($this->fp);
}
public function addRefname($id, $ref) {
$this->refs[$ref] = $id;
}
public function addClassname($id, $class) {
$this->classes[$class] = $id;
}
public function addVarname($id, $var) {
$this->vars[$var] = $id;
}
public function getChangelogsForChildrenOf($bookids) {
$ids = array();
foreach((array)$bookids as $bookid) {
$ids[] = "'" . $this->sqlite->escapeString($bookid) . "'";
}
$results = $this->sqlite->query("SELECT * FROM changelogs WHERE parent_id IN (" . join(", ", $ids) . ")");
return $this->_returnChangelog($results);
}
public function getChangelogsForMembershipOf($memberships) {
$ids = array();
foreach((array)$memberships as $membership) {
$ids[] = "'" . $this->sqlite->escapeString($membership) . "'";
}
$results = $this->sqlite->query("SELECT * FROM changelogs WHERE membership IN (" . join(", ", $ids) . ")");
return $this->_returnChangelog($results);
}
public function _returnChangelog($results) {
if (!$results) {
return array();
}
$changelogs = array();
while ($row = $results->fetchArray()) {
$changelogs[] = $row;
}
return $changelogs;
}
public function getRefs() {
return $this->refs;
}
public function getExamples() {
return $this->examples;
}
public function getRefnameLink($ref) {
return isset($this->refs[$ref]) ? $this->refs[$ref] : null;
}
public function getClassnameLink($class) {
return isset($this->classes[$class]) ? $this->classes[$class] : null;
}
public function getVarnameLink($var) {
return isset($this->vars[$var]) ? $this->vars[$var] : null;
}
public function getGeneratedExampleID($index) {
return $this->examples[$index];
}
final public function registerElementMap(array $map) {
$this->elementmap = $map;
}
final public function registerTextMap(array $map) {
$this->textmap = $map;
}
final public function attach($obj, $inf = array()) {
if (!($obj instanceof $this) && get_class($obj) != get_class($this)) {
throw new InvalidArgumentException(get_class($this) . " themes *MUST* _inherit_ " .get_class($this). ", got " . get_class($obj));
}
$obj->notify(Render::STANDALONE, false);
return parent::attach($obj, $inf);
}
final public function getElementMap() {
return $this->elementmap;
}
final public function getTextMap() {
return $this->textmap;
}
final public function registerFormatName($name) {
$this->formatname = $name;
}
public function getFormatName() {
return $this->formatname;
}
/* Buffer where append data instead of the standard stream (see format's appendData()) */
final public function parse($xml) {
$parsed = "";
$reader = new Reader();
$render = new Render();
$reader->XML("" . $xml . "");
$this->appendToBuffer = true;
$render->attach($this);
$render->execute($reader);
$this->appendToBuffer = false;
$parsed = $this->buffer;
$this->buffer = "";
return $parsed;
}
final public static function autogen($text, $lang) {
if ($lang == NULL) {
$lang = Config::language();
}
if (isset(self::$autogen[$lang])) {
if (isset(self::$autogen[$lang][$text])) {
return self::$autogen[$lang][$text];
}
if ($lang == Config::fallback_language()) {
throw new \InvalidArgumentException("Cannot autogenerate text for '$text'");
}
return self::autogen($text, Config::fallback_language());
}
$filename = Config::lang_dir() . $lang . ".xml";
$r = new \XMLReader;
if (!file_exists($filename) || !$r->open($filename)) {
if ($lang == Config::fallback_language()) {
throw new \Exception("Cannot open $filename");
}
return self::autogen($text, Config::fallback_language());
}
$autogen = array();
while ($r->read()) {
if ($r->nodeType != \XMLReader::ELEMENT) {
continue;
}
if ($r->name == "term") {
$r->read();
$k = $r->value;
$autogen[$k] = "";
} else if ($r->name == "simpara") {
$r->read();
$autogen[$k] = $r->value;
}
}
self::$autogen[$lang] = $autogen;
return self::autogen($text, $lang);
}
/* {{{ TOC helper functions */
/**
* Returns the filename for the given id, without the file extension
*
* @param string $id XML Id
*
* @return mixed Stringular filename or false if no filename
* can be detected.
*/
final public function getFilename($id)
{
return isset($this->indexes[$id]['filename'])
? $this->indexes[$id]['filename']
: false;
}
final public function getPrevious($id) {
return $this->indexes[$id]["previous"];
}
final public function getNext($id) {
return $this->indexes[$id]["next"];
}
final public function getParent($id) {
return $this->indexes[$id]["parent_id"];
}
final public function getLongDescription($id, &$isLDesc = null) {
if ($this->indexes[$id]["ldesc"]) {
$isLDesc = true;
return $this->indexes[$id]["ldesc"];
} else {
$isLDesc = false;
return $this->indexes[$id]["sdesc"];
}
}
final public function getShortDescription($id, &$isSDesc = null) {
if ($this->indexes[$id]["sdesc"]) {
$isSDesc = true;
return $this->indexes[$id]["sdesc"];
} else {
$isSDesc = false;
return $this->indexes[$id]["ldesc"];
}
}
/**
* Returns an array of children IDs of given ID.
*
* @param string $id XML ID to retrieve children for.
*
* @return array Array of XML IDs
*/
final public function getChildren($id)
{
if (!isset($this->children[$id])
|| !is_array($this->children[$id])
|| count($this->children[$id]) == 0
) {
return null;
}
return $this->children[$id];
}
/**
* Tells you if the given ID is to be chunked or not.
*
* @param string $id XML ID to get chunk status for
*
* @return boolean True if it is to be chunked
*/
final public function isChunkID($id)
{
return isset($this->indexes[$id]['chunk'])
? $this->indexes[$id]['chunk']
: false;
}
final public function getRootIndex() {
static $root = null;
if ($root == null) {
$root = $this->sqlite->querySingle('SELECT * FROM ids WHERE parent_id=""', true);
}
return $root;
}
/* }}} */
/* {{{ Table helper functions */
public function tgroup($attrs) {
if (isset($attrs["cols"])) {
$this->TABLE["cols"] = $attrs["cols"];
unset($attrs["cols"]);
}
$this->TABLE["defaults"] = $attrs;
$this->TABLE["colspec"] = array();
}
public function colspec(array $attrs) {
$colspec = self::getColSpec($attrs);
$this->TABLE["colspec"][$colspec["colnum"]] = $colspec;
return $colspec;
}
public function getColspec(array $attrs) {
/* defaults */
$defaults["colname"] = count($this->TABLE["colspec"])+1;
$defaults["colnum"] = count($this->TABLE["colspec"])+1;
return array_merge($defaults, $this->TABLE["defaults"], $attrs);
}
public function getColCount() {
return $this->TABLE["cols"];
}
public function initRow() {
$this->TABLE["next_colnum"] = 1;
}
public function getEntryOffset(array $attrs) {
$curr = $this->TABLE["next_colnum"];
foreach($this->TABLE["colspec"] as $col => $spec) {
if ($spec["colname"] == $attrs["colname"]) {
$colnum = $spec["colnum"];
$this->TABLE["next_colnum"] += $colnum-$curr;
return $colnum-$curr;
}
}
return -1;
}
public function colspan(array $attrs) {
if (isset($attrs["namest"])) {
foreach($this->TABLE["colspec"] as $colnum => $spec) {
if ($spec["colname"] == $attrs["namest"]) {
$from = $spec["colnum"];
continue;
}
if ($spec["colname"] == $attrs["nameend"]) {
$to = $spec["colnum"];
continue;
}
}
$colspan = $to-$from+1;
$this->TABLE["next_colnum"] += $colspan;
return $colspan;
}
$this->TABLE["next_colnum"]++;
return 1;
}
public function rowspan($attrs) {
if (isset($attrs["morerows"])) {
return $attrs["morerows"]+1;
}
return 1;
}
/* }}} */
/**
* Highlight (color) the given piece of source code
*
* @param string $text Text to highlight
* @param string $role Source code role to use (php, xml, html, ...)
* @param string $format Format to highlight (pdf, xhtml, troff, ...)
*
* @return string Highlighted code
*/
public function highlight($text, $role = 'php', $format = 'xhtml')
{
if (!isset(self::$highlighters[$format])) {
$class = Config::highlighter();
self::$highlighters[$format] = $class::factory($format);
}
return self::$highlighters[$format]->highlight(
$text, $role, $format
);
}
/**
* Provide a nested list of IDs from the document root to the CURRENT_ID.
*
* @param string $name The name of the current element.
* @param mixed[] $props Properties relating to the current element.
*
* @return string A nested list of IDs from the root to the CURRENT_ID.
*/
public function getDebugTree($name, $props)
{
/* Build the list of IDs from the CURRENT_ID to the root. */
$ids = array();
$id = $this->CURRENT_ID;
while($id != '')
{
$ids[] = '<' . $this->indexes[$id]['element'] . ' id="' . $id . '">';
$id = $this->indexes[$id]['parent_id'];
}
/* Reverse the list so that it goes form the root to the CURRENT_ID. */
$ids = array_reverse($ids);
/* Build an indented tree view of the ids. */
$tree = '';
$indent = 0;
array_walk($ids, function($value, $key) use(&$tree, &$indent)
{
$tree .= str_repeat(' ', $indent++) . $value . PHP_EOL;
});
/* Add the open and closed sibling and the current element. */
$tree .=
str_repeat(' ', $indent) . '<' . $props['sibling'] . '>' . PHP_EOL .
str_repeat(' ', $indent) . '...' . PHP_EOL .
str_repeat(' ', $indent) . '' . $props['sibling'] . '>' . PHP_EOL .
str_repeat(' ', $indent) . '<' . $name . '>' . PHP_EOL;
return $tree;
}
}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/functions.php 0000644 00000015234 11767147641 0013204 0 ustar 00 isFile() || $fileinfo->isLink()) {
unlink($fileinfo->getPathName());
} elseif (!$fileinfo->isDot() && $fileinfo->isDir()) {
removeDir($fileinfo->getPathName());
}
}
rmdir($path);
}
/* }}} */
/* {{{ The PhD errorhandler */
function errh($errno, $msg, $file, $line, $ctx = null) {
static $err = array(
// PHP Triggered Errors
E_DEPRECATED => 'E_DEPRECATED ',
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR ',
E_STRICT => 'E_STRICT ',
E_WARNING => 'E_WARNING ',
E_NOTICE => 'E_NOTICE ',
// User Triggered Errors
E_USER_ERROR => 'E_USER_ERROR ',
E_USER_WARNING => 'E_USER_WARNING ',
E_USER_NOTICE => 'E_USER_NOTICE ',
E_USER_DEPRECATED => 'E_USER_DEPRECATED ',
// PhD informationals
VERBOSE_INDEXING => 'Indexing ',
VERBOSE_FORMAT_RENDERING => 'Rendering Format ',
VERBOSE_THEME_RENDERING => 'Rendering Theme ',
VERBOSE_RENDER_STYLE => 'Rendering Style ',
VERBOSE_PARTIAL_READING => 'Partial Reading ',
VERBOSE_PARTIAL_CHILD_READING => 'Partial Child Reading ',
VERBOSE_TOC_WRITING => 'Writing TOC ',
VERBOSE_CHUNK_WRITING => 'Writing Chunk ',
VERBOSE_MESSAGES => 'Heads up ',
// PhD warnings
VERBOSE_NOVERSION => 'No version information',
VERBOSE_BROKEN_LINKS => 'Broken links ',
VERBOSE_OLD_LIBXML => 'Old libxml2 ',
VERBOSE_MISSING_ATTRIBUTES => 'Missing attributes ',
);
static $recursive = false;
// Respect the error_reporting setting
if (!(error_reporting() & $errno)) {
return false;
}
// Recursive protection
if ($recursive) {
// Thats bad.. lets print a backtrace right away
debug_print_backtrace();
// Fallback to the default errorhandler
return false;
}
$recursive = true;
$time = date(Config::date_format());
switch($errno) {
case VERBOSE_INDEXING:
case VERBOSE_FORMAT_RENDERING:
case VERBOSE_THEME_RENDERING:
case VERBOSE_RENDER_STYLE:
case VERBOSE_PARTIAL_READING:
case VERBOSE_PARTIAL_CHILD_READING:
case VERBOSE_TOC_WRITING:
case VERBOSE_CHUNK_WRITING:
case VERBOSE_MESSAGES:
$color = Config::phd_info_color();
$output = Config::phd_info_output();
$data = $msg;
break;
case VERBOSE_NOVERSION:
case VERBOSE_BROKEN_LINKS:
case VERBOSE_MISSING_ATTRIBUTES:
$color = Config::phd_warning_color();
$output = Config::phd_warning_output();
$data = $msg;
break;
// User triggered errors
case E_USER_ERROR:
case E_USER_WARNING:
case E_USER_NOTICE:
$color = Config::user_error_color();
$output = Config::user_error_output();
$data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
break;
// PHP triggered errors
case E_DEPRECATED:
case E_RECOVERABLE_ERROR:
case E_STRICT:
case E_WARNING:
case E_NOTICE:
$color = Config::php_error_color();
$output = Config::php_error_output();
$data = sprintf("%s:%d\n\t%s", $file, $line, $msg);
break;
default:
$recursive = false;
return false;
}
$timestamp = term_color(sprintf("[%s - %s]", $time, $err[$errno]), $color);
fprintf($output, "%s %s\n", $timestamp, $data);
// Abort on fatal errors
if ($errno & (E_USER_ERROR|E_RECOVERABLE_ERROR)) {
exit(1);
}
$recursive = false;
return true;
}
/* }}} */
set_error_handler(__NAMESPACE__ . '\\errh');
/* }}} */
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/
PhD-1.1.6/phpdotnet/phd/Highlighter.php 0000644 00000004103 11767147641 0013423 0 ustar 00
* @license http://www.opensource.org/licenses/bsd-license.php BSD Style
* @version SVN: $Id$
* @link https://doc.php.net/phd/
*/
namespace phpdotnet\phd;
/**
* Source code highlighting class for phd.
*
* @category PhD
* @package PhD
* @author Christian Weiske
* @license http://www.opensource.org/licenses/bsd-license.php BSD Style
* @link https://doc.php.net/phd/
*/
class Highlighter
{
/**
* Create a new highlighter instance for the given format.
*
* We use a factory so you can return different objects/classes
* per format.
*
* @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return PhDHighlighter Highlighter object
*/
public static function factory($format)
{
return new self();
}//public static function factory(..)
/**
* Highlight a given piece of source code.
* Dead simple version that only works for xhtml+php. Returns text as
* it was in all other cases.
*
* @param string $text Text to highlight
* @param string $role Source code role to use (php, xml, html, ...)
* @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return string Highlighted code
*/
public function highlight($text, $role, $format)
{
if ($format == 'troff') {
return "\n.PP\n.nf\n"
. str_replace("\\", "\\\\", trim($text))
. "\n.fi";
} else if ($format != 'xhtml') {
return $text;
}
if ($role == 'php') {
return highlight_string($text, 1);
} else {
return '