Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fusiondirectory
fusiondirectory
Commits
f20b783c
Commit
f20b783c
authored
Nov 05, 2015
by
Côme Chilliet
Browse files
Fixes
#4001
Added a random string modifier
parent
e8a9e516
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/class_plugin.inc
View file @
f20b783c
...
...
@@ -702,6 +702,49 @@ class plugin
}
else
{
return
array
(
substr
(
$str
,
$args
[
0
],
$args
[
1
]));
}
case
'r'
:
// random string
$length
=
8
;
$chars
=
'b'
;
if
(
count
(
$args
)
>=
2
)
{
$length
=
mt_rand
(
$args
[
0
],
$args
[
1
]);
if
(
count
(
$args
)
>=
3
)
{
$chars
=
$args
[
2
];
}
}
elseif
(
count
(
$args
)
>=
1
)
{
$length
=
$args
[
0
];
}
$res
=
''
;
for
(
$i
=
0
;
$i
<
$args
[
0
];
++
$i
)
{
switch
(
$chars
)
{
case
'l'
:
$res
.
=
(
string
)
rand
(
0
,
9
);
break
;
case
'd'
:
$nb
=
mt_rand
(
65
,
116
);
if
(
$nb
>
90
)
{
/* lowercase */
$nb
+=
6
;
}
$res
.
=
chr
(
$nb
);
break
;
case
'b'
:
default
:
$nb
=
mt_rand
(
65
,
126
);
if
(
$nb
>
116
)
{
/* digit */
$nb
=
(
string
)(
$nb
-
117
);
}
else
{
if
(
$nb
>
90
)
{
/* lowercase */
$nb
+=
6
;
}
$nb
=
chr
(
$nb
);
}
$res
.
=
$nb
;
break
;
}
}
return
$res
;
default
:
trigger_error
(
"Unkown modifier '
$m
'"
);
return
array
(
$str
);
...
...
@@ -718,16 +761,14 @@ class plugin
$modifiers
=
$m
[
1
];
$mask
=
substr
(
$mask
,
strlen
(
$m
[
0
]));
}
$result
=
array
(
''
);
if
(
isset
(
$attrs
[
$mask
]))
{
$result
=
array
(
$attrs
[
$mask
]);
if
(
is_array
(
$result
[
0
]))
{
unset
(
$result
[
0
][
'count'
]);
}
}
else
{
if
(
!
preg_match
(
'/c/'
,
$modifiers
))
{
trigger_error
(
"'
$mask
' was not found in attributes"
);
}
$result
=
array
(
''
);
}
elseif
((
$mask
!==
''
)
&&
!
preg_match
(
'/c/'
,
$modifiers
))
{
trigger_error
(
"'
$mask
' was not found in attributes"
);
}
$len
=
strlen
(
$modifiers
);
for
(
$i
=
0
;
$i
<
$len
;
++
$i
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment