Initial commit
[2ch-be.git] / dev-test / old / messaging.class.php
blob7a6cf9b29a072164f0d892d19224a85201a847dd
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 = filter_var($string, FILTER_SANITIZE_STRING);
9 $string = str_replace("<", "&lt;", $string);
10 $string = str_replace(">", "&gt;", $string);
11 $string = str_replace("\n", "<br>", $string);
12 $string = str_replace(" ", "&nbsp;", $string);
13 $string = urlencode($string);
14 return $string;
18 function FindUser($id,$id_mail_path) {
19 $list = file($id_mail_path);
20 $em = "";
21 foreach ($list as $key => $value) {
22 if (substr($value, 0, 9) == $id) {
23 $r = explode("<><>", $value);
24 $em = trim($r[1]);
27 return $em;
30 function WriteMDB($user, $inf) {
31 $fdir = substr($user, 0, 1);
32 $sdir = substr($user, 1, 1);
33 $udir = str_replace("@", "-", $user);
34 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
35 if (!file_exists($path)) {
36 @mkdir(MDB_PATH."{$fdir}");
37 @mkdir(MDB_PATH."{$fdir}/{$sdir}");
38 @mkdir(MDB_PATH."{$fdir}/{$sdir}/{$udir}");
40 $time = time();
41 $writeData = "<id>{$time}</id><c_id></c_id><from>UNDECIDED_YET</from><msg>{$inf}</msg>\n";
42 $filename = $path."/u_".$time.".dat";
43 if (!file_exists($filename)) {
44 if(!file_put_contents($filename,$writeData)) {
45 echo "Error!";
46 return false;
48 echo $filename;
49 echo $writeData;
50 } else {
51 $handle = fopen($filename, "a+");
52 if(!fwrite($handle, $writeData)) {
53 echo "Error!";
54 return false;
56 fclose($handle);
57 echo $writeData;
59 return true;