Limit Forum Description On Index To X Number Of Characters

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Scam Warning
Post Reply
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

Hi all,

It's my first post, how exciting.

Is there any way I am able to limit how many characters are displayed from my forum descriptions on the index?

As there isn't any text block mod (tell me if I'm wrong), that I can deploy on my individual forum pages, in order to get content on these pages I need to max out the forum descriptions, however, that means all of that content will be visible on the index too.

Is there any way I can limit the descriptions on the index to let's say 50 characters?

Thanks, Brett
Last edited by Kailey on Wed Mar 14, 2018 11:06 pm, edited 1 time in total.
Reason: Moved to Extension Requests
User avatar
tbackoff
Former Team Member
Posts: 7068
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: Limit Forum Description On Index To X Number Of Characters

Post by tbackoff »

I'm pretty sure you would need to modify the following line in /includes/functions_display.php:

Code: Select all

			'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
You could also request an extension to handle this here.
Flying is the second best thrill to cheerleaders; being caught is the first.
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by warmweer »

dansmith018f wrote: Wed Mar 14, 2018 4:57 pm ...
Is there any way I can limit the descriptions on the index to let's say 50 characters?
Is this 50 characters in one fluent sentence, or perhaps 3 lines of 17/18 characters?

Since this seems to be a strictly personal wish you have I see no need to code anything; it should be fairly simple for you to limit yourself to a the description with max 50 characters.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by 3Di »

^^ this.

Or for the sake of other admins which are potentially messing with that in ACP, the above mentioned line of code could be changed to be

Code: Select all

'FORUM_DESC'			=> generate_text_for_display(truncate_string($row['forum_desc'], 50), $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
Well, not tested.. but should do.

Edit: removed extra opening parenthesis
Last edited by 3Di on Mon Mar 19, 2018 10:55 pm, edited 1 time in total.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Re: Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

3DI, that doesn't work unfortunately, I get an error :/
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by mrgoldy »

Remove one ( infront of 'truncate'.
However, I am not familar with the interaction, bit what happens if a bbcode is opening within the first 50 chars but the closing tag is beyond that. Will that give problems with the display?
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by 3Di »

Yeah, the admin should take care of it nonetheless.

As per the docs:
* Truncates string while retaining special characters if going over the max length
* The default max length is 60 at the moment
* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a "quote"' (length: 19)
*
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Re: Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

Hi all,

Thanks for your responses, I am slightly confused.

I added the "edited" code above - the site loads fine now, no errors, however, it doesn't work.

I expanded the forum description, multiple paragraphs, however, it all still reflects on the forum index, and it doesn't look good.

What do you mean that I can limti the number of characters in ACP? where?
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Limit Forum Description On Index To X Number Of Characters

Post by RMcGirr83 »

There are two FORUM_DESC within that file. Did you edit the correct one?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Re: Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

ah, yes, brilliant, it works!

Looks like <t> is placed at the beginning of the forum description on the index if it's to long, is there anyway to remove this?

also, instead of the paragraph/text being cut off, which looks odd, is there anyway to add '...' to the end?

So, it's obvious that there is more information inside?

Thanks for all your help!
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Limit Forum Description On Index To X Number Of Characters

Post by GanstaZ »

Here is all the info about that function:

Code: Select all

/**
* Truncates string while retaining special characters if going over the max length
* The default max length is 60 at the moment
* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a &quot;quote&quot;' (length: 19)
*
* @param string $string The text to truncate to the given length. String is specialchared.
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
* @param bool $allow_reply Allow Re: in front of string
* 	NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated.
* @param string $append String to be appended
*/
function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by 3Di »

You can try truncate_string($row['forum_desc'], 50, 255, false, '...') not tested.

Sincerely, I don't have time to follow this custom code.

Being this forum for Extension Requests you may try and post in the other devoted forum.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Re: Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

That works! Thank you so much.

<t> is still present however at the start, any idea how to remove this?
dansmith018f
Registered User
Posts: 12
Joined: Mon Mar 12, 2018 4:40 pm

Re: Limit Forum Description On Index To X Number Of Characters

Post by dansmith018f »

Bump - is there anyone that's able to help here? :)
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Limit Forum Description On Index To X Number Of Characters

Post by 3Di »

dansmith018f wrote: Thu Mar 22, 2018 1:49 pm <t> is still present however at the start, any idea how to remove this?
Yes, but as I said making an extension around of this it is not really worth the effort, by my side at least.

The ACP is decoupled from the main core like UCP and MCP and those "<t>" are there because of the new parser, dunno if a PHP's string manipulation of sort could amend that somehow, not tried. Perhaps using Twig, I recall of some positive experiments I did in the past.. but again: good luck.

There is a devoted forum for custom coding: viewforum.php?f=641 maybe you could try asking over there?
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Extension Requests”