/
warp-userprofile.php
249 lines (219 loc) · 7.45 KB
/
warp-userprofile.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
<?php
/*
Plugin Name: Warp User Profile extension
Plugin URI: http://people.warp.es/~koke/wp-plugins/warp-userprofile
Description: Shows a directory of authors and their personal info
Version: 0.1
Author: Jorge Bernal
Author URI: http://koke.amedias.org/
*/
/* Copyright 2008 Jorge Bernal <jbernal@warp.es>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define(warp_userprofile_version,'0.1');
/**
* Warp User Profile extension
*/
class Warp_UserProfile
{
function init()
{
// Register actions and filters here
add_action('edit_user_profile', array('Warp_UserProfile', 'show_extra_fields'));
add_action('show_user_profile', array('Warp_UserProfile', 'show_extra_fields'));
add_action('profile_update', array('Warp_UserProfile', 'save_extra_fields'));
add_action('personal_options_update', array('Warp_UserProfile', 'save_extra_fields'));
add_filter('query_vars', array('Warp_UserProfile', 'query_vars'));
add_filter('generate_rewrite_rules', array('Warp_UserProfile', 'register_rewrite_rules'));
add_action('template_redirect', array('Warp_UserProfile', 'show_profiles'));
add_action('admin_print_scripts', array('Warp_UserProfile', 'admin_js'));
add_action('admin_menu', array('Warp_UserProfile', 'add_option_pages'));
register_activation_hook(__FILE__, array('Warp_UserProfile', 'register_version'));
}
function register_version()
{
add_option('warp_userprofile_version', warp_userprofile_version);
update_option('warp_userprofile_version', warp_userprofile_version);
add_option("warp_userprofile_page");
}
function register_rewrite_rules($wp_rewrite)
{
$plink = Warp_UserProfile::get_plink();
$userprofile_rules = array(
// 'people/?' => 'wp-content/plugins/warp-userprofile/people.php'
"$plink([^/]+)/?" => 'index.php?showprofiles=1&person=' . $wp_rewrite->preg_index(1) . '&page_id=' . get_option('warp_userprofile_page'),
"$plink?" => 'index.php?showprofiles=1' . '&page_id=' . get_option('warp_userprofile_page'),
);
$wp_rewrite->rules = array_merge($userprofile_rules, $wp_rewrite->rules);
}
function add_option_pages()
{
add_options_page(__('Profiles', 'warp_userprofile'), __('Profiles', 'warp_userprofile'), 8, 'warp-userprofile', array('Warp_UserProfile', 'options_page'));
}
function query_vars($vars)
{
$vars[] = "showprofiles";
$vars[] = "person";
$vars[] = "page_id";
return $vars;
}
function admin_js()
{
wp_enqueue_script("editor");
}
function show_profiles()
{
global $wp_rewrite, $wp_query;
if (get_query_var("showprofiles")) {
if (get_query_var("person")) {
$user = get_userdatabylogin(get_query_var('person'));
if (get_usermeta($user->ID, 'warp_up_public') == 1) {
require 'person.php';
} else {
$wp_query->is_404 = true;
return;
}
} else {
require 'people.php';
}
exit;
}
}
function options_page()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
$warp_userprofile_page = get_option("warp_userprofile_page");
echo "<div class='wrap'>";
echo "<h2>" . __( 'Profiles Options', 'warp_userprofile') . "</h2>";
?>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<h3><?php _e( 'General options', 'warp_lms'); ?></h3>
<table class="form-table">
<tr>
<th>
<?php _e( 'Profiles page', 'warp_lms'); ?>
</th>
<td>
<?php wp_dropdown_pages(array('name' => 'warp_userprofile_page', 'selected' => $warp_userprofile_page)); ?>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="page_options" value="warp_userprofile_page" />
<input type="hidden" name="action" value="update" />
<p class="submit"><input type="submit" value="<?php _e( 'Update Options', 'warp_userprofile'); ?>"></p>
</form>
<?php
echo "</div>";
}
function show_extra_fields()
{
$user = $GLOBALS['profileuser'];
echo '<h3>' . __( 'Profile extras', 'warp_userprofile' ) . '</h3>';
?>
<table class="form-table">
<tbody>
<tr>
<th>
<?php _e( 'Public profile', 'warp_userprofile' ); ?>
</th>
<td>
<input type="checkbox" name="warp_up_public" value="1" id="warp_up_public" <?php if (get_usermeta($user->ID, 'warp_up_public') == 1) { echo 'checked="checked"'; } ?> />
<label for="warp_up_public"><?php _e( 'If checked, this profile will be shown in the public directory', 'warp_userprofile' ); ?></label>
</td>
</tr>
<tr>
<th>
<?php _e( 'Title', 'warp_userprofile' ); ?>
</th>
<td>
<input type="text" name="warp_up_title" value="<?php echo get_usermeta($user->ID, 'warp_up_title'); ?>" id="warp_up_title" /><br />
<?php _e( 'Your position at the company', 'warp_userprofile' ); ?>
</td>
</tr>
</tbody>
</table>
<div id="editorcontainer">
</div>
<script type="text/javascript">
<!--
// edCanvas = document.getElementById('description');
tinyMCE.execCommand("mceAddControl", false, "description");
//-->
</script>
<?php
}
function save_extra_fields()
{
global $wpdb;
$user_id = (int) $_POST["user_id"];
update_usermeta($user_id, "warp_up_title", $_POST["warp_up_title"]);
update_usermeta($user_id, "warp_up_public", $_POST["warp_up_public"]);
update_usermeta( $user_id, 'description', $wpdb->escape($_POST["description"]) );
// var_dump($_POST);//die;
}
function get_plink()
{
$home = get_option('home');
$profile_page_id = get_option('warp_userprofile_page');
$plink = preg_replace("|^$home/?|","",get_permalink($profile_page_id));
return $plink;
}
function permalink()
{
$profile_page_id = get_option('warp_userprofile_page');
return get_permalink($profile_page_id);
}
function title()
{
$profile_page_id = get_option('warp_userprofile_page');
$page = get_post($profile_page_id);
return $page->post_title;
}
function parse_email($email)
{
$out = "";
for ($i=0; $i < strlen($email); $i++) {
$c = unpack("C", $email[$i]);
$out.= sprintf("&#x%02X;", $c[1]);
}
return $out;
}
function avatar_for($user)
{
if ( $image = glob(ABSPATH . 'wp-content/authors/' . $user->user_login . '-*.jpg') )
{
$image = current($image);
$site_url = trailingslashit(get_option('siteurl'));
return '<img src="'
. str_replace(ABSPATH, $site_url, $image)
. '"'
. ' alt="" class="avatar avatar-48" height="48" width="48"'
. ' />';
}
else
{
return get_avatar($user->user_email, 48);
}
}
function get_users_of_blog( $id = '' ) {
global $wpdb, $blog_id;
if ( empty($id) )
$id = (int) $blog_id;
$users = $wpdb->get_results( "SELECT user_id, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE " . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id AND meta_key = '" . $wpdb->prefix . "capabilities' ORDER BY {$wpdb->users}.display_name" );
return $users;
}
}
Warp_UserProfile::init();