-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleasingcom_widget.module
64 lines (59 loc) · 2.58 KB
/
leasingcom_widget.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
<?php
/**
* @file
* Main Wywisyg plugin module file.
*/
define("LEASINGCOM_PLACEHOLDER_PATTERN_INNER", 'wysiwyg_leasingcom-widget-embed_plugin');
define("LEASINGCOM_PLACEHOLDER_PATTERN", '<!--' . LEASINGCOM_PLACEHOLDER_PATTERN_INNER . '-->');
/**
* Implements hook_wysiwyg_include_directory().
*/
function leasingcom_widget_wysiwyg_include_directory($type) {
return $type;
}
/**
* Implements hook_page_alter().
*/
function leasingcom_widget_page_alter(&$page) {
drupal_add_css(drupal_get_path('module', 'leasingcom_widget') . '/plugins/leasingcom_widget_embed/leasingcom_widget_embed.css');
}
/**
* Implements hook_node_view().
*/
function leasingcom_widget_node_view($node) {
if (node_is_page($node)) {
$data_cid = variable_get('leasingcom_data_cid', '0000');
// @todo Do this in a better way using Dom.
$leasing_markup = '<div id="leasingdotcom-best-deals" data-cid="' . $data_cid . '" data-financeType="Personal" data-vehicleType="Car" [data-manufacturer] [data-manufacturer-ranges]></div>
<script type="text/javascript" src="https://webapps.leasing.com/best-deals/load"></script>';
$body = $node->content['body'][0]['#markup'];
if (preg_match('/<!--leasingcom_widget_embed_plugin-(.*?)-->/', $body, $match) == 1) {
$tag_values = $match[1];
$params_array = array();
$params = $match[1];
if (preg_match('/data_manufacturer:(.*?)-data_manufacturer_ranges:/', $params, $match) == 1) {
$params_array['data_manufacturer'] = $match[1];
}
if (preg_match('/data_manufacturer_ranges:(.*)/',$params, $match) == 1) {
$params_array['data_manufacturer_ranges'] = $match[1];
}
// Data manufacturer.
if ($params_array['data_manufacturer'] != 'undefined') {
$leasing_markup = str_replace('[data-manufacturer]', 'data-manufacturer="' . $params_array['data_manufacturer'] . '"', $leasing_markup);
}
else {
$leasing_markup = str_replace('[data-manufacturer]', '', $leasing_markup);
}
// Data manufacturer ranges
if ($params_array['data_manufacturer_ranges'] != 'undefined') {
$leasing_markup = str_replace('[data-manufacturer-ranges]', 'data-manufacturerRanges="' . $params_array['data_manufacturer_ranges'] . '"', $leasing_markup);
}
else {
$leasing_markup = str_replace('[data-manufacturer-ranges]', '', $leasing_markup);
}
$full_comment = "<!--leasingcom_widget_embed_plugin-$tag_values-->";
// Add leasing markup.
$node->content['body'][0]['#markup'] = str_replace($full_comment, $leasing_markup, $node->content['body'][0]['#markup']);
}
}
}