Browse Source

add category column for view posts tables, each post can have multiple tags so table column header "Tags"

pull/431/head
sean1138 4 years ago
parent
commit
2a7f8e938e
1 changed files with 48 additions and 47 deletions
  1. +48
    -47
      system/admin/admin.php

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

@ -58,7 +58,7 @@ function session($user, $pass)
$_SESSION[config("site.url")]['user'] = $user; $_SESSION[config("site.url")]['user'] = $user;
header('location: admin'); header('location: admin');
} else { } else {
return $str = '<li>Your username and password mismatch.</li>';
return $str = '<li>Your username and password mismatch.</li>';
} }
} else if (old_password_verify($pass, $user_enc, $user_pass)) { } else if (old_password_verify($pass, $user_enc, $user_pass)) {
update_user($user, $pass, $user_role); update_user($user, $pass, $user_role);
@ -104,46 +104,46 @@ function add_content($title, $tag, $url, $content, $user, $description = null, $
$tagmd = "\n<!--tag " . $post_tagmd . " tag-->"; $tagmd = "\n<!--tag " . $post_tagmd . " tag-->";
} else { } else {
$tagmd = ""; $tagmd = "";
}
}
if ($media!== null) { if ($media!== null) {
$post_media = "\n<!--" .$type. " " . $post_media . " " .$type. "-->"; $post_media = "\n<!--" .$type. " " . $post_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;
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)) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$post_content = stripslashes($post_content); $post_content = stripslashes($post_content);
} }
$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. '/'; $dir = 'content/' . $user . '/blog/' . $category. '/'.$type. '/';
} else { } else {
$dir = 'content/' . $user . '/blog/' . $category. '/draft/'; $dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true)); file_put_contents($dir . $filename, print_r($post_content, true));
} else { } else {
mkdir($dir, 0775, true); mkdir($dir, 0775, true);
file_put_contents($dir . $filename, print_r($post_content, true)); file_put_contents($dir . $filename, print_r($post_content, true));
} }
save_tag_i18n($post_tag, $post_tagmd); save_tag_i18n($post_tag, $post_tagmd);
rebuilt_cache('all'); rebuilt_cache('all');
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'; $redirect = site_url() . 'admin/mine';
} else { } else {
$redirect = site_url() . 'admin/draft'; $redirect = site_url() . 'admin/draft';
} }
header("Location: $redirect"); header("Location: $redirect");
} }
} }
@ -154,7 +154,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $destination = nul
$oldurl = explode('_', $oldfile); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
$olddate = date('Y-m-d-H-i-s', strtotime($date)); $olddate = date('Y-m-d-H-i-s', strtotime($date));
if ($date !== null) { if ($date !== null) {
$oldurl[0] = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/' . $olddate; $oldurl[0] = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/' . $olddate;
} }
@ -177,47 +177,47 @@ function edit_content($title, $tag, $url, $content, $oldfile, $destination = nul
$tagmd = "\n<!--tag " . $post_tagmd . " tag-->"; $tagmd = "\n<!--tag " . $post_tagmd . " tag-->";
} else { } else {
$tagmd = ""; $tagmd = "";
}
}
if ($media !== null) { if ($media !== null) {
$post_media = "\n<!--" . $type . " " . $post_media. " " . $type . "-->"; $post_media = "\n<!--" . $type . " " . $post_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;
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)) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$post_content = stripslashes($post_content); $post_content = stripslashes($post_content);
} }
if(!empty($revertPost) || !empty($publishDraft)) { if(!empty($revertPost) || !empty($publishDraft)) {
$dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/'; $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/';
$dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; $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';
$filename = $dirBlog . $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)) { if (is_dir($dirBlog)) {
} else { } else {
mkdir($dirBlog, 0775, true);
mkdir($dirBlog, 0775, true);
} }
if (is_dir($dirDraft)) { if (is_dir($dirDraft)) {
} else { } else {
mkdir($dirDraft, 0775, true);
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) { if ($dir[3] === $category) {
$newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md';
if ($oldfile === $newfile) { if ($oldfile === $newfile) {
@ -227,37 +227,37 @@ function edit_content($title, $tag, $url, $content, $oldfile, $destination = nul
file_put_contents($newfile, print_r($post_content, true)); file_put_contents($newfile, print_r($post_content, true));
} }
} else { } else {
$dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type. '/'; $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type. '/';
$dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; $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';
$filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} }
if (is_dir($dirBlog)) { if (is_dir($dirBlog)) {
} else { } else {
mkdir($dirBlog, 0775, true);
mkdir($dirBlog, 0775, true);
} }
if (is_dir($dirDraft)) { if (is_dir($dirDraft)) {
} else { } else {
mkdir($dirDraft, 0775, true);
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';
} }
} }
if(!empty($publishDraft)) { if(!empty($publishDraft)) {
$dt = $olddate; $dt = $olddate;
$t = str_replace('-', '', $dt);
$t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d"); $timestamp = $time->format("Y-m-d");
} else { } else {
@ -267,19 +267,19 @@ function edit_content($title, $tag, $url, $content, $oldfile, $destination = nul
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d"); $timestamp = $time->format("Y-m-d");
} }
// The post date // The post date
$postdate = strtotime($timestamp); $postdate = strtotime($timestamp);
// The post URL // The post URL
if (config('permalink.type') == 'post') { if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url; $posturl = site_url() . 'post/' . $post_url;
} else { } else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url; $posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
} }
save_tag_i18n($post_tag, $post_tagmd); save_tag_i18n($post_tag, $post_tagmd);
rebuilt_cache('all'); rebuilt_cache('all');
clear_post_cache($dt, $post_tag, $post_url, $newfile, $category, $type); clear_post_cache($dt, $post_tag, $post_url, $newfile, $category, $type);
if ($destination == 'post') { if ($destination == 'post') {
@ -375,7 +375,7 @@ function add_sub_page($title, $url, $content, $static, $description = null)
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null, $static = null) function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null, $static = null)
{ {
$dir = substr($oldfile, 0, strrpos($oldfile, '/')); $dir = substr($oldfile, 0, strrpos($oldfile, '/'));
$post_title = safe_html($title); $post_title = safe_html($title);
$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);
@ -410,7 +410,7 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
} else { } else {
$posturl = site_url() . $post_url; $posturl = site_url() . $post_url;
} }
rebuilt_cache('all'); rebuilt_cache('all');
clear_page_cache($post_url); clear_page_cache($post_url);
if ($destination == 'post') { if ($destination == 'post') {
@ -471,7 +471,7 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d
} }
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$post_content = stripslashes($post_content); $post_content = stripslashes($post_content);
} }
@ -482,9 +482,9 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d
rename($oldfile, $newfile); rename($oldfile, $newfile);
file_put_contents($newfile, print_r($post_content, true)); file_put_contents($newfile, print_r($post_content, true));
} }
rename_category_folder($post_url, $oldfile); rename_category_folder($post_url, $oldfile);
rebuilt_cache('all'); rebuilt_cache('all');
if ($destination == 'post') { if ($destination == 'post') {
header("Location: $posturl"); header("Location: $posturl");
@ -681,7 +681,7 @@ function get_user_posts()
echo '<tr class="head"><th>' . i18n('Title') . '</th><th>' . i18n('Published') . '</th>'; echo '<tr class="head"><th>' . i18n('Title') . '</th><th>' . i18n('Published') . '</th>';
if (config("views.counter") == "true") if (config("views.counter") == "true")
echo '<th>Views</th>'; echo '<th>Views</th>';
echo '<th>' . i18n('Tag') . '</th><th>' . i18n('Operations') . '</th></tr>';
echo '<th>' . i18n('Category') . '</th><th>' . i18n('Tags') . '</th><th>' . i18n('Operations') . '</th></tr>';
$i = 0; $i = 0;
$len = count($posts); $len = count($posts);
foreach ($posts as $p) { foreach ($posts as $p) {
@ -698,6 +698,7 @@ function get_user_posts()
echo '<td>' . format_date($p->date) . '</td>'; echo '<td>' . format_date($p->date) . '</td>';
if (config("views.counter") == "true") if (config("views.counter") == "true")
echo '<td>' . $p->views . '</td>'; echo '<td>' . $p->views . '</td>';
echo '<td>' . $p->category . '</td>';
echo '<td>' . $p->tag . '</td>'; echo '<td>' . $p->tag . '</td>';
echo '<td><a href="' . $p->url . '/edit?destination=admin">' . i18n('Edit') . '</a> <a href="' . $p->url . '/delete?destination=admin">' . i18n('Delete') . '</a></td>'; echo '<td><a href="' . $p->url . '/edit?destination=admin">' . i18n('Edit') . '</a> <a href="' . $p->url . '/delete?destination=admin">' . i18n('Delete') . '</a></td>';
echo '</tr>'; echo '</tr>';
@ -815,7 +816,7 @@ function clear_post_cache($post_date, $post_tag, $post_url, $filename, $category
if (file_exists($p)) { if (file_exists($p)) {
unlink($p); unlink($p);
} }
// Delete post permalink // Delete post permalink
$pp = 'cache/page/' . $b . 'post#' . $post_url . '.cache'; $pp = 'cache/page/' . $b . 'post#' . $post_url . '.cache';
if (file_exists($pp)) { if (file_exists($pp)) {
@ -873,7 +874,7 @@ function clear_post_cache($post_date, $post_tag, $post_url, $filename, $category
foreach (glob('cache/page/' . $b . 'search#*.cache', GLOB_NOSORT) as $file) { foreach (glob('cache/page/' . $b . 'search#*.cache', GLOB_NOSORT) as $file) {
unlink($file); unlink($file);
} }
// Delete category // Delete category
$cc = 'cache/page/' . $b . 'category#' . $category . '.cache'; $cc = 'cache/page/' . $b . 'category#' . $category . '.cache';
if (file_exists($cc)) { if (file_exists($cc)) {
@ -882,7 +883,7 @@ function clear_post_cache($post_date, $post_tag, $post_url, $filename, $category
foreach (glob('cache/page/' . $b . 'category#' . $category . '~*.cache', GLOB_NOSORT) as $file) { foreach (glob('cache/page/' . $b . 'category#' . $category . '~*.cache', GLOB_NOSORT) as $file) {
unlink($file); unlink($file);
} }
// Delete type // Delete type
$tp = 'cache/page/' . $b . 'type#' . $type . '.cache'; $tp = 'cache/page/' . $b . 'type#' . $type . '.cache';
if (file_exists($tp)) { if (file_exists($tp)) {


Loading…
Cancel
Save