This repository has been archived by the owner on Mar 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrClient.module
191 lines (172 loc) · 5.4 KB
/
btrClient.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
<?php
/**
* @file
* Module file for btrClient.
*/
module_load_include('php', 'btrClient', 'lib/bcl');
/**
* Implements hook_init().
*/
function btrClient_init() {
// Include the stylesheets.
$path = drupal_get_path('module', 'btrClient');
drupal_add_css($path . '/css/styles.css.less');
}
/**
* Implements hook_inside_iframe().
*/
function btrClient_inside_iframe() {
$path = drupal_get_path('module', 'btrClient');
drupal_add_css($path . '/css/iframe.css.less');
}
/**
* Implements hook_menu().
*/
function btrClient_menu() {
$items = array();
$items['admin/config/bcl'] = array(
'title' => 'B-Translator Client',
'description' => 'B-Translator Client Profile',
'weight' => -100,
'page callback' => 'system_admin_menu_block_page',
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'access callback' => TRUE,
);
$items['admin/config/bcl/client'] = array(
'title' => 'BTR Client',
'description' => 'B-Translator Client configuration settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('btrClient_config'),
'access callback' => TRUE,
'file' => 'callback/admin.inc',
);
// Return a RSS feed.
$items['btr/rss-feed'] = array(
'type' => MENU_CALLBACK,
'title' => 'Latest Translation Feedback',
'page callback' => 'btrClient_rss_feed',
'file' => 'callback/rss_feed.inc',
'access callback' => TRUE,
);
// Return a random tweet from B-Translator.
$items['btr/tweet'] = array(
'type' => MENU_CALLBACK,
'title' => 'Return a random string (and translations) in a form suitable for twitter.',
'page callback' => 'btrClient_tweet',
'file' => 'callback/tweet.inc',
'access callback' => TRUE,
);
// Return a string context, related projects (where a string is found), etc.
$items['btr/ajax/string_details'] = array(
'type' => MENU_CALLBACK,
'title' => 'String details',
'page callback' => 'btrClient_string_details',
'file' => 'callback/ajax.inc',
'access callback' => TRUE,
);
return $items;
}
/**
* Implements hook_menu_alter().
*/
function btrClient_menu_alter(&$items) {
// Move the configuration of oauth2_login to the section of B-Translator.
$items['admin/config/bcl/oauth2_login'] = $items['admin/config/people/oauth2_login'];
unset($items['admin/config/people/oauth2_login']);
}
/**
* Implements hook_oauth2_profile_fields_alter().
*/
function btrClient_oauth2_profile_fields_alter(&$profile_fields) {
// Add these additional fields to the profile.
// These extra fields can be defined by the server
// on hook_oauth2_loginprovider_userprofile_alter().
$profile_fields += [
'translation_lng',
'auxiliary_languages',
'permissions',
'subscribed_projects',
'admin_projects',
'moderate_projects',
];
}
/**
* Implements hook_oauth2_user_alter().
*
* $oauth2_user is the remote user profile that comes from the server.
*/
function btrClient_oauth2_user_alter(&$oauth2_user) {
// Keep only the fields of the user profile that we are interested in.
$btr_user = [
'uid' => $oauth2_user['identifier'],
'name' => $oauth2_user['displayName'],
'translation_lng' => $oauth2_user['translation_lng'],
'auxiliary_languages' => $oauth2_user['auxiliary_languages'],
'permissions' => $oauth2_user['permissions'],
'subscribed_projects' => $oauth2_user['subscribed_projects'],
'admin_projects' => $oauth2_user['admin_projects'],
'moderate_projects' => $oauth2_user['moderate_projects'],
];
$oauth2_user = $btr_user;
}
/**
* Implementation of hook_form_alter().
*/
function btrClient_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['remote_account'] = array(
'#type' => 'fieldset',
'#title' => t('Edit the profile on B-Translator Server'),
'#weight' => -500,
'#suffix' => '<hr/>',
);
$url = variable_get('btrClient_server') . '/user/';
$form['remote_account']['link_to_btranslator_profile'] = array(
'#markup' => '<a href="' . $url . '" target="_blank" class="btn btn-default">'
. t('Edit B-Translator Profile') . '</a>',
);
}
}
/**
* Implements hook_theme().
*/
function btrClient_theme($existing, $type, $theme, $path) {
return array(
'btrClient_filter_form_element' => array(
'render element' => 'element',
),
'btrClient_translate_translation' => array(
'render element' => 'element',
),
'btrClient_translate_actions' => array(
'render element' => 'element',
),
'btrClient_in_context' => array(
'variables' => array('source' => NULL),
),
'btrClient_translate_radio' => array(
'render element' => 'element',
),
'btrClient_translate_source' => array(
'render element' => 'element',
),
'btrClient_translate_translation_list' => array(
'render element' => 'element',
),
'btrClient_translate_table' => array(
'render element' => 'element',
),
);
}
/**
* Implements hook_flush_caches().
*
* Add cache table names to the list of cache tables
* that will be cleared by the Clear button on the Performance page
* or whenever drupal_flush_all_caches is invoked.
* Returns an array of cache table names.
*/
function btrClient_flush_caches() {
return array('cache_btrClient');
}