TYPO3 CMS  TYPO3_6-2
RecyclerModuleController.php
Go to the documentation of this file.
1 <?php
3 
18 
19 // This checks permissions and exits if the users has no permission for entry.
20 
27 
31  public $doc;
32 
33  protected $relativePath;
34 
35  protected $pageRecord = array();
36 
37  protected $isAccessibleForCurrentUser = FALSE;
38 
39  protected $allowDelete = FALSE;
40 
41  protected $recordsPageLimit = 50;
42 
46  protected $pageRenderer;
47 
51  public function __construct() {
52  $GLOBALS['LANG']->includeLLFile('EXT:recycler/mod1/locallang.xlf');
53  $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
54  }
55 
61  public function initialize() {
62  parent::init();
63  $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
64  $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('recycler') . 'mod1/mod_template.html');
65  $this->doc->backPath = $GLOBALS['BACK_PATH'];
66  $this->doc->setExtDirectStateProvider();
67  $this->pageRenderer = $this->doc->getPageRenderer();
69  $this->pageRecord = BackendUtility::readPageAccess($this->id, $this->perms_clause);
70  $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin();
71  //don't access in workspace
72  if ($GLOBALS['BE_USER']->workspace !== 0) {
73  $this->isAccessibleForCurrentUser = FALSE;
74  }
75  //read configuration
76  $modTS = $GLOBALS['BE_USER']->getTSConfig('mod.recycler');
77  if ($this->isCurrentUserAdmin()) {
78  $this->allowDelete = TRUE;
79  } else {
80  $this->allowDelete = $modTS['properties']['allowDelete'] == '1';
81  }
82  if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
83  $this->recordsPageLimit = (int)$modTS['properties']['recordsPageLimit'];
84  }
85  }
86 
92  public function render() {
93  $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
94  $this->content .= '<p class="lead">' . $GLOBALS['LANG']->getLL('description') . '</p>';
95  if ($this->isAccessibleForCurrentUser) {
96  $this->loadHeaderData();
97  // div container for renderTo
98  $this->content .= '<div id="recyclerContent"></div>';
99  } else {
100  // If no access or if ID == zero
101  $this->content .= $this->doc->spacer(10);
102  }
103  }
104 
110  public function flush() {
111  $content = $this->doc->moduleBody($this->pageRecord, $this->getDocHeaderButtons(), $this->getTemplateMarkers());
112  // Renders the module page
113  $content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $content);
114  $this->content = NULL;
115  $this->doc = NULL;
116  echo $content;
117  }
118 
124  protected function isCurrentUserAdmin() {
125  return (bool) $GLOBALS['BE_USER']->user['admin'];
126  }
127 
133  protected function loadHeaderData() {
134  // Load CSS Stylesheets:
135  $this->pageRenderer->addCssFile($this->relativePath . 'res/css/customExtJs.css');
136  // Load Ext JS:
137  $this->pageRenderer->loadExtJS();
138  $this->pageRenderer->enableExtJSQuickTips();
139  // Integrate dynamic JavaScript such as configuration or lables:
140  $this->pageRenderer->addInlineSettingArray('Recycler', $this->getJavaScriptConfiguration());
141  $this->pageRenderer->addInlineLanguageLabelArray($this->getJavaScriptLabels());
142  // Load Recycler JavaScript:
143  // Load Plugins
144  $uxPath = $this->doc->backpath . 'js/extjs/ux/';
145  $this->pageRenderer->addJsFile($uxPath . 'Ext.grid.RowExpander.js');
146  $this->pageRenderer->addJsFile($uxPath . 'Ext.app.SearchField.js');
147  $this->pageRenderer->addJsFile($uxPath . 'Ext.ux.FitToParent.js');
148  // Load main script
149  $this->pageRenderer->addJsFile($this->relativePath . 'res/js/t3_recycler.js');
150  }
151 
157  protected function getJavaScriptConfiguration() {
158  $configuration = array(
159  'pagingSize' => $this->recordsPageLimit,
160  'showDepthMenu' => 1,
161  'startUid' => $this->id,
162  'tableDefault' => 'pages',
163  'renderTo' => 'recyclerContent',
164  'isSSL' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL'),
165  'deleteDisable' => $this->allowDelete ? 0 : 1,
166  'depthSelection' => $this->getDataFromSession('depthSelection', 0),
167  'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'),
168  'States' => $GLOBALS['BE_USER']->uc['moduleData']['web_recycler']['States']
169  );
170  return $configuration;
171  }
172 
178  protected function getJavaScriptLabels() {
179  $coreLabels = array(
180  'title' => $GLOBALS['LANG']->getLL('title'),
181  'path' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'),
182  'table' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'),
183  'depth' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'),
184  'depth_0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
185  'depth_1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
186  'depth_2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
187  'depth_3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
188  'depth_4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
189  'depth_infi' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
190  );
191  $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
192  $javaScriptLabels = array_merge($coreLabels, $extensionLabels);
193  return $javaScriptLabels;
194  }
195 
204  protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
205  $extraction = array();
206  $labels = array_merge((array) $GLOBALS['LOCAL_LANG']['default'], (array) $GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]);
207  // Regular expression to strip the selection prefix and possibly something from the label name:
208  $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
209  // Iterate through all locallang labels:
210  foreach ($labels as $label => $value) {
211  if (strpos($label, $selectionPrefix) === 0) {
212  $key = preg_replace($labelPattern, '', $label);
213  $extraction[$key] = $value;
214  }
215  }
216  return $extraction;
217  }
218 
224  protected function getDocHeaderButtons() {
225  $buttons = array(
226  'csh' => BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
227  'shortcut' => $this->getShortcutButton(),
228  'save' => ''
229  );
230  // SAVE button
231  $buttons['save'] = '';
232  return $buttons;
233  }
234 
240  protected function getShortcutButton() {
241  $result = '';
242  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
243  $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
244  }
245  return $result;
246  }
247 
253  protected function getTemplateMarkers() {
254  $markers = array(
255  'FUNC_MENU' => $this->getFunctionMenu(),
256  'CONTENT' => $this->content,
257  'TITLE' => $GLOBALS['LANG']->getLL('title')
258  );
259  return $markers;
260  }
261 
267  protected function getFunctionMenu() {
268  return BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
269  }
270 
278  protected function getDataFromSession($identifier, $default = NULL) {
279  $sessionData = &$GLOBALS['BE_USER']->uc['tx_recycler'];
280  if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
281  $data = $sessionData[$identifier];
282  } else {
283  $data = $default;
284  }
285  return $data;
286  }
287 
288 }
static readPageAccess($id, $perms_clause)
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
getJavaScriptLabelsFromLocallang($selectionPrefix='js.', $stripFromSelectionName='')
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]