[TASK] Deprecate MenuViewHelperTrait
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid_styled_content / Classes / ViewHelpers / Menu / UpdatedViewHelper.php
1 <?php
2 namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A view helper which returns recently updated subpages (multiple levels) of the given pages
19 *
20 * = Example =
21 *
22 * <code title="Pages with the similar keyword(s) of page uid = 1 and uid = 2">
23 * <ce:menu.updated pageUids="{0: 1, 1: 2}" as="pages">
24 * <f:for each="{pages}" as="page">
25 * {page.title}
26 * </f:for>
27 * </ce:menu.updated>
28 * </code>
29 *
30 * <output>
31 * Recently updated subpage 1
32 * Recently updated subpage 2
33 * Recently updated subpage 3
34 * </output>
35 */
36 class UpdatedViewHelper extends AbstractMenuViewHelper
37 {
38 /**
39 * Output escaping is disabled as child content contains HTML by default
40 *
41 * @var bool
42 */
43 protected $escapeOutput = false;
44
45 /**
46 * Initialize ViewHelper arguments
47 *
48 * @return void
49 */
50 public function initializeArguments()
51 {
52 $this->registerArgument('as', 'string', 'Name of the template variable that will contain selected pages', true);
53 $this->registerArgument('pageUids', 'array', 'Page UIDs of parent pages', false, array());
54 $this->registerArgument('sortField', 'string', 'Field to sort pages; possible values: starttime, lastUpdated, tstamp, crdate', false, 'SYS_LASTCHANGED');
55 $this->registerArgument('maximumAge', 'string', 'Maximum age of pages to be included; supports mathematical expressions', false, '604800');
56 $this->registerArgument('includeNotInMenu', 'boolean', 'Include pages that are marked "hide in menu"?', false, false);
57 $this->registerArgument('includeMenuSeparator', 'boolean', 'Include pages of the type "Menu separator"?', false, false);
58 $this->registerArgument('excludeNoSearchPages', 'boolean', 'Exclude pages that are NOT marked "include in search"?', false, true);
59 }
60
61 /**
62 * Render the view helper
63 *
64 * @return string
65 */
66 public function render()
67 {
68 $typoScriptFrontendController = $this->getTypoScriptFrontendController();
69 $as = (string)$this->arguments['as'];
70 $pageUids = (array)$this->arguments['pageUids'];
71 $sortField = $this->arguments['sortField'];
72 $maximumAge = $this->arguments['maximumAge'];
73 $includeNotInMenu = (bool)$this->arguments['includeNotInMenu'];
74 $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
75 $excludeNoSearchPages = (bool)$this->arguments['excludeNoSearchPages'];
76
77 // If no pages have been defined, use the current page
78 if (empty($pageUids)) {
79 $pageUids = array($typoScriptFrontendController->page['uid']);
80 }
81
82 $unfilteredPageTreeUids = array();
83 foreach ($pageUids as $pageUid) {
84 $unfilteredPageTreeUids = array_merge(
85 $unfilteredPageTreeUids,
86 explode(
87 ',',
88 $typoScriptFrontendController->cObj->getTreeList($pageUid, 20)
89 )
90 );
91 }
92 $pageTreeUids = array_unique($unfilteredPageTreeUids);
93
94 $constraints = $this->getPageConstraints($includeNotInMenu, $includeMenuSeparator);
95
96 if ($excludeNoSearchPages) {
97 $constraints .= ' AND no_search = 0';
98 }
99
100 if (!in_array($sortField, ['starttime', 'lastUpdated', 'tstamp', 'crdate'])) {
101 $sortField = 'SYS_LASTCHANGED';
102 }
103
104 $minimumTimeStamp = time() - (int)$typoScriptFrontendController->cObj->calc($maximumAge);
105 $constraints .= ' AND ' . $sortField . ' >=' . $minimumTimeStamp;
106
107 $pages = $typoScriptFrontendController->sys_page->getMenuForPages(
108 $pageTreeUids,
109 '*',
110 $sortField . ' DESC',
111 $constraints
112 );
113 return $this->renderChildrenWithVariables(array(
114 $as => $pages
115 ));
116 }
117 }