Are there any reasons why it is not possible to use php's include_path configuration-option so drupal's code can be re-used for several sites (multisite possibility).

Is it only because people are to lazy or to busy to rewrite drupal so it will become possible? Or has it something to do with security reasons or so? When it's the first i'll be prepared to do it (as a matter of fact, I already did some rewriting and testing).

Comments

drubeedoo’s picture

Multi-site is already integral to Drupal... and calling people lazy, even in jest, won't get you very far. :(

Try using PHP ini_set() in your code if you must fiddle with include_path or other PHP settings, though this might be blocked by your host.

casey’s picture

I am not calling people lazy! It was a question which I ment rhetorically. Sorry if it did seem to be ment elseway.

My point is that you can't use include_path with drupal, because functions (like file_exists) are used which make this impossible. I wondered if it isn't a idea to rewrite this. I think the possibility to use include_path for multisite purposes is very useful.

casey’s picture

I think it isn't very hard to make the include_path setting usefull.

- remove all './' prefixes from includes (seems not to work with include_path).
- replace file_exists function with one which bears include_path in mind. Like something like this:

function is_includeable($filename, $returnpaths = false) {
   $include_paths = explode(PATH_SEPARATOR, ini_get('include_path'));

   foreach ($include_paths as $path) {
       $include = $path.DIRECTORY_SEPARATOR.$filename;
       if (is_file($include) && is_readable($include)) {
           if ($returnpaths == true) {
               $includable_paths[] = $path;
           } else {
               return true;
           }
       }
   }

   return (isset($includeable_paths) && $returnpaths == true) ? $includeable_paths : false;
}
drubeedoo’s picture

Thanks for the clarification. I haven't thought of that. This may not be close to what you're thinking, but I was going to write a quick module to parse all references to "/sites/www.example.com/files/" in HTML output and replace it with a rewrite rule of "/files/" so multi-site installations look and feel just like single sites and can easily be moved between the two. I've got the .htaccess mod_rewrite working already.

Now even if the files folder doesn't exist in Drupal root, multi-site content files can be accessed via:

http://www.example.com/files/picture.jpg

rather than using the cryptic and ugly:

http://www.example.com/sites/www.example.com/files/picture.jpg

All I need now is for Drupal to write out the "shorter" path, rather than the full (ugly) path.

Moving sites around from Localhost to Single Site, or Single Site to Multi-Site, or Public to Private is an ugly mess right now with paths stored in the db (where they don't belong). Having some way to edit a path without affecting all files referenced in the db would be fantastic.

I'm not sure if using include_path is generic enough that shared hosts across the board will allow us to use it for this intent. (I don't know enough about general Apache/PHP security setup to comment.)

casey’s picture

If there are no security issues involved I think it should be implemented. It brings some very usefull possibilities for advanced users.

<<

/path/to/drupal

/path/to/some_site_which_uses_drupal/

  • .htaccess (pretty same as drupal's except replacement of "index.php" for "drupal.php")
  • drupal.php:
    <?php
    ini_set('include_path', '.:/path/to/drupal');
    
    // simply include drupal's index.php
    include 'index.php';
    // or a rewrite of index.php with additional functionallty
    ?>
    
  • every file in /path/to/drupal can be replaced

Example;

...

I'm not sure if using include_path is generic enough that shared hosts across the board will allow us to use it for this intent.
(I don't know enough about general Apache/PHP security setup to comment.)

...

Me not very much either. Things I do know:

  • include_path is disabled with safe_mode
  • include_path is not working outside configured openbase_dir

Maybe others do know some more about it and give some input. I think that when there are no security issues involved and it isn't interfere with other functionallity it should be implemented.

...hoping for some nice constructive discussions...

//edit

Oww, another thing is that you don't need symbolic links in your drupal/sites directory: just replace the sites directory in /path/to/some_site_which_uses_drupal/. (for people who wants to use symbolic links: no problem, nothing will change for them).