Browse Source

Fix views reset problem. See #618

pull/640/head
danpros 2 years ago
parent
commit
23c4427300
7 changed files with 34 additions and 71 deletions
  1. +29
    -10
      system/admin/admin.php
  2. +2
    -12
      system/admin/views/popular-posts.html.php
  3. +0
    -12
      system/admin/views/posts-list.html.php
  4. +0
    -12
      system/admin/views/scheduled.html.php
  5. +0
    -12
      system/admin/views/user-draft.html.php
  6. +0
    -12
      system/admin/views/user-posts.html.php
  7. +3
    -1
      system/includes/functions.php

+ 29
- 10
system/admin/admin.php View File

@ -231,6 +231,9 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
$tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ',')));
$tag = array_filter(array_unique($tag));
$tagslang = "content/data/tags.lang";
$newfile = '';
$views = array();
$viewsFile = "content/data/views.json";
if (file_exists($tagslang)) {
$taglang = array_flip(unserialize(file_get_contents($tagslang)));
$tflip = array_intersect_key($taglang, array_flip($tag));
@ -347,17 +350,16 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
if($dir[4] == 'draft') {
if (date('Y-m-d-H-i-s') >= $olddate) {
$filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else {
$filename = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
}
} else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
}
file_put_contents($filename, print_r($post_content, true));
file_put_contents($newfile, print_r($post_content, true));
unlink($oldfile);
$newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else {
@ -382,18 +384,17 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
} else {
if($dir[4] == 'draft') {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else {
if (date('Y-m-d-H-i-s') >= $olddate) {
$filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else {
$filename = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $dirScheduled . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
}
}
file_put_contents($filename, print_r($post_content, true));
file_put_contents($newfile, print_r($post_content, true));
unlink($oldfile);
$newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md';
}
@ -426,6 +427,15 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
rebuilt_cache('all');
clear_post_cache($dt, $post_tag, $post_url, $oldfile, $category, $type);
if ($oldfile != $newfile) {
if (file_exists($viewsFile)) {
$views = json_decode(file_get_contents($viewsFile), true);
$arr = replace_key($views, $oldfile, $newfile);
file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE));
}
}
if ($destination == 'post') {
if(!empty($revertPost)) {
$drafturl = site_url() . 'admin/draft';
@ -1109,3 +1119,12 @@ function clear_cache()
unlink($file);
}
}
function replace_key($arr, $oldkey, $newkey) {
if(array_key_exists($oldkey, $arr)) {
$keys = array_keys($arr);
$keys[array_search($oldkey, $keys)] = $newkey;
return array_combine($keys, $arr);
}
return $arr;
}

+ 2
- 12
system/admin/views/popular-posts.html.php View File

@ -14,19 +14,8 @@
<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++;
?>
<?php if (strpos($p->file, '/scheduled/') == false && strpos($p->file, '/draft/') == false) { ?>
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo format_date($p->date) ?></td>
@ -38,6 +27,7 @@
<td><a class="btn btn-primary btn-xs" href="<?php echo $p->url ?>/edit?destination=admin/posts"><?php echo i18n('Edit');?></a> <a
class="btn btn-danger btn-xs" href="<?php echo $p->url ?>/delete?destination=admin/posts"><?php echo i18n('Delete');?></a></td>
</tr>
<?php } ?>
<?php endforeach; ?>
</table>
<?php } else {


+ 0
- 12
system/admin/views/posts-list.html.php View File

@ -14,19 +14,7 @@
<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><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo format_date($p->date) ?></td>


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

@ -12,19 +12,7 @@
<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>


+ 0
- 12
system/admin/views/user-draft.html.php View File

@ -12,19 +12,7 @@
<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) ?></td>


+ 0
- 12
system/admin/views/user-posts.html.php View File

@ -15,19 +15,7 @@
<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><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo format_date($p->date) ?></td>


+ 3
- 1
system/includes/functions.php View File

@ -1437,7 +1437,9 @@ function popular_posts($custom = null, $count = null)
if (empty($custom)) {
echo '<ul>';
foreach ($posts as $post) {
echo '<li><a href="' . $post->url . '">' . $post->title . '</a></li>';
if (strpos($post->file, '/scheduled/') == false && strpos($post->file, '/draft/') == false) {
echo '<li><a href="' . $post->url . '">' . $post->title . '</a></li>';
}
}
echo '</ul>';
}


Loading…
Cancel
Save