-
Notifications
You must be signed in to change notification settings - Fork 1
/
uservoice.module
159 lines (150 loc) · 5.67 KB
/
uservoice.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
<?php
// $Id$
/**
* @file
* Configure setting for interacting with UserVoice.
*
* Adds Feedback Tab, SSO, and API interaction with the feedback service UserVoice.
*/
/**
* Implementation of hook_help().
*/
function uservoice_help($path, $arg) {
switch ($path) {
case 'admin/help#uservoice':
return t('<a href="@url">Uservoice</a> is a tool to let users suggest and vote on ideas, and report bugs. This module provides services to better integrate Drupal with Uservoice.', array('@url' => 'http://uservoice.com/'));
}
}
/**
* Implementation of hook_init().
*/
function uservoice_init() {
if (variable_get('uservoice_feedback_tab_enabled', FALSE)) {
_uservoice_create_feedback_tab();
}
}
/**
* Valid permissions for this module
* @return
* array An array of permissions for the uservoice module
*/
function uservoice_perm() {
return array('administer uservoice');
}
/**
* Implementation of hook_menu().
*/
function uservoice_menu() {
$items = array();
$items['admin/settings/uservoice'] = array(
'title' => 'UserVoice',
'description' => 'Enable and configure UserVoice settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('_uservoice_admin_settings'),
'access arguments' => array('administer uservoice'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Returns string for drupal_add_js() to pull Feedback Tab javascript from UserVoice.
*/
function _uservoice_create_feedback_tab() {
$key = variable_get('uservoice_feedback_tab_key', FALSE);
$host = variable_get('uservoice_feedback_tab_host', FALSE);
$forum = variable_get('uservoice_feedback_tab_forum', 'general');
$alignment = variable_get('uservoice_feedback_tab_alignment', 'left');
$background_color = variable_get('uservoice_feedback_tab_background_color', '#ff0000');
$text_color = variable_get('uservoice_feedback_tab_text_color', 'white');
$hover_color = variable_get('uservoice_feedback_tab_hover_color', '#0066cc');
$lang = variable_get('uservoice_feedback_tab_lang', 'en');
$js_widget_1 = <<<JS_WIDGET_1
var uservoiceJsHost = ("https:" == document.location.protocol) ? "https://uservoice.com" : "http://cdn.uservoice.com";
document.write(unescape("%3Cscript src='" + uservoiceJsHost + "/javascripts/widgets/tab.js' type='text/javascript'%3E%3C/script%3E"))
JS_WIDGET_1;
$js_widget_2 = <<<JS_WIDGET_2
UserVoice.Tab.show({
key: '$key',
host: '$host',
forum: '$forum',
alignment: '$alignment',
background_color:'$background_color',
text_color: '$text_color',
hover_color: '$hover_color',
lang: '$lang'
})
JS_WIDGET_2;
if ($key && $host) {
drupal_add_js($js_widget_1, 'inline', 'footer');
drupal_add_js($js_widget_2, 'inline', 'footer');
}
}
/**
* Settings form for administration.
*/
function _uservoice_admin_settings() {
variable_get('uservoice_feedback_tab_enabled', FALSE) ? $enabled = TRUE : $enabled = FALSE;
$form = array();
$form['uservoice_feedback_tab_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Feedback Tab.'),
'#default_value' => variable_get('uservoice_feedback_tab_enabled', FALSE),
'#description' => t('Enables the Feedback Tab on all pages.'),
);
$form['feedback_tab'] = array(
'#type' => 'fieldset',
'#title' => t('Feedback Tab settings'),
'#collapsible' => TRUE,
'#collapsed' => !$enabled,
);
$form['feedback_tab']['uservoice_feedback_tab_key'] = array(
'#type' => 'textfield',
'#title' => t('Your UserVoice subdomain'),
'#required' => $enabled,
'#default_value' => variable_get('uservoice_feedback_tab_key', ''),
);
$form['feedback_tab']['uservoice_feedback_tab_host'] = array(
'#type' => 'textfield',
'#title' => t('Your UserVoice URL'),
'#required' => $enabled,
'#default_value' => variable_get('uservoice_feedback_tab_host', ''),
'#description' => t('example.uservoice.com'),
);
$form['feedback_tab']['uservoice_feedback_tab_forum'] = array(
'#type' => 'textfield',
'#title' => t('Key for chosen Topic (aka Forum) '),
'#required' => $enabled,
'#default_value' => variable_get('uservoice_feedback_tab_forum', 'general'),
);
$form['feedback_tab']['uservoice_feedback_tab_alignment'] = array(
'#type' => 'radios',
'#title' => t('Alignment'),
'#default_value' => variable_get('uservoice_feedback_tab_alignment', 'left'),
'#options' => array('left' => t('left'), 'right' => t('right')),
);
$form['feedback_tab']['uservoice_feedback_tab_background_color'] = array(
'#type' => 'textfield',
'#title' => t('Background color'),
'#default_value' => variable_get('uservoice_feedback_tab_background_color', '#ff0000'),
'#description' => t('Hex color code. Example: #ff0000'),
);
$form['feedback_tab']['uservoice_feedback_tab_text_color'] = array(
'#type' => 'select',
'#title' => t('Text color'),
'#default_value' => variable_get('uservoice_feedback_tab_text_color', 'white'),
'#options' => array('white' => t('white'), 'black' => t('black'), 'blank' => t('blank')),
);
$form['feedback_tab']['uservoice_feedback_tab_hover_color'] = array(
'#type' => 'textfield',
'#title' => t('Hover color'),
'#default_value' => variable_get('uservoice_feedback_tab_hover_color', '#0066cc'),
'#description' => t('Hex color code. Example: #0066cc'),
);
$form['feedback_tab']['uservoice_feedback_tab_lang'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => variable_get('uservoice_feedback_tab_lang', 'en'),
'#options' => array('en' => t('English'), 'de' => t('German'), 'nl' => t('Dutch'), 'es' => t('Spanish'), 'fr' => t('French'), 'pt_BR' => t('Portuguese')),
);
return system_settings_form($form);
}