2016-08-31 09:11:55 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2016-08-31 09:11:55 -04:00
|
|
|
|
|
|
|
|
namespace Icinga\Web\Form\Validator;
|
|
|
|
|
|
2022-12-01 09:50:46 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2016-08-31 09:11:55 -04:00
|
|
|
use Zend_Validate_Abstract;
|
2016-09-09 09:21:06 -04:00
|
|
|
use Icinga\Web\Url;
|
2016-08-31 09:11:55 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validator that checks whether a textfield doesn't contain an external URL
|
|
|
|
|
*/
|
|
|
|
|
class InternalUrlValidator extends Zend_Validate_Abstract
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function isValid($value)
|
|
|
|
|
{
|
2022-12-01 09:50:46 -05:00
|
|
|
$url = Url::fromPath($value);
|
2023-01-09 04:03:09 -05:00
|
|
|
if ($url->getRelativeUrl() === '' || $url->isExternal()) {
|
2016-08-31 09:11:55 -04:00
|
|
|
$this->_error('IS_EXTERNAL');
|
2016-09-09 09:22:24 -04:00
|
|
|
|
|
|
|
|
return false;
|
2016-08-31 09:11:55 -04:00
|
|
|
}
|
2016-09-09 09:22:24 -04:00
|
|
|
|
|
|
|
|
return true;
|
2016-08-31 09:11:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|