60072687a985b3d620ea1724b0e679b10ddee199
[Packages/TYPO3.CMS.git] / typo3 / sysext / func / Classes / Controller / PageFunctionsController.php
1 <?php
2 namespace TYPO3\CMS\Func\Controller;
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 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20 use TYPO3\CMS\Fluid\View\StandaloneView;
21 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
22
23 /**
24 * Script Class for the Web > Functions module
25 * This class creates the framework to which other extensions can connect their sub-modules
26 */
27 class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
28
29 /**
30 * @var array
31 * @internal
32 */
33 public $pageinfo;
34
35 /**
36 * Document Template Object
37 *
38 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
39 */
40 public $doc;
41
42 /**
43 * The name of the module
44 *
45 * @var string
46 */
47 protected $moduleName = 'web_func';
48
49 /**
50 * Constructor
51 */
52 public function __construct() {
53 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
54 $this->MCONF = array(
55 'name' => $this->moduleName,
56 );
57 }
58
59 /**
60 * Initialize module header etc and call extObjContent function
61 *
62 * @return void
63 */
64 public function main() {
65 // Access check...
66 // The page will show only if there is a valid page and if this page may be viewed by the user
67 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
68 $access = is_array($this->pageinfo);
69 // Template markers
70 $markers = array(
71 'CSH' => '',
72 'FUNC_MENU' => '',
73 'CONTENT' => ''
74 );
75 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
76 $this->doc->backPath = $GLOBALS['BACK_PATH'];
77 $this->doc->setModuleTemplate('EXT:func/Resources/Private/Templates/func.html');
78 // Main
79 if ($this->id && $access) {
80 // JavaScript
81 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
82 // Setting up the context sensitive menu:
83 $this->doc->getContextMenuCode();
84 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
85 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
86 if ($vContent) {
87 $this->content .= $this->doc->section('', $vContent);
88 }
89 $this->extObjContent();
90 // Setting up the buttons and markers for docheader
91 $docHeaderButtons = $this->getButtons();
92 $markers['CSH'] = $docHeaderButtons['csh'];
93 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
94 $this->id,
95 'SET[function]',
96 $this->MOD_SETTINGS['function'],
97 $this->MOD_MENU['function']
98 );
99 $markers['CONTENT'] = $this->content;
100 } else {
101 // If no access or if ID == zero
102 $title = $this->getLanguageService()->getLL('title');
103 $message = $this->getLanguageService()->getLL('clickAPage_content');
104 $view = GeneralUtility::makeInstance(StandaloneView::class);
105 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
106 $view->assignMultiple(array(
107 'title' => $title,
108 'message' => $message,
109 'state' => InfoboxViewHelper::STATE_INFO
110 ));
111 $this->content = $view->render();
112
113 // Setting up the buttons and markers for docheader
114 $docHeaderButtons = $this->getButtons();
115 $markers['CSH'] = $docHeaderButtons['csh'];
116 $markers['CONTENT'] = $this->content;
117 }
118 // Build the <body> for the module
119 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
120 // Renders the module page
121 $this->content = $this->doc->render($this->getLanguageService()->getLL('title'), $this->content);
122 }
123
124 /**
125 * Print module content (from $this->content)
126 *
127 * @return void
128 */
129 public function printContent() {
130 echo $this->content;
131 }
132
133 /**
134 * Create the panel of buttons for submitting the form or otherwise perform operations.
135 *
136 * @return array All available buttons as an assoc. array
137 */
138 protected function getButtons() {
139 $buttons = array(
140 'csh' => '',
141 'view' => '',
142 'shortcut' => ''
143 );
144 // CSH
145 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '');
146 if ($this->id && is_array($this->pageinfo)) {
147 // View page
148 $buttons['view'] = '<a href="#" '
149 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
150 . 'title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
151 . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
152 // Shortcut
153 if ($this->getBackendUser()->mayMakeShortcut()) {
154 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->moduleName);
155 }
156 }
157 return $buttons;
158 }
159
160 /**
161 * Returns LanguageService
162 *
163 * @return \TYPO3\CMS\Lang\LanguageService
164 */
165 protected function getLanguageService() {
166 return $GLOBALS['LANG'];
167 }
168
169 /**
170 * Returns the current BE user.
171 *
172 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
173 */
174 protected function getBackendUser() {
175 return $GLOBALS['BE_USER'];
176 }
177
178
179 }