X-Git-Url: https://git.bts.cx/cx.git/blobdiff_plain/2c13f7538d3e22d07bbdf3d8aec3e16d8c156986..c31a7eee27fd40e7aa558ad15e33f65f9fb6aed2:/cx/lib/posts.php?ds=sidebyside diff --git a/cx/lib/posts.php b/cx/lib/posts.php index 9fb4e35..326d81c 100644 --- a/cx/lib/posts.php +++ b/cx/lib/posts.php @@ -45,6 +45,11 @@ class Post { } } + public function get_permalink_path() { + $post_permalink = $this->is_page ? '/' . $this->slug : '/' . date('Y', $this->date) . '/' . date('m', $this->date) . '/' . $this->slug; + return $post_permalink; + } + public function get_metadata() { $data = []; @@ -99,7 +104,8 @@ function cx_posts_add_post($site_id, $title, $slug, $date, $page, $draft, $nav_i 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) { @@ -211,30 +217,43 @@ function cx_posts_find_post($post_id) { 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 == ? - 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; + } -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 == ? - 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'];