11
11
12
12
class TopNav extends Theme
13
13
{
14
+ protected array $ defaultNav = [];
15
+
14
16
public function css (): string
15
17
{
16
18
elog (__METHOD__ );
@@ -93,125 +95,140 @@ public function log(): string
93
95
94
96
$ alts = '' ;
95
97
foreach (Util::log () as $ lvl => $ msg ) {
96
- $ alts .= $ msg ? '
98
+ if ($ msg ) {
99
+ $ alts .= sprintf (
100
+ '
97
101
<div class="col-12">
98
- <div class="alert alert- ' . $ lvl . ' alert-dismissible fade show" role="alert">
99
- <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> ' . $ msg . '
102
+ <div class="alert alert-%s alert-dismissible fade show" role="alert">
103
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>%s
100
104
</div>
101
- </div> ' : '' ;
105
+ </div> ' ,
106
+ $ lvl ,
107
+ $ msg
108
+ );
109
+ }
102
110
}
103
-
104
111
return $ alts ;
105
112
}
106
113
107
114
public function head (): string
108
115
{
109
116
elog (__METHOD__ );
110
117
111
- return '
118
+ return sprintf (
119
+ '
112
120
<nav class="navbar navbar-expand-lg navbar-dark fixed-top bg-dark">
113
- <div class=container>
114
- <a class="navbar-brand" href=" ' . $ this -> g -> cfg [ ' self ' ] . ' ">
115
- <b><i class="bi bi-server"></i> ' . $ this -> g -> out [ ' head ' ] . ' </b>
121
+ <div class=" container" >
122
+ <a class="navbar-brand" href="%s ">
123
+ <b><i class="bi bi-server" aria-hidden="true" ></i> %s </b>
116
124
</a>
117
125
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsDefault" aria-controls="navbarsDefault" aria-expanded="false" aria-label="Toggle navigation">
118
126
<span class="navbar-toggler-icon"></span>
119
127
</button>
120
128
<div class="collapse navbar-collapse" id="navbarsDefault">
121
- <ul class="navbar-nav me-auto"> ' . $ this ->g ->out ['nav1 ' ] . '
122
- </ul>
123
- <ul class="navbar-nav ms-auto"> ' . $ this ->g ->out ['nav3 ' ] . '
124
- </ul>
129
+ <ul class="navbar-nav me-auto">%s</ul>
130
+ <ul class="navbar-nav ms-auto">%s</ul>
125
131
</div>
126
132
</div>
127
- </nav> ' ;
133
+ </nav> ' ,
134
+ $ this ->g ->cfg ['self ' ],
135
+ $ this ->g ->out ['head ' ],
136
+ $ this ->g ->out ['nav1 ' ],
137
+ $ this ->g ->out ['nav3 ' ]
138
+ );
128
139
}
129
140
130
141
public function nav1 (array $ a = []): string
131
142
{
132
143
elog (__METHOD__ );
133
144
134
- $ a = isset ( $ a [0 ]) ? $ a : Util::get_nav ($ this ->g ->nav1 );
145
+ $ a = $ a [0 ] ?? Util::get_nav ($ this ->g ->nav1 );
135
146
$ o = '?o= ' . $ this ->g ->in ['o ' ];
136
147
$ t = '?t= ' . Util::ses ('t ' );
137
148
138
- return implode ('' , array_map (function ($ n ) use ($ o , $ t ) {
139
- if (is_array ($ n [1 ])) {
140
- return $ this ->nav_dropdown ($ n );
141
- }
142
- $ c = $ o === $ n [1 ] || $ t === $ n [1 ] ? ' active ' : '' ;
143
- $ i = isset ($ n [2 ]) ? '<i class=" ' . $ n [2 ] . '"></i> ' : '' ;
144
-
145
- return '
146
- <li class="nav-item ' . $ c . '"><a class="nav-link" href=" ' . $ n [1 ] . '"> ' . $ i . $ n [0 ] . '</a></li> ' ;
147
- }, $ a ));
149
+ return implode ('' , array_map (
150
+ fn ($ n ) =>
151
+ is_array ($ n [1 ])
152
+ ? $ this ->nav_dropdown ($ n )
153
+ : sprintf (
154
+ '<li class="nav-item%s"><a class="nav-link%s" href="%s">%s%s</a></li> ' ,
155
+ $ o === $ n [1 ] || $ t === $ n [1 ] ? ' active ' : '' ,
156
+ $ o === $ n [1 ] || $ t === $ n [1 ] ? ' active ' : '' ,
157
+ $ n [1 ],
158
+ $ n [2 ] ?? '' ? '<i class=" ' . $ n [2 ] . '" aria-hidden="true"></i> ' : '' ,
159
+ $ n [0 ]
160
+ ),
161
+ $ a
162
+ ));
148
163
}
149
164
150
165
public function nav2 (): string
151
166
{
152
167
elog (__METHOD__ );
153
-
154
168
return $ this ->nav_dropdown (['Theme ' , $ this ->g ->nav2 , 'fa fa-th fa-fw ' ]);
155
169
}
156
170
157
171
public function nav3 (): string
158
172
{
159
173
elog (__METHOD__ );
160
174
161
- if (Util::is_usr ()) {
162
- $ usr [] = ['Change Profile ' , '?o=Accounts&m=read&i= ' . $ _SESSION ['usr ' ]['id ' ], 'fas fa-user fa-fw ' ];
163
- $ usr [] = ['Change Password ' , '?o=Auth&m=update&i= ' . $ _SESSION ['usr ' ]['id ' ], 'fas fa-key fa-fw ' ];
164
- $ usr [] = ['Sign out ' , '?o=Auth&m=delete ' , 'fas fa-sign-out-alt fa-fw ' ];
175
+ if (!Util::is_usr ()) {
176
+ return '' ;
177
+ }
165
178
166
- if (Util::is_adm () && !Util::is_acl (0 )) {
167
- $ usr [] =
168
- ['Switch to sysadm ' , '?o=Accounts&m=switch_user&i= ' . $ _SESSION ['adm ' ], 'fas fa-user fa-fw ' ];
169
- }
179
+ $ usr = [
180
+ ['Change Profile ' , '?o=Accounts&m=read&i= ' . $ _SESSION ['usr ' ]['id ' ], 'fas fa-user fa-fw ' ],
181
+ ['Change Password ' , '?o=Auth&m=update&i= ' . $ _SESSION ['usr ' ]['id ' ], 'fas fa-key fa-fw ' ],
182
+ ['Sign out ' , '?o=Auth&m=delete ' , 'fas fa-sign-out-alt fa-fw ' ]
183
+ ];
170
184
171
- return $ this ->nav_dropdown ([$ _SESSION ['usr ' ]['login ' ], $ usr , 'fas fa-user fa-fw ' ]);
185
+ if (Util::is_adm () && !Util::is_acl (0 )) {
186
+ $ usr [] = ['Switch to sysadm ' , '?o=Accounts&m=switch_user&i= ' . $ _SESSION ['adm ' ], 'fas fa-user fa-fw ' ];
172
187
}
173
188
174
- return '' ;
189
+ return $ this -> nav_dropdown ([ $ _SESSION [ ' usr ' ][ ' login ' ], $ usr , ' fas fa-user fa-fw ' ]) ;
175
190
}
176
191
177
192
public function nav_dropdown (array $ a = []): string
178
193
{
179
194
elog (__METHOD__ );
180
195
181
196
$ o = '?o= ' . $ this ->g ->in ['o ' ];
182
- $ i = isset ( $ a [2 ]) ? ' <i class=" ' . $ a [ 2 ] . ' "></i> ' : '' ;
197
+ $ icon = $ a [2 ] ?? '' ;
183
198
184
- return '
199
+ return sprintf (
200
+ '
185
201
<li class="nav-item dropdown">
186
- <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> ' . $ i . $ a [0 ] . '</a>
187
- <div class="dropdown-menu"> ' . implode ('' , array_map (function ($ n ) use ($ o ) {
188
- $ c = $ o === $ n [1 ] ? ' active ' : '' ;
189
- $ i = isset ($ n [2 ]) ? '<i class=" ' . $ n [2 ] . '"></i> ' : '' ;
190
-
191
- return '
192
- <a class="dropdown-item" href=" ' . $ n [1 ] . '"> ' . $ i . $ n [0 ] . '</a> ' ;
193
- }, $ a [1 ])) . '
194
- </div>
195
- </li> ' ;
202
+ <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">%s%s</a>
203
+ <div class="dropdown-menu">%s</div>
204
+ </li> ' ,
205
+ $ icon ? sprintf ('<i class="%s" aria-hidden="true"></i> ' , $ icon ) : '' ,
206
+ $ a [0 ],
207
+ implode ('' , array_map (fn ($ n ) => sprintf (
208
+ '
209
+ <a class="dropdown-item%s" href="%s">%s%s</a> ' ,
210
+ $ o === $ n [1 ] ? ' active ' : '' ,
211
+ $ n [1 ],
212
+ $ n [2 ] ?? '' ? sprintf ('<i class="%s" aria-hidden="true"></i> ' , $ n [2 ]) : '' ,
213
+ $ n [0 ]
214
+ ), $ a [1 ]))
215
+ );
196
216
}
197
217
198
218
public function main (): string
199
219
{
200
220
elog (__METHOD__ );
201
221
202
- return '
222
+ return sprintf (
223
+ '
203
224
<main class="container">
204
- <div class="row"> ' . $ this ->g ->out ['log ' ] . $ this ->g ->out ['main ' ] . '
205
- </div>
206
- </main> ' ;
207
- }
208
- /*
209
- public function foot(): string
210
- {
211
- elog(__METHOD__);
212
- return ''; // Override Theme's foot() to prevent extra copyright notice in modals
225
+ <div class="row">%s%s</div>
226
+ </main> ' ,
227
+ $ this ->g ->out ['log ' ],
228
+ $ this ->g ->out ['main ' ]
229
+ );
213
230
}
214
- */
231
+
215
232
public function js (): string
216
233
{
217
234
elog (__METHOD__ );
@@ -228,55 +245,44 @@ protected function modal(array $ary): string
228
245
{
229
246
elog (__METHOD__ );
230
247
231
- extract ( $ ary) ;
232
- $ hidden = isset ( $ hidden) && $ hidden ? $ hidden : '' ;
233
- $ footer = $ footer ? '
248
+ [ ' id ' => $ id , ' title ' => $ title , ' body ' => $ body , ' action ' => $ action ] = $ ary ;
249
+ $ hidden = $ ary [ ' hidden ' ] ?? '' ;
250
+ $ footer = isset ( $ ary [ ' footer ' ]) ? sprintf ( '
234
251
<div class="modal-footer">
235
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
236
- <button type="submit" class="btn btn-primary"> ' . $ footer . '</button>
237
- </div> ' : '' ;
238
-
239
- return '
240
- <div class="modal fade" id=" ' . $ id . '" tabindex="-1" role="dialog" aria-labelledby=" ' . $ id . '" aria-hidden="true">
241
- <div class="modal-dialog" role="document">
242
- <div class="modal-content">
243
- <div class="modal-header">
244
- <h5 class="modal-title"> ' . $ title . '</h5>
245
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
246
- </div>
247
- <form method="post" action=" ' . $ this ->g ->cfg ['self ' ] . '">
248
- <input type="hidden" name="c" value=" ' . $ _SESSION ['c ' ] . '">
249
- <input type="hidden" name="o" value=" ' . $ this ->g ->in ['o ' ] . '">
250
- <input type="hidden" name="m" value=" ' . $ action . '">
251
- <input type="hidden" name="i" value=" ' . $ this ->g ->in ['i ' ] . '"> ' . $ hidden . '
252
- <div class="modal-body"> ' . $ body . '
253
- </div> ' . $ footer . '
254
- </form>
252
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
253
+ %s
254
+ </div> ' , $ ary ['footer ' ]) : '' ;
255
+
256
+ return sprintf (
257
+ '
258
+ <div class="modal fade" id="%1$s" tabindex="-1" aria-labelledby="%1$s-label" aria-hidden="true">
259
+ <div class="modal-dialog modal-dialog-centered">
260
+ <div class="modal-content">
261
+ <div class="modal-header">
262
+ <h5 class="modal-title" id="%1$s-label">%2$s</h5>
263
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
264
+ </div>
265
+ <form method="post" action="%3$s">
266
+ <input type="hidden" name="c" value="%4$s">
267
+ <input type="hidden" name="o" value="%5$s">
268
+ <input type="hidden" name="m" value="%6$s">
269
+ <input type="hidden" name="i" value="%7$s">%8$s
270
+ <div class="modal-body">%9$s</div>
271
+ %10$s
272
+ </form>
273
+ </div>
255
274
</div>
256
- </div>
257
- </div> ' ;
258
- }
259
-
260
- public function modal_content (): string
261
- {
262
- elog (__METHOD__ );
263
-
264
- return '
265
- <div class="modal fade" id="mainModal" tabindex="-1" aria-labelledby="mainModalLabel" aria-hidden="true">
266
- <div class="modal-dialog">
267
- <div class="modal-content">
268
- <div class="modal-header">
269
- <h5 class="modal-title" id="mainModalLabel"> ' . ($ this ->g ->out ['modal_title ' ] ?? 'Modal Title ' ) . '</h5>
270
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
271
- </div>
272
- <div class="modal-body"> ' . ($ this ->g ->out ['modal_body ' ] ?? '' ) . '
273
- </div>
274
- <div class="modal-footer">
275
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> ' .
276
- ($ this ->g ->out ['modal_footer ' ] ?? '' ) . '
277
- </div>
278
- </div>
279
- </div>
280
- </div> ' ;
275
+ </div> ' ,
276
+ $ id ,
277
+ $ title ,
278
+ $ this ->g ->cfg ['self ' ],
279
+ $ _SESSION ['c ' ],
280
+ $ this ->g ->in ['o ' ],
281
+ $ action ,
282
+ $ this ->g ->in ['i ' ],
283
+ $ hidden ,
284
+ $ body ,
285
+ $ footer
286
+ );
281
287
}
282
288
}
0 commit comments