forked from slaFFik/BP-GTM-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp-gtm-templatetags.php
1220 lines (1114 loc) · 54.5 KB
/
bp-gtm-templatetags.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
function bp_gtm_filter_users($resps = null) {
global $bp;
if (bp_group_has_members(array('per_page' => 1000, 'exclude_admins_mods' => 0))) :
$check = array();
if (!empty($resps) && !empty($bp->action_variables[1]) && $bp->action_variables[1] == 'edit') {
$check = $resps;
};
?>
<div class="wrap-roles">
<?php do_action('bp_before_group_members_list'); ?>
<ul id="member-list" class="item-list" role="main">
<?php while (bp_group_members()) : bp_group_the_member(); ?>
<?php $member = bp_get_member_user_login(); ?>
<li <?php echo in_array($member, $check) ? 'class="red"' : ''; ?> ><input type="checkbox" name="user_ids[<?php esc_attr(bp_member_user_login()) ?>]" class="check-user" value="<?php esc_attr(bp_member_user_login()) ?>" <?php echo in_array($member, $check) ? 'checked="checked"' : ''; ?> />
<?php bp_group_member_avatar_thumb(); ?>
<h5><?php echo $member; ?></h5>
<?php if (bp_is_active('friends')) : ?>
<div class="action">
<?php do_action('bp_directory_members_actions_loop', bp_get_member_user_login()); ?>
</div>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php do_action('bp_after_group_members_list'); ?>
</div>
<?php else: ?>
<div id="message" class="info">
<p><?php _e("Sorry, no members were found.", 'buddypress'); ?></p>
</div>
<?php
endif;
}
function bp_gtm_truncate($text) {
$matchesarray = array();
$text = stripslashes(trim($text));
preg_match('/\s+/i', $text, $matchesarray);
if (!empty($matchesarray)) {
return $text;
} else {
return substr($text, 0, 30);
}
}
function bp_gtm_resps_loop($resps = array()) {
global $bp;
$count = array();
$bp_gtm = get_option('bp_gtm');
foreach ($resps as $resp) {
if (in_array($resp->id, $count)) {
continue;
}//prevent duplicate users
else {
$count[] = $resp->id;
}//prevent duplicate users
if ($resp->id != 0) {
$role = bp_gtm_get_role_for_user($resp->id);
?>
<tr id="<?php echo $resp->id; ?>">
<td class="td-title">
<?php
bp_gtm_poster_discussion_meta($resp->id);
$arg['item_id'] = $resp->id;
?>
</td>
<?php if ($bp_gtm['groups'] == 'all' || array_key_exists($bp->groups->current_group->id, $bp_gtm['groups'])) { ?>
<td class="td-title">
<?php echo empty($role) ? __('Admin', 'bp_gtm') : $role->role_name; ?>
</td>
<?php } ?>
<td class="td-poster">
<?php bp_gtm_get_issues($resp->id, 'tasks') ?>
</td>
<td class="td-group">
<?php bp_gtm_get_issues($resp->id) ?>
</td>
<td id="users" class="td-freshness">
<?php
bp_gtm_get_involved_mention_link($bp->loggedin_user->id, $resp->id);
bp_gtm_get_involved_messaage_send_link($bp->loggedin_user->id, $resp->id);
bp_gtm_get_involded_send_email_link($resp->id);
?>
<?php do_action('bp_directory_involved_actions', $resp->id); ?>
</td>
<?php do_action('bp_directory_involved_extra_cell') ?>
</tr>
<?php
do_action('bp_directory_involved_extra_row');
}
}
}
/**
* Get activity message link
* @param int $bp_loggedin_user_id id of logining user
* @param int $resp_id id of invilved user
* @return bool true if access allowed and false in etc.
*/
function bp_gtm_get_involved_mention_link($bp_loggedin_user_id, $resp_id) {
if (bp_gtm_check_access('involved_mention')) {
?>
<a href="<?php echo bp_core_get_user_domain($bp_loggedin_user_id, false, false) . BP_ACTIVITY_SLUG . '/?r=' . bp_core_get_username($resp_id, false, false) ?>" title="<?php _e('Mention this user', 'bp_gtm'); ?>">@</a> |
<?php
return true;
} else {
return false;
}
}
/**
* Get send private message to involved user
* @param int $bp_loggedin_user_id id of logining user
* @param int $resp_id id of invilved user
* @return bool true if access allowed and false in etc.
*/
function bp_gtm_get_involved_messaage_send_link($bp_loggedin_user_id, $resp_id) {
if (bp_gtm_check_access('involved_pm')) {
?>
<a href="<?php echo bp_core_get_user_domain($bp_loggedin_user_id, false, false) . BP_MESSAGES_SLUG . '/compose/?r=' . bp_core_get_username($resp_id, false, false) ?>" title="<?php _e('Send a private meassage', 'bp_gtm'); ?>"><?php _e('PM', 'bp_gtm'); ?></a>
<?php
return true;
} else {
return false;
}
}
/**
* Notify user about pending tasks and projects
* @param int $resp_id id of inlilved user
* @return bool true if access allowed and false in etc.
*/
function bp_gtm_get_involded_send_email_link($resp_id) {
if (bp_gtm_check_access('involved_email')) {
?>
| <a href="#" class="email_notify" id="<?php echo $resp_id ?>" title="<?php _e('Notify user about pending tasks and projects', 'bp_gtm') ?>"><?php _e('N', 'bp_gtm') ?></a>
<?php
return true;
} else {
return false;
}
}
/**
* Get count of tasks or projects in current group
* @param int $resp_id id of involved member
* @param string $issues_type tasks or projects count needs to calculate
* @return bool true
*/
function bp_gtm_get_issues($resp_id, $issues_type = 'projects') {
$count_tasks = BP_GTM_Resps::get_el_count($resp_id, $issues_type, bp_get_current_group_id());
if ($issues_type == 'tasks') {
echo sprintf(_n('%s task', '%s tasks', $count_tasks, 'bp_gtm'), $count_tasks);
} else {
echo sprintf(_n('%s project', '%s projects', $count_tasks, 'bp_gtm'), $count_tasks);
}
return TRUE;
}
function bp_gtm_terms_loop($tags, $tax) {
global $bp;
foreach ($tags as $tag) {
?>
<tr class="" id="<?php echo $tag['id']; ?>">
<td class="td-title">
<a class="topic-title" href="<?php echo $gtm_link . $bp->action_variables[0] . '/view/' . $tag['id'] ?>" title="<?php _e('Permalink on this term page', 'bp_gtm') ?>"><?php echo bp_gtm_truncate($tag['name']); ?></a>
</td>
<td class="td-postcount"><?php echo $tag['count']; ?></td>
<td id="tag" class="td-freshness">
<?php if (bp_gtm_check_access('taxon_edit')) { ?>
<a class="edit_me" id="<?php echo $tag['id']; ?>" href="#"><img height='16' width='16' src="<?php echo GTM_URL ?>_inc/images/edit.png" alt="<?php _e('Edit', 'bp_gtm') ?>" /></a>
<?php } ?>
<?php if (bp_gtm_check_access('taxon_delete')) { ?>
<a class="delete_me" id="<?php echo $tag['id']; ?>" href="#"><img height='16' width='16' src="<?php echo GTM_URL ?>_inc/images/delete.png" alt="<?php _e('Delete', 'bp_gtm') ?>" /></a>
<?php } ?>
</td>
<?php do_action('bp_directory_' . $tax . '_extra_cell') ?>
</tr>
<?php do_action('bp_directory_' . $tax . '_extra_row') ?>
<?php
}
}
function bp_gtm_terms_nodes($elements = array(), $task_or_proj = 'project', $gtm_link) {
foreach ($elements as $task_id => $task_name):
?>
<tr class="" id="<?php echo $task_id; ?>">
<td class="td-title">
<a href="<?php echo $gtm_link . $task_or_proj . '/view/' . $task_id ?>" title="<?php sprintf(_e('Permalink to this %s page', 'bp_gtm'), $task_or_proj) ?>"><?php echo $task_name; ?></a>
</td>
<td class="td-postcount">
<?php bp_gtm_is_elem_done($task_id, $task_or_proj) ? _e('Yes', 'bp_gtm') : _e('No', 'bp_gtm'); ?>
</td>
</tr>
<?php
endforeach;
}
function bp_gtm_task_project($parent_task = 0, $task = null) {
$projects = array();
if ($parent_task == 0) { ?>
<p>
<label for="task_project"><?php _e('Project that this task corresponds to', 'bp_gtm'); ?></label>
<?php
$projects = bp_gtm_get_projects(bp_get_current_group_id(), 'alpha');
if (count($projects) > 0) : ?>
<table>
<?php
foreach ($projects as $project) :
($task == $project->id) ? $checked = 'checked="checked" ' : $checked = '';
?>
<tr>
<td class="task-project"><input type="radio" name="task_project" value="<?php echo $project->id ?>" <?php echo $checked; ?>/><?php echo $project->name ?></td>
<td class="padding0"><?php _e('Deadline', 'bp_gtm') ?>: <?php bp_gtm_format_date($project->deadline); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
else :
_e('Please create at least one project to proceed.', 'bp_gtm');
endif;
?>
</p>
<?php
}
return count($projects);
}
function bp_gtm_term_task_edit_loop($task_id, $tax) {
$terms = BP_GTM_Taxon::get_terms_4task(bp_get_current_group_id(), $task_id, $tax);
if (count($terms) > 0) {
if($tax!='tag'){
foreach ($terms as $tag) {
($tag['used'] == '1') ? $used = 'checked="checked"' : $used = '';
echo '<input name="task_old_' . $tax . 's[]" type="checkbox" ' . $used . ' value="' . stripslashes($tag['name']) . '" /> ' . stripslashes($tag['name']) . '<br>';
}
} else {
foreach ($terms as $tag) {
if($tag['used'] == '1')
echo '<li class="resps-tab" id="un-tag"><span>' . stripslashes($tag['name']) . '</span> <span class="p">X</span></li>';
}
}
} else {
$link = 'terms';
echo '<p>' . sprintf(__('There are no %ss to display. Create them <a href="%s" target="_blank">here</a>', 'bp_gtm'), $tax, $link) . '</p>';
}
}
function bp_gtm_discussion_list($task_id, $tax = 'task') {
?>
<ul id="topic-post-list" class="item-list discussions">
<?php
$posts = BP_GTM_Discussion::get_posts($task_id, $tax);
$i = 1;
if (count($posts) > 0)
foreach ($posts as $post) {
?>
<li id="post-<?php echo $post->id; ?>" class="alt">
<div class="poster-meta">
<?php bp_gtm_poster_discussion_meta($post->author_id); ?>
<?php echo ' ' . sprintf(__('said %s:', 'bp_gtm'), bp_core_time_since($post->date_created)) ?>
</div>
<div class="post-content"><?php echo $post->text; ?></div>
<?php do_action('bp_gtm_discuss_after_content', $post, 'discuss', true); ?>
<div class="admin-links">
<?php bp_gtm_discuss_admin_links($post->id, $i, $tax, $task_id); ?>
</div>
</li>
<?php
$i++;
}
?>
</ul>
<?php
}
function bp_gtm_get_responsibles($task_resp_id) {
$users_logins = explode(' ', $task_resp_id);
$arg['width'] = '25';
$arg['height'] = '25';
if (!empty($users_logins)) {
echo '<span class="responsible">' . __('Responsible', 'bp_gtm') . '</span><br>';
foreach ($users_logins as $users_login) {
if ($users_login != '') {
$arg['item_id'] = bp_core_get_userid($users_login);
?>
<a class="responsible-link" href="<?php echo bp_core_get_userlink($arg['item_id'], false, true); ?>" title="<?php echo bp_core_get_userlink($arg['item_id'], true, false); ?>">
<?php echo bp_core_fetch_avatar($arg); ?>
</a>
<?php
}
}
}
}
function bp_gtm_terms_for_project($project_id, $tax) {
global $bp;
$gtm_link = bp_get_group_permalink(). $bp->gtm->slug . '/';
$terms = BP_GTM_Taxon::get_terms_4project(bp_get_current_group_id(), $project_id, $tax);
if (count($terms) > 0) {
if ($tax != 'tag') {
echo '<p>';
foreach ($terms as $tag) {
if ($tag['name'] != '') {
($tag['used'] == '1') ? $used = 'checked="checked"' : $used = '';
echo '<input name="project_old_' . $tax . 's[]" type="checkbox" ' . $used . ' value="' . stripslashes($tag['name']) . '" /> ' . stripslashes($tag['name']) . '<br>';
}
}
echo '</p>';
} else {
foreach ($terms as $tag) {
if ($tag['used'] == '1')
echo '<li class="resps-tab" id="un-tag"><span>' . stripslashes($tag['name']) . '</span> <span class="p">X</span></li>';
}
}
} else {
$link = $gtm_link . 'terms';
echo sprintf(__('<p>There are no tags to display. Create them <a href="%s" target="_blank">here</a></p>', 'bp_gtm'), $link);
}
}
function bp_gtm_get_cats_for_group() {
$terms = BP_GTM_Taxon::get_terms_in_group(bp_get_current_group_id(), 'cat');
if (count($terms) > 0) {
echo '<div class="group_cats">';
foreach ($terms as $tag) {
if ($tag['name'] != '') {
($tag['used'] == '1') ? $used = 'checked="checked"' : $used = '';
echo '<p><input name="project_cats[]" type="checkbox" ' . $used . ' value="' . stripslashes($tag['name']) . '" /> <span>' . stripslashes($tag['name']) . '</span></p>';
}
}
echo '</div>';
}
}
function bp_gtm_project_list_settings() {
$options = array();
$options['filter'] = !empty($_GET['filter']) ? $_GET['filter'] : 'deadline';
$options['action'] = !empty($_GET['action']) ? 'project_' . $_GET['action'] : 'project_view';
if ($options['filter'] == 'done') {
$options['page_h4'] = __('Completed Projects', 'bp_gtm');
$options['projects'] = bp_gtm_get_projects(bp_get_current_group_id(), 'done');
$options['done_style'] = 'class="grey"';
} elseif ($options['filter'] == 'alpha') {
$options['page_h4'] = __('Projects by A/Z', 'bp_gtm');
$options['projects'] = bp_gtm_get_projects(bp_get_current_group_id(), 'alpha');
$options['alpha_style'] = 'class="grey"';
} elseif ($options['filter'] == 'deadline') {
$options['page_h4'] = __('Projects by Deadline', 'bp_gtm');
$options['projects'] = bp_gtm_get_projects(bp_get_current_group_id(), 'deadline');
$options['deadline_style'] = 'class="grey"';
}
return $options;
}
function bp_gtm_task_list_settings($bp_gtm_group_settings) {
$limit['per_page'] = $option['per_page'] = $bp_gtm_group_settings['tasks_pp']; // how many to show
$limit['miss'] = $option['miss'] = 0; // from the very first one - need to be on the 1st page
$option['filter'] = !empty($_GET['filter']) ? $_GET['filter'] : '';
$option['action'] = !empty($_GET['action']) ? $_GET['action'] : 'task_view';
if (empty($_GET['project'])) {
$option['project_id'] = false;
if ($option['filter'] == 'done') {
$option['page_h4'] = __('All Completed Tasks', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'done', false, $limit);
$option['done_style'] = 'class="grey"';
} elseif ($option['filter'] == 'alpha') {
$option['page_h4'] = __('Tasks by A/Z', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'alpha', false, $limit);
$option['alpha_style'] = 'class="grey"';
} elseif ($option['filter'] == 'deadline') {
$option['page_h4'] = __('Tasks by Deadline', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'deadline', false, $limit);
$option['deadline_style'] = 'class="grey"';
} elseif ($option['filter'] == 'without') {
$option['page_h4'] = __('Tasks whithout Project', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'], false, $limit);
$option['by_proj_style'] = 'class="grey"';
} else {
$option['page_h4'] = __('Tasks by Deadline', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'deadline', false, $limit);
$option['deadline_style'] = 'class="grey"';
}
} elseif (!empty($_GET['project']) && !empty($option['filter'])) {
if ($option['filter'] == 'done') {
$option['project_id'] = $_GET['project'];
$option['page_h4'] = __('Completed Tasks in Project', 'bp_gtm') . ' "' . bp_gtm_get_el_name_by_id($_GET['project'], 'project') . '"';
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'done', $_GET['project'], $limit);
$option['by_proj_style'] = 'class="grey"';
}
} elseif (!empty($_GET['project']) && empty($option['filter'])) {
if ($_GET['project'] == 'without') {
$option['page_h4'] = __('Tasks whithout Project', 'bp_gtm');
$option['tasks'] = BP_GTM_Tasks::get_task_whithout_project(bp_get_current_group_id());
$option['by_proj_style'] = 'class="grey"';
} else {
$option['page_h4'] = __('Tasks by Deadline', 'bp_gtm');
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'inproject', $_GET['project'], $limit);
$option['deadline_style'] = 'class="grey"';
}
} else {
$option['project_id'] = false;
$option['page_h4'] = __('Pending Tasks in Project', 'bp_gtm') . ' "' . bp_gtm_get_el_name_by_id($_GET['project'], 'project') . '"';
$option['tasks'] = bp_gtm_get_tasks(bp_get_current_group_id(), $option['filter'] = 'project', $_GET['project'], $limit);
$option['view_project'] = '<a href="' . $gtm_link . 'projects/view/' . $_GET['project'] . '" class="button" title="' . __('Go to project\'s page', 'bp_gtm') . '">' . __('View Project', 'bp_gtm') . '</a>';
$option['filter'] = $_GET['project'];
$option['by_proj_style'] = 'class="grey"';
}
return $option;
}
// Load next page content
function bp_gtm_tasks_navi_content() {
global $bp, $wpdb;
$data = explode('-', $_GET['nextPage']);
$limit['miss'] = ($data['0'] * $data['1']);
$limit['per_page'] = $data['1'];
if ($_GET['project'] && !$_GET['filter']) {
$tasks = bp_gtm_get_tasks($bp->groups->current_group->id, $filter = 'project', $_GET['project'], $limit);
} elseif ($_GET['project'] && $_GET['filter'] == 'done') {
$tasks = bp_gtm_get_tasks($bp->groups->current_group->id, $filter = 'done', $_GET['project'], $limit);
} else {
$tasks = bp_gtm_get_tasks($bp->groups->current_group->id, $_GET['filter'], false, $limit);
}
if (!empty($tasks)) {
$i = 1;
foreach ((array) $tasks as $task) {
$alt = is_int($i / 2) ? ' alt' : '';
?>
<tr id="<?php echo $task->id; ?>" class="<?php
bp_gtm_task_check_date($task->id, $task->deadline);
echo $alt
?>">
<td class="td-title">
<span class="subtasks_<?php echo $task->id; ?> td-title">
<span class="all_in_all" title="<?php _e('Current number of subtasks', 'bp_gtm'); ?>"><?php echo bp_gtm_get_subtasks_count($task->id) ?></span>
<?php bp_get_create_subtask_link($task->id, $gtm_link); ?>
</span>
<?php bp_gtm_view_link($task, $gtm_link, 'task') ?>
</td>
<td class="td-poster">
<?php bp_gtm_get_responsibles($task->resp_id); ?>
</td>
<td class="td-group">
<?php bp_gtm_view_link(BP_GTM_Projects::get_project_by_id($task->project_id), $gtm_link, 'project'); ?>
</td>
<td class="td-group">
<div class="object-name center"><?php bp_gtm_format_date($task->deadline) ?></div>
</td>
<td id="tasks" class="td-freshness">
<?php
bp_gtm_edit_link($task->id, $gtm_link, 'tasks');
bp_gtm_delete_task_link($task->id);
bp_gtm_done_link($option['filter'], $task->id, $el_type = 'task');
?>
</td>
<?php do_action('bp_directory_tasks_extra_cell') ?>
</tr>
<?php
do_action('bp_directory_tasks_extra_row');
$i++;
}
} else {
echo '<div id="message" class="info"><p>' . __('There are no tasks to display.', 'bp_gtm') . '</p></div>';
}
}
add_action('wp_ajax_bp_gtm_tasks_navi_content', 'bp_gtm_tasks_navi_content');
// Load next page content
function bp_gtm_discuss_navi_content() {
global $bp, $wpdb;
$data = explode('-', $_GET['nextPage']);
$limit['miss'] = ($data['0'] * $data['1']);
$limit['per_page'] = $data['1'];
$discusses = BP_GTM_Discussion::get_list($bp->groups->current_group->id, $_GET['what'], $limit);
if (count($discusses) > 0) {
$i = 1;
foreach ((array) $discusses as $post) {
if (is_int($i / 2)) {
$alt = ' alt';
} else {
$alt = '';
}
?>
<tr class="<?php echo $alt ?>">
<td class="td-title">
<?php bp_gtm_view_disscuss_link($post->elem_id, $gtm_link, $_GET['what']); ?>
</td>
<td class="td-poster">
<?php bp_gtm_poster_discussion_meta($post->author_id); ?></div>
</td>
<td class="td-postcount">
<?php echo $post->discuss_count; ?>
</td>
<td class="td-freshness"><div class="object-name" class="center"><?php bp_gtm_format_date($post->date_created) ?></div>
</td>
<?php do_action('bp_gtm_discuss_extra_cell') ?>
</tr>
<?php
do_action('bp_gtm_discuss_extra_row');
$i++;
}
} else {
echo '<div id="message" class="info"><p>' . __('There are no posts to display.', 'bp_gtm') . '</p></div>';
}
}
add_action('wp_ajax_bp_gtm_discuss_navi_content', 'bp_gtm_discuss_navi_content');
// Discussions page pagination func
function bp_gtm_discuss_navi($type = 'tasks', $group_id = false, $per_page = 20) {
global $bp, $wpdb;
$cur = 1;
$discusses = BP_GTM_Discussion::get_count($type, $group_id);
$pages = ceil($discusses / $per_page);
if ($pages > 1) {
echo '<p class="navi" id="' . $discusses . '">';
echo sprintf(__('<span id="cur_discuss">%d - %d</span> out of %d. ', 'bp_gtm'), $cur, $per_page, $discusses);
_e('Pagination:', 'bp_gtm');
for ($i = 0; $i < $pages; $i++) {
$c = $i + 1;
$cur = $cur - 1;
$current = $cur == $i ? ' current' : '';
echo ' <a id="' . $i . '-' . $per_page . '" class="discuss_navi' . $current . '" href="#">' . $c . '</a>';
}
echo '</p>';
} else {
_e('List of the latest tasks/projects discussions in this group.', 'bp_gtm');
}
}
// Display admin links near every post - view, edit, delete or whatever
function bp_gtm_discuss_admin_links($post_id, $post_number, $elem_type, $elem_id) {
global $bp;
?>
<a href="#post-<?php echo $post_id; ?>" title="<?php _e('Permalink', 'bp_gtm') ?>">#<?php echo $post_number ?></a>
<?php if (bp_gtm_check_access('discuss_edit')) { ?>
<a class="edit_post" id="<?php echo $post_id ?>" rel="<?php echo $elem_type . '_' . $elem_id; ?>" href="#" title="<?php _e('Edit', 'bp_gtm') ?>"><?php _e('Edit', 'bp_gtm'); ?></a>
<?php
}
if (bp_gtm_check_access('discuss_delete')) {
?>
<a class="delete_post" id="<?php echo $post_id ?>" rel="<?php echo $elem_type . '_' . $elem_id; ?>" href="#" title="<?php _e('Delete', 'bp_gtm') ?>"><?php _e('Delete', 'bp_gtm'); ?></a>
<?php
}
do_action('bp_gtm_discuss_admin_links');
}
// Load next page content
function bp_gtm_personal_tasks_navi_content() {
global $bp, $wpdb;
$data = explode('-', $_GET['nextPage']);
$limit['miss'] = ($data['0'] * $data['1']);
$limit['per_page'] = $data['1'];
if ($_GET['project'] && !$_GET['filter']) {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'project', $limit, $_GET['project']);
} elseif ($_GET['group'] && !$_GET['filter']) {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'group', $limit, $_GET['group']);
} else {
if ($_GET['filter'] == 'done') {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'done', $limit);
} elseif ($_GET['filter'] == 'alpha') {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'alpha', $limit);
} elseif ($_GET['filter'] == 'deadline') {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'deadline', $limit);
} elseif ($_GET['filter'] == 'without') {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'without', $limit);
} else {
$tasks = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'deadline', $limit);
}
}
if (count($tasks) > 0) {
$i = 1;
foreach ((array) $tasks as $task) {
if (is_int($i / 2)) {
$alt = ' alt';
} else {
$alt = '';
}
$gtm_link = bp_get_group_permalink() . $bp->gtm->slug . '/';
?>
<tr id="<?php echo $task->id; ?>" class="<?php
bp_gtm_task_check_date($task->id, $task->deadline);
echo $alt
?>">
<td class="td-title">
<a class="topic-title" href="<?php echo $gtm_link . $bp->current_action . '/view/' . $task->id ?>" title="<?php _e('Permalink on task\'s page', 'bp_gtm') ?>">
<?php echo $task->name; ?>
</a>
</td>
<td class="td-group">
<?php echo '<div class="object-name">
<a href="' . $gtm_link . 'projects/view/' . $task->project_id . '" title="' . __('Go to project\'s page', 'bp_gtm') . '">
' . bp_gtm_get_el_name_by_id($task->project_id, 'project') . '
</a>
</div>'; ?>
</td>
<td class="td-poster">
<?php
$group = groups_get_group(array('group_id' => $task->group_id));
//print_var($group);
echo '<a href="' . $gtm_link . '" title="' . $group->description . '">' . $group->name . '</a>';
?>
</td>
<td class="td-group"><div class="object-name" class="text-right"><?php bp_gtm_format_date($task->deadline); ?></div>
</td>
<?php do_action('bp_directory_personal_tasks_extra_cell') ?>
</tr>
<?php
do_action('bp_directory_personal_tasks_extra_row');
$i++;
}
} else {
echo '<div id="message" class="info"><p>' . __('There are no tasks to display.', 'bp_gtm') . '</p></div>';
}
}
add_action('wp_ajax_bp_gtm_personal_tasks_navi_content', 'bp_gtm_personal_tasks_navi_content');
// Display current role of a member in group members list
add_action('bp_group_members_list_item', 'bp_gtm_display_span_role');
function bp_gtm_display_span_role($user_id = false) {
global $bp, $members_template;
$bp_gtm = get_option('bp_gtm');
if ($bp_gtm['groups'] == 'all' || (!empty($bp_gtm['groups']) && array_key_exists($bp->groups->current_group->id, $bp_gtm['groups']) )) {
if (!$user_id)
$user_id = $members_template->member->user_id;
$role = bp_gtm_get_role_for_user($user_id);
if ($role)
$role_span = '<span class="activity role">' . __('Role', 'bp_gtm') . ' → ' . $role->role_name . '</span>';
if (!$role && groups_is_user_admin($user_id, $bp->groups->current_group->id))
$role_span = '<span class="activity role">' . __('Role', 'bp_gtm') . ' → ' . __('Group Admin', 'bp_gtm') . '</span>';
elseif (!$role && !groups_is_user_admin($user_id, $bp->groups->current_group->id))
$role_span = '<span class="activity role">' . __('No Role', 'bp_gtm') . '</span>';
echo $role_span;
}
}
function bp_gtm_role_actions($role) {
echo '<input id="input-' . $role->id . '" type="hidden" name="role[' . $role->id . '][role_id]" value="' . $role->id . '" />';
echo '<li id="li-' . $role->id . '" class="one">
#' . $role->id . ': ' . $role->role_name . ' → <input name="role[' . $role->id . '][role_name]" type="text" value="' . $role->role_name . '" />
<span class="actions">
<a id="role-open" rel="' . $role->id . '" class="button" href="">' . __('Permissions', 'bp_gtm') . '</a>
<a id="role-delete" rel="' . $role->id . '" class="button" href="">' . __('Delete role', 'bp_gtm') . '</a>
</span>
</li>
<div id="toggler">
<div id="box-' . $role->id . '" class="box">
<div class="left_block">
<div class="projects">
<p class="role_title">' . __('Projects', 'bp_gtm') . '</p><ul>';
$actions_project = bp_gtm_get_actions('project', 'all');
foreach ($actions_project as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /projects -->
<div class="tasks">
<p class="role_title">' . __('Tasks', 'bp_gtm') . '</p><ul>';
$actions_task = bp_gtm_get_actions('task', 'all');
foreach ($actions_task as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /tasks -->
<div class="delete">
<p class="role_title">' . __('Delete', 'bp_gtm') . '</p><ul>';
$actions_delete = bp_gtm_get_actions('delete', 'all');
foreach ($actions_delete as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /delete -->
</div><!-- /left_block -->
<div class="right_block">
<div class="taxon">
<p class="role_title">' . __('Classifier', 'bp_gtm') . '</p><ul>';
$actions_taxon = bp_gtm_get_actions('taxon', 'all');
foreach ($actions_taxon as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /taxon -->
<div class="involved">
<p class="role_title">' . __('Involved', 'bp_gtm') . '</p><ul>';
$actions_involved = bp_gtm_get_actions('involved', 'all');
foreach ($actions_involved as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /involved -->
<div class="discuss">
<p class="role_title">' . __('Discussions', 'bp_gtm') . '</p><ul>';
$actions_discuss = bp_gtm_get_actions('discuss', 'all');
foreach ($actions_discuss as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /discuss -->
<div class="settings">
<p class="role_title">' . __('Settings', 'bp_gtm') . '</p><ul>';
$actions_settings = bp_gtm_get_actions('settings', 'all');
foreach ($actions_settings as $action_slug => $action_name) {
echo '<li>
<input type="checkbox" name="role[' . $role->id . '][' . $action_slug . ']" value = "1" ' . bp_gtm_get_checked($role->$action_slug, '1') . ' /> ' . $action_name . '
</li>';
}
echo '</ul></div><!-- /settings -->
</div><!-- /right_block -->
</div><!-- /box --><div class"clear"></div>
</div><!-- /toggler -->';
}
function bp_gtm_get_presonal_tasks_option($bp_gtm_p_tasks_pp) {
global $bp;
$limit['per_page'] = $options['per_page'] = $bp_gtm_p_tasks_pp; // how many to show
$limit['miss'] = $options['miss'] = 0; // from the very first one - need to be on the 1st page
$options['done'] = 0;
$options['user'] = $bp->loggedin_user->id;
$options['id'] = 0;
$options['type'] = !empty($_GET['filter']) ? $_GET['filter'] : '';
$options['alpha_style'] = $options['deadline_style'] = $options['by_proj_style'] = $options['by_group_style'] = $options['done_style'] = '';
if (empty($_GET['project']) && empty($_GET['group'])) { // standard filters
$project_id = false;
if (!empty($_GET['filter']) && $_GET['filter'] == 'done') {
$options['done'] = 1;
$options['page_h4'] = __('All Completed Personal Tasks', 'bp_gtm');
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'done', $limit);
$options['done_style'] = 'class="grey"';
} elseif (!empty($_GET['filter']) && $_GET['filter'] == 'alpha') { // done
$options['page_h4'] = __('Personal Tasks by A/Z', 'bp_gtm');
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'alpha', $limit);
$options['alpha_style'] = 'class="grey"';
} elseif (empty($_GET['filter']) || $_GET['filter'] == 'deadline') { // done
$options['page_h4'] = __('Personal Tasks by Deadline', 'bp_gtm');
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'deadline', $limit);
$options['deadline_style'] = 'class="grey"';
} elseif (!empty($_GET['filter']) && $_GET['filter'] == 'without') { // done
$options['page_h4'] = __('Personal Tasks without Projects', 'bp_gtm');
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'without', $limit);
$options['by_proj_style'] = 'class="grey"';
}
} elseif (empty($_GET['project']) && !empty($_GET['group'])) { // show tasks in group
$options['group'] = groups_get_group(array('group_id' => $_GET['group']));
$options['page_h4'] = __('Personal Tasks in Group', 'bp_gtm') . ' "' . $group->name . '"';
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'group', $limit, $_GET['group']);
$options['id'] = $_GET['group'];
$options['type'] = 'group';
$options['by_group_style'] = 'class="grey"';
} elseif (!empty($_GET['project']) && empty($_GET['group'])) { // show tasks in project
$options['page_h4'] = __('Personal Tasks in Project', 'bp_gtm') . ' "' . bp_gtm_get_el_name_by_id($_GET['project'], 'project') . '"';
$options['tasks'] = BP_GTM_Personal::get_tasks($bp->loggedin_user->id, $filter = 'project', $limit, $_GET['project']);
$options['id'] = $_GET['project'];
$options['type'] = 'project';
$options['by_proj_style'] = 'class="grey"';
}
return $options;
}
function bp_gtm_get_personal_filter_project_list() {
global $bp;
?> <div id="toggler" class="padder">
<div id="box" class="filter_project">
<p><strong><?php _e('Projects List', 'bp_gtm') ?></strong><span class="close"><a id="open_project" href="#" title="<?php _e('Close', 'bp_gtm'); ?>">X</a></span></p>
<ul class="projects-filter">
<li><a href="tasks?filter=without">Without Project</a></li><?php
$projects = BP_GTM_Personal::get_projects($bp->loggedin_user->id, $filter = 'alpha');
foreach ($projects as $project) {
$personal_link = $bp->loggedin_user->domain . $bp->gtm->slug . '/';
echo '<li><a href="' . $personal_link . 'tasks?project=' . $project->id . '"> ' . $project->name . '</a></li>';
}
?>
</ul>
<p><small><?php _e('Click on a project to see its tasks', 'bp_gtm'); ?></small></p>
</div>
<?php
return TRUE;
}
function bp_gtm_get_personal_filter_group_list() {
global $bp;
?>
<div id="box" class="filter_group">
<p><strong><?php _e('Groups List', 'bp_gtm') ?></strong><span class="close"><a id="open_group" href="#" title="<?php _e('Close', 'bp_gtm'); ?>">X</a></span></p>
<ul class="projects-filter">
<?php
$groups = BP_GTM_Personal::get_groups($bp->loggedin_user->id, $filter = 'alpha');
foreach ($groups as $group) {
$personal_link = $bp->loggedin_user->domain . $bp->gtm->slug . '/';
echo '<li><a href="' . $personal_link . 'tasks?group=' . $group->id . '"> ' . $group->name . '</a></li>';
}
?>
</ul>
<p><small><?php _e('Click on a group to see its tasks', 'bp_gtm'); ?></small></p>
</div>
<?php
}
function bp_gtm_get_groups_filter_list() {
?>
<div id="toggler">
<div id="box" id="box">
<p><strong><?php _e('Projects List', 'bp_gtm') ?></strong><span class="close"><a id="open" href="#" title="<?php _e('Close', 'bp_gtm'); ?>">X</a></span></p>
<ul class="projects-filter">
<li><a href="tasks?filter=without">Without Project</a></li>
<?php
$projects = bp_gtm_get_projects(bp_get_current_group_id(), $option['filter'] = 'alpha');
foreach ($projects as $project) {
echo '<li><a href="' . $gtm_link . 'tasks?project=' . $project->id . '"> ' . $project->name . '</a></li>';
}
?>
</ul>
<p><small><?php _e('Click on a project to see its tasks', 'bp_gtm'); ?></small></p>
</div>
</div>
<?php
}
function bp_gtm_get_personal_task_list($tasks) {
global $bp;
foreach ($tasks as $task) {
$group = groups_get_group(array('group_id' => $task->group_id));
$gtm_link = bp_get_group_permalink($group) . $bp->gtm->slug . '/';
?>
<tr id="<?php echo $task->id; ?>" class="<?php bp_gtm_task_check_date($task->id, $task->deadline); ?>">
<td class="td-title">
<a class="topic-title" href="<?php echo $gtm_link . $bp->current_action . '/view/' . $task->id ?>" title="<?php _e('Permalink on task\'s page', 'bp_gtm') ?>">
<?php echo $task->name; ?>
</a>
</td>
<td class="td-group">
<?php echo '<div class="object-name">
<a href="' . $gtm_link . 'projects/view/' . $task->project_id . '" title="' . __('Go to project\'s page', 'bp_gtm') . '">
' . bp_gtm_get_el_name_by_id($task->project_id, 'project') . '
</a>
</div>'; ?>
</td>
<td class="td-poster">
<?php
echo '<a href="' . $gtm_link . '" title="' . $group->description . '">' . $group->name . '</a>';
?>
</td>
<td class="td-group">
<div class="object-name center"><?php bp_gtm_format_date($task->deadline); ?></div>
</td>
<?php do_action('bp_gtm_personal_tasks_extra_cell') ?>
</tr>
<?php
do_action('bp_gtm_personal_tasks_extra_row');
}
}
function bp_gtm_get_personal_project_list($projects) {
global $bp;
foreach ((array) $projects as $project) {
$group = groups_get_group(array('group_id' => $project->group_id));
$gtm_url = bp_get_group_permalink($group) . $bp->gtm->slug
?>
<tr class="">
<td class="td-title">
<a class="topic-title" href="<?php echo $gtm_url . '/projects/view/' . $project->id ?>" title="<?php _e('Permalink', 'bp_gtm') ?>">
<?php echo $project->name; ?>
</a>
</td>
<td class="td-poster"><!-- group name -->
<?php
echo '<a href="' . $gtm_url . '" title="' . $group->description . '">' . $group->name . '</a>';
?>
</td>
<td class="td-poster">
<div class="object-name" class="center"><?php bp_gtm_format_date($project->deadline); ?></div>
</td>
<?php do_action('bp_gtm_personal_projects_extra_cell') ?>
</tr>
<?php
do_action('bp_gtm_personal_projects_extra_row');
}
}
function bp_gtm_get_personal_profile_settings() {
global $bp;
$options['filter'] = !empty($_GET['filter']) ? $_GET['filter'] : '';
if (empty($_GET['filter']) || $_GET['filter'] == 'deadline') {
$options['projects'] = BP_GTM_Personal::get_projects($bp->loggedin_user->id, $options['filter']);
$options['h4_title'] = __('Personal Projects by Deadline', 'bp_gtm');
$options['styles_d_cur'] = 'grey';
} elseif ($_GET['filter'] == 'alpha') {
$options['projects'] = BP_GTM_Personal::get_projects($bp->loggedin_user->id, $options['filter']);
$options['h4_title'] = __('Personal Projects by A/Z', 'bp_gtm');
$options['styles_a_cur'] = 'grey';
}
return $options;
}
function bp_gtm_get_discussion_settings($bp_gtm_group_settings) {
$options = array();
$limit['per_page'] = $bp_gtm_group_settings['discuss_pp']; // how many to show
$limit['miss'] = 0; // from the very first one - need to be on the 1st page
if (empty($_GET['filter']) || $_GET['filter'] == 'tasks') {
$options['h4_title'] = __('Tasks Discussions', 'bp_gtm');
$options['type'] = 'tasks';
$options['th_title'] = __('Task Name', 'bp_gtm');
$options['styles_t_cur'] = 'grey';
$options['styles_p_cur'] = '';
} elseif (!empty($_GET['filter']) && $_GET['filter'] == 'projects') {
$options['h4_title'] = __('Projects Discussions', 'bp_gtm');
$options['th_title'] = __('Project Name', 'bp_gtm');
$options['type'] = 'projects';
$options['styles_t_cur'] = '';
$options['styles_p_cur'] = 'grey';
}
$options['posts'] = BP_GTM_Discussion::get_list(bp_get_current_group_id(), $options['type'], $limit);
return $options;
}
function bp_gtm_get_group_project_respossibles($project) {
$users_logins = explode(' ', $project->resp_id);
$arg['width'] = '25';
$arg['height'] = '25';
if (count($users_logins) > 1) {
foreach ($users_logins as $users_login) {
$arg['item_id'] = bp_core_get_userid($users_login);
?>
<div class="poster-name">
<a href="<?php echo bp_core_get_userlink($arg['item_id'], false, true); ?>" title="<?php echo bp_core_get_userlink($arg['item_id'], true, false); ?>">
<?php echo bp_core_fetch_avatar($arg); ?>
</a>
</div>
<?php
}
} else {
$arg['item_id'] = bp_core_get_userid($users_logins['0']);
?>
<div class="poster-name"><?php
echo bp_core_fetch_avatar($arg);
echo bp_core_get_userlink($arg['item_id']);
?></div>
<?php
}
}
function bp_gtm_get_done_undone_links($project_id, $project_group_id, $gtm_link) {
$count = BP_GTM_Projects::get_count_tasks($project_id, $project_group_id);
echo '<a href="' . $gtm_link . 'tasks?project=' . $project_id . '"
title="' . __('Pending tasks', 'bp_gtm') . '">' . $count['undone'] . '</a>
/ <a href="' . $gtm_link . 'tasks?project=' . $project_id . '&filter=done"