cvs: livedocs / common.php error.php livedoc-index.php livedoc.php mkindex.php mktoc.php search.php style_mapping.php xml_classes.php
| From: | Derick Rethans | Date: | Mon, 16 Feb 2004 17:54:59 +0000 |
| Subject: | cvs: livedocs / common.php error.php livedoc-index.php livedoc.php mkindex.php mktoc.php search.php style_mapping.php xml_classes.php | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969358968@lists.php.net to get a copy of this message | ||
derick Mon Feb 16 12:54:59 2004 EDT
Modified files:
/livedocs common.php error.php livedoc-index.php livedoc.php
mkindex.php mktoc.php search.php style_mapping.php
xml_classes.php
Log:
- Revert using spaces for indentation. We use tabs here, like in PHP source
code.
http://cvs.php.net/diff.php/livedocs/common.php?r1=1.6&r2=1.7&ty=u Index: livedocs/common.php diff -u livedocs/common.php:1.6 livedocs/common.php:1.7 --- livedocs/common.php:1.6 Fri Jan 30 00:49:15 2004 +++ livedocs/common.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Common PHP header, with some basic settings | // +----------------------------------------------------------------------+ // -// $Id: common.php,v 1.6 2004/01/30 05:49:15 momo Exp $ +// $Id: common.php,v 1.7 2004/02/16 17:54:59 derick Exp $ set_magic_quotes_runtime(0); error_reporting(E_ALL); ini_set('display_errors', '1'); @@ -38,14 +38,14 @@ $css_url = WEBBASE . 'themes/' . THEME_NAME . '/livedoc.css'; if (!isset($_GET['l'])) { - // if we are dealing with path info URL check for language - if (!empty($_SERVER['REDIRECT_URL']) && preg_match('|([A-Za-z_]{2,5})/(.*)|', substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)), $m)) { - $lang = $m[1]; - } else { - $lang = FALLBACK_LANG; - } + // if we are dealing with path info URL check for language + if (!empty($_SERVER['REDIRECT_URL']) && preg_match('|([A-Za-z_]{2,5})/(.*)|', substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)), $m)) { + $lang = $m[1]; + } else { + $lang = FALLBACK_LANG; + } } else { - $lang = preg_replace(LANGREG, '', $_GET['l']); + $lang = preg_replace(LANGREG, '', $_GET['l']); } define('BASE', PHPDOC . "/$lang/"); @@ -55,11 +55,11 @@ $fb_idx = @sqlite_open(FALLBACK_INDEX); if ($lang == FALLBACK_LANG || !($idx = @sqlite_open(INDEX))) { - $idx = $fb_idx; - $lang = FALLBACK_LANG; + $idx = $fb_idx; + $lang = FALLBACK_LANG; } if (!$idx) { - die ("No index found"); + die ("No index found"); } ?> http://cvs.php.net/diff.php/livedocs/error.php?r1=1.6&r2=1.7&ty=u Index: livedocs/error.php diff -u livedocs/error.php:1.6 livedocs/error.php:1.7 --- livedocs/error.php:1.6 Thu Feb 5 15:35:12 2004 +++ livedocs/error.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,84 +18,84 @@ // | Handles the 404 error and try to redirect to the good place. | // +----------------------------------------------------------------------+ // -// $Id: error.php,v 1.6 2004/02/05 20:35:12 wez Exp $ +// $Id: error.php,v 1.7 2004/02/16 17:54:59 derick Exp $ /* handle IIS style 404 handler */ if (strncmp($_SERVER['SERVER_SOFTWARE'], "Microsoft", 9) == 0 && - isset($_SERVER['QUERY_STRING']) && - strncmp($_SERVER['QUERY_STRING'], "404;", 4) == 0) { + isset($_SERVER['QUERY_STRING']) && + strncmp($_SERVER['QUERY_STRING'], "404;", 4) == 0) { - $rurl = parse_url(substr($_SERVER['QUERY_STRING'], 4)); + $rurl = parse_url(substr($_SERVER['QUERY_STRING'], 4)); - $_SERVER['REDIRECT_URL'] = $rurl['path']; - if (isset($rurl['query'])) { - $_SERVER['REDIRECT_URL'] .= '?' . $rurl['query']; - } + $_SERVER['REDIRECT_URL'] = $rurl['path']; + if (isset($rurl['query'])) { + $_SERVER['REDIRECT_URL'] .= '?' . $rurl['query']; + } } if (!empty($_SERVER['REDIRECT_URL'])) { - // This is the requested page that caused the error - $current_page = substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)); - if (strncmp(substr($current_page, -5), ".html", 5)) { - if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { - $current_page = $m[2]; - } - - $lookup_name = preg_replace('!.*\.!', '', strtolower($current_page)); - $lookup_name = preg_replace('![^a-z0-9]!', '', $lookup_name); - - $db_m = sqlite_array_query($idx, "SELECT path, prio FROM searchi WHERE (skey='" . sqlite_escape_string($lookup_name) . "' OR skey='".sqlite_escape_string(metaphone($lookup_name))."') ORDER BY prio LIMIT 1", SQLITE_NUM); - if ($db_m) { - if ($db_m[0][1] < 5 || (sqlite_fetch_string(sqlite_unbuffered_query($idx, "SELECT count(*) FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5")) == 1)) { - $current_page = $lang . '/' . $db_m[0][0] . '.html'; - if (@file_exists(OUTPUTDIR . '/' . $current_page)) { - header('Location: ' . WEBBASE . $current_page . '?#' . $db_m[0][0]); - exit; - } - } else { - list($title, $filename, $fileid, $dirid) = do_nav($idx, $fb_idx, $lang, 'bookinfo', $nav, $children); - $date = gmdate('Y-m-d H:i:s') . ' GMT'; - if (empty($file_revision)) { - $file_revision = 'unknown revision'; - } - $db_m = sqlite_array_query($idx, "SELECT path FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5 LIMIT 10", SQLITE_NUM); - $rs_size = count($db_m); - $fpath = WEBBASE . $lang . '/'; + // This is the requested page that caused the error + $current_page = substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)); + if (strncmp(substr($current_page, -5), ".html", 5)) { + if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { + $current_page = $m[2]; + } + + $lookup_name = preg_replace('!.*\.!', '', strtolower($current_page)); + $lookup_name = preg_replace('![^a-z0-9]!', '', $lookup_name); + + $db_m = sqlite_array_query($idx, "SELECT path, prio FROM searchi WHERE (skey='" . sqlite_escape_string($lookup_name) . "' OR skey='".sqlite_escape_string(metaphone($lookup_name))."') ORDER BY prio LIMIT 1", SQLITE_NUM); + if ($db_m) { + if ($db_m[0][1] < 5 || (sqlite_fetch_string(sqlite_unbuffered_query($idx, "SELECT count(*) FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5")) == 1)) { + $current_page = $lang . '/' . $db_m[0][0] . '.html'; + if (@file_exists(OUTPUTDIR . '/' . $current_page)) { + header('Location: ' . WEBBASE . $current_page . '?#' . $db_m[0][0]); + exit; + } + } else { + list($title, $filename, $fileid, $dirid) = do_nav($idx, $fb_idx, $lang, 'bookinfo', $nav, $children); + $date = gmdate('Y-m-d H:i:s') . ' GMT'; + if (empty($file_revision)) { + $file_revision = 'unknown revision'; + } + $db_m = sqlite_array_query($idx, "SELECT path FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5 LIMIT 10", SQLITE_NUM); + $rs_size = count($db_m); + $fpath = WEBBASE . $lang . '/'; - echo error_page_header(); + echo error_page_header(); - foreach($db_m as $v) { - if (($p = strrpos($v[0], '.')) !== FALSE) { - $f_name = substr($v[0], ($p + 1)); - } else { - $f_name = $v[0]; - } - $f_name = str_replace('-', '_', $f_name); - echo <<<FUNC_MATCH + foreach($db_m as $v) { + if (($p = strrpos($v[0], '.')) !== FALSE) { + $f_name = substr($v[0], ($p + 1)); + } else { + $f_name = $v[0]; + } + $f_name = str_replace('-', '_', $f_name); + echo <<< FUNC_MATCH <a class="function" href="{$fpath}{$v[0]}.html#{$v[0]}">{$f_name}()</a><br /> FUNC_MATCH; - } - - echo error_page_footer(); - exit; - } - } - } - - $current_page = preg_replace('|^/|', '', $current_page); - $current_page = preg_replace('|\.html$|', '', $current_page); - if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { - $current_page = preg_replace(IDREG, '', $m[2]); - $save_url = TRUE; - } else if (preg_match('|(.*)|', $current_page, $m)) { - $current_page = preg_replace(IDREG, '', $m[1]); - $save_url = TRUE; - } else { - $current_page = 'manual'; - } + } + + echo error_page_footer(); + exit; + } + } + } + + $current_page = preg_replace('|^/|', '', $current_page); + $current_page = preg_replace('|\.html$|', '', $current_page); + if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { + $current_page = preg_replace(IDREG, '', $m[2]); + $save_url = TRUE; + } else if (preg_match('|(.*)|', $current_page, $m)) { + $current_page = preg_replace(IDREG, '', $m[1]); + $save_url = TRUE; + } else { + $current_page = 'manual'; + } } if (empty($current_page)) { - $current_page = 'manual'; + $current_page = 'manual'; } http://cvs.php.net/diff.php/livedocs/livedoc-index.php?r1=1.7&r2=1.8&ty=u Index: livedocs/livedoc-index.php diff -u livedocs/livedoc-index.php:1.7 livedocs/livedoc-index.php:1.8 --- livedocs/livedoc-index.php:1.7 Mon Feb 2 15:33:28 2004 +++ livedocs/livedoc-index.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,56 +18,56 @@ // | Livedocs index | // +----------------------------------------------------------------------+ // -// $Id: livedoc-index.php,v 1.7 2004/02/02 20:33:28 momo Exp $ +// $Id: livedoc-index.php,v 1.8 2004/02/16 17:54:59 derick Exp $ echo index_page_header(); $alphabet = range('a', 'z'); foreach ($alphabet as $char) { - echo "<a href='" . WEBBASE . "index.php?l=$lang&s=INDEX&i=$char'>$char</a> "; + echo "<a href='" . WEBBASE . "index.php?l=$lang&s=INDEX&i=$char'>$char</a> "; } echo "</div><hr />\n"; if (!isset($_GET['i'])) { - /* Show alphabet */ + /* Show alphabet */ } else { - /* Sanitize index letter */ - if (strlen($_GET['i']) < 1) { - $idxl = 'a'; - } else { - $idxl = substr($_GET['i'], 0, 1); - } - - /* Create function call back for STARTS_WITH and TO_LOWER */ - sqlite_create_function($idx, 'STARTS_WITH', 'sqlite_starts_with'); - sqlite_create_function($idx, 'TO_LOWER', 'sqlite_to_lower'); - - /* Select all titles starting with $idxl */ - $q = sqlite_query($idx, "SELECT title, id FROM idents WHERE STARTS_WITH(title, '$idxl') ORDER BY TO_LOWER(title)"); - if ($q) { - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $id) = $r; - $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id"; - echo "<span class='index'><a href='" . WEBBASE . "$url'>$title</a></span><br />\n"; - } - } + /* Sanitize index letter */ + if (strlen($_GET['i']) < 1) { + $idxl = 'a'; + } else { + $idxl = substr($_GET['i'], 0, 1); + } + + /* Create function call back for STARTS_WITH and TO_LOWER */ + sqlite_create_function($idx, 'STARTS_WITH', 'sqlite_starts_with'); + sqlite_create_function($idx, 'TO_LOWER', 'sqlite_to_lower'); + + /* Select all titles starting with $idxl */ + $q = sqlite_query($idx, "SELECT title, id FROM idents WHERE STARTS_WITH(title, '$idxl') ORDER BY TO_LOWER(title)"); + if ($q) { + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $id) = $r; + $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id"; + echo "<span class='index'><a href='" . WEBBASE . "$url'>$title</a></span><br />\n"; + } + } } $date = date("d-m-Y H:i:s"); echo index_page_footer(); function sqlite_starts_with($title, $char) { - $title = strtolower($title); - $char = strtolower($char); - if (!strlen($title) || !strlen($char)) { - return FALSE; - } - return ($title{0} == $char{0}); + $title = strtolower($title); + $char = strtolower($char); + if (!strlen($title) || !strlen($char)) { + return FALSE; + } + return ($title{0} == $char{0}); } function sqlite_to_lower($text) { - return strtolower($text); + return strtolower($text); } ?> http://cvs.php.net/diff.php/livedocs/livedoc.php?r1=1.79&r2=1.80&ty=u Index: livedocs/livedoc.php diff -u livedocs/livedoc.php:1.79 livedocs/livedoc.php:1.80 --- livedocs/livedoc.php:1.79 Fri Jan 23 09:58:38 2004 +++ livedocs/livedoc.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Generate an HTML version of a phpdoc/docbook page on the fly | // +----------------------------------------------------------------------+ // -// $Id: livedoc.php,v 1.79 2004/01/23 14:58:38 didou Exp $ +// $Id: livedoc.php,v 1.80 2004/02/16 17:54:59 derick Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include LIVEDOC_SOURCE . '/common.php'; @@ -27,13 +27,13 @@ include LIVEDOC_SOURCE . '/themes/' . THEME_NAME . '/html_format.php'; if (!isset($_GET['q'])) { - // Handles the 404. If a matching page is found, we redirect to it. - // Else, we display a page with the closest matches and we stop the script. - // If something goes wrong with the database, $current_page will default - // to some value. - include LIVEDOC_SOURCE . '/error.php'; + // Handles the 404. If a matching page is found, we redirect to it. + // Else, we display a page with the closest matches and we stop the script. + // If something goes wrong with the database, $current_page will default + // to some value. +include LIVEDOC_SOURCE . '/error.php'; } else { - $current_page = preg_replace(IDREG, '', $_GET['q']); + $current_page = preg_replace(IDREG, '', $_GET['q']); } /***************************************************************************** @@ -41,21 +41,21 @@ * Please keep the arrays sorted by keys */ $aliases = array( - 'api' => 'streams', - 'appendixes' => 'handle_appendixes', - 'faq' => 'faq.general', - 'features' => 'features.http-auth', - 'funcref' => 'handle_funcref', - 'getting-started' => 'introduction', - 'installation' => 'install.general', - 'langref' => 'language.basic-syntax', - 'manual' => 'handle_contents', - 'security' => 'security.index' + 'api' => 'streams', + 'appendixes' => 'handle_appendixes', + 'faq' => 'faq.general', + 'features' => 'features.http-auth', + 'funcref' => 'handle_funcref', + 'getting-started' => 'introduction', + 'installation' => 'install.general', + 'langref' => 'language.basic-syntax', + 'manual' => 'handle_contents', + 'security' => 'security.index' ); if (isset($_GET['s'])) { - include LIVEDOC_SOURCE . '/livedoc-index.php'; - exit; + include LIVEDOC_SOURCE . '/livedoc-index.php'; + exit; } /***************************************************************************** @@ -63,11 +63,11 @@ */ $special_content = false; if (isset($aliases[$current_page])) { - if (is_callable($aliases[$current_page])) { - $special_content = true; - } else { - $current_page = $aliases[$current_page]; - } + if (is_callable($aliases[$current_page])) { + $special_content = true; + } else { + $current_page = $aliases[$current_page]; + } } @@ -78,33 +78,33 @@ if (!$special_content) { - if ($filename == null) { - // no matching node was found - handle_missing_index(); - } else { - // load the content - $page = load_xml_doc(BASE . $filename, false, FALLBACK_BASE . $filename); - } + if ($filename == null) { + // no matching node was found + handle_missing_index(); + } else { + // load the content + $page = load_xml_doc(BASE . $filename, false, FALLBACK_BASE . $filename); + } } /***************************************************************************** * Grabbing the output for normal or special pages */ if ($save_url) { - ob_start(); + ob_start(); } echo manual_page_header(); if ($special_content) { - echo call_user_func($aliases[$current_page]); + echo call_user_func($aliases[$current_page]); } else { - echo $page->transform($map, $current_page); + echo $page->transform($map, $current_page); } $date = gmdate('Y-m-d H:i:s') . ' GMT'; if (empty($file_revision)) { - $file_revision = 'unknown revision'; + $file_revision = 'unknown revision'; } echo manual_page_footer(); @@ -113,12 +113,12 @@ * Saving the generated page to the cache */ if ($save_url) { - $contents = ob_get_contents(); - ob_clean(); - $f = fopen($lang . "/" . $current_page . ".html", 'w'); - fwrite($f, $contents); - fclose($f); - echo $contents; + $contents = ob_get_contents(); + ob_clean(); + $f = fopen($lang . "/" . $current_page . ".html", 'w'); + fwrite($f, $contents); + fclose($f); + echo $contents; } return; @@ -129,158 +129,158 @@ function do_nav($idx, $fb_idx, $lang, $current_page, &$nav, &$children) { - $nav = "<table class='nav' border='0' cellpadding='0' cellspacing='0' width='150'>"; + $nav = "<table class='nav' border='0' cellpadding='0' cellspacing='0' width='150'>"; - /* Get the fileinfo for the reference */ - $q = sqlite_query($idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); + /* Get the fileinfo for the reference */ + $q = sqlite_query($idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); - if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $filename, $fileid, $dirid) = $tr; - } else { - $q = sqlite_query($fb_idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); - - if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $filename, $fileid, $dirid) = $tr; - } - } - - /* Get parent ID and child IDs */ - /* - first we get the first three parts of the path */ - $q = sqlite_query($idx, " - SELECT path - FROM toc - WHERE docbook_id = '$current_page' - "); - $r = sqlite_fetch_array($q, SQLITE_NUM); - if ($r[0]) { - $parent_ids = explode(",", $r[0]); - foreach($parent_ids as $id) { - $path[] = $id; - } - } else { - $path = array('manual'); - } - - foreach ($path as $item) { - $last_item = $item; - $nav .= do_nav_line($item, 'up', $current_page, $lang, $dummy); - } - - /* With $last_item we're going to show all brothers */ - $q = sqlite_query($idx, " - SELECT docbook_id - FROM toc - WHERE parent_docbook_id = '$last_item' - ORDER BY id - "); - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $nav .= do_nav_line($r[0], 'down', $current_page, $lang, $dummy); - } - - $children = array(); - /* And finally all children, but only if $current_page != $last_item - * because showing the same thing twice makes no sense */ - $q = sqlite_query($idx, " - SELECT docbook_id - FROM toc - WHERE parent_docbook_id = '$current_page' - AND parent_docbook_id <> 'manual' - ORDER BY id - "); - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $nav .= do_nav_line($r[0], 'downdown', $current_page, $lang, $title); - $children[$r[0]] = $title; - } + if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $filename, $fileid, $dirid) = $tr; + } else { + $q = sqlite_query($fb_idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); + + if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $filename, $fileid, $dirid) = $tr; + } + } + + /* Get parent ID and child IDs */ + /* - first we get the first three parts of the path */ + $q = sqlite_query($idx, " + SELECT path + FROM toc + WHERE docbook_id = '$current_page' + "); + $r = sqlite_fetch_array($q, SQLITE_NUM); + if ($r[0]) { + $parent_ids = explode(",", $r[0]); + foreach($parent_ids as $id) { + $path[] = $id; + } + } else { + $path = array('manual'); + } + + foreach ($path as $item) { + $last_item = $item; + $nav .= do_nav_line($item, 'up', $current_page, $lang, $dummy); + } + + /* With $last_item we're going to show all brothers */ + $q = sqlite_query($idx, " + SELECT docbook_id + FROM toc + WHERE parent_docbook_id = '$last_item' + ORDER BY id + "); + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $nav .= do_nav_line($r[0], 'down', $current_page, $lang, $dummy); + } + + $children = array(); + /* And finally all children, but only if $current_page != $last_item + * because showing the same thing twice makes no sense */ + $q = sqlite_query($idx, " + SELECT docbook_id + FROM toc + WHERE parent_docbook_id = '$current_page' + AND parent_docbook_id <> 'manual' + ORDER BY id + "); + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $nav .= do_nav_line($r[0], 'downdown', $current_page, $lang, $title); + $children[$r[0]] = $title; + } - $nav .= "</table>\n"; - return $tr; + $nav .= "</table>\n"; + return $tr; } function generate_url_for_id($lang, $ref) { - static $cache = array(); + static $cache = array(); - if (isset($cache[$lang][$ref])) { - return $cache[$lang][$ref]; - } - - /* first determine the file in which the node can be found */ - $fileid = null; - $firstid = $ref; - - $saferef = sqlite_escape_string($ref); - - $q = sqlite_query($GLOBALS['idx'], "SELECT fileid from idents where id='$saferef'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $fileid = $r[0]; - $idx = $GLOBALS['idx']; - } elseif (isset($GLOBALS['fb_idx'])) { - $q = sqlite_query($GLOBALS['fb_idx'], "SELECT fileid from idents where id='$saferef'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $fileid = $r[0]; - $idx = $GLOBALS['fb_idx']; - } - } - - if ($fileid !== null) { - /* determine the first node within that file */ - $q = sqlite_query($idx, "SELECT id from idents where fileid='$fileid' LIMIT 1"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $firstid = $r[0]; - } - } - - if ($firstid != $ref) { - $hash = "#$ref"; - } else { - $hash = ""; - } - - if ($firstid == 'manual') { - $firstid = $ref; - $hash = ''; - } - - if (FORCE_DYNAMIC) { - $url = "{$_SERVER['PHP_SELF']}?l=$lang&q=$firstid$hash"; - } else { - $url = WEBBASE . "$lang/$firstid.html$hash"; - } + if (isset($cache[$lang][$ref])) { + return $cache[$lang][$ref]; + } + + /* first determine the file in which the node can be found */ + $fileid = null; + $firstid = $ref; + + $saferef = sqlite_escape_string($ref); + + $q = sqlite_query($GLOBALS['idx'], "SELECT fileid from idents where id='$saferef'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $fileid = $r[0]; + $idx = $GLOBALS['idx']; + } elseif (isset($GLOBALS['fb_idx'])) { + $q = sqlite_query($GLOBALS['fb_idx'], "SELECT fileid from idents where id='$saferef'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $fileid = $r[0]; + $idx = $GLOBALS['fb_idx']; + } + } + + if ($fileid !== null) { + /* determine the first node within that file */ + $q = sqlite_query($idx, "SELECT id from idents where fileid='$fileid' LIMIT 1"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $firstid = $r[0]; + } + } + + if ($firstid != $ref) { + $hash = "#$ref"; + } else { + $hash = ""; + } + + if ($firstid == 'manual') { + $firstid = $ref; + $hash = ''; + } + + if (FORCE_DYNAMIC) { + $url = "{$_SERVER['PHP_SELF']}?l=$lang&q=$firstid$hash"; + } else { + $url = WEBBASE . "$lang/$firstid.html$hash"; + } - $cache[$lang][$ref] = $url; - return $url; + $cache[$lang][$ref] = $url; + return $url; } function do_nav_line($item, $class, $current_page, $lang, &$fulltitle) { - global $current_page_title; + global $current_page_title; - $nolink = FALSE; + $nolink = FALSE; - $title = lookup_title($item); - $fulltitle = $title; - if (strlen($title) > 25) { - $ftitle = " title='$title'"; - $title = substr($title, 0, 22). '...'; - } else { - $ftitle = ""; - } - if (empty($title)) { - $title = $item. ' [?]'; - $nolink = TRUE; - } - if ($item == $current_page) { - $current_page_title = $title; - $title = "<b>$title</b>"; - } - $title = str_replace(' ', ' ', $title); - - if ($nolink) { - return "<tr><td class='$class'>$title</td></tr>\n"; - } else { - $url = generate_url_for_id($lang, $item); - return "<tr><td class='$class'><a $ftitle class='$class' href='$url'>$title</a></td></tr>\n"; - } + $title = lookup_title($item); + $fulltitle = $title; + if (strlen($title) > 25) { + $ftitle = " title='$title'"; + $title = substr($title, 0, 22). '...'; + } else { + $ftitle = ""; + } + if (empty($title)) { + $title = $item. ' [?]'; + $nolink = TRUE; + } + if ($item == $current_page) { + $current_page_title = $title; + $title = "<b>$title</b>"; + } + $title = str_replace(' ', ' ', $title); + + if ($nolink) { + return "<tr><td class='$class'>$title</td></tr>\n"; + } else { + $url = generate_url_for_id($lang, $item); + return "<tr><td class='$class'><a $ftitle class='$class' href='$url'>$title</a></td></tr>\n"; + } } @@ -289,227 +289,227 @@ */ function &load_xml_doc($filename, $included = false, $fallback_filename = '') { - global $file_revision, $idx; + global $file_revision, $idx; - $replace = array(); - $search = array('æ', '©', 'é', 'è', 'à', 'ï', 'ö', 'ä', 'Ä', - 'ô', 'ê', 'û', 'î', 'â', 'ë', 'ç', 'ù'); - foreach ($search as $item) { - $replace[] = html_entity_decode($item); - } - - $sanity = 0; - $data = @file_get_contents($filename); - if (strlen($data) == 0 && strlen($fallback_filename)) { - $data = @file_get_contents($fallback_filename); - - if (strlen($data) == 0) { - $data = "<warning>permissions problem for $filename?</warning>"; - } - } - - /* get file revision */ - if (empty($file_revision) && preg_match('/\$' . 'Revision: [^$]+ \$/', $data, $matches)) { - $file_revision .= $matches[0]; - } - - /* strip comments */ - $data = preg_replace('@<!--\s+.*\s-->@Usm', '', $data); - /* list the entities that are required */ - $entities = array(); - do { - $ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches); - if ($ent_count == 0) { - break; - } - - /* now collect their values */ - $entities_to_find = array_unique($matches[1]); - $ents = implode("','", $entities_to_find); - $q = sqlite_query($idx, "SELECT entid, value from ents where entid in ('" . $ents . "')"); - if (!$q) { - break; - } - - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $entities['&' . $r[0] . ';'] = $r[1]; - } - - /* substitute */ - $data = strtr($data, $entities); - - } while ($sanity++ < 5); - - /* catch any undefined entities */ - if ($included) { - if (basename($filename) == 'functions.xml') { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_function_link("\\1.\\2");', $data); - } else { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_xref("\\1.\\2");', $data); - } - if (!$data || $data{1} != '?') { - $data = '<div>' . $data . '</div>'; - } else { - $data = preg_replace('@(<\\?xml.*\\?>)@U', '\\1<div>', $data) . '</div>'; - } - } else { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sm', '<phpdoc_include ref="\\1.\\2"/>', $data); - } + $replace = array(); + $search = array('æ', '©', 'é', 'è', 'à', 'ï', 'ö', 'ä', 'Ä', + 'ô', 'ê', 'û', 'î', 'â', 'ë', 'ç', 'ù'); + foreach ($search as $item) { + $replace[] = html_entity_decode($item); + } + + $sanity = 0; + $data = @file_get_contents($filename); + if (strlen($data) == 0 && strlen($fallback_filename)) { + $data = @file_get_contents($fallback_filename); + + if (strlen($data) == 0) { + $data = "<warning>permissions problem for $filename?</warning>"; + } + } + + /* get file revision */ + if (empty($file_revision) && preg_match('/\$' . 'Revision: [^$]+ \$/', $data, $matches)) { + $file_revision .= $matches[0]; + } + + /* strip comments */ + $data = preg_replace('@<!--\s+.*\s-->@Usm', '', $data); + /* list the entities that are required */ + $entities = array(); + do { + $ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches); + if ($ent_count == 0) { + break; + } + + /* now collect their values */ + $entities_to_find = array_unique($matches[1]); + $ents = implode("','", $entities_to_find); + $q = sqlite_query($idx, "SELECT entid, value from ents where entid in ('" . $ents . "')"); + if (!$q) { + break; + } + + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $entities['&' . $r[0] . ';'] = $r[1]; + } + + /* substitute */ + $data = strtr($data, $entities); + + } while ($sanity++ < 5); + + /* catch any undefined entities */ + if ($included) { + if (basename($filename) == 'functions.xml') { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_function_link("\\1.\\2");', $data); + } else { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_xref("\\1.\\2");', $data); + } + if (!$data || $data{1} != '?') { + $data = '<div>' . $data . '</div>'; + } else { + $data = preg_replace('@(<\\?xml.*\\?>)@U', '\\1<div>', $data) . '</div>'; + } + } else { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sm', '<phpdoc_include ref="\\1.\\2"/>', $data); + } - $data = str_replace($search, $replace, $data); + $data = str_replace($search, $replace, $data); - $page = new DocBookToHTML($data); + $page = new DocBookToHTML($data); - return $page; + return $page; } function lookup_title($nodeid) { - static $ids = array(); + static $ids = array(); - /* Define your own title mappings here: */ - static $special = array ('indexes' => 'FunctionIndex'); + /* Define your own title mappings here: */ + static $special = array ('indexes' => 'FunctionIndex'); - /* we're going to do some tricky stuff here for languages, - * by using entities as much as possible */ - if (isset($special[$nodeid])) { - /* Check for the entity value */ - $q = sqlite_query($GLOBALS['idx'], "SELECT * FROM ents WHERE entid = '$special[$nodeid]'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - return $r[1]; - } else { /* It's not an entity, let's just return it then */ - return $special[$nodeid]; - } - } - - /* See if the title lookup is in the cache already */ - if (isset($ids[$nodeid])) { - return $ids[$nodeid]; - } - - /* It's not, so we try to resolve it from the DB */ - $safeid = sqlite_escape_string($nodeid); - $q = sqlite_query($GLOBALS['idx'], "SELECT title from idents where id='$safeid'"); - - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $ids[$nodeid] = $r[0]; - return $r[0]; - } elseif (isset($GLOBALS['fb_idx'])) { - $q = sqlite_query($GLOBALS['fb_idx'], "SELECT title from idents where id='$safeid'"); - - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $ids[$nodeid] = $r[0]; - return $r[0]; - } - } - return null; + /* we're going to do some tricky stuff here for languages, + * by using entities as much as possible */ + if (isset($special[$nodeid])) { + /* Check for the entity value */ + $q = sqlite_query($GLOBALS['idx'], "SELECT * FROM ents WHERE entid = '$special[$nodeid]'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + return $r[1]; + } else { /* It's not an entity, let's just return it then */ + return $special[$nodeid]; + } + } + + /* See if the title lookup is in the cache already */ + if (isset($ids[$nodeid])) { + return $ids[$nodeid]; + } + + /* It's not, so we try to resolve it from the DB */ + $safeid = sqlite_escape_string($nodeid); + $q = sqlite_query($GLOBALS['idx'], "SELECT title from idents where id='$safeid'"); + + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $ids[$nodeid] = $r[0]; + return $r[0]; + } elseif (isset($GLOBALS['fb_idx'])) { + $q = sqlite_query($GLOBALS['fb_idx'], "SELECT title from idents where id='$safeid'"); + + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $ids[$nodeid] = $r[0]; + return $r[0]; + } + } + return null; } function make_function_link($ref) { - $parts = explode('.', $ref); - $id = 'function.'. $parts[3]; - $title = lookup_title($id); - if (!$title) { - $title = $id. ' [?]'; - } - $func_name = strtr($parts[3], array('-'=>'_')); - if ($title == $func_name) { - $title = ""; - } else { - $title = " - $title"; - } - return "<div class=\"function_link\"><function>$func_name</function>$title</div>"; + $parts = explode('.', $ref); + $id = 'function.'. $parts[3]; + $title = lookup_title($id); + if (!$title) { + $title = $id. ' [?]'; + } + $func_name = strtr($parts[3], array('-'=>'_')); + if ($title == $func_name) { + $title = ""; + } else { + $title = " - $title"; + } + return "<div class=\"function_link\"><function>$func_name</function>$title</div>"; } function make_xref($ref) { - $parts = explode('.', $ref); - if ($parts[0] == 'reference' && $parts[2] == 'functions') { - $id = 'function.'. $parts[3]; - } - $title = lookup_title($id); - if (!$title) { - $title = $id. ' [?]'; - } - return "<xref linkend=\"$id\">$title</xref>"; + $parts = explode('.', $ref); + if ($parts[0] == 'reference' && $parts[2] == 'functions') { + $id = 'function.'. $parts[3]; + } + $title = lookup_title($id); + if (!$title) { + $title = $id. ' [?]'; + } + return "<xref linkend=\"$id\">$title</xref>"; } function handle_funcref() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - $ret = "<h1>$current_page_title</h1>\n"; - foreach ($children as $id => $title) { - $url = generate_url_for_id($lang, $id); - $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; - } - return $ret."<br /><br />"; + $ret = "<h1>$current_page_title</h1>\n"; + foreach ($children as $id => $title) { + $url = generate_url_for_id($lang, $id); + $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; + } + return $ret."<br /><br />"; } function handle_appendixes() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - $ret = "<h1>$current_page_title</h1>\n"; - foreach ($children as $id => $title) { - $url = generate_url_for_id($lang, $id); - $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; - } - return $ret . "<br /><br />"; - + $ret = "<h1>$current_page_title</h1>\n"; + foreach ($children as $id => $title) { + $url = generate_url_for_id($lang, $id); + $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; + } + return $ret . "<br /><br />"; + } function do_contents($id, $level) { - global $lang; - $q = "SELECT id, docbook_id FROM toc WHERE parent_id = $id"; - $r = sqlite_query($GLOBALS['idx'], $q); - $ret = "<ul>"; - while ($r && $row = sqlite_fetch_array($r, SQLITE_NUM)) { - $ret .= "<li>"; - - $title = lookup_title($row[1]); - if (empty($title)) { - $title = $row[1]. ' [?]'; - $ret .= $title; - } else { - $url = generate_url_for_id($lang, $row[1]); - $ret .= "<a href='$url'>$title</a>"; - } - - if (($level < 2 && substr($row[1], 0, 3) != 'ref') || $level < 1) { - $ret .= do_contents($row[0], $level + 1); - } - $ret .= "</li>\n"; - } - return $ret .= "</ul>\n"; + global $lang; + $q = "SELECT id, docbook_id FROM toc WHERE parent_id = $id"; + $r = sqlite_query($GLOBALS['idx'], $q); + $ret = "<ul>"; + while ($r && $row = sqlite_fetch_array($r, SQLITE_NUM)) { + $ret .= "<li>"; + + $title = lookup_title($row[1]); + if (empty($title)) { + $title = $row[1]. ' [?]'; + $ret .= $title; + } else { + $url = generate_url_for_id($lang, $row[1]); + $ret .= "<a href='$url'>$title</a>"; + } + + if (($level < 2 && substr($row[1], 0, 3) != 'ref') || $level < 1) { + $ret .= do_contents($row[0], $level + 1); + } + $ret .= "</li>\n"; + } + return $ret .= "</ul>\n"; } function handle_contents() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - return "<center><h1>PHP Manual</h1></center><h2>Contents</h2>" . do_contents(1, 0); + return "<center><h1>PHP Manual</h1></center><h2>Contents</h2>" . do_contents(1, 0); } function handle_include($node) { - $filename = BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; - $fallback_filename = FALLBACK_BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; + $filename = BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; + $fallback_filename = FALLBACK_BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; - $doc = load_xml_doc($filename, true, $fallback_filename); - return $doc->transform($GLOBALS['map']); + $doc = load_xml_doc($filename, true, $fallback_filename); + return $doc->transform($GLOBALS['map']); } // Handle the case where a requested node id was not found function handle_missing_index() { - global $current_page, $lang; + global $current_page, $lang; - header('Location: ' . WEBBASE . 'search.php?q=' . urlencode($current_page) . '&l=' . $lang); - exit; + header('Location: ' . WEBBASE . 'search.php?q=' . urlencode($current_page) . '&l=' . $lang); + exit; } ?> http://cvs.php.net/diff.php/livedocs/mkindex.php?r1=1.16&r2=1.17&ty=u Index: livedocs/mkindex.php diff -u livedocs/mkindex.php:1.16 livedocs/mkindex.php:1.17 --- livedocs/mkindex.php:1.16 Mon Jan 12 18:04:30 2004 +++ livedocs/mkindex.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -19,7 +19,7 @@ // | construct an index | // +----------------------------------------------------------------------+ // -// $Id: mkindex.php,v 1.16 2004/01/12 23:04:30 didou Exp $ +// $Id: mkindex.php,v 1.17 2004/02/16 17:54:59 derick Exp $ /* just to be on the safe side */ @@ -31,234 +31,234 @@ $TMPDIR = $argv[3]; if (!is_dir($PHPDOC) || !is_dir($PHPDOC . DIRECTORY_SEPARATOR . $LANG)) { - echo "Usage: index-phpdoc.php /path/to/phpdoc lang tmp-dir\n"; - exit(1); + echo "Usage: index-phpdoc.php /path/to/phpdoc lang tmp-dir\n"; + exit(1); } function entity_replace($data) { - global $replacements; + global $replacements; - $entity_name = substr($data[0], 1, -1); - if (isset($replacements[$entity_name])) { - $data[0] = $replacements[$entity_name]; - } else { - $data[0] = ''; - } + $entity_name = substr($data[0], 1, -1); + if (isset($replacements[$entity_name])) { + $data[0] = $replacements[$entity_name]; + } else { + $data[0] = ''; + } - return $data[0]; + return $data[0]; } class DocBookXMLFileParser { - var $fileid = false; - var $last_id = false; - var $cdata = null; - var $data = ''; - - function DocBookXMLFileParser($filename, $rel, $parser) { - $this->fileid = $GLOBALS['fileid']; - - xml_set_object($parser, $this); - xml_set_element_handler($parser, "start_elem", "end_elem"); - xml_set_character_data_handler($parser, "cdata"); - xml_set_external_entity_ref_handler($parser, "ext_ent"); - xml_set_unparsed_entity_decl_handler($parser, "unp_ent"); - - $data = file_get_contents($filename); - /* Yes, we do this twice, because the entities can contain entities again */ - $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); - $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); - if (!xml_parse($parser, $data, true)) { - if (xml_get_error_code($parser) != XML_ERROR_NO_ELEMENTS) { - $lines = split("\n", $data); - printf("XML Error: %s:%d %s: '%s'\n", - $filename, xml_get_current_line_number($parser), - xml_error_string(xml_get_error_code($parser)), - $lines[xml_get_current_line_number($parser) - 1] - ); - } - } - } - - function start_elem($parser, $name, $attrs) { - // if there is an ID attribute, record it - if (isset($attrs['ID'])) { - $this->last_id = $attrs['ID']; - } - } - - function end_elem($parser, $name) { - if ($this->last_id !== false) { - echo "\tAdded ID {$this->last_id}\n"; - - $this->data .= "INSERT INTO idents VALUES ('{$this->last_id}', {$this->fileid}, '" . sqlite_escape_string(trim($this->cdata)) . "');"; - - if ($this->last_id == 'wrappers') { - echo "\n\n"; - } - - $this->last_id = false; - } - } - - function cdata($parser, $data) { - if ($this->last_id !== false) { - $this->cdata = $data; - } - } - - function ext_ent($parser, $openEntityNames, $base, $systemId, $publicId) { - echo "EXT:"; - $a = func_get_args(); - array_shift($a); - print_r($a); - return false; - } - - function unp_ent($parser, $entity_name, $base, $system_id, $public_id, $notation_name) { - echo "UNP:"; - $a = func_get_args(); - array_shift($a); - print_r($a); - return false; - } + var $fileid = false; + var $last_id = false; + var $cdata = null; + var $data = ''; + + function DocBookXMLFileParser($filename, $rel, $parser) { + $this->fileid = $GLOBALS['fileid']; + + xml_set_object($parser, $this); + xml_set_element_handler($parser, "start_elem", "end_elem"); + xml_set_character_data_handler($parser, "cdata"); + xml_set_external_entity_ref_handler($parser, "ext_ent"); + xml_set_unparsed_entity_decl_handler($parser, "unp_ent"); + + $data = file_get_contents($filename); + /* Yes, we do this twice, because the entities can contain entities again */ + $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); + $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); + if (!xml_parse($parser, $data, true)) { + if (xml_get_error_code($parser) != XML_ERROR_NO_ELEMENTS) { + $lines = split("\n", $data); + printf("XML Error: %s:%d %s: '%s'\n", + $filename, xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser)), + $lines[xml_get_current_line_number($parser) - 1] + ); + } + } + } + + function start_elem($parser, $name, $attrs) { + // if there is an ID attribute, record it + if (isset($attrs['ID'])) { + $this->last_id = $attrs['ID']; + } + } + + function end_elem($parser, $name) { + if ($this->last_id !== false) { + echo "\tAdded ID {$this->last_id}\n"; + + $this->data .= "INSERT INTO idents VALUES ('{$this->last_id}', {$this->fileid}, '" . sqlite_escape_string(trim($this->cdata)) . "');"; + + if ($this->last_id == 'wrappers') { + echo "\n\n"; + } + + $this->last_id = false; + } + } + + function cdata($parser, $data) { + if ($this->last_id !== false) { + $this->cdata = $data; + } + } + + function ext_ent($parser, $openEntityNames, $base, $systemId, $publicId) { + echo "EXT:"; + $a = func_get_args(); + array_shift($a); + print_r($a); + return false; + } + + function unp_ent($parser, $entity_name, $base, $system_id, $public_id, $notation_name) { + echo "UNP:"; + $a = func_get_args(); + array_shift($a); + print_r($a); + return false; + } } function build_func_list() { - global $idx; - - $list = file_get_contents($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . "xsl/version.xml"); - $x = preg_match_all('@<function name=([\'"])([a-zA-Z0-9_]+)\\1 from=([\'"])(.+)\\3@Usm', $list, $matches); - $data = ''; - for ($i = 0; $i < $x; $i++) { - $func = sqlite_escape_string($matches[2][$i]); - $vers = sqlite_escape_string($matches[4][$i]); - $data .= "INSERT INTO funcs VALUES('$func', '$vers');"; - } - if ($data) { - sqlite_query($idx, $data); - } + global $idx; + + $list = file_get_contents($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . "xsl/version.xml"); + $x = preg_match_all('@<function name=([\'"])([a-zA-Z0-9_]+)\\1 from=([\'"])(.+)\\3@Usm', $list, $matches); + $data = ''; + for ($i = 0; $i < $x; $i++) { + $func = sqlite_escape_string($matches[2][$i]); + $vers = sqlite_escape_string($matches[4][$i]); + $data .= "INSERT INTO funcs VALUES('$func', '$vers');"; + } + if ($data) { + sqlite_query($idx, $data); + } } function parse_file($filename, $rel, $dirid) { - global $idx, $fileid; + global $idx, $fileid; - echo "Parse file: $rel "; + echo "Parse file: $rel "; - /* create an entry in the files table */ - $q = sqlite_query($idx, "SELECT fileid, mtime from files where filename='$rel'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - list($fileid, $mtime) = $r; - if (filemtime($filename) <= $mtime) { - echo " Skipping; already indexed\n"; - return; - } - echo " Reparsing file ID $fileid\n"; - } else { - $mtime = filemtime($filename); - sqlite_query($idx, "INSERT INTO files VALUES (NULL, '$rel', $mtime, $dirid)"); - $fileid = sqlite_last_insert_rowid($idx); - echo " Parsing file ID $fileid\n"; - } - - $parser = xml_parser_create(); - $p = new DocBookXMLFileParser($filename, $rel, $parser); - xml_parser_free($parser); - - if ($p->data) { - sqlite_query($idx, $p->data); - } + /* create an entry in the files table */ + $q = sqlite_query($idx, "SELECT fileid, mtime from files where filename='$rel'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + list($fileid, $mtime) = $r; + if (filemtime($filename) <= $mtime) { + echo " Skipping; already indexed\n"; + return; + } + echo " Reparsing file ID $fileid\n"; + } else { + $mtime = filemtime($filename); + sqlite_query($idx, "INSERT INTO files VALUES (NULL, '$rel', $mtime, $dirid)"); + $fileid = sqlite_last_insert_rowid($idx); + echo " Parsing file ID $fileid\n"; + } + + $parser = xml_parser_create(); + $p = new DocBookXMLFileParser($filename, $rel, $parser); + xml_parser_free($parser); + + if ($p->data) { + sqlite_query($idx, $p->data); + } } function scan_entities($dirname) { - global $idx, $LANG; + global $idx, $LANG; - sqlite_query($idx, 'delete from ents'); + sqlite_query($idx, 'delete from ents'); - $ents = glob($dirname . '/*.ent'); - $language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . $LANG . DIRECTORY_SEPARATOR . '*.ent'); - if ($LANG != 'en') { - $fallback_language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '*.ent'); - } else { - $fallback_language_defs = array(); - } - $files = array_merge($ents, $language_defs, $fallback_language_defs); - $skip = array('chapters.ent');//, 'file-entities.ent'); - $language_def_files = array('language-defs.ent', 'language-snippets.ent'); - $pats = array( '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+\'([^\']+)\'>/Usm', '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+"([^"]+)">/Usm' ); - - foreach ($files as $filename) { - echo "Entities: $filename\n"; - if (in_array(basename($filename), $skip)) { - echo "Skip!\n"; - continue; - } - - $d = file_get_contents($filename); - - foreach ($pats as $pat) { - $x = preg_match_all($pat, $d, $matches); - - for ($i = 0; $i < $x; $i++) { - if (!isset($replacements[$matches[1][$i]])) { - $id = sqlite_escape_string($matches[1][$i]); - $value = sqlite_escape_string($matches[2][$i]); - @sqlite_query($idx, "INSERT INTO ents VALUES ('$id', '$value')"); - - $replacements[$matches[1][$i]] = $matches[2][$i]; - } - } - } - } - return $replacements; + $ents = glob($dirname . '/*.ent'); + $language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . $LANG . DIRECTORY_SEPARATOR . '*.ent'); + if ($LANG != 'en') { + $fallback_language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '*.ent'); + } else { + $fallback_language_defs = array(); + } + $files = array_merge($ents, $language_defs, $fallback_language_defs); + $skip = array('chapters.ent');//, 'file-entities.ent'); + $language_def_files = array('language-defs.ent', 'language-snippets.ent'); + $pats = array( '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+\'([^\']+)\'>/Usm', '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+"([^"]+)">/Usm' ); + + foreach ($files as $filename) { + echo "Entities: $filename\n"; + if (in_array(basename($filename), $skip)) { + echo "Skip!\n"; + continue; + } + + $d = file_get_contents($filename); + + foreach ($pats as $pat) { + $x = preg_match_all($pat, $d, $matches); + + for ($i = 0; $i < $x; $i++) { + if (!isset($replacements[$matches[1][$i]])) { + $id = sqlite_escape_string($matches[1][$i]); + $value = sqlite_escape_string($matches[2][$i]); + @sqlite_query($idx, "INSERT INTO ents VALUES ('$id', '$value')"); + + $replacements[$matches[1][$i]] = $matches[2][$i]; + } + } + } + } + return $replacements; } function scan_dir($dirname, $rel = '') { - global $idx; - - $d = opendir($dirname); - if (!$d) { - return false; - } - - if ($rel == 'functions') { - return; - } - - $files = array(); - $rel_l = strlen($rel); - - $q = sqlite_query($idx, "SELECT dirid from dirs where dirname='$rel'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $dirid = $r[0]; - } else { - sqlite_query($idx, "INSERT INTO dirs VALUES(NULL, '$rel')"); - $dirid = sqlite_last_insert_rowid($idx); - } - - readdir($d); - readdir($d); - while (($f = readdir($d)) !== false) { - if ($f == 'CVS') { - continue; - } - $full = $dirname . DIRECTORY_SEPARATOR . $f; - if ($rel_l) { - $relname = $rel . DIRECTORY_SEPARATOR . $f; - } else { - $relname = $f; - } - if (is_dir($full)) { - scan_dir($full, $relname); - } else if (substr($f, -4) == '.xml') { - if ($f != 'functions.xml' || $relname == 'language/functions.xml') { - $files[$f] = $full; - parse_file($full, $relname, $dirid); - } - } - } - closedir($d); + global $idx; + + $d = opendir($dirname); + if (!$d) { + return false; + } + + if ($rel == 'functions') { + return; + } + + $files = array(); + $rel_l = strlen($rel); + + $q = sqlite_query($idx, "SELECT dirid from dirs where dirname='$rel'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $dirid = $r[0]; + } else { + sqlite_query($idx, "INSERT INTO dirs VALUES(NULL, '$rel')"); + $dirid = sqlite_last_insert_rowid($idx); + } + + readdir($d); + readdir($d); + while (($f = readdir($d)) !== false) { + if ($f == 'CVS') { + continue; + } + $full = $dirname . DIRECTORY_SEPARATOR . $f; + if ($rel_l) { + $relname = $rel . DIRECTORY_SEPARATOR . $f; + } else { + $relname = $f; + } + if (is_dir($full)) { + scan_dir($full, $relname); + } else if (substr($f, -4) == '.xml') { + if ($f != 'functions.xml' || $relname == 'language/functions.xml') { + $files[$f] = $full; + parse_file($full, $relname, $dirid); + } + } + } + closedir($d); } @@ -272,66 +272,66 @@ sqlite_query($idx, 'PRAGMA cache_size=100000'); if (!$idx) { - die("could not open sqlite database"); + die("could not open sqlite database"); } $create = <<<SQL CREATE TABLE dirs ( - dirid INTEGER PRIMARY KEY, - dirname TEXT + dirid INTEGER PRIMARY KEY, + dirname TEXT ); CREATE TABLE files ( - fileid INTEGER PRIMARY KEY, - filename TEXT, - mtime INTEGER, - dirid INTEGER + fileid INTEGER PRIMARY KEY, + filename TEXT, + mtime INTEGER, + dirid INTEGER ); CREATE TABLE idents ( - id TEXT PRIMARY KEY, - fileid INTEGER, -- The file in which the identifier can be found - title TEXT -- Caption of the identifier for linking purposes + id TEXT PRIMARY KEY, + fileid INTEGER, -- The file in which the identifier can be found + title TEXT -- Caption of the identifier for linking purposes ); CREATE TABLE ents ( - entid TEXT PRIMARY KEY, - value TEXT + entid TEXT PRIMARY KEY, + value TEXT ); CREATE TABLE funcs ( - funcname TEXT PRIMARY KEY, - versinfo TEXT + funcname TEXT PRIMARY KEY, + versinfo TEXT ); CREATE TABLE toc ( - id INTEGER PRIMARY KEY, - lvl INTEGER, - parent_id INTEGER, - docbook_id TEXT, - parent_docbook_id TEXT, - path TEXT, - title TEXT, - descr TEXT + id INTEGER PRIMARY KEY, + lvl INTEGER, + parent_id INTEGER, + docbook_id TEXT, + parent_docbook_id TEXT, + path TEXT, + title TEXT, + descr TEXT ); CREATE TABLE searchi ( - skey VARCHAR(230), - path VARCHAR(230), - prio INTEGER + skey VARCHAR(230), + path VARCHAR(230), + prio INTEGER ); CREATE INDEX searchi_skey_idx ON searchi(skey); CREATE TABLE full_search ( - skey VARCHAR(100), - toc_id INTEGER + skey VARCHAR(100), + toc_id INTEGER ); CREATE INDEX full_search_skey_idx ON full_search(skey); CREATE TABLE stop_list ( - slkey VARCHAR(100) + slkey VARCHAR(100) ); CREATE INDEX stop_list_idx ON stop_list(slkey); SQL; @@ -348,7 +348,7 @@ sqlite_query($idx, 'COMMIT'); $qry_str = ''; - + /* * Priority List * 1 - section @@ -357,27 +357,27 @@ * 4 - function metaphone * 5 - function name minus 1 prefix str_replace -> replace */ - + $f_len = strlen('function.'); - + $r = sqlite_unbuffered_query("SELECT docbook_id FROM toc", $idx); while (($f = sqlite_fetch_string($r)) !== FALSE) { - $path = sqlite_escape_string($f); - if (($p = strrpos($f, '.')) !== false) { - $fn = strtolower(substr($f, ++$p)); - } else { - $fn = strtolower($f); - } - $f_name = preg_replace('![^a-z0-9]!', '', $fn); - - if (!strncmp($f, 'function.', $f_len)) { - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 2);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 4);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(preg_replace('![^a-z0-9]!', '', substr(strstr($f, '-'), 1)))."', '" . $path . "', 5);"; - } else { - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 1);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 3);"; - } + $path = sqlite_escape_string($f); + if (($p = strrpos($f, '.')) !== false) { + $fn = strtolower(substr($f, ++$p)); + } else { + $fn = strtolower($f); + } + $f_name = preg_replace('![^a-z0-9]!', '', $fn); + + if (!strncmp($f, 'function.', $f_len)) { + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 2);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 4);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(preg_replace('![^a-z0-9]!', '', substr(strstr($f, '-'), 1)))."', '" . $path . "', 5);"; + } else { + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 1);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 3);"; + } } sqlite_query($idx, 'BEGIN TRANSACTION; '.$qry_str.' COMMIT'); unset($qry_str); @@ -389,112 +389,112 @@ define('MIN_WORD_LEN', 2); function search_parse_file($file, &$descr) { - $descr = $ret = ''; - $p = 0; - $fd = file_get_contents($file); - - if (($p = strpos($fd, '<title>')) !== FALSE) { - $p += TITLE_LEN; - if (($e = strpos($fd, '</refpurpose>', $p)) !== FALSE) { - $descr = substr($fd, $p, ($e - $p)); - $p = $e + 1 + TITLE_LEN; - } - } - - if (($p = strpos($fd, '<refpurpose>')) !== false) { - $p += REFP_LEN; - if (($e = strpos($fd, '</refpurpose>', $p)) !== false) { - $descr = substr($fd, $p, ($e - $p)); - $ret = $descr . ' '; - $p = SEE_ALSO_LEN + $e + 1; - } - } - - while (($p = strpos($fd, 'para>', $p)) !== false) { - if ($fd{$p - 1} == '<') { - $tag = '</para>'; - $p += 5; - } else if ($fd{$p - 1} == 'm' && $fd{$p - 2} == 'i' && $fd{$p - 3} == 's' && $fd{$p - 4} == '<') { - $tag = '</simpara>'; - $p += 5; - } else { - $p += 5; - continue; - } - if (($e = strpos($fd, $tag, $p)) === false) { - echo "Warning: non terminated $tag inside $file\n"; - break; - } - $d = substr($fd, $p, ($e - $p)); - $p = $e; - - if (!strncmp($d, 'See also:', SEE_ALSO_LEN)) { - continue; - } + $descr = $ret = ''; + $p = 0; + $fd = file_get_contents($file); + + if (($p = strpos($fd, '<title>')) !== FALSE) { + $p += TITLE_LEN; + if (($e = strpos($fd, '</refpurpose>', $p)) !== FALSE) { + $descr = substr($fd, $p, ($e - $p)); + $p = $e + 1 + TITLE_LEN; + } + } + + if (($p = strpos($fd, '<refpurpose>')) !== false) { + $p += REFP_LEN; + if (($e = strpos($fd, '</refpurpose>', $p)) !== false) { + $descr = substr($fd, $p, ($e - $p)); + $ret = $descr . ' '; + $p = SEE_ALSO_LEN + $e + 1; + } + } + + while (($p = strpos($fd, 'para>', $p)) !== false) { + if ($fd{$p - 1} == '<') { + $tag = '</para>'; + $p += 5; + } else if ($fd{$p - 1} == 'm' && $fd{$p - 2} == 'i' && $fd{$p - 3} == 's' && $fd{$p - 4} == '<') { + $tag = '</simpara>'; + $p += 5; + } else { + $p += 5; + continue; + } + if (($e = strpos($fd, $tag, $p)) === false) { + echo "Warning: non terminated $tag inside $file\n"; + break; + } + $d = substr($fd, $p, ($e - $p)); + $p = $e; + + if (!strncmp($d, 'See also:', SEE_ALSO_LEN)) { + continue; + } - $ret .= $d . ' '; - } + $ret .= $d . ' '; + } - $ret = preg_replace('![^a-z0-9\'_-]!', ' ', strtolower(strip_tags($ret))); - $ret = preg_replace('!\s+!', ' ', $ret); + $ret = preg_replace('![^a-z0-9\'_-]!', ' ', strtolower(strip_tags($ret))); + $ret = preg_replace('!\s+!', ' ', $ret); - return array_unique(explode(' ', sqlite_escape_string($ret))); + return array_unique(explode(' ', sqlite_escape_string($ret))); } function search_parse_dir($path, $section) { - global $idx, $toca, $tocd; + global $idx, $toca, $tocd; - $d = opendir($path); - readdir($d); readdir($d); + $d = opendir($path); + readdir($d); readdir($d); - while (($f = readdir($d))) { - if ($f == 'functions.xml' || $f == 'CVS' || $f == '.cvsignore') { - continue; - } - switch (filetype($path . '/' . $f)) { - case 'file': - switch ($section) { - case 'reference' : - if ($f == 'configure.xml' || $f == 'constants.xml' || $f == 'ini.xml' || $f == 'reference.xml') { - $docbook_id = 'ref.' . basename($path); - } else { - $docbook_id = 'function.' . substr($f, 0, -4); - } - break; - case 'faq': - case 'security' : - $docbook_id = $section . '.' . substr($f, 0, -4); - break; - case 'chapters' : - case 'appendices' : - $docbook_id = substr($f, 0, -4); - break; - } - - if (isset($toca[$docbook_id])) { - $id = $toca[$docbook_id]; - $wl = search_parse_file($path . '/' . $f, $descr); - if ($descr && !isset($tocd[$id])) { - $tocd[$id] = trim($descr); - } - $qry = ''; - foreach ($wl as $w) { - if (strlen($w) > MIN_WORD_LEN) { - $qry .= "INSERT INTO full_search VALUES('{$w}', {$id});"; - } - } - sqlite_query($idx, $qry); - } else { - echo "BAD ID: $docbook_id ($path, $f, $section)\n"; - } - break; - case 'dir' : - search_parse_dir($path . '/' . $f, $section); - break; - } - } - closedir($d); + while (($f = readdir($d))) { + if ($f == 'functions.xml' || $f == 'CVS' || $f == '.cvsignore') { + continue; + } + switch (filetype($path . '/' . $f)) { + case 'file': + switch ($section) { + case 'reference' : + if ($f == 'configure.xml' || $f == 'constants.xml' || $f == 'ini.xml' || $f == 'reference.xml') { + $docbook_id = 'ref.' . basename($path); + } else { + $docbook_id = 'function.' . substr($f, 0, -4); + } + break; + case 'faq': + case 'security' : + $docbook_id = $section . '.' . substr($f, 0, -4); + break; + case 'chapters' : + case 'appendices' : + $docbook_id = substr($f, 0, -4); + break; + } + + if (isset($toca[$docbook_id])) { + $id = $toca[$docbook_id]; + $wl = search_parse_file($path . '/' . $f, $descr); + if ($descr && !isset($tocd[$id])) { + $tocd[$id] = trim($descr); + } + $qry = ''; + foreach ($wl as $w) { + if (strlen($w) > MIN_WORD_LEN) { + $qry .= "INSERT INTO full_search VALUES('{$w}', {$id});"; + } + } + sqlite_query($idx, $qry); + } else { + echo "BAD ID: $docbook_id ($path, $f, $section)\n"; + } + break; + case 'dir' : + search_parse_dir($path . '/' . $f, $section); + break; + } + } + closedir($d); } // list of directories to index @@ -504,18 +504,18 @@ sqlite_query($idx, 'BEGIN TRANSACTION'); $r = sqlite_unbuffered_query("SELECT id, docbook_id FROM toc", $idx); while (($row = sqlite_fetch_array($r, SQLITE_NUM))) { - $toca[$row[1]] = $row[0]; + $toca[$row[1]] = $row[0]; } $tocd = array(); foreach ($parse_dirs as $dir) { - search_parse_dir($path . $dir, $dir); + search_parse_dir($path . $dir, $dir); } $qry = ''; foreach ($tocd as $k => $v) { - $qry .= "UPDATE toc SET descr='".sqlite_escape_string($v)."' WHERE id={$k};"; + $qry .= "UPDATE toc SET descr='".sqlite_escape_string($v)."' WHERE id={$k};"; } sqlite_query($idx, $qry); sqlite_query($idx, 'COMMIT'); @@ -525,10 +525,10 @@ sqlite_query($idx, 'BEGIN TRANSACTION'); $qry1 = $qry2 = ''; foreach ($file as $w) { - $w = sqlite_escape_string(rtrim($w)); + $w = sqlite_escape_string(rtrim($w)); - $qry1 .= "DELETE FROM full_search WHERE skey='{$w}';"; - $qry2 .= "INSERT INTO stop_list VALUES('{$w}');"; + $qry1 .= "DELETE FROM full_search WHERE skey='{$w}';"; + $qry2 .= "INSERT INTO stop_list VALUES('{$w}');"; } sqlite_query($idx, $qry1); sqlite_query($idx, $qry2); @@ -539,12 +539,12 @@ $qry = ''; sqlite_query($idx, 'BEGIN TRANSACTION'); while (($row = sqlite_fetch_array($r, SQLITE_NUM))) { - if ($row[2] == 1) { - break; - } + if ($row[2] == 1) { + break; + } - $del = $row[2] - 1; - $qry .= "DELETE FROM full_search WHERE skey='".sqlite_escape_string($row[0])."' AND toc_id=".$row[1].";"; + $del = $row[2] - 1; + $qry .= "DELETE FROM full_search WHERE skey='".sqlite_escape_string($row[0])."' AND toc_id=".$row[1].";"; } sqlite_query($idx, $qry); sqlite_query($idx, 'COMMIT'); @@ -557,17 +557,17 @@ $tbl_data = <<<SQL_CACHE CREATE TABLE cache_data ( - toc_id INTEGER, - qry_id INTEGER, - pos INTEGER + toc_id INTEGER, + qry_id INTEGER, + pos INTEGER ); CREATE INDEX cache_data_idx ON cache_data(qry_id); CREATE TABLE search_cache ( - id INTEGER PRIMARY KEY, - ttl INTEGER, - qry TEXT + id INTEGER PRIMARY KEY, + ttl INTEGER, + qry TEXT ); CREATE INDEX search_cache_idx ON search_cache(qry); http://cvs.php.net/diff.php/livedocs/mktoc.php?r1=1.7&r2=1.8&ty=u Index: livedocs/mktoc.php diff -u livedocs/mktoc.php:1.7 livedocs/mktoc.php:1.8 --- livedocs/mktoc.php:1.7 Fri Jan 30 00:49:15 2004 +++ livedocs/mktoc.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -20,85 +20,85 @@ // | tree into the toc table. | // +----------------------------------------------------------------------+ // -// $Id: mktoc.php,v 1.7 2004/01/30 05:49:15 momo Exp $ +// $Id: mktoc.php,v 1.8 2004/02/16 17:54:59 derick Exp $ set_magic_quotes_runtime(0); class DocBookTOCParser { - var $cdata = null; - var $id_stack = array(); - var $docbook_id_stack = array(); - var $last_id = 1; - - function DocBookTOCParser($filename, $rel, $parser) { - $this->fileid = $GLOBALS['fileid']; - - xml_set_object($parser, $this); - xml_set_element_handler($parser, "start_elem", "end_elem"); - - $data = file_get_contents($filename); - if (!xml_parse($parser, $data, true)) { - printf("XML: %s:%d %s\n", - $filename, xml_get_current_line_number($parser), - xml_error_string(xml_get_error_code($parser)) - ); - } - } - - function start_elem($parser, $name, $attrs) { - global $idx; - - /* if there is an ID attribute, record it */ - $docbook_id = sqlite_escape_string($attrs['ID']); - $title = sqlite_escape_string($attrs['TITLE']); - - $level = sizeof($this->id_stack) - 1; - if (isset($this->id_stack[$level])) { - $parent_id = (int) $this->id_stack[$level]; - } else { - $parent_id = 0; - } - $level = sizeof($this->docbook_id_stack) - 1; - if (isset($this->docbook_id_stack[$level])) { - $docbook_parent_id = sqlite_escape_string($this->docbook_id_stack[$level]); - } else { - $docbook_parent_id = ''; - } - $path = sqlite_escape_string(implode(",", $this->docbook_id_stack)); - - array_push($this->id_stack, $this->last_id); - array_push($this->docbook_id_stack, $docbook_id); - - echo "INSERT INTO toc VALUES ({$this->last_id}, {$level}, {$parent_id}, '{$docbook_id}', '{$docbook_parent_id}', '{$path}', '{$title}', '{$title}');\n"; - $this->last_id++; - } - - function end_elem($parser, $name) { - array_pop($this->docbook_id_stack); - array_pop($this->id_stack); - } + var $cdata = null; + var $id_stack = array(); + var $docbook_id_stack = array(); + var $last_id = 1; + + function DocBookTOCParser($filename, $rel, $parser) { + $this->fileid = $GLOBALS['fileid']; + + xml_set_object($parser, $this); + xml_set_element_handler($parser, "start_elem", "end_elem"); + + $data = file_get_contents($filename); + if (!xml_parse($parser, $data, true)) { + printf("XML: %s:%d %s\n", + $filename, xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser)) + ); + } + } + + function start_elem($parser, $name, $attrs) { + global $idx; + + /* if there is an ID attribute, record it */ + $docbook_id = sqlite_escape_string($attrs['ID']); + $title = sqlite_escape_string($attrs['TITLE']); + + $level = sizeof($this->id_stack) - 1; + if (isset($this->id_stack[$level])) { + $parent_id = (int) $this->id_stack[$level]; + } else { + $parent_id = 0; + } + $level = sizeof($this->docbook_id_stack) - 1; + if (isset($this->docbook_id_stack[$level])) { + $docbook_parent_id = sqlite_escape_string($this->docbook_id_stack[$level]); + } else { + $docbook_parent_id = ''; + } + $path = sqlite_escape_string(implode(",", $this->docbook_id_stack)); + + array_push($this->id_stack, $this->last_id); + array_push($this->docbook_id_stack, $docbook_id); + + echo "INSERT INTO toc VALUES ({$this->last_id}, {$level}, {$parent_id}, '{$docbook_id}', '{$docbook_parent_id}', '{$path}', '{$title}', '{$title}');\n"; + $this->last_id++; + } + + function end_elem($parser, $name) { + array_pop($this->docbook_id_stack); + array_pop($this->id_stack); + } } $TOC = $argv[1]; if (!strlen($TOC)) { - echo "Usage: mktoc.php tocfile.xml\n"; - exit(1); + echo "Usage: mktoc.php tocfile.xml\n"; + exit(1); } elseif (!is_file($TOC)) { - echo "Error: $TOC cannot be found or is not a file\n"; - exit(1); + echo "Error: $TOC cannot be found or is not a file\n"; + exit(1); } parse_file($TOC); exit; function parse_file($filename) { - global $idx, $fileid; + global $idx, $fileid; - $parser = xml_parser_create(); - $p = new DocBookTOCParser($filename, $rel='', $parser); - xml_parser_free($parser); + $parser = xml_parser_create(); + $p = new DocBookTOCParser($filename, $rel='', $parser); + xml_parser_free($parser); } ?> http://cvs.php.net/diff.php/livedocs/search.php?r1=1.6&r2=1.7&ty=u Index: livedocs/search.php diff -u livedocs/search.php:1.6 livedocs/search.php:1.7 --- livedocs/search.php:1.6 Fri Jan 23 09:58:38 2004 +++ livedocs/search.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Search page | // +----------------------------------------------------------------------+ // -// $Id: search.php,v 1.6 2004/01/23 14:58:38 didou Exp $ +// $Id: search.php,v 1.7 2004/02/16 17:54:59 derick Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include './common.php'; @@ -29,128 +29,128 @@ define('RESULT_PER_PAGE', 10); function search($qry, $strict, $lang, $idx, &$ttl) { - $key = str_replace("'", '', implode('', $qry)); - sqlite_query($idx, 'BEGIN TRANSACTION'); - sqlite_query($idx, "ATTACH '" . OUTPUTDIR . "/{$lang}/livedoc-cache-idx.{$lang}.sqlite' AS sc"); - - if (($data = sqlite_array_query($idx, "SELECT id, ttl FROM search_cache WHERE qry='{$key}'"))) { - $ttl = $data[0][1]; - $id = $data[0][0]; - } else { - sqlite_query($idx, "INSERT INTO search_cache (ttl, qry) VALUES(0, '{$key}')"); - $id = sqlite_last_insert_rowid($idx); - - sqlite_query($idx, "INSERT INTO cache_data (toc_id, qry_id, pos) SELECT fs.toc_id, '{$id}', count(fs.toc_id) AS cnt FROM - full_search fs WHERE fs.skey IN(" . implode(',', $qry) . ") GROUP BY fs.toc_id ORDER BY cnt DESC LIMIT 300"); - - $ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id}")); - if ($ttl) { - sqlite_query($idx, "UPDATE search_cache SET ttl={$ttl} WHERE id={$id}"); - } - } - sqlite_query($idx, 'COMMIT'); - - if (!$ttl) { - return 0; - } - - if (!isset($_GET['p']) || $ttl <= $_GET['p']) { - $start = $_GET['p'] = 0; - } else { - $start = $_GET['p'] = (int) $_GET['p']; - } - - if ($strict) { - if (!($ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id} AND pos=" . count($qry))))) { - return 0; - } - return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} AND pos=" . count($qry) . " ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); - } + $key = str_replace("'", '', implode('', $qry)); + sqlite_query($idx, 'BEGIN TRANSACTION'); + sqlite_query($idx, "ATTACH '" . OUTPUTDIR . "/{$lang}/livedoc-cache-idx.{$lang}.sqlite' AS sc"); + + if (($data = sqlite_array_query($idx, "SELECT id, ttl FROM search_cache WHERE qry='{$key}'"))) { + $ttl = $data[0][1]; + $id = $data[0][0]; + } else { + sqlite_query($idx, "INSERT INTO search_cache (ttl, qry) VALUES(0, '{$key}')"); + $id = sqlite_last_insert_rowid($idx); + + sqlite_query($idx, "INSERT INTO cache_data (toc_id, qry_id, pos) SELECT fs.toc_id, '{$id}', count(fs.toc_id) AS cnt FROM + full_search fs WHERE fs.skey IN(" . implode(',', $qry) . ") GROUP BY fs.toc_id ORDER BY cnt DESC LIMIT 300"); + + $ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id}")); + if ($ttl) { + sqlite_query($idx, "UPDATE search_cache SET ttl={$ttl} WHERE id={$id}"); + } + } + sqlite_query($idx, 'COMMIT'); + + if (!$ttl) { + return 0; + } + + if (!isset($_GET['p']) || $ttl <= $_GET['p']) { + $start = $_GET['p'] = 0; + } else { + $start = $_GET['p'] = (int) $_GET['p']; + } + + if ($strict) { + if (!($ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id} AND pos=" . count($qry))))) { + return 0; + } + return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} AND pos=" . count($qry) . " ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); + } - return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); + return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); } $res_str = ''; if (!empty($_GET['q'])) { - if (ini_get("magic_quotes_gpc") == '1') { - $tx_qry = stripslashes($_GET['q']); - } else { - $tx_qry = $_GET['q']; - } - $strict = isset($_GET['s']) ? 'checked' : ''; - - $qry = preg_replace('![^a-z0-9 \'_-]!', ' ', strtolower($tx_qry)); - $qry = trim(preg_replace('!\s+!', ' ', $qry)); - $qb = array_unique(explode(' ', $qry)); - foreach ($qb as $w) { - /* XXX: once we upgrade to 4.3.3 or php5 we can optimize this */ - if ($w && strlen($w) > 2) { - $qry_cond[$w] = "'" . sqlite_escape_string($w) . "'"; - } - } - - $html_path = WEBBASE . $lang . '/'; - - if (isset($qry_cond)) { - $data = sqlite_array_query($idx, "SELECT slkey FROM stop_list WHERE slkey IN(" . implode(',', $qry_cond) . ")"); - foreach ($data as $v) { - unset($qry_cond[$v[0]]); - } - if (count($qry_cond)) { - $wl_size = count($qry_cond); - - $data = search($qry_cond, $strict, $lang, $idx, $ttl); - - switch ($ttl) { - case 0: - $res_str = 'No Results Found'; - break; - case 1: - header("Location: {$html_path}{$data[0][0]}.html#{$data[0][0]}"); - exit; - break; - default: - $i = 0; - foreach ($data as $v) { - $m = round(($v[3] / $wl_size) * 100); - $class = !strncmp($v[0], 'function.', strlen('function.')) ? 'function' : 'link'; - ++$i; + if (ini_get("magic_quotes_gpc") == '1') { + $tx_qry = stripslashes($_GET['q']); + } else { + $tx_qry = $_GET['q']; + } + $strict = isset($_GET['s']) ? 'checked' : ''; + + $qry = preg_replace('![^a-z0-9 \'_-]!', ' ', strtolower($tx_qry)); + $qry = trim(preg_replace('!\s+!', ' ', $qry)); + $qb = array_unique(explode(' ', $qry)); + foreach ($qb as $w) { + /* XXX: once we upgrade to 4.3.3 or php5 we can optimize this */ + if ($w && strlen($w) > 2) { + $qry_cond[$w] = "'" . sqlite_escape_string($w) . "'"; + } + } + + $html_path = WEBBASE . $lang . '/'; + + if (isset($qry_cond)) { + $data = sqlite_array_query($idx, "SELECT slkey FROM stop_list WHERE slkey IN(" . implode(',', $qry_cond) . ")"); + foreach ($data as $v) { + unset($qry_cond[$v[0]]); + } + if (count($qry_cond)) { + $wl_size = count($qry_cond); + + $data = search($qry_cond, $strict, $lang, $idx, $ttl); + + switch ($ttl) { + case 0: + $res_str = 'No Results Found'; + break; + case 1: + header("Location: {$html_path}{$data[0][0]}.html#{$data[0][0]}"); + exit; + break; + default: + $i = 0; + foreach ($data as $v) { + $m = round(($v[3] / $wl_size) * 100); + $class = !strncmp($v[0], 'function.', strlen('function.')) ? 'function' : 'link'; + ++$i; $res_str .= <<< SEARCH_RES {$i}) <a class='{$class}' href='{$html_path}{$v[0]}.html#{$v[0]}'>{$v[1]}</a> <b>{$m}% match</b><br /><span class="para">{$v[2]}</span><hr align="left" class="search" /> SEARCH_RES; - } - break; - } - } else { - $res_str = 'No Results Found'; - } - } + } + break; + } + } else { + $res_str = 'No Results Found'; + } + } } else { - $tx_qry = $strict = ''; + $tx_qry = $strict = ''; } echo search_page_header(); - echo $res_str; + echo $res_str; - /* if we have more then 1 page worth of results, let's draw a pager */ - if (isset($ttl) && $ttl > RESULT_PER_PAGE) { - $ttlp = ceil($ttl / RESULT_PER_PAGE); - $curp = floor($_GET['p'] / RESULT_PER_PAGE); - $q = urlencode($tx_qry); - $st = $strict ? '&s=1' : ''; - - echo "<span='para'><b>Pages ({$ttlp}): ["; - for ($i = 0; $i < $ttlp; $i++) { - if ($i != $curp) { - echo " <a class='link' href='" . WEBBASE . "search.php?q={$q}&l={$lang}&p=" . ($i * RESULT_PER_PAGE) . "{$st}'>".($i + 1)."</a> "; - } else { - echo " ".($i + 1)." "; - } - } - echo "]<br /></span>"; - } + /* if we have more then 1 page worth of results, let's draw a pager */ + if (isset($ttl) && $ttl > RESULT_PER_PAGE) { + $ttlp = ceil($ttl / RESULT_PER_PAGE); + $curp = floor($_GET['p'] / RESULT_PER_PAGE); + $q = urlencode($tx_qry); + $st = $strict ? '&s=1' : ''; + + echo "<span='para'><b>Pages ({$ttlp}): ["; + for ($i = 0; $i < $ttlp; $i++) { + if ($i != $curp) { + echo " <a class='link' href='" . WEBBASE . "search.php?q={$q}&l={$lang}&p=" . ($i * RESULT_PER_PAGE) . "{$st}'>".($i + 1)."</a> "; + } else { + echo " ".($i + 1)." "; + } + } + echo "]<br /></span>"; + } echo search_page_footer(); http://cvs.php.net/diff.php/livedocs/style_mapping.php?r1=1.2&r2=1.3&ty=u Index: livedocs/style_mapping.php diff -u livedocs/style_mapping.php:1.2 livedocs/style_mapping.php:1.3 --- livedocs/style_mapping.php:1.2 Sat Jan 17 06:34:07 2004 +++ livedocs/style_mapping.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,494 +18,494 @@ // | Helper functions for formatting elements | // +----------------------------------------------------------------------+ // -// $Id: style_mapping.php,v 1.2 2004/01/17 11:34:07 nlopess Exp $ +// $Id: style_mapping.php,v 1.3 2004/02/16 17:54:59 derick Exp $ // almost XPATH.. ;-) $map = array( - 'acronym' => 'acronym', - 'appendix/title' => 'h1', - 'author' => 'format_name', - 'authorgroup' => 'format_authorgroup', - 'bookinfo/title' => 'h1', - 'chapter/title' => 'h1', - 'classname' => 'span', - 'classsynopsis' => 'format_class_synopsis', - 'code' => 'code', - 'collab' => 'span', - 'collabname' => 'span', - 'command' => 'span', - 'computeroutput' => 'span', - 'constant' => 'span', - 'copyright' => 'format_copyright', - 'copyright/year' => 'span', - 'copyright/holder' => 'span', - 'editor' => 'format_name', - 'emphasis' => 'em', - 'enumname' => 'span', - 'envar' => 'span', - 'filename' => 'span', - 'funcsynopsis' => 'format_funcsynopsis', - 'function' => 'format_function', - 'glossterm' => 'span', - 'htmlcode' => 'format_htmlcode', - 'informaltable' => 'table', - 'informaltable/title' => 'caption', - 'itemizedlist' => 'ul', - 'itemizedlist/listitem' => 'li', - 'legalnotice/title' => 'h3', - 'link' => 'format_link', - 'literal' => 'span', - 'literallayout' => 'format_listing', - 'methodparam' => 'span', - 'methodsynopsis' => 'format_params', - 'option' => 'span', - 'orderedlist' => 'ol', - 'orderedlist/listitem' => 'li', - 'parameter' => 'span', - 'phpdoc_include' => 'handle_include', - 'preface/title' => 'h1', - 'productname' => 'span', - 'programlisting' => 'format_listing', - 'propname' => 'span', - 'proptype' => 'span', - 'pubdate' => 'format_pubdate', - 'reference/title' => 'h1', - 'refnamediv/refname' => 'format_refname', - 'refnamediv/refpurpose' => 'h2', - 'refsect1/title' => 'h3', - 'refsect2/title' => 'h4', - 'replaceable' => 'span', - 'screen' => 'format_listing', - 'section/title' => 'h1', - 'sect1/title' => 'h2', - 'sect2/title' => 'h3', - 'sect3/title' => 'h4', - 'sect4/title' => 'h5', - 'sect5/title' => 'h6', - 'signalname' => 'span', - 'simpara' => 'p', - 'simplelist' => 'ul', - 'simplelist/member' => 'li', - 'subscript' => 'span', - 'systemitem' => 'span', - 'table' => 'table', - 'table/title' => 'caption', - 'tbody' => 'tbody', - 'tbody/row' => 'tr', - 'tbody/row/entry' => 'td', - 'tgroup' => '', - 'thead' => 'thead', - 'thead/row' => 'tr', - 'thead/row/entry' => 'th', - 'titleabbrev' => '', - 'type' => 'span', - 'ulink' => 'format_ulink', - 'userinput' => 'span', - 'varname' => 'span', - 'warning/title' => 'format_warning_title', - 'xref' => 'format_link', + 'acronym' => 'acronym', + 'appendix/title' => 'h1', + 'author' => 'format_name', + 'authorgroup' => 'format_authorgroup', + 'bookinfo/title' => 'h1', + 'chapter/title' => 'h1', + 'classname' => 'span', + 'classsynopsis' => 'format_class_synopsis', + 'code' => 'code', + 'collab' => 'span', + 'collabname' => 'span', + 'command' => 'span', + 'computeroutput' => 'span', + 'constant' => 'span', + 'copyright' => 'format_copyright', + 'copyright/year' => 'span', + 'copyright/holder' => 'span', + 'editor' => 'format_name', + 'emphasis' => 'em', + 'enumname' => 'span', + 'envar' => 'span', + 'filename' => 'span', + 'funcsynopsis' => 'format_funcsynopsis', + 'function' => 'format_function', + 'glossterm' => 'span', + 'htmlcode' => 'format_htmlcode', + 'informaltable' => 'table', + 'informaltable/title' => 'caption', + 'itemizedlist' => 'ul', + 'itemizedlist/listitem' => 'li', + 'legalnotice/title' => 'h3', + 'link' => 'format_link', + 'literal' => 'span', + 'literallayout' => 'format_listing', + 'methodparam' => 'span', + 'methodsynopsis' => 'format_params', + 'option' => 'span', + 'orderedlist' => 'ol', + 'orderedlist/listitem' => 'li', + 'parameter' => 'span', + 'phpdoc_include' => 'handle_include', + 'preface/title' => 'h1', + 'productname' => 'span', + 'programlisting' => 'format_listing', + 'propname' => 'span', + 'proptype' => 'span', + 'pubdate' => 'format_pubdate', + 'reference/title' => 'h1', + 'refnamediv/refname' => 'format_refname', + 'refnamediv/refpurpose' => 'h2', + 'refsect1/title' => 'h3', + 'refsect2/title' => 'h4', + 'replaceable' => 'span', + 'screen' => 'format_listing', + 'section/title' => 'h1', + 'sect1/title' => 'h2', + 'sect2/title' => 'h3', + 'sect3/title' => 'h4', + 'sect4/title' => 'h5', + 'sect5/title' => 'h6', + 'signalname' => 'span', + 'simpara' => 'p', + 'simplelist' => 'ul', + 'simplelist/member' => 'li', + 'subscript' => 'span', + 'systemitem' => 'span', + 'table' => 'table', + 'table/title' => 'caption', + 'tbody' => 'tbody', + 'tbody/row' => 'tr', + 'tbody/row/entry' => 'td', + 'tgroup' => '', + 'thead' => 'thead', + 'thead/row' => 'tr', + 'thead/row/entry' => 'th', + 'titleabbrev' => '', + 'type' => 'span', + 'ulink' => 'format_ulink', + 'userinput' => 'span', + 'varname' => 'span', + 'warning/title' => 'format_warning_title', + 'xref' => 'format_link', ); function format_authorgroup($node) { - $l = ''; - $cl = array(); + $l = ''; + $cl = array(); - foreach ($node->children as $child) { - if ($child->tagname == "author" || $child->tagname == "editor") { - $l .= format_name($child); - } - if ($child->tagname == "collab") { - $cl[] = $child->children[0]->content; - } - } - switch ($node->attributes['id']) { - case "authors": - $prefix = "Authors:<br />"; - break; - case "editors": - $prefix = "Edited by:<br />"; - break; - case "translators"; - $prefix = $cl[0]."<br />"; - unset($cl[0]); - break; - default: - $prefix = $node->attributes['id']; - } + foreach ($node->children as $child) { + if ($child->tagname == "author" || $child->tagname == "editor") { + $l .= format_name($child); + } + if ($child->tagname == "collab") { + $cl[] = $child->children[0]->content; + } + } + switch ($node->attributes['id']) { + case "authors": + $prefix = "Authors:<br />"; + break; + case "editors": + $prefix = "Edited by:<br />"; + break; + case "translators"; + $prefix = $cl[0]."<br />"; + unset($cl[0]); + break; + default: + $prefix = $node->attributes['id']; + } - return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', $node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl)); + return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', $node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl)); } function format_copyright($node) { - $y = array(); + $y = array(); - foreach ($node->children as $child) { - if ($child->tagname == "year") { - $y[] = $child->content; - } else if ($child->tagname == "holder") { - $holder = $child->content; - } - } + foreach ($node->children as $child) { + if ($child->tagname == "year") { + $y[] = $child->content; + } else if ($child->tagname == "holder") { + $holder = $child->content; + } + } - return sprintf('<div class="copyright">Copyright © %s by %s</div>', implode(", ", $y), $holder); + return sprintf('<div class="copyright">Copyright © %s by %s</div>', implode(", ", $y), $holder); } function format_refname($node) { - global $current_page, $idx; + global $current_page, $idx; - $vers = ''; + $vers = ''; - if (substr($current_page, 0, 9) == 'function.') { - $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', '_')); - $q = sqlite_query($idx, "SELECT versinfo FROM funcs where funcname='$func_name'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $vers = sprintf('<div class="versinfo">%s</div>', $r[0]); - } - } - - return sprintf('<h1 class="%s">%s</h1>%s', $node->tagname, $node->content, $vers); + if (substr($current_page, 0, 9) == 'function.') { + $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', '_')); + $q = sqlite_query($idx, "SELECT versinfo FROM funcs where funcname='$func_name'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $vers = sprintf('<div class="versinfo">%s</div>', $r[0]); + } + } + + return sprintf('<h1 class="%s">%s</h1>%s', $node->tagname, $node->content, $vers); } function format_name($node) { - $class = $node->parent->attributes['id']; - foreach ($node->children as $child) { - if ($child->tagname == 'firstname') { - $firstname = $child->content; - } - if ($child->tagname == 'surname') { - $surname = $child->content; - } - } - switch ($class) { - case 'authors': - case 'editors': - $tag = 'div'; - break; - case 'translators': - $tag = 'span'; - break; - default: - $tag = 'span'; - } - return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, $surname, $tag); + $class = $node->parent->attributes['id']; + foreach ($node->children as $child) { + if ($child->tagname == 'firstname') { + $firstname = $child->content; + } + if ($child->tagname == 'surname') { + $surname = $child->content; + } + } + switch ($class) { + case 'authors': + case 'editors': + $tag = 'div'; + break; + case 'translators': + $tag = 'span'; + break; + default: + $tag = 'span'; + } + return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, $surname, $tag); } function format_parameter($node) { - return sprintf('<span class="%s">$%s</span>', $node->tagname, $node->content); + return sprintf('<span class="%s">$%s</span>', $node->tagname, $node->content); } function format_pubdate($node) { - return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, $node->content); + return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, $node->content); } function format_ulink($node) { - return sprintf('<a target="_blank" class="ulink" href="%s">%s</a>', - $node->attributes['url'], - $node->content - ); + return sprintf('<a target="_blank" class="ulink" href="%s">%s</a>', + $node->attributes['url'], + $node->content + ); } function format_warning_title($node) { - return sprintf('<span class="warning_title">%s</span>', $node->content); + return sprintf('<span class="warning_title">%s</span>', $node->content); } function format_link($node) { - global $lang; + global $lang; - $caption = $node->content; - if (strlen($caption) == 0) { - $caption = lookup_title($node->attributes['linkend']); - } - if (strlen($caption) == 0) { - $caption = $node->attributes['linkend']; - } - $url = generate_url_for_id($lang, $node->attributes['linkend']); - return sprintf('<a class="%s" href="%s">%s</a>', - $node->tagname, - $url, - $caption - ); + $caption = $node->content; + if (strlen($caption) == 0) { + $caption = lookup_title($node->attributes['linkend']); + } + if (strlen($caption) == 0) { + $caption = $node->attributes['linkend']; + } + $url = generate_url_for_id($lang, $node->attributes['linkend']); + return sprintf('<a class="%s" href="%s">%s</a>', + $node->tagname, + $url, + $caption + ); } function format_function($node) { - global $current_page, $lang; + global $current_page, $lang; - $itemid = strtr($node->content, '_', '-'); + $itemid = strtr($node->content, '_', '-'); - $class = 'function'; - if (isset($node->attributes['class'])) { - $class = 'method'; - $dest = $node->attributes['class'] . '.method.' . $itemid; - } else { - $dest = 'function.' . $itemid; - } - - if ($current_page == $dest) { - return sprintf('<span class="%s">%s()</span>', $class, $node->content); - } - - $url = generate_url_for_id($lang, $dest); - return sprintf('<a class="%s" href="%s">%s()</a>', - $class, - $url, - $node->content - ); + $class = 'function'; + if (isset($node->attributes['class'])) { + $class = 'method'; + $dest = $node->attributes['class'] . '.method.' . $itemid; + } else { + $dest = 'function.' . $itemid; + } + + if ($current_page == $dest) { + return sprintf('<span class="%s">%s()</span>', $class, $node->content); + } + + $url = generate_url_for_id($lang, $dest); + return sprintf('<a class="%s" href="%s">%s()</a>', + $class, + $url, + $node->content + ); } function format_listing($node) { - $content = trim($node->content); + $content = trim($node->content); - if (substr($content, 0, 5) == '<?php') { - $node->attributes['role'] = 'php'; - } - if (!isset($node->attributes['role'])) { - $node->attributes['role'] = ''; - } - - switch ($node->attributes['role']) { - case 'php': - $content = preg_replace(array( - '@<br />@', - '@<font color="([^"]+)">@', - '@</font>@', - ), - array( - "<br />\n", - '<span class="\\1">', - '</span>', - ), - highlight_string($content, 1)); - break; - case 'shell': - case 'html': - case 'xml': - case 'c': - $content = '<pre>' . htmlentities($content) . '</pre>'; - break; - default: - $content = htmlspecialchars($content); - } + if (substr($content, 0, 5) == '<?php') { + $node->attributes['role'] = 'php'; + } + if (!isset($node->attributes['role'])) { + $node->attributes['role'] = ''; + } + + switch ($node->attributes['role']) { + case 'php': + $content = preg_replace(array( + '@<br />@', + '@<font color="([^"]+)">@', + '@</font>@', + ), + array( + "<br />\n", + '<span class="\\1">', + '</span>', + ), + highlight_string($content, 1)); + break; + case 'shell': + case 'html': + case 'xml': + case 'c': + $content = '<pre>' . htmlentities($content) . '</pre>'; + break; + default: + $content = htmlspecialchars($content); + } - return sprintf('<div class="%scode">%s</div>', $node->attributes['role'], $content); + return sprintf('<div class="%scode">%s</div>', $node->attributes['role'], $content); } function format_params($node) { - $node->parent = null; + $node->parent = null; - /* Check role */ - if (isset($node->attributes['role'])) { - $role = $node->attributes['role']; - } else { - $role = 'php'; - } - - /* build up prototype */ - $type = $node->children[0]->content; - $fname = $node->children[1]->content; - $params = ""; - $optclose = ""; - - for ($i = 2; $i < count($node->children); $i++) { - $k = $node->children[$i]; - - if (strlen($k->tagname) == 0 || $k->tagname == 'void') { - continue; - } - - $p = ''; - if (strlen($params)) { - $p .= ','; - } - - if (isset($k->attributes['choice']) && $k->attributes['choice'] == 'opt') { - $p = '[' . $p ; - $optclose .= ']'; - if (strlen($params)) { - $p = ' ' . $p; - } - } - - if (strlen($p)) { - $p .= ' '; - } - - $p .= '<span class="methodparam"><span class="type">' . $k->children[0]->content . '</span>'; - - $name = $k->children[1]->content; - switch ($role) { - case 'c': - break; - default: - if ($name && $name{0} == '&') { - $name = '&$' . substr($name, 1); - } else { - $name = '$' . $name; - } - } + /* Check role */ + if (isset($node->attributes['role'])) { + $role = $node->attributes['role']; + } else { + $role = 'php'; + } + + /* build up prototype */ + $type = $node->children[0]->content; + $fname = $node->children[1]->content; + $params = ""; + $optclose = ""; + + for ($i = 2; $i < count($node->children); $i++) { + $k = $node->children[$i]; + + if (strlen($k->tagname) == 0 || $k->tagname == 'void') { + continue; + } + + $p = ''; + if (strlen($params)) { + $p .= ','; + } + + if (isset($k->attributes['choice']) && $k->attributes['choice'] == 'opt') { + $p = '[' . $p ; + $optclose .= ']'; + if (strlen($params)) { + $p = ' ' . $p; + } + } + + if (strlen($p)) { + $p .= ' '; + } + + $p .= '<span class="methodparam"><span class="type">' . $k->children[0]->content . '</span>'; + + $name = $k->children[1]->content; + switch ($role) { + case 'c': + break; + default: + if ($name && $name{0} == '&') { + $name = '&$' . substr($name, 1); + } else { + $name = '$' . $name; + } + } - $p .= ' <span class="varname">' . $name . '</span></span>'; + $p .= ' <span class="varname">' . $name . '</span></span>'; - $params .= $p; - } + $params .= $p; + } - return "<div class=\"methodsynopsis\"><span class=\"type\">$type</span> <span class=\"function\">$fname(</span>$params$optclose<span class=\"function\">)</span></div>"; + return "<div class=\"methodsynopsis\"><span class=\"type\">$type</span> <span class=\"function\">$fname(</span>$params$optclose<span class=\"function\">)</span></div>"; } function format_class_synopsis($node) { - $classname = $node->children[0]->children[0]->content; + $classname = $node->children[0]->children[0]->content; - $head = "<div class=\"classsynopsis\">class <span class=\"classname\">$classname</span> {\n<div class=\"classcontents\">"; - $foot = "</div>}\n</div>"; - $body = ""; - - for ($i = 1; $i < count($node->children); $i++) { - $k = $node->children[$i]; - - switch ($k->tagname) { - case 'constructorsynopsis': - case 'methodsynopsis': - $body .= format_params($k); - break; - case 'fieldsynopsis': - $body .= "<div class=\"fieldsynopsis\"><span class=\"type\">" . - $k->children[0]->content . "</span> <span class=\"varname\">" . - $k->children[1]->content . "</span></div>\n"; - break; - } - } + $head = "<div class=\"classsynopsis\">class <span class=\"classname\">$classname</span> {\n<div class=\"classcontents\">"; + $foot = "</div>}\n</div>"; + $body = ""; + + for ($i = 1; $i < count($node->children); $i++) { + $k = $node->children[$i]; + + switch ($k->tagname) { + case 'constructorsynopsis': + case 'methodsynopsis': + $body .= format_params($k); + break; + case 'fieldsynopsis': + $body .= "<div class=\"fieldsynopsis\"><span class=\"type\">" . + $k->children[0]->content . "</span> <span class=\"varname\">" . + $k->children[1]->content . "</span></div>\n"; + break; + } + } - return $head . $body . $foot; + return $head . $body . $foot; } function format_funcsynopsis($node) { - $html = "<div class=\"funcsynopsis\">"; + $html = "<div class=\"funcsynopsis\">"; - /* for each prototype in the synopsis */ - for ($proto = 0; $proto < count($node->children); $proto++) { - $p = $node->children[$proto]; - - if ($p->tagname != 'funcprototype') - continue; - - if (isset($p->attributes['role'])) { - $role = $node->attributes['role']; - } else { - $role = 'php'; - } - - $funcdef = $p->children[0]; - $rettype = ""; - $funcname = ""; - - for ($i = 0; $i < count($funcdef->children); $i++) { - $k = $funcdef->children[$i]; - switch($k->tagname) { - case '': - $rettype = $k->content; - break; - case 'function': - $funcname = $k->content; - break; - } - } - - if ($rettype == '') { - $rettype = 'void'; - } - - - $html .= "<div class=\"funcprototype\"><span class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>"; - - $params = ""; - $optclose = ""; - - for ($i = 1; $i < count($p->children); $i++) { - $def = $p->children[$i]; - if ($def->tagname != 'paramdef') { - continue; - } - $paramhtml = ""; - $paramtype = ""; - $param = null; - - for ($j = 0; $j < count($def->children); $j++) { - $k = $def->children[$j]; - switch($k->tagname) { - case 'parameter': - $param = $k; - break; - case 'enumname': - $paramtype = "<span class=\"enumname\">{$k->content}</enumname>"; - break; - case '': - if (strlen($paramtype) == 0) - $paramtype = $k->content; - break; - } - } - if ($paramtype == '') { - $paramtype = 'void'; - } - - if (count($param->children) > 1) { - $param = $param->children[1]; - $optional = true; - } else { - $optional = false; - } - $paramname = trim($param->content); - - if (strlen($params)) { - $paramhtml .= ','; - } - if ($optional) { - $paramhtml = '[' . $paramhtml; - $optclose .= ']'; - if (strlen($params)) { - $paramhtml = ' ' . $parmhtml; - } - } - - if (strlen($paramhtml)) { - $paramhtml .= ' '; - } - - $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' . $paramtype . '</span>'; - - switch ($role) { - case 'c': - break; - default: - if ($paramname && $paramname{0} == '&') { - $paramname = '&$' . substr($paramname, 1); - } else { - $paramname = '$' . $paramname; - } - } - - $paramhtml .= ' <span class=\"parameter\">' . $paramname . '</span></span>'; + /* for each prototype in the synopsis */ + for ($proto = 0; $proto < count($node->children); $proto++) { + $p = $node->children[$proto]; + + if ($p->tagname != 'funcprototype') + continue; + + if (isset($p->attributes['role'])) { + $role = $node->attributes['role']; + } else { + $role = 'php'; + } + + $funcdef = $p->children[0]; + $rettype = ""; + $funcname = ""; + + for ($i = 0; $i < count($funcdef->children); $i++) { + $k = $funcdef->children[$i]; + switch($k->tagname) { + case '': + $rettype = $k->content; + break; + case 'function': + $funcname = $k->content; + break; + } + } + + if ($rettype == '') { + $rettype = 'void'; + } + + + $html .= "<div class=\"funcprototype\"><span class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>"; + + $params = ""; + $optclose = ""; + + for ($i = 1; $i < count($p->children); $i++) { + $def = $p->children[$i]; + if ($def->tagname != 'paramdef') { + continue; + } + $paramhtml = ""; + $paramtype = ""; + $param = null; + + for ($j = 0; $j < count($def->children); $j++) { + $k = $def->children[$j]; + switch($k->tagname) { + case 'parameter': + $param = $k; + break; + case 'enumname': + $paramtype = "<span class=\"enumname\">{$k->content}</enumname>"; + break; + case '': + if (strlen($paramtype) == 0) + $paramtype = $k->content; + break; + } + } + if ($paramtype == '') { + $paramtype = 'void'; + } + + if (count($param->children) > 1) { + $param = $param->children[1]; + $optional = true; + } else { + $optional = false; + } + $paramname = trim($param->content); + + if (strlen($params)) { + $paramhtml .= ','; + } + if ($optional) { + $paramhtml = '[' . $paramhtml; + $optclose .= ']'; + if (strlen($params)) { + $paramhtml = ' ' . $parmhtml; + } + } + + if (strlen($paramhtml)) { + $paramhtml .= ' '; + } + + $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' . $paramtype . '</span>'; + + switch ($role) { + case 'c': + break; + default: + if ($paramname && $paramname{0} == '&') { + $paramname = '&$' . substr($paramname, 1); + } else { + $paramname = '$' . $paramname; + } + } + + $paramhtml .= ' <span class=\"parameter\">' . $paramname . '</span></span>'; - $params .= $paramhtml; - } + $params .= $paramhtml; + } - $html .= '(' . $params . $optclose . ")</div>"; - } + $html .= '(' . $params . $optclose . ")</div>"; + } - return $html . "</div>"; + return $html . "</div>"; } http://cvs.php.net/diff.php/livedocs/xml_classes.php?r1=1.2&r2=1.3&ty=u Index: livedocs/xml_classes.php diff -u livedocs/xml_classes.php:1.2 livedocs/xml_classes.php:1.3 --- livedocs/xml_classes.php:1.2 Sat Jan 17 06:34:07 2004 +++ livedocs/xml_classes.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,189 +18,189 @@ // | Two XML handling classes for the docbook to html transformation | // +----------------------------------------------------------------------+ // -// $Id: xml_classes.php,v 1.2 2004/01/17 11:34:07 nlopess Exp $ +// $Id: xml_classes.php,v 1.3 2004/02/16 17:54:59 derick Exp $ class Node { /* {{{ */ - var $tagname = ""; - var $attributes = array(); - var $children = array(); - var $parent = null; - var $index = 0; - var $content = ""; - var $nodeid = 0; - - function transform($map) - { - if (strlen($this->tagname) == 0) { - return htmlspecialchars($this->content, ENT_NOQUOTES); - } - - $tagname = 'div'; - $attributes = $this->attributes; - $attributes['class'] = $this->tagname; - - /* do we match any of the patterns in the map ? */ - foreach ($map as $mapent) { - if ($mapent[0][0] == $this->tagname) { - $n =& $this->parent; - $match = true; - for ($i = 1; $i < count($mapent[0]); $i++) { - if ($n->tagname != $mapent[0][$i]) { - $match = false; - break; - } - $n =& $n->parent; - } - if ($match) { - if (is_callable($mapent[1])) { - return call_user_func($mapent[1], $this); - } else { - $tagname = $mapent[1]; - } - } - } - } - - if (isset($this->attributes['id'])) { - $anchor = sprintf('<a name="%s"></a>', $this->attributes['id']); - } else { - $anchor = ''; - } - - if (strlen($tagname)) { - $xml = '<' . $tagname; - foreach ($attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - } else { - $xml = ''; - } - - $content = ""; - - if (count($this->children) == 0) { - - if (strlen($tagname) == 0) { - return ''; - } - - if (strlen($this->content)) { - $content = htmlspecialchars($this->content, ENT_NOQUOTES); - } - } else { - for ($i = 0; $i < count($this->children); $i++) { - $child = $this->children[$i]; - $content .= $child->transform($map); - } - } - - if (strlen($tagname)) { - $xml .= '>'; - } - - if ($tagname == 'th' && strlen($content) == 0) { - $content = ' '; - } - - $xml .= $anchor; - $xml .= $content; - if (strlen($tagname)) { - $xml .= '</' . $tagname . '>'; - } - - return $xml; - } - - function &select_node($id) - { - if (isset($this->attributes['id']) && $this->attributes['id'] == $id) { - return $node; - } - // look for children that match - for ($i = 0; $i < count($this->children); $i++) { - $x =& $this->select_node($this->children[$i], $id); - if (is_object($x)) { - return $x; - } - } - return null; - } - - function Node($tagname, $attributes) - { - static $nodeid = 0; - - $this->nodeid = $nodeid++; - $this->tagname = $tagname; - $this->attributes = $attributes; - } - - function set_parent(&$parent) - { - $this->parent =& $parent; - $this->index = count($parent->children); - $parent->children[$this->index] =& $this; - } - - function compress() - { - if (count($this->children) == 1 && $this->children[0]->tagname == '') { - $this->content = $this->children[0]->content; - $this->children = array(); - } - } - - function as_xml() - { - if (strlen($this->tagname) == 0) { - return htmlspecialchars($this->content, ENT_NOQUOTES); - } - - $xml = '<' . $this->tagname; - foreach ($this->attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - if (count($this->children) == 0) { - if (strlen($this->content) == 0) { - $xml .= '/>'; - } else { - $xml .= '>' . htmlspecialchars($this->content, ENT_NOQUOTES) . '</' . $this->tagname . '>'; - } - } else { - $xml .= '>'; - for ($i = 0; $i < count($this->children); $i++) { - $xml .= $this->children[$i]->as_xml(); - } - $xml .= '</' . $this->tagname . '>'; - } - return $xml; - } - - function add_child(&$child) - { - if (count($this->children) == 0 && strlen($this->content)) { - if (strlen(trim($this->content)) > 0) { - // promote content to an anonymous cdata node - $node = new Node("", array()); - $node->content = $this->content; - $node->set_parent($this); - } - $this->content = ""; - } - $child->set_parent($this); - } - - function add_cdata($data) - { - if (count($this->children) == 0) { - $this->content .= $data; - } else { - $node = new Node("", array()); - $node->content = $data; - $this->add_child($node); - } - } + var $tagname = ""; + var $attributes = array(); + var $children = array(); + var $parent = null; + var $index = 0; + var $content = ""; + var $nodeid = 0; + + function transform($map) + { + if (strlen($this->tagname) == 0) { + return htmlspecialchars($this->content, ENT_NOQUOTES); + } + + $tagname = 'div'; + $attributes = $this->attributes; + $attributes['class'] = $this->tagname; + + /* do we match any of the patterns in the map ? */ + foreach ($map as $mapent) { + if ($mapent[0][0] == $this->tagname) { + $n =& $this->parent; + $match = true; + for ($i = 1; $i < count($mapent[0]); $i++) { + if ($n->tagname != $mapent[0][$i]) { + $match = false; + break; + } + $n =& $n->parent; + } + if ($match) { + if (is_callable($mapent[1])) { + return call_user_func($mapent[1], $this); + } else { + $tagname = $mapent[1]; + } + } + } + } + + if (isset($this->attributes['id'])) { + $anchor = sprintf('<a name="%s"></a>', $this->attributes['id']); + } else { + $anchor = ''; + } + + if (strlen($tagname)) { + $xml = '<' . $tagname; + foreach ($attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + } else { + $xml = ''; + } + + $content = ""; + + if (count($this->children) == 0) { + + if (strlen($tagname) == 0) { + return ''; + } + + if (strlen($this->content)) { + $content = htmlspecialchars($this->content, ENT_NOQUOTES); + } + } else { + for ($i = 0; $i < count($this->children); $i++) { + $child = $this->children[$i]; + $content .= $child->transform($map); + } + } + + if (strlen($tagname)) { + $xml .= '>'; + } + + if ($tagname == 'th' && strlen($content) == 0) { + $content = ' '; + } + + $xml .= $anchor; + $xml .= $content; + if (strlen($tagname)) { + $xml .= '</' . $tagname . '>'; + } + + return $xml; + } + + function &select_node($id) + { + if (isset($this->attributes['id']) && $this->attributes['id'] == $id) { + return $node; + } + // look for children that match + for ($i = 0; $i < count($this->children); $i++) { + $x =& $this->select_node($this->children[$i], $id); + if (is_object($x)) { + return $x; + } + } + return null; + } + + function Node($tagname, $attributes) + { + static $nodeid = 0; + + $this->nodeid = $nodeid++; + $this->tagname = $tagname; + $this->attributes = $attributes; + } + + function set_parent(&$parent) + { + $this->parent =& $parent; + $this->index = count($parent->children); + $parent->children[$this->index] =& $this; + } + + function compress() + { + if (count($this->children) == 1 && $this->children[0]->tagname == '') { + $this->content = $this->children[0]->content; + $this->children = array(); + } + } + + function as_xml() + { + if (strlen($this->tagname) == 0) { + return htmlspecialchars($this->content, ENT_NOQUOTES); + } + + $xml = '<' . $this->tagname; + foreach ($this->attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + if (count($this->children) == 0) { + if (strlen($this->content) == 0) { + $xml .= '/>'; + } else { + $xml .= '>' . htmlspecialchars($this->content, ENT_NOQUOTES) . '</' . $this->tagname . '>'; + } + } else { + $xml .= '>'; + for ($i = 0; $i < count($this->children); $i++) { + $xml .= $this->children[$i]->as_xml(); + } + $xml .= '</' . $this->tagname . '>'; + } + return $xml; + } + + function add_child(&$child) + { + if (count($this->children) == 0 && strlen($this->content)) { + if (strlen(trim($this->content)) > 0) { + // promote content to an anonymous cdata node + $node = new Node("", array()); + $node->content = $this->content; + $node->set_parent($this); + } + $this->content = ""; + } + $child->set_parent($this); + } + + function add_cdata($data) + { + if (count($this->children) == 0) { + $this->content .= $data; + } else { + $node = new Node("", array()); + $node->content = $data; + $this->add_child($node); + } + } } /* }}} */ @@ -209,126 +209,126 @@ class DocBookToHTML { /* {{{ */ - var $html = ""; - var $top = null; - var $current = null; - - function DocBookToHTML($xml, $id = null) - { - if (strlen($xml) == 0) { - return; - } - - $p = xml_parser_create(); - xml_set_object($p, $this); - xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($p, 'start_elem', 'end_elem'); - xml_set_character_data_handler($p, 'cdata'); - - if (!xml_parse($p, $xml, true)) { - printf("XML: %d:%d %s\n", - xml_get_current_line_number($p), - xml_get_current_column_number($p), - xml_error_string(xml_get_error_code($p)) - ); - $lines = explode("\n", $xml); - $l = xml_get_current_line_number($p); - echo "\nLine: $l is \n" . htmlentities($lines[$l-1]) . "\n"; - echo htmlentities($xml); - } - xml_parser_free($p); - - if ($id !== null) { - $newtop = $this->top->select_node($id); - if (is_object($newtop)) { - $this->top = $newtop; - $this->top->parent = null; - } - } - } - - /* apply a transformation map to content */ - function transform($map) - { - /* pre-parse the map */ - - if (!is_object($this->top)) { - return "<div class=\"warning\">XML document contained no data</div>"; - } - - $pmap = array(); - foreach ($map as $pat => $rep) { - $h = array_reverse(explode('/', $pat)); - $pmap[] = array($h, $rep); - } - return $this->top->transform($pmap); - } - - /* returns structure as XML */ - function as_xml() - { - return $this->_as_xml($this->top); - } - - function _as_xml(&$node) - { - if (strlen($node->tagname) == 0) { - return htmlspecialchars($node->content, ENT_NOQUOTES); - } - - $xml = '<' . $node->tagname; - foreach ($node->attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - if (count($node->children) == 0) { - if (strlen($node->content) == 0) { - $xml .= '/>'; - } else { - $xml .= '>' . htmlspecialchars($node->content, ENT_NOQUOTES) . '</' . $node->tagname . '>'; - } - } else { - $xml .= '>'; - for ($i = 0; $i < count($node->children); $i++) { - $xml .= $this->_as_xml($node->children[$i]); - } - $xml .= '</' . $node->tagname . '>'; - } - return $xml . "<!-- $node->nodeid -->"; - } - - function start_elem($parser, $tagname, $attributes) - { - /* create a new node as a child of the current node */ - $node = new Node($tagname, $attributes); - - if ($this->top === null) { - /* set the top node */ - $this->top =& $node; - $this->current =& $node; - } else { - /* child of current */ - $this->current->add_child($node); - $this->current =& $node; - } - } - - function end_elem($parser, $tagname) - { - /* pop up to parent of the current node */ - if ($this->current === null) { - return; - } - /* optimize the node; if it only contains a single cdata (anonymous) node, - * compress that node into the content */ - $this->current->compress(); - - $this->current = &$this->current->parent; - } - - function cdata($parser, $data) - { - $this->current->add_cdata($data); - } + var $html = ""; + var $top = null; + var $current = null; + + function DocBookToHTML($xml, $id = null) + { + if (strlen($xml) == 0) { + return; + } + + $p = xml_parser_create(); + xml_set_object($p, $this); + xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); + xml_set_element_handler($p, 'start_elem', 'end_elem'); + xml_set_character_data_handler($p, 'cdata'); + + if (!xml_parse($p, $xml, true)) { + printf("XML: %d:%d %s\n", + xml_get_current_line_number($p), + xml_get_current_column_number($p), + xml_error_string(xml_get_error_code($p)) + ); + $lines = explode("\n", $xml); + $l = xml_get_current_line_number($p); + echo "\nLine: $l is \n" . htmlentities($lines[$l-1]) . "\n"; + echo htmlentities($xml); + } + xml_parser_free($p); + + if ($id !== null) { + $newtop = $this->top->select_node($id); + if (is_object($newtop)) { + $this->top = $newtop; + $this->top->parent = null; + } + } + } + + /* apply a transformation map to content */ + function transform($map) + { + /* pre-parse the map */ + + if (!is_object($this->top)) { + return "<div class=\"warning\">XML document contained no data</div>"; + } + + $pmap = array(); + foreach ($map as $pat => $rep) { + $h = array_reverse(explode('/', $pat)); + $pmap[] = array($h, $rep); + } + return $this->top->transform($pmap); + } + + /* returns structure as XML */ + function as_xml() + { + return $this->_as_xml($this->top); + } + + function _as_xml(&$node) + { + if (strlen($node->tagname) == 0) { + return htmlspecialchars($node->content, ENT_NOQUOTES); + } + + $xml = '<' . $node->tagname; + foreach ($node->attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + if (count($node->children) == 0) { + if (strlen($node->content) == 0) { + $xml .= '/>'; + } else { + $xml .= '>' . htmlspecialchars($node->content, ENT_NOQUOTES) . '</' . $node->tagname . '>'; + } + } else { + $xml .= '>'; + for ($i = 0; $i < count($node->children); $i++) { + $xml .= $this->_as_xml($node->children[$i]); + } + $xml .= '</' . $node->tagname . '>'; + } + return $xml . "<!-- $node->nodeid -->"; + } + + function start_elem($parser, $tagname, $attributes) + { + /* create a new node as a child of the current node */ + $node = new Node($tagname, $attributes); + + if ($this->top === null) { + /* set the top node */ + $this->top =& $node; + $this->current =& $node; + } else { + /* child of current */ + $this->current->add_child($node); + $this->current =& $node; + } + } + + function end_elem($parser, $tagname) + { + /* pop up to parent of the current node */ + if ($this->current === null) { + return; + } + /* optimize the node; if it only contains a single cdata (anonymous) node, + * compress that node into the content */ + $this->current->compress(); + + $this->current = &$this->current->parent; + } + + function cdata($parser, $data) + { + $this->current->add_cdata($data); + } } /* }}} */
http://cvs.php.net/diff.php/livedocs/common.php?r1=1.6&r2=1.7&ty=u Index: livedocs/common.php diff -u livedocs/common.php:1.6 livedocs/common.php:1.7 --- livedocs/common.php:1.6 Fri Jan 30 00:49:15 2004 +++ livedocs/common.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Common PHP header, with some basic settings | // +----------------------------------------------------------------------+ // -// $Id: common.php,v 1.6 2004/01/30 05:49:15 momo Exp $ +// $Id: common.php,v 1.7 2004/02/16 17:54:59 derick Exp $ set_magic_quotes_runtime(0); error_reporting(E_ALL); ini_set('display_errors', '1'); @@ -38,14 +38,14 @@ $css_url = WEBBASE . 'themes/' . THEME_NAME . '/livedoc.css'; if (!isset($_GET['l'])) { - // if we are dealing with path info URL check for language - if (!empty($_SERVER['REDIRECT_URL']) && preg_match('|([A-Za-z_]{2,5})/(.*)|', substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)), $m)) { - $lang = $m[1]; - } else { - $lang = FALLBACK_LANG; - } + // if we are dealing with path info URL check for language + if (!empty($_SERVER['REDIRECT_URL']) && preg_match('|([A-Za-z_]{2,5})/(.*)|', substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)), $m)) { + $lang = $m[1]; + } else { + $lang = FALLBACK_LANG; + } } else { - $lang = preg_replace(LANGREG, '', $_GET['l']); + $lang = preg_replace(LANGREG, '', $_GET['l']); } define('BASE', PHPDOC . "/$lang/"); @@ -55,11 +55,11 @@ $fb_idx = @sqlite_open(FALLBACK_INDEX); if ($lang == FALLBACK_LANG || !($idx = @sqlite_open(INDEX))) { - $idx = $fb_idx; - $lang = FALLBACK_LANG; + $idx = $fb_idx; + $lang = FALLBACK_LANG; } if (!$idx) { - die ("No index found"); + die ("No index found"); } ?> http://cvs.php.net/diff.php/livedocs/error.php?r1=1.6&r2=1.7&ty=u Index: livedocs/error.php diff -u livedocs/error.php:1.6 livedocs/error.php:1.7 --- livedocs/error.php:1.6 Thu Feb 5 15:35:12 2004 +++ livedocs/error.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,84 +18,84 @@ // | Handles the 404 error and try to redirect to the good place. | // +----------------------------------------------------------------------+ // -// $Id: error.php,v 1.6 2004/02/05 20:35:12 wez Exp $ +// $Id: error.php,v 1.7 2004/02/16 17:54:59 derick Exp $ /* handle IIS style 404 handler */ if (strncmp($_SERVER['SERVER_SOFTWARE'], "Microsoft", 9) == 0 && - isset($_SERVER['QUERY_STRING']) && - strncmp($_SERVER['QUERY_STRING'], "404;", 4) == 0) { + isset($_SERVER['QUERY_STRING']) && + strncmp($_SERVER['QUERY_STRING'], "404;", 4) == 0) { - $rurl = parse_url(substr($_SERVER['QUERY_STRING'], 4)); + $rurl = parse_url(substr($_SERVER['QUERY_STRING'], 4)); - $_SERVER['REDIRECT_URL'] = $rurl['path']; - if (isset($rurl['query'])) { - $_SERVER['REDIRECT_URL'] .= '?' . $rurl['query']; - } + $_SERVER['REDIRECT_URL'] = $rurl['path']; + if (isset($rurl['query'])) { + $_SERVER['REDIRECT_URL'] .= '?' . $rurl['query']; + } } if (!empty($_SERVER['REDIRECT_URL'])) { - // This is the requested page that caused the error - $current_page = substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)); - if (strncmp(substr($current_page, -5), ".html", 5)) { - if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { - $current_page = $m[2]; - } - - $lookup_name = preg_replace('!.*\.!', '', strtolower($current_page)); - $lookup_name = preg_replace('![^a-z0-9]!', '', $lookup_name); - - $db_m = sqlite_array_query($idx, "SELECT path, prio FROM searchi WHERE (skey='" . sqlite_escape_string($lookup_name) . "' OR skey='".sqlite_escape_string(metaphone($lookup_name))."') ORDER BY prio LIMIT 1", SQLITE_NUM); - if ($db_m) { - if ($db_m[0][1] < 5 || (sqlite_fetch_string(sqlite_unbuffered_query($idx, "SELECT count(*) FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5")) == 1)) { - $current_page = $lang . '/' . $db_m[0][0] . '.html'; - if (@file_exists(OUTPUTDIR . '/' . $current_page)) { - header('Location: ' . WEBBASE . $current_page . '?#' . $db_m[0][0]); - exit; - } - } else { - list($title, $filename, $fileid, $dirid) = do_nav($idx, $fb_idx, $lang, 'bookinfo', $nav, $children); - $date = gmdate('Y-m-d H:i:s') . ' GMT'; - if (empty($file_revision)) { - $file_revision = 'unknown revision'; - } - $db_m = sqlite_array_query($idx, "SELECT path FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5 LIMIT 10", SQLITE_NUM); - $rs_size = count($db_m); - $fpath = WEBBASE . $lang . '/'; + // This is the requested page that caused the error + $current_page = substr($_SERVER['REDIRECT_URL'], strlen(WEBBASE)); + if (strncmp(substr($current_page, -5), ".html", 5)) { + if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { + $current_page = $m[2]; + } + + $lookup_name = preg_replace('!.*\.!', '', strtolower($current_page)); + $lookup_name = preg_replace('![^a-z0-9]!', '', $lookup_name); + + $db_m = sqlite_array_query($idx, "SELECT path, prio FROM searchi WHERE (skey='" . sqlite_escape_string($lookup_name) . "' OR skey='".sqlite_escape_string(metaphone($lookup_name))."') ORDER BY prio LIMIT 1", SQLITE_NUM); + if ($db_m) { + if ($db_m[0][1] < 5 || (sqlite_fetch_string(sqlite_unbuffered_query($idx, "SELECT count(*) FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5")) == 1)) { + $current_page = $lang . '/' . $db_m[0][0] . '.html'; + if (@file_exists(OUTPUTDIR . '/' . $current_page)) { + header('Location: ' . WEBBASE . $current_page . '?#' . $db_m[0][0]); + exit; + } + } else { + list($title, $filename, $fileid, $dirid) = do_nav($idx, $fb_idx, $lang, 'bookinfo', $nav, $children); + $date = gmdate('Y-m-d H:i:s') . ' GMT'; + if (empty($file_revision)) { + $file_revision = 'unknown revision'; + } + $db_m = sqlite_array_query($idx, "SELECT path FROM searchi WHERE skey='" . sqlite_escape_string($lookup_name) . "' AND prio=5 LIMIT 10", SQLITE_NUM); + $rs_size = count($db_m); + $fpath = WEBBASE . $lang . '/'; - echo error_page_header(); + echo error_page_header(); - foreach($db_m as $v) { - if (($p = strrpos($v[0], '.')) !== FALSE) { - $f_name = substr($v[0], ($p + 1)); - } else { - $f_name = $v[0]; - } - $f_name = str_replace('-', '_', $f_name); - echo <<<FUNC_MATCH + foreach($db_m as $v) { + if (($p = strrpos($v[0], '.')) !== FALSE) { + $f_name = substr($v[0], ($p + 1)); + } else { + $f_name = $v[0]; + } + $f_name = str_replace('-', '_', $f_name); + echo <<< FUNC_MATCH <a class="function" href="{$fpath}{$v[0]}.html#{$v[0]}">{$f_name}()</a><br /> FUNC_MATCH; - } - - echo error_page_footer(); - exit; - } - } - } - - $current_page = preg_replace('|^/|', '', $current_page); - $current_page = preg_replace('|\.html$|', '', $current_page); - if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { - $current_page = preg_replace(IDREG, '', $m[2]); - $save_url = TRUE; - } else if (preg_match('|(.*)|', $current_page, $m)) { - $current_page = preg_replace(IDREG, '', $m[1]); - $save_url = TRUE; - } else { - $current_page = 'manual'; - } + } + + echo error_page_footer(); + exit; + } + } + } + + $current_page = preg_replace('|^/|', '', $current_page); + $current_page = preg_replace('|\.html$|', '', $current_page); + if (preg_match('|([A-Za-z_]{2,5})/(.*)|', $current_page, $m)) { + $current_page = preg_replace(IDREG, '', $m[2]); + $save_url = TRUE; + } else if (preg_match('|(.*)|', $current_page, $m)) { + $current_page = preg_replace(IDREG, '', $m[1]); + $save_url = TRUE; + } else { + $current_page = 'manual'; + } } if (empty($current_page)) { - $current_page = 'manual'; + $current_page = 'manual'; } http://cvs.php.net/diff.php/livedocs/livedoc-index.php?r1=1.7&r2=1.8&ty=u Index: livedocs/livedoc-index.php diff -u livedocs/livedoc-index.php:1.7 livedocs/livedoc-index.php:1.8 --- livedocs/livedoc-index.php:1.7 Mon Feb 2 15:33:28 2004 +++ livedocs/livedoc-index.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,56 +18,56 @@ // | Livedocs index | // +----------------------------------------------------------------------+ // -// $Id: livedoc-index.php,v 1.7 2004/02/02 20:33:28 momo Exp $ +// $Id: livedoc-index.php,v 1.8 2004/02/16 17:54:59 derick Exp $ echo index_page_header(); $alphabet = range('a', 'z'); foreach ($alphabet as $char) { - echo "<a href='" . WEBBASE . "index.php?l=$lang&s=INDEX&i=$char'>$char</a> "; + echo "<a href='" . WEBBASE . "index.php?l=$lang&s=INDEX&i=$char'>$char</a> "; } echo "</div><hr />\n"; if (!isset($_GET['i'])) { - /* Show alphabet */ + /* Show alphabet */ } else { - /* Sanitize index letter */ - if (strlen($_GET['i']) < 1) { - $idxl = 'a'; - } else { - $idxl = substr($_GET['i'], 0, 1); - } - - /* Create function call back for STARTS_WITH and TO_LOWER */ - sqlite_create_function($idx, 'STARTS_WITH', 'sqlite_starts_with'); - sqlite_create_function($idx, 'TO_LOWER', 'sqlite_to_lower'); - - /* Select all titles starting with $idxl */ - $q = sqlite_query($idx, "SELECT title, id FROM idents WHERE STARTS_WITH(title, '$idxl') ORDER BY TO_LOWER(title)"); - if ($q) { - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $id) = $r; - $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id"; - echo "<span class='index'><a href='" . WEBBASE . "$url'>$title</a></span><br />\n"; - } - } + /* Sanitize index letter */ + if (strlen($_GET['i']) < 1) { + $idxl = 'a'; + } else { + $idxl = substr($_GET['i'], 0, 1); + } + + /* Create function call back for STARTS_WITH and TO_LOWER */ + sqlite_create_function($idx, 'STARTS_WITH', 'sqlite_starts_with'); + sqlite_create_function($idx, 'TO_LOWER', 'sqlite_to_lower'); + + /* Select all titles starting with $idxl */ + $q = sqlite_query($idx, "SELECT title, id FROM idents WHERE STARTS_WITH(title, '$idxl') ORDER BY TO_LOWER(title)"); + if ($q) { + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $id) = $r; + $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id"; + echo "<span class='index'><a href='" . WEBBASE . "$url'>$title</a></span><br />\n"; + } + } } $date = date("d-m-Y H:i:s"); echo index_page_footer(); function sqlite_starts_with($title, $char) { - $title = strtolower($title); - $char = strtolower($char); - if (!strlen($title) || !strlen($char)) { - return FALSE; - } - return ($title{0} == $char{0}); + $title = strtolower($title); + $char = strtolower($char); + if (!strlen($title) || !strlen($char)) { + return FALSE; + } + return ($title{0} == $char{0}); } function sqlite_to_lower($text) { - return strtolower($text); + return strtolower($text); } ?> http://cvs.php.net/diff.php/livedocs/livedoc.php?r1=1.79&r2=1.80&ty=u Index: livedocs/livedoc.php diff -u livedocs/livedoc.php:1.79 livedocs/livedoc.php:1.80 --- livedocs/livedoc.php:1.79 Fri Jan 23 09:58:38 2004 +++ livedocs/livedoc.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Generate an HTML version of a phpdoc/docbook page on the fly | // +----------------------------------------------------------------------+ // -// $Id: livedoc.php,v 1.79 2004/01/23 14:58:38 didou Exp $ +// $Id: livedoc.php,v 1.80 2004/02/16 17:54:59 derick Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include LIVEDOC_SOURCE . '/common.php'; @@ -27,13 +27,13 @@ include LIVEDOC_SOURCE . '/themes/' . THEME_NAME . '/html_format.php'; if (!isset($_GET['q'])) { - // Handles the 404. If a matching page is found, we redirect to it. - // Else, we display a page with the closest matches and we stop the script. - // If something goes wrong with the database, $current_page will default - // to some value. - include LIVEDOC_SOURCE . '/error.php'; + // Handles the 404. If a matching page is found, we redirect to it. + // Else, we display a page with the closest matches and we stop the script. + // If something goes wrong with the database, $current_page will default + // to some value. +include LIVEDOC_SOURCE . '/error.php'; } else { - $current_page = preg_replace(IDREG, '', $_GET['q']); + $current_page = preg_replace(IDREG, '', $_GET['q']); } /***************************************************************************** @@ -41,21 +41,21 @@ * Please keep the arrays sorted by keys */ $aliases = array( - 'api' => 'streams', - 'appendixes' => 'handle_appendixes', - 'faq' => 'faq.general', - 'features' => 'features.http-auth', - 'funcref' => 'handle_funcref', - 'getting-started' => 'introduction', - 'installation' => 'install.general', - 'langref' => 'language.basic-syntax', - 'manual' => 'handle_contents', - 'security' => 'security.index' + 'api' => 'streams', + 'appendixes' => 'handle_appendixes', + 'faq' => 'faq.general', + 'features' => 'features.http-auth', + 'funcref' => 'handle_funcref', + 'getting-started' => 'introduction', + 'installation' => 'install.general', + 'langref' => 'language.basic-syntax', + 'manual' => 'handle_contents', + 'security' => 'security.index' ); if (isset($_GET['s'])) { - include LIVEDOC_SOURCE . '/livedoc-index.php'; - exit; + include LIVEDOC_SOURCE . '/livedoc-index.php'; + exit; } /***************************************************************************** @@ -63,11 +63,11 @@ */ $special_content = false; if (isset($aliases[$current_page])) { - if (is_callable($aliases[$current_page])) { - $special_content = true; - } else { - $current_page = $aliases[$current_page]; - } + if (is_callable($aliases[$current_page])) { + $special_content = true; + } else { + $current_page = $aliases[$current_page]; + } } @@ -78,33 +78,33 @@ if (!$special_content) { - if ($filename == null) { - // no matching node was found - handle_missing_index(); - } else { - // load the content - $page = load_xml_doc(BASE . $filename, false, FALLBACK_BASE . $filename); - } + if ($filename == null) { + // no matching node was found + handle_missing_index(); + } else { + // load the content + $page = load_xml_doc(BASE . $filename, false, FALLBACK_BASE . $filename); + } } /***************************************************************************** * Grabbing the output for normal or special pages */ if ($save_url) { - ob_start(); + ob_start(); } echo manual_page_header(); if ($special_content) { - echo call_user_func($aliases[$current_page]); + echo call_user_func($aliases[$current_page]); } else { - echo $page->transform($map, $current_page); + echo $page->transform($map, $current_page); } $date = gmdate('Y-m-d H:i:s') . ' GMT'; if (empty($file_revision)) { - $file_revision = 'unknown revision'; + $file_revision = 'unknown revision'; } echo manual_page_footer(); @@ -113,12 +113,12 @@ * Saving the generated page to the cache */ if ($save_url) { - $contents = ob_get_contents(); - ob_clean(); - $f = fopen($lang . "/" . $current_page . ".html", 'w'); - fwrite($f, $contents); - fclose($f); - echo $contents; + $contents = ob_get_contents(); + ob_clean(); + $f = fopen($lang . "/" . $current_page . ".html", 'w'); + fwrite($f, $contents); + fclose($f); + echo $contents; } return; @@ -129,158 +129,158 @@ function do_nav($idx, $fb_idx, $lang, $current_page, &$nav, &$children) { - $nav = "<table class='nav' border='0' cellpadding='0' cellspacing='0' width='150'>"; + $nav = "<table class='nav' border='0' cellpadding='0' cellspacing='0' width='150'>"; - /* Get the fileinfo for the reference */ - $q = sqlite_query($idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); + /* Get the fileinfo for the reference */ + $q = sqlite_query($idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); - if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $filename, $fileid, $dirid) = $tr; - } else { - $q = sqlite_query($fb_idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); - - if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { - list($title, $filename, $fileid, $dirid) = $tr; - } - } - - /* Get parent ID and child IDs */ - /* - first we get the first three parts of the path */ - $q = sqlite_query($idx, " - SELECT path - FROM toc - WHERE docbook_id = '$current_page' - "); - $r = sqlite_fetch_array($q, SQLITE_NUM); - if ($r[0]) { - $parent_ids = explode(",", $r[0]); - foreach($parent_ids as $id) { - $path[] = $id; - } - } else { - $path = array('manual'); - } - - foreach ($path as $item) { - $last_item = $item; - $nav .= do_nav_line($item, 'up', $current_page, $lang, $dummy); - } - - /* With $last_item we're going to show all brothers */ - $q = sqlite_query($idx, " - SELECT docbook_id - FROM toc - WHERE parent_docbook_id = '$last_item' - ORDER BY id - "); - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $nav .= do_nav_line($r[0], 'down', $current_page, $lang, $dummy); - } - - $children = array(); - /* And finally all children, but only if $current_page != $last_item - * because showing the same thing twice makes no sense */ - $q = sqlite_query($idx, " - SELECT docbook_id - FROM toc - WHERE parent_docbook_id = '$current_page' - AND parent_docbook_id <> 'manual' - ORDER BY id - "); - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $nav .= do_nav_line($r[0], 'downdown', $current_page, $lang, $title); - $children[$r[0]] = $title; - } + if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $filename, $fileid, $dirid) = $tr; + } else { + $q = sqlite_query($fb_idx, "SELECT title, filename, idents.fileid, files.dirid from idents, files where id='$current_page' and idents.fileid=files.fileid"); + + if ($q && $tr = sqlite_fetch_array($q, SQLITE_NUM)) { + list($title, $filename, $fileid, $dirid) = $tr; + } + } + + /* Get parent ID and child IDs */ + /* - first we get the first three parts of the path */ + $q = sqlite_query($idx, " + SELECT path + FROM toc + WHERE docbook_id = '$current_page' + "); + $r = sqlite_fetch_array($q, SQLITE_NUM); + if ($r[0]) { + $parent_ids = explode(",", $r[0]); + foreach($parent_ids as $id) { + $path[] = $id; + } + } else { + $path = array('manual'); + } + + foreach ($path as $item) { + $last_item = $item; + $nav .= do_nav_line($item, 'up', $current_page, $lang, $dummy); + } + + /* With $last_item we're going to show all brothers */ + $q = sqlite_query($idx, " + SELECT docbook_id + FROM toc + WHERE parent_docbook_id = '$last_item' + ORDER BY id + "); + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $nav .= do_nav_line($r[0], 'down', $current_page, $lang, $dummy); + } + + $children = array(); + /* And finally all children, but only if $current_page != $last_item + * because showing the same thing twice makes no sense */ + $q = sqlite_query($idx, " + SELECT docbook_id + FROM toc + WHERE parent_docbook_id = '$current_page' + AND parent_docbook_id <> 'manual' + ORDER BY id + "); + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $nav .= do_nav_line($r[0], 'downdown', $current_page, $lang, $title); + $children[$r[0]] = $title; + } - $nav .= "</table>\n"; - return $tr; + $nav .= "</table>\n"; + return $tr; } function generate_url_for_id($lang, $ref) { - static $cache = array(); + static $cache = array(); - if (isset($cache[$lang][$ref])) { - return $cache[$lang][$ref]; - } - - /* first determine the file in which the node can be found */ - $fileid = null; - $firstid = $ref; - - $saferef = sqlite_escape_string($ref); - - $q = sqlite_query($GLOBALS['idx'], "SELECT fileid from idents where id='$saferef'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $fileid = $r[0]; - $idx = $GLOBALS['idx']; - } elseif (isset($GLOBALS['fb_idx'])) { - $q = sqlite_query($GLOBALS['fb_idx'], "SELECT fileid from idents where id='$saferef'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $fileid = $r[0]; - $idx = $GLOBALS['fb_idx']; - } - } - - if ($fileid !== null) { - /* determine the first node within that file */ - $q = sqlite_query($idx, "SELECT id from idents where fileid='$fileid' LIMIT 1"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $firstid = $r[0]; - } - } - - if ($firstid != $ref) { - $hash = "#$ref"; - } else { - $hash = ""; - } - - if ($firstid == 'manual') { - $firstid = $ref; - $hash = ''; - } - - if (FORCE_DYNAMIC) { - $url = "{$_SERVER['PHP_SELF']}?l=$lang&q=$firstid$hash"; - } else { - $url = WEBBASE . "$lang/$firstid.html$hash"; - } + if (isset($cache[$lang][$ref])) { + return $cache[$lang][$ref]; + } + + /* first determine the file in which the node can be found */ + $fileid = null; + $firstid = $ref; + + $saferef = sqlite_escape_string($ref); + + $q = sqlite_query($GLOBALS['idx'], "SELECT fileid from idents where id='$saferef'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $fileid = $r[0]; + $idx = $GLOBALS['idx']; + } elseif (isset($GLOBALS['fb_idx'])) { + $q = sqlite_query($GLOBALS['fb_idx'], "SELECT fileid from idents where id='$saferef'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $fileid = $r[0]; + $idx = $GLOBALS['fb_idx']; + } + } + + if ($fileid !== null) { + /* determine the first node within that file */ + $q = sqlite_query($idx, "SELECT id from idents where fileid='$fileid' LIMIT 1"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $firstid = $r[0]; + } + } + + if ($firstid != $ref) { + $hash = "#$ref"; + } else { + $hash = ""; + } + + if ($firstid == 'manual') { + $firstid = $ref; + $hash = ''; + } + + if (FORCE_DYNAMIC) { + $url = "{$_SERVER['PHP_SELF']}?l=$lang&q=$firstid$hash"; + } else { + $url = WEBBASE . "$lang/$firstid.html$hash"; + } - $cache[$lang][$ref] = $url; - return $url; + $cache[$lang][$ref] = $url; + return $url; } function do_nav_line($item, $class, $current_page, $lang, &$fulltitle) { - global $current_page_title; + global $current_page_title; - $nolink = FALSE; + $nolink = FALSE; - $title = lookup_title($item); - $fulltitle = $title; - if (strlen($title) > 25) { - $ftitle = " title='$title'"; - $title = substr($title, 0, 22). '...'; - } else { - $ftitle = ""; - } - if (empty($title)) { - $title = $item. ' [?]'; - $nolink = TRUE; - } - if ($item == $current_page) { - $current_page_title = $title; - $title = "<b>$title</b>"; - } - $title = str_replace(' ', ' ', $title); - - if ($nolink) { - return "<tr><td class='$class'>$title</td></tr>\n"; - } else { - $url = generate_url_for_id($lang, $item); - return "<tr><td class='$class'><a $ftitle class='$class' href='$url'>$title</a></td></tr>\n"; - } + $title = lookup_title($item); + $fulltitle = $title; + if (strlen($title) > 25) { + $ftitle = " title='$title'"; + $title = substr($title, 0, 22). '...'; + } else { + $ftitle = ""; + } + if (empty($title)) { + $title = $item. ' [?]'; + $nolink = TRUE; + } + if ($item == $current_page) { + $current_page_title = $title; + $title = "<b>$title</b>"; + } + $title = str_replace(' ', ' ', $title); + + if ($nolink) { + return "<tr><td class='$class'>$title</td></tr>\n"; + } else { + $url = generate_url_for_id($lang, $item); + return "<tr><td class='$class'><a $ftitle class='$class' href='$url'>$title</a></td></tr>\n"; + } } @@ -289,227 +289,227 @@ */ function &load_xml_doc($filename, $included = false, $fallback_filename = '') { - global $file_revision, $idx; + global $file_revision, $idx; - $replace = array(); - $search = array('æ', '©', 'é', 'è', 'à', 'ï', 'ö', 'ä', 'Ä', - 'ô', 'ê', 'û', 'î', 'â', 'ë', 'ç', 'ù'); - foreach ($search as $item) { - $replace[] = html_entity_decode($item); - } - - $sanity = 0; - $data = @file_get_contents($filename); - if (strlen($data) == 0 && strlen($fallback_filename)) { - $data = @file_get_contents($fallback_filename); - - if (strlen($data) == 0) { - $data = "<warning>permissions problem for $filename?</warning>"; - } - } - - /* get file revision */ - if (empty($file_revision) && preg_match('/\$' . 'Revision: [^$]+ \$/', $data, $matches)) { - $file_revision .= $matches[0]; - } - - /* strip comments */ - $data = preg_replace('@<!--\s+.*\s-->@Usm', '', $data); - /* list the entities that are required */ - $entities = array(); - do { - $ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches); - if ($ent_count == 0) { - break; - } - - /* now collect their values */ - $entities_to_find = array_unique($matches[1]); - $ents = implode("','", $entities_to_find); - $q = sqlite_query($idx, "SELECT entid, value from ents where entid in ('" . $ents . "')"); - if (!$q) { - break; - } - - while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { - $entities['&' . $r[0] . ';'] = $r[1]; - } - - /* substitute */ - $data = strtr($data, $entities); - - } while ($sanity++ < 5); - - /* catch any undefined entities */ - if ($included) { - if (basename($filename) == 'functions.xml') { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_function_link("\\1.\\2");', $data); - } else { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_xref("\\1.\\2");', $data); - } - if (!$data || $data{1} != '?') { - $data = '<div>' . $data . '</div>'; - } else { - $data = preg_replace('@(<\\?xml.*\\?>)@U', '\\1<div>', $data) . '</div>'; - } - } else { - $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sm', '<phpdoc_include ref="\\1.\\2"/>', $data); - } + $replace = array(); + $search = array('æ', '©', 'é', 'è', 'à', 'ï', 'ö', 'ä', 'Ä', + 'ô', 'ê', 'û', 'î', 'â', 'ë', 'ç', 'ù'); + foreach ($search as $item) { + $replace[] = html_entity_decode($item); + } + + $sanity = 0; + $data = @file_get_contents($filename); + if (strlen($data) == 0 && strlen($fallback_filename)) { + $data = @file_get_contents($fallback_filename); + + if (strlen($data) == 0) { + $data = "<warning>permissions problem for $filename?</warning>"; + } + } + + /* get file revision */ + if (empty($file_revision) && preg_match('/\$' . 'Revision: [^$]+ \$/', $data, $matches)) { + $file_revision .= $matches[0]; + } + + /* strip comments */ + $data = preg_replace('@<!--\s+.*\s-->@Usm', '', $data); + /* list the entities that are required */ + $entities = array(); + do { + $ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches); + if ($ent_count == 0) { + break; + } + + /* now collect their values */ + $entities_to_find = array_unique($matches[1]); + $ents = implode("','", $entities_to_find); + $q = sqlite_query($idx, "SELECT entid, value from ents where entid in ('" . $ents . "')"); + if (!$q) { + break; + } + + while ($r = sqlite_fetch_array($q, SQLITE_NUM)) { + $entities['&' . $r[0] . ';'] = $r[1]; + } + + /* substitute */ + $data = strtr($data, $entities); + + } while ($sanity++ < 5); + + /* catch any undefined entities */ + if ($included) { + if (basename($filename) == 'functions.xml') { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_function_link("\\1.\\2");', $data); + } else { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sme', 'make_xref("\\1.\\2");', $data); + } + if (!$data || $data{1} != '?') { + $data = '<div>' . $data . '</div>'; + } else { + $data = preg_replace('@(<\\?xml.*\\?>)@U', '\\1<div>', $data) . '</div>'; + } + } else { + $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sm', '<phpdoc_include ref="\\1.\\2"/>', $data); + } - $data = str_replace($search, $replace, $data); + $data = str_replace($search, $replace, $data); - $page = new DocBookToHTML($data); + $page = new DocBookToHTML($data); - return $page; + return $page; } function lookup_title($nodeid) { - static $ids = array(); + static $ids = array(); - /* Define your own title mappings here: */ - static $special = array ('indexes' => 'FunctionIndex'); + /* Define your own title mappings here: */ + static $special = array ('indexes' => 'FunctionIndex'); - /* we're going to do some tricky stuff here for languages, - * by using entities as much as possible */ - if (isset($special[$nodeid])) { - /* Check for the entity value */ - $q = sqlite_query($GLOBALS['idx'], "SELECT * FROM ents WHERE entid = '$special[$nodeid]'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - return $r[1]; - } else { /* It's not an entity, let's just return it then */ - return $special[$nodeid]; - } - } - - /* See if the title lookup is in the cache already */ - if (isset($ids[$nodeid])) { - return $ids[$nodeid]; - } - - /* It's not, so we try to resolve it from the DB */ - $safeid = sqlite_escape_string($nodeid); - $q = sqlite_query($GLOBALS['idx'], "SELECT title from idents where id='$safeid'"); - - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $ids[$nodeid] = $r[0]; - return $r[0]; - } elseif (isset($GLOBALS['fb_idx'])) { - $q = sqlite_query($GLOBALS['fb_idx'], "SELECT title from idents where id='$safeid'"); - - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $ids[$nodeid] = $r[0]; - return $r[0]; - } - } - return null; + /* we're going to do some tricky stuff here for languages, + * by using entities as much as possible */ + if (isset($special[$nodeid])) { + /* Check for the entity value */ + $q = sqlite_query($GLOBALS['idx'], "SELECT * FROM ents WHERE entid = '$special[$nodeid]'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + return $r[1]; + } else { /* It's not an entity, let's just return it then */ + return $special[$nodeid]; + } + } + + /* See if the title lookup is in the cache already */ + if (isset($ids[$nodeid])) { + return $ids[$nodeid]; + } + + /* It's not, so we try to resolve it from the DB */ + $safeid = sqlite_escape_string($nodeid); + $q = sqlite_query($GLOBALS['idx'], "SELECT title from idents where id='$safeid'"); + + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $ids[$nodeid] = $r[0]; + return $r[0]; + } elseif (isset($GLOBALS['fb_idx'])) { + $q = sqlite_query($GLOBALS['fb_idx'], "SELECT title from idents where id='$safeid'"); + + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $ids[$nodeid] = $r[0]; + return $r[0]; + } + } + return null; } function make_function_link($ref) { - $parts = explode('.', $ref); - $id = 'function.'. $parts[3]; - $title = lookup_title($id); - if (!$title) { - $title = $id. ' [?]'; - } - $func_name = strtr($parts[3], array('-'=>'_')); - if ($title == $func_name) { - $title = ""; - } else { - $title = " - $title"; - } - return "<div class=\"function_link\"><function>$func_name</function>$title</div>"; + $parts = explode('.', $ref); + $id = 'function.'. $parts[3]; + $title = lookup_title($id); + if (!$title) { + $title = $id. ' [?]'; + } + $func_name = strtr($parts[3], array('-'=>'_')); + if ($title == $func_name) { + $title = ""; + } else { + $title = " - $title"; + } + return "<div class=\"function_link\"><function>$func_name</function>$title</div>"; } function make_xref($ref) { - $parts = explode('.', $ref); - if ($parts[0] == 'reference' && $parts[2] == 'functions') { - $id = 'function.'. $parts[3]; - } - $title = lookup_title($id); - if (!$title) { - $title = $id. ' [?]'; - } - return "<xref linkend=\"$id\">$title</xref>"; + $parts = explode('.', $ref); + if ($parts[0] == 'reference' && $parts[2] == 'functions') { + $id = 'function.'. $parts[3]; + } + $title = lookup_title($id); + if (!$title) { + $title = $id. ' [?]'; + } + return "<xref linkend=\"$id\">$title</xref>"; } function handle_funcref() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - $ret = "<h1>$current_page_title</h1>\n"; - foreach ($children as $id => $title) { - $url = generate_url_for_id($lang, $id); - $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; - } - return $ret."<br /><br />"; + $ret = "<h1>$current_page_title</h1>\n"; + foreach ($children as $id => $title) { + $url = generate_url_for_id($lang, $id); + $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; + } + return $ret."<br /><br />"; } function handle_appendixes() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - $ret = "<h1>$current_page_title</h1>\n"; - foreach ($children as $id => $title) { - $url = generate_url_for_id($lang, $id); - $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; - } - return $ret . "<br /><br />"; - + $ret = "<h1>$current_page_title</h1>\n"; + foreach ($children as $id => $title) { + $url = generate_url_for_id($lang, $id); + $ret .= "<h2 class='funcref'><a href='$url'>$title</a></h2>\n"; + } + return $ret . "<br /><br />"; + } function do_contents($id, $level) { - global $lang; - $q = "SELECT id, docbook_id FROM toc WHERE parent_id = $id"; - $r = sqlite_query($GLOBALS['idx'], $q); - $ret = "<ul>"; - while ($r && $row = sqlite_fetch_array($r, SQLITE_NUM)) { - $ret .= "<li>"; - - $title = lookup_title($row[1]); - if (empty($title)) { - $title = $row[1]. ' [?]'; - $ret .= $title; - } else { - $url = generate_url_for_id($lang, $row[1]); - $ret .= "<a href='$url'>$title</a>"; - } - - if (($level < 2 && substr($row[1], 0, 3) != 'ref') || $level < 1) { - $ret .= do_contents($row[0], $level + 1); - } - $ret .= "</li>\n"; - } - return $ret .= "</ul>\n"; + global $lang; + $q = "SELECT id, docbook_id FROM toc WHERE parent_id = $id"; + $r = sqlite_query($GLOBALS['idx'], $q); + $ret = "<ul>"; + while ($r && $row = sqlite_fetch_array($r, SQLITE_NUM)) { + $ret .= "<li>"; + + $title = lookup_title($row[1]); + if (empty($title)) { + $title = $row[1]. ' [?]'; + $ret .= $title; + } else { + $url = generate_url_for_id($lang, $row[1]); + $ret .= "<a href='$url'>$title</a>"; + } + + if (($level < 2 && substr($row[1], 0, 3) != 'ref') || $level < 1) { + $ret .= do_contents($row[0], $level + 1); + } + $ret .= "</li>\n"; + } + return $ret .= "</ul>\n"; } function handle_contents() { - global $current_page_title, $children, $lang; + global $current_page_title, $children, $lang; - return "<center><h1>PHP Manual</h1></center><h2>Contents</h2>" . do_contents(1, 0); + return "<center><h1>PHP Manual</h1></center><h2>Contents</h2>" . do_contents(1, 0); } function handle_include($node) { - $filename = BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; - $fallback_filename = FALLBACK_BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; + $filename = BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; + $fallback_filename = FALLBACK_BASE . strtr($node->attributes['ref'], '.', '/') . '.xml'; - $doc = load_xml_doc($filename, true, $fallback_filename); - return $doc->transform($GLOBALS['map']); + $doc = load_xml_doc($filename, true, $fallback_filename); + return $doc->transform($GLOBALS['map']); } // Handle the case where a requested node id was not found function handle_missing_index() { - global $current_page, $lang; + global $current_page, $lang; - header('Location: ' . WEBBASE . 'search.php?q=' . urlencode($current_page) . '&l=' . $lang); - exit; + header('Location: ' . WEBBASE . 'search.php?q=' . urlencode($current_page) . '&l=' . $lang); + exit; } ?> http://cvs.php.net/diff.php/livedocs/mkindex.php?r1=1.16&r2=1.17&ty=u Index: livedocs/mkindex.php diff -u livedocs/mkindex.php:1.16 livedocs/mkindex.php:1.17 --- livedocs/mkindex.php:1.16 Mon Jan 12 18:04:30 2004 +++ livedocs/mkindex.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -19,7 +19,7 @@ // | construct an index | // +----------------------------------------------------------------------+ // -// $Id: mkindex.php,v 1.16 2004/01/12 23:04:30 didou Exp $ +// $Id: mkindex.php,v 1.17 2004/02/16 17:54:59 derick Exp $ /* just to be on the safe side */ @@ -31,234 +31,234 @@ $TMPDIR = $argv[3]; if (!is_dir($PHPDOC) || !is_dir($PHPDOC . DIRECTORY_SEPARATOR . $LANG)) { - echo "Usage: index-phpdoc.php /path/to/phpdoc lang tmp-dir\n"; - exit(1); + echo "Usage: index-phpdoc.php /path/to/phpdoc lang tmp-dir\n"; + exit(1); } function entity_replace($data) { - global $replacements; + global $replacements; - $entity_name = substr($data[0], 1, -1); - if (isset($replacements[$entity_name])) { - $data[0] = $replacements[$entity_name]; - } else { - $data[0] = ''; - } + $entity_name = substr($data[0], 1, -1); + if (isset($replacements[$entity_name])) { + $data[0] = $replacements[$entity_name]; + } else { + $data[0] = ''; + } - return $data[0]; + return $data[0]; } class DocBookXMLFileParser { - var $fileid = false; - var $last_id = false; - var $cdata = null; - var $data = ''; - - function DocBookXMLFileParser($filename, $rel, $parser) { - $this->fileid = $GLOBALS['fileid']; - - xml_set_object($parser, $this); - xml_set_element_handler($parser, "start_elem", "end_elem"); - xml_set_character_data_handler($parser, "cdata"); - xml_set_external_entity_ref_handler($parser, "ext_ent"); - xml_set_unparsed_entity_decl_handler($parser, "unp_ent"); - - $data = file_get_contents($filename); - /* Yes, we do this twice, because the entities can contain entities again */ - $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); - $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); - if (!xml_parse($parser, $data, true)) { - if (xml_get_error_code($parser) != XML_ERROR_NO_ELEMENTS) { - $lines = split("\n", $data); - printf("XML Error: %s:%d %s: '%s'\n", - $filename, xml_get_current_line_number($parser), - xml_error_string(xml_get_error_code($parser)), - $lines[xml_get_current_line_number($parser) - 1] - ); - } - } - } - - function start_elem($parser, $name, $attrs) { - // if there is an ID attribute, record it - if (isset($attrs['ID'])) { - $this->last_id = $attrs['ID']; - } - } - - function end_elem($parser, $name) { - if ($this->last_id !== false) { - echo "\tAdded ID {$this->last_id}\n"; - - $this->data .= "INSERT INTO idents VALUES ('{$this->last_id}', {$this->fileid}, '" . sqlite_escape_string(trim($this->cdata)) . "');"; - - if ($this->last_id == 'wrappers') { - echo "\n\n"; - } - - $this->last_id = false; - } - } - - function cdata($parser, $data) { - if ($this->last_id !== false) { - $this->cdata = $data; - } - } - - function ext_ent($parser, $openEntityNames, $base, $systemId, $publicId) { - echo "EXT:"; - $a = func_get_args(); - array_shift($a); - print_r($a); - return false; - } - - function unp_ent($parser, $entity_name, $base, $system_id, $public_id, $notation_name) { - echo "UNP:"; - $a = func_get_args(); - array_shift($a); - print_r($a); - return false; - } + var $fileid = false; + var $last_id = false; + var $cdata = null; + var $data = ''; + + function DocBookXMLFileParser($filename, $rel, $parser) { + $this->fileid = $GLOBALS['fileid']; + + xml_set_object($parser, $this); + xml_set_element_handler($parser, "start_elem", "end_elem"); + xml_set_character_data_handler($parser, "cdata"); + xml_set_external_entity_ref_handler($parser, "ext_ent"); + xml_set_unparsed_entity_decl_handler($parser, "unp_ent"); + + $data = file_get_contents($filename); + /* Yes, we do this twice, because the entities can contain entities again */ + $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); + $data = preg_replace_callback('/&[a-zA-Z0-9.-]+;/', 'entity_replace', $data); + if (!xml_parse($parser, $data, true)) { + if (xml_get_error_code($parser) != XML_ERROR_NO_ELEMENTS) { + $lines = split("\n", $data); + printf("XML Error: %s:%d %s: '%s'\n", + $filename, xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser)), + $lines[xml_get_current_line_number($parser) - 1] + ); + } + } + } + + function start_elem($parser, $name, $attrs) { + // if there is an ID attribute, record it + if (isset($attrs['ID'])) { + $this->last_id = $attrs['ID']; + } + } + + function end_elem($parser, $name) { + if ($this->last_id !== false) { + echo "\tAdded ID {$this->last_id}\n"; + + $this->data .= "INSERT INTO idents VALUES ('{$this->last_id}', {$this->fileid}, '" . sqlite_escape_string(trim($this->cdata)) . "');"; + + if ($this->last_id == 'wrappers') { + echo "\n\n"; + } + + $this->last_id = false; + } + } + + function cdata($parser, $data) { + if ($this->last_id !== false) { + $this->cdata = $data; + } + } + + function ext_ent($parser, $openEntityNames, $base, $systemId, $publicId) { + echo "EXT:"; + $a = func_get_args(); + array_shift($a); + print_r($a); + return false; + } + + function unp_ent($parser, $entity_name, $base, $system_id, $public_id, $notation_name) { + echo "UNP:"; + $a = func_get_args(); + array_shift($a); + print_r($a); + return false; + } } function build_func_list() { - global $idx; - - $list = file_get_contents($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . "xsl/version.xml"); - $x = preg_match_all('@<function name=([\'"])([a-zA-Z0-9_]+)\\1 from=([\'"])(.+)\\3@Usm', $list, $matches); - $data = ''; - for ($i = 0; $i < $x; $i++) { - $func = sqlite_escape_string($matches[2][$i]); - $vers = sqlite_escape_string($matches[4][$i]); - $data .= "INSERT INTO funcs VALUES('$func', '$vers');"; - } - if ($data) { - sqlite_query($idx, $data); - } + global $idx; + + $list = file_get_contents($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . "xsl/version.xml"); + $x = preg_match_all('@<function name=([\'"])([a-zA-Z0-9_]+)\\1 from=([\'"])(.+)\\3@Usm', $list, $matches); + $data = ''; + for ($i = 0; $i < $x; $i++) { + $func = sqlite_escape_string($matches[2][$i]); + $vers = sqlite_escape_string($matches[4][$i]); + $data .= "INSERT INTO funcs VALUES('$func', '$vers');"; + } + if ($data) { + sqlite_query($idx, $data); + } } function parse_file($filename, $rel, $dirid) { - global $idx, $fileid; + global $idx, $fileid; - echo "Parse file: $rel "; + echo "Parse file: $rel "; - /* create an entry in the files table */ - $q = sqlite_query($idx, "SELECT fileid, mtime from files where filename='$rel'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - list($fileid, $mtime) = $r; - if (filemtime($filename) <= $mtime) { - echo " Skipping; already indexed\n"; - return; - } - echo " Reparsing file ID $fileid\n"; - } else { - $mtime = filemtime($filename); - sqlite_query($idx, "INSERT INTO files VALUES (NULL, '$rel', $mtime, $dirid)"); - $fileid = sqlite_last_insert_rowid($idx); - echo " Parsing file ID $fileid\n"; - } - - $parser = xml_parser_create(); - $p = new DocBookXMLFileParser($filename, $rel, $parser); - xml_parser_free($parser); - - if ($p->data) { - sqlite_query($idx, $p->data); - } + /* create an entry in the files table */ + $q = sqlite_query($idx, "SELECT fileid, mtime from files where filename='$rel'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + list($fileid, $mtime) = $r; + if (filemtime($filename) <= $mtime) { + echo " Skipping; already indexed\n"; + return; + } + echo " Reparsing file ID $fileid\n"; + } else { + $mtime = filemtime($filename); + sqlite_query($idx, "INSERT INTO files VALUES (NULL, '$rel', $mtime, $dirid)"); + $fileid = sqlite_last_insert_rowid($idx); + echo " Parsing file ID $fileid\n"; + } + + $parser = xml_parser_create(); + $p = new DocBookXMLFileParser($filename, $rel, $parser); + xml_parser_free($parser); + + if ($p->data) { + sqlite_query($idx, $p->data); + } } function scan_entities($dirname) { - global $idx, $LANG; + global $idx, $LANG; - sqlite_query($idx, 'delete from ents'); + sqlite_query($idx, 'delete from ents'); - $ents = glob($dirname . '/*.ent'); - $language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . $LANG . DIRECTORY_SEPARATOR . '*.ent'); - if ($LANG != 'en') { - $fallback_language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '*.ent'); - } else { - $fallback_language_defs = array(); - } - $files = array_merge($ents, $language_defs, $fallback_language_defs); - $skip = array('chapters.ent');//, 'file-entities.ent'); - $language_def_files = array('language-defs.ent', 'language-snippets.ent'); - $pats = array( '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+\'([^\']+)\'>/Usm', '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+"([^"]+)">/Usm' ); - - foreach ($files as $filename) { - echo "Entities: $filename\n"; - if (in_array(basename($filename), $skip)) { - echo "Skip!\n"; - continue; - } - - $d = file_get_contents($filename); - - foreach ($pats as $pat) { - $x = preg_match_all($pat, $d, $matches); - - for ($i = 0; $i < $x; $i++) { - if (!isset($replacements[$matches[1][$i]])) { - $id = sqlite_escape_string($matches[1][$i]); - $value = sqlite_escape_string($matches[2][$i]); - @sqlite_query($idx, "INSERT INTO ents VALUES ('$id', '$value')"); - - $replacements[$matches[1][$i]] = $matches[2][$i]; - } - } - } - } - return $replacements; + $ents = glob($dirname . '/*.ent'); + $language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . $LANG . DIRECTORY_SEPARATOR . '*.ent'); + if ($LANG != 'en') { + $fallback_language_defs = glob($GLOBALS['PHPDOC'] . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '*.ent'); + } else { + $fallback_language_defs = array(); + } + $files = array_merge($ents, $language_defs, $fallback_language_defs); + $skip = array('chapters.ent');//, 'file-entities.ent'); + $language_def_files = array('language-defs.ent', 'language-snippets.ent'); + $pats = array( '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+\'([^\']+)\'>/Usm', '/<!ENTITY\s+([a-zA-Z0-9.-]+)\s+"([^"]+)">/Usm' ); + + foreach ($files as $filename) { + echo "Entities: $filename\n"; + if (in_array(basename($filename), $skip)) { + echo "Skip!\n"; + continue; + } + + $d = file_get_contents($filename); + + foreach ($pats as $pat) { + $x = preg_match_all($pat, $d, $matches); + + for ($i = 0; $i < $x; $i++) { + if (!isset($replacements[$matches[1][$i]])) { + $id = sqlite_escape_string($matches[1][$i]); + $value = sqlite_escape_string($matches[2][$i]); + @sqlite_query($idx, "INSERT INTO ents VALUES ('$id', '$value')"); + + $replacements[$matches[1][$i]] = $matches[2][$i]; + } + } + } + } + return $replacements; } function scan_dir($dirname, $rel = '') { - global $idx; - - $d = opendir($dirname); - if (!$d) { - return false; - } - - if ($rel == 'functions') { - return; - } - - $files = array(); - $rel_l = strlen($rel); - - $q = sqlite_query($idx, "SELECT dirid from dirs where dirname='$rel'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $dirid = $r[0]; - } else { - sqlite_query($idx, "INSERT INTO dirs VALUES(NULL, '$rel')"); - $dirid = sqlite_last_insert_rowid($idx); - } - - readdir($d); - readdir($d); - while (($f = readdir($d)) !== false) { - if ($f == 'CVS') { - continue; - } - $full = $dirname . DIRECTORY_SEPARATOR . $f; - if ($rel_l) { - $relname = $rel . DIRECTORY_SEPARATOR . $f; - } else { - $relname = $f; - } - if (is_dir($full)) { - scan_dir($full, $relname); - } else if (substr($f, -4) == '.xml') { - if ($f != 'functions.xml' || $relname == 'language/functions.xml') { - $files[$f] = $full; - parse_file($full, $relname, $dirid); - } - } - } - closedir($d); + global $idx; + + $d = opendir($dirname); + if (!$d) { + return false; + } + + if ($rel == 'functions') { + return; + } + + $files = array(); + $rel_l = strlen($rel); + + $q = sqlite_query($idx, "SELECT dirid from dirs where dirname='$rel'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $dirid = $r[0]; + } else { + sqlite_query($idx, "INSERT INTO dirs VALUES(NULL, '$rel')"); + $dirid = sqlite_last_insert_rowid($idx); + } + + readdir($d); + readdir($d); + while (($f = readdir($d)) !== false) { + if ($f == 'CVS') { + continue; + } + $full = $dirname . DIRECTORY_SEPARATOR . $f; + if ($rel_l) { + $relname = $rel . DIRECTORY_SEPARATOR . $f; + } else { + $relname = $f; + } + if (is_dir($full)) { + scan_dir($full, $relname); + } else if (substr($f, -4) == '.xml') { + if ($f != 'functions.xml' || $relname == 'language/functions.xml') { + $files[$f] = $full; + parse_file($full, $relname, $dirid); + } + } + } + closedir($d); } @@ -272,66 +272,66 @@ sqlite_query($idx, 'PRAGMA cache_size=100000'); if (!$idx) { - die("could not open sqlite database"); + die("could not open sqlite database"); } $create = <<<SQL CREATE TABLE dirs ( - dirid INTEGER PRIMARY KEY, - dirname TEXT + dirid INTEGER PRIMARY KEY, + dirname TEXT ); CREATE TABLE files ( - fileid INTEGER PRIMARY KEY, - filename TEXT, - mtime INTEGER, - dirid INTEGER + fileid INTEGER PRIMARY KEY, + filename TEXT, + mtime INTEGER, + dirid INTEGER ); CREATE TABLE idents ( - id TEXT PRIMARY KEY, - fileid INTEGER, -- The file in which the identifier can be found - title TEXT -- Caption of the identifier for linking purposes + id TEXT PRIMARY KEY, + fileid INTEGER, -- The file in which the identifier can be found + title TEXT -- Caption of the identifier for linking purposes ); CREATE TABLE ents ( - entid TEXT PRIMARY KEY, - value TEXT + entid TEXT PRIMARY KEY, + value TEXT ); CREATE TABLE funcs ( - funcname TEXT PRIMARY KEY, - versinfo TEXT + funcname TEXT PRIMARY KEY, + versinfo TEXT ); CREATE TABLE toc ( - id INTEGER PRIMARY KEY, - lvl INTEGER, - parent_id INTEGER, - docbook_id TEXT, - parent_docbook_id TEXT, - path TEXT, - title TEXT, - descr TEXT + id INTEGER PRIMARY KEY, + lvl INTEGER, + parent_id INTEGER, + docbook_id TEXT, + parent_docbook_id TEXT, + path TEXT, + title TEXT, + descr TEXT ); CREATE TABLE searchi ( - skey VARCHAR(230), - path VARCHAR(230), - prio INTEGER + skey VARCHAR(230), + path VARCHAR(230), + prio INTEGER ); CREATE INDEX searchi_skey_idx ON searchi(skey); CREATE TABLE full_search ( - skey VARCHAR(100), - toc_id INTEGER + skey VARCHAR(100), + toc_id INTEGER ); CREATE INDEX full_search_skey_idx ON full_search(skey); CREATE TABLE stop_list ( - slkey VARCHAR(100) + slkey VARCHAR(100) ); CREATE INDEX stop_list_idx ON stop_list(slkey); SQL; @@ -348,7 +348,7 @@ sqlite_query($idx, 'COMMIT'); $qry_str = ''; - + /* * Priority List * 1 - section @@ -357,27 +357,27 @@ * 4 - function metaphone * 5 - function name minus 1 prefix str_replace -> replace */ - + $f_len = strlen('function.'); - + $r = sqlite_unbuffered_query("SELECT docbook_id FROM toc", $idx); while (($f = sqlite_fetch_string($r)) !== FALSE) { - $path = sqlite_escape_string($f); - if (($p = strrpos($f, '.')) !== false) { - $fn = strtolower(substr($f, ++$p)); - } else { - $fn = strtolower($f); - } - $f_name = preg_replace('![^a-z0-9]!', '', $fn); - - if (!strncmp($f, 'function.', $f_len)) { - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 2);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 4);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(preg_replace('![^a-z0-9]!', '', substr(strstr($f, '-'), 1)))."', '" . $path . "', 5);"; - } else { - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 1);"; - $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 3);"; - } + $path = sqlite_escape_string($f); + if (($p = strrpos($f, '.')) !== false) { + $fn = strtolower(substr($f, ++$p)); + } else { + $fn = strtolower($f); + } + $f_name = preg_replace('![^a-z0-9]!', '', $fn); + + if (!strncmp($f, 'function.', $f_len)) { + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 2);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 4);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(preg_replace('![^a-z0-9]!', '', substr(strstr($f, '-'), 1)))."', '" . $path . "', 5);"; + } else { + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string($f_name) . "', '" . $path . "', 1);"; + $qry_str .= "INSERT INTO searchi VALUES('" . sqlite_escape_string(metaphone($f_name)) . "', '" . $path . "', 3);"; + } } sqlite_query($idx, 'BEGIN TRANSACTION; '.$qry_str.' COMMIT'); unset($qry_str); @@ -389,112 +389,112 @@ define('MIN_WORD_LEN', 2); function search_parse_file($file, &$descr) { - $descr = $ret = ''; - $p = 0; - $fd = file_get_contents($file); - - if (($p = strpos($fd, '<title>')) !== FALSE) { - $p += TITLE_LEN; - if (($e = strpos($fd, '</refpurpose>', $p)) !== FALSE) { - $descr = substr($fd, $p, ($e - $p)); - $p = $e + 1 + TITLE_LEN; - } - } - - if (($p = strpos($fd, '<refpurpose>')) !== false) { - $p += REFP_LEN; - if (($e = strpos($fd, '</refpurpose>', $p)) !== false) { - $descr = substr($fd, $p, ($e - $p)); - $ret = $descr . ' '; - $p = SEE_ALSO_LEN + $e + 1; - } - } - - while (($p = strpos($fd, 'para>', $p)) !== false) { - if ($fd{$p - 1} == '<') { - $tag = '</para>'; - $p += 5; - } else if ($fd{$p - 1} == 'm' && $fd{$p - 2} == 'i' && $fd{$p - 3} == 's' && $fd{$p - 4} == '<') { - $tag = '</simpara>'; - $p += 5; - } else { - $p += 5; - continue; - } - if (($e = strpos($fd, $tag, $p)) === false) { - echo "Warning: non terminated $tag inside $file\n"; - break; - } - $d = substr($fd, $p, ($e - $p)); - $p = $e; - - if (!strncmp($d, 'See also:', SEE_ALSO_LEN)) { - continue; - } + $descr = $ret = ''; + $p = 0; + $fd = file_get_contents($file); + + if (($p = strpos($fd, '<title>')) !== FALSE) { + $p += TITLE_LEN; + if (($e = strpos($fd, '</refpurpose>', $p)) !== FALSE) { + $descr = substr($fd, $p, ($e - $p)); + $p = $e + 1 + TITLE_LEN; + } + } + + if (($p = strpos($fd, '<refpurpose>')) !== false) { + $p += REFP_LEN; + if (($e = strpos($fd, '</refpurpose>', $p)) !== false) { + $descr = substr($fd, $p, ($e - $p)); + $ret = $descr . ' '; + $p = SEE_ALSO_LEN + $e + 1; + } + } + + while (($p = strpos($fd, 'para>', $p)) !== false) { + if ($fd{$p - 1} == '<') { + $tag = '</para>'; + $p += 5; + } else if ($fd{$p - 1} == 'm' && $fd{$p - 2} == 'i' && $fd{$p - 3} == 's' && $fd{$p - 4} == '<') { + $tag = '</simpara>'; + $p += 5; + } else { + $p += 5; + continue; + } + if (($e = strpos($fd, $tag, $p)) === false) { + echo "Warning: non terminated $tag inside $file\n"; + break; + } + $d = substr($fd, $p, ($e - $p)); + $p = $e; + + if (!strncmp($d, 'See also:', SEE_ALSO_LEN)) { + continue; + } - $ret .= $d . ' '; - } + $ret .= $d . ' '; + } - $ret = preg_replace('![^a-z0-9\'_-]!', ' ', strtolower(strip_tags($ret))); - $ret = preg_replace('!\s+!', ' ', $ret); + $ret = preg_replace('![^a-z0-9\'_-]!', ' ', strtolower(strip_tags($ret))); + $ret = preg_replace('!\s+!', ' ', $ret); - return array_unique(explode(' ', sqlite_escape_string($ret))); + return array_unique(explode(' ', sqlite_escape_string($ret))); } function search_parse_dir($path, $section) { - global $idx, $toca, $tocd; + global $idx, $toca, $tocd; - $d = opendir($path); - readdir($d); readdir($d); + $d = opendir($path); + readdir($d); readdir($d); - while (($f = readdir($d))) { - if ($f == 'functions.xml' || $f == 'CVS' || $f == '.cvsignore') { - continue; - } - switch (filetype($path . '/' . $f)) { - case 'file': - switch ($section) { - case 'reference' : - if ($f == 'configure.xml' || $f == 'constants.xml' || $f == 'ini.xml' || $f == 'reference.xml') { - $docbook_id = 'ref.' . basename($path); - } else { - $docbook_id = 'function.' . substr($f, 0, -4); - } - break; - case 'faq': - case 'security' : - $docbook_id = $section . '.' . substr($f, 0, -4); - break; - case 'chapters' : - case 'appendices' : - $docbook_id = substr($f, 0, -4); - break; - } - - if (isset($toca[$docbook_id])) { - $id = $toca[$docbook_id]; - $wl = search_parse_file($path . '/' . $f, $descr); - if ($descr && !isset($tocd[$id])) { - $tocd[$id] = trim($descr); - } - $qry = ''; - foreach ($wl as $w) { - if (strlen($w) > MIN_WORD_LEN) { - $qry .= "INSERT INTO full_search VALUES('{$w}', {$id});"; - } - } - sqlite_query($idx, $qry); - } else { - echo "BAD ID: $docbook_id ($path, $f, $section)\n"; - } - break; - case 'dir' : - search_parse_dir($path . '/' . $f, $section); - break; - } - } - closedir($d); + while (($f = readdir($d))) { + if ($f == 'functions.xml' || $f == 'CVS' || $f == '.cvsignore') { + continue; + } + switch (filetype($path . '/' . $f)) { + case 'file': + switch ($section) { + case 'reference' : + if ($f == 'configure.xml' || $f == 'constants.xml' || $f == 'ini.xml' || $f == 'reference.xml') { + $docbook_id = 'ref.' . basename($path); + } else { + $docbook_id = 'function.' . substr($f, 0, -4); + } + break; + case 'faq': + case 'security' : + $docbook_id = $section . '.' . substr($f, 0, -4); + break; + case 'chapters' : + case 'appendices' : + $docbook_id = substr($f, 0, -4); + break; + } + + if (isset($toca[$docbook_id])) { + $id = $toca[$docbook_id]; + $wl = search_parse_file($path . '/' . $f, $descr); + if ($descr && !isset($tocd[$id])) { + $tocd[$id] = trim($descr); + } + $qry = ''; + foreach ($wl as $w) { + if (strlen($w) > MIN_WORD_LEN) { + $qry .= "INSERT INTO full_search VALUES('{$w}', {$id});"; + } + } + sqlite_query($idx, $qry); + } else { + echo "BAD ID: $docbook_id ($path, $f, $section)\n"; + } + break; + case 'dir' : + search_parse_dir($path . '/' . $f, $section); + break; + } + } + closedir($d); } // list of directories to index @@ -504,18 +504,18 @@ sqlite_query($idx, 'BEGIN TRANSACTION'); $r = sqlite_unbuffered_query("SELECT id, docbook_id FROM toc", $idx); while (($row = sqlite_fetch_array($r, SQLITE_NUM))) { - $toca[$row[1]] = $row[0]; + $toca[$row[1]] = $row[0]; } $tocd = array(); foreach ($parse_dirs as $dir) { - search_parse_dir($path . $dir, $dir); + search_parse_dir($path . $dir, $dir); } $qry = ''; foreach ($tocd as $k => $v) { - $qry .= "UPDATE toc SET descr='".sqlite_escape_string($v)."' WHERE id={$k};"; + $qry .= "UPDATE toc SET descr='".sqlite_escape_string($v)."' WHERE id={$k};"; } sqlite_query($idx, $qry); sqlite_query($idx, 'COMMIT'); @@ -525,10 +525,10 @@ sqlite_query($idx, 'BEGIN TRANSACTION'); $qry1 = $qry2 = ''; foreach ($file as $w) { - $w = sqlite_escape_string(rtrim($w)); + $w = sqlite_escape_string(rtrim($w)); - $qry1 .= "DELETE FROM full_search WHERE skey='{$w}';"; - $qry2 .= "INSERT INTO stop_list VALUES('{$w}');"; + $qry1 .= "DELETE FROM full_search WHERE skey='{$w}';"; + $qry2 .= "INSERT INTO stop_list VALUES('{$w}');"; } sqlite_query($idx, $qry1); sqlite_query($idx, $qry2); @@ -539,12 +539,12 @@ $qry = ''; sqlite_query($idx, 'BEGIN TRANSACTION'); while (($row = sqlite_fetch_array($r, SQLITE_NUM))) { - if ($row[2] == 1) { - break; - } + if ($row[2] == 1) { + break; + } - $del = $row[2] - 1; - $qry .= "DELETE FROM full_search WHERE skey='".sqlite_escape_string($row[0])."' AND toc_id=".$row[1].";"; + $del = $row[2] - 1; + $qry .= "DELETE FROM full_search WHERE skey='".sqlite_escape_string($row[0])."' AND toc_id=".$row[1].";"; } sqlite_query($idx, $qry); sqlite_query($idx, 'COMMIT'); @@ -557,17 +557,17 @@ $tbl_data = <<<SQL_CACHE CREATE TABLE cache_data ( - toc_id INTEGER, - qry_id INTEGER, - pos INTEGER + toc_id INTEGER, + qry_id INTEGER, + pos INTEGER ); CREATE INDEX cache_data_idx ON cache_data(qry_id); CREATE TABLE search_cache ( - id INTEGER PRIMARY KEY, - ttl INTEGER, - qry TEXT + id INTEGER PRIMARY KEY, + ttl INTEGER, + qry TEXT ); CREATE INDEX search_cache_idx ON search_cache(qry); http://cvs.php.net/diff.php/livedocs/mktoc.php?r1=1.7&r2=1.8&ty=u Index: livedocs/mktoc.php diff -u livedocs/mktoc.php:1.7 livedocs/mktoc.php:1.8 --- livedocs/mktoc.php:1.7 Fri Jan 30 00:49:15 2004 +++ livedocs/mktoc.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -20,85 +20,85 @@ // | tree into the toc table. | // +----------------------------------------------------------------------+ // -// $Id: mktoc.php,v 1.7 2004/01/30 05:49:15 momo Exp $ +// $Id: mktoc.php,v 1.8 2004/02/16 17:54:59 derick Exp $ set_magic_quotes_runtime(0); class DocBookTOCParser { - var $cdata = null; - var $id_stack = array(); - var $docbook_id_stack = array(); - var $last_id = 1; - - function DocBookTOCParser($filename, $rel, $parser) { - $this->fileid = $GLOBALS['fileid']; - - xml_set_object($parser, $this); - xml_set_element_handler($parser, "start_elem", "end_elem"); - - $data = file_get_contents($filename); - if (!xml_parse($parser, $data, true)) { - printf("XML: %s:%d %s\n", - $filename, xml_get_current_line_number($parser), - xml_error_string(xml_get_error_code($parser)) - ); - } - } - - function start_elem($parser, $name, $attrs) { - global $idx; - - /* if there is an ID attribute, record it */ - $docbook_id = sqlite_escape_string($attrs['ID']); - $title = sqlite_escape_string($attrs['TITLE']); - - $level = sizeof($this->id_stack) - 1; - if (isset($this->id_stack[$level])) { - $parent_id = (int) $this->id_stack[$level]; - } else { - $parent_id = 0; - } - $level = sizeof($this->docbook_id_stack) - 1; - if (isset($this->docbook_id_stack[$level])) { - $docbook_parent_id = sqlite_escape_string($this->docbook_id_stack[$level]); - } else { - $docbook_parent_id = ''; - } - $path = sqlite_escape_string(implode(",", $this->docbook_id_stack)); - - array_push($this->id_stack, $this->last_id); - array_push($this->docbook_id_stack, $docbook_id); - - echo "INSERT INTO toc VALUES ({$this->last_id}, {$level}, {$parent_id}, '{$docbook_id}', '{$docbook_parent_id}', '{$path}', '{$title}', '{$title}');\n"; - $this->last_id++; - } - - function end_elem($parser, $name) { - array_pop($this->docbook_id_stack); - array_pop($this->id_stack); - } + var $cdata = null; + var $id_stack = array(); + var $docbook_id_stack = array(); + var $last_id = 1; + + function DocBookTOCParser($filename, $rel, $parser) { + $this->fileid = $GLOBALS['fileid']; + + xml_set_object($parser, $this); + xml_set_element_handler($parser, "start_elem", "end_elem"); + + $data = file_get_contents($filename); + if (!xml_parse($parser, $data, true)) { + printf("XML: %s:%d %s\n", + $filename, xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser)) + ); + } + } + + function start_elem($parser, $name, $attrs) { + global $idx; + + /* if there is an ID attribute, record it */ + $docbook_id = sqlite_escape_string($attrs['ID']); + $title = sqlite_escape_string($attrs['TITLE']); + + $level = sizeof($this->id_stack) - 1; + if (isset($this->id_stack[$level])) { + $parent_id = (int) $this->id_stack[$level]; + } else { + $parent_id = 0; + } + $level = sizeof($this->docbook_id_stack) - 1; + if (isset($this->docbook_id_stack[$level])) { + $docbook_parent_id = sqlite_escape_string($this->docbook_id_stack[$level]); + } else { + $docbook_parent_id = ''; + } + $path = sqlite_escape_string(implode(",", $this->docbook_id_stack)); + + array_push($this->id_stack, $this->last_id); + array_push($this->docbook_id_stack, $docbook_id); + + echo "INSERT INTO toc VALUES ({$this->last_id}, {$level}, {$parent_id}, '{$docbook_id}', '{$docbook_parent_id}', '{$path}', '{$title}', '{$title}');\n"; + $this->last_id++; + } + + function end_elem($parser, $name) { + array_pop($this->docbook_id_stack); + array_pop($this->id_stack); + } } $TOC = $argv[1]; if (!strlen($TOC)) { - echo "Usage: mktoc.php tocfile.xml\n"; - exit(1); + echo "Usage: mktoc.php tocfile.xml\n"; + exit(1); } elseif (!is_file($TOC)) { - echo "Error: $TOC cannot be found or is not a file\n"; - exit(1); + echo "Error: $TOC cannot be found or is not a file\n"; + exit(1); } parse_file($TOC); exit; function parse_file($filename) { - global $idx, $fileid; + global $idx, $fileid; - $parser = xml_parser_create(); - $p = new DocBookTOCParser($filename, $rel='', $parser); - xml_parser_free($parser); + $parser = xml_parser_create(); + $p = new DocBookTOCParser($filename, $rel='', $parser); + xml_parser_free($parser); } ?> http://cvs.php.net/diff.php/livedocs/search.php?r1=1.6&r2=1.7&ty=u Index: livedocs/search.php diff -u livedocs/search.php:1.6 livedocs/search.php:1.7 --- livedocs/search.php:1.6 Fri Jan 23 09:58:38 2004 +++ livedocs/search.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ // | Search page | // +----------------------------------------------------------------------+ // -// $Id: search.php,v 1.6 2004/01/23 14:58:38 didou Exp $ +// $Id: search.php,v 1.7 2004/02/16 17:54:59 derick Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include './common.php'; @@ -29,128 +29,128 @@ define('RESULT_PER_PAGE', 10); function search($qry, $strict, $lang, $idx, &$ttl) { - $key = str_replace("'", '', implode('', $qry)); - sqlite_query($idx, 'BEGIN TRANSACTION'); - sqlite_query($idx, "ATTACH '" . OUTPUTDIR . "/{$lang}/livedoc-cache-idx.{$lang}.sqlite' AS sc"); - - if (($data = sqlite_array_query($idx, "SELECT id, ttl FROM search_cache WHERE qry='{$key}'"))) { - $ttl = $data[0][1]; - $id = $data[0][0]; - } else { - sqlite_query($idx, "INSERT INTO search_cache (ttl, qry) VALUES(0, '{$key}')"); - $id = sqlite_last_insert_rowid($idx); - - sqlite_query($idx, "INSERT INTO cache_data (toc_id, qry_id, pos) SELECT fs.toc_id, '{$id}', count(fs.toc_id) AS cnt FROM - full_search fs WHERE fs.skey IN(" . implode(',', $qry) . ") GROUP BY fs.toc_id ORDER BY cnt DESC LIMIT 300"); - - $ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id}")); - if ($ttl) { - sqlite_query($idx, "UPDATE search_cache SET ttl={$ttl} WHERE id={$id}"); - } - } - sqlite_query($idx, 'COMMIT'); - - if (!$ttl) { - return 0; - } - - if (!isset($_GET['p']) || $ttl <= $_GET['p']) { - $start = $_GET['p'] = 0; - } else { - $start = $_GET['p'] = (int) $_GET['p']; - } - - if ($strict) { - if (!($ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id} AND pos=" . count($qry))))) { - return 0; - } - return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} AND pos=" . count($qry) . " ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); - } + $key = str_replace("'", '', implode('', $qry)); + sqlite_query($idx, 'BEGIN TRANSACTION'); + sqlite_query($idx, "ATTACH '" . OUTPUTDIR . "/{$lang}/livedoc-cache-idx.{$lang}.sqlite' AS sc"); + + if (($data = sqlite_array_query($idx, "SELECT id, ttl FROM search_cache WHERE qry='{$key}'"))) { + $ttl = $data[0][1]; + $id = $data[0][0]; + } else { + sqlite_query($idx, "INSERT INTO search_cache (ttl, qry) VALUES(0, '{$key}')"); + $id = sqlite_last_insert_rowid($idx); + + sqlite_query($idx, "INSERT INTO cache_data (toc_id, qry_id, pos) SELECT fs.toc_id, '{$id}', count(fs.toc_id) AS cnt FROM + full_search fs WHERE fs.skey IN(" . implode(',', $qry) . ") GROUP BY fs.toc_id ORDER BY cnt DESC LIMIT 300"); + + $ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id}")); + if ($ttl) { + sqlite_query($idx, "UPDATE search_cache SET ttl={$ttl} WHERE id={$id}"); + } + } + sqlite_query($idx, 'COMMIT'); + + if (!$ttl) { + return 0; + } + + if (!isset($_GET['p']) || $ttl <= $_GET['p']) { + $start = $_GET['p'] = 0; + } else { + $start = $_GET['p'] = (int) $_GET['p']; + } + + if ($strict) { + if (!($ttl = sqlite_fetch_string(sqlite_query($idx, "SELECT count(*) FROM cache_data WHERE qry_id={$id} AND pos=" . count($qry))))) { + return 0; + } + return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} AND pos=" . count($qry) . " ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); + } - return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); + return sqlite_array_query($idx, "SELECT t.docbook_id, t.title, t.descr, cd.pos FROM cache_data cd INNER JOIN toc t ON cd.toc_id=t.id WHERE cd.qry_id={$id} ORDER BY cd.pos DESC LIMIT {$start}," . RESULT_PER_PAGE); } $res_str = ''; if (!empty($_GET['q'])) { - if (ini_get("magic_quotes_gpc") == '1') { - $tx_qry = stripslashes($_GET['q']); - } else { - $tx_qry = $_GET['q']; - } - $strict = isset($_GET['s']) ? 'checked' : ''; - - $qry = preg_replace('![^a-z0-9 \'_-]!', ' ', strtolower($tx_qry)); - $qry = trim(preg_replace('!\s+!', ' ', $qry)); - $qb = array_unique(explode(' ', $qry)); - foreach ($qb as $w) { - /* XXX: once we upgrade to 4.3.3 or php5 we can optimize this */ - if ($w && strlen($w) > 2) { - $qry_cond[$w] = "'" . sqlite_escape_string($w) . "'"; - } - } - - $html_path = WEBBASE . $lang . '/'; - - if (isset($qry_cond)) { - $data = sqlite_array_query($idx, "SELECT slkey FROM stop_list WHERE slkey IN(" . implode(',', $qry_cond) . ")"); - foreach ($data as $v) { - unset($qry_cond[$v[0]]); - } - if (count($qry_cond)) { - $wl_size = count($qry_cond); - - $data = search($qry_cond, $strict, $lang, $idx, $ttl); - - switch ($ttl) { - case 0: - $res_str = 'No Results Found'; - break; - case 1: - header("Location: {$html_path}{$data[0][0]}.html#{$data[0][0]}"); - exit; - break; - default: - $i = 0; - foreach ($data as $v) { - $m = round(($v[3] / $wl_size) * 100); - $class = !strncmp($v[0], 'function.', strlen('function.')) ? 'function' : 'link'; - ++$i; + if (ini_get("magic_quotes_gpc") == '1') { + $tx_qry = stripslashes($_GET['q']); + } else { + $tx_qry = $_GET['q']; + } + $strict = isset($_GET['s']) ? 'checked' : ''; + + $qry = preg_replace('![^a-z0-9 \'_-]!', ' ', strtolower($tx_qry)); + $qry = trim(preg_replace('!\s+!', ' ', $qry)); + $qb = array_unique(explode(' ', $qry)); + foreach ($qb as $w) { + /* XXX: once we upgrade to 4.3.3 or php5 we can optimize this */ + if ($w && strlen($w) > 2) { + $qry_cond[$w] = "'" . sqlite_escape_string($w) . "'"; + } + } + + $html_path = WEBBASE . $lang . '/'; + + if (isset($qry_cond)) { + $data = sqlite_array_query($idx, "SELECT slkey FROM stop_list WHERE slkey IN(" . implode(',', $qry_cond) . ")"); + foreach ($data as $v) { + unset($qry_cond[$v[0]]); + } + if (count($qry_cond)) { + $wl_size = count($qry_cond); + + $data = search($qry_cond, $strict, $lang, $idx, $ttl); + + switch ($ttl) { + case 0: + $res_str = 'No Results Found'; + break; + case 1: + header("Location: {$html_path}{$data[0][0]}.html#{$data[0][0]}"); + exit; + break; + default: + $i = 0; + foreach ($data as $v) { + $m = round(($v[3] / $wl_size) * 100); + $class = !strncmp($v[0], 'function.', strlen('function.')) ? 'function' : 'link'; + ++$i; $res_str .= <<< SEARCH_RES {$i}) <a class='{$class}' href='{$html_path}{$v[0]}.html#{$v[0]}'>{$v[1]}</a> <b>{$m}% match</b><br /><span class="para">{$v[2]}</span><hr align="left" class="search" /> SEARCH_RES; - } - break; - } - } else { - $res_str = 'No Results Found'; - } - } + } + break; + } + } else { + $res_str = 'No Results Found'; + } + } } else { - $tx_qry = $strict = ''; + $tx_qry = $strict = ''; } echo search_page_header(); - echo $res_str; + echo $res_str; - /* if we have more then 1 page worth of results, let's draw a pager */ - if (isset($ttl) && $ttl > RESULT_PER_PAGE) { - $ttlp = ceil($ttl / RESULT_PER_PAGE); - $curp = floor($_GET['p'] / RESULT_PER_PAGE); - $q = urlencode($tx_qry); - $st = $strict ? '&s=1' : ''; - - echo "<span='para'><b>Pages ({$ttlp}): ["; - for ($i = 0; $i < $ttlp; $i++) { - if ($i != $curp) { - echo " <a class='link' href='" . WEBBASE . "search.php?q={$q}&l={$lang}&p=" . ($i * RESULT_PER_PAGE) . "{$st}'>".($i + 1)."</a> "; - } else { - echo " ".($i + 1)." "; - } - } - echo "]<br /></span>"; - } + /* if we have more then 1 page worth of results, let's draw a pager */ + if (isset($ttl) && $ttl > RESULT_PER_PAGE) { + $ttlp = ceil($ttl / RESULT_PER_PAGE); + $curp = floor($_GET['p'] / RESULT_PER_PAGE); + $q = urlencode($tx_qry); + $st = $strict ? '&s=1' : ''; + + echo "<span='para'><b>Pages ({$ttlp}): ["; + for ($i = 0; $i < $ttlp; $i++) { + if ($i != $curp) { + echo " <a class='link' href='" . WEBBASE . "search.php?q={$q}&l={$lang}&p=" . ($i * RESULT_PER_PAGE) . "{$st}'>".($i + 1)."</a> "; + } else { + echo " ".($i + 1)." "; + } + } + echo "]<br /></span>"; + } echo search_page_footer(); http://cvs.php.net/diff.php/livedocs/style_mapping.php?r1=1.2&r2=1.3&ty=u Index: livedocs/style_mapping.php diff -u livedocs/style_mapping.php:1.2 livedocs/style_mapping.php:1.3 --- livedocs/style_mapping.php:1.2 Sat Jan 17 06:34:07 2004 +++ livedocs/style_mapping.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,494 +18,494 @@ // | Helper functions for formatting elements | // +----------------------------------------------------------------------+ // -// $Id: style_mapping.php,v 1.2 2004/01/17 11:34:07 nlopess Exp $ +// $Id: style_mapping.php,v 1.3 2004/02/16 17:54:59 derick Exp $ // almost XPATH.. ;-) $map = array( - 'acronym' => 'acronym', - 'appendix/title' => 'h1', - 'author' => 'format_name', - 'authorgroup' => 'format_authorgroup', - 'bookinfo/title' => 'h1', - 'chapter/title' => 'h1', - 'classname' => 'span', - 'classsynopsis' => 'format_class_synopsis', - 'code' => 'code', - 'collab' => 'span', - 'collabname' => 'span', - 'command' => 'span', - 'computeroutput' => 'span', - 'constant' => 'span', - 'copyright' => 'format_copyright', - 'copyright/year' => 'span', - 'copyright/holder' => 'span', - 'editor' => 'format_name', - 'emphasis' => 'em', - 'enumname' => 'span', - 'envar' => 'span', - 'filename' => 'span', - 'funcsynopsis' => 'format_funcsynopsis', - 'function' => 'format_function', - 'glossterm' => 'span', - 'htmlcode' => 'format_htmlcode', - 'informaltable' => 'table', - 'informaltable/title' => 'caption', - 'itemizedlist' => 'ul', - 'itemizedlist/listitem' => 'li', - 'legalnotice/title' => 'h3', - 'link' => 'format_link', - 'literal' => 'span', - 'literallayout' => 'format_listing', - 'methodparam' => 'span', - 'methodsynopsis' => 'format_params', - 'option' => 'span', - 'orderedlist' => 'ol', - 'orderedlist/listitem' => 'li', - 'parameter' => 'span', - 'phpdoc_include' => 'handle_include', - 'preface/title' => 'h1', - 'productname' => 'span', - 'programlisting' => 'format_listing', - 'propname' => 'span', - 'proptype' => 'span', - 'pubdate' => 'format_pubdate', - 'reference/title' => 'h1', - 'refnamediv/refname' => 'format_refname', - 'refnamediv/refpurpose' => 'h2', - 'refsect1/title' => 'h3', - 'refsect2/title' => 'h4', - 'replaceable' => 'span', - 'screen' => 'format_listing', - 'section/title' => 'h1', - 'sect1/title' => 'h2', - 'sect2/title' => 'h3', - 'sect3/title' => 'h4', - 'sect4/title' => 'h5', - 'sect5/title' => 'h6', - 'signalname' => 'span', - 'simpara' => 'p', - 'simplelist' => 'ul', - 'simplelist/member' => 'li', - 'subscript' => 'span', - 'systemitem' => 'span', - 'table' => 'table', - 'table/title' => 'caption', - 'tbody' => 'tbody', - 'tbody/row' => 'tr', - 'tbody/row/entry' => 'td', - 'tgroup' => '', - 'thead' => 'thead', - 'thead/row' => 'tr', - 'thead/row/entry' => 'th', - 'titleabbrev' => '', - 'type' => 'span', - 'ulink' => 'format_ulink', - 'userinput' => 'span', - 'varname' => 'span', - 'warning/title' => 'format_warning_title', - 'xref' => 'format_link', + 'acronym' => 'acronym', + 'appendix/title' => 'h1', + 'author' => 'format_name', + 'authorgroup' => 'format_authorgroup', + 'bookinfo/title' => 'h1', + 'chapter/title' => 'h1', + 'classname' => 'span', + 'classsynopsis' => 'format_class_synopsis', + 'code' => 'code', + 'collab' => 'span', + 'collabname' => 'span', + 'command' => 'span', + 'computeroutput' => 'span', + 'constant' => 'span', + 'copyright' => 'format_copyright', + 'copyright/year' => 'span', + 'copyright/holder' => 'span', + 'editor' => 'format_name', + 'emphasis' => 'em', + 'enumname' => 'span', + 'envar' => 'span', + 'filename' => 'span', + 'funcsynopsis' => 'format_funcsynopsis', + 'function' => 'format_function', + 'glossterm' => 'span', + 'htmlcode' => 'format_htmlcode', + 'informaltable' => 'table', + 'informaltable/title' => 'caption', + 'itemizedlist' => 'ul', + 'itemizedlist/listitem' => 'li', + 'legalnotice/title' => 'h3', + 'link' => 'format_link', + 'literal' => 'span', + 'literallayout' => 'format_listing', + 'methodparam' => 'span', + 'methodsynopsis' => 'format_params', + 'option' => 'span', + 'orderedlist' => 'ol', + 'orderedlist/listitem' => 'li', + 'parameter' => 'span', + 'phpdoc_include' => 'handle_include', + 'preface/title' => 'h1', + 'productname' => 'span', + 'programlisting' => 'format_listing', + 'propname' => 'span', + 'proptype' => 'span', + 'pubdate' => 'format_pubdate', + 'reference/title' => 'h1', + 'refnamediv/refname' => 'format_refname', + 'refnamediv/refpurpose' => 'h2', + 'refsect1/title' => 'h3', + 'refsect2/title' => 'h4', + 'replaceable' => 'span', + 'screen' => 'format_listing', + 'section/title' => 'h1', + 'sect1/title' => 'h2', + 'sect2/title' => 'h3', + 'sect3/title' => 'h4', + 'sect4/title' => 'h5', + 'sect5/title' => 'h6', + 'signalname' => 'span', + 'simpara' => 'p', + 'simplelist' => 'ul', + 'simplelist/member' => 'li', + 'subscript' => 'span', + 'systemitem' => 'span', + 'table' => 'table', + 'table/title' => 'caption', + 'tbody' => 'tbody', + 'tbody/row' => 'tr', + 'tbody/row/entry' => 'td', + 'tgroup' => '', + 'thead' => 'thead', + 'thead/row' => 'tr', + 'thead/row/entry' => 'th', + 'titleabbrev' => '', + 'type' => 'span', + 'ulink' => 'format_ulink', + 'userinput' => 'span', + 'varname' => 'span', + 'warning/title' => 'format_warning_title', + 'xref' => 'format_link', ); function format_authorgroup($node) { - $l = ''; - $cl = array(); + $l = ''; + $cl = array(); - foreach ($node->children as $child) { - if ($child->tagname == "author" || $child->tagname == "editor") { - $l .= format_name($child); - } - if ($child->tagname == "collab") { - $cl[] = $child->children[0]->content; - } - } - switch ($node->attributes['id']) { - case "authors": - $prefix = "Authors:<br />"; - break; - case "editors": - $prefix = "Edited by:<br />"; - break; - case "translators"; - $prefix = $cl[0]."<br />"; - unset($cl[0]); - break; - default: - $prefix = $node->attributes['id']; - } + foreach ($node->children as $child) { + if ($child->tagname == "author" || $child->tagname == "editor") { + $l .= format_name($child); + } + if ($child->tagname == "collab") { + $cl[] = $child->children[0]->content; + } + } + switch ($node->attributes['id']) { + case "authors": + $prefix = "Authors:<br />"; + break; + case "editors": + $prefix = "Edited by:<br />"; + break; + case "translators"; + $prefix = $cl[0]."<br />"; + unset($cl[0]); + break; + default: + $prefix = $node->attributes['id']; + } - return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', $node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl)); + return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', $node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl)); } function format_copyright($node) { - $y = array(); + $y = array(); - foreach ($node->children as $child) { - if ($child->tagname == "year") { - $y[] = $child->content; - } else if ($child->tagname == "holder") { - $holder = $child->content; - } - } + foreach ($node->children as $child) { + if ($child->tagname == "year") { + $y[] = $child->content; + } else if ($child->tagname == "holder") { + $holder = $child->content; + } + } - return sprintf('<div class="copyright">Copyright © %s by %s</div>', implode(", ", $y), $holder); + return sprintf('<div class="copyright">Copyright © %s by %s</div>', implode(", ", $y), $holder); } function format_refname($node) { - global $current_page, $idx; + global $current_page, $idx; - $vers = ''; + $vers = ''; - if (substr($current_page, 0, 9) == 'function.') { - $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', '_')); - $q = sqlite_query($idx, "SELECT versinfo FROM funcs where funcname='$func_name'"); - if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { - $vers = sprintf('<div class="versinfo">%s</div>', $r[0]); - } - } - - return sprintf('<h1 class="%s">%s</h1>%s', $node->tagname, $node->content, $vers); + if (substr($current_page, 0, 9) == 'function.') { + $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', '_')); + $q = sqlite_query($idx, "SELECT versinfo FROM funcs where funcname='$func_name'"); + if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) { + $vers = sprintf('<div class="versinfo">%s</div>', $r[0]); + } + } + + return sprintf('<h1 class="%s">%s</h1>%s', $node->tagname, $node->content, $vers); } function format_name($node) { - $class = $node->parent->attributes['id']; - foreach ($node->children as $child) { - if ($child->tagname == 'firstname') { - $firstname = $child->content; - } - if ($child->tagname == 'surname') { - $surname = $child->content; - } - } - switch ($class) { - case 'authors': - case 'editors': - $tag = 'div'; - break; - case 'translators': - $tag = 'span'; - break; - default: - $tag = 'span'; - } - return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, $surname, $tag); + $class = $node->parent->attributes['id']; + foreach ($node->children as $child) { + if ($child->tagname == 'firstname') { + $firstname = $child->content; + } + if ($child->tagname == 'surname') { + $surname = $child->content; + } + } + switch ($class) { + case 'authors': + case 'editors': + $tag = 'div'; + break; + case 'translators': + $tag = 'span'; + break; + default: + $tag = 'span'; + } + return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, $surname, $tag); } function format_parameter($node) { - return sprintf('<span class="%s">$%s</span>', $node->tagname, $node->content); + return sprintf('<span class="%s">$%s</span>', $node->tagname, $node->content); } function format_pubdate($node) { - return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, $node->content); + return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, $node->content); } function format_ulink($node) { - return sprintf('<a target="_blank" class="ulink" href="%s">%s</a>', - $node->attributes['url'], - $node->content - ); + return sprintf('<a target="_blank" class="ulink" href="%s">%s</a>', + $node->attributes['url'], + $node->content + ); } function format_warning_title($node) { - return sprintf('<span class="warning_title">%s</span>', $node->content); + return sprintf('<span class="warning_title">%s</span>', $node->content); } function format_link($node) { - global $lang; + global $lang; - $caption = $node->content; - if (strlen($caption) == 0) { - $caption = lookup_title($node->attributes['linkend']); - } - if (strlen($caption) == 0) { - $caption = $node->attributes['linkend']; - } - $url = generate_url_for_id($lang, $node->attributes['linkend']); - return sprintf('<a class="%s" href="%s">%s</a>', - $node->tagname, - $url, - $caption - ); + $caption = $node->content; + if (strlen($caption) == 0) { + $caption = lookup_title($node->attributes['linkend']); + } + if (strlen($caption) == 0) { + $caption = $node->attributes['linkend']; + } + $url = generate_url_for_id($lang, $node->attributes['linkend']); + return sprintf('<a class="%s" href="%s">%s</a>', + $node->tagname, + $url, + $caption + ); } function format_function($node) { - global $current_page, $lang; + global $current_page, $lang; - $itemid = strtr($node->content, '_', '-'); + $itemid = strtr($node->content, '_', '-'); - $class = 'function'; - if (isset($node->attributes['class'])) { - $class = 'method'; - $dest = $node->attributes['class'] . '.method.' . $itemid; - } else { - $dest = 'function.' . $itemid; - } - - if ($current_page == $dest) { - return sprintf('<span class="%s">%s()</span>', $class, $node->content); - } - - $url = generate_url_for_id($lang, $dest); - return sprintf('<a class="%s" href="%s">%s()</a>', - $class, - $url, - $node->content - ); + $class = 'function'; + if (isset($node->attributes['class'])) { + $class = 'method'; + $dest = $node->attributes['class'] . '.method.' . $itemid; + } else { + $dest = 'function.' . $itemid; + } + + if ($current_page == $dest) { + return sprintf('<span class="%s">%s()</span>', $class, $node->content); + } + + $url = generate_url_for_id($lang, $dest); + return sprintf('<a class="%s" href="%s">%s()</a>', + $class, + $url, + $node->content + ); } function format_listing($node) { - $content = trim($node->content); + $content = trim($node->content); - if (substr($content, 0, 5) == '<?php') { - $node->attributes['role'] = 'php'; - } - if (!isset($node->attributes['role'])) { - $node->attributes['role'] = ''; - } - - switch ($node->attributes['role']) { - case 'php': - $content = preg_replace(array( - '@<br />@', - '@<font color="([^"]+)">@', - '@</font>@', - ), - array( - "<br />\n", - '<span class="\\1">', - '</span>', - ), - highlight_string($content, 1)); - break; - case 'shell': - case 'html': - case 'xml': - case 'c': - $content = '<pre>' . htmlentities($content) . '</pre>'; - break; - default: - $content = htmlspecialchars($content); - } + if (substr($content, 0, 5) == '<?php') { + $node->attributes['role'] = 'php'; + } + if (!isset($node->attributes['role'])) { + $node->attributes['role'] = ''; + } + + switch ($node->attributes['role']) { + case 'php': + $content = preg_replace(array( + '@<br />@', + '@<font color="([^"]+)">@', + '@</font>@', + ), + array( + "<br />\n", + '<span class="\\1">', + '</span>', + ), + highlight_string($content, 1)); + break; + case 'shell': + case 'html': + case 'xml': + case 'c': + $content = '<pre>' . htmlentities($content) . '</pre>'; + break; + default: + $content = htmlspecialchars($content); + } - return sprintf('<div class="%scode">%s</div>', $node->attributes['role'], $content); + return sprintf('<div class="%scode">%s</div>', $node->attributes['role'], $content); } function format_params($node) { - $node->parent = null; + $node->parent = null; - /* Check role */ - if (isset($node->attributes['role'])) { - $role = $node->attributes['role']; - } else { - $role = 'php'; - } - - /* build up prototype */ - $type = $node->children[0]->content; - $fname = $node->children[1]->content; - $params = ""; - $optclose = ""; - - for ($i = 2; $i < count($node->children); $i++) { - $k = $node->children[$i]; - - if (strlen($k->tagname) == 0 || $k->tagname == 'void') { - continue; - } - - $p = ''; - if (strlen($params)) { - $p .= ','; - } - - if (isset($k->attributes['choice']) && $k->attributes['choice'] == 'opt') { - $p = '[' . $p ; - $optclose .= ']'; - if (strlen($params)) { - $p = ' ' . $p; - } - } - - if (strlen($p)) { - $p .= ' '; - } - - $p .= '<span class="methodparam"><span class="type">' . $k->children[0]->content . '</span>'; - - $name = $k->children[1]->content; - switch ($role) { - case 'c': - break; - default: - if ($name && $name{0} == '&') { - $name = '&$' . substr($name, 1); - } else { - $name = '$' . $name; - } - } + /* Check role */ + if (isset($node->attributes['role'])) { + $role = $node->attributes['role']; + } else { + $role = 'php'; + } + + /* build up prototype */ + $type = $node->children[0]->content; + $fname = $node->children[1]->content; + $params = ""; + $optclose = ""; + + for ($i = 2; $i < count($node->children); $i++) { + $k = $node->children[$i]; + + if (strlen($k->tagname) == 0 || $k->tagname == 'void') { + continue; + } + + $p = ''; + if (strlen($params)) { + $p .= ','; + } + + if (isset($k->attributes['choice']) && $k->attributes['choice'] == 'opt') { + $p = '[' . $p ; + $optclose .= ']'; + if (strlen($params)) { + $p = ' ' . $p; + } + } + + if (strlen($p)) { + $p .= ' '; + } + + $p .= '<span class="methodparam"><span class="type">' . $k->children[0]->content . '</span>'; + + $name = $k->children[1]->content; + switch ($role) { + case 'c': + break; + default: + if ($name && $name{0} == '&') { + $name = '&$' . substr($name, 1); + } else { + $name = '$' . $name; + } + } - $p .= ' <span class="varname">' . $name . '</span></span>'; + $p .= ' <span class="varname">' . $name . '</span></span>'; - $params .= $p; - } + $params .= $p; + } - return "<div class=\"methodsynopsis\"><span class=\"type\">$type</span> <span class=\"function\">$fname(</span>$params$optclose<span class=\"function\">)</span></div>"; + return "<div class=\"methodsynopsis\"><span class=\"type\">$type</span> <span class=\"function\">$fname(</span>$params$optclose<span class=\"function\">)</span></div>"; } function format_class_synopsis($node) { - $classname = $node->children[0]->children[0]->content; + $classname = $node->children[0]->children[0]->content; - $head = "<div class=\"classsynopsis\">class <span class=\"classname\">$classname</span> {\n<div class=\"classcontents\">"; - $foot = "</div>}\n</div>"; - $body = ""; - - for ($i = 1; $i < count($node->children); $i++) { - $k = $node->children[$i]; - - switch ($k->tagname) { - case 'constructorsynopsis': - case 'methodsynopsis': - $body .= format_params($k); - break; - case 'fieldsynopsis': - $body .= "<div class=\"fieldsynopsis\"><span class=\"type\">" . - $k->children[0]->content . "</span> <span class=\"varname\">" . - $k->children[1]->content . "</span></div>\n"; - break; - } - } + $head = "<div class=\"classsynopsis\">class <span class=\"classname\">$classname</span> {\n<div class=\"classcontents\">"; + $foot = "</div>}\n</div>"; + $body = ""; + + for ($i = 1; $i < count($node->children); $i++) { + $k = $node->children[$i]; + + switch ($k->tagname) { + case 'constructorsynopsis': + case 'methodsynopsis': + $body .= format_params($k); + break; + case 'fieldsynopsis': + $body .= "<div class=\"fieldsynopsis\"><span class=\"type\">" . + $k->children[0]->content . "</span> <span class=\"varname\">" . + $k->children[1]->content . "</span></div>\n"; + break; + } + } - return $head . $body . $foot; + return $head . $body . $foot; } function format_funcsynopsis($node) { - $html = "<div class=\"funcsynopsis\">"; + $html = "<div class=\"funcsynopsis\">"; - /* for each prototype in the synopsis */ - for ($proto = 0; $proto < count($node->children); $proto++) { - $p = $node->children[$proto]; - - if ($p->tagname != 'funcprototype') - continue; - - if (isset($p->attributes['role'])) { - $role = $node->attributes['role']; - } else { - $role = 'php'; - } - - $funcdef = $p->children[0]; - $rettype = ""; - $funcname = ""; - - for ($i = 0; $i < count($funcdef->children); $i++) { - $k = $funcdef->children[$i]; - switch($k->tagname) { - case '': - $rettype = $k->content; - break; - case 'function': - $funcname = $k->content; - break; - } - } - - if ($rettype == '') { - $rettype = 'void'; - } - - - $html .= "<div class=\"funcprototype\"><span class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>"; - - $params = ""; - $optclose = ""; - - for ($i = 1; $i < count($p->children); $i++) { - $def = $p->children[$i]; - if ($def->tagname != 'paramdef') { - continue; - } - $paramhtml = ""; - $paramtype = ""; - $param = null; - - for ($j = 0; $j < count($def->children); $j++) { - $k = $def->children[$j]; - switch($k->tagname) { - case 'parameter': - $param = $k; - break; - case 'enumname': - $paramtype = "<span class=\"enumname\">{$k->content}</enumname>"; - break; - case '': - if (strlen($paramtype) == 0) - $paramtype = $k->content; - break; - } - } - if ($paramtype == '') { - $paramtype = 'void'; - } - - if (count($param->children) > 1) { - $param = $param->children[1]; - $optional = true; - } else { - $optional = false; - } - $paramname = trim($param->content); - - if (strlen($params)) { - $paramhtml .= ','; - } - if ($optional) { - $paramhtml = '[' . $paramhtml; - $optclose .= ']'; - if (strlen($params)) { - $paramhtml = ' ' . $parmhtml; - } - } - - if (strlen($paramhtml)) { - $paramhtml .= ' '; - } - - $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' . $paramtype . '</span>'; - - switch ($role) { - case 'c': - break; - default: - if ($paramname && $paramname{0} == '&') { - $paramname = '&$' . substr($paramname, 1); - } else { - $paramname = '$' . $paramname; - } - } - - $paramhtml .= ' <span class=\"parameter\">' . $paramname . '</span></span>'; + /* for each prototype in the synopsis */ + for ($proto = 0; $proto < count($node->children); $proto++) { + $p = $node->children[$proto]; + + if ($p->tagname != 'funcprototype') + continue; + + if (isset($p->attributes['role'])) { + $role = $node->attributes['role']; + } else { + $role = 'php'; + } + + $funcdef = $p->children[0]; + $rettype = ""; + $funcname = ""; + + for ($i = 0; $i < count($funcdef->children); $i++) { + $k = $funcdef->children[$i]; + switch($k->tagname) { + case '': + $rettype = $k->content; + break; + case 'function': + $funcname = $k->content; + break; + } + } + + if ($rettype == '') { + $rettype = 'void'; + } + + + $html .= "<div class=\"funcprototype\"><span class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>"; + + $params = ""; + $optclose = ""; + + for ($i = 1; $i < count($p->children); $i++) { + $def = $p->children[$i]; + if ($def->tagname != 'paramdef') { + continue; + } + $paramhtml = ""; + $paramtype = ""; + $param = null; + + for ($j = 0; $j < count($def->children); $j++) { + $k = $def->children[$j]; + switch($k->tagname) { + case 'parameter': + $param = $k; + break; + case 'enumname': + $paramtype = "<span class=\"enumname\">{$k->content}</enumname>"; + break; + case '': + if (strlen($paramtype) == 0) + $paramtype = $k->content; + break; + } + } + if ($paramtype == '') { + $paramtype = 'void'; + } + + if (count($param->children) > 1) { + $param = $param->children[1]; + $optional = true; + } else { + $optional = false; + } + $paramname = trim($param->content); + + if (strlen($params)) { + $paramhtml .= ','; + } + if ($optional) { + $paramhtml = '[' . $paramhtml; + $optclose .= ']'; + if (strlen($params)) { + $paramhtml = ' ' . $parmhtml; + } + } + + if (strlen($paramhtml)) { + $paramhtml .= ' '; + } + + $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' . $paramtype . '</span>'; + + switch ($role) { + case 'c': + break; + default: + if ($paramname && $paramname{0} == '&') { + $paramname = '&$' . substr($paramname, 1); + } else { + $paramname = '$' . $paramname; + } + } + + $paramhtml .= ' <span class=\"parameter\">' . $paramname . '</span></span>'; - $params .= $paramhtml; - } + $params .= $paramhtml; + } - $html .= '(' . $params . $optclose . ")</div>"; - } + $html .= '(' . $params . $optclose . ")</div>"; + } - return $html . "</div>"; + return $html . "</div>"; } http://cvs.php.net/diff.php/livedocs/xml_classes.php?r1=1.2&r2=1.3&ty=u Index: livedocs/xml_classes.php diff -u livedocs/xml_classes.php:1.2 livedocs/xml_classes.php:1.3 --- livedocs/xml_classes.php:1.2 Sat Jan 17 06:34:07 2004 +++ livedocs/xml_classes.php Mon Feb 16 12:54:59 2004 @@ -1,5 +1,5 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ @@ -18,189 +18,189 @@ // | Two XML handling classes for the docbook to html transformation | // +----------------------------------------------------------------------+ // -// $Id: xml_classes.php,v 1.2 2004/01/17 11:34:07 nlopess Exp $ +// $Id: xml_classes.php,v 1.3 2004/02/16 17:54:59 derick Exp $ class Node { /* {{{ */ - var $tagname = ""; - var $attributes = array(); - var $children = array(); - var $parent = null; - var $index = 0; - var $content = ""; - var $nodeid = 0; - - function transform($map) - { - if (strlen($this->tagname) == 0) { - return htmlspecialchars($this->content, ENT_NOQUOTES); - } - - $tagname = 'div'; - $attributes = $this->attributes; - $attributes['class'] = $this->tagname; - - /* do we match any of the patterns in the map ? */ - foreach ($map as $mapent) { - if ($mapent[0][0] == $this->tagname) { - $n =& $this->parent; - $match = true; - for ($i = 1; $i < count($mapent[0]); $i++) { - if ($n->tagname != $mapent[0][$i]) { - $match = false; - break; - } - $n =& $n->parent; - } - if ($match) { - if (is_callable($mapent[1])) { - return call_user_func($mapent[1], $this); - } else { - $tagname = $mapent[1]; - } - } - } - } - - if (isset($this->attributes['id'])) { - $anchor = sprintf('<a name="%s"></a>', $this->attributes['id']); - } else { - $anchor = ''; - } - - if (strlen($tagname)) { - $xml = '<' . $tagname; - foreach ($attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - } else { - $xml = ''; - } - - $content = ""; - - if (count($this->children) == 0) { - - if (strlen($tagname) == 0) { - return ''; - } - - if (strlen($this->content)) { - $content = htmlspecialchars($this->content, ENT_NOQUOTES); - } - } else { - for ($i = 0; $i < count($this->children); $i++) { - $child = $this->children[$i]; - $content .= $child->transform($map); - } - } - - if (strlen($tagname)) { - $xml .= '>'; - } - - if ($tagname == 'th' && strlen($content) == 0) { - $content = ' '; - } - - $xml .= $anchor; - $xml .= $content; - if (strlen($tagname)) { - $xml .= '</' . $tagname . '>'; - } - - return $xml; - } - - function &select_node($id) - { - if (isset($this->attributes['id']) && $this->attributes['id'] == $id) { - return $node; - } - // look for children that match - for ($i = 0; $i < count($this->children); $i++) { - $x =& $this->select_node($this->children[$i], $id); - if (is_object($x)) { - return $x; - } - } - return null; - } - - function Node($tagname, $attributes) - { - static $nodeid = 0; - - $this->nodeid = $nodeid++; - $this->tagname = $tagname; - $this->attributes = $attributes; - } - - function set_parent(&$parent) - { - $this->parent =& $parent; - $this->index = count($parent->children); - $parent->children[$this->index] =& $this; - } - - function compress() - { - if (count($this->children) == 1 && $this->children[0]->tagname == '') { - $this->content = $this->children[0]->content; - $this->children = array(); - } - } - - function as_xml() - { - if (strlen($this->tagname) == 0) { - return htmlspecialchars($this->content, ENT_NOQUOTES); - } - - $xml = '<' . $this->tagname; - foreach ($this->attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - if (count($this->children) == 0) { - if (strlen($this->content) == 0) { - $xml .= '/>'; - } else { - $xml .= '>' . htmlspecialchars($this->content, ENT_NOQUOTES) . '</' . $this->tagname . '>'; - } - } else { - $xml .= '>'; - for ($i = 0; $i < count($this->children); $i++) { - $xml .= $this->children[$i]->as_xml(); - } - $xml .= '</' . $this->tagname . '>'; - } - return $xml; - } - - function add_child(&$child) - { - if (count($this->children) == 0 && strlen($this->content)) { - if (strlen(trim($this->content)) > 0) { - // promote content to an anonymous cdata node - $node = new Node("", array()); - $node->content = $this->content; - $node->set_parent($this); - } - $this->content = ""; - } - $child->set_parent($this); - } - - function add_cdata($data) - { - if (count($this->children) == 0) { - $this->content .= $data; - } else { - $node = new Node("", array()); - $node->content = $data; - $this->add_child($node); - } - } + var $tagname = ""; + var $attributes = array(); + var $children = array(); + var $parent = null; + var $index = 0; + var $content = ""; + var $nodeid = 0; + + function transform($map) + { + if (strlen($this->tagname) == 0) { + return htmlspecialchars($this->content, ENT_NOQUOTES); + } + + $tagname = 'div'; + $attributes = $this->attributes; + $attributes['class'] = $this->tagname; + + /* do we match any of the patterns in the map ? */ + foreach ($map as $mapent) { + if ($mapent[0][0] == $this->tagname) { + $n =& $this->parent; + $match = true; + for ($i = 1; $i < count($mapent[0]); $i++) { + if ($n->tagname != $mapent[0][$i]) { + $match = false; + break; + } + $n =& $n->parent; + } + if ($match) { + if (is_callable($mapent[1])) { + return call_user_func($mapent[1], $this); + } else { + $tagname = $mapent[1]; + } + } + } + } + + if (isset($this->attributes['id'])) { + $anchor = sprintf('<a name="%s"></a>', $this->attributes['id']); + } else { + $anchor = ''; + } + + if (strlen($tagname)) { + $xml = '<' . $tagname; + foreach ($attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + } else { + $xml = ''; + } + + $content = ""; + + if (count($this->children) == 0) { + + if (strlen($tagname) == 0) { + return ''; + } + + if (strlen($this->content)) { + $content = htmlspecialchars($this->content, ENT_NOQUOTES); + } + } else { + for ($i = 0; $i < count($this->children); $i++) { + $child = $this->children[$i]; + $content .= $child->transform($map); + } + } + + if (strlen($tagname)) { + $xml .= '>'; + } + + if ($tagname == 'th' && strlen($content) == 0) { + $content = ' '; + } + + $xml .= $anchor; + $xml .= $content; + if (strlen($tagname)) { + $xml .= '</' . $tagname . '>'; + } + + return $xml; + } + + function &select_node($id) + { + if (isset($this->attributes['id']) && $this->attributes['id'] == $id) { + return $node; + } + // look for children that match + for ($i = 0; $i < count($this->children); $i++) { + $x =& $this->select_node($this->children[$i], $id); + if (is_object($x)) { + return $x; + } + } + return null; + } + + function Node($tagname, $attributes) + { + static $nodeid = 0; + + $this->nodeid = $nodeid++; + $this->tagname = $tagname; + $this->attributes = $attributes; + } + + function set_parent(&$parent) + { + $this->parent =& $parent; + $this->index = count($parent->children); + $parent->children[$this->index] =& $this; + } + + function compress() + { + if (count($this->children) == 1 && $this->children[0]->tagname == '') { + $this->content = $this->children[0]->content; + $this->children = array(); + } + } + + function as_xml() + { + if (strlen($this->tagname) == 0) { + return htmlspecialchars($this->content, ENT_NOQUOTES); + } + + $xml = '<' . $this->tagname; + foreach ($this->attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + if (count($this->children) == 0) { + if (strlen($this->content) == 0) { + $xml .= '/>'; + } else { + $xml .= '>' . htmlspecialchars($this->content, ENT_NOQUOTES) . '</' . $this->tagname . '>'; + } + } else { + $xml .= '>'; + for ($i = 0; $i < count($this->children); $i++) { + $xml .= $this->children[$i]->as_xml(); + } + $xml .= '</' . $this->tagname . '>'; + } + return $xml; + } + + function add_child(&$child) + { + if (count($this->children) == 0 && strlen($this->content)) { + if (strlen(trim($this->content)) > 0) { + // promote content to an anonymous cdata node + $node = new Node("", array()); + $node->content = $this->content; + $node->set_parent($this); + } + $this->content = ""; + } + $child->set_parent($this); + } + + function add_cdata($data) + { + if (count($this->children) == 0) { + $this->content .= $data; + } else { + $node = new Node("", array()); + $node->content = $data; + $this->add_child($node); + } + } } /* }}} */ @@ -209,126 +209,126 @@ class DocBookToHTML { /* {{{ */ - var $html = ""; - var $top = null; - var $current = null; - - function DocBookToHTML($xml, $id = null) - { - if (strlen($xml) == 0) { - return; - } - - $p = xml_parser_create(); - xml_set_object($p, $this); - xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($p, 'start_elem', 'end_elem'); - xml_set_character_data_handler($p, 'cdata'); - - if (!xml_parse($p, $xml, true)) { - printf("XML: %d:%d %s\n", - xml_get_current_line_number($p), - xml_get_current_column_number($p), - xml_error_string(xml_get_error_code($p)) - ); - $lines = explode("\n", $xml); - $l = xml_get_current_line_number($p); - echo "\nLine: $l is \n" . htmlentities($lines[$l-1]) . "\n"; - echo htmlentities($xml); - } - xml_parser_free($p); - - if ($id !== null) { - $newtop = $this->top->select_node($id); - if (is_object($newtop)) { - $this->top = $newtop; - $this->top->parent = null; - } - } - } - - /* apply a transformation map to content */ - function transform($map) - { - /* pre-parse the map */ - - if (!is_object($this->top)) { - return "<div class=\"warning\">XML document contained no data</div>"; - } - - $pmap = array(); - foreach ($map as $pat => $rep) { - $h = array_reverse(explode('/', $pat)); - $pmap[] = array($h, $rep); - } - return $this->top->transform($pmap); - } - - /* returns structure as XML */ - function as_xml() - { - return $this->_as_xml($this->top); - } - - function _as_xml(&$node) - { - if (strlen($node->tagname) == 0) { - return htmlspecialchars($node->content, ENT_NOQUOTES); - } - - $xml = '<' . $node->tagname; - foreach ($node->attributes as $name => $value) { - $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; - } - if (count($node->children) == 0) { - if (strlen($node->content) == 0) { - $xml .= '/>'; - } else { - $xml .= '>' . htmlspecialchars($node->content, ENT_NOQUOTES) . '</' . $node->tagname . '>'; - } - } else { - $xml .= '>'; - for ($i = 0; $i < count($node->children); $i++) { - $xml .= $this->_as_xml($node->children[$i]); - } - $xml .= '</' . $node->tagname . '>'; - } - return $xml . "<!-- $node->nodeid -->"; - } - - function start_elem($parser, $tagname, $attributes) - { - /* create a new node as a child of the current node */ - $node = new Node($tagname, $attributes); - - if ($this->top === null) { - /* set the top node */ - $this->top =& $node; - $this->current =& $node; - } else { - /* child of current */ - $this->current->add_child($node); - $this->current =& $node; - } - } - - function end_elem($parser, $tagname) - { - /* pop up to parent of the current node */ - if ($this->current === null) { - return; - } - /* optimize the node; if it only contains a single cdata (anonymous) node, - * compress that node into the content */ - $this->current->compress(); - - $this->current = &$this->current->parent; - } - - function cdata($parser, $data) - { - $this->current->add_cdata($data); - } + var $html = ""; + var $top = null; + var $current = null; + + function DocBookToHTML($xml, $id = null) + { + if (strlen($xml) == 0) { + return; + } + + $p = xml_parser_create(); + xml_set_object($p, $this); + xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); + xml_set_element_handler($p, 'start_elem', 'end_elem'); + xml_set_character_data_handler($p, 'cdata'); + + if (!xml_parse($p, $xml, true)) { + printf("XML: %d:%d %s\n", + xml_get_current_line_number($p), + xml_get_current_column_number($p), + xml_error_string(xml_get_error_code($p)) + ); + $lines = explode("\n", $xml); + $l = xml_get_current_line_number($p); + echo "\nLine: $l is \n" . htmlentities($lines[$l-1]) . "\n"; + echo htmlentities($xml); + } + xml_parser_free($p); + + if ($id !== null) { + $newtop = $this->top->select_node($id); + if (is_object($newtop)) { + $this->top = $newtop; + $this->top->parent = null; + } + } + } + + /* apply a transformation map to content */ + function transform($map) + { + /* pre-parse the map */ + + if (!is_object($this->top)) { + return "<div class=\"warning\">XML document contained no data</div>"; + } + + $pmap = array(); + foreach ($map as $pat => $rep) { + $h = array_reverse(explode('/', $pat)); + $pmap[] = array($h, $rep); + } + return $this->top->transform($pmap); + } + + /* returns structure as XML */ + function as_xml() + { + return $this->_as_xml($this->top); + } + + function _as_xml(&$node) + { + if (strlen($node->tagname) == 0) { + return htmlspecialchars($node->content, ENT_NOQUOTES); + } + + $xml = '<' . $node->tagname; + foreach ($node->attributes as $name => $value) { + $xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"'; + } + if (count($node->children) == 0) { + if (strlen($node->content) == 0) { + $xml .= '/>'; + } else { + $xml .= '>' . htmlspecialchars($node->content, ENT_NOQUOTES) . '</' . $node->tagname . '>'; + } + } else { + $xml .= '>'; + for ($i = 0; $i < count($node->children); $i++) { + $xml .= $this->_as_xml($node->children[$i]); + } + $xml .= '</' . $node->tagname . '>'; + } + return $xml . "<!-- $node->nodeid -->"; + } + + function start_elem($parser, $tagname, $attributes) + { + /* create a new node as a child of the current node */ + $node = new Node($tagname, $attributes); + + if ($this->top === null) { + /* set the top node */ + $this->top =& $node; + $this->current =& $node; + } else { + /* child of current */ + $this->current->add_child($node); + $this->current =& $node; + } + } + + function end_elem($parser, $tagname) + { + /* pop up to parent of the current node */ + if ($this->current === null) { + return; + } + /* optimize the node; if it only contains a single cdata (anonymous) node, + * compress that node into the content */ + $this->current->compress(); + + $this->current = &$this->current->parent; + } + + function cdata($parser, $data) + { + $this->current->add_cdata($data); + } } /* }}} */