On Mon, Mar 2, 2009 at 4:56 PM, Hans <[email protected]> wrote:
>
> Why don't you just use a configurable preg_replace pattern for valid
> pagenames?
> I know you are much more comfortable using str_replace, but the
> solution with it are getting more complicated and harder to maintain
> stability in development.
I prefer to use str_replace, for now, because it seems to be adequate
in most cases. The patterns on ISO8859MakePageNamePatterns could just
as easily be done with strings rather than regex, and strings would be
faster. (See BOLTutf8_strip). In fact, with the strtr() function, the
code is even simpler. Currently I have this:
function BOLTXtarget($value, $field) {
global $target;
if (strpos($field, 'fix') !== false) {
global $BOLTfixPage;
$value = strtr($value, $BOLTfixPage);
}
$target = BOLTpageshortcuts($value);
if (BOLTfilter($target, 'page') == '') BOLTabort('invalid_page_name');
return $target;
}
With this early in engine.php. Note the default ' '=> '-'
$BOLTfixPage = Array('"'=>'', "'"=>'', ','=>'', '?'=>'', '!'=>'',
'''=>'','"'=>'', ' '=>'-');
Granted, it's not as powerful as regex, but it would be very easy and
fast. But after thinking about it a bit more, I realized we could do
something like this with little impact on speed:
function BOLTXtarget($value, $field) {
global $target;
if (strpos($field, 'fix') !== false) {
global $BOLTfixPage;
$value = strtr($value, $BOLTfixPage);
}
if (strpos($field, 'regex') != false) {
global $BOLTfixRegex;
if (is_array($BOLTfixRegex)) $value =
preg_replace(array_keys($BOLTfixRegex), array_values($BOLTfixRegex),
$value);
}
$target = BOLTpageshortcuts($value);
if (BOLTfilter($target, 'page') == '') BOLTabort('invalid_page_name');
return $target;
}
This would mean you could do target_regex (or for multiple lines
(target_regex_1, etc) and use the BOLTfixRegex array. For simple
string replacements, use the BOLTfixPage and target_fix. A bit clunky,
but do you think this will work for you?
Another option is to add a new command to the core: filter. This
could be used on any field, with code like this (and then take the
fix/regex stuff out of the target function completely).
function BOLTXfilter($value, $field) {
global $BOLTfilter2;
$filter = substr($field, 7);
if (strpos($filter, '_') !== false) $filter = substr($filter, 0,
strpos($filter, '_'));
if (is_array($BOLTfilter2[$filter])) {
foreach ($BOLTfilter2[$filter] as $in => $out) {
if (substr($in, 0, 1) == '/') $value =
preg_replace($in, $out, $value);
else $value = str_replace($in, $out, $value);
}
}
return $value;
}
I used $BOLTfilter2 temporarily because of a namespace conflict... In
this case our markup would change from
[form]
Title: [text title][submit]
[session target_regex "{=title}"]
[session warn {=target_regex}]
[form]
to
[form]
Title: [text title][submit]
[session filter_blog {=title}]
[session target "{=filter_blog}"]
[session warn {=target}]
[form]
And we define in a config file:
$BOLTfilter['blog'] = Array('"'=>'', "'"=>'', ','=>'', '?'=>'',
'!'=>'', '''=>'','"'=>'', ' '=>'-');
(could mix strings with /patterns/ => 'out' also)
I really like this idea. Have just tested it, and feel it is more
straightforward and versatile than what we have. What do you think of
this idea?
The only question is the namespace issue. Currently BOLTwire has a
BOLTfilter function and a $BOLTfilter array for filtering user input.
I could possibly change that all to BOLTclean or BOLTcheck or
something. With a big search and replace. I think we need "filter"
more for this command as it is the term users will see more in forms,
etc. That is, one is internal, the other is external.
Cheers,
Dan
P.S. We probably would also need to set a default filter, to not lose
current capabilties. Perhaps $BOLTfilter['title'] is better than
'blog'?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"BoltWire" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/boltwire?hl=en
-~----------~----~----~----~------~----~------~--~---