Initial commit
[2ch-be.git] / dev-test / mb / noti.bak~
blob935b05473a6f4e02df8f8be5cebe5c538f79976d
1 <?php
3 if (!isset($_COOKIE['DMDM']) && !isset($_COOKIE['MDMD'])) {
4         echo "NG";
5         exit;
8 $email = urldecode(trim($_GET['un']));
9 if(filter_var($email, FILTER_VALIDATE_EMAIL))
10         $email = $email;
11 else
12         die("NG");
14 define('MDB_PATH', '/home/mdb/');
17 function loggedEmail($email, $directory){
18         $strReplaced = str_replace("@", "-", $email);
19         $firstChar   = substr($email, 0, 1);
20         $secondChar  = substr($email, 1, 1);
21         $directory   = $directory.$firstChar."/".$secondChar."/".$strReplaced."/";
22         return $directory;
25 function within_str($subject, $lsearch, $rsearch) {
26         $data = strstr($subject, $lsearch);
27         $data = str_replace($lsearch, "", $data);
28         $trim = strstr($data, $rsearch);
30         return(str_replace($trim, "", $data));
33 function notification($directory) {
34         $i = 0;
35         @chdir($directory);
36         try{
37                 $files = glob("*.dat");
38                 if(!$files){
39                         throw new Exception("");
40                 }else{
41                         foreach($files as $filename){
42                                 $array = file($filename);
43                                 $value = max($array);
44                                 $checkUnread = within_str($value, "<read>", "</read>");
45                                 if($checkUnread==0){
46                                   $i++;
47                                 }
48                         }
49                         return ($i==0) ? '' : $i;
50                 }
51         }catch(Exception $e){
52                 return $e->getMessage();
53         }
57 $userDirectory = loggedEmail($email, MDB_PATH);
59 $count = notification($userDirectory);
60 echo $count;