|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\ViewHelper; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2009-2015 Ingo Renner <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* viewhelper class to format unix timestamps as date |
|
33
|
|
|
* Replaces viewhelpers ###DATE:timestamp### |
|
34
|
|
|
* |
|
35
|
|
|
* @author Ingo Renner <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
class Date implements ViewHelper |
|
38
|
|
|
{ |
|
39
|
|
|
protected $dateFormat = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* instance of ContentObjectRenderer |
|
43
|
|
|
* |
|
44
|
|
|
* @var ContentObjectRenderer |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $contentObject = null; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Constructor |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $arguments |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function __construct(array $arguments = []) |
|
54
|
|
|
{ |
|
55
|
4 |
|
if (is_null($this->dateFormat) || is_null($this->contentObject)) { |
|
56
|
4 |
|
$configuration = Util::getSolrConfiguration(); |
|
57
|
4 |
|
$this->dateFormat = $configuration->getValueByPathOrDefaultValue('plugin.tx_solr.general.dateFormat.', ['date' => 'd.m.Y H:i']); |
|
58
|
4 |
|
$this->contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
|
59
|
4 |
|
} |
|
60
|
4 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Converts a given unix timestamp to a human readable date |
|
64
|
|
|
* |
|
65
|
|
|
* @param array $arguments |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
4 |
|
public function execute(array $arguments = []) |
|
69
|
|
|
{ |
|
70
|
4 |
|
$content = ''; |
|
71
|
|
|
|
|
72
|
4 |
|
if (count($arguments) > 1) { |
|
73
|
2 |
|
$this->dateFormat['date'] = $arguments[1]; |
|
74
|
2 |
|
} |
|
75
|
4 |
|
if (is_numeric($arguments[0])) { |
|
76
|
4 |
|
$content = $this->contentObject->stdWrap($arguments[0], |
|
77
|
4 |
|
$this->dateFormat); |
|
78
|
4 |
|
} |
|
79
|
|
|
|
|
80
|
4 |
|
return $content; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|