TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DocumentController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Documentation\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 
29 
34 {
39 
44 
48  protected $languageUtility;
49 
54 
60  protected $defaultViewObjectName = BackendTemplateView::class;
61 
67  protected $view;
68 
74  protected function initializeView(ViewInterface $view)
75  {
76  if ($view instanceof BackendTemplateView) {
78  parent::initializeView($view);
79  $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
80  $uriBuilder = $this->objectManager->get(UriBuilder::class);
81  $uriBuilder->setRequest($this->request);
82 
83  $this->view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Documentation/Main');
84  $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
85  $menu->setIdentifier('DocumentationModuleMenu');
86 
87  $isListActive = $this->request->getControllerActionName() === 'list' ? true : false;
88  $uri = $uriBuilder->reset()->uriFor('list', [], 'Document');
89  $listMenuItem = $menu->makeMenuItem()
90  ->setTitle($this->getLanguageService()
91  ->sL('LLL:EXT:documentation/Resources/Private/Language/locallang.xlf:showDocumentation'))
92  ->setHref($uri)
93  ->setActive($isListActive);
94  $menu->addMenuItem($listMenuItem);
95 
96  if ($this->getBackendUser()->isAdmin()) {
97  $isDownloadActive = $this->request->getControllerActionName() ===
98  'download' ? true : false;
99  $uri =
100  $uriBuilder->reset()->uriFor('download', [], 'Document');
101  $downloadMenuItem = $menu->makeMenuItem()
102  ->setTitle($this->getLanguageService()
103  ->sL('LLL:EXT:documentation/Resources/Private/Language/locallang.xlf:downloadDocumentation'))
104  ->setHref($uri)
105  ->setActive($isDownloadActive);
106  $menu->addMenuItem($downloadMenuItem);
107  }
108 
109  $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
110  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
111  }
112  }
113 
118  {
119  $this->documentRepository = $documentRepository;
120  }
121 
126  {
127  $this->documentationService = $documentationService;
128  }
129 
134  {
135  $this->languageUtility = $languageUtility;
136  }
137 
142  {
143  $this->signalSlotDispatcher = $signalSlotDispatcher;
144  }
145 
151  public function listAction()
152  {
153  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
154 
155  $documents = $this->getDocuments();
156 
157  // Filter documents to be shown for current user
158  $hideDocuments = $this->getBackendUser()->getTSConfigVal('mod.help_DocumentationDocumentation.documents.hide');
159  $hideDocuments = GeneralUtility::trimExplode(',', $hideDocuments, true);
160  if (!empty($hideDocuments)) {
161  $documents = array_diff_key($documents, array_flip($hideDocuments));
162  }
163  $showDocuments = $this->getBackendUser()->getTSConfigVal('mod.help_DocumentationDocumentation.documents.show');
164  $showDocuments = GeneralUtility::trimExplode(',', $showDocuments, true);
165  if (!empty($showDocuments)) {
166  $documents = array_intersect_key($documents, array_flip($showDocuments));
167  }
168 
169  $this->view->assign('documents', $documents);
170  }
171 
178  public function getDocuments()
179  {
180  $language = $this->languageUtility->getDocumentationLanguage();
181  $documents = $this->documentRepository->findByLanguage($language);
182 
183  $documents = $this->emitAfterInitializeDocumentsSignal($language, $documents);
184 
185  return $documents;
186  }
187 
195  protected function emitAfterInitializeDocumentsSignal($language, array $documents)
196  {
197  $this->signalSlotDispatcher->dispatch(
198  __CLASS__,
199  'afterInitializeDocuments',
200  [
201  $language,
202  &$documents,
203  ]
204  );
205  return $documents;
206  }
207 
213  public function downloadAction()
214  {
215  // This action is reserved for admin users. Redirect to default view if not.
216  if (!$this->getBackendUser()->isAdmin()) {
217  $this->redirect('list');
218  }
219 
220  // Retrieve the list of official documents
221  $documents = $this->documentationService->getOfficialDocuments();
222 
223  // Merge with the list of local extensions
224  $extensions = $this->documentationService->getLocalExtensions();
225  $allDocuments = array_merge($documents, $extensions);
226 
227  $this->view->assign('documents', $allDocuments);
228  }
229 
238  public function fetchAction($url, $key, $version = null)
239  {
240  // This action is reserved for admin users. Redirect to default view if not.
241  if (!$this->getBackendUser()->isAdmin()) {
242  $this->redirect('list');
243  }
244 
245  $language = $this->languageUtility->getDocumentationLanguage();
246  try {
247  $result = $this->documentationService->fetchNearestDocument($url, $key, $version ?: 'latest', $language);
248  if ($result) {
249  $this->addFlashMessage(
251  'downloadSucceeded',
252  'documentation'
253  ),
254  '',
256  );
257  } else {
258  $this->addFlashMessage(
260  'downloadFailedNoArchive',
261  'documentation'
262  ),
264  'downloadFailed',
265  'documentation'
266  ),
268  );
269  }
270  } catch (\Exception $e) {
271  $this->addFlashMessage(
273  'downloadFailedDetails',
274  'documentation',
275  [
276  $key,
277  $e->getMessage(),
278  $e->getCode()
279  ]
280  ),
282  'downloadFailed',
283  'documentation'
284  ),
286  );
287  }
288  $this->redirect('download');
289  }
290 
296  protected function getBackendUser()
297  {
298  return $GLOBALS['BE_USER'];
299  }
300 
306  protected function getLanguageService()
307  {
308  return $GLOBALS['LANG'];
309  }
310 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher)
injectDocumentationService(DocumentationService $documentationService)
static translate($key, $extensionName, $arguments=null)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
addFlashMessage($messageBody, $messageTitle= '', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)
injectDocumentRepository(DocumentRepository $documentRepository)