📄 general.php
字号:
<?php
/**
* general functions used by the installer
* @package Installer
* @access private
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: general.php 7333 2007-10-31 10:16:15Z drbyte $
*/
if (!defined('TABLE_UPGRADE_EXCEPTIONS')) define('TABLE_UPGRADE_EXCEPTIONS','upgrade_exceptions');
function zen_not_null($value) {
if (is_array($value)) {
if (sizeof($value) > 0) {
return true;
} else {
return false;
}
} else {
if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
return true;
} else {
return false;
}
}
}
function zen_output_string($string, $translate = false, $protected = false) {
if ($protected == true) {
return htmlspecialchars($string);
} else {
if ($translate == false) {
return zen_parse_input_field_data($string, array('"' => '"'));
} else {
return zen_parse_input_field_data($string, $translate);
}
}
}
////
function zen_db_input($string) {
return addslashes($string);
}
////
function zen_parse_input_field_data($data, $parse) {
return strtr(trim($data), $parse);
}
function setInputValue($input, $constant, $default) {
if (isset($input)) {
define($constant, $input);
} else {
define($constant, $default);
}
}
function setRadioChecked($input, $constant, $default) {
if ($input == '') {
$input = $default;
}
if ($input == 'true') {
define($constant . '_FALSE', '');
define($constant . '_TRUE', 'checked="checked" ');
} else {
define($constant . '_FALSE', 'checked="checked" ');
define($constant . '_TRUE', '');
}
}
function setSelected($input, $selected) {
if ($input == $selected) {
return ' selected="selected"';
}
}
function executeSql($sql_file, $database, $table_prefix = '', $isupgrade=false) {
$debug=false;
if (!defined('DB_PREFIX')) define('DB_PREFIX',$table_prefix);
// echo 'start SQL execute';
global $db;
$ignored_count=0;
$ignore_line=false;
$results=0;
$string='';
$result='';
$errors=array();
// prepare for upgrader processing
if ($isupgrade) zen_create_upgrader_table(); // only creates table if doesn't already exist
if (!get_cfg_var('safe_mode')) {
@set_time_limit(1200);
}
$counter = 0;
$lines = file($sql_file);
$newline = '';
$lines_to_keep_together_counter=0;
// $saveline = '';
foreach ($lines as $line) {
$line = trim($line);
// $line = $saveline . $line;
$keep_together = 1; // count of number of lines to treat as a single command
// split the line into words ... starts at $param[0] and so on. Also remove the ';' from end of last param if exists
$param=explode(" ",(substr($line,-1)==';') ? substr($line,0,strlen($line)-1) : $line);
if (!isset($param[4])) $param[4] = '';
if (!isset($param[5])) $param[5] = '';
// The following command checks to see if we're asking for a block of commands to be run at once.
// Syntax: #NEXT_X_ROWS_AS_ONE_COMMAND:6 for running the next 6 commands together (commands denoted by a ;)
if (substr($line,0,28) == '#NEXT_X_ROWS_AS_ONE_COMMAND:') $keep_together = substr($line,28);
if (substr($line,0,1) != '#' && substr($line,0,1) != '-' && $line != '') {
// if ($table_prefix != -1) {
//echo '*}'.$line.'<br>';
$line_upper=strtoupper($line);
switch (true) {
case (substr($line_upper, 0, 21) == 'DROP TABLE IF EXISTS '):
$line = 'DROP TABLE IF EXISTS ' . $table_prefix . substr($line, 21);
break;
case (substr($line_upper, 0, 11) == 'DROP TABLE ' && $param[2] != 'IF'):
if (!$checkprivs = zen_check_database_privs('DROP')) $result=sprintf(REASON_NO_PRIVILEGES,'DROP');
if (!zen_table_exists($param[2]) || zen_not_null($result)) {
zen_write_to_upgrade_exceptions_table($line, (zen_not_null($result) ? $result : sprintf(REASON_TABLE_DOESNT_EXIST,$param[2])), $sql_file);
$ignore_line=true;
$result=(zen_not_null($result) ? $result : sprintf(REASON_TABLE_DOESNT_EXIST,$param[2])); //duplicated here for on-screen error-reporting
break;
} else {
$line = 'DROP TABLE ' . $table_prefix . substr($line, 11);
}
break;
case (substr($line_upper, 0, 13) == 'CREATE TABLE '):
// check to see if table exists
$table = (strtoupper($param[2].' '.$param[3].' '.$param[4]) == 'IF NOT EXISTS') ? $param[5] : $param[2];
$result=zen_table_exists($table);
if ($result==true) {
zen_write_to_upgrade_exceptions_table($line, sprintf(REASON_TABLE_ALREADY_EXISTS,$table), $sql_file);
$ignore_line=true;
$result=sprintf(REASON_TABLE_ALREADY_EXISTS,$table); //duplicated here for on-screen error-reporting
break;
} else {
$line = (strtoupper($param[2].' '.$param[3].' '.$param[4]) == 'IF NOT EXISTS') ? 'CREATE TABLE IF NOT EXISTS ' . $table_prefix . substr($line, 27) : 'CREATE TABLE ' . $table_prefix . substr($line, 13);
}
break;
case (substr($line_upper, 0, 13) == 'REPLACE INTO '):
//check to see if table prefix is going to match
if (!$tbl_exists = zen_table_exists($param[2])) $result=sprintf(REASON_TABLE_NOT_FOUND,$param[2]).' 妫
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -