News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Title stripper (as sexy as it sounds, trust me ;))

Started by Jade Elizabeth, November 13, 2014, 09:24:31 AM

Previous topic - Next topic

Jade Elizabeth

I'm sick and tired of dodgy titles...so I want them stripped of the dodgyness...


  • No double spaces in titles
  • No spaces before punctuation
  • ADD spaces after punctuation (except at the end)

I could have called this a title cleaner but you guys would have ignored me ;).
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

Post.php

Code (find) Select
// At this point, we want to make sure the subject isn't too long.

Code (before it, add) Select
// Strip spaces either side of punctuation (we will fix this in a bit)
$_POST['subject'] = preg_replace('~\s+([!,\.;:&])\s*~', '$1', $_POST['subject']);
// Spaces after punctuation except for last one
$_POST['subject'] = trim(preg_replace('~([!,\.;:&])~', '$1 ', $_POST['subject']));
// Strip multiple spaces
$_POST['subject'] = preg_replace('~\s+~', ' ', $_POST['subject']);


Not tested.

Steve

Hey Jade ... how about title case or at least the first word capitalized? I'm so anal I hate seeing topic titles starting out with lower case letters.  :-[
DO NOT pm me for support!

live627

Quote from: Arantor on November 13, 2014, 09:41:36 AM
Post.php

Code (find) Select
// At this point, we want to make sure the subject isn't too long.

Code (before it, add) Select
// Strip spaces either side of punctuation (we will fix this in a bit)
$_POST['subject'] = preg_replace('~\s+([!,\.;:&])\s*~', '$1', $_POST['subject']);
// Spaces after punctuation except for last one
$_POST['subject'] = trim(preg_replace('~([!,\.;:&])~', '$1 ', $_POST['subject']));
// Strip multiple spaces
$_POST['subject'] = preg_replace('~\s+~', ' ', $_POST['subject']);


Not tested.
Not sexy enough. Needs 80085!

Steve

DO NOT pm me for support!

Arantor


Jade Elizabeth

Quote from: Steve on November 13, 2014, 05:27:59 PM
Hey Jade ... how about title case or at least the first word capitalized? I'm so anal I hate seeing topic titles starting out with lower case letters.  :-[

OMG YES!!!! Do we need a full stop remover? Yes? Okay.

Quote from: Arantor on November 13, 2014, 09:41:36 AM
Post.php

Code (find) Select
// At this point, we want to make sure the subject isn't too long.

Code (before it, add) Select
// Strip spaces either side of punctuation (we will fix this in a bit)
$_POST['subject'] = preg_replace('~\s+([!,\.;:&])\s*~', '$1', $_POST['subject']);
// Spaces after punctuation except for last one
$_POST['subject'] = trim(preg_replace('~([!,\.;:&])~', '$1 ', $_POST['subject']));
// Strip multiple spaces
$_POST['subject'] = preg_replace('~\s+~', ' ', $_POST['subject']);


Not tested.

THANK YOU SO MUCH FOR YOUR ALWAYS SEXY CODE!!!

I love you so much in this moment. If possible can you also add:

1. Capital first letter (regardless of other chars - so 8756 blah becomes 8765 Blah)
2. Capital letter after [ and ] (square brackets only)
3. No full stop on end UNLESS ... or .. but not ....
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Jade Elizabeth

Seriously thank you so much, this has actually been a HUGE source of stress for me, I can't tell you how grateful I am right now - you have literally just made my day!!
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Gwenwyfar

#8
Never thought about this but thanks for the code as well! You rock 8)

Another thing that is annoying as well is when people make an all caps title... But not sure how hard would be that to make (just learning the basics of regex, not sure yet how you replace something with content already there really, or if you can do it).
"It is impossible to communicate with one that does not wish to communicate"

Arantor

All caps? I probably wouldn't do that with regex. Not every problem can be fixed that way ;)

Quote1. Capital first letter (regardless of other chars - so 8756 blah becomes 8765 Blah)

With or without considering the Re: prefix? Bear in mind all the code goes through the same routine, even the replies.

Quote2. Capital letter after [ and ] (square brackets only)

Difficult to do reliably.

Quote3. No full stop on end UNLESS ... or .. but not ....

Ugh.

You know, you could just try moderating members and talking to them like human beings?

Gwenwyfar

