Initially reported by: @chrisjdavis as #TRAC61
''Moved from GCode Issue
Reported by chrisdmitri, Oct 16, 2007
What steps will reproduce the problem?
- create a sub site that is NOT a sub-domain
- run the installer
- witness the brokeness. Specifically the links and refs all point to the root site, not the subsite. Additionally post data is not displayed.
What is the expected output? What do you see instead?
To have a working sub-site
Comment 1 by smerrill, Oct 16, 2007
Site::get_url() mistakenly uses the parent directory for the URL, rather than the
(non-existant) sub-directory. I expect that Site::get_path() suffers similarly.
There exists in the Site class a property to define the install type (local, sub-dir,
and sub-domain). The Site class needs to be updated to determine the install type
and generate URLs and paths appropriately for each kind.
Comment 2 by chrisdmitri, Oct 16, 2007
Could/should that constant be moved to the config.php of each sub-site? We are already requiring the rolling of
configs by hand, I don't think that adding this to the config would be that big of a deal.
Comment 3 by smerrill, Oct 17, 2007
I'd prefer that config.php not have any notion of what kind of install it is. For
example, if you decide to take your sub-site database to a new host as a fresh
non-multi installation, I don't think you should have to change anything in
config.php (save maybe the database credentials) in order to keep Habari working.
Put another way, Habari should be smart enough to figure out what kind of
installation it is on its own.
Similarly, Habari should be able to determine the path(s) and URL(s) necessary for
running a sub-site in a sub-directory. That means that we'll need to unspool the
directory name in /user/sites/ in some way.
Comment 4 by smerrill, Oct 17, 2007
I added this to Site::get_url() :
case 'habari':
$url= Site::get_url( 'host' );
$path= trim( dirname( $_SERVER['SCRIPT_NAME'] ), '/\\' );
if ( self::$config_type == Site::CONFIG_SUBDIR ) {
$config_dir= basename( Site::get_dir('config'));
$host= substr( Site::get_url('host'), strpos(Site::get_url('host'), '//') + 2 );
$tmp= str_replace( $host, '', $config_dir);
$tmp= str_replace( '.', '/', $tmp);
$url.= $tmp;
}
elseif ( '' != $path ) {
$url.= '/' . $path;
}
break;
That works for generating the correct link for get_url('habari') for sub-sites in
sub-directories. Unfortunately, it does not properly account for user and theme
directories, which do not necessarily live in /user/sites/x.y.z/. The code above
also doesn't properly handle sites on non-standard ports.
Hopefully the above will be a useful starting point for someone looking to fix this
problem more completely.
Comment 5 by epithet, Oct 27, 2007
Trying to make the subdirectory sites work has led me on a strange journey through
the interdependent wonderland that is the Site class, ending at the conclusion that
the class needs more general work than just fixing this one issue.
We should consider how we might centralize the way values are constructed for return
by the Site class, and then build functions that return those values. I think this
will yield more readable code than trying to build the output from within each
function. We could call an ::init() somewhere at the beginning, so that there would
be no question about dependencies. And in the case where a directory changes
depending on whether it's present at the root or a sub-site, the process that does
this could be clear and centralized.
In any case, this "small" thing,even if we don't rework this class, is much bigger
than we should wait for 0.3. Pushing to 0.4.