Changeset 2364 in ExiteCMS for branches/PLi-Fusion/forum/post.php
- Timestamp:
- 07/29/10 17:16:11 (22 months ago)
- File:
-
- 1 edited
-
branches/PLi-Fusion/forum/post.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/PLi-Fusion/forum/post.php
r2348 r2364 62 62 // function to validate the contents of the $_POST array 63 63 function validatepost() { 64 global $locale ;64 global $locale, $fdata; 65 65 66 66 // we need both a subject and a message body … … 71 71 if ($_POST['new_prefix'] == '[?]') $_POST['new_prefix'] = ''; 72 72 73 // is a prefix required? 74 if ($fdata['forum_prefix'] && !empty($fdata['forum_prefixes']) && empty($_POST['new_prefix'])) { 75 return $locale['475']; 76 } 77 73 78 return ""; 74 79 } 75 80 76 81 // function to add or replace the prefix in the subject 77 function subject_prefix($subject, $prefix) { 82 function 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 109 function add_prefix($subject, $prefix) { 78 110 79 111 // was a prefix defined … … 83 115 84 116 // 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]); 90 122 } else { 91 123 $subject = '[' . $prefix . '] ' . $subject; 92 124 } 93 125 } 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 } 102 135 } 103 136 … … 490 523 $preview['post_subject'] = trim(stripinput(censorwords($_POST['subject'])));; 491 524 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']))); 493 526 } 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']))); 495 528 } 496 529 $preview['post_message'] = trim(stripmessageinput(censorwords($_POST['message']))); … … 614 647 // bail out if an edit is requested, but no edit rights have been detected 615 648 if ($action == "edit" && !$user_can_edit) { 616 resultdialog($locale['408'], $locale['5 02']);649 resultdialog($locale['408'], $locale['552']); 617 650 } elseif (isset($_POST["cancel"])) { 618 651 // post cancelled? … … 649 682 $smileys = isset($_POST['disable_smileys']) ? "0" : "1"; 650 683 $subject = trim(stripinput(censorwords($_POST['subject']))); 684 if (isset($tdata) && strtolower(substr($subject,0,3)) != "re:") { 651 685 if ($subject == "") { 652 686 $subject = "Re: ".$tdata['thread_subject']; 687 } else { 688 if ($action != "edit") { 689 $subject = "Re: ".$subject; 653 690 } 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 } 655 696 $message = trim(stripmessageinput(censorwords($_POST['message']))); 656 697 if ($action == 'edit') { 657 698 // update the post record 658 699 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'"); 660 701 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'"); 662 703 } 663 704 $data = dbarray(dbquery("SELECT * FROM ".$db_prefix."posts WHERE thread_id='$thread_id' ORDER BY post_datestamp ASC LIMIT 1")); 664 705 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'"); 666 707 } 667 708 // flag the forum and the thread as updated … … 808 849 rename(PATH_ATTACHMENTS.$attachment['attach_tmp'], PATH_ATTACHMENTS.$attachname); 809 850 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']."')"); 811 852 } 812 853 } … … 1020 1061 $variables['prefixes'] = array(); 1021 1062 foreach ($prefixes as $prefix) { 1022 if (!empty($prefix)) $variables['prefixes'][] = trim($prefix); 1063 $prefix = trim($prefix); 1064 if (!empty($prefix)) $variables['prefixes'][] = $prefix; 1023 1065 } 1024 1066 if (!isset($title)) $title = $locale['415']." #".$reply_id; … … 1044 1086 } elseif ($post_id > 0 || $reply_id > 0) { 1045 1087 $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:") { 1055 1089 $variables['subject'] = 'Re: '.$subject; 1056 1090 } else { … … 1088 1122 $bbcolor = ""; 1089 1123 } 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 1090 1144 // process attachments 1091 1145 if ($settings['attachments'] == "1" && $fdata['forum_attach'] == "1") {
Note: See TracChangeset
for help on using the changeset viewer.
