News:

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

Main Menu

Stop Auto-Posters from screwing up your forum

Started by MrMike, September 17, 2011, 10:40:30 AM

Previous topic - Next topic

MrMike

I offer this in the hope it may help someone who has a similar issue.

I recently converted a VBulletin forum (MGKiller.com) with ~300,000 posts to SMF 2, and found that several auto-poster users (which we allow) were messing things up by submitting a non-existent message icon name in their posts.

The icon name used to exist, but after switching it's no longer there. But the auto-posters were still cranking away, submitting the form with the old icon name. (SMF doesn't check to see if the icon name being submitted is a valid icon name, unfortunately.)

This had the effect of causing either a broken or missing image (a blank space). Sometimes the missing image showed the alt text of "Message icon". Correcting these by hand was too much work, so I coded a small fail-safe for this.

The code just gets a list of all the currently available icons and verifies that the icon name being submitted actually matches one of them. If not, it sends the user to the preview screen with an error message. Using this cured the problem completely.

Step 1:
Add this line to post.english.php (and any other languages you use):

$txt['error_message_icon'] = 'Please select a valid Message Icon for this post';


Step 2:
In /Sources/Post.php, find this code:

    // Creating a new topic?
    $newTopic = empty($_REQUEST['msg']) && empty($topic);

    $_POST['icon'] = !empty($attachIDs) && $_POST['icon'] == 'xx' ? 'clip' : $_POST['icon'];



Add this code immediately after the lines above:

    /////////////////////////////////////////////////////
    // hack to prevent auto-posters from using non-existent icons

    // get all existing icons by the icon key name and create an array
    // so they can be searched for a matching name
    $icon_sql = "SELECT filename FROM smf_message_icons";
    $icon_result = mysql_query($icon_sql);
    while( $icon_data =  mysql_fetch_array($icon_result)){
        $icon_list[] = $icon_data['filename'];
    }

    // see if the incoming icon name is a valid icon, if not, throw an error
    // and recycle to the preview screen with an error message
    if( (!in_array($_POST['icon'], $icon_list)) || ($_POST['icon'] == 'xx') ) {

            // add the error key to the error list
            $post_errors[] = 'message_icon';

            if (!empty($post_errors))
        {
            loadLanguage('Post');
            // Previewing.
            $_REQUEST['preview'] = true;
   
            $context['post_error'] = array('messages' => array());
            foreach ($post_errors as $post_error)
            {
                $context['post_error'][$post_error] = true;
                $context['post_error']['messages'][] = $txt['error_' . $post_error];
            }
   
            return Post();
        }

    }
    /////////////////////////////////////////////////////

vpn

This should be reported as a bug. The forum should detect if someone is submitting a post icon that doesnt exist
VPN Tutorials [nofollow]
VPN Support Forums [nofollow]

Advertisement: