public static function writeAction($type)
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if ($type == 'publish') {
             $state = \BWBlog\Post::STATE_OPEN;
         } else {
             if ($type == 'draft') {
                 $state = \BWBlog\Post::STATE_DRAFT;
             } else {
                 if ($type == 'page') {
                     $state = \BWBlog\Post::STATE_PAGE;
                 } else {
                     throw new \Exception('Invalid publish type (publish / draft)');
                 }
             }
         }
         if (!isset($_POST['title']) || mb_strlen($_POST['title']) == 0) {
             throw new \Exception('Please enter title');
         }
         if (!isset($_POST['url']) || mb_strlen($_POST['url']) == 0) {
             throw new \Exception('Please enter clean-URI');
         }
         if (!isset($_POST['markdown'])) {
             throw new \Exception('Missing argument: markdown');
         }
         if (!isset($_POST['category'])) {
             throw new \Exception('Missing argument: category');
         }
         if (!isset($_POST['tags'])) {
             throw new \Exception('Missing argument: tags');
         }
         if (!isset($_POST['time'])) {
             throw new \Exception('Missing argument: time');
         }
         $time = \DateTime::createFromFormat('Y-n-j H:i:s', $_POST['time']);
         if ($time === false) {
             throw new \Exception('Invalid date-time format');
         }
         $time = $time->getTimestamp();
         if (mb_strlen(trim($_POST['tags'])) > 0) {
             $tags = array_map('trim', explode(',', $_POST['tags']));
         } else {
             $tags = [];
         }
         if (isset($_POST['id'])) {
             $id = $_POST['id'];
         } else {
             $id = null;
         }
         die(json_encode(\BWBlog\Post::edit($_POST['title'], $_POST['markdown'], $_POST['url'], $time, $_POST['category'], $tags, $state, $id)));
     } else {
         $id = $type;
         $post = \BWBlog\Post::getById($id);
         if ($post !== null) {
             return ['POST' => $post, 'TITLE' => 'Edit'];
         } else {
             return ['TITLE' => 'Write'];
         }
     }
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 public static function indexAction()
 {
     $rss = new \UniversalFeedCreator();
     $rss->useCached('RSS1.0', ROOT_DIR . '/runtime/rss.xml');
     $rss->title = P_TITLE;
     $rss->link = ENV_PREFERED_PROTOCOL . '://' . CONFIG_HOST . P_PREFIX;
     $rss->syndicationURL = $rss->link . '/feed';
     $posts = \BWBlog\Post::list_all([], 1, 0);
     foreach ($posts as $post) {
         $item = new \FeedItem();
         $item->title = $post['title'];
         $item->link = ENV_PREFERED_PROTOCOL . '://' . CONFIG_HOST . P_PREFIX . $post['rest_url'];
         $item->description = $post['content']['html'];
         $item->date = $post['time']['main'];
         $rss->addItem($item);
     }
     echo $rss->saveFeed('RSS1.0', ROOT_DIR . '/runtime/rss.xml');
 }
Exemple #5
0
 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;
 }