From cfd114b7d360c563932f0f15b23d825583372d7a Mon Sep 17 00:00:00 2001 From: Yaya Laressa Date: Thu, 8 Jul 2021 02:44:21 +0700 Subject: [PATCH] add menu config custom robots.txt --- config/config.ini.example | 3 ++ content/data/configList.json | 2 +- system/admin/views/config-metatags.html.php | 59 ++++++++++++++++++++++++++++- system/htmly.php | 3 ++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/config/config.ini.example b/config/config.ini.example index eae1ae8..ff039cb 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -96,6 +96,9 @@ description.char = "150" ; Post date display as, set "true" display as social media or set "false" as default timeago.format = "false" +; Custom robots.txt configuration +custom.robots = "false" + ; RSS feed count rss.count = "10" diff --git a/content/data/configList.json b/content/data/configList.json index a45e538..ffa3e76 100644 --- a/content/data/configList.json +++ b/content/data/configList.json @@ -1 +1 @@ -["site.url","timezone","date.format","language","blog.title","blog.tagline","blog.description","blog.copyright","permalink.type","static.frontpage","blog.enable","social.twitter","social.facebook","breadcrumb.home","comment.system","fb.appid","fb.num","fb.color","disqus.shortname","google.wmt.id","google.analytics.id","google.gtag.id","google.reCaptcha","google.reCaptcha.public","google.reCaptcha.private","posts.perpage","category.perpage","tag.perpage","archive.perpage","search.perpage","profile.perpage","type.perpage","json.count","category.info","related.count","recent.count","popular.count","teaser.type","read.more","teaser.char","description.char","timeago.format","rss.count","rss.char","views.counter","sitemap.priority.base","sitemap.priority.post","sitemap.priority.static","sitemap.priority.category","sitemap.priority.tag","sitemap.priority.archiveDay","sitemap.priority.archiveMonth","sitemap.priority.archiveYear","sitemap.priority.author","sitemap.priority.type","prerelease","cache.expiration","cache.off","generation.time","cache.timestamp","cache.minify","views.root","views.layout"] +["site.url", "timezone", "date.format", "language", "blog.title", "blog.tagline", "blog.description", "blog.copyright", "permalink.type", "static.frontpage", "blog.enable", "social.twitter", "social.facebook", "breadcrumb.home", "comment.system", "fb.appid", "fb.num", "fb.color", "disqus.shortname", "google.wmt.id", "google.analytics.id", "google.gtag.id", "google.reCaptcha", "google.reCaptcha.public", "google.reCaptcha.private", "posts.perpage", "category.perpage", "tag.perpage", "archive.perpage", "search.perpage", "profile.perpage", "type.perpage", "json.count", "category.info", "related.count", "recent.count", "popular.count", "teaser.type", "read.more", "teaser.char", "description.char", "timeago.format", "custom.robots", "rss.count", "rss.char", "views.counter", "sitemap.priority.base", "sitemap.priority.post", "sitemap.priority.static", "sitemap.priority.category", "sitemap.priority.tag", "sitemap.priority.archiveDay", "sitemap.priority.archiveMonth", "sitemap.priority.archiveYear", "sitemap.priority.author", "sitemap.priority.type", "prerelease", "cache.expiration", "cache.off", "generation.time", "cache.timestamp", "cache.minify", "views.root", "views.layout"] \ No newline at end of file diff --git a/system/admin/views/config-metatags.html.php b/system/admin/views/config-metatags.html.php index efbf41b..8a5d545a 100644 --- a/system/admin/views/config-metatags.html.php +++ b/system/admin/views/config-metatags.html.php @@ -5,6 +5,37 @@ $array = array(); if (file_exists($config_file)) { $array = parse_ini_file($config_file, true); } + +// robots.txt config +$backup_robots = 'content/data/robots.backup'; +$custom_robots = 'content/data/robots.custom'; + +if(!file_exists($backup_robots)) { + // backup robots.txt dulu jika belum ada backupan + $robots = file_get_contents('robots.txt'); + file_put_contents($backup_robots, $robots); +} + +if(!file_exists($custom_robots)) { + // buat custom robots.txt dulu jika belum ada + file_put_contents($custom_robots, ''); +} + +if(config('custom.robots') === 'true') +{ + unlink('robots.txt'); + // create robots.txt custom + $robots = file_get_contents($custom_robots); + file_put_contents('robots.txt', $robots); +} + +if(config('custom.robots') === 'false') +{ + unlink('robots.txt'); + $robots = file_get_contents($backup_robots); + file_put_contents('robots.txt', $robots); +} + ?>


@@ -38,7 +69,7 @@ if (file_exists($config_file)) { - +
@@ -52,6 +83,32 @@ if (file_exists($config_file)) {
+
+ +
+
+
+ checked> + +
+
+ checked> + +
+
+
+
+
+ +
+ + https://developers.google.com/search/docs/advanced/robots/create-robots-txt +
+


diff --git a/system/htmly.php b/system/htmly.php index 03b531d..7f8069b 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1710,6 +1710,8 @@ post('/admin/config/metatags', function () { ini_set("display_errors", 1); $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + $robots = from($_REQUEST, 'robots'); + if (login() && $proper) { $new_config = array(); $new_Keys = array(); @@ -1725,6 +1727,7 @@ post('/admin/config/metatags', function () { } } save_config($new_config, $new_Keys); + file_put_contents('content/data/robots.custom', $robots); $login = site_url() . 'admin/config/metatags'; header("location: $login"); } else {