]> git.bts.cx Git - cx.git/blobdiff - cx/lib/posts.php
Added cache support
[cx.git] / cx / lib / posts.php
index 64374333e6636212486f084cd7c838c6016a2b96..e46aa28cd6816f79a5827f5c7fe17a6f8fecd198 100644 (file)
@@ -19,6 +19,7 @@ class Post {
        public $title;
        public $slug;
        public $date;
        public $title;
        public $slug;
        public $date;
+       public $is_page;
        public $is_draft;
        public $data;
        public $html_content;
        public $is_draft;
        public $data;
        public $html_content;
@@ -29,6 +30,7 @@ class Post {
                $this->title = $dict['post_title'];
                $this->slug = $dict['post_slug'];
                $this->date = $dict['post_date'];
                $this->title = $dict['post_title'];
                $this->slug = $dict['post_slug'];
                $this->date = $dict['post_date'];
+               $this->is_page = $dict['post_is_page'];
                $this->is_draft = $dict['post_is_draft'];
                $this->data = $dict['post_data'];
                $this->html_content = cx_markdown_generate_html($this->data);
                $this->is_draft = $dict['post_is_draft'];
                $this->data = $dict['post_data'];
                $this->html_content = cx_markdown_generate_html($this->data);
@@ -133,6 +135,7 @@ function cx_posts_get(int $limit = 0, int $offset = 0, bool $include_drafts = fa
                post_id,
                post_slug,
                post_date,
                post_id,
                post_slug,
                post_date,
+               post_is_page,
                post_is_draft,
                post_title,
                post_data
                post_is_draft,
                post_title,
                post_data
@@ -186,6 +189,7 @@ function cx_posts_find_post($post_id) {
                post_id,
                post_slug,
                post_date,
                post_id,
                post_slug,
                post_date,
+               post_is_page,
                post_is_draft,
                post_title,
                post_data
                post_is_draft,
                post_title,
                post_data
@@ -233,18 +237,25 @@ function cx_posts_find_page_id($post_slug) {
        return null;
 }
 
        return null;
 }
 
-function cx_pages_get() {
+function cx_pages_get(bool $include_drafts = false) {
        $sql = 'SELECT
                post_id,
                post_slug,
                post_date,
        $sql = 'SELECT
                post_id,
                post_slug,
                post_date,
+               post_is_page,
                post_is_draft,
                post_title,
                post_data
                FROM posts
                post_is_draft,
                post_title,
                post_data
                FROM posts
-               WHERE post_is_page == TRUE
-               AND post_is_draft == FALSE
-               ORDER BY post_creation_time DESC;';
+               WHERE post_is_page == TRUE';
+
+       if ($include_drafts == false) {
+               $sql .= ' AND post_is_draft == FALSE';
+       }
+
+       $sql .= ' ORDER BY post_date ASC';
+
+       $sql .= ';';
 
        foreach (cx_db_query($sql) as $post) {
                $p = new Post($post);
 
        foreach (cx_db_query($sql) as $post) {
                $p = new Post($post);