Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1173857
site_helper.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Oct 1, 4:57 PM
Size
4 KB
Mime Type
text/x-php
Expires
Fri, Oct 3, 4:57 PM (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
760963
Attached To
rINP In-Portal
site_helper.php
View Options
<?php
/**
* @version $Id: site_helper.php 16328 2016-01-23 19:58:28Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2010 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
SiteHelper
extends
kHelper
{
/**
* Returns default country
*
* @param string $country_prefix
* @param bool $iso_format
* @return int
*/
function
getDefaultCountry
(
$country_prefix
=
''
,
$iso_format
=
true
)
{
$country
=
$this
->
Application
->
siteDomainField
(
$country_prefix
.
'Country'
);
if
(
$iso_format
&&
!
$country
)
{
$country
=
'USA'
;
}
if
(!
$iso_format
&&
strlen
(
$country
))
{
return
$this
->
getCountryId
(
$country
);
}
return
$country
;
}
/**
* Returns country id based on it's ISO code
*
* @param string $iso_code
* @return int
*/
function
getCountryId
(
$iso_code
)
{
static
$cache
=
null
;
if
(!
isset
(
$cache
))
{
$sql
=
'SELECT CountryStateId, IsoCode
FROM '
.
$this
->
Application
->
getUnitConfig
(
'country-state'
)->
getTableName
()
.
'
WHERE Type = '
.
DESTINATION_TYPE_COUNTRY
;
$cache
=
$this
->
Conn
->
GetCol
(
$sql
,
'IsoCode'
);
}
return
$cache
[
$iso_code
];
}
/**
* Gets site domains from cache
*
* @return Array
*/
function
getSiteDomains
()
{
static
$cache
=
null
;
if
(
!
isset
(
$cache
)
)
{
if
(
$this
->
Application
->
isCachingType
(
CACHING_TYPE_MEMORY
)
)
{
$cache
=
$this
->
Application
->
getCache
(
'master:domains_parsed'
,
false
,
CacheSettings
::
$domainsParsedRebuildTime
);
}
else
{
$cache
=
$this
->
Application
->
getDBCache
(
'domains_parsed'
,
CacheSettings
::
$domainsParsedRebuildTime
);
}
if
(
$cache
)
{
$cache
=
unserialize
(
$cache
);
}
else
{
$sql
=
'SELECT *
FROM '
.
TABLE_PREFIX
.
'SiteDomains
WHERE Status = '
.
STATUS_ACTIVE
.
'
ORDER BY Priority DESC'
;
$cache
=
$this
->
Conn
->
Query
(
$sql
,
'DomainId'
);
if
(
$this
->
Application
->
isCachingType
(
CACHING_TYPE_MEMORY
))
{
$this
->
Application
->
setCache
(
'master:domains_parsed'
,
serialize
(
$cache
));
}
else
{
$this
->
Application
->
setDBCache
(
'domains_parsed'
,
serialize
(
$cache
));
}
}
}
return
$cache
;
}
/**
* Try to match visited domain to any of existing
*
* @param string $field
* @param string $value
* @return int
*/
function
getDomainByName
(
$field
,
$value
)
{
$site_domains
=
$this
->
getSiteDomains
();
$name_fields
=
Array
(
'DomainName'
,
'SSLDomainName'
);
foreach
(
$site_domains
as
$id
=>
$site_domain
)
{
if
(
in_array
(
$field
,
$name_fields
)
)
{
if
(
!
$site_domain
[
$field
.
'UsesRegExp'
]
)
{
// not regular expression -> escape manually
$site_domain
[
$field
]
=
preg_quote
(
$site_domain
[
$field
],
'/'
);
}
if
(
$site_domain
[
$field
]
&&
preg_match
(
'/^'
.
$site_domain
[
$field
]
.
'$/'
,
$value
)
)
{
return
$id
;
}
}
elseif
(
$site_domain
[
$field
]
==
$value
)
{
return
$id
;
}
}
return
false
;
}
/**
* Try to match domain settings based on visitor's IP address
*
* @return int
*/
function
getDomainByIP
()
{
$site_domains
=
$this
->
getSiteDomains
();
foreach
(
$site_domains
as
$id
=>
$site_domain
)
{
if
(
kUtil
::
ipMatch
(
$site_domain
[
'DomainIPRange'
],
"
\n
"
))
{
return
$id
;
}
}
return
false
;
}
/**
* Compares 2 domains.
*
* @param string $match_domain Domain to compare with.
* @param string $domain_field Site domain field to search within.
* @param string $primary_domain Primary domain to use in case if no site domain matches.
*
* @return boolean
*/
public
function
compare
(
$match_domain
,
$domain_field
,
$primary_domain
)
{
$domain_id
=
$this
->
getDomainByName
(
$domain_field
,
$match_domain
);
return
$domain_id
>
0
?
true
:
(
$match_domain
==
$primary_domain
);
}
}
Event Timeline
Log In to Comment