MyBB Community Forums

Full Version: Variable length in Forum Display $lastpost_subject (Ellipsis)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Actual Situation:
The subject of lastpost in forumdisplay is cut down to a fixed value of 25 characters with three trailing dots (full stops).
Neither a typographic ellipsis character is chosen.

This is hard-coded in function_forumlist.php / Line 312-315 / up to version 1.8.21
if(my_strlen($lastpost_subject) > 25)
{
  $lastpost_subject = my_substr($lastpost_subject, 0, 25)."...";
}

Improvement:
Use an own setting to define the max length of the subject string to be cut down.
Optionally allow the three dots to be an individual string or left empty.

Settings could make availabe two variables, for example:

1) $mybb->settings['lastpostsubjectlength']
Any numeric value [0-9]*
Set to 0 to deacitvate cut down.

2) $mybb->settings['lastpostsubjectellipsis']
Any varchar, e.g. "...", any html-code (img) or just left empty.


Implementation:
Insert settings into the database to group of Forum Display Options (7):
INSERT INTO mybb_settings
(sid, name, title, description, optionscode, value, disporder, gid, isdefault)
VALUES
(9991, 'lastpostsubjectlength', '[ETS] Max length of subject in last post until cut down.', 'If the subject text in last post is exceeding this value, it is cut down and replaced by dots at the end of line. Set to 0 to disable', 'numeric\nmin=0', '25', 91, 7, 1);
INSERT INTO mybb_settings
(sid, name, title, description, optionscode, value, disporder, gid, isdefault)
VALUES
(9992, 'lastpostsubjectellipsis', '[ETS] Ellipsis for cut down subjects in last post.', 'Replacement string at the end of subject line cut down.', 'text', '...', 92, 7, 1);
(sid + disporder are exemplary)

Replace the mentioned PHP code in function_forumlist.php with the following:
if ($mybb->settings['lastpostsubjectlength'] > 0)
{
  if(my_strlen($lastpost_subject) > $mybb->settings['lastpostsubjectlength'])
  {
    $lastpost_subject = my_substr($lastpost_subject, 0, $mybb->settings['lastpostsubjectlength']).$mybb->settings['lastpostsubjectellipsis'];
  }
}

That's it! Smile

If this enhancement will not follow a future implementation, other users can take it to improve their design even though.

Cheers!
[ExiTuS]
It would definitely make sense to make the length a setting, and the phrase used to show shortened subjects should be a language variable IMO.
(2019-06-16, 01:54 PM)Euan T Wrote: [ -> ]the phrase used to show shortened subjects should be a language variable IMO.

Agreed.

Something like:
// $maxlen = 25
$ellipsis = '';
if (strlen($subject) > $maxlen) {
	$ellipsis = $lang->ellipsis;
	$subject = my_substr($subject, 0, $maxlen - strlen($ellipsis)).$ellipsis;
}
(2019-06-16, 02:04 PM)Wildcard Wrote: [ -> ]
(2019-06-16, 01:54 PM)Euan T Wrote: [ -> ]the phrase used to show shortened subjects should be a language variable IMO.

Agreed.

Something like:
// $maxlen = 25
$ellipsis = '';
if (strlen($subject) > $maxlen) {
 $ellipsis = $lang->ellipsis;
 $subject = my_substr($subject, 0, $maxlen - strlen($ellipsis)).$ellipsis;
}
I was more thinking:
// $maxlen = 25

if (my_strlen($subject) > $maxlen) {
    $subject = $lang->sprintf($lang->subject_too_long_var, my_substr($subject, 0, $maxlen));
}
If you don't take into account the length of the ellipsis, then the limit is exceeded AND replacing the ellipsis with a single character (symbol) won't work correctly.
(2019-06-16, 03:49 PM)Wildcard Wrote: [ -> ]If you don't take into account the length of the ellipsis, then the limit is exceeded AND replacing the ellipsis with a single character (symbol) won't work correctly.

True
Sorry, but I failed to understand the discussion.
We can just delete the length cut in PHP and handle entirely through CSS, as someone already suggested
https://github.com/mybb/mybb/issues/3565
(2019-06-17, 02:14 AM)effone Wrote: [ -> ]Sorry, but I failed to understand the discussion.
We can just delete the length cut in PHP and handle entirely through CSS, as someone already suggested
https://github.com/mybb/mybb/issues/3565
I'd forgotten about that issue completely. CSS would be easier.
Oh dear!
It is no question of convenience - it's a main principle:
CSS is used for style formatting and is not intended to use for content manipulating!

It is not strict going the CSS-way. It is really in bad style decreasing the quality of the forums system at all.

[ExiTuS]

BTW.
It would be beneficial to create an own function for cut down with ellipsis.
Making this global function available all over the forum it could also be used for any kind of text cropping, like:
- last post subject
- preview posts in search results
- further preview on posts

[ExiTuS]