From 212bdf41522513f4e0d796ad9d567b9e401940c3 Mon Sep 17 00:00:00 2001 From: danpros Date: Wed, 29 Nov 2023 16:34:32 +0700 Subject: [PATCH] Simple scheduled post Publish a post with future date or time, it will go into scheduled posts. --- system/admin/admin.php | 124 +++++++++++++-------- system/admin/views/add-content.html.php | 13 ++- system/admin/views/edit-content.html.php | 7 +- system/admin/views/scheduled.html.php | 57 ++++++++++ system/htmly.php | 142 +++++++++++++++++++----- system/includes/functions.php | 181 +++++++++++++++++++++++++++---- 6 files changed, 424 insertions(+), 100 deletions(-) create mode 100644 system/admin/views/scheduled.html.php diff --git a/system/admin/admin.php b/system/admin/admin.php index dbd1d1d..c8c99c2 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -85,7 +85,7 @@ function remove_accent($str) } // Add content -function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null) +function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null, $dateTime = null) { $tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ','))); @@ -118,12 +118,8 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty $post_tagmd = safe_html(implode(',', $tag)); } - $post_date = date('Y-m-d-H-i-s'); - $post_title = safe_html($title); - if (is_null($media)) { - $media = ''; - } - $post_media = preg_replace('/\s\s+/', ' ', strip_tags($media)); + $post_date = date('Y-m-d-H-i-s', strtotime($dateTime)); + $post_title = safe_html($title); $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($post_tag))); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); @@ -131,7 +127,7 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty $post_t = explode(',', $post_tag); $pret_t = explode(',', $post_tagmd); $tags = tag_cloud(true); - $timestamp = date('YmdHis'); + $timestamp = date('YmdHis', strtotime($dateTime)); $combine = array_combine($pret_t, $post_t); $inter = array_intersect_key($tags, array_flip($post_t)); @@ -180,7 +176,7 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty $tagmd = ""; } if ($media!== null) { - $post_media = "\n"; + $post_media = "\n"; } else { $post_media = ""; } @@ -193,7 +189,11 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/' . $category. '/'.$type. '/'; + if (date('Y-m-d-H-i-s') >= $post_date) { + $dir = 'content/' . $user . '/blog/' . $category. '/'.$type. '/'; + } else { + $dir = 'content/' . $user . '/blog/' . $category. '/'.$type. '/scheduled/'; + } } else { $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } @@ -211,7 +211,11 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename, $category, $type); if (empty($draft)) { - $redirect = site_url() . 'admin/mine'; + if (date('Y-m-d-H-i-s') >= $post_date) { + $redirect = site_url() . 'admin/mine'; + } else { + $redirect = site_url() . 'admin/scheduled'; + } } else { $redirect = site_url() . 'admin/draft'; } @@ -263,10 +267,6 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ } $post_title = safe_html($title); - if (is_null($media)) { - $media = ''; - } - $post_media = preg_replace('/\s\s+/', ' ', strip_tags($media)); $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($post_tag))); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); @@ -314,11 +314,30 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ $tagmd = ""; } if ($media !== null) { - $post_media = "\n"; + $post_media = "\n"; } else { $post_media = ""; } $post_content = "" . $post_description . $tagmd . $post_media . "\n\n" . $content; + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + $dirScheduled = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/scheduled/'; + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + if (is_dir($dirScheduled)) { + } else { + mkdir($dirScheduled, 0775, true); + } if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { @@ -326,33 +345,34 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[4] == 'draft') { - $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + if (date('Y-m-d-H-i-s') >= $olddate) { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } - if (is_dir($dirBlog)) { - } else { - mkdir($dirBlog, 0775, true); - } - - if (is_dir($dirDraft)) { - } else { - mkdir($dirDraft, 0775, true); - } - file_put_contents($filename, print_r($post_content, true)); unlink($oldfile); $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { - if ($dir[3] === $category) { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; + if ($dir[3] === $category) { + + if($dir[4] == 'draft') { + $newfile = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + if (date('Y-m-d-H-i-s') >= $olddate) { + $newfile = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $newfile = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + } + if ($oldfile === $newfile) { file_put_contents($oldfile, print_r($post_content, true)); } else { @@ -361,23 +381,14 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ } } else { - $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type. '/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[4] == 'draft') { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { - $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; - } - - if (is_dir($dirBlog)) { - } else { - mkdir($dirBlog, 0775, true); - } - - if (is_dir($dirDraft)) { - } else { - mkdir($dirDraft, 0775, true); + if (date('Y-m-d-H-i-s') >= $olddate) { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } file_put_contents($filename, print_r($post_content, true)); @@ -420,11 +431,21 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ $drafturl = site_url() . 'admin/draft'; header("Location: $drafturl"); } else { - header("Location: $posturl"); + if (date('Y-m-d-H-i-s') >= $olddate) { + header("Location: $posturl"); + } else { + $schurl = site_url() . 'admin/scheduled'; + header("Location: $schurl"); + } } } else { if(!empty($publishDraft)) { - header("Location: $posturl"); + if (date('Y-m-d-H-i-s') >= $olddate) { + header("Location: $posturl"); + } else { + $schurl = site_url() . 'admin/scheduled'; + header("Location: $schurl"); + } } elseif (!empty($revertPost)) { $drafturl = site_url() . 'admin/draft'; header("Location: $drafturl"); @@ -1081,3 +1102,10 @@ function clear_page_cache($url) unlink($p); } } + +function clear_cache() +{ + foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } +} diff --git a/system/admin/views/add-content.html.php b/system/admin/views/add-content.html.php index bf22196..316c53d 100644 --- a/system/admin/views/add-content.html.php +++ b/system/admin/views/add-content.html.php @@ -106,7 +106,18 @@ $( function() {
- +
+
+ + +
+
+ + +
+ Publish a post with future date or time, it will go into scheduled posts. +
+

diff --git a/system/admin/views/edit-content.html.php b/system/admin/views/edit-content.html.php index e69cdce..befe1bc 100644 --- a/system/admin/views/edit-content.html.php +++ b/system/admin/views/edit-content.html.php @@ -39,7 +39,11 @@ $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; // Category string $cat = explode('/', $replaced); -$category = $cat[count($cat) - 3]; +if ($cat[count($cat) - 2] === 'scheduled') { +$category = $cat[count($cat) - 4]; +} else { +$category = $cat[count($cat) - 3]; +} $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); @@ -161,6 +165,7 @@ $( function() {
+ Publish a post with future date or time, it will go into scheduled posts.
diff --git a/system/admin/views/scheduled.html.php b/system/admin/views/scheduled.html.php new file mode 100644 index 0000000..4176248 --- /dev/null +++ b/system/admin/views/scheduled.html.php @@ -0,0 +1,57 @@ + +

+
+ +

+ + + + + + + + + + + + + + + + + + + + +
title ?>date, 'd F Y, H:i:s') ?>category);?>tag ?>
+ +
+
+ +
+ + diff --git a/system/htmly.php b/system/htmly.php index a1e4dda..10fbcca 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -14,6 +14,9 @@ if (config('timezone')) { date_default_timezone_set('Asia/Jakarta'); } +// Publish scheduled post +publish_scheduled(); + // The front page of the blog get('/index', function () { @@ -466,6 +469,12 @@ post('/add/content', function () { $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); $category = from($_REQUEST, 'category'); + $date = from($_REQUEST, 'date'); + $time = from($_REQUEST, 'time'); + $dateTime = null; + if ($date !== null && $time !== null) { + $dateTime = $date . ' ' . $time; + } if (empty($is_post) && empty($is_image) && empty($is_video) && empty($is_audio) && empty($is_link) && empty($is_quote)) { $add = site_url() . 'admin/content'; @@ -474,45 +483,45 @@ post('/add/content', function () { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime); } } else { $message['error'] = ''; @@ -977,6 +986,71 @@ get('/admin/draft', function () { } }); +// Show admin/scheduled +get('/admin/scheduled', function () { + + if (login()) { + + config('views.root', 'system/admin/views'); + + $name = $_SESSION[config("site.url")]['user']; + + $page = from($_GET, 'page'); + $page = $page ? (int)$page : 1; + $perpage = config('profile.perpage'); + + $posts = get_scheduled($name, $page, $perpage); + + $total = get_scheduledcount($name); + + $author = get_author($name); + + if (isset($author[0])) { + $author = $author[0]; + } else { + $author = default_profile($name); + } + + if (empty($posts) || $page < 1) { + render('scheduled', array( + 'title' => 'Scheduled posts' . ' - ' . blog_title(), + 'description' => strip_tags(blog_description()), + 'canonical' => site_url(), + 'page' => $page, + 'heading' => 'Scheduled posts', + 'posts' => null, + 'about' => $author->about, + 'name' => $author->name, + 'type' => 'is_admin-scheduled', + 'is_admin' => true, + 'bodyclass' => 'admin-scheduled', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Scheduled posts for: ' . $author->name, + 'pagination' => has_pagination($total, $perpage, $page) + )); + die; + } + + render('scheduled', array( + 'title' => 'Scheduled posts' . ' - ' . blog_title(), + 'description' => strip_tags(blog_description()), + 'canonical' => site_url(), + 'heading' => 'Scheduled posts', + 'page' => $page, + 'posts' => $posts, + 'about' => $author->about, + 'name' => $author->name, + 'type' => 'is_admin-scheduled', + 'is_admin' => true, + 'bodyclass' => 'admin-scheduled', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Scheduled posts for: ' . $author->name, + 'pagination' => has_pagination($total, $perpage, $page) + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + // Show admin/content get('/admin/content', function () { if (login()) { @@ -2347,10 +2421,14 @@ get('/post/:name/edit', function ($name) { $post = find_post(null, null, $name); if (!$post) { - $post = find_draft(null, null, $name); - if (!$post) { - not_found(); - } + $post = find_draft($year, $month, $name); + if (!$post) { + $post = find_scheduled($year, $month, $name); + if (!$post) { + not_found(); + } + } + } $current = $post['current']; @@ -2554,10 +2632,14 @@ get('/post/:name/delete', function ($name) { $post = find_post(null, null, $name); if (!$post) { - $post = find_draft(null, null, $name); - if (!$post) { - not_found(); - } + $post = find_draft($year, $month, $name); + if (!$post) { + $post = find_scheduled($year, $month, $name); + if (!$post) { + not_found(); + } + } + } $current = $post['current']; @@ -3341,9 +3423,13 @@ get('/:year/:month/:name/edit', function ($year, $month, $name) { if (!$post) { $post = find_draft($year, $month, $name); - if (!$post) { - not_found(); - } + if (!$post) { + $post = find_scheduled($year, $month, $name); + if (!$post) { + not_found(); + } + } + } $current = $post['current']; @@ -3548,9 +3634,13 @@ get('/:year/:month/:name/delete', function ($year, $month, $name) { if (!$post) { $post = find_draft($year, $month, $name); - if (!$post) { - not_found(); - } + if (!$post) { + $post = find_scheduled($year, $month, $name); + if (!$post) { + not_found(); + } + } + } $current = $post['current']; diff --git a/system/includes/functions.php b/system/includes/functions.php index 904ee69..160bb3f 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -126,6 +126,20 @@ function get_draft_posts() return $_draft; } +// Get scheduled posts. +function get_scheduled_posts() +{ + static $_scheduled = array(); + if (empty($_scheduled)) { + $url = 'cache/index/index-scheduled.txt'; + if (!file_exists($url)) { + rebuilt_cache('all'); + } + $_scheduled = unserialize(file_get_contents($url)); + } + return $_scheduled; +} + // Get category info files. function get_category_files() { @@ -176,37 +190,28 @@ function rebuilt_cache($type) $posts_cache_unsorted = array(); $page_cache = array(); $author_cache = array(); + $scheduled = array(); if (is_dir($dir) === false) { mkdir($dir, 0775, true); } if ($type === 'posts') { - $tmpu = array(); - $tmpu = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); - if (is_array($tmpu)) { - foreach ($tmpu as $fileu) { - if(strpos($fileu, '/draft/') === false) { - $posts_cache_unsorted[] = $fileu; - } - } - } - $string = serialize($posts_cache_unsorted); - file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); - $tmp = array(); $tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); - - if (is_array($tmp)) { + if (is_array($tmp)) { foreach ($tmp as $file) { - if(strpos($file, '/draft/') === false) { - $posts_cache_sorted[] = pathinfo($file); + if(strpos($file, '/draft/') === false && strpos($file, '/scheduled/') === false) { + $posts_cache_unsorted[] = $file; + $posts_cache_sorted[] = pathinfo($file); } } } + $string_unsorted = serialize($posts_cache_unsorted); + file_put_contents('cache/index/index-unsorted.txt', print_r($string_unsorted, true)); usort($posts_cache_sorted, "sortfile"); - $string = serialize($posts_cache_sorted); - file_put_contents('cache/index/index-sorted.txt', print_r($string, true)); + $string_sorted = serialize($posts_cache_sorted); + file_put_contents('cache/index/index-sorted.txt', print_r($string_sorted, true)); } elseif ($type === 'page') { $page_cache = glob('content/static/*.md', GLOB_NOSORT); $string = serialize($page_cache); @@ -223,12 +228,24 @@ function rebuilt_cache($type) $category_cache = glob('content/data/category/*.md', GLOB_NOSORT); $string = serialize($category_cache); file_put_contents('cache/index/index-category.txt', print_r($string, true)); + } elseif ($type === 'scheduled') { + $tmp = array(); + $tmp = glob('content/*/*/*/*/scheduled/*.md', GLOB_NOSORT); + if (is_array($tmp)) { + foreach ($tmp as $file) { + $scheduled[] = pathinfo($file); + } + } + usort($scheduled, "sortfile"); + $string = serialize($scheduled); + file_put_contents('cache/index/index-scheduled.txt', print_r($string, true)); } elseif ($type === 'all') { rebuilt_cache('posts'); rebuilt_cache('page'); rebuilt_cache('subpage'); rebuilt_cache('author'); rebuilt_cache('category'); + rebuilt_cache('scheduled'); } foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) { @@ -266,7 +283,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // Author string $str = explode('/', $replaced); $author = $str[count($str) - 5]; - if($str[count($str) - 3] == 'uncategorized') { + if($str[count($str) - 3] && $str[count($str) - 4]== 'uncategorized') { $category = default_category(); $post->category = '' . $category->title . ''; $post->categoryUrl = $category->url; @@ -274,9 +291,8 @@ function get_posts($posts, $page = 1, $perpage = 0) $post->categoryTitle = $category->title; $post->categoryb = '' . $category->title . ''; } else { - foreach ($catC as $k => $v) { - if ($v['0'] === $str[count($str) - 3]) { + if ($v['0'] === $str[count($str) - 3] || $v['0'] === $str[count($str) - 4]) { $post->category = '' . $v['1'] . ''; $post->categoryUrl = site_url() . 'category/' . $v['0']; $post->categorySlug = $v['0']; @@ -303,7 +319,6 @@ function get_posts($posts, $page = 1, $perpage = 0) } $post->type = $type; - $dt = str_replace($replaced, '', $arr[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -486,6 +501,50 @@ function find_draft($year, $month, $name) } } +// Find draft. +function find_scheduled($year, $month, $name) +{ + $posts = get_scheduled_posts(); + + foreach ($posts as $index => $v) { + $arr = explode('_', $v['basename']); + if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_posts($posts, $index + 1, 1); + $nx = get_posts($posts, $index, 1); + $pr = get_posts($posts, $index + 2, 1); + + if ($index == 0) { + if (isset($pr[0])) { + return array( + 'current' => $ar[0], + 'prev' => $pr[0] + ); + } else { + return array( + 'current' => $ar[0], + 'prev' => null + ); + } + } elseif (count($posts) == $index + 1) { + return array( + 'current' => $ar[0], + 'next' => $nx[0] + ); + } else { + return array( + 'current' => $ar[0], + 'next' => $nx[0], + 'prev' => $pr[0] + ); + } + } + } +} + // Return category page. function get_category($category, $page, $perpage, $random) { @@ -779,6 +838,31 @@ function get_draft($profile, $page, $perpage) return $tmp = get_posts($tmp, $page, $perpage); } +// Return scheduled list +function get_scheduled($profile, $page, $perpage) +{ + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + $posts = get_scheduled_posts(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + $str = explode('/', $v['dirname']); + $author = $str[count($str) - 5]; + if (strtolower($profile) === strtolower($author) || $role === 'admin') { + $tmp[] = $v; + } + } + + if (empty($tmp)) { + return false; + } + + return $tmp = get_posts($tmp, $page, $perpage); +} + // Return author info. function get_author($name) { @@ -1130,6 +1214,34 @@ function get_draftcount($var) return count($tmp); } +// Return draft count. Matching $var and $str provided. +function get_scheduledcount($var) +{ + $posts = get_scheduled_posts(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + + $filepath = $v['dirname'] . '/' . $v['basename']; + + // Extract the date + $arr = explode('_', $filepath); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + $str = explode('/', $replaced); + $cat = $str[count($str) - 5]; + + if (stripos($cat, "$var") !== false) { + $tmp[] = $v; + } + } + + return count($tmp); +} + // Return tag count. Matching $var and $str provided. function get_tagcount($var, $str) { @@ -2916,6 +3028,7 @@ EOF; } } echo '
  • ' . i18n('Pages') . '
  • '; + echo '
  • ' . 'Scheduled' . '
  • '; echo '
  • ' . i18n('Draft') . '
  • '; if ($role === 'admin') { echo '
  • ' . i18n('Categories') . '
  • '; @@ -3035,7 +3148,7 @@ function get_content_tag($tag, $string, $alt = null) // Strip html comment function remove_html_comments($content) { - $patterns = array('/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/'); + $patterns = array('/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/', '/(\s|)(\s|)/'); return preg_replace($patterns, '', $content); } @@ -3260,7 +3373,7 @@ function format_date($date, $dateFormat = null) $dateFormat = config('date.format'); } if (extension_loaded('intl')) { - $format_map = array('d' => 'dd', 'm' => 'MM', 'M' => 'MMM', 'F' => 'MMMM', 'Y' => 'yyyy'); + $format_map = array('s' => 'ss', 'i' => 'mm', 'H' => 'HH','d' => 'dd', 'm' => 'MM', 'M' => 'MMM', 'F' => 'MMMM', 'Y' => 'yyyy'); $intlFormat = strtr($dateFormat, $format_map); $formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::NONE, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $intlFormat); return $formatter->format($date); @@ -3283,3 +3396,23 @@ function valueMaker($value) return "0"; return (string)$value; } + +function publish_scheduled() +{ + $posts = get_scheduled_posts(); + if (!empty($posts)) { + foreach ($posts as $index => $v) { + $str = explode('_', $v['basename']); + $old = $v['dirname'] . '/' . $v['basename']; + $new = dirname($v['dirname']) . '/' . $v['basename']; + $t = str_replace('-', '', $str[0]); + $time = new DateTime($t); + $timestamp = $time->format("Y m d H:i:s"); + if (date('Y m d H:i:s') >= $timestamp) { + rename($old, $new); + rebuilt_cache('all'); + clear_cache(); + } + } + } +} \ No newline at end of file