forked from heybige/cscart_cli_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_lib.php
168 lines (133 loc) · 4.89 KB
/
cli_lib.php
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
<?php
$php_value = phpversion();
if (version_compare($php_value, '5.3.0') == -1) {
echo 'Currently installed PHP version (' . $php_value . ') is not supported. Minimal required PHP version is 5.3.0.';
die();
}
define('AREA', 'A');
define('ACCOUNT_TYPE', 'admin');
use Tygh\Bootstrap;
use Tygh\Registry;
use Tygh\Debugger;
// Register autoloader
$this_dir = dirname(__FILE__);
$this_dir = "/home/eshop4golf";
$classLoader = require($this_dir . '/app/lib/vendor/autoload.php');
$classLoader->add('Tygh', $this_dir . '/app');
// Prepare environment and process request vars
list($_REQUEST, $_SERVER) = Bootstrap::initEnv($_GET, $_POST, $_SERVER, $this_dir);
// Get config data
$config = require(DIR_ROOT . '/config.php');
Debugger::init();
// Start debugger log
Debugger::checkpoint('Before init');
// Check if software is installed
if ($config['db_host'] == '%DB_HOST%') {
$product_name = (PRODUCT_EDITION == 'ULTIMATE' ? PRODUCT_NAME : 'Multi-Vendor');
die($product_name . ' is <b>not installed</b>. Please click here to start the installation process: <a href="install/">[install]</a>');
}
// Load core functions
$fn_list = array(
'fn.database.php',
'fn.users.php',
'fn.catalog.php',
'fn.cms.php',
'fn.cart.php',
'fn.locations.php',
'fn.common.php',
'fn.fs.php',
'fn.images.php',
'fn.init.php',
'fn.control.php',
'fn.search.php',
'fn.promotions.php',
'fn.log.php',
'fn.companies.php',
'fn.addons.php'
);
$fn_list[] = 'fn.' . strtolower(PRODUCT_EDITION) . '.php';
foreach ($fn_list as $file) {
require($config['dir']['functions'] . $file);
}
Registry::set('class_loader', $classLoader);
Registry::set('config', $config);
unset($config);
// Connect to database
if (!db_initiate(Registry::get('config.db_host'), Registry::get('config.db_user'), Registry::get('config.db_password'), Registry::get('config.db_name'))) {
fn_error('Cannot connect to the database server');
}
register_shutdown_function(array('\\Tygh\\Registry', 'save'));
// define lifetime for the cache data
date_default_timezone_set('UTC'); // setting temporary timezone to avoid php warnings
if (defined('API')) {
fn_init_stack(
array('fn_init_api')
);
}
fn_init_stack(
array('fn_init_storage'),
array('fn_init_ua')
);
if (fn_allowed_for('ULTIMATE')) {
fn_init_stack(array('fn_init_store_params_by_host', &$_REQUEST));
}
fn_init_stack(
array(array('\\Tygh\\Session', 'init'), &$_REQUEST),
array('fn_init_ajax'),
array('fn_init_company_id', &$_REQUEST),
array('fn_check_cache', $_REQUEST),
array('fn_init_settings'),
array('fn_init_addons'),
array('fn_get_route', &$_REQUEST),
array('fn_simple_ultimate', &$_REQUEST)
);
if (!fn_allowed_for('ULTIMATE:FREE')) {
fn_init_stack(array('fn_init_localization', &$_REQUEST));
}
fn_init_stack(array('fn_init_language', &$_REQUEST),
array('fn_init_currency', &$_REQUEST),
array('fn_init_company_data', $_REQUEST),
array('fn_init_full_path', $_REQUEST),
array('fn_init_layout', &$_REQUEST),
array('fn_init_user'),
array('fn_init_templater')
);
// Run INIT
fn_init($_REQUEST);
$stack = Registry::get('init_stack');
// Cleanup stack
Registry::set('init_stack', array());
foreach ($stack as $function_data) {
$function = array_shift($function_data);
if (!is_callable($function)) {
continue;
}
$result = call_user_func_array($function, $function_data);
$status = !empty($result[0]) ? $result[0] : INIT_STATUS_OK;
$url = !empty($result[1]) ? $result[1] : '';
$message = !empty($result[2]) ? $result[2] : '';
if ($status == INIT_STATUS_OK && !empty($url)) {
$redirect_url = $url;
} elseif ($status == INIT_STATUS_REDIRECT && !empty($url)) {
$redirect_url = $url;
break;
} elseif ($status == INIT_STATUS_FAIL) {
if (empty($message)) {
$message = 'Initiation failed in <b>' . (is_array($function) ? implode('::', $function) : $function) . '</b> function';
}
die($message);
}
}
/* if (!empty($redirect_url)) {
if (!defined('CART_LANGUAGE')) {
fn_init_language($request); // we need CART_LANGUAGE in fn_url function that called in fn_redirect
}
fn_redirect($redirect_url);
} */
$stack = Registry::get('init_stack');
if (!empty($stack)) {
// New init functions were added to stack. Execute them
fn_init($request);
}
Debugger::init(true);
?>