|
1 <?php |
|
2 |
|
3 /* |
|
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
5 * Version 1.1.5 (Caoineag alpha 5) |
|
6 * Copyright (C) 2006-2008 Dan Fuhry |
|
7 * |
|
8 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 */ |
|
14 |
|
15 class Namespace_User extends Namespace_Default |
|
16 { |
|
17 public function send() |
|
18 { |
|
19 global $db, $session, $paths, $template, $plugins; // Common objects |
|
20 global $email; |
|
21 global $lang, $output; |
|
22 |
|
23 /** |
|
24 * PLUGGING INTO USER PAGES |
|
25 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
26 * Userpages are highly programmable and extendable using a number of |
|
27 * hooks. These hooks are: |
|
28 * |
|
29 * - userpage_sidebar_left |
|
30 * - userpage_sidebar_right |
|
31 * - userpage_tabs_links |
|
32 * - userpage_tabs_body |
|
33 * |
|
34 * You can add a variety of sections to user pages, including new tabs |
|
35 * and new sections on the tables. To add a tab, attach to |
|
36 * userpage_tabs_links and echo out: |
|
37 * |
|
38 * <li><a href="#tab:YOURTABID">YOUR TAB TEXT</a></li> |
|
39 * |
|
40 * Then hook into userpage_tabs_body and echo out: |
|
41 * |
|
42 * <div id="tab:YOURTABID">YOUR TAB CONTENT</div> |
|
43 * |
|
44 * The userpage javascript runtime will take care of everything else, |
|
45 * meaning transitions, click events, etc. Currently it's not possible |
|
46 * to add custom click events to tabs, but any DOM-related JS that needs |
|
47 * to run in your tab can be run onload and the effects will be seen when |
|
48 * your tab is clicked. YOURTABID should be lowercase alphanumeric and |
|
49 * have a short prefix so as to assure that it remains specific to your |
|
50 * plugin. |
|
51 * |
|
52 * To hook into the "profile" tab, use userpage_sidebar_{left,right}. Just |
|
53 * echo out table cells as normal. The table on the left (the wide one) has |
|
54 * four columns, and the one on the right has one column. |
|
55 * |
|
56 * See plugins.php for a guide on creating and attaching to hooks. |
|
57 */ |
|
58 |
|
59 $page_urlname = dirtify_page_id($this->page_id); |
|
60 if ( $this->page_id == $paths->page_id && $this->namespace == $paths->namespace ) |
|
61 { |
|
62 $page_name = ( isset($paths->cpage['name']) ) ? $paths->cpage['name'] : $this->page_id; |
|
63 } |
|
64 else |
|
65 { |
|
66 $page_name = ( isset($paths->pages[$this->page_id]) ) ? $paths->pages[$this->page_id]['name'] : $this->page_id; |
|
67 } |
|
68 |
|
69 $target_username = strtr($page_urlname, |
|
70 Array( |
|
71 '_' => ' ', |
|
72 '<' => '<', |
|
73 '>' => '>' |
|
74 )); |
|
75 |
|
76 $target_username = preg_replace('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', '', $target_username); |
|
77 list($target_username) = explode('/', $target_username); |
|
78 |
|
79 if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists ) |
|
80 { |
|
81 $page_name = $lang->get('userpage_page_title', array('username' => $target_username)); |
|
82 } |
|
83 else |
|
84 { |
|
85 // User has a custom title for their userpage |
|
86 $page_name = $paths->pages[ $paths->nslist[$this->namespace] . $this->page_id ]['name']; |
|
87 } |
|
88 |
|
89 $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($page_name); |
|
90 |
|
91 $q = $db->sql_query('SELECT u.username, u.user_id AS authoritative_uid, u.real_name, u.email, u.reg_time, u.user_has_avatar, u.avatar_type, x.*, COUNT(c.comment_id) AS n_comments |
|
92 FROM '.table_prefix.'users u |
|
93 LEFT JOIN '.table_prefix.'users_extra AS x |
|
94 ON ( u.user_id = x.user_id OR x.user_id IS NULL ) |
|
95 LEFT JOIN '.table_prefix.'comments AS c |
|
96 ON ( ( c.user_id=u.user_id AND c.name=u.username AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) ) |
|
97 WHERE u.username=\'' . $db->escape($target_username) . '\' |
|
98 GROUP BY u.username, u.user_id, u.real_name, u.email, u.reg_time, u.user_has_avatar, u.avatar_type, x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;'); |
|
99 if ( !$q ) |
|
100 $db->_die(); |
|
101 |
|
102 $user_exists = true; |
|
103 |
|
104 if ( $db->numrows() < 1 ) |
|
105 { |
|
106 $user_exists = false; |
|
107 } |
|
108 else |
|
109 { |
|
110 $userdata = $db->fetchrow(); |
|
111 if ( $userdata['authoritative_uid'] == 1 ) |
|
112 { |
|
113 // Hide data for anonymous user |
|
114 $user_exists = false; |
|
115 unset($userdata); |
|
116 } |
|
117 } |
|
118 |
|
119 // get the user's rank |
|
120 if ( $user_exists ) |
|
121 { |
|
122 $rank_data = $session->get_user_rank(intval($userdata['authoritative_uid'])); |
|
123 } |
|
124 else |
|
125 { |
|
126 // get the rank data for the anonymous user (placeholder basically) |
|
127 $rank_data = $session->get_user_rank(1); |
|
128 } |
|
129 |
|
130 // add the userpage script to the header |
|
131 $template->add_header('<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/userpage.js"></script>'); |
|
132 |
|
133 $output->header(); |
|
134 |
|
135 // if ( $send_headers ) |
|
136 // { |
|
137 // display_page_headers(); |
|
138 // } |
|
139 |
|
140 // |
|
141 // BASIC INFORMATION |
|
142 // Presentation of username/rank/avatar/basic info |
|
143 // |
|
144 |
|
145 if ( $user_exists ) |
|
146 { |
|
147 |
|
148 ?> |
|
149 <div id="userpage_wrap"> |
|
150 <ul id="userpage_links"> |
|
151 <li><a href="#tab:profile"><?php echo $lang->get('userpage_tab_profile'); ?></a></li> |
|
152 <li><a href="#tab:content"><?php echo $lang->get('userpage_tab_content'); ?></a></li> |
|
153 <?php |
|
154 $code = $plugins->setHook('userpage_tabs_links'); |
|
155 foreach ( $code as $cmd ) |
|
156 { |
|
157 eval($cmd); |
|
158 } |
|
159 ?> |
|
160 </ul> |
|
161 |
|
162 <div id="tab:profile"> |
|
163 |
|
164 <?php |
|
165 |
|
166 echo '<table border="0" cellspacing="0" cellpadding="0"> |
|
167 <tr>'; |
|
168 |
|
169 echo ' <td valign="top">'; |
|
170 |
|
171 echo '<div class="tblholder"> |
|
172 <table border="0" cellspacing="1" cellpadding="4">'; |
|
173 |
|
174 // heading |
|
175 echo ' <tr> |
|
176 <th colspan="' . ( $session->user_level >= USER_LEVEL_ADMIN ? '3' : '4' ) . '"> |
|
177 ' . $lang->get('userpage_heading_basics', array('username' => htmlspecialchars($target_username))) . ' |
|
178 </th> |
|
179 ' . ( |
|
180 $session->user_level >= USER_LEVEL_ADMIN ? |
|
181 '<th class="subhead" style="width: 25%;"><a href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&user=' . urlencode($target_username), true) . '" onclick="ajaxAdminUser(\'' . addslashes($target_username) . '\'); return false;">» ' . $lang->get('userpage_btn_administer_user') . '</a></th>' |
|
182 : '' |
|
183 ) . ' |
|
184 </tr>'; |
|
185 |
|
186 // avi/rank/username |
|
187 echo ' <tr> |
|
188 <td class="row3" colspan="4"> |
|
189 ' . ( |
|
190 $userdata['user_has_avatar'] == 1 ? |
|
191 '<div style="float: left; margin-right: 10px;"> |
|
192 <img alt="' . $lang->get('usercp_avatar_image_alt', array('username' => $userdata['username'])) . '" src="' . make_avatar_url(intval($userdata['authoritative_uid']), $userdata['avatar_type'], $userdata['email']) . '" /> |
|
193 </div>' |
|
194 : '' |
|
195 ) . ' |
|
196 <span style="font-size: x-large; ' . $rank_data['rank_style'] . '">' . htmlspecialchars($userdata['username']) . '</span> |
|
197 ' . ( !empty($rank_data['user_title']) ? '<br />' . htmlspecialchars($rank_data['user_title']) : '' ) . ' |
|
198 ' . ( !empty($rank_data['rank_title']) ? '<br />' . htmlspecialchars($lang->get($rank_data['rank_title'])) : '' ) . ' |
|
199 </td> |
|
200 </tr>'; |
|
201 |
|
202 // join date & total comments |
|
203 echo '<tr>'; |
|
204 echo ' <td class="row2" style="text-align: right; width: 25%;"> |
|
205 ' . $lang->get('userpage_lbl_joined') . ' |
|
206 </td> |
|
207 <td class="row1" style="text-align: left; width: 25%;"> |
|
208 ' . enano_date('F d, Y h:i a', $userdata['reg_time']) . ' |
|
209 </td>'; |
|
210 echo ' <td class="row2" style="text-align: right; width: 25%;"> |
|
211 ' . $lang->get('userpage_lbl_num_comments') . ' |
|
212 </td> |
|
213 <td class="row1" style="text-align: left; width: 25%;"> |
|
214 ' . $userdata['n_comments'] . ' |
|
215 </td>'; |
|
216 echo '</tr>'; |
|
217 |
|
218 // real name |
|
219 if ( !empty($userdata['real_name']) ) |
|
220 { |
|
221 echo '<tr> |
|
222 <td class="row2" style="text-align: right;"> |
|
223 ' . $lang->get('userpage_lbl_real_name') . ' |
|
224 </td> |
|
225 <td class="row1" colspan="3" style="text-align: left;"> |
|
226 ' . htmlspecialchars($userdata['real_name']) . ' |
|
227 </td> |
|
228 </tr>'; |
|
229 } |
|
230 |
|
231 // latest comments |
|
232 |
|
233 echo '<tr><th class="subhead" colspan="4">' . $lang->get('userpage_heading_comments', array('username' => htmlspecialchars($target_username))) . '</th></tr>'; |
|
234 $q = $db->sql_query('SELECT page_id, namespace, subject, time FROM '.table_prefix.'comments WHERE name=\'' . $db->escape($target_username) . '\' AND user_id=' . $userdata['authoritative_uid'] . ' AND approved=1 ORDER BY time DESC LIMIT 7;'); |
|
235 if ( !$q ) |
|
236 $db->_die(); |
|
237 |
|
238 $comments = Array(); |
|
239 $no_comments = false; |
|
240 |
|
241 if ( $row = $db->fetchrow() ) |
|
242 { |
|
243 do |
|
244 { |
|
245 $row['time'] = enano_date('F d, Y', $row['time']); |
|
246 $comments[] = $row; |
|
247 } |
|
248 while ( $row = $db->fetchrow() ); |
|
249 } |
|
250 else |
|
251 { |
|
252 $no_comments = true; |
|
253 } |
|
254 |
|
255 echo '<tr><td class="row3" colspan="4">'; |
|
256 echo '<div style="border: 1px solid #000000; padding: 0px; width: 100%; clip: rect(0px,auto,auto,0px); overflow: auto; background-color: transparent;" class="tblholder">'; |
|
257 |
|
258 echo '<table border="0" cellspacing="1" cellpadding="4" style="width: 200%;"><tr>'; |
|
259 $class = 'row1'; |
|
260 |
|
261 $tpl = ' <td class="{CLASS}"> |
|
262 <a href="{PAGE_LINK}" <!-- BEGINNOT page_exists -->class="wikilink-nonexistent"<!-- END page_exists -->>{PAGE}</a><br /> |
|
263 <small>{lang:userpage_comments_lbl_posted} {DATE}<br /></small> |
|
264 <b><a href="{COMMENT_LINK}">{SUBJECT}</a></b> |
|
265 </td>'; |
|
266 $parser = $template->makeParserText($tpl); |
|
267 |
|
268 if ( count($comments) > 0 ) |
|
269 { |
|
270 foreach ( $comments as $comment ) |
|
271 { |
|
272 $c_page_id = $paths->nslist[ $comment['namespace'] ] . sanitize_page_id($comment['page_id']); |
|
273 if ( isset($paths->pages[ $c_page_id ]) ) |
|
274 { |
|
275 $parser->assign_bool(array( |
|
276 'page_exists' => true |
|
277 )); |
|
278 $page_title = htmlspecialchars($paths->pages[ $c_page_id ]['name']); |
|
279 } |
|
280 else |
|
281 { |
|
282 $parser->assign_bool(array( |
|
283 'page_exists' => false |
|
284 )); |
|
285 $page_title = htmlspecialchars(dirtify_page_id($c_page_id)); |
|
286 } |
|
287 $parser->assign_vars(array( |
|
288 'CLASS' => $class, |
|
289 'PAGE_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id'])), |
|
290 'PAGE' => $page_title, |
|
291 'SUBJECT' => $comment['subject'], |
|
292 'DATE' => $comment['time'], |
|
293 'COMMENT_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id']), 'do=comments', true) |
|
294 )); |
|
295 $class = ( $class == 'row3' ) ? 'row1' : 'row3'; |
|
296 echo $parser->run(); |
|
297 } |
|
298 } |
|
299 else |
|
300 { |
|
301 echo '<td class="' . $class . '">' . $lang->get('userpage_msg_no_comments') . '</td>'; |
|
302 } |
|
303 echo '</tr></table>'; |
|
304 |
|
305 echo '</div>'; |
|
306 echo '</td></tr>'; |
|
307 |
|
308 $code = $plugins->setHook('userpage_sidebar_left'); |
|
309 foreach ( $code as $cmd ) |
|
310 { |
|
311 eval($cmd); |
|
312 } |
|
313 |
|
314 echo ' </table> |
|
315 </div>'; |
|
316 |
|
317 echo '</td>'; |
|
318 |
|
319 // |
|
320 // CONTACT INFORMATION |
|
321 // |
|
322 |
|
323 echo ' <td valign="top" style="width: 150px; padding-left: 10px;">'; |
|
324 |
|
325 echo '<div class="tblholder"> |
|
326 <table border="0" cellspacing="1" cellpadding="4">'; |
|
327 |
|
328 // |
|
329 // Main part of sidebar |
|
330 // |
|
331 |
|
332 // Contact information |
|
333 |
|
334 echo '<tr><th class="subhead">' . $lang->get('userpage_heading_contact') . '</th></tr>'; |
|
335 |
|
336 $class = 'row3'; |
|
337 |
|
338 if ( $userdata['email_public'] == 1 ) |
|
339 { |
|
340 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
341 $email_link = $email->encryptEmail($userdata['email']); |
|
342 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_email') . ' ' . $email_link . '</td></tr>'; |
|
343 } |
|
344 |
|
345 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
346 if ( $session->user_logged_in ) |
|
347 { |
|
348 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_btn_send_pm', array('username' => htmlspecialchars($target_username), 'pm_link' => makeUrlNS('Special', 'PrivateMessages/Compose/to/' . $this->page_id, false, true))) . '</td></tr>'; |
|
349 } |
|
350 else |
|
351 { |
|
352 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_btn_send_pm_guest', array('username' => htmlspecialchars($target_username), 'login_flags' => 'href="' . makeUrlNS('Special', 'Login/' . $paths->nslist[$this->namespace] . $this->page_id) . '" onclick="ajaxStartLogin(); return false;"')) . '</td></tr>'; |
|
353 } |
|
354 |
|
355 if ( !empty($userdata['user_aim']) ) |
|
356 { |
|
357 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
358 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_aim') . ' ' . $userdata['user_aim'] . '</td></tr>'; |
|
359 } |
|
360 |
|
361 if ( !empty($userdata['user_yahoo']) ) |
|
362 { |
|
363 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
364 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_yim') . ' ' . $userdata['user_yahoo'] . '</td></tr>'; |
|
365 } |
|
366 |
|
367 if ( !empty($userdata['user_msn']) ) |
|
368 { |
|
369 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
370 $email_link = $email->encryptEmail($userdata['user_msn']); |
|
371 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_wlm') . ' ' . $email_link . '</td></tr>'; |
|
372 } |
|
373 |
|
374 if ( !empty($userdata['user_xmpp']) ) |
|
375 { |
|
376 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
377 $email_link = $email->encryptEmail($userdata['user_xmpp']); |
|
378 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_xmpp') . ' ' . $email_link . '</td></tr>'; |
|
379 } |
|
380 |
|
381 // Real life |
|
382 |
|
383 echo '<tr><th class="subhead">' . $lang->get('userpage_heading_real_life', array('username' => htmlspecialchars($target_username))) . '</th></tr>'; |
|
384 |
|
385 if ( !empty($userdata['user_location']) ) |
|
386 { |
|
387 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
388 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_location') . ' ' . $userdata['user_location'] . '</td></tr>'; |
|
389 } |
|
390 |
|
391 if ( !empty($userdata['user_job']) ) |
|
392 { |
|
393 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
394 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_job') . ' ' . $userdata['user_job'] . '</td></tr>'; |
|
395 } |
|
396 |
|
397 if ( !empty($userdata['user_hobbies']) ) |
|
398 { |
|
399 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
400 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_lbl_hobbies') . ' ' . $userdata['user_hobbies'] . '</td></tr>'; |
|
401 } |
|
402 |
|
403 if ( empty($userdata['user_location']) && empty($userdata['user_job']) && empty($userdata['user_hobbies']) ) |
|
404 { |
|
405 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
|
406 echo '<tr><td class="'.$class.'">' . $lang->get('userpage_msg_no_contact_info', array('username' => htmlspecialchars($target_username))) . '</td></tr>'; |
|
407 } |
|
408 |
|
409 $code = $plugins->setHook('userpage_sidebar_right'); |
|
410 foreach ( $code as $cmd ) |
|
411 { |
|
412 eval($cmd); |
|
413 } |
|
414 |
|
415 echo ' </table> |
|
416 </div>'; |
|
417 echo '</td>'; |
|
418 |
|
419 // |
|
420 // End of profile |
|
421 // |
|
422 |
|
423 echo '</tr></table>'; |
|
424 |
|
425 echo '</div>'; // tab:profile |
|
426 |
|
427 } |
|
428 |
|
429 // User's own content |
|
430 |
|
431 echo '<span class="menuclear"></span>'; |
|
432 |
|
433 echo '<div id="tab:content">'; |
|
434 |
|
435 if ( $this->exists ) |
|
436 { |
|
437 $this->send_from_db(true, false); |
|
438 } |
|
439 else |
|
440 { |
|
441 $this->error_404(true); |
|
442 } |
|
443 |
|
444 echo '</div>'; // tab:content |
|
445 |
|
446 $code = $plugins->setHook('userpage_tabs_body'); |
|
447 foreach ( $code as $cmd ) |
|
448 { |
|
449 eval($cmd); |
|
450 } |
|
451 |
|
452 if ( $user_exists ) |
|
453 { |
|
454 echo '</div>'; // userpage_wrap |
|
455 } |
|
456 else |
|
457 { |
|
458 if ( !is_valid_ip($target_username) ) |
|
459 { |
|
460 echo '<p>' . $lang->get('userpage_msg_user_not_exist', array('username' => htmlspecialchars($target_username))) . '</p>'; |
|
461 } |
|
462 } |
|
463 |
|
464 // if ( $send_headers ) |
|
465 // { |
|
466 // display_page_footers(); |
|
467 // } |
|
468 |
|
469 $output->footer(); |
|
470 } |
|
471 } |
|
472 |