[TASK] BACK_PATH BE controller
[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->setModuleTemplate('EXT:func/Resources/Private/Templates/func.html');
77 // Main
78 if ($this->id && $access) {
79 // JavaScript
80 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
81 // Setting up the context sensitive menu:
82 $this->doc->getContextMenuCode();
83 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
84 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
85 if ($vContent) {
86 $this->content .= $this->doc->section('', $vContent);
87 }
88 $this->extObjContent();
89 // Setting up the buttons and markers for docheader
90 $docHeaderButtons = $this->getButtons();
91 $markers['CSH'] = $docHeaderButtons['csh'];
92 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
93 $this->id,
94 'SET[function]',
95 $this->MOD_SETTINGS['function'],
96 $this->MOD_MENU['function']
97 );
98 $markers['CONTENT'] = $this->content;
99 } else {
100 // If no access or if ID == zero
101 $title = $this->getLanguageService()->getLL('title');
102 $message = $this->getLanguageService()->getLL('clickAPage_content');
103 $view = GeneralUtility::makeInstance(StandaloneView::class);
104 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
105 $view->assignMultiple(array(
106 'title' => $title,
107 'message' => $message,
108 'state' => InfoboxViewHelper::STATE_INFO
109 ));
110 $this->content = $view->render();
111
112 // Setting up the buttons and markers for docheader
113 $docHeaderButtons = $this->getButtons();
114 $markers['CSH'] = $docHeaderButtons['csh'];
115 $markers['CONTENT'] = $this->content;
116 }
117 // Build the <body> for the module
118 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
119 // Renders the module page
120 $this->content = $this->doc->render($this->getLanguageService()->getLL('title'), $this->content);
121 }
122
123 /**
124 * Print module content (from $this->content)
125 *
126 * @return void
127 */
128 public function printContent() {
129 echo $this->content;
130 }
131
132 /**
133 * Create the panel of buttons for submitting the form or otherwise perform operations.
134 *
135 * @return array All available buttons as an assoc. array
136 */
137 protected function getButtons() {
138 $buttons = array(
139 'csh' => '',
140 'view' => '',
141 'shortcut' => ''
142 );
143 // CSH
144 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '');
145 if ($this->id && is_array($this->pageinfo)) {
146 // View page
147 $buttons['view'] = '<a href="#" '
148 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
149 . 'title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
150 . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
151 // Shortcut
152 if ($this->getBackendUser()->mayMakeShortcut()) {
153 $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);
154 }
155 }
156 return $buttons;
157 }
158
159 /**
160 * Returns LanguageService
161 *
162 * @return \TYPO3\CMS\Lang\LanguageService
163 */
164 protected function getLanguageService() {
165 return $GLOBALS['LANG'];
166 }
167
168 /**
169 * Returns the current BE user.
170 *
171 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
172 */
173 protected function getBackendUser() {
174 return $GLOBALS['BE_USER'];
175 }
176
177
178 }