Skip to content

Commit

Permalink
Remove gipfl/format package dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 authored and nilmerg committed Feb 7, 2024
1 parent 087ce05 commit e49cccd
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion library/Director/Web/Form/CsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function isValid($token)
return false;
}

list($seed, $token) = explode('|', $elementValue);
list($seed, $token) = explode('|', $token);

if (!is_numeric($seed)) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions library/Director/Web/Form/QuickForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ public function hasBeenSent()
$this->hasBeenSent = true;
} elseif ($req->isPost()) {
$post = $req->getPost();
if (! CsrfToken::isValid($post[self::CSRF])) {
throw new Exception('Invalid CSRF token provided');
}

$this->hasBeenSent = array_key_exists(self::ID, $post) &&
$post[self::ID] === $this->getName();
} else {
Expand Down
5 changes: 2 additions & 3 deletions library/Director/Web/Table/ActivityLogTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use Icinga\Module\Director\Util;
use ipl\Html\BaseHtmlElement;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;

class ActivityLogTable extends ZfQueryBasedTable
class ActivityLogTable extends IntlZfQueryBasedTable
{
protected $filters = [];

Expand Down Expand Up @@ -55,7 +54,7 @@ public function renderRow($row)

return $this::tr([
$this::td($this->makeLink($row))->setSeparator(' '),
$this::td(strftime('%H:%M:%S', $row->ts_change_time))
$this::td($this->getTime($row->ts_change_time))
])->addAttributes(['class' => $action]);
}

Expand Down
3 changes: 1 addition & 2 deletions library/Director/Web/Table/BasketSnapshotTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use ipl\Html\Html;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use Icinga\Date\DateFormatter;
use Icinga\Module\Director\Core\Json;
use Icinga\Module\Director\DirectorObject\Automation\Basket;
use RuntimeException;

class BasketSnapshotTable extends ZfQueryBasedTable
class BasketSnapshotTable extends IntlZfQueryBasedTable
{
use DbHelper;

Expand Down
3 changes: 1 addition & 2 deletions library/Director/Web/Table/DeploymentLogTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Icinga\Module\Director\Web\Table;

use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use Icinga\Date\DateFormatter;

class DeploymentLogTable extends ZfQueryBasedTable
class DeploymentLogTable extends IntlZfQueryBasedTable
{
use DbHelper;

Expand Down
51 changes: 51 additions & 0 deletions library/Director/Web/Table/IntlZfQueryBasedTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Icinga\Module\Director\Web\Table;

use DateTime;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use IntlDateFormatter;
use Locale;

abstract class IntlZfQueryBasedTable extends ZfQueryBasedTable
{
protected function getDateFormatter()
{
return (new IntlDateFormatter(
Locale::getDefault(),
IntlDateFormatter::FULL,
IntlDateFormatter::NONE
));
}

/**
* @param int $timestamp
*/
protected function renderDayIfNew($timestamp)
{
$day = $this->getDateFormatter()->format((new DateTime())->setTimestamp($timestamp));

if ($this->lastDay !== $day) {
$this->nextHeader()->add(
$this::th($day, [
'colspan' => 2,
'class' => 'table-header-day'
])
);

$this->lastDay = $day;
$this->nextBody();
}
}

protected function getTime(int $timeStamp)
{
$timeFormatter = $this->getDateFormatter();

$timeFormatter->setPattern(
in_array(Locale::getDefault(), ['en_US', 'en_US.UTF-8']) ? 'h:mm:ss a': 'H:mm:ss'
);

return $timeFormatter->format((new DateTime())->setTimestamp($timeStamp));
}
}
5 changes: 2 additions & 3 deletions library/Director/Web/Table/SyncRunTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

use Icinga\Module\Director\Objects\SyncRule;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;

class SyncRunTable extends ZfQueryBasedTable
class SyncRunTable extends IntlZfQueryBasedTable
{
/** @var SyncRule */
protected $rule;
Expand All @@ -28,7 +27,7 @@ public function renderRow($row)
return $this::tr([
$this::td($this->makeSummary($row)),
$this::td(new Link(
strftime('%H:%M:%S', $time),
$this->getTime($time),
'director/syncrule/history',
[
'id' => $row->rule_id,
Expand Down

0 comments on commit e49cccd

Please sign in to comment.