Skip to content

Commit

Permalink
fix subfolder based multisite
Browse files Browse the repository at this point in the history
  • Loading branch information
yllumi committed Jan 2, 2015
1 parent a98fdc9 commit dfb3f74
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dploy.yaml
dploy.yaml
sites/_domain/pusakadev.com.conf
2 changes: 1 addition & 1 deletion system/application/config/pusaka.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| live domain
|--------------------------------------------------------------------------
|
| Domain in live server to enable subsite mode.
| Domain in live server to enable subsite mode, example 'yoursite.com'.
| If it is set, your site domain will become http://yoursite.com/siteslug/
| and so your multisite.
| Default to false.
Expand Down
53 changes: 53 additions & 0 deletions system/application/core/MY_Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

require APPPATH."libraries/MX/Config.php";

class MY_Config extends MX_Config
{
/**
* Site URL
* Returns base_url . index_page [. uri_string]
*
* @param mixed the URI string or an array of segments
* @return string
*/
public function site_url($uri = '')
{
$site_slug = SITE_SLUG.'/';

include APPPATH.'config/pusaka.php';
$domain = $_SERVER['HTTP_HOST'];

if($domain != $config['localhost_domain'] && $domain != $config['subsite_domain'])
$site_slug = '';

if (empty($uri))
{
return $this->slash_item('base_url').$this->item('index_page').$site_slug;
}

$uri = $this->_uri_string($uri);

if ($this->item('enable_query_strings') === FALSE)
{
$suffix = ($this->item('url_suffix') === FALSE) ? '' : $this->item('url_suffix');

if ($suffix !== '' && ($offset = strpos($uri, '?')) !== FALSE)
{
$uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
}
else
{
$uri .= $suffix;
}

return $this->slash_item('base_url').$this->slash_item('index_page').$site_slug.$uri;
}
elseif (strpos($uri, '?') === FALSE)
{
$uri = '?'.$uri;
}

return $this->slash_item('base_url').$this->item('index_page').$site_slug.$uri;
}
}
26 changes: 25 additions & 1 deletion system/application/core/MY_URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ protected function _detect_uri()
return '';
}

include APPPATH.'config/pusaka.php';

$domain = $_SERVER['HTTP_HOST'];

// if it's localhost, then make uri begin from segment 2
if($_SERVER['HTTP_HOST'] == 'localhost'){
if($domain == $config['localhost_domain']){

if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
{
$uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'].'/'.SITE_SLUG));
Expand All @@ -33,6 +38,25 @@ protected function _detect_uri()
{
$uri = $_SERVER['REQUEST_URI'].'/'.SITE_SLUG;
}

}

// if subfolder base multisite chosen
elseif($domain == $config['subsite_domain']){

if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
{
$uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'].'/'.SITE_SLUG));
}
elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
$uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME']).'/'.SITE_SLUG));
}
else
{
$uri = $_SERVER['REQUEST_URI'].'/'.SITE_SLUG;
}

} else {
if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
{
Expand Down
9 changes: 6 additions & 3 deletions system/application/hooks/MyHookClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

function multisite()
{
include_once APPPATH.'config/pusaka.php';
include APPPATH.'config/pusaka.php';

$domain = $_SERVER['HTTP_HOST'];

// if it is a local server
if($domain == $config['localhost_domain'] || $domain == $config['subsite_domain']) {
$uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'].'/')));
if($domain == $config['localhost_domain'] || $domain == $config['subsite_domain']){
$uri = ($domain == $config['localhost_domain'])
? substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'].'/')))
: $uri = $_SERVER['REQUEST_URI'];

$segments = explode('/', $uri);

if(isset($segments[1]) && !empty($segments[1])) {
Expand Down
44 changes: 0 additions & 44 deletions system/application/libraries/MX/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,48 +68,4 @@ public function load($file = 'config', $use_sections = FALSE, $fail_gracefully =
return $this->item($file);
}
}

/**
* Site URL
* Returns base_url . index_page [. uri_string]
*
* @param mixed the URI string or an array of segments
* @return string
*/
public function site_url($uri = '')
{
$site_slug = SITE_SLUG.'/';

if($_SERVER['HTTP_HOST'] != 'localhost')
$site_slug = '';

if (empty($uri))
{
return $this->slash_item('base_url').$this->item('index_page').$site_slug;
}

$uri = $this->_uri_string($uri);

if ($this->item('enable_query_strings') === FALSE)
{
$suffix = ($this->item('url_suffix') === FALSE) ? '' : $this->item('url_suffix');

if ($suffix !== '' && ($offset = strpos($uri, '?')) !== FALSE)
{
$uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
}
else
{
$uri .= $suffix;
}

return $this->slash_item('base_url').$this->slash_item('index_page').$site_slug.$uri;
}
elseif (strpos($uri, '?') === FALSE)
{
$uri = '?'.$uri;
}

return $this->slash_item('base_url').$this->item('index_page').$site_slug.$uri;
}
}

0 comments on commit dfb3f74

Please sign in to comment.