iliaa           Fri Jun 17 18:10:18 2005 EDT

  Modified files:              
    /livedocs   livedoc_funcs.php mkindex.php 
  Log:
  Added some warnings on common errors.
  Fixed bug #33358 (Use TITLEABBREV in table of contents).
  
  
http://cvs.php.net/diff.php/livedocs/livedoc_funcs.php?r1=1.26&r2=1.27&ty=u
Index: livedocs/livedoc_funcs.php
diff -u livedocs/livedoc_funcs.php:1.26 livedocs/livedoc_funcs.php:1.27
--- livedocs/livedoc_funcs.php:1.26     Thu Feb 10 07:23:32 2005
+++ livedocs/livedoc_funcs.php  Fri Jun 17 18:10:16 2005
@@ -160,16 +160,20 @@
 
        $nolink = FALSE;
 
-       $title = lookup_title($item);
-       $fulltitle = $title;
-       if (NAV_TRUNCATE && isset($title{NAV_TRUNCATE}) ) {
-               $ftitle = " title='$title'";
-               $title = substr($title, 0, NAV_TRUNCATE-3). '...';
+       list($fulltitle, $title) = lookup_title($item, 1);
+       
+       if ($title) { /* got abbreviated title */
+               $ftitle = " title='$fulltitle'";
+       } else if (NAV_TRUNCATE && isset($fulltitle{NAV_TRUNCATE})) {
+               $ftitle = " title='$fulltitle'";
+               $title = substr($fulltitle, 0, NAV_TRUNCATE-3). '...';
        } else {
                $ftitle = "";
-               if (!$title) {
+               if (!$fulltitle) {
                        $title = $item . ' [?]';
                        $nolink = TRUE;
+               } else {
+                       $title = $fulltitle;
                }
        }
        
@@ -316,7 +320,7 @@
        return $inner . "</div>";
 }
 
-function lookup_title($nodeid) 
+function lookup_title($nodeid, $get_abbr=0)
 {
        static $ids = array();
 
@@ -335,18 +339,23 @@
        }
 
        /* See if the title lookup is in the cache already */
-       if (isset($ids[$nodeid])) {
-               return $ids[$nodeid];
+       if (!isset($ids[$nodeid])) {
+               /* It's not, so we try to resolve it from the DB */
+               $safeid = sqlite_escape_string($nodeid);
+               if (!($ids[$nodeid] =  sqlite_array_query($GLOBALS['idx'], 
"SELECT title, abbrtitle from idents where id='$safeid'", SQLITE_NUM)) && 
isset($GLOBALS['fb_idx'])) {
+                       $ids[$nodeid] = sqlite_array_query($GLOBALS['fb_idx'], 
"SELECT title, abbrtitle from idents where id='$safeid'", SQLITE_NUM);
+               }
        }
 
-       /* It's not, so we try to resolve it from the DB */
-       $safeid = sqlite_escape_string($nodeid);
-       if (($ids[$nodeid] = sqlite_single_query($GLOBALS['idx'], "SELECT title 
from idents where id='$safeid'"))) {
-               return $ids[$nodeid];
-       } else if (isset($GLOBALS['fb_idx']) && ($ids[$nodeid] = 
sqlite_single_query($GLOBALS['fb_idx'], "SELECT title from idents where 
id='$safeid'"))) {
-               return $ids[$nodeid];
+       if (isset($ids[$nodeid][0])) {
+               if ($get_abbr) {
+                       return $ids[$nodeid][0];
+               } else {
+                       return $ids[$nodeid][0][0];
+               }
        }
-       return null;
+
+       return $get_abbr ? array('','') : null;
 }
 
 /* transform an entity name of the form "reference.XXXX.functions.ID"
http://cvs.php.net/diff.php/livedocs/mkindex.php?r1=1.40&r2=1.41&ty=u
Index: livedocs/mkindex.php
diff -u livedocs/mkindex.php:1.40 livedocs/mkindex.php:1.41
--- livedocs/mkindex.php:1.40   Wed Jun 15 21:11:01 2005
+++ livedocs/mkindex.php        Fri Jun 17 18:10:16 2005
@@ -19,23 +19,23 @@
 // | construct an index                                                   |
 // +----------------------------------------------------------------------+
 //
-// $Id: mkindex.php,v 1.40 2005/06/16 01:11:01 iliaa Exp $
+// $Id: mkindex.php,v 1.41 2005/06/17 22:10:16 iliaa Exp $
 
 
 /* just to be on the safe side */
 set_time_limit(0);
 set_magic_quotes_runtime(0);
 
+if ($argc != 5 || !is_dir($argv[1]) || !is_dir($argv[1] . DIRECTORY_SEPARATOR 
. $argv[2])) {
+       echo "Usage: mkindex.php /path/to/docs lang tmp-dir build-type\n";
+       exit(1);
+}
+
 $DOCS = $argv[1];
 $LANG = $argv[2];
 $TMPDIR = $argv[3];
 $BUILDTYPE = $argv[4];
 
-if (!is_dir($DOCS) || !is_dir($DOCS . DIRECTORY_SEPARATOR . $LANG)) {
-       echo "Usage: mkindex.php /path/to/docs lang tmp-dir build-type\n";
-       exit(1);
-}
-
 require 'mk_' . $BUILDTYPE . '.php';
 
 function entity_replace($data) {
@@ -54,12 +54,15 @@
        return '';
 }
 
+$titles = array('TITLE'=>1, 'REFNAME'=>2, 'QANDAENTRY'=>2, 'VARLISTENTRY'=>2, 
'TITLEABBREV' => 2);
+
 class DocBookXMLFileParser {
        var $fileid = false;
        var $last_id = false;
        var $cdata = null;
        var $data = '';
        var $title_depth = -1;
+       var $incomp = 0;
 
        function DocBookXMLFileParser($filename, $rel, $parser) {
                $this->fileid = $GLOBALS['fileid'];
@@ -87,13 +90,11 @@
        }
 
        function start_elem($parser, $name, $attrs) {
-               static $titles = array('TITLE'=>1, 'REFNAME'=>1, 
'QANDAENTRY'=>1, 'VARLISTENTRY'=>1);
-
                // if there is an ID attribute, record it
                if (isset($attrs['ID'])) {
                        $this->last_id = $attrs['ID'];
                }
-               if ($this->last_id !== false && isset($titles[$name])) {
+               if ($this->last_id !== false && 
isset($GLOBALS['titles'][$name])) {
                        $this->title_depth = 1;
                }
        }
@@ -102,9 +103,30 @@
                if ($this->last_id !== false && $this->title_depth && 
--$this->title_depth == 0) {
                        echo "\tAdded ID {$this->last_id}\n";
 
-                       $this->data .= "INSERT INTO idents VALUES ('" . 
strtolower($this->last_id) . "', {$this->fileid}, '" . 
sqlite_escape_string(str_replace('||amp||', '&', trim($this->cdata))) . "');";
+                       if (!isset($GLOBALS['titles'][$name])) {
+                               if ($this->incomp) {
+                                       $this->data .= "'');";
+                                       $this->incomp = 0;
+                               }
+                               $this->cdata = null;
+                               $this->last_id = false;
+                               return;
+                       }
 
-                       $this->last_id = false;
+                       if ($name != 'TITLEABBREV') {
+                               if ($this->incomp) {
+                                       $this->data .= "'');";
+                               }
+                               $this->data .= "INSERT INTO idents VALUES ('" . 
strtolower($this->last_id) . "', {$this->fileid}, '" . 
sqlite_escape_string(str_replace('||amp||', '&', trim($this->cdata))) . "',";
+                               $this->incomp = 1;
+                       } else {
+                               $this->data .= 
"'".sqlite_escape_string(str_replace('||amp||', '&', trim($this->cdata)))."');";
+                               $this->incomp = 0;
+                       }
+
+                       if ($GLOBALS['titles'][$name] != 1) {
+                               $this->last_id = false;
+                       }
                        $this->cdata = null;
                }
        }
@@ -175,7 +197,12 @@
        xml_parser_free($parser);
 
        if ($p->data) {
-               sqlite_query($idx, $p->data);
+               if ($p->incomp) {
+                       $p->data .= "'');";
+               }
+               if (!sqlite_query($idx, $p->data)) {
+                       exit("Failed Query (". 
sqlite_error_string(sqlite_last_error($idx))."): ".$p->data);
+               }
        }
 }
 
@@ -302,15 +329,15 @@
 @unlink("livedoc-idx.$LANG.sqlite-journal");
 $idx = sqlite_open("livedoc-idx.$LANG.sqlite");
 
+if (!$idx) {
+       die("could not open sqlite database");
+}
+
 /* optimization trick */
 sqlite_query($idx, 'PRAGMA default_synchronous=OFF');
 sqlite_query($idx, 'PRAGMA count_changes=OFF');
 sqlite_query($idx, 'PRAGMA cache_size=100000');
 
-if (!$idx) {
-       die("could not open sqlite database");
-}
-
 $create = <<<SQL
 CREATE TABLE dirs (
        dirid INTEGER PRIMARY KEY,
@@ -327,7 +354,8 @@
 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
+       title TEXT, -- Caption of the identifier for linking purposes
+       abbrtitle TEXT -- Abbreviated title for menus 
 );
 
 CREATE TABLE ents (

Reply via email to