442df36f02087157311f1aacc3275f3257b2c882
[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
19 /**
20 * Script Class for the Web > Functions module
21 * This class creates the framework to which other extensions can connect their sub-modules
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
26
27 /**
28 * @var array
29 * @internal
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 * Constructor
42 */
43 public function __construct() {
44 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
45 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
46 }
47
48 /**
49 * Initialize module header etc and call extObjContent function
50 *
51 * @return void
52 */
53 public function main() {
54 // Access check...
55 // The page will show only if there is a valid page and if this page may be viewed by the user
56 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
57 $access = is_array($this->pageinfo);
58 // Template markers
59 $markers = array(
60 'CSH' => '',
61 'FUNC_MENU' => '',
62 'CONTENT' => ''
63 );
64 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
65 $this->doc->backPath = $GLOBALS['BACK_PATH'];
66 $this->doc->setModuleTemplate('EXT:func/Resources/Private/Templates/func.html');
67 // Main
68 if ($this->id && $access) {
69 // JavaScript
70 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
71 // Setting up the context sensitive menu:
72 $this->doc->getContextMenuCode();
73 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
74 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
75 if ($vContent) {
76 $this->content .= $this->doc->section('', $vContent);
77 }
78 $this->extObjContent();
79 // Setting up the buttons and markers for docheader
80 $docHeaderButtons = $this->getButtons();
81 $markers['CSH'] = $docHeaderButtons['csh'];
82 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
83 $this->id,
84 'SET[function]',
85 $this->MOD_SETTINGS['function'],
86 $this->MOD_MENU['function']
87 );
88 $markers['CONTENT'] = $this->content;
89 } else {
90 // If no access or if ID == zero
91 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
92 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
93 $GLOBALS['LANG']->getLL('clickAPage_content'),
94 $GLOBALS['LANG']->getLL('title'),
95 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
96 );
97 $this->content = $flashMessage->render();
98 // Setting up the buttons and markers for docheader
99 $docHeaderButtons = $this->getButtons();
100 $markers['CSH'] = $docHeaderButtons['csh'];
101 $markers['CONTENT'] = $this->content;
102 }
103 // Build the <body> for the module
104 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
105 // Renders the module page
106 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
107 }
108
109 /**
110 * Print module content (from $this->content)
111 *
112 * @return void
113 */
114 public function printContent() {
115 echo $this->content;
116 }
117
118 /**
119 * Create the panel of buttons for submitting the form or otherwise perform operations.
120 *
121 * @return array All available buttons as an assoc. array
122 */
123 protected function getButtons() {
124 $buttons = array(
125 'csh' => '',
126 'view' => '',
127 'shortcut' => ''
128 );
129 // CSH
130 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH'], '', TRUE);
131 if ($this->id && is_array($this->pageinfo)) {
132 // View page
133 $buttons['view'] = '<a href="#" '
134 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
135 . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
136 . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
137 // Shortcut
138 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
139 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
140 }
141 }
142 return $buttons;
143 }
144
145 }