Browse Source

Remove newlines and modifiers from thread title

Parts sampled from NPFchan
pull/40/head
discomrade 11 months ago
parent
commit
77da46c424
  1. 15
      inc/functions.php
  2. 2
      inc/lib/Twig/Extensions/Extension/Tinyboard.php
  3. 2
      templates/thread.html

15
inc/functions.php

@ -1914,6 +1914,10 @@ function unicodify($body) {
return $body;
}
function newline_to_full_stop($body) {
return str_replace("\n", '. ', $body);
}
function extract_modifiers($body) {
$modifiers = array();
@ -1928,6 +1932,17 @@ function extract_modifiers($body) {
return $modifiers;
}
function remove_markup($body) {
global $config;
foreach ($config['markup'] as $markup) {
if (is_string($markup[1]))
$body = preg_replace($markup[0], "$1", $body);
}
return $body;
}
function remove_modifiers($body) {
return preg_replace('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@usm', '', $body);
}

2
inc/lib/Twig/Extensions/Extension/Tinyboard.php

@ -18,6 +18,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
new Twig_SimpleFilter('sprintf', 'sprintf'),
new Twig_SimpleFilter('capcode', 'capcode'),
new Twig_SimpleFilter('remove_modifiers', 'remove_modifiers'),
new Twig_SimpleFilter('remove_markup', 'remove_markup'),
new Twig_SimpleFilter('newline_to_full_stop', 'newline_to_full_stop'),
new Twig_SimpleFilter('hasPermission', 'twig_hasPermission_filter'),
new Twig_SimpleFilter('date', 'twig_date_filter'),
new Twig_SimpleFilter('poster_id', 'poster_id'),

2
templates/thread.html

@ -13,7 +13,7 @@
{% include 'header.html' %}
{% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup[:256]|remove_modifiers|e }}{% endif %}{% endset %}
{% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup[:256]|remove_modifiers|newline_to_full_stop|remove_markup|e }}{% endif %}{% endset %}
<meta name="description" content="{{ board.url }} - {{ board.title|e }} - {{ meta_subject }}" />
<meta name="twitter:card" value="summary">

Loading…
Cancel
Save