WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 14.07.2021 13:00:20

awuest
Mitglied

CreateToc "Zurück zum Anfang" nach der Tabelle

Hallo liebe Mitstreiter,
kennt ihr eine Möglichkeit den ersten "Zurück zum Anfang" Link gleich nach der erzeugten "Auf dieser Seite..." (also unter "div class toc") Section zu entfernen?

<div class="toc" style="margin:5px;padding:5px;border:1px solid #ccc;">
<a name="toc" style="font-weight:bold;">Auf dieser Seite...</a><br>
<span style="margin-left:20px;"><a href="#toc3">1. Link</a></span><br>
</div>
<a style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">Zurück zum Anfang</a>

Vielen Dank
Andreas

Online

#2 14.07.2021 13:38:02

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Entweder so: Häng mal beim Droplet-Aufruf noch ein &skip=2 (oder &skip=3, je nach Template) ran, also z.B. so

[[CreateToc?float=right&skip=2]]

Dann werden die ersten beiden / die ersten drei Überschriften übergangen, allerdings auch im Inhaltsverzeichnis nicht mit aufgeführt.
Oder im Droplet-Code selbst, Zeile 57

 ( ( $i > 0 && $toplink ) ? '<br /><a href="#toc">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a><br />' : '' ).

da mal die 0 durch 1 oder 2 ersetzen:

 ( ( $i > 1 && $toplink ) ? '<br /><a href="#toc">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a><br />' : '' ).

dann erscheinen alle Headlines auf der Seite im ToC, aber bei den n ersten kein Zurücklink.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

awuest

#3 15.07.2021 18:07:10

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Es klappt leider nicht!!!
Aber sowie es aussieht, ist es nicht Nach der Tabelle, sondern vor dem ersten "Zurück zum Anfang" Link.
Mein Droplet sieht so aus ( + kleine Änderungen)

$toc     = array();
$output  = NULL;
$number  = ( isset($number) ? true     : false );
$skip    = ( isset($skip)   ? $skip    : NULL  ); // skip X headings
$toplink = ( isset($toplink)? $toplink : true  ); // add 'back to top' links
$current = array( '1' => 0 );
$last    = 1;
$dump    = array();
$strings = array(
  'DE' => 'Inhalt...',
  'EN' => 'On this page...',
);
$btt     = array(
  'DE' => 'Zurück zum Anfang',
  'EN' => 'Back to top',
);

preg_match_all( '#<h([1-6]).*>([^<].+)</h[1-6]>#i', $wb_page_data, $matches, PREG_PATTERN_ORDER );

