From a4f65190b398ae8f1207709a5be747d561ba0689 Mon Sep 17 00:00:00 2001 From: danpros Date: Sun, 28 Feb 2021 23:27:26 +0700 Subject: [PATCH] Tag creation improvements Allow to use tag like C++ and double check for the same tag slug. --- system/admin/admin.php | 57 ++++++++++++++++++++++++++++++++ system/admin/views/add-content.html.php | 5 +++ system/admin/views/edit-content.html.php | 5 +++ 3 files changed, 67 insertions(+) diff --git a/system/admin/admin.php b/system/admin/admin.php index 42e58ef..8547a59 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -95,6 +95,34 @@ function add_content($title, $tag, $url, $content, $user, $description = null, $ $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); + + $post_t = explode(',', $post_tag); + $pret_t = explode(',', $post_tagmd); + $tags = tag_cloud(true); + $timestamp = date('YmdHis'); + + $combine = array_combine($pret_t, $post_t); + $inter = array_intersect_key($tags, array_flip($post_t)); + $newtag = array(); + + foreach ($combine as $tag => $v) { + if (array_key_exists($v, $tags)) { + foreach ($inter as $in => $i){ + if($v === $in) { + if (strtolower($tag) === strtolower(tag_i18n($in))) { + $newtag[$v]= $tag; + } else { + $newtag[$v.'-'. $timestamp]= $tag; + } + } + } + } else { + $newtag[$v] = $tag; + } + } + + $post_tag = implode(',', array_keys($newtag)); + if ($description !== null) { $post_description = "\n"; } else { @@ -166,6 +194,35 @@ function edit_content($title, $tag, $url, $content, $oldfile, $destination = nul $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); + + + $post_t = explode(',', $post_tag); + $pret_t = explode(',', $post_tagmd); + $tags = tag_cloud(true); + $timestamp = date('YmdHis'); + + $combine = array_combine($pret_t, $post_t); + $inter = array_intersect_key($tags, array_flip($post_t)); + $newtag = array(); + + foreach ($combine as $tag => $v) { + if (array_key_exists($v, $tags)) { + foreach ($inter as $in => $i){ + if($v === $in) { + if (strtolower($tag) === strtolower(tag_i18n($in))) { + $newtag[$v]= $tag; + } else { + $newtag[$v.'-'. $timestamp]= $tag; + } + } + } + } else { + $newtag[$v] = $tag; + } + } + + $post_tag = implode(',', array_keys($newtag)); + if ($description !== null) { $post_description = "\n"; } else { diff --git a/system/admin/views/add-content.html.php b/system/admin/views/add-content.html.php index 414733a..1f16980 100644 --- a/system/admin/views/add-content.html.php +++ b/system/admin/views/add-content.html.php @@ -10,6 +10,11 @@ if ($type != 'is_post' && $type != 'is_image' && $type != 'is_video' && $type != $desc = get_category_info(null); $tags = tag_cloud(true); +$ptags = unserialize(file_get_contents('content/data/tags.lang')); +$tkey = array_keys($tags); +$newlang = array_intersect_key($ptags, array_flip($tkey)); +$tmp = serialize($newlang); +file_put_contents('content/data/tags.lang', print_r($tmp, true)); ?> diff --git a/system/admin/views/edit-content.html.php b/system/admin/views/edit-content.html.php index 2f4b836..0d04794 100644 --- a/system/admin/views/edit-content.html.php +++ b/system/admin/views/edit-content.html.php @@ -55,6 +55,11 @@ if (config('permalink.type') == 'post') { } $tags = tag_cloud(true); +$ptags = unserialize(file_get_contents('content/data/tags.lang')); +$tkey = array_keys($tags); +$newlang = array_intersect_key($ptags, array_flip($tkey)); +$tmp = serialize($newlang); +file_put_contents('content/data/tags.lang', print_r($tmp, true)); ?>