Initial commit
[2ch-be.git] / dev-test / reply2.php
blobd8c228698995c62edc70e43ffbb063dd1330fb22
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="Shift_JIS">
5 </head>
6 <body>
7 <?php
8 if (!isset($_COOKIE['DMDM']) && !isset($_COOKIE['MDMD'])) {
9 header('location:index.php');
10 exit;
12 session_start();
13 include('encrypt.php');
15 //$sub = addslashes(trim($_POST['zxcvbnm']));
16 $sub = Decrypt(addslashes(trim($_POST['zxcvbnm'])), KEY);
17 $msg = trim($_POST['msg']);
18 $sbj = trim($_POST['sbj']);
20 if (strlen($msg) > 250) {
21 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">長すぎるコンテンツ</div>";
22 header('Location:message.php?d='.$file);
23 exit;
26 $from = substr($sub, 0, 9);
27 $to = substr($sub, 9, 9);
28 $file = substr($sub, 18);
30 $reply = new Message;
31 if($reply->CheckBanMessaging()) {
32 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">BEポイントが足りないので、メッセージを送信することができません。</div>";
33 header('Location:message.php?d='.$file);
34 exit;
37 $msg = $reply->BeSanitize($msg);
38 $reply_receiver = $reply->FindUser($to,$id_mail_path);
40 $fdir = substr($reply_receiver, 0, 1);
41 $sdir = substr($reply_receiver, 1, 1);
42 $udir = str_replace("@", "-", $reply_receiver);
43 $file_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/{$file}.dat";
44 $file_del_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/del/{$file}.dat";
45 //$ufile_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/u_{$file}.dat";
46 $tmp_copy_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
48 if (file_exists($tmp_copy_path."/ban.txt")) {
49 $banlist = file($tmp_copy_path."/ban.txt");
50 foreach ($banlist as $key => $value) {
51 if (trim($from) == trim($value)) {
52 //echo "Message sending failed, You have been blocked by the user";
53 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥ メッセージ送信が失敗し、ユーザーによってブロックされています </div>";
54 header('Location:message.php?d='.$file);
55 exit;
60 $sender_path = $reply->FindUser($from,$id_mail_path);
61 if ($sender_path == false) {
62 echo "NG";
63 exit;
66 $allow_post = $reply->CheckPostLimit($from,$plimit_path,TRUE);
67 if (($allow_post >= 60) && ($allow_post != false)) {
68 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">到達した後の制限は、次の分お待ちください</div>";
69 header('Location:message.php?d='.$file);
70 exit;
73 $allow_post = $reply->CheckPostLimit($from,$plimit_hpath,FALSE);
74 if (($allow_post >= 600) && ($allow_post != false)) {
75 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">到達した後の制限は、次の1時間お待ちください</div>";
76 header('Location:message.php?d='.$file);
77 exit;
80 $fdir2 = substr($sender_path, 0, 1);
81 $sdir2 = substr($sender_path, 1, 1);
82 $udir2 = str_replace("@", "-", $sender_path);
83 $sender_file_path = MDB_PATH."{$fdir2}/{$sdir2}/{$udir2}/{$file}.dat";
84 //$usender_file_path = MDB_PATH."{$fdir2}/{$sdir2}/{$udir2}/u_{$file}.dat";
85 date_default_timezone_set("Asia/Tokyo");
86 $time = time();
88 $writeData = "<id>{$time}</id><from>{$from}</from><to>{$to}</to><subj>{$sbj}</subj><msg>{$msg}</msg><read>0</read>¥n";
89 $writeDataSender = "<id>{$time}</id><from>{$from}</from><to>{$to}</to><subj>{$sbj}</subj><msg>{$msg}</msg><read>1</read>¥n";
91 if (file_exists($file_del_path)) {
92 file_put_contents($file_path, "");
93 unlink($file_del_path);
96 //echo $file_path."<br>";
97 //echo $sender_file_path;
98 if (!file_exists($file_path)) {
99 //echo "--una--";
100 if (file_exists($sender_file_path)) {
101 if (!file_exists($tmp_copy_path)) {
102 @mkdir(MDB_PATH."{$fdir}");
103 @mkdir(MDB_PATH."{$fdir}/{$sdir}");
104 @mkdir(MDB_PATH."{$fdir}/{$sdir}/{$udir}");
106 if (file_exists($tmp_copy_path."/ban.txt")) {
107 $banlist = file($tmp_copy_path."/ban.txt");
108 foreach ($banlist as $key => $value) {
109 if (trim($from) == trim($value)) {
110 //echo "Message sending failed, You have been blocked by the user";
111 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">メッセージ送信が失敗し、ユーザーによってブロックされた</div>";
112 header('Location:message.php?d='.$file);
113 // header('Location:inbox.php');
114 exit;
118 $aa = file($sender_file_path);
119 $aa = implode("¥n", $aa);
120 $aa = str_replace("¥n¥n", "¥n", $aa); // A pain before I found this bug!
121 file_put_contents($file_path, $aa);
122 $handle = fopen($sender_file_path, "a");
123 //if(!fwrite($handle, $writeData)) {
124 if(!fwrite($handle, $writeDataSender)) {
125 echo "Error 1!";
126 exit;
128 fclose($handle);
129 } else {
130 echo "Error 2!";
132 if (trim($sender_file_path) <> trim($file_path)) {
133 $handle = fopen($file_path, "a");
134 if(!fwrite($handle, $writeData)) {
135 echo "Error 3!";
136 exit;
138 fclose($handle);
141 $add_post = $reply->AddPostLimit($from,$plimit_path,TRUE);
142 $add_post = $reply->AddPostLimit($from,$plimit_hpath,FALSE);
144 # $_SESSION['msg'] = "<div class=¥"alert alert-success¥">正常に送信されたメッセージ</div>";
145 $_SESSION['msg'] = "<div class=¥"alert alert-success¥">正常に送信されたメッセージ</div>";
146 header('Location:message.php?d='.$file);
147 // header('Location:inbox.php');
149 } else {
150 if (file_exists($tmp_copy_path."/ban.txt")) {
151 $banlist = file($tmp_copy_path."/ban.txt");
152 foreach ($banlist as $key => $value) {
153 if (trim($from) == trim($value)) {
154 //echo "Message sending failed, You have been blocked by the user";
155 $_SESSION['msg'] = "<div class=¥"alert alert-danger¥">メッセージ送信が失敗し、ユーザーによってブロックされた</div>";
156 header('Location:message.php?d='.$file);
157 // header('Location:inbox.php');
158 exit;
162 //echo "--pangalawa--";
163 $handle = fopen($sender_file_path, "a");
164 //if(!fwrite($handle, $writeData)) {
165 if(!fwrite($handle, $writeDataSender)) {
166 echo "Error 4";
167 exit;
169 fclose($handle);
170 if (trim($sender_file_path) <> trim($file_path)) {
171 $handle = fopen($file_path, "a");
172 if(!fwrite($handle, $writeData)) {
173 echo "Error 5";
174 exit;
176 fclose($handle);
179 $add_post = $reply->AddPostLimit($from,$plimit_path,TRUE);
180 $add_post = $reply->AddPostLimit($from,$plimit_hpath,FALSE);
181 # $_SESSION['msg'] = "<div class=¥"alert alert-success¥">正常に送信されたメッセージ</div>";
182 $_SESSION['msg'] = "<div class=¥"alert alert-success¥">正常に送信されたメッセージ</div>";
183 // header('Location:inbox.php');
184 header('Location:message.php?d='.$file);
188 </body>
189 </html>