|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | /** |
4 | | - * EasePHPbricks - Live Age |
| 6 | + * This file is part of the EaseHtmlWidgets package |
| 7 | + * |
| 8 | + * https://github.com/VitexSoftware/php-vitexsoftware-ease-html-widgets |
| 9 | + * |
| 10 | + * (c) Vítězslav Dvořák <http://vitexsoftware.com> |
5 | 11 | * |
6 | | - * @author Vítězslav Dvořák <vitex@arachne.cz> |
7 | | - * @copyright 2018 Vitex Software |
| 12 | + * For the full copyright and license information, please view the LICENSE |
| 13 | + * file that was distributed with this source code. |
8 | 14 | */ |
9 | 15 |
|
10 | 16 | namespace Ease\Html\Widgets; |
11 | 17 |
|
12 | 18 | /** |
13 | | - * LiveAge |
| 19 | + * LiveAge. |
14 | 20 | * |
15 | 21 | * @author Vítězslav Dvořák <info@vitexsoftware.cz> |
16 | 22 | */ |
17 | 23 | class LiveAge extends \Ease\Html\TimeTag |
18 | 24 | { |
19 | 25 | /** |
20 | | - * Show live time to timestamp |
| 26 | + * Show live time to timestamp. |
21 | 27 | * |
22 | | - * @param long $timestamp UnixTime |
23 | | - * @param array $properties TimeTag properties |
| 28 | + * @param long $timestamp UnixTime |
| 29 | + * @param array $properties TimeTag properties |
24 | 30 | */ |
25 | 31 | public function __construct($timestamp, $properties = []) |
26 | 32 | { |
27 | | - $age = time() - $timestamp; |
| 33 | + $age = time() - $timestamp; |
28 | 34 | $days = floor($age / 86400); |
29 | 35 | $dater = new \DateTime(); |
30 | 36 | $dater->setTimestamp($timestamp); |
31 | 37 | $properties['datetime'] = $dater->format('Y-m-d\TH:i:s'); |
32 | 38 | parent::__construct( |
33 | | - $days . ' ' . _('days') . ', ' . gmdate("G:i:s", $age), |
34 | | - $properties |
| 39 | + $days.' '._('days').', '.gmdate('G:i:s', $age), |
| 40 | + $properties, |
35 | 41 | ); |
36 | 42 | $this->setTagID(); |
37 | 43 |
|
38 | | - $this->addJavaScript(' |
39 | | -var timestamp' . $this->getTagID() . ' = ' . $age . '; |
| 44 | + $this->addJavaScript(<<<'EOD' |
| 45 | +
|
| 46 | +var timestamp |
| 47 | +EOD.$this->getTagID().' = '.$age.<<<'EOD' |
| 48 | +; |
40 | 49 |
|
41 | 50 | function component(x, v) { |
42 | 51 | return Math.floor(x / v); |
43 | 52 | } |
44 | 53 |
|
45 | | -var $div' . $this->getTagID() . ' = $(\'#' . $this->getTagID() . '\'); |
| 54 | +var $div |
| 55 | +EOD.$this->getTagID().' = $(\'#'.$this->getTagID().<<<'EOD' |
| 56 | +'); |
46 | 57 |
|
47 | 58 | setInterval(function() { |
48 | 59 |
|
49 | | - timestamp' . $this->getTagID() . '++; |
| 60 | + timestamp |
| 61 | +EOD.$this->getTagID().<<<'EOD' |
| 62 | +++; |
50 | 63 |
|
51 | | - var days' . $this->getTagID() . ' = component(timestamp' . $this->getTagID() . ', 24 * 60 * 60), |
52 | | - hours' . $this->getTagID() . ' = component(timestamp' . $this->getTagID() . ', 60 * 60) % 24, |
53 | | - minutes' . $this->getTagID() . ' = component(timestamp' . $this->getTagID() . ', 60) % 60, |
54 | | - seconds' . $this->getTagID() . ' = component(timestamp' . $this->getTagID() . ', 1) % 60; |
| 64 | + var days |
| 65 | +EOD.$this->getTagID().' = component(timestamp'.$this->getTagID().<<<'EOD' |
| 66 | +, 24 * 60 * 60), |
| 67 | + hours |
| 68 | +EOD.$this->getTagID().' = component(timestamp'.$this->getTagID().<<<'EOD' |
| 69 | +, 60 * 60) % 24, |
| 70 | + minutes |
| 71 | +EOD.$this->getTagID().' = component(timestamp'.$this->getTagID().<<<'EOD' |
| 72 | +, 60) % 60, |
| 73 | + seconds |
| 74 | +EOD.$this->getTagID().' = component(timestamp'.$this->getTagID().<<<'EOD' |
| 75 | +, 1) % 60; |
55 | 76 |
|
56 | | - $div' . $this->getTagID() . '.html(days' . $this->getTagID() . ' + " ' . _('days') . ', " + hours' . $this->getTagID() . ' + ":" + minutes' . $this->getTagID() . ' + ":" + seconds' . $this->getTagID() . '); |
| 77 | + $div |
| 78 | +EOD.$this->getTagID().'.html(days'.$this->getTagID().' + " '._('days').', " + hours'.$this->getTagID().' + ":" + minutes'.$this->getTagID().' + ":" + seconds'.$this->getTagID().<<<'EOD' |
| 79 | +); |
57 | 80 |
|
58 | 81 | }, 1000); |
59 | | - '); |
| 82 | + |
| 83 | +EOD); |
60 | 84 | } |
61 | 85 | } |
0 commit comments