This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtrClient.module
210 lines (189 loc) · 5.98 KB
/
qtrClient.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* @file
* Module file for qtrClient.
*/
module_load_include('php', 'qtrClient', 'lib/qcl');
module_load_include('inc', 'qtrClient', 'blocks/blocks');
/**
* Implements hook_init().
*/
function qtrClient_init() {
// Include the stylesheets.
$path = drupal_get_path('module', 'qtrClient');
drupal_add_css($path . '/css/styles.css.less');
}
/**
* Implements hook_inside_iframe().
*/
function qtrClient_inside_iframe() {
$path = drupal_get_path('module', 'qtrClient');
drupal_add_css($path . '/css/iframe.css.less');
}
/**
* Implements hook_menu().
*/
function qtrClient_menu() {
$items = array();
$items['admin/config/qcl'] = array(
'title' => 'Q-Translate Client',
'description' => 'Q-Translate 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/qcl/client'] = array(
'title' => 'BTR Client',
'description' => 'Q-Translate Client configuration settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('qtrClient_config'),
'access callback' => TRUE,
'file' => 'callback/admin.inc',
);
// Get Translations.
$items['qtr'] = array(
'type' => MENU_NORMAL_ITEM,
'title' => 'Translations',
'description' => 'Get a verse and its translations.',
'page callback' => 'qtrClient_translations',
'file' => 'callback/translations.inc',
'access callback' => TRUE,
);
// Search Translations.
$items['qtr/search'] = array(
'type' => MENU_NORMAL_ITEM,
'title' => 'Search',
'description' => 'Search verses and translations using various filters.',
'page callback' => 'qtrClient_search',
'file' => 'callback/search.inc',
'access callback' => TRUE,
'weight' => 2,
);
// Return a RSS feed.
$items['qtr/rss-feed'] = array(
'type' => MENU_CALLBACK,
'title' => 'Latest Translation Feedback',
'page callback' => 'qtrClient_rss_feed',
'file' => 'callback/rss_feed.inc',
'access callback' => TRUE,
);
// Return a random translation tweet from Q-Translate.
$items['qtr/tweet'] = array(
'type' => MENU_CALLBACK,
'title' => 'Return a random translation in a form suitable for twitter.',
'page callback' => 'qtrClient_tweet',
'file' => 'callback/tweet.inc',
'access callback' => TRUE,
);
return $items;
}
/**
* Implements hook_menu_alter().
*/
function qtrClient_menu_alter(&$items) {
// Move the configuration of oauth2_login to the section of Q-Translate.
$items['admin/config/qcl/oauth2_login'] = $items['admin/config/people/oauth2_login'];
unset($items['admin/config/people/oauth2_login']);
}
/**
* Implements hook_oauth2_profile_fields_alter().
*/
function qtrClient_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',
'permissions',
];
}
/**
* Implements hook_oauth2_user_alter().
*
* $oauth2_user is the remote user profile that comes from the server.
*/
function qtrClient_oauth2_user_alter(&$oauth2_user) {
// Keep only the fields of the user profile that we are interested in.
$qtr_user = [
'uid' => $oauth2_user['identifier'],
'name' => $oauth2_user['displayName'],
'translation_lng' => $oauth2_user['translation_lng'],
'permissions' => $oauth2_user['permissions'],
];
$oauth2_user = $qtr_user;
}
/**
* Implementation of hook_form_alter().
*/
function qtrClient_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 Q-Translate Server'),
'#weight' => -500,
'#suffix' => '<hr/>',
);
$url = variable_get('qtrClient_server') . '/user/';
$form['remote_account']['link_to_qtranslate_profile'] = array(
'#markup' => '<a href="' . $url . '" target="_blank" class="btn btn-default">'
. t('Edit Q-Translate Profile') . '</a>',
);
}
}
/**
* Implements hook_default_wsclient_service().
*
* Defines web service descriptions (one public and one private).
* This hook is invoked when web service descriptions
* are loaded like this:
* $qtr = wsclient_service_load('qtranslate.org');
* $result = $qtr->stats('en');
*/
function qtrClient_default_wsclient_service() {
module_load_include('inc', 'qtrClient', 'services/public');
module_load_include('inc', 'qtrClient', 'services/authenticated');
$services['public_qtr'] = _qtrClientWS_public('public_qtr');
$services['qtr'] = _qtrClientWS_authenticated('qtr');
return $services;
}
/**
* Implements hook_theme().
*/
function qtrClient_theme($existing, $type, $theme, $path) {
return array(
'qtrClient_filter_form_element' => array(
'render element' => 'element',
),
'qtrClient_translate_translation' => array(
'render element' => 'element',
),
'qtrClient_translate_actions' => array(
'render element' => 'element',
),
'qtrClient_translate_radio' => array(
'render element' => 'element',
),
'qtrClient_translate_source' => array(
'render element' => 'element',
),
'qtrClient_translate_translation_list' => array(
'render element' => 'element',
),
'qtrClient_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 qtrClient_flush_caches() {
return array('cache_qtrClient');
}