1 (edited by h4ever 2020-02-28 16:00)

Topic: How to print errors for post.php when sending post?

Hello,
I want to modify post.php so that when user sends a post into topic, I want to check the data using my own checking algorithm. I generate errors array and on the line with add_post I return the array from within the function:

$errors = add_post($post_info, $new_pid, $tid, $cur_posting['first_post_id']);
/*if (!empty($errors))
      {print_r($errors);die;}*/

Now I need to print the errors when the errors array is not  empty. I know I cannot print them directly, but I need to send the headers and use buffering, but I have no idea how.

Can you help?

PS: Just to give you idea about the add_post() code that I added:

 $int = preg_match("%\[quote=.{0,40}\].*\[/quote\]%is", $post_info['message'], $results);
 if ($int > 0):
   $errors = search_quote($post_info['message']);
   if (!empty($errors))
     return $errors;
 endif;

Re: How to print errors for post.php when sending post?

No need to change the engine code. There are hooks and extensions for this.

http://punbb.informer.com/wiki/punbb13/ … evelopment

All checks for the user's message are in the post.php file above the line

    // Did everything go according to plan?
    if (empty($errors) && !isset($_POST['preview']))

So to add your own checks you need to use the "po_end_validation" hook.
post.php:

    ($hook = get_hook('po_end_validation')) ? eval($hook) : null;

    // Did everything go according to plan?
    if (empty($errors) && !isset($_POST['preview']))

You need to add such a hook to your extension:

    <hook id="po_end_validation"><![CDATA[
         if (preg_match("%\[quote=.{0,40}\].*\[/quote\]%is", $message)) {
             $errors[] = 'YOUR ERROR';
         }
    ]]></hook>
Parserus, UserAgentAnalyzer.
I speak only Russian  :P