Autor Thema: PHP-Hilfe?  (Gelesen 1848 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

Online schneeland

  • Moderator
  • Mythos
  • *****
  • Cogito ergo possum
  • Beiträge: 11.488
  • Username: schneeland
Re: PHP-Hilfe?
« Antwort #25 am: 19.02.2023 | 13:37 »
Beim Link wirst Du's m.E. nicht brauchen, aber ja, der Titel möchte dann anscheinend auch dekodiert werden.
Brothers of the mine rejoice!
Swing, swing, swing with me
Raise your pick and raise your voice!
Sing, sing, sing with me

Offline Blechpirat

  • Administrator
  • Titan
  • *****
  • Beiträge: 13.567
  • Username: Karsten
    • Richtig Spielleiten!
Re: PHP-Hilfe?
« Antwort #26 am: 19.02.2023 | 13:38 »
Ich habe das jetzt mal so gefasst - wird das funktionieren?

// Always share supported Post Types.
add_filter( 'share_on_mastodon_enabled', '__return_true' );

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $title= html_entity_decode($post->post_title);
  $text = wp_strip_all_tags( $post->post_content );
  $text = html_entity_decode($text);
  $link = get_permalink( $post );
  $text = mb_substr($text,0, 480 - mb_strlen($post->post_title) - mb_strlen ($link)); //500 - 4 line  breaks, 3 dots - 9 für Hashtags
  return $title .  "\n\n" . $text . "...\n\n" . $link . "\n\n #pnpde";
}, 10, 2 );

Online schneeland

  • Moderator
  • Mythos
  • *****
  • Cogito ergo possum
  • Beiträge: 11.488
  • Username: schneeland
Re: PHP-Hilfe?
« Antwort #27 am: 19.02.2023 | 14:05 »
Im Prinzip ja, aber beim Längencheck m.E. besser auch den dekodierten Titel verwenden:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $title= html_entity_decode($post->post_title);
  $text = wp_strip_all_tags( $post->post_content );
  $text = html_entity_decode($text);
  $link = get_permalink( $post );
  $text = mb_substr($text,0, 484 - mb_strlen($title) - mb_strlen ($link)); //500 - 6 line breaks, 3 dots, 1 space, 6 for hashtag
  return $title .  "\n\n" . $text . "...\n\n" . $link . "\n\n #pnpde";
}, 10, 2 );

(ich hab' außerdem mal den Kommentar angepasst und die Maximallänge auf 484 korrigiert)
Brothers of the mine rejoice!
Swing, swing, swing with me
Raise your pick and raise your voice!
Sing, sing, sing with me

Offline Blechpirat

  • Administrator
  • Titan
  • *****
  • Beiträge: 13.567
  • Username: Karsten
    • Richtig Spielleiten!
Re: PHP-Hilfe?
« Antwort #28 am: 21.02.2023 | 15:43 »
Arg!

Ein "I'm" zieht dann doch einen Fehler. Okay, englische Beiträge sollte eh nicht sein, aber:

https://social.karsten-voigt.de/@rspblogs/109903211946640035

Was ist da schief gegangen?

Online schneeland

  • Moderator
  • Mythos
  • *****
  • Cogito ergo possum
  • Beiträge: 11.488
  • Username: schneeland
Re: PHP-Hilfe?
« Antwort #29 am: 21.02.2023 | 15:58 »
Es scheint als bräuchtest Du einen zusätzlichen Parameter für html_entity_decode (siehe Stackoverflow).

Probier' mal html_entity_decode($var, ENT_QUOTES) statt html_entity_decode($var), sprich:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $title= html_entity_decode($post->post_title, ENT_QUOTES);
  $text = wp_strip_all_tags( $post->post_content );
  $text = html_entity_decode($text, ENT_QUOTES);
  $link = get_permalink( $post );
  $text = mb_substr($text,0, 484 - mb_strlen($title) - mb_strlen ($link)); //500 - 6 line breaks, 3 dots, 1 space, 6 for hashtag
  return $title .  "\n\n" . $text . "...\n\n" . $link . "\n\n #pnpde";
}, 10, 2 );
« Letzte Änderung: 21.02.2023 | 16:35 von schneeland »
Brothers of the mine rejoice!
Swing, swing, swing with me
Raise your pick and raise your voice!
Sing, sing, sing with me

Offline Blechpirat

  • Administrator
  • Titan
  • *****
  • Beiträge: 13.567
  • Username: Karsten
    • Richtig Spielleiten!
Re: PHP-Hilfe?
« Antwort #30 am: 21.02.2023 | 16:34 »
Danke, probieren wir es mal!