$page = $page ? (int) $page : 1; $perpage = config('posts.perpage'); $posts = get_posts(null, $page, $perpage); $total = ''; $tl = blog_tagline(); if ($tl) { $tagline = ' - ' . $tl; } else { $tagline = ''; } if (empty($posts) || $page < 1) { // a non-existing page render('no-posts', array('title' => 'Blog - ' . blog_title(), 'description' => blog_title() . ' Blog Homepage', 'canonical' => site_url(), 'bodyclass' => 'noposts', 'is_front' => true)); die; } render('main', array('title' => 'Blog - ' . blog_title(), 'description' => blog_title() . ' Blog Homepage', 'canonical' => site_url() . 'blog', 'page' => $page, 'posts' => $posts, 'bodyclass' => 'inblog', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » Blog', 'pagination' => has_pagination($total, $perpage, $page), 'is_blog' => true)); } elseif ($static === 'front') { $redir = site_url(); header("location: {$redir}", TRUE, 301); } else { if (config("views.counter") != "true") { if (!login()) { file_cache($_SERVER['REQUEST_URI']); } } $post = get_static_post($static); if (!$post) { not_found(); } $post = $post[0]; if (config("views.counter") == "true") {
?> </time> by <?php echo article_author('real_name'); ?> . </footer> </article> <hr> </li> <?php } ?> </ul> <?php if (has_pagination()) { ?> <nav class="pagination"> <div class="wrap"> <?php echo posts_prev(); ?> <?php echo posts_next(); ?> </div> </nav> <?php } ?>
// The search page get('/search/:keyword', function ($keyword) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); } $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $perpage = config('search.perpage'); $posts = get_keyword($keyword, $page, $perpage); $total = keyword_count($keyword); if (empty($posts) || $page < 1) { // a non-existing page render('404-search', null, false); die; } render('main', array('head_contents' => head_contents('Search results for: ' . $keyword . ' - ' . blog_title(), 'Search results for: ' . $keyword . ' on ' . blog_title() . '.', site_url() . 'search/' . $keyword), 'page' => $page, 'posts' => $posts, 'bodyclass' => 'insearch', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » Search results for: ' . $keyword, 'pagination' => has_pagination($total, $perpage, $page))); }); // The JSON API get('/api/json', function () { header('Content-type: application/json'); $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $perpage = config('json.count'); echo generate_json(get_posts(null, $page, $perpage)); }); // Show the RSS feed get('/feed/rss', function () { header('Content-Type: application/rss+xml'); // Show an RSS feed with the 30 latest posts echo generate_rss(get_posts(null, 1, config('rss.count'))); });
// and our functions.php file require 'app/includes/dispatch.php'; require 'app/includes/functions.php'; // Load the configuration file config('source', 'app/config.ini'); // The front page of the blog. // This will match the root url get('/index', function () { $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $posts = get_posts($page); if (empty($posts) || $page < 1) { // a non-existing page not_found(); } render('main', array('page' => $page, 'posts' => $posts, 'has_pagination' => has_pagination($page))); }); // The post page get('/:year/:month/:name', function ($year, $month, $name) { $post = find_post($year, $month, $name); if (!$post) { not_found(); } render('post', array('title' => $post->title . ' ⋅ ' . config('blog.title'), 'p' => $post)); }); // The JSON API get('/api/json', function () { header('Content-type: application/json'); // Print the 10 latest posts as JSON echo generate_json(get_posts(1, 10)); });
// Show the search page get('/search/:keyword', function ($keyword) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); } $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $perpage = config('search.perpage'); $posts = get_keyword($keyword, $page, $perpage); $total = keyword_count($keyword); if (empty($posts) || $page < 1) { // a non-existing page render('404-search', null, false); die; } render('main', array('title' => 'Search results for: ' . $keyword . ' - ' . blog_title(), 'description' => 'Search results for: ' . $keyword . ' on ' . blog_title() . '.', 'canonical' => site_url() . 'search/' . $keyword, 'page' => $page, 'posts' => $posts, 'bodyclass' => 'insearch', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » Search results for: ' . $keyword, 'pagination' => has_pagination($total, $perpage, $page), 'is_search' => is_search(true))); }); // The JSON API get('/api/json', function () { header('Content-type: application/json'); $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $perpage = config('json.count'); echo generate_json(get_posts(null, $page, $perpage)); }); // Show the RSS feed get('/feed/rss', function () { header('Content-Type: application/rss+xml'); // Show an RSS feed with the 30 latest posts echo generate_rss(get_posts(null, 1, config('rss.count'))); });
# 路由 ##################################################### $app->get('/test', function () use($app) { $Parsedown = new Parsedown(); echo $Parsedown->parse(''); })->name('test'); #主页 $app->get('/', function () use($app) { $app->render('welcome.html'); }); $app->get('/home(/:page)', function ($page = 1) use($app) { $posts = get_posts($page); if (empty($posts) || $page < 1) { $app->notFound(); } $app->render('index.html', ['page' => $page, 'posts' => $posts, 'has_pagination' => has_pagination($page)]); })->conditions(array('page' => '[0-9]*')); # Posts页 $app->get('/:year/:month/:name', function ($year, $month, $name) use($app) { $post = find_post($year, $month, $name); if (!$post) { $app->notFound(); } $app->render('post.html', ['post' => $post]); }); # 生成rss $app->get('/rss', function () use($app) { $app->response->headers->set('Content-Type', 'application/rss+xml'); echo generate_rss(get_posts(1, 30)); }); # 非法页面
foreach ($author as $p) { $total = $p->count; } render('profile', array('exists' => $exists, 'page' => $page, 'posts' => $posts, 'total' => $author['count'], 'author' => $author, 'name' => $name, 'tags' => $tags, 'category' => $category, 'likes' => $likes, 'has_pagination' => has_pagination($page, $total))); }); get('/cat/:name', function ($name) { $page = from($_GET, 'page'); $page = $page ? (int) $page : 1; $categoryposts = get_posts_category($name); $tags = get_tags(); $category = get_category(); $likes = get_likes(); foreach ($categoryposts as $p) { $total = $p->count; } render('category', array('page' => $page, 'author' => $categoryposts, 'tags' => $tags, 'category' => $category, 'likes' => $likes, 'has_pagination' => has_pagination($page, $total))); }); get('/post/:title', function ($title) { $post = find_post($title); if (!$post) { not_found(); } foreach ($post as $ps) { $id = $ps['id']; } $tags = get_tags(); $comments = get_comments($id); $category = get_category(); $likes = get_likes(); render('post', array('title' => $post->title . ' ⋅ ' . config('blog.title'), 'p' => $post, 'tags' => $tags, 'comments' => $comments, 'category' => $category, 'likes' => $likes)); });