. * * PHP version 5 * @copyright cgo IT, 2012-2013 * @author Carsten Götzinger (info@cgo-it.de) * @package aeo * @license GNU/LGPL * @filesource */ namespace cgoIT\aeo; /** * Class AeoUtil */ class AeoUtil extends \Controller { /** * Initialize the object * @param array */ public function __construct() { parent::__construct(); $this->import('\\Database', 'Database'); } /** * Liefert die Redirect-Page je nach Sprache * @param $pageId */ public function getRedirectPageForLanguage($arrRedirectPages, $language) { $defaultLanguage = $this->Database->prepare("SELECT language FROM tl_page WHERE type = 'root' and fallback = 1")->limit(1)->execute(); if (is_array($arrRedirectPages)) { foreach ($arrRedirectPages as $key => $value) { if ($value['aeo_language'] == $language) { return $this->getPageId($value['aeo_redirecturl']); } if ($value['aeo_language'] == $defaultLanguage->language) { $defaultPage = $this->getPageId($value['aeo_redirecturl']); } } } return $defaultPage; } /** * Liefert die PageId zu einem InsertTag * @param $tag */ public function getPageId($tag) { $tags = preg_split('/\{\{([^\}]+)\}\}/', $tag, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($tags as $strTag) { if ($strTag == '') { continue; } $elements = explode('::', $strTag); return $elements[1]; } } /** * Fix up current language depending on momentary user preference. * Strangely $GLOBALS['TL_LANGUAGE'] is switched to the current user language if user is just * authentitcating and has the language property set. * See system/libraries/User.php:202 * We override this behavior and let the user temporarily use the selected by him language. * One workaround would be to not let the members have a language property. * Then this method will not be needed any more. */ public function fixupCurrentLanguage(){ $selected_language = $this->Input->post('language'); //allow GET request for language if(!$selected_language){ $selected_language = $this->Input->get('language'); } if( ($selected_language) && in_array($selected_language, \I18nl10n\Classes\I18nl10n::getInstance()->getAvailableLanguages(true, true)) ) { $_SESSION['TL_LANGUAGE'] = $GLOBALS['TL_LANGUAGE'] = $selected_language; } elseif(isset($_SESSION['TL_LANGUAGE'])) { $GLOBALS['TL_LANGUAGE'] = $_SESSION['TL_LANGUAGE']; } } } ?>