[ Index ]

PHP Cross Reference of PivotX trunk SVN

title

Body

[close]

/pivotx/modules/ -> module_multisite.php (source)

   1  <?php
   2  
   3  /**
   4   * Contains the functions we use to support multi-site PivotX installs.
   5   *
   6   * @package pivotx
   7   * @subpackage modules
   8   */
   9  
  10  
  11  // ---------------------------------------------------------------------------
  12  //
  13  // PIVOTX - LICENSE:
  14  //
  15  // This file is part of PivotX. PivotX and all its parts are licensed under
  16  // the GPL version 2. see: http://docs.pivotx.net/doku.php?id=help_about_gpl
  17  // for more information.
  18  //
  19  // $Id: module_multisite.php 2006 2009-06-12 09:24:59Z hansfn $
  20  //
  21  // ---------------------------------------------------------------------------
  22  
  23  
  24  /**
  25   * The class that contains the multi-sites functions.
  26   *
  27   */
  28  class MultiSite {
  29  
  30      var $active;
  31      var $path;
  32  
  33      /**
  34       * Initializes the class.
  35       */
  36      function MultiSite() {
  37          global $PIVOTX, $pivotx_path;
  38  
  39          $sites_path = $pivotx_path . 'sites/';
  40  
  41          if (file_exists($sites_path)) {
  42              /* Based on similar code in Drupal (see conf_path function in includes/bootstrap.inc). */
  43              if (function_exists('getPivotxURL')) {
  44                  $uri = explode('/',getPivotxURL());
  45                  $dummy = array_pop($uri);
  46              } else {
  47                  // The function isn't defined when PivotX isn't loaded (i.e, viewing the debug log).
  48                  if (!empty($_SERVER['PATH_INFO'])) {
  49                      $uri = $_SERVER['PATH_INFO'];
  50                  } else if (!empty($_SERVER['PHP_SELF'])) {
  51                      $uri = $_SERVER['PHP_SELF'];
  52                  } else {
  53                      $uri = $_SERVER['SCRIPT_NAME'];
  54                  }
  55                  $uri = dirname($uri);
  56                  $uri = explode('/', $uri);
  57              }
  58              $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
  59              for ($i = count($uri) - 1; $i > 0; $i--) {
  60                  for ($j = count($server); $j > 0; $j--) {
  61                      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
  62                      if (file_exists($sites_path . $dir)) {
  63                          $this->path = 'sites/' . $dir . '/';
  64                          $this->active = true;
  65                          return;
  66                      }
  67                  }
  68              }
  69          }
  70  
  71          $this->active = false;
  72  
  73          return;
  74      }
  75  
  76      /**
  77       * Returns whether Multi-Site is active.
  78       * 
  79       * @return boolean
  80       */
  81      function isActive() {
  82          return $this->active;
  83      }
  84  
  85      /**
  86       * Returns the relative directory path for this site.
  87       *
  88       * @return string
  89       */
  90      function getPath() {
  91          if ($this->active) {
  92              return $this->path;
  93          } else {
  94              return '';
  95          }
  96      }
  97  
  98  }
  99  
 100  ?>


Generated: Mon May 21 01:08:32 2012 Cross-referenced by PHPXref 0.6