Initial commit
[2ch-be.git] / dev-test / old_dev / include / messaging1.class.php
blobd0123063ab454bcc2bfbcbeb0ccfa7055a1751c2
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 "ƒ�ƒbƒZ�[ƒW‘—�M‚ªŽ¸”s‚µ�Aƒ†�[ƒU�[‚É‚æ‚Á‚ăuƒ�ƒbƒN‚³‚ꂽ<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 $count = (count($messages) <= 4) ? "TRUE" : "FALSE";
182 $messages = array_slice($messages, -4, 4);
183 return array($messages, $count);
185 }else{
186 return false;
189 // function specificMDB($user, $dat) {
190 // $fdir = substr($user, 0, 1);
191 // $sdir = substr($user, 1, 1);
192 // $udir = str_replace("@", "-", $user);
193 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
194 // $messages = array();
195 // if(file_exists($path."/{$dat}.dat")){
196 // $i = 0;
197 // //$dat = (!preg_match("/u_/i", $dat)) ? $dat : "u_".$dat;
199 // foreach (glob($path."/{$dat}.dat") as $filename) {
200 // $m = file($filename);
201 // $j = 0;
202 // foreach ($m as $key => $value) {
203 // // print_r($messages);
204 // $messages[$i][$j] = $value;
205 // $j++;
206 // }
207 // $i++;
208 // }
209 // return $messages;
210 // }else{
211 // return false;
212 // }
213 // }
215 // function renameMDB($user, $dat) {
216 // $fdir = substr($user, 0, 1);
217 // $sdir = substr($user, 1, 1);
218 // $udir = str_replace("@", "-", $user);
219 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
220 // $messages = array();
221 // $i = 0;
222 // $substr = $dat.".dat";
223 // $substr2 = substr($substr, 2);
224 // if(preg_match("/u_/i", $substr)){
225 // rename($_SESSION['sLoggedDir'] ."/".$substr, $_SESSION['sLoggedDir'] ."/".$substr2);
226 // }
227 // }
229 function within_str($subject, $lsearch, $rsearch) {
230 $data = strstr($subject, $lsearch);
231 $data = str_replace($lsearch, "", $data);
232 $trim = strstr($data, $rsearch);
234 return(str_replace($trim, "", $data));
237 function countMessage($subject) {
238 $count=0;
239 $str = $this->getContent3($subject);
240 foreach($str as $key){
241 if($this->within_str($key, "<read>", "</read>")==0 && !empty($key)){
242 $count++;
245 return $count;
248 // function getContent($files) {
249 // $i = 0;
250 // $j = 0;
251 // $homepage = file_get_contents($files);
252 // $test = explode(PHP_EOL, $homepage);
253 // foreach($test as $value){
254 // // echo $value."<br>";
255 // $valueTest = preg_replace('/\<[a-z]*>/', '', $value);
256 // $trim = preg_replace('/\<\/[a-z]*>/', '|', $valueTest);
257 // $valueTest1[] = rtrim($trim, '|');
258 // }
259 // return $valueTest1;
260 // // print_r($valueTest1);
261 // }
263 function getContent($files) {
264 $i = 0;
265 $j = 0;
266 $homepage = file_get_contents($files);
267 $test = explode(PHP_EOL, $homepage);
268 return $test;
270 function getContent3($files) {
271 $i = 0;
272 $j = 0;
273 $homepage = file_get_contents($files);
274 $test = explode(PHP_EOL, $homepage);
275 return $test;
278 function getContent2($files) {
279 $i = 0;
280 $j = 0;
281 $homepage = file($files);
283 return $homepage;
284 // print_r($valueTest1);
287 function passContent($array) {
288 $fetch = array();
289 foreach ($array as $formidable) {
290 // print_r($array);
291 if($formidable!=''){
292 $fetch[] = explode('|', $formidable);
295 // print_r($array)."<br>";
296 return $fetch;
300 function GetImgTrip($mail) {
301 $mail = trim($mail);
302 $fdir = substr($mail, 0, 1);
303 $sdir = substr($mail, 1, 1);
304 $impo = file_get_contents(DB_PATH."$fdir/$sdir/$mail");
305 if ($impo != NULL && $impo != "") {
306 return $impo;
307 } else {
308 return false;
312 function AddPostLimit($id,$plimit_path,$mah) {
313 if($mah) {
314 $handle = fopen($plimit_path.$id.".txt", "a");
315 if(!fwrite($handle,"1\n"))
316 return false;
317 fclose($handle);
318 return true;
319 } else {
320 $handle = fopen($plimit_path.$id.".txt", "a");
321 if(!fwrite($handle,"1\n"))
322 return false;
323 fclose($handle);
324 return true;
328 function CheckPostLimit($id,$plimit_path,$mah) {
329 if($mah) {
330 if (file_exists($plimit_path.$id.".txt")) {
331 $post_number = file($plimit_path.$id.".txt");
332 $post_number = count($post_number);
333 return $post_number;
335 return false;
336 } else {
337 if (file_exists($plimit_path.$id.".txt")) {
338 $post_number = file($plimit_path.$id.".txt");
339 $post_number = count($post_number);
340 return $post_number;
342 return false;
346 function CheckBanMessaging() {
347 $email = Decrypt($_COOKIE['DMDM'], KEY);
348 $fdir = substr($email, 0, 1);
349 $sdir = substr($email, 1, 1);
350 $info = file(DB_PATH."$fdir/$sdir/$email");
351 if(abs(trim($info[3])) < 1000)
352 return true;
353 return false;
358 function array_sort($array, $on, $order=SORT_ASC) {
359 $new_array = array();
360 $sortable_array = array();
361 if (count($array) > 0) {
362 foreach ($array as $k => $v) {
363 if (is_array($v)) {
364 foreach ($v as $k2 => $v2) {
365 if ($k2 == $on) {
366 $sortable_array[$k] = $v2;
369 } else {
370 $sortable_array[$k] = $v;
374 switch ($order) {
375 case SORT_ASC:
376 asort($sortable_array);
377 break;
378 case SORT_DESC:
379 arsort($sortable_array);
380 break;
383 foreach ($sortable_array as $k => $v) {
384 $new_array[$k] = $array[$k];
388 return $new_array;
391 function GetPath() {
392 $email = Decrypt($_COOKIE['DMDM'], KEY);
393 $fdir = substr($email, 0, 1);
394 $sdir = substr($email, 1, 1);
395 $tmp = strrpos($email, "@");
396 if ($tmp != false) {
397 $zz = $email;
398 $zz[$tmp] = "-";
400 $info = MDB_PATH."$fdir/$sdir/$zz";
401 return $info;