Initial commit
[2ch-be.git] / dev-test / old_dev / bak / messaging / messaging.class.php
blob1b386c8b0a2fda91069dbb0772b8985f6835c75c
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 $err = true;
22 foreach ($list as $key => $value) {
23 if (substr(trim($value), 0, 9) == $id) {
24 $r = explode("<><>", $value);
25 $em = trim($r[1]);
26 $err = false;
29 if ($err) {
30 return false;
32 return $em;
35 function GetID($cookie,$id_mail_path) {
36 $email = Decrypt($_COOKIE['DMDM'], KEY);
37 $list = file($id_mail_path);
38 $em = "";
39 $err = true;
40 foreach ($list as $key => $value) {
41 $mail = explode("<><>", trim($value));
42 if ($mail[1] == trim($email)) {
43 $em = $mail[0];
44 $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 $time = time();
64 $writeData = "<id>{$time}</id><from>{$sender}</from><to>{$to}</to><subj>{$subj}</subj><msg>{$inf}</msg>\n";
65 $filename = $path."/u_".$time.".dat";
66 if (!file_exists($filename)) {
67 if(!file_put_contents($filename,$writeData)) {
68 echo "Error!";
69 return false;
71 // echo $filename;
72 // echo $writeData;
73 } else {
74 $handle = fopen($filename, "a+");
75 if(!fwrite($handle, $writeData)) {
76 echo "Error!";
77 return false;
79 fclose($handle);
80 // echo $writeData;
82 return true;
85 function ReadMDB($user) {
86 $fdir = substr($user, 0, 1);
87 $sdir = substr($user, 1, 1);
88 $udir = str_replace("@", "-", $user);
89 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
90 $messages = array();
91 $i = 0;
92 foreach (glob($path."/*.dat") as $filename) {
93 $m = file($filename);
94 $j = 0;
95 foreach ($m as $key => $value) {
96 $messages[$i][$j] = $value;
97 $j++;
99 $i++;
101 return $messages;
104 function specificMDB($user, $dat) {
105 $fdir = substr($user, 0, 1);
106 $sdir = substr($user, 1, 1);
107 $udir = str_replace("@", "-", $user);
108 $path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
109 $messages = array();
110 $i = 0;
111 //$dat = (!preg_match("/u_/i", $dat)) ? $dat : "u_".$dat;
113 foreach (glob($path."/{$dat}.dat") as $filename) {
114 $m = file($filename);
115 $j = 0;
116 foreach ($m as $key => $value) {
117 $messages[$i][$j] = $value;
118 $j++;
120 $i++;
122 return $messages;
125 function within_str($subject, $lsearch, $rsearch) {
126 $data = strstr($subject, $lsearch);
127 $data = str_replace($lsearch, "", $data);
128 $trim = strstr($data, $rsearch);
130 return(str_replace($trim, "", $data));
133 function getContent($files){
134 $i = 0;
135 $j = 0;
136 $homepage = file_get_contents($files);
137 $test = explode(PHP_EOL, $homepage);
138 foreach($test as $value){
139 // echo $value."<br>";
140 $valueTest = preg_replace('/\<[a-z]*>/', '', $value);
141 $trim = preg_replace('/\<\/[a-z]*>/', '|', $valueTest);
142 $valueTest1[] = rtrim($trim, '|');
144 return $valueTest1;
145 // print_r($valueTest1);
148 function passContent($array){
149 $fetch = array();
150 foreach ($array as $formidable) {
151 if($formidable!=''){
152 $fetch[] = explode('|', $formidable);
155 // print_r($array)."<br>";
156 return $fetch;