-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwpg2usersadmin.php
298 lines (266 loc) · 12.1 KB
/
wpg2usersadmin.php
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
/*
Author: WPG2 Team
Updated: 13:17 25/05/2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/**
*Provide Embedded Gallery2 User Accounts with Create, Delete and Admin (de)Promoting Functions
*
* @param NULL
* @return NULL
*/
// Grab Current WP User (Prevent Admin Changes)
global $user_ID;
if ( !current_user_can('edit_users') )
die ( __('Cheatin’ uh?', 'wpg2') );
if (function_exists('btev_trigger_error')) {
btev_trigger_error('FUNCTION: WPG2 Manage G2 Users', E_USER_NOTICE, __FILE__);
}
// Initialize Gallery
if (!defined('G2INIT')) {
$ret = g2_login();
if ($ret) {
echo '<h2>' . __('Fatal G2 error:', 'wpg2') . '</h2>' . $ret;
exit;
}
}
// Remove the g2_user cap
if($_GET['duser_id'] != "" && $_GET['dg2user_id'] == "") {
$usercap = new WP_User($_GET['duser_id']);
if ($usercap->has_cap('gallery2_user')) {
?><div id="message" class="updated fade"><p><strong><?php _e('Gallery2 User deleted and Wordpress Gallery2 User capability Revoked.', 'wpg2') ?></strong></p></div><?php
$usercap->add_cap('gallery2_user', false);
if (function_exists('btev_trigger_error')) {
btev_trigger_error('G2USER capability removed from WP ID:'.$_GET['duser_id'], E_USER_NOTICE, __FILE__);
}
g2_delete_user($_GET['duser_id']);
}
}
// add the g2_user cap
if($_GET['auser_id'] != "" && $_GET['ag2user_id'] == "" ) {
$usercap = new WP_User($_GET['auser_id']);
if (!$usercap->has_cap('gallery2_user')) {
$usercap->add_cap('gallery2_user', true);
?><div id="message" class="updated fade"><p><strong><?php _e('Gallery2 User Created and Wordpress Gallery2 User capability Granted.', 'wpg2') ?></strong></p></div><?php
if (function_exists('btev_trigger_error')) {
btev_trigger_error('G2USER capability Granted to WP ID:'.$_GET['auser_id'], E_USER_NOTICE, __FILE__);
}
}
g2_create_user($_GET['auser_id']);
}
// Remove the g2_admin cap
if($_GET['duser_id'] != "" && $_GET['dg2user_id'] != "" ) {
$usercap = new WP_User($_GET['duser_id']);
if ($usercap->has_cap('gallery2_admin')) {
?><div id="message" class="updated fade"><p><strong><?php _e('Gallery2 admin capability Revoked.', 'wpg2') ?></strong></p></div><?php
$usercap->add_cap('gallery2_admin', false);
if (function_exists('btev_trigger_error')) {
btev_trigger_error('G2ADMIN capability removed from WP ID:'.$_GET['duser_id'], E_USER_NOTICE, __FILE__);
}
$ret = g2_admin_user($_GET['duser_id']);
}
}
// Add the g2_admin cap
if($_GET['auser_id'] != "" && $_GET['ag2user_id'] != "" ) {
$usercap = new WP_User($_GET['auser_id']);
if (!$usercap->has_cap('gallery2_admin')) {
$usercap->add_cap('gallery2_admin', true);
?><div id="message" class="updated fade"><p><strong><?php _e('Gallery2 admin capability Granted.', 'wpg2') ?></strong></p></div><?php
// Add BTEV Event Message
if (function_exists('btev_trigger_error')) {
btev_trigger_error('G2ADMIN capability added to WP ID:'.$_GET['auser_id'], E_USER_NOTICE, __FILE__);
}
$ret = g2_admin_user($_GET['auser_id']);
}
}
// ---- END ACTIONS
// Renew a List of all externally Mapped Users in Gallery2
list ($ret, $g2users) = GalleryEmbed::getExternalIdMap('externalId');
if (!$ret) {
foreach ($g2users as $g2user) {
if ( $g2user['entityType'] == "GalleryUser" ) {
$ret = GalleryCoreApi::removeMapEntry('ExternalIdMap', array('externalId' => $g2user['externalId'], 'entityType' => 'GalleryUser'));
}
}
}
// Get a List of all current WP Users & Renew Mapping
$wpusers = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY ID");
foreach ($wpusers as $wpuser) {
// Does the user have gallery2_user Role
$usercap = new WP_User($wpuser->ID);
if ($usercap->has_cap('gallery2_user')) {
// Find User by UserName to Remap
list ($ret, $g2user ) = GalleryCoreApi::fetchUserByUsername($usercap->user_login);
if ($ret) // Secondary Find by Email Address
list ($ret, $g2user ) = g2_fetchUserByUserEmail($usercap->user_email);
if (!$ret) {
list ($ret, $g2_results) = GalleryCoreApi::getMapEntry('ExternalIdMap', array('entityId'), array('entityId' => $g2user->id, 'entityType' => 'GalleryUser'));
if (!($g2_result = $g2_results->nextResult())) {
GalleryEmbed::addExternalIdMapEntry($wpuser->ID, $g2user->id, 'GalleryUser');
} else
g2_create_user($wpuser->ID);
}
}
}
// Get a List of all current WP Users
$wpusers = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY ID");
$cnt = 0;
foreach ($wpusers as $wpuser) {
$wparray[$cnt] = $wpuser->ID;
$cnt++;
}
// Get G2 Mapping
list ($ret, $g2users) = GalleryEmbed::getExternalIdMap('entityId');
if ($ret) {
echo __('Fatal G2 error:', 'wpg2') . $ret->getAsHtml();
exit;
}
foreach ($g2users as $g2user) {
if ( $g2user['entityType'] == "GalleryUser" ) {
$ret = GalleryCoreApi::removeMapEntry( 'ExternalIdMap', array('externalId' => $g2array[$entity], 'entityType' => 'GalleryUser'));
$g2entityarray[$g2user['externalId']] = $g2user['entityId'];
}
}
echo '<div class="wrap">';
// Wordpress Accounts Mapped to G2
echo '<h2>' . __('Wordpress Users with Gallery2 admin accounts', 'wpg2') . '</h2>';
echo '<table cellpadding="3" cellspacing="3">';
echo '<tr><th>' . __('WP ID', 'wpg2') . '</th>';
echo '<th>' . __('G2 ID', 'wpg2') . '</th>';
echo '<th>' . __('User Name', 'wpg2') . '</th>';
echo '<th>' . __('Nickname', 'wpg2') . '</th>';
echo '<th>' . __('Name', 'wpg2') . '</th>';
echo '<th>' . __('Email', 'wpg2') . '</th>';
echo '<th>' . __('WP<>G2 Password Encryption', 'wpg2') . '</th>';
echo '<th>' . __('Action', 'wpg2') . '</th>';
echo '<th> </th>';
echo '</tr>';
$style = '';
echo '<FORM METHOD="POST" ACTION="">';
foreach ($wpusers as $wpuser) {
// Get WP & G2 Member Information
$userdata = new WP_User($wpuser->ID);
$wpuserid = $wpuser->ID;
if ($userdata->has_cap('gallery2_user') && $userdata->has_cap('gallery2_admin') && $g2entityarray[$wpuserid] != '' ) {
// Output WP Infomation
if ( strlen($userdata->user_pass) > 32 )
$wpg2_passwordhash = '<font color="red">Incompatible</font>';
else
$wpg2_passwordhash = 'Compatible';
$email = $userdata->user_email;
$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
echo "";
echo "<tr $style>";
echo '<td align="center">' . $userdata->ID . '</td>';
echo '<td align="center">' . $g2entityarray[$wpuserid] . '</td>';
echo '<td align="center">' . $userdata->user_login . '</td>';
echo '<td align="center">' . $userdata->nickname . '</td>';
echo '<td align="center">' . $userdata->user_firstname .' ' . $userdata->user_lastname . '</td>';
echo '<td align="center"><a href="mailto:' . $email . '" title="' . __('e-mail: ', 'wpg2') . $email . '">' . $email . '</a></td>';
echo '<td align="center">'.$wpg2_passwordhash.'</td>';
if ( current_user_can('gallery2_admin') && ($user_ID != $wpuserid ))
echo '<td align="center"><a href="profile.php?page=wpg2/wpg2usersadmin.php&duser_id=' . $userdata->ID . '&dg2user_id=' . $g2entityarray[$wpuserid] . '">' . __('Revoke G2 Admin', 'wpg2') . '</a></td>';
else
echo '<td align="center">NA</td>';
echo '</tr>';
}
}
echo '</table><br />';
echo '<h2>' . __('Wordpress Users without Gallery2 admin accounts', 'wpg2') . '</h2>';
echo '<table cellpadding="3" cellspacing="3" >';
echo '<tr><th>' . __('WP ID', 'wpg2') . '</th>';
echo '<th>' . __('G2 ID', 'wpg2') . '</th>';
echo '<th>' . __('User Name', 'wpg2') . '</th>';
echo '<th>' . __('Nickname', 'wpg2') . '</th>';
echo '<th>' . __('Name', 'wpg2') . '</th>';
echo '<th>' . __('Email', 'wpg2') . '</th>';
echo '<th>' . __('WP<>G2 Password Encryption', 'wpg2') . '</th>';
echo '<th>' . __('Action', 'wpg2') . '</th>';
echo '<th> </th>';
echo '</tr>';
$style = '';
foreach ($wpusers as $wpuser) {
// Get WP & G2 Member Information
$userdata = new WP_User($wpuser->ID);
$wpuserid = $wpuser->ID;
if ($userdata->has_cap('gallery2_user') && !$userdata->has_cap('gallery2_admin') && $g2entityarray[$wpuserid] != '' ) {
// Output WP Infomation
$email = $userdata->user_email;
if ( strlen($userdata->user_pass) > 32 )
$wpg2_passwordhash = '<font color="red">Incompatible</font>';
else
$wpg2_passwordhash = 'Compatible';
$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
echo "";
echo "<tr $style>";
echo '<td align="center">' . $userdata->ID . '</td>';
echo '<td align="center">' . $g2entityarray[$wpuserid] . '</td>';
echo '<td align="center">' . $userdata->user_login . '</td>';
echo '<td align="center">' . $userdata->nickname . '</td>';
echo '<td align="center">' . $userdata->user_firstname .' ' . $userdata->user_lastname . '</td>';
echo '<td align="center"><a href="mailto:' . $email . '" title="' . __('e-mail: ', 'wpg2') . $email . '">' . $email . '</a></td>';
echo '<td align="center">'.$wpg2_passwordhash.'</td>';
if ( current_user_can('gallery2_admin') ) {
echo '<td align="center"><a href="profile.php?page=wpg2/wpg2usersadmin.php&auser_id=' . $userdata->ID . '&ag2user_id=' . $g2entityarray[$wpuserid] . '">' . __('Grant G2 Admin', 'wpg2') . '</a>';
echo ' / <a href="profile.php?page=wpg2/wpg2usersadmin.php&duser_id=' . $userdata->ID . '">' . __('Revoke G2 User', 'wpg2') . '</a></td>';
} else {
echo '<td align="center"><a href="profile.php?page=wpg2/wpg2usersadmin.php&duser_id=' . $userdata->ID . '">' . __('Revoke G2 User', 'wpg2') . '</a></td>';
}
echo '</tr>';
}
}
echo '</table><br />';
// Wordpress Accounts Not mapped to G2
echo '<h2>' . __('Wordpress Users without Gallery2 accounts', 'wpg2') . '</h2>';
echo '<table cellpadding="3" cellspacing="3" >';
echo '<tr><th>' . __('WP ID', 'wpg2') . '</th>';
echo '<th>' . __('G2 ID', 'wpg2') . '</th>';
echo '<th>' . __('User Name', 'wpg2') . '</th>';
echo '<th>' . __('Nickname', 'wpg2') . '</th>';
echo '<th>' . __('Name', 'wpg2') . '</th>';
echo '<th>' . __('Email', 'wpg2') . '</th>';
echo '<th>' . __('WP<>G2 Password Encryption', 'wpg2') . '</th>';
echo '<th>' . __('Action', 'wpg2') . '</th>';
echo '<th> </th>';
echo '</tr>';
$style = '';
foreach ($wpusers as $wpuser) {
// Get WP & G2 Member Information
$wpuserid = $wpuser->ID;
$userdata = new WP_User($wpuser->ID);
if (!$userdata->has_cap('gallery2_user') || $g2entityarray[$wpuserid] == '' ) {
// Output WP Infomation
$email = $userdata->user_email;
if ( strlen($userdata->user_pass) > 32 )
$wpg2_passwordhash = '<font color="red">Incompatible</font>';
else
$wpg2_passwordhash = 'Compatible';
$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
echo "";
echo "<tr $style>";
echo '<td align="center">' . $userdata->ID . '</td>';
echo '<td align="center">' . __('NA', 'wpg2') . '</td>';
echo '<td align="center">' . $userdata->user_login . '</td>';
echo '<td align="center">' . $userdata->nickname . '</td>';
echo '<td align="center">' . $userdata->user_firstname . ' ' . $userdata->user_lastname . '</td>';
echo '<td align="center"><a href="mailto:' . $email . '" title="' . __('e-mail: ', 'wpg2') . $email . '">' . $email . '</a></td>';
echo '<td align="center">'.$wpg2_passwordhash.'</td>';
if ( strlen($userdata->user_pass) > 32 )
echo '<td align="center">'.__('NA','wpg2').'</td>';
else
echo '<td align="center"><a href="profile.php?page=wpg2/wpg2usersadmin.php&auser_id=' . $userdata->ID . '">' . __('Grant G2 User', 'wpg2') . '</a></td>';
echo '</tr>';
}
}
echo '</form></table>';
echo __('<br />NOTE: Due to password encryption changes in Wordpress 2.5, passwords are not initially compatible with Gallery2.<br />WPG2 can only make the Wordpress password compatible with Gallery2 after you have logged off the wordpress user and logged back in.','wpg2');
echo '</div>';
?>