-
Notifications
You must be signed in to change notification settings - Fork 1
/
post.php
146 lines (122 loc) · 5.64 KB
/
post.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
# The layout of posts of a site.
#
# This is one mandatory layout for a Lightweight CMS theme.
# Require a private utility script.
require_once __DIR__ . "/../src/utils.php";
# Take global data.
$post = $GLOBALS[LIGHTWEIGHT_CMS_POST];
$wordCount = \LightweightCMS\Plugin\wordCount($post[LIGHTWEIGHT_CMS_POST_CONTENT]);
$readTime = \LightweightCMS\Plugin\readTime($wordCount);
# Add id for each subtitle if none.
if (ENABLE_TOC) {
$originalPost = $post[LIGHTWEIGHT_CMS_POST_CONTENT];
$post[LIGHTWEIGHT_CMS_POST_CONTENT]
= preg_replace_callback(
"/<h2(?: id=\"[^\"]+\")?>(.+?)<\/h2>/",
function ($matches) {
$id = preg_replace("/<(.+?)>/", "", $matches[1]);
$id = preg_replace("/[ ]+/", "-", $id);
$id = strtolower($id);
return "<h2 id=\"" . $id . "\">" . $matches[1] . "</h2>";
},
$post[LIGHTWEIGHT_CMS_POST_CONTENT]
);
if (strlen($originalPost) === strlen($post[LIGHTWEIGHT_CMS_POST_CONTENT])) {
$noSubtitle = TRUE;
}
else {
$noSubtitle = FALSE;
}
$GLOBALS[LIGHTWEIGHT_CMS_POST] = $post;
}
?>
<!DOCTYPE html>
<html lang="<?php echo SITE_LANGUAGE; ?>">
<head>
<?php
if (!is_null(GOOGLE_ANALYTICS_ID) && "" != GOOGLE_ANALYTICS_ID) {
echo "<!-- Google Analytics -->";
echo \LightweightCMS\Plugin\googleAnalytics(GOOGLE_ANALYTICS_ID);
}
?>
<title><?php echo $post[LIGHTWEIGHT_CMS_POST_TITLE] . " | " . SITE_NAME; ?></title>
<?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_AUTHOR, $post) && "" != $post[LIGHTWEIGHT_CMS_POST_AUTHOR]): ?>
<meta name="author" content="<?php echo $post[LIGHTWEIGHT_CMS_POST_AUTHOR]; ?>">
<?php endif; ?>
<?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_META, $post)
&& array_key_exists("description", $post[LIGHTWEIGHT_CMS_POST_META])): ?>
<meta name="description" content="<?php echo $post[LIGHTWEIGHT_CMS_POST_META]["description"]; ?>">
<?php else: ?>
<meta name="description" content="<?php echo \LightweightCMS\Plugin\excerpt($post[LIGHTWEIGHT_CMS_POST_CONTENT]); ?>">
<?php endif; ?>
<?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_META, $post)
&& array_key_exists(METADATA_NOINDEX, $post[LIGHTWEIGHT_CMS_POST_META])
&& $post[LIGHTWEIGHT_CMS_POST_META][METADATA_NOINDEX]): ?>
<!-- Some functional post doesn't benefit SEO. -->
<meta name="robots" content="noindex, follow">
<?php endif; ?>
<?php includePartials("openGraph.php"); ?>
<?php includePartials("header.php"); ?>
</head>
<body>
<?php includePartials("navbar.php"); ?>
<div id="top" class="jumbotron">
<div class="container">
<div>
<header>
<h1>
<img class="d-none d-md-block" src="<?php echo SITE_PREFIX; ?>/img/<?php echo SITE_LOGO; ?>-64x64.png" alt="<?php echo SITE_AUTHOR; ?>" style="margin-right: 10px;" />
<span>
<?php echo $post[LIGHTWEIGHT_CMS_POST_TITLE]; ?>
</span>
</h1>
</header>
<div class="post-info">
<?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_AUTHOR, $post) && "" != $post[LIGHTWEIGHT_CMS_POST_AUTHOR]): ?>
<span class="author">Written by <?php echo $post[LIGHTWEIGHT_CMS_POST_AUTHOR]; ?><?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_MTIME, $post)): ?>.<?php endif; ?></span>
<?php endif; ?>
<?php if (array_key_exists(LIGHTWEIGHT_CMS_POST_MTIME, $post)): ?>
<span class="last-modified-time">Last modified on <?php echo date("Y-m-d", $post[LIGHTWEIGHT_CMS_POST_MTIME]); ?></span>
<?php endif; ?>
</div>
<?php includePartials("breadcrumb.php"); ?>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div id="main-content" class="col-lg-9 col-xs-12">
<!-- 300 wpm is the average reading speed of adults. -->
<div class="alert alert-info" role="alert">
There are <?php echo $wordCount; ?> word(s) in the post.
It will take <?php echo $readTime; ?> minute(s) to read.
</div>
<?php includePartials("tags.php"); ?>
<?php includePartials("shareButtons.php"); ?>
<main>
<?php echo $post[LIGHTWEIGHT_CMS_POST_CONTENT]; ?>
</main>
</div>
<div id="fixed-sidebar" class="col-lg-3 col-xs-12">
<aside>
<?php
if ($noSubtitle) {
includePartials("sideInfo.php");
}
else if (!is_null(ENABLE_TOC) && ENABLE_TOC) {
includePartials("toc.php");
}
else {
includePartials("sideInfo.php");
}
?>
</aside>
</div>
</div>
</div>
<?php includePartials("footer.php"); ?>
<?php includePartials("library.php"); ?>
</body>
</html>
<?php http_response_code($post[LIGHTWEIGHT_CMS_POST_STATUS]); ?>