-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
292 lines (224 loc) · 8.78 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
namespace Dropplets;
require_once ('./vendor/autoload.php');
use \Mibe\FeedWriter\RSS2;
use \Dropplets\SavePreferences;
use \Dropplets\PageHelper;
use \Dropplets\PostManager;
session_start ();
/* ----------------------------------------------------------------------------------- */
/*
* If There's a Config Exists, Continue
* /*-----------------------------------------------------------------------------------
*/
$settings = Settings::instance ();
$settings->init ();
$category = NULL;
$url = (isset($_GET ['filename']))? $_GET ['filename'] :"";
$filename = null;
if ($url == 'rss' || $url == 'atom' || $url == 'postman') {
$filename = $_GET ['filename'];
} else if ($url == 'dropplets/save') {
$save = new \Dropplets\SavePreferences ();
$save->save ();
exit ();
} elseif ($url !== "") {
// Filename can be /some/blog/post-filename.md We should get the last part only
$filename = explode ( '/', $url );
// File name could be the name of a category
if (count ( $filename ) > 1) {
if ($filename [count ( $filename ) - 2] == "category") {
$category = $filename [count ( $filename ) - 1];
$filename = null;
}
} else {
// Individual Post
$filename = $settings->posts_dir . $filename [count ( $filename ) - 1] . $settings->get ( 'file_ext' );
}
}
$page = new PageHelper();
if (file_exists ( './config.ini' )) {
/* ----------------------------------------------------------------------------------- */
/*
* Get Settings & Functions
* /*-----------------------------------------------------------------------------------
*/
include ('./dropplets/functions.php');
$index_cache = $settings->get ( 'index_cache' );
$post_cache = $settings->get ( 'post_cache' );
$is_home = false;
/* ----------------------------------------------------------------------------------- */
/*
* The Home Page (All Posts)
* /*-----------------------------------------------------------------------------------
*/
if ($filename == NULL) {
if ($category)
$page->homepage($category);
else
$page->homepage();
}
if ($filename == 'rss' || $filename == 'atom') {
$page->rss($filename);
}
elseif ($filename == 'postman') {
$postMan = new PostManager();
$postMan->invoke();
}
/* ----------------------------------------------------------------------------------- */
/*
* Single Post Pages
* /*-----------------------------------------------------------------------------------
*/
else {
ob_start ();
// Define the post file.
$fcontents = file ( $filename );
$slug_array = explode ( "/", $filename );
$slug_len = count ( $slug_array );
// This was hardcoded array index, it should always return the last index.
$slug = str_replace ( array (
$settings->get ( 'file_ext' )
), '', $slug_array [$slug_len - 1] );
// Define the cached file.
$cachefile = $settings->config ( "cache_dir" ) . $slug . '.html';
// If there's no file for the selected permalink, grab the 404 page template.
if (! file_exists ( $filename )) {
// Change the cache file to 404 page.
$cachefile = CACHE_DIR . '404.html';
// Define the site title.
$page_title = $error_title;
// Get the 404 page template.
include $not_found_file;
// Get the contents.
$content = ob_get_contents ();
// Flush the buffer so that we dont get the page 2x times.
ob_end_clean ();
// Start new buffer.
ob_start ();
// Get the index template file.
// include_once $index_file;
// Cache the post on if caching is turned on.
if ($settings->get ( 'post_cache' ) != 'off') {
$fp = fopen ( $cachefile, 'w' );
fwrite ( $fp, ob_get_contents () );
fclose ( $fp );
}
// If there is a cached file for the selected permalink, display the cached post.
} else if (file_exists ( $cachefile )) {
// Define site title
$page_title = str_replace ( '# ', '', $fcontents [0] );
// Get the cached post.
include $cachefile;
exit ();
// If there is a file for the selected permalink, display and cache the post.
} else {
// Variables for template
$blog_url = $settings->get ( 'blog_title' );
$intro_title = $settings->get ( 'intro_title' );
$intro_text = $settings->get ( 'intro_text' );
$blog_url = $settings->get ( 'blog_url' );
$blog_email = $settings->get ( 'blog_email' );
$blog_title = $settings->get ( 'blog_title' );
$blog_twitter = $settings->get ( 'blog_twitter' );
$date_format = $settings->get ( 'date_format' );
$template_dir_url = $blog_url . '/templates/' . $settings->get ( 'template' ) . '/';
$template_dir = 'templates/' . $settings->get ( 'template' ) . '/';
$index_file = $template_dir . 'index.php';
// Get the post title.
$post_title = \Michelf\Markdown::defaultTransform ( $fcontents [0] );
$post_title = str_replace ( array (
"\n",
'<h1>',
'</h1>'
), '', $post_title );
// Get the post intro.
$post_intro = htmlspecialchars ( trim ( $fcontents [7] ) );
// Get the post author.
$post_author = str_replace ( array (
"\n",
'-'
), '', $fcontents [1] );
// Get the post author Twitter ID.
$post_author_twitter = str_replace ( array (
"\n",
'- '
), '', $fcontents [2] );
// Get the published date.
$published_iso_date = str_replace ( '-', '', $fcontents [3] );
// Generate the published date.
$published_date = strftime ( $date_format, strtotime ( $published_iso_date ) );
// Get the post category.
$post_category = str_replace ( array (
"\n",
'-'
), '', $fcontents [4] );
// Get the post status.
$post_status = str_replace ( array (
"\n",
'- '
), '', $fcontents [5] );
// Get the post category link.
$post_category_link = $blog_url . 'category/' . urlencode ( trim ( strtolower ( $post_category ) ) );
// Get the post link.
$post_link = $blog_url . str_replace ( array (
$settings->get ( 'file_ext' ),
$settings->posts_dir
), '', $filename );
// Get the post image url.
$postHelper = new PostHelper ();
$post_image = $postHelper->get_post_image_url ( $filename ) ? : $postHelper->get_twitter_profile_img ( $post_author_twitter );
// Get the post content
$file_array = array_slice ( file ( $filename ), 7 );
$post_content = \Michelf\Markdown::defaultTransform ( trim ( implode ( "", $file_array ) ) );
// free memory
unset ( $file_array );
// Get the site title.
$page_title = trim ( str_replace ( '# ', '', $fcontents [0] ) );
// Generate the page description and author meta.
$get_page_meta [] = '<meta name="description" content="' . $post_intro . '">';
$get_page_meta [] = '<meta name="author" content="' . $post_author . '">';
// Generate the Twitter card.
$get_page_meta [] = '<meta name="twitter:card" content="summary">';
$get_page_meta [] = '<meta name="twitter:site" content="' . $blog_twitter . '">';
$get_page_meta [] = '<meta name="twitter:title" content="' . $page_title . '">';
$get_page_meta [] = '<meta name="twitter:description" content="' . $post_intro . '">';
$get_page_meta [] = '<meta name="twitter:creator" content="' . $post_author_twitter . '">';
$get_page_meta [] = '<meta name="twitter:image:src" content="' . $post_image . '">';
$get_page_meta [] = '<meta name="twitter:domain" content="' . $post_link . '">';
// Get the Open Graph tags.
$get_page_meta [] = '<meta property="og:type" content="article">';
$get_page_meta [] = '<meta property="og:title" content="' . $page_title . '">';
$get_page_meta [] = '<meta property="og:site_name" content="' . $page_title . '">';
$get_page_meta [] = '<meta property="og:url" content="' . $post_link . '">';
$get_page_meta [] = '<meta property="og:description" content="' . $post_intro . '">';
$get_page_meta [] = '<meta property="og:image" content="' . $post_image . '">';
// Generate all page meta.
$page_meta = implode ( "\n\t", $get_page_meta );
// Generate the post.
$post = \Michelf\Markdown::defaultTransform ( join ( '', $fcontents ) );
$post_file = $template_dir . 'post.php';
// Get the post template file.
include $post_file;
$content = ob_get_contents ();
ob_end_clean ();
ob_start ();
// Get the index template file.
include_once $index_file;
// Cache the post on if caching is turned on.
if ($post_cache == 'true') {
$fp = fopen ( $cachefile, 'w' );
fwrite ( $fp, ob_get_contents () );
fclose ( $fp );
}
}
}
/* ----------------------------------------------------------------------------------- */
/*
* Run Setup if No Config
* /*-----------------------------------------------------------------------------------
*/
} else {
$install = new InstallHelper();
$install->start();
}