Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add (optional) MinLength for sliceParagraph #3484

Merged
merged 4 commits into from Mar 23, 2016
Merged

Conversation

korelstar
Copy link
Contributor

In my forum, I have several discussions beginning with a short greeting, like:

Hi folks,

foo bar is great. Bla bla bla.

The DiscussionController uses sliceParagraph for setting an appropriate description in the meta tags of the discussion page. Hence, the result is currently Hi folks, which is not very useful (and e.g. google webmaster tools complain about a too short description).

Therefore, I propose to add a new parameter MinLength. If the found paragraph is shorter than this value, then the string is sliced on a sentence.

In the example, the result will be Hi folks, foo bar is great. which has clearly more benefit.

* @return string
*/
function sliceParagraph($String, $MaxLength = 500, $Suffix = '…') {
function sliceParagraph($String, $MaxLength = 500, $Suffix = '…', $MinLength = 50) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bothers me to throw a parameter on the end like this. Now param 4 is related to param 2 with something you probably never want to override in between.

What if we made the second parameter default to [32,500] as list($min, $max) or defaults to just $max if an int is passed?

I also note your more useful suggestion is still only 27 characters. :) Maybe a lower min default of 32?

@korelstar
Copy link
Contributor Author

You're right, @linc : the example does not fit completely. It was only intended to show the general approach. I don't know, which default would be the best. We could use your suggestion of 32 chars and look how it will behave in real forums (I've tested it with 50 chars for two months and I'm not getting any warnings from google webmaster tools).

Regarding the parameter order: since sliceParagraph is never called without the second parameter, there should always be a default for $MinLength. I've implemented your suggestion with the array parameter. However, I don't know if the documentation syntax for this parameter is correct.

@linc linc merged commit 6fa50d3 into vanilla:master Mar 23, 2016
@linc
Copy link
Contributor

linc commented Mar 23, 2016

Good revision, thank you.

@korelstar korelstar deleted the patch-3 branch March 25, 2016 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants