📄 installer.php
字号:
$response = $errnum . ' => ' . $errtext . (trim($result) != '' ? ' [' . $result . ']' : '');
$this->setError(($mode == 'NONSSL' ? ERROR_TEXT_CURL_PROBLEM_GENERAL : ERROR_TEXT_CURL_SSL_PROBLEM) . ' ' . $response, ERROR_CODE_CURL_SUPPORT, false);
return ($mode == 'NONSSL' ? ERROR_TEXT_CURL_PROBLEM_GENERAL : ERROR_TEXT_CURL_SSL_PROBLEM) . ' ' . $response;
}
return OKAY; // yes, this is an intentional constant
}
function trimTrailingSlash($string) {
return (substr($string,-1)=='/') ? substr($string,0,(strlen($string)-1)) : $string;
}
function resetConfigInfo() {
$this->configInfo = array();
$_SESSION['installerConfigInfo'] = $this->configInfo;
}
function setConfigInfo($key, $val) {
if ($val == 'unset_this') {
unset($this->configInfo[$key]);
} else {
$this->configInfo[$key] = $val;
}
$_SESSION['installerConfigInfo'] = $this->configInfo;
}
function getConfigInfo($key = '*', $printable = false) {
if ($key == '*') {
return ($printable) ? print_r($this->configInfo, true) : $this->configInfo;
} else {
return (isset($this->configInfo[$key])) ? $this->configInfo[$key] : '';
}
}
function resetConfigKeys() {
$this->configKeys = array();
$_SESSION['installerConfigKeys'] = $this->configKeys;
}
function setConfigKey($key, $val) {
if ($val == 'unset_this') {
unset($this->configKeys[$key]);
} else {
if ($key == 'DB_SERVER_PASSWORD') $val = $this->obfuscate($val);
$this->configKeys[$key] = $val;
}
$_SESSION['installerConfigKeys'] = $this->configKeys;
}
function setConfigKeyMulti($key_array) {
foreach($key_array as $key=>$val) {
$this->configKeys[$key] = $val;
if ($val == 'unset_this') unset($this->configKeys[$key]);
}
$_SESSION['installerConfigKeys'] = $this->configKeys;
}
function getConfigKey($key = '*', $printable = false) {
if ($key == '*') {
return ($printable) ? print_r($this->configKeys, true) : $this->configKeys;
} else if ($key == '-') {
$cleanKeys = $this->configKeys;
if (isset($cleanKeys['DB_SERVER_PASSWORD'])) $cleanKeys['DB_SERVER_PASSWORD'] = '***private***';
return ($printable) ? print_r($cleanKeys, true) : $cleanKeys;
} else {
$retVal = (isset($this->configKeys[$key])) ? $this->configKeys[$key] : '';
if ($key == 'DB_SERVER_PASSWORD') $retVal = $this->obfuscate($retVal, 'out');
return $retVal;
}
}
function getConfigKeysAsPost() {
$string = '';
foreach($this->configKeys as $key => $value) {
$string .= '<input type="hidden" name="zcinst[' . $key . ']" value="' . $value . '" />' . "\n";
}
return $string;
}
function readConfigKeysFromPost() {
$postArray = $_POST['zcinst'];
foreach($postArray as $key => $value) {
if ($key == 'DB_SERVER_PASSWORD') $value = $this->obfuscate($value, 'out');
$this->setConfigKey($key, $value);
}
return $this->configKeys;
}
function obfuscate($var, $mode='in') {
if ($mode == 'in') return base64_encode(base64_encode($var));
if ($mode == 'out') return base64_decode(base64_decode($var));
return $var;
}
function throwException($details, $moreinfo = '', $location = '', $fname = '') {
global $current_page;
$fname = ($fname == '') ? date('M-d-Y_h-i') : $fname;
$location = ($location == '') ? $current_page : $location;
if ($fp = @fopen(DEBUG_LOG_FOLDER . '/zcInstallExceptionDetails_' . $fname . '.log', 'a')) {
fwrite($fp, '---------------' . "\n" . date('M d Y G:i') . ' -- ' . $location . "\n" . $details . "\n\n");
fclose($fp);
}
}
function logDetails($details, $location = '', $fname = '') {
global $current_page;
$fname = ($fname == '') ? date('M-d-Y_h') : $fname;
$location = ($location == '') ? $current_page : $location;
if ($fp = @fopen(DEBUG_LOG_FOLDER . '/zcInstallLog_' . $fname . '.log', 'a')) {
fwrite($fp, '---------------' . "\n" . date('M d Y G:i') . ' -- ' . $location . "\n" . $details . "\n\n");
fclose($fp);
}
}
// Determine Document Root
function detectDocumentRoot() {
$dir_fs_www_root = realpath(dirname(basename(__FILE__)) . "/..");
if ($dir_fs_www_root == '') $dir_fs_www_root = '/';
$dir_fs_www_root = str_replace(array('\\','//'), '/', $dir_fs_www_root);
return $dir_fs_www_root;
}
// OLD METHOD ... should be removed
function detectDocumentRoot_OLD() {
// old method:
$realPath = realpath(dirname(basename(__FILE__)));
$script_filename = (isset($_SERVER['PATH_TRANSLATED'])) ? $_SERVER['PATH_TRANSLATED'] : (isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : $realPath);
$script_filename = str_replace(array('\\','//'), '/', $script_filename);
// split into an array in order to read its parts
$dir_fs_www_root_array = explode('/', dirname($script_filename));
// re-assemble with all except the last part
$dir_fs_www_root_tmp = array();
for ($i=0, $n=sizeof($dir_fs_www_root_array)-1; $i<$n; $i++) {
$dir_fs_www_root_tmp[] = $dir_fs_www_root_array[$i];
}
$dir_fs_www_root = implode('/', $dir_fs_www_root_tmp);
// if blank, at least give it a single slash /
if ($dir_fs_www_root == '') $dir_fs_www_root = '/';
return $dir_fs_www_root;
}
function writeConfigFiles() {
$virtual_http_path = parse_url($this->getConfigKey('virtual_http_path'));
$http_server = $virtual_http_path['scheme'] . '://' . $virtual_http_path['host'];
$http_catalog = (isset($virtual_http_path['path'])) ? $virtual_http_path['path'] : '';
if (isset($virtual_http_path['port']) && !empty($virtual_http_path['port'])) {
$http_server .= ':' . $virtual_http_path['port'];
}
if (substr($http_catalog, -1) != '/') {
$http_catalog .= '/';
}
$sql_cache_dir = (int)$this->getConfigKey('DIR_FS_SQL_CACHE');
$cache_type = $this->getConfigKey('SQL_CACHE_METHOD');
$https_server = $this->getConfigKey('virtual_https_server');
$https_catalog = $this->getConfigKey('virtual_https_path');
//if the https:// entries were left blank, use non-SSL versions instead of blank
if ($https_server=='' || $https_server=='https://' || $https_server=='://') $https_server=$http_server;
if ($https_catalog=='') $https_catalog=$http_catalog;
$https_catalog_path = ereg_replace($https_server,'',$https_catalog) . '/';
$https_catalog = $https_catalog_path;
//now let's write the files
// Catalog version first:
require('includes/store_configure.php');
$config_file_contents_catalog = $file_contents;
$fp = @fopen($this->getConfigKey('DIR_FS_CATALOG') . '/includes/configure.php', 'w');
if ($fp) {
fputs($fp, $file_contents);
fclose($fp);
@chmod($this->getConfigKey('DIR_FS_CATALOG') . '/includes/configure.php', 0644);
}
// now Admin version:
require('includes/admin_configure.php');
$config_file_contents_admin = $file_contents;
$fp = @fopen($this->getConfigKey('DIR_FS_CATALOG') . '/admin/includes/configure.php', 'w');
if ($fp) {
fputs($fp, $file_contents);
fclose($fp);
@chmod($this->getConfigKey('DIR_FS_CATALOG') . '/admin/includes/configure.php', 0644);
}
$this->configFiles = array('catalog' => $config_file_contents_catalog, 'admin' => $config_file_contents_admin);
return $this->validateConfigFiles($http_server);
}
function validateConfigFiles($http_server) {
// test whether the files were written successfully
$ztst_http_server = zen_read_config_value('HTTP_SERVER');
$ztst_db_server = zen_read_config_value('DB_SERVER');
$ztst_sqlcachedir = zen_read_config_value('DIR_FS_SQL_CACHE');
if ($ztst_http_server != $http_server || $ztst_db_server != $this->getConfigKey('DB_SERVER') || $ztst_sqlcachedir != $this->getConfigKey('DIR_FS_SQL_CACHE') || $this->getConfigKey('DB_SERVER') == '') {
$this->setError(ERROR_TEXT_COULD_NOT_WRITE_CONFIGURE_FILES, ERROR_CODE_COULD_NOT_WRITE_CONFIGURE_FILES, true);
$this->throwException('Failed writing configure.php file: Found in config file: [' . $ztst_http_server . '], expecting [' . $http_server . ']');
$this->throwException('Failed writing configure.php file: Found in config file: [' . $ztst_db_server . '], expecting [' . $this->getConfigKey('DB_SERVER') . ']');
$this->throwException('Failed writing configure.php file: Found in config file: [' . $ztst_sqlcachedir . '], expecting [' . $this->getConfigKey('DIR_FS_SQL_CACHE') . ']');
$retVal = false;
} else {
$retVal = true;
}
return $retVal;
}
function validateDatabaseSetup($data) {
if ($data['db_type'] != 'mysql') $data['db_prefix'] = ''; // if not using mysql, don't support prefixes because we don't trap for them
if ($data['db_sess'] != 'true' || $data['cache_type'] == 'file') { //if not storing sessions in database, or if caching to file, check folder
$this->isEmpty($data['sql_cache_dir'], ERROR_TEXT_CACHE_DIR_ISEMPTY, ERROR_CODE_CACHE_DIR_ISEMPTY);
$this->isDir($data['sql_cache_dir'], ERROR_TEXT_CACHE_DIR_ISDIR, ERROR_CODE_CACHE_DIR_ISDIR);
$this->isWriteable($data['sql_cache_dir'], ERROR_TEXT_CACHE_DIR_ISWRITEABLE, ERROR_CODE_CACHE_DIR_ISWRITEABLE);
}
//$this->checkPrefix($data['db_prefix'], ERROR_TEXT_DB_PREFIX_NODOTS, ERROR_CODE_DB_PREFIX_NODOTS);
$data['db_prefix'] == preg_replace('/[^0-9a-zA-Z_]/', '_', $data['db_prefix']);
$this->isEmpty($data['db_host'], ERROR_TEXT_DB_HOST_ISEMPTY, ERROR_CODE_DB_HOST_ISEMPTY);
$this->isEmpty($data['db_username'], ERROR_TEXT_DB_USERNAME_ISEMPTY, ERROR_CODE_DB_USERNAME_ISEMPTY);
$this->isEmpty($data['db_name'], ERROR_TEXT_DB_NAME_ISEMPTY, ERROR_CODE_DB_NAME_ISEMPTY);
$this->fileExists('sql/' . $data['db_type'] . '_zencart.sql', ERROR_TEXT_DB_SQL_NOTEXIST, ERROR_CODE_DB_SQL_NOTEXIST);
$this->functionExists($data['db_type'], ERROR_TEXT_DB_NOTSUPPORTED, ERROR_CODE_DB_NOTSUPPORTED);
$this->dbConnect($data['db_type'], $data['db_host'], $data['db_name'], $data['db_username'], $data['db_pass'], ERROR_TEXT_DB_CONNECTION_FAILED, ERROR_CODE_DB_CONNECTION_FAILED,ERROR_TEXT_DB_NOTEXIST, ERROR_CODE_DB_NOTEXIST);
$this->dbExists(false, $data['db_type'], $data['db_host'], $data['db_username'], $data['db_pass'], $data['db_name'], ERROR_TEXT_DB_NOTEXIST, ERROR_CODE_DB_NOTEXIST);
$data['db_sess'] = ($data['db_sess'] == 'true') ? 'db' : '';
$this->setConfigKey('DB_TYPE', $data['db_type']);
$this->setConfigKey('DB_PREFIX', $data['db_prefix']);
$this->setConfigKey('DB_SERVER', $data['db_host']);
$this->setConfigKey('DB_SERVER_USERNAME', $data['db_username']);
$this->setConfigKey('DB_SERVER_PASSWORD', $data['db_pass']);
$this->setConfigKey('DB_DATABASE', $data['db_name']);
$this->setConfigKey('STORE_SESSIONS', $data['db_sess']);
$this->setConfigKey('USE_PCONNECT', @$data['db_conn']);
$this->setConfigKey('SQL_CACHE_METHOD', $data['cache_type']);
$this->setConfigKey('DIR_FS_SQL_CACHE', $this->trimTrailingSlash($data['sql_cache_dir']));
}
function dbActivate() {
if (isset($this->db)) return;
if ($this->getConfigKey('DB_TYPE') == '') $this->setConfigKey('DB_TYPE', zen_read_config_value('DB_TYPE'));
if ($this->getConfigKey('DB_PREFIX') == '') $this->setConfigKey('DB_PREFIX', zen_read_config_value('DB_PREFIX'));
if ($this->getConfigKey('DB_SERVER') == '') $this->setConfigKey('DB_SERVER', zen_read_config_value('DB_SERVER'));
if ($this->getConfigKey('DB_SERVER_USERNAME') == '') $this->setConfigKey('DB_SERVER_USERNAME', zen_read_config_value('DB_SERVER_USERNAME'));
if ($this->getConfigKey('DB_SERVER_PASSWORD') == '') $this->setConfigKey('DB_SERVER_PASSWORD', zen_read_config_value('DB_SERVER_PASSWORD'));
if ($this->getConfigKey('DB_DATABASE') == '') $this->setConfigKey('DB_DATABASE', zen_read_config_value('DB_DATABASE'));
include_once('../includes/classes/db/' . $this->getConfigKey('DB_TYPE') . '/query_factory.php');
$this->db = new queryFactory;
$this->db->Connect($this->getConfigKey('DB_SERVER'), $this->getConfigKey('DB_SERVER_USERNAME'), $this->getConfigKey('DB_SERVER_PASSWORD'), $this->getConfigKey('DB_DATABASE'), true);
}
function dbLoadProcedure() {
$this->dbActivate(); // can likely remove this line for v1.4
global $db;
$db = $this->db;
// modified by zen-cart.cn
if (version_compare(mysql_get_server_info(), '4.1.3', '>='))
{
executeSql('sql/' . $this->getConfigKey('DB_TYPE') . '_zencart.sql', $this->getConfigKey('DB_DATABASE'), $this->getConfigKey('DB_PREFIX'));
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -