-
Notifications
You must be signed in to change notification settings - Fork 6
/
bpi.module
761 lines (658 loc) · 21.4 KB
/
bpi.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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
<?php
/**
* @file
* BPI main module file.
*
* Defines BPI specific constants, menu, theme and node hooks.
*/
/**
* URL search query key.
*/
define('BPI_SEARCH_PHRASE_KEY', 'text');
/**
* Ascending sorting identifier.
*/
define('BPI_SORT_ASCENDING', 'asc');
/**
* Descending sorting identifier.
*/
define('BPI_SORT_DESCENDING', 'desc');
/**
* Syndicated node identifier.
*/
define('BPI_SYNDICATED', 1);
/**
* Pushed node identifier.
*/
define('BPI_PUSHED', 2);
/**
* Default number of BPI content per page when searching.
*/
define('BPI_CONTENT_PER_PAGE', 10);
/**
* Default number of BPI content per page when searching.
*/
define('BPI_DATE_PICKER_FORMAT', 'Y-m-d');
/**
* Default number of BPI content per page when searching.
*/
define('BPI_ONE_MONTH', 86400 * 30);
/**
* Implements hook_menu().
*/
function bpi_menu() {
$menu = array();
$menu['admin/bpi'] = array(
'title' => 'BPI syndication',
'description' => 'Syndicate content from the well.',
'page callback' => 'drupal_get_form',
'page arguments' => array('bpi_syndicate_page_form'),
'access arguments' => array('bpi syndicate content'),
'file' => 'bpi.syndicate.inc',
);
$menu['admin/bpi/preview/%/%'] = array(
'page callback' => 'admin_bpi_preview_ajax_callback',
'page arguments' => array(3, 4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'bpi.preview.inc',
);
$menu['admin/bpi/syndicate/%'] = array(
'page callback' => 'bpi_syndicate_action',
'page arguments' => array(3),
'access arguments' => array('bpi syndicate content'),
'file' => 'bpi.syndicate.inc',
);
$menu['admin/bpi/push_http/%'] = array(
'title' => 'Push to BPI',
'page arguments' => array(3),
'page callback' => 'bpi_http_push_action',
'access arguments' => array('bpi push content'),
'file' => 'bpi.push.inc',
);
$menu['admin/bpi/push/nojs/%'] = array(
'title' => 'Push to BPI',
'page callback' => 'bpi_push_action',
'page arguments' => array(3, 4),
'access arguments' => array('bpi push content'),
'file' => 'bpi.push.inc',
);
$menu['admin/bpi/push/ajax/%'] = array(
'delivery callback' => 'ajax_deliver',
) + $menu['admin/bpi/push/nojs/%'];
$menu['admin/bpi/delete/nojs/%node'] = array(
'title' => 'Delete from BPI',
'page callback' => 'bpi_delete_action',
'page arguments' => array(3, 4),
'access arguments' => array('delete bpi content'),
'file' => 'bpi.delete.inc',
);
$menu['admin/bpi/delete/ajax/%node'] = array(
'delivery callback' => 'ajax_deliver',
) + $menu['admin/bpi/delete/nojs/%node'];
$menu['admin/bpi/statistics/nojs'] = array(
'page callback' => 'bpi_statistics',
'page arguments' => array(3),
'access arguments' => array('view bpi statistics'),
'file' => 'bpi.statistics.inc',
);
$menu['admin/bpi/statistics/ajax'] = array(
'delivery callback' => 'ajax_deliver',
) + $menu['admin/bpi/statistics/nojs'];
$menu['admin/bpi/images/nojs'] = array(
'page callback' => 'bpi_syndicate_images',
'page arguments' => array(3),
'access arguments' => array('bpi syndicate content'),
'file' => 'bpi.images.inc',
);
$menu['admin/bpi/images/ajax'] = array(
'delivery callback' => 'ajax_deliver',
) + $menu['admin/bpi/images/nojs'];
$menu['admin/config/bpi'] = array(
'title' => 'BPI',
'description' => 'BPI Related Settings',
'access arguments' => array('administer bpi'),
'page callback' => 'bpi_admin_menu_block_page',
'page arguments' => array(),
'file' => 'bpi.admin.inc',
);
$menu['admin/config/bpi/settings'] = array(
'title' => 'Service settings',
'description' => 'BPI integration settings',
'access arguments' => array('administer bpi'),
'page callback' => 'drupal_get_form',
'page arguments' => array('bpi_admin_settings_form'),
'file' => 'bpi.admin.inc',
);
$menu['admin/config/bpi/content_mapping'] = array(
'title' => 'Content mapping',
'description' => 'Map BPI fields to your content fields.',
'access arguments' => array('administer bpi'),
'page callback' => 'drupal_get_form',
'page arguments' => array('bpi_admin_content_mapping_form'),
'file' => 'bpi.admin.inc',
);
return $menu;
}
/**
* Implements hook_permission().
*/
function bpi_permission() {
$perm = array();
$perm['administer bpi'] = array(
'title' => t('Administer BPI settings'),
);
$perm['bpi syndicate content'] = array(
'title' => t('Syndicate content'),
);
$perm['bpi push content'] = array(
'title' => t('Push content'),
);
$perm['view bpi statistics'] = array(
'title' => t('View statistics'),
);
$perm['delete bpi content'] = array(
'title' => t('Delete from bpi'),
);
return $perm;
}
/**
* Implements hook_theme().
*/
function bpi_theme($existing, $type, $theme, $path) {
$hooks = array();
$hooks['bpi_filter_item'] = array(
'variables' => array(),
'path' => $path . '/templates/',
'template' => 'bpi-filter-item',
);
$hooks['bpi_preview_item'] = array(
'variables' => array(),
'path' => $path . '/templates/',
'template' => 'bpi-preview-item',
);
$hooks['bpi_search_results'] = array(
'variables' => array('items' => array()),
'file' => 'bpi.syndicate.inc',
);
return $hooks;
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*
* Set some default values for the fields, when syndicating content,
* according to mapped settings.
*/
function bpi_form_node_form_alter(&$form, &$form_state, $form_id) {
$bpi_ctype = variable_get('bpi_content_type', '');
if (empty($bpi_ctype)) {
return;
}
$bpi_id = isset($_GET['bpi_id']) ? (string) $_GET['bpi_id'] : FALSE;
// Checking nid for NULL would say that this is create node form, not edit.
if ($form_id == $bpi_ctype . '_node_form' && $form['nid']['#value'] == NULL && $bpi_id) {
$form_state['node']->bpi_id = $bpi_id;
try {
$bpi = bpi_client_instance();
$bpi_node = $bpi->getNode($bpi_id);
$bpi_content = $bpi_node->getProperties();
$bpi_assets = $bpi_node->getAssets();
drupal_set_message(
t(
'Syndicating content <strong>@title</strong>, from category <strong>@category</strong> and audience <strong>@audience</strong>.',
array(
'@title' => $bpi_content['title'],
'@category' => $bpi_content['category'],
'@audience' => $bpi_content['audience'],
)
)
);
}
catch (Exception $e) {
watchdog_exception('bpi', $e);
drupal_set_message(
t('Failed to fetch the article from BPI well.'),
'error'
);
return;
}
$form['title']['#default_value'] = isset($bpi_content['title']) ? $bpi_content['title'] : '';
$teaser = variable_get('bpi_field_teaser', '');
$body = variable_get('bpi_field_body', '');
$materials_field = variable_get('bpi_field_materials', '');
$current_language = $form['language']['#value'];
if (module_exists('ting_reference') && isset($bpi_content['material'])) {
foreach ((array) $bpi_content['material'] as $key => $material_number) {
$form[$materials_field][$current_language][$key] = array();
$form[$materials_field][$current_language][$key] = ting_reference_field_widget_form(
$form,
$form_state,
$materials_field,
array(),
$current_language,
array(),
0,
$form[$materials_field][$current_language][$key]
);
// Overwrite agency id by local value.
$number_parts = explode(':', $material_number);
$form[$materials_field][$current_language][$key]['#default_value'] = variable_get('bpi_agency_id', '') . ':' . $number_parts[1];
}
}
// Guessing where to put 'teaser' text in the form.
$bpi_teaser = isset($bpi_content['teaser']) ? $bpi_content['teaser'] : '';
if (isset($form[$teaser][$current_language][0]['summary'])) {
$form[$teaser][$current_language][0]['summary']['#default_value'] = $bpi_teaser;
}
elseif (isset($form[$teaser][$current_language][0]['value'])) {
$form[$teaser][$current_language][0]['value']['#default_value'] = $bpi_teaser;
}
elseif (isset($form[$teaser][$current_language][0])) {
$form[$teaser][$current_language][0]['#default_value'] = $bpi_teaser;
}
// Guessing where to put 'body' text in the form.
$bpi_body = isset($bpi_content['body']) ? $bpi_content['body'] : '';
if (isset($form[$body][$current_language][0]['value'])) {
$form[$body][$current_language][0]['value']['#default_value'] = $bpi_body;
}
elseif (isset($form[$body][$current_language][0])) {
$form[$body][$current_language][0]['#default_value'] = $bpi_body;
}
if ($bpi_id) {
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'jquery.form');
drupal_add_library('system', 'ui.dialog');
drupal_add_js(drupal_get_path('module', 'bpi') . '/js/bpi.scripts.js', 'file');
drupal_add_js(drupal_get_path('module', 'ding_popup') . '/ding_popup.js', 'file');
drupal_add_css(drupal_get_path('module', 'bpi') . '/css/bpi-admin.styles.css', 'file');
$_SESSION['bpi']['assets'] = $bpi_assets;
}
}
// Add "Save & Push" button.
if ($form_id == $bpi_ctype . '_node_form' && !$bpi_id) {
$push_permission = user_access('bpi push content');
if ($push_permission) {
$form['actions']['push'] = $form['actions']['submit'];
$form['actions']['push']['#value'] = t('Save and push');
$form['actions']['push']['#submit'][] = 'bpi_push_directly_callback_action';
}
}
}
/**
* Implements hook_form_ID_alter().
*
* Adds BPI specific labels and actions to content items.
*/
function bpi_form_node_admin_content_alter(&$form, &$form_state) {
$form['#attached']['css'][] = drupal_get_path('module', 'bpi') . '/css/bpi-admin.styles.css';
drupal_add_library('system', 'drupal.ajax');
// Mark BPI nodes.
$nodes_in_table = array_keys($form['admin']['nodes']['#options']);
$bpi_nodes = bpi_get_bpi_nodes($nodes_in_table);
if (!empty($nodes_in_table)) {
$nodes_to_mark = array_keys($bpi_nodes);
foreach ($form['admin']['nodes']['#options'] as $node_id => &$row) {
if (in_array($node_id, $nodes_to_mark)) {
$row['title']['data']['#suffix'] .= '<sup class="bpi-marker">BPI</sup>';
}
}
}
// BPI filter.
if (isset($form['filter']['filters']['status']['filters'])) {
$current_bpi_filter = isset($_SESSION['bpi']['filter']) ? $_SESSION['bpi']['filter'] : 'all';
$bpi_filters = array(
'all' => t('any'),
'bpi_only' => t('BPI only'),
'bpi_syndicated' => t('Syndicated'),
'bpi_pushed' => t('Pushed'),
);
$form['filter']['filters']['status']['filters']['bpi'] = array(
'#type' => 'select',
'#title' => t('bpi'),
'#options' => $bpi_filters,
'#default_value' => $current_bpi_filter,
);
// It's viable that this module hooks, are fired before the standard ones.
array_unshift($form['#submit'], '_bpi_node_admin_content_submit');
// If a BPI filter is set, prepend an active BPI filter marker.
if ($current_bpi_filter != 'all') {
$drupal_filters = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
$t_args = array(
'%property' => 'bpi',
'%value' => $bpi_filters[$current_bpi_filter],
);
$bpi_filter_marker['#markup'] = t('where %property is %value', $t_args);
// Whether there are some filters active, prepend a plural form.
if (count($drupal_filters)) {
$bpi_filter_marker['#prefix'] = t('and') . ' ';
}
// Add a BPI filter marker to active filters.
$form['filter']['filters']['current'][] = $bpi_filter_marker;
// Add standard filter buttons,
// since those are showed only if drupal filters array is not empty.
$filter_actions = &$form['filter']['filters']['status']['actions'];
$filter_actions['submit']['#value'] = t('Refine');
$filter_actions['undo'] = array('#type' => 'submit', '#value' => t('Undo'));
$filter_actions['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
}
}
// Content grid columns.
$form['admin']['nodes']['#header']['bpi_timestamp'] = t('BPI import/export');
// Cheat!
// Make the operations column last.
$tmp = $form['admin']['nodes']['#header']['operations'];
unset($form['admin']['nodes']['#header']['operations']);
$form['admin']['nodes']['#header']['operations'] = $tmp;
foreach ($form['admin']['nodes']['#options'] as $key => &$row) {
$row['bpi_timestamp'] = '';
if (in_array($key, $nodes_to_mark)) {
$row['bpi_timestamp'] = format_date($bpi_nodes[$key]->timestamp, 'short');
}
// Cheat!
// Make the operations column value last.
$tmp = $row['operations'];
unset($row['operations']);
$row['operations'] = $tmp;
$push_permission = user_access('bpi push content');
// Adds a push link to operations.
if ($push_permission && bpi_push_available($key)) {
$row['operations']['data']['#links']['push'] = array(
'title' => t('push'),
'href' => 'admin/bpi/push/nojs/' . $key,
'attributes' => array(
'class' => array(
'use-ajax',
),
),
);
}
$delete_permission = bpi_ability($key, 'delete');
// Adds a delete from bpi link.
if ($delete_permission && isset($bpi_nodes[$key]) && $bpi_nodes[$key]->status == BPI_PUSHED) {
$row['operations']['data']['#links']['delete_from_bpi'] = array(
'title' => t('delete from bpi'),
'href' => 'admin/bpi/delete/nojs/' . $key,
'attributes' => array(
'class' => array(
'use-ajax',
),
)
);
}
}
}
/**
* Implements hook_form_ID_alter().
*
* Add ajax submit handler.
*/
function bpi_form_bpi_push_form_alter(&$form, &$form_state) {
$form['actions']['submit']['#ajax'] = array(
'callback' => 'bpi_push_action_ajax_callback',
);
}
/**
* Implements hook_form_ID_alter().
*
* Add ajax submit handler.
*/
function bpi_form_bpi_delete_form_alter(&$form, &$form_state) {
$form['actions']['submit']['#ajax'] = array(
'callback' => 'bpi_delete_action_ajax_callback',
);
}
/**
* Custom submit form for "Save and Push" function.
*
* @param array $form
* Form structure.
* @param array $form_state
* Form state values.
*/
function bpi_push_directly_callback_action(&$form, &$form_state) {
// Reset destination.
unset($_GET['destination']);
drupal_static_reset('drupal_get_destination');
$_GET['destination'] = 'admin/bpi/push_http/' . $form_state['node']->nid;
}
/**
* Custom submit handler for the node filtering form.
*
* Since drupal has a hardcoded set of node filters, save the new
* BPI related filter separately.
* Also, munge the standard filter actions above BPI filtering.
*
* @param array $form
* Form structure.
* @param array $form_state
* Form state values.
*/
function _bpi_node_admin_content_submit(&$form, &$form_state) {
$bpi_filter = $form_state['input']['bpi'];
$op = $form_state['input']['op'];
// These are standard filter actions.
// Due to specific BPI filter nature, handle standard actions here.
if ($op == 'Reset') {
unset($_SESSION['bpi']['filter']);
}
elseif ($op == 'Undo' && !empty($_SESSION['bpi']['filter'])) {
// Cheat!
// Let the drupal filters know that there is a BPI filter, but in
// real it's kept in this module.
// Since BPI filter will always be shown as last, it will pop a filter stub
// from self array, and here we kill the actual bpi filter.
$_SESSION['node_overview_filter'][] = '';
unset($_SESSION['bpi']['filter']);
}
elseif ($op == 'Filter' || $op == 'Refine') {
$_SESSION['bpi']['filter'] = $bpi_filter;
}
}
/**
* Returns proper permission.
*
* @global object $user
* Current user object.
* @param int $nid
* Node id.
* @param string $op
* Operation to check permissions for.
* @return boolean
* Status.
*/
function bpi_ability($nid, $op) {
global $user;
$node = node_load($nid);
$ability = FALSE;
// Check for ownership.
if (is_object($node)) {
if ($node->uid == $user->uid) {
$ability = TRUE;
}
}
switch ($op) {
case 'push':
return $ability && bpi_push_available($nid);
break;
case 'delete':
break;
}
return $ability;
}
/**
* Implements hook_node_insert().
*
* Act on node insert, and if it was created through syndication,
* write a record about it.
*/
function bpi_node_insert($node) {
if (!empty($node->bpi_id)) {
try {
$bpi = bpi_client_instance();
$bpi->syndicateNode($node->bpi_id);
db_merge('bpi_syndicated')
->fields(array(
'nid' => $node->nid,
'bid' => $node->bpi_id,
'status' => BPI_SYNDICATED,
'timestamp' => time(),
))
->condition('nid', $node->nid, '=')
->execute();
}
catch (Exception $e) {
watchdog_exception('bpi', $e);
drupal_set_message(t('Syndication error, node was not created. Check reports for more information.'), 'error');
// We should prevent creation of node due to handled exception.
// Maybe there is better solution than deletetion of newly created node.
node_delete($node->nid);
}
}
}
/**
* Implements hook_node_load().
*
* Enrich node object with bpi_id, if any.
*/
function bpi_node_load($nodes) {
$nids = array_keys($nodes);
$result = db_select('bpi_syndicated', 'bs')
->fields('bs', array(
'nid', 'bid'
))
->condition('nid', $nids, 'IN')
->execute()
->fetchAllAssoc('nid');
foreach ($nodes as $nid => &$node) {
if (isset($result[$nid])) {
$node->bpi_id = $result[$nid]->bid;
}
}
}
/**
* Implements hook_query_alter().
*
* Alters the query for node retrieval in the content grid,
* so it now takes into account the BPI filtering settings.
*/
function bpi_query_alter($query) {
$filter = isset($_SESSION['bpi']['filter']) ? $_SESSION['bpi']['filter'] : 'all';
$available_filters = array('bpi_only', 'bpi_syndicated', 'bpi_pushed');
// Alter the pagination query.
if ($query->hasTag('tablesort')) {
$tables = &$query->getTables();
// In any case, when BPI filter is used, attach the BPI table.
if (in_array($filter, $available_filters)) {
$tables['bs'] = array(
'join type' => 'INNER',
'table' => 'bpi_syndicated',
'alias' => 'bs',
'condition' => 'bs.nid = n.nid',
'arguments' => array(),
);
}
}
// Alter the content query.
if ($query->hasTag('node_load_multiple')) {
$tables = &$query->getTables();
$conditions = &$query->conditions();
// In any case, when BPI filter is used, attach the BPI table.
if (in_array($filter, $available_filters)) {
$tables['bs'] = array(
'join type' => 'INNER',
'table' => 'bpi_syndicated',
'alias' => 'bs',
'condition' => 'bs.nid = base.nid',
'arguments' => array(),
);
}
if ($filter == 'bpi_syndicated') {
$conditions[] = array(
'field' => 'bs.status',
'value' => BPI_SYNDICATED,
'operator' => '=',
);
}
elseif ($filter == 'bpi_pushed') {
$conditions[] = array(
'field' => 'bs.status',
'value' => BPI_PUSHED,
'operator' => '=',
);
}
}
}
/**
* Get the node id's which were actually syndicated/pushed from/to bpi.
*
* @param array/int $nodes
* An array of node id's or a single id.
* @return
* An array of node id's matching the criteria.
*/
function bpi_get_bpi_nodes($nodes) {
$query = db_select('bpi_syndicated', 'bs')
->fields('bs', array('nid', 'bid', 'timestamp', 'status',));
if (is_array($nodes) && count($nodes) > 0) {
$query->condition('nid', $nodes, 'IN');
}
elseif (is_numeric($nodes)) {
$query->condition('nid', $nodes, '=');
}
$result = $query
->execute()
->fetchAllAssoc('nid');
return $result;
}
/**
* Check if a node can be actually pushed.
*
* @param int $nid
* Node id.
* @return boolean
* TRUE/FALSE whether the node can be pushed.
*/
function bpi_push_available($nid) {
// No nid given.
if (empty($nid)) {
return FALSE;
}
$node = node_load($nid);
// Node not found.
if ($node === FALSE) {
return FALSE;
}
$mapped_type = variable_get('bpi_content_type', '');
// Allow pushing of nodes, to which bpi was mapped in the BE.
if ($node->type != $mapped_type) {
return FALSE;
}
$result = db_select('bpi_syndicated', 'bs')
->fields('bs', array('nid', 'timestamp', 'status'))
->condition('nid', $nid, '=')
->execute()
->fetchAllAssoc('nid');
// A node can be pushed if it is either:
// - new to BPI
// - has been syndicated (not pushed)
// - has been modified after the last push
$bpi_action = isset($result[$nid]);
$was_pushed = ($bpi_action && $result[$nid]->status == BPI_PUSHED);
$modified_after_push = $was_pushed && ($node->changed > $result[$nid]->timestamp);
$can_be_pushed = (!$was_pushed || $modified_after_push || !$bpi_action);
return $can_be_pushed;
}
/**
* Creates new Bpi client instance.
* It shouldn't behave as singleton.
*
* @return Bpi
* Webservice client.
*/
function bpi_client_instance() {
$endpoint = variable_get('bpi_service_url', '');
$agency_id = variable_get('bpi_agency_id', '');
$api_key = variable_get('bpi_api_key', '');
$secret_key = variable_get('bpi_secret_key', '');
return new Bpi($endpoint, $agency_id, $api_key, $secret_key);
}