#10
Quote from: Arantor on November 14, 2014, 09:45:46 AM
All caps? I probably wouldn't do that with regex. Not every problem can be fixed that way ;)
I see. Still on the basics of php as well, still don't know much about all it can do. Then again it would be hard to know whether the caps was intentional or not, for abbreviations and etc, so it could ruin some good titles.

And well, its rare enough and annoying enough that it deserves a mod edit without people complaining about the change :P

But on the regex thing (replacing something, like on the case of capital letters, but keeping the character) is it even possible? Kinda off-topic question but it would make my life much easier on some mass-replaces I need to do if it is.

The only other thing I'd add to those three then are multiple exclamation/interrogation marks. Nobody likes those, and some people are remarkable for liking to spam them. (and this I think should be simple/fitting enough for regex ;), I could give it a try myself but you're probably gonna do a better job at that :D)
"It is impossible to communicate with one that does not wish to communicate"

Arantor

Sure it is, you would take the regex to match it and use preg_replace_callback to call a function that calls strtolower. The manual page for that function actually gives you an example of doing such.

Gwenwyfar

But then wouldn't that be php + regex? Sorry, I forgot to specify. I need to change some things on database, for example, old forum links, they still have the same topic id, so I'd want to find it, take the id part, and put it on a new link with the new domain and smf format. Unless its simple to take a sql/text file/search on database then just run it through a php replace, because I've been using editor/sql replace for the simpler changes so far :P
"It is impossible to communicate with one that does not wish to communicate"

Illori

smf_messages set body = replace(body, 'oldstuff', 'newstuff')

sql query

Gwenwyfar

#14
For simpler changes that works fine, the problem is keeping something in-between. The urls are more like domain.xx/ID-topic-name-and-other-stuff-here

Though thinking better I guess it doesn't make a difference if I don't change whats after the id, since smf ignores that, duh. Then it would only be needed for message links, which are few.

Also made this out of Arantor's code to remove multiple exclamation/interrogation marks, I don't guarantee anything, but seems to work ok:


//Strip multiple interrogation and exclamation marks
$_POST['subject'] = preg_replace('~!+~', '!', $_POST['subject']);
$_POST['subject'] = preg_replace('~\?+~', '?', $_POST['subject']);
"It is impossible to communicate with one that does not wish to communicate"

Arantor


Jade Elizabeth

Quote from: Arantor on November 14, 2014, 09:45:46 AM
All caps? I probably wouldn't do that with regex. Not every problem can be fixed that way ;)

Quote1. Capital first letter (regardless of other chars - so 8756 blah becomes 8765 Blah)

With or without considering the Re: prefix? Bear in mind all the code goes through the same routine, even the replies.

Well mostly I'm only worried about the first posts, the titles can't be changed from there onwards on my forum :).

Quote from: Arantor on November 14, 2014, 09:45:46 AM
You know, you could just try moderating members and talking to them like human beings?

Today I edited 7 topic titles from the one member who still insists on putting in spaces before ? and who still refuses to use square brackets in one board where every topic has a prefix. I can't fix that until there's a prefix mod.

I've messaged her 4 times, she says she's doing it right so she obviously doesn't get it ha ha.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

Quotethe titles can't be changed from there onwards on my forum

Really? Are you sure?

QuoteI've messaged her 4 times, she says she's doing it right so she obviously doesn't get it ha ha.

And it couldn't be, say, that you didn't explain it properly? Or that her first language isn't English and in other languages they do have precedent for spaces before punctuation? Do not be so quick to assume the fault is with other people.

Jade Elizabeth

Quote from: Arantor on November 16, 2014, 04:46:30 AM
Quotethe titles can't be changed from there onwards on my forum

Really? Are you sure?

Yeah, even if they are they don't display and they don't screw up links so I'm not worried about it :).

Quote from: Arantor on November 16, 2014, 04:46:30 AM
QuoteI've messaged her 4 times, she says she's doing it right so she obviously doesn't get it ha ha.

And it couldn't be, say, that you didn't explain it properly? Or that her first language isn't English and in other languages they do have precedent for spaces before punctuation? Do not be so quick to assume the fault is with other people.

She is very old and set in her ways. She's a natural English speaker but it's like trying to get my dad to understand that Facebook privacy can be set to friends only or public. He still thinks everyone will see it and that Facebook ads will give him a virus. And some bright spark has only stoked that fire.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Jade Elizabeth

Can we make a check that the punctuation isn't multiple before spaces?

"Too  many  spaces !!"

becomes

"Too many spaces! !"
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Advertisement: