Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c57505d
updated reserved IP addresses
gbentley Jan 14, 2013
f25083a
changed country DEBUG msg
gbentley Jan 14, 2013
af17ccb
updated region.sql with latest CSV data
gbentley Jan 14, 2013
7a52e33
Merge branch 'master' of github.com:philandteds/region
gbentley Jan 14, 2013
d30d3d9
fix bug when SiteLanguageList is not empty
SerheyDolgushev Jan 20, 2013
794d82a
fixing issue when language list is empty
SerheyDolgushev Jan 20, 2013
9737aeb
Language list is empty, checkbox is used
SerheyDolgushev Jan 20, 2013
aeb3df5
fix issue when language list is empty and translation checkbox is used
SerheyNXC Jan 21, 2013
1007163
fix issue with empty language list and +2 languages
SerheyNXC Jan 21, 2013
f4ad9fe
fix the case with empty language list
SerheyNXC Feb 18, 2013
9f54c8a
https://github.com/philandteds/region/issues/1
SerheyDolgushev Apr 9, 2013
ca23baa
module views
SerheyDolgushev Apr 26, 2013
2e88e19
Direct URL
SerheyDolgushev Jul 10, 2013
05df825
canonical URL tools
SerheyDolgushev Jul 11, 2013
3f1218e
alternate URLs
SerheyDolgushev Jul 11, 2013
9f4cd55
LocaleCountryList for alternate URL
SerheyDolgushev Jul 12, 2013
a41f697
added locale back into translation output
gbentley Aug 22, 2013
d93bf4b
UPDATE: Added necessary files to validate user region
draghu9 Feb 9, 2016
e7671b9
UPDATE: Fixed URL translations
draghu9 Feb 28, 2016
6993fdf
UPDATE: Merge conflicts fix
draghu9 Feb 28, 2016
ff55285
UPDATE: Removed US related stuff
draghu9 Mar 2, 2016
8b0de91
BUFGIX: Fixed popup showing up for correct region
draghu9 Mar 7, 2016
c0bb51b
added region_alert tpls, JS, and translations
gbentley Apr 25, 2016
1bef185
ensure region.js is loaded
gbentley Apr 25, 2016
b1a3c96
added docs around region/check access
gbentley Apr 25, 2016
7d5f03d
added region alert spanish translation
gbentley Apr 25, 2016
2c8386a
dev code for adding locale to i18n operator
gbentley May 9, 2016
7a6bb5b
revert to Geoff's version
gbentley May 23, 2016
7e5533c
fixes to region alert
gbentley May 23, 2016
a911102
Merge remote-tracking branch 'origin/region_alert'
gbentley May 23, 2016
4e5e989
removed obselete tpl operator
gbentley May 23, 2016
53ac37c
added hreflang exception for US region
gbentley May 31, 2016
03e6364
set correct mime-type for region check
gbentley Jun 16, 2016
a0f2e65
no need to parse JSON data
gbentley Jun 16, 2016
7476fd4
Minor tweaks: cleaned up the JSON output of region/check
Nov 25, 2016
e966031
Now uses local storage to flag whether a region check has been perfor…
Nov 30, 2016
13dc7a5
Removed bogus region checking session variable (was causing region ch…
Jan 17, 2017
ece31a2
Trap clicks on the region selector and disable the popup.
Jan 19, 2017
5710e6e
More debugging
Jan 20, 2017
84fce46
Allow region check regardless of node id
Jan 20, 2017
11999a1
Convert region/check to a GET and call against the current siteaccess…
Jan 20, 2017
ce785ba
Now uses ezxRegion::getRegionURL to generate URL to redirect to, inst…
Jan 23, 2017
96f3da1
When retrieving the translations for the dialog, do not use the cache…
Feb 15, 2017
2385cfc
Removed the EZREGION cookie (experimental)
Feb 20, 2018
002126d
Force a check for region on region/check (was previously only running…
Feb 22, 2018
9c0b482
Prevent repeated region checks by only calling the ajax when the site…
Mar 4, 2018
d18dc88
Updating region translations for German and French
Feb 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions autoloads/eztemplateautoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
$eZTemplateOperatorArray[] =
array( 'script' => eZExtension::baseDirectory() . '/region/autoloads/region.php',
'class' => 'Region',
'operator_names' => array( 'language_uri', 'region_languages', 'regions', 'in_region' ) );

'operator_names' => array( 'language_uri', 'region_languages', 'regions', 'in_region', 'canonical_url', 'canonical_language_url', 'detected_region', 'detected_locale' ) );
?>
101 changes: 89 additions & 12 deletions autoloads/region.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Region()
*/
function operatorList()
{
return array( 'region_languages', 'regions', 'language_uri', 'in_region' );
return array( 'region_languages', 'regions', 'language_uri', 'in_region', 'canonical_url', 'canonical_language_url', 'detected_region', 'detected_locale' );
}
/*!
\return true to tell the template engine that the parameter list exists per operator type,
Expand All @@ -23,8 +23,8 @@ function operatorList()
function namedParameterPerOperator()
{
return true;
}
}

/*!
See eZTemplateOperator::namedParameterList
*/
Expand All @@ -42,17 +42,25 @@ function namedParameterList()
'regions' => array( 'siteaccessname' => array( 'type' => 'string',
'required' => true,
'default' => false ) ),
'in_region' => array( 'region' => array( 'type' => 'string',
'required' => true,
'default' => false ) ),
);
'in_region' => array( 'region' => array( 'type' => 'string',
'required' => true,
'default' => false ) ),
'canonical_url' => array(),
'canonical_language_url' => array(),
'detected_region' => array(),
'detected_locale' => array()
);

}
/*!
Executes the PHP function for the operator cleanup and modifies \a $operatorValue.
*/
function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
{
$moduleResult = $tpl->hasVariable( 'module_result' ) ? $tpl->variable( 'module_result' ) : array();
$contentInfo = isset( $moduleResult['content_info'] ) ? $moduleResult['content_info'] : array();
$currentNodeId = isset( $moduleResult['node_id'] ) ? (int) $moduleResult['node_id'] : 0;

switch ( $operatorName )
{
case 'language_uri':
Expand All @@ -76,24 +84,93 @@ function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &
case 'in_region':
$regionini = eZINI::instance( 'region.ini' );
$regions = $regionini->variableArray('Regions', 'RegionCountryList');

$ip = ( array_key_exists( 'TESTIP', $_GET ) and ezxISO3166::validip( $_GET['TESTIP'] ) ) ? new ezxISO3166( $_GET['TESTIP']) : new ezxISO3166();
$ccode = ( array_key_exists( 'country', $_GET ) ) ? strtoupper($_GET['country']) : $ip->getCCfromIP();
eZDebug::writeDebug( $regions, 'Regions' );
eZDebug::writeDebug( $ccode, 'Country code' );

// CHECK THAT THE REGION EXISTS IN THE REGION GROUP
if ( in_array( $ccode, $regions[$namedParameters['region']] ) && array_key_exists($namedParameters['region'], $regions) )
{
$operatorValue = true;
break;
}

$operatorValue = false;
break;
case 'canonical_url':
if(
isset( $contentInfo['main_node_url_alias'] )
&& $contentInfo['main_node_url_alias']
) {
$operatorValue = $contentInfo['main_node_url_alias'];
}
break;
case 'canonical_language_url':
$return = array();

$node = eZContentObjectTreeNode::fetch( $currentNodeId );
$object = false;
if( $node instanceof eZContentObjectTreeNode ) {
$object = $node->attribute( 'object' );
}

$translatedURLs = ezpLanguageSwitcher::setupTranslationSAList( $currentNodeId );
$localeCountries = eZINI::instance( 'region.ini' )->variable( 'Regions', 'LocaleCountryList' );
foreach( $translatedURLs as $sa => $translation ) {
$ini = eZSiteAccess::getIni( $sa );
$localeCode = $ini->variable( 'RegionalSettings', 'Locale' );
$locale = new eZLocale( $localeCode );
if( isset( $localeCountries[ $localeCode ] ) && $localeCode != 'eng-US' ) {
$tmp = explode( '-', strtolower( $locale->attribute( 'http_locale_code' ) ) );
$countryCode = $tmp[0];
$languages = explode( ';', strtolower( $localeCountries[ $localeCode ] ) );
foreach( $languages as $language ) {
$return[] = array(
'language' => $countryCode . '-' . $language,
'url' => $translation['url'],
'siteaccess' => $sa
);
}
} else {
$return[] = array(
'language' => strtolower( $locale->attribute( 'http_locale_code' ) ),
'url' => $translation['url'],
'siteaccess' => $sa
);
}
}

$operatorValue = $return;
break;
case 'detected_region':
$operatorValue = eZINI::instance( 'site.ini' )->variable('SiteSettings','DefaultAccess');
$systemIdentifiedRegion = ezxRegion::getRegionData(ezxISO3166::getRealIpAddr());
$preferredRegion = $systemIdentifiedRegion['preferred_region'];

if(array_key_exists('preferred_regions',$systemIdentifiedRegion)) {
$preferredRegion = empty($preferredRegion) ? 'eng-US' : $preferredRegion;
$systemIdentifiedSiteAccess = $systemIdentifiedRegion['preferred_regions'][$preferredRegion][0];

$countryNames = eZINI::instance( 'site.ini' )->variable( 'RegionalSettings', 'TranslationSA' );
$operatorValue = array_key_exists($systemIdentifiedSiteAccess, $countryNames) ? $countryNames[$systemIdentifiedSiteAccess] : 'United States';
}
break;
case 'detected_locale':
$operatorValue = eZINI::instance( 'site.ini' )->variable('SiteSettings','DefaultAccess');
$systemIdentifiedRegion = ezxRegion::getRegionData(ezxISO3166::getRealIpAddr());
$preferredRegion = $systemIdentifiedRegion['preferred_region'];
if(array_key_exists('preferred_regions',$systemIdentifiedRegion)) {
$preferredRegion = empty($preferredRegion) ? 'eng-US' : $preferredRegion;

$operatorValue = $preferredRegion;
}
break;

}


}
}
?>
184 changes: 184 additions & 0 deletions classes/ezi18noperator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php
/**
* File containing the eZi18nOperator class.
*
* @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version 2012.8
* @package kernel
*/

//!! eZKernel
//! The class eZi18nOperator does
/*!

*/

class eZi18nOperator
{
function eZi18nOperator( $name = 'i18n', $extensionName = 'x18n', $dynamicName = 'd18n' )
{
$this->Operators = array( $name, $extensionName, $dynamicName );
$this->Name = $name;
$this->ExtensionName = $extensionName;
// d18n is a i18n alias for use with dynamic variables as input
// where you don't want ezlupdate to pick up the string
$this->DynamicName = $dynamicName;
}

/*!
Returns the operators in this class.
*/
function operatorList()
{
return $this->Operators;
}

/*!
\return true to tell the template engine that the parameter list exists per operator type.
*/
function namedParameterPerOperator()
{
return true;
}

/*!
See eZTemplateOperator::namedParameterList()
*/
function namedParameterList()
{
$def = array( $this->Name => array( 'context' => array( 'type' => 'string',
'required' => false,
'default' => false ),
'comment' => array( 'type' => 'string',
'required' => false,
'default' => '' ),
'arguments' => array( 'type' => 'hash',
'required' => false,
'default' => false ),
'locale' => array( 'type' => 'array',
'required' => false,
'default' => false ) ),
$this->ExtensionName => array( 'extension' => array( 'type' => 'string',
'required' => true,
'default' => false ),
'context' => array( 'type' => 'string',
'required' => false,
'default' => false ),
'comment' => array( 'type' => 'string',
'required' => false,
'default' => '' ),
'arguments' => array( 'type' => 'hash',
'required' => false,
'default' => false ) ) );
$def[ $this->DynamicName ] = $def[ $this->Name ];
return $def;
}

function operatorTemplateHints()
{
$def = array( $this->Name => array( 'input' => true,
'output' => true,
'parameters' => true,
'element-transformation' => true,
'transform-parameters' => true,
'input-as-parameter' => 'always',
'element-transformation-func' => 'i18nTrans') );
$def[ $this->DynamicName ] = $def[ $this->Name ];
return $def;
}

function i18nTrans( $operatorName, &$node, $tpl, &$resourceData,
$element, $lastElement, $elementList, $elementTree, &$parameters )
{
// i18n( $input, $context, $comment, $arguments )
// Check if if the three first parameters are constants, if not we cannot compile it
foreach ( array_slice( $parameters, 0, 3 ) as $parameter )
{
if ( $parameter !== null &&
!eZTemplateNodeTool::isConstantElement( $parameter ) )
{
return false;
}
}
$value = eZTemplateNodeTool::elementConstantValue( $parameters[0] );

$numParameters = count ( $parameters );
$context = ( $numParameters > 1 ) ? eZTemplateNodeTool::elementConstantValue( $parameters[1] ) : null;
$comment = ( $numParameters > 2 ) ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) : null;
$locale = ( $numParameters > 4 ) ? eZTemplateNodeTool::elementConstantValue( $parameters[4] ) : null;

if ( $numParameters < 4 )
{
return array ( eZTemplateNodeTool::createStringElement( ezpI18n::tr( $context, $value, $comment, null ) ) );
}

$values = array();

$ini = eZINI::instance();
if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
{
$language = ( $locale != null ) ? eZLocale::instance($locale)->localeFullCode() : eZLocale::instance()->localeFullCode();
if ( $language != "eng-GB" ) // eng-GB does not need translation
{
$file = 'translation.ts';
$ini = eZINI::instance();
$useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
eZTSTranslator::initialize( $context, $language, $file, $useCache );

$man = eZTranslatorManager::instance();
$newValue = $man->translate( $context, $value, $comment );
if ( $newValue )
{
$value = $newValue;
}
}
}

$values[] = array( eZTemplateNodeTool::createStringElement( $value ) );
$values[] = $parameters[3];

$code = '%tmp1% = array();' . "\n" .
'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" .
'{' . "\n" .
' if ( is_int( %tmp2% ) )' . "\n" .
' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" .
' else' . "\n" .
' %tmp1%[%tmp2%] = %tmp3%;' . "\n" .
'}' . "\n" .
'%output% = strtr( %1%, %tmp1% );' . "\n";

return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 3 ) );
}

function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, &$namedParameters, $placement )
{
switch ( $operatorName )
{
case $this->Name:
case $this->DynamicName:
{
$context = $namedParameters['context'];
$comment = $namedParameters['comment'];
$arguments = $namedParameters['arguments'];
$locale = $namedParameters['locale'];
$value = ezpI18n::tr( $context, $value, $comment, $arguments, $locale );
} break;
case $this->ExtensionName:
{
$extension = $namedParameters['extension'];
$context = $namedParameters['context'];
$comment = $namedParameters['comment'];
$arguments = $namedParameters['arguments'];
$value = ezpI18n::tr( $context, $value, $comment, $arguments );
} break;
}
}

/// \privatesection
public $Operators;
public $Name;
public $ExtensionName;
}

?>
Loading