-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvklikebutton.theme.inc
73 lines (67 loc) · 1.78 KB
/
vklikebutton.theme.inc
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
<?php
/**
* @file
* Theme function for vklikebutton.
*/
/**
* Returns field content to display.
*/
function theme_vklikebutton($conf) {
$width = $conf['width'];
$height = $conf['height'];
$type = $conf['type'];
$verb = $conf['verb'];
$appid = $conf['appid'];
$title = $conf['title'];
$description = $conf['description'];
$text = $conf['text'];
$url = $conf['url'];
$image = $conf['image'];
$page_id = $conf['page_id'];
$element_id = 'vk_like_' . $page_id;
$options = array();
if ($width) {
$options[] = 'width: "' . $width . '"';
}
if ($height) {
$options[] = 'height: "' . $height . '"';
}
if ($type) {
$options[] = 'type: "' . $type . '"';
}
if (!is_null($verb)) {
$options[] = 'verb: "' . $verb . '"';
}
if ($title) {
$options[] = 'pageTitle: "' . $title . '"';
}
if ($description) {
$options[] = 'pageDescription: "' . $description . '"';
$options[] = 'description: "' . $description . '"';
}
if ($url) {
$options[] = 'pageUrl: "' . $url . '"';
}
$options[] = 'pageImage: "' . $image . '"';
$options[] = 'image: "' . $image . '"';
if ($text) {
$options[] = 'text: "' . $text . '"';
}
$output = '<div id="' . $element_id . '"></div>';
drupal_add_js('http://vk.com/js/api/openapi.js', array(
'type' => 'external',
'weight' => '-20',
'group' => JS_LIBRARY,
), 'vklikebutton_openapi');
drupal_add_js('VK.init({apiId: ' . $appid . ', onlyWidgets: true});', array(
'type' => 'inline',
'scope' => 'header',
'weight' => '0',
'group' => JS_LIBRARY,
), 'vklikebutton_init');
drupal_add_js('VK.Widgets.Like(' . json_encode($element_id) . ', {' . implode(",\n", $options) . '}, 16' . $page_id . ');', array(
'type' => 'inline',
'scope' => 'footer',
));
return $output;
}