Loading...
 
Skip to main content

Improving PDF TOCs with large wiki documents using mix of TOC and MAKETOC

Status
Closed
Subject
Improving PDF TOCs with large wiki documents using mix of TOC and MAKETOC
Version
12.x
Category
  • Patch
Feature
Wiki Structure (book & table of content)
Resolution status
Fixed or Solved
Submitted by
larryg
Lastmod by
lindon
Rating
(0)
Related-to
Description

I do not know how to contribute code, but have developed the following "fix" that works to create TOCs when using the >Print Current Document feature in TW. This fixes the problem with the TOC growing to enormous length on a large page with each new section TOC being appended to the previous section's TOC. This fix has worked across many major versions.

File: tikiwiki/lib/parser/parserlib.php
Insertion point: in 12.0 line 2814; in 12.2 line 2967

Insert IMMEDIATELY BEFORE the following existing code:

Copy to clipboard
if (!empty($maketoc)) { $maketoc = $maketoc_header.$maketoc.$maketoc_footer; }


Inserted code:

Copy to clipboard
//=====larryg -- beginning of custom code to make TOC and MAKETOC work properly in tandem global $TOC_newstring, $TOC_oldstring ; $TOC_newstring = $maketoc ; //===== get a copy of the newest TOC before we do anything to it if ( strpos($maketoc, $TOC_oldstring) ) // larryg - if this MAKETOC contains previous chapter's TOC entries, remove that portion of the string { $maketoc = substr($maketoc, 0 , strpos($maketoc, $TOC_oldstring)).substr($maketoc, strpos($maketoc, $TOC_oldstring)+ strlen($TOC_oldstring)) ; } //prepare this chapter's TOC entry to be compared with the next chapter's string] $head_string = '<li><a href=' ; $tail_string = '<!--toc-->' ; if ( strpos($TOC_newstring, $head_string ) && strpos($TOC_newstring, $tail_string) ) { $TOC_newstring = substr($TOC_newstring, strpos($TOC_newstring, $head_string) ) ; // trim unwanted stuff from the beginning of the string // $maketoc_header = 'PRESTRINGFOUND'.$maketoc_header ; $TOC_newstring = substr($TOC_newstring, 0, (strpos($TOC_newstring, $tail_string) -5)) ; // trim the stuff from the tail of the string </ul></li></ul> // $maketoc_footer = 'POSTRINGFOUND' ; $TOC_oldstring = $TOC_newstring ; } //=====larryg -- end of custom code for TOC and MAKETOC

Please feel free to apply/use as you see appropriate,

-larryg


See comments to this item.
In addition, a show.t.o instance has been created where the issue is reproduced:

http://larryg-10847-5405.show.tikiwiki.org/tiki-print_multi_pages.php?printstructures=%255B%25221%2522%255D&find=&print=Print

u: admin
p: 12345

As you can see, the table of contents in Chapter 2 ("3.2" in the numbering of the single html) shows the issue.
After applying your patch, I get the same issue still in this example.

You can test locally if you want by means of downloading a snapshot of the show instance.

Solution
I'm guessing this was fixed with r52327 so I am closing this report. Please re-open if any issues.
Importance
5
Easy to solve?
8
Priority
40
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
5405
Created
Wednesday 06 August, 2014 13:59:23 UTC
by larryg
LastModif
Saturday 14 November, 2015 02:03:46 UTC


Show PHP error messages