-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
84 lines (71 loc) · 2.07 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
<?php
include "app/core/loader.php";
$themeBase = "themes/".$Lando->config["theme"]."/";
$template = "404";
$url = current_path();
$Current = new Page();
if($url == "/") {
$Current = $Lando->get_content();
$template = $Current ? "home" : "404";
}
if(preg_match('~^/([\w-]+)$~', $url, $matches)) {
switch($matches[1]) {
case "posts":
$template = "posts_all";
break;
case "drafts":
$template = "drafts_all";
break;
case "rss":
$template = "rss";
break;
default:
$Current = $Lando->get_content();
if(!$Current)
$template = "404";
elseif(include_exists($themeBase.$matches[1].".php"))
$template = $matches[1];
else
$template = "page";
}
}
if(preg_match('~^/posts/from/(\d{4})(?:/(\d{2}))?(?:/(\d{2}))?$~', $url))
$template = "posts_by_date";
elseif(preg_match('~^/posts/tagged/([\w\s\+-,]+)$~', $url))
$template = "posts_by_tag";
elseif(preg_match('~^/([\w-]+)(?:/([\w-]+))+$~', $url, $matches)) {
$Current = $Lando->get_content();
if(!$Current)
$template = "404";
else {
switch($matches[1]) {
case "posts":
$template = "post";
break;
case "drafts":
$template = "draft";
break;
default:
if(include_exists($themeBase.$matches[2].".php"))
$template = $matches[2];
else
$template = inheritedTemplate(path_segments(), $themeBase);
}
}
}
//kick out to login if trying to view drafts
if(in_array($template, array("draft", "drafts_all")) && !admin_cookie())
header("Location: ".$Lando->config["site_root"]."/admin/login.php?redirect=drafts");
$helper_file = $themeBase."theme_functions.php";
if(include_exists($helper_file))
include $helper_file;
if(!include_exists($themeBase.$template.".php")) {
if(include_exists("app/templates/$template.php"))
$themeBase = "app/templates/"; //fallback for missing optional custom templates
else
system_error("Missing Theme/Template", "The template file <strong>$template.php</strong> could not be found in <strong>$theme_dir</strong>.");
}
//for 404 page, serve blank content
if(!$Current)
$Current = new Page();
include_once $themeBase.$template.".php";