mirror of
https://github.com/Icinga/icingaweb2.git
synced 2026-05-28 04:02:39 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
43 lines
983 B
PHP
43 lines
983 B
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Icinga\Web\Form\Validator;
|
|
|
|
use Icinga\Application\Icinga;
|
|
use Zend_Validate_Abstract;
|
|
use Icinga\Web\Url;
|
|
|
|
/**
|
|
* Validator that checks whether a textfield doesn't contain an external URL
|
|
*/
|
|
class InternalUrlValidator extends Zend_Validate_Abstract
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function isValid($value)
|
|
{
|
|
$url = Url::fromPath($value);
|
|
if ($url->getRelativeUrl() === '' || $url->isExternal()) {
|
|
$this->_error('IS_EXTERNAL');
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function _error($messageKey, $value = null)
|
|
{
|
|
if ($messageKey === 'IS_EXTERNAL') {
|
|
$this->_messages[$messageKey] = t('The url must not be external.');
|
|
} else {
|
|
parent::_error($messageKey, $value);
|
|
}
|
|
}
|
|
}
|