> Hey Nuno,
>
> You're using sqlite_array_query() where you could just use
> sqlite_single_query():

Done.


> What exactly was the problem that you fixed in make_function_link, and
> how did you fix it?

make_function_link was a big confusion and slow. I've cleaned it up and I'm
using just a DB query instead of two. (it was calling lookup_title() and
I've removed that call)
It will also fetch the english description if the translated is not
avaliable.

Attached is the corrected patch.
It also fixes a small bug I've found when displaying the messages for
outdated translation (if the current page is using the callback DB);
and doesn't link a function (when highlighting PHP code) if the
current_page=function.


Nuno


> Thanks,
>
> --Wez.
>
> > -----Original Message-----
> > From: Nuno Lopes [mailto:[EMAIL PROTECTED]
> > Sent: 08 May 2004 12:31
> > To: PHPdoc
> > Subject: [PHP-DOC] [PATCH] several bug fix in livedocs
> >
> > Here is one more patch for livedocs.
> > It address the following issues:
> >  * Fetch english entities if other's languages aren't avaliable;
> >  * Small bug in load_xml_doc(): replace pre-defined entites before
> > bind_entities();
> >  * Re-writen make_function_link(): there was a problem because of DOM
> > extension;
> >  * Fix problems of UpPeRcAsE IDs: turn everything lowercase
> > when building;
> >  * Implemented forgotten &livedocs.published; entity.
> >
> > Nuno
Index: livedoc.php
===================================================================
RCS file: /repository/livedocs/livedoc.php,v
retrieving revision 1.103
diff -u -r1.103 livedoc.php
--- livedoc.php 7 May 2004 13:32:58 -0000       1.103
+++ livedoc.php 9 May 2004 09:19:53 -0000
@@ -127,7 +127,7 @@
 }
 
 /* Checks if translated file is updated */
-if ($lang != 'en' && isset($lang_rev)) {
+if ($lang != 'en' && $lang_rev) {
 
        /* get english file revision */
        $data = @file_get_contents(FALLBACK_BASE . $filename);
@@ -349,6 +349,19 @@
                        $entities['&' . $r[0] . ';'] = $r[1];
                }
 
+               /* If language!=English and entity was not found */
+               if($GLOBALS['lang'] != 'en') {
+                       foreach($entities_to_find as $ent) {
+                               if(!isset($entities['&' . $ent . ';'])) {
+                                       $q = sqlite_single_query($GLOBALS['fb_idx'], 
"SELECT value FROM ents WHERE entid='$ent'");
+                                       if (!$q) {
+                                               break;
+                                       }
+                                       $entities['&' . $ent . ';'] = $q;
+                               }
+                       }
+               }
+
                /* substitute */
                $data = strtr($data, $entities);
 
@@ -395,6 +408,7 @@
        $data = preg_replace('@<!--\s+.*\s-->@Usm', '', $data);
 
        /* Replace entities */
+       $data = str_replace($search, $replace, $data);
        $data = bind_entities($data);
 
        /* catch any undefined entities */
@@ -413,8 +427,6 @@
                $data = preg_replace('/&([a-zA-Z0-9-]+)\.([a-zA-Z0-9.-]+);/sm', 
'<phpdoc_include ref="\\1.\\2"/>', $data);
        }
 
-       $data = str_replace($search, $replace, $data);
-
        $page = new DocBookToHTML($data);
 
 
@@ -505,31 +517,35 @@
 function make_function_link($ref) 
 {
        $parts = explode('.', $ref);
-
        $stag = 'function';
        $etag = 'function';
 
-       if (count($parts) == 4) {
-               $id = 'function.' . $parts[3];
-               $func_name = lookup_title($id);
-       } elseif ($parts[3] == 'class' && count($parts) == 5) {
+       if (count($parts) == 5 && $parts[3] == 'class') {
                $id = 'class.' . $parts[4];
-               $func_name = strtr($parts[4], array('-'=>'_'));
                $stag = "xref linkend=\"$id\"";
-               $etag = "xref";
-       } else {
-               /* some weird node type we don't understand */
-               $id = $ref;
-               $func_name = 'Unknown ??';
-       }
-       
-       if($parts[3] == 'class') {
-               $title = ' - ' . lookup_title($id) . ' class';
-       } else {
-               $title = ' - ' . bind_entities(sqlite_single_query($GLOBALS['idx'], 
"SELECT descr from toc where docbook_id='$id'"));
+               $etag = 'xref';
+               $name = strtoupper($parts[4]);
+               $title = "$name class";
+       } else {
+               $id = 'function.' . strtolower($parts[3]);
+               $q = sqlite_array_query($GLOBALS['idx'], "SELECT title,descr from toc 
where docbook_id='$id'", SQLITE_NUM);
+
+               if($q) {
+                       $name = $q[0][0];
+                       $title = $q[0][1];
+               } else {
+                       $name = $id;
+                       $title = '???';
+               }
+
+               /* Fetch english description */
+               if($GLOBALS['lang'] != 'en' && $name == $title) {
+                       $title = sqlite_single_query($GLOBALS['fb_idx'], "SELECT descr 
from toc where docbook_id='$id'");
+               }
+
        }
 
-       return "<div class=\"function_link\"><$stag>$func_name</$etag>$title</div>";
+       return "<div class=\"function_link\"><$stag>$name</$etag> - " . 
bind_entities($title) . '</div>';
 }
 
 function make_xref($ref) 
Index: mk_phpdoc.php
===================================================================
RCS file: /repository/livedocs/mk_phpdoc.php,v
retrieving revision 1.8
diff -u -r1.8 mk_phpdoc.php
--- mk_phpdoc.php       1 May 2004 09:46:46 -0000       1.8
+++ mk_phpdoc.php       9 May 2004 09:19:54 -0000
@@ -46,7 +46,7 @@
                                                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);
+                                                       $docbook_id = 'function.' . 
strtolower(substr($f, 0, -4));
                                                }
                                                break;
                                        case 'language' :
Index: mkindex.php
===================================================================
RCS file: /repository/livedocs/mkindex.php,v
retrieving revision 1.32
diff -u -r1.32 mkindex.php
--- mkindex.php 27 Apr 2004 14:43:28 -0000      1.32
+++ mkindex.php 9 May 2004 09:19:54 -0000
@@ -96,7 +96,7 @@
                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)) . "');";
