From 196d8be4dccdcffc083bdb2406b185b576446b99 Mon Sep 17 00:00:00 2001 From: Adam Franco Date: Thu, 11 Oct 2012 10:19:16 -0400 Subject: [PATCH] Allow setting the ACTIVE_SITE via the environment. This patch allows Kurogo to serve multiple sites from the same code directory where the active-site selection is configured by something beyond the limited subpath structure of MultiSite mode. One example enabled by this patch is to serve different Kurogo sites for each VirtualHost on the machine: ServerName students.example.edu DocumentRoot /var/www/kurogo/www/ SetEnv ACTIVE_SITE Students ServerName faculty.example.edu DocumentRoot /var/www/kurogo/www/ SetEnv ACTIVE_SITE Faculty This patch does not interfere with normal single-site operation or with MultiSite mode. See the additions to doc/mw/multisite.rst in this patch for more detailed configuration instructions. --- doc/mw/multisite.rst | 39 +++++++++++++++++++++++++++++++++++++++ lib/Kurogo.php | 15 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/doc/mw/multisite.rst b/doc/mw/multisite.rst index b85afa746..2e0c26a66 100644 --- a/doc/mw/multisite.rst +++ b/doc/mw/multisite.rst @@ -36,3 +36,42 @@ To setup Multisite, you must first enable it in the config/kurogo.ini file. ACTIVE_SITES[] = "es" This would enable only the *en* and *es* sites on this server. + +============================================ +Setting the active-site from the environment +============================================ + +There are some cases where there is a need to host multiple Kurogo sites from the same +webserver, but where one cannot use MultiSite mode due to its dependency on subpaths. +An example is serving each Kurogo site under a different host-name or domain name, +e.g. students.example.edu and faculty.example.edu. + +To accomplish this switching, Kurogo supports the specification of the ``ACTIVE_SITE`` +parameter via an environmental variable set by your webserver. Kurogo will only look for the ``ACTIVE_SITE`` in the environment when *not* in MultiSite mode and when the ``ACTIVE_SITE`` parameter has no value. + +Example ``kurogo.ini``: + +.. code-block:: ini + + [kurogo] + MULTI_SITE = 0 + ACTIVE_SITE = "" + +The ``ACTIVE_SITE`` environmental parameter can be set in a number of ways, but one of +the easiest is in your Apache configuration: + +:: + + + ServerName students.example.edu + DocumentRoot /var/www/kurogo/www/ + + SetEnv ACTIVE_SITE Students + + + + ServerName faculty.example.edu + DocumentRoot /var/www/kurogo/www/ + + SetEnv ACTIVE_SITE Faculty + \ No newline at end of file diff --git a/lib/Kurogo.php b/lib/Kurogo.php index 432d2de61..ddbd25f72 100644 --- a/lib/Kurogo.php +++ b/lib/Kurogo.php @@ -734,6 +734,21 @@ private function initSite(&$path) { define('SITE_NAME', $site); } else { + // If there is no active site configured and there is one set in the environment + // (such as set by a VirtualHost SetEnv entry), then set the active site to the one + // defined in the environment. + try { + $activeSite = $siteConfig->getVar('ACTIVE_SITE', 'kurogo'); + if (empty($activeSite)) { + throw new KurogoKeyNotFoundException('ACTIVE_SITE is empty'); + } + } catch (KurogoKeyNotFoundException $e) { + $activeSite = getenv('ACTIVE_SITE'); + if (!empty($activeSite)) { + $siteConfig->setVar('kurogo', 'ACTIVE_SITE', $activeSite, $changed); + } + } + $site = ''; if (PHP_SAPI == 'cli') {