コード例 #1
0
ファイル: tagController.php プロジェクト: yunxuanhao/BWBlog
 public static function initialize($param)
 {
     $tag = strtolower($param['action']);
     $page = (int) ($param['parameter'] ?: '1');
     $pages = ceil(\BWBlog\Post::count(['ltags' => $tag]) / P_POSTS_PER_PAGE);
     $posts = \BWBlog\Post::list_all(['ltags' => $tag], $page);
     \BWBlog\Service\Template::render('pages/list', ['POSTS' => $posts, 'PAGE' => $page, 'PAGE_COUNT' => $pages, 'TAG' => $tag, 'TITLE' => ucwords($tag), 'BASE_URI' => '/tag/' . $param['action'] . '/']);
     return false;
 }
コード例 #2
0
ファイル: postController.php プロジェクト: yunxuanhao/BWBlog
 public static function viewAction($rest)
 {
     $post = \BWBlog\Post::get($rest);
     if ($post == null) {
         throw new \ReflectionException();
         return false;
     }
     \BWBlog\Service\Template::render('pages/post', ['TITLE' => $post['title'], 'POST' => $post]);
     return false;
 }
コード例 #3
0
ファイル: pageController.php プロジェクト: yunxuanhao/BWBlog
 public static function initialize($param)
 {
     if (is_numeric($param['action'])) {
         // page/1
         $page = (int) $param['action'];
         $pages = ceil(\BWBlog\Post::count() / P_POSTS_PER_PAGE);
         $posts = \BWBlog\Post::list_all([], $page);
         \BWBlog\Service\Template::render('pages/list', ['CATEGORY' => 'home', 'POSTS' => $posts, 'PAGE' => $page, 'PAGE_COUNT' => $pages, 'BASE_URI' => '/page/']);
     } else {
         // page/custom_page
         $post = \BWBlog\Post::get($param['raw']);
         if ($post == null) {
             throw new \ReflectionException();
             return false;
         }
         \BWBlog\Service\Template::render('pages/page', ['TITLE' => $post['title'], 'POST' => $post]);
     }
     return false;
 }
コード例 #4
0
ファイル: Utils.php プロジェクト: yunxuanhao/BWBlog
 public static function invoke($rest, $controller, $action, $parameter = null)
 {
     $controller = strtolower($controller);
     $action = strtolower($action);
     $reflection = new \ReflectionClass('\\BWBlog\\Controllers\\' . $controller . 'Controller');
     // call initialize
     if ($reflection->hasMethod('initialize')) {
         $method = $reflection->getMethod('initialize');
         $result = $method->invoke(null, ['controller' => $controller, 'action' => $action, 'parameter' => $parameter, 'raw' => $rest]);
         if ($result === false) {
             return false;
         }
     }
     $method = $reflection->getMethod($action . 'Action');
     $result = $method->invoke(null, $parameter);
     if ($result !== false) {
         if ($result == null) {
             $result = [];
         }
         \BWBlog\Service\Template::render($controller . '/' . $action, $result);
     }
 }