+                       $this->data .= "INSERT INTO idents VALUES ('". 
strtolower($this->last_id) . "', {$this->fileid}, '" . 
sqlite_escape_string(trim($this->cdata)) . "');";
 
                        $this->last_id = false;
                }
Index: mktoc.php
===================================================================
RCS file: /repository/livedocs/mktoc.php,v
retrieving revision 1.8
diff -u -r1.8 mktoc.php
--- mktoc.php   16 Feb 2004 17:54:59 -0000      1.8
+++ mktoc.php   9 May 2004 09:19:54 -0000
@@ -68,7 +68,7 @@
                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";
+               echo "INSERT INTO toc VALUES ({$this->last_id}, {$level}, 
{$parent_id}, '".strtolower($docbook_id)."', '{$docbook_parent_id}', '{$path}', 
'{$title}', '{$title}');\n";
                $this->last_id++;
        }
 
Index: style_mapping.php
===================================================================
RCS file: /repository/livedocs/style_mapping.php,v
retrieving revision 1.13
diff -u -r1.13 style_mapping.php
--- style_mapping.php   8 May 2004 09:20:43 -0000       1.13
+++ style_mapping.php   9 May 2004 09:19:54 -0000
@@ -204,7 +204,7 @@
 
 function format_pubdate($node) 
 {
-       return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, 
$node->content);
+       return sprintf('<div class="%s">' . bind_entities('&livedocs.published;') . 
'</div>', $node->tagname, $node->content);
 }
 
 function format_ulink($node) 
@@ -248,7 +248,7 @@
                        '->' => '-');
 
        $itemid = strtr($node->content, $replace);
-       $itemid = strtr($itemid, array('---' => '-'));
+       $itemid = strtolower(strtr($itemid, array('---' => '-')));
 
        $class = 'function';
        if (isset($node->attributes['class'])) {
@@ -274,9 +274,12 @@
 {
        global $lang;
 
-       $link = strtr($matches[1], array('_' => '-'));
-       $link = WEBBASE . (FORCE_DYNAMIC ? "?l=$lang&q=function.$link" : 
"$lang/function.$link.html");
-       return '<a class="phpfunc" href="' . $link . '">' . $matches[1] . '</a>(';
+       $link = 'function.' . strtr($matches[1], array('_' => '-'));
+       if ($link == $GLOBALS['current_page'])
+               return $matches[0];
+
+       $link = WEBBASE . (FORCE_DYNAMIC ? "?l=$lang&q=$link" : "$lang/$link.html");
+       return '<a class="phpfunc" href="' . $link . '">' . $matches[1] . 
'</a></span>' . $matches[3];
 }
 
 function format_listing($node) 

Reply via email to