forked from leegarner-glfusion/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoinstall.php
316 lines (259 loc) · 9.81 KB
/
autoinstall.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
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
<?php
/**
* Automatic installation functions for the Paypal plugin.
*
* @author Lee Garner <[email protected]>
* @author Mark Evans <[email protected]>
* @copyright Copyright (c) 2009-2011 Lee Garner <[email protected]>
* @copyright Copyright (c) 2009 Mark Evans <[email protected]>
* @package paypal
* @version 0.5.0
* @license http://opensource.org/licenses/gpl-2.0.php
* GNU Public License v2 or later
* @filesource
*/
if (!defined ('GVERSION')) {
die ('This file can not be used on its own.');
}
global $_DB_dbms;
/** Include plugin configuration */
require_once $_CONF['path'].'plugins/paypal/paypal.php';
/** Include database queries */
require_once $_CONF['path'].'plugins/paypal/sql/'.$_DB_dbms.'_install.php';
/** Include default values */
require_once $_CONF['path'].'plugins/paypal/install_defaults.php';
$language = $_CONF['language'];
if (!is_file($_CONF['path'].'plugins/paypal/language/' . $language . '.php')) {
$language = 'english';
}
require_once $_CONF['path'].'plugins/paypal/language/' . $language . '.php';
global $LANG_PP;
/**
* Plugin installation options
*/
$INSTALL_plugin['paypal'] = array(
'installer' => array(
'type' => 'installer',
'version' => '1',
'mode' => 'install'),
'plugin' => array(
'type' => 'plugin',
'name' => $_PP_CONF['pi_name'],
'ver' => $_PP_CONF['pi_version'],
'gl_ver' => $_PP_CONF['gl_version'],
'url' => $_PP_CONF['pi_url'],
'display' => $_PP_CONF['pi_display_name']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.ipnlog'],
'sql' => $_SQL['paypal.ipnlog']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.products'],
'sql' => $_SQL['paypal.products']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.purchases'],
'sql' => $_SQL['paypal.purchases']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.categories'],
'sql' => $_SQL['paypal.categories']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.prod_attr'],
'sql' => $_SQL['paypal.prod_attr']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.images'],
'sql' => $_SQL['paypal.images']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.orders'],
'sql' => $_SQL['paypal.orders']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.gateways'],
'sql' => $_SQL['paypal.gateways']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.address'],
'sql' => $_SQL['paypal.address']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.userinfo'],
'sql' => $_SQL['paypal.userinfo']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.cart'],
'sql' => $_SQL['paypal.cart']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.workflows'],
'sql' => $_SQL['paypal.workflows']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.buttons'],
'sql' => $_SQL['paypal.buttons']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.orderstatus'],
'sql' => $_SQL['paypal.orderstatus']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.order_log'],
'sql' => $_SQL['paypal.order_log']),
array( 'type' => 'table',
'table' => $_TABLES['paypal.currency'],
'sql' => $_SQL['paypal.currency']),
array( 'type' => 'group',
'group' => 'paypal Admin',
'desc' => 'Users in this group can administer the PayPal plugin',
'variable' => 'admin_group_id',
'admin' => true,
'addroot' => true),
array( 'type' => 'feature',
'feature' => 'paypal.admin',
'desc' => 'Ability to administer the PayPal plugin',
'variable' => 'admin_feature_id'),
array( 'type' => 'feature',
'feature' => 'paypal.user',
'desc' => 'Ability to use the PayPal plugin',
'variable' => 'user_feature_id'),
array( 'type' => 'feature',
'feature' => 'paypal.view',
'desc' => 'Ability to view PayPal entries',
'variable' => 'view_feature_id'),
array( 'type' => 'mapping',
'group' => 'admin_group_id',
'feature' => 'admin_feature_id',
'log' => 'Adding feature to the admin group'),
array( 'type' => 'mapping',
'findgroup' => 'All Users',
'feature' => 'view_feature_id',
'log' => 'Adding feature to the All Users group'),
array( 'type' => 'mapping',
'findgroup' => 'Logged-in Users',
'feature' => 'user_feature_id',
'log' => 'Adding feature to the Logged-in Users group'),
array( 'type' => 'block',
'name' => 'paypal_random',
'title' => 'Random Product',
'phpblockfn' => 'phpblock_paypal_random',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'is_enabled' => 0),
array( 'type' => 'block',
'name' => 'paypal_categories',
'title' => 'Product Categories',
'phpblockfn' => 'phpblock_paypal_categories',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'is_enabled' => 0),
array( 'type' => 'block',
'name' => 'paypal_featured',
'title' => 'Featured Products',
'phpblockfn' => 'phpblock_paypal_featured',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'is_enabled' => 0),
array( 'type' => 'block',
'name' => 'paypal_popular',
'title' => 'Popular',
'phpblockfn' => 'phpblock_paypal_popular',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'is_enabled' => 0),
array( 'type' => 'block',
'name' => 'paypal_recent',
'title' => 'Newest Items',
'phpblockfn' => 'phpblock_paypal_recent',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'is_enabled' => 0),
array( 'type' => 'block',
'name' => 'paypal_cart',
'title' => 'Shopping Cart',
'phpblockfn' => 'phpblock_paypal_cart',
'block_type' => 'phpblock',
'group_id' => 'admin_group_id',
'blockorder' => 5,
'onleft' => 1,
'is_enabled' => 1),
);
/**
* Puts the datastructures for this plugin into the glFusion database
* Note: Corresponding uninstall routine is in functions.inc
*
* @return boolean True if successful False otherwise
*/
function plugin_install_paypal()
{
global $INSTALL_plugin, $_PP_CONF;
$pi_name = $_PP_CONF['pi_name'];
$pi_display_name = $_PP_CONF['pi_display_name'];
COM_errorLog("Attempting to install the $pi_display_name plugin", 1);
$ret = INSTALLER_install($INSTALL_plugin[$pi_name]);
if ($ret > 0) {
return false;
}
return true;
}
/**
* Loads the configuration records for the Online Config Manager
*
* @return boolean true = proceed with install, false = an error occured
*/
function plugin_load_configuration_paypal()
{
global $_CONF, $_PP_CONF, $_TABLES;
// Get the group ID that was saved previously.
$group_id = (int)DB_getItem($_TABLES['groups'], 'grp_id',
"grp_name='{$_PP_CONF['pi_name']} Admin'");
return plugin_initconfig_paypal($group_id);
}
/**
* Plugin-specific post-installation function
* Creates the file download path and working area
*/
function plugin_postinstall_paypal()
{
global $_CONF, $_PP_CONF, $_PP_DEFAULTS, $_PP_SAMPLEDATA, $_TABLES;
// Create the working directory. Under private/data by default
// 0.5.0 - download path moved under tmpdir, so both are created
// here.
$paths = array(
$_PP_DEFAULTS['tmpdir'],
$_PP_DEFAULTS['tmpdir'] . 'keys',
$_PP_DEFAULTS['tmpdir'] . 'cache',
$_PP_DEFAULTS['download_path'],
);
foreach ($paths as $path) {
COM_errorLog("Creating $path");
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
if (!is_writable($path)) {
COM_errorLog("Cannot write to $path");
}
}
// Create an empty log file
if (!file_exists($_PP_CONF['logfile'])) {
$fp = fopen($_PP_CONF['logfile'], "w+");
if (!$fp) {
COM_errorLog("Failed to create logfile {$_PP_CONF['logfile']}");
} else {
fwrite($fp, "*** Logfile Created ***\n");
}
}
if (!is_writable($_PP_CONF['logfile'])) {
COM_errorLog("Can't write to {$_PP_CONF['logfile']}");
}
$pi_path = $_CONF['path'] . '/plugins/' . $_PP_CONF['pi_name'];
if (is_file($pi_path . '/config.php')) {
if (!rename($pi_path . '/config.php', $pi_path . '/config.old.php')) {
COM_errorLog("Failed to rename old config.php file. Manual intervention needed");
}
}
if (is_array($_PP_SAMPLEDATA)) {
foreach ($_PP_SAMPLEDATA as $sql) {
DB_query($sql, 1);
if (DB_error()) {
COM_errorLog("Sample Data SQL Error: $sql");
}
}
}
// Set the paypal Admin ID
$gid = (int)DB_getItem($_TABLES['groups'], 'grp_id',
"grp_name='{$_PP_CONF['pi_name']} Admin'");
if ($gid < 1)
$gid = 1; // default to Root if paypal group not found
DB_query("INSERT INTO {$_TABLES['vars']}
SET name='paypal_gid', value=$gid");
}
?>