function saveConfig($return_data = 0) { $sef_config_file = sh404SEF_ADMIN_ABS_PATH . 'config/config.sef.php'; $database =& JFactory::getDBO(); $quoteGPC = get_magic_quotes_gpc(); $user = JFactory::getUser(); $userName = empty($user) ? '-' : $user->username; $userId = empty($user) ? '-' : $user->id; //build the data file $config_data = '<?php' . "\n" . '// config.sef.php : configuration file for sh404SEF for Joomla 1.5.x' . "\n" . '// ' . $this->version . "\n" . '// saved at: ' . date('Y-m-d H:i:s') . "\n" . '// by: ' . $userName . ' (id: ' . $userId . ' )' . "\n" . '// domain: ' . sh404sefFactory::getPageInfo()->getDefaultFrontLiveSite() . "\n\n" . 'if (!defined(\'_JEXEC\')) die(\'Direct Access to this location is not allowed.\');' . "\n\n"; foreach ($this as $key => $value) { if ($key != "0" && $key != 'ipWhiteList' && $key != 'ipBlackList' && $key != 'uAgentWhiteList' && $key != 'uAgentBlackList' && $key != 'defaultParamList') { $config_data .= "\${$key} = "; if ($key == 'shLangTranslateList' || $key == 'shLangInsertCodeList' || $key == 'defaultComponentStringList' || $key == 'pageTexts' || $key == 'liveSites') { $datastring = ''; foreach ($value as $key2 => $data) { $datastring .= '"' . $key2 . '"=>' . '"' . str_replace('"', '\\"', $quoteGPC ? stripslashes($data) : $data) . '",'; } $datastring = JString::substr($datastring, 0, -1); $config_data .= "array({$datastring})"; } else { switch (gettype($value)) { case "boolean": $config_data .= $value ? "true" : "false"; break; case "string": $datastring = str_replace("'", "\\'", $quoteGPC ? stripslashes($value) : $value); $config_data .= "'" . $datastring . "'"; break; case "integer": case "double": $config_data .= strval($value); break; case "array": $datastring = ''; foreach ($value as $key2 => $data) { $datastring .= '"' . str_replace('"', '\\"', $quoteGPC ? stripslashes($data) : $data) . '",'; } $datastring = JString::substr($datastring, 0, -1); $config_data .= "array({$datastring})"; break; default: $config_data .= "null"; break; } } $config_data .= ";\n"; } } $config_data .= '?' . '>'; if ($return_data == 1) { return $config_data; } else { // write to disk $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); $config_data = strtr($config_data, $trans_tbl); jimport('joomla.filesystem.file'); $ret = JFile::write($sef_config_file, $config_data); // save lists shSaveFile(sh404SEF_ADMIN_ABS_PATH . 'security/sh404SEF_IP_white_list.dat', $this->ipWhiteList); shSaveFile(sh404SEF_ADMIN_ABS_PATH . 'security/sh404SEF_IP_black_list.dat', $this->ipBlackList); shSaveFile(sh404SEF_ADMIN_ABS_PATH . 'security/sh404SEF_uAgent_white_list.dat', $this->uAgentWhiteList); shSaveFile(sh404SEF_ADMIN_ABS_PATH . 'security/sh404SEF_uAgent_black_list.dat', $this->uAgentBlackList); shSaveFile(sh404SEF_ADMIN_ABS_PATH . 'custom.sef.php', $quoteGPC ? stripslashes($this->defaultParamList) : $this->defaultParamList); // V 1.2.4.q : save copy of config file to other location for automatic recovering of config when upgrading $fileName = sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_' . str_replace('/', '_', str_replace('http://', '', sh404sefFactory::getPageInfo()->getDefaultFrontLiveSite())) . '.php'; JFile::write($fileName, $config_data); // save lists to backup location if (!is_writable(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security')) { jimport('joomla.filesystem.folder'); JFolder::create(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security'); } shSaveFile(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security/sh404SEF_IP_white_list.dat', $this->ipWhiteList); shSaveFile(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security/sh404SEF_IP_black_list.dat', $this->ipBlackList); shSaveFile(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security/sh404SEF_uAgent_white_list.dat', $this->uAgentWhiteList); shSaveFile(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_security/sh404SEF_uAgent_black_list.dat', $this->uAgentBlackList); shSaveFile(sh404SEF_ABS_PATH . 'media/sh404sef/sh404_upgrade_conf_' . str_replace('/', '_', str_replace('http://', '', sh404sefFactory::getPageInfo()->getDefaultFrontLiveSite())) . '.custom.php', $quoteGPC ? stripslashes($this->defaultParamList) : $this->defaultParamList); // v 3.0+ : as we are now using J! router, we need to update the global configuration object with the rewrite mode setting // as otherwise users would have to manually change it return $ret; } }
protected function shInitLanguageList($currentList, $default, $defaultLangDefault) { $ret = array(); $shKind = shIsMultilingual(); $app = JFactory::getApplication(); if (!$shKind && !$app->isAdmin()) { if (empty($currentList) || !isset($currentList[sh404sefFactory::getPageInfo()->currentLanguageTag])) { $ret[sh404sefFactory::getPageInfo()->currentLanguageTag] = $defaultLangDefault; } else { $ret[sh404sefFactory::getPageInfo()->currentLanguageTag] = $currentList[sh404sefFactory::getPageInfo()->currentLanguageTag]; } } else { $activeLanguages = shGetActiveLanguages(); if (empty($activeLanguages)) { if (empty($currentList) || !isset($currentList[sh404sefFactory::getPageInfo()->currentLanguageTag])) { $ret[sh404sefFactory::getPageInfo()->currentLanguageTag] = $defaultLangDefault; } else { $ret[sh404sefFactory::getPageInfo()->currentLanguageTag] = $currentList[sh404sefFactory::getPageInfo()->currentLanguageTag]; } } else { foreach ($activeLanguages as $language) { if (empty($currentList) || !isset($currentList[$language->code])) { $ret[$language->code] = $language->code == sh404sefFactory::getPageInfo()->currentLanguageTag ? $defaultLangDefault : $default; } else { $ret[$language->code] = $currentList[$language->code]; } } } } return $ret; }