Initial commit
[2ch-be.git] / dev-test / rewrite / include / messaging.bak.class.php
blob63239e4601d13b218882303d3d1e810d9fae7ecc
1 <?php
2 class Message {
3 function BeSanitize($string) {
4 if (strlen($string) > 250) {
5 $echo = "Content too long";
6 return false;
7 } else {
8 $string = str_replace("<", "&lt;", $string);
9 $string = str_replace(">", "&gt;", $string);
10 $string = str_replace("\n", "<br>", $string);
11 $string = str_replace(" ", "&nbsp;", $string);
12 $string = urlencode($string);
13 return $string;
17 function FindUser($id,$id_mail_path) {
18 $list = file($id_mail_path);
19 $em = "";
20 $err = true;
21 foreach ($list as $key => $value) {
22 if (substr(trim($value), 0, 9) == $id) {
23 $r = explode("<><>", $value);
24 $em = trim($r[1]);
25 $err = false;
28 if ($err) {
29 return false;
31 return $em;
34 function GetID($cookie,$id_mail_path) {
35 $email = Decrypt($_COOKIE['DMDM'], KEY);
36 $list = file($id_mail_path);
37 $em = "";
38 $err = true;
39 foreach ($list as $key => $value) {
40 $mail = explode("<><>", trim($value));
41 if ($mail[1] == trim($email)) {
42 $em = $mail[0];
43 $err = false;
47 if ($err) {
48 return false;
50 return $em;
53 function WriteMDB($user, $inf, $sender, $subj, $to) {
54 $fdir = substr($user, 0, 1);
55 $sdir = substr($user, 1, 1);
56 $udir = str_replace("@", "-", $user);
57 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
58 if (!file_exists($path)) {
59 @mkdir(MDB_PATH."{$fdir}");
60 @mkdir(MDB_PATH."{$fdir}/{$sdir}");
61 @mkdir(MDB_PATH."{$fdir}/{$sdir}/{$udir}");
63 if (file_exists($path."/ban.txt")) {
64 $banlist = file($path."/ban.txt");
65 foreach ($banlist as $key => $value) {
66 if (trim($sender) == trim($value)) {
67 echo "メッセージ送信が失敗し、ユーザーによってブロックされた<br>";
68 return false;
72 $time = time();
73 $writeData = "<id>{$time}</id><from>{$sender}</from><to>{$to}</to><subj>{$subj}</subj><msg>{$inf}</msg><read>0</read>\n";
74 $filename = $path."/".$time.".dat";
75 if (!file_exists($filename)) {
76 if(!file_put_contents($filename,$writeData)) {
77 echo "Error!";
78 return false;
80 // echo $filename;
81 // echo $writeData;
82 } else {
83 $handle = fopen($filename, "w");
84 if(!fwrite($handle, $writeData)) {
85 echo "Error!";
86 return false;
88 fclose($handle);
89 // echo $writeData;
91 return true;
94 function BlockUser($user,$kausap) {
95 $fdir = substr($user, 0, 1);
96 $sdir = substr($user, 1, 1);
97 $udir = str_replace("@", "-", $user);
98 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
99 $banlist = file($path);
100 $meron = false;
101 foreach ($banlist as $key => $value) {
102 if (trim($value) == trim($kausap))
103 $meron = true;
105 if (!$meron) {
106 $handle = fopen($path, "a");
107 $bandata = trim($kausap)."\n";
108 if(!fwrite($handle, $bandata))
109 return false;
110 fclose($handle);
112 return true;
115 function UnblockUser($user,$kausap) {
116 $fdir = substr($user, 0, 1);
117 $sdir = substr($user, 1, 1);
118 $udir = str_replace("@", "-", $user);
119 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
120 $banlist = file($path);
121 foreach ($banlist as $key => $value) {
122 if (trim($value) == trim($kausap))
123 unset($banlist[$key]);
125 $banlist = implode("\n", $banlist);
126 if (empty($banlist)) {
127 if(!file_put_contents($path, $banlist))
128 return true;
129 } else {
130 if(!file_put_contents($path, $banlist))
131 return false;
133 return true;
136 function CheckBanList($user,$kausap) {
137 $fdir = substr($user, 0, 1);
138 $sdir = substr($user, 1, 1);
139 $udir = str_replace("@", "-", $user);
140 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
141 $banlist = file($path);
142 foreach ($banlist as $key => $value) {
143 if (trim($value) == trim($kausap))
144 return true;
146 return false;
149 function ReadMDB($user) {
150 $fdir = substr($user, 0, 1);
151 $sdir = substr($user, 1, 1);
152 $udir = str_replace("@", "-", $user);
153 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
154 $messages = array();
155 $i = 0;
156 foreach (glob($path."/*.dat") as $filename) {
157 $m = file($filename);
158 $j = 0;
159 foreach ($m as $key => $value) {
160 $messages[$i][$j] = $value;
161 $j++;
163 $i++;
165 return $messages;
168 function specificMDB($user, $dat, $bool = FALSE) {
169 $fdir = substr($user, 0, 1);
170 $sdir = substr($user, 1, 1);
171 $udir = str_replace("@", "-", $user);
172 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
173 $messages = array();
174 if(file_exists($path."/{$dat}.dat")){
175 $i = 0;
176 $messages = file("{$path}/{$dat}.dat");
178 if($bool){
179 return $messages[0];
180 }else{
181 $messages = array_slice($messages, -4, 4);
182 return $messages;
184 }else{
185 return false;
188 // function specificMDB($user, $dat) {
189 // $fdir = substr($user, 0, 1);
190 // $sdir = substr($user, 1, 1);
191 // $udir = str_replace("@", "-", $user);
192 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
193 // $messages = array();
194 // if(file_exists($path."/{$dat}.dat")){
195 // $i = 0;
196 // //$dat = (!preg_match("/u_/i", $dat)) ? $dat : "u_".$dat;
198 // foreach (glob($path."/{$dat}.dat") as $filename) {
199 // $m = file($filename);
200 // $j = 0;
201 // foreach ($m as $key => $value) {
202 // // print_r($messages);
203 // $messages[$i][$j] = $value;
204 // $j++;
205 // }
206 // $i++;
207 // }
208 // return $messages;
209 // }else{
210 // return false;
211 // }
212 // }
214 // function renameMDB($user, $dat) {
215 // $fdir = substr($user, 0, 1);
216 // $sdir = substr($user, 1, 1);
217 // $udir = str_replace("@", "-", $user);
218 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
219 // $messages = array();
220 // $i = 0;
221 // $substr = $dat.".dat";
222 // $substr2 = substr($substr, 2);
223 // if(preg_match("/u_/i", $substr)){
224 // rename($_SESSION['sLoggedDir'] ."/".$substr, $_SESSION['sLoggedDir'] ."/".$substr2);
225 // }
226 // }
228 function within_str($subject, $lsearch, $rsearch) {
229 $data = strstr($subject, $lsearch);
230 $data = str_replace($lsearch, "", $data);
231 $trim = strstr($data, $rsearch);
233 return(str_replace($trim, "", $data));
236 // function getContent($files) {
237 // $i = 0;
238 // $j = 0;
239 // $homepage = file_get_contents($files);
240 // $test = explode(PHP_EOL, $homepage);
241 // foreach($test as $value){
242 // // echo $value."<br>";
243 // $valueTest = preg_replace('/\<[a-z]*>/', '', $value);
244 // $trim = preg_replace('/\<\/[a-z]*>/', '|', $valueTest);
245 // $valueTest1[] = rtrim($trim, '|');
246 // }
247 // return $valueTest1;
248 // // print_r($valueTest1);
249 // }
251 function getContent($files) {
252 $i = 0;
253 $j = 0;
254 $homepage = file_get_contents($files);
255 $test = explode(PHP_EOL, $homepage);
256 return $test;
259 function getContent2($files) {
260 $i = 0;
261 $j = 0;
262 $homepage = file($files);
264 return $homepage;
265 // print_r($valueTest1);
268 function passContent($array) {
269 $fetch = array();
270 foreach ($array as $formidable) {
271 // print_r($array);
272 if($formidable!=''){
273 $fetch[] = explode('|', $formidable);
276 // print_r($array)."<br>";
277 return $fetch;
281 function GetImgTrip($mail) {
282 $mail = trim($mail);
283 $fdir = substr($mail, 0, 1);
284 $sdir = substr($mail, 1, 1);
285 $impo = file_get_contents(DB_PATH."$fdir/$sdir/$mail");
286 if ($impo != NULL && $impo != "") {
287 return $impo;
288 } else {
289 return false;
293 function AddPostLimit($id,$plimit_path,$mah) {
294 if($mah) {
295 $handle = fopen($plimit_path.$id.".txt", "a");
296 if(!fwrite($handle,"1\n"))
297 return false;
298 fclose($handle);
299 return true;
300 } else {
301 $handle = fopen($plimit_path.$id.".txt", "a");
302 if(!fwrite($handle,"1\n"))
303 return false;
304 fclose($handle);
305 return true;
309 function CheckPostLimit($id,$plimit_path,$mah) {
310 if($mah) {
311 if (file_exists($plimit_path.$id.".txt")) {
312 $post_number = file($plimit_path.$id.".txt");
313 $post_number = count($post_number);
314 return $post_number;
316 return false;
317 } else {
318 if (file_exists($plimit_path.$id.".txt")) {
319 $post_number = file($plimit_path.$id.".txt");
320 $post_number = count($post_number);
321 return $post_number;
323 return false;