forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout_api.php
1333 lines (1118 loc) · 40.5 KB
/
layout_api.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
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Layout API
*
* UI functions to render layout elements in every page. The layout api layer sits above the html api and abstract
* the lower level html markup into web components
*
* Here is the call order for the layout functions
*
* layout_page_header
* layout_page_header_begin
* layout_page_header_end
* layout_page_begin
* ...Page content here...
* layout_page_end
*
*
*
* @package CoreAPI
* @subpackage LayoutAPI
* @copyright Copyright 2014 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses access_api.php
* @uses utility_api.php
*/
require_api( 'access_api.php' );
require_api( 'utility_api.php' );
/**
* Print the page header section
* @param string $p_page_title Html page title.
* @param string $p_redirect_url URL to redirect to if necessary.
* @param string $p_page_id The page id.
* @return void
*/
function layout_page_header( $p_page_title = null, $p_redirect_url = null, $p_page_id = null ) {
layout_page_header_begin( $p_page_title );
if( $p_redirect_url !== null ) {
html_meta_redirect( $p_redirect_url );
}
layout_page_header_end( $p_page_id );
}
/**
* Print the part of the page that comes before meta redirect tags should be inserted
* @param string $p_page_title Page title.
* @return void
*/
function layout_page_header_begin( $p_page_title = null ) {
html_begin();
html_head_begin();
html_content_type();
global $g_robots_meta;
if( !is_blank( $g_robots_meta ) ) {
echo "\t", '<meta name="robots" content="', $g_robots_meta, '" />', "\n";
}
html_title( $p_page_title );
layout_head_meta();
html_css();
layout_head_css();
html_rss_link();
$t_favicon_image = config_get( 'favicon_image' );
if( !is_blank( $t_favicon_image ) ) {
echo "\t", '<link rel="shortcut icon" href="', helper_mantis_url( $t_favicon_image ), '" type="image/x-icon" />', "\n";
}
# Advertise the availability of the browser search plug-ins.
$t_title = config_get( 'search_title' );
$t_searches = array( 'text', 'id' );
foreach( $t_searches as $t_type ) {
echo "\t",
'<link rel="search" type="application/opensearchdescription+xml" ',
'title="' . sprintf( lang_get( "opensearch_{$t_type}_description" ), $t_title ) . '" ',
'href="' . string_sanitize_url( 'browser_search_plugin.php?type=' . $t_type, true ) .
'"/>',
"\n";
}
html_head_javascript();
}
/**
* Print the part of the page that comes after meta tags and before the
* actual page content, but without login info or menus. This is used
* directly during the login process and other times when the user may
* not be authenticated
*
* @param string $p_page_id The id of the page.
*
* @return void
*/
function layout_page_header_end( $p_page_id = null) {
global $g_error_send_page_header;
event_signal( 'EVENT_LAYOUT_RESOURCES' );
html_head_end();
if ( $p_page_id === null ) {
$t_body_id = '';
} else {
$t_body_id = 'id="' . $p_page_id . '" ';
}
# Add right-to-left css if needed
if( layout_is_rtl() ) {
echo '<body ' . $t_body_id . 'class="skin-3 rtl">', "\n";
} else {
echo '<body ' . $t_body_id . 'class="skin-3">', "\n";
}
# Set user font preference
layout_user_font_preference();
event_signal( 'EVENT_LAYOUT_BODY_BEGIN' );
$g_error_send_page_header = false;
}
/**
* Print page common elements including navbar, sidebar, info bar
* @param string $p_active_sidebar_page sidebar page where the current page lives under
* @return void
*/
function layout_page_begin( $p_active_sidebar_page = null ) {
if( !db_is_connected() ) {
return;
}
current_user_modify_single_project_default();
layout_navbar();
layout_main_container_begin();
layout_print_sidebar( $p_active_sidebar_page );
layout_main_content_begin();
layout_breadcrumbs();
layout_page_content_begin();
if( auth_is_user_authenticated() ) {
if( ON == config_get( 'show_project_menu_bar' ) ) {
echo '<div class="row">' , "\n";
print_project_menu_bar();
echo '</div>' , "\n";
}
}
echo '<div class="row">' , "\n";
event_signal( 'EVENT_LAYOUT_CONTENT_BEGIN' );
}
/**
* Print elements at the end of each page
* @return void
*/
function layout_page_end() {
if( !db_is_connected() ) {
return;
}
event_signal( 'EVENT_LAYOUT_CONTENT_END' );
echo '</div>' , "\n";
layout_page_content_end();
layout_main_content_end();
layout_footer();
layout_scroll_up_button();
layout_main_container_end();
layout_body_javascript();
html_body_end();
html_end();
}
/**
* Print common elements for admin pages
* @return void
*/
function layout_admin_page_begin() {
layout_navbar();
layout_main_container_begin();
}
/**
* Print elements at the end of each admin page
* @return void
*/
function layout_admin_page_end() {
layout_footer();
layout_scroll_up_button();
layout_main_container_end();
layout_body_javascript();
html_body_end();
html_end();
}
/**
* Check if the layout is setup for right to left languages
* @return bool
*/
function layout_is_rtl() {
if( lang_get( 'directionality' ) == 'rtl' ) {
return true;
}
return false;
}
/**
* Print meta tags for the page head
* @return void
*/
function layout_head_meta() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />' . "\n";
}
/**
* Print css link directives for the head section of the page
* @return void
*/
function layout_head_css() {
# bootstrap & fontawesome
if ( config_get_global( 'cdn_enabled' ) == ON ) {
html_css_cdn_link( 'https://stackpath.bootstrapcdn.com/bootstrap/' . BOOTSTRAP_VERSION . '/css/bootstrap.min.css',BOOTSTRAP_HASH_CSS );
html_css_cdn_link( 'https://stackpath.bootstrapcdn.com/font-awesome/' . FONT_AWESOME_VERSION . '/css/font-awesome.min.css', FONT_AWESOME_HASH );
# theme text fonts
$t_font_family = config_get( 'font_family', null, null, ALL_PROJECTS );
html_css_cdn_link( 'https://fonts.googleapis.com/css?family=' . urlencode( $t_font_family ) );
# datetimepicker
html_css_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/' . DATETIME_PICKER_VERSION . '/css/bootstrap-datetimepicker.min.css', DATETIME_PICKER_HASH_CSS );
} else {
html_css_link( 'bootstrap-' . BOOTSTRAP_VERSION . '.min.css' );
html_css_link( 'font-awesome-' . FONT_AWESOME_VERSION . '.min.css' );
# theme text fonts
html_css_link( 'fonts.css' );
# datetimepicker
html_css_link( 'bootstrap-datetimepicker-' . DATETIME_PICKER_VERSION . '.min.css' );
}
# page specific plugin styles
# theme styles
html_css_link( 'ace.min.css' );
html_css_link( 'ace-mantis.css' );
html_css_link( 'ace-skins.min.css' );
if( layout_is_rtl() ) {
html_css_link( 'ace-rtl.min.css' );
}
echo "\n";
}
/**
* Print user font preference
* @return void
*/
function layout_user_font_preference() {
$t_font_family = config_get( 'font_family', null, null, ALL_PROJECTS );
echo '<style>', "\n";
echo '* { font-family: "' . $t_font_family . '"; } ', "\n";
echo 'h1, h2, h3, h4, h5 { font-family: "' . $t_font_family . '"; } ', "\n";
echo '</style>', "\n";
}
/**
* Print javascript directives before the closing of the page body element
* @return void
*/
function layout_body_javascript() {
if ( config_get_global( 'cdn_enabled' ) == ON ) {
# bootstrap
html_javascript_cdn_link( 'https://stackpath.bootstrapcdn.com/bootstrap/' . BOOTSTRAP_VERSION . '/js/bootstrap.min.js', BOOTSTRAP_HASH_JS );
# moment & datetimepicker
html_javascript_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/' . MOMENT_VERSION . '/moment-with-locales.min.js', MOMENT_HASH );
html_javascript_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/' . DATETIME_PICKER_VERSION . '/js/bootstrap-datetimepicker.min.js', DATETIME_PICKER_HASH_JS );
# typeahead.js
html_javascript_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/corejs-typeahead/' . TYPEAHEAD_VERSION . '/typeahead.jquery.min.js', TYPEAHEAD_HASH );
# listjs
html_javascript_cdn_link( 'https://cdnjs.cloudflare.com/ajax/libs/list.js/' . LISTJS_VERSION . '/list.min.js', LISTJS_HASH );
} else {
# bootstrap
html_javascript_link( 'bootstrap-' . BOOTSTRAP_VERSION . '.min.js' );
# moment & datetimepicker
html_javascript_link( 'moment-with-locales-' . MOMENT_VERSION . '.min.js' );
html_javascript_link( 'bootstrap-datetimepicker-' . DATETIME_PICKER_VERSION . '.min.js' );
# typeahead.js
html_javascript_link( 'typeahead.jquery-' . TYPEAHEAD_VERSION . '.min.js' );
# listjs
html_javascript_link( 'list-' . LISTJS_VERSION . '.min.js' );
}
# ace theme scripts
html_javascript_link( 'ace.min.js' );
}
/**
* Print opening markup for login/signup/register pages
* @return void
*/
function layout_login_page_begin() {
html_begin();
html_head_begin();
html_content_type();
global $g_robots_meta;
if( !is_blank( $g_robots_meta ) ) {
echo "\t", '<meta name="robots" content="', $g_robots_meta, '" />', "\n";
}
html_title();
layout_head_meta();
html_css();
layout_head_css();
html_rss_link();
$t_favicon_image = config_get( 'favicon_image' );
if( !is_blank( $t_favicon_image ) ) {
echo "\t", '<link rel="shortcut icon" href="', helper_mantis_url( $t_favicon_image ), '" type="image/x-icon" />', "\n";
}
# Advertise the availability of the browser search plug-ins.
echo "\t", '<link rel="search" type="application/opensearchdescription+xml" title="MantisBT: Text Search" href="' . string_sanitize_url( 'browser_search_plugin.php?type=text', true) . '" />' . "\n";
echo "\t", '<link rel="search" type="application/opensearchdescription+xml" title="MantisBT: Issue Id" href="' . string_sanitize_url( 'browser_search_plugin.php?type=id', true) . '" />' . "\n";
html_head_javascript();
event_signal( 'EVENT_LAYOUT_RESOURCES' );
html_head_end();
echo '<body class="login-layout light-login">';
# Set font preference
layout_user_font_preference();
layout_main_container_begin();
layout_main_content_begin();
echo '<div class="row">';
}
/**
* Print closing markup for login/signup/register pages
* @return void
*/
function layout_login_page_end() {
echo '</div>';
layout_main_content_end();
layout_main_container_end();
layout_body_javascript();
echo '</body>', "\n";
}
/**
* Render navbar at the top of the page
* @return void
*/
function layout_navbar() {
$t_logo_url = config_get_global('logo_url');
$t_short_path = config_get_global('short_path');
echo '<div id="navbar" class="navbar navbar-default navbar-collapse navbar-fixed-top noprint">';
echo '<div id="navbar-container" class="navbar-container">';
echo '<button id="menu-toggler" type="button" class="navbar-toggle menu-toggler pull-left hidden-lg hidden-md" data-target="#sidebar">';
echo '<span class="sr-only">Toggle sidebar</span>';
echo '<span class="icon-bar"></span>';
echo '<span class="icon-bar"></span>';
echo '<span class="icon-bar"></span>';
echo '</button>';
echo '<div class="navbar-header">';
echo '<a href="' . $t_short_path . $t_logo_url . '" class="navbar-brand">';
echo '<span class="smaller-75"> ';
echo string_display_line( config_get('window_title') );
echo ' </span>';
echo '</a>';
$t_toggle_class = (OFF == config_get('show_avatar') ? 'navbar-toggle' : 'navbar-toggle-img');
echo '<button type="button" class="navbar-toggle ' . $t_toggle_class . ' collapsed pull-right hidden-sm hidden-md hidden-lg" data-toggle="collapse" data-target=".navbar-buttons,.navbar-menu">';
echo '<span class="sr-only">Toggle user menu</span>';
if (auth_is_user_authenticated()) {
layout_navbar_user_avatar();
}
echo '</button>';
echo '</div>';
echo '<div class="navbar-buttons navbar-header navbar-collapse collapse">';
echo '<ul class="nav ace-nav">';
if (auth_is_user_authenticated()) {
# shortcuts button bar
layout_navbar_button_bar();
# projects dropdown menu
layout_navbar_projects_menu();
# user buttons such as messages, notifications and user menu
layout_navbar_user_menu();
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '</div>';
}
/**
* Print navbar menu item
* @param string $p_url destination url of the menu item
* @param string $p_title menu item title
* @param string $p_icon icon to use for this menu
* @return void
*/
function layout_navbar_menu_item( $p_url, $p_title, $p_icon ) {
echo '<li>';
echo '<a href="' . $p_url . '">';
echo '<i class="ace-icon fa ' . $p_icon . '"> </i> ' . $p_title;
echo '</a>';
echo '</li>';
}
/**
* Print navbar user menu at the top right of the page
* @param bool $p_show_avatar decide whether to show logged in user avatar
* @return void
*/
function layout_navbar_user_menu( $p_show_avatar = true ) {
if( !auth_is_user_authenticated() ) {
return;
}
$t_username = current_user_get_field( 'username' );
echo '<li class="grey">';
echo '<a data-toggle="dropdown" href="#" class="dropdown-toggle">';
if( $p_show_avatar ) {
layout_navbar_user_avatar();
echo '<span class="user-info">';
echo $t_username;
echo '</span>';
echo '<i class="ace-icon fa fa-angle-down"></i>';
} else {
echo ' ' . $t_username . ' ' . "\n";
echo '<i class="ace-icon fa fa-angle-down bigger-110"></i>';
}
echo '</a>';
echo '<ul class="user-menu dropdown-menu dropdown-menu-right dropdown-yellow dropdown-caret dropdown-close">';
# My Account
if( !current_user_is_protected() ) {
layout_navbar_menu_item( helper_mantis_url( 'account_page.php' ), lang_get( 'account_link' ), 'fa-user' );
}
# RSS Feed
if( OFF != config_get( 'rss_enabled' ) ) {
layout_navbar_menu_item( htmlspecialchars( rss_get_issues_feed_url() ), lang_get( 'rss' ), 'fa-rss-square orange' );
}
echo '<li class="divider"></li>';
# Logout
layout_navbar_menu_item( helper_mantis_url( auth_logout_page() ), lang_get( 'logout_link' ), 'fa-sign-out' );
echo '</ul>';
echo '</li>';
}
/**
* Print navbar projects menu at the top right of the page
* @return void
*/
function layout_navbar_projects_menu() {
if( !layout_navbar_can_show_projects_menu() ) {
return;
}
echo '<li class="grey" id="dropdown_projects_menu">' . "\n";
echo '<a data-toggle="dropdown" href="#" class="dropdown-toggle">' . "\n";
$t_current_project_id = helper_get_current_project();
# Check user's access to the project, and if not authorized select display
# ALL PROJECTS to avoid disclosing the private project's name.
if( ALL_PROJECTS == $t_current_project_id || !access_get_project_level( $t_current_project_id ) ) {
echo ' ' . string_attribute( lang_get( 'all_projects' ) ) . ' ' . "\n";
} else {
echo ' ' . string_attribute( project_get_field( $t_current_project_id, 'name' ) ) . ' ' . "\n";
}
echo ' <i class="ace-icon fa fa-angle-down bigger-110"></i>' . "\n";
echo '</a>' . "\n";
echo '<ul id="projects-list" class=" dropdown-menu dropdown-menu-right dropdown-yellow dropdown-caret dropdown-close">' . "\n";
layout_navbar_projects_list( implode( ';', helper_get_current_project_trace() ), true, null, true );
echo '</ul>' . "\n";
echo '</li>' . "\n";
}
/**
* Print navbar buttons
* @return void
*/
function layout_navbar_button_bar() {
if( !auth_is_user_authenticated() ) {
return;
}
$t_show_report_bug_button = access_has_any_project_level( 'report_bug_threshold' ) &&
!is_page_name( string_get_bug_page( "report" ) ) &&
!is_page_name( string_get_bug_page( "update" ) );
$t_show_invite_user_button = access_has_global_level( config_get( 'manage_user_threshold' ) );
if( !$t_show_report_bug_button && !$t_show_invite_user_button ) {
return;
}
echo '<li class="hidden-sm hidden-xs">';
echo '<div class="btn-group btn-corner padding-right-8 padding-left-8">';
if( $t_show_report_bug_button ) {
$t_bug_url = string_get_bug_report_url();
echo '<a class="btn btn-primary btn-sm" href="' . $t_bug_url . '">';
echo '<i class="fa fa-edit"></i> ' . lang_get( 'report_bug_link' );
echo '</a>';
}
if( $t_show_invite_user_button ) {
echo '<a class="btn btn-primary btn-sm" href="manage_user_create_page.php">';
echo '<i class="fa fa-user-plus"></i> ' . lang_get( 'invite_users' );
echo '</a>';
}
echo '</div>';
echo '</li>';
}
/**
* Print projects that the current user has access to.
*
* @param int $p_project_id The current project id or null to use cookie.
* @param bool $p_include_all_projects true: include "All Projects", otherwise false.
* @param int|null $p_filter_project_id The id of a project to exclude or null.
* @param string|bool $p_trace The current project trace, identifies the sub-project via a path from top to bottom.
* @return void
*/
function layout_navbar_projects_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false ) {
$t_user_id = auth_get_current_user_id();
# Cache all needed projects
project_cache_array_rows( user_get_all_accessible_projects( $t_user_id ) );
# Get top level projects
$t_project_ids = user_get_accessible_projects( $t_user_id );
echo '<li>';
echo '<div class="projects-searchbox">';
echo '<input class="search form-control input-md" placeholder="' . lang_get( 'search' ) . '" />';
echo '</div>';
echo '</li>';
echo '<li class="divider"></li>' . "\n";
echo '<li>';
echo '<div class="scrollable-menu">';
echo '<ul class="list dropdown-yellow no-margin">';
if( $p_include_all_projects && $p_filter_project_id !== ALL_PROJECTS ) {
echo ALL_PROJECTS == $p_project_id ? '<li class="active">' : '<li>';
echo '<a href="' . helper_mantis_url( 'set_project.php' ) . '?project_id=' . ALL_PROJECTS . '">';
echo lang_get( 'all_projects' ) . ' </a></li>' . "\n";
echo '<li class="divider"></li>' . "\n";
}
foreach( $t_project_ids as $t_id ) {
echo 0 == strcmp( $t_id, $p_project_id ) ? '<li class="active">' : '<li>';
echo '<a href="' . helper_mantis_url( 'set_project.php' ) . '?project_id=' . $t_id . '"';
echo ' class="project-link"> ' . string_attribute( project_get_field( $t_id, 'name' ) ) . ' </a></li>' . "\n";
layout_navbar_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace );
}
echo '</ul>';
echo '</div>';
echo '</li>';
}
/**
* List projects that the current user has access to
*
* @param integer $p_parent_id A parent project identifier.
* @param integer $p_project_id A project identifier.
* @param integer $p_filter_project_id A filter project identifier.
* @param boolean $p_trace Whether to trace parent projects.
* @param array $p_parents Array of parent projects.
* @return void
*/
function layout_navbar_subproject_option_list( $p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_trace = false, array $p_parents = array() ) {
array_push( $p_parents, $p_parent_id );
$t_user_id = auth_get_current_user_id();
$t_project_ids = user_get_accessible_subprojects( $t_user_id, $p_parent_id );
foreach( $t_project_ids as $t_id ) {
if( $p_trace ) {
$t_full_id = implode( ";", $p_parents ) . ';' . $t_id;
} else {
$t_full_id = $t_id;
}
echo 0 == strcmp( $p_project_id, $t_full_id ) ? '<li class="active">' : '<li>';
echo '<a href="' . helper_mantis_url( 'set_project.php' ) . '?project_id=' . $t_full_id . '"';
echo ' class="project-link"> ' . str_repeat( ' ', count( $p_parents ) * 4 );
echo string_attribute( project_get_field( $t_id, 'name' ) ) . '</a></li>' . "\n";
layout_navbar_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_parents );
}
}
/**
* Print user avatar in the navbar
* @param string $p_img_class css class to use with the img tag
* @return void
*/
function layout_navbar_user_avatar( $p_img_class = 'nav' ) {
$t_default_avatar = '<i class="ace-icon fa fa-user fa-2x white"></i> ';
if( OFF === config_get( 'show_avatar' ) ) {
echo $t_default_avatar;
return;
}
$p_user_id = auth_get_current_user_id();
if( !user_exists( $p_user_id ) ) {
echo $t_default_avatar;
return;
}
if( access_has_project_level( config_get( 'show_avatar_threshold' ), null, $p_user_id ) ) {
$t_avatar = Avatar::get( $p_user_id, 40 );
if( false !== $t_avatar ) {
echo prepare_raw_avatar( $t_avatar, $p_img_class, 40 );
return;
}
}
echo $t_default_avatar;
}
/**
* Print sidebar
* @param string $p_active_sidebar_page page where the displayed page lives under
* @return void
*/
function layout_print_sidebar( $p_active_sidebar_page = null ) {
if( auth_is_user_authenticated() ) {
$t_current_project = helper_get_current_project();
# Store all items in an array before outputting
$t_sidebar_items = array();
# Plugin / Event added options
$t_event_menu_main_front = event_signal( 'EVENT_MENU_MAIN_FRONT' );
$t_plugin_menu_items_front = layout_plugin_menu_options_for_sidebar( $t_event_menu_main_front );
if( is_array( $t_plugin_menu_items_front ) ) {
$t_sidebar_items = $t_plugin_menu_items_front;
}
# Main Page
if( config_get( 'news_enabled' ) == ON ) {
$t_sidebar_items[] = array(
'url' => 'main_page.php',
'title' => 'main_link',
'icon' => 'fa-bullhorn'
);
}
# My View
$t_sidebar_items[] = array(
'url' => 'my_view_page.php',
'title' => 'my_view_link',
'icon' => 'fa-dashboard'
);
# View Bugs
$t_sidebar_items[] = array(
'url' => 'view_all_bug_page.php',
'title' => 'view_bugs_link',
'icon' => 'fa-list-alt'
);
# Report Bugs
if( access_has_any_project_level( 'report_bug_threshold' ) ) {
$t_sidebar_items[] = array(
'url' => string_get_bug_report_url(),
'title' => 'report_bug_link',
'icon' => 'fa-edit'
);
}
# Changelog Page
$t_sidebar_items[] = array(
'url' => 'changelog_page.php',
'title' => 'changelog_link',
'icon' => 'fa-retweet',
'access_level' => config_get( 'view_changelog_threshold' )
);
# Roadmap Page
$t_sidebar_items[] = array(
'url' => 'roadmap_page.php',
'title' => 'roadmap_link',
'icon' => 'fa-road',
'access_level' => config_get( 'roadmap_view_threshold' )
);
# Summary Page
$t_sidebar_items[] = array(
'url' => 'summary_page.php',
'title' => 'summary_link',
'icon' => 'fa-bar-chart-o',
'access_level' => config_get( 'view_summary_threshold' )
);
# Project Documentation Page
if( ON == config_get( 'enable_project_documentation' ) ) {
$t_sidebar_items[] = array(
'url' => 'proj_doc_page.php',
'title' => 'docs_link',
'icon' => 'fa-book'
);
}
# Project Wiki
if( ON == config_get_global( 'wiki_enable' ) ) {
$t_sidebar_items[] = array(
'url' => 'wiki.php?type=project&id=' . $t_current_project,
'title' => 'wiki',
'icon' => 'fa-book'
);
}
# Manage Users (admins) or Manage Project (managers) or Manage Custom Fields
$t_link = layout_manage_menu_link();
if( !is_blank( $t_link ) ) {
$t_sidebar_items[] = array(
'url' => $t_link,
'title' => 'manage_link',
'icon' => 'fa-gears',
);
}
# Time Tracking / Billing
if( config_get( 'time_tracking_enabled' ) && access_has_project_level( config_get( 'time_tracking_reporting_threshold', $t_current_project ) ) ) {
$t_sidebar_items[] = array(
'url' => 'billing_page.php',
'title' => 'time_tracking_billing_link',
'icon' => 'fa-clock-o',
);
}
# Plugin / Event added options
$t_event_menu_main = event_signal( 'EVENT_MENU_MAIN' );
$t_plugin_menu_items_back = layout_plugin_menu_options_for_sidebar( $t_event_menu_main );
if( is_array( $t_plugin_menu_items_back ) ) {
$t_sidebar_items = array_merge( $t_sidebar_items, $t_plugin_menu_items_back );
}
# Config based custom options
$t_config_menu_items = layout_config_menu_options_for_sidebar();
if( is_array( $t_config_menu_items ) ) {
$t_sidebar_items = array_merge( $t_sidebar_items, $t_config_menu_items );
}
# Allow plugins to alter the sidebar items array
$t_modified_sidebar_items = event_signal( 'EVENT_MENU_MAIN_FILTER', array( $t_sidebar_items ) );
if( is_array( $t_modified_sidebar_items ) && count( $t_modified_sidebar_items ) > 0 ) {
$t_sidebar_items = $t_modified_sidebar_items[0];
}
if( count( $t_sidebar_items ) > 0 ) {
# Starting sidebar markup
layout_sidebar_begin();
# Output the sidebar items
layout_options_for_sidebar( $t_sidebar_items, $p_active_sidebar_page );
# Ending sidebar markup
layout_sidebar_end();
}
}
}
/**
* Process plugin menu options for sidebar
* @param array $p_plugin_event_response The response from the plugin event signal.
* @return array containing sidebar items
*/
function layout_plugin_menu_options_for_sidebar( $p_plugin_event_response ) {
$t_menu_options = array();
foreach( $p_plugin_event_response as $t_plugin => $t_plugin_menu_options ) {
foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
if( is_array( $t_callback_menu_options ) ) {
$t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
} else {
if( !is_null( $t_callback_menu_options ) ) {
$t_menu_options[] = $t_callback_menu_options;
}
}
}
}
return $t_menu_options;
}
/**
* Process main menu options from config.
* @return array containing sidebar items
*/
function layout_config_menu_options_for_sidebar( ) {
$t_menu_options = array();
$t_custom_options = config_get( 'main_menu_custom_options' );
foreach( $t_custom_options as $t_custom_option ) {
if( isset( $t_custom_option['url'] ) ) {
$t_menu_option = $t_custom_option;
} else {
# Support < 2.0.0 custom menu options config format
$t_menu_option = array();
$t_menu_option['title'] = $t_custom_option[0];
$t_menu_option['access_level'] = $t_custom_option[1];
$t_menu_option['url'] = $t_custom_option[2];
}
$t_menu_options[] = $t_menu_option;
}
return $t_menu_options;
}
/**
* Process main menu options
* @param array $p_menu_options Array of menu options to output.
* @param string $p_active_sidebar_page The active page on the sidebar.
* @return void
*/
function layout_options_for_sidebar( $p_menu_options, $p_active_sidebar_page ) {
foreach( $p_menu_options as $t_menu_option ) {
$t_icon = isset( $t_menu_option['icon'] ) ? $t_menu_option['icon'] : 'fa-plug';
if( !isset( $t_menu_option['url'] ) || !isset( $t_menu_option['title'] ) ) {
continue;
}
if( isset( $t_menu_option['access_level'] ) ) {
if( !access_has_project_level( $t_menu_option['access_level'] ) ) {
continue;
}
}
layout_sidebar_menu( $t_menu_option['url'], $t_menu_option['title'], $t_icon, $p_active_sidebar_page );
}
}
/**
* Print sidebar opening elements
* @return void
*/
function layout_sidebar_begin() {
$t_collapse_block = is_collapsed( 'sidebar' );
$t_block_css = $t_collapse_block ? 'menu-min' : '';
echo '<div id="sidebar" class="sidebar sidebar-fixed responsive compact ' . $t_block_css . '">';
echo '<ul class="nav nav-list">';
}
/**
* Print sidebar menu item
* @param string $p_page page name
* @param string $p_title menu title in english
* @param string $p_icon icon to use for this menu
* @param string $p_active_sidebar_page page name to set as active
* @return void
*/
function layout_sidebar_menu( $p_page, $p_title, $p_icon, $p_active_sidebar_page = null ) {
if( $p_page == $p_active_sidebar_page ||
$p_page == basename( $_SERVER['SCRIPT_NAME'] ) ) {
echo '<li class="active">' . "\n";
} else {
echo '<li>' . "\n";
}
# Handle relative / absolute urls
if ( stripos( $p_page, 'https:' ) === 0 || stripos( $p_page, 'http:' ) === 0 ) {
$t_url = $p_page;
} else {
$t_url = helper_mantis_url( $p_page );
}
echo '<a href="' . $t_url . '">' . "\n";
echo '<i class="menu-icon fa ' . $p_icon . '"></i> ' . "\n";
echo '<span class="menu-text"> ' . lang_get_defaulted( $p_title ) . ' </span>' . "\n";
echo '</a>' . "\n";
echo '<b class="arrow"></b>' . "\n";
echo '</li>' . "\n";
}
/**
* Print sidebar closing elements
* @return void
*/
function layout_sidebar_end() {
echo '</ul>';
$t_collapse_block = is_collapsed( 'sidebar' );
echo '<div id="sidebar-btn" class="sidebar-toggle sidebar-collapse">';
if( layout_is_rtl() ) {
$t_block_icon = $t_collapse_block ? 'fa-angle-double-left' : 'fa-angle-double-right';
echo '<i data-icon2="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-right"
class="ace-icon fa ' . $t_block_icon . '"></i>';
} else {
$t_block_icon = $t_collapse_block ? 'fa-angle-double-right' : 'fa-angle-double-left';
echo '<i data-icon2="ace-icon fa fa-angle-double-right" data-icon1="ace-icon fa fa-angle-double-left"
class="ace-icon fa ' . $t_block_icon . '"></i>';
}
echo '</div>';
echo '</div>';
}
/**
* Render opening markup for main container
* @return void
*/
function layout_main_container_begin() {
echo '<div class="main-container" id="main-container">', "\n";
}
/**
* Render closing markup for main container
* @return void
*/
function layout_main_container_end() {
echo '</div>' , "\n";
}
/**
* Render opening markup for main content
* @return void
*/
function layout_main_content_begin() {
echo '<div class="main-content">' , "\n";
}
/**
* Render closing markup for main content
* @return void