Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
129 lines (108 loc) 路 3.21 KB
/
Copy pathindex.php
File metadata and controls
129 lines (108 loc) 路 3.21 KB
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
require_once 'vendor/autoload.php';
require_once 'app/posts.php';
require_once 'app/pages.php';
require_once 'app/plugins.php';
require_once 'app/generate.php';
require_once 'app/api.php';
$config = include('config.php');
$router = new AltoRouter();
$router->setBasePath($config['base_url']);
/* ============================================
Plugins
============================================ */
load_plugins();
/* ============================================
Subscription Feeds
============================================ */
$router->map('GET','/json/', function() {
header('Content-type: application/json');
echo generate_json(get_posts());
});
$router->map('GET','/rss/', function() {
header('Content-type: application/xml');
echo generate_rss(get_posts());
});
/* ============================================
API
============================================ */
$router->map('GET','/api/feed/', function() {
header('Content-type: application/json');
echo generate_json(api_feed());
});
$router->map('GET','/api/single/', function() {
header('Content-type: application/json');
echo generate_json(api_single());
});
/* ============================================
Front-end
============================================ */
// If the front-end option in config is set to false, skip the loading of frontend functionality
if(!$config['use_frontend']) {
$router->map('GET','/', function() {
require 'views/default.php';
});
} else {
require_once 'app/frontend.php';
require_once 'themes/' . $config['frontend_theme'] . '/functions.php';
$router->map('GET','/tag/[:tag]/[i:page]?/', function($tag, $page = 1) {
$config = include('config.php');
$posts = get_posts($page, $config['posts_per_page'], $tag);
$tag = str_replace('%20', ' ', $tag);
if($posts) {
include 'themes/' . $config['frontend_theme'] . '/tag.php';
} else {
error_404();
}
});
$router->map('GET','/[i:page]?/', function($page = 1) {
$config = include('config.php');
$posts = get_posts($page);
if($posts) {
include 'themes/' . $config['frontend_theme'] . '/home.php';
} else {
error_404();
}
});
$router->map('GET','/page/[:page]/', function($page) {
$config = include('config.php');
$page = get_page($page);
if($page->title) {
include 'themes/' . $config['frontend_theme'] . '/page.php';
} else {
error_404();
}
});
// Must be last to ensure other routes get detected first
if($config['post_base']) {
$router->map('GET','/[:year]/[:month]/[:slug]/', function($year, $month, $slug) {
$config = include('config.php');
$post = get_single($slug, $year, $month);
if($post->date) {
include 'themes/' . $config['frontend_theme'] . '/single.php';
} else {
error_404();
}
});
}
else {
$router->map('GET','/[:slug]/', function($slug) {
$config = include('config.php');
$post = get_single($slug);
if($post->date) {
include 'themes/' . $config['frontend_theme'] . '/single.php';
} else {
error_404();
}
});
}
}
/* ============================================
Matching
============================================ */
$match = $router->match();
if($match) {
call_user_func_array( $match['target'], $match['params'] );
} else {
error_404();
}