Commit b46ddb4 1 parent de468a8 commit b46ddb4 Copy full SHA for b46ddb4
File tree 5 files changed +36
-7
lines changed
5 files changed +36
-7
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## [ master - 02.02.2025]
4
+
5
+ ### Added
6
+ * Twig session(key) function + reworked session functions to accept multi-array like in Laravel
7
+
3
8
## [ 1.1 - 27.01.2025]
4
9
5
10
### Changed
Original file line number Diff line number Diff line change @@ -1057,17 +1057,36 @@ function get_browser_real_ip() {
1057
1057
1058
1058
return '0 ' ;
1059
1059
}
1060
- function setSession ($ key , $ data ): void {
1061
- $ _SESSION [setting ('core.session_prefix ' ) . $ key ] = $ data ;
1060
+ function setSession ($ key , $ value = null ): void {
1061
+ if (!is_array ($ key )) {
1062
+ $ key = [$ key => $ value ];
1063
+ }
1064
+
1065
+ foreach ($ key as $ arrayKey => $ arrayValue ) {
1066
+ if (is_null ($ arrayValue )) {
1067
+ unsetSession ($ arrayKey );
1068
+ }
1069
+ else {
1070
+ $ _SESSION [setting ('core.session_prefix ' ) . $ arrayKey ] = $ arrayValue ;
1071
+ }
1072
+ }
1062
1073
}
1063
1074
function getSession ($ key ) {
1064
- $ key = setting ('core.session_prefix ' ) . $ key ;
1065
- return $ _SESSION [$ key ] ?? false ;
1075
+ return $ _SESSION [setting ('core.session_prefix ' ) . $ key ] ?? null ;
1066
1076
}
1067
1077
function unsetSession ($ key ): void {
1068
1078
unset($ _SESSION [setting ('core.session_prefix ' ) . $ key ]);
1069
1079
}
1070
1080
1081
+ function session ($ key ): mixed {
1082
+ if (is_array ($ key )) {
1083
+ setSession ($ key );
1084
+ return null ;
1085
+ }
1086
+
1087
+ return getSession ($ key );
1088
+ }
1089
+
1071
1090
function csrf (bool $ return = false ): string {
1072
1091
return CsrfToken::create ($ return );
1073
1092
}
Original file line number Diff line number Diff line change 14
14
15
15
// stay-logged with sessions
16
16
$ current_session = getSession ('account ' );
17
- if ($ current_session !== false )
17
+ if ($ current_session )
18
18
{
19
19
$ account_logged ->load ($ current_session );
20
20
if ($ account_logged ->isLoaded () && $ account_logged ->getPassword () == getSession ('password ' )
21
21
//&& (!isset($_SESSION['admin']) || admin())
22
- && (getSession ('remember_me ' ) !== false || getSession ('last_visit ' ) > time () - 15 * 60 )) { // login for 15 minutes if "remember me" is not used
22
+ && (getSession ('remember_me ' ) || getSession ('last_visit ' ) > time () - 15 * 60 )) { // login for 15 minutes if "remember me" is not used
23
23
$ logged = true ;
24
24
}
25
25
else {
Original file line number Diff line number Diff line change 41
41
}
42
42
else {
43
43
$ template_session = getSession ('template ' );
44
- if ($ template_session !== false ) {
44
+ if ($ template_session ) {
45
45
if (!preg_match ("/[^A-z0-9_\-]/ " , $ template_session )) {
46
46
$ template_name = $ template_session ;
47
47
}
Original file line number Diff line number Diff line change 140
140
});
141
141
$ twig ->addFunction ($ function );
142
142
143
+ $ function = new TwigFunction ('session ' , function ($ key ) {
144
+ return session ($ key );
145
+ });
146
+ $ twig ->addFunction ($ function );
147
+
143
148
$ filter = new TwigFilter ('urlencode ' , function ($ s ) {
144
149
return urlencode ($ s );
145
150
});
You can’t perform that action at this time.
0 commit comments