dd226f0cdf4ca0d9b3184067a127106d8317d48c
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / InfoModuleController.php
1 <?php
2 namespace TYPO3\CMS\Info\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\Module\BaseScriptClass;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\Utility\IconUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Script Class for the Web > Info module
24 * This class creates the framework to which other extensions can connect their sub-modules
25 *
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 */
28 class InfoModuleController extends BaseScriptClass {
29
30 /**
31 * @var array
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 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
44 */
45 protected $backendUser;
46
47 /**
48 * @var \TYPO3\CMS\Lang\LanguageService
49 */
50 protected $languageService;
51
52 /**
53 * Constructor
54 */
55 public function __construct() {
56 $this->languageService = $GLOBALS['LANG'];
57 $this->languageService->includeLLFile('EXT:lang/locallang_mod_web_info.xlf');
58
59 $this->backendUser = $GLOBALS['BE_USER'];
60 $this->backendUser->modAccess($GLOBALS['MCONF'], TRUE);
61 }
62
63 /**
64 * Initialize module header etc and call extObjContent function
65 *
66 * @return void
67 */
68 public function main() {
69 // Access check...
70 // The page will show only if there is a valid page and if this page
71 // may be viewed by the user
72 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
73 $access = is_array($this->pageinfo);
74 if ($this->id && $access || $this->backendUser->user['admin'] && !$this->id) {
75 if ($this->backendUser->user['admin'] && !$this->id) {
76 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
77 }
78 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
79 $this->doc->backPath = $GLOBALS['BACK_PATH'];
80 $this->doc->setModuleTemplate('EXT:info/Resources/Private/Templates/info.html');
81 $this->doc->tableLayout = array(
82 '0' => array(
83 '0' => array('<td valign="top"><strong>', '</strong></td>'),
84 'defCol' => array('<td><img src="' . $this->doc->backPath .
85 'clear.gif" width="10" height="1" alt="" /></td><td valign="top"><strong>', '</strong></td>')
86 ),
87 'defRow' => array(
88 '0' => array('<td valign="top">', '</td>'),
89 'defCol' => array('<td><img src="' . $this->doc->backPath .
90 'clear.gif" width="10" height="1" alt="" /></td><td valign="top">', '</td>')
91 )
92 );
93 // JavaScript
94 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
95 // Setting up the context sensitive menu:
96 $this->doc->getContextMenuCode();
97 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_info')) .
98 '" method="post" name="webinfoForm">';
99 $vContent = $this->doc->getVersionSelector($this->id, 1);
100 if ($vContent) {
101 $this->content .= $this->doc->section('', $vContent);
102 }
103 $this->extObjContent();
104 // Setting up the buttons and markers for docheader
105 $docHeaderButtons = $this->getButtons();
106 $markers = array(
107 'CSH' => $docHeaderButtons['csh'],
108 'FUNC_MENU' => BackendUtility::getFuncMenu(
109 $this->id,
110 'SET[function]',
111 $this->MOD_SETTINGS['function'],
112 $this->MOD_MENU['function']
113 ),
114 'CONTENT' => $this->content
115 );
116 // Build the <body> for the module
117 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
118 } else {
119 // If no access or if ID == zero
120 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
121 $this->doc->backPath = $GLOBALS['BACK_PATH'];
122 $this->content = $this->doc->header($this->languageService->getLL('title'));
123 $this->content .= $this->doc->spacer(5);
124 $this->content .= $this->doc->spacer(10);
125 }
126 // Renders the module page
127 $this->content = $this->doc->render($this->languageService->getLL('title'), $this->content);
128 }
129
130 /**
131 * Print module content (from $this->content)
132 *
133 * @return void
134 */
135 public function printContent() {
136 $this->content = $this->doc->insertStylesAndJS($this->content);
137 echo $this->content;
138 }
139
140 /**
141 * Create the panel of buttons for submitting the form or otherwise perform operations.
142 *
143 * @return array All available buttons as an assoc. array
144 */
145 protected function getButtons() {
146 $buttons = array(
147 'csh' => '',
148 'view' => '',
149 'shortcut' => ''
150 );
151 // CSH
152 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_info', '', $GLOBALS['BACK_PATH'], '', TRUE);
153 // View page
154 $buttons['view'] = '<a href="#" ' .
155 'onclick="' . htmlspecialchars(
156 BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'],
157 BackendUtility::BEgetRootLine($this->pageinfo['uid']))
158 ) . '" ' .
159 'title="' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' .
160 IconUtility::getSpriteIcon('actions-document-view') .
161 '</a>';
162 // Shortcut
163 if ($this->backendUser->mayMakeShortcut()) {
164 $buttons['shortcut'] = $this->doc->makeShortcutIcon(
165 'id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit',
166 implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
167 }
168 return $buttons;
169 }
170 }