Version Description
Bug fixes and improved WordPress 3.0 support. Important upgrade.
=
Download this release
Release Info
Developer | johnjamesjacoby |
Plugin | BuddyPress |
Version | 1.2.6 |
Comparing to | |
See all releases |
Code changes from version 1.2.5.2 to 1.2.6
- bp-activity.php +1214 -1197
- bp-activity/bp-activity-classes.php +552 -552
- bp-activity/bp-activity-filters.php +144 -141
- bp-activity/bp-activity-notifications.php +17 -14
- bp-activity/bp-activity-templatetags.php +1073 -953
- bp-activity/feeds/bp-activity-friends-feed.php +59 -59
- bp-activity/feeds/bp-activity-personal-feed.php +58 -58
- bp-activity/feeds/bp-activity-sitewide-feed.php +54 -54
- bp-blogs.php +820 -803
- bp-blogs/bp-blogs-classes.php +312 -310
- bp-blogs/bp-blogs-templatetags.php +544 -504
- bp-blogs/bp-blogs-widgets.php +83 -83
- bp-core.php +2174 -2143
- bp-core/bp-core-admin.php +250 -250
- bp-core/bp-core-adminbar.php +257 -257
- bp-core/bp-core-avatars.php +574 -569
- bp-core/bp-core-catchuri.php +300 -289
- bp-core/bp-core-classes.php +652 -489
- bp-core/bp-core-cssjs.php +176 -183
- bp-core/bp-core-filters.php +7 -7
- bp-core/bp-core-notifications.php +94 -94
- bp-core/bp-core-settings.php +197 -198
- bp-core/bp-core-signup.php +624 -624
- bp-core/bp-core-templatetags.php +2081 -2081
- bp-core/bp-core-widgets.php +254 -242
- bp-core/bp-core-wpabstraction.php +33 -18
- bp-forums.php +555 -555
- bp-forums/bb-config.php +10 -10
- bp-forums/bp-forums-admin.php +257 -257
- bp-forums/bp-forums-bbpress.php +174 -174
- bp-forums/bp-forums-filters.php +113 -91
- bp-forums/bp-forums-templatetags.php +512 -1089
bp-activity.php
CHANGED
@@ -1,1198 +1,1215 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
|
4 |
-
|
5 |
-
/* Define the slug for the component */
|
6 |
-
if ( !defined( 'BP_ACTIVITY_SLUG' ) )
|
7 |
-
define ( 'BP_ACTIVITY_SLUG', 'activity' );
|
8 |
-
|
9 |
-
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
|
10 |
-
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
|
11 |
-
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
|
12 |
-
|
13 |
-
function bp_activity_install() {
|
14 |
-
global $wpdb, $bp;
|
15 |
-
|
16 |
-
if ( !empty($wpdb->charset) )
|
17 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
18 |
-
|
19 |
-
/* Rename the old user activity cached table if needed. */
|
20 |
-
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
|
21 |
-
$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
|
22 |
-
|
23 |
-
/* Rename fields from pre BP 1.2 */
|
24 |
-
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
|
25 |
-
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
|
26 |
-
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
|
27 |
-
|
28 |
-
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
|
29 |
-
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Build the tables
|
34 |
-
*/
|
35 |
-
$sql[] = "CREATE TABLE {$bp->activity->table_name} (
|
36 |
-
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
37 |
-
user_id bigint(20) NOT NULL,
|
38 |
-
component varchar(75) NOT NULL,
|
39 |
-
type varchar(75) NOT NULL,
|
40 |
-
action text NOT NULL,
|
41 |
-
content longtext NOT NULL,
|
42 |
-
primary_link varchar(150) NOT NULL,
|
43 |
-
item_id varchar(75) NOT NULL,
|
44 |
-
secondary_item_id varchar(75) DEFAULT NULL,
|
45 |
-
date_recorded datetime NOT NULL,
|
46 |
-
hide_sitewide bool DEFAULT 0,
|
47 |
-
mptt_left int(11) NOT NULL DEFAULT 0,
|
48 |
-
mptt_right int(11) NOT NULL DEFAULT 0,
|
49 |
-
KEY date_recorded (date_recorded),
|
50 |
-
KEY user_id (user_id),
|
51 |
-
KEY item_id (item_id),
|
52 |
-
KEY secondary_item_id (secondary_item_id),
|
53 |
-
KEY component (component),
|
54 |
-
KEY type (type),
|
55 |
-
KEY mptt_left (mptt_left),
|
56 |
-
KEY mptt_right (mptt_right),
|
57 |
-
KEY hide_sitewide (hide_sitewide)
|
58 |
-
) {$charset_collate};";
|
59 |
-
|
60 |
-
$sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
|
61 |
-
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
62 |
-
activity_id bigint(20) NOT NULL,
|
63 |
-
meta_key varchar(255) DEFAULT NULL,
|
64 |
-
meta_value longtext DEFAULT NULL,
|
65 |
-
KEY activity_id (activity_id),
|
66 |
-
KEY meta_key (meta_key)
|
67 |
-
) {$charset_collate};";
|
68 |
-
|
69 |
-
require_once( ABSPATH . 'wp-admin/upgrade
|
70 |
-
dbDelta($sql);
|
71 |
-
|
72 |
-
update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
|
73 |
-
}
|
74 |
-
|
75 |
-
function bp_activity_setup_globals() {
|
76 |
-
global $bp, $
|
77 |
-
|
78 |
-
/* Internal identifier */
|
79 |
-
$bp->activity->id = 'activity';
|
80 |
-
|
81 |
-
$bp->activity->
|
82 |
-
|
83 |
-
$bp->activity->
|
84 |
-
$bp->activity->
|
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 |
-
$bp->
|
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 |
-
* Screen
|
159 |
-
*
|
160 |
-
* functions
|
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 |
-
bp_core_redirect(
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
<th class="
|
270 |
-
<th class="
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
<td
|
279 |
-
<td
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
<td
|
285 |
-
<td
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
* Action
|
299 |
-
*
|
300 |
-
*
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
bp_core_add_message( __( '
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
$
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
bp_core_add_message( __( '
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
'
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
bp_core_add_message( __( '
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
bp_core_add_message( __( '
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
bp_core_add_message( __( '
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
* Business
|
565 |
-
*
|
566 |
-
*
|
567 |
-
*
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
'
|
575 |
-
'
|
576 |
-
'
|
577 |
-
|
578 |
-
'
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
*
|
585 |
-
*
|
586 |
-
*
|
587 |
-
* '
|
588 |
-
* '
|
589 |
-
*
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
'
|
614 |
-
'
|
615 |
-
'
|
616 |
-
'
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
$
|
629 |
-
|
630 |
-
|
631 |
-
'
|
632 |
-
|
633 |
-
|
634 |
-
'
|
635 |
-
|
636 |
-
'
|
637 |
-
|
638 |
-
'
|
639 |
-
|
640 |
-
'
|
641 |
-
'
|
642 |
-
'
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
$activity
|
658 |
-
|
659 |
-
$activity->
|
660 |
-
$activity->
|
661 |
-
$activity->
|
662 |
-
$activity->
|
663 |
-
$activity->
|
664 |
-
$activity->
|
665 |
-
$activity->
|
666 |
-
$activity->
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
$
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
$
|
699 |
-
|
700 |
-
$
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
'
|
707 |
-
'
|
708 |
-
'
|
709 |
-
'
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
$
|
727 |
-
|
728 |
-
|
729 |
-
'
|
730 |
-
'
|
731 |
-
'
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
'
|
752 |
-
'
|
753 |
-
'
|
754 |
-
'
|
755 |
-
'
|
756 |
-
'
|
757 |
-
'
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
*
|
776 |
-
*
|
777 |
-
*
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
'
|
784 |
-
'
|
785 |
-
'
|
786 |
-
'
|
787 |
-
'
|
788 |
-
'
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
*
|
801 |
-
*
|
802 |
-
*
|
803 |
-
*
|
804 |
-
*
|
805 |
-
*
|
806 |
-
*
|
807 |
-
*
|
808 |
-
*
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
'
|
819 |
-
'
|
820 |
-
'
|
821 |
-
'
|
822 |
-
'
|
823 |
-
'
|
824 |
-
'
|
825 |
-
'
|
826 |
-
'
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
$user_id = $
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
$
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
$link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
*
|
934 |
-
*
|
935 |
-
*
|
936 |
-
*
|
937 |
-
* @
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
$
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
$
|
964 |
-
|
965 |
-
$
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
$fav_count = 1;
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
$my_favs =
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
* Meta
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d
|
1099 |
-
} else {
|
1100 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
|
1101 |
-
}
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
$
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
return $metas;
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
$wpdb->query( $wpdb->prepare( "
|
1160 |
-
} else {
|
1161 |
-
|
1162 |
-
}
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
add_action( '
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
*
|
1187 |
-
*
|
1188 |
-
*
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
function
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1198 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
|
4 |
+
|
5 |
+
/* Define the slug for the component */
|
6 |
+
if ( !defined( 'BP_ACTIVITY_SLUG' ) )
|
7 |
+
define ( 'BP_ACTIVITY_SLUG', 'activity' );
|
8 |
+
|
9 |
+
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
|
10 |
+
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
|
11 |
+
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
|
12 |
+
|
13 |
+
function bp_activity_install() {
|
14 |
+
global $wpdb, $bp;
|
15 |
+
|
16 |
+
if ( !empty($wpdb->charset) )
|
17 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
18 |
+
|
19 |
+
/* Rename the old user activity cached table if needed. */
|
20 |
+
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
|
21 |
+
$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
|
22 |
+
|
23 |
+
/* Rename fields from pre BP 1.2 */
|
24 |
+
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
|
25 |
+
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
|
26 |
+
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
|
27 |
+
|
28 |
+
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
|
29 |
+
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Build the tables
|
34 |
+
*/
|
35 |
+
$sql[] = "CREATE TABLE {$bp->activity->table_name} (
|
36 |
+
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
37 |
+
user_id bigint(20) NOT NULL,
|
38 |
+
component varchar(75) NOT NULL,
|
39 |
+
type varchar(75) NOT NULL,
|
40 |
+
action text NOT NULL,
|
41 |
+
content longtext NOT NULL,
|
42 |
+
primary_link varchar(150) NOT NULL,
|
43 |
+
item_id varchar(75) NOT NULL,
|
44 |
+
secondary_item_id varchar(75) DEFAULT NULL,
|
45 |
+
date_recorded datetime NOT NULL,
|
46 |
+
hide_sitewide bool DEFAULT 0,
|
47 |
+
mptt_left int(11) NOT NULL DEFAULT 0,
|
48 |
+
mptt_right int(11) NOT NULL DEFAULT 0,
|
49 |
+
KEY date_recorded (date_recorded),
|
50 |
+
KEY user_id (user_id),
|
51 |
+
KEY item_id (item_id),
|
52 |
+
KEY secondary_item_id (secondary_item_id),
|
53 |
+
KEY component (component),
|
54 |
+
KEY type (type),
|
55 |
+
KEY mptt_left (mptt_left),
|
56 |
+
KEY mptt_right (mptt_right),
|
57 |
+
KEY hide_sitewide (hide_sitewide)
|
58 |
+
) {$charset_collate};";
|
59 |
+
|
60 |
+
$sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
|
61 |
+
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
62 |
+
activity_id bigint(20) NOT NULL,
|
63 |
+
meta_key varchar(255) DEFAULT NULL,
|
64 |
+
meta_value longtext DEFAULT NULL,
|
65 |
+
KEY activity_id (activity_id),
|
66 |
+
KEY meta_key (meta_key)
|
67 |
+
) {$charset_collate};";
|
68 |
+
|
69 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
70 |
+
dbDelta($sql);
|
71 |
+
|
72 |
+
update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
|
73 |
+
}
|
74 |
+
|
75 |
+
function bp_activity_setup_globals() {
|
76 |
+
global $bp, $current_blog;
|
77 |
+
|
78 |
+
/* Internal identifier */
|
79 |
+
$bp->activity->id = 'activity';
|
80 |
+
|
81 |
+
$bp->activity->slug = BP_ACTIVITY_SLUG;
|
82 |
+
|
83 |
+
$bp->activity->table_name = $bp->table_prefix . 'bp_activity';
|
84 |
+
$bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta';
|
85 |
+
|
86 |
+
$bp->activity->format_notification_function = 'bp_activity_format_notifications';
|
87 |
+
|
88 |
+
/* Register this in the active components array */
|
89 |
+
$bp->active_components[$bp->activity->slug] = $bp->activity->id;
|
90 |
+
|
91 |
+
do_action( 'bp_activity_setup_globals' );
|
92 |
+
}
|
93 |
+
add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
|
94 |
+
|
95 |
+
function bp_activity_check_installed() {
|
96 |
+
global $bp;
|
97 |
+
|
98 |
+
if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
|
99 |
+
bp_activity_install();
|
100 |
+
}
|
101 |
+
add_action( 'admin_menu', 'bp_activity_check_installed' );
|
102 |
+
|
103 |
+
function bp_activity_setup_root_component() {
|
104 |
+
/* Register 'activity' as a root component (for RSS feed use) */
|
105 |
+
bp_core_add_root_component( BP_ACTIVITY_SLUG );
|
106 |
+
}
|
107 |
+
add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
|
108 |
+
|
109 |
+
function bp_activity_setup_nav() {
|
110 |
+
global $bp;
|
111 |
+
|
112 |
+
/* Add 'Activity' to the main navigation */
|
113 |
+
bp_core_new_nav_item( array( 'name' => __( 'Activity', 'buddypress' ), 'slug' => $bp->activity->slug, 'position' => 10, 'screen_function' => 'bp_activity_screen_my_activity', 'default_subnav_slug' => 'just-me', 'item_css_id' => $bp->activity->id ) );
|
114 |
+
|
115 |
+
$user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
|
116 |
+
$user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
|
117 |
+
$activity_link = $user_domain . $bp->activity->slug . '/';
|
118 |
+
|
119 |
+
/* Add the subnav items to the activity nav item if we are using a theme that supports this */
|
120 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Personal', 'buddypress' ), 'slug' => 'just-me', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10 ) );
|
121 |
+
|
122 |
+
if ( bp_is_active( 'friends' ) )
|
123 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Friends', 'buddypress' ), 'slug' => BP_FRIENDS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_friends', 'position' => 20, 'item_css_id' => 'activity-friends' ) );
|
124 |
+
|
125 |
+
if ( bp_is_active( 'groups' ) )
|
126 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
|
127 |
+
|
128 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
|
129 |
+
bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
|
130 |
+
|
131 |
+
if ( $bp->current_component == $bp->activity->slug ) {
|
132 |
+
if ( bp_is_my_profile() ) {
|
133 |
+
$bp->bp_options_title = __( 'My Activity', 'buddypress' );
|
134 |
+
} else {
|
135 |
+
$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
|
136 |
+
$bp->bp_options_title = $bp->displayed_user->fullname;
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
do_action( 'bp_activity_setup_nav' );
|
141 |
+
}
|
142 |
+
add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
|
143 |
+
|
144 |
+
function bp_activity_directory_activity_setup() {
|
145 |
+
global $bp;
|
146 |
+
|
147 |
+
if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
|
148 |
+
$bp->is_directory = true;
|
149 |
+
|
150 |
+
do_action( 'bp_activity_directory_activity_setup' );
|
151 |
+
bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
|
155 |
+
|
156 |
+
|
157 |
+
/********************************************************************************
|
158 |
+
* Screen Functions
|
159 |
+
*
|
160 |
+
* Screen functions are the controllers of BuddyPress. They will execute when their
|
161 |
+
* specific URL is caught. They will first save or manipulate data using business
|
162 |
+
* functions, then pass on the user to a template file.
|
163 |
+
*/
|
164 |
+
|
165 |
+
function bp_activity_screen_my_activity() {
|
166 |
+
do_action( 'bp_activity_screen_my_activity' );
|
167 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
|
168 |
+
}
|
169 |
+
|
170 |
+
function bp_activity_screen_friends() {
|
171 |
+
global $bp;
|
172 |
+
|
173 |
+
if ( !bp_is_active( 'friends' ) )
|
174 |
+
return false;
|
175 |
+
|
176 |
+
if ( !is_super_admin() )
|
177 |
+
$bp->is_item_admin = false;
|
178 |
+
|
179 |
+
do_action( 'bp_activity_screen_friends' );
|
180 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
|
181 |
+
}
|
182 |
+
|
183 |
+
function bp_activity_screen_groups() {
|
184 |
+
global $bp;
|
185 |
+
|
186 |
+
if ( !bp_is_active( 'groups' ) )
|
187 |
+
return false;
|
188 |
+
|
189 |
+
if ( !is_super_admin() )
|
190 |
+
$bp->is_item_admin = false;
|
191 |
+
|
192 |
+
do_action( 'bp_activity_screen_groups' );
|
193 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
|
194 |
+
}
|
195 |
+
|
196 |
+
function bp_activity_screen_favorites() {
|
197 |
+
global $bp;
|
198 |
+
|
199 |
+
if ( !is_super_admin() )
|
200 |
+
$bp->is_item_admin = false;
|
201 |
+
|
202 |
+
do_action( 'bp_activity_screen_favorites' );
|
203 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
|
204 |
+
}
|
205 |
+
|
206 |
+
function bp_activity_screen_mentions() {
|
207 |
+
global $bp;
|
208 |
+
|
209 |
+
if ( !is_super_admin() )
|
210 |
+
$bp->is_item_admin = false;
|
211 |
+
|
212 |
+
do_action( 'bp_activity_screen_mentions' );
|
213 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
|
214 |
+
}
|
215 |
+
|
216 |
+
function bp_activity_screen_single_activity_permalink() {
|
217 |
+
global $bp;
|
218 |
+
|
219 |
+
if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
|
220 |
+
return false;
|
221 |
+
|
222 |
+
if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
|
223 |
+
return false;
|
224 |
+
|
225 |
+
/* Get the activity details */
|
226 |
+
$activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
|
227 |
+
|
228 |
+
if ( !$activity = $activity['activities'][0] )
|
229 |
+
bp_core_redirect( $bp->root_domain );
|
230 |
+
|
231 |
+
$has_access = true;
|
232 |
+
/* Redirect based on the type of activity */
|
233 |
+
if ( $activity->component == $bp->groups->id ) {
|
234 |
+
if ( !function_exists( 'groups_get_group' ) )
|
235 |
+
bp_core_redirect( $bp->root_domain );
|
236 |
+
|
237 |
+
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
|
238 |
+
/* Check to see if the group is not public, if so, check the user has access to see this activity */
|
239 |
+
if ( 'public' != $group->status ) {
|
240 |
+
if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
|
241 |
+
$has_access = false;
|
242 |
+
}
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
$has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
|
247 |
+
|
248 |
+
do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
|
249 |
+
|
250 |
+
if ( !$has_access ) {
|
251 |
+
bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
|
252 |
+
|
253 |
+
if ( is_user_logged_in() )
|
254 |
+
bp_core_redirect( $bp->loggedin_user->domain );
|
255 |
+
else
|
256 |
+
bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
|
257 |
+
}
|
258 |
+
|
259 |
+
bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
|
260 |
+
}
|
261 |
+
/* This screen is not attached to a nav item, so we need to add an action for it. */
|
262 |
+
add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
|
263 |
+
|
264 |
+
function bp_activity_screen_notification_settings() {
|
265 |
+
global $bp; ?>
|
266 |
+
<table class="notification-settings zebra" id="activity-notification-settings">
|
267 |
+
<thead>
|
268 |
+
<tr>
|
269 |
+
<th class="icon"></th>
|
270 |
+
<th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
|
271 |
+
<th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
|
272 |
+
<th class="no"><?php _e( 'No', 'buddypress' )?></th>
|
273 |
+
</tr>
|
274 |
+
</thead>
|
275 |
+
|
276 |
+
<tbody>
|
277 |
+
<tr>
|
278 |
+
<td></td>
|
279 |
+
<td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
|
280 |
+
<td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
|
281 |
+
<td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
|
282 |
+
</tr>
|
283 |
+
<tr>
|
284 |
+
<td></td>
|
285 |
+
<td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
|
286 |
+
<td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
|
287 |
+
<td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
|
288 |
+
</tr>
|
289 |
+
|
290 |
+
<?php do_action( 'bp_activity_screen_notification_settings' ) ?>
|
291 |
+
</tbody>
|
292 |
+
</table>
|
293 |
+
<?php
|
294 |
+
}
|
295 |
+
add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
|
296 |
+
|
297 |
+
/********************************************************************************
|
298 |
+
* Action Functions
|
299 |
+
*
|
300 |
+
* Action functions are exactly the same as screen functions, however they do not
|
301 |
+
* have a template screen associated with them. Usually they will send the user
|
302 |
+
* back to the default screen after execution.
|
303 |
+
*/
|
304 |
+
|
305 |
+
function bp_activity_action_permalink_router() {
|
306 |
+
global $bp;
|
307 |
+
|
308 |
+
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
|
309 |
+
return false;
|
310 |
+
|
311 |
+
if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
|
312 |
+
return false;
|
313 |
+
|
314 |
+
/* Get the activity details */
|
315 |
+
$activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
|
316 |
+
|
317 |
+
if ( !$activity = $activity['activities'][0] )
|
318 |
+
bp_core_redirect( $bp->root_domain );
|
319 |
+
|
320 |
+
$redirect = false;
|
321 |
+
/* Redirect based on the type of activity */
|
322 |
+
if ( $activity->component == $bp->groups->id ) {
|
323 |
+
if ( $activity->user_id )
|
324 |
+
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
|
325 |
+
else {
|
326 |
+
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
|
327 |
+
$redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
|
328 |
+
}
|
329 |
+
} else
|
330 |
+
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
|
331 |
+
|
332 |
+
$redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
|
333 |
+
|
334 |
+
if ( !$redirect )
|
335 |
+
bp_core_redirect( $bp->root_domain );
|
336 |
+
|
337 |
+
/* Redirect to the actual activity permalink page */
|
338 |
+
bp_core_redirect( $redirect );
|
339 |
+
}
|
340 |
+
add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
|
341 |
+
|
342 |
+
function bp_activity_action_delete_activity() {
|
343 |
+
global $bp;
|
344 |
+
|
345 |
+
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
|
346 |
+
return false;
|
347 |
+
|
348 |
+
if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
|
349 |
+
return false;
|
350 |
+
|
351 |
+
/* Check the nonce */
|
352 |
+
check_admin_referer( 'bp_activity_delete_link' );
|
353 |
+
|
354 |
+
$activity_id = $bp->action_variables[0];
|
355 |
+
$activity = new BP_Activity_Activity( $activity_id );
|
356 |
+
|
357 |
+
/* Check access */
|
358 |
+
if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
|
359 |
+
return false;
|
360 |
+
|
361 |
+
/* Call the action before the delete so plugins can still fetch information about it */
|
362 |
+
do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
|
363 |
+
|
364 |
+
/* Now delete the activity item */
|
365 |
+
if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
|
366 |
+
bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
|
367 |
+
else
|
368 |
+
bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
|
369 |
+
|
370 |
+
bp_core_redirect( wp_get_referer() );
|
371 |
+
}
|
372 |
+
add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
|
373 |
+
|
374 |
+
function bp_activity_action_post_update() {
|
375 |
+
global $bp;
|
376 |
+
|
377 |
+
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
|
378 |
+
return false;
|
379 |
+
|
380 |
+
/* Check the nonce */
|
381 |
+
check_admin_referer( 'post_update', '_wpnonce_post_update' );
|
382 |
+
|
383 |
+
$content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
|
384 |
+
$object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
|
385 |
+
$item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
|
386 |
+
|
387 |
+
if ( empty( $content ) ) {
|
388 |
+
bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
|
389 |
+
bp_core_redirect( wp_get_referer() );
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( !(int)$item_id ) {
|
393 |
+
$activity_id = bp_activity_post_update( array( 'content' => $content ) );
|
394 |
+
|
395 |
+
} else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
|
396 |
+
if ( (int)$item_id ) {
|
397 |
+
$activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
|
398 |
+
}
|
399 |
+
} else
|
400 |
+
$activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
|
401 |
+
|
402 |
+
if ( !empty( $activity_id ) )
|
403 |
+
bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
|
404 |
+
else
|
405 |
+
bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
|
406 |
+
|
407 |
+
bp_core_redirect( wp_get_referer() );
|
408 |
+
}
|
409 |
+
add_action( 'wp', 'bp_activity_action_post_update', 3 );
|
410 |
+
|
411 |
+
function bp_activity_action_post_comment() {
|
412 |
+
global $bp;
|
413 |
+
|
414 |
+
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
|
415 |
+
return false;
|
416 |
+
|
417 |
+
/* Check the nonce */
|
418 |
+
check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
|
419 |
+
|
420 |
+
$activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
|
421 |
+
$content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
|
422 |
+
|
423 |
+
if ( empty( $content ) ) {
|
424 |
+
bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
|
425 |
+
bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
|
426 |
+
}
|
427 |
+
|
428 |
+
$comment_id = bp_activity_new_comment( array(
|
429 |
+
'content' => $content,
|
430 |
+
'activity_id' => $activity_id,
|
431 |
+
'parent_id' => $parent_id
|
432 |
+
));
|
433 |
+
|
434 |
+
if ( !empty( $comment_id ) )
|
435 |
+
bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
|
436 |
+
else
|
437 |
+
bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
|
438 |
+
|
439 |
+
bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
|
440 |
+
}
|
441 |
+
add_action( 'wp', 'bp_activity_action_post_comment', 3 );
|
442 |
+
|
443 |
+
function bp_activity_action_mark_favorite() {
|
444 |
+
global $bp;
|
445 |
+
|
446 |
+
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
|
447 |
+
return false;
|
448 |
+
|
449 |
+
/* Check the nonce */
|
450 |
+
check_admin_referer( 'mark_favorite' );
|
451 |
+
|
452 |
+
if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
|
453 |
+
bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
|
454 |
+
else
|
455 |
+
bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
|
456 |
+
|
457 |
+
bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
|
458 |
+
}
|
459 |
+
add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
|
460 |
+
|
461 |
+
function bp_activity_action_remove_favorite() {
|
462 |
+
global $bp;
|
463 |
+
|
464 |
+
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
|
465 |
+
return false;
|
466 |
+
|
467 |
+
/* Check the nonce */
|
468 |
+
check_admin_referer( 'unmark_favorite' );
|
469 |
+
|
470 |
+
if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
|
471 |
+
bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
|
472 |
+
else
|
473 |
+
bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
|
474 |
+
|
475 |
+
bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
|
476 |
+
}
|
477 |
+
add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
|
478 |
+
|
479 |
+
function bp_activity_action_sitewide_feed() {
|
480 |
+
global $bp, $wp_query;
|
481 |
+
|
482 |
+
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
|
483 |
+
return false;
|
484 |
+
|
485 |
+
$wp_query->is_404 = false;
|
486 |
+
status_header( 200 );
|
487 |
+
|
488 |
+
include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
|
489 |
+
die;
|
490 |
+
}
|
491 |
+
add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
|
492 |
+
|
493 |
+
function bp_activity_action_personal_feed() {
|
494 |
+
global $bp, $wp_query;
|
495 |
+
|
496 |
+
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
|
497 |
+
return false;
|
498 |
+
|
499 |
+
$wp_query->is_404 = false;
|
500 |
+
status_header( 200 );
|
501 |
+
|
502 |
+
include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
|
503 |
+
die;
|
504 |
+
}
|
505 |
+
add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
|
506 |
+
|
507 |
+
function bp_activity_action_friends_feed() {
|
508 |
+
global $bp, $wp_query;
|
509 |
+
|
510 |
+
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
|
511 |
+
return false;
|
512 |
+
|
513 |
+
$wp_query->is_404 = false;
|
514 |
+
status_header( 200 );
|
515 |
+
|
516 |
+
include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
|
517 |
+
die;
|
518 |
+
}
|
519 |
+
add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
|
520 |
+
|
521 |
+
function bp_activity_action_my_groups_feed() {
|
522 |
+
global $bp, $wp_query;
|
523 |
+
|
524 |
+
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
|
525 |
+
return false;
|
526 |
+
|
527 |
+
$wp_query->is_404 = false;
|
528 |
+
status_header( 200 );
|
529 |
+
|
530 |
+
include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
|
531 |
+
die;
|
532 |
+
}
|
533 |
+
add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
|
534 |
+
|
535 |
+
function bp_activity_action_mentions_feed() {
|
536 |
+
global $bp, $wp_query;
|
537 |
+
|
538 |
+
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
|
539 |
+
return false;
|
540 |
+
|
541 |
+
$wp_query->is_404 = false;
|
542 |
+
status_header( 200 );
|
543 |
+
|
544 |
+
include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
|
545 |
+
die;
|
546 |
+
}
|
547 |
+
add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
|
548 |
+
|
549 |
+
function bp_activity_action_favorites_feed() {
|
550 |
+
global $bp, $wp_query;
|
551 |
+
|
552 |
+
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
|
553 |
+
return false;
|
554 |
+
|
555 |
+
$wp_query->is_404 = false;
|
556 |
+
status_header( 200 );
|
557 |
+
|
558 |
+
include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
|
559 |
+
die;
|
560 |
+
}
|
561 |
+
add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
|
562 |
+
|
563 |
+
/********************************************************************************
|
564 |
+
* Business Functions
|
565 |
+
*
|
566 |
+
* Business functions are where all the magic happens in BuddyPress. They will
|
567 |
+
* handle the actual saving or manipulation of information. Usually they will
|
568 |
+
* hand off to a database class for data access, then return
|
569 |
+
* true or false on success or failure.
|
570 |
+
*/
|
571 |
+
|
572 |
+
function bp_activity_get( $args = '' ) {
|
573 |
+
$defaults = array(
|
574 |
+
'max' => false, // Maximum number of results to return
|
575 |
+
'page' => 1, // page 1 without a per_page will result in no pagination.
|
576 |
+
'per_page' => false, // results per page
|
577 |
+
'sort' => 'DESC', // sort ASC or DESC
|
578 |
+
'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
|
579 |
+
|
580 |
+
'search_terms' => false, // Pass search terms as a string
|
581 |
+
'show_hidden' => false, // Show activity items that are hidden site-wide?
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Pass filters as an array -- all filter items can be multiple values comma separated:
|
585 |
+
* array(
|
586 |
+
* 'user_id' => false, // user_id to filter on
|
587 |
+
* 'object' => false, // object to filter on e.g. groups, profile, status, friends
|
588 |
+
* 'action' => false, // action to filter on e.g. activity_update, profile_updated
|
589 |
+
* 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
|
590 |
+
* 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
|
591 |
+
* );
|
592 |
+
*/
|
593 |
+
'filter' => array()
|
594 |
+
);
|
595 |
+
|
596 |
+
$r = wp_parse_args( $args, $defaults );
|
597 |
+
extract( $r, EXTR_SKIP );
|
598 |
+
|
599 |
+
/* Attempt to return a cached copy of the first page of sitewide activity. */
|
600 |
+
if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
|
601 |
+
if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
|
602 |
+
$activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
|
603 |
+
wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
|
604 |
+
}
|
605 |
+
} else
|
606 |
+
$activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
|
607 |
+
|
608 |
+
return apply_filters( 'bp_activity_get', $activity, &$r );
|
609 |
+
}
|
610 |
+
|
611 |
+
function bp_activity_get_specific( $args = '' ) {
|
612 |
+
$defaults = array(
|
613 |
+
'activity_ids' => false, // A single activity_id or array of IDs.
|
614 |
+
'page' => 1, // page 1 without a per_page will result in no pagination.
|
615 |
+
'per_page' => false, // results per page
|
616 |
+
'max' => false, // Maximum number of results to return
|
617 |
+
'sort' => 'DESC', // sort ASC or DESC
|
618 |
+
'display_comments' => false // true or false to display threaded comments for these specific activity items
|
619 |
+
);
|
620 |
+
|
621 |
+
$r = wp_parse_args( $args, $defaults );
|
622 |
+
extract( $r, EXTR_SKIP );
|
623 |
+
|
624 |
+
return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
|
625 |
+
}
|
626 |
+
|
627 |
+
function bp_activity_add( $args = '' ) {
|
628 |
+
global $bp;
|
629 |
+
|
630 |
+
$defaults = array(
|
631 |
+
'id' => false, // Pass an existing activity ID to update an existing entry.
|
632 |
+
|
633 |
+
'action' => '', // The activity action - e.g. "Jon Doe posted an update"
|
634 |
+
'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
|
635 |
+
|
636 |
+
'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
|
637 |
+
'type' => false, // The activity type e.g. activity_update, profile_updated
|
638 |
+
'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
|
639 |
+
|
640 |
+
'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
|
641 |
+
'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
|
642 |
+
'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
|
643 |
+
'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
|
644 |
+
'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
|
645 |
+
);
|
646 |
+
|
647 |
+
$params = wp_parse_args( $args, $defaults );
|
648 |
+
extract( $params, EXTR_SKIP );
|
649 |
+
|
650 |
+
/* Make sure we are backwards compatible */
|
651 |
+
if ( empty( $component ) && !empty( $component_name ) )
|
652 |
+
$component = $component_name;
|
653 |
+
|
654 |
+
if ( empty( $type ) && !empty( $component_action ) )
|
655 |
+
$type = $component_action;
|
656 |
+
|
657 |
+
$activity = new BP_Activity_Activity( $id );
|
658 |
+
|
659 |
+
$activity->user_id = $user_id;
|
660 |
+
$activity->component = $component;
|
661 |
+
$activity->type = $type;
|
662 |
+
$activity->action = $action;
|
663 |
+
$activity->content = $content;
|
664 |
+
$activity->primary_link = $primary_link;
|
665 |
+
$activity->item_id = $item_id;
|
666 |
+
$activity->secondary_item_id = $secondary_item_id;
|
667 |
+
$activity->date_recorded = $recorded_time;
|
668 |
+
$activity->hide_sitewide = $hide_sitewide;
|
669 |
+
|
670 |
+
if ( !$activity->save() )
|
671 |
+
return false;
|
672 |
+
|
673 |
+
/* If this is an activity comment, rebuild the tree */
|
674 |
+
if ( 'activity_comment' == $activity->type )
|
675 |
+
BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
|
676 |
+
|
677 |
+
wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
|
678 |
+
do_action( 'bp_activity_add', $params );
|
679 |
+
|
680 |
+
return $activity->id;
|
681 |
+
}
|
682 |
+
|
683 |
+
function bp_activity_post_update( $args = '' ) {
|
684 |
+
global $bp;
|
685 |
+
|
686 |
+
$defaults = array(
|
687 |
+
'content' => false,
|
688 |
+
'user_id' => $bp->loggedin_user->id
|
689 |
+
);
|
690 |
+
|
691 |
+
$r = wp_parse_args( $args, $defaults );
|
692 |
+
extract( $r, EXTR_SKIP );
|
693 |
+
|
694 |
+
if ( empty( $content ) || !strlen( trim( $content ) ) )
|
695 |
+
return false;
|
696 |
+
|
697 |
+
/* Record this on the user's profile */
|
698 |
+
$from_user_link = bp_core_get_userlink( $user_id );
|
699 |
+
$activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
|
700 |
+
$activity_content = $content;
|
701 |
+
|
702 |
+
$primary_link = bp_core_get_userlink( $user_id, false, true );
|
703 |
+
|
704 |
+
/* Now write the values */
|
705 |
+
$activity_id = bp_activity_add( array(
|
706 |
+
'user_id' => $user_id,
|
707 |
+
'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
|
708 |
+
'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
|
709 |
+
'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
|
710 |
+
'component' => $bp->activity->id,
|
711 |
+
'type' => 'activity_update'
|
712 |
+
) );
|
713 |
+
|
714 |
+
/* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
|
715 |
+
update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
|
716 |
+
|
717 |
+
/* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
|
718 |
+
require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
|
719 |
+
|
720 |
+
do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
|
721 |
+
|
722 |
+
return $activity_id;
|
723 |
+
}
|
724 |
+
|
725 |
+
function bp_activity_new_comment( $args = '' ) {
|
726 |
+
global $bp;
|
727 |
+
|
728 |
+
$defaults = array(
|
729 |
+
'id' => false,
|
730 |
+
'content' => false,
|
731 |
+
'user_id' => $bp->loggedin_user->id,
|
732 |
+
'activity_id' => false, // ID of the root activity item
|
733 |
+
'parent_id' => false // ID of a parent comment (optional)
|
734 |
+
);
|
735 |
+
|
736 |
+
$params = wp_parse_args( $args, $defaults );
|
737 |
+
extract( $params, EXTR_SKIP );
|
738 |
+
|
739 |
+
if ( empty($content) || empty($user_id) || empty($activity_id) )
|
740 |
+
return false;
|
741 |
+
|
742 |
+
if ( empty($parent_id) )
|
743 |
+
$parent_id = $activity_id;
|
744 |
+
|
745 |
+
/* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
|
746 |
+
$activity = new BP_Activity_Activity( $activity_id );
|
747 |
+
$is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
|
748 |
+
|
749 |
+
/* Insert the activity comment */
|
750 |
+
$comment_id = bp_activity_add( array(
|
751 |
+
'id' => $id,
|
752 |
+
'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
|
753 |
+
'content' => apply_filters( 'bp_activity_comment_content', $content ),
|
754 |
+
'component' => $bp->activity->id,
|
755 |
+
'type' => 'activity_comment',
|
756 |
+
'user_id' => $user_id,
|
757 |
+
'item_id' => $activity_id,
|
758 |
+
'secondary_item_id' => $parent_id,
|
759 |
+
'hide_sitewide' => $is_hidden
|
760 |
+
) );
|
761 |
+
|
762 |
+
/* Send an email notification if settings allow */
|
763 |
+
require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
|
764 |
+
bp_activity_new_comment_notification( $comment_id, $user_id, $params );
|
765 |
+
|
766 |
+
/* Clear the comment cache for this activity */
|
767 |
+
wp_cache_delete( 'bp_activity_comments_' . $parent_id );
|
768 |
+
|
769 |
+
do_action( 'bp_activity_comment_posted', $comment_id, $params );
|
770 |
+
|
771 |
+
return $comment_id;
|
772 |
+
}
|
773 |
+
|
774 |
+
/**
|
775 |
+
* bp_activity_get_activity_id()
|
776 |
+
*
|
777 |
+
* Fetch the activity_id for an existing activity entry in the DB.
|
778 |
+
*
|
779 |
+
* @package BuddyPress Activity
|
780 |
+
*/
|
781 |
+
function bp_activity_get_activity_id( $args = '' ) {
|
782 |
+
$defaults = array(
|
783 |
+
'user_id' => false,
|
784 |
+
'component' => false,
|
785 |
+
'type' => false,
|
786 |
+
'item_id' => false,
|
787 |
+
'secondary_item_id' => false,
|
788 |
+
'action' => false,
|
789 |
+
'content' => false,
|
790 |
+
'date_recorded' => false,
|
791 |
+
);
|
792 |
+
|
793 |
+
$r = wp_parse_args( $args, $defaults );
|
794 |
+
extract( $r, EXTR_SKIP );
|
795 |
+
|
796 |
+
return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
|
797 |
+
}
|
798 |
+
|
799 |
+
/***
|
800 |
+
* Deleting Activity
|
801 |
+
*
|
802 |
+
* If you're looking to hook into one action that provides the ID(s) of
|
803 |
+
* the activity/activities deleted, then use:
|
804 |
+
*
|
805 |
+
* add_action( 'bp_activity_deleted_activities', 'my_function' );
|
806 |
+
*
|
807 |
+
* The action passes one parameter that is a single activity ID or an
|
808 |
+
* array of activity IDs depending on the number deleted.
|
809 |
+
*
|
810 |
+
* If you are deleting an activity comment please use bp_activity_delete_comment();
|
811 |
+
*/
|
812 |
+
|
813 |
+
function bp_activity_delete( $args = '' ) {
|
814 |
+
global $bp;
|
815 |
+
|
816 |
+
/* Pass one or more the of following variables to delete by those variables */
|
817 |
+
$defaults = array(
|
818 |
+
'id' => false,
|
819 |
+
'action' => false,
|
820 |
+
'content' => false,
|
821 |
+
'component' => false,
|
822 |
+
'type' => false,
|
823 |
+
'primary_link' => false,
|
824 |
+
'user_id' => false,
|
825 |
+
'item_id' => false,
|
826 |
+
'secondary_item_id' => false,
|
827 |
+
'date_recorded' => false,
|
828 |
+
'hide_sitewide' => false
|
829 |
+
);
|
830 |
+
|
831 |
+
$args = wp_parse_args( $args, $defaults );
|
832 |
+
|
833 |
+
if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
|
834 |
+
return false;
|
835 |
+
|
836 |
+
/* Check if the user's latest update has been deleted */
|
837 |
+
if ( empty( $args['user_id'] ) )
|
838 |
+
$user_id = $bp->loggedin_user->id;
|
839 |
+
else
|
840 |
+
$user_id = $args['user_id'];
|
841 |
+
|
842 |
+
$latest_update = get_user_meta( $user_id, 'bp_latest_update', true );
|
843 |
+
if ( !empty( $latest_update ) ) {
|
844 |
+
if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
|
845 |
+
delete_user_meta( $user_id, 'bp_latest_update' );
|
846 |
+
}
|
847 |
+
|
848 |
+
do_action( 'bp_activity_delete', $args );
|
849 |
+
do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
|
850 |
+
|
851 |
+
wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
|
852 |
+
|
853 |
+
return true;
|
854 |
+
}
|
855 |
+
/* The following functions have been deprecated in place of bp_activity_delete() */
|
856 |
+
function bp_activity_delete_by_item_id( $args = '' ) {
|
857 |
+
global $bp;
|
858 |
+
|
859 |
+
$defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
|
860 |
+
$r = wp_parse_args( $args, $defaults );
|
861 |
+
extract( $r, EXTR_SKIP );
|
862 |
+
|
863 |
+
return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
|
864 |
+
}
|
865 |
+
|
866 |
+
function bp_activity_delete_by_activity_id( $activity_id ) {
|
867 |
+
return bp_activity_delete( array( 'id' => $activity_id ) );
|
868 |
+
}
|
869 |
+
|
870 |
+
function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
|
871 |
+
return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
|
872 |
+
}
|
873 |
+
|
874 |
+
function bp_activity_delete_for_user_by_component( $user_id, $component ) {
|
875 |
+
return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
|
876 |
+
}
|
877 |
+
/* End deprecation */
|
878 |
+
|
879 |
+
function bp_activity_delete_comment( $activity_id, $comment_id ) {
|
880 |
+
/***
|
881 |
+
* You may want to hook into this filter if you want to override this function and
|
882 |
+
* handle the deletion of child comments differently. Make sure you return false.
|
883 |
+
*/
|
884 |
+
if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
|
885 |
+
return false;
|
886 |
+
|
887 |
+
/* Delete any children of this comment. */
|
888 |
+
bp_activity_delete_children( $activity_id, $comment_id );
|
889 |
+
|
890 |
+
/* Delete the actual comment */
|
891 |
+
if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
|
892 |
+
return false;
|
893 |
+
|
894 |
+
/* Recalculate the comment tree */
|
895 |
+
BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
|
896 |
+
|
897 |
+
do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
|
898 |
+
|
899 |
+
return true;
|
900 |
+
}
|
901 |
+
function bp_activity_delete_children( $activity_id, $comment_id) {
|
902 |
+
/* Recursively delete all children of this comment. */
|
903 |
+
if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
|
904 |
+
foreach( (array)$children as $child )
|
905 |
+
bp_activity_delete_children( $activity_id, $child->id );
|
906 |
+
}
|
907 |
+
bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
|
908 |
+
}
|
909 |
+
|
910 |
+
function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
|
911 |
+
global $bp;
|
912 |
+
|
913 |
+
if ( !$activity_obj )
|
914 |
+
$activity_obj = new BP_Activity_Activity( $activity_id );
|
915 |
+
|
916 |
+
if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type )
|
917 |
+
$link = $activity_obj->primary_link;
|
918 |
+
else {
|
919 |
+
if ( 'activity_comment' == $activity_obj->type )
|
920 |
+
$link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
|
921 |
+
else
|
922 |
+
$link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
|
923 |
+
}
|
924 |
+
|
925 |
+
return apply_filters( 'bp_activity_get_permalink', $link );
|
926 |
+
}
|
927 |
+
|
928 |
+
function bp_activity_hide_user_activity( $user_id ) {
|
929 |
+
return BP_Activity_Activity::hide_all_for_user( $user_id );
|
930 |
+
}
|
931 |
+
|
932 |
+
/**
|
933 |
+
* bp_activity_thumbnail_content_images()
|
934 |
+
*
|
935 |
+
* Take content, remove all images and replace them with one thumbnail image.
|
936 |
+
*
|
937 |
+
* @package BuddyPress Activity
|
938 |
+
* @param $content str - The content to work with
|
939 |
+
* @return $content str - The content with images stripped and replaced with a single thumb.
|
940 |
+
*/
|
941 |
+
function bp_activity_thumbnail_content_images( $content ) {
|
942 |
+
preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
|
943 |
+
$content = preg_replace('/<img[^>]*>/Ui', '', $content );
|
944 |
+
|
945 |
+
if ( !empty( $matches ) ) {
|
946 |
+
/* Get the SRC value */
|
947 |
+
preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
|
948 |
+
|
949 |
+
/* Get the width and height */
|
950 |
+
preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
|
951 |
+
preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
|
952 |
+
|
953 |
+
if ( !empty( $src ) ) {
|
954 |
+
$src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
|
955 |
+
$height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
|
956 |
+
$width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
|
957 |
+
|
958 |
+
if ( empty( $width ) || empty( $height ) ) {
|
959 |
+
$width = 100;
|
960 |
+
$height = 100;
|
961 |
+
}
|
962 |
+
|
963 |
+
$ratio = (int)$width / (int)$height;
|
964 |
+
$new_height = 100;
|
965 |
+
$new_width = $new_height * $ratio;
|
966 |
+
|
967 |
+
$content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
|
968 |
+
}
|
969 |
+
}
|
970 |
+
|
971 |
+
return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
|
972 |
+
}
|
973 |
+
|
974 |
+
function bp_activity_set_action( $component_id, $key, $value ) {
|
975 |
+
global $bp;
|
976 |
+
|
977 |
+
if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
|
978 |
+
return false;
|
979 |
+
|
980 |
+
$bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
|
981 |
+
'key' => $key,
|
982 |
+
'value' => $value
|
983 |
+
), $component_id, $key, $value );
|
984 |
+
}
|
985 |
+
|
986 |
+
function bp_activity_get_action( $component_id, $key ) {
|
987 |
+
global $bp;
|
988 |
+
|
989 |
+
if ( empty( $component_id ) || empty( $key ) )
|
990 |
+
return false;
|
991 |
+
|
992 |
+
return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
|
993 |
+
}
|
994 |
+
|
995 |
+
function bp_activity_get_user_favorites( $user_id ) {
|
996 |
+
$my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
|
997 |
+
$existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
|
998 |
+
|
999 |
+
foreach( (array)$existing_favs['activities'] as $fav )
|
1000 |
+
$new_favs[] = $fav->id;
|
1001 |
+
|
1002 |
+
$new_favs = array_unique( (array)$new_favs );
|
1003 |
+
update_user_meta( $user_id, 'bp_favorite_activities', $new_favs );
|
1004 |
+
|
1005 |
+
return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
|
1006 |
+
}
|
1007 |
+
|
1008 |
+
function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
|
1009 |
+
global $bp;
|
1010 |
+
|
1011 |
+
if ( !$user_id )
|
1012 |
+
$user_id = $bp->loggedin_user->id;
|
1013 |
+
|
1014 |
+
/* Update the user's personal favorites */
|
1015 |
+
$my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
|
1016 |
+
$my_favs[] = $activity_id;
|
1017 |
+
|
1018 |
+
/* Update the total number of users who have favorited this activity */
|
1019 |
+
$fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
|
1020 |
+
|
1021 |
+
if ( !empty( $fav_count ) )
|
1022 |
+
$fav_count = (int)$fav_count + 1;
|
1023 |
+
else
|
1024 |
+
$fav_count = 1;
|
1025 |
+
|
1026 |
+
update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
|
1027 |
+
bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
|
1028 |
+
|
1029 |
+
do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
|
1030 |
+
|
1031 |
+
return true;
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
|
1035 |
+
global $bp;
|
1036 |
+
|
1037 |
+
if ( !$user_id )
|
1038 |
+
$user_id = $bp->loggedin_user->id;
|
1039 |
+
|
1040 |
+
/* Remove the fav from the user's favs */
|
1041 |
+
$my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
|
1042 |
+
$my_favs = array_flip( (array) $my_favs );
|
1043 |
+
unset( $my_favs[$activity_id] );
|
1044 |
+
$my_favs = array_unique( array_flip( $my_favs ) );
|
1045 |
+
|
1046 |
+
/* Update the total number of users who have favorited this activity */
|
1047 |
+
$fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
|
1048 |
+
|
1049 |
+
if ( !empty( $fav_count ) ) {
|
1050 |
+
$fav_count = (int)$fav_count - 1;
|
1051 |
+
bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
|
1055 |
+
|
1056 |
+
do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
|
1057 |
+
|
1058 |
+
return true;
|
1059 |
+
}
|
1060 |
+
|
1061 |
+
function bp_activity_check_exists_by_content( $content ) {
|
1062 |
+
return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
function bp_activity_get_last_updated() {
|
1066 |
+
return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
function bp_activity_total_favorites_for_user( $user_id = false ) {
|
1070 |
+
global $bp;
|
1071 |
+
|
1072 |
+
if ( !$user_id )
|
1073 |
+
$user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
|
1074 |
+
|
1075 |
+
return BP_Activity_Activity::total_favorite_count( $user_id );
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
/********************************************************************************
|
1079 |
+
* Activity Meta Functions
|
1080 |
+
*
|
1081 |
+
* Meta functions allow you to store extra data for a particular item.
|
1082 |
+
*/
|
1083 |
+
|
1084 |
+
function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
|
1085 |
+
global $wpdb, $bp;
|
1086 |
+
|
1087 |
+
if ( !is_numeric( $activity_id ) )
|
1088 |
+
return false;
|
1089 |
+
|
1090 |
+
$meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
|
1091 |
+
|
1092 |
+
if ( is_array( $meta_value ) || is_object( $meta_value ) )
|
1093 |
+
$meta_value = serialize( $meta_value );
|
1094 |
+
|
1095 |
+
$meta_value = trim( $meta_value );
|
1096 |
+
|
1097 |
+
if ( !$meta_key ) {
|
1098 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
|
1099 |
+
} else if ( $meta_value ) {
|
1100 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value ) );
|
1101 |
+
} else {
|
1102 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
|
1103 |
+
}
|
1104 |
+
|
1105 |
+
wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
|
1106 |
+
|
1107 |
+
return true;
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
|
1111 |
+
global $wpdb, $bp;
|
1112 |
+
|
1113 |
+
$activity_id = (int)$activity_id;
|
1114 |
+
|
1115 |
+
if ( !$activity_id )
|
1116 |
+
return false;
|
1117 |
+
|
1118 |
+
if ( !empty($meta_key) ) {
|
1119 |
+
$meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
|
1120 |
+
|
1121 |
+
if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
|
1122 |
+
$metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
|
1123 |
+
wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
|
1124 |
+
}
|
1125 |
+
} else
|
1126 |
+
$metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
|
1127 |
+
|
1128 |
+
if ( empty($metas) )
|
1129 |
+
return false;
|
1130 |
+
|
1131 |
+
$metas = array_map( 'maybe_unserialize', (array)$metas );
|
1132 |
+
|
1133 |
+
if ( 1 == count($metas) )
|
1134 |
+
return $metas[0];
|
1135 |
+
else
|
1136 |
+
return $metas;
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
|
1140 |
+
global $wpdb, $bp;
|
1141 |
+
|
1142 |
+
if ( !is_numeric( $activity_id ) )
|
1143 |
+
return false;
|
1144 |
+
|
1145 |
+
$meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
|
1146 |
+
|
1147 |
+
if ( is_string( $meta_value ) )
|
1148 |
+
$meta_value = stripslashes( $wpdb->escape( $meta_value ) );
|
1149 |
+
|
1150 |
+
$meta_value = maybe_serialize( $meta_value );
|
1151 |
+
|
1152 |
+
if ( empty( $meta_value ) ) {
|
1153 |
+
return bp_activity_delete_meta( $activity_id, $meta_key );
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
$cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
|
1157 |
+
|
1158 |
+
if ( !$cur ) {
|
1159 |
+
$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ) );
|
1160 |
+
} else if ( $cur->meta_value != $meta_value ) {
|
1161 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name_meta} SET meta_value = %s WHERE activity_id = %d AND meta_key = %s", $meta_value, $activity_id, $meta_key ) );
|
1162 |
+
} else {
|
1163 |
+
return false;
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
|
1167 |
+
|
1168 |
+
return true;
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
function bp_activity_remove_data( $user_id ) {
|
1172 |
+
// Clear the user's activity from the sitewide stream and clear their activity tables
|
1173 |
+
bp_activity_delete( array( 'user_id' => $user_id ) );
|
1174 |
+
|
1175 |
+
// Remove any usermeta
|
1176 |
+
delete_user_meta( $user_id, 'bp_latest_update' );
|
1177 |
+
delete_user_meta( $user_id, 'bp_favorite_activities' );
|
1178 |
+
|
1179 |
+
do_action( 'bp_activity_remove_data', $user_id );
|
1180 |
+
}
|
1181 |
+
add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
|
1182 |
+
add_action( 'delete_user', 'bp_activity_remove_data' );
|
1183 |
+
add_action( 'make_spam_user', 'bp_activity_remove_data' );
|
1184 |
+
|
1185 |
+
/**
|
1186 |
+
* updates_register_activity_actions()
|
1187 |
+
*
|
1188 |
+
* Register the activity stream actions for updates
|
1189 |
+
*
|
1190 |
+
* @global array $bp
|
1191 |
+
*/
|
1192 |
+
function updates_register_activity_actions() {
|
1193 |
+
global $bp;
|
1194 |
+
|
1195 |
+
bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) );
|
1196 |
+
|
1197 |
+
do_action( 'updates_register_activity_actions' );
|
1198 |
+
}
|
1199 |
+
add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' );
|
1200 |
+
|
1201 |
+
/********************************************************************************
|
1202 |
+
* Custom Actions
|
1203 |
+
*
|
1204 |
+
* Functions to set up custom BuddyPress actions that all other components can
|
1205 |
+
* hook in to.
|
1206 |
+
*/
|
1207 |
+
|
1208 |
+
/* Allow core components and dependent plugins to register activity actions */
|
1209 |
+
function bp_register_activity_actions() {
|
1210 |
+
do_action( 'bp_register_activity_actions' );
|
1211 |
+
}
|
1212 |
+
add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
|
1213 |
+
|
1214 |
+
|
1215 |
?>
|
bp-activity/bp-activity-classes.php
CHANGED
@@ -1,553 +1,553 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
Class BP_Activity_Activity {
|
4 |
-
var $id;
|
5 |
-
var $item_id;
|
6 |
-
var $secondary_item_id;
|
7 |
-
var $user_id;
|
8 |
-
var $primary_link;
|
9 |
-
var $component;
|
10 |
-
var $type;
|
11 |
-
var $action;
|
12 |
-
var $content;
|
13 |
-
var $date_recorded;
|
14 |
-
var $hide_sitewide = false;
|
15 |
-
|
16 |
-
function bp_activity_activity( $id = false ) {
|
17 |
-
global $bp;
|
18 |
-
|
19 |
-
if ( $id ) {
|
20 |
-
$this->id = $id;
|
21 |
-
$this->populate();
|
22 |
-
}
|
23 |
-
}
|
24 |
-
|
25 |
-
function populate() {
|
26 |
-
global $wpdb, $bp;
|
27 |
-
|
28 |
-
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
|
29 |
-
if ( $row ) {
|
30 |
-
$this->id = $row->id;
|
31 |
-
$this->item_id = $row->item_id;
|
32 |
-
$this->secondary_item_id = $row->secondary_item_id;
|
33 |
-
$this->user_id = $row->user_id;
|
34 |
-
$this->primary_link = $row->primary_link;
|
35 |
-
$this->component = $row->component;
|
36 |
-
$this->type = $row->type;
|
37 |
-
$this->action = $row->action;
|
38 |
-
$this->content = $row->content;
|
39 |
-
$this->date_recorded = $row->date_recorded;
|
40 |
-
$this->hide_sitewide = $row->hide_sitewide;
|
41 |
-
$this->mptt_left = $row->mptt_left;
|
42 |
-
$this->mptt_right = $row->mptt_right;
|
43 |
-
}
|
44 |
-
}
|
45 |
-
|
46 |
-
function save() {
|
47 |
-
global $wpdb, $bp, $current_user;
|
48 |
-
|
49 |
-
do_action( 'bp_activity_before_save', &$this );
|
50 |
-
|
51 |
-
$this->id = apply_filters( 'bp_activity_id_before_save', $this->id, &$this );
|
52 |
-
$this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id, &$this );
|
53 |
-
$this->secondary_item_id = apply_filters( 'bp_activity_secondary_item_id_before_save', $this->secondary_item_id, &$this );
|
54 |
-
$this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id, &$this );
|
55 |
-
$this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link, &$this );
|
56 |
-
$this->component = apply_filters( 'bp_activity_component_before_save', $this->component, &$this );
|
57 |
-
$this->type = apply_filters( 'bp_activity_type_before_save', $this->type, &$this );
|
58 |
-
$this->action = apply_filters( 'bp_activity_action_before_save', $this->action, &$this );
|
59 |
-
$this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );
|
60 |
-
$this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded, &$this );
|
61 |
-
$this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide, &$this );
|
62 |
-
$this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left, &$this );
|
63 |
-
$this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right, &$this );
|
64 |
-
|
65 |
-
if ( !$this->component || !$this->type )
|
66 |
-
return false;
|
67 |
-
|
68 |
-
if ( !$this->primary_link )
|
69 |
-
$this->primary_link = $bp->loggedin_user->domain;
|
70 |
-
|
71 |
-
/* If we have an existing ID, update the activity item, otherwise insert it. */
|
72 |
-
if ( $this->id )
|
73 |
-
$q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
|
74 |
-
else
|
75 |
-
$q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
|
76 |
-
|
77 |
-
if ( !$wpdb->query( $q ) )
|
78 |
-
return false;
|
79 |
-
|
80 |
-
if ( empty( $this->id ) )
|
81 |
-
$this->id = $wpdb->insert_id;
|
82 |
-
|
83 |
-
do_action( 'bp_activity_after_save', &$this );
|
84 |
-
return true;
|
85 |
-
}
|
86 |
-
|
87 |
-
/* Static Functions */
|
88 |
-
|
89 |
-
function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
|
90 |
-
global $wpdb, $bp;
|
91 |
-
|
92 |
-
/* Select conditions */
|
93 |
-
$select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
|
94 |
-
|
95 |
-
$from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
|
96 |
-
|
97 |
-
/* Where conditions */
|
98 |
-
$where_conditions = array();
|
99 |
-
|
100 |
-
/* Searching */
|
101 |
-
if ( $search_terms ) {
|
102 |
-
$search_terms = $wpdb->escape( $search_terms );
|
103 |
-
$where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
|
104 |
-
}
|
105 |
-
|
106 |
-
/* Filtering */
|
107 |
-
if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
|
108 |
-
$where_conditions['filter_sql'] = $filter_sql;
|
109 |
-
|
110 |
-
/* Sorting */
|
111 |
-
if ( $sort != 'ASC' && $sort != 'DESC' )
|
112 |
-
$sort = 'DESC';
|
113 |
-
|
114 |
-
/* Hide Hidden Items? */
|
115 |
-
if ( !$show_hidden )
|
116 |
-
$where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
|
117 |
-
|
118 |
-
/* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
|
119 |
-
if ( !$display_comments || 'threaded' == $display_comments ) {
|
120 |
-
$where_conditions[] = "a.type != 'activity_comment'";
|
121 |
-
}
|
122 |
-
|
123 |
-
$where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
|
124 |
-
|
125 |
-
if ( $per_page && $page ) {
|
126 |
-
$pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
|
127 |
-
$activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
|
128 |
-
} else
|
129 |
-
$activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
|
130 |
-
|
131 |
-
$total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
|
132 |
-
|
133 |
-
/* Get the fullnames of users so we don't have to query in the loop */
|
134 |
-
if ( function_exists( 'xprofile_install' ) && $activities ) {
|
135 |
-
foreach ( (array)$activities as $activity ) {
|
136 |
-
if ( (int)$activity->user_id )
|
137 |
-
$activity_user_ids[] = $activity->user_id;
|
138 |
-
}
|
139 |
-
|
140 |
-
$activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
|
141 |
-
if ( !empty( $activity_user_ids ) ) {
|
142 |
-
if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
|
143 |
-
foreach ( (array)$names as $name )
|
144 |
-
$tmp_names[$name->user_id] = $name->user_fullname;
|
145 |
-
|
146 |
-
foreach ( (array)$activities as $i => $activity ) {
|
147 |
-
if ( !empty( $tmp_names[$activity->user_id] ) )
|
148 |
-
$activities[$i]->user_fullname = $tmp_names[$activity->user_id];
|
149 |
-
}
|
150 |
-
|
151 |
-
unset( $names );
|
152 |
-
unset( $tmp_names );
|
153 |
-
}
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
if ( $activities && $display_comments )
|
158 |
-
$activities = BP_Activity_Activity::append_comments( &$activities );
|
159 |
-
|
160 |
-
/* If $max is set, only return up to the max results */
|
161 |
-
if ( !empty( $max ) ) {
|
162 |
-
if ( (int)$total_activities > (int)$max )
|
163 |
-
$total_activities = $max;
|
164 |
-
}
|
165 |
-
|
166 |
-
return array( 'activities' => $activities, 'total' => (int)$total_activities );
|
167 |
-
}
|
168 |
-
|
169 |
-
function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
|
170 |
-
global $wpdb, $bp;
|
171 |
-
|
172 |
-
if ( is_array( $activity_ids ) )
|
173 |
-
$activity_ids = implode( ',', $activity_ids );
|
174 |
-
|
175 |
-
$activity_ids = $wpdb->escape( $activity_ids );
|
176 |
-
|
177 |
-
if ( empty( $activity_ids ) )
|
178 |
-
return false;
|
179 |
-
|
180 |
-
if ( $per_page && $page )
|
181 |
-
$pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
|
182 |
-
|
183 |
-
if ( $sort != 'ASC' && $sort != 'DESC' )
|
184 |
-
$sort = 'DESC';
|
185 |
-
|
186 |
-
$activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) );
|
187 |
-
$total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) );
|
188 |
-
|
189 |
-
if ( $display_comments )
|
190 |
-
$activities = BP_Activity_Activity::append_comments( $activities );
|
191 |
-
|
192 |
-
/* If $max is set, only return up to the max results */
|
193 |
-
if ( !empty( $max ) ) {
|
194 |
-
if ( (int)$total_activities > (int)$max )
|
195 |
-
$total_activities = $max;
|
196 |
-
}
|
197 |
-
|
198 |
-
return array( 'activities' => $activities, 'total' => (int)$total_activities );
|
199 |
-
}
|
200 |
-
|
201 |
-
function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
|
202 |
-
global $bp, $wpdb;
|
203 |
-
|
204 |
-
$where_args = false;
|
205 |
-
|
206 |
-
if ( !empty( $user_id ) )
|
207 |
-
$where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
|
208 |
-
|
209 |
-
if ( !empty( $component ) )
|
210 |
-
$where_args[] = $wpdb->prepare( "component = %s", $component );
|
211 |
-
|
212 |
-
if ( !empty( $type ) )
|
213 |
-
$where_args[] = $wpdb->prepare( "type = %s", $type );
|
214 |
-
|
215 |
-
if ( !empty( $item_id ) )
|
216 |
-
$where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
|
217 |
-
|
218 |
-
if ( !empty( $secondary_item_id ) )
|
219 |
-
$where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
|
220 |
-
|
221 |
-
if ( !empty( $action ) )
|
222 |
-
$where_args[] = $wpdb->prepare( "action = %s", $action );
|
223 |
-
|
224 |
-
if ( !empty( $content ) )
|
225 |
-
$where_args[] = $wpdb->prepare( "content = %s", $content );
|
226 |
-
|
227 |
-
if ( !empty( $date_recorded ) )
|
228 |
-
$where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
|
229 |
-
|
230 |
-
if ( !empty( $where_args ) )
|
231 |
-
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
|
232 |
-
else
|
233 |
-
return false;
|
234 |
-
|
235 |
-
return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
|
236 |
-
}
|
237 |
-
|
238 |
-
function delete( $args ) {
|
239 |
-
global $wpdb, $bp;
|
240 |
-
|
241 |
-
extract( $args );
|
242 |
-
|
243 |
-
$defaults = array(
|
244 |
-
'id' => false,
|
245 |
-
'action' => false,
|
246 |
-
'content' => false,
|
247 |
-
'component' => false,
|
248 |
-
'type' => false,
|
249 |
-
'primary_link' => false,
|
250 |
-
'user_id' => false,
|
251 |
-
'item_id' => false,
|
252 |
-
'secondary_item_id' => false,
|
253 |
-
'date_recorded' => false,
|
254 |
-
'hide_sitewide' => false
|
255 |
-
);
|
256 |
-
|
257 |
-
$where_args = false;
|
258 |
-
|
259 |
-
if ( !empty( $id ) )
|
260 |
-
$where_args[] = $wpdb->prepare( "id = %d", $id );
|
261 |
-
|
262 |
-
if ( !empty( $user_id ) )
|
263 |
-
$where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
|
264 |
-
|
265 |
-
if ( !empty( $action ) )
|
266 |
-
$where_args[] = $wpdb->prepare( "action = %s", $action );
|
267 |
-
|
268 |
-
if ( !empty( $content ) )
|
269 |
-
$where_args[] = $wpdb->prepare( "content = %s", $content );
|
270 |
-
|
271 |
-
if ( !empty( $component ) )
|
272 |
-
$where_args[] = $wpdb->prepare( "component = %s", $component );
|
273 |
-
|
274 |
-
if ( !empty( $type ) )
|
275 |
-
$where_args[] = $wpdb->prepare( "type = %s", $type );
|
276 |
-
|
277 |
-
if ( !empty( $primary_link ) )
|
278 |
-
$where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
|
279 |
-
|
280 |
-
if ( !empty( $item_id ) )
|
281 |
-
$where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
|
282 |
-
|
283 |
-
if ( !empty( $secondary_item_id ) )
|
284 |
-
$where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
|
285 |
-
|
286 |
-
if ( !empty( $date_recorded ) )
|
287 |
-
$where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
|
288 |
-
|
289 |
-
if ( !empty( $hide_sitewide ) )
|
290 |
-
$where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
|
291 |
-
|
292 |
-
if ( !empty( $where_args ) )
|
293 |
-
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
|
294 |
-
else
|
295 |
-
return false;
|
296 |
-
|
297 |
-
/* Fetch the activity IDs so we can delete any comments for this activity item */
|
298 |
-
$activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
|
299 |
-
|
300 |
-
if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
|
301 |
-
return false;
|
302 |
-
|
303 |
-
if ( $activity_ids ) {
|
304 |
-
BP_Activity_Activity::delete_activity_item_comments( $activity_ids );
|
305 |
-
BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
|
306 |
-
|
307 |
-
return $activity_ids;
|
308 |
-
}
|
309 |
-
|
310 |
-
return $activity_ids;
|
311 |
-
}
|
312 |
-
|
313 |
-
function delete_activity_item_comments( $activity_ids ) {
|
314 |
-
global $bp, $wpdb;
|
315 |
-
|
316 |
-
if ( is_array($activity_ids) )
|
317 |
-
$activity_ids = implode( ',', $activity_ids );
|
318 |
-
|
319 |
-
$activity_ids = $wpdb->escape( $activity_ids );
|
320 |
-
|
321 |
-
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
|
322 |
-
}
|
323 |
-
|
324 |
-
function delete_activity_meta_entries( $activity_ids ) {
|
325 |
-
global $bp, $wpdb;
|
326 |
-
|
327 |
-
if ( is_array($activity_ids) )
|
328 |
-
$activity_ids = implode( ',', $activity_ids );
|
329 |
-
|
330 |
-
$activity_ids = $wpdb->escape( $activity_ids );
|
331 |
-
|
332 |
-
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
|
333 |
-
}
|
334 |
-
|
335 |
-
function append_comments( $activities ) {
|
336 |
-
global $bp, $wpdb;
|
337 |
-
|
338 |
-
/* Now fetch the activity comments and parse them into the correct position in the activities array. */
|
339 |
-
foreach( (array)$activities as $activity ) {
|
340 |
-
if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
|
341 |
-
$activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
|
342 |
-
}
|
343 |
-
|
344 |
-
/* Merge the comments with the activity items */
|
345 |
-
foreach( (array)$activities as $key => $activity )
|
346 |
-
$activities[$key]->children = $activity_comments[$activity->id];
|
347 |
-
|
348 |
-
return $activities;
|
349 |
-
}
|
350 |
-
|
351 |
-
function get_activity_comments( $activity_id, $left, $right ) {
|
352 |
-
global $wpdb, $bp;
|
353 |
-
|
354 |
-
if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
|
355 |
-
/* Select the user's fullname with the query so we don't have to fetch it for each comment */
|
356 |
-
if ( function_exists( 'xprofile_install' ) ) {
|
357 |
-
$fullname_select = ", pd.value as user_fullname";
|
358 |
-
$fullname_from = ", {$bp->profile->table_name_data} pd ";
|
359 |
-
$fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
|
360 |
-
}
|
361 |
-
|
362 |
-
/* Retrieve all descendants of the $root node */
|
363 |
-
$descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
|
364 |
-
|
365 |
-
/* Loop descendants and build an assoc array */
|
366 |
-
foreach ( (array)$descendants as $d ) {
|
367 |
-
$d->children = array();
|
368 |
-
|
369 |
-
/* If we have a reference on the parent */
|
370 |
-
if ( isset( $ref[ $d->secondary_item_id ] ) ) {
|
371 |
-
$ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
|
372 |
-
$ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
|
373 |
-
|
374 |
-
/* If we don't have a reference on the parent, put in the root level */
|
375 |
-
} else {
|
376 |
-
$comments[ $d->id ] = $d;
|
377 |
-
$ref[ $d->id ] =& $comments[ $d->id ];
|
378 |
-
}
|
379 |
-
}
|
380 |
-
wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
|
381 |
-
}
|
382 |
-
|
383 |
-
return $comments;
|
384 |
-
}
|
385 |
-
|
386 |
-
function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
|
387 |
-
global $wpdb, $bp;
|
388 |
-
|
389 |
-
/* The right value of this node is the left value + 1 */
|
390 |
-
$right = $left + 1;
|
391 |
-
|
392 |
-
/* Get all descendants of this node */
|
393 |
-
$descendants = BP_Activity_Activity::get_child_comments( $parent_id );
|
394 |
-
|
395 |
-
/* Loop the descendants and recalculate the left and right values */
|
396 |
-
foreach ( (array)$descendants as $descendant )
|
397 |
-
$right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
|
398 |
-
|
399 |
-
/* We've got the left value, and now that we've processed the children of this node we also know the right value */
|
400 |
-
if ( 1 == $left )
|
401 |
-
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
|
402 |
-
else
|
403 |
-
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
|
404 |
-
|
405 |
-
/* Return the right value of this node + 1 */
|
406 |
-
return $right + 1;
|
407 |
-
}
|
408 |
-
|
409 |
-
function get_child_comments( $parent_id ) {
|
410 |
-
global $bp, $wpdb;
|
411 |
-
|
412 |
-
return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
|
413 |
-
}
|
414 |
-
|
415 |
-
function get_recorded_components() {
|
416 |
-
global $wpdb, $bp;
|
417 |
-
|
418 |
-
return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) );
|
419 |
-
}
|
420 |
-
|
421 |
-
function get_sitewide_items_for_feed( $limit = 35 ) {
|
422 |
-
global $wpdb, $bp;
|
423 |
-
|
424 |
-
$activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
|
425 |
-
|
426 |
-
for ( $i = 0; $i < count($activities); $i++ ) {
|
427 |
-
$title = explode( '<span', $activities[$i]['content'] );
|
428 |
-
|
429 |
-
$activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
|
430 |
-
$activity_feed[$i]['link'] = $activities[$i]['primary_link'];
|
431 |
-
$activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
|
432 |
-
$activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
|
433 |
-
}
|
434 |
-
|
435 |
-
return $activity_feed;
|
436 |
-
}
|
437 |
-
|
438 |
-
function get_filter_sql( $filter_array ) {
|
439 |
-
global $wpdb;
|
440 |
-
|
441 |
-
if ( !empty( $filter_array['user_id'] ) ) {
|
442 |
-
$user_filter = explode( ',', $filter_array['user_id'] );
|
443 |
-
$user_sql = ' ( a.user_id IN ( ' . $filter_array['user_id'] . ' ) )';
|
444 |
-
$filter_sql[] = $user_sql;
|
445 |
-
}
|
446 |
-
|
447 |
-
if ( !empty( $filter_array['object'] ) ) {
|
448 |
-
$object_filter = explode( ',', $filter_array['object'] );
|
449 |
-
$object_sql = ' ( ';
|
450 |
-
|
451 |
-
$counter = 1;
|
452 |
-
foreach( (array) $object_filter as $object ) {
|
453 |
-
$object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
|
454 |
-
|
455 |
-
if ( $counter != count( $object_filter ) )
|
456 |
-
$object_sql .= ' || ';
|
457 |
-
|
458 |
-
$counter++;
|
459 |
-
}
|
460 |
-
|
461 |
-
$object_sql .= ' )';
|
462 |
-
$filter_sql[] = $object_sql;
|
463 |
-
}
|
464 |
-
|
465 |
-
if ( !empty( $filter_array['action'] ) ) {
|
466 |
-
$action_filter = explode( ',', $filter_array['action'] );
|
467 |
-
$action_sql = ' ( ';
|
468 |
-
|
469 |
-
$counter = 1;
|
470 |
-
foreach( (array) $action_filter as $action ) {
|
471 |
-
$action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
|
472 |
-
|
473 |
-
if ( $counter != count( $action_filter ) )
|
474 |
-
$action_sql .= ' || ';
|
475 |
-
|
476 |
-
$counter++;
|
477 |
-
}
|
478 |
-
|
479 |
-
$action_sql .= ' )';
|
480 |
-
$filter_sql[] = $action_sql;
|
481 |
-
}
|
482 |
-
|
483 |
-
if ( !empty( $filter_array['primary_id'] ) ) {
|
484 |
-
$pid_filter = explode( ',', $filter_array['primary_id'] );
|
485 |
-
$pid_sql = ' ( ';
|
486 |
-
|
487 |
-
$counter = 1;
|
488 |
-
foreach( (array) $pid_filter as $pid ) {
|
489 |
-
$pid_sql .= $wpdb->prepare( "a.item_id = %s", trim( $pid ) );
|
490 |
-
|
491 |
-
if ( $counter != count( $pid_filter ) )
|
492 |
-
$pid_sql .= ' || ';
|
493 |
-
|
494 |
-
$counter++;
|
495 |
-
}
|
496 |
-
|
497 |
-
$pid_sql .= ' )';
|
498 |
-
$filter_sql[] = $pid_sql;
|
499 |
-
}
|
500 |
-
|
501 |
-
if ( !empty( $filter_array['secondary_id'] ) ) {
|
502 |
-
$sid_filter = explode( ',', $filter_array['secondary_id'] );
|
503 |
-
$sid_sql = ' ( ';
|
504 |
-
|
505 |
-
$counter = 1;
|
506 |
-
foreach( (array) $sid_filter as $sid ) {
|
507 |
-
$sid_sql .= $wpdb->prepare( "a.secondary_item_id = %s", trim( $sid ) );
|
508 |
-
|
509 |
-
if ( $counter != count( $sid_filter ) )
|
510 |
-
$sid_sql .= ' || ';
|
511 |
-
|
512 |
-
$counter++;
|
513 |
-
}
|
514 |
-
|
515 |
-
$sid_sql .= ' )';
|
516 |
-
$filter_sql[] = $sid_sql;
|
517 |
-
}
|
518 |
-
|
519 |
-
if ( empty($filter_sql) )
|
520 |
-
return false;
|
521 |
-
|
522 |
-
return join( ' AND ', $filter_sql );
|
523 |
-
}
|
524 |
-
|
525 |
-
function get_last_updated() {
|
526 |
-
global $bp, $wpdb;
|
527 |
-
|
528 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" ) );
|
529 |
-
}
|
530 |
-
|
531 |
-
function total_favorite_count( $user_id ) {
|
532 |
-
global $bp;
|
533 |
-
|
534 |
-
if ( !$favorite_activity_entries =
|
535 |
-
return 0;
|
536 |
-
|
537 |
-
return count( maybe_unserialize( $favorite_activity_entries ) );
|
538 |
-
}
|
539 |
-
|
540 |
-
function check_exists_by_content( $content ) {
|
541 |
-
global $wpdb, $bp;
|
542 |
-
|
543 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
|
544 |
-
}
|
545 |
-
|
546 |
-
function hide_all_for_user( $user_id ) {
|
547 |
-
global $wpdb, $bp;
|
548 |
-
|
549 |
-
return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
|
550 |
-
}
|
551 |
-
}
|
552 |
-
|
553 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class BP_Activity_Activity {
|
4 |
+
var $id;
|
5 |
+
var $item_id;
|
6 |
+
var $secondary_item_id;
|
7 |
+
var $user_id;
|
8 |
+
var $primary_link;
|
9 |
+
var $component;
|
10 |
+
var $type;
|
11 |
+
var $action;
|
12 |
+
var $content;
|
13 |
+
var $date_recorded;
|
14 |
+
var $hide_sitewide = false;
|
15 |
+
|
16 |
+
function bp_activity_activity( $id = false ) {
|
17 |
+
global $bp;
|
18 |
+
|
19 |
+
if ( $id ) {
|
20 |
+
$this->id = $id;
|
21 |
+
$this->populate();
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
function populate() {
|
26 |
+
global $wpdb, $bp;
|
27 |
+
|
28 |
+
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
|
29 |
+
if ( $row ) {
|
30 |
+
$this->id = $row->id;
|
31 |
+
$this->item_id = $row->item_id;
|
32 |
+
$this->secondary_item_id = $row->secondary_item_id;
|
33 |
+
$this->user_id = $row->user_id;
|
34 |
+
$this->primary_link = $row->primary_link;
|
35 |
+
$this->component = $row->component;
|
36 |
+
$this->type = $row->type;
|
37 |
+
$this->action = $row->action;
|
38 |
+
$this->content = $row->content;
|
39 |
+
$this->date_recorded = $row->date_recorded;
|
40 |
+
$this->hide_sitewide = $row->hide_sitewide;
|
41 |
+
$this->mptt_left = $row->mptt_left;
|
42 |
+
$this->mptt_right = $row->mptt_right;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
function save() {
|
47 |
+
global $wpdb, $bp, $current_user;
|
48 |
+
|
49 |
+
do_action( 'bp_activity_before_save', &$this );
|
50 |
+
|
51 |
+
$this->id = apply_filters( 'bp_activity_id_before_save', $this->id, &$this );
|
52 |
+
$this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id, &$this );
|
53 |
+
$this->secondary_item_id = apply_filters( 'bp_activity_secondary_item_id_before_save', $this->secondary_item_id, &$this );
|
54 |
+
$this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id, &$this );
|
55 |
+
$this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link, &$this );
|
56 |
+
$this->component = apply_filters( 'bp_activity_component_before_save', $this->component, &$this );
|
57 |
+
$this->type = apply_filters( 'bp_activity_type_before_save', $this->type, &$this );
|
58 |
+
$this->action = apply_filters( 'bp_activity_action_before_save', $this->action, &$this );
|
59 |
+
$this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );
|
60 |
+
$this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded, &$this );
|
61 |
+
$this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide, &$this );
|
62 |
+
$this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left, &$this );
|
63 |
+
$this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right, &$this );
|
64 |
+
|
65 |
+
if ( !$this->component || !$this->type )
|
66 |
+
return false;
|
67 |
+
|
68 |
+
if ( !$this->primary_link )
|
69 |
+
$this->primary_link = $bp->loggedin_user->domain;
|
70 |
+
|
71 |
+
/* If we have an existing ID, update the activity item, otherwise insert it. */
|
72 |
+
if ( $this->id )
|
73 |
+
$q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
|
74 |
+
else
|
75 |
+
$q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
|
76 |
+
|
77 |
+
if ( !$wpdb->query( $q ) )
|
78 |
+
return false;
|
79 |
+
|
80 |
+
if ( empty( $this->id ) )
|
81 |
+
$this->id = $wpdb->insert_id;
|
82 |
+
|
83 |
+
do_action( 'bp_activity_after_save', &$this );
|
84 |
+
return true;
|
85 |
+
}
|
86 |
+
|
87 |
+
/* Static Functions */
|
88 |
+
|
89 |
+
function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
|
90 |
+
global $wpdb, $bp;
|
91 |
+
|
92 |
+
/* Select conditions */
|
93 |
+
$select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
|
94 |
+
|
95 |
+
$from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
|
96 |
+
|
97 |
+
/* Where conditions */
|
98 |
+
$where_conditions = array();
|
99 |
+
|
100 |
+
/* Searching */
|
101 |
+
if ( $search_terms ) {
|
102 |
+
$search_terms = $wpdb->escape( $search_terms );
|
103 |
+
$where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
|
104 |
+
}
|
105 |
+
|
106 |
+
/* Filtering */
|
107 |
+
if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
|
108 |
+
$where_conditions['filter_sql'] = $filter_sql;
|
109 |
+
|
110 |
+
/* Sorting */
|
111 |
+
if ( $sort != 'ASC' && $sort != 'DESC' )
|
112 |
+
$sort = 'DESC';
|
113 |
+
|
114 |
+
/* Hide Hidden Items? */
|
115 |
+
if ( !$show_hidden )
|
116 |
+
$where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
|
117 |
+
|
118 |
+
/* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
|
119 |
+
if ( !$display_comments || 'threaded' == $display_comments ) {
|
120 |
+
$where_conditions[] = "a.type != 'activity_comment'";
|
121 |
+
}
|
122 |
+
|
123 |
+
$where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
|
124 |
+
|
125 |
+
if ( $per_page && $page ) {
|
126 |
+
$pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
|
127 |
+
$activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
|
128 |
+
} else
|
129 |
+
$activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
|
130 |
+
|
131 |
+
$total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
|
132 |
+
|
133 |
+
/* Get the fullnames of users so we don't have to query in the loop */
|
134 |
+
if ( function_exists( 'xprofile_install' ) && $activities ) {
|
135 |
+
foreach ( (array)$activities as $activity ) {
|
136 |
+
if ( (int)$activity->user_id )
|
137 |
+
$activity_user_ids[] = $activity->user_id;
|
138 |
+
}
|
139 |
+
|
140 |
+
$activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
|
141 |
+
if ( !empty( $activity_user_ids ) ) {
|
142 |
+
if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
|
143 |
+
foreach ( (array)$names as $name )
|
144 |
+
$tmp_names[$name->user_id] = $name->user_fullname;
|
145 |
+
|
146 |
+
foreach ( (array)$activities as $i => $activity ) {
|
147 |
+
if ( !empty( $tmp_names[$activity->user_id] ) )
|
148 |
+
$activities[$i]->user_fullname = $tmp_names[$activity->user_id];
|
149 |
+
}
|
150 |
+
|
151 |
+
unset( $names );
|
152 |
+
unset( $tmp_names );
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
if ( $activities && $display_comments )
|
158 |
+
$activities = BP_Activity_Activity::append_comments( &$activities );
|
159 |
+
|
160 |
+
/* If $max is set, only return up to the max results */
|
161 |
+
if ( !empty( $max ) ) {
|
162 |
+
if ( (int)$total_activities > (int)$max )
|
163 |
+
$total_activities = $max;
|
164 |
+
}
|
165 |
+
|
166 |
+
return array( 'activities' => $activities, 'total' => (int)$total_activities );
|
167 |
+
}
|
168 |
+
|
169 |
+
function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
|
170 |
+
global $wpdb, $bp;
|
171 |
+
|
172 |
+
if ( is_array( $activity_ids ) )
|
173 |
+
$activity_ids = implode( ',', $activity_ids );
|
174 |
+
|
175 |
+
$activity_ids = $wpdb->escape( $activity_ids );
|
176 |
+
|
177 |
+
if ( empty( $activity_ids ) )
|
178 |
+
return false;
|
179 |
+
|
180 |
+
if ( $per_page && $page )
|
181 |
+
$pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
|
182 |
+
|
183 |
+
if ( $sort != 'ASC' && $sort != 'DESC' )
|
184 |
+
$sort = 'DESC';
|
185 |
+
|
186 |
+
$activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) );
|
187 |
+
$total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) );
|
188 |
+
|
189 |
+
if ( $display_comments )
|
190 |
+
$activities = BP_Activity_Activity::append_comments( $activities );
|
191 |
+
|
192 |
+
/* If $max is set, only return up to the max results */
|
193 |
+
if ( !empty( $max ) ) {
|
194 |
+
if ( (int)$total_activities > (int)$max )
|
195 |
+
$total_activities = $max;
|
196 |
+
}
|
197 |
+
|
198 |
+
return array( 'activities' => $activities, 'total' => (int)$total_activities );
|
199 |
+
}
|
200 |
+
|
201 |
+
function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
|
202 |
+
global $bp, $wpdb;
|
203 |
+
|
204 |
+
$where_args = false;
|
205 |
+
|
206 |
+
if ( !empty( $user_id ) )
|
207 |
+
$where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
|
208 |
+
|
209 |
+
if ( !empty( $component ) )
|
210 |
+
$where_args[] = $wpdb->prepare( "component = %s", $component );
|
211 |
+
|
212 |
+
if ( !empty( $type ) )
|
213 |
+
$where_args[] = $wpdb->prepare( "type = %s", $type );
|
214 |
+
|
215 |
+
if ( !empty( $item_id ) )
|
216 |
+
$where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
|
217 |
+
|
218 |
+
if ( !empty( $secondary_item_id ) )
|
219 |
+
$where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
|
220 |
+
|
221 |
+
if ( !empty( $action ) )
|
222 |
+
$where_args[] = $wpdb->prepare( "action = %s", $action );
|
223 |
+
|
224 |
+
if ( !empty( $content ) )
|
225 |
+
$where_args[] = $wpdb->prepare( "content = %s", $content );
|
226 |
+
|
227 |
+
if ( !empty( $date_recorded ) )
|
228 |
+
$where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
|
229 |
+
|
230 |
+
if ( !empty( $where_args ) )
|
231 |
+
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
|
232 |
+
else
|
233 |
+
return false;
|
234 |
+
|
235 |
+
return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
|
236 |
+
}
|
237 |
+
|
238 |
+
function delete( $args ) {
|
239 |
+
global $wpdb, $bp;
|
240 |
+
|
241 |
+
extract( $args );
|
242 |
+
|
243 |
+
$defaults = array(
|
244 |
+
'id' => false,
|
245 |
+
'action' => false,
|
246 |
+
'content' => false,
|
247 |
+
'component' => false,
|
248 |
+
'type' => false,
|
249 |
+
'primary_link' => false,
|
250 |
+
'user_id' => false,
|
251 |
+
'item_id' => false,
|
252 |
+
'secondary_item_id' => false,
|
253 |
+
'date_recorded' => false,
|
254 |
+
'hide_sitewide' => false
|
255 |
+
);
|
256 |
+
|
257 |
+
$where_args = false;
|
258 |
+
|
259 |
+
if ( !empty( $id ) )
|
260 |
+
$where_args[] = $wpdb->prepare( "id = %d", $id );
|
261 |
+
|
262 |
+
if ( !empty( $user_id ) )
|
263 |
+
$where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
|
264 |
+
|
265 |
+
if ( !empty( $action ) )
|
266 |
+
$where_args[] = $wpdb->prepare( "action = %s", $action );
|
267 |
+
|
268 |
+
if ( !empty( $content ) )
|
269 |
+
$where_args[] = $wpdb->prepare( "content = %s", $content );
|
270 |
+
|
271 |
+
if ( !empty( $component ) )
|
272 |
+
$where_args[] = $wpdb->prepare( "component = %s", $component );
|
273 |
+
|
274 |
+
if ( !empty( $type ) )
|
275 |
+
$where_args[] = $wpdb->prepare( "type = %s", $type );
|
276 |
+
|
277 |
+
if ( !empty( $primary_link ) )
|
278 |
+
$where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
|
279 |
+
|
280 |
+
if ( !empty( $item_id ) )
|
281 |
+
$where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
|
282 |
+
|
283 |
+
if ( !empty( $secondary_item_id ) )
|
284 |
+
$where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
|
285 |
+
|
286 |
+
if ( !empty( $date_recorded ) )
|
287 |
+
$where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
|
288 |
+
|
289 |
+
if ( !empty( $hide_sitewide ) )
|
290 |
+
$where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
|
291 |
+
|
292 |
+
if ( !empty( $where_args ) )
|
293 |
+
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
|
294 |
+
else
|
295 |
+
return false;
|
296 |
+
|
297 |
+
/* Fetch the activity IDs so we can delete any comments for this activity item */
|
298 |
+
$activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
|
299 |
+
|
300 |
+
if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
|
301 |
+
return false;
|
302 |
+
|
303 |
+
if ( $activity_ids ) {
|
304 |
+
BP_Activity_Activity::delete_activity_item_comments( $activity_ids );
|
305 |
+
BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
|
306 |
+
|
307 |
+
return $activity_ids;
|
308 |
+
}
|
309 |
+
|
310 |
+
return $activity_ids;
|
311 |
+
}
|
312 |
+
|
313 |
+
function delete_activity_item_comments( $activity_ids ) {
|
314 |
+
global $bp, $wpdb;
|
315 |
+
|
316 |
+
if ( is_array($activity_ids) )
|
317 |
+
$activity_ids = implode( ',', $activity_ids );
|
318 |
+
|
319 |
+
$activity_ids = $wpdb->escape( $activity_ids );
|
320 |
+
|
321 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
|
322 |
+
}
|
323 |
+
|
324 |
+
function delete_activity_meta_entries( $activity_ids ) {
|
325 |
+
global $bp, $wpdb;
|
326 |
+
|
327 |
+
if ( is_array($activity_ids) )
|
328 |
+
$activity_ids = implode( ',', $activity_ids );
|
329 |
+
|
330 |
+
$activity_ids = $wpdb->escape( $activity_ids );
|
331 |
+
|
332 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
|
333 |
+
}
|
334 |
+
|
335 |
+
function append_comments( $activities ) {
|
336 |
+
global $bp, $wpdb;
|
337 |
+
|
338 |
+
/* Now fetch the activity comments and parse them into the correct position in the activities array. */
|
339 |
+
foreach( (array)$activities as $activity ) {
|
340 |
+
if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
|
341 |
+
$activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
|
342 |
+
}
|
343 |
+
|
344 |
+
/* Merge the comments with the activity items */
|
345 |
+
foreach( (array)$activities as $key => $activity )
|
346 |
+
$activities[$key]->children = $activity_comments[$activity->id];
|
347 |
+
|
348 |
+
return $activities;
|
349 |
+
}
|
350 |
+
|
351 |
+
function get_activity_comments( $activity_id, $left, $right ) {
|
352 |
+
global $wpdb, $bp;
|
353 |
+
|
354 |
+
if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
|
355 |
+
/* Select the user's fullname with the query so we don't have to fetch it for each comment */
|
356 |
+
if ( function_exists( 'xprofile_install' ) ) {
|
357 |
+
$fullname_select = ", pd.value as user_fullname";
|
358 |
+
$fullname_from = ", {$bp->profile->table_name_data} pd ";
|
359 |
+
$fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
|
360 |
+
}
|
361 |
+
|
362 |
+
/* Retrieve all descendants of the $root node */
|
363 |
+
$descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
|
364 |
+
|
365 |
+
/* Loop descendants and build an assoc array */
|
366 |
+
foreach ( (array)$descendants as $d ) {
|
367 |
+
$d->children = array();
|
368 |
+
|
369 |
+
/* If we have a reference on the parent */
|
370 |
+
if ( isset( $ref[ $d->secondary_item_id ] ) ) {
|
371 |
+
$ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
|
372 |
+
$ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
|
373 |
+
|
374 |
+
/* If we don't have a reference on the parent, put in the root level */
|
375 |
+
} else {
|
376 |
+
$comments[ $d->id ] = $d;
|
377 |
+
$ref[ $d->id ] =& $comments[ $d->id ];
|
378 |
+
}
|
379 |
+
}
|
380 |
+
wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
|
381 |
+
}
|
382 |
+
|
383 |
+
return $comments;
|
384 |
+
}
|
385 |
+
|
386 |
+
function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
|
387 |
+
global $wpdb, $bp;
|
388 |
+
|
389 |
+
/* The right value of this node is the left value + 1 */
|
390 |
+
$right = $left + 1;
|
391 |
+
|
392 |
+
/* Get all descendants of this node */
|
393 |
+
$descendants = BP_Activity_Activity::get_child_comments( $parent_id );
|
394 |
+
|
395 |
+
/* Loop the descendants and recalculate the left and right values */
|
396 |
+
foreach ( (array)$descendants as $descendant )
|
397 |
+
$right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
|
398 |
+
|
399 |
+
/* We've got the left value, and now that we've processed the children of this node we also know the right value */
|
400 |
+
if ( 1 == $left )
|
401 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
|
402 |
+
else
|
403 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
|
404 |
+
|
405 |
+
/* Return the right value of this node + 1 */
|
406 |
+
return $right + 1;
|
407 |
+
}
|
408 |
+
|
409 |
+
function get_child_comments( $parent_id ) {
|
410 |
+
global $bp, $wpdb;
|
411 |
+
|
412 |
+
return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
|
413 |
+
}
|
414 |
+
|
415 |
+
function get_recorded_components() {
|
416 |
+
global $wpdb, $bp;
|
417 |
+
|
418 |
+
return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) );
|
419 |
+
}
|
420 |
+
|
421 |
+
function get_sitewide_items_for_feed( $limit = 35 ) {
|
422 |
+
global $wpdb, $bp;
|
423 |
+
|
424 |
+
$activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
|
425 |
+
|
426 |
+
for ( $i = 0; $i < count($activities); $i++ ) {
|
427 |
+
$title = explode( '<span', $activities[$i]['content'] );
|
428 |
+
|
429 |
+
$activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
|
430 |
+
$activity_feed[$i]['link'] = $activities[$i]['primary_link'];
|
431 |
+
$activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
|
432 |
+
$activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
|
433 |
+
}
|
434 |
+
|
435 |
+
return $activity_feed;
|
436 |
+
}
|
437 |
+
|
438 |
+
function get_filter_sql( $filter_array ) {
|
439 |
+
global $wpdb;
|
440 |
+
|
441 |
+
if ( !empty( $filter_array['user_id'] ) ) {
|
442 |
+
$user_filter = explode( ',', $filter_array['user_id'] );
|
443 |
+
$user_sql = ' ( a.user_id IN ( ' . $filter_array['user_id'] . ' ) )';
|
444 |
+
$filter_sql[] = $user_sql;
|
445 |
+
}
|
446 |
+
|
447 |
+
if ( !empty( $filter_array['object'] ) ) {
|
448 |
+
$object_filter = explode( ',', $filter_array['object'] );
|
449 |
+
$object_sql = ' ( ';
|
450 |
+
|
451 |
+
$counter = 1;
|
452 |
+
foreach( (array) $object_filter as $object ) {
|
453 |
+
$object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
|
454 |
+
|
455 |
+
if ( $counter != count( $object_filter ) )
|
456 |
+
$object_sql .= ' || ';
|
457 |
+
|
458 |
+
$counter++;
|
459 |
+
}
|
460 |
+
|
461 |
+
$object_sql .= ' )';
|
462 |
+
$filter_sql[] = $object_sql;
|
463 |
+
}
|
464 |
+
|
465 |
+
if ( !empty( $filter_array['action'] ) ) {
|
466 |
+
$action_filter = explode( ',', $filter_array['action'] );
|
467 |
+
$action_sql = ' ( ';
|
468 |
+
|
469 |
+
$counter = 1;
|
470 |
+
foreach( (array) $action_filter as $action ) {
|
471 |
+
$action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
|
472 |
+
|
473 |
+
if ( $counter != count( $action_filter ) )
|
474 |
+
$action_sql .= ' || ';
|
475 |
+
|
476 |
+
$counter++;
|
477 |
+
}
|
478 |
+
|
479 |
+
$action_sql .= ' )';
|
480 |
+
$filter_sql[] = $action_sql;
|
481 |
+
}
|
482 |
+
|
483 |
+
if ( !empty( $filter_array['primary_id'] ) ) {
|
484 |
+
$pid_filter = explode( ',', $filter_array['primary_id'] );
|
485 |
+
$pid_sql = ' ( ';
|
486 |
+
|
487 |
+
$counter = 1;
|
488 |
+
foreach( (array) $pid_filter as $pid ) {
|
489 |
+
$pid_sql .= $wpdb->prepare( "a.item_id = %s", trim( $pid ) );
|
490 |
+
|
491 |
+
if ( $counter != count( $pid_filter ) )
|
492 |
+
$pid_sql .= ' || ';
|
493 |
+
|
494 |
+
$counter++;
|
495 |
+
}
|
496 |
+
|
497 |
+
$pid_sql .= ' )';
|
498 |
+
$filter_sql[] = $pid_sql;
|
499 |
+
}
|
500 |
+
|
501 |
+
if ( !empty( $filter_array['secondary_id'] ) ) {
|
502 |
+
$sid_filter = explode( ',', $filter_array['secondary_id'] );
|
503 |
+
$sid_sql = ' ( ';
|
504 |
+
|
505 |
+
$counter = 1;
|
506 |
+
foreach( (array) $sid_filter as $sid ) {
|
507 |
+
$sid_sql .= $wpdb->prepare( "a.secondary_item_id = %s", trim( $sid ) );
|
508 |
+
|
509 |
+
if ( $counter != count( $sid_filter ) )
|
510 |
+
$sid_sql .= ' || ';
|
511 |
+
|
512 |
+
$counter++;
|
513 |
+
}
|
514 |
+
|
515 |
+
$sid_sql .= ' )';
|
516 |
+
$filter_sql[] = $sid_sql;
|
517 |
+
}
|
518 |
+
|
519 |
+
if ( empty($filter_sql) )
|
520 |
+
return false;
|
521 |
+
|
522 |
+
return join( ' AND ', $filter_sql );
|
523 |
+
}
|
524 |
+
|
525 |
+
function get_last_updated() {
|
526 |
+
global $bp, $wpdb;
|
527 |
+
|
528 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" ) );
|
529 |
+
}
|
530 |
+
|
531 |
+
function total_favorite_count( $user_id ) {
|
532 |
+
global $bp;
|
533 |
+
|
534 |
+
if ( !$favorite_activity_entries = get_user_meta( $user_id, 'bp_favorite_activities', true ) )
|
535 |
+
return 0;
|
536 |
+
|
537 |
+
return count( maybe_unserialize( $favorite_activity_entries ) );
|
538 |
+
}
|
539 |
+
|
540 |
+
function check_exists_by_content( $content ) {
|
541 |
+
global $wpdb, $bp;
|
542 |
+
|
543 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
|
544 |
+
}
|
545 |
+
|
546 |
+
function hide_all_for_user( $user_id ) {
|
547 |
+
global $wpdb, $bp;
|
548 |
+
|
549 |
+
return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
?>
|
bp-activity/bp-activity-filters.php
CHANGED
@@ -1,141 +1,144 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/* Apply WordPress defined filters */
|
4 |
-
add_filter( 'bp_get_activity_action',
|
5 |
-
add_filter( 'bp_get_activity_content_body',
|
6 |
-
add_filter( 'bp_get_activity_content',
|
7 |
-
add_filter( 'bp_get_activity_parent_content',
|
8 |
-
add_filter( 'bp_get_activity_latest_update',
|
9 |
-
add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses', 1 );
|
10 |
-
add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
|
11 |
-
add_filter( 'bp_activity_content_before_save',
|
12 |
-
add_filter( 'bp_activity_action_before_save',
|
13 |
-
|
14 |
-
add_filter( 'bp_get_activity_action',
|
15 |
-
add_filter( 'bp_get_activity_content_body',
|
16 |
-
add_filter( 'bp_get_activity_content',
|
17 |
-
add_filter( 'bp_get_activity_latest_update',
|
18 |
-
add_filter( 'bp_get_activity_latest_update_excerpt', 'force_balance_tags' );
|
19 |
-
add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
|
20 |
-
|
21 |
-
add_filter( '
|
22 |
-
|
23 |
-
add_filter( '
|
24 |
-
add_filter( '
|
25 |
-
add_filter( '
|
26 |
-
add_filter( '
|
27 |
-
|
28 |
-
add_filter( '
|
29 |
-
|
30 |
-
add_filter( '
|
31 |
-
add_filter( '
|
32 |
-
add_filter( '
|
33 |
-
add_filter( '
|
34 |
-
|
35 |
-
add_filter( '
|
36 |
-
|
37 |
-
add_filter( '
|
38 |
-
add_filter( '
|
39 |
-
add_filter( '
|
40 |
-
add_filter( '
|
41 |
-
|
42 |
-
add_filter( '
|
43 |
-
|
44 |
-
add_filter( '
|
45 |
-
add_filter( '
|
46 |
-
|
47 |
-
add_filter( '
|
48 |
-
|
49 |
-
add_filter( '
|
50 |
-
add_filter( '
|
51 |
-
add_filter( '
|
52 |
-
add_filter( '
|
53 |
-
add_filter( '
|
54 |
-
|
55 |
-
add_filter( '
|
56 |
-
|
57 |
-
add_filter( '
|
58 |
-
add_filter( '
|
59 |
-
add_filter( '
|
60 |
-
add_filter( '
|
61 |
-
add_filter( '
|
62 |
-
add_filter( '
|
63 |
-
|
64 |
-
add_filter( '
|
65 |
-
|
66 |
-
|
67 |
-
add_filter( '
|
68 |
-
add_filter( '
|
69 |
-
add_filter( '
|
70 |
-
|
71 |
-
add_filter( '
|
72 |
-
|
73 |
-
|
74 |
-
add_filter( '
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$
|
82 |
-
|
83 |
-
$activity_allowedtags
|
84 |
-
$activity_allowedtags['
|
85 |
-
$activity_allowedtags['
|
86 |
-
$activity_allowedtags['
|
87 |
-
$activity_allowedtags['
|
88 |
-
$activity_allowedtags['
|
89 |
-
$activity_allowedtags['
|
90 |
-
$activity_allowedtags['img']
|
91 |
-
$activity_allowedtags['img']['
|
92 |
-
$activity_allowedtags['img']['
|
93 |
-
$activity_allowedtags['img']['class']
|
94 |
-
$activity_allowedtags['img']['
|
95 |
-
$activity_allowedtags['img']['
|
96 |
-
$activity_allowedtags['
|
97 |
-
|
98 |
-
$activity_allowedtags
|
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 |
-
add_filter( '
|
129 |
-
add_filter( '
|
130 |
-
add_filter( '
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/* Apply WordPress defined filters */
|
4 |
+
add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
|
5 |
+
add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
|
6 |
+
add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
|
7 |
+
add_filter( 'bp_get_activity_parent_content', 'bp_activity_filter_kses', 1 );
|
8 |
+
add_filter( 'bp_get_activity_latest_update', 'bp_activity_filter_kses', 1 );
|
9 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses', 1 );
|
10 |
+
add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
|
11 |
+
add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
|
12 |
+
add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
|
13 |
+
|
14 |
+
add_filter( 'bp_get_activity_action', 'force_balance_tags' );
|
15 |
+
add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
|
16 |
+
add_filter( 'bp_get_activity_content', 'force_balance_tags' );
|
17 |
+
add_filter( 'bp_get_activity_latest_update', 'force_balance_tags' );
|
18 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'force_balance_tags' );
|
19 |
+
add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
|
20 |
+
add_filter( 'bp_activity_content_before_save', 'force_balance_tags' );
|
21 |
+
add_filter( 'bp_activity_action_before_save', 'force_balance_tags' );
|
22 |
+
|
23 |
+
add_filter( 'bp_get_activity_action', 'wptexturize' );
|
24 |
+
add_filter( 'bp_get_activity_content_body', 'wptexturize' );
|
25 |
+
add_filter( 'bp_get_activity_content', 'wptexturize' );
|
26 |
+
add_filter( 'bp_get_activity_parent_content', 'wptexturize' );
|
27 |
+
add_filter( 'bp_get_activity_latest_update', 'wptexturize' );
|
28 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'wptexturize' );
|
29 |
+
|
30 |
+
add_filter( 'bp_get_activity_action', 'convert_smilies' );
|
31 |
+
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
|
32 |
+
add_filter( 'bp_get_activity_content', 'convert_smilies' );
|
33 |
+
add_filter( 'bp_get_activity_parent_content', 'convert_smilies' );
|
34 |
+
add_filter( 'bp_get_activity_latest_update', 'convert_smilies' );
|
35 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_smilies' );
|
36 |
+
|
37 |
+
add_filter( 'bp_get_activity_action', 'convert_chars' );
|
38 |
+
add_filter( 'bp_get_activity_content_body', 'convert_chars' );
|
39 |
+
add_filter( 'bp_get_activity_content', 'convert_chars' );
|
40 |
+
add_filter( 'bp_get_activity_parent_content', 'convert_chars' );
|
41 |
+
add_filter( 'bp_get_activity_latest_update', 'convert_chars' );
|
42 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_chars' );
|
43 |
+
|
44 |
+
add_filter( 'bp_get_activity_action', 'wpautop' );
|
45 |
+
add_filter( 'bp_get_activity_content_body', 'wpautop' );
|
46 |
+
add_filter( 'bp_get_activity_content', 'wpautop' );
|
47 |
+
add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
|
48 |
+
|
49 |
+
add_filter( 'bp_get_activity_action', 'make_clickable' );
|
50 |
+
add_filter( 'bp_get_activity_content_body', 'make_clickable' );
|
51 |
+
add_filter( 'bp_get_activity_content', 'make_clickable' );
|
52 |
+
add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
|
53 |
+
add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
|
54 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable' );
|
55 |
+
add_filter( 'bp_get_activity_feed_item_description', 'make_clickable' );
|
56 |
+
|
57 |
+
add_filter( 'bp_acomment_name', 'stripslashes_deep' );
|
58 |
+
add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
|
59 |
+
add_filter( 'bp_get_activity_content', 'stripslashes_deep' );
|
60 |
+
add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );
|
61 |
+
add_filter( 'bp_get_activity_parent_content', 'stripslashes_deep' );
|
62 |
+
add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
|
63 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
|
64 |
+
add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
|
65 |
+
|
66 |
+
/* Apply BuddyPress defined filters */
|
67 |
+
add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
|
68 |
+
add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
|
69 |
+
add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
|
70 |
+
add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_filter' );
|
71 |
+
add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
|
72 |
+
add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
|
73 |
+
|
74 |
+
add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
|
75 |
+
|
76 |
+
/* Allow shortcodes in activity posts */
|
77 |
+
add_filter( 'bp_get_activity_content', 'do_shortcode' );
|
78 |
+
add_filter( 'bp_get_activity_content_body', 'do_shortcode' );
|
79 |
+
|
80 |
+
function bp_activity_filter_kses( $content ) {
|
81 |
+
global $allowedtags;
|
82 |
+
|
83 |
+
$activity_allowedtags = $allowedtags;
|
84 |
+
$activity_allowedtags['span'] = array();
|
85 |
+
$activity_allowedtags['span']['class'] = array();
|
86 |
+
$activity_allowedtags['div'] = array();
|
87 |
+
$activity_allowedtags['div']['class'] = array();
|
88 |
+
$activity_allowedtags['div']['id'] = array();
|
89 |
+
$activity_allowedtags['a']['class'] = array();
|
90 |
+
$activity_allowedtags['img'] = array();
|
91 |
+
$activity_allowedtags['img']['src'] = array();
|
92 |
+
$activity_allowedtags['img']['alt'] = array();
|
93 |
+
$activity_allowedtags['img']['class'] = array();
|
94 |
+
$activity_allowedtags['img']['width'] = array();
|
95 |
+
$activity_allowedtags['img']['height'] = array();
|
96 |
+
$activity_allowedtags['img']['class'] = array();
|
97 |
+
$activity_allowedtags['img']['id'] = array();
|
98 |
+
$activity_allowedtags['img']['title'] = array();
|
99 |
+
$activity_allowedtags['code'] = array();
|
100 |
+
|
101 |
+
$activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
|
102 |
+
return wp_kses( $content, $activity_allowedtags );
|
103 |
+
}
|
104 |
+
|
105 |
+
function bp_activity_at_name_filter( $content ) {
|
106 |
+
include_once( ABSPATH . WPINC . '/registration.php' );
|
107 |
+
|
108 |
+
$pattern = '/[@]+([A-Za-z0-9-_\.]+)/';
|
109 |
+
preg_match_all( $pattern, $content, $usernames );
|
110 |
+
|
111 |
+
// Make sure there's only one instance of each username
|
112 |
+
if ( !$usernames = array_unique( $usernames[1] ) )
|
113 |
+
return $content;
|
114 |
+
|
115 |
+
foreach( (array)$usernames as $username ) {
|
116 |
+
if ( !$user_id = username_exists( $username ) )
|
117 |
+
continue;
|
118 |
+
|
119 |
+
// Increase the number of new @ mentions for the user
|
120 |
+
$new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true );
|
121 |
+
update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
|
122 |
+
|
123 |
+
$content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content );
|
124 |
+
}
|
125 |
+
|
126 |
+
return $content;
|
127 |
+
}
|
128 |
+
add_filter( 'bp_activity_new_update_content', 'bp_activity_at_name_filter' );
|
129 |
+
add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
|
130 |
+
add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
|
131 |
+
add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
|
132 |
+
add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
|
133 |
+
add_filter( 'bp_activity_comment_content', 'bp_activity_at_name_filter' );
|
134 |
+
|
135 |
+
function bp_activity_make_nofollow_filter( $text ) {
|
136 |
+
return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
|
137 |
+
}
|
138 |
+
function bp_activity_make_nofollow_filter_callback( $matches ) {
|
139 |
+
$text = $matches[1];
|
140 |
+
$text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
|
141 |
+
return "<a $text rel=\"nofollow\">";
|
142 |
+
}
|
143 |
+
|
144 |
+
?>
|
bp-activity/bp-activity-notifications.php
CHANGED
@@ -4,7 +4,7 @@ function bp_activity_at_message_notification( $content, $poster_user_id, $activi
|
|
4 |
global $bp;
|
5 |
|
6 |
/* Scan for @username strings in an activity update. Notify each user. */
|
7 |
-
$pattern = '/[@]+([A-Za-z0-9-_]+)/';
|
8 |
preg_match_all( $pattern, $content, $usernames );
|
9 |
|
10 |
/* Make sure there's only one instance of each username */
|
@@ -16,7 +16,7 @@ function bp_activity_at_message_notification( $content, $poster_user_id, $activi
|
|
16 |
continue;
|
17 |
|
18 |
// Now email the user with the contents of the message (if they have enabled email notifications)
|
19 |
-
if ( 'no' !=
|
20 |
$poster_name = bp_core_get_user_displayname( $poster_user_id );
|
21 |
|
22 |
$message_link = bp_activity_get_permalink( $activity_id );
|
@@ -26,9 +26,10 @@ function bp_activity_at_message_notification( $content, $poster_user_id, $activi
|
|
26 |
$content = bp_activity_filter_kses( stripslashes($content) );
|
27 |
|
28 |
// Set up and send the message
|
29 |
-
$ud
|
30 |
-
$to
|
31 |
-
$
|
|
|
32 |
|
33 |
$message = sprintf( __(
|
34 |
'%s mentioned you in an update:
|
@@ -60,7 +61,7 @@ function bp_activity_new_comment_notification( $comment_id, $commenter_id, $para
|
|
60 |
|
61 |
$original_activity = new BP_Activity_Activity( $activity_id );
|
62 |
|
63 |
-
if ( $original_activity->user_id != $commenter_id && 'no' !=
|
64 |
$poster_name = bp_core_get_user_displayname( $commenter_id );
|
65 |
$thread_link = bp_activity_get_permalink( $activity_id );
|
66 |
$settings_link = bp_core_get_user_domain( $original_activity->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
|
@@ -69,9 +70,10 @@ function bp_activity_new_comment_notification( $comment_id, $commenter_id, $para
|
|
69 |
$content = bp_activity_filter_kses( stripslashes($content) );
|
70 |
|
71 |
// Set up and send the message
|
72 |
-
$ud
|
73 |
-
$to
|
74 |
-
$
|
|
|
75 |
|
76 |
$message = sprintf( __(
|
77 |
'%s replied to one of your updates:
|
@@ -102,15 +104,16 @@ To view your original update and all comments, log in and visit: %s
|
|
102 |
|
103 |
$parent_comment = new BP_Activity_Activity( $parent_id );
|
104 |
|
105 |
-
if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' !=
|
106 |
$poster_name = bp_core_get_user_displayname( $commenter_id );
|
107 |
$thread_link = bp_activity_get_permalink( $activity_id );
|
108 |
$settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
|
109 |
|
110 |
// Set up and send the message
|
111 |
-
$ud
|
112 |
-
$to
|
113 |
-
$
|
|
|
114 |
|
115 |
$poster_name = stripslashes( $poster_name );
|
116 |
$content = bp_activity_filter_kses( stripslashes( $content ) );
|
@@ -136,4 +139,4 @@ To view the original activity, your comment and all replies, log in and visit: %
|
|
136 |
}
|
137 |
}
|
138 |
|
139 |
-
?>
|
4 |
global $bp;
|
5 |
|
6 |
/* Scan for @username strings in an activity update. Notify each user. */
|
7 |
+
$pattern = '/[@]+([A-Za-z0-9-_\.]+)/';
|
8 |
preg_match_all( $pattern, $content, $usernames );
|
9 |
|
10 |
/* Make sure there's only one instance of each username */
|
16 |
continue;
|
17 |
|
18 |
// Now email the user with the contents of the message (if they have enabled email notifications)
|
19 |
+
if ( 'no' != get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
|
20 |
$poster_name = bp_core_get_user_displayname( $poster_user_id );
|
21 |
|
22 |
$message_link = bp_activity_get_permalink( $activity_id );
|
26 |
$content = bp_activity_filter_kses( stripslashes($content) );
|
27 |
|
28 |
// Set up and send the message
|
29 |
+
$ud = bp_core_get_core_userdata( $receiver_user_id );
|
30 |
+
$to = $ud->user_email;
|
31 |
+
$sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
|
32 |
+
$subject = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
|
33 |
|
34 |
$message = sprintf( __(
|
35 |
'%s mentioned you in an update:
|
61 |
|
62 |
$original_activity = new BP_Activity_Activity( $activity_id );
|
63 |
|
64 |
+
if ( $original_activity->user_id != $commenter_id && 'no' != get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
|
65 |
$poster_name = bp_core_get_user_displayname( $commenter_id );
|
66 |
$thread_link = bp_activity_get_permalink( $activity_id );
|
67 |
$settings_link = bp_core_get_user_domain( $original_activity->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
|
70 |
$content = bp_activity_filter_kses( stripslashes($content) );
|
71 |
|
72 |
// Set up and send the message
|
73 |
+
$ud = bp_core_get_core_userdata( $original_activity->user_id );
|
74 |
+
$to = $ud->user_email;
|
75 |
+
$sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
|
76 |
+
$subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
|
77 |
|
78 |
$message = sprintf( __(
|
79 |
'%s replied to one of your updates:
|
104 |
|
105 |
$parent_comment = new BP_Activity_Activity( $parent_id );
|
106 |
|
107 |
+
if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
|
108 |
$poster_name = bp_core_get_user_displayname( $commenter_id );
|
109 |
$thread_link = bp_activity_get_permalink( $activity_id );
|
110 |
$settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
|
111 |
|
112 |
// Set up and send the message
|
113 |
+
$ud = bp_core_get_core_userdata( $parent_comment->user_id );
|
114 |
+
$to = $ud->user_email;
|
115 |
+
$sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
|
116 |
+
$subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
|
117 |
|
118 |
$poster_name = stripslashes( $poster_name );
|
119 |
$content = bp_activity_filter_kses( stripslashes( $content ) );
|
139 |
}
|
140 |
}
|
141 |
|
142 |
+
?>
|
bp-activity/bp-activity-templatetags.php
CHANGED
@@ -1,954 +1,1074 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class BP_Activity_Template {
|
4 |
-
var $current_activity = -1;
|
5 |
-
var $activity_count;
|
6 |
-
var $total_activity_count;
|
7 |
-
var $activities;
|
8 |
-
var $activity;
|
9 |
-
|
10 |
-
var $in_the_loop;
|
11 |
-
|
12 |
-
var $pag_page;
|
13 |
-
var $pag_num;
|
14 |
-
var $pag_links;
|
15 |
-
|
16 |
-
var $full_name;
|
17 |
-
|
18 |
-
function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
|
19 |
-
global $bp;
|
20 |
-
|
21 |
-
$this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
|
22 |
-
$this->pag_num
|
23 |
-
|
24 |
-
|
25 |
-
$this->disable_blogforum_replies = $bp->site_options['bp-disable-blogforum-comments'];
|
26 |
-
|
27 |
-
|
28 |
-
$this->my_favs = maybe_unserialize(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
$this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if ( !$max || $max >= (int)$this->activities['total'] )
|
38 |
-
$this->total_activity_count = (int)$this->activities['total'];
|
39 |
-
else
|
40 |
-
$this->total_activity_count = (int)$max;
|
41 |
-
|
42 |
-
$this->activities = $this->activities['activities'];
|
43 |
-
|
44 |
-
if ( $max ) {
|
45 |
-
if ( $max >= count($this->activities) )
|
46 |
-
$this->activity_count = count($this->activities);
|
47 |
-
else
|
48 |
-
$this->activity_count = (int)$max;
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
if ( !empty( $
|
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 |
-
return $activities_template->
|
255 |
-
}
|
256 |
-
|
257 |
-
function
|
258 |
-
global $activities_template;
|
259 |
-
return $activities_template->
|
260 |
-
}
|
261 |
-
|
262 |
-
function
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
function
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
function
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
function
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
function
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
function
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
function
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
}
|
378 |
-
function
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
function
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
$
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
/*
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
function
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
function
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
}
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
function
|
682 |
-
echo
|
683 |
-
}
|
684 |
-
function
|
685 |
-
global $activities_template;
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
}
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
$
|
748 |
-
|
749 |
-
);
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
$
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
if (
|
814 |
-
return false;
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
$
|
878 |
-
|
879 |
-
$
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
function
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
954 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class BP_Activity_Template {
|
4 |
+
var $current_activity = -1;
|
5 |
+
var $activity_count;
|
6 |
+
var $total_activity_count;
|
7 |
+
var $activities;
|
8 |
+
var $activity;
|
9 |
+
|
10 |
+
var $in_the_loop;
|
11 |
+
|
12 |
+
var $pag_page;
|
13 |
+
var $pag_num;
|
14 |
+
var $pag_links;
|
15 |
+
|
16 |
+
var $full_name;
|
17 |
+
|
18 |
+
function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
|
19 |
+
global $bp;
|
20 |
+
|
21 |
+
$this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
|
22 |
+
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
|
23 |
+
|
24 |
+
// Check if blog/forum replies are disabled
|
25 |
+
$this->disable_blogforum_replies = $bp->site_options['bp-disable-blogforum-comments'];
|
26 |
+
|
27 |
+
// Get an array of the logged in user's favorite activities
|
28 |
+
$this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
|
29 |
+
|
30 |
+
// Fetch specific activity items based on ID's
|
31 |
+
if ( !empty( $include ) )
|
32 |
+
$this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
|
33 |
+
// Fetch all activity items
|
34 |
+
else
|
35 |
+
$this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
|
36 |
+
|
37 |
+
if ( !$max || $max >= (int)$this->activities['total'] )
|
38 |
+
$this->total_activity_count = (int)$this->activities['total'];
|
39 |
+
else
|
40 |
+
$this->total_activity_count = (int)$max;
|
41 |
+
|
42 |
+
$this->activities = $this->activities['activities'];
|
43 |
+
|
44 |
+
if ( $max ) {
|
45 |
+
if ( $max >= count($this->activities) ) {
|
46 |
+
$this->activity_count = count( $this->activities );
|
47 |
+
} else {
|
48 |
+
$this->activity_count = (int)$max;
|
49 |
+
}
|
50 |
+
} else {
|
51 |
+
$this->activity_count = count( $this->activities );
|
52 |
+
}
|
53 |
+
|
54 |
+
$this->full_name = $bp->displayed_user->fullname;
|
55 |
+
|
56 |
+
// Fetch parent content for activity comments so we do not have to query in the loop
|
57 |
+
foreach ( (array)$this->activities as $activity ) {
|
58 |
+
if ( 'activity_comment' != $activity->type )
|
59 |
+
continue;
|
60 |
+
|
61 |
+
$parent_ids[] = $activity->item_id;
|
62 |
+
}
|
63 |
+
|
64 |
+
if ( !empty( $parent_ids ) )
|
65 |
+
$activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
|
66 |
+
|
67 |
+
if ( !empty( $activity_parents['activities'] ) ) {
|
68 |
+
foreach( $activity_parents['activities'] as $parent )
|
69 |
+
$this->activity_parents[$parent->id] = $parent;
|
70 |
+
|
71 |
+
unset( $activity_parents );
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( (int)$this->total_activity_count && (int)$this->pag_num ) {
|
75 |
+
$this->pag_links = paginate_links( array(
|
76 |
+
'base' => add_query_arg( 'acpage', '%#%' ),
|
77 |
+
'format' => '',
|
78 |
+
'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
|
79 |
+
'current' => (int)$this->pag_page,
|
80 |
+
'prev_text' => '←',
|
81 |
+
'next_text' => '→',
|
82 |
+
'mid_size' => 1
|
83 |
+
) );
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
function has_activities() {
|
88 |
+
if ( $this->activity_count )
|
89 |
+
return true;
|
90 |
+
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
|
94 |
+
function next_activity() {
|
95 |
+
$this->current_activity++;
|
96 |
+
$this->activity = $this->activities[$this->current_activity];
|
97 |
+
|
98 |
+
return $this->activity;
|
99 |
+
}
|
100 |
+
|
101 |
+
function rewind_activities() {
|
102 |
+
$this->current_activity = -1;
|
103 |
+
if ( $this->activity_count > 0 ) {
|
104 |
+
$this->activity = $this->activities[0];
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
function user_activities() {
|
109 |
+
if ( $this->current_activity + 1 < $this->activity_count ) {
|
110 |
+
return true;
|
111 |
+
} elseif ( $this->current_activity + 1 == $this->activity_count ) {
|
112 |
+
do_action('activity_loop_end');
|
113 |
+
// Do some cleaning up after the loop
|
114 |
+
$this->rewind_activities();
|
115 |
+
}
|
116 |
+
|
117 |
+
$this->in_the_loop = false;
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
|
121 |
+
function the_activity() {
|
122 |
+
global $activity;
|
123 |
+
|
124 |
+
$this->in_the_loop = true;
|
125 |
+
$this->activity = $this->next_activity();
|
126 |
+
|
127 |
+
if ( is_array( $this->activity ) )
|
128 |
+
$this->activity = (object) $this->activity;
|
129 |
+
|
130 |
+
if ( $this->current_activity == 0 ) // loop has just started
|
131 |
+
do_action('activity_loop_start');
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
function bp_has_activities( $args = '' ) {
|
136 |
+
global $bp, $activities_template;
|
137 |
+
|
138 |
+
/***
|
139 |
+
* Set the defaults based on the current page. Any of these will be overridden
|
140 |
+
* if arguments are directly passed into the loop. Custom plugins should always
|
141 |
+
* pass their parameters directly to the loop.
|
142 |
+
*/
|
143 |
+
$user_id = false;
|
144 |
+
$include = false;
|
145 |
+
$show_hidden = false;
|
146 |
+
$object = false;
|
147 |
+
$primary_id = false;
|
148 |
+
|
149 |
+
/* User filtering */
|
150 |
+
if ( !empty( $bp->displayed_user->id ) )
|
151 |
+
$user_id = $bp->displayed_user->id;
|
152 |
+
|
153 |
+
/* Group filtering */
|
154 |
+
if ( !empty( $bp->groups->current_group ) ) {
|
155 |
+
$object = $bp->groups->id;
|
156 |
+
$primary_id = $bp->groups->current_group->id;
|
157 |
+
|
158 |
+
if ( 'public' != $bp->groups->current_group->status && ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) || $bp->loggedin_user->is_super_admin ) )
|
159 |
+
$show_hidden = true;
|
160 |
+
}
|
161 |
+
|
162 |
+
/* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
|
163 |
+
if ( $bp->current_action == $bp->activity->slug )
|
164 |
+
$include = $bp->action_variables[0];
|
165 |
+
|
166 |
+
/* Note: any params used for filtering can be a single value, or multiple values comma separated. */
|
167 |
+
$defaults = array(
|
168 |
+
'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
|
169 |
+
'include' => $include, // pass an activity_id or string of ID's comma separated
|
170 |
+
'sort' => 'DESC', // sort DESC or ASC
|
171 |
+
'page' => 1, // which page to load
|
172 |
+
'per_page' => 20, // number of items per page
|
173 |
+
'max' => false, // max number to return
|
174 |
+
'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
|
175 |
+
|
176 |
+
/* Scope - pre-built activity filters for a user (friends/groups/favorites/mentions) */
|
177 |
+
'scope' => $bp->current_action,
|
178 |
+
|
179 |
+
/* Filtering */
|
180 |
+
'user_id' => $user_id, // user_id to filter on
|
181 |
+
'object' => $object, // object to filter on e.g. groups, profile, status, friends
|
182 |
+
'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
|
183 |
+
'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
|
184 |
+
'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
|
185 |
+
|
186 |
+
/* Searching */
|
187 |
+
'search_terms' => false // specify terms to search on
|
188 |
+
);
|
189 |
+
|
190 |
+
$r = wp_parse_args( $args, $defaults );
|
191 |
+
extract( $r );
|
192 |
+
|
193 |
+
/* If you have passed a "scope" then this will override any filters you have passed. */
|
194 |
+
if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
|
195 |
+
if ( 'just-me' == $scope )
|
196 |
+
$display_comments = 'stream';
|
197 |
+
|
198 |
+
if ( $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id ) {
|
199 |
+
$show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
|
200 |
+
|
201 |
+
switch ( $scope ) {
|
202 |
+
case 'friends':
|
203 |
+
if ( function_exists( 'friends_get_friend_user_ids' ) )
|
204 |
+
$friends = friends_get_friend_user_ids( $user_id );
|
205 |
+
if ( empty( $friends ) )
|
206 |
+
return false;
|
207 |
+
|
208 |
+
$user_id = implode( ',', (array)$friends );
|
209 |
+
break;
|
210 |
+
case 'groups':
|
211 |
+
if ( function_exists( 'groups_get_user_groups' ) ) {
|
212 |
+
$groups = groups_get_user_groups( $user_id );
|
213 |
+
if ( empty( $groups['groups'] ) )
|
214 |
+
return false;
|
215 |
+
|
216 |
+
$object = $bp->groups->id;
|
217 |
+
$primary_id = implode( ',', (array)$groups['groups'] );
|
218 |
+
|
219 |
+
$user_id = false;
|
220 |
+
}
|
221 |
+
break;
|
222 |
+
case 'favorites':
|
223 |
+
$favs = bp_activity_get_user_favorites( $user_id );
|
224 |
+
if ( empty( $favs ) )
|
225 |
+
return false;
|
226 |
+
|
227 |
+
$include = implode( ',', (array)$favs );
|
228 |
+
break;
|
229 |
+
case 'mentions':
|
230 |
+
$user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
|
231 |
+
$user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
|
232 |
+
$search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
|
233 |
+
$display_comments = 'stream';
|
234 |
+
$user_id = false;
|
235 |
+
break;
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( $max ) {
|
241 |
+
if ( $per_page > $max )
|
242 |
+
$per_page = $max;
|
243 |
+
}
|
244 |
+
|
245 |
+
/* Support for basic filters in earlier BP versions. */
|
246 |
+
$filter = false;
|
247 |
+
if ( isset( $_GET['afilter'] ) )
|
248 |
+
$filter = array( 'object' => $_GET['afilter'] );
|
249 |
+
else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
|
250 |
+
$filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
|
251 |
+
|
252 |
+
$activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
|
253 |
+
|
254 |
+
return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
|
255 |
+
}
|
256 |
+
|
257 |
+
function bp_activities() {
|
258 |
+
global $activities_template;
|
259 |
+
return $activities_template->user_activities();
|
260 |
+
}
|
261 |
+
|
262 |
+
function bp_the_activity() {
|
263 |
+
global $activities_template;
|
264 |
+
return $activities_template->the_activity();
|
265 |
+
}
|
266 |
+
|
267 |
+
function bp_activity_pagination_count() {
|
268 |
+
echo bp_get_activity_pagination_count();
|
269 |
+
}
|
270 |
+
function bp_get_activity_pagination_count() {
|
271 |
+
global $bp, $activities_template;
|
272 |
+
|
273 |
+
$start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
|
274 |
+
$from_num = bp_core_number_format( $start_num );
|
275 |
+
$to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
|
276 |
+
$total = bp_core_number_format( $activities_template->total_activity_count );
|
277 |
+
|
278 |
+
return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' <span class="ajax-loader"></span>';
|
279 |
+
}
|
280 |
+
|
281 |
+
function bp_activity_pagination_links() {
|
282 |
+
echo bp_get_activity_pagination_links();
|
283 |
+
}
|
284 |
+
function bp_get_activity_pagination_links() {
|
285 |
+
global $activities_template;
|
286 |
+
|
287 |
+
return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
|
288 |
+
}
|
289 |
+
|
290 |
+
function bp_activity_count() {
|
291 |
+
echo bp_get_activity_count();
|
292 |
+
}
|
293 |
+
function bp_get_activity_count() {
|
294 |
+
global $activities_template;
|
295 |
+
|
296 |
+
return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
|
297 |
+
}
|
298 |
+
|
299 |
+
function bp_activity_per_page() {
|
300 |
+
echo bp_get_activity_per_page();
|
301 |
+
}
|
302 |
+
function bp_get_activity_per_page() {
|
303 |
+
global $activities_template;
|
304 |
+
|
305 |
+
return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
|
306 |
+
}
|
307 |
+
|
308 |
+
function bp_activities_title() {
|
309 |
+
global $bp_activity_title;
|
310 |
+
|
311 |
+
echo bp_get_activities_title();
|
312 |
+
}
|
313 |
+
function bp_get_activities_title() {
|
314 |
+
global $bp_activity_title;
|
315 |
+
|
316 |
+
return apply_filters( 'bp_get_activities_title', $bp_activity_title );
|
317 |
+
}
|
318 |
+
|
319 |
+
function bp_activities_no_activity() {
|
320 |
+
global $bp_activity_no_activity;
|
321 |
+
|
322 |
+
echo bp_get_activities_no_activity();
|
323 |
+
}
|
324 |
+
function bp_get_activities_no_activity() {
|
325 |
+
global $bp_activity_no_activity;
|
326 |
+
|
327 |
+
return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
|
328 |
+
}
|
329 |
+
|
330 |
+
function bp_activity_id() {
|
331 |
+
echo bp_get_activity_id();
|
332 |
+
}
|
333 |
+
function bp_get_activity_id() {
|
334 |
+
global $activities_template;
|
335 |
+
return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
|
336 |
+
}
|
337 |
+
|
338 |
+
function bp_activity_item_id() {
|
339 |
+
echo bp_get_activity_item_id();
|
340 |
+
}
|
341 |
+
function bp_get_activity_item_id() {
|
342 |
+
global $activities_template;
|
343 |
+
return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
|
344 |
+
}
|
345 |
+
|
346 |
+
function bp_activity_secondary_item_id() {
|
347 |
+
echo bp_get_activity_secondary_item_id();
|
348 |
+
}
|
349 |
+
function bp_get_activity_secondary_item_id() {
|
350 |
+
global $activities_template;
|
351 |
+
return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
|
352 |
+
}
|
353 |
+
|
354 |
+
function bp_activity_date_recorded() {
|
355 |
+
echo bp_get_activity_date_recorded();
|
356 |
+
}
|
357 |
+
function bp_get_activity_date_recorded() {
|
358 |
+
global $activities_template;
|
359 |
+
return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
|
360 |
+
}
|
361 |
+
|
362 |
+
function bp_activity_object_name() {
|
363 |
+
echo bp_get_activity_object_name();
|
364 |
+
}
|
365 |
+
function bp_get_activity_object_name() {
|
366 |
+
global $activities_template;
|
367 |
+
return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
|
368 |
+
}
|
369 |
+
|
370 |
+
function bp_activity_type() {
|
371 |
+
echo bp_get_activity_type();
|
372 |
+
}
|
373 |
+
function bp_get_activity_type() {
|
374 |
+
global $activities_template;
|
375 |
+
return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
|
376 |
+
}
|
377 |
+
function bp_activity_action_name() { echo bp_activity_type(); }
|
378 |
+
function bp_get_activity_action_name() { return bp_get_activity_type(); }
|
379 |
+
|
380 |
+
function bp_activity_user_id() {
|
381 |
+
echo bp_get_activity_user_id();
|
382 |
+
}
|
383 |
+
function bp_get_activity_user_id() {
|
384 |
+
global $activities_template;
|
385 |
+
return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
|
386 |
+
}
|
387 |
+
|
388 |
+
function bp_activity_user_link() {
|
389 |
+
echo bp_get_activity_user_link();
|
390 |
+
}
|
391 |
+
function bp_get_activity_user_link() {
|
392 |
+
global $activities_template;
|
393 |
+
|
394 |
+
if ( empty( $activities_template->activity->user_id ) )
|
395 |
+
$link = $activities_template->activity->primary_link;
|
396 |
+
else
|
397 |
+
$link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
|
398 |
+
|
399 |
+
return apply_filters( 'bp_get_activity_user_link', $link );
|
400 |
+
}
|
401 |
+
|
402 |
+
/**
|
403 |
+
* bp_activity_avatar( $args )
|
404 |
+
*
|
405 |
+
* Output the avatar of the user that performed the action
|
406 |
+
*
|
407 |
+
* @param array $args
|
408 |
+
*/
|
409 |
+
function bp_activity_avatar( $args = '' ) {
|
410 |
+
echo bp_get_activity_avatar( $args );
|
411 |
+
}
|
412 |
+
/**
|
413 |
+
* bp_get_activity_avatar( $args )
|
414 |
+
*
|
415 |
+
* Return the avatar of the user that performed the action
|
416 |
+
*
|
417 |
+
* @global array $bp
|
418 |
+
* @global object $activities_template
|
419 |
+
* @param array $args optional
|
420 |
+
* @return string
|
421 |
+
*/
|
422 |
+
function bp_get_activity_avatar( $args = '' ) {
|
423 |
+
global $bp, $activities_template;
|
424 |
+
|
425 |
+
$defaults = array(
|
426 |
+
'type' => 'thumb',
|
427 |
+
'width' => 20,
|
428 |
+
'height' => 20,
|
429 |
+
'class' => 'avatar',
|
430 |
+
'alt' => __( 'Avatar', 'buddypress' ),
|
431 |
+
'email' => false
|
432 |
+
);
|
433 |
+
|
434 |
+
$r = wp_parse_args( $args, $defaults );
|
435 |
+
extract( $r, EXTR_SKIP );
|
436 |
+
|
437 |
+
// Primary activity avatar is always a user, but can be modified via a filter
|
438 |
+
$object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, 'user' );
|
439 |
+
$item_id = apply_filters( 'bp_get_activity_avatar_item_id', $activities_template->activity->user_id );
|
440 |
+
|
441 |
+
// If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
|
442 |
+
if ( 'user' == $object && empty( $email ) )
|
443 |
+
$email = $activities_template->activity->user_email;
|
444 |
+
|
445 |
+
return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* bp_activity_secondary_avatar( $args )
|
450 |
+
*
|
451 |
+
* Output the avatar of the object that action was performed on
|
452 |
+
*
|
453 |
+
* @param array $args optional
|
454 |
+
*/
|
455 |
+
function bp_activity_secondary_avatar( $args = '' ) {
|
456 |
+
echo bp_get_activity_secondary_avatar( $args );
|
457 |
+
}
|
458 |
+
/**
|
459 |
+
* bp_get_activity_secondary_avatar( $args )
|
460 |
+
*
|
461 |
+
* Return the avatar of the object that action was performed on
|
462 |
+
*
|
463 |
+
* @global array $bp
|
464 |
+
* @global object $activities_template
|
465 |
+
* @param array $args optional
|
466 |
+
* @return string
|
467 |
+
*/
|
468 |
+
function bp_get_activity_secondary_avatar( $args = '' ) {
|
469 |
+
global $bp, $activities_template;
|
470 |
+
|
471 |
+
$defaults = array(
|
472 |
+
'type' => 'thumb',
|
473 |
+
'width' => 20,
|
474 |
+
'height' => 20,
|
475 |
+
'class' => 'avatar',
|
476 |
+
'alt' => __( 'Avatar', 'buddypress' ),
|
477 |
+
'email' => false
|
478 |
+
);
|
479 |
+
|
480 |
+
$r = wp_parse_args( $args, $defaults );
|
481 |
+
extract( $r, EXTR_SKIP );
|
482 |
+
|
483 |
+
// Set item_id and object (default to user)
|
484 |
+
switch ( $activities_template->activity->component ) {
|
485 |
+
case 'groups' :
|
486 |
+
$object = 'group';
|
487 |
+
$item_id = $activities_template->activity->item_id;
|
488 |
+
break;
|
489 |
+
case 'blogs' :
|
490 |
+
$object = 'blog';
|
491 |
+
$item_id = $activities_template->activity->item_id;
|
492 |
+
break;
|
493 |
+
case 'friends' :
|
494 |
+
$object = 'user';
|
495 |
+
$item_id = $activities_template->activity->secondary_item_id;
|
496 |
+
break;
|
497 |
+
default :
|
498 |
+
$object = 'user';
|
499 |
+
$item_id = $activities_template->activity->user_id;
|
500 |
+
$email = $activities_template->activity->user_email;
|
501 |
+
break;
|
502 |
+
}
|
503 |
+
|
504 |
+
// Allow object and item_id to be filtered
|
505 |
+
$object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
|
506 |
+
$item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
|
507 |
+
|
508 |
+
// If we have no item_id or object, there is no avatar to display
|
509 |
+
if ( empty( $item_id ) || empty( $object ) )
|
510 |
+
return false;
|
511 |
+
|
512 |
+
return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
|
513 |
+
}
|
514 |
+
|
515 |
+
function bp_activity_action() {
|
516 |
+
echo bp_get_activity_action();
|
517 |
+
}
|
518 |
+
function bp_get_activity_action() {
|
519 |
+
global $activities_template;
|
520 |
+
|
521 |
+
$action = $activities_template->activity->action;
|
522 |
+
|
523 |
+
$action = apply_filters( 'bp_get_activity_action_pre_meta', $action, &$activities_template->activity );
|
524 |
+
|
525 |
+
if ( !empty( $action ) )
|
526 |
+
$action = bp_insert_activity_meta( $action );
|
527 |
+
|
528 |
+
return apply_filters( 'bp_get_activity_action', $action, &$activities_template->activity );
|
529 |
+
}
|
530 |
+
|
531 |
+
function bp_activity_content_body() {
|
532 |
+
echo bp_get_activity_content_body();
|
533 |
+
}
|
534 |
+
function bp_get_activity_content_body() {
|
535 |
+
global $activities_template;
|
536 |
+
|
537 |
+
/* Backwards compatibility if action is not being used */
|
538 |
+
if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
|
539 |
+
$activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
|
540 |
+
|
541 |
+
return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content, &$activities_template->activity );
|
542 |
+
}
|
543 |
+
|
544 |
+
function bp_activity_has_content() {
|
545 |
+
global $activities_template;
|
546 |
+
|
547 |
+
if ( !empty( $activities_template->activity->content ) )
|
548 |
+
return true;
|
549 |
+
|
550 |
+
return false;
|
551 |
+
}
|
552 |
+
|
553 |
+
function bp_activity_content() {
|
554 |
+
echo bp_get_activity_content();
|
555 |
+
}
|
556 |
+
function bp_get_activity_content() {
|
557 |
+
global $activities_template;
|
558 |
+
|
559 |
+
/***
|
560 |
+
* If you want to filter activity update content, please use
|
561 |
+
* the filter 'bp_get_activity_content_body'
|
562 |
+
*
|
563 |
+
* This function is mainly for backwards comptibility.
|
564 |
+
*/
|
565 |
+
|
566 |
+
$content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
|
567 |
+
return apply_filters( 'bp_get_activity_content', $content );
|
568 |
+
}
|
569 |
+
|
570 |
+
function bp_insert_activity_meta( $content ) {
|
571 |
+
global $activities_template, $bp;
|
572 |
+
|
573 |
+
/* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */
|
574 |
+
$content = str_replace( '<span class="time-since">%s</span>', '', $content );
|
575 |
+
|
576 |
+
/* Insert the time since. */
|
577 |
+
$content .= ' ' . apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( ' %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );
|
578 |
+
|
579 |
+
/* Insert the permalink */
|
580 |
+
$content .= apply_filters( 'bp_activity_permalink', ' · <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity );
|
581 |
+
|
582 |
+
/* Add the delete link if the user has permission on this item */
|
583 |
+
if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_super_admin )
|
584 |
+
$content .= apply_filters( 'bp_activity_delete_link', ' · ' . bp_get_activity_delete_link(), &$activities_template->activity );
|
585 |
+
|
586 |
+
return apply_filters( 'bp_insert_activity_meta', $content );
|
587 |
+
}
|
588 |
+
|
589 |
+
function bp_activity_parent_content( $args = '' ) {
|
590 |
+
echo bp_get_activity_parent_content($args);
|
591 |
+
}
|
592 |
+
function bp_get_activity_parent_content( $args = '' ) {
|
593 |
+
global $bp, $activities_template;
|
594 |
+
|
595 |
+
$defaults = array(
|
596 |
+
'hide_user' => false
|
597 |
+
);
|
598 |
+
|
599 |
+
$r = wp_parse_args( $args, $defaults );
|
600 |
+
extract( $r, EXTR_SKIP );
|
601 |
+
|
602 |
+
/* Get the ID of the parent activity content */
|
603 |
+
if ( !$parent_id = $activities_template->activity->item_id )
|
604 |
+
return false;
|
605 |
+
|
606 |
+
/* Get the content of the parent */
|
607 |
+
if ( empty( $activities_template->activity_parents[$parent_id] ) )
|
608 |
+
return false;
|
609 |
+
|
610 |
+
if ( empty( $activities_template->activity_parents[$parent_id]->content ) )
|
611 |
+
$content = $activities_template->activity_parents[$parent_id]->action;
|
612 |
+
else
|
613 |
+
$content = $activities_template->activity_parents[$parent_id]->action . ' ' . $activities_template->activity_parents[$parent_id]->content;
|
614 |
+
|
615 |
+
/* Remove the time since content for backwards compatibility */
|
616 |
+
$content = str_replace( '<span class="time-since">%s</span>', '', $content );
|
617 |
+
|
618 |
+
/* Remove images */
|
619 |
+
$content = preg_replace( '/<img[^>]*>/Ui', '', $content );
|
620 |
+
|
621 |
+
return apply_filters( 'bp_get_activity_parent_content', $content );
|
622 |
+
}
|
623 |
+
|
624 |
+
function bp_activity_is_favorite() {
|
625 |
+
echo bp_get_activity_is_favorite();
|
626 |
+
}
|
627 |
+
function bp_get_activity_is_favorite() {
|
628 |
+
global $bp, $activities_template;
|
629 |
+
|
630 |
+
return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
|
631 |
+
}
|
632 |
+
|
633 |
+
function bp_activity_comments( $args = '' ) {
|
634 |
+
echo bp_activity_get_comments( $args );
|
635 |
+
}
|
636 |
+
function bp_activity_get_comments( $args = '' ) {
|
637 |
+
global $activities_template, $bp;
|
638 |
+
|
639 |
+
if ( !$activities_template->activity->children )
|
640 |
+
return false;
|
641 |
+
|
642 |
+
$comments_html = bp_activity_recurse_comments( $activities_template->activity );
|
643 |
+
|
644 |
+
return apply_filters( 'bp_activity_get_comments', $comments_html );
|
645 |
+
}
|
646 |
+
/* TODO: The HTML in this function is temporary and will be moved to the template in a future version. */
|
647 |
+
function bp_activity_recurse_comments( $comment ) {
|
648 |
+
global $activities_template, $bp;
|
649 |
+
|
650 |
+
if ( !$comment->children )
|
651 |
+
return false;
|
652 |
+
|
653 |
+
$content .= '<ul>';
|
654 |
+
foreach ( (array)$comment->children as $comment ) {
|
655 |
+
if ( !$comment->user_fullname )
|
656 |
+
$comment->user_fullname = $comment->display_name;
|
657 |
+
|
658 |
+
$content .= '<li id="acomment-' . $comment->id . '">';
|
659 |
+
$content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 20, 'height' => 20, 'email' => $comment->user_email ) ) . '</a></div>';
|
660 |
+
$content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_acomment_name', $comment->user_fullname, $comment ) . '</a> · ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $comment->date_recorded ) );
|
661 |
+
|
662 |
+
/* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
|
663 |
+
if ( is_user_logged_in() )
|
664 |
+
$content .= '<span class="acomment-replylink"> · <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>';
|
665 |
+
|
666 |
+
/* Delete link */
|
667 |
+
if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id )
|
668 |
+
$content .= ' · <a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
|
669 |
+
|
670 |
+
$content .= '</div>';
|
671 |
+
$content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
|
672 |
+
|
673 |
+
$content .= bp_activity_recurse_comments( $comment );
|
674 |
+
$content .= '</li>';
|
675 |
+
}
|
676 |
+
$content .= '</ul>';
|
677 |
+
|
678 |
+
return apply_filters( 'bp_activity_recurse_comments', $content );
|
679 |
+
}
|
680 |
+
|
681 |
+
function bp_activity_comment_count() {
|
682 |
+
echo bp_activity_get_comment_count();
|
683 |
+
}
|
684 |
+
function bp_activity_get_comment_count( $args = '' ) {
|
685 |
+
global $activities_template, $bp;
|
686 |
+
|
687 |
+
if ( !$activities_template->activity->children )
|
688 |
+
return 0;
|
689 |
+
|
690 |
+
$count = bp_activity_recurse_comment_count( $activities_template->activity );
|
691 |
+
|
692 |
+
return apply_filters( 'bp_activity_get_comment_count', (int)$count );
|
693 |
+
}
|
694 |
+
function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
|
695 |
+
global $activities_template, $bp;
|
696 |
+
|
697 |
+
if ( !$comment->children )
|
698 |
+
return $count;
|
699 |
+
|
700 |
+
foreach ( (array)$comment->children as $comment ) {
|
701 |
+
$count++;
|
702 |
+
$count = bp_activity_recurse_comment_count( $comment, $count );
|
703 |
+
}
|
704 |
+
|
705 |
+
return $count;
|
706 |
+
}
|
707 |
+
|
708 |
+
function bp_activity_comment_link() {
|
709 |
+
echo bp_get_activity_comment_link();
|
710 |
+
}
|
711 |
+
function bp_get_activity_comment_link() {
|
712 |
+
global $activities_template;
|
713 |
+
return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
|
714 |
+
}
|
715 |
+
|
716 |
+
function bp_activity_comment_form_nojs_display() {
|
717 |
+
echo bp_get_activity_comment_form_nojs_display();
|
718 |
+
}
|
719 |
+
function bp_get_activity_comment_form_nojs_display() {
|
720 |
+
global $activities_template;
|
721 |
+
if ( $_GET['ac'] == $activities_template->activity->id . '/' )
|
722 |
+
return 'style="display: block"';
|
723 |
+
|
724 |
+
return false;
|
725 |
+
}
|
726 |
+
|
727 |
+
function bp_activity_comment_form_action() {
|
728 |
+
echo bp_get_activity_comment_form_action();
|
729 |
+
}
|
730 |
+
function bp_get_activity_comment_form_action() {
|
731 |
+
return apply_filters( 'bp_get_activity_comment_form_action', site_url( BP_ACTIVITY_SLUG . '/reply/' ) );
|
732 |
+
}
|
733 |
+
|
734 |
+
function bp_activity_permalink_id() {
|
735 |
+
echo bp_get_activity_permalink_id();
|
736 |
+
}
|
737 |
+
function bp_get_activity_permalink_id() {
|
738 |
+
global $bp;
|
739 |
+
|
740 |
+
return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
|
741 |
+
}
|
742 |
+
|
743 |
+
function bp_activity_thread_permalink() {
|
744 |
+
echo bp_get_activity_thread_permalink();
|
745 |
+
}
|
746 |
+
function bp_get_activity_thread_permalink() {
|
747 |
+
global $bp, $activities_template;
|
748 |
+
|
749 |
+
$link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
|
750 |
+
|
751 |
+
return apply_filters( 'bp_get_activity_thread_permalink', $link );
|
752 |
+
}
|
753 |
+
|
754 |
+
function bp_activity_favorite_link() {
|
755 |
+
echo bp_get_activity_favorite_link();
|
756 |
+
}
|
757 |
+
function bp_get_activity_favorite_link() {
|
758 |
+
global $activities_template;
|
759 |
+
return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
|
760 |
+
}
|
761 |
+
|
762 |
+
function bp_activity_unfavorite_link() {
|
763 |
+
echo bp_get_activity_unfavorite_link();
|
764 |
+
}
|
765 |
+
function bp_get_activity_unfavorite_link() {
|
766 |
+
global $activities_template;
|
767 |
+
return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
|
768 |
+
}
|
769 |
+
|
770 |
+
function bp_activity_css_class() {
|
771 |
+
echo bp_get_activity_css_class();
|
772 |
+
}
|
773 |
+
function bp_get_activity_css_class() {
|
774 |
+
global $activities_template;
|
775 |
+
|
776 |
+
$mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
|
777 |
+
'friendship_accepted',
|
778 |
+
'friendship_created',
|
779 |
+
'new_blog',
|
780 |
+
'joined_group',
|
781 |
+
'created_group',
|
782 |
+
'new_member'
|
783 |
+
) );
|
784 |
+
|
785 |
+
$class = '';
|
786 |
+
if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
|
787 |
+
$class = ' mini';
|
788 |
+
|
789 |
+
if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
|
790 |
+
$class .= ' has-comments';
|
791 |
+
|
792 |
+
return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
|
793 |
+
}
|
794 |
+
|
795 |
+
function bp_activity_delete_link() {
|
796 |
+
echo bp_get_activity_delete_link();
|
797 |
+
}
|
798 |
+
function bp_get_activity_delete_link() {
|
799 |
+
global $activities_template, $bp;
|
800 |
+
|
801 |
+
return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm">' . __( 'Delete', 'buddypress' ) . '</a>' );
|
802 |
+
}
|
803 |
+
|
804 |
+
function bp_activity_latest_update( $user_id = false ) {
|
805 |
+
echo bp_get_activity_latest_update( $user_id );
|
806 |
+
}
|
807 |
+
function bp_get_activity_latest_update( $user_id = false ) {
|
808 |
+
global $bp;
|
809 |
+
|
810 |
+
if ( !$user_id )
|
811 |
+
$user_id = $bp->displayed_user->id;
|
812 |
+
|
813 |
+
if ( !$update = get_user_meta( $user_id, 'bp_latest_update', true ) )
|
814 |
+
return false;
|
815 |
+
|
816 |
+
$latest_update = '"' . apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) ) . '"';
|
817 |
+
$latest_update .= ' · <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
|
818 |
+
|
819 |
+
return apply_filters( 'bp_get_activity_latest_update', $latest_update );
|
820 |
+
}
|
821 |
+
|
822 |
+
function bp_activity_filter_links( $args = false ) {
|
823 |
+
echo bp_get_activity_filter_links( $args );
|
824 |
+
}
|
825 |
+
function bp_get_activity_filter_links( $args = false ) {
|
826 |
+
global $activities_template, $bp;
|
827 |
+
|
828 |
+
$defaults = array(
|
829 |
+
'style' => 'list'
|
830 |
+
);
|
831 |
+
|
832 |
+
$r = wp_parse_args( $args, $defaults );
|
833 |
+
extract( $r, EXTR_SKIP );
|
834 |
+
|
835 |
+
/* Fetch the names of components that have activity recorded in the DB */
|
836 |
+
$components = BP_Activity_Activity::get_recorded_components();
|
837 |
+
|
838 |
+
if ( !$components )
|
839 |
+
return false;
|
840 |
+
|
841 |
+
foreach ( (array) $components as $component ) {
|
842 |
+
/* Skip the activity comment filter */
|
843 |
+
if ( 'activity' == $component )
|
844 |
+
continue;
|
845 |
+
|
846 |
+
if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
|
847 |
+
$selected = ' class="selected"';
|
848 |
+
else
|
849 |
+
unset($selected);
|
850 |
+
|
851 |
+
$component = esc_attr( $component );
|
852 |
+
|
853 |
+
switch ( $style ) {
|
854 |
+
case 'list':
|
855 |
+
$tag = 'li';
|
856 |
+
$before = '<li id="afilter-' . $component . '"' . $selected . '>';
|
857 |
+
$after = '</li>';
|
858 |
+
break;
|
859 |
+
case 'paragraph':
|
860 |
+
$tag = 'p';
|
861 |
+
$before = '<p id="afilter-' . $component . '"' . $selected . '>';
|
862 |
+
$after = '</p>';
|
863 |
+
break;
|
864 |
+
case 'span':
|
865 |
+
$tag = 'span';
|
866 |
+
$before = '<span id="afilter-' . $component . '"' . $selected . '>';
|
867 |
+
$after = '</span>';
|
868 |
+
break;
|
869 |
+
}
|
870 |
+
|
871 |
+
$link = add_query_arg( 'afilter', $component );
|
872 |
+
$link = remove_query_arg( 'acpage' , $link );
|
873 |
+
|
874 |
+
$link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
|
875 |
+
|
876 |
+
/* Make sure all core internal component names are translatable */
|
877 |
+
$translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
|
878 |
+
|
879 |
+
$component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
|
880 |
+
}
|
881 |
+
|
882 |
+
$link = remove_query_arg( 'afilter' , $link );
|
883 |
+
|
884 |
+
if ( isset( $_GET['afilter'] ) )
|
885 |
+
$component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
|
886 |
+
|
887 |
+
return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
|
888 |
+
}
|
889 |
+
|
890 |
+
function bp_activity_can_comment() {
|
891 |
+
global $activities_template, $bp;
|
892 |
+
|
893 |
+
if ( false === $activities_template->disable_blogforum_replies || (int)$activities_template->disable_blogforum_replies ) {
|
894 |
+
if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() )
|
895 |
+
return false;
|
896 |
+
}
|
897 |
+
|
898 |
+
if ( 'activity_comment' == bp_get_activity_action_name() )
|
899 |
+
return false;
|
900 |
+
|
901 |
+
return true;
|
902 |
+
}
|
903 |
+
|
904 |
+
function bp_total_favorite_count_for_user( $user_id = false ) {
|
905 |
+
echo bp_get_total_favorite_count_for_user( $user_id );
|
906 |
+
}
|
907 |
+
function bp_get_total_favorite_count_for_user( $user_id = false ) {
|
908 |
+
return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
|
909 |
+
}
|
910 |
+
|
911 |
+
function bp_total_mention_count_for_user( $user_id = false ) {
|
912 |
+
echo bp_get_total_favorite_count_for_user( $user_id );
|
913 |
+
}
|
914 |
+
function bp_get_total_mention_count_for_user( $user_id = false ) {
|
915 |
+
return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) );
|
916 |
+
}
|
917 |
+
|
918 |
+
function bp_send_public_message_link() {
|
919 |
+
echo bp_get_send_public_message_link();
|
920 |
+
}
|
921 |
+
function bp_get_send_public_message_link() {
|
922 |
+
global $bp;
|
923 |
+
|
924 |
+
if ( bp_is_my_profile() || !is_user_logged_in() )
|
925 |
+
return false;
|
926 |
+
|
927 |
+
return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->activity->slug . '/?r=' . bp_core_get_username( $bp->displayed_user->user_id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ) );
|
928 |
+
}
|
929 |
+
|
930 |
+
/**
|
931 |
+
* bp_send_public_message_button( $args )
|
932 |
+
*
|
933 |
+
* Output button for sending a public message
|
934 |
+
*
|
935 |
+
* @param array $args
|
936 |
+
*/
|
937 |
+
function bp_send_public_message_button( $args = '' ) {
|
938 |
+
echo bp_get_send_public_message_button( $args );
|
939 |
+
}
|
940 |
+
/**
|
941 |
+
* bp_get_send_public_message_button( $args )
|
942 |
+
*
|
943 |
+
* Return button for sending a public message
|
944 |
+
*
|
945 |
+
* @param array $args
|
946 |
+
* @return string
|
947 |
+
*/
|
948 |
+
function bp_get_send_public_message_button( $args = '' ) {
|
949 |
+
$defaults = array(
|
950 |
+
'id' => 'public_message',
|
951 |
+
'component' => 'activity',
|
952 |
+
'must_be_logged_in' => true,
|
953 |
+
'block_self' => true,
|
954 |
+
'wrapper_id' => 'post-mention',
|
955 |
+
'link_href' => bp_get_send_public_message_link(),
|
956 |
+
'link_title' => __( 'Mention this user in a new public message, this will send the user a notification to get their attention.', 'buddypress' ),
|
957 |
+
'link_text' => __( 'Mention this User', 'buddypress' )
|
958 |
+
);
|
959 |
+
|
960 |
+
$button = wp_parse_args( $args, $defaults );
|
961 |
+
|
962 |
+
// Filter and return the HTML button
|
963 |
+
return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) );
|
964 |
+
}
|
965 |
+
|
966 |
+
function bp_activity_post_form_action() {
|
967 |
+
echo bp_get_activity_post_form_action();
|
968 |
+
}
|
969 |
+
function bp_get_activity_post_form_action() {
|
970 |
+
return apply_filters( 'bp_get_activity_post_form_action', site_url( BP_ACTIVITY_SLUG . '/post/' ) );
|
971 |
+
}
|
972 |
+
|
973 |
+
/* RSS Feed Template Tags ***************************/
|
974 |
+
|
975 |
+
function bp_sitewide_activity_feed_link() {
|
976 |
+
echo bp_get_sitewide_activity_feed_link();
|
977 |
+
}
|
978 |
+
function bp_get_sitewide_activity_feed_link() {
|
979 |
+
global $bp;
|
980 |
+
|
981 |
+
return apply_filters( 'bp_get_sitewide_activity_feed_link', site_url( $bp->activity->slug . '/feed/' ) );
|
982 |
+
}
|
983 |
+
|
984 |
+
function bp_member_activity_feed_link() {
|
985 |
+
echo bp_get_member_activity_feed_link();
|
986 |
+
}
|
987 |
+
function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
|
988 |
+
|
989 |
+
function bp_get_member_activity_feed_link() {
|
990 |
+
global $bp;
|
991 |
+
|
992 |
+
if ( $bp->current_component == $bp->profile->slug || 'just-me' == $bp->current_action )
|
993 |
+
$link = $bp->displayed_user->domain . $bp->activity->slug . '/feed/';
|
994 |
+
else if ( 'friends' == $bp->current_action )
|
995 |
+
$link = $bp->displayed_user->domain . $bp->activity->slug . '/friends/feed/';
|
996 |
+
else if ( 'groups' == $bp->current_action )
|
997 |
+
$link = $bp->displayed_user->domain . $bp->activity->slug . '/groups/feed/';
|
998 |
+
else if ( 'favorites' == $bp->current_action )
|
999 |
+
$link = $bp->displayed_user->domain . $bp->activity->slug . '/favorites/feed/';
|
1000 |
+
else if ( 'mentions' == $bp->current_action )
|
1001 |
+
$link = $bp->displayed_user->domain . $bp->activity->slug . '/mentions/feed/';
|
1002 |
+
|
1003 |
+
return apply_filters( 'bp_get_activities_member_rss_link', $link );
|
1004 |
+
}
|
1005 |
+
function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
|
1006 |
+
|
1007 |
+
|
1008 |
+
/* Template tags for RSS feed output */
|
1009 |
+
|
1010 |
+
function bp_activity_feed_item_guid() {
|
1011 |
+
echo bp_get_activity_feed_item_guid();
|
1012 |
+
}
|
1013 |
+
function bp_get_activity_feed_item_guid() {
|
1014 |
+
global $activities_template;
|
1015 |
+
|
1016 |
+
return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
function bp_activity_feed_item_title() {
|
1020 |
+
echo bp_get_activity_feed_item_title();
|
1021 |
+
}
|
1022 |
+
function bp_get_activity_feed_item_title() {
|
1023 |
+
global $activities_template;
|
1024 |
+
|
1025 |
+
if ( !empty( $activities_template->activity->action ) )
|
1026 |
+
$content = $activities_template->activity->action;
|
1027 |
+
else
|
1028 |
+
$content = $activities_template->activity->content;
|
1029 |
+
|
1030 |
+
$content = explode( '<span', $content );
|
1031 |
+
$title = trim( strip_tags( html_entity_decode( utf8_encode( $content[0] ) ) ) );
|
1032 |
+
|
1033 |
+
if ( ':' == substr( $title, -1 ) )
|
1034 |
+
$title = substr( $title, 0, -1 );
|
1035 |
+
|
1036 |
+
if ( 'activity_update' == $activities_template->activity->type )
|
1037 |
+
$title .= ': ' . strip_tags( bp_create_excerpt( $activities_template->activity->content, 15 ) );
|
1038 |
+
|
1039 |
+
return apply_filters( 'bp_get_activity_feed_item_title', $title );
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
function bp_activity_feed_item_link() {
|
1043 |
+
echo bp_get_activity_feed_item_link();
|
1044 |
+
}
|
1045 |
+
function bp_get_activity_feed_item_link() {
|
1046 |
+
global $activities_template;
|
1047 |
+
|
1048 |
+
return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
function bp_activity_feed_item_date() {
|
1052 |
+
echo bp_get_activity_feed_item_date();
|
1053 |
+
}
|
1054 |
+
function bp_get_activity_feed_item_date() {
|
1055 |
+
global $activities_template;
|
1056 |
+
|
1057 |
+
return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
function bp_activity_feed_item_description() {
|
1061 |
+
echo bp_get_activity_feed_item_description();
|
1062 |
+
}
|
1063 |
+
function bp_get_activity_feed_item_description() {
|
1064 |
+
global $activities_template;
|
1065 |
+
|
1066 |
+
if ( empty( $activities_template->activity->action ) )
|
1067 |
+
$content = $activities_template->activity->content;
|
1068 |
+
else
|
1069 |
+
$content = $activities_template->activity->action . ' ' . $activities_template->activity->content;
|
1070 |
+
|
1071 |
+
return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $content ) ) );
|
1072 |
+
}
|
1073 |
+
|
1074 |
?>
|
bp-activity/feeds/bp-activity-friends-feed.php
CHANGED
@@ -1,59 +1,59 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* RSS2 Feed Template for displaying a member's friends activity stream.
|
4 |
-
*
|
5 |
-
* @package BuddyPress
|
6 |
-
*/
|
7 |
-
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
8 |
-
header('Status: 200 OK');
|
9 |
-
?>
|
10 |
-
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
11 |
-
|
12 |
-
<rss version="2.0"
|
13 |
-
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
14 |
-
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
15 |
-
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
16 |
-
xmlns:atom="http://www.w3.org/2005/Atom"
|
17 |
-
<?php do_action('bp_activity_friends_feed'); ?>
|
18 |
-
>
|
19 |
-
|
20 |
-
<channel>
|
21 |
-
<title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Friends Activity', 'buddypress' ) ?></title>
|
22 |
-
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
23 |
-
<link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' ?></link>
|
24 |
-
<description><?php printf( __( '%s - Friends Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
|
25 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
26 |
-
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
27 |
-
<language><?php echo get_option('rss_language'); ?></language>
|
28 |
-
<?php do_action('bp_activity_friends_feed_head'); ?>
|
29 |
-
|
30 |
-
<?php $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->displayed_user->id ) ); ?>
|
31 |
-
<?php if ( bp_has_activities( 'user_id=' . $friend_ids . '&max=50&display_comments=stream' ) ) : ?>
|
32 |
-
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
33 |
-
<item>
|
34 |
-
<guid><?php bp_activity_thread_permalink() ?></guid>
|
35 |
-
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
36 |
-
<link><?php echo bp_activity_thread_permalink() ?></link>
|
37 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
38 |
-
|
39 |
-
<description>
|
40 |
-
<![CDATA[
|
41 |
-
<?php bp_activity_feed_item_description() ?>
|
42 |
-
|
43 |
-
<?php if ( bp_activity_can_comment() ) : ?>
|
44 |
-
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
45 |
-
<?php endif; ?>
|
46 |
-
|
47 |
-
<?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
|
48 |
-
<br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
|
49 |
-
<?php bp_activity_parent_content() ?>
|
50 |
-
<?php endif; ?>
|
51 |
-
]]>
|
52 |
-
</description>
|
53 |
-
<?php do_action('bp_activity_personal_feed_item'); ?>
|
54 |
-
</item>
|
55 |
-
<?php endwhile; ?>
|
56 |
-
|
57 |
-
<?php endif; ?>
|
58 |
-
</channel>
|
59 |
-
</rss>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* RSS2 Feed Template for displaying a member's friends activity stream.
|
4 |
+
*
|
5 |
+
* @package BuddyPress
|
6 |
+
*/
|
7 |
+
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
8 |
+
header('Status: 200 OK');
|
9 |
+
?>
|
10 |
+
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
11 |
+
|
12 |
+
<rss version="2.0"
|
13 |
+
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
14 |
+
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
15 |
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
16 |
+
xmlns:atom="http://www.w3.org/2005/Atom"
|
17 |
+
<?php do_action('bp_activity_friends_feed'); ?>
|
18 |
+
>
|
19 |
+
|
20 |
+
<channel>
|
21 |
+
<title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Friends Activity', 'buddypress' ) ?></title>
|
22 |
+
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
23 |
+
<link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' ?></link>
|
24 |
+
<description><?php printf( __( '%s - Friends Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
|
25 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
26 |
+
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
27 |
+
<language><?php echo get_option('rss_language'); ?></language>
|
28 |
+
<?php do_action('bp_activity_friends_feed_head'); ?>
|
29 |
+
|
30 |
+
<?php $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->displayed_user->id ) ); ?>
|
31 |
+
<?php if ( bp_has_activities( 'user_id=' . $friend_ids . '&max=50&display_comments=stream' ) ) : ?>
|
32 |
+
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
33 |
+
<item>
|
34 |
+
<guid><?php bp_activity_thread_permalink() ?></guid>
|
35 |
+
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
36 |
+
<link><?php echo bp_activity_thread_permalink() ?></link>
|
37 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
38 |
+
|
39 |
+
<description>
|
40 |
+
<![CDATA[
|
41 |
+
<?php bp_activity_feed_item_description() ?>
|
42 |
+
|
43 |
+
<?php if ( bp_activity_can_comment() ) : ?>
|
44 |
+
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
45 |
+
<?php endif; ?>
|
46 |
+
|
47 |
+
<?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
|
48 |
+
<br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
|
49 |
+
<?php bp_activity_parent_content() ?>
|
50 |
+
<?php endif; ?>
|
51 |
+
]]>
|
52 |
+
</description>
|
53 |
+
<?php do_action('bp_activity_personal_feed_item'); ?>
|
54 |
+
</item>
|
55 |
+
<?php endwhile; ?>
|
56 |
+
|
57 |
+
<?php endif; ?>
|
58 |
+
</channel>
|
59 |
+
</rss>
|
bp-activity/feeds/bp-activity-personal-feed.php
CHANGED
@@ -1,58 +1,58 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* RSS2 Feed Template for displaying a member's activity stream.
|
4 |
-
*
|
5 |
-
* @package BuddyPress
|
6 |
-
*/
|
7 |
-
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
8 |
-
header('Status: 200 OK');
|
9 |
-
?>
|
10 |
-
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
11 |
-
|
12 |
-
<rss version="2.0"
|
13 |
-
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
14 |
-
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
15 |
-
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
16 |
-
xmlns:atom="http://www.w3.org/2005/Atom"
|
17 |
-
<?php do_action('bp_activity_personal_feed'); ?>
|
18 |
-
>
|
19 |
-
|
20 |
-
<channel>
|
21 |
-
<title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Activity', 'buddypress' ) ?></title>
|
22 |
-
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
23 |
-
<link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/feed' ?></link>
|
24 |
-
<description><?php printf( __( '%s - Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
|
25 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
26 |
-
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
27 |
-
<language><?php echo get_option('rss_language'); ?></language>
|
28 |
-
<?php do_action('bp_activity_personal_feed_head'); ?>
|
29 |
-
|
30 |
-
<?php if ( bp_has_activities( 'user_id=' . $bp->displayed_user->id . '&max=50&display_comments=stream' ) ) : ?>
|
31 |
-
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
32 |
-
<item>
|
33 |
-
<guid><?php bp_activity_thread_permalink() ?></guid>
|
34 |
-
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
35 |
-
<link><?php echo bp_activity_thread_permalink() ?></link>
|
36 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
37 |
-
|
38 |
-
<description>
|
39 |
-
<![CDATA[
|
40 |
-
<?php bp_activity_feed_item_description() ?>
|
41 |
-
|
42 |
-
<?php if ( bp_activity_can_comment() ) : ?>
|
43 |
-
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
44 |
-
<?php endif; ?>
|
45 |
-
|
46 |
-
<?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
|
47 |
-
<br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
|
48 |
-
<?php bp_activity_parent_content() ?>
|
49 |
-
<?php endif; ?>
|
50 |
-
]]>
|
51 |
-
</description>
|
52 |
-
<?php do_action('bp_activity_personal_feed_item'); ?>
|
53 |
-
</item>
|
54 |
-
<?php endwhile; ?>
|
55 |
-
|
56 |
-
<?php endif; ?>
|
57 |
-
</channel>
|
58 |
-
</rss>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* RSS2 Feed Template for displaying a member's activity stream.
|
4 |
+
*
|
5 |
+
* @package BuddyPress
|
6 |
+
*/
|
7 |
+
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
8 |
+
header('Status: 200 OK');
|
9 |
+
?>
|
10 |
+
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
11 |
+
|
12 |
+
<rss version="2.0"
|
13 |
+
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
14 |
+
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
15 |
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
16 |
+
xmlns:atom="http://www.w3.org/2005/Atom"
|
17 |
+
<?php do_action('bp_activity_personal_feed'); ?>
|
18 |
+
>
|
19 |
+
|
20 |
+
<channel>
|
21 |
+
<title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Activity', 'buddypress' ) ?></title>
|
22 |
+
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
23 |
+
<link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/feed' ?></link>
|
24 |
+
<description><?php printf( __( '%s - Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
|
25 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
26 |
+
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
27 |
+
<language><?php echo get_option('rss_language'); ?></language>
|
28 |
+
<?php do_action('bp_activity_personal_feed_head'); ?>
|
29 |
+
|
30 |
+
<?php if ( bp_has_activities( 'user_id=' . $bp->displayed_user->id . '&max=50&display_comments=stream' ) ) : ?>
|
31 |
+
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
32 |
+
<item>
|
33 |
+
<guid><?php bp_activity_thread_permalink() ?></guid>
|
34 |
+
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
35 |
+
<link><?php echo bp_activity_thread_permalink() ?></link>
|
36 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
37 |
+
|
38 |
+
<description>
|
39 |
+
<![CDATA[
|
40 |
+
<?php bp_activity_feed_item_description() ?>
|
41 |
+
|
42 |
+
<?php if ( bp_activity_can_comment() ) : ?>
|
43 |
+
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
44 |
+
<?php endif; ?>
|
45 |
+
|
46 |
+
<?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
|
47 |
+
<br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
|
48 |
+
<?php bp_activity_parent_content() ?>
|
49 |
+
<?php endif; ?>
|
50 |
+
]]>
|
51 |
+
</description>
|
52 |
+
<?php do_action('bp_activity_personal_feed_item'); ?>
|
53 |
+
</item>
|
54 |
+
<?php endwhile; ?>
|
55 |
+
|
56 |
+
<?php endif; ?>
|
57 |
+
</channel>
|
58 |
+
</rss>
|
bp-activity/feeds/bp-activity-sitewide-feed.php
CHANGED
@@ -1,54 +1,54 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* RSS2 Feed Template for displaying the site wide activity stream.
|
4 |
-
*
|
5 |
-
* @package BuddyPress
|
6 |
-
*/
|
7 |
-
|
8 |
-
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
9 |
-
header('Status: 200 OK');
|
10 |
-
?>
|
11 |
-
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
12 |
-
|
13 |
-
<rss version="2.0"
|
14 |
-
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
15 |
-
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
16 |
-
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
17 |
-
xmlns:atom="http://www.w3.org/2005/Atom"
|
18 |
-
<?php do_action('bp_activity_sitewide_feed'); ?>
|
19 |
-
>
|
20 |
-
|
21 |
-
<channel>
|
22 |
-
<title><?php echo bp_site_name() ?> | <?php _e( 'Site Wide Activity', 'buddypress' ) ?></title>
|
23 |
-
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
24 |
-
<link><?php echo site_url() . '/' . $bp->activity->slug . '/feed' ?></link>
|
25 |
-
<description><?php _e( 'Site Wide Activity Feed', 'buddypress' ) ?></description>
|
26 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
27 |
-
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
28 |
-
<language><?php echo get_option('rss_language'); ?></language>
|
29 |
-
<?php do_action('bp_activity_sitewide_feed_head'); ?>
|
30 |
-
|
31 |
-
<?php if ( bp_has_activities( 'type=sitewide&max=50&display_comments=threaded' ) ) : ?>
|
32 |
-
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
33 |
-
<item>
|
34 |
-
<guid><?php bp_activity_thread_permalink() ?></guid>
|
35 |
-
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
36 |
-
<link><?php bp_activity_thread_permalink() ?></link>
|
37 |
-
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
38 |
-
|
39 |
-
<description>
|
40 |
-
<![CDATA[
|
41 |
-
<?php bp_activity_feed_item_description() ?>
|
42 |
-
|
43 |
-
<?php if ( bp_activity_can_comment() ) : ?>
|
44 |
-
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
45 |
-
<?php endif; ?>
|
46 |
-
]]>
|
47 |
-
</description>
|
48 |
-
<?php do_action('bp_activity_personal_feed_item'); ?>
|
49 |
-
</item>
|
50 |
-
<?php endwhile; ?>
|
51 |
-
|
52 |
-
<?php endif; ?>
|
53 |
-
</channel>
|
54 |
-
</rss>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* RSS2 Feed Template for displaying the site wide activity stream.
|
4 |
+
*
|
5 |
+
* @package BuddyPress
|
6 |
+
*/
|
7 |
+
|
8 |
+
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
9 |
+
header('Status: 200 OK');
|
10 |
+
?>
|
11 |
+
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
|
12 |
+
|
13 |
+
<rss version="2.0"
|
14 |
+
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
15 |
+
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
16 |
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
17 |
+
xmlns:atom="http://www.w3.org/2005/Atom"
|
18 |
+
<?php do_action('bp_activity_sitewide_feed'); ?>
|
19 |
+
>
|
20 |
+
|
21 |
+
<channel>
|
22 |
+
<title><?php echo bp_site_name() ?> | <?php _e( 'Site Wide Activity', 'buddypress' ) ?></title>
|
23 |
+
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
|
24 |
+
<link><?php echo site_url() . '/' . $bp->activity->slug . '/feed' ?></link>
|
25 |
+
<description><?php _e( 'Site Wide Activity Feed', 'buddypress' ) ?></description>
|
26 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
|
27 |
+
<generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
|
28 |
+
<language><?php echo get_option('rss_language'); ?></language>
|
29 |
+
<?php do_action('bp_activity_sitewide_feed_head'); ?>
|
30 |
+
|
31 |
+
<?php if ( bp_has_activities( 'type=sitewide&max=50&display_comments=threaded' ) ) : ?>
|
32 |
+
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
33 |
+
<item>
|
34 |
+
<guid><?php bp_activity_thread_permalink() ?></guid>
|
35 |
+
<title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
|
36 |
+
<link><?php bp_activity_thread_permalink() ?></link>
|
37 |
+
<pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
|
38 |
+
|
39 |
+
<description>
|
40 |
+
<![CDATA[
|
41 |
+
<?php bp_activity_feed_item_description() ?>
|
42 |
+
|
43 |
+
<?php if ( bp_activity_can_comment() ) : ?>
|
44 |
+
<p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
|
45 |
+
<?php endif; ?>
|
46 |
+
]]>
|
47 |
+
</description>
|
48 |
+
<?php do_action('bp_activity_personal_feed_item'); ?>
|
49 |
+
</item>
|
50 |
+
<?php endwhile; ?>
|
51 |
+
|
52 |
+
<?php endif; ?>
|
53 |
+
</channel>
|
54 |
+
</rss>
|
bp-blogs.php
CHANGED
@@ -1,803 +1,820 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
define ( 'BP_BLOGS_DB_VERSION', '2015' );
|
4 |
-
|
5 |
-
/* Define the slug for the component */
|
6 |
-
if ( !defined( 'BP_BLOGS_SLUG' ) )
|
7 |
-
define ( 'BP_BLOGS_SLUG', 'blogs' );
|
8 |
-
|
9 |
-
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' );
|
10 |
-
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
|
11 |
-
|
12 |
-
/* Include the sitewide blog posts widget if this is a multisite installation */
|
13 |
-
if ( bp_core_is_multisite() )
|
14 |
-
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
|
15 |
-
|
16 |
-
function bp_blogs_install() {
|
17 |
-
global $wpdb, $bp;
|
18 |
-
|
19 |
-
if ( !empty($wpdb->charset) )
|
20 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
21 |
-
|
22 |
-
$sql[] = "CREATE TABLE {$bp->blogs->table_name} (
|
23 |
-
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
24 |
-
user_id bigint(20) NOT NULL,
|
25 |
-
blog_id bigint(20) NOT NULL,
|
26 |
-
KEY user_id (user_id),
|
27 |
-
KEY blog_id (blog_id)
|
28 |
-
) {$charset_collate};";
|
29 |
-
|
30 |
-
$sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
|
31 |
-
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
32 |
-
blog_id bigint(20) NOT NULL,
|
33 |
-
meta_key varchar(255) DEFAULT NULL,
|
34 |
-
meta_value longtext DEFAULT NULL,
|
35 |
-
KEY blog_id (blog_id),
|
36 |
-
KEY meta_key (meta_key)
|
37 |
-
) {$charset_collate};";
|
38 |
-
|
39 |
-
|
40 |
-
require_once(ABSPATH . 'wp-admin/upgrade
|
41 |
-
|
42 |
-
dbDelta($sql);
|
43 |
-
|
44 |
-
// On first installation - record all existing blogs in the system.
|
45 |
-
if ( !(int)get_site_option('bp-blogs-first-install') && bp_core_is_multisite() ) {
|
46 |
-
bp_blogs_record_existing_blogs();
|
47 |
-
add_site_option( 'bp-blogs-first-install', 1 );
|
48 |
-
}
|
49 |
-
|
50 |
-
update_site_option( 'bp-blogs-db-version', BP_BLOGS_DB_VERSION );
|
51 |
-
}
|
52 |
-
|
53 |
-
function bp_blogs_check_installed() {
|
54 |
-
global $wpdb, $bp, $userdata;
|
55 |
-
|
56 |
-
/* Only create the bp-blogs tables if this is a multisite install */
|
57 |
-
if (
|
58 |
-
/* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
|
59 |
-
if ( get_site_option( 'bp-blogs-db-version' ) < BP_BLOGS_DB_VERSION )
|
60 |
-
bp_blogs_install();
|
61 |
-
}
|
62 |
-
}
|
63 |
-
add_action( 'admin_menu', 'bp_blogs_check_installed' );
|
64 |
-
|
65 |
-
function bp_blogs_setup_globals() {
|
66 |
-
global $bp, $wpdb;
|
67 |
-
|
68 |
-
/* For internal identification */
|
69 |
-
$bp->blogs->id = 'blogs';
|
70 |
-
|
71 |
-
$bp->blogs->
|
72 |
-
|
73 |
-
$bp->blogs->
|
74 |
-
$bp->blogs->
|
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 |
-
* Screen
|
145 |
-
*
|
146 |
-
* functions
|
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 |
-
bp_activity_set_action( $bp->blogs->id, '
|
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 |
-
* Business
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
$
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
}
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
*
|
376 |
-
*
|
377 |
-
*
|
378 |
-
*
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
));
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
if
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
if
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
return
|
625 |
-
}
|
626 |
-
|
627 |
-
function
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
}
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
$meta_key =
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
}
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
return
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
}
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define ( 'BP_BLOGS_DB_VERSION', '2015' );
|
4 |
+
|
5 |
+
/* Define the slug for the component */
|
6 |
+
if ( !defined( 'BP_BLOGS_SLUG' ) )
|
7 |
+
define ( 'BP_BLOGS_SLUG', 'blogs' );
|
8 |
+
|
9 |
+
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' );
|
10 |
+
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
|
11 |
+
|
12 |
+
/* Include the sitewide blog posts widget if this is a multisite installation */
|
13 |
+
if ( bp_core_is_multisite() )
|
14 |
+
require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
|
15 |
+
|
16 |
+
function bp_blogs_install() {
|
17 |
+
global $wpdb, $bp;
|
18 |
+
|
19 |
+
if ( !empty($wpdb->charset) )
|
20 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
21 |
+
|
22 |
+
$sql[] = "CREATE TABLE {$bp->blogs->table_name} (
|
23 |
+
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
24 |
+
user_id bigint(20) NOT NULL,
|
25 |
+
blog_id bigint(20) NOT NULL,
|
26 |
+
KEY user_id (user_id),
|
27 |
+
KEY blog_id (blog_id)
|
28 |
+
) {$charset_collate};";
|
29 |
+
|
30 |
+
$sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
|
31 |
+
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
32 |
+
blog_id bigint(20) NOT NULL,
|
33 |
+
meta_key varchar(255) DEFAULT NULL,
|
34 |
+
meta_value longtext DEFAULT NULL,
|
35 |
+
KEY blog_id (blog_id),
|
36 |
+
KEY meta_key (meta_key)
|
37 |
+
) {$charset_collate};";
|
38 |
+
|
39 |
+
|
40 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
41 |
+
|
42 |
+
dbDelta($sql);
|
43 |
+
|
44 |
+
// On first installation - record all existing blogs in the system.
|
45 |
+
if ( !(int)get_site_option('bp-blogs-first-install') && bp_core_is_multisite() ) {
|
46 |
+
bp_blogs_record_existing_blogs();
|
47 |
+
add_site_option( 'bp-blogs-first-install', 1 );
|
48 |
+
}
|
49 |
+
|
50 |
+
update_site_option( 'bp-blogs-db-version', BP_BLOGS_DB_VERSION );
|
51 |
+
}
|
52 |
+
|
53 |
+
function bp_blogs_check_installed() {
|
54 |
+
global $wpdb, $bp, $userdata;
|
55 |
+
|
56 |
+
/* Only create the bp-blogs tables if this is a multisite install */
|
57 |
+
if ( is_super_admin() && bp_core_is_multisite() ) {
|
58 |
+
/* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
|
59 |
+
if ( get_site_option( 'bp-blogs-db-version' ) < BP_BLOGS_DB_VERSION )
|
60 |
+
bp_blogs_install();
|
61 |
+
}
|
62 |
+
}
|
63 |
+
add_action( 'admin_menu', 'bp_blogs_check_installed' );
|
64 |
+
|
65 |
+
function bp_blogs_setup_globals() {
|
66 |
+
global $bp, $wpdb;
|
67 |
+
|
68 |
+
/* For internal identification */
|
69 |
+
$bp->blogs->id = 'blogs';
|
70 |
+
|
71 |
+
$bp->blogs->slug = BP_BLOGS_SLUG;
|
72 |
+
|
73 |
+
$bp->blogs->table_name = $bp->table_prefix . 'bp_user_blogs';
|
74 |
+
$bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta';
|
75 |
+
|
76 |
+
$bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
|
77 |
+
|
78 |
+
/* Register this in the active components array */
|
79 |
+
$bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
|
80 |
+
|
81 |
+
do_action( 'bp_blogs_setup_globals' );
|
82 |
+
}
|
83 |
+
add_action( 'bp_setup_globals', 'bp_blogs_setup_globals' );
|
84 |
+
|
85 |
+
function bp_blogs_setup_root_component() {
|
86 |
+
/* Register 'blogs' as a root component */
|
87 |
+
bp_core_add_root_component( BP_BLOGS_SLUG );
|
88 |
+
}
|
89 |
+
add_action( 'bp_setup_root_components', 'bp_blogs_setup_root_component' );
|
90 |
+
|
91 |
+
/**
|
92 |
+
* bp_blogs_setup_nav()
|
93 |
+
*
|
94 |
+
* Adds "Blog" to the navigation arrays for the current and logged in user.
|
95 |
+
*
|
96 |
+
* @package BuddyPress Blogs
|
97 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
98 |
+
* @uses bp_is_my_profile() Checks to see if the current user being viewed is the logged in user
|
99 |
+
*/
|
100 |
+
function bp_blogs_setup_nav() {
|
101 |
+
global $bp;
|
102 |
+
|
103 |
+
/* Blog/post/comment menus should not appear on single WordPress setups. Although comments
|
104 |
+
and posts made by users will still show on their activity stream .*/
|
105 |
+
if ( !bp_core_is_multisite() )
|
106 |
+
return false;
|
107 |
+
|
108 |
+
/* Add 'Blogs' to the main navigation */
|
109 |
+
bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
|
110 |
+
|
111 |
+
$blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
|
112 |
+
|
113 |
+
/* Set up the component options navigation for Blog */
|
114 |
+
if ( 'blogs' == $bp->current_component ) {
|
115 |
+
if ( bp_is_my_profile() ) {
|
116 |
+
if ( function_exists('xprofile_setup_nav') ) {
|
117 |
+
$bp->bp_options_title = __('My Blogs', 'buddypress');
|
118 |
+
}
|
119 |
+
} else {
|
120 |
+
/* If we are not viewing the logged in user, set up the current users avatar and name */
|
121 |
+
$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
|
122 |
+
$bp->bp_options_title = $bp->displayed_user->fullname;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
do_action( 'bp_blogs_setup_nav' );
|
127 |
+
}
|
128 |
+
add_action( 'bp_setup_nav', 'bp_blogs_setup_nav' );
|
129 |
+
|
130 |
+
function bp_blogs_directory_blogs_setup() {
|
131 |
+
global $bp;
|
132 |
+
|
133 |
+
if ( bp_core_is_multisite() && $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
|
134 |
+
$bp->is_directory = true;
|
135 |
+
|
136 |
+
do_action( 'bp_blogs_directory_blogs_setup' );
|
137 |
+
bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
|
138 |
+
}
|
139 |
+
}
|
140 |
+
add_action( 'wp', 'bp_blogs_directory_blogs_setup', 2 );
|
141 |
+
|
142 |
+
|
143 |
+
/********************************************************************************
|
144 |
+
* Screen Functions
|
145 |
+
*
|
146 |
+
* Screen functions are the controllers of BuddyPress. They will execute when their
|
147 |
+
* specific URL is caught. They will first save or manipulate data using business
|
148 |
+
* functions, then pass on the user to a template file.
|
149 |
+
*/
|
150 |
+
|
151 |
+
function bp_blogs_screen_my_blogs() {
|
152 |
+
global $bp;
|
153 |
+
|
154 |
+
if ( !bp_core_is_multisite() )
|
155 |
+
return false;
|
156 |
+
|
157 |
+
do_action( 'bp_blogs_screen_my_blogs' );
|
158 |
+
bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
|
159 |
+
}
|
160 |
+
|
161 |
+
function bp_blogs_screen_create_a_blog() {
|
162 |
+
global $bp;
|
163 |
+
|
164 |
+
if ( !bp_core_is_multisite() || $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
|
165 |
+
return false;
|
166 |
+
|
167 |
+
if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
|
168 |
+
return false;
|
169 |
+
|
170 |
+
do_action( 'bp_blogs_screen_create_a_blog' );
|
171 |
+
bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
|
172 |
+
}
|
173 |
+
/* The create screen is not attached to a nav item, so we need to attach it to an action */
|
174 |
+
add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
|
175 |
+
|
176 |
+
|
177 |
+
/********************************************************************************
|
178 |
+
* Activity & Notification Functions
|
179 |
+
*
|
180 |
+
* These functions handle the recording, deleting and formatting of activity and
|
181 |
+
* notifications for the user and for this specific component.
|
182 |
+
*/
|
183 |
+
|
184 |
+
function bp_blogs_register_activity_actions() {
|
185 |
+
global $bp;
|
186 |
+
|
187 |
+
if ( !function_exists( 'bp_activity_set_action' ) )
|
188 |
+
return false;
|
189 |
+
|
190 |
+
bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New blog created', 'buddypress' ) );
|
191 |
+
bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New blog post published', 'buddypress' ) );
|
192 |
+
bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New blog post comment posted', 'buddypress' ) );
|
193 |
+
|
194 |
+
do_action( 'bp_blogs_register_activity_actions' );
|
195 |
+
}
|
196 |
+
add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
|
197 |
+
|
198 |
+
function bp_blogs_record_activity( $args = '' ) {
|
199 |
+
global $bp;
|
200 |
+
|
201 |
+
if ( !function_exists( 'bp_activity_add' ) )
|
202 |
+
return false;
|
203 |
+
|
204 |
+
/* Because blog, comment, and blog post code execution happens before anything else
|
205 |
+
we may need to manually instantiate the activity component globals */
|
206 |
+
if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
|
207 |
+
bp_activity_setup_globals();
|
208 |
+
|
209 |
+
$defaults = array(
|
210 |
+
'user_id' => $bp->loggedin_user->id,
|
211 |
+
'action' => '',
|
212 |
+
'content' => '',
|
213 |
+
'primary_link' => '',
|
214 |
+
'component' => $bp->blogs->id,
|
215 |
+
'type' => false,
|
216 |
+
'item_id' => false,
|
217 |
+
'secondary_item_id' => false,
|
218 |
+
'recorded_time' => bp_core_current_time(),
|
219 |
+
'hide_sitewide' => false
|
220 |
+
);
|
221 |
+
|
222 |
+
$r = wp_parse_args( $args, $defaults );
|
223 |
+
extract( $r, EXTR_SKIP );
|
224 |
+
|
225 |
+
/* Remove large images and replace them with just one image thumbnail */
|
226 |
+
if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
|
227 |
+
$content = bp_activity_thumbnail_content_images( $content );
|
228 |
+
|
229 |
+
if ( !empty( $action ) )
|
230 |
+
$action = apply_filters( 'bp_blogs_record_activity_action', $action );
|
231 |
+
|
232 |
+
if ( !empty( $content ) )
|
233 |
+
$content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
|
234 |
+
|
235 |
+
/* Check for an existing entry and update if one exists. */
|
236 |
+
$id = bp_activity_get_activity_id( array(
|
237 |
+
'user_id' => $user_id,
|
238 |
+
'component' => $component,
|
239 |
+
'type' => $type,
|
240 |
+
'item_id' => $item_id,
|
241 |
+
'secondary_item_id' => $secondary_item_id
|
242 |
+
) );
|
243 |
+
|
244 |
+
return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
|
245 |
+
}
|
246 |
+
|
247 |
+
function bp_blogs_delete_activity( $args = true ) {
|
248 |
+
global $bp;
|
249 |
+
|
250 |
+
if ( function_exists('bp_activity_delete_by_item_id') ) {
|
251 |
+
$defaults = array(
|
252 |
+
'item_id' => false,
|
253 |
+
'component' => $bp->blogs->id,
|
254 |
+
'type' => false,
|
255 |
+
'user_id' => false,
|
256 |
+
'secondary_item_id' => false
|
257 |
+
);
|
258 |
+
|
259 |
+
$params = wp_parse_args( $args, $defaults );
|
260 |
+
extract( $params, EXTR_SKIP );
|
261 |
+
|
262 |
+
bp_activity_delete_by_item_id( array(
|
263 |
+
'item_id' => $item_id,
|
264 |
+
'component' => $component,
|
265 |
+
'type' => $type,
|
266 |
+
'user_id' => $user_id,
|
267 |
+
'secondary_item_id' => $secondary_item_id
|
268 |
+
) );
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
/********************************************************************************
|
273 |
+
* Business Functions
|
274 |
+
*
|
275 |
+
* Business functions are where all the magic happens in BuddyPress. They will
|
276 |
+
* handle the actual saving or manipulation of information. Usually they will
|
277 |
+
* hand off to a database class for data access, then return
|
278 |
+
* true or false on success or failure.
|
279 |
+
*/
|
280 |
+
|
281 |
+
function bp_blogs_get_blogs( $args = '' ) {
|
282 |
+
global $bp;
|
283 |
+
|
284 |
+
$defaults = array(
|
285 |
+
'type' => 'active', // active, alphabetical, newest, or random.
|
286 |
+
'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on.
|
287 |
+
'search_terms' => false, // Limit to blogs that match these search terms
|
288 |
+
|
289 |
+
'per_page' => 20, // The number of results to return per page
|
290 |
+
'page' => 1, // The page to return if limiting per page
|
291 |
+
);
|
292 |
+
|
293 |
+
$params = wp_parse_args( $args, $defaults );
|
294 |
+
extract( $params, EXTR_SKIP );
|
295 |
+
|
296 |
+
return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
|
297 |
+
}
|
298 |
+
|
299 |
+
function bp_blogs_record_existing_blogs() {
|
300 |
+
global $bp, $wpdb;
|
301 |
+
|
302 |
+
/* Truncate user blogs table and re-record. */
|
303 |
+
$wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
|
304 |
+
|
305 |
+
$blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0" ) );
|
306 |
+
|
307 |
+
if ( $blog_ids ) {
|
308 |
+
foreach( (array)$blog_ids as $blog_id ) {
|
309 |
+
$users = get_users_of_blog( $blog_id );
|
310 |
+
|
311 |
+
if ( $users ) {
|
312 |
+
foreach ( (array)$users as $user ) {
|
313 |
+
$role = unserialize( $user->meta_value );
|
314 |
+
|
315 |
+
if ( !isset( $role['subscriber'] ) )
|
316 |
+
bp_blogs_record_blog( $blog_id, $user->user_id, true );
|
317 |
+
}
|
318 |
+
}
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Makes BuddyPress aware of a new site so that it can track its activity.
|
325 |
+
*
|
326 |
+
* @global object $bp BuddyPress global settings
|
327 |
+
* @param int $blog_id
|
328 |
+
* @param int $user_id
|
329 |
+
* @param $bool $no_activity ; optional.
|
330 |
+
* @since 1.0
|
331 |
+
* @uses BP_Blogs_Blog
|
332 |
+
*/
|
333 |
+
function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
|
334 |
+
global $bp;
|
335 |
+
|
336 |
+
if ( !$user_id )
|
337 |
+
$user_id = $bp->loggedin_user->id;
|
338 |
+
|
339 |
+
$name = get_blog_option( $blog_id, 'blogname' );
|
340 |
+
$description = get_blog_option( $blog_id, 'blogdescription' );
|
341 |
+
|
342 |
+
if ( empty( $name ) )
|
343 |
+
return false;
|
344 |
+
|
345 |
+
$recorded_blog = new BP_Blogs_Blog;
|
346 |
+
$recorded_blog->user_id = $user_id;
|
347 |
+
$recorded_blog->blog_id = $blog_id;
|
348 |
+
|
349 |
+
$recorded_blog_id = $recorded_blog->save();
|
350 |
+
|
351 |
+
bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
|
352 |
+
bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
|
353 |
+
bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
|
354 |
+
|
355 |
+
// Only record this activity if the blog is public
|
356 |
+
if ( (int)$_POST['blog_public'] && !$no_activity ) {
|
357 |
+
// Record this in activity streams
|
358 |
+
bp_blogs_record_activity( array(
|
359 |
+
'user_id' => $recorded_blog->user_id,
|
360 |
+
'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
|
361 |
+
'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
|
362 |
+
'type' => 'new_blog',
|
363 |
+
'item_id' => $recorded_blog->blog_id
|
364 |
+
) );
|
365 |
+
}
|
366 |
+
|
367 |
+
do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded );
|
368 |
+
}
|
369 |
+
add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
|
370 |
+
|
371 |
+
/**
|
372 |
+
* bp_blogs_update_option_blogname()
|
373 |
+
*
|
374 |
+
* Updates blogname in BuddyPress blogmeta table
|
375 |
+
*
|
376 |
+
* @global object $wpdb DB Layer
|
377 |
+
* @param string $oldvalue Value before save (not used)
|
378 |
+
* @param string $newvalue Value to change meta to
|
379 |
+
*/
|
380 |
+
function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
|
381 |
+
global $wpdb;
|
382 |
+
bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
|
383 |
+
}
|
384 |
+
add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
|
385 |
+
|
386 |
+
/**
|
387 |
+
* bp_blogs_update_option_blogdescription()
|
388 |
+
*
|
389 |
+
* Updates blogdescription in BuddyPress blogmeta table
|
390 |
+
*
|
391 |
+
* @global object $wpdb DB Layer
|
392 |
+
* @param string $oldvalue Value before save (not used)
|
393 |
+
* @param string $newvalue Value to change meta to
|
394 |
+
*/
|
395 |
+
function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
|
396 |
+
global $wpdb;
|
397 |
+
bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
|
398 |
+
}
|
399 |
+
add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
|
400 |
+
|
401 |
+
function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
|
402 |
+
global $bp, $wpdb;
|
403 |
+
|
404 |
+
$post_id = (int)$post_id;
|
405 |
+
$blog_id = (int)$wpdb->blogid;
|
406 |
+
|
407 |
+
if ( !$user_id )
|
408 |
+
$user_id = (int)$post->post_author;
|
409 |
+
|
410 |
+
/* This is to stop infinite loops with Donncha's sitewide tags plugin */
|
411 |
+
if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
|
412 |
+
return false;
|
413 |
+
|
414 |
+
/* Don't record this if it's not a post */
|
415 |
+
if ( $post->post_type != 'post' )
|
416 |
+
return false;
|
417 |
+
|
418 |
+
if ( 'publish' == $post->post_status && '' == $post->post_password ) {
|
419 |
+
if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
|
420 |
+
/* Record this in activity streams */
|
421 |
+
$post_permalink = get_permalink( $post_id );
|
422 |
+
|
423 |
+
$activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
|
424 |
+
$activity_content = $post->post_content;
|
425 |
+
|
426 |
+
bp_blogs_record_activity( array(
|
427 |
+
'user_id' => (int)$post->post_author,
|
428 |
+
'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
|
429 |
+
'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
|
430 |
+
'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
|
431 |
+
'type' => 'new_blog_post',
|
432 |
+
'item_id' => $blog_id,
|
433 |
+
'secondary_item_id' => $post_id,
|
434 |
+
'recorded_time' => $post->post_date_gmt
|
435 |
+
));
|
436 |
+
}
|
437 |
+
} else
|
438 |
+
bp_blogs_remove_post( $post_id, $blog_id );
|
439 |
+
|
440 |
+
bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
|
441 |
+
|
442 |
+
do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
|
443 |
+
}
|
444 |
+
add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
|
445 |
+
|
446 |
+
/**
|
447 |
+
* bp_blogs_record_comment()
|
448 |
+
*
|
449 |
+
* Record blog comment activity. Checks if blog is public and post is not
|
450 |
+
* password protected.
|
451 |
+
*
|
452 |
+
* @global object $wpdb
|
453 |
+
* @global $bp $bp
|
454 |
+
* @param int $comment_id
|
455 |
+
* @param bool $is_approved
|
456 |
+
* @return mixed
|
457 |
+
*/
|
458 |
+
|
459 |
+
function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
|
460 |
+
global $wpdb, $bp;
|
461 |
+
|
462 |
+
// Get the users comment
|
463 |
+
$recorded_comment = get_comment( $comment_id );
|
464 |
+
|
465 |
+
// Don't record activity if the comment hasn't been approved
|
466 |
+
if ( !$is_approved || !$recorded_comment->comment_approved )
|
467 |
+
return false;
|
468 |
+
|
469 |
+
// Don't record activity if no email address has been included
|
470 |
+
if ( empty( $recorded_comment->comment_author_email ) )
|
471 |
+
return false;
|
472 |
+
|
473 |
+
// Get the user_id from the comment author email.
|
474 |
+
$user = get_user_by_email( $recorded_comment->comment_author_email );
|
475 |
+
$user_id = (int)$user->ID;
|
476 |
+
|
477 |
+
// If there's no registered user id, don't record activity
|
478 |
+
if ( empty( $user_id ) )
|
479 |
+
return false;
|
480 |
+
|
481 |
+
// Get blog and post data
|
482 |
+
$blog_id = (int)$wpdb->blogid;
|
483 |
+
$recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
|
484 |
+
|
485 |
+
// If this is a password protected post, don't record the comment
|
486 |
+
if ( !empty( $recorded_comment->post->post_password ) )
|
487 |
+
return false;
|
488 |
+
|
489 |
+
// If blog is public allow activity to be posted
|
490 |
+
if ( get_blog_option( $blog_id, 'blog_public' ) ) {
|
491 |
+
|
492 |
+
// Get activity related links
|
493 |
+
$post_permalink = get_permalink( $recorded_comment->comment_post_ID );
|
494 |
+
$comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
|
495 |
+
|
496 |
+
// Prepare to record in activity streams
|
497 |
+
$activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
|
498 |
+
$activity_content = $recorded_comment->comment_content;
|
499 |
+
|
500 |
+
// Record in activity streams
|
501 |
+
bp_blogs_record_activity( array(
|
502 |
+
'user_id' => $user_id,
|
503 |
+
'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
|
504 |
+
'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
|
505 |
+
'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
|
506 |
+
'type' => 'new_blog_comment',
|
507 |
+
'item_id' => $blog_id,
|
508 |
+
'secondary_item_id' => $comment_id,
|
509 |
+
'recorded_time' => $recorded_comment->comment_date_gmt
|
510 |
+
) );
|
511 |
+
|
512 |
+
// Update the blogs last active date
|
513 |
+
bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
|
514 |
+
}
|
515 |
+
|
516 |
+
return $recorded_comment;
|
517 |
+
}
|
518 |
+
add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
|
519 |
+
add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
|
520 |
+
|
521 |
+
function bp_blogs_manage_comment( $comment_id, $comment_status ) {
|
522 |
+
if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
|
523 |
+
return bp_blogs_remove_comment( $comment_id );
|
524 |
+
|
525 |
+
return bp_blogs_record_comment( $comment_id, true );
|
526 |
+
}
|
527 |
+
add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
|
528 |
+
|
529 |
+
function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id = false ) {
|
530 |
+
global $current_blog;
|
531 |
+
|
532 |
+
if ( empty( $blog_id ) )
|
533 |
+
$blog_id = $current_blog->blog_id;
|
534 |
+
|
535 |
+
if ( $role != 'subscriber' )
|
536 |
+
bp_blogs_record_blog( $blog_id, $user_id, true );
|
537 |
+
}
|
538 |
+
add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
|
539 |
+
|
540 |
+
function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) {
|
541 |
+
global $current_blog;
|
542 |
+
|
543 |
+
if ( empty( $blog_id ) )
|
544 |
+
$blog_id = $current_blog->blog_id;
|
545 |
+
|
546 |
+
bp_blogs_remove_blog_for_user( $user_id, $blog_id );
|
547 |
+
}
|
548 |
+
add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
|
549 |
+
|
550 |
+
function bp_blogs_remove_blog( $blog_id ) {
|
551 |
+
global $bp;
|
552 |
+
|
553 |
+
$blog_id = (int)$blog_id;
|
554 |
+
|
555 |
+
BP_Blogs_Blog::delete_blog_for_all( $blog_id );
|
556 |
+
|
557 |
+
// Delete activity stream item
|
558 |
+
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
|
559 |
+
|
560 |
+
do_action( 'bp_blogs_remove_blog', $blog_id );
|
561 |
+
}
|
562 |
+
add_action( 'delete_blog', 'bp_blogs_remove_blog' );
|
563 |
+
|
564 |
+
function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
|
565 |
+
global $current_user;
|
566 |
+
|
567 |
+
$blog_id = (int)$blog_id;
|
568 |
+
$user_id = (int)$user_id;
|
569 |
+
|
570 |
+
BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
|
571 |
+
|
572 |
+
// Delete activity stream item
|
573 |
+
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
|
574 |
+
|
575 |
+
do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
|
576 |
+
}
|
577 |
+
add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
|
578 |
+
|
579 |
+
function bp_blogs_remove_post( $post_id, $blog_id = false ) {
|
580 |
+
global $current_blog, $bp;
|
581 |
+
|
582 |
+
$post_id = (int)$post_id;
|
583 |
+
|
584 |
+
if ( !$blog_id )
|
585 |
+
$blog_id = (int)$current_blog->blog_id;
|
586 |
+
|
587 |
+
// Delete activity stream item
|
588 |
+
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
|
589 |
+
|
590 |
+
do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
|
591 |
+
}
|
592 |
+
add_action( 'delete_post', 'bp_blogs_remove_post' );
|
593 |
+
|
594 |
+
function bp_blogs_remove_comment( $comment_id ) {
|
595 |
+
global $wpdb, $bp;
|
596 |
+
|
597 |
+
// Delete activity stream item
|
598 |
+
bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
|
599 |
+
|
600 |
+
do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
|
601 |
+
}
|
602 |
+
add_action( 'delete_comment', 'bp_blogs_remove_comment' );
|
603 |
+
|
604 |
+
function bp_blogs_total_blogs() {
|
605 |
+
if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
|
606 |
+
$blogs = BP_Blogs_Blog::get_all();
|
607 |
+
$count = $blogs['total'];
|
608 |
+
wp_cache_set( 'bp_total_blogs', $count, 'bp' );
|
609 |
+
}
|
610 |
+
return $count;
|
611 |
+
}
|
612 |
+
|
613 |
+
function bp_blogs_total_blogs_for_user( $user_id = false ) {
|
614 |
+
global $bp;
|
615 |
+
|
616 |
+
if ( !$user_id )
|
617 |
+
$user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
|
618 |
+
|
619 |
+
if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
|
620 |
+
$count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
|
621 |
+
wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
|
622 |
+
}
|
623 |
+
|
624 |
+
return $count;
|
625 |
+
}
|
626 |
+
|
627 |
+
function bp_blogs_remove_data_for_blog( $blog_id ) {
|
628 |
+
global $bp;
|
629 |
+
|
630 |
+
/* If this is regular blog, delete all data for that blog. */
|
631 |
+
BP_Blogs_Blog::delete_blog_for_all( $blog_id );
|
632 |
+
|
633 |
+
// Delete activity stream item
|
634 |
+
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
|
635 |
+
|
636 |
+
do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
|
637 |
+
}
|
638 |
+
add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
|
639 |
+
|
640 |
+
function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
|
641 |
+
return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
|
642 |
+
}
|
643 |
+
|
644 |
+
function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
|
645 |
+
return BP_Blogs_Blog::get_all( $limit, $page );
|
646 |
+
}
|
647 |
+
|
648 |
+
function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
|
649 |
+
return BP_Blogs_Blog::get( 'random', $limit, $page );
|
650 |
+
}
|
651 |
+
|
652 |
+
function bp_blogs_is_blog_hidden( $blog_id ) {
|
653 |
+
return BP_Blogs_Blog::is_hidden( $blog_id );
|
654 |
+
}
|
655 |
+
|
656 |
+
function bp_blogs_redirect_to_random_blog() {
|
657 |
+
global $bp, $wpdb;
|
658 |
+
|
659 |
+
if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
|
660 |
+
$blog = bp_blogs_get_random_blogs( 1, 1 );
|
661 |
+
|
662 |
+
bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
|
663 |
+
}
|
664 |
+
}
|
665 |
+
add_action( 'wp', 'bp_blogs_redirect_to_random_blog', 6 );
|
666 |
+
|
667 |
+
|
668 |
+
//
|
669 |
+
// Blog meta functions
|
670 |
+
// These functions are used to store specific blogmeta in one global table, rather than in each
|
671 |
+
// blog's options table. Significantly speeds up global blog queries.
|
672 |
+
// By default each blog's name, description and last updated time are stored and synced here.
|
673 |
+
//
|
674 |
+
|
675 |
+
function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
|
676 |
+
global $wpdb, $bp;
|
677 |
+
|
678 |
+
if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
|
679 |
+
return false;
|
680 |
+
|
681 |
+
$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
|
682 |
+
|
683 |
+
if ( is_array($meta_value) || is_object($meta_value) )
|
684 |
+
$meta_value = serialize($meta_value);
|
685 |
+
|
686 |
+
$meta_value = trim( $meta_value );
|
687 |
+
|
688 |
+
if ( !$meta_key ) {
|
689 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
|
690 |
+
} else if ( $meta_value ) {
|
691 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
|
692 |
+
} else {
|
693 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
|
694 |
+
}
|
695 |
+
|
696 |
+
wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
|
697 |
+
|
698 |
+
return true;
|
699 |
+
}
|
700 |
+
|
701 |
+
function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
|
702 |
+
global $wpdb, $bp;
|
703 |
+
|
704 |
+
$blog_id = (int) $blog_id;
|
705 |
+
|
706 |
+
if ( !$blog_id || !bp_core_is_multisite() )
|
707 |
+
return false;
|
708 |
+
|
709 |
+
if ( !empty($meta_key) ) {
|
710 |
+
$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
|
711 |
+
|
712 |
+
if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
|
713 |
+
$metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
|
714 |
+
wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
|
715 |
+
}
|
716 |
+
} else {
|
717 |
+
$metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
|
718 |
+
}
|
719 |
+
|
720 |
+
if ( empty($metas) ) {
|
721 |
+
if ( empty($meta_key) )
|
722 |
+
return array();
|
723 |
+
else
|
724 |
+
return '';
|
725 |
+
}
|
726 |
+
|
727 |
+
$metas = array_map('maybe_unserialize', (array)$metas);
|
728 |
+
|
729 |
+
if ( 1 == count($metas) )
|
730 |
+
return $metas[0];
|
731 |
+
else
|
732 |
+
return $metas;
|
733 |
+
}
|
734 |
+
|
735 |
+
function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
|
736 |
+
global $wpdb, $bp;
|
737 |
+
|
738 |
+
if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
|
739 |
+
return false;
|
740 |
+
|
741 |
+
$meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
|
742 |
+
|
743 |
+
if ( is_string($meta_value) )
|
744 |
+
$meta_value = stripslashes($wpdb->escape($meta_value));
|
745 |
+
|
746 |
+
$meta_value = maybe_serialize($meta_value);
|
747 |
+
|
748 |
+
if (empty($meta_value)) {
|
749 |
+
return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
|
750 |
+
}
|
751 |
+
|
752 |
+
$cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
|
753 |
+
|
754 |
+
if ( !$cur ) {
|
755 |
+
$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) );
|
756 |
+
} else if ( $cur->meta_value != $meta_value ) {
|
757 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key ) );
|
758 |
+
} else {
|
759 |
+
return false;
|
760 |
+
}
|
761 |
+
|
762 |
+
wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
|
763 |
+
|
764 |
+
return true;
|
765 |
+
}
|
766 |
+
|
767 |
+
function bp_blogs_remove_data( $user_id ) {
|
768 |
+
if ( !bp_core_is_multisite() )
|
769 |
+
return false;
|
770 |
+
|
771 |
+
/* If this is regular blog, delete all data for that blog. */
|
772 |
+
BP_Blogs_Blog::delete_blogs_for_user( $user_id );
|
773 |
+
|
774 |
+
do_action( 'bp_blogs_remove_data', $user_id );
|
775 |
+
}
|
776 |
+
add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
|
777 |
+
add_action( 'delete_user', 'bp_blogs_remove_data' );
|
778 |
+
add_action( 'make_spam_user', 'bp_blogs_remove_data' );
|
779 |
+
|
780 |
+
|
781 |
+
/********************************************************************************
|
782 |
+
* Caching
|
783 |
+
*
|
784 |
+
* Caching functions handle the clearing of cached objects and pages on specific
|
785 |
+
* actions throughout BuddyPress.
|
786 |
+
*/
|
787 |
+
|
788 |
+
function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
|
789 |
+
wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
|
790 |
+
wp_cache_delete( 'bp_blogs_for_user_' . $user_id, 'bp' );
|
791 |
+
wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
|
792 |
+
|
793 |
+
/* Clear the sitewide activity cache */
|
794 |
+
wp_cache_delete( 'sitewide_activity', 'bp' );
|
795 |
+
}
|
796 |
+
|
797 |
+
function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
|
798 |
+
bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
|
799 |
+
|
800 |
+
/* Clear the sitewide activity cache */
|
801 |
+
wp_cache_delete( 'sitewide_activity', 'bp' );
|
802 |
+
wp_cache_delete( 'bp_total_blogs', 'bp' );
|
803 |
+
}
|
804 |
+
|
805 |
+
// List actions to clear object caches on
|
806 |
+
add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
|
807 |
+
add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
|
808 |
+
|
809 |
+
// List actions to clear super cached pages on, if super cache is installed
|
810 |
+
add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
|
811 |
+
add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
|
812 |
+
add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
|
813 |
+
add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
|
814 |
+
add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
|
815 |
+
add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
|
816 |
+
add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
|
817 |
+
add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
|
818 |
+
add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
|
819 |
+
|
820 |
+
?>
|
bp-blogs/bp-blogs-classes.php
CHANGED
@@ -1,311 +1,313 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
Class BP_Blogs_Blog {
|
4 |
-
var $id;
|
5 |
-
var $user_id;
|
6 |
-
var $blog_id;
|
7 |
-
|
8 |
-
function bp_blogs_blog( $id = null ) {
|
9 |
-
global $bp, $wpdb;
|
10 |
-
|
11 |
-
if ( !$user_id )
|
12 |
-
$user_id = $bp->displayed_user->id;
|
13 |
-
|
14 |
-
if ( $id ) {
|
15 |
-
$this->id = $id;
|
16 |
-
$this->populate();
|
17 |
-
}
|
18 |
-
}
|
19 |
-
|
20 |
-
function populate() {
|
21 |
-
global $wpdb, $bp;
|
22 |
-
|
23 |
-
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
|
24 |
-
|
25 |
-
$this->user_id = $blog->user_id;
|
26 |
-
$this->blog_id = $blog->blog_id;
|
27 |
-
}
|
28 |
-
|
29 |
-
function save() {
|
30 |
-
global $wpdb, $bp;
|
31 |
-
|
32 |
-
$this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
|
33 |
-
$this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
|
34 |
-
|
35 |
-
do_action( 'bp_blogs_blog_before_save', $this );
|
36 |
-
|
37 |
-
// Don't try and save if there is no user ID or blog ID set.
|
38 |
-
if ( !$this->user_id || !$this->blog_id )
|
39 |
-
return false;
|
40 |
-
|
41 |
-
// Don't save if this blog has already been recorded for the user.
|
42 |
-
if ( !$this->id && $this->exists() )
|
43 |
-
return false;
|
44 |
-
|
45 |
-
if ( $this->id ) {
|
46 |
-
// Update
|
47 |
-
$sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
|
48 |
-
} else {
|
49 |
-
// Save
|
50 |
-
$sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
|
51 |
-
}
|
52 |
-
|
53 |
-
if ( !$wpdb->query($sql) )
|
54 |
-
return false;
|
55 |
-
|
56 |
-
do_action( 'bp_blogs_blog_after_save', $this );
|
57 |
-
|
58 |
-
if ( $this->id )
|
59 |
-
return $this->id;
|
60 |
-
else
|
61 |
-
return $wpdb->insert_id;
|
62 |
-
}
|
63 |
-
|
64 |
-
function exists() {
|
65 |
-
global $bp, $wpdb;
|
66 |
-
|
67 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
|
68 |
-
}
|
69 |
-
|
70 |
-
/* Static Functions */
|
71 |
-
|
72 |
-
function get( $type, $limit = false, $page = false, $user_id = false, $search_terms = false ) {
|
73 |
-
global $bp, $wpdb;
|
74 |
-
|
75 |
-
if ( !$bp->blogs )
|
76 |
-
bp_blogs_setup_globals();
|
77 |
-
|
78 |
-
if ( !is_user_logged_in() || ( !
|
79 |
-
$hidden_sql = "AND wb.public = 1";
|
80 |
-
|
81 |
-
if ( $limit && $page )
|
82 |
-
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
83 |
-
|
84 |
-
if ( $user_id )
|
85 |
-
$user_sql = $wpdb->prepare( " AND b.user_id = %d", $user_id );
|
86 |
-
|
87 |
-
switch ( $type ) {
|
88 |
-
case 'active': default:
|
89 |
-
$order_sql = "ORDER BY bm.meta_value DESC";
|
90 |
-
break;
|
91 |
-
case 'alphabetical':
|
92 |
-
$order_sql = "ORDER BY bm2.meta_value ASC";
|
93 |
-
break;
|
94 |
-
case 'newest':
|
95 |
-
$order_sql = "ORDER BY wb.registered DESC";
|
96 |
-
break;
|
97 |
-
case 'random':
|
98 |
-
$order_sql = "ORDER BY RAND()";
|
99 |
-
break;
|
100 |
-
}
|
101 |
-
|
102 |
-
if ( !empty( $search_terms ) ) {
|
103 |
-
$filter = like_escape( $wpdb->escape( $search_terms ) );
|
104 |
-
$paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND bm2.meta_value LIKE '%%$filter%%' {$user_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
|
105 |
-
$total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND bm.blog_id = b.blog_id AND bm2.blog_id = b.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'name' AND bm2.meta_key = 'description' AND ( bm.meta_value LIKE '%%$filter%%' || bm2.meta_value LIKE '%%$filter%%' ) {$user_sql}" );
|
106 |
-
} else {
|
107 |
-
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' GROUP BY b.blog_id {$order_sql} {$pag_sql}" ) );
|
108 |
-
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql}" ) );
|
109 |
-
}
|
110 |
-
|
111 |
-
foreach ( (array)$paged_blogs as $blog ) $blog_ids[] = $blog->blog_id;
|
112 |
-
$blog_ids = $wpdb->escape( join( ',', (array)$blog_ids ) );
|
113 |
-
$paged_blogs = BP_Blogs_Blog::get_blog_extras( &$paged_blogs, $blog_ids, $type );
|
114 |
-
|
115 |
-
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
116 |
-
}
|
117 |
-
|
118 |
-
function delete_blog_for_all( $blog_id ) {
|
119 |
-
global $wpdb, $bp;
|
120 |
-
|
121 |
-
if ( !$bp->blogs )
|
122 |
-
bp_blogs_setup_globals();
|
123 |
-
|
124 |
-
bp_blogs_delete_blogmeta( $blog_id );
|
125 |
-
|
126 |
-
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
|
127 |
-
}
|
128 |
-
|
129 |
-
function delete_blog_for_user( $blog_id, $user_id = null ) {
|
130 |
-
global $wpdb, $bp;
|
131 |
-
|
132 |
-
if ( !$bp->blogs )
|
133 |
-
bp_blogs_setup_globals();
|
134 |
-
|
135 |
-
if ( !$user_id )
|
136 |
-
$user_id = $bp->loggedin_user->id;
|
137 |
-
|
138 |
-
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
|
139 |
-
}
|
140 |
-
|
141 |
-
function delete_blogs_for_user( $user_id = null ) {
|
142 |
-
global $wpdb, $bp;
|
143 |
-
|
144 |
-
if ( !$bp->blogs )
|
145 |
-
bp_blogs_setup_globals();
|
146 |
-
|
147 |
-
if ( !$user_id )
|
148 |
-
$user_id = $bp->loggedin_user->id;
|
149 |
-
|
150 |
-
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
|
151 |
-
}
|
152 |
-
|
153 |
-
function get_blogs_for_user( $user_id = false, $show_hidden = false ) {
|
154 |
-
global $bp, $wpdb;
|
155 |
-
|
156 |
-
if ( !$bp->blogs )
|
157 |
-
bp_blogs_setup_globals();
|
158 |
-
|
159 |
-
if ( !$user_id )
|
160 |
-
$user_id = $bp->displayed_user->id;
|
161 |
-
|
162 |
-
// Show logged in users their hidden blogs.
|
163 |
-
if ( !bp_is_my_profile() && !$show_hidden )
|
164 |
-
$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
|
165 |
-
else
|
166 |
-
$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
|
167 |
-
|
168 |
-
$total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
|
169 |
-
|
170 |
-
foreach ( (array)$blogs as $blog ) {
|
171 |
-
$user_blogs[$blog->blog_id] = new stdClass;
|
172 |
-
$user_blogs[$blog->blog_id]->id = $blog->id;
|
173 |
-
$user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
|
174 |
-
$user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
|
175 |
-
$user_blogs[$blog->blog_id]->name = $blog->name;
|
176 |
-
}
|
177 |
-
|
178 |
-
return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
|
179 |
-
}
|
180 |
-
|
181 |
-
function get_blog_ids_for_user( $user_id = false ) {
|
182 |
-
global $bp, $wpdb;
|
183 |
-
|
184 |
-
if ( !$bp->blogs )
|
185 |
-
bp_blogs_setup_globals();
|
186 |
-
|
187 |
-
if ( !$user_id )
|
188 |
-
$user_id = $bp->displayed_user->id;
|
189 |
-
|
190 |
-
return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
|
191 |
-
}
|
192 |
-
|
193 |
-
function is_recorded( $blog_id ) {
|
194 |
-
global $bp, $wpdb;
|
195 |
-
|
196 |
-
if ( !$bp->blogs )
|
197 |
-
bp_blogs_setup_globals();
|
198 |
-
|
199 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
|
200 |
-
}
|
201 |
-
|
202 |
-
function total_blog_count_for_user( $user_id = null ) {
|
203 |
-
global $bp, $wpdb;
|
204 |
-
|
205 |
-
if ( !$bp->blogs )
|
206 |
-
bp_blogs_setup_globals();
|
207 |
-
|
208 |
-
if ( !$user_id )
|
209 |
-
$user_id = $bp->displayed_user->id;
|
210 |
-
|
211 |
-
// If the user is logged in return the blog count including their hidden blogs.
|
212 |
-
if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) ||
|
213 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
|
214 |
-
else
|
215 |
-
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
|
216 |
-
}
|
217 |
-
|
218 |
-
function search_blogs( $filter, $limit = null, $page = null ) {
|
219 |
-
global $wpdb, $bp;
|
220 |
-
|
221 |
-
if ( !$bp->blogs )
|
222 |
-
bp_blogs_setup_globals();
|
223 |
-
|
224 |
-
$filter = like_escape( $wpdb->escape( $filter ) );
|
225 |
-
|
226 |
-
if ( !
|
227 |
-
$hidden_sql = "AND wb.public = 1";
|
228 |
-
|
229 |
-
if ( $limit && $page )
|
230 |
-
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
231 |
-
|
232 |
-
$paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
|
233 |
-
$total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
|
234 |
-
|
235 |
-
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
236 |
-
}
|
237 |
-
|
238 |
-
function get_all( $limit = null, $page = null ) {
|
239 |
-
global $bp, $wpdb;
|
240 |
-
|
241 |
-
if ( !$bp->blogs )
|
242 |
-
bp_blogs_setup_globals();
|
243 |
-
|
244 |
-
if ( !
|
245 |
-
$hidden_sql = "AND wb.public = 1";
|
246 |
-
|
247 |
-
if ( $limit && $page )
|
248 |
-
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
249 |
-
|
250 |
-
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" ) );
|
251 |
-
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" ) );
|
252 |
-
|
253 |
-
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
254 |
-
}
|
255 |
-
|
256 |
-
function get_by_letter( $letter, $limit = null, $page = null ) {
|
257 |
-
global $bp, $wpdb;
|
258 |
-
|
259 |
-
if ( !$bp->blogs )
|
260 |
-
bp_blogs_setup_globals();
|
261 |
-
|
262 |
-
$letter = like_escape( $wpdb->escape( $letter ) );
|
263 |
-
|
264 |
-
if ( !
|
265 |
-
$hidden_sql = "AND wb.public = 1";
|
266 |
-
|
267 |
-
if ( $limit && $page )
|
268 |
-
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
269 |
-
|
270 |
-
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) );
|
271 |
-
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
|
272 |
-
|
273 |
-
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
274 |
-
}
|
275 |
-
|
276 |
-
function get_blog_extras( $paged_blogs, $blog_ids, $type = false ) {
|
277 |
-
global $bp, $wpdb;
|
278 |
-
|
279 |
-
if ( empty( $blog_ids ) )
|
280 |
-
return $paged_blogs;
|
281 |
-
|
282 |
-
for ( $i = 0; $i < count( $paged_blogs ); $i++ )
|
283 |
-
$
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
|
|
|
|
311 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class BP_Blogs_Blog {
|
4 |
+
var $id;
|
5 |
+
var $user_id;
|
6 |
+
var $blog_id;
|
7 |
+
|
8 |
+
function bp_blogs_blog( $id = null ) {
|
9 |
+
global $bp, $wpdb;
|
10 |
+
|
11 |
+
if ( !$user_id )
|
12 |
+
$user_id = $bp->displayed_user->id;
|
13 |
+
|
14 |
+
if ( $id ) {
|
15 |
+
$this->id = $id;
|
16 |
+
$this->populate();
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
function populate() {
|
21 |
+
global $wpdb, $bp;
|
22 |
+
|
23 |
+
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
|
24 |
+
|
25 |
+
$this->user_id = $blog->user_id;
|
26 |
+
$this->blog_id = $blog->blog_id;
|
27 |
+
}
|
28 |
+
|
29 |
+
function save() {
|
30 |
+
global $wpdb, $bp;
|
31 |
+
|
32 |
+
$this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
|
33 |
+
$this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
|
34 |
+
|
35 |
+
do_action( 'bp_blogs_blog_before_save', $this );
|
36 |
+
|
37 |
+
// Don't try and save if there is no user ID or blog ID set.
|
38 |
+
if ( !$this->user_id || !$this->blog_id )
|
39 |
+
return false;
|
40 |
+
|
41 |
+
// Don't save if this blog has already been recorded for the user.
|
42 |
+
if ( !$this->id && $this->exists() )
|
43 |
+
return false;
|
44 |
+
|
45 |
+
if ( $this->id ) {
|
46 |
+
// Update
|
47 |
+
$sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
|
48 |
+
} else {
|
49 |
+
// Save
|
50 |
+
$sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
|
51 |
+
}
|
52 |
+
|
53 |
+
if ( !$wpdb->query($sql) )
|
54 |
+
return false;
|
55 |
+
|
56 |
+
do_action( 'bp_blogs_blog_after_save', $this );
|
57 |
+
|
58 |
+
if ( $this->id )
|
59 |
+
return $this->id;
|
60 |
+
else
|
61 |
+
return $wpdb->insert_id;
|
62 |
+
}
|
63 |
+
|
64 |
+
function exists() {
|
65 |
+
global $bp, $wpdb;
|
66 |
+
|
67 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
|
68 |
+
}
|
69 |
+
|
70 |
+
/* Static Functions */
|
71 |
+
|
72 |
+
function get( $type, $limit = false, $page = false, $user_id = false, $search_terms = false ) {
|
73 |
+
global $bp, $wpdb;
|
74 |
+
|
75 |
+
if ( !$bp->blogs )
|
76 |
+
bp_blogs_setup_globals();
|
77 |
+
|
78 |
+
if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
|
79 |
+
$hidden_sql = "AND wb.public = 1";
|
80 |
+
|
81 |
+
if ( $limit && $page )
|
82 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
83 |
+
|
84 |
+
if ( $user_id )
|
85 |
+
$user_sql = $wpdb->prepare( " AND b.user_id = %d", $user_id );
|
86 |
+
|
87 |
+
switch ( $type ) {
|
88 |
+
case 'active': default:
|
89 |
+
$order_sql = "ORDER BY bm.meta_value DESC";
|
90 |
+
break;
|
91 |
+
case 'alphabetical':
|
92 |
+
$order_sql = "ORDER BY bm2.meta_value ASC";
|
93 |
+
break;
|
94 |
+
case 'newest':
|
95 |
+
$order_sql = "ORDER BY wb.registered DESC";
|
96 |
+
break;
|
97 |
+
case 'random':
|
98 |
+
$order_sql = "ORDER BY RAND()";
|
99 |
+
break;
|
100 |
+
}
|
101 |
+
|
102 |
+
if ( !empty( $search_terms ) ) {
|
103 |
+
$filter = like_escape( $wpdb->escape( $search_terms ) );
|
104 |
+
$paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND bm2.meta_value LIKE '%%$filter%%' {$user_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
|
105 |
+
$total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND bm.blog_id = b.blog_id AND bm2.blog_id = b.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'name' AND bm2.meta_key = 'description' AND ( bm.meta_value LIKE '%%$filter%%' || bm2.meta_value LIKE '%%$filter%%' ) {$user_sql}" );
|
106 |
+
} else {
|
107 |
+
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' GROUP BY b.blog_id {$order_sql} {$pag_sql}" ) );
|
108 |
+
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql}" ) );
|
109 |
+
}
|
110 |
+
|
111 |
+
foreach ( (array)$paged_blogs as $blog ) $blog_ids[] = $blog->blog_id;
|
112 |
+
$blog_ids = $wpdb->escape( join( ',', (array)$blog_ids ) );
|
113 |
+
$paged_blogs = BP_Blogs_Blog::get_blog_extras( &$paged_blogs, $blog_ids, $type );
|
114 |
+
|
115 |
+
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
116 |
+
}
|
117 |
+
|
118 |
+
function delete_blog_for_all( $blog_id ) {
|
119 |
+
global $wpdb, $bp;
|
120 |
+
|
121 |
+
if ( !$bp->blogs )
|
122 |
+
bp_blogs_setup_globals();
|
123 |
+
|
124 |
+
bp_blogs_delete_blogmeta( $blog_id );
|
125 |
+
|
126 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
|
127 |
+
}
|
128 |
+
|
129 |
+
function delete_blog_for_user( $blog_id, $user_id = null ) {
|
130 |
+
global $wpdb, $bp;
|
131 |
+
|
132 |
+
if ( !$bp->blogs )
|
133 |
+
bp_blogs_setup_globals();
|
134 |
+
|
135 |
+
if ( !$user_id )
|
136 |
+
$user_id = $bp->loggedin_user->id;
|
137 |
+
|
138 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
|
139 |
+
}
|
140 |
+
|
141 |
+
function delete_blogs_for_user( $user_id = null ) {
|
142 |
+
global $wpdb, $bp;
|
143 |
+
|
144 |
+
if ( !$bp->blogs )
|
145 |
+
bp_blogs_setup_globals();
|
146 |
+
|
147 |
+
if ( !$user_id )
|
148 |
+
$user_id = $bp->loggedin_user->id;
|
149 |
+
|
150 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
|
151 |
+
}
|
152 |
+
|
153 |
+
function get_blogs_for_user( $user_id = false, $show_hidden = false ) {
|
154 |
+
global $bp, $wpdb;
|
155 |
+
|
156 |
+
if ( !$bp->blogs )
|
157 |
+
bp_blogs_setup_globals();
|
158 |
+
|
159 |
+
if ( !$user_id )
|
160 |
+
$user_id = $bp->displayed_user->id;
|
161 |
+
|
162 |
+
// Show logged in users their hidden blogs.
|
163 |
+
if ( !bp_is_my_profile() && !$show_hidden )
|
164 |
+
$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
|
165 |
+
else
|
166 |
+
$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
|
167 |
+
|
168 |
+
$total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
|
169 |
+
|
170 |
+
foreach ( (array)$blogs as $blog ) {
|
171 |
+
$user_blogs[$blog->blog_id] = new stdClass;
|
172 |
+
$user_blogs[$blog->blog_id]->id = $blog->id;
|
173 |
+
$user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
|
174 |
+
$user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
|
175 |
+
$user_blogs[$blog->blog_id]->name = $blog->name;
|
176 |
+
}
|
177 |
+
|
178 |
+
return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
|
179 |
+
}
|
180 |
+
|
181 |
+
function get_blog_ids_for_user( $user_id = false ) {
|
182 |
+
global $bp, $wpdb;
|
183 |
+
|
184 |
+
if ( !$bp->blogs )
|
185 |
+
bp_blogs_setup_globals();
|
186 |
+
|
187 |
+
if ( !$user_id )
|
188 |
+
$user_id = $bp->displayed_user->id;
|
189 |
+
|
190 |
+
return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
|
191 |
+
}
|
192 |
+
|
193 |
+
function is_recorded( $blog_id ) {
|
194 |
+
global $bp, $wpdb;
|
195 |
+
|
196 |
+
if ( !$bp->blogs )
|
197 |
+
bp_blogs_setup_globals();
|
198 |
+
|
199 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
|
200 |
+
}
|
201 |
+
|
202 |
+
function total_blog_count_for_user( $user_id = null ) {
|
203 |
+
global $bp, $wpdb;
|
204 |
+
|
205 |
+
if ( !$bp->blogs )
|
206 |
+
bp_blogs_setup_globals();
|
207 |
+
|
208 |
+
if ( !$user_id )
|
209 |
+
$user_id = $bp->displayed_user->id;
|
210 |
+
|
211 |
+
// If the user is logged in return the blog count including their hidden blogs.
|
212 |
+
if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_super_admin() )
|
213 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
|
214 |
+
else
|
215 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
|
216 |
+
}
|
217 |
+
|
218 |
+
function search_blogs( $filter, $limit = null, $page = null ) {
|
219 |
+
global $wpdb, $bp;
|
220 |
+
|
221 |
+
if ( !$bp->blogs )
|
222 |
+
bp_blogs_setup_globals();
|
223 |
+
|
224 |
+
$filter = like_escape( $wpdb->escape( $filter ) );
|
225 |
+
|
226 |
+
if ( !is_super_admin() )
|
227 |
+
$hidden_sql = "AND wb.public = 1";
|
228 |
+
|
229 |
+
if ( $limit && $page )
|
230 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
231 |
+
|
232 |
+
$paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
|
233 |
+
$total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
|
234 |
+
|
235 |
+
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
236 |
+
}
|
237 |
+
|
238 |
+
function get_all( $limit = null, $page = null ) {
|
239 |
+
global $bp, $wpdb;
|
240 |
+
|
241 |
+
if ( !$bp->blogs )
|
242 |
+
bp_blogs_setup_globals();
|
243 |
+
|
244 |
+
if ( !is_super_admin() )
|
245 |
+
$hidden_sql = "AND wb.public = 1";
|
246 |
+
|
247 |
+
if ( $limit && $page )
|
248 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
249 |
+
|
250 |
+
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" ) );
|
251 |
+
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" ) );
|
252 |
+
|
253 |
+
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
254 |
+
}
|
255 |
+
|
256 |
+
function get_by_letter( $letter, $limit = null, $page = null ) {
|
257 |
+
global $bp, $wpdb;
|
258 |
+
|
259 |
+
if ( !$bp->blogs )
|
260 |
+
bp_blogs_setup_globals();
|
261 |
+
|
262 |
+
$letter = like_escape( $wpdb->escape( $letter ) );
|
263 |
+
|
264 |
+
if ( !is_super_admin() )
|
265 |
+
$hidden_sql = "AND wb.public = 1";
|
266 |
+
|
267 |
+
if ( $limit && $page )
|
268 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
269 |
+
|
270 |
+
$paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) );
|
271 |
+
$total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
|
272 |
+
|
273 |
+
return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
|
274 |
+
}
|
275 |
+
|
276 |
+
function get_blog_extras( $paged_blogs, $blog_ids, $type = false ) {
|
277 |
+
global $bp, $wpdb;
|
278 |
+
|
279 |
+
if ( empty( $blog_ids ) )
|
280 |
+
return $paged_blogs;
|
281 |
+
|
282 |
+
for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
|
283 |
+
$blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
|
284 |
+
$paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
|
285 |
+
}
|
286 |
+
|
287 |
+
/* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
|
288 |
+
$blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
|
289 |
+
|
290 |
+
for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
|
291 |
+
foreach ( (array)$blog_descs as $desc ) {
|
292 |
+
if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
|
293 |
+
$paged_blogs[$i]->description = $desc->description;
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
return $paged_blogs;
|
298 |
+
}
|
299 |
+
|
300 |
+
function is_hidden( $blog_id ) {
|
301 |
+
global $wpdb;
|
302 |
+
|
303 |
+
if ( !$bp->blogs )
|
304 |
+
bp_blogs_setup_globals();
|
305 |
+
|
306 |
+
if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
|
307 |
+
return true;
|
308 |
+
|
309 |
+
return false;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
?>
|
bp-blogs/bp-blogs-templatetags.php
CHANGED
@@ -1,504 +1,544 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**********************************************************************
|
4 |
-
* Blog listing template class.
|
5 |
-
*/
|
6 |
-
|
7 |
-
class BP_Blogs_Template {
|
8 |
-
var $current_blog = -1;
|
9 |
-
var $blog_count;
|
10 |
-
var $blogs;
|
11 |
-
var $blog;
|
12 |
-
|
13 |
-
var $in_the_loop;
|
14 |
-
|
15 |
-
var $pag_page;
|
16 |
-
var $pag_num;
|
17 |
-
var $pag_links;
|
18 |
-
var $total_blog_count;
|
19 |
-
|
20 |
-
function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
|
21 |
-
global $bp;
|
22 |
-
|
23 |
-
$this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
|
24 |
-
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
|
25 |
-
|
26 |
-
if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
|
27 |
-
$this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
|
28 |
-
else
|
29 |
-
$this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
|
30 |
-
|
31 |
-
if ( !$max || $max >= (int)$this->blogs['total'] )
|
32 |
-
$this->total_blog_count = (int)$this->blogs['total'];
|
33 |
-
else
|
34 |
-
$this->total_blog_count = (int)$max;
|
35 |
-
|
36 |
-
$this->blogs = $this->blogs['blogs'];
|
37 |
-
|
38 |
-
if ( $max ) {
|
39 |
-
if ( $max >= count($this->blogs) )
|
40 |
-
$this->blog_count = count($this->blogs);
|
41 |
-
else
|
42 |
-
$this->blog_count = (int)$max;
|
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 |
-
if ( !empty( $
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
$
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
<
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
<p>
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
<
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
$
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
<?php
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
<?php
|
502 |
-
|
503 |
-
|
504 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**********************************************************************
|
4 |
+
* Blog listing template class.
|
5 |
+
*/
|
6 |
+
|
7 |
+
class BP_Blogs_Template {
|
8 |
+
var $current_blog = -1;
|
9 |
+
var $blog_count;
|
10 |
+
var $blogs;
|
11 |
+
var $blog;
|
12 |
+
|
13 |
+
var $in_the_loop;
|
14 |
+
|
15 |
+
var $pag_page;
|
16 |
+
var $pag_num;
|
17 |
+
var $pag_links;
|
18 |
+
var $total_blog_count;
|
19 |
+
|
20 |
+
function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
|
21 |
+
global $bp;
|
22 |
+
|
23 |
+
$this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
|
24 |
+
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
|
25 |
+
|
26 |
+
if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
|
27 |
+
$this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
|
28 |
+
else
|
29 |
+
$this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
|
30 |
+
|
31 |
+
if ( !$max || $max >= (int)$this->blogs['total'] )
|
32 |
+
$this->total_blog_count = (int)$this->blogs['total'];
|
33 |
+
else
|
34 |
+
$this->total_blog_count = (int)$max;
|
35 |
+
|
36 |
+
$this->blogs = $this->blogs['blogs'];
|
37 |
+
|
38 |
+
if ( $max ) {
|
39 |
+
if ( $max >= count($this->blogs) ) {
|
40 |
+
$this->blog_count = count( $this->blogs );
|
41 |
+
} else {
|
42 |
+
$this->blog_count = (int)$max;
|
43 |
+
}
|
44 |
+
} else {
|
45 |
+
$this->blog_count = count( $this->blogs );
|
46 |
+
}
|
47 |
+
|
48 |
+
if ( (int)$this->total_blog_count && (int)$this->pag_num ) {
|
49 |
+
$this->pag_links = paginate_links( array(
|
50 |
+
'base' => add_query_arg( 'bpage', '%#%' ),
|
51 |
+
'format' => '',
|
52 |
+
'total' => ceil( (int)$this->total_blog_count / (int)$this->pag_num ),
|
53 |
+
'current' => (int)$this->pag_page,
|
54 |
+
'prev_text' => '←',
|
55 |
+
'next_text' => '→',
|
56 |
+
'mid_size' => 1
|
57 |
+
) );
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
function has_blogs() {
|
62 |
+
if ( $this->blog_count )
|
63 |
+
return true;
|
64 |
+
|
65 |
+
return false;
|
66 |
+
}
|
67 |
+
|
68 |
+
function next_blog() {
|
69 |
+
$this->current_blog++;
|
70 |
+
$this->blog = $this->blogs[$this->current_blog];
|
71 |
+
|
72 |
+
return $this->blog;
|
73 |
+
}
|
74 |
+
|
75 |
+
function rewind_blogs() {
|
76 |
+
$this->current_blog = -1;
|
77 |
+
if ( $this->blog_count > 0 ) {
|
78 |
+
$this->blog = $this->blogs[0];
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
function blogs() {
|
83 |
+
if ( $this->current_blog + 1 < $this->blog_count ) {
|
84 |
+
return true;
|
85 |
+
} elseif ( $this->current_blog + 1 == $this->blog_count ) {
|
86 |
+
do_action('loop_end');
|
87 |
+
// Do some cleaning up after the loop
|
88 |
+
$this->rewind_blogs();
|
89 |
+
}
|
90 |
+
|
91 |
+
$this->in_the_loop = false;
|
92 |
+
return false;
|
93 |
+
}
|
94 |
+
|
95 |
+
function the_blog() {
|
96 |
+
global $blog;
|
97 |
+
|
98 |
+
$this->in_the_loop = true;
|
99 |
+
$this->blog = $this->next_blog();
|
100 |
+
|
101 |
+
if ( 0 == $this->current_blog ) // loop has just started
|
102 |
+
do_action('loop_start');
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
function bp_rewind_blogs() {
|
107 |
+
global $blogs_template;
|
108 |
+
|
109 |
+
$blogs_template->rewind_blogs();
|
110 |
+
}
|
111 |
+
|
112 |
+
function bp_has_blogs( $args = '' ) {
|
113 |
+
global $bp, $blogs_template;
|
114 |
+
|
115 |
+
/***
|
116 |
+
* Set the defaults based on the current page. Any of these will be overridden
|
117 |
+
* if arguments are directly passed into the loop. Custom plugins should always
|
118 |
+
* pass their parameters directly to the loop.
|
119 |
+
*/
|
120 |
+
$type = 'active';
|
121 |
+
$user_id = false;
|
122 |
+
$search_terms = false;
|
123 |
+
|
124 |
+
/* User filtering */
|
125 |
+
if ( !empty( $bp->displayed_user->id ) )
|
126 |
+
$user_id = $bp->displayed_user->id;
|
127 |
+
|
128 |
+
if ( !empty( $_REQUEST['s'] ) )
|
129 |
+
$search_terms = $_REQUEST['s'];
|
130 |
+
|
131 |
+
$defaults = array(
|
132 |
+
'type' => $type,
|
133 |
+
'page' => 1,
|
134 |
+
'per_page' => 20,
|
135 |
+
'max' => false,
|
136 |
+
|
137 |
+
'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
|
138 |
+
'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
|
139 |
+
);
|
140 |
+
|
141 |
+
$r = wp_parse_args( $args, $defaults );
|
142 |
+
extract( $r );
|
143 |
+
|
144 |
+
if ( $max ) {
|
145 |
+
if ( $per_page > $max )
|
146 |
+
$per_page = $max;
|
147 |
+
}
|
148 |
+
|
149 |
+
$blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
|
150 |
+
return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
|
151 |
+
}
|
152 |
+
|
153 |
+
function bp_blogs() {
|
154 |
+
global $blogs_template;
|
155 |
+
|
156 |
+
return $blogs_template->blogs();
|
157 |
+
}
|
158 |
+
|
159 |
+
function bp_the_blog() {
|
160 |
+
global $blogs_template;
|
161 |
+
|
162 |
+
return $blogs_template->the_blog();
|
163 |
+
}
|
164 |
+
|
165 |
+
function bp_blogs_pagination_count() {
|
166 |
+
global $bp, $blogs_template;
|
167 |
+
|
168 |
+
$start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
|
169 |
+
$from_num = bp_core_number_format( $start_num );
|
170 |
+
$to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
|
171 |
+
$total = bp_core_number_format( $blogs_template->total_blog_count );
|
172 |
+
|
173 |
+
echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?>
|
174 |
+
<span class="ajax-loader"></span><?php
|
175 |
+
}
|
176 |
+
|
177 |
+
function bp_blogs_pagination_links() {
|
178 |
+
echo bp_get_blogs_pagination_links();
|
179 |
+
}
|
180 |
+
function bp_get_blogs_pagination_links() {
|
181 |
+
global $blogs_template;
|
182 |
+
|
183 |
+
return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
|
184 |
+
}
|
185 |
+
|
186 |
+
function bp_blog_avatar( $args = '' ) {
|
187 |
+
echo bp_get_blog_avatar( $args );
|
188 |
+
}
|
189 |
+
function bp_get_blog_avatar( $args = '' ) {
|
190 |
+
global $blogs_template, $bp;
|
191 |
+
|
192 |
+
$defaults = array(
|
193 |
+
'type' => 'full',
|
194 |
+
'width' => false,
|
195 |
+
'height' => false,
|
196 |
+
'class' => 'avatar',
|
197 |
+
'id' => false,
|
198 |
+
'alt' => __( 'Blog avatar', 'buddypress' ),
|
199 |
+
'no_grav' => true
|
200 |
+
);
|
201 |
+
|
202 |
+
$r = wp_parse_args( $args, $defaults );
|
203 |
+
extract( $r, EXTR_SKIP );
|
204 |
+
|
205 |
+
/***
|
206 |
+
* In future BuddyPress versions you will be able to set the avatar for a blog.
|
207 |
+
* Right now you can use a filter with the ID of the blog to change it if you wish.
|
208 |
+
* By default it will return the avatar for the primary blog admin.
|
209 |
+
*/
|
210 |
+
return apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, bp_core_fetch_avatar( array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) ) );
|
211 |
+
}
|
212 |
+
|
213 |
+
function bp_blog_permalink() {
|
214 |
+
echo bp_get_blog_permalink();
|
215 |
+
}
|
216 |
+
function bp_get_blog_permalink() {
|
217 |
+
global $blogs_template;
|
218 |
+
|
219 |
+
if ( empty( $blogs_template->blog->domain ) )
|
220 |
+
$permalink = $bp->root_domain . $blogs_template->blog->path;
|
221 |
+
else {
|
222 |
+
$protocol = 'http://';
|
223 |
+
if ( is_ssl() )
|
224 |
+
$protocol = 'https://';
|
225 |
+
|
226 |
+
$permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
|
227 |
+
}
|
228 |
+
|
229 |
+
return apply_filters( 'bp_get_blog_permalink', $permalink );
|
230 |
+
}
|
231 |
+
|
232 |
+
function bp_blog_name() {
|
233 |
+
echo bp_get_blog_name();
|
234 |
+
}
|
235 |
+
function bp_get_blog_name() {
|
236 |
+
global $blogs_template;
|
237 |
+
|
238 |
+
return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
|
239 |
+
}
|
240 |
+
|
241 |
+
function bp_blog_description() {
|
242 |
+
echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
|
243 |
+
}
|
244 |
+
function bp_get_blog_description() {
|
245 |
+
global $blogs_template;
|
246 |
+
|
247 |
+
return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
|
248 |
+
}
|
249 |
+
|
250 |
+
function bp_blog_last_active() {
|
251 |
+
echo bp_get_blog_last_active();
|
252 |
+
}
|
253 |
+
function bp_get_blog_last_active() {
|
254 |
+
global $blogs_template;
|
255 |
+
|
256 |
+
return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s ago', 'buddypress' ) ) );
|
257 |
+
}
|
258 |
+
|
259 |
+
function bp_blog_latest_post() {
|
260 |
+
echo bp_get_blog_latest_post();
|
261 |
+
}
|
262 |
+
function bp_get_blog_latest_post() {
|
263 |
+
global $blogs_template;
|
264 |
+
|
265 |
+
if ( null == $blogs_template->blog->latest_post )
|
266 |
+
return false;
|
267 |
+
|
268 |
+
return apply_filters( 'bp_get_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $blogs_template->blog->latest_post->post_title ) . '</a>' ) );
|
269 |
+
}
|
270 |
+
|
271 |
+
function bp_blog_hidden_fields() {
|
272 |
+
if ( isset( $_REQUEST['s'] ) ) {
|
273 |
+
echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( isset( $_REQUEST['letter'] ) ) {
|
277 |
+
echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
|
278 |
+
}
|
279 |
+
|
280 |
+
if ( isset( $_REQUEST['blogs_search'] ) ) {
|
281 |
+
echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
function bp_total_blog_count() {
|
286 |
+
echo bp_get_total_blog_count();
|
287 |
+
}
|
288 |
+
function bp_get_total_blog_count() {
|
289 |
+
return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
|
290 |
+
}
|
291 |
+
add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
|
292 |
+
|
293 |
+
function bp_total_blog_count_for_user( $user_id = false ) {
|
294 |
+
echo bp_get_total_blog_count_for_user( $user_id );
|
295 |
+
}
|
296 |
+
function bp_get_total_blog_count_for_user( $user_id = false ) {
|
297 |
+
return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
|
298 |
+
}
|
299 |
+
add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
|
300 |
+
|
301 |
+
|
302 |
+
/* Blog registration template tags */
|
303 |
+
|
304 |
+
function bp_blog_signup_enabled() {
|
305 |
+
global $bp;
|
306 |
+
|
307 |
+
$active_signup = $bp->site_options['registration'];
|
308 |
+
|
309 |
+
if ( !$active_signup )
|
310 |
+
$active_signup = 'all';
|
311 |
+
|
312 |
+
$active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
|
313 |
+
|
314 |
+
if ( 'none' == $active_signup || 'user' == $active_signup )
|
315 |
+
return false;
|
316 |
+
|
317 |
+
return true;
|
318 |
+
}
|
319 |
+
|
320 |
+
function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
|
321 |
+
global $current_user, $current_site;
|
322 |
+
global $bp;
|
323 |
+
|
324 |
+
require_once( ABSPATH . WPINC . '/registration.php' );
|
325 |
+
|
326 |
+
if ( isset($_POST['submit']) ) {
|
327 |
+
bp_blogs_validate_blog_signup();
|
328 |
+
} else {
|
329 |
+
if ( ! is_wp_error($errors) ) {
|
330 |
+
$errors = new WP_Error();
|
331 |
+
}
|
332 |
+
|
333 |
+
// allow definition of default variables
|
334 |
+
$filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
|
335 |
+
$blogname = $filtered_results['blogname'];
|
336 |
+
$blog_title = $filtered_results['blog_title'];
|
337 |
+
$errors = $filtered_results['errors'];
|
338 |
+
|
339 |
+
if ( $errors->get_error_code() ) {
|
340 |
+
echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
|
341 |
+
}
|
342 |
+
?>
|
343 |
+
<p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p>
|
344 |
+
|
345 |
+
<p><?php _e("If you’re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
|
346 |
+
|
347 |
+
<form class="standard-form" id="setupform" method="post" action="">
|
348 |
+
|
349 |
+
<input type="hidden" name="stage" value="gimmeanotherblog" />
|
350 |
+
<?php do_action( 'signup_hidden_fields' ); ?>
|
351 |
+
|
352 |
+
<?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
|
353 |
+
<p>
|
354 |
+
<input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog →', 'buddypress') ?>" />
|
355 |
+
</p>
|
356 |
+
|
357 |
+
<?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
|
358 |
+
</form>
|
359 |
+
<?php
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
|
364 |
+
global $current_site;
|
365 |
+
|
366 |
+
// Blog name
|
367 |
+
if( !is_subdomain_install() )
|
368 |
+
echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
|
369 |
+
else
|
370 |
+
echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
|
371 |
+
|
372 |
+
if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
|
373 |
+
<p class="error"><?php echo $errmsg ?></p>
|
374 |
+
<?php }
|
375 |
+
|
376 |
+
if ( !is_subdomain_install() )
|
377 |
+
echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
|
378 |
+
else
|
379 |
+
echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
|
380 |
+
|
381 |
+
if ( !is_user_logged_in() ) {
|
382 |
+
print '(<strong>' . __( 'Your address will be ' , 'buddypress');
|
383 |
+
|
384 |
+
if ( !is_subdomain_install() ) {
|
385 |
+
print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
|
386 |
+
} else {
|
387 |
+
print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
|
388 |
+
}
|
389 |
+
|
390 |
+
echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
|
391 |
+
}
|
392 |
+
|
393 |
+
// Blog Title
|
394 |
+
?>
|
395 |
+
<label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
|
396 |
+
<?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
|
397 |
+
<p class="error"><?php echo $errmsg ?></p>
|
398 |
+
<?php }
|
399 |
+
echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
|
400 |
+
?>
|
401 |
+
|
402 |
+
<p>
|
403 |
+
<label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
|
404 |
+
<?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
|
405 |
+
|
406 |
+
|
407 |
+
<label class="checkbox" for="blog_public_on">
|
408 |
+
<input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
|
409 |
+
<strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
|
410 |
+
</label>
|
411 |
+
<label class="checkbox" for="blog_public_off">
|
412 |
+
<input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
|
413 |
+
<strong><?php _e( 'No' , 'buddypress'); ?></strong>
|
414 |
+
</label>
|
415 |
+
</p>
|
416 |
+
|
417 |
+
<?php
|
418 |
+
do_action('signup_blogform', $errors);
|
419 |
+
}
|
420 |
+
|
421 |
+
function bp_blogs_validate_blog_signup() {
|
422 |
+
global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
|
423 |
+
|
424 |
+
if ( !check_admin_referer( 'bp_blog_signup_form' ) )
|
425 |
+
return false;
|
426 |
+
|
427 |
+
$current_user = wp_get_current_user();
|
428 |
+
|
429 |
+
if( !is_user_logged_in() )
|
430 |
+
die();
|
431 |
+
|
432 |
+
$result = bp_blogs_validate_blog_form();
|
433 |
+
extract($result);
|
434 |
+
|
435 |
+
if ( $errors->get_error_code() ) {
|
436 |
+
unset($_POST['submit']);
|
437 |
+
bp_show_blog_signup_form( $blogname, $blog_title, $errors );
|
438 |
+
return false;
|
439 |
+
}
|
440 |
+
|
441 |
+
$public = (int) $_POST['blog_public'];
|
442 |
+
|
443 |
+
$meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
|
444 |
+
$meta = apply_filters( 'add_signup_meta', $meta );
|
445 |
+
|
446 |
+
/* If this is a VHOST install, remove the username from the domain as we are setting this blog
|
447 |
+
up inside a user domain, not the root domain. */
|
448 |
+
|
449 |
+
wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
|
450 |
+
bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
|
451 |
+
return true;
|
452 |
+
}
|
453 |
+
|
454 |
+
function bp_blogs_validate_blog_form() {
|
455 |
+
$user = '';
|
456 |
+
if ( is_user_logged_in() )
|
457 |
+
$user = wp_get_current_user();
|
458 |
+
|
459 |
+
return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
|
460 |
+
}
|
461 |
+
|
462 |
+
function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
|
463 |
+
?>
|
464 |
+
<p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
|
465 |
+
<p>
|
466 |
+
<?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?>
|
467 |
+
</p>
|
468 |
+
<?php
|
469 |
+
do_action('signup_finished');
|
470 |
+
}
|
471 |
+
|
472 |
+
function bp_create_blog_link() {
|
473 |
+
global $bp;
|
474 |
+
|
475 |
+
if ( bp_is_my_profile() ) {
|
476 |
+
echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
|
477 |
+
}
|
478 |
+
}
|
479 |
+
|
480 |
+
function bp_blogs_blog_tabs() {
|
481 |
+
global $bp, $groups_template;
|
482 |
+
|
483 |
+
// Don't show these tabs on a user's own profile
|
484 |
+
if ( bp_is_my_profile() )
|
485 |
+
return false;
|
486 |
+
|
487 |
+
$current_tab = $bp->current_action
|
488 |
+
?>
|
489 |
+
<ul class="content-header-nav">
|
490 |
+
<li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
|
491 |
+
<li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
|
492 |
+
<li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
|
493 |
+
</ul>
|
494 |
+
<?php
|
495 |
+
do_action( 'bp_blogs_blog_tabs', $current_tab );
|
496 |
+
}
|
497 |
+
|
498 |
+
function bp_directory_blogs_search_form() {
|
499 |
+
global $bp; ?>
|
500 |
+
<form action="" method="get" id="search-blogs-form">
|
501 |
+
<label><input type="text" name="s" id="blogs_search" value="<?php if ( isset( $_GET['s'] ) ) { echo $_GET['s']; } else { _e( 'Search anything...', 'buddypress' ); } ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
|
502 |
+
<input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
|
503 |
+
</form>
|
504 |
+
<?php
|
505 |
+
}
|
506 |
+
|
507 |
+
/**
|
508 |
+
* bp_blogs_visit_blog_button()
|
509 |
+
*
|
510 |
+
* Output button for visiting a blog in a loop
|
511 |
+
*
|
512 |
+
* @param array $args Custom button properties
|
513 |
+
*/
|
514 |
+
function bp_blogs_visit_blog_button( $args = '' ) {
|
515 |
+
echo bp_get_blogs_visit_blog_button( $args );
|
516 |
+
}
|
517 |
+
/**
|
518 |
+
* bp_get_blogs_visit_blog_button()
|
519 |
+
*
|
520 |
+
* Return button for visiting a blog in a loop
|
521 |
+
*
|
522 |
+
* @param array $args Custom button properties
|
523 |
+
* @return string
|
524 |
+
*/
|
525 |
+
function bp_get_blogs_visit_blog_button( $args = '' ) {
|
526 |
+
$defaults = array(
|
527 |
+
'id' => 'visit_blog',
|
528 |
+
'component' => 'blogs',
|
529 |
+
'must_be_logged_in' => false,
|
530 |
+
'block_self' => false,
|
531 |
+
'wrapper_class' => 'blog-button visit',
|
532 |
+
'link_href' => bp_get_blog_permalink(),
|
533 |
+
'link_class' => 'visit',
|
534 |
+
'link_text' => __( 'Visit Blog', 'buddypress' ),
|
535 |
+
'link_title' => __( 'Visit Blog', 'buddypress' ),
|
536 |
+
);
|
537 |
+
|
538 |
+
$button = wp_parse_args( $args, $defaults );
|
539 |
+
|
540 |
+
// Filter and return the HTML button
|
541 |
+
return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
|
542 |
+
}
|
543 |
+
|
544 |
+
?>
|
bp-blogs/bp-blogs-widgets.php
CHANGED
@@ -1,84 +1,84 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/***
|
4 |
-
* The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
|
5 |
-
* Why not make some of your own widgets using a filtered activity stream?
|
6 |
-
*/
|
7 |
-
|
8 |
-
function bp_blogs_register_widgets() {
|
9 |
-
global $current_blog, $bp;
|
10 |
-
|
11 |
-
if ( bp_is_active( 'activity' ) && (int)$current_blog->blog_id == BP_ROOT_BLOG )
|
12 |
-
add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
|
13 |
-
}
|
14 |
-
add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
|
15 |
-
|
16 |
-
class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
|
17 |
-
function bp_blogs_recent_posts_widget() {
|
18 |
-
parent::WP_Widget( false, $name = __( 'Recent Site Wide Posts', 'buddypress' ) );
|
19 |
-
}
|
20 |
-
|
21 |
-
function widget($args, $instance) {
|
22 |
-
global $bp;
|
23 |
-
|
24 |
-
extract( $args );
|
25 |
-
|
26 |
-
echo $before_widget;
|
27 |
-
echo $before_title . $widget_name . $after_title;
|
28 |
-
|
29 |
-
if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
|
30 |
-
$instance['max_posts'] = 10; ?>
|
31 |
-
|
32 |
-
<?php if ( bp_has_activities( 'action=new_blog_post&max=' . $instance['max_posts'] . '&per_page=' . $instance['max_posts'] ) ) : ?>
|
33 |
-
|
34 |
-
<ul id="blog-post-list" class="activity-list item-list">
|
35 |
-
|
36 |
-
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
37 |
-
|
38 |
-
<li>
|
39 |
-
<div class="activity-content" style="margin: 0">
|
40 |
-
|
41 |
-
<div class="activity-header">
|
42 |
-
<?php bp_activity_action() ?>
|
43 |
-
</div>
|
44 |
-
|
45 |
-
<?php if ( bp_get_activity_content_body() ) : ?>
|
46 |
-
<div class="activity-inner">
|
47 |
-
<?php bp_activity_content_body() ?>
|
48 |
-
</div>
|
49 |
-
<?php endif; ?>
|
50 |
-
|
51 |
-
</div>
|
52 |
-
</li>
|
53 |
-
|
54 |
-
<?php endwhile; ?>
|
55 |
-
|
56 |
-
</ul>
|
57 |
-
|
58 |
-
<?php else : ?>
|
59 |
-
<div id="message" class="info">
|
60 |
-
<p><?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?></p>
|
61 |
-
</div>
|
62 |
-
<?php endif; ?>
|
63 |
-
|
64 |
-
<?php echo $after_widget; ?>
|
65 |
-
<?php
|
66 |
-
}
|
67 |
-
|
68 |
-
function update( $new_instance, $old_instance ) {
|
69 |
-
$instance = $old_instance;
|
70 |
-
$instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
|
71 |
-
|
72 |
-
return $instance;
|
73 |
-
}
|
74 |
-
|
75 |
-
function form( $instance ) {
|
76 |
-
$instance = wp_parse_args( (array) $instance, array( 'max_posts' => 10 ) );
|
77 |
-
$max_posts = strip_tags( $instance['max_posts'] );
|
78 |
-
?>
|
79 |
-
|
80 |
-
<p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo
|
81 |
-
<?php
|
82 |
-
}
|
83 |
-
}
|
84 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/***
|
4 |
+
* The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
|
5 |
+
* Why not make some of your own widgets using a filtered activity stream?
|
6 |
+
*/
|
7 |
+
|
8 |
+
function bp_blogs_register_widgets() {
|
9 |
+
global $current_blog, $bp;
|
10 |
+
|
11 |
+
if ( bp_is_active( 'activity' ) && (int)$current_blog->blog_id == BP_ROOT_BLOG )
|
12 |
+
add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
|
13 |
+
}
|
14 |
+
add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
|
15 |
+
|
16 |
+
class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
|
17 |
+
function bp_blogs_recent_posts_widget() {
|
18 |
+
parent::WP_Widget( false, $name = __( 'Recent Site Wide Posts', 'buddypress' ) );
|
19 |
+
}
|
20 |
+
|
21 |
+
function widget($args, $instance) {
|
22 |
+
global $bp;
|
23 |
+
|
24 |
+
extract( $args );
|
25 |
+
|
26 |
+
echo $before_widget;
|
27 |
+
echo $before_title . $widget_name . $after_title;
|
28 |
+
|
29 |
+
if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
|
30 |
+
$instance['max_posts'] = 10; ?>
|
31 |
+
|
32 |
+
<?php if ( bp_has_activities( 'action=new_blog_post&max=' . $instance['max_posts'] . '&per_page=' . $instance['max_posts'] ) ) : ?>
|
33 |
+
|
34 |
+
<ul id="blog-post-list" class="activity-list item-list">
|
35 |
+
|
36 |
+
<?php while ( bp_activities() ) : bp_the_activity(); ?>
|
37 |
+
|
38 |
+
<li>
|
39 |
+
<div class="activity-content" style="margin: 0">
|
40 |
+
|
41 |
+
<div class="activity-header">
|
42 |
+
<?php bp_activity_action() ?>
|
43 |
+
</div>
|
44 |
+
|
45 |
+
<?php if ( bp_get_activity_content_body() ) : ?>
|
46 |
+
<div class="activity-inner">
|
47 |
+
<?php bp_activity_content_body() ?>
|
48 |
+
</div>
|
49 |
+
<?php endif; ?>
|
50 |
+
|
51 |
+
</div>
|
52 |
+
</li>
|
53 |
+
|
54 |
+
<?php endwhile; ?>
|
55 |
+
|
56 |
+
</ul>
|
57 |
+
|
58 |
+
<?php else : ?>
|
59 |
+
<div id="message" class="info">
|
60 |
+
<p><?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?></p>
|
61 |
+
</div>
|
62 |
+
<?php endif; ?>
|
63 |
+
|
64 |
+
<?php echo $after_widget; ?>
|
65 |
+
<?php
|
66 |
+
}
|
67 |
+
|
68 |
+
function update( $new_instance, $old_instance ) {
|
69 |
+
$instance = $old_instance;
|
70 |
+
$instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
|
71 |
+
|
72 |
+
return $instance;
|
73 |
+
}
|
74 |
+
|
75 |
+
function form( $instance ) {
|
76 |
+
$instance = wp_parse_args( (array) $instance, array( 'max_posts' => 10 ) );
|
77 |
+
$max_posts = strip_tags( $instance['max_posts'] );
|
78 |
+
?>
|
79 |
+
|
80 |
+
<p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
}
|
84 |
?>
|
bp-core.php
CHANGED
@@ -1,2144 +1,2175 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/* Define the current version number for checking if DB tables are up to date. */
|
4 |
-
define( 'BP_CORE_DB_VERSION', '1800' );
|
5 |
-
|
6 |
-
/***
|
7 |
-
* Define the path and url of the BuddyPress plugins directory.
|
8 |
-
* It is important to use plugins_url() core function to obtain
|
9 |
-
* the correct scheme used (http or https).
|
10 |
-
*/
|
11 |
-
define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' );
|
12 |
-
define( 'BP_PLUGIN_URL', plugins_url( $path = '/buddypress' ) );
|
13 |
-
|
14 |
-
/* Load the WP abstraction file so BuddyPress can run on all WordPress setups. */
|
15 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
|
16 |
-
|
17 |
-
/* Place your custom code (actions/filters) in a file called /plugins/bp-custom.php and it will be loaded before anything else. */
|
18 |
-
if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
|
19 |
-
require( WP_PLUGIN_DIR . '/bp-custom.php' );
|
20 |
-
|
21 |
-
/* Define on which blog ID BuddyPress should run */
|
22 |
-
if ( !defined( 'BP_ROOT_BLOG' ) )
|
23 |
-
define( 'BP_ROOT_BLOG', 1 );
|
24 |
-
|
25 |
-
/* Define the user and usermeta table names, useful if you are using custom or shared tables. */
|
26 |
-
if ( !defined( 'CUSTOM_USER_TABLE' ) )
|
27 |
-
define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' );
|
28 |
-
|
29 |
-
if ( !defined( 'CUSTOM_USER_META_TABLE' ) )
|
30 |
-
define( 'CUSTOM_USER_META_TABLE', $wpdb->base_prefix . 'usermeta' );
|
31 |
-
|
32 |
-
/* Load the files containing functions that we globally will need. */
|
33 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
|
34 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
|
35 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
|
36 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
|
37 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
|
38 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
|
39 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php' );
|
40 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
|
41 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
|
42 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
|
43 |
-
|
44 |
-
/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
|
45 |
-
if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
46 |
-
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
|
47 |
-
|
48 |
-
/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
|
49 |
-
if ( !defined( 'BP_MEMBERS_SLUG' ) )
|
50 |
-
define( 'BP_MEMBERS_SLUG', 'members' );
|
51 |
-
|
52 |
-
/* Define the slug for the register/signup page */
|
53 |
-
if ( !defined( 'BP_REGISTER_SLUG' ) )
|
54 |
-
define( 'BP_REGISTER_SLUG', 'register' );
|
55 |
-
|
56 |
-
/* Define the slug for the activation page */
|
57 |
-
if ( !defined( 'BP_ACTIVATION_SLUG' ) )
|
58 |
-
define( 'BP_ACTIVATION_SLUG', 'activate' );
|
59 |
-
|
60 |
-
/* Define the slug for the search page */
|
61 |
-
if ( !defined( 'BP_SEARCH_SLUG' ) )
|
62 |
-
define( 'BP_SEARCH_SLUG', 'search' );
|
63 |
-
|
64 |
-
/* Register BuddyPress themes contained within the bp-theme folder */
|
65 |
-
if ( function_exists( 'register_theme_directory') )
|
66 |
-
register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
|
67 |
-
|
68 |
-
|
69 |
-
/* "And now for something completely different" .... */
|
70 |
-
|
71 |
-
|
72 |
-
/**
|
73 |
-
* bp_core_setup_globals()
|
74 |
-
*
|
75 |
-
* Sets up default global BuddyPress configuration settings and stores
|
76 |
-
* them in a $bp variable.
|
77 |
-
*
|
78 |
-
* @package BuddyPress Core Core
|
79 |
-
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
80 |
-
* @global $current_user A WordPress global containing current user information
|
81 |
-
* @global $current_component Which is set up in /bp-core/bp-core-catch-uri.php
|
82 |
-
* @global $current_action Which is set up in /bp-core/bp-core-catch-uri.php
|
83 |
-
* @global $action_variables Which is set up in /bp-core/bp-core-catch-uri.php
|
84 |
-
* @uses bp_core_get_user_domain() Returns the domain for a user
|
85 |
-
*/
|
86 |
-
function bp_core_setup_globals() {
|
87 |
-
global $bp
|
88 |
-
global $current_user, $current_component, $current_action, $current_blog;
|
89 |
-
global $displayed_user_id;
|
90 |
-
global $action_variables;
|
91 |
-
|
92 |
-
$current_user = wp_get_current_user();
|
93 |
-
|
94 |
-
/*
|
95 |
-
$bp->
|
96 |
-
|
97 |
-
/* The
|
98 |
-
$bp->
|
99 |
-
|
100 |
-
/* The
|
101 |
-
$bp->loggedin_user->
|
102 |
-
|
103 |
-
/* The
|
104 |
-
$bp->loggedin_user->
|
105 |
-
|
106 |
-
/*
|
107 |
-
$bp->loggedin_user->
|
108 |
-
|
109 |
-
/*
|
110 |
-
$bp->
|
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 |
-
$bp->
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
$bp->
|
162 |
-
$bp->
|
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 |
-
function
|
214 |
-
global $wpdb
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
/**
|
319 |
-
*
|
320 |
-
*
|
321 |
-
*
|
322 |
-
*
|
323 |
-
*
|
324 |
-
* @
|
325 |
-
* @
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
/*
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
'
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
*
|
392 |
-
*
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
*
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
/*
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
*
|
605 |
-
*
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
*
|
626 |
-
*
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
return apply_filters( '
|
637 |
-
}
|
638 |
-
|
639 |
-
/**
|
640 |
-
*
|
641 |
-
*
|
642 |
-
*
|
643 |
-
*
|
644 |
-
*
|
645 |
-
* @
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
}
|
923 |
-
|
924 |
-
/**
|
925 |
-
*
|
926 |
-
*
|
927 |
-
*
|
928 |
-
*
|
929 |
-
*
|
930 |
-
*
|
931 |
-
*
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
*
|
946 |
-
*
|
947 |
-
*
|
948 |
-
*
|
949 |
-
*
|
950 |
-
*
|
951 |
-
*
|
952 |
-
*
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
*
|
960 |
-
*
|
961 |
-
*
|
962 |
-
*
|
963 |
-
*
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
*
|
973 |
-
*
|
974 |
-
*
|
975 |
-
*
|
976 |
-
* @
|
977 |
-
* @
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
*
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
*
|
1014 |
-
*
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
*
|
1034 |
-
*
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
$
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
$
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
}
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
*
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
*
|
1115 |
-
*
|
1116 |
-
*
|
1117 |
-
*
|
1118 |
-
*
|
1119 |
-
*
|
1120 |
-
*
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
$
|
1185 |
-
|
1186 |
-
if (
|
1187 |
-
$
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
*
|
1221 |
-
*
|
1222 |
-
*
|
1223 |
-
*
|
1224 |
-
* @
|
1225 |
-
* @
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
*
|
1238 |
-
*
|
1239 |
-
*
|
1240 |
-
*
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
*
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
*
|
1309 |
-
*
|
1310 |
-
*
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
*
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
*
|
1399 |
-
*
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
/* Step
|
1452 |
-
|
1453 |
-
$
|
1454 |
-
|
1455 |
-
|
1456 |
-
if ( ( $
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
*
|
1547 |
-
*
|
1548 |
-
*
|
1549 |
-
*
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
'
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
*
|
1651 |
-
*
|
1652 |
-
*
|
1653 |
-
*
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
*
|
1668 |
-
*
|
1669 |
-
*
|
1670 |
-
*
|
1671 |
-
* @package BuddyPress Core
|
1672 |
-
* @
|
1673 |
-
*/
|
1674 |
-
function
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
-
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
|
1783 |
-
|
1784 |
-
|
1785 |
-
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
/**
|
1802 |
-
*
|
1803 |
-
*
|
1804 |
-
*
|
1805 |
-
*
|
1806 |
-
* @package BuddyPress Core
|
1807 |
-
*/
|
1808 |
-
function
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
*
|
1820 |
-
*
|
1821 |
-
*
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
|
1834 |
-
*
|
1835 |
-
*
|
1836 |
-
*
|
1837 |
-
*
|
1838 |
-
* @package BuddyPress Core
|
1839 |
-
*/
|
1840 |
-
function
|
1841 |
-
global $
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
}
|
1848 |
-
|
1849 |
-
|
1850 |
-
/**
|
1851 |
-
*
|
1852 |
-
*
|
1853 |
-
*
|
1854 |
-
*
|
1855 |
-
* @package BuddyPress Core
|
1856 |
-
*/
|
1857 |
-
function
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
*
|
1924 |
-
*
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
|
1931 |
-
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
*
|
1944 |
-
*
|
1945 |
-
*
|
1946 |
-
|
1947 |
-
|
1948 |
-
*/
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
add_action
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
|
1967 |
-
|
1968 |
-
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
1973 |
-
|
1974 |
-
|
1975 |
-
|
1976 |
-
|
1977 |
-
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
*
|
1983 |
-
*
|
1984 |
-
*
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
1996 |
-
|
1997 |
-
|
1998 |
-
|
1999 |
-
|
2000 |
-
|
2001 |
-
|
2002 |
-
|
2003 |
-
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
}
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
-
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
|
2030 |
-
|
2031 |
-
|
2032 |
-
|
2033 |
-
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
2037 |
-
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
|
2042 |
-
|
2043 |
-
|
2044 |
-
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
|
2049 |
-
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
2055 |
-
|
2056 |
-
|
2057 |
-
|
2058 |
-
|
2059 |
-
|
2060 |
-
|
2061 |
-
|
2062 |
-
}
|
2063 |
-
|
2064 |
-
|
2065 |
-
|
2066 |
-
*
|
2067 |
-
*
|
2068 |
-
*
|
2069 |
-
*/
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
|
2107 |
-
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
2113 |
-
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
|
2118 |
-
|
2119 |
-
|
2120 |
-
|
2121 |
-
|
2122 |
-
|
2123 |
-
*
|
2124 |
-
*
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
|
2130 |
-
|
2131 |
-
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2144 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/* Define the current version number for checking if DB tables are up to date. */
|
4 |
+
define( 'BP_CORE_DB_VERSION', '1800' );
|
5 |
+
|
6 |
+
/***
|
7 |
+
* Define the path and url of the BuddyPress plugins directory.
|
8 |
+
* It is important to use plugins_url() core function to obtain
|
9 |
+
* the correct scheme used (http or https).
|
10 |
+
*/
|
11 |
+
define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' );
|
12 |
+
define( 'BP_PLUGIN_URL', plugins_url( $path = '/buddypress' ) );
|
13 |
+
|
14 |
+
/* Load the WP abstraction file so BuddyPress can run on all WordPress setups. */
|
15 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
|
16 |
+
|
17 |
+
/* Place your custom code (actions/filters) in a file called /plugins/bp-custom.php and it will be loaded before anything else. */
|
18 |
+
if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
|
19 |
+
require( WP_PLUGIN_DIR . '/bp-custom.php' );
|
20 |
+
|
21 |
+
/* Define on which blog ID BuddyPress should run */
|
22 |
+
if ( !defined( 'BP_ROOT_BLOG' ) )
|
23 |
+
define( 'BP_ROOT_BLOG', 1 );
|
24 |
+
|
25 |
+
/* Define the user and usermeta table names, useful if you are using custom or shared tables. */
|
26 |
+
if ( !defined( 'CUSTOM_USER_TABLE' ) )
|
27 |
+
define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' );
|
28 |
+
|
29 |
+
if ( !defined( 'CUSTOM_USER_META_TABLE' ) )
|
30 |
+
define( 'CUSTOM_USER_META_TABLE', $wpdb->base_prefix . 'usermeta' );
|
31 |
+
|
32 |
+
/* Load the files containing functions that we globally will need. */
|
33 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
|
34 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
|
35 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
|
36 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
|
37 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
|
38 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
|
39 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php' );
|
40 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
|
41 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
|
42 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
|
43 |
+
|
44 |
+
/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
|
45 |
+
if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
46 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
|
47 |
+
|
48 |
+
/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
|
49 |
+
if ( !defined( 'BP_MEMBERS_SLUG' ) )
|
50 |
+
define( 'BP_MEMBERS_SLUG', 'members' );
|
51 |
+
|
52 |
+
/* Define the slug for the register/signup page */
|
53 |
+
if ( !defined( 'BP_REGISTER_SLUG' ) )
|
54 |
+
define( 'BP_REGISTER_SLUG', 'register' );
|
55 |
+
|
56 |
+
/* Define the slug for the activation page */
|
57 |
+
if ( !defined( 'BP_ACTIVATION_SLUG' ) )
|
58 |
+
define( 'BP_ACTIVATION_SLUG', 'activate' );
|
59 |
+
|
60 |
+
/* Define the slug for the search page */
|
61 |
+
if ( !defined( 'BP_SEARCH_SLUG' ) )
|
62 |
+
define( 'BP_SEARCH_SLUG', 'search' );
|
63 |
+
|
64 |
+
/* Register BuddyPress themes contained within the bp-theme folder */
|
65 |
+
if ( function_exists( 'register_theme_directory') )
|
66 |
+
register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
|
67 |
+
|
68 |
+
|
69 |
+
/* "And now for something completely different" .... */
|
70 |
+
|
71 |
+
|
72 |
+
/**
|
73 |
+
* bp_core_setup_globals()
|
74 |
+
*
|
75 |
+
* Sets up default global BuddyPress configuration settings and stores
|
76 |
+
* them in a $bp variable.
|
77 |
+
*
|
78 |
+
* @package BuddyPress Core Core
|
79 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
80 |
+
* @global $current_user A WordPress global containing current user information
|
81 |
+
* @global $current_component Which is set up in /bp-core/bp-core-catch-uri.php
|
82 |
+
* @global $current_action Which is set up in /bp-core/bp-core-catch-uri.php
|
83 |
+
* @global $action_variables Which is set up in /bp-core/bp-core-catch-uri.php
|
84 |
+
* @uses bp_core_get_user_domain() Returns the domain for a user
|
85 |
+
*/
|
86 |
+
function bp_core_setup_globals() {
|
87 |
+
global $bp;
|
88 |
+
global $current_user, $current_component, $current_action, $current_blog;
|
89 |
+
global $displayed_user_id;
|
90 |
+
global $action_variables;
|
91 |
+
|
92 |
+
$current_user = wp_get_current_user();
|
93 |
+
|
94 |
+
/* Get the base database prefix */
|
95 |
+
$bp->table_prefix = bp_core_get_table_prefix();
|
96 |
+
|
97 |
+
/* The domain for the root of the site where the main blog resides */
|
98 |
+
$bp->root_domain = bp_core_get_root_domain();
|
99 |
+
|
100 |
+
/* The user ID of the user who is currently logged in. */
|
101 |
+
$bp->loggedin_user->id = $current_user->ID;
|
102 |
+
|
103 |
+
/* The domain for the user currently logged in. eg: http://domain.com/members/andy */
|
104 |
+
$bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id );
|
105 |
+
|
106 |
+
/* The core userdata of the user who is currently logged in. */
|
107 |
+
$bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );
|
108 |
+
|
109 |
+
/* is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
|
110 |
+
$bp->loggedin_user->is_super_admin = is_super_admin();
|
111 |
+
$bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6
|
112 |
+
|
113 |
+
/* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
|
114 |
+
$bp->displayed_user->id = $displayed_user_id;
|
115 |
+
|
116 |
+
/* The domain for the user currently being displayed */
|
117 |
+
$bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id );
|
118 |
+
|
119 |
+
/* The core userdata of the user who is currently being displayed */
|
120 |
+
$bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
|
121 |
+
|
122 |
+
/* The component being used eg: http://domain.com/members/andy/ [profile] */
|
123 |
+
$bp->current_component = $current_component; // type: string
|
124 |
+
|
125 |
+
/* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */
|
126 |
+
$bp->current_action = $current_action; // type: string
|
127 |
+
|
128 |
+
/* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */
|
129 |
+
$bp->action_variables = $action_variables; // type: array
|
130 |
+
|
131 |
+
/* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/
|
132 |
+
$bp->current_item = ''; // type: string
|
133 |
+
|
134 |
+
/* Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group) */
|
135 |
+
$bp->is_single_item = false;
|
136 |
+
|
137 |
+
/* The default component to use if none are set and someone visits: http://domain.com/members/andy */
|
138 |
+
if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
|
139 |
+
if ( defined( 'BP_ACTIVITY_SLUG' ) )
|
140 |
+
$bp->default_component = BP_ACTIVITY_SLUG;
|
141 |
+
else
|
142 |
+
$bp->default_component = 'profile';
|
143 |
+
} else {
|
144 |
+
$bp->default_component = BP_DEFAULT_COMPONENT;
|
145 |
+
}
|
146 |
+
|
147 |
+
/* Fetches all of the core database based BuddyPress settings in one foul swoop */
|
148 |
+
$bp->site_options = bp_core_get_site_options();
|
149 |
+
|
150 |
+
/* Sets up the array container for the component navigation rendered by bp_get_nav() */
|
151 |
+
$bp->bp_nav = array();
|
152 |
+
|
153 |
+
/* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
|
154 |
+
$bp->bp_options_nav = array();
|
155 |
+
|
156 |
+
/* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
|
157 |
+
$bp->active_components = array();
|
158 |
+
|
159 |
+
/* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
|
160 |
+
$bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
|
161 |
+
$bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
|
162 |
+
$bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
|
163 |
+
|
164 |
+
/* Fetch the full name for the logged in and current user */
|
165 |
+
$bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
|
166 |
+
$bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
|
167 |
+
|
168 |
+
/* Used to determine if user has admin rights on current content. If the logged in user is viewing
|
169 |
+
their own profile and wants to delete something, is_item_admin is used. This is a
|
170 |
+
generic variable so it can be used by other components. It can also be modified, so when viewing a group
|
171 |
+
'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
|
172 |
+
$bp->is_item_admin = bp_user_has_access();
|
173 |
+
|
174 |
+
/* Used to determine if the logged in user is a moderator for the current content. */
|
175 |
+
$bp->is_item_mod = false;
|
176 |
+
|
177 |
+
$bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
|
178 |
+
|
179 |
+
if ( !$bp->current_component && $bp->displayed_user->id )
|
180 |
+
$bp->current_component = $bp->default_component;
|
181 |
+
|
182 |
+
do_action( 'bp_core_setup_globals' );
|
183 |
+
}
|
184 |
+
add_action( 'bp_setup_globals', 'bp_core_setup_globals' );
|
185 |
+
|
186 |
+
/**
|
187 |
+
* bp_core_setup_root_uris()
|
188 |
+
*
|
189 |
+
* Adds the core URIs that should run in the root of the installation.
|
190 |
+
*
|
191 |
+
* For example: http://example.org/search/ or http://example.org/members/
|
192 |
+
*
|
193 |
+
* @package BuddyPress Core
|
194 |
+
* @uses bp_core_add_root_component() Adds a slug to the root components global variable.
|
195 |
+
*/
|
196 |
+
function bp_core_setup_root_uris() {
|
197 |
+
// Add core root components
|
198 |
+
bp_core_add_root_component( BP_MEMBERS_SLUG );
|
199 |
+
bp_core_add_root_component( BP_REGISTER_SLUG );
|
200 |
+
bp_core_add_root_component( BP_ACTIVATION_SLUG );
|
201 |
+
bp_core_add_root_component( BP_SEARCH_SLUG );
|
202 |
+
}
|
203 |
+
add_action( 'bp_setup_root_components', 'bp_core_setup_root_uris' );
|
204 |
+
|
205 |
+
/**
|
206 |
+
* bp_core_get_table_prefix()
|
207 |
+
*
|
208 |
+
* Allow filtering of database prefix. Intended for use in multinetwork installations.
|
209 |
+
*
|
210 |
+
* @global object $wpdb WordPress database object
|
211 |
+
* @return string Filtered database prefix
|
212 |
+
*/
|
213 |
+
function bp_core_get_table_prefix() {
|
214 |
+
global $wpdb;
|
215 |
+
|
216 |
+
return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* bp_core_install()
|
221 |
+
*
|
222 |
+
* Installs the core DB tables for BuddyPress.
|
223 |
+
*
|
224 |
+
* @package BuddyPress Core
|
225 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
226 |
+
* @global $wpdb WordPress DB access object.
|
227 |
+
* @uses dbDelta() Performs a table creation, or upgrade based on what already exists in the DB.
|
228 |
+
* @uses bp_core_add_illegal_names() Adds illegal blog names to the WP settings
|
229 |
+
*/
|
230 |
+
function bp_core_install() {
|
231 |
+
global $wpdb, $bp;
|
232 |
+
|
233 |
+
if ( !empty($wpdb->charset) )
|
234 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
235 |
+
|
236 |
+
$sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (
|
237 |
+
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
238 |
+
user_id bigint(20) NOT NULL,
|
239 |
+
item_id bigint(20) NOT NULL,
|
240 |
+
secondary_item_id bigint(20),
|
241 |
+
component_name varchar(75) NOT NULL,
|
242 |
+
component_action varchar(75) NOT NULL,
|
243 |
+
date_notified datetime NOT NULL,
|
244 |
+
is_new bool NOT NULL DEFAULT 0,
|
245 |
+
KEY item_id (item_id),
|
246 |
+
KEY secondary_item_id (secondary_item_id),
|
247 |
+
KEY user_id (user_id),
|
248 |
+
KEY is_new (is_new),
|
249 |
+
KEY component_name (component_name),
|
250 |
+
KEY component_action (component_action),
|
251 |
+
KEY useritem (user_id,is_new)
|
252 |
+
) {$charset_collate};";
|
253 |
+
|
254 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
255 |
+
dbDelta( $sql );
|
256 |
+
|
257 |
+
/* Add names of root components to the banned blog list to avoid conflicts */
|
258 |
+
if ( bp_core_is_multisite() )
|
259 |
+
bp_core_add_illegal_names();
|
260 |
+
|
261 |
+
update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* bp_core_check_installed()
|
266 |
+
*
|
267 |
+
* Checks to make sure the database tables are set up for the core component.
|
268 |
+
*
|
269 |
+
* @package BuddyPress Core
|
270 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
271 |
+
* @global $current_user WordPress global variable containing current logged in user information
|
272 |
+
* @uses is_super_admin() returns true if the current user is a site admin, false if not
|
273 |
+
* @uses get_site_option() fetches the value for a meta_key in the wp_sitemeta table
|
274 |
+
* @uses bp_core_install() runs the installation of DB tables for the core component
|
275 |
+
*/
|
276 |
+
function bp_core_check_installed() {
|
277 |
+
global $bp;
|
278 |
+
|
279 |
+
if ( !is_super_admin() )
|
280 |
+
return false;
|
281 |
+
|
282 |
+
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' );
|
283 |
+
|
284 |
+
/* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
|
285 |
+
if ( get_site_option( 'bp-core-db-version' ) < BP_CORE_DB_VERSION )
|
286 |
+
bp_core_install();
|
287 |
+
}
|
288 |
+
add_action( 'admin_menu', 'bp_core_check_installed' );
|
289 |
+
|
290 |
+
/**
|
291 |
+
* bp_core_add_admin_menu()
|
292 |
+
*
|
293 |
+
* Adds the "BuddyPress" admin submenu item to the Site Admin tab.
|
294 |
+
*
|
295 |
+
* @package BuddyPress Core
|
296 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
297 |
+
* @uses is_super_admin() returns true if the current user is a site admin, false if not
|
298 |
+
* @uses add_submenu_page() WP function to add a submenu item
|
299 |
+
*/
|
300 |
+
function bp_core_add_admin_menu() {
|
301 |
+
if ( !is_super_admin() )
|
302 |
+
return false;
|
303 |
+
|
304 |
+
/* Add the administration tab under the "Site Admin" tab for site administrators */
|
305 |
+
bp_core_add_admin_menu_page( array(
|
306 |
+
'menu_title' => __( 'BuddyPress', 'buddypress' ),
|
307 |
+
'page_title' => __( 'BuddyPress', 'buddypress' ),
|
308 |
+
'access_level' => 10, 'file' => 'bp-general-settings',
|
309 |
+
'function' => 'bp_core_admin_settings',
|
310 |
+
'position' => 2
|
311 |
+
) );
|
312 |
+
|
313 |
+
add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
|
314 |
+
add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
|
315 |
+
}
|
316 |
+
add_action( 'admin_menu', 'bp_core_add_admin_menu' );
|
317 |
+
|
318 |
+
/**
|
319 |
+
* bp_core_is_root_component()
|
320 |
+
*
|
321 |
+
* Checks to see if a component's URL should be in the root, not under a member page:
|
322 |
+
* eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
|
323 |
+
*
|
324 |
+
* @package BuddyPress Core
|
325 |
+
* @return true if root component, else false.
|
326 |
+
*/
|
327 |
+
function bp_core_is_root_component( $component_name ) {
|
328 |
+
global $bp;
|
329 |
+
|
330 |
+
return in_array( $component_name, $bp->root_components );
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* bp_core_setup_nav()
|
335 |
+
*
|
336 |
+
* Sets up the profile navigation item if the Xprofile component is not installed.
|
337 |
+
*
|
338 |
+
* @package BuddyPress Core
|
339 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
340 |
+
* @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation
|
341 |
+
* @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item
|
342 |
+
* @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user
|
343 |
+
* @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
|
344 |
+
*/
|
345 |
+
function bp_core_setup_nav() {
|
346 |
+
global $bp;
|
347 |
+
|
348 |
+
/***
|
349 |
+
* If the extended profiles component is disabled, we need to revert to using the
|
350 |
+
* built in WordPress profile information
|
351 |
+
*/
|
352 |
+
if ( !function_exists( 'xprofile_install' ) ) {
|
353 |
+
/* Fallback values if xprofile is disabled */
|
354 |
+
$bp->core->profile->slug = 'profile';
|
355 |
+
$bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
|
356 |
+
|
357 |
+
/* Add 'Profile' to the main navigation */
|
358 |
+
bp_core_new_nav_item( array(
|
359 |
+
'name' => __('Profile', 'buddypress'),
|
360 |
+
'slug' => $bp->core->profile->slug,
|
361 |
+
'position' => 20,
|
362 |
+
'screen_function' => 'bp_core_catch_profile_uri',
|
363 |
+
'default_subnav_slug' => 'public'
|
364 |
+
) );
|
365 |
+
|
366 |
+
$profile_link = $bp->loggedin_user->domain . '/profile/';
|
367 |
+
|
368 |
+
/* Add the subnav items to the profile */
|
369 |
+
bp_core_new_subnav_item( array(
|
370 |
+
'name' => __( 'Public', 'buddypress' ),
|
371 |
+
'slug' => 'public',
|
372 |
+
'parent_url' => $profile_link,
|
373 |
+
'parent_slug' => $bp->core->profile->slug,
|
374 |
+
'screen_function' => 'bp_core_catch_profile_uri'
|
375 |
+
) );
|
376 |
+
|
377 |
+
|
378 |
+
if ( 'profile' == $bp->current_component ) {
|
379 |
+
if ( bp_is_my_profile() ) {
|
380 |
+
$bp->bp_options_title = __('My Profile', 'buddypress');
|
381 |
+
} else {
|
382 |
+
$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
|
383 |
+
$bp->bp_options_title = $bp->displayed_user->fullname;
|
384 |
+
}
|
385 |
+
}
|
386 |
+
}
|
387 |
+
}
|
388 |
+
add_action( 'bp_setup_nav', 'bp_core_setup_nav' );
|
389 |
+
|
390 |
+
/********************************************************************************
|
391 |
+
* Action Functions
|
392 |
+
*
|
393 |
+
* Action functions are exactly the same as screen functions, however they do not
|
394 |
+
* have a template screen associated with them. Usually they will send the user
|
395 |
+
* back to the default screen after execution.
|
396 |
+
*/
|
397 |
+
|
398 |
+
/**
|
399 |
+
* bp_core_action_directory_members()
|
400 |
+
*
|
401 |
+
* Listens to the $bp component and action variables to determine if the user is viewing the members
|
402 |
+
* directory page. If they are, it will set up the directory and load the members directory template.
|
403 |
+
*
|
404 |
+
* @package BuddyPress Core
|
405 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
406 |
+
* @uses wp_enqueue_script() Loads a JS script into the header of the page.
|
407 |
+
* @uses bp_core_load_template() Loads a specific template file.
|
408 |
+
*/
|
409 |
+
function bp_core_action_directory_members() {
|
410 |
+
global $bp;
|
411 |
+
|
412 |
+
if ( is_null( $bp->displayed_user->id ) && $bp->current_component == BP_MEMBERS_SLUG ) {
|
413 |
+
$bp->is_directory = true;
|
414 |
+
|
415 |
+
do_action( 'bp_core_action_directory_members' );
|
416 |
+
bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );
|
417 |
+
}
|
418 |
+
}
|
419 |
+
add_action( 'wp', 'bp_core_action_directory_members', 2 );
|
420 |
+
|
421 |
+
/**
|
422 |
+
* bp_core_action_set_spammer_status()
|
423 |
+
*
|
424 |
+
* When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
|
425 |
+
* this action will fire and mark or unmark the user and their blogs as spam.
|
426 |
+
* Must be a site admin for this function to run.
|
427 |
+
*
|
428 |
+
* @package BuddyPress Core
|
429 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
430 |
+
*/
|
431 |
+
function bp_core_action_set_spammer_status() {
|
432 |
+
global $bp, $wpdb, $wp_version;
|
433 |
+
|
434 |
+
if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
|
435 |
+
return false;
|
436 |
+
|
437 |
+
if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
|
438 |
+
/* Check the nonce */
|
439 |
+
check_admin_referer( 'mark-unmark-spammer' );
|
440 |
+
|
441 |
+
/* Get the functions file */
|
442 |
+
if ( bp_core_is_multisite() ) {
|
443 |
+
if ( $wp_version >= '3.0' )
|
444 |
+
require_once( ABSPATH . '/wp-admin/includes/ms.php' );
|
445 |
+
else
|
446 |
+
require_once( ABSPATH . '/wp-admin/includes/mu.php' );
|
447 |
+
}
|
448 |
+
|
449 |
+
if ( 'mark-spammer' == $bp->current_action )
|
450 |
+
$is_spam = 1;
|
451 |
+
else
|
452 |
+
$is_spam = 0;
|
453 |
+
|
454 |
+
/* Get the blogs for the user */
|
455 |
+
$blogs = get_blogs_of_user( $bp->displayed_user->id, true );
|
456 |
+
|
457 |
+
foreach ( (array) $blogs as $key => $details ) {
|
458 |
+
/* Do not mark the main or current root blog as spam */
|
459 |
+
if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
|
460 |
+
continue;
|
461 |
+
|
462 |
+
/* Update the blog status */
|
463 |
+
update_blog_status( $details->userblog_id, 'spam', $is_spam );
|
464 |
+
|
465 |
+
/* Fire the standard WPMU hook */
|
466 |
+
do_action( 'make_spam_blog', $details->userblog_id );
|
467 |
+
}
|
468 |
+
|
469 |
+
/* Finally, mark this user as a spammer */
|
470 |
+
if ( bp_core_is_multisite() )
|
471 |
+
$wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
|
472 |
+
|
473 |
+
$wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
|
474 |
+
|
475 |
+
if ( $is_spam )
|
476 |
+
bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
|
477 |
+
else
|
478 |
+
bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
|
479 |
+
|
480 |
+
/* Hide this user's activity */
|
481 |
+
if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
|
482 |
+
bp_activity_hide_user_activity( $bp->displayed_user->id );
|
483 |
+
|
484 |
+
do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );
|
485 |
+
|
486 |
+
bp_core_redirect( wp_get_referer() );
|
487 |
+
}
|
488 |
+
}
|
489 |
+
add_action( 'wp', 'bp_core_action_set_spammer_status', 3 );
|
490 |
+
|
491 |
+
/**
|
492 |
+
* bp_core_action_delete_user()
|
493 |
+
*
|
494 |
+
* Allows a site admin to delete a user from the adminbar menu.
|
495 |
+
*
|
496 |
+
* @package BuddyPress Core
|
497 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
498 |
+
*/
|
499 |
+
function bp_core_action_delete_user() {
|
500 |
+
global $bp;
|
501 |
+
|
502 |
+
if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
|
503 |
+
return false;
|
504 |
+
|
505 |
+
if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
|
506 |
+
/* Check the nonce */
|
507 |
+
check_admin_referer( 'delete-user' );
|
508 |
+
|
509 |
+
$errors = false;
|
510 |
+
|
511 |
+
if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
|
512 |
+
bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );
|
513 |
+
} else {
|
514 |
+
bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' );
|
515 |
+
$errors = true;
|
516 |
+
}
|
517 |
+
|
518 |
+
do_action( 'bp_core_action_delete_user', $errors );
|
519 |
+
|
520 |
+
if ( $errors )
|
521 |
+
bp_core_redirect( $bp->displayed_user->domain );
|
522 |
+
else
|
523 |
+
bp_core_redirect( $bp->loggedin_user->domain );
|
524 |
+
}
|
525 |
+
}
|
526 |
+
add_action( 'wp', 'bp_core_action_delete_user', 3 );
|
527 |
+
|
528 |
+
|
529 |
+
/********************************************************************************
|
530 |
+
* Business Functions
|
531 |
+
*
|
532 |
+
* Business functions are where all the magic happens in BuddyPress. They will
|
533 |
+
* handle the actual saving or manipulation of information. Usually they will
|
534 |
+
* hand off to a database class for data access, then return
|
535 |
+
* true or false on success or failure.
|
536 |
+
*/
|
537 |
+
|
538 |
+
/**
|
539 |
+
* bp_core_get_users()
|
540 |
+
*
|
541 |
+
* Return an array of users IDs based on the parameters passed.
|
542 |
+
*
|
543 |
+
* @package BuddyPress Core
|
544 |
+
*/
|
545 |
+
function bp_core_get_users( $args = '' ) {
|
546 |
+
global $bp;
|
547 |
+
|
548 |
+
$defaults = array(
|
549 |
+
'type' => 'active', // active, newest, alphabetical, random or popular
|
550 |
+
'user_id' => false, // Pass a user_id to limit to only friend connections for this user
|
551 |
+
'search_terms' => false, // Limit to users that match these search terms
|
552 |
+
|
553 |
+
'include' => false, // Pass comma separated list of user_ids to limit to only these users
|
554 |
+
'per_page' => 20, // The number of results to return per page
|
555 |
+
'page' => 1, // The page to return if limiting per page
|
556 |
+
'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update
|
557 |
+
);
|
558 |
+
|
559 |
+
$params = wp_parse_args( $args, $defaults );
|
560 |
+
extract( $params, EXTR_SKIP );
|
561 |
+
|
562 |
+
return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* bp_core_get_user_domain()
|
567 |
+
*
|
568 |
+
* Returns the domain for the passed user:
|
569 |
+
* e.g. http://domain.com/members/andy/
|
570 |
+
*
|
571 |
+
* @package BuddyPress Core
|
572 |
+
* @global $current_user WordPress global variable containing current logged in user information
|
573 |
+
* @param user_id The ID of the user.
|
574 |
+
* @uses get_user_meta() WordPress function to get the usermeta for a user.
|
575 |
+
*/
|
576 |
+
function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
|
577 |
+
global $bp;
|
578 |
+
|
579 |
+
if ( !$user_id ) return;
|
580 |
+
|
581 |
+
if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
|
582 |
+
$username = bp_core_get_username( $user_id, $user_nicename, $user_login );
|
583 |
+
|
584 |
+
/* If we are using a members slug, include it. */
|
585 |
+
if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
|
586 |
+
$domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
|
587 |
+
else
|
588 |
+
$domain = $bp->root_domain . '/' . $username . '/';
|
589 |
+
|
590 |
+
/* Cache the link */
|
591 |
+
if ( !empty( $domain ) )
|
592 |
+
wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
|
593 |
+
}
|
594 |
+
|
595 |
+
return apply_filters( 'bp_core_get_user_domain', $domain );
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* bp_core_get_core_userdata()
|
600 |
+
*
|
601 |
+
* Fetch everything in the wp_users table for a user, without any usermeta.
|
602 |
+
*
|
603 |
+
* @package BuddyPress Core
|
604 |
+
* @param user_id The ID of the user.
|
605 |
+
* @uses BP_Core_User::get_core_userdata() Performs the query.
|
606 |
+
*/
|
607 |
+
function bp_core_get_core_userdata( $user_id ) {
|
608 |
+
if ( empty( $user_id ) )
|
609 |
+
return false;
|
610 |
+
|
611 |
+
if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
|
612 |
+
$userdata = BP_Core_User::get_core_userdata( $user_id );
|
613 |
+
wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
|
614 |
+
}
|
615 |
+
return apply_filters( 'bp_core_get_core_userdata', $userdata );
|
616 |
+
}
|
617 |
+
|
618 |
+
/**
|
619 |
+
* bp_core_get_root_domain()
|
620 |
+
*
|
621 |
+
* Returns the domain for the root blog.
|
622 |
+
* eg: http://domain.com/ OR https://domain.com
|
623 |
+
*
|
624 |
+
* @package BuddyPress Core
|
625 |
+
* @uses get_blog_option() WordPress function to fetch blog meta.
|
626 |
+
* @return $domain The domain URL for the blog.
|
627 |
+
*/
|
628 |
+
function bp_core_get_root_domain() {
|
629 |
+
global $current_blog;
|
630 |
+
|
631 |
+
if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
|
632 |
+
$domain = get_blog_option( $current_blog->blog_id, 'home' );
|
633 |
+
else
|
634 |
+
$domain = get_blog_option( BP_ROOT_BLOG, 'home' );
|
635 |
+
|
636 |
+
return apply_filters( 'bp_core_get_root_domain', $domain );
|
637 |
+
}
|
638 |
+
|
639 |
+
/**
|
640 |
+
* bp_core_get_displayed_userid()
|
641 |
+
*
|
642 |
+
* Returns the user id for the user that is currently being displayed.
|
643 |
+
* eg: http://andy.domain.com/ or http://domain.com/andy/
|
644 |
+
*
|
645 |
+
* @package BuddyPress Core
|
646 |
+
* @global $current_blog WordPress global containing information and settings for the current blog being viewed.
|
647 |
+
* @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed
|
648 |
+
* @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog.
|
649 |
+
*/
|
650 |
+
function bp_core_get_displayed_userid( $user_login ) {
|
651 |
+
return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) );
|
652 |
+
}
|
653 |
+
|
654 |
+
/**
|
655 |
+
* bp_core_new_nav_item()
|
656 |
+
*
|
657 |
+
* Adds a navigation item to the main navigation array used in BuddyPress themes.
|
658 |
+
*
|
659 |
+
* @package BuddyPress Core
|
660 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
661 |
+
*/
|
662 |
+
function bp_core_new_nav_item( $args = '' ) {
|
663 |
+
global $bp;
|
664 |
+
|
665 |
+
$defaults = array(
|
666 |
+
'name' => false, // Display name for the nav item
|
667 |
+
'slug' => false, // URL slug for the nav item
|
668 |
+
'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
|
669 |
+
'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
|
670 |
+
'site_admin_only' => false, // Can only site admins see this nav item?
|
671 |
+
'position' => 99, // Index of where this nav item should be positioned
|
672 |
+
'screen_function' => false, // The name of the function to run when clicked
|
673 |
+
'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
|
674 |
+
);
|
675 |
+
|
676 |
+
$r = wp_parse_args( $args, $defaults );
|
677 |
+
extract( $r, EXTR_SKIP );
|
678 |
+
|
679 |
+
/* If we don't have the required info we need, don't create this subnav item */
|
680 |
+
if ( empty($name) || empty($slug) )
|
681 |
+
return false;
|
682 |
+
|
683 |
+
/* If this is for site admins only and the user is not one, don't create the subnav item */
|
684 |
+
if ( $site_admin_only && !is_super_admin() )
|
685 |
+
return false;
|
686 |
+
|
687 |
+
if ( empty( $item_css_id ) )
|
688 |
+
$item_css_id = $slug;
|
689 |
+
|
690 |
+
$bp->bp_nav[$slug] = array(
|
691 |
+
'name' => $name,
|
692 |
+
'slug' => $slug,
|
693 |
+
'link' => $bp->loggedin_user->domain . $slug . '/',
|
694 |
+
'css_id' => $item_css_id,
|
695 |
+
'show_for_displayed_user' => $show_for_displayed_user,
|
696 |
+
'position' => $position
|
697 |
+
);
|
698 |
+
|
699 |
+
/***
|
700 |
+
* If this nav item is hidden for the displayed user, and
|
701 |
+
* the logged in user is not the displayed user
|
702 |
+
* looking at their own profile, don't create the nav item.
|
703 |
+
*/
|
704 |
+
if ( !$show_for_displayed_user && !bp_user_has_access() )
|
705 |
+
return false;
|
706 |
+
|
707 |
+
/***
|
708 |
+
* If we are not viewing a user, and this is a root component, don't attach the
|
709 |
+
* default subnav function so we can display a directory or something else.
|
710 |
+
*/
|
711 |
+
if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
|
712 |
+
return;
|
713 |
+
|
714 |
+
if ( $bp->current_component == $slug && !$bp->current_action ) {
|
715 |
+
if ( !is_object( $screen_function[0] ) )
|
716 |
+
add_action( 'wp', $screen_function, 3 );
|
717 |
+
else
|
718 |
+
add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
|
719 |
+
|
720 |
+
if ( $default_subnav_slug )
|
721 |
+
$bp->current_action = $default_subnav_slug;
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
/**
|
726 |
+
* bp_core_new_nav_default()
|
727 |
+
*
|
728 |
+
* Modify the default subnav item to load when a top level nav item is clicked.
|
729 |
+
*
|
730 |
+
* @package BuddyPress Core
|
731 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
732 |
+
*/
|
733 |
+
function bp_core_new_nav_default( $args = '' ) {
|
734 |
+
global $bp;
|
735 |
+
|
736 |
+
$defaults = array(
|
737 |
+
'parent_slug' => false, // Slug of the parent
|
738 |
+
'screen_function' => false, // The name of the function to run when clicked
|
739 |
+
'subnav_slug' => false // The slug of the subnav item to select when clicked
|
740 |
+
);
|
741 |
+
|
742 |
+
$r = wp_parse_args( $args, $defaults );
|
743 |
+
extract( $r, EXTR_SKIP );
|
744 |
+
|
745 |
+
if ( $bp->current_component == $parent_slug && !$bp->current_action ) {
|
746 |
+
if ( !is_object( $screen_function[0] ) )
|
747 |
+
add_action( 'wp', $screen_function, 3 );
|
748 |
+
else
|
749 |
+
add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
|
750 |
+
|
751 |
+
if ( $subnav_slug )
|
752 |
+
$bp->current_action = $subnav_slug;
|
753 |
+
}
|
754 |
+
}
|
755 |
+
|
756 |
+
/**
|
757 |
+
* bp_core_sort_nav_items()
|
758 |
+
*
|
759 |
+
* We can only sort nav items by their position integer at a later point in time, once all
|
760 |
+
* plugins have registered their navigation items.
|
761 |
+
*
|
762 |
+
* @package BuddyPress Core
|
763 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
764 |
+
*/
|
765 |
+
function bp_core_sort_nav_items() {
|
766 |
+
global $bp;
|
767 |
+
|
768 |
+
if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
|
769 |
+
return false;
|
770 |
+
|
771 |
+
foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {
|
772 |
+
if ( empty( $temp[$nav_item['position']]) )
|
773 |
+
$temp[$nav_item['position']] = $nav_item;
|
774 |
+
else {
|
775 |
+
// increase numbers here to fit new items in.
|
776 |
+
do {
|
777 |
+
$nav_item['position']++;
|
778 |
+
} while ( !empty( $temp[$nav_item['position']] ) );
|
779 |
+
|
780 |
+
$temp[$nav_item['position']] = $nav_item;
|
781 |
+
}
|
782 |
+
}
|
783 |
+
|
784 |
+
ksort( $temp );
|
785 |
+
$bp->bp_nav = &$temp;
|
786 |
+
}
|
787 |
+
add_action( 'wp_head', 'bp_core_sort_nav_items' );
|
788 |
+
add_action( 'admin_head', 'bp_core_sort_nav_items' );
|
789 |
+
|
790 |
+
/**
|
791 |
+
* bp_core_new_subnav_item()
|
792 |
+
*
|
793 |
+
* Adds a navigation item to the sub navigation array used in BuddyPress themes.
|
794 |
+
*
|
795 |
+
* @package BuddyPress Core
|
796 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
797 |
+
*/
|
798 |
+
function bp_core_new_subnav_item( $args = '' ) {
|
799 |
+
global $bp;
|
800 |
+
|
801 |
+
$defaults = array(
|
802 |
+
'name' => false, // Display name for the nav item
|
803 |
+
'slug' => false, // URL slug for the nav item
|
804 |
+
'parent_slug' => false, // URL slug of the parent nav item
|
805 |
+
'parent_url' => false, // URL of the parent item
|
806 |
+
'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
|
807 |
+
'user_has_access' => true, // Can the logged in user see this nav item?
|
808 |
+
'site_admin_only' => false, // Can only site admins see this nav item?
|
809 |
+
'position' => 90, // Index of where this nav item should be positioned
|
810 |
+
'screen_function' => false // The name of the function to run when clicked
|
811 |
+
);
|
812 |
+
|
813 |
+
$r = wp_parse_args( $args, $defaults );
|
814 |
+
extract( $r, EXTR_SKIP );
|
815 |
+
|
816 |
+
/* If we don't have the required info we need, don't create this subnav item */
|
817 |
+
if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
|
818 |
+
return false;
|
819 |
+
|
820 |
+
/* If this is for site admins only and the user is not one, don't create the subnav item */
|
821 |
+
if ( $site_admin_only && !is_super_admin() )
|
822 |
+
return false;
|
823 |
+
|
824 |
+
if ( empty( $item_css_id ) )
|
825 |
+
$item_css_id = $slug;
|
826 |
+
|
827 |
+
$bp->bp_options_nav[$parent_slug][$slug] = array(
|
828 |
+
'name' => $name,
|
829 |
+
'link' => $parent_url . $slug . '/',
|
830 |
+
'slug' => $slug,
|
831 |
+
'css_id' => $item_css_id,
|
832 |
+
'position' => $position,
|
833 |
+
'user_has_access' => $user_has_access,
|
834 |
+
'screen_function' => $screen_function
|
835 |
+
);
|
836 |
+
|
837 |
+
if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
|
838 |
+
if ( !is_object( $screen_function[0] ) )
|
839 |
+
add_action( 'wp', $screen_function, 3 );
|
840 |
+
else
|
841 |
+
add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
|
842 |
+
}
|
843 |
+
}
|
844 |
+
|
845 |
+
function bp_core_sort_subnav_items() {
|
846 |
+
global $bp;
|
847 |
+
|
848 |
+
if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
|
849 |
+
return false;
|
850 |
+
|
851 |
+
foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {
|
852 |
+
if ( !is_array( $subnav_items ) )
|
853 |
+
continue;
|
854 |
+
|
855 |
+
foreach ( (array)$subnav_items as $subnav_item ) {
|
856 |
+
if ( empty( $temp[$subnav_item['position']]) )
|
857 |
+
$temp[$subnav_item['position']] = $subnav_item;
|
858 |
+
else {
|
859 |
+
// increase numbers here to fit new items in.
|
860 |
+
do {
|
861 |
+
$subnav_item['position']++;
|
862 |
+
} while ( !empty( $temp[$subnav_item['position']] ) );
|
863 |
+
|
864 |
+
$temp[$subnav_item['position']] = $subnav_item;
|
865 |
+
}
|
866 |
+
}
|
867 |
+
ksort( $temp );
|
868 |
+
$bp->bp_options_nav[$parent_slug] = &$temp;
|
869 |
+
unset($temp);
|
870 |
+
}
|
871 |
+
}
|
872 |
+
add_action( 'wp_head', 'bp_core_sort_subnav_items' );
|
873 |
+
add_action( 'admin_head', 'bp_core_sort_subnav_items' );
|
874 |
+
|
875 |
+
/**
|
876 |
+
* bp_core_remove_nav_item()
|
877 |
+
*
|
878 |
+
* Removes a navigation item from the sub navigation array used in BuddyPress themes.
|
879 |
+
*
|
880 |
+
* @package BuddyPress Core
|
881 |
+
* @param $parent_id The id of the parent navigation item.
|
882 |
+
* @param $slug The slug of the sub navigation item.
|
883 |
+
*/
|
884 |
+
function bp_core_remove_nav_item( $parent_id ) {
|
885 |
+
global $bp;
|
886 |
+
|
887 |
+
/* Unset subnav items for this nav item */
|
888 |
+
if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {
|
889 |
+
foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
|
890 |
+
bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
|
891 |
+
}
|
892 |
+
}
|
893 |
+
|
894 |
+
unset( $bp->bp_nav[$parent_id] );
|
895 |
+
}
|
896 |
+
|
897 |
+
/**
|
898 |
+
* bp_core_remove_subnav_item()
|
899 |
+
*
|
900 |
+
* Removes a navigation item from the sub navigation array used in BuddyPress themes.
|
901 |
+
*
|
902 |
+
* @package BuddyPress Core
|
903 |
+
* @param $parent_id The id of the parent navigation item.
|
904 |
+
* @param $slug The slug of the sub navigation item.
|
905 |
+
*/
|
906 |
+
function bp_core_remove_subnav_item( $parent_id, $slug ) {
|
907 |
+
global $bp;
|
908 |
+
|
909 |
+
$screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
|
910 |
+
|
911 |
+
if ( $screen_function ) {
|
912 |
+
if ( !is_object( $screen_function[0] ) )
|
913 |
+
remove_action( 'wp', $screen_function, 3 );
|
914 |
+
else
|
915 |
+
remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
|
916 |
+
}
|
917 |
+
|
918 |
+
unset( $bp->bp_options_nav[$parent_id][$slug] );
|
919 |
+
|
920 |
+
if ( !count( $bp->bp_options_nav[$parent_id] ) )
|
921 |
+
unset($bp->bp_options_nav[$parent_id]);
|
922 |
+
}
|
923 |
+
|
924 |
+
/**
|
925 |
+
* bp_core_reset_subnav_items()
|
926 |
+
*
|
927 |
+
* Clear the subnav items for a specific nav item.
|
928 |
+
*
|
929 |
+
* @package BuddyPress Core
|
930 |
+
* @param $parent_id The id of the parent navigation item.
|
931 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
932 |
+
*/
|
933 |
+
function bp_core_reset_subnav_items($parent_slug) {
|
934 |
+
global $bp;
|
935 |
+
|
936 |
+
unset($bp->bp_options_nav[$parent_slug]);
|
937 |
+
}
|
938 |
+
|
939 |
+
/**
|
940 |
+
* bp_core_load_template()
|
941 |
+
*
|
942 |
+
* Uses the bp_catch_uri function to load a specific template file with fallback support.
|
943 |
+
*
|
944 |
+
* Example:
|
945 |
+
* bp_core_load_template( 'profile/edit-profile' );
|
946 |
+
* Loads:
|
947 |
+
* wp-content/themes/[activated_theme]/profile/edit-profile.php
|
948 |
+
*
|
949 |
+
* @package BuddyPress Core
|
950 |
+
* @param $username str Username to check.
|
951 |
+
* @return false on no match
|
952 |
+
* @return int the user ID of the matched user.
|
953 |
+
*/
|
954 |
+
function bp_core_load_template( $template, $skip_blog_check = false ) {
|
955 |
+
return bp_catch_uri( $template, $skip_blog_check );
|
956 |
+
}
|
957 |
+
|
958 |
+
/**
|
959 |
+
* bp_core_add_root_component()
|
960 |
+
*
|
961 |
+
* Adds a component to the $bp->root_components global.
|
962 |
+
* Any component that runs in the "root" of an install should be added.
|
963 |
+
* The "root" as in, it can or always runs outside of the /members/username/ path.
|
964 |
+
*
|
965 |
+
* Example of a root component:
|
966 |
+
* Groups: http://domain.com/groups/group-name
|
967 |
+
* http://community.domain.com/groups/group-name
|
968 |
+
* http://domain.com/wpmu/groups/group-name
|
969 |
+
*
|
970 |
+
* Example of a component that is NOT a root component:
|
971 |
+
* Friends: http://domain.com/members/andy/friends
|
972 |
+
* http://community.domain.com/members/andy/friends
|
973 |
+
* http://domain.com/wpmu/members/andy/friends
|
974 |
+
*
|
975 |
+
* @package BuddyPress Core
|
976 |
+
* @param $slug str The slug of the component
|
977 |
+
* @global $bp BuddyPress global settings
|
978 |
+
*/
|
979 |
+
function bp_core_add_root_component( $slug ) {
|
980 |
+
global $bp;
|
981 |
+
|
982 |
+
$bp->root_components[] = $slug;
|
983 |
+
}
|
984 |
+
|
985 |
+
/**
|
986 |
+
* bp_core_get_random_member()
|
987 |
+
*
|
988 |
+
* Returns the user_id for a user based on their username.
|
989 |
+
*
|
990 |
+
* @package BuddyPress Core
|
991 |
+
* @param $username str Username to check.
|
992 |
+
* @return false on no match
|
993 |
+
* @return int the user ID of the matched user.
|
994 |
+
*/
|
995 |
+
function bp_core_get_random_member() {
|
996 |
+
global $bp;
|
997 |
+
|
998 |
+
if ( isset( $_GET['random-member'] ) ) {
|
999 |
+
$user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
|
1000 |
+
bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
|
1001 |
+
}
|
1002 |
+
}
|
1003 |
+
add_action( 'wp', 'bp_core_get_random_member' );
|
1004 |
+
|
1005 |
+
/**
|
1006 |
+
* bp_core_get_userid()
|
1007 |
+
*
|
1008 |
+
* Returns the user_id for a user based on their username.
|
1009 |
+
*
|
1010 |
+
* @package BuddyPress Core
|
1011 |
+
* @param $username str Username to check.
|
1012 |
+
* @global $wpdb WordPress DB access object.
|
1013 |
+
* @return false on no match
|
1014 |
+
* @return int the user ID of the matched user.
|
1015 |
+
*/
|
1016 |
+
function bp_core_get_userid( $username ) {
|
1017 |
+
global $wpdb;
|
1018 |
+
|
1019 |
+
if ( empty( $username ) )
|
1020 |
+
return false;
|
1021 |
+
|
1022 |
+
return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
|
1023 |
+
}
|
1024 |
+
|
1025 |
+
/**
|
1026 |
+
* bp_core_get_userid_from_nicename()
|
1027 |
+
*
|
1028 |
+
* Returns the user_id for a user based on their user_nicename.
|
1029 |
+
*
|
1030 |
+
* @package BuddyPress Core
|
1031 |
+
* @param $username str Username to check.
|
1032 |
+
* @global $wpdb WordPress DB access object.
|
1033 |
+
* @return false on no match
|
1034 |
+
* @return int the user ID of the matched user.
|
1035 |
+
*/
|
1036 |
+
function bp_core_get_userid_from_nicename( $user_nicename ) {
|
1037 |
+
global $wpdb;
|
1038 |
+
|
1039 |
+
if ( empty( $user_nicename ) )
|
1040 |
+
return false;
|
1041 |
+
|
1042 |
+
return apply_filters( 'bp_core_get_userid_from_nicename', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $user_nicename ) ) );
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
/**
|
1046 |
+
* bp_core_get_username()
|
1047 |
+
*
|
1048 |
+
* Returns the username for a user based on their user id.
|
1049 |
+
*
|
1050 |
+
* @package BuddyPress Core
|
1051 |
+
* @param $uid int User ID to check.
|
1052 |
+
* @global $userdata WordPress user data for the current logged in user.
|
1053 |
+
* @uses get_userdata() WordPress function to fetch the userdata for a user ID
|
1054 |
+
* @return false on no match
|
1055 |
+
* @return str the username of the matched user.
|
1056 |
+
*/
|
1057 |
+
function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
|
1058 |
+
global $bp;
|
1059 |
+
|
1060 |
+
if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
|
1061 |
+
if ( empty( $user_nicename ) && empty( $user_login ) ) {
|
1062 |
+
$ud = false;
|
1063 |
+
|
1064 |
+
if ( $bp->loggedin_user->id == $user_id )
|
1065 |
+
$ud = &$bp->loggedin_user->userdata;
|
1066 |
+
|
1067 |
+
if ( $bp->displayed_user->id == $user_id )
|
1068 |
+
$ud = &$bp->displayed_user->userdata;
|
1069 |
+
|
1070 |
+
if ( empty( $ud ) ) {
|
1071 |
+
if ( !$ud = bp_core_get_core_userdata( $user_id ) )
|
1072 |
+
return false;
|
1073 |
+
}
|
1074 |
+
|
1075 |
+
$user_nicename = $ud->user_nicename;
|
1076 |
+
$user_login = $ud->user_login;
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
|
1080 |
+
$username = $user_login;
|
1081 |
+
else
|
1082 |
+
$username = $user_nicename;
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
/* Add this to cache */
|
1086 |
+
if ( !empty( $username ) )
|
1087 |
+
wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
|
1088 |
+
|
1089 |
+
return apply_filters( 'bp_core_get_username', $username );
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
/**
|
1093 |
+
* bp_core_get_user_email()
|
1094 |
+
*
|
1095 |
+
* Returns the email address for the user based on user ID
|
1096 |
+
*
|
1097 |
+
* @package BuddyPress Core
|
1098 |
+
* @param $uid int User ID to check.
|
1099 |
+
* @uses get_userdata() WordPress function to fetch the userdata for a user ID
|
1100 |
+
* @return false on no match
|
1101 |
+
* @return str The email for the matched user.
|
1102 |
+
*/
|
1103 |
+
function bp_core_get_user_email( $uid ) {
|
1104 |
+
if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
|
1105 |
+
$ud = bp_core_get_core_userdata($uid);
|
1106 |
+
$email = $ud->user_email;
|
1107 |
+
wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
return apply_filters( 'bp_core_get_user_email', $email );
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* bp_core_get_userlink()
|
1115 |
+
*
|
1116 |
+
* Returns a HTML formatted link for a user with the user's full name as the link text.
|
1117 |
+
* eg: <a href="http://andy.domain.com/">Andy Peatling</a>
|
1118 |
+
* Optional parameters will return just the name, or just the URL, or disable "You" text when
|
1119 |
+
* user matches the logged in user.
|
1120 |
+
*
|
1121 |
+
* [NOTES: This function needs to be cleaned up or split into separate functions]
|
1122 |
+
*
|
1123 |
+
* @package BuddyPress Core
|
1124 |
+
* @param $uid int User ID to check.
|
1125 |
+
* @param $no_anchor bool Disable URL and HTML and just return full name. Default false.
|
1126 |
+
* @param $just_link bool Disable full name and HTML and just return the URL text. Default false.
|
1127 |
+
* @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false.
|
1128 |
+
* @global $userdata WordPress user data for the current logged in user.
|
1129 |
+
* @uses get_userdata() WordPress function to fetch the userdata for a user ID
|
1130 |
+
* @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID.
|
1131 |
+
* @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID
|
1132 |
+
* @return false on no match
|
1133 |
+
* @return str The link text based on passed parameters.
|
1134 |
+
*/
|
1135 |
+
function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {
|
1136 |
+
$display_name = bp_core_get_user_displayname( $user_id );
|
1137 |
+
|
1138 |
+
if ( empty( $display_name ) )
|
1139 |
+
return false;
|
1140 |
+
|
1141 |
+
if ( $no_anchor )
|
1142 |
+
return $display_name;
|
1143 |
+
|
1144 |
+
if ( !$url = bp_core_get_user_domain($user_id) )
|
1145 |
+
return false;
|
1146 |
+
|
1147 |
+
if ( $just_link )
|
1148 |
+
return $url;
|
1149 |
+
|
1150 |
+
return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );
|
1151 |
+
}
|
1152 |
+
|
1153 |
+
|
1154 |
+
/**
|
1155 |
+
* bp_core_get_user_displayname()
|
1156 |
+
*
|
1157 |
+
* Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
|
1158 |
+
* Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
|
1159 |
+
*
|
1160 |
+
* @package BuddyPress Core
|
1161 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1162 |
+
* @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
|
1163 |
+
* @uses get_userdata() Fetches the WP userdata for a specific user.
|
1164 |
+
* @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
|
1165 |
+
* @uses wp_cache_set() Adds a value to the cache.
|
1166 |
+
* @return str The display name for the user in question.
|
1167 |
+
*/
|
1168 |
+
function bp_core_get_user_displayname( $user_id_or_username ) {
|
1169 |
+
global $bp;
|
1170 |
+
|
1171 |
+
if ( !$user_id_or_username )
|
1172 |
+
return false;
|
1173 |
+
|
1174 |
+
if ( !is_numeric( $user_id_or_username ) )
|
1175 |
+
$user_id = bp_core_get_userid( $user_id_or_username );
|
1176 |
+
else
|
1177 |
+
$user_id = $user_id_or_username;
|
1178 |
+
|
1179 |
+
if ( !$user_id )
|
1180 |
+
return false;
|
1181 |
+
|
1182 |
+
if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
|
1183 |
+
if ( function_exists('xprofile_install') ) {
|
1184 |
+
$fullname = xprofile_get_field_data( 1, $user_id );
|
1185 |
+
|
1186 |
+
if ( empty($fullname) ) {
|
1187 |
+
$ud = bp_core_get_core_userdata( $user_id );
|
1188 |
+
|
1189 |
+
if ( !empty( $ud->display_name ) )
|
1190 |
+
$fullname = $ud->display_name;
|
1191 |
+
else
|
1192 |
+
$fullname = $ud->user_nicename;
|
1193 |
+
|
1194 |
+
xprofile_set_field_data( 1, $user_id, $fullname );
|
1195 |
+
}
|
1196 |
+
} else {
|
1197 |
+
$ud = bp_core_get_core_userdata($user_id);
|
1198 |
+
|
1199 |
+
if ( !empty( $ud->display_name ) )
|
1200 |
+
$fullname = $ud->display_name;
|
1201 |
+
else
|
1202 |
+
$fullname = $ud->user_nicename;
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
if ( !empty( $fullname ) )
|
1206 |
+
wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );
|
1210 |
+
}
|
1211 |
+
add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
|
1212 |
+
add_filter( 'bp_core_get_user_displayname', 'trim' );
|
1213 |
+
add_filter( 'bp_core_get_user_displayname', 'stripslashes' );
|
1214 |
+
|
1215 |
+
|
1216 |
+
/**
|
1217 |
+
* bp_core_get_userlink_by_email()
|
1218 |
+
*
|
1219 |
+
* Returns the user link for the user based on user email address
|
1220 |
+
*
|
1221 |
+
* @package BuddyPress Core
|
1222 |
+
* @param $email str The email address for the user.
|
1223 |
+
* @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
|
1224 |
+
* @uses get_user_by_email() WordPress function to get userdata via an email address
|
1225 |
+
* @return str The link to the users home base. False on no match.
|
1226 |
+
*/
|
1227 |
+
function bp_core_get_userlink_by_email( $email ) {
|
1228 |
+
$user = get_user_by_email( $email );
|
1229 |
+
return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) );
|
1230 |
+
}
|
1231 |
+
|
1232 |
+
/**
|
1233 |
+
* bp_core_get_userlink_by_username()
|
1234 |
+
*
|
1235 |
+
* Returns the user link for the user based on user's username
|
1236 |
+
*
|
1237 |
+
* @package BuddyPress Core
|
1238 |
+
* @param $username str The username for the user.
|
1239 |
+
* @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
|
1240 |
+
* @return str The link to the users home base. False on no match.
|
1241 |
+
*/
|
1242 |
+
function bp_core_get_userlink_by_username( $username ) {
|
1243 |
+
global $wpdb;
|
1244 |
+
|
1245 |
+
$user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
|
1246 |
+
return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
|
1247 |
+
}
|
1248 |
+
|
1249 |
+
/**
|
1250 |
+
* bp_core_get_total_member_count()
|
1251 |
+
*
|
1252 |
+
* Returns the total number of members for the installation.
|
1253 |
+
*
|
1254 |
+
* @package BuddyPress Core
|
1255 |
+
* @return int The total number of members.
|
1256 |
+
*/
|
1257 |
+
function bp_core_get_total_member_count() {
|
1258 |
+
global $wpdb, $bp;
|
1259 |
+
|
1260 |
+
if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) {
|
1261 |
+
$status_sql = bp_core_get_status_sql();
|
1262 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) );
|
1263 |
+
wp_cache_set( 'bp_total_member_count', $count, 'bp' );
|
1264 |
+
}
|
1265 |
+
|
1266 |
+
return apply_filters( 'bp_core_get_total_member_count', $count );
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
/**
|
1270 |
+
* bp_core_is_user_spammer()
|
1271 |
+
*
|
1272 |
+
* Checks if the user has been marked as a spammer.
|
1273 |
+
*
|
1274 |
+
* @package BuddyPress Core
|
1275 |
+
* @param $user_id int The id for the user.
|
1276 |
+
* @return int 1 if spammer, 0 if not.
|
1277 |
+
*/
|
1278 |
+
function bp_core_is_user_spammer( $user_id ) {
|
1279 |
+
global $wpdb;
|
1280 |
+
|
1281 |
+
if ( bp_core_is_multisite() )
|
1282 |
+
$is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
|
1283 |
+
else
|
1284 |
+
$is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
|
1285 |
+
|
1286 |
+
return apply_filters( 'bp_core_is_user_spammer', $is_spammer );
|
1287 |
+
}
|
1288 |
+
|
1289 |
+
/**
|
1290 |
+
* bp_core_is_user_deleted()
|
1291 |
+
*
|
1292 |
+
* Checks if the user has been marked as deleted.
|
1293 |
+
*
|
1294 |
+
* @package BuddyPress Core
|
1295 |
+
* @param $user_id int The id for the user.
|
1296 |
+
* @return int 1 if deleted, 0 if not.
|
1297 |
+
*/
|
1298 |
+
function bp_core_is_user_deleted( $user_id ) {
|
1299 |
+
global $wpdb;
|
1300 |
+
|
1301 |
+
return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) );
|
1302 |
+
}
|
1303 |
+
|
1304 |
+
/**
|
1305 |
+
* bp_core_current_time()
|
1306 |
+
*
|
1307 |
+
* Get the current GMT time to save into the DB
|
1308 |
+
*
|
1309 |
+
* @package BuddyPress Core
|
1310 |
+
* @since 1.2.6
|
1311 |
+
*/
|
1312 |
+
function bp_core_current_time( $gmt = true ) {
|
1313 |
+
// Get current time in MYSQL format
|
1314 |
+
$current_time = current_time( 'mysql', $gmt );
|
1315 |
+
|
1316 |
+
return apply_filters( 'bp_core_current_time', $current_time );
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
/**
|
1320 |
+
* bp_core_add_message()
|
1321 |
+
*
|
1322 |
+
* Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
|
1323 |
+
*
|
1324 |
+
* @package BuddyPress Core
|
1325 |
+
*/
|
1326 |
+
function bp_core_add_message( $message, $type = false ) {
|
1327 |
+
global $bp;
|
1328 |
+
|
1329 |
+
if ( !$type )
|
1330 |
+
$type = 'success';
|
1331 |
+
|
1332 |
+
/* Send the values to the cookie for page reload display */
|
1333 |
+
@setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
|
1334 |
+
@setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
|
1335 |
+
|
1336 |
+
/***
|
1337 |
+
* Send the values to the $bp global so we can still output messages
|
1338 |
+
* without a page reload
|
1339 |
+
*/
|
1340 |
+
$bp->template_message = $message;
|
1341 |
+
$bp->template_message_type = $type;
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
/**
|
1345 |
+
* bp_core_setup_message()
|
1346 |
+
*
|
1347 |
+
* Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
|
1348 |
+
* so that the message can be parsed into the template and displayed to the user.
|
1349 |
+
*
|
1350 |
+
* After the message is displayed, it removes the message vars from the cookie so that the message
|
1351 |
+
* is not shown to the user multiple times.
|
1352 |
+
*
|
1353 |
+
* @package BuddyPress Core
|
1354 |
+
* @global $bp_message The message text
|
1355 |
+
* @global $bp_message_type The type of message (error/success)
|
1356 |
+
* @uses setcookie() Sets a cookie value for the user.
|
1357 |
+
*/
|
1358 |
+
function bp_core_setup_message() {
|
1359 |
+
global $bp;
|
1360 |
+
|
1361 |
+
if ( empty( $bp->template_message ) )
|
1362 |
+
$bp->template_message = $_COOKIE['bp-message'];
|
1363 |
+
|
1364 |
+
if ( empty( $bp->template_message_type ) )
|
1365 |
+
$bp->template_message_type = $_COOKIE['bp-message-type'];
|
1366 |
+
|
1367 |
+
add_action( 'template_notices', 'bp_core_render_message' );
|
1368 |
+
|
1369 |
+
@setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
|
1370 |
+
@setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
|
1371 |
+
}
|
1372 |
+
add_action( 'wp', 'bp_core_setup_message', 2 );
|
1373 |
+
|
1374 |
+
/**
|
1375 |
+
* bp_core_render_message()
|
1376 |
+
*
|
1377 |
+
* Renders a feedback message (either error or success message) to the theme template.
|
1378 |
+
* The hook action 'template_notices' is used to call this function, it is not called directly.
|
1379 |
+
*
|
1380 |
+
* @package BuddyPress Core
|
1381 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1382 |
+
*/
|
1383 |
+
function bp_core_render_message() {
|
1384 |
+
global $bp;
|
1385 |
+
|
1386 |
+
if ( $bp->template_message ) {
|
1387 |
+
$type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
|
1388 |
+
?>
|
1389 |
+
<div id="message" class="<?php echo $type; ?>">
|
1390 |
+
<p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>
|
1391 |
+
</div>
|
1392 |
+
<?php
|
1393 |
+
do_action( 'bp_core_render_message' );
|
1394 |
+
}
|
1395 |
+
}
|
1396 |
+
|
1397 |
+
/**
|
1398 |
+
* bp_core_time_since()
|
1399 |
+
*
|
1400 |
+
* Based on function created by Dunstan Orchard - http://1976design.com
|
1401 |
+
*
|
1402 |
+
* This function will return an English representation of the time elapsed
|
1403 |
+
* since a given date.
|
1404 |
+
* eg: 2 hours and 50 minutes
|
1405 |
+
* eg: 4 days
|
1406 |
+
* eg: 4 weeks and 6 days
|
1407 |
+
*
|
1408 |
+
* @package BuddyPress Core
|
1409 |
+
* @param $older_date int Unix timestamp of date you want to calculate the time since for
|
1410 |
+
* @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).
|
1411 |
+
* @return str The time since.
|
1412 |
+
*/
|
1413 |
+
function bp_core_time_since( $older_date, $newer_date = false ) {
|
1414 |
+
|
1415 |
+
// array of time period chunks
|
1416 |
+
$chunks = array(
|
1417 |
+
array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
|
1418 |
+
array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
|
1419 |
+
array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
|
1420 |
+
array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
|
1421 |
+
array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
|
1422 |
+
array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
|
1423 |
+
array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
|
1424 |
+
);
|
1425 |
+
|
1426 |
+
if ( !is_numeric( $older_date ) ) {
|
1427 |
+
$time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
|
1428 |
+
$date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
|
1429 |
+
|
1430 |
+
$older_date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
|
1431 |
+
}
|
1432 |
+
|
1433 |
+
/* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
|
1434 |
+
/* $newer_date will have a value if we want to work out time elapsed between two known dates */
|
1435 |
+
$newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
|
1436 |
+
|
1437 |
+
/* Difference in seconds */
|
1438 |
+
$since = $newer_date - $older_date;
|
1439 |
+
|
1440 |
+
/* Something went wrong with date calculation and we ended up with a negative date. */
|
1441 |
+
if ( 0 > $since )
|
1442 |
+
return __( 'sometime', 'buddypress' );
|
1443 |
+
|
1444 |
+
/**
|
1445 |
+
* We only want to output two chunks of time here, eg:
|
1446 |
+
* x years, xx months
|
1447 |
+
* x days, xx hours
|
1448 |
+
* so there's only two bits of calculation below:
|
1449 |
+
*/
|
1450 |
+
|
1451 |
+
/* Step one: the first chunk */
|
1452 |
+
for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
|
1453 |
+
$seconds = $chunks[$i][0];
|
1454 |
+
|
1455 |
+
/* Finding the biggest chunk (if the chunk fits, break) */
|
1456 |
+
if ( ( $count = floor($since / $seconds) ) != 0 )
|
1457 |
+
break;
|
1458 |
+
}
|
1459 |
+
|
1460 |
+
/* Set output var */
|
1461 |
+
$output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
|
1462 |
+
|
1463 |
+
/* Step two: the second chunk */
|
1464 |
+
if ( $i + 2 < $j ) {
|
1465 |
+
$seconds2 = $chunks[$i + 1][0];
|
1466 |
+
$name2 = $chunks[$i + 1][1];
|
1467 |
+
|
1468 |
+
if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
|
1469 |
+
/* Add to output var */
|
1470 |
+
$output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
|
1471 |
+
}
|
1472 |
+
}
|
1473 |
+
|
1474 |
+
if ( !(int)trim($output) )
|
1475 |
+
$output = '0 ' . __( 'seconds', 'buddypress' );
|
1476 |
+
|
1477 |
+
return $output;
|
1478 |
+
}
|
1479 |
+
|
1480 |
+
|
1481 |
+
/**
|
1482 |
+
* bp_core_record_activity()
|
1483 |
+
*
|
1484 |
+
* Record user activity to the database. Many functions use a "last active" feature to
|
1485 |
+
* show the length of time since the user was last active.
|
1486 |
+
* This function will update that time as a usermeta setting for the user every 5 minutes.
|
1487 |
+
*
|
1488 |
+
* @package BuddyPress Core
|
1489 |
+
* @global $userdata WordPress user data for the current logged in user.
|
1490 |
+
* @uses update_user_meta() WordPress function to update user metadata in the usermeta table.
|
1491 |
+
*/
|
1492 |
+
function bp_core_record_activity() {
|
1493 |
+
global $bp;
|
1494 |
+
|
1495 |
+
if ( !is_user_logged_in() )
|
1496 |
+
return false;
|
1497 |
+
|
1498 |
+
$activity = get_user_meta( $bp->loggedin_user->id, 'last_activity', true );
|
1499 |
+
|
1500 |
+
if ( !is_numeric( $activity ) )
|
1501 |
+
$activity = strtotime( $activity );
|
1502 |
+
|
1503 |
+
// Get current time
|
1504 |
+
$current_time = bp_core_current_time();
|
1505 |
+
|
1506 |
+
if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
|
1507 |
+
update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time );
|
1508 |
+
}
|
1509 |
+
add_action( 'wp_head', 'bp_core_record_activity' );
|
1510 |
+
|
1511 |
+
|
1512 |
+
/**
|
1513 |
+
* bp_core_get_last_activity()
|
1514 |
+
*
|
1515 |
+
* Formats last activity based on time since date given.
|
1516 |
+
*
|
1517 |
+
* @package BuddyPress Core
|
1518 |
+
* @param last_activity_date The date of last activity.
|
1519 |
+
* @param $before The text to prepend to the activity time since figure.
|
1520 |
+
* @param $after The text to append to the activity time since figure.
|
1521 |
+
* @uses bp_core_time_since() This function will return an English representation of the time elapsed.
|
1522 |
+
*/
|
1523 |
+
function bp_core_get_last_activity( $last_activity_date, $string ) {
|
1524 |
+
if ( !$last_activity_date || empty( $last_activity_date ) ) {
|
1525 |
+
$last_active = __( 'not recently active', 'buddypress' );
|
1526 |
+
} else {
|
1527 |
+
$last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
function bp_core_number_format( $number, $decimals = false ) {
|
1534 |
+
/* Check we actually have a number first. */
|
1535 |
+
if ( empty( $number ) )
|
1536 |
+
return $number;
|
1537 |
+
|
1538 |
+
return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
|
1539 |
+
}
|
1540 |
+
|
1541 |
+
/**
|
1542 |
+
* bp_core_get_all_posts_for_user()
|
1543 |
+
*
|
1544 |
+
* Fetch every post that is authored by the given user for the current blog.
|
1545 |
+
*
|
1546 |
+
* @package BuddyPress Core
|
1547 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1548 |
+
* @global $wpdb WordPress user data for the current logged in user.
|
1549 |
+
* @return array of post ids.
|
1550 |
+
*/
|
1551 |
+
function bp_core_get_all_posts_for_user( $user_id = null ) {
|
1552 |
+
global $bp, $wpdb;
|
1553 |
+
|
1554 |
+
if ( !$user_id )
|
1555 |
+
$user_id = $bp->displayed_user->id;
|
1556 |
+
|
1557 |
+
return apply_filters( 'bp_core_get_all_posts_for_user', $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) ) );
|
1558 |
+
}
|
1559 |
+
|
1560 |
+
/**
|
1561 |
+
* bp_core_get_site_path()
|
1562 |
+
*
|
1563 |
+
* Get the path of of the current site.
|
1564 |
+
*
|
1565 |
+
* @package BuddyPress Core
|
1566 |
+
*
|
1567 |
+
* @global $bp $bp
|
1568 |
+
* @global object $current_site
|
1569 |
+
* @return string
|
1570 |
+
*/
|
1571 |
+
function bp_core_get_site_path() {
|
1572 |
+
global $bp, $current_site;
|
1573 |
+
|
1574 |
+
if ( bp_core_is_multisite() )
|
1575 |
+
$site_path = $current_site->path;
|
1576 |
+
else {
|
1577 |
+
$site_path = (array) explode( '/', site_url() );
|
1578 |
+
|
1579 |
+
if ( count( $site_path ) < 2 )
|
1580 |
+
$site_path = '/';
|
1581 |
+
else {
|
1582 |
+
/* Unset the first three segments (http(s)://domain.com part) */
|
1583 |
+
unset( $site_path[0] );
|
1584 |
+
unset( $site_path[1] );
|
1585 |
+
unset( $site_path[2] );
|
1586 |
+
|
1587 |
+
if ( !count( $site_path ) )
|
1588 |
+
$site_path = '/';
|
1589 |
+
else
|
1590 |
+
$site_path = '/' . implode( '/', $site_path ) . '/';
|
1591 |
+
}
|
1592 |
+
}
|
1593 |
+
|
1594 |
+
return apply_filters( 'bp_core_get_site_path', $site_path );
|
1595 |
+
}
|
1596 |
+
/**
|
1597 |
+
* bp_core_get_site_options()
|
1598 |
+
*
|
1599 |
+
* BuddyPress uses site options to store configuration settings. Many of these settings are needed
|
1600 |
+
* at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
|
1601 |
+
* them all in one go.
|
1602 |
+
*
|
1603 |
+
* @package BuddyPress Core
|
1604 |
+
*/
|
1605 |
+
function bp_core_get_site_options() {
|
1606 |
+
global $bp, $wpdb;
|
1607 |
+
|
1608 |
+
$options = apply_filters( 'bp_core_site_options', array(
|
1609 |
+
'bp-deactivated-components',
|
1610 |
+
'bp-blogs-first-install',
|
1611 |
+
'bp-disable-blog-forum-comments',
|
1612 |
+
'bp-xprofile-base-group-name',
|
1613 |
+
'bp-xprofile-fullname-field-name',
|
1614 |
+
'bp-disable-profile-sync',
|
1615 |
+
'bp-disable-avatar-uploads',
|
1616 |
+
'bp-disable-account-deletion',
|
1617 |
+
'bp-disable-forum-directory',
|
1618 |
+
'bp-disable-blogforum-comments',
|
1619 |
+
'bb-config-location',
|
1620 |
+
'hide-loggedout-adminbar',
|
1621 |
+
|
1622 |
+
/* Useful WordPress settings used often */
|
1623 |
+
'user-avatar-default',
|
1624 |
+
'tags_blog_id',
|
1625 |
+
'registration',
|
1626 |
+
'fileupload_maxk'
|
1627 |
+
) );
|
1628 |
+
|
1629 |
+
$meta_keys = "'" . implode( "','", (array)$options ) ."'";
|
1630 |
+
|
1631 |
+
if ( bp_core_is_multisite() )
|
1632 |
+
$meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );
|
1633 |
+
else
|
1634 |
+
$meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
|
1635 |
+
|
1636 |
+
$site_options = array();
|
1637 |
+
if ( !empty( $meta ) ) {
|
1638 |
+
foreach( (array)$meta as $meta_item )
|
1639 |
+
$site_options[$meta_item->name] = $meta_item->value;
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
return apply_filters( 'bp_core_get_site_options', $site_options );
|
1643 |
+
}
|
1644 |
+
|
1645 |
+
/**
|
1646 |
+
* bp_core_redirect()
|
1647 |
+
*
|
1648 |
+
* Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
|
1649 |
+
*
|
1650 |
+
* @package BuddyPress Core
|
1651 |
+
* @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
|
1652 |
+
* @uses get_themes()
|
1653 |
+
* @return An array containing all of the themes.
|
1654 |
+
*/
|
1655 |
+
function bp_core_redirect( $location, $status = 302 ) {
|
1656 |
+
global $bp_no_status_set;
|
1657 |
+
|
1658 |
+
// Make sure we don't call status_header() in bp_core_do_catch_uri()
|
1659 |
+
// as this conflicts with wp_redirect()
|
1660 |
+
$bp_no_status_set = true;
|
1661 |
+
|
1662 |
+
wp_redirect( $location, $status );
|
1663 |
+
die;
|
1664 |
+
}
|
1665 |
+
|
1666 |
+
/**
|
1667 |
+
* bp_core_referrer()
|
1668 |
+
*
|
1669 |
+
* Returns the referrer URL without the http(s)://
|
1670 |
+
*
|
1671 |
+
* @package BuddyPress Core
|
1672 |
+
* @return The referrer URL
|
1673 |
+
*/
|
1674 |
+
function bp_core_referrer() {
|
1675 |
+
$referer = explode( '/', wp_get_referer() );
|
1676 |
+
unset( $referer[0], $referer[1], $referer[2] );
|
1677 |
+
return implode( '/', $referer );
|
1678 |
+
}
|
1679 |
+
|
1680 |
+
/**
|
1681 |
+
* bp_core_add_illegal_names()
|
1682 |
+
*
|
1683 |
+
* Adds illegal names to WP so that root components will not conflict with
|
1684 |
+
* blog names on a subdirectory installation.
|
1685 |
+
*
|
1686 |
+
* For example, it would stop someone creating a blog with the slug "groups".
|
1687 |
+
*
|
1688 |
+
* @package BuddyPress Core
|
1689 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1690 |
+
*/
|
1691 |
+
function bp_core_add_illegal_names() {
|
1692 |
+
global $bp;
|
1693 |
+
|
1694 |
+
$current = maybe_unserialize( get_site_option( 'illegal_names' ) );
|
1695 |
+
$bp_illegal_names = $bp->root_components;
|
1696 |
+
|
1697 |
+
if ( is_array( $current ) ) {
|
1698 |
+
foreach( (array)$bp_illegal_names as $bp_illegal_name ) {
|
1699 |
+
if ( !in_array( $bp_illegal_name, $current ) )
|
1700 |
+
$current[] = $bp_illegal_name;
|
1701 |
+
}
|
1702 |
+
$new = $current;
|
1703 |
+
} else {
|
1704 |
+
$bp_illegal_names[] = $current;
|
1705 |
+
$new = $bp_illegal_names;
|
1706 |
+
}
|
1707 |
+
|
1708 |
+
update_site_option( 'illegal_names', $new );
|
1709 |
+
}
|
1710 |
+
|
1711 |
+
/**
|
1712 |
+
* bp_core_delete_account()
|
1713 |
+
*
|
1714 |
+
* Allows a user to completely remove their account from the system
|
1715 |
+
*
|
1716 |
+
* @package BuddyPress Core
|
1717 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1718 |
+
* @uses is_super_admin() Checks to see if the user is a site administrator.
|
1719 |
+
* @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
|
1720 |
+
* @uses wp_delete_user() Deletes a user from the system on singlesite installs.
|
1721 |
+
* @uses get_site_option Checks if account deletion is allowed
|
1722 |
+
*/
|
1723 |
+
function bp_core_delete_account( $user_id = false ) {
|
1724 |
+
global $bp, $wp_version;
|
1725 |
+
|
1726 |
+
if ( !$user_id )
|
1727 |
+
$user_id = $bp->loggedin_user->id;
|
1728 |
+
|
1729 |
+
/* Make sure account deletion is not disabled */
|
1730 |
+
if ( (int)get_site_option( 'bp-disable-account-deletion' ) )
|
1731 |
+
return false;
|
1732 |
+
|
1733 |
+
/* Site admins cannot be deleted */
|
1734 |
+
if ( is_super_admin( bp_core_get_username( $user_id ) ) )
|
1735 |
+
return false;
|
1736 |
+
|
1737 |
+
/* Specifically handle multi-site environment */
|
1738 |
+
if ( bp_core_is_multisite() ) {
|
1739 |
+
if ( $wp_version >= '3.0' )
|
1740 |
+
require_once( ABSPATH . '/wp-admin/includes/ms.php' );
|
1741 |
+
else
|
1742 |
+
require_once( ABSPATH . '/wp-admin/includes/mu.php' );
|
1743 |
+
|
1744 |
+
require_once( ABSPATH . '/wp-admin/includes/user.php' );
|
1745 |
+
|
1746 |
+
return wpmu_delete_user( $user_id );
|
1747 |
+
|
1748 |
+
/* Single site user deletion */
|
1749 |
+
} else {
|
1750 |
+
require_once( ABSPATH . '/wp-admin/includes/user.php' );
|
1751 |
+
return wp_delete_user( $user_id );
|
1752 |
+
}
|
1753 |
+
}
|
1754 |
+
|
1755 |
+
|
1756 |
+
/**
|
1757 |
+
* bp_core_search_site()
|
1758 |
+
*
|
1759 |
+
* A javascript free implementation of the search functions in BuddyPress
|
1760 |
+
*
|
1761 |
+
* @package BuddyPress Core
|
1762 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
1763 |
+
* @param $slug The slug to redirect to for searching.
|
1764 |
+
*/
|
1765 |
+
function bp_core_action_search_site( $slug = false ) {
|
1766 |
+
global $bp;
|
1767 |
+
|
1768 |
+
if ( $bp->current_component == BP_SEARCH_SLUG ) {
|
1769 |
+
$search_terms = $_POST['search-terms'];
|
1770 |
+
$search_which = $_POST['search-which'];
|
1771 |
+
|
1772 |
+
if ( !$slug || empty( $slug ) ) {
|
1773 |
+
switch ( $search_which ) {
|
1774 |
+
case 'members': default:
|
1775 |
+
$slug = BP_MEMBERS_SLUG;
|
1776 |
+
$var = '/?s=';
|
1777 |
+
break;
|
1778 |
+
case 'groups':
|
1779 |
+
$slug = BP_GROUPS_SLUG;
|
1780 |
+
$var = '/?s=';
|
1781 |
+
break;
|
1782 |
+
case 'forums':
|
1783 |
+
$slug = BP_FORUMS_SLUG;
|
1784 |
+
$var = '/?fs=';
|
1785 |
+
break;
|
1786 |
+
case 'blogs':
|
1787 |
+
$slug = BP_BLOGS_SLUG;
|
1788 |
+
$var = '/?s=';
|
1789 |
+
break;
|
1790 |
+
}
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
$search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms );
|
1794 |
+
|
1795 |
+
bp_core_redirect( $search_url );
|
1796 |
+
}
|
1797 |
+
}
|
1798 |
+
add_action( 'init', 'bp_core_action_search_site', 5 );
|
1799 |
+
|
1800 |
+
|
1801 |
+
/**
|
1802 |
+
* bp_core_ucfirst()
|
1803 |
+
*
|
1804 |
+
* Localization safe ucfirst() support.
|
1805 |
+
*
|
1806 |
+
* @package BuddyPress Core
|
1807 |
+
*/
|
1808 |
+
function bp_core_ucfirst( $str ) {
|
1809 |
+
if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
|
1810 |
+
$fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
|
1811 |
+
return $fc.mb_substr( $str, 1 );
|
1812 |
+
} else {
|
1813 |
+
return ucfirst( $str );
|
1814 |
+
}
|
1815 |
+
}
|
1816 |
+
|
1817 |
+
|
1818 |
+
/**
|
1819 |
+
* bp_core_strip_username_spaces()
|
1820 |
+
*
|
1821 |
+
* Strips spaces from usernames that are created using add_user() and wp_insert_user()
|
1822 |
+
*
|
1823 |
+
* @package BuddyPress Core
|
1824 |
+
*/
|
1825 |
+
function bp_core_strip_username_spaces( $username ) {
|
1826 |
+
return str_replace( ' ', '-', $username );
|
1827 |
+
}
|
1828 |
+
add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );
|
1829 |
+
|
1830 |
+
|
1831 |
+
/**
|
1832 |
+
* bp_core_clear_cache()
|
1833 |
+
* REQUIRES WP-SUPER-CACHE
|
1834 |
+
*
|
1835 |
+
* When wp-super-cache is installed this function will clear cached pages
|
1836 |
+
* so that success/error messages are not cached, or time sensitive content.
|
1837 |
+
*
|
1838 |
+
* @package BuddyPress Core
|
1839 |
+
*/
|
1840 |
+
function bp_core_clear_cache() {
|
1841 |
+
global $cache_path, $cache_filename;
|
1842 |
+
|
1843 |
+
if ( function_exists( 'prune_super_cache' ) ) {
|
1844 |
+
do_action( 'bp_core_clear_cache' );
|
1845 |
+
|
1846 |
+
return prune_super_cache( $cache_path, true );
|
1847 |
+
}
|
1848 |
+
}
|
1849 |
+
|
1850 |
+
/**
|
1851 |
+
* bp_core_print_generation_time()
|
1852 |
+
*
|
1853 |
+
* Prints the generation time in the footer of the site.
|
1854 |
+
*
|
1855 |
+
* @package BuddyPress Core
|
1856 |
+
*/
|
1857 |
+
function bp_core_print_generation_time() {
|
1858 |
+
?>
|
1859 |
+
|
1860 |
+
<!-- Generated in <?php timer_stop(1); ?> seconds. -->
|
1861 |
+
|
1862 |
+
<?php
|
1863 |
+
}
|
1864 |
+
add_action( 'wp_footer', 'bp_core_print_generation_time' );
|
1865 |
+
|
1866 |
+
/**
|
1867 |
+
* bp_core_add_admin_menu_page()
|
1868 |
+
*
|
1869 |
+
* A better version of add_admin_menu_page() that allows positioning of menus.
|
1870 |
+
*
|
1871 |
+
* @package BuddyPress Core
|
1872 |
+
*/
|
1873 |
+
function bp_core_add_admin_menu_page( $args = '' ) {
|
1874 |
+
global $menu, $admin_page_hooks, $_registered_pages;
|
1875 |
+
|
1876 |
+
$defaults = array(
|
1877 |
+
'page_title' => '',
|
1878 |
+
'menu_title' => '',
|
1879 |
+
'access_level' => 2,
|
1880 |
+
'file' => false,
|
1881 |
+
'function' => false,
|
1882 |
+
'icon_url' => false,
|
1883 |
+
'position' => 100
|
1884 |
+
);
|
1885 |
+
|
1886 |
+
$r = wp_parse_args( $args, $defaults );
|
1887 |
+
extract( $r, EXTR_SKIP );
|
1888 |
+
|
1889 |
+
$file = plugin_basename( $file );
|
1890 |
+
|
1891 |
+
$admin_page_hooks[$file] = sanitize_title( $menu_title );
|
1892 |
+
|
1893 |
+
$hookname = get_plugin_page_hookname( $file, '' );
|
1894 |
+
if (!empty ( $function ) && !empty ( $hookname ))
|
1895 |
+
add_action( $hookname, $function );
|
1896 |
+
|
1897 |
+
if ( empty($icon_url) )
|
1898 |
+
$icon_url = 'images/generic.png';
|
1899 |
+
elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
|
1900 |
+
$icon_url = 'https://' . substr($icon_url, 7);
|
1901 |
+
|
1902 |
+
do {
|
1903 |
+
$position++;
|
1904 |
+
} while ( !empty( $menu[$position] ) );
|
1905 |
+
|
1906 |
+
$menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
|
1907 |
+
|
1908 |
+
$_registered_pages[$hookname] = true;
|
1909 |
+
|
1910 |
+
return $hookname;
|
1911 |
+
}
|
1912 |
+
|
1913 |
+
/**
|
1914 |
+
* bp_core_boot_spammer()
|
1915 |
+
*
|
1916 |
+
* When a user logs in, check if they have been marked as a spammer. If yes then simply
|
1917 |
+
* redirect them to the home page and stop them from logging in.
|
1918 |
+
*
|
1919 |
+
* @package BuddyPress Core
|
1920 |
+
* @param $auth_obj The WP authorization object
|
1921 |
+
* @param $username The username of the user logging in.
|
1922 |
+
* @uses get_userdatabylogin() Get the userdata object for a user based on their username
|
1923 |
+
* @uses bp_core_redirect() Safe redirect to a page
|
1924 |
+
* @return $auth_obj If the user is not a spammer, return the authorization object
|
1925 |
+
*/
|
1926 |
+
function bp_core_boot_spammer( $auth_obj, $username ) {
|
1927 |
+
global $bp;
|
1928 |
+
|
1929 |
+
$user = get_userdatabylogin( $username );
|
1930 |
+
|
1931 |
+
if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
|
1932 |
+
bp_core_redirect( $bp->root_domain );
|
1933 |
+
else
|
1934 |
+
return $auth_obj;
|
1935 |
+
}
|
1936 |
+
add_filter( 'authenticate', 'bp_core_boot_spammer', 11, 2 );
|
1937 |
+
|
1938 |
+
/**
|
1939 |
+
* bp_core_remove_data()
|
1940 |
+
*
|
1941 |
+
* Deletes usermeta for the user when the user is deleted.
|
1942 |
+
*
|
1943 |
+
* @package BuddyPress Core
|
1944 |
+
* @param $user_id The user id for the user to delete usermeta for
|
1945 |
+
* @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key
|
1946 |
+
*/
|
1947 |
+
function bp_core_remove_data( $user_id ) {
|
1948 |
+
/* Remove usermeta */
|
1949 |
+
delete_user_meta( $user_id, 'last_activity' );
|
1950 |
+
|
1951 |
+
/* Flush the cache to remove the user from all cached objects */
|
1952 |
+
wp_cache_flush();
|
1953 |
+
}
|
1954 |
+
add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
|
1955 |
+
add_action( 'delete_user', 'bp_core_remove_data' );
|
1956 |
+
add_action( 'make_spam_user', 'bp_core_remove_data' );
|
1957 |
+
|
1958 |
+
/**
|
1959 |
+
* bp_load_buddypress_textdomain()
|
1960 |
+
*
|
1961 |
+
* Load the buddypress translation file for current language
|
1962 |
+
*
|
1963 |
+
* @package BuddyPress Core
|
1964 |
+
*/
|
1965 |
+
function bp_core_load_buddypress_textdomain() {
|
1966 |
+
$locale = apply_filters( 'buddypress_locale', get_locale() );
|
1967 |
+
$mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo";
|
1968 |
+
|
1969 |
+
if ( file_exists( $mofile ) )
|
1970 |
+
load_textdomain( 'buddypress', $mofile );
|
1971 |
+
}
|
1972 |
+
add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 );
|
1973 |
+
|
1974 |
+
function bp_core_add_ajax_hook() {
|
1975 |
+
/* Theme only, we already have the wp_ajax_ hook firing in wp-admin */
|
1976 |
+
if ( !defined( 'WP_ADMIN' ) )
|
1977 |
+
do_action( 'wp_ajax_' . $_REQUEST['action'] );
|
1978 |
+
}
|
1979 |
+
add_action( 'init', 'bp_core_add_ajax_hook' );
|
1980 |
+
|
1981 |
+
/**
|
1982 |
+
* bp_core_update_message()
|
1983 |
+
*
|
1984 |
+
* Add an extra update message to the update plugin notification.
|
1985 |
+
*
|
1986 |
+
* @package BuddyPress Core
|
1987 |
+
*/
|
1988 |
+
function bp_core_update_message() {
|
1989 |
+
echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/getting-started/upgrading-from-10x/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';
|
1990 |
+
}
|
1991 |
+
add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
|
1992 |
+
|
1993 |
+
/**
|
1994 |
+
* bp_core_activation_notice()
|
1995 |
+
*
|
1996 |
+
* When BuddyPress is activated we must make sure that mod_rewrite is enabled.
|
1997 |
+
* We must also make sure a BuddyPress compatible theme is enabled. This function
|
1998 |
+
* will show helpful messages to the administrator.
|
1999 |
+
*
|
2000 |
+
* @package BuddyPress Core
|
2001 |
+
*/
|
2002 |
+
function bp_core_activation_notice() {
|
2003 |
+
global $wp_rewrite, $current_blog, $bp;
|
2004 |
+
|
2005 |
+
if ( isset( $_POST['permalink_structure'] ) )
|
2006 |
+
return false;
|
2007 |
+
|
2008 |
+
if ( !is_super_admin() )
|
2009 |
+
return false;
|
2010 |
+
|
2011 |
+
if ( !empty( $current_blog ) ) {
|
2012 |
+
if ( $current_blog->blog_id != BP_ROOT_BLOG )
|
2013 |
+
return false;
|
2014 |
+
}
|
2015 |
+
|
2016 |
+
if ( empty( $wp_rewrite->permalink_structure ) ) { ?>
|
2017 |
+
<div id="message" class="updated fade">
|
2018 |
+
<p><?php printf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ) ?></p>
|
2019 |
+
</div><?php
|
2020 |
+
} else {
|
2021 |
+
/* Get current theme info */
|
2022 |
+
$ct = current_theme_info();
|
2023 |
+
|
2024 |
+
/* The best way to remove this notice is to add a "buddypress" tag to your active theme's CSS header. */
|
2025 |
+
if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>
|
2026 |
+
<div id="message" class="updated fade">
|
2027 |
+
<p style="line-height: 150%"><?php printf( __( "<strong>BuddyPress is ready</strong>. You'll need to <a href='%s'>activate a BuddyPress compatible theme</a> to take advantage of all of the features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>upgrade your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), admin_url( 'plugin-install.php?type=term&tab=search&s=bp-template-pack' ) ) ?></p>
|
2028 |
+
</div><?php
|
2029 |
+
}
|
2030 |
+
}
|
2031 |
+
}
|
2032 |
+
add_action( 'admin_notices', 'bp_core_activation_notice' );
|
2033 |
+
|
2034 |
+
/**
|
2035 |
+
* bp_core_activate_site_options()
|
2036 |
+
*
|
2037 |
+
* When switching from single to multisite we need to copy blog options to
|
2038 |
+
* site options.
|
2039 |
+
*
|
2040 |
+
* @package BuddyPress Core
|
2041 |
+
*/
|
2042 |
+
function bp_core_activate_site_options( $keys = array() ) {
|
2043 |
+
global $bp;
|
2044 |
+
|
2045 |
+
if ( !empty( $keys ) && is_array( $keys ) ) {
|
2046 |
+
$errors = false;
|
2047 |
+
|
2048 |
+
foreach ( $keys as $key => $default ) {
|
2049 |
+
if ( empty( $bp->site_options[ $key ] ) ) {
|
2050 |
+
$bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
|
2051 |
+
|
2052 |
+
if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
|
2053 |
+
$errors = true;
|
2054 |
+
}
|
2055 |
+
}
|
2056 |
+
|
2057 |
+
if ( empty( $errors ) )
|
2058 |
+
return true;
|
2059 |
+
}
|
2060 |
+
|
2061 |
+
return false;
|
2062 |
+
}
|
2063 |
+
|
2064 |
+
/********************************************************************************
|
2065 |
+
* Custom Actions
|
2066 |
+
*
|
2067 |
+
* Functions to set up custom BuddyPress actions that all other components can
|
2068 |
+
* hook in to.
|
2069 |
+
*/
|
2070 |
+
|
2071 |
+
/**
|
2072 |
+
* bp_include()
|
2073 |
+
*
|
2074 |
+
* Allow plugins to include their files ahead of core filters
|
2075 |
+
*/
|
2076 |
+
function bp_include() {
|
2077 |
+
do_action( 'bp_include' );
|
2078 |
+
}
|
2079 |
+
add_action( 'bp_loaded', 'bp_include', 2 );
|
2080 |
+
|
2081 |
+
/**
|
2082 |
+
* bp_setup_root_components()
|
2083 |
+
*
|
2084 |
+
* Allow core components and dependent plugins to set root components
|
2085 |
+
*/
|
2086 |
+
function bp_setup_root_components() {
|
2087 |
+
do_action( 'bp_setup_root_components' );
|
2088 |
+
}
|
2089 |
+
add_action( 'bp_loaded', 'bp_setup_root_components', 2 );
|
2090 |
+
|
2091 |
+
/**
|
2092 |
+
* bp_setup_globals()
|
2093 |
+
*
|
2094 |
+
* Allow core components and dependent plugins to set globals
|
2095 |
+
*/
|
2096 |
+
function bp_setup_globals() {
|
2097 |
+
do_action( 'bp_setup_globals' );
|
2098 |
+
}
|
2099 |
+
add_action( 'bp_loaded', 'bp_setup_globals', 6 );
|
2100 |
+
|
2101 |
+
/**
|
2102 |
+
* bp_setup_nav()
|
2103 |
+
*
|
2104 |
+
* Allow core components and dependent plugins to set their nav
|
2105 |
+
*/
|
2106 |
+
function bp_setup_nav() {
|
2107 |
+
do_action( 'bp_setup_nav' );
|
2108 |
+
}
|
2109 |
+
add_action( 'bp_loaded', 'bp_setup_nav', 8 );
|
2110 |
+
|
2111 |
+
/**
|
2112 |
+
* bp_setup_widgets()
|
2113 |
+
*
|
2114 |
+
* Allow core components and dependent plugins to register widgets
|
2115 |
+
*/
|
2116 |
+
function bp_setup_widgets() {
|
2117 |
+
do_action( 'bp_register_widgets' );
|
2118 |
+
}
|
2119 |
+
add_action( 'bp_loaded', 'bp_setup_widgets', 8 );
|
2120 |
+
|
2121 |
+
/**
|
2122 |
+
* bp_init()
|
2123 |
+
*
|
2124 |
+
* Allow components to initialize themselves cleanly
|
2125 |
+
*/
|
2126 |
+
function bp_init() {
|
2127 |
+
do_action( 'bp_init' );
|
2128 |
+
}
|
2129 |
+
add_action( 'bp_loaded', 'bp_init' );
|
2130 |
+
|
2131 |
+
/********************************************************************************
|
2132 |
+
* Caching
|
2133 |
+
*
|
2134 |
+
* Caching functions handle the clearing of cached objects and pages on specific
|
2135 |
+
* actions throughout BuddyPress.
|
2136 |
+
*/
|
2137 |
+
|
2138 |
+
/**
|
2139 |
+
* bp_core_add_global_group()
|
2140 |
+
*
|
2141 |
+
* Add's 'bp' to global group of network wide cachable objects
|
2142 |
+
*
|
2143 |
+
* @package BuddyPress Core
|
2144 |
+
*/
|
2145 |
+
function bp_core_add_global_group() {
|
2146 |
+
wp_cache_init();
|
2147 |
+
|
2148 |
+
if ( function_exists( 'wp_cache_add_global_groups' ) )
|
2149 |
+
wp_cache_add_global_groups( array( 'bp' ) );
|
2150 |
+
}
|
2151 |
+
add_action( 'init', 'bp_core_add_global_group' );
|
2152 |
+
|
2153 |
+
/**
|
2154 |
+
* bp_core_clear_user_object_cache()
|
2155 |
+
*
|
2156 |
+
* Clears all cached objects for a user, or a user is part of.
|
2157 |
+
*
|
2158 |
+
* @package BuddyPress Core
|
2159 |
+
*/
|
2160 |
+
function bp_core_clear_user_object_cache( $user_id ) {
|
2161 |
+
wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
|
2162 |
+
wp_cache_delete( 'bp_core_avatar_v1_u' . $user_id, 'bp' );
|
2163 |
+
wp_cache_delete( 'bp_core_avatar_v2_u' . $user_id, 'bp' );
|
2164 |
+
wp_cache_delete( 'online_users' );
|
2165 |
+
wp_cache_delete( 'newest_users' );
|
2166 |
+
}
|
2167 |
+
|
2168 |
+
// List actions to clear super cached pages on, if super cache is installed
|
2169 |
+
add_action( 'wp_login', 'bp_core_clear_cache' );
|
2170 |
+
add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
|
2171 |
+
|
2172 |
+
// Remove the catch non existent blogs hook so WPMU doesn't think BuddyPress pages are non existing blogs
|
2173 |
+
remove_action( 'plugins_loaded', 'catch_nonexistant_blogs' );
|
2174 |
+
|
2175 |
?>
|
bp-core/bp-core-admin.php
CHANGED
@@ -1,251 +1,251 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function bp_core_admin_settings() {
|
4 |
-
global $wpdb, $bp, $current_blog;
|
5 |
-
?>
|
6 |
-
|
7 |
-
<?php
|
8 |
-
if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) {
|
9 |
-
if ( !check_admin_referer('bp-admin') )
|
10 |
-
return false;
|
11 |
-
|
12 |
-
// Settings form submitted, now save the settings.
|
13 |
-
foreach ( (array)$_POST['bp-admin'] as $key => $value ) {
|
14 |
-
|
15 |
-
if ( function_exists( 'xprofile_install' ) ) {
|
16 |
-
if ( 'bp-xprofile-base-group-name' == $key ) {
|
17 |
-
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE id = 1", $value ) );
|
18 |
-
}
|
19 |
-
|
20 |
-
if ( 'bp-xprofile-fullname-field-name' == $key ) {
|
21 |
-
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET name = %s WHERE group_id = 1 AND id = 1", $value ) );
|
22 |
-
}
|
23 |
-
}
|
24 |
-
|
25 |
-
update_site_option( $key, $value );
|
26 |
-
}
|
27 |
-
}
|
28 |
-
?>
|
29 |
-
|
30 |
-
<div class="wrap">
|
31 |
-
|
32 |
-
<h2><?php _e( 'BuddyPress Settings', 'buddypress' ) ?></h2>
|
33 |
-
|
34 |
-
<?php if ( isset( $_POST['bp-admin'] ) ) : ?>
|
35 |
-
<div id="message" class="updated fade">
|
36 |
-
<p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
|
37 |
-
</div>
|
38 |
-
<?php endif; ?>
|
39 |
-
|
40 |
-
<form action="" method="post" id="bp-admin-form">
|
41 |
-
|
42 |
-
<table class="form-table">
|
43 |
-
<tbody>
|
44 |
-
<?php if ( function_exists( 'xprofile_install' ) ) :?>
|
45 |
-
<tr>
|
46 |
-
<th scope="row"><?php _e( 'Base profile group name', 'buddypress' ) ?>:</th>
|
47 |
-
<td>
|
48 |
-
<input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" />
|
49 |
-
</td>
|
50 |
-
</tr>
|
51 |
-
<tr>
|
52 |
-
<th scope="row"><?php _e( 'Full Name field name', 'buddypress' ) ?>:</th>
|
53 |
-
<td>
|
54 |
-
<input name="bp-admin[bp-xprofile-fullname-field-name]" id="bp-xprofile-fullname-field-name" value="<?php echo get_site_option('bp-xprofile-fullname-field-name') ?>" />
|
55 |
-
</td>
|
56 |
-
</tr>
|
57 |
-
<tr>
|
58 |
-
<th scope="row"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</th>
|
59 |
-
<td>
|
60 |
-
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
61 |
-
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
62 |
-
</td>
|
63 |
-
</tr>
|
64 |
-
<?php endif; ?>
|
65 |
-
<tr>
|
66 |
-
<th scope="row"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</th>
|
67 |
-
<td>
|
68 |
-
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
69 |
-
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
70 |
-
</td>
|
71 |
-
</tr>
|
72 |
-
<tr>
|
73 |
-
<th scope="row"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</th>
|
74 |
-
<td>
|
75 |
-
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
76 |
-
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
77 |
-
</td>
|
78 |
-
</tr>
|
79 |
-
<tr>
|
80 |
-
<th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
|
81 |
-
<td>
|
82 |
-
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
83 |
-
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
84 |
-
</td>
|
85 |
-
</tr>
|
86 |
-
<?php if ( function_exists( 'bp_forums_setup') ) : ?>
|
87 |
-
<tr>
|
88 |
-
<th scope="row"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</th>
|
89 |
-
<td>
|
90 |
-
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
91 |
-
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
92 |
-
</td>
|
93 |
-
</tr>
|
94 |
-
<?php endif; ?>
|
95 |
-
<?php if ( function_exists( 'bp_activity_install') ) : ?>
|
96 |
-
<tr>
|
97 |
-
<th scope="row"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</th>
|
98 |
-
<td>
|
99 |
-
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
100 |
-
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
101 |
-
</td>
|
102 |
-
</tr>
|
103 |
-
<?php endif; ?>
|
104 |
-
|
105 |
-
<tr>
|
106 |
-
<th scope="row"><?php _e( 'Default User Avatar', 'buddypress' ) ?></th>
|
107 |
-
<td>
|
108 |
-
<p><?php _e( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address', 'buddypress' ) ?></p>
|
109 |
-
|
110 |
-
<label><input name="bp-admin[user-avatar-default]" id="avatar_mystery" value="mystery" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'mystery' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>&?s=32&d=<?php echo BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' ?>&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Mystery Man', 'buddypress' ) ?></label><br>
|
111 |
-
<label><input name="bp-admin[user-avatar-default]" id="avatar_identicon" value="identicon" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'identicon' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=identicon&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Identicon (Generated)', 'buddypress' ) ?></label><br>
|
112 |
-
<label><input name="bp-admin[user-avatar-default]" id="avatar_wavatar" value="wavatar" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'wavatar' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=wavatar&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Wavatar (Generated)', 'buddypress' ) ?> </label><br>
|
113 |
-
<label><input name="bp-admin[user-avatar-default]" id="avatar_monsterid" value="monsterid" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'monsterid' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=monsterid&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'MonsterID (Generated)', 'buddypress' ) ?></label>
|
114 |
-
</td>
|
115 |
-
</tr>
|
116 |
-
|
117 |
-
<?php do_action( 'bp_core_admin_screen_fields' ) ?>
|
118 |
-
</tbody>
|
119 |
-
</table>
|
120 |
-
|
121 |
-
<?php do_action( 'bp_core_admin_screen' ) ?>
|
122 |
-
|
123 |
-
<p class="submit">
|
124 |
-
<input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
|
125 |
-
</p>
|
126 |
-
|
127 |
-
<?php wp_nonce_field( 'bp-admin' ) ?>
|
128 |
-
|
129 |
-
</form>
|
130 |
-
|
131 |
-
</div>
|
132 |
-
|
133 |
-
<?php
|
134 |
-
}
|
135 |
-
|
136 |
-
function bp_core_admin_component_setup() {
|
137 |
-
global $wpdb, $bp;
|
138 |
-
?>
|
139 |
-
|
140 |
-
<?php
|
141 |
-
if ( isset( $_POST['bp-admin-component-submit'] ) && isset( $_POST['bp_components'] ) ) {
|
142 |
-
if ( !check_admin_referer('bp-admin-component-setup') )
|
143 |
-
return false;
|
144 |
-
|
145 |
-
// Settings form submitted, now save the settings.
|
146 |
-
foreach ( (array)$_POST['bp_components'] as $key => $value ) {
|
147 |
-
if ( !(int) $value )
|
148 |
-
$disabled[$key] = 1;
|
149 |
-
}
|
150 |
-
update_site_option( 'bp-deactivated-components', $disabled );
|
151 |
-
}
|
152 |
-
?>
|
153 |
-
|
154 |
-
<div class="wrap">
|
155 |
-
|
156 |
-
<h2><?php _e( 'BuddyPress Component Setup', 'buddypress' ) ?></h2>
|
157 |
-
|
158 |
-
<?php if ( isset( $_POST['bp-admin-component-submit'] ) ) : ?>
|
159 |
-
<div id="message" class="updated fade">
|
160 |
-
<p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
|
161 |
-
</div>
|
162 |
-
<?php endif; ?>
|
163 |
-
|
164 |
-
<form action="" method="post" id="bp-admin-component-form">
|
165 |
-
|
166 |
-
<p><?php _e('By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form below. Your BuddyPress installation will continue to function, however the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ) ?></p>
|
167 |
-
|
168 |
-
<?php $disabled_components = get_site_option( 'bp-deactivated-components' ); ?>
|
169 |
-
|
170 |
-
<table class="form-table" style="width: 80%">
|
171 |
-
<tbody>
|
172 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-activity.php') ) : ?>
|
173 |
-
<tr>
|
174 |
-
<td><h3><?php _e( 'Activity Streams', 'buddypress' ) ?></h3><p><?php _e( 'Allow users to post activity updates and track all activity across the entire site.', 'buddypress' ) ?></p></td>
|
175 |
-
<td>
|
176 |
-
<input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
177 |
-
<input type="radio" name="bp_components[bp-activity.php]" value="0"<?php if ( isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
178 |
-
</td>
|
179 |
-
</tr>
|
180 |
-
<?php endif; ?>
|
181 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-blogs.php') && bp_core_is_multisite() ) : ?>
|
182 |
-
<tr>
|
183 |
-
<td><h3><?php _e( 'Blog Tracking', 'buddypress' ) ?></h3><p><?php _e( 'Tracks blogs, blog posts and blogs comments for a user across a WPMU installation.', 'buddypress' ) ?></p></td>
|
184 |
-
<td>
|
185 |
-
<input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
186 |
-
<input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
187 |
-
</td>
|
188 |
-
</tr>
|
189 |
-
<?php endif; ?>
|
190 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-forums.php') ) : ?>
|
191 |
-
<tr>
|
192 |
-
<td><h3><?php _e( 'bbPress Forums', 'buddypress' ) ?></h3><p><?php _e( 'Activates bbPress forum support within BuddyPress groups or any other custom component.', 'buddypress' ) ?></p></td>
|
193 |
-
<td>
|
194 |
-
<input type="radio" name="bp_components[bp-forums.php]" value="1"<?php if ( !isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
195 |
-
<input type="radio" name="bp_components[bp-forums.php]" value="0"<?php if ( isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
196 |
-
</td>
|
197 |
-
</tr>
|
198 |
-
<?php endif; ?>
|
199 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-friends.php') ) : ?>
|
200 |
-
<tr>
|
201 |
-
<td><h3><?php _e( 'Friends', 'buddypress' ) ?></h3><p><?php _e( 'Allows the creation of friend connections between users.', 'buddypress' ) ?></p></td>
|
202 |
-
<td>
|
203 |
-
<input type="radio" name="bp_components[bp-friends.php]" value="1"<?php if ( !isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
204 |
-
<input type="radio" name="bp_components[bp-friends.php]" value="0"<?php if ( isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
205 |
-
</td>
|
206 |
-
</tr>
|
207 |
-
<?php endif; ?>
|
208 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-groups.php') ) : ?>
|
209 |
-
<tr>
|
210 |
-
<td><h3><?php _e( 'Groups', 'buddypress' ) ?></h3><p><?php _e( 'Let users create, join and participate in groups.', 'buddypress' ) ?></p></td>
|
211 |
-
<td>
|
212 |
-
<input type="radio" name="bp_components[bp-groups.php]" value="1"<?php if ( !isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
213 |
-
<input type="radio" name="bp_components[bp-groups.php]" value="0"<?php if ( isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
214 |
-
</td>
|
215 |
-
</tr>
|
216 |
-
<?php endif; ?>
|
217 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-messages.php') ) : ?>
|
218 |
-
<tr>
|
219 |
-
<td><h3><?php _e( 'Private Messaging', 'buddypress' ) ?></h3><p><?php _e( 'Let users send private messages to one another. Site admins can also send site-wide notices.', 'buddypress' ) ?></p></td>
|
220 |
-
<td>
|
221 |
-
<input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
222 |
-
<input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
223 |
-
</td>
|
224 |
-
</tr>
|
225 |
-
<?php endif; ?>
|
226 |
-
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') ) : ?>
|
227 |
-
<tr>
|
228 |
-
<td><h3><?php _e( 'Extended Profiles', 'buddypress' ) ?></h3><p><?php _e( 'Activates customizable profiles and avatars for site users.', 'buddypress' ) ?></p></td>
|
229 |
-
<td width="45%">
|
230 |
-
<input type="radio" name="bp_components[bp-xprofile.php]" value="1"<?php if ( !isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
231 |
-
<input type="radio" name="bp_components[bp-xprofile.php]" value="0"<?php if ( isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
232 |
-
</td>
|
233 |
-
</tr>
|
234 |
-
<?php endif; ?>
|
235 |
-
</tbody>
|
236 |
-
</table>
|
237 |
-
|
238 |
-
<p class="submit">
|
239 |
-
<input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
|
240 |
-
</p>
|
241 |
-
|
242 |
-
<?php wp_nonce_field( 'bp-admin-component-setup' ) ?>
|
243 |
-
|
244 |
-
</form>
|
245 |
-
|
246 |
-
</div>
|
247 |
-
|
248 |
-
<?php
|
249 |
-
}
|
250 |
-
|
251 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function bp_core_admin_settings() {
|
4 |
+
global $wpdb, $bp, $current_blog;
|
5 |
+
?>
|
6 |
+
|
7 |
+
<?php
|
8 |
+
if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) {
|
9 |
+
if ( !check_admin_referer('bp-admin') )
|
10 |
+
return false;
|
11 |
+
|
12 |
+
// Settings form submitted, now save the settings.
|
13 |
+
foreach ( (array)$_POST['bp-admin'] as $key => $value ) {
|
14 |
+
|
15 |
+
if ( function_exists( 'xprofile_install' ) ) {
|
16 |
+
if ( 'bp-xprofile-base-group-name' == $key ) {
|
17 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE id = 1", $value ) );
|
18 |
+
}
|
19 |
+
|
20 |
+
if ( 'bp-xprofile-fullname-field-name' == $key ) {
|
21 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET name = %s WHERE group_id = 1 AND id = 1", $value ) );
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
update_site_option( $key, $value );
|
26 |
+
}
|
27 |
+
}
|
28 |
+
?>
|
29 |
+
|
30 |
+
<div class="wrap">
|
31 |
+
|
32 |
+
<h2><?php _e( 'BuddyPress Settings', 'buddypress' ) ?></h2>
|
33 |
+
|
34 |
+
<?php if ( isset( $_POST['bp-admin'] ) ) : ?>
|
35 |
+
<div id="message" class="updated fade">
|
36 |
+
<p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
|
37 |
+
</div>
|
38 |
+
<?php endif; ?>
|
39 |
+
|
40 |
+
<form action="" method="post" id="bp-admin-form">
|
41 |
+
|
42 |
+
<table class="form-table">
|
43 |
+
<tbody>
|
44 |
+
<?php if ( function_exists( 'xprofile_install' ) ) :?>
|
45 |
+
<tr>
|
46 |
+
<th scope="row"><?php _e( 'Base profile group name', 'buddypress' ) ?>:</th>
|
47 |
+
<td>
|
48 |
+
<input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" />
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
<tr>
|
52 |
+
<th scope="row"><?php _e( 'Full Name field name', 'buddypress' ) ?>:</th>
|
53 |
+
<td>
|
54 |
+
<input name="bp-admin[bp-xprofile-fullname-field-name]" id="bp-xprofile-fullname-field-name" value="<?php echo get_site_option('bp-xprofile-fullname-field-name') ?>" />
|
55 |
+
</td>
|
56 |
+
</tr>
|
57 |
+
<tr>
|
58 |
+
<th scope="row"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</th>
|
59 |
+
<td>
|
60 |
+
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
61 |
+
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
62 |
+
</td>
|
63 |
+
</tr>
|
64 |
+
<?php endif; ?>
|
65 |
+
<tr>
|
66 |
+
<th scope="row"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</th>
|
67 |
+
<td>
|
68 |
+
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
69 |
+
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
70 |
+
</td>
|
71 |
+
</tr>
|
72 |
+
<tr>
|
73 |
+
<th scope="row"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</th>
|
74 |
+
<td>
|
75 |
+
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
76 |
+
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
77 |
+
</td>
|
78 |
+
</tr>
|
79 |
+
<tr>
|
80 |
+
<th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
|
81 |
+
<td>
|
82 |
+
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
83 |
+
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
84 |
+
</td>
|
85 |
+
</tr>
|
86 |
+
<?php if ( function_exists( 'bp_forums_setup') ) : ?>
|
87 |
+
<tr>
|
88 |
+
<th scope="row"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</th>
|
89 |
+
<td>
|
90 |
+
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
91 |
+
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
92 |
+
</td>
|
93 |
+
</tr>
|
94 |
+
<?php endif; ?>
|
95 |
+
<?php if ( function_exists( 'bp_activity_install') ) : ?>
|
96 |
+
<tr>
|
97 |
+
<th scope="row"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</th>
|
98 |
+
<td>
|
99 |
+
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?>
|
100 |
+
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
|
101 |
+
</td>
|
102 |
+
</tr>
|
103 |
+
<?php endif; ?>
|
104 |
+
|
105 |
+
<tr>
|
106 |
+
<th scope="row"><?php _e( 'Default User Avatar', 'buddypress' ) ?></th>
|
107 |
+
<td>
|
108 |
+
<p><?php _e( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address', 'buddypress' ) ?></p>
|
109 |
+
|
110 |
+
<label><input name="bp-admin[user-avatar-default]" id="avatar_mystery" value="mystery" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'mystery' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>&?s=32&d=<?php echo BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' ?>&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Mystery Man', 'buddypress' ) ?></label><br>
|
111 |
+
<label><input name="bp-admin[user-avatar-default]" id="avatar_identicon" value="identicon" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'identicon' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=identicon&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Identicon (Generated)', 'buddypress' ) ?></label><br>
|
112 |
+
<label><input name="bp-admin[user-avatar-default]" id="avatar_wavatar" value="wavatar" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'wavatar' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=wavatar&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'Wavatar (Generated)', 'buddypress' ) ?> </label><br>
|
113 |
+
<label><input name="bp-admin[user-avatar-default]" id="avatar_monsterid" value="monsterid" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'monsterid' ) : ?> checked="checked"<?php endif; ?> /> <img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&d=monsterid&r=PG&forcedefault=1" class="avatar avatar-32" height="32" width="32"> <?php _e( 'MonsterID (Generated)', 'buddypress' ) ?></label>
|
114 |
+
</td>
|
115 |
+
</tr>
|
116 |
+
|
117 |
+
<?php do_action( 'bp_core_admin_screen_fields' ) ?>
|
118 |
+
</tbody>
|
119 |
+
</table>
|
120 |
+
|
121 |
+
<?php do_action( 'bp_core_admin_screen' ) ?>
|
122 |
+
|
123 |
+
<p class="submit">
|
124 |
+
<input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
|
125 |
+
</p>
|
126 |
+
|
127 |
+
<?php wp_nonce_field( 'bp-admin' ) ?>
|
128 |
+
|
129 |
+
</form>
|
130 |
+
|
131 |
+
</div>
|
132 |
+
|
133 |
+
<?php
|
134 |
+
}
|
135 |
+
|
136 |
+
function bp_core_admin_component_setup() {
|
137 |
+
global $wpdb, $bp;
|
138 |
+
?>
|
139 |
+
|
140 |
+
<?php
|
141 |
+
if ( isset( $_POST['bp-admin-component-submit'] ) && isset( $_POST['bp_components'] ) ) {
|
142 |
+
if ( !check_admin_referer('bp-admin-component-setup') )
|
143 |
+
return false;
|
144 |
+
|
145 |
+
// Settings form submitted, now save the settings.
|
146 |
+
foreach ( (array)$_POST['bp_components'] as $key => $value ) {
|
147 |
+
if ( !(int) $value )
|
148 |
+
$disabled[$key] = 1;
|
149 |
+
}
|
150 |
+
update_site_option( 'bp-deactivated-components', $disabled );
|
151 |
+
}
|
152 |
+
?>
|
153 |
+
|
154 |
+
<div class="wrap">
|
155 |
+
|
156 |
+
<h2><?php _e( 'BuddyPress Component Setup', 'buddypress' ) ?></h2>
|
157 |
+
|
158 |
+
<?php if ( isset( $_POST['bp-admin-component-submit'] ) ) : ?>
|
159 |
+
<div id="message" class="updated fade">
|
160 |
+
<p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
|
161 |
+
</div>
|
162 |
+
<?php endif; ?>
|
163 |
+
|
164 |
+
<form action="" method="post" id="bp-admin-component-form">
|
165 |
+
|
166 |
+
<p><?php _e('By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form below. Your BuddyPress installation will continue to function, however the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ) ?></p>
|
167 |
+
|
168 |
+
<?php $disabled_components = get_site_option( 'bp-deactivated-components' ); ?>
|
169 |
+
|
170 |
+
<table class="form-table" style="width: 80%">
|
171 |
+
<tbody>
|
172 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-activity.php') ) : ?>
|
173 |
+
<tr>
|
174 |
+
<td><h3><?php _e( 'Activity Streams', 'buddypress' ) ?></h3><p><?php _e( 'Allow users to post activity updates and track all activity across the entire site.', 'buddypress' ) ?></p></td>
|
175 |
+
<td>
|
176 |
+
<input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
177 |
+
<input type="radio" name="bp_components[bp-activity.php]" value="0"<?php if ( isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
178 |
+
</td>
|
179 |
+
</tr>
|
180 |
+
<?php endif; ?>
|
181 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-blogs.php') && bp_core_is_multisite() ) : ?>
|
182 |
+
<tr>
|
183 |
+
<td><h3><?php _e( 'Blog Tracking', 'buddypress' ) ?></h3><p><?php _e( 'Tracks blogs, blog posts and blogs comments for a user across a WPMU installation.', 'buddypress' ) ?></p></td>
|
184 |
+
<td>
|
185 |
+
<input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
186 |
+
<input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
187 |
+
</td>
|
188 |
+
</tr>
|
189 |
+
<?php endif; ?>
|
190 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-forums.php') ) : ?>
|
191 |
+
<tr>
|
192 |
+
<td><h3><?php _e( 'bbPress Forums', 'buddypress' ) ?></h3><p><?php _e( 'Activates bbPress forum support within BuddyPress groups or any other custom component.', 'buddypress' ) ?></p></td>
|
193 |
+
<td>
|
194 |
+
<input type="radio" name="bp_components[bp-forums.php]" value="1"<?php if ( !isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
195 |
+
<input type="radio" name="bp_components[bp-forums.php]" value="0"<?php if ( isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
196 |
+
</td>
|
197 |
+
</tr>
|
198 |
+
<?php endif; ?>
|
199 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-friends.php') ) : ?>
|
200 |
+
<tr>
|
201 |
+
<td><h3><?php _e( 'Friends', 'buddypress' ) ?></h3><p><?php _e( 'Allows the creation of friend connections between users.', 'buddypress' ) ?></p></td>
|
202 |
+
<td>
|
203 |
+
<input type="radio" name="bp_components[bp-friends.php]" value="1"<?php if ( !isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
204 |
+
<input type="radio" name="bp_components[bp-friends.php]" value="0"<?php if ( isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
205 |
+
</td>
|
206 |
+
</tr>
|
207 |
+
<?php endif; ?>
|
208 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-groups.php') ) : ?>
|
209 |
+
<tr>
|
210 |
+
<td><h3><?php _e( 'Groups', 'buddypress' ) ?></h3><p><?php _e( 'Let users create, join and participate in groups.', 'buddypress' ) ?></p></td>
|
211 |
+
<td>
|
212 |
+
<input type="radio" name="bp_components[bp-groups.php]" value="1"<?php if ( !isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
213 |
+
<input type="radio" name="bp_components[bp-groups.php]" value="0"<?php if ( isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
214 |
+
</td>
|
215 |
+
</tr>
|
216 |
+
<?php endif; ?>
|
217 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-messages.php') ) : ?>
|
218 |
+
<tr>
|
219 |
+
<td><h3><?php _e( 'Private Messaging', 'buddypress' ) ?></h3><p><?php _e( 'Let users send private messages to one another. Site admins can also send site-wide notices.', 'buddypress' ) ?></p></td>
|
220 |
+
<td>
|
221 |
+
<input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
222 |
+
<input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
223 |
+
</td>
|
224 |
+
</tr>
|
225 |
+
<?php endif; ?>
|
226 |
+
<?php if ( file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') ) : ?>
|
227 |
+
<tr>
|
228 |
+
<td><h3><?php _e( 'Extended Profiles', 'buddypress' ) ?></h3><p><?php _e( 'Activates customizable profiles and avatars for site users.', 'buddypress' ) ?></p></td>
|
229 |
+
<td width="45%">
|
230 |
+
<input type="radio" name="bp_components[bp-xprofile.php]" value="1"<?php if ( !isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?>
|
231 |
+
<input type="radio" name="bp_components[bp-xprofile.php]" value="0"<?php if ( isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
|
232 |
+
</td>
|
233 |
+
</tr>
|
234 |
+
<?php endif; ?>
|
235 |
+
</tbody>
|
236 |
+
</table>
|
237 |
+
|
238 |
+
<p class="submit">
|
239 |
+
<input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
|
240 |
+
</p>
|
241 |
+
|
242 |
+
<?php wp_nonce_field( 'bp-admin-component-setup' ) ?>
|
243 |
+
|
244 |
+
</form>
|
245 |
+
|
246 |
+
</div>
|
247 |
+
|
248 |
+
<?php
|
249 |
+
}
|
250 |
+
|
251 |
?>
|
bp-core/bp-core-adminbar.php
CHANGED
@@ -1,258 +1,258 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function bp_core_admin_bar() {
|
4 |
-
global $bp, $wpdb, $current_blog;
|
5 |
-
|
6 |
-
if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
7 |
-
return false;
|
8 |
-
|
9 |
-
if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
|
10 |
-
return false;
|
11 |
-
|
12 |
-
$bp->doing_admin_bar = true;
|
13 |
-
|
14 |
-
echo '<div id="wp-admin-bar"><div class="padder">';
|
15 |
-
|
16 |
-
// **** Do bp-adminbar-logo Actions ********
|
17 |
-
do_action( 'bp_adminbar_logo' );
|
18 |
-
|
19 |
-
echo '<ul class="main-nav">';
|
20 |
-
|
21 |
-
// **** Do bp-adminbar-menus Actions ********
|
22 |
-
do_action( 'bp_adminbar_menus' );
|
23 |
-
|
24 |
-
echo '</ul>';
|
25 |
-
echo "</div></div><!-- #wp-admin-bar -->\n\n";
|
26 |
-
|
27 |
-
$bp->doing_admin_bar = false;
|
28 |
-
}
|
29 |
-
|
30 |
-
// **** Default BuddyPress admin bar logo ********
|
31 |
-
function bp_adminbar_logo() {
|
32 |
-
global $bp;
|
33 |
-
|
34 |
-
echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>';
|
35 |
-
}
|
36 |
-
|
37 |
-
// **** "Log In" and "Sign Up" links (Visible when not logged in) ********
|
38 |
-
function bp_adminbar_login_menu() {
|
39 |
-
global $bp;
|
40 |
-
|
41 |
-
if ( is_user_logged_in() )
|
42 |
-
return false;
|
43 |
-
|
44 |
-
echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
|
45 |
-
|
46 |
-
// Show "Sign Up" link if user registrations are allowed
|
47 |
-
if ( bp_get_signup_allowed() ) {
|
48 |
-
echo '<li class="bp-signup no-arrow"><a href="' . bp_get_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>';
|
49 |
-
}
|
50 |
-
}
|
51 |
-
|
52 |
-
|
53 |
-
// **** "My Account" Menu ******
|
54 |
-
function bp_adminbar_account_menu() {
|
55 |
-
global $bp;
|
56 |
-
|
57 |
-
if ( !$bp->bp_nav || !is_user_logged_in() )
|
58 |
-
return false;
|
59 |
-
|
60 |
-
echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
|
61 |
-
|
62 |
-
echo __( 'My Account', 'buddypress' ) . '</a>';
|
63 |
-
echo '<ul>';
|
64 |
-
|
65 |
-
/* Loop through each navigation item */
|
66 |
-
$counter = 0;
|
67 |
-
foreach( (array)$bp->bp_nav as $nav_item ) {
|
68 |
-
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
69 |
-
|
70 |
-
echo '<li' . $alt . '>';
|
71 |
-
echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
|
72 |
-
|
73 |
-
if ( is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
|
74 |
-
echo '<ul>';
|
75 |
-
$sub_counter = 0;
|
76 |
-
|
77 |
-
foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
|
78 |
-
$link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
|
79 |
-
$name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
|
80 |
-
$alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
|
81 |
-
echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
|
82 |
-
$sub_counter++;
|
83 |
-
}
|
84 |
-
echo '</ul>';
|
85 |
-
}
|
86 |
-
|
87 |
-
echo '</li>';
|
88 |
-
|
89 |
-
$counter++;
|
90 |
-
}
|
91 |
-
|
92 |
-
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
93 |
-
|
94 |
-
echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
|
95 |
-
echo '</ul>';
|
96 |
-
echo '</li>';
|
97 |
-
}
|
98 |
-
|
99 |
-
// *** "My Blogs" Menu ********
|
100 |
-
function bp_adminbar_blogs_menu() {
|
101 |
-
global $bp;
|
102 |
-
|
103 |
-
if ( !is_user_logged_in() || !function_exists('bp_blogs_install') )
|
104 |
-
return false;
|
105 |
-
|
106 |
-
if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
|
107 |
-
$blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
|
108 |
-
wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
|
109 |
-
}
|
110 |
-
|
111 |
-
echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/
|
112 |
-
|
113 |
-
_e( 'My Blogs', 'buddypress' );
|
114 |
-
|
115 |
-
echo '</a>';
|
116 |
-
echo '<ul>';
|
117 |
-
|
118 |
-
if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
|
119 |
-
$counter = 0;
|
120 |
-
foreach ( (array)$blogs['blogs'] as $blog ) {
|
121 |
-
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
122 |
-
$site_url = esc_attr( $blog->siteurl );
|
123 |
-
|
124 |
-
echo '<li' . $alt . '>';
|
125 |
-
echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
|
126 |
-
|
127 |
-
echo '<ul>';
|
128 |
-
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
|
129 |
-
echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
|
130 |
-
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
|
131 |
-
echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
|
132 |
-
echo '</ul>';
|
133 |
-
|
134 |
-
echo '</li>';
|
135 |
-
$counter++;
|
136 |
-
}
|
137 |
-
}
|
138 |
-
|
139 |
-
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
140 |
-
|
141 |
-
if ( bp_blog_signup_enabled() ) {
|
142 |
-
echo '<li' . $alt . '>';
|
143 |
-
echo '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create/">' . __( 'Create a Blog!', 'buddypress' ) . '</a>';
|
144 |
-
echo '</li>';
|
145 |
-
}
|
146 |
-
|
147 |
-
echo '</ul>';
|
148 |
-
echo '</li>';
|
149 |
-
}
|
150 |
-
|
151 |
-
// **** "Notifications" Menu *********
|
152 |
-
function bp_adminbar_notifications_menu() {
|
153 |
-
global $bp;
|
154 |
-
|
155 |
-
if ( !is_user_logged_in() )
|
156 |
-
return false;
|
157 |
-
|
158 |
-
echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
|
159 |
-
_e( 'Notifications', 'buddypress' );
|
160 |
-
|
161 |
-
if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
|
162 |
-
<span><?php echo count($notifications) ?></span>
|
163 |
-
<?php
|
164 |
-
}
|
165 |
-
|
166 |
-
echo '</a>';
|
167 |
-
echo '<ul>';
|
168 |
-
|
169 |
-
if ( $notifications ) { ?>
|
170 |
-
<?php $counter = 0; ?>
|
171 |
-
<?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
|
172 |
-
<?php $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
|
173 |
-
<li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
|
174 |
-
<?php $counter++; ?>
|
175 |
-
<?php } ?>
|
176 |
-
<?php } else { ?>
|
177 |
-
<li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
|
178 |
-
<?php
|
179 |
-
}
|
180 |
-
|
181 |
-
echo '</ul>';
|
182 |
-
echo '</li>';
|
183 |
-
}
|
184 |
-
|
185 |
-
// **** "Blog Authors" Menu (visible when not logged in) ********
|
186 |
-
function bp_adminbar_authors_menu() {
|
187 |
-
global $bp, $current_blog, $wpdb;
|
188 |
-
|
189 |
-
if ( $current_blog->blog_id == BP_ROOT_BLOG || !function_exists( 'bp_blogs_install' ) )
|
190 |
-
return false;
|
191 |
-
|
192 |
-
$blog_prefix = $wpdb->get_blog_prefix( $current_blog->id );
|
193 |
-
$authors = $wpdb->get_results( "SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id" );
|
194 |
-
|
195 |
-
if ( !empty( $authors ) ) {
|
196 |
-
/* This is a blog, render a menu with links to all authors */
|
197 |
-
echo '<li id="bp-adminbar-authors-menu"><a href="/">';
|
198 |
-
_e('Blog Authors', 'buddypress');
|
199 |
-
echo '</a>';
|
200 |
-
|
201 |
-
echo '<ul class="author-list">';
|
202 |
-
foreach( (array)$authors as $author ) {
|
203 |
-
$caps = maybe_unserialize( $author->caps );
|
204 |
-
if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
|
205 |
-
|
206 |
-
echo '<li>';
|
207 |
-
echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
|
208 |
-
echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
|
209 |
-
echo ' ' . $author->display_name . '</a>';
|
210 |
-
echo '<div class="admin-bar-clear"></div>';
|
211 |
-
echo '</li>';
|
212 |
-
}
|
213 |
-
echo '</ul>';
|
214 |
-
echo '</li>';
|
215 |
-
}
|
216 |
-
}
|
217 |
-
|
218 |
-
// **** "Random" Menu (visible when not logged in) ********
|
219 |
-
function bp_adminbar_random_menu() {
|
220 |
-
global $bp; ?>
|
221 |
-
<li class="align-right" id="bp-adminbar-visitrandom-menu">
|
222 |
-
<a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
|
223 |
-
<ul class="random-list">
|
224 |
-
<li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
|
225 |
-
|
226 |
-
<?php if ( function_exists('groups_install') ) : ?>
|
227 |
-
<li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
|
228 |
-
<?php endif; ?>
|
229 |
-
|
230 |
-
<?php if ( function_exists('bp_blogs_install') && bp_core_is_multisite() ) : ?>
|
231 |
-
<li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
|
232 |
-
|
233 |
-
<?php endif; ?>
|
234 |
-
|
235 |
-
<?php do_action( 'bp_adminbar_random_menu' ) ?>
|
236 |
-
</ul>
|
237 |
-
</li>
|
238 |
-
<?php
|
239 |
-
}
|
240 |
-
|
241 |
-
add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
|
242 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
|
243 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
|
244 |
-
|
245 |
-
if ( bp_core_is_multisite() )
|
246 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
|
247 |
-
|
248 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
|
249 |
-
|
250 |
-
if ( bp_core_is_multisite() )
|
251 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
|
252 |
-
|
253 |
-
add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
|
254 |
-
|
255 |
-
add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
|
256 |
-
add_action( 'admin_footer', 'bp_core_admin_bar' );
|
257 |
-
|
258 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function bp_core_admin_bar() {
|
4 |
+
global $bp, $wpdb, $current_blog;
|
5 |
+
|
6 |
+
if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
7 |
+
return false;
|
8 |
+
|
9 |
+
if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
|
10 |
+
return false;
|
11 |
+
|
12 |
+
$bp->doing_admin_bar = true;
|
13 |
+
|
14 |
+
echo '<div id="wp-admin-bar"><div class="padder">';
|
15 |
+
|
16 |
+
// **** Do bp-adminbar-logo Actions ********
|
17 |
+
do_action( 'bp_adminbar_logo' );
|
18 |
+
|
19 |
+
echo '<ul class="main-nav">';
|
20 |
+
|
21 |
+
// **** Do bp-adminbar-menus Actions ********
|
22 |
+
do_action( 'bp_adminbar_menus' );
|
23 |
+
|
24 |
+
echo '</ul>';
|
25 |
+
echo "</div></div><!-- #wp-admin-bar -->\n\n";
|
26 |
+
|
27 |
+
$bp->doing_admin_bar = false;
|
28 |
+
}
|
29 |
+
|
30 |
+
// **** Default BuddyPress admin bar logo ********
|
31 |
+
function bp_adminbar_logo() {
|
32 |
+
global $bp;
|
33 |
+
|
34 |
+
echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>';
|
35 |
+
}
|
36 |
+
|
37 |
+
// **** "Log In" and "Sign Up" links (Visible when not logged in) ********
|
38 |
+
function bp_adminbar_login_menu() {
|
39 |
+
global $bp;
|
40 |
+
|
41 |
+
if ( is_user_logged_in() )
|
42 |
+
return false;
|
43 |
+
|
44 |
+
echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
|
45 |
+
|
46 |
+
// Show "Sign Up" link if user registrations are allowed
|
47 |
+
if ( bp_get_signup_allowed() ) {
|
48 |
+
echo '<li class="bp-signup no-arrow"><a href="' . bp_get_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>';
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
// **** "My Account" Menu ******
|
54 |
+
function bp_adminbar_account_menu() {
|
55 |
+
global $bp;
|
56 |
+
|
57 |
+
if ( !$bp->bp_nav || !is_user_logged_in() )
|
58 |
+
return false;
|
59 |
+
|
60 |
+
echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
|
61 |
+
|
62 |
+
echo __( 'My Account', 'buddypress' ) . '</a>';
|
63 |
+
echo '<ul>';
|
64 |
+
|
65 |
+
/* Loop through each navigation item */
|
66 |
+
$counter = 0;
|
67 |
+
foreach( (array)$bp->bp_nav as $nav_item ) {
|
68 |
+
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
69 |
+
|
70 |
+
echo '<li' . $alt . '>';
|
71 |
+
echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
|
72 |
+
|
73 |
+
if ( is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
|
74 |
+
echo '<ul>';
|
75 |
+
$sub_counter = 0;
|
76 |
+
|
77 |
+
foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
|
78 |
+
$link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
|
79 |
+
$name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
|
80 |
+
$alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
|
81 |
+
echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
|
82 |
+
$sub_counter++;
|
83 |
+
}
|
84 |
+
echo '</ul>';
|
85 |
+
}
|
86 |
+
|
87 |
+
echo '</li>';
|
88 |
+
|
89 |
+
$counter++;
|
90 |
+
}
|
91 |
+
|
92 |
+
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
93 |
+
|
94 |
+
echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
|
95 |
+
echo '</ul>';
|
96 |
+
echo '</li>';
|
97 |
+
}
|
98 |
+
|
99 |
+
// *** "My Blogs" Menu ********
|
100 |
+
function bp_adminbar_blogs_menu() {
|
101 |
+
global $bp;
|
102 |
+
|
103 |
+
if ( !is_user_logged_in() || !function_exists('bp_blogs_install') )
|
104 |
+
return false;
|
105 |
+
|
106 |
+
if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
|
107 |
+
$blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
|
108 |
+
wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
|
109 |
+
}
|
110 |
+
|
111 |
+
echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/">';
|
112 |
+
|
113 |
+
_e( 'My Blogs', 'buddypress' );
|
114 |
+
|
115 |
+
echo '</a>';
|
116 |
+
echo '<ul>';
|
117 |
+
|
118 |
+
if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
|
119 |
+
$counter = 0;
|
120 |
+
foreach ( (array)$blogs['blogs'] as $blog ) {
|
121 |
+
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
122 |
+
$site_url = esc_attr( $blog->siteurl );
|
123 |
+
|
124 |
+
echo '<li' . $alt . '>';
|
125 |
+
echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
|
126 |
+
|
127 |
+
echo '<ul>';
|
128 |
+
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
|
129 |
+
echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
|
130 |
+
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
|
131 |
+
echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
|
132 |
+
echo '</ul>';
|
133 |
+
|
134 |
+
echo '</li>';
|
135 |
+
$counter++;
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
|
140 |
+
|
141 |
+
if ( bp_blog_signup_enabled() ) {
|
142 |
+
echo '<li' . $alt . '>';
|
143 |
+
echo '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create/">' . __( 'Create a Blog!', 'buddypress' ) . '</a>';
|
144 |
+
echo '</li>';
|
145 |
+
}
|
146 |
+
|
147 |
+
echo '</ul>';
|
148 |
+
echo '</li>';
|
149 |
+
}
|
150 |
+
|
151 |
+
// **** "Notifications" Menu *********
|
152 |
+
function bp_adminbar_notifications_menu() {
|
153 |
+
global $bp;
|
154 |
+
|
155 |
+
if ( !is_user_logged_in() )
|
156 |
+
return false;
|
157 |
+
|
158 |
+
echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
|
159 |
+
_e( 'Notifications', 'buddypress' );
|
160 |
+
|
161 |
+
if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
|
162 |
+
<span><?php echo count($notifications) ?></span>
|
163 |
+
<?php
|
164 |
+
}
|
165 |
+
|
166 |
+
echo '</a>';
|
167 |
+
echo '<ul>';
|
168 |
+
|
169 |
+
if ( $notifications ) { ?>
|
170 |
+
<?php $counter = 0; ?>
|
171 |
+
<?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
|
172 |
+
<?php $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
|
173 |
+
<li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
|
174 |
+
<?php $counter++; ?>
|
175 |
+
<?php } ?>
|
176 |
+
<?php } else { ?>
|
177 |
+
<li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
|
178 |
+
<?php
|
179 |
+
}
|
180 |
+
|
181 |
+
echo '</ul>';
|
182 |
+
echo '</li>';
|
183 |
+
}
|
184 |
+
|
185 |
+
// **** "Blog Authors" Menu (visible when not logged in) ********
|
186 |
+
function bp_adminbar_authors_menu() {
|
187 |
+
global $bp, $current_blog, $wpdb;
|
188 |
+
|
189 |
+
if ( $current_blog->blog_id == BP_ROOT_BLOG || !function_exists( 'bp_blogs_install' ) )
|
190 |
+
return false;
|
191 |
+
|
192 |
+
$blog_prefix = $wpdb->get_blog_prefix( $current_blog->id );
|
193 |
+
$authors = $wpdb->get_results( "SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id" );
|
194 |
+
|
195 |
+
if ( !empty( $authors ) ) {
|
196 |
+
/* This is a blog, render a menu with links to all authors */
|
197 |
+
echo '<li id="bp-adminbar-authors-menu"><a href="/">';
|
198 |
+
_e('Blog Authors', 'buddypress');
|
199 |
+
echo '</a>';
|
200 |
+
|
201 |
+
echo '<ul class="author-list">';
|
202 |
+
foreach( (array)$authors as $author ) {
|
203 |
+
$caps = maybe_unserialize( $author->caps );
|
204 |
+
if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
|
205 |
+
|
206 |
+
echo '<li>';
|
207 |
+
echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
|
208 |
+
echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
|
209 |
+
echo ' ' . $author->display_name . '</a>';
|
210 |
+
echo '<div class="admin-bar-clear"></div>';
|
211 |
+
echo '</li>';
|
212 |
+
}
|
213 |
+
echo '</ul>';
|
214 |
+
echo '</li>';
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
// **** "Random" Menu (visible when not logged in) ********
|
219 |
+
function bp_adminbar_random_menu() {
|
220 |
+
global $bp; ?>
|
221 |
+
<li class="align-right" id="bp-adminbar-visitrandom-menu">
|
222 |
+
<a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
|
223 |
+
<ul class="random-list">
|
224 |
+
<li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
|
225 |
+
|
226 |
+
<?php if ( function_exists('groups_install') ) : ?>
|
227 |
+
<li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
|
228 |
+
<?php endif; ?>
|
229 |
+
|
230 |
+
<?php if ( function_exists('bp_blogs_install') && bp_core_is_multisite() ) : ?>
|
231 |
+
<li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
|
232 |
+
|
233 |
+
<?php endif; ?>
|
234 |
+
|
235 |
+
<?php do_action( 'bp_adminbar_random_menu' ) ?>
|
236 |
+
</ul>
|
237 |
+
</li>
|
238 |
+
<?php
|
239 |
+
}
|
240 |
+
|
241 |
+
add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
|
242 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
|
243 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
|
244 |
+
|
245 |
+
if ( bp_core_is_multisite() )
|
246 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
|
247 |
+
|
248 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
|
249 |
+
|
250 |
+
if ( bp_core_is_multisite() )
|
251 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
|
252 |
+
|
253 |
+
add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
|
254 |
+
|
255 |
+
add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
|
256 |
+
add_action( 'admin_footer', 'bp_core_admin_bar' );
|
257 |
+
|
258 |
?>
|
bp-core/bp-core-avatars.php
CHANGED
@@ -1,570 +1,575 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
|
4 |
-
Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
|
5 |
-
*/
|
6 |
-
|
7 |
-
/***
|
8 |
-
* Set up the constants we need for avatar support
|
9 |
-
*/
|
10 |
-
function bp_core_set_avatar_constants() {
|
11 |
-
global $bp;
|
12 |
-
|
13 |
-
if ( !defined( 'BP_AVATAR_UPLOAD_PATH' ) )
|
14 |
-
define( 'BP_AVATAR_UPLOAD_PATH', bp_core_avatar_upload_path() );
|
15 |
-
|
16 |
-
if ( !defined( 'BP_AVATAR_URL' ) )
|
17 |
-
define( 'BP_AVATAR_URL', bp_core_avatar_url() );
|
18 |
-
|
19 |
-
if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
|
20 |
-
define( 'BP_AVATAR_THUMB_WIDTH', 50 );
|
21 |
-
|
22 |
-
if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
|
23 |
-
define( 'BP_AVATAR_THUMB_HEIGHT', 50 );
|
24 |
-
|
25 |
-
if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) )
|
26 |
-
define( 'BP_AVATAR_FULL_WIDTH', 150 );
|
27 |
-
|
28 |
-
if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) )
|
29 |
-
define( 'BP_AVATAR_FULL_HEIGHT', 150 );
|
30 |
-
|
31 |
-
if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
|
32 |
-
define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
|
33 |
-
|
34 |
-
if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
|
35 |
-
if ( !$bp->site_options['fileupload_maxk'] )
|
36 |
-
define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); /* 5mb */
|
37 |
-
else
|
38 |
-
define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
|
39 |
-
}
|
40 |
-
|
41 |
-
if ( !defined( 'BP_AVATAR_DEFAULT' ) )
|
42 |
-
define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
|
43 |
-
|
44 |
-
if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
|
45 |
-
define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
|
46 |
-
}
|
47 |
-
add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
|
48 |
-
|
49 |
-
/**
|
50 |
-
* bp_core_fetch_avatar()
|
51 |
-
*
|
52 |
-
* Fetches an avatar from a BuddyPress object. Supports user/group/blog as
|
53 |
-
* default, but can be extended to include your own custom components too.
|
54 |
-
*
|
55 |
-
* @global object $bp
|
56 |
-
* @global object $current_blog
|
57 |
-
* @param array $args Determine the output of this function
|
58 |
-
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
|
59 |
-
*/
|
60 |
-
function bp_core_fetch_avatar( $args = '' ) {
|
61 |
-
global $bp, $current_blog;
|
62 |
-
|
63 |
-
// Set a few default variables
|
64 |
-
$def_object = 'user';
|
65 |
-
$def_type = 'thumb';
|
66 |
-
$def_class = 'avatar';
|
67 |
-
$def_alt = __( 'Avatar Image', 'buddypress' );
|
68 |
-
|
69 |
-
// Set the default variables array
|
70 |
-
$defaults = array(
|
71 |
-
'item_id' => false,
|
72 |
-
'object' => $def_object, // user/group/blog/custom type (if you use filters)
|
73 |
-
'type' => $def_type, // thumb or full
|
74 |
-
'avatar_dir' => false, // Specify a custom avatar directory for your object
|
75 |
-
'width' => false, // Custom width (int)
|
76 |
-
'height' => false, // Custom height (int)
|
77 |
-
'class' => $def_class, // Custom <img> class (string)
|
78 |
-
'css_id' => false, // Custom <img> ID (string)
|
79 |
-
'alt' => $def_alt, // Custom <img> alt (string)
|
80 |
-
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
|
81 |
-
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
|
82 |
-
'html' => true // Wrap the return img URL in <img />
|
83 |
-
);
|
84 |
-
|
85 |
-
// Compare defaults to passed and extract
|
86 |
-
$params = wp_parse_args( $args, $defaults );
|
87 |
-
extract( $params, EXTR_SKIP );
|
88 |
-
|
89 |
-
// Set item_id if not passed
|
90 |
-
if ( !$item_id ) {
|
91 |
-
if ( 'user' == $object )
|
92 |
-
$item_id = $bp->displayed_user->id;
|
93 |
-
else if ( 'group' == $object )
|
94 |
-
$item_id = $bp->groups->current_group->id;
|
95 |
-
else if ( 'blog' == $object )
|
96 |
-
$item_id = $current_blog->id;
|
97 |
-
|
98 |
-
$item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
|
99 |
-
|
100 |
-
if ( !$item_id ) return false;
|
101 |
-
}
|
102 |
-
|
103 |
-
// Set avatar_dir if not passed (uses $object)
|
104 |
-
if ( !$avatar_dir ) {
|
105 |
-
if ( 'user' == $object )
|
106 |
-
$avatar_dir = 'avatars';
|
107 |
-
else if ( 'group' == $object )
|
108 |
-
$avatar_dir = 'group-avatars';
|
109 |
-
else if ( 'blog' == $object )
|
110 |
-
$avatar_dir = 'blog-avatars';
|
111 |
-
|
112 |
-
$avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
|
113 |
-
|
114 |
-
if ( !$avatar_dir ) return false;
|
115 |
-
}
|
116 |
-
|
117 |
-
// Add an identifying class to each item
|
118 |
-
$class .= ' ' . $object . '-' . $item_id . '-avatar';
|
119 |
-
|
120 |
-
// Set CSS ID if passed
|
121 |
-
if ( !empty( $css_id ) )
|
122 |
-
$css_id = " id='{$css_id}'";
|
123 |
-
|
124 |
-
// Set avatar width
|
125 |
-
if ( $width )
|
126 |
-
$html_width = " width='{$width}'";
|
127 |
-
else
|
128 |
-
$html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
|
129 |
-
|
130 |
-
// Set avatar height
|
131 |
-
if ( $height )
|
132 |
-
$html_height = " height='{$height}'";
|
133 |
-
else
|
134 |
-
$html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
|
135 |
-
|
136 |
-
// Set avatar URL and DIR based on prepopulated constants
|
137 |
-
$avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', BP_AVATAR_URL . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
138 |
-
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
139 |
-
|
140 |
-
/****
|
141 |
-
* Look for uploaded avatar first. Use it if it exists.
|
142 |
-
* Set the file names to search for, to select the full size
|
143 |
-
* or thumbnail image.
|
144 |
-
*/
|
145 |
-
$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
|
146 |
-
$legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
|
147 |
-
$legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
|
148 |
-
|
149 |
-
// Check for directory
|
150 |
-
if ( file_exists( $avatar_folder_dir ) ) {
|
151 |
-
|
152 |
-
// Open directory
|
153 |
-
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
154 |
-
|
155 |
-
// Stash files in an array once to check for one that matches
|
156 |
-
$avatar_files = array();
|
157 |
-
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
158 |
-
// Only add files to the array (skip directories)
|
159 |
-
if ( 2 < strlen( $avatar_file ) )
|
160 |
-
$avatar_files[] = $avatar_file;
|
161 |
-
}
|
162 |
-
|
163 |
-
// Check for array
|
164 |
-
if ( 0 < count( $avatar_files ) ) {
|
165 |
-
|
166 |
-
// Check for current avatar
|
167 |
-
foreach( $avatar_files as $key => $value ) {
|
168 |
-
if ( strpos ( $value, $avatar_size )!== false )
|
169 |
-
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
170 |
-
}
|
171 |
-
|
172 |
-
// Legacy avatar check
|
173 |
-
if ( !isset( $avatar_url ) ) {
|
174 |
-
foreach( $avatar_files as $key => $value ) {
|
175 |
-
if ( strpos ( $value, $legacy_user_avatar_name )!== false )
|
176 |
-
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
177 |
-
}
|
178 |
-
|
179 |
-
// Legacy group avatar check
|
180 |
-
if ( !isset( $avatar_url ) ) {
|
181 |
-
foreach( $avatar_files as $key => $value ) {
|
182 |
-
if ( strpos ( $value, $legacy_group_avatar_name )!== false )
|
183 |
-
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
184 |
-
}
|
185 |
-
}
|
186 |
-
}
|
187 |
-
}
|
188 |
-
}
|
189 |
-
|
190 |
-
// Close the avatar directory
|
191 |
-
closedir( $av_dir );
|
192 |
-
|
193 |
-
// If we found a locally uploaded avatar
|
194 |
-
if ( $avatar_url ) {
|
195 |
-
|
196 |
-
// Return it wrapped in an <img> element
|
197 |
-
if ( true === $html ) {
|
198 |
-
return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
199 |
-
|
200 |
-
// ...or only the URL
|
201 |
-
} else {
|
202 |
-
return apply_filters( 'bp_core_fetch_avatar_url', $avatar_url );
|
203 |
-
}
|
204 |
-
}
|
205 |
-
}
|
206 |
-
|
207 |
-
// If no avatars could be found, try to display a gravatar
|
208 |
-
|
209 |
-
// Skips gravatar check if $no_grav is passed
|
210 |
-
if ( !$no_grav ) {
|
211 |
-
|
212 |
-
// Set gravatar size
|
213 |
-
if ( $width )
|
214 |
-
$grav_size = $width;
|
215 |
-
else if ( 'full' == $type )
|
216 |
-
$grav_size = BP_AVATAR_FULL_WIDTH;
|
217 |
-
else if ( 'thumb' == $type )
|
218 |
-
$grav_size = BP_AVATAR_THUMB_WIDTH;
|
219 |
-
|
220 |
-
// Set gravatar type
|
221 |
-
if ( empty( $bp->grav_default->{$object} ) )
|
222 |
-
$default_grav = 'wavatar';
|
223 |
-
else if ( 'mystery' == $bp->grav_default->{$object} )
|
224 |
-
$default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
|
225 |
-
else
|
226 |
-
$default_grav = $bp->grav_default->{$object};
|
227 |
-
|
228 |
-
// Set gravatar object
|
229 |
-
if ( empty( $email ) ) {
|
230 |
-
if ( 'user' == $object ) {
|
231 |
-
$email = bp_core_get_user_email( $item_id );
|
232 |
-
} else if ( 'group' == $object || 'blog' == $object ) {
|
233 |
-
$email = "{$item_id}-{$object}@{$bp->root_domain}";
|
234 |
-
}
|
235 |
-
}
|
236 |
-
|
237 |
-
// Set host based on if using ssl
|
238 |
-
if ( is_ssl() )
|
239 |
-
$host = 'https://secure.gravatar.com/avatar/';
|
240 |
-
else
|
241 |
-
$host = 'http://www.gravatar.com/avatar/';
|
242 |
-
|
243 |
-
// Filter gravatar vars
|
244 |
-
$email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
|
245 |
-
$gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&s=' . $grav_size;
|
246 |
-
|
247 |
-
// Return gravatar wrapped in <img />
|
248 |
-
if ( true === $html )
|
249 |
-
return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
250 |
-
|
251 |
-
// ...or only return the gravatar URL
|
252 |
-
else
|
253 |
-
return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
|
254 |
-
|
255 |
-
} else {
|
256 |
-
return apply_filters( 'bp_core_fetch_avatar', false, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
257 |
-
}
|
258 |
-
}
|
259 |
-
|
260 |
-
function bp_core_delete_existing_avatar( $args = '' ) {
|
261 |
-
global $bp;
|
262 |
-
|
263 |
-
$defaults = array(
|
264 |
-
'item_id' => false,
|
265 |
-
'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
|
266 |
-
'avatar_dir' => false
|
267 |
-
);
|
268 |
-
|
269 |
-
$args = wp_parse_args( $args, $defaults );
|
270 |
-
extract( $args, EXTR_SKIP );
|
271 |
-
|
272 |
-
if ( !$item_id ) {
|
273 |
-
if ( 'user' == $object )
|
274 |
-
$item_id = $bp->displayed_user->id;
|
275 |
-
else if ( 'group' == $object )
|
276 |
-
$item_id = $bp->groups->current_group->id;
|
277 |
-
else if ( 'blog' == $object )
|
278 |
-
$item_id = $current_blog->id;
|
279 |
-
|
280 |
-
$item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
|
281 |
-
|
282 |
-
if ( !$item_id ) return false;
|
283 |
-
}
|
284 |
-
|
285 |
-
if ( !$avatar_dir ) {
|
286 |
-
if ( 'user' == $object )
|
287 |
-
$avatar_dir = 'avatars';
|
288 |
-
else if ( 'group' == $object )
|
289 |
-
$avatar_dir = 'group-avatars';
|
290 |
-
else if ( 'blog' == $object )
|
291 |
-
$avatar_dir = 'blog-avatars';
|
292 |
-
|
293 |
-
$avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
|
294 |
-
|
295 |
-
if ( !$avatar_dir ) return false;
|
296 |
-
}
|
297 |
-
|
298 |
-
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
299 |
-
|
300 |
-
if ( !file_exists( $avatar_folder_dir ) )
|
301 |
-
return false;
|
302 |
-
|
303 |
-
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
304 |
-
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
305 |
-
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
306 |
-
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
307 |
-
}
|
308 |
-
}
|
309 |
-
closedir($av_dir);
|
310 |
-
|
311 |
-
@rmdir( $avatar_folder_dir );
|
312 |
-
|
313 |
-
do_action( 'bp_core_delete_existing_avatar', $args );
|
314 |
-
|
315 |
-
return true;
|
316 |
-
}
|
317 |
-
|
318 |
-
function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
|
319 |
-
global $bp;
|
320 |
-
|
321 |
-
/***
|
322 |
-
* You may want to hook into this filter if you want to override this function.
|
323 |
-
* Make sure you return false.
|
324 |
-
*/
|
325 |
-
if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) )
|
326 |
-
return true;
|
327 |
-
|
328 |
-
require_once( ABSPATH . '/wp-admin/includes/image.php' );
|
329 |
-
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
330 |
-
|
331 |
-
$uploadErrors = array(
|
332 |
-
0 => __("There is no error, the file uploaded with success", 'buddypress'),
|
333 |
-
1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
|
334 |
-
2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
|
335 |
-
3 => __("The uploaded file was only partially uploaded", 'buddypress'),
|
336 |
-
4 => __("No file was uploaded", 'buddypress'),
|
337 |
-
6 => __("Missing a temporary folder", 'buddypress')
|
338 |
-
);
|
339 |
-
|
340 |
-
if ( !bp_core_check_avatar_upload( $file ) ) {
|
341 |
-
bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' );
|
342 |
-
return false;
|
343 |
-
}
|
344 |
-
|
345 |
-
if ( !bp_core_check_avatar_size( $file ) ) {
|
346 |
-
bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
|
347 |
-
return false;
|
348 |
-
}
|
349 |
-
|
350 |
-
if ( !bp_core_check_avatar_type( $file ) ) {
|
351 |
-
bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
|
352 |
-
return false;
|
353 |
-
}
|
354 |
-
|
355 |
-
/* Filter the upload location */
|
356 |
-
add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
|
357 |
-
|
358 |
-
$bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
|
359 |
-
|
360 |
-
/* Move the file to the correct upload location. */
|
361 |
-
if ( !empty( $bp->avatar_admin->original['error'] ) ) {
|
362 |
-
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
|
363 |
-
return false;
|
364 |
-
}
|
365 |
-
|
366 |
-
/* Get image size */
|
367 |
-
$size = @getimagesize( $bp->avatar_admin->original['file'] );
|
368 |
-
|
369 |
-
/* Check image size and shrink if too large */
|
370 |
-
if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
|
371 |
-
$thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
|
372 |
-
|
373 |
-
/* Check for thumbnail creation errors */
|
374 |
-
if ( is_wp_error( $thumb ) ) {
|
375 |
-
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
|
376 |
-
return false;
|
377 |
-
}
|
378 |
-
|
379 |
-
/* Thumbnail is good so proceed */
|
380 |
-
$bp->avatar_admin->resized = $thumb;
|
381 |
-
}
|
382 |
-
|
383 |
-
/* We only want to handle one image after resize. */
|
384 |
-
if ( empty( $bp->avatar_admin->resized ) )
|
385 |
-
$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
|
386 |
-
else {
|
387 |
-
$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
|
388 |
-
@unlink( $bp->avatar_admin->original['file'] );
|
389 |
-
}
|
390 |
-
|
391 |
-
/* Set the url value for the image */
|
392 |
-
$bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
|
393 |
-
|
394 |
-
return true;
|
395 |
-
}
|
396 |
-
|
397 |
-
function bp_core_avatar_handle_crop( $args = '' ) {
|
398 |
-
global $bp;
|
399 |
-
|
400 |
-
$defaults = array(
|
401 |
-
'object' => 'user',
|
402 |
-
'avatar_dir' => 'avatars',
|
403 |
-
'item_id' => false,
|
404 |
-
'original_file' => false,
|
405 |
-
'crop_w' => BP_AVATAR_FULL_WIDTH,
|
406 |
-
'crop_h' => BP_AVATAR_FULL_HEIGHT,
|
407 |
-
'crop_x' => 0,
|
408 |
-
'crop_y' => 0
|
409 |
-
);
|
410 |
-
|
411 |
-
$r = wp_parse_args( $args, $defaults );
|
412 |
-
|
413 |
-
/***
|
414 |
-
* You may want to hook into this filter if you want to override this function.
|
415 |
-
* Make sure you return false.
|
416 |
-
*/
|
417 |
-
if ( !apply_filters( 'bp_core_pre_avatar_handle_crop', true, $r ) )
|
418 |
-
return true;
|
419 |
-
|
420 |
-
extract( $r, EXTR_SKIP );
|
421 |
-
|
422 |
-
if ( !$original_file )
|
423 |
-
return false;
|
424 |
-
|
425 |
-
$original_file = BP_AVATAR_UPLOAD_PATH . $original_file;
|
426 |
-
|
427 |
-
if ( !file_exists( $original_file ) )
|
428 |
-
return false;
|
429 |
-
|
430 |
-
if ( !$item_id )
|
431 |
-
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
|
432 |
-
else
|
433 |
-
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
434 |
-
|
435 |
-
if ( !file_exists( $avatar_folder_dir ) )
|
436 |
-
return false;
|
437 |
-
|
438 |
-
require_once( ABSPATH . '/wp-admin/includes/image.php' );
|
439 |
-
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
440 |
-
|
441 |
-
/* Delete the existing avatar files for the object */
|
442 |
-
bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
|
443 |
-
|
444 |
-
/* Make sure we at least have a width and height for cropping */
|
445 |
-
if ( !(int)$crop_w )
|
446 |
-
$crop_w = BP_AVATAR_FULL_WIDTH;
|
447 |
-
|
448 |
-
if ( !(int)$crop_h )
|
449 |
-
$crop_h = BP_AVATAR_FULL_HEIGHT;
|
450 |
-
|
451 |
-
/* Set the full and thumb filenames */
|
452 |
-
$full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
|
453 |
-
$thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
|
454 |
-
|
455 |
-
/* Crop the image */
|
456 |
-
$full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
|
457 |
-
$thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
|
458 |
-
|
459 |
-
/* Remove the original */
|
460 |
-
@unlink( $original_file );
|
461 |
-
|
462 |
-
return true;
|
463 |
-
}
|
464 |
-
|
465 |
-
/**
|
466 |
-
* bp_core_fetch_avatar_filter()
|
467 |
-
*
|
468 |
-
* Attempts to filter get_avatar function and let BuddyPress have a go
|
469 |
-
* at finding an avatar that may have been uploaded locally.
|
470 |
-
*
|
471 |
-
* @global array $authordata
|
472 |
-
* @param string $avatar The result of get_avatar from before-filter
|
473 |
-
* @param int|string|object $user A user ID, email address, or comment object
|
474 |
-
* @param int $size Size of the avatar image (thumb/full)
|
475 |
-
* @param string $default URL to a default image to use if no avatar is available
|
476 |
-
* @param string $alt Alternate text to use in image tag. Defaults to blank
|
477 |
-
* @return <type>
|
478 |
-
*/
|
479 |
-
function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
|
480 |
-
|
481 |
-
|
482 |
-
if
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
*
|
533 |
-
*
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
*
|
555 |
-
*
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
|
|
|
|
|
|
|
|
|
|
570 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
|
4 |
+
Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
|
5 |
+
*/
|
6 |
+
|
7 |
+
/***
|
8 |
+
* Set up the constants we need for avatar support
|
9 |
+
*/
|
10 |
+
function bp_core_set_avatar_constants() {
|
11 |
+
global $bp;
|
12 |
+
|
13 |
+
if ( !defined( 'BP_AVATAR_UPLOAD_PATH' ) )
|
14 |
+
define( 'BP_AVATAR_UPLOAD_PATH', bp_core_avatar_upload_path() );
|
15 |
+
|
16 |
+
if ( !defined( 'BP_AVATAR_URL' ) )
|
17 |
+
define( 'BP_AVATAR_URL', bp_core_avatar_url() );
|
18 |
+
|
19 |
+
if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
|
20 |
+
define( 'BP_AVATAR_THUMB_WIDTH', 50 );
|
21 |
+
|
22 |
+
if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
|
23 |
+
define( 'BP_AVATAR_THUMB_HEIGHT', 50 );
|
24 |
+
|
25 |
+
if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) )
|
26 |
+
define( 'BP_AVATAR_FULL_WIDTH', 150 );
|
27 |
+
|
28 |
+
if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) )
|
29 |
+
define( 'BP_AVATAR_FULL_HEIGHT', 150 );
|
30 |
+
|
31 |
+
if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
|
32 |
+
define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
|
33 |
+
|
34 |
+
if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
|
35 |
+
if ( !$bp->site_options['fileupload_maxk'] )
|
36 |
+
define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); /* 5mb */
|
37 |
+
else
|
38 |
+
define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( !defined( 'BP_AVATAR_DEFAULT' ) )
|
42 |
+
define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
|
43 |
+
|
44 |
+
if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
|
45 |
+
define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
|
46 |
+
}
|
47 |
+
add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
|
48 |
+
|
49 |
+
/**
|
50 |
+
* bp_core_fetch_avatar()
|
51 |
+
*
|
52 |
+
* Fetches an avatar from a BuddyPress object. Supports user/group/blog as
|
53 |
+
* default, but can be extended to include your own custom components too.
|
54 |
+
*
|
55 |
+
* @global object $bp
|
56 |
+
* @global object $current_blog
|
57 |
+
* @param array $args Determine the output of this function
|
58 |
+
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
|
59 |
+
*/
|
60 |
+
function bp_core_fetch_avatar( $args = '' ) {
|
61 |
+
global $bp, $current_blog;
|
62 |
+
|
63 |
+
// Set a few default variables
|
64 |
+
$def_object = 'user';
|
65 |
+
$def_type = 'thumb';
|
66 |
+
$def_class = 'avatar';
|
67 |
+
$def_alt = __( 'Avatar Image', 'buddypress' );
|
68 |
+
|
69 |
+
// Set the default variables array
|
70 |
+
$defaults = array(
|
71 |
+
'item_id' => false,
|
72 |
+
'object' => $def_object, // user/group/blog/custom type (if you use filters)
|
73 |
+
'type' => $def_type, // thumb or full
|
74 |
+
'avatar_dir' => false, // Specify a custom avatar directory for your object
|
75 |
+
'width' => false, // Custom width (int)
|
76 |
+
'height' => false, // Custom height (int)
|
77 |
+
'class' => $def_class, // Custom <img> class (string)
|
78 |
+
'css_id' => false, // Custom <img> ID (string)
|
79 |
+
'alt' => $def_alt, // Custom <img> alt (string)
|
80 |
+
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
|
81 |
+
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
|
82 |
+
'html' => true // Wrap the return img URL in <img />
|
83 |
+
);
|
84 |
+
|
85 |
+
// Compare defaults to passed and extract
|
86 |
+
$params = wp_parse_args( $args, $defaults );
|
87 |
+
extract( $params, EXTR_SKIP );
|
88 |
+
|
89 |
+
// Set item_id if not passed
|
90 |
+
if ( !$item_id ) {
|
91 |
+
if ( 'user' == $object )
|
92 |
+
$item_id = $bp->displayed_user->id;
|
93 |
+
else if ( 'group' == $object )
|
94 |
+
$item_id = $bp->groups->current_group->id;
|
95 |
+
else if ( 'blog' == $object )
|
96 |
+
$item_id = $current_blog->id;
|
97 |
+
|
98 |
+
$item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
|
99 |
+
|
100 |
+
if ( !$item_id ) return false;
|
101 |
+
}
|
102 |
+
|
103 |
+
// Set avatar_dir if not passed (uses $object)
|
104 |
+
if ( !$avatar_dir ) {
|
105 |
+
if ( 'user' == $object )
|
106 |
+
$avatar_dir = 'avatars';
|
107 |
+
else if ( 'group' == $object )
|
108 |
+
$avatar_dir = 'group-avatars';
|
109 |
+
else if ( 'blog' == $object )
|
110 |
+
$avatar_dir = 'blog-avatars';
|
111 |
+
|
112 |
+
$avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
|
113 |
+
|
114 |
+
if ( !$avatar_dir ) return false;
|
115 |
+
}
|
116 |
+
|
117 |
+
// Add an identifying class to each item
|
118 |
+
$class .= ' ' . $object . '-' . $item_id . '-avatar';
|
119 |
+
|
120 |
+
// Set CSS ID if passed
|
121 |
+
if ( !empty( $css_id ) )
|
122 |
+
$css_id = " id='{$css_id}'";
|
123 |
+
|
124 |
+
// Set avatar width
|
125 |
+
if ( $width )
|
126 |
+
$html_width = " width='{$width}'";
|
127 |
+
else
|
128 |
+
$html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
|
129 |
+
|
130 |
+
// Set avatar height
|
131 |
+
if ( $height )
|
132 |
+
$html_height = " height='{$height}'";
|
133 |
+
else
|
134 |
+
$html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
|
135 |
+
|
136 |
+
// Set avatar URL and DIR based on prepopulated constants
|
137 |
+
$avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', BP_AVATAR_URL . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
138 |
+
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
139 |
+
|
140 |
+
/****
|
141 |
+
* Look for uploaded avatar first. Use it if it exists.
|
142 |
+
* Set the file names to search for, to select the full size
|
143 |
+
* or thumbnail image.
|
144 |
+
*/
|
145 |
+
$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
|
146 |
+
$legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
|
147 |
+
$legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
|
148 |
+
|
149 |
+
// Check for directory
|
150 |
+
if ( file_exists( $avatar_folder_dir ) ) {
|
151 |
+
|
152 |
+
// Open directory
|
153 |
+
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
154 |
+
|
155 |
+
// Stash files in an array once to check for one that matches
|
156 |
+
$avatar_files = array();
|
157 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
158 |
+
// Only add files to the array (skip directories)
|
159 |
+
if ( 2 < strlen( $avatar_file ) )
|
160 |
+
$avatar_files[] = $avatar_file;
|
161 |
+
}
|
162 |
+
|
163 |
+
// Check for array
|
164 |
+
if ( 0 < count( $avatar_files ) ) {
|
165 |
+
|
166 |
+
// Check for current avatar
|
167 |
+
foreach( $avatar_files as $key => $value ) {
|
168 |
+
if ( strpos ( $value, $avatar_size )!== false )
|
169 |
+
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
170 |
+
}
|
171 |
+
|
172 |
+
// Legacy avatar check
|
173 |
+
if ( !isset( $avatar_url ) ) {
|
174 |
+
foreach( $avatar_files as $key => $value ) {
|
175 |
+
if ( strpos ( $value, $legacy_user_avatar_name )!== false )
|
176 |
+
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
177 |
+
}
|
178 |
+
|
179 |
+
// Legacy group avatar check
|
180 |
+
if ( !isset( $avatar_url ) ) {
|
181 |
+
foreach( $avatar_files as $key => $value ) {
|
182 |
+
if ( strpos ( $value, $legacy_group_avatar_name )!== false )
|
183 |
+
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
// Close the avatar directory
|
191 |
+
closedir( $av_dir );
|
192 |
+
|
193 |
+
// If we found a locally uploaded avatar
|
194 |
+
if ( $avatar_url ) {
|
195 |
+
|
196 |
+
// Return it wrapped in an <img> element
|
197 |
+
if ( true === $html ) {
|
198 |
+
return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
199 |
+
|
200 |
+
// ...or only the URL
|
201 |
+
} else {
|
202 |
+
return apply_filters( 'bp_core_fetch_avatar_url', $avatar_url );
|
203 |
+
}
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
// If no avatars could be found, try to display a gravatar
|
208 |
+
|
209 |
+
// Skips gravatar check if $no_grav is passed
|
210 |
+
if ( !$no_grav ) {
|
211 |
+
|
212 |
+
// Set gravatar size
|
213 |
+
if ( $width )
|
214 |
+
$grav_size = $width;
|
215 |
+
else if ( 'full' == $type )
|
216 |
+
$grav_size = BP_AVATAR_FULL_WIDTH;
|
217 |
+
else if ( 'thumb' == $type )
|
218 |
+
$grav_size = BP_AVATAR_THUMB_WIDTH;
|
219 |
+
|
220 |
+
// Set gravatar type
|
221 |
+
if ( empty( $bp->grav_default->{$object} ) )
|
222 |
+
$default_grav = 'wavatar';
|
223 |
+
else if ( 'mystery' == $bp->grav_default->{$object} )
|
224 |
+
$default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
|
225 |
+
else
|
226 |
+
$default_grav = $bp->grav_default->{$object};
|
227 |
+
|
228 |
+
// Set gravatar object
|
229 |
+
if ( empty( $email ) ) {
|
230 |
+
if ( 'user' == $object ) {
|
231 |
+
$email = bp_core_get_user_email( $item_id );
|
232 |
+
} else if ( 'group' == $object || 'blog' == $object ) {
|
233 |
+
$email = "{$item_id}-{$object}@{$bp->root_domain}";
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
// Set host based on if using ssl
|
238 |
+
if ( is_ssl() )
|
239 |
+
$host = 'https://secure.gravatar.com/avatar/';
|
240 |
+
else
|
241 |
+
$host = 'http://www.gravatar.com/avatar/';
|
242 |
+
|
243 |
+
// Filter gravatar vars
|
244 |
+
$email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
|
245 |
+
$gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&s=' . $grav_size;
|
246 |
+
|
247 |
+
// Return gravatar wrapped in <img />
|
248 |
+
if ( true === $html )
|
249 |
+
return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
250 |
+
|
251 |
+
// ...or only return the gravatar URL
|
252 |
+
else
|
253 |
+
return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
|
254 |
+
|
255 |
+
} else {
|
256 |
+
return apply_filters( 'bp_core_fetch_avatar', false, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
function bp_core_delete_existing_avatar( $args = '' ) {
|
261 |
+
global $bp;
|
262 |
+
|
263 |
+
$defaults = array(
|
264 |
+
'item_id' => false,
|
265 |
+
'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
|
266 |
+
'avatar_dir' => false
|
267 |
+
);
|
268 |
+
|
269 |
+
$args = wp_parse_args( $args, $defaults );
|
270 |
+
extract( $args, EXTR_SKIP );
|
271 |
+
|
272 |
+
if ( !$item_id ) {
|
273 |
+
if ( 'user' == $object )
|
274 |
+
$item_id = $bp->displayed_user->id;
|
275 |
+
else if ( 'group' == $object )
|
276 |
+
$item_id = $bp->groups->current_group->id;
|
277 |
+
else if ( 'blog' == $object )
|
278 |
+
$item_id = $current_blog->id;
|
279 |
+
|
280 |
+
$item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
|
281 |
+
|
282 |
+
if ( !$item_id ) return false;
|
283 |
+
}
|
284 |
+
|
285 |
+
if ( !$avatar_dir ) {
|
286 |
+
if ( 'user' == $object )
|
287 |
+
$avatar_dir = 'avatars';
|
288 |
+
else if ( 'group' == $object )
|
289 |
+
$avatar_dir = 'group-avatars';
|
290 |
+
else if ( 'blog' == $object )
|
291 |
+
$avatar_dir = 'blog-avatars';
|
292 |
+
|
293 |
+
$avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
|
294 |
+
|
295 |
+
if ( !$avatar_dir ) return false;
|
296 |
+
}
|
297 |
+
|
298 |
+
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
299 |
+
|
300 |
+
if ( !file_exists( $avatar_folder_dir ) )
|
301 |
+
return false;
|
302 |
+
|
303 |
+
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
304 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
305 |
+
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
306 |
+
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
307 |
+
}
|
308 |
+
}
|
309 |
+
closedir($av_dir);
|
310 |
+
|
311 |
+
@rmdir( $avatar_folder_dir );
|
312 |
+
|
313 |
+
do_action( 'bp_core_delete_existing_avatar', $args );
|
314 |
+
|
315 |
+
return true;
|
316 |
+
}
|
317 |
+
|
318 |
+
function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
|
319 |
+
global $bp;
|
320 |
+
|
321 |
+
/***
|
322 |
+
* You may want to hook into this filter if you want to override this function.
|
323 |
+
* Make sure you return false.
|
324 |
+
*/
|
325 |
+
if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) )
|
326 |
+
return true;
|
327 |
+
|
328 |
+
require_once( ABSPATH . '/wp-admin/includes/image.php' );
|
329 |
+
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
330 |
+
|
331 |
+
$uploadErrors = array(
|
332 |
+
0 => __("There is no error, the file uploaded with success", 'buddypress'),
|
333 |
+
1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
|
334 |
+
2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
|
335 |
+
3 => __("The uploaded file was only partially uploaded", 'buddypress'),
|
336 |
+
4 => __("No file was uploaded", 'buddypress'),
|
337 |
+
6 => __("Missing a temporary folder", 'buddypress')
|
338 |
+
);
|
339 |
+
|
340 |
+
if ( !bp_core_check_avatar_upload( $file ) ) {
|
341 |
+
bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' );
|
342 |
+
return false;
|
343 |
+
}
|
344 |
+
|
345 |
+
if ( !bp_core_check_avatar_size( $file ) ) {
|
346 |
+
bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
|
347 |
+
return false;
|
348 |
+
}
|
349 |
+
|
350 |
+
if ( !bp_core_check_avatar_type( $file ) ) {
|
351 |
+
bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
|
352 |
+
return false;
|
353 |
+
}
|
354 |
+
|
355 |
+
/* Filter the upload location */
|
356 |
+
add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
|
357 |
+
|
358 |
+
$bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
|
359 |
+
|
360 |
+
/* Move the file to the correct upload location. */
|
361 |
+
if ( !empty( $bp->avatar_admin->original['error'] ) ) {
|
362 |
+
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
|
363 |
+
return false;
|
364 |
+
}
|
365 |
+
|
366 |
+
/* Get image size */
|
367 |
+
$size = @getimagesize( $bp->avatar_admin->original['file'] );
|
368 |
+
|
369 |
+
/* Check image size and shrink if too large */
|
370 |
+
if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
|
371 |
+
$thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
|
372 |
+
|
373 |
+
/* Check for thumbnail creation errors */
|
374 |
+
if ( is_wp_error( $thumb ) ) {
|
375 |
+
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
|
376 |
+
return false;
|
377 |
+
}
|
378 |
+
|
379 |
+
/* Thumbnail is good so proceed */
|
380 |
+
$bp->avatar_admin->resized = $thumb;
|
381 |
+
}
|
382 |
+
|
383 |
+
/* We only want to handle one image after resize. */
|
384 |
+
if ( empty( $bp->avatar_admin->resized ) )
|
385 |
+
$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
|
386 |
+
else {
|
387 |
+
$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
|
388 |
+
@unlink( $bp->avatar_admin->original['file'] );
|
389 |
+
}
|
390 |
+
|
391 |
+
/* Set the url value for the image */
|
392 |
+
$bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
|
393 |
+
|
394 |
+
return true;
|
395 |
+
}
|
396 |
+
|
397 |
+
function bp_core_avatar_handle_crop( $args = '' ) {
|
398 |
+
global $bp;
|
399 |
+
|
400 |
+
$defaults = array(
|
401 |
+
'object' => 'user',
|
402 |
+
'avatar_dir' => 'avatars',
|
403 |
+
'item_id' => false,
|
404 |
+
'original_file' => false,
|
405 |
+
'crop_w' => BP_AVATAR_FULL_WIDTH,
|
406 |
+
'crop_h' => BP_AVATAR_FULL_HEIGHT,
|
407 |
+
'crop_x' => 0,
|
408 |
+
'crop_y' => 0
|
409 |
+
);
|
410 |
+
|
411 |
+
$r = wp_parse_args( $args, $defaults );
|
412 |
+
|
413 |
+
/***
|
414 |
+
* You may want to hook into this filter if you want to override this function.
|
415 |
+
* Make sure you return false.
|
416 |
+
*/
|
417 |
+
if ( !apply_filters( 'bp_core_pre_avatar_handle_crop', true, $r ) )
|
418 |
+
return true;
|
419 |
+
|
420 |
+
extract( $r, EXTR_SKIP );
|
421 |
+
|
422 |
+
if ( !$original_file )
|
423 |
+
return false;
|
424 |
+
|
425 |
+
$original_file = BP_AVATAR_UPLOAD_PATH . $original_file;
|
426 |
+
|
427 |
+
if ( !file_exists( $original_file ) )
|
428 |
+
return false;
|
429 |
+
|
430 |
+
if ( !$item_id )
|
431 |
+
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
|
432 |
+
else
|
433 |
+
$avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
|
434 |
+
|
435 |
+
if ( !file_exists( $avatar_folder_dir ) )
|
436 |
+
return false;
|
437 |
+
|
438 |
+
require_once( ABSPATH . '/wp-admin/includes/image.php' );
|
439 |
+
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
440 |
+
|
441 |
+
/* Delete the existing avatar files for the object */
|
442 |
+
bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
|
443 |
+
|
444 |
+
/* Make sure we at least have a width and height for cropping */
|
445 |
+
if ( !(int)$crop_w )
|
446 |
+
$crop_w = BP_AVATAR_FULL_WIDTH;
|
447 |
+
|
448 |
+
if ( !(int)$crop_h )
|
449 |
+
$crop_h = BP_AVATAR_FULL_HEIGHT;
|
450 |
+
|
451 |
+
/* Set the full and thumb filenames */
|
452 |
+
$full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
|
453 |
+
$thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
|
454 |
+
|
455 |
+
/* Crop the image */
|
456 |
+
$full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
|
457 |
+
$thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
|
458 |
+
|
459 |
+
/* Remove the original */
|
460 |
+
@unlink( $original_file );
|
461 |
+
|
462 |
+
return true;
|
463 |
+
}
|
464 |
+
|
465 |
+
/**
|
466 |
+
* bp_core_fetch_avatar_filter()
|
467 |
+
*
|
468 |
+
* Attempts to filter get_avatar function and let BuddyPress have a go
|
469 |
+
* at finding an avatar that may have been uploaded locally.
|
470 |
+
*
|
471 |
+
* @global array $authordata
|
472 |
+
* @param string $avatar The result of get_avatar from before-filter
|
473 |
+
* @param int|string|object $user A user ID, email address, or comment object
|
474 |
+
* @param int $size Size of the avatar image (thumb/full)
|
475 |
+
* @param string $default URL to a default image to use if no avatar is available
|
476 |
+
* @param string $alt Alternate text to use in image tag. Defaults to blank
|
477 |
+
* @return <type>
|
478 |
+
*/
|
479 |
+
function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
|
480 |
+
global $pagenow;
|
481 |
+
|
482 |
+
// Do not filter if inside WordPress options page
|
483 |
+
if ( 'options-discussion.php' == $pagenow )
|
484 |
+
return $avatar;
|
485 |
+
|
486 |
+
// If passed an object, assume $user->user_id
|
487 |
+
if ( is_object( $user ) )
|
488 |
+
$id = $user->user_id;
|
489 |
+
|
490 |
+
// If passed a number, assume it was a $user_id
|
491 |
+
else if ( is_numeric( $user ) )
|
492 |
+
$id = $user;
|
493 |
+
|
494 |
+
// If passed a string and that string returns a user, get the $id
|
495 |
+
else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
|
496 |
+
$id = $user_by_email->ID;
|
497 |
+
|
498 |
+
// If somehow $id hasn't been assigned, return the result of get_avatar
|
499 |
+
if ( empty( $id ) )
|
500 |
+
return !empty( $avatar ) ? $avatar : $default;
|
501 |
+
|
502 |
+
// Let BuddyPress handle the fetching of the avatar
|
503 |
+
$bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
|
504 |
+
|
505 |
+
// If BuddyPress found an avatar, use it. If not, use the result of get_avatar
|
506 |
+
return ( !$bp_avatar ) ? $avatar : $bp_avatar;
|
507 |
+
}
|
508 |
+
add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
|
509 |
+
|
510 |
+
function bp_core_check_avatar_upload($file) {
|
511 |
+
if ( $file['error'] )
|
512 |
+
return false;
|
513 |
+
|
514 |
+
return true;
|
515 |
+
}
|
516 |
+
|
517 |
+
function bp_core_check_avatar_size($file) {
|
518 |
+
if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
|
519 |
+
return false;
|
520 |
+
|
521 |
+
return true;
|
522 |
+
}
|
523 |
+
|
524 |
+
function bp_core_check_avatar_type($file) {
|
525 |
+
if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
|
526 |
+
return false;
|
527 |
+
|
528 |
+
return true;
|
529 |
+
}
|
530 |
+
|
531 |
+
/**
|
532 |
+
* bp_core_avatar_upload_path()
|
533 |
+
*
|
534 |
+
* Returns the absolute upload path for the WP installation
|
535 |
+
*
|
536 |
+
* @global object $current_blog Current blog information
|
537 |
+
* @uses wp_upload_dir To get upload directory info
|
538 |
+
* @return string Absolute path to WP upload directory
|
539 |
+
*/
|
540 |
+
function bp_core_avatar_upload_path() {
|
541 |
+
global $current_blog;
|
542 |
+
|
543 |
+
// Get upload directory information from current site
|
544 |
+
$upload_dir = wp_upload_dir();
|
545 |
+
|
546 |
+
// If multisite, and current blog does not match root blog, make adjustments
|
547 |
+
if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
|
548 |
+
$upload_dir['basedir'] = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
|
549 |
+
|
550 |
+
return apply_filters( 'bp_core_avatar_upload_path', $upload_dir['basedir'] );
|
551 |
+
}
|
552 |
+
|
553 |
+
/**
|
554 |
+
* bp_core_avatar_url()
|
555 |
+
*
|
556 |
+
* Returns the raw base URL for root site upload location
|
557 |
+
*
|
558 |
+
* @global object $current_blog Current blog information
|
559 |
+
* @uses wp_upload_dir To get upload directory info
|
560 |
+
* @return string Full URL to current upload location
|
561 |
+
*/
|
562 |
+
function bp_core_avatar_url() {
|
563 |
+
global $current_blog;
|
564 |
+
|
565 |
+
// Get upload directory information from current site
|
566 |
+
$upload_dir = wp_upload_dir();
|
567 |
+
|
568 |
+
// If multisite, and current blog does not match root blog, make adjustments
|
569 |
+
if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
|
570 |
+
$upload_dir['baseurl'] = str_replace( get_blog_option( $current_blog->blog_id, 'home' ) , get_blog_option( BP_ROOT_BLOG, 'home' ), $upload_dir['baseurl'] );
|
571 |
+
|
572 |
+
return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
|
573 |
+
}
|
574 |
+
|
575 |
?>
|
bp-core/bp-core-catchuri.php
CHANGED
@@ -1,290 +1,301 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
|
4 |
-
Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
|
5 |
-
*/
|
6 |
-
|
7 |
-
/**
|
8 |
-
* bp_core_set_uri_globals()
|
9 |
-
*
|
10 |
-
* Analyzes the URI structure and breaks it down into parts for use in code.
|
11 |
-
* The idea is that BuddyPress can use complete custom friendly URI's without the
|
12 |
-
* user having to add new re-write rules.
|
13 |
-
*
|
14 |
-
* Future custom components would then be able to use their own custom URI structure.
|
15 |
-
*
|
16 |
-
* The URI's are broken down as follows:
|
17 |
-
* - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
|
18 |
-
* - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
|
19 |
-
*
|
20 |
-
* Example:
|
21 |
-
* - http://domain.com/members/andy/profile/edit/group/5/
|
22 |
-
* - $bp->current_component: string 'profile'
|
23 |
-
* - $bp->current_action: string 'edit'
|
24 |
-
* - $bp->action_variables: array ['group', 5]
|
25 |
-
*
|
26 |
-
* @package BuddyPress Core
|
27 |
-
*/
|
28 |
-
function bp_core_set_uri_globals() {
|
29 |
-
global $current_component, $current_action, $action_variables;
|
30 |
-
global $displayed_user_id;
|
31 |
-
global $is_member_page;
|
32 |
-
global $bp_unfiltered_uri;
|
33 |
-
global $bp, $current_blog;
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
|
38 |
-
return false;
|
39 |
-
|
40 |
-
|
41 |
-
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
|
42 |
-
$path = bp_core_referrer();
|
43 |
-
else
|
44 |
-
$path =
|
45 |
-
|
46 |
-
$path = apply_filters( 'bp_uri', $path );
|
47 |
-
|
48 |
-
//
|
49 |
-
// they are still registered in the global $_GET variable
|
50 |
-
$noget = substr( $path, 0, strpos( $path, '?' ) );
|
51 |
-
if ( $noget != '' )
|
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 |
-
$action_variables
|
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 |
-
if ( !$
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
|
4 |
+
Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
|
5 |
+
*/
|
6 |
+
|
7 |
+
/**
|
8 |
+
* bp_core_set_uri_globals()
|
9 |
+
*
|
10 |
+
* Analyzes the URI structure and breaks it down into parts for use in code.
|
11 |
+
* The idea is that BuddyPress can use complete custom friendly URI's without the
|
12 |
+
* user having to add new re-write rules.
|
13 |
+
*
|
14 |
+
* Future custom components would then be able to use their own custom URI structure.
|
15 |
+
*
|
16 |
+
* The URI's are broken down as follows:
|
17 |
+
* - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
|
18 |
+
* - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
|
19 |
+
*
|
20 |
+
* Example:
|
21 |
+
* - http://domain.com/members/andy/profile/edit/group/5/
|
22 |
+
* - $bp->current_component: string 'profile'
|
23 |
+
* - $bp->current_action: string 'edit'
|
24 |
+
* - $bp->action_variables: array ['group', 5]
|
25 |
+
*
|
26 |
+
* @package BuddyPress Core
|
27 |
+
*/
|
28 |
+
function bp_core_set_uri_globals() {
|
29 |
+
global $current_component, $current_action, $action_variables;
|
30 |
+
global $displayed_user_id;
|
31 |
+
global $is_member_page;
|
32 |
+
global $bp_unfiltered_uri;
|
33 |
+
global $bp, $current_blog;
|
34 |
+
|
35 |
+
// Only catch URI's on the root blog if we are not running BP on multiple blogs
|
36 |
+
if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() )
|
37 |
+
if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
|
38 |
+
return false;
|
39 |
+
|
40 |
+
// Ajax or not?
|
41 |
+
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
|
42 |
+
$path = bp_core_referrer();
|
43 |
+
else
|
44 |
+
$path = esc_url( $_SERVER['REQUEST_URI'] );
|
45 |
+
|
46 |
+
$path = apply_filters( 'bp_uri', $path );
|
47 |
+
|
48 |
+
// Take GET variables off the URL to avoid problems,
|
49 |
+
// they are still registered in the global $_GET variable
|
50 |
+
$noget = substr( $path, 0, strpos( $path, '?' ) );
|
51 |
+
if ( $noget != '' )
|
52 |
+
$path = $noget;
|
53 |
+
|
54 |
+
// Fetch the current URI and explode each part separated by '/' into an array
|
55 |
+
$bp_uri = explode( '/', $path );
|
56 |
+
|
57 |
+
// Loop and remove empties
|
58 |
+
foreach ( (array)$bp_uri as $key => $uri_chunk )
|
59 |
+
if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
|
60 |
+
|
61 |
+
// Running off blog other than root
|
62 |
+
if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
|
63 |
+
|
64 |
+
// Any subdirectory names must be removed from $bp_uri.
|
65 |
+
// This includes two cases: (1) when WP is installed in a subdirectory,
|
66 |
+
// and (2) when BP is running on secondary blog of a subdirectory
|
67 |
+
// multisite installation. Phew!
|
68 |
+
if ( $chunks = explode( '/', $current_blog->path ) ) {
|
69 |
+
foreach( $chunks as $key => $chunk ) {
|
70 |
+
$bkey = array_search( $chunk, $bp_uri );
|
71 |
+
|
72 |
+
if ( $bkey !== false )
|
73 |
+
unset( $bp_uri[$bkey] );
|
74 |
+
|
75 |
+
$bp_uri = array_values( $bp_uri );
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
// Set the indexes, these are incresed by one if we are not on a VHOST install
|
81 |
+
$component_index = 0;
|
82 |
+
$action_index = $component_index + 1;
|
83 |
+
|
84 |
+
// If this is a WordPress page, return from the function.
|
85 |
+
if ( is_page( $bp_uri[$component_index] ) )
|
86 |
+
return false;
|
87 |
+
|
88 |
+
// Get site path items
|
89 |
+
$paths = explode( '/', bp_core_get_site_path() );
|
90 |
+
|
91 |
+
// Take empties off the end of path
|
92 |
+
if ( empty( $paths[count($paths) - 1] ) )
|
93 |
+
array_pop( $paths );
|
94 |
+
|
95 |
+
// Take empties off the start of path
|
96 |
+
if ( empty( $paths[0] ) )
|
97 |
+
array_shift( $paths );
|
98 |
+
|
99 |
+
foreach ( (array)$bp_uri as $key => $uri_chunk )
|
100 |
+
if ( in_array( $uri_chunk, $paths ))
|
101 |
+
unset( $bp_uri[$key] );
|
102 |
+
|
103 |
+
// Reset the keys by merging with an empty array
|
104 |
+
$bp_uri = array_merge( array(), $bp_uri );
|
105 |
+
$bp_unfiltered_uri = $bp_uri;
|
106 |
+
|
107 |
+
// If we are under anything with a members slug, set the correct globals
|
108 |
+
if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
|
109 |
+
$is_member_page = true;
|
110 |
+
$is_root_component = true;
|
111 |
+
}
|
112 |
+
|
113 |
+
// Catch a member page and set the current member ID
|
114 |
+
if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
|
115 |
+
if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
|
116 |
+
// We are within a member page, set up user id globals
|
117 |
+
if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
|
118 |
+
$displayed_user_id = bp_core_get_userid( urldecode( $bp_uri[1] ) );
|
119 |
+
else
|
120 |
+
$displayed_user_id = bp_core_get_userid_from_nicename( urldecode( $bp_uri[1] ) );
|
121 |
+
|
122 |
+
unset( $bp_uri[0] );
|
123 |
+
unset( $bp_uri[1] );
|
124 |
+
|
125 |
+
// Reset the keys by merging with an empty array
|
126 |
+
$bp_uri = array_merge( array(), $bp_uri );
|
127 |
+
}
|
128 |
+
} else {
|
129 |
+
if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
|
130 |
+
$is_member_page = true;
|
131 |
+
$is_root_component = true;
|
132 |
+
|
133 |
+
// We are within a member page, set up user id globals
|
134 |
+
if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
|
135 |
+
$displayed_user_id = bp_core_get_userid( urldecode( $bp_uri[0] ) );
|
136 |
+
else
|
137 |
+
$displayed_user_id = bp_core_get_userid_from_nicename( urldecode( $bp_uri[0] ) );
|
138 |
+
|
139 |
+
unset( $bp_uri[0] );
|
140 |
+
|
141 |
+
// Reset the keys by merging with an empty array
|
142 |
+
$bp_uri = array_merge( array(), $bp_uri );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
if ( !isset( $is_root_component ) )
|
147 |
+
$is_root_component = in_array( $bp_uri[0], $bp->root_components );
|
148 |
+
|
149 |
+
if ( !is_subdomain_install() && !$is_root_component ) {
|
150 |
+
$component_index++;
|
151 |
+
$action_index++;
|
152 |
+
}
|
153 |
+
|
154 |
+
// Set the current component
|
155 |
+
$current_component = $bp_uri[$component_index];
|
156 |
+
|
157 |
+
// Set the current action
|
158 |
+
$current_action = $bp_uri[$action_index];
|
159 |
+
|
160 |
+
// Set the entire URI as the action variables, we will unset the current_component and action in a second
|
161 |
+
$action_variables = $bp_uri;
|
162 |
+
|
163 |
+
// Unset the current_component and action from action_variables
|
164 |
+
unset( $action_variables[$component_index] );
|
165 |
+
unset( $action_variables[$action_index] );
|
166 |
+
|
167 |
+
// Remove the username from action variables if this is not a VHOST install
|
168 |
+
if ( !is_subdomain_install() && !$is_root_component )
|
169 |
+
array_shift( $action_variables );
|
170 |
+
|
171 |
+
// Reset the keys by merging with an empty array
|
172 |
+
$action_variables = array_merge( array(), $action_variables );
|
173 |
+
}
|
174 |
+
add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
|
175 |
+
|
176 |
+
/**
|
177 |
+
* bp_catch_uri()
|
178 |
+
*
|
179 |
+
* Takes either a single page name or array of page names and
|
180 |
+
* loads the first template file that can be found.
|
181 |
+
*
|
182 |
+
* Please don't call this function directly anymore, use: bp_core_load_template()
|
183 |
+
*
|
184 |
+
* @package BuddyPress Core
|
185 |
+
* @global $bp_path BuddyPress global containing the template file names to use.
|
186 |
+
* @param $pages Template file names to use.
|
187 |
+
* @uses add_action() Hooks a function on to a specific action
|
188 |
+
*/
|
189 |
+
function bp_catch_uri( $pages, $skip_blog_check = false ) {
|
190 |
+
global $bp_path, $bp_skip_blog_check;
|
191 |
+
|
192 |
+
$bp_skip_blog_check = $skip_blog_check;
|
193 |
+
|
194 |
+
$bp_path = $pages;
|
195 |
+
|
196 |
+
if ( !bp_is_blog_page() ) {
|
197 |
+
remove_action( 'template_redirect', 'redirect_canonical' );
|
198 |
+
}
|
199 |
+
add_action( 'template_redirect', 'bp_core_do_catch_uri', 2 );
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* bp_core_do_catch_uri()
|
204 |
+
*
|
205 |
+
* Loads the first template file found based on the $bp_path global.
|
206 |
+
*
|
207 |
+
* @package BuddyPress Core
|
208 |
+
* @global $bp_path BuddyPress global containing the template file names to use.
|
209 |
+
*/
|
210 |
+
function bp_core_do_catch_uri() {
|
211 |
+
global $bp_path, $bp, $wpdb;
|
212 |
+
global $current_blog, $bp_skip_blog_check;
|
213 |
+
global $bp_no_status_set;
|
214 |
+
global $wp_query;
|
215 |
+
|
216 |
+
/* Can be a single template or an array of templates */
|
217 |
+
$templates = $bp_path;
|
218 |
+
|
219 |
+
/* Don't hijack any URLs on blog pages */
|
220 |
+
if ( bp_is_blog_page() ) {
|
221 |
+
if ( !$bp_skip_blog_check )
|
222 |
+
return false;
|
223 |
+
} else {
|
224 |
+
$wp_query->is_home = false;
|
225 |
+
}
|
226 |
+
|
227 |
+
/* Make sure this is not reported as a 404 */
|
228 |
+
if ( !$bp_no_status_set ) {
|
229 |
+
status_header( 200 );
|
230 |
+
$wp_query->is_404 = false;
|
231 |
+
$wp_query->is_page = true;
|
232 |
+
}
|
233 |
+
|
234 |
+
foreach ( (array)$templates as $template )
|
235 |
+
$filtered_templates[] = $template . '.php';
|
236 |
+
|
237 |
+
if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
|
238 |
+
load_template( apply_filters( 'bp_load_template', $located_template ) );
|
239 |
+
} else {
|
240 |
+
if ( $located_template = locate_template( array( '404.php' ) ) ) {
|
241 |
+
status_header( 404 );
|
242 |
+
load_template( $located_template );
|
243 |
+
} else
|
244 |
+
bp_core_redirect( $bp->root_domain );
|
245 |
+
}
|
246 |
+
die;
|
247 |
+
}
|
248 |
+
|
249 |
+
function bp_core_catch_no_access() {
|
250 |
+
global $bp, $bp_path, $bp_unfiltered_uri, $bp_no_status_set;
|
251 |
+
|
252 |
+
// If bp_core_redirect() and $bp_no_status_set is true,
|
253 |
+
// we are redirecting to an accessable page, so skip this check.
|
254 |
+
if ( $bp_no_status_set )
|
255 |
+
return false;
|
256 |
+
|
257 |
+
/* If this user has been marked as a spammer and the logged in user is not a site admin, redirect. */
|
258 |
+
if ( isset( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
|
259 |
+
if ( !is_super_admin() )
|
260 |
+
bp_core_redirect( $bp->root_domain );
|
261 |
+
else
|
262 |
+
bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
|
263 |
+
}
|
264 |
+
|
265 |
+
// If this user does not exist, redirect to the root domain.
|
266 |
+
if ( !$bp->displayed_user->id && $bp_unfiltered_uri[0] == BP_MEMBERS_SLUG && isset($bp_unfiltered_uri[1]) )
|
267 |
+
bp_core_redirect( $bp->root_domain );
|
268 |
+
|
269 |
+
// Add .php to all options in $bp_path
|
270 |
+
foreach( (array) $bp_path as $template )
|
271 |
+
$filtered_templates[] = "$template.php";
|
272 |
+
|
273 |
+
// If the template file doesn't exist, redirect to the root domain.
|
274 |
+
if ( !bp_is_blog_page() && !file_exists( apply_filters( 'bp_located_template', locate_template( $filtered_templates, false ), $filtered_templates ) ) )
|
275 |
+
bp_core_redirect( $bp->root_domain );
|
276 |
+
|
277 |
+
if ( !$bp_path && !bp_is_blog_page() ) {
|
278 |
+
if ( is_user_logged_in() ) {
|
279 |
+
wp_redirect( $bp->root_domain );
|
280 |
+
} else {
|
281 |
+
wp_redirect( site_url( 'wp-login.php?redirect_to=' . site_url() . $_SERVER['REQUEST_URI'] ) );
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}
|
285 |
+
add_action( 'wp', 'bp_core_catch_no_access' );
|
286 |
+
|
287 |
+
/**
|
288 |
+
* bp_core_catch_profile_uri()
|
289 |
+
*
|
290 |
+
* If the extended profiles component is not installed we still need
|
291 |
+
* to catch the /profile URI's and display whatever we have installed.
|
292 |
+
*
|
293 |
+
*/
|
294 |
+
function bp_core_catch_profile_uri() {
|
295 |
+
global $bp;
|
296 |
+
|
297 |
+
if ( !function_exists('xprofile_install') )
|
298 |
+
bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
|
299 |
+
}
|
300 |
+
|
301 |
?>
|
bp-core/bp-core-classes.php
CHANGED
@@ -1,489 +1,652 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* BP_Core_User class can be used by any component. It will fetch useful
|
4 |
-
* details for any user when provided with a user_id.
|
5 |
-
*
|
6 |
-
* Example:
|
7 |
-
* $user = new BP_Core_User( $user_id );
|
8 |
-
* $user_avatar = $user->avatar;
|
9 |
-
* $user_email = $user->email;
|
10 |
-
* $user_status = $user->status;
|
11 |
-
* etc.
|
12 |
-
*
|
13 |
-
* @package BuddyPress Core
|
14 |
-
*/
|
15 |
-
class BP_Core_User {
|
16 |
-
var $id;
|
17 |
-
var $avatar;
|
18 |
-
var $avatar_thumb;
|
19 |
-
var $avatar_mini;
|
20 |
-
var $fullname;
|
21 |
-
var $email;
|
22 |
-
|
23 |
-
var $user_url;
|
24 |
-
var $user_link;
|
25 |
-
|
26 |
-
var $last_active;
|
27 |
-
|
28 |
-
/* Extras */
|
29 |
-
var $total_friends;
|
30 |
-
var $total_blogs;
|
31 |
-
var $total_groups;
|
32 |
-
|
33 |
-
function bp_core_user( $user_id, $populate_extras = false ) {
|
34 |
-
if ( $user_id ) {
|
35 |
-
$this->id = $user_id;
|
36 |
-
$this->populate();
|
37 |
-
|
38 |
-
if ( $populate_extras )
|
39 |
-
$this->populate_extras();
|
40 |
-
}
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* populate()
|
45 |
-
*
|
46 |
-
* Populate the instantiated class with data based on the User ID provided.
|
47 |
-
*
|
48 |
-
* @package BuddyPress Core
|
49 |
-
* @global $userdata WordPress user data for the current logged in user.
|
50 |
-
* @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
|
51 |
-
* @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
|
52 |
-
* @uses bp_core_get_user_email() Returns the email address for the user based on user ID
|
53 |
-
* @uses
|
54 |
-
* @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user
|
55 |
-
* @uses bp_profile_last_updated_date() Returns the last updated date for a user.
|
56 |
-
*/
|
57 |
-
function populate() {
|
58 |
-
if ( function_exists( 'xprofile_install' ) )
|
59 |
-
$this->profile_data = $this->get_profile_data();
|
60 |
-
|
61 |
-
if ( $this->profile_data ) {
|
62 |
-
$this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
|
63 |
-
$this->fullname =
|
64 |
-
$this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>";
|
65 |
-
$this->email =
|
66 |
-
} else {
|
67 |
-
$this->user_url = bp_core_get_user_domain( $this->id );
|
68 |
-
$this->user_link = bp_core_get_userlink( $this->id );
|
69 |
-
$this->fullname =
|
70 |
-
$this->email =
|
71 |
-
}
|
72 |
-
|
73 |
-
/* Cache a few things that are fetched often */
|
74 |
-
wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
|
75 |
-
wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
|
76 |
-
wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
|
77 |
-
|
78 |
-
$this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) );
|
79 |
-
$this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
|
80 |
-
$this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
|
81 |
-
|
82 |
-
$this->last_active = bp_core_get_last_activity(
|
83 |
-
}
|
84 |
-
|
85 |
-
function populate_extras() {
|
86 |
-
global $bp;
|
87 |
-
|
88 |
-
if ( function_exists('friends_install') )
|
89 |
-
$this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
|
90 |
-
|
91 |
-
if ( function_exists('groups_install') ) {
|
92 |
-
$this->total_groups = BP_Groups_Member::total_group_count( $this->id );
|
93 |
-
|
94 |
-
if ( $this->total_groups ) {
|
95 |
-
if ( 1 == $this->total_groups )
|
96 |
-
$this->total_groups .= ' ' . __( 'group', 'buddypress' );
|
97 |
-
else
|
98 |
-
$this->total_groups .= ' ' . __( 'groups', 'buddypress' );
|
99 |
-
}
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
function get_profile_data() {
|
104 |
-
return BP_XProfile_ProfileData::get_all_for_user( $this->id );
|
105 |
-
}
|
106 |
-
|
107 |
-
/* Static Functions */
|
108 |
-
|
109 |
-
function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) {
|
110 |
-
global $wpdb, $bp;
|
111 |
-
|
112 |
-
$sql = array();
|
113 |
-
|
114 |
-
$sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
|
115 |
-
|
116 |
-
if ( 'active' == $type || 'online' == $type )
|
117 |
-
$sql['select_active'] = ", um.meta_value as last_activity";
|
118 |
-
|
119 |
-
if ( 'popular' == $type )
|
120 |
-
$sql['select_popular'] = ", um.meta_value as total_friend_count";
|
121 |
-
|
122 |
-
if ( 'alphabetical' == $type )
|
123 |
-
$sql['select_alpha'] = ", pd.value as fullname";
|
124 |
-
|
125 |
-
$sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
|
126 |
-
|
127 |
-
if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
|
128 |
-
$sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
|
129 |
-
|
130 |
-
$sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
|
131 |
-
|
132 |
-
if ( 'active' == $type || 'online' == $type )
|
133 |
-
$sql['where_active'] = "AND um.meta_key = 'last_activity'";
|
134 |
-
|
135 |
-
if ( 'popular' == $type )
|
136 |
-
$sql['where_popular'] = "AND um.meta_key = 'total_friend_count'";
|
137 |
-
|
138 |
-
if ( 'online' == $type )
|
139 |
-
$sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
|
140 |
-
|
141 |
-
if ( 'alphabetical' == $type )
|
142 |
-
$sql['where_alpha'] = "AND pd.field_id = 1";
|
143 |
-
|
144 |
-
if ( $include ) {
|
145 |
-
if ( is_array( $include ) )
|
146 |
-
$uids = $wpdb->escape( implode( ',', (array)$include ) );
|
147 |
-
else
|
148 |
-
$uids = $wpdb->escape( $include );
|
149 |
-
|
150 |
-
if ( !empty( $uids ) )
|
151 |
-
$sql['where_users'] = "AND u.ID IN ({$uids})";
|
152 |
-
}
|
153 |
-
|
154 |
-
else if ( $user_id && function_exists( 'friends_install' ) ) {
|
155 |
-
$friend_ids = friends_get_friend_user_ids( $user_id );
|
156 |
-
$friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
|
157 |
-
|
158 |
-
if ( !empty( $friend_ids ) )
|
159 |
-
$sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
|
160 |
-
else {
|
161 |
-
/* User has no friends, return false since there will be no users to fetch. */
|
162 |
-
return false;
|
163 |
-
}
|
164 |
-
}
|
165 |
-
|
166 |
-
if ( $search_terms && function_exists( 'xprofile_install' ) ) {
|
167 |
-
$search_terms = like_escape( $wpdb->escape( $search_terms ) );
|
168 |
-
$sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
|
169 |
-
}
|
170 |
-
|
171 |
-
switch ( $type ) {
|
172 |
-
case 'active': case 'online': default:
|
173 |
-
$sql[] = "ORDER BY um.meta_value DESC";
|
174 |
-
break;
|
175 |
-
case 'newest':
|
176 |
-
$sql[] = "ORDER BY u.user_registered DESC";
|
177 |
-
break;
|
178 |
-
case 'alphabetical':
|
179 |
-
$sql[] = "ORDER BY pd.value ASC";
|
180 |
-
break;
|
181 |
-
case 'random':
|
182 |
-
$sql[] = "ORDER BY rand()";
|
183 |
-
break;
|
184 |
-
case 'popular':
|
185 |
-
$sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
|
186 |
-
break;
|
187 |
-
}
|
188 |
-
|
189 |
-
if ( $limit && $page )
|
190 |
-
$sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
191 |
-
|
192 |
-
/* Get paginated results */
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
if ( '
|
341 |
-
$
|
342 |
-
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
343 |
-
foreach ( (array)$
|
344 |
-
if ( $
|
345 |
-
$paged_users[$i]->
|
346 |
-
}
|
347 |
-
}
|
348 |
-
}
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
*
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
$this->
|
414 |
-
$this->
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
$
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* BP_Core_User class can be used by any component. It will fetch useful
|
4 |
+
* details for any user when provided with a user_id.
|
5 |
+
*
|
6 |
+
* Example:
|
7 |
+
* $user = new BP_Core_User( $user_id );
|
8 |
+
* $user_avatar = $user->avatar;
|
9 |
+
* $user_email = $user->email;
|
10 |
+
* $user_status = $user->status;
|
11 |
+
* etc.
|
12 |
+
*
|
13 |
+
* @package BuddyPress Core
|
14 |
+
*/
|
15 |
+
class BP_Core_User {
|
16 |
+
var $id;
|
17 |
+
var $avatar;
|
18 |
+
var $avatar_thumb;
|
19 |
+
var $avatar_mini;
|
20 |
+
var $fullname;
|
21 |
+
var $email;
|
22 |
+
|
23 |
+
var $user_url;
|
24 |
+
var $user_link;
|
25 |
+
|
26 |
+
var $last_active;
|
27 |
+
|
28 |
+
/* Extras */
|
29 |
+
var $total_friends;
|
30 |
+
var $total_blogs;
|
31 |
+
var $total_groups;
|
32 |
+
|
33 |
+
function bp_core_user( $user_id, $populate_extras = false ) {
|
34 |
+
if ( $user_id ) {
|
35 |
+
$this->id = $user_id;
|
36 |
+
$this->populate();
|
37 |
+
|
38 |
+
if ( $populate_extras )
|
39 |
+
$this->populate_extras();
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* populate()
|
45 |
+
*
|
46 |
+
* Populate the instantiated class with data based on the User ID provided.
|
47 |
+
*
|
48 |
+
* @package BuddyPress Core
|
49 |
+
* @global $userdata WordPress user data for the current logged in user.
|
50 |
+
* @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
|
51 |
+
* @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
|
52 |
+
* @uses bp_core_get_user_email() Returns the email address for the user based on user ID
|
53 |
+
* @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table
|
54 |
+
* @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user
|
55 |
+
* @uses bp_profile_last_updated_date() Returns the last updated date for a user.
|
56 |
+
*/
|
57 |
+
function populate() {
|
58 |
+
if ( function_exists( 'xprofile_install' ) )
|
59 |
+
$this->profile_data = $this->get_profile_data();
|
60 |
+
|
61 |
+
if ( $this->profile_data ) {
|
62 |
+
$this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
|
63 |
+
$this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );
|
64 |
+
$this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>";
|
65 |
+
$this->email = esc_attr( $this->profile_data['user_email'] );
|
66 |
+
} else {
|
67 |
+
$this->user_url = bp_core_get_user_domain( $this->id );
|
68 |
+
$this->user_link = bp_core_get_userlink( $this->id );
|
69 |
+
$this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) );
|
70 |
+
$this->email = esc_attr( bp_core_get_user_email( $this->id ) );
|
71 |
+
}
|
72 |
+
|
73 |
+
/* Cache a few things that are fetched often */
|
74 |
+
wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
|
75 |
+
wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
|
76 |
+
wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
|
77 |
+
|
78 |
+
$this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) );
|
79 |
+
$this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
|
80 |
+
$this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
|
81 |
+
|
82 |
+
$this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) );
|
83 |
+
}
|
84 |
+
|
85 |
+
function populate_extras() {
|
86 |
+
global $bp;
|
87 |
+
|
88 |
+
if ( function_exists('friends_install') )
|
89 |
+
$this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
|
90 |
+
|
91 |
+
if ( function_exists('groups_install') ) {
|
92 |
+
$this->total_groups = BP_Groups_Member::total_group_count( $this->id );
|
93 |
+
|
94 |
+
if ( $this->total_groups ) {
|
95 |
+
if ( 1 == $this->total_groups )
|
96 |
+
$this->total_groups .= ' ' . __( 'group', 'buddypress' );
|
97 |
+
else
|
98 |
+
$this->total_groups .= ' ' . __( 'groups', 'buddypress' );
|
99 |
+
}
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
function get_profile_data() {
|
104 |
+
return BP_XProfile_ProfileData::get_all_for_user( $this->id );
|
105 |
+
}
|
106 |
+
|
107 |
+
/* Static Functions */
|
108 |
+
|
109 |
+
function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) {
|
110 |
+
global $wpdb, $bp;
|
111 |
+
|
112 |
+
$sql = array();
|
113 |
+
|
114 |
+
$sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
|
115 |
+
|
116 |
+
if ( 'active' == $type || 'online' == $type )
|
117 |
+
$sql['select_active'] = ", um.meta_value as last_activity";
|
118 |
+
|
119 |
+
if ( 'popular' == $type )
|
120 |
+
$sql['select_popular'] = ", um.meta_value as total_friend_count";
|
121 |
+
|
122 |
+
if ( 'alphabetical' == $type )
|
123 |
+
$sql['select_alpha'] = ", pd.value as fullname";
|
124 |
+
|
125 |
+
$sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
|
126 |
+
|
127 |
+
if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
|
128 |
+
$sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
|
129 |
+
|
130 |
+
$sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
|
131 |
+
|
132 |
+
if ( 'active' == $type || 'online' == $type )
|
133 |
+
$sql['where_active'] = "AND um.meta_key = 'last_activity'";
|
134 |
+
|
135 |
+
if ( 'popular' == $type )
|
136 |
+
$sql['where_popular'] = "AND um.meta_key = 'total_friend_count'";
|
137 |
+
|
138 |
+
if ( 'online' == $type )
|
139 |
+
$sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
|
140 |
+
|
141 |
+
if ( 'alphabetical' == $type )
|
142 |
+
$sql['where_alpha'] = "AND pd.field_id = 1";
|
143 |
+
|
144 |
+
if ( $include ) {
|
145 |
+
if ( is_array( $include ) )
|
146 |
+
$uids = $wpdb->escape( implode( ',', (array)$include ) );
|
147 |
+
else
|
148 |
+
$uids = $wpdb->escape( $include );
|
149 |
+
|
150 |
+
if ( !empty( $uids ) )
|
151 |
+
$sql['where_users'] = "AND u.ID IN ({$uids})";
|
152 |
+
}
|
153 |
+
|
154 |
+
else if ( $user_id && function_exists( 'friends_install' ) ) {
|
155 |
+
$friend_ids = friends_get_friend_user_ids( $user_id );
|
156 |
+
$friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
|
157 |
+
|
158 |
+
if ( !empty( $friend_ids ) )
|
159 |
+
$sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
|
160 |
+
else {
|
161 |
+
/* User has no friends, return false since there will be no users to fetch. */
|
162 |
+
return false;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
if ( $search_terms && function_exists( 'xprofile_install' ) ) {
|
167 |
+
$search_terms = like_escape( $wpdb->escape( $search_terms ) );
|
168 |
+
$sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
|
169 |
+
}
|
170 |
+
|
171 |
+
switch ( $type ) {
|
172 |
+
case 'active': case 'online': default:
|
173 |
+
$sql[] = "ORDER BY um.meta_value DESC";
|
174 |
+
break;
|
175 |
+
case 'newest':
|
176 |
+
$sql[] = "ORDER BY u.user_registered DESC";
|
177 |
+
break;
|
178 |
+
case 'alphabetical':
|
179 |
+
$sql[] = "ORDER BY pd.value ASC";
|
180 |
+
break;
|
181 |
+
case 'random':
|
182 |
+
$sql[] = "ORDER BY rand()";
|
183 |
+
break;
|
184 |
+
case 'popular':
|
185 |
+
$sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
|
186 |
+
break;
|
187 |
+
}
|
188 |
+
|
189 |
+
if ( $limit && $page )
|
190 |
+
$sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
191 |
+
|
192 |
+
/* Get paginated results */
|
193 |
+
$paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array)$sql ), $sql );
|
194 |
+
$paged_users = $wpdb->get_results( $paged_users_sql );
|
195 |
+
|
196 |
+
/* Re-jig the SQL so we can get the total user count */
|
197 |
+
unset( $sql['select_main'] );
|
198 |
+
|
199 |
+
if ( !empty( $sql['select_active'] ) )
|
200 |
+
unset( $sql['select_active'] );
|
201 |
+
|
202 |
+
if ( !empty( $sql['select_popular'] ) )
|
203 |
+
unset( $sql['select_popular'] );
|
204 |
+
|
205 |
+
if ( !empty( $sql['select_alpha'] ) )
|
206 |
+
unset( $sql['select_alpha'] );
|
207 |
+
|
208 |
+
if ( !empty( $sql['pagination'] ) )
|
209 |
+
unset( $sql['pagination'] );
|
210 |
+
|
211 |
+
array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
|
212 |
+
|
213 |
+
/* Get total user results */
|
214 |
+
$total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array)$sql ), $sql );
|
215 |
+
$total_users = $wpdb->get_var( $total_users_sql );
|
216 |
+
|
217 |
+
/***
|
218 |
+
* Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
|
219 |
+
* We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
|
220 |
+
*/
|
221 |
+
if ( $populate_extras ) {
|
222 |
+
foreach ( (array)$paged_users as $user )
|
223 |
+
$user_ids[] = $user->id;
|
224 |
+
|
225 |
+
$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
|
226 |
+
|
227 |
+
/* Add additional data to the returned results */
|
228 |
+
$paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
|
229 |
+
}
|
230 |
+
|
231 |
+
return array( 'users' => $paged_users, 'total' => $total_users );
|
232 |
+
}
|
233 |
+
|
234 |
+
function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true ) {
|
235 |
+
global $wpdb, $bp;
|
236 |
+
|
237 |
+
if ( $limit && $page )
|
238 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
239 |
+
|
240 |
+
// Multibyte compliance
|
241 |
+
if ( function_exists( 'mb_strlen' ) ) {
|
242 |
+
if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
|
243 |
+
return false;
|
244 |
+
}
|
245 |
+
} else {
|
246 |
+
if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) {
|
247 |
+
return false;
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
$letter = like_escape( $wpdb->escape( $letter ) );
|
252 |
+
$status_sql = bp_core_get_status_sql( 'u.' );
|
253 |
+
|
254 |
+
$total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
|
255 |
+
$paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
|
256 |
+
|
257 |
+
$total_users = $wpdb->get_var( $total_users_sql );
|
258 |
+
$paged_users = $wpdb->get_results( $paged_users_sql );
|
259 |
+
|
260 |
+
/***
|
261 |
+
* Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
|
262 |
+
* We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
|
263 |
+
*/
|
264 |
+
foreach ( (array)$paged_users as $user )
|
265 |
+
$user_ids[] = $user->id;
|
266 |
+
|
267 |
+
$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
|
268 |
+
|
269 |
+
/* Add additional data to the returned results */
|
270 |
+
if ( $populate_extras )
|
271 |
+
$paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
|
272 |
+
|
273 |
+
return array( 'users' => $paged_users, 'total' => $total_users );
|
274 |
+
}
|
275 |
+
|
276 |
+
function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
|
277 |
+
global $wpdb, $bp;
|
278 |
+
|
279 |
+
if ( $limit && $page )
|
280 |
+
$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
|
281 |
+
|
282 |
+
$search_terms = like_escape( $wpdb->escape( $search_terms ) );
|
283 |
+
$status_sql = bp_core_get_status_sql( 'u.' );
|
284 |
+
|
285 |
+
$total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
|
286 |
+
$paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
|
287 |
+
|
288 |
+
$total_users = $wpdb->get_var( $total_users_sql );
|
289 |
+
$paged_users = $wpdb->get_results( $paged_users_sql );
|
290 |
+
|
291 |
+
/***
|
292 |
+
* Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
|
293 |
+
* We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
|
294 |
+
*/
|
295 |
+
foreach ( (array)$paged_users as $user )
|
296 |
+
$user_ids[] = $user->id;
|
297 |
+
|
298 |
+
$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
|
299 |
+
|
300 |
+
/* Add additional data to the returned results */
|
301 |
+
if ( $populate_extras )
|
302 |
+
$paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
|
303 |
+
|
304 |
+
return array( 'users' => $paged_users, 'total' => $total_users );
|
305 |
+
}
|
306 |
+
|
307 |
+
function get_user_extras( $paged_users, $user_ids, $type = false ) {
|
308 |
+
global $bp, $wpdb;
|
309 |
+
|
310 |
+
if ( empty( $user_ids ) )
|
311 |
+
return $paged_users;
|
312 |
+
|
313 |
+
/* Fetch the user's full name */
|
314 |
+
if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
|
315 |
+
/* Ensure xprofile globals are set */
|
316 |
+
if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
|
317 |
+
xprofile_setup_globals();
|
318 |
+
|
319 |
+
$names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", BP_XPROFILE_FULLNAME_FIELD_NAME ) );
|
320 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
321 |
+
foreach ( (array)$names as $name ) {
|
322 |
+
if ( $name->id == $paged_users[$i]->id )
|
323 |
+
$paged_users[$i]->fullname = $name->fullname;
|
324 |
+
}
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
/* Fetch the user's total friend count */
|
329 |
+
if ( 'popular' != $type ) {
|
330 |
+
$friend_count = $wpdb->get_results( "SELECT user_id as id, meta_value as total_friend_count FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'total_friend_count' AND user_id IN ( {$user_ids} )" );
|
331 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
332 |
+
foreach ( (array)$friend_count as $count ) {
|
333 |
+
if ( $count->id == $paged_users[$i]->id )
|
334 |
+
$paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
/* Fetch whether or not the user is a friend */
|
340 |
+
if ( function_exists( 'friends_install' ) ) {
|
341 |
+
$friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
|
342 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
343 |
+
foreach ( (array)$friend_status as $status ) {
|
344 |
+
if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
|
345 |
+
$paged_users[$i]->is_friend = $status->is_confirmed;
|
346 |
+
}
|
347 |
+
}
|
348 |
+
}
|
349 |
+
|
350 |
+
if ( 'active' != $type ) {
|
351 |
+
$user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
|
352 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
353 |
+
foreach ( (array)$user_activity as $activity ) {
|
354 |
+
if ( $activity->id == $paged_users[$i]->id )
|
355 |
+
$paged_users[$i]->last_activity = $activity->last_activity;
|
356 |
+
}
|
357 |
+
}
|
358 |
+
}
|
359 |
+
|
360 |
+
/* Fetch the user's last_activity */
|
361 |
+
if ( 'active' != $type ) {
|
362 |
+
$user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
|
363 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
364 |
+
foreach ( (array)$user_activity as $activity ) {
|
365 |
+
if ( $activity->id == $paged_users[$i]->id )
|
366 |
+
$paged_users[$i]->last_activity = $activity->last_activity;
|
367 |
+
}
|
368 |
+
}
|
369 |
+
}
|
370 |
+
|
371 |
+
/* Fetch the user's latest update */
|
372 |
+
$user_update = $wpdb->get_results( "SELECT user_id as id, meta_value as latest_update FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'bp_latest_update' AND user_id IN ( {$user_ids} )" );
|
373 |
+
for ( $i = 0; $i < count( $paged_users ); $i++ ) {
|
374 |
+
foreach ( (array)$user_update as $update ) {
|
375 |
+
if ( $update->id == $paged_users[$i]->id )
|
376 |
+
$paged_users[$i]->latest_update = $update->latest_update;
|
377 |
+
}
|
378 |
+
}
|
379 |
+
|
380 |
+
return $paged_users;
|
381 |
+
}
|
382 |
+
|
383 |
+
function get_core_userdata( $user_id ) {
|
384 |
+
global $wpdb;
|
385 |
+
|
386 |
+
if ( !$user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )
|
387 |
+
return false;
|
388 |
+
|
389 |
+
return $user;
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
|
394 |
+
/**
|
395 |
+
* BP_Core_Notification class can be used by any component.
|
396 |
+
* It will handle the fetching, saving and deleting of a user notification.
|
397 |
+
*
|
398 |
+
* @package BuddyPress Core
|
399 |
+
*/
|
400 |
+
|
401 |
+
class BP_Core_Notification {
|
402 |
+
var $id;
|
403 |
+
var $item_id;
|
404 |
+
var $secondary_item_id = null;
|
405 |
+
var $user_id;
|
406 |
+
var $component_name;
|
407 |
+
var $component_action;
|
408 |
+
var $date_notified;
|
409 |
+
var $is_new;
|
410 |
+
|
411 |
+
function bp_core_notification( $id = false ) {
|
412 |
+
if ( $id ) {
|
413 |
+
$this->id = $id;
|
414 |
+
$this->populate();
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
function populate() {
|
419 |
+
global $wpdb, $bp;
|
420 |
+
|
421 |
+
if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
|
422 |
+
$this->item_id = $notification->item_id;
|
423 |
+
$this->secondary_item_id = $notification->secondary_item_id;
|
424 |
+
$this->user_id = $notification->user_id;
|
425 |
+
$this->component_name = $notification->component_name;
|
426 |
+
$this->component_action = $notification->component_action;
|
427 |
+
$this->date_notified = $notification->date_notified;
|
428 |
+
$this->is_new = $notification->is_new;
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
function save() {
|
433 |
+
global $wpdb, $bp;
|
434 |
+
|
435 |
+
if ( $this->id ) {
|
436 |
+
// Update
|
437 |
+
$sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
|
438 |
+
} else {
|
439 |
+
// Save
|
440 |
+
$sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
|
441 |
+
}
|
442 |
+
|
443 |
+
if ( !$result = $wpdb->query( $sql ) )
|
444 |
+
return false;
|
445 |
+
|
446 |
+
$this->id = $wpdb->insert_id;
|
447 |
+
return true;
|
448 |
+
}
|
449 |
+
|
450 |
+
/* Static functions */
|
451 |
+
|
452 |
+
function check_access( $user_id, $notification_id ) {
|
453 |
+
global $wpdb, $bp;
|
454 |
+
|
455 |
+
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
|
456 |
+
}
|
457 |
+
|
458 |
+
function get_all_for_user( $user_id ) {
|
459 |
+
global $wpdb, $bp;
|
460 |
+
|
461 |
+
return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
|
462 |
+
}
|
463 |
+
|
464 |
+
function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
|
465 |
+
global $wpdb, $bp;
|
466 |
+
|
467 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
|
468 |
+
}
|
469 |
+
|
470 |
+
function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
|
471 |
+
global $wpdb, $bp;
|
472 |
+
|
473 |
+
if ( $secondary_item_id )
|
474 |
+
$secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
|
475 |
+
|
476 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
|
477 |
+
}
|
478 |
+
|
479 |
+
function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
|
480 |
+
global $wpdb, $bp;
|
481 |
+
|
482 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
|
483 |
+
}
|
484 |
+
|
485 |
+
function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
|
486 |
+
global $wpdb, $bp;
|
487 |
+
|
488 |
+
if ( $component_action )
|
489 |
+
$component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
|
490 |
+
|
491 |
+
if ( $secondary_item_id )
|
492 |
+
$secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
|
493 |
+
|
494 |
+
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
|
495 |
+
}
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* BP_Button
|
500 |
+
*
|
501 |
+
* API to create BuddyPress buttons
|
502 |
+
*
|
503 |
+
* @package BuddyPress Core
|
504 |
+
* @since 1.2.6
|
505 |
+
*/
|
506 |
+
class BP_Button {
|
507 |
+
|
508 |
+
// Button properties
|
509 |
+
var $id;
|
510 |
+
var $component;
|
511 |
+
var $must_be_logged_in;
|
512 |
+
var $block_self;
|
513 |
+
|
514 |
+
// Wrapper div
|
515 |
+
var $wrapper_class;
|
516 |
+
var $wrapper_id;
|
517 |
+
|
518 |
+
// Button
|
519 |
+
var $link_href;
|
520 |
+
var $link_class;
|
521 |
+
var $link_id;
|
522 |
+
var $link_rel;
|
523 |
+
var $link_title;
|
524 |
+
var $link_text;
|
525 |
+
|
526 |
+
// HTML result
|
527 |
+
var $contents;
|
528 |
+
|
529 |
+
/**
|
530 |
+
* bp_button()
|
531 |
+
*
|
532 |
+
* Builds the button based on passed parameters:
|
533 |
+
*
|
534 |
+
* component: Which component this button is for
|
535 |
+
* must_be_logged_in: Button only appears for logged in users
|
536 |
+
* block_self: Button will not appear when viewing your own profile.
|
537 |
+
* wrapper_id: The DOM ID of the button wrapper
|
538 |
+
* wrapper_class: The DOM class of the button wrapper
|
539 |
+
* link_href: The destination link of the button
|
540 |
+
* link_title: Title of the button
|
541 |
+
* link_id: The DOM ID of the button
|
542 |
+
* link_class: The DOM class of the button
|
543 |
+
* link_rel: The DOM rel of the button
|
544 |
+
* link_text: The contents of the button
|
545 |
+
*
|
546 |
+
* @param array $args
|
547 |
+
* @return bool False if not allowed
|
548 |
+
*/
|
549 |
+
function bp_button( $args = '' ) {
|
550 |
+
|
551 |
+
$defaults = array(
|
552 |
+
'id' => '',
|
553 |
+
'component' => 'core',
|
554 |
+
'must_be_logged_in' => true,
|
555 |
+
'block_self' => true,
|
556 |
+
|
557 |
+
'wrapper_id' => '',
|
558 |
+
'wrapper_class' => '',
|
559 |
+
|
560 |
+
'link_href' => '',
|
561 |
+
'link_title' => '',
|
562 |
+
'link_id' => '',
|
563 |
+
'link_class' => '',
|
564 |
+
'link_rel' => '',
|
565 |
+
'link_text' => '',
|
566 |
+
);
|
567 |
+
|
568 |
+
$r = wp_parse_args( $args, $defaults );
|
569 |
+
extract( $r, EXTR_SKIP );
|
570 |
+
|
571 |
+
// Required button properties
|
572 |
+
$this->id = $id;
|
573 |
+
$this->component = $component;
|
574 |
+
$this->must_be_logged_in = (bool)$must_be_logged_in;
|
575 |
+
$this->block_self = (bool)$block_self;
|
576 |
+
|
577 |
+
// $id and $component are required
|
578 |
+
if ( empty( $id ) || empty( $component ) )
|
579 |
+
return false;
|
580 |
+
|
581 |
+
// No button if component is not active
|
582 |
+
if ( !bp_is_active( $this->component ) )
|
583 |
+
return false;
|
584 |
+
|
585 |
+
// No button for guests if must be logged in
|
586 |
+
if ( true == $this->must_be_logged_in && !is_user_logged_in() )
|
587 |
+
return false;
|
588 |
+
|
589 |
+
// No button if viewing your own profile
|
590 |
+
if ( true == $this->block_self && bp_is_my_profile() )
|
591 |
+
return false;
|
592 |
+
|
593 |
+
// Wrapper properties
|
594 |
+
if ( !empty( $wrapper_id ) )
|
595 |
+
$this->wrapper_id = ' id="' . $wrapper_id . '"';
|
596 |
+
|
597 |
+
if ( !empty( $wrapper_class ) )
|
598 |
+
$this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
|
599 |
+
else
|
600 |
+
$this->wrapper_class = ' class="generic-button"';
|
601 |
+
|
602 |
+
// Link properties
|
603 |
+
if ( !empty( $link_id ) )
|
604 |
+
$this->link_id = ' id="' . $link_id . '"';
|
605 |
+
|
606 |
+
if ( !empty( $link_href ) )
|
607 |
+
$this->link_href = ' href="' . $link_href . '"';
|
608 |
+
|
609 |
+
if ( !empty( $link_title ) )
|
610 |
+
$this->link_title = ' title="' . $link_title . '"';
|
611 |
+
|
612 |
+
if ( !empty( $link_rel ) )
|
613 |
+
$this->link_rel = ' rel="' . $link_rel . '"';
|
614 |
+
|
615 |
+
if ( !empty( $link_class ) )
|
616 |
+
$this->link_class = ' class="' . $link_class . '"';
|
617 |
+
|
618 |
+
if ( !empty( $link_text ) )
|
619 |
+
$this->link_text = $link_text;
|
620 |
+
|
621 |
+
// Build the button
|
622 |
+
$this->contents = '<div' . $this->wrapper_class . $this->wrapper_id . '>';
|
623 |
+
$this->contents .= '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>';
|
624 |
+
$this->contents .= '</div>';
|
625 |
+
|
626 |
+
// Allow button to be manipulated externally
|
627 |
+
$this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this );
|
628 |
+
}
|
629 |
+
|
630 |
+
/**
|
631 |
+
* contents()
|
632 |
+
*
|
633 |
+
* Return contents of button
|
634 |
+
*
|
635 |
+
* @return string
|
636 |
+
*/
|
637 |
+
function contents() {
|
638 |
+
return $this->contents;
|
639 |
+
}
|
640 |
+
|
641 |
+
/**
|
642 |
+
* display()
|
643 |
+
*
|
644 |
+
* Output contents of button
|
645 |
+
*/
|
646 |
+
function display() {
|
647 |
+
if ( !empty( $this->contents ) )
|
648 |
+
echo $this->contents;
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
?>
|
bp-core/bp-core-cssjs.php
CHANGED
@@ -1,183 +1,176 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* bp_core_add_admin_bar_css()
|
5 |
-
*
|
6 |
-
* Add the CSS needed for the admin bar on blogs (other than the root) and in the admin area.
|
7 |
-
*
|
8 |
-
* @package BuddyPress Core
|
9 |
-
* @uses get_option() Selects a site setting from the DB.
|
10 |
-
*/
|
11 |
-
function bp_core_add_admin_bar_css() {
|
12 |
-
global $bp, $current_blog;
|
13 |
-
|
14 |
-
if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
15 |
-
return false;
|
16 |
-
|
17 |
-
if ( ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG ) || is_admin() ) {
|
18 |
-
$stylesheet = get_blog_option( BP_ROOT_BLOG, 'stylesheet' );
|
19 |
-
|
20 |
-
if ( file_exists( WP_CONTENT_DIR . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) )
|
21 |
-
wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', WP_CONTENT_URL . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) );
|
22 |
-
else
|
23 |
-
wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/css/adminbar.css' ) );
|
24 |
-
}
|
25 |
-
}
|
26 |
-
add_action( 'init', 'bp_core_add_admin_bar_css' );
|
27 |
-
|
28 |
-
/**
|
29 |
-
* bp_core_admin_menu_icon_css()
|
30 |
-
*
|
31 |
-
* Add a hover-able icon to the "BuddyPress" wp-admin area menu.
|
32 |
-
*
|
33 |
-
* @package BuddyPress Core
|
34 |
-
*/
|
35 |
-
function bp_core_admin_menu_icon_css() {
|
36 |
-
global $bp;
|
37 |
-
?>
|
38 |
-
|
39 |
-
|
40 |
-
ul#adminmenu li.toplevel_page_bp-general-settings
|
41 |
-
ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a
|
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 |
-
if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) {
|
178 |
-
?>
|
179 |
-
<style type="text/css">body { padding-top: 0 !important; } #wp-admin-bar { display: none; }</style>
|
180 |
-
<?php }
|
181 |
-
}
|
182 |
-
add_action( 'wp_footer', 'bp_core_override_adminbar_css' );
|
183 |
-
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* bp_core_add_admin_bar_css()
|
5 |
+
*
|
6 |
+
* Add the CSS needed for the admin bar on blogs (other than the root) and in the admin area.
|
7 |
+
*
|
8 |
+
* @package BuddyPress Core
|
9 |
+
* @uses get_option() Selects a site setting from the DB.
|
10 |
+
*/
|
11 |
+
function bp_core_add_admin_bar_css() {
|
12 |
+
global $bp, $current_blog;
|
13 |
+
|
14 |
+
if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
|
15 |
+
return false;
|
16 |
+
|
17 |
+
if ( ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG ) || is_admin() ) {
|
18 |
+
$stylesheet = get_blog_option( BP_ROOT_BLOG, 'stylesheet' );
|
19 |
+
|
20 |
+
if ( file_exists( WP_CONTENT_DIR . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) )
|
21 |
+
wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', WP_CONTENT_URL . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) );
|
22 |
+
else
|
23 |
+
wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/css/adminbar.css' ) );
|
24 |
+
}
|
25 |
+
}
|
26 |
+
add_action( 'init', 'bp_core_add_admin_bar_css' );
|
27 |
+
|
28 |
+
/**
|
29 |
+
* bp_core_admin_menu_icon_css()
|
30 |
+
*
|
31 |
+
* Add a hover-able icon to the "BuddyPress" wp-admin area menu.
|
32 |
+
*
|
33 |
+
* @package BuddyPress Core
|
34 |
+
*/
|
35 |
+
function bp_core_admin_menu_icon_css() {
|
36 |
+
global $bp;
|
37 |
+
?>
|
38 |
+
|
39 |
+
<style type="text/css">
|
40 |
+
ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo BP_PLUGIN_URL . '/bp-core/images/admin_menu_icon.png' ?> ) !important; background-position: -1px -32px; }
|
41 |
+
ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a, ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a { background-position: -1px 0; }
|
42 |
+
ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
|
43 |
+
</style>
|
44 |
+
|
45 |
+
<?php
|
46 |
+
}
|
47 |
+
add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
|
48 |
+
|
49 |
+
function bp_core_confirmation_js() {
|
50 |
+
global $current_blog;
|
51 |
+
|
52 |
+
if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
|
53 |
+
return false;
|
54 |
+
?>
|
55 |
+
|
56 |
+
<script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
|
57 |
+
|
58 |
+
<?php
|
59 |
+
}
|
60 |
+
add_action( 'wp_head', 'bp_core_confirmation_js', 100 );
|
61 |
+
|
62 |
+
/**
|
63 |
+
* bp_core_add_jquery_cropper()
|
64 |
+
*
|
65 |
+
* Makes sure the jQuery jCrop library is loaded.
|
66 |
+
*
|
67 |
+
* @package BuddyPress Core
|
68 |
+
*/
|
69 |
+
function bp_core_add_jquery_cropper() {
|
70 |
+
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
|
71 |
+
add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
|
72 |
+
add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* bp_core_add_cropper_inline_js()
|
77 |
+
*
|
78 |
+
* Adds the inline JS needed for the cropper to work on a per-page basis.
|
79 |
+
*
|
80 |
+
* @package BuddyPress Core
|
81 |
+
*/
|
82 |
+
function bp_core_add_cropper_inline_js() {
|
83 |
+
global $bp;
|
84 |
+
|
85 |
+
$image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) );
|
86 |
+
$aspect_ratio = 1;
|
87 |
+
|
88 |
+
// Calculate Aspect Ratio
|
89 |
+
if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
|
90 |
+
$aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
|
91 |
+
?>
|
92 |
+
|
93 |
+
<script type="text/javascript">
|
94 |
+
jQuery(window).load( function(){
|
95 |
+
jQuery('#avatar-to-crop').Jcrop({
|
96 |
+
onChange: showPreview,
|
97 |
+
onSelect: showPreview,
|
98 |
+
onSelect: updateCoords,
|
99 |
+
aspectRatio: <?php echo $aspect_ratio ?>,
|
100 |
+
setSelect: [ 50, 50, <?php echo $image[0] / 2 ?>, <?php echo $image[1] / 2 ?> ]
|
101 |
+
});
|
102 |
+
});
|
103 |
+
|
104 |
+
function updateCoords(c) {
|
105 |
+
jQuery('#x').val(c.x);
|
106 |
+
jQuery('#y').val(c.y);
|
107 |
+
jQuery('#w').val(c.w);
|
108 |
+
jQuery('#h').val(c.h);
|
109 |
+
};
|
110 |
+
|
111 |
+
function showPreview(coords) {
|
112 |
+
if ( parseInt(coords.w) > 0 ) {
|
113 |
+
var rx = <?php echo (int) constant( 'BP_AVATAR_FULL_WIDTH' ) ?> / coords.w;
|
114 |
+
var ry = <?php echo (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ?> / coords.h;
|
115 |
+
|
116 |
+
jQuery('#avatar-crop-preview').css({
|
117 |
+
<?php if ( $image ) : ?>
|
118 |
+
width: Math.round(rx * <?php echo $image[0] ?>) + 'px',
|
119 |
+
height: Math.round(ry * <?php echo $image[1] ?>) + 'px',
|
120 |
+
<?php endif; ?>
|
121 |
+
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
|
122 |
+
marginTop: '-' + Math.round(ry * coords.y) + 'px'
|
123 |
+
});
|
124 |
+
}
|
125 |
+
}
|
126 |
+
</script>
|
127 |
+
|
128 |
+
<?php
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* bp_core_add_cropper_inline_css()
|
133 |
+
*
|
134 |
+
* Adds the inline CSS needed for the cropper to work on a per-page basis.
|
135 |
+
*
|
136 |
+
* @package BuddyPress Core
|
137 |
+
*/
|
138 |
+
function bp_core_add_cropper_inline_css() {
|
139 |
+
global $bp;
|
140 |
+
?>
|
141 |
+
|
142 |
+
<style type="text/css">
|
143 |
+
.jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
|
144 |
+
.jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url( <?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif ); }
|
145 |
+
.jcrop-vline { height: 100%; width: 1px !important; }
|
146 |
+
.jcrop-hline { width: 100%; height: 1px !important; }
|
147 |
+
.jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }
|
148 |
+
.jcrop-tracker { width: 100%; height: 100%; }
|
149 |
+
.custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
|
150 |
+
.custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
|
151 |
+
#avatar-crop-pane { width: <?php echo BP_AVATAR_FULL_WIDTH ?>px; height: <?php echo BP_AVATAR_FULL_HEIGHT ?>px; overflow: hidden; }
|
152 |
+
#avatar-crop-submit { margin: 20px 0; }
|
153 |
+
#avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
|
154 |
+
</style>
|
155 |
+
|
156 |
+
<?php
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* bp_core_add_ajax_url_js()
|
161 |
+
*
|
162 |
+
* Adds AJAX target URL so themes can access the WordPress AJAX functionality.
|
163 |
+
*
|
164 |
+
* @package BuddyPress Core
|
165 |
+
*/
|
166 |
+
function bp_core_add_ajax_url_js() {
|
167 |
+
global $bp;
|
168 |
+
?>
|
169 |
+
|
170 |
+
<script type="text/javascript">var ajaxurl = "<?php echo site_url( 'wp-load.php' ); ?>";</script>
|
171 |
+
|
172 |
+
<?php
|
173 |
+
}
|
174 |
+
add_action( 'wp_head', 'bp_core_add_ajax_url_js' );
|
175 |
+
|
176 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bp-core/bp-core-filters.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* @return The blog name for the root blog
|
11 |
*/
|
12 |
function bp_core_email_from_name_filter() {
|
13 |
-
return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
|
14 |
}
|
15 |
add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
|
16 |
|
@@ -43,7 +43,7 @@ add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
|
|
43 |
function bp_core_allow_default_theme( $themes ) {
|
44 |
global $bp, $current_blog;
|
45 |
|
46 |
-
if ( !
|
47 |
return $themes;
|
48 |
|
49 |
if ( $current_blog->ID == $bp->root_blog ) {
|
@@ -165,7 +165,7 @@ function bp_core_activation_signup_blog_notification( $domain, $path, $title, $u
|
|
165 |
|
166 |
// Send email with activation link.
|
167 |
$activate_url = bp_get_activation_page() ."?key=$key";
|
168 |
-
$activate_url =
|
169 |
|
170 |
$admin_email = get_site_option( "admin_email" );
|
171 |
|
@@ -174,8 +174,8 @@ function bp_core_activation_signup_blog_notification( $domain, $path, $title, $u
|
|
174 |
|
175 |
$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
|
176 |
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
|
177 |
-
$message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%s", 'buddypress' ), $activate_url,
|
178 |
-
$subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ),
|
179 |
|
180 |
/* Send the message */
|
181 |
$to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
|
@@ -194,7 +194,7 @@ function bp_core_activation_signup_user_notification( $user, $user_email, $key,
|
|
194 |
global $current_site;
|
195 |
|
196 |
$activate_url = bp_get_activation_page() ."?key=$key";
|
197 |
-
$activate_url =
|
198 |
$admin_email = get_site_option( "admin_email" );
|
199 |
|
200 |
if ( empty( $admin_email ) )
|
@@ -206,7 +206,7 @@ function bp_core_activation_signup_user_notification( $user, $user_email, $key,
|
|
206 |
|
207 |
$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
|
208 |
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
|
209 |
-
$message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email,
|
210 |
$subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
|
211 |
|
212 |
/* Send the message */
|
10 |
* @return The blog name for the root blog
|
11 |
*/
|
12 |
function bp_core_email_from_name_filter() {
|
13 |
+
return apply_filters( 'bp_core_email_from_name_filter', wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ) );
|
14 |
}
|
15 |
add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
|
16 |
|
43 |
function bp_core_allow_default_theme( $themes ) {
|
44 |
global $bp, $current_blog;
|
45 |
|
46 |
+
if ( !is_super_admin() )
|
47 |
return $themes;
|
48 |
|
49 |
if ( $current_blog->ID == $bp->root_blog ) {
|
165 |
|
166 |
// Send email with activation link.
|
167 |
$activate_url = bp_get_activation_page() ."?key=$key";
|
168 |
+
$activate_url = esc_url($activate_url);
|
169 |
|
170 |
$admin_email = get_site_option( "admin_email" );
|
171 |
|
174 |
|
175 |
$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
|
176 |
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
|
177 |
+
$message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%s", 'buddypress' ), $activate_url, esc_url("http://{$domain}{$path}" ) );
|
178 |
+
$subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), esc_url('http://' . $domain . $path));
|
179 |
|
180 |
/* Send the message */
|
181 |
$to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
|
194 |
global $current_site;
|
195 |
|
196 |
$activate_url = bp_get_activation_page() ."?key=$key";
|
197 |
+
$activate_url = esc_url($activate_url);
|
198 |
$admin_email = get_site_option( "admin_email" );
|
199 |
|
200 |
if ( empty( $admin_email ) )
|
206 |
|
207 |
$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
|
208 |
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
|
209 |
+
$message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, esc_url( "http://{$domain}{$path}" ) );
|
210 |
$subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
|
211 |
|
212 |
/* Send the message */
|
bp-core/bp-core-notifications.php
CHANGED
@@ -1,95 +1,95 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
|
4 |
-
global $bp;
|
5 |
-
|
6 |
-
if ( !$date_notified )
|
7 |
-
$date_notified =
|
8 |
-
|
9 |
-
$notification = new BP_Core_Notification;
|
10 |
-
$notification->item_id = $item_id;
|
11 |
-
$notification->user_id = $user_id;
|
12 |
-
$notification->component_name = $component_name;
|
13 |
-
$notification->component_action = $component_action;
|
14 |
-
$notification->date_notified = $date_notified;
|
15 |
-
$notification->is_new = 1;
|
16 |
-
|
17 |
-
if ( $secondary_item_id )
|
18 |
-
$notification->secondary_item_id = $secondary_item_id;
|
19 |
-
|
20 |
-
if ( !$notification->save() )
|
21 |
-
return false;
|
22 |
-
|
23 |
-
return true;
|
24 |
-
}
|
25 |
-
|
26 |
-
function bp_core_delete_notification( $id ) {
|
27 |
-
if ( !bp_core_check_notification_access( $bp->loggedin_user->id, $id ) )
|
28 |
-
return false;
|
29 |
-
|
30 |
-
return BP_Core_Notification::delete( $id );
|
31 |
-
}
|
32 |
-
|
33 |
-
function bp_core_get_notification( $id ) {
|
34 |
-
return new BP_Core_Notification( $id );
|
35 |
-
}
|
36 |
-
|
37 |
-
function bp_core_get_notifications_for_user( $user_id ) {
|
38 |
-
global $bp;
|
39 |
-
|
40 |
-
$notifications = BP_Core_Notification::get_all_for_user( $user_id );
|
41 |
-
|
42 |
-
/* Group notifications by component and component_action and provide totals */
|
43 |
-
for ( $i = 0; $i < count($notifications); $i++ ) {
|
44 |
-
$notification = $notifications[$i];
|
45 |
-
|
46 |
-
$grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
|
47 |
-
}
|
48 |
-
|
49 |
-
if ( !$grouped_notifications )
|
50 |
-
return false;
|
51 |
-
|
52 |
-
/* Calculated a renderable outcome for each notification type */
|
53 |
-
foreach ( (array)$grouped_notifications as $component_name => $action_arrays ) {
|
54 |
-
if ( !$action_arrays )
|
55 |
-
continue;
|
56 |
-
|
57 |
-
foreach ( (array)$action_arrays as $component_action_name => $component_action_items ) {
|
58 |
-
$action_item_count = count($component_action_items);
|
59 |
-
|
60 |
-
if ( $action_item_count < 1 )
|
61 |
-
continue;
|
62 |
-
|
63 |
-
if ( function_exists( $bp->{$component_name}->format_notification_function ) ) {
|
64 |
-
$renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
|
65 |
-
}
|
66 |
-
}
|
67 |
-
}
|
68 |
-
|
69 |
-
return $renderable;
|
70 |
-
}
|
71 |
-
|
72 |
-
function bp_core_delete_notifications_for_user_by_type( $user_id, $component_name, $component_action ) {
|
73 |
-
return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action );
|
74 |
-
}
|
75 |
-
|
76 |
-
function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
|
77 |
-
return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
|
78 |
-
}
|
79 |
-
|
80 |
-
function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
|
81 |
-
return BP_Core_Notification::delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
|
82 |
-
}
|
83 |
-
|
84 |
-
function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
|
85 |
-
return BP_Core_Notification::delete_from_user_by_type( $user_id, $component_name, $component_action );
|
86 |
-
}
|
87 |
-
|
88 |
-
function bp_core_check_notification_access( $user_id, $notification_id ) {
|
89 |
-
if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) )
|
90 |
-
return false;
|
91 |
-
|
92 |
-
return true;
|
93 |
-
}
|
94 |
-
|
95 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
|
4 |
+
global $bp;
|
5 |
+
|
6 |
+
if ( !$date_notified )
|
7 |
+
$date_notified = bp_core_current_time();
|
8 |
+
|
9 |
+
$notification = new BP_Core_Notification;
|
10 |
+
$notification->item_id = $item_id;
|
11 |
+
$notification->user_id = $user_id;
|
12 |
+
$notification->component_name = $component_name;
|
13 |
+
$notification->component_action = $component_action;
|
14 |
+
$notification->date_notified = $date_notified;
|
15 |
+
$notification->is_new = 1;
|
16 |
+
|
17 |
+
if ( $secondary_item_id )
|
18 |
+
$notification->secondary_item_id = $secondary_item_id;
|
19 |
+
|
20 |
+
if ( !$notification->save() )
|
21 |
+
return false;
|
22 |
+
|
23 |
+
return true;
|
24 |
+
}
|
25 |
+
|
26 |
+
function bp_core_delete_notification( $id ) {
|
27 |
+
if ( !bp_core_check_notification_access( $bp->loggedin_user->id, $id ) )
|
28 |
+
return false;
|
29 |
+
|
30 |
+
return BP_Core_Notification::delete( $id );
|
31 |
+
}
|
32 |
+
|
33 |
+
function bp_core_get_notification( $id ) {
|
34 |
+
return new BP_Core_Notification( $id );
|
35 |
+
}
|
36 |
+
|
37 |
+
function bp_core_get_notifications_for_user( $user_id ) {
|
38 |
+
global $bp;
|
39 |
+
|
40 |
+
$notifications = BP_Core_Notification::get_all_for_user( $user_id );
|
41 |
+
|
42 |
+
/* Group notifications by component and component_action and provide totals */
|
43 |
+
for ( $i = 0; $i < count($notifications); $i++ ) {
|
44 |
+
$notification = $notifications[$i];
|
45 |
+
|
46 |
+
$grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( !$grouped_notifications )
|
50 |
+
return false;
|
51 |
+
|
52 |
+
/* Calculated a renderable outcome for each notification type */
|
53 |
+
foreach ( (array)$grouped_notifications as $component_name => $action_arrays ) {
|
54 |
+
if ( !$action_arrays )
|
55 |
+
continue;
|
56 |
+
|
57 |
+
foreach ( (array)$action_arrays as $component_action_name => $component_action_items ) {
|
58 |
+
$action_item_count = count($component_action_items);
|
59 |
+
|
60 |
+
if ( $action_item_count < 1 )
|
61 |
+
continue;
|
62 |
+
|
63 |
+
if ( function_exists( $bp->{$component_name}->format_notification_function ) ) {
|
64 |
+
$renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
return $renderable;
|
70 |
+
}
|
71 |
+
|
72 |
+
function bp_core_delete_notifications_for_user_by_type( $user_id, $component_name, $component_action ) {
|
73 |
+
return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action );
|
74 |
+
}
|
75 |
+
|
76 |
+
function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
|
77 |
+
return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
|
78 |
+
}
|
79 |
+
|
80 |
+
function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
|
81 |
+
return BP_Core_Notification::delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
|
82 |
+
}
|
83 |
+
|
84 |
+
function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
|
85 |
+
return BP_Core_Notification::delete_from_user_by_type( $user_id, $component_name, $component_action );
|
86 |
+
}
|
87 |
+
|
88 |
+
function bp_core_check_notification_access( $user_id, $notification_id ) {
|
89 |
+
if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) )
|
90 |
+
return false;
|
91 |
+
|
92 |
+
return true;
|
93 |
+
}
|
94 |
+
|
95 |
?>
|
bp-core/bp-core-settings.php
CHANGED
@@ -1,198 +1,197 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( !defined( 'BP_SETTINGS_SLUG' ) )
|
4 |
-
define( 'BP_SETTINGS_SLUG', 'settings' );
|
5 |
-
|
6 |
-
function bp_core_add_settings_nav() {
|
7 |
-
global $bp;
|
8 |
-
|
9 |
-
/* Set up settings as a sudo-component for identification and nav selection */
|
10 |
-
$bp->settings->id = 'settings';
|
11 |
-
$bp->settings->slug = BP_SETTINGS_SLUG;
|
12 |
-
|
13 |
-
/* Register this in the active components array */
|
14 |
-
$bp->active_components[$bp->settings->slug] = $bp->settings->id;
|
15 |
-
|
16 |
-
/* Add the settings navigation item */
|
17 |
-
bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => $bp->settings->slug, 'position' => 100, 'show_for_displayed_user' => false, 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );
|
18 |
-
|
19 |
-
$settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
|
20 |
-
|
21 |
-
bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_my_profile() ) );
|
22 |
-
bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
|
23 |
-
|
24 |
-
if ( !
|
25 |
-
bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) );
|
26 |
-
}
|
27 |
-
add_action( '
|
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 |
-
add_action( '
|
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 |
-
<input type="password" name="
|
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 |
-
add_action( '
|
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 |
-
add_action( '
|
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 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !defined( 'BP_SETTINGS_SLUG' ) )
|
4 |
+
define( 'BP_SETTINGS_SLUG', 'settings' );
|
5 |
+
|
6 |
+
function bp_core_add_settings_nav() {
|
7 |
+
global $bp;
|
8 |
+
|
9 |
+
/* Set up settings as a sudo-component for identification and nav selection */
|
10 |
+
$bp->settings->id = 'settings';
|
11 |
+
$bp->settings->slug = BP_SETTINGS_SLUG;
|
12 |
+
|
13 |
+
/* Register this in the active components array */
|
14 |
+
$bp->active_components[$bp->settings->slug] = $bp->settings->id;
|
15 |
+
|
16 |
+
/* Add the settings navigation item */
|
17 |
+
bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => $bp->settings->slug, 'position' => 100, 'show_for_displayed_user' => false, 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );
|
18 |
+
|
19 |
+
$settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
|
20 |
+
|
21 |
+
bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_my_profile() ) );
|
22 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
|
23 |
+
|
24 |
+
if ( !is_super_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )
|
25 |
+
bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) );
|
26 |
+
}
|
27 |
+
add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' );
|
28 |
+
|
29 |
+
/**** GENERAL SETTINGS ****/
|
30 |
+
|
31 |
+
function bp_core_screen_general_settings() {
|
32 |
+
global $current_user, $bp_settings_updated, $pass_error;
|
33 |
+
|
34 |
+
$bp_settings_updated = false;
|
35 |
+
$pass_error = false;
|
36 |
+
|
37 |
+
if ( isset($_POST['submit']) ) {
|
38 |
+
check_admin_referer('bp_settings_general');
|
39 |
+
|
40 |
+
require_once( WPINC . '/registration.php' );
|
41 |
+
|
42 |
+
// Form has been submitted and nonce checks out, lets do it.
|
43 |
+
|
44 |
+
if ( $_POST['email'] != '' )
|
45 |
+
$current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
|
46 |
+
|
47 |
+
if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
|
48 |
+
if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
|
49 |
+
$current_user->user_pass = $_POST['pass1'];
|
50 |
+
else
|
51 |
+
$pass_error = true;
|
52 |
+
} else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
|
53 |
+
$pass_error = true;
|
54 |
+
} else {
|
55 |
+
unset( $current_user->user_pass );
|
56 |
+
}
|
57 |
+
|
58 |
+
if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
|
59 |
+
$bp_settings_updated = true;
|
60 |
+
}
|
61 |
+
|
62 |
+
add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
|
63 |
+
add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
|
64 |
+
|
65 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
function bp_core_screen_general_settings_title() {
|
69 |
+
_e( 'General Settings', 'buddypress' );
|
70 |
+
}
|
71 |
+
|
72 |
+
function bp_core_screen_general_settings_content() {
|
73 |
+
global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
|
74 |
+
|
75 |
+
<?php if ( $bp_settings_updated && !$pass_error ) { ?>
|
76 |
+
<div id="message" class="updated fade">
|
77 |
+
<p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
|
78 |
+
</div>
|
79 |
+
<?php } ?>
|
80 |
+
|
81 |
+
<?php if ( $pass_error && !$bp_settings_updated ) { ?>
|
82 |
+
<div id="message" class="error fade">
|
83 |
+
<p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
|
84 |
+
</div>
|
85 |
+
<?php } ?>
|
86 |
+
|
87 |
+
<form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
|
88 |
+
<label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
|
89 |
+
<input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" />
|
90 |
+
|
91 |
+
<label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
|
92 |
+
<input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> <?php _e( 'New Password', 'buddypress' ) ?><br />
|
93 |
+
<input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> <?php _e( 'Repeat New Password', 'buddypress' ) ?>
|
94 |
+
|
95 |
+
<div class="submit">
|
96 |
+
<input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
|
97 |
+
</div>
|
98 |
+
|
99 |
+
<?php wp_nonce_field('bp_settings_general') ?>
|
100 |
+
</form>
|
101 |
+
<?php
|
102 |
+
}
|
103 |
+
|
104 |
+
/***** NOTIFICATION SETTINGS ******/
|
105 |
+
|
106 |
+
function bp_core_screen_notification_settings() {
|
107 |
+
global $current_user, $bp_settings_updated;
|
108 |
+
|
109 |
+
$bp_settings_updated = false;
|
110 |
+
|
111 |
+
if ( $_POST['submit'] ) {
|
112 |
+
check_admin_referer('bp_settings_notifications');
|
113 |
+
|
114 |
+
if ( $_POST['notifications'] ) {
|
115 |
+
foreach ( (array)$_POST['notifications'] as $key => $value ) {
|
116 |
+
update_user_meta( (int)$current_user->id, $key, $value );
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
$bp_settings_updated = true;
|
121 |
+
}
|
122 |
+
|
123 |
+
add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );
|
124 |
+
add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
|
125 |
+
|
126 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
127 |
+
}
|
128 |
+
|
129 |
+
function bp_core_screen_notification_settings_title() {
|
130 |
+
_e( 'Notification Settings', 'buddypress' );
|
131 |
+
}
|
132 |
+
|
133 |
+
function bp_core_screen_notification_settings_content() {
|
134 |
+
global $bp, $current_user, $bp_settings_updated; ?>
|
135 |
+
|
136 |
+
<?php if ( $bp_settings_updated ) { ?>
|
137 |
+
<div id="message" class="updated fade">
|
138 |
+
<p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
|
139 |
+
</div>
|
140 |
+
<?php } ?>
|
141 |
+
|
142 |
+
<form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
|
143 |
+
<h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
|
144 |
+
<p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
|
145 |
+
|
146 |
+
<?php do_action( 'bp_notification_settings' ) ?>
|
147 |
+
|
148 |
+
<div class="submit">
|
149 |
+
<input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
|
150 |
+
</div>
|
151 |
+
|
152 |
+
<?php wp_nonce_field('bp_settings_notifications') ?>
|
153 |
+
|
154 |
+
</form>
|
155 |
+
<?php
|
156 |
+
}
|
157 |
+
|
158 |
+
/**** DELETE ACCOUNT ****/
|
159 |
+
|
160 |
+
function bp_core_screen_delete_account() {
|
161 |
+
if ( isset( $_POST['delete-account-understand'] ) ) {
|
162 |
+
check_admin_referer( 'delete-account' );
|
163 |
+
|
164 |
+
// delete the users account
|
165 |
+
if ( bp_core_delete_account() )
|
166 |
+
bp_core_redirect( site_url() );
|
167 |
+
}
|
168 |
+
|
169 |
+
add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' );
|
170 |
+
add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
|
171 |
+
|
172 |
+
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
173 |
+
}
|
174 |
+
|
175 |
+
function bp_core_screen_delete_account_title() {
|
176 |
+
_e( 'Delete Account', 'buddypress' );
|
177 |
+
}
|
178 |
+
|
179 |
+
function bp_core_screen_delete_account_content() {
|
180 |
+
global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
|
181 |
+
|
182 |
+
<form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/delete-account'; ?>" name="account-delete-form" id="account-delete-form" class="standard-form" method="post">
|
183 |
+
|
184 |
+
<div id="message" class="info">
|
185 |
+
<p><?php _e( 'WARNING: Deleting your account will completely remove ALL content associated with it. There is no way back, please be careful with this option.', 'buddypress' ); ?></p>
|
186 |
+
</div>
|
187 |
+
|
188 |
+
<input type="checkbox" name="delete-account-understand" id="delete-account-understand" value="1" onclick="if(this.checked) { document.getElementById('delete-account-button').disabled = ''; } else { document.getElementById('delete-account-button').disabled = 'disabled'; }" /> <?php _e( 'I understand the consequences of deleting my account.', 'buddypress' ); ?>
|
189 |
+
|
190 |
+
<div class="submit">
|
191 |
+
<input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> →" id="delete-account-button" name="delete-account-button" />
|
192 |
+
</div>
|
193 |
+
|
194 |
+
<?php wp_nonce_field('delete-account') ?>
|
195 |
+
</form>
|
196 |
+
<?php
|
197 |
+
}
|
|
bp-core/bp-core-signup.php
CHANGED
@@ -1,625 +1,625 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/********************************************************************************
|
4 |
-
* Screen Functions
|
5 |
-
*
|
6 |
-
* Screen functions are the controllers of BuddyPress. They will execute when their
|
7 |
-
* specific URL is caught. They will first save or manipulate data using business
|
8 |
-
* functions, then pass on the user to a template file.
|
9 |
-
*/
|
10 |
-
|
11 |
-
function bp_core_screen_signup() {
|
12 |
-
global $bp, $wpdb;
|
13 |
-
|
14 |
-
if ( $bp->current_component != BP_REGISTER_SLUG )
|
15 |
-
return false;
|
16 |
-
|
17 |
-
/* If the user is logged in, redirect away from here */
|
18 |
-
if ( is_user_logged_in() )
|
19 |
-
bp_core_redirect( $bp->root_domain );
|
20 |
-
|
21 |
-
/* If signups are disabled, just re-direct */
|
22 |
-
if ( !bp_get_signup_allowed() )
|
23 |
-
bp_core_redirect( $bp->root_domain );
|
24 |
-
|
25 |
-
$bp->signup->step = 'request-details';
|
26 |
-
|
27 |
-
/* If the signup page is submitted, validate and save */
|
28 |
-
if ( isset( $_POST['signup_submit'] ) ) {
|
29 |
-
|
30 |
-
/* Check the nonce */
|
31 |
-
check_admin_referer( 'bp_new_signup' );
|
32 |
-
|
33 |
-
require_once( ABSPATH . WPINC . '/registration.php' );
|
34 |
-
|
35 |
-
/* Check the base account details for problems */
|
36 |
-
$account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
|
37 |
-
|
38 |
-
/* If there are errors with account details, set them for display */
|
39 |
-
if ( !empty( $account_details['errors']->errors['user_name'] ) )
|
40 |
-
$bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
|
41 |
-
|
42 |
-
if ( !empty( $account_details['errors']->errors['user_email'] ) )
|
43 |
-
$bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
|
44 |
-
|
45 |
-
/* Check that both password fields are filled in */
|
46 |
-
if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
|
47 |
-
$bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
|
48 |
-
|
49 |
-
/* Check that the passwords match */
|
50 |
-
if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
|
51 |
-
$bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
|
52 |
-
|
53 |
-
$bp->signup->username = $_POST['signup_username'];
|
54 |
-
$bp->signup->email = $_POST['signup_email'];
|
55 |
-
|
56 |
-
/* Now we've checked account details, we can check profile information */
|
57 |
-
if ( function_exists( 'xprofile_check_is_required_field' ) ) {
|
58 |
-
|
59 |
-
/* Make sure hidden field is passed and populated */
|
60 |
-
if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
|
61 |
-
|
62 |
-
/* Let's compact any profile field info into an array */
|
63 |
-
$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
|
64 |
-
|
65 |
-
/* Loop through the posted fields formatting any datebox values then validate the field */
|
66 |
-
foreach ( (array) $profile_field_ids as $field_id ) {
|
67 |
-
if ( !isset( $_POST['field_' . $field_id] ) ) {
|
68 |
-
if ( isset( $_POST['field_' . $field_id . '_day'] ) )
|
69 |
-
$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
|
70 |
-
}
|
71 |
-
|
72 |
-
/* Create errors for required fields without values */
|
73 |
-
if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
|
74 |
-
$bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
|
75 |
-
}
|
76 |
-
|
77 |
-
/* This situation doesn't naturally occur so bounce to website root */
|
78 |
-
} else {
|
79 |
-
bp_core_redirect( $bp->root_domain );
|
80 |
-
}
|
81 |
-
}
|
82 |
-
|
83 |
-
/* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
|
84 |
-
if ( isset( $_POST['signup_with_blog'] ) ) {
|
85 |
-
$active_signup = $bp->site_options['registration'];
|
86 |
-
|
87 |
-
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
|
88 |
-
$blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
|
89 |
-
|
90 |
-
/* If there are errors with blog details, set them for display */
|
91 |
-
if ( !empty( $blog_details['errors']->errors['blogname'] ) )
|
92 |
-
$bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
|
93 |
-
|
94 |
-
if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
|
95 |
-
$bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
do_action( 'bp_signup_validate' );
|
100 |
-
|
101 |
-
/* Add any errors to the action for the field in the template for display. */
|
102 |
-
if ( !empty( $bp->signup->errors ) ) {
|
103 |
-
foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
|
104 |
-
add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
|
105 |
-
} else {
|
106 |
-
$bp->signup->step = 'save-details';
|
107 |
-
|
108 |
-
/* No errors! Let's register those deets. */
|
109 |
-
$active_signup = $bp->site_options['registration'];
|
110 |
-
|
111 |
-
if ( 'none' != $active_signup ) {
|
112 |
-
|
113 |
-
/* Let's compact any profile field info into usermeta */
|
114 |
-
$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
|
115 |
-
|
116 |
-
/* Loop through the posted fields formatting any datebox values then add to usermeta */
|
117 |
-
foreach ( (array) $profile_field_ids as $field_id ) {
|
118 |
-
if ( !isset( $_POST['field_' . $field_id] ) ) {
|
119 |
-
if ( isset( $_POST['field_' . $field_id . '_day'] ) )
|
120 |
-
$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
|
121 |
-
}
|
122 |
-
|
123 |
-
if ( !empty( $_POST['field_' . $field_id] ) )
|
124 |
-
$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
|
125 |
-
}
|
126 |
-
|
127 |
-
/* Store the profile field ID's in usermeta */
|
128 |
-
$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
|
129 |
-
|
130 |
-
/* Hash and store the password */
|
131 |
-
$usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
|
132 |
-
|
133 |
-
/* If the user decided to create a blog, save those details to usermeta */
|
134 |
-
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
|
135 |
-
$usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
|
136 |
-
}
|
137 |
-
|
138 |
-
$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
|
139 |
-
|
140 |
-
/* Finally, sign up the user and/or blog */
|
141 |
-
if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
|
142 |
-
bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
|
143 |
-
else {
|
144 |
-
bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
|
145 |
-
}
|
146 |
-
|
147 |
-
$bp->signup->step = 'completed-confirmation';
|
148 |
-
}
|
149 |
-
|
150 |
-
do_action( 'bp_complete_signup' );
|
151 |
-
}
|
152 |
-
|
153 |
-
}
|
154 |
-
|
155 |
-
$bp->avatar_admin->step = 'upload-image';
|
156 |
-
|
157 |
-
/* If user has uploaded a new avatar */
|
158 |
-
if ( !empty( $_FILES ) ) {
|
159 |
-
|
160 |
-
/* Check the nonce */
|
161 |
-
check_admin_referer( 'bp_avatar_upload' );
|
162 |
-
|
163 |
-
$bp->signup->step = 'completed-confirmation';
|
164 |
-
|
165 |
-
if ( bp_core_is_multisite() ) {
|
166 |
-
/* Get the activation key */
|
167 |
-
if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
|
168 |
-
bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
|
169 |
-
} else {
|
170 |
-
/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
|
171 |
-
$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
|
172 |
-
}
|
173 |
-
} else {
|
174 |
-
$user_id = bp_core_get_userid( $_POST['signup_username'] );
|
175 |
-
$bp->signup->avatar_dir = wp_hash( $user_id );
|
176 |
-
}
|
177 |
-
|
178 |
-
/* Pass the file to the avatar upload handler */
|
179 |
-
if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
|
180 |
-
$bp->avatar_admin->step = 'crop-image';
|
181 |
-
|
182 |
-
/* Make sure we include the jQuery jCrop file for image cropping */
|
183 |
-
add_action( 'wp', 'bp_core_add_jquery_cropper' );
|
184 |
-
}
|
185 |
-
}
|
186 |
-
|
187 |
-
/* If the image cropping is done, crop the image and save a full/thumb version */
|
188 |
-
if ( isset( $_POST['avatar-crop-submit'] ) ) {
|
189 |
-
|
190 |
-
/* Check the nonce */
|
191 |
-
check_admin_referer( 'bp_avatar_cropstore' );
|
192 |
-
|
193 |
-
/* Reset the avatar step so we can show the upload form again if needed */
|
194 |
-
$bp->signup->step = 'completed-confirmation';
|
195 |
-
$bp->avatar_admin->step = 'upload-image';
|
196 |
-
|
197 |
-
if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
|
198 |
-
bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
|
199 |
-
else
|
200 |
-
bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
|
201 |
-
}
|
202 |
-
bp_core_load_template( 'registration/register' );
|
203 |
-
}
|
204 |
-
add_action( 'wp', 'bp_core_screen_signup', 3 );
|
205 |
-
|
206 |
-
function bp_core_screen_activation() {
|
207 |
-
global $bp, $wpdb;
|
208 |
-
|
209 |
-
if ( BP_ACTIVATION_SLUG != $bp->current_component )
|
210 |
-
return false;
|
211 |
-
|
212 |
-
/* Check if an activation key has been passed */
|
213 |
-
if ( isset( $_GET['key'] ) ) {
|
214 |
-
|
215 |
-
require_once( ABSPATH . WPINC . '/registration.php' );
|
216 |
-
|
217 |
-
/* Activate the signup */
|
218 |
-
$user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
|
219 |
-
|
220 |
-
/* If there was errors, add a message and redirect */
|
221 |
-
if ( $user->errors ) {
|
222 |
-
bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
|
223 |
-
bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
|
224 |
-
}
|
225 |
-
|
226 |
-
/* Check for an uploaded avatar and move that to the correct user folder */
|
227 |
-
if ( bp_core_is_multisite() )
|
228 |
-
$hashed_key = wp_hash( $_GET['key'] );
|
229 |
-
else
|
230 |
-
$hashed_key = wp_hash( $user );
|
231 |
-
|
232 |
-
/* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
|
233 |
-
if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
|
234 |
-
@rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
|
235 |
-
|
236 |
-
bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
|
237 |
-
|
238 |
-
$bp->activation_complete = true;
|
239 |
-
}
|
240 |
-
|
241 |
-
if ( '' != locate_template( array( 'registration/activate' ), false ) )
|
242 |
-
bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
|
243 |
-
else
|
244 |
-
bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
|
245 |
-
}
|
246 |
-
add_action( 'wp', 'bp_core_screen_activation', 3 );
|
247 |
-
|
248 |
-
|
249 |
-
/********************************************************************************
|
250 |
-
* Business Functions
|
251 |
-
*
|
252 |
-
* Business functions are where all the magic happens in BuddyPress. They will
|
253 |
-
* handle the actual saving or manipulation of information. Usually they will
|
254 |
-
* hand off to a database class for data access, then return
|
255 |
-
* true or false on success or failure.
|
256 |
-
*/
|
257 |
-
|
258 |
-
/**
|
259 |
-
* bp_core_flush_illegal_names()
|
260 |
-
*
|
261 |
-
* Flush illegal names by getting and setting 'illegal_names' site option
|
262 |
-
*/
|
263 |
-
function bp_core_flush_illegal_names() {
|
264 |
-
$illegal_names = get_site_option( 'illegal_names' );
|
265 |
-
update_site_option( 'illegal_names', $illegal_names );
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* bp_core_illegal_names()
|
270 |
-
*
|
271 |
-
* Filter the illegal_names site option and make sure it includes a few
|
272 |
-
* specific BuddyPress and Multi-site slugs
|
273 |
-
*
|
274 |
-
* @param array|string $value Illegal names from field
|
275 |
-
* @param array|string $oldvalue The value as it is currently
|
276 |
-
* @return array Merged and unique array of illegal names
|
277 |
-
*/
|
278 |
-
function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
|
279 |
-
|
280 |
-
// Make sure $value is array
|
281 |
-
if ( empty( $value ) )
|
282 |
-
$db_illegal_names = array();
|
283 |
-
if ( is_array( $value ) )
|
284 |
-
$db_illegal_names = $value;
|
285 |
-
elseif ( is_string( $value ) )
|
286 |
-
$db_illegal_names = implode( ' ', $names );
|
287 |
-
|
288 |
-
// Add our slugs to the array and allow them to be filtered
|
289 |
-
$filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
|
290 |
-
|
291 |
-
// Merge the arrays together
|
292 |
-
$merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
|
293 |
-
|
294 |
-
// Remove duplicates
|
295 |
-
$illegal_names = array_unique( (array)$merged_names );
|
296 |
-
|
297 |
-
return apply_filters( 'bp_core_illegal_names', $illegal_names );
|
298 |
-
}
|
299 |
-
add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
|
300 |
-
|
301 |
-
/**
|
302 |
-
* bp_core_validate_user_signup()
|
303 |
-
*
|
304 |
-
* Validate a user name and email address when creating a new user.
|
305 |
-
*
|
306 |
-
* @global object $wpdb DB Layer
|
307 |
-
* @param string $user_name Username to validate
|
308 |
-
* @param string $user_email Email address to validate
|
309 |
-
* @return array Results of user validation including errors, if any
|
310 |
-
*/
|
311 |
-
function bp_core_validate_user_signup( $user_name, $user_email ) {
|
312 |
-
global $wpdb;
|
313 |
-
|
314 |
-
$errors = new WP_Error();
|
315 |
-
$user_email = sanitize_email( $user_email );
|
316 |
-
|
317 |
-
if ( empty( $user_name ) )
|
318 |
-
$errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
|
319 |
-
|
320 |
-
$maybe = array();
|
321 |
-
preg_match( "/[a-z0-9]+/", $user_name, $maybe );
|
322 |
-
|
323 |
-
// Make sure illegal names include BuddyPress slugs and values
|
324 |
-
bp_core_flush_illegal_names();
|
325 |
-
|
326 |
-
if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
|
327 |
-
$errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
|
328 |
-
|
329 |
-
if( strlen( $user_name ) < 4 )
|
330 |
-
$errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
|
331 |
-
|
332 |
-
if ( strpos( ' ' . $user_name, '_' ) != false )
|
333 |
-
$errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
|
334 |
-
|
335 |
-
/* Is the user_name all numeric? */
|
336 |
-
$match = array();
|
337 |
-
preg_match( '/[0-9]*/', $user_name, $match );
|
338 |
-
|
339 |
-
if ( $match[0] == $user_name )
|
340 |
-
$errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
|
341 |
-
|
342 |
-
if ( !is_email( $user_email ) )
|
343 |
-
$errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
|
344 |
-
|
345 |
-
$limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
|
346 |
-
|
347 |
-
if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
|
348 |
-
$emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
|
349 |
-
|
350 |
-
if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
|
351 |
-
$errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
|
352 |
-
}
|
353 |
-
|
354 |
-
/* Check if the username has been used already. */
|
355 |
-
if ( username_exists( $user_name ) )
|
356 |
-
$errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
|
357 |
-
|
358 |
-
/* Check if the email address has been used already. */
|
359 |
-
if ( email_exists( $user_email ) )
|
360 |
-
$errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
|
361 |
-
|
362 |
-
$result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
|
363 |
-
|
364 |
-
/* Apply WPMU legacy filter */
|
365 |
-
$result = apply_filters( 'wpmu_validate_user_signup', $result );
|
366 |
-
|
367 |
-
return apply_filters( 'bp_core_validate_user_signup', $result );
|
368 |
-
}
|
369 |
-
|
370 |
-
function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
|
371 |
-
if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
|
372 |
-
return false;
|
373 |
-
|
374 |
-
return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
|
375 |
-
}
|
376 |
-
|
377 |
-
function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
|
378 |
-
global $bp, $wpdb;
|
379 |
-
|
380 |
-
/* Multisite installs have their own install procedure */
|
381 |
-
if ( bp_core_is_multisite() ) {
|
382 |
-
wpmu_signup_user( $user_login, $user_email, $usermeta );
|
383 |
-
|
384 |
-
} else {
|
385 |
-
$errors = new WP_Error();
|
386 |
-
|
387 |
-
$user_id = wp_insert_user( array(
|
388 |
-
'user_login' => $user_login,
|
389 |
-
'user_pass' => $user_password,
|
390 |
-
'display_name' => sanitize_title( $user_login ),
|
391 |
-
'user_email' => $user_email
|
392 |
-
) );
|
393 |
-
|
394 |
-
if ( !$user_id ) {
|
395 |
-
$errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
|
396 |
-
return $errors;
|
397 |
-
}
|
398 |
-
|
399 |
-
/* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
|
400 |
-
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
|
401 |
-
|
402 |
-
/* Set any profile data */
|
403 |
-
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
404 |
-
if ( !empty( $usermeta['profile_field_ids'] ) ) {
|
405 |
-
$profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
|
406 |
-
|
407 |
-
foreach( (array)$profile_field_ids as $field_id ) {
|
408 |
-
$current_field = $usermeta["field_{$field_id}"];
|
409 |
-
|
410 |
-
if ( !empty( $current_field ) )
|
411 |
-
xprofile_set_field_data( $field_id, $user_id, $current_field );
|
412 |
-
}
|
413 |
-
}
|
414 |
-
}
|
415 |
-
}
|
416 |
-
$bp->signup->username = $user_login;
|
417 |
-
|
418 |
-
/***
|
419 |
-
* Now generate an activation key and send an email to the user so they can activate their account
|
420 |
-
* and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
|
421 |
-
*
|
422 |
-
* To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false.
|
423 |
-
*/
|
424 |
-
if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
|
425 |
-
if ( !bp_core_is_multisite() ) {
|
426 |
-
$activation_key = wp_hash( $user_id );
|
427 |
-
|
428 |
-
bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
|
429 |
-
}
|
430 |
-
}
|
431 |
-
|
432 |
-
do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
|
433 |
-
|
434 |
-
return $user_id;
|
435 |
-
}
|
436 |
-
|
437 |
-
function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
|
438 |
-
if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
|
439 |
-
return false;
|
440 |
-
|
441 |
-
return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
|
442 |
-
}
|
443 |
-
|
444 |
-
function bp_core_activate_signup( $key ) {
|
445 |
-
global $bp, $wpdb;
|
446 |
-
|
447 |
-
$user = false;
|
448 |
-
|
449 |
-
/* Multisite installs have their own activation routine */
|
450 |
-
if ( bp_core_is_multisite() ) {
|
451 |
-
$user = wpmu_activate_signup( $key );
|
452 |
-
|
453 |
-
/* If there was errors, add a message and redirect */
|
454 |
-
if ( $user->errors ) {
|
455 |
-
bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
|
456 |
-
bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
|
457 |
-
}
|
458 |
-
|
459 |
-
$user_id = $user['user_id'];
|
460 |
-
|
461 |
-
/* Set any profile data */
|
462 |
-
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
463 |
-
if ( !empty( $user['meta']['profile_field_ids'] ) ) {
|
464 |
-
$profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
|
465 |
-
|
466 |
-
foreach( (array)$profile_field_ids as $field_id ) {
|
467 |
-
$current_field = $user['meta']["field_{$field_id}"];
|
468 |
-
|
469 |
-
if ( !empty( $current_field ) )
|
470 |
-
xprofile_set_field_data( $field_id, $user_id, $current_field );
|
471 |
-
}
|
472 |
-
}
|
473 |
-
}
|
474 |
-
|
475 |
-
} else {
|
476 |
-
/* Get the user_id based on the $key */
|
477 |
-
$user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
|
478 |
-
|
479 |
-
if ( empty( $user_id ) )
|
480 |
-
return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
|
481 |
-
|
482 |
-
/* Change the user's status so they become active */
|
483 |
-
if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
|
484 |
-
return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
|
485 |
-
|
486 |
-
/* Notify the site admin of a new user registration */
|
487 |
-
wp_new_user_notification( $user_id );
|
488 |
-
|
489 |
-
/* Remove the activation key meta */
|
490 |
-
|
491 |
-
}
|
492 |
-
|
493 |
-
/* Update the user_url and display_name */
|
494 |
-
wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
|
495 |
-
|
496 |
-
/* Add a last active entry */
|
497 |
-
|
498 |
-
|
499 |
-
/* Set the password on multisite installs */
|
500 |
-
if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
|
501 |
-
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
|
502 |
-
|
503 |
-
/* Delete the total member cache */
|
504 |
-
wp_cache_delete( 'bp_total_member_count', 'bp' );
|
505 |
-
|
506 |
-
do_action( 'bp_core_activated_user', $user_id, $key, $user );
|
507 |
-
|
508 |
-
return $user_id;
|
509 |
-
}
|
510 |
-
|
511 |
-
function bp_core_new_user_activity( $user ) {
|
512 |
-
if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
|
513 |
-
return false;
|
514 |
-
|
515 |
-
if ( is_array( $user ) )
|
516 |
-
$user_id = $user['user_id'];
|
517 |
-
else
|
518 |
-
$user_id = $user;
|
519 |
-
|
520 |
-
if ( empty( $user_id ) )
|
521 |
-
return false;
|
522 |
-
|
523 |
-
$userlink = bp_core_get_userlink( $user_id );
|
524 |
-
|
525 |
-
bp_activity_add( array(
|
526 |
-
'user_id' => $user_id,
|
527 |
-
'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
|
528 |
-
'component' => 'profile',
|
529 |
-
'type' => 'new_member'
|
530 |
-
) );
|
531 |
-
}
|
532 |
-
add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
|
533 |
-
|
534 |
-
function bp_core_map_user_registration( $user_id ) {
|
535 |
-
/* Only map data when the site admin is adding users, not on registration. */
|
536 |
-
if ( !is_admin() )
|
537 |
-
return false;
|
538 |
-
|
539 |
-
/* Add a last active entry */
|
540 |
-
|
541 |
-
|
542 |
-
/* Add the user's fullname to Xprofile */
|
543 |
-
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
544 |
-
$firstname =
|
545 |
-
$lastname = ' ' .
|
546 |
-
$name = $firstname . $lastname;
|
547 |
-
|
548 |
-
if ( empty( $name ) || ' ' == $name )
|
549 |
-
$name =
|
550 |
-
|
551 |
-
xprofile_set_field_data( 1, $user_id, $name );
|
552 |
-
}
|
553 |
-
}
|
554 |
-
add_action( 'user_register', 'bp_core_map_user_registration' );
|
555 |
-
|
556 |
-
function bp_core_signup_avatar_upload_dir() {
|
557 |
-
global $bp;
|
558 |
-
|
559 |
-
if ( !$bp->signup->avatar_dir )
|
560 |
-
return false;
|
561 |
-
|
562 |
-
$path = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
|
563 |
-
$newbdir = $path;
|
564 |
-
|
565 |
-
if ( !file_exists( $path ) )
|
566 |
-
@wp_mkdir_p( $path );
|
567 |
-
|
568 |
-
$newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
|
569 |
-
$newburl = $newurl;
|
570 |
-
$newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
|
571 |
-
|
572 |
-
return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
|
573 |
-
}
|
574 |
-
|
575 |
-
function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
|
576 |
-
$activate_url = bp_get_activation_page() ."?key=$key";
|
577 |
-
$activate_url =
|
578 |
-
$admin_email = get_site_option( "admin_email" );
|
579 |
-
|
580 |
-
if ( empty( $admin_email ) )
|
581 |
-
$admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
|
582 |
-
|
583 |
-
$from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
|
584 |
-
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
|
585 |
-
$message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
|
586 |
-
$subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
|
587 |
-
|
588 |
-
/* Send the message */
|
589 |
-
$to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
|
590 |
-
$subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
|
591 |
-
$message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
|
592 |
-
|
593 |
-
wp_mail( $to, $subject, $message, $message_headers );
|
594 |
-
}
|
595 |
-
|
596 |
-
/* Stop user accounts logging in that have not been activated (user_status = 2) */
|
597 |
-
function bp_core_signup_disable_inactive( $auth_obj, $username ) {
|
598 |
-
global $bp, $wpdb;
|
599 |
-
|
600 |
-
if ( !$user_id = bp_core_get_userid( $username ) )
|
601 |
-
return $auth_obj;
|
602 |
-
|
603 |
-
$user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
|
604 |
-
|
605 |
-
if ( 2 == $user_status )
|
606 |
-
bp_core_redirect( $bp->root_domain );
|
607 |
-
else
|
608 |
-
return $auth_obj;
|
609 |
-
}
|
610 |
-
add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
|
611 |
-
|
612 |
-
/* Kill the wp-signup.php if custom registration signup templates are present */
|
613 |
-
function bp_core_wpsignup_redirect() {
|
614 |
-
if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
|
615 |
-
return false;
|
616 |
-
|
617 |
-
if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
|
618 |
-
bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
|
619 |
-
}
|
620 |
-
if ( bp_core_is_multisite() )
|
621 |
-
add_action( 'wp', 'bp_core_wpsignup_redirect' );
|
622 |
-
else
|
623 |
-
add_action( 'init', 'bp_core_wpsignup_redirect' );
|
624 |
-
|
625 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/********************************************************************************
|
4 |
+
* Screen Functions
|
5 |
+
*
|
6 |
+
* Screen functions are the controllers of BuddyPress. They will execute when their
|
7 |
+
* specific URL is caught. They will first save or manipulate data using business
|
8 |
+
* functions, then pass on the user to a template file.
|
9 |
+
*/
|
10 |
+
|
11 |
+
function bp_core_screen_signup() {
|
12 |
+
global $bp, $wpdb;
|
13 |
+
|
14 |
+
if ( $bp->current_component != BP_REGISTER_SLUG )
|
15 |
+
return false;
|
16 |
+
|
17 |
+
/* If the user is logged in, redirect away from here */
|
18 |
+
if ( is_user_logged_in() )
|
19 |
+
bp_core_redirect( $bp->root_domain );
|
20 |
+
|
21 |
+
/* If signups are disabled, just re-direct */
|
22 |
+
if ( !bp_get_signup_allowed() )
|
23 |
+
bp_core_redirect( $bp->root_domain );
|
24 |
+
|
25 |
+
$bp->signup->step = 'request-details';
|
26 |
+
|
27 |
+
/* If the signup page is submitted, validate and save */
|
28 |
+
if ( isset( $_POST['signup_submit'] ) ) {
|
29 |
+
|
30 |
+
/* Check the nonce */
|
31 |
+
check_admin_referer( 'bp_new_signup' );
|
32 |
+
|
33 |
+
require_once( ABSPATH . WPINC . '/registration.php' );
|
34 |
+
|
35 |
+
/* Check the base account details for problems */
|
36 |
+
$account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
|
37 |
+
|
38 |
+
/* If there are errors with account details, set them for display */
|
39 |
+
if ( !empty( $account_details['errors']->errors['user_name'] ) )
|
40 |
+
$bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
|
41 |
+
|
42 |
+
if ( !empty( $account_details['errors']->errors['user_email'] ) )
|
43 |
+
$bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
|
44 |
+
|
45 |
+
/* Check that both password fields are filled in */
|
46 |
+
if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
|
47 |
+
$bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
|
48 |
+
|
49 |
+
/* Check that the passwords match */
|
50 |
+
if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
|
51 |
+
$bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
|
52 |
+
|
53 |
+
$bp->signup->username = $_POST['signup_username'];
|
54 |
+
$bp->signup->email = $_POST['signup_email'];
|
55 |
+
|
56 |
+
/* Now we've checked account details, we can check profile information */
|
57 |
+
if ( function_exists( 'xprofile_check_is_required_field' ) ) {
|
58 |
+
|
59 |
+
/* Make sure hidden field is passed and populated */
|
60 |
+
if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
|
61 |
+
|
62 |
+
/* Let's compact any profile field info into an array */
|
63 |
+
$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
|
64 |
+
|
65 |
+
/* Loop through the posted fields formatting any datebox values then validate the field */
|
66 |
+
foreach ( (array) $profile_field_ids as $field_id ) {
|
67 |
+
if ( !isset( $_POST['field_' . $field_id] ) ) {
|
68 |
+
if ( isset( $_POST['field_' . $field_id . '_day'] ) )
|
69 |
+
$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
|
70 |
+
}
|
71 |
+
|
72 |
+
/* Create errors for required fields without values */
|
73 |
+
if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
|
74 |
+
$bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
|
75 |
+
}
|
76 |
+
|
77 |
+
/* This situation doesn't naturally occur so bounce to website root */
|
78 |
+
} else {
|
79 |
+
bp_core_redirect( $bp->root_domain );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
/* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
|
84 |
+
if ( isset( $_POST['signup_with_blog'] ) ) {
|
85 |
+
$active_signup = $bp->site_options['registration'];
|
86 |
+
|
87 |
+
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
|
88 |
+
$blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
|
89 |
+
|
90 |
+
/* If there are errors with blog details, set them for display */
|
91 |
+
if ( !empty( $blog_details['errors']->errors['blogname'] ) )
|
92 |
+
$bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
|
93 |
+
|
94 |
+
if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
|
95 |
+
$bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
do_action( 'bp_signup_validate' );
|
100 |
+
|
101 |
+
/* Add any errors to the action for the field in the template for display. */
|
102 |
+
if ( !empty( $bp->signup->errors ) ) {
|
103 |
+
foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
|
104 |
+
add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
|
105 |
+
} else {
|
106 |
+
$bp->signup->step = 'save-details';
|
107 |
+
|
108 |
+
/* No errors! Let's register those deets. */
|
109 |
+
$active_signup = $bp->site_options['registration'];
|
110 |
+
|
111 |
+
if ( 'none' != $active_signup ) {
|
112 |
+
|
113 |
+
/* Let's compact any profile field info into usermeta */
|
114 |
+
$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
|
115 |
+
|
116 |
+
/* Loop through the posted fields formatting any datebox values then add to usermeta */
|
117 |
+
foreach ( (array) $profile_field_ids as $field_id ) {
|
118 |
+
if ( !isset( $_POST['field_' . $field_id] ) ) {
|
119 |
+
if ( isset( $_POST['field_' . $field_id . '_day'] ) )
|
120 |
+
$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
|
121 |
+
}
|
122 |
+
|
123 |
+
if ( !empty( $_POST['field_' . $field_id] ) )
|
124 |
+
$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
|
125 |
+
}
|
126 |
+
|
127 |
+
/* Store the profile field ID's in usermeta */
|
128 |
+
$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
|
129 |
+
|
130 |
+
/* Hash and store the password */
|
131 |
+
$usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
|
132 |
+
|
133 |
+
/* If the user decided to create a blog, save those details to usermeta */
|
134 |
+
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
|
135 |
+
$usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
|
136 |
+
}
|
137 |
+
|
138 |
+
$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
|
139 |
+
|
140 |
+
/* Finally, sign up the user and/or blog */
|
141 |
+
if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
|
142 |
+
bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
|
143 |
+
else {
|
144 |
+
bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
|
145 |
+
}
|
146 |
+
|
147 |
+
$bp->signup->step = 'completed-confirmation';
|
148 |
+
}
|
149 |
+
|
150 |
+
do_action( 'bp_complete_signup' );
|
151 |
+
}
|
152 |
+
|
153 |
+
}
|
154 |
+
|
155 |
+
$bp->avatar_admin->step = 'upload-image';
|
156 |
+
|
157 |
+
/* If user has uploaded a new avatar */
|
158 |
+
if ( !empty( $_FILES ) ) {
|
159 |
+
|
160 |
+
/* Check the nonce */
|
161 |
+
check_admin_referer( 'bp_avatar_upload' );
|
162 |
+
|
163 |
+
$bp->signup->step = 'completed-confirmation';
|
164 |
+
|
165 |
+
if ( bp_core_is_multisite() ) {
|
166 |
+
/* Get the activation key */
|
167 |
+
if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
|
168 |
+
bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
|
169 |
+
} else {
|
170 |
+
/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
|
171 |
+
$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
|
172 |
+
}
|
173 |
+
} else {
|
174 |
+
$user_id = bp_core_get_userid( $_POST['signup_username'] );
|
175 |
+
$bp->signup->avatar_dir = wp_hash( $user_id );
|
176 |
+
}
|
177 |
+
|
178 |
+
/* Pass the file to the avatar upload handler */
|
179 |
+
if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
|
180 |
+
$bp->avatar_admin->step = 'crop-image';
|
181 |
+
|
182 |
+
/* Make sure we include the jQuery jCrop file for image cropping */
|
183 |
+
add_action( 'wp', 'bp_core_add_jquery_cropper' );
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
/* If the image cropping is done, crop the image and save a full/thumb version */
|
188 |
+
if ( isset( $_POST['avatar-crop-submit'] ) ) {
|
189 |
+
|
190 |
+
/* Check the nonce */
|
191 |
+
check_admin_referer( 'bp_avatar_cropstore' );
|
192 |
+
|
193 |
+
/* Reset the avatar step so we can show the upload form again if needed */
|
194 |
+
$bp->signup->step = 'completed-confirmation';
|
195 |
+
$bp->avatar_admin->step = 'upload-image';
|
196 |
+
|
197 |
+
if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
|
198 |
+
bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
|
199 |
+
else
|
200 |
+
bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
|
201 |
+
}
|
202 |
+
bp_core_load_template( 'registration/register' );
|
203 |
+
}
|
204 |
+
add_action( 'wp', 'bp_core_screen_signup', 3 );
|
205 |
+
|
206 |
+
function bp_core_screen_activation() {
|
207 |
+
global $bp, $wpdb;
|
208 |
+
|
209 |
+
if ( BP_ACTIVATION_SLUG != $bp->current_component )
|
210 |
+
return false;
|
211 |
+
|
212 |
+
/* Check if an activation key has been passed */
|
213 |
+
if ( isset( $_GET['key'] ) ) {
|
214 |
+
|
215 |
+
require_once( ABSPATH . WPINC . '/registration.php' );
|
216 |
+
|
217 |
+
/* Activate the signup */
|
218 |
+
$user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
|
219 |
+
|
220 |
+
/* If there was errors, add a message and redirect */
|
221 |
+
if ( $user->errors ) {
|
222 |
+
bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
|
223 |
+
bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
|
224 |
+
}
|
225 |
+
|
226 |
+
/* Check for an uploaded avatar and move that to the correct user folder */
|
227 |
+
if ( bp_core_is_multisite() )
|
228 |
+
$hashed_key = wp_hash( $_GET['key'] );
|
229 |
+
else
|
230 |
+
$hashed_key = wp_hash( $user );
|
231 |
+
|
232 |
+
/* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
|
233 |
+
if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
|
234 |
+
@rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
|
235 |
+
|
236 |
+
bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
|
237 |
+
|
238 |
+
$bp->activation_complete = true;
|
239 |
+
}
|
240 |
+
|
241 |
+
if ( '' != locate_template( array( 'registration/activate' ), false ) )
|
242 |
+
bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
|
243 |
+
else
|
244 |
+
bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
|
245 |
+
}
|
246 |
+
add_action( 'wp', 'bp_core_screen_activation', 3 );
|
247 |
+
|
248 |
+
|
249 |
+
/********************************************************************************
|
250 |
+
* Business Functions
|
251 |
+
*
|
252 |
+
* Business functions are where all the magic happens in BuddyPress. They will
|
253 |
+
* handle the actual saving or manipulation of information. Usually they will
|
254 |
+
* hand off to a database class for data access, then return
|
255 |
+
* true or false on success or failure.
|
256 |
+
*/
|
257 |
+
|
258 |
+
/**
|
259 |
+
* bp_core_flush_illegal_names()
|
260 |
+
*
|
261 |
+
* Flush illegal names by getting and setting 'illegal_names' site option
|
262 |
+
*/
|
263 |
+
function bp_core_flush_illegal_names() {
|
264 |
+
$illegal_names = get_site_option( 'illegal_names' );
|
265 |
+
update_site_option( 'illegal_names', $illegal_names );
|
266 |
+
}
|
267 |
+
|
268 |
+
/**
|
269 |
+
* bp_core_illegal_names()
|
270 |
+
*
|
271 |
+
* Filter the illegal_names site option and make sure it includes a few
|
272 |
+
* specific BuddyPress and Multi-site slugs
|
273 |
+
*
|
274 |
+
* @param array|string $value Illegal names from field
|
275 |
+
* @param array|string $oldvalue The value as it is currently
|
276 |
+
* @return array Merged and unique array of illegal names
|
277 |
+
*/
|
278 |
+
function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
|
279 |
+
|
280 |
+
// Make sure $value is array
|
281 |
+
if ( empty( $value ) )
|
282 |
+
$db_illegal_names = array();
|
283 |
+
if ( is_array( $value ) )
|
284 |
+
$db_illegal_names = $value;
|
285 |
+
elseif ( is_string( $value ) )
|
286 |
+
$db_illegal_names = implode( ' ', $names );
|
287 |
+
|
288 |
+
// Add our slugs to the array and allow them to be filtered
|
289 |
+
$filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
|
290 |
+
|
291 |
+
// Merge the arrays together
|
292 |
+
$merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
|
293 |
+
|
294 |
+
// Remove duplicates
|
295 |
+
$illegal_names = array_unique( (array)$merged_names );
|
296 |
+
|
297 |
+
return apply_filters( 'bp_core_illegal_names', $illegal_names );
|
298 |
+
}
|
299 |
+
add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
|
300 |
+
|
301 |
+
/**
|
302 |
+
* bp_core_validate_user_signup()
|
303 |
+
*
|
304 |
+
* Validate a user name and email address when creating a new user.
|
305 |
+
*
|
306 |
+
* @global object $wpdb DB Layer
|
307 |
+
* @param string $user_name Username to validate
|
308 |
+
* @param string $user_email Email address to validate
|
309 |
+
* @return array Results of user validation including errors, if any
|
310 |
+
*/
|
311 |
+
function bp_core_validate_user_signup( $user_name, $user_email ) {
|
312 |
+
global $wpdb;
|
313 |
+
|
314 |
+
$errors = new WP_Error();
|
315 |
+
$user_email = sanitize_email( $user_email );
|
316 |
+
|
317 |
+
if ( empty( $user_name ) )
|
318 |
+
$errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
|
319 |
+
|
320 |
+
$maybe = array();
|
321 |
+
preg_match( "/[a-z0-9]+/", $user_name, $maybe );
|
322 |
+
|
323 |
+
// Make sure illegal names include BuddyPress slugs and values
|
324 |
+
bp_core_flush_illegal_names();
|
325 |
+
|
326 |
+
if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
|
327 |
+
$errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
|
328 |
+
|
329 |
+
if( strlen( $user_name ) < 4 )
|
330 |
+
$errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
|
331 |
+
|
332 |
+
if ( strpos( ' ' . $user_name, '_' ) != false )
|
333 |
+
$errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
|
334 |
+
|
335 |
+
/* Is the user_name all numeric? */
|
336 |
+
$match = array();
|
337 |
+
preg_match( '/[0-9]*/', $user_name, $match );
|
338 |
+
|
339 |
+
if ( $match[0] == $user_name )
|
340 |
+
$errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
|
341 |
+
|
342 |
+
if ( !is_email( $user_email ) )
|
343 |
+
$errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
|
344 |
+
|
345 |
+
$limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
|
346 |
+
|
347 |
+
if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
|
348 |
+
$emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
|
349 |
+
|
350 |
+
if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
|
351 |
+
$errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
|
352 |
+
}
|
353 |
+
|
354 |
+
/* Check if the username has been used already. */
|
355 |
+
if ( username_exists( $user_name ) )
|
356 |
+
$errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
|
357 |
+
|
358 |
+
/* Check if the email address has been used already. */
|
359 |
+
if ( email_exists( $user_email ) )
|
360 |
+
$errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
|
361 |
+
|
362 |
+
$result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
|
363 |
+
|
364 |
+
/* Apply WPMU legacy filter */
|
365 |
+
$result = apply_filters( 'wpmu_validate_user_signup', $result );
|
366 |
+
|
367 |
+
return apply_filters( 'bp_core_validate_user_signup', $result );
|
368 |
+
}
|
369 |
+
|
370 |
+
function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
|
371 |
+
if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
|
372 |
+
return false;
|
373 |
+
|
374 |
+
return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
|
375 |
+
}
|
376 |
+
|
377 |
+
function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
|
378 |
+
global $bp, $wpdb;
|
379 |
+
|
380 |
+
/* Multisite installs have their own install procedure */
|
381 |
+
if ( bp_core_is_multisite() ) {
|
382 |
+
wpmu_signup_user( $user_login, $user_email, $usermeta );
|
383 |
+
|
384 |
+
} else {
|
385 |
+
$errors = new WP_Error();
|
386 |
+
|
387 |
+
$user_id = wp_insert_user( array(
|
388 |
+
'user_login' => $user_login,
|
389 |
+
'user_pass' => $user_password,
|
390 |
+
'display_name' => sanitize_title( $user_login ),
|
391 |
+
'user_email' => $user_email
|
392 |
+
) );
|
393 |
+
|
394 |
+
if ( !$user_id ) {
|
395 |
+
$errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
|
396 |
+
return $errors;
|
397 |
+
}
|
398 |
+
|
399 |
+
/* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
|
400 |
+
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
|
401 |
+
|
402 |
+
/* Set any profile data */
|
403 |
+
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
404 |
+
if ( !empty( $usermeta['profile_field_ids'] ) ) {
|
405 |
+
$profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
|
406 |
+
|
407 |
+
foreach( (array)$profile_field_ids as $field_id ) {
|
408 |
+
$current_field = $usermeta["field_{$field_id}"];
|
409 |
+
|
410 |
+
if ( !empty( $current_field ) )
|
411 |
+
xprofile_set_field_data( $field_id, $user_id, $current_field );
|
412 |
+
}
|
413 |
+
}
|
414 |
+
}
|
415 |
+
}
|
416 |
+
$bp->signup->username = $user_login;
|
417 |
+
|
418 |
+
/***
|
419 |
+
* Now generate an activation key and send an email to the user so they can activate their account
|
420 |
+
* and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
|
421 |
+
*
|
422 |
+
* To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false.
|
423 |
+
*/
|
424 |
+
if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
|
425 |
+
if ( !bp_core_is_multisite() ) {
|
426 |
+
$activation_key = wp_hash( $user_id );
|
427 |
+
update_user_meta( $user_id, 'activation_key', $activation_key );
|
428 |
+
bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
|
433 |
+
|
434 |
+
return $user_id;
|
435 |
+
}
|
436 |
+
|
437 |
+
function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
|
438 |
+
if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
|
439 |
+
return false;
|
440 |
+
|
441 |
+
return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
|
442 |
+
}
|
443 |
+
|
444 |
+
function bp_core_activate_signup( $key ) {
|
445 |
+
global $bp, $wpdb;
|
446 |
+
|
447 |
+
$user = false;
|
448 |
+
|
449 |
+
/* Multisite installs have their own activation routine */
|
450 |
+
if ( bp_core_is_multisite() ) {
|
451 |
+
$user = wpmu_activate_signup( $key );
|
452 |
+
|
453 |
+
/* If there was errors, add a message and redirect */
|
454 |
+
if ( $user->errors ) {
|
455 |
+
bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
|
456 |
+
bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
|
457 |
+
}
|
458 |
+
|
459 |
+
$user_id = $user['user_id'];
|
460 |
+
|
461 |
+
/* Set any profile data */
|
462 |
+
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
463 |
+
if ( !empty( $user['meta']['profile_field_ids'] ) ) {
|
464 |
+
$profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
|
465 |
+
|
466 |
+
foreach( (array)$profile_field_ids as $field_id ) {
|
467 |
+
$current_field = $user['meta']["field_{$field_id}"];
|
468 |
+
|
469 |
+
if ( !empty( $current_field ) )
|
470 |
+
xprofile_set_field_data( $field_id, $user_id, $current_field );
|
471 |
+
}
|
472 |
+
}
|
473 |
+
}
|
474 |
+
|
475 |
+
} else {
|
476 |
+
/* Get the user_id based on the $key */
|
477 |
+
$user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) );
|
478 |
+
|
479 |
+
if ( empty( $user_id ) )
|
480 |
+
return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
|
481 |
+
|
482 |
+
/* Change the user's status so they become active */
|
483 |
+
if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
|
484 |
+
return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
|
485 |
+
|
486 |
+
/* Notify the site admin of a new user registration */
|
487 |
+
wp_new_user_notification( $user_id );
|
488 |
+
|
489 |
+
/* Remove the activation key meta */
|
490 |
+
delete_user_meta( $user_id, 'activation_key' );
|
491 |
+
}
|
492 |
+
|
493 |
+
/* Update the user_url and display_name */
|
494 |
+
wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
|
495 |
+
|
496 |
+
/* Add a last active entry */
|
497 |
+
update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
|
498 |
+
|
499 |
+
/* Set the password on multisite installs */
|
500 |
+
if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
|
501 |
+
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
|
502 |
+
|
503 |
+
/* Delete the total member cache */
|
504 |
+
wp_cache_delete( 'bp_total_member_count', 'bp' );
|
505 |
+
|
506 |
+
do_action( 'bp_core_activated_user', $user_id, $key, $user );
|
507 |
+
|
508 |
+
return $user_id;
|
509 |
+
}
|
510 |
+
|
511 |
+
function bp_core_new_user_activity( $user ) {
|
512 |
+
if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
|
513 |
+
return false;
|
514 |
+
|
515 |
+
if ( is_array( $user ) )
|
516 |
+
$user_id = $user['user_id'];
|
517 |
+
else
|
518 |
+
$user_id = $user;
|
519 |
+
|
520 |
+
if ( empty( $user_id ) )
|
521 |
+
return false;
|
522 |
+
|
523 |
+
$userlink = bp_core_get_userlink( $user_id );
|
524 |
+
|
525 |
+
bp_activity_add( array(
|
526 |
+
'user_id' => $user_id,
|
527 |
+
'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
|
528 |
+
'component' => 'profile',
|
529 |
+
'type' => 'new_member'
|
530 |
+
) );
|
531 |
+
}
|
532 |
+
add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
|
533 |
+
|
534 |
+
function bp_core_map_user_registration( $user_id ) {
|
535 |
+
/* Only map data when the site admin is adding users, not on registration. */
|
536 |
+
if ( !is_admin() )
|
537 |
+
return false;
|
538 |
+
|
539 |
+
/* Add a last active entry */
|
540 |
+
update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
|
541 |
+
|
542 |
+
/* Add the user's fullname to Xprofile */
|
543 |
+
if ( function_exists( 'xprofile_set_field_data' ) ) {
|
544 |
+
$firstname = get_user_meta( $user_id, 'first_name', true );
|
545 |
+
$lastname = ' ' . get_user_meta( $user_id, 'last_name', true );
|
546 |
+
$name = $firstname . $lastname;
|
547 |
+
|
548 |
+
if ( empty( $name ) || ' ' == $name )
|
549 |
+
$name = get_user_meta( $user_id, 'nickname', true );
|
550 |
+
|
551 |
+
xprofile_set_field_data( 1, $user_id, $name );
|
552 |
+
}
|
553 |
+
}
|
554 |
+
add_action( 'user_register', 'bp_core_map_user_registration' );
|
555 |
+
|
556 |
+
function bp_core_signup_avatar_upload_dir() {
|
557 |
+
global $bp;
|
558 |
+
|
559 |
+
if ( !$bp->signup->avatar_dir )
|
560 |
+
return false;
|
561 |
+
|
562 |
+
$path = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
|
563 |
+
$newbdir = $path;
|
564 |
+
|
565 |
+
if ( !file_exists( $path ) )
|
566 |
+
@wp_mkdir_p( $path );
|
567 |
+
|
568 |
+
$newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
|
569 |
+
$newburl = $newurl;
|
570 |
+
$newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
|
571 |
+
|
572 |
+
return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
|
573 |
+
}
|
574 |
+
|
575 |
+
function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
|
576 |
+
$activate_url = bp_get_activation_page() ."?key=$key";
|
577 |
+
$activate_url = esc_url( $activate_url );
|
578 |
+
$admin_email = get_site_option( "admin_email" );
|
579 |
+
|
580 |
+
if ( empty( $admin_email ) )
|
581 |
+
$admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
|
582 |
+
|
583 |
+
$from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
|
584 |
+
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
|
585 |
+
$message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
|
586 |
+
$subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
|
587 |
+
|
588 |
+
/* Send the message */
|
589 |
+
$to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
|
590 |
+
$subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
|
591 |
+
$message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
|
592 |
+
|
593 |
+
wp_mail( $to, $subject, $message, $message_headers );
|
594 |
+
}
|
595 |
+
|
596 |
+
/* Stop user accounts logging in that have not been activated (user_status = 2) */
|
597 |
+
function bp_core_signup_disable_inactive( $auth_obj, $username ) {
|
598 |
+
global $bp, $wpdb;
|
599 |
+
|
600 |
+
if ( !$user_id = bp_core_get_userid( $username ) )
|
601 |
+
return $auth_obj;
|
602 |
+
|
603 |
+
$user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
|
604 |
+
|
605 |
+
if ( 2 == $user_status )
|
606 |
+
bp_core_redirect( $bp->root_domain );
|
607 |
+
else
|
608 |
+
return $auth_obj;
|
609 |
+
}
|
610 |
+
add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
|
611 |
+
|
612 |
+
/* Kill the wp-signup.php if custom registration signup templates are present */
|
613 |
+
function bp_core_wpsignup_redirect() {
|
614 |
+
if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
|
615 |
+
return false;
|
616 |
+
|
617 |
+
if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
|
618 |
+
bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
|
619 |
+
}
|
620 |
+
if ( bp_core_is_multisite() )
|
621 |
+
add_action( 'wp', 'bp_core_wpsignup_redirect' );
|
622 |
+
else
|
623 |
+
add_action( 'init', 'bp_core_wpsignup_redirect' );
|
624 |
+
|
625 |
?>
|
bp-core/bp-core-templatetags.php
CHANGED
@@ -1,2082 +1,2082 @@
|
|
1 |
-
<?php
|
2 |
-
/***
|
3 |
-
* Members template loop that will allow you to loop all members or friends of a member
|
4 |
-
* if you pass a user_id.
|
5 |
-
*/
|
6 |
-
|
7 |
-
class BP_Core_Members_Template {
|
8 |
-
var $current_member = -1;
|
9 |
-
var $member_count;
|
10 |
-
var $members;
|
11 |
-
var $member;
|
12 |
-
|
13 |
-
var $in_the_loop;
|
14 |
-
|
15 |
-
var $pag_page;
|
16 |
-
var $pag_num;
|
17 |
-
var $pag_links;
|
18 |
-
var $total_member_count;
|
19 |
-
|
20 |
-
function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras ) {
|
21 |
-
global $bp;
|
22 |
-
|
23 |
-
$this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
|
24 |
-
$this->pag_num
|
25 |
-
$this->type
|
26 |
-
|
27 |
-
if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
|
28 |
-
$this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
|
29 |
-
|
30 |
-
$this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
} else {
|
46 |
-
$this->member_count = count($this->members);
|
47 |
-
}
|
48 |
-
|
49 |
-
if ( (int)
|
50 |
-
$this->pag_links = paginate_links( array(
|
51 |
-
'base'
|
52 |
-
'format'
|
53 |
-
'total'
|
54 |
-
'current'
|
55 |
-
'prev_text' => '←',
|
56 |
-
'next_text' => '→',
|
57 |
-
'mid_size'
|
58 |
-
));
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
function has_members() {
|
63 |
-
if ( $this->member_count )
|
64 |
-
return true;
|
65 |
-
|
66 |
-
return false;
|
67 |
-
}
|
68 |
-
|
69 |
-
function next_member() {
|
70 |
-
$this->current_member++;
|
71 |
-
$this->member = $this->members[$this->current_member];
|
72 |
-
|
73 |
-
return $this->member;
|
74 |
-
}
|
75 |
-
|
76 |
-
function rewind_members() {
|
77 |
-
$this->current_member = -1;
|
78 |
-
if ( $this->member_count > 0 ) {
|
79 |
-
$this->member = $this->members[0];
|
80 |
-
}
|
81 |
-
}
|
82 |
-
|
83 |
-
function members() {
|
84 |
-
if ( $this->current_member + 1 < $this->member_count ) {
|
85 |
-
return true;
|
86 |
-
} elseif ( $this->current_member + 1 == $this->member_count ) {
|
87 |
-
do_action('loop_end');
|
88 |
-
// Do some cleaning up after the loop
|
89 |
-
$this->rewind_members();
|
90 |
-
}
|
91 |
-
|
92 |
-
$this->in_the_loop = false;
|
93 |
-
return false;
|
94 |
-
}
|
95 |
-
|
96 |
-
function the_member() {
|
97 |
-
global $member, $bp;
|
98 |
-
|
99 |
-
$this->in_the_loop = true;
|
100 |
-
$this->member = $this->next_member();
|
101 |
-
|
102 |
-
if ( 0 == $this->current_member ) // loop has just started
|
103 |
-
do_action('loop_start');
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
-
function bp_rewind_members() {
|
108 |
-
global $members_template;
|
109 |
-
|
110 |
-
return $members_template->rewind_members();
|
111 |
-
}
|
112 |
-
|
113 |
-
function bp_has_members( $args = '' ) {
|
114 |
-
global $bp, $members_template;
|
115 |
-
|
116 |
-
/***
|
117 |
-
* Set the defaults based on the current page. Any of these will be overridden
|
118 |
-
* if arguments are directly passed into the loop. Custom plugins should always
|
119 |
-
* pass their parameters directly to the loop.
|
120 |
-
*/
|
121 |
-
$type = 'active';
|
122 |
-
$user_id = false;
|
123 |
-
$page = 1;
|
124 |
-
$search_terms = false;
|
125 |
-
|
126 |
-
// User filtering
|
127 |
-
if ( !empty( $bp->displayed_user->id ) )
|
128 |
-
$user_id = $bp->displayed_user->id;
|
129 |
-
|
130 |
-
// Pass a filter if ?s= is set.
|
131 |
-
if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
|
132 |
-
$search_terms = $_REQUEST['s'];
|
133 |
-
|
134 |
-
// type: active ( default ) | random | newest | popular | online | alphabetical
|
135 |
-
$defaults = array(
|
136 |
-
'type' => $type,
|
137 |
-
'page' => $page,
|
138 |
-
'per_page' => 20,
|
139 |
-
'max' => false,
|
140 |
-
|
141 |
-
'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
|
142 |
-
|
143 |
-
'user_id' => $user_id, // Pass a user_id to only show friends of this user
|
144 |
-
'search_terms' => $search_terms, // Pass search_terms to filter users by their profile data
|
145 |
-
|
146 |
-
'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
|
147 |
-
);
|
148 |
-
|
149 |
-
$r = wp_parse_args( $args, $defaults );
|
150 |
-
extract( $r );
|
151 |
-
|
152 |
-
if ( $max ) {
|
153 |
-
if ( $per_page > $max )
|
154 |
-
$per_page = $max;
|
155 |
-
}
|
156 |
-
|
157 |
-
// Make sure we return no members if we looking at friendship requests and there are none.
|
158 |
-
if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
|
159 |
-
return false;
|
160 |
-
|
161 |
-
$members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
|
162 |
-
return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
|
163 |
-
}
|
164 |
-
|
165 |
-
function bp_the_member() {
|
166 |
-
global $members_template;
|
167 |
-
return $members_template->the_member();
|
168 |
-
}
|
169 |
-
|
170 |
-
function bp_members() {
|
171 |
-
global $members_template;
|
172 |
-
return $members_template->members();
|
173 |
-
}
|
174 |
-
|
175 |
-
function bp_members_pagination_count() {
|
176 |
-
global $bp, $members_template;
|
177 |
-
|
178 |
-
$start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
|
179 |
-
$from_num = bp_core_number_format( $start_num );
|
180 |
-
$to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
|
181 |
-
$total = bp_core_number_format( $members_template->total_member_count );
|
182 |
-
|
183 |
-
if ( 'active' == $members_template->type )
|
184 |
-
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s active members)', 'buddypress' ), $from_num, $to_num, $total );
|
185 |
-
else if ( 'popular' == $members_template->type )
|
186 |
-
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members with friends)', 'buddypress' ), $from_num, $to_num, $total );
|
187 |
-
else if ( 'online' == $members_template->type )
|
188 |
-
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members online)', 'buddypress' ), $from_num, $to_num, $total );
|
189 |
-
else
|
190 |
-
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
|
191 |
-
|
192 |
-
?><span class="ajax-loader"></span><?php
|
193 |
-
}
|
194 |
-
|
195 |
-
function bp_members_pagination_links() {
|
196 |
-
echo bp_get_members_pagination_links();
|
197 |
-
}
|
198 |
-
function bp_get_members_pagination_links() {
|
199 |
-
global $members_template;
|
200 |
-
|
201 |
-
return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* bp_member_user_id()
|
206 |
-
*
|
207 |
-
* Echo id from bp_get_member_user_id()
|
208 |
-
*
|
209 |
-
* @uses bp_get_member_user_id()
|
210 |
-
*/
|
211 |
-
function bp_member_user_id() {
|
212 |
-
echo bp_get_member_user_id();
|
213 |
-
}
|
214 |
-
/**
|
215 |
-
* bp_get_member_user_id()
|
216 |
-
*
|
217 |
-
* Get the id of the user in a members loop
|
218 |
-
*
|
219 |
-
* @global object $members_template
|
220 |
-
* @return string Members id
|
221 |
-
*/
|
222 |
-
function bp_get_member_user_id() {
|
223 |
-
global $members_template;
|
224 |
-
|
225 |
-
return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
|
226 |
-
}
|
227 |
-
|
228 |
-
/**
|
229 |
-
* bp_member_user_nicename()
|
230 |
-
*
|
231 |
-
* Echo nicename from bp_get_member_user_nicename()
|
232 |
-
*
|
233 |
-
* @uses bp_get_member_user_nicename()
|
234 |
-
*/
|
235 |
-
function bp_member_user_nicename() {
|
236 |
-
echo bp_get_member_user_nicename();
|
237 |
-
}
|
238 |
-
/**
|
239 |
-
* bp_get_member_user_nicename()
|
240 |
-
*
|
241 |
-
* Get the nicename of the user in a members loop
|
242 |
-
*
|
243 |
-
* @global object $members_template
|
244 |
-
* @return string Members nicename
|
245 |
-
*/
|
246 |
-
function bp_get_member_user_nicename() {
|
247 |
-
global $members_template;
|
248 |
-
return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
|
249 |
-
}
|
250 |
-
|
251 |
-
/**
|
252 |
-
* bp_member_user_login()
|
253 |
-
*
|
254 |
-
* Echo login from bp_get_member_user_login()
|
255 |
-
*
|
256 |
-
* @uses bp_get_member_user_login()
|
257 |
-
*/
|
258 |
-
function bp_member_user_login() {
|
259 |
-
echo bp_get_member_user_login();
|
260 |
-
}
|
261 |
-
/**
|
262 |
-
* bp_get_member_user_login()
|
263 |
-
*
|
264 |
-
* Get the login of the user in a members loop
|
265 |
-
*
|
266 |
-
* @global object $members_template
|
267 |
-
* @return string Members login
|
268 |
-
*/
|
269 |
-
function bp_get_member_user_login() {
|
270 |
-
global $members_template;
|
271 |
-
return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
|
272 |
-
}
|
273 |
-
|
274 |
-
/**
|
275 |
-
* bp_member_user_email()
|
276 |
-
*
|
277 |
-
* Echo email address from bp_get_member_user_email()
|
278 |
-
*
|
279 |
-
* @uses bp_get_member_user_email()
|
280 |
-
*/
|
281 |
-
function bp_member_user_email() {
|
282 |
-
echo bp_get_member_user_email();
|
283 |
-
}
|
284 |
-
/**
|
285 |
-
* bp_get_member_user_email()
|
286 |
-
*
|
287 |
-
* Get the email address of the user in a members loop
|
288 |
-
*
|
289 |
-
* @global object $members_template
|
290 |
-
* @return string Members email address
|
291 |
-
*/
|
292 |
-
function bp_get_member_user_email() {
|
293 |
-
global $members_template;
|
294 |
-
return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
|
295 |
-
}
|
296 |
-
|
297 |
-
function bp_member_is_loggedin_user() {
|
298 |
-
global $bp, $members_template;
|
299 |
-
return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
|
300 |
-
}
|
301 |
-
|
302 |
-
function bp_member_avatar( $args = '' ) {
|
303 |
-
echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
|
304 |
-
}
|
305 |
-
function bp_get_member_avatar( $args = '' ) {
|
306 |
-
global $bp, $members_template;
|
307 |
-
|
308 |
-
$defaults = array(
|
309 |
-
'type' => 'thumb',
|
310 |
-
'width' => false,
|
311 |
-
'height' => false,
|
312 |
-
'class' => 'avatar',
|
313 |
-
'id' => false,
|
314 |
-
'alt' => __( 'Member avatar', 'buddypress' )
|
315 |
-
);
|
316 |
-
|
317 |
-
$r = wp_parse_args( $args, $defaults );
|
318 |
-
extract( $r, EXTR_SKIP );
|
319 |
-
|
320 |
-
return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
|
321 |
-
}
|
322 |
-
|
323 |
-
function bp_member_permalink() {
|
324 |
-
echo bp_get_member_permalink();
|
325 |
-
}
|
326 |
-
function bp_get_member_permalink() {
|
327 |
-
global $members_template;
|
328 |
-
|
329 |
-
return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
|
330 |
-
}
|
331 |
-
function bp_member_link() { echo bp_get_member_permalink(); }
|
332 |
-
function bp_get_member_link() { return bp_get_member_permalink(); }
|
333 |
-
|
334 |
-
function bp_member_name() {
|
335 |
-
echo apply_filters( 'bp_member_name', bp_get_member_name() );
|
336 |
-
}
|
337 |
-
function bp_get_member_name() {
|
338 |
-
global $members_template;
|
339 |
-
|
340 |
-
if ( empty($members_template->member->fullname) )
|
341 |
-
$members_template->member->fullname = $members_template->member->display_name;
|
342 |
-
|
343 |
-
return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
|
344 |
-
}
|
345 |
-
add_filter( 'bp_get_member_name', 'wp_filter_kses' );
|
346 |
-
add_filter( 'bp_get_member_name', 'stripslashes' );
|
347 |
-
add_filter( 'bp_get_member_name', 'strip_tags' );
|
348 |
-
|
349 |
-
function bp_member_last_active() {
|
350 |
-
echo bp_get_member_last_active();
|
351 |
-
}
|
352 |
-
function bp_get_member_last_active() {
|
353 |
-
global $members_template;
|
354 |
-
|
355 |
-
$last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) );
|
356 |
-
|
357 |
-
return apply_filters( 'bp_member_last_active', $last_activity );
|
358 |
-
}
|
359 |
-
|
360 |
-
function bp_member_latest_update( $args = '' ) {
|
361 |
-
echo bp_get_member_latest_update( $args );
|
362 |
-
}
|
363 |
-
function bp_get_member_latest_update( $args = '' ) {
|
364 |
-
global $members_template, $bp;
|
365 |
-
|
366 |
-
$defaults = array(
|
367 |
-
'length' => 15
|
368 |
-
);
|
369 |
-
|
370 |
-
$r = wp_parse_args( $args, $defaults );
|
371 |
-
extract( $r, EXTR_SKIP );
|
372 |
-
|
373 |
-
if ( !$update = maybe_unserialize( $members_template->member->latest_update ) )
|
374 |
-
return false;
|
375 |
-
|
376 |
-
$update_content = apply_filters( 'bp_get_activity_latest_update', strip_tags( bp_create_excerpt( $update['content'], $length ) ) );
|
377 |
-
|
378 |
-
if ( !empty( $update['id'] ) )
|
379 |
-
$update_content .= ' · <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '">' . __( 'View', 'buddypress' ) . '</a>';
|
380 |
-
|
381 |
-
return apply_filters( 'bp_get_member_latest_update', $update_content );
|
382 |
-
}
|
383 |
-
|
384 |
-
function bp_member_profile_data( $args = '' ) {
|
385 |
-
echo bp_get_member_profile_data( $args );
|
386 |
-
}
|
387 |
-
function bp_get_member_profile_data( $args = '' ) {
|
388 |
-
global $members_template;
|
389 |
-
|
390 |
-
if ( !function_exists( 'xprofile_install' ) )
|
391 |
-
return false;
|
392 |
-
|
393 |
-
$defaults = array(
|
394 |
-
'field' => false, // Field name
|
395 |
-
);
|
396 |
-
|
397 |
-
$r = wp_parse_args( $args, $defaults );
|
398 |
-
extract( $r, EXTR_SKIP );
|
399 |
-
|
400 |
-
// Populate the user if it hasn't been already.
|
401 |
-
if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
|
402 |
-
$members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
|
403 |
-
|
404 |
-
$data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
|
405 |
-
|
406 |
-
return apply_filters( 'bp_get_member_profile_data', $data );
|
407 |
-
}
|
408 |
-
|
409 |
-
function bp_member_registered() {
|
410 |
-
echo bp_get_member_registered();
|
411 |
-
}
|
412 |
-
function bp_get_member_registered() {
|
413 |
-
global $members_template;
|
414 |
-
|
415 |
-
$registered =
|
416 |
-
|
417 |
-
return apply_filters( 'bp_member_last_active', $registered );
|
418 |
-
}
|
419 |
-
|
420 |
-
function
|
421 |
-
global $members_template;
|
422 |
-
|
423 |
-
if ( function_exists( '
|
424 |
-
|
425 |
-
$
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
}
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
}
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
*
|
557 |
-
*
|
558 |
-
*
|
559 |
-
*
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
if (
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
$
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
return apply_filters( '
|
715 |
-
}
|
716 |
-
|
717 |
-
function
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
}
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
<td class="
|
772 |
-
<?php
|
773 |
-
</td>
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
<td class="
|
782 |
-
<?php
|
783 |
-
</td>
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
<td class="
|
792 |
-
<?php
|
793 |
-
</td>
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
$
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
}
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
} else if (
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
$title =
|
915 |
-
|
916 |
-
$title = __( '
|
917 |
-
|
918 |
-
} else if (
|
919 |
-
|
920 |
-
|
921 |
-
} else if (
|
922 |
-
$title =
|
923 |
-
|
924 |
-
} else if (
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
} else
|
934 |
-
$
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
return
|
950 |
-
}
|
951 |
-
|
952 |
-
function
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
';
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
function
|
1083 |
-
|
1084 |
-
}
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
}
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
function
|
1152 |
-
echo
|
1153 |
-
}
|
1154 |
-
function
|
1155 |
-
return apply_filters( '
|
1156 |
-
}
|
1157 |
-
|
1158 |
-
function
|
1159 |
-
echo
|
1160 |
-
}
|
1161 |
-
function
|
1162 |
-
return apply_filters( '
|
1163 |
-
}
|
1164 |
-
|
1165 |
-
function
|
1166 |
-
echo
|
1167 |
-
}
|
1168 |
-
function
|
1169 |
-
return apply_filters( '
|
1170 |
-
}
|
1171 |
-
|
1172 |
-
function
|
1173 |
-
echo
|
1174 |
-
}
|
1175 |
-
function
|
1176 |
-
return apply_filters( '
|
1177 |
-
}
|
1178 |
-
|
1179 |
-
function
|
1180 |
-
echo
|
1181 |
-
}
|
1182 |
-
function
|
1183 |
-
return apply_filters( '
|
1184 |
-
}
|
1185 |
-
|
1186 |
-
function
|
1187 |
-
echo
|
1188 |
-
}
|
1189 |
-
function
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
$
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
)
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
}
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
function
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
*
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
function
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
}
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
echo bp_get_displayed_user_fullname();
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] ==
|
1521 |
-
}
|
1522 |
-
|
1523 |
-
function bp_is_directory() {
|
1524 |
-
global $bp;
|
1525 |
-
|
1526 |
-
return $bp->is_directory;
|
1527 |
-
}
|
1528 |
-
|
1529 |
-
function bp_is_page($page) {
|
1530 |
-
global $bp;
|
1531 |
-
|
1532 |
-
if ( !$bp->displayed_user->id && $bp->current_component == $page )
|
1533 |
-
return true;
|
1534 |
-
|
1535 |
-
if ( 'home' == $page )
|
1536 |
-
return bp_is_front_page();
|
1537 |
-
|
1538 |
-
return false;
|
1539 |
-
}
|
1540 |
-
|
1541 |
-
function bp_is_active( $component ) {
|
1542 |
-
global $bp_deactivated;
|
1543 |
-
|
1544 |
-
if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
|
1545 |
-
return true;
|
1546 |
-
|
1547 |
-
return false;
|
1548 |
-
}
|
1549 |
-
|
1550 |
-
function bp_is_profile_component() {
|
1551 |
-
global $bp;
|
1552 |
-
|
1553 |
-
if ( BP_XPROFILE_SLUG == $bp->current_component )
|
1554 |
-
return true;
|
1555 |
-
|
1556 |
-
return false;
|
1557 |
-
}
|
1558 |
-
|
1559 |
-
function bp_is_activity_component() {
|
1560 |
-
global $bp;
|
1561 |
-
|
1562 |
-
if ( BP_ACTIVITY_SLUG == $bp->current_component )
|
1563 |
-
return true;
|
1564 |
-
|
1565 |
-
return false;
|
1566 |
-
}
|
1567 |
-
|
1568 |
-
function bp_is_blogs_component() {
|
1569 |
-
global $bp;
|
1570 |
-
|
1571 |
-
if ( BP_BLOGS_SLUG == $bp->current_component )
|
1572 |
-
return true;
|
1573 |
-
|
1574 |
-
return false;
|
1575 |
-
}
|
1576 |
-
|
1577 |
-
function bp_is_messages_component() {
|
1578 |
-
global $bp;
|
1579 |
-
|
1580 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component )
|
1581 |
-
return true;
|
1582 |
-
|
1583 |
-
return false;
|
1584 |
-
}
|
1585 |
-
|
1586 |
-
function bp_is_friends_component() {
|
1587 |
-
global $bp;
|
1588 |
-
|
1589 |
-
if ( BP_FRIENDS_SLUG == $bp->current_component )
|
1590 |
-
return true;
|
1591 |
-
|
1592 |
-
return false;
|
1593 |
-
}
|
1594 |
-
|
1595 |
-
function bp_is_groups_component() {
|
1596 |
-
global $bp;
|
1597 |
-
|
1598 |
-
if ( BP_GROUPS_SLUG == $bp->current_component )
|
1599 |
-
return true;
|
1600 |
-
|
1601 |
-
return false;
|
1602 |
-
}
|
1603 |
-
|
1604 |
-
function bp_is_settings_component() {
|
1605 |
-
global $bp;
|
1606 |
-
|
1607 |
-
if ( BP_SETTINGS_SLUG == $bp->current_component )
|
1608 |
-
return true;
|
1609 |
-
|
1610 |
-
return false;
|
1611 |
-
}
|
1612 |
-
|
1613 |
-
function bp_is_member() {
|
1614 |
-
global $bp;
|
1615 |
-
|
1616 |
-
if ( $bp->displayed_user->id )
|
1617 |
-
return true;
|
1618 |
-
|
1619 |
-
return false;
|
1620 |
-
}
|
1621 |
-
|
1622 |
-
function bp_is_user_activity() {
|
1623 |
-
global $bp;
|
1624 |
-
|
1625 |
-
if ( BP_ACTIVITY_SLUG == $bp->current_component )
|
1626 |
-
return true;
|
1627 |
-
|
1628 |
-
return false;
|
1629 |
-
}
|
1630 |
-
|
1631 |
-
function bp_is_user_friends_activity() {
|
1632 |
-
global $bp;
|
1633 |
-
|
1634 |
-
if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
|
1635 |
-
return true;
|
1636 |
-
|
1637 |
-
return false;
|
1638 |
-
}
|
1639 |
-
|
1640 |
-
function bp_is_activity_permalink() {
|
1641 |
-
global $bp;
|
1642 |
-
|
1643 |
-
if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
|
1644 |
-
return true;
|
1645 |
-
|
1646 |
-
return false;
|
1647 |
-
}
|
1648 |
-
|
1649 |
-
function bp_is_user_profile() {
|
1650 |
-
global $bp;
|
1651 |
-
|
1652 |
-
if ( BP_XPROFILE_SLUG == $bp->current_component || $bp->core->profile->slug == $bp->current_component )
|
1653 |
-
return true;
|
1654 |
-
|
1655 |
-
return false;
|
1656 |
-
}
|
1657 |
-
|
1658 |
-
function bp_is_profile_edit() {
|
1659 |
-
global $bp;
|
1660 |
-
|
1661 |
-
if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
|
1662 |
-
return true;
|
1663 |
-
|
1664 |
-
return false;
|
1665 |
-
}
|
1666 |
-
|
1667 |
-
function bp_is_change_avatar() {
|
1668 |
-
global $bp;
|
1669 |
-
|
1670 |
-
if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
|
1671 |
-
return true;
|
1672 |
-
|
1673 |
-
return false;
|
1674 |
-
}
|
1675 |
-
|
1676 |
-
function bp_is_user_groups() {
|
1677 |
-
global $bp;
|
1678 |
-
|
1679 |
-
if ( BP_GROUPS_SLUG == $bp->current_component )
|
1680 |
-
return true;
|
1681 |
-
|
1682 |
-
return false;
|
1683 |
-
}
|
1684 |
-
|
1685 |
-
function bp_is_group() {
|
1686 |
-
global $bp;
|
1687 |
-
|
1688 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->groups->current_group )
|
1689 |
-
return true;
|
1690 |
-
|
1691 |
-
return false;
|
1692 |
-
}
|
1693 |
-
|
1694 |
-
function bp_is_group_home() {
|
1695 |
-
global $bp;
|
1696 |
-
|
1697 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
|
1698 |
-
return true;
|
1699 |
-
|
1700 |
-
return false;
|
1701 |
-
}
|
1702 |
-
|
1703 |
-
function bp_is_group_create() {
|
1704 |
-
global $bp;
|
1705 |
-
|
1706 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
|
1707 |
-
return true;
|
1708 |
-
|
1709 |
-
return false;
|
1710 |
-
}
|
1711 |
-
|
1712 |
-
|
1713 |
-
function bp_is_group_admin_page() {
|
1714 |
-
global $bp;
|
1715 |
-
|
1716 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
|
1717 |
-
return true;
|
1718 |
-
|
1719 |
-
return false;
|
1720 |
-
}
|
1721 |
-
|
1722 |
-
function bp_is_group_forum() {
|
1723 |
-
global $bp;
|
1724 |
-
|
1725 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
|
1726 |
-
return true;
|
1727 |
-
|
1728 |
-
return false;
|
1729 |
-
}
|
1730 |
-
|
1731 |
-
function bp_is_group_activity() {
|
1732 |
-
global $bp;
|
1733 |
-
|
1734 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
|
1735 |
-
return true;
|
1736 |
-
|
1737 |
-
return false;
|
1738 |
-
}
|
1739 |
-
|
1740 |
-
function bp_is_group_forum_topic() {
|
1741 |
-
global $bp;
|
1742 |
-
|
1743 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
|
1744 |
-
return true;
|
1745 |
-
|
1746 |
-
return false;
|
1747 |
-
}
|
1748 |
-
|
1749 |
-
function bp_is_group_forum_topic_edit() {
|
1750 |
-
global $bp;
|
1751 |
-
|
1752 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] && 'edit' == $bp->action_variables[2] )
|
1753 |
-
return true;
|
1754 |
-
|
1755 |
-
return false;
|
1756 |
-
}
|
1757 |
-
|
1758 |
-
function bp_is_group_members() {
|
1759 |
-
global $bp;
|
1760 |
-
|
1761 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
|
1762 |
-
return true;
|
1763 |
-
|
1764 |
-
return false;
|
1765 |
-
}
|
1766 |
-
|
1767 |
-
function bp_is_group_invites() {
|
1768 |
-
global $bp;
|
1769 |
-
|
1770 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
|
1771 |
-
return true;
|
1772 |
-
|
1773 |
-
return false;
|
1774 |
-
}
|
1775 |
-
|
1776 |
-
function bp_is_group_membership_request() {
|
1777 |
-
global $bp;
|
1778 |
-
|
1779 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
|
1780 |
-
return true;
|
1781 |
-
|
1782 |
-
return false;
|
1783 |
-
}
|
1784 |
-
|
1785 |
-
function bp_is_group_leave() {
|
1786 |
-
global $bp;
|
1787 |
-
|
1788 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
|
1789 |
-
return true;
|
1790 |
-
|
1791 |
-
return false;
|
1792 |
-
}
|
1793 |
-
|
1794 |
-
function bp_is_group_single() {
|
1795 |
-
global $bp;
|
1796 |
-
|
1797 |
-
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
|
1798 |
-
return true;
|
1799 |
-
|
1800 |
-
return false;
|
1801 |
-
}
|
1802 |
-
|
1803 |
-
function bp_is_user_blogs() {
|
1804 |
-
global $bp;
|
1805 |
-
|
1806 |
-
if ( BP_BLOGS_SLUG == $bp->current_component )
|
1807 |
-
return true;
|
1808 |
-
|
1809 |
-
return false;
|
1810 |
-
}
|
1811 |
-
|
1812 |
-
function bp_is_user_recent_posts() {
|
1813 |
-
global $bp;
|
1814 |
-
|
1815 |
-
if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
|
1816 |
-
return true;
|
1817 |
-
|
1818 |
-
return false;
|
1819 |
-
}
|
1820 |
-
|
1821 |
-
function bp_is_user_recent_commments() {
|
1822 |
-
global $bp;
|
1823 |
-
|
1824 |
-
if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
|
1825 |
-
return true;
|
1826 |
-
|
1827 |
-
return false;
|
1828 |
-
}
|
1829 |
-
|
1830 |
-
function bp_is_create_blog() {
|
1831 |
-
global $bp;
|
1832 |
-
|
1833 |
-
if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
|
1834 |
-
return true;
|
1835 |
-
|
1836 |
-
return false;
|
1837 |
-
}
|
1838 |
-
|
1839 |
-
function bp_is_user_friends() {
|
1840 |
-
global $bp;
|
1841 |
-
|
1842 |
-
if ( BP_FRIENDS_SLUG == $bp->current_component )
|
1843 |
-
return true;
|
1844 |
-
|
1845 |
-
return false;
|
1846 |
-
}
|
1847 |
-
|
1848 |
-
function bp_is_friend_requests() {
|
1849 |
-
global $bp;
|
1850 |
-
|
1851 |
-
if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
|
1852 |
-
return true;
|
1853 |
-
|
1854 |
-
return false;
|
1855 |
-
}
|
1856 |
-
|
1857 |
-
function bp_is_user_messages() {
|
1858 |
-
global $bp;
|
1859 |
-
|
1860 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component )
|
1861 |
-
return true;
|
1862 |
-
|
1863 |
-
return false;
|
1864 |
-
}
|
1865 |
-
|
1866 |
-
function bp_is_messages_inbox() {
|
1867 |
-
global $bp;
|
1868 |
-
|
1869 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
|
1870 |
-
return true;
|
1871 |
-
|
1872 |
-
return false;
|
1873 |
-
}
|
1874 |
-
|
1875 |
-
function bp_is_messages_sentbox() {
|
1876 |
-
global $bp;
|
1877 |
-
|
1878 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
|
1879 |
-
return true;
|
1880 |
-
|
1881 |
-
return false;
|
1882 |
-
}
|
1883 |
-
|
1884 |
-
|
1885 |
-
function bp_is_notices() {
|
1886 |
-
global $bp;
|
1887 |
-
|
1888 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
|
1889 |
-
return true;
|
1890 |
-
|
1891 |
-
return false;
|
1892 |
-
}
|
1893 |
-
|
1894 |
-
|
1895 |
-
function bp_is_messages_compose_screen() {
|
1896 |
-
global $bp;
|
1897 |
-
|
1898 |
-
if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
|
1899 |
-
return true;
|
1900 |
-
|
1901 |
-
return false;
|
1902 |
-
}
|
1903 |
-
|
1904 |
-
function bp_is_single_item() {
|
1905 |
-
global $bp;
|
1906 |
-
|
1907 |
-
if ( $bp->is_single_item )
|
1908 |
-
return true;
|
1909 |
-
|
1910 |
-
return false;
|
1911 |
-
}
|
1912 |
-
|
1913 |
-
function bp_is_activation_page() {
|
1914 |
-
global $bp;
|
1915 |
-
|
1916 |
-
if ( BP_ACTIVATION_SLUG == $bp->current_component )
|
1917 |
-
return true;
|
1918 |
-
|
1919 |
-
return false;
|
1920 |
-
}
|
1921 |
-
|
1922 |
-
function bp_is_register_page() {
|
1923 |
-
global $bp;
|
1924 |
-
|
1925 |
-
if ( BP_REGISTER_SLUG == $bp->current_component )
|
1926 |
-
return true;
|
1927 |
-
|
1928 |
-
return false;
|
1929 |
-
}
|
1930 |
-
|
1931 |
-
/* Use the above is_() functions to output a body class for each page */
|
1932 |
-
|
1933 |
-
function bp_the_body_class() {
|
1934 |
-
echo bp_get_the_body_class();
|
1935 |
-
}
|
1936 |
-
function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
|
1937 |
-
global $bp;
|
1938 |
-
|
1939 |
-
if ( bp_is_front_page() )
|
1940 |
-
$bp_classes[] = 'home-page';
|
1941 |
-
|
1942 |
-
if ( bp_is_directory() )
|
1943 |
-
$bp_classes[] = 'directory';
|
1944 |
-
|
1945 |
-
if ( bp_is_user_profile() && !bp_is_blog_page() )
|
1946 |
-
$bp_classes[] = 'profile';
|
1947 |
-
|
1948 |
-
if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
|
1949 |
-
$bp_classes[] = 'activity';
|
1950 |
-
|
1951 |
-
if ( bp_is_blogs_component() && !bp_is_blog_page() )
|
1952 |
-
$bp_classes[] = 'blogs';
|
1953 |
-
|
1954 |
-
if ( bp_is_messages_component() && !bp_is_blog_page() )
|
1955 |
-
$bp_classes[] = 'messages';
|
1956 |
-
|
1957 |
-
if ( bp_is_friends_component() && !bp_is_blog_page() )
|
1958 |
-
$bp_classes[] = 'friends';
|
1959 |
-
|
1960 |
-
if ( bp_is_groups_component() && !bp_is_blog_page() )
|
1961 |
-
$bp_classes[] = 'groups';
|
1962 |
-
|
1963 |
-
if ( bp_is_settings_component() && !bp_is_blog_page() )
|
1964 |
-
$bp_classes[] = 'settings';
|
1965 |
-
|
1966 |
-
if ( bp_is_single_item() )
|
1967 |
-
$bp_classes[] = 'single-item';
|
1968 |
-
|
1969 |
-
if ( bp_is_messages_inbox() )
|
1970 |
-
$bp_classes[] = 'inbox';
|
1971 |
-
|
1972 |
-
if ( bp_is_messages_sentbox() )
|
1973 |
-
$bp_classes[] = 'sentbox';
|
1974 |
-
|
1975 |
-
if ( bp_is_messages_compose_screen() )
|
1976 |
-
$bp_classes[] = 'compose';
|
1977 |
-
|
1978 |
-
if ( bp_is_notices() )
|
1979 |
-
$bp_classes[] = 'notices';
|
1980 |
-
|
1981 |
-
if ( bp_is_friend_requests() )
|
1982 |
-
$bp_classes[] = 'friend-requests';
|
1983 |
-
|
1984 |
-
if ( bp_is_user_friends() )
|
1985 |
-
$bp_classes[] = 'my-friends';
|
1986 |
-
|
1987 |
-
if ( bp_is_create_blog() )
|
1988 |
-
$bp_classes[] = 'create-blog';
|
1989 |
-
|
1990 |
-
if ( bp_is_user_recent_commments() )
|
1991 |
-
$bp_classes[] = 'recent-comments';
|
1992 |
-
|
1993 |
-
if ( bp_is_user_recent_posts() )
|
1994 |
-
$bp_classes[] = 'recent-posts';
|
1995 |
-
|
1996 |
-
if ( bp_is_user_blogs() && !bp_is_directory() )
|
1997 |
-
$bp_classes[] = 'my-blogs';
|
1998 |
-
|
1999 |
-
if ( bp_is_user_groups() && !bp_is_directory() )
|
2000 |
-
$bp_classes[] = 'my-groups';
|
2001 |
-
|
2002 |
-
if ( bp_is_group_leave() )
|
2003 |
-
$bp_classes[] = 'leave-group';
|
2004 |
-
|
2005 |
-
if ( bp_is_group_invites() )
|
2006 |
-
$bp_classes[] = 'group-invites';
|
2007 |
-
|
2008 |
-
if ( bp_is_group_members() )
|
2009 |
-
$bp_classes[] = 'group-members';
|
2010 |
-
|
2011 |
-
if ( bp_is_group_forum_topic() )
|
2012 |
-
$bp_classes[] = 'group-forum-topic';
|
2013 |
-
|
2014 |
-
if ( bp_is_group_forum_topic_edit() )
|
2015 |
-
$bp_classes[] = 'group-forum-topic-edit';
|
2016 |
-
|
2017 |
-
if ( bp_is_group_forum() )
|
2018 |
-
$bp_classes[] = 'group-forum';
|
2019 |
-
|
2020 |
-
if ( bp_is_group_admin_page() )
|
2021 |
-
$bp_classes[] = 'group-admin';
|
2022 |
-
|
2023 |
-
if ( bp_is_group_create() )
|
2024 |
-
$bp_classes[] = 'group-create';
|
2025 |
-
|
2026 |
-
if ( bp_is_group_home() )
|
2027 |
-
$bp_classes[] = 'group-home';
|
2028 |
-
|
2029 |
-
if ( bp_is_change_avatar() )
|
2030 |
-
$bp_classes[] = 'change-avatar';
|
2031 |
-
|
2032 |
-
if ( bp_is_profile_edit() )
|
2033 |
-
$bp_classes[] = 'profile-edit';
|
2034 |
-
|
2035 |
-
if ( bp_is_user_friends_activity() )
|
2036 |
-
$bp_classes[] = 'friends-activity';
|
2037 |
-
|
2038 |
-
if ( bp_is_user_activity() && !bp_is_directory() )
|
2039 |
-
$bp_classes[] = 'my-activity';
|
2040 |
-
|
2041 |
-
if ( bp_is_activity_permalink() )
|
2042 |
-
$bp_classes[] = 'activity-permalink';
|
2043 |
-
|
2044 |
-
if ( bp_is_register_page() )
|
2045 |
-
$bp_classes[] = 'registration';
|
2046 |
-
|
2047 |
-
if ( bp_is_activation_page() )
|
2048 |
-
$bp_classes[] = 'activation';
|
2049 |
-
|
2050 |
-
if ( is_user_logged_in() )
|
2051 |
-
$bp_classes[] = 'logged-in';
|
2052 |
-
|
2053 |
-
/* Add the current_component, current_action into the bp classes */
|
2054 |
-
if ( !bp_is_blog_page() ) {
|
2055 |
-
if ( !empty( $bp->current_component ) )
|
2056 |
-
$bp_classes[] = $bp->current_component;
|
2057 |
-
|
2058 |
-
if ( !empty( $bp->current_action ) )
|
2059 |
-
$bp_classes[] = $bp->current_action;
|
2060 |
-
}
|
2061 |
-
|
2062 |
-
/* We don't want WordPress blog classes to appear on non-blog pages. */
|
2063 |
-
if ( !bp_is_blog_page() || is_home() ) {
|
2064 |
-
/* Preserve any custom classes already set */
|
2065 |
-
if ( !empty( $custom_classes ) )
|
2066 |
-
$wp_classes = (array) $custom_classes;
|
2067 |
-
else
|
2068 |
-
$wp_classes = array();
|
2069 |
-
}
|
2070 |
-
|
2071 |
-
/* Merge WP classes with BP classes */
|
2072 |
-
$classes = array_merge( (array) $bp_classes, (array) $wp_classes );
|
2073 |
-
|
2074 |
-
/* Remove any duplicates */
|
2075 |
-
$classes = array_unique( $classes );
|
2076 |
-
|
2077 |
-
return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
|
2078 |
-
}
|
2079 |
-
add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 )
|
2080 |
-
|
2081 |
-
|
2082 |
?>
|
1 |
+
<?php
|
2 |
+
/***
|
3 |
+
* Members template loop that will allow you to loop all members or friends of a member
|
4 |
+
* if you pass a user_id.
|
5 |
+
*/
|
6 |
+
|
7 |
+
class BP_Core_Members_Template {
|
8 |
+
var $current_member = -1;
|
9 |
+
var $member_count;
|
10 |
+
var $members;
|
11 |
+
var $member;
|
12 |
+
|
13 |
+
var $in_the_loop;
|
14 |
+
|
15 |
+
var $pag_page;
|
16 |
+
var $pag_num;
|
17 |
+
var $pag_links;
|
18 |
+
var $total_member_count;
|
19 |
+
|
20 |
+
function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras ) {
|
21 |
+
global $bp;
|
22 |
+
|
23 |
+
$this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
|
24 |
+
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
|
25 |
+
$this->type = $type;
|
26 |
+
|
27 |
+
if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
|
28 |
+
$this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
|
29 |
+
else
|
30 |
+
$this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
|
31 |
+
|
32 |
+
if ( !$max || $max >= (int)$this->members['total'] )
|
33 |
+
$this->total_member_count = (int)$this->members['total'];
|
34 |
+
else
|
35 |
+
$this->total_member_count = (int)$max;
|
36 |
+
|
37 |
+
$this->members = $this->members['users'];
|
38 |
+
|
39 |
+
if ( $max ) {
|
40 |
+
if ( $max >= count($this->members) ) {
|
41 |
+
$this->member_count = count( $this->members );
|
42 |
+
} else {
|
43 |
+
$this->member_count = (int)$max;
|
44 |
+
}
|
45 |
+
} else {
|
46 |
+
$this->member_count = count( $this->members );
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( (int)$this->total_member_count && (int)$this->pag_num ) {
|
50 |
+
$this->pag_links = paginate_links( array(
|
51 |
+
'base' => add_query_arg( 'upage', '%#%' ),
|
52 |
+
'format' => '',
|
53 |
+
'total' => ceil( (int)$this->total_member_count / (int)$this->pag_num ),
|
54 |
+
'current' => (int)$this->pag_page,
|
55 |
+
'prev_text' => '←',
|
56 |
+
'next_text' => '→',
|
57 |
+
'mid_size' => 1
|
58 |
+
) );
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
function has_members() {
|
63 |
+
if ( $this->member_count )
|
64 |
+
return true;
|
65 |
+
|
66 |
+
return false;
|
67 |
+
}
|
68 |
+
|
69 |
+
function next_member() {
|
70 |
+
$this->current_member++;
|
71 |
+
$this->member = $this->members[$this->current_member];
|
72 |
+
|
73 |
+
return $this->member;
|
74 |
+
}
|
75 |
+
|
76 |
+
function rewind_members() {
|
77 |
+
$this->current_member = -1;
|
78 |
+
if ( $this->member_count > 0 ) {
|
79 |
+
$this->member = $this->members[0];
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
function members() {
|
84 |
+
if ( $this->current_member + 1 < $this->member_count ) {
|
85 |
+
return true;
|
86 |
+
} elseif ( $this->current_member + 1 == $this->member_count ) {
|
87 |
+
do_action('loop_end');
|
88 |
+
// Do some cleaning up after the loop
|
89 |
+
$this->rewind_members();
|
90 |
+
}
|
91 |
+
|
92 |
+
$this->in_the_loop = false;
|
93 |
+
return false;
|
94 |
+
}
|
95 |
+
|
96 |
+
function the_member() {
|
97 |
+
global $member, $bp;
|
98 |
+
|
99 |
+
$this->in_the_loop = true;
|
100 |
+
$this->member = $this->next_member();
|
101 |
+
|
102 |
+
if ( 0 == $this->current_member ) // loop has just started
|
103 |
+
do_action('loop_start');
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
function bp_rewind_members() {
|
108 |
+
global $members_template;
|
109 |
+
|
110 |
+
return $members_template->rewind_members();
|
111 |
+
}
|
112 |
+
|
113 |
+
function bp_has_members( $args = '' ) {
|
114 |
+
global $bp, $members_template;
|
115 |
+
|
116 |
+
/***
|
117 |
+
* Set the defaults based on the current page. Any of these will be overridden
|
118 |
+
* if arguments are directly passed into the loop. Custom plugins should always
|
119 |
+
* pass their parameters directly to the loop.
|
120 |
+
*/
|
121 |
+
$type = 'active';
|
122 |
+
$user_id = false;
|
123 |
+
$page = 1;
|
124 |
+
$search_terms = false;
|
125 |
+
|
126 |
+
// User filtering
|
127 |
+
if ( !empty( $bp->displayed_user->id ) )
|
128 |
+
$user_id = $bp->displayed_user->id;
|
129 |
+
|
130 |
+
// Pass a filter if ?s= is set.
|
131 |
+
if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
|
132 |
+
$search_terms = $_REQUEST['s'];
|
133 |
+
|
134 |
+
// type: active ( default ) | random | newest | popular | online | alphabetical
|
135 |
+
$defaults = array(
|
136 |
+
'type' => $type,
|
137 |
+
'page' => $page,
|
138 |
+
'per_page' => 20,
|
139 |
+
'max' => false,
|
140 |
+
|
141 |
+
'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
|
142 |
+
|
143 |
+
'user_id' => $user_id, // Pass a user_id to only show friends of this user
|
144 |
+
'search_terms' => $search_terms, // Pass search_terms to filter users by their profile data
|
145 |
+
|
146 |
+
'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
|
147 |
+
);
|
148 |
+
|
149 |
+
$r = wp_parse_args( $args, $defaults );
|
150 |
+
extract( $r );
|
151 |
+
|
152 |
+
if ( $max ) {
|
153 |
+
if ( $per_page > $max )
|
154 |
+
$per_page = $max;
|
155 |
+
}
|
156 |
+
|
157 |
+
// Make sure we return no members if we looking at friendship requests and there are none.
|
158 |
+
if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
|
159 |
+
return false;
|
160 |
+
|
161 |
+
$members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
|
162 |
+
return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
|
163 |
+
}
|
164 |
+
|
165 |
+
function bp_the_member() {
|
166 |
+
global $members_template;
|
167 |
+
return $members_template->the_member();
|
168 |
+
}
|
169 |
+
|
170 |
+
function bp_members() {
|
171 |
+
global $members_template;
|
172 |
+
return $members_template->members();
|
173 |
+
}
|
174 |
+
|
175 |
+
function bp_members_pagination_count() {
|
176 |
+
global $bp, $members_template;
|
177 |
+
|
178 |
+
$start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
|
179 |
+
$from_num = bp_core_number_format( $start_num );
|
180 |
+
$to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
|
181 |
+
$total = bp_core_number_format( $members_template->total_member_count );
|
182 |
+
|
183 |
+
if ( 'active' == $members_template->type )
|
184 |
+
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s active members)', 'buddypress' ), $from_num, $to_num, $total );
|
185 |
+
else if ( 'popular' == $members_template->type )
|
186 |
+
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members with friends)', 'buddypress' ), $from_num, $to_num, $total );
|
187 |
+
else if ( 'online' == $members_template->type )
|
188 |
+
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members online)', 'buddypress' ), $from_num, $to_num, $total );
|
189 |
+
else
|
190 |
+
echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
|
191 |
+
|
192 |
+
?><span class="ajax-loader"></span><?php
|
193 |
+
}
|
194 |
+
|
195 |
+
function bp_members_pagination_links() {
|
196 |
+
echo bp_get_members_pagination_links();
|
197 |
+
}
|
198 |
+
function bp_get_members_pagination_links() {
|
199 |
+
global $members_template;
|
200 |
+
|
201 |
+
return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* bp_member_user_id()
|
206 |
+
*
|
207 |
+
* Echo id from bp_get_member_user_id()
|
208 |
+
*
|
209 |
+
* @uses bp_get_member_user_id()
|
210 |
+
*/
|
211 |
+
function bp_member_user_id() {
|
212 |
+
echo bp_get_member_user_id();
|
213 |
+
}
|
214 |
+
/**
|
215 |
+
* bp_get_member_user_id()
|
216 |
+
*
|
217 |
+
* Get the id of the user in a members loop
|
218 |
+
*
|
219 |
+
* @global object $members_template
|
220 |
+
* @return string Members id
|
221 |
+
*/
|
222 |
+
function bp_get_member_user_id() {
|
223 |
+
global $members_template;
|
224 |
+
|
225 |
+
return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* bp_member_user_nicename()
|
230 |
+
*
|
231 |
+
* Echo nicename from bp_get_member_user_nicename()
|
232 |
+
*
|
233 |
+
* @uses bp_get_member_user_nicename()
|
234 |
+
*/
|
235 |
+
function bp_member_user_nicename() {
|
236 |
+
echo bp_get_member_user_nicename();
|
237 |
+
}
|
238 |
+
/**
|
239 |
+
* bp_get_member_user_nicename()
|
240 |
+
*
|
241 |
+
* Get the nicename of the user in a members loop
|
242 |
+
*
|
243 |
+
* @global object $members_template
|
244 |
+
* @return string Members nicename
|
245 |
+
*/
|
246 |
+
function bp_get_member_user_nicename() {
|
247 |
+
global $members_template;
|
248 |
+
return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* bp_member_user_login()
|
253 |
+
*
|
254 |
+
* Echo login from bp_get_member_user_login()
|
255 |
+
*
|
256 |
+
* @uses bp_get_member_user_login()
|
257 |
+
*/
|
258 |
+
function bp_member_user_login() {
|
259 |
+
echo bp_get_member_user_login();
|
260 |
+
}
|
261 |
+
/**
|
262 |
+
* bp_get_member_user_login()
|
263 |
+
*
|
264 |
+
* Get the login of the user in a members loop
|
265 |
+
*
|
266 |
+
* @global object $members_template
|
267 |
+
* @return string Members login
|
268 |
+
*/
|
269 |
+
function bp_get_member_user_login() {
|
270 |
+
global $members_template;
|
271 |
+
return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* bp_member_user_email()
|
276 |
+
*
|
277 |
+
* Echo email address from bp_get_member_user_email()
|
278 |
+
*
|
279 |
+
* @uses bp_get_member_user_email()
|
280 |
+
*/
|
281 |
+
function bp_member_user_email() {
|
282 |
+
echo bp_get_member_user_email();
|
283 |
+
}
|
284 |
+
/**
|
285 |
+
* bp_get_member_user_email()
|
286 |
+
*
|
287 |
+
* Get the email address of the user in a members loop
|
288 |
+
*
|
289 |
+
* @global object $members_template
|
290 |
+
* @return string Members email address
|
291 |
+
*/
|
292 |
+
function bp_get_member_user_email() {
|
293 |
+
global $members_template;
|
294 |
+
return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
|
295 |
+
}
|
296 |
+
|
297 |
+
function bp_member_is_loggedin_user() {
|
298 |
+
global $bp, $members_template;
|
299 |
+
return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
|
300 |
+
}
|
301 |
+
|
302 |
+
function bp_member_avatar( $args = '' ) {
|
303 |
+
echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
|
304 |
+
}
|
305 |
+
function bp_get_member_avatar( $args = '' ) {
|
306 |
+
global $bp, $members_template;
|
307 |
+
|
308 |
+
$defaults = array(
|
309 |
+
'type' => 'thumb',
|
310 |
+
'width' => false,
|
311 |
+
'height' => false,
|
312 |
+
'class' => 'avatar',
|
313 |
+
'id' => false,
|
314 |
+
'alt' => __( 'Member avatar', 'buddypress' )
|
315 |
+
);
|
316 |
+
|
317 |
+
$r = wp_parse_args( $args, $defaults );
|
318 |
+
extract( $r, EXTR_SKIP );
|
319 |
+
|
320 |
+
return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
|
321 |
+
}
|
322 |
+
|
323 |
+
function bp_member_permalink() {
|
324 |
+
echo bp_get_member_permalink();
|
325 |
+
}
|
326 |
+
function bp_get_member_permalink() {
|
327 |
+
global $members_template;
|
328 |
+
|
329 |
+
return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
|
330 |
+
}
|
331 |
+
function bp_member_link() { echo bp_get_member_permalink(); }
|
332 |
+
function bp_get_member_link() { return bp_get_member_permalink(); }
|
333 |
+
|
334 |
+
function bp_member_name() {
|
335 |
+
echo apply_filters( 'bp_member_name', bp_get_member_name() );
|
336 |
+
}
|
337 |
+
function bp_get_member_name() {
|
338 |
+
global $members_template;
|
339 |
+
|
340 |
+
if ( empty($members_template->member->fullname) )
|
341 |
+
$members_template->member->fullname = $members_template->member->display_name;
|
342 |
+
|
343 |
+
return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
|
344 |
+
}
|
345 |
+
add_filter( 'bp_get_member_name', 'wp_filter_kses' );
|
346 |
+
add_filter( 'bp_get_member_name', 'stripslashes' );
|
347 |
+
add_filter( 'bp_get_member_name', 'strip_tags' );
|
348 |
+
|
349 |
+
function bp_member_last_active() {
|
350 |
+
echo bp_get_member_last_active();
|
351 |
+
}
|
352 |
+
function bp_get_member_last_active() {
|
353 |
+
global $members_template;
|
354 |
+
|
355 |
+
$last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) );
|
356 |
+
|
357 |
+
return apply_filters( 'bp_member_last_active', $last_activity );
|
358 |
+
}
|
359 |
+
|
360 |
+
function bp_member_latest_update( $args = '' ) {
|
361 |
+
echo bp_get_member_latest_update( $args );
|
362 |
+
}
|
363 |
+
function bp_get_member_latest_update( $args = '' ) {
|
364 |
+
global $members_template, $bp;
|
365 |
+
|
366 |
+
$defaults = array(
|
367 |
+
'length' => 15
|
368 |
+
);
|
369 |
+
|
370 |
+
$r = wp_parse_args( $args, $defaults );
|
371 |
+
extract( $r, EXTR_SKIP );
|
372 |
+
|
373 |
+
if ( !$update = maybe_unserialize( $members_template->member->latest_update ) )
|
374 |
+
return false;
|
375 |
+
|
376 |
+
$update_content = apply_filters( 'bp_get_activity_latest_update', strip_tags( bp_create_excerpt( $update['content'], $length ) ) );
|
377 |
+
|
378 |
+
if ( !empty( $update['id'] ) )
|
379 |
+
$update_content .= ' · <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '">' . __( 'View', 'buddypress' ) . '</a>';
|
380 |
+
|
381 |
+
return apply_filters( 'bp_get_member_latest_update', $update_content );
|
382 |
+
}
|
383 |
+
|
384 |
+
function bp_member_profile_data( $args = '' ) {
|
385 |
+
echo bp_get_member_profile_data( $args );
|
386 |
+
}
|
387 |
+
function bp_get_member_profile_data( $args = '' ) {
|
388 |
+
global $members_template;
|
389 |
+
|
390 |
+
if ( !function_exists( 'xprofile_install' ) )
|
391 |
+
return false;
|
392 |
+
|
393 |
+
$defaults = array(
|
394 |
+
'field' => false, // Field name
|
395 |
+
);
|
396 |
+
|
397 |
+
$r = wp_parse_args( $args, $defaults );
|
398 |
+
extract( $r, EXTR_SKIP );
|
399 |
+
|
400 |
+
// Populate the user if it hasn't been already.
|
401 |
+
if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
|
402 |
+
$members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
|
403 |
+
|
404 |
+
$data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
|
405 |
+
|
406 |
+
return apply_filters( 'bp_get_member_profile_data', $data );
|
407 |
+
}
|
408 |
+
|
409 |
+
function bp_member_registered() {
|
410 |
+
echo bp_get_member_registered();
|
411 |
+
}
|
412 |
+
function bp_get_member_registered() {
|
413 |
+
global $members_template;
|
414 |
+
|
415 |
+
$registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
|
416 |
+
|
417 |
+
return apply_filters( 'bp_member_last_active', $registered );
|
418 |
+
}
|
419 |
+
|
420 |
+
function bp_member_random_profile_data() {
|
421 |
+
global $members_template;
|
422 |
+
|
423 |
+
if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
|
424 |
+
<?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
|
425 |
+
<strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
|
426 |
+
<?php echo wp_filter_kses( $random_data[0]->value ) ?>
|
427 |
+
<?php }
|
428 |
+
}
|
429 |
+
|
430 |
+
function bp_member_hidden_fields() {
|
431 |
+
if ( isset( $_REQUEST['s'] ) ) {
|
432 |
+
echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';
|
433 |
+
}
|
434 |
+
|
435 |
+
if ( isset( $_REQUEST['letter'] ) ) {
|
436 |
+
echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
|
437 |
+
}
|
438 |
+
|
439 |
+
if ( isset( $_REQUEST['members_search'] ) ) {
|
440 |
+
echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
function bp_directory_members_search_form() {
|
445 |
+
global $bp;
|
446 |
+
|
447 |
+
$search_value = __( 'Search anything...', 'buddypress' );
|
448 |
+
if ( !empty( $_GET['s'] ) )
|
449 |
+
$search_value = $_GET['s'];
|
450 |
+
|
451 |
+
?>
|
452 |
+
<form action="" method="get" id="search-members-form">
|
453 |
+
<label><input type="text" name="s" id="members_search" value="<?php echo esc_attr( $search_value ) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
|
454 |
+
<input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
|
455 |
+
</form>
|
456 |
+
<?php
|
457 |
+
}
|
458 |
+
|
459 |
+
function bp_total_site_member_count() {
|
460 |
+
echo bp_get_total_site_member_count();
|
461 |
+
}
|
462 |
+
function bp_get_total_site_member_count() {
|
463 |
+
return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
|
464 |
+
}
|
465 |
+
|
466 |
+
|
467 |
+
/** Navigation and other misc template tags **/
|
468 |
+
|
469 |
+
/**
|
470 |
+
* bp_get_nav()
|
471 |
+
* TEMPLATE TAG
|
472 |
+
*
|
473 |
+
* Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
|
474 |
+
* Each component adds to this navigation array within its own [component_name]_setup_nav() function.
|
475 |
+
*
|
476 |
+
* This navigation array is the top level navigation, so it contains items such as:
|
477 |
+
* [Blog, Profile, Messages, Groups, Friends] ...
|
478 |
+
*
|
479 |
+
* The function will also analyze the current component the user is in, to determine whether
|
480 |
+
* or not to highlight a particular nav item.
|
481 |
+
*
|
482 |
+
* @package BuddyPress Core
|
483 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
484 |
+
*/
|
485 |
+
function bp_get_loggedin_user_nav() {
|
486 |
+
global $bp, $current_blog;
|
487 |
+
|
488 |
+
/* Loop through each navigation item */
|
489 |
+
foreach( (array) $bp->bp_nav as $nav_item ) {
|
490 |
+
/* If the current component matches the nav item id, then add a highlight CSS class. */
|
491 |
+
if ( !bp_is_directory() && $bp->active_components[$bp->current_component] == $nav_item['css_id'] )
|
492 |
+
$selected = ' class="current selected"';
|
493 |
+
else
|
494 |
+
$selected = '';
|
495 |
+
|
496 |
+
/* If we are viewing another person (current_userid does not equal loggedin_user->id)
|
497 |
+
then check to see if the two users are friends. if they are, add a highlight CSS class
|
498 |
+
to the friends nav item if it exists. */
|
499 |
+
if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
|
500 |
+
$selected = '';
|
501 |
+
|
502 |
+
if ( function_exists('friends_install') ) {
|
503 |
+
if ( $nav_item['css_id'] == $bp->friends->id ) {
|
504 |
+
if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
|
505 |
+
$selected = ' class="current selected"';
|
506 |
+
}
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
/* echo out the final list item */
|
511 |
+
echo apply_filters( 'bp_get_loggedin_user_nav_' . $nav_item['css_id'], '<li id="li-nav-' . $nav_item['css_id'] . '" ' . $selected . '><a id="my-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>', &$nav_item );
|
512 |
+
}
|
513 |
+
|
514 |
+
/* Always add a log out list item to the end of the navigation */
|
515 |
+
if ( function_exists( 'wp_logout_url' ) ) {
|
516 |
+
$logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
|
517 |
+
} else {
|
518 |
+
$logout_link = '<li><a id="wp-logout" href="' . site_url() . '/wp-login.php?action=logout&redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
|
519 |
+
}
|
520 |
+
|
521 |
+
echo apply_filters( 'bp_logout_nav_link', $logout_link );
|
522 |
+
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* bp_get_displayed_user_nav()
|
526 |
+
* TEMPLATE TAG
|
527 |
+
*
|
528 |
+
* Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
|
529 |
+
* yourself.
|
530 |
+
*
|
531 |
+
* @package BuddyPress Core
|
532 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
533 |
+
*/
|
534 |
+
function bp_get_displayed_user_nav() {
|
535 |
+
global $bp;
|
536 |
+
|
537 |
+
foreach ( (array)$bp->bp_nav as $user_nav_item ) {
|
538 |
+
if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
|
539 |
+
continue;
|
540 |
+
|
541 |
+
if ( $bp->current_component == $user_nav_item['slug'] )
|
542 |
+
$selected = ' class="current selected"';
|
543 |
+
else
|
544 |
+
$selected = '';
|
545 |
+
|
546 |
+
if ( $bp->loggedin_user->domain )
|
547 |
+
$link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
|
548 |
+
else
|
549 |
+
$link = $bp->displayed_user->domain . $user_nav_item['link'];
|
550 |
+
|
551 |
+
echo apply_filters( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item );
|
552 |
+
}
|
553 |
+
}
|
554 |
+
|
555 |
+
/**
|
556 |
+
* bp_get_options_nav()
|
557 |
+
* TEMPLATE TAG
|
558 |
+
*
|
559 |
+
* Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
|
560 |
+
* Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
|
561 |
+
*
|
562 |
+
* This sub navigation array is the secondary level navigation, so for profile it contains:
|
563 |
+
* [Public, Edit Profile, Change Avatar]
|
564 |
+
*
|
565 |
+
* The function will also analyze the current action for the current component to determine whether
|
566 |
+
* or not to highlight a particular sub nav item.
|
567 |
+
*
|
568 |
+
* @package BuddyPress Core
|
569 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
570 |
+
* @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
|
571 |
+
*/
|
572 |
+
function bp_get_options_nav() {
|
573 |
+
global $bp;
|
574 |
+
|
575 |
+
if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
|
576 |
+
return false;
|
577 |
+
|
578 |
+
/* Loop through each navigation item */
|
579 |
+
foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
|
580 |
+
if ( !$subnav_item['user_has_access'] )
|
581 |
+
continue;
|
582 |
+
|
583 |
+
/* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
|
584 |
+
if ( $subnav_item['slug'] == $bp->current_action ) {
|
585 |
+
$selected = ' class="current selected"';
|
586 |
+
} else {
|
587 |
+
$selected = '';
|
588 |
+
}
|
589 |
+
|
590 |
+
/* echo out the final list item */
|
591 |
+
echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li id="' . $subnav_item['css_id'] . '-personal-li" ' . $selected . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>', $subnav_item );
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
function bp_get_options_title() {
|
596 |
+
global $bp;
|
597 |
+
|
598 |
+
if ( empty( $bp->bp_options_title ) )
|
599 |
+
$bp->bp_options_title = __( 'Options', 'buddypress' );
|
600 |
+
|
601 |
+
echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) );
|
602 |
+
}
|
603 |
+
|
604 |
+
|
605 |
+
/** AVATAR TEMPLATE TAGS *******************************************************/
|
606 |
+
|
607 |
+
/**
|
608 |
+
* bp_has_options_avatar()
|
609 |
+
* TEMPLATE TAG
|
610 |
+
*
|
611 |
+
* Check to see if there is an options avatar. An options avatar is an avatar for something
|
612 |
+
* like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
|
613 |
+
*
|
614 |
+
* @package BuddyPress Core
|
615 |
+
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
|
616 |
+
*/
|
617 |
+
function bp_has_options_avatar() {
|
618 |
+
global $bp;
|
619 |
+
|
620 |
+
if ( empty( $bp->bp_options_avatar ) )
|
621 |
+
return false;
|
622 |
+
|
623 |
+
return true;
|
624 |
+
}
|
625 |
+
|
626 |
+
function bp_get_options_avatar() {
|
627 |
+
global $bp;
|
628 |
+
|
629 |
+
echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
|
630 |
+
}
|
631 |
+
|
632 |
+
function bp_comment_author_avatar() {
|
633 |
+
global $comment;
|
634 |
+
|
635 |
+
if ( function_exists('bp_core_fetch_avatar') ) {
|
636 |
+
echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
|
637 |
+
} else if ( function_exists('get_avatar') ) {
|
638 |
+
get_avatar();
|
639 |
+
}
|
640 |
+
}
|
641 |
+
|
642 |
+
function bp_post_author_avatar() {
|
643 |
+
global $post;
|
644 |
+
|
645 |
+
if ( function_exists('bp_core_fetch_avatar') ) {
|
646 |
+
echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
|
647 |
+
} else if ( function_exists('get_avatar') ) {
|
648 |
+
get_avatar();
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
function bp_loggedin_user_avatar( $args = '' ) {
|
653 |
+
echo bp_get_loggedin_user_avatar( $args );
|
654 |
+
}
|
655 |
+
function bp_get_loggedin_user_avatar( $args = '' ) {
|
656 |
+
global $bp;
|
657 |
+
|
658 |
+
$defaults = array(
|
659 |
+
'type' => 'thumb',
|
660 |
+
'width' => false,
|
661 |
+
'height' => false,
|
662 |
+
'html' => true
|
663 |
+
);
|
664 |
+
|
665 |
+
$r = wp_parse_args( $args, $defaults );
|
666 |
+
extract( $r, EXTR_SKIP );
|
667 |
+
|
668 |
+
return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
|
669 |
+
}
|
670 |
+
|
671 |
+
function bp_displayed_user_avatar( $args = '' ) {
|
672 |
+
echo bp_get_displayed_user_avatar( $args );
|
673 |
+
}
|
674 |
+
function bp_get_displayed_user_avatar( $args = '' ) {
|
675 |
+
global $bp;
|
676 |
+
|
677 |
+
$defaults = array(
|
678 |
+
'type' => 'thumb',
|
679 |
+
'width' => false,
|
680 |
+
'height' => false,
|
681 |
+
'html' => true
|
682 |
+
);
|
683 |
+
|
684 |
+
$r = wp_parse_args( $args, $defaults );
|
685 |
+
extract( $r, EXTR_SKIP );
|
686 |
+
|
687 |
+
return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
|
688 |
+
}
|
689 |
+
|
690 |
+
function bp_avatar_admin_step() {
|
691 |
+
echo bp_get_avatar_admin_step();
|
692 |
+
}
|
693 |
+
function bp_get_avatar_admin_step() {
|
694 |
+
global $bp;
|
695 |
+
|
696 |
+
return apply_filters( 'bp_get_avatar_admin_step', $bp->avatar_admin->step );
|
697 |
+
}
|
698 |
+
|
699 |
+
function bp_avatar_to_crop() {
|
700 |
+
echo bp_get_avatar_to_crop();
|
701 |
+
}
|
702 |
+
function bp_get_avatar_to_crop() {
|
703 |
+
global $bp;
|
704 |
+
|
705 |
+
return apply_filters( 'bp_get_avatar_to_crop', $bp->avatar_admin->image->url );
|
706 |
+
}
|
707 |
+
|
708 |
+
function bp_avatar_to_crop_src() {
|
709 |
+
echo bp_get_avatar_to_crop_src();
|
710 |
+
}
|
711 |
+
function bp_get_avatar_to_crop_src() {
|
712 |
+
global $bp;
|
713 |
+
|
714 |
+
return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
|
715 |
+
}
|
716 |
+
|
717 |
+
function bp_avatar_cropper() {
|
718 |
+
global $bp;
|
719 |
+
|
720 |
+
echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
|
721 |
+
}
|
722 |
+
|
723 |
+
/** OTHER TEMPLATE TAGS *******************************************************/
|
724 |
+
|
725 |
+
function bp_site_name() {
|
726 |
+
echo apply_filters( 'bp_site_name', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
|
727 |
+
}
|
728 |
+
|
729 |
+
function bp_core_get_wp_profile() {
|
730 |
+
global $bp;
|
731 |
+
|
732 |
+
$ud = get_userdata( $bp->displayed_user->id );
|
733 |
+
?>
|
734 |
+
|
735 |
+
<div class="bp-widget wp-profile">
|
736 |
+
<h4><?php _e( 'My Profile' ) ?></h4>
|
737 |
+
|
738 |
+
<table class="wp-profile-fields zebra">
|
739 |
+
<?php if ( $ud->display_name ) { ?>
|
740 |
+
<tr id="wp_displayname">
|
741 |
+
<td class="label">
|
742 |
+
<?php _e( 'Name', 'buddypress' ) ?>
|
743 |
+
</td>
|
744 |
+
<td class="data">
|
745 |
+
<?php echo $ud->display_name ?>
|
746 |
+
</td>
|
747 |
+
</tr>
|
748 |
+
<?php } ?>
|
749 |
+
<?php if ( $ud->user_description ) { ?>
|
750 |
+
<tr id="wp_desc">
|
751 |
+
<td class="label">
|
752 |
+
<?php _e( 'About Me', 'buddypress' ) ?>
|
753 |
+
</td>
|
754 |
+
<td class="data">
|
755 |
+
<?php echo $ud->user_description ?>
|
756 |
+
</td>
|
757 |
+
</tr>
|
758 |
+
<?php } ?>
|
759 |
+
<?php if ( $ud->user_url ) { ?>
|
760 |
+
<tr id="wp_website">
|
761 |
+
<td class="label">
|
762 |
+
<?php _e( 'Website', 'buddypress' ) ?>
|
763 |
+
</td>
|
764 |
+
<td class="data">
|
765 |
+
<?php echo make_clickable( $ud->user_url ) ?>
|
766 |
+
</td>
|
767 |
+
</tr>
|
768 |
+
<?php } ?>
|
769 |
+
<?php if ( $ud->jabber ) { ?>
|
770 |
+
<tr id="wp_jabber">
|
771 |
+
<td class="label">
|
772 |
+
<?php _e( 'Jabber', 'buddypress' ) ?>
|
773 |
+
</td>
|
774 |
+
<td class="data">
|
775 |
+
<?php echo $ud->jabber ?>
|
776 |
+
</td>
|
777 |
+
</tr>
|
778 |
+
<?php } ?>
|
779 |
+
<?php if ( $ud->aim ) { ?>
|
780 |
+
<tr id="wp_aim">
|
781 |
+
<td class="label">
|
782 |
+
<?php _e( 'AOL Messenger', 'buddypress' ) ?>
|
783 |
+
</td>
|
784 |
+
<td class="data">
|
785 |
+
<?php echo $ud->aim ?>
|
786 |
+
</td>
|
787 |
+
</tr>
|
788 |
+
<?php } ?>
|
789 |
+
<?php if ( $ud->yim ) { ?>
|
790 |
+
<tr id="wp_yim">
|
791 |
+
<td class="label">
|
792 |
+
<?php _e( 'Yahoo Messenger', 'buddypress' ) ?>
|
793 |
+
</td>
|
794 |
+
<td class="data">
|
795 |
+
<?php echo $ud->yim ?>
|
796 |
+
</td>
|
797 |
+
</tr>
|
798 |
+
<?php } ?>
|
799 |
+
</table>
|
800 |
+
</div>
|
801 |
+
<?php
|
802 |
+
}
|
803 |
+
|
804 |
+
function bp_get_profile_header() {
|
805 |
+
locate_template( array( '/profile/profile-header.php' ), true );
|
806 |
+
}
|
807 |
+
|
808 |
+
function bp_exists( $component_name ) {
|
809 |
+
if ( function_exists($component_name . '_install') )
|
810 |
+
return true;
|
811 |
+
|
812 |
+
return false;
|
813 |
+
}
|
814 |
+
|
815 |
+
function bp_format_time( $time, $just_date = false ) {
|
816 |
+
if ( !$time )
|
817 |
+
return false;
|
818 |
+
|
819 |
+
// Get GMT offset from root blog
|
820 |
+
$root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
|
821 |
+
|
822 |
+
// Calculate offset time
|
823 |
+
$time_offest = $time + ( $root_blog_offset * 3600 );
|
824 |
+
|
825 |
+
// Current date (January 1, 2010)
|
826 |
+
$date = date( 'F j, Y ', $time_offest );
|
827 |
+
|
828 |
+
// Should we show the time also?
|
829 |
+
if ( !$just_date ) {
|
830 |
+
// Current time (9:50pm)
|
831 |
+
$time = date( ' g:ia', $time_offest );
|
832 |
+
|
833 |
+
// Return string formatted with date and time
|
834 |
+
$date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time );
|
835 |
+
}
|
836 |
+
|
837 |
+
return apply_filters( 'bp_format_time', $date );
|
838 |
+
}
|
839 |
+
|
840 |
+
function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
|
841 |
+
global $bp;
|
842 |
+
|
843 |
+
if ( $capitalize )
|
844 |
+
$youtext = bp_core_ucfirst($youtext);
|
845 |
+
|
846 |
+
if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
|
847 |
+
if ( $echo )
|
848 |
+
echo apply_filters( 'bp_word_or_name', $youtext );
|
849 |
+
else
|
850 |
+
return apply_filters( 'bp_word_or_name', $youtext );
|
851 |
+
} else {
|
852 |
+
$fullname = (array)explode( ' ', $bp->displayed_user->fullname );
|
853 |
+
$nametext = sprintf( $nametext, $fullname[0] );
|
854 |
+
if ( $echo )
|
855 |
+
echo apply_filters( 'bp_word_or_name', $nametext );
|
856 |
+
else
|
857 |
+
return apply_filters( 'bp_word_or_name', $nametext );
|
858 |
+
}
|
859 |
+
}
|
860 |
+
|
861 |
+
function bp_your_or_their( $capitalize = true, $echo = true ) {
|
862 |
+
global $bp;
|
863 |
+
|
864 |
+
if ( $capitalize )
|
865 |
+
$yourtext = bp_core_ucfirst($yourtext);
|
866 |
+
|
867 |
+
if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
|
868 |
+
if ( $echo )
|
869 |
+
echo apply_filters( 'bp_your_or_their', $yourtext );
|
870 |
+
else
|
871 |
+
return apply_filters( 'bp_your_or_their', $yourtext );
|
872 |
+
} else {
|
873 |
+
if ( $echo )
|
874 |
+
echo apply_filters( 'bp_your_or_their', $theirtext );
|
875 |
+
else
|
876 |
+
return apply_filters( 'bp_your_or_their', $theirtext );
|
877 |
+
}
|
878 |
+
}
|
879 |
+
|
880 |
+
function bp_get_plugin_sidebar() {
|
881 |
+
locate_template( array( 'plugin-sidebar.php' ), true );
|
882 |
+
}
|
883 |
+
|
884 |
+
function bp_page_title() {
|
885 |
+
echo bp_get_page_title();
|
886 |
+
}
|
887 |
+
|
888 |
+
function bp_get_page_title() {
|
889 |
+
global $bp, $post, $wp_query, $current_blog;
|
890 |
+
|
891 |
+
if ( is_front_page() || ( is_home() && bp_is_page( 'home' ) ) ) {
|
892 |
+
$title = __( 'Home', 'buddypress' );
|
893 |
+
|
894 |
+
} else if ( bp_is_blog_page() ) {
|
895 |
+
if ( is_single() ) {
|
896 |
+
$title = __( 'Blog | ' . $post->post_title, 'buddypress' );
|
897 |
+
} else if ( is_category() ) {
|
898 |
+
$title = __( 'Blog | Categories | ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
|
899 |
+
} else if ( is_tag() ) {
|
900 |
+
$title = __( 'Blog | Tags | ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
|
901 |
+
} else if ( is_page() ){
|
902 |
+
$title = $post->post_title;
|
903 |
+
} else
|
904 |
+
$title = __( 'Blog', 'buddypress' );
|
905 |
+
|
906 |
+
} else if ( !empty( $bp->displayed_user->fullname ) ) {
|
907 |
+
$title = strip_tags( $bp->displayed_user->fullname . ' | ' . ucwords( $bp->current_component ) );
|
908 |
+
|
909 |
+
} else if ( $bp->is_single_item ) {
|
910 |
+
$title = ucwords( $bp->current_component ) . ' | ' . $bp->bp_options_title . ' | ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'];
|
911 |
+
|
912 |
+
} else if ( $bp->is_directory ) {
|
913 |
+
if ( !$bp->current_component )
|
914 |
+
$title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
|
915 |
+
else
|
916 |
+
$title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
|
917 |
+
|
918 |
+
} else if ( bp_is_register_page() ) {
|
919 |
+
$title = __( 'Create an Account', 'buddypress' );
|
920 |
+
|
921 |
+
} else if ( bp_is_activation_page() ) {
|
922 |
+
$title = __( 'Activate your Account', 'buddypress' );
|
923 |
+
|
924 |
+
} else if ( bp_is_group_create() ) {
|
925 |
+
$title = __( 'Create a Group', 'buddypress' );
|
926 |
+
|
927 |
+
} else if ( bp_is_create_blog() ) {
|
928 |
+
$title = __( 'Create a Blog', 'buddypress' );
|
929 |
+
}
|
930 |
+
|
931 |
+
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
|
932 |
+
$blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
|
933 |
+
} else {
|
934 |
+
$blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
|
935 |
+
}
|
936 |
+
|
937 |
+
return apply_filters( 'bp_page_title', $blog_title . ' | ' . esc_attr( $title ), esc_attr( $title ) );
|
938 |
+
}
|
939 |
+
|
940 |
+
function bp_styles() {
|
941 |
+
do_action( 'bp_styles' );
|
942 |
+
wp_print_styles();
|
943 |
+
}
|
944 |
+
|
945 |
+
function bp_has_custom_signup_page() {
|
946 |
+
if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
|
947 |
+
return true;
|
948 |
+
|
949 |
+
return false;
|
950 |
+
}
|
951 |
+
|
952 |
+
function bp_signup_page() {
|
953 |
+
echo bp_get_signup_page();
|
954 |
+
}
|
955 |
+
function bp_get_signup_page() {
|
956 |
+
global $bp;
|
957 |
+
|
958 |
+
if ( bp_has_custom_signup_page() )
|
959 |
+
$page = $bp->root_domain . '/' . BP_REGISTER_SLUG;
|
960 |
+
else
|
961 |
+
$page = $bp->root_domain . '/wp-signup.php';
|
962 |
+
|
963 |
+
return apply_filters( 'bp_get_signup_page', $page );
|
964 |
+
}
|
965 |
+
|
966 |
+
function bp_has_custom_activation_page() {
|
967 |
+
if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
|
968 |
+
return true;
|
969 |
+
|
970 |
+
return false;
|
971 |
+
}
|
972 |
+
|
973 |
+
function bp_activation_page() {
|
974 |
+
echo bp_get_activation_page();
|
975 |
+
}
|
976 |
+
function bp_get_activation_page() {
|
977 |
+
global $bp;
|
978 |
+
|
979 |
+
if ( bp_has_custom_activation_page() )
|
980 |
+
$page = $bp->root_domain . '/' . BP_ACTIVATION_SLUG;
|
981 |
+
else
|
982 |
+
$page = $bp->root_domain . '/wp-activate.php';
|
983 |
+
|
984 |
+
return apply_filters( 'bp_get_activation_page', $page );
|
985 |
+
}
|
986 |
+
|
987 |
+
/**
|
988 |
+
* bp_search_form_available()
|
989 |
+
*
|
990 |
+
* Only show the search form if there are available objects to search for.
|
991 |
+
*
|
992 |
+
* @global array $bp
|
993 |
+
* @uses function_exists
|
994 |
+
* @uses bp_core_is_multisite()
|
995 |
+
* @return bool Filterable result
|
996 |
+
*/
|
997 |
+
function bp_search_form_enabled() {
|
998 |
+
global $bp;
|
999 |
+
|
1000 |
+
if ( function_exists( 'xprofile_install' )
|
1001 |
+
|| function_exists( 'groups_install' )
|
1002 |
+
|| ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
|
1003 |
+
|| ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
|
1004 |
+
) {
|
1005 |
+
$search_enabled = true;
|
1006 |
+
} else {
|
1007 |
+
$search_enabled = false;
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
return apply_filters( 'bp_search_form_enabled', $search_enabled );
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
function bp_search_form_action() {
|
1014 |
+
global $bp;
|
1015 |
+
|
1016 |
+
return apply_filters( 'bp_search_form_action', $bp->root_domain . '/' . BP_SEARCH_SLUG );
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
function bp_search_form_type_select() {
|
1020 |
+
global $bp;
|
1021 |
+
|
1022 |
+
// Eventually this won't be needed and a page will be built to integrate all search results.
|
1023 |
+
$selection_box = '<select name="search-which" id="search-which" style="width: auto">';
|
1024 |
+
|
1025 |
+
if ( function_exists( 'xprofile_install' ) )
|
1026 |
+
$selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
|
1027 |
+
|
1028 |
+
if ( function_exists( 'groups_install' ) )
|
1029 |
+
$selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
|
1030 |
+
|
1031 |
+
if ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
|
1032 |
+
$selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
|
1033 |
+
|
1034 |
+
if ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
|
1035 |
+
$selection_box .= '<option value="blogs">' . __( 'Blogs', 'buddypress' ) . '</option>';
|
1036 |
+
|
1037 |
+
$selection_box .= '</select>';
|
1038 |
+
|
1039 |
+
return apply_filters( 'bp_search_form_type_select', $selection_box );
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
function bp_search_form() {
|
1043 |
+
$form = '
|
1044 |
+
<form action="' . bp_search_form_action() . '" method="post" id="search-form">
|
1045 |
+
<input type="text" id="search-terms" name="search-terms" value="" />
|
1046 |
+
' . bp_search_form_type_select() . '
|
1047 |
+
|
1048 |
+
<input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
|
1049 |
+
' . wp_nonce_field( 'bp_search_form' ) . '
|
1050 |
+
</form>
|
1051 |
+
';
|
1052 |
+
|
1053 |
+
echo apply_filters( 'bp_search_form', $form );
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
function bp_log_out_link() {
|
1057 |
+
global $bp;
|
1058 |
+
if ( function_exists('wp_logout_url') )
|
1059 |
+
$logout_link = '<a href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
|
1060 |
+
else
|
1061 |
+
$logout_link = '<a href="' . $bp->root_domain . '/wp-login.php?action=logout&redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
|
1062 |
+
|
1063 |
+
echo apply_filters( 'bp_logout_link', $logout_link );
|
1064 |
+
}
|
1065 |
+
|
1066 |
+
function bp_custom_profile_boxes() {
|
1067 |
+
do_action( 'bp_custom_profile_boxes' );
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
function bp_custom_profile_sidebar_boxes() {
|
1071 |
+
do_action( 'bp_custom_profile_sidebar_boxes' );
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
/**
|
1075 |
+
* bp_button( $button )
|
1076 |
+
*
|
1077 |
+
* Creates and outputs a button.
|
1078 |
+
* Args: div_id | div_class | a_href | a_title | a_id | a_class | a_rel | a_text
|
1079 |
+
*
|
1080 |
+
* @param array $button
|
1081 |
+
*/
|
1082 |
+
function bp_button( $button = '' ) {
|
1083 |
+
echo bp_get_button( $button );
|
1084 |
+
}
|
1085 |
+
/**
|
1086 |
+
* bp_get_button( $button )
|
1087 |
+
*
|
1088 |
+
* Creates and returns a button.
|
1089 |
+
* Args: div_id | div_class | a_href | a_title | a_id | a_class | a_rel | a_text
|
1090 |
+
*
|
1091 |
+
* @param array $button
|
1092 |
+
* @return string
|
1093 |
+
*/
|
1094 |
+
function bp_get_button( $button = '' ) {
|
1095 |
+
$btn = new BP_Button( $button );
|
1096 |
+
return apply_filters( 'bp_get_button', $btn->contents, $button );
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
/**
|
1100 |
+
* bp_create_excerpt()
|
1101 |
+
*
|
1102 |
+
* Fakes an excerpt on any content. Will not truncate words.
|
1103 |
+
*
|
1104 |
+
* @package BuddyPress Core
|
1105 |
+
* @param $text str The text to create the excerpt from
|
1106 |
+
* @uses $excerpt_length The maximum length in characters of the excerpt.
|
1107 |
+
* @return str The excerpt text
|
1108 |
+
*/
|
1109 |
+
function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
|
1110 |
+
$text = str_replace(']]>', ']]>', $text);
|
1111 |
+
|
1112 |
+
if ( $filter_shortcodes )
|
1113 |
+
$text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
|
1114 |
+
|
1115 |
+
$words = preg_split(
|
1116 |
+
"%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
|
1117 |
+
$text,
|
1118 |
+
$excerpt_length + 1,
|
1119 |
+
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
|
1120 |
+
);
|
1121 |
+
|
1122 |
+
if (count($words) > $excerpt_length) {
|
1123 |
+
array_pop($words);
|
1124 |
+
array_push($words, '[...]');
|
1125 |
+
$text = implode(' ', $words);
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
return apply_filters( 'bp_create_excerpt', $text );
|
1129 |
+
}
|
1130 |
+
add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
|
1131 |
+
add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
|
1132 |
+
add_filter( 'bp_create_excerpt', 'force_balance_tags' );
|
1133 |
+
|
1134 |
+
function bp_total_member_count() {
|
1135 |
+
echo bp_get_total_member_count();
|
1136 |
+
}
|
1137 |
+
function bp_get_total_member_count() {
|
1138 |
+
return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
|
1139 |
+
}
|
1140 |
+
add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
|
1141 |
+
|
1142 |
+
/*** Signup form template tags **********************/
|
1143 |
+
|
1144 |
+
function bp_signup_username_value() {
|
1145 |
+
echo bp_get_signup_username_value();
|
1146 |
+
}
|
1147 |
+
function bp_get_signup_username_value() {
|
1148 |
+
return apply_filters( 'bp_get_signup_username_value', $_POST['signup_username'] );
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
function bp_signup_email_value() {
|
1152 |
+
echo bp_get_signup_email_value();
|
1153 |
+
}
|
1154 |
+
function bp_get_signup_email_value() {
|
1155 |
+
return apply_filters( 'bp_get_signup_email_value', $_POST['signup_email'] );
|
1156 |
+
}
|
1157 |
+
|
1158 |
+
function bp_signup_with_blog_value() {
|
1159 |
+
echo bp_get_signup_with_blog_value();
|
1160 |
+
}
|
1161 |
+
function bp_get_signup_with_blog_value() {
|
1162 |
+
return apply_filters( 'bp_get_signup_with_blog_value', $_POST['signup_with_blog'] );
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
function bp_signup_blog_url_value() {
|
1166 |
+
echo bp_get_signup_blog_url_value();
|
1167 |
+
}
|
1168 |
+
function bp_get_signup_blog_url_value() {
|
1169 |
+
return apply_filters( 'bp_get_signup_blog_url_value', $_POST['signup_blog_url'] );
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
function bp_signup_blog_title_value() {
|
1173 |
+
echo bp_get_signup_blog_title_value();
|
1174 |
+
}
|
1175 |
+
function bp_get_signup_blog_title_value() {
|
1176 |
+
return apply_filters( 'bp_get_signup_blog_title_value', $_POST['signup_blog_title'] );
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
function bp_signup_blog_privacy_value() {
|
1180 |
+
echo bp_get_signup_blog_privacy_value();
|
1181 |
+
}
|
1182 |
+
function bp_get_signup_blog_privacy_value() {
|
1183 |
+
return apply_filters( 'bp_get_signup_blog_privacy_value', $_POST['signup_blog_privacy'] );
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
function bp_signup_avatar_dir_value() {
|
1187 |
+
echo bp_get_signup_avatar_dir_value();
|
1188 |
+
}
|
1189 |
+
function bp_get_signup_avatar_dir_value() {
|
1190 |
+
global $bp;
|
1191 |
+
|
1192 |
+
return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
|
1193 |
+
}
|
1194 |
+
|
1195 |
+
function bp_current_signup_step() {
|
1196 |
+
echo bp_get_current_signup_step();
|
1197 |
+
}
|
1198 |
+
function bp_get_current_signup_step() {
|
1199 |
+
global $bp;
|
1200 |
+
|
1201 |
+
return $bp->signup->step;
|
1202 |
+
}
|
1203 |
+
|
1204 |
+
function bp_signup_avatar( $args = '' ) {
|
1205 |
+
echo bp_get_signup_avatar( $args );
|
1206 |
+
}
|
1207 |
+
function bp_get_signup_avatar( $args = '' ) {
|
1208 |
+
global $bp;
|
1209 |
+
|
1210 |
+
$defaults = array(
|
1211 |
+
'size' => BP_AVATAR_FULL_WIDTH,
|
1212 |
+
'class' => 'avatar',
|
1213 |
+
'alt' => __( 'Your Avatar', 'buddypress' )
|
1214 |
+
);
|
1215 |
+
|
1216 |
+
$r = wp_parse_args( $args, $defaults );
|
1217 |
+
extract( $r, EXTR_SKIP );
|
1218 |
+
|
1219 |
+
$signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
|
1220 |
+
|
1221 |
+
if ( empty( $signup_avatar_dir ) ) {
|
1222 |
+
if ( empty( $bp->grav_default->user ) ) {
|
1223 |
+
$default_grav = 'wavatar';
|
1224 |
+
} else if ( 'mystery' == $bp->grav_default->user ) {
|
1225 |
+
$default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
|
1226 |
+
} else {
|
1227 |
+
$default_grav = $bp->grav_default->user;
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
$gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
|
1231 |
+
$gravatar_img = '<img src="' . $gravatar_url . md5( strtolower( $_POST['signup_email'] ) ) . '?d=' . $default_grav . '&s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
|
1232 |
+
} else {
|
1233 |
+
$gravatar_img = bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) );
|
1234 |
+
}
|
1235 |
+
|
1236 |
+
return apply_filters( 'bp_get_signup_avatar', $gravatar_img );
|
1237 |
+
}
|
1238 |
+
|
1239 |
+
function bp_signup_allowed() {
|
1240 |
+
echo bp_get_signup_allowed();
|
1241 |
+
}
|
1242 |
+
function bp_get_signup_allowed() {
|
1243 |
+
global $bp;
|
1244 |
+
|
1245 |
+
if ( bp_core_is_multisite() ) {
|
1246 |
+
if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
|
1247 |
+
return true;
|
1248 |
+
} else {
|
1249 |
+
if ( (int)get_option( 'users_can_register') )
|
1250 |
+
return true;
|
1251 |
+
}
|
1252 |
+
return false;
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
function bp_blog_signup_allowed() {
|
1256 |
+
echo bp_get_blog_signup_allowed();
|
1257 |
+
}
|
1258 |
+
function bp_get_blog_signup_allowed() {
|
1259 |
+
global $bp;
|
1260 |
+
|
1261 |
+
if ( !bp_core_is_multisite() )
|
1262 |
+
return false;
|
1263 |
+
|
1264 |
+
$status = $bp->site_options['registration'];
|
1265 |
+
if ( 'none' != $status && 'user' != $status )
|
1266 |
+
return true;
|
1267 |
+
|
1268 |
+
return false;
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
function bp_account_was_activated() {
|
1272 |
+
global $bp;
|
1273 |
+
|
1274 |
+
return $bp->activation_complete;
|
1275 |
+
}
|
1276 |
+
|
1277 |
+
function bp_registration_needs_activation() {
|
1278 |
+
return apply_filters( 'bp_registration_needs_activation', true );
|
1279 |
+
}
|
1280 |
+
|
1281 |
+
function bp_mentioned_user_display_name( $user_id_or_username ) {
|
1282 |
+
echo bp_get_mentioned_user_display_name( $user_id_or_username );
|
1283 |
+
}
|
1284 |
+
function bp_get_mentioned_user_display_name( $user_id_or_username ) {
|
1285 |
+
if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
|
1286 |
+
$name = __( 'a user' );
|
1287 |
+
|
1288 |
+
return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
function bp_get_option( $option_name ) {
|
1292 |
+
global $bp;
|
1293 |
+
|
1294 |
+
return apply_filters( 'bp_get_option', $bp->site_options[$option_name] );
|
1295 |
+
}
|
1296 |
+
|
1297 |
+
/**
|
1298 |
+
* Allow templates to pass parameters directly into the template loops via AJAX
|
1299 |
+
*
|
1300 |
+
* For the most part this will be filtered in a theme's functions.php for example
|
1301 |
+
* in the default theme it is filtered via bp_dtheme_ajax_querystring()
|
1302 |
+
*
|
1303 |
+
* By using this template tag in the templates it will stop them from showing errors
|
1304 |
+
* if someone copies the templates from the default theme into another WordPress theme
|
1305 |
+
* without coping the functions from functions.php.
|
1306 |
+
*/
|
1307 |
+
function bp_ajax_querystring( $object = false ) {
|
1308 |
+
global $bp;
|
1309 |
+
|
1310 |
+
$bp->ajax_querystring = apply_filters( 'bp_ajax_querystring', $query_string, $object );
|
1311 |
+
return $bp->ajax_querystring;
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
|
1315 |
+
/*** CUSTOM LOOP TEMPLATE CLASSES *******************/
|
1316 |
+
|
1317 |
+
|
1318 |
+
/* Template functions for fetching globals, without querying the DB again
|
1319 |
+
also means we dont have to use the $bp variable in the template (looks messy) */
|
1320 |
+
|
1321 |
+
function bp_last_activity( $user_id = false, $echo = true ) {
|
1322 |
+
global $bp;
|
1323 |
+
|
1324 |
+
if ( !$user_id )
|
1325 |
+
$user_id = $bp->displayed_user->id;
|
1326 |
+
|
1327 |
+
$last_activity = bp_core_get_last_activity( get_user_meta( $user_id, 'last_activity', true ), __('active %s ago', 'buddypress') );
|
1328 |
+
|
1329 |
+
if ( $echo )
|
1330 |
+
echo apply_filters( 'bp_last_activity', $last_activity );
|
1331 |
+
else
|
1332 |
+
return apply_filters( 'bp_last_activity', $last_activity );
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
function bp_user_has_access() {
|
1336 |
+
global $bp;
|
1337 |
+
|
1338 |
+
if ( is_super_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
|
1339 |
+
$has_access = true;
|
1340 |
+
else
|
1341 |
+
$has_access = false;
|
1342 |
+
|
1343 |
+
return apply_filters( 'bp_user_has_access', $has_access );
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
function bp_user_firstname() {
|
1347 |
+
echo bp_get_user_firstname();
|
1348 |
+
}
|
1349 |
+
function bp_get_user_firstname( $name = false ) {
|
1350 |
+
global $bp;
|
1351 |
+
|
1352 |
+
// Try to get displayed user
|
1353 |
+
if ( empty( $name ) )
|
1354 |
+
$name = $bp->displayed_user->fullname;
|
1355 |
+
|
1356 |
+
// Fall back on logged in user
|
1357 |
+
if ( empty( $name ) )
|
1358 |
+
$name = $bp->loggedin_user->fullname;
|
1359 |
+
|
1360 |
+
$fullname = (array)explode( ' ', $name );
|
1361 |
+
|
1362 |
+
return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
function bp_loggedin_user_link() {
|
1366 |
+
echo bp_get_loggedin_user_link();
|
1367 |
+
}
|
1368 |
+
function bp_get_loggedin_user_link() {
|
1369 |
+
global $bp;
|
1370 |
+
|
1371 |
+
return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
|
1372 |
+
}
|
1373 |
+
|
1374 |
+
/* @todo Deprecate incorrectly named function? */
|
1375 |
+
function bp_loggedinuser_link() {
|
1376 |
+
global $bp;
|
1377 |
+
|
1378 |
+
if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
|
1379 |
+
echo apply_filters( 'bp_loggedin_user_link', $link );
|
1380 |
+
}
|
1381 |
+
|
1382 |
+
function bp_displayed_user_link() {
|
1383 |
+
echo bp_get_displayed_user_link();
|
1384 |
+
}
|
1385 |
+
function bp_get_displayed_user_link() {
|
1386 |
+
global $bp;
|
1387 |
+
|
1388 |
+
return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
|
1389 |
+
}
|
1390 |
+
function bp_user_link() { bp_displayed_user_link(); } // Deprecated.
|
1391 |
+
|
1392 |
+
function bp_displayed_user_id() {
|
1393 |
+
global $bp;
|
1394 |
+
return apply_filters( 'bp_displayed_user_id', $bp->displayed_user->id );
|
1395 |
+
}
|
1396 |
+
function bp_current_user_id() { return bp_displayed_user_id(); }
|
1397 |
+
|
1398 |
+
function bp_loggedin_user_id() {
|
1399 |
+
global $bp;
|
1400 |
+
return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
|
1401 |
+
}
|
1402 |
+
|
1403 |
+
function bp_displayed_user_domain() {
|
1404 |
+
global $bp;
|
1405 |
+
return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
function bp_loggedin_user_domain() {
|
1409 |
+
global $bp;
|
1410 |
+
return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
|
1411 |
+
}
|
1412 |
+
|
1413 |
+
function bp_displayed_user_fullname() {
|
1414 |
+
echo bp_get_displayed_user_fullname();
|
1415 |
+
}
|
1416 |
+
function bp_get_displayed_user_fullname() {
|
1417 |
+
global $bp;
|
1418 |
+
|
1419 |
+
return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
|
1420 |
+
}
|
1421 |
+
function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
|
1422 |
+
|
1423 |
+
|
1424 |
+
function bp_loggedin_user_fullname() {
|
1425 |
+
echo bp_get_loggedin_user_fullname();
|
1426 |
+
}
|
1427 |
+
function bp_get_loggedin_user_fullname() {
|
1428 |
+
global $bp;
|
1429 |
+
return apply_filters( 'bp_get_loggedin_user_fullname', $bp->loggedin_user->fullname );
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
function bp_displayed_user_username() {
|
1433 |
+
echo bp_get_displayed_user_username();
|
1434 |
+
}
|
1435 |
+
function bp_get_displayed_user_username() {
|
1436 |
+
global $bp;
|
1437 |
+
return apply_filters( 'bp_get_displayed_user_username', bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) );
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
function bp_loggedin_user_username() {
|
1441 |
+
echo bp_get_loggedin_user_username();
|
1442 |
+
}
|
1443 |
+
function bp_get_loggedin_user_username() {
|
1444 |
+
global $bp;
|
1445 |
+
return apply_filters( 'bp_get_loggedin_user_username', bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) );
|
1446 |
+
}
|
1447 |
+
|
1448 |
+
function bp_current_component() {
|
1449 |
+
global $bp;
|
1450 |
+
return apply_filters( 'bp_current_component', $bp->current_component );
|
1451 |
+
}
|
1452 |
+
|
1453 |
+
function bp_current_action() {
|
1454 |
+
global $bp;
|
1455 |
+
return apply_filters( 'bp_current_action', $bp->current_action );
|
1456 |
+
}
|
1457 |
+
|
1458 |
+
function bp_current_item() {
|
1459 |
+
global $bp;
|
1460 |
+
return apply_filters( 'bp_current_item', $bp->current_item );
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
function bp_action_variables() {
|
1464 |
+
global $bp;
|
1465 |
+
return apply_filters( 'bp_action_variables', $bp->action_variables );
|
1466 |
+
}
|
1467 |
+
|
1468 |
+
function bp_root_domain() {
|
1469 |
+
echo bp_get_root_domain();
|
1470 |
+
}
|
1471 |
+
function bp_get_root_domain() {
|
1472 |
+
global $bp;
|
1473 |
+
|
1474 |
+
return apply_filters( 'bp_get_root_domain', $bp->root_domain );
|
1475 |
+
}
|
1476 |
+
|
1477 |
+
/* Template is_() functions to determine the current page */
|
1478 |
+
|
1479 |
+
function bp_is_blog_page() {
|
1480 |
+
global $bp, $is_member_page, $wp_query;
|
1481 |
+
|
1482 |
+
if ( $wp_query->is_home && !$bp->is_directory )
|
1483 |
+
return true;
|
1484 |
+
|
1485 |
+
if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
|
1486 |
+
return true;
|
1487 |
+
|
1488 |
+
return false;
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
function bp_is_my_profile() {
|
1492 |
+
global $bp;
|
1493 |
+
|
1494 |
+
if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
|
1495 |
+
$my_profile = true;
|
1496 |
+
else
|
1497 |
+
$my_profile = false;
|
1498 |
+
|
1499 |
+
return apply_filters( 'bp_is_my_profile', $my_profile );
|
1500 |
+
}
|
1501 |
+
function bp_is_home() { return bp_is_my_profile(); }
|
1502 |
+
|
1503 |
+
function bp_is_front_page() {
|
1504 |
+
if ( 'posts' == get_option('show_on_front') && is_home() )
|
1505 |
+
return true;
|
1506 |
+
else if ( bp_is_activity_front_page() )
|
1507 |
+
return true;
|
1508 |
+
else
|
1509 |
+
return is_front_page();
|
1510 |
+
}
|
1511 |
+
|
1512 |
+
function bp_is_activity_front_page() {
|
1513 |
+
global $current_blog;
|
1514 |
+
|
1515 |
+
if ( bp_core_is_main_site() )
|
1516 |
+
$path = bp_core_get_site_path();
|
1517 |
+
else
|
1518 |
+
$path = $current_blog->path;
|
1519 |
+
|
1520 |
+
return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == $path );
|
1521 |
+
}
|
1522 |
+
|
1523 |
+
function bp_is_directory() {
|
1524 |
+
global $bp;
|
1525 |
+
|
1526 |
+
return $bp->is_directory;
|
1527 |
+
}
|
1528 |
+
|
1529 |
+
function bp_is_page($page) {
|
1530 |
+
global $bp;
|
1531 |
+
|
1532 |
+
if ( !$bp->displayed_user->id && $bp->current_component == $page )
|
1533 |
+
return true;
|
1534 |
+
|
1535 |
+
if ( 'home' == $page )
|
1536 |
+
return bp_is_front_page();
|
1537 |
+
|
1538 |
+
return false;
|
1539 |
+
}
|
1540 |
+
|
1541 |
+
function bp_is_active( $component ) {
|
1542 |
+
global $bp_deactivated;
|
1543 |
+
|
1544 |
+
if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
|
1545 |
+
return true;
|
1546 |
+
|
1547 |
+
return false;
|
1548 |
+
}
|
1549 |
+
|
1550 |
+
function bp_is_profile_component() {
|
1551 |
+
global $bp;
|
1552 |
+
|
1553 |
+
if ( BP_XPROFILE_SLUG == $bp->current_component )
|
1554 |
+
return true;
|
1555 |
+
|
1556 |
+
return false;
|
1557 |
+
}
|
1558 |
+
|
1559 |
+
function bp_is_activity_component() {
|
1560 |
+
global $bp;
|
1561 |
+
|
1562 |
+
if ( BP_ACTIVITY_SLUG == $bp->current_component )
|
1563 |
+
return true;
|
1564 |
+
|
1565 |
+
return false;
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
function bp_is_blogs_component() {
|
1569 |
+
global $bp;
|
1570 |
+
|
1571 |
+
if ( BP_BLOGS_SLUG == $bp->current_component )
|
1572 |
+
return true;
|
1573 |
+
|
1574 |
+
return false;
|
1575 |
+
}
|
1576 |
+
|
1577 |
+
function bp_is_messages_component() {
|
1578 |
+
global $bp;
|
1579 |
+
|
1580 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component )
|
1581 |
+
return true;
|
1582 |
+
|
1583 |
+
return false;
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
function bp_is_friends_component() {
|
1587 |
+
global $bp;
|
1588 |
+
|
1589 |
+
if ( BP_FRIENDS_SLUG == $bp->current_component )
|
1590 |
+
return true;
|
1591 |
+
|
1592 |
+
return false;
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
function bp_is_groups_component() {
|
1596 |
+
global $bp;
|
1597 |
+
|
1598 |
+
if ( BP_GROUPS_SLUG == $bp->current_component )
|
1599 |
+
return true;
|
1600 |
+
|
1601 |
+
return false;
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
function bp_is_settings_component() {
|
1605 |
+
global $bp;
|
1606 |
+
|
1607 |
+
if ( BP_SETTINGS_SLUG == $bp->current_component )
|
1608 |
+
return true;
|
1609 |
+
|
1610 |
+
return false;
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
function bp_is_member() {
|
1614 |
+
global $bp;
|
1615 |
+
|
1616 |
+
if ( $bp->displayed_user->id )
|
1617 |
+
return true;
|
1618 |
+
|
1619 |
+
return false;
|
1620 |
+
}
|
1621 |
+
|
1622 |
+
function bp_is_user_activity() {
|
1623 |
+
global $bp;
|
1624 |
+
|
1625 |
+
if ( BP_ACTIVITY_SLUG == $bp->current_component )
|
1626 |
+
return true;
|
1627 |
+
|
1628 |
+
return false;
|
1629 |
+
}
|
1630 |
+
|
1631 |
+
function bp_is_user_friends_activity() {
|
1632 |
+
global $bp;
|
1633 |
+
|
1634 |
+
if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
|
1635 |
+
return true;
|
1636 |
+
|
1637 |
+
return false;
|
1638 |
+
}
|
1639 |
+
|
1640 |
+
function bp_is_activity_permalink() {
|
1641 |
+
global $bp;
|
1642 |
+
|
1643 |
+
if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
|
1644 |
+
return true;
|
1645 |
+
|
1646 |
+
return false;
|
1647 |
+
}
|
1648 |
+
|
1649 |
+
function bp_is_user_profile() {
|
1650 |
+
global $bp;
|
1651 |
+
|
1652 |
+
if ( BP_XPROFILE_SLUG == $bp->current_component || $bp->core->profile->slug == $bp->current_component )
|
1653 |
+
return true;
|
1654 |
+
|
1655 |
+
return false;
|
1656 |
+
}
|
1657 |
+
|
1658 |
+
function bp_is_profile_edit() {
|
1659 |
+
global $bp;
|
1660 |
+
|
1661 |
+
if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
|
1662 |
+
return true;
|
1663 |
+
|
1664 |
+
return false;
|
1665 |
+
}
|
1666 |
+
|
1667 |
+
function bp_is_change_avatar() {
|
1668 |
+
global $bp;
|
1669 |
+
|
1670 |
+
if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
|
1671 |
+
return true;
|
1672 |
+
|
1673 |
+
return false;
|
1674 |
+
}
|
1675 |
+
|
1676 |
+
function bp_is_user_groups() {
|
1677 |
+
global $bp;
|
1678 |
+
|
1679 |
+
if ( BP_GROUPS_SLUG == $bp->current_component )
|
1680 |
+
return true;
|
1681 |
+
|
1682 |
+
return false;
|
1683 |
+
}
|
1684 |
+
|
1685 |
+
function bp_is_group() {
|
1686 |
+
global $bp;
|
1687 |
+
|
1688 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->groups->current_group )
|
1689 |
+
return true;
|
1690 |
+
|
1691 |
+
return false;
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
function bp_is_group_home() {
|
1695 |
+
global $bp;
|
1696 |
+
|
1697 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
|
1698 |
+
return true;
|
1699 |
+
|
1700 |
+
return false;
|
1701 |
+
}
|
1702 |
+
|
1703 |
+
function bp_is_group_create() {
|
1704 |
+
global $bp;
|
1705 |
+
|
1706 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
|
1707 |
+
return true;
|
1708 |
+
|
1709 |
+
return false;
|
1710 |
+
}
|
1711 |
+
|
1712 |
+
|
1713 |
+
function bp_is_group_admin_page() {
|
1714 |
+
global $bp;
|
1715 |
+
|
1716 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
|
1717 |
+
return true;
|
1718 |
+
|
1719 |
+
return false;
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
function bp_is_group_forum() {
|
1723 |
+
global $bp;
|
1724 |
+
|
1725 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
|
1726 |
+
return true;
|
1727 |
+
|
1728 |
+
return false;
|
1729 |
+
}
|
1730 |
+
|
1731 |
+
function bp_is_group_activity() {
|
1732 |
+
global $bp;
|
1733 |
+
|
1734 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
|
1735 |
+
return true;
|
1736 |
+
|
1737 |
+
return false;
|
1738 |
+
}
|
1739 |
+
|
1740 |
+
function bp_is_group_forum_topic() {
|
1741 |
+
global $bp;
|
1742 |
+
|
1743 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
|
1744 |
+
return true;
|
1745 |
+
|
1746 |
+
return false;
|
1747 |
+
}
|
1748 |
+
|
1749 |
+
function bp_is_group_forum_topic_edit() {
|
1750 |
+
global $bp;
|
1751 |
+
|
1752 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] && 'edit' == $bp->action_variables[2] )
|
1753 |
+
return true;
|
1754 |
+
|
1755 |
+
return false;
|
1756 |
+
}
|
1757 |
+
|
1758 |
+
function bp_is_group_members() {
|
1759 |
+
global $bp;
|
1760 |
+
|
1761 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
|
1762 |
+
return true;
|
1763 |
+
|
1764 |
+
return false;
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
function bp_is_group_invites() {
|
1768 |
+
global $bp;
|
1769 |
+
|
1770 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
|
1771 |
+
return true;
|
1772 |
+
|
1773 |
+
return false;
|
1774 |
+
}
|
1775 |
+
|
1776 |
+
function bp_is_group_membership_request() {
|
1777 |
+
global $bp;
|
1778 |
+
|
1779 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
|
1780 |
+
return true;
|
1781 |
+
|
1782 |
+
return false;
|
1783 |
+
}
|
1784 |
+
|
1785 |
+
function bp_is_group_leave() {
|
1786 |
+
global $bp;
|
1787 |
+
|
1788 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
|
1789 |
+
return true;
|
1790 |
+
|
1791 |
+
return false;
|
1792 |
+
}
|
1793 |
+
|
1794 |
+
function bp_is_group_single() {
|
1795 |
+
global $bp;
|
1796 |
+
|
1797 |
+
if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
|
1798 |
+
return true;
|
1799 |
+
|
1800 |
+
return false;
|
1801 |
+
}
|
1802 |
+
|
1803 |
+
function bp_is_user_blogs() {
|
1804 |
+
global $bp;
|
1805 |
+
|
1806 |
+
if ( BP_BLOGS_SLUG == $bp->current_component )
|
1807 |
+
return true;
|
1808 |
+
|
1809 |
+
return false;
|
1810 |
+
}
|
1811 |
+
|
1812 |
+
function bp_is_user_recent_posts() {
|
1813 |
+
global $bp;
|
1814 |
+
|
1815 |
+
if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
|
1816 |
+
return true;
|
1817 |
+
|
1818 |
+
return false;
|
1819 |
+
}
|
1820 |
+
|
1821 |
+
function bp_is_user_recent_commments() {
|
1822 |
+
global $bp;
|
1823 |
+
|
1824 |
+
if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
|
1825 |
+
return true;
|
1826 |
+
|
1827 |
+
return false;
|
1828 |
+
}
|
1829 |
+
|
1830 |
+
function bp_is_create_blog() {
|
1831 |
+
global $bp;
|
1832 |
+
|
1833 |
+
if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
|
1834 |
+
return true;
|
1835 |
+
|
1836 |
+
return false;
|
1837 |
+
}
|
1838 |
+
|
1839 |
+
function bp_is_user_friends() {
|
1840 |
+
global $bp;
|
1841 |
+
|
1842 |
+
if ( BP_FRIENDS_SLUG == $bp->current_component )
|
1843 |
+
return true;
|
1844 |
+
|
1845 |
+
return false;
|
1846 |
+
}
|
1847 |
+
|
1848 |
+
function bp_is_friend_requests() {
|
1849 |
+
global $bp;
|
1850 |
+
|
1851 |
+
if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
|
1852 |
+
return true;
|
1853 |
+
|
1854 |
+
return false;
|
1855 |
+
}
|
1856 |
+
|
1857 |
+
function bp_is_user_messages() {
|
1858 |
+
global $bp;
|
1859 |
+
|
1860 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component )
|
1861 |
+
return true;
|
1862 |
+
|
1863 |
+
return false;
|
1864 |
+
}
|
1865 |
+
|
1866 |
+
function bp_is_messages_inbox() {
|
1867 |
+
global $bp;
|
1868 |
+
|
1869 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
|
1870 |
+
return true;
|
1871 |
+
|
1872 |
+
return false;
|
1873 |
+
}
|
1874 |
+
|
1875 |
+
function bp_is_messages_sentbox() {
|
1876 |
+
global $bp;
|
1877 |
+
|
1878 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
|
1879 |
+
return true;
|
1880 |
+
|
1881 |
+
return false;
|
1882 |
+
}
|
1883 |
+
|
1884 |
+
|
1885 |
+
function bp_is_notices() {
|
1886 |
+
global $bp;
|
1887 |
+
|
1888 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
|
1889 |
+
return true;
|
1890 |
+
|
1891 |
+
return false;
|
1892 |
+
}
|
1893 |
+
|
1894 |
+
|
1895 |
+
function bp_is_messages_compose_screen() {
|
1896 |
+
global $bp;
|
1897 |
+
|
1898 |
+
if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
|
1899 |
+
return true;
|
1900 |
+
|
1901 |
+
return false;
|
1902 |
+
}
|
1903 |
+
|
1904 |
+
function bp_is_single_item() {
|
1905 |
+
global $bp;
|
1906 |
+
|
1907 |
+
if ( $bp->is_single_item )
|
1908 |
+
return true;
|
1909 |
+
|
1910 |
+
return false;
|
1911 |
+
}
|
1912 |
+
|
1913 |
+
function bp_is_activation_page() {
|
1914 |
+
global $bp;
|
1915 |
+
|
1916 |
+
if ( BP_ACTIVATION_SLUG == $bp->current_component )
|
1917 |
+
return true;
|
1918 |
+
|
1919 |
+
return false;
|
1920 |
+
}
|
1921 |
+
|
1922 |
+
function bp_is_register_page() {
|
1923 |
+
global $bp;
|
1924 |
+
|
1925 |
+
if ( BP_REGISTER_SLUG == $bp->current_component )
|
1926 |
+
return true;
|
1927 |
+
|
1928 |
+
return false;
|
1929 |
+
}
|
1930 |
+
|
1931 |
+
/* Use the above is_() functions to output a body class for each page */
|
1932 |
+
|
1933 |
+
function bp_the_body_class() {
|
1934 |
+
echo bp_get_the_body_class();
|
1935 |
+
}
|
1936 |
+
function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
|
1937 |
+
global $bp;
|
1938 |
+
|
1939 |
+
if ( bp_is_front_page() )
|
1940 |
+
$bp_classes[] = 'home-page';
|
1941 |
+
|
1942 |
+
if ( bp_is_directory() )
|
1943 |
+
$bp_classes[] = 'directory';
|
1944 |
+
|
1945 |
+
if ( bp_is_user_profile() && !bp_is_blog_page() )
|
1946 |
+
$bp_classes[] = 'profile';
|
1947 |
+
|
1948 |
+
if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
|
1949 |
+
$bp_classes[] = 'activity';
|
1950 |
+
|
1951 |
+
if ( bp_is_blogs_component() && !bp_is_blog_page() )
|
1952 |
+
$bp_classes[] = 'blogs';
|
1953 |
+
|
1954 |
+
if ( bp_is_messages_component() && !bp_is_blog_page() )
|
1955 |
+
$bp_classes[] = 'messages';
|
1956 |
+
|
1957 |
+
if ( bp_is_friends_component() && !bp_is_blog_page() )
|
1958 |
+
$bp_classes[] = 'friends';
|
1959 |
+
|
1960 |
+
if ( bp_is_groups_component() && !bp_is_blog_page() )
|
1961 |
+
$bp_classes[] = 'groups';
|
1962 |
+
|
1963 |
+
if ( bp_is_settings_component() && !bp_is_blog_page() )
|
1964 |
+
$bp_classes[] = 'settings';
|
1965 |
+
|
1966 |
+
if ( bp_is_single_item() )
|
1967 |
+
$bp_classes[] = 'single-item';
|
1968 |
+
|
1969 |
+
if ( bp_is_messages_inbox() )
|
1970 |
+
$bp_classes[] = 'inbox';
|
1971 |
+
|
1972 |
+
if ( bp_is_messages_sentbox() )
|
1973 |
+
$bp_classes[] = 'sentbox';
|
1974 |
+
|
1975 |
+
if ( bp_is_messages_compose_screen() )
|
1976 |
+
$bp_classes[] = 'compose';
|
1977 |
+
|
1978 |
+
if ( bp_is_notices() )
|
1979 |
+
$bp_classes[] = 'notices';
|
1980 |
+
|
1981 |
+
if ( bp_is_friend_requests() )
|
1982 |
+
$bp_classes[] = 'friend-requests';
|
1983 |
+
|
1984 |
+
if ( bp_is_user_friends() )
|
1985 |
+
$bp_classes[] = 'my-friends';
|
1986 |
+
|
1987 |
+
if ( bp_is_create_blog() )
|
1988 |
+
$bp_classes[] = 'create-blog';
|
1989 |
+
|
1990 |
+
if ( bp_is_user_recent_commments() )
|
1991 |
+
$bp_classes[] = 'recent-comments';
|
1992 |
+
|
1993 |
+
if ( bp_is_user_recent_posts() )
|
1994 |
+
$bp_classes[] = 'recent-posts';
|
1995 |
+
|
1996 |
+
if ( bp_is_user_blogs() && !bp_is_directory() )
|
1997 |
+
$bp_classes[] = 'my-blogs';
|
1998 |
+
|
1999 |
+
if ( bp_is_user_groups() && !bp_is_directory() )
|
2000 |
+
$bp_classes[] = 'my-groups';
|
2001 |
+
|
2002 |
+
if ( bp_is_group_leave() )
|
2003 |
+
$bp_classes[] = 'leave-group';
|
2004 |
+
|
2005 |
+
if ( bp_is_group_invites() )
|
2006 |
+
$bp_classes[] = 'group-invites';
|
2007 |
+
|
2008 |
+
if ( bp_is_group_members() )
|
2009 |
+
$bp_classes[] = 'group-members';
|
2010 |
+
|
2011 |
+
if ( bp_is_group_forum_topic() )
|
2012 |
+
$bp_classes[] = 'group-forum-topic';
|
2013 |
+
|
2014 |
+
if ( bp_is_group_forum_topic_edit() )
|
2015 |
+
$bp_classes[] = 'group-forum-topic-edit';
|
2016 |
+
|
2017 |
+
if ( bp_is_group_forum() )
|
2018 |
+
$bp_classes[] = 'group-forum';
|
2019 |
+
|
2020 |
+
if ( bp_is_group_admin_page() )
|
2021 |
+
$bp_classes[] = 'group-admin';
|
2022 |
+
|
2023 |
+
if ( bp_is_group_create() )
|
2024 |
+
$bp_classes[] = 'group-create';
|
2025 |
+
|
2026 |
+
if ( bp_is_group_home() )
|
2027 |
+
$bp_classes[] = 'group-home';
|
2028 |
+
|
2029 |
+
if ( bp_is_change_avatar() )
|
2030 |
+
$bp_classes[] = 'change-avatar';
|
2031 |
+
|
2032 |
+
if ( bp_is_profile_edit() )
|
2033 |
+
$bp_classes[] = 'profile-edit';
|
2034 |
+
|
2035 |
+
if ( bp_is_user_friends_activity() )
|
2036 |
+
$bp_classes[] = 'friends-activity';
|
2037 |
+
|
2038 |
+
if ( bp_is_user_activity() && !bp_is_directory() )
|
2039 |
+
$bp_classes[] = 'my-activity';
|
2040 |
+
|
2041 |
+
if ( bp_is_activity_permalink() )
|
2042 |
+
$bp_classes[] = 'activity-permalink';
|
2043 |
+
|
2044 |
+
if ( bp_is_register_page() )
|
2045 |
+
$bp_classes[] = 'registration';
|
2046 |
+
|
2047 |
+
if ( bp_is_activation_page() )
|
2048 |
+
$bp_classes[] = 'activation';
|
2049 |
+
|
2050 |
+
if ( is_user_logged_in() )
|
2051 |
+
$bp_classes[] = 'logged-in';
|
2052 |
+
|
2053 |
+
/* Add the current_component, current_action into the bp classes */
|
2054 |
+
if ( !bp_is_blog_page() ) {
|
2055 |
+
if ( !empty( $bp->current_component ) )
|
2056 |
+
$bp_classes[] = $bp->current_component;
|
2057 |
+
|
2058 |
+
if ( !empty( $bp->current_action ) )
|
2059 |
+
$bp_classes[] = $bp->current_action;
|
2060 |
+
}
|
2061 |
+
|
2062 |
+
/* We don't want WordPress blog classes to appear on non-blog pages. */
|
2063 |
+
if ( !bp_is_blog_page() || is_home() ) {
|
2064 |
+
/* Preserve any custom classes already set */
|
2065 |
+
if ( !empty( $custom_classes ) )
|
2066 |
+
$wp_classes = (array) $custom_classes;
|
2067 |
+
else
|
2068 |
+
$wp_classes = array();
|
2069 |
+
}
|
2070 |
+
|
2071 |
+
/* Merge WP classes with BP classes */
|
2072 |
+
$classes = array_merge( (array) $bp_classes, (array) $wp_classes );
|
2073 |
+
|
2074 |
+
/* Remove any duplicates */
|
2075 |
+
$classes = array_unique( $classes );
|
2076 |
+
|
2077 |
+
return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
|
2078 |
+
}
|
2079 |
+
add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 )
|
2080 |
+
|
2081 |
+
|
2082 |
?>
|
bp-core/bp-core-widgets.php
CHANGED
@@ -1,243 +1,255 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/* Register widgets for the core component */
|
4 |
-
function bp_core_register_widgets() {
|
5 |
-
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
|
6 |
-
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
|
7 |
-
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
|
8 |
-
}
|
9 |
-
add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
|
10 |
-
|
11 |
-
/*** MEMBERS WIDGET *****************/
|
12 |
-
|
13 |
-
class BP_Core_Members_Widget extends WP_Widget {
|
14 |
-
function bp_core_members_widget() {
|
15 |
-
parent::WP_Widget( false, $name = __( 'Members', 'buddypress' ) );
|
16 |
-
|
17 |
-
if ( is_active_widget( false, false, $this->id_base ) )
|
18 |
-
wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.js', array('jquery') );
|
19 |
-
}
|
20 |
-
|
21 |
-
function widget($args, $instance) {
|
22 |
-
global $bp;
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
echo $before_widget;
|
27 |
-
echo $before_title
|
28 |
-
. $widget_name
|
29 |
-
. $after_title; ?>
|
30 |
-
|
31 |
-
<?php if ( bp_has_members( 'user_id=0&type=newest&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
|
32 |
-
<div class="item-options" id="members-list-options">
|
33 |
-
<span class="ajax-loader" id="ajax-loader-members"></span>
|
34 |
-
<a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="newest-members" class="selected"><?php _e( 'Newest', 'buddypress' ) ?></a>
|
35 |
-
<a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="recently-active-members"><?php _e( 'Active', 'buddypress' ) ?></a>
|
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 |
-
<?php
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
$instance =
|
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 |
-
<?php
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
$instance =
|
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 |
-
<?php
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
$instance =
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
case '
|
209 |
-
$type = '
|
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 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/* Register widgets for the core component */
|
4 |
+
function bp_core_register_widgets() {
|
5 |
+
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
|
6 |
+
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
|
7 |
+
add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
|
8 |
+
}
|
9 |
+
add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
|
10 |
+
|
11 |
+
/*** MEMBERS WIDGET *****************/
|
12 |
+
|
13 |
+
class BP_Core_Members_Widget extends WP_Widget {
|
14 |
+
function bp_core_members_widget() {
|
15 |
+
parent::WP_Widget( false, $name = __( 'Members', 'buddypress' ) );
|
16 |
+
|
17 |
+
if ( is_active_widget( false, false, $this->id_base ) )
|
18 |
+
wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.js', array('jquery') );
|
19 |
+
}
|
20 |
+
|
21 |
+
function widget($args, $instance) {
|
22 |
+
global $bp;
|
23 |
+
|
24 |
+
extract( $args );
|
25 |
+
|
26 |
+
echo $before_widget;
|
27 |
+
echo $before_title
|
28 |
+
. $widget_name
|
29 |
+
. $after_title; ?>
|
30 |
+
|
31 |
+
<?php if ( bp_has_members( 'user_id=0&type=newest&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
|
32 |
+
<div class="item-options" id="members-list-options">
|
33 |
+
<span class="ajax-loader" id="ajax-loader-members"></span>
|
34 |
+
<a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="newest-members" class="selected"><?php _e( 'Newest', 'buddypress' ) ?></a>
|
35 |
+
| <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="recently-active-members"><?php _e( 'Active', 'buddypress' ) ?></a>
|
36 |
+
|
37 |
+
<?php if ( bp_is_active( 'friends' ) ) : ?>
|
38 |
+
|
39 |
+
| <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
|
40 |
+
|
41 |
+
<?php endif; ?>
|
42 |
+
|
43 |
+
</div>
|
44 |
+
|
45 |
+
<ul id="members-list" class="item-list">
|
46 |
+
<?php while ( bp_members() ) : bp_the_member(); ?>
|
47 |
+
<li class="vcard">
|
48 |
+
<div class="item-avatar">
|
49 |
+
<a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
|
50 |
+
</div>
|
51 |
+
|
52 |
+
<div class="item">
|
53 |
+
<div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
|
54 |
+
<div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
|
55 |
+
</div>
|
56 |
+
</li>
|
57 |
+
|
58 |
+
<?php endwhile; ?>
|
59 |
+
</ul>
|
60 |
+
<?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members' ); ?>
|
61 |
+
<input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo esc_attr( $instance['max_members'] ); ?>" />
|
62 |
+
|
63 |
+
<?php else: ?>
|
64 |
+
|
65 |
+
<div class="widget-error">
|
66 |
+
<?php _e('No one has signed up yet!', 'buddypress') ?>
|
67 |
+
</div>
|
68 |
+
|
69 |
+
<?php endif; ?>
|
70 |
+
|
71 |
+
<?php echo $after_widget; ?>
|
72 |
+
<?php
|
73 |
+
}
|
74 |
+
|
75 |
+
function update( $new_instance, $old_instance ) {
|
76 |
+
$instance = $old_instance;
|
77 |
+
$instance['max_members'] = strip_tags( $new_instance['max_members'] );
|
78 |
+
|
79 |
+
return $instance;
|
80 |
+
}
|
81 |
+
|
82 |
+
function form( $instance ) {
|
83 |
+
$instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
|
84 |
+
$max_members = strip_tags( $instance['max_members'] );
|
85 |
+
?>
|
86 |
+
|
87 |
+
<p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
|
88 |
+
<?php
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
/*** WHO'S ONLINE WIDGET *****************/
|
93 |
+
|
94 |
+
class BP_Core_Whos_Online_Widget extends WP_Widget {
|
95 |
+
function bp_core_whos_online_widget() {
|
96 |
+
parent::WP_Widget( false, $name = __( "Who's Online Avatars", 'buddypress' ) );
|
97 |
+
}
|
98 |
+
|
99 |
+
function widget($args, $instance) {
|
100 |
+
global $bp;
|
101 |
+
|
102 |
+
extract( $args );
|
103 |
+
|
104 |
+
echo $before_widget;
|
105 |
+
echo $before_title
|
106 |
+
. $widget_name
|
107 |
+
. $after_title; ?>
|
108 |
+
|
109 |
+
<?php if ( bp_has_members( 'user_id=0&type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
|
110 |
+
<div class="avatar-block">
|
111 |
+
<?php while ( bp_members() ) : bp_the_member(); ?>
|
112 |
+
<div class="item-avatar">
|
113 |
+
<a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
|
114 |
+
</div>
|
115 |
+
<?php endwhile; ?>
|
116 |
+
</div>
|
117 |
+
<?php else: ?>
|
118 |
+
|
119 |
+
<div class="widget-error">
|
120 |
+
<?php _e( 'There are no users currently online', 'buddypress' ) ?>
|
121 |
+
</div>
|
122 |
+
|
123 |
+
<?php endif; ?>
|
124 |
+
|
125 |
+
<?php echo $after_widget; ?>
|
126 |
+
<?php
|
127 |
+
}
|
128 |
+
|
129 |
+
function update( $new_instance, $old_instance ) {
|
130 |
+
$instance = $old_instance;
|
131 |
+
$instance['max_members'] = strip_tags( $new_instance['max_members'] );
|
132 |
+
|
133 |
+
return $instance;
|
134 |
+
}
|
135 |
+
|
136 |
+
function form( $instance ) {
|
137 |
+
$instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
|
138 |
+
$max_members = strip_tags( $instance['max_members'] );
|
139 |
+
?>
|
140 |
+
|
141 |
+
<p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
|
142 |
+
<?php
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
/*** RECENTLY ACTIVE WIDGET *****************/
|
147 |
+
|
148 |
+
class BP_Core_Recently_Active_Widget extends WP_Widget {
|
149 |
+
function bp_core_recently_active_widget() {
|
150 |
+
parent::WP_Widget( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ) );
|
151 |
+
}
|
152 |
+
|
153 |
+
function widget($args, $instance) {
|
154 |
+
global $bp;
|
155 |
+
|
156 |
+
extract( $args );
|
157 |
+
|
158 |
+
echo $before_widget;
|
159 |
+
echo $before_title
|
160 |
+
. $widget_name
|
161 |
+
. $after_title; ?>
|
162 |
+
|
163 |
+
<?php if ( bp_has_members( 'user_id=0&type=active&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
|
164 |
+
<div class="avatar-block">
|
165 |
+
<?php while ( bp_members() ) : bp_the_member(); ?>
|
166 |
+
<div class="item-avatar">
|
167 |
+
<a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
|
168 |
+
</div>
|
169 |
+
<?php endwhile; ?>
|
170 |
+
</div>
|
171 |
+
<?php else: ?>
|
172 |
+
|
173 |
+
<div class="widget-error">
|
174 |
+
<?php _e( 'There are no recently active members', 'buddypress' ) ?>
|
175 |
+
</div>
|
176 |
+
|
177 |
+
<?php endif; ?>
|
178 |
+
|
179 |
+
<?php echo $after_widget; ?>
|
180 |
+
<?php
|
181 |
+
}
|
182 |
+
|
183 |
+
function update( $new_instance, $old_instance ) {
|
184 |
+
$instance = $old_instance;
|
185 |
+
$instance['max_members'] = strip_tags( $new_instance['max_members'] );
|
186 |
+
|
187 |
+
return $instance;
|
188 |
+
}
|
189 |
+
|
190 |
+
function form( $instance ) {
|
191 |
+
$instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
|
192 |
+
$max_members = strip_tags( $instance['max_members'] );
|
193 |
+
?>
|
194 |
+
|
195 |
+
<p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
|
196 |
+
<?php
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
/** Widget AJAX ******************/
|
201 |
+
|
202 |
+
function bp_core_ajax_widget_members() {
|
203 |
+
global $bp;
|
204 |
+
|
205 |
+
check_ajax_referer( 'bp_core_widget_members' );
|
206 |
+
|
207 |
+
switch ( $_POST['filter'] ) {
|
208 |
+
case 'newest-members':
|
209 |
+
$type = 'newest';
|
210 |
+
break;
|
211 |
+
|
212 |
+
case 'recently-active-members':
|
213 |
+
$type = 'active';
|
214 |
+
break;
|
215 |
+
|
216 |
+
case 'popular-members':
|
217 |
+
if ( bp_is_active( 'friends' ) )
|
218 |
+
$type = 'popular';
|
219 |
+
else
|
220 |
+
$type = 'active';
|
221 |
+
|
222 |
+
break;
|
223 |
+
}
|
224 |
+
|
225 |
+
if ( bp_has_members( 'user_id=0&type=' . $type . '&per_page=' . $_POST['max-members'] . '&max=' . $_POST['max-members'] . '&populate_extras=0' ) ) : ?>
|
226 |
+
<?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this. ?>
|
227 |
+
<div class="avatar-block">
|
228 |
+
<?php while ( bp_members() ) : bp_the_member(); ?>
|
229 |
+
<li class="vcard">
|
230 |
+
<div class="item-avatar">
|
231 |
+
<a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
|
232 |
+
</div>
|
233 |
+
|
234 |
+
<div class="item">
|
235 |
+
<div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
|
236 |
+
<?php if ( 'active' == $type || 'newest' == $type ) : ?>
|
237 |
+
<div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
|
238 |
+
<?php elseif ( bp_is_active( 'friends' ) ) : ?>
|
239 |
+
<div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
|
240 |
+
<?php endif; ?>
|
241 |
+
</div>
|
242 |
+
</li>
|
243 |
+
|
244 |
+
<?php endwhile; ?>
|
245 |
+
</div>
|
246 |
+
|
247 |
+
<?php else: ?>
|
248 |
+
<?php echo "-1[[SPLIT]]<li>"; ?>
|
249 |
+
<?php _e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
|
250 |
+
<?php echo "</li>"; ?>
|
251 |
+
<?php endif;
|
252 |
+
}
|
253 |
+
add_action( 'wp_ajax_widget_members', 'bp_core_ajax_widget_members' );
|
254 |
+
|
255 |
?>
|
bp-core/bp-core-wpabstraction.php
CHANGED
@@ -24,6 +24,29 @@ function bp_core_is_multisite() {
|
|
24 |
return true;
|
25 |
}
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
function bp_core_get_status_sql( $prefix = false ) {
|
28 |
if ( !bp_core_is_multisite() )
|
29 |
return "{$prefix}user_status = 0";
|
@@ -67,23 +90,6 @@ if ( !function_exists( 'get_blogs_of_user' ) ) {
|
|
67 |
}
|
68 |
}
|
69 |
|
70 |
-
if ( !function_exists( 'is_site_admin' ) ) {
|
71 |
-
function is_site_admin( $user_id = false ) {
|
72 |
-
if ( current_user_can( 'manage_options' ) )
|
73 |
-
return true;
|
74 |
-
|
75 |
-
return false;
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
if ( !function_exists( 'get_current_user_id' ) ) {
|
80 |
-
function get_current_user_id() {
|
81 |
-
global $current_user;
|
82 |
-
get_currentuserinfo();
|
83 |
-
return $current_user->data->ID;
|
84 |
-
}
|
85 |
-
}
|
86 |
-
|
87 |
if ( !function_exists( 'update_blog_status' ) ) {
|
88 |
function update_blog_status() {
|
89 |
return true;
|
@@ -97,4 +103,13 @@ if ( !function_exists( 'is_subdomain_install' ) ) {
|
|
97 |
|
98 |
return false;
|
99 |
}
|
100 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return true;
|
25 |
}
|
26 |
|
27 |
+
/**
|
28 |
+
* bp_core_is_main_site
|
29 |
+
*
|
30 |
+
* Checks if current blog is root blog of site
|
31 |
+
*
|
32 |
+
* @since 1.2.6
|
33 |
+
* @package BuddyPress
|
34 |
+
*
|
35 |
+
* @param int $blog_id optional blog id to test (default current blog)
|
36 |
+
* @return bool True if not multisite or $blog_id is main site
|
37 |
+
*/
|
38 |
+
function bp_core_is_main_site( $blog_id = '' ) {
|
39 |
+
global $current_site, $current_blog;
|
40 |
+
|
41 |
+
if ( !bp_core_is_multisite() )
|
42 |
+
return true;
|
43 |
+
|
44 |
+
if ( empty( $blog_id ) )
|
45 |
+
$blog_id = $current_blog->blog_id;
|
46 |
+
|
47 |
+
return $blog_id == $current_site->blog_id;
|
48 |
+
}
|
49 |
+
|
50 |
function bp_core_get_status_sql( $prefix = false ) {
|
51 |
if ( !bp_core_is_multisite() )
|
52 |
return "{$prefix}user_status = 0";
|
90 |
}
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
if ( !function_exists( 'update_blog_status' ) ) {
|
94 |
function update_blog_status() {
|
95 |
return true;
|
103 |
|
104 |
return false;
|
105 |
}
|
106 |
+
}
|
107 |
+
|
108 |
+
// Deprecated - 1.2.6
|
109 |
+
if ( !function_exists( 'is_site_admin' ) ) {
|
110 |
+
function is_site_admin( $user_id = false ) {
|
111 |
+
return is_super_admin( $user_id );
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
?>
|
bp-forums.php
CHANGED
@@ -1,556 +1,556 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/* Define the parent forum ID */
|
4 |
-
if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
|
5 |
-
define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
|
6 |
-
|
7 |
-
if ( !defined( 'BP_FORUMS_SLUG' ) )
|
8 |
-
define( 'BP_FORUMS_SLUG', 'forums' );
|
9 |
-
|
10 |
-
if ( !defined( 'BB_PATH' ) )
|
11 |
-
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' );
|
12 |
-
|
13 |
-
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-templatetags.php' );
|
14 |
-
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-filters.php' );
|
15 |
-
|
16 |
-
function bp_forums_setup() {
|
17 |
-
global $bp;
|
18 |
-
|
19 |
-
/* For internal identification */
|
20 |
-
$bp->forums->id = 'forums';
|
21 |
-
|
22 |
-
$bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
|
23 |
-
$bp->forums->bbconfig = $bp->site_options['bb-config-location'];
|
24 |
-
$bp->forums->slug = BP_FORUMS_SLUG;
|
25 |
-
|
26 |
-
/* Register this in the active components array */
|
27 |
-
$bp->active_components[$bp->forums->slug] = $bp->forums->id;
|
28 |
-
|
29 |
-
do_action( 'bp_forums_setup' );
|
30 |
-
}
|
31 |
-
add_action( 'bp_setup_globals', 'bp_forums_setup' );
|
32 |
-
|
33 |
-
function bp_forums_is_installed_correctly() {
|
34 |
-
global $bp;
|
35 |
-
|
36 |
-
if ( file_exists( $bp->forums->bbconfig ) )
|
37 |
-
return true;
|
38 |
-
|
39 |
-
return false;
|
40 |
-
}
|
41 |
-
|
42 |
-
function bp_forums_setup_root_component() {
|
43 |
-
/* Register 'forums' as a root component */
|
44 |
-
bp_core_add_root_component( BP_FORUMS_SLUG );
|
45 |
-
}
|
46 |
-
add_action( 'bp_setup_root_components', 'bp_forums_setup_root_component' );
|
47 |
-
|
48 |
-
function bp_forums_directory_forums_setup() {
|
49 |
-
global $bp;
|
50 |
-
|
51 |
-
if ( $bp->current_component == $bp->forums->slug ) {
|
52 |
-
if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
|
53 |
-
return false;
|
54 |
-
|
55 |
-
if ( !bp_forums_is_installed_correctly() ) {
|
56 |
-
bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
|
57 |
-
bp_core_redirect( $bp->root_domain );
|
58 |
-
}
|
59 |
-
|
60 |
-
$bp->is_directory = true;
|
61 |
-
|
62 |
-
do_action( 'bbpress_init' );
|
63 |
-
|
64 |
-
/* Check to see if the user has posted a new topic from the forums page. */
|
65 |
-
if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
|
66 |
-
/* Check the nonce */
|
67 |
-
check_admin_referer( 'bp_forums_new_topic' );
|
68 |
-
|
69 |
-
if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
|
70 |
-
/* Auto join this user if they are not yet a member of this group */
|
71 |
-
if ( !
|
72 |
-
groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
|
73 |
-
|
74 |
-
if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
|
75 |
-
if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
|
76 |
-
bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
|
77 |
-
else
|
78 |
-
bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
|
79 |
-
|
80 |
-
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
|
81 |
-
} else {
|
82 |
-
bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
|
83 |
-
}
|
84 |
-
}
|
85 |
-
}
|
86 |
-
|
87 |
-
do_action( 'bp_forums_directory_forums_setup' );
|
88 |
-
|
89 |
-
bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
|
90 |
-
}
|
91 |
-
}
|
92 |
-
add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
|
93 |
-
|
94 |
-
function bp_forums_add_admin_menu() {
|
95 |
-
global $bp;
|
96 |
-
|
97 |
-
if ( !
|
98 |
-
return false;
|
99 |
-
|
100 |
-
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
|
101 |
-
|
102 |
-
/* Add the administration tab under the "Site Admin" tab for site administrators */
|
103 |
-
add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
|
104 |
-
}
|
105 |
-
add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
|
106 |
-
|
107 |
-
/* Forum Functions */
|
108 |
-
|
109 |
-
function bp_forums_get_forum( $forum_id ) {
|
110 |
-
do_action( 'bbpress_init' );
|
111 |
-
return bb_get_forum( $forum_id );
|
112 |
-
}
|
113 |
-
|
114 |
-
function bp_forums_new_forum( $args = '' ) {
|
115 |
-
do_action( 'bbpress_init' );
|
116 |
-
|
117 |
-
$defaults = array(
|
118 |
-
'forum_name' => '',
|
119 |
-
'forum_desc' => '',
|
120 |
-
'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
|
121 |
-
'forum_order' => false,
|
122 |
-
'forum_is_category' => 0
|
123 |
-
);
|
124 |
-
|
125 |
-
$r = wp_parse_args( $args, $defaults );
|
126 |
-
extract( $r, EXTR_SKIP );
|
127 |
-
|
128 |
-
return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
|
129 |
-
}
|
130 |
-
|
131 |
-
function bp_forums_update_forum( $args = '' ) {
|
132 |
-
do_action( 'bbpress_init' );
|
133 |
-
|
134 |
-
$defaults = array(
|
135 |
-
'forum_id' => '',
|
136 |
-
'forum_name' => '',
|
137 |
-
'forum_desc' => '',
|
138 |
-
'forum_slug' => '',
|
139 |
-
'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
|
140 |
-
'forum_order' => false,
|
141 |
-
'forum_is_category' => 0
|
142 |
-
);
|
143 |
-
|
144 |
-
$r = wp_parse_args( $args, $defaults );
|
145 |
-
extract( $r, EXTR_SKIP );
|
146 |
-
|
147 |
-
return bb_update_forum( array( 'forum_id' => (int)$forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
|
148 |
-
}
|
149 |
-
|
150 |
-
/* Topic Functions */
|
151 |
-
|
152 |
-
function bp_forums_get_forum_topics( $args = '' ) {
|
153 |
-
global $bp;
|
154 |
-
|
155 |
-
do_action( 'bbpress_init' );
|
156 |
-
|
157 |
-
$defaults = array(
|
158 |
-
'type' => 'newest',
|
159 |
-
'forum_id' => false,
|
160 |
-
'user_id' => false,
|
161 |
-
'page' => 1,
|
162 |
-
'per_page' => 15,
|
163 |
-
'exclude' => false,
|
164 |
-
'show_stickies' => 'all',
|
165 |
-
'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
|
166 |
-
);
|
167 |
-
|
168 |
-
$r = wp_parse_args( $args, $defaults );
|
169 |
-
extract( $r, EXTR_SKIP );
|
170 |
-
|
171 |
-
switch ( $type ) {
|
172 |
-
case 'newest':
|
173 |
-
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
|
174 |
-
$topics =& $query->results;
|
175 |
-
break;
|
176 |
-
|
177 |
-
case 'popular':
|
178 |
-
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
|
179 |
-
$topics =& $query->results;
|
180 |
-
break;
|
181 |
-
|
182 |
-
case 'unreplied':
|
183 |
-
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
|
184 |
-
$topics =& $query->results;
|
185 |
-
break;
|
186 |
-
|
187 |
-
case 'tags':
|
188 |
-
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
|
189 |
-
$topics =& $query->results;
|
190 |
-
break;
|
191 |
-
}
|
192 |
-
|
193 |
-
return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
|
194 |
-
}
|
195 |
-
|
196 |
-
function bp_forums_get_topic_details( $topic_id ) {
|
197 |
-
do_action( 'bbpress_init' );
|
198 |
-
|
199 |
-
$query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
|
200 |
-
|
201 |
-
return $query->results[0];
|
202 |
-
}
|
203 |
-
|
204 |
-
function bp_forums_get_topic_id_from_slug( $topic_slug ) {
|
205 |
-
do_action( 'bbpress_init' );
|
206 |
-
return bb_get_id_from_slug( 'topic', $topic_slug );
|
207 |
-
}
|
208 |
-
|
209 |
-
function bp_forums_new_topic( $args = '' ) {
|
210 |
-
global $bp;
|
211 |
-
|
212 |
-
do_action( 'bbpress_init' );
|
213 |
-
|
214 |
-
$defaults = array(
|
215 |
-
'topic_title' => '',
|
216 |
-
'topic_slug' => '',
|
217 |
-
'topic_text' => '',
|
218 |
-
'topic_poster' => $bp->loggedin_user->id, // accepts ids
|
219 |
-
'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
|
220 |
-
'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
|
221 |
-
'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
|
222 |
-
'topic_start_time' => date( 'Y-m-d H:i:s' ),
|
223 |
-
'topic_time' => date( 'Y-m-d H:i:s' ),
|
224 |
-
'topic_open' => 1,
|
225 |
-
'topic_tags' => false, // accepts array or comma delim
|
226 |
-
'forum_id' => 0 // accepts ids or slugs
|
227 |
-
);
|
228 |
-
|
229 |
-
$r = wp_parse_args( $args, $defaults );
|
230 |
-
extract( $r, EXTR_SKIP );
|
231 |
-
|
232 |
-
$topic_title = strip_tags( $topic_title );
|
233 |
-
|
234 |
-
if ( empty( $topic_title ) || !strlen( trim( $topic_title ) ) )
|
235 |
-
return false;
|
236 |
-
|
237 |
-
if ( empty( $topic_slug ) )
|
238 |
-
$topic_slug = sanitize_title( $topic_title );
|
239 |
-
|
240 |
-
if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id, 'tags' => $topic_tags ) ) )
|
241 |
-
return false;
|
242 |
-
|
243 |
-
/* Now insert the first post. */
|
244 |
-
if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
|
245 |
-
return false;
|
246 |
-
|
247 |
-
do_action( 'bp_forums_new_topic', $topic_id );
|
248 |
-
|
249 |
-
return $topic_id;
|
250 |
-
}
|
251 |
-
|
252 |
-
function bp_forums_update_topic( $args = '' ) {
|
253 |
-
global $bp;
|
254 |
-
|
255 |
-
do_action( 'bbpress_init' );
|
256 |
-
|
257 |
-
$defaults = array(
|
258 |
-
'topic_id' => false,
|
259 |
-
'topic_title' => '',
|
260 |
-
'topic_text' => ''
|
261 |
-
);
|
262 |
-
|
263 |
-
$r = wp_parse_args( $args, $defaults );
|
264 |
-
extract( $r, EXTR_SKIP );
|
265 |
-
|
266 |
-
if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
|
267 |
-
return false;
|
268 |
-
|
269 |
-
if ( !$post = bb_get_first_post( $topic_id ) )
|
270 |
-
return false;
|
271 |
-
|
272 |
-
/* Update the first post */
|
273 |
-
if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) )
|
274 |
-
return false;
|
275 |
-
|
276 |
-
return bp_forums_get_topic_details( $topic_id );
|
277 |
-
}
|
278 |
-
|
279 |
-
function bp_forums_sticky_topic( $args = '' ) {
|
280 |
-
global $bp;
|
281 |
-
|
282 |
-
do_action( 'bbpress_init' );
|
283 |
-
|
284 |
-
$defaults = array(
|
285 |
-
'topic_id' => false,
|
286 |
-
'mode' => 'stick' // stick/unstick
|
287 |
-
);
|
288 |
-
|
289 |
-
$r = wp_parse_args( $args, $defaults );
|
290 |
-
extract( $r, EXTR_SKIP );
|
291 |
-
|
292 |
-
if ( 'stick' == $mode )
|
293 |
-
return bb_stick_topic( $topic_id );
|
294 |
-
else if ( 'unstick' == $mode )
|
295 |
-
return bb_unstick_topic( $topic_id );
|
296 |
-
|
297 |
-
return false;
|
298 |
-
}
|
299 |
-
|
300 |
-
function bp_forums_openclose_topic( $args = '' ) {
|
301 |
-
global $bp;
|
302 |
-
|
303 |
-
do_action( 'bbpress_init' );
|
304 |
-
|
305 |
-
$defaults = array(
|
306 |
-
'topic_id' => false,
|
307 |
-
'mode' => 'close' // stick/unstick
|
308 |
-
);
|
309 |
-
|
310 |
-
$r = wp_parse_args( $args, $defaults );
|
311 |
-
extract( $r, EXTR_SKIP );
|
312 |
-
|
313 |
-
if ( 'close' == $mode )
|
314 |
-
return bb_close_topic( $topic_id );
|
315 |
-
else if ( 'open' == $mode )
|
316 |
-
return bb_open_topic( $topic_id );
|
317 |
-
|
318 |
-
return false;
|
319 |
-
}
|
320 |
-
|
321 |
-
function bp_forums_delete_topic( $args = '' ) {
|
322 |
-
global $bp;
|
323 |
-
|
324 |
-
do_action( 'bbpress_init' );
|
325 |
-
|
326 |
-
$defaults = array(
|
327 |
-
'topic_id' => false
|
328 |
-
);
|
329 |
-
|
330 |
-
$r = wp_parse_args( $args, $defaults );
|
331 |
-
extract( $r, EXTR_SKIP );
|
332 |
-
|
333 |
-
return bb_delete_topic( $topic_id, 1 );
|
334 |
-
}
|
335 |
-
|
336 |
-
function bp_forums_total_topic_count() {
|
337 |
-
do_action( 'bbpress_init' );
|
338 |
-
|
339 |
-
$query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => -1, 'count' => true ) );
|
340 |
-
$count = $query->count;
|
341 |
-
$query = null;
|
342 |
-
|
343 |
-
return $count;
|
344 |
-
}
|
345 |
-
|
346 |
-
function bp_forums_total_topic_count_for_user( $user_id = false ) {
|
347 |
-
global $bp;
|
348 |
-
|
349 |
-
do_action( 'bbpress_init' );
|
350 |
-
|
351 |
-
if ( !$user_id )
|
352 |
-
$user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
|
353 |
-
|
354 |
-
$query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
|
355 |
-
$count = $query->count;
|
356 |
-
$query = null;
|
357 |
-
|
358 |
-
return $count;
|
359 |
-
}
|
360 |
-
|
361 |
-
function bp_forums_get_topic_extras( $topics ) {
|
362 |
-
global $bp, $wpdb, $bbdb;
|
363 |
-
|
364 |
-
if ( empty( $topics ) )
|
365 |
-
return $topics;
|
366 |
-
|
367 |
-
/* Get the topic ids */
|
368 |
-
foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
|
369 |
-
$topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
|
370 |
-
|
371 |
-
/* Fetch the topic's last poster details */
|
372 |
-
$poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
|
373 |
-
for ( $i = 0; $i < count( $topics ); $i++ ) {
|
374 |
-
foreach ( (array)$poster_details as $poster ) {
|
375 |
-
if ( $poster->topic_id == $topics[$i]->topic_id ) {
|
376 |
-
$topics[$i]->topic_last_poster_email = $poster->user_email;
|
377 |
-
$topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
|
378 |
-
$topics[$i]->topic_last_poster_login = $poster->user_login;
|
379 |
-
$topics[$i]->topic_last_poster_displayname = $poster->display_name;
|
380 |
-
}
|
381 |
-
}
|
382 |
-
}
|
383 |
-
|
384 |
-
/* Fetch fullname for the topic's last poster */
|
385 |
-
if ( function_exists( 'xprofile_install' ) ) {
|
386 |
-
$poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
|
387 |
-
for ( $i = 0; $i < count( $topics ); $i++ ) {
|
388 |
-
foreach ( (array)$poster_names as $name ) {
|
389 |
-
if ( $name->topic_id == $topics[$i]->topic_id )
|
390 |
-
$topics[$i]->topic_last_poster_displayname = $name->value;
|
391 |
-
}
|
392 |
-
}
|
393 |
-
}
|
394 |
-
|
395 |
-
return $topics;
|
396 |
-
}
|
397 |
-
|
398 |
-
/* Post Functions */
|
399 |
-
|
400 |
-
function bp_forums_get_topic_posts( $args = '' ) {
|
401 |
-
do_action( 'bbpress_init' );
|
402 |
-
|
403 |
-
$defaults = array(
|
404 |
-
'topic_id' => false,
|
405 |
-
'page' => 1,
|
406 |
-
'per_page' => 15,
|
407 |
-
'order' => 'ASC'
|
408 |
-
);
|
409 |
-
|
410 |
-
$args = wp_parse_args( $args, $defaults );
|
411 |
-
|
412 |
-
$query = new BB_Query( 'post', $args, 'get_thread' );
|
413 |
-
return bp_forums_get_post_extras( $query->results );
|
414 |
-
}
|
415 |
-
|
416 |
-
function bp_forums_get_post( $post_id ) {
|
417 |
-
do_action( 'bbpress_init' );
|
418 |
-
return bb_get_post( $post_id );
|
419 |
-
}
|
420 |
-
|
421 |
-
function bp_forums_delete_post( $args = '' ) {
|
422 |
-
global $bp;
|
423 |
-
|
424 |
-
do_action( 'bbpress_init' );
|
425 |
-
|
426 |
-
$defaults = array(
|
427 |
-
'post_id' => false
|
428 |
-
);
|
429 |
-
|
430 |
-
$r = wp_parse_args( $args, $defaults );
|
431 |
-
extract( $r, EXTR_SKIP );
|
432 |
-
|
433 |
-
return bb_delete_post( $post_id, 1 );
|
434 |
-
}
|
435 |
-
|
436 |
-
function bp_forums_insert_post( $args = '' ) {
|
437 |
-
global $bp;
|
438 |
-
|
439 |
-
do_action( 'bbpress_init' );
|
440 |
-
|
441 |
-
$defaults = array(
|
442 |
-
'post_id' => false,
|
443 |
-
'topic_id' => false,
|
444 |
-
'post_text' => '',
|
445 |
-
'post_time' => date( 'Y-m-d H:i:s' ),
|
446 |
-
'poster_id' => $bp->loggedin_user->id, // accepts ids or names
|
447 |
-
'poster_ip' => $_SERVER['REMOTE_ADDR'],
|
448 |
-
'post_status' => 0, // use bb_delete_post() instead
|
449 |
-
'post_position' => false
|
450 |
-
);
|
451 |
-
|
452 |
-
$r = wp_parse_args( $args, $defaults );
|
453 |
-
extract( $r, EXTR_SKIP );
|
454 |
-
|
455 |
-
if ( !$post = bp_forums_get_post( $post_id ) )
|
456 |
-
$post_id = false;
|
457 |
-
|
458 |
-
if ( !isset( $topic_id ) )
|
459 |
-
$topic_id = $post->topic_id;
|
460 |
-
|
461 |
-
if ( empty( $post_text ) )
|
462 |
-
$post_text = $post->post_text;
|
463 |
-
|
464 |
-
if ( !isset( $post_time ) )
|
465 |
-
$post_time = $post->post_time;
|
466 |
-
|
467 |
-
if ( !isset( $post_position ) )
|
468 |
-
$post_position = $post->post_position;
|
469 |
-
|
470 |
-
$post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
|
471 |
-
|
472 |
-
if ( $post_id )
|
473 |
-
do_action( 'bp_forums_new_post', $post_id );
|
474 |
-
|
475 |
-
return $post_id;
|
476 |
-
}
|
477 |
-
|
478 |
-
function bp_forums_get_post_extras( $posts ) {
|
479 |
-
global $bp, $wpdb;
|
480 |
-
|
481 |
-
if ( empty( $posts ) )
|
482 |
-
return $posts;
|
483 |
-
|
484 |
-
/* Get the user ids */
|
485 |
-
foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
|
486 |
-
$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
|
487 |
-
|
488 |
-
/* Fetch the poster's user_email, user_nicename and user_login */
|
489 |
-
$poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
|
490 |
-
|
491 |
-
for ( $i = 0; $i < count( $posts ); $i++ ) {
|
492 |
-
foreach ( (array)$poster_details as $poster ) {
|
493 |
-
if ( $poster->user_id == $posts[$i]->poster_id ) {
|
494 |
-
$posts[$i]->poster_email = $poster->user_email;
|
495 |
-
$posts[$i]->poster_login = $poster->user_nicename;
|
496 |
-
$posts[$i]->poster_nicename = $poster->user_login;
|
497 |
-
$posts[$i]->poster_name = $poster->display_name;
|
498 |
-
}
|
499 |
-
}
|
500 |
-
}
|
501 |
-
|
502 |
-
/* Fetch fullname for each poster. */
|
503 |
-
if ( function_exists( 'xprofile_install' ) ) {
|
504 |
-
$poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
|
505 |
-
for ( $i = 0; $i < count( $posts ); $i++ ) {
|
506 |
-
foreach ( (array)$poster_names as $name ) {
|
507 |
-
if ( $name->user_id == $topics[$i]->user_id )
|
508 |
-
$posts[$i]->poster_name = $poster->value;
|
509 |
-
}
|
510 |
-
}
|
511 |
-
}
|
512 |
-
|
513 |
-
return $posts;
|
514 |
-
}
|
515 |
-
|
516 |
-
|
517 |
-
function bp_forums_get_forum_topicpost_count( $forum_id ) {
|
518 |
-
global $wpdb, $bbdb;
|
519 |
-
|
520 |
-
do_action( 'bbpress_init' );
|
521 |
-
|
522 |
-
/* Need to find a bbPress function that does this */
|
523 |
-
return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
|
524 |
-
}
|
525 |
-
|
526 |
-
|
527 |
-
function bp_forums_filter_caps( $allcaps ) {
|
528 |
-
global $bp, $wp_roles, $bb_table_prefix;
|
529 |
-
|
530 |
-
$bb_cap =
|
531 |
-
|
532 |
-
if ( empty( $bb_cap ) )
|
533 |
-
return $allcaps;
|
534 |
-
|
535 |
-
$bb_cap = array_keys($bb_cap);
|
536 |
-
$bb_cap = $wp_roles->get_role( $bb_cap[0] );
|
537 |
-
$bb_cap = $bb_cap->capabilities;
|
538 |
-
|
539 |
-
return array_merge( (array) $allcaps, (array) $bb_cap );
|
540 |
-
}
|
541 |
-
add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
|
542 |
-
|
543 |
-
|
544 |
-
/********************************************************************************
|
545 |
-
* Caching
|
546 |
-
*
|
547 |
-
* Caching functions handle the clearing of cached objects and pages on specific
|
548 |
-
* actions throughout BuddyPress.
|
549 |
-
*/
|
550 |
-
|
551 |
-
// List actions to clear super cached pages on, if super cache is installed
|
552 |
-
add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
|
553 |
-
add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
|
554 |
-
add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
|
555 |
-
|
556 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/* Define the parent forum ID */
|
4 |
+
if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
|
5 |
+
define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
|
6 |
+
|
7 |
+
if ( !defined( 'BP_FORUMS_SLUG' ) )
|
8 |
+
define( 'BP_FORUMS_SLUG', 'forums' );
|
9 |
+
|
10 |
+
if ( !defined( 'BB_PATH' ) )
|
11 |
+
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' );
|
12 |
+
|
13 |
+
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-templatetags.php' );
|
14 |
+
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-filters.php' );
|
15 |
+
|
16 |
+
function bp_forums_setup() {
|
17 |
+
global $bp;
|
18 |
+
|
19 |
+
/* For internal identification */
|
20 |
+
$bp->forums->id = 'forums';
|
21 |
+
|
22 |
+
$bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
|
23 |
+
$bp->forums->bbconfig = $bp->site_options['bb-config-location'];
|
24 |
+
$bp->forums->slug = BP_FORUMS_SLUG;
|
25 |
+
|
26 |
+
/* Register this in the active components array */
|
27 |
+
$bp->active_components[$bp->forums->slug] = $bp->forums->id;
|
28 |
+
|
29 |
+
do_action( 'bp_forums_setup' );
|
30 |
+
}
|
31 |
+
add_action( 'bp_setup_globals', 'bp_forums_setup' );
|
32 |
+
|
33 |
+
function bp_forums_is_installed_correctly() {
|
34 |
+
global $bp;
|
35 |
+
|
36 |
+
if ( file_exists( $bp->forums->bbconfig ) )
|
37 |
+
return true;
|
38 |
+
|
39 |
+
return false;
|
40 |
+
}
|
41 |
+
|
42 |
+
function bp_forums_setup_root_component() {
|
43 |
+
/* Register 'forums' as a root component */
|
44 |
+
bp_core_add_root_component( BP_FORUMS_SLUG );
|
45 |
+
}
|
46 |
+
add_action( 'bp_setup_root_components', 'bp_forums_setup_root_component' );
|
47 |
+
|
48 |
+
function bp_forums_directory_forums_setup() {
|
49 |
+
global $bp;
|
50 |
+
|
51 |
+
if ( $bp->current_component == $bp->forums->slug ) {
|
52 |
+
if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
|
53 |
+
return false;
|
54 |
+
|
55 |
+
if ( !bp_forums_is_installed_correctly() ) {
|
56 |
+
bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
|
57 |
+
bp_core_redirect( $bp->root_domain );
|
58 |
+
}
|
59 |
+
|
60 |
+
$bp->is_directory = true;
|
61 |
+
|
62 |
+
do_action( 'bbpress_init' );
|
63 |
+
|
64 |
+
/* Check to see if the user has posted a new topic from the forums page. */
|
65 |
+
if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
|
66 |
+
/* Check the nonce */
|
67 |
+
check_admin_referer( 'bp_forums_new_topic' );
|
68 |
+
|
69 |
+
if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
|
70 |
+
/* Auto join this user if they are not yet a member of this group */
|
71 |
+
if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
|
72 |
+
groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
|
73 |
+
|
74 |
+
if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
|
75 |
+
if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
|
76 |
+
bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
|
77 |
+
else
|
78 |
+
bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
|
79 |
+
|
80 |
+
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
|
81 |
+
} else {
|
82 |
+
bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
|
83 |
+
}
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
do_action( 'bp_forums_directory_forums_setup' );
|
88 |
+
|
89 |
+
bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
|
90 |
+
}
|
91 |
+
}
|
92 |
+
add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
|
93 |
+
|
94 |
+
function bp_forums_add_admin_menu() {
|
95 |
+
global $bp;
|
96 |
+
|
97 |
+
if ( !is_super_admin() )
|
98 |
+
return false;
|
99 |
+
|
100 |
+
require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
|
101 |
+
|
102 |
+
/* Add the administration tab under the "Site Admin" tab for site administrators */
|
103 |
+
add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
|
104 |
+
}
|
105 |
+
add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
|
106 |
+
|
107 |
+
/* Forum Functions */
|
108 |
+
|
109 |
+
function bp_forums_get_forum( $forum_id ) {
|
110 |
+
do_action( 'bbpress_init' );
|
111 |
+
return bb_get_forum( $forum_id );
|
112 |
+
}
|
113 |
+
|
114 |
+
function bp_forums_new_forum( $args = '' ) {
|
115 |
+
do_action( 'bbpress_init' );
|
116 |
+
|
117 |
+
$defaults = array(
|
118 |
+
'forum_name' => '',
|
119 |
+
'forum_desc' => '',
|
120 |
+
'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
|
121 |
+
'forum_order' => false,
|
122 |
+
'forum_is_category' => 0
|
123 |
+
);
|
124 |
+
|
125 |
+
$r = wp_parse_args( $args, $defaults );
|
126 |
+
extract( $r, EXTR_SKIP );
|
127 |
+
|
128 |
+
return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
|
129 |
+
}
|
130 |
+
|
131 |
+
function bp_forums_update_forum( $args = '' ) {
|
132 |
+
do_action( 'bbpress_init' );
|
133 |
+
|
134 |
+
$defaults = array(
|
135 |
+
'forum_id' => '',
|
136 |
+
'forum_name' => '',
|
137 |
+
'forum_desc' => '',
|
138 |
+
'forum_slug' => '',
|
139 |
+
'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
|
140 |
+
'forum_order' => false,
|
141 |
+
'forum_is_category' => 0
|
142 |
+
);
|
143 |
+
|
144 |
+
$r = wp_parse_args( $args, $defaults );
|
145 |
+
extract( $r, EXTR_SKIP );
|
146 |
+
|
147 |
+
return bb_update_forum( array( 'forum_id' => (int)$forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
|
148 |
+
}
|
149 |
+
|
150 |
+
/* Topic Functions */
|
151 |
+
|
152 |
+
function bp_forums_get_forum_topics( $args = '' ) {
|
153 |
+
global $bp;
|
154 |
+
|
155 |
+
do_action( 'bbpress_init' );
|
156 |
+
|
157 |
+
$defaults = array(
|
158 |
+
'type' => 'newest',
|
159 |
+
'forum_id' => false,
|
160 |
+
'user_id' => false,
|
161 |
+
'page' => 1,
|
162 |
+
'per_page' => 15,
|
163 |
+
'exclude' => false,
|
164 |
+
'show_stickies' => 'all',
|
165 |
+
'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
|
166 |
+
);
|
167 |
+
|
168 |
+
$r = wp_parse_args( $args, $defaults );
|
169 |
+
extract( $r, EXTR_SKIP );
|
170 |
+
|
171 |
+
switch ( $type ) {
|
172 |
+
case 'newest':
|
173 |
+
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
|
174 |
+
$topics =& $query->results;
|
175 |
+
break;
|
176 |
+
|
177 |
+
case 'popular':
|
178 |
+
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
|
179 |
+
$topics =& $query->results;
|
180 |
+
break;
|
181 |
+
|
182 |
+
case 'unreplied':
|
183 |
+
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
|
184 |
+
$topics =& $query->results;
|
185 |
+
break;
|
186 |
+
|
187 |
+
case 'tags':
|
188 |
+
$query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
|
189 |
+
$topics =& $query->results;
|
190 |
+
break;
|
191 |
+
}
|
192 |
+
|
193 |
+
return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
|
194 |
+
}
|
195 |
+
|
196 |
+
function bp_forums_get_topic_details( $topic_id ) {
|
197 |
+
do_action( 'bbpress_init' );
|
198 |
+
|
199 |
+
$query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
|
200 |
+
|
201 |
+
return $query->results[0];
|
202 |
+
}
|
203 |
+
|
204 |
+
function bp_forums_get_topic_id_from_slug( $topic_slug ) {
|
205 |
+
do_action( 'bbpress_init' );
|
206 |
+
return bb_get_id_from_slug( 'topic', $topic_slug );
|
207 |
+
}
|
208 |
+
|
209 |
+
function bp_forums_new_topic( $args = '' ) {
|
210 |
+
global $bp;
|
211 |
+
|
212 |
+
do_action( 'bbpress_init' );
|
213 |
+
|
214 |
+
$defaults = array(
|
215 |
+
'topic_title' => '',
|
216 |
+
'topic_slug' => '',
|
217 |
+
'topic_text' => '',
|
218 |
+
'topic_poster' => $bp->loggedin_user->id, // accepts ids
|
219 |
+
'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
|
220 |
+
'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
|
221 |
+
'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
|
222 |
+
'topic_start_time' => date( 'Y-m-d H:i:s' ),
|
223 |
+
'topic_time' => date( 'Y-m-d H:i:s' ),
|
224 |
+
'topic_open' => 1,
|
225 |
+
'topic_tags' => false, // accepts array or comma delim
|
226 |
+
'forum_id' => 0 // accepts ids or slugs
|
227 |
+
);
|
228 |
+
|
229 |
+
$r = wp_parse_args( $args, $defaults );
|
230 |
+
extract( $r, EXTR_SKIP );
|
231 |
+
|
232 |
+
$topic_title = strip_tags( $topic_title );
|
233 |
+
|
234 |
+
if ( empty( $topic_title ) || !strlen( trim( $topic_title ) ) )
|
235 |
+
return false;
|
236 |
+
|
237 |
+
if ( empty( $topic_slug ) )
|
238 |
+
$topic_slug = sanitize_title( $topic_title );
|
239 |
+
|
240 |
+
if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id, 'tags' => $topic_tags ) ) )
|
241 |
+
return false;
|
242 |
+
|
243 |
+
/* Now insert the first post. */
|
244 |
+
if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
|
245 |
+
return false;
|
246 |
+
|
247 |
+
do_action( 'bp_forums_new_topic', $topic_id );
|
248 |
+
|
249 |
+
return $topic_id;
|
250 |
+
}
|
251 |
+
|
252 |
+
function bp_forums_update_topic( $args = '' ) {
|
253 |
+
global $bp;
|
254 |
+
|
255 |
+
do_action( 'bbpress_init' );
|
256 |
+
|
257 |
+
$defaults = array(
|
258 |
+
'topic_id' => false,
|
259 |
+
'topic_title' => '',
|
260 |
+
'topic_text' => ''
|
261 |
+
);
|
262 |
+
|
263 |
+
$r = wp_parse_args( $args, $defaults );
|
264 |
+
extract( $r, EXTR_SKIP );
|
265 |
+
|
266 |
+
if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
|
267 |
+
return false;
|
268 |
+
|
269 |
+
if ( !$post = bb_get_first_post( $topic_id ) )
|
270 |
+
return false;
|
271 |
+
|
272 |
+
/* Update the first post */
|
273 |
+
if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) )
|
274 |
+
return false;
|
275 |
+
|
276 |
+
return bp_forums_get_topic_details( $topic_id );
|
277 |
+
}
|
278 |
+
|
279 |
+
function bp_forums_sticky_topic( $args = '' ) {
|
280 |
+
global $bp;
|
281 |
+
|
282 |
+
do_action( 'bbpress_init' );
|
283 |
+
|
284 |
+
$defaults = array(
|
285 |
+
'topic_id' => false,
|
286 |
+
'mode' => 'stick' // stick/unstick
|
287 |
+
);
|
288 |
+
|
289 |
+
$r = wp_parse_args( $args, $defaults );
|
290 |
+
extract( $r, EXTR_SKIP );
|
291 |
+
|
292 |
+
if ( 'stick' == $mode )
|
293 |
+
return bb_stick_topic( $topic_id );
|
294 |
+
else if ( 'unstick' == $mode )
|
295 |
+
return bb_unstick_topic( $topic_id );
|
296 |
+
|
297 |
+
return false;
|
298 |
+
}
|
299 |
+
|
300 |
+
function bp_forums_openclose_topic( $args = '' ) {
|
301 |
+
global $bp;
|
302 |
+
|
303 |
+
do_action( 'bbpress_init' );
|
304 |
+
|
305 |
+
$defaults = array(
|
306 |
+
'topic_id' => false,
|
307 |
+
'mode' => 'close' // stick/unstick
|
308 |
+
);
|
309 |
+
|
310 |
+
$r = wp_parse_args( $args, $defaults );
|
311 |
+
extract( $r, EXTR_SKIP );
|
312 |
+
|
313 |
+
if ( 'close' == $mode )
|
314 |
+
return bb_close_topic( $topic_id );
|
315 |
+
else if ( 'open' == $mode )
|
316 |
+
return bb_open_topic( $topic_id );
|
317 |
+
|
318 |
+
return false;
|
319 |
+
}
|
320 |
+
|
321 |
+
function bp_forums_delete_topic( $args = '' ) {
|
322 |
+
global $bp;
|
323 |
+
|
324 |
+
do_action( 'bbpress_init' );
|
325 |
+
|
326 |
+
$defaults = array(
|
327 |
+
'topic_id' => false
|
328 |
+
);
|
329 |
+
|
330 |
+
$r = wp_parse_args( $args, $defaults );
|
331 |
+
extract( $r, EXTR_SKIP );
|
332 |
+
|
333 |
+
return bb_delete_topic( $topic_id, 1 );
|
334 |
+
}
|
335 |
+
|
336 |
+
function bp_forums_total_topic_count() {
|
337 |
+
do_action( 'bbpress_init' );
|
338 |
+
|
339 |
+
$query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => -1, 'count' => true ) );
|
340 |
+
$count = $query->count;
|
341 |
+
$query = null;
|
342 |
+
|
343 |
+
return $count;
|
344 |
+
}
|
345 |
+
|
346 |
+
function bp_forums_total_topic_count_for_user( $user_id = false ) {
|
347 |
+
global $bp;
|
348 |
+
|
349 |
+
do_action( 'bbpress_init' );
|
350 |
+
|
351 |
+
if ( !$user_id )
|
352 |
+
$user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
|
353 |
+
|
354 |
+
$query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
|
355 |
+
$count = $query->count;
|
356 |
+
$query = null;
|
357 |
+
|
358 |
+
return $count;
|
359 |
+
}
|
360 |
+
|
361 |
+
function bp_forums_get_topic_extras( $topics ) {
|
362 |
+
global $bp, $wpdb, $bbdb;
|
363 |
+
|
364 |
+
if ( empty( $topics ) )
|
365 |
+
return $topics;
|
366 |
+
|
367 |
+
/* Get the topic ids */
|
368 |
+
foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
|
369 |
+
$topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
|
370 |
+
|
371 |
+
/* Fetch the topic's last poster details */
|
372 |
+
$poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
|
373 |
+
for ( $i = 0; $i < count( $topics ); $i++ ) {
|
374 |
+
foreach ( (array)$poster_details as $poster ) {
|
375 |
+
if ( $poster->topic_id == $topics[$i]->topic_id ) {
|
376 |
+
$topics[$i]->topic_last_poster_email = $poster->user_email;
|
377 |
+
$topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
|
378 |
+
$topics[$i]->topic_last_poster_login = $poster->user_login;
|
379 |
+
$topics[$i]->topic_last_poster_displayname = $poster->display_name;
|
380 |
+
}
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
/* Fetch fullname for the topic's last poster */
|
385 |
+
if ( function_exists( 'xprofile_install' ) ) {
|
386 |
+
$poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
|
387 |
+
for ( $i = 0; $i < count( $topics ); $i++ ) {
|
388 |
+
foreach ( (array)$poster_names as $name ) {
|
389 |
+
if ( $name->topic_id == $topics[$i]->topic_id )
|
390 |
+
$topics[$i]->topic_last_poster_displayname = $name->value;
|
391 |
+
}
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
return $topics;
|
396 |
+
}
|
397 |
+
|
398 |
+
/* Post Functions */
|
399 |
+
|
400 |
+
function bp_forums_get_topic_posts( $args = '' ) {
|
401 |
+
do_action( 'bbpress_init' );
|
402 |
+
|
403 |
+
$defaults = array(
|
404 |
+
'topic_id' => false,
|
405 |
+
'page' => 1,
|
406 |
+
'per_page' => 15,
|
407 |
+
'order' => 'ASC'
|
408 |
+
);
|
409 |
+
|
410 |
+
$args = wp_parse_args( $args, $defaults );
|
411 |
+
|
412 |
+
$query = new BB_Query( 'post', $args, 'get_thread' );
|
413 |
+
return bp_forums_get_post_extras( $query->results );
|
414 |
+
}
|
415 |
+
|
416 |
+
function bp_forums_get_post( $post_id ) {
|
417 |
+
do_action( 'bbpress_init' );
|
418 |
+
return bb_get_post( $post_id );
|
419 |
+
}
|
420 |
+
|
421 |
+
function bp_forums_delete_post( $args = '' ) {
|
422 |
+
global $bp;
|
423 |
+
|
424 |
+
do_action( 'bbpress_init' );
|
425 |
+
|
426 |
+
$defaults = array(
|
427 |
+
'post_id' => false
|
428 |
+
);
|
429 |
+
|
430 |
+
$r = wp_parse_args( $args, $defaults );
|
431 |
+
extract( $r, EXTR_SKIP );
|
432 |
+
|
433 |
+
return bb_delete_post( $post_id, 1 );
|
434 |
+
}
|
435 |
+
|
436 |
+
function bp_forums_insert_post( $args = '' ) {
|
437 |
+
global $bp;
|
438 |
+
|
439 |
+
do_action( 'bbpress_init' );
|
440 |
+
|
441 |
+
$defaults = array(
|
442 |
+
'post_id' => false,
|
443 |
+
'topic_id' => false,
|
444 |
+
'post_text' => '',
|
445 |
+
'post_time' => date( 'Y-m-d H:i:s' ),
|
446 |
+
'poster_id' => $bp->loggedin_user->id, // accepts ids or names
|
447 |
+
'poster_ip' => $_SERVER['REMOTE_ADDR'],
|
448 |
+
'post_status' => 0, // use bb_delete_post() instead
|
449 |
+
'post_position' => false
|
450 |
+
);
|
451 |
+
|
452 |
+
$r = wp_parse_args( $args, $defaults );
|
453 |
+
extract( $r, EXTR_SKIP );
|
454 |
+
|
455 |
+
if ( !$post = bp_forums_get_post( $post_id ) )
|
456 |
+
$post_id = false;
|
457 |
+
|
458 |
+
if ( !isset( $topic_id ) )
|
459 |
+
$topic_id = $post->topic_id;
|
460 |
+
|
461 |
+
if ( empty( $post_text ) )
|
462 |
+
$post_text = $post->post_text;
|
463 |
+
|
464 |
+
if ( !isset( $post_time ) )
|
465 |
+
$post_time = $post->post_time;
|
466 |
+
|
467 |
+
if ( !isset( $post_position ) )
|
468 |
+
$post_position = $post->post_position;
|
469 |
+
|
470 |
+
$post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
|
471 |
+
|
472 |
+
if ( $post_id )
|
473 |
+
do_action( 'bp_forums_new_post', $post_id );
|
474 |
+
|
475 |
+
return $post_id;
|
476 |
+
}
|
477 |
+
|
478 |
+
function bp_forums_get_post_extras( $posts ) {
|
479 |
+
global $bp, $wpdb;
|
480 |
+
|
481 |
+
if ( empty( $posts ) )
|
482 |
+
return $posts;
|
483 |
+
|
484 |
+
/* Get the user ids */
|
485 |
+
foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
|
486 |
+
$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
|
487 |
+
|
488 |
+
/* Fetch the poster's user_email, user_nicename and user_login */
|
489 |
+
$poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
|
490 |
+
|
491 |
+
for ( $i = 0; $i < count( $posts ); $i++ ) {
|
492 |
+
foreach ( (array)$poster_details as $poster ) {
|
493 |
+
if ( $poster->user_id == $posts[$i]->poster_id ) {
|
494 |
+
$posts[$i]->poster_email = $poster->user_email;
|
495 |
+
$posts[$i]->poster_login = $poster->user_nicename;
|
496 |
+
$posts[$i]->poster_nicename = $poster->user_login;
|
497 |
+
$posts[$i]->poster_name = $poster->display_name;
|
498 |
+
}
|
499 |
+
}
|
500 |
+
}
|
501 |
+
|
502 |
+
/* Fetch fullname for each poster. */
|
503 |
+
if ( function_exists( 'xprofile_install' ) ) {
|
504 |
+
$poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
|
505 |
+
for ( $i = 0; $i < count( $posts ); $i++ ) {
|
506 |
+
foreach ( (array)$poster_names as $name ) {
|
507 |
+
if ( $name->user_id == $topics[$i]->user_id )
|
508 |
+
$posts[$i]->poster_name = $poster->value;
|
509 |
+
}
|
510 |
+
}
|
511 |
+
}
|
512 |
+
|
513 |
+
return $posts;
|
514 |
+
}
|
515 |
+
|
516 |
+
|
517 |
+
function bp_forums_get_forum_topicpost_count( $forum_id ) {
|
518 |
+
global $wpdb, $bbdb;
|
519 |
+
|
520 |
+
do_action( 'bbpress_init' );
|
521 |
+
|
522 |
+
/* Need to find a bbPress function that does this */
|
523 |
+
return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
|
524 |
+
}
|
525 |
+
|
526 |
+
|
527 |
+
function bp_forums_filter_caps( $allcaps ) {
|
528 |
+
global $bp, $wp_roles, $bb_table_prefix;
|
529 |
+
|
530 |
+
$bb_cap = get_user_meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities', true );
|
531 |
+
|
532 |
+
if ( empty( $bb_cap ) )
|
533 |
+
return $allcaps;
|
534 |
+
|
535 |
+
$bb_cap = array_keys($bb_cap);
|
536 |
+
$bb_cap = $wp_roles->get_role( $bb_cap[0] );
|
537 |
+
$bb_cap = $bb_cap->capabilities;
|
538 |
+
|
539 |
+
return array_merge( (array) $allcaps, (array) $bb_cap );
|
540 |
+
}
|
541 |
+
add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
|
542 |
+
|
543 |
+
|
544 |
+
/********************************************************************************
|
545 |
+
* Caching
|
546 |
+
*
|
547 |
+
* Caching functions handle the clearing of cached objects and pages on specific
|
548 |
+
* actions throughout BuddyPress.
|
549 |
+
*/
|
550 |
+
|
551 |
+
// List actions to clear super cached pages on, if super cache is installed
|
552 |
+
add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
|
553 |
+
add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
|
554 |
+
add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
|
555 |
+
|
556 |
?>
|
bp-forums/bb-config.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
<?php
|
2 |
-
/***
|
3 |
-
* *** IMPORTANT ****
|
4 |
-
* This file will stop people from accessing your bbPress installation directly.
|
5 |
-
* It is very important from a security standpoint that this file is not moved.
|
6 |
-
* Your actual bb-config.php file will be installed in the root of your WordPress
|
7 |
-
* installation once you have set up the forums component in BuddyPress.
|
8 |
-
*/
|
9 |
-
|
10 |
-
header("HTTP/1.0 403 Forbidden"); die;
|
11 |
?>
|
1 |
+
<?php
|
2 |
+
/***
|
3 |
+
* *** IMPORTANT ****
|
4 |
+
* This file will stop people from accessing your bbPress installation directly.
|
5 |
+
* It is very important from a security standpoint that this file is not moved.
|
6 |
+
* Your actual bb-config.php file will be installed in the root of your WordPress
|
7 |
+
* installation once you have set up the forums component in BuddyPress.
|
8 |
+
*/
|
9 |
+
|
10 |
+
header("HTTP/1.0 403 Forbidden"); die;
|
11 |
?>
|
bp-forums/bp-forums-admin.php
CHANGED
@@ -1,258 +1,258 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function bp_forums_bbpress_admin() {
|
4 |
-
global $bp;
|
5 |
-
?>
|
6 |
-
<div class="wrap">
|
7 |
-
|
8 |
-
<h2><?php _e( 'Forums Setup', 'buddypress' ) ?></h2>
|
9 |
-
|
10 |
-
<?php if ( isset( $_POST['submit'] ) ) : ?>
|
11 |
-
<div id="message" class="updated fade">
|
12 |
-
<p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
|
13 |
-
</div>
|
14 |
-
<?php endif; ?>
|
15 |
-
|
16 |
-
<?php
|
17 |
-
|
18 |
-
if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) {
|
19 |
-
update_site_option( 'bb-config-location', false );
|
20 |
-
bp_forums_bbpress_install_wizard();
|
21 |
-
} else { ?>
|
22 |
-
<p><?php printf( __( 'bbPress forum integration in BuddyPress has been set up correctly. If you are having problems you can <a href="%s" title="Reinstall bbPress">re-install</a>', 'buddypress' ), site_url( 'wp-admin/admin.php?page=bb-forums-setup&reinstall=1' ) ); ?>
|
23 |
-
<p><?php _e( 'NOTE: The forums directory will only work if your bbPress tables are in the same database as your WordPress tables. If you are not using an existing bbPress install you can ignore this message.', 'buddypress' ) ?></p>
|
24 |
-
<?php
|
25 |
-
}
|
26 |
-
?>
|
27 |
-
</div>
|
28 |
-
<?php
|
29 |
-
}
|
30 |
-
|
31 |
-
function bp_forums_bbpress_install_wizard() {
|
32 |
-
$post_url = site_url( 'wp-admin/admin.php?page=bb-forums-setup' );
|
33 |
-
|
34 |
-
switch( $_REQUEST['step'] ) {
|
35 |
-
case 'existing':
|
36 |
-
if ( 1 == (int)$_REQUEST['doinstall'] ) {
|
37 |
-
if ( !bp_forums_configure_existing_install() ) {
|
38 |
-
_e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
|
39 |
-
} else {
|
40 |
-
?>
|
41 |
-
<h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
|
42 |
-
<p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
|
43 |
-
}
|
44 |
-
} else {
|
45 |
-
?>
|
46 |
-
<form action="" method="post">
|
47 |
-
<h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
|
48 |
-
<p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
|
49 |
-
<p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
|
50 |
-
<p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
|
51 |
-
<input type="hidden" name="step" value="existing" />
|
52 |
-
<input type="hidden" name="doinstall" value="1" />
|
53 |
-
<?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
|
54 |
-
</form>
|
55 |
-
<?php
|
56 |
-
}
|
57 |
-
break;
|
58 |
-
|
59 |
-
case 'new':
|
60 |
-
if ( 1 == (int)$_REQUEST['doinstall'] ) {
|
61 |
-
$result = bp_forums_bbpress_install();
|
62 |
-
|
63 |
-
switch ( $result ) {
|
64 |
-
case 1:
|
65 |
-
_e( 'All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.', 'buddypress' );
|
66 |
-
break;
|
67 |
-
default:
|
68 |
-
// Just write the contents to screen
|
69 |
-
_e( 'A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.', 'buddypress' );
|
70 |
-
?><code style="display:block; margin-top: 30px;"><pre><?php echo htmlspecialchars( $result ) ?></pre></code><?php
|
71 |
-
break;
|
72 |
-
}
|
73 |
-
} else {
|
74 |
-
?>
|
75 |
-
<h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
|
76 |
-
<p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
|
77 |
-
process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
|
78 |
-
<p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
|
79 |
-
<?php
|
80 |
-
}
|
81 |
-
break;
|
82 |
-
|
83 |
-
default:
|
84 |
-
if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
|
85 |
-
<div id="message" class="error">
|
86 |
-
<p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
|
87 |
-
</div>
|
88 |
-
<?php } else { ?>
|
89 |
-
|
90 |
-
<p><?php _e( 'Forums in BuddyPress make use of a bbPress installation to function. You can choose to either let BuddyPress set up a new bbPress install, or use an already existing bbPress install. Please choose one of the options below.', 'buddypress' ) ?></p>
|
91 |
-
|
92 |
-
<a class="button" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Set up a new bbPress installation', 'buddypress' ) ?></a>
|
93 |
-
<a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use an existing bbPress installation', 'buddypress' ) ?></a>
|
94 |
-
|
95 |
-
<?php }
|
96 |
-
break;
|
97 |
-
}
|
98 |
-
}
|
99 |
-
|
100 |
-
function bp_forums_configure_existing_install() {
|
101 |
-
global $wpdb, $bbdb;
|
102 |
-
|
103 |
-
check_admin_referer( 'bp_forums_existing_install_init' );
|
104 |
-
|
105 |
-
/* Sanitize $_REQUEST['bbconfigloc'] */
|
106 |
-
$_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
|
107 |
-
|
108 |
-
if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
|
109 |
-
if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
|
110 |
-
$_REQUEST['bbconfigloc'] .= '/';
|
111 |
-
|
112 |
-
$_REQUEST['bbconfigloc'] .= 'bb-config.php';
|
113 |
-
}
|
114 |
-
|
115 |
-
if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
|
116 |
-
return false;
|
117 |
-
|
118 |
-
update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
|
119 |
-
|
120 |
-
return true;
|
121 |
-
}
|
122 |
-
|
123 |
-
function bp_forums_bbpress_install() {
|
124 |
-
global $wpdb, $bbdb;
|
125 |
-
|
126 |
-
check_admin_referer( 'bp_forums_new_install_init' );
|
127 |
-
|
128 |
-
/* Create the bb-config.php file */
|
129 |
-
$initial_write = bp_forums_bbpress_write(
|
130 |
-
BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
|
131 |
-
ABSPATH . 'bb-config.php',
|
132 |
-
array(
|
133 |
-
"define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
|
134 |
-
"define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
|
135 |
-
"define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ),
|
136 |
-
"define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ),
|
137 |
-
"define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ),
|
138 |
-
"define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ),
|
139 |
-
"define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ),
|
140 |
-
"define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ),
|
141 |
-
"define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ),
|
142 |
-
"define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ),
|
143 |
-
"\$bb_table_prefix = '" => array( "'bb_'", "'" . $
|
144 |
-
"define( 'BB_LANG', '" => array( "''", "'" . WPLANG . "'" )
|
145 |
-
)
|
146 |
-
);
|
147 |
-
|
148 |
-
/* Add the custom user and usermeta entries to the config file */
|
149 |
-
if ( $initial_write == 1 ) {
|
150 |
-
$file = file_get_contents( ABSPATH . 'bb-config.php' );
|
151 |
-
} else {
|
152 |
-
$file = &$initial_write;
|
153 |
-
}
|
154 |
-
|
155 |
-
$file = substr( $file, 0, -2 );
|
156 |
-
$file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
|
157 |
-
$file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
|
158 |
-
$file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
|
159 |
-
$file .= "\n" . '$bb->name = \'' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
|
160 |
-
|
161 |
-
if ( bp_core_is_multisite() )
|
162 |
-
$file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . BP_ROOT_BLOG . ';';
|
163 |
-
|
164 |
-
if ( defined( 'AUTH_SALT' ) )
|
165 |
-
$file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
|
166 |
-
|
167 |
-
if ( defined( 'LOGGED_IN_SALT' ) )
|
168 |
-
$file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
|
169 |
-
|
170 |
-
if ( defined( 'SECURE_AUTH_SALT' ) )
|
171 |
-
$file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
|
172 |
-
|
173 |
-
$file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
|
174 |
-
$file .= "\n\n" . '?>';
|
175 |
-
|
176 |
-
if ( $initial_write == 1 ) {
|
177 |
-
$file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
|
178 |
-
fwrite( $file_handle, $file );
|
179 |
-
fclose( $file_handle );
|
180 |
-
} else {
|
181 |
-
$initial_write = $file;
|
182 |
-
}
|
183 |
-
|
184 |
-
update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
|
185 |
-
return $initial_write;
|
186 |
-
}
|
187 |
-
|
188 |
-
function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
|
189 |
-
if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) {
|
190 |
-
return -1;
|
191 |
-
}
|
192 |
-
|
193 |
-
if ( !$file_target ) {
|
194 |
-
$file_target = $file_source;
|
195 |
-
}
|
196 |
-
|
197 |
-
if ( !$alterations || !is_array( $alterations ) ) {
|
198 |
-
return -2;
|
199 |
-
}
|
200 |
-
|
201 |
-
// Get the existing lines in the file
|
202 |
-
$lines = file( $file_source );
|
203 |
-
|
204 |
-
// Initialise an array to store the modified lines
|
205 |
-
$modified_lines = array();
|
206 |
-
|
207 |
-
// Loop through the lines and modify them
|
208 |
-
foreach ( (array)$lines as $line ) {
|
209 |
-
if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
|
210 |
-
$alteration = $alterations[substr( $line, 0, 20 )];
|
211 |
-
$modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
|
212 |
-
} else {
|
213 |
-
$modified_lines[] = $line;
|
214 |
-
}
|
215 |
-
}
|
216 |
-
|
217 |
-
$writable = true;
|
218 |
-
if ( file_exists( $file_target ) ) {
|
219 |
-
if ( !is_writable( $file_target ) ) {
|
220 |
-
$writable = false;
|
221 |
-
}
|
222 |
-
} else {
|
223 |
-
$dir_target = dirname( $file_target );
|
224 |
-
|
225 |
-
if ( file_exists( $dir_target ) ) {
|
226 |
-
if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) {
|
227 |
-
$writable = false;
|
228 |
-
}
|
229 |
-
} else {
|
230 |
-
$writable = false;
|
231 |
-
}
|
232 |
-
}
|
233 |
-
|
234 |
-
if ( !$writable )
|
235 |
-
return trim( join( null, $modified_lines ) );
|
236 |
-
|
237 |
-
// Open the file for writing - rewrites the whole file
|
238 |
-
$file_handle = fopen( $file_target, 'w' );
|
239 |
-
|
240 |
-
// Write lines one by one to avoid OS specific newline hassles
|
241 |
-
foreach ( (array)$modified_lines as $modified_line ) {
|
242 |
-
if ( false !== strpos( $modified_line, '?>' ) ) {
|
243 |
-
$modified_line = '?>';
|
244 |
-
}
|
245 |
-
fwrite( $file_handle, $modified_line );
|
246 |
-
if ( $modified_line == '?>' ) {
|
247 |
-
break;
|
248 |
-
}
|
249 |
-
}
|
250 |
-
|
251 |
-
// Close the config file
|
252 |
-
fclose( $file_handle );
|
253 |
-
|
254 |
-
@chmod( $file_target, 0666 );
|
255 |
-
|
256 |
-
return 1;
|
257 |
-
}
|
258 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function bp_forums_bbpress_admin() {
|
4 |
+
global $bp;
|
5 |
+
?>
|
6 |
+
<div class="wrap">
|
7 |
+
|
8 |
+
<h2><?php _e( 'Forums Setup', 'buddypress' ) ?></h2>
|
9 |
+
|
10 |
+
<?php if ( isset( $_POST['submit'] ) ) : ?>
|
11 |
+
<div id="message" class="updated fade">
|
12 |
+
<p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
|
13 |
+
</div>
|
14 |
+
<?php endif; ?>
|
15 |
+
|
16 |
+
<?php
|
17 |
+
|
18 |
+
if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) {
|
19 |
+
update_site_option( 'bb-config-location', false );
|
20 |
+
bp_forums_bbpress_install_wizard();
|
21 |
+
} else { ?>
|
22 |
+
<p><?php printf( __( 'bbPress forum integration in BuddyPress has been set up correctly. If you are having problems you can <a href="%s" title="Reinstall bbPress">re-install</a>', 'buddypress' ), site_url( 'wp-admin/admin.php?page=bb-forums-setup&reinstall=1' ) ); ?>
|
23 |
+
<p><?php _e( 'NOTE: The forums directory will only work if your bbPress tables are in the same database as your WordPress tables. If you are not using an existing bbPress install you can ignore this message.', 'buddypress' ) ?></p>
|
24 |
+
<?php
|
25 |
+
}
|
26 |
+
?>
|
27 |
+
</div>
|
28 |
+
<?php
|
29 |
+
}
|
30 |
+
|
31 |
+
function bp_forums_bbpress_install_wizard() {
|
32 |
+
$post_url = site_url( 'wp-admin/admin.php?page=bb-forums-setup' );
|
33 |
+
|
34 |
+
switch( $_REQUEST['step'] ) {
|
35 |
+
case 'existing':
|
36 |
+
if ( 1 == (int)$_REQUEST['doinstall'] ) {
|
37 |
+
if ( !bp_forums_configure_existing_install() ) {
|
38 |
+
_e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
|
39 |
+
} else {
|
40 |
+
?>
|
41 |
+
<h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
|
42 |
+
<p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
|
43 |
+
}
|
44 |
+
} else {
|
45 |
+
?>
|
46 |
+
<form action="" method="post">
|
47 |
+
<h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
|
48 |
+
<p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
|
49 |
+
<p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
|
50 |
+
<p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
|
51 |
+
<input type="hidden" name="step" value="existing" />
|
52 |
+
<input type="hidden" name="doinstall" value="1" />
|
53 |
+
<?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
|
54 |
+
</form>
|
55 |
+
<?php
|
56 |
+
}
|
57 |
+
break;
|
58 |
+
|
59 |
+
case 'new':
|
60 |
+
if ( 1 == (int)$_REQUEST['doinstall'] ) {
|
61 |
+
$result = bp_forums_bbpress_install();
|
62 |
+
|
63 |
+
switch ( $result ) {
|
64 |
+
case 1:
|
65 |
+
_e( 'All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.', 'buddypress' );
|
66 |
+
break;
|
67 |
+
default:
|
68 |
+
// Just write the contents to screen
|
69 |
+
_e( 'A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.', 'buddypress' );
|
70 |
+
?><code style="display:block; margin-top: 30px;"><pre><?php echo htmlspecialchars( $result ) ?></pre></code><?php
|
71 |
+
break;
|
72 |
+
}
|
73 |
+
} else {
|
74 |
+
?>
|
75 |
+
<h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
|
76 |
+
<p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
|
77 |
+
process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
|
78 |
+
<p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
|
79 |
+
<?php
|
80 |
+
}
|
81 |
+
break;
|
82 |
+
|
83 |
+
default:
|
84 |
+
if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
|
85 |
+
<div id="message" class="error">
|
86 |
+
<p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
|
87 |
+
</div>
|
88 |
+
<?php } else { ?>
|
89 |
+
|
90 |
+
<p><?php _e( 'Forums in BuddyPress make use of a bbPress installation to function. You can choose to either let BuddyPress set up a new bbPress install, or use an already existing bbPress install. Please choose one of the options below.', 'buddypress' ) ?></p>
|
91 |
+
|
92 |
+
<a class="button" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Set up a new bbPress installation', 'buddypress' ) ?></a>
|
93 |
+
<a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use an existing bbPress installation', 'buddypress' ) ?></a>
|
94 |
+
|
95 |
+
<?php }
|
96 |
+
break;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
function bp_forums_configure_existing_install() {
|
101 |
+
global $wpdb, $bbdb;
|
102 |
+
|
103 |
+
check_admin_referer( 'bp_forums_existing_install_init' );
|
104 |
+
|
105 |
+
/* Sanitize $_REQUEST['bbconfigloc'] */
|
106 |
+
$_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
|
107 |
+
|
108 |
+
if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
|
109 |
+
if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
|
110 |
+
$_REQUEST['bbconfigloc'] .= '/';
|
111 |
+
|
112 |
+
$_REQUEST['bbconfigloc'] .= 'bb-config.php';
|
113 |
+
}
|
114 |
+
|
115 |
+
if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
|
116 |
+
return false;
|
117 |
+
|
118 |
+
update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
|
119 |
+
|
120 |
+
return true;
|
121 |
+
}
|
122 |
+
|
123 |
+
function bp_forums_bbpress_install() {
|
124 |
+
global $wpdb, $bbdb, $bp;
|
125 |
+
|
126 |
+
check_admin_referer( 'bp_forums_new_install_init' );
|
127 |
+
|
128 |
+
/* Create the bb-config.php file */
|
129 |
+
$initial_write = bp_forums_bbpress_write(
|
130 |
+
BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
|
131 |
+
ABSPATH . 'bb-config.php',
|
132 |
+
array(
|
133 |
+
"define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
|
134 |
+
"define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
|
135 |
+
"define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ),
|
136 |
+
"define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ),
|
137 |
+
"define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ),
|
138 |
+
"define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ),
|
139 |
+
"define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ),
|
140 |
+
"define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ),
|
141 |
+
"define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ),
|
142 |
+
"define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ),
|
143 |
+
"\$bb_table_prefix = '" => array( "'bb_'", "'" . $bp->table_prefix . "bb_'" ),
|
144 |
+
"define( 'BB_LANG', '" => array( "''", "'" . WPLANG . "'" )
|
145 |
+
)
|
146 |
+
);
|
147 |
+
|
148 |
+
/* Add the custom user and usermeta entries to the config file */
|
149 |
+
if ( $initial_write == 1 ) {
|
150 |
+
$file = file_get_contents( ABSPATH . 'bb-config.php' );
|
151 |
+
} else {
|
152 |
+
$file = &$initial_write;
|
153 |
+
}
|
154 |
+
|
155 |
+
$file = substr( $file, 0, -2 );
|
156 |
+
$file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
|
157 |
+
$file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
|
158 |
+
$file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
|
159 |
+
$file .= "\n" . '$bb->name = \'' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
|
160 |
+
|
161 |
+
if ( bp_core_is_multisite() )
|
162 |
+
$file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . BP_ROOT_BLOG . ';';
|
163 |
+
|
164 |
+
if ( defined( 'AUTH_SALT' ) )
|
165 |
+
$file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
|
166 |
+
|
167 |
+
if ( defined( 'LOGGED_IN_SALT' ) )
|
168 |
+
$file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
|
169 |
+
|
170 |
+
if ( defined( 'SECURE_AUTH_SALT' ) )
|
171 |
+
$file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
|
172 |
+
|
173 |
+
$file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
|
174 |
+
$file .= "\n\n" . '?>';
|
175 |
+
|
176 |
+
if ( $initial_write == 1 ) {
|
177 |
+
$file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
|
178 |
+
fwrite( $file_handle, $file );
|
179 |
+
fclose( $file_handle );
|
180 |
+
} else {
|
181 |
+
$initial_write = $file;
|
182 |
+
}
|
183 |
+
|
184 |
+
update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
|
185 |
+
return $initial_write;
|
186 |
+
}
|
187 |
+
|
188 |
+
function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
|
189 |
+
if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) {
|
190 |
+
return -1;
|
191 |
+
}
|
192 |
+
|
193 |
+
if ( !$file_target ) {
|
194 |
+
$file_target = $file_source;
|
195 |
+
}
|
196 |
+
|
197 |
+
if ( !$alterations || !is_array( $alterations ) ) {
|
198 |
+
return -2;
|
199 |
+
}
|
200 |
+
|
201 |
+
// Get the existing lines in the file
|
202 |
+
$lines = file( $file_source );
|
203 |
+
|
204 |
+
// Initialise an array to store the modified lines
|
205 |
+
$modified_lines = array();
|
206 |
+
|
207 |
+
// Loop through the lines and modify them
|
208 |
+
foreach ( (array)$lines as $line ) {
|
209 |
+
if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
|
210 |
+
$alteration = $alterations[substr( $line, 0, 20 )];
|
211 |
+
$modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
|
212 |
+
} else {
|
213 |
+
$modified_lines[] = $line;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
$writable = true;
|
218 |
+
if ( file_exists( $file_target ) ) {
|
219 |
+
if ( !is_writable( $file_target ) ) {
|
220 |
+
$writable = false;
|
221 |
+
}
|
222 |
+
} else {
|
223 |
+
$dir_target = dirname( $file_target );
|
224 |
+
|
225 |
+
if ( file_exists( $dir_target ) ) {
|
226 |
+
if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) {
|
227 |
+
$writable = false;
|
228 |
+
}
|
229 |
+
} else {
|
230 |
+
$writable = false;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
if ( !$writable )
|
235 |
+
return trim( join( null, $modified_lines ) );
|
236 |
+
|
237 |
+
// Open the file for writing - rewrites the whole file
|
238 |
+
$file_handle = fopen( $file_target, 'w' );
|
239 |
+
|
240 |
+
// Write lines one by one to avoid OS specific newline hassles
|
241 |
+
foreach ( (array)$modified_lines as $modified_line ) {
|
242 |
+
if ( false !== strpos( $modified_line, '?>' ) ) {
|
243 |
+
$modified_line = '?>';
|
244 |
+
}
|
245 |
+
fwrite( $file_handle, $modified_line );
|
246 |
+
if ( $modified_line == '?>' ) {
|
247 |
+
break;
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
// Close the config file
|
252 |
+
fclose( $file_handle );
|
253 |
+
|
254 |
+
@chmod( $file_target, 0666 );
|
255 |
+
|
256 |
+
return 1;
|
257 |
+
}
|
258 |
?>
|
bp-forums/bp-forums-bbpress.php
CHANGED
@@ -1,175 +1,175 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function bp_forums_load_bbpress() {
|
4 |
-
global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object;
|
5 |
-
global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
|
6 |
-
global $bb_roles, $wp_taxonomy_object;
|
7 |
-
|
8 |
-
/* Return if we've already run this function. */
|
9 |
-
if ( is_object( $bbdb ) && is_object( $bb_roles ) )
|
10 |
-
return;
|
11 |
-
|
12 |
-
if ( !bp_forums_is_installed_correctly() )
|
13 |
-
return false;
|
14 |
-
|
15 |
-
define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
|
16 |
-
define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
|
17 |
-
define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
|
18 |
-
define( 'BB_INC', 'bb-includes/' );
|
19 |
-
|
20 |
-
require_once( BB_PATH . BB_INC . 'class.bb-query.php' );
|
21 |
-
require_once( BB_PATH . BB_INC . 'class.bb-walker.php' );
|
22 |
-
|
23 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-core.php' );
|
24 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' );
|
25 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' );
|
26 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' );
|
27 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' );
|
28 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' );
|
29 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' );
|
30 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' );
|
31 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' );
|
32 |
-
require_once( BB_PATH . BB_INC . 'functions.bb-template.php' );
|
33 |
-
|
34 |
-
require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' );
|
35 |
-
require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' );
|
36 |
-
|
37 |
-
$bb = new stdClass();
|
38 |
-
require_once( $bp->forums->bbconfig );
|
39 |
-
|
40 |
-
// Setup the global database connection
|
41 |
-
$bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
|
42 |
-
|
43 |
-
/* Set the table names */
|
44 |
-
$bbdb->forums = $bb_table_prefix . 'forums';
|
45 |
-
$bbdb->meta = $bb_table_prefix . 'meta';
|
46 |
-
$bbdb->posts = $bb_table_prefix . 'posts';
|
47 |
-
$bbdb->terms = $bb_table_prefix . 'terms';
|
48 |
-
$bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
|
49 |
-
$bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
|
50 |
-
$bbdb->topics = $bb_table_prefix . 'topics';
|
51 |
-
|
52 |
-
if ( isset( $bb->custom_user_table ) )
|
53 |
-
$bbdb->users = $bb->custom_user_table;
|
54 |
-
else
|
55 |
-
$bbdb->users = $wpdb->users;
|
56 |
-
|
57 |
-
if ( isset( $bb->custom_user_meta_table ) )
|
58 |
-
$bbdb->usermeta = $bb->custom_user_meta_table;
|
59 |
-
else
|
60 |
-
$bbdb->usermeta = $wpdb->usermeta;
|
61 |
-
|
62 |
-
$bbdb->prefix = $bb_table_prefix;
|
63 |
-
|
64 |
-
define( 'BB_INSTALLING', false );
|
65 |
-
|
66 |
-
/* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
|
67 |
-
if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
|
68 |
-
require_once( ABSPATH . 'wp-admin/upgrade
|
69 |
-
|
70 |
-
require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
|
71 |
-
|
72 |
-
if ( is_object( $wp_roles ) ) {
|
73 |
-
$bb_roles
|
74 |
-
bb_init_roles( $bb_roles );
|
75 |
-
}
|
76 |
-
|
77 |
-
do_action( 'bb_got_roles' );
|
78 |
-
do_action( 'bb_init' );
|
79 |
-
do_action( 'init_roles' );
|
80 |
-
|
81 |
-
$bb_current_user = $current_user;
|
82 |
-
$wp_users_object = new BP_Forums_BB_Auth;
|
83 |
-
|
84 |
-
if ( !isset( $wp_taxonomy_object ) )
|
85 |
-
$wp_taxonomy_object = new BB_Taxonomy( $bbdb );
|
86 |
-
|
87 |
-
$wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );
|
88 |
-
|
89 |
-
// Set a site id if there isn't one already
|
90 |
-
if ( !isset( $bb->site_id ) )
|
91 |
-
$bb->site_id = BP_ROOT_BLOG;
|
92 |
-
|
93 |
-
/* Check if the tables are installed, if not, install them */
|
94 |
-
if ( !$tables_installed ) {
|
95 |
-
require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );
|
96 |
-
|
97 |
-
/* Backticks and "IF NOT EXISTS" break the dbDelta function. */
|
98 |
-
dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) );
|
99 |
-
|
100 |
-
require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' );
|
101 |
-
bb_update_db_version();
|
102 |
-
|
103 |
-
/* Set the site admins as the keymasters */
|
104 |
-
$site_admins = get_site_option( 'site_admins', array('admin') );
|
105 |
-
foreach ( (array)$site_admins as $site_admin )
|
106 |
-
|
107 |
-
|
108 |
-
// Create the first forum.
|
109 |
-
bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
|
110 |
-
|
111 |
-
// Set the site URI
|
112 |
-
bb_update_option( 'uri', BB_URL );
|
113 |
-
}
|
114 |
-
|
115 |
-
register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) );
|
116 |
-
}
|
117 |
-
add_action( 'bbpress_init', 'bp_forums_load_bbpress' );
|
118 |
-
|
119 |
-
/* WP to bbP wrapper functions */
|
120 |
-
function bb_get_current_user() { global $current_user; return $current_user; }
|
121 |
-
function bb_get_user( $user_id ) { return get_userdata( $user_id ); }
|
122 |
-
function bb_cache_users( $users ) {}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* bbPress needs this class for its usermeta manipulation.
|
126 |
-
*/
|
127 |
-
class BP_Forums_BB_Auth {
|
128 |
-
function update_meta( $args = '' ) {
|
129 |
-
$defaults = array( 'id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users' );
|
130 |
-
$args = wp_parse_args( $args, $defaults );
|
131 |
-
extract( $args, EXTR_SKIP );
|
132 |
-
|
133 |
-
return
|
134 |
-
}
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* bbPress needs the DB class to be BPDB, but we want to use WPDB, so we can
|
139 |
-
* extend it and use this.
|
140 |
-
*/
|
141 |
-
class BPDB extends WPDB {
|
142 |
-
function escape_deep( $data ) {
|
143 |
-
if ( is_array( $data ) ) {
|
144 |
-
foreach ( (array) $data as $k => $v ) {
|
145 |
-
if ( is_array( $v ) ) {
|
146 |
-
$data[$k] = $this->_escape( $v );
|
147 |
-
} else {
|
148 |
-
$data[$k] = $this->_real_escape( $v );
|
149 |
-
}
|
150 |
-
}
|
151 |
-
} else {
|
152 |
-
$data = $this->_real_escape( $data );
|
153 |
-
}
|
154 |
-
|
155 |
-
return $data;
|
156 |
-
}
|
157 |
-
}
|
158 |
-
|
159 |
-
/* BBPress needs this function to convert vars */
|
160 |
-
function backpress_convert_object( &$object, $output ) {
|
161 |
-
if ( is_array( $object ) ) {
|
162 |
-
foreach ( array_keys( $object ) as $key )
|
163 |
-
backpress_convert_object( $object[$key], $output );
|
164 |
-
} else {
|
165 |
-
switch ( $output ) {
|
166 |
-
case OBJECT : break;
|
167 |
-
case ARRAY_A : $object = get_object_vars($object); break;
|
168 |
-
case ARRAY_N : $object = array_values(get_object_vars($object)); break;
|
169 |
-
}
|
170 |
-
}
|
171 |
-
}
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function bp_forums_load_bbpress() {
|
4 |
+
global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object;
|
5 |
+
global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
|
6 |
+
global $bb_roles, $wp_taxonomy_object;
|
7 |
+
|
8 |
+
/* Return if we've already run this function. */
|
9 |
+
if ( is_object( $bbdb ) && is_object( $bb_roles ) )
|
10 |
+
return;
|
11 |
+
|
12 |
+
if ( !bp_forums_is_installed_correctly() )
|
13 |
+
return false;
|
14 |
+
|
15 |
+
define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
|
16 |
+
define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
|
17 |
+
define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
|
18 |
+
define( 'BB_INC', 'bb-includes/' );
|
19 |
+
|
20 |
+
require_once( BB_PATH . BB_INC . 'class.bb-query.php' );
|
21 |
+
require_once( BB_PATH . BB_INC . 'class.bb-walker.php' );
|
22 |
+
|
23 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-core.php' );
|
24 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' );
|
25 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' );
|
26 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' );
|
27 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' );
|
28 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' );
|
29 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' );
|
30 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' );
|
31 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' );
|
32 |
+
require_once( BB_PATH . BB_INC . 'functions.bb-template.php' );
|
33 |
+
|
34 |
+
require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' );
|
35 |
+
require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' );
|
36 |
+
|
37 |
+
$bb = new stdClass();
|
38 |
+
require_once( $bp->forums->bbconfig );
|
39 |
+
|
40 |
+
// Setup the global database connection
|
41 |
+
$bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
|
42 |
+
|
43 |
+
/* Set the table names */
|
44 |
+
$bbdb->forums = $bb_table_prefix . 'forums';
|
45 |
+
$bbdb->meta = $bb_table_prefix . 'meta';
|
46 |
+
$bbdb->posts = $bb_table_prefix . 'posts';
|
47 |
+
$bbdb->terms = $bb_table_prefix . 'terms';
|
48 |
+
$bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
|
49 |
+
$bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
|
50 |
+
$bbdb->topics = $bb_table_prefix . 'topics';
|
51 |
+
|
52 |
+
if ( isset( $bb->custom_user_table ) )
|
53 |
+
$bbdb->users = $bb->custom_user_table;
|
54 |
+
else
|
55 |
+
$bbdb->users = $wpdb->users;
|
56 |
+
|
57 |
+
if ( isset( $bb->custom_user_meta_table ) )
|
58 |
+
$bbdb->usermeta = $bb->custom_user_meta_table;
|
59 |
+
else
|
60 |
+
$bbdb->usermeta = $wpdb->usermeta;
|
61 |
+
|
62 |
+
$bbdb->prefix = $bb_table_prefix;
|
63 |
+
|
64 |
+
define( 'BB_INSTALLING', false );
|
65 |
+
|
66 |
+
/* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
|
67 |
+
if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
|
68 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
69 |
+
|
70 |
+
require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
|
71 |
+
|
72 |
+
if ( is_object( $wp_roles ) ) {
|
73 |
+
$bb_roles = $wp_roles;
|
74 |
+
bb_init_roles( $bb_roles );
|
75 |
+
}
|
76 |
+
|
77 |
+
do_action( 'bb_got_roles' );
|
78 |
+
do_action( 'bb_init' );
|
79 |
+
do_action( 'init_roles' );
|
80 |
+
|
81 |
+
$bb_current_user = $current_user;
|
82 |
+
$wp_users_object = new BP_Forums_BB_Auth;
|
83 |
+
|
84 |
+
if ( !isset( $wp_taxonomy_object ) )
|
85 |
+
$wp_taxonomy_object = new BB_Taxonomy( $bbdb );
|
86 |
+
|
87 |
+
$wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );
|
88 |
+
|
89 |
+
// Set a site id if there isn't one already
|
90 |
+
if ( !isset( $bb->site_id ) )
|
91 |
+
$bb->site_id = BP_ROOT_BLOG;
|
92 |
+
|
93 |
+
/* Check if the tables are installed, if not, install them */
|
94 |
+
if ( !$tables_installed ) {
|
95 |
+
require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );
|
96 |
+
|
97 |
+
/* Backticks and "IF NOT EXISTS" break the dbDelta function. */
|
98 |
+
dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) );
|
99 |
+
|
100 |
+
require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' );
|
101 |
+
bb_update_db_version();
|
102 |
+
|
103 |
+
/* Set the site admins as the keymasters */
|
104 |
+
$site_admins = get_site_option( 'site_admins', array('admin') );
|
105 |
+
foreach ( (array)$site_admins as $site_admin )
|
106 |
+
update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
|
107 |
+
|
108 |
+
// Create the first forum.
|
109 |
+
bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
|
110 |
+
|
111 |
+
// Set the site URI
|
112 |
+
bb_update_option( 'uri', BB_URL );
|
113 |
+
}
|
114 |
+
|
115 |
+
register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) );
|
116 |
+
}
|
117 |
+
add_action( 'bbpress_init', 'bp_forums_load_bbpress' );
|
118 |
+
|
119 |
+
/* WP to bbP wrapper functions */
|
120 |
+
function bb_get_current_user() { global $current_user; return $current_user; }
|
121 |
+
function bb_get_user( $user_id ) { return get_userdata( $user_id ); }
|
122 |
+
function bb_cache_users( $users ) {}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* bbPress needs this class for its usermeta manipulation.
|
126 |
+
*/
|
127 |
+
class BP_Forums_BB_Auth {
|
128 |
+
function update_meta( $args = '' ) {
|
129 |
+
$defaults = array( 'id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users' );
|
130 |
+
$args = wp_parse_args( $args, $defaults );
|
131 |
+
extract( $args, EXTR_SKIP );
|
132 |
+
|
133 |
+
return update_user_meta( $id, $meta_key, $meta_value );
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* bbPress needs the DB class to be BPDB, but we want to use WPDB, so we can
|
139 |
+
* extend it and use this.
|
140 |
+
*/
|
141 |
+
class BPDB extends WPDB {
|
142 |
+
function escape_deep( $data ) {
|
143 |
+
if ( is_array( $data ) ) {
|
144 |
+
foreach ( (array) $data as $k => $v ) {
|
145 |
+
if ( is_array( $v ) ) {
|
146 |
+
$data[$k] = $this->_escape( $v );
|
147 |
+
} else {
|
148 |
+
$data[$k] = $this->_real_escape( $v );
|
149 |
+
}
|
150 |
+
}
|
151 |
+
} else {
|
152 |
+
$data = $this->_real_escape( $data );
|
153 |
+
}
|
154 |
+
|
155 |
+
return $data;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
/* BBPress needs this function to convert vars */
|
160 |
+
function backpress_convert_object( &$object, $output ) {
|
161 |
+
if ( is_array( $object ) ) {
|
162 |
+
foreach ( array_keys( $object ) as $key )
|
163 |
+
backpress_convert_object( $object[$key], $output );
|
164 |
+
} else {
|
165 |
+
switch ( $output ) {
|
166 |
+
case OBJECT : break;
|
167 |
+
case ARRAY_A : $object = get_object_vars($object); break;
|
168 |
+
case ARRAY_N : $object = array_values(get_object_vars($object)); break;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
?>
|
bp-forums/bp-forums-filters.php
CHANGED
@@ -1,91 +1,113 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/* Apply WordPress defined filters */
|
4 |
-
add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
|
5 |
-
add_filter( 'bp_forums_bbconfig_location', '
|
6 |
-
|
7 |
-
add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
|
8 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
|
9 |
-
add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
|
10 |
-
|
11 |
-
add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
|
12 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
|
13 |
-
add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
|
14 |
-
|
15 |
-
add_filter( 'bp_get_the_topic_title', 'wptexturize' );
|
16 |
-
add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
|
17 |
-
add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
|
18 |
-
add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
|
19 |
-
add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
|
20 |
-
|
21 |
-
add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
|
22 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
|
23 |
-
add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
|
24 |
-
|
25 |
-
add_filter( 'bp_get_the_topic_title', 'convert_chars' );
|
26 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
|
27 |
-
add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
|
28 |
-
|
29 |
-
add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
|
30 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
|
31 |
-
|
32 |
-
add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
|
33 |
-
add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
|
34 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
|
35 |
-
add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
|
36 |
-
add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
|
37 |
-
add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
|
38 |
-
|
39 |
-
add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
|
40 |
-
|
41 |
-
add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
|
42 |
-
add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
|
43 |
-
|
44 |
-
add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
|
45 |
-
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
|
46 |
-
add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
|
47 |
-
|
48 |
-
function bp_forums_filter_kses( $content ) {
|
49 |
-
global $allowedtags;
|
50 |
-
|
51 |
-
$forums_allowedtags = $allowedtags;
|
52 |
-
$forums_allowedtags['span'] = array();
|
53 |
-
$forums_allowedtags['span']['class'] = array();
|
54 |
-
$forums_allowedtags['div'] = array();
|
55 |
-
$forums_allowedtags['div']['class'] = array();
|
56 |
-
$forums_allowedtags['div']['id'] = array();
|
57 |
-
$forums_allowedtags['a']['class'] = array();
|
58 |
-
$forums_allowedtags['img'] = array();
|
59 |
-
$forums_allowedtags['br'] = array();
|
60 |
-
$forums_allowedtags['p'] = array();
|
61 |
-
$forums_allowedtags['img']['src'] = array();
|
62 |
-
$forums_allowedtags['img']['alt'] = array();
|
63 |
-
$forums_allowedtags['img']['class'] = array();
|
64 |
-
$forums_allowedtags['img']['width'] = array();
|
65 |
-
$forums_allowedtags['img']['height'] = array();
|
66 |
-
$forums_allowedtags['img']['class'] = array();
|
67 |
-
$forums_allowedtags['img']['id'] = array();
|
68 |
-
$forums_allowedtags['code'] = array();
|
69 |
-
$forums_allowedtags['blockquote'] = array();
|
70 |
-
|
71 |
-
$forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
|
72 |
-
return wp_kses( $content, $forums_allowedtags );
|
73 |
-
}
|
74 |
-
|
75 |
-
function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
|
76 |
-
global $bp;
|
77 |
-
|
78 |
-
return apply_filters( 'bp_forums_filter_tag_link', $bp->root_domain . '/' . $bp->forums->slug . '/tag/' . $tag . '/' );
|
79 |
-
}
|
80 |
-
add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
|
81 |
-
|
82 |
-
function bp_forums_make_nofollow_filter( $text ) {
|
83 |
-
return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
|
84 |
-
}
|
85 |
-
function bp_forums_make_nofollow_filter_callback( $matches ) {
|
86 |
-
$text = $matches[1];
|
87 |
-
$text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
|
88 |
-
return "<a $text rel=\"nofollow\">";
|
89 |
-
}
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/* Apply WordPress defined filters */
|
4 |
+
add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
|
5 |
+
add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 );
|
6 |
+
|
7 |
+
add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
|
8 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
|
9 |
+
add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
|
10 |
+
|
11 |
+
add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
|
12 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
|
13 |
+
add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
|
14 |
+
|
15 |
+
add_filter( 'bp_get_the_topic_title', 'wptexturize' );
|
16 |
+
add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
|
17 |
+
add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
|
18 |
+
add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
|
19 |
+
add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
|
20 |
+
|
21 |
+
add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
|
22 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
|
23 |
+
add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
|
24 |
+
|
25 |
+
add_filter( 'bp_get_the_topic_title', 'convert_chars' );
|
26 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
|
27 |
+
add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
|
28 |
+
|
29 |
+
add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
|
30 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
|
31 |
+
|
32 |
+
add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
|
33 |
+
add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
|
34 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
|
35 |
+
add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
|
36 |
+
add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
|
37 |
+
add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
|
38 |
+
|
39 |
+
add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
|
40 |
+
|
41 |
+
add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
|
42 |
+
add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
|
43 |
+
|
44 |
+
add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
|
45 |
+
add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
|
46 |
+
add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
|
47 |
+
|
48 |
+
function bp_forums_filter_kses( $content ) {
|
49 |
+
global $allowedtags;
|
50 |
+
|
51 |
+
$forums_allowedtags = $allowedtags;
|
52 |
+
$forums_allowedtags['span'] = array();
|
53 |
+
$forums_allowedtags['span']['class'] = array();
|
54 |
+
$forums_allowedtags['div'] = array();
|
55 |
+
$forums_allowedtags['div']['class'] = array();
|
56 |
+
$forums_allowedtags['div']['id'] = array();
|
57 |
+
$forums_allowedtags['a']['class'] = array();
|
58 |
+
$forums_allowedtags['img'] = array();
|
59 |
+
$forums_allowedtags['br'] = array();
|
60 |
+
$forums_allowedtags['p'] = array();
|
61 |
+
$forums_allowedtags['img']['src'] = array();
|
62 |
+
$forums_allowedtags['img']['alt'] = array();
|
63 |
+
$forums_allowedtags['img']['class'] = array();
|
64 |
+
$forums_allowedtags['img']['width'] = array();
|
65 |
+
$forums_allowedtags['img']['height'] = array();
|
66 |
+
$forums_allowedtags['img']['class'] = array();
|
67 |
+
$forums_allowedtags['img']['id'] = array();
|
68 |
+
$forums_allowedtags['code'] = array();
|
69 |
+
$forums_allowedtags['blockquote'] = array();
|
70 |
+
|
71 |
+
$forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
|
72 |
+
return wp_kses( $content, $forums_allowedtags );
|
73 |
+
}
|
74 |
+
|
75 |
+
function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
|
76 |
+
global $bp;
|
77 |
+
|
78 |
+
return apply_filters( 'bp_forums_filter_tag_link', $bp->root_domain . '/' . $bp->forums->slug . '/tag/' . $tag . '/' );
|
79 |
+
}
|
80 |
+
add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
|
81 |
+
|
82 |
+
function bp_forums_make_nofollow_filter( $text ) {
|
83 |
+
return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
|
84 |
+
}
|
85 |
+
function bp_forums_make_nofollow_filter_callback( $matches ) {
|
86 |
+
$text = $matches[1];
|
87 |
+
$text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
|
88 |
+
return "<a $text rel=\"nofollow\">";
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* bp_forums_add_forum_topic_to_page_title( $title )
|
93 |
+
*
|
94 |
+
* Append forum topic to page title
|
95 |
+
*
|
96 |
+
* @global object $bp
|
97 |
+
* @param string $title
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
function bp_forums_add_forum_topic_to_page_title( $title ) {
|
101 |
+
global $bp;
|
102 |
+
|
103 |
+
if ( $bp->current_action == 'forum' && $bp->action_variables[0] == 'topic' ) {
|
104 |
+
if ( bp_has_forum_topic_posts() ) {
|
105 |
+
$title .= ' | ' . bp_get_the_topic_title();
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
return $title;
|
110 |
+
}
|
111 |
+
add_filter( 'bp_page_title', 'bp_forums_add_forum_topic_to_page_title' );
|
112 |
+
|
113 |
+
?>
|
bp-forums/bp-forums-templatetags.php
CHANGED
@@ -1,1090 +1,1105 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class BP_Forums_Template_Forum {
|
4 |
-
var $current_topic = -1;
|
5 |
-
var $topic_count;
|
6 |
-
var $topics;
|
7 |
-
var $topic;
|
8 |
-
|
9 |
-
var $forum_id;
|
10 |
-
|
11 |
-
var $in_the_loop;
|
12 |
-
|
13 |
-
var $pag_page;
|
14 |
-
var $pag_num;
|
15 |
-
var $pag_links;
|
16 |
-
var $total_topic_count;
|
17 |
-
|
18 |
-
var $single_topic = false;
|
19 |
-
|
20 |
-
var $sort_by;
|
21 |
-
var $order;
|
22 |
-
|
23 |
-
function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
|
24 |
-
global $bp;
|
25 |
-
|
26 |
-
$this->pag_page
|
27 |
-
$this->pag_num
|
28 |
-
$this->type
|
29 |
-
$this->search_terms = $search_terms;
|
30 |
-
$this->forum_id
|
31 |
-
|
32 |
-
switch ( $type ) {
|
33 |
-
case 'newest': default:
|
34 |
-
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
35 |
-
break;
|
36 |
-
|
37 |
-
case 'popular':
|
38 |
-
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
39 |
-
break;
|
40 |
-
|
41 |
-
case 'unreplied':
|
42 |
-
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
43 |
-
break;
|
44 |
-
|
45 |
-
case 'tags':
|
46 |
-
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
47 |
-
break;
|
48 |
-
}
|
49 |
-
|
50 |
-
$this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
|
51 |
-
|
52 |
-
if ( !(int)$this->topics ) {
|
53 |
-
$this->topic_count
|
54 |
-
$this->total_topic_count = 0;
|
55 |
-
} else {
|
56 |
-
if ( $forum_id ) {
|
57 |
-
$topic_count = bp_forums_get_forum( $forum_id );
|
58 |
-
$topic_count = (int)$topic_count->topics;
|
59 |
-
} else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) {
|
60 |
-
$topic_count = (int)groups_total_public_forum_topic_count( $type );
|
61 |
-
} else {
|
62 |
-
$topic_count = count( $this->topics );
|
63 |
-
}
|
64 |
-
|
65 |
-
if ( !$max || $max >= $topic_count )
|
66 |
-
$this->total_topic_count = $topic_count;
|
67 |
-
else
|
68 |
-
$this->total_topic_count = (int)$max;
|
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 |
-
$this->
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
if ( $this->
|
131 |
-
|
132 |
-
}
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
$this->
|
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 |
-
$forum_id = $bp->groups->current_group->forum_id;
|
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 |
-
function
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
function
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
function
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
function
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
function
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
function
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
function
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
$
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
$
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
function
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
function
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
function
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
function
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
function
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
function
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
function
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
function
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
function
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
function
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
'length' => 10
|
514 |
-
);
|
515 |
-
|
516 |
-
$r = wp_parse_args( $args, $defaults );
|
517 |
-
extract( $r, EXTR_SKIP );
|
518 |
-
|
519 |
-
$post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
|
520 |
-
$post = bp_create_excerpt( $post->post_text, $length );
|
521 |
-
return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post );
|
522 |
-
}
|
523 |
-
|
524 |
-
function bp_the_topic_time_since_last_post() {
|
525 |
-
global $forum_template;
|
526 |
-
|
527 |
-
echo bp_get_the_topic_time_since_last_post();
|
528 |
-
}
|
529 |
-
function bp_get_the_topic_time_since_last_post() {
|
530 |
-
global $forum_template;
|
531 |
-
|
532 |
-
return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( strtotime( $forum_template->topic->topic_time ) ) );
|
533 |
-
}
|
534 |
-
|
535 |
-
function bp_the_topic_is_mine() {
|
536 |
-
echo bp_get_the_topic_is_mine();
|
537 |
-
}
|
538 |
-
function bp_get_the_topic_is_mine() {
|
539 |
-
global $bp, $forum_template;
|
540 |
-
|
541 |
-
return $bp->loggedin_user->id == $forum_template->topic->topic_poster;
|
542 |
-
}
|
543 |
-
|
544 |
-
function bp_the_topic_admin_links( $args = '' ) {
|
545 |
-
echo bp_get_the_topic_admin_links( $args );
|
546 |
-
}
|
547 |
-
function bp_get_the_topic_admin_links( $args = '' ) {
|
548 |
-
global $bp, $forum_template;
|
549 |
-
|
550 |
-
$defaults = array(
|
551 |
-
'seperator' => '|'
|
552 |
-
);
|
553 |
-
|
554 |
-
$r = wp_parse_args( $args, $defaults );
|
555 |
-
extract( $r, EXTR_SKIP );
|
556 |
-
|
557 |
-
$links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
|
558 |
-
|
559 |
-
if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
|
560 |
-
if ( 0 == (int)$forum_template->topic->topic_sticky )
|
561 |
-
$links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
|
562 |
-
else
|
563 |
-
$links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
|
564 |
-
|
565 |
-
if ( 0 == (int)$forum_template->topic->topic_open )
|
566 |
-
$links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
|
567 |
-
else
|
568 |
-
$links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
|
569 |
-
|
570 |
-
$links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete Topic', 'buddypress' ) . '</a>';
|
571 |
-
}
|
572 |
-
|
573 |
-
return implode( ' ' . $seperator . ' ', (array) $links );
|
574 |
-
}
|
575 |
-
|
576 |
-
function bp_the_topic_css_class() {
|
577 |
-
echo bp_get_the_topic_css_class();
|
578 |
-
}
|
579 |
-
|
580 |
-
function bp_get_the_topic_css_class() {
|
581 |
-
global $forum_template;
|
582 |
-
|
583 |
-
$class = false;
|
584 |
-
|
585 |
-
if ( $forum_template->current_topic % 2 == 1 )
|
586 |
-
$class .= 'alt';
|
587 |
-
|
588 |
-
if ( 1 == (int)$forum_template->topic->topic_sticky )
|
589 |
-
$class .= ' sticky';
|
590 |
-
|
591 |
-
if ( 0 == (int)$forum_template->topic->topic_open )
|
592 |
-
$class .= ' closed';
|
593 |
-
|
594 |
-
return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
|
595 |
-
}
|
596 |
-
|
597 |
-
function bp_my_forum_topics_link() {
|
598 |
-
echo bp_get_my_forum_topics_link();
|
599 |
-
}
|
600 |
-
function bp_get_my_forum_topics_link() {
|
601 |
-
global $bp;
|
602 |
-
|
603 |
-
return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' );
|
604 |
-
}
|
605 |
-
|
606 |
-
function bp_unreplied_forum_topics_link() {
|
607 |
-
echo bp_get_unreplied_forum_topics_link();
|
608 |
-
}
|
609 |
-
function bp_get_unreplied_forum_topics_link() {
|
610 |
-
global $bp;
|
611 |
-
|
612 |
-
return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' );
|
613 |
-
}
|
614 |
-
|
615 |
-
|
616 |
-
function bp_popular_forum_topics_link() {
|
617 |
-
echo bp_get_popular_forum_topics_link();
|
618 |
-
}
|
619 |
-
function bp_get_popular_forum_topics_link() {
|
620 |
-
global $bp;
|
621 |
-
|
622 |
-
return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' );
|
623 |
-
}
|
624 |
-
|
625 |
-
function bp_newest_forum_topics_link() {
|
626 |
-
echo bp_get_newest_forum_topics_link();
|
627 |
-
}
|
628 |
-
function bp_get_newest_forum_topics_link() {
|
629 |
-
global $bp;
|
630 |
-
|
631 |
-
return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' );
|
632 |
-
}
|
633 |
-
|
634 |
-
function bp_forum_topic_type() {
|
635 |
-
echo bp_get_forum_topic_type();
|
636 |
-
}
|
637 |
-
function bp_get_forum_topic_type() {
|
638 |
-
global $bp;
|
639 |
-
|
640 |
-
if ( !$bp->is_directory || !$bp->current_action )
|
641 |
-
return 'newest';
|
642 |
-
|
643 |
-
|
644 |
-
return apply_filters( 'bp_get_forum_topic_type', $bp->current_action );
|
645 |
-
}
|
646 |
-
|
647 |
-
function bp_forums_tag_name() {
|
648 |
-
echo bp_get_forums_tag_name();
|
649 |
-
}
|
650 |
-
function bp_get_forums_tag_name() {
|
651 |
-
global $bp;
|
652 |
-
|
653 |
-
if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
|
654 |
-
return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
|
655 |
-
}
|
656 |
-
|
657 |
-
function bp_forum_pagination() {
|
658 |
-
echo bp_get_forum_pagination();
|
659 |
-
}
|
660 |
-
function bp_get_forum_pagination() {
|
661 |
-
global $forum_template;
|
662 |
-
|
663 |
-
return apply_filters( 'bp_get_forum_pagination', $forum_template->pag_links );
|
664 |
-
}
|
665 |
-
|
666 |
-
function bp_forum_pagination_count() {
|
667 |
-
global $bp, $forum_template;
|
668 |
-
|
669 |
-
$start_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
|
670 |
-
$from_num = bp_core_number_format( $start_num );
|
671 |
-
$to_num = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) );
|
672 |
-
$total = bp_core_number_format( $forum_template->total_topic_count );
|
673 |
-
|
674 |
-
$pag_filter = false;
|
675 |
-
if ( 'tags' == $forum_template->type && !empty( $forum_template->search_terms ) )
|
676 |
-
$pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms );
|
677 |
-
|
678 |
-
echo apply_filters( 'bp_forum_pagination_count', sprintf( __( 'Viewing topic %1$s to %2$s (%3$s total topics%4$s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) );
|
679 |
-
?>
|
680 |
-
<span class="ajax-loader"></span>
|
681 |
-
<?php
|
682 |
-
}
|
683 |
-
|
684 |
-
function bp_is_edit_topic() {
|
685 |
-
global $bp;
|
686 |
-
|
687 |
-
if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) )
|
688 |
-
return false;
|
689 |
-
|
690 |
-
return true;
|
691 |
-
}
|
692 |
-
|
693 |
-
|
694 |
-
class BP_Forums_Template_Topic {
|
695 |
-
var $current_post = -1;
|
696 |
-
var $post_count;
|
697 |
-
var $posts;
|
698 |
-
var $post;
|
699 |
-
|
700 |
-
var $forum_id;
|
701 |
-
var $topic_id;
|
702 |
-
var $topic;
|
703 |
-
|
704 |
-
var $in_the_loop;
|
705 |
-
|
706 |
-
var $pag_page;
|
707 |
-
var $pag_num;
|
708 |
-
var $pag_links;
|
709 |
-
var $total_post_count;
|
710 |
-
|
711 |
-
var $single_post = false;
|
712 |
-
|
713 |
-
var $sort_by;
|
714 |
-
var $order;
|
715 |
-
|
716 |
-
function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {
|
717 |
-
global $bp, $current_user, $forum_template;
|
718 |
-
|
719 |
-
$this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
|
720 |
-
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
|
721 |
-
|
722 |
-
$this->topic_id = $topic_id;
|
723 |
-
$forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
|
724 |
-
$this->forum_id = $forum_template->topic->forum_id;
|
725 |
-
|
726 |
-
$this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
|
727 |
-
|
728 |
-
if ( !$this->posts ) {
|
729 |
-
$this->post_count = 0;
|
730 |
-
$this->total_post_count = 0;
|
731 |
-
} else {
|
732 |
-
if ( !$max || $max >= (int) $forum_template->topic->topic_posts )
|
733 |
-
$this->total_post_count = (int) $forum_template->topic->topic_posts;
|
734 |
-
else
|
735 |
-
$this->total_post_count = (int)$max;
|
736 |
-
|
737 |
-
if ( $max ) {
|
738 |
-
if ( $max >= count($this->posts) )
|
739 |
-
$this->post_count = count( $this->posts );
|
740 |
-
else
|
741 |
-
$this->post_count = (int)$max;
|
742 |
-
} else {
|
743 |
-
$this->post_count = count( $this->posts );
|
744 |
-
}
|
745 |
-
}
|
746 |
-
|
747 |
-
$this->pag_links = paginate_links( array(
|
748 |
-
'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => $this->pag_num ) ),
|
749 |
-
'format' => '',
|
750 |
-
'total' => ceil($this->total_post_count / $this->pag_num),
|
751 |
-
'current' => $this->pag_page,
|
752 |
-
'prev_text' => '←',
|
753 |
-
'next_text' => '→',
|
754 |
-
'mid_size' => 1
|
755 |
-
));
|
756 |
-
$this->pag->total_pages = ceil($this->total_post_count / $this->pag_num);
|
757 |
-
}
|
758 |
-
|
759 |
-
function has_posts() {
|
760 |
-
if ( $this->post_count )
|
761 |
-
return true;
|
762 |
-
|
763 |
-
return false;
|
764 |
-
}
|
765 |
-
|
766 |
-
function next_post() {
|
767 |
-
$this->current_post++;
|
768 |
-
$this->post = $this->posts[$this->current_post];
|
769 |
-
|
770 |
-
return $this->post;
|
771 |
-
}
|
772 |
-
|
773 |
-
function rewind_posts() {
|
774 |
-
$this->current_post = -1;
|
775 |
-
if ( $this->post_count > 0 ) {
|
776 |
-
$this->post = $this->posts[0];
|
777 |
-
}
|
778 |
-
}
|
779 |
-
|
780 |
-
function user_posts() {
|
781 |
-
if ( $this->current_post + 1 < $this->post_count ) {
|
782 |
-
return true;
|
783 |
-
} elseif ( $this->current_post + 1 == $this->post_count ) {
|
784 |
-
do_action('loop_end');
|
785 |
-
// Do some cleaning up after the loop
|
786 |
-
$this->rewind_posts();
|
787 |
-
}
|
788 |
-
|
789 |
-
$this->in_the_loop = false;
|
790 |
-
return false;
|
791 |
-
}
|
792 |
-
|
793 |
-
function the_post() {
|
794 |
-
global $post;
|
795 |
-
|
796 |
-
$this->in_the_loop = true;
|
797 |
-
$this->post = $this->next_post();
|
798 |
-
$this->post = (object)$this->post;
|
799 |
-
|
800 |
-
if ( $this->current_post == 0 ) // loop has just started
|
801 |
-
do_action('loop_start');
|
802 |
-
}
|
803 |
-
}
|
804 |
-
|
805 |
-
function bp_has_forum_topic_posts( $args = '' ) {
|
806 |
-
global $topic_template, $bp;
|
807 |
-
|
808 |
-
$defaults = array(
|
809 |
-
'topic_id' => false,
|
810 |
-
'per_page' => 15,
|
811 |
-
'max' => false
|
812 |
-
);
|
813 |
-
|
814 |
-
$r = wp_parse_args( $args, $defaults );
|
815 |
-
extract( $r, EXTR_SKIP );
|
816 |
-
|
817 |
-
if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
|
818 |
-
$topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );
|
819 |
-
|
820 |
-
if ( is_numeric( $topic_id ) ) {
|
821 |
-
$topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max );
|
822 |
-
|
823 |
-
// Current topic forum_id needs to match current_group forum_id
|
824 |
-
if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) )
|
825 |
-
return false;
|
826 |
-
|
827 |
-
} else {
|
828 |
-
return false;
|
829 |
-
}
|
830 |
-
|
831 |
-
return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
|
832 |
-
}
|
833 |
-
|
834 |
-
function bp_forum_topic_posts() {
|
835 |
-
global $topic_template;
|
836 |
-
return $topic_template->user_posts();
|
837 |
-
}
|
838 |
-
|
839 |
-
function bp_the_forum_topic_post() {
|
840 |
-
global $topic_template;
|
841 |
-
return $topic_template->the_post();
|
842 |
-
}
|
843 |
-
|
844 |
-
function bp_the_topic_post_id() {
|
845 |
-
echo bp_get_the_topic_post_id();
|
846 |
-
}
|
847 |
-
function bp_get_the_topic_post_id() {
|
848 |
-
global $topic_template;
|
849 |
-
|
850 |
-
return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id );
|
851 |
-
}
|
852 |
-
|
853 |
-
function bp_the_topic_post_content() {
|
854 |
-
echo bp_get_the_topic_post_content();
|
855 |
-
}
|
856 |
-
function bp_get_the_topic_post_content() {
|
857 |
-
global $topic_template;
|
858 |
-
|
859 |
-
return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) );
|
860 |
-
}
|
861 |
-
|
862 |
-
function bp_the_topic_post_css_class() {
|
863 |
-
echo bp_get_the_topic_post_css_class();
|
864 |
-
}
|
865 |
-
|
866 |
-
function bp_get_the_topic_post_css_class() {
|
867 |
-
global $topic_template;
|
868 |
-
|
869 |
-
$class = false;
|
870 |
-
|
871 |
-
if ( $topic_template->current_post % 2 == 1 )
|
872 |
-
$class .= 'alt';
|
873 |
-
|
874 |
-
if ( 1 == (int)$topic_template->post->post_status )
|
875 |
-
$class .= ' deleted';
|
876 |
-
|
877 |
-
if ( 0 == (int)$topic_template->post->post_status )
|
878 |
-
$class .= ' open';
|
879 |
-
|
880 |
-
return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
|
881 |
-
}
|
882 |
-
|
883 |
-
function bp_the_topic_post_poster_avatar( $args = '' ) {
|
884 |
-
echo bp_get_the_topic_post_poster_avatar( $args );
|
885 |
-
}
|
886 |
-
function bp_get_the_topic_post_poster_avatar( $args = '' ) {
|
887 |
-
global $topic_template;
|
888 |
-
|
889 |
-
$defaults = array(
|
890 |
-
'type' => 'thumb',
|
891 |
-
'width' => 20,
|
892 |
-
'height' => 20,
|
893 |
-
);
|
894 |
-
|
895 |
-
$r = wp_parse_args( $args, $defaults );
|
896 |
-
extract( $r, EXTR_SKIP );
|
897 |
-
|
898 |
-
return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
|
899 |
-
}
|
900 |
-
|
901 |
-
function bp_the_topic_post_poster_name() {
|
902 |
-
echo bp_get_the_topic_post_poster_name();
|
903 |
-
}
|
904 |
-
function bp_get_the_topic_post_poster_name() {
|
905 |
-
global $topic_template;
|
906 |
-
|
907 |
-
if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
|
908 |
-
return __( 'Deleted User', 'buddypress' );
|
909 |
-
|
910 |
-
return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . $link . '" title="' . $topic_template->post->poster_name . '">' . $topic_template->post->poster_name . '</a>' );
|
911 |
-
}
|
912 |
-
|
913 |
-
function bp_the_topic_post_poster_link() {
|
914 |
-
echo bp_get_the_topic_post_poster_link();
|
915 |
-
}
|
916 |
-
function bp_get_the_topic_post_poster_link() {
|
917 |
-
global $topic_template;
|
918 |
-
|
919 |
-
return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) );
|
920 |
-
}
|
921 |
-
|
922 |
-
function bp_the_topic_post_time_since() {
|
923 |
-
echo bp_get_the_topic_post_time_since();
|
924 |
-
}
|
925 |
-
function bp_get_the_topic_post_time_since() {
|
926 |
-
global $topic_template;
|
927 |
-
|
928 |
-
return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( strtotime( $topic_template->post->post_time ) ) );
|
929 |
-
}
|
930 |
-
|
931 |
-
function bp_the_topic_post_is_mine() {
|
932 |
-
echo bp_the_topic_post_is_mine();
|
933 |
-
}
|
934 |
-
function bp_get_the_topic_post_is_mine() {
|
935 |
-
global $bp, $topic_template;
|
936 |
-
|
937 |
-
return $bp->loggedin_user->id == $topic_template->post->poster_id;
|
938 |
-
}
|
939 |
-
|
940 |
-
function bp_the_topic_post_admin_links( $args = '' ) {
|
941 |
-
echo bp_get_the_topic_post_admin_links( $args );
|
942 |
-
}
|
943 |
-
function bp_get_the_topic_post_admin_links( $args = '' ) {
|
944 |
-
global $topic_template;
|
945 |
-
|
946 |
-
/* Never show for the first post in a topic. */
|
947 |
-
if ( 0 == $topic_template->current_post && $topic_template->pag_page == 1 )
|
948 |
-
return;
|
949 |
-
|
950 |
-
$defaults = array(
|
951 |
-
'seperator' => '|'
|
952 |
-
);
|
953 |
-
|
954 |
-
$r = wp_parse_args( $args, $defaults );
|
955 |
-
extract( $r, EXTR_SKIP );
|
956 |
-
|
957 |
-
if ( $_SERVER['QUERY_STRING'] )
|
958 |
-
$query_vars = '?' . $_SERVER['QUERY_STRING'];
|
959 |
-
|
960 |
-
$links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
|
961 |
-
$links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a> | ';
|
962 |
-
|
963 |
-
return $links;
|
964 |
-
}
|
965 |
-
|
966 |
-
function bp_the_topic_post_edit_text() {
|
967 |
-
echo bp_get_the_topic_post_edit_text();
|
968 |
-
}
|
969 |
-
function bp_get_the_topic_post_edit_text() {
|
970 |
-
global $bp;
|
971 |
-
|
972 |
-
$post = bp_forums_get_post( $bp->action_variables[4] );
|
973 |
-
return apply_filters( 'bp_get_the_topic_post_edit_text', attribute_escape( $post->post_text ) );
|
974 |
-
}
|
975 |
-
|
976 |
-
function bp_the_topic_pagination() {
|
977 |
-
echo bp_get_the_topic_pagination();
|
978 |
-
}
|
979 |
-
function bp_get_the_topic_pagination() {
|
980 |
-
global $topic_template;
|
981 |
-
|
982 |
-
return apply_filters( 'bp_get_the_topic_pagination', $topic_template->pag_links );
|
983 |
-
}
|
984 |
-
|
985 |
-
function bp_the_topic_pagination_count() {
|
986 |
-
global $bp, $topic_template;
|
987 |
-
|
988 |
-
$start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
|
989 |
-
$from_num = bp_core_number_format( $start_num );
|
990 |
-
$to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) );
|
991 |
-
$total = bp_core_number_format( $topic_template->total_post_count );
|
992 |
-
|
993 |
-
echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %1$s to %2$s (%3$s total posts)', 'buddypress' ), $from_num, $to_num, $total ) );
|
994 |
-
?>
|
995 |
-
<span class="ajax-loader"></span>
|
996 |
-
<?php
|
997 |
-
}
|
998 |
-
|
999 |
-
function bp_the_topic_is_last_page() {
|
1000 |
-
echo bp_get_the_topic_is_last_page();
|
1001 |
-
}
|
1002 |
-
function bp_get_the_topic_is_last_page() {
|
1003 |
-
global $topic_template;
|
1004 |
-
|
1005 |
-
return apply_filters( 'bp_get_the_topic_is_last_page', $topic_template->pag_page == $topic_template->pag->total_pages );
|
1006 |
-
}
|
1007 |
-
|
1008 |
-
function bp_directory_forums_search_form() {
|
1009 |
-
global $bp;
|
1010 |
-
|
1011 |
-
$search_value = __( 'Search anything...', 'buddypress' );
|
1012 |
-
if ( !empty( $_REQUEST['fs'] ) )
|
1013 |
-
$search_value = $_REQUEST['fs'];
|
1014 |
-
|
1015 |
-
?>
|
1016 |
-
<form action="" method="get" id="search-forums-form">
|
1017 |
-
<label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($search_value) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
|
1018 |
-
<input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
|
1019 |
-
</form>
|
1020 |
-
<?php
|
1021 |
-
}
|
1022 |
-
function bp_forum_permalink() {
|
1023 |
-
echo bp_get_forum_permalink();
|
1024 |
-
}
|
1025 |
-
function bp_get_forum_permalink() {
|
1026 |
-
global $bp;
|
1027 |
-
|
1028 |
-
if ( $bp->is_single_item )
|
1029 |
-
$permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
|
1030 |
-
else
|
1031 |
-
$permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
|
1032 |
-
|
1033 |
-
return apply_filters( 'bp_get_forum_permalink', $permalink . 'forum' );
|
1034 |
-
}
|
1035 |
-
|
1036 |
-
function bp_forum_directory_permalink() {
|
1037 |
-
echo bp_get_forum_directory_permalink();
|
1038 |
-
}
|
1039 |
-
function bp_get_forum_directory_permalink() {
|
1040 |
-
global $bp;
|
1041 |
-
|
1042 |
-
return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug );
|
1043 |
-
}
|
1044 |
-
|
1045 |
-
function bp_forums_tag_heat_map( $args = '' ) {
|
1046 |
-
$defaults = array(
|
1047 |
-
'smallest' => '10',
|
1048 |
-
'largest' => '42',
|
1049 |
-
'sizing' => 'px',
|
1050 |
-
'limit' => '50'
|
1051 |
-
);
|
1052 |
-
|
1053 |
-
$r = wp_parse_args( $args, $defaults );
|
1054 |
-
extract( $r, EXTR_SKIP );
|
1055 |
-
|
1056 |
-
bb_tag_heat_map( $smallest, $largest, $sizing, $limit );
|
1057 |
-
}
|
1058 |
-
|
1059 |
-
function bp_forum_action() {
|
1060 |
-
echo bp_get_forum_action();
|
1061 |
-
}
|
1062 |
-
function bp_get_forum_action() {
|
1063 |
-
global $topic_template;
|
1064 |
-
|
1065 |
-
return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
|
1066 |
-
}
|
1067 |
-
|
1068 |
-
function bp_forum_topic_action() {
|
1069 |
-
echo bp_get_forum_topic_action();
|
1070 |
-
}
|
1071 |
-
function bp_get_forum_topic_action() {
|
1072 |
-
global $bp;
|
1073 |
-
|
1074 |
-
return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
|
1075 |
-
}
|
1076 |
-
|
1077 |
-
function bp_forum_topic_count_for_user( $user_id = false ) {
|
1078 |
-
echo bp_get_forum_topic_count_for_user( $user_id );
|
1079 |
-
}
|
1080 |
-
function bp_get_forum_topic_count_for_user( $user_id = false ) {
|
1081 |
-
return apply_filters( 'bp_get_forum_topic_count_for_user', bp_forums_total_topic_count_for_user( $user_id ) );
|
1082 |
-
}
|
1083 |
-
|
1084 |
-
function bp_forum_topic_count( $user_id = false ) {
|
1085 |
-
echo bp_get_forum_topic_count( $user_id );
|
1086 |
-
}
|
1087 |
-
function bp_get_forum_topic_count( $user_id = false ) {
|
1088 |
-
return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) );
|
1089 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class BP_Forums_Template_Forum {
|
4 |
+
var $current_topic = -1;
|
5 |
+
var $topic_count;
|
6 |
+
var $topics;
|
7 |
+
var $topic;
|
8 |
+
|
9 |
+
var $forum_id;
|
10 |
+
|
11 |
+
var $in_the_loop;
|
12 |
+
|
13 |
+
var $pag_page;
|
14 |
+
var $pag_num;
|
15 |
+
var $pag_links;
|
16 |
+
var $total_topic_count;
|
17 |
+
|
18 |
+
var $single_topic = false;
|
19 |
+
|
20 |
+
var $sort_by;
|
21 |
+
var $order;
|
22 |
+
|
23 |
+
function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
|
24 |
+
global $bp;
|
25 |
+
|
26 |
+
$this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
|
27 |
+
$this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
|
28 |
+
$this->type = $type;
|
29 |
+
$this->search_terms = $search_terms;
|
30 |
+
$this->forum_id = $forum_id;
|
31 |
+
|
32 |
+
switch ( $type ) {
|
33 |
+
case 'newest': default:
|
34 |
+
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
35 |
+
break;
|
36 |
+
|
37 |
+
case 'popular':
|
38 |
+
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
39 |
+
break;
|
40 |
+
|
41 |
+
case 'unreplied':
|
42 |
+
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
43 |
+
break;
|
44 |
+
|
45 |
+
case 'tags':
|
46 |
+
$this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
|
47 |
+
break;
|
48 |
+
}
|
49 |
+
|
50 |
+
$this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
|
51 |
+
|
52 |
+
if ( !(int)$this->topics ) {
|
53 |
+
$this->topic_count = 0;
|
54 |
+
$this->total_topic_count = 0;
|
55 |
+
} else {
|
56 |
+
if ( $forum_id ) {
|
57 |
+
$topic_count = bp_forums_get_forum( $forum_id );
|
58 |
+
$topic_count = (int)$topic_count->topics;
|
59 |
+
} else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) {
|
60 |
+
$topic_count = (int)groups_total_public_forum_topic_count( $type );
|
61 |
+
} else {
|
62 |
+
$topic_count = count( $this->topics );
|
63 |
+
}
|
64 |
+
|
65 |
+
if ( !$max || $max >= $topic_count ) {
|
66 |
+
$this->total_topic_count = $topic_count;
|
67 |
+
} else {
|
68 |
+
$this->total_topic_count = (int)$max;
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( $max ) {
|
72 |
+
if ( $max >= count($this->topics) ) {
|
73 |
+
$this->topic_count = count( $this->topics );
|
74 |
+
} else {
|
75 |
+
$this->topic_count = (int)$max;
|
76 |
+
}
|
77 |
+
} else {
|
78 |
+
$this->topic_count = count( $this->topics );
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
$this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
|
83 |
+
$this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
|
84 |
+
|
85 |
+
if ( !$no_stickies ) {
|
86 |
+
// Place stickies at the top - not sure why bbPress doesn't do this?
|
87 |
+
foreach( (array)$this->topics as $topic ) {
|
88 |
+
if ( 1 == (int)$topic->topic_sticky ) {
|
89 |
+
$stickies[] = $topic;
|
90 |
+
} else {
|
91 |
+
$standard[] = $topic;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
$this->topics = array_merge( (array)$stickies, (array)$standard );
|
96 |
+
}
|
97 |
+
|
98 |
+
// Fetch extra information for topics, so we don't have to query inside the loop
|
99 |
+
$this->topics = bp_forums_get_topic_extras( &$this->topics );
|
100 |
+
|
101 |
+
if ( (int)$this->total_topic_count && (int)$this->pag_num ) {
|
102 |
+
$this->pag_links = paginate_links( array(
|
103 |
+
'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
|
104 |
+
'format' => '',
|
105 |
+
'total' => ceil( (int)$this->total_topic_count / (int)$this->pag_num),
|
106 |
+
'current' => $this->pag_page,
|
107 |
+
'prev_text' => '←',
|
108 |
+
'next_text' => '→',
|
109 |
+
'mid_size' => 1
|
110 |
+
) );
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
function has_topics() {
|
115 |
+
if ( $this->topic_count )
|
116 |
+
return true;
|
117 |
+
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
|
121 |
+
function next_topic() {
|
122 |
+
$this->current_topic++;
|
123 |
+
$this->topic = $this->topics[$this->current_topic];
|
124 |
+
|
125 |
+
return $this->topic;
|
126 |
+
}
|
127 |
+
|
128 |
+
function rewind_topics() {
|
129 |
+
$this->current_topic = -1;
|
130 |
+
if ( $this->topic_count > 0 ) {
|
131 |
+
$this->topic = $this->topics[0];
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
function user_topics() {
|
136 |
+
if ( $this->current_topic + 1 < $this->topic_count ) {
|
137 |
+
return true;
|
138 |
+
} elseif ( $this->current_topic + 1 == $this->topic_count ) {
|
139 |
+
do_action('loop_end');
|
140 |
+
// Do some cleaning up after the loop
|
141 |
+
$this->rewind_topics();
|
142 |
+
}
|
143 |
+
|
144 |
+
$this->in_the_loop = false;
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
|
148 |
+
function the_topic() {
|
149 |
+
global $topic;
|
150 |
+
|
151 |
+
$this->in_the_loop = true;
|
152 |
+
$this->topic = $this->next_topic();
|
153 |
+
$this->topic = (object)$this->topic;
|
154 |
+
|
155 |
+
if ( $this->current_topic == 0 ) // loop has just started
|
156 |
+
do_action('loop_start');
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
function bp_has_forum_topics( $args = '' ) {
|
161 |
+
global $forum_template, $bp;
|
162 |
+
|
163 |
+
/***
|
164 |
+
* Set the defaults based on the current page. Any of these will be overridden
|
165 |
+
* if arguments are directly passed into the loop. Custom plugins should always
|
166 |
+
* pass their parameters directly to the loop.
|
167 |
+
*/
|
168 |
+
$type = 'newest';
|
169 |
+
$user_id = false;
|
170 |
+
$forum_id = false;
|
171 |
+
$search_terms = false;
|
172 |
+
$no_stickies = 'all';
|
173 |
+
|
174 |
+
/* User filtering */
|
175 |
+
if ( !empty( $bp->displayed_user->id ) )
|
176 |
+
$user_id = $bp->displayed_user->id;
|
177 |
+
|
178 |
+
/* If we're in a single group, set this group's forum_id */
|
179 |
+
if ( !$forum_id && $bp->groups->current_group ) {
|
180 |
+
$bp->groups->current_group->forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
|
181 |
+
|
182 |
+
/* If it turns out there is no forum for this group, return false so we don't fetch all global topics */
|
183 |
+
if ( !$bp->groups->current_group->forum_id )
|
184 |
+
return false;
|
185 |
+
|
186 |
+
$forum_id = $bp->groups->current_group->forum_id;
|
187 |
+
}
|
188 |
+
|
189 |
+
/* If $_GET['fs'] is set, let's auto populate the search_terms var */
|
190 |
+
if ( $bp->is_directory && !empty( $_GET['fs'] ) )
|
191 |
+
$search_terms = $_GET['fs'];
|
192 |
+
|
193 |
+
/* Show stickies on a group forum */
|
194 |
+
if ( $bp->groups->current_group )
|
195 |
+
$no_stickies = null;
|
196 |
+
|
197 |
+
$defaults = array(
|
198 |
+
'type' => $type,
|
199 |
+
'forum_id' => $forum_id,
|
200 |
+
'user_id' => $user_id,
|
201 |
+
'page' => 1,
|
202 |
+
'per_page' => 20,
|
203 |
+
'max' => false,
|
204 |
+
'no_stickies' => $no_stickies,
|
205 |
+
'search_terms' => $search_terms
|
206 |
+
);
|
207 |
+
|
208 |
+
$r = wp_parse_args( $args, $defaults );
|
209 |
+
extract( $r );
|
210 |
+
|
211 |
+
/* If we're viewing a tag URL in the directory, let's override the type and set it to tags and the filter to the tag name */
|
212 |
+
if ( 'tag' == $bp->current_action && !empty( $bp->action_variables[0] ) ) {
|
213 |
+
$search_terms = $bp->action_variables[0];
|
214 |
+
$type = 'tags';
|
215 |
+
}
|
216 |
+
|
217 |
+
$forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
|
218 |
+
return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
|
219 |
+
}
|
220 |
+
|
221 |
+
function bp_forum_topics() {
|
222 |
+
global $forum_template;
|
223 |
+
return $forum_template->user_topics();
|
224 |
+
}
|
225 |
+
|
226 |
+
function bp_the_forum_topic() {
|
227 |
+
global $forum_template;
|
228 |
+
return $forum_template->the_topic();
|
229 |
+
}
|
230 |
+
|
231 |
+
function bp_the_topic_id() {
|
232 |
+
echo bp_get_the_topic_id();
|
233 |
+
}
|
234 |
+
function bp_get_the_topic_id() {
|
235 |
+
global $forum_template;
|
236 |
+
|
237 |
+
return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id );
|
238 |
+
}
|
239 |
+
|
240 |
+
function bp_the_topic_title() {
|
241 |
+
echo bp_get_the_topic_title();
|
242 |
+
}
|
243 |
+
function bp_get_the_topic_title() {
|
244 |
+
global $forum_template;
|
245 |
+
|
246 |
+
return apply_filters( 'bp_get_the_topic_title', stripslashes( $forum_template->topic->topic_title ) );
|
247 |
+
}
|
248 |
+
|
249 |
+
function bp_the_topic_slug() {
|
250 |
+
echo bp_get_the_topic_slug();
|
251 |
+
}
|
252 |
+
function bp_get_the_topic_slug() {
|
253 |
+
global $forum_template;
|
254 |
+
|
255 |
+
return apply_filters( 'bp_get_the_topic_slug', $forum_template->topic->topic_slug );
|
256 |
+
}
|
257 |
+
|
258 |
+
function bp_the_topic_text() {
|
259 |
+
echo bp_get_the_topic_text();
|
260 |
+
}
|
261 |
+
function bp_get_the_topic_text() {
|
262 |
+
global $forum_template;
|
263 |
+
|
264 |
+
$post = bb_get_first_post( (int)$forum_template->topic->topic_id, false );
|
265 |
+
return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) );
|
266 |
+
}
|
267 |
+
|
268 |
+
function bp_the_topic_poster_id() {
|
269 |
+
echo bp_get_the_topic_poster_id();
|
270 |
+
}
|
271 |
+
function bp_get_the_topic_poster_id() {
|
272 |
+
global $forum_template;
|
273 |
+
|
274 |
+
return apply_filters( 'bp_get_the_topic_poster_id', $forum_template->topic->topic_poster );
|
275 |
+
}
|
276 |
+
|
277 |
+
function bp_the_topic_poster_avatar( $args = '' ) {
|
278 |
+
echo bp_get_the_topic_poster_avatar( $args );
|
279 |
+
}
|
280 |
+
function bp_get_the_topic_poster_avatar( $args = '' ) {
|
281 |
+
global $forum_template;
|
282 |
+
|
283 |
+
$defaults = array(
|
284 |
+
'type' => 'thumb',
|
285 |
+
'width' => false,
|
286 |
+
'height' => false,
|
287 |
+
);
|
288 |
+
|
289 |
+
$r = wp_parse_args( $args, $defaults );
|
290 |
+
extract( $r, EXTR_SKIP );
|
291 |
+
|
292 |
+
return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
|
293 |
+
}
|
294 |
+
|
295 |
+
function bp_the_topic_poster_name() {
|
296 |
+
echo bp_get_the_topic_poster_name();
|
297 |
+
}
|
298 |
+
function bp_get_the_topic_poster_name() {
|
299 |
+
global $forum_template;
|
300 |
+
|
301 |
+
$poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
|
302 |
+
|
303 |
+
if ( !$name = bp_core_get_userlink( $poster_id ) )
|
304 |
+
return __( 'Deleted User', 'buddypress' );
|
305 |
+
|
306 |
+
return apply_filters( 'bp_get_the_topic_poster_name', $name );
|
307 |
+
}
|
308 |
+
|
309 |
+
function bp_the_topic_object_id() {
|
310 |
+
echo bp_get_the_topic_object_id();
|
311 |
+
}
|
312 |
+
function bp_get_the_topic_object_id() {
|
313 |
+
global $forum_template;
|
314 |
+
|
315 |
+
return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
|
316 |
+
}
|
317 |
+
|
318 |
+
function bp_the_topic_object_name() {
|
319 |
+
echo bp_get_the_topic_object_name();
|
320 |
+
}
|
321 |
+
function bp_get_the_topic_object_name() {
|
322 |
+
global $forum_template;
|
323 |
+
|
324 |
+
return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name );
|
325 |
+
}
|
326 |
+
|
327 |
+
function bp_the_topic_object_slug() {
|
328 |
+
echo bp_get_the_topic_object_slug();
|
329 |
+
}
|
330 |
+
function bp_get_the_topic_object_slug() {
|
331 |
+
global $forum_template;
|
332 |
+
|
333 |
+
return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
|
334 |
+
}
|
335 |
+
|
336 |
+
function bp_the_topic_object_permalink() {
|
337 |
+
echo bp_get_the_topic_object_permalink();
|
338 |
+
}
|
339 |
+
function bp_get_the_topic_object_permalink() {
|
340 |
+
global $bp, $forum_template;
|
341 |
+
|
342 |
+
/* Currently this will only work with group forums, extended support in the future */
|
343 |
+
return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/forum/' );
|
344 |
+
}
|
345 |
+
|
346 |
+
function bp_the_topic_last_poster_name() {
|
347 |
+
echo bp_get_the_topic_last_poster_name();
|
348 |
+
}
|
349 |
+
function bp_get_the_topic_last_poster_name() {
|
350 |
+
global $forum_template;
|
351 |
+
|
352 |
+
if ( !$domain = bp_core_get_user_domain( $forum_template->topic->topic_last_poster, $forum_template->topic->topic_last_poster_nicename, $forum_template->topic->topic_last_poster_login ) )
|
353 |
+
return __( 'Deleted User', 'buddypress' );
|
354 |
+
|
355 |
+
return apply_filters( 'bp_get_the_topic_last_poster_name', '<a href="' . $domain . '">' . $forum_template->topic->topic_last_poster_displayname . '</a>' );
|
356 |
+
}
|
357 |
+
|
358 |
+
function bp_the_topic_object_avatar( $args = '' ) {
|
359 |
+
echo bp_get_the_topic_object_avatar( $args );
|
360 |
+
}
|
361 |
+
function bp_get_the_topic_object_avatar( $args = '' ) {
|
362 |
+
global $forum_template;
|
363 |
+
|
364 |
+
$defaults = array(
|
365 |
+
'type' => 'thumb',
|
366 |
+
'width' => false,
|
367 |
+
'height' => false,
|
368 |
+
);
|
369 |
+
|
370 |
+
$r = wp_parse_args( $args, $defaults );
|
371 |
+
extract( $r, EXTR_SKIP );
|
372 |
+
|
373 |
+
return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) );
|
374 |
+
}
|
375 |
+
|
376 |
+
function bp_the_topic_last_poster_avatar( $args = '' ) {
|
377 |
+
echo bp_get_the_topic_last_poster_avatar( $args );
|
378 |
+
}
|
379 |
+
function bp_get_the_topic_last_poster_avatar( $args = '' ) {
|
380 |
+
global $forum_template;
|
381 |
+
|
382 |
+
$defaults = array(
|
383 |
+
'type' => 'thumb',
|
384 |
+
'width' => false,
|
385 |
+
'height' => false,
|
386 |
+
);
|
387 |
+
|
388 |
+
$r = wp_parse_args( $args, $defaults );
|
389 |
+
extract( $r, EXTR_SKIP );
|
390 |
+
|
391 |
+
return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
|
392 |
+
}
|
393 |
+
|
394 |
+
function bp_the_topic_start_time() {
|
395 |
+
echo bp_get_the_topic_start_time();
|
396 |
+
}
|
397 |
+
function bp_get_the_topic_start_time() {
|
398 |
+
global $forum_template;
|
399 |
+
|
400 |
+
return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time );
|
401 |
+
}
|
402 |
+
|
403 |
+
function bp_the_topic_time() {
|
404 |
+
echo bp_get_the_topic_time();
|
405 |
+
}
|
406 |
+
function bp_get_the_topic_time() {
|
407 |
+
global $forum_template;
|
408 |
+
|
409 |
+
return apply_filters( 'bp_get_the_topic_time', $forum_template->topic->topic_time );
|
410 |
+
}
|
411 |
+
|
412 |
+
function bp_the_topic_forum_id() {
|
413 |
+
echo bp_get_the_topic_forum_id();
|
414 |
+
}
|
415 |
+
function bp_get_the_topic_forum_id() {
|
416 |
+
global $forum_template;
|
417 |
+
|
418 |
+
return apply_filters( 'bp_get_the_topic_forum_id', $forum_template->topic->topic_forum_id );
|
419 |
+
}
|
420 |
+
|
421 |
+
function bp_the_topic_status() {
|
422 |
+
echo bp_get_the_topic_status();
|
423 |
+
}
|
424 |
+
function bp_get_the_topic_status() {
|
425 |
+
global $forum_template;
|
426 |
+
|
427 |
+
return apply_filters( 'bp_get_the_topic_status', $forum_template->topic->topic_status );
|
428 |
+
}
|
429 |
+
|
430 |
+
function bp_the_topic_is_topic_open() {
|
431 |
+
echo bp_get_the_topic_is_topic_open();
|
432 |
+
}
|
433 |
+
function bp_get_the_topic_is_topic_open() {
|
434 |
+
global $forum_template;
|
435 |
+
|
436 |
+
return apply_filters( 'bp_get_the_topic_is_topic_open', $forum_template->topic->topic_open );
|
437 |
+
}
|
438 |
+
|
439 |
+
function bp_the_topic_last_post_id() {
|
440 |
+
echo bp_get_the_topic_last_post_id();
|
441 |
+
}
|
442 |
+
function bp_get_the_topic_last_post_id() {
|
443 |
+
global $forum_template;
|
444 |
+
|
445 |
+
return apply_filters( 'bp_get_the_topic_last_post_id', $forum_template->topic->topic_last_post_id );
|
446 |
+
}
|
447 |
+
|
448 |
+
function bp_the_topic_is_sticky() {
|
449 |
+
echo bp_get_the_topic_is_sticky();
|
450 |
+
}
|
451 |
+
function bp_get_the_topic_is_sticky() {
|
452 |
+
global $forum_template;
|
453 |
+
|
454 |
+
return apply_filters( 'bp_get_the_topic_is_sticky', $forum_template->topic->topic_sticky );
|
455 |
+
}
|
456 |
+
|
457 |
+
function bp_the_topic_total_post_count() {
|
458 |
+
echo bp_get_the_topic_total_post_count();
|
459 |
+
}
|
460 |
+
function bp_get_the_topic_total_post_count() {
|
461 |
+
global $forum_template;
|
462 |
+
|
463 |
+
if ( $forum_template->topic->topic_posts == 1 )
|
464 |
+
return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d post', 'buddypress' ), $forum_template->topic->topic_posts ) );
|
465 |
+
else
|
466 |
+
return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );
|
467 |
+
}
|
468 |
+
|
469 |
+
function bp_the_topic_total_posts() {
|
470 |
+
echo bp_get_the_topic_total_posts();
|
471 |
+
}
|
472 |
+
function bp_get_the_topic_total_posts() {
|
473 |
+
global $forum_template;
|
474 |
+
|
475 |
+
return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
|
476 |
+
}
|
477 |
+
|
478 |
+
function bp_the_topic_tag_count() {
|
479 |
+
echo bp_get_the_topic_tag_count();
|
480 |
+
}
|
481 |
+
function bp_get_the_topic_tag_count() {
|
482 |
+
global $forum_template;
|
483 |
+
|
484 |
+
return apply_filters( 'bp_get_the_topic_tag_count', $forum_template->topic->tag_count );
|
485 |
+
}
|
486 |
+
|
487 |
+
function bp_the_topic_permalink() {
|
488 |
+
echo bp_get_the_topic_permalink();
|
489 |
+
}
|
490 |
+
function bp_get_the_topic_permalink() {
|
491 |
+
global $forum_template, $bp;
|
492 |
+
|
493 |
+
if ( $forum_template->topic->object_slug )
|
494 |
+
$permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/';
|
495 |
+
else if ( $bp->is_single_item )
|
496 |
+
$permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
|
497 |
+
else
|
498 |
+
$permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/';
|
499 |
+
|
500 |
+
return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' );
|
501 |
+
}
|
502 |
+
|
503 |
+
function bp_the_topic_time_since_created() {
|
504 |
+
echo bp_get_the_topic_time_since_created();
|
505 |
+
}
|
506 |
+
function bp_get_the_topic_time_since_created() {
|
507 |
+
global $forum_template;
|
508 |
+
|
509 |
+
return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) );
|
510 |
+
}
|
511 |
+
|
512 |
+
func
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|