-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
128 lines (98 loc) · 3.08 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
date_default_timezone_set('Asia/Taipei');
/** The array which we'll store the diays later */
$Diarys = array();
/**
* Generate
*
* Output the diarys.
*/
function Diary($SingleDiary)
{
/** Get the information of the diary */
$Title = $SingleDiary['Title'];
$Date = $SingleDiary['Date'];
$Content = $SingleDiary['Content'];
$MD5 = $SingleDiary['MD5'];
/** Convert the date of the diary */
$Month = date('F' , $Date);
$Day = date('j', $Date);
$DayEnd = date('S', $Date);
$Week = date('l' , $Date);
echo <<<EOF
<div class="g-2">
<div class="diary-date shw-e rd-4">
<div class="month">$Month</div>
<div class="date">$Day<span class="end">$DayEnd</span></div>
<div class="week">$Week</div>
</div>
</div>
<div class="diary-container word-break shw-e g-9 rd-4 text-left border-box">
<h3>$Title</h3>
<div class="content">
$Content
</div>
</div>
EOF;
}
/**
* Scan
*
* Get all the diary files
*/
$OS = (DIRECTORY_SEPARATOR == '\\') ? 'Windows' : 'Linux';
foreach(glob(__DIR__ . '/diary/*.txt') as $Diary)
{
/** The file name is the title of this diary */
/** Now we remove the path first, next is the file extension */
$Title = ($OS == 'Linux') ? preg_replace('/\.\w*$/', '', preg_replace('/^.+[\\\\\\/]/', '', $Diary))
: iconv('BIG5', 'UTF-8', preg_replace('/\.\w*$/', '', preg_replace('/^.+[\\\\\\/]/', '', $Diary)));
/** Get the content */
$Content = nl2br(htmlspecialchars(iconv("BIG5","UTF-8", file_get_contents($Diary))));
/** Get the unix timestramp of the file */
$Date = filemtime($Diary);
/** Get the md5 of the file */
$MD5 = md5_file($Diary);
/** Push to the diary collection */
array_push($Diarys, array('Title' => $Title,
'Content' => $Content,
'Date' => $Date,
'MD5' => $MD5));
}
/**
* Sort
*
* Sort the posts by last modif time.
*/
$Modif = array();
foreach($Diarys as $Key => $Val)
$Modif[$Key] = $Val['Date'];
array_multisort($Modif, SORT_DESC, $Diarys);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/tocas.css">
<link rel="stylesheet" href="css/filary.css">
<link href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin" rel="stylesheet">
<title>Filary</title>
</head>
<body>
<nav class="shw-e center"><h1>Filary</h1></nav>
<section>
<?php if(empty($Diarys)) { //If there's no any diary now ?>
<div id="empty" class="table fill">
<div class="table-cell center">
<p>目前沒有任何日記。</p>
<p>There's no any diary now.</p>
</div>
</div>
<?php } else { //If there's a diary or many of them, then we echo them ?>
<div class="row center">
<?php foreach($Diarys as $Single) Diary($Single); ?>
</div>
<?php } ?>
</section>
</body>
</html>