-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
2658 lines (2438 loc) · 141 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
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
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
<?php //Opening PHP tag
// Add reporting for missing image assets.
// Requires jQuery and Rollbar to be set, otherwise logs to console.
//
// This only works after the initial page load, not for images that are
// added to the page later dynamically.
function report_missing_image_assets() {
echo '<script type="text/javascript">
function report(messageText, data) {
if (window.Rollbar) {
window.Rollbar.error(messageText, data)
} else {
console.warn(messageText, data);
}
}
function reportFailedLoad(e) {
report("Detected that image failed to load: " + e.src);
}
// Defer checking, to allow the page to load.
//
// Report errors on images that have already failed to load,
// and listen for errors on images that are still loading.
function reportImageLoadFailures() {
setTimeout(function() {
window.jQuery("img").toArray().forEach(function(el) {
if (el.naturalWidth === 0 && el.naturalHeight === 0) {
report("Found image that failed to load: " + el.src, { src: el.src });
} else {
window.jQuery(el).on("error", reportFailedLoad);
}
});
}, 10000);
}
// reportImageLoadFailures();
</script>';
}
add_action('wp_head', 'report_missing_image_assets' );
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
// Colin's changes
/*
if( !function_exists('dwqa_wp_knowledge_base_scripts') ){
function dwqa_wp_knowledge_base_scripts(){
wp_enqueue_style( 'dw-wp-knowledge-base-qa', get_stylesheet_directory_uri() . '/dwqa-templates/style.css' );
}
add_action( 'wp_enqueue_scripts', 'dwqa_wp_knowledge_base_scripts' );
}
*/
function kbc_forum_folder_desc() {
$content = bbp_get_forum_content();
if($content != '') {
echo '<div id="desc-box">';
echo $content;
echo '</div>';
}
}
add_action('bbp_template_before_single_forum', 'kbc_forum_folder_desc');
function kbc_bp_groups_message() {
$descTxt = "Join an existing group or create a new group to participate in group discussions. Groups administrators have control over who can join and participate in the Groups forums.";
// wp-content/plugins/buddypress/bp-groups/bp-groups-template.php
// wp-content/plugins/buddypress/bp-core/bp-core-filters.php
$workinggroupcreationbutton = bp_get_button(array(
'id' => 'create_working_group',
'component' => 'groups',
'link_text' => __( 'Sign up for a Working Group', 'buddypress' ),
'link_title' => __( 'Sign up for a Working Group', 'buddypress' ),
'link_class' => 'button group-create bp-title-button',
'link_href' => trailingslashit( bp_get_root_domain() ) . "working-group-signup-survey/",
'wrapper' => false,
)
);
echo '<div id="desc-box">' . $descTxt . '</div>';
}
add_action('bp_before_directory_groups_content', 'kbc_bp_groups_message', 1);
function kbc_bp_members_message() {
$descTxt = "Find and connect with members who are using these forums.";
echo '<div id="desc-box">' . $descTxt . '</div>';
}
add_action('bp_before_directory_members_page', 'kbc_bp_members_message', 1);
function kbc_remove_feature_requests()
{
remove_action('bbp_template_before_topics_loop', 'dtbaker_vote_bbp_template_before_topics_loop');
}
add_action('after_setup_theme', 'kbc_remove_feature_requests');
function kbc_edx_login_redirect() {
if(!strpos($_SERVER["REQUEST_URI"], 'admin-login')) {
//http://stackoverflow.com/questions/7921229/how-do-i-read-values-from-wp-config-php
// The edX url is set in the config file wp-config-basics.php
header("Location: ".MY_EDX_URL);
exit;
}
}
add_action('login_enqueue_scripts', 'kbc_edx_login_redirect');
/* Fix issue with Support Forums plugin
* - can only see subscriptions to topics you start
*/
function kbc_remove_author_lock() {
remove_filter('bbp_has_topics_query','bbps_lock_to_author');
}
add_action('bbp_template_before_user_subscriptions', 'kbc_remove_author_lock');
function kbc_re_add_author_lock() {
add_filter('bbp_has_topics_query','bbps_lock_to_author');
}
add_action('bbp_template_after_user_subscriptions', 'kbc_re_add_author_lock');
/* Remove forced sorting by votes on voting forums, to allow also sorting by date or replies */
remove_filter('bbp_after_has_topics_parse_args','bbps_filter_bbp_after_has_topics_parse_args',10);
/* If the list of topics is sorted, make sure the paginated links keep it sorted */
function kbc_pagination_links ($links) {
$order_index = strpos($_SERVER['REQUEST_URI'], '?order');
if($order_index !== false) {
$uri_query = substr($_SERVER['REQUEST_URI'], $order_index);
return $links.$uri_query;
} else {
return $links;
}
}
add_filter('paginate_links', 'kbc_pagination_links', 100, 1);
// End Colin's changes
// Taken from http://wordpress.stackexchange.com/questions/74742/how-to-set-different-cookies-for-logged-in-admin-users-and-logge$
function set_admin_specific_cookie($user_login, $user, $userroles=NULL){
// http://wordpress.stackexchange.com/questions/43528/how-to-get-a-buddypress-user-profile-link-and-a-certain-user-profile-field-for-t
setcookie('uname',$user->user_login,0,'/');
// $userroles gets passed in from LTI because $user->roles is often not set yet when this function is called from LTI.
// $user->roles is properly set when this function is called from admin-login
$my_uroles = $userroles;
if(is_null($my_uroles)){
$my_uroles = $user->roles;
}
if(user_can($user,'administrator')||(array_key_exists('administrator',$my_uroles))||(lti_site_admin())||(array_key_exists('bbp_moderator',$my_uroles))||(array_key_exists('bbp_keymaster',$my_uroles))||(array_key_exists('bbp_blocked',$my_uroles))){
// error_log("oritgigo admin or bbp moderator");
if(!isset($_COOKIE['disable_my_cache'])){
// error_log("oritgigo empty cookie");
setcookie('disable_my_cache',1,0,'/');
}
} else {
// If the user is not an admin and the disable_my_cache cookie is there, remove it!
if(isset($_COOKIE['disable_my_cache'])){
// error_log("The user is not an admin, oritgigo clear existing cookie: disable_my_cache ".is_admin());
setcookie('disable_my_cache',0, time()-3600,'/');
unset($_COOKIE['disable_my_cache']);
}
}
}
function clear_admin_specific_cookie(){
// error_log("oritgigo clear cache cookie");
if(isset($_COOKIE['uname'])){
setcookie('uname',$user->ID,time()-3600,'/');
unset($_COOKIE['uname']);
}
if(isset($_COOKIE['disable_my_cache'])){
error_log("oritgigo clear existing cookie");
//http://www.w3schools.com/php/php_cookies.asp
setcookie('disable_my_cache',0, time()-3600,'/');
unset($_COOKIE['disable_my_cache']);
}
}
//function set_bpdomain_cookie(){
// error_log("domain:".bp_loggedin_user_domain( '/' ));
//}
// error_log("oritgigo here");
// see http://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
// the last two arguments (10 and 2) enable set_admin_specific_cookie to get the use arguments
add_action('wp_login', 'set_admin_specific_cookie', 10,2);
add_action('wp_og_LTI_login', 'set_admin_specific_cookie', 10,3);
add_action('wp_logout', 'clear_admin_specific_cookie');
//add_action('bp_loaded', 'set_bpdomain_cookie');
function my_disable_page_cache($mypageurl){
setrawcookie('disable_my_page_cache',$mypageurl, time()+65, $mypageurl);
}
function my_reply_update_handler(){
//error_log("og reply id:".$_POST['bbp_reply_id']);
//error_log("og redirect:".bbp_get_redirect_to());
error_log("page uri:".$_SERVER['REQUEST_URI']);
//$myreplyid = (int) $_POST['bbp_reply_id'];
//$myredirect = bbp_get_redirect_to();
//$myreplyurl = bbp_get_reply_url($myreplyid,$myredirect);
//$myreplyurlpart=preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",$myreplyurl));
//error_log("og reply url:".home_url());
//error_log("og reply uri:".$myreplyurlpart);
//if(!isset($_COOKIE['disable_my_page_cache'])){
//setrawcookie('disable_my_page_cache',$_SERVER['REQUEST_URI'], time()+180);
// Temporarily (until the cache times out) disable the cache for this page for this user,
// since they just poste and we want them to be able to see their posts.
my_disable_page_cache($_SERVER['REQUEST_URI']);
error_log("page uri:".$_SERVER['REQUEST_URI']);
//}
}
function my_reply_edit_handler(){
//error_log("og reply id:".$_POST['bbp_reply_id']);
//error_log("og redirect:".bbp_get_redirect_to());
//error_log("page uri:".$_SERVER['REQUEST_URI']);
// Edit replies do not have the url that we don't want to cache (unlike new posts).
// In order to disable the cache for the editing user for this topic, we need to obtain
// its url
// Get the post id
$myreplyid = (int) $_POST['bbp_reply_id'];
// Get the full redirect url
$myredirect = bbp_get_redirect_to();
$myreplyurl = bbp_get_reply_url($myreplyid,$myredirect);
// Get rid of the extras (such as the domain name and the #post123)
$myreplyurlpart=trim(preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",$myreplyurl)));
//error_log("og reply url:".home_url());
error_log("og reply uri:".$myreplyurlpart);
my_disable_page_cache($myreplyurlpart);
error_log("og reply uri:".$myreplyurlpart);
}
function my_new_topic_handler(){
//error_log("og reply id:".$_POST['bbp_reply_id']);
//error_log("og redirect:".bbp_get_redirect_to());
error_log("page uri:".$_SERVER['REQUEST_URI']);
//$myreplyid = (int) $_POST['bbp_reply_id'];
//$myredirect = bbp_get_redirect_to();
//$myreplyurl = bbp_get_reply_url($myreplyid,$myredirect);
//$myreplyurlpart=preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",$myreplyurl));
//error_log("og reply url:".home_url());
//error_log("og reply uri:".$myreplyurlpart);
//if(!isset($_COOKIE['disable_my_page_cache'])){
//setrawcookie('disable_my_page_cache',$_SERVER['REQUEST_URI'], time()+180);
// Temporarily (until the cache times out) disable the cache for this page for this user,
// since they just poste and we want them to be able to see their posts.
my_disable_page_cache($_SERVER['REQUEST_URI']);
error_log("page uri:".$_SERVER['REQUEST_URI']);
//}
}
function my_topic_edit_handler(){
//error_log("og reply id:".$_POST['bbp_reply_id']);
//error_log("og redirect:".bbp_get_redirect_to());
//error_log("page uri:".$_SERVER['REQUEST_URI']);
// Edit replies do not have the url that we don't want to cache (unlike new posts).
// In order to disable the cache for the editing user for this topic, we need to obtain
// its url
// Get the post id
$mytopicid = (int) $_POST['bbp_topic_id'];
// Get the full redirect url
$myredirect = bbp_get_redirect_to();
$myreplyurl = bbp_get_topic_permalink($mytopicid);
$myforumid = bbp_get_topic_forum_id($mytopicid);
error_log("topic url: ".$myreplyurl." og topic id: ".$_POST['bbp_topic_id']." og forumid: ".$myforumid);
// Get rid of the extras (such as the domain name and the #post123)
$myreplyurlpart=trim(preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",$myreplyurl)));
$myforumurl = bbp_get_forum_permalink($myforumid);
$myforumurlpart=trim(preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",$myforumurl)));
//error_log("og reply url:".home_url());
// Don't cache the topic so that the user can see their updated content and title
error_log("og topic uri:".$myreplyurlpart);
my_disable_page_cache($myreplyurlpart);
error_log("og topic uri:".$myreplyurlpart);
error_log("og forum uri:".$myforumurlpart);
// Don't cache the forum so that the user can see their updated title
my_disable_page_cache($myreplyurlpart);
}
// Create a cookie when the user posts a reply. This is done in order to prevent the cache from getting a cached version of the page for this specific user.
add_action('bbp_edit_reply', 'my_reply_edit_handler');
add_action('bbp_new_reply', 'my_reply_update_handler');
add_action('bbp_new_topic', 'my_new_topic_handler');
add_action('bbp_edit_topic', 'my_topic_edit_handler');
function my_group_creation_handler(){
// Create a cookie that will tell varnish not to cache the group directory for this user for the next x minutes, so the user can see the group they just created.
// error_log("group url:".bp_get_groups_directory_permalink());
$mygroupdir = trim(preg_replace("/([^\/]+$)/","",preg_replace("/^https?:\/\/[^\/]+(\/*.+\/).*/", " $1 ",bp_get_groups_directory_permalink())));
// error_log("group uri:".$mygroupdir);
setrawcookie('disable_my_page_cache',$mygroupdir, time()+65, $mygroupdir);
}
add_action('groups_group_create_complete', 'my_group_creation_handler');
// Parent override
// For more information see http://www.paulund.co.uk/override-parent-theme-functions
function ipt_kb_bbp_forum_freshness_in_list( $forum_id = 0 ) {
$og_forum_last_topic_id = bbp_get_forum_last_topic_id($forum_id);
$og_last_topic_id = bbp_get_topic_last_active_id($og_forum_last_topic_id);
$author_link = bbp_get_author_link( array(
'post_id' => $og_last_topic_id,
'type' => 'name'
) );
$freshness = bbp_get_author_link( array( 'post_id' => $og_last_topic_id, 'size' => 32, 'type' => 'avatar' ) );
?>
<?php if ( ! empty( $freshness ) ) : ?>
<span class="pull-left thumbnail">
<?php echo $freshness; ?>
</span>
<?php endif; ?>
<?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?>
<ul class="list-unstyled ipt_kb_forum_freshness_meta">
<li class="bbp-topic-freshness-link"><?php echo bbp_topic_freshness_link($og_forum_last_topic_id); ?> </li>
<li class="bbp-topic-freshness-author">
<?php do_action( 'bbp_theme_before_topic_author' ); ?>
<?php if ( ! empty( $author_link ) ) printf( __( 'by %s', 'ipt_kb' ), $author_link ); ?>
<?php do_action( 'bbp_theme_after_topic_author' ); ?>
</li>
</ul>
<?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?>
<?php
}
// https://buddypress.org/support/topic/removing-menus-not-working-in-buddypress-1-5-help-please/
//function ja_remove_navigation_tabs() {
// global $bp;
// //remove_action('groups_custom_create_steps', array( $this, 'maybe_create_screen' ));
// $bp->groups->group_creation_steps['forum']=null;
//bp_core_remove_subnav_item(buddypress()->groups->group_creation_steps->slug,'forum');
// bp_core_remove_subnav_item( $bp->groups->slug, 'forum' );
//}
//add_action( 'groups_custom_create_steps', 'ja_remove_navigation_tabs', 25 );
// When the group has a forum, set the group page's default tab to 'forum'. For groups that don't have a forum, the 'home' tab will be the default.
// Some of this code was copied from https://buddypress.org/support/topic/bp_groups_default_extension/
function bbg_set_group_default_extension( $ext ) {
global $bp;
// error_log("og extension".print_r($ext,true));
// error_log("og extension2".print_r($bp->groups->current_group,true));
// error_log("og extension3".print_r($bp->active_components,true)." test");
//if ( $bp->groups->current_group->enable_forum && bp_is_active( 'forums' ) ){
// Mystery: based on bp_is_active, forums are disabled, but the group menu is still displayed
if ( $bp->groups->current_group->enable_forum){
// error_log("og extension forums");
return 'forum';
}
else{
return $ext;
}
}
add_filter( 'bp_groups_default_extension', 'bbg_set_group_default_extension' );
# Breadcrumbs
# This function channges the "Forums" breadcrumb link for non admin users in order to avoid confusion. When a non-admin user sees a link named "forums", they assume that it
# points to the root of the forums (the home page). The default "Forums" breadcrumb points to another page that lists all the forums. This page is very useful for admins,
# but it generally confuses non-admin users. As a result, we decided to make this page available for admins only and have non-admin users go to the homepage instead.
# For more info about editing breadcrubs see https://bbpress.org/forums/topic/how-do-i-remove-first-two-parts-of-breadcrumb/
# and https://bbpress.org/forums/topic/how-do-i-edit-bbpress-breadcrumbs/
function my_filter_breadcrumbs($my_curret_crumbs){
//error_log("og crumbs ".print_r($my_curret_crumbs,true));
# Admins get the default forum page when clicking the "forum" breadcrub
if(isset($_COOKIE['disable_my_cache'])){
return $my_curret_crumbs;
} # Non admins get the home page when clicking the "forum" breadcrub
else{
$my_breadcrumbhome = "/(.*a href=\")(.*)(\".*class=\"bbp-breadcrumb-home\".*)/";
$my_breadcrumbroot = "/(.*a href=\")(.*)(\".*class=\"bbp-breadcrumb-root\".*)/";
$my_breadcrumbhomeurl = "";
for($i=0;$i<count($my_curret_crumbs);$i++){
$my_breadcrumbhomematches = array();
if(preg_match($my_breadcrumbhome,$my_curret_crumbs[$i],$my_breadcrumbhomematches)){
if(count($my_breadcrumbhomematches>3)){
$my_breadcrumbhomeurl = $my_breadcrumbhomematches[2];
//error_log("og breadcrumbs found ".$my_breadcrumbhomeurl);
}
}
}
for($i=0;$i<count($my_curret_crumbs);$i++){
$my_breadcrumbrootmatches = array();
if(preg_match($my_breadcrumbroot,$my_curret_crumbs[$i],$my_breadcrumbrootmatches)){
if(count($my_breadcrumbhomematches>4)){
$my_curret_crumbs[$i] = $my_breadcrumbrootmatches[1].$my_breadcrumbhomeurl.$my_breadcrumbrootmatches[3];
//error_log("og breadcrumbs ".$my_breadcrumbrootmatches[3].", ".$my_breadcrumbhomeurl.", ".$my_breadcrumbrootmatches[3]);
}
}
}
}
return $my_curret_crumbs;
}
add_filter('bbp_breadcrumbs', 'my_filter_breadcrumbs');
/////////////// Group sorting
// How to add a sort option:
// 1. Add an option to the group directory's sort drop down. You can use the actions bp_groups_directory_order_options and bp_member_group_order_options to do this.
// The functions og_num_posts_option and og_rank_option add sort options to the sort drop down. You can use these two examples as a guide.
// 2. Add your sort/metadata type to the $og_my_curr_types list in og_my_order_by_number_of_posts. This will work only if your meta type is numeric. If your meta type is not numeric,
// you'll have to add your own SQL code to og_my_order_by_number_of_posts.
// 3. Update your metadata type when needed, using some action or filter (e.g. in og_groups_update_num_posts_and_rank_options, right before an activity occurs)
// Taken from https://codex.buddypress.org/plugindev/group-meta-queries-usage-example/#filter-bp_ajax_querystring-to-eventually-extend-the-groups-query
// The code below adds the new sort options to the sort box
// Number of posts
// Add the number of posts option to the sort drop down list
function og_num_posts_option() {
?>
<option value="og_num_posts"><?php _e( 'Number of Posts' ); ?></option>
<?php
}
/* finally you create your options in the different select boxes */
// you need to do it for the Groups directory
add_action( 'bp_groups_directory_order_options', 'og_num_posts_option' );
// and for the groups tab of the user's profile
add_action( 'bp_member_group_order_options', 'og_num_posts_option' );
// Rank
// Add the rank option to the sort drop down list
function og_rank_option() {
?>
<option value="og_rank"><?php _e( 'Rank' ); ?></option>
<?php
}
/* finally you create your options in the different select boxes */
// you need to do it for the Groups directory
add_action( 'bp_groups_directory_order_options', 'og_rank_option' );
// and for the groups tab of the user's profile
add_action( 'bp_member_group_order_options', 'og_rank_option' );
// Additional sort options
// Currently none
// Code that updates and sorts the rank and number of posts
// Taken from wp-content/plugins/buddypress/bp-groups/bp-groups-activity.php
// Update the group's rank and number of posts right before a group activity gets recorded
// Taken from wp-content/plugins/bbpress/includes/extend/buddypress/groups.php map_activity_to_group and wp-content/plugins/buddypress/bp-groups/bp-groups-activity.php
function og_groups_update_num_posts_and_rank_options($args = array() ){
// wp-content/plugins/buddypress/bp-groups/bp-groups-forums.php
//error_log("og group post count here ".print_r($args,true));
//echo "og here";
$group_id = 0;
$og_my_postcount = 0;
//error_log("og group post count here");
$group = groups_get_current_group();
//Taken from wp-content/plugins/bbpress/includes/extend/buddypress/groups.php
// Not posting from a BuddyPress group? stop now!
if ( !empty( $group ) ) {
$group_id = $group->id; //bp_get_current_group_id(); //$bp->groups->current_group->id;
error_log("og group post count id ".$group_id);
}
else{
return $args;
}
//Taken from wp-content/plugins/bbpress/includes/extend/buddypress/groups.php
$my_forum_ids = bbp_get_group_forum_ids( $my_group_id );
$forum_id = null;
// Get the first forum ID
if ( !empty( $my_forum_ids ) ) {
$forum_id = (int) is_array( $my_forum_ids ) ? $my_forum_ids[0] : $my_forum_ids;
$og_my_postcount = bbp_show_lead_topic() ? bbp_get_forum_reply_count($forum_id) : bbp_get_forum_post_count($forum_id);
}
// Update the group's post count
//error_log("og group post count ".$og_my_postcount);
groups_update_groupmeta( $group_id, 'og_num_posts', $og_my_postcount );
// Taken from p-content/plugins/buddypress/bp-groups/bp-groups-forums.php
// Update the group's rank, based on its previous rank
$og_rank_arg = 'og_rank';
// Get the previous rank
$og_prev_grp_rank = groups_get_groupmeta($group_id, $og_rank_arg);
//error_log("og group post rank ".empty($og_prev_grp_rank));
// If the rank doesn't exist yet, make it 0
if(empty($og_prev_grp_rank==null)){
$og_prev_grp_rank = 0;
}
// Update the rank as follows: rank = .7*prev rank + .3*current unix time
// groups_update_groupmeta .5*og_rank+.5*lastactivitytimeinunix
groups_update_groupmeta($group_id, $og_rank_arg, .7*$og_prev_grp_rank + .3*microtime(true));
return $args;
}
add_filter( 'bbp_before_record_activity_parse_args', 'og_groups_update_num_posts_and_rank_options' );
// Sort by rank or number of posts by modifying the SQL query
// Taken from https://codex.buddypress.org/plugindev/add-custom-filters-to-loops-and-enjoy-them-within-your-plugin/ and wp-content/plugins/buddypress/bp-groups/bp-groups-classes.php and from the actual sort values
function og_my_order_by_number_of_posts( $sql = '', $sql_arr = '',$args){
//error_log("og og_my_order_by_most_favorited ".$sql.": ".print_r($sql_arr,true).": ".print_r($args,true));
// If the curret sort type matches one of the items in the list, we sort by this type
$og_my_curr_types = array("og_num_posts","og_rank"); // You can add your own numeric meta type to this list. If your meta type is not numeric you'll have to add your own SQL code to the code below.
if(in_array($args["type"],$og_my_curr_types)){
$og_my_curr_type = "";
$og_idx = array_search($args["type"],$og_my_curr_types);
$og_my_curr_type = $og_my_curr_types[$og_idx];
// We need to change the SQL query to include our new meta types (otherwise it'll only include total_member_count and last_activity)
// The original SQL query looks like this:
// SELECT DISTINCT g.id, g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity
// FROM wp_bp_groups_groupmeta gm1, wp_bp_groups_groupmeta gm2, wp_bp_groups_members m, wp_bp_groups g
// WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'
// AND m.user_id = 90 AND m.is_confirmed = 1 AND m.is_banned = 0
// ORDER BY last_activity DESC
// LIMIT 0, 20
// gm1 is used to obtain the total member count and gm2 is used to get the last activity.
// Here we add a 3rd gm from table from which we get the meta value of our meta type (rank or number of posts). We also make sure to add it
// to the where clause, to select it and to order by it.
$sql_arr["select"]=$sql_arr["select"].", cast(gm3.meta_value as unsigned) AS ".$og_my_curr_type;
$sql_arr["from"]=$sql_arr["from"]." wp_bp_groups_groupmeta gm3,";
$sql_arr["where"]=$sql_arr["where"]." AND gm3.meta_key = '".$og_my_curr_type."'"." AND g.id = gm3.group_id";
$sql_arr[0]="ORDER BY ".$og_my_curr_type." DESC";
//error_log("og og_my_order_by_most_favorited sql:".join( ' ', (array) $sql_arr ));
return join( ' ', (array) $sql_arr );
}
else{
return $sql;
}
}
add_filter( 'bp_groups_get_paged_groups_sql', 'og_my_order_by_number_of_posts' , 10, 6 );
// Forum - specific search:
///////////////////////////
// Taken from http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress
//
// Additional resources:
// https://bbpress.org/forums/topic/forum-search-inside-buddypress-group/
// https://wordpress.org/support/topic/meta_query-does-not-filter-at-all
//https://wordpress.org/support/topic/meta_query-does-not-filter-at-all
// http://codex.bbpress.org/bbp_list_forums/
// https://bbpress.org/forums/topic/how-to-display-list-of-sub-forums-on-separate-lines-instead-of-big-blob/
///////////////////////////////////////////////////////////////////////////////////////
function my_bbp_search_form(){
/*?>
<div class="bbp-search-form">
<?php bbp_get_template_part( 'form', 'search' ); ?>
</div>
<?php */
}
add_action( 'bbp_template_before_single_forum', 'my_bbp_search_form' );
/*
* Search only a specific forum
* Taken from http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress
*/
function my_bbp_filter_search_results( $r ){
//error_log("og my_bbp_filter_search_results ".print_r($r, true));
//Get the submitted forum ID (from the hidden field added in step 2)
$forum_id = sanitize_title_for_query( $_GET['bbp_search_forum_id'] );
if(!$forum_id){
// http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress
$forum_id = bbpress()->current_forum_id;//bbp_get_forum_id();
}
//error_log("og my_bbp_filter_search_results jan 2016 forumid=".$forum_id." get: ". print_r($_GET,true));
//https://wordpress.org/support/topic/meta_query-does-not-filter-at-all
// http://codex.bbpress.org/bbp_list_forums/
// https://bbpress.org/forums/topic/how-to-display-list-of-sub-forums-on-separate-lines-instead-of-big-blob/
// https://wordpress.org/support/topic/how-to-get-top-level-parent-pages
// https://bbpress.trac.wordpress.org/attachment/ticket/2303/forums-template-tags-4.patch%E2%80%8B
// wp-content/plugins/bbpress/includes/forums/template.php
// https://bbpress.org/forums/topic/my-customized-sub-sub-forums/
// wp-content/themes/wp-knowledge-base/inc/bbpress.php
// Colin's code in this file (above)
// http://php.net/manual/en/function.array-push.php
// http://codex.wordpress.org/Class_Reference/WP_Meta_Query
// https://wordpress.org/support/topic/wp-multiple-meta_query-from-array
// http://wordpress.stackexchange.com/questions/115608/meta-query-with-array-as-value-with-multiple-arrays
// http://stackoverflow.com/questions/18401396/how-to-pass-array-into-meta-query-value-with-advanced-custom-fields
// wp-content/themes/wp-knowledge-base/inc/bbpress.php
// wp-content/plugins/bbpress/includes/common/functions.php
// and the sources above
//If the forum ID exits, filter the query
if( $forum_id && is_numeric( $forum_id ) ){
// Get the sub forums and add them to the query in order to search through them too, since the forum search IS NOT RECURSIVE
//error_log("og bbp_forum_get_subforums ".print_r(function_exists('bbp_forum_get_subforums'),true));
$ogmysubforums = bbp_forum_get_subforums("".$forum_id);
//bbp_forum_get_subforums("".$forum_id);
$mysearchforums = array($forum_id);
// Pass $mycollectedsearchforums by reference, so we can add forum ids to it
// http://php.net/manual/en/language.references.pass.php
function my_recursive_findsubforums($ogmyrecsubforums, &$mycollectedsearchforums){
if ( ! empty( $ogmyrecsubforums ) ) {
foreach ( $ogmyrecsubforums as $sub_forum ) {
error_log("og bbp_list_forums sub: ".print_r($sub_forum->ID,true));
array_push($mycollectedsearchforums, $sub_forum->ID);
// Find the subforums of the current sub forum
my_recursive_findsubforums(bbp_forum_get_subforums("".$sub_forum->ID), $mycollectedsearchforums);
}
}
}
my_recursive_findsubforums($ogmysubforums, $mysearchforums);
//error_log("og bbp_list_forums4: ".print_r($ogmysubforums,true)." ".print_r($mysearchforums,true));
// https://github.com/ntwb/bbPress/blob/master/src/includes/forums/template.php
// http://phpcrossref.com/xref/bbpress/includes/forums/template.php.html#l767
// http://stackoverflow.com/questions/12778304/wordpress-custom-query-missing-two-posts
//echo bbp_list_forums(array('forum_id' =>"".$forum_id));
// Recursive (search the current forum and all its sub forums)
$r['meta_query'] = array(
array(
'key' => '_bbp_forum_id',
'value' => $mysearchforums,
'compare' => 'IN',
'post_type' => array('forum', 'topic', 'reply'),
)
);
// Non-recursive (search teh current forum and don't search its sub forums)
//$r['meta_query'] = array(
// array(
// 'key' => '_bbp_forum_id',
// 'value' => $forum_id,
// 'compare' => '=',
// )
//);
}
return $r;
}
add_filter( 'bbp_after_has_search_results_parse_args' , 'my_bbp_filter_search_results' );
// Add the forum id to the redirect (otherwise we won't have it in, because itgets lost in bbp_search_results_redirect)
// Taken from http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress (including the comments)
// and
// wp-content/plugins/bbpress/includes/search/template.php
// wp-content/plugins/bbpress/includes/search/template.php
// wp-content/plugins/bbpress/includes/search/template.php
// wp-content/plugins/bbpress/includes/search/functions.php
// wp-includes/pluggable.php wp_redirect and wp_safe_redirect
// other wordpress, buddypress and bbpress sourcecode..
//function my_bbp_get_search_results_url($mysearchurl){
//function my_bbp_search_results_pagination($args){
//function my_bbp_get_search_results_url($mysearchurl){
// my_bbp_search_results_redirect
// Don't let wp redirect to the search forum page without adding the forum id!
// We can't add bbp_search_forum_id in bbp_get_search_results_url because then pagination doesn't work (see bbp_has_search_results in
// wp-content/plugins/bbpress/includes/search/template.php for more information). Basically, bbp_get_search_results_url is called before
// pagination gets added and if we add the forum search id before the pagination string then we'll get pagination link urls that look like this:
// https://....../search/<search terms>?bbp_search_forum_id=<forum id>/page/<page id> meaning that pagination WILL NOT WORK
// By adding the bbp_search_forum_id argument here, we prevent this from happening while making sure to pass the bbp_search_forum_id to
// the search (the search will have access to the bbp_search_forum_id but it will not affect the pagination links, so we'll never get
// the bad url structure described above)
function my_wp_redirect($mysearchurl){
$mynewsearchurl=$mysearchurl;
//if(array_key_exists('base', $args)){
//$mysearchurl = $args['base'];
// error_log("og my_bbp_get_search_results_url ".$mysearchurl." ".print_r($_GET,true));
//error_log("og bbp_search_results_pagination ".$mysearchurl." ".print_r($_GET,true)." ".print_r($args,true));
// Make sure bbp_search_forum_id doesn't get lost during redirect to search results
if(array_key_exists('bbp_search_forum_id', $_REQUEST)){
// We only do this when redirecting to search results
if(bbp_get_search_results_url()===$mynewsearchurl){
$mynewsearchurl=$mysearchurl;
$mybbp_search_forum_id=$_REQUEST['bbp_search_forum_id'];
if($mybbp_search_forum_id){
// Sdd bbp_search_forum_id to the url we are redirecting to...
$mynewsearchurl = add_query_arg(array('bbp_search_forum_id'=>$_GET['bbp_search_forum_id']),$mynewsearchurl);
}
}
}
//$args['base'] = $mynewsearchurl;
//}
return $mynewsearchurl;
}
// Add the bbp_search_forum_id to the pagination links (the right way, meaning AFTER the pagination string, /page/<page#>/)
function my_bbp_search_results_pagination($args){
if(array_key_exists('bbp_search_forum_id', $_REQUEST)){
// Copied from wp-content/plugins/bbpress/includes/search/template.php bbp_has_search_results
// and
// wp-includes/general-template.php paginate_links
$add_args = array();
if(array_key_exists('add_args', $args)){
$add_args = $args['add_args'];
}
$add_args['bbp_search_forum_id'] = $_REQUEST['bbp_search_forum_id'];
$args['add_args'] = $add_args;
}
return $args;
}
//add_filter( 'bbp_get_search_results_url' , 'my_bbp_get_search_results_url' );
// https://codex.wordpress.org/Function_Reference/add_filter
// add_filter( 'bbp_search_results_pagination' , 'my_bbp_search_results_pagination', 20, 1);
add_filter('wp_redirect', 'my_wp_redirect', 20, 1);
add_filter('bbp_search_results_pagination', 'my_bbp_search_results_pagination', 20, 1);
//////////////////////////////////////////////////////////////////////////////////////////////////
// Mark as unread
// Uncomment this code if you want to add content to read or unread topics that are
// listed on the topic list page)
//////////////////////////////////////////////////////////////////////////////////////////////////
// http://codex.bbpress.org/bbp_theme_before_forum_freshness_link/
// http://codex.bbpress.org/bbp_theme_before_topic_author/
// http://etivite.com/api-hooks/bbpress/trigger/do_action/bbp_theme_before_topic_freshness_link/
//add_action( 'bbp_theme_before_topic_freshness_link', 'og_before_topic_freshness_link' );
/*function og_before_topic_freshness_link() {
//wp-content/plugins/bbpress-mark-as-read/bbp-mark-as-read.php
$unreadpluginobj = $GLOBALS['bbp_mark_as_read'];
// https://bbpress.trac.wordpress.org/browser/tags/2.0/bbp-themes/bbp-twentyten/bbpress/loop-single-topic.php#L16
// https://bbpress.org/forums/topic-tag/bbp_get_topic_id/
$mytopicid = bbp_get_topic_id();
// http://codex.wordpress.org/Function_Reference/get_current_user_id
$myuserid = get_current_user_id();
if($unreadpluginobj && $mytopicid && $myuserid){
$addedtopicclassclass = "readunread_topic ";
if($unreadpluginobj->is_read($myuserid,$mytopicid)){
$addedtopicclassclass .= "read_topic";
}
else{
$addedtopicclassclass .= "unread_topic";
}
echo "<div class='".$addedtopicclassclass."'> </div>";
}
}*/
//////////////////////////////////////////////////////////////////////////////////////////////////
// bbpress forum voting
// The functions below enable administrators to change the voting button's text per forum
// The default text is set to the button's original text "Vote for this!"
//////////////////////////////////////////////////////////////////////////////////////////////////
// This function adds a text box to the admin's forum editing interface. This textbox contains the voting button's text for the forum $forum_id.
// We use the action bbp_forum_metabox to add this content (which is what the bbp forum plugin does)
//http://codex.wordpress.org/Function_Reference/add_action
// Taken and copied from wp-content/plugins/bbPress-Support-Forums-master/admin/bbps-admin.php bbps_extend_forum_attributes_mb
function my_bbps_extend_forum_attributes_mb($forum_id){
echo "<p>";
// http://codex.wordpress.org/Function_Reference/get_post_meta
// http://codex.wordpress.org/Function_Reference/update_post_meta
// Inspired by wp-content/plugins/bbPress-Support-Forums-master/includes/bbps-common-functions.php bbps_is_premium_forum
$voting_forum_button_text = get_post_meta( $forum_id, '_bbps_my_voting_btn_txt', true);
if(empty($voting_forum_button_text)){
$voting_forum_button_text = "Vote for this!";
}
// We have to use 3 different echos. If you concatinate the strings instead using "." php will mess up the order.
echo '<strong> '; echo _e( 'Voting Button Text:', 'bbps' ); echo ' </strong>';
echo "<input type='text' id='votingbtntxt' name='votingbtntxt' value='".$voting_forum_button_text."'/>";
echo "</p>";
echo "<br />";
}
add_action('bbp_forum_metabox' , 'my_bbps_extend_forum_attributes_mb', 20, 1);
// This function saves the content of the "voting button text" textbox as the new voting button's text for the forum $forum_id.
// We use the action bbp_forum_attributes_metabox_save to save the content (which is what the bbp forum plugin does)
// Taken and copied from wp-content/plugins/bbPress-Support-Forums-master/admin/bbps-admin.php bbps_forum_attributes_mb_save
function my_bbps_forum_attributes_mb_save($forum_id){
// Update the voting button's text for this forum
// http://codex.wordpress.org/Function_Reference/get_post_meta
$voting_forum_button_text = $_POST['votingbtntxt'];
// Make sure that the button can be displayed properly
if(empty($voting_forum_button_text)){
$voting_forum_button_text = " ";
}
update_post_meta($forum_id, '_bbps_my_voting_btn_txt', $voting_forum_button_text);
return $forum_id;
}
add_action( 'bbp_forum_attributes_metabox_save' , 'my_bbps_forum_attributes_mb_save', 20, 1);
// This function adds javascript code to the page that sets the text of the voting button to the text from the forum's config options
// I used JS here because there seemed to be no other way (other than possibly creating a script an using ...enqueue_script...) to change the button's text without
// changing the plugin's code. The plugin dod not provide filters or actions to override the button's text. It didn't even use translation functions to set the button's text,
// so I couldn't use translation events to override it.
// We use the action bbp_template_before_single_topic to add the code and make sure it only get added
// to voting forums (which is similar to what the bbp forum plugin does when it creates the voting button)
// Taken and copied from wp-content/plugins/bbPress-Support-Forums-master/admin/bbps-admin.php bbps_add_voting_forum_features
function my_bbps_add_voting_forum_features(){
$texttorteplace = "Vote for this!";
$forum_id = bbp_get_forum_id();
// Taken and copied from wp-content/plugins/bbPress-Support-Forums-master/admin/bbps-admin.php bbps_modify_vote_title
if(bbps_is_voting_forum($forum_id)){
// http://codex.wordpress.org/Function_Reference/get_post_meta
$voting_forum_button_text = get_post_meta( $forum_id, '_bbps_my_voting_btn_txt', true);
// Don't change the text if this setting hasn't been set yet
// (and when it gets set we always make sure it's not empty)
// wp-content/plugins/bbPress-Support-Forums-master/admin/bbps-admin.php
if(empty($voting_forum_button_text)){
return;
}
//echo "abcd".print_r($voting_forum_button_text,true);
// http://www.w3schools.com/tags/tag_script.asp
// http://api.jquery.com/contains-selector/
// http://stackoverflow.com/questions/2338439/select-element-based-on-exact-text-contents
// http://learn.jquery.com/using-jquery-core/document-ready/
echo "<script>";
echo "jQuery( document ).ready( function(){ ";
echo "jQuery(\"a:contains('".$texttorteplace."')\").each(function () {";
echo " if(jQuery(this).text()=='".$texttorteplace."'){";
echo " jQuery(this).text('".$voting_forum_button_text."');";
echo " }";
echo "})";
echo "});";
echo "</script>";
}
}
add_action('bbp_template_before_single_topic', 'my_bbps_add_voting_forum_features');
//////////////////////////////////////////////////////////////////////////////////////////////////
// User group preferences
// Used Plugin:
// https://github.com/fpcorso/quiz_master_next/
//////////////////////////////////////////////////////////////////////////////////////////////////
// Taken from http://php.net/manual/en/language.oop5.php and samples
// http://php.net/manual/en/language.oop5.magic.php
// http://php.net/manual/en/language.oop5.magic.php#object.tostring
class QuestionAnswer {
protected $m_question;
protected $m_answer;
protected $m_score;
protected $m_correctanswer;
protected $m_usercomments;
protected $m_correctanswerinfo;
protected $m_points;
protected $m_maxpoints;
public function __construct($questionanswerarray, $questioninfoarray=array()){
// Taken from https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_template_variables.php
$this->m_question = $questionanswerarray[0];
$this->m_answer = $questionanswerarray[1];
$this->m_correctanswer = $questionanswerarray[2];
$this->m_usercomments = $questionanswerarray[3];
$this->m_correctanswerinfo = $questionanswerarray['id'];
$this->m_points = $questionanswerarray['points'];
if($questioninfoarray && count($questioninfoarray)>0){
// http://php.net/manual/en/function.array-map.php and example 2
$getpoints = function(&$questionanswer){
return $questionanswer[1];
};
$this->m_maxpoints = max(array_map($getpoints,$questioninfoarray));
}
else{
$this->m_maxpoints=-1;
}
}
public function getMaxPoints(){
return $this->m_maxpoints;
}
public function setMaxPoints($maxPointsArg){
$this->m_maxpoints = $maxPointsArg;
}
public function getQuestion(){
return $this->m_question;
}
public function getAnswer(){
return $this->m_answer;
}
public function getCorrectAnswer(){
return $this->m_correctanswer;
}
public function getUserComments(){
return $this->m_usercomments;
}
public function getCorrentAnswerInfo(){
return $this->correctanswerinfo;
}
public function getPoints(){
return $this->m_points;
}
// http://php.net/manual/en/language.oop5.magic.php#object.tostring
// http://php.net/manual/en/language.oop5.magic.php#object.debuginfo
public function __toString(){
return "Question: ".$this->getQuestion()." Answer: ".$this->getAnswer(). " Points: ".$this->getPoints()." Max points:".$this->getMaxPoints();
}
}
class UserResponse{
protected $m_extrainfo;
protected $m_info;
protected $m_answers;
// Takes quiz response information
public function __construct($mlw_quiz_info, $questioninfo, $extrainfo=null){
// Taken from https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_results_details.php
// and https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_results.php
$mlw_qmn_results_array = @unserialize($mlw_quiz_info->quiz_results);
if (is_array($mlw_qmn_results_array)){
// Taken from https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_results_details.php
// and https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_template_variables.php
$qmn_array_for_variables = array(
'quiz_id' => $mlw_quiz_info->quiz_id,
'quiz_name' => $mlw_quiz_info->quiz_name,
'quiz_system' => $mlw_quiz_info->quiz_system,
'user_name' => $mlw_quiz_info->name,
'user_business' => $mlw_quiz_info->business,
'user_email' => $mlw_quiz_info->email,
'user_phone' => $mlw_quiz_info->phone,
'user_id' => $mlw_quiz_info->user,
'timer' => $mlw_qmn_results_array[0],
'total_points' => $mlw_quiz_info->point_score,
'total_score' => $mlw_quiz_info->correct_score,
'total_correct' => $mlw_quiz_info->correct,
'total_questions' => $mlw_quiz_info->total,
'comments' => $mlw_qmn_results_array[2],
'question_answers_array' => $mlw_qmn_results_array[1]
);
$this->m_info = $qmn_array_for_variables;
$myuseranswers = $qmn_array_for_variables['question_answers_array'];
// Inspired by qmn_array_for_variables above:
// //https://github.com/fpcorso/quiz_master_next/blob/master/includes/qmn_quiz.php
$this->m_answers = array(
'number_of_hours'=> new QuestionAnswer($myuseranswers[0]),
'time'=> new QuestionAnswer($myuseranswers[1],@unserialize($questioninfo[1]->answer_array)),
'unit'=> new QuestionAnswer($myuseranswers[2],@unserialize($questioninfo[2]->answer_array)),
'game_design_background'=> new QuestionAnswer($myuseranswers[3], @unserialize($questioninfo[3]->answer_array)),
'game_design_background_homogeneity'=> new QuestionAnswer($myuseranswers[4], @unserialize($questioninfo[4]->answer_array)),
'tech_background'=> new QuestionAnswer($myuseranswers[5], @unserialize($questioninfo[5]->answer_array)),
'tech_background_homogeneity'=> new QuestionAnswer($myuseranswers[6], @unserialize($questioninfo[6]->answer_array)),
'experience_with_online_courses'=> new QuestionAnswer($myuseranswers[7], @unserialize($questioninfo[7]->answer_array)),
'experience_with_online_courses_homogeneity'=> new QuestionAnswer($myuseranswers[8], @unserialize($questioninfo[8]->answer_array)),
'education'=> new QuestionAnswer($myuseranswers[9], @unserialize($questioninfo[9]->answer_array)),
'education_homogeneity'=> new QuestionAnswer($myuseranswers[10], @unserialize($questioninfo[10]->answer_array))
);
//error_log("strange thing".print_r($myuseranswers[4],true));
/*$this->m_answers = array(
/ 'number_of_hours'=> new QuestionAnswer($myuseranswers[0]),
'start_time'=> new QuestionAnswer($myuseranswers[1],@unserialize($questioninfo[1]->answer_array)),
'end_time'=> new QuestionAnswer($myuseranswers[2], @unserialize($questioninfo[2]->answer_array)),
'game_design_background'=> new QuestionAnswer($myuseranswers[3], @unserialize($questioninfo[3]->answer_array)),
'tech_background'=> new QuestionAnswer($myuseranswers[4], @unserialize($questioninfo[4]->answer_array)),
'experience_with_online_courses'=> new QuestionAnswer($myuseranswers[5], @unserialize($questioninfo[5]->answer_array)),
'education'=> new QuestionAnswer($myuseranswers[6], @unserialize($questioninfo[6]->answer_array))
);*/
$this->m_extrainfo = $extrainfo;
}
}
public function getInfo(){
return $this->m_info;
}
public function getAnswers(){
return $this->m_answers;
}
public function getExtraInfo(){
return $this->m_extrainfo;
}
public function setExtraInfo($extrainfo){
$this->m_extrainfo = $extrainfo;
}
// Send an email to the user who completed the survey
public function sendEmailToUser($subjectline,$content){
$useremailaddress = $this->getInfo()["user_email"];
if($useremailaddress){
// wp-content/plugins/bbpress/includes/users/functions.php
// bbp_add_user_subscription
//bbp_add_user_forum_subscription
//wp-content/plugins/bbpress/templates/default/bbpress-functions.php
// Taken from wp-content/plugins/bbPress-Support-Forums-master/includes/bbps-support-functions.php
//bbps_assign_topic
//wp_mail
// http://codex.wordpress.org/Function_Reference/wp_mail
// Send an email to the user who just got added to the group