/** * @return JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function indexAction() { //set some permissions $permissions = $this->factory->getSecurity()->isGranted(['core:themes:view', 'core:themes:create', 'core:themes:edit', 'core:themes:delete'], "RETURN_ARRAY"); if (!$permissions['core:themes:view']) { return $this->accessDenied(); } $themeHelper = $this->container->get('mautic.helper.theme'); $dir = $this->factory->getSystemPath('themes', true); $action = $this->generateUrl('mautic_themes_index'); $form = $this->get('form.factory')->create('theme_upload', [], ['action' => $action]); if ($this->request->getMethod() == 'POST') { if (isset($form) && !($cancelled = $this->isFormCancelled($form))) { if ($this->isFormValid($form)) { $fileData = $form['file']->getData(); $fileName = InputHelper::filename($fileData->getClientOriginalName()); $themeName = basename($fileName, '.zip'); if (in_array($themeName, $this->defaultThemes)) { $form->addError(new FormError($this->factory->getTranslator()->trans('mautic.core.theme.default.cannot.overwrite', ['%name%' => $themeName], 'validators'))); } elseif (!empty($fileData)) { try { $fileData->move($dir, $fileName); $themeHelper->install($dir . '/' . $fileName); $this->addFlash('mautic.core.theme.installed', ['%name%' => $themeName]); } catch (\Exception $e) { $form->addError(new FormError($this->factory->getTranslator()->trans($e->getMessage(), [], 'validators'))); } } else { $form->addError(new FormError($this->factory->getTranslator()->trans('mautic.dashboard.upload.filenotfound', [], 'validators'))); } } } } return $this->delegateView(['viewParameters' => ['items' => $themeHelper->getInstalledThemes('all', true, true), 'defaultThemes' => $this->defaultThemes, 'form' => $form->createView(), 'permissions' => $permissions, 'security' => $this->factory->getSecurity()], 'contentTemplate' => 'MauticCoreBundle:Theme:list.html.php', 'passthroughVars' => ['activeLink' => '#mautic_themes_index', 'mauticContent' => 'theme', 'route' => $this->generateUrl('mautic_themes_index')]]); }
/** * @param $newName * * @return string */ private function getDirectoryName($newName) { return InputHelper::filename($newName, true); }