diff --git a/system/includes/functions.php b/system/includes/functions.php index aabeaa8..eec8e4d 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -9,44 +9,49 @@ use \Suin\RSSWriter\Channel; use \Suin\RSSWriter\Item; // Get blog post path. Unsorted. Mostly used on widget. -function get_post_unsorted(){ +function get_post_unsorted($draft = false){ static $_cache = array(); if(empty($_cache)){ // Get the names of all the posts - - $_cache = glob('content/*/blog/*.md', GLOB_NOSORT); + $folder = ($draft)?'draft/*/blog/*.md':'content/*/blog/*.md'; + $_cache = glob($folder, GLOB_NOSORT); } return $_cache; } // Get blog post with more info about the path. Sorted by filename. -function get_post_sorted(){ +function get_post_sorted($draft = false){ static $tmp= array(); static $_cache = array(); - - if(empty($_cache)){ + static $_cache_draft = array(); + + if((!$draft && empty($_cache)) || ($draft && empty($_cache_draft))){ // Get the names of all the posts - - $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); + $folder = (($draft)?'draft/*/blog/*.md':'content/*/blog/*.md'); + $tmp = glob($folder, GLOB_NOSORT); if (is_array($tmp)) { foreach($tmp as $file) { - $_cache[] = pathinfo($file); + if ($draft) + $_cache_draft[] = pathinfo($file); + else + $_cache[] = pathinfo($file); } } } - - usort($_cache, "sortfile"); - - return $_cache; + if ($draft) + usort($_cache_draft, "sortfile"); + else + usort($_cache, "sortfile"); + return ($draft)?$_cache_draft:$_cache; } // Get static page path. Unsorted. @@ -108,10 +113,9 @@ function sortdate($a, $b) { } // Return blog posts. -function get_posts($posts, $page = 1, $perpage = 0){ - +function get_posts($posts, $page = 1, $perpage = 0 , $draft = false){ if(empty($posts)) { - $posts = get_post_sorted(); + $posts = get_post_sorted($draft); } $tmp = array(); @@ -196,9 +200,9 @@ function get_posts($posts, $page = 1, $perpage = 0){ } // Find post by year, month and name, previous, and next. -function find_post($year, $month, $name){ +function find_post($year, $month, $name,$draft = false){ - $posts = get_post_sorted(); + $posts = get_post_sorted($draft); foreach ($posts as $index => $v) { $url = $v['basename']; @@ -300,9 +304,9 @@ function get_archive($req, $page, $perpage){ } // Return posts list on profile. -function get_profile($profile, $page, $perpage){ +function get_profile($profile, $page, $perpage, $draft = false){ - $posts = get_post_sorted(); + $posts = get_post_sorted($draft); $tmp = array(); @@ -1563,8 +1567,12 @@ function toolbar() { EOF; echo '
'; -} \ No newline at end of file +}