TYPO3  7.6
PageFunctionsController.php
Go to the documentation of this file.
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 
26 
32 {
37  public $pageinfo;
38 
44  protected $moduleTemplate;
45 
51  public $doc;
52 
58  protected $moduleName = 'web_func';
59 
63  protected $iconFactory;
64 
68  public function __construct()
69  {
70  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
71  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
72  $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
73  $this->MCONF = array(
74  'name' => $this->moduleName,
75  );
76  }
77 
87  {
88  $GLOBALS['SOBE'] = $this;
89  $this->init();
90 
91  // Checking for first level external objects
92  $this->checkExtObj();
93 
94  // Checking second level external objects
95  $this->checkSubExtObj();
96  $this->main();
97 
98  $this->moduleTemplate->setContent($this->content);
99 
100  $response->getBody()->write($this->moduleTemplate->renderContent());
101  return $response;
102  }
103 
109  public function main()
110  {
111  // Access check...
112  // The page will show only if there is a valid page and if this page may be viewed by the user
113  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
114  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
115  $access = is_array($this->pageinfo);
116  // We keep this here, in case somebody relies on the old doc being here
117  $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
118  // Main
119  if ($this->id && $access) {
120  // JavaScript
121  $this->moduleTemplate->addJavaScriptCode(
122  'WebFuncInLineJS',
123  'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
124  // Setting up the context sensitive menu:
125  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
126  $this->content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" id="PageFunctionsController" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
127  $vContent = $this->moduleTemplate->getVersionSelector($this->id, true);
128  if ($vContent) {
129  $this->content .= '<div>' . $vContent . '</div>';
130  }
131  $this->extObjContent();
132  // Setting up the buttons and markers for docheader
133  $this->getButtons();
134  $this->generateMenu();
135  $this->content .= '</form>';
136  } else {
137  // If no access or if ID == zero
138  $title = $this->getLanguageService()->getLL('title');
139  $message = $this->getLanguageService()->getLL('clickAPage_content');
140  $view = GeneralUtility::makeInstance(StandaloneView::class);
141  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
142  $view->assignMultiple(array(
143  'title' => $title,
144  'message' => $message,
146  ));
147  $this->content = $view->render();
148  // Setting up the buttons and markers for docheader
149  $this->getButtons();
150  }
151  }
152 
158  protected function generateMenu()
159  {
160  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
161  $menu->setIdentifier('WebFuncJumpMenu');
162  foreach ($this->MOD_MENU['function'] as $controller => $title) {
163  $item = $menu
164  ->makeMenuItem()
165  ->setHref(
166  BackendUtility::getModuleUrl(
167  $this->moduleName,
168  [
169  'id' => $this->id,
170  'SET' => [
171  'function' => $controller
172  ]
173  ]
174  )
175  )
176  ->setTitle($title);
177  if ($controller === $this->MOD_SETTINGS['function']) {
178  $item->setActive(true);
179  }
180  $menu->addMenuItem($item);
181  }
182  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
183  }
184 
191  public function printContent()
192  {
194  echo $this->content;
195  }
196 
200  protected function getButtons()
201  {
202  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
203  // CSH
204  $cshButton = $buttonBar->makeHelpButton()
205  ->setModuleName('_MOD_web_func')
206  ->setFieldName('');
207  $buttonBar->addButton($cshButton);
208  if ($this->id && is_array($this->pageinfo)) {
209  // View page
210  $viewButton = $buttonBar->makeLinkButton()
211  ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
212  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
213  ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
214  ->setHref('#');
215  $buttonBar->addButton($viewButton);
216  // Shortcut
217  $shortcutButton = $buttonBar->makeShortcutButton()
218  ->setModuleName($this->moduleName)
219  ->setGetVariables(['id', 'edit_record', 'pointer', 'new_unique_uid', 'search_field', 'search_levels', 'showLimit'])
220  ->setSetVariables(array_keys($this->MOD_MENU));
221  $buttonBar->addButton($shortcutButton);
222  }
223  }
224 
230  protected function getLanguageService()
231  {
232  return $GLOBALS['LANG'];
233  }
234 
240  protected function getBackendUser()
241  {
242  return $GLOBALS['BE_USER'];
243  }
244 }