Formatting User Entered Data in Topic Subjects and Search Terms...

Started by lou-in-usa, April 26, 2011, 05:49:52 PM

Previous topic - Next topic

lou-in-usa

Greeting again everyone!
It has been a long time since I've done any modifications to Simple Machines.
  I want to build a board where people can start topics and add to them where an email address is the topic and can only occur once as a topic.  So someone wants to post a topic they just put an email address in the subject line and my script would scrub the subject line for spaces and incorrect formatting and then start a new topic if it doesn't exist or append to the topic if it does and obviously kick back an error if the email address can't be made to look like an email address.  Similarly, I wanted to see if I could scrub and limit the searches to this format as well.  I know how to write the data formatting script, I just wanted to see if anyone has done this and which scripts I should be looking at to modify the posting and searching functions. 
Thanks again guys!

ascaland

#1
What you're generally looking at is editting the Post.php to fix up your subjects which is what im assuming you just want changed, the best part is that it isnt hard at all. What you would basically do here is validate the input as being a valid email address. SMF supplies this for us. In Post2() of Post.php, perhaps above,
// Any mistakes?
if (!empty($post_errors))


This is the sort of code you would use to validate addresses,
if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['subject']) == 0)
$post_errors[] = 'bad_email';


As for the search functions, I cant imagine a need for making modifications to the way SMF searches topics because its looking in the subject (which are the email addresses) anyways. All users would have to do is search with keywords such as a persons email name or hotmail.com, or gmail.com and such.

By the way,
QuoteI want to build a board where people can start topics and add to them where an email address is the topic and can only occur once as a topic.
Are you talking about duplicate email subjects?

lou-in-usa

Project Evolution:
Thanks for your fast and considerate reply.
Basically I want to ensure that only an email ID is entered into the subject line and then make it the topic while ensuring there is only one topic for a given email ID.  Essentially creating a "NEW TOPIC/SUBJECT" when an email ID has been entered that doesn't already have a topic existing or automatically making it a "Reply" to the the "TOPIC/SUBJECT" when the email ID already exists as a "TOPIC/SUBJECT".

ascaland

Then just under the instructions I gave you above you can use something like this,
$query = $smcFunc['db_query']('', '
SELECT subject
FROM {db_prefix}messages
WHERE subject = {string:subject}
LIMIT 1',
array(
'subject' => $_POST['subject'],
)
);

if ($smcFunc['db_num_rows']($query) > 0)
$post_errors[] = 'bad_email';
$smcFunc['db_free_result']($query);


If you play around with the query a bit im sure you can get it working for specific boards or something. In the meantime this applies to any messages.

Advertisement: