Initial commit
[2ch-be.git] / dev-test / zwitch / include / messaging.class.php
blob4a642ec2113c892391b8837b338836dbac973acb
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 loggedEmail($email, $directory){
18 $strReplaced = str_replace("@", "-", $email);
19 $firstChar = substr($email, 0, 1);
20 $secondChar = substr($email, 1, 1);
21 $strReplaced = trim($strReplaced);
22 $directory = $directory.$firstChar."/".$secondChar."/".$strReplaced."/";
23 return $directory;
25 function FindUser($id,$id_mail_path) {
26 $list = file($id_mail_path);
27 $em = "";
28 $err = true;
29 foreach ($list as $key => $value) {
30 if (substr(trim($value), 0, 9) == $id) {
31 $r = explode("<><>", $value);
32 $em = trim($r[1]);
33 $err = false;
36 if ($err) {
37 return false;
39 return $em;
42 function GetID($cookie,$id_mail_path) {
43 $email = $cookie;
44 $list = file($id_mail_path);
45 $em = "";
46 $err = true;
47 foreach ($list as $key => $value) {
48 $mail = explode("<><>", trim($value));
49 if ($mail[1] == trim($email)) {
50 $em = $mail[0];
51 $err = false;
55 if ($err) {
56 return false;
58 return $em;
61 function WriteMDB($user, $inf, $sender, $subj, $to) {
62 $fdir = substr($user, 0, 1);
63 $sdir = substr($user, 1, 1);
64 $udir = str_replace("@", "-", $user);
65 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
66 if (!file_exists($path)) {
67 @mkdir(MDB_PATH."{$fdir}");
68 @mkdir(MDB_PATH."{$fdir}/{$sdir}");
69 @mkdir(MDB_PATH."{$fdir}/{$sdir}/{$udir}");
71 if (file_exists($path."/ban.txt")) {
72 $banlist = file($path."/ban.txt");
73 foreach ($banlist as $key => $value) {
74 if (trim($sender) == trim($value)) {
75 echo "Message sending failed, You have been blocked by the user";
76 return false;
80 $time = time();
81 $writeData = "<id>{$time}</id><from>{$sender}</from><to>{$to}</to><subj>{$subj}</subj><msg>{$inf}</msg><read>0</read>\n";
82 $filename = $path."/".$time.".dat";
83 if (!file_exists($filename)) {
84 if(!file_put_contents($filename,$writeData)) {
85 echo "Error!";
86 return false;
88 // echo $filename;
89 // echo $writeData;
90 } else {
91 $handle = fopen($filename, "w");
92 if(!fwrite($handle, $writeData)) {
93 echo "Error!";
94 return false;
96 fclose($handle);
97 // echo $writeData;
99 return true;
102 function BlockUser($user,$kausap) {
103 $fdir = substr($user, 0, 1);
104 $sdir = substr($user, 1, 1);
105 $udir = str_replace("@", "-", $user);
106 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
107 $banlist = file($path);
108 $meron = false;
109 foreach ($banlist as $key => $value) {
110 if (trim($value) == trim($kausap))
111 $meron = true;
113 if (!$meron) {
114 $handle = fopen($path, "a");
115 $bandata = trim($kausap)."\n";
116 if(!fwrite($handle, $bandata))
117 return false;
118 fclose($handle);
120 return true;
123 function UnblockUser($user,$kausap) {
124 $fdir = substr($user, 0, 1);
125 $sdir = substr($user, 1, 1);
126 $udir = str_replace("@", "-", $user);
127 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
128 $banlist = file($path);
129 foreach ($banlist as $key => $value) {
130 if (trim($value) == trim($kausap))
131 unset($banlist[$key]);
133 $banlist = implode("\n", $banlist);
134 if (empty($banlist)) {
135 if(!file_put_contents($path, $banlist))
136 return true;
137 } else {
138 if(!file_put_contents($path, $banlist))
139 return false;
141 return true;
144 function CheckBanList($user,$kausap) {
145 $fdir = substr($user, 0, 1);
146 $sdir = substr($user, 1, 1);
147 $udir = str_replace("@", "-", $user);
148 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/ban.txt";
149 $banlist = file($path);
150 foreach ($banlist as $key => $value) {
151 if (trim($value) == trim($kausap))
152 return true;
154 return false;
157 function ReadMDB($user) {
158 $fdir = substr($user, 0, 1);
159 $sdir = substr($user, 1, 1);
160 $udir = str_replace("@", "-", $user);
161 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
162 $messages = array();
163 $i = 0;
164 foreach (glob($path."/*.dat") as $filename) {
165 $m = file($filename);
166 $j = 0;
167 foreach ($m as $key => $value) {
168 $messages[$i][$j] = $value;
169 $j++;
171 $i++;
173 return $messages;
176 function specificMDB($user, $dat, $bool = FALSE) {
177 $fdir = substr($user, 0, 1);
178 $sdir = substr($user, 1, 1);
179 $udir = str_replace("@", "-", $user);
180 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
181 // echo $dat."<br />";
182 $messages = array();
183 if(file_exists($path."/{$dat}.dat")){
184 $i = 0;
185 $messages = file("{$path}/{$dat}.dat");
187 if($bool){
188 return $messages[0];
189 }else{
190 // $messages = array_slice($messages, -4, 4);
191 return $messages;
193 }else{
194 return false;
197 // function specificMDB($user, $dat) {
198 // $fdir = substr($user, 0, 1);
199 // $sdir = substr($user, 1, 1);
200 // $udir = str_replace("@", "-", $user);
201 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
202 // $messages = array();
203 // if(file_exists($path."/{$dat}.dat")){
204 // $i = 0;
205 // //$dat = (!preg_match("/u_/i", $dat)) ? $dat : "u_".$dat;
207 // foreach (glob($path."/{$dat}.dat") as $filename) {
208 // $m = file($filename);
209 // $j = 0;
210 // foreach ($m as $key => $value) {
211 // // print_r($messages);
212 // $messages[$i][$j] = $value;
213 // $j++;
214 // }
215 // $i++;
216 // }
217 // return $messages;
218 // }else{
219 // return false;
220 // }
221 // }
223 // function renameMDB($user, $dat) {
224 // $fdir = substr($user, 0, 1);
225 // $sdir = substr($user, 1, 1);
226 // $udir = str_replace("@", "-", $user);
227 // $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
228 // $messages = array();
229 // $i = 0;
230 // $substr = $dat.".dat";
231 // $substr2 = substr($substr, 2);
232 // if(preg_match("/u_/i", $substr)){
233 // rename($_SESSION['sLoggedDir'] ."/".$substr, $_SESSION['sLoggedDir'] ."/".$substr2);
234 // }
235 // }
237 function within_str($subject, $lsearch, $rsearch) {
238 $data = strstr($subject, $lsearch);
239 $data = str_replace($lsearch, "", $data);
240 $trim = strstr($data, $rsearch);
242 return(str_replace($trim, "", $data));
245 // function getContent($files) {
246 // $i = 0;
247 // $j = 0;
248 // $homepage = file_get_contents($files);
249 // $test = explode(PHP_EOL, $homepage);
250 // foreach($test as $value){
251 // // echo $value."<br>";
252 // $valueTest = preg_replace('/\<[a-z]*>/', '', $value);
253 // $trim = preg_replace('/\<\/[a-z]*>/', '|', $valueTest);
254 // $valueTest1[] = rtrim($trim, '|');
255 // }
256 // return $valueTest1;
257 // // print_r($valueTest1);
258 // }
260 function getContent($files) {
261 $i = 0;
262 $j = 0;
263 $homepage = file_get_contents($files);
264 $test = explode(PHP_EOL, $homepage);
265 return $test;
268 function getContent2($files) {
269 $i = 0;
270 $j = 0;
271 $homepage = file($files);
273 return $homepage;
274 // print_r($valueTest1);
277 function passContent($array) {
278 $fetch = array();
279 foreach ($array as $formidable) {
280 // print_r($array);
281 if($formidable!=''){
282 $fetch[] = explode('|', $formidable);
285 // print_r($array)."<br>";
286 return $fetch;
290 function GetImgTrip($mail) {
291 $mail = trim($mail);
292 $fdir = substr($mail, 0, 1);
293 $sdir = substr($mail, 1, 1);
294 $impo = file_get_contents(DB_PATH."$fdir/$sdir/$mail");
295 if ($impo != NULL && $impo != "") {
296 return $impo;
297 } else {
298 return false;
302 function AddPostLimit($id,$plimit_path,$mah) {
303 if($mah) {
304 $handle = fopen($plimit_path.$id.".txt", "a");
305 if(!fwrite($handle,"1\n"))
306 return false;
307 fclose($handle);
308 return true;
309 } else {
310 $handle = fopen($plimit_path.$id.".txt", "a");
311 if(!fwrite($handle,"1\n"))
312 return false;
313 fclose($handle);
314 return true;
318 function CheckPostLimit($id,$plimit_path,$mah) {
319 if($mah) {
320 if (file_exists($plimit_path.$id.".txt")) {
321 $post_number = file($plimit_path.$id.".txt");
322 $post_number = count($post_number);
323 return $post_number;
325 return false;
326 } else {
327 if (file_exists($plimit_path.$id.".txt")) {
328 $post_number = file($plimit_path.$id.".txt");
329 $post_number = count($post_number);
330 return $post_number;
332 return false;