-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.module
135 lines (126 loc) · 3.69 KB
/
google.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
<?php
/**
* @file google.module
* Provide access to the Google APIs, should be completely configurable.
*
* @author Raymond Jelierse
*/
/**
* Implements hook_init()
*/
function google_init() {
if (variable_get('google_plusone_button_enabled', FALSE)) {
drupal_set_html_head('<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>');
}
}
/**
* Implements hook_menu()
*/
function google_menu() {
$menu = array(
'admin/settings/google' => array(
'title' => 'Google',
'description' => 'Manage the available Google APIs',
'page callback' => 'drupal_get_form',
'page arguments' => array('google_settings_form'),
'access arguments' => array('administer google configuration'),
),
'admin/settings/google/manage-apis' => array(
'title' => 'Manage',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -50,
),
'admin/settings/google/plus-one' => array(
'title' => 'Google +1',
'page callback' => 'drupal_get_form',
'page arguments' => array('google_plusone_button_settings_form'),
'access arguments' => array('administer google configuration'),
'type' => MENU_LOCAL_TASK,
'weight' => -49,
),
);
return $menu;
}
/**
* Implements hook_namespaces()
*/
function google_namespaces() {
return array(
'g' => 'http://base.google.com/ns/1.0',
'gm' => 'http://base.google.com/ns-metadata/1.0',
);
}
/**
* Implements hook_theme()
*/
function google_theme() {
return array(
'plusone_button' => array(),
);
}
/**
* General settings for the Google APIs.
*
* @return
* The settings form
*/
function google_settings_form() {
return system_settings_form(array(
'google_apis' => array(
'#type' => 'fieldset',
'#title' => t('Available APIs'),
'#collapsible' => TRUE,
'google_plusone_button_enabled' => array(
'#type' => 'checkbox',
'#title' => t('Google +1 Button'),
'#default_value' => variable_get('google_plusone_button_enabled', FALSE),
),
),
));
}
/**
* Google +1 Button settings
*
* @return
* The settings form
*/
function google_plusone_button_settings_form() {
return system_settings_form(array(
'google_plusone_button_size' => array(
'#type' => 'select',
'#title' => t('Button size'),
'#default_value' => variable_get('google_plusone_button_size', 'tall'),
'#options' => array(
'small' => t('Small'),
'medium' => t('Medium'),
'standard' => t('Standard'),
'tall' => t('Tall'),
),
),
'google_plusone_button_count' => array(
'#type' => 'checkbox',
'#title' => t('Show number of +1\'s'),
'#default_value' => variable_get('google_plusone_button_count', TRUE),
'#description' => t('Note. This setting only applies to some of the button sizes, see the <a href="@plusone-doc">documentation</a> for more information.', array('@plusone-doc' => 'http://code.google.com/apis/+1button/#button-sizes'))
),
));
}
function google_nodeapi(&$node, $operation, $data1 = NULL, $data2 = NULL) {
switch ($operation) {
case 'view':
if (variable_get('google_plusone_button_enabled', FALSE)) {
$node->content['google_plusone'] = array(
'#value' => theme('plusone_button'),
);
$node->google_plusone_rendered = drupal_render($node->content['google_plusone']);
}
break;
}
}
function theme_plusone_button() {
$content = '<g:plusone';
$content .= ' size="' . variable_get('google_plusone_button_size', 'tall') . '"';
$content .= ' count="' . (variable_get('google_plusone_button_count', TRUE) ? 'true' : 'false') . '"';
$content .= '></g:plusone>';
return $content;
}