Initial commit
[2ch-be.git] / dev-test / mb / noti.php
blob0068e7298757dd2c37653e3711026448c0fc2634
1 <?php
2 error_reporting(E_ALL); ini_set("display_errors", 1);
3 require_once '../include/messaging.class.php';
4 $init = new Message;
5 if (!isset($_COOKIE['DMDM']) && !isset($_COOKIE['MDMD'])) {
6 echo "NG";
7 exit;
10 $email = urldecode(trim($_GET['un']));
11 if(filter_var($email, FILTER_VALIDATE_EMAIL))
12 $email = $email;
13 else
14 die("NG");
16 define('MDB_PATH', '/home/mdb/');
19 function loggedEmail($email, $directory){
20 $strReplaced = str_replace("@", "-", $email);
21 $firstChar = substr($email, 0, 1);
22 $secondChar = substr($email, 1, 1);
23 $directory = $directory.$firstChar."/".$secondChar."/".$strReplaced."/";
24 return $directory;
27 function within_str($subject, $lsearch, $rsearch) {
28 $data = strstr($subject, $lsearch);
29 $data = str_replace($lsearch, "", $data);
30 $trim = strstr($data, $rsearch);
32 return(str_replace($trim, "", $data));
35 function notification($directory,$init) {
36 $i = 0;
37 @chdir($directory);
38 try{
39 $files = glob("*.dat");
40 foreach($files as $filename){
41 $value = $init->getContent($filename);
42 //echo "<pre>";
43 //print_r($value);
44 //echo "</pre>";
45 //echo max($value);
46 $from = $init->within_str(max($value), "<from>", "</from>");
47 // $to = $init->within_str(max($value), "<to>", "</to>");
48 $id = $init->within_str(max($value), "<id>", "</id>");
49 // $subj = $init->within_str(max($value), "<subj>", "</subj>");
50 $read = $init->within_str(max($value), "<read>", "</read>");
51 // $msg = $init->within_str(max($value), "<msg>", "</msg>");
52 $array[$filename] = array("id" => $id, "read"=>$read, "from" => $from);
53 // $array[$filename] = array("id" => $id, "subj" =>$subj, "read"=>$read, "msg"=>$msg ,"from" => $from, "to" => $to, );
55 //print_r($array);
56 //$array = $init->array_sort($array, 'id', SORT_ASC);
57 //echo "<pre>";
58 //print_r($array);
59 //echo "</pre>";
60 if(!$files){
61 throw new Exception("");
62 }else{
63 // print_r($array);
64 $array = $init->array_sort($array, 'id', SORT_ASC);
65 foreach($array as $filename => $value){
66 // $array = file($filename);
67 // $value = max($array);
68 //echo $value;
69 $checkUnread = $value['read'];
70 if($checkUnread==0){
71 $date = $value['id'];
72 $i++;
75 return ($i==0) ? '' : $i.",".$date;
77 }catch(Exception $e){
78 return $e->getMessage();
83 $userDirectory = loggedEmail($email, MDB_PATH);
85 $count = notification($userDirectory,$init);
86 echo (empty($count)) ? "0,0" : $count;