eZ Publish  [trunk]
ezsiteaccess.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing (site)access functionality
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /**
00012  * Provides functions for siteaccess handling
00013  *
00014  * @package kernel
00015  */
00016 class eZSiteAccess
00017 {
00018     /**
00019      * Integer constants that identify the siteaccess matching used
00020      *
00021      * @since 4.4 Was earlier in access.php as normal constants
00022      */
00023     const TYPE_DEFAULT = 1;
00024     const TYPE_URI = 2;
00025     const TYPE_PORT = 3;
00026     const TYPE_HTTP_HOST = 4;
00027     const TYPE_INDEX_FILE = 5;
00028     const TYPE_STATIC = 6;
00029     const TYPE_SERVER_VAR = 7;
00030     const TYPE_URL = 8;
00031     const TYPE_HTTP_HOST_URI = 9;
00032 
00033     const SUBTYPE_PRE = 1;
00034     const SUBTYPE_POST = 2;
00035 
00036     /*!
00037      Constructor
00038     */
00039     function eZSiteAccess()
00040     {
00041     }
00042 
00043     static function siteAccessList()
00044     {
00045         $siteAccessList = array();
00046         $ini = eZINI::instance();
00047         $availableSiteAccessList = $ini->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' );
00048         if ( !is_array( $availableSiteAccessList ) )
00049             $availableSiteAccessList = array();
00050 
00051         $serverSiteAccess = eZSys::serverVariable( $ini->variable( 'SiteAccessSettings', 'ServerVariableName' ), true );
00052         if ( $serverSiteAccess )
00053             $availableSiteAccessList[] = $serverSiteAccess;
00054 
00055         $availableSiteAccessList = array_unique( $availableSiteAccessList );
00056         foreach ( $availableSiteAccessList as $siteAccessName )
00057         {
00058             $siteAccessItem = array();
00059             $siteAccessItem['name'] = $siteAccessName;
00060             $siteAccessItem['id'] = eZSys::ezcrc32( $siteAccessName );
00061             $siteAccessList[] = $siteAccessItem;
00062         }
00063         return $siteAccessList;
00064     }
00065 
00066     /**
00067      * Returns path to site access
00068      *
00069      * @param string $siteAccess
00070      * @return string|false Return path to siteacces or false if invalid
00071      */
00072     static function findPathToSiteAccess( $siteAccess )
00073     {
00074         $ini = eZINI::instance();
00075         $siteAccessList = $ini->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' );
00076         if ( !in_array( $siteAccess, $siteAccessList )  )
00077             return false;
00078 
00079         $currentPath = 'settings/siteaccess/' . $siteAccess;
00080         if ( file_exists( $currentPath ) )
00081             return $currentPath;
00082 
00083         $activeExtensions = eZExtension::activeExtensions();
00084         $baseDir = eZExtension::baseDirectory();
00085         foreach ( $activeExtensions as $extension )
00086         {
00087             $currentPath = $baseDir . '/' . $extension . '/settings/siteaccess/' . $siteAccess;
00088             if ( file_exists( $currentPath ) )
00089                 return $currentPath;
00090         }
00091 
00092         return 'settings/siteaccess/' . $siteAccess;
00093     }
00094 
00095     /**
00096      * Goes trough the access matching rules and returns the access match.
00097      * The returned match is an associative array with:
00098      *  name     => string Name of the siteaccess (same as folder name)
00099      *  type     => int The constant that represent the matching used
00100      *  uri_part => array(string) List of path elements that was used in start of url for the match
00101      *
00102      * @since 4.4
00103      * @param eZURI $uri
00104      * @param string $host
00105      * @param string(numeric) $port
00106      * @param string $file Example '/index.php'
00107      * @return array
00108      */
00109     public static function match( eZURI $uri, $host, $port = 80, $file = '/index.php' )
00110     {
00111         eZDebugSetting::writeDebug( 'kernel-siteaccess', array( 'uri' => $uri,
00112                                                                 'host' => $host,
00113                                                                 'port' => $port,
00114                                                                 'file' => $file ), __METHOD__ );
00115         $ini = eZINI::instance();
00116         if ( $ini->hasVariable( 'SiteAccessSettings', 'StaticMatch' ) )
00117         {
00118             $match = $ini->variable( 'SiteAccessSettings', 'StaticMatch' );
00119             if ( $match != '' )
00120             {
00121                 $access = array( 'name' => $match,
00122                                  'type' => eZSiteAccess::TYPE_STATIC,
00123                                  'uri_part' => array() );
00124                 return $access;
00125             }
00126         }
00127 
00128         list( $siteAccessList, $order ) =
00129             $ini->variableMulti( 'SiteAccessSettings', array( 'AvailableSiteAccessList', 'MatchOrder' ) );
00130         $access = array( 'name' => $ini->variable( 'SiteSettings', 'DefaultAccess' ),
00131                          'type' => eZSiteAccess::TYPE_DEFAULT,
00132                          'uri_part' => array() );
00133 
00134         if ( $order == 'none' )
00135             return $access;
00136 
00137         $order = $ini->variableArray( 'SiteAccessSettings', 'MatchOrder' );
00138 
00139         // Change the default type to eZSiteAccess::TYPE_URI if we're using URI MatchOrder.
00140         // This is to keep backward compatiblity with the ezurl operator. ezurl has since
00141         // rev 4949 added default siteaccess to generated URLs, even when there is
00142         // no siteaccess in the current URL.
00143         if ( in_array( 'uri', $order ) )
00144         {
00145             $access['type'] = eZSiteAccess::TYPE_URI;
00146         }
00147 
00148         foreach ( $order as $matchprobe )
00149         {
00150             $name = '';
00151             $type = '';
00152             $match_type = '';
00153             $uri_part = array();
00154 
00155             switch( $matchprobe )
00156             {
00157                 case 'servervar':
00158                 {
00159                     if ( $serversiteaccess = eZSys::serverVariable( $ini->variable( 'SiteAccessSettings', 'ServerVariableName' ), true ) )
00160                     {
00161                         $access['name'] = $serversiteaccess;
00162                         $access['type'] = eZSiteAccess::TYPE_SERVER_VAR;
00163                         return $access;
00164                     }
00165                     else
00166                         continue;
00167                 } break;
00168                 case 'port':
00169                 {
00170                     if ( $ini->hasVariable( 'PortAccessSettings', $port ) )
00171                     {
00172                         $access['name'] = $ini->variable( 'PortAccessSettings', $port );
00173                         $access['type'] = eZSiteAccess::TYPE_PORT;
00174                         return $access;
00175                     }
00176                     else
00177                         continue;
00178                 } break;
00179                 case 'uri':
00180                 {
00181                     $type = eZSiteAccess::TYPE_URI;
00182                     $match_type = $ini->variable( 'SiteAccessSettings', 'URIMatchType' );
00183 
00184                     if ( $match_type == 'map' )
00185                     {
00186                         if ( $ini->hasVariable( 'SiteAccessSettings', 'URIMatchMapItems' ) )
00187                         {
00188                             $match_item = $uri->element( 0 );
00189                             $matchMapItems = $ini->variableArray( 'SiteAccessSettings', 'URIMatchMapItems' );
00190                             foreach ( $matchMapItems as $matchMapItem )
00191                             {
00192                                 $matchMapURI = $matchMapItem[0];
00193                                 $matchMapAccess = $matchMapItem[1];
00194                                 if ( $access['name']  == $matchMapAccess and in_array( $matchMapAccess, $siteAccessList ) )
00195                                 {
00196                                     $uri_part = array( $matchMapURI );
00197                                 }
00198                                 if ( $matchMapURI == $match_item and in_array( $matchMapAccess, $siteAccessList ) )
00199                                 {
00200                                     $uri->increase( 1 );
00201                                     $uri->dropBase();
00202                                     $access['name'] = $matchMapAccess;
00203                                     $access['type'] = $type;
00204                                     $access['uri_part'] = array( $matchMapURI );
00205                                     return $access;
00206                                 }
00207                             }
00208                         }
00209                     }
00210                     else if ( $match_type == 'element' )
00211                     {
00212                         $match_index = $ini->variable( 'SiteAccessSettings', 'URIMatchElement' );
00213                         $elements = $uri->elements( false );
00214                         $elements = array_slice( $elements, 0, $match_index );
00215                         $name = implode( '_', $elements );
00216                         $uri_part = $elements;
00217                     }
00218                     else if ( $match_type == 'text' )
00219                     {
00220                         $match_item = $uri->elements();
00221                         $matcher_pre = $ini->variable( 'SiteAccessSettings', 'URIMatchSubtextPre' );
00222                         $matcher_post = $ini->variable( 'SiteAccessSettings', 'URIMatchSubtextPost' );
00223                     }
00224                     else if ( $match_type == 'regexp' )
00225                     {
00226                         $match_item = $uri->elements();
00227                         $matcher = $ini->variable( 'SiteAccessSettings', 'URIMatchRegexp' );
00228                         $match_num = $ini->variable( 'SiteAccessSettings', 'URIMatchRegexpItem' );
00229                     }
00230                     else
00231                         continue;
00232                 } break;
00233                 case 'host':
00234                 {
00235                     $type = eZSiteAccess::TYPE_HTTP_HOST;
00236                     $match_type = $ini->variable( 'SiteAccessSettings', 'HostMatchType' );
00237                     $match_item = $host;
00238                     if ( $match_type == 'map' )
00239                     {
00240                         if ( $ini->hasVariable( 'SiteAccessSettings', 'HostMatchMapItems' ) )
00241                         {
00242                             $matchMapItems = $ini->variableArray( 'SiteAccessSettings', 'HostMatchMapItems' );
00243                             foreach ( $matchMapItems as $matchMapItem )
00244                             {
00245                                 $matchMapHost = $matchMapItem[0];
00246                                 $matchMapAccess = $matchMapItem[1];
00247                                 if ( $matchMapHost == $host )
00248                                 {
00249                                     $access['name'] = $matchMapAccess;
00250                                     $access['type'] = $type;
00251                                     return $access;
00252                                 }
00253                             }
00254                         }
00255                     }
00256                     else if ( $match_type == 'element' )
00257                     {
00258                         $match_index = $ini->variable( 'SiteAccessSettings', 'HostMatchElement' );
00259                         $match_arr = explode( '.', $match_item );
00260                         $name = $match_arr[$match_index];
00261                     }
00262                     else if ( $match_type == 'text' )
00263                     {
00264                         $matcher_pre = $ini->variable( 'SiteAccessSettings', 'HostMatchSubtextPre' );
00265                         $matcher_post = $ini->variable( 'SiteAccessSettings', 'HostMatchSubtextPost' );
00266                     }
00267                     else if ( $match_type == 'regexp' )
00268                     {
00269                         $matcher = $ini->variable( 'SiteAccessSettings', 'HostMatchRegexp' );
00270                         $match_num = $ini->variable( 'SiteAccessSettings', 'HostMatchRegexpItem' );
00271                     }
00272                     else
00273                         continue;
00274                 } break;
00275                 case 'host_uri':
00276                 {
00277                     $type = eZSiteAccess::TYPE_HTTP_HOST_URI;
00278                     if ( $ini->hasVariable( 'SiteAccessSettings', 'HostUriMatchMapItems' ) )
00279                     {
00280                         $uriString = $uri->elements();
00281                         $matchMapItems = $ini->variableArray( 'SiteAccessSettings', 'HostUriMatchMapItems' );
00282                         $defaultHostMatchMethod = $ini->variable( 'SiteAccessSettings', 'HostUriMatchMethodDefault' );
00283 
00284                         foreach ( $matchMapItems as $matchMapItem )
00285                         {
00286                             $matchHost       = $matchMapItem[0];
00287                             $matchURI        = $matchMapItem[1];
00288                             $matchAccess     = $matchMapItem[2];
00289                             $matchHostMethod = isset( $matchMapItem[3] ) ? $matchMapItem[3] : $defaultHostMatchMethod;
00290 
00291                             if ( $matchURI !== '' && !preg_match( "@^$matchURI\b@", $uriString ) )
00292                                 continue;
00293 
00294                             switch( $matchHostMethod )
00295                             {
00296                                 case 'strict':
00297                                 {
00298                                     $hasHostMatch = ( $matchHost === $host );
00299                                 } break;
00300                                 case 'start':
00301                                 {
00302                                     $hasHostMatch = ( strpos($host, $matchHost) === 0 );
00303                                 } break;
00304                                 case 'end':
00305                                 {
00306                                     $hasHostMatch = ( strstr($host, $matchHost) === $matchHost );
00307                                 } break;
00308                                 case 'part':
00309                                 {
00310                                     $hasHostMatch = ( strpos($host, $matchHost) !== false );
00311                                 } break;
00312                                 default:
00313                                 {
00314                                     $hasHostMatch = false;
00315                                     eZDebug::writeError( "Unknown host_uri host match: $matchHostMethod", "access" );
00316                                 } break;
00317                             }
00318 
00319                             if ( $hasHostMatch )
00320                             {
00321                                 if ( $matchURI !== '' )
00322                                 {
00323                                     $matchURIFolders = explode( '/', $matchURI );
00324                                     $uri->increase( count( $matchURIFolders ) );
00325                                     $uri->dropBase();
00326                                     $access['uri_part'] = $matchURIFolders;
00327                                 }
00328                                 $access['name'] = $matchAccess;
00329                                 $access['type'] = $type;
00330                                 return $access;
00331                             }
00332                         }
00333                     }
00334                 } break;
00335                 case 'index':
00336                 {
00337                     $type = eZSiteAccess::TYPE_INDEX_FILE;
00338                     $match_type = $ini->variable( 'SiteAccessSettings', 'IndexMatchType' );
00339                     $match_item = $file;
00340                     if ( $match_type == 'element' )
00341                     {
00342                         $match_index = $ini->variable( 'SiteAccessSettings', 'IndexMatchElement' );
00343                         $match_pos = strpos( $match_item, '.php' );
00344                         if ( $match_pos !== false )
00345                         {
00346                             $match_item = substr( $match_item, 0, $match_pos );
00347                             $match_arr = explode( '_', $match_item );
00348                             $name = $match_arr[$match_index];
00349                         }
00350                     }
00351                     else if ( $match_type == 'text' )
00352                     {
00353                         $matcher_pre = $ini->variable( 'SiteAccessSettings', 'IndexMatchSubtextPre' );
00354                         $matcher_post = $ini->variable( 'SiteAccessSettings', 'IndexMatchSubtextPost' );
00355                     }
00356                     else if ( $match_type == 'regexp' )
00357                     {
00358                         $matcher = $ini->variable( 'SiteAccessSettings', 'IndexMatchRegexp' );
00359                         $match_num = $ini->variable( 'SiteAccessSettings', 'IndexMatchRegexpItem' );
00360                     }
00361                     else
00362                         continue;
00363                 } break;
00364                 default:
00365                 {
00366                     eZDebug::writeError( "Unknown access match: $matchprobe", "access" );
00367                 } break;
00368             }
00369 
00370             if ( $match_type == 'regexp' )
00371                 $name = self::matchRegexp( $match_item, $matcher, $match_num );
00372             else if ( $match_type == 'text' )
00373                 $name = self::matchText( $match_item, $matcher_pre, $matcher_post );
00374 
00375             if ( isset( $name ) && $name != '' )
00376             {
00377                 $name = preg_replace( array( '/[^a-zA-Z0-9]+/', '/_+/', '/^_/', '/_$/' ),
00378                                       array( '_', '_', '', '' ),
00379                                       $name );
00380 
00381                 if ( in_array( $name, $siteAccessList ) )
00382                 {
00383                     if ( $type == eZSiteAccess::TYPE_URI )
00384                     {
00385                         if ( $match_type == 'element' )
00386                         {
00387                             $uri->increase( $match_index );
00388                             $uri->dropBase();
00389                         }
00390                         else if ( $match_type == 'regexp' )
00391                         {
00392                             $uri->setURIString( $match_item );
00393                         }
00394                         else if ( $match_type == 'text' )
00395                         {
00396                             $uri->setURIString( $match_item );
00397                         }
00398                     }
00399                     $access['type']     = $type;
00400                     $access['name']     = $name;
00401                     $access['uri_part'] = $uri_part;
00402                     return $access;
00403                 }
00404             }
00405         }
00406         return $access;
00407     }
00408 
00409     /**
00410      * Match a regex expression
00411      *
00412      * @since 4.4
00413      * @param string $text
00414      * @param string $reg
00415      * @param int $num
00416      * @return string|null
00417      */
00418     static function matchRegexp( &$text, $reg, $num )
00419     {
00420         $reg = str_replace( '/', "\\/", $reg );
00421         if ( preg_match( "/$reg/", $text, $regs ) && $num < count( $regs ) )
00422         {
00423             $text = str_replace( $regs[$num], '', $text );
00424             return $regs[$num];
00425         }
00426         return null;
00427     }
00428 
00429     /**
00430      * Match a text string with pre or/or post text strings
00431      *
00432      * @since 4.4
00433      * @param string $text
00434      * @param string $match_pre
00435      * @param string $match_post
00436      * @return string|null
00437      */
00438     static function matchText( &$text, $match_pre, $match_post )
00439     {
00440         $ret = null;
00441         if ( $match_pre !== '' )
00442         {
00443             $pos = strpos( $text, $match_pre );
00444             if ( $pos === false )
00445                 return null;
00446 
00447             $ret = substr( $text, $pos + strlen( $match_pre ) );
00448             $text = substr( $text, 0, $pos );
00449         }
00450         if ( $match_post !== '' )
00451         {
00452             $pos = strpos( $ret, $match_post );
00453             if ( $pos === false )
00454                 return null;
00455 
00456             $text .= substr( $ret, $pos + 1 );
00457             $ret = substr( $ret, 0, $pos );
00458         }
00459         return $ret;
00460     }
00461 
00462     /**
00463      * Re-initialises the current site access
00464      * If a siteaccess is set, then executes {@link eZSiteAccess::load()}
00465      *
00466      * @return bool True if re-initialisation was successful
00467      */
00468     static function reInitialise()
00469     {
00470         if ( isset( $GLOBALS['eZCurrentAccess'] ) )
00471         {
00472             self::load( $GLOBALS['eZCurrentAccess'] );
00473             return true;
00474         }
00475         else
00476         {
00477             return false;
00478         }
00479     }
00480 
00481     /**
00482      * Changes the site access to what's defined in $access. It will change the
00483      * access path in eZSys and prepend an override dir to eZINI
00484      * Note: does not load extensions, use {@link eZSiteAccess::load()} if you want that
00485      *
00486      * @since 4.4
00487      * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array).
00488      *                      See {@link eZSiteAccess::match()} for array structure definition
00489      * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini
00490      *                   hence skip changing eZSys access paths (but not siteaccess, see {@link eZSiteAccess::load()})
00491      * @return array The $access parameter
00492      */
00493     static function change( array $access, eZINI $siteINI = null )
00494     {
00495         $name = $access['name'];
00496         $GLOBALS['eZCurrentAccess'] =& $access;
00497         if ( $siteINI !== null )
00498         {
00499             $ini = $siteINI;
00500         }
00501         else
00502         {
00503             $ini = eZINI::instance();
00504         }
00505 
00506         $ini->prependOverrideDir( "siteaccess/$name", false, 'siteaccess', 'siteaccess' );
00507 
00508         /* Make sure extension siteaccesses are prepended */
00509         eZExtension::prependExtensionSiteAccesses( $name, $ini );
00510 
00511         $ini->loadCache();
00512 
00513         // change some global settings if $siteINI is null
00514         if ( $siteINI === null )
00515         {
00516             eZSys::clearAccessPath();
00517             if ( !isset( $access['uri_part'] ) || $access['uri_part'] === null )
00518             {
00519                 if ( $ini->hasVariable('SiteSettings', 'SiteUriParts') )
00520                     $access['uri_part'] = $ini->variable('SiteSettings', 'SiteUriParts');
00521                 else if ( isset( $access['type'] ) && $access['type'] === eZSiteAccess::TYPE_URI )
00522                     $access['uri_part'] = array( $access['name'] );
00523                 else
00524                     $access['uri_part'] = array();
00525             }
00526             eZSys::setAccessPath( $access['uri_part'], $name );
00527 
00528             eZUpdateDebugSettings();
00529             eZDebugSetting::writeDebug( 'kernel-siteaccess', "Updated settings to use siteaccess '$name'", __METHOD__ );
00530         }
00531 
00532         return $access;
00533     }
00534 
00535     /**
00536      * Reloads extensions and changes siteaccess globally
00537      * If you only want changes on a instance of ini, use {@link eZSiteAccess::getIni()}
00538      *
00539      * - clears all in-memory caches used by the INI system
00540      * - re-builds the list of paths where INI files are searched for
00541      * - runs {@link eZSiteAccess::change()}
00542      * - re-searches module paths {@link eZModule::setGlobalPathList()}
00543      *
00544      * @since 4.4
00545      * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array).
00546      *                      See {@link eZSiteAccess::match()} for array structure definition
00547      * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini
00548      *                            If set, then global siteacceess will not be changed as well.
00549      * @return array The $access parameter
00550      */
00551     static function load( array $access, eZINI $siteINI = null )
00552     {
00553         $currentSiteAccess = $GLOBALS['eZCurrentAccess'];
00554         unset( $GLOBALS['eZCurrentAccess'] );
00555 
00556         // Clear all ini override dirs
00557         if ( $siteINI instanceof eZINI )
00558         {
00559             $siteINI->resetOverrideDirs();
00560         }
00561         else
00562         {
00563             eZINI::resetAllInstances();
00564             eZExtension::clearActiveExtensionsMemoryCache();
00565             eZTemplateDesignResource::clearInMemoryCache();
00566         }
00567 
00568         // Reload extensions, siteaccess and access extensions
00569         eZExtension::activateExtensions( 'default', $siteINI );
00570         $access = self::change( $access, $siteINI );
00571         eZExtension::activateExtensions( 'access', $siteINI );
00572 
00573         // Restore current (old) siteacces if changes where only to be applied to locale instance of site.ini
00574         if ( $siteINI instanceof eZINI )
00575         {
00576             $GLOBALS['eZCurrentAccess'] = $currentSiteAccess;
00577         }
00578         else
00579         {
00580             $moduleRepositories = eZModule::activeModuleRepositories();
00581             eZModule::setGlobalPathList( $moduleRepositories );
00582         }
00583 
00584         return $access;
00585     }
00586 
00587     /**
00588      * Loads ini environment for a specific siteaccess
00589      *
00590      * eg: $ini = eZSiteAccess::getIni( 'eng', 'site.ini' );
00591      *
00592      * @since 4.4
00593      * @param string $siteAccess
00594      * @param string $settingFile
00595      * @return eZINI
00596      */
00597     static function getIni( $siteAccess, $settingFile = 'site.ini' )
00598     {
00599         // return global if siteaccess is same as requested or false
00600         if ( isset( $GLOBALS['eZCurrentAccess']['name'] )
00601           && $GLOBALS['eZCurrentAccess']['name'] === $siteAccess )
00602         {
00603             return eZINI::instance( $settingFile );
00604         }
00605         else if ( !$siteAccess )
00606         {
00607             return eZINI::instance( $settingFile );
00608         }
00609 
00610         // create a site ini instance using $useLocalOverrides = true
00611         $siteIni = new eZINI( 'site.ini', 'settings', null, null, true );
00612 
00613         // create a dummy access definition (not used as long as $siteIni is sent to self::load() )
00614         $access = array( 'name' => $siteAccess,
00615                          'type' => eZSiteAccess::TYPE_STATIC,
00616                          'uri_part' => array() );
00617 
00618         // Load siteaccess but on our locale instance of site.ini only
00619         $access = self::load( $access, $siteIni );
00620 
00621         // if site.ini, return with no further work needed
00622         if ( $settingFile === 'site.ini' )
00623         {
00624             return $siteIni;
00625         }
00626 
00627         // load settings file with $useLocalOverrides = true
00628         $ini = new eZINI( $settingFile,'settings', null, null, true );
00629         $ini->setOverrideDirs( $siteIni->overrideDirs( false ) );
00630         $ini->load();
00631 
00632         return $ini;
00633     }
00634 
00635     /**
00636      * Get current siteaccess data if set, see {@link eZSiteAccess::match()} for array structure
00637      *
00638      * @since 4.4
00639      * return array|null
00640      */
00641     static function current()
00642     {
00643         if ( isset( $GLOBALS['eZCurrentAccess']['name'] ) )
00644             return $GLOBALS['eZCurrentAccess'];
00645         return null;
00646     }
00647 
00648     /**
00649      * Gets siteaccess name by language based on site.ini\[RegionalSettings]\LanguageSA[]
00650      * if defined otherwise by convention ( eng-GB -> eng ), in both cases sa needs to
00651      * be in site.ini\[SiteAccessSettings]\RelatedSiteAccessList[] as well to be valid.
00652      *
00653      * @since 4.5
00654      * @param string $language eg: eng-GB
00655      * @return string|null
00656      */
00657     public static function saNameByLanguage( $language )
00658     {
00659         $ini = eZINI::instance();
00660         if ( $ini->hasVariable( 'RegionalSettings', 'LanguageSA' ) )
00661         {
00662             $langMap = $ini->variable( 'RegionalSettings', 'LanguageSA' );
00663             if ( !isset( $langMap[$language] ) )
00664             {
00665                 return null;
00666             }
00667             $sa = $langMap[$language];
00668         }
00669         else
00670         {
00671             $sa = explode( '-', $language );
00672             $sa = $sa[0];
00673         }
00674 
00675         if ( in_array( $sa, $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' ) ) )
00676         {
00677             return $sa;
00678         }
00679         eZDebug::writeWarning("Tried to find siteaccess based on '$language' but '$sa' is not a valid RelatedSiteAccessList[]", __METHOD__ );
00680         return null;
00681     }
00682 
00683     /**
00684      * Checks if site access debug is enabled
00685      *
00686      * @since 4.4
00687      * @deprecated Should use debug.ini conditions instead of extra settings
00688      * @return bool
00689      */
00690     static function debugEnabled()
00691     {
00692         $ini = eZINI::instance();
00693         return $ini->variable( 'SiteAccessSettings', 'DebugAccess' ) === 'enabled';
00694     }
00695 
00696     /**
00697      * Checks if extra site access debug is enabled
00698      *
00699      * @since 4.4
00700      * @deprecated Should use debug.ini conditions instead of extra settings
00701      * @return bool
00702      */
00703     static function extraDebugEnabled()
00704     {
00705         $ini = eZINI::instance();
00706         return $ini->variable( 'SiteAccessSettings', 'DebugExtraAccess' ) === 'enabled';
00707     }
00708 }
00709 
00710 ?>