Browse Source

Simple scheduled post

Publish a post with future date or time, it will go into scheduled posts.
pull/640/head
danpros 2 years ago
parent
commit
212bdf4152
6 changed files with 424 additions and 100 deletions
  1. +76
    -48
      system/admin/admin.php
  2. +12
    -1
      system/admin/views/add-content.html.php
  3. +6
    -1
      system/admin/views/edit-content.html.php
  4. +57
    -0
      system/admin/views/scheduled.html.php
  5. +116
    -26
      system/htmly.php
  6. +157
    -24
      system/includes/functions.php

+ 76
- 48
system/admin/admin.php View File

@ -85,7 +85,7 @@ function remove_accent($str)
} }
// Add content // 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, ','))); $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_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_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))); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$description = safe_html($description); $description = safe_html($description);
@ -131,7 +127,7 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty
$post_t = explode(',', $post_tag); $post_t = explode(',', $post_tag);
$pret_t = explode(',', $post_tagmd); $pret_t = explode(',', $post_tagmd);
$tags = tag_cloud(true); $tags = tag_cloud(true);
$timestamp = date('YmdHis');
$timestamp = date('YmdHis', strtotime($dateTime));
$combine = array_combine($pret_t, $post_t); $combine = array_combine($pret_t, $post_t);
$inter = array_intersect_key($tags, array_flip($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 = ""; $tagmd = "";
} }
if ($media!== null) { if ($media!== null) {
$post_media = "\n<!--" .$type. " " . $post_media . " " .$type. "-->";
$post_media = "\n<!--" .$type. " " . preg_replace('/\s\s+/', ' ', strip_tags($media)) . " " .$type. "-->";
} else { } else {
$post_media = ""; $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { 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 { } else {
$dir = 'content/' . $user . '/blog/' . $category. '/draft/'; $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); clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename, $category, $type);
if (empty($draft)) { 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 { } else {
$redirect = site_url() . 'admin/draft'; $redirect = site_url() . 'admin/draft';
} }
@ -263,10 +267,6 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
} }
$post_title = safe_html($title); $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_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))); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$description = safe_html($description); $description = safe_html($description);
@ -314,11 +314,30 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
$tagmd = ""; $tagmd = "";
} }
if ($media !== null) { if ($media !== null) {
$post_media = "\n<!--" . $type . " " . $post_media. " " . $type . "-->";
$post_media = "\n<!--" . $type . " " . preg_replace('/\s\s+/', ' ', strip_tags($media)) . " " . $type . "-->";
} else { } else {
$post_media = ""; $post_media = "";
} }
$post_content = "<!--t " . $post_title . " t-->" . $post_description . $tagmd . $post_media . "\n\n" . $content; $post_content = "<!--t " . $post_title . " t-->" . $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)) { 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)) { 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') { 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 { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $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)); file_put_contents($filename, print_r($post_content, true));
unlink($oldfile); unlink($oldfile);
$newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } 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) { if ($oldfile === $newfile) {
file_put_contents($oldfile, print_r($post_content, true)); file_put_contents($oldfile, print_r($post_content, true));
} else { } else {
@ -361,23 +381,14 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
} }
} else { } else {
$dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type. '/';
$dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/';
if($dir[4] == 'draft') { if($dir[4] == 'draft') {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } 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)); 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'; $drafturl = site_url() . 'admin/draft';
header("Location: $drafturl"); header("Location: $drafturl");
} else { } 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 { } else {
if(!empty($publishDraft)) { 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)) { } elseif (!empty($revertPost)) {
$drafturl = site_url() . 'admin/draft'; $drafturl = site_url() . 'admin/draft';
header("Location: $drafturl"); header("Location: $drafturl");
@ -1081,3 +1102,10 @@ function clear_page_cache($url)
unlink($p); unlink($p);
} }
} }
function clear_cache()
{
foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) {
unlink($file);
}
}

+ 12
- 1
system/admin/views/add-content.html.php View File

