-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
67 lines (57 loc) · 1.71 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
<?php
// include_once
require_once 'header.php';
// define('_PAGE_TPL', 'index.tpl');
$page_title = '首頁';
// 判斷是否有OP
$op = isset($_REQUEST['op']) ? filter_var($_REQUEST['op']) : '';
$sn = isset($_REQUEST['sn']) ? (int) ($_REQUEST['sn']) : 0;
switch ($op) {
default:
if ($sn) {
show_article($sn);
$op = 'show_article';
} else {
list_article();
$op = 'list_article';
}
break;
}
require_once 'footer.php';
/*************函數區**************/
// //標題
// $title = $_POST['title'];
// $smarty->assign('title', $title);
// //顏色
// $color = $_POST['color'];
// $smarty->assign('color', $color);
// $smarty->assign('now', date("Y年m月d日 H:i:s"));
//讀出單一文章
function show_article($sn)
{
require_once 'HTMLPurifier/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
global $db, $smarty;
$sql = "SELECT * FROM `article` WHERE `sn`='$sn'";
$result = $db->query($sql) or die($db->error);
$data = $result->fetch_assoc();
$data['content'] = $purifier->purify($data['content']);
$smarty->assign('article', $data);
}
//讀出所有文章
function list_article()
{
global $db, $smarty;
$sql = "SELECT * FROM `article` ORDER BY `update_time` DESC LIMIT 0,9";
$result = $db->query($sql) or die($db->error);
$all = [];
$i = 0;
while ($data = $result->fetch_assoc()) {
$all[$i] = $data;
$all[$i]['summary'] = mb_substr(strip_tags($data['content']), 0, 90);
$i++;
}
//測試用 die(var_export($all));
$smarty->assign('all', $all);
}