Exemplo n.º 1
0
define('THEME', 'theme1');
define('ROOT', getcwd());
chdir('admin');
require_once 'admin/init.php';
require_once 'lib/route/Route.php';
new TSession();
TTransaction::open('blog');
// render a category
Route::get('show_category', function ($args) {
    $partial_article = file_get_contents(ROOT . '/templates/' . THEME . '/partials/article.html');
    $partial_category = file_get_contents(ROOT . '/templates/' . THEME . '/partials/category.html');
    $category_id = (int) $args['category_id'];
    $category = isset($args['category_id']) ? $args['category_id'] : Category::getFirst();
    $categories = CategoryRender::render($category_id, $partial_category);
    $articles = PostRender::renderForCategory($category_id, $partial_article);
    $category = new Category($category_id);
    render_content(['articles' => $articles, 'category' => $categories]);
});
// render a post
Route::get('show_post', function ($args) {
    $partial_article = file_get_contents(ROOT . '/templates/' . THEME . '/partials/article.html');
    $partial_category = file_get_contents(ROOT . '/templates/' . THEME . '/partials/category.html');
    $post_id = isset($args['post_id']) ? (int) $args['post_id'] : NULL;
    $post = new Post($post_id);
    $articles = PostRender::renderPost(new Post($post_id), $partial_article);
    $categories = CategoryRender::render($post->category_id, $partial_category);
    render_content(['articles' => $articles, 'category' => $categories]);
});
// default action
Route::get('', function ($args) {