-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlc_connector.module
444 lines (406 loc) · 12.9 KB
/
lc_connector.module
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<?php
// vim: set ts=4 sw=4 sts=4 et ft=php:
/**
* @file
* General module functionality
*
* @category Litecommerce connector
* @package Litecommerce connector
* @author Creative Development LLC <[email protected]>
* @copyright Copyright (c) 2011 Creative Development LLC <[email protected]>. All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @link http://www.litecommerce.com/
* @since 1.0.0
*/
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', TRUE);
/**
* Module initialization
*
* @hook init
* @return void
* @since 1.0.0
*/
function lc_connector_init() {
return LCConnector_Handler::callSafely('Module', 'invokeHookInit');
}
/**
* Navigation menu access point declaration
*
* @hook menu
* @return array
* @since 1.0.0
*/
function lc_connector_menu() {
return array(
'admin/modules/lc_connector' => array(
'title' => 'LC Connector',
'description' => 'Settings for the LC connector module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('lc_connector_get_settings_form'),
'access arguments' => array('administer users'),
'file' => 'lc_connector.admin.inc',
),
) + ((array) LCConnector_Handler::callSafely('Module', 'invokeHookMenu'));
}
/**
* Modify admin area form for new widget
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_block_add_block_form_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterWidgetModifyForm', array(&$form, &$form_state));
}
/**
* Modify admin area form for existing widget
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_block_admin_configure_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterWidgetModifyForm', array(&$form, &$form_state));
}
/**
* Modify admin area form for widget delete confirmation
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_custom_block_delete_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterWidgetDeleteForm', array(&$form, &$form_state));
}
/**
* Change block definition before saving to the database
*
* @param array $blocks A multidimensional array of blocks keyed by the defining module and delta
* @param string $theme The theme these blocks belong to
* @param array $code_blocks The blocks as defined in hook_block_info() before being overwritten by the database data
*
* @hook block_info_alter
* @return void
* @since 1.0.0
*/
function lc_connector_block_info_alter(array &$blocks, $theme, array $code_blocks) {
return LCConnector_Handler::callSafely('Admin', 'alterBlockInfo', array(&$blocks, $theme, $code_blocks));
}
/**
* Modify block content
*
* @param array &$data Data returned from the hook_block_view()
* @param \stdClass $form_state Block object loaded from the database
*
* @hook block_view_alter
* @return void
* @since 1.0.0
*/
function lc_connector_block_view_alter(array &$data, \stdClass $block) {
$settings = block_custom_block_get($block->delta);
if (!empty($settings['lc_class']) && !LCConnector_Handler::callSafely('Block', 'setBlockContent', array(&$data, $block))) {
$data['content'] = NULL;
}
}
/**
* Preprocess theme variables for a specific theme block
*
* @param array &$variables The variables array (modify in place)
*
* @hook preprocess_block
* @return void
* @since 1.0.0
*/
function lc_connector_preprocess_block(array &$variables) {
$settings = block_custom_block_get($variables['block']->delta);
// Inject a CSS class for blocks generated by LiteCommerce
if (!empty($settings['lc_class'])) {
LCConnector_Handler::callSafely('Block', 'addCSSClass', array(&$variables, $settings['lc_class']));
}
}
/**
* A user account is about to be created or updated
*
* @param array $edit The array of form values submitted by the user
* @param \stdClass $account The user object on which the operation is performed
* @param mixed $category The active category of user information being edited
*
* @hook user_presave
* @return void
* @since 1.0.0
*/
function lc_connector_user_presave(array &$edit, \stdClass $account, $category) {
return LCConnector_Handler::callSafely('Profile', 'performAction', array('presave', &$edit, $account, $category));
}
/**
* A user account was created
*
* @param array $edit The array of form values submitted by the user
* @param \stdClass $account The user object on which the operation is performed
* @param mixed $category The active category of user information being edited
*
* @hook user_insert
* @return void
* @since 1.0.0
*/
function lc_connector_user_insert(array &$edit, \stdClass $account, $category) {
$account->passwd = LCConnector_Handler::getVariable('passwd');
return LCConnector_Handler::callSafely('Profile', 'performAction', array('insert', &$edit, $account, $category));
}
/**
* A user account was updated
*
* @param array $edit The array of form values submitted by the user
* @param \stdClass $account The user object on which the operation is performed
* @param mixed $category The active category of user information being edited
*
* @hook user_update
* @return void
* @since 1.0.0
*/
function lc_connector_user_update(array &$edit, \stdClass $account, $category) {
$account->passwd = LCConnector_Handler::getVariable('passwd');
return LCConnector_Handler::callSafely('Profile', 'performAction', array('update', &$edit, $account, $category));
}
/**
* A user account was cancelled
*
* @param array $edit The array of form values submitted by the user
* @param \stdClass $account The user object on which the operation is performed
* @param mixed $category The active category of user information being edited
*
* @hook user_cancel
* @return void
* @since 1.0.0
*/
function lc_connector_user_cancel(array $edit, \stdClass $account, $category) {
return LCConnector_Handler::callSafely('Profile', 'performAction', array('cancel', &$edit, $account, $category));
}
/**
* A user account was deleted
*
* @param \stdClass $account The user object on which the operation is performed
*
* @hook user_delete
* @return void
* @since 1.0.0
*/
function lc_connector_user_delete($account) {
$edit = array();
return LCConnector_Handler::callSafely('Profile', 'performAction', array('delete', &$edit, $account, NULL));
}
/**
* A role deleted
*
* @param \stdClass $role The role object on which the operation is performed
*
* @hook user_role_delete
* @return void
* @since 1.0.0
*/
function lc_connector_user_role_delete($role) {
$roles = array($role);
return LCConnector_Handler::callSafely('Profile', 'performAction', array('deleteRole', &$roles, new \stdClass(), NULL));
}
/**
* The user just logged in
*
* @param array $edit The array of form values submitted by the user
* @param \stdClass $account The user object on which the operation is performed
* @param mixed $category The active category of user information being edited
*
* @hook user_login
* @return void
* @since 1.0.0
*/
function lc_connector_user_login(array &$edit, \stdClass $account, $category) {
return LCConnector_Handler::callSafely('Profile', 'performAction', array('login', &$edit, $account, $category));
}
/**
* The user just logged out
*
* @param \stdClass $account The user object on which the operation is performed
*
* @hook user_logout
* @return void
* @since 1.0.0
*/
function lc_connector_user_logout(\stdClass $account) {
$edit = array();
return LCConnector_Handler::callSafely('Profile', 'performAction', array('logout', &$edit, $account, NULL));
}
/**
* Modify login form
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_user_login_block_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Customer', 'alterLoginForm', array(&$form, &$form_state));
}
/**
* Perform necessary alterations to the JavaScript before it is presented on the page
*
* @param array &$javascript An array of all JavaScript being presented on the page
*
* @hook js_alter
* @return void
* @since 1.0.0
*/
function lc_connector_js_alter(array &$javascript) {
return LCConnector_Handler::callSafely('Module', 'optimizeJSFiles', array(&$javascript));
}
/**
* Perform necessary alterations to the CSS before it is presented on the page
*
* @param array &$css An array of all CSS being presented on the page
*
* @hook css_alter
* @return void
* @since 1.0.0
*/
function lc_connector_css_alter(array &$css) {
return LCConnector_Handler::callSafely('Module', 'optimizeCSSFiles', array(&$css));
}
/**
* Alters outbound URLs
*
* @param string &$path The outbound path to alter
* @param array &$options A set of URL options
* @param string $original_path The original path, before being altered by any modules
*
* @hook url_outbound_alter
* @return void
* @since 1.0.0
*/
function lc_connector_url_outbound_alter(&$path, array &$options, $original_path) {
LCConnector_Handler::callSafely('Module', 'translateOutboundURL', array(&$path, &$options, $original_path));
}
/**
* Alters inbound URLs
*
* @param string &$path Path
* @param string $original_path Original path
* @param string $path_language Path language
*
* @hook url_inbound_alter
* @return void
* @since 1.0.0
*/
function lc_connector_url_inbound_alter(&$path, $original_path, $path_language) {
LCConnector_Handler::callSafely('Module', 'translateInboundURL', array(&$path, $original_path, $path_language));
}
/**
* Process cron tasks
*
* @hook cron
* @return void
* @since 1.0.0
*/
function lc_connector_cron() {
LCConnector_Handler::callSafely('Module', 'runCronTasks');
}
/**
* Returns lc_connector specific permissions
*
* @hook permission
* @return array
* @since 1.0.0
*/
function lc_connector_permission() {
return array('lc admin' => array('title' => t('LiteCommerce administrator')));
}
/**
* Add additional processor on submit to the form
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_user_profile_form_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterUserProfileForm', array(&$form, &$form_state));
}
/**
* Add additional processor on submit to the form
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_user_register_form_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterUserRegisterForm', array(&$form, &$form_state));
}
/**
* Update variables array passed to the template
*
* @param array &$variables Array of variables
*
* @hook template_process_page
* @return void
* @since 1.0.0
*/
function lc_connector_process_page(array &$variables) {
return LCConnector_Handler::callSafely('Controller', 'updateTemplateVars', array(&$variables));
}
/**
* Update meta tags array passed to the template
*
* @param array &$elements Array of meta tags
*
* @hook html_head_alter
* @return void
* @since 1.0.0
*/
function lc_connector_html_head_alter(array &$elements) {
LCConnector_Handler::callSafely('Controller', 'updateMetaTags', array(&$elements));
}
/**
* Add additional processor on submit to the form
*
* @param array &$form Form description
* @param array &$form_state Form state
*
* @hook form_FORM_ID_alter
* @return void
* @since 1.0.0
*/
function lc_connector_form_user_admin_permissions_alter(array &$form, array &$form_state) {
return LCConnector_Handler::callSafely('Admin', 'alterUserPermissionsForm', array(&$form, &$form_state));
}
/**
* Check access for current LC controller
*
* FIXME: Drupal calls this function before the module is initialized.
* So, we cannot move it into the "Include/Callbacks.php".
* See: http://drupal.org/node/928160
*
* TODO: check if we can call LC methods here.
* Or the initialization is not required.
* Or it's not needed to check anything here at all
*
* @return boolean
* @since 1.0.0
*/
function lc_connector_check_controller_access() {
return is_null($result = LCConnector_Handler::callSafely('Controller', 'checkAccess')) ? TRUE : $result;
}