Fix that strtoupper can't handle non ascii chars

Fixed by not using strtoupper or by using it prior
to the translation of the corresponding string.

fixes #8163
This commit is contained in:
Johannes Meyer 2015-01-22 14:36:22 +01:00
parent 78a6937c22
commit 6845480b5f
11 changed files with 29 additions and 45 deletions

View File

@ -14,7 +14,7 @@
</div>
<div class="hbox-item" style="font-size: 14px">
<?php foreach (array_filter($hostStates) as $text => $count) {
echo sprintf('%s: %u <br>', strtoupper($text), $count);
echo sprintf('%s: %u <br>', $this->translate(strtoupper($text)), $count);
} ?>
</div>

View File

@ -12,7 +12,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
$this->stats->services_ok,
$selfUrl,
array('service_state' => 0),
array('title' => sprintf($this->translate('Services with state %s'), strtoupper($this->translate('ok'))))
array('title' => sprintf($this->translate('Services with state %s'), $this->translate('OK')))
) ?></span>
<?php endif ?>
@ -44,7 +44,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$this->stats->$unhandled,
$selfUrl,
$paramsUnhandled,
array('title' => sprintf($this->translate('Unhandled services with state %s'), strtoupper($this->translate($state))))
array('title' => sprintf($this->translate('Unhandled services with state %s'), $this->translate(strtoupper($state))))
);
}
if ($this->stats->$handled) {
@ -61,7 +61,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$this->stats->$handled,
$selfUrl,
$paramsHandled,
array('title' => sprintf($this->translate('Handled services with state %s'), strtoupper($this->translate($state))))
array('title' => sprintf($this->translate('Handled services with state %s'), $this->translate(strtoupper($state))))
);
if ($this->stats->$unhandled) {
echo "</span>\n";
@ -77,7 +77,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$this->stats->services_pending,
$selfUrl,
array('service_state' => 99),
array('title' => sprintf($this->translate('Services with state %s'), strtoupper($this->translate('pending'))))
array('title' => sprintf($this->translate('Services with state %s'), $this->translate('PENDING')))
) ?></span>
<?php endif ?>
</span>

View File

@ -70,21 +70,13 @@ use Icinga\Module\Monitoring\Object\Service;
$icon = $isService ? 'service' : 'host';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? Service::getStateText($event->state, true)
: Host::getStateText($event->state, true)
);
$title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true);
break;
case 'soft_state':
$icon = 'lightbulb';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? Service::getStateText($event->state, true)
: Host::getStateText($event->state, true)
);
$title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true);
break;
case 'dt_start':
$icon = 'starttime';

View File

