Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: waplist on April 04, 2017, 01:27:26 AM

Title: How to increase topic tilte/subject length?
Post by: waplist on April 04, 2017, 01:27:26 AM
Hello,
         I tried to create new topic but i think smf doesnt allow title longer titles . there is also no setting to change that in smf.  Help on this thank you
Title: Re: How to increase topic tilte/subject length?
Post by: Illori on April 04, 2017, 05:07:29 AM
are you actually using SMF 2.1?
Title: Re: How to increase topic tilte/subject length?
Post by: waplist on April 04, 2017, 05:39:29 AM
Sorry actually its 2.0.13.
Title: Re: How to increase topic tilte/subject length?
Post by: Kindred on April 04, 2017, 10:18:06 AM
And, the next question is..  why?

Why do you think you need a topic longer than 80 characters?

In almost every case, when someone asks for this, they are attempting to "abuse" the system for a reason that is not actually necessary or even good.

And, as to why it's not a setting... you would gave to change a source file, a template file and the database
Title: Re: How to increase topic tilte/subject length?
Post by: shadav on September 08, 2019, 09:48:12 PM
sorry to bump an old topic, and hijack it
but I have the same question....
2.0.15
I need to lengthen the topic title
I post a lot of article type posts and have run into the issue of the title character limit, can't find a setting in the admin to change it
I would think that 120 would be more than enough
Title: Re: How to increase topic tilte/subject length?
Post by: Antechinus on September 08, 2019, 10:02:13 PM
Shouldn't need a database change. It's already varchar(255) which is more than adequate.

The template code is here, in Post.template.php:

// Now show the subject box for this post.
echo '
<dt>
<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
</dt>
<dd>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />


Where the size is just the visible width, and the max length is the critical part. The database would allow you to set 255 here if you were that bonkers.

The trickier part is Sources/Post.php (because Sources is always a tad gnarly IME):

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > 100)
$form_subject = $smcFunc['substr']($form_subject, 0, 100);


Which is obviously happy with 100 characters, but will truncate anything over that. It should, I think, be safe to increase that to 120 if you need that many. At which point Arantor will probably pop up and tell me about all sorts of dire things that will happen.
Title: Re: How to increase topic tilte/subject length?
Post by: Arantor on September 09, 2019, 02:28:52 AM
As requested.

255 is only enough if you don't have special characters in the subject. The relationship between the logical length of the string and the physical is tenuous at best.

A " will consume 6 out of the 255 but only 1 out of the 100/120. Emojis are the worst though, they usually only count as 1 out of the 100/120 but up to 9 out of the 255, each.

That's why the disjoint, trying to cover as many cases of space consumption as possible, or at least, as was likely at the time (as those numbers were set long before the current emoji even existed)

The only problem is that it will truncate somewhat spuriously in this case, either with an error or more likely no error and then you just get a mangled title. Or it gets mangled later by the forced "Re:" stuff that is normally covered but suddenly now might not be.
Title: Re: How to increase topic tilte/subject length?
Post by: Antechinus on September 09, 2019, 02:42:54 AM
Learn something every day. Ok, do you think it would be safe to increase it to 100, to match the truncation limit in Post.php?

Assuming that whoever was using it had enough sense to not fill the subject up with smileys and special ZOMG characters.

Which some clown is bound to do sooner or later, but you can always just point at them and start giggling.
Title: Re: How to increase topic tilte/subject length?
Post by: Arantor on September 09, 2019, 02:54:26 AM
Even 120 is safe as long as the subject isn't full of ', ", <, >, & or emojis. These are all characters that are stored in an encoded format. A few is ok, a lot breaks it.
Title: Re: How to increase topic tilte/subject length?
Post by: Antechinus on September 09, 2019, 03:18:32 AM
Caveat scriptor, then. :)

I suppose it would technically be possible to break things even with the default 80 character limit, if you specifically set out to do that just to prove a point.
Title: Re: How to increase topic tilte/subject length?
Post by: Arantor on September 09, 2019, 03:35:07 AM
Yup, and it has been observed, but generally it isn't usually a problem, because most posts don't trip over this, because topic titles that are a mass of specific punctuation are annoying as are topics that are just emoji.
Title: Re: How to increase topic tilte/subject length?
Post by: shadav on September 09, 2019, 12:18:09 PM
thank you both and interesting info
hopefully smilies and whatnots won't be an issue

so then am I correct in that I changed, the 80's to 120's
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="120" maxlength="120" class="input_text" />

and that I changed the 100's to 120's

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > 120)
$form_subject = $smcFunc['substr']($form_subject, 0, 120);


it seems to work so far....
Title: Re: How to increase topic tilte/subject length?
Post by: Antechinus on September 09, 2019, 05:19:31 PM
Yep. That should be all it needs.