]> git.bts.cx Git - cx.git/blobdiff - cx/lib/posts.php
Use the correct file request call
[cx.git] / cx / lib / posts.php
index 9fb4e356433a4529c1554839d3a42fc453658905..4d122dfe642ff2fb087af6a49b9c818138b2a4fc 100644 (file)
@@ -45,6 +45,14 @@ class Post {
                }
        }
 
                }
        }
 
+       public function get_permalink_path() {
+               $permalink = '/' . $this->slug;
+               if ($this->is_page == false) {
+                       $permalink = '/' . date('Y', $this->date) . '/' . date('m', $this->date) . '/' . $this->slug;
+               }
+               return $permalink;
+       }
+
        public function get_metadata() {
                $data = [];
 
        public function get_metadata() {
                $data = [];
 
@@ -99,7 +107,8 @@ function cx_posts_add_post($site_id, $title, $slug, $date, $page, $draft, $nav_i
                        post_data,
                        post_data_version)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
                        post_data,
                        post_data_version)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
-       cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, $page, $draft, $nav_index, $title, $data, 1);
+       $id = cx_db_exec($sql, $site_id, $creation_time, $update_time, $slug, $date, $page, $draft, $nav_index, $title, $data, 1);
+       return $id;
 }
 
 function cx_posts_update_post($post_id, $title, $slug, $date, $page, $draft, $nav_index, $data) {
 }
 
 function cx_posts_update_post($post_id, $title, $slug, $date, $page, $draft, $nav_index, $data) {
@@ -211,30 +220,43 @@ function cx_posts_find_post($post_id) {
        return null;
 }
 
        return null;
 }
 
-function cx_posts_find_article_id($post_slug) {
+function cx_posts_find_article_id($post_slug, bool $include_drafts = false) {
        $sql = 'SELECT
                post_id
                FROM posts
                WHERE post_slug == ?
        $sql = 'SELECT
                post_id
                FROM posts
                WHERE post_slug == ?
-               AND post_is_page == FALSE
-               AND post_is_draft == FALSE
-               LIMIT 1;';
+               AND post_is_page == FALSE';
+
+       if ($include_drafts == false) {
+               $sql .= ' AND post_is_draft == FALSE';
+       }
+
+       $sql .= ' LIMIT 1';
+
+       $sql .= ';';
 
        foreach (cx_db_query($sql, $post_slug) as $post) {
                return $post['post_id'];
        }
 
        return null;
 
        foreach (cx_db_query($sql, $post_slug) as $post) {
                return $post['post_id'];
        }
 
        return null;
+
 }
 
 }
 
-function cx_posts_find_page_id($post_slug) {
+function cx_posts_find_page_id($post_slug, bool $include_drafts = false) {
        $sql = 'SELECT
                post_id
                FROM posts
                WHERE post_slug == ?
        $sql = 'SELECT
                post_id
                FROM posts
                WHERE post_slug == ?
-               AND post_is_page == TRUE
-               AND post_is_draft == FALSE
-               LIMIT 1;';
+               AND post_is_page == TRUE';
+
+       if ($include_drafts == false) {
+               $sql .= ' AND post_is_draft == FALSE';
+       }
+
+       $sql .= ' LIMIT 1';
+
+       $sql .= ';';
 
        foreach (cx_db_query($sql, $post_slug) as $post) {
                return $post['post_id'];
 
        foreach (cx_db_query($sql, $post_slug) as $post) {
                return $post['post_id'];