@ -80,7 +80,7 @@ if ($hosts->count() === 0) {
<tr class="state <?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
<!-- State -->
<td class="state">
<strong><?= strtoupper(Host::getStateText($host->host_state, true)); ?></strong><br />
<strong><?= Host::getStateText($host->host_state, true); ?></strong><br />
<?php if ((int) $host->host_state !== 99): ?>
<?= $this->prefixedTimeSince($host->host_last_state_change, true) ?>
<?php if ($host->host_state > 0 && (int) $host->host_state_type === 0): ?>

View File

@ -56,7 +56,7 @@ foreach ($services as $service):
?>
<tr class="state <?= $serviceStateName ?><?= $service->service_handled ? ' handled' : '' ?>">
<td class="state">
<strong><?= strtoupper(Service::getStateText($service->service_state, true)); ?></strong><br />
<strong><?= Service::getStateText($service->service_state, true); ?></strong><br />
<?php if (!$this->compact): ?><?= $this->prefixedTimeSince($service->service_last_state_change); ?><?php else: ?><?= $this->timeSince($service->service_last_state_change); ?><?php endif ?>
<?php if ($service->service_state > 0 && (int) $service->service_state_type === 0): ?>
<br />
@ -106,7 +106,7 @@ foreach ($services as $service):
<?php endif ?>
<a href="<?= $serviceLink ?>"><?= $this->escape($service->service_display_name) ?></a><?php if ($this->showHost): ?> on <a href="<?= $hostLink ?>"><?= $this->escape($service->host_display_name) ?>
<?php if ($service->host_state != 0): ?>
(<?= strtoupper(Host::getStateText($service->host_state, true)); ?>)
(<?= Host::getStateText($service->host_state, true); ?>)
<?php endif ?>
</a><?php endif ?><br />
<p class="pluginoutput"><?= $this->escape($this->ellipsis($service->service_output, 10000)); ?></p>

View File

@ -16,7 +16,7 @@
</div>
<div class="hbox-item" style="font-size: 14px">
<?php foreach (array_filter($serviceStates) as $text => $count) {
echo sprintf(' %s: %u <br>', strtoupper($text), $count);
echo sprintf(' %s: %u <br>', $this->translate(strtoupper($text)), $count);
} ?>
</div>
</div>
@ -31,7 +31,7 @@
</div>
<div class="hbox-item" style="font-size: 14px">
<?php foreach (array_filter($hostStates) as $text => $count) {
echo sprintf('%s: %u <br>', strtoupper($text), $count);
echo sprintf('%s: %u <br>', $this->translate(strtoupper($text)), $count);
} ?>
</div>
</div>

View File

@ -14,7 +14,7 @@ $isService = $object->getType() === $object::TYPE_SERVICE;
<table class="objectstate">
<tr class="state <?= Host::getStateText($object->host_state); ?><?= $object->host_handled ? ' handled' : '' ?>">
<td class="state"<?= $isService ? '' : ' rowspan="2"' ?>>
<strong><?= strtoupper(Host::getStateText($object->host_state, true)); ?></strong><br>
<strong><?= Host::getStateText($object->host_state, true); ?></strong><br>
<?= $this->prefixedTimeSince($object->host_last_state_change, true) ?>
</td>
<td>
@ -31,7 +31,7 @@ $isService = $object->getType() === $object::TYPE_SERVICE;
<?php if ($isService): ?>
<tr class="state <?= Service::getStateText($object->service_state); ?><?= $object->service_handled ? ' handled' : '' ?>">
<td class="state">
<strong><?= strtoupper(Service::getStateText($object->service_state, true)); ?></strong><br>
<strong><?= Service::getStateText($object->service_state, true); ?></strong><br>
<?= $this->prefixedTimeSince($object->service_last_state_change, true) ?>
</td>
<td>

View File

@ -17,7 +17,7 @@ $currentUrl = Url::fromRequest()->without('limit')->getRelativeUrl();
$object->stats->services_ok,
$selfUrl,
array('service_state' => 0),
array('title' => sprintf($this->translate('Services with state %s'), strtoupper($this->translate('ok'))))
array('title' => sprintf($this->translate('Services with state %s'), $this->translate('OK')))
) ?></span>
<?php endif ?>
<?php
@ -48,7 +48,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$object->stats->$unhandled,
$selfUrl,
$paramsUnhandled,
array('title' => sprintf($this->translate('Unhandled services with state %s'), strtoupper($this->translate($state))))
array('title' => sprintf($this->translate('Unhandled services with state %s'), $this->translate(strtoupper($state))))
);
}
if ($object->stats->$handled) {
@ -65,7 +65,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$object->stats->$handled,
$selfUrl,
$paramsHandled,
array('title' => sprintf($this->translate('Handled services with state %s'), strtoupper($this->translate($state))))
array('title' => sprintf($this->translate('Handled services with state %s'), $this->translate(strtoupper($state))))
);
if ($object->stats->$unhandled) {
echo "</span>\n";
@ -81,7 +81,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
$object->stats->services_pending,
$selfUrl,
array('service_state' => 99),
array('title' => sprintf($this->translate('Services with state %s'), strtoupper($this->translate('pending'))))
array('title' => sprintf($this->translate('Services with state %s'), $this->translate('PENDING')))
) ?></span>
<?php endif ?>
</span>

View File

@ -92,21 +92,13 @@ function contactsLink($match, $view) {
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$icon = 'attention-alt';
$title = strtoupper(
$isService
? Service::getStateText($event->state)
: Host::getStateText($event->state)
);
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
break;
case 'soft_state':
$icon = 'spinner';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? Service::getStateText($event->state)
: Host::getStateText($event->state)
);
$title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
break;
case 'dt_start':
$icon = 'downtime_start';

View File

@ -173,16 +173,16 @@ class Host extends MonitoredObject
$translate = (bool) $translate;
switch ((int) $state) {
case self::STATE_UP:
$text = $translate ? mt('monitoring', 'up') : 'up';
$text = $translate ? mt('monitoring', 'UP') : 'up';
break;
case self::STATE_DOWN:
$text = $translate ? mt('monitoring', 'down') : 'down';
$text = $translate ? mt('monitoring', 'DOWN') : 'down';
break;
case self::STATE_UNREACHABLE:
$text = $translate ? mt('monitoring', 'unreachable') : 'unreachable';
$text = $translate ? mt('monitoring', 'UNREACHABLE') : 'unreachable';
break;
case self::STATE_PENDING:
$text = $translate ? mt('monitoring', 'pending') : 'pending';
$text = $translate ? mt('monitoring', 'PENDING') : 'pending';
break;
default:
throw new InvalidArgumentException('Invalid host state \'%s\'', $state);

View File

@ -214,19 +214,19 @@ class Service extends MonitoredObject
$translate = (bool) $translate;
switch ((int) $state) {
case self::STATE_OK:
$text = $translate ? mt('monitoring', 'ok') : 'ok';
$text = $translate ? mt('monitoring', 'OK') : 'ok';
break;
case self::STATE_WARNING:
$text = $translate ? mt('monitoring', 'warning') : 'warning';
$text = $translate ? mt('monitoring', 'WARNING') : 'warning';
break;
case self::STATE_CRITICAL:
$text = $translate ? mt('monitoring', 'critical') : 'critical';
$text = $translate ? mt('monitoring', 'CRITICAL') : 'critical';
break;
case self::STATE_UNKNOWN:
$text = $translate ? mt('monitoring', 'unknown') : 'unknown';
$text = $translate ? mt('monitoring', 'UNKNOWN') : 'unknown';
break;
case self::STATE_PENDING:
$text = $translate ? mt('monitoring', 'pending') : 'pending';
$text = $translate ? mt('monitoring', 'PENDING') : 'pending';
break;
default:
throw new InvalidArgumentException('Invalid service state \'%s\'', $state);