7b99eb0dc76a863238ee708247eda5c6098802ce
[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->JScode = $this->doc->wrapScriptTags('
90 script_ended = 0;
91 function jumpToUrl(URL) {
92 window.location.href = URL;
93 }
94 ');
95 $this->doc->postCode = $this->doc->wrapScriptTags('
96 script_ended = 1;
97 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
98 ');
99 // Setting up the context sensitive menu:
100 $this->doc->getContextMenuCode();
101 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
102 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
103 if ($vContent) {
104 $this->content .= $this->doc->section('', $vContent);
105 }
106 $this->extObjContent();
107 // Setting up the buttons and markers for docheader
108 $docHeaderButtons = $this->getButtons();
109 $markers['CSH'] = $docHeaderButtons['csh'];
110 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
111 $this->id,
112 'SET[function]',
113 $this->MOD_SETTINGS['function'],
114 $this->MOD_MENU['function']
115 );
116 $markers['CONTENT'] = $this->content;
117 } else {
118 // If no access or if ID == zero
119 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
120 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
121 $GLOBALS['LANG']->getLL('clickAPage_content'),
122 $GLOBALS['LANG']->getLL('title'),
123 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
124 );
125 $this->content = $flashMessage->render();
126 // Setting up the buttons and markers for docheader
127 $docHeaderButtons = $this->getButtons();
128 $markers['CSH'] = $docHeaderButtons['csh'];
129 $markers['CONTENT'] = $this->content;
130 }
131 // Build the <body> for the module
132 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
133 // Renders the module page
134 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
135 }
136
137 /**
138 * Print module content (from $this->content)
139 *
140 * @return void
141 */
142 public function printContent() {
143 echo $this->content;
144 }
145
146 /**
147 * Create the panel of buttons for submitting the form or otherwise perform operations.
148 *
149 * @return array All available buttons as an assoc. array
150 */
151 protected function getButtons() {
152 $buttons = array(
153 'csh' => '',
154 'view' => '',
155 'shortcut' => ''
156 );
157 // CSH
158 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH'], '', TRUE);
159 if ($this->id && is_array($this->pageinfo)) {
160 // View page
161 $buttons['view'] = '<a href="#" '
162 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
163 . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
164 . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-view') . '</a>';
165 // Shortcut
166 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
167 $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']);
168 }
169 }
170 return $buttons;
171 }
172
173 }