@@ -279,6 +279,9 @@ function document_end(){
279279 // Insert TOC (if required)
280280 $ this ->insert_TOC ();
281281
282+ // Replace local link placeholders
283+ $ this ->insert_locallinks ();
284+
282285 // Build the document
283286 $ this ->finalize_ODTfile ();
284287 }
@@ -478,11 +481,11 @@ protected function insert_TOC() {
478481 $ params = explode (', ' , $ item );
479482
480483 // Only add the heading to the TOC if its <= $max_outline_level
481- if ( $ params [2 ] <= $ max_outline_level ) {
482- $ level = $ params [2 ];
484+ if ( $ params [3 ] <= $ max_outline_level ) {
485+ $ level = $ params [3 ];
483486 $ toc .= '<text:p text:style-name=" ' .$ p_styles [$ level ].'"> ' ;
484487 $ toc .= '<text:a xlink:type="simple" xlink:href="# ' .$ params [0 ].'" text:style-name=" ' .$ stylesLNames [$ level ].'" text:visited-style-name=" ' .$ stylesLNames [$ level ].'"> ' ;
485- $ toc .= $ params [1 ];
488+ $ toc .= $ params [2 ];
486489 $ toc .= '<text:tab/> ' ;
487490 $ page ++;
488491 $ toc .= $ page ;
@@ -500,6 +503,12 @@ protected function insert_TOC() {
500503 $ toc .= '<text:p text:style-name="pagebreak"/> ' ;
501504 }
502505
506+ // Only for debugging
507+ //foreach ($this->toc as $item) {
508+ // $params = explode (',', $item);
509+ // $toc .= '<text:p>'.$params [0].'€'.$params [1].'€'.$params [2].'€'.$params [3].'</text:p>';
510+ //}
511+
503512 // Replace placeholder with TOC content.
504513 $ this ->doc = str_replace ('<text:table-of-content/> ' , $ toc , $ this ->doc );
505514 }
@@ -534,8 +543,8 @@ protected function _buildTOCReferenceID($title) {
534543 * @param string $text the text to display
535544 * @param int $level the nesting level
536545 */
537- function toc_additem ($ refID , $ text , $ level ) {
538- $ item = $ refID .', ' .$ text .', ' . $ level ;
546+ function toc_additem ($ refID , $ hid , $ text , $ level ) {
547+ $ item = $ refID .', ' .$ hid . ' , ' . $ text .', ' . $ level ;
539548 $ this ->toc [] = $ item ;
540549 }
541550
@@ -728,7 +737,7 @@ function header($text, $level, $pos){
728737
729738 // Do not add headings in frames
730739 if ( $ this ->in_div_as_frame == 0 ) {
731- $ this ->toc_additem ($ TOCRef , $ text , $ level );
740+ $ this ->toc_additem ($ TOCRef , $ hid , $ text , $ level );
732741 }
733742 }
734743
@@ -1422,6 +1431,37 @@ function externallink($url, $name = NULL) {
14221431 $ this ->_doLink ($ url ,$ name );
14231432 }
14241433
1434+ /**
1435+ * Replace local links with bookmark references or text
1436+ */
1437+ protected function insert_locallinks () {
1438+ $ matches = array ();
1439+ if ( preg_match ('/<locallink>.+<\/locallink>/ ' , $ this ->doc , $ matches ) === 1 ) {
1440+ foreach ($ matches as $ match ) {
1441+ $ text = substr ($ match , 11 );
1442+ $ text = str_replace ('</locallink> ' , '' , $ text );
1443+ $ page = str_replace (' ' , '_ ' , $ text );
1444+
1445+ $ found = false ;
1446+ foreach ($ this ->toc as $ item ) {
1447+ $ params = explode (', ' , $ item );
1448+ if ( $ page == $ params [1 ] ) {
1449+ $ found = true ;
1450+ $ link = '<text:a xlink:type="simple" xlink:href="# ' .$ params [0 ].'"> ' ;
1451+ $ link .= $ text ;
1452+ $ link .= '</text:a> ' ;
1453+
1454+ $ this ->doc = str_replace ($ match , $ link , $ this ->doc );
1455+ }
1456+ }
1457+
1458+ if ( $ found == false ) {
1459+ $ this ->doc = str_replace ($ match , $ text , $ this ->doc );
1460+ }
1461+ }
1462+ }
1463+ }
1464+
14251465 /**
14261466 * Just print local links
14271467 *
@@ -1432,7 +1472,7 @@ function externallink($url, $name = NULL) {
14321472 */
14331473 function locallink ($ hash , $ name = NULL ){
14341474 $ name = $ this ->_getLinkTitle ($ name , $ hash , $ isImage );
1435- $ this ->doc .= $ name ;
1475+ $ this ->doc .= ' <locallink> ' . $ name. ' </locallink> ' ;
14361476 }
14371477
14381478 /**
0 commit comments