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)
Suggested Hosts
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 » Wed Mar 14, 2018 4:57 pm

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 kinerity on Wed Mar 14, 2018 11:06 pm, edited 1 time in total.
Reason: Moved to Extension Requests

User avatar
t_backoff
Former Team Member
Posts: 6995
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 t_backoff » Wed Mar 14, 2018 8:54 pm

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.

User avatar
warmweer
Registered User
Posts: 1516
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

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

Post by warmweer » Wed Mar 14, 2018 8:59 pm

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.
A bug is a feature that hasn't made it to the manual (yet)

User avatar
3Di
Registered User
Posts: 13151
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

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

Post by 3Di » Thu Mar 15, 2018 2:38 am

^^ 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.
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

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 » Sat Mar 17, 2018 2:12 pm

3DI, that doesn't work unfortunately, I get an error :/

User avatar
mrgoldy
Jr. Extension Validator
Posts: 753
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

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

Post by mrgoldy » Mon Mar 19, 2018 10:41 pm

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?
Formerly known as posey.
''Proud member of the Studio"

User avatar
3Di
Registered User
Posts: 13151
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

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

Post by 3Di » Mon Mar 19, 2018 10:53 pm

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)
*
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

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 » Tue Mar 20, 2018 4:06 pm

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
Recognised Extension Developer
Posts: 21010
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

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

Post by RMcGirr83 » Tue Mar 20, 2018 4:16 pm

There are two FORUM_DESC within that file. Did you edit the correct one?
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

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 » Wed Mar 21, 2018 9:25 pm

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
Jr. Extension Validator
Posts: 658
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

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

Post by GanstaZ » Wed Mar 21, 2018 9:50 pm

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 = '')
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 13151
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

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

Post by 3Di » Wed Mar 21, 2018 10:04 pm

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.
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

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 » Thu Mar 22, 2018 1:49 pm

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 » Fri Mar 23, 2018 9:05 pm

Bump - is there anyone that's able to help here? :)

User avatar
3Di
Registered User
Posts: 13151
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

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

Post by 3Di » Fri Mar 23, 2018 9:22 pm

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?
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Post Reply

Return to “Extension Requests”

Who is online

Users browsing this forum: No registered users and 16 guests