8 July 2014 - Listening Session with Emiral Audio
FALSE,
"version" => "2.0.0",
"urlParameter" => "",
"urlPreferredParameter" => "lang",
"urlParameterLanguage" => "",
"urlParametersSupported" => array("lang", "language", "rwml", "hl", "loc", "locale"),
"cookieName" => "rwml_preferred_language",
"cookieHTTPS" => FALSE,
"cookiePath" => "/",
"cookieAge" => 7776000, // Direct setting of 86400 * 90 days e.g. is not supported by RW and requires PHP 5.6 for math expressions to work in constant definitions so try protected instead. Read from config.
"cookieDays" => 180,
"cookieDomain" => "",
"languageDefault" => "EN",
"languageActive" => "",
"languageSelectDefault" => true,
"languagesUsed" => array("EN", "", "", "", "", "", "", "", "", ""), // Read from config.
"tidyPages" => "index.php", // Follow the RW default of creating nice looking URL links
"serverName" => "",
"serverPort" => 80,
"serverDefaultPorts" => array(80, 443),
"scriptName" => "",
"scriptNameRWML" => "", // As used for the links created by RWML
"scriptURI" => "",
"scriptLanguageSwitch" => "",
"scriptLanguageAlternativeSwitch" => "",
);
public function __construct() {
// Note that $_SERVER['SERVER_NAME'] is not set in RW6 Preview mode.
// SERVER_NAME / HTTP_HOST
// SCRIPT_URI / REQUEST_URI.
$this->setProperty("serverName", $_SERVER["SERVER_NAME"]);
$this->setProperty("serverPort", $_SERVER["SERVER_PORT"]);
$this->setProperty("scriptName", $_SERVER["SCRIPT_NAME"]);
@$this->setProperty("scriptURI", $_SERVER["REQUEST_URI"]);
$this->setProperty("scriptNameRWML", str_replace($this->getProperty("tidyPages"), '', $this->getProperty("scriptName")));
$this->setProperty("cookieAge", 86400 * intval($this->getProperty("cookieDays")));
$this->setProperty("languagesUsed", array_diff($this->getProperty("languagesUsed"), array("")));
// Set to a non-empty value if the script was queried through the HTTPS protocol.
// Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
$this->setProperty("cookieHTTPS", TRUE);
}
}
private function _addProperty($configItem, $configValue) {
@$this->_configuration[$configItem] = $configValue;
}
public function setProperty($configItem, $configValue) {
foreach ($this->_configuration as $key => &$value) {
if ($key == $configItem) {
$value = $configValue;
break;
}
}
}
public function getProperty($configItem) {
$returnValue = "Oops a daisy";
foreach ($this->_configuration as $key => $value) {
if ($key == $configItem) {
$returnValue = $value;
break;
}
}
return $returnValue;
}
public function dump($prefix, $tail, $lineBreak) {
$dump = $prefix.$lineBreak;
foreach ($this->_configuration as $key => $value) {
$dump .= $key." = ";
if(is_array($value)) {
$dump .= var_export(implode(", ", $value), TRUE);
} else {
$dump .= var_export($value, TRUE);
}
$dump .= $lineBreak;
}
$dump .= $tail.$lineBreak;
echo $dump;
}
}
}
if (!class_exists('rwmlSystem')) {
class rwmlSystem {
private $_configuration;
// Parameters:
// 1 = Debug, Boolean
public function __construct($debug) {
$helperVar = "";
$this->_configuration = new rwmlConfiguration();
if($debug == TRUE) {
$this->_configuration->setProperty("debug", $debug);
}
// Get Possible URL Parameters that are supported by RWML and override the possible stored language value.
foreach ($this->_configuration->getProperty("urlParametersSupported") as $parameter) {
if(($this->_configuration->getProperty("languageActive") === "") && (isset($_GET[$parameter]))) {
$parameterValue = $_GET[$parameter];
$this->_configuration->setProperty("languageActive", $parameterValue);
$this->_configuration->setProperty("urlParameter", $parameter);
$this->_configuration->setProperty("urlParameterLanguage", $parameterValue);
}
}
// Get the stored language value from the RWML Cookie.
if (($this->_configuration->getProperty("languageActive") === "") && (isset($_COOKIE[$this->_configuration->getProperty("cookieName")]))) {
$this->_configuration->setProperty("languageActive", $_COOKIE[$this->_configuration->getProperty("cookieName")]);
}
// Auto Select Default Language based on the configuration once no other value is known.
if(($this->_configuration->getProperty("languageActive") === "") && ($this->_configuration->getProperty("languageSelectDefault") === TRUE)) {
$this->_configuration->setProperty("languageActive", $this->_configuration->getProperty("languageDefault"));
}
// Set or Refresh the Cookie, Not possible with PHP if the header is already sent so add a JavaScript fallback and/or enable PHP buffering.
if($this->_configuration->getProperty("languageActive") != "") {
@setcookie($this->_configuration->getProperty("cookieName"), $this->_configuration->getProperty("languageActive"), time()+$this->_configuration->getProperty("cookieAge"), $this->_configuration->getProperty("cookiePath"), $this->_configuration->getProperty("serverName"), $this->_configuration->getProperty("cookieHTTPS"));
}
// Detect for usage of URL parameter and possible other RW extensions using the ? so we need to use & to add our language switches or adapt them a little bit.
// Rapid Cart URL example: ?catalog/all/-/date/1
// Add detection of uses and preferred URL Parameters
$helperVar = "";
$helperURLParameter = $this->_configuration->getProperty("urlParameter");
if($helperURLParameter === "") { $helperURLParameter = $this->_configuration->getProperty("urlPreferredParameter"); }
$helperVar = $this->_configuration->getProperty("scriptNameRWML")."?".$helperURLParameter."=";
if(($this->_configuration->getProperty("urlParameterLanguage") == "") && ($strpos = strpos($this->_configuration->getProperty("scriptURI"), "?") !== FALSE)) {
$helperVar = $this->_configuration->getProperty("scriptURI")."&".$helperURLParameter."=";
$helperVar = str_replace ("?&".$helperURLParameter."=" , "?".$helperURLParameter."=" , $helperVar);
}
if(($this->_configuration->getProperty("urlParameterLanguage") != "") && ($strpos = strpos($this->_configuration->getProperty("scriptURI"), "?") !== FALSE)) {
$helperVar = str_replace("&".$this->_configuration->getProperty("urlParameter")."=".$this->_configuration->getProperty("urlParameterLanguage"), "&".$helperURLParameter."=", $this->_configuration->getProperty("scriptURI"));
$helperVar = str_replace("?".$this->_configuration->getProperty("urlParameter")."=".$this->_configuration->getProperty("urlParameterLanguage") , "?".$helperURLParameter."=", $helperVar);
}
$this->_configuration->setProperty("scriptLanguageSwitch", $helperVar);
unset($helperVar);
// Alternative Language Switch as required for Head Links.
$helperVar = ($this->_configuration->getProperty("cookieHTTPS") == TRUE) ? "https://" : "http://" . rtrim($this->_configuration->getProperty("serverName"), "/");
$helperVar .= (!in_array($this->_configuration->getProperty("serverPort"), $this->_configuration->getProperty("serverDefaultPorts"))) ? ":" . $this->_configuration->getProperty("serverPort") : "";
$helperVar .= $this->_configuration->getProperty("scriptLanguageSwitch");
$this->_configuration->setProperty("scriptLanguageAlternativeSwitch", $helperVar);
unset($helperVar);
}
public function getConfiguration($htmlComment = FALSE) {
if($htmlComment){
return $this->_configuration->dump("", "\r\n");
} else {
return $this->_configuration->dump("-- Begin of RWML Configuration --", "-- End of RWML Configuration --", "
"); } } // https://support.google.com/webmasters/answer/189077?hl=nl // https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes public function getAlternativeLanguageHeadHTML() { $alternativeHeadHTML = ""; $activeLanguage = $this->_configuration->getProperty("languageActive"); $url = $this->_configuration->getProperty("scriptLanguageAlternativeSwitch"); @$languagesUsed = $this->_configuration->getProperty("languagesUsed"); if (is_array($languagesUsed)) { foreach ($languagesUsed as $value) { if ($activeLanguage != $value) { $alternativeHeadHTML .= "\n"; } } } // $alternativeHeadHTML .= "\n"; return $alternativeHeadHTML; } public function getLanguageSwitch($language) { $languageSwitch = "?lang=".$language; @$languageSwitch = $this->_configuration->getProperty("scriptLanguageSwitch").$language; return $languageSwitch; } public function isActiveLanguage($language = "$%^") { if($this->_configuration->getProperty("languageActive") === $language) { return TRUE; } else { return FALSE; } } } } if (!isset($rwml)) { $rwml = new rwmlSystem(FALSE); // debug, $ob_rw_org_head = ob_get_clean(); ob_start(); echo($rwml->getAlternativeLanguageHeadHTML()); $ob_rwml_meta = ob_get_clean(); ob_start(); echo str_replace(''.'head>',$ob_rwml_meta.''.'head>',$ob_rw_org_head); } ?>
"); } } // https://support.google.com/webmasters/answer/189077?hl=nl // https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes public function getAlternativeLanguageHeadHTML() { $alternativeHeadHTML = ""; $activeLanguage = $this->_configuration->getProperty("languageActive"); $url = $this->_configuration->getProperty("scriptLanguageAlternativeSwitch"); @$languagesUsed = $this->_configuration->getProperty("languagesUsed"); if (is_array($languagesUsed)) { foreach ($languagesUsed as $value) { if ($activeLanguage != $value) { $alternativeHeadHTML .= "\n"; } } } // $alternativeHeadHTML .= "\n"; return $alternativeHeadHTML; } public function getLanguageSwitch($language) { $languageSwitch = "?lang=".$language; @$languageSwitch = $this->_configuration->getProperty("scriptLanguageSwitch").$language; return $languageSwitch; } public function isActiveLanguage($language = "$%^") { if($this->_configuration->getProperty("languageActive") === $language) { return TRUE; } else { return FALSE; } } } } if (!isset($rwml)) { $rwml = new rwmlSystem(FALSE); // debug, $ob_rw_org_head = ob_get_clean(); ob_start(); echo($rwml->getAlternativeLanguageHeadHTML()); $ob_rwml_meta = ob_get_clean(); ob_start(); echo str_replace(''.'head>',$ob_rwml_meta.''.'head>',$ob_rw_org_head); } ?>