Changeset 2364 in ExiteCMS for branches/PLi-Fusion/forum/post.php


Ignore:
Timestamp:
07/29/10 17:16:11 (22 months ago)
Author:
root
Message:

merged trunk into branches PLi-Fusion and ITXP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PLi-Fusion/forum/post.php

    r2348 r2364  
    6262// function to validate the contents of the $_POST array 
    6363function validatepost() { 
    64     global $locale; 
     64    global $locale, $fdata; 
    6565 
    6666    // we need both a subject and a message body 
     
    7171    if ($_POST['new_prefix'] == '[?]') $_POST['new_prefix'] = ''; 
    7272 
     73    // is a prefix required? 
     74    if ($fdata['forum_prefix'] && !empty($fdata['forum_prefixes']) && empty($_POST['new_prefix'])) { 
     75        return $locale['475']; 
     76    } 
     77 
    7378    return ""; 
    7479} 
    7580 
    7681// function to add or replace the prefix in the subject 
    77 function subject_prefix($subject, $prefix) { 
     82function strip_prefix($subject) { 
     83 
     84    $result = array('subject' => '', 'prefix' => ''); 
     85 
     86    // check for a reply, and strip the reply prefix 
     87    if (strtolower(substr($subject,0,3))=="re:") { 
     88        $result['subject'] = "Re: "; 
     89        $subject = trim(substr($subject,3)); 
     90    } 
     91 
     92    // split the subject to check for a prefix 
     93    if (preg_match('~(.*?)\[(.*?)\](.*)~i', $subject, $matches)) { 
     94        // a match must be at the beginning 
     95        if (empty($matches[1])) { 
     96            $result['prefix'] .= $matches[2]; 
     97            $result['subject'] .= trim($matches[3]); 
     98        } else { 
     99            $result['subject'] .= $matches[0]; 
     100        } 
     101    } else { 
     102        $result['subject'] .= $subject; 
     103    } 
     104 
     105    return $result; 
     106} 
     107 
     108// function to add or replace the prefix in the subject 
     109function add_prefix($subject, $prefix) { 
    78110 
    79111    // was a prefix defined 
     
    83115 
    84116        // split the subject to check for a prefix 
    85         if (!preg_match('~(.*)\[(.*)\](.*)~', $subject, $matches)) 
    86         { 
    87             // was this a reply? 
    88             if (strtolower(substr($subject,0,3)) == 're:') { 
    89                 $subject = 'Re: [' . $prefix . '] ' . substr($subject,4); 
     117        if (!preg_match('~(re:)(.*?)\[(.*?)\](.*)~i', $subject, $matches)) { 
     118 
     119            if (preg_match('~(.*?)\[(.*?)\](.*)~i', $subject, $matches)) { 
     120                if (empty($matches[1])) { 
     121                    $subject = '[' . $prefix . '] ' . trim($matches[3]); 
    90122            } else { 
    91123                $subject = '[' . $prefix . '] ' . $subject; 
    92124            } 
    93125        } else { 
    94             // remove spaces from the matches 
    95             foreach($matches as $key => $value) { 
    96                 $matches[$key] = trim($value); 
    97             } 
    98             unset($matches[0]); 
    99             $matches[2] = '[' . trim($prefix) . ']'; 
    100             $subject = trim(implode(' ', $matches)); 
    101         } 
     126                if (preg_match('~(re:)(.*)~i', $subject, $matches)) { 
     127                    $subject = 'Re: [' . $prefix . '] ' . trim($matches[2]); 
     128                } else { 
     129                    $subject = '[' . $prefix . '] ' . $subject; 
     130            } 
     131        } 
     132        } else { 
     133            $subject = 'Re: [' . $prefix . '] ' . trim($matches[4]); 
     134    } 
    102135    } 
    103136 
     
    490523            $preview['post_subject'] = trim(stripinput(censorwords($_POST['subject'])));; 
    491524            if ($preview['post_subject'] == "" && isset($tdata) && is_array($tdata)) { 
    492                 $preview['post_subject'] = "Re: ".$tdata['thread_subject']; 
     525                $preview['post_subject'] = add_prefix("Re: ".$tdata['thread_subject'], trim(stripinput($_POST['new_prefix']))); 
    493526            } else { 
    494                 $preview['post_subject'] = subject_prefix($preview['post_subject'], trim(stripinput($_POST['new_prefix']))); 
     527                $preview['post_subject'] = add_prefix($preview['post_subject'], trim(stripinput($_POST['new_prefix']))); 
    495528            } 
    496529            $preview['post_message'] = trim(stripmessageinput(censorwords($_POST['message']))); 
     
    614647// bail out if an edit is requested, but no edit rights have been detected 
    615648if ($action == "edit" && !$user_can_edit) { 
    616     resultdialog($locale['408'], $locale['502']); 
     649    resultdialog($locale['408'], $locale['552']); 
    617650} elseif (isset($_POST["cancel"])) { 
    618651    // post cancelled? 
     
    649682                    $smileys = isset($_POST['disable_smileys']) ? "0" : "1"; 
    650683                    $subject = trim(stripinput(censorwords($_POST['subject']))); 
     684                    if (isset($tdata) && strtolower(substr($subject,0,3)) != "re:") { 
    651685                    if ($subject == "") { 
    652686                        $subject = "Re: ".$tdata['thread_subject']; 
     687                        } else { 
     688                            if ($action != "edit") { 
     689                                $subject = "Re: ".$subject; 
    653690                    } 
    654                     $subject = subject_prefix($subject, stripinput($_POST['new_prefix'])); 
     691                        } 
     692                    } 
     693                    if ($fdata['forum_prefix']) { 
     694                        $subject = add_prefix($subject, stripinput($_POST['new_prefix'])); 
     695                    } 
    655696                    $message = trim(stripmessageinput(censorwords($_POST['message']))); 
    656697                    if ($action == 'edit') { 
    657698                        // update the post record 
    658699                        if ($_POST['message'] == $_POST['org_message']) 
    659                             $result = dbquery("UPDATE ".$db_prefix."posts SET post_subject='$subject', post_smileys='$smileys' WHERE post_id='$post_id'"); 
     700                            $result = dbquery("UPDATE ".$db_prefix."posts SET post_subject='".mysql_real_escape_string($subject)."', post_smileys='$smileys' WHERE post_id='$post_id'"); 
    660701                        else { 
    661                             $result = dbquery("UPDATE ".$db_prefix."posts SET post_subject='$subject', post_message='$message', post_smileys='$smileys', post_edituser='".$userdata['user_id']."', post_edittime='".time()."' WHERE post_id='$post_id'"); 
     702                            $result = dbquery("UPDATE ".$db_prefix."posts SET post_subject='".mysql_real_escape_string($subject)."', post_message='".mysql_real_escape_string($message)."', post_smileys='$smileys', post_edituser='".$userdata['user_id']."', post_edittime='".time()."' WHERE post_id='$post_id'"); 
    662703                        } 
    663704                        $data = dbarray(dbquery("SELECT * FROM ".$db_prefix."posts WHERE thread_id='$thread_id' ORDER BY post_datestamp ASC LIMIT 1")); 
    664705                        if ($data['post_id'] == $post_id) { 
    665                             $result = dbquery("UPDATE ".$db_prefix."threads SET thread_subject='$subject' WHERE thread_id='$thread_id'"); 
     706                            $result = dbquery("UPDATE ".$db_prefix."threads SET thread_subject='".mysql_real_escape_string($subject)."' WHERE thread_id='$thread_id'"); 
    666707                        } 
    667708                        // flag the forum and the thread as updated 
     
    808849                        rename(PATH_ATTACHMENTS.$attachment['attach_tmp'], PATH_ATTACHMENTS.$attachname); 
    809850                        chmod(PATH_ATTACHMENTS.$attachname,0664); 
    810                         $result = dbquery("INSERT INTO ".$db_prefix."forum_attachments (thread_id, post_id, attach_name, attach_realname, attach_comment, attach_ext, attach_size) VALUES ('$thread_id', '$post_id', '$attachname', '".$attachment['attach_name']."', '".$attachment['attach_comment']."', '$attachext', '".$attachment['attach_size']."')"); 
     851                        $result = dbquery("INSERT INTO ".$db_prefix."forum_attachments (thread_id, post_id, attach_name, attach_realname, attach_comment, attach_ext, attach_size) VALUES ('$thread_id', '$post_id', '".mysql_real_escape_string($attachname)."', '".mysql_real_escape_string($attachment['attach_name'])."', '".mysql_real_escape_string($attachment['attach_comment'])."', '$attachext', '".$attachment['attach_size']."')"); 
    811852                    } 
    812853                } 
     
    10201061            $variables['prefixes'] = array(); 
    10211062            foreach ($prefixes as $prefix) { 
    1022                 if (!empty($prefix)) $variables['prefixes'][] = trim($prefix); 
     1063                $prefix = trim($prefix); 
     1064                if (!empty($prefix)) $variables['prefixes'][] = $prefix; 
    10231065            } 
    10241066            if (!isset($title)) $title = $locale['415']." #".$reply_id; 
     
    10441086            } elseif ($post_id > 0 || $reply_id > 0) { 
    10451087                $subject = $pdata['post_subject']; 
    1046                 // split the subject to check for a prefix 
    1047                 if (preg_match('~(.*)\[(.*)\](.*)~', $subject, $matches)) 
    1048                 { 
    1049                     // update the subject, set the prefixes 
    1050                     $subject = trim($matches[3]); 
    1051                     $variables['prefix'] = $matches[2]; 
    1052                     $variables['new_prefix'] = '['.$matches[2].']'; 
    1053                 } 
    1054                 if ($action != "newthread" && strtolower(substr($subject,0,3)) != "re:") { 
     1088                if (!in_array($action, array("edit","newthread")) && strtolower(substr($subject,0,3)) != "re:") { 
    10551089                    $variables['subject'] = 'Re: '.$subject; 
    10561090                } else { 
     
    10881122                $bbcolor = ""; 
    10891123            } 
     1124            // do we need to deal with a subject prefix 
     1125            if (!isset($variables['prefix'])) { 
     1126                $sparray = strip_prefix($variables['subject']); 
     1127 
     1128                $variables['subject'] = $sparray['subject']; 
     1129                // check if it's a custom prefix 
     1130                if (in_array($sparray['prefix'],$variables['prefixes'])) { 
     1131                    $variables['prefix'] = $sparray['prefix']; 
     1132                    $variables['new_prefix'] = '['.$sparray['prefix'].']'; 
     1133                } else { 
     1134                    if (empty($sparray['prefix'])) { 
     1135                        $variables['prefix'] = ''; 
     1136                        $variables['new_prefix'] = '[?]'; 
     1137                    } else { 
     1138                        $variables['prefix'] = '?'; 
     1139                        $variables['new_prefix'] = '['.$sparray['prefix'].']'; 
     1140                    } 
     1141                } 
     1142            } 
     1143 
    10901144            // process attachments 
    10911145            if ($settings['attachments'] == "1" && $fdata['forum_attach'] == "1") { 
Note: See TracChangeset for help on using the changeset viewer.