if ( count($matches) ) {
    $found = 0;
    foreach( $matches[2] as $i => $text ) {
        $found++;
        if ( $skip && $found <= $skip ) {
            continue;
        }
        $level = $matches[1][$i]; // current level
        if ( $number ) {
            if ( $level < $last ) {
                for( $n=($level+1); $n<=$last; $n++ ) {
                    unset($current[$n]);
                }
            }
            if ( isset( $current[$level] ) ) {
                $current[$level]++;
            }
            else {
                $current[$level]=1;
            }
            $prefix = array();
            for( $m=1; $m<=$level; $m++ ) {
                if ( ! isset($current[$m] ) ) {
                    $current[$m] = 1;
                }
                $prefix[] = $current[$m];
            }
            $text = implode('.', $prefix ) . ' ' . $text;
        }
        $last  = $level;
        $toc[] = '<span style="margin-left:'
               . ( 10 * ( $level - 1 ) )
               . 'px;"><a href="#toc'.$i.'">'.$text.'</a></span>';
        $wb_page_data = str_replace(
            $matches[0][$i],
            ( ( $i > 1 && $toplink ) ? '<a style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).
            '<a name="toc'.$i.'"> </a>' . $matches[0][$i],
            $wb_page_data
        );
    }

    $output = '<div class="toc" style="margin:5px;padding:5px;border:1px solid #ccc;';
    if ( isset($float) && $float == 'right' ) {
        $output .= ' float:right;';
    }
    $output .= '">'
            . '<a name="toc" style="font-weight:bold;">'
            . ( isset($strings[LANGUAGE]) ? $strings[LANGUAGE] : $strings['EN'] )
            . '</a><br />'
            .  implode( '<br />', $toc )
            .  '</div>';
}

// this removes double 'to top' links if CreateToc is called more than once
//<a href="#toc">Back to top</a><br /><a name="toc1"> </a><br /><a href="#toc">Back to top</a><br /><a name="toc1"> </a>
$regex = '('.preg_replace('~\s~','\\s*',preg_quote('<br /><a href="#toc">Back to top</a><br /><a name="toc','~').'\d+'.preg_quote('"> </a>','~')).'){2,}';
$wb_page_data = preg_replace(
    '~'.$regex.'~',
    '$1',
    $wb_page_data
);

return $output;

Die Ausgabe ist diese:

https://photos.app.goo.gl/5v2M3Eow3atu5n619

Vielleicht habe ich durch meine Änderungen etwas anders ....
Viele Grüße
Andreas

Beitrag geändert von florian (16.07.2021 06:56:59)

Online

#4 16.07.2021 06:59:05

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Ich hatte einen Denkfehler. Der skip-Parameter kann raus.

Ändere die Zeile

( ( $i > 1 && $toplink ) ? '<a style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).

zu

( ( $i > 0 && $toplink ) ? '<a class="toplink'.$i.'" style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).

und füge vor

// this removes double 'to top' links if CreateToc is called more than once

ein:

$wb_page_data = str_replace('<a class="toplink1" style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">Zurück zum Anfang</a>','',$wb_page_data);

Code allein macht nicht glücklich. Jetzt spenden!

Offline

#5 16.07.2021 09:19:24

berny
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Darf ich fragen, warum man $output auf NULL setzt und nicht auf "", wenn er nachher mit einem String gefüllt wird?

Vorteil? Nachteil? Egal?

Offline

#6 16.07.2021 10:47:54

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

sad  habe es probiert, leider ohne Erfolg. Was jetzt passiert: jeder "Zum Anfang" Link bekommt eine class="toplink" der fortlaufend nummeriert wird: toplink1, toplink2 ... usw. Habe jetzt "Trick 17 cool " angewendet indem ich der Seite die body id zuweise und dieser toplink über css ausblende - nicht elegant aber es geht, bin aber für eine andere Lösung sehr dankbar. Vielen Dank, Andreas

Online

#7 16.07.2021 10:51:25

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Hast Du die 2. Zeile, die mit "$wb_page_data" beginnt, an genau der Stelle eingefügt wie beschrieben?
Wichtig ist auch, dass das, was da in den ersten einfachen Anführungszeichen steht, genau dem entspricht, was später nicht mehr auf der Seite erscheinen soll.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#8 16.07.2021 11:07:42

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Das Droplet sieht jetzt so aus:

$toc     = array();
$output  = NULL;
$number  = ( isset($number) ? true     : false );
$skip    = ( isset($skip)   ? $skip    : NULL  ); // skip X headings
$toplink = ( isset($toplink)? $toplink : true  ); // add 'back to top' links
$current = array( '1' => 0 );
$last    = 1;
$dump    = array();
$strings = array(
  'DE' => 'Inhalt...',
  'EN' => 'On this page...',
);
$btt     = array(
  'DE' => 'Zurück zum Anfang',
  'EN' => 'Back to top',
);

preg_match_all( '#<h([1-6]).*>([^<].+)</h[1-6]>#i', $wb_page_data, $matches, PREG_PATTERN_ORDER );

if ( count($matches) ) {
    $found = 0;
    foreach( $matches[2] as $i => $text ) {
        $found++;
        if ( $skip && $found <= $skip ) {
            continue;
        }
        $level = $matches[1][$i]; // current level
        if ( $number ) {
            if ( $level < $last ) {
                for( $n=($level+1); $n<=$last; $n++ ) {
                    unset($current[$n]);
                }
            }
            if ( isset( $current[$level] ) ) {
                $current[$level]++;
            }
            else {
                $current[$level]=1;
            }
            $prefix = array();
            for( $m=1; $m<=$level; $m++ ) {
                if ( ! isset($current[$m] ) ) {
                    $current[$m] = 1;
                }
                $prefix[] = $current[$m];
            }
            $text = implode('.', $prefix ) . ' ' . $text;
        }
        $last  = $level;
        $toc[] = '<span style="margin-left:'
               . ( 10 * ( $level - 1 ) )
               . 'px;"><a href="#toc'.$i.'">'.$text.'</a></span>';
        $wb_page_data = str_replace(
            $matches[0][$i],
            ( ( $i > 0 && $toplink ) ? '<a class="toplink'.$i.'" style="text-align:right; font-weight:bold; display:inherit;" href="#toc" class="ZumAnfang">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).
            '<a name="toc'.$i.'"> </a>' . $matches[0][$i],
            $wb_page_data
        );
    }

    $output = '<div class="toc" style="margin:5px;padding:5px;border:1px solid #ccc;';
    if ( isset($float) && $float == 'right' ) {
        $output .= ' float:right;';
    }
    $output .= '">'
            . '<a name="toc" style="font-weight:bold;">'
            . ( isset($strings[LANGUAGE]) ? $strings[LANGUAGE] : $strings['EN'] )
            . '</a><br />'
            .  implode( '<br />', $toc )
            .  '</div>';
}

$wb_page_data = str_replace('<a class="toplink1" style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;" href="#toc" class="ZumAnfang">Zurück zum Anfang</a>','',$wb_page_data);

// this removes double 'to top' links if CreateToc is called more than once
//<a href="#toc">Back to top</a><br /><a name="toc1"> </a><br /><a href="#toc">Back to top</a><br /><a name="toc1"> </a>
$regex = '('.preg_replace('~\s~','\\s*',preg_quote('<br /><a href="#toc">Back to top</a><br /><a name="toc','~').'\d+'.preg_quote('"> </a>','~')).'){2,}';
$wb_page_data = preg_replace(
    '~'.$regex.'~',
    '$1',
    $wb_page_data
);

return $output;

Online

#9 16.07.2021 11:12:33

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Na ja, siehst Du, da ist doch das Problem.
Der erzeugte Code sieht jetzt so aus:
<a class="toplink1"
style="text-align:right; font-weight:bold; display:inherit;"
href="#toc" class="ZumAnfang">Zurück zum Anfang</a>

Gesucht wird aber nach
<a class="toplink1"
style="text-align:right;font-weight:bold;display:inherit;margin-bottom:-15px;"
href="#toc" class="ZumAnfang">Zurück zum Anfang</a>


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#10 16.07.2021 11:26:38

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Auf ein Neues ;-)

$toc     = array();
$output  = NULL;
$number  = ( isset($number) ? true     : false );
$skip    = ( isset($skip)   ? $skip    : NULL  ); // skip X headings
$toplink = ( isset($toplink)? $toplink : true  ); // add 'back to top' links
$current = array( '1' => 0 );
$last    = 1;
$dump    = array();
$strings = array(
  'DE' => 'Inhalt...',
  'EN' => 'On this page...',
);
$btt     = array(
  'DE' => 'Zurück zum Anfang',
  'EN' => 'Back to top',
);

preg_match_all( '#<h([1-6]).*>([^<].+)</h[1-6]>#i', $wb_page_data, $matches, PREG_PATTERN_ORDER );

if ( count($matches) ) {
    $found = 0;
    foreach( $matches[2] as $i => $text ) {
        $found++;
        if ( $skip && $found <= $skip ) {
            continue;
        }
        $level = $matches[1][$i]; // current level
        if ( $number ) {
            if ( $level < $last ) {
                for( $n=($level+1); $n<=$last; $n++ ) {
                    unset($current[$n]);
                }
            }
            if ( isset( $current[$level] ) ) {
                $current[$level]++;
            }
            else {
                $current[$level]=1;
            }
            $prefix = array();
            for( $m=1; $m<=$level; $m++ ) {
                if ( ! isset($current[$m] ) ) {
                    $current[$m] = 1;
                }
                $prefix[] = $current[$m];
            }
            $text = implode('.', $prefix ) . ' ' . $text;
        }
        $last  = $level;
        $toc[] = '<span style="margin-left:'
               . ( 10 * ( $level - 1 ) )
               . 'px;"><a href="#toc'.$i.'">'.$text.'</a></span>';
        $wb_page_data = str_replace(
            $matches[0][$i],
            ( ( $i > 0 && $toplink ) ? '<a class="toplink'.$i.'" style="text-align:right; font-weight:bold; display:inherit;" href="#toc">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).
            '<a name="toc'.$i.'"> </a>' . $matches[0][$i],
            $wb_page_data
        );
    }

    $output = '<div class="toc" style="margin:5px;padding:5px;border:1px solid #ccc;';
    if ( isset($float) && $float == 'right' ) {
        $output .= ' float:right;';
    }
    $output .= '">'
            . '<a name="toc" style="font-weight:bold;">'
            . ( isset($strings[LANGUAGE]) ? $strings[LANGUAGE] : $strings['EN'] )
            . '</a><br />'
            .  implode( '<br />', $toc )
            .  '</div>';
}

$wb_page_data = str_replace('<a class="toplink1" style="text-align:right;font-weight:bold;display:inherit;" href="#toc">Zurück zum Anfang</a>','',$wb_page_data);

// this removes double 'to top' links if CreateToc is called more than once
//<a href="#toc">Back to top</a><br /><a name="toc1"> </a><br /><a href="#toc">Back to top</a><br /><a name="toc1"> </a>
$regex = '('.preg_replace('~\s~','\\s*',preg_quote('<br /><a href="#toc">Back to top</a><br /><a name="toc','~').'\d+'.preg_quote('"> </a>','~')).'){2,}';
$wb_page_data = preg_replace(
    '~'.$regex.'~',
    '$1',
    $wb_page_data
);

return $output;

Online

#11 16.07.2021 11:27:57

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Letzter Versuch, sonst bin ich raus.

$toc     = array();
$output  = NULL;
$number  = ( isset($number) ? true     : false );
$skip    = ( isset($skip)   ? $skip    : NULL  ); // skip X headings
$toplink = ( isset($toplink)? $toplink : true  ); // add 'back to top' links
$current = array( '1' => 0 );
$last    = 1;
$dump    = array();
$strings = array(
  'DE' => 'Inhalt...',
  'EN' => 'On this page...',
);
$btt     = array(
  'DE' => 'Zurück zum Anfang',
  'EN' => 'Back to top',
);

preg_match_all( '#<h([1-6]).*>([^<].+)</h[1-6]>#i', $wb_page_data, $matches, PREG_PATTERN_ORDER );

if ( count($matches) ) {
    $found = 0;
    foreach( $matches[2] as $i => $text ) {
        $found++;
        if ( $skip && $found <= $skip ) {
            continue;
        }
        $level = $matches[1][$i]; // current level
        if ( $number ) {
            if ( $level < $last ) {
                for( $n=($level+1); $n<=$last; $n++ ) {
                    unset($current[$n]);
                }
            }
            if ( isset( $current[$level] ) ) {
                $current[$level]++;
            }
            else {
                $current[$level]=1;
            }
            $prefix = array();
            for( $m=1; $m<=$level; $m++ ) {
                if ( ! isset($current[$m] ) ) {
                    $current[$m] = 1;
                }
                $prefix[] = $current[$m];
            }
            $text = implode('.', $prefix ) . ' ' . $text;
        }
        $last  = $level;
        $toc[] = '<span style="margin-left:'
               . ( 10 * ( $level - 1 ) )
               . 'px;"><a href="#toc'.$i.'">'.$text.'</a></span>';
        $wb_page_data = str_replace(
            $matches[0][$i],
            ( ( $i > 0 && $toplink ) ? '<a class="toplink'.$i.'" style="text-align:right; font-weight:bold; display:inherit;" href="#toc">'.(isset($btt[LANGUAGE]) ? $btt[LANGUAGE] : $btt['EN']).'</a>' : '' ).
            '<a name="toc'.$i.'"> </a>' . $matches[0][$i],
            $wb_page_data
        );
    }

    $output = '<div class="toc" style="margin:5px;padding:5px;border:1px solid #ccc;';
    if ( isset($float) && $float == 'right' ) {
        $output .= ' float:right;';
    }
    $output .= '">'
            . '<a name="toc" style="font-weight:bold;">'
            . ( isset($strings[LANGUAGE]) ? $strings[LANGUAGE] : $strings['EN'] )
            . '</a><br />'
            .  implode( '<br />', $toc )
            .  '</div>';
}

$wb_page_data = str_replace('<a class="toplink1" style="text-align:right; font-weight:bold; display:inherit;" href="#toc">Zurück zum Anfang</a>','',$wb_page_data);

// this removes double 'to top' links if CreateToc is called more than once
//<a href="#toc">Back to top</a><br /><a name="toc1"> </a><br /><a href="#toc">Back to top</a><br /><a name="toc1"> </a>
$regex = '('.preg_replace('~\s~','\\s*',preg_quote('<br /><a href="#toc">Back to top</a><br /><a name="toc','~').'\d+'.preg_quote('"> </a>','~')).'){2,}';
$wb_page_data = preg_replace(
    '~'.$regex.'~',
    '$1',
    $wb_page_data
);

return $output;

@berny: keine Ahnung. Das Droplet ist nicht von mir.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#12 16.07.2021 11:30:35

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Habe auch
$wb_page_data = str_replace('<a class="toplink1" mit toplink ersetzt, da tut sich nichts, Sorry

Online

#13 16.07.2021 13:11:58

florian
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Mit dem zuletzt von mir geposteten Code funktionierts auf meiner Testwebsite.
attachment.php?item=3007&download=1
Bei dem Droplet passieren folgende Dinge:
1. Der gesamte Output wird eingelesen und alle Überschriften identifiziert.
2. Daraus wird das Inhaltsverzeichnis generiert.
3. Über dem eigentlichen Seiteninhalt wird das Inhaltsverzeichnis eingefügt.
4. Im Seiteninhalt wird mittels einer Schleife vor jede Überschrift der Zurück-Link gesetzt.
Hinzu kommt nun noch
5. Im Seiteninhalt wird nach dem exakten Vorkommen (Zeilenumbrüche nur hier im Forum zur besseren Lesbarkeit!) von
<a class="toplink1"
style="text-align:right; font-weight:bold; display:inherit;"
href="#toc" class="ZumAnfang">Zurück zum Anfang</a>

gesucht, und, sofern dies gefunden wird, durch einen Leerstring ersetzt.
Wenn es nur eine kleine Abweichung - im konkreten Fall: Leerzeichen nach den Strichpunkten in den Inline-Style-Anweisungen - gibt, wird der betr. Vergleichsstring nicht gefunden und der unerwünschte Zurück-Link bleibt folglich drin.

Eine andere Möglichkeit wäre sonst noch, auf Schritt 5 zu  verzichten und nur mittels der durch die Anpassung vorhandenen CSS-Klasse den unerwünschten Link auszublenden, also im Template-Stylesheet zu ergänzen

.toplink1 {display:none;}

Nur bei der ganzen Zeit, die jetzt hier in diese Sache versenkt worden ist, wäre es inzwischen wahrscheinlich 5x schneller gegangen, das Inhaltsverzeichnis und die Zurück-Links von Hand zu erzeugen.

Beitrag geändert von florian (16.07.2021 13:13:53)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

webbird, awuest

#14 16.07.2021 13:28:55

webbird
Administrator

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

berny schrieb:

Darf ich fragen, warum man $output auf NULL setzt und nicht auf "", wenn er nachher mit einem String gefüllt wird?

Vorteil? Nachteil? Egal?

An dieser Stelle ist es egal, an anderer ist NULL halt nicht das Gleiche wie ein leerer String, da kann das relevant sein. Gewohnheit. angel


Ich habe eine Amazon-Wishlist. wink Oder spende an das Projekt.
Ich kann, wenn ich will, aber wer will, dass ich muss, kann mich mal

Offline

Liked by:

berny

#15 17.07.2021 18:10:42

awuest
Mitglied

Re: CreateToc "Zurück zum Anfang" nach der Tabelle

Danke Florian für die Erklärung und die angebotene Lösung.
Ein schönes Wochenende
Andreas

Online

Fußzeile des Forums

up