From 90759d673c39579a2872a3023c5fc5b4c3f1d9f7 Mon Sep 17 00:00:00 2001 From: danpros Date: Sat, 6 Jan 2024 16:22:12 +0700 Subject: [PATCH] Allow multiple site.urls. See #549 If you upload an image on one of the sites, change the image address to relative path. --- config/config.ini.example | 3 +++ content/data/configList.json | 2 +- system/admin/views/config-performance.html.php | 22 ++++++++++++++++++ system/includes/dispatch.php | 31 +++++++++++++++++++++----- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/config/config.ini.example b/config/config.ini.example index f593661..93434c2 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -132,6 +132,9 @@ generation.time = "false" ; Switch on and off the cache timestamp. Options "false" and "true" cache.timestamp = "false" +; The site.url depends on where you are visiting from. Same installation +multi.site = "false" + ; Set the theme here views.root = "themes/twentyfifteen" diff --git a/content/data/configList.json b/content/data/configList.json index 95c379d..b3dc5c9 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","tagcloud.count","teaser.type","read.more","teaser.char","description.char","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","views.root","views.layout"] \ No newline at end of file +["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","tagcloud.count","teaser.type","read.more","teaser.char","description.char","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","multi.site","views.root","views.layout"] \ No newline at end of file diff --git a/system/admin/views/config-performance.html.php b/system/admin/views/config-performance.html.php index 2c235ca..3a45731 100644 --- a/system/admin/views/config-performance.html.php +++ b/system/admin/views/config-performance.html.php @@ -78,6 +78,28 @@
+

Multisite

+
+
+ +
+
+
+ checked> + +
+
+ checked> + +
+
+
+
+


diff --git a/system/includes/dispatch.php b/system/includes/dispatch.php index e2a474a..264c53e 100644 --- a/system/includes/dispatch.php +++ b/system/includes/dispatch.php @@ -14,11 +14,32 @@ function _log($message) function site_url() { - if (config('site.url') == null) - error(500, '[site.url] is not set'); + if (config('multi.site') == "true"){ + return rtrim(generateSiteUrl(), '/') . '/'; + } else { + if (config('site.url') == null) + error(500, '[site.url] is not set'); + // Forcing the forward slash + return rtrim(config('site.url'), '/') . '/'; + } +} - // Forcing the forward slash - return rtrim(config('site.url'), '/') . '/'; +function generateSiteUrl() +{ + $dir = trim(dirname(substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]))), '/'); + if ($dir == '.' || $dir == '..') { + $dir = ''; + } + $port = ''; + if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { + $port = ':' . $_SERVER["SERVER_PORT"]; + } + $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http'; + if ($dir === '') { + $siteUrl = $scheme . '://' . trim($_SERVER['SERVER_NAME'], "/") . $port . "/"; + return; + } + return $siteUrl = $scheme . '://' . trim($_SERVER['SERVER_NAME'], "/") . $port . "/" . $dir . '/'; } function site_path() @@ -29,7 +50,7 @@ function site_path() error(500, '[site.url] is not set'); if (!$_path) - $_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH), '/'); + $_path = rtrim(parse_url(site_url(), PHP_URL_PATH), '/'); return $_path; }