PropertyModifier: clean them up, better descriptions

This commit is contained in:
Thomas Gelf 2016-03-06 00:37:03 +01:00
parent d8f721081e
commit 252093f794
4 changed files with 45 additions and 12 deletions

View File

@ -10,17 +10,32 @@ class PropertyModifierRegexReplace extends PropertyModifierHook
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'pattern', array(
'label' => 'Regex pattern',
'required' => true,
'label' => 'Regex pattern',
'description' => $form->translate(
'The pattern you want to search for. This can be a regular expression like /^www\d+\./'
),
'required' => true,
));
$form->addElement('text', 'replacement', array(
'label' => 'Replacement',
'label' => 'Replacement',
'description' => $form->translate(
'The string that should be used as a preplacement'
),
));
}
public function getName()
{
return 'Regular expression based replacement';
}
public function transform($value)
{
return preg_replace($this->settings['pattern'], $this->settings['replacement'], $value);
return preg_replace(
$this->getSetting('pattern'),
$this->getSetting('replacement'),
$value
);
}
}

View File

@ -10,13 +10,15 @@ class PropertyModifierReplace extends PropertyModifierHook
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'string', array(
'label' => 'Search string',
'required' => true,
'label' => 'Search string',
'description' => $form->translate('The string you want to search for'),
'required' => true,
));
$form->addElement('text', 'replacement', array(
'label' => 'Replacement',
'required' => true,
'label' => 'Replacement',
'description' => $form->translate('Your replacement string'),
'required' => true,
));
}

View File

@ -11,13 +11,24 @@ class PropertyModifierStripDomain extends PropertyModifierHook
{
$form->addElement('text', 'domain', array(
'label' => 'Domain name',
'description' => 'Domain to be replaced',
'description' => $form->translate('The domain name you want to be stripped'),
'required' => true,
));
}
public function getName()
{
return 'Strip a domain name';
}
public function transform($value)
{
return preg_replace($this->settings['domain'], '', $value);
$domain = preg_quote(ltrim($this->getSetting('domain'), '.'), '/');
return preg_replace(
'/\.' . $domain . '$/',
'',
$value
);
}
}

View File

@ -14,7 +14,7 @@ class PropertyModifierSubstring extends PropertyModifierHook
'required' => true,
'description' => sprintf(
$form->translate(
'Please see %s for detailled instructions of how start and and work'
'Please see %s for detailled instructions of how start and end work'
),
'http://php.net/manual/en/function.substr.php'
)
@ -22,7 +22,12 @@ class PropertyModifierSubstring extends PropertyModifierHook
$form->addElement('text', 'length', array(
'label' => 'End',
'required' => true,
'description' => sprintf(
$form->translate(
'Please see %s for detailled instructions of how start and end work'
),
'http://php.net/manual/en/function.substr.php'
)
));
}