@ -106,7 +106,18 @@ $( function() {
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-row">
<div class="col">
<label for="pDate"><?php echo i18n('Date');?></label>
<input type="date" id="pDate" name="date" class="form-control text" value="<?php echo date('Y-m-d'); ?>">
</div>
<div class="col">
<label for="pTime"><?php echo i18n('Time');?></label>
<input step="1" type="time" id="pTime" name="time" class="form-control text" value="<?php echo date('H:i:s'); ?>">
</div>
<small style="margin-top:10px;"><em>Publish a post with future date or time, it will go into scheduled posts.</em></small>
</div>
<br>
<label for="pURL">Url (<?php echo i18n('optional');?>)</label> <label for="pURL">Url (<?php echo i18n('optional');?>)</label>
<input type="text" class="form-control text" id="pURL" name="url" value="<?php if (isset($postUrl)) { echo $postUrl;} ?>" placeholder="<?php echo i18n('If_the_url_leave_empty_we_will_use_the_post_title');?>"/> <input type="text" class="form-control text" id="pURL" name="url" value="<?php if (isset($postUrl)) { echo $postUrl;} ?>" placeholder="<?php echo i18n('If_the_url_leave_empty_we_will_use_the_post_title');?>"/>
<br> <br>


+ 6
- 1
system/admin/views/edit-content.html.php View File

@ -39,7 +39,11 @@ $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string // Category string
$cat = explode('/', $replaced); $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]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
@ -161,6 +165,7 @@ $( function() {
<label for="pTime"><?php echo i18n('Time');?></label> <label for="pTime"><?php echo i18n('Time');?></label>
<input step="1" type="time" id="pTime" name="time" class="form-control text" value="<?php echo $time->format('H:i:s'); ?>"> <input step="1" type="time" id="pTime" name="time" class="form-control text" value="<?php echo $time->format('H:i:s'); ?>">
</div> </div>
<small style="margin-top:10px;"><em>Publish a post with future date or time, it will go into scheduled posts.</em></small>
</div> </div>
<br> <br>
<label for="pURL">Url (<?php echo i18n('optional');?>)</label> <label for="pURL">Url (<?php echo i18n('optional');?>)</label>


+ 57
- 0
system/admin/views/scheduled.html.php View File

@ -0,0 +1,57 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<h2 class="post-index"><?php echo $heading ?></h2>
<br>
<a class="btn btn-primary right" href="<?php echo site_url();?>admin/content"><?php echo i18n('Add_new_post');?></a>
<br><br>
<?php if (!empty($posts)) { ?>
<table class="table post-list">
<tr class="head">
<th><?php echo i18n('Title');?></th>
<th><?php echo i18n('Publish');?></th>
<th><?php echo i18n('Category');?></th>
<th><?php echo i18n('Tags');?></th>
<th><?php echo i18n('Operations');?></th>
</tr>
<?php $i = 0;
$len = count($posts); ?>
<?php foreach ($posts as $p): ?>
<?php
if ($i == 0) {
$class = 'item first';
} elseif ($i == $len - 1) {
$class = 'item last';
} else {
$class = 'item';
}
$i++;
?>
<tr class="<?php echo $class ?>">
<td><?php echo $p->title ?></td>
<td><?php echo format_date($p->date, 'd F Y, H:i:s') ?></td>
<td><a href="<?php echo str_replace('category', 'admin/categories', $p->categoryUrl); ?>"><?php echo strip_tags($p->category);?></a></td>
<td><?php echo $p->tag ?></td>
<td><a class="btn btn-primary btn-xs" href="<?php echo $p->url ?>/edit?destination=admin/scheduled"><?php echo i18n('Edit');?></a> <a class="btn btn-danger btn-xs" href="<?php echo $p->url ?>/delete?destination=admin/scheduled"><?php echo i18n('Delete');?></a></td>
</tr>
<?php endforeach; ?>
</table>
<?php if (!empty($pagination['prev']) || !empty($pagination['next'])): ?>
<br>
<div class="pager">
<ul class="pagination">
<?php if (!empty($pagination['prev'])) { ?>
<li class="newer page-item"><a class="page-link" href="?page=<?php echo $page - 1 ?>" rel="prev">&#8592; <?php echo i18n('Newer');?></a></li>
<?php } else { ?>
<li class="page-item disabled" ><span class="page-link">&#8592; <?php echo i18n('Newer');?></span></li>
<?php } ?>
<li class="page-number page-item disabled"><span class="page-link"><?php echo $pagination['pagenum'];?></span></li>
<?php if (!empty($pagination['next'])) { ?>
<li class="older page-item" ><a class="page-link" href="?page=<?php echo $page + 1 ?>" rel="next"><?php echo i18n('Older');?> &#8594;</a></li>
<?php } else { ?>
<li class="page-item disabled" ><span class="page-link"><?php echo i18n('Older');?> &#8594;</span></li>
<?php } ?>
</ul>
</div>
<?php endif; ?>
<?php } else {
echo 'No scheduled posts found!';
} ?>

+ 116
- 26
system/htmly.php View File

@ -14,6 +14,9 @@ if (config('timezone')) {
date_default_timezone_set('Asia/Jakarta'); date_default_timezone_set('Asia/Jakarta');
} }
// Publish scheduled post
publish_scheduled();
// The front page of the blog // The front page of the blog
get('/index', function () { get('/index', function () {
@ -466,6 +469,12 @@ post('/add/content', function () {
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category'); $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)) { if (empty($is_post) && empty($is_image) && empty($is_video) && empty($is_audio) && empty($is_link) && empty($is_quote)) {
$add = site_url() . 'admin/content'; $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 ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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)) { } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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)) { } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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)) { } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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)) { } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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)) { } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (!empty($url)) { 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 { } else {
$url = $title; $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 { } else {
$message['error'] = ''; $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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Scheduled posts for: ' . $author->name,
'pagination' => has_pagination($total, $perpage, $page)
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Show admin/content // Show admin/content
get('/admin/content', function () { get('/admin/content', function () {
if (login()) { if (login()) {
@ -2347,10 +2421,14 @@ get('/post/:name/edit', function ($name) {
$post = find_post(null, null, $name); $post = find_post(null, null, $name);
if (!$post) { 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']; $current = $post['current'];
@ -2554,10 +2632,14 @@ get('/post/:name/delete', function ($name) {
$post = find_post(null, null, $name); $post = find_post(null, null, $name);
if (!$post) { 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']; $current = $post['current'];
@ -3341,9 +3423,13 @@ get('/:year/:month/:name/edit', function ($year, $month, $name) {
if (!$post) { if (!$post) {
$post = find_draft($year, $month, $name); $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']; $current = $post['current'];
@ -3548,9 +3634,13 @@ get('/:year/:month/:name/delete', function ($year, $month, $name) {
if (!$post) { if (!$post) {
$post = find_draft($year, $month, $name); $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']; $current = $post['current'];


+ 157
- 24
system/includes/functions.php View File

@ -126,6 +126,20 @@ function get_draft_posts()
return $_draft; 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. // Get category info files.
function get_category_files() function get_category_files()
{ {
@ -176,37 +190,28 @@ function rebuilt_cache($type)
$posts_cache_unsorted = array(); $posts_cache_unsorted = array();
$page_cache = array(); $page_cache = array();
$author_cache = array(); $author_cache = array();
$scheduled = array();
if (is_dir($dir) === false) { if (is_dir($dir) === false) {
mkdir($dir, 0775, true); mkdir($dir, 0775, true);
} }
if ($type === 'posts') { 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 = array();
$tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); $tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT);
if (is_array($tmp)) {
if (is_array($tmp)) {
foreach ($tmp as $file) { 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"); 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') { } elseif ($type === 'page') {
$page_cache = glob('content/static/*.md', GLOB_NOSORT); $page_cache = glob('content/static/*.md', GLOB_NOSORT);
$string = serialize($page_cache); $string = serialize($page_cache);
@ -223,12 +228,24 @@ function rebuilt_cache($type)
$category_cache = glob('content/data/category/*.md', GLOB_NOSORT); $category_cache = glob('content/data/category/*.md', GLOB_NOSORT);
$string = serialize($category_cache); $string = serialize($category_cache);
file_put_contents('cache/index/index-category.txt', print_r($string, true)); 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') { } elseif ($type === 'all') {
rebuilt_cache('posts'); rebuilt_cache('posts');
rebuilt_cache('page'); rebuilt_cache('page');
rebuilt_cache('subpage'); rebuilt_cache('subpage');
rebuilt_cache('author'); rebuilt_cache('author');
rebuilt_cache('category'); rebuilt_cache('category');
rebuilt_cache('scheduled');
} }
foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) { foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) {
@ -266,7 +283,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Author string // Author string
$str = explode('/', $replaced); $str = explode('/', $replaced);
$author = $str[count($str) - 5]; $author = $str[count($str) - 5];
if($str[count($str) - 3] == 'uncategorized') {
if($str[count($str) - 3] && $str[count($str) - 4]== 'uncategorized') {
$category = default_category(); $category = default_category();
$post->category = '<a href="' . $category->url . '">' . $category->title . '</a>'; $post->category = '<a href="' . $category->url . '">' . $category->title . '</a>';
$post->categoryUrl = $category->url; $post->categoryUrl = $category->url;
@ -274,9 +291,8 @@ function get_posts($posts, $page = 1, $perpage = 0)
$post->categoryTitle = $category->title; $post->categoryTitle = $category->title;
$post->categoryb = '<a itemprop="item" href="' . $category->url . '"><span itemprop="name">' . $category->title . '</span></a>'; $post->categoryb = '<a itemprop="item" href="' . $category->url . '"><span itemprop="name">' . $category->title . '</span></a>';
} else { } else {
foreach ($catC as $k => $v) { 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 = '<a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1'] . '</a>'; $post->category = '<a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1'] . '</a>';
$post->categoryUrl = site_url() . 'category/' . $v['0']; $post->categoryUrl = site_url() . 'category/' . $v['0'];
$post->categorySlug = $v['0']; $post->categorySlug = $v['0'];
@ -303,7 +319,6 @@ function get_posts($posts, $page = 1, $perpage = 0)
} }
$post->type = $type; $post->type = $type;
$dt = str_replace($replaced, '', $arr[0]); $dt = str_replace($replaced, '', $arr[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $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. // Return category page.
function get_category($category, $page, $perpage, $random) 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 $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. // Return author info.
function get_author($name) function get_author($name)
{ {
@ -1130,6 +1214,34 @@ function get_draftcount($var)
return count($tmp); 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. // Return tag count. Matching $var and $str provided.
function get_tagcount($var, $str) function get_tagcount($var, $str)
{ {
@ -2916,6 +3028,7 @@ EOF;
} }
} }
echo '<li class="tb-mine"><a href="' . $base . 'admin/pages">' . i18n('Pages') . '</a></li>'; echo '<li class="tb-mine"><a href="' . $base . 'admin/pages">' . i18n('Pages') . '</a></li>';
echo '<li class="tb-draft"><a href="' . $base . 'admin/scheduled">' . 'Scheduled' . '</a></li>';
echo '<li class="tb-draft"><a href="' . $base . 'admin/draft">' . i18n('Draft') . '</a></li>'; echo '<li class="tb-draft"><a href="' . $base . 'admin/draft">' . i18n('Draft') . '</a></li>';
if ($role === 'admin') { if ($role === 'admin') {
echo '<li class="tb-categories"><a href="' . $base . 'admin/categories">' . i18n('Categories') . '</a></li>'; echo '<li class="tb-categories"><a href="' . $base . 'admin/categories">' . i18n('Categories') . '</a></li>';
@ -3035,7 +3148,7 @@ function get_content_tag($tag, $string, $alt = null)
// Strip html comment // Strip html comment
function remove_html_comments($content) function remove_html_comments($content)
{ {
$patterns = array('/(\s|)<!--t(.*)t-->(\s|)/', '/(\s|)<!--d(.*)d-->(\s|)/', '/(\s|)<!--tag(.*)tag-->(\s|)/', '/(\s|)<!--image(.*)image-->(\s|)/', '/(\s|)<!--video(.*)video-->(\s|)/', '/(\s|)<!--audio(.*)audio-->(\s|)/', '/(\s|)<!--link(.*)link-->(\s|)/', '/(\s|)<!--quote(.*)quote-->(\s|)/');
$patterns = array('/(\s|)<!--t(.*)t-->(\s|)/', '/(\s|)<!--d(.*)d-->(\s|)/', '/(\s|)<!--tag(.*)tag-->(\s|)/', '/(\s|)<!--image(.*)image-->(\s|)/', '/(\s|)<!--video(.*)video-->(\s|)/', '/(\s|)<!--audio(.*)audio-->(\s|)/', '/(\s|)<!--link(.*)link-->(\s|)/', '/(\s|)<!--quote(.*)quote-->(\s|)/', '/(\s|)<!--post(.*)post-->(\s|)/');
return preg_replace($patterns, '', $content); return preg_replace($patterns, '', $content);
} }
@ -3260,7 +3373,7 @@ function format_date($date, $dateFormat = null)
$dateFormat = config('date.format'); $dateFormat = config('date.format');
} }
if (extension_loaded('intl')) { 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); $intlFormat = strtr($dateFormat, $format_map);
$formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::NONE, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $intlFormat); $formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::NONE, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $intlFormat);
return $formatter->format($date); return $formatter->format($date);
@ -3283,3 +3396,23 @@ function valueMaker($value)
return "0"; return "0";
return (string)$value; 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();
}
}
}
}

Loading…
Cancel
Save