1- <?php
2- /**
3- * Widget add panel
4- *
5- * @uses $vars['context'] The context for this widget layout
6- * @uses $vars['owner_guid'] Container limit widgets for
7- */
8-
9- elgg_ajax_gatekeeper ();
10-
11- // restoring context stack
12- $ context_stack = get_input ('context_stack ' );
13- if (!empty ($ context_stack ) && is_array ($ context_stack )) {
14- elgg_set_context_stack ($ context_stack );
15- }
16-
17- elgg_require_js ('resources/widgets/add_panel ' );
18- elgg_require_js ('widget_manager/add_panel ' );
19-
20- $ context = elgg_extract ('context ' , $ vars , get_input ('context ' ));
21- $ owner_guid = (int ) elgg_extract ('owner_guid ' , $ vars , (int ) get_input ('owner_guid ' ));
22- elgg_entity_gatekeeper ($ owner_guid );
23-
24- $ owner = get_entity ($ owner_guid );
25-
26- elgg_set_page_owner_guid ($ owner ->guid );
27-
28- $ widgets = elgg_get_widgets ($ owner ->guid , $ context );
29- $ widget_types = elgg_get_widget_types ([
30- 'context ' => $ context ,
31- 'container ' => $ owner ,
32- ]);
33- uasort ($ widget_types , function ($ a , $ b ) {
34- return strcmp ($ a ->name , $ b ->name );
35- });
36-
37- $ current_handlers = [];
38- foreach ($ widgets as $ column_widgets ) {
39- foreach ($ column_widgets as $ widget ) {
40- $ current_handlers [] = $ widget ->handler ;
41- }
42- }
43-
44- $ result = elgg_format_element ('p ' , [
45- 'class ' => 'elgg-text-help ' ,
46- ], elgg_echo ('widgets:add:description ' ));
47-
48- $ list_items = '' ;
49- foreach ($ widget_types as $ handler => $ widget_type ) {
50- $ can_add = widget_manager_get_widget_setting ($ handler , 'can_add ' , $ context );
51- $ hide = widget_manager_get_widget_setting ($ handler , 'hide ' , $ context );
52-
53- if (!$ can_add || $ hide ) {
54- // can not add or should be hidden
55- continue ;
56- }
57-
58- $ class = [];
59- // check if widget added and only one instance allowed
60- if (!$ widget_type ->multiple && in_array ($ handler , $ current_handlers )) {
61- $ class [] = 'elgg-state-unavailable ' ;
62- } else {
63- $ class [] = 'elgg-state-available ' ;
64- }
65-
66- $ class [] = $ widget_type ->multiple ? 'elgg-widget-multiple ' : 'elgg-widget-single ' ;
67-
68- $ action = '<div class="elgg-widgets-add-actions elgg-level"> ' ;
69- if (!$ widget_type ->multiple ) {
70- $ action .= elgg_format_element ('span ' , ['class ' => 'elgg-quiet ' ], elgg_echo ('widget:unavailable ' ));
71- }
72- $ add_link = elgg_http_add_url_query_elements ('action/widgets/add ' , [
73- 'handler ' => $ handler ,
74- 'page_owner_guid ' => $ owner_guid ,
75- 'context ' => $ context ,
76- 'show_access ' => elgg_extract ('show_access ' , $ vars ),
77- 'default_widgets ' => elgg_in_context ('default_widgets ' ),
78- ]);
79-
80- $ action .= elgg_view ('output/url ' , [
81- 'class ' => 'elgg-button elgg-button-submit elgg-size-small ' ,
82- 'text ' => elgg_echo ('add ' ),
83- 'href ' => $ add_link ,
84- 'is_action ' => true ,
85- ]);
86- $ action .= '</div> ' ;
87-
88- $ description = "<h4> {$ widget_type ->name }</h4> " ;
89-
90- if ($ widget_type ->description ) {
91- $ description .= elgg_format_element ('div ' , ['class ' => 'elgg-quiet ' ], $ widget_type ->description );
92- }
93-
94- $ description = elgg_format_element ('div ' , [
95- 'class ' => 'elgg-widgets-add-description ' ,
96- ], $ description );
97-
98- $ item_content = elgg_format_element ('div ' , [
99- 'class ' => 'elgg-level ' ,
100- ], $ description . $ action );
101-
102- $ list_items .= elgg_format_element ('li ' , [
103- 'class ' => $ class ,
104- 'data-elgg-widget-type ' => $ handler ,
105- ], $ item_content );
106- }
107-
108- $ result .= "<ul> $ list_items</ul> " ;
109-
110- $ search_box = elgg_format_element ('div ' , ['id ' => 'widget_manager_widgets_search ' ], elgg_view ('input/text ' , [
111- 'title ' => elgg_echo ('search ' ),
112- 'placeholder ' => elgg_echo ('search ' ),
113- ]));
114-
115- echo elgg_view_module ('aside ' , elgg_echo ('widgets:add ' ), $ result , [
116- 'class ' => 'elgg-widgets-add-panel ' ,
117- 'menu ' => $ search_box ,
118- ]);
1+ <?php
2+ /**
3+ * Widget add panel
4+ *
5+ * @uses $vars['context'] The context for this widget layout
6+ * @uses $vars['owner_guid'] Container limit widgets for
7+ */
8+
9+ elgg_ajax_gatekeeper ();
10+
11+ // restoring context stack
12+ $ context_stack = get_input ('context_stack ' );
13+ if (!empty ($ context_stack ) && is_array ($ context_stack )) {
14+ elgg_set_context_stack ($ context_stack );
15+ }
16+
17+ elgg_require_js ('resources/widgets/add_panel ' );
18+ elgg_require_js ('widget_manager/add_panel ' );
19+
20+ $ context = elgg_extract ('context ' , $ vars , get_input ('context ' ));
21+ $ owner_guid = (int ) elgg_extract ('owner_guid ' , $ vars , (int ) get_input ('owner_guid ' ));
22+ elgg_entity_gatekeeper ($ owner_guid );
23+
24+ $ owner = get_entity ($ owner_guid );
25+
26+ elgg_set_page_owner_guid ($ owner ->guid );
27+
28+ $ widgets = elgg_get_widgets ($ owner ->guid , $ context );
29+ $ widget_types = elgg_get_widget_types ([
30+ 'context ' => $ context ,
31+ 'container ' => $ owner ,
32+ ]);
33+ uasort ($ widget_types , function ($ a , $ b ) {
34+ return strcmp ($ a ->name , $ b ->name );
35+ });
36+
37+ $ current_handlers = [];
38+ foreach ($ widgets as $ column_widgets ) {
39+ foreach ($ column_widgets as $ widget ) {
40+ $ current_handlers [] = $ widget ->handler ;
41+ }
42+ }
43+
44+ $ result = elgg_format_element ('p ' , [
45+ 'class ' => 'elgg-text-help ' ,
46+ ], elgg_echo ('widgets:add:description ' ));
47+
48+ $ list_items = '' ;
49+ foreach ($ widget_types as $ handler => $ widget_type ) {
50+ $ can_add = widget_manager_get_widget_setting ($ handler , 'can_add ' , $ context );
51+ $ hide = widget_manager_get_widget_setting ($ handler , 'hide ' , $ context );
52+
53+ if (!$ can_add || $ hide ) {
54+ // can not add or should be hidden
55+ continue ;
56+ }
57+
58+ $ class = [];
59+ // check if widget added and only one instance allowed
60+ if (!$ widget_type ->multiple && in_array ($ handler , $ current_handlers )) {
61+ $ class [] = 'elgg-state-unavailable ' ;
62+ } else {
63+ $ class [] = 'elgg-state-available ' ;
64+ }
65+
66+ $ class [] = $ widget_type ->multiple ? 'elgg-widget-multiple ' : 'elgg-widget-single ' ;
67+
68+ $ action = '<div class="elgg-widgets-add-actions elgg-level"> ' ;
69+ if (!$ widget_type ->multiple ) {
70+ $ action .= elgg_format_element ('span ' , ['class ' => 'elgg-quiet ' ], elgg_echo ('widget:unavailable ' ));
71+ }
72+ $ add_link = elgg_http_add_url_query_elements ('action/widgets/add ' , [
73+ 'handler ' => $ handler ,
74+ 'page_owner_guid ' => $ owner_guid ,
75+ 'context ' => $ context ,
76+ 'show_access ' => elgg_extract ('show_access ' , $ vars ),
77+ 'default_widgets ' => elgg_in_context ('default_widgets ' ),
78+ ]);
79+
80+ $ action .= elgg_view ('output/url ' , [
81+ 'class ' => 'elgg-button elgg-button-submit elgg-size-small ' ,
82+ 'text ' => elgg_echo ('add ' ),
83+ 'href ' => $ add_link ,
84+ 'is_action ' => true ,
85+ ]);
86+ $ action .= '</div> ' ;
87+
88+ $ description = "<h4> {$ widget_type ->name }</h4> " ;
89+
90+ if ($ widget_type ->description ) {
91+ $ description .= elgg_format_element ('div ' , ['class ' => 'elgg-quiet ' ], $ widget_type ->description );
92+ }
93+
94+ $ description = elgg_format_element ('div ' , [
95+ 'class ' => 'elgg-widgets-add-description ' ,
96+ ], $ description );
97+
98+ $ item_content = elgg_format_element ('div ' , [
99+ 'class ' => 'elgg-level ' ,
100+ ], $ description . $ action );
101+
102+ $ list_items .= elgg_format_element ('li ' , [
103+ 'class ' => $ class ,
104+ 'data-elgg-widget-type ' => $ handler ,
105+ ], $ item_content );
106+ }
107+
108+ $ result .= "<ul> $ list_items</ul> " ;
109+
110+ $ search_box = elgg_format_element ('div ' , ['id ' => 'widget_manager_widgets_search ' ], elgg_view ('input/text ' , [
111+ 'title ' => elgg_echo ('search ' ),
112+ 'placeholder ' => elgg_echo ('search ' ),
113+ ]));
114+
115+ echo elgg_view_module ('aside ' , elgg_echo ('widgets:add ' ), $ result , [
116+ 'class ' => 'elgg-widgets-add-panel ' ,
117+ 'menu ' => $ search_box ,
118+ ]);
119119
0 commit comments