Skip to content

Commit e49cccd

Browse files
raviks789nilmerg
authored andcommitted
Remove gipfl/format package dependency
1 parent 087ce05 commit e49cccd

File tree

7 files changed

+62
-11
lines changed

7 files changed

+62
-11
lines changed

library/Director/Web/Form/CsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function isValid($token)
1717
return false;
1818
}
1919

20-
list($seed, $token) = explode('|', $elementValue);
20+
list($seed, $token) = explode('|', $token);
2121

2222
if (!is_numeric($seed)) {
2323
return false;

library/Director/Web/Form/QuickForm.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ public function hasBeenSent()
619619
$this->hasBeenSent = true;
620620
} elseif ($req->isPost()) {
621621
$post = $req->getPost();
622+
if (! CsrfToken::isValid($post[self::CSRF])) {
623+
throw new Exception('Invalid CSRF token provided');
624+
}
625+
622626
$this->hasBeenSent = array_key_exists(self::ID, $post) &&
623627
$post[self::ID] === $this->getName();
624628
} else {

library/Director/Web/Table/ActivityLogTable.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
use Icinga\Module\Director\Util;
66
use ipl\Html\BaseHtmlElement;
77
use gipfl\IcingaWeb2\Link;
8-
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
98

10-
class ActivityLogTable extends ZfQueryBasedTable
9+
class ActivityLogTable extends IntlZfQueryBasedTable
1110
{
1211
protected $filters = [];
1312

@@ -55,7 +54,7 @@ public function renderRow($row)
5554

5655
return $this::tr([
5756
$this::td($this->makeLink($row))->setSeparator(' '),
58-
$this::td(strftime('%H:%M:%S', $row->ts_change_time))
57+
$this::td($this->getTime($row->ts_change_time))
5958
])->addAttributes(['class' => $action]);
6059
}
6160

library/Director/Web/Table/BasketSnapshotTable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
use ipl\Html\Html;
66
use gipfl\IcingaWeb2\Link;
7-
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
87
use Icinga\Date\DateFormatter;
98
use Icinga\Module\Director\Core\Json;
109
use Icinga\Module\Director\DirectorObject\Automation\Basket;
1110
use RuntimeException;
1211

13-
class BasketSnapshotTable extends ZfQueryBasedTable
12+
class BasketSnapshotTable extends IntlZfQueryBasedTable
1413
{
1514
use DbHelper;
1615

library/Director/Web/Table/DeploymentLogTable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Icinga\Module\Director\Web\Table;
44

55
use gipfl\IcingaWeb2\Link;
6-
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
76
use Icinga\Date\DateFormatter;
87

9-
class DeploymentLogTable extends ZfQueryBasedTable
8+
class DeploymentLogTable extends IntlZfQueryBasedTable
109
{
1110
use DbHelper;
1211

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Icinga\Module\Director\Web\Table;
4+
5+
use DateTime;
6+
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
7+
use IntlDateFormatter;
8+
use Locale;
9+
10+
abstract class IntlZfQueryBasedTable extends ZfQueryBasedTable
11+
{
12+
protected function getDateFormatter()
13+
{
14+
return (new IntlDateFormatter(
15+
Locale::getDefault(),
16+
IntlDateFormatter::FULL,
17+
IntlDateFormatter::NONE
18+
));
19+
}
20+
21+
/**
22+
* @param int $timestamp
23+
*/
24+
protected function renderDayIfNew($timestamp)
25+
{
26+
$day = $this->getDateFormatter()->format((new DateTime())->setTimestamp($timestamp));
27+
28+
if ($this->lastDay !== $day) {
29+
$this->nextHeader()->add(
30+
$this::th($day, [
31+
'colspan' => 2,
32+
'class' => 'table-header-day'
33+
])
34+
);
35+
36+
$this->lastDay = $day;
37+
$this->nextBody();
38+
}
39+
}
40+
41+
protected function getTime(int $timeStamp)
42+
{
43+
$timeFormatter = $this->getDateFormatter();
44+
45+
$timeFormatter->setPattern(
46+
in_array(Locale::getDefault(), ['en_US', 'en_US.UTF-8']) ? 'h:mm:ss a': 'H:mm:ss'
47+
);
48+
49+
return $timeFormatter->format((new DateTime())->setTimestamp($timeStamp));
50+
}
51+
}

library/Director/Web/Table/SyncRunTable.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
use Icinga\Module\Director\Objects\SyncRule;
66
use gipfl\IcingaWeb2\Link;
7-
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
87

9-
class SyncRunTable extends ZfQueryBasedTable
8+
class SyncRunTable extends IntlZfQueryBasedTable
109
{
1110
/** @var SyncRule */
1211
protected $rule;
@@ -28,7 +27,7 @@ public function renderRow($row)
2827
return $this::tr([
2928
$this::td($this->makeSummary($row)),
3029
$this::td(new Link(
31-
strftime('%H:%M:%S', $time),
30+
$this->getTime($time),
3231
'director/syncrule/history',
3332
[
3433
'id' => $row->rule_id,

0 commit comments

Comments
 (0)