4bc82da21a4e300cf2ac2a7db6859aea16518197
[Packages/TYPO3.CMS.git] / typo3 / sysext / func / Classes / Controller / PageFunctionsController.php
1 <?php
2 namespace TYPO3\CMS\Func\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31
32 /**
33 * Script Class for the Web > Functions module
34 * This class creates the framework to which other extensions can connect their sub-modules
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
39
40 /**
41 * @Internal
42 * @todo Define visibility
43 */
44 public $pageinfo;
45
46 /**
47 * @todo Define visibility
48 */
49 public $fileProcessor;
50
51 /**
52 * Document Template Object
53 *
54 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
55 * @todo Define visibility
56 */
57 public $doc;
58
59 /**
60 * Constructor
61 */
62 public function __construct() {
63 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
64 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
65 }
66
67 /**
68 * Initialize module header etc and call extObjContent function
69 *
70 * @return void
71 */
72 public function main() {
73 // Access check...
74 // The page will show only if there is a valid page and if this page may be viewed by the user
75 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
76 $access = is_array($this->pageinfo);
77 // Template markers
78 $markers = array(
79 'CSH' => '',
80 'FUNC_MENU' => '',
81 'CONTENT' => ''
82 );
83 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
84 $this->doc->backPath = $GLOBALS['BACK_PATH'];
85 $this->doc->setModuleTemplate('EXT:func/Resources/Private/Templates/func.html');
86 // Main
87 if ($this->id && $access) {
88 // JavaScript
89 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
90 // Setting up the context sensitive menu:
91 $this->doc->getContextMenuCode();
92 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
93 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
94 if ($vContent) {
95 $this->content .= $this->doc->section('', $vContent);
96 }
97 $this->extObjContent();
98 // Setting up the buttons and markers for docheader
99 $docHeaderButtons = $this->getButtons();
100 $markers['CSH'] = $docHeaderButtons['csh'];
101 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
102 $this->id,
103 'SET[function]',
104 $this->MOD_SETTINGS['function'],
105 $this->MOD_MENU['function']
106 );
107 $markers['CONTENT'] = $this->content;
108 } else {
109 // If no access or if ID == zero
110 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
111 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
112 $GLOBALS['LANG']->getLL('clickAPage_content'),
113 $GLOBALS['LANG']->getLL('title'),
114 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
115 );
116 $this->content = $flashMessage->render();
117 // Setting up the buttons and markers for docheader
118 $docHeaderButtons = $this->getButtons();
119 $markers['CSH'] = $docHeaderButtons['csh'];
120 $markers['CONTENT'] = $this->content;
121 }
122 // Build the <body> for the module
123 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
124 // Renders the module page
125 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
126 }
127
128 /**
129 * Print module content (from $this->content)
130 *
131 * @return void
132 */
133 public function printContent() {
134 echo $this->content;
135 }
136
137 /**
138 * Create the panel of buttons for submitting the form or otherwise perform operations.
139 *
140 * @return array All available buttons as an assoc. array
141 */
142 protected function getButtons() {
143 $buttons = array(
144 'csh' => '',
145 'view' => '',
146 'shortcut' => ''
147 );
148 // CSH
149 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH'], '', TRUE);
150 if ($this->id && is_array($this->pageinfo)) {
151 // View page
152 $buttons['view'] = '<a href="#" '
153 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
154 . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
155 . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
156 // Shortcut
157 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
158 $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']);
159 }
160 }
161 return $buttons;
162 }
163
164 }