f12cb7b5520cd011d5e59cc6c94b2011e7e9e715
[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 class InfoModuleController extends BaseScriptClass {
27
28 /**
29 * @var array
30 */
31 public $pageinfo;
32
33 /**
34 * Document Template Object
35 *
36 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
37 */
38 public $doc;
39
40 /**
41 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
42 */
43 protected $backendUser;
44
45 /**
46 * @var \TYPO3\CMS\Lang\LanguageService
47 */
48 protected $languageService;
49
50 /**
51 * The name of the module
52 *
53 * @var string
54 */
55 protected $moduleName = 'web_info';
56
57 /**
58 * Constructor
59 */
60 public function __construct() {
61 $this->languageService = $GLOBALS['LANG'];
62 $this->languageService->includeLLFile('EXT:lang/locallang_mod_web_info.xlf');
63
64 $this->backendUser = $GLOBALS['BE_USER'];
65
66 $this->MCONF = array(
67 'name' => $this->moduleName,
68 );
69 }
70
71 /**
72 * Initialize module header etc and call extObjContent function
73 *
74 * @return void
75 */
76 public function main() {
77 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
78 $this->doc->backPath = $GLOBALS['BACK_PATH'];
79
80 // The page will show only if there is a valid page and if this page
81 // may be viewed by the user
82 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
83 $access = is_array($this->pageinfo);
84 if ($this->id && $access || $this->backendUser->user['admin'] && !$this->id) {
85 if ($this->backendUser->user['admin'] && !$this->id) {
86 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
87 }
88 $this->doc->setModuleTemplate('EXT:info/Resources/Private/Templates/info.html');
89
90 // JavaScript
91 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
92 // Setting up the context sensitive menu:
93 $this->doc->getContextMenuCode();
94 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName)) .
95 '" method="post" name="webinfoForm" class="form-inline form-inline-spaced">';
96 $vContent = $this->doc->getVersionSelector($this->id, 1);
97 if ($vContent) {
98 $this->content .= $this->doc->section('', $vContent);
99 }
100 $this->extObjContent();
101 // Setting up the buttons and markers for docheader
102 $docHeaderButtons = $this->getButtons();
103 $markers = array(
104 'CSH' => $docHeaderButtons['csh'],
105 'FUNC_MENU' => BackendUtility::getFuncMenu(
106 $this->id,
107 'SET[function]',
108 $this->MOD_SETTINGS['function'],
109 $this->MOD_MENU['function']
110 ),
111 'CONTENT' => $this->content
112 );
113 // Build the <body> for the module
114 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
115 } else {
116 // If no access or if ID == zero
117 $this->content = $this->doc->header($this->languageService->getLL('title'));
118 }
119 // Renders the module page
120 $this->content = $this->doc->render($this->languageService->getLL('title'), $this->content);
121 }
122
123 /**
124 * Print module content (from $this->content)
125 *
126 * @return void
127 */
128 public function printContent() {
129 $this->content = $this->doc->insertStylesAndJS($this->content);
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_info', '');
146 // View page
147 $buttons['view'] = '<a href="#" ' .
148 'onclick="' . htmlspecialchars(
149 BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'],
150 BackendUtility::BEgetRootLine($this->pageinfo['uid']))
151 ) . '" ' .
152 'title="' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' .
153 IconUtility::getSpriteIcon('actions-document-view') .
154 '</a>';
155 // Shortcut
156 if ($this->backendUser->mayMakeShortcut()) {
157 $buttons['shortcut'] = $this->doc->makeShortcutIcon(
158 'id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit',
159 implode(',', array_keys($this->MOD_MENU)), $this->moduleName);
160 }
161 return $buttons;
162 }
163
164 }