1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320:
<?php
class PHPShopBase {
var $iniPath;
var $SysValue;
var $codBase = "cp1251";
var $locale = 'ru_RU.cp1251';
var $debug = true;
var $mysql_error = null;
function __construct($iniPath, $connectdb = true, $error = true) {
$this->setPHPCoreReporting($error);
$this->iniPath = $iniPath;
$this->SysValue = parse_ini_file_true($this->iniPath, 1);
if ($this->getParam("connect.charset") != "") {
$this->codBase = $this->getParam("connect.charset");
if ($this->codBase == 'utf8')
$this->codBase = 'utf-8';
}
$this->fixUTF();
define('parser_function_allowed', $this->SysValue['function']['allowed']);
define('parser_function_deny', $this->SysValue['function']['deny']);
define('parser_function_guard', $this->SysValue['function']['guard']);
$GLOBALS['SysValue'] = &$this->SysValue;
if ($connectdb)
$this->link_db = $this->connect($connectdb);
}
function getSysValue() {
return $this->SysValue;
}
function getParam($param) {
$param = explode(".", $param);
if (count($param) > 2)
return $this->SysValue[$param[0]][$param[1]][$param[2]];
return $this->SysValue[$param[0]][$param[1]];
}
function setParam($param, $value) {
$param = explode(".", $param);
if ($param[0] == "var")
$param[0] = "other";
$GLOBALS['SysValue'][$param[0]][$param[1]] = $value;
}
function errorConnect($e = false, $message = "", $error = false) {
$message = '<strong>' . $message . '' . $error . '</em>';
if (is_dir($_SERVER['DOCUMENT_ROOT'] . '/install/') and $e != 105) {
header('Location: /install/');
}
if (function_exists('ParseTemplateReturn')) {
$GLOBALS['SysValue']['other']['message'] = $message;
$GLOBALS['SysValue']['other']['title'] = $e;
$error = ParseTemplateReturn('phpshop/lib/templates/error/error.tpl', true);
if ($GLOBALS['PHPShopBase']->codBase == 'utf-8')
$error = iconv("windows-1251", "utf-8", $error);
exit($error);
} elseif (class_exists('PHPShopObj')) {
PHPShopObj::loadClass('parser');
PHPShopParser::set('message', $message);
PHPShopParser::set('title', $e);
$error = PHPShopParser::file($_SERVER['DOCUMENT_ROOT'] . '/phpshop/lib/templates/error/error.tpl');
if ($GLOBALS['PHPShopBase']->codBase == 'utf-8')
$error = iconv("windows-1251", "utf-8", $error);
exit($error);
} else
exit($message);
}
function connect($connectdb = true) {
global $link_db;
$link_db = mysqli_connect($this->getParam("connect.host"), $this->getParam("connect.user_db"), $this->getParam("connect.pass_db")) or $this->mysql_error = mysqli_connect_error();
mysqli_select_db($link_db, $this->getParam("connect.dbase")) or $this->mysql_error .= mysqli_error($link_db);
if ($this->codBase != "utf-8")
mysqli_query($link_db, "SET NAMES '" . $this->codBase . "'");
mysqli_query($link_db, "SET SESSION sql_mode=''");
if ($connectdb and ! empty($this->mysql_error))
$this->errorConnect(101, "", $this->mysql_error);
else if (empty($this->mysql_error))
return $link_db;
}
function chekAdmin() {
require_once dirname(__FILE__) . '/../lib/phpass/passwordhash.php';
PHPShopObj::loadClass('admrule');
$this->Rule = new PHPShopAdminRule();
}
function getNumRows($from_base, $query) {
$sql = "select COUNT('id') as count from " . $this->SysValue['base'][$from_base] . " " . $query;
$result = mysqli_query($this->link_db, $sql);
$row = @mysqli_fetch_array($result);
$num = $row['count'];
return intval($num);
}
function setLocale() {
if (function_exists('setlocale') and ! empty($this->locale))
setlocale(LC_ALL, $this->locale);
}
function fixUTF() {
if (stristr(ini_get("default_charset"), "utf") and function_exists('ini_set') and $this->codBase != "utf-8") {
ini_set("default_charset", $this->codBase);
}
if (floatval(phpversion()) < 5.6) {
if (ini_get("mbstring.func_overload") > 0 and function_exists('ini_set')) {
ini_set("mbstring.internal_encoding", null);
}
}
}
function setPHPCoreReporting($error) {
if (function_exists('error_reporting')) {
if (empty($error)) {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT);
if ($this->phpversion() and function_exists('ini_set')) {
ini_set('allow_call_time_pass_reference', 1);
}
} else
error_reporting(0);
if (ini_get("short_open_tag") == 0) {
ini_set('short_open_tag', 1);
}
}
}
function phpversion($version = '5.3') {
if ((phpversion() * 1) >= $version)
return true;
}
function checkMultibase($path = '../') {
global $PHPShopSystem;
$this->LicenseParse = @parse_ini_file_true($path . 'license/' . PHPShopFile::searchFile($path . 'license/', 'getLicense', true), 1);
if (is_array($this->LicenseParse) and strstr($this->LicenseParse['License']['HardwareLocked'], 'Showcase')) {
if (getenv('SERVER_NAME') == $this->LicenseParse['License']['DomenLocked'] or getenv('SERVER_NAME') == 'www.' . $this->LicenseParse['License']['DomenLocked']) {
define("HostMain", true);
} else {
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['servers']);
$PHPShopOrm->debug = false;
$data = $PHPShopOrm->select(array('id', 'name', 'company', 'logo', 'price'), array('enabled' => "='1'", 'host' => '="' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . '"'), false, array('limit' => 1));
if (is_array($data)) {
define("HostID", intval($data['id']));
if (!empty($data['price']))
define("HostPrice", $data['price']);
if ($PHPShopSystem) {
if (!empty($data['company']))
$PHPShopSystem->setParam('company', $data['company']);
if (!empty($data['name']))
$PHPShopSystem->setParam('name', $data['name']);
if (!empty($data['logo']))
$PHPShopSystem->setParam('logo', $data['logo']);
}
}
}
}
}
}
function parse_ini_file_true($file, $process_sections) {
if (function_exists('parse_ini_file'))
return @parse_ini_file($file, $process_sections);
elseif (is_file($file))
return parse_ini_string(@file_get_contents($file), $process_sections);
}
?>