-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
129 lines (125 loc) · 5.24 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
129
<?php
include_once dirname(__FILE__)."/view/utilityView/prevent.php";
require_once (dirname(__FILE__)."/view/indexView/indexView.php");
$view = new IndexView();
require_once (dirname(__FILE__)."/controller/activityController/activityController.php");
BannerView::getBanner()->setSelected("index.php");
$uri = $_SERVER['REQUEST_URI'];
$arr = explode("/", $uri);
if (count($arr) > 2){
if ($arr[2] == "logout"){
$_SESSION["id"] = null;
$_SESSION["name"] = null;
$_SESSION["face"] = null;
$_SESSION["isManager"] = null;
header("Location: /login.php");
exit();
}
}
require_once (dirname(__FILE__)."/controller/indexController/indexController.php");
$controller = new IndexController();
$result = $controller->initialize();
$newsList = $result->newsList;
$newsStr = "";
foreach ($newsList->children() as $child){
$itemHtml = new DOMDocument();
$itemHtml->loadHTMLFile(dirname(__FILE__)."/view/indexView/index-info.html");
$itemHtml->getElementsByTagName("a")[0]->appendChild($itemHtml->createTextNode($child->title[0]));
$itemHtml->getElementsByTagName("div")[0]->appendChild($itemHtml->createTextNode($child->time[0]));
$newsStr.= $itemHtml->saveHTML();
}
$view->setNews($newsStr);
$announcementList = $result->announcementList;
$announcementStr = "";
foreach ($announcementList->children() as $child){
$itemHtml = new DOMDocument();
$itemHtml->loadHTMLFile(dirname(__FILE__)."/view/indexView/index-info.html");
$itemHtml->getElementsByTagName("a")[0]->appendChild($itemHtml->createTextNode($child->title[0]));
$itemHtml->getElementsByTagName("div")[0]->appendChild($itemHtml->createTextNode($child->time[0]));
$announcementStr.= $itemHtml->saveHTML();
}
$view->setAnnouncements($announcementStr);
$activityList = $result->activityList;
$activityStr = "";
foreach ($activityList->children() as $child){
$itemHtml = new DOMDocument();
$itemHtml->loadHTMLFile(dirname(__FILE__)."/view/indexView/activity-info.html");
$itemHtml->getElementsByTagName("a")[0]->setAttribute("href","/activity.php/activity/".$child->id[0]);
$itemHtml->getElementsByTagName("a")[0]->appendChild($itemHtml->createTextNode($child->title[0]));
$itemHtml->getElementsByTagName("div")[0]->appendChild($itemHtml->createTextNode($child->time[0]));
$activityStr.= $itemHtml->saveHTML();
}
$view->setActivities($activityStr);
$rank = $result->rank;
$rankStr = "";
$i = 1;
foreach ($rank->children() as $child){
$itemHtml = new DOMDocument();
$itemHtml->loadHTMLFile(dirname(__FILE__)."/view/indexView/rank-info.html");
$itemHtml->getElementsByTagName("a")[0]->setAttribute("href","/personal.php/person/".$child->userId[0]);
$itemHtml->getElementsByTagName("img")[0]->setAttribute("src",$child->face[0]);
$itemHtml->getElementsByTagName("img")[0]->setAttribute("alt",$child->username[0]);
$itemHtml->getElementsByTagName("div")[0]->appendChild($itemHtml->createTextNode($i));
switch ($i){
case 1:
$itemHtml->getElementsByTagName("div")[0]->setAttribute("class","rank-num rank-first common-column");
break;
case 2:
$itemHtml->getElementsByTagName("div")[0]->setAttribute("class","rank-num rank-second common-column");
break;
case 3:
$itemHtml->getElementsByTagName("div")[0]->setAttribute("class","rank-num rank-third common-column");
break;
default:
$itemHtml->getElementsByTagName("div")[0]->setAttribute("class","rank-num common-column");
break;
}
$itemHtml->getElementsByTagName("div")[1]->appendChild($itemHtml->createTextNode($child->username[0]));
$itemHtml->getElementsByTagName("div")[2]->appendChild($itemHtml->createTextNode($child->num[0]."步"));
$i++;
$rankStr.= $itemHtml->saveHTML();
}
$view->setRank($rankStr);
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>跑得快 - 运动没这个是最痛苦的!</title>
<link rel="stylesheet" type="text/css" href="/assets/css/common.css">
<link rel="stylesheet" type="text/css" href="/assets/css/index.css">
</head>
<body>
<?php include dirname(__FILE__)."/view/utilityView/banner.php" ?>
<div role="main">
<div class="common-columns index-row">
<div class="announcement common-column content content-first index-item item-left">
<div class="title">网站公告</div>
<ul class="news-ul">
<?php echo $view->getAnnouncements()?>
</ul>
</div>
<div class="news common-column content content-first index-item">
<div class="title">网站新闻</div>
<ul class="news-ul">
<?php echo $view->getNews()?>
</ul>
</div>
</div>
<div class="common-columns index-row">
<div class="activity common-column content index-item item-left">
<div class="title">最新活动</div>
<ul class="news-ul">
<?php echo $view->getActivities()?>
</ul>
</div>
<div class="rank common-column content index-item">
<div class="title">运动排名</div>
<ul class="rank-ul">
<?php echo $view->getRank()?>
</ul>
</div>
</div>
</div>
</body